Skip to content

Commit 30a64d4

Browse files
committed
fix morse smale complex for multiblock input
1 parent fac0085 commit 30a64d4

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

core/vtk/ttkMorseSmaleComplex/ttkMorseSmaleComplex.cpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
#include <ttkMorseSmaleComplex.h>
33
#include <ttkUtils.h>
44

5+
#include <vtkAbstractArray.h>
56
#include <vtkCellData.h>
67
#include <vtkDataArray.h>
78
#include <vtkDataObject.h>
9+
#include <vtkDataObjectTypes.h>
810
#include <vtkDataSet.h>
911
#include <vtkDoubleArray.h>
1012
#include <vtkFloatArray.h>
1113
#include <vtkIdTypeArray.h>
14+
#include <vtkImageData.h>
1215
#include <vtkInformation.h>
1316
#include <vtkNew.h>
1417
#include <vtkPointData.h>
@@ -40,14 +43,18 @@ int ttkMorseSmaleComplex::FillOutputPortInformation(int port,
4043
return 1;
4144
} else if(port == 3) {
4245
info->Set(ttkAlgorithm::SAME_DATA_TYPE_AS_INPUT_PORT(), 0);
46+
// info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkDataSet");
4347
return 1;
4448
}
4549
return 0;
4650
}
4751

4852
template <typename vtkArrayType, typename vectorType>
4953
void setArray(vtkArrayType &vtkArray, vectorType &vector) {
50-
ttkUtils::SetVoidArray(vtkArray, vector.data(), vector.size(), 1);
54+
vtkArray->SetNumberOfTuples(vector.size());
55+
for(unsigned int i = 0; i < vector.size(); i++) {
56+
vtkArray->SetValue(i, vector[i]);
57+
}
5158
}
5259

5360
template <typename scalarType, typename triangulationType>
@@ -61,6 +68,9 @@ int ttkMorseSmaleComplex::dispatch(vtkDataArray *const inputScalars,
6168
const int dimensionality = triangulation.getDimensionality();
6269
const auto scalars = ttkUtils::GetPointer<scalarType>(inputScalars);
6370

71+
OutputCriticalPoints criticalPoints_{};
72+
Output1Separatrices separatrices1_{};
73+
Output2Separatrices separatrices2_{};
6474
const int ret = this->execute(
6575
criticalPoints_, separatrices1_, separatrices2_, segmentations_, scalars,
6676
inputScalars->GetMTime(), inputOffsets, triangulation);
@@ -148,7 +158,6 @@ int ttkMorseSmaleComplex::dispatch(vtkDataArray *const inputScalars,
148158
pointData->AddArray(PLVertexIdentifiers);
149159
pointData->AddArray(manifoldSizeScalars);
150160
}
151-
152161
// 1-separatrices
153162
if(ComputeAscendingSeparatrices1 or ComputeDescendingSeparatrices1
154163
or ComputeSaddleConnectors) {
@@ -177,7 +186,12 @@ int ttkMorseSmaleComplex::dispatch(vtkDataArray *const inputScalars,
177186
#endif
178187

179188
pointsCoords->SetNumberOfComponents(3);
180-
setArray(pointsCoords, separatrices1_.pt.points_);
189+
pointsCoords->SetNumberOfTuples(separatrices1_.pt.numberOfPoints_);
190+
for(int i = 0; i < separatrices1_.pt.numberOfPoints_; i++) {
191+
pointsCoords->SetTuple3(i, separatrices1_.pt.points_[3 * i],
192+
separatrices1_.pt.points_[3 * i + 1],
193+
separatrices1_.pt.points_[3 * i + 2]);
194+
}
181195

182196
smoothingMask->SetNumberOfComponents(1);
183197
smoothingMask->SetName(ttk::MaskScalarFieldName);
@@ -309,7 +323,12 @@ int ttkMorseSmaleComplex::dispatch(vtkDataArray *const inputScalars,
309323
#endif
310324

311325
pointsCoords->SetNumberOfComponents(3);
312-
setArray(pointsCoords, separatrices2_.pt.points_);
326+
pointsCoords->SetNumberOfTuples(separatrices2_.pt.points_.size());
327+
for(int i = 0; i < separatrices2_.pt.numberOfPoints_; i++) {
328+
pointsCoords->SetTuple3(i, separatrices2_.pt.points_[0],
329+
separatrices2_.pt.points_[1],
330+
separatrices2_.pt.points_[2]);
331+
}
313332

314333
sourceIds->SetNumberOfComponents(1);
315334
sourceIds->SetName(ttk::MorseSmaleSourceIdName);
@@ -387,15 +406,15 @@ int ttkMorseSmaleComplex::dispatch(vtkDataArray *const inputScalars,
387406
cellData->AddArray(separatrixFunctionDiffs);
388407
cellData->AddArray(isOnBoundary);
389408
}
390-
391409
return ret;
392410
}
393411

394412
int ttkMorseSmaleComplex::RequestData(vtkInformation *ttkNotUsed(request),
395413
vtkInformationVector **inputVector,
396414
vtkInformationVector *outputVector) {
397415

398-
const auto input = vtkDataSet::GetData(inputVector[0]);
416+
const auto input
417+
= vtkImageData::SafeDownCast(vtkDataSet::GetData(inputVector[0]));
399418
auto outputCriticalPoints = vtkPolyData::GetData(outputVector, 0);
400419
auto outputSeparatrices1 = vtkPolyData::GetData(outputVector, 1);
401420
auto outputSeparatrices2 = vtkPolyData::GetData(outputVector, 2);
@@ -469,6 +488,7 @@ int ttkMorseSmaleComplex::RequestData(vtkInformation *ttkNotUsed(request),
469488
return -1;
470489
}
471490
#endif
491+
472492
ascendingManifold->SetNumberOfComponents(1);
473493
ascendingManifold->SetNumberOfTuples(numberOfVertices);
474494
ascendingManifold->SetName(ttk::MorseSmaleAscendingName);

0 commit comments

Comments
 (0)