]> 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 <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   cpPlugins::Interface::Image* image =
37     this->GetInput< cpPlugins::Interface::Image >( "ReferenceImage" );
38   if( image == NULL )
39     return( "SeedWidget: No input image." );
40
41   itk::DataObject* itk_image = image->GetITK< _2DImage >( );
42   if( itk_image != NULL )
43     return( this->_GD0< _2DImage >( itk_image ) );
44   else
45   {
46     itk_image = image->GetITK< _3DImage >( );
47     if( itk_image != NULL )
48       return( this->_GD0< _3DImage >( itk_image ) );
49
50   } // fi
51
52   return( "SeedWidget: Input image dimension not supported." );
53 }
54
55 // -------------------------------------------------------------------------
56 template< class I >
57 std::string cpPlugins::Widgets::SeedWidget::
58 _GD0( itk::DataObject* image )
59 {
60   typedef cpExtensions::Interaction::ImageInteractorStyle _S;
61
62   I* base_image = dynamic_cast< I* >( image );
63   cpPlugins::Interface::PointList* out =
64     this->GetOutput< cpPlugins::Interface::PointList >( "Output" );
65   double aux_pnt[ 3 ];
66   unsigned int dim = ( I::ImageDimension < 3 )? I::ImageDimension: 3;
67
68   out->Clear( );
69
70   // MPR
71   if( this->m_MPRViewer != NULL )
72   {
73     for( unsigned int i = 0; i < 4; ++i )
74     {
75       _S* s =
76         dynamic_cast< _S* >(
77           this->m_MPRViewer->GetInteractor( i )->GetInteractorStyle( )
78           );
79       if( s != NULL )
80       {
81         if( this->m_Configured )
82         {
83           for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i )
84           {
85             s->GetSeedAsPoint( i, aux_pnt );
86             typename I::PointType seed;
87             for( unsigned int d = 0; d < dim; ++d )
88               seed[ d ] = aux_pnt[ d ];
89             out->AddPoint( seed );
90
91           } // rof
92         }
93         else
94           s->SeedWidgetOn( );
95
96       } // fi
97
98     } // rof
99
100   } // fi
101
102   // Single interactor
103   _S* s = dynamic_cast< _S* >( this->m_SingleInteractor.GetPointer( ) );
104   if( s != NULL )
105   {
106     if( this->m_Configured )
107     {
108       for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i )
109       {
110         s->GetSeedAsPoint( i, aux_pnt );
111         typename I::PointType seed;
112         for( unsigned int d = 0; d < dim; ++d )
113           seed[ d ] = aux_pnt[ d ];
114         out->AddPoint( seed );
115
116       } // rof
117     }
118     else
119       s->SeedWidgetOn( );
120
121   } // fi
122
123   /* TODO
124   auto iIt = this->m_Interactors.begin( );
125   for( ; iIt != this->m_Interactors.end( ); ++iIt )
126   {
127     _S* s = dynamic_cast< _S* >( ( *iIt )->GetInteractorStyle( ) );
128     if( s != NULL )
129     {
130       if( this->m_Configured )
131       {
132         for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i )
133         {
134           s->GetSeedAsPoint( i, aux_pnt );
135           typename I::PointType seed;
136           for( unsigned int d = 0; d < dim; ++d )
137             seed[ d ] = aux_pnt[ d ];
138           out->AddPoint( seed );
139
140         } // rof
141       }
142       else
143         s->SeedWidgetOn( );
144
145     } // fi
146
147   } // rof
148   */
149   this->m_Configured = true;
150   return( "" );
151 }
152
153 // eof - $RCSfile$