X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=plugins%2FPlugins%2FImageDijkstra.cxx;h=7017c77af94f38605b68ae00327f7cf1e79b849f;hb=a993dd7dc7f3154d00eed3d3a4796fb9e3ff582d;hp=be69f49e8f91f4dfe303e82d78f0111da9614d02;hpb=56b8bb48cc05a297a3faa264f8f2a88de21ef203;p=FrontAlgorithms.git diff --git a/plugins/Plugins/ImageDijkstra.cxx b/plugins/Plugins/ImageDijkstra.cxx index be69f49..7017c77 100644 --- a/plugins/Plugins/ImageDijkstra.cxx +++ b/plugins/Plugins/ImageDijkstra.cxx @@ -1,12 +1,9 @@ -#include "ImageDijkstra.h" -// TODO: #include "MinimumSpanningTree.h" - +#include #include -#include +#include -#include +#include #include -#include #include // ------------------------------------------------------------------------- @@ -14,15 +11,18 @@ fpaPlugins::ImageDijkstra:: ImageDijkstra( ) : Superclass( ) { - this->_ConfigureInput< cpPlugins::BaseObjects::DataObject >( "CostFunctor", false, false ); - this->_ConfigureOutput< cpPlugins::BaseObjects::DataObject >( "MST" ); + typedef cpPlugins::BaseObjects::DataObject _TData; + typedef cpPlugins::DataObjects::Image _TMST; + + this->_ConfigureInput< _TData >( "Cost", false, false ); + this->_ConfigureInput< _TData >( "CostConversion", false, false ); + this->_ConfigureOutput< _TMST >( "MST" ); + std::vector< std::string > choices; choices.push_back( "float" ); choices.push_back( "double" ); this->m_Parameters.ConfigureAsChoices( "ResultType", choices ); this->m_Parameters.SetSelectedChoice( "ResultType", "float" ); - this->m_Parameters.ConfigureAsBool( "FillNodeQueue" ); - this->m_Parameters.SetBool( "FillNodeQueue", false ); } // ------------------------------------------------------------------------- @@ -45,41 +45,66 @@ template< class _TImage > void fpaPlugins::ImageDijkstra:: _GD0( _TImage* image ) { + typedef itk::Image< float, _TImage::ImageDimension > _TFloat; + typedef itk::Image< double, _TImage::ImageDimension > _TDouble; + auto rtype = this->m_Parameters.GetSelectedChoice( "ResultType" ); - if( rtype == "float" ) this->_GD1< _TImage, float >( image ); - else if( rtype == "double" ) this->_GD1< _TImage, double >( image ); + if ( rtype == "float" ) this->_GD1< _TImage, _TFloat >( image ); + else if( rtype == "double" ) this->_GD1< _TImage, _TDouble >( image ); } // ------------------------------------------------------------------------- -template< class _TInputImage, class _TOutput > +template< class _TInputImage, class _TOutputImage > void fpaPlugins::ImageDijkstra:: -_GD1( _TInputImage* input ) +_GD1( _TInputImage* image ) { - typedef itk::Image< _TOutput, _TInputImage::ImageDimension > _TOutputImage; - typedef fpa::Image::Dijkstra< _TInputImage, _TOutputImage > _TFilter; - typedef typename _TFilter::TCostConversionFunction _TCostFunctor; - - // Get functor - auto base_functor = - this->GetInputData< itk::LightObject >( "CostFunctor" ); - _TCostFunctor* functor = NULL; - if( base_functor != NULL ) + typedef fpa::Image::Dijkstra< _TInputImage, _TOutputImage > _TFilter; + typedef typename _TFilter::TCostConversionFunction _TCostConversion; + typedef typename _TFilter::TCostFunction _TCost; + typedef typename _TFilter::TNeighborhoodFunction _TNeighborhood; + + // Get functors + auto neig = this->GetInputData< _TNeighborhood >( "Neighborhood" ); + auto cost = this->GetInputData< _TCost >( "Cost" ); + auto conv = this->GetInputData< _TCostConversion >( "CostConversion" ); + + // Configure filter + auto filter = this->_CreateITK< _TFilter >( ); + filter->SetInput( image ); + if( neig != NULL ) + filter->SetNeighborhoodFunction( neig ); + if( cost != NULL ) + filter->SetCostFunction( cost ); + if( conv != NULL ) + filter->SetCostConversionFunction( conv ); + filter->SetStopAtOneFront( this->m_Parameters.GetBool( "StopAtOneFront" ) ); + + // Assign seeds + auto seeds = this->GetInputData< vtkPolyData >( "Seeds" ); + if( seeds != NULL ) { - functor = dynamic_cast< _TCostFunctor* >( base_functor ); - if( functor == NULL ) - this->_Error( "Given cost functor is invalid." ); + typename _TInputImage::PointType pnt; + typename _TInputImage::IndexType idx; + unsigned int dim = + ( _TInputImage::ImageDimension < 3 )? _TInputImage::ImageDimension: 3; + for( int i = 0; i < seeds->GetNumberOfPoints( ); ++i ) + { + double buf[ 3 ]; + seeds->GetPoint( i, buf ); + pnt.Fill( 0 ); + for( unsigned int d = 0; d < dim; ++d ) + pnt[ d ] = buf[ d ]; - } // fi + if( image->TransformPhysicalPointToIndex( pnt, idx ) ) + filter->AddSeed( idx, 0 ); - // Create filter - _TFilter* filter = this->_ConfigureFilter< _TFilter >( ); - // TODO: filter->SetFillNodeQueue( this->m_Parameters.GetBool( "FillNodeQueue" ) ); - filter->SetCostConversionFunction( functor ); + } // rof - // Go!!! - this->_ExecuteFilter( filter ); + } // fi - // Connect remaining output + // Assign outputs + filter->Update( ); + this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) ); this->GetOutput( "MST" )->SetITK( filter->GetMinimumSpanningTree( ) ); }