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__
10 # include <vtkCellArray.h>
11 # include <vtkInformation.h>
12 # include <vtkInformationVector.h>
13 # include <vtkPointData.h>
14 # include <vtkUnsignedIntArray.h>
15 # include <vtkSmartPointer.h>
18 // -------------------------------------------------------------------------
19 template< class _TSkeleton >
20 typename fpa::Image::SkeletonToPolyDataFilter< _TSkeleton >::
21 Self* fpa::Image::SkeletonToPolyDataFilter< _TSkeleton >::
24 return( new Self( ) );
27 // -------------------------------------------------------------------------
28 template< class _TSkeleton >
30 fpa::Image::SkeletonToPolyDataFilter< _TSkeleton >::
31 TSkeleton* fpa::Image::SkeletonToPolyDataFilter< _TSkeleton >::
34 return( this->m_Skeleton );
37 // -------------------------------------------------------------------------
38 template< class _TSkeleton >
39 void fpa::Image::SkeletonToPolyDataFilter< _TSkeleton >::
40 SetInput( const TSkeleton* sk )
42 if( this->m_Skeleton != sk )
44 this->m_Skeleton = sk;
52 // -------------------------------------------------------------------------
53 template< class _TSkeleton >
54 fpa::Image::SkeletonToPolyDataFilter< _TSkeleton >::
55 SkeletonToPolyDataFilter( )
57 : vtkPolyDataAlgorithm( ),
62 this->SetNumberOfInputPorts( 0 );
66 // -------------------------------------------------------------------------
67 template< class _TSkeleton >
68 fpa::Image::SkeletonToPolyDataFilter< _TSkeleton >::
69 ~SkeletonToPolyDataFilter( )
74 // -------------------------------------------------------------------------
75 template< class _TSkeleton >
76 int fpa::Image::SkeletonToPolyDataFilter< _TSkeleton >::
78 vtkInformation* information,
79 vtkInformationVector** input,
80 vtkInformationVector* output
83 typedef typename _TSkeleton::TPath _TPath;
84 static const unsigned int dim = _TPath::PathDimension;
86 if( this->m_Skeleton == NULL )
90 vtkInformation* info = output->GetInformationObject( 0 );
91 vtkPolyData* out = vtkPolyData::SafeDownCast(
92 info->Get( vtkDataObject::DATA_OBJECT( ) )
96 out->SetPoints( vtkSmartPointer< vtkPoints >::New( ) );
97 out->SetVerts( vtkSmartPointer< vtkCellArray >::New( ) );
98 out->SetLines( vtkSmartPointer< vtkCellArray >::New( ) );
99 out->SetPolys( vtkSmartPointer< vtkCellArray >::New( ) );
100 out->SetStrips( vtkSmartPointer< vtkCellArray >::New( ) );
101 vtkSmartPointer< vtkUnsignedIntArray > darray =
102 vtkSmartPointer< vtkUnsignedIntArray >::New( );
103 darray->SetNumberOfComponents( 1 );
104 out->GetPointData( )->SetScalars( darray );
105 vtkPoints* points = out->GetPoints( );
106 vtkCellArray* lines = out->GetLines( );
109 unsigned int dcount = 0;
110 typename TSkeleton::TMatrix::const_iterator mIt = this->m_Skeleton->BeginEdgesRows( );
111 for( ; mIt != this->m_Skeleton->EndEdgesRows( ); ++mIt )
113 // TODO: mIt->first; --> this is the row index. <--
114 typename TSkeleton::TMatrixRow::const_iterator rIt = mIt->second.begin( );
115 for( ; rIt != mIt->second.end( ); ++rIt )
117 // TODO: rIt->first; --> this is the column index.
118 typename TSkeleton::TEdges::const_iterator eIt = rIt->second.begin( );
119 for( ; eIt != rIt->second.end( ); ++eIt )
122 for( unsigned long i = 0; i < path->GetSize( ); ++i )
124 auto pnt = path->GetPoint( i );
126 points->InsertNextPoint( pnt[ 0 ], 0, 0 );
128 points->InsertNextPoint( pnt[ 0 ], pnt[ 1 ], 0 );
130 points->InsertNextPoint( pnt[ 0 ], pnt[ 1 ], pnt[ 2 ] );
131 darray->InsertNextTuple1( double( dcount ) );
134 lines->InsertNextCell( 2 );
135 lines->InsertCellPoint( points->GetNumberOfPoints( ) - 2 );
136 lines->InsertCellPoint( points->GetNumberOfPoints( ) - 1 );
151 // -------------------------------------------------------------------------
152 template< class _TSkeleton >
153 int fpa::Image::SkeletonToPolyDataFilter< _TSkeleton >::
155 vtkInformation* information,
156 vtkInformationVector** input,
157 vtkInformationVector* output
164 #endif // __fpa__Image__SkeletonToPolyDataFilterFilter__hxx__