#include #include #include #include #include // ------------------------------------------------------------------------- fpaPlugins::ImageDijkstra:: ImageDijkstra( ) : Superclass( ) { typedef cpPlugins::BaseObjects::DataObject _TData; typedef cpInstances::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" ); } // ------------------------------------------------------------------------- fpaPlugins::ImageDijkstra:: ~ImageDijkstra( ) { } // ------------------------------------------------------------------------- void fpaPlugins::ImageDijkstra:: _GenerateData( ) { auto o = this->GetInputData( "Input" ); cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 ) this->_Error( "Invalid input image." ); } // ------------------------------------------------------------------------- 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, _TFloat >( image ); else if( rtype == "double" ) this->_GD1< _TImage, _TDouble >( image ); } // ------------------------------------------------------------------------- template< class _TInputImage, class _TOutputImage > void fpaPlugins::ImageDijkstra:: _GD1( _TInputImage* image ) { 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 ) { 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 ]; if( image->TransformPhysicalPointToIndex( pnt, idx ) ) filter->AddSeed( idx, 0 ); } // rof } // fi // Assign outputs filter->Update( ); this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) ); this->GetOutput( "MST" )->SetITK( filter->GetMinimumSpanningTree( ) ); } // eof - $RCSfile$