]> Creatis software - FrontAlgorithms.git/blob - lib/fpaPlugins/ExtractBranchesFromMinimumSpanningTree.cxx
...
[FrontAlgorithms.git] / lib / fpaPlugins / ExtractBranchesFromMinimumSpanningTree.cxx
1 #include "ExtractBranchesFromMinimumSpanningTree.h"
2
3 #include <itkIndex.h>
4
5 #include <cpPlugins/Interface/PointList.h>
6 #include <cpPlugins/Interface/PolyLineParametricPath.h>
7 #include <fpaPlugins/MinimumSpanningTree.h>
8
9 #include <fpa/Base/MinimumSpanningTree.h>
10 #include <fpa/Base/ExtractBranchesFromMinimumSpanningTree.h>
11
12 // -------------------------------------------------------------------------
13 fpaPlugins::ExtractBranchesFromMinimumSpanningTree::
14 ExtractBranchesFromMinimumSpanningTree( )
15   : Superclass( )
16 {
17   this->_AddInput( "MinimumSpanningTree" );
18   this->_AddInput( "EndPoints" );
19   this->_AddOutput< cpPlugins::Interface::PolyLineParametricPath >( "Output" );
20 }
21
22 // -------------------------------------------------------------------------
23 fpaPlugins::ExtractBranchesFromMinimumSpanningTree::
24 ~ExtractBranchesFromMinimumSpanningTree( )
25 {
26 }
27
28 // -------------------------------------------------------------------------
29 std::string fpaPlugins::ExtractBranchesFromMinimumSpanningTree::
30 _GenerateData( )
31 {
32   std::string err = this->_GD0< 2 >( );
33   if( err != "" )
34     err = this->_GD0< 3 >( );
35   if( err != "" )
36     err = this->_GD0< 4 >( );
37   return( err );
38 }
39
40 // -------------------------------------------------------------------------
41 template< unsigned int D >
42 std::string fpaPlugins::ExtractBranchesFromMinimumSpanningTree::
43 _GD0( )
44 {
45   typedef itk::Index< D >                                           _V;
46   typedef itk::Functor::IndexLexicographicCompare< D >              _VC;
47   typedef fpa::Base::MinimumSpanningTree< _V, _VC >                 _MST;
48   typedef fpa::Base::ExtractBranchesFromMinimumSpanningTree< _MST > _Filter;
49
50   // Get inputs
51   auto tree =
52     this->GetInputData< fpaPlugins::MinimumSpanningTree >(
53       "MinimumSpanningTree"
54       )->GetITK< _MST >( );
55   if( tree == NULL )
56     return( "fpaPlugins::ExtractBranchesFromMinimumSpanningTree: Input MST type not supported." );
57   auto endpoints =
58     this->GetInputData< cpPlugins::Interface::PointList >( "EndPoints" );
59   if( endpoints->GetNumberOfPoints( ) < 2 )
60     return( "fpaPlugins::ExtractBranchesFromMinimumSpanningTree: Not enough end-points (<2)." );
61   if( endpoints->HaveEuclideanPoints( ) )
62     return( "fpaPlugins::ExtractBranchesFromMinimumSpanningTree: end-points are on euclidean space." );
63
64   // Create filter and connect input
65   _Filter* filter = this->_CreateITK< _Filter >( );
66   filter->SetInput( tree );
67   for( unsigned int i = 0; i < endpoints->GetNumberOfPoints( ); ++i )
68     filter->AddEndPoint( endpoints->GetPoint< _V >( i ) );
69   filter->Update( );
70
71   // Connect output and finish
72   auto out =
73     this->GetOutputData< cpPlugins::Interface::PolyLineParametricPath >( "Output" );
74   out->SetITK( filter->GetOutput( ) );
75   return( "" );
76 }
77
78 // eof - $RCSfile$