From: Leonardo Florez-Valencia Date: Wed, 23 Sep 2015 17:14:51 +0000 (+0200) Subject: ... X-Git-Tag: v0.1~367 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=62d056ccb528d63392d197552830460e980a5aba;p=cpPlugins.git ... --- diff --git a/appli/ImageMPR/ImageMPR.cxx b/appli/ImageMPR/ImageMPR.cxx index 337aac1..f17e719 100644 --- a/appli/ImageMPR/ImageMPR.cxx +++ b/appli/ImageMPR/ImageMPR.cxx @@ -30,18 +30,13 @@ ImageMPR::ImageMPR( QWidget* parent ) this->m_UI->setupUi( this ); // Create and associate renderers - this->m_MPRActors = vtkSmartPointer< TMPRActors >::New( ); - - for( unsigned int i = 0; i < 4; ++i ) - { - this->m_Renderers[ i ] = vtkSmartPointer< vtkRenderer >::New( ); - this->m_Renderers[ i ]->SetBackground( 0.1, 0.3, 0.8 ); - - } // rof - this->m_UI->m_XPlaneVTK->GetRenderWindow( )->AddRenderer( this->m_Renderers[ 0 ] ); - this->m_UI->m_YPlaneVTK->GetRenderWindow( )->AddRenderer( this->m_Renderers[ 1 ] ); - this->m_UI->m_ZPlaneVTK->GetRenderWindow( )->AddRenderer( this->m_Renderers[ 2 ] ); - this->m_UI->m_3DVTK->GetRenderWindow( )->AddRenderer( this->m_Renderers[ 3 ] ); + this->m_MPRObjects = vtkSmartPointer< TMPRObjects >::New( ); + this->m_MPRObjects->SetRenderWindows( + this->m_UI->m_XPlaneVTK->GetRenderWindow( ), + this->m_UI->m_YPlaneVTK->GetRenderWindow( ), + this->m_UI->m_ZPlaneVTK->GetRenderWindow( ), + this->m_UI->m_3DVTK->GetRenderWindow( ) + ); // signals <-> slots QObject::connect( @@ -80,6 +75,9 @@ ImageMPR:: bool ImageMPR:: _LoadPlugins( const std::string& filename ) { + QApplication::setOverrideCursor( Qt::WaitCursor ); + this->setEnabled( false ); + this->m_ImageReaderClass = ""; this->m_ImageWriterClass = ""; this->m_MeshReaderClass = ""; @@ -134,6 +132,9 @@ _LoadPlugins( const std::string& filename ) } // fi } // rof + QApplication::restoreOverrideCursor( ); + this->setEnabled( true ); + return( true ); } @@ -168,7 +169,7 @@ _triggered_actionOpenInputImage( ) dialog.setFileMode( QFileDialog::ExistingFiles ); dialog.setDirectory( tr( "." ) ); dialog.setNameFilter( - tr( "Medical image files (*.mhd *.bin *.dcm *.nrri);;All files (*)" ) + tr( "Medical image files (*.mhd *.bin *.dcm);;All files (*)" ) ); dialog.setDefaultSuffix( tr( "mhd" ) ); if( !( dialog.exec( ) ) ) @@ -189,40 +190,34 @@ _triggered_actionOpenInputImage( ) reader->SetParameters( reader_params ); // Execute and get error message, if any + QApplication::setOverrideCursor( Qt::WaitCursor ); + this->setEnabled( false ); std::string err = reader->Update( ); + QApplication::restoreOverrideCursor( ); + this->setEnabled( true ); // Assign fresh image, if any if( err == "" ) { - this->m_InputImage = - dynamic_cast< TPluginImage* >( reader->GetOutput( 0 ) ); + this->m_InputImage = reader->GetOutput< TPluginImage >( 0 ); reader->DisconnectOutputs( ); if( this->m_InputImage.IsNotNull( ) ) { - this->m_MPRActors->SetInputData( this->m_InputImage->GetVTKImageData( ) ); - this->m_MPRActors->PushDataInto( - this->m_Renderers[ 0 ], - this->m_Renderers[ 1 ], - this->m_Renderers[ 2 ], - this->m_Renderers[ 3 ] - ); - - /* - this->m_MPR.AssociatePlaneInteractor( 0, this->m_UI->m_XPlaneVTK->GetRenderWindow( )->GetInteractor( ) ); - this->m_MPR.AssociatePlaneInteractor( 1, this->m_UI->m_YPlaneVTK->GetRenderWindow( )->GetInteractor( ) ); - this->m_MPR.AssociatePlaneInteractor( 2, this->m_UI->m_ZPlaneVTK->GetRenderWindow( )->GetInteractor( ) ); - */ + vtkImageData* vtk_id = this->m_InputImage->GetVTKImageData( ); + if( vtk_id != NULL ) + { + this->m_MPRObjects->SetImage( vtk_id ); + this->m_MPRObjects->ResetCameras( ); + this->m_MPRObjects->RenderAll( ); + } + else + QMessageBox::critical( + this, + tr( "Error message" ), + tr( "Read image does not have a valid VTK converter." ) + ); } // fi - this->m_Renderers[ 0 ]->ResetCamera( ); - this->m_Renderers[ 1 ]->ResetCamera( ); - this->m_Renderers[ 2 ]->ResetCamera( ); - this->m_Renderers[ 3 ]->ResetCamera( ); - - this->m_UI->m_XPlaneVTK->GetRenderWindow( )->Render( ); - this->m_UI->m_YPlaneVTK->GetRenderWindow( )->Render( ); - this->m_UI->m_ZPlaneVTK->GetRenderWindow( )->Render( ); - this->m_UI->m_3DVTK->GetRenderWindow( )->Render( ); } else QMessageBox::critical( @@ -236,64 +231,73 @@ _triggered_actionOpenInputImage( ) void ImageMPR:: _triggered_actionOpenInputPolyData( ) { - /* // Show dialog and check if it was accepted QFileDialog dialog( this ); dialog.setFileMode( QFileDialog::ExistingFile ); - dialog.setDirectory( "." ); - dialog.setNameFilter( tr( "VTK file (*.vtk);;All files (*)" ) ); + dialog.setDirectory( tr( "." ) ); + dialog.setNameFilter( + tr( "Mesh files (*.vtk *.obj);;All files (*)" ) + ); dialog.setDefaultSuffix( tr( "vtk" ) ); if( !( dialog.exec( ) ) ) return; - std::string fname = dialog.selectedFiles( ).at( 0 ).toStdString( ); - this->m_InputMesh = NULL; // Get a reader from plugins TPluginFilter::Pointer reader = - this->m_Plugins.CreateProcessObject( - this->m_BaseClasses[ "MeshReader" ] - ); + this->m_Plugins.CreateProcessObject( this->m_MeshReaderClass ); - // Configure plugin + // Configure reader TParameters reader_params = reader->GetDefaultParameters( ); - reader_params.SetValueAsString( "FileName", fname ); + QStringList q_fnames = dialog.selectedFiles( ); + QStringList::const_iterator qIt = q_fnames.begin( ); + for( ; qIt != q_fnames.end( ); ++qIt ) + reader_params.SetValueAsString( "FileName", qIt->toStdString( ) ); reader->SetParameters( reader_params ); // Execute and get error message, if any + QApplication::setOverrideCursor( Qt::WaitCursor ); + this->setEnabled( false ); std::string err = reader->Update( ); + QApplication::restoreOverrideCursor( ); + this->setEnabled( true ); + // Assign fresh image, if any if( err == "" ) { - this->m_InputMesh = - dynamic_cast< TPluginMesh* >( reader->GetOutput( 0 ) ); + this->m_InputMesh = reader->GetOutput< TPluginMesh >( 0 ); reader->DisconnectOutputs( ); if( this->m_InputMesh.IsNotNull( ) ) { - this->m_InputMeshMapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); - this->m_InputMeshMapper->SetInputData( this->m_InputMesh->GetVTKPolyData( ) ); - this->m_InputMeshActor = vtkSmartPointer< vtkActor >::New( ); - this->m_InputMeshActor->SetMapper( this->m_InputMeshMapper ); - this->m_MPR->Add3DActor( this->m_InputMeshActor ); + vtkActor* vtk_actor = this->m_InputMesh->GetVTKActor( ); + if( vtk_actor != NULL ) + { + this->m_MPRObjects->Get3DRenderer( )->AddActor( vtk_actor ); + this->m_MPRObjects->Render( 4 ); + } + else + QMessageBox::critical( + this, + tr( "Error message" ), + tr( "Read mesh does not have a valid vtkActor." ) + ); } // fi } else QMessageBox::critical( this, - tr( "Error reading polydata" ), + tr( "Error reading mesh" ), tr( err.c_str( ) ) ); - */ } // ------------------------------------------------------------------------- void ImageMPR:: _triggered_actionImageToImage( ) { - /* TODO if( this->m_InputImage.IsNull( ) ) return; @@ -315,19 +319,22 @@ _triggered_actionImageToImage( ) return; // Execute filter + QApplication::setOverrideCursor( Qt::WaitCursor ); + this->setEnabled( false ); filter->SetParameters( parameters ); filter->SetInput( 0, this->m_InputImage ); std::string err = filter->Update( ); + QApplication::restoreOverrideCursor( ); + this->setEnabled( true ); // Update image if( err == "" ) { - TPluginImage* result = - dynamic_cast< TPluginImage* >( filter->GetOutput( 0 ) ); + TPluginImage* result = filter->GetOutput< TPluginImage >( 0 ); result->DisconnectPipeline( ); this->m_InputImage = result; if( this->m_InputImage.IsNotNull( ) ) - this->m_MPR->SetImage( this->m_InputImage->GetVTKImageData( ) ); + this->m_MPRObjects->SetImage( this->m_InputImage->GetVTKImageData( ) ); } else QMessageBox::critical( @@ -335,7 +342,6 @@ _triggered_actionImageToImage( ) tr( "Error executing filter" ), tr( err.c_str( ) ) ); - */ } // ------------------------------------------------------------------------- @@ -363,21 +369,24 @@ _triggered_actionImageToMesh( ) return; // Execute filter + QApplication::setOverrideCursor( Qt::WaitCursor ); + this->setEnabled( false ); filter->SetParameters( parameters ); filter->SetInput( 0, this->m_InputImage ); std::string err = filter->Update( ); + QApplication::restoreOverrideCursor( ); + this->setEnabled( true ); // Update image if( err == "" ) { - /* TODO - TPluginImage* result = - dynamic_cast< TPluginImage* >( filter->GetOutput( 0 ) ); - result->DisconnectPipeline( ); - this->m_InputImage = result; - if( this->m_InputImage.IsNotNull( ) ) - this->m_MPR->SetImage( this->m_InputImage->GetVTKImageData( ) ); - */ + TPluginMesh* result = filter->GetOutput< TPluginMesh >( 0 ); + result->DisconnectPipeline( ); + this->m_InputMesh = result; + if( this->m_InputMesh.IsNotNull( ) ) + this->m_MPRObjects->Get3DRenderer( )->AddActor( + this->m_InputMesh->GetVTKActor( ) + ); } else QMessageBox::critical( diff --git a/appli/ImageMPR/ImageMPR.h b/appli/ImageMPR/ImageMPR.h index 808c0ab..ba05de9 100644 --- a/appli/ImageMPR/ImageMPR.h +++ b/appli/ImageMPR/ImageMPR.h @@ -9,9 +9,8 @@ #include // vtk stuff -#include #include -#include +#include // Plugins interface #include @@ -44,7 +43,7 @@ public: typedef cpPlugins::Interface::Parameters TParameters; typedef std::set< std::string > TStringContainer; - typedef cpExtensions::Visualization::MPRActors TMPRActors; + typedef cpExtensions::Visualization::MPRObjects TMPRObjects; public: explicit ImageMPR( QWidget* parent = 0 ); @@ -79,10 +78,7 @@ private: TPluginMesh::Pointer m_InputMesh; // Visualization stuff - vtkSmartPointer< TMPRActors > m_MPRActors; - vtkSmartPointer< vtkRenderer > m_Renderers[ 4 ]; - vtkSmartPointer< vtkPolyDataMapper > m_InputMeshMapper; - vtkSmartPointer< vtkActor > m_InputMeshActor; + vtkSmartPointer< TMPRObjects > m_MPRObjects; /* TODO vtkSmartPointer< vtkOrientationMarkerWidget > m_3DOrientationWidget; diff --git a/appli/examples/CMakeLists.txt b/appli/examples/CMakeLists.txt index f233136..586eddf 100644 --- a/appli/examples/CMakeLists.txt +++ b/appli/examples/CMakeLists.txt @@ -25,6 +25,7 @@ FOREACH(prog ${EXAMPLES_PROGRAMS}) ) TARGET_LINK_LIBRARIES( ${prog} + cpExtensions cpPlugins_Interface ) ENDFOREACH(prog) diff --git a/appli/examples/example_MPR.cxx b/appli/examples/example_MPR.cxx index 1691e08..502302c 100644 --- a/appli/examples/example_MPR.cxx +++ b/appli/examples/example_MPR.cxx @@ -5,12 +5,108 @@ #include #include #include -#include +#include +#include #include #include #include +#include +#include +#include + +// ------------------------------------------------------------------------- +typedef cpPlugins::Interface::Interface TInterface; +typedef cpPlugins::Interface::ProcessObject TFilter; +typedef cpPlugins::Interface::Parameters TParameters; +typedef cpPlugins::Interface::Image TImage; + +typedef cpExtensions::Visualization::MPRActors TMPRActors; + +// ------------------------------------------------------------------------- +class SliderCallback + : public vtkCommand +{ +public: + static SliderCallback* New( ) + { + return new SliderCallback; + } + virtual void Execute( vtkObject* caller, unsigned long eId , void* data ) + { + vtkSliderWidget* wdg = + reinterpret_cast< vtkSliderWidget* >( caller ); + if( wdg == NULL ) + return; + vtkSliderRepresentation* rep = + static_cast< vtkSliderRepresentation* >( + wdg->GetRepresentation( ) + ); + if( rep == NULL ) + return; + std::string title = rep->GetTitleText( ); + if( title == "X" ) + this->Actors->SetSlice( 0, int( rep->GetValue( ) ) ); + else if( title == "Y" ) + this->Actors->SetSlice( 1, int( rep->GetValue( ) ) ); + else if( title == "Z" ) + this->Actors->SetSlice( 2, int( rep->GetValue( ) ) ); + else if( title == "Window" ) + this->Actors->SetWindow( rep->GetValue( ) ); + else if( title == "Level" ) + this->Actors->SetLevel( rep->GetValue( ) ); + } + SliderCallback( ) + : vtkCommand( ) + { + } + +public: + TMPRActors* Actors; +}; + +// ------------------------------------------------------------------------- +struct Slider +{ + vtkSmartPointer< vtkSliderRepresentation2D > Representation; + vtkSmartPointer< vtkSliderWidget > Widget; + + Slider( + double min_value, + double max_value, + double value, + const std::string& title, + vtkRenderWindowInteractor* iren, + double p1x, double p1y, double p2x, double p2y, + SliderCallback* callback = NULL + ) + { + this->Representation = + vtkSmartPointer< vtkSliderRepresentation2D >::New( ); + this->Representation->SetMinimumValue( min_value ); + this->Representation->SetMaximumValue( max_value ); + this->Representation->SetValue( value ); + this->Representation->SetTitleText( title.c_str( ) ); + this->Representation->GetPoint1Coordinate( )-> + SetCoordinateSystemToNormalizedDisplay(); + this->Representation->GetPoint1Coordinate( )-> + SetValue( p1x, p1y ); + this->Representation->GetPoint2Coordinate( )-> + SetCoordinateSystemToNormalizedDisplay(); + this->Representation->GetPoint2Coordinate( )->SetValue( p2x, p2y ); + + this->Widget = vtkSmartPointer< vtkSliderWidget >::New( ); + this->Widget->SetInteractor( iren ); + this->Widget->SetRepresentation( this->Representation ); + this->Widget->SetAnimationModeToAnimate( ); + this->Widget->EnabledOn( ); + if( callback != NULL ) + this->Widget->AddObserver( vtkCommand::InteractionEvent, callback ); + } +}; + +// ------------------------------------------------------------------------- int main( int argc, char* argv[] ) { if( argc < 3 ) @@ -25,20 +121,15 @@ int main( int argc, char* argv[] ) std::string plugins_file = argv[ 1 ]; // Create interface - typedef cpPlugins::Interface::Interface TInterface; - typedef TInterface::TClasses TClasses; - TInterface plugins; plugins.Load( plugins_file ); - // Create objects - typedef cpPlugins::Interface::ProcessObject TProcessObject; - typedef cpPlugins::Interface::Parameters TParameters; - cpPlugins::Interface::ProcessObject::Pointer reader; - reader = plugins.CreateProcessObject( "cpPlugins::ImageReader" ); + // Create reader + TFilter::Pointer reader = + plugins.CreateProcessObject( "cpPlugins::ImageReader" ); if( reader.IsNull( ) ) { - std::cerr << "No suitable reader found in plugins." << std::endl; + std::cerr << "No suitable image reader found in plugins." << std::endl; return( 1 ); } // fi @@ -57,10 +148,10 @@ int main( int argc, char* argv[] ) return( 1 ); } // fi - cpPlugins::Interface::Image* image = - dynamic_cast< cpPlugins::Interface::Image* >( reader->GetOutput( 0 ) ); - vtkImageData* vtk_image = image->GetVTKImageData( ); - if( vtk_image == NULL ) + + // Get input image's vtk representation + vtkImageData* image = reader->GetOutput< TImage >( 0 )->GetVTKImageData( ); + if( image == NULL ) { std::cerr << "ERROR: read image does not have a valid VTK conversion." @@ -85,13 +176,51 @@ int main( int argc, char* argv[] ) interactor->SetRenderWindow( window ); // Actors - cpExtensions::Visualization::MPRObjects mpr; - mpr.SetImage( vtk_image ); - /* - mpr.AssociatePlaneInteractor( 0, interactor ); - mpr.AssociatePlaneInteractor( 1, interactor ); - mpr.AssociatePlaneInteractor( 2, interactor ); - */ + vtkSmartPointer< TMPRActors > mpr_actors = + vtkSmartPointer< TMPRActors >::New( ); + mpr_actors->SetInputData( image ); + mpr_actors->PushDataInto( NULL, NULL, NULL, renderer ); + + // Callbacks + vtkSmartPointer< SliderCallback > cb = + vtkSmartPointer< SliderCallback >::New( ); + cb->Actors = mpr_actors; + + Slider x_slider( + mpr_actors->GetSliceNumberMinValue( 0 ), + mpr_actors->GetSliceNumberMaxValue( 0 ), + mpr_actors->GetSliceNumberMinValue( 0 ), + "X", interactor, + 0.100, 0.15, 0.290, 0.15, cb + ); + Slider y_slider( + mpr_actors->GetSliceNumberMinValue( 1 ), + mpr_actors->GetSliceNumberMaxValue( 1 ), + mpr_actors->GetSliceNumberMinValue( 1 ), + "Y", interactor, + 0.300, 0.15, 0.490, 0.15, cb + ); + Slider z_slider( + mpr_actors->GetSliceNumberMinValue( 2 ), + mpr_actors->GetSliceNumberMaxValue( 2 ), + mpr_actors->GetSliceNumberMinValue( 2 ), + "Z", interactor, + 0.500, 0.15, 0.690, 0.15, cb + ); + Slider w_slider( + mpr_actors->GetMinWindow( ), + mpr_actors->GetMaxWindow( ), + mpr_actors->GetWindow( ), + "Window", interactor, + 0.100, 0.05, 0.290, 0.05, cb + ); + Slider l_slider( + mpr_actors->GetMinWindow( ), + mpr_actors->GetMaxWindow( ), + mpr_actors->GetWindow( ), + "Level", interactor, + 0.300, 0.05, 0.490, 0.05, cb + ); // Begin interaction renderer->ResetCamera( ); diff --git a/appli/examples/example_MarchingCubes.cxx b/appli/examples/example_MarchingCubes.cxx index 7894fe0..fbd43bb 100644 --- a/appli/examples/example_MarchingCubes.cxx +++ b/appli/examples/example_MarchingCubes.cxx @@ -30,6 +30,7 @@ int main( int argc, char* argv[] ) // Create objects typedef cpPlugins::Interface::ProcessObject TProcessObject; + typedef cpPlugins::Interface::DataObject TDataObject; typedef cpPlugins::Interface::Parameters TParameters; cpPlugins::Interface::ProcessObject::Pointer reader, writer, mc; reader = plugins.CreateProcessObject( "cpPlugins::ImageReader" ); @@ -59,8 +60,8 @@ int main( int argc, char* argv[] ) writer->SetParameters( writer_params ); // Connect pipeline - mc->SetInput( 0, reader->GetOutput( 0 ) ); - writer->SetInput( 0, mc->GetOutput( 0 ) ); + mc->SetInput( 0, reader->GetOutput< TDataObject >( 0 ) ); + writer->SetInput( 0, mc->GetOutput< TDataObject >( 0 ) ); // Execute pipeline std::string err = writer->Update( ); diff --git a/appli/examples/example_OtsuFilter.cxx b/appli/examples/example_OtsuFilter.cxx index 9f91835..21c7a7e 100644 --- a/appli/examples/example_OtsuFilter.cxx +++ b/appli/examples/example_OtsuFilter.cxx @@ -30,6 +30,7 @@ int main( int argc, char* argv[] ) // Create objects typedef cpPlugins::Interface::ProcessObject TProcessObject; + typedef cpPlugins::Interface::DataObject TDataObject; typedef cpPlugins::Interface::Parameters TParameters; cpPlugins::Interface::ProcessObject::Pointer reader, writer, otsu; reader = plugins.CreateProcessObject( "cpPlugins::ImageReader" ); @@ -61,8 +62,8 @@ int main( int argc, char* argv[] ) writer->SetParameters( writer_params ); // Connect pipeline - otsu->SetInput( 0, reader->GetOutput( 0 ) ); - writer->SetInput( 0, otsu->GetOutput( 0 ) ); + otsu->SetInput( 0, reader->GetOutput< TDataObject >( 0 ) ); + writer->SetInput( 0, otsu->GetOutput< TDataObject >( 0 ) ); // Execute pipeline std::string err = writer->Update( ); diff --git a/appli/examples/example_RGBImageToHSVChannels.cxx b/appli/examples/example_RGBImageToHSVChannels.cxx index 03d0eea..57d0581 100644 --- a/appli/examples/example_RGBImageToHSVChannels.cxx +++ b/appli/examples/example_RGBImageToHSVChannels.cxx @@ -30,6 +30,7 @@ int main( int argc, char* argv[] ) // Create objects typedef cpPlugins::Interface::ProcessObject TProcessObject; + typedef cpPlugins::Interface::DataObject TDataObject; typedef cpPlugins::Interface::Parameters TParameters; cpPlugins::Interface::ProcessObject::Pointer reader, writer, filter; reader = plugins.CreateProcessObject( "cpPlugins::ImageReader" ); @@ -59,8 +60,8 @@ int main( int argc, char* argv[] ) writer->SetParameters( writer_params ); // Connect pipeline - filter->SetInput( 0, reader->GetOutput( 0 ) ); - writer->SetInput( 0, filter->GetOutput( 0 ) ); + filter->SetInput( 0, reader->GetOutput< TDataObject >( 0 ) ); + writer->SetInput( 0, filter->GetOutput< TDataObject >( 0 ) ); // Execute pipeline std::string err = writer->Update( ); diff --git a/appli/examples/example_RGBImageToYPbPrChannels.cxx b/appli/examples/example_RGBImageToYPbPrChannels.cxx index 7806289..d589db9 100644 --- a/appli/examples/example_RGBImageToYPbPrChannels.cxx +++ b/appli/examples/example_RGBImageToYPbPrChannels.cxx @@ -30,6 +30,7 @@ int main( int argc, char* argv[] ) // Create objects typedef cpPlugins::Interface::ProcessObject TProcessObject; + typedef cpPlugins::Interface::DataObject TDataObject; typedef cpPlugins::Interface::Parameters TParameters; cpPlugins::Interface::ProcessObject::Pointer reader, writer, filter; reader = plugins.CreateProcessObject( "cpPlugins::ImageReader" ); @@ -59,8 +60,8 @@ int main( int argc, char* argv[] ) writer->SetParameters( writer_params ); // Connect pipeline - filter->SetInput( 0, reader->GetOutput( 0 ) ); - writer->SetInput( 0, filter->GetOutput( 0 ) ); + filter->SetInput( 0, reader->GetOutput< TDataObject >( 0 ) ); + writer->SetInput( 0, filter->GetOutput< TDataObject >( 0 ) ); // Execute pipeline std::string err = writer->Update( ); diff --git a/appli/examples/example_ReadWriteImage.cxx b/appli/examples/example_ReadWriteImage.cxx index 0098973..5f01b44 100644 --- a/appli/examples/example_ReadWriteImage.cxx +++ b/appli/examples/example_ReadWriteImage.cxx @@ -32,6 +32,7 @@ int main( int argc, char* argv[] ) // Create objects typedef cpPlugins::Interface::ProcessObject TProcessObject; + typedef cpPlugins::Interface::DataObject TDataObject; typedef cpPlugins::Interface::Parameters TParameters; cpPlugins::Interface::ProcessObject::Pointer reader, writer; reader = plugins.CreateProcessObject( "cpPlugins::ImageReader" ); @@ -61,7 +62,7 @@ int main( int argc, char* argv[] ) writer->SetParameters( writer_params ); // Connect pipeline - writer->SetInput( 0, reader->GetOutput( 0 ) ); + writer->SetInput( 0, reader->GetOutput< TDataObject >( 0 ) ); // Execute pipeline std::string err = writer->Update( ); @@ -72,8 +73,6 @@ int main( int argc, char* argv[] ) } // fi - dynamic_cast< cpPlugins::Interface::Image* >( reader->GetOutput( 0 ) )->GetVTKImageData( )->Print( std::cout ); - return( 0 ); } diff --git a/lib/cpExtensions/Visualization/ImageInteractorStyle.cxx b/lib/cpExtensions/Visualization/ImageInteractorStyle.cxx index 236fb43..9dec032 100644 --- a/lib/cpExtensions/Visualization/ImageInteractorStyle.cxx +++ b/lib/cpExtensions/Visualization/ImageInteractorStyle.cxx @@ -315,6 +315,10 @@ OnMouseWheelForward( ) int s = this->m_SliceActors->GetSliceNumber( ) + off; int maxs = this->m_SliceActors->GetSliceNumberMaxValue( ); this->m_SliceActors->SetSliceNumber( ( s < maxs )? s: maxs ); + this->m_MPRActors->SetSlice( + this->m_SliceActors->GetAxis( ), + this->m_SliceActors->GetSliceNumber( ) + ); this->Interactor->Render( ); this->_RenderAssociateInteractors( ); } @@ -331,6 +335,10 @@ OnMouseWheelBackward( ) int s = this->m_SliceActors->GetSliceNumber( ) - off; int mins = this->m_SliceActors->GetSliceNumberMinValue( ); this->m_SliceActors->SetSliceNumber( ( mins < s )? s: mins ); + this->m_MPRActors->SetSlice( + this->m_SliceActors->GetAxis( ), + this->m_SliceActors->GetSliceNumber( ) + ); this->Interactor->Render( ); this->_RenderAssociateInteractors( ); } diff --git a/lib/cpExtensions/Visualization/MPRActors.cxx b/lib/cpExtensions/Visualization/MPRActors.cxx index 43600a3..2f7ce68 100644 --- a/lib/cpExtensions/Visualization/MPRActors.cxx +++ b/lib/cpExtensions/Visualization/MPRActors.cxx @@ -22,7 +22,7 @@ ImageSliceActors* cpExtensions::Visualization::MPRActors:: GetSliceActors( const int& i ) const { if( i < 3 ) - return( this->Slices[ i ] ); + return( this->Slices[ 0 ][ i ] ); else return( NULL ); } @@ -47,28 +47,29 @@ SetInputData( vtkImageData* image ) // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: -PushDataInto( vtkRenderer* x, vtkRenderer* y, vtkRenderer* z, vtkRenderer* w ) +PushDataInto( + vtkRenderer* x, vtkRenderer* y, vtkRenderer* z, vtkRenderer* w + ) { vtkRenderer* rends[] = { x, y, z }; for( int i = 0; i < 3; ++i ) { if( rends[ i ] != NULL ) { - rends[ i ]->AddActor( this->Slices[ i ]->GetImageActor( ) ); - rends[ i ]->AddActor( this->Slices[ i ]->GetTextActor( ) ); + rends[ i ]->AddActor( this->Slices[ 0 ][ i ]->GetImageActor( ) ); + rends[ i ]->AddActor( this->Slices[ 0 ][ i ]->GetTextActor( ) ); for( int j = 0; j < 3; ++j ) - rends[ i ]->AddActor( this->Slices[ j ]->GetPlaneActor( ) ); - if( w != NULL ) - { - w->AddActor( this->Slices[ i ]->GetImageActor( ) ); - w->AddActor( this->Slices[ i ]->GetPlaneActor( ) ); + rends[ i ]->AddActor( this->Slices[ 0 ][ j ]->GetPlaneActor( ) ); - } // fi + } // fi + if( w != NULL ) + { + w->AddActor( this->Slices[ 1 ][ i ]->GetImageActor( ) ); + w->AddActor( this->Slices[ 1 ][ i ]->GetPlaneActor( ) ); } // fi } // rof - if( w != NULL ) w->AddActor( this->ImageOutlineActor ); } @@ -82,14 +83,14 @@ PopDataFrom( vtkRenderer* x, vtkRenderer* y, vtkRenderer* z, vtkRenderer* w ) { if( rends[ i ] != NULL ) { - rends[ i ]->RemoveActor( this->Slices[ i ]->GetImageActor( ) ); - rends[ i ]->RemoveActor( this->Slices[ i ]->GetTextActor( ) ); + rends[ i ]->RemoveActor( this->Slices[ 0 ][ i ]->GetImageActor( ) ); + rends[ i ]->RemoveActor( this->Slices[ 0 ][ i ]->GetTextActor( ) ); for( int j = 0; j < 3; ++j ) - rends[ i ]->RemoveActor( this->Slices[ j ]->GetPlaneActor( ) ); + rends[ i ]->RemoveActor( this->Slices[ 0 ][ j ]->GetPlaneActor( ) ); if( w != NULL ) { - w->RemoveActor( this->Slices[ i ]->GetImageActor( ) ); - w->RemoveActor( this->Slices[ i ]->GetPlaneActor( ) ); + w->RemoveActor( this->Slices[ 1 ][ i ]->GetImageActor( ) ); + w->RemoveActor( this->Slices[ 1 ][ i ]->GetPlaneActor( ) ); } // fi @@ -98,10 +99,7 @@ PopDataFrom( vtkRenderer* x, vtkRenderer* y, vtkRenderer* z, vtkRenderer* w ) } // rof if( w != NULL ) - { w->RemoveActor( this->ImageOutlineActor ); - - } // fi } // ------------------------------------------------------------------------- @@ -289,21 +287,21 @@ ResetWindowLevel( ) int cpExtensions::Visualization::MPRActors:: GetSliceNumberMinValue( const int& axis ) const { - return( this->Slices[ axis ]->GetSliceNumberMinValue( ) ); + return( this->Slices[ 0 ][ axis ]->GetSliceNumberMinValue( ) ); } // ------------------------------------------------------------------------- int cpExtensions::Visualization::MPRActors:: GetSliceNumberMaxValue( const int& axis ) const { - return( this->Slices[ axis ]->GetSliceNumberMaxValue( ) ); + return( this->Slices[ 0 ][ axis ]->GetSliceNumberMaxValue( ) ); } // ------------------------------------------------------------------------- int cpExtensions::Visualization::MPRActors:: GetSlice( const int& axis ) const { - return( this->Slices[ axis ]->GetSliceNumber( ) ); + return( this->Slices[ 0 ][ axis ]->GetSliceNumber( ) ); } // ------------------------------------------------------------------------- @@ -326,7 +324,8 @@ SetSlice( const int& axis, const int& slice ) real = ext[ ( axis << 1 ) + 1 ]; // Change slice - this->Slices[ axis ]->SetSliceNumber( real ); + this->Slices[ 0 ][ axis ]->SetSliceNumber( real ); + this->Slices[ 1 ][ axis ]->SetSliceNumber( real ); this->Modified( ); } @@ -370,9 +369,12 @@ MPRActors( ) { this->ImageMapToColors = vtkSmartPointer< vtkImageMapToColors >::New( ); this->ImageOutlineActor = vtkSmartPointer< vtkActor >::New( ); - this->Slices[ 0 ] = vtkSmartPointer< _TSlice >::New( ); - this->Slices[ 1 ] = vtkSmartPointer< _TSlice >::New( ); - this->Slices[ 2 ] = vtkSmartPointer< _TSlice >::New( ); + this->Slices[ 0 ][ 0 ] = vtkSmartPointer< _TSlice >::New( ); + this->Slices[ 0 ][ 1 ] = vtkSmartPointer< _TSlice >::New( ); + this->Slices[ 0 ][ 2 ] = vtkSmartPointer< _TSlice >::New( ); + this->Slices[ 1 ][ 0 ] = vtkSmartPointer< _TSlice >::New( ); + this->Slices[ 1 ][ 1 ] = vtkSmartPointer< _TSlice >::New( ); + this->Slices[ 1 ][ 2 ] = vtkSmartPointer< _TSlice >::New( ); } // ------------------------------------------------------------------------- @@ -402,12 +404,16 @@ _UpdateSlices( ) return; this->ImageMapToColors->Update( ); - for( int i = 0; i < 3; ++i ) + for( int j = 0; j < 2; ++j ) { - this->Slices[ i ]->SetInputConnection( - this->ImageMapToColors->GetOutputPort( ), i - ); - this->Slices[ i ]->UpdateText( ); + for( int i = 0; i < 3; ++i ) + { + this->Slices[ j ][ i ]->SetInputConnection( + this->ImageMapToColors->GetOutputPort( ), i + ); + this->Slices[ j ][ i ]->UpdateText( ); + + } // rof } // rof diff --git a/lib/cpExtensions/Visualization/MPRActors.h b/lib/cpExtensions/Visualization/MPRActors.h index 85c7b63..c8718a3 100644 --- a/lib/cpExtensions/Visualization/MPRActors.h +++ b/lib/cpExtensions/Visualization/MPRActors.h @@ -101,7 +101,7 @@ namespace cpExtensions typedef cpExtensions::Visualization::ImageSliceActors _TSlice; - vtkSmartPointer< _TSlice > Slices[ 3 ]; + vtkSmartPointer< _TSlice > Slices[ 2 ][ 3 ]; unsigned int ImageOutlineActorIndex; }; diff --git a/lib/cpExtensions/Visualization/MPRWithDifferentWindows.cxx b/lib/cpExtensions/Visualization/MPRObjects.cxx similarity index 60% rename from lib/cpExtensions/Visualization/MPRWithDifferentWindows.cxx rename to lib/cpExtensions/Visualization/MPRObjects.cxx index cf0a68c..9c14323 100644 --- a/lib/cpExtensions/Visualization/MPRWithDifferentWindows.cxx +++ b/lib/cpExtensions/Visualization/MPRObjects.cxx @@ -1,22 +1,24 @@ -#include -#include +#include // ------------------------------------------------------------------------- -cpExtensions::Visualization::MPRWithDifferentWindows:: -MPRWithDifferentWindows( - vtkRenderWindow* xWin, - vtkRenderWindow* yWin, - vtkRenderWindow* zWin, - vtkRenderWindow* auxWin - ) +cpExtensions::Visualization::MPRObjects* +cpExtensions::Visualization::MPRObjects:: +New( ) { - this->m_Windows[ 0 ] = xWin; - this->m_Windows[ 1 ] = yWin; - this->m_Windows[ 2 ] = zWin; - this->m_Windows[ 3 ] = auxWin; + return( new Self( ) ); +} - // Prepare actors - this->m_MPRActors = vtkSmartPointer< TMPRActors >::New( ); +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::MPRObjects:: +SetRenderWindows( + vtkRenderWindow* wx, vtkRenderWindow* wy, + vtkRenderWindow* wz, vtkRenderWindow* w3D + ) +{ + this->m_Windows[ 0 ] = wx; + this->m_Windows[ 1 ] = wy; + this->m_Windows[ 2 ] = wz; + this->m_Windows[ 3 ] = w3D; // Prepare renderers for( int i = 0; i < 4; ++i ) @@ -72,13 +74,7 @@ MPRWithDifferentWindows( } // ------------------------------------------------------------------------- -cpExtensions::Visualization::MPRWithDifferentWindows:: -~MPRWithDifferentWindows( ) -{ -} - -// ------------------------------------------------------------------------- -void cpExtensions::Visualization::MPRWithDifferentWindows:: +void cpExtensions::Visualization::MPRObjects:: SetImage( vtkImageData* image ) { this->m_MPRActors->SetInputData( image ); @@ -103,31 +99,7 @@ SetImage( vtkImageData* image ) } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::MPRWithDifferentWindows:: -SetModeToNavigation( ) -{ - for( unsigned int i = 0; i < 3; ++i ) - { - if( this->m_Styles[ i ].GetPointer( ) != NULL ) - this->m_Styles[ i ]->SetModeToNavigation( ); - - } // rof -} - -// ------------------------------------------------------------------------- -void cpExtensions::Visualization::MPRWithDifferentWindows:: -SetModeToDeformation( ) -{ - for( unsigned int i = 0; i < 3; ++i ) - { - if( this->m_Styles[ i ].GetPointer( ) != NULL ) - this->m_Styles[ i ]->SetModeToDeformation( ); - - } // rof -} - -// ------------------------------------------------------------------------- -void cpExtensions::Visualization::MPRWithDifferentWindows:: +void cpExtensions::Visualization::MPRObjects:: ResetCamera( const int& id ) { if( id < 4 ) @@ -136,7 +108,7 @@ ResetCamera( const int& id ) } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::MPRWithDifferentWindows:: +void cpExtensions::Visualization::MPRObjects:: ResetCameras( ) { for( int i = 0; i < 4; ++i ) @@ -145,7 +117,7 @@ ResetCameras( ) } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::MPRWithDifferentWindows:: +void cpExtensions::Visualization::MPRObjects:: Render( const int& id ) { if( id < 4 ) @@ -154,7 +126,7 @@ Render( const int& id ) } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::MPRWithDifferentWindows:: +void cpExtensions::Visualization::MPRObjects:: RenderAll( ) { for( int i = 0; i < 4; ++i ) @@ -163,26 +135,74 @@ RenderAll( ) } // ------------------------------------------------------------------------- -vtkRenderer* cpExtensions::Visualization::MPRWithDifferentWindows:: -GetRenderer( const int& id ) const +vtkRenderer* cpExtensions::Visualization::MPRObjects:: +GetXRenderer( ) { - if( id < 4 ) - return( this->m_Renderers[ id ] ); - else - return( NULL ); + return( this->m_Renderers[ 0 ] ); } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::MPRWithDifferentWindows:: -Add3DActor( vtkProp3D* prop ) +vtkRenderer* cpExtensions::Visualization::MPRObjects:: +GetYRenderer( ) { - if( this->m_Renderers[ 3 ] != NULL ) - { - this->m_Renderers[ 3 ]->AddActor( prop ); - this->ResetCamera( 3 ); - this->Render( 3 ); + return( this->m_Renderers[ 1 ] ); +} - } // fi +// ------------------------------------------------------------------------- +vtkRenderer* cpExtensions::Visualization::MPRObjects:: +GetZRenderer( ) +{ + return( this->m_Renderers[ 2 ] ); +} + +// ------------------------------------------------------------------------- +vtkRenderer* cpExtensions::Visualization::MPRObjects:: +Get3DRenderer( ) +{ + return( this->m_Renderers[ 3 ] ); +} + +// ------------------------------------------------------------------------- +const vtkRenderer* cpExtensions::Visualization::MPRObjects:: +GetXRenderer( ) const +{ + return( this->m_Renderers[ 0 ] ); +} + +// ------------------------------------------------------------------------- +const vtkRenderer* cpExtensions::Visualization::MPRObjects:: +GetYRenderer( ) const +{ + return( this->m_Renderers[ 1 ] ); +} + +// ------------------------------------------------------------------------- +const vtkRenderer* cpExtensions::Visualization::MPRObjects:: +GetZRenderer( ) const +{ + return( this->m_Renderers[ 2 ] ); +} + +// ------------------------------------------------------------------------- +const vtkRenderer* cpExtensions::Visualization::MPRObjects:: +Get3DRenderer( ) const +{ + return( this->m_Renderers[ 3 ] ); +} + +// ------------------------------------------------------------------------- +cpExtensions::Visualization::MPRObjects:: +MPRObjects( ) + : vtkObject( ) +{ + // Prepare actors + this->m_MPRActors = vtkSmartPointer< TMPRActors >::New( ); +} + +// ------------------------------------------------------------------------- +cpExtensions::Visualization::MPRObjects:: +~MPRObjects( ) +{ } // eof - $RCSfile$ diff --git a/lib/cpExtensions/Visualization/MPRObjects.h b/lib/cpExtensions/Visualization/MPRObjects.h new file mode 100644 index 0000000..84db5d2 --- /dev/null +++ b/lib/cpExtensions/Visualization/MPRObjects.h @@ -0,0 +1,77 @@ +#ifndef __CPEXTENSIONS__VISUALIZATION__MPROBJECTS__H__ +#define __CPEXTENSIONS__VISUALIZATION__MPROBJECTS__H__ + +#include +#include +#include + +#include +#include +#include + +namespace cpExtensions +{ + namespace Visualization + { + /** + */ + class cpExtensions_EXPORT MPRObjects + : public vtkObject + { + public: + typedef MPRObjects Self; + typedef cpExtensions::Visualization::MPRActors TMPRActors; + typedef cpExtensions::Visualization::ImageInteractorStyle TStyle; + + public: + vtkTypeMacro( MPRObjects, vtkObject ); + + public: + // Creation + static MPRObjects* New( ); + + void SetRenderWindows( + vtkRenderWindow* wx, vtkRenderWindow* wy, + vtkRenderWindow* wz, vtkRenderWindow* w3D + ); + + void SetImage( vtkImageData* image ); + void ResetCamera( const int& id ); + void ResetCameras( ); + void Render( const int& id ); + void RenderAll( ); + vtkRenderer* GetXRenderer( ); + vtkRenderer* GetYRenderer( ); + vtkRenderer* GetZRenderer( ); + vtkRenderer* Get3DRenderer( ); + const vtkRenderer* GetXRenderer( ) const; + const vtkRenderer* GetYRenderer( ) const; + const vtkRenderer* GetZRenderer( ) const; + const vtkRenderer* Get3DRenderer( ) const; + + protected: + MPRObjects( ); + virtual ~MPRObjects( ); + + private: + // Purposely not implemented + MPRObjects( const Self& ); + Self& operator=( const Self& ); + + protected: + // Inputs + vtkSmartPointer< vtkRenderWindow > m_Windows[ 4 ]; + + // Internal pipelines + vtkSmartPointer< TMPRActors > m_MPRActors; + vtkSmartPointer< vtkRenderer > m_Renderers[ 4 ]; + vtkSmartPointer< TStyle > m_Styles[ 3 ]; + }; + + } // ecapseman + +} // ecapseman + +#endif // __CPEXTENSIONS__VISUALIZATION__MPROBJECTS__H__ + +// eof - $RCSfile$ diff --git a/lib/cpExtensions/Visualization/MPRWithDifferentWindows.h b/lib/cpExtensions/Visualization/MPRWithDifferentWindows.h deleted file mode 100644 index 2b5a4e7..0000000 --- a/lib/cpExtensions/Visualization/MPRWithDifferentWindows.h +++ /dev/null @@ -1,92 +0,0 @@ -#ifndef __CPEXTENSIONS__VISUALIZATION__MPRWITHDIFFERENTWINDOWS__H__ -#define __CPEXTENSIONS__VISUALIZATION__MPRWITHDIFFERENTWINDOWS__H__ - -#include -#include -#include - -#include -#include -#include -#include - -// ------------------------------------------------------------------------- -#define cpPlugins_MPRWithDifferentWindows_ObserverMacro( e ) \ - inline void Add##e##Observer( vtkCommand* observer ) \ - { \ - for( int i = 0; i < 3; ++i ) \ - if( this->m_Styles[ i ].GetPointer( ) != NULL ) \ - this->m_Styles[ i ]->Add##e##Observer( observer ); \ - } \ - inline void Remove##e##Observer( vtkCommand* observer ) \ - { \ - for( int i = 0; i < 3; ++i ) \ - if( this->m_Styles[ i ].GetPointer( ) != NULL ) \ - this->m_Styles[ i ]->Remove##e##Observer( observer ); \ - } \ - inline void Remove##e##Observers( ) \ - { \ - for( int i = 0; i < 3; ++i ) \ - if( this->m_Styles[ i ].GetPointer( ) != NULL ) \ - this->m_Styles[ i ]->Remove##e##Observers( ); \ - } - -namespace cpExtensions -{ - namespace Visualization - { - /** - */ - class cpExtensions_EXPORT MPRWithDifferentWindows - { - public: - typedef cpExtensions::Visualization:: - MPRActors TMPRActors; - typedef cpExtensions::Visualization:: - ImageInteractorStyle TStyle; - - public: - cpPlugins_MPRWithDifferentWindows_ObserverMacro( DoubleClick ); - cpPlugins_MPRWithDifferentWindows_ObserverMacro( Cursor ); - cpPlugins_MPRWithDifferentWindows_ObserverMacro( Radius ); - - public: - MPRWithDifferentWindows( - vtkRenderWindow* xWin = NULL, - vtkRenderWindow* yWin = NULL, - vtkRenderWindow* zWin = NULL, - vtkRenderWindow* auxWin = NULL - ); - virtual ~MPRWithDifferentWindows( ); - - void SetImage( vtkImageData* image ); - void SetModeToNavigation( ); - void SetModeToDeformation( ); - - void ResetCamera( const int& id ); - void ResetCameras( ); - void Render( const int& id ); - void RenderAll( ); - - vtkRenderer* GetRenderer( const int& id ) const; - - void Add3DActor( vtkProp3D* prop ); - - protected: - // Inputs - vtkRenderWindow* m_Windows[ 4 ]; - - // Internal pipelines - vtkSmartPointer< TMPRActors > m_MPRActors; - vtkSmartPointer< vtkRenderer > m_Renderers[ 4 ]; - vtkSmartPointer< TStyle > m_Styles[ 3 ]; - }; - - } // ecapseman - -} // ecapseman - -#endif // __CPEXTENSIONS__VISUALIZATION__MPRWITHDIFFERENTWINDOWS__H__ - - -// eof - $RCSfile$ diff --git a/lib/cpPlugins/Interface/Mesh.cxx b/lib/cpPlugins/Interface/Mesh.cxx index 0f74681..8507a4b 100644 --- a/lib/cpPlugins/Interface/Mesh.cxx +++ b/lib/cpPlugins/Interface/Mesh.cxx @@ -7,6 +7,13 @@ void cpPlugins::Interface::Mesh:: SetVTKMesh( vtkPolyData* mesh ) { this->m_VTKObject = mesh; + + this->m_Mapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); + this->m_Actor = vtkSmartPointer< vtkActor >::New( ); + + this->m_Mapper->SetInputData( mesh ); + this->m_Actor->SetMapper( this->m_Mapper ); + this->Modified( ); } @@ -26,6 +33,20 @@ GetVTKMesh( ) const ); } +// ------------------------------------------------------------------------- +vtkActor* cpPlugins::Interface::Mesh:: +GetVTKActor( ) +{ + return( this->m_Actor ); +} + +// ------------------------------------------------------------------------- +const vtkActor* cpPlugins::Interface::Mesh:: +GetVTKActor( ) const +{ + return( this->m_Actor ); +} + // ------------------------------------------------------------------------- cpPlugins::Interface::Mesh:: Mesh( ) diff --git a/lib/cpPlugins/Interface/Mesh.h b/lib/cpPlugins/Interface/Mesh.h index c934f33..75c5eb3 100644 --- a/lib/cpPlugins/Interface/Mesh.h +++ b/lib/cpPlugins/Interface/Mesh.h @@ -4,7 +4,10 @@ #include #include -class vtkPolyData; +#include +#include +#include +#include namespace cpPlugins { @@ -38,6 +41,8 @@ namespace cpPlugins virtual void SetVTKMesh( vtkPolyData* mesh ); virtual vtkPolyData* GetVTKMesh( ); virtual const vtkPolyData* GetVTKMesh( ) const; + virtual vtkActor* GetVTKActor( ); + virtual const vtkActor* GetVTKActor( ) const; protected: Mesh( ); @@ -47,6 +52,10 @@ namespace cpPlugins // Purposely not implemented Mesh( const Self& ); Self& operator=( const Self& ); + + protected: + vtkSmartPointer< vtkActor > m_Actor; + vtkSmartPointer< vtkPolyDataMapper > m_Mapper; }; } // ecapseman diff --git a/lib/cpPlugins/Interface/ParametersQtDialog.cxx b/lib/cpPlugins/Interface/ParametersQtDialog.cxx index 819abd3..1cc5820 100644 --- a/lib/cpPlugins/Interface/ParametersQtDialog.cxx +++ b/lib/cpPlugins/Interface/ParametersQtDialog.cxx @@ -10,6 +10,7 @@ #include #include #include +#include #include // ------------------------------------------------------------------------- @@ -47,7 +48,6 @@ ParametersQtDialog( BoolList, IntList, UintList, - RealList, IndexList, PointList, NoType @@ -91,6 +91,26 @@ ParametersQtDialog( v_double->setMaximum( std::numeric_limits< double >::max( ) ); v_double->setValue( parameters.GetValueAsReal( *nIt ) ); w_input = v_double; + } + else if( pt == Parameters::RealList ) + { + QStringList header; + header << nIt->c_str( ); + + QTableWidget* l_double = new QTableWidget( dlg ); + l_double->setColumnCount( 1 ); + l_double->setRowCount( 1 ); + l_double->setHorizontalHeaderLabels( header ); + l_double->setShowGrid( true ); + l_double->setSelectionBehavior( QAbstractItemView::SelectRows ); + l_double->setSelectionMode( QAbstractItemView::SingleSelection ); + + QObject::connect( + l_double, SIGNAL( cellDoubleClicked( int, int ) ), + l_double, SLOT( insertRow( int ) ) + ); + + w_input = l_double; } // fi @@ -159,6 +179,24 @@ ParametersQtDialog( dlg->findChild< QDoubleSpinBox* >( nIt->c_str( ) ); if( v_double != NULL ) parameters.SetValueAsReal( *nIt, v_double->value( ) ); + } + else if( pt == Parameters::RealList ) + { + QTableWidget* l_double = + dlg->findChild< QTableWidget* >( nIt->c_str( ) ); + if( l_double != NULL ) + { + for( int r = 0; r < l_double->rowCount( ); ++r ) + { + double v = + std::atof( + l_double->item( r, 0 )->text( ).toStdString( ).c_str( ) + ); + parameters.AddValueToRealList( *nIt, v ); + + } // rof + + } // fi } // fi diff --git a/lib/cpPlugins/Interface/ProcessObject.cxx b/lib/cpPlugins/Interface/ProcessObject.cxx index 0f8f288..3630e49 100644 --- a/lib/cpPlugins/Interface/ProcessObject.cxx +++ b/lib/cpPlugins/Interface/ProcessObject.cxx @@ -60,16 +60,6 @@ SetInput( unsigned int idx, cpPlugins::Interface::DataObject* dobj ) } // fi } -// ------------------------------------------------------------------------- -cpPlugins::Interface::DataObject* cpPlugins::Interface::ProcessObject:: -GetOutput( unsigned int idx ) -{ - if( idx < this->m_Outputs.size( ) ) - return( this->m_Outputs[ idx ] ); - else - return( NULL ); -} - // ------------------------------------------------------------------------- std::string cpPlugins::Interface::ProcessObject:: Update( ) diff --git a/lib/cpPlugins/Interface/ProcessObject.h b/lib/cpPlugins/Interface/ProcessObject.h index 3381fa8..d201a6c 100644 --- a/lib/cpPlugins/Interface/ProcessObject.h +++ b/lib/cpPlugins/Interface/ProcessObject.h @@ -37,29 +37,28 @@ namespace cpPlugins virtual void SetNumberOfOutputs( unsigned int n ); virtual void SetInput( unsigned int idx, DataObject* dobj ); - virtual DataObject* GetOutput( unsigned int idx ); virtual std::string Update( ); virtual void DisconnectOutputs( ); - protected: - ProcessObject( ); - virtual ~ProcessObject( ); - - template< class O > - inline void _MakeOutput( unsigned int idx ); - template< class T > - inline T* _Input( unsigned int idx ); + inline T* GetInput( unsigned int idx ); template< class T > - inline const T* _Input( unsigned int idx ) const; + inline const T* GetInput( unsigned int idx ) const; template< class T > - inline T* _Output( unsigned int idx ); + inline T* GetOutput( unsigned int idx ); template< class T > - inline const T* _Output( unsigned int idx ) const; + inline const T* GetOutput( unsigned int idx ) const; + + protected: + ProcessObject( ); + virtual ~ProcessObject( ); + + template< class O > + inline void _MakeOutput( unsigned int idx ); virtual std::string _GenerateData( ) = 0; diff --git a/lib/cpPlugins/Interface/ProcessObject.hxx b/lib/cpPlugins/Interface/ProcessObject.hxx index a4a417b..f84d4a6 100644 --- a/lib/cpPlugins/Interface/ProcessObject.hxx +++ b/lib/cpPlugins/Interface/ProcessObject.hxx @@ -1,21 +1,10 @@ #ifndef __CPPLUGINS__INTERFACE__PROCESSOBJECT__HXX__ #define __CPPLUGINS__INTERFACE__PROCESSOBJECT__HXX__ -// ------------------------------------------------------------------------- -template< class O > -void cpPlugins::Interface::ProcessObject:: -_MakeOutput( unsigned int idx ) -{ - if( idx >= this->m_Outputs.size( ) ) - return; - this->m_Outputs[ idx ] = O::New( ); - this->m_Outputs[ idx ]->SetSource( this ); -} - // ------------------------------------------------------------------------- template< class T > T* cpPlugins::Interface::ProcessObject:: -_Input( unsigned int idx ) +GetInput( unsigned int idx ) { if( idx < this->m_Inputs.size( ) ) return( dynamic_cast< T* >( this->m_Inputs[ idx ].GetPointer( ) ) ); @@ -26,7 +15,7 @@ _Input( unsigned int idx ) // ------------------------------------------------------------------------- template< class T > const T* cpPlugins::Interface::ProcessObject:: -_Input( unsigned int idx ) const +GetInput( unsigned int idx ) const { if( idx < this->m_Inputs.size( ) ) return( @@ -39,7 +28,7 @@ _Input( unsigned int idx ) const // ------------------------------------------------------------------------- template< class T > T* cpPlugins::Interface::ProcessObject:: -_Output( unsigned int idx ) +GetOutput( unsigned int idx ) { if( idx < this->m_Outputs.size( ) ) return( dynamic_cast< T* >( this->m_Outputs[ idx ].GetPointer( ) ) ); @@ -50,7 +39,7 @@ _Output( unsigned int idx ) // ------------------------------------------------------------------------- template< class T > const T* cpPlugins::Interface::ProcessObject:: -_Output( unsigned int idx ) const +GetOutput( unsigned int idx ) const { if( idx < this->m_Outputs.size( ) ) return( @@ -60,6 +49,17 @@ _Output( unsigned int idx ) const return( NULL ); } +// ------------------------------------------------------------------------- +template< class O > +void cpPlugins::Interface::ProcessObject:: +_MakeOutput( unsigned int idx ) +{ + if( idx >= this->m_Outputs.size( ) ) + return; + this->m_Outputs[ idx ] = O::New( ); + this->m_Outputs[ idx ]->SetSource( this ); +} + #endif // __CPPLUGINS__INTERFACE__PROCESSOBJECT__HXX__ // eof - $RCSfile$ diff --git a/lib/cpPlugins/Plugins/ImageReader.cxx b/lib/cpPlugins/Plugins/ImageReader.cxx index fc752ef..73611cb 100644 --- a/lib/cpPlugins/Plugins/ImageReader.cxx +++ b/lib/cpPlugins/Plugins/ImageReader.cxx @@ -49,7 +49,7 @@ _GenerateData( ) { io->SetFileName( names[ 0 ] ); io->ReadImageInformation( ); - if( names.size( ) == 1 ) + if( names.size( ) >= 1 ) { switch( io->GetNumberOfDimensions( ) ) { @@ -57,19 +57,7 @@ _GenerateData( ) case 3: r = this->_GD0< 3 >( io, names ); break; case 4: r = this->_GD0< 4 >( io, names ); break; default: - r = "ImageReader: Single image dimension not supported."; - break; - } // hctiws - } - else if( names.size( ) > 1 ) - { - switch( io->GetNumberOfDimensions( ) ) - { - case 1: r = this->_GD0< 2 >( io, names ); break; - case 2: r = this->_GD0< 3 >( io, names ); break; - case 3: r = this->_GD0< 4 >( io, names ); break; - default: - r = "ImageReader: Multiple images dimension not supported."; + r = "ImageReader: Image dimension not supported."; break; } // hctiws @@ -149,8 +137,26 @@ _GD0( itk::ImageIOBase* io, const TStringList& names ) case itk::ImageIOBase::SHORT: r = this->_RealGD< itk::RGBPixel< short >, 2 >( names ); break; + case itk::ImageIOBase::UINT: + r = this->_RealGD< itk::RGBPixel< unsigned int >, 2 >( names ); + break; + case itk::ImageIOBase::INT: + r = this->_RealGD< itk::RGBPixel< int >, 2 >( names ); + break; + case itk::ImageIOBase::ULONG: + r = this->_RealGD< itk::RGBPixel< unsigned long >, 2 >( names ); + break; + case itk::ImageIOBase::LONG: + r = this->_RealGD< itk::RGBPixel< long >, 2 >( names ); + break; + case itk::ImageIOBase::FLOAT: + r = this->_RealGD< itk::RGBPixel< float >, 2 >( names ); + break; + case itk::ImageIOBase::DOUBLE: + r = this->_RealGD< itk::RGBPixel< double >, 2 >( names ); + break; default: - r = "ImageReader: Scalar pixel type not supported."; + r = "ImageReader: RGB pixel type not supported."; break; } // hctiws } @@ -170,8 +176,26 @@ _GD0( itk::ImageIOBase* io, const TStringList& names ) case itk::ImageIOBase::SHORT: r = this->_RealGD< itk::RGBPixel< short >, 3 >( names ); break; + case itk::ImageIOBase::UINT: + r = this->_RealGD< itk::RGBPixel< unsigned int >, 3 >( names ); + break; + case itk::ImageIOBase::INT: + r = this->_RealGD< itk::RGBPixel< int >, 3 >( names ); + break; + case itk::ImageIOBase::ULONG: + r = this->_RealGD< itk::RGBPixel< unsigned long >, 3 >( names ); + break; + case itk::ImageIOBase::LONG: + r = this->_RealGD< itk::RGBPixel< long >, 3 >( names ); + break; + case itk::ImageIOBase::FLOAT: + r = this->_RealGD< itk::RGBPixel< float >, 3 >( names ); + break; + case itk::ImageIOBase::DOUBLE: + r = this->_RealGD< itk::RGBPixel< double >, 3 >( names ); + break; default: - r = "ImageReader: Scalar pixel type not supported."; + r = "ImageReader: RGB pixel type not supported."; break; } // hctiws } @@ -191,8 +215,26 @@ _GD0( itk::ImageIOBase* io, const TStringList& names ) case itk::ImageIOBase::SHORT: r = this->_RealGD< itk::RGBPixel< short >, 4 >( names ); break; + case itk::ImageIOBase::UINT: + r = this->_RealGD< itk::RGBPixel< unsigned int >, 4 >( names ); + break; + case itk::ImageIOBase::INT: + r = this->_RealGD< itk::RGBPixel< int >, 4 >( names ); + break; + case itk::ImageIOBase::ULONG: + r = this->_RealGD< itk::RGBPixel< unsigned long >, 4 >( names ); + break; + case itk::ImageIOBase::LONG: + r = this->_RealGD< itk::RGBPixel< long >, 4 >( names ); + break; + case itk::ImageIOBase::FLOAT: + r = this->_RealGD< itk::RGBPixel< float >, 4 >( names ); + break; + case itk::ImageIOBase::DOUBLE: + r = this->_RealGD< itk::RGBPixel< double >, 4 >( names ); + break; default: - r = "ImageReader: Scalar pixel type not supported."; + r = "ImageReader: RGB pixel type not supported."; break; } // hctiws @@ -216,8 +258,26 @@ _GD0( itk::ImageIOBase* io, const TStringList& names ) case itk::ImageIOBase::SHORT: r = this->_RealGD< itk::RGBAPixel< short >, 2 >( names ); break; + case itk::ImageIOBase::UINT: + r = this->_RealGD< itk::RGBAPixel< unsigned int >, 2 >( names ); + break; + case itk::ImageIOBase::INT: + r = this->_RealGD< itk::RGBAPixel< int >, 2 >( names ); + break; + case itk::ImageIOBase::ULONG: + r = this->_RealGD< itk::RGBAPixel< unsigned long >, 2 >( names ); + break; + case itk::ImageIOBase::LONG: + r = this->_RealGD< itk::RGBAPixel< long >, 2 >( names ); + break; + case itk::ImageIOBase::FLOAT: + r = this->_RealGD< itk::RGBAPixel< float >, 2 >( names ); + break; + case itk::ImageIOBase::DOUBLE: + r = this->_RealGD< itk::RGBAPixel< double >, 2 >( names ); + break; default: - r = "ImageReader: Scalar pixel type not supported."; + r = "ImageReader: RGBA pixel type not supported."; break; } // hctiws } @@ -237,8 +297,26 @@ _GD0( itk::ImageIOBase* io, const TStringList& names ) case itk::ImageIOBase::SHORT: r = this->_RealGD< itk::RGBAPixel< short >, 3 >( names ); break; + case itk::ImageIOBase::UINT: + r = this->_RealGD< itk::RGBAPixel< unsigned int >, 3 >( names ); + break; + case itk::ImageIOBase::INT: + r = this->_RealGD< itk::RGBAPixel< int >, 3 >( names ); + break; + case itk::ImageIOBase::ULONG: + r = this->_RealGD< itk::RGBAPixel< unsigned long >, 3 >( names ); + break; + case itk::ImageIOBase::LONG: + r = this->_RealGD< itk::RGBAPixel< long >, 3 >( names ); + break; + case itk::ImageIOBase::FLOAT: + r = this->_RealGD< itk::RGBAPixel< float >, 3 >( names ); + break; + case itk::ImageIOBase::DOUBLE: + r = this->_RealGD< itk::RGBAPixel< double >, 3 >( names ); + break; default: - r = "ImageReader: Scalar pixel type not supported."; + r = "ImageReader: RGBA pixel type not supported."; break; } // hctiws } @@ -258,8 +336,26 @@ _GD0( itk::ImageIOBase* io, const TStringList& names ) case itk::ImageIOBase::SHORT: r = this->_RealGD< itk::RGBAPixel< short >, 4 >( names ); break; + case itk::ImageIOBase::UINT: + r = this->_RealGD< itk::RGBAPixel< unsigned int >, 4 >( names ); + break; + case itk::ImageIOBase::INT: + r = this->_RealGD< itk::RGBAPixel< int >, 4 >( names ); + break; + case itk::ImageIOBase::ULONG: + r = this->_RealGD< itk::RGBAPixel< unsigned long >, 4 >( names ); + break; + case itk::ImageIOBase::LONG: + r = this->_RealGD< itk::RGBAPixel< long >, 4 >( names ); + break; + case itk::ImageIOBase::FLOAT: + r = this->_RealGD< itk::RGBAPixel< float >, 4 >( names ); + break; + case itk::ImageIOBase::DOUBLE: + r = this->_RealGD< itk::RGBAPixel< double >, 4 >( names ); + break; default: - r = "ImageReader: Scalar pixel type not supported."; + r = "ImageReader: RGBA pixel type not supported."; break; } // hctiws @@ -324,7 +420,7 @@ _GD0( itk::ImageIOBase* io, const TStringList& names ) r = this->_RealGD< itk::CovariantVector< double, D >, D >( names ); break; default: - r = "ImageReader: Vector type not supported."; + r = "ImageReader: CovariantVector type not supported."; break; } // hctiws } @@ -416,6 +512,11 @@ _RealGD( const TStringList& names ) { typedef itk::Image< P, D > _I; + cpPlugins::Interface::Image* out = + this->GetOutput< cpPlugins::Interface::Image >( 0 ); + if( out == NULL ) + return( "ImageReader: No output object properly created." ); + std::string r = ""; if( names.size( ) == 1 ) { @@ -434,22 +535,12 @@ _RealGD( const TStringList& names ) try { reader->Update( ); - cpPlugins::Interface::Image* out = - this->_Output< cpPlugins::Interface::Image >( 0 ); - if( out != NULL ) - out->SetITKImage< _I >( reader->GetOutput( ) ); - else - r = "ImageReader: output not correctly created."; + out->SetITKImage< _I >( reader->GetOutput( ) ); } catch( itk::ExceptionObject& err ) { r = "ImageReader: " + std::string( err.GetDescription( ) ); - cpPlugins::Interface::Image* out = - this->_Output< cpPlugins::Interface::Image >( 0 ); - if( out != NULL ) - out->SetITKImage< _I >( NULL ); - else - r = "ImageReader: output not correctly created."; + out->SetITKImage< _I >( NULL ); } // yrt } @@ -472,26 +563,18 @@ _RealGD( const TStringList& names ) } // fi std::set< std::string >::const_iterator fnIt = ordered_names.begin( ); for( ; fnIt != ordered_names.end( ); ++fnIt ) + { reader->AddFileName( *fnIt ); + } try { reader->Update( ); - cpPlugins::Interface::Image* out = - this->_Output< cpPlugins::Interface::Image >( 0 ); - if( out != NULL ) - out->SetITKImage< _I >( reader->GetOutput( ) ); - else - r = "ImageReader: output not correctly created."; + out->SetITKImage< _I >( reader->GetOutput( ) ); } catch( itk::ExceptionObject& err ) { r = "ImageReader: " + std::string( err.GetDescription( ) ); - cpPlugins::Interface::Image* out = - this->_Output< cpPlugins::Interface::Image >( 0 ); - if( out != NULL ) - out->SetITKImage< _I >( NULL ); - else - r = "ImageReader: output not correctly created."; + out->SetITKImage< _I >( NULL ); } // yrt } diff --git a/lib/cpPlugins/Plugins/ImageWriter.cxx b/lib/cpPlugins/Plugins/ImageWriter.cxx index 921df92..59dbe83 100644 --- a/lib/cpPlugins/Plugins/ImageWriter.cxx +++ b/lib/cpPlugins/Plugins/ImageWriter.cxx @@ -28,7 +28,7 @@ std::string cpPlugins::Plugins::ImageWriter:: _GenerateData( ) { cpPlugins::Interface::Image* image = - this->_Input< cpPlugins::Interface::Image >( 0 ); + this->GetInput< cpPlugins::Interface::Image >( 0 ); if( image == NULL ) return( "ImageWriter: No input image." ); diff --git a/lib/cpPlugins/Plugins/MarchingCubes.cxx b/lib/cpPlugins/Plugins/MarchingCubes.cxx index ca6e5bf..94af090 100644 --- a/lib/cpPlugins/Plugins/MarchingCubes.cxx +++ b/lib/cpPlugins/Plugins/MarchingCubes.cxx @@ -38,7 +38,7 @@ _GenerateData( ) { // Get input cpPlugins::Interface::Image* image = - this->_Input< cpPlugins::Interface::Image >( 0 ); + this->GetInput< cpPlugins::Interface::Image >( 0 ); if( image == NULL ) return( "MarchingCubes: Input data is not a valid image." ); vtkImageData* vtk_image = image->GetVTKImageData( ); @@ -72,7 +72,7 @@ _GenerateData( ) // Execute filter this->m_Algorithm->Update( ); cpPlugins::Interface::Mesh* out = - this->_Output< cpPlugins::Interface::Mesh >( 0 ); + this->GetOutput< cpPlugins::Interface::Mesh >( 0 ); out->SetVTKMesh( this->m_Algorithm->GetOutput( ) ); return( "" ); } diff --git a/lib/cpPlugins/Plugins/MeshReader.cxx b/lib/cpPlugins/Plugins/MeshReader.cxx index 0528e6c..1993259 100644 --- a/lib/cpPlugins/Plugins/MeshReader.cxx +++ b/lib/cpPlugins/Plugins/MeshReader.cxx @@ -79,7 +79,7 @@ _GD1( ) pdr->Update( ); cpPlugins::Interface::Mesh* out = - this->_Output< cpPlugins::Interface::Mesh >( 0 ); + this->GetOutput< cpPlugins::Interface::Mesh >( 0 ); if( out != NULL ) out->SetVTKMesh( pdr->GetOutput( ) ); else diff --git a/lib/cpPlugins/Plugins/MeshWriter.cxx b/lib/cpPlugins/Plugins/MeshWriter.cxx index 5b06347..6cc7841 100644 --- a/lib/cpPlugins/Plugins/MeshWriter.cxx +++ b/lib/cpPlugins/Plugins/MeshWriter.cxx @@ -33,7 +33,7 @@ std::string cpPlugins::Plugins::MeshWriter:: _GenerateData( ) { cpPlugins::Interface::Mesh* mesh = - this->_Input< cpPlugins::Interface::Mesh >( 0 ); + this->GetInput< cpPlugins::Interface::Mesh >( 0 ); if( mesh == NULL ) return( "MeshWriter: No input mesh." ); vtkPolyData* i = mesh->GetVTKMesh( ); diff --git a/lib/cpPlugins/Plugins/OtsuThresholdImageFilter.cxx b/lib/cpPlugins/Plugins/OtsuThresholdImageFilter.cxx index efc7d6a..dc6fd94 100644 --- a/lib/cpPlugins/Plugins/OtsuThresholdImageFilter.cxx +++ b/lib/cpPlugins/Plugins/OtsuThresholdImageFilter.cxx @@ -37,7 +37,7 @@ std::string cpPlugins::Plugins::OtsuThresholdImageFilter:: _GenerateData( ) { cpPlugins::Interface::Image* image = - this->_Input< cpPlugins::Interface::Image >( 0 ); + this->GetInput< cpPlugins::Interface::Image >( 0 ); if( image == NULL ) return( "OtsuThresholdImageFilter: No input image." ); @@ -98,7 +98,7 @@ _RealGD( itk::DataObject* image ) // Connect output cpPlugins::Interface::Image* out = - this->_Output< cpPlugins::Interface::Image >( 0 ); + this->GetOutput< cpPlugins::Interface::Image >( 0 ); if( out != NULL ) { out->SetITKImage< O >( filter->GetOutput( ) ); diff --git a/lib/cpPlugins/Plugins/RGBImageToOtherChannelsFilter.cxx b/lib/cpPlugins/Plugins/RGBImageToOtherChannelsFilter.cxx index 1a88201..6cc0d1c 100644 --- a/lib/cpPlugins/Plugins/RGBImageToOtherChannelsFilter.cxx +++ b/lib/cpPlugins/Plugins/RGBImageToOtherChannelsFilter.cxx @@ -53,7 +53,7 @@ std::string cpPlugins::Plugins::RGBImageToOtherChannelsFilter:: _GenerateData( ) { cpPlugins::Interface::Image* image = - this->_Input< cpPlugins::Interface::Image >( 0 ); + this->GetInput< cpPlugins::Interface::Image >( 0 ); if( image == NULL ) return( "RGBImageToOtherChannelsFilter: No input image." ); @@ -119,7 +119,7 @@ _RealGD( itk::DataObject* image ) // Connect output cpPlugins::Interface::Image* out = - this->_Output< cpPlugins::Interface::Image >( 0 ); + this->GetOutput< cpPlugins::Interface::Image >( 0 ); if( out != NULL ) { out->SetITKImage< _O >( filter->GetOutput( ) ); diff --git a/lib/cpPlugins/Plugins/SecondRankDiffusionTensorToPolyData.cxx b/lib/cpPlugins/Plugins/SecondRankDiffusionTensorToPolyData.cxx index 47261cc..62a5907 100644 --- a/lib/cpPlugins/Plugins/SecondRankDiffusionTensorToPolyData.cxx +++ b/lib/cpPlugins/Plugins/SecondRankDiffusionTensorToPolyData.cxx @@ -36,7 +36,7 @@ _GenerateData( ) { // Get input cpPlugins::Interface::Image* image = - this->_Input< cpPlugins::Interface::Image >( 0 ); + this->GetInput< cpPlugins::Interface::Image >( 0 ); if( image == NULL ) return( "SecondRankDiffusionTensorToPolyData: Input data is not a valid image." ); @@ -69,7 +69,7 @@ _RealGD( itk::DataObject* image ) // Connect output cpPlugins::Interface::Mesh* out = - this->_Output< cpPlugins::Interface::Mesh >( 0 ); + this->GetOutput< cpPlugins::Interface::Mesh >( 0 ); if( out != NULL ) { out->SetVTKMesh( this->m_Algorithm->GetOutput( ) );