From 93ddd2fe04d05b28dff31448032fd3af93ffe750 Mon Sep 17 00:00:00 2001 From: Leonardo Florez-Valencia Date: Mon, 15 Dec 2014 18:06:12 +0100 Subject: [PATCH] New plugin added --- .../CMakeLists.txt | 5 +- .../InteractorStyleImage.cxx | 493 ------------ .../InteractorStyleImage.h | 190 ----- .../MainWnd.cxx | 530 +++--------- .../MainWnd.h | 66 +- .../MainWnd_ExecutePlugins.cxx | 188 +++++ .../MainWnd_LoadPlugins.cxx | 98 ++- .../SegmentationParametersDlg.ui | 149 ---- .../VolumeActors.cxx | 757 ------------------ .../VolumeActors.h | 203 ----- .../idms.plugins.in | 2 + lib/cpm/CMakeLists.txt | 10 + lib/cpm/Plugins/CMakeLists.txt | 37 + lib/cpm/Plugins/Host.cxx | 12 + lib/cpm/Plugins/SimpleFillRegion.cxx | 35 + lib/cpm/Plugins/SimpleFillRegion.h | 45 ++ 16 files changed, 513 insertions(+), 2307 deletions(-) delete mode 100644 appli/InteractiveDeformableMeshSegmentation/InteractorStyleImage.cxx delete mode 100644 appli/InteractiveDeformableMeshSegmentation/InteractorStyleImage.h create mode 100644 appli/InteractiveDeformableMeshSegmentation/MainWnd_ExecutePlugins.cxx delete mode 100644 appli/InteractiveDeformableMeshSegmentation/SegmentationParametersDlg.ui delete mode 100644 appli/InteractiveDeformableMeshSegmentation/VolumeActors.cxx delete mode 100644 appli/InteractiveDeformableMeshSegmentation/VolumeActors.h create mode 100644 lib/cpm/Plugins/CMakeLists.txt create mode 100644 lib/cpm/Plugins/Host.cxx create mode 100644 lib/cpm/Plugins/SimpleFillRegion.cxx create mode 100644 lib/cpm/Plugins/SimpleFillRegion.h diff --git a/appli/InteractiveDeformableMeshSegmentation/CMakeLists.txt b/appli/InteractiveDeformableMeshSegmentation/CMakeLists.txt index a5691be..e61acbb 100644 --- a/appli/InteractiveDeformableMeshSegmentation/CMakeLists.txt +++ b/appli/InteractiveDeformableMeshSegmentation/CMakeLists.txt @@ -12,12 +12,11 @@ IF(BUILD_FINAL_APPLICATION) App_QT_SOURCES MainWnd.cxx MainWnd_LoadPlugins.cxx + MainWnd_ExecutePlugins.cxx ) SET( App_SOURCES main.cxx - VolumeActors.cxx - InteractorStyleImage.cxx ) SET( App_QT_HEADERS @@ -25,8 +24,6 @@ IF(BUILD_FINAL_APPLICATION) ) SET( App_HEADERS - VolumeActors.h - InteractorStyleImage.h ) FILE(GLOB App_QT_UI "${App_SOURCE_DIR}/*.ui") FILE(GLOB App_QT_RES "${App_SOURCE_DIR}/*.qrc") diff --git a/appli/InteractiveDeformableMeshSegmentation/InteractorStyleImage.cxx b/appli/InteractiveDeformableMeshSegmentation/InteractorStyleImage.cxx deleted file mode 100644 index f192117..0000000 --- a/appli/InteractiveDeformableMeshSegmentation/InteractorStyleImage.cxx +++ /dev/null @@ -1,493 +0,0 @@ -#include "InteractorStyleImage.h" -#include "VolumeActors.h" - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// ------------------------------------------------------------------------- -int idms::InteractorStyleImage::SliceEvent = vtkCommand::UserEvent + 1; - -// ------------------------------------------------------------------------- -idms::InteractorStyleImage:: -Self* idms::InteractorStyleImage:: -New( ) -{ - return( new Self( ) ); -} - -// ------------------------------------------------------------------------- -void idms::InteractorStyleImage:: -Configure( VolumeActors* actors, const int& axis ) -{ - this->Actors = actors; - this->Axis = axis; - this->SetModeToNavigation( ); - - if( axis == 0 ) - this->PropPicker->AddPickList( actors->GetXPlaneActor( ) ); - else if( axis == 1 ) - this->PropPicker->AddPickList( actors->GetYPlaneActor( ) ); - else // if( axis == 2 ) - this->PropPicker->AddPickList( actors->GetZPlaneActor( ) ); - - this->Modified( ); -} - -// ------------------------------------------------------------------------- -void idms::InteractorStyleImage:: -SetModeToNavigation( ) -{ - this->Mode = Self::NavigationMode; -} - -// ------------------------------------------------------------------------- -void idms::InteractorStyleImage:: -SetModeToDeformation( ) -{ - this->Mode = Self::DeformationMode; -} - -// ------------------------------------------------------------------------- -void idms::InteractorStyleImage:: -SetInteractor( vtkRenderWindowInteractor* rwi ) -{ - this->Superclass::SetInteractor( rwi ); - this->OrientationWidget->SetInteractor( rwi ); - this->LineWdg->SetInteractor( rwi ); - if( rwi == NULL ) - return; - - rwi->SetPicker( this->PropPicker ); - - // Enable 2D orientation widget - this->OrientationWidget->SetEnabled( 1 ); - this->OrientationWidget->InteractiveOff( ); - - // Disable line widget - this->LineWdg->SetEnabled( 0 ); - - // Get camera, avoiding segfaults - vtkRenderer* ren = - rwi->GetRenderWindow( )->GetRenderers( )->GetFirstRenderer( ); - if( ren == NULL ) - return; - vtkCamera* cam = ren->GetActiveCamera( ); - if( cam == NULL ) - return; - - // Parallel projections are better when displaying 2D images - cam->ParallelProjectionOn( ); - cam->SetFocalPoint( double( 0 ), double( 0 ), double( 0 ) ); - this->Plane->SetOrigin( double( 0 ), double( 0 ), double( 0 ) ); - if( this->Axis == 0 ) - { - cam->SetPosition( double( 1 ), double( 0 ), double( 0 ) ); - cam->SetViewUp ( double( 0 ), double( 1 ), double( 0 ) ); - this->Plane->SetNormal( double( 1 ), double( 0 ), double( 0 ) ); - } - else if( this->Axis == 1 ) - { - cam->SetPosition( double( 0 ), double( 1 ), double( 0 ) ); - cam->SetViewUp ( double( 0 ), double( 0 ), double( -1 ) ); - this->Plane->SetNormal( double( 0 ), double( 1 ), double( 0 ) ); - } - else // if( this->Axis == 2 ) - { - cam->SetPosition( double( 0 ), double( 0 ), double( 1 ) ); - cam->SetViewUp ( double( 0 ), double( 1 ), double( 0 ) ); - this->Plane->SetNormal( double( 0 ), double( 0 ), double( 1 ) ); - - } // fi -} - -// ------------------------------------------------------------------------- -void idms::InteractorStyleImage:: -OnMouseMove( ) -{ - if( this->Mode == Self::DeformationMode ) - this->_UpdateCursor( ); - - // Propagate event - this->Superclass::OnMouseMove( ); -} - -// ------------------------------------------------------------------------- -void idms::InteractorStyleImage:: -OnLeftButtonDown( ) -{ - if( this->Mode == Self::DeformationMode ) - { - vtkRenderWindowInteractor* rwi = this->GetInteractor( ); - if( this->Actors != NULL && rwi != NULL ) - { - if( rwi->GetShiftKey( ) == 1 ) - { - this->Actors->GetRegionActor( )->GetProperty( )->SetOpacity( 0.3 ); - this->UpdatingRegion = true; - } - else - this->Superclass::OnLeftButtonDown( ); - } - else - this->Superclass::OnLeftButtonDown( ); - } - else if( this->Mode == Self::NavigationMode ) - this->Superclass::OnLeftButtonDown( ); -} - -// ------------------------------------------------------------------------- -void idms::InteractorStyleImage:: -OnLeftButtonUp( ) -{ - if( this->Mode == Self::DeformationMode ) - { - vtkRenderWindowInteractor* rwi = this->GetInteractor( ); - if( this->Actors != NULL && rwi != NULL ) - { - if( rwi->GetShiftKey( ) == 1 ) - { - this->Actors->GetRegionActor( )->GetProperty( )->SetOpacity( 0 ); - this->UpdatingRegion = false; - } - else - this->Superclass::OnLeftButtonUp( ); - } - else - this->Superclass::OnLeftButtonUp( ); - } - else if( this->Mode == Self::NavigationMode ) - this->Superclass::OnLeftButtonUp( ); -} - -// ------------------------------------------------------------------------- -void idms::InteractorStyleImage:: -OnMouseWheelForward( ) -{ - vtkRenderWindowInteractor* rwi = this->GetInteractor( ); - if( this->Actors == NULL || rwi == NULL ) - return; - int off = 1; - if( rwi->GetShiftKey( ) == 1 ) - off *= 10; - int s = this->Actors->GetSlice( this->Axis ) + off; - int maxs = this->Actors->GetSliceNumberMaxValue( this->Axis ); - this->Actors->SetSlice( this->Axis, ( s < maxs )? s: maxs ); - this->Actors->Render( ); - - if( this->Mode == Self::DeformationMode ) - this->_UpdateCursor( ); - - this->InvokeEvent( Self::SliceEvent, &( this->Axis ) ); -} - -// ------------------------------------------------------------------------- -void idms::InteractorStyleImage:: -OnMouseWheelBackward( ) -{ - vtkRenderWindowInteractor* rwi = this->GetInteractor( ); - if( this->Actors == NULL || rwi == NULL ) - return; - int off = 1; - if( rwi->GetShiftKey( ) == 1 ) - off *= 10; - int s = this->Actors->GetSlice( this->Axis ) - off; - int mins = this->Actors->GetSliceNumberMinValue( this->Axis ); - this->Actors->SetSlice( this->Axis, ( s < mins )? mins: s ); - this->Actors->Render( ); - - if( this->Mode == Self::DeformationMode ) - this->_UpdateCursor( ); - - this->InvokeEvent( Self::SliceEvent, &( this->Axis ) ); -} - -// ------------------------------------------------------------------------- -void idms::InteractorStyleImage:: -OnChar( ) -{ - vtkRenderWindowInteractor* rwi = this->GetInteractor( ); - if( rwi == NULL ) - return; - - switch( rwi->GetKeyCode( ) ) - { - case 'r': case 'R': - { - vtkRenderer* ren = - rwi->GetRenderWindow( )->GetRenderers( )->GetFirstRenderer( ); - if( ren != NULL ) - { - double bounds[ 6 ]; - this->Actors->GetImageBounds( bounds ); - ren->ResetCamera( bounds ); - rwi->Render( ); - - } // fi - } - break; - case 'l': case 'L': - { - this->Actors->ResetWindowLevel( ); - this->Actors->Render( ); - } - break; - case 's': case 'S': - { - int idx[ 3 ]; - idx[ 0 ] = this->Actors->GetSlice( 0 ); - idx[ 1 ] = this->Actors->GetSlice( 1 ); - idx[ 2 ] = this->Actors->GetSlice( 2 ); - this->Actors->AddSeed( idx ); - } - break; - default: - break; - } // hctiws -} - -// ------------------------------------------------------------------------- -void idms::InteractorStyleImage:: -Pan( ) -{ - if( this->Mode == Self::DeformationMode ) - { - this->Actors->Render( ); - } - else if( this->Mode == Self::NavigationMode ) - this->Superclass::Pan( ); -} - -// ------------------------------------------------------------------------- -void idms::InteractorStyleImage:: -Spin( ) -{ - if( this->Mode == Self::NavigationMode ) - { - double pos[ 3 ]; - if( this->_PickPosition( pos ) ) - { - if( this->Axis != 0 ) this->Actors->SetSlice( 0, pos[ 0 ] ); - if( this->Axis != 1 ) this->Actors->SetSlice( 1, pos[ 1 ] ); - if( this->Axis != 2 ) this->Actors->SetSlice( 2, pos[ 2 ] ); - this->Actors->Render( ); - - } // fi - } - else if( this->Mode == Self::DeformationMode ) - { - // TODO - - } // fi -} - -// ------------------------------------------------------------------------- -void idms::InteractorStyleImage:: -StartWindowLevel( ) -{ - if( this->Mode == Self::NavigationMode ) - { - if( this->State != VTKIS_NONE ) - return; - this->StartState( VTKIS_WINDOW_LEVEL ); - - this->WindowLevelInitial[ 0 ] = this->Actors->GetWindow( ); - this->WindowLevelInitial[ 1 ] = this->Actors->GetLevel( ); - } - else if( this->Mode == Self::DeformationMode ) - { - // TODO - - } // fi -} - -// ------------------------------------------------------------------------- -void idms::InteractorStyleImage:: -WindowLevel( ) -{ - if( this->Mode == Self::NavigationMode ) - { - vtkRenderWindowInteractor* rwi = this->GetInteractor( ); - if( rwi == NULL ) - return; - vtkRenderer* ren = - rwi->GetRenderWindow( )->GetRenderers( )->GetFirstRenderer( ); - if( ren == NULL ) - return; - - // Compute scales - this->WindowLevelCurrentPosition[ 0 ] = rwi->GetEventPosition( )[ 0 ]; - this->WindowLevelCurrentPosition[ 1 ] = rwi->GetEventPosition( )[ 1 ]; - int* size = ren->GetSize( ); - double sw = double( - this->WindowLevelCurrentPosition[ 0 ] - - this->WindowLevelStartPosition[ 0 ] - ) / double( size[ 0 ] ); - double sl = ( - this->WindowLevelStartPosition[ 1 ] - - this->WindowLevelCurrentPosition[ 1 ] - ) / double( size[ 1 ] ); - - double w = this->WindowLevelInitial[ 0 ] * ( double( 1 ) + sw ); - double l = this->WindowLevelInitial[ 1 ] * ( double( 1 ) + sl ); - double minw = this->Actors->GetMinWindow( ); - double maxw = this->Actors->GetMaxWindow( ); - double minl = this->Actors->GetMinLevel( ); - double maxl = this->Actors->GetMaxLevel( ); - - if( w < minw ) w = minw; - if( maxw < w ) w = maxw; - if( l < minl ) l = minl; - if( maxl < l ) l = maxl; - - this->Actors->SetWindowLevel( w, l ); - this->Actors->Render( ); - } - else if( this->Mode == Self::DeformationMode ) - { - // TODO - - } // fi -} - -// ------------------------------------------------------------------------- -idms::InteractorStyleImage:: -InteractorStyleImage( ) - : Superclass( ), - Mode( Self::NavigationMode ), - Actors( NULL ), - Axis( 2 ) -{ - // Orientation marks - vtkSmartPointer< vtkAnnotatedCubeActor > cube = - vtkSmartPointer< vtkAnnotatedCubeActor >::New( ); - cube->GetCubeProperty( )->SetColor( 0.9, 0.7, 0.2 ); - cube->GetTextEdgesProperty( )->SetLineWidth( 1 ); - cube->GetTextEdgesProperty( )->SetDiffuse( 0 ); - cube->GetTextEdgesProperty( )->SetAmbient( 1 ); - cube->GetTextEdgesProperty( )->SetColor( 0.18, 0.28, 0.23 ); - cube->GetXPlusFaceProperty( )->SetColor( 1, 0, 0 ); - cube->GetXPlusFaceProperty( )->SetInterpolationToFlat( ); - cube->GetXMinusFaceProperty( )->SetColor( 1, 0, 0 ); - cube->GetXMinusFaceProperty( )->SetInterpolationToFlat( ); - cube->GetYPlusFaceProperty( )->SetColor( 0, 1, 0 ); - cube->GetYPlusFaceProperty( )->SetInterpolationToFlat( ); - cube->GetYMinusFaceProperty( )->SetColor( 0, 1, 0 ); - cube->GetYMinusFaceProperty( )->SetInterpolationToFlat( ); - cube->GetZPlusFaceProperty( )->SetColor( 0, 0, 1 ); - cube->GetZPlusFaceProperty( )->SetInterpolationToFlat( ); - cube->GetZMinusFaceProperty( )->SetColor( 0, 0, 1 ); - cube->GetZMinusFaceProperty( )->SetInterpolationToFlat( ); - - vtkSmartPointer< vtkAxesActor > axes = - vtkSmartPointer< vtkAxesActor >::New( ); - axes->AxisLabelsOff( ); - axes->SetShaftTypeToCylinder( ); - axes->SetTotalLength( 2, 2, 2 ); - - vtkSmartPointer< vtkPropAssembly > actors = - vtkSmartPointer< vtkPropAssembly >::New( ); - actors->AddPart( cube ); - actors->AddPart( axes ); - - this->OrientationWidget = - vtkSmartPointer< vtkOrientationMarkerWidget >::New( ); - this->OrientationWidget->SetOutlineColor( 0.93, 0.57, 0.13 ); - this->OrientationWidget->SetOrientationMarker( actors ); - this->OrientationWidget->SetViewport( 0.0, 0.0, 0.2, 0.2 ); - - this->Plane = vtkSmartPointer< vtkPlane >::New( ); - - this->PropPicker = vtkSmartPointer< vtkPropPicker >::New( ); - this->PropPicker->PickFromListOn( ); - - this->LineRep = vtkSmartPointer< vtkLineRepresentation >::New( ); - this->LineWdg = vtkSmartPointer< vtkLineWidget2 >::New( ); - - this->LineWdg->SetRepresentation( this->LineRep ); -} - -// ------------------------------------------------------------------------- -idms::InteractorStyleImage:: -~InteractorStyleImage( ) -{ -} - -// ------------------------------------------------------------------------- -bool idms::InteractorStyleImage:: -_PickPosition( double pos[ 3 ] ) -{ - vtkRenderWindowInteractor* rwi = this->GetInteractor( ); - if( this->Actors == NULL || rwi == NULL ) - return( false ); - this->FindPokedRenderer( - rwi->GetEventPosition( )[ 0 ], - rwi->GetEventPosition( )[ 1 ] - ); - int success = rwi->GetPicker( )->Pick( - rwi->GetEventPosition( )[ 0 ], - rwi->GetEventPosition( )[ 1 ], - 0.0, - this->CurrentRenderer - ); - if( success == 0 ) - return( false ); - - /* - vtkAbstractPropPicker* picker = - vtkAbstractPropPicker::SafeDownCast( rwi->GetPicker( ) ); - if( picker != NULL ) - { - */ - this->PropPicker->GetPickPosition( pos ); - return( true ); - /* - } - else - return( false ); - */ -} - -// ------------------------------------------------------------------------- -void idms::InteractorStyleImage:: -_UpdateCursor( ) -{ - double p[ 3 ]; - if( this->_PickPosition( p ) ) - { - this->Actors->SetCursorPosition( p ); - if( this->UpdatingRegion ) - this->Actors->SetRegionRadius( p ); - else - this->Actors->SetRegionPosition( p ); - this->Actors->RenderAuxiliaryInteractors( ); - - /* TODO - double c[ 3 ]; - int i[ 3 ]; - vtkImageData* img = this->Actors->GetImage( ); - bool inside = ( img->ComputeStructuredCoordinates( p, i, c ) != 0 ); - if( inside ) - { - std::cout - << i[ 0 ] << " " - << i[ 1 ] << " " - << i[ 2 ] - << std::endl; - - } // fi - */ - } // fi -} - -// eof - $RCSfile$ diff --git a/appli/InteractiveDeformableMeshSegmentation/InteractorStyleImage.h b/appli/InteractiveDeformableMeshSegmentation/InteractorStyleImage.h deleted file mode 100644 index 87acbfd..0000000 --- a/appli/InteractiveDeformableMeshSegmentation/InteractorStyleImage.h +++ /dev/null @@ -1,190 +0,0 @@ -#ifndef __IDMS__INTERACTORSTYLEIMAGE__H__ -#define __IDMS__INTERACTORSTYLEIMAGE__H__ - -#include -#include -#include -#include -#include -#include -#include - -class vtkImageData; - -namespace idms -{ - class VolumeActors; - - /** - */ - class InteractorStyleImage - : public vtkInteractorStyleImage - { - public: - typedef InteractorStyleImage Self; - - enum InteractionMode - { - NavigationMode = 0, - DeformationMode - }; - - public: - vtkTypeMacro( InteractorStyleImage, vtkInteractorStyleImage ); - - public: - static Self* New( ); - - void Configure( VolumeActors* actors, const int& axis ); - - void SetModeToNavigation( ); - void SetModeToDeformation( ); - virtual void SetInteractor( vtkRenderWindowInteractor* interactor ); - - // Description: - // Event bindings controlling the effects of pressing mouse buttons - // or moving the mouse. - virtual void OnMouseMove( ); - virtual void OnLeftButtonDown( ); - virtual void OnLeftButtonUp( ); - /* - virtual void OnMiddleButtonDown( ); - virtual void OnMiddleButtonUp( ); - virtual void OnRightButtonDown( ); - virtual void OnRightButtonUp( ); - */ - virtual void OnMouseWheelForward( ); - virtual void OnMouseWheelBackward( ); - - // Description: - // Override the "fly-to" (f keypress) for images. - virtual void OnChar( ); - - // These methods for the different interactions in different modes - // are overridden in subclasses to perform the correct motion. Since - // they might be called from OnTimer, they do not have mouse coord - // parameters (use interactor's GetEventPosition and GetLastEventPosition) - virtual void Rotate( ) - { - std::cout << "Rotate" << std::endl; - } - virtual void Pan( ); - virtual void Spin( ); - virtual void Zoom( ) - { - std::cout << "Zoom" << std::endl; - } - virtual void StartWindowLevel( ); - virtual void WindowLevel( ); - virtual void Pick( ) - { - std::cout << "Pick" << std::endl; - } - virtual void Slice( ) - { - std::cout << "Slice" << std::endl; - } - - // Interaction mode entry points used internally. - /* - virtual void StartWindowLevel(); - virtual void EndWindowLevel(); - virtual void StartPick(); - virtual void EndPick(); - virtual void StartSlice(); - virtual void EndSlice(); - */ - - // Description: - // Set/Get current mode to 2D or 3D. The default is 2D. In 3D mode, - // it is possible to rotate the camera to view oblique slices. In Slicing - // mode, it is possible to slice through the data, but not to generate oblique - // views by rotating the camera. - /* - vtkSetClampMacro(InteractionMode, int, VTKIS_IMAGE2D, VTKIS_IMAGE_SLICING); - vtkGetMacro(InteractionMode, int); - void SetInteractionModeToImage2D() { - this->SetInteractionMode(VTKIS_IMAGE2D); } - void SetInteractionModeToImage3D() { - this->SetInteractionMode(VTKIS_IMAGE3D); } - void SetInteractionModeToImageSlicing() { - this->SetInteractionMode(VTKIS_IMAGE_SLICING); } - */ - - // Description: - // Set the orientations that will be used when the X, Y, or Z - // keys are pressed. See SetImageOrientation for more information. - /* - vtkSetVector3Macro(XViewRightVector, double); - vtkGetVector3Macro(XViewRightVector, double); - vtkSetVector3Macro(XViewUpVector, double); - vtkGetVector3Macro(XViewUpVector, double); - vtkSetVector3Macro(YViewRightVector, double); - vtkGetVector3Macro(YViewRightVector, double); - vtkSetVector3Macro(YViewUpVector, double); - vtkGetVector3Macro(YViewUpVector, double); - vtkSetVector3Macro(ZViewRightVector, double); - vtkGetVector3Macro(ZViewRightVector, double); - vtkSetVector3Macro(ZViewUpVector, double); - vtkGetVector3Macro(ZViewUpVector, double); - */ - - // Description: - // Set the view orientation, in terms of the horizontal and - // vertical directions of the computer screen. The first - // vector gives the direction that will correspond to moving - // horizontally left-to-right across the screen, and the - // second vector gives the direction that will correspond to - // moving bottom-to-top up the screen. This method changes - // the position of the camera to provide the desired view. - /* - void SetImageOrientation( - const double leftToRight[3], - const double bottomToTop[3]); - */ - - // Description: - // Get the current image property, which is set when StartWindowLevel - // is called immediately before StartWindowLevelEvent is generated. - // This is the image property of the topmost vtkImageSlice in the - // renderer or NULL if no image actors are present. - /* - vtkImageProperty *GetCurrentImageProperty() { - return this->CurrentImageProperty; } - */ - - protected: - InteractorStyleImage( ); - virtual ~InteractorStyleImage( ); - - bool _PickPosition( double pos[ 3 ] ); - void _UpdateCursor( ); - - private: - // Purposely not implemented - InteractorStyleImage( const Self& ); - Self& operator=( const Self& ); - - protected: - Self::InteractionMode Mode; - - vtkSmartPointer< vtkOrientationMarkerWidget > OrientationWidget; - VolumeActors* Actors; - int Axis; - vtkSmartPointer< vtkPlane > Plane; - vtkSmartPointer< vtkPropPicker > PropPicker; - - bool UpdatingRegion; - - vtkSmartPointer< vtkLineRepresentation > LineRep; - vtkSmartPointer< vtkLineWidget2 > LineWdg; - - public: - static int SliceEvent; - }; - -} // ecapseman - -#endif // __IDMS__INTERACTORSTYLEIMAGE__H__ - -// eof - $RCSfile$ diff --git a/appli/InteractiveDeformableMeshSegmentation/MainWnd.cxx b/appli/InteractiveDeformableMeshSegmentation/MainWnd.cxx index bbb9080..f6d38fa 100644 --- a/appli/InteractiveDeformableMeshSegmentation/MainWnd.cxx +++ b/appli/InteractiveDeformableMeshSegmentation/MainWnd.cxx @@ -28,7 +28,9 @@ MainWnd::MainWnd( QWidget* parent ) : QMainWindow( parent ), m_UI( new Ui::MainWnd ), m_InputImage( NULL ), - m_SegmentedImage( NULL ) + m_SegmentedImage( NULL ), + m_ActivePlugin( NULL ), + m_ActiveParameters( NULL ) { this->m_UI->setupUi( this ); @@ -37,88 +39,59 @@ MainWnd::MainWnd( QWidget* parent ) this->m_PluginsConfigurationFile = "idms.plugins"; this->_LoadApplicationPreferences( ); - // Create and associate renderers - this->m_3DRenderer = vtkSmartPointer< vtkRenderer >::New( ); - this->m_XPlaneRenderer = vtkSmartPointer< vtkRenderer >::New( ); - this->m_YPlaneRenderer = vtkSmartPointer< vtkRenderer >::New( ); - this->m_ZPlaneRenderer = vtkSmartPointer< vtkRenderer >::New( ); - this->m_AuxRenderer = vtkSmartPointer< vtkRenderer >::New( ); - this->m_3DRenderer->SetBackground( 0.2, 0.2, 0.2 ); - this->m_XPlaneRenderer->SetBackground( 0.1, 0.3, 0.8 ); - this->m_YPlaneRenderer->SetBackground( 0.1, 0.3, 0.8 ); - this->m_ZPlaneRenderer->SetBackground( 0.1, 0.3, 0.8 ); - this->m_AuxRenderer->SetBackground( 0.1, 0.3, 0.8 ); - this->m_UI->m_3DVTK->GetRenderWindow( )-> - AddRenderer( this->m_3DRenderer ); - this->m_UI->m_XPlaneVTK->GetRenderWindow( )-> - AddRenderer( this->m_XPlaneRenderer ); - this->m_UI->m_YPlaneVTK->GetRenderWindow( )-> - AddRenderer( this->m_YPlaneRenderer ); - this->m_UI->m_ZPlaneVTK->GetRenderWindow( )-> - AddRenderer( this->m_ZPlaneRenderer ); - this->m_UI->m_AuxVTK->GetRenderWindow( )-> - AddRenderer( this->m_AuxRenderer ); - - // Configure MPR actors - this->m_ImageActors = vtkSmartPointer< idms::VolumeActors >::New( ); - - // Interaction styles - this->m_XStyle = vtkSmartPointer< idms::InteractorStyleImage >::New( ); - this->m_YStyle = vtkSmartPointer< idms::InteractorStyleImage >::New( ); - this->m_ZStyle = vtkSmartPointer< idms::InteractorStyleImage >::New( ); - this->m_XStyle->Configure( this->m_ImageActors, 0 ); - this->m_YStyle->Configure( this->m_ImageActors, 1 ); - this->m_ZStyle->Configure( this->m_ImageActors, 2 ); - this->m_UI->m_XPlaneVTK->GetInteractor( )-> - SetInteractorStyle( this->m_XStyle ); - this->m_UI->m_YPlaneVTK->GetInteractor( )-> - SetInteractorStyle( this->m_YStyle ); - this->m_UI->m_ZPlaneVTK->GetInteractor( )-> - SetInteractorStyle( this->m_ZStyle ); + // Create MPR objects + this->m_MPR = new TMPR( + this->m_UI->m_XPlaneVTK->GetRenderWindow( ), + this->m_UI->m_YPlaneVTK->GetRenderWindow( ), + this->m_UI->m_ZPlaneVTK->GetRenderWindow( ), + this->m_UI->m_3DVTK->GetRenderWindow( ) + ); // Orientation marks - vtkSmartPointer< vtkAnnotatedCubeActor > oCube = - vtkSmartPointer< vtkAnnotatedCubeActor >::New( ); - oCube->GetCubeProperty( )->SetColor( 0.9, 0.7, 0.2 ); - oCube->GetTextEdgesProperty( )->SetLineWidth( 1 ); - oCube->GetTextEdgesProperty( )->SetDiffuse( 0 ); - oCube->GetTextEdgesProperty( )->SetAmbient( 1 ); - oCube->GetTextEdgesProperty( )->SetColor( 0.18, 0.28, 0.23 ); - oCube->GetXPlusFaceProperty( )->SetColor( 1, 0, 0 ); - oCube->GetXPlusFaceProperty( )->SetInterpolationToFlat( ); - oCube->GetXMinusFaceProperty( )->SetColor( 1, 0, 0 ); - oCube->GetXMinusFaceProperty( )->SetInterpolationToFlat( ); - oCube->GetYPlusFaceProperty( )->SetColor( 0, 1, 0 ); - oCube->GetYPlusFaceProperty( )->SetInterpolationToFlat( ); - oCube->GetYMinusFaceProperty( )->SetColor( 0, 1, 0 ); - oCube->GetYMinusFaceProperty( )->SetInterpolationToFlat( ); - oCube->GetZPlusFaceProperty( )->SetColor( 0, 0, 1 ); - oCube->GetZPlusFaceProperty( )->SetInterpolationToFlat( ); - oCube->GetZMinusFaceProperty( )->SetColor( 0, 0, 1 ); - oCube->GetZMinusFaceProperty( )->SetInterpolationToFlat( ); - - vtkSmartPointer< vtkAxesActor > oAxes = - vtkSmartPointer< vtkAxesActor >::New( ); - oAxes->AxisLabelsOff( ); - oAxes->SetShaftTypeToCylinder( ); - oAxes->SetTotalLength( 2.5, 2.5, 2.5 ); - - vtkSmartPointer< vtkPropAssembly > oActors = - vtkSmartPointer< vtkPropAssembly >::New( ); - oActors->AddPart( oCube ); - oActors->AddPart( oAxes ); - - this->m_3DOrientationWidget = - vtkSmartPointer< vtkOrientationMarkerWidget >::New( ); - this->m_3DOrientationWidget->SetOutlineColor( 0.93, 0.57, 0.13 ); - this->m_3DOrientationWidget->SetOrientationMarker( oActors ); - this->m_3DOrientationWidget->SetViewport( 0.0, 0.0, 0.2, 0.2 ); - - // Add actors, widgets, stuff, ... - this->m_3DOrientationWidget-> - SetInteractor( this->m_UI->m_3DVTK->GetInteractor( ) ); - this->m_3DOrientationWidget->SetEnabled( 1 ); - this->m_3DOrientationWidget->InteractiveOff( ); + /* TODO + vtkSmartPointer< vtkAnnotatedCubeActor > oCube = + vtkSmartPointer< vtkAnnotatedCubeActor >::New( ); + oCube->GetCubeProperty( )->SetColor( 0.9, 0.7, 0.2 ); + oCube->GetTextEdgesProperty( )->SetLineWidth( 1 ); + oCube->GetTextEdgesProperty( )->SetDiffuse( 0 ); + oCube->GetTextEdgesProperty( )->SetAmbient( 1 ); + oCube->GetTextEdgesProperty( )->SetColor( 0.18, 0.28, 0.23 ); + oCube->GetXPlusFaceProperty( )->SetColor( 1, 0, 0 ); + oCube->GetXPlusFaceProperty( )->SetInterpolationToFlat( ); + oCube->GetXMinusFaceProperty( )->SetColor( 1, 0, 0 ); + oCube->GetXMinusFaceProperty( )->SetInterpolationToFlat( ); + oCube->GetYPlusFaceProperty( )->SetColor( 0, 1, 0 ); + oCube->GetYPlusFaceProperty( )->SetInterpolationToFlat( ); + oCube->GetYMinusFaceProperty( )->SetColor( 0, 1, 0 ); + oCube->GetYMinusFaceProperty( )->SetInterpolationToFlat( ); + oCube->GetZPlusFaceProperty( )->SetColor( 0, 0, 1 ); + oCube->GetZPlusFaceProperty( )->SetInterpolationToFlat( ); + oCube->GetZMinusFaceProperty( )->SetColor( 0, 0, 1 ); + oCube->GetZMinusFaceProperty( )->SetInterpolationToFlat( ); + + vtkSmartPointer< vtkAxesActor > oAxes = + vtkSmartPointer< vtkAxesActor >::New( ); + oAxes->AxisLabelsOff( ); + oAxes->SetShaftTypeToCylinder( ); + oAxes->SetTotalLength( 2.5, 2.5, 2.5 ); + + vtkSmartPointer< vtkPropAssembly > oActors = + vtkSmartPointer< vtkPropAssembly >::New( ); + oActors->AddPart( oCube ); + oActors->AddPart( oAxes ); + + this->m_3DOrientationWidget = + vtkSmartPointer< vtkOrientationMarkerWidget >::New( ); + this->m_3DOrientationWidget->SetOutlineColor( 0.93, 0.57, 0.13 ); + this->m_3DOrientationWidget->SetOrientationMarker( oActors ); + this->m_3DOrientationWidget->SetViewport( 0.0, 0.0, 0.2, 0.2 ); + + // Add actors, widgets, stuff, ... + this->m_3DOrientationWidget-> + SetInteractor( this->m_UI->m_3DVTK->GetInteractor( ) ); + this->m_3DOrientationWidget->SetEnabled( 1 ); + this->m_3DOrientationWidget->InteractiveOff( ); + */ // Qt signals <-> slots IDMS_QT_ACTION( ReloadPlugins ); @@ -150,6 +123,14 @@ MainWnd:: // Delete objects delete this->m_UI; + delete this->m_MPR; + if( this->m_ActiveParameters != NULL ) + { + this->m_ActiveParameters->close( ); + delete this->m_ActiveParameters; + + } // fi + if( this->m_ActivePlugin != NULL ) delete this->m_ActivePlugin; if( this->m_InputImage != NULL ) delete this->m_InputImage; if( this->m_SegmentedImage != NULL ) delete this->m_SegmentedImage; } @@ -193,10 +174,9 @@ _LoadApplicationPreferences( ) // ------------------------------------------------------------------------- MainWnd:: -TPluginData* MainWnd:: +TPluginImage* MainWnd:: _LoadImage( const std::string& image_type, const std::string& image_dim ) { -/* // Show dialog and check if it was accepted QFileDialog dialog( this ); dialog.setFileMode( QFileDialog::ExistingFiles ); @@ -208,11 +188,11 @@ _LoadImage( const std::string& image_type, const std::string& image_dim ) if( !( dialog.exec( ) ) ) return( NULL ); - TPluginData* ret = NULL; + TPluginImage* ret = NULL; unsigned int nFiles = dialog.selectedFiles( ).size( ); if( nFiles == 1 ) { - if( this->m_ImageReaderClassName == "" ) + if( this->m_BaseClasses[ "ImageReader" ] == "" ) { QMessageBox::critical( this, @@ -228,7 +208,7 @@ _LoadImage( const std::string& image_type, const std::string& image_dim ) TPlugin* reader = dynamic_cast< TPlugin* >( - this->m_Plugins.CreateObject( this->m_ImageReaderClassName ) + this->m_Plugins.CreateObject( this->m_BaseClasses[ "ImageReader" ] ) ); TParameters reader_params = reader->GetDefaultParameters( ); @@ -241,7 +221,7 @@ _LoadImage( const std::string& image_type, const std::string& image_dim ) if( err == "" ) { - ret = reader->GetOutput( 0 ); + ret = dynamic_cast< TPluginImage* >( reader->GetOutput( 0 ) ); reader->DisconnectOutputs( ); } else @@ -251,27 +231,26 @@ _LoadImage( const std::string& image_type, const std::string& image_dim ) tr( err.c_str( ) ) ); delete reader; - return( ret ); } else if( nFiles > 1 ) { - if( this->m_ImageSeriesReaderClassName == "" ) - { - QMessageBox::critical( - this, - tr( "No plugin to read an image series found!" ), - tr( "No plugin to read an image series found!" ) - ); - return( ret ); - - } // fi + /* TODO + if( this->m_ImageSeriesReaderClassName == "" ) + { + QMessageBox::critical( + this, + tr( "No plugin to read an image series found!" ), + tr( "No plugin to read an image series found!" ) + ); + return( ret ); + + } // fi std::string fname = dialog.selectedFiles( ).at( 0 ).toStdString( ); this->m_LastOpenedFile = fname; - return( ret ); + */ } // fi return( ret ); -*/ } // ------------------------------------------------------------------------- @@ -287,27 +266,22 @@ _UpdateEnabledFlags( ) this->m_UI->m_ZPlaneVTK->setEnabled( img ); this->m_UI->m_AuxVTK->setEnabled( img ); - /* TODO - bool seg = this->m_Segmentation.IsNotNull( ); - this->m_UI->menuFilterSegmentedImage->setEnabled( seg ); - this->m_UI->menuExtractMesh->setEnabled( seg ); - this->m_UI->actionOpenMesh->setEnabled( seg ); - - this->m_UI->actionNavigation->setEnabled( img && seg ); - this->m_UI->actionSegmentationInteractiveDeformation-> - setEnabled( img && seg ); - */ + bool seg = ( this->m_SegmentedImage != NULL ); + this->m_UI->menuFilterSegmentedImage->setEnabled( seg ); + this->m_UI->menuExtractMesh->setEnabled( seg ); + this->m_UI->menuProcessMesh->setEnabled( seg ); + this->m_UI->actionOpenMesh->setEnabled( seg ); + + this->m_UI->actionNavigation->setEnabled( img && seg ); + this->m_UI->actionSegmentationInteractiveDeformation-> + setEnabled( img && seg ); } // ------------------------------------------------------------------------- void MainWnd:: _triggered_actionReloadPlugins( ) { - if( this->_LoadPlugins( ) ) - { - this->_UpdateEnabledFlags( ); - } - else + if( !( this->_LoadPlugins( ) ) ) { QMessageBox::critical( this, @@ -315,126 +289,8 @@ _triggered_actionReloadPlugins( ) tr( "Could not load plugins from given file." ) ); - } // fi - /* - this->m_Plugins.UnloadAll( ); - - this->m_ImageReaderClassName = ""; - this->m_ImageSeriesReaderClassName = ""; - this->m_ImageWriterClassName = ""; - - std::ifstream in( this->m_PluginsConfigurationFile.c_str( ) ); - if( in ) - { - std::string plugin; - std::getline( in, plugin ); - while( !( in.eof( ) ) ) - { - if( this->m_Plugins.Load( plugin ) ) - { - TPluginsInterface::TClassesIterator cIt = - this->m_Plugins.GetClasses( ).begin( ); - TPluginsInterface::TClassesIterator end_cIt = - this->m_Plugins.GetClasses( ).end( ); - for( ; cIt != end_cIt; ++cIt ) - { - std::string c_name = cIt->first; - c_name = c_name.substr( c_name.find_last_of( ":" ) + 1 ); - if( c_name == "ImageReader" ) - { - this->m_ImageReaderClassName = cIt->first; - } - else if( c_name == "ImageSeriesReader" ) - { - this->m_ImageSeriesReaderClassName = cIt->first; - } - else if( c_name == "ImageWriter" ) - { - this->m_ImageWriterClassName = cIt->first; - } - else - { - } // fi - - } // rof - - TFilterPlugins::TClassesIterator cIt = - this->m_Plugins.BeginClasses( ); - for( ; cIt != this->m_Plugins.EndClasses( ); ++cIt ) - { - TFilterObject* filter = - this->m_Plugins.CreateObject( cIt->first ); - if( filter == NULL ) - continue; - std::string cat = filter->GetCategory( ); - std::string catType = cat.substr( cat.find_last_of( ":" ) ); - if( catType == ":BinaryImageToBinaryImageFilter" ) - { - QAction* action = this->m_UI->menuFilterSegmentedImage-> - addAction( QString( cIt->first.c_str( ) ) ); - QObject::connect( - action, SIGNAL( triggered( ) ), - this, SLOT( triggered_aFilterSegmentedImage( ) ) - ); - } - else if( catType == ":ImageToMeshFilter" ) - { - QAction* action = this->m_UI->menuExtractMesh-> - addAction( QString( cIt->first.c_str( ) ) ); - QObject::connect( - action, SIGNAL( triggered( ) ), - this, SLOT( triggered_aSegmentedImageToMesh( ) ) - ); - - } // fi - delete filter; - } // rof - } - else - { - QMessageBox::warning( - this, - tr( "Ignoring plugin" ), - tr( plugin.c_str( ) ) - ); - - } // fi - std::getline( in, plugin ); - - } // elihw - } - else - { - QMessageBox::critical( - this, - tr( "No plugins file loaded!" ), - tr( this->m_PluginsConfigurationFile.c_str( ) ) - ); - - } // fi - in.close( ); - - if( this->m_ImageReaderClassName == "" ) - { - QMessageBox::critical( - this, - tr( "No ImageReader found in plugins!" ), - tr( this->m_PluginsConfigurationFile.c_str( ) ) - ); - - } // fi - - if( this->m_ImageWriterClassName == "" ) - { - QMessageBox::critical( - this, - tr( "No ImageWriter found in plugins!" ), - tr( this->m_PluginsConfigurationFile.c_str( ) ) - ); - } // fi this->_UpdateEnabledFlags( ); - */ } // ------------------------------------------------------------------------- @@ -450,40 +306,7 @@ _triggered_actionOpenInputImage( ) ); if( this->m_InputImage != NULL ) { - cpPlugins::Interface::Image* img = - dynamic_cast< cpPlugins::Interface::Image* >( this->m_InputImage ); - this->m_ImageActors->Configure( - img->GetVTKImageData( ), - this->m_UI->m_XPlaneVTK->GetInteractor( ), - this->m_UI->m_YPlaneVTK->GetInteractor( ), - this->m_UI->m_ZPlaneVTK->GetInteractor( ) - ); - this->m_ImageActors-> - AddAuxiliaryInteractor( this->m_UI->m_3DVTK->GetInteractor( ) ); - - // Associate actors - this->m_3DRenderer->AddActor( - this->m_ImageActors->GetImageOutlineActor( ) - ); - this->m_3DRenderer->AddActor( - this->m_ImageActors->GetXBoundsActor( ) - ); - this->m_3DRenderer->AddActor( - this->m_ImageActors->GetYBoundsActor( ) - ); - this->m_3DRenderer->AddActor( - this->m_ImageActors->GetZBoundsActor( ) - ); - - // Reset all cameras - this->m_3DRenderer->ResetCamera( ); - this->m_ImageActors->ResetCameras( ); - - // Ok, start! - this->m_UI->m_3DVTK->GetRenderWindow( )->Render( ); - this->m_UI->m_XPlaneVTK->GetRenderWindow( )->Render( ); - this->m_UI->m_YPlaneVTK->GetRenderWindow( )->Render( ); - this->m_UI->m_ZPlaneVTK->GetRenderWindow( )->Render( ); + this->m_MPR->SetImage( this->m_InputImage->GetVTKImageData( ) ); // Update activations this->_UpdateEnabledFlags( ); @@ -506,9 +329,14 @@ _triggered_actionOpenSegmentedImage( ) ); if( this->m_SegmentedImage != NULL ) { - cpPlugins::Interface::Image* img = - dynamic_cast< cpPlugins::Interface::Image* >( this->m_SegmentedImage ); - this->m_ImageActors->SetSegmentation( img->GetVTKImageData( ) ); + this->m_MPR->SetSegmentation( + this->m_SegmentedImage->GetVTKImageData( ) + ); + /* TODO + cpPlugins::Interface::Image* img = + dynamic_cast< cpPlugins::Interface::Image* >( this->m_SegmentedImage ); + this->m_ImageActors->SetSegmentation( img->GetVTKImageData( ) ); + */ // Ok, start! this->m_UI->m_XPlaneVTK->GetRenderWindow( )->Render( ); @@ -688,168 +516,6 @@ _ParametersDialog( TParameters& parameters ) return( false ); } - // ------------------------------------------------------------------------- - template< class I > - bool MainWnd:: - _LoadImage( typename I::Pointer& image ) - { - QStringList qList = - QFileDialog::getOpenFileNames( - this, - tr( "Open an image" ), - tr( this->m_LastOpenedFile.c_str( ) ), - tr( "Medical image files (*.mhd *.bin *.dcm);;All files (*)" ) - ); - if( qList.size( ) == 0 ) - return( false ); - - bool ret = true; - QStringList::Iterator fIt = qList.begin( ); - if( qList.size( ) == 1 ) - { - // Read a single image - std::string fn = fIt->toStdString( ); - this->m_LastOpenedFile = fn; - - typename itk::ImageFileReader< I >::Pointer reader = - itk::ImageFileReader< I >::New( ); - reader->SetFileName( fn ); - try - { - reader->Update( ); - } - catch( itk::ExceptionObject& err ) - { - QMessageBox::critical( - this, - tr( "Error opening single image!" ), - tr( err.GetDescription( ) ) - ); - ret = false; - - } // yrt - image = reader->GetOutput( ); - image->DisconnectPipeline( ); - } - else if( qList.size( ) > 1 ) - { - typedef std::set< std::string > _TOrderedStringList; - - // Read a slice set - _TOrderedStringList filenames; - for( ; fIt != qList.end( ); ++fIt ) - filenames.insert( fIt->toStdString( ) ); - typename itk::ImageSeriesReader< I >::Pointer reader = - itk::ImageSeriesReader< I >::New( ); - reader->SetImageIO( itk::GDCMImageIO::New( ) ); - _TOrderedStringList::const_iterator oIt = filenames.begin( ); - for( ; oIt != filenames.end( ); ++oIt ) - { - reader->AddFileName( *oIt ); - this->m_LastOpenedFile = *oIt; - - } // rof - try - { - reader->Update( ); - } - catch( itk::ExceptionObject& err ) - { - QMessageBox::critical( - this, - tr( "Error opening image series!" ), - tr( err.GetDescription( ) ) - ); - ret = false; - - } // yrt - image = reader->GetOutput( ); - image->DisconnectPipeline( ); - - } // fi - return( ret ); - } - -// ------------------------------------------------------------------------- -void MainWnd:: -triggered_aReloadPlugins( ) -{ -} - -// ------------------------------------------------------------------------- -void MainWnd:: -triggered_aOpenInputImage( ) -{ - if( this->_LoadImage< TImage >( this->m_Image ) ) - { - // Connect image to VTK - this->m_VTKImage = TVTKImage::New( ); - this->m_VTKImage->SetInput( this->m_Image ); - this->m_VTKImage->Update( ); - - this->m_ImageActors->Configure( - this->m_VTKImage->GetOutput( ), - this->m_UI->m_XPlaneVTK->GetInteractor( ), - this->m_UI->m_YPlaneVTK->GetInteractor( ), - this->m_UI->m_ZPlaneVTK->GetInteractor( ) - ); - this->m_ImageActors-> - AddAuxiliaryInteractor( this->m_UI->m_3DVTK->GetInteractor( ) ); - - // Associate actors - this->m_3DRenderer->AddActor( - this->m_ImageActors->GetImageOutlineActor( ) - ); - this->m_3DRenderer->AddActor( - this->m_ImageActors->GetXBoundsActor( ) - ); - this->m_3DRenderer->AddActor( - this->m_ImageActors->GetYBoundsActor( ) - ); - this->m_3DRenderer->AddActor( - this->m_ImageActors->GetZBoundsActor( ) - ); - - // Reset all cameras - this->m_3DRenderer->ResetCamera( ); - this->m_ImageActors->ResetCameras( ); - - // Ok, start! - this->m_UI->m_3DVTK->GetRenderWindow( )->Render( ); - this->m_UI->m_XPlaneVTK->GetRenderWindow( )->Render( ); - this->m_UI->m_YPlaneVTK->GetRenderWindow( )->Render( ); - this->m_UI->m_ZPlaneVTK->GetRenderWindow( )->Render( ); - this->_UpdateEnabledFlags( ); - this->m_UI->aNavigation->setChecked( true ); - this->triggered_aSwitchMode( ); - - } // fi -} - -// ------------------------------------------------------------------------- -void MainWnd:: -triggered_aOpenSegmentedImage( ) -{ - if( this->_LoadImage< TImage >( this->m_Segmentation ) ) - { - // Connect image to VTK - this->m_VTKSegmentation = TVTKImage::New( ); - this->m_VTKSegmentation->SetInput( this->m_Segmentation ); - this->m_VTKSegmentation->Update( ); - - this->m_ImageActors->SetSegmentation( - this->m_VTKSegmentation->GetOutput( ) - ); - - // Ok, start! - this->m_UI->m_XPlaneVTK->GetRenderWindow( )->Render( ); - this->m_UI->m_YPlaneVTK->GetRenderWindow( )->Render( ); - this->m_UI->m_ZPlaneVTK->GetRenderWindow( )->Render( ); - this->_UpdateEnabledFlags( ); - - } // fi -} - // ------------------------------------------------------------------------- void MainWnd:: triggered_aFilterSegmentedImage( ) diff --git a/appli/InteractiveDeformableMeshSegmentation/MainWnd.h b/appli/InteractiveDeformableMeshSegmentation/MainWnd.h index 1389cc8..3576ac5 100644 --- a/appli/InteractiveDeformableMeshSegmentation/MainWnd.h +++ b/appli/InteractiveDeformableMeshSegmentation/MainWnd.h @@ -7,6 +7,7 @@ // Qt stuff #include +#include // vtk stuff #include @@ -16,22 +17,9 @@ // Plugins interface #include #include +#include #include - -// Local stuff -#include "InteractorStyleImage.h" -#include "VolumeActors.h" - - -/* - #include - #include - - #include - - #include - #include -*/ +#include // ------------------------------------------------------------------------- namespace Ui @@ -52,8 +40,10 @@ public: typedef cpPlugins::Interface::Interface TPluginsInterface; typedef cpPlugins::Interface::Object TPluginObject; typedef cpPlugins::Interface::DataObject TPluginData; + typedef cpPlugins::Interface::Image TPluginImage; typedef cpPlugins::Interface::ProcessObject TPlugin; typedef TPlugin::TParameters TParameters; + typedef cpPlugins::Extensions::Visualization::MPRWithDifferentWindows TMPR; typedef std::map< std::string, std::string > TStringMap; @@ -65,16 +55,19 @@ protected: void _LoadApplicationPreferences( ); bool _LoadPlugins( ); bool _CheckClassesInPlugins( const TStringMap& classes ); - TPluginData* _LoadImage( + void _AddPluginActions( + const TStringMap& classes, QMenu* menu, const char* method + ); + TPluginImage* _LoadImage( const std::string& image_type, const std::string& image_dim ); void _UpdateEnabledFlags( ); + bool _ParametersDialog( const TParameters& parameters ); + /* TODO - bool _ParametersDialog( TParameters& parameters ); template< class I > */ - /* void _SliceMesh( int axis ); static void _SliceEventCallback( @@ -90,6 +83,10 @@ private slots: void _triggered_actionOpenSegmentedImage( ); void _triggered_actionSwitchMode( ); + void _triggered_actionSegmentImage( ); + void _triggered_actionFilterSegmentation( ); + void _triggered_actionProcessMesh( ); + /* TODO void triggered_aOpenSegmentedImage( ); void triggered_aFilterSegmentedImage( ); @@ -119,36 +116,15 @@ private: std::string m_LastOpenedFile; // Real data - TPluginData* m_InputImage; - TPluginData* m_SegmentedImage; - - /* TODO - // Inputs - TImage::Pointer m_Image; - TImage::Pointer m_Segmentation; - TMesh::Pointer m_Mesh; - TVTKImage::Pointer m_VTKImage; - TVTKImage::Pointer m_VTKSegmentation; - */ + TPluginImage* m_InputImage; + TPluginImage* m_SegmentedImage; // Visualization stuff - vtkSmartPointer< vtkRenderer > m_3DRenderer; - vtkSmartPointer< vtkRenderer > m_XPlaneRenderer; - vtkSmartPointer< vtkRenderer > m_YPlaneRenderer; - vtkSmartPointer< vtkRenderer > m_ZPlaneRenderer; - vtkSmartPointer< vtkRenderer > m_AuxRenderer; - vtkSmartPointer< idms::VolumeActors > m_ImageActors; - vtkSmartPointer< idms::InteractorStyleImage > m_XStyle; - vtkSmartPointer< idms::InteractorStyleImage > m_YStyle; - vtkSmartPointer< idms::InteractorStyleImage > m_ZStyle; - vtkSmartPointer< vtkOrientationMarkerWidget > m_3DOrientationWidget; + TMPR* m_MPR; - /* - TTriangulation::Pointer m_Mesh; - vtkSmartPointer< TTriangulationMapper > m_MeshMapper; - vtkSmartPointer< vtkActor > m_MeshActor; - TCutter::Pointer m_ZCutter; - */ + // Active plugin + TPlugin* m_ActivePlugin; + QWidget* m_ActiveParameters; }; #endif // __MAINWND__H__ diff --git a/appli/InteractiveDeformableMeshSegmentation/MainWnd_ExecutePlugins.cxx b/appli/InteractiveDeformableMeshSegmentation/MainWnd_ExecutePlugins.cxx new file mode 100644 index 0000000..8429a81 --- /dev/null +++ b/appli/InteractiveDeformableMeshSegmentation/MainWnd_ExecutePlugins.cxx @@ -0,0 +1,188 @@ +#include "MainWnd.h" +#include "ui_MainWnd.h" + +#include + +#include +#include + +// ------------------------------------------------------------------------- +bool MainWnd:: +_ParametersDialog( const TParameters& parameters ) +{ + if( this->m_ActiveParameters != NULL ) + this->m_ActiveParameters->close( ); + this->m_ActiveParameters = new QWidget( NULL ); + this->m_ActiveParameters->setWindowFlags( Qt::FramelessWindowHint ); + this->m_ActiveParameters->setWindowFlags( Qt::WindowTitleHint ); + + QGridLayout* gridLayout = new QGridLayout( this->m_ActiveParameters ); + QVBoxLayout* verticalLayout = new QVBoxLayout( ); + + // Put values + QLabel* title = new QLabel( this->m_ActiveParameters ); + title->setText( this->m_ActivePlugin->GetClassName( ).c_str( ) ); + verticalLayout->addWidget( title ); + + TParameters::const_iterator pIt = parameters.begin( ); + for( ; pIt != parameters.end( ); ++pIt ) + { + std::string par_name = pIt->first; + std::string par_type = pIt->second.first; + std::string par_value = pIt->second.second; + + if( par_type == "double" ) + { + QHBoxLayout* horizontalLayout = new QHBoxLayout( ); + QLabel* label = new QLabel( this->m_ActiveParameters ); + label->setText( QString( par_name.c_str( ) ) ); + horizontalLayout->addWidget( label ); + + QDoubleSpinBox* v_double = + new QDoubleSpinBox( this->m_ActiveParameters ); + v_double->setDecimals( 3 ); + v_double->setMinimum( -( std::numeric_limits< double >::max( ) ) ); + v_double->setMaximum( std::numeric_limits< double >::max( ) ); + v_double->setValue( std::atof( par_value.c_str( ) ) ); + v_double->setObjectName( QString( par_name.c_str( ) ) ); + horizontalLayout->addWidget( v_double ); + verticalLayout->addLayout( horizontalLayout ); + + } // fi + + } // rof + gridLayout->addLayout( verticalLayout, 0, 0, 1, 1 ); + QMetaObject::connectSlotsByName( this->m_ActiveParameters ); + this->m_ActiveParameters->show( ); + + /* + typedef std::map< std::string, QWidget* > _TWidgets; + _TWidgets widgets; + TParameters::const_iterator pIt = parameters.begin( ); + for( ; pIt != parameters.end( ); ++pIt ) + { + unsigned long pos = pIt->first.find_last_of( ":" ); + std::string v_name = pIt->first.substr( 0, pos ); + std::string v_type = pIt->first.substr( pos + 1 ); + QHBoxLayout* horizontalLayout = new QHBoxLayout( ); + QLabel* label = new QLabel( this->m_ActiveParameters ); + label->setText( QString( v_name.c_str( ) ) ); + horizontalLayout->addWidget( label ); + if( v_type == "real" ) + { + QDoubleSpinBox* v_double = new QDoubleSpinBox( this->m_ActiveParameters ); + v_double->setDecimals( 3 ); + v_double->setMinimum( -( std::numeric_limits< double >::max( ) ) ); + v_double->setMaximum( std::numeric_limits< double >::max( ) ); + v_double->setValue( std::atof( pIt->second.c_str( ) ) ); + horizontalLayout->addWidget( v_double ); + widgets[ pIt->first ] = v_double; + } + else if( v_type == "atomic_real" ) + { + if( v_name == "MeshType" ) + { + QLabel* info = new QLabel( this->m_ActiveParameters ); + if( typeid( TScalar ) == typeid( float ) ) + info->setText( QString( "float" ) ); + else if( typeid( TScalar ) == typeid( double ) ) + info->setText( QString( "double" ) ); + horizontalLayout->addWidget( info ); + widgets[ pIt->first ] = info; + } // fi + } // fi + verticalLayout.addLayout( horizontalLayout ); + } // rof + gridLayout.addLayout( &verticalLayout, 0, 0, 1, 1 ); + // Buttons box + QDialogButtonBox buttonBox( this->m_ActiveParameters ); + buttonBox.setOrientation( Qt::Horizontal ); + buttonBox.setStandardButtons( + QDialogButtonBox::Cancel | QDialogButtonBox::Ok + ); + gridLayout.addWidget( &buttonBox, 1, 0, 1, 1 ); + QObject::connect( + &buttonBox, SIGNAL( accepted( ) ), + this->m_ActiveParameters, SLOT( accept( ) ) + ); + QObject::connect( + &buttonBox, SIGNAL( rejected( ) ), + this->m_ActiveParameters, SLOT( reject( ) ) + ); + QMetaObject::connectSlotsByName( this->m_ActiveParameters ); + + // Execute dialog + if( dlg.exec( ) == QDialog::Accepted ) + { + _TWidgets::const_iterator wIt = widgets.begin( ); + for( ; wIt != widgets.end( ); ++wIt ) + { + unsigned long pos = wIt->first.find_last_of( ":" ); + std::string v_name = wIt->first.substr( 0, pos ); + std::string v_type = wIt->first.substr( pos + 1 ); + std::stringstream sstr; + if( v_type == "real" ) + { + QDoubleSpinBox* v_double = + dynamic_cast< QDoubleSpinBox* >( wIt->second ); + if( v_double != NULL ) + sstr << v_double->value( ); + } + else if( v_type == "atomic_real" ) + { + if( v_name == "MeshType" ) + { + QLabel* info = dynamic_cast< QLabel* >( wIt->second ); + if( info != NULL ) + sstr << info->text( ).toStdString( ); + + } // fi + + } // fi + parameters[ wIt->first ] = sstr.str( ); + + } // rof + return( true ); + } + */ + return( false ); +} + +// ------------------------------------------------------------------------- +void MainWnd:: +_triggered_actionSegmentImage( ) +{ +} + +// ------------------------------------------------------------------------- +void MainWnd:: +_triggered_actionFilterSegmentation( ) +{ + // Get filter name + if( this->m_SegmentedImage == NULL ) + return; + QAction* action = dynamic_cast< QAction* >( this->sender( ) ); + if( action == NULL ) + return; + std::string filter_name = action->text( ).toStdString( ); + + // Create plugin + if( this->m_ActivePlugin != NULL ) delete this->m_ActivePlugin; + this->m_ActivePlugin = + dynamic_cast< TPlugin* >( + this->m_Plugins.CreateObject( + this->m_SegmentationFilterClasses[ filter_name ] + ) + ); + + // Show parameters dialog + this->_ParametersDialog( this->m_ActivePlugin->GetDefaultParameters( ) ); +} + +// ------------------------------------------------------------------------- +void MainWnd:: +_triggered_actionProcessMesh( ) +{ +} + +// eof - $RCSfile$ diff --git a/appli/InteractiveDeformableMeshSegmentation/MainWnd_LoadPlugins.cxx b/appli/InteractiveDeformableMeshSegmentation/MainWnd_LoadPlugins.cxx index 8f673c1..8c01ef8 100644 --- a/appli/InteractiveDeformableMeshSegmentation/MainWnd_LoadPlugins.cxx +++ b/appli/InteractiveDeformableMeshSegmentation/MainWnd_LoadPlugins.cxx @@ -30,52 +30,55 @@ _LoadPlugins( ) std::remove_if( clean_line.begin( ), clean_line.end( ), isspace ), clean_line.end( ) ); - if( - clean_line != "sectionplugins" && - clean_line != "sectionbase_classes" && - clean_line != "sectionsegmentation_classes" && - clean_line != "sectionsegmentation_filter_classes" && - clean_line != "sectionmesh_filter_classes" - ) + if( clean_line[ 0 ] != '#' ) { - if( clean_line != "" ) + if( + clean_line != "sectionplugins" && + clean_line != "sectionbase_classes" && + clean_line != "sectionsegmentation_classes" && + clean_line != "sectionsegmentation_filter_classes" && + clean_line != "sectionmesh_filter_classes" + ) { - if( actual_section == "sectionplugins" ) + if( clean_line != "" ) { - if( !( this->m_Plugins.Load( clean_line ) ) ) + if( actual_section == "sectionplugins" ) { - QMessageBox::warning( - this, - tr( "Ignoring plugin" ), - tr( clean_line.c_str( ) ) - ); + if( !( this->m_Plugins.Load( clean_line ) ) ) + { + QMessageBox::warning( + this, + tr( "Ignoring plugin" ), + tr( clean_line.c_str( ) ) + ); + + } // fi + } + else + { + std::string name = + clean_line.substr( clean_line.find_last_of( ":" ) + 1 ); + if( actual_section == "sectionbase_classes" ) + this->m_BaseClasses[ name ] = clean_line; + else if( actual_section == "sectionsegmentation_classes" ) + this->m_SegmentationClasses[ name ] = clean_line; + else if( actual_section == "sectionsegmentation_filter_classes" ) + this->m_SegmentationFilterClasses[ name ] = clean_line; + else if( actual_section == "sectionmesh_filter_classes" ) + this->m_MeshFilterClasses[ name ] = clean_line; } // fi - } - else - { - std::string name = - clean_line.substr( clean_line.find_last_of( ":" ) + 1 ); - if( actual_section == "sectionbase_classes" ) - this->m_BaseClasses[ name ] = clean_line; - else if( actual_section == "sectionsegmentation_classes" ) - this->m_SegmentationClasses[ name ] = clean_line; - else if( actual_section == "sectionsegmentation_filter_classes" ) - this->m_SegmentationFilterClasses[ name ] = clean_line; - else if( actual_section == "sectionmesh_filter_classes" ) - this->m_MeshFilterClasses[ name ] = clean_line; } // fi + } + else if( clean_line != "" ) + { + if( clean_line[ 0 ] != '#' ) + actual_section = clean_line; } // fi - } - else if( clean_line != "" ) - { - if( clean_line[ 0 ] != '#' ) - actual_section = clean_line; } // fi - std::getline( in, line ); } // elihw @@ -94,6 +97,18 @@ _LoadPlugins( ) } // fi // Needed object from plugins + this->_AddPluginActions( + this->m_SegmentationClasses, this->m_UI->menuSegmentInputImage, + SLOT( _triggered_actionSegmentImage( ) ) + ); + this->_AddPluginActions( + this->m_SegmentationFilterClasses, this->m_UI->menuFilterSegmentedImage, + SLOT( _triggered_actionFilterSegmentation( ) ) + ); + this->_AddPluginActions( + this->m_MeshFilterClasses, this->m_UI->menuProcessMesh, + SLOT( _triggered_actionProcessMesh( ) ) + ); // Historic objects @@ -235,4 +250,19 @@ _CheckClassesInPlugins( const TStringMap& classes ) return( r ); } +// ------------------------------------------------------------------------- +void MainWnd:: +_AddPluginActions( + const TStringMap& classes, QMenu* menu, const char* method + ) +{ + TStringMap::const_iterator clIt = classes.begin( ); + for( ; clIt != classes.end( ); ++clIt ) + { + QAction* action = menu->addAction( QString( clIt->first.c_str( ) ) ); + QObject::connect( action, SIGNAL( triggered( ) ), this, method ); + + } // rof +} + // eof - $RCSfile$ diff --git a/appli/InteractiveDeformableMeshSegmentation/SegmentationParametersDlg.ui b/appli/InteractiveDeformableMeshSegmentation/SegmentationParametersDlg.ui deleted file mode 100644 index 5369aff..0000000 --- a/appli/InteractiveDeformableMeshSegmentation/SegmentationParametersDlg.ui +++ /dev/null @@ -1,149 +0,0 @@ - - - SegmentationParametersDlg - - - - 0 - 0 - 312 - 205 - - - - - 312 - 205 - - - - - 312 - 205 - - - - Dialog - - - - - - - - - - Min threshold: - - - - - - - 0 - - - -30000.000000000000000 - - - 30000.000000000000000 - - - - - - - - - - - Max threshold: - - - - - - - 0 - - - -30000.000000000000000 - - - 30000.000000000000000 - - - - - - - - - - - Number of samples: - - - - - - - 1 - - - 1000 - - - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - - buttonBox - accepted() - SegmentationParametersDlg - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - SegmentationParametersDlg - reject() - - - 316 - 260 - - - 286 - 274 - - - - - diff --git a/appli/InteractiveDeformableMeshSegmentation/VolumeActors.cxx b/appli/InteractiveDeformableMeshSegmentation/VolumeActors.cxx deleted file mode 100644 index b48cd9b..0000000 --- a/appli/InteractiveDeformableMeshSegmentation/VolumeActors.cxx +++ /dev/null @@ -1,757 +0,0 @@ -#include "VolumeActors.h" - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - - -// ------------------------------------------------------------------------- -idms::VolumeActors::SliceActor:: -SliceActor( ) -{ - this->SliceMapper = vtkSmartPointer< vtkImageSliceMapper >::New( ); - this->PlaneSource = vtkSmartPointer< vtkPlaneSource >::New( ); - this->PlaneMapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); - this->PlaneActor = vtkSmartPointer< vtkActor >::New( ); - this->ImageActor = vtkSmartPointer< vtkImageActor >::New( ); - this->TextActor = vtkSmartPointer< vtkTextActor >::New( ); - this->RegionCutterPlane = vtkSmartPointer< vtkPlane >::New( ); - - this->PlaneSource->SetXResolution( 1 ); - this->PlaneSource->SetYResolution( 1 ); - this->PlaneMapper-> - SetInputConnection( this->PlaneSource->GetOutputPort( ) ); - this->PlaneActor->SetMapper( this->PlaneMapper ); - - this->TextActor->SetTextScaleModeToNone( ); - vtkTextProperty* textprop = this->TextActor->GetTextProperty( ); - textprop->SetColor( 1, 1, 1 ); - textprop->SetFontFamilyToCourier( ); - textprop->SetFontSize( 18 ); - textprop->BoldOff( ); - textprop->ItalicOff( ); - textprop->ShadowOff( ); - textprop->SetJustificationToLeft( ); - textprop->SetVerticalJustificationToBottom( ); - vtkCoordinate* coord = this->TextActor->GetPositionCoordinate( ); - coord->SetCoordinateSystemToNormalizedViewport( ); - coord->SetValue( 0.01, 0.01 ); -} - -// ------------------------------------------------------------------------- -void idms::VolumeActors::SliceActor:: -Configure( vtkAlgorithmOutput* aout, int axis ) -{ - this->SliceMapper->SetInputConnection( aout ); - this->SliceMapper->SetOrientation( axis ); - this->ImageActor->SetMapper( this->SliceMapper ); - this->ImageActor->Modified( ); -} - -// ------------------------------------------------------------------------- -void idms::VolumeActors::SliceActor:: -ConfigureRegion( vtkAlgorithmOutput* aout ) -{ - this->RegionCutter = vtkSmartPointer< vtkCutter >::New( ); - this->RegionCutterMapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); - this->RegionCutterActor = vtkSmartPointer< vtkActor >::New( ); - - this->RegionCutter->SetInputConnection( aout ); - this->RegionCutter->SetCutFunction( this->RegionCutterPlane ); - this->RegionCutterMapper-> - SetInputConnection( this->RegionCutter->GetOutputPort( ) ); - this->RegionCutterActor->SetMapper( this->RegionCutterMapper ); - this->RegionCutterActor->GetProperty( )->SetColor( 0, 0, 1 ); -} - -// ------------------------------------------------------------------------- -void idms::VolumeActors::SliceActor:: -SetSegmentation( vtkAlgorithmOutput* aout ) -{ - this->SegmentationSliceMapper = - vtkSmartPointer< vtkImageSliceMapper >::New( ); - this->SegmentationSliceMapper->SetInputConnection( aout ); - this->SegmentationSliceMapper-> - SetOrientation( this->SliceMapper->GetOrientation( ) ); - this->SegmentationSliceMapper-> - SetSliceNumber( this->SliceMapper->GetSliceNumber( ) ); - - this->SegmentationActor = vtkSmartPointer< vtkImageActor >::New( ); - this->SegmentationActor->SetMapper( this->SegmentationSliceMapper ); - this->SegmentationActor->Modified( ); -} - -// ------------------------------------------------------------------------- -void idms::VolumeActors::SliceActor:: -SetSliceNumber( const int& slice ) -{ - this->SliceMapper->SetSliceNumber( slice ); - this->SliceMapper->Update( ); - if( this->SegmentationSliceMapper.GetPointer( ) != NULL ) - { - this->SegmentationSliceMapper->SetSliceNumber( slice ); - this->SegmentationSliceMapper->Update( ); - - } // fi - - // Compute plane - vtkAlgorithm* algo = this->SliceMapper->GetInputAlgorithm( ); - vtkInformation* info = algo->GetOutputInformation( 0 ); - int ext[ 6 ]; - double ori[ 3 ], spac[ 3 ], pos[ 3 ]; - info->Get( vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT( ), ext ); - info->Get( vtkDataObject::ORIGIN( ), ori ); - info->Get( vtkDataObject::SPACING( ), spac ); - this->SliceMapper->GetSlicePlane( )->GetOrigin( pos ); - - // Prevent obscuring voxels by offsetting the plane geometry - double xbnds[ ] = - { - ori[ 0 ] + ( spac[ 0 ] * double( ext[ 0 ] ) ), - ori[ 0 ] + ( spac[ 0 ] * double( ext[ 1 ] ) ) - }; - double ybnds[ ] = - { - ori[ 1 ] + ( spac[ 1 ] * double( ext[ 2 ] ) ), - ori[ 1 ] + ( spac[ 1 ] * double( ext[ 3 ] ) ) - }; - double zbnds[ ] = - { - ori[ 2 ] + ( spac[ 2 ] * double( ext[ 4 ] ) ), - ori[ 2 ] + ( spac[ 2 ] * double( ext[ 5 ] ) ) - }; - - if( spac[ 0 ] < double( 0 ) ) - { - double t = xbnds[ 0 ]; - xbnds[ 0 ] = xbnds[ 1 ]; - xbnds[ 1 ] = t; - - } // fi - if( spac[ 1 ] < double( 0 ) ) - { - double t = ybnds[ 0 ]; - ybnds[ 0 ] = ybnds[ 1 ]; - ybnds[ 1 ] = t; - - } // fi - if( spac[ 2 ] < double( 0 ) ) - { - double t = zbnds[ 0 ]; - zbnds[ 0 ] = zbnds[ 1 ]; - zbnds[ 1 ] = t; - - } // fi - - int axis = this->SliceMapper->GetOrientation( ); - this->PlaneActor->GetProperty( )->SetRepresentationToWireframe( ); - this->PlaneActor->GetProperty( )->SetLineWidth( 2 ); - if( axis == 0 ) // YZ, x-normal - { - this->PlaneSource->SetOrigin( pos[ 0 ], ybnds[ 0 ], zbnds[ 0 ]); - this->PlaneSource->SetPoint1( pos[ 0 ], ybnds[ 1 ], zbnds[ 0 ] ); - this->PlaneSource->SetPoint2( pos[ 0 ], ybnds[ 0 ], zbnds[ 1 ] ); - this->PlaneActor->GetProperty( )->SetColor( 1, 0, 0 ); - - this->RegionCutterPlane->SetOrigin( pos[ 0 ], ybnds[ 0 ], zbnds[ 0 ]); - this->RegionCutterPlane->SetNormal( 1, 0, 0 ); - } - else if( axis == 1 ) // ZX, y-normal - { - this->PlaneSource->SetOrigin( xbnds[ 0 ], pos[ 1 ], zbnds[ 0 ] ); - this->PlaneSource->SetPoint1( xbnds[ 0 ], pos[ 1 ], zbnds[ 1 ] ); - this->PlaneSource->SetPoint2( xbnds[ 1 ], pos[ 1 ], zbnds[ 0 ] ); - this->PlaneActor->GetProperty( )->SetColor( 0, 1, 0 ); - - this->RegionCutterPlane->SetOrigin( xbnds[ 0 ], pos[ 1 ], zbnds[ 0 ] ); - this->RegionCutterPlane->SetNormal( 0, 1, 0 ); - } - else // XY, z-normal - { - this->PlaneSource->SetOrigin( xbnds[ 0 ], ybnds[ 0 ], pos[ 2 ] ); - this->PlaneSource->SetPoint1( xbnds[ 1 ], ybnds[ 0 ], pos[ 2 ] ); - this->PlaneSource->SetPoint2( xbnds[ 0 ], ybnds[ 1 ], pos[ 2 ] ); - this->PlaneActor->GetProperty( )->SetColor( 0, 0, 1 ); - - this->RegionCutterPlane->SetOrigin( xbnds[ 0 ], ybnds[ 0 ], pos[ 2 ] ); - this->RegionCutterPlane->SetNormal( 0, 0, 1 ); - - } // fi - - this->RegionCutter->Modified( ); - this->RegionCutterMapper->Modified( ); - this->RegionCutterActor->Modified( ); -} - -// ------------------------------------------------------------------------- -void idms::VolumeActors::SliceActor:: -UpdateText( const double& w, const double& l ) -{ - char axis; - if ( this->SliceMapper->GetOrientation( ) == 0 ) axis = 'X'; - else if( this->SliceMapper->GetOrientation( ) == 1 ) axis = 'Y'; - else if( this->SliceMapper->GetOrientation( ) == 2 ) axis = 'Z'; - - std::sprintf( - this->TextBuffer, "Axis: %c (%d)\nWin/Lev: %.2f/%.2f", - axis, this->SliceMapper->GetSliceNumber( ), w, l - ); - this->TextActor->SetInput( this->TextBuffer ); - this->TextActor->Modified( ); -} - -// ------------------------------------------------------------------------- -idms::VolumeActors* idms::VolumeActors:: -New( ) -{ - return( new Self( ) ); -} - -// ------------------------------------------------------------------------- -void idms::VolumeActors:: -Configure( - vtkImageData* image, - vtkRenderWindowInteractor* xi, - vtkRenderWindowInteractor* yi, - vtkRenderWindowInteractor* zi - ) -{ - if( image == NULL || xi == NULL || yi == NULL || zi == NULL ) - vtkErrorMacro( "At least one object is \"NULL\"" ); - - this->Image = image; - this->Interactors[ 0 ] = xi; - this->Interactors[ 1 ] = yi; - this->Interactors[ 2 ] = zi; - - this->ImageToWindowLevel->SetInputData( this->Image ); - this->ResetWindowLevel( ); - this->ImageToWindowLevel->Update( ); - - // Create 3D outline - this->ImageOutlineSource = - vtkSmartPointer< vtkOutlineSource >::New( ); - vtkSmartPointer< vtkPolyDataMapper > img_ol_mapper = - vtkSmartPointer< vtkPolyDataMapper >::New( ); - this->ImageOutlineSource->SetBounds( this->Image->GetBounds( ) ); - img_ol_mapper->SetInputConnection( - this->ImageOutlineSource->GetOutputPort( ) - ); - this->ImageOutlineIndex = this->GetNumberOfItems( ); - vtkSmartPointer< vtkActor > img_ol_actor = - vtkSmartPointer< vtkActor >::New( ); - img_ol_actor->SetMapper( img_ol_mapper ); - img_ol_actor->GetProperty( )->SetColor( 1, 1, 1 ); - img_ol_actor->GetProperty( )->SetLineWidth( 1 ); - this->AddItem( img_ol_actor ); - - // Cursor radius - double spac[ 3 ]; - image->GetSpacing( spac ); - double radius = spac[ 0 ]; - radius = ( spac[ 1 ] < radius )? spac[ 1 ]: radius; - radius = ( spac[ 2 ] < radius )? spac[ 2 ]: radius; - radius *= double( 6 ); - this->Cursor->SetRadius( radius ); - this->CursorMapper->Modified( ); - this->CursorActor->Modified( ); - - // Plane actors - for( int a = 0; a < 3; ++a ) - { - // Configure actors - this->Planes[ a ].Configure( this->ImageToWindowLevel->GetOutputPort( ), a ); - this->Planes[ a ].ConfigureRegion( this->Region->GetOutputPort( ) ); - this->Planes[ a ].UpdateText( this->GetWindow( ), this->GetLevel( ) ); - - // Add them to renderer - vtkRenderer* ren = this->Interactors[ a ]->GetRenderWindow( )-> - GetRenderers( )->GetFirstRenderer( ); - if( ren == NULL ) - vtkErrorMacro( "At least one interactor doesn't have a valid renderer" ); - ren->AddActor( this->Planes[ a ].ImageActor ); - ren->AddActor( this->Planes[ a ].TextActor ); - - for( int i = 0; i < 3; ++i ) - this->Interactors[ a ]->GetRenderWindow( )-> - GetRenderers( )->GetFirstRenderer( )-> - AddActor( this->Planes[ i ].PlaneActor ); - - } // rof - - // Keep track into collection -/* - this->XPlaneIndex = this->GetNumberOfItems( ); - this->AddItem( this->Planes[ 0 ].ImageActor.GetPointer( ) ); - this->XTextIndex = this->GetNumberOfItems( ); - this->AddItem( this->Planes[ 0 ].TextActor.GetPointer( ) ); - this->XBoundsIndex = this->GetNumberOfItems( ); - this->AddItem( this->Planes[ 0 ].PlaneActor.GetPointer( ) ); - - this->YPlaneIndex = this->GetNumberOfItems( ); - this->AddItem( this->Planes[ 1 ].ImageActor.GetPointer( ) ); - this->YTextIndex = this->GetNumberOfItems( ); - this->AddItem( this->Planes[ 1 ].TextActor.GetPointer( ) ); - this->YBoundsIndex = this->GetNumberOfItems( ); - this->AddItem( this->Planes[ 1 ].PlaneActor.GetPointer( ) ); - - this->ZPlaneIndex = this->GetNumberOfItems( ); - this->AddItem( this->Planes[ 2 ].ImageActor.GetPointer( ) ); - this->ZTextIndex = this->GetNumberOfItems( ); - this->AddItem( this->Planes[ 2 ].TextActor.GetPointer( ) ); - this->ZBoundsIndex = this->GetNumberOfItems( ); - this->AddItem( this->Planes[ 2 ].PlaneActor.GetPointer( ) ); -*/ - // Initialize slice visualization - this->ResetSlices( ); - - /* - #error CONTOUR_WIDGET <- ACA VOY - static vtkSmartPointer contourRep = - vtkSmartPointer::New(); - static vtkSmartPointer contourWidget = - vtkSmartPointer::New(); - contourWidget->SetInteractor( zi ); - contourWidget->SetRepresentation( contourRep ); - contourWidget->On( ); - */ - - - - - - - - - -} - -// ------------------------------------------------------------------------- -void idms::VolumeActors:: -SetSegmentation( vtkImageData* segmentation ) -{ - double range[ 2 ]; - this->Segmentation = segmentation; - this->Segmentation->GetScalarRange( range ); - - vtkSmartPointer< vtkLookupTable > lut = - vtkSmartPointer< vtkLookupTable >::New( ); - lut->SetNumberOfTableValues( 2 ); - lut->SetTableRange( range ); - lut->SetTableValue( 0, 0, 0, 0, 0 ); - lut->SetTableValue( 1, 1, 0, 0, 0.4 ); - - this->SegmentationToColors->SetInputData( this->Segmentation ); - this->SegmentationToColors->SetLookupTable( lut ); - this->SegmentationToColors->Update( ); - - for( unsigned int a = 0; a < 3; ++a ) - { - this->Planes[ a ].SetSegmentation( - this->SegmentationToColors->GetOutputPort( ) - ); - vtkRenderer* ren = this->Interactors[ a ]->GetRenderWindow( )-> - GetRenderers( )->GetFirstRenderer( ); - ren->AddActor( this->Planes[ a ].SegmentationActor ); - - } // rof - this->Render( ); -} - -// ------------------------------------------------------------------------- -void idms::VolumeActors:: -AddAuxiliaryInteractor( vtkRenderWindowInteractor* i ) -{ - if( i != NULL ) - { - this->AuxiliaryInteractors.insert( i ); - this->Modified( ); - - } // fi -} - -// ------------------------------------------------------------------------- -double idms::VolumeActors:: -GetMinWindow( ) const -{ - return( double( 0.01 ) ); -} - -// ------------------------------------------------------------------------- -double idms::VolumeActors:: -GetMaxWindow( ) const -{ - if( this->Image == NULL ) - return( double( 0 ) ); - - double range[ 2 ]; - this->Image->GetScalarRange( range ); - return( range[ 1 ] - range[ 0 ] ); -} - -// ------------------------------------------------------------------------- -double idms::VolumeActors:: -GetMinLevel( ) const -{ - if( this->Image == NULL ) - return( double( 0 ) ); - - double range[ 2 ]; - this->Image->GetScalarRange( range ); - return( range[ 0 ] ); -} - -// ------------------------------------------------------------------------- -double idms::VolumeActors:: -GetMaxLevel( ) const -{ - if( this->Image == NULL ) - return( double( 0 ) ); - - double range[ 2 ]; - this->Image->GetScalarRange( range ); - return( range[ 1 ] ); -} - -// ------------------------------------------------------------------------- -double idms::VolumeActors:: -GetWindow( ) const -{ - return( this->ImageToWindowLevel->GetWindow( ) ); -} - -// ------------------------------------------------------------------------- -double idms::VolumeActors:: -GetLevel( ) const -{ - return( this->ImageToWindowLevel->GetLevel( ) ); -} - -// ------------------------------------------------------------------------- -void idms::VolumeActors:: -SetWindow( const double& w ) -{ - this->ImageToWindowLevel->SetWindow( w ); -} - -// ------------------------------------------------------------------------- -void idms::VolumeActors:: -SetLevel( const double& l ) -{ - this->ImageToWindowLevel->SetLevel( l ); -} - -// ------------------------------------------------------------------------- -void idms::VolumeActors:: -SetWindowLevel( const double& w, const double& l ) -{ - this->ImageToWindowLevel->SetWindow( w ); - this->ImageToWindowLevel->SetLevel( l ); - for( int a = 0; a < 3; ++a ) - this->Planes[ a ].UpdateText( w, l ); -} - -// ------------------------------------------------------------------------- -void idms::VolumeActors:: -ResetWindowLevel( ) -{ - double range[ 2 ]; - this->Image->GetScalarRange( range ); - this->SetWindowLevel( - range[ 1 ] - range[ 0 ], - ( ( range[ 1 ] + range[ 0 ] ) / double( 2 ) ) + range[ 0 ] - ); -} - -// ------------------------------------------------------------------------- -vtkPlane* idms::VolumeActors:: -GetSlicePlane( const int& axis ) const -{ - return( this->Planes[ axis ].SliceMapper->GetSlicePlane( ) ); -} - -// ------------------------------------------------------------------------- -int idms::VolumeActors:: -GetSliceNumberMinValue( const int& axis ) const -{ - return( this->Planes[ axis ].SliceMapper->GetSliceNumberMinValue( ) ); -} - -// ------------------------------------------------------------------------- -int idms::VolumeActors:: -GetSliceNumberMaxValue( const int& axis ) const -{ - return( this->Planes[ axis ].SliceMapper->GetSliceNumberMaxValue( ) ); -} - -// ------------------------------------------------------------------------- -int idms::VolumeActors:: -GetSlice( const int& axis ) const -{ - return( this->Planes[ axis ].SliceMapper->GetSliceNumber( ) ); -} - -// ------------------------------------------------------------------------- -void idms::VolumeActors:: -SetSlice( const int& axis, const int& slice ) -{ - this->Planes[ axis ].SetSliceNumber( slice ); - this->Planes[ axis ].UpdateText( this->GetWindow( ), this->GetLevel( ) ); - this->RenderAuxiliaryInteractors( ); -} - -// ------------------------------------------------------------------------- -void idms::VolumeActors:: -SetSlice( const int& axis, const double& slice ) -{ - vtkAlgorithm* algo = - this->Planes[ axis ].SliceMapper->GetInputAlgorithm( ); - vtkInformation* info = algo->GetOutputInformation( 0 ); - int ext[ 6 ]; - double ori[ 3 ], spac[ 3 ]; - info->Get( vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT( ), ext ); - info->Get( vtkDataObject::ORIGIN( ), ori ); - info->Get( vtkDataObject::SPACING( ), spac ); - this->SetSlice( - axis, - int( ( slice - ori[ axis ] ) / spac[ axis ] ) + ext[ axis << 1 ] - ); -} - -// ------------------------------------------------------------------------- -void idms::VolumeActors:: -ResetSlices( ) -{ - for( int a = 0; a < 3; ++a ) - this->SetSlice( a, this->GetSliceNumberMinValue( a ) ); - this->Render( ); -} - -// ------------------------------------------------------------------------- -void idms::VolumeActors:: -AddSeed( int idx[ 3 ] ) -{ - this->Seeds.push_back( std::vector< int >( idx, idx + 3 ) ); - this->Modified( ); -} - -// ------------------------------------------------------------------------- -void idms::VolumeActors:: -AddSeed( double pos[ 3 ] ) -{ - /* TODO - this->Seeds.push_back( std::vector< double >( pos, pos + 3 ) ); - this->Modified( ); - */ -} - -// ------------------------------------------------------------------------- -unsigned int idms::VolumeActors:: -GetNumberOfSeeds( ) const -{ - return( this->Seeds.size( ) ); -} - -// ------------------------------------------------------------------------- -void idms::VolumeActors:: -GetSeed( unsigned int i, int idx[ 3 ] ) const -{ - if( i < this->Seeds.size( ) ) - { - idx[ 0 ] = this->Seeds[ i ][ 0 ]; - idx[ 1 ] = this->Seeds[ i ][ 1 ]; - idx[ 2 ] = this->Seeds[ i ][ 2 ]; - - } // fi -} - -// ------------------------------------------------------------------------- -void idms::VolumeActors:: -SetCursorPosition( double pos[ 3 ] ) -{ - this->Cursor->SetCenter( pos ); -} - -// ------------------------------------------------------------------------- -void idms::VolumeActors:: -ShowRegion( int a ) -{ - vtkRenderer* ren = this->Interactors[ a ]->GetRenderWindow( )-> - GetRenderers( )->GetFirstRenderer( ); - ren->AddActor( this->Planes[ a ].RegionCutterActor ); -} - -// ------------------------------------------------------------------------- -void idms::VolumeActors:: -HideRegion( int a ) -{ - vtkRenderer* ren = this->Interactors[ a ]->GetRenderWindow( )-> - GetRenderers( )->GetFirstRenderer( ); - ren->RemoveActor( this->Planes[ a ].RegionCutterActor ); -} - -// ------------------------------------------------------------------------- -void idms::VolumeActors:: -SetRegionPosition( double pos[ 3 ] ) -{ - this->Region->SetCenter( pos ); -} - -// ------------------------------------------------------------------------- -void idms::VolumeActors:: -SetRegionRadius( double pos[ 3 ] ) -{ - double rpos[ 3 ]; - - this->Region->GetCenter( rpos ); - double x = pos[ 0 ] - rpos[ 0 ]; - double y = pos[ 1 ] - rpos[ 1 ]; - double z = pos[ 2 ] - rpos[ 2 ]; - double d = ( x * x ) + ( y * y ) + ( z * z ); - if( double( 0 ) < d ) - d = std::sqrt( d ); - else - d = double( 0 ); - this->Region->SetRadius( d ); - this->Planes[ 0 ].RegionCutter->Modified( ); - this->Planes[ 1 ].RegionCutter->Modified( ); - this->Planes[ 2 ].RegionCutter->Modified( ); - this->Planes[ 0 ].RegionCutterMapper->Modified( ); - this->Planes[ 1 ].RegionCutterMapper->Modified( ); - this->Planes[ 2 ].RegionCutterMapper->Modified( ); - this->Planes[ 0 ].RegionCutterActor->Modified( ); - this->Planes[ 1 ].RegionCutterActor->Modified( ); - this->Planes[ 2 ].RegionCutterActor->Modified( ); - this->Render( ); -} - -// ------------------------------------------------------------------------- -void idms::VolumeActors:: -GetImageBounds( double bounds[ 6 ] ) const -{ - if( this->Image != NULL ) - this->Image->GetBounds( bounds ); -} - -// ------------------------------------------------------------------------- -void idms::VolumeActors:: -Render( ) -{ - for( int a = 0; a < 3; ++a ) - if( this->Interactors[ a ] != NULL ) - this->Interactors[ a ]->Render( ); -} - -// ------------------------------------------------------------------------- -void idms::VolumeActors:: -RenderAuxiliaryInteractors( ) -{ - for( - TInteractors::iterator iIt = this->AuxiliaryInteractors.begin( ); - iIt != this->AuxiliaryInteractors.end( ); - ++iIt - ) - ( *iIt )->Render( ); -} - -// ------------------------------------------------------------------------- -void idms::VolumeActors:: -ResetCameras( ) -{ - double b[ 6 ]; - this->GetImageBounds( b ); - for( int a = 0; a < 3; ++a ) - { - if( this->Interactors[ a ] == NULL ) - continue; - vtkRenderer* ren = this->Interactors[ a ]->GetRenderWindow( )-> - GetRenderers( )->GetFirstRenderer( ); - if( ren != NULL ) ren->ResetCamera( b ); - - } // rof -} - -// ------------------------------------------------------------------------- -idms::VolumeActors:: -VolumeActors( ) - : Superclass( ), - Image( NULL ), - Segmentation( NULL ) -{ - for( int a = 0; a < 3; ++a ) - this->Interactors[ a ] = NULL; - - this->ImageToWindowLevel = - vtkSmartPointer< vtkImageMapToWindowLevelColors >::New( ); - this->ImageToWindowLevel->SetOutputFormatToLuminance( ); - this->SegmentationToColors = - vtkSmartPointer< vtkImageMapToColors >::New( ); - - this->Cursor = vtkSmartPointer< vtkSphereSource >::New( ); - this->CursorMapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); - this->CursorActor = vtkSmartPointer< vtkActor >::New( ); - - this->Cursor->SetPhiResolution( 36 ); - this->Cursor->SetThetaResolution( 36 ); - this->CursorMapper->SetInputConnection( this->Cursor->GetOutputPort( ) ); - this->CursorActor->SetMapper( this->CursorMapper ); - this->CursorActor->GetProperty( )->SetColor( 1, 1, 0 ); - this->CursorIndex = this->GetNumberOfItems( ); - this->AddItem( this->CursorActor ); - - this->Region = vtkSmartPointer< vtkSphereSource >::New( ); - this->RegionMapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); - this->RegionActor = vtkSmartPointer< vtkActor >::New( ); - - this->Region->SetPhiResolution( 36 ); - this->Region->SetThetaResolution( 36 ); - this->RegionMapper->SetInputConnection( this->Region->GetOutputPort( ) ); - this->RegionActor->SetMapper( this->RegionMapper ); - this->RegionActor->GetProperty( )->SetColor( 0, 0, 1 ); - this->RegionActor->GetProperty( )->SetOpacity( 0 ); - this->RegionIndex = this->GetNumberOfItems( ); - this->AddItem( this->RegionActor ); - - this->XPlaneIndex = this->GetNumberOfItems( ); - this->AddItem( this->Planes[ 0 ].ImageActor.GetPointer( ) ); - this->XTextIndex = this->GetNumberOfItems( ); - this->AddItem( this->Planes[ 0 ].TextActor.GetPointer( ) ); - this->XBoundsIndex = this->GetNumberOfItems( ); - this->AddItem( this->Planes[ 0 ].PlaneActor.GetPointer( ) ); - - this->YPlaneIndex = this->GetNumberOfItems( ); - this->AddItem( this->Planes[ 1 ].ImageActor.GetPointer( ) ); - this->YTextIndex = this->GetNumberOfItems( ); - this->AddItem( this->Planes[ 1 ].TextActor.GetPointer( ) ); - this->YBoundsIndex = this->GetNumberOfItems( ); - this->AddItem( this->Planes[ 1 ].PlaneActor.GetPointer( ) ); - - this->ZPlaneIndex = this->GetNumberOfItems( ); - this->AddItem( this->Planes[ 2 ].ImageActor.GetPointer( ) ); - this->ZTextIndex = this->GetNumberOfItems( ); - this->AddItem( this->Planes[ 2 ].TextActor.GetPointer( ) ); - this->ZBoundsIndex = this->GetNumberOfItems( ); - this->AddItem( this->Planes[ 2 ].PlaneActor.GetPointer( ) ); -} - -// ------------------------------------------------------------------------- -idms::VolumeActors:: -~VolumeActors( ) -{ -} - -// eof - $RCSfile$ diff --git a/appli/InteractiveDeformableMeshSegmentation/VolumeActors.h b/appli/InteractiveDeformableMeshSegmentation/VolumeActors.h deleted file mode 100644 index 6d478a3..0000000 --- a/appli/InteractiveDeformableMeshSegmentation/VolumeActors.h +++ /dev/null @@ -1,203 +0,0 @@ -#ifndef __IDMS__VOLUMEACTORS__H__ -#define __IDMS__VOLUMEACTORS__H__ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -class vtkImageData; -class vtkPlane; -class vtkRenderWindowInteractor; - -// ------------------------------------------------------------------------- -#define IDMS_VOLUMEACTORS( name, type ) \ - inline type* Get##name##Actor( ) const \ - { \ - return( \ - dynamic_cast< type* >( \ - const_cast< Self* >( this )-> \ - GetItemAsObject( this->name##Index ) \ - ) \ - ); \ - } - -namespace idms -{ - /** - */ - class VolumeActors - : public vtkPropCollection - { - public: - typedef VolumeActors Self; - - protected: - struct SliceActor - { - vtkSmartPointer< vtkImageSliceMapper > SliceMapper; - vtkSmartPointer< vtkImageSliceMapper > SegmentationSliceMapper; - vtkSmartPointer< vtkPlaneSource > PlaneSource; - vtkSmartPointer< vtkPolyDataMapper > PlaneMapper; - vtkSmartPointer< vtkActor > PlaneActor; - vtkSmartPointer< vtkImageActor > ImageActor; - vtkSmartPointer< vtkImageActor > SegmentationActor; - vtkSmartPointer< vtkTextActor > TextActor; - vtkSmartPointer< vtkPlane > RegionCutterPlane; - vtkSmartPointer< vtkCutter > RegionCutter; - vtkSmartPointer< vtkPolyDataMapper > RegionCutterMapper; - vtkSmartPointer< vtkActor > RegionCutterActor; - char TextBuffer[ 128 ]; - - SliceActor( ); - void Configure( vtkAlgorithmOutput* aout, int axis ); - void ConfigureRegion( vtkAlgorithmOutput* aout ); - void SetSegmentation( vtkAlgorithmOutput* aout ); - void SetSliceNumber( const int& slice ); - void UpdateText( const double& w, const double& l ); - }; - typedef std::set< vtkRenderWindowInteractor* > TInteractors; - - public: - vtkTypeMacro( VolumeActors, vtkPropCollection ); - - IDMS_VOLUMEACTORS( ImageOutline, vtkActor ); - IDMS_VOLUMEACTORS( XPlane, vtkImageActor ); - IDMS_VOLUMEACTORS( YPlane, vtkImageActor ); - IDMS_VOLUMEACTORS( ZPlane, vtkImageActor ); - IDMS_VOLUMEACTORS( XText, vtkTextActor ); - IDMS_VOLUMEACTORS( YText, vtkTextActor ); - IDMS_VOLUMEACTORS( ZText, vtkTextActor ); - IDMS_VOLUMEACTORS( XBounds, vtkActor ); - IDMS_VOLUMEACTORS( YBounds, vtkActor ); - IDMS_VOLUMEACTORS( ZBounds, vtkActor ); - IDMS_VOLUMEACTORS( Cursor, vtkActor ); - IDMS_VOLUMEACTORS( Region, vtkActor ); - - public: - // Creation - static VolumeActors* New( ); - void Configure( - vtkImageData* image, - vtkRenderWindowInteractor* xi, - vtkRenderWindowInteractor* yi, - vtkRenderWindowInteractor* zi - ); - void SetSegmentation( vtkImageData* segmentation ); - void AddAuxiliaryInteractor( vtkRenderWindowInteractor* i ); - - inline vtkImageData* GetImage( ) - { return( this->Image ); } - inline vtkImageData* GetSegmentation( ) - { return( this->Segmentation ); } - inline const vtkImageData* GetImage( ) const - { return( this->Image ); } - inline const vtkImageData* GetSegmentation( ) const - { return( this->Segmentation ); } - - // Window/Level - double GetMinWindow( ) const; - double GetMaxWindow( ) const; - double GetMinLevel( ) const; - double GetMaxLevel( ) const; - double GetWindow( ) const; - double GetLevel( ) const; - void SetWindow( const double& w ); - void SetLevel( const double& l ); - void SetWindowLevel( const double& w, const double& l ); - void ResetWindowLevel( ); - - // Slice access - vtkPlane* GetSlicePlane( const int& axis ) const; - int GetSliceNumberMinValue( const int& axis ) const; - int GetSliceNumberMaxValue( const int& axis ) const; - int GetSlice( const int& axis ) const; - void SetSlice( const int& axis, const int& slice ); - void SetSlice( const int& axis, const double& slice ); - void ResetSlices( ); - - // Seeds - void AddSeed( int idx[ 3 ] ); - void AddSeed( double pos[ 3 ] ); - unsigned int GetNumberOfSeeds( ) const; - void GetSeed( unsigned int i, int idx[ 3 ] ) const; - - // 3D cursor and region - void SetCursorPosition( double pos[ 3 ] ); - void ShowRegion( int a ); - void HideRegion( int a ); - void SetRegionPosition( double pos[ 3 ] ); - void SetRegionRadius( double pos[ 3 ] ); - - // General accessors - void GetImageBounds( double bounds[ 6 ] ) const; - - // Rendering synch - void Render( ); - void RenderAuxiliaryInteractors( ); - void ResetCameras( ); - - protected: - VolumeActors( ); - virtual ~VolumeActors( ); - - private: - // Purposely not implemented - VolumeActors( const Self& ); - Self& operator=( const Self& ); - - protected: - vtkImageData* Image; - vtkImageData* Segmentation; - vtkRenderWindowInteractor* Interactors[ 3 ]; - TInteractors AuxiliaryInteractors; - - vtkSmartPointer< vtkImageMapToWindowLevelColors > ImageToWindowLevel; - vtkSmartPointer< vtkImageMapToColors > SegmentationToColors; - - vtkSmartPointer< vtkOutlineSource > ImageOutlineSource; - SliceActor Planes[ 3 ]; - - std::vector< std::vector< int > > Seeds; - - vtkSmartPointer< vtkSphereSource > Cursor; - vtkSmartPointer< vtkPolyDataMapper > CursorMapper; - vtkSmartPointer< vtkActor > CursorActor; - - vtkSmartPointer< vtkSphereSource > Region; - vtkSmartPointer< vtkPolyDataMapper > RegionMapper; - vtkSmartPointer< vtkActor > RegionActor; - - unsigned int ImageOutlineIndex; - unsigned int XPlaneIndex; - unsigned int YPlaneIndex; - unsigned int ZPlaneIndex; - unsigned int XTextIndex; - unsigned int YTextIndex; - unsigned int ZTextIndex; - unsigned int XBoundsIndex; - unsigned int YBoundsIndex; - unsigned int ZBoundsIndex; - unsigned int CursorIndex; - unsigned int RegionIndex; - }; - -} // ecapseman - -#endif // __IDMS__VOLUMEACTORS__H__ - -// eof - $RCSfile$ diff --git a/appli/InteractiveDeformableMeshSegmentation/idms.plugins.in b/appli/InteractiveDeformableMeshSegmentation/idms.plugins.in index 6a38b2c..1085fe4 100644 --- a/appli/InteractiveDeformableMeshSegmentation/idms.plugins.in +++ b/appli/InteractiveDeformableMeshSegmentation/idms.plugins.in @@ -1,5 +1,6 @@ section plugins @cpPlugins_LIBRARY_NAME@ + libcpmPlugins.so section base_classes cpPlugins::Plugins::ImageReader @@ -10,6 +11,7 @@ section base_classes section segmentation_classes section segmentation_filter_classes + cpm::Plugins::SimpleFillRegion section mesh_filter_classes diff --git a/lib/cpm/CMakeLists.txt b/lib/cpm/CMakeLists.txt index 12f5311..199cb31 100644 --- a/lib/cpm/CMakeLists.txt +++ b/lib/cpm/CMakeLists.txt @@ -58,4 +58,14 @@ TARGET_LINK_LIBRARIES( ${VTK_LIBRARIES} ) +## ============================ +## = If needed, build plugins = +## ============================ + +IF(BUILD_FINAL_APPLICATION) + SUBDIRS( + Plugins + ) +ENDIF(BUILD_FINAL_APPLICATION) + ## eof - $RCSfile$ diff --git a/lib/cpm/Plugins/CMakeLists.txt b/lib/cpm/Plugins/CMakeLists.txt new file mode 100644 index 0000000..d070bb5 --- /dev/null +++ b/lib/cpm/Plugins/CMakeLists.txt @@ -0,0 +1,37 @@ +SET(LIBRARY_NAME cpmPlugins) + +## =============== +## = Source code = +## =============== + +FILE(GLOB LIB_HEADERS_H "*.h") +FILE(GLOB LIB_HEADERS_HPP "*.hpp") +FILE(GLOB LIB_HEADERS_HXX "*.hxx") +FILE(GLOB LIB_SOURCES_C "*.c") +FILE(GLOB LIB_SOURCES_CPP "*.cpp") +FILE(GLOB LIB_SOURCES_CXX "*.cxx") + +## ===================== +## = Compilation rules = +## ===================== + +ADD_LIBRARY( + ${LIBRARY_NAME} + SHARED + ${LIB_SOURCES_C} + ${LIB_SOURCES_CPP} + ${LIB_SOURCES_CXX} + ) +GENERATE_EXPORT_HEADER( + ${LIBRARY_NAME} + BASE_NAME ${LIBRARY_NAME} + EXPORT_MACRO_NAME ${LIBRARY_NAME}_EXPORT + EXPORT_FILE_NAME ${PROJECT_BINARY_DIR}/lib/cpm/Plugins/${LIBRARY_NAME}_Export.h + STATIC_DEFINE ${LIBRARY_NAME}_BUILT_AS_STATIC + ) +TARGET_LINK_LIBRARIES( + ${LIBRARY_NAME} + ${cpPlugins_Interface_LIBRARIES} + ) + +## eof - $RCSfile$ diff --git a/lib/cpm/Plugins/Host.cxx b/lib/cpm/Plugins/Host.cxx new file mode 100644 index 0000000..1152622 --- /dev/null +++ b/lib/cpm/Plugins/Host.cxx @@ -0,0 +1,12 @@ +#include +#include + +/// TODO: doc +PLUMA_CONNECTOR +bool connect( pluma::Host& host ) +{ + host.add( new cpm::Plugins::SimpleFillRegionProvider( ) ); + return( true ); +} + +// eof - $RCSfile$ diff --git a/lib/cpm/Plugins/SimpleFillRegion.cxx b/lib/cpm/Plugins/SimpleFillRegion.cxx new file mode 100644 index 0000000..167c9e0 --- /dev/null +++ b/lib/cpm/Plugins/SimpleFillRegion.cxx @@ -0,0 +1,35 @@ +#include + +// ------------------------------------------------------------------------- +cpm::Plugins::SimpleFillRegion:: +SimpleFillRegion( ) + : Superclass( ) +{ + this->SetNumberOfInputs( 2 ); + + this->m_DefaultParameters[ "MinDelta" ] = TParameter( "double", "0" ); + this->m_DefaultParameters[ "MaxDelta" ] = TParameter( "double", "0" ); + this->m_DefaultParameters[ "Seed" ] = TParameter( "point", "0:0:0" ); +} + +// ------------------------------------------------------------------------- +cpm::Plugins::SimpleFillRegion:: +~SimpleFillRegion( ) +{ +} + +// ------------------------------------------------------------------------- +std::string cpm::Plugins::SimpleFillRegion:: +GetClassName( ) const +{ + return( "cpm::Plugins::SimpleFillRegion" ); +} + +// ------------------------------------------------------------------------- +std::string cpm::Plugins::SimpleFillRegion:: +_GenerateData( ) +{ + std::cout << "Simple fill region" << std::endl; +} + +// eof - $RCSfile$ diff --git a/lib/cpm/Plugins/SimpleFillRegion.h b/lib/cpm/Plugins/SimpleFillRegion.h new file mode 100644 index 0000000..1e84ef6 --- /dev/null +++ b/lib/cpm/Plugins/SimpleFillRegion.h @@ -0,0 +1,45 @@ +#ifndef __CPM__PLUGINS__SIMPLEFILLREGION__H__ +#define __CPM__PLUGINS__SIMPLEFILLREGION__H__ + +#include + +namespace cpm +{ + namespace Plugins + { + /** + */ + class SimpleFillRegion + : public cpPlugins::Interface::ImageToImageFilter + { + public: + typedef SimpleFillRegion Self; + typedef cpPlugins::Interface::ImageToImageFilter Superclass; + + typedef Superclass::TParameter TParameter; + typedef Superclass::TParameters TParameters; + + public: + SimpleFillRegion( ); + virtual ~SimpleFillRegion( ); + + virtual std::string GetClassName( ) const; + + protected: + virtual std::string _GenerateData( ); + + protected: + itk::ProcessObject::Pointer m_Filter; + }; + + // --------------------------------------------------------------------- + PLUMA_INHERIT_PROVIDER( SimpleFillRegion, cpPlugins::Interface::Object ); + + } // ecapseman + +} // ecapseman + +#endif // __CPM__PLUGINS__SIMPLEFILLREGION__H__ + + +// eof - $RCSfile$ -- 2.45.0