]> Creatis software - cpPlugins.git/blob - plugins/cpPluginsWidgets/SeedWidget.cxx
b65d29f06de5e4f97f3d965d66721a2e0d23077f
[cpPlugins.git] / plugins / cpPluginsWidgets / SeedWidget.cxx
1 #include "SeedWidget.h"
2
3 #include <cpPlugins/Image.h>
4 #include <cpExtensions/DataStructures/ImageIndexesContainer.h>
5 #include <cpExtensions/QT/SimpleMPRWidget.h>
6 #include <cpExtensions/Interaction/ImageInteractorStyle.h>
7 #include <vtkRenderWindowInteractor.h>
8 #include <itkSimpleDataObjectDecorator.h>
9 #include <itkSimpleDataObjectDecorator.hxx>
10
11 // -------------------------------------------------------------------------
12 itk::ModifiedTimeType cpPluginsWidgets::SeedWidget::
13 GetMTime( ) const
14 {
15   // std::cout << "Seed GetMTime" << std::endl;
16   return( 0 /*this->Superclass::GetMTime( )*/ );
17 }
18
19 // -------------------------------------------------------------------------
20 cpPluginsWidgets::SeedWidget::
21 SeedWidget( )
22   : Superclass( ),
23     m_Configured( false )
24 {
25   this->_AddInput( "ReferenceImage" );
26   this->_AddOutput< cpPlugins::DataObject >( "Output" );
27 }
28
29 // -------------------------------------------------------------------------
30 cpPluginsWidgets::SeedWidget::
31 ~SeedWidget( )
32 {
33 }
34
35 // -------------------------------------------------------------------------
36 std::string cpPluginsWidgets::SeedWidget::
37 _GenerateData( )
38 {
39   auto image = this->GetInputData( "ReferenceImage" );
40   std::string   r = cpPlugin_Image_Demangle_Dim( _GD0, image, 3 );
41   if( r != "" ) r = cpPlugin_Image_Demangle_Dim( _GD0, image, 2 );
42   return( r );
43 }
44
45 // -------------------------------------------------------------------------
46 template< class _TImage >
47 std::string cpPluginsWidgets::SeedWidget::
48 _GD0( _TImage* image )
49 {
50   typedef
51     cpExtensions::DataStructures::ImageIndexesContainer< _TImage::ImageDimension >
52     _TContainer;
53   typedef cpExtensions::Interaction::ImageInteractorStyle _S;
54
55   if( image != NULL )
56   {
57     auto container = this->_CreateITK< _TContainer >( );
58     double aux_pnt[ 3 ];
59     unsigned int dim = ( _TImage::ImageDimension < 3 )? _TImage::ImageDimension: 3;
60     container->Get( ).clear( );
61
62     // MPR
63     if( this->m_MPRViewer != NULL )
64     {
65       for( unsigned int i = 0; i < 4; ++i )
66       {
67         _S* s =
68           dynamic_cast< _S* >(
69             this->m_MPRViewer->GetInteractor( i )->GetInteractorStyle( )
70             );
71         if( s != NULL )
72         {
73           if( this->m_Configured )
74           {
75             for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i )
76             {
77               s->GetSeedAsPoint( i, aux_pnt );
78               typename _TImage::PointType seed;
79               for( unsigned int d = 0; d < dim; ++d )
80                 seed[ d ] = aux_pnt[ d ];
81               typename _TImage::IndexType idx;
82               if( image->TransformPhysicalPointToIndex( seed, idx ) )
83                 container->Get( ).push_back( idx );
84
85             } // rof
86           }
87           else
88             s->SeedWidgetOn( );
89
90         } // fi
91
92       } // rof
93
94     } // fi
95
96     // Single interactor
97     _S* s = dynamic_cast< _S* >( this->m_SingleInteractor );
98     if( s != NULL )
99     {
100       if( this->m_Configured )
101       {
102         for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i )
103         {
104           s->GetSeedAsPoint( i, aux_pnt );
105           typename _TImage::PointType seed;
106           for( unsigned int d = 0; d < dim; ++d )
107             seed[ d ] = aux_pnt[ d ];
108           typename _TImage::IndexType idx;
109           if( image->TransformPhysicalPointToIndex( seed, idx ) )
110             container->Get( ).push_back( idx );
111
112         } // rof
113       }
114       else
115         s->SeedWidgetOn( );
116
117     } // fi
118     this->m_Configured = true;
119     container->SetReferenceImage( image );
120     this->GetOutputData( "Output" )->SetITK( container );
121     return( "" );
122   }
123   else
124     return( "Widgets::SeedWidget: Input image dimension not supported." );
125 }
126
127 // eof - $RCSfile$