1 #include "ImageDijkstra.h"
3 #include <cpPlugins/Interface/Image.h>
4 #include <cpPlugins/Interface/PointList.h>
5 #include <fpaPlugins/MinimumSpanningTree.h>
7 #include <fpa/Image/Dijkstra.h>
8 #include <fpa/VTK/Image2DObserver.h>
9 #include <fpa/VTK/Image3DObserver.h>
10 #include <fpa/Base/Functors/InvertCostFunction.h>
12 #include <vtkRenderWindow.h>
13 #include <vtkRenderWindowInteractor.h>
15 // -------------------------------------------------------------------------
16 fpaPlugins::ImageDijkstra::
20 this->_AddInput( "Input" );
21 this->_AddInput( "Seeds" );
22 this->_AddOutput< cpPlugins::Interface::Image >( "Output" );
23 this->_AddOutput< fpaPlugins::MinimumSpanningTree >( "MinimumSpanningTree" );
25 this->m_Parameters->ConfigureAsBool( "VisualDebug" );
26 this->m_Parameters->ConfigureAsBool( "StopAtOneFront" );
27 this->m_Parameters->SetBool( "VisualDebug", false );
28 this->m_Parameters->SetBool( "StopAtOneFront", false );
30 std::vector< std::string > orders;
31 orders.push_back( "1" );
32 orders.push_back( "2" );
33 this->m_Parameters->ConfigureAsChoices( "NeighborhoodOrder", orders );
34 this->m_Parameters->SetSelectedChoice( "NeighborhoodOrder", "1" );
37 // -------------------------------------------------------------------------
38 fpaPlugins::ImageDijkstra::
43 // -------------------------------------------------------------------------
44 std::string fpaPlugins::ImageDijkstra::
48 this->GetInputData< cpPlugins::Interface::Image >( "Input" );
50 return( "fpaPlugins::ImageDijkstra: No input image." );
52 itk::DataObject* image = NULL;
54 cpPlugins_Image_Demangle_AllScalarTypes( 2, input, image, r, _GD0 );
55 else cpPlugins_Image_Demangle_AllScalarTypes( 3, input, image, r, _GD0 );
56 else r = "fpaPlugins::ImageDijkstra: Input image type not supported.";
60 // -------------------------------------------------------------------------
62 std::string fpaPlugins::ImageDijkstra::
63 _GD0( itk::DataObject* data )
65 typedef typename I::PixelType _TOutPixel;
66 typedef itk::Image< _TOutPixel, I::ImageDimension > _TOut;
67 typedef fpa::Image::Dijkstra< I, _TOut > _TFilter;
68 typedef typename _TFilter::TResult _TCost;
69 typedef fpa::Base::Functors::InvertCostFunction< _TCost > _TCostFunctor;
70 typedef typename I::PointType _TPoint;
71 typedef typename _TFilter::TMinimumSpanningTree _TMST;
74 this->GetInputData< cpPlugins::Interface::PointList >( "Seeds" );
76 return( "fpaPlugins::ImageRegionGrow: No given seeds." );
77 I* image = dynamic_cast< I* >( data );
79 // Create filter and connect input
80 _TFilter* filter = this->_CreateITK< _TFilter >( );
81 filter->SetInput( image );
83 // Connect cost functor
84 typename _TCostFunctor::Pointer functor = _TCostFunctor::New( );
85 filter->SetConversionFunction( functor );
87 // Set numeric parameters
88 Superclass::TParameters* params = this->m_Parameters;
89 std::string order = params->GetSelectedChoice( "NeighborhoodOrder" );
90 filter->SetNeighborhoodOrder( order[ 0 ] - '0' );
91 filter->SetStopAtOneFront( params->GetBool( "StopAtOneFront" ) );
94 filter->ClearSeeds( );
95 for( unsigned int s = 0; s < seeds->GetNumberOfPoints( ); ++s )
97 _TPoint pnt = seeds->GetPoint< _TPoint >( s );
98 typename I::IndexType idx;
99 if( image->TransformPhysicalPointToIndex( pnt, idx ) )
100 filter->AddSeed( idx, 0 );
105 this->_ConfigureDebugger( filter );
107 this->_DeconfigureDebugger( filter );
111 this->GetOutputData< cpPlugins::Interface::Image >( "Output" );
113 this->GetOutputData< fpaPlugins::MinimumSpanningTree >( "MinimumSpanningTree" );
115 out->SetITK< _TOut >( filter->GetOutput( ) );
117 return( "fpaPlugins::ImageDijkstra: output not correctly created." );
121 mst->SetITK< _TMST >( filter->GetMinimumSpanningTree( ) );
125 return( "fpaPlugins::ImageDijkstra: minimum spanning tree." );