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