]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/Widgets/SeedWidget.cxx
...
[cpPlugins.git] / lib / cpPlugins / Plugins / Widgets / SeedWidget.cxx
1 #include "SeedWidget.h"
2
3 #include <cpPlugins/Interface/Image.h>
4 #include <cpPlugins/Interface/PointList.h>
5 #include <cpExtensions/Interaction/ImageInteractorStyle.h>
6
7 #include <vtkRenderWindowInteractor.h>
8
9 // -------------------------------------------------------------------------
10 cpPlugins::Widgets::SeedWidget::
11 SeedWidget( )
12   : Superclass( ),
13     m_Configured( false )
14 {
15   this->_AddInput( "ReferenceImage" );
16   this->_MakeOutput< cpPlugins::Interface::PointList >( "Output" );
17
18   this->m_Parameters->ConfigureAsBool( "SeedsAreInRealSpace" );
19   this->m_Parameters->SetBool( "SeedsAreInRealSpace", true );
20 }
21
22 // -------------------------------------------------------------------------
23 cpPlugins::Widgets::SeedWidget::
24 ~SeedWidget( )
25 {
26 }
27
28 // -------------------------------------------------------------------------
29 std::string cpPlugins::Widgets::SeedWidget::
30 _GenerateData( )
31 {
32   typedef itk::ImageBase< 2 > _2DImage;
33   typedef itk::ImageBase< 3 > _3DImage;
34
35   cpPlugins::Interface::Image* image =
36     this->GetInput< cpPlugins::Interface::Image >( "ReferenceImage" );
37   if( image == NULL )
38     return( "SeedWidget: No input image." );
39
40   itk::DataObject* itk_image = image->GetITK< _2DImage >( );
41   if( itk_image != NULL )
42     return( this->_GD0< _2DImage >( itk_image ) );
43   else
44   {
45     itk_image = image->GetITK< _3DImage >( );
46     if( itk_image != NULL )
47       return( this->_GD0< _3DImage >( itk_image ) );
48
49   } // fi
50
51   return( "SeedWidget: Input image dimension not supported." );
52 }
53
54 // -------------------------------------------------------------------------
55 template< class I >
56 std::string cpPlugins::Widgets::SeedWidget::
57 _GD0( itk::DataObject* image )
58 {
59   typedef cpExtensions::Interaction::ImageInteractorStyle _S;
60
61   I* base_image = dynamic_cast< I* >( image );
62   cpPlugins::Interface::PointList* out =
63     this->GetOutput< cpPlugins::Interface::PointList >( "Output" );
64   double aux_pnt[ 3 ];
65   unsigned int dim = ( I::ImageDimension < 3 )? I::ImageDimension: 3;
66
67   out->Clear( );
68   auto iIt = this->m_Interactors.begin( );
69   for( ; iIt != this->m_Interactors.end( ); ++iIt )
70   {
71     _S* s = dynamic_cast< _S* >( ( *iIt )->GetInteractorStyle( ) );
72     if( s != NULL )
73     {
74       if( this->m_Configured )
75       {
76         for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i )
77         {
78           s->GetSeedAsPoint( i, aux_pnt );
79           typename I::PointType seed;
80           for( unsigned int d = 0; d < dim; ++d )
81             seed[ d ] = aux_pnt[ d ];
82           out->AddPoint( seed );
83
84         } // rof
85       }
86       else
87         s->SeedWidgetOn( );
88
89     } // fi
90
91   } // rof
92   this->m_Configured = true;
93   return( "" );
94 }
95
96 // eof - $RCSfile$