15
15
16
16
#include < vtkAppendFilter.h>
17
17
#include < vtkCellData.h>
18
- #include < vtkDataSet.h>
19
18
#include < vtkDataSetAttributes.h>
19
+ #include < vtkDataSet.h>
20
20
#include < vtkIdList.h>
21
+ #include < vtkIdTypeArray.h>
21
22
#include < vtkIntArray.h>
22
23
#include < vtkMath.h>
23
24
#include < vtkNew.h>
26
27
#include < vtkSmartPointer.h>
27
28
#include < vtkUnstructuredGrid.h>
28
29
30
+ #include < numeric> // for iota
31
+
29
32
// ////////////////////////////////////////////////////////////////////////////
30
33
namespace {
31
34
@@ -111,6 +114,29 @@ void CreateDataset(vtkPolyData* dataset,
111
114
}
112
115
113
116
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
+ }
114
140
}
115
141
116
142
// ////////////////////////////////////////////////////////////////////////////
@@ -135,10 +161,9 @@ int strcmp_null(const char* s1, const char* s2)
135
161
// ////////////////////////////////////////////////////////////////////////////
136
162
// Prints and checks point/cell data
137
163
// ////////////////////////////////////////////////////////////////////////////
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)
140
165
{
141
- vtkDataSetAttributes* dataArrays = selector ( output);
166
+ vtkDataSetAttributes* dataArrays = output-> GetAttributes (fieldType );
142
167
std::cout << " Evaluating '" << dataArrays->GetClassName () << " '\n " ;
143
168
144
169
for (int arrayIndex = 0 ; arrayIndex < dataArrays->GetNumberOfArrays (); ++arrayIndex)
@@ -180,7 +205,7 @@ int PrintAndCheck(const std::vector<vtkPolyData*>& inputs, vtkDataSet* output,
180
205
vtkIdType numInputTuples = 0 ;
181
206
for (size_t inputIndex = 0 ; inputIndex < inputs.size (); ++inputIndex)
182
207
{
183
- vtkDataArray* array = selector ( inputs[inputIndex])->GetArray (arrayName);
208
+ vtkDataArray* array = inputs[inputIndex]-> GetAttributes (fieldType )->GetArray (arrayName);
184
209
if (!array)
185
210
{
186
211
std::cerr << " No array named '" << arrayName << " ' in input " << inputIndex << " \n " ;
@@ -198,7 +223,7 @@ int PrintAndCheck(const std::vector<vtkPolyData*>& inputs, vtkDataSet* output,
198
223
vtkIdType offset = 0 ;
199
224
for (size_t inputIndex = 0 ; inputIndex < inputs.size (); ++inputIndex)
200
225
{
201
- vtkDataArray* array = selector ( inputs[inputIndex])->GetArray (arrayName);
226
+ vtkDataArray* array = inputs[inputIndex]-> GetAttributes (fieldType )->GetArray (arrayName);
202
227
for (int i = 0 ; i < array->GetNumberOfTuples (); ++i)
203
228
{
204
229
for (int j = 0 ; j < array->GetNumberOfComponents (); ++j)
@@ -233,7 +258,7 @@ int PrintAndCheck(const std::vector<vtkPolyData*>& inputs, vtkDataSet* output,
233
258
for (size_t inputIndex = 0 ; inputIndex < inputs.size (); ++inputIndex)
234
259
{
235
260
vtkAbstractArray* inputAttributeArray =
236
- selector ( inputs[inputIndex])->GetAbstractAttribute (attributeIndex);
261
+ inputs[inputIndex]-> GetAttributes (fieldType )->GetAbstractAttribute (attributeIndex);
237
262
238
263
if (outputAttributeArray && !inputAttributeArray)
239
264
{
@@ -258,7 +283,7 @@ int PrintAndCheck(const std::vector<vtkPolyData*>& inputs, vtkDataSet* output,
258
283
for (size_t inputIndex = 0 ; inputIndex < inputs.size (); ++inputIndex)
259
284
{
260
285
vtkAbstractArray* inputAttributeArray =
261
- selector ( inputs[inputIndex])->GetAbstractAttribute (attributeIndex);
286
+ inputs[inputIndex]-> GetAttributes (fieldType )->GetAbstractAttribute (attributeIndex);
262
287
if (!inputAttributeArray)
263
288
{
264
289
allInputsHaveAttribute = false ;
@@ -268,11 +293,11 @@ int PrintAndCheck(const std::vector<vtkPolyData*>& inputs, vtkDataSet* output,
268
293
if (allInputsHaveAttribute)
269
294
{
270
295
vtkAbstractArray* firstAttributeArray =
271
- selector ( inputs[0 ])->GetAbstractAttribute (attributeIndex);
296
+ inputs[0 ]-> GetAttributes (fieldType )->GetAbstractAttribute (attributeIndex);
272
297
for (size_t inputIndex = 1 ; inputIndex < inputs.size (); ++inputIndex)
273
298
{
274
299
vtkAbstractArray* inputAttributeArray =
275
- selector ( inputs[inputIndex])->GetAbstractAttribute (attributeIndex);
300
+ inputs[inputIndex]-> GetAttributes (fieldType )->GetAbstractAttribute (attributeIndex);
276
301
if (strcmp_null (firstAttributeArray->GetName (), inputAttributeArray->GetName ()) != 0 )
277
302
{
278
303
allInputsHaveSameName = false ;
@@ -284,7 +309,7 @@ int PrintAndCheck(const std::vector<vtkPolyData*>& inputs, vtkDataSet* output,
284
309
if (allInputsHaveAttribute && allInputsHaveSameName)
285
310
{
286
311
const char * attributeArrayName =
287
- selector ( inputs[0 ])->GetAbstractAttribute (attributeIndex)->GetName ();
312
+ inputs[0 ]-> GetAttributes (fieldType )->GetAbstractAttribute (attributeIndex)->GetName ();
288
313
if (!outputAttributeArray)
289
314
{
290
315
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,
306
331
vtkIdType offset = 0 ;
307
332
for (size_t inputIndex = 0 ; inputIndex < inputs.size (); ++inputIndex)
308
333
{
309
- vtkDataArray* attributeArray = selector ( inputs[inputIndex])->GetAttribute (attributeIndex);
334
+ vtkDataArray* attributeArray = inputs[inputIndex]-> GetAttributes (fieldType )->GetAttribute (attributeIndex);
310
335
if (!attributeArray)
311
336
{
312
337
continue ;
@@ -332,30 +357,6 @@ int PrintAndCheck(const std::vector<vtkPolyData*>& inputs, vtkDataSet* output,
332
357
return 1 ;
333
358
}
334
359
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
-
359
360
// ////////////////////////////////////////////////////////////////////////////
360
361
// Returns 1 on success, 0 otherwise
361
362
// ////////////////////////////////////////////////////////////////////////////
@@ -379,6 +380,17 @@ int AppendDatasetsAndCheckMergedArrayLengths(vtkAppendFilter* append)
379
380
return 0 ;
380
381
}
381
382
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
+
382
394
return 1 ;
383
395
}
384
396
@@ -395,12 +407,24 @@ int AppendDatasetsAndPrint(const std::vector<vtkPolyData*>& inputs)
395
407
append->Update ();
396
408
vtkUnstructuredGrid * output = append->GetOutput ();
397
409
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 )
399
420
{
421
+ std::cerr << " Point global ids should have been preserved!\n " ;
400
422
return 0 ;
401
423
}
402
- if (!PrintAndCheck (inputs, output, CellDataSelector))
424
+
425
+ if (output->GetCellData ()->GetGlobalIds () == nullptr )
403
426
{
427
+ std::cerr << " Cell global ids should have been preserved!\n " ;
404
428
return 0 ;
405
429
}
406
430
0 commit comments