]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/Widgets/SeedWidget.cxx
MAC compilation issues solved... Now some tests please
[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", true );
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   std::cout << "update seeds" << std::endl;
65
66   typedef cpExtensions::Interaction::ImageInteractorStyle _S;
67
68   I* base_image = dynamic_cast< I* >( image );
69   auto out =
70     this->GetOutputData< cpPlugins::Interface::PointList >( "Output" );
71   double aux_pnt[ 3 ];
72   unsigned int dim = ( I::ImageDimension < 3 )? I::ImageDimension: 3;
73
74   out->Clear( );
75
76   // MPR
77   if( this->m_MPRViewer != NULL )
78   {
79     for( unsigned int i = 0; i < 4; ++i )
80     {
81       _S* s =
82         dynamic_cast< _S* >(
83           this->m_MPRViewer->GetInteractor( i )->GetInteractorStyle( )
84           );
85       if( s != NULL )
86       {
87         if( this->m_Configured )
88         {
89           for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i )
90           {
91             s->GetSeedAsPoint( i, aux_pnt );
92             typename I::PointType seed;
93             for( unsigned int d = 0; d < dim; ++d )
94               seed[ d ] = aux_pnt[ d ];
95             out->AddPoint( seed );
96
97           } // rof
98         }
99         else
100           s->SeedWidgetOn( );
101
102       } // fi
103
104     } // rof
105
106   } // fi
107
108   // Single interactor
109   _S* s = dynamic_cast< _S* >( this->m_SingleInteractor );
110   if( s != NULL )
111   {
112     if( this->m_Configured )
113     {
114       for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i )
115       {
116         s->GetSeedAsPoint( i, aux_pnt );
117         typename I::PointType seed;
118         for( unsigned int d = 0; d < dim; ++d )
119           seed[ d ] = aux_pnt[ d ];
120         out->AddPoint( seed );
121
122       } // rof
123     }
124     else
125       s->SeedWidgetOn( );
126
127   } // fi
128   this->m_Configured = true;
129   return( "" );
130 }
131
132 // eof - $RCSfile$