]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/Widgets/SeedWidget.cxx
ee8a59dfe3062d763e09ac186fe6164295af5c29
[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 <cpPlugins/Interface/SimpleMPRWidget.h>
6 #include <cpExtensions/Interaction/ImageInteractorStyle.h>
7
8 #include <vtkRenderWindowInteractor.h>
9
10 // -------------------------------------------------------------------------
11 cpPlugins::Widgets::SeedWidget::
12 SeedWidget( )
13   : Superclass( ),
14     m_Configured( false )
15 {
16   this->_AddInput( "ReferenceImage" );
17   this->_AddOutput< cpPlugins::Interface::PointList >( "Output" );
18
19   this->m_Parameters->ConfigureAsBool( "SeedsAreInRealSpace" );
20   this->m_Parameters->SetBool( "SeedsAreInRealSpace", true );
21 }
22
23 // -------------------------------------------------------------------------
24 cpPlugins::Widgets::SeedWidget::
25 ~SeedWidget( )
26 {
27 }
28
29 // -------------------------------------------------------------------------
30 std::string cpPlugins::Widgets::SeedWidget::
31 _GenerateData( )
32 {
33   typedef itk::ImageBase< 2 > _2DImage;
34   typedef itk::ImageBase< 3 > _3DImage;
35
36   auto image =
37     this->GetInputData< cpPlugins::Interface::Image >( "ReferenceImage" );
38   itk::DataObject* itk_image = image->GetITK< _2DImage >( );
39   if( itk_image != NULL )
40     return( this->_GD0< _2DImage >( itk_image ) );
41   else
42   {
43     itk_image = image->GetITK< _3DImage >( );
44     if( itk_image != NULL )
45       return( this->_GD0< _3DImage >( itk_image ) );
46
47   } // fi
48   return( "SeedWidget: Input image dimension not supported." );
49 }
50
51 // -------------------------------------------------------------------------
52 template< class I >
53 std::string cpPlugins::Widgets::SeedWidget::
54 _GD0( itk::DataObject* image )
55 {
56   typedef cpExtensions::Interaction::ImageInteractorStyle _S;
57
58   I* base_image = dynamic_cast< I* >( image );
59   auto out =
60     this->GetOutputData< cpPlugins::Interface::PointList >( "Output" );
61   double aux_pnt[ 3 ];
62   unsigned int dim = ( I::ImageDimension < 3 )? I::ImageDimension: 3;
63
64   out->Clear( );
65
66   // MPR
67   if( this->m_MPRViewer != NULL )
68   {
69     for( unsigned int i = 0; i < 4; ++i )
70     {
71       _S* s =
72         dynamic_cast< _S* >(
73           this->m_MPRViewer->GetInteractor( i )->GetInteractorStyle( )
74           );
75       if( s != NULL )
76       {
77         if( this->m_Configured )
78         {
79           for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i )
80           {
81             s->GetSeedAsPoint( i, aux_pnt );
82             typename I::PointType seed;
83             for( unsigned int d = 0; d < dim; ++d )
84               seed[ d ] = aux_pnt[ d ];
85             out->AddPoint( seed );
86
87           } // rof
88         }
89         else
90           s->SeedWidgetOn( );
91
92       } // fi
93
94     } // rof
95
96   } // fi
97
98   // Single interactor
99   _S* s = dynamic_cast< _S* >( this->m_SingleInteractor );
100   if( s != NULL )
101   {
102     if( this->m_Configured )
103     {
104       for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i )
105       {
106         s->GetSeedAsPoint( i, aux_pnt );
107         typename I::PointType seed;
108         for( unsigned int d = 0; d < dim; ++d )
109           seed[ d ] = aux_pnt[ d ];
110         out->AddPoint( seed );
111
112       } // rof
113     }
114     else
115       s->SeedWidgetOn( );
116
117   } // fi
118   this->m_Configured = true;
119   return( "" );
120 }
121
122 // eof - $RCSfile$