From 2553991938011b002691361f0ed4ae95a552a686 Mon Sep 17 00:00:00 2001 From: Leonardo Florez-Valencia Date: Tue, 13 Oct 2015 18:13:04 -0500 Subject: [PATCH] Parameters are now part of the pipeline update process --- CMakeLists.txt | 27 +- COMPILATION | 143 +++-- README | 3 +- appli/ImageMPR/CMakeLists.txt | 6 + appli/ImageMPR/ImageMPR.cxx | 169 +++++- appli/ImageMPR/ImageMPR.h | 105 ++-- appli/ImageMPR/ImageMPR.ui | 205 +++---- appli/ImageMPR/MementoState.cxx | 1 + appli/ImageMPR/Plugins.cfg.in | 2 + lib/cpExtensions/QT/QuadSplitter.cxx | 25 +- lib/cpExtensions/QT/QuadSplitter.h | 11 +- .../Visualization/ImageSliceActors.cxx | 356 ++++++++----- .../Visualization/ImageSliceActors.h | 47 +- lib/cpExtensions/Visualization/MPRActors.cxx | 501 +++++------------- lib/cpExtensions/Visualization/MPRActors.h | 61 +-- lib/cpExtensions/Visualization/MPRObjects.cxx | 86 +-- lib/cpExtensions/Visualization/MPRObjects.h | 5 +- lib/cpPlugins/Interface/BaseMPRWindow.cxx | 295 ++++++++++- lib/cpPlugins/Interface/BaseMPRWindow.h | 67 ++- lib/cpPlugins/Interface/BaseMPRWindow.ui | 230 -------- lib/cpPlugins/Interface/CMakeLists.txt | 1 - lib/cpPlugins/Interface/Instances_itkMesh.cxx | 1 + .../Interface/Instances_itkVectorImage.cxx | 1 + lib/cpPlugins/Interface/Interface.cxx | 81 ++- lib/cpPlugins/Interface/Parameters.cxx | 2 +- .../BasicFilters/BinaryErodeImageFilter.cxx | 17 +- .../BinaryThresholdImageFilter.cxx | 24 +- .../BasicFilters/BinaryThresholdImageFilter.h | 2 +- lib/cpPlugins/Plugins/BasicFilters/Cutter.cxx | 2 - .../BasicFilters/ExtractSliceImageFilter.cxx | 17 +- .../BasicFilters/FloodFillImageFilter.cxx | 20 +- .../Plugins/BasicFilters/MarchingCubes.cxx | 6 +- .../BasicFilters/MedianImageFilter.cxx | 9 +- .../BasicFilters/OtsuThresholdImageFilter.cxx | 20 +- .../RGBImageToOtherChannelsFilter.cxx | 8 +- .../Plugins/BasicFilters/SphereMeshSource.cxx | 25 +- lib/cpPlugins/Plugins/CMakeLists.txt | 2 +- lib/cpPlugins/Plugins/IO/ImageReader.cxx | 4 + lib/cpPlugins/Plugins/IO/ImageWriter.cxx | 40 +- lib/cpPlugins/Plugins/IO/ImageWriter.h | 9 + lib/third_party/Pluma/DLibrary.cpp | 33 +- lib/third_party/Pluma/Dir.cpp | 8 +- lib/third_party/Pluma/Host.cpp | 16 +- lib/third_party/Pluma/PluginManager.cpp | 25 +- 44 files changed, 1396 insertions(+), 1322 deletions(-) create mode 100644 appli/ImageMPR/Plugins.cfg.in delete mode 100644 lib/cpPlugins/Interface/BaseMPRWindow.ui diff --git a/CMakeLists.txt b/CMakeLists.txt index 76b21ce..fd4ebea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,19 +47,20 @@ ENDIF(BUILD_SHARED_LIBRARIES) ## = Packages and options = ## ======================== -# it seems that by default on Visual Studio Compiler supports c++11, so it only need to be test on other O.S. - if(NOT MSVC) - INCLUDE(CheckCXXCompilerFlag) - CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) - CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X) - IF(COMPILER_SUPPORTS_CXX11) - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") - ELSEIF(COMPILER_SUPPORTS_CXX0X) - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") - ELSE() - MESSAGE(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") - ENDIF() -endif(NOT MSVC) +# NOTE: It seems that by default on Visual Studio Compiler supports c++11, +# so it only need to be test on other O.S. +IF(NOT MSVC) + INCLUDE(CheckCXXCompilerFlag) + CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) + CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X) + IF(COMPILER_SUPPORTS_CXX11) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + ELSEIF(COMPILER_SUPPORTS_CXX0X) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") + ELSE() + MESSAGE(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") + ENDIF() +ENDIF(NOT MSVC) # Prepare header to build shared libs (windows) INCLUDE(GenerateExportHeader) diff --git a/COMPILATION b/COMPILATION index b92c2ce..de796b5 100644 --- a/COMPILATION +++ b/COMPILATION @@ -5,49 +5,128 @@ @prerequisites + 0. A decent compiler for your system: + Linux: g++ with c++11 support + Mac: Xcode + Windows: any Visual Studio >= 2010 + 1. CMake (>=2.8.12.2) + Just use your favorite repository or get the installer from http://www.cmake.org. - 2. Visualization Toolkit -VTK- (>=6.1.0) - 2.1 Steps - Open CMake - Select the soruce and the binary folder - Select the desired version of generator to compile (Visual Studio 12 2013) and click on configure and wait until the options are enabled, and the make sure - 2.2 Required cmake flags: - BUILD_EXAMPLES OFF - BUILD_SHARED_LIBS ON - BUILD_TESTING OFF - Module_VtkGUISupportQt ON - Module_VtkGUISupportQtOpenGL ON - Module_VtkGUISupportQtSql OFF - Module_VtkGUISupportQtWebkit OFF + 2. [Optional] Qt (=4.8) + On linux just install the corresponding package. On Mac and Windows, download + the source code and compile it with your favorite compiler. Please be aware that: + - Both release and debug configs are needed. + - Compile Qt with only SHARED support. + - Compile Qt without Webkit support. + 3. Visualization Toolkit -VTK- (>=6.1.0) + 1. Download VTK source code from http://www.vtk.org, copy the downloaded + zip/tar.gz file to your work directory (say ~/sources), uncompress the + source file and create an empty folder (say ~/sources/vtk-build) + 2. Execute cmake taking care to put two directories: the source dir (where + the VTK source code is after decompression) and the build dir (the new + empty folder you just created). + 3. On linux/mac, it is easier to execute from a command line console: + $ cd ~/sources/vtk-build + *** WARNING: IF YOU INSTALLED QT *** + $ cmake -DCMAKE_CXX_FLAGS:STRING=-std=c++11 \ + -DBUILD_DOCUMENTATION:BOOL=OFF \ + -DBUILD_EXAMPLES:BOOL=OFF \ + -DBUILD_SHARED_LIBS:BOOL=ON \ + -DBUILD_TESTING:BOOL=OFF \ + -DCMAKE_BUILD_TYPE:STRING=MinSizeRel \ + -DModule_vtkGUISupportQt:BOOL=ON \ + -DModule_vtkGUISupportQtOpenGL:BOOL=ON \ + -DModule_vtkGUISupportQtSQL:BOOL=OFF \ + -DModule_vtkGUISupportQtWebkit:BOOL=OFF \ + -DCMAKE_INSTALL_PREFIX:PATH=~/local \ + ~/source/the_folder_where_vtk_was_decompressed + *** WARNING: IF YOU DIDN'T INSTALLED QT *** + $ cmake -DCMAKE_CXX_FLAGS:STRING=-std=c++11 \ + -DBUILD_DOCUMENTATION:BOOL=OFF \ + -DBUILD_EXAMPLES:BOOL=OFF \ + -DBUILD_SHARED_LIBS:BOOL=ON \ + -DBUILD_TESTING:BOOL=OFF \ + -DCMAKE_BUILD_TYPE:STRING=MinSizeRel \ + -DModule_vtkGUISupportQt:BOOL=OFF \ + -DModule_vtkGUISupportQtOpenGL:BOOL=OFF \ + -DModule_vtkGUISupportQtSQL:BOOL=OFF \ + -DModule_vtkGUISupportQtWebkit:BOOL=OFF \ + -DCMAKE_INSTALL_PREFIX:PATH=~/local \ + ~/source/the_folder_where_vtk_was_decompressed + $ make + ... WAIT A FEW MINUTES ... + $ make install + 4. On windows, make sure that the following cmake variables are configured as: + BUILD_DOCUMENTATION:BOOL=OFF + BUILD_EXAMPLES:BOOL=OFF + BUILD_SHARED_LIBS:BOOL=ON + BUILD_TESTING:BOOL=OFF + CMAKE_BUILD_TYPE:STRING=MinSizeRel + Module_vtkGUISupportQt:BOOL=[OFF/ON] ** "ON", IF YOU INSTALLED Qt + Module_vtkGUISupportQtOpenGL:BOOL=[OFF/ON] ** "ON", IF YOU INSTALLED Qt + Module_vtkGUISupportQtSQL:BOOL=OFF \ + Module_vtkGUISupportQtWebkit:BOOL=OFF \ + NOTE: Normally, windows compilers already support c++11. 3. Insight Toolkit -ITK- (>=4.6.0) - 3.1 Required cmake flags: - BUILD_SHARED_LIBS:BOOL=ON - Module_ITKVtkGlue:BOOL=ON + 1. Download ITK source code from http://www.itk.org, copy the downloaded + zip/tar.gz file to your work directory (say ~/sources), uncompress the + source file and create an empty folder (say ~/sources/itk-build) + 2. Execute cmake taking care to put two directories: the source dir (where + the ITK source code is after decompression) and the build dir (the new + empty folder you just created). + 3. On linux/mac, it is easier to execute from a command line console: + $ cd ~/sources/itk-build + $ cmake -DCMAKE_CXX_FLAGS:STRING=-std=c++11 \ + -DBUILD_DOCUMENTATION:BOOL=OFF \ + -DBUILD_EXAMPLES:BOOL=OFF \ + -DBUILD_SHARED_LIBS:BOOL=ON \ + -DBUILD_TESTING:BOOL=OFF \ + -DCMAKE_BUILD_TYPE:STRING=MinSizeRel \ + -DModule_ITKReview:BOOL=ON \ + -DModule_ITKVtkGlue:BOOL=OFF \ + -DCMAKE_INSTALL_PREFIX:PATH=~/local \ + ~/source/the_folder_where_itk_was_decompressed + $ make + ... WAIT A FEW MINUTES ... + $ make install + 4. On windows, make sure that the following cmake variables are configured as: + BUILD_DOCUMENTATION:BOOL=OFF + BUILD_EXAMPLES:BOOL=OFF + BUILD_SHARED_LIBS:BOOL=ON + BUILD_TESTING:BOOL=OFF + CMAKE_BUILD_TYPE:STRING=MinSizeRel + Module_ITKReview:BOOL=ON + Module_ITKVtkGlue:BOOL=OFF + NOTE: Normally, windows compilers already support c++11. 4. WARNING: Notes on compilation on MS-Windows - As the time being (circa dec 2014), I've been using MSVC-2013 - (compiler version 12). As expected, weird behavior is related to - this config. Please take into account the following in order to - have a successful compilation: + As the time being (circa dec 2014), I've been using MSVC-2013 (compiler + version 12). As expected, weird behavior is related to this config. Please + take into account the following in order to have a successful compilation: 4.1 If you want to build the Qt-based code, please be sure that it was compiled with EXACTLY the same compiler you are using. 4.2 Since the dll load-unload procedure in MSWin is kind of magic, - VTK should be compiled as shared libraries and ITK should be - compiled as static libraries. This allows a correct - execution of the SmartPointer's thus preventing anoying crashes. + VTK and ITK should be compiled as shared libraries. This allows a + correct execution of the SmartPointer's thus preventing anoying crashes. 4.3 If you found more problems in any MSWin config, please let us know at florez-l@javeriana.edu.co - - -@cmake_flags - BUILD_DEMOS:BOOL - Build example applications? (most of them are command line) - CMAKE_BUILD_TYPE:STRING - Debug/Release? - CMAKE_INSTALL_PREFIX:STRING - Where to put installation products? (in windows this option has no use) + +@compilation + The project uses CMake as project manager. You can use the CMake GUI to configure + it on your box. Please take into account the following variables: + USE_QT4:BOOL -> It allows you to compile the Qt support + BUILD_EXAMPLES:BOOL -> Do you want to compile the examples? + BUILD_SHARED_LIBRARIES -> Put this allways "ON". "OFF" is still experimental + CMAKE_BUILD_TYPE -> Compilation type. Possible values: Debug, Release, + MinSizeRel, RelWithDebInfo, None + ITK_DIR -> Where ITK was intalled. If you followed this list, + it should be on: ~/local/lib/cmake/ITK-X.Y (X and Y are + the version numbers) + VTK_DIR -> Where VTK was intalled. If you followed this list, + it should be on: ~/local/lib/cmake/vtk-X.Y (X and Y are + the version numbers) ## eof - $RCSfile$ diff --git a/README b/README index 667adda..46efa01 100644 --- a/README +++ b/README @@ -7,8 +7,9 @@ 0.0.1 (2014-12-31) @authors + Leonardo FLÓREZ-VALENCIA (florez-l@javeriana.edu.co) Maciej ORKISZ (maciej.orkisz@creatis.insa-lyon.fr) - Leonardo FLOREZ-VALENCIA (florez-l@javeriana.edu.co) + José Luis GUZMÁN-RODRÍGUEZ (cycopepe@gmail.com) @description diff --git a/appli/ImageMPR/CMakeLists.txt b/appli/ImageMPR/CMakeLists.txt index 95a7757..2359c70 100644 --- a/appli/ImageMPR/CMakeLists.txt +++ b/appli/ImageMPR/CMakeLists.txt @@ -1,5 +1,11 @@ IF(USE_QT4) + CONFIGURE_FILE( + Plugins.cfg.in + ${PROJECT_BINARY_DIR}/Plugins.cfg + @ONLY + ) + ## ==================================================== ## = Source code, user interafaces and resources here = ## ==================================================== diff --git a/appli/ImageMPR/ImageMPR.cxx b/appli/ImageMPR/ImageMPR.cxx index 402baff..ada90ea 100644 --- a/appli/ImageMPR/ImageMPR.cxx +++ b/appli/ImageMPR/ImageMPR.cxx @@ -1,7 +1,173 @@ #include "ImageMPR.h" -#include "MementoState.h" #include "ui_ImageMPR.h" +// ------------------------------------------------------------------------- +#define ImageMPR_ConnectAction( ACTION ) \ + QObject::connect( \ + this->m_UI->a##ACTION, SIGNAL( triggered( ) ), \ + this, SLOT( _a##ACTION( ) ) \ + ) + +// ------------------------------------------------------------------------- +ImageMPR:: +ImageMPR( QWidget* parent ) + : QMainWindow( parent ), + m_UI( new Ui::ImageMPR ), + m_ImageLoaded( false ) +{ + this->m_UI->setupUi( this ); + + // Connect actions + ImageMPR_ConnectAction( OpenImage ); + ImageMPR_ConnectAction( OpenSegmentation ); + ImageMPR_ConnectAction( OpenPolyData ); + ImageMPR_ConnectAction( SaveImage ); + ImageMPR_ConnectAction( SaveSegmentation ); + ImageMPR_ConnectAction( SavePolyData ); + ImageMPR_ConnectAction( Undo ); + ImageMPR_ConnectAction( Redo ); + ImageMPR_ConnectAction( LoadPlugins ); + ImageMPR_ConnectAction( ShowPlugins ); + + // Try to load default plugins + this->m_UI->MPR->LoadPlugins( ); + this->m_UI->MPR->AssociatePluginsToMenu( + this->m_UI->MenuFilters, this, SLOT( _execPlugin( ) ) + ); +} + +// ------------------------------------------------------------------------- +ImageMPR:: +~ImageMPR( ) +{ + delete this->m_UI; +} + +// ------------------------------------------------------------------------- +void ImageMPR:: +_aOpenImage( ) +{ + if( this->m_ImageLoaded ) + this->m_UI->MPR->ClearAll( ); + this->m_ImageLoaded = this->m_UI->MPR->LoadImage( ); +} + +// ------------------------------------------------------------------------- +void ImageMPR:: +_aOpenSegmentation( ) +{ + if( this->m_ImageLoaded ) + this->m_ImageLoaded = this->m_UI->MPR->LoadImage( ); +} + +// ------------------------------------------------------------------------- +void ImageMPR:: +_aOpenPolyData( ) +{ +} + +// ------------------------------------------------------------------------- +void ImageMPR:: +_aSaveImage( ) +{ +} + +// ------------------------------------------------------------------------- +void ImageMPR:: +_aSaveSegmentation( ) +{ +} + +// ------------------------------------------------------------------------- +void ImageMPR:: +_aSavePolyData( ) +{ +} + +// ------------------------------------------------------------------------- +void ImageMPR:: +_aUndo( ) +{ +} + +// ------------------------------------------------------------------------- +void ImageMPR:: +_aRedo( ) +{ +} + +// ------------------------------------------------------------------------- +void ImageMPR:: +_aLoadPlugins( ) +{ + this->m_UI->MPR->DialogLoadPlugins( ); + this->m_UI->MPR->AssociatePluginsToMenu( + this->m_UI->MenuFilters, this, SLOT( _execPlugin( ) ) + ); +} + +// ------------------------------------------------------------------------- +void ImageMPR:: +_aShowPlugins( ) +{ +} + +// ------------------------------------------------------------------------- +void ImageMPR:: +_execPlugin( ) +{ + // Get filter name + QAction* action = dynamic_cast< QAction* >( this->sender( ) ); + if( action == NULL ) + return; + std::string name = action->text( ).toStdString( ); + this->m_UI->MPR->ExecuteFilter( name, 0 ); + + // Configure filter + /* + TPluginFilter::Pointer filter = + this->m_Plugins.CreateProcessObject( name ); + bool dlg_ok = filter->ExecConfigurationDialog( NULL ); + if( !dlg_ok ) + return; + + // Execute filter + QApplication::setOverrideCursor( Qt::WaitCursor ); + this->setEnabled( false ); + filter->SetInput( 0, this->m_Image ); + std::string err = filter->Update( ); + QApplication::restoreOverrideCursor( ); + this->setEnabled( true ); + + // Update image + if( err == "" ) + { + TPluginImage* result = filter->GetOutput< TPluginImage >( 0 ); + result->DisconnectPipeline( ); + this->m_Image = result; + if( this->m_Image.IsNotNull( ) ) + this->m_MPRObjects->SetImage( + this->m_Image->GetVTK< vtkImageData >( ) + ); + MementoState(this->m_state, this->m_Image); + this->m_state++; + if (this->m_state > this->m_max_state) + { + this->m_max_state = this->m_state; + } + } + else + QMessageBox::critical( + this, + tr( "Error executing filter" ), + tr( err.c_str( ) ) + ); + */ +} + +/* +#include "MementoState.h" + #include #include #include @@ -546,5 +712,6 @@ _triggered_actionRedo() } +*/ // eof - $RCSfile$ diff --git a/appli/ImageMPR/ImageMPR.h b/appli/ImageMPR/ImageMPR.h index c864bfe..1cc16c9 100644 --- a/appli/ImageMPR/ImageMPR.h +++ b/appli/ImageMPR/ImageMPR.h @@ -120,63 +120,76 @@ class ImageMPR public: // Plugins types - typedef cpPlugins::Interface::Interface TPluginsInterface; - typedef cpPlugins::Interface::Object TPluginObject; - typedef cpPlugins::Interface::DataObject TPluginData; - typedef cpPlugins::Interface::Image TPluginImage; - typedef cpPlugins::Interface::ImplicitFunction TPluginImplicitFunction; - typedef cpPlugins::Interface::Mesh TPluginMesh; - typedef cpPlugins::Interface::ProcessObject TPluginFilter; - typedef cpPlugins::Interface::Parameters TParameters; - - typedef cpExtensions::Visualization::MPRObjects TMPRObjects; + /* + typedef cpPlugins::Interface::Interface TPluginsInterface; + typedef cpPlugins::Interface::Object TPluginObject; + typedef cpPlugins::Interface::DataObject TPluginData; + typedef cpPlugins::Interface::Image TPluginImage; + typedef cpPlugins::Interface::ImplicitFunction TPluginImplicitFunction; + typedef cpPlugins::Interface::Mesh TPluginMesh; + typedef cpPlugins::Interface::ProcessObject TPluginFilter; + typedef cpPlugins::Interface::Parameters TParameters; + typedef cpExtensions::Visualization::MPRObjects TMPRObjects; + */ public: explicit ImageMPR( QWidget* parent = 0 ); virtual ~ImageMPR( ); -protected: - bool _LoadPlugins( const std::string& filename ); - std::string _LoadImage( TPluginImage::Pointer& image ); - std::string _ConfigureMeshActors( ); + /* + protected: + bool _LoadPlugins( const std::string& filename ); + std::string _LoadImage( TPluginImage::Pointer& image ); + std::string _ConfigureMeshActors( ); + */ private slots: - void _triggered_actionOpenPlugins( ); - void _triggered_actionOpenInputImage( ); - void _triggered_actionOpenSegmentation( ); - void _triggered_actionOpenInputPolyData( ); - void _triggered_actionImageToImage( ); - void _triggered_actionImageToMesh( ); - void _triggered_actionUndo(); - void _triggered_actionRedo(); + void _aOpenImage( ); + void _aOpenSegmentation( ); + void _aOpenPolyData( ); + void _aSaveImage( ); + void _aSaveSegmentation( ); + void _aSavePolyData( ); + void _aUndo( ); + void _aRedo( ); + void _aLoadPlugins( ); + void _aShowPlugins( ); + + void _execPlugin( ); + private: Ui::ImageMPR* m_UI; + // Some state flags + bool m_ImageLoaded; + // Plugins objects - TPluginsInterface m_Plugins; - - // Needed object from plugins - std::string m_ImageReaderClass; - std::string m_ImageWriterClass; - std::string m_MeshReaderClass; - std::string m_MeshWriterClass; - std::string m_MeshCutterClass; - - // Real data - TPluginImage::Pointer m_Image; - TPluginImage::Pointer m_Segmentation; - TPluginMesh::Pointer m_Mesh; - - // Cutters - TPluginFilter::Pointer m_Cutters[ 3 ]; - TPluginImplicitFunction::Pointer m_Planes[ 3 ]; - - // Visualization stuff - vtkSmartPointer< TMPRObjects > m_MPRObjects; - - // Memento stuff - unsigned long m_state; - unsigned long m_max_state; + /* + TPluginsInterface m_Plugins; + + // Needed object from plugins + std::string m_ImageReaderClass; + std::string m_ImageWriterClass; + std::string m_MeshReaderClass; + std::string m_MeshWriterClass; + std::string m_MeshCutterClass; + + // Real data + TPluginImage::Pointer m_Image; + TPluginImage::Pointer m_Segmentation; + TPluginMesh::Pointer m_Mesh; + + // Cutters + TPluginFilter::Pointer m_Cutters[ 3 ]; + TPluginImplicitFunction::Pointer m_Planes[ 3 ]; + + // Visualization stuff + vtkSmartPointer< TMPRObjects > m_MPRObjects; + + // Memento stuff + unsigned long m_state; + unsigned long m_max_state; + */ /* TODO vtkSmartPointer< vtkOrientationMarkerWidget > m_3DOrientationWidget; diff --git a/appli/ImageMPR/ImageMPR.ui b/appli/ImageMPR/ImageMPR.ui index 8fd0d12..7a292a2 100644 --- a/appli/ImageMPR/ImageMPR.ui +++ b/appli/ImageMPR/ImageMPR.ui @@ -17,128 +17,71 @@ - Interactive deformable mesh segmentation (v0.1) + ImageMPR (v0.1) - + - - - - 700 - 400 - - - - Qt::Horizontal - - - - Qt::Vertical - - - - Qt::Horizontal - - - - true - - - - 200 - 200 - - - - - - true - - - - 200 - 200 - - - - - - - Qt::Horizontal - - - - true - - - - 200 - 200 - - - - - - true - - - - 200 - 200 - - - - - - + - + 0 0 718 - 21 + 25 - + &File - + + + - - - + + + - + - + - Image to image + &Edit + + + &Plugins + + + + + + + + - + - Image to mesh + &Help - + - Edit + &Filters - - - - - - + + + + - + + true @@ -149,69 +92,97 @@ Ctrl+O - - - true + + + Exit + + - Open plugins + Open polydata - Ctrl+P + Ctrl+M - + - Exit + Open segmentation + + + Ctrl+S - + - Open polydata + &Undo - Ctrl+M + Ctrl+Z - + - dasdasd + &Redo + + + Ctrl+Y - + - Open segmentation + Load plugins + + + Ctrl+P - + - Undo + Show plugins - Ctrl+Z + Ctrl+H - + - Redo + Save image - Ctrl+Y + Ctrl+Shift+I + + + + + Save segmentation + + + Ctrl+Shift+S + + + + + Save polydata + + + Ctrl+Shift+M - QVTKWidget - QWidget -
QVTKWidget.h
+ cpPlugins::Interface::BaseMPRWindow + QFrame +
cpPlugins/Interface/BaseMPRWindow.h
+ 1
- actionExit + aExit triggered() ImageMPR close() diff --git a/appli/ImageMPR/MementoState.cxx b/appli/ImageMPR/MementoState.cxx index 72bd435..cfc9b7c 100644 --- a/appli/ImageMPR/MementoState.cxx +++ b/appli/ImageMPR/MementoState.cxx @@ -68,6 +68,7 @@ MementoState::load(const std::string& filename) { reader->Update(); return reader; */ +return( NULL ); } // eof - $RCSfile$ diff --git a/appli/ImageMPR/Plugins.cfg.in b/appli/ImageMPR/Plugins.cfg.in new file mode 100644 index 0000000..09b8bed --- /dev/null +++ b/appli/ImageMPR/Plugins.cfg.in @@ -0,0 +1,2 @@ +@CMAKE_SHARED_LIBRARY_PREFIX@cpPluginsIO@CMAKE_SHARED_LIBRARY_SUFFIX@ +@CMAKE_SHARED_LIBRARY_PREFIX@cpPluginsBasicFilters@CMAKE_SHARED_LIBRARY_SUFFIX@ diff --git a/lib/cpExtensions/QT/QuadSplitter.cxx b/lib/cpExtensions/QT/QuadSplitter.cxx index 89fc717..6713180 100644 --- a/lib/cpExtensions/QT/QuadSplitter.cxx +++ b/lib/cpExtensions/QT/QuadSplitter.cxx @@ -11,19 +11,19 @@ // ------------------------------------------------------------------------- cpExtensions::QT::QuadSplitter:: -QuadSplitter( QWidget* parent, Qt::WindowFlags f ) - : QFrame( parent, f ) +QuadSplitter( QWidget* parent ) + : QSplitter( parent ) { - this->m_Parent.setOrientation(Qt::Vertical); - this->m_Parent.addWidget(&this->m_Upper); - this->m_Parent.addWidget(&this->m_Bottom); + this->setOrientation( Qt::Vertical ); + this->addWidget( &this->m_Upper ); + this->addWidget( &this->m_Bottom ); QObject::connect( - &this->m_Upper, SIGNAL( splitterMoved( int, int ) ), + &( this->m_Upper ), SIGNAL( splitterMoved( int, int ) ), this, SLOT( _SyncBottom( int, int ) ) ); QObject::connect( - &this->m_Bottom, SIGNAL( splitterMoved( int, int ) ), + &( this->m_Bottom ), SIGNAL( splitterMoved( int, int ) ), this, SLOT( _SyncUpper( int, int ) ) ); } @@ -34,13 +34,6 @@ cpExtensions::QT::QuadSplitter:: { } -// ------------------------------------------------------------------------- -void cpExtensions::QT::QuadSplitter:: -show( ) -{ - this->m_Parent.show( ); -} - // ------------------------------------------------------------------------- void cpExtensions::QT::QuadSplitter:: addWidgets( QWidget* a, QWidget* b, QWidget* c, QWidget* d ) @@ -55,14 +48,14 @@ addWidgets( QWidget* a, QWidget* b, QWidget* c, QWidget* d ) void cpExtensions::QT::QuadSplitter:: _SyncBottom( int a, int b ) { - this->m_Bottom.setSizes( m_Upper.sizes( ) ); + this->m_Bottom.setSizes( this->m_Upper.sizes( ) ); } // ------------------------------------------------------------------------- void cpExtensions::QT::QuadSplitter:: _SyncUpper( int a, int b ) { - this->m_Upper.setSizes( m_Bottom.sizes( ) ); + this->m_Upper.setSizes( this->m_Bottom.sizes( ) ); } #endif // cpExtensions_Interface_QT4 diff --git a/lib/cpExtensions/QT/QuadSplitter.h b/lib/cpExtensions/QT/QuadSplitter.h index c431dfa..7c27509 100644 --- a/lib/cpExtensions/QT/QuadSplitter.h +++ b/lib/cpExtensions/QT/QuadSplitter.h @@ -1,6 +1,7 @@ #ifndef __CPEXTENSIONS__QT__QUADSPLITTER__H__ #define __CPEXTENSIONS__QT__QUADSPLITTER__H__ +#include #include #ifdef cpExtensions_Interface_QT4 @@ -10,7 +11,6 @@ * https://forum.qt.io/topic/7144/quad-splitter-windows-an-implementation/2 */ -#include #include namespace cpExtensions @@ -19,25 +19,22 @@ namespace cpExtensions { /** */ - class QuadSplitter - : public QFrame + class cpExtensions_EXPORT QuadSplitter + : public QSplitter { Q_OBJECT; public: - QuadSplitter( QWidget* parent = 0, Qt::WindowFlags f = 0 ); + QuadSplitter( QWidget* parent = 0 ); virtual ~QuadSplitter( ); - void show( ); void addWidgets( QWidget* a, QWidget* b, QWidget* c, QWidget* d ); - private slots: void _SyncBottom( int a, int b ); void _SyncUpper( int a, int b ); protected: - QSplitter m_Parent; QSplitter m_Bottom; QSplitter m_Upper; }; diff --git a/lib/cpExtensions/Visualization/ImageSliceActors.cxx b/lib/cpExtensions/Visualization/ImageSliceActors.cxx index 558fed7..250c2ed 100644 --- a/lib/cpExtensions/Visualization/ImageSliceActors.cxx +++ b/lib/cpExtensions/Visualization/ImageSliceActors.cxx @@ -29,7 +29,7 @@ New( ) // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -AddInputConnection( vtkAlgorithmOutput* aout, int axis, LUTType lut ) +AddInputConnection( vtkAlgorithmOutput* aout, int axis ) { vtkImageData* data = dynamic_cast< vtkImageData* >( aout->GetProducer( )->GetOutputDataObject( aout->GetIndex( ) ) @@ -42,7 +42,7 @@ AddInputConnection( vtkAlgorithmOutput* aout, int axis, LUTType lut ) if( new_map == NULL ) { // Configure LUT - this->_ConfigureNewLUT( data, lut ); + this->_ConfigureNewLUT( data ); new_map = *( this->ImageMaps.rbegin( ) ); if( new_map != NULL ) { @@ -67,10 +67,10 @@ AddInputConnection( vtkAlgorithmOutput* aout, int axis, LUTType lut ) // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -AddInputData( vtkImageData* data, int axis, LUTType lut ) +AddInputData( vtkImageData* data, int axis ) { // Configure LUT - this->_ConfigureNewLUT( data, lut ); + this->_ConfigureNewLUT( data ); vtkImageMapToColors* new_map = *( this->ImageMaps.rbegin( ) ); if( new_map != NULL ) { @@ -109,7 +109,7 @@ Clear( ) this->CursorMapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); this->CursorActor = vtkSmartPointer< vtkActor >::New( ); this->PlaneFunction = vtkSmartPointer< vtkPlane >::New( ); - this->PlaneSource = vtkSmartPointer< vtkPolyData >::New( ); + this->Plane = vtkSmartPointer< vtkPolyData >::New( ); this->PlaneMapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); this->TextActor = vtkSmartPointer< vtkTextActor >::New( ); this->PlaneActor = vtkSmartPointer< vtkActor >::New( ); @@ -160,10 +160,10 @@ Clear( ) plane_lines->InsertCellPoint( 2 ); plane_lines->InsertCellPoint( 3 ); plane_lines->InsertCellPoint( 0 ); - this->PlaneSource->SetPoints( plane_points ); - this->PlaneSource->SetLines( plane_lines ); + this->Plane->SetPoints( plane_points ); + this->Plane->SetLines( plane_lines ); - this->PlaneMapper->SetInputData( this->PlaneSource ); + this->PlaneMapper->SetInputData( this->Plane ); this->PlaneActor->SetMapper( this->PlaneMapper ); this->TextActor->SetTextScaleModeToNone( ); @@ -517,16 +517,21 @@ GetImageMap( unsigned int id ) const // ------------------------------------------------------------------------- double cpExtensions::Visualization::ImageSliceActors:: -GetWindow( unsigned int id ) const +GetWindow( ) const { - if( this->ImageMaps[ id ].GetPointer( ) != NULL ) + if( this->ImageMaps.size( ) > 0 ) { - vtkWindowLevelLookupTable* lut = - dynamic_cast< vtkWindowLevelLookupTable* >( - this->ImageMaps[ id ]->GetLookupTable( ) - ); - if( lut != NULL ) - return( lut->GetWindow( ) ); + if( this->ImageMaps[ 0 ].GetPointer( ) != NULL ) + { + vtkWindowLevelLookupTable* lut = + dynamic_cast< vtkWindowLevelLookupTable* >( + this->ImageMaps[ 0 ]->GetLookupTable( ) + ); + if( lut != NULL ) + return( lut->GetWindow( ) ); + else + return( double( 0 ) ); + } else return( double( 0 ) ); } @@ -536,16 +541,21 @@ GetWindow( unsigned int id ) const // ------------------------------------------------------------------------- double cpExtensions::Visualization::ImageSliceActors:: -GetLevel( unsigned int id ) const +GetLevel( ) const { - if( this->ImageMaps[ id ].GetPointer( ) != NULL ) + if( this->ImageMaps.size( ) > 0 ) { - vtkWindowLevelLookupTable* lut = - dynamic_cast< vtkWindowLevelLookupTable* >( - this->ImageMaps[ id ]->GetLookupTable( ) - ); - if( lut != NULL ) - return( lut->GetLevel( ) ); + if( this->ImageMaps[ 0 ].GetPointer( ) != NULL ) + { + vtkWindowLevelLookupTable* lut = + dynamic_cast< vtkWindowLevelLookupTable* >( + this->ImageMaps[ 0 ]->GetLookupTable( ) + ); + if( lut != NULL ) + return( lut->GetLevel( ) ); + else + return( double( 0 ) ); + } else return( double( 0 ) ); } @@ -555,20 +565,30 @@ GetLevel( unsigned int id ) const // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -SetWindow( unsigned int id, double w ) +SetWindow( double w ) { - if( this->ImageMaps[ id ].GetPointer( ) != NULL ) + if( this->ImageMaps.size( ) > 0 ) { - vtkWindowLevelLookupTable* lut = - dynamic_cast< vtkWindowLevelLookupTable* >( - this->ImageMaps[ id ]->GetLookupTable( ) - ); - if( lut != NULL ) + if( this->ImageMaps[ 0 ].GetPointer( ) != NULL ) { - lut->SetWindow( w ); - lut->Build( ); - this->ImageMaps[ id ]->Modified( ); - this->Modified( ); + vtkWindowLevelLookupTable* lut = + dynamic_cast< vtkWindowLevelLookupTable* >( + this->ImageMaps[ 0 ]->GetLookupTable( ) + ); + if( lut != NULL ) + { + /* TODO: Min and Max values are assigned 0!!! + if( w < this->MinWindow ) + w = this->MinWindow; + if( w > this->MaxWindow ) + w = this->MaxWindow; + */ + lut->SetWindow( w ); + lut->Build( ); + this->ImageMaps[ 0 ]->Modified( ); + this->Modified( ); + + } // fi } // fi @@ -577,20 +597,30 @@ SetWindow( unsigned int id, double w ) // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -SetLevel( unsigned int id, double l ) +SetLevel( double l ) { - if( this->ImageMaps[ id ].GetPointer( ) != NULL ) + if( this->ImageMaps.size( ) > 0 ) { - vtkWindowLevelLookupTable* lut = - dynamic_cast< vtkWindowLevelLookupTable* >( - this->ImageMaps[ id ]->GetLookupTable( ) - ); - if( lut != NULL ) + if( this->ImageMaps[ 0 ].GetPointer( ) != NULL ) { - lut->SetLevel( l ); - lut->Build( ); - this->ImageMaps[ id ]->Modified( ); - this->Modified( ); + vtkWindowLevelLookupTable* lut = + dynamic_cast< vtkWindowLevelLookupTable* >( + this->ImageMaps[ 0 ]->GetLookupTable( ) + ); + if( lut != NULL ) + { + /* TODO: Min and Max values are assigned 0!!! + if( l < this->MinLevel ) + l = this->MinLevel; + if( l > this->MaxLevel ) + l = this->MaxLevel; + */ + lut->SetLevel( l ); + lut->Build( ); + this->ImageMaps[ 0 ]->Modified( ); + this->Modified( ); + + } // fi } // fi @@ -599,21 +629,65 @@ SetLevel( unsigned int id, double l ) // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -SetWindowLevel( unsigned int id, double w, double l ) +SetWindowLevel( double w, double l ) { - if( this->ImageMaps[ id ].GetPointer( ) != NULL ) + if( this->ImageMaps.size( ) > 0 ) { - vtkWindowLevelLookupTable* lut = - dynamic_cast< vtkWindowLevelLookupTable* >( - this->ImageMaps[ id ]->GetLookupTable( ) - ); - if( lut != NULL ) + if( this->ImageMaps[ 0 ].GetPointer( ) != NULL ) + { + vtkWindowLevelLookupTable* lut = + dynamic_cast< vtkWindowLevelLookupTable* >( + this->ImageMaps[ 0 ]->GetLookupTable( ) + ); + if( lut != NULL ) + { + /* TODO: Min and Max values are assigned 0!!! + std::cout << this->MinWindow << " " << this->MaxWindow << std::endl; + std::cout << this->MinLevel << " " << this->MaxLevel << std::endl; + std::cout << w << " " << l << " <-> " << std::ends; + if( w < this->MinWindow ) + w = this->MinWindow; + if( w > this->MaxWindow ) + w = this->MaxWindow; + if( l < this->MinLevel ) + l = this->MinLevel; + if( l > this->MaxLevel ) + l = this->MaxLevel; + std::cout << w << " " << l << std::endl; + */ + lut->SetWindow( w ); + lut->SetLevel( l ); + lut->Build( ); + this->ImageMaps[ 0 ]->Modified( ); + this->Modified( ); + + } // fi + + } // fi + + } // fi +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +ResetWindowLevel( ) +{ + this->SetWindowLevel( + this->MaxWindow, + ( this->MaxLevel + this->MinLevel ) / double( 2 ) + ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +SetLookupTable( unsigned int id, vtkLookupTable* lut ) +{ + if( id < this->ImageMaps.size( ) && id > 0 ) + { + if( this->ImageMaps[ id ].GetPointer( ) != NULL ) { - lut->SetWindow( w ); - lut->SetLevel( l ); - lut->Build( ); + this->ImageMaps[ id ]->SetLookupTable( lut ); this->ImageMaps[ id ]->Modified( ); - this->UpdateText( w, l ); this->Modified( ); } // fi @@ -623,8 +697,58 @@ SetWindowLevel( unsigned int id, double w, double l ) // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -ResetWindowLevel( unsigned int id ) +SetLookupTableAsColor( unsigned int id, double r, double g, double b ) { + static const double _0 = double( 0 ); + static const double _2 = double( 2 ); + static const double _4 = double( 4 ); + static const double _6 = double( 6 ); + static const double _OPACITY = double( 0.6 ); + + // Check ID consistency + if( id == 0 || id >= this->ImageMaps.size( ) ) + return; + + // Get image scalar range + vtkAlgorithmOutput* aout = this->ImageMaps[ id ]->GetOutputPort( ); + vtkImageData* image = dynamic_cast< vtkImageData* >( + aout->GetProducer( )->GetOutputDataObject( aout->GetIndex( ) ) + ); + double range[ 2 ]; + image->GetScalarRange( range ); + + // Get HSV from display color + double cmax = ( r > g )? r: g; cmax = ( b > cmax )? b: cmax; + double cmin = ( r < g )? r: g; cmin = ( b < cmin )? b: cmin; + double d = cmax - cmin; + + double saturation = ( std::fabs( cmax ) > _0 )? d / cmax: _0; + double value = cmax; + double hue = _0; + if( d > _0 ) + { + if( r == cmax ) + hue = std::fmod( ( g - b ) / d, _6 ); + else if( g == cmax ) + hue = ( ( b - r ) / d ) + _2; + else if( b == cmax ) + hue = ( ( r - g ) / d ) + _4; + hue /= _6; + + } // fi + + // Define new lookup table + vtkSmartPointer< vtkLookupTable > lut = + vtkSmartPointer< vtkLookupTable >::New( ); + lut->SetScaleToLinear( ); + lut->SetNanColor( _0, _0, _0, _0 ); + lut->SetTableRange( range[ 0 ], range[ 1 ] ); + lut->SetAlphaRange( _0, _OPACITY ); + lut->SetHueRange( _0, hue ); + lut->SetSaturationRange( _0, saturation ); + lut->SetValueRange( _0, value ); + lut->Build( ); + this->SetLookupTable( id, lut ); } // ------------------------------------------------------------------------- @@ -741,7 +865,7 @@ SetSliceNumber( const int& slice ) int axis = this->SliceMappers[ 0 ]->GetOrientation( ); this->PlaneActor->GetProperty( )->SetRepresentationToWireframe( ); this->PlaneActor->GetProperty( )->SetLineWidth( 2 ); - vtkPoints* plane_points = this->PlaneSource->GetPoints( ); + vtkPoints* plane_points = this->Plane->GetPoints( ); if( axis == 0 ) // YZ, x-normal { this->PlaneFunction->SetNormal( 1, 0, 0 ); @@ -771,7 +895,7 @@ SetSliceNumber( const int& slice ) } // fi this->PlaneFunction->Modified( ); - this->PlaneSource->Modified( ); + this->Plane->Modified( ); this->PlaneMapper->Modified( ); this->PlaneActor->Modified( ); @@ -825,14 +949,6 @@ SetSlice( double* pos ) this->SetSliceNumber( ijk[ this->GetAxis( ) ] ); } -// ------------------------------------------------------------------------- -/* TODO - void cpExtensions::Visualization::ImageSliceActors:: - SetSlices( double pos[ 3 ] ) - { - } -*/ - // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: UpdateText( ) @@ -906,7 +1022,7 @@ UpdateText( double pos[ 3 ] ) ); str << ")"; std::sprintf( - this->TextBuffer, "Axis: %c (%d) | Pixel %s", + this->TextBuffer, "Axis: %c (%d)\nPixel %s", axis, slice, str.str( ).c_str( ) ); @@ -932,7 +1048,7 @@ UpdateText( const double& w, const double& l ) else if( axId == 2 ) axis = 'Z'; std::sprintf( - this->TextBuffer, "Axis: %c (%d) | W/L (%.2f/%.2f)", + this->TextBuffer, "Axis: %c (%d)\nW/L (%.2f/%.2f)", axis, this->SliceMappers[ 0 ]->GetSliceNumber( ), w, l ); } @@ -971,76 +1087,41 @@ cpExtensions::Visualization::ImageSliceActors:: // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -_ConfigureNewLUT( vtkImageData* data, LUTType lut_t ) +_ConfigureNewLUT( vtkImageData* data ) { - static const double _0 = double( 0 ); - static const double _1 = double( 1 ); - static const double _2 = double( 2 ); - static const double _4 = double( 4 ); - static const double _6 = double( 6 ); - static const double _OPACITY = double( 0.6 ); + // Does the new LUT is a window-level one? + unsigned int nImgs = this->ImageMaps.size( ); + unsigned int nCmps = data->GetNumberOfScalarComponents( ); - // Configure LUT - vtkSmartPointer< vtkImageMapToColors > new_map( NULL ); - if( data->GetNumberOfScalarComponents( ) == 1 ) + if( nCmps > 1 ) { - double range[ 2 ]; - data->GetScalarRange( range ); - if( lut_t == Self::LUTType_WindowLevel ) - { - vtkSmartPointer< vtkWindowLevelLookupTable > lut = - vtkSmartPointer< vtkWindowLevelLookupTable >::New( ); - lut->SetScaleToLinear( ); - lut->SetTableRange( range ); - lut->SetWindow( range[ 1 ] - range[ 0 ] ); - lut->SetLevel( ( range[ 1 ] + range[ 0 ] ) / double( 2 ) ); - lut->Build( ); - - new_map = vtkSmartPointer< vtkImageMapToColors >::New( ); - new_map->SetLookupTable( lut ); - } - else if( lut_t == LUTType_Colors ) - { - // Get HSV from display color - double r = 1, g = 0, b = 0; - double cmax = ( r > g )? r: g; cmax = ( b > cmax )? b: cmax; - double cmin = ( r < g )? r: g; cmin = ( b < cmin )? b: cmin; - double d = cmax - cmin; - - double saturation = ( std::fabs( cmax ) > _0 )? d / cmax: _0; - double value = cmax; - double hue = _0; - if( d > _0 ) - { - if( r == cmax ) - hue = std::fmod( ( g - b ) / d, _6 ); - else if( g == cmax ) - hue = ( ( b - r ) / d ) + _2; - else if( b == cmax ) - hue = ( ( r - g ) / d ) + _4; - hue *= _1 / _6; - - } // fi - - // Define new lookup table - vtkSmartPointer< vtkLookupTable > lut = - vtkSmartPointer< vtkLookupTable >::New( ); - lut->SetScaleToLinear( ); - lut->SetNanColor( _0, _0, _0, _0 ); - lut->SetTableRange( range[ 0 ], range[ 1 ] ); - lut->SetAlphaRange( _0, _OPACITY ); - lut->SetHueRange( _0, hue ); - lut->SetSaturationRange( _0, saturation ); - lut->SetValueRange( _0, value ); - lut->Build( ); - - new_map = vtkSmartPointer< vtkImageMapToColors >::New( ); - new_map->SetLookupTable( lut ); - - } // fi + this->ImageMaps.push_back( NULL ); + return; } // fi - this->ImageMaps.push_back( new_map ); + + // Create LUT filter + this->ImageMaps.push_back( vtkSmartPointer< vtkImageMapToColors >::New( ) ); + if( nImgs == 0 ) + { + double range[ 2 ]; + data->GetScalarRange( range ); + vtkSmartPointer< vtkWindowLevelLookupTable > lut = + vtkSmartPointer< vtkWindowLevelLookupTable >::New( ); + lut->SetScaleToLinear( ); + lut->SetTableRange( range ); + lut->SetWindow( range[ 1 ] - range[ 0 ] ); + lut->SetLevel( ( range[ 1 ] + range[ 0 ] ) / double( 2 ) ); + lut->Build( ); + this->ImageMaps[ 0 ]->SetLookupTable( lut ); + + this->MinWindow = double( 0 ); + this->MaxWindow = range[ 1 ] - range[ 0 ]; + this->MinLevel = range[ 0 ]; + this->MaxLevel = range[ 1 ]; + } + else + this->SetLookupTableAsColor( nImgs, 1, 0, 0 ); } // ------------------------------------------------------------------------- @@ -1122,7 +1203,6 @@ _MouseMoveCommand( dx *= actors->StartWindowLevel[ 0 ]; dy *= actors->StartWindowLevel[ 1 ]; actors->SetWindowLevel( - 0, actors->StartWindowLevel[ 0 ] + dx, actors->StartWindowLevel[ 1 ] + dy ); @@ -1147,8 +1227,8 @@ _MouseClickCommand( actors->StartWindowLevelPos[ 0 ] = pos[ 0 ]; actors->StartWindowLevelPos[ 1 ] = pos[ 1 ]; actors->StartWindowLevelPos[ 2 ] = pos[ 2 ]; - actors->StartWindowLevel[ 0 ] = actors->GetWindow( 0 ); - actors->StartWindowLevel[ 1 ] = actors->GetLevel( 0 ); + actors->StartWindowLevel[ 0 ] = actors->GetWindow( ); + actors->StartWindowLevel[ 1 ] = actors->GetLevel( ); } // ------------------------------------------------------------------------- diff --git a/lib/cpExtensions/Visualization/ImageSliceActors.h b/lib/cpExtensions/Visualization/ImageSliceActors.h index 962c8f2..22bfe6a 100644 --- a/lib/cpExtensions/Visualization/ImageSliceActors.h +++ b/lib/cpExtensions/Visualization/ImageSliceActors.h @@ -22,6 +22,7 @@ // ------------------------------------------------------------------------- class vtkAlgorithmOutput; class vtkImageData; +class vtkLookupTable; // ------------------------------------------------------------------------- namespace cpExtensions @@ -41,26 +42,17 @@ namespace cpExtensions public: vtkTypeMacro( ImageSliceActors, vtkPropCollection ); - enum LUTType - { - LUTType_None = 0, - LUTType_WindowLevel, - LUTType_Colors - }; + vtkGetMacro( MinWindow, double ); + vtkGetMacro( MaxWindow, double ); + vtkGetMacro( MinLevel, double ); + vtkGetMacro( MaxLevel, double ); public: // Creation static ImageSliceActors* New( ); - void AddInputConnection( - vtkAlgorithmOutput* aout, - int axis = 2, - LUTType lut = Self::LUTType_None - ); - void AddInputData( - vtkImageData* data, - int axis = 2, - LUTType lut = Self::LUTType_None ); + void AddInputConnection( vtkAlgorithmOutput* aout, int axis = 2 ); + void AddInputData( vtkImageData* data, int axis = 2 ); void Clear( ); void AssociateSlice( Self* other ); @@ -97,12 +89,17 @@ namespace cpExtensions vtkImageMapToColors* GetImageMap( unsigned int id ); const vtkImageMapToColors* GetImageMap( unsigned int id ) const; - double GetWindow( unsigned int id ) const; - double GetLevel( unsigned int id ) const; - void SetWindow( unsigned int id, double w ); - void SetLevel( unsigned int id, double l ); - void SetWindowLevel( unsigned int id, double w, double l ); - void ResetWindowLevel( unsigned int id ); + double GetWindow( ) const; + double GetLevel( ) const; + void SetWindow( double w ); + void SetLevel( double l ); + void SetWindowLevel( double w, double l ); + void ResetWindowLevel( ); + + void SetLookupTable( unsigned int id, vtkLookupTable* lut ); + void SetLookupTableAsColor( + unsigned int id, double r, double g, double b + ); int GetAxis( ) const; int GetSliceNumber( ) const; @@ -118,7 +115,7 @@ namespace cpExtensions ImageSliceActors( ); virtual ~ImageSliceActors( ); - void _ConfigureNewLUT( vtkImageData* data, LUTType lut_t ); + void _ConfigureNewLUT( vtkImageData* data ); void _ConfigureNewInput( int axis ); // Events @@ -160,6 +157,10 @@ namespace cpExtensions std::vector< vtkSmartPointer< vtkImageActor > > ImageActors; bool Interpolate; + // Window-Level values + double MinWindow, MaxWindow; + double MinLevel, MaxLevel; + // Other associated slices std::vector< vtkSmartPointer< Self > > AssociatedSlices; TCursorCommand SlicesCommand; @@ -175,7 +176,7 @@ namespace cpExtensions vtkSmartPointer< vtkPolyDataMapper > CursorMapper; vtkSmartPointer< vtkActor > CursorActor; vtkSmartPointer< vtkPlane > PlaneFunction; - vtkSmartPointer< vtkPolyData > PlaneSource; + vtkSmartPointer< vtkPolyData > Plane; vtkSmartPointer< vtkPolyDataMapper > PlaneMapper; char TextBuffer[ 1024 ]; vtkSmartPointer< vtkTextActor > TextActor; diff --git a/lib/cpExtensions/Visualization/MPRActors.cxx b/lib/cpExtensions/Visualization/MPRActors.cxx index 4498a2b..55f271c 100644 --- a/lib/cpExtensions/Visualization/MPRActors.cxx +++ b/lib/cpExtensions/Visualization/MPRActors.cxx @@ -1,5 +1,6 @@ #include +#include #include #include #include @@ -26,55 +27,61 @@ GetSliceActors( const int& i ) const // ------------------------------------------------------------------------- int cpExtensions::Visualization::MPRActors:: -AddInputConnection( - vtkAlgorithmOutput* aout, ImageSliceActors::LUTType lut - ) +AddInputConnection( vtkAlgorithmOutput* aout ) { int N = this->Slices[ 0 ][ 0 ]->GetNumberOfImageActors( ); if( N == 0 ) { - this->Slices[ 0 ][ 0 ]->AddInputConnection( aout, 0, lut ); + this->Slices[ 0 ][ 0 ]->AddInputConnection( aout, 0 ); vtkImageMapToColors* imap = this->Slices[ 0 ][ 0 ]->GetImageMap( 0 ); for( unsigned int i = 0; i < 2; ++i ) for( unsigned int j = 0; j < 3; ++j ) if( i != 0 || j != 0 ) this->Slices[ i ][ j ]->AddInputConnection( - ( ( imap != NULL )? imap->GetOutputPort( ): aout ), j, - ImageSliceActors::LUTType_None + ( ( imap != NULL )? imap->GetOutputPort( ): aout ), j ); } else { - /* // Check if the image share the same space - vtkImageData* ref_image = this->_Image( 0 ); - vtkImageData* new_image = - vtkImageData::SafeDownCast( - aout->GetProducer( )->GetOutputInformation( 0 )-> - Get( vtkDataObject::DATA_OBJECT( ) ) - ); - int ref_ext[ 6 ], new_ext[ 6 ]; - ref_image->GetExtent( ref_ext ); - new_image->GetExtent( new_ext ); - if( - ref_ext[ 0 ] == new_ext[ 0 ] && ref_ext[ 1 ] == new_ext[ 1 ] && - ref_ext[ 2 ] == new_ext[ 2 ] && ref_ext[ 3 ] == new_ext[ 3 ] && - ref_ext[ 4 ] == new_ext[ 4 ] && ref_ext[ 5 ] == new_ext[ 5 ] - ) + vtkImageData* new_image = dynamic_cast< vtkImageData* >( + aout->GetProducer( )->GetOutputDataObject( aout->GetIndex( ) ) + ); + if( new_image != NULL ) { - this->ImageMaps.push_back( - vtkSmartPointer< vtkImageMapToColors >::New( ) + vtkAlgorithmOutput* ref_aout = + this->Slices[ 0 ][ 0 ]->GetImageMap( 0 )->GetOutputPort( ); + vtkImageData* ref_image = dynamic_cast< vtkImageData* >( + ref_aout->GetProducer( )->GetOutputDataObject( ref_aout->GetIndex( ) ) ); - this->ImageMaps[ N ]->SetInputConnection( aout ); - this->SetLookupTableToColor( - N, double( 1 ), double( 0 ), double( 0 ) - ); - this->_Update( N ); - return( N ); + if( ref_image != NULL ) + { + int ref_ext[ 6 ], new_ext[ 6 ]; + ref_image->GetExtent( ref_ext ); + new_image->GetExtent( new_ext ); + if( + ref_ext[ 0 ] == new_ext[ 0 ] && ref_ext[ 1 ] == new_ext[ 1 ] && + ref_ext[ 2 ] == new_ext[ 2 ] && ref_ext[ 3 ] == new_ext[ 3 ] && + ref_ext[ 4 ] == new_ext[ 4 ] && ref_ext[ 5 ] == new_ext[ 5 ] + ) + { + this->Slices[ 0 ][ 0 ]->AddInputConnection( aout, 0 ); + vtkImageMapToColors* imap = this->Slices[ 0 ][ 0 ]->GetImageMap( N ); + for( unsigned int i = 0; i < 2; ++i ) + for( unsigned int j = 0; j < 3; ++j ) + if( i != 0 || j != 0 ) + this->Slices[ i ][ j ]->AddInputConnection( + ( ( imap != NULL )? imap->GetOutputPort( ): aout ), j + ); + } + else + N = -1; + } + else + N = -1; } else - N = -1; - */ + N = -1; } // fi return( N ); @@ -82,12 +89,12 @@ AddInputConnection( // ------------------------------------------------------------------------- int cpExtensions::Visualization::MPRActors:: -AddInputData( vtkImageData* image, ImageSliceActors::LUTType lut ) +AddInputData( vtkImageData* new_image ) { int N = this->Slices[ 0 ][ 0 ]->GetNumberOfImageActors( ); if( N == 0 ) { - this->Slices[ 0 ][ 0 ]->AddInputData( image, 0, lut ); + this->Slices[ 0 ][ 0 ]->AddInputData( new_image, 0 ); vtkImageMapToColors* imap = this->Slices[ 0 ][ 0 ]->GetImageMap( 0 ); for( unsigned int i = 0; i < 2; ++i ) for( unsigned int j = 0; j < 3; ++j ) @@ -95,62 +102,62 @@ AddInputData( vtkImageData* image, ImageSliceActors::LUTType lut ) { if( imap != NULL ) this->Slices[ i ][ j ]->AddInputConnection( - imap->GetOutputPort( ), j, - ImageSliceActors::LUTType_None + imap->GetOutputPort( ), j ); else - this->Slices[ i ][ j ]->AddInputData( - image, j, - ImageSliceActors::LUTType_None - ); + this->Slices[ i ][ j ]->AddInputData( new_image, j ); + } // fi } else - { - } // fi - return( N ); - /* - int N = this->ImageMaps.size( ); - if( N == 0 ) - { - this->ImageMaps.push_back( - vtkSmartPointer< vtkImageMapToColors >::New( ) - ); - this->ImageMaps[ 0 ]->SetInputData( image ); - this->SetLookupTableToWindowLevel( 0 ); - this->_Update( 0 ); - this->ResetWindowLevel( 0 ); - return( 0 ); - } - else { // Check if the image share the same space - vtkImageData* ref_image = this->_Image( 0 ); - vtkImageData* new_image = image; - int ref_ext[ 6 ], new_ext[ 6 ]; - ref_image->GetExtent( ref_ext ); - new_image->GetExtent( new_ext ); - if( - ref_ext[ 0 ] == new_ext[ 0 ] && ref_ext[ 1 ] == new_ext[ 1 ] && - ref_ext[ 2 ] == new_ext[ 2 ] && ref_ext[ 3 ] == new_ext[ 3 ] && - ref_ext[ 4 ] == new_ext[ 4 ] && ref_ext[ 5 ] == new_ext[ 5 ] - ) + vtkAlgorithmOutput* ref_aout = + this->Slices[ 0 ][ 0 ]->GetImageMap( 0 )->GetOutputPort( ); + vtkImageData* ref_image = dynamic_cast< vtkImageData* >( + ref_aout->GetProducer( )->GetOutputDataObject( ref_aout->GetIndex( ) ) + ); + if( ref_image != NULL ) { - this->ImageMaps.push_back( - vtkSmartPointer< vtkImageMapToColors >::New( ) - ); - this->ImageMaps[ N ]->SetInputData( image ); - this->SetLookupTableToColor( - N, double( 1 ), double( 0 ), double( 0 ) - ); - this->_Update( N ); - return( N ); + int ref_ext[ 6 ], new_ext[ 6 ]; + ref_image->GetExtent( ref_ext ); + new_image->GetExtent( new_ext ); + if( + ref_ext[ 0 ] == new_ext[ 0 ] && ref_ext[ 1 ] == new_ext[ 1 ] && + ref_ext[ 2 ] == new_ext[ 2 ] && ref_ext[ 3 ] == new_ext[ 3 ] && + ref_ext[ 4 ] == new_ext[ 4 ] && ref_ext[ 5 ] == new_ext[ 5 ] + ) + { + this->Slices[ 0 ][ 0 ]->AddInputData( new_image, 0 ); + vtkImageMapToColors* imap = this->Slices[ 0 ][ 0 ]->GetImageMap( N ); + for( unsigned int i = 0; i < 2; ++i ) + for( unsigned int j = 0; j < 3; ++j ) + if( i != 0 || j != 0 ) + { + if( imap != NULL ) + this->Slices[ i ][ j ]->AddInputConnection( + imap->GetOutputPort( ), j + ); + else + this->Slices[ i ][ j ]->AddInputData( new_image, j ); + + } // fi + } + else + N = -1; } else - return( -1 ); + N = -1; } // fi - */ + return( N ); +} + +// ------------------------------------------------------------------------- +unsigned int cpExtensions::Visualization::MPRActors:: +GetNumberOfImages( ) const +{ + return( this->Slices[ 0 ][ 0 ]->GetNumberOfImageActors( ) ); } // ------------------------------------------------------------------------- @@ -211,330 +218,64 @@ PushActorsInto( // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: -PopDataFrom( - vtkRenderer* x, - vtkRenderer* y, - vtkRenderer* z, - vtkRenderer* w +PopActorsFrom( + vtkRenderWindow* x, vtkRenderWindow* y, vtkRenderWindow* z, + vtkRenderWindow* w ) { - /* - vtkRenderer* rends[] = { x, y, z }; + this->Slices[ 0 ][ 0 ]->PopActorsFrom( x ); + this->Slices[ 0 ][ 1 ]->PopActorsFrom( y ); + this->Slices[ 0 ][ 2 ]->PopActorsFrom( z ); + + vtkRenderer* wren = + ( w != NULL )? w->GetRenderers( )->GetFirstRenderer( ): NULL; + vtkRenderer* rends[ ] = + { + ( x != NULL )? x->GetRenderers( )->GetFirstRenderer( ): NULL, + ( y != NULL )? y->GetRenderers( )->GetFirstRenderer( ): NULL, + ( z != NULL )? z->GetRenderers( )->GetFirstRenderer( ): NULL + }; for( int i = 0; i < 3; ++i ) { if( rends[ i ] != NULL ) - { - for( - unsigned int k = 0; - k < this->Slices[ 0 ][ i ]->GetNumberOfImageActors( ); - ++k - ) - rends[ i ]->RemoveActor( this->Slices[ 0 ][ i ]->GetImageActor( k ) ); - rends[ i ]->RemoveActor( this->Slices[ 0 ][ i ]->GetTextActor( ) ); for( int j = 0; j < 3; ++j ) - rends[ i ]->RemoveActor( this->Slices[ 0 ][ j ]->GetPlaneActor( ) ); - - } // fi - if( w != NULL ) + if( i != j ) + rends[ i ]->RemoveActor( this->Slices[ 0 ][ j ]->GetPlaneActor( ) ); + if( wren != NULL ) { for( unsigned int k = 0; k < this->Slices[ 1 ][ i ]->GetNumberOfImageActors( ); ++k ) - w->RemoveActor( this->Slices[ 1 ][ i ]->GetImageActor( k ) ); - w->RemoveActor( this->Slices[ 1 ][ i ]->GetPlaneActor( ) ); + wren->RemoveActor( this->Slices[ 1 ][ i ]->GetImageActor( k ) ); + wren->RemoveActor( this->Slices[ 1 ][ i ]->GetPlaneActor( ) ); } // fi } // rof - if( w != NULL ) - w->RemoveActor( this->ImageOutlineActor ); - */ -} - -// ------------------------------------------------------------------------- - /* -void cpExtensions::Visualization::MPRActors:: -LinkInteractors( ) -{ - this->_Update( 0 ); - this->_Update( 1 ); - this->_Update( 2 ); -} - */ - -// ------------------------------------------------------------------------- -void cpExtensions::Visualization::MPRActors:: -SetLookupTable( unsigned int i, vtkScalarsToColors* lut ) -{ - /* - if( i < this->ImageMaps.size( ) ) - { - this->ImageMaps[ i ]->SetLookupTable( lut ); - this->ImageMaps[ i ]->Update( ); - this->Modified( ); - - } // fi - */ -} - -// ------------------------------------------------------------------------- -vtkScalarsToColors* cpExtensions::Visualization::MPRActors:: -GetLookupTable( unsigned int i ) const -{ - /* - if( i < this->ImageMaps.size( ) ) - return( this->ImageMaps[ i ]->GetLookupTable( ) ); - else - return( NULL ); - */ -} - -// ------------------------------------------------------------------------- -void cpExtensions::Visualization::MPRActors:: -SetLookupTableToWindowLevel( unsigned int i ) -{ - /* - // Check if the input has been configured - vtkImageData* image = this->_Image( i ); - if( image == NULL ) - return; - - double r[ 2 ]; - image->GetScalarRange( r ); - - vtkSmartPointer< vtkWindowLevelLookupTable > lut = - vtkSmartPointer< vtkWindowLevelLookupTable >::New( ); - lut->SetScaleToLinear( ); - lut->SetTableRange( r ); - lut->Build( ); - - this->SetLookupTable( i, lut ); - */ -} - -// ------------------------------------------------------------------------- -double cpExtensions::Visualization::MPRActors:: -GetMinWindow( unsigned int i ) const -{ - return( 0 ); -} - -// ------------------------------------------------------------------------- -double cpExtensions::Visualization::MPRActors:: -GetMaxWindow( unsigned int i ) const -{ - /* - // Check if the input has been configured - vtkImageData* image = this->_Image( i ); - if( image == NULL ) - return( double( 0 ) ); - - double r[ 2 ]; - image->GetScalarRange( r ); - return( r[ 1 ] - r[ 0 ] ); - */ -} - -// ------------------------------------------------------------------------- -double cpExtensions::Visualization::MPRActors:: -GetMinLevel( unsigned int i ) const -{ - /* - // Check if the input has been configured - vtkImageData* image = this->_Image( i ); - if( image == NULL ) - return( double( 0 ) ); - - double r[ 2 ]; - image->GetScalarRange( r ); - return( r[ 0 ] ); - */ -} - -// ------------------------------------------------------------------------- -double cpExtensions::Visualization::MPRActors:: -GetMaxLevel( unsigned int i ) const -{ - /* - // Check if the input has been configured - vtkImageData* image = this->_Image( i ); - if( image == NULL ) - return( double( 0 ) ); - - double r[ 2 ]; - image->GetScalarRange( r ); - return( r[ 1 ] ); - */ -} - -// ------------------------------------------------------------------------- -double cpExtensions::Visualization::MPRActors:: -GetWindow( unsigned int i ) const -{ - /* - vtkWindowLevelLookupTable* lut = - dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( i ) ); - if( lut != NULL ) - return( lut->GetWindow( ) ); - else - return( double( 0 ) ); - */ -} - -// ------------------------------------------------------------------------- -double cpExtensions::Visualization::MPRActors:: -GetLevel( unsigned int i ) const -{ - /* - vtkWindowLevelLookupTable* lut = - dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( i ) ); - if( lut != NULL ) - return( lut->GetLevel( ) ); - else - return( double( 0 ) ); - */ -} - -// ------------------------------------------------------------------------- -void cpExtensions::Visualization::MPRActors:: -SetWindow( unsigned int i, const double& w ) -{ - /* - vtkWindowLevelLookupTable* lut = - dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( i ) ); - if( lut != NULL ) - { - lut->SetWindow( w ); - lut->Build( ); - this->ImageMaps[ i ]->Modified( ); - this->Modified( ); - - } // fi - */ -} - -// ------------------------------------------------------------------------- -void cpExtensions::Visualization::MPRActors:: -SetLevel( unsigned int i, const double& l ) -{ - /* - vtkWindowLevelLookupTable* lut = - dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( i ) ); - if( lut != NULL ) - { - lut->SetLevel( l ); - lut->Build( ); - this->ImageMaps[ i ]->Modified( ); - this->Modified( ); - - } // fi - */ -} - -// ------------------------------------------------------------------------- -void cpExtensions::Visualization::MPRActors:: -SetWindowLevel( unsigned int i, const double& w, const double& l ) -{ - /* - vtkWindowLevelLookupTable* lut = - dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( i ) ); - if( lut != NULL ) - { - lut->SetWindow( w ); - lut->SetLevel( l ); - lut->Build( ); - this->ImageMaps[ i ]->Modified( ); - - for( unsigned int j = 0; j < 3; ++j ) - this->Slices[ 0 ][ j ]->UpdateText( w, l ); - - this->Modified( ); - - } // fi - */ -} - -// ------------------------------------------------------------------------- -void cpExtensions::Visualization::MPRActors:: -ResetWindowLevel( unsigned int i ) -{ - /* - vtkImageData* image = this->_Image( i ); - vtkWindowLevelLookupTable* lut = - dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( i ) ); - if( image != NULL && lut != NULL ) - { - double r[ 2 ]; - image->GetScalarRange( r ); - lut->SetTableRange( r ); - lut->SetWindow( r[ 1 ] - r[ 0 ] ); - lut->SetLevel( ( r[ 1 ] + r[ 0 ] ) / double( 2 ) ); - lut->Build( ); - this->ImageMaps[ i ]->Modified( ); - this->Modified( ); + if( wren != NULL ) + wren->RemoveActor( this->ImageOutlineActor ); - } // fi - */ + this->Slices[ 0 ][ 0 ]->Clear( ); + this->Slices[ 0 ][ 1 ]->Clear( ); + this->Slices[ 0 ][ 2 ]->Clear( ); + this->Slices[ 1 ][ 0 ]->Clear( ); + this->Slices[ 1 ][ 1 ]->Clear( ); + this->Slices[ 1 ][ 2 ]->Clear( ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: -SetLookupTableToColor( - unsigned int i, const double& r, const double& g, const double& b - ) -{ - /* - static const double _0 = double( 0 ); - static const double _1 = double( 1 ); - static const double _2 = double( 2 ); - static const double _4 = double( 4 ); - static const double _6 = double( 6 ); - static const double _OPACITY = double( 0.6 ); - - // Check if the input has been configured - vtkImageData* image = this->_Image( i ); - if( image == NULL ) - return; - - double range[ 2 ]; - image->GetScalarRange( range ); - - // Get HSV from display color - double cmax = ( r > g )? r: g; cmax = ( b > cmax )? b: cmax; - double cmin = ( r < g )? r: g; cmin = ( b < cmin )? b: cmin; - double d = cmax - cmin; - - double saturation = ( std::fabs( cmax ) > _0 )? d / cmax: _0; - double value = cmax; - double hue = _0; - if( d > _0 ) - { - if( r == cmax ) - hue = std::fmod( ( g - b ) / d, _6 ); - else if( g == cmax ) - hue = ( ( b - r ) / d ) + _2; - else if( b == cmax ) - hue = ( ( r - g ) / d ) + _4; - hue *= _1 / _6; - - } // fi - - // Define new lookup table - vtkSmartPointer< vtkLookupTable > lut = - vtkSmartPointer< vtkLookupTable >::New( ); - lut->SetScaleToLinear( ); - lut->SetNanColor( _0, _0, _0, _0 ); - lut->SetTableRange( range[ 0 ], range[ 1 ] ); - lut->SetAlphaRange( _0, _OPACITY ); - lut->SetHueRange( _0, hue ); - lut->SetSaturationRange( _0, saturation ); - lut->SetValueRange( _0, value ); - lut->Build( ); - - this->SetLookupTable( i, lut ); - */ +SetLookupTableAsColor( unsigned int i, double r, double g, double b ) +{ + this->Slices[ 0 ][ 0 ]->SetLookupTableAsColor( 0, r, g, b ); + this->Slices[ 0 ][ 1 ]->Modified( ); + this->Slices[ 0 ][ 2 ]->Modified( ); + this->Slices[ 1 ][ 0 ]->Modified( ); + this->Slices[ 1 ][ 1 ]->Modified( ); + this->Slices[ 1 ][ 2 ]->Modified( ); + this->Modified( ); } // ------------------------------------------------------------------------- diff --git a/lib/cpExtensions/Visualization/MPRActors.h b/lib/cpExtensions/Visualization/MPRActors.h index f9fb213..85cee59 100644 --- a/lib/cpExtensions/Visualization/MPRActors.h +++ b/lib/cpExtensions/Visualization/MPRActors.h @@ -6,21 +6,6 @@ #include #include -/* -#include -#include -#include -*/ - -// ------------------------------------------------------------------------- -/* -class vtkAlgorithmOutput; -class vtkImageData; -class vtkRenderer; -class vtkScalarsToColors; -*/ - -// ------------------------------------------------------------------------- namespace cpExtensions { namespace Visualization @@ -42,14 +27,9 @@ namespace cpExtensions ImageSliceActors* GetSliceActors( const int& i ) const; - int AddInputConnection( - vtkAlgorithmOutput* aout, - ImageSliceActors::LUTType lut = ImageSliceActors::LUTType_WindowLevel - ); - int AddInputData( - vtkImageData* image, - ImageSliceActors::LUTType lut = ImageSliceActors::LUTType_WindowLevel - ); + int AddInputConnection( vtkAlgorithmOutput* aout ); + int AddInputData( vtkImageData* new_image ); + unsigned int GetNumberOfImages( ) const; void PushActorsInto( vtkRenderWindow* x, @@ -57,36 +37,16 @@ namespace cpExtensions vtkRenderWindow* z, vtkRenderWindow* w ); - void PopDataFrom( - vtkRenderer* x, - vtkRenderer* y, - vtkRenderer* z, - vtkRenderer* w + void PopActorsFrom( + vtkRenderWindow* x, + vtkRenderWindow* y, + vtkRenderWindow* z, + vtkRenderWindow* w ); - // Lookup table methods - void SetLookupTable( unsigned int i, vtkScalarsToColors* lut ); - vtkScalarsToColors* GetLookupTable( unsigned int i ) const; - - // Grayscale window/level lookup - void SetLookupTableToWindowLevel( unsigned int i ); - double GetMinWindow( unsigned int i ) const; - double GetMaxWindow( unsigned int i ) const; - double GetMinLevel( unsigned int i ) const; - double GetMaxLevel( unsigned int i ) const; - double GetWindow( unsigned int i ) const; - double GetLevel( unsigned int i ) const; - void SetWindow( unsigned int i, const double& w ); - void SetLevel( unsigned int i, const double& l ); - void SetWindowLevel( unsigned int i, const double& w, const double& l ); - void ResetWindowLevel( unsigned int i ); - // Color lookup table - void SetLookupTableToColor( - unsigned int i, - const double& r = double( 1 ), - const double& g = double( 0 ), - const double& b = double( 0 ) + void SetLookupTableAsColor( + unsigned int i, double r, double g, double b ); // Slice access @@ -112,7 +72,6 @@ namespace cpExtensions Self& operator=( const Self& ); protected: - // TODO: std::vector< vtkSmartPointer< vtkImageMapToColors > > ImageMaps; vtkSmartPointer< vtkActor > ImageOutlineActor; vtkSmartPointer< ImageSliceActors > Slices[ 2 ][ 3 ]; }; diff --git a/lib/cpExtensions/Visualization/MPRObjects.cxx b/lib/cpExtensions/Visualization/MPRObjects.cxx index 0e52249..cfee04e 100644 --- a/lib/cpExtensions/Visualization/MPRObjects.cxx +++ b/lib/cpExtensions/Visualization/MPRObjects.cxx @@ -48,7 +48,7 @@ SetRenderWindows( // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRObjects:: -SetImage( vtkImageData* image ) +AddImage( vtkImageData* image ) { this->m_MPRActors->AddInputData( image ); this->m_MPRActors->PushActorsInto( @@ -59,93 +59,25 @@ SetImage( vtkImageData* image ) ); // First rendering - this->m_MPRActors->ResetSlices( ); - this->ResetCameras( ); + if( this->m_MPRActors->GetNumberOfImages( ) == 1 ) + { + this->m_MPRActors->ResetSlices( ); + this->ResetCameras( ); + + } // fi this->RenderAll( ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRObjects:: -AddAuxiliaryImage( vtkImageData* image ) +ClearAll( ) { - // Try to add new image - int id = this->m_MPRActors->AddInputData( image ); - if( id < 0 ) - return; - - // Push everything on renderers - this->m_MPRActors->PushActorsInto( + this->m_MPRActors->PopActorsFrom( this->m_Windows[ 0 ], this->m_Windows[ 1 ], this->m_Windows[ 2 ], this->m_Windows[ 3 ] ); - - // Rendering - this->RenderAll( ); -} - -// ------------------------------------------------------------------------- -void cpExtensions::Visualization::MPRObjects:: -ActivateInteractors( ) -{ - // Prepare renderers - for( int i = 0; i < 3; ++i ) - { - // Check prerrequisites - if( this->m_Windows[ i ] == NULL || this->m_Renderers[ i ] == NULL ) - { - // TODO: this->m_Styles[ i ] = NULL; - continue; - - } // fi - - ImageSliceActors* actors = this->m_MPRActors->GetSliceActors( i ); - if( actors == NULL ) - { - // TODO: this->m_Styles[ i ] = NULL; - continue; - - } // fi - - /* TODO - this->m_Styles[ i ] = vtkSmartPointer< TStyle >::New( ); - this->m_Styles[ i ]->Configure( actors, this->m_MPRActors ); - this->m_Styles[ i ]-> - SetInteractor( this->m_Windows[ i ]->GetInteractor( ), i ); - this->m_Styles[ i ]->SetModeToNavigation( ); - */ - - } // rof - - // Synch 2D and 3D renderers - for( int i = 0; i < 3; ++i ) - { - for( int j = 0; j < 3; ++j ) - { - /* TODO - if( - this->m_Windows[ i ] != NULL && - this->m_Windows[ j ] != NULL && - i != j - ) - this->m_Styles[ i ]-> - AssociateInteractor( this->m_Windows[ j ]->GetInteractor( ) ); - */ - - } // rof - /* TODO - if( this->m_Windows[ 3 ] != NULL ) - this->m_Styles[ i ]-> - AssociateInteractor( this->m_Windows[ 3 ]->GetInteractor( ) ); - */ - - } // rof - - // Finish interactor linking - // TODO: this->m_MPRActors->LinkInteractors( ); - - // Restart rendering this->ResetCameras( ); this->RenderAll( ); } diff --git a/lib/cpExtensions/Visualization/MPRObjects.h b/lib/cpExtensions/Visualization/MPRObjects.h index 7d33f3f..39e827f 100644 --- a/lib/cpExtensions/Visualization/MPRObjects.h +++ b/lib/cpExtensions/Visualization/MPRObjects.h @@ -32,9 +32,8 @@ namespace cpExtensions vtkRenderWindow* wx, vtkRenderWindow* wy, vtkRenderWindow* wz, vtkRenderWindow* w3D ); - void SetImage( vtkImageData* image ); - void AddAuxiliaryImage( vtkImageData* image ); - void ActivateInteractors( ); + void AddImage( vtkImageData* image ); + void ClearAll( ); void ResetCamera( const int& id ); void ResetCameras( ); diff --git a/lib/cpPlugins/Interface/BaseMPRWindow.cxx b/lib/cpPlugins/Interface/BaseMPRWindow.cxx index cc3f9b3..b439755 100644 --- a/lib/cpPlugins/Interface/BaseMPRWindow.cxx +++ b/lib/cpPlugins/Interface/BaseMPRWindow.cxx @@ -2,21 +2,42 @@ #ifdef cpPlugins_Interface_QT4 -#include +#ifdef _WIN32 +# define PLUGIN_PREFIX "" +# define PLUGIN_EXT "dll" +# define PLUGIN_REGEX "Plugins file (*.dll);;All files (*)" +#else // Linux +# define PLUGIN_PREFIX "lib" +# define PLUGIN_EXT "so" +# define PLUGIN_REGEX "Plugins file (*.so);;All files (*)" +#endif // _WIN32 + +#include +#include + +#include +#include // ------------------------------------------------------------------------- cpPlugins::Interface::BaseMPRWindow:: BaseMPRWindow( QWidget* parent ) - : QMainWindow( parent ), - m_UI( new Ui::BaseMPRWindow ) + : cpExtensions::QT::QuadSplitter( parent ), + m_LastLoadedPlugin( "." ) { - // Create and associate renderers + // Configure splitter + this->m_XVTK = new QVTKWidget( this ); + this->m_YVTK = new QVTKWidget( this ); + this->m_ZVTK = new QVTKWidget( this ); + this->m_WVTK = new QVTKWidget( this ); + this->addWidgets( this->m_XVTK, this->m_YVTK, this->m_ZVTK, this->m_WVTK ); + + // Create and associate vtk renderers this->m_MPRObjects = vtkSmartPointer< TMPRObjects >::New( ); this->m_MPRObjects->SetRenderWindows( - this->m_UI->m_XVTK->GetRenderWindow( ), - this->m_UI->m_YVTK->GetRenderWindow( ), - this->m_UI->m_ZVTK->GetRenderWindow( ), - this->m_UI->m_WVTK->GetRenderWindow( ) + this->m_XVTK->GetRenderWindow( ), + this->m_YVTK->GetRenderWindow( ), + this->m_ZVTK->GetRenderWindow( ), + this->m_WVTK->GetRenderWindow( ) ); } @@ -24,42 +45,268 @@ BaseMPRWindow( QWidget* parent ) cpPlugins::Interface::BaseMPRWindow:: ~BaseMPRWindow( ) { - if( this->m_UI != NULL ) - delete this->m_UI; + if( this->m_WVTK != NULL ) + delete this->m_WVTK; + if( this->m_ZVTK != NULL ) + delete this->m_ZVTK; + if( this->m_YVTK != NULL ) + delete this->m_YVTK; + if( this->m_XVTK != NULL ) + delete this->m_XVTK; +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::BaseMPRWindow:: +DialogLoadPlugins( ) +{ + // Show dialog and check if it was accepted + QFileDialog dialog( this ); + dialog.setFileMode( QFileDialog::ExistingFile ); + dialog.setDirectory( this->m_LastLoadedPlugin.c_str( ) ); + dialog.setNameFilter( tr( PLUGIN_REGEX ) ); + dialog.setDefaultSuffix( tr( PLUGIN_EXT ) ); + if( !( dialog.exec( ) ) ) + return; + + std::string fname = dialog.selectedFiles( ).at( 0 ).toStdString( ); + if( !( this->LoadPlugins( fname ) ) ) + QMessageBox::critical( + this, tr( "Ignoring plugin" ), tr( fname.c_str( ) ) + ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::BaseMPRWindow:: +AssociatePluginsToMenu( QMenu* menu, QObject* obj, const char* slot ) +{ + std::map< std::string, std::set< std::string > >::const_iterator i; + std::set< std::string >::const_iterator j; + + menu->clear( ); + for( i = this->m_Filters.begin( ); i != this->m_Filters.end( ); i++ ) + { + QMenu* newMenu = menu->addMenu( i->first.c_str( ) ); + for( j = i->second.begin( ); j != i->second.end( ); ++j ) + { + QAction* a = newMenu->addAction( j->c_str( ) ); + QObject::connect( a, SIGNAL( triggered( ) ), obj, slot ); + + } // rof + + } // rof } // ------------------------------------------------------------------------- bool cpPlugins::Interface::BaseMPRWindow:: -_LoadPlugins( const std::string& fname ) +LoadPlugins( const std::string& fname ) { - return( false ); + this->Block( ); + + // Is it already loaded? + if( this->m_LoadedPlugins.find( fname ) != this->m_LoadedPlugins.end( ) ) + { + this->Unblock( ); + return( true ); + + } // fi + + // Was it succesfully loaded? + if( !( this->m_Interface.Load( fname ) ) ) + { + this->Unblock( ); + return( false ); + + } // fi + + // Update a simple track + this->m_LoadedPlugins.insert( fname ); + this->m_LastLoadedPlugin = fname; + this->_UpdatePlugins( ); + + this->Unblock( ); + return( true ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::BaseMPRWindow:: +LoadPlugins( ) +{ + // Load file into a char buffer + std::ifstream in( + "Plugins.cfg", std::ios::in | std::ios::binary | std::ios::ate + ); + if( !in.is_open( ) ) + return; + std::streampos size = in.tellg( ); + char* buffer = new char[ size ]; + in.seekg( 0, std::ios::beg ); + in.read( buffer, size ); + in.close( ); + + // Read stream + std::stringstream in_stream( buffer ); + while( in_stream ) + { + char line[ 2048 ]; + in_stream.getline( line, 2048 ); + this->LoadPlugins( line ); + + } // elihw + + // Finish + delete buffer; } // ------------------------------------------------------------------------- bool cpPlugins::Interface::BaseMPRWindow:: -_LoadImage( const std::string& fname ) +LoadImage( ) { - return( false ); + std::string msg = ""; + bool ret = true; + if( this->m_ImageReader.IsNull( ) ) + { + msg = "No valid image reader. Please load a valid plugin file."; + ret = false; + + } // fi + + if( this->m_ImageReader->ExecConfigurationDialog( this ) ) + { + this->Block( ); + msg = this->m_ImageReader->Update( ); + if( msg == "" ) + { + this->m_Images.push_back( + this->m_ImageReader->GetOutput< TImage >( 0 ) + ); + this->m_ImageReader->DisconnectOutputs( ); + this->m_ImageReader->GetParameters( )->ClearStringList( "FileNames" ); + vtkImageData* vtk_id = + this->m_Images.rbegin( )->GetPointer( )->GetVTK< vtkImageData >( ); + if( vtk_id != NULL ) + { + this->m_MPRObjects->AddImage( vtk_id ); + /* + MementoState(m_state, this->m_Image); + this->m_state++; + */ + } + else + msg = "Read image does not have a valid VTK converter."; + } + else + ret = false; + + } // fi + + // Show errors and return + this->Unblock( ); + if( msg != "" ) + QMessageBox::critical( + this, tr( "Error reading image." ), tr( msg.c_str( ) ) + ); + return( ret ); } // ------------------------------------------------------------------------- bool cpPlugins::Interface::BaseMPRWindow:: -_LoadMesh( const std::string& fname ) +LoadMesh( ) { return( false ); } -/* - TInterface m_Interface; +// ------------------------------------------------------------------------- +void cpPlugins::Interface::BaseMPRWindow:: +ExecuteFilter( const std::string& name, int input_id, int output_id ) +{ + TProcessObject::Pointer filter = + this->m_Interface.CreateProcessObject( name ); + std::string category = filter->GetClassCategory( ); + if( category == "ImageToBinaryImageFilter" ) + { + if( input_id < this->m_Images.size( ) ) + { + filter->SetInput( 0, this->m_Images[ input_id ] ); + bool dlg_ok = filter->ExecConfigurationDialog( NULL ); + if( !dlg_ok ) + return; - TProcessObject::Pointer m_ImageReader; - TProcessObject::Pointer m_ImageWriter; - TProcessObject::Pointer m_MeshReader; - TProcessObject::Pointer m_MeshWriter; + } // fi - TImages m_Images; - TMeshes m_Meshes; -*/ + } // fi +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::BaseMPRWindow:: +ClearAll( ) +{ + this->m_MPRObjects->ClearAll( ); + this->m_Images.clear( ); + this->m_Meshes.clear( ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::BaseMPRWindow:: +_UpdatePlugins( ) +{ + typedef TInterface::TClasses _C; + + this->m_Filters.clear( ); + _C& classes = this->m_Interface.GetClasses( ); + for( _C::const_iterator i = classes.begin( ); i != classes.end( ); ++i ) + { + TProcessObject::Pointer o = + this->m_Interface.CreateProcessObject( i->first ); + std::string name = o->GetClassName( ); + std::string category = o->GetClassCategory( ); + if( category == "ImageReader" ) + this->m_ImageReader = o; + else if( category == "ImageWriter" ) + this->m_ImageWriter = o; + else if( category == "MeshReader" ) + this->m_MeshReader = o; + else if( category == "MeshWriter" ) + this->m_MeshWriter = o; + else + this->m_Filters[ category ].insert( name ); + + /* + if( category == "ImageReader" ) + this->m_ImageReaderClass = name; + else if( category == "ImageWriter" ) + this->m_ImageWriterClass = name; + else if( category == "MeshReader" ) + this->m_MeshReaderClass = name; + else if( category == "MeshWriter" ) + this->m_MeshWriterClass = name; + else if( category == "MeshToMeshFilter" ) + { + if( name.find_last_of( "Cutter" ) != std::string::npos ) + this->m_MeshCutterClass = name; + } + else if( category == "ImageToImageFilter" ) + { + QAction* action = + this->m_UI->MenuImageToImage->addAction( QString( name.c_str( ) ) ); + QObject::connect( + action, SIGNAL( triggered( ) ), + this, SLOT( _triggered_actionImageToImage( ) ) + ); + } + else if( category == "ImageToMeshFilter" ) + { + QAction* action = + this->m_UI->MenuImageToMesh->addAction( QString( name.c_str( ) ) ); + QObject::connect( + action, SIGNAL( triggered( ) ), + this, SLOT( _triggered_actionImageToMesh( ) ) + ); + + } // fi + */ + + } // rof +} #endif // cpPlugins_Interface_QT4 diff --git a/lib/cpPlugins/Interface/BaseMPRWindow.h b/lib/cpPlugins/Interface/BaseMPRWindow.h index 37dd18e..d050967 100644 --- a/lib/cpPlugins/Interface/BaseMPRWindow.h +++ b/lib/cpPlugins/Interface/BaseMPRWindow.h @@ -1,35 +1,36 @@ #ifndef __CPPLUGINS__INTERFACE__BASEMPRWINDOW__H__ #define __CPPLUGINS__INTERFACE__BASEMPRWINDOW__H__ +#include #include #ifdef cpPlugins_Interface_QT4 #include +#include +#include -#include +#include +#include +#include #include +#include #include #include #include #include #include -namespace Ui -{ - class BaseMPRWindow; -} - namespace cpPlugins { namespace Interface { /** */ - class BaseMPRWindow - : public QMainWindow + class cpPlugins_Interface_EXPORT BaseMPRWindow + : public cpExtensions::QT::QuadSplitter { Q_OBJECT; @@ -40,30 +41,64 @@ namespace cpPlugins typedef cpPlugins::Interface::Image TImage; typedef cpPlugins::Interface::Mesh TMesh; - typedef std::set< TImage::Pointer > TImages; - typedef std::set< TMesh::Pointer > TMeshes; + typedef std::vector< TImage::Pointer > TImages; + typedef std::vector< TMesh::Pointer > TMeshes; + typedef std::set< std::string > TOrderedStringContainer; + typedef std::map< std::string, std::set< std::string > > TFilters; public: - explicit BaseMPRWindow( QWidget* parent = NULL ); + explicit BaseMPRWindow( QWidget* parent = 0 ); virtual ~BaseMPRWindow( ); - protected: - bool _LoadPlugins( const std::string& fname ); - bool _LoadImage( const std::string& fname ); - bool _LoadMesh( const std::string& fname ); + void DialogLoadPlugins( ); + void AssociatePluginsToMenu( + QMenu* menu, QObject* obj, const char* slot + ); + + inline void Block( ) + { + QApplication::setOverrideCursor( Qt::WaitCursor ); + this->setEnabled( false ); + } + inline void Unblock( ) + { + QApplication::restoreOverrideCursor( ); + this->setEnabled( true ); + } + + bool LoadPlugins( const std::string& fname ); + void LoadPlugins( ); + bool LoadImage( ); + bool LoadMesh( ); + + void ExecuteFilter( + const std::string& name, + int input_id, int output_id = -1 + ); + + void ClearAll( ); protected: - Ui::BaseMPRWindow* m_UI; + void _UpdatePlugins( ); + protected: typedef cpExtensions::Visualization::MPRObjects TMPRObjects; vtkSmartPointer< TMPRObjects > m_MPRObjects; + QVTKWidget* m_XVTK; + QVTKWidget* m_YVTK; + QVTKWidget* m_ZVTK; + QVTKWidget* m_WVTK; + TInterface m_Interface; + TOrderedStringContainer m_LoadedPlugins; + std::string m_LastLoadedPlugin; TProcessObject::Pointer m_ImageReader; TProcessObject::Pointer m_ImageWriter; TProcessObject::Pointer m_MeshReader; TProcessObject::Pointer m_MeshWriter; + TFilters m_Filters; TImages m_Images; TMeshes m_Meshes; diff --git a/lib/cpPlugins/Interface/BaseMPRWindow.ui b/lib/cpPlugins/Interface/BaseMPRWindow.ui deleted file mode 100644 index ad47ad5..0000000 --- a/lib/cpPlugins/Interface/BaseMPRWindow.ui +++ /dev/null @@ -1,230 +0,0 @@ - - - BaseMPRWindow - - - - 0 - 0 - 718 - 706 - - - - - 718 - 706 - - - - Put a fancy title here - - - - - - - - 700 - 400 - - - - Qt::Horizontal - - - - Qt::Vertical - - - - Qt::Horizontal - - - - true - - - - 200 - 200 - - - - - - true - - - - 200 - 200 - - - - - - - Qt::Horizontal - - - - true - - - - 200 - 200 - - - - - - true - - - - 200 - 200 - - - - - - - - - - - - - 0 - 0 - 718 - 27 - - - - - &File - - - - - - - - - - - - Image to image - - - - - Image to mesh - - - - - Edit - - - - - - - - - - - - true - - - Open image - - - Ctrl+O - - - - - true - - - Open plugins - - - Ctrl+P - - - - - Exit - - - - - Open polydata - - - Ctrl+M - - - - - dasdasd - - - - - Open segmentation - - - - - Undo - - - Ctrl+Z - - - - - Redo - - - Ctrl+Y - - - - - - - QVTKWidget - QWidget -
QVTKWidget.h
-
-
- - - - actionExit - triggered() - BaseMPRWindow - close() - - - -1 - -1 - - - 378 - 235 - - - - -
diff --git a/lib/cpPlugins/Interface/CMakeLists.txt b/lib/cpPlugins/Interface/CMakeLists.txt index 9cd9c5a..83552b2 100644 --- a/lib/cpPlugins/Interface/CMakeLists.txt +++ b/lib/cpPlugins/Interface/CMakeLists.txt @@ -21,7 +21,6 @@ IF(USE_QT4) SET( LIB_QT_UI ParametersListWidget.ui - BaseMPRWindow.ui ) SET( LIB_QT_Headers diff --git a/lib/cpPlugins/Interface/Instances_itkMesh.cxx b/lib/cpPlugins/Interface/Instances_itkMesh.cxx index a7d3df4..c721b5e 100644 --- a/lib/cpPlugins/Interface/Instances_itkMesh.cxx +++ b/lib/cpPlugins/Interface/Instances_itkMesh.cxx @@ -1,5 +1,6 @@ #include +#undef ITK_MANUAL_INSTANTIATION #include #include diff --git a/lib/cpPlugins/Interface/Instances_itkVectorImage.cxx b/lib/cpPlugins/Interface/Instances_itkVectorImage.cxx index 3db15c6..5c4d599 100644 --- a/lib/cpPlugins/Interface/Instances_itkVectorImage.cxx +++ b/lib/cpPlugins/Interface/Instances_itkVectorImage.cxx @@ -2,6 +2,7 @@ #include +#undef ITK_MANUAL_INSTANTIATION #include #include diff --git a/lib/cpPlugins/Interface/Interface.cxx b/lib/cpPlugins/Interface/Interface.cxx index e4160c6..4d470b6 100644 --- a/lib/cpPlugins/Interface/Interface.cxx +++ b/lib/cpPlugins/Interface/Interface.cxx @@ -61,61 +61,96 @@ CreateProcessObject( const std::string& name ) const bool cpPlugins::Interface::Interface:: Load( const std::string& path ) { - if( this->m_Pluma.load( path ) ) + bool ret = true; + try { - this->_LoadClasses( ); - return( true ); + ret = this->m_Pluma.load( path ); + if( ret ) + this->_LoadClasses( ); } - else - return( false ); + catch( ... ) + { + ret = false; + + } // yrt + return( ret ); } // ------------------------------------------------------------------------- bool cpPlugins::Interface::Interface:: Load( const std::string& folder, const std::string& name ) { - if( this->m_Pluma.load( folder, name ) ) + bool ret = true; + try { - this->_LoadClasses( ); - return( true ); + ret = this->m_Pluma.load( folder, name ); + if( ret ) + this->_LoadClasses( ); } - else - return( false ); + catch( ... ) + { + ret = false; + + } // yrt + return( ret ); } // ------------------------------------------------------------------------- int cpPlugins::Interface::Interface:: LoadFromFolder( const std::string& folder, bool r ) { - if( this->m_Pluma.loadFromFolder( folder, r ) ) + bool ret = true; + try { - this->_LoadClasses( ); - return( true ); + ret = this->m_Pluma.loadFromFolder( folder, r ); + if( ret ) + this->_LoadClasses( ); } - else - return( false ); + catch( ... ) + { + ret = false; + + } // yrt + return( ret ); } // ------------------------------------------------------------------------- bool cpPlugins::Interface::Interface:: Unload( const std::string& name ) { - if( this->m_Pluma.unload( name ) ) + bool ret = true; + try { - this->m_Providers.clear( ); - this->m_Classes.clear( ); - this->_LoadClasses( ); - return( true ); + ret = this->m_Pluma.unload( name ); + if( ret ) + { + this->m_Providers.clear( ); + this->m_Classes.clear( ); + this->_LoadClasses( ); + + } // fi } - else - return( false ); + catch( ... ) + { + ret = false; + + } // yrt + return( ret ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::Interface:: UnloadAll( ) { - this->m_Pluma.unloadAll( ); + try + { + this->m_Pluma.unloadAll( ); + } + catch( ... ) + { + // Do nothing + + } // yrt this->m_Providers.clear( ); this->m_Classes.clear( ); } diff --git a/lib/cpPlugins/Interface/Parameters.cxx b/lib/cpPlugins/Interface/Parameters.cxx index d2ae7f1..b02168b 100644 --- a/lib/cpPlugins/Interface/Parameters.cxx +++ b/lib/cpPlugins/Interface/Parameters.cxx @@ -380,7 +380,7 @@ cpPlugins_Parameters_Add( Real ); TParameters::iterator i = this->m_Parameters.find( name ); \ if( i == this->m_Parameters.end( ) ) \ return; \ - if( i->second.first != Self::Y ) \ + if( i->second.first != Self::Y##List ) \ return; \ i->second.second.second = ""; \ this->Modified( ); \ diff --git a/lib/cpPlugins/Plugins/BasicFilters/BinaryErodeImageFilter.cxx b/lib/cpPlugins/Plugins/BasicFilters/BinaryErodeImageFilter.cxx index fd207a0..0713edf 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/BinaryErodeImageFilter.cxx +++ b/lib/cpPlugins/Plugins/BasicFilters/BinaryErodeImageFilter.cxx @@ -16,12 +16,7 @@ BinaryErodeImageFilter( ) this->SetNumberOfOutputs( 1 ); this->_MakeOutput< cpPlugins::Interface::Image >( 0 ); - using namespace cpPlugins::Interface; - this->m_DefaultParameters.Configure( Parameters::Uint, "Radius" ); - - this->m_DefaultParameters.SetValueAsUint( "Radius", 2 ); - - this->m_Parameters = this->m_DefaultParameters; + this->m_Parameters->ConfigureAsUint( "Radius", 2 ); } // ------------------------------------------------------------------------- @@ -72,19 +67,17 @@ _RealGD( itk::DataObject* image ) // Get parameters _RT rad_val; - rad_val.Fill( this->m_Parameters.GetValueAsUint( "Radius" ) ); + rad_val.Fill( this->m_Parameters->GetUint( "Radius" ) ); // Configure filter StructuringElementType structuringElement; - structuringElement.SetRadius(rad_val); - structuringElement.CreateStructuringElement(); - - + structuringElement.SetRadius( rad_val ); + structuringElement.CreateStructuringElement( ); _F* filter = this->_CreateITK< _F >( ); filter->SetInput( dynamic_cast< I* >( image ) ); - filter->SetKernel(structuringElement); + filter->SetKernel( structuringElement ); filter->Update( ); // Connect output diff --git a/lib/cpPlugins/Plugins/BasicFilters/BinaryThresholdImageFilter.cxx b/lib/cpPlugins/Plugins/BasicFilters/BinaryThresholdImageFilter.cxx index 10704aa..21df227 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/BinaryThresholdImageFilter.cxx +++ b/lib/cpPlugins/Plugins/BasicFilters/BinaryThresholdImageFilter.cxx @@ -12,18 +12,10 @@ BinaryThresholdImageFilter( ) this->SetNumberOfOutputs( 1 ); this->_MakeOutput< cpPlugins::Interface::Image >( 0 ); - using namespace cpPlugins::Interface; - this->m_DefaultParameters.Configure( Parameters::Real, "LowerThresholdValue" ); - this->m_DefaultParameters.Configure( Parameters::Real, "UpperThresholdValue" ); - this->m_DefaultParameters.Configure( Parameters::Real, "InsideValue" ); - this->m_DefaultParameters.Configure( Parameters::Real, "OutsideValue" ); - - this->m_DefaultParameters.SetValueAsReal( "LowerThresholdValue", 100 ); - this->m_DefaultParameters.SetValueAsReal( "UpperThresholdValue", 500 ); - this->m_DefaultParameters.SetValueAsReal( "InsideValue", 255 ); - this->m_DefaultParameters.SetValueAsReal( "OutsideValue", 0 ); - - this->m_Parameters = this->m_DefaultParameters; + this->m_Parameters->ConfigureAsReal( "LowerThresholdValue", 0 ); + this->m_Parameters->ConfigureAsReal( "UpperThresholdValue", 0 ); + this->m_Parameters->ConfigureAsUint( "InsideValue", 255 ); + this->m_Parameters->ConfigureAsUint( "OutsideValue", 1 ); } // ------------------------------------------------------------------------- @@ -74,10 +66,10 @@ _RealGD( itk::DataObject* image ) // Get parameters //unsigned int bins = // this->m_Parameters.GetValueAsUint( "NumberOfHistogramBins" ); - _IP lower_val = _IP( this->m_Parameters.GetValueAsReal( "LowerValue" ) ); - _IP upper_val = _IP( this->m_Parameters.GetValueAsReal( "UpperValue" ) ); - _OP in_val = _OP( this->m_Parameters.GetValueAsReal( "InsideValue" ) ); - _OP out_val = _OP( this->m_Parameters.GetValueAsReal( "OutsideValue" ) ); + _IP lower_val = _IP( this->m_Parameters->GetReal( "LowerValue" ) ); + _IP upper_val = _IP( this->m_Parameters->GetReal( "UpperValue" ) ); + _OP in_val = _OP( this->m_Parameters->GetUint( "InsideValue" ) ); + _OP out_val = _OP( this->m_Parameters->GetUint( "OutsideValue" ) ); // Configure filter _F* filter = this->_CreateITK< _F >( ); diff --git a/lib/cpPlugins/Plugins/BasicFilters/BinaryThresholdImageFilter.h b/lib/cpPlugins/Plugins/BasicFilters/BinaryThresholdImageFilter.h index 7bfa56c..6f83314 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/BinaryThresholdImageFilter.h +++ b/lib/cpPlugins/Plugins/BasicFilters/BinaryThresholdImageFilter.h @@ -27,7 +27,7 @@ namespace cpPlugins ); cpPlugins_Id_Macro( cpPlugins::BasicFilters::BinaryThresholdImageFilter, - "ImageToImageFilter" + "ImageToBinaryImageFilter" ); protected: diff --git a/lib/cpPlugins/Plugins/BasicFilters/Cutter.cxx b/lib/cpPlugins/Plugins/BasicFilters/Cutter.cxx index e0c80b4..e3f1e2b 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/Cutter.cxx +++ b/lib/cpPlugins/Plugins/BasicFilters/Cutter.cxx @@ -16,8 +16,6 @@ Cutter( ) this->SetNumberOfInputs( 2 ); this->SetNumberOfOutputs( 1 ); this->_MakeOutput< cpPlugins::Interface::Mesh >( 0 ); - - this->m_Parameters = this->m_DefaultParameters; } // ------------------------------------------------------------------------- diff --git a/lib/cpPlugins/Plugins/BasicFilters/ExtractSliceImageFilter.cxx b/lib/cpPlugins/Plugins/BasicFilters/ExtractSliceImageFilter.cxx index 88b3152..df46d6f 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/ExtractSliceImageFilter.cxx +++ b/lib/cpPlugins/Plugins/BasicFilters/ExtractSliceImageFilter.cxx @@ -12,12 +12,8 @@ ExtractSliceImageFilter( ) this->SetNumberOfOutputs( 1 ); this->_MakeOutput< cpPlugins::Interface::Image >( 0 ); - using namespace cpPlugins::Interface; - this->m_DefaultParameters.Configure( Parameters::Int, "Axis" ); - this->m_DefaultParameters.Configure( Parameters::Int, "Slice" ); - this->m_DefaultParameters.SetValueAsInt( "Axis", 0 ); - this->m_DefaultParameters.SetValueAsInt( "Slice", 0 ); - this->m_Parameters = this->m_DefaultParameters; + this->m_Parameters->ConfigureAsUint( "Axis", 0 ); + this->m_Parameters->ConfigureAsInt( "Slice", 0 ); } // ------------------------------------------------------------------------- @@ -61,11 +57,8 @@ _RealGD( itk::DataObject* image ) typedef typename O::PixelType _OP; // Get parameters - int axis = this->m_Parameters.GetValueAsInt( "Axis" ); - int slice = this->m_Parameters.GetValueAsInt( "Slice" ); - - std::cout << "HOLA: " << slice << std::endl; - + int axis = this->m_Parameters->GetUint( "Axis" ); + int slice = this->m_Parameters->GetInt( "Slice" ); // Compute region I* img = dynamic_cast< I* >( image ); @@ -77,8 +70,6 @@ _RealGD( itk::DataObject* image ) region.SetSize( size ); region.SetIndex( index ); - std::cout << "HOLA-: " << region << std::endl; - // Configure filter _F* filter = this->_CreateITK< _F >( ); filter->SetInput( img ); diff --git a/lib/cpPlugins/Plugins/BasicFilters/FloodFillImageFilter.cxx b/lib/cpPlugins/Plugins/BasicFilters/FloodFillImageFilter.cxx index 471c10b..07fc939 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/FloodFillImageFilter.cxx +++ b/lib/cpPlugins/Plugins/BasicFilters/FloodFillImageFilter.cxx @@ -13,14 +13,10 @@ FloodFillImageFilter( ) this->SetNumberOfOutputs( 1 ); this->_MakeOutput< cpPlugins::Interface::Image >( 0 ); - using namespace cpPlugins::Interface; - this->m_DefaultParameters.Configure( Parameters::Point, "Seed" ); - this->m_DefaultParameters.Configure( Parameters::Real, "InsideValue" ); - this->m_DefaultParameters.Configure( Parameters::Real, "OutsideValue" ); - this->m_DefaultParameters.SetValueAsPoint( "Seed", 3, 0, 0, 0 ); - this->m_DefaultParameters.SetValueAsReal( "InsideValue", 255 ); - this->m_DefaultParameters.SetValueAsReal( "OutsideValue", 0 ); - this->m_Parameters = this->m_DefaultParameters; + double seed[ 3 ] = { double( 0 ) }; + this->m_Parameters->ConfigureAsPoint( "Seed", 3, seed ); + this->m_Parameters->ConfigureAsUint( "InsideValue", 0 ); + this->m_Parameters->ConfigureAsUint( "OutsideValue", 255 ); } // ------------------------------------------------------------------------- @@ -119,9 +115,11 @@ _RealGD( itk::DataObject* image ) typedef itk::FloodFilledImageFunctionConditionalConstIterator< I, _F > _It; typename I::PointType pseed; - pseed = this->m_Parameters.GetValueAsPoint< typename I::PointType >( "Seed" ); - _OP in_val = _OP( this->m_Parameters.GetValueAsReal( "InsideValue" ) ); - _OP out_val = _OP( this->m_Parameters.GetValueAsReal( "OutsideValue" ) ); + pseed = this->m_Parameters->GetPoint< typename I::PointType >( + "Seed", I::ImageDimension + ); + _OP in_val = _OP( this->m_Parameters->GetUint( "InsideValue" ) ); + _OP out_val = _OP( this->m_Parameters->GetUint( "OutsideValue" ) ); const I* in = dynamic_cast< const I* >( image ); typename I::IndexType seed; diff --git a/lib/cpPlugins/Plugins/BasicFilters/MarchingCubes.cxx b/lib/cpPlugins/Plugins/BasicFilters/MarchingCubes.cxx index 9253860..e833675 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/MarchingCubes.cxx +++ b/lib/cpPlugins/Plugins/BasicFilters/MarchingCubes.cxx @@ -15,9 +15,7 @@ MarchingCubes( ) this->SetNumberOfOutputs( 1 ); this->_MakeOutput< cpPlugins::Interface::Mesh >( 0 ); - using namespace cpPlugins::Interface; - this->m_DefaultParameters.Configure( Parameters::RealList, "Thresholds" ); - this->m_Parameters = this->m_DefaultParameters; + this->m_Parameters->ConfigureAsRealList( "Thresholds" ); } // ------------------------------------------------------------------------- @@ -40,7 +38,7 @@ _GenerateData( ) return( "MarchingCubes: Input does not have a valid VTK conversion." ); std::vector< double > values; - this->m_Parameters.GetValueAsRealList( values, "Thresholds" ); + this->m_Parameters->GetRealList( values, "Thresholds" ); vtkPolyData* pd = NULL; if( vtk_image->GetDataDimension( ) == 2 ) { diff --git a/lib/cpPlugins/Plugins/BasicFilters/MedianImageFilter.cxx b/lib/cpPlugins/Plugins/BasicFilters/MedianImageFilter.cxx index 083c6b9..d1205e7 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/MedianImageFilter.cxx +++ b/lib/cpPlugins/Plugins/BasicFilters/MedianImageFilter.cxx @@ -12,12 +12,7 @@ MedianImageFilter( ) this->SetNumberOfOutputs( 1 ); this->_MakeOutput< cpPlugins::Interface::Image >( 0 ); - using namespace cpPlugins::Interface; - this->m_DefaultParameters.Configure( Parameters::Uint, "Radius" ); - - this->m_DefaultParameters.SetValueAsUint( "Radius", 3 ); - - this->m_Parameters = this->m_DefaultParameters; + this->m_Parameters->ConfigureAsUint( "Radius", 3 ); } // ------------------------------------------------------------------------- @@ -66,7 +61,7 @@ _RealGD( itk::DataObject* image ) // Get parameters _RT rad_val; - rad_val.Fill( this->m_Parameters.GetValueAsUint( "Radius" ) ); + rad_val.Fill( this->m_Parameters->GetUint( "Radius" ) ); // Configure filter _F* filter = this->_CreateITK< _F >( ); diff --git a/lib/cpPlugins/Plugins/BasicFilters/OtsuThresholdImageFilter.cxx b/lib/cpPlugins/Plugins/BasicFilters/OtsuThresholdImageFilter.cxx index 59f98f5..65df9e0 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/OtsuThresholdImageFilter.cxx +++ b/lib/cpPlugins/Plugins/BasicFilters/OtsuThresholdImageFilter.cxx @@ -12,16 +12,9 @@ OtsuThresholdImageFilter( ) this->SetNumberOfOutputs( 1 ); this->_MakeOutput< cpPlugins::Interface::Image >( 0 ); - using namespace cpPlugins::Interface; - this->m_DefaultParameters.Configure( - Parameters::Uint, "NumberOfHistogramBins" - ); - this->m_DefaultParameters.Configure( Parameters::Real, "InsideValue" ); - this->m_DefaultParameters.Configure( Parameters::Real, "OutsideValue" ); - this->m_DefaultParameters.SetValueAsUint( "NumberOfHistogramBins", 100 ); - this->m_DefaultParameters.SetValueAsReal( "InsideValue", 255 ); - this->m_DefaultParameters.SetValueAsReal( "OutsideValue", 0 ); - this->m_Parameters = this->m_DefaultParameters; + this->m_Parameters->ConfigureAsUint( "NumberOfHistogramBins", 100 ); + this->m_Parameters->ConfigureAsUint( "InsideValue", 255 ); + this->m_Parameters->ConfigureAsUint( "OutsideValue", 0 ); } // ------------------------------------------------------------------------- @@ -69,10 +62,9 @@ _RealGD( itk::DataObject* image ) typedef typename O::PixelType _OP; // Get parameters - unsigned int bins = - this->m_Parameters.GetValueAsUint( "NumberOfHistogramBins" ); - _OP in_val = _OP( this->m_Parameters.GetValueAsReal( "InsideValue" ) ); - _OP out_val = _OP( this->m_Parameters.GetValueAsReal( "OutsideValue" ) ); + unsigned int bins = this->m_Parameters->GetUint( "NumberOfHistogramBins" ); + _OP in_val = _OP( this->m_Parameters->GetUint( "InsideValue" ) ); + _OP out_val = _OP( this->m_Parameters->GetUint( "OutsideValue" ) ); // Configure filter _F* filter = this->_CreateITK< _F >( ); diff --git a/lib/cpPlugins/Plugins/BasicFilters/RGBImageToOtherChannelsFilter.cxx b/lib/cpPlugins/Plugins/BasicFilters/RGBImageToOtherChannelsFilter.cxx index 5282f60..31bd0fc 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/RGBImageToOtherChannelsFilter.cxx +++ b/lib/cpPlugins/Plugins/BasicFilters/RGBImageToOtherChannelsFilter.cxx @@ -17,8 +17,10 @@ RGBImageToOtherChannelsFilter( ) this->SetNumberOfOutputs( 1 ); this->_MakeOutput< cpPlugins::Interface::Image >( 0 ); - this->m_DefaultParameters.Configure( TParameters::String, "OutChannel" ); - this->m_Parameters = this->m_DefaultParameters; + std::vector< std::string > choices; + choices.push_back( "HSV" ); + choices.push_back( "YPbPr" ); + this->m_Parameters->ConfigureAsChoices( "OutChannel", choices ); } // ------------------------------------------------------------------------- @@ -52,7 +54,7 @@ _GD0( itk::DataObject* image ) { typedef typename I::PixelType _P; - std::string outc = this->m_Parameters.GetValueAsString( "OutChannel" ); + std::string outc = this->m_Parameters->GetSelectedChoice( "OutChannel" ); std::string r = ""; using namespace cpExtensions::Algorithms; diff --git a/lib/cpPlugins/Plugins/BasicFilters/SphereMeshSource.cxx b/lib/cpPlugins/Plugins/BasicFilters/SphereMeshSource.cxx index 8ba50cc..78aff5f 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/SphereMeshSource.cxx +++ b/lib/cpPlugins/Plugins/BasicFilters/SphereMeshSource.cxx @@ -14,16 +14,11 @@ SphereMeshSource( ) this->SetNumberOfOutputs( 1 ); this->_MakeOutput< cpPlugins::Interface::Mesh >( 0 ); - using namespace cpPlugins::Interface; - this->m_DefaultParameters.Configure( Parameters::Point, "Center" ); - this->m_DefaultParameters.Configure( Parameters::Real, "Radius" ); - this->m_DefaultParameters.Configure( Parameters::Uint, "PhiResolution" ); - this->m_DefaultParameters.Configure( Parameters::Uint, "ThetaResolution" ); - this->m_DefaultParameters.SetValueAsPoint( "Center", 3, 0, 0, 0 ); - this->m_DefaultParameters.SetValueAsReal( "Radius", 1 ); - this->m_DefaultParameters.SetValueAsUint( "PhiResolution", 10 ); - this->m_DefaultParameters.SetValueAsUint( "ThetaResolution", 10 ); - this->m_Parameters = this->m_DefaultParameters; + double point[ 3 ] = { double( 0 ) }; + this->m_Parameters->ConfigureAsPoint( "Center", 3, point ); + this->m_Parameters->ConfigureAsReal( "Radius", 1 ); + this->m_Parameters->ConfigureAsUint( "PhiResolution", 8 ); + this->m_Parameters->ConfigureAsUint( "ThetaResolution", 8 ); } // ------------------------------------------------------------------------- @@ -37,11 +32,11 @@ std::string cpPlugins::BasicFilters::SphereMeshSource:: _GenerateData( ) { itk::Point< double, 3 > center = - this->m_Parameters.GetValueAsPoint< itk::Point< double, 3 > >( "Center" ); - center.Fill( double( 0 ) ); // TODO - double radius = this->m_Parameters.GetValueAsReal( "Radius" ); - unsigned int phi = this->m_Parameters.GetValueAsUint( "PhiResolution" ); - unsigned int theta = this->m_Parameters.GetValueAsUint( "ThetaResolution" ); + this->m_Parameters->GetPoint< itk::Point< double, 3 > >( "Center", 3 ); + // TODO: center.Fill( double( 0 ) ); // TODO + double radius = this->m_Parameters->GetReal( "Radius" ); + unsigned int phi = this->m_Parameters->GetUint( "PhiResolution" ); + unsigned int theta = this->m_Parameters->GetUint( "ThetaResolution" ); vtkSphereSource* src = this->_CreateVTK< vtkSphereSource >( ); src->SetCenter( center[ 0 ], center[ 1 ], center[ 2 ] ); diff --git a/lib/cpPlugins/Plugins/CMakeLists.txt b/lib/cpPlugins/Plugins/CMakeLists.txt index f0ab717..6fe1263 100644 --- a/lib/cpPlugins/Plugins/CMakeLists.txt +++ b/lib/cpPlugins/Plugins/CMakeLists.txt @@ -1,6 +1,6 @@ SUBDIRS( IO - ## BasicFilters + BasicFilters ) ## eof - $RCSfile$ diff --git a/lib/cpPlugins/Plugins/IO/ImageReader.cxx b/lib/cpPlugins/Plugins/IO/ImageReader.cxx index 60b33b6..48deb00 100644 --- a/lib/cpPlugins/Plugins/IO/ImageReader.cxx +++ b/lib/cpPlugins/Plugins/IO/ImageReader.cxx @@ -367,11 +367,13 @@ _RealGD( const TStringList& names ) { reader->Update( ); out->SetITK< I >( reader->GetOutput( ) ); + out->SetName( names[ 0 ] ); } catch( itk::ExceptionObject& err ) { r = "ImageReader: " + std::string( err.GetDescription( ) ); out->SetITK< I >( NULL ); + out->SetName( "" ); } // yrt } @@ -391,11 +393,13 @@ _RealGD( const TStringList& names ) { reader->Update( ); out->SetITK< I >( reader->GetOutput( ) ); + out->SetName( *( ordered_names.begin( ) ) ); } catch( itk::ExceptionObject& err ) { r = "ImageReader: " + std::string( err.GetDescription( ) ); out->SetITK< I >( NULL ); + out->SetName( "" ); } // yrt } diff --git a/lib/cpPlugins/Plugins/IO/ImageWriter.cxx b/lib/cpPlugins/Plugins/IO/ImageWriter.cxx index 7dd1313..2b4d897 100644 --- a/lib/cpPlugins/Plugins/IO/ImageWriter.cxx +++ b/lib/cpPlugins/Plugins/IO/ImageWriter.cxx @@ -22,6 +22,39 @@ cpPlugins::IO::ImageWriter:: // ------------------------------------------------------------------------- std::string cpPlugins::IO::ImageWriter:: _GenerateData( ) +{ + // Thank you very much Microsoft !!! :-@ + std::string r = this->_GD0_Image< 2 >( ); + if( r != "" ) r = this->_GD0_Image< 3 >( ); + if( r != "" ) r = this->_GD0_Image< 4 >( ); + if( r != "" ) r = this->_GD0_VectorImage< 2 >( ); + if( r != "" ) r = this->_GD0_VectorImage< 3 >( ); + if( r != "" ) r = this->_GD0_VectorImage< 4 >( ); + return( r ); +} + +// ------------------------------------------------------------------------- +template< unsigned int D > +std::string cpPlugins::IO::ImageWriter:: +_GD0_Image( ) +{ + cpPlugins::Interface::Image* image = + this->GetInput< cpPlugins::Interface::Image >( 0 ); + if( image == NULL ) + return( "ImageWriter: No input image." ); + + itk::DataObject* itk_image = NULL; + std::string r = ""; + cpPlugins_Image_Demangle_AllTypes( D, image, itk_image, r, _RealGD ); + else r = "ImageWriter: Input image type not supported."; + + return( r ); +} + +// ------------------------------------------------------------------------- +template< unsigned int D > +std::string cpPlugins::IO::ImageWriter:: +_GD0_VectorImage( ) { cpPlugins::Interface::Image* image = this->GetInput< cpPlugins::Interface::Image >( 0 ); @@ -30,12 +63,7 @@ _GenerateData( ) itk::DataObject* itk_image = NULL; std::string r = ""; - cpPlugins_Image_Demangle_AllTypes( 2, image, itk_image, r, _RealGD ); - else cpPlugins_Image_Demangle_AllTypes( 3, image, itk_image, r, _RealGD ); - else cpPlugins_Image_Demangle_AllTypes( 4, image, itk_image, r, _RealGD ); - else cpPlugins_VectorImage_Demangle_AllTypes( 2, image, itk_image, r, _RealGD ); - else cpPlugins_VectorImage_Demangle_AllTypes( 3, image, itk_image, r, _RealGD ); - else cpPlugins_VectorImage_Demangle_AllTypes( 4, image, itk_image, r, _RealGD ); + cpPlugins_VectorImage_Demangle_AllTypes( D, image, itk_image, r, _RealGD ); else r = "ImageWriter: Input image type not supported."; return( r ); diff --git a/lib/cpPlugins/Plugins/IO/ImageWriter.h b/lib/cpPlugins/Plugins/IO/ImageWriter.h index 2d72067..2c97de9 100644 --- a/lib/cpPlugins/Plugins/IO/ImageWriter.h +++ b/lib/cpPlugins/Plugins/IO/ImageWriter.h @@ -32,6 +32,15 @@ namespace cpPlugins virtual std::string _GenerateData( ); + /* + * These two methods are Microsort courtesy: inner loop error ! + */ + template< unsigned int D > + inline std::string _GD0_Image( ); + + template< unsigned int D > + inline std::string _GD0_VectorImage( ); + template< class I > inline std::string _RealGD( itk::DataObject* image ); diff --git a/lib/third_party/Pluma/DLibrary.cpp b/lib/third_party/Pluma/DLibrary.cpp index 9b617db..923d825 100644 --- a/lib/third_party/Pluma/DLibrary.cpp +++ b/lib/third_party/Pluma/DLibrary.cpp @@ -29,6 +29,7 @@ #include #include #include +#include namespace pluma{ @@ -36,7 +37,8 @@ namespace pluma{ //////////////////////////////////////////////////////////// DLibrary* DLibrary::load(const std::string& path){ if ( path.empty() ){ - fprintf(stderr, "Failed to load library: Empty path\n"); + // fprintf(stderr, "Failed to load library: Empty path\n"); + throw std::runtime_error( "Failed to load library: Empty path." ); return NULL; } void* handle = NULL; @@ -45,16 +47,23 @@ DLibrary* DLibrary::load(const std::string& path){ #ifdef PLUMA_SYS_WINDOWS handle = ::LoadLibraryA(path.c_str()); if (!handle){ - fprintf(stderr, "Failed to load library \"%s\".\n", path.c_str()); - return NULL; + //fprintf(stderr, "Failed to load library \"%s\".\n", path.c_str()); + throw std::runtime_error( + std::string( "Failed to load library \"" ) + + path + + std::string( "\"." ); + ); + return NULL; } #else handle = ::dlopen(path.c_str(), RTLD_NOW); if (!handle){ const char* errorString = ::dlerror(); - fprintf(stderr, "Failed to load library \"%s\".", path.c_str()); - if(errorString) fprintf(stderr, " OS returned error: \"%s\".", errorString); - fprintf(stderr, "\n"); + std::string error_text = "Failed to load library \""; + // fprintf(stderr, "Failed to load library \"%s\".", path.c_str()); + if(errorString) error_text += std::string( errorString ); // fprintf(stderr, " OS returned error: \"%s\".", errorString); + // fprintf(stderr, "\n"); + throw std::runtime_error( error_text + std::string( "\"." ) ); return NULL; } #endif @@ -78,7 +87,8 @@ DLibrary::~DLibrary(){ //////////////////////////////////////////////////////////// void* DLibrary::getSymbol(const std::string& symbol){ if (!handle){ - fprintf(stderr, "Cannot inspect library symbols, library isn't loaded.\n"); + //fprintf(stderr, "Cannot inspect library symbols, library isn't loaded.\n"); + throw std::runtime_error( "Cannot inspect library symbols, library isn't loaded." ); return NULL; } void* res; @@ -88,8 +98,13 @@ void* DLibrary::getSymbol(const std::string& symbol){ res = (void*)(::dlsym(handle, symbol.c_str())); #endif if (!res){ - fprintf(stderr, "Library symbol \"%s\" not found.\n", symbol.c_str()); - return NULL; + // fprintf(stderr, "Library symbol \"%s\" not found.\n", symbol.c_str()); + throw std::runtime_error( + std::string( "Library symbol \"" ) + + symbol + + std::string( "\" not found." ) + ); + return NULL; } return res; } diff --git a/lib/third_party/Pluma/Dir.cpp b/lib/third_party/Pluma/Dir.cpp index 860220e..b0494b7 100644 --- a/lib/third_party/Pluma/Dir.cpp +++ b/lib/third_party/Pluma/Dir.cpp @@ -30,6 +30,7 @@ #include #include #include +#include namespace pluma{ @@ -46,7 +47,12 @@ void listFiles(std::list& list, const std::string& folder, const st dir = opendir(folder.c_str()); if (dir == NULL){ // could not open directory - fprintf(stderr, "Could not open \"%s\" directory.\n", folder.c_str()); + // fprintf(stderr, "Could not open \"%s\" directory.\n", folder.c_str()); + throw std::runtime_error( + std::string( "Could not open \"" ) + + folder + + std::string( "\" directory." ) + ); return; }else{ // close, we'll process it next diff --git a/lib/third_party/Pluma/Host.cpp b/lib/third_party/Pluma/Host.cpp index eb37c33..6fb5539 100644 --- a/lib/third_party/Pluma/Host.cpp +++ b/lib/third_party/Pluma/Host.cpp @@ -28,6 +28,7 @@ //////////////////////////////////////////////////////////// #include #include +#include namespace pluma{ @@ -41,7 +42,8 @@ Host::Host(){ //////////////////////////////////////////////////////////// bool Host::add(Provider* provider){ if (provider == NULL){ - fprintf(stderr, "Trying to add a null provider.\n"); + //fprintf(stderr, "Trying to add a null provider.\n"); + throw std::runtime_error( "Trying to add a null provider." ); return false; } if (!validateProvider(provider)){ @@ -122,11 +124,19 @@ const std::list* Host::getProviders(const std::string& type) const{ bool Host::validateProvider(Provider* provider) const{ const std::string& type = provider->plumaGetType(); if ( !knows(type) ){ - fprintf(stderr, "%s provider type isn't registered.\n", type.c_str()); + // fprintf(stderr, "%s provider type isn't registered.\n", type.c_str()); + throw std::runtime_error( + type + std::string( " provider type isn't registered." ) + ); return false; } if (!provider->isCompatible(*this)){ - fprintf(stderr, "Incompatible %s provider version.\n", type.c_str()); + // fprintf(stderr, "Incompatible %s provider version.\n", type.c_str()); + throw std::runtime_error( + std::string( "Incompatible " ) + + type + + std::string( " provider version." ) + ); return false; } return true; diff --git a/lib/third_party/Pluma/PluginManager.cpp b/lib/third_party/Pluma/PluginManager.cpp index 9579da2..491a1a9 100644 --- a/lib/third_party/Pluma/PluginManager.cpp +++ b/lib/third_party/Pluma/PluginManager.cpp @@ -30,6 +30,7 @@ #include #include #include +#include namespace pluma{ @@ -56,16 +57,26 @@ bool PluginManager::load(const std::string& path){ registerFunction = reinterpret_cast(lib->getSymbol("connect")); if(!registerFunction){ - fprintf(stderr, "Failed to initialize plugin \"%s\": connect function not found\n", plugName.c_str()); + //fprintf(stderr, "Failed to initialize plugin \"%s\": connect function not found\n", plugName.c_str()); delete lib; + throw std::runtime_error( + std::string( "Failed to initialize plugin \"" ) + + plugName + + std::string( "\": connect function not found" ) + ); return false; } // try to initialize plugin: if (!registerFunction(host)){ // plugin decided to fail - fprintf(stderr, "Self registry failed on plugin \"%s\".\n", plugName.c_str()); + // fprintf(stderr, "Self registry failed on plugin \"%s\".\n", plugName.c_str()); host.cancelAddictions(); delete lib; + throw std::runtime_error( + std::string( "Self registry failed on plugin \"" ) + + plugName + + std::string( "\"" ) + ); return false; } // Store the library if addictions are confirmed @@ -73,8 +84,13 @@ bool PluginManager::load(const std::string& path){ libraries[plugName] = lib; else{ // otherwise nothing was registered - fprintf(stderr, "Nothing registered by plugin \"%s\".\n", plugName.c_str()); + // fprintf(stderr, "Nothing registered by plugin \"%s\".\n", plugName.c_str()); delete lib; + throw std::runtime_error( + std::string( "Nothing registered by plugin \"" ) + + plugName + + std::string( "\"." ) + ); return false; } return true; @@ -166,7 +182,8 @@ void PluginManager::registerType(const std::string& type, unsigned int version, //////////////////////////////////////////////////////////// bool PluginManager::addProvider(Provider* provider){ if (provider == NULL){ - fprintf(stderr, "Trying to add null provider\n"); + // fprintf(stderr, "Trying to add null provider\n"); + throw std::runtime_error( "Trying to add null provider." ); return false; } return host.registerProvider(provider); -- 2.45.1