Skip to content

Commit 3371584

Browse files
utkarshayachitkwrobot
authored andcommittedDec 20, 2018
Merge topic 'append-filters-preserve-global-ids'
dd5e5d3 extend TestAppendFilter to check for global ids ae5d870 make append filters preserve global ids. Acked-by: Kitware Robot <[email protected]> Acked-by: David E. DeMarle <[email protected]> Acked-by: Bill Lorensen <[email protected]> Merge-request: !5008
2 parents a998a79 + dd5e5d3 commit 3371584

File tree

3 files changed

+75
-38
lines changed

3 files changed

+75
-38
lines changed
 

‎Filters/Core/Testing/Cxx/TestAppendFilter.cxx

+62-38
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515

1616
#include <vtkAppendFilter.h>
1717
#include <vtkCellData.h>
18-
#include <vtkDataSet.h>
1918
#include <vtkDataSetAttributes.h>
19+
#include <vtkDataSet.h>
2020
#include <vtkIdList.h>
21+
#include <vtkIdTypeArray.h>
2122
#include <vtkIntArray.h>
2223
#include <vtkMath.h>
2324
#include <vtkNew.h>
@@ -26,6 +27,8 @@
2627
#include <vtkSmartPointer.h>
2728
#include <vtkUnstructuredGrid.h>
2829

30+
#include <numeric> // for iota
31+
2932
//////////////////////////////////////////////////////////////////////////////
3033
namespace {
3134

@@ -111,6 +114,29 @@ void CreateDataset(vtkPolyData* dataset,
111114
}
112115

113116
dataset->SetPoints( points );
117+
118+
// Add global point and cell ids.
119+
static int next_point_gid = 0;
120+
if (auto nodeids = vtkSmartPointer<vtkIntArray>::New())
121+
{
122+
nodeids->SetName("GlobalNodeIds");
123+
nodeids->SetNumberOfTuples(numberOfPoints);
124+
std::iota(nodeids->GetPointer(0), nodeids->GetPointer(0) + numberOfPoints, next_point_gid);
125+
dataset->GetPointData()->SetGlobalIds(nodeids);
126+
127+
next_point_gid += numberOfPoints;
128+
}
129+
130+
static int next_cell_gid = 0;
131+
if (auto elementids = vtkSmartPointer<vtkIntArray>::New())
132+
{
133+
elementids->SetName("GlobalElementIds");
134+
elementids->SetNumberOfTuples(numberOfCells);
135+
std::iota(elementids->GetPointer(0), elementids->GetPointer(0) + numberOfCells, next_cell_gid);
136+
dataset->GetCellData()->SetGlobalIds(elementids);
137+
138+
next_cell_gid += numberOfCells;
139+
}
114140
}
115141

116142
//////////////////////////////////////////////////////////////////////////////
@@ -135,10 +161,9 @@ int strcmp_null(const char* s1, const char* s2)
135161
//////////////////////////////////////////////////////////////////////////////
136162
// Prints and checks point/cell data
137163
//////////////////////////////////////////////////////////////////////////////
138-
int PrintAndCheck(const std::vector<vtkPolyData*>& inputs, vtkDataSet* output,
139-
vtkDataSetAttributes*(*selector)(vtkDataSet*))
164+
int PrintAndCheck(const std::vector<vtkPolyData*>& inputs, vtkDataSet* output, int fieldType)
140165
{
141-
vtkDataSetAttributes* dataArrays = selector(output);
166+
vtkDataSetAttributes* dataArrays = output->GetAttributes(fieldType);
142167
std::cout << "Evaluating '" << dataArrays->GetClassName() << "'\n";
143168

144169
for (int arrayIndex = 0; arrayIndex < dataArrays->GetNumberOfArrays(); ++arrayIndex)
@@ -180,7 +205,7 @@ int PrintAndCheck(const std::vector<vtkPolyData*>& inputs, vtkDataSet* output,
180205
vtkIdType numInputTuples = 0;
181206
for (size_t inputIndex = 0; inputIndex < inputs.size(); ++inputIndex)
182207
{
183-
vtkDataArray* array = selector(inputs[inputIndex])->GetArray(arrayName);
208+
vtkDataArray* array = inputs[inputIndex]->GetAttributes(fieldType)->GetArray(arrayName);
184209
if (!array)
185210
{
186211
std::cerr << "No array named '" << arrayName << "' in input " << inputIndex << "\n";
@@ -198,7 +223,7 @@ int PrintAndCheck(const std::vector<vtkPolyData*>& inputs, vtkDataSet* output,
198223
vtkIdType offset = 0;
199224
for (size_t inputIndex = 0; inputIndex < inputs.size(); ++inputIndex)
200225
{
201-
vtkDataArray* array = selector(inputs[inputIndex])->GetArray(arrayName);
226+
vtkDataArray* array = inputs[inputIndex]->GetAttributes(fieldType)->GetArray(arrayName);
202227
for (int i = 0; i < array->GetNumberOfTuples(); ++i)
203228
{
204229
for (int j = 0; j < array->GetNumberOfComponents(); ++j)
@@ -233,7 +258,7 @@ int PrintAndCheck(const std::vector<vtkPolyData*>& inputs, vtkDataSet* output,
233258
for (size_t inputIndex = 0; inputIndex < inputs.size(); ++inputIndex)
234259
{
235260
vtkAbstractArray* inputAttributeArray =
236-
selector(inputs[inputIndex])->GetAbstractAttribute(attributeIndex);
261+
inputs[inputIndex]->GetAttributes(fieldType)->GetAbstractAttribute(attributeIndex);
237262

238263
if (outputAttributeArray && !inputAttributeArray)
239264
{
@@ -258,7 +283,7 @@ int PrintAndCheck(const std::vector<vtkPolyData*>& inputs, vtkDataSet* output,
258283
for (size_t inputIndex = 0; inputIndex < inputs.size(); ++inputIndex)
259284
{
260285
vtkAbstractArray* inputAttributeArray =
261-
selector(inputs[inputIndex])->GetAbstractAttribute(attributeIndex);
286+
inputs[inputIndex]->GetAttributes(fieldType)->GetAbstractAttribute(attributeIndex);
262287
if (!inputAttributeArray)
263288
{
264289
allInputsHaveAttribute = false;
@@ -268,11 +293,11 @@ int PrintAndCheck(const std::vector<vtkPolyData*>& inputs, vtkDataSet* output,
268293
if (allInputsHaveAttribute)
269294
{
270295
vtkAbstractArray* firstAttributeArray =
271-
selector(inputs[0])->GetAbstractAttribute(attributeIndex);
296+
inputs[0]->GetAttributes(fieldType)->GetAbstractAttribute(attributeIndex);
272297
for (size_t inputIndex = 1; inputIndex < inputs.size(); ++inputIndex)
273298
{
274299
vtkAbstractArray* inputAttributeArray =
275-
selector(inputs[inputIndex])->GetAbstractAttribute(attributeIndex);
300+
inputs[inputIndex]->GetAttributes(fieldType)->GetAbstractAttribute(attributeIndex);
276301
if (strcmp_null(firstAttributeArray->GetName(), inputAttributeArray->GetName()) != 0)
277302
{
278303
allInputsHaveSameName = false;
@@ -284,7 +309,7 @@ int PrintAndCheck(const std::vector<vtkPolyData*>& inputs, vtkDataSet* output,
284309
if (allInputsHaveAttribute && allInputsHaveSameName)
285310
{
286311
const char* attributeArrayName =
287-
selector(inputs[0])->GetAbstractAttribute(attributeIndex)->GetName();
312+
inputs[0]->GetAttributes(fieldType)->GetAbstractAttribute(attributeIndex)->GetName();
288313
if (!outputAttributeArray)
289314
{
290315
std::cerr << "Inputs all have the attribute '" << attributeName << "' set to the name '"
@@ -306,7 +331,7 @@ int PrintAndCheck(const std::vector<vtkPolyData*>& inputs, vtkDataSet* output,
306331
vtkIdType offset = 0;
307332
for (size_t inputIndex = 0; inputIndex < inputs.size(); ++inputIndex)
308333
{
309-
vtkDataArray* attributeArray = selector(inputs[inputIndex])->GetAttribute(attributeIndex);
334+
vtkDataArray* attributeArray = inputs[inputIndex]->GetAttributes(fieldType)->GetAttribute(attributeIndex);
310335
if (!attributeArray)
311336
{
312337
continue;
@@ -332,30 +357,6 @@ int PrintAndCheck(const std::vector<vtkPolyData*>& inputs, vtkDataSet* output,
332357
return 1;
333358
}
334359

335-
336-
//////////////////////////////////////////////////////////////////////////////
337-
// Selectors for point and cell data
338-
//////////////////////////////////////////////////////////////////////////////
339-
vtkDataSetAttributes* PointDataSelector(vtkDataSet* ds)
340-
{
341-
if (ds)
342-
{
343-
return ds->GetPointData();
344-
}
345-
346-
return nullptr;
347-
}
348-
349-
vtkDataSetAttributes* CellDataSelector(vtkDataSet* ds)
350-
{
351-
if (ds)
352-
{
353-
return ds->GetCellData();
354-
}
355-
356-
return nullptr;
357-
}
358-
359360
//////////////////////////////////////////////////////////////////////////////
360361
// Returns 1 on success, 0 otherwise
361362
//////////////////////////////////////////////////////////////////////////////
@@ -379,6 +380,17 @@ int AppendDatasetsAndCheckMergedArrayLengths(vtkAppendFilter* append)
379380
return 0;
380381
}
381382

383+
if (output->GetPointData()->GetGlobalIds() != nullptr)
384+
{
385+
std::cerr << "Point global ids should have been discarded after merge!\n";
386+
return 0;
387+
}
388+
if (output->GetCellData()->GetGlobalIds() == nullptr)
389+
{
390+
std::cerr << "Cell global ids should have been preserved after merge!\n";
391+
return 0;
392+
}
393+
382394
return 1;
383395
}
384396

@@ -395,12 +407,24 @@ int AppendDatasetsAndPrint(const std::vector<vtkPolyData*>& inputs)
395407
append->Update();
396408
vtkUnstructuredGrid * output = append->GetOutput();
397409

398-
if (!PrintAndCheck(inputs, output, PointDataSelector))
410+
if (!PrintAndCheck(inputs, output, vtkDataObject::POINT))
411+
{
412+
return 0;
413+
}
414+
if (!PrintAndCheck(inputs, output, vtkDataObject::CELL))
415+
{
416+
return 0;
417+
}
418+
419+
if (output->GetPointData()->GetGlobalIds() == nullptr)
399420
{
421+
std::cerr << "Point global ids should have been preserved!\n";
400422
return 0;
401423
}
402-
if (!PrintAndCheck(inputs, output, CellDataSelector))
424+
425+
if (output->GetCellData()->GetGlobalIds() == nullptr)
403426
{
427+
std::cerr << "Cell global ids should have been preserved!\n";
404428
return 0;
405429
}
406430

‎Filters/Core/vtkAppendFilter.cxx

+8
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,14 @@ int vtkAppendFilter::RequestData(
332332
ptOffset += dataSetNumPts;
333333
}
334334

335+
// this filter can copy global ids except for global point ids when merging
336+
// points (see paraview/paraview#18666).
337+
// Note, not copying global ids is the default behavior.
338+
if (reallyMergePoints == false)
339+
{
340+
output->GetPointData()->CopyAllOn(vtkDataSetAttributes::COPYTUPLE);
341+
}
342+
output->GetCellData()->CopyAllOn(vtkDataSetAttributes::COPYTUPLE);
335343

336344
// Now copy the array data
337345
this->AppendArrays(

‎Filters/Core/vtkAppendPolyData.cxx

+5
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,11 @@ int vtkAppendPolyData::ExecuteAppend(vtkPolyData* output,
331331
return 0;
332332
}
333333

334+
// Since points are cells are not merged,
335+
// this filter can easily pass all field arrays, including global ids.
336+
outputPD->CopyAllOn(vtkDataSetAttributes::COPYTUPLE);
337+
outputCD->CopyAllOn(vtkDataSetAttributes::COPYTUPLE);
338+
334339
// Allocate the point and cell data
335340
outputPD->CopyAllocate(ptList,numPts);
336341
outputCD->CopyAllocate(cellList,numCells);

0 commit comments

Comments
 (0)
Please sign in to comment.