2 #include "ui_MainWnd.h"
7 #include <QDoubleSpinBox>
11 #include <itkImageRegionIterator.h>
12 #include <itkImageRegionConstIterator.h>
13 #define ITK_MANUAL_INSTANTIATION
16 // -------------------------------------------------------------------------
18 _ParametersDialog( const TParameters& parameters )
20 if( this->m_ActiveParameters != NULL )
21 this->m_ActiveParameters->close( );
22 this->m_ActiveParameters = new QWidget( NULL );
23 this->m_ActiveParameters->setWindowFlags( Qt::FramelessWindowHint );
24 this->m_ActiveParameters->setWindowFlags( Qt::WindowTitleHint );
26 QGridLayout* gridLayout = new QGridLayout( this->m_ActiveParameters );
27 QVBoxLayout* verticalLayout = new QVBoxLayout( );
30 QLabel* title = new QLabel( this->m_ActiveParameters );
31 title->setText( this->m_ActivePlugin->GetClassName( ).c_str( ) );
32 verticalLayout->addWidget( title );
34 TParameters::const_iterator pIt = parameters.begin( );
35 for( ; pIt != parameters.end( ); ++pIt )
37 std::string par_name = pIt->first;
38 std::string par_type = pIt->second.first;
39 std::string par_value = pIt->second.second;
41 if( par_type == "double" )
43 QHBoxLayout* horizontalLayout = new QHBoxLayout( );
44 QLabel* label = new QLabel( this->m_ActiveParameters );
45 label->setText( QString( par_name.c_str( ) ) );
46 horizontalLayout->addWidget( label );
48 QDoubleSpinBox* v_double =
49 new QDoubleSpinBox( this->m_ActiveParameters );
50 v_double->setDecimals( 3 );
51 v_double->setMinimum( -( std::numeric_limits< double >::max( ) ) );
52 v_double->setMaximum( std::numeric_limits< double >::max( ) );
53 v_double->setValue( std::atof( par_value.c_str( ) ) );
54 v_double->setObjectName( QString( par_name.c_str( ) ) );
55 horizontalLayout->addWidget( v_double );
56 verticalLayout->addLayout( horizontalLayout );
61 gridLayout->addLayout( verticalLayout, 0, 0, 1, 1 );
64 TParameters::const_iterator seedIt = parameters.find( "Seed" );
65 TParameters::const_iterator radiusIt = parameters.find( "Radius" );
66 TParameters::const_iterator endIt = parameters.end( );
67 if( seedIt == endIt && radiusIt == endIt )
68 this->m_ActivePluginType = Self::GlobalPluginType;
69 else if( seedIt != endIt && radiusIt == endIt )
70 this->m_ActivePluginType = Self::DoubleClickPluginType;
71 else if( seedIt != endIt && radiusIt != endIt )
72 this->m_ActivePluginType = Self::SpherePluginType;
74 this->m_ActivePluginType = Self::NonePluginType;
76 QMetaObject::connectSlotsByName( this->m_ActiveParameters );
77 this->m_ActiveParameters->show( );
82 // -------------------------------------------------------------------------
84 _ExecuteDoubleClickPlugin( const double* pnt )
87 this->m_InputImage == NULL ||
88 this->m_SegmentedImage == NULL ||
89 this->m_ActivePlugin == NULL ||
90 this->m_ActiveParameters == NULL ||
91 this->m_ActivePluginType != Self::DoubleClickPluginType
95 TParameters parameters = this->m_ActivePlugin->GetDefaultParameters( );
97 // Variable parameters
99 TParameters::iterator pIt = parameters.begin( );
100 pIt != parameters.end( );
104 if( pIt->first != "Seed" )
106 if( pIt->second.first == "double" )
108 QDoubleSpinBox* v_double = this->m_ActiveParameters->
109 findChild< QDoubleSpinBox* >( pIt->first.c_str( ) );
110 if( v_double != NULL )
111 parameters[ pIt->first ] =
112 TParameter( "double", v_double->text( ).toStdString( ) );
121 std::stringstream seed_str;
122 seed_str << pnt[ 0 ] << ":" << pnt[ 1 ] << ":" << pnt[ 2 ];
123 parameters[ "Seed" ] = TParameter( "point", seed_str.str( ) );
126 this->m_ActivePlugin->SetParameters( parameters );
127 this->m_ActivePlugin->SetInput( 0, this->m_InputImage );
128 this->m_ActivePlugin->SetInput( 1, this->m_SegmentedImage );
129 std::string err = this->m_ActivePlugin->Update( );
132 QMessageBox::critical( this, tr( "Error caugth!" ), tr( err.c_str( ) ) );
138 itk::DataObject* s = this->m_SegmentedImage->GetDataObject( );
139 if( dynamic_cast< itk::Image< char, 3 >* >( s ) != NULL )
140 this->_JoinSegmentations< char >( );
141 else if( dynamic_cast< itk::Image< short, 3 >* >( s ) != NULL )
142 this->_JoinSegmentations< short >( );
143 else if( dynamic_cast< itk::Image< int, 3 >* >( s ) != NULL )
144 this->_JoinSegmentations< int >( );
145 else if( dynamic_cast< itk::Image< long, 3 >* >( s ) != NULL )
146 this->_JoinSegmentations< long >( );
147 else if( dynamic_cast< itk::Image< unsigned char, 3 >* >( s ) != NULL )
148 this->_JoinSegmentations< unsigned char >( );
149 else if( dynamic_cast< itk::Image< unsigned short, 3 >* >( s ) != NULL )
150 this->_JoinSegmentations< unsigned short >( );
151 else if( dynamic_cast< itk::Image< unsigned int, 3 >* >( s ) != NULL )
152 this->_JoinSegmentations< unsigned int >( );
153 else if( dynamic_cast< itk::Image< unsigned long, 3 >* >( s ) != NULL )
154 this->_JoinSegmentations< unsigned long >( );
156 // Update visualization
157 this->m_SegmentedImage->UpdateVTKImageData( );
158 this->m_MPR->Render( 0 );
159 this->m_MPR->Render( 1 );
160 this->m_MPR->Render( 2 );
163 // -------------------------------------------------------------------------
165 _triggered_actionSegmentImage( )
169 // -------------------------------------------------------------------------
171 _triggered_actionFilterSegmentation( )
174 if( this->m_SegmentedImage == NULL )
176 QAction* action = dynamic_cast< QAction* >( this->sender( ) );
179 std::string filter_name = action->text( ).toStdString( );
182 if( this->m_ActivePlugin != NULL ) delete this->m_ActivePlugin;
183 this->m_ActivePlugin =
184 dynamic_cast< TPlugin* >(
185 this->m_Plugins.CreateObject(
186 this->m_SegmentationFilterClasses[ filter_name ]
189 this->m_ActivePluginCategory = Self::SegmentationFilteringPluginCategory;
191 // Show parameters dialog
192 this->_ParametersDialog( this->m_ActivePlugin->GetDefaultParameters( ) );
195 // -------------------------------------------------------------------------
197 _triggered_actionProcessMesh( )
201 // -------------------------------------------------------------------------
204 _JoinSegmentations( )
206 typedef itk::Image< P, 3 > _TImage;
208 _TImage* old_segmentation =
209 dynamic_cast< _TImage* >( this->m_SegmentedImage->GetDataObject( ) );
210 _TImage* new_segmentation =
211 dynamic_cast< _TImage* >(
212 dynamic_cast< TPluginImage* >(
213 this->m_ActivePlugin->GetOutput( 0 )
217 /* TODO: InPlaceOn does not execute correctly on input image
218 typedef itk::AndImageFilter< _TImage, _TImage, _TImage > _TFilter;
219 typename _TFilter::Pointer filter = _TFilter::New( );
220 filter->InPlaceOn( );
221 filter->SetInput( 0, old_segmentation );
222 filter->SetInput( 1, new_segmentation );
224 //old_segmentation->DisconnectPipeline( );
226 std::cout << old_segmentation->GetRequestedRegion( ) << std::endl;
227 std::cout << new_segmentation->GetRequestedRegion( ) << std::endl;
228 std::cout << old_segmentation->GetBufferedRegion( ) << std::endl;
229 std::cout << new_segmentation->GetBufferedRegion( ) << std::endl;
231 typedef itk::ImageRegionConstIterator< _TImage > _TConstIt;
232 typedef itk::ImageRegionIterator< _TImage > _TIt;
233 _TConstIt nIt( new_segmentation, new_segmentation->GetRequestedRegion( ) );
234 _TIt oIt( old_segmentation, old_segmentation->GetRequestedRegion( ) );
237 for( ; !nIt.IsAtEnd( ); ++nIt, ++oIt )
238 oIt.Set( nIt.Get( ) | oIt.Get( ) );
241 // -------------------------------------------------------------------------
242 DoubleClickCommand* DoubleClickCommand::
245 return( new DoubleClickCommand( ) );
248 // -------------------------------------------------------------------------
249 void DoubleClickCommand::
250 SetMainWnd( MainWnd* wnd )
252 this->m_MainWnd = wnd;
255 // -------------------------------------------------------------------------
256 void DoubleClickCommand::
257 Execute( vtkObject* caller, unsigned long eid, void* data )
259 if( this->m_MainWnd != NULL )
260 this->m_MainWnd->_ExecuteDoubleClickPlugin(
261 reinterpret_cast< const double* >( data )
265 // -------------------------------------------------------------------------
267 DoubleClickCommand( )
273 // -------------------------------------------------------------------------
275 ~DoubleClickCommand( )