]> Creatis software - FrontAlgorithms.git/blob - plugins/Plugins/SkeletonFilter.cxx
...
[FrontAlgorithms.git] / plugins / Plugins / SkeletonFilter.cxx
1 #include <Plugins/SkeletonFilter.h>
2 #include <cpPlugins/DataObjects/Image.h>
3 #include <cpPlugins/DataObjects/Image_Demanglers.h>
4 #include <cpPlugins/DataObjects/Skeleton.h>
5
6 #include <fpa/Image/SkeletonFilter.h>
7 #include <itkImage.h>
8
9 /* TODO
10    #include <fpa/Image/SkeletonFilter.hxx>
11    #include <itkSimpleDataObjectDecorator.hxx>
12 */
13
14 // -------------------------------------------------------------------------
15 fpaPlugins::SkeletonFilter::
16 SkeletonFilter( )
17   : Superclass( )
18 {
19   typedef cpPlugins::DataObjects::Image    _TImage;
20   typedef cpPlugins::DataObjects::Skeleton _TSkeleton;
21
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" );
27   /* TODO
28      this->_ConfigureOutput< _TMesh >( "EndPoints" );
29      this->_ConfigureOutput< _TMesh >( "Bifurcations" );
30   */
31 }
32
33 // -------------------------------------------------------------------------
34 fpaPlugins::SkeletonFilter::
35 ~SkeletonFilter( )
36 {
37 }
38
39 // -------------------------------------------------------------------------
40 void fpaPlugins::SkeletonFilter::
41 _GenerateData( )
42 {
43   auto o = this->GetInputData( "DistanceMap" );
44   cpPlugins_Demangle_Image_RealPixels_AllDims_1( o, _GD0 )
45     this->_Error( "Invalid input image." );
46 }
47
48 // -------------------------------------------------------------------------
49 template< class _TDistanceMap >
50 void fpaPlugins::SkeletonFilter::
51 _GD0( _TDistanceMap* dmap )
52 {
53   auto o = this->GetInputData( "CostMap" );
54   cpPlugins_Demangle_Image_RealPixels_2( o, _GD1, _TDistanceMap::ImageDimension, dmap )
55     this->_Error( "Invalid input image." );
56 }
57
58 // -------------------------------------------------------------------------
59 template< class _TCostMap, class _TDistanceMap >
60 void fpaPlugins::SkeletonFilter::
61 _GD1( _TCostMap* cmap, _TDistanceMap* dmap )
62 {
63   typedef fpa::Image::SkeletonFilter< _TDistanceMap, _TCostMap > _TFilter;
64   typedef typename _TFilter::TMST _TMST;
65
66   auto mst = this->GetInputData< _TMST >( "MST" );
67   if( mst == NULL )
68     this->_Error( "Invalid MST." );
69
70   auto filter = this->_CreateITK< _TFilter >( );
71   filter->SetDistanceMap( dmap );
72   filter->SetCostMap( cmap );
73   filter->SetMinimumSpanningTree( mst );
74   filter->Update( );
75   this->GetOutput( "Skeleton" )->SetITK( filter->GetSkeleton( ) );
76   this->GetOutput( "Marks" )->SetITK( filter->GetMarks( ) );
77
78   /* TODO
79      auto ep = filter->GetEndPoints( );
80      auto bi = filter->GetBifurcations( );
81
82      auto ep_pd = this->GetOutputData< vtkPolyData >( "EndPoints" );
83      if( ep_pd == NULL )
84      {
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 );
96
97      this->GetOutput( "EndPoints" )->SetVTK( pd );
98      ep_pd = this->GetOutputData< vtkPolyData >( "EndPoints" );
99
100      } // fi
101
102      for( auto iIt = ep.begin( ); iIt != ep.end( ); ++iIt )
103      {
104      typename _TCostMap::PointType p;
105      cmap->TransformIndexToPhysicalPoint( *iIt, p );
106
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 ] );
113
114      ep_pd->GetVerts( )->InsertNextCell( 1 );
115      ep_pd->GetVerts( )->InsertCellPoint( ep_pd->GetNumberOfPoints( ) - 1 );
116
117      } // rof
118   */
119 }
120
121 // eof - $RCSfile$