1 #include "ExtractPathFromMinimumSpanningTree.h"
2 #include "MinimumSpanningTree.h"
4 #include <itkDataObject.h>
6 #include <itkSimpleDataObjectDecorator.hxx>
7 #include <cpPlugins_Instances/Paths.h>
8 #include <cpPlugins/DataObject.h>
9 #include <fpa/Base/ExtractPathFromMinimumSpanningTree.h>
10 #include <fpa/Base/ExtractPathFromMinimumSpanningTree.hxx>
12 // -------------------------------------------------------------------------
13 fpaPlugins::ExtractPathFromMinimumSpanningTree::
14 ExtractPathFromMinimumSpanningTree( )
17 this->_AddInput( "MST" );
18 this->_AddInput( "Seeds" );
19 this->_AddOutput< cpPlugins::DataObject >( "Output" );
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 );
27 // -------------------------------------------------------------------------
28 fpaPlugins::ExtractPathFromMinimumSpanningTree::
29 ~ExtractPathFromMinimumSpanningTree( )
33 // -------------------------------------------------------------------------
34 std::string fpaPlugins::ExtractPathFromMinimumSpanningTree::
37 typedef fpa::Image::MinimumSpanningTree< 2 > _2DMST;
38 typedef fpa::Image::MinimumSpanningTree< 3 > _3DMST;
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 );
48 // -------------------------------------------------------------------------
49 template< class _TMST >
50 std::string fpaPlugins::ExtractPathFromMinimumSpanningTree::
53 typedef fpa::Base::ExtractPathFromMinimumSpanningTree< _TMST > _TFilter;
54 typedef typename _TMST::TVertex _TVertex;
55 typedef itk::SimpleDataObjectDecorator< std::vector< _TVertex > > _TVertices;
58 "fpaPlugins::ExtractPathFromMinimumSpanningTree: No valid input tree."
60 auto vertices = this->GetInputData( "Seeds" )->GetITK< _TVertices >( );
61 if( vertices == NULL )
63 "fpaPlugins::ExtractPathFromMinimumSpanningTree: No valid vertices."
65 if( vertices->Get( ).size( ) < 2 )
67 "fpaPlugins::ExtractPathFromMinimumSpanningTree: Not enough vertices."
69 auto v0 = vertices->Get( )[ this->m_Parameters.GetUint( "Vertex0" ) ];
70 auto v1 = vertices->Get( )[ this->m_Parameters.GetUint( "Vertex1" ) ];
72 // Create filter and connect input
73 _TFilter* filter = this->_CreateITK< _TFilter >( );
74 filter->SetInput( mst );
75 filter->SetVertex0( v0 );
76 filter->SetVertex1( v1 );
79 // Connect output and finish
80 this->GetOutputData( "Output" )->SetITK( filter->GetOutput( ) );