]> Creatis software - FrontAlgorithms.git/blobdiff - plugins/Plugins/SkeletonFilter.cxx
Skeletonization improved.
[FrontAlgorithms.git] / plugins / Plugins / SkeletonFilter.cxx
index d68db4fc516fb9b71b70091377da5b448067c298..31f0f5c6cd3ca8031174016ae7b760a2a8e98c83 100644 (file)
@@ -5,11 +5,7 @@
 
 #include <fpa/Image/SkeletonFilter.h>
 #include <itkImage.h>
-
-/* TODO
-   #include <fpa/Image/SkeletonFilter.hxx>
-   #include <itkSimpleDataObjectDecorator.hxx>
-*/
+#include <vtkPolyData.h>
 
 // -------------------------------------------------------------------------
 fpaPlugins::SkeletonFilter::
@@ -18,16 +14,12 @@ SkeletonFilter( )
 {
   typedef cpPlugins::DataObjects::Image    _TImage;
   typedef cpPlugins::DataObjects::Skeleton _TSkeleton;
+  typedef cpPlugins::BaseObjects::DataObject _TData;
 
-  this->_ConfigureInput< _TImage >( "DistanceMap", true, false );
-  this->_ConfigureInput< _TImage >( "CostMap", true, false );
-  this->_ConfigureInput< _TImage >( "MST", true, false );
+  this->_ConfigureInput< _TImage >( "Input", true, false );
+  this->_ConfigureInput< _TData >( "Seeds", true, false );
   this->_ConfigureOutput< _TSkeleton >( "Skeleton" );
   this->_ConfigureOutput< _TImage >( "Marks" );
-  /* TODO
-     this->_ConfigureOutput< _TMesh >( "EndPoints" );
-     this->_ConfigureOutput< _TMesh >( "Bifurcations" );
-  */
 }
 
 // -------------------------------------------------------------------------
@@ -40,82 +32,46 @@ fpaPlugins::SkeletonFilter::
 void fpaPlugins::SkeletonFilter::
 _GenerateData( )
 {
-  auto o = this->GetInputData( "DistanceMap" );
+  auto o = this->GetInputData( "Input" );
   cpPlugins_Demangle_Image_RealPixels_AllDims_1( o, _GD0 )
     this->_Error( "Invalid input image." );
 }
 
 // -------------------------------------------------------------------------
-template< class _TDistanceMap >
+template< class _TImage >
 void fpaPlugins::SkeletonFilter::
-_GD0( _TDistanceMap* dmap )
+_GD0( _TImage* image )
 {
-  auto o = this->GetInputData( "CostMap" );
-  cpPlugins_Demangle_Image_RealPixels_2( o, _GD1, _TDistanceMap::ImageDimension, dmap )
-    this->_Error( "Invalid input image." );
-}
-
-// -------------------------------------------------------------------------
-template< class _TCostMap, class _TDistanceMap >
-void fpaPlugins::SkeletonFilter::
-_GD1( _TCostMap* cmap, _TDistanceMap* dmap )
-{
-  typedef fpa::Image::SkeletonFilter< _TDistanceMap, _TCostMap > _TFilter;
-  typedef typename _TFilter::TMST _TMST;
-
-  auto mst = this->GetInputData< _TMST >( "MST" );
-  if( mst == NULL )
-    this->_Error( "Invalid MST." );
-
+  typedef fpa::Image::SkeletonFilter< _TImage > _TFilter;
   auto filter = this->_CreateITK< _TFilter >( );
-  filter->SetDistanceMap( dmap );
-  filter->SetCostMap( cmap );
-  filter->SetMinimumSpanningTree( mst );
-  filter->Update( );
-  this->GetOutput( "Skeleton" )->SetITK( filter->GetSkeleton( ) );
-  this->GetOutput( "Marks" )->SetITK( filter->GetMarks( ) );
-
-  /* TODO
-     auto ep = filter->GetEndPoints( );
-     auto bi = filter->GetBifurcations( );
+  filter->SetInput( image );
 
-     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 );
+  auto seeds = this->GetInputData< vtkPolyData >( "Seeds" );
+  if( seeds != NULL )
+  {
+    typename _TImage::PointType pnt;
+    typename _TImage::IndexType idx;
+    unsigned int dim =
+      ( _TImage::ImageDimension < 3 )? _TImage::ImageDimension: 3;
 
-     this->GetOutput( "EndPoints" )->SetVTK( pd );
-     ep_pd = this->GetOutputData< vtkPolyData >( "EndPoints" );
+    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 );
 
-     for( auto iIt = ep.begin( ); iIt != ep.end( ); ++iIt )
-     {
-     typename _TCostMap::PointType p;
-     cmap->TransformIndexToPhysicalPoint( *iIt, p );
+    } // rof
 
-     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 ] );
+  } // fi
 
-     ep_pd->GetVerts( )->InsertNextCell( 1 );
-     ep_pd->GetVerts( )->InsertCellPoint( ep_pd->GetNumberOfPoints( ) - 1 );
-
-     } // rof
-  */
+  filter->Update( );
+  this->GetOutput( "Skeleton" )->SetITK( filter->GetSkeleton( ) );
+  this->GetOutput( "Marks" )->SetITK( filter->GetMarks( ) );
 }
 
 // eof - $RCSfile$