]> Creatis software - FrontAlgorithms.git/blob - plugins/ImageAlgorithms/SkeletonFilter.cxx
8d434c75311e23b7858d8540164824c06e12f63d
[FrontAlgorithms.git] / plugins / ImageAlgorithms / SkeletonFilter.cxx
1 #include <ImageAlgorithms/SkeletonFilter.h>
2 #include <cpInstances/DataObjects/Image.h>
3 #include <cpInstances/DataObjects/Skeleton.h>
4
5 #include <fpa/Image/SkeletonFilter.h>
6 #include <itkImage.h>
7 #include <vtkPolyData.h>
8
9 // -------------------------------------------------------------------------
10 fpaPluginsImageAlgorithms::SkeletonFilter::
11 SkeletonFilter( )
12   : Superclass( )
13 {
14   typedef cpInstances::DataObjects::Image    _TImage;
15   typedef cpInstances::DataObjects::Skeleton _TSkeleton;
16   typedef cpPlugins::Pipeline::DataObject _TData;
17
18   this->_ConfigureInput< _TImage >( "Input", true, false );
19   this->_ConfigureInput< _TData >( "Seeds", true, false );
20   this->_ConfigureOutput< _TSkeleton >( "Skeleton" );
21   this->_ConfigureOutput< _TImage >( "Marks" );
22 }
23
24 // -------------------------------------------------------------------------
25 fpaPluginsImageAlgorithms::SkeletonFilter::
26 ~SkeletonFilter( )
27 {
28 }
29
30 // -------------------------------------------------------------------------
31 void fpaPluginsImageAlgorithms::SkeletonFilter::
32 _GenerateData( )
33 {
34   auto o = this->GetInputData( "Input" );
35   cpPlugins_Demangle_Image_RealPixels_AllDims_1( o, _GD0 )
36     this->_Error( "Invalid input image." );
37 }
38
39 // -------------------------------------------------------------------------
40 template< class _TImage >
41 void fpaPluginsImageAlgorithms::SkeletonFilter::
42 _GD0( _TImage* image )
43 {
44   typedef fpa::Image::SkeletonFilter< _TImage > _TFilter;
45   auto filter = this->_CreateITK< _TFilter >( );
46   filter->SetInput( image );
47
48   auto seeds = this->GetInputData< vtkPolyData >( "Seeds" );
49   if( seeds != NULL )
50   {
51     typename _TImage::PointType pnt;
52     typename _TImage::IndexType idx;
53     unsigned int dim =
54       ( _TImage::ImageDimension < 3 )? _TImage::ImageDimension: 3;
55
56     for( int i = 0; i < seeds->GetNumberOfPoints( ); ++i )
57     {
58       double buf[ 3 ];
59       seeds->GetPoint( i, buf );
60       pnt.Fill( 0 );
61       for( unsigned int d = 0; d < dim; ++d )
62         pnt[ d ] = buf[ d ];
63
64       if( image->TransformPhysicalPointToIndex( pnt, idx ) )
65         filter->AddSeed( idx, 0 );
66
67     } // rof
68
69   } // fi
70
71   filter->Update( );
72   this->GetOutput( "Skeleton" )->SetITK( filter->GetSkeleton( ) );
73   this->GetOutput( "Marks" )->SetITK( filter->GetMarks( ) );
74 }
75
76 // eof - $RCSfile$