1 #include "SkeletonFilter.h"
2 #include <cpInstances/DataObjects/Image.h>
3 #include <cpInstances/DataObjects/Skeleton.h>
5 // -------------------------------------------------------------------------
6 fpaPlugins_ImageAlgorithms::SkeletonFilter::
10 typedef cpPlugins::Pipeline::DataObject _TData;
11 typedef cpInstances::DataObjects::Image _TImage;
12 typedef cpInstances::DataObjects::Skeleton _TSkeleton;
14 this->_ConfigureInput< _TImage >( "Input", true, false );
15 this->_ConfigureInput< _TData >( "Seeds", true, false );
16 this->_ConfigureOutput< _TSkeleton >( "Output" );
19 // -------------------------------------------------------------------------
20 fpaPlugins_ImageAlgorithms::SkeletonFilter::
25 // -------------------------------------------------------------------------
26 void fpaPlugins_ImageAlgorithms::SkeletonFilter::
30 typedef fpa::Image::MinimumSpanningTree< 2 > _TMST2;
31 typedef fpa::Image::MinimumSpanningTree< 3 > _TMST3;
33 auto mst2 = this->GetInputData< _TMST2 >( "MST" );
34 auto mst3 = this->GetInputData< _TMST3 >( "MST" );
35 if ( mst2 != NULL ) this->_GD0( mst2 );
36 else if( mst3 != NULL ) this->_GD0( mst3 );
37 else this->_Error( "Invalid input spanning tree." );
41 // -------------------------------------------------------------------------
42 template< class _TImage >
43 void fpaPlugins_ImageAlgorithms::SkeletonFilter::
44 _GD0( _TImage* image )
47 typedef typename _TMST::IndexType _TIndex;
48 typedef typename _TMST::TPath _TPath;
51 std::vector< _TIndex > seeds;
52 auto points = this->GetInputData< vtkPolyData >( "Seeds" );
55 if( points->GetNumberOfPoints( ) < 2 )
56 this->_Error( "Not enough seeds (<2)." );
58 typename _TMST::PointType pnt;
59 typename _TMST::IndexType idx;
61 ( _TMST::ImageDimension < 3 )? _TMST::ImageDimension: 3;
62 for( unsigned int i = 0; i < 2; ++i )
65 points->GetPoint( i, buf );
67 for( unsigned int d = 0; d < dim; ++d )
69 if( mst->TransformPhysicalPointToIndex( pnt, idx ) )
70 seeds.push_back( idx );
76 typename _TPath::Pointer path;
77 mst->GetPath( path, seeds[ 0 ], seeds[ 1 ] );
78 this->GetOutput( "Output" )->SetITK( path );