]> Creatis software - FrontAlgorithms.git/blob - plugins/fpa/ExtractPathFromMinimumSpanningTree.cxx
6a2aef5ad7a68883153c61519b8669518c989ae9
[FrontAlgorithms.git] / plugins / fpa / ExtractPathFromMinimumSpanningTree.cxx
1 #include "ExtractPathFromMinimumSpanningTree.h"
2 #include "MinimumSpanningTree.h"
3
4 #include <itkDataObject.h>
5 #include <itkIndex.h>
6 #include <cpPlugins_ITKInstances/Paths.h>
7 #include <cpPlugins/DataObject.h>
8 #include <fpa/Base/ExtractPathFromMinimumSpanningTree.h>
9 #include <fpa/Base/ExtractPathFromMinimumSpanningTree.hxx>
10
11 // -------------------------------------------------------------------------
12 fpaPlugins::ExtractPathFromMinimumSpanningTree::
13 ExtractPathFromMinimumSpanningTree( )
14   : Superclass( )
15 {
16   this->_AddInput( "MST" );
17   this->_AddInput( "Seeds" );
18   this->_AddOutput< cpPlugins::DataObject >( "Output" );
19
20   this->m_Parameters.ConfigureAsUint( "Vertex0" );
21   this->m_Parameters.ConfigureAsUint( "Vertex1" );
22   this->m_Parameters.SetUint( "Vertex0", 0 );
23   this->m_Parameters.SetUint( "Vertex1", 1 );
24 }
25
26 // -------------------------------------------------------------------------
27 fpaPlugins::ExtractPathFromMinimumSpanningTree::
28 ~ExtractPathFromMinimumSpanningTree( )
29 {
30 }
31
32 // -------------------------------------------------------------------------
33 std::string fpaPlugins::ExtractPathFromMinimumSpanningTree::
34 _GenerateData( )
35 {
36   typedef fpa::Image::MinimumSpanningTree< 2 > _2DMST;
37   typedef fpa::Image::MinimumSpanningTree< 3 > _3DMST;
38
39   auto mst = this->GetInputData( "MST" )->GetITK< itk::DataObject >( );
40   auto mst2 = dynamic_cast< _2DMST* >( mst );
41   auto mst3 = dynamic_cast< _3DMST* >( mst );
42   std::string   r = this->_GD0( mst2 );
43   if( r != "" ) r = this->_GD0( mst3 );
44   return( r );
45 }
46
47 // -------------------------------------------------------------------------
48 template< class _TMST >
49 std::string fpaPlugins::ExtractPathFromMinimumSpanningTree::
50 _GD0( _TMST* mst )
51 {
52   typedef fpa::Base::ExtractPathFromMinimumSpanningTree< _TMST >    _TFilter;
53   typedef typename _TMST::TVertex                                   _TVertex;
54   typedef itk::SimpleDataObjectDecorator< std::vector< _TVertex > > _TVertices;
55   if( mst == NULL )
56     return(
57       "fpaPlugins::ExtractPathFromMinimumSpanningTree: No valid input tree."
58       );
59   auto vertices = this->GetInputData( "Seeds" )->GetITK< _TVertices >( );
60   if( vertices == NULL )
61     return(
62       "fpaPlugins::ExtractPathFromMinimumSpanningTree: No valid vertices."
63       );
64   if( vertices->Get( ).size( ) < 2 )
65     return(
66       "fpaPlugins::ExtractPathFromMinimumSpanningTree: Not enough vertices."
67       );
68   auto v0 = vertices->Get( )[ this->m_Parameters.GetUint( "Vertex0" ) ];
69   auto v1 = vertices->Get( )[ this->m_Parameters.GetUint( "Vertex1" ) ];
70
71   // Create filter and connect input
72   _TFilter* filter = this->_CreateITK< _TFilter >( );
73   filter->SetInput( mst );
74   filter->SetVertex0( v0 );
75   filter->SetVertex1( v1 );
76   filter->Update( );
77
78   // Connect output and finish
79   this->GetOutputData( "Output" )->SetITK( filter->GetOutput( ) );
80   return( "" );
81 }
82
83 // eof - $RCSfile$