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