1 #include "ExtractPathFromMinimumSpanningTree.h"
2 #include <fpa_Instances/Instances.h>
4 #include <itkDataObject.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>
14 // -------------------------------------------------------------------------
15 fpaPlugins::ExtractPathFromMinimumSpanningTree::
16 ExtractPathFromMinimumSpanningTree( )
19 this->_AddInput( "MST" );
20 this->_AddInput( "Seeds" );
21 this->_AddOutput< cpPlugins::Path >( "Output" );
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 );
29 // -------------------------------------------------------------------------
30 fpaPlugins::ExtractPathFromMinimumSpanningTree::
31 ~ExtractPathFromMinimumSpanningTree( )
35 // -------------------------------------------------------------------------
36 std::string fpaPlugins::ExtractPathFromMinimumSpanningTree::
39 typedef fpa::Image::MinimumSpanningTree< 2 > _2DMST;
40 typedef fpa::Image::MinimumSpanningTree< 3 > _3DMST;
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 );
50 // -------------------------------------------------------------------------
51 template< class _TMST >
52 std::string fpaPlugins::ExtractPathFromMinimumSpanningTree::
55 typedef fpa::Base::ExtractPathFromMinimumSpanningTree< _TMST > _TFilter;
56 typedef typename _TMST::TVertex _TVertex;
57 typedef itk::SimpleDataObjectDecorator< std::vector< _TVertex > > _TVertices;
60 "fpaPlugins::ExtractPathFromMinimumSpanningTree: No valid input tree."
62 auto vertices = this->GetInputData( "Seeds" )->GetITK< _TVertices >( );
63 if( vertices == NULL )
65 "fpaPlugins::ExtractPathFromMinimumSpanningTree: No valid vertices."
67 if( vertices->Get( ).size( ) < 2 )
69 "fpaPlugins::ExtractPathFromMinimumSpanningTree: Not enough vertices."
71 auto v0 = vertices->Get( )[ this->m_Parameters.GetUint( "Vertex0" ) ];
72 auto v1 = vertices->Get( )[ this->m_Parameters.GetUint( "Vertex1" ) ];
74 // Create filter and connect input
75 _TFilter* filter = this->_CreateITK< _TFilter >( );
76 filter->SetInput( mst );
77 filter->SetVertex0( v0 );
78 filter->SetVertex1( v1 );
81 // Connect output and finish
82 this->GetOutputData( "Output" )->SetITK( filter->GetOutput( ) );