Skip to content

Commit bcd4c3b

Browse files
author
Ricardo Ortiz
committed
Fix bugs and refactoring some of the info keys.
Issue #8
1 parent 6ecf184 commit bcd4c3b

3 files changed

Lines changed: 26 additions & 41 deletions

File tree

Applications/ButtonClusters/msvQButtonClustersMainWindow.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ void msvQButtonClustersMainWindowPrivate::enableClustering(bool value)
255255
{
256256
this->ButtonsManager->ClusteringEnabledOff();
257257
this->ButtonsManager->ShowButtons();
258+
this->ButtonsManager->HideClusterButtons(1);
258259
}
259260
this->update();
260261
}

Libs/VTK/Widgets/msvVTKWidgetClusters.cxx

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -486,12 +486,9 @@ void msvVTKWidgetClusters::vtkInternal::GetDisplayCoordinates(vtkPoints* from,
486486
//------------------------------------------------------------------------------
487487
vtkStandardNewMacro(msvVTKWidgetClusters);
488488
vtkInformationKeyMacro(msvVTKWidgetClusters, CLUSTER_IDX, IdType);
489-
vtkInformationKeyRestrictedMacro(msvVTKWidgetClusters, CLUSTER_BUTTONS_RANGE,
489+
vtkInformationKeyMacro(msvVTKWidgetClusters, DATASET_BUTTONS_OFFSET, IdType);
490+
vtkInformationKeyRestrictedMacro(msvVTKWidgetClusters, CLUSTER_BUTTONS_OFFSET,
490491
IntegerVector, 2);
491-
vtkInformationKeyRestrictedMacro(msvVTKWidgetClusters, DATASET_BUTTONS_RANGE,
492-
IntegerVector, 2);
493-
vtkInformationKeyRestrictedMacro(msvVTKWidgetClusters, DATA_DIMENSIONALITY,
494-
DoubleVector, 6);
495492

496493
//------------------------------------------------------------------------------
497494
vtkCxxSetObjectMacro(msvVTKWidgetClusters,ColorLookUpTable,vtkLookupTable);
@@ -517,19 +514,9 @@ void msvVTKWidgetClusters::SetDataSet(size_t level, size_t idx,
517514
vtkInformation* info = levelDS->GetMetaData(idx);
518515
if (info)
519516
{
520-
double *bounds = points->GetBounds();
521-
info->Set(DATA_DIMENSIONALITY(),
522-
bounds[0], bounds[1], bounds[2],
523-
bounds[3], bounds[4], bounds[5]);
524517
info->Set(CLUSTER_IDX(),clusterIdx);
525-
526-
int range[2] = {0};
527-
range[0] = this->Internal->ButtonList.size();
528-
range[1] = this->Internal->ButtonList.size() +
529-
points->GetNumberOfPoints();
530-
531-
info->Set(DATASET_BUTTONS_RANGE(), range, 2);
532-
518+
vtkIdType offset = this->Internal->ButtonList.size();
519+
info->Set(DATASET_BUTTONS_OFFSET(), offset);
533520
}
534521
this->Internal->SetButtons(points,this->Internal->ButtonList);
535522
}
@@ -616,11 +603,11 @@ void msvVTKWidgetClusters::SetRenderer(vtkRenderer* renderer)
616603
//------------------------------------------------------------------------------
617604
void msvVTKWidgetClusters::UpdateWidgets()
618605
{
606+
this->Clear();
619607
if(!this->ClusteringEnabled)
620608
{
621609
return;
622610
}
623-
this->Clear();
624611

625612
size_t numLevels = this->GetNumberOfLevels();
626613
for(size_t levelIdx = 0; levelIdx < numLevels; ++levelIdx)
@@ -636,24 +623,22 @@ void msvVTKWidgetClusters::UpdateWidgets()
636623
= vtkUnstructuredGrid::SafeDownCast(levelDS->GetPiece(dataSetIdx));
637624
// Recompute clusters for each dataset
638625
vtkPoints *points = ds->GetPoints();
639-
vtkIdType clusterIdx = this->Internal->ComputeClusters(points);
626+
size_t clusterIdx = this->Internal->ComputeClusters(points);
640627

641628
// Get the cluster structure and assign a button to each cluster
642-
vtkInternal::IndexMapType& indexMap = this->Internal->IndexMaps.back();
629+
vtkInternal::IndexMapType& indexMap = this->Internal->IndexMaps[clusterIdx];
643630

644631
vtkNew<vtkPoints> clusterPositions;
645632
this->Internal->GetClustersPositions(points,indexMap,
646633
clusterPositions.GetPointer());
647634
vtkInformation* info = levelDS->GetMetaData(dataSetIdx);
648635
if(info)
649636
{
650-
651637
int range[2] = {0};
652638
range[0] = this->Internal->ClusterButtons.size();
653-
range[1] = this->Internal->ClusterButtons.size() +
654-
clusterPositions->GetNumberOfPoints();
639+
range[1] = clusterPositions->GetNumberOfPoints();
655640
info->Set(CLUSTER_IDX(),clusterIdx);
656-
info->Set(CLUSTER_BUTTONS_RANGE(),range,2);
641+
info->Set(CLUSTER_BUTTONS_OFFSET(),range,2);
657642
}
658643
this->Internal->SetButtons(
659644
clusterPositions.GetPointer(), this->Internal->ClusterButtons);
@@ -765,11 +750,11 @@ void msvVTKWidgetClusters::ShowClusterButtons(size_t level)
765750
vtkInformation* info = levelDS->GetMetaData(dataSetIdx);
766751
if(info)
767752
{
768-
int buttonRange[2];
769-
info->Get(CLUSTER_BUTTONS_RANGE(),buttonRange);
770-
for(int i = buttonRange[0]; i < buttonRange[1]; ++i)
753+
int offset[2];
754+
info->Get(CLUSTER_BUTTONS_OFFSET(),offset);
755+
for(int i = 0; i < offset[1]; ++i)
771756
{
772-
this->Internal->ClusterButtons[i]->Show();
757+
this->Internal->ClusterButtons[offset[0]+i]->Show();
773758
}
774759
}
775760
}
@@ -794,11 +779,11 @@ void msvVTKWidgetClusters::HideClusterButtons(size_t level)
794779
vtkInformation* info = levelDS->GetMetaData(dataSetIdx);
795780
if(info)
796781
{
797-
int buttonRange[2];
798-
info->Get(CLUSTER_BUTTONS_RANGE(),buttonRange);
799-
for(int i = buttonRange[0]; i < buttonRange[1]; ++i)
782+
int offset[2];
783+
info->Get(CLUSTER_BUTTONS_OFFSET(),offset);
784+
for(int i = 0; i < offset[1]; ++i)
800785
{
801-
this->Internal->ClusterButtons[i]->Hide();
786+
this->Internal->ClusterButtons[offset[0]+i]->Hide();
802787
}
803788
}
804789
}
@@ -820,12 +805,12 @@ void msvVTKWidgetClusters::ShowButtons(size_t level)
820805
size_t numDataSets = this->GetNumberOfDataSets(level);
821806
for(size_t dataSetIdx = 0; dataSetIdx < numDataSets; ++dataSetIdx)
822807
{
808+
size_t numButtons = vtkUnstructuredGrid::SafeDownCast(levelDS->GetPiece(dataSetIdx))->GetPoints()->GetNumberOfPoints();
823809
vtkInformation* info = levelDS->GetMetaData(dataSetIdx);
824810
if(info)
825811
{
826-
int buttonRange[2];
827-
info->Get(DATASET_BUTTONS_RANGE(),buttonRange);
828-
for(int i = buttonRange[0]; i < buttonRange[1]; ++i)
812+
vtkIdType offset = info->Get(DATASET_BUTTONS_OFFSET());
813+
for(size_t i = offset, end = offset+numButtons; i < end; ++i)
829814
{
830815
this->Internal->ButtonList[i]->Show();
831816
}
@@ -845,12 +830,12 @@ void msvVTKWidgetClusters::HideButtons(size_t level)
845830
size_t numDataSets = this->GetNumberOfDataSets(level);
846831
for(size_t dataSetIdx = 0; dataSetIdx < numDataSets; ++dataSetIdx)
847832
{
833+
size_t numButtons = vtkUnstructuredGrid::SafeDownCast(levelDS->GetPiece(dataSetIdx))->GetPoints()->GetNumberOfPoints();
848834
vtkInformation* info = levelDS->GetMetaData(dataSetIdx);
849835
if(info)
850836
{
851-
int buttonRange[2];
852-
info->Get(DATASET_BUTTONS_RANGE(),buttonRange);
853-
for(int i = buttonRange[0]; i < buttonRange[1]; ++i)
837+
vtkIdType offset = info->Get(DATASET_BUTTONS_OFFSET());
838+
for(size_t i = offset, end = offset+numButtons; i < end; ++i)
854839
{
855840
this->Internal->ButtonList[i]->Hide();
856841
}

Libs/VTK/Widgets/msvVTKWidgetClusters.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,9 @@ class msvVTKWidgetClusters : public vtkObject
100100
// Returns the number of levels.
101101
size_t GetNumberOfLevels();
102102

103-
static vtkInformationDoubleVectorKey* DATA_DIMENSIONALITY();
104103
static vtkInformationIdTypeKey* CLUSTER_IDX();
105-
static vtkInformationIntegerVectorKey* CLUSTER_BUTTONS_RANGE();
106-
static vtkInformationIntegerVectorKey* DATASET_BUTTONS_RANGE();
104+
static vtkInformationIdTypeKey* DATASET_BUTTONS_OFFSET();
105+
static vtkInformationIntegerVectorKey* CLUSTER_BUTTONS_OFFSET();
107106

108107
virtual void UpdateWidgets();
109108
virtual void Clear();

0 commit comments

Comments
 (0)