48 vtkInformationVector **inputVector,
49 vtkInformationVector *outputVector) {
52 auto inputDataSet = vtkDataSet::GetData(inputVector[0]);
56 const auto nPoints = inputDataSet->GetNumberOfPoints();
58 auto featureMask = this->GetInputArrayToProcess(0, inputVector);
60 if(featureMask && this->GetInputArrayAssociation(0, inputVector) != 0)
61 return !this->
printErr(
"Input array needs to be a point data array.");
63 if(featureMask && featureMask->GetNumberOfComponents() != 1)
64 return !this->
printErr(
"Input array needs to be a scalar array.");
72 componentIds->SetName(
"ComponentId");
73 componentIds->SetNumberOfTuples(nPoints);
76 componentSize->SetName(
"ComponentSize");
77 if(this->AugmentSegmentationWithComponentSize)
78 componentSize->SetNumberOfTuples(nPoints);
81 std::vector<ttk::ConnectedComponents::Component> components;
86 ttkTypeMacroA(featureMask ? featureMask->GetDataType() : VTK_INT,
87 (status = this->initializeComponentIds<T0>(
88 ttkUtils::GetPointer<int>(componentIds), nPoints,
89 ttkUtils::GetPointer<const T0>(featureMask),
90 this->BackgroundThreshold)));
97 (status = this->computeConnectedComponents<T0>(
98 components, ttkUtils::GetPointer<int>(componentIds),
99 static_cast<const T0 *
>(triangulation->getData()))));
109 if(this->AugmentSegmentationWithComponentSize) {
111 components, ttkUtils::GetPointer<int>(componentIds), nPoints,
112 [](
const std::vector<ttk::ConnectedComponents::Component> &components_,
113 const int cIdx) {
return cIdx < 0 ? 0.0 : components_[cIdx].size; },
114 ttkUtils::GetPointer<float>(componentSize));
121 components, ttkUtils::GetPointer<int>(componentIds), nPoints,
122 [](
const std::vector<ttk::ConnectedComponents::Component> &components_,
123 const int cIdx) {
return cIdx < 0 ? -1 : components_[cIdx].id; },
124 ttkUtils::GetPointer<int>(componentIds));
131 auto outputDataSet = vtkDataSet::GetData(outputVector, 0);
132 outputDataSet->ShallowCopy(inputDataSet);
133 outputDataSet->GetPointData()->AddArray(componentIds);
134 if(this->AugmentSegmentationWithComponentSize)
135 outputDataSet->GetPointData()->AddArray(componentSize);
140 const int nComponents = components.size();
141 auto outputComponents = vtkPolyData::GetData(outputVector, 1);
146 sizeArray->SetName(
"Size");
147 sizeArray->SetNumberOfTuples(nComponents);
148 auto sizeArrayData = ttkUtils::GetPointer<float>(sizeArray);
151 idArray->SetName(
"ComponentId");
152 idArray->SetNumberOfTuples(nComponents);
153 auto idArrayData = ttkUtils::GetPointer<int>(idArray);
156 points->SetDataTypeToFloat();
157 points->SetNumberOfPoints(nComponents);
158 auto pointsData = ttkUtils::GetPointer<float>(points->GetData());
159 for(
int i = 0, j = 0; i < nComponents; i++) {
160 const auto &c = components[i];
161 pointsData[j++] = c.center[0];
162 pointsData[j++] = c.center[1];
163 pointsData[j++] = c.center[2];
165 sizeArrayData[i] = c.size;
166 idArrayData[i] = c.id;
169 outputComponents->SetPoints(points);
170 auto pd = outputComponents->GetPointData();
171 pd->AddArray(sizeArray);
172 pd->AddArray(idArray);
178 connectivityArray->SetNumberOfTuples(nComponents);
179 auto connectivityArrayData = ttkUtils::GetPointer<int>(connectivityArray);
180 for(
int i = 0; i < nComponents; i++)
181 connectivityArrayData[i] = i;
184 offsetArray->SetNumberOfTuples(nComponents + 1);
185 auto offsetArrayData = ttkUtils::GetPointer<int>(offsetArray);
186 for(
int i = 0; i <= nComponents; i++)
187 offsetArrayData[i] = i;
190 cellArray->SetData(offsetArray, connectivityArray);
192 outputComponents->SetVerts(cellArray);
196 outputComponents->GetFieldData()->ShallowCopy(inputDataSet->GetFieldData());