1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
5 #ifndef __fpa__VTK__Image__SkeletonToPolyDataFilter__hxx__
6 #define __fpa__VTK__Image__SkeletonToPolyDataFilter__hxx__
8 #include <vtkCellArray.h>
9 #include <vtkInformation.h>
10 #include <vtkInformationVector.h>
11 #include <vtkPointData.h>
12 #include <vtkUnsignedIntArray.h>
13 #include <vtkSmartPointer.h>
15 // -------------------------------------------------------------------------
16 template< class _TSkeleton >
17 typename fpa::VTK::Image::SkeletonToPolyDataFilter< _TSkeleton >::
18 Self* fpa::VTK::Image::SkeletonToPolyDataFilter< _TSkeleton >::
21 return( new Self( ) );
24 // -------------------------------------------------------------------------
25 template< class _TSkeleton >
27 fpa::VTK::Image::SkeletonToPolyDataFilter< _TSkeleton >::
28 TSkeleton* fpa::VTK::Image::SkeletonToPolyDataFilter< _TSkeleton >::
31 return( this->m_Skeleton );
34 // -------------------------------------------------------------------------
35 template< class _TSkeleton >
36 void fpa::VTK::Image::SkeletonToPolyDataFilter< _TSkeleton >::
37 SetInput( const TSkeleton* sk )
39 if( this->m_Skeleton != sk )
41 this->m_Skeleton = sk;
47 // -------------------------------------------------------------------------
48 template< class _TSkeleton >
49 fpa::VTK::Image::SkeletonToPolyDataFilter< _TSkeleton >::
50 SkeletonToPolyDataFilter( )
51 : vtkPolyDataAlgorithm( ),
54 this->SetNumberOfInputPorts( 0 );
57 // -------------------------------------------------------------------------
58 template< class _TSkeleton >
59 fpa::VTK::Image::SkeletonToPolyDataFilter< _TSkeleton >::
60 ~SkeletonToPolyDataFilter( )
64 // -------------------------------------------------------------------------
65 template< class _TSkeleton >
66 int fpa::VTK::Image::SkeletonToPolyDataFilter< _TSkeleton >::
68 vtkInformation* information,
69 vtkInformationVector** input,
70 vtkInformationVector* output
73 typedef typename _TSkeleton::TPath _TPath;
74 static const unsigned int dim = _TPath::PathDimension;
76 if( this->m_Skeleton == NULL )
80 vtkInformation* info = output->GetInformationObject( 0 );
81 vtkPolyData* out = vtkPolyData::SafeDownCast(
82 info->Get( vtkDataObject::DATA_OBJECT( ) )
86 out->SetPoints( vtkSmartPointer< vtkPoints >::New( ) );
87 out->SetVerts( vtkSmartPointer< vtkCellArray >::New( ) );
88 out->SetLines( vtkSmartPointer< vtkCellArray >::New( ) );
89 out->SetPolys( vtkSmartPointer< vtkCellArray >::New( ) );
90 out->SetStrips( vtkSmartPointer< vtkCellArray >::New( ) );
91 vtkSmartPointer< vtkUnsignedIntArray > darray =
92 vtkSmartPointer< vtkUnsignedIntArray >::New( );
93 darray->SetNumberOfComponents( 1 );
94 out->GetPointData( )->SetScalars( darray );
95 vtkPoints* points = out->GetPoints( );
96 vtkCellArray* lines = out->GetLines( );
99 unsigned int dcount = 0;
100 typename TSkeleton::TMatrix::const_iterator mIt = this->m_Skeleton->BeginEdgesRows( );
101 for( ; mIt != this->m_Skeleton->EndEdgesRows( ); ++mIt )
103 // TODO: mIt->first; --> this is the row index. <--
104 typename TSkeleton::TMatrixRow::const_iterator rIt = mIt->second.begin( );
105 for( ; rIt != mIt->second.end( ); ++rIt )
107 // TODO: rIt->first; --> this is the column index.
108 typename TSkeleton::TEdges::const_iterator eIt = rIt->second.begin( );
109 for( ; eIt != rIt->second.end( ); ++eIt )
112 for( unsigned long i = 0; i < path->GetSize( ); ++i )
114 auto pnt = path->GetPoint( i );
116 points->InsertNextPoint( pnt[ 0 ], 0, 0 );
118 points->InsertNextPoint( pnt[ 0 ], pnt[ 1 ], 0 );
120 points->InsertNextPoint( pnt[ 0 ], pnt[ 1 ], pnt[ 2 ] );
121 darray->InsertNextTuple1( double( dcount ) );
124 lines->InsertNextCell( 2 );
125 lines->InsertCellPoint( points->GetNumberOfPoints( ) - 2 );
126 lines->InsertCellPoint( points->GetNumberOfPoints( ) - 1 );
141 // -------------------------------------------------------------------------
142 template< class _TSkeleton >
143 int fpa::VTK::Image::SkeletonToPolyDataFilter< _TSkeleton >::
145 vtkInformation* information,
146 vtkInformationVector** input,
147 vtkInformationVector* output
153 #endif // __fpa__VTK__Image__SkeletonToPolyDataFilterFilter__hxx__