1 #include "SeedWidget.h"
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 #include <cpExtensions/DataStructures/VectorValuesContainer.h>
9 #include <vtkRenderWindowInteractor.h>
11 // -------------------------------------------------------------------------
12 itk::ModifiedTimeType cpPlugins::Widgets::SeedWidget::
15 // std::cout << "Seed GetMTime" << std::endl;
16 return( 0 /*this->Superclass::GetMTime( )*/ );
19 // -------------------------------------------------------------------------
20 cpPlugins::Widgets::SeedWidget::
25 this->_AddInput( "ReferenceImage" );
26 this->_AddOutput< cpPlugins::Interface::PointList >( "Output" );
28 this->m_Parameters->ConfigureAsBool( "SeedsAreInRealSpace" );
29 this->m_Parameters->SetBool( "SeedsAreInRealSpace", false );
32 // -------------------------------------------------------------------------
33 cpPlugins::Widgets::SeedWidget::
38 // -------------------------------------------------------------------------
39 std::string cpPlugins::Widgets::SeedWidget::
42 typedef itk::ImageBase< 2 > _2DImage;
43 typedef itk::ImageBase< 3 > _3DImage;
45 auto image = this->GetInputData( "ReferenceImage" );
46 itk::DataObject* itk_image = image->GetITK< _2DImage >( );
47 if( itk_image != NULL )
48 return( this->_GD0< _2DImage >( itk_image ) );
51 itk_image = image->GetITK< _3DImage >( );
52 if( itk_image != NULL )
53 return( this->_GD0< _3DImage >( itk_image ) );
56 return( "SeedWidget: Input image dimension not supported." );
59 // -------------------------------------------------------------------------
61 std::string cpPlugins::Widgets::SeedWidget::
62 _GD0( itk::DataObject* image )
64 if( this->m_Parameters->GetBool( "SeedsAreInRealSpace" ) )
65 return( this->_GD1_Points< I >( dynamic_cast< I* >( image ) ) );
67 return( this->_GD1_Vertices< I >( dynamic_cast< I* >( image ) ) );
70 // -------------------------------------------------------------------------
72 std::string cpPlugins::Widgets::SeedWidget::
73 _GD1_Points( I* image )
75 typedef cpExtensions::Interaction::ImageInteractorStyle _S;
76 typedef itk::Point< double, I::ImageDimension > _P;
77 typedef cpExtensions::DataStructures::VectorValuesContainer< _P > _Container;
79 auto container = this->_CreateITK< _Container >( );
82 unsigned int dim = ( I::ImageDimension < 3 )? I::ImageDimension: 3;
84 container->Get( ).clear( );
87 if( this->m_MPRViewer != NULL )
89 for( unsigned int i = 0; i < 4; ++i )
93 this->m_MPRViewer->GetInteractor( i )->GetInteractorStyle( )
97 if( this->m_Configured )
99 for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i )
101 s->GetSeedAsPoint( i, aux_pnt );
103 for( unsigned int d = 0; d < dim; ++d )
104 seed[ d ] = aux_pnt[ d ];
105 container->PushBack( seed );
119 _S* s = dynamic_cast< _S* >( this->m_SingleInteractor );
122 if( this->m_Configured )
124 for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i )
126 s->GetSeedAsPoint( i, aux_pnt );
128 for( unsigned int d = 0; d < dim; ++d )
129 seed[ d ] = aux_pnt[ d ];
130 container->PushBack( seed );
138 this->m_Configured = true;
140 auto out = this->GetOutputData( "Output" );
141 out->SetITK( container );
145 // -------------------------------------------------------------------------
147 std::string cpPlugins::Widgets::SeedWidget::
148 _GD1_Vertices( I* image )
150 typedef cpExtensions::Interaction::ImageInteractorStyle _S;
151 typedef cpExtensions::DataStructures::VectorValuesContainer< typename I::IndexType > _Container;
153 auto container = this->_CreateITK< _Container >( );
156 unsigned int dim = ( I::ImageDimension < 3 )? I::ImageDimension: 3;
158 container->Get( ).clear( );
161 if( this->m_MPRViewer != NULL )
163 for( unsigned int i = 0; i < 4; ++i )
167 this->m_MPRViewer->GetInteractor( i )->GetInteractorStyle( )
171 if( this->m_Configured )
173 for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i )
175 s->GetSeedAsPoint( i, aux_pnt );
176 typename I::PointType seed;
177 for( unsigned int d = 0; d < dim; ++d )
178 seed[ d ] = aux_pnt[ d ];
179 typename I::IndexType idx;
180 if( image->TransformPhysicalPointToIndex( seed, idx ) )
181 container->PushBack( idx );
195 _S* s = dynamic_cast< _S* >( this->m_SingleInteractor );
198 if( this->m_Configured )
200 for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i )
202 s->GetSeedAsPoint( i, aux_pnt );
203 typename I::PointType seed;
204 for( unsigned int d = 0; d < dim; ++d )
205 seed[ d ] = aux_pnt[ d ];
206 typename I::IndexType idx;
207 if( image->TransformPhysicalPointToIndex( seed, idx ) )
208 container->PushBack( idx );
216 this->m_Configured = true;
218 auto out = this->GetOutputData( "Output" );
219 out->SetITK( container );