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