]> Creatis software - FrontAlgorithms.git/blob - plugins/Plugins/EndPointsFilter.cxx
...
[FrontAlgorithms.git] / plugins / Plugins / EndPointsFilter.cxx
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>
6
7 // -------------------------------------------------------------------------
8 fpaPlugins::EndPointsFilter::
9 EndPointsFilter( )
10   : Superclass( )
11 {
12   typedef cpPlugins::DataObjects::Image _TImage;
13   typedef cpPlugins::DataObjects::Mesh  _TMesh;
14
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" );
20 }
21
22 // -------------------------------------------------------------------------
23 fpaPlugins::EndPointsFilter::
24 ~EndPointsFilter( )
25 {
26 }
27
28 // -------------------------------------------------------------------------
29 void fpaPlugins::EndPointsFilter::
30 _GenerateData( )
31 {
32   auto o = this->GetInputData( "DistanceMap" );
33   cpPlugins_Demangle_ImageScalars_Dims( o, _GD0 );
34   else this->_Error( "Invalid input image." );
35 }
36
37 // -------------------------------------------------------------------------
38 template< class _TDistanceMap >
39 void fpaPlugins::EndPointsFilter::
40 _GD0( _TDistanceMap* dmap )
41 {
42   auto cmap = this->GetInputData< _TDistanceMap >( "CostMap" );
43   if( cmap != NULL )
44     this->_GD1( dmap, cmap );
45   else
46     this->_Error( "Temporary error: invalid cost map." );
47 }
48
49 // -------------------------------------------------------------------------
50 template< class _TDistanceMap, class _TCostMap >
51 void fpaPlugins::EndPointsFilter::
52 _GD1( _TDistanceMap* dmap, _TCostMap* cmap )
53 {
54   typedef fpa::Image::EndPointsFilter< _TDistanceMap, _TCostMap > _TFilter;
55   typedef typename _TFilter::TMST _TMST;
56
57   auto mst = this->GetInputData< _TMST >( "MST" );
58   if( mst == NULL )
59     this->_Error( "Invalid MST." );
60
61
62   auto filter = this->_CreateITK< _TFilter >( );
63   filter->SetDistanceMap( dmap );
64   filter->SetCostMap( cmap );
65   filter->SetMST( mst );
66   filter->Compute( );
67
68   auto ep = filter->GetEndPoints( );
69   auto bi = filter->GetBifurcations( );
70
71   auto ep_pd = this->GetOutputData< vtkPolyData >( "EndPoints" );
72   if( ep_pd == NULL )
73   {
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 );
85
86     this->GetOutput( "EndPoints" )->SetVTK( pd );
87     ep_pd = this->GetOutputData< vtkPolyData >( "EndPoints" );
88
89   } // fi
90
91   for( auto iIt = ep.begin( ); iIt != ep.end( ); ++iIt )
92   {
93     typename _TCostMap::PointType p;
94     cmap->TransformIndexToPhysicalPoint( *iIt, p );
95
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 ] );
102
103     ep_pd->GetVerts( )->InsertNextCell( 1 );
104     ep_pd->GetVerts( )->InsertCellPoint( ep_pd->GetNumberOfPoints( ) - 1 );
105
106   } // rof
107 }
108
109 // eof - $RCSfile$