1 #include <Plugins/SkeletonFilter.h>
2 #include <cpPlugins/DataObjects/Image.h>
3 #include <cpPlugins/DataObjects/Image_Demanglers.h>
4 #include <cpPlugins/DataObjects/Skeleton.h>
6 #include <fpa/Image/SkeletonFilter.h>
10 #include <fpa/Image/SkeletonFilter.hxx>
11 #include <itkSimpleDataObjectDecorator.hxx>
14 // -------------------------------------------------------------------------
15 fpaPlugins::SkeletonFilter::
19 typedef cpPlugins::DataObjects::Image _TImage;
20 typedef cpPlugins::DataObjects::Skeleton _TSkeleton;
22 this->_ConfigureInput< _TImage >( "DistanceMap", true, false );
23 this->_ConfigureInput< _TImage >( "CostMap", true, false );
24 this->_ConfigureInput< _TImage >( "MST", true, false );
25 this->_ConfigureOutput< _TSkeleton >( "Skeleton" );
26 this->_ConfigureOutput< _TImage >( "Marks" );
28 this->_ConfigureOutput< _TMesh >( "EndPoints" );
29 this->_ConfigureOutput< _TMesh >( "Bifurcations" );
33 // -------------------------------------------------------------------------
34 fpaPlugins::SkeletonFilter::
39 // -------------------------------------------------------------------------
40 void fpaPlugins::SkeletonFilter::
43 auto o = this->GetInputData( "DistanceMap" );
44 cpPlugins_Demangle_Image_RealPixels_AllDims_1( o, _GD0 )
45 this->_Error( "Invalid input image." );
48 // -------------------------------------------------------------------------
49 template< class _TDistanceMap >
50 void fpaPlugins::SkeletonFilter::
51 _GD0( _TDistanceMap* dmap )
53 auto o = this->GetInputData( "CostMap" );
54 cpPlugins_Demangle_Image_RealPixels_2( o, _GD1, _TDistanceMap::ImageDimension, dmap )
55 this->_Error( "Invalid input image." );
58 // -------------------------------------------------------------------------
59 template< class _TCostMap, class _TDistanceMap >
60 void fpaPlugins::SkeletonFilter::
61 _GD1( _TCostMap* cmap, _TDistanceMap* dmap )
63 typedef fpa::Image::SkeletonFilter< _TDistanceMap, _TCostMap > _TFilter;
64 typedef typename _TFilter::TMST _TMST;
66 auto mst = this->GetInputData< _TMST >( "MST" );
68 this->_Error( "Invalid MST." );
70 auto filter = this->_CreateITK< _TFilter >( );
71 filter->SetDistanceMap( dmap );
72 filter->SetCostMap( cmap );
73 filter->SetMinimumSpanningTree( mst );
75 this->GetOutput( "Skeleton" )->SetITK( filter->GetSkeleton( ) );
76 this->GetOutput( "Marks" )->SetITK( filter->GetMarks( ) );
79 auto ep = filter->GetEndPoints( );
80 auto bi = filter->GetBifurcations( );
82 auto ep_pd = this->GetOutputData< vtkPolyData >( "EndPoints" );
85 auto points = vtkSmartPointer< vtkPoints >::New( );
86 auto verts = vtkSmartPointer< vtkCellArray >::New( );
87 auto lines = vtkSmartPointer< vtkCellArray >::New( );
88 auto polys = vtkSmartPointer< vtkCellArray >::New( );
89 auto strips = vtkSmartPointer< vtkCellArray >::New( );
90 auto pd = vtkSmartPointer< vtkPolyData >::New( );
91 pd->SetPoints( points );
92 pd->SetVerts( verts );
93 pd->SetLines( lines );
94 pd->SetPolys( polys );
95 pd->SetStrips( strips );
97 this->GetOutput( "EndPoints" )->SetVTK( pd );
98 ep_pd = this->GetOutputData< vtkPolyData >( "EndPoints" );
102 for( auto iIt = ep.begin( ); iIt != ep.end( ); ++iIt )
104 typename _TCostMap::PointType p;
105 cmap->TransformIndexToPhysicalPoint( *iIt, p );
107 if( _TCostMap::ImageDimension == 1 )
108 ep_pd->GetPoints( )->InsertNextPoint( p[ 0 ], 0, 0 );
109 else if( _TCostMap::ImageDimension == 2 )
110 ep_pd->GetPoints( )->InsertNextPoint( p[ 0 ], p[ 1 ], 0 );
111 else if( _TCostMap::ImageDimension > 2 )
112 ep_pd->GetPoints( )->InsertNextPoint( p[ 0 ], p[ 1 ], p[ 2 ] );
114 ep_pd->GetVerts( )->InsertNextCell( 1 );
115 ep_pd->GetVerts( )->InsertCellPoint( ep_pd->GetNumberOfPoints( ) - 1 );