44 vtkInformationVector **inputVector,
45 vtkInformationVector *outputVector) {
50 auto *input = vtkTable::GetData(inputVector[0]);
51 auto *output = vtkUnstructuredGrid::GetData(outputVector);
53 if(SelectFieldsWithRegexp) {
56 const auto n = input->GetNumberOfColumns();
57 for(
int i = 0; i < n; ++i) {
58 const auto &name = input->GetColumnName(i);
59 if(std::regex_match(name, std::regex(RegexpString))) {
60 ScalarFields.emplace_back(name);
65 const SimplexId numberOfRows = input->GetNumberOfRows();
66 const SimplexId numberOfColumns = ScalarFields.size();
68 if(numberOfRows <= 0 || numberOfColumns <= 0) {
69 this->
printErr(
"Input matrix has invalid dimensions (rows: "
70 + std::to_string(numberOfRows)
71 +
", columns: " + std::to_string(numberOfColumns) +
")");
75 if(numberOfColumns != numberOfRows) {
76 this->
printErr(
"Input distance matrix is not square (rows: "
77 + std::to_string(numberOfRows)
78 +
", columns: " + std::to_string(numberOfColumns) +
")");
82 std::array<vtkAbstractArray *, 3> components{
83 input->GetColumnByName(this->XColumn.data()),
84 input->GetColumnByName(this->YColumn.data()),
85 input->GetColumnByName(this->ZColumn.data()),
89 vtkNew<vtkPoints> points{};
90 const auto nPoints = components[0]->GetNumberOfTuples();
91 points->SetNumberOfPoints(nPoints);
92#ifdef TTK_ENABLE_OPENMP
93#pragma omp parallel for num_threads(this->threadNumber_)
95 for(vtkIdType i = 0; i < nPoints; ++i) {
96 std::array<float, 3> coords{};
97 if(components[0] !=
nullptr) {
98 coords[0] = components[0]->GetVariantValue(i).ToFloat();
100 if(components[1] !=
nullptr && components[1] != components[0]) {
101 coords[1] = components[1]->GetVariantValue(i).ToFloat();
103 if(components[2] !=
nullptr && components[2] != components[0]
104 && components[2] != components[1]) {
105 coords[2] = components[2]->GetVariantValue(i).ToFloat();
107 points->SetPoint(i, coords.data());
110 std::vector<vtkAbstractArray *> arrays{};
111 arrays.reserve(ScalarFields.size());
112 for(
const auto &s : ScalarFields) {
113 arrays.push_back(input->GetColumnByName(s.data()));
116 std::vector<std::vector<double>> inputMatrix(numberOfRows);
117#ifdef TTK_ENABLE_OPENMP
118#pragma omp parallel for num_threads(this->threadNumber_)
120 for(SimplexId i = 0; i < numberOfRows; ++i) {
121 for(
size_t j = 0; j < arrays.size(); ++j) {
122 inputMatrix[i].emplace_back(arrays[j]->GetVariantValue(i).ToDouble());
126 std::vector<ttk::SimplexId> vec_connectivity{};
127 std::vector<double> diameters{};
129 vtkNew<vtkDoubleArray> diamMin{}, diamMean{}, diamMax{};
130 diamMin->SetName(
"MinDiameter");
131 diamMean->SetName(
"MeanDiameter");
132 diamMax->SetName(
"MaxDiameter");
133 diamMin->SetNumberOfTuples(numberOfRows);
134 diamMean->SetNumberOfTuples(numberOfRows);
135 diamMax->SetNumberOfTuples(numberOfRows);
136 vtkNew<vtkDoubleArray> gaussianDensity{};
137 gaussianDensity->SetName(
"GaussianDensity");
138 gaussianDensity->SetNumberOfTuples(numberOfRows);
141 = this->
execute(vec_connectivity, diameters,
142 std::array<double *const, 3>{
143 ttkUtils::GetPointer<double>(diamMin),
144 ttkUtils::GetPointer<double>(diamMean),
145 ttkUtils::GetPointer<double>(diamMax),
147 inputMatrix, ttkUtils::GetPointer<double>(gaussianDensity));
153 const auto nCells = vec_connectivity.size() / (this->
OutputDimension + 1);
154 vtkNew<ttkSimplexIdTypeArray> offsets{}, connectivity{};
155 offsets->SetNumberOfComponents(1);
156 offsets->SetNumberOfTuples(nCells + 1);
157 connectivity->SetNumberOfComponents(1);
158 connectivity->SetNumberOfTuples(vec_connectivity.size());
160#ifdef TTK_ENABLE_OPENMP
161#pragma omp parallel for num_threads(this->threadNumber_)
163 for(
size_t i = 0; i < nCells + 1; ++i) {
167#ifdef TTK_ENABLE_OPENMP
168#pragma omp parallel for num_threads(this->threadNumber_)
170 for(
size_t i = 0; i < vec_connectivity.size(); ++i) {
171 connectivity->SetTuple1(i, vec_connectivity[i]);
175 vtkNew<vtkCellArray> cells{};
176#ifndef TTK_ENABLE_64BIT_IDS
177 cells->Use32BitStorage();
179 cells->SetData(offsets, connectivity);
181 const auto getCellType = [](
const SimplexId dim) ->
int {
184 }
else if(dim == 2) {
186 }
else if(dim == 1) {
192 output->SetPoints(points);
196 vtkNew<vtkDoubleArray> cellDiameters{};
197 cellDiameters->SetNumberOfTuples(nCells);
198 cellDiameters->SetName(
"Diameter");
200#ifdef TTK_ENABLE_OPENMP
201#pragma omp parallel for num_threads(this->threadNumber_)
203 for(
size_t i = 0; i < nCells; ++i) {
204 cellDiameters->SetTuple1(i, diameters[i]);
207 output->GetPointData()->AddArray(diamMin);
208 output->GetPointData()->AddArray(diamMean);
209 output->GetPointData()->AddArray(diamMax);
211 output->GetPointData()->AddArray(gaussianDensity);
213 output->GetCellData()->AddArray(cellDiameters);
215 if(this->KeepAllDataArrays) {
216 auto pd = output->GetPointData();
218 for(vtkIdType i = 0; i < input->GetNumberOfColumns(); ++i) {
219 pd->AddArray(input->GetColumn(i));
224 this->
printMsg(
"Produced " + std::to_string(nCells) +
" cells of dimension "
226 1.0, tm.getElapsedTime(), this->threadNumber_);