-#include <plugins/Plugins/EndPointsFilter.h>
-#include <cpPlugins/DataObjects/Image.h>
-#include <cpPlugins/DataObjects/Mesh.h>
-#include <fpa/Image/EndPointsFilter.h>
-#include <fpa/Image/EndPointsFilter.hxx>
-
-// -------------------------------------------------------------------------
-fpaPlugins::EndPointsFilter::
-EndPointsFilter( )
- : Superclass( )
-{
- typedef cpPlugins::DataObjects::Image _TImage;
- typedef cpPlugins::DataObjects::Mesh _TMesh;
-
- this->_ConfigureInput< _TImage >( "DistanceMap", true, false );
- this->_ConfigureInput< _TImage >( "CostMap", true, false );
- this->_ConfigureInput< _TImage >( "MST", true, false );
- this->_ConfigureOutput< _TMesh >( "EndPoints" );
- this->_ConfigureOutput< _TMesh >( "Bifurcations" );
-}
-
-// -------------------------------------------------------------------------
-fpaPlugins::EndPointsFilter::
-~EndPointsFilter( )
-{
-}
-
-// -------------------------------------------------------------------------
-void fpaPlugins::EndPointsFilter::
-_GenerateData( )
-{
- auto o = this->GetInputData( "DistanceMap" );
- cpPlugins_Demangle_ImageScalars_Dims( o, _GD0 );
- else this->_Error( "Invalid input image." );
-}
-
-// -------------------------------------------------------------------------
-template< class _TDistanceMap >
-void fpaPlugins::EndPointsFilter::
-_GD0( _TDistanceMap* dmap )
-{
- auto cmap = this->GetInputData< _TDistanceMap >( "CostMap" );
- if( cmap != NULL )
- this->_GD1( dmap, cmap );
- else
- this->_Error( "Temporary error: invalid cost map." );
-}
-
-// -------------------------------------------------------------------------
-template< class _TDistanceMap, class _TCostMap >
-void fpaPlugins::EndPointsFilter::
-_GD1( _TDistanceMap* dmap, _TCostMap* cmap )
-{
- typedef fpa::Image::EndPointsFilter< _TDistanceMap, _TCostMap > _TFilter;
- typedef typename _TFilter::TMST _TMST;
-
- auto mst = this->GetInputData< _TMST >( "MST" );
- if( mst == NULL )
- this->_Error( "Invalid MST." );
-
-
- auto filter = this->_CreateITK< _TFilter >( );
- filter->SetDistanceMap( dmap );
- filter->SetCostMap( cmap );
- filter->SetMST( mst );
- filter->Compute( );
-
- auto ep = filter->GetEndPoints( );
- auto bi = filter->GetBifurcations( );
-
- auto ep_pd = this->GetOutputData< vtkPolyData >( "EndPoints" );
- if( ep_pd == NULL )
- {
- auto points = vtkSmartPointer< vtkPoints >::New( );
- auto verts = vtkSmartPointer< vtkCellArray >::New( );
- auto lines = vtkSmartPointer< vtkCellArray >::New( );
- auto polys = vtkSmartPointer< vtkCellArray >::New( );
- auto strips = vtkSmartPointer< vtkCellArray >::New( );
- auto pd = vtkSmartPointer< vtkPolyData >::New( );
- pd->SetPoints( points );
- pd->SetVerts( verts );
- pd->SetLines( lines );
- pd->SetPolys( polys );
- pd->SetStrips( strips );
-
- this->GetOutput( "EndPoints" )->SetVTK( pd );
- ep_pd = this->GetOutputData< vtkPolyData >( "EndPoints" );
-
- } // fi
-
- for( auto iIt = ep.begin( ); iIt != ep.end( ); ++iIt )
- {
- typename _TCostMap::PointType p;
- cmap->TransformIndexToPhysicalPoint( *iIt, p );
-
- if( _TCostMap::ImageDimension == 1 )
- ep_pd->GetPoints( )->InsertNextPoint( p[ 0 ], 0, 0 );
- else if( _TCostMap::ImageDimension == 2 )
- ep_pd->GetPoints( )->InsertNextPoint( p[ 0 ], p[ 1 ], 0 );
- else if( _TCostMap::ImageDimension > 2 )
- ep_pd->GetPoints( )->InsertNextPoint( p[ 0 ], p[ 1 ], p[ 2 ] );
-
- ep_pd->GetVerts( )->InsertNextCell( 1 );
- ep_pd->GetVerts( )->InsertCellPoint( ep_pd->GetNumberOfPoints( ) - 1 );
-
- } // rof
-}
-
-// eof - $RCSfile$