1 #ifndef __FPA__VTK__IMAGESKELETONTOPOLYDATA__HXX__
2 #define __FPA__VTK__IMAGESKELETONTOPOLYDATA__HXX__
4 #include <vtkInformation.h>
5 #include <vtkInformationVector.h>
6 #include <vtkSmartPointer.h>
8 // -------------------------------------------------------------------------
9 template< class _TSkeleton >
10 typename fpa::VTK::Image::ImageSkeletonToPolyData< _TSkeleton >::
11 Self* fpa::VTK::Image::ImageSkeletonToPolyData< _TSkeleton >::
14 return( new Self( ) );
17 // -------------------------------------------------------------------------
18 template< class _TSkeleton >
19 const _TSkeleton* fpa::VTK::Image::ImageSkeletonToPolyData< _TSkeleton >::
22 return( this->m_Skeleton );
25 // -------------------------------------------------------------------------
26 template< class _TSkeleton >
27 void fpa::VTK::Image::ImageSkeletonToPolyData< _TSkeleton >::
28 SetInput( const _TSkeleton* sk )
30 if( this->m_Skeleton != sk )
32 this->m_Skeleton = sk;
38 // -------------------------------------------------------------------------
39 template< class _TSkeleton >
40 fpa::VTK::Image::ImageSkeletonToPolyData< _TSkeleton >::
41 ImageSkeletonToPolyData( )
42 : vtkPolyDataAlgorithm( ),
45 this->SetNumberOfInputPorts( 0 );
48 // -------------------------------------------------------------------------
49 template< class _TSkeleton >
50 fpa::VTK::Image::ImageSkeletonToPolyData< _TSkeleton >::
51 ~ImageSkeletonToPolyData( )
55 // -------------------------------------------------------------------------
56 template< class _TSkeleton >
57 int fpa::VTK::Image::ImageSkeletonToPolyData< _TSkeleton >::
59 vtkInformation* information,
60 vtkInformationVector** input,
61 vtkInformationVector* output
64 typedef typename _TSkeleton::TVertex _TVertex;
65 typedef typename _TSkeleton::TVertexCmp _TCmp;
66 typedef itk::Point< double, _TVertex::Dimension > _TPoint;
68 std::map< _TVertex, std::map< _TVertex, bool, _TCmp >, _TCmp >
70 static const unsigned int dim = _TVertex::Dimension;
72 if( this->m_Skeleton == NULL )
76 vtkInformation* info = output->GetInformationObject( 0 );
77 vtkPolyData* out = vtkPolyData::SafeDownCast(
78 info->Get( vtkDataObject::DATA_OBJECT( ) )
81 // Prepare points and cells
82 vtkSmartPointer< vtkPoints > points =
83 vtkSmartPointer< vtkPoints >::New( );
84 vtkSmartPointer< vtkCellArray > lines =
85 vtkSmartPointer< vtkCellArray >::New( );
87 // Iterator over input data
88 auto& sk = this->m_Skeleton->Get( );
89 auto mst = this->m_Skeleton->GetMinimumSpanningTree( );
91 for( auto i = sk.begin( ); i != sk.end( ); ++i )
93 for( auto j = i->second.begin( ); j != i->second.end( ); ++j )
95 if( !marks[ i->first ][ j->first ] )
97 auto path = j->second.GetPointer( );
100 auto vertices = path->GetVertexList( );
101 for( unsigned int v = 0; v < vertices->Size( ); ++v )
103 auto idx = vertices->GetElement( v );
105 mst->TransformContinuousIndexToPhysicalPoint( idx, pnt );
107 points->InsertNextPoint( pnt[ 0 ], 0, 0 );
109 points->InsertNextPoint( pnt[ 0 ], pnt[ 1 ], 0 );
111 points->InsertNextPoint( pnt[ 0 ], pnt[ 1 ], pnt[ 2 ] );
114 lines->InsertNextCell( 2 );
115 lines->InsertCellPoint( points->GetNumberOfPoints( ) - 2 );
116 lines->InsertCellPoint( points->GetNumberOfPoints( ) - 1 );
124 // Mark path and its symmetric as visited
125 marks[ i->first ][ j->first ] = true;
126 marks[ j->first ][ i->first ] = true;
133 out->SetPoints( points );
134 out->SetLines( lines );
138 // -------------------------------------------------------------------------
139 template< class _TSkeleton >
140 int fpa::VTK::Image::ImageSkeletonToPolyData< _TSkeleton >::
142 vtkInformation* information,
143 vtkInformationVector** input,
144 vtkInformationVector* output
147 vtkInformation* info = output->GetInformationObject( 0 );
150 vtkStreamingDemandDrivenPipeline::MAXIMUM_NUMBER_OF_PIECES( ), -1
154 if( this->m_Skeleton != NULL )
157 typename C::TScalar len = this->m_RGC->GetTotalLength( );
158 typename C::TScalar s0 = this->m_RGC->Gets0( );
159 typename C::TPoint p0 = this->m_RGC->Axis( s0 );
160 typename C::TPoint p1 = this->m_RGC->Axis( s0 + len );
163 vtkStreamingDemandDrivenPipeline::WHOLE_BOUNDING_BOX( ),
164 double( p0[ 0 ] ), double( p1[ 0 ] ),
165 double( p0[ 1 ] ), double( p1[ 1 ] ),
166 double( p0[ 2 ] ), double( p1[ 2 ] )
174 #endif // __FPA__VTK__IMAGESKELETONTOPOLYDATA__HXX__