1 #include <plugins/Plugins/SkeletonFilter.h>
2 #include <cpPlugins/DataObjects/Image.h>
3 #include <cpPlugins/DataObjects/Skeleton.h>
4 #include <fpa/Image/SkeletonFilter.h>
5 #include <fpa/Image/SkeletonFilter.hxx>
6 #include <itkSimpleDataObjectDecorator.hxx>
8 // -------------------------------------------------------------------------
9 fpaPlugins::SkeletonFilter::
13 typedef cpPlugins::DataObjects::Image _TImage;
14 typedef cpPlugins::DataObjects::Skeleton _TSkeleton;
16 this->_ConfigureInput< _TImage >( "DistanceMap", true, false );
17 this->_ConfigureInput< _TImage >( "CostMap", true, false );
18 this->_ConfigureInput< _TImage >( "MST", true, false );
19 this->_ConfigureOutput< _TSkeleton >( "Skeleton" );
20 this->_ConfigureOutput< _TImage >( "Marks" );
22 this->_ConfigureOutput< _TMesh >( "EndPoints" );
23 this->_ConfigureOutput< _TMesh >( "Bifurcations" );
27 // -------------------------------------------------------------------------
28 fpaPlugins::SkeletonFilter::
33 // -------------------------------------------------------------------------
34 void fpaPlugins::SkeletonFilter::
37 auto o = this->GetInputData( "DistanceMap" );
38 cpPlugins_Demangle_ImageScalars_Dims( o, _GD0 );
39 else this->_Error( "Invalid input image." );
42 // -------------------------------------------------------------------------
43 template< class _TDistanceMap >
44 void fpaPlugins::SkeletonFilter::
45 _GD0( _TDistanceMap* dmap )
47 auto cmap = this->GetInputData< _TDistanceMap >( "CostMap" );
49 this->_GD1( dmap, cmap );
51 this->_Error( "Temporary error: invalid cost map." );
54 // -------------------------------------------------------------------------
55 template< class _TDistanceMap, class _TCostMap >
56 void fpaPlugins::SkeletonFilter::
57 _GD1( _TDistanceMap* dmap, _TCostMap* cmap )
59 typedef fpa::Image::SkeletonFilter< _TDistanceMap, _TCostMap > _TFilter;
60 typedef typename _TFilter::TMST _TMST;
62 auto mst = this->GetInputData< _TMST >( "MST" );
64 this->_Error( "Invalid MST." );
66 auto filter = this->_CreateITK< _TFilter >( );
67 filter->SetDistanceMap( dmap );
68 filter->SetCostMap( cmap );
69 filter->SetMinimumSpanningTree( mst );
71 this->GetOutput( "Skeleton" )->SetITK( filter->GetSkeleton( ) );
72 this->GetOutput( "Marks" )->SetITK( filter->GetMarks( ) );
76 auto ep = filter->GetEndPoints( );
77 auto bi = filter->GetBifurcations( );
79 auto ep_pd = this->GetOutputData< vtkPolyData >( "EndPoints" );
82 auto points = vtkSmartPointer< vtkPoints >::New( );
83 auto verts = vtkSmartPointer< vtkCellArray >::New( );
84 auto lines = vtkSmartPointer< vtkCellArray >::New( );
85 auto polys = vtkSmartPointer< vtkCellArray >::New( );
86 auto strips = vtkSmartPointer< vtkCellArray >::New( );
87 auto pd = vtkSmartPointer< vtkPolyData >::New( );
88 pd->SetPoints( points );
89 pd->SetVerts( verts );
90 pd->SetLines( lines );
91 pd->SetPolys( polys );
92 pd->SetStrips( strips );
94 this->GetOutput( "EndPoints" )->SetVTK( pd );
95 ep_pd = this->GetOutputData< vtkPolyData >( "EndPoints" );
99 for( auto iIt = ep.begin( ); iIt != ep.end( ); ++iIt )
101 typename _TCostMap::PointType p;
102 cmap->TransformIndexToPhysicalPoint( *iIt, p );
104 if( _TCostMap::ImageDimension == 1 )
105 ep_pd->GetPoints( )->InsertNextPoint( p[ 0 ], 0, 0 );
106 else if( _TCostMap::ImageDimension == 2 )
107 ep_pd->GetPoints( )->InsertNextPoint( p[ 0 ], p[ 1 ], 0 );
108 else if( _TCostMap::ImageDimension > 2 )
109 ep_pd->GetPoints( )->InsertNextPoint( p[ 0 ], p[ 1 ], p[ 2 ] );
111 ep_pd->GetVerts( )->InsertNextCell( 1 );
112 ep_pd->GetVerts( )->InsertCellPoint( ep_pd->GetNumberOfPoints( ) - 1 );