Skip to content

Commit 4b7c4d7

Browse files
committed
Merge branch 'ButtonClustering'
# By Julien Finet (9) and Ricardo Ortiz (6) # Via Julien Finet (2) and Ricardo Ortiz (1) * ButtonClustering: Fix crash on uninitialized variables Show VTKButtons on interaction Don't refresh the view unnecessarilly when toggling data visibility Support sub-subdirectory for loading data Don't show the volume corners Copy icon.png to build and install directory Fix compilation warnings by using vtkIdType instead of size_t Use CTK utility functions to convert vtkImage to QImage Fix unistd compilation error with VisualStudio Add multiple improvements. WIP: Adding cluster representation to display clustering using a graph WIP: Add cluster visualization and cleaned GUI a bit. WIP: Adding msvVTKButtons support WIP: Adding msvVTKButtons support in button clustering WIP: Integrating msvVTKButtons to the clustering interface. Conflicts: Applications/ButtonClusters/msvQButtonClustersMainWindow.cxx Libs/VTK/Widgets/msvVTKButtonsManager.cxx Libs/VTK/Widgets/msvVTKButtonsManager.h Libs/VTK/Widgets/msvVTKWidgetClusters.cxx Libs/VTK/Widgets/msvVTKWidgetClusters.h
2 parents bf3cd7a + e00b632 commit 4b7c4d7

15 files changed

Lines changed: 359 additions & 391 deletions

Applications/ButtonClusters/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ target_link_libraries(msv${KIT}
8484
msvQtWidgets
8585
)
8686

87+
add_custom_command(TARGET msv${KIT} PRE_BUILD
88+
COMMAND ${CMAKE_COMMAND} -E copy
89+
"${CMAKE_CURRENT_SOURCE_DIR}/Resources/Logo/icon.png"
90+
"$<TARGET_FILE_DIR:msv${KIT}>/Resources/Logo/icon.png")
91+
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/Resources/Logo/icon.png"
92+
DESTINATION "${MSVTK_INSTALL_BIN_DIR}/Resources/Logo/")
93+
8794
install(TARGETS msv${KIT}
8895
RUNTIME DESTINATION ${MSVTK_INSTALL_BIN_DIR} COMPONENT RuntimeLibraries
8996
LIBRARY DESTINATION ${MSVTK_INSTALL_LIB_DIR} COMPONENT RuntimeLibraries

Applications/ButtonClusters/msvQButtonClustersMainWindow.cxx

Lines changed: 69 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
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"
@@ -57,7 +56,10 @@
5756
#include "vtkVolumeProperty.h"
5857
#include "vtkVolume.h"
5958

60-
59+
// STD includes
60+
#ifndef _WIN32
61+
#include <unistd.h>
62+
#endif
6163

6264
// ------------------------------------------------------------------------------
6365
class 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()
250254
void msvQButtonClustersMainWindowPrivate::showData(int idx, bool value)
251255
{
252256
this->dataActorMap[idx]->SetVisibility(value);
253-
this->updateView();
254257
}
255258

256259
// ------------------------------------------------------------------------------
257260
void 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
// ------------------------------------------------------------------------------
384380
void msvQButtonClustersMainWindowPrivate::update()
385381
{
386-
this->updateUi();
387382
this->updateView();
388383
}
389384

390385
// ------------------------------------------------------------------------------
391386
void 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
// ------------------------------------------------------------------------------
527522
void 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
// ------------------------------------------------------------------------------

Applications/FFS/msvFluidSimulator.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1616
See the License for the specific language governing permissions and
1717
limitations under the License.
18-
kile
1918
==============================================================================*/
2019

2120
#ifndef __msvFluidSimulator_h

Applications/VTKButtons/msvQVTKButtonsMainWindow.cxx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#include <QVector>
2828
#include <QBuffer>
2929

30+
// CTK includes
31+
#include <ctkWidgetsUtils.h>
3032

3133
// MSV includes
3234
#include "msvQVTKButtonsMainWindow.h"
@@ -270,12 +272,7 @@ void msvQVTKButtonsMainWindowPrivate::setToolTip(msvQVTKButtons *b)
270272
text.append("<tr>");
271273
text.append("<td>");
272274
QImage preview = b->getPreview(180,180);
273-
QByteArray ba;
274-
QBuffer buffer(&ba);
275-
buffer.open(QIODevice::WriteOnly);
276-
preview.save(&buffer, "PNG");
277-
278-
text.append(QString("<img src=\"data:image/png;base64,%1\">").arg(QString(buffer.data().toBase64())));
275+
text.append(QString("<img src=\"%1\">").arg(ctk::base64HTMLImageTagSrc(preview)));
279276
text.append("</td>");
280277

281278
text.append("<td>");

0 commit comments

Comments
 (0)