1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
6 #ifndef __fpa__Image__SkeletonToPolyDataFilter__hxx__
7 #define __fpa__Image__SkeletonToPolyDataFilter__hxx__
9 #include <vtkCellArray.h>
10 #include <vtkInformation.h>
11 #include <vtkInformationVector.h>
12 #include <vtkSmartPointer.h>
14 // -------------------------------------------------------------------------
15 template< class _TSkeleton >
16 typename fpa::Image::SkeletonToPolyDataFilter< _TSkeleton >::
17 Self* fpa::Image::SkeletonToPolyDataFilter< _TSkeleton >::
20 return( new Self( ) );
23 // -------------------------------------------------------------------------
24 template< class _TSkeleton >
26 fpa::Image::SkeletonToPolyDataFilter< _TSkeleton >::
27 TSkeleton* fpa::Image::SkeletonToPolyDataFilter< _TSkeleton >::
30 return( this->m_Skeleton );
33 // -------------------------------------------------------------------------
34 template< class _TSkeleton >
35 void fpa::Image::SkeletonToPolyDataFilter< _TSkeleton >::
36 SetInput( const TSkeleton* sk )
38 if( this->m_Skeleton != sk )
40 this->m_Skeleton = sk;
46 // -------------------------------------------------------------------------
47 template< class _TSkeleton >
48 fpa::Image::SkeletonToPolyDataFilter< _TSkeleton >::
49 SkeletonToPolyDataFilter( )
50 : vtkPolyDataAlgorithm( ),
53 this->SetNumberOfInputPorts( 0 );
56 // -------------------------------------------------------------------------
57 template< class _TSkeleton >
58 fpa::Image::SkeletonToPolyDataFilter< _TSkeleton >::
59 ~SkeletonToPolyDataFilter( )
63 // -------------------------------------------------------------------------
64 template< class _TSkeleton >
65 int fpa::Image::SkeletonToPolyDataFilter< _TSkeleton >::
67 vtkInformation* information,
68 vtkInformationVector** input,
69 vtkInformationVector* output
72 typedef typename _TSkeleton::TPath _TPath;
73 static const unsigned int dim = _TPath::PathDimension;
75 if( this->m_Skeleton == NULL )
79 vtkInformation* info = output->GetInformationObject( 0 );
80 vtkPolyData* out = vtkPolyData::SafeDownCast(
81 info->Get( vtkDataObject::DATA_OBJECT( ) )
85 out->SetPoints( vtkSmartPointer< vtkPoints >::New( ) );
86 out->SetVerts( vtkSmartPointer< vtkCellArray >::New( ) );
87 out->SetLines( vtkSmartPointer< vtkCellArray >::New( ) );
88 out->SetPolys( vtkSmartPointer< vtkCellArray >::New( ) );
89 out->SetStrips( vtkSmartPointer< vtkCellArray >::New( ) );
90 vtkPoints* points = out->GetPoints( );
91 vtkCellArray* lines = out->GetLines( );
94 typename TMatrix::const_iterator mIt = this->m_Skeleton->BeginEdgesRows( );
95 for( ; mIt != this->m_Skeleton->EndEdgesRows( ); ++mIt )
97 // TODO: mIt->first; --> this is the row index. <--
98 typename TMatrixRow::const_iterator rIt = mIt->second.begin( );
99 for( ; rIt != mIt->second.end( ); ++rIt )
101 // TODO: rIt->first; --> this is the column index.
102 typename TEdges::const_iterator eIt = rIt->second.begin( );
103 for( ; eIt != rIt->second.end( ); ++eIt )
106 for( unsigned long i = 0; i < path->GetSize( ); ++i )
108 auto pnt = path->GetPoint( i );
110 points->InsertNextPoint( pnt[ 0 ], 0, 0 );
112 points->InsertNextPoint( pnt[ 0 ], pnt[ 1 ], 0 );
114 points->InsertNextPoint( pnt[ 0 ], pnt[ 1 ], pnt[ 2 ] );
117 lines->InsertNextCell( 2 );
118 lines->InsertCellPoint( points->GetNumberOfPoints( ) - 2 );
119 lines->InsertCellPoint( points->GetNumberOfPoints( ) - 1 );
133 // -------------------------------------------------------------------------
134 template< class _TSkeleton >
135 int fpa::Image::SkeletonToPolyDataFilter< _TSkeleton >::
137 vtkInformation* information,
138 vtkInformationVector** input,
139 vtkInformationVector* output
145 #endif // __fpa__Image__SkeletonToPolyDataFilterFilter__hxx__