]> Creatis software - FrontAlgorithms.git/blob - lib/fpaPlugins/MinimumSpanningTreeToMesh.cxx
8596bc5034f3074a633b7b02b8542ab0093eac30
[FrontAlgorithms.git] / lib / fpaPlugins / MinimumSpanningTreeToMesh.cxx
1 #include "MinimumSpanningTreeToMesh.h"
2
3 #include <cpPlugins/Interface/Image.h>
4 #include <cpPlugins/Interface/Mesh.h>
5 #include <cpPlugins/Interface/PointList.h>
6 #include <fpaPlugins/MinimumSpanningTree.h>
7 #include <fpa/Base/MinimumSpanningTree.h>
8
9 #include <vtkCellArray.h>
10 #include <vtkPoints.h>
11 #include <vtkPolyData.h>
12
13 // -------------------------------------------------------------------------
14 fpaPlugins::MinimumSpanningTreeToMesh::
15 MinimumSpanningTreeToMesh( )
16   : Superclass( )
17 {
18   this->_AddInput( "Input" );
19   this->_AddInput( "Seeds" );
20   this->_AddInput( "ReferenceImage" );
21   this->_AddOutput< cpPlugins::Interface::Mesh >( "Output" );
22
23   this->m_Parameters->ConfigureAsUint( "Kernel" );
24   this->m_Parameters->SetUint( "Kernel", 0 );
25 }
26
27 // -------------------------------------------------------------------------
28 fpaPlugins::MinimumSpanningTreeToMesh::
29 ~MinimumSpanningTreeToMesh( )
30 {
31 }
32
33 // -------------------------------------------------------------------------
34 std::string fpaPlugins::MinimumSpanningTreeToMesh::
35 _GenerateData( )
36 {
37   typedef itk::ImageBase< 2 > _2D;
38   typedef itk::ImageBase< 3 > _3D;
39
40   auto input = this->GetInputData( "ReferenceImage" );
41   _2D* im2d = input->GetITK< _2D >( );
42   _3D* im3d = input->GetITK< _3D >( );
43   if( im2d != NULL )
44     return( this->_GD0( im2d ) );
45   else if( im3d != NULL )
46     return( this->_GD0( im3d ) );
47   else
48     return( "fpaPlugins::MinimumSpanningTreeToMesh: Reference image type not supported." );
49 }
50
51 // -------------------------------------------------------------------------
52 template< class I >
53 std::string fpaPlugins::MinimumSpanningTreeToMesh::
54 _GD0( I* image )
55 {
56   /* TODO
57   typedef typename I::IndexType                                        _V;
58   typedef typename I::PointType                                        _P;
59   typedef itk::Functor::IndexLexicographicCompare< I::ImageDimension > _VC;
60   typedef fpa::Base::MinimumSpanningTree< _V, _VC >                    _MST;
61
62   // Get inputs
63   auto mst_wrapper = this->GetInputData( "Input" );
64   _MST* mst = mst_wrapper->GetITK< _MST >( );
65   if( mst == NULL )
66     return( "fpaPlugins::MinimumSpanningTreeToMesh: Input MST type not supported." );
67   auto seeds = dynamic_cast< cpPlugins::Interface::PointList* >(
68     this->GetInputData( "Seeds" )
69     );
70   if( seeds == NULL )
71     return( "fpaPlugins::MinimumSpanningTreeToMesh: Not valid seeds." );
72   if( seeds->GetNumberOfPoints( ) < 2 )
73     return( "fpaPlugins::MinimumSpanningTreeToMesh: Not enough seeds (<2)." );
74
75   // Get output
76   auto out = this->GetOutputData( "Output" );
77   vtkSmartPointer< vtkPolyData > pd = out->GetVTK< vtkPolyData >( );
78   if( pd.GetPointer( ) == NULL )
79   {
80     pd = vtkPolyData::New( );
81     out->SetVTK( pd );
82
83   } // fi
84
85   _P pa = seeds->GetPoint< _P >( 0 );
86   _P pb = seeds->GetPoint< _P >( 1 );
87   _V va, vb;
88   image->TransformPhysicalPointToIndex( pa, va );
89   image->TransformPhysicalPointToIndex( pb, vb );
90
91   std::vector< _P > path =
92     mst->GetPathFromImage(
93       va, vb, image,
94       this->m_Parameters->GetUint( "Kernel" )
95       );
96
97   vtkSmartPointer< vtkPoints > points =
98     vtkSmartPointer< vtkPoints >::New( );
99   vtkSmartPointer< vtkCellArray > array =
100     vtkSmartPointer< vtkCellArray >::New( );
101   for( unsigned int i = 0; i < path.size( ); ++i )
102   {
103     if( I::ImageDimension == 2 )
104       points->InsertNextPoint( path[ i ][ 0 ], path[ i ][ 1 ], 0 );
105     else if( I::ImageDimension == 3 )
106       points->InsertNextPoint(
107         path[ i ][ 0 ], path[ i ][ 1 ], path[ i ][ 2 ]
108         );
109     else
110       points->InsertNextPoint( 0, 0, 0 );
111     if( i > 0 )
112     {
113       array->InsertNextCell( 2 );
114       array->InsertCellPoint( i - 1 );
115       array->InsertCellPoint( i );
116
117     } // fi
118     
119   } // rof
120   pd->SetPoints( points );
121   pd->SetLines( array );
122
123   return( "" );
124   */
125   return( "Not yet implemented." );
126 }
127
128 // eof - $RCSfile$