4#include <vtkCellData.h>
5#include <vtkConnectivityFilter.h>
6#include <vtkDoubleArray.h>
7#include <vtkInformation.h>
8#include <vtkPointData.h>
9#include <vtkUnstructuredGrid.h>
16 this->SetNumberOfInputPorts(1);
17 this->SetNumberOfOutputPorts(1);
19 vtkWarningMacro(
"`TTK ComponentSize' is now deprecated. Please use "
20 "`Connectivity' instead.");
27 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),
"vtkDataSet");
34 vtkInformation *info) {
43 vtkInformationVector **inputVector,
44 vtkInformationVector *outputVector) {
52 connectivityFilter->SetInputData(vtkDataSet::GetData(inputVector[0]));
53 connectivityFilter->SetExtractionModeToAllRegions();
54 connectivityFilter->ColorRegionsOn();
55 connectivityFilter->Update();
57 size_t nRegions = connectivityFilter->GetNumberOfExtractedRegions();
59 this->
printErr(
"Unable to compute connected components.");
64 "Computing connected components (" + std::to_string(nRegions) +
")", 1,
68 this->
printMsg(
"Computing component sizes", 0, 0, threadNumber,
71 auto output = vtkDataSet::GetData(outputVector);
72 output->ShallowCopy(connectivityFilter->GetOutput());
74 size_t nVertices = output->GetNumberOfPoints();
75 size_t nCells = output->GetNumberOfCells();
78 output->GetPointData()->GetArray(
"RegionId"));
80 output->GetCellData()->GetArray(
"RegionId"));
82 if(!vertexIds || !cellIds) {
83 this->
printErr(
"Unable to retrieve vertex and cell Identifiers.");
91 std::vector<double> regionIdToVertexCountMap(nRegions, 0);
92#ifdef TTK_ENABLE_OPENMP
93#pragma omp parallel for num_threads(threadNumber)
95 for(
size_t i = 0; i < nVertices; i++) {
96 auto regionId = vertexIds[i];
98#ifdef TTK_ENABLE_OPENMP
99#pragma omp atomic update
101 regionIdToVertexCountMap[regionId]++;
105 std::vector<double> regionIdToCellCountMap(nRegions, 0);
106#ifdef TTK_ENABLE_OPENMP
107#pragma omp parallel for num_threads(threadNumber)
109 for(
size_t i = 0; i < nCells; i++) {
110 auto regionId = cellIds[i];
112#ifdef TTK_ENABLE_OPENMP
113#pragma omp atomic update
115 regionIdToCellCountMap[regionId]++;
121 vertexNumbers->SetNumberOfComponents(1);
122 vertexNumbers->SetNumberOfTuples(nVertices);
123 vertexNumbers->SetName(
"VertexNumber");
126#ifdef TTK_ENABLE_OPENMP
127#pragma omp parallel for num_threads(threadNumber)
129 for(
size_t i = 0; i < nVertices; i++) {
130 vertexNumbersData[i] = regionIdToVertexCountMap[vertexIds[i]];
133 output->GetPointData()->AddArray(vertexNumbers);
139 cellNumbers->SetNumberOfComponents(1);
140 cellNumbers->SetNumberOfTuples(nCells);
141 cellNumbers->SetName(
"CellNumber");
144#ifdef TTK_ENABLE_OPENMP
145#pragma omp parallel for num_threads(threadNumber)
147 for(
size_t i = 0; i < nCells; i++) {
148 cellNumbersData[i] = regionIdToCellCountMap[cellIds[i]];
151 output->GetCellData()->AddArray(cellNumbers);
155 "Computing component sizes", 1, t.
getElapsedTime(), threadNumber);
#define ttkNotUsed(x)
Mark function/method parameters that are not used in the function body at all.
static vtkInformationIntegerKey * SAME_DATA_TYPE_AS_INPUT_PORT()
TTK VTK-filter that computes the connected components of a data-set, and that computes their size (nu...
~ttkComponentSize() override
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
int FillInputPortInformation(int port, vtkInformation *info) override
int FillOutputPortInformation(int port, vtkInformation *info) override
static void * GetVoidPointer(vtkDataArray *array, vtkIdType start=0)
int getThreadNumber() const
void setDebugMsgPrefix(const std::string &prefix)
int printMsg(const std::string &msg, const debug::Priority &priority=debug::Priority::INFO, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cout) const
int printErr(const std::string &msg, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cerr) const
vtkStandardNewMacro(ttkComponentSize)