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