1 #include "ExtractPathFromMinimumSpanningTree.h"
2 #include <cpPlugins/Path.h>
3 #include <cpExtensions/DataStructures/ImageIndexesContainer.h>
4 #include <fpa_Instances/Backtracking.h>
6 // -------------------------------------------------------------------------
7 fpaPlugins::ExtractPathFromMinimumSpanningTree::
8 ExtractPathFromMinimumSpanningTree( )
11 this->_AddInput( "MST" );
12 this->_AddInput( "Seeds" );
13 this->_AddOutput< cpPlugins::Path >( "Output" );
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 );
21 // -------------------------------------------------------------------------
22 fpaPlugins::ExtractPathFromMinimumSpanningTree::
23 ~ExtractPathFromMinimumSpanningTree( )
27 // -------------------------------------------------------------------------
28 void fpaPlugins::ExtractPathFromMinimumSpanningTree::
31 typedef fpa::Image::MinimumSpanningTree< 2 > _2DMST;
32 typedef fpa::Image::MinimumSpanningTree< 3 > _3DMST;
34 auto mst = this->GetInputData( "MST" )->GetITK< itk::DataObject >( );
35 auto mst2 = dynamic_cast< _2DMST* >( mst );
36 auto mst3 = dynamic_cast< _3DMST* >( mst );
37 if ( mst2 != NULL ) this->_GD0( mst2 );
38 else if( mst3 != NULL ) this->_GD0( mst3 );
39 else this->_Error( "Invalid input MST." );
42 // -------------------------------------------------------------------------
43 template< class _TMST >
44 void fpaPlugins::ExtractPathFromMinimumSpanningTree::
47 typedef fpa::Base::ExtractPathFromMinimumSpanningTree< _TMST > _TFilter;
49 cpExtensions::DataStructures::ImageIndexesContainer< _TMST::Dimension >
51 auto vertices = this->GetInputData( "Seeds" )->GetITK< _TVertices >( );
52 if( vertices == NULL )
53 this->_Error( "No valid vertices." );
54 if( vertices->Get( ).size( ) < 2 )
55 this->_Error( "Not enough vertices." );
56 auto v0 = vertices->Get( )[ this->m_Parameters.GetUint( "Vertex0" ) ];
57 auto v1 = vertices->Get( )[ this->m_Parameters.GetUint( "Vertex1" ) ];
59 // Create filter and connect input
60 _TFilter* filter = this->_CreateITK< _TFilter >( );
61 filter->SetInput( mst );
62 filter->SetVertex0( v0 );
63 filter->SetVertex1( v1 );
66 // Connect output and finish
67 this->GetOutputData( "Output" )->SetITK( filter->GetOutput( ) );