#include "ExtractPathFromMinimumSpanningTree.h" #include #include #include // ------------------------------------------------------------------------- fpaPlugins::ExtractPathFromMinimumSpanningTree:: ExtractPathFromMinimumSpanningTree( ) : Superclass( ) { this->_AddInput( "MST" ); this->_AddInput( "Seeds" ); this->_AddOutput< cpPlugins::Path >( "Output" ); this->m_Parameters.ConfigureAsUint( "Vertex0" ); this->m_Parameters.ConfigureAsUint( "Vertex1" ); this->m_Parameters.SetUint( "Vertex0", 0 ); this->m_Parameters.SetUint( "Vertex1", 1 ); } // ------------------------------------------------------------------------- fpaPlugins::ExtractPathFromMinimumSpanningTree:: ~ExtractPathFromMinimumSpanningTree( ) { } // ------------------------------------------------------------------------- void fpaPlugins::ExtractPathFromMinimumSpanningTree:: _GenerateData( ) { typedef fpa::Image::MinimumSpanningTree< 2 > _2DMST; typedef fpa::Image::MinimumSpanningTree< 3 > _3DMST; auto mst = this->GetInputData< itk::DataObject >( "MST" ); auto mst2 = dynamic_cast< _2DMST* >( mst ); auto mst3 = dynamic_cast< _3DMST* >( mst ); if ( mst2 != NULL ) this->_GD0( mst2 ); else if( mst3 != NULL ) this->_GD0( mst3 ); else this->_Error( "Invalid input MST." ); } // ------------------------------------------------------------------------- template< class _TMST > void fpaPlugins::ExtractPathFromMinimumSpanningTree:: _GD0( _TMST* mst ) { typedef fpa::Base::ExtractPathFromMinimumSpanningTree< _TMST > _TFilter; auto vertices = this->GetInputData< vtkPoints >( "Seeds" ); if( vertices == NULL ) this->_Error( "No valid vertices." ); if( vertices->GetNumberOfPoints( ) < 2 ) this->_Error( "Not enough vertices." ); double b0[ 3 ], b1[ 3 ]; vertices->GetPoint( this->m_Parameters.GetUint( "Vertex0" ), b0 ); vertices->GetPoint( this->m_Parameters.GetUint( "Vertex1" ), b1 ); typename _TMST::PointType p0, p1; unsigned int dim = ( _TMST::ImageDimension < 3 )? _TMST::ImageDimension: 3; for( unsigned int d = 0; d < dim; ++d ) { p0[ d ] = b0[ d ]; p1[ d ] = b1[ d ]; } // rof typename _TMST::TVertex v0, v1; mst->TransformPhysicalPointToIndex( p0, v0 ); mst->TransformPhysicalPointToIndex( p1, v1 ); // Create filter and connect input _TFilter* filter = this->_CreateITK< _TFilter >( ); filter->SetInput( mst ); filter->SetVertex0( v0 ); filter->SetVertex1( v1 ); filter->Update( ); // Connect output and finish this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) ); } // eof - $RCSfile$