]> Creatis software - FrontAlgorithms.git/blob - plugins/Plugins/SkeletonFilter.cxx
...
[FrontAlgorithms.git] / plugins / Plugins / SkeletonFilter.cxx
1 #include <plugins/Plugins/SkeletonFilter.h>
2 #include <cpPlugins/DataObjects/Image.h>
3 #include <cpPlugins/DataObjects/Skeleton.h>
4 #include <fpa/Image/SkeletonFilter.h>
5 #include <fpa/Image/SkeletonFilter.hxx>
6 #include <itkSimpleDataObjectDecorator.hxx>
7
8 // -------------------------------------------------------------------------
9 fpaPlugins::SkeletonFilter::
10 SkeletonFilter( )
11   : Superclass( )
12 {
13   typedef cpPlugins::DataObjects::Image    _TImage;
14   typedef cpPlugins::DataObjects::Skeleton _TSkeleton;
15
16   this->_ConfigureInput< _TImage >( "DistanceMap", true, false );
17   this->_ConfigureInput< _TImage >( "CostMap", true, false );
18   this->_ConfigureInput< _TImage >( "MST", true, false );
19   this->_ConfigureOutput< _TSkeleton >( "Skeleton" );
20   this->_ConfigureOutput< _TImage >( "Marks" );
21   /* TODO
22      this->_ConfigureOutput< _TMesh >( "EndPoints" );
23      this->_ConfigureOutput< _TMesh >( "Bifurcations" );
24   */
25 }
26
27 // -------------------------------------------------------------------------
28 fpaPlugins::SkeletonFilter::
29 ~SkeletonFilter( )
30 {
31 }
32
33 // -------------------------------------------------------------------------
34 void fpaPlugins::SkeletonFilter::
35 _GenerateData( )
36 {
37   auto o = this->GetInputData( "DistanceMap" );
38   cpPlugins_Demangle_ImageScalars_Dims( o, _GD0 );
39   else this->_Error( "Invalid input image." );
40 }
41
42 // -------------------------------------------------------------------------
43 template< class _TDistanceMap >
44 void fpaPlugins::SkeletonFilter::
45 _GD0( _TDistanceMap* dmap )
46 {
47   auto cmap = this->GetInputData< _TDistanceMap >( "CostMap" );
48   if( cmap != NULL )
49     this->_GD1( dmap, cmap );
50   else
51     this->_Error( "Temporary error: invalid cost map." );
52 }
53
54 // -------------------------------------------------------------------------
55 template< class _TDistanceMap, class _TCostMap >
56 void fpaPlugins::SkeletonFilter::
57 _GD1( _TDistanceMap* dmap, _TCostMap* cmap )
58 {
59   typedef fpa::Image::SkeletonFilter< _TDistanceMap, _TCostMap > _TFilter;
60   typedef typename _TFilter::TMST _TMST;
61
62   auto mst = this->GetInputData< _TMST >( "MST" );
63   if( mst == NULL )
64     this->_Error( "Invalid MST." );
65
66   auto filter = this->_CreateITK< _TFilter >( );
67   filter->SetDistanceMap( dmap );
68   filter->SetCostMap( cmap );
69   filter->SetMinimumSpanningTree( mst );
70   filter->Update( );
71   this->GetOutput( "Skeleton" )->SetITK( filter->GetSkeleton( ) );
72   this->GetOutput( "Marks" )->SetITK( filter->GetMarks( ) );
73
74
75   /* TODO
76      auto ep = filter->GetEndPoints( );
77      auto bi = filter->GetBifurcations( );
78
79      auto ep_pd = this->GetOutputData< vtkPolyData >( "EndPoints" );
80      if( ep_pd == NULL )
81      {
82      auto points = vtkSmartPointer< vtkPoints >::New( );
83      auto verts = vtkSmartPointer< vtkCellArray >::New( );
84      auto lines = vtkSmartPointer< vtkCellArray >::New( );
85      auto polys = vtkSmartPointer< vtkCellArray >::New( );
86      auto strips = vtkSmartPointer< vtkCellArray >::New( );
87      auto pd = vtkSmartPointer< vtkPolyData >::New( );
88      pd->SetPoints( points );
89      pd->SetVerts( verts );
90      pd->SetLines( lines );
91      pd->SetPolys( polys );
92      pd->SetStrips( strips );
93
94      this->GetOutput( "EndPoints" )->SetVTK( pd );
95      ep_pd = this->GetOutputData< vtkPolyData >( "EndPoints" );
96
97      } // fi
98
99      for( auto iIt = ep.begin( ); iIt != ep.end( ); ++iIt )
100      {
101      typename _TCostMap::PointType p;
102      cmap->TransformIndexToPhysicalPoint( *iIt, p );
103
104      if( _TCostMap::ImageDimension == 1 )
105      ep_pd->GetPoints( )->InsertNextPoint( p[ 0 ], 0, 0 );
106      else if( _TCostMap::ImageDimension == 2 )
107      ep_pd->GetPoints( )->InsertNextPoint( p[ 0 ], p[ 1 ], 0 );
108      else if( _TCostMap::ImageDimension > 2 )
109      ep_pd->GetPoints( )->InsertNextPoint( p[ 0 ], p[ 1 ], p[ 2 ] );
110
111      ep_pd->GetVerts( )->InsertNextCell( 1 );
112      ep_pd->GetVerts( )->InsertCellPoint( ep_pd->GetNumberOfPoints( ) - 1 );
113
114      } // rof
115   */
116 }
117
118 // eof - $RCSfile$