]> Creatis software - FrontAlgorithms.git/blob - lib/fpaPlugins/ImageDijkstra.cxx
...
[FrontAlgorithms.git] / lib / fpaPlugins / ImageDijkstra.cxx
1 #include "ImageDijkstra.h"
2
3 #include <cpPlugins/Interface/Image.h>
4 #include <cpPlugins/Interface/PointList.h>
5 #include <fpa/Image/Dijkstra.h>
6
7 // -------------------------------------------------------------------------
8 fpaPlugins::ImageDijkstra::
9 ImageDijkstra( )
10   : Superclass( )
11 {
12   this->_AddInput( "Input" );
13   this->_AddInput( "Seeds" );
14   this->_MakeOutput< cpPlugins::Interface::Image >( "Output" );
15
16   this->m_Parameters->ConfigureAsBool( "VisualDebug" );
17   this->m_Parameters->ConfigureAsBool( "StopAtOneFront" );
18
19   /*
20     this->m_Parameters->ConfigureAsReal( "InsideValue" );
21     this->m_Parameters->ConfigureAsReal( "OutsideValue" );
22     // TODO: this->m_Parameters->ConfigureAsPointList( "Seeds" );
23     */
24
25   this->m_Parameters->SetBool( "VisualDebug", false );
26   this->m_Parameters->SetBool( "StopAtOneFront", false );
27   /*
28     this->m_Parameters->SetReal( "InsideValue", 1 );
29     this->m_Parameters->SetReal( "OutsideValue", 0 );
30   */
31
32   std::vector< std::string > orders;
33   orders.push_back( "1" );
34   orders.push_back( "2" );
35   this->m_Parameters->ConfigureAsChoices( "NeighborhoodOrder", orders );
36   this->m_Parameters->SetSelectedChoice( "NeighborhoodOrder", "1" );
37 }
38
39 // -------------------------------------------------------------------------
40 fpaPlugins::ImageDijkstra::
41 ~ImageDijkstra( )
42 {
43 }
44
45 // -------------------------------------------------------------------------
46 std::string fpaPlugins::ImageDijkstra::
47 _GenerateData( )
48 {
49   cpPlugins::Interface::Image* input =
50     this->GetInput< cpPlugins::Interface::Image >( "Input" );
51   if( input == NULL )
52     return( "fpaPlugins::ImageDijkstra: No input image." );
53
54   itk::DataObject* image = NULL;
55   std::string r = "";
56   cpPlugins_Image_Demangle_AllScalarTypes( 2, input, image, r, _GD0 );
57   else cpPlugins_Image_Demangle_AllScalarTypes( 3, input, image, r, _GD0 );
58   else r = "fpaPlugins::ImageDijkstra: Input image type not supported.";
59   return( r );
60 }
61
62 // -------------------------------------------------------------------------
63 template< class I >
64 std::string fpaPlugins::ImageDijkstra::
65 _GD0( itk::DataObject* data )
66 {
67   /* TODO
68   typedef unsigned char                               _TOutPixel;
69   typedef itk::Image< _TOutPixel, I::ImageDimension > _TOut;
70   typedef fpa::Image::Dijkstra< I, _TOut >          _TFilter;
71   typedef typename _TFilter::TGrowingFunction         _TFunctor;
72   typedef typename I::PointType                       _TPoint;
73
74   cpPlugins::Interface::PointList* seeds =
75     this->GetInput< cpPlugins::Interface::PointList >( "Seeds" );
76   if( seeds == NULL )
77     return( "fpaPlugins::ImageDijkstra: No given seeds." );
78   I* image = dynamic_cast< I* >( data );
79
80   // Create filter and connect input
81   _TFilter* filter = this->_CreateITK< _TFilter >( );
82   filter->SetInput( image );
83
84   // Connect grow functor (or create a tautology)
85   typename _TFunctor::Pointer functor;
86   cpPlugins::Interface::DataObject* functor_wrapper =
87     this->GetInput< cpPlugins::Interface::DataObject >( "GrowFunction" );
88   if( functor_wrapper != NULL )
89     functor = functor_wrapper->GetITK< _TFunctor >( );
90   if( functor.IsNull( ) )
91     functor =
92       fpa::Image::Functors::DijkstraAllBelongsFunction< I >::New( );
93   filter->SetGrowingFunction( functor );
94
95   // Set numeric parameters
96   Superclass::TParameters* params = this->m_Parameters;
97   std::string order = params->GetSelectedChoice( "NeighborhoodOrder" );
98   filter->SetNeighborhoodOrder( order[ 0 ] - '0' );
99   filter->SetStopAtOneFront( params->GetBool( "StopAtOneFront" ) );
100   filter->SetInsideValue( _TOutPixel( params->GetReal( "InsideValue" ) ) );
101   filter->SetOutsideValue( _TOutPixel( params->GetReal( "OutsideValue" ) ) );
102
103   // Assign seeds
104   for( unsigned int s = 0; s < seeds->GetNumberOfPoints( ); ++s )
105   {
106     _TPoint pnt = seeds->GetPoint< _TPoint >( s );
107     typename I::IndexType idx;
108     if( image->TransformPhysicalPointToIndex( pnt, idx ) )
109       filter->AddSeed( idx, 0 );
110
111   } // rof
112
113   // Connect visual debugger
114   // TODO: this->m_Parameters->ConfigureAsBool( "VisualDebug", false );
115
116   // Go!!!
117   filter->Update( );
118
119   // Connect output
120   cpPlugins::Interface::Image* out =
121     this->GetOutput< cpPlugins::Interface::Image >( "Output" );
122   if( out != NULL )
123   {
124     out->SetITK< _TOut >( filter->GetOutput( ) );
125     return( "" );
126   }
127   else
128     return( "fpaPlugins::ImageDijkstra: output not correctly created." );
129   */
130   return( "" );
131 }
132
133 // eof - $RCSfile$