]> Creatis software - FrontAlgorithms.git/blob - plugins/fpa/ExtractPathFromMinimumSpanningTree.cxx
...
[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 void 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< itk::DataObject >( "MST" );
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." );
40 }
41
42 // -------------------------------------------------------------------------
43 template< class _TMST >
44 void fpaPlugins::ExtractPathFromMinimumSpanningTree::
45 _GD0( _TMST* mst )
46 {
47   typedef fpa::Base::ExtractPathFromMinimumSpanningTree< _TMST > _TFilter;
48   auto vertices = this->GetInputData< vtkPoints >( "Seeds" );
49   if( vertices == NULL )
50     this->_Error( "No valid vertices." );
51   if( vertices->GetNumberOfPoints( ) < 2 )
52     this->_Error( "Not enough vertices." );
53
54   double b0[ 3 ], b1[ 3 ];
55   vertices->GetPoint( this->m_Parameters.GetUint( "Vertex0" ), b0 );
56   vertices->GetPoint( this->m_Parameters.GetUint( "Vertex1" ), b1 );
57
58   typename _TMST::PointType p0, p1;
59   unsigned int dim = ( _TMST::ImageDimension < 3 )? _TMST::ImageDimension: 3;
60   for( unsigned int d = 0; d < dim; ++d )
61   {
62     p0[ d ] = b0[ d ];
63     p1[ d ] = b1[ d ];
64
65   } // rof
66   typename _TMST::TVertex v0, v1;
67   mst->TransformPhysicalPointToIndex( p0, v0 );
68   mst->TransformPhysicalPointToIndex( p1, v1 );
69
70   // Create filter and connect input
71   _TFilter* filter = this->_CreateITK< _TFilter >( );
72   filter->SetInput( mst );
73   filter->SetVertex0( v0 );
74   filter->SetVertex1( v1 );
75   filter->Update( );
76
77   // Connect output and finish
78   this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
79 }
80
81 // eof - $RCSfile$