2222
2323#include " itkVertexCell.h"
2424#include " itkLineCell.h"
25+ #include " itkPolyLineCell.h"
2526#include " itkMesh.h"
2627#include " itkTriangleCell.h"
2728#include " itkQuadrilateralCell.h"
@@ -45,6 +46,7 @@ public:
4546
4647 using VertexCellType = itk::VertexCell<CellInterfaceType>;
4748 using LineCellType = itk::LineCell<CellInterfaceType>;
49+ using PolyLineCellType = itk::PolyLineCell<CellInterfaceType>;
4850 using TriangleCellType = itk::TriangleCell<CellInterfaceType>;
4951 using QuadrilateralCellType = itk::QuadrilateralCell<CellInterfaceType>;
5052 using PolygonCellType = itk::PolygonCell<CellInterfaceType>;
@@ -115,9 +117,22 @@ public:
115117 m_Lines->push_back ( numberOfPoints );
116118 const typename LineCellType::PointIdConstIterator pointIdEnd = cell->PointIdsEnd ();
117119 for ( typename LineCellType::PointIdConstIterator pointIdIt = cell->PointIdsBegin (); pointIdIt != pointIdEnd; ++pointIdIt )
118- {
120+ {
119121 m_Lines->push_back ( *pointIdIt );
120- }
122+ }
123+ m_LinesCellIds->push_back ( static_cast < unsigned int >( cellId ) );
124+ }
125+
126+ // Visit a polyline and create a polyline in the output
127+ void Visit (unsigned long cellId, PolyLineCellType* cell)
128+ {
129+ int numberOfPoints = cell->GetNumberOfPoints ();
130+ m_Lines->push_back ( numberOfPoints );
131+ const typename PolyLineCellType::PointIdConstIterator pointIdEnd = cell->PointIdsEnd ();
132+ for ( typename PolyLineCellType::PointIdConstIterator pointIdIt = cell->PointIdsBegin (); pointIdIt != pointIdEnd; ++pointIdIt )
133+ {
134+ m_Lines->push_back ( *pointIdIt );
135+ }
121136 m_LinesCellIds->push_back ( static_cast < unsigned int >( cellId ) );
122137 }
123138
@@ -430,6 +445,8 @@ MeshToPolyDataFilter< TInputMesh >
430445 vertices->reserve ( numberOfCells / 4 + 1 );
431446 typename CellsContainerType::Pointer lines = CellsContainerType::New ();
432447 lines->reserve ( numberOfCells / 4 + 1 );
448+ typename CellsContainerType::Pointer polylines = CellsContainerType::New ();
449+ polylines->reserve ( numberOfCells / 4 + 1 );
433450 typename CellsContainerType::Pointer polygons = CellsContainerType::New ();
434451 polygons->reserve ( numberOfCells / 4 + 1 );
435452 // typename CellsContainerType::Pointer triangleStrips = CellsContainerType::New();
@@ -465,6 +482,21 @@ MeshToPolyDataFilter< TInputMesh >
465482 vertexVisitor->SetPolygonsCellIds ( polygonsCellIds );
466483 // vertexVisitor->SetTriangleStripsCellIds( triangleStripsCellIds );
467484
485+ // Setup the poly line visitor
486+ typedef CellInterfaceVisitorImplementation<
487+ PixelType, CellTraits,
488+ PolyLineCell< CellInterface< PixelType, CellTraits > >,
489+ VisitCellsClass< InputMeshType, PolyDataType > > PolyLineVisitor;
490+ typename PolyLineVisitor::Pointer polyLineVisitor = PolyLineVisitor::New ();
491+ polyLineVisitor->SetVertices ( vertices );
492+ polyLineVisitor->SetLines ( polylines );
493+ polyLineVisitor->SetPolygons ( polygons );
494+ // lineVisitor->SetTriangleStrips( triangleStrips );
495+ polyLineVisitor->SetVerticesCellIds ( verticesCellIds );
496+ polyLineVisitor->SetLinesCellIds ( linesCellIds );
497+ polyLineVisitor->SetPolygonsCellIds ( polygonsCellIds );
498+ // lineVisitor->SetTriangleStripsCellIds( triangleStripsCellIds );
499+
468500 // Setup the line visitor
469501 typedef CellInterfaceVisitorImplementation<
470502 PixelType, CellTraits,
@@ -545,6 +577,7 @@ MeshToPolyDataFilter< TInputMesh >
545577 typename InputMeshType::CellType::MultiVisitor::Pointer multiVisitor = InputMeshType::CellType::MultiVisitor::New ();
546578 multiVisitor->AddVisitor (vertexVisitor.GetPointer ());
547579 multiVisitor->AddVisitor (lineVisitor.GetPointer ());
580+ multiVisitor->AddVisitor (polyLineVisitor.GetPointer ());
548581 multiVisitor->AddVisitor (triangleVisitor.GetPointer ());
549582 multiVisitor->AddVisitor (quadrilateralVisitor.GetPointer ());
550583 multiVisitor->AddVisitor (polygonVisitor.GetPointer ());
@@ -554,14 +587,23 @@ MeshToPolyDataFilter< TInputMesh >
554587 // will Call Visit for each cell in the mesh that matches the
555588 // cell types of the visitors added to the MultiVisitor
556589 if ( numberOfCells )
557- {
590+ {
558591 inputMesh->Accept (multiVisitor);
559- }
592+ }
560593
561594 vertices->shrink_to_fit ();
562595 outputPolyData->SetVertices ( vertices );
596+
597+ // Append lines to polylines before calling SetLines
563598 lines->shrink_to_fit ();
564- outputPolyData->SetLines ( lines );
599+ polylines->shrink_to_fit ();
600+
601+ auto iterator_start_lines = lines->begin ();
602+ auto iterator_end_lines = lines->end ();
603+ auto iterator_end_polylines = polylines->end ();
604+ polylines->insert (iterator_end_polylines, iterator_start_lines, iterator_end_lines);
605+
606+ outputPolyData->SetLines ( polylines);
565607 polygons->shrink_to_fit ();
566608 outputPolyData->SetPolygons ( polygons );
567609 // triangleStrips->shrink_to_fit();
@@ -570,7 +612,7 @@ MeshToPolyDataFilter< TInputMesh >
570612 using CellDataContainerType = typename PolyDataType::CellDataContainer;
571613 const CellDataContainerType * inputCellData = inputMesh->GetCellData ();
572614 if ( inputCellData && inputCellData->Size () )
573- {
615+ {
574616 typename CellDataContainerType::Pointer outputCellData = CellDataContainerType::New ();
575617 outputCellData->Reserve ( inputCellData->Size () );
576618 SizeValueType offset = 0 ;
0 commit comments