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