1 #include "ImageDijkstra.h"
3 #include <cpPlugins/Interface/Image.h>
4 #include <cpPlugins/Interface/PointList.h>
5 #include <fpa/Image/Dijkstra.h>
7 // -------------------------------------------------------------------------
8 fpaPlugins::ImageDijkstra::
12 this->_AddInput( "Input" );
13 this->_AddInput( "Seeds" );
14 this->_MakeOutput< cpPlugins::Interface::Image >( "Output" );
16 this->m_Parameters->ConfigureAsBool( "VisualDebug" );
17 this->m_Parameters->ConfigureAsBool( "StopAtOneFront" );
20 this->m_Parameters->ConfigureAsReal( "InsideValue" );
21 this->m_Parameters->ConfigureAsReal( "OutsideValue" );
22 // TODO: this->m_Parameters->ConfigureAsPointList( "Seeds" );
25 this->m_Parameters->SetBool( "VisualDebug", false );
26 this->m_Parameters->SetBool( "StopAtOneFront", false );
28 this->m_Parameters->SetReal( "InsideValue", 1 );
29 this->m_Parameters->SetReal( "OutsideValue", 0 );
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" );
39 // -------------------------------------------------------------------------
40 fpaPlugins::ImageDijkstra::
45 // -------------------------------------------------------------------------
46 std::string fpaPlugins::ImageDijkstra::
49 cpPlugins::Interface::Image* input =
50 this->GetInput< cpPlugins::Interface::Image >( "Input" );
52 return( "fpaPlugins::ImageDijkstra: No input image." );
54 itk::DataObject* image = NULL;
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.";
62 // -------------------------------------------------------------------------
64 std::string fpaPlugins::ImageDijkstra::
65 _GD0( itk::DataObject* data )
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;
74 cpPlugins::Interface::PointList* seeds =
75 this->GetInput< cpPlugins::Interface::PointList >( "Seeds" );
77 return( "fpaPlugins::ImageDijkstra: No given seeds." );
78 I* image = dynamic_cast< I* >( data );
80 // Create filter and connect input
81 _TFilter* filter = this->_CreateITK< _TFilter >( );
82 filter->SetInput( image );
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( ) )
92 fpa::Image::Functors::DijkstraAllBelongsFunction< I >::New( );
93 filter->SetGrowingFunction( functor );
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" ) ) );
104 for( unsigned int s = 0; s < seeds->GetNumberOfPoints( ); ++s )
106 _TPoint pnt = seeds->GetPoint< _TPoint >( s );
107 typename I::IndexType idx;
108 if( image->TransformPhysicalPointToIndex( pnt, idx ) )
109 filter->AddSeed( idx, 0 );
113 // Connect visual debugger
114 // TODO: this->m_Parameters->ConfigureAsBool( "VisualDebug", false );
120 cpPlugins::Interface::Image* out =
121 this->GetOutput< cpPlugins::Interface::Image >( "Output" );
124 out->SetITK< _TOut >( filter->GetOutput( ) );
128 return( "fpaPlugins::ImageDijkstra: output not correctly created." );