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>
9 // -------------------------------------------------------------------------
10 itk::ModifiedTimeType cpPluginsWidgets::SeedWidget::
13 // std::cout << "Seed GetMTime" << std::endl;
14 return( 0 /*this->Superclass::GetMTime( )*/ );
17 // -------------------------------------------------------------------------
18 cpPluginsWidgets::SeedWidget::
23 this->_AddInput( "ReferenceImage" );
24 this->_AddOutput< cpPlugins::DataObject >( "Output" );
26 this->m_Parameters.ConfigureAsBool( "SeedsAreInRealSpace" );
27 this->m_Parameters.SetBool( "SeedsAreInRealSpace", false );
30 // -------------------------------------------------------------------------
31 cpPluginsWidgets::SeedWidget::
36 // -------------------------------------------------------------------------
37 std::string cpPluginsWidgets::SeedWidget::
40 auto image = this->GetInputData( "ReferenceImage" );
41 std::string r = cpPlugin_Image_Demangle_Dim( _GD0, image, 3 );
42 if( r != "" ) r = cpPlugin_Image_Demangle_Dim( _GD0, image, 2 );
46 // -------------------------------------------------------------------------
48 std::string cpPluginsWidgets::SeedWidget::
53 if( this->m_Parameters.GetBool( "SeedsAreInRealSpace" ) )
54 return( this->_GD1_Points< I >( image ) );
56 return( this->_GD1_Vertices< I >( image ) );
59 return( "Widgets::SeedWidget: Input image dimension not supported." );
62 // -------------------------------------------------------------------------
64 std::string cpPluginsWidgets::SeedWidget::
65 _GD1_Points( I* image )
67 typedef cpExtensions::Interaction::ImageInteractorStyle _S;
68 typedef itk::Point< double, I::ImageDimension > _P;
69 typedef itk::SimpleDataObjectDecorator< std::vector< _P > > _Container;
71 auto container = this->_CreateITK< _Container >( );
74 unsigned int dim = ( I::ImageDimension < 3 )? I::ImageDimension: 3;
76 container->Get( ).clear( );
79 if( this->m_MPRViewer != NULL )
81 for( unsigned int i = 0; i < 4; ++i )
85 this->m_MPRViewer->GetInteractor( i )->GetInteractorStyle( )
89 if( this->m_Configured )
91 for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i )
93 s->GetSeedAsPoint( i, aux_pnt );
95 for( unsigned int d = 0; d < dim; ++d )
96 seed[ d ] = aux_pnt[ d ];
97 container->Get( ).push_back( seed );
111 _S* s = dynamic_cast< _S* >( this->m_SingleInteractor );
114 if( this->m_Configured )
116 for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i )
118 s->GetSeedAsPoint( i, aux_pnt );
120 for( unsigned int d = 0; d < dim; ++d )
121 seed[ d ] = aux_pnt[ d ];
122 container->Get( ).push_back( seed );
130 this->m_Configured = true;
132 this->GetOutputData( "Output" )->SetITK( container );
136 // -------------------------------------------------------------------------
138 std::string cpPluginsWidgets::SeedWidget::
139 _GD1_Vertices( I* image )
141 typedef cpExtensions::Interaction::ImageInteractorStyle _S;
143 itk::SimpleDataObjectDecorator< std::vector< typename I::IndexType > >
145 auto container = this->_CreateITK< _Container >( );
148 unsigned int dim = ( I::ImageDimension < 3 )? I::ImageDimension: 3;
150 container->Get( ).clear( );
153 if( this->m_MPRViewer != NULL )
155 for( unsigned int i = 0; i < 4; ++i )
159 this->m_MPRViewer->GetInteractor( i )->GetInteractorStyle( )
163 if( this->m_Configured )
165 for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i )
167 s->GetSeedAsPoint( i, aux_pnt );
168 typename I::PointType seed;
169 for( unsigned int d = 0; d < dim; ++d )
170 seed[ d ] = aux_pnt[ d ];
171 typename I::IndexType idx;
172 if( image->TransformPhysicalPointToIndex( seed, idx ) )
173 container->Get( ).push_back( idx );
187 _S* s = dynamic_cast< _S* >( this->m_SingleInteractor );
190 if( this->m_Configured )
192 for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i )
194 s->GetSeedAsPoint( i, aux_pnt );
195 typename I::PointType seed;
196 for( unsigned int d = 0; d < dim; ++d )
197 seed[ d ] = aux_pnt[ d ];
198 typename I::IndexType idx;
199 if( image->TransformPhysicalPointToIndex( seed, idx ) )
200 container->Get( ).push_back( idx );
208 this->m_Configured = true;
210 this->GetOutputData( "Output" )->SetITK( container );