52 vtkInformationVector **inputVector,
53 vtkInformationVector *outputVector) {
54 const auto input = vtkPointSet::GetData(inputVector[0]);
55 auto output = vtkPolyData::GetData(outputVector);
57 if(input ==
nullptr || output ==
nullptr) {
58 this->
printErr(
"Null input data, aborting");
61 const auto oa = this->GetInputArrayToProcess(0, inputVector);
62 const auto oa2 = this->GetInputArrayToProcess(1, inputVector);
64 this->
printErr(
"Cannot find the required data X array");
68 this->
printErr(
"Cannot find the required data Y array");
72 const auto nvalues = oa->GetNumberOfTuples();
75 std::vector<std::tuple<vtkIdType, double, double>> orderedValues;
77#ifndef TTK_ENABLE_DOUBLE_TEMPLATING
78 switch(oa->GetDataType()) {
84 switch(vtkTemplate2PackMacro(oa->GetDataType(), oa2->GetDataType())) {
92 std::vector<double> xValues(orderedValues.size()),
93 yValues(orderedValues.size());
94 for(
unsigned int i = 0; i < orderedValues.size(); ++i) {
95 auto tup = orderedValues[i];
96 xValues[i] = std::get<1>(tup);
97 yValues[i] = std::get<2>(tup);
100 const auto nUniqueXValues
101 = std::unique(xValues.begin(), xValues.end()) - xValues.begin();
103 const auto nUniqueYValues
104 = std::unique(yValues.begin(), yValues.end()) - yValues.begin();
106 if(nUniqueXValues * nUniqueYValues != input->GetNumberOfPoints()) {
108 "Number of unique values in first array times the number of unique "
109 "values in the second one does not equal the number of points");
114 double yRange[2] = {*std::min_element(yValues.begin(), yValues.end()),
115 *std::max_element(yValues.begin(), yValues.end())};
116 double minXInterval = std::numeric_limits<double>::max();
117 for(
unsigned int i = 1; i < nUniqueXValues; ++i)
118 minXInterval = std::min(minXInterval, xValues[i] - xValues[i - 1]);
119 const auto normValue = [&](
double v) {
120 return (v - yRange[0]) / (yRange[1] - yRange[0]) * minXInterval * 0.99;
122 const auto cmp = [&](
const std::tuple<int, double, double> &a,
123 const std::tuple<int, double, double> &b) {
124 return std::get<1>(a) + normValue(std::get<2>(a))
125 < std::get<1>(b) + normValue(std::get<2>(b));
130 this->
threadNumber_, orderedValues.begin(), orderedValues.end(), cmp);
133 std::vector<std::vector<vtkIdType>> orderedIds(
134 nUniqueXValues, std::vector<vtkIdType>(nUniqueYValues));
135 for(
unsigned int i = 0; i < nUniqueXValues; ++i) {
136 for(
unsigned int j = 0; j < nUniqueYValues; ++j) {
137 auto index = i * nUniqueYValues + j;
138 orderedIds[i][j] = std::get<0>(orderedValues[index]);
143 vtkNew<vtkPolyData> vtkOutput{};
144 vtkOutput->DeepCopy(input);
145 auto numberOfCells = (nUniqueXValues - 1) * nUniqueYValues
146 + nUniqueXValues * (nUniqueYValues - 1)
147 + (nUniqueXValues - 1) * (nUniqueYValues - 1);
148 vtkOutput->Allocate(numberOfCells);
150 for(
unsigned int i = 0; i < nUniqueXValues; ++i) {
151 for(
unsigned int j = 0; j < nUniqueYValues; ++j) {
153 std::array<vtkIdType, 2> linePoints{
154 orderedIds[i][j - 1], orderedIds[i][j]};
155 vtkOutput->InsertNextCell(VTK_LINE, 2, linePoints.data());
159 std::array<vtkIdType, 2> linePoints{
160 orderedIds[i - 1][j], orderedIds[i][j]};
161 vtkOutput->InsertNextCell(VTK_LINE, 2, linePoints.data());
164 if(i != 0 and j != 0) {
165 std::array<vtkIdType, 4> cellPoints{
166 orderedIds[i - 1][j - 1], orderedIds[i - 1][j], orderedIds[i][j],
167 orderedIds[i][j - 1]};
168 vtkOutput->InsertNextCell(VTK_QUAD, 4, cellPoints.data());
173 auto noCells = vtkOutput->GetNumberOfCells();
174 vtkNew<vtkIntArray> cellTypeArray{};
175 cellTypeArray->SetName(
"CellType");
176 cellTypeArray->SetNumberOfTuples(noCells);
177 for(
int i = 0; i < noCells; ++i) {
178 cellTypeArray->SetTuple1(i, vtkOutput->GetCellType(i));
180 vtkOutput->GetCellData()->AddArray(cellTypeArray);
182 output->ShallowCopy(vtkOutput);