1 #include "SeedWidget.h"
3 #include <cpPlugins/Image.h>
4 #include <cpExtensions/QT/SimpleMPRWidget.h>
5 #include <cpExtensions/Interaction/ImageInteractorStyle.h>
6 #include <vtkRenderWindowInteractor.h>
7 #include <itkSimpleDataObjectDecorator.h>
8 #include <itkSimpleDataObjectDecorator.hxx>
10 // -------------------------------------------------------------------------
11 itk::ModifiedTimeType cpPluginsWidgets::SeedWidget::
14 // std::cout << "Seed GetMTime" << std::endl;
15 return( 0 /*this->Superclass::GetMTime( )*/ );
18 // -------------------------------------------------------------------------
19 cpPluginsWidgets::SeedWidget::
24 this->_AddInput( "ReferenceImage" );
25 this->_AddOutput< cpPlugins::DataObject >( "Output" );
27 this->m_Parameters.ConfigureAsBool( "SeedsAreInRealSpace" );
28 this->m_Parameters.SetBool( "SeedsAreInRealSpace", false );
31 // -------------------------------------------------------------------------
32 cpPluginsWidgets::SeedWidget::
37 // -------------------------------------------------------------------------
38 std::string cpPluginsWidgets::SeedWidget::
41 auto image = this->GetInputData( "ReferenceImage" );
42 std::string r = cpPlugin_Image_Demangle_Dim( _GD0, image, 3 );
43 if( r != "" ) r = cpPlugin_Image_Demangle_Dim( _GD0, image, 2 );
47 // -------------------------------------------------------------------------
48 template< class _TImage >
49 std::string cpPluginsWidgets::SeedWidget::
50 _GD0( _TImage* image )
54 if( this->m_Parameters.GetBool( "SeedsAreInRealSpace" ) )
55 return( this->_GD1_Points( image ) );
57 return( this->_GD1_Vertices( image ) );
60 return( "Widgets::SeedWidget: Input image dimension not supported." );
63 // -------------------------------------------------------------------------
64 template< class _TImage >
65 std::string cpPluginsWidgets::SeedWidget::
66 _GD1_Points( _TImage* image )
68 typedef cpExtensions::Interaction::ImageInteractorStyle _S;
69 typedef itk::Point< double, _TImage::ImageDimension > _P;
70 typedef itk::SimpleDataObjectDecorator< std::vector< _P > > _Container;
72 auto container = this->_CreateITK< _Container >( );
75 unsigned int dim = ( _TImage::ImageDimension < 3 )? _TImage::ImageDimension: 3;
77 container->Get( ).clear( );
80 if( this->m_MPRViewer != NULL )
82 for( unsigned int i = 0; i < 4; ++i )
86 this->m_MPRViewer->GetInteractor( i )->GetInteractorStyle( )
90 if( this->m_Configured )
92 for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i )
94 s->GetSeedAsPoint( i, aux_pnt );
96 for( unsigned int d = 0; d < dim; ++d )
97 seed[ d ] = aux_pnt[ d ];
98 container->Get( ).push_back( seed );
112 _S* s = dynamic_cast< _S* >( this->m_SingleInteractor );
115 if( this->m_Configured )
117 for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i )
119 s->GetSeedAsPoint( i, aux_pnt );
121 for( unsigned int d = 0; d < dim; ++d )
122 seed[ d ] = aux_pnt[ d ];
123 container->Get( ).push_back( seed );
131 this->m_Configured = true;
133 this->GetOutputData( "Output" )->SetITK( container );
137 // -------------------------------------------------------------------------
138 template< class _TImage >
139 std::string cpPluginsWidgets::SeedWidget::
140 _GD1_Vertices( _TImage* image )
142 typedef cpExtensions::Interaction::ImageInteractorStyle _S;
144 itk::SimpleDataObjectDecorator< std::vector< typename _TImage::IndexType > >
146 auto container = this->_CreateITK< _Container >( );
149 unsigned int dim = ( _TImage::ImageDimension < 3 )? _TImage::ImageDimension: 3;
151 container->Get( ).clear( );
154 if( this->m_MPRViewer != NULL )
156 for( unsigned int i = 0; i < 4; ++i )
160 this->m_MPRViewer->GetInteractor( i )->GetInteractorStyle( )
164 if( this->m_Configured )
166 for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i )
168 s->GetSeedAsPoint( i, aux_pnt );
169 typename _TImage::PointType seed;
170 for( unsigned int d = 0; d < dim; ++d )
171 seed[ d ] = aux_pnt[ d ];
172 typename _TImage::IndexType idx;
173 if( image->TransformPhysicalPointToIndex( seed, idx ) )
174 container->Get( ).push_back( idx );
188 _S* s = dynamic_cast< _S* >( this->m_SingleInteractor );
191 if( this->m_Configured )
193 for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i )
195 s->GetSeedAsPoint( i, aux_pnt );
196 typename _TImage::PointType seed;
197 for( unsigned int d = 0; d < dim; ++d )
198 seed[ d ] = aux_pnt[ d ];
199 typename _TImage::IndexType idx;
200 if( image->TransformPhysicalPointToIndex( seed, idx ) )
201 container->Get( ).push_back( idx );
209 this->m_Configured = true;
211 this->GetOutputData( "Output" )->SetITK( container );