11/* ==============================================================================
22
3- Library: MSVTK
3+ Library: MSVTK
44
5- Copyright (c) Kitware Inc.
5+ Copyright (c) Kitware Inc.
66
7- Licensed under the Apache License, Version 2.0 (the "License");
8- you may not use this file except in compliance with the License.
9- You may obtain a copy of the License at
7+ Licensed under the Apache License, Version 2.0 (the "License");
8+ you may not use this file except in compliance with the License.
9+ You may obtain a copy of the License at
1010
11- http://www.apache.org/licenses/LICENSE-2.0.txt
11+ http://www.apache.org/licenses/LICENSE-2.0.txt
1212
13- Unless required by applicable law or agreed to in writing, software
14- distributed under the License is distributed on an "AS IS" BASIS,
15- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16- See the License for the specific language governing permissions and
17- limitations under the License.
13+ Unless required by applicable law or agreed to in writing, software
14+ distributed under the License is distributed on an "AS IS" BASIS,
15+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+ See the License for the specific language governing permissions and
17+ limitations under the License.
1818
19- ==============================================================================*/
19+ ==============================================================================*/
2020
2121// Qt includes
2222#include < QDebug>
2323#include < QFileDialog>
2424#include < QMessageBox>
2525#include < QModelIndex>
2626#include < QString>
27- #include < unistd.h>
2827
2928// MSV includes
3029#include " msvQButtonClustersMainWindow.h"
5756#include " vtkVolumeProperty.h"
5857#include " vtkVolume.h"
5958
60-
59+ // STD includes
60+ #ifndef _WIN32
61+ #include < unistd.h>
62+ #endif
6163
6264// ------------------------------------------------------------------------------
6365class msvQButtonClustersMainWindowPrivate
@@ -84,7 +86,7 @@ class msvQButtonClustersMainWindowPrivate
8486 vtkSmartPointer<vtkPolyDataMapper> SurfaceMapper;
8587 vtkSmartPointer<vtkActor> SurfaceActor;
8688
87- std::vector<vtkSmartPointer<vtkVolume> > VolumeList;
89+ std::vector<vtkSmartPointer<vtkVolume> > VolumeList;
8890 std::vector<vtkSmartPointer<vtkPolyData> > PolyDataList;
8991 std::map<int ,vtkProp3D*> dataActorMap;
9092
@@ -118,8 +120,9 @@ class msvQButtonClustersMainWindowPrivate
118120 virtual void clear ();
119121
120122 virtual void readData (const QString&);
121- virtual void readDataFiles (const QString&, int &, int );
122- virtual void readDataFile (const QString&, int &, int );
123+ virtual void readData (const QString& directory, int & idx, int group);
124+ virtual void readDataFiles (const QString&, int & idx, int group);
125+ virtual void readDataFile (const QString&, int & idx, int group);
123126
124127 void readPolyData (const QString&, int idx, int group);
125128 void readVolumeData (const QString&, int idx, int group);
@@ -216,8 +219,9 @@ msvQButtonClustersMainWindowPrivate::msvQButtonClustersMainWindowPrivate(
216219 this ->VolumeProperty ->SetSpecular (0.2 );
217220
218221 // Set the buttons manager
222+ QFileInfo icon (QDir (qApp->applicationDirPath ()), " Resources/Logo/icon.png" );
219223 this ->buttonsIcon = vtkSmartPointer<vtkPNGReader>::New ();
220- this ->buttonsIcon ->SetFileName (" Resources/Logo/ icon.png " );
224+ this ->buttonsIcon ->SetFileName (icon.absoluteFilePath (). toLatin1 () );
221225 this ->buttonsIcon ->Update ();
222226 this ->ButtonsManager = vtkSmartPointer<msvVTKWidgetClusters>::New ();
223227 this ->ButtonsManager ->UseImprovedClusteringOn ();
@@ -250,21 +254,13 @@ msvQButtonClustersMainWindowPrivate::~msvQButtonClustersMainWindowPrivate()
250254void msvQButtonClustersMainWindowPrivate::showData (int idx, bool value)
251255{
252256 this ->dataActorMap [idx]->SetVisibility (value);
253- this ->updateView ();
254257}
255258
256259// ------------------------------------------------------------------------------
257260void msvQButtonClustersMainWindowPrivate::enableClustering (bool value)
258261{
259262 this ->ButtonsManager ->SetClustering (value);
260- if (value)
261- {
262- this ->ButtonsManager ->HideButtons ();
263- }
264- else
265- {
266- this ->ButtonsManager ->ShowButtons ();
267- }
263+ this ->ButtonsManager ->SetCustersButtonsVisibility (value);
268264 this ->ButtonsManager ->UpdateWidgets ();
269265 this ->updateView ();
270266}
@@ -383,15 +379,14 @@ void msvQButtonClustersMainWindowPrivate::setupView()
383379// ------------------------------------------------------------------------------
384380void msvQButtonClustersMainWindowPrivate::update ()
385381{
386- this ->updateUi ();
387382 this ->updateView ();
388383}
389384
390385// ------------------------------------------------------------------------------
391386void msvQButtonClustersMainWindowPrivate::updateUi ()
392387{
393- // this->enableClustering(this->EnableClustering->isChecked());
394- // this->setPixelRadius(this->PixelRadius->value());
388+ this ->enableClustering (this ->EnableClustering ->isChecked ());
389+ this ->setPixelRadius (this ->PixelRadius ->value ());
395390}
396391
397392// ------------------------------------------------------------------------------
@@ -417,28 +412,30 @@ void msvQButtonClustersMainWindowPrivate::readVolumeData(const QString &file,
417412 reader->SetFileName (file.toLatin1 ().constData ());
418413 reader->Update ();
419414
415+ #ifdef CREATE_VOLUME_CORNER_BUTTONS
420416 // Create 8 buttons for the volume.
421417 vtkNew<vtkPoints> points;
422418 points->SetNumberOfPoints (8 );
423419
424420 double *bounds = reader->GetOutput ()->GetBounds ();
425421 double point[8 ][3 ] =
426422 {
427- {bounds[0 ], bounds[2 ], bounds[4 ]},
428- {bounds[0 ], bounds[2 ], bounds[5 ]},
429- {bounds[0 ], bounds[3 ], bounds[4 ]},
430- {bounds[0 ], bounds[3 ], bounds[5 ]},
431- {bounds[1 ], bounds[2 ], bounds[4 ]},
432- {bounds[1 ], bounds[2 ], bounds[5 ]},
433- {bounds[1 ], bounds[3 ], bounds[4 ]},
434- {bounds[1 ], bounds[3 ], bounds[5 ]}
423+ {bounds[0 ], bounds[2 ], bounds[4 ]},
424+ {bounds[0 ], bounds[2 ], bounds[5 ]},
425+ {bounds[0 ], bounds[3 ], bounds[4 ]},
426+ {bounds[0 ], bounds[3 ], bounds[5 ]},
427+ {bounds[1 ], bounds[2 ], bounds[4 ]},
428+ {bounds[1 ], bounds[2 ], bounds[5 ]},
429+ {bounds[1 ], bounds[3 ], bounds[4 ]},
430+ {bounds[1 ], bounds[3 ], bounds[5 ]}
435431 };
436432
437433 for (vtkIdType i = 0 ; i < 8 ; ++i)
438434 {
439435 points->InsertPoint (i, point[i]);
440436 }
441437 this ->ButtonsManager ->SetDataSet (group,idx,points.GetPointer ());
438+ #endif
442439 this ->VolumeList .push_back (volume.GetPointer ());
443440 this ->dataActorMap [idx] = volume.GetPointer ();
444441}
@@ -484,74 +481,69 @@ void msvQButtonClustersMainWindowPrivate::readPolyData(const QString &file,
484481}
485482
486483// ------------------------------------------------------------------------------
487- void msvQButtonClustersMainWindowPrivate::readDataFiles (const QString& dirName ,
488- int & idx,
489- int group)
484+ void msvQButtonClustersMainWindowPrivate::readDataFiles (const QString& directory ,
485+ int & idx,
486+ int group)
490487{
491- QDir dir (dirName);
492- QStringList dataFiles = dir. entryList ( QDir::Files, QDir::Name). filter ( " vtk " );
488+ QFileInfoList dataFiles = QDir (directory). entryInfoList (
489+ QStringList ( " *.vtk " ), QDir::Files, QDir::Name);
493490
494- foreach (const QString &file, dataFiles)
491+ foreach (const QFileInfo &file, dataFiles)
495492 {
496- QString fileName = QFileInfo (dir,file).absoluteFilePath ();
497- this ->DataLoader ->insertItem (idx,file);
498- readDataFile (fileName,idx,group);
493+ this ->DataLoader ->insertItem (idx,file.baseName ());
494+ this ->readDataFile (file.absoluteFilePath (), idx, group);
499495 this ->DataLoader ->setItemData (idx-1 , Qt::Checked, Qt::CheckStateRole);
500496 }
501497}
502498
503499// ------------------------------------------------------------------------------
504- void msvQButtonClustersMainWindowPrivate::readDataFile (const QString& fileName,
505- int & idx,
506- int group)
500+ void msvQButtonClustersMainWindowPrivate
501+ ::readDataFile (const QString& fileName, int & idx, int group)
507502{
508503 vtkNew<vtkDataReader> reader;
509504 reader->SetFileName (fileName.toLatin1 ().constData ());
510- if (reader->IsFilePolyData ())
505+ if (reader->IsFilePolyData ())
511506 {
512- readPolyData (fileName,idx,group);
507+ this -> readPolyData (fileName,idx,group);
513508 idx++;
514509 }
515- else if (reader->IsFileStructuredPoints ())
510+ else if (reader->IsFileStructuredPoints ())
516511 {
517- readVolumeData (fileName,idx,group);
512+ this -> readVolumeData (fileName,idx,group);
518513 idx++;
519514 }
520515 else
521516 {
522- return ;
517+ qCritical () << " File " << fileName << " is not supported. " ;
523518 }
524519}
525520
526521// ------------------------------------------------------------------------------
527522void msvQButtonClustersMainWindowPrivate::readData (const QString& rootDirectory)
528523{
529- QDir dir (rootDirectory);
530-
531- QStringList files =
532- dir.entryList (QDir::Files, QDir::Name).filter (" vtk" );
533- QStringList directories = dir.entryList (QDir::Dirs | QDir::NoDotAndDotDot,
534- QDir::Name);
535-
536524 int idx = 0 ;
537525 int group = 0 ;
538- foreach (const QString &file, files)
539- {
540- QString fileName = QFileInfo (dir,file).absoluteFilePath ();
541- this ->DataLoader ->insertItem (idx,file);
542- readDataFile (fileName,idx,group);
543- this ->DataLoader ->setItemData (idx-1 , Qt::Checked, Qt::CheckStateRole);
544- }
545- foreach (const QString &directory, directories)
546- {
547- readDataFiles (QFileInfo (dir,directory).absoluteFilePath (),idx,group);
548- }
526+ this ->readData (rootDirectory, idx, group);
527+
528+ this ->updateUi ();
549529
550530 // Render
551531 double extent[6 ];
552532 this ->getMaximumExtent (extent);
553533 this ->ThreeDRenderer ->ResetCamera (extent);
534+ }
554535
536+ // ------------------------------------------------------------------------------
537+ void msvQButtonClustersMainWindowPrivate
538+ ::readData (const QString& directory, int & idx, int group)
539+ {
540+ QFileInfoList subDirectories = QDir (directory).entryInfoList (
541+ QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
542+ foreach (const QFileInfo& subdirectory, subDirectories)
543+ {
544+ this ->readData (subdirectory.absoluteFilePath (), idx, group);
545+ }
546+ this ->readDataFiles (directory,idx, group);
555547}
556548
557549// ------------------------------------------------------------------------------
@@ -576,7 +568,6 @@ void msvQButtonClustersMainWindowPrivate::getMaximumExtent(double extent[6])
576568 {
577569 extent[j+1 ] = bounds[j+1 ];
578570 }
579-
580571 }
581572 }
582573 size = this ->PolyDataList .size ();
@@ -707,14 +698,12 @@ void msvQButtonClustersMainWindow::on_DataLoader_checkedIndexesChanged( )
707698{
708699 Q_D (msvQButtonClustersMainWindow);
709700 QModelIndexList dataList = d->DataLoader ->checkedIndexes ();
710- for (size_t i = 0 , end = d->dataActorMap .size (); i < end; ++i)
701+ for (vtkIdType i = 0 , end = d->dataActorMap .size (); i < end; ++i)
711702 {
712- d->showData (i,false );
713- }
714- foreach (const QModelIndex &index, dataList)
715- {
716- d->showData (index.row (),true );
703+ QModelIndex index = d->DataLoader ->model ()->index (i,0 );
704+ d->showData (i, d->DataLoader ->checkState (index) == Qt::Checked);
717705 }
706+ d->updateView ();
718707}
719708
720709// ------------------------------------------------------------------------------
0 commit comments