1 #include <cpExtensions/Visualization/SkeletonToPolyData.h>
3 #include <vtkCellArray.h>
4 #include <vtkInformation.h>
5 #include <vtkInformationVector.h>
6 #include <vtkSmartPointer.h>
8 // -------------------------------------------------------------------------
9 template< class _TSkeleton >
10 typename cpExtensions::Visualization::SkeletonToPolyData< _TSkeleton >::
11 Self* cpExtensions::Visualization::SkeletonToPolyData< _TSkeleton >::
14 return( new Self( ) );
17 // -------------------------------------------------------------------------
18 template< class _TSkeleton >
20 cpExtensions::Visualization::SkeletonToPolyData< _TSkeleton >::
21 TSkeleton* cpExtensions::Visualization::SkeletonToPolyData< _TSkeleton >::
24 return( this->m_Skeleton );
27 // -------------------------------------------------------------------------
28 template< class _TSkeleton >
29 void cpExtensions::Visualization::SkeletonToPolyData< _TSkeleton >::
30 SetInput( const TSkeleton* sk )
32 if( this->m_Skeleton != sk )
34 this->m_Skeleton = sk;
40 // -------------------------------------------------------------------------
41 template< class _TSkeleton >
42 cpExtensions::Visualization::SkeletonToPolyData< _TSkeleton >::
44 : vtkPolyDataAlgorithm( ),
47 this->SetNumberOfInputPorts( 0 );
50 // -------------------------------------------------------------------------
51 template< class _TSkeleton >
52 cpExtensions::Visualization::SkeletonToPolyData< _TSkeleton >::
53 ~SkeletonToPolyData( )
57 // -------------------------------------------------------------------------
58 template< class _TSkeleton >
59 int cpExtensions::Visualization::SkeletonToPolyData< _TSkeleton >::
61 vtkInformation* information,
62 vtkInformationVector** input,
63 vtkInformationVector* output
66 typedef typename _TSkeleton::TPath _TPath;
67 static const unsigned int dim = _TPath::PathDimension;
69 if( this->m_Skeleton == NULL )
73 vtkInformation* info = output->GetInformationObject( 0 );
74 vtkPolyData* out = vtkPolyData::SafeDownCast(
75 info->Get( vtkDataObject::DATA_OBJECT( ) )
79 out->SetPoints( vtkSmartPointer< vtkPoints >::New( ) );
80 out->SetVerts( vtkSmartPointer< vtkCellArray >::New( ) );
81 out->SetLines( vtkSmartPointer< vtkCellArray >::New( ) );
82 out->SetPolys( vtkSmartPointer< vtkCellArray >::New( ) );
83 out->SetStrips( vtkSmartPointer< vtkCellArray >::New( ) );
84 vtkPoints* points = out->GetPoints( );
85 vtkCellArray* lines = out->GetLines( );
88 auto mIt = this->m_Skeleton->BeginEdgesRows( );
89 for( ; mIt != this->m_Skeleton->EndEdgesRows( ); ++mIt )
91 // TODO: mIt->first; --> this is the row index. <--
92 auto rIt = mIt->second.begin( );
93 for( ; rIt != mIt->second.end( ); ++rIt )
95 // TODO: rIt->first; --> this is the column index.
96 auto eIt = rIt->second.begin( );
97 for( ; eIt != rIt->second.end( ); ++eIt )
100 for( unsigned long i = 0; i < path->GetSize( ); ++i )
102 auto pnt = path->GetPoint( i );
104 points->InsertNextPoint( pnt[ 0 ], 0, 0 );
106 points->InsertNextPoint( pnt[ 0 ], pnt[ 1 ], 0 );
108 points->InsertNextPoint( pnt[ 0 ], pnt[ 1 ], pnt[ 2 ] );
111 lines->InsertNextCell( 2 );
112 lines->InsertCellPoint( points->GetNumberOfPoints( ) - 2 );
113 lines->InsertCellPoint( points->GetNumberOfPoints( ) - 1 );
127 // -------------------------------------------------------------------------
128 template< class _TSkeleton >
129 int cpExtensions::Visualization::SkeletonToPolyData< _TSkeleton >::
131 vtkInformation* information,
132 vtkInformationVector** input,
133 vtkInformationVector* output
139 // -------------------------------------------------------------------------
140 #include <cpExtensions/DataStructures/Skeleton.h>
142 template class cpExtensions::Visualization::SkeletonToPolyData< cpExtensions::DataStructures::Skeleton< 1 > >;
143 template class cpExtensions::Visualization::SkeletonToPolyData< cpExtensions::DataStructures::Skeleton< 2 > >;
144 template class cpExtensions::Visualization::SkeletonToPolyData< cpExtensions::DataStructures::Skeleton< 3 > >;
145 template class cpExtensions::Visualization::SkeletonToPolyData< cpExtensions::DataStructures::Skeleton< 4 > >;