1 #include <plugins/Plugins/EndPointsFilter.h>
2 #include <cpPlugins/DataObjects/Image.h>
3 #include <cpPlugins/DataObjects/Mesh.h>
4 #include <fpa/Image/EndPointsFilter.h>
5 #include <fpa/Image/EndPointsFilter.hxx>
7 // -------------------------------------------------------------------------
8 fpaPlugins::EndPointsFilter::
12 typedef cpPlugins::DataObjects::Image _TImage;
13 typedef cpPlugins::DataObjects::Mesh _TMesh;
15 this->_ConfigureInput< _TImage >( "DistanceMap", true, false );
16 this->_ConfigureInput< _TImage >( "CostMap", true, false );
17 this->_ConfigureInput< _TImage >( "MST", true, false );
18 this->_ConfigureOutput< _TMesh >( "EndPoints" );
19 this->_ConfigureOutput< _TMesh >( "Bifurcations" );
22 // -------------------------------------------------------------------------
23 fpaPlugins::EndPointsFilter::
28 // -------------------------------------------------------------------------
29 void fpaPlugins::EndPointsFilter::
32 auto o = this->GetInputData( "DistanceMap" );
33 cpPlugins_Demangle_ImageScalars_Dims( o, _GD0 );
34 else this->_Error( "Invalid input image." );
37 // -------------------------------------------------------------------------
38 template< class _TDistanceMap >
39 void fpaPlugins::EndPointsFilter::
40 _GD0( _TDistanceMap* dmap )
42 auto cmap = this->GetInputData< _TDistanceMap >( "CostMap" );
44 this->_GD1( dmap, cmap );
46 this->_Error( "Temporary error: invalid cost map." );
49 // -------------------------------------------------------------------------
50 template< class _TDistanceMap, class _TCostMap >
51 void fpaPlugins::EndPointsFilter::
52 _GD1( _TDistanceMap* dmap, _TCostMap* cmap )
54 typedef fpa::Image::EndPointsFilter< _TDistanceMap, _TCostMap > _TFilter;
55 typedef typename _TFilter::TMST _TMST;
57 auto mst = this->GetInputData< _TMST >( "MST" );
59 this->_Error( "Invalid MST." );
62 auto filter = this->_CreateITK< _TFilter >( );
63 filter->SetDistanceMap( dmap );
64 filter->SetCostMap( cmap );
65 filter->SetMST( mst );
68 auto ep = filter->GetEndPoints( );
69 auto bi = filter->GetBifurcations( );
71 auto ep_pd = this->GetOutputData< vtkPolyData >( "EndPoints" );
74 auto points = vtkSmartPointer< vtkPoints >::New( );
75 auto verts = vtkSmartPointer< vtkCellArray >::New( );
76 auto lines = vtkSmartPointer< vtkCellArray >::New( );
77 auto polys = vtkSmartPointer< vtkCellArray >::New( );
78 auto strips = vtkSmartPointer< vtkCellArray >::New( );
79 auto pd = vtkSmartPointer< vtkPolyData >::New( );
80 pd->SetPoints( points );
81 pd->SetVerts( verts );
82 pd->SetLines( lines );
83 pd->SetPolys( polys );
84 pd->SetStrips( strips );
86 this->GetOutput( "EndPoints" )->SetVTK( pd );
87 ep_pd = this->GetOutputData< vtkPolyData >( "EndPoints" );
91 for( auto iIt = ep.begin( ); iIt != ep.end( ); ++iIt )
93 typename _TCostMap::PointType p;
94 cmap->TransformIndexToPhysicalPoint( *iIt, p );
96 if( _TCostMap::ImageDimension == 1 )
97 ep_pd->GetPoints( )->InsertNextPoint( p[ 0 ], 0, 0 );
98 else if( _TCostMap::ImageDimension == 2 )
99 ep_pd->GetPoints( )->InsertNextPoint( p[ 0 ], p[ 1 ], 0 );
100 else if( _TCostMap::ImageDimension > 2 )
101 ep_pd->GetPoints( )->InsertNextPoint( p[ 0 ], p[ 1 ], p[ 2 ] );
103 ep_pd->GetVerts( )->InsertNextCell( 1 );
104 ep_pd->GetVerts( )->InsertCellPoint( ep_pd->GetNumberOfPoints( ) - 1 );