/
itkMeshToPolyDataFilter.hxx
657 lines (570 loc) · 24.4 KB
/
itkMeshToPolyDataFilter.hxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef itkMeshToPolyDataFilter_hxx
#define itkMeshToPolyDataFilter_hxx
#include "itkMeshToPolyDataFilter.h"
#include "itkVertexCell.h"
#include "itkLineCell.h"
#include "itkPolyLineCell.h"
#include "itkMesh.h"
#include "itkTriangleCell.h"
#include "itkQuadrilateralCell.h"
#include "itkPolygonCell.h"
#include "itkTetrahedronCell.h"
#include "itkHexahedronCell.h"
namespace
{
template< typename TMesh, typename TPolyData >
class VisitCellsClass
{
public:
using MeshType = TMesh;
using PolyDataType = TPolyData;
// typedef the itk cells we are interested in
using CellInterfaceType = itk::CellInterface< typename MeshType::PixelType, typename MeshType::CellTraits >;
using CellsContainerType = typename TPolyData::CellsContainer;
using VertexCellType = itk::VertexCell<CellInterfaceType>;
using LineCellType = itk::LineCell<CellInterfaceType>;
using PolyLineCellType = itk::PolyLineCell<CellInterfaceType>;
using TriangleCellType = itk::TriangleCell<CellInterfaceType>;
using QuadrilateralCellType = itk::QuadrilateralCell<CellInterfaceType>;
using PolygonCellType = itk::PolygonCell<CellInterfaceType>;
using TetrahedronCellType = itk::TetrahedronCell<CellInterfaceType>;
using HexahedronCellType = itk::HexahedronCell<CellInterfaceType>;
// Set the output polydata vertices container
void SetVertices(CellsContainerType* vertices)
{
m_Vertices = vertices;
}
// Set the output polydata polygons container
void SetLines(CellsContainerType* lines)
{
m_Lines = lines;
}
// Set the output polydata polygons container
void SetPolygons(CellsContainerType* polygons)
{
m_Polygons = polygons;
}
// Set the output polydata triangleStrips container
void SetTriangleStrips(CellsContainerType* triangleStrips)
{
m_TriangleStrips = triangleStrips;
}
// Set the associated input cell id container
void SetVerticesCellIds(CellsContainerType* cellIds)
{
m_VerticesCellIds = cellIds;
}
// Set the associated input cell id container
void SetLinesCellIds(CellsContainerType* cellIds)
{
m_LinesCellIds = cellIds;
}
// Set the associated input cell id container
void SetPolygonsCellIds(CellsContainerType* cellIds)
{
m_PolygonsCellIds = cellIds;
}
// Set the associated input cell id container
void SetTriangleStripsCellIds(CellsContainerType* cellIds)
{
m_TriangleStripsCellIds = cellIds;
}
// Visit a vertex and create a vertex in the output
void Visit(unsigned long cellId, VertexCellType* cell)
{
constexpr unsigned int numberOfPoints = VertexCellType::NumberOfPoints;
m_Vertices->push_back( numberOfPoints );
m_Vertices->push_back( cell->GetPointId() );
m_VerticesCellIds->push_back( static_cast< unsigned int >( cellId ) );
}
// Visit a line and create a line in the output
void Visit(unsigned long cellId, LineCellType* cell)
{
constexpr unsigned int numberOfPoints = LineCellType::NumberOfPoints;
m_Lines->push_back( numberOfPoints );
const typename LineCellType::PointIdConstIterator pointIdEnd = cell->PointIdsEnd();
for( typename LineCellType::PointIdConstIterator pointIdIt = cell->PointIdsBegin(); pointIdIt != pointIdEnd; ++pointIdIt )
{
m_Lines->push_back( *pointIdIt );
}
m_LinesCellIds->push_back( static_cast< unsigned int >( cellId ) );
}
// Visit a polyline and create a polyline in the output
void Visit(unsigned long cellId, PolyLineCellType* cell)
{
int numberOfPoints = cell->GetNumberOfPoints();
m_Lines->push_back( numberOfPoints );
const typename PolyLineCellType::PointIdConstIterator pointIdEnd = cell->PointIdsEnd();
for( typename PolyLineCellType::PointIdConstIterator pointIdIt = cell->PointIdsBegin(); pointIdIt != pointIdEnd; ++pointIdIt )
{
m_Lines->push_back( *pointIdIt );
}
m_LinesCellIds->push_back( static_cast< unsigned int >( cellId ) );
}
// Visit a triangle and create a triangle in the output
void Visit(unsigned long cellId, TriangleCellType* cell)
{
constexpr unsigned int numberOfPoints = TriangleCellType::NumberOfPoints;
m_Polygons->push_back( numberOfPoints );
const typename TriangleCellType::PointIdConstIterator pointIdEnd = cell->PointIdsEnd();
for( typename TriangleCellType::PointIdConstIterator pointIdIt = cell->PointIdsBegin(); pointIdIt != pointIdEnd; ++pointIdIt )
{
m_Polygons->push_back( *pointIdIt );
}
m_PolygonsCellIds->push_back( static_cast< unsigned int >( cellId ) );
}
// Visit a quadrilateral and create a quadrilateral in the output
void Visit(unsigned long cellId, QuadrilateralCellType* cell)
{
constexpr unsigned int numberOfPoints = QuadrilateralCellType::NumberOfPoints;
m_Polygons->push_back( numberOfPoints );
const typename QuadrilateralCellType::PointIdConstIterator pointIdEnd = cell->PointIdsEnd();
for( typename QuadrilateralCellType::PointIdConstIterator pointIdIt = cell->PointIdsBegin(); pointIdIt != pointIdEnd; ++pointIdIt )
{
m_Polygons->push_back( *pointIdIt );
}
m_PolygonsCellIds->push_back( static_cast< unsigned int >( cellId ) );
}
// Visit a polygon and create a polygon in the output
void Visit(unsigned long cellId, PolygonCellType* cell)
{
const unsigned int numberOfPoints = cell->GetNumberOfPoints();
m_Polygons->push_back( numberOfPoints );
const typename PolygonCellType::PointIdConstIterator pointIdEnd = cell->PointIdsEnd();
for( typename PolygonCellType::PointIdConstIterator pointIdIt = cell->PointIdsBegin(); pointIdIt != pointIdEnd; ++pointIdIt )
{
m_Polygons->push_back( *pointIdIt );
}
m_PolygonsCellIds->push_back( static_cast< unsigned int >( cellId ) );
}
//// Visit a tetrahedron and create a tetrahedron in the output
//void Visit(unsigned long, TetrahedronCellType* cell)
//{
//constexpr unsigned int numberOfPoints = TetrahedronCellType::NumberOfPoints;
//constexpr unsigned int numberOfFaces = TetrahedronCellType::NumberOfFaces;
//constexpr unsigned int numberOfEdges = TetrahedronCellType::NumberOfFaces;
//for( unsigned int faceId = 0; faceId < numberOfFaces; ++faceId )
//{
//typename TetrahedronCellType::FaceAutoPointer facePointer;
//cell->GetFace( faceId, facePointer );
//// TODO
////faceIds = vtkIdList::New();
////case VTK_TETRA:
////for (faceId = 0; faceId < 4; faceId++)
////{
////faceIds->Reset();
////faceVerts = vtkTetra::GetFaceArray(faceId);
////faceIds->InsertNextId(pts[faceVerts[0]]);
////faceIds->InsertNextId(pts[faceVerts[1]]);
////faceIds->InsertNextId(pts[faceVerts[2]]);
////numFacePts = 3;
////input->GetCellNeighbors(cellId, faceIds, cellIds);
////if ( cellIds->GetNumberOfIds() <= 0 )
////{
////polys->InsertNextCell(numFacePts);
////for ( int i=0; i < numFacePts; i++)
////{
////polys->InsertCellPoint(pts[faceVerts[i]]);
////}
////polyCellIds.push_back(cellId);
////}
////}
////break;
//}
//}
//// Visit a hexahedron and create a hexahedron in the output
//void Visit(unsigned long, HexahedronCellType* cell)
//{
//// TODO
////case VTK_HEXAHEDRON:
////for (faceId = 0; faceId < 6; faceId++)
////{
////faceIds->Reset();
////faceVerts = vtkHexahedron::GetFaceArray(faceId);
////faceIds->InsertNextId(pts[faceVerts[0]]);
////faceIds->InsertNextId(pts[faceVerts[1]]);
////faceIds->InsertNextId(pts[faceVerts[2]]);
////faceIds->InsertNextId(pts[faceVerts[3]]);
////numFacePts = 4;
////input->GetCellNeighbors(cellId, faceIds, cellIds);
////if ( cellIds->GetNumberOfIds() <= 0 )
////{
////polys->InsertNextCell(numFacePts);
////for ( int i=0; i < numFacePts; i++)
////{
////polys->InsertCellPoint(pts[faceVerts[i]]);
////}
////polyCellIds.push_back(cellId);
////}
////}
////break;
//}
private:
CellsContainerType * m_Vertices;
CellsContainerType * m_Lines;
CellsContainerType * m_Polygons;
CellsContainerType * m_TriangleStrips;
CellsContainerType * m_VerticesCellIds;
CellsContainerType * m_LinesCellIds;
CellsContainerType * m_PolygonsCellIds;
CellsContainerType * m_TriangleStripsCellIds;
};
} // end anonymous namespace
namespace itk
{
template< typename TInputMesh >
MeshToPolyDataFilter< TInputMesh >
::MeshToPolyDataFilter()
{
// Modify superclass default values, can be overridden by subclasses
this->SetNumberOfRequiredInputs(1);
typename PolyDataType::Pointer output =
static_cast< PolyDataType * >( this->MakeOutput(0).GetPointer() );
this->ProcessObject::SetNumberOfRequiredOutputs(1);
this->ProcessObject::SetNthOutput( 0, output.GetPointer() );
}
template< typename TInputMesh >
void
MeshToPolyDataFilter< TInputMesh >
::PrintSelf( std::ostream& os, Indent indent ) const
{
Superclass::PrintSelf( os, indent );
}
template< typename TInputMesh >
void
MeshToPolyDataFilter< TInputMesh >
::SetInput(const TInputMesh *input)
{
// Process object is not const-correct so the const_cast is required here
this->ProcessObject::SetNthInput( 0, const_cast< TInputMesh * >( input ) );
}
template< typename TInputMesh >
const typename MeshToPolyDataFilter< TInputMesh >::InputMeshType *
MeshToPolyDataFilter< TInputMesh >
::GetInput() const
{
return itkDynamicCastInDebugMode< const TInputMesh * >( this->GetPrimaryInput() );
}
template< typename TInputMesh >
const typename MeshToPolyDataFilter< TInputMesh >::InputMeshType *
MeshToPolyDataFilter< TInputMesh >
::GetInput(unsigned int idx) const
{
return dynamic_cast< const TInputMesh * > ( this->ProcessObject::GetInput(idx) );
}
template< typename TInputMesh >
ProcessObject::DataObjectPointer
MeshToPolyDataFilter< TInputMesh >
::MakeOutput(ProcessObject::DataObjectPointerArraySizeType)
{
return PolyDataType::New().GetPointer();
}
template< typename TInputMesh >
ProcessObject::DataObjectPointer
MeshToPolyDataFilter< TInputMesh >
::MakeOutput(const ProcessObject::DataObjectIdentifierType &)
{
return PolyDataType::New().GetPointer();
}
template< typename TInputMesh >
typename MeshToPolyDataFilter< TInputMesh >::PolyDataType *
MeshToPolyDataFilter< TInputMesh >
::GetOutput()
{
// we assume that the first output is of the templated type
return itkDynamicCastInDebugMode< PolyDataType * >( this->GetPrimaryOutput() );
}
template< typename TInputMesh >
const typename MeshToPolyDataFilter< TInputMesh >::PolyDataType *
MeshToPolyDataFilter< TInputMesh >
::GetOutput() const
{
// we assume that the first output is of the templated type
return itkDynamicCastInDebugMode< const PolyDataType * >( this->GetPrimaryOutput() );
}
template< typename TInputMesh >
typename MeshToPolyDataFilter< TInputMesh >::PolyDataType *
MeshToPolyDataFilter< TInputMesh >
::GetOutput(unsigned int idx)
{
auto * out = dynamic_cast< PolyDataType * > ( this->ProcessObject::GetOutput(idx) );
if ( out == nullptr && this->ProcessObject::GetOutput(idx) != nullptr )
{
itkWarningMacro (<< "Unable to convert output number " << idx << " to type " << typeid( PolyDataType ).name () );
}
return out;
}
template< typename TInputMesh >
void
MeshToPolyDataFilter< TInputMesh >
::GenerateData()
{
const InputMeshType * inputMesh = this->GetInput();
PolyDataType * outputPolyData = this->GetOutput();
using MeshPointsContainerType = typename InputMeshType::PointsContainer;
using PolyDataPointsContainerType = typename PolyDataType::PointsContainer;
const MeshPointsContainerType * inputPoints = inputMesh->GetPoints();
typename PolyDataPointsContainerType::Pointer outputPoints = PolyDataPointsContainerType::New();
outputPoints->resize( inputPoints->Size() );
// 2D Mesh -> 3D PolyData, third dimension point locations defaults to 0.0.
typename PolyDataType::PointType nullPoint{ 0.0f };
outputPoints->assign( inputPoints->Size(), nullPoint );
typename MeshPointsContainerType::ConstIterator inputPointItr = inputPoints->Begin();
typename MeshPointsContainerType::ConstIterator inputPointEnd = inputPoints->End();
typename PolyDataPointsContainerType::Iterator outputPointItr = outputPoints->Begin();
while ( inputPointItr != inputPointEnd )
{
for( unsigned int ii = 0; ii < InputMeshType::PointDimension; ++ii )
{
outputPointItr.Value()[ii] = inputPointItr.Value()[ii];
}
++inputPointItr;
++outputPointItr;
}
outputPolyData->SetPoints( outputPoints );
using PointDataContainerType = typename PolyDataType::PointDataContainer;
const PointDataContainerType * inputPointData = inputMesh->GetPointData();
if( inputPointData )
{
typename PointDataContainerType::Pointer outputPointData = PointDataContainerType::New();
outputPointData->Reserve( inputPointData->Size() );
typename PointDataContainerType::ConstIterator inputPointDataItr = inputPointData->Begin();
typename PointDataContainerType::ConstIterator inputPointDataEnd = inputPointData->End();
typename PointDataContainerType::Iterator outputPointDataItr = outputPointData->Begin();
while( inputPointDataItr != inputPointDataEnd )
{
outputPointDataItr.Value() = inputPointDataItr.Value();
++inputPointDataItr;
++outputPointDataItr;
}
outputPolyData->SetPointData( outputPointData );
}
GenerateDataDispatch< TInputMesh >();
}
template< typename TInputMesh >
template < typename TInputMeshDispatch, typename std::enable_if< !HasCellTraits<TInputMeshDispatch>::value, int>::type >
void
MeshToPolyDataFilter< TInputMesh >
::GenerateDataDispatch()
{
// Nothing else to do
}
template< typename TInputMesh >
template < typename TInputMeshDispatch, typename std::enable_if< HasCellTraits<TInputMeshDispatch>::value, int>::type >
void
MeshToPolyDataFilter< TInputMesh >
::GenerateDataDispatch()
{
// Also propagate cells and cell data
const InputMeshType * inputMesh = this->GetInput();
PolyDataType * outputPolyData = this->GetOutput();
const IdentifierType numberOfCells = inputMesh->GetNumberOfCells();
using CellsContainerType = typename PolyDataType::CellsContainer;
typename CellsContainerType::Pointer vertices = CellsContainerType::New();
vertices->reserve( numberOfCells / 4 + 1 );
typename CellsContainerType::Pointer lines = CellsContainerType::New();
lines->reserve( numberOfCells / 4 + 1 );
typename CellsContainerType::Pointer polylines = CellsContainerType::New();
polylines->reserve( numberOfCells / 4 + 1 );
typename CellsContainerType::Pointer polygons = CellsContainerType::New();
polygons->reserve( numberOfCells / 4 + 1 );
//typename CellsContainerType::Pointer triangleStrips = CellsContainerType::New();
//triangleStrips->reserve( numberOfCells / 4 + 1 );
// These store the cell ids of the input that map to the
// new vert/line/poly/strip cells, for copying cell data
// in appropriate order.
typename CellsContainerType::Pointer verticesCellIds = CellsContainerType::New();
verticesCellIds->Reserve( numberOfCells / 4 + 1 );
typename CellsContainerType::Pointer linesCellIds = CellsContainerType::New();
linesCellIds->Reserve( numberOfCells / 4 + 1 );
typename CellsContainerType::Pointer polygonsCellIds = CellsContainerType::New();
polygonsCellIds->Reserve( numberOfCells / 4 + 1 );
//typename CellsContainerType::Pointer triangleStripsCellIds = CellsContainerType::New();
//triangleStripsCellIds->Reserve( numberOfCells / 4 + 1 );
using CellTraits = typename InputMeshType::CellTraits;
using PixelType = typename InputMeshType::PixelType;
// Setup the vertex visitor
typedef CellInterfaceVisitorImplementation<
PixelType, CellTraits,
VertexCell< CellInterface< PixelType, CellTraits > >,
VisitCellsClass< InputMeshType, PolyDataType > > VertexVisitor;
typename VertexVisitor::Pointer vertexVisitor = VertexVisitor::New();
vertexVisitor->SetVertices( vertices );
vertexVisitor->SetLines( lines );
vertexVisitor->SetPolygons( polygons );
//vertexVisitor->SetTriangleStrips( triangleStrips );
vertexVisitor->SetVerticesCellIds( verticesCellIds );
vertexVisitor->SetLinesCellIds( linesCellIds );
vertexVisitor->SetPolygonsCellIds( polygonsCellIds );
//vertexVisitor->SetTriangleStripsCellIds( triangleStripsCellIds );
// Setup the poly line visitor
typedef CellInterfaceVisitorImplementation<
PixelType, CellTraits,
PolyLineCell< CellInterface< PixelType, CellTraits > >,
VisitCellsClass< InputMeshType, PolyDataType > > PolyLineVisitor;
typename PolyLineVisitor::Pointer polyLineVisitor = PolyLineVisitor::New();
polyLineVisitor->SetVertices( vertices );
polyLineVisitor->SetLines( polylines );
polyLineVisitor->SetPolygons( polygons );
//lineVisitor->SetTriangleStrips( triangleStrips );
polyLineVisitor->SetVerticesCellIds( verticesCellIds );
polyLineVisitor->SetLinesCellIds( linesCellIds );
polyLineVisitor->SetPolygonsCellIds( polygonsCellIds );
//lineVisitor->SetTriangleStripsCellIds( triangleStripsCellIds );
// Setup the line visitor
typedef CellInterfaceVisitorImplementation<
PixelType, CellTraits,
LineCell< CellInterface< PixelType, CellTraits > >,
VisitCellsClass< InputMeshType, PolyDataType > > LineVisitor;
typename LineVisitor::Pointer lineVisitor = LineVisitor::New();
lineVisitor->SetVertices( vertices );
lineVisitor->SetLines( lines );
lineVisitor->SetPolygons( polygons );
//lineVisitor->SetTriangleStrips( triangleStrips );
lineVisitor->SetVerticesCellIds( verticesCellIds );
lineVisitor->SetLinesCellIds( linesCellIds );
lineVisitor->SetPolygonsCellIds( polygonsCellIds );
//lineVisitor->SetTriangleStripsCellIds( triangleStripsCellIds );
// Setup the triangle visitor
typedef CellInterfaceVisitorImplementation<
PixelType, CellTraits,
TriangleCell< CellInterface< PixelType, CellTraits > >,
VisitCellsClass< InputMeshType, PolyDataType > > TriangleVisitor;
typename TriangleVisitor::Pointer triangleVisitor = TriangleVisitor::New();
triangleVisitor->SetVertices( vertices );
triangleVisitor->SetLines( lines );
triangleVisitor->SetPolygons( polygons );
//triangleVisitor->SetTriangleStrips( triangleStrips );
triangleVisitor->SetVerticesCellIds( verticesCellIds );
triangleVisitor->SetLinesCellIds( linesCellIds );
triangleVisitor->SetPolygonsCellIds( polygonsCellIds );
//triangleVisitor->SetTriangleStripsCellIds( triangleStripsCellIds );
// Setup the quadrilateral visitor
typedef CellInterfaceVisitorImplementation<
PixelType, CellTraits,
QuadrilateralCell< CellInterface< PixelType, CellTraits > >,
VisitCellsClass< InputMeshType, PolyDataType > > QuadrilateralVisitor;
typename QuadrilateralVisitor::Pointer quadrilateralVisitor = QuadrilateralVisitor::New();
quadrilateralVisitor->SetVertices( vertices );
quadrilateralVisitor->SetLines( lines );
quadrilateralVisitor->SetPolygons( polygons );
//quadrilateralVisitor->SetTriangleStrips( triangleStrips );
quadrilateralVisitor->SetVerticesCellIds( verticesCellIds );
quadrilateralVisitor->SetLinesCellIds( linesCellIds );
quadrilateralVisitor->SetPolygonsCellIds( polygonsCellIds );
//quadrilateralVisitor->SetTriangleStripsCellIds( triangleStripsCellIds );
// Setup the polygon visitor
typedef CellInterfaceVisitorImplementation<
PixelType, CellTraits,
PolygonCell< CellInterface< PixelType, CellTraits > >,
VisitCellsClass< InputMeshType, PolyDataType > > PolygonVisitor;
typename PolygonVisitor::Pointer polygonVisitor = PolygonVisitor::New();
polygonVisitor->SetVertices( vertices );
polygonVisitor->SetLines( lines );
polygonVisitor->SetPolygons( polygons );
//polygonVisitor->SetTriangleStrips( triangleStrips );
polygonVisitor->SetVerticesCellIds( verticesCellIds );
polygonVisitor->SetLinesCellIds( linesCellIds );
polygonVisitor->SetPolygonsCellIds( polygonsCellIds );
//polygonVisitor->SetTriangleStripsCellIds( triangleStripsCellIds );
// TODO
// Setup the tetrahedron visitor
//typedef CellInterfaceVisitorImplementation<
//PixelType, CellTraits,
//TetrahedronCell< CellInterface< PixelType, CellTraits > >,
//VisitCellsClass< InputMeshType, PolyDataType > > TetrahedronVisitor;
//typename TetrahedronVisitor::Pointer tetrahedronVisitor = TetrahedronVisitor::New();
//tetrahedronVisitor->SetVertices( vertices );
//tetrahedronVisitor->SetLines( lines );
//tetrahedronVisitor->SetPolygons( polygons );
//tetrahedronVisitor->SetTriangleStrips( triangleStrips );
//tetrahedronVisitor->SetVerticesCellIds( verticesCellIds );
//tetrahedronVisitor->SetLinesCellIds( linesCellIds );
//tetrahedronVisitor->SettetrahedronsCellIds( tetrahedronsCellIds );
//tetrahedronVisitor->SetTriangleStripsCellIds( triangleStripsCellIds );
typename InputMeshType::CellType::MultiVisitor::Pointer multiVisitor = InputMeshType::CellType::MultiVisitor::New();
multiVisitor->AddVisitor(vertexVisitor.GetPointer());
multiVisitor->AddVisitor(lineVisitor.GetPointer());
multiVisitor->AddVisitor(polyLineVisitor.GetPointer());
multiVisitor->AddVisitor(triangleVisitor.GetPointer());
multiVisitor->AddVisitor(quadrilateralVisitor.GetPointer());
multiVisitor->AddVisitor(polygonVisitor.GetPointer());
//multiVisitor->AddVisitor(tetrahedronVisitor.GetPointer());
// Now ask the mesh to accept the multivisitor which
// will Call Visit for each cell in the mesh that matches the
// cell types of the visitors added to the MultiVisitor
if( numberOfCells )
{
inputMesh->Accept(multiVisitor);
}
vertices->shrink_to_fit();
outputPolyData->SetVertices( vertices );
// Append lines to polylines before calling SetLines
lines->shrink_to_fit();
polylines->shrink_to_fit();
auto iterator_start_lines = lines->begin();
auto iterator_end_lines = lines->end();
auto iterator_end_polylines = polylines->end();
polylines->insert(iterator_end_polylines, iterator_start_lines, iterator_end_lines);
outputPolyData->SetLines( polylines);
polygons->shrink_to_fit();
outputPolyData->SetPolygons( polygons );
//triangleStrips->shrink_to_fit();
//outputPolyData->SetTriangleStrips( triangleStrips );
using CellDataContainerType = typename PolyDataType::CellDataContainer;
const CellDataContainerType * inputCellData = inputMesh->GetCellData();
if( inputCellData && inputCellData->Size() )
{
typename CellDataContainerType::Pointer outputCellData = CellDataContainerType::New();
outputCellData->Reserve( inputCellData->Size() );
SizeValueType offset = 0;
SizeValueType size = verticesCellIds->Size();
// Copy the cell data in appropriate order : verts / lines / polys / strips
for( SizeValueType ii = 0; ii < verticesCellIds->Size(); ++ii )
{
outputCellData->InsertElement( ii,
inputCellData->ElementAt( verticesCellIds->ElementAt( ii ) ) );
}
offset += size;
size = linesCellIds->Size();
for( SizeValueType ii = 0; ii < size; ++ii )
{
outputCellData->InsertElement( offset + ii,
inputCellData->ElementAt( linesCellIds->ElementAt( ii ) ) );
}
offset += size;
size = polygonsCellIds->Size();
for( SizeValueType ii = 0; ii < size; ++ii )
{
outputCellData->InsertElement( offset + ii,
inputCellData->ElementAt( polygonsCellIds->ElementAt( ii ) ) );
}
offset += size;
//size = triangleStripsCellIds->Size();
//for( SizeValueType ii = 0; ii < size; ++ii )
//{
//outputCellData->InsertElement( offset + ii,
//inputCellData->ElementAt( triangleStripsCellIds->ElementAt( ii ) ) );
//}
outputPolyData->SetCellData( outputCellData );
}
}
} // end namespace itk
#endif // itkMeshToPolyDataFilter_hxx