1 #include "ExtractPathFromMinimumSpanningTree.h"
2 #include "MinimumSpanningTree.h"
4 #include <itkDataObject.h>
6 #include <cpPlugins_ITKInstances/Paths.h>
7 #include <cpPlugins/DataObject.h>
8 #include <fpa/Base/ExtractPathFromMinimumSpanningTree.h>
9 #include <fpa/Base/ExtractPathFromMinimumSpanningTree.hxx>
11 // -------------------------------------------------------------------------
12 fpaPlugins::ExtractPathFromMinimumSpanningTree::
13 ExtractPathFromMinimumSpanningTree( )
16 this->_AddInput( "MST" );
17 this->_AddInput( "Seeds" );
18 this->_AddOutput< cpPlugins::DataObject >( "Output" );
20 this->m_Parameters.ConfigureAsUint( "Vertex0" );
21 this->m_Parameters.ConfigureAsUint( "Vertex1" );
22 this->m_Parameters.SetUint( "Vertex0", 0 );
23 this->m_Parameters.SetUint( "Vertex1", 1 );
26 // -------------------------------------------------------------------------
27 fpaPlugins::ExtractPathFromMinimumSpanningTree::
28 ~ExtractPathFromMinimumSpanningTree( )
32 // -------------------------------------------------------------------------
33 std::string fpaPlugins::ExtractPathFromMinimumSpanningTree::
36 typedef fpa::Image::MinimumSpanningTree< 2 > _2DMST;
37 typedef fpa::Image::MinimumSpanningTree< 3 > _3DMST;
39 auto mst = this->GetInputData( "MST" )->GetITK< itk::DataObject >( );
40 auto mst2 = dynamic_cast< _2DMST* >( mst );
41 auto mst3 = dynamic_cast< _3DMST* >( mst );
42 std::string r = this->_GD0( mst2 );
43 if( r != "" ) r = this->_GD0( mst3 );
47 // -------------------------------------------------------------------------
48 template< class _TMST >
49 std::string fpaPlugins::ExtractPathFromMinimumSpanningTree::
52 typedef fpa::Base::ExtractPathFromMinimumSpanningTree< _TMST > _TFilter;
53 typedef typename _TMST::TVertex _TVertex;
54 typedef itk::SimpleDataObjectDecorator< std::vector< _TVertex > > _TVertices;
57 "fpaPlugins::ExtractPathFromMinimumSpanningTree: No valid input tree."
59 auto vertices = this->GetInputData( "Seeds" )->GetITK< _TVertices >( );
60 if( vertices == NULL )
62 "fpaPlugins::ExtractPathFromMinimumSpanningTree: No valid vertices."
64 if( vertices->Get( ).size( ) < 2 )
66 "fpaPlugins::ExtractPathFromMinimumSpanningTree: Not enough vertices."
68 auto v0 = vertices->Get( )[ this->m_Parameters.GetUint( "Vertex0" ) ];
69 auto v1 = vertices->Get( )[ this->m_Parameters.GetUint( "Vertex1" ) ];
71 // Create filter and connect input
72 _TFilter* filter = this->_CreateITK< _TFilter >( );
73 filter->SetInput( mst );
74 filter->SetVertex0( v0 );
75 filter->SetVertex1( v1 );
78 // Connect output and finish
79 this->GetOutputData( "Output" )->SetITK( filter->GetOutput( ) );