## = 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)
@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$
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)
<Who else?>
@description
IF(USE_QT4)
+ CONFIGURE_FILE(
+ Plugins.cfg.in
+ ${PROJECT_BINARY_DIR}/Plugins.cfg
+ @ONLY
+ )
+
## ====================================================
## = Source code, user interafaces and resources here =
## ====================================================
SET(
App_QT_SOURCES
- ImageMPR.cxx
+ ImageMPR.cxx
)
SET(
App_SOURCES
- MementoState.cxx
- main.cxx
+ MementoState.cxx
+ main.cxx
)
SET(
App_QT_HEADERS
)
SET(
App_HEADERS
- MementoState.h
+ MementoState.h
)
FILE(GLOB App_QT_UI "${App_SOURCE_DIR}/*.ui")
FILE(GLOB App_QT_RES "${App_SOURCE_DIR}/*.qrc")
#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( "" ),
+ m_Flooding( false )
+{
+ this->m_UI->setupUi( this );
+
+ // Associate callbacks
+ this->m_UI->MPR->AddCursorCommand( Self::_CursorCommand, 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( );
+
+ if( name == "cpPlugins::BasicFilters::FloodFillImageFilter" )
+ {
+ this->m_Flooding = true;
+ }
+ else
+ {
+ this->m_Flooding = false;
+ this->m_UI->MPR->ExecuteFilter(
+ name, this->m_ImageLoaded, "SegmentedImage"
+ );
+
+ } // fi
+
+ // 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( ) )
+ );
+ */
+}
+
+// -------------------------------------------------------------------------
+void ImageMPR::
+_CursorCommand( double* pos, int axis, void* data )
+{
+ Self* app = reinterpret_cast< Self* >( data );
+ if( app == NULL )
+ return;
+ if( !( app->m_Flooding ) )
+ return;
+
+ cpPlugins::Interface::ProcessObject::Pointer filter =
+ app->m_UI->MPR->CreateFilter(
+ "cpPlugins::BasicFilters::FloodFillImageFilter"
+ );
+ if( filter.IsNull( ) )
+ return;
+
+ cpPlugins::Interface::Parameters* params = filter->GetParameters( );
+ params->SetPoint( "Seed", 3, pos );
+ params->SetReal( "Window", app->m_UI->MPR->GetWindow( ) );
+ params->SetReal( "Level", app->m_UI->MPR->GetLevel( ) );
+ params->SetUint( "InsideValue", 1 );
+ params->SetUint( "OutsideValue", 0 );
+ filter->SetInput( "Input", app->m_UI->MPR->GetImage( app->m_ImageLoaded ) );
+ app->m_UI->MPR->Block( );
+ std::string err = filter->Update( );
+ cpPlugins::Interface::BaseMPRWindow::TImage::Pointer image = filter->GetOutput< cpPlugins::Interface::BaseMPRWindow::TImage >( "Output" );
+ filter->DisconnectOutputs( );
+ app->m_UI->MPR->AddImage( "Segmentation", image );
+ app->m_UI->MPR->Unblock( );
+
+
+
+ /* TODO
+ std::cout
+ << "CursorCommand ==> "
+ << pos[ 0 ] << " "
+ << pos[ 1 ] << " "
+ << pos[ 2 ] << " : "
+ << axis << " "
+ << data << std::endl;
+ */
+}
+
+/*
+#include "MementoState.h"
+
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkMetaImageReader.h>
}
+*/
// eof - $RCSfile$
Q_OBJECT;
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 ImageMPR Self;
+ typedef QMainWindow Superclass;
typedef cpExtensions::Visualization::MPRObjects TMPRObjects;
+ typedef TMPRObjects::TCursorCommand TCursorCommand;
+ typedef TMPRObjects::TMouseCommand TMouseCommand;
+ typedef TMPRObjects::TMouseWheelCommand TMouseWheelCommand;
+ typedef TMPRObjects::TKeyCommand TKeyCommand;
+
+ // 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;
+ */
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( );
+
+protected:
+ // Callbacks
+ static void _CursorCommand( double* pos, int axis, void* data );
+
private:
Ui::ImageMPR* m_UI;
+ // Some state flags
+ std::string m_ImageLoaded;
+ bool m_Flooding;
+
// 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;
</size>
</property>
<property name="windowTitle">
- <string>Interactive deformable mesh segmentation (v0.1)</string>
+ <string>ImageMPR (v0.1)</string>
</property>
- <widget class="QWidget" name="centralWidget">
+ <widget class="QWidget" name="CentralWidget">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
- <widget class="QSplitter" name="splitter_4">
- <property name="minimumSize">
- <size>
- <width>700</width>
- <height>400</height>
- </size>
- </property>
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <widget class="QSplitter" name="splitter_3">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <widget class="QSplitter" name="splitter">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <widget class="QVTKWidget" name="m_YPlaneVTK" native="true">
- <property name="enabled">
- <bool>true</bool>
- </property>
- <property name="minimumSize">
- <size>
- <width>200</width>
- <height>200</height>
- </size>
- </property>
- </widget>
- <widget class="QVTKWidget" name="m_XPlaneVTK" native="true">
- <property name="enabled">
- <bool>true</bool>
- </property>
- <property name="minimumSize">
- <size>
- <width>200</width>
- <height>200</height>
- </size>
- </property>
- </widget>
- </widget>
- <widget class="QSplitter" name="splitter_2">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <widget class="QVTKWidget" name="m_ZPlaneVTK" native="true">
- <property name="enabled">
- <bool>true</bool>
- </property>
- <property name="minimumSize">
- <size>
- <width>200</width>
- <height>200</height>
- </size>
- </property>
- </widget>
- <widget class="QVTKWidget" name="m_3DVTK" native="true">
- <property name="enabled">
- <bool>true</bool>
- </property>
- <property name="minimumSize">
- <size>
- <width>200</width>
- <height>200</height>
- </size>
- </property>
- </widget>
- </widget>
- </widget>
- </widget>
+ <widget class="cpPlugins::Interface::BaseMPRWindow" name="MPR"/>
</item>
</layout>
</widget>
- <widget class="QMenuBar" name="menuBar">
+ <widget class="QMenuBar" name="MenuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>718</width>
- <height>21</height>
+ <height>25</height>
</rect>
</property>
- <widget class="QMenu" name="menuFile">
+ <widget class="QMenu" name="MenuOptionFile">
<property name="title">
<string>&File</string>
</property>
- <addaction name="actionOpenPlugins"/>
+ <addaction name="aOpenImage"/>
+ <addaction name="aOpenSegmentation"/>
+ <addaction name="aOpenPolyData"/>
<addaction name="separator"/>
- <addaction name="actionOpenInputImage"/>
- <addaction name="actionOpenSegmentation"/>
- <addaction name="actionOpenInputPolyData"/>
+ <addaction name="aSaveImage"/>
+ <addaction name="aSaveSegmentation"/>
+ <addaction name="aSavePolyData"/>
<addaction name="separator"/>
- <addaction name="actionExit"/>
+ <addaction name="aExit"/>
</widget>
- <widget class="QMenu" name="MenuImageToImage">
+ <widget class="QMenu" name="MenuOptionEdit">
<property name="title">
- <string>Image to image</string>
+ <string>&Edit</string>
</property>
+ <widget class="QMenu" name="MenuOptionPlugins">
+ <property name="title">
+ <string>&Plugins</string>
+ </property>
+ <addaction name="aLoadPlugins"/>
+ <addaction name="aShowPlugins"/>
+ </widget>
+ <addaction name="aUndo"/>
+ <addaction name="aRedo"/>
+ <addaction name="separator"/>
+ <addaction name="MenuOptionPlugins"/>
</widget>
- <widget class="QMenu" name="MenuImageToMesh">
+ <widget class="QMenu" name="MenuOptionHelp">
<property name="title">
- <string>Image to mesh</string>
+ <string>&Help</string>
</property>
</widget>
- <widget class="QMenu" name="menuEdit">
+ <widget class="QMenu" name="MenuFilters">
<property name="title">
- <string>Edit</string>
+ <string>&Filters</string>
</property>
- <addaction name="actionUndo"/>
- <addaction name="actionRedo"/>
</widget>
- <addaction name="menuFile"/>
- <addaction name="menuEdit"/>
- <addaction name="MenuImageToImage"/>
- <addaction name="MenuImageToMesh"/>
+ <addaction name="MenuOptionFile"/>
+ <addaction name="MenuOptionEdit"/>
+ <addaction name="MenuFilters"/>
+ <addaction name="MenuOptionHelp"/>
</widget>
- <action name="actionOpenInputImage">
+ <widget class="QStatusBar" name="StatusBar"/>
+ <action name="aOpenImage">
<property name="enabled">
<bool>true</bool>
</property>
<string>Ctrl+O</string>
</property>
</action>
- <action name="actionOpenPlugins">
- <property name="enabled">
- <bool>true</bool>
+ <action name="aExit">
+ <property name="text">
+ <string>Exit</string>
</property>
+ </action>
+ <action name="aOpenPolyData">
<property name="text">
- <string>Open plugins</string>
+ <string>Open polydata</string>
</property>
<property name="shortcut">
- <string>Ctrl+P</string>
+ <string>Ctrl+M</string>
</property>
</action>
- <action name="actionExit">
+ <action name="aOpenSegmentation">
<property name="text">
- <string>Exit</string>
+ <string>Open segmentation</string>
+ </property>
+ <property name="shortcut">
+ <string>Ctrl+S</string>
</property>
</action>
- <action name="actionOpenInputPolyData">
+ <action name="aUndo">
<property name="text">
- <string>Open polydata</string>
+ <string>&Undo</string>
</property>
<property name="shortcut">
- <string>Ctrl+M</string>
+ <string>Ctrl+Z</string>
</property>
</action>
- <action name="actionDasdasd">
+ <action name="aRedo">
<property name="text">
- <string>dasdasd</string>
+ <string>&Redo</string>
+ </property>
+ <property name="shortcut">
+ <string>Ctrl+Y</string>
</property>
</action>
- <action name="actionOpenSegmentation">
+ <action name="aLoadPlugins">
<property name="text">
- <string>Open segmentation</string>
+ <string>Load plugins</string>
+ </property>
+ <property name="shortcut">
+ <string>Ctrl+P</string>
</property>
</action>
- <action name="actionUndo">
+ <action name="aShowPlugins">
<property name="text">
- <string>Undo</string>
+ <string>Show plugins</string>
</property>
<property name="shortcut">
- <string>Ctrl+Z</string>
+ <string>Ctrl+H</string>
</property>
</action>
- <action name="actionRedo">
+ <action name="aSaveImage">
<property name="text">
- <string>Redo</string>
+ <string>Save image</string>
</property>
<property name="shortcut">
- <string>Ctrl+Y</string>
+ <string>Ctrl+Shift+I</string>
+ </property>
+ </action>
+ <action name="aSaveSegmentation">
+ <property name="text">
+ <string>Save segmentation</string>
+ </property>
+ <property name="shortcut">
+ <string>Ctrl+Shift+S</string>
+ </property>
+ </action>
+ <action name="aSavePolyData">
+ <property name="text">
+ <string>Save polydata</string>
+ </property>
+ <property name="shortcut">
+ <string>Ctrl+Shift+M</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
- <class>QVTKWidget</class>
- <extends>QWidget</extends>
- <header>QVTKWidget.h</header>
+ <class>cpPlugins::Interface::BaseMPRWindow</class>
+ <extends>QFrame</extends>
+ <header location="global">cpPlugins/Interface/BaseMPRWindow.h</header>
+ <container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
- <sender>actionExit</sender>
+ <sender>aExit</sender>
<signal>triggered()</signal>
<receiver>ImageMPR</receiver>
<slot>close()</slot>
// -------------------------------------------------------------------------
MementoState::MementoState(long id, TPluginImage* _img)
{
- char * base = "state";
+ char base[] = "state";
std::ostringstream oss;
oss << id;
std::string str = oss.str();
vtkSmartPointer<vtkMetaImageReader>
MementoState::getMemento(long id)
{
- char * base = "state";
+ char base[] = "state";
std::ostringstream oss;
oss << id;
std::string str = oss.str();
// -------------------------------------------------------------------------
void MementoState::
save(const std::string& filename, const std::string& filenameRaw, TPluginImage* img) {
+ /* TODO
vtkSmartPointer<vtkMetaImageWriter> writer =
vtkSmartPointer<vtkMetaImageWriter>::New();
writer->SetInputData(img->GetVTK< vtkImageData >());
writer->SetFileName(filename.c_str());
writer->SetRAWFileName(filenameRaw.c_str());
writer->Write();
+ */
}
// -------------------------------------------------------------------------
vtkSmartPointer<vtkMetaImageReader>
MementoState::load(const std::string& filename) {
+ /* TODO
vtkSmartPointer<vtkMetaImageReader> reader =
vtkSmartPointer<vtkMetaImageReader>::New();
reader->SetFileName(filename.c_str());
reader->Update();
return reader;
+ */
+return( NULL );
}
// eof - $RCSfile$
--- /dev/null
+@CMAKE_SHARED_LIBRARY_PREFIX@cpPluginsIO@CMAKE_SHARED_LIBRARY_SUFFIX@
+@CMAKE_SHARED_LIBRARY_PREFIX@cpPluginsBasicFilters@CMAKE_SHARED_LIBRARY_SUFFIX@
## =========================
SET(
- EXAMPLES_PROGRAMS
+ EXAMPLES_PROGRAMS_ONLY_EXTENSIONS
+ example_TestQuadSplitter
+ )
+
+FOREACH(prog ${EXAMPLES_PROGRAMS_ONLY_EXTENSIONS})
+ ADD_EXECUTABLE(${prog} ${prog}.cxx)
+ TARGET_LINK_LIBRARIES(${prog} cpExtensions)
+ENDFOREACH(prog)
+
+SET(
+ EXAMPLES_PROGRAMS_ONLY_INTERFACE
example_TestParameters
example_LoadPlugins
- example_ReadWriteImage
- example_View2DImage
- example_Test_async
+ )
+
+FOREACH(prog ${EXAMPLES_PROGRAMS_ONLY_INTERFACE})
+ ADD_EXECUTABLE(${prog} ${prog}.cxx)
+ TARGET_LINK_LIBRARIES(${prog} cpPlugins_Interface)
+ENDFOREACH(prog)
+
+SET(
+ EXAMPLES_PROGRAMS_WITH_PLUGINS
+ #example_ReadWriteImage
+ #example_MPR
+ #example_View2DImage
##example_MarchingCubes
##example_OtsuFilter
##example_RGBImageToHSVChannels
##example_MPR
)
-
-FOREACH(prog ${EXAMPLES_PROGRAMS})
+FOREACH(prog ${EXAMPLES_PROGRAMS_WITH_PLUGINS})
ADD_EXECUTABLE(
${prog}
${prog}.cxx
NOPLUGINS_EXAMPLES_PROGRAMS
example_BaseInteractorStyle
example_ContourWidget
+ example_Test_async
## example_Test_DoubleClick
## example_ExtractDICOMSeries
## example_ImageGaussianModelEstimator
}
virtual void Execute( vtkObject* caller, unsigned long eId , void* data )
{
+ /*
vtkSliderWidget* wdg =
reinterpret_cast< vtkSliderWidget* >( caller );
if( wdg == NULL )
this->Actors->SetWindow( 0, rep->GetValue( ) );
else if( title == "Level" )
this->Actors->SetLevel( 0, rep->GetValue( ) );
+ */
}
SliderCallback( )
: vtkCommand( )
// Create reader
TFilter::Pointer reader =
- plugins.CreateProcessObject( "cpPlugins::ImageReader" );
+ plugins.CreateProcessObject( "cpPlugins::IO::ImageReader" );
if( reader.IsNull( ) )
{
- std::cerr << "No suitable image reader found in plugins." << std::endl;
+ std::cerr
+ << "ERROR: No suitable image reader found in plugins."
+ << std::endl;
return( 1 );
} // fi
// Configure reader
- TParameters reader_params = reader->GetDefaultParameters( );
+ TParameters* reader_params = reader->GetParameters( );
for( int i = 2; i < argc; ++i )
- reader_params.AddValueToStringList( "FileNames", argv[ i ] );
- reader->SetParameters( reader_params );
+ reader_params->AddToStringList( "FileNames", argv[ i ] );
// Execute reader
std::string msg = reader->Update( );
} // fi
// Get input image's vtk representation
- vtkImageData* image = reader->GetOutput< TImage >( 0 )->GetVTKImageData( );
+ vtkImageData* image =
+ reader->GetOutput< TImage >( "Output" )->GetVTK< vtkImageData >( );
if( image == NULL )
{
std::cerr
// Renderers
vtkSmartPointer< vtkRenderer > renderer =
vtkSmartPointer< vtkRenderer >::New( );
+ renderer->SetBackground( 0, 0, 1 );
window->AddRenderer( renderer );
// Interactor
vtkSmartPointer< TMPRActors > mpr_actors =
vtkSmartPointer< TMPRActors >::New( );
mpr_actors->AddInputData( image );
- mpr_actors->PushDataInto( NULL, NULL, NULL, renderer );
+ mpr_actors->PushActorsInto( NULL, NULL, NULL, window );
// Callbacks
vtkSmartPointer< SliderCallback > cb =
vtkSmartPointer< SliderCallback >::New( );
cb->Actors = mpr_actors;
+ /*
Slider x_slider(
mpr_actors->GetSliceNumberMinValue( 0 ),
mpr_actors->GetSliceNumberMaxValue( 0 ),
"Level", interactor,
0.300, 0.05, 0.490, 0.05, cb
);
+ */
// Begin interaction
renderer->ResetCamera( );
typedef itk::Index< 3 > TIndex;
typedef itk::Point< float, 3 > TPoint;
- TParameters parameters;
-
- parameters.Configure( TParameters::String, "StringParam" );
- parameters.Configure( TParameters::Bool, "BoolParam" );
- parameters.Configure( TParameters::Int, "IntParam" );
- parameters.Configure( TParameters::Uint, "UintParam" );
- parameters.Configure( TParameters::Real, "RealParam" );
- parameters.Configure( TParameters::Index, "IndexParam" );
- parameters.Configure( TParameters::Point, "PointParam" );
- parameters.Configure( TParameters::StringList, "StringListParam" );
- parameters.Configure( TParameters::BoolList, "BoolListParam" );
- parameters.Configure( TParameters::IntList, "IntListParam" );
- parameters.Configure( TParameters::UintList, "UintListParam" );
- parameters.Configure( TParameters::RealList, "RealListParam" );
- parameters.Configure( TParameters::IndexList, "IndexListParam" );
- parameters.Configure( TParameters::PointList, "PointListParam" );
-
- parameters.SetValueAsString( "StringParam", "test_value" );
- parameters.SetValueAsBool( "BoolParam", true );
- parameters.SetValueAsInt( "IntParam", -1234567 );
- parameters.SetValueAsUint( "UintParam", 1234567 );
- parameters.SetValueAsReal( "RealParam", 3.14159244444 );
- parameters.SetValueAsIndex( "IndexParam", 3, 4, -3, 2 );
- parameters.SetValueAsPoint( "PointParam", 3, 9.4, 8.3, 7.2 );
-
- parameters.ClearStringList( "StringListParam" );
- parameters.ClearBoolList( "BoolListParam" );
- parameters.ClearIntList( "IntListParam" );
- parameters.ClearUintList( "UintListParam" );
- parameters.ClearRealList( "RealListParam" );
- parameters.ClearIndexList( "IndexListParam" );
- parameters.ClearPointList( "PointListParam" );
-
- parameters.AddValueToStringList( "StringListParam", "one" );
- parameters.AddValueToStringList( "StringListParam", "two" );
- parameters.AddValueToStringList( "StringListParam", "three" );
- parameters.AddValueToStringList( "StringListParam", "four" );
-
- parameters.AddValueToBoolList( "BoolListParam", 1 );
- parameters.AddValueToBoolList( "BoolListParam", 0 );
- parameters.AddValueToBoolList( "BoolListParam", 0 );
- parameters.AddValueToBoolList( "BoolListParam", 1 );
- parameters.AddValueToBoolList( "BoolListParam", 1 );
-
- parameters.AddValueToIntList( "IntListParam", 1 );
- parameters.AddValueToIntList( "IntListParam", -2 );
- parameters.AddValueToIntList( "IntListParam", 3 );
- parameters.AddValueToIntList( "IntListParam", -4 );
- parameters.AddValueToIntList( "IntListParam", 5 );
- parameters.AddValueToIntList( "IntListParam", -6 );
- parameters.AddValueToIntList( "IntListParam", 7 );
- parameters.AddValueToIntList( "IntListParam", -8 );
- parameters.AddValueToIntList( "IntListParam", 9 );
- parameters.AddValueToIntList( "IntListParam", -10 );
- parameters.AddValueToIntList( "IntListParam", 11 );
-
- parameters.AddValueToUintList( "UintListParam", 1 );
- parameters.AddValueToUintList( "UintListParam", 2 );
- parameters.AddValueToUintList( "UintListParam", 3 );
- parameters.AddValueToUintList( "UintListParam", 4 );
- parameters.AddValueToUintList( "UintListParam", 5 );
- parameters.AddValueToUintList( "UintListParam", 6 );
- parameters.AddValueToUintList( "UintListParam", 7 );
- parameters.AddValueToUintList( "UintListParam", 8 );
- parameters.AddValueToUintList( "UintListParam", 9 );
- parameters.AddValueToUintList( "UintListParam", 10 );
- parameters.AddValueToUintList( "UintListParam", 11 );
-
- parameters.AddValueToRealList( "RealListParam", 1.9 );
- parameters.AddValueToRealList( "RealListParam", 2.8 );
- parameters.AddValueToRealList( "RealListParam", 3.7 );
- parameters.AddValueToRealList( "RealListParam", 4.6 );
- parameters.AddValueToRealList( "RealListParam", 5.5 );
- parameters.AddValueToRealList( "RealListParam", 6.4 );
- parameters.AddValueToRealList( "RealListParam", 7.3 );
- parameters.AddValueToRealList( "RealListParam", 8.2 );
- parameters.AddValueToRealList( "RealListParam", 9.1 );
- parameters.AddValueToRealList( "RealListParam", 1.0012 );
- parameters.AddValueToRealList( "RealListParam", 1.131245 );
-
- parameters.AddValueToIndexList( "IndexListParam", 3, -1, 2, 3 );
- parameters.AddValueToIndexList( "IndexListParam", 3, 2, -3, 4 );
- parameters.AddValueToIndexList( "IndexListParam", 3, 3, 4, 7 );
-
- parameters.AddValueToPointList( "PointListParam", 3, 3.45, 4.67, 7.9 );
- parameters.AddValueToPointList( "PointListParam", 3, 3.45, 4.67, 3.14 );
- parameters.AddValueToPointList( "PointListParam", 3, 1.45, 3.67, 2.14 );
- parameters.AddValueToPointList( "PointListParam", 3, 4.5, 6.7, 4.2 );
-
- std::vector< TParameters::TString > names = parameters.GetParameters( );
- std::cout << "Names:" << std::endl;
- for( unsigned int i = 0; i < names.size( ); ++i )
- std::cout
- << "\t... "
- << names[ i ] << " "
- << parameters.GetRawValue( names[ i ] ) << "("
- << parameters.GetParameterType( names[ i ] ) << ")"
- << std::endl;
-
- std::cout << std::endl << "Values with type checking" << std::endl;
- std::cout
- << "\t... " << "StringParam: "
- << parameters.GetValueAsString( "StringParam" ) << std::endl
- << "\t... " << "BoolParam: "
- << parameters.GetValueAsBool( "BoolParam" ) << std::endl
- << "\t... " << "IntParam: "
- << parameters.GetValueAsInt( "IntParam" ) << std::endl
- << "\t... " << "UintParam: "
- << parameters.GetValueAsUint( "UintParam" ) << std::endl
- << "\t... " << "RealParam: "
- << parameters.GetValueAsReal( "RealParam" ) << std::endl
- << "\t... " << "IndexParam: "
- << parameters.GetValueAsIndex< TIndex >( "IndexParam" ) << std::endl
- << "\t... " << "PointParam: "
- << parameters.GetValueAsPoint< TPoint >( "PointParam" ) << std::endl;
-
- std::vector< TParameters::TString > string_lst;
- std::vector< TParameters::TBool > bool_lst;
- std::vector< TParameters::TInt > int_lst;
- std::vector< TParameters::TUint > uint_lst;
- std::vector< TParameters::TReal > real_lst;
- std::vector< TIndex > index_lst;
- std::vector< TPoint > point_lst;
-
- parameters.GetValueAsStringList( string_lst, "StringListParam" );
- parameters.GetValueAsBoolList( bool_lst, "BoolListParam" );
- parameters.GetValueAsIntList( int_lst, "IntListParam" );
- parameters.GetValueAsUintList( uint_lst, "UintListParam" );
- parameters.GetValueAsRealList( real_lst, "RealListParam" );
- parameters.GetValueAsIndexList( index_lst, "IndexListParam" );
- parameters.GetValueAsPointList( point_lst, "PointListParam" );
-
- std::cout << "List parameters:" << std::endl;
- PrintList( string_lst, "StringListParam" );
- PrintList( bool_lst, "BoolListParam" );
- PrintList( int_lst, "IntListParam" );
- PrintList( uint_lst, "UintListParam" );
- PrintList( real_lst, "RealListParam" );
- PrintList( index_lst, "IndexListParam" );
- PrintList( point_lst, "PointListParam" );
+ TParameters::Pointer parameters = TParameters::New( );
+
+ TIndex idx; idx[ 0 ] = 1; idx[ 1 ] = 2; idx[ 2 ] = 3;
+ TPoint pnt; pnt[ 0 ] = 3.1; pnt[ 1 ] = 2.2; pnt[ 2 ] = 1.3;
+
+ parameters->ConfigureAsString( "StringParam", "String_Value" );
+ parameters->ConfigureAsBool( "BoolParam", false );
+ parameters->ConfigureAsInt( "IntParam", -314 );
+ parameters->ConfigureAsUint( "UintParam", 314 );
+ parameters->ConfigureAsReal( "RealParam", 3.14 );
+ parameters->ConfigureAsIndex( "IndexParam", 3, idx );
+ parameters->ConfigureAsPoint( "PointParam", 3, pnt );
+ parameters->ConfigureAsStringList( "StringListParam" );
+ parameters->ConfigureAsBoolList( "BoolListParam" );
+ parameters->ConfigureAsIntList( "IntListParam" );
+ parameters->ConfigureAsUintList( "UintListParam" );
+ parameters->ConfigureAsRealList( "RealListParam" );
+ parameters->ConfigureAsIndexList( "IndexListParam" );
+ parameters->ConfigureAsPointList( "PointListParam" );
+
+ std::vector< std::string > choices;
+ choices.push_back( "bat" );
+ choices.push_back( "deux" );
+ choices.push_back( "drei" );
+ choices.push_back( "cuatro" );
+ choices.push_back( "cinque" );
+ parameters->ConfigureAsChoices( "ChoicesParam", choices );
+
+ std::cout << "---------------------------------------------" << std::endl;
+ parameters->Print( std::cout );
+ std::cout << "---------------------------------------------" << std::endl;
+
+ parameters->SetString( "StringParam", "test_value" );
+ parameters->SetBool( "BoolParam", true );
+ parameters->SetInt( "IntParam", -1234567 );
+ parameters->SetUint( "UintParam", 1234567 );
+ parameters->SetReal( "RealParam", 3.14159244444 );
+
+ idx[ 0 ] = 10; idx[ 1 ] = 20; idx[ 2 ] = 30;
+ pnt[ 0 ] = 30.1; pnt[ 1 ] = 21.2; pnt[ 2 ] = 12.3;
+ parameters->SetIndex( "IndexParam", 3, idx );
+ parameters->SetPoint( "PointParam", 3, pnt );
+
+ std::cout << "---------------------------------------------" << std::endl;
+ parameters->Print( std::cout );
+ std::cout << "---------------------------------------------" << std::endl;
+
+ parameters->ClearStringList( "StringListParam" );
+ parameters->ClearBoolList( "BoolListParam" );
+ parameters->ClearIntList( "IntListParam" );
+ parameters->ClearUintList( "UintListParam" );
+ parameters->ClearRealList( "RealListParam" );
+ parameters->ClearIndexList( "IndexListParam" );
+ parameters->ClearPointList( "PointListParam" );
+
+ parameters->AddToStringList( "StringListParam", "one" );
+ parameters->AddToStringList( "StringListParam", "two" );
+ parameters->AddToStringList( "StringListParam", "three" );
+ parameters->AddToStringList( "StringListParam", "four" );
+
+ parameters->AddToBoolList( "BoolListParam", 1 );
+ parameters->AddToBoolList( "BoolListParam", 0 );
+ parameters->AddToBoolList( "BoolListParam", 0 );
+ parameters->AddToBoolList( "BoolListParam", 1 );
+ parameters->AddToBoolList( "BoolListParam", 1 );
+
+ parameters->AddToIntList( "IntListParam", 1 );
+ parameters->AddToIntList( "IntListParam", -2 );
+ parameters->AddToIntList( "IntListParam", 3 );
+ parameters->AddToIntList( "IntListParam", -4 );
+ parameters->AddToIntList( "IntListParam", 5 );
+ parameters->AddToIntList( "IntListParam", -6 );
+ parameters->AddToIntList( "IntListParam", 7 );
+ parameters->AddToIntList( "IntListParam", -8 );
+ parameters->AddToIntList( "IntListParam", 9 );
+ parameters->AddToIntList( "IntListParam", -10 );
+ parameters->AddToIntList( "IntListParam", 11 );
+
+ parameters->AddToUintList( "UintListParam", 1 );
+ parameters->AddToUintList( "UintListParam", 2 );
+ parameters->AddToUintList( "UintListParam", 3 );
+ parameters->AddToUintList( "UintListParam", 4 );
+ parameters->AddToUintList( "UintListParam", 5 );
+ parameters->AddToUintList( "UintListParam", 6 );
+ parameters->AddToUintList( "UintListParam", 7 );
+ parameters->AddToUintList( "UintListParam", 8 );
+ parameters->AddToUintList( "UintListParam", 9 );
+ parameters->AddToUintList( "UintListParam", 10 );
+ parameters->AddToUintList( "UintListParam", 11 );
+
+ parameters->AddToRealList( "RealListParam", 1.9 );
+ parameters->AddToRealList( "RealListParam", 2.8 );
+ parameters->AddToRealList( "RealListParam", 3.7 );
+ parameters->AddToRealList( "RealListParam", 4.6 );
+ parameters->AddToRealList( "RealListParam", 5.5 );
+ parameters->AddToRealList( "RealListParam", 6.4 );
+ parameters->AddToRealList( "RealListParam", 7.3 );
+ parameters->AddToRealList( "RealListParam", 8.2 );
+ parameters->AddToRealList( "RealListParam", 9.1 );
+ parameters->AddToRealList( "RealListParam", 1.0012 );
+ parameters->AddToRealList( "RealListParam", 1.131245 );
+
+ idx.Fill( 1 );
+ parameters->AddToIndexList( "IndexListParam", 3, idx );
+ idx.Fill( 2 );
+ parameters->AddToIndexList( "IndexListParam", 3, idx );
+ idx.Fill( 3 );
+ parameters->AddToIndexList( "IndexListParam", 3, idx );
+
+ pnt.Fill( 1.2 );
+ parameters->AddToPointList( "PointListParam", 3, pnt );
+ pnt.Fill( 3.14 );
+ parameters->AddToPointList( "PointListParam", 3, pnt );
+ pnt.Fill( 6.28 );
+ parameters->AddToPointList( "PointListParam", 3, pnt );
+ pnt.Fill( 1.63 );
+ parameters->AddToPointList( "PointListParam", 3, pnt );
+
+ std::cout << "---------------------------------------------" << std::endl;
+ parameters->Print( std::cout );
+ std::cout << "---------------------------------------------" << std::endl;
+
+ parameters->SetSelectedChoice( "ChoicesParam", "drei" );
+
+ std::cout << "---------------------------------------------" << std::endl;
+ parameters->Print( std::cout );
+ std::cout << "---------------------------------------------" << std::endl;
+
+ parameters->SetSelectedChoice( "ChoicesParam", "zeven" );
+
+ std::cout << "---------------------------------------------" << std::endl;
+ parameters->Print( std::cout );
+ std::cout << "---------------------------------------------" << std::endl;
return( 0 );
}
--- /dev/null
+#include <QApplication>
+#include <QTextEdit>
+#include <cpExtensions/QT/QuadSplitter.h>
+
+int main( int argc, char* argv[] )
+{
+ int ret = 0;
+#ifdef cpExtensions_Interface_QT4
+ QApplication app( argc, argv );
+
+ QTextEdit* t1 = new QTextEdit;
+ QTextEdit* t2 = new QTextEdit;
+ QTextEdit* t3 = new QTextEdit;
+ QTextEdit* t4 = new QTextEdit;
+
+ cpExtensions::QT::QuadSplitter quadSplit;
+ quadSplit.addWidgets( t1, t2, t3, t4 );
+ quadSplit.show( );
+ ret = app.exec( );
+#endif // cpExtensions_Interface_QT4
+ return( ret );
+}
+
+// eof - $RCSfile$
#else
#endif
+#ifdef WIN32
+#define mysleep Sleep(2000);
+#else
+#define mysleep usleep(2000);
+#endif
+
class Test
{
private:
void called_from_async()
{
-#ifdef WIN32
- Sleep(2000);
-#else
- usleep(2000 * 1000);
-#endif
+
std::cout << "called from async" << std::endl;
this->state.insert(this->it ,10);
}
std::string returned_from_async() {
-#ifdef WIN32
- Sleep(2000);
-#else
- usleep(2000 * 1000);
-#endif
- //std::cout << "Async call" << std::endl;
+ mysleep;
return "Async call";
}
SET(LIBRARY_NAME cpExtensions)
+CONFIGURE_FILE(
+ Config.h.in
+ ${PROJECT_BINARY_DIR}/lib/cpExtensions/Config.h
+ @ONLY
+ )
+
## ===============
## = Source code =
## ===============
)
ENDFOREACH(dir)
+IF(USE_QT4)
+ FILE(GLOB LIB_QT_UI "QT/*.ui")
+ FILE(GLOB LIB_QT_Headers "QT/*.h")
+ FILE(GLOB LIB_QT_Sources "QT/*.cxx")
+ FILE(GLOB LIB_QT_Resources "QT/*.rc")
+
+ QT4_WRAP_UI(LIB_QT_Wrapped_Headers ${LIB_QT_UI})
+ QT4_WRAP_CPP(LIB_QT_Wrapped_MOC_Sources ${LIB_QT_Headers})
+ QT4_ADD_RESOURCES(LIB_QT_Wrapped_Resources_Sources ${LIB_QT_Resources})
+
+ SET(
+ LIB_HEADERS_H
+ ${LIB_HEADERS_H}
+ ${LIB_QT_Wrapped_Headers}
+ )
+ SET(
+ LIB_SOURCES_CXX
+ ${LIB_SOURCES_CXX}
+ ${LIB_QT_Sources}
+ ${LIB_QT_Wrapped_Headers}
+ ${LIB_QT_Wrapped_MOC_Sources}
+ ${LIB_QT_Wrapped_Resources_Sources}
+ )
+ENDIF(USE_QT4)
+
+
## =====================
## = Compilation rules =
## =====================
)
TARGET_LINK_LIBRARIES(
${LIBRARY_NAME}
+ ${QT_LIBRARIES}
${ITK_LIBRARIES}
${VTK_LIBRARIES}
)
--- /dev/null
+#ifndef __CPEXTENSIONS__CONFIG__H__
+#define __CPEXTENSIONS__CONFIG__H__
+
+#define cpExtensions_MAJOR_VERSION @prj_MAJOR_VERSION@
+#define cpExtensions_MINOR_VERSION @prj_MINOR_VERSION@
+#define cpExtensions_RELEASE_VERSION @prj_RELEASE_VERSION@
+#define cpExtensions_VERSION "@prj_VERSION@"
+
+#define cpExtensions_Interface_QT4_USED @QT4_FOUND@
+#if cpExtensions_Interface_QT4_USED == 1
+# define cpExtensions_Interface_QT4
+#else // cpExtensions_Interface_QT4_USED == 1
+# undef cpExtensions_Interface_QT4
+#endif // cpExtensions_Interface_QT4_USED == 1
+
+#endif // __CPEXTENSIONS__CONFIG__H__
+
+// eof - $RCSfile$
--- /dev/null
+#include <cpExtensions/QT/QuadSplitter.h>
+
+#include <cpExtensions/Config.h>
+
+#ifdef cpExtensions_Interface_QT4
+
+/**
+ * Inspired by:
+ * https://forum.qt.io/topic/7144/quad-splitter-windows-an-implementation/2
+ */
+
+// -------------------------------------------------------------------------
+cpExtensions::QT::QuadSplitter::
+QuadSplitter( QWidget* parent )
+ : QSplitter( parent )
+{
+ this->setOrientation( Qt::Vertical );
+ this->addWidget( &this->m_Upper );
+ this->addWidget( &this->m_Bottom );
+
+ QObject::connect(
+ &( this->m_Upper ), SIGNAL( splitterMoved( int, int ) ),
+ this, SLOT( _SyncBottom( int, int ) )
+ );
+ QObject::connect(
+ &( this->m_Bottom ), SIGNAL( splitterMoved( int, int ) ),
+ this, SLOT( _SyncUpper( int, int ) )
+ );
+}
+
+// -------------------------------------------------------------------------
+cpExtensions::QT::QuadSplitter::
+~QuadSplitter( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::QT::QuadSplitter::
+addWidgets( QWidget* a, QWidget* b, QWidget* c, QWidget* d )
+{
+ this->m_Upper.addWidget( a );
+ this->m_Upper.addWidget( b );
+ this->m_Bottom.addWidget( c );
+ this->m_Bottom.addWidget( d );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::QT::QuadSplitter::
+_SyncBottom( int a, int b )
+{
+ this->m_Bottom.setSizes( this->m_Upper.sizes( ) );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::QT::QuadSplitter::
+_SyncUpper( int a, int b )
+{
+ this->m_Upper.setSizes( this->m_Bottom.sizes( ) );
+}
+
+#endif // cpExtensions_Interface_QT4
+
+// eof - $RCSfile$
--- /dev/null
+#ifndef __CPEXTENSIONS__QT__QUADSPLITTER__H__
+#define __CPEXTENSIONS__QT__QUADSPLITTER__H__
+
+#include <cpExtensions/cpExtensions_Export.h>
+#include <cpExtensions/Config.h>
+
+#ifdef cpExtensions_Interface_QT4
+
+/**
+ * Inspired by:
+ * https://forum.qt.io/topic/7144/quad-splitter-windows-an-implementation/2
+ */
+
+#include <QSplitter>
+
+namespace cpExtensions
+{
+ namespace QT
+ {
+ /**
+ */
+ class cpExtensions_EXPORT QuadSplitter
+ : public QSplitter
+ {
+ Q_OBJECT;
+
+ public:
+ QuadSplitter( QWidget* parent = 0 );
+ virtual ~QuadSplitter( );
+
+ 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_Bottom;
+ QSplitter m_Upper;
+ };
+
+ } // ecapseman
+
+} // ecapseman
+
+#endif // cpExtensions_Interface_QT4
+
+#endif // __CPEXTENSIONS__QT__QUADSPLITTER__H__
+
+// eof - $RCSfile$
// -------------------------------------------------------------------------
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( ) )
if( new_map == NULL )
{
// Configure LUT
- this->_ConfigureNewLUT( data, lut );
+ this->_ConfigureNewLUT( data );
new_map = *( this->ImageMaps.rbegin( ) );
if( new_map != NULL )
{
// -------------------------------------------------------------------------
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 )
{
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( );
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( );
void cpExtensions::Visualization::ImageSliceActors::
PushActorsInto( vtkRenderWindow* window, bool force_style )
{
+ if( window == NULL )
+ return;
vtkRenderWindowInteractor* rwi = window->GetInteractor( );
vtkRenderer* renderer = window->GetRenderers( )->GetFirstRenderer( );
-
+ if( rwi == NULL || renderer == NULL )
+ return;
+
// Update style
- if( rwi != NULL && force_style )
- {
+ if( force_style )
if( rwi->GetInteractorStyle( ) != this->Style.GetPointer( ) )
- {
rwi->SetInteractorStyle( this->Style );
- } // fi
-
- } // fi
+ // Update actors
+ unsigned int N = this->GetNumberOfImageActors( );
+ for( unsigned int n = 0; n < N; ++n )
+ renderer->AddActor( this->GetImageActor( n ) );
+ renderer->AddActor( this->CursorActor );
+ renderer->AddActor( this->PlaneActor );
+ renderer->AddActor( this->TextActor );
+ renderer->Modified( );
+
+ // Configure camera
+ vtkCamera* camera = renderer->GetActiveCamera( );
+ if( camera == NULL )
+ return;
- if( renderer != NULL )
+ // Parallel projections are better when displaying 2D images
+ if( force_style )
{
- // Update actors
- unsigned int N = this->GetNumberOfImageActors( );
- for( unsigned int n = 0; n < N; ++n )
- renderer->AddActor( this->GetImageActor( n ) );
- renderer->AddActor( this->CursorActor );
- renderer->AddActor( this->PlaneActor );
- renderer->AddActor( this->TextActor );
- renderer->Modified( );
-
- // Configure camera
- vtkCamera* camera = renderer->GetActiveCamera( );
- if( camera == NULL )
- return;
-
- // Parallel projections are better when displaying 2D images
- if( force_style )
+ int axis = this->GetAxis( );
+ camera->ParallelProjectionOn( );
+ camera->SetFocalPoint( double( 0 ), double( 0 ), double( 0 ) );
+ if( axis == 0 )
{
- int axis = this->GetAxis( );
- camera->ParallelProjectionOn( );
- camera->SetFocalPoint( double( 0 ), double( 0 ), double( 0 ) );
- if( axis == 0 )
- {
- camera->SetPosition( double( 1 ), double( 0 ), double( 0 ) );
- camera->SetViewUp ( double( 0 ), double( 1 ), double( 0 ) );
- }
- else if( axis == 1 )
- {
- camera->SetPosition( double( 0 ), double( 1 ), double( 0 ) );
- camera->SetViewUp ( double( 0 ), double( 0 ), double( -1 ) );
- }
- else // if( axis == 2 )
- {
- camera->SetPosition( double( 0 ), double( 0 ), double( 1 ) );
- camera->SetViewUp ( double( 0 ), double( 1 ), double( 0 ) );
-
- } // fi
+ camera->SetPosition( double( 1 ), double( 0 ), double( 0 ) );
+ camera->SetViewUp ( double( 0 ), double( 1 ), double( 0 ) );
+ }
+ else if( axis == 1 )
+ {
+ camera->SetPosition( double( 0 ), double( 1 ), double( 0 ) );
+ camera->SetViewUp ( double( 0 ), double( 0 ), double( -1 ) );
+ }
+ else // if( axis == 2 )
+ {
+ camera->SetPosition( double( 0 ), double( 0 ), double( 1 ) );
+ camera->SetViewUp ( double( 0 ), double( 1 ), double( 0 ) );
} // fi
- renderer->ResetCamera( );
- rwi->Render( );
} // fi
+ renderer->ResetCamera( );
+ rwi->Render( );
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
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 ) );
}
// -------------------------------------------------------------------------
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 ) );
}
// -------------------------------------------------------------------------
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
// -------------------------------------------------------------------------
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
// -------------------------------------------------------------------------
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
// -------------------------------------------------------------------------
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 );
}
// -------------------------------------------------------------------------
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 );
} // fi
this->PlaneFunction->Modified( );
- this->PlaneSource->Modified( );
+ this->Plane->Modified( );
this->PlaneMapper->Modified( );
this->PlaneActor->Modified( );
this->SetSliceNumber( ijk[ this->GetAxis( ) ] );
}
-// -------------------------------------------------------------------------
-/* TODO
- void cpExtensions::Visualization::ImageSliceActors::
- SetSlices( double pos[ 3 ] )
- {
- }
-*/
-
// -------------------------------------------------------------------------
void cpExtensions::Visualization::ImageSliceActors::
UpdateText( )
void cpExtensions::Visualization::ImageSliceActors::
UpdateText( double pos[ 3 ] )
{
+ /* TODO
if( this->SliceMappers.size( ) > 0 )
{
char axis;
);
str << ")";
std::sprintf(
- this->TextBuffer, "Axis: %c (%d) | Pixel %s",
+ this->TextBuffer, "Axis: %c (%d)\nPixel %s",
axis, slice, str.str( ).c_str( )
);
this->TextActor->SetInput( this->TextBuffer );
this->TextActor->Modified( );
this->Modified( );
+ */
}
// -------------------------------------------------------------------------
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
);
}
// -------------------------------------------------------------------------
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 );
}
// -------------------------------------------------------------------------
dx *= actors->StartWindowLevel[ 0 ];
dy *= actors->StartWindowLevel[ 1 ];
actors->SetWindowLevel(
- 0,
actors->StartWindowLevel[ 0 ] + dx,
actors->StartWindowLevel[ 1 ] + dy
);
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( );
}
// -------------------------------------------------------------------------
if( !alt && !ctr && !sft )
actors->SetCursor( pos );
else if( !alt && ctr && !sft && actors->SlicesCommand != NULL )
+ {
actors->SlicesCommand( pos, actors->GetAxis( ), actors->SlicesData );
+ for( unsigned int i = 0; i < actors->CursorCommands.size( ); ++i )
+ actors->CursorCommands[ i ].first(
+ pos,
+ actors->GetAxis( ),
+ actors->CursorCommands[ i ].second
+ );
+
+ } // fi
}
else if( btn == ImageInteractorStyle::ButtonID_Middle )
{
// -------------------------------------------------------------------------
class vtkAlgorithmOutput;
class vtkImageData;
+class vtkLookupTable;
// -------------------------------------------------------------------------
namespace cpExtensions
typedef ImageSliceActors Self;
typedef void ( *TCursorCommand )( double*, int, void* );
+ typedef ImageInteractorStyle::TMouseCommand TMouseCommand;
+ typedef ImageInteractorStyle::TMouseWheelCommand TMouseWheelCommand;
+ typedef ImageInteractorStyle::TKeyCommand TKeyCommand;
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 AddCursorCommand( TCursorCommand command, void* data )
+ {
+ this->CursorCommands.push_back(
+ std::pair< TCursorCommand, void* >(
+ command, data
+ )
+ );
+ }
+
+ void AddInputConnection( vtkAlgorithmOutput* aout, int axis = 2 );
+ void AddInputData( vtkImageData* data, int axis = 2 );
void Clear( );
void AssociateSlice( Self* other );
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;
ImageSliceActors( );
virtual ~ImageSliceActors( );
- void _ConfigureNewLUT( vtkImageData* data, LUTType lut_t );
+ void _ConfigureNewLUT( vtkImageData* data );
void _ConfigureNewInput( int axis );
// Events
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;
void* SlicesData;
+ // Associated commands
+ std::vector< std::pair< TCursorCommand, void* > > CursorCommands;
+ std::vector< TMouseCommand > MouseCommands;
+ std::vector< TMouseCommand > MouseClickCommands;
+ std::vector< TMouseCommand > MouseDoubleClickCommands;
+ std::vector< TMouseWheelCommand > MouseWheelCommands;
+ std::vector< TKeyCommand > KeyCommands;
+
// Other associated actors
typedef std::pair< vtkAlgorithm*, vtkActor* > TAssociatedActor;
typedef std::vector< TAssociatedActor > TAssociatedActors;
vtkSmartPointer< vtkPolyDataMapper > CursorMapper;
vtkSmartPointer< vtkActor > CursorActor;
vtkSmartPointer< vtkPlane > PlaneFunction;
- vtkSmartPointer< vtkPolyData > PlaneSource;
+ vtkSmartPointer< vtkPolyData > Plane;
vtkSmartPointer< vtkPolyDataMapper > PlaneMapper;
char TextBuffer[ 1024 ];
vtkSmartPointer< vtkTextActor > TextActor;
#include <cpExtensions/Visualization/MPRActors.h>
+#include <vtkAlgorithmOutput.h>
#include <vtkImageData.h>
+#include <vtkOutlineSource.h>
+#include <vtkProperty.h>
#include <vtkRenderer.h>
#include <vtkRendererCollection.h>
#include <vtkRenderWindow.h>
// -------------------------------------------------------------------------
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
);
+
+ // Create bounding box
+ vtkImageData* new_image = dynamic_cast< vtkImageData* >(
+ aout->GetProducer( )->GetOutputDataObject( aout->GetIndex( ) )
+ );
+
+ // Create 3D outline
+ double bb[ 6 ];
+ new_image->GetBounds( bb );
+
+ vtkSmartPointer< vtkOutlineSource > img_ol =
+ vtkSmartPointer< vtkOutlineSource >::New( );
+ img_ol->SetBounds( bb );
+
+ vtkSmartPointer< vtkPolyDataMapper > img_ol_mapper =
+ vtkSmartPointer< vtkPolyDataMapper >::New( );
+ img_ol_mapper->SetInputConnection( img_ol->GetOutputPort( ) );
+ this->ImageOutlineActor->SetMapper( img_ol_mapper );
+ this->ImageOutlineActor->GetProperty( )->SetColor( 1, 1, 1 );
+ this->ImageOutlineActor->GetProperty( )->SetLineWidth( 1 );
+
+ this->AddItem( this->ImageOutlineActor );
}
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( )
- );
- this->ImageMaps[ N ]->SetInputConnection( aout );
- this->SetLookupTableToColor(
- N, double( 1 ), double( 0 ), double( 0 )
+ vtkAlgorithmOutput* ref_aout =
+ this->Slices[ 0 ][ 0 ]->GetImageMap( 0 )->GetOutputPort( );
+ vtkImageData* ref_image = dynamic_cast< vtkImageData* >(
+ ref_aout->GetProducer( )->GetOutputDataObject( ref_aout->GetIndex( ) )
);
- 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 );
// -------------------------------------------------------------------------
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 )
{
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 );
+
+ // Create 3D outline
+ double bb[ 6 ];
+ new_image->GetBounds( bb );
+
+ vtkSmartPointer< vtkOutlineSource > img_ol =
+ vtkSmartPointer< vtkOutlineSource >::New( );
+ img_ol->SetBounds( bb );
+
+ vtkSmartPointer< vtkPolyDataMapper > img_ol_mapper =
+ vtkSmartPointer< vtkPolyDataMapper >::New( );
+ img_ol_mapper->SetInputConnection( img_ol->GetOutputPort( ) );
+ this->ImageOutlineActor->SetMapper( img_ol_mapper );
+ this->ImageOutlineActor->GetProperty( )->SetColor( 1, 1, 1 );
+ this->ImageOutlineActor->GetProperty( )->SetLineWidth( 1 );
+
+ this->AddItem( this->ImageOutlineActor );
}
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( ) );
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
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 );
- */
- return 0;
-}
-
-// -------------------------------------------------------------------------
-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 ] );
- */
- return 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 ] );
- */
- return 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 ] );
- */
- return 0;
-}
-
-// -------------------------------------------------------------------------
-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 ) );
- */
- return 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 ) );
- */
- return 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( );
}
// -------------------------------------------------------------------------
#include <cpExtensions/cpExtensions_Export.h>
#include <cpExtensions/Visualization/ImageSliceActors.h>
-/*
-#include <vtkSmartPointer.h>
-#include <vtkActor.h>
-#include <vtkImageMapToColors.h>
-*/
-
-// -------------------------------------------------------------------------
-/*
-class vtkAlgorithmOutput;
-class vtkImageData;
-class vtkRenderer;
-class vtkScalarsToColors;
-*/
-
-// -------------------------------------------------------------------------
namespace cpExtensions
{
namespace Visualization
public:
typedef MPRActors Self;
+ typedef ImageSliceActors::TCursorCommand TCursorCommand;
+ typedef ImageSliceActors::TMouseCommand TMouseCommand;
+ typedef ImageSliceActors::TMouseWheelCommand TMouseWheelCommand;
+ typedef ImageSliceActors::TKeyCommand TKeyCommand;
+
public:
vtkTypeMacro( MPRActors, vtkPropCollection );
// Creation
static MPRActors* New( );
+ void AddCursorCommand( TCursorCommand command, void* data )
+ {
+ this->Slices[ 0 ][ 0 ]->AddCursorCommand( command, data );
+ this->Slices[ 0 ][ 1 ]->AddCursorCommand( command, data );
+ this->Slices[ 0 ][ 2 ]->AddCursorCommand( command, data );
+ }
+
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,
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
);
+ double GetWindow( )
+ {
+ return( this->Slices[ 0 ][ 0 ]->GetWindow( ) );
+ }
+ double GetLevel( )
+ {
+ return( this->Slices[ 0 ][ 0 ]->GetLevel( ) );
+ }
+
// Slice access
int GetSliceNumberMinValue( const int& axis ) const;
int GetSliceNumberMaxValue( const int& axis ) const;
Self& operator=( const Self& );
protected:
- // TODO: std::vector< vtkSmartPointer< vtkImageMapToColors > > ImageMaps;
vtkSmartPointer< vtkActor > ImageOutlineActor;
vtkSmartPointer< ImageSliceActors > Slices[ 2 ][ 3 ];
+
+ std::vector< TCursorCommand > CursorCommands;
+ std::vector< TMouseCommand > MouseCommands;
+ std::vector< TMouseCommand > MouseClickCommands;
+ std::vector< TMouseCommand > MouseDoubleClickCommands;
+ std::vector< TMouseWheelCommand > MouseWheelCommands;
+ std::vector< TKeyCommand > KeyCommands;
};
} // ecapseman
// -------------------------------------------------------------------------
void cpExtensions::Visualization::MPRObjects::
-SetImage( vtkImageData* image )
+AddImage( vtkImageData* image )
{
this->m_MPRActors->AddInputData( image );
this->m_MPRActors->PushActorsInto(
);
// 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( );
}
typedef MPRObjects Self;
typedef cpExtensions::Visualization::MPRActors TMPRActors;
+ typedef TMPRActors::TCursorCommand TCursorCommand;
+ typedef TMPRActors::TMouseCommand TMouseCommand;
+ typedef TMPRActors::TMouseWheelCommand TMouseWheelCommand;
+ typedef TMPRActors::TKeyCommand TKeyCommand;
+
public:
vtkTypeMacro( MPRObjects, vtkObject );
// Creation
static MPRObjects* New( );
+ void AddCursorCommand( TCursorCommand command, void* data )
+ {
+ this->m_MPRActors->AddCursorCommand( command, data );
+ }
+
void SetRenderWindows(
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( );
TMPRActors* GetMPRActors( );
const TMPRActors* GetMPRActors( ) const;
+ double GetWindow( ) const
+ {
+ return( this->m_MPRActors->GetWindow( ) );
+ }
+ double GetLevel( ) const
+ {
+ return( this->m_MPRActors->GetLevel( ) );
+ }
+
protected:
MPRObjects( );
virtual ~MPRObjects( );
// Internal pipelines
vtkSmartPointer< TMPRActors > m_MPRActors;
vtkSmartPointer< vtkRenderer > m_Renderers[ 4 ];
+
+ std::vector< TCursorCommand > CursorCommands;
+ std::vector< TMouseCommand > MouseCommands;
+ std::vector< TMouseCommand > MouseClickCommands;
+ std::vector< TMouseCommand > MouseDoubleClickCommands;
+ std::vector< TMouseWheelCommand > MouseWheelCommands;
+ std::vector< TKeyCommand > KeyCommands;
};
} // ecapseman
--- /dev/null
+#include <cpPlugins/Interface/BaseMPRWindow.h>
+
+#ifdef cpPlugins_Interface_QT4
+
+#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 <fstream>
+#include <sstream>
+
+#include <QFileDialog>
+#include <QMessageBox>
+
+// -------------------------------------------------------------------------
+cpPlugins::Interface::BaseMPRWindow::
+BaseMPRWindow( QWidget* parent )
+ : cpExtensions::QT::QuadSplitter( parent ),
+ m_LastLoadedPlugin( "." )
+{
+ // 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_XVTK->GetRenderWindow( ),
+ this->m_YVTK->GetRenderWindow( ),
+ this->m_ZVTK->GetRenderWindow( ),
+ this->m_WVTK->GetRenderWindow( )
+ );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Interface::BaseMPRWindow::
+~BaseMPRWindow( )
+{
+ 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 )
+{
+ 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;
+}
+
+// -------------------------------------------------------------------------
+std::string cpPlugins::Interface::BaseMPRWindow::
+LoadImage( )
+{
+ std::string msg = "";
+ std::string ret = "";
+ if( this->m_ImageReader.IsNull( ) )
+ msg = "No valid image reader. Please load a valid plugin file.";
+
+ if( this->m_ImageReader->ExecConfigurationDialog( this ) )
+ {
+ this->Block( );
+ msg = this->m_ImageReader->Update( );
+ if( msg == "" )
+ {
+ TImage::Pointer image =
+ this->m_ImageReader->GetOutput< TImage >( "Output" );
+ if( this->m_Images.size( ) == 0 )
+ ret = image->GetName( );
+ else
+ ret = "Segmentation";
+ this->m_Images[ ret ] = image;
+ this->m_ImageReader->DisconnectOutputs( );
+ this->m_ImageReader->GetParameters( )->ClearStringList( "FileNames" );
+ vtkImageData* vtk_id = image->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 = "";
+
+ } // fi
+
+ // Show errors and return
+ this->Unblock( );
+ if( msg != "" )
+ QMessageBox::critical(
+ this, tr( "Error reading image." ), tr( msg.c_str( ) )
+ );
+ return( ret );
+}
+
+// -------------------------------------------------------------------------
+std::string cpPlugins::Interface::BaseMPRWindow::
+LoadMesh( )
+{
+ return( "" );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::BaseMPRWindow::
+ExecuteFilter(
+ const std::string& name,
+ const std::string& input_id,
+ const std::string& output_id
+ )
+{
+ TProcessObject::Pointer filter =
+ this->m_Interface.CreateProcessObject( name );
+ std::string category = filter->GetClassCategory( );
+ if( category == "ImageToBinaryImageFilter" )
+ {
+ TImages::iterator iIt = this->m_Images.find( input_id );
+ if( iIt != this->m_Images.end( ) )
+ {
+ filter->SetInput( "Input", this->m_Images[ input_id ] );
+ bool dlg_ok = filter->ExecConfigurationDialog( NULL );
+ if( !dlg_ok )
+ return;
+
+ std::string err = filter->Update( );
+ std::cout << "ERR: " << err << std::endl;
+ if( err == "" )
+ {
+ this->m_Images[ "Segmentation" ] =
+ filter->GetOutput< TImage >( "Output" );
+ filter->DisconnectOutputs( );
+
+ vtkImageData* vtk_id =
+ this->m_Images[ "Segmentation" ]->GetVTK< vtkImageData >( );
+ if( vtk_id != NULL )
+ this->m_MPRObjects->AddImage( vtk_id );
+ }
+ else
+ QMessageBox::critical(
+ this, tr( "Error with plugin" ), tr( err.c_str( ) )
+ );
+
+ } // fi
+
+ } // fi
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::BaseMPRWindow::
+AddImage( const std::string& name, TImage* image )
+{
+ this->m_Images[ name ] = image;
+ vtkImageData* vtk_id =
+ this->m_Images[ name ]->GetVTK< vtkImageData >( );
+ if( vtk_id != NULL )
+ this->m_MPRObjects->AddImage( vtk_id );
+}
+
+// -------------------------------------------------------------------------
+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
+
+// eof - $RCSfile$
--- /dev/null
+#ifndef __CPPLUGINS__INTERFACE__BASEMPRWINDOW__H__
+#define __CPPLUGINS__INTERFACE__BASEMPRWINDOW__H__
+
+#include <cpPlugins/Interface/cpPlugins_Interface_Export.h>
+#include <cpPlugins/Interface/Config.h>
+
+#ifdef cpPlugins_Interface_QT4
+
+#include <map>
+#include <set>
+#include <string>
+
+#include <QApplication>
+#include <QMenu>
+#include <QVTKWidget.h>
+
+#include <vtkSmartPointer.h>
+
+#include <cpExtensions/QT/QuadSplitter.h>
+#include <cpExtensions/Visualization/MPRObjects.h>
+#include <cpPlugins/Interface/Interface.h>
+#include <cpPlugins/Interface/ProcessObject.h>
+#include <cpPlugins/Interface/Image.h>
+#include <cpPlugins/Interface/Mesh.h>
+
+namespace cpPlugins
+{
+ namespace Interface
+ {
+ /**
+ */
+ class cpPlugins_Interface_EXPORT BaseMPRWindow
+ : public cpExtensions::QT::QuadSplitter
+ {
+ Q_OBJECT;
+
+ public:
+ typedef cpPlugins::Interface::Interface TInterface;
+ typedef cpPlugins::Interface::ProcessObject TProcessObject;
+ typedef cpPlugins::Interface::DataObject TDataObject;
+ typedef cpPlugins::Interface::Image TImage;
+ typedef cpPlugins::Interface::Mesh TMesh;
+
+ typedef cpExtensions::Visualization::MPRObjects TMPRObjects;
+ typedef TMPRObjects::TCursorCommand TCursorCommand;
+ typedef TMPRObjects::TMouseCommand TMouseCommand;
+ typedef TMPRObjects::TMouseWheelCommand TMouseWheelCommand;
+ typedef TMPRObjects::TKeyCommand TKeyCommand;
+
+ typedef std::map< std::string, TImage::Pointer > TImages;
+ typedef std::map< std::string, TMesh::Pointer > TMeshes;
+ typedef std::set< std::string > TOrderedStringContainer;
+ typedef std::map< std::string, std::set< std::string > > TFilters;
+
+ public:
+ explicit BaseMPRWindow( QWidget* parent = 0 );
+ virtual ~BaseMPRWindow( );
+
+ void AddCursorCommand( TCursorCommand command, void* data )
+ {
+ this->m_MPRObjects->AddCursorCommand( command, data );
+ }
+
+ 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( );
+ std::string LoadImage( );
+ std::string LoadMesh( );
+
+ void ExecuteFilter(
+ const std::string& name,
+ const std::string& input_id,
+ const std::string& output_id
+ );
+
+ TProcessObject::Pointer CreateFilter( const std::string& name )
+ {
+ return( this->m_Interface.CreateProcessObject( name ) );
+ }
+
+ void AddImage( const std::string& name, TImage* image );
+ TImage* GetImage( std::string& name ) const
+ {
+ TImages::const_iterator i = this->m_Images.find( name );
+ if( i != this->m_Images.end( ) )
+ return( i->second );
+ else
+ return( NULL );
+ }
+
+ double GetWindow( ) const
+ {
+ return( this->m_MPRObjects->GetWindow( ) );
+ }
+ double GetLevel( ) const
+ {
+ return( this->m_MPRObjects->GetLevel( ) );
+ }
+
+ void ClearAll( );
+
+ protected:
+ void _UpdatePlugins( );
+
+ protected:
+ 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;
+ };
+
+ } // ecapseman
+
+} // ecapseman
+
+#endif // cpPlugins_Interface_QT4
+
+#endif // __CPPLUGINS__INTERFACE__BASEMPRWINDOW__H__
+
+// eof - $RCSfile$
SET(
LIB_QT_Headers
ParametersListWidget.h
+ BaseMPRWindow.h
)
SET(
LIB_QT_Sources
ParametersListWidget.cxx
+ BaseMPRWindow.cxx
)
SET(
LIB_QT_Resources
${QT_LIBRARIES}
${ITK_LIBRARIES}
${VTK_LIBRARIES}
+ cpExtensions
)
## ========================
#ifndef __CPPLUGINS__INTERFACE__CONFIG__H__
#define __CPPLUGINS__INTERFACE__CONFIG__H__
-
#define cpPlugins_MAJOR_VERSION @prj_MAJOR_VERSION@
#define cpPlugins_MINOR_VERSION @prj_MINOR_VERSION@
#define cpPlugins_RELEASE_VERSION @prj_RELEASE_VERSION@
#include <cpPlugins/Interface/Macros.h>
+#undef ITK_MANUAL_INSTANTIATION
#include <itkMesh.h>
#include <itkQuadEdgeMesh.h>
#include <complex>
+#undef ITK_MANUAL_INSTANTIATION
#include <itkVectorImage.h>
#include <itkCovariantVector.h>
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( );
}
#include <cpPlugins/Interface/Parameters.h>
-#include <cstdarg>
-#include <cstdlib>
-#include <sstream>
-
-// -------------------------------------------------------------------------
-#define cpPlugins_Interface_Parameters_SetMacro( TYPE ) \
- void cpPlugins::Interface::Parameters:: \
- SetValueAs##TYPE( const TString& name, const T##TYPE& v ) \
- { \
- TParameters::iterator pIt = this->m_Parameters.find( name ); \
- if( pIt == this->m_Parameters.end( ) ) \
- return; \
- if( pIt->second.first != Self::TYPE ) \
- return; \
- std::stringstream ss; \
- ss << v; \
- pIt->second.second = ss.str( ); \
- }
-
-cpPlugins_Interface_Parameters_SetMacro( String );
-cpPlugins_Interface_Parameters_SetMacro( Bool );
-cpPlugins_Interface_Parameters_SetMacro( Int );
-cpPlugins_Interface_Parameters_SetMacro( Uint );
-cpPlugins_Interface_Parameters_SetMacro( Real );
-
-// -------------------------------------------------------------------------
-#define cpPlugins_Interface_Parameters_SetArrayMacro( TYPE, ATYPE ) \
- void cpPlugins::Interface::Parameters:: \
- SetValueAs##TYPE( const TString& name, const TUint& n, ... ) \
- { \
- TParameters::iterator pIt = this->m_Parameters.find( name ); \
- if( pIt == this->m_Parameters.end( ) ) \
- return; \
- if( pIt->second.first != Self::TYPE ) \
- return; \
- va_list v_lst; \
- va_start( v_lst, n ); \
- std::stringstream ss; \
- for( TUint i = 0; i < n; ++i ) \
- ss << va_arg( v_lst, ATYPE ) << ","; \
- va_end( v_lst ); \
- pIt->second.second = ss.str( ); \
- }
-
-cpPlugins_Interface_Parameters_SetArrayMacro( Index, int );
-cpPlugins_Interface_Parameters_SetArrayMacro( Point, double );
+#include <cpPlugins/Interface/ProcessObject.h>
-// -------------------------------------------------------------------------
-#define cpPlugins_Interface_Parameters_SetListMacro( TYPE ) \
- void cpPlugins::Interface::Parameters:: \
- AddValueTo##TYPE##List( const TString& name, const T##TYPE& v ) \
- { \
- TParameters::iterator pIt = this->m_Parameters.find( name ); \
- if( pIt == this->m_Parameters.end( ) ) \
- return; \
- if( pIt->second.first != Self::TYPE##List ) \
- return; \
- std::stringstream ss; \
- ss << pIt->second.second << v << "#"; \
- pIt->second.second = ss.str( ); \
- }
-
-cpPlugins_Interface_Parameters_SetListMacro( String );
-cpPlugins_Interface_Parameters_SetListMacro( Bool );
-cpPlugins_Interface_Parameters_SetListMacro( Int );
-cpPlugins_Interface_Parameters_SetListMacro( Uint );
-cpPlugins_Interface_Parameters_SetListMacro( Real );
-
-// -------------------------------------------------------------------------
-#define cpPlugins_Interface_Parameters_SetArrayListMacro( TYPE, ATYPE ) \
- void cpPlugins::Interface::Parameters:: \
- AddValueTo##TYPE##List( const TString& name, const TUint& n, ... ) \
- { \
- TParameters::iterator pIt = this->m_Parameters.find( name ); \
- if( pIt == this->m_Parameters.end( ) ) \
- return; \
- if( pIt->second.first != Self::TYPE##List ) \
- return; \
- va_list v_lst; \
- va_start( v_lst, n ); \
- std::stringstream ss; \
- ss << pIt->second.second; \
- for( TUint i = 0; i < n; ++i ) \
- ss << va_arg( v_lst, ATYPE ) << ","; \
- va_end( v_lst ); \
- ss << "#"; \
- pIt->second.second = ss.str( ); \
- }
-
-cpPlugins_Interface_Parameters_SetArrayListMacro( Index, int );
-cpPlugins_Interface_Parameters_SetArrayListMacro( Point, double );
-
-// -------------------------------------------------------------------------
-#define cpPlugins_Interface_Parameters_ClearListMacro( TYPE ) \
- void cpPlugins::Interface::Parameters:: \
- Clear##TYPE##List( const TString& name ) \
- { \
- TParameters::iterator pIt = this->m_Parameters.find( name ); \
- if( pIt == this->m_Parameters.end( ) ) \
- return; \
- if( pIt->second.first != Self::TYPE##List ) \
- return; \
- pIt->second.second = ""; \
- }
-
-cpPlugins_Interface_Parameters_ClearListMacro( String );
-cpPlugins_Interface_Parameters_ClearListMacro( Bool );
-cpPlugins_Interface_Parameters_ClearListMacro( Int );
-cpPlugins_Interface_Parameters_ClearListMacro( Uint );
-cpPlugins_Interface_Parameters_ClearListMacro( Real );
-cpPlugins_Interface_Parameters_ClearListMacro( Index );
-cpPlugins_Interface_Parameters_ClearListMacro( Point );
+#include <sstream>
// -------------------------------------------------------------------------
-cpPlugins::Interface::Parameters::
-Parameters( )
+const cpPlugins::Interface::
+ProcessObject* cpPlugins::Interface::Parameters::
+GetProcessObject( ) const
{
- this->Clear( );
+ return( this->m_Process );
}
// -------------------------------------------------------------------------
-cpPlugins::Interface::Parameters::
-Parameters( const Self& other )
+void cpPlugins::Interface::Parameters::
+SetProcessObject( ProcessObject* v )
{
- this->m_Parameters = other.m_Parameters;
+ this->m_Process = v;
}
// -------------------------------------------------------------------------
-cpPlugins::Interface::Parameters::
-~Parameters( )
+void cpPlugins::Interface::Parameters::
+Modified( ) const
{
- this->Clear( );
+ this->Superclass::Modified( );
+ if( this->m_Process != NULL )
+ this->m_Process->Modified( );
}
// -------------------------------------------------------------------------
-cpPlugins::Interface::Parameters::
-Self& cpPlugins::Interface::Parameters::
-operator=( const Self& other )
+void cpPlugins::Interface::Parameters::
+Clear( )
{
- this->m_Parameters = other.m_Parameters;
- return( *this );
+ this->m_Parameters.clear( );
+ this->Modified( );
}
// -------------------------------------------------------------------------
void cpPlugins::Interface::Parameters::
-Clear( )
+ConfigureAsString( const TString& name, const TString& v )
{
- this->m_Parameters.clear( );
+ this->m_Parameters[ name ] = TParameter( Self::String, TValues( v, v ) );
+ this->Modified( );
}
+// -------------------------------------------------------------------------
+#define cpPlugins_Parameters_Configure( Y ) \
+ void cpPlugins::Interface::Parameters:: \
+ ConfigureAs##Y( const TString& name, const T##Y& v ) \
+ { \
+ std::stringstream str; \
+ str << v; \
+ std::string s = str.str( ); \
+ this->m_Parameters[ name ] = \
+ TParameter( Self::Y, TValues( s, s ) ); \
+ this->Modified( ); \
+ }
+
+cpPlugins_Parameters_Configure( Bool );
+cpPlugins_Parameters_Configure( Int );
+cpPlugins_Parameters_Configure( Uint );
+cpPlugins_Parameters_Configure( Real );
+
+// -------------------------------------------------------------------------
+#define cpPlugins_Parameters_List_Configure( Y ) \
+ void cpPlugins::Interface::Parameters:: \
+ ConfigureAs##Y##List( const TString& name ) \
+ { \
+ this->m_Parameters[ name ] = \
+ TParameter( Self::Y##List, TValues( "", "" ) ); \
+ this->Modified( ); \
+ }
+
+cpPlugins_Parameters_List_Configure( String );
+cpPlugins_Parameters_List_Configure( Bool );
+cpPlugins_Parameters_List_Configure( Int );
+cpPlugins_Parameters_List_Configure( Uint );
+cpPlugins_Parameters_List_Configure( Real );
+cpPlugins_Parameters_List_Configure( Index );
+cpPlugins_Parameters_List_Configure( Point );
+
// -------------------------------------------------------------------------
void cpPlugins::Interface::Parameters::
-Configure( const Self::Type& type, const TString& name )
+ConfigureAsChoices(
+ const TString& name, const std::vector< TString >& choices
+ )
{
- this->m_Parameters[ name ] = TParameter( type, "" );
+ // It is invalid not to give choices when configuring
+ if( choices.size( ) == 0 )
+ return;
+
+ std::stringstream str_choices;
+ str_choices << choices[ 0 ];
+ for( unsigned int i = 1; i < choices.size( ); ++i )
+ str_choices << "#" << choices[ i ];
+ this->m_Parameters[ name ] =
+ TParameter( Self::Choices, TValues( str_choices.str( ), "" ) );
+ this->Modified( );
}
// -------------------------------------------------------------------------
-std::vector< cpPlugins::Interface::Parameters::TString >
-cpPlugins::Interface::Parameters::
-GetParameters( ) const
+void cpPlugins::Interface::Parameters::
+GetNames( std::vector< TString >& container ) const
{
- std::vector< TString > parameters;
- TParameters::const_iterator pIt = this->m_Parameters.begin( );
- for( ; pIt != this->m_Parameters.end( ); ++pIt )
- parameters.push_back( pIt->first );
- return( parameters );
+ container.clear( );
+ TParameters::const_iterator i = this->m_Parameters.begin( );
+ for( ; i != this->m_Parameters.end( ); ++i )
+ container.push_back( i->first );
}
// -------------------------------------------------------------------------
cpPlugins::Interface::Parameters::
Type cpPlugins::Interface::Parameters::
-GetParameterType( const TString& name ) const
+GetType( const TString& name ) const
{
- TParameters::const_iterator pIt = this->m_Parameters.find( name );
- if( pIt == this->m_Parameters.end( ) )
+ TParameters::const_iterator i = this->m_Parameters.find( name );
+ if( i != this->m_Parameters.end( ) )
+ return( i->second.first );
+ else
return( Self::NoType );
- return( pIt->second.first );
}
// -------------------------------------------------------------------------
-const cpPlugins::Interface::Parameters::
-TString& cpPlugins::Interface::Parameters::
-GetRawValue( const TString& name ) const
-{
- static const TString null_str = "";
- TParameters::const_iterator pIt = this->m_Parameters.find( name );
- if( pIt == this->m_Parameters.end( ) )
- return( null_str );
- return( pIt->second.second );
-}
+#define cpPlugins_Parameters_Has( Y ) \
+ bool cpPlugins::Interface::Parameters:: \
+ Has##Y( const TString& name ) const \
+ { \
+ TParameters::const_iterator i = this->m_Parameters.find( name ); \
+ if( i != this->m_Parameters.end( ) ) \
+ return( i->second.first == Self::Y ); \
+ else \
+ return( false ); \
+ }
+
+cpPlugins_Parameters_Has( String );
+cpPlugins_Parameters_Has( Bool );
+cpPlugins_Parameters_Has( Int );
+cpPlugins_Parameters_Has( Uint );
+cpPlugins_Parameters_Has( Real );
+cpPlugins_Parameters_Has( Index );
+cpPlugins_Parameters_Has( Point );
+cpPlugins_Parameters_Has( StringList );
+cpPlugins_Parameters_Has( BoolList );
+cpPlugins_Parameters_Has( IntList );
+cpPlugins_Parameters_Has( UintList );
+cpPlugins_Parameters_Has( RealList );
+cpPlugins_Parameters_Has( IndexList );
+cpPlugins_Parameters_Has( PointList );
+cpPlugins_Parameters_Has( Choices );
// -------------------------------------------------------------------------
-const cpPlugins::Interface::Parameters::
-TString& cpPlugins::Interface::Parameters::
-GetValueAsString( const TString& name ) const
+cpPlugins::Interface::Parameters::
+TString cpPlugins::Interface::Parameters::
+GetString( const TString& name ) const
{
- static const TString null_str = "";
- TParameters::const_iterator pIt = this->m_Parameters.find( name );
- if( pIt == this->m_Parameters.end( ) )
- return( null_str );
- if( pIt->second.first != Self::String )
- return( null_str );
-
- return( pIt->second.second );
+ TParameters::const_iterator i = this->m_Parameters.find( name );
+ if( i != this->m_Parameters.end( ) )
+ {
+ if( i->second.first == Self::String )
+ return( i->second.second.second );
+
+ } // fi
+ return( "" );
}
// -------------------------------------------------------------------------
cpPlugins::Interface::Parameters::
TBool cpPlugins::Interface::Parameters::
-GetValueAsBool( const TString& name ) const
+GetBool( const TString& name ) const
{
- TParameters::const_iterator pIt = this->m_Parameters.find( name );
- if( pIt == this->m_Parameters.end( ) )
- return( TBool( false ) );
- if( pIt->second.first != Self::Bool )
- return( TBool( false ) );
- return( TBool( std::atoi( pIt->second.second.c_str( ) ) == 1 ) );
+ TParameters::const_iterator i = this->m_Parameters.find( name );
+ if( i != this->m_Parameters.end( ) )
+ {
+ if( i->second.first == Self::Bool )
+ return( std::atoi( i->second.second.second.c_str( ) ) == 1 );
+
+ } // fi
+ return( false );
}
// -------------------------------------------------------------------------
cpPlugins::Interface::Parameters::
TInt cpPlugins::Interface::Parameters::
-GetValueAsInt( const TString& name ) const
+GetInt( const TString& name ) const
{
- TParameters::const_iterator pIt = this->m_Parameters.find( name );
- if( pIt == this->m_Parameters.end( ) )
- return( TInt( 0 ) );
- if( pIt->second.first != Self::Int )
- return( TInt( 0 ) );
- return( TInt( std::atoi( pIt->second.second.c_str( ) ) ) );
+ TParameters::const_iterator i = this->m_Parameters.find( name );
+ if( i != this->m_Parameters.end( ) )
+ {
+ if( i->second.first == Self::Int )
+ return( TInt( std::atoi( i->second.second.second.c_str( ) ) ) );
+
+ } // fi
+ return( TInt( 0 ) );
}
// -------------------------------------------------------------------------
cpPlugins::Interface::Parameters::
TUint cpPlugins::Interface::Parameters::
-GetValueAsUint( const TString& name ) const
+GetUint( const TString& name ) const
{
- TParameters::const_iterator pIt = this->m_Parameters.find( name );
- if( pIt == this->m_Parameters.end( ) )
- return( TUint( 0 ) );
- if( pIt->second.first != Self::Uint )
- return( TUint( 0 ) );
- return( TUint( std::atoi( pIt->second.second.c_str( ) ) ) );
+ TParameters::const_iterator i = this->m_Parameters.find( name );
+ if( i != this->m_Parameters.end( ) )
+ {
+ if( i->second.first == Self::Uint )
+ return( TUint( std::atoi( i->second.second.second.c_str( ) ) ) );
+
+ } // fi
+ return( TUint( 0 ) );
}
// -------------------------------------------------------------------------
cpPlugins::Interface::Parameters::
TReal cpPlugins::Interface::Parameters::
-GetValueAsReal( const TString& name ) const
+GetReal( const TString& name ) const
{
- TParameters::const_iterator pIt = this->m_Parameters.find( name );
- if( pIt == this->m_Parameters.end( ) )
- return( TReal( 0 ) );
- if( pIt->second.first != Self::Real )
- return( TReal( 0 ) );
- return( TReal( std::atof( pIt->second.second.c_str( ) ) ) );
+ TParameters::const_iterator i = this->m_Parameters.find( name );
+ if( i != this->m_Parameters.end( ) )
+ {
+ if( i->second.first == Self::Real )
+ return( TReal( std::atof( i->second.second.second.c_str( ) ) ) );
+
+ } // fi
+ return( TReal( 0 ) );
}
// -------------------------------------------------------------------------
void cpPlugins::Interface::Parameters::
-GetValueAsStringList(
- std::vector< TString >& lst, const TString& name
- ) const
+GetStringList( std::vector< TString >& lst, const TString& name ) const
{
lst.clear( );
- TParameters::const_iterator pIt = this->m_Parameters.find( name );
- if( pIt == this->m_Parameters.end( ) )
+ TParameters::const_iterator i = this->m_Parameters.find( name );
+ if( i == this->m_Parameters.end( ) )
return;
- if( pIt->second.first != Self::StringList )
+ if( i->second.first != Self::StringList )
return;
- std::istringstream ss( pIt->second.second );
+ std::istringstream str( i->second.second.second );
std::string token;
- while( std::getline( ss, token, '#' ) )
- if( token != "" )
- lst.push_back( token );
+ while( std::getline( str, token, '#' ) )
+ lst.push_back( token );
}
// -------------------------------------------------------------------------
void cpPlugins::Interface::Parameters::
-GetValueAsBoolList( std::vector< TBool >& lst, const TString& name ) const
+GetBoolList( std::vector< TBool >& lst, const TString& name ) const
{
lst.clear( );
- TParameters::const_iterator pIt = this->m_Parameters.find( name );
- if( pIt == this->m_Parameters.end( ) )
+ TParameters::const_iterator i = this->m_Parameters.find( name );
+ if( i == this->m_Parameters.end( ) )
return;
- if( pIt->second.first != Self::BoolList )
+ if( i->second.first != Self::BoolList )
return;
- std::istringstream ss( pIt->second.second );
+ std::istringstream str( i->second.second.second );
std::string token;
- while( std::getline( ss, token, '#' ) )
- if( token != "" )
- lst.push_back( TBool( std::atoi( token.c_str( ) ) == 1 ) );
+ while( std::getline( str, token, '#' ) )
+ lst.push_back( std::atoi( token.c_str( ) ) == 1 );
}
// -------------------------------------------------------------------------
void cpPlugins::Interface::Parameters::
-GetValueAsIntList( std::vector< TInt >& lst, const TString& name ) const
+GetIntList( std::vector< TInt >& lst, const TString& name ) const
{
lst.clear( );
- TParameters::const_iterator pIt = this->m_Parameters.find( name );
- if( pIt == this->m_Parameters.end( ) )
+ TParameters::const_iterator i = this->m_Parameters.find( name );
+ if( i == this->m_Parameters.end( ) )
return;
- if( pIt->second.first != Self::IntList )
+ if( i->second.first != Self::IntList )
return;
- std::istringstream ss( pIt->second.second );
+ std::istringstream str( i->second.second.second );
std::string token;
- while( std::getline( ss, token, '#' ) )
- if( token != "" )
- lst.push_back( TInt( std::atoi( token.c_str( ) ) ) );
+ while( std::getline( str, token, '#' ) )
+ lst.push_back( TInt( std::atoi( token.c_str( ) ) ) );
}
// -------------------------------------------------------------------------
void cpPlugins::Interface::Parameters::
-GetValueAsUintList( std::vector< TUint >& lst, const TString& name ) const
+GetUintList( std::vector< TUint >& lst, const TString& name ) const
{
lst.clear( );
- TParameters::const_iterator pIt = this->m_Parameters.find( name );
- if( pIt == this->m_Parameters.end( ) )
+ TParameters::const_iterator i = this->m_Parameters.find( name );
+ if( i == this->m_Parameters.end( ) )
return;
- if( pIt->second.first != Self::UintList )
+ if( i->second.first != Self::UintList )
return;
- std::istringstream ss( pIt->second.second );
+ std::istringstream str( i->second.second.second );
std::string token;
- while( std::getline( ss, token, '#' ) )
- if( token != "" )
- lst.push_back( TUint( std::atoi( token.c_str( ) ) ) );
+ while( std::getline( str, token, '#' ) )
+ lst.push_back( TUint( std::atoi( token.c_str( ) ) ) );
}
// -------------------------------------------------------------------------
void cpPlugins::Interface::Parameters::
-GetValueAsRealList( std::vector< TReal >& lst, const TString& name ) const
+GetRealList( std::vector< TReal >& lst, const TString& name ) const
{
lst.clear( );
- TParameters::const_iterator pIt = this->m_Parameters.find( name );
- if( pIt == this->m_Parameters.end( ) )
+ TParameters::const_iterator i = this->m_Parameters.find( name );
+ if( i == this->m_Parameters.end( ) )
return;
- if( pIt->second.first != Self::RealList )
+ if( i->second.first != Self::RealList )
return;
- std::istringstream ss( pIt->second.second );
+ std::istringstream str( i->second.second.second );
std::string token;
- while( std::getline( ss, token, '#' ) )
- if( token != "" )
- lst.push_back( TReal( std::atof( token.c_str( ) ) ) );
+ while( std::getline( str, token, '#' ) )
+ lst.push_back( TReal( std::atof( token.c_str( ) ) ) );
}
// -------------------------------------------------------------------------
-bool cpPlugins::Interface::Parameters::
-HasStringValue( const TString& name ) const
-{
- TParameters::const_iterator pIt = this->m_Parameters.find( name );
- if( pIt != this->m_Parameters.end( ) )
- return( pIt->second.first == Self::String );
- return( false );
-}
-
-// -------------------------------------------------------------------------
-bool cpPlugins::Interface::Parameters::
-HasBoolValue( const TString& name ) const
-{
- TParameters::const_iterator pIt = this->m_Parameters.find( name );
- if( pIt != this->m_Parameters.end( ) )
- return( pIt->second.first == Self::Bool );
- return( false );
-}
-
-// -------------------------------------------------------------------------
-bool cpPlugins::Interface::Parameters::
-HasIntValue( const TString& name ) const
-{
- TParameters::const_iterator pIt = this->m_Parameters.find( name );
- if( pIt != this->m_Parameters.end( ) )
- return( pIt->second.first == Self::Int );
- return( false );
-}
-
-// -------------------------------------------------------------------------
-bool cpPlugins::Interface::Parameters::
-HasUintValue( const TString& name ) const
+void cpPlugins::Interface::Parameters::
+GetChoices( std::vector< TString >& choices, const TString& name ) const
{
- TParameters::const_iterator pIt = this->m_Parameters.find( name );
- if( pIt != this->m_Parameters.end( ) )
- return( pIt->second.first == Self::Uint );
- return( false );
-}
+ choices.clear( );
+ TParameters::const_iterator i = this->m_Parameters.find( name );
+ if( i == this->m_Parameters.end( ) )
+ return;
+ if( i->second.first != Self::Choices )
+ return;
-// -------------------------------------------------------------------------
-bool cpPlugins::Interface::Parameters::
-HasRealValue( const TString& name ) const
-{
- TParameters::const_iterator pIt = this->m_Parameters.find( name );
- if( pIt != this->m_Parameters.end( ) )
- return( pIt->second.first == Self::Real );
- return( false );
+ std::istringstream str( i->second.second.first );
+ std::string token;
+ while( std::getline( str, token, '#' ) )
+ choices.push_back( token );
}
// -------------------------------------------------------------------------
-bool cpPlugins::Interface::Parameters::
-HasIndexValue( const TString& name ) const
+cpPlugins::Interface::Parameters::
+TString cpPlugins::Interface::Parameters::
+GetSelectedChoice( const TString& name ) const
{
- TParameters::const_iterator pIt = this->m_Parameters.find( name );
- if( pIt != this->m_Parameters.end( ) )
- return( pIt->second.first == Self::Index );
- return( false );
+ TParameters::const_iterator i = this->m_Parameters.find( name );
+ if( i == this->m_Parameters.end( ) )
+ return( "" );
+ if( i->second.first != Self::Choices )
+ return( "" );
+ return( i->second.second.second );
}
// -------------------------------------------------------------------------
-bool cpPlugins::Interface::Parameters::
-HasPointValue( const TString& name ) const
+void cpPlugins::Interface::Parameters::
+SetString( const TString& name, const TString& v )
{
- TParameters::const_iterator pIt = this->m_Parameters.find( name );
- if( pIt != this->m_Parameters.end( ) )
- return( pIt->second.first == Self::Point );
- return( false );
-}
+ TParameters::iterator i = this->m_Parameters.find( name );
+ if( i == this->m_Parameters.end( ) )
+ return;
+ if( i->second.first != Self::String )
+ return;
+ i->second.second.second = v;
+ this->Modified( );
+}
+
+// -------------------------------------------------------------------------
+#define cpPlugins_Parameters_Set( Y ) \
+ void cpPlugins::Interface::Parameters:: \
+ Set##Y( const TString& name, const T##Y& v ) \
+ { \
+ TParameters::iterator i = this->m_Parameters.find( name ); \
+ if( i == this->m_Parameters.end( ) ) \
+ return; \
+ if( i->second.first != Self::Y ) \
+ return; \
+ std::stringstream str; \
+ str << v; \
+ i->second.second.second = str.str( ); \
+ this->Modified( ); \
+ }
-// -------------------------------------------------------------------------
-bool cpPlugins::Interface::Parameters::
-HasStringListValue( const TString& name ) const
-{
- TParameters::const_iterator pIt = this->m_Parameters.find( name );
- if( pIt != this->m_Parameters.end( ) )
- return( pIt->second.first == Self::StringList );
- return( false );
-}
+cpPlugins_Parameters_Set( Bool );
+cpPlugins_Parameters_Set( Int );
+cpPlugins_Parameters_Set( Uint );
+cpPlugins_Parameters_Set( Real );
+
+// -------------------------------------------------------------------------
+#define cpPlugins_Parameters_Add( Y ) \
+ void cpPlugins::Interface::Parameters:: \
+ AddTo##Y##List( const TString& name, const T##Y& v ) \
+ { \
+ TParameters::iterator i = this->m_Parameters.find( name ); \
+ if( i == this->m_Parameters.end( ) ) \
+ return; \
+ if( i->second.first != Self::Y##List ) \
+ return; \
+ std::stringstream str; \
+ if( i->second.second.second == "" ) \
+ str << v; \
+ else \
+ str << "#" << v; \
+ i->second.second.second += str.str( ); \
+ this->Modified( ); \
+ }
-// -------------------------------------------------------------------------
-bool cpPlugins::Interface::Parameters::
-HasBoolListValue( const TString& name ) const
-{
- TParameters::const_iterator pIt = this->m_Parameters.find( name );
- if( pIt != this->m_Parameters.end( ) )
- return( pIt->second.first == Self::BoolList );
- return( false );
-}
+cpPlugins_Parameters_Add( String );
+cpPlugins_Parameters_Add( Bool );
+cpPlugins_Parameters_Add( Int );
+cpPlugins_Parameters_Add( Uint );
+cpPlugins_Parameters_Add( Real );
+
+// -------------------------------------------------------------------------
+#define cpPlugins_Parameters_Clear( Y ) \
+ void cpPlugins::Interface::Parameters:: \
+ Clear##Y##List( const TString& name ) \
+ { \
+ TParameters::iterator i = this->m_Parameters.find( name ); \
+ if( i == this->m_Parameters.end( ) ) \
+ return; \
+ if( i->second.first != Self::Y##List ) \
+ return; \
+ i->second.second.second = ""; \
+ this->Modified( ); \
+ }
-// -------------------------------------------------------------------------
-bool cpPlugins::Interface::Parameters::
-HasIntListValue( const TString& name ) const
-{
- TParameters::const_iterator pIt = this->m_Parameters.find( name );
- if( pIt != this->m_Parameters.end( ) )
- return( pIt->second.first == Self::IntList );
- return( false );
-}
+cpPlugins_Parameters_Clear( String );
+cpPlugins_Parameters_Clear( Bool );
+cpPlugins_Parameters_Clear( Int );
+cpPlugins_Parameters_Clear( Uint );
+cpPlugins_Parameters_Clear( Real );
+cpPlugins_Parameters_Clear( Index );
+cpPlugins_Parameters_Clear( Point );
// -------------------------------------------------------------------------
bool cpPlugins::Interface::Parameters::
-HasUintListValue( const TString& name ) const
-{
- TParameters::const_iterator pIt = this->m_Parameters.find( name );
- if( pIt != this->m_Parameters.end( ) )
- return( pIt->second.first == Self::UintList );
- return( false );
+SetSelectedChoice( const TString& name, const TString& choice )
+{
+ TParameters::iterator i = this->m_Parameters.find( name );
+ if( i == this->m_Parameters.end( ) )
+ return( false );
+ if( i->second.first != Self::Choices )
+ return( false );
+ if( i->second.second.first.find( choice ) != std::string::npos )
+ {
+ i->second.second.second = choice;
+ this->Modified( );
+ return( true );
+ }
+ else
+ return( false );
}
// -------------------------------------------------------------------------
-bool cpPlugins::Interface::Parameters::
-HasRealListValue( const TString& name ) const
+cpPlugins::Interface::Parameters::
+Parameters( )
+ : Superclass( ),
+ m_Process( NULL )
{
- TParameters::const_iterator pIt = this->m_Parameters.find( name );
- if( pIt != this->m_Parameters.end( ) )
- return( pIt->second.first == Self::RealList );
- return( false );
+ this->Clear( );
}
// -------------------------------------------------------------------------
-bool cpPlugins::Interface::Parameters::
-HasIndexListValue( const TString& name ) const
+cpPlugins::Interface::Parameters::
+~Parameters( )
{
- TParameters::const_iterator pIt = this->m_Parameters.find( name );
- if( pIt != this->m_Parameters.end( ) )
- return( pIt->second.first == Self::IndexList );
- return( false );
}
// -------------------------------------------------------------------------
-bool cpPlugins::Interface::Parameters::
-HasPointListValue( const TString& name ) const
-{
- TParameters::const_iterator pIt = this->m_Parameters.find( name );
- if( pIt != this->m_Parameters.end( ) )
- return( pIt->second.first == Self::PointList );
- return( false );
+void cpPlugins::Interface::Parameters::
+PrintSelf( std::ostream& os, itk::Indent indent ) const
+{
+ TParameters::const_iterator i = this->m_Parameters.begin( );
+ for( ; i != this->m_Parameters.end( ); ++i )
+ os << indent
+ << i->first << ": ("
+ << i->second.first << " | "
+ << i->second.second.first << " | "
+ << i->second.second.second << ")"
+ << std::endl;
}
// eof - $RCSfile$
#ifndef __CPPLUGINS__INTERFACE__PARAMETERS__H__
#define __CPPLUGINS__INTERFACE__PARAMETERS__H__
+#include <cpPlugins/Interface/cpPlugins_Interface_Export.h>
+
#include <map>
#include <ostream>
#include <string>
#include <vector>
-#include <cpPlugins/Interface/cpPlugins_Interface_Export.h>
+
+#include <itkObject.h>
+#include <itkObjectFactory.h>
namespace cpPlugins
{
namespace Interface
{
+ // Some forward declarations
+ class ProcessObject;
+
/**
*/
class cpPlugins_Interface_EXPORT Parameters
+ : public itk::Object
{
- // -------------------------------------------------------------------
- friend std::ostream& operator<<(
- std::ostream& os, const Parameters& p
- )
- {
- Parameters::TParameters::const_iterator pIt =
- p.m_Parameters.begin( );
- for( ; pIt != p.m_Parameters.end( ); ++pIt )
- {
- os
- << pIt->first << ": ("
- << pIt->second.first << ", "
- << pIt->second.second << ")"
- << std::endl;
-
- } // rof
- return( os );
- }
-
public:
- typedef Parameters Self;
+ typedef Parameters Self;
+ typedef itk::Object Superclass;
+ typedef itk::SmartPointer< Self > Pointer;
+ typedef itk::SmartPointer< const Self > ConstPointer;
enum Type
{
Uint , Real , Index ,
Point , StringList , BoolList ,
IntList , UintList , RealList ,
- IndexList , PointList , NoType
+ IndexList , PointList , Choices ,
+ NoType
};
typedef bool TBool;
typedef double TReal;
typedef std::string TString;
- typedef std::pair< Self::Type, TString > TParameter;
+ // NOTE: std::pair< default, value >
+ typedef std::pair< TString, TString > TValues;
+ typedef std::pair< Self::Type, TValues > TParameter;
typedef std::map< TString, TParameter > TParameters;
public:
- Parameters( );
- Parameters( const Self& other );
- virtual ~Parameters( );
+ itkNewMacro( Self );
+ itkTypeMacro( cpPlugins::Interface::Parameters, itk::Object );
- Self& operator=( const Self& other );
+ public:
+ // To impact pipeline
+ virtual const ProcessObject* GetProcessObject( ) const;
+ virtual void SetProcessObject( ProcessObject* v );
+ virtual void Modified( ) const;
+ // Parameters container configuration
void Clear( );
- void Configure( const Self::Type& type, const TString& name );
- void SetValueAsString( const TString& name, const TString& v );
- void SetValueAsBool( const TString& name, const TBool& v );
- void SetValueAsInt( const TString& name, const TInt& v );
- void SetValueAsUint( const TString& name, const TUint& v );
- void SetValueAsReal( const TString& name, const TReal& v );
- void SetValueAsIndex( const TString& name, const TUint& n, ... );
- void SetValueAsPoint( const TString& name, const TUint& n, ... );
-
- void AddValueToStringList( const TString& name, const TString& v );
- void AddValueToBoolList( const TString& name, const TBool& v );
- void AddValueToIntList( const TString& name, const TInt& v );
- void AddValueToUintList( const TString& name, const TUint& v );
- void AddValueToRealList( const TString& name, const TReal& v );
- void AddValueToIndexList( const TString& name, const TUint& n, ... );
- void AddValueToPointList( const TString& name, const TUint& n, ... );
- void ClearStringList( const TString& name );
- void ClearBoolList( const TString& name );
- void ClearIntList( const TString& name );
- void ClearUintList( const TString& name );
- void ClearRealList( const TString& name );
- void ClearIndexList( const TString& name );
- void ClearPointList( const TString& name );
-
- std::vector< TString > GetParameters( ) const;
- Self::Type GetParameterType( const TString& name ) const;
- const TString& GetRawValue( const TString& name ) const;
- const TString& GetValueAsString( const TString& name ) const;
- TBool GetValueAsBool( const TString& name ) const;
- TInt GetValueAsInt( const TString& name ) const;
- TUint GetValueAsUint( const TString& name ) const;
- TReal GetValueAsReal( const TString& name ) const;
+ void ConfigureAsString( const TString& name, const TString& v );
+ void ConfigureAsBool( const TString& name, const TBool& v );
+ void ConfigureAsInt( const TString& name, const TInt& v );
+ void ConfigureAsUint( const TString& name, const TUint& v );
+ void ConfigureAsReal( const TString& name, const TReal& v );
template< class I >
- I GetValueAsIndex( const TString& name ) const;
-
+ inline void ConfigureAsIndex(
+ const TString& name, const TUint& dim, const I& v
+ );
template< class P >
- P GetValueAsPoint( const TString& name ) const;
-
- void GetValueAsStringList(
+ inline void ConfigureAsPoint(
+ const TString& name, const TUint& dim, const P& v
+ );
+
+ void ConfigureAsStringList( const TString& name );
+ void ConfigureAsBoolList( const TString& name );
+ void ConfigureAsIntList( const TString& name );
+ void ConfigureAsUintList( const TString& name );
+ void ConfigureAsRealList( const TString& name );
+ void ConfigureAsIndexList( const TString& name );
+ void ConfigureAsPointList( const TString& name );
+ void ConfigureAsChoices(
+ const TString& name, const std::vector< TString >& choices
+ );
+
+ // Get methods
+ void GetNames( std::vector< TString >& container ) const;
+ Type GetType( const TString& name ) const;
+
+ bool HasString( const TString& name ) const;
+ bool HasBool( const TString& name ) const;
+ bool HasInt( const TString& name ) const;
+ bool HasUint( const TString& name ) const;
+ bool HasReal( const TString& name ) const;
+ bool HasIndex( const TString& name ) const;
+ bool HasPoint( const TString& name ) const;
+ bool HasStringList( const TString& name ) const;
+ bool HasBoolList( const TString& name ) const;
+ bool HasIntList( const TString& name ) const;
+ bool HasUintList( const TString& name ) const;
+ bool HasRealList( const TString& name ) const;
+ bool HasIndexList( const TString& name ) const;
+ bool HasPointList( const TString& name ) const;
+ bool HasChoices( const TString& name ) const;
+
+ TString GetString( const TString& name ) const;
+ TBool GetBool( const TString& name ) const;
+ TInt GetInt( const TString& name ) const;
+ TUint GetUint( const TString& name ) const;
+ TReal GetReal( const TString& name ) const;
+
+ void GetStringList(
std::vector< TString >& lst, const TString& name
) const;
- void GetValueAsBoolList(
+ void GetBoolList(
std::vector< TBool >& lst, const TString& name
) const;
- void GetValueAsIntList(
+ void GetIntList(
std::vector< TInt >& lst, const TString& name
) const;
- void GetValueAsUintList(
+ void GetUintList(
std::vector< TUint >& lst, const TString& name
) const;
- void GetValueAsRealList(
+ void GetRealList(
std::vector< TReal >& lst, const TString& name
) const;
- template< class I >
- void GetValueAsIndexList(
- std::vector< I >& lst, const TString& name
+ void GetChoices(
+ std::vector< TString >& choices, const TString& name
) const;
+ TString GetSelectedChoice( const TString& name ) const;
+ template< class I >
+ inline I GetIndex( const TString& name, const TUint& dim ) const;
template< class P >
- void GetValueAsPointList(
- std::vector< P >& lst, const TString& name
- ) const;
+ inline P GetPoint( const TString& name, const TUint& dim ) const;
+
+ template< class I >
+ inline void GetIndexList(
+ std::vector< I >& lst, const TString& name, const TUint& dim
+ ) const;
+ template< class P >
+ inline void GetPointList(
+ std::vector< P >& lst, const TString& name, const TUint& dim
+ ) const;
+
+ // Set methods
+ void SetString( const TString& name, const TString& v );
+ void SetBool( const TString& name, const TBool& v );
+ void SetInt( const TString& name, const TInt& v );
+ void SetUint( const TString& name, const TUint& v );
+ void SetReal( const TString& name, const TReal& v );
+
+ template< class I >
+ inline void SetIndex(
+ const TString& name, const TUint& dim, const I& v
+ );
+ template< class P >
+ inline void SetPoint(
+ const TString& name, const TUint& dim, const P& v
+ );
+
+ void AddToStringList( const TString& name, const TString& v );
+ void AddToBoolList( const TString& name, const TBool& v );
+ void AddToIntList( const TString& name, const TInt& v );
+ void AddToUintList( const TString& name, const TUint& v );
+ void AddToRealList( const TString& name, const TReal& v );
- bool HasStringValue( const TString& name ) const;
- bool HasBoolValue( const TString& name ) const;
- bool HasIntValue( const TString& name ) const;
- bool HasUintValue( const TString& name ) const;
- bool HasRealValue( const TString& name ) const;
- bool HasIndexValue( const TString& name ) const;
- bool HasPointValue( const TString& name ) const;
- bool HasStringListValue( const TString& name ) const;
- bool HasBoolListValue( const TString& name ) const;
- bool HasIntListValue( const TString& name ) const;
- bool HasUintListValue( const TString& name ) const;
- bool HasRealListValue( const TString& name ) const;
- bool HasIndexListValue( const TString& name ) const;
- bool HasPointListValue( const TString& name ) const;
+ template< class I >
+ inline void AddToIndexList(
+ const TString& name, const TUint& dim, const I& v
+ );
+ template< class P >
+ inline void AddToPointList(
+ const TString& name, const TUint& dim, const P& v
+ );
+
+ void ClearStringList( const TString& name );
+ void ClearBoolList( const TString& name );
+ void ClearIntList( const TString& name );
+ void ClearUintList( const TString& name );
+ void ClearRealList( const TString& name );
+ void ClearIndexList( const TString& name );
+ void ClearPointList( const TString& name );
+
+ bool SetSelectedChoice( const TString& name, const TString& choice );
+
+ protected:
+ Parameters( );
+ virtual ~Parameters( );
+ void PrintSelf( std::ostream& os, itk::Indent indent ) const;
+
+ private:
+ // Purposely not implemented
+ Parameters( const Self& other );
+ Self& operator=( const Self& other );
protected:
TParameters m_Parameters;
+ const ProcessObject* m_Process;
};
} // ecapseman
#ifndef __CPPLUGINS__INTERFACE__PARAMETERS__HXX__
#define __CPPLUGINS__INTERFACE__PARAMETERS__HXX__
-#include <cstdlib>
-#include <iostream>
-#include <sstream>
+// -------------------------------------------------------------------------
+template< class I >
+void cpPlugins::Interface::Parameters::
+ConfigureAsIndex( const TString& name, const TUint& dim, const I& v )
+{
+ std::stringstream str;
+ str << v[ 0 ];
+ for( unsigned int d = 1; d < dim; ++d )
+ str << ";" << v[ d ];
+ std::string s = str.str( );
+ this->m_Parameters[ name ] = TParameter( Self::Index, TValues( s, s ) );
+ this->Modified( );
+}
// -------------------------------------------------------------------------
-#define cpPlugins_Interface_Parameters_SetIndexOrPointMacro( NAME, TYPE ) \
- template< class T > \
- T cpPlugins::Interface::Parameters:: \
- GetValueAs##NAME( const TString& name ) const \
- { \
- T val; \
- TParameters::const_iterator pIt = this->m_Parameters.find( name ); \
- if( pIt != this->m_Parameters.end( ) ) \
- { \
- if( pIt->second.first == Self::NAME ) \
- { \
- std::istringstream ss( pIt->second.second ); \
- std::string token; \
- unsigned int i = 0; \
- while( std::getline( ss, token, ',' ) ) \
- { \
- if( token != "" ) \
- val[ i++ ] = TYPE( std::atof( token.c_str( ) ) ); \
- } \
- } \
- } \
- return( val ); \
- }
-
-cpPlugins_Interface_Parameters_SetIndexOrPointMacro( Index, long );
-cpPlugins_Interface_Parameters_SetIndexOrPointMacro( Point, double );
+template< class P >
+void cpPlugins::Interface::Parameters::
+ConfigureAsPoint( const TString& name, const TUint& dim, const P& v )
+{
+ std::stringstream str;
+ str << v[ 0 ];
+ for( unsigned int d = 1; d < dim; ++d )
+ str << ";" << v[ d ];
+ std::string s = str.str( );
+ this->m_Parameters[ name ] = TParameter( Self::Point, TValues( s, s ) );
+ this->Modified( );
+}
+
+// -------------------------------------------------------------------------
+template< class I >
+I cpPlugins::Interface::Parameters::
+GetIndex( const TString& name, const TUint& dim ) const
+{
+ I v;
+ TParameters::const_iterator i = this->m_Parameters.find( name );
+ if( i != this->m_Parameters.end( ) )
+ {
+ if( i->second.first == Self::Index )
+ {
+ std::istringstream str( i->second.second.second );
+ std::string token;
+ unsigned int d = 0;
+ while( std::getline( str, token, ';' ) && d < dim )
+ {
+ v[ d ] = std::atoi( token.c_str( ) );
+ d++;
+
+ } // elihw
+ return( v );
+
+ } // fi
+
+ } // fi
+
+ // If parameter not found
+ for( unsigned int d = 0; d < dim; ++d )
+ v[ d ] = 0;
+ return( v );
+}
+
+// -------------------------------------------------------------------------
+template< class P >
+P cpPlugins::Interface::Parameters::
+GetPoint( const TString& name, const TUint& dim ) const
+{
+ P v;
+ TParameters::const_iterator i = this->m_Parameters.find( name );
+ if( i != this->m_Parameters.end( ) )
+ {
+ if( i->second.first == Self::Point )
+ {
+ std::istringstream str( i->second.second.second );
+ std::string token;
+ unsigned int d = 0;
+ while( std::getline( str, token, ';' ) && d < dim )
+ {
+ v[ d ] = std::atof( token.c_str( ) );
+ d++;
+
+ } // elihw
+ return( v );
+
+ } // fi
+
+ } // fi
+
+ // If parameter not found
+ for( unsigned int d = 0; d < dim; ++d )
+ v[ d ] = float( 0 );
+ return( v );
+}
// -------------------------------------------------------------------------
template< class I >
void cpPlugins::Interface::Parameters::
-GetValueAsIndexList( std::vector< I >& lst, const TString& name ) const
+GetIndexList(
+ std::vector< I >& lst, const TString& name, const TUint& dim
+ ) const
{
lst.clear( );
- TParameters::const_iterator pIt = this->m_Parameters.find( name );
- if( pIt == this->m_Parameters.end( ) )
+
+ TParameters::const_iterator i = this->m_Parameters.find( name );
+ if( i == this->m_Parameters.end( ) )
return;
- if( pIt->second.first != Self::IndexList )
+ if( i->second.first == Self::IndexList )
return;
- std::istringstream ss( pIt->second.second );
+ std::istringstream str( i->second.second.second );
std::string token;
- while( std::getline( ss, token, ':' ) )
+ unsigned int d = 0;
+ while( std::getline( str, token, '#' ) )
{
- if( token != "" )
+ std::istringstream str2( token );
+ std::string token2;
+ unsigned int d = 0;
+ I v;
+ while( std::getline( str2, token2, ';' ) && d < dim )
{
- std::istringstream ts( token );
- std::string text;
- unsigned int i = 0;
- I idx;
- while( std::getline( ts, text, ',' ) )
- if( text != "" )
- idx[ i++ ] = std::atoi( text.c_str( ) );
- lst.push_back( idx );
+ v[ d ] = std::atoi( token.c_str( ) );
+ d++;
- } // fi
+ } // elihw
+ lst.push_back( v );
} // elihw
}
// -------------------------------------------------------------------------
template< class P >
void cpPlugins::Interface::Parameters::
-GetValueAsPointList( std::vector< P >& lst, const TString& name ) const
+GetPointList(
+ std::vector< P >& lst, const TString& name, const TUint& dim
+ ) const
{
lst.clear( );
- TParameters::const_iterator pIt = this->m_Parameters.find( name );
- if( pIt == this->m_Parameters.end( ) )
+
+ TParameters::const_iterator i = this->m_Parameters.find( name );
+ if( i == this->m_Parameters.end( ) )
return;
- if( pIt->second.first != Self::PointList )
+ if( i->second.first == Self::PointList )
return;
- std::istringstream ss( pIt->second.second );
+ std::istringstream str( i->second.second.second );
std::string token;
- while( std::getline( ss, token, ':' ) )
+ unsigned int d = 0;
+ while( std::getline( str, token, '#' ) )
{
- if( token != "" )
+ std::istringstream str2( token );
+ std::string token2;
+ unsigned int d = 0;
+ P v;
+ while( std::getline( str2, token2, ';' ) && d < dim )
{
- std::istringstream ts( token );
- std::string text;
- unsigned int i = 0;
- P pnt;
- while( std::getline( ts, text, ',' ) )
- if( text != "" )
- pnt[ i++ ] = std::atof( text.c_str( ) );
- lst.push_back( pnt );
+ v[ d ] = std::atof( token.c_str( ) );
+ d++;
- } // fi
+ } // elihw
+ lst.push_back( v );
} // elihw
}
+// -------------------------------------------------------------------------
+template< class I >
+void cpPlugins::Interface::Parameters::
+SetIndex( const TString& name, const TUint& dim, const I& v )
+{
+ TParameters::iterator i = this->m_Parameters.find( name );
+ if( i == this->m_Parameters.end( ) )
+ return;
+ if( i->second.first != Self::Index )
+ return;
+
+ std::stringstream str;
+ str << v[ 0 ];
+ for( unsigned int d = 1; d < dim; ++d )
+ str << ";" << v[ d ];
+ i->second.second.second = str.str( );
+ this->Modified( );
+}
+
+// -------------------------------------------------------------------------
+template< class P >
+void cpPlugins::Interface::Parameters::
+SetPoint( const TString& name, const TUint& dim, const P& v )
+{
+ TParameters::iterator i = this->m_Parameters.find( name );
+ if( i == this->m_Parameters.end( ) )
+ return;
+ if( i->second.first != Self::Point )
+ return;
+
+ std::stringstream str;
+ str << v[ 0 ];
+ for( unsigned int d = 1; d < dim; ++d )
+ str << ";" << v[ d ];
+ i->second.second.second = str.str( );
+ this->Modified( );
+}
+
+// -------------------------------------------------------------------------
+template< class I >
+void cpPlugins::Interface::Parameters::
+AddToIndexList( const TString& name, const TUint& dim, const I& v )
+{
+ TParameters::iterator i = this->m_Parameters.find( name );
+ if( i == this->m_Parameters.end( ) )
+ return;
+ if( i->second.first != Self::IndexList )
+ return;
+
+ std::stringstream str;
+ if( i->second.second.second == "" )
+ str << v[ 0 ];
+ else
+ str << "#" << v[ 0 ];
+ for( unsigned int d = 1; d < dim; ++d )
+ str << ";" << v[ d ];
+ i->second.second.second += str.str( );
+ this->Modified( );
+}
+
+// -------------------------------------------------------------------------
+template< class P >
+void cpPlugins::Interface::Parameters::
+AddToPointList( const TString& name, const TUint& dim, const P& v )
+{
+ TParameters::iterator i = this->m_Parameters.find( name );
+ if( i == this->m_Parameters.end( ) )
+ return;
+ if( i->second.first != Self::PointList )
+ return;
+
+ std::stringstream str;
+ if( i->second.second.second == "" )
+ str << v[ 0 ];
+ else
+ str << "#" << v[ 0 ];
+ for( unsigned int d = 1; d < dim; ++d )
+ str << ";" << v[ d ];
+ i->second.second.second += str.str( );
+ this->Modified( );
+}
+
#endif // __CPPLUGINS__INTERFACE__PARAMETERS__HXX__
// eof - $RCSfile$
// -------------------------------------------------------------------------
bool cpPlugins::Interface::
ParametersQtDialog(
- Parameters& parameters, const std::string& title, QWidget* parent
+ Parameters* parameters, const std::string& title, QWidget* parent
)
{
// Create dialog with a simple layout
verticalLayout->addWidget( dlg_title );
// Put values
- std::vector< std::string > names = parameters.GetParameters( );
+ std::vector< std::string > names;
+ parameters->GetNames( names );
std::vector< std::string >::const_iterator nIt = names.begin( );
for( ; nIt != names.end( ); ++nIt )
{
- Parameters::Type pt = parameters.GetParameterType( *nIt );
+ Parameters::Type pt = parameters->GetType( *nIt );
/* TODO
enum Type
{
QCheckBox* v_bool = new QCheckBox( dlg );
v_bool->setText( "[ON/OFF]" );
- v_bool->setChecked( parameters.GetValueAsBool( *nIt ) );
+ v_bool->setChecked( parameters->GetBool( *nIt ) );
w_input = v_bool;
}
else if( pt == Parameters::Uint )
QSpinBox* v_uint = new QSpinBox( dlg );
v_uint->setMinimum( 0 );
v_uint->setMaximum( std::numeric_limits< int >::max( ) );
- v_uint->setValue( parameters.GetValueAsUint( *nIt ) );
+ v_uint->setValue( parameters->GetUint( *nIt ) );
w_input = v_uint;
}
else if( pt == Parameters::Int )
QSpinBox* v_int = new QSpinBox( dlg );
v_int->setMinimum( -std::numeric_limits< int >::max( ) );
v_int->setMaximum( std::numeric_limits< int >::max( ) );
- v_int->setValue( parameters.GetValueAsInt( *nIt ) );
+ v_int->setValue( parameters->GetInt( *nIt ) );
w_input = v_int;
}
else if( pt == Parameters::Real )
v_double->setDecimals( 3 );
v_double->setMinimum( -std::numeric_limits< double >::max( ) );
v_double->setMaximum( std::numeric_limits< double >::max( ) );
- v_double->setValue( parameters.GetValueAsReal( *nIt ) );
+ v_double->setValue( parameters->GetReal( *nIt ) );
w_input = v_double;
}
else if(
nIt = names.begin( );
for( ; nIt != names.end( ); ++nIt )
{
- Parameters::Type pt = parameters.GetParameterType( *nIt );
+ Parameters::Type pt = parameters->GetType( *nIt );
if( pt == Parameters::String )
{
QLineEdit* v_string = dlg->findChild< QLineEdit* >( nIt->c_str( ) );
if( v_string != NULL )
- parameters.SetValueAsString( *nIt, v_string->text( ).toStdString( ) );
+ parameters->SetString( *nIt, v_string->text( ).toStdString( ) );
}
else if( pt == Parameters::Bool )
{
QCheckBox* v_bool = dlg->findChild< QCheckBox* >( nIt->c_str( ) );
if( v_bool != NULL )
- parameters.SetValueAsBool( *nIt, v_bool->isChecked( ) );
+ parameters->SetBool( *nIt, v_bool->isChecked( ) );
}
else if( pt == Parameters::Uint )
{
QSpinBox* v_uint = dlg->findChild< QSpinBox* >( nIt->c_str( ) );
if( v_uint != NULL )
- parameters.SetValueAsUint( *nIt, v_uint->value( ) );
+ parameters->SetUint( *nIt, v_uint->value( ) );
}
else if( pt == Parameters::Int )
{
QSpinBox* v_int = dlg->findChild< QSpinBox* >( nIt->c_str( ) );
if( v_int != NULL )
- parameters.SetValueAsInt( *nIt, v_int->value( ) );
+ parameters->SetInt( *nIt, v_int->value( ) );
}
else if( pt == Parameters::Real )
{
QDoubleSpinBox* v_double =
dlg->findChild< QDoubleSpinBox* >( nIt->c_str( ) );
if( v_double != NULL )
- parameters.SetValueAsReal( *nIt, v_double->value( ) );
+ parameters->SetReal( *nIt, v_double->value( ) );
}
else if(
pt == Parameters::StringList ||
{
std::vector< std::string > values = l_double->GetStringValues( );
for( int r = 0; r < values.size( ); ++r )
- parameters.AddValueToStringList( *nIt, values[ r ] );
+ parameters->AddToStringList( *nIt, values[ r ] );
}
else if( pt == Parameters::IntList )
{
std::vector< int > values = l_double->GetIntValues( );
for( int r = 0; r < values.size( ); ++r )
- parameters.AddValueToIntList( *nIt, values[ r ] );
+ parameters->AddToIntList( *nIt, values[ r ] );
}
else if( pt == Parameters::UintList )
{
std::vector< unsigned int > values = l_double->GetUintValues( );
for( int r = 0; r < values.size( ); ++r )
- parameters.AddValueToUintList( *nIt, values[ r ] );
+ parameters->AddToUintList( *nIt, values[ r ] );
}
else if( pt == Parameters::RealList )
{
std::vector< double > values = l_double->GetDoubleValues( );
for( int r = 0; r < values.size( ); ++r )
- parameters.AddValueToRealList( *nIt, values[ r ] );
+ parameters->AddToRealList( *nIt, values[ r ] );
} // fi
namespace Interface
{
bool cpPlugins_Interface_EXPORT ParametersQtDialog(
- Parameters& parameters,
+ Parameters* parameters,
const std::string& title,
QWidget* parent = NULL
);
#endif // cpPlugins_Interface_QT4
// -------------------------------------------------------------------------
-const cpPlugins::Interface::Parameters&
+void cpPlugins::Interface::ProcessObject::
+Modified( ) const
+{
+ if( this->m_ITKObject.IsNotNull( ) )
+ this->m_ITKObject->Modified( );
+ if( this->m_VTKObject.GetPointer( ) != NULL )
+ this->m_VTKObject->Modified( );
+ this->Superclass::Modified( );
+}
+
+// -------------------------------------------------------------------------
cpPlugins::Interface::ProcessObject::
-GetDefaultParameters( ) const
+TParameters* cpPlugins::Interface::ProcessObject::
+GetParameters( )
{
- return( this->m_DefaultParameters );
+ return( this->m_Parameters.GetPointer( ) );
}
// -------------------------------------------------------------------------
-void cpPlugins::Interface::ProcessObject::
-SetParameters( const cpPlugins::Interface::Parameters& params )
+const cpPlugins::Interface::ProcessObject::
+TParameters* cpPlugins::Interface::ProcessObject::
+GetParameters( ) const
{
- this->m_Parameters = params;
- this->Modified( );
+ return( this->m_Parameters.GetPointer( ) );
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
void cpPlugins::Interface::ProcessObject::
-SetNumberOfInputs( unsigned int n )
-{
- this->m_Inputs.clear( );
- this->m_Inputs.resize( n );
- this->Modified( );
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::Interface::ProcessObject::
-SetNumberOfOutputs( unsigned int n )
+SetInput( const std::string& id, cpPlugins::Interface::DataObject* dobj )
{
- this->m_Outputs.clear( );
- this->m_Outputs.resize( n );
- this->Modified( );
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::Interface::ProcessObject::
-SetInput( unsigned int idx, cpPlugins::Interface::DataObject* dobj )
-{
- if( idx < this->m_Inputs.size( ) )
+ _TDataContainer::iterator i = this->m_Inputs.find( id );
+ if( i != this->m_Inputs.end( ) )
{
- this->m_Inputs[ idx ] = dobj;
+ i->second = dobj;
this->Modified( );
} // fi
std::string r = "";
// Force upstream updates
- for( unsigned int i = 0; i < this->m_Inputs.size( ) && r == ""; ++i )
+ _TDataContainer::iterator i = this->m_Inputs.begin( );
+ for( ; i != this->m_Inputs.end( ) && r == ""; ++i )
{
- Self* src = dynamic_cast< Self* >( this->m_Inputs[ i ]->GetSource( ) );
+ Self* src = dynamic_cast< Self* >( i->second->GetSource( ) );
if( src != NULL )
r = src->Update( );
void cpPlugins::Interface::ProcessObject::
DisconnectOutputs( )
{
- for( unsigned int idx = 0; idx < this->m_Outputs.size( ); ++idx )
- if( this->m_Outputs[ idx ].IsNotNull( ) )
- this->m_Outputs[ idx ]->DisconnectPipeline( );
+ _TDataContainer::iterator i = this->m_Outputs.begin( );
+ for( ; i != this->m_Outputs.end( ); ++i )
+ if( i->second.IsNotNull( ) )
+ i->second->DisconnectPipeline( );
}
// -------------------------------------------------------------------------
#ifdef cpPlugins_Interface_QT4
- Parameters parameters = this->m_DefaultParameters;
r = cpPlugins::Interface::ParametersQtDialog(
- parameters,
+ this->m_Parameters,
this->GetClassName( ) + std::string( " basic configuration" ),
parent
);
- if( r )
- this->m_Parameters = parameters;
+ /*
+ if( r )
+ // TODO: !!! this->m_Parameters = parameters;
+ */
#endif // cpPlugins_Interface_QT4
m_ITKObject( NULL ),
m_VTKObject( NULL )
{
+ this->m_Parameters = TParameters::New( );
}
// -------------------------------------------------------------------------
{
}
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::ProcessObject::
+_AddInput( const std::string& name )
+{
+ this->m_Inputs[ name ] = NULL;
+ this->Modified( );
+}
+
// eof - $RCSfile$
#define __CPPLUGINS__INTERFACE__PROCESSOBJECT__H__
#include <cpPlugins/Interface/cpPlugins_Interface_Export.h>
+
+#include <map>
+
#include <cpPlugins/Interface/Config.h>
#include <cpPlugins/Interface/Object.h>
#include <cpPlugins/Interface/DataObject.h>
typedef itk::SmartPointer< Self > Pointer;
typedef itk::SmartPointer< const Self > ConstPointer;
+ typedef Parameters TParameters;
+
public:
itkTypeMacro( ProcessObject, Object );
cpPlugins_Id_Macro(
);
public:
- virtual const Parameters& GetDefaultParameters( ) const;
- virtual void SetParameters( const Parameters& params );
+ // To impact pipeline
+ virtual void Modified( ) const;
+
+ virtual TParameters* GetParameters( );
+ virtual const TParameters* GetParameters( ) const;
virtual unsigned int GetNumberOfInputs( ) const;
virtual unsigned int GetNumberOfOutputs( ) const;
- virtual void SetNumberOfInputs( unsigned int n );
- virtual void SetNumberOfOutputs( unsigned int n );
-
- virtual void SetInput( unsigned int idx, DataObject* dobj );
+ virtual void SetInput( const std::string& id, DataObject* dobj );
virtual std::string Update( );
virtual void DisconnectOutputs( );
inline const T* GetVTK( ) const;
template< class T >
- inline T* GetInput( unsigned int idx );
+ inline T* GetInput( const std::string& id );
template< class T >
- inline const T* GetInput( unsigned int idx ) const;
+ inline const T* GetInput( const std::string& id ) const;
template< class T >
- inline T* GetOutput( unsigned int idx );
+ inline T* GetOutput( const std::string& id );
template< class T >
- inline const T* GetOutput( unsigned int idx ) const;
+ inline const T* GetOutput( const std::string& id ) const;
protected:
ProcessObject( );
virtual ~ProcessObject( );
+ virtual void _AddInput( const std::string& name );
+
template< class F >
inline F* _CreateITK( );
inline F* _CreateVTK( );
template< class O >
- inline void _MakeOutput( unsigned int idx );
+ inline void _MakeOutput( const std::string& id );
virtual std::string _GenerateData( ) = 0;
itk::ProcessObject::Pointer m_ITKObject;
vtkSmartPointer< vtkAlgorithm > m_VTKObject;
- Parameters m_DefaultParameters;
- Parameters m_Parameters;
+ Parameters::Pointer m_Parameters;
- std::vector< DataObject::Pointer > m_Inputs;
- std::vector< DataObject::Pointer > m_Outputs;
+ typedef std::map< std::string, DataObject::Pointer > _TDataContainer;
+ _TDataContainer m_Inputs;
+ _TDataContainer m_Outputs;
};
} // ecapseman
// -------------------------------------------------------------------------
template< class T >
T* cpPlugins::Interface::ProcessObject::
-GetInput( unsigned int idx )
+GetInput( const std::string& id )
{
- if( idx < this->m_Inputs.size( ) )
- return( dynamic_cast< T* >( this->m_Inputs[ idx ].GetPointer( ) ) );
+ _TDataContainer::iterator i = this->m_Inputs.find( id );
+ if( i != this->m_Inputs.end( ) )
+ return( dynamic_cast< T* >( i->second.GetPointer( ) ) );
else
return( NULL );
}
// -------------------------------------------------------------------------
template< class T >
const T* cpPlugins::Interface::ProcessObject::
-GetInput( unsigned int idx ) const
+GetInput( const std::string& id ) const
{
- if( idx < this->m_Inputs.size( ) )
- return(
- dynamic_cast< const T* >( this->m_Inputs[ idx ].GetPointer( ) )
- );
+ _TDataContainer::const_iterator i = this->m_Inputs.find( id );
+ if( i != this->m_Inputs.end( ) )
+ return( dynamic_cast< const T* >( i->second.GetPointer( ) ) );
else
return( NULL );
}
// -------------------------------------------------------------------------
template< class T >
T* cpPlugins::Interface::ProcessObject::
-GetOutput( unsigned int idx )
+GetOutput( const std::string& id )
{
- if( idx < this->m_Outputs.size( ) )
- return( dynamic_cast< T* >( this->m_Outputs[ idx ].GetPointer( ) ) );
+ _TDataContainer::iterator i = this->m_Outputs.find( id );
+ if( i != this->m_Outputs.end( ) )
+ return( dynamic_cast< T* >( i->second.GetPointer( ) ) );
else
return( NULL );
}
// -------------------------------------------------------------------------
template< class T >
const T* cpPlugins::Interface::ProcessObject::
-GetOutput( unsigned int idx ) const
+GetOutput( const std::string& id ) const
{
- if( idx < this->m_Outputs.size( ) )
- return(
- dynamic_cast< const T* >( this->m_Outputs[ idx ].GetPointer( ) )
- );
+ _TDataContainer::const_iterator i = this->m_Outputs.find( id );
+ if( i != this->m_Outputs.end( ) )
+ return( dynamic_cast< const T* >( i->second.GetPointer( ) ) );
else
return( NULL );
}
// -------------------------------------------------------------------------
template< class O >
void cpPlugins::Interface::ProcessObject::
-_MakeOutput( unsigned int idx )
+_MakeOutput( const std::string& id )
{
- if( idx >= this->m_Outputs.size( ) )
- return;
- this->m_Outputs[ idx ] = O::New( );
- this->m_Outputs[ idx ]->SetSource( this );
+ this->m_Outputs[ id ] = O::New( );
+ this->m_Outputs[ id ]->SetSource( this );
+ this->Modified( );
}
#endif // __CPPLUGINS__INTERFACE__PROCESSOBJECT__HXX__
BinaryErodeImageFilter( )
: Superclass( )
{
- //this->m_ClassName = "cpPlugins::BasicFilters::BinaryErodeImageFilter";
- //this->m_ClassCategory = "ImageToImageFilter";
- this->SetNumberOfInputs( 1 );
- this->SetNumberOfOutputs( 1 );
- this->_MakeOutput< cpPlugins::Interface::Image >( 0 );
+ this->_AddInput( "Input" );
+ this->_MakeOutput< cpPlugins::Interface::Image >( "Output" );
- 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 );
}
// -------------------------------------------------------------------------
_GenerateData( )
{
cpPlugins::Interface::Image* image =
- this->GetInput< cpPlugins::Interface::Image >( 0 );
+ this->GetInput< cpPlugins::Interface::Image >( "Input" );
if( image == NULL )
return( "BinaryErodeImageFilter: No input 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
cpPlugins::Interface::Image* out =
- this->GetOutput< cpPlugins::Interface::Image >( 0 );
+ this->GetOutput< cpPlugins::Interface::Image >( "Output" );
if( out != NULL )
{
out->SetITK< O >( filter->GetOutput( ) );
BinaryThresholdImageFilter( )
: Superclass( )
{
- this->SetNumberOfInputs( 1 );
- this->SetNumberOfOutputs( 1 );
- this->_MakeOutput< cpPlugins::Interface::Image >( 0 );
+ this->_AddInput( "Input" );
+ this->_MakeOutput< cpPlugins::Interface::Image >( "Output" );
- 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", 10000 );
+ this->m_Parameters->ConfigureAsUint( "InsideValue", 1 );
+ this->m_Parameters->ConfigureAsUint( "OutsideValue", 0 );
}
// -------------------------------------------------------------------------
_GenerateData( )
{
cpPlugins::Interface::Image* image =
- this->GetInput< cpPlugins::Interface::Image >( 0 );
+ this->GetInput< cpPlugins::Interface::Image >( "Input" );
if( image == NULL )
return( "BinaryThresholdImageFilter: No input 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( "LowerThresholdValue" ) );
+ _IP upper_val = _IP( this->m_Parameters->GetReal( "UpperThresholdValue" ) );
+ _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 >( );
// Connect output
cpPlugins::Interface::Image* out =
- this->GetOutput< cpPlugins::Interface::Image >( 0 );
+ this->GetOutput< cpPlugins::Interface::Image >( "Output" );
if( out != NULL )
{
out->SetITK< O >( filter->GetOutput( ) );
);
cpPlugins_Id_Macro(
cpPlugins::BasicFilters::BinaryThresholdImageFilter,
- "ImageToImageFilter"
+ "ImageToBinaryImageFilter"
);
protected:
Cutter( )
: Superclass( )
{
- this->SetNumberOfInputs( 2 );
- this->SetNumberOfOutputs( 1 );
- this->_MakeOutput< cpPlugins::Interface::Mesh >( 0 );
-
- this->m_Parameters = this->m_DefaultParameters;
+ this->_AddInput( "InputMesh" );
+ this->_AddInput( "InputFunction" );
+ this->_MakeOutput< cpPlugins::Interface::Mesh >( "Output" );
}
// -------------------------------------------------------------------------
{
// Get inputs
cpPlugins::Interface::Mesh* mesh =
- this->GetInput< cpPlugins::Interface::Mesh >( 0 );
+ this->GetInput< cpPlugins::Interface::Mesh >( "InputMesh" );
cpPlugins::Interface::ImplicitFunction* function =
- this->GetInput< cpPlugins::Interface::ImplicitFunction >( 1 );
+ this->GetInput< cpPlugins::Interface::ImplicitFunction >(
+ "InputFunction"
+ );
if( function == NULL )
return( "Cutter: Input data 1 is not a valid implicit function." );
// Execute filter
cpPlugins::Interface::Mesh* out =
- this->GetOutput< cpPlugins::Interface::Mesh >( 0 );
+ this->GetOutput< cpPlugins::Interface::Mesh >( "Output" );
out->SetVTK( cutter->GetOutput( ) );
return( "" );
ExtractSliceImageFilter( )
: Superclass( )
{
- this->SetNumberOfInputs( 1 );
- this->SetNumberOfOutputs( 1 );
- this->_MakeOutput< cpPlugins::Interface::Image >( 0 );
+ this->_AddInput( "Input" );
+ this->_MakeOutput< cpPlugins::Interface::Image >( "Output" );
- 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 );
}
// -------------------------------------------------------------------------
_GenerateData( )
{
cpPlugins::Interface::Image* image =
- this->GetInput< cpPlugins::Interface::Image >( 0 );
+ this->GetInput< cpPlugins::Interface::Image >( "Input" );
if( image == NULL )
return( "ExtractSliceImageFilter: No input 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 );
region.SetSize( size );
region.SetIndex( index );
- std::cout << "HOLA-: " << region << std::endl;
-
// Configure filter
_F* filter = this->_CreateITK< _F >( );
filter->SetInput( img );
// Connect output
cpPlugins::Interface::Image* out =
- this->GetOutput< cpPlugins::Interface::Image >( 0 );
+ this->GetOutput< cpPlugins::Interface::Image >( "Output" );
if( out != NULL )
{
out->SetITK< O >( filter->GetOutput( ) );
FloodFillImageFilter( )
: Superclass( )
{
- this->SetNumberOfInputs( 1 );
- 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;
+ this->_AddInput( "Input" );
+ this->_MakeOutput< cpPlugins::Interface::Image >( "Output" );
+
+ double seed[ 3 ] = { double( 0 ) };
+ this->m_Parameters->ConfigureAsPoint( "Seed", 3, seed );
+ this->m_Parameters->ConfigureAsReal( "Window", 0 );
+ this->m_Parameters->ConfigureAsReal( "Level", 0 );
+ this->m_Parameters->ConfigureAsUint( "InsideValue", 0 );
+ this->m_Parameters->ConfigureAsUint( "OutsideValue", 255 );
}
// -------------------------------------------------------------------------
_GenerateData( )
{
cpPlugins::Interface::Image* image =
- this->GetInput< cpPlugins::Interface::Image >( 0 );
+ this->GetInput< cpPlugins::Interface::Image >( "Input" );
if( image == NULL )
return( "FloodFillImageFilter: No input image." );
itkImageFunction
);
+ itkSetMacro( Window, double );
+ itkSetMacro( Level, double );
+
public:
virtual bool Evaluate( const TPoint& point ) const
{
}
virtual bool EvaluateAtIndex( const TIndex& index ) const
{
- return( true );
+ if( !( this->IsInsideBuffer( index ) ) )
+ return( false );
+
+ const I* image = this->GetInputImage( );
+ double w2 = this->m_Window / double( 2 );
+ double min = this->m_Level - w2;
+ double max = this->m_Level + w2;
+ unsigned char val = double( 0 );
+ double x = double( image->GetPixel( index ) );
+ double m = double( 100 ) / this->m_Window;
+ double b = ( this->m_Window - ( double( 2 ) * this->m_Level ) );
+ b *= double( 50 ) / this->m_Window;
+ if( x > min && x < max )
+ val = ( unsigned char )( ( m * x ) + b );
+
+ if( this->m_Start )
+ {
+ this->m_StartValue = val;
+ this->m_Start = false;
+ return( true );
+ }
+ else
+ return( std::abs( this->m_StartValue - val ) <= 2 );
}
virtual bool EvaluateAtContinuousIndex( const TCIndex& index ) const
{
protected:
cpPlugins_BasicFilters_FloodFillImageFilter_Function( )
- : Superclass( )
+ : Superclass( ),
+ m_Window( double( 0 ) ),
+ m_Level( double( 0 ) ),
+ m_Start( true )
{
}
virtual ~cpPlugins_BasicFilters_FloodFillImageFilter_Function( )
// Purposely not implemented
cpPlugins_BasicFilters_FloodFillImageFilter_Function( const Self& other );
Self& operator=( const Self& other );
+
+protected:
+ double m_Window;
+ double m_Level;
+ mutable unsigned char m_StartValue;
+ mutable bool m_Start;
};
// -------------------------------------------------------------------------
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
+ );
+ double window = this->m_Parameters->GetReal( "Window" );
+ double level = this->m_Parameters->GetReal( "Level" );
+ _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;
out->FillBuffer( out_val );
typename _F::Pointer f = _F::New( );
+ f->SetInputImage( in );
+ f->SetWindow( window );
+ f->SetLevel( level );
_It i( in, f );
i.AddSeed( seed );
// Connect output
cpPlugins::Interface::Image* out_port =
- this->GetOutput< cpPlugins::Interface::Image >( 0 );
+ this->GetOutput< cpPlugins::Interface::Image >( "Output" );
if( out_port != NULL )
{
out_port->SetITK< O >( out );
);
cpPlugins_Id_Macro(
cpPlugins::BasicFilters::FloodFillImageFilter,
- "ImageToImageFilter"
+ "ImageToBinaryImageFilter"
);
protected:
MarchingCubes( )
: Superclass( )
{
- this->SetNumberOfInputs( 1 );
- this->SetNumberOfOutputs( 1 );
- this->_MakeOutput< cpPlugins::Interface::Mesh >( 0 );
+ this->_AddInput( "Input" );
+ this->_MakeOutput< cpPlugins::Interface::Mesh >( "Output" );
- using namespace cpPlugins::Interface;
- this->m_DefaultParameters.Configure( Parameters::RealList, "Thresholds" );
- this->m_Parameters = this->m_DefaultParameters;
+ this->m_Parameters->ConfigureAsRealList( "Thresholds" );
}
// -------------------------------------------------------------------------
{
// Get input
cpPlugins::Interface::Image* image =
- this->GetInput< cpPlugins::Interface::Image >( 0 );
+ this->GetInput< cpPlugins::Interface::Image >( "Input" );
if( image == NULL )
return( "MarchingCubes: Input data is not a valid image." );
vtkImageData* vtk_image = image->GetVTK< vtkImageData >( );
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 )
{
// Execute filter
cpPlugins::Interface::Mesh* out =
- this->GetOutput< cpPlugins::Interface::Mesh >( 0 );
+ this->GetOutput< cpPlugins::Interface::Mesh >( "Output" );
out->SetVTK( pd );
return( "" );
}
MedianImageFilter( )
: Superclass( )
{
- this->SetNumberOfInputs( 1 );
- this->SetNumberOfOutputs( 1 );
- this->_MakeOutput< cpPlugins::Interface::Image >( 0 );
+ this->_AddInput( "Input" );
+ this->_MakeOutput< cpPlugins::Interface::Image >( "Output" );
- 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 );
}
// -------------------------------------------------------------------------
_GenerateData( )
{
cpPlugins::Interface::Image* image =
- this->GetInput< cpPlugins::Interface::Image >( 0 );
+ this->GetInput< cpPlugins::Interface::Image >( "Input" );
if( image == NULL )
return( "MedianImageFilter: No input 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 >( );
// Connect output
cpPlugins::Interface::Image* out =
- this->GetOutput< cpPlugins::Interface::Image >( 0 );
+ this->GetOutput< cpPlugins::Interface::Image >( "Output" );
if( out != NULL )
{
out->SetITK< O >( filter->GetOutput( ) );
OtsuThresholdImageFilter( )
: Superclass( )
{
- this->SetNumberOfInputs( 1 );
- this->SetNumberOfOutputs( 1 );
- this->_MakeOutput< cpPlugins::Interface::Image >( 0 );
+ this->_AddInput( "Input" );
+ this->_MakeOutput< cpPlugins::Interface::Image >( "Output" );
- 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 );
}
// -------------------------------------------------------------------------
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 >( );
// Connect output
cpPlugins::Interface::Image* out =
- this->GetOutput< cpPlugins::Interface::Image >( 0 );
+ this->GetOutput< cpPlugins::Interface::Image >( "Output" );
if( out != NULL )
{
out->SetITK< O >( filter->GetOutput( ) );
{
typedef cpPlugins::Interface::Parameters TParameters;
- this->SetNumberOfInputs( 1 );
- this->SetNumberOfOutputs( 1 );
- this->_MakeOutput< cpPlugins::Interface::Image >( 0 );
+ this->_AddInput( "Input" );
+ this->_MakeOutput< cpPlugins::Interface::Image >( "Output" );
- 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 );
}
// -------------------------------------------------------------------------
_GenerateData( )
{
cpPlugins::Interface::Image* image =
- this->GetInput< cpPlugins::Interface::Image >( 0 );
+ this->GetInput< cpPlugins::Interface::Image >( "Input" );
if( image == NULL )
return( "RGBImageToOtherChannelsFilter: No input 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;
// Connect output
cpPlugins::Interface::Image* out =
- this->GetOutput< cpPlugins::Interface::Image >( 0 );
+ this->GetOutput< cpPlugins::Interface::Image >( "Output" );
if( out != NULL )
{
out->SetITK< _O >( filter->GetOutput( ) );
SphereMeshSource( )
: Superclass( )
{
- this->SetNumberOfInputs( 0 );
- 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;
+ this->_MakeOutput< cpPlugins::Interface::Mesh >( "Output" );
+
+ 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 );
}
// -------------------------------------------------------------------------
_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 ] );
// Execute filter
cpPlugins::Interface::Mesh* out =
- this->GetOutput< cpPlugins::Interface::Mesh >( 0 );
+ this->GetOutput< cpPlugins::Interface::Mesh >( "Output" );
out->SetVTK( src->GetOutput( ) );
return( "" );
}
dialog.setNameFilter( QFileDialog::tr( "All files (*)" ) );
if( dialog.exec( ) )
{
- this->m_Parameters = this->m_DefaultParameters;
QStringList names = dialog.selectedFiles( );
QStringList::const_iterator qIt = names.begin( );
for( ; qIt != names.end( ); ++qIt )
- this->m_Parameters.AddValueToStringList(
+ this->m_Parameters->AddToStringList(
"FileNames", qIt->toStdString( )
);
- this->m_Parameters.SetValueAsBool( "VectorType", false );
+ this->m_Parameters->SetBool( "VectorType", false );
r = true;
} // fi
ImageReader( )
: Superclass( )
{
- this->SetNumberOfOutputs( 1 );
- this->_MakeOutput< cpPlugins::Interface::Image >( 0 );
+ this->_MakeOutput< cpPlugins::Interface::Image >( "Output" );
- using namespace cpPlugins::Interface;
- this->m_DefaultParameters.Configure( Parameters::StringList, "FileNames" );
- this->m_DefaultParameters.Configure( Parameters::Bool, "VectorType" );
- this->m_DefaultParameters.SetValueAsBool( "VectorType", false );
- this->m_Parameters = this->m_DefaultParameters;
+ this->m_Parameters->ConfigureAsStringList( "FileNames" );
+ this->m_Parameters->ConfigureAsBool( "VectorType", false );
}
// -------------------------------------------------------------------------
{
// Get filenames
TStringList names;
- this->m_Parameters.GetValueAsStringList( names, "FileNames" );
+ this->m_Parameters->GetStringList( names, "FileNames" );
std::string r = "";
if( names.size( ) >= 1 )
std::string cpPlugins::IO::ImageReader::
_GD1( const TStringList& names )
{
- if( this->m_Parameters.GetValueAsBool( "VectorType" ) )
+ if( this->m_Parameters->GetBool( "VectorType" ) )
return( this->_RealGD< itk::VectorImage< P, D > >( names ) );
else
return( this->_RealGD< itk::Image< P, D > >( names ) );
_RealGD( const TStringList& names )
{
cpPlugins::Interface::Image* out =
- this->GetOutput< cpPlugins::Interface::Image >( 0 );
+ this->GetOutput< cpPlugins::Interface::Image >( "Output" );
if( out == NULL )
return( "ImageReader: No output object properly created." );
{
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
}
{
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
}
typedef itk::SmartPointer< Self > Pointer;
typedef itk::SmartPointer< const Self > ConstPointer;
- typedef
- std::vector< cpPlugins::Interface::Parameters::TString >
- TStringList;
+ typedef Superclass::TParameters TParameters;
+ typedef std::vector< TParameters::TString > TStringList;
public:
itkNewMacro( Self );
ImageWriter( )
: Superclass( )
{
- this->SetNumberOfInputs( 1 );
+ this->_AddInput( "Input" );
- using namespace cpPlugins::Interface;
- this->m_DefaultParameters.Configure( Parameters::String, "FileName" );
- this->m_Parameters = this->m_DefaultParameters;
+ this->m_Parameters->ConfigureAsString( "FileName", "" );
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
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 >( "Input" );
+ 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 );
+ this->GetInput< cpPlugins::Interface::Image >( "Input" );
if( image == NULL )
return( "ImageWriter: No input image." );
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 );
- else */r = "ImageWriter: Input image type not supported.";
+ cpPlugins_VectorImage_Demangle_AllTypes( D, image, itk_image, r, _RealGD );
+ else r = "ImageWriter: Input image type not supported.";
return( r );
}
_RealGD( itk::DataObject* image )
{
// Get filename
- std::string fname = this->m_Parameters.GetValueAsString( "FileName" );
+ std::string fname = this->m_Parameters->GetString( "FileName" );
typedef itk::ImageFileWriter< I > _W;
_W* writer = this->_CreateITK< _W >( );
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 );
dialog.setNameFilter( QFileDialog::tr( "All files (*)" ) );
if( dialog.exec( ) )
{
- this->m_Parameters = this->m_DefaultParameters;
QStringList names = dialog.selectedFiles( );
- this->m_Parameters.SetValueAsString(
- "FileName", names[ 0 ].toStdString( )
- );
-
- /* TODO
- this->m_Parameters.SetValueAsString( "PixelType", "float" );
- this->m_Parameters.SetValueAsUint( "Dimension", 3 );
- */
+ this->m_Parameters->SetString( "FileName", names[ 0 ].toStdString( ) );
+ this->m_Parameters->SetSelectedChoice( "PixelType", "float" );
+ this->m_Parameters->SetUint( "Dimension", 3 );
r = true;
MeshReader( )
: Superclass( )
{
- this->SetNumberOfOutputs( 1 );
- this->_MakeOutput< cpPlugins::Interface::Mesh >( 0 );
-
- using namespace cpPlugins::Interface;
- this->m_DefaultParameters.Configure( Parameters::String, "FileName" );
- this->m_DefaultParameters.Configure( Parameters::String, "PixelType" );
- this->m_DefaultParameters.Configure( Parameters::Uint, "Dimension" );
- this->m_DefaultParameters.SetValueAsString( "PixelType", "float" );
- this->m_DefaultParameters.SetValueAsUint( "Dimension", 3 );
- this->m_Parameters = this->m_DefaultParameters;
+ this->_MakeOutput< cpPlugins::Interface::Mesh >( "Output" );
+
+ std::vector< TParameters::TString > valid_types;
+ valid_types.push_back( "float" );
+ valid_types.push_back( "double" );
+ this->m_Parameters->ConfigureAsString( "FileName", "" );
+ this->m_Parameters->ConfigureAsChoices( "PixelType", valid_types );
+ this->m_Parameters->ConfigureAsUint( "Dimension", 3 );
}
// -------------------------------------------------------------------------
_GenerateData( )
{
using namespace cpPlugins::Interface;
- Parameters::TUint dim = this->m_Parameters.GetValueAsUint( "Dimension" );
+ Parameters::TUint dim = this->m_Parameters->GetUint( "Dimension" );
std::string r = "MeshReader: Mesh dimension not supported.";
if( dim == 2 )
r = this->_GD0< 2 >( );
_GD0( )
{
using namespace cpPlugins::Interface;
- Parameters::TString pt = this->m_Parameters.GetValueAsString( "PixelType" );
+ Parameters::TString pt =
+ this->m_Parameters->GetSelectedChoice( "PixelType" );
std::string r = "MeshReader: Mesh pixel type not supported";
if( pt == "float" ) r = this->_GD1< float, D >( );
else if( pt == "double" ) r = this->_GD1< double, D >( );
_GD1( )
{
// Get filename
- using namespace cpPlugins::Interface;
- Parameters::TString fname =
- this->m_Parameters.GetValueAsString( "FileName" );
+ std::string fname = this->m_Parameters->GetString( "FileName" );
vtkPolyDataReader* pdr = this->_CreateVTK< vtkPolyDataReader >( );
pdr->SetFileName( fname.c_str( ) );
pdr->Update( );
cpPlugins::Interface::Mesh* out =
- this->GetOutput< cpPlugins::Interface::Mesh >( 0 );
+ this->GetOutput< cpPlugins::Interface::Mesh >( "Output" );
if( out != NULL )
out->SetVTK( pdr->GetOutput( ) );
else
MeshWriter( )
: Superclass( )
{
- this->SetNumberOfInputs( 1 );
+ this->_AddInput( "Input" );
- using namespace cpPlugins::Interface;
- this->m_DefaultParameters.Configure( Parameters::String, "FileName" );
- this->m_Parameters = this->m_DefaultParameters;
+ this->m_Parameters->ConfigureAsString( "FileName", "" );
}
// -------------------------------------------------------------------------
_GenerateData( )
{
cpPlugins::Interface::Mesh* mesh =
- this->GetInput< cpPlugins::Interface::Mesh >( 0 );
+ this->GetInput< cpPlugins::Interface::Mesh >( "Input" );
if( mesh == NULL )
return( "MeshWriter: No input mesh." );
vtkPolyData* i = mesh->GetVTK< vtkPolyData >( );
if( i == NULL )
return( "MeshWriter: No suitable input." );
- std::string fname = this->m_Parameters.GetValueAsString( "FileName" );
+ std::string fname = this->m_Parameters->GetString( "FileName" );
vtkPolyDataWriter* pdw = this->_CreateVTK< vtkPolyDataWriter >( );
pdw->SetInputData( i );
#include <Pluma/DLibrary.hpp>\r
#include <cstdio>\r
#include <string>\r
+#include <stdexcept>\r
\r
\r
namespace pluma{\r
////////////////////////////////////////////////////////////\r
DLibrary* DLibrary::load(const std::string& path){\r
if ( path.empty() ){\r
- fprintf(stderr, "Failed to load library: Empty path\n");\r
+ // fprintf(stderr, "Failed to load library: Empty path\n");\r
+ throw std::runtime_error( "Failed to load library: Empty path." );\r
return NULL;\r
}\r
void* handle = NULL;\r
#ifdef PLUMA_SYS_WINDOWS\r
handle = ::LoadLibraryA(path.c_str());\r
if (!handle){\r
- fprintf(stderr, "Failed to load library \"%s\".\n", path.c_str());\r
- return NULL;\r
+ //fprintf(stderr, "Failed to load library \"%s\".\n", path.c_str());\r
+ throw std::runtime_error(\r
+ std::string( "Failed to load library \"" ) +\r
+ path +\r
+ std::string( "\"." )\r
+ );\r
+ return NULL;\r
}\r
#else\r
handle = ::dlopen(path.c_str(), RTLD_NOW);\r
if (!handle){\r
const char* errorString = ::dlerror();\r
- fprintf(stderr, "Failed to load library \"%s\".", path.c_str());\r
- if(errorString) fprintf(stderr, " OS returned error: \"%s\".", errorString);\r
- fprintf(stderr, "\n");\r
+ std::string error_text = "Failed to load library \"";\r
+ // fprintf(stderr, "Failed to load library \"%s\".", path.c_str());\r
+ if(errorString) error_text += std::string( errorString ); // fprintf(stderr, " OS returned error: \"%s\".", errorString);\r
+ // fprintf(stderr, "\n");\r
+ throw std::runtime_error( error_text + std::string( "\"." ) );\r
return NULL;\r
}\r
#endif\r
////////////////////////////////////////////////////////////\r
void* DLibrary::getSymbol(const std::string& symbol){\r
if (!handle){\r
- fprintf(stderr, "Cannot inspect library symbols, library isn't loaded.\n");\r
+ //fprintf(stderr, "Cannot inspect library symbols, library isn't loaded.\n");\r
+ throw std::runtime_error( "Cannot inspect library symbols, library isn't loaded." );\r
return NULL;\r
}\r
void* res;\r
res = (void*)(::dlsym(handle, symbol.c_str()));\r
#endif\r
if (!res){\r
- fprintf(stderr, "Library symbol \"%s\" not found.\n", symbol.c_str());\r
- return NULL;\r
+ // fprintf(stderr, "Library symbol \"%s\" not found.\n", symbol.c_str());\r
+ throw std::runtime_error(\r
+ std::string( "Library symbol \"" ) +\r
+ symbol +\r
+ std::string( "\" not found." )\r
+ );\r
+ return NULL;\r
}\r
return res;\r
}\r
#include <Pluma/uce-dirent.h>\r
#include <cstdio>\r
#include <queue>\r
+#include <stdexcept>\r
\r
\r
namespace pluma{\r
dir = opendir(folder.c_str());\r
if (dir == NULL){\r
// could not open directory\r
- fprintf(stderr, "Could not open \"%s\" directory.\n", folder.c_str());\r
+ // fprintf(stderr, "Could not open \"%s\" directory.\n", folder.c_str());\r
+ throw std::runtime_error(\r
+ std::string( "Could not open \"" ) +\r
+ folder +\r
+ std::string( "\" directory." )\r
+ );\r
return;\r
}else{\r
// close, we'll process it next\r
////////////////////////////////////////////////////////////\r
#include <Pluma/Host.hpp>\r
#include <cstdio>\r
+#include <stdexcept>\r
\r
\r
namespace pluma{\r
////////////////////////////////////////////////////////////\r
bool Host::add(Provider* provider){\r
if (provider == NULL){\r
- fprintf(stderr, "Trying to add a null provider.\n");\r
+ //fprintf(stderr, "Trying to add a null provider.\n");\r
+ throw std::runtime_error( "Trying to add a null provider." );\r
return false;\r
}\r
if (!validateProvider(provider)){\r
bool Host::validateProvider(Provider* provider) const{\r
const std::string& type = provider->plumaGetType();\r
if ( !knows(type) ){\r
- fprintf(stderr, "%s provider type isn't registered.\n", type.c_str());\r
+ // fprintf(stderr, "%s provider type isn't registered.\n", type.c_str());\r
+ throw std::runtime_error(\r
+ type + std::string( " provider type isn't registered." )\r
+ );\r
return false;\r
}\r
if (!provider->isCompatible(*this)){\r
- fprintf(stderr, "Incompatible %s provider version.\n", type.c_str());\r
+ // fprintf(stderr, "Incompatible %s provider version.\n", type.c_str());\r
+ throw std::runtime_error(\r
+ std::string( "Incompatible " ) +\r
+ type +\r
+ std::string( " provider version." )\r
+ );\r
return false;\r
}\r
return true;\r
#include <Pluma/DLibrary.hpp>\r
#include <Pluma/Dir.hpp>\r
#include <cstdio>\r
+#include <stdexcept>\r
\r
namespace pluma{\r
\r
registerFunction = reinterpret_cast<fnRegisterPlugin*>(lib->getSymbol("connect"));\r
\r
if(!registerFunction){\r
- fprintf(stderr, "Failed to initialize plugin \"%s\": connect function not found\n", plugName.c_str());\r
+ //fprintf(stderr, "Failed to initialize plugin \"%s\": connect function not found\n", plugName.c_str());\r
delete lib;\r
+ throw std::runtime_error(\r
+ std::string( "Failed to initialize plugin \"" ) +\r
+ plugName +\r
+ std::string( "\": connect function not found" )\r
+ );\r
return false;\r
}\r
// try to initialize plugin:\r
if (!registerFunction(host)){\r
// plugin decided to fail\r
- fprintf(stderr, "Self registry failed on plugin \"%s\".\n", plugName.c_str());\r
+ // fprintf(stderr, "Self registry failed on plugin \"%s\".\n", plugName.c_str());\r
host.cancelAddictions();\r
delete lib;\r
+ throw std::runtime_error(\r
+ std::string( "Self registry failed on plugin \"" ) +\r
+ plugName +\r
+ std::string( "\"" )\r
+ );\r
return false;\r
}\r
// Store the library if addictions are confirmed\r
libraries[plugName] = lib;\r
else{\r
// otherwise nothing was registered\r
- fprintf(stderr, "Nothing registered by plugin \"%s\".\n", plugName.c_str());\r
+ // fprintf(stderr, "Nothing registered by plugin \"%s\".\n", plugName.c_str());\r
delete lib;\r
+ throw std::runtime_error(\r
+ std::string( "Nothing registered by plugin \"" ) +\r
+ plugName +\r
+ std::string( "\"." )\r
+ );\r
return false;\r
}\r
return true;\r
////////////////////////////////////////////////////////////\r
bool PluginManager::addProvider(Provider* provider){\r
if (provider == NULL){\r
- fprintf(stderr, "Trying to add null provider\n");\r
+ // fprintf(stderr, "Trying to add null provider\n");\r
+ throw std::runtime_error( "Trying to add null provider." );\r
return false;\r
}\r
return host.registerProvider(provider);\r