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