From a422d88602e9b49085ccfab0ef0f9f2d93fb6a1e Mon Sep 17 00:00:00 2001 From: Leonardo Florez-Valencia Date: Tue, 13 Sep 2016 22:41:41 -0500 Subject: [PATCH] Start contour tracer widget debugging: change interactor style. --- appli/examples/plugins/ImageTracer.cxx | 164 ++++++++ appli/examples/plugins/ShowImage.cxx | 44 ++- .../Interaction/ImageSliceStyle.cxx | 133 ++++++- .../Interaction/ImageSliceStyle.h | 45 ++- lib/cpExtensions/QT/ImageWidget.cxx | 77 +++- lib/cpExtensions/QT/ImageWidget.h | 71 ++-- lib/cpExtensions/QT/MPRInteractionCommand.cxx | 16 +- lib/cpExtensions/QT/RendererWidget.cxx | 365 ++++++------------ lib/cpExtensions/QT/RendererWidget.h | 37 +- lib/cpExtensions/QT/SimpleMPRWidget.cxx | 26 +- lib/cpExtensions/Visualization/ImageActor.cxx | 12 - .../Visualization/ImageOutlineActor.h | 2 +- .../Visualization/MPR3DActors.cxx | 18 +- .../Visualization/WindowLevelImageActor.cxx | 115 ++++-- .../Visualization/WindowLevelImageActor.h | 17 +- 15 files changed, 744 insertions(+), 398 deletions(-) create mode 100644 appli/examples/plugins/ImageTracer.cxx diff --git a/appli/examples/plugins/ImageTracer.cxx b/appli/examples/plugins/ImageTracer.cxx new file mode 100644 index 0000000..014d64d --- /dev/null +++ b/appli/examples/plugins/ImageTracer.cxx @@ -0,0 +1,164 @@ +#include + +#ifdef cpExtensions_QT4 + +#include +#include +#include + +#include +#include +#include +#include + +#include + + +#include +#include +#include +#include + + +#endif // cpExtensions_QT4 + +//---------------------------------------------------------------------------- +int main( int argc, char* argv[] ) +{ +#ifdef cpExtensions_QT4 + + // Manage inputs + if( argc < 2 ) + { + std::cerr << "Usage: " << argv[ 0 ] << " image_file(s)" << std::endl; + return( 1 ); + + } // fi + + // Create interface + cpPlugins::Interface::Plugins::Pointer interface = + cpPlugins::Interface::Plugins::New( ); + try + { + interface->LoadEnvironments( ); + interface->GuessPlugins( ); + } + catch( std::exception& err ) + { + std::cerr << "Error caught: " << err.what( ) << std::endl; + return( 1 ); + + } // yrt + + // Create workspace + typedef cpPlugins::Interface::Workspace _TWorkspace; + _TWorkspace::Pointer ws = _TWorkspace::New( ); + ws->PrintExecutionOn( ); + + // Configure reader + auto reader = ws->CreateFilter( "IO", "ImageReader", "reader" ); + auto params = reader->GetParameters( ); + for( int i = 1; i < argc; ++i ) + params->AddToOpenFileNameList( "FileNames", argv[ i ] ); + + // Execute reader + try + { + reader->Update( ); + } + catch( std::exception& err ) + { + std::cerr << "Error caugth: " << err.what( ) << std::endl; + return( 1 ); + + } // yrt + + vtkSmartPointer< vtkImageTracerWidget > itw; + + // Configure viewer + auto image = reader->GetOutputData< vtkImageData >( "Output" ); + auto dim = image->GetDataDimension( ); + switch( dim ) + { + case 2: case 3: + { + // Qt initialization + QApplication app( argc, argv ); + QMainWindow wnd; + wnd.setGeometry( 0, 0, 1024, 768 ); + + // Create main widget + QWidget* wdg = NULL; + if( dim == 2 ) + { + auto view = new cpExtensions::QT::ImageWidget( &wnd ); + view->SetImage( image, 2, "image" ); + view->SetQuadrant( 2 ); + view->SetImageOpacity( 0.5 ); + wdg = view; + + itw = vtkSmartPointer< vtkImageTracerWidget >::New( ); + itw->SetCaptureRadius(1.5); + itw->GetGlyphSource()->SetColor(1, 0, 0); + itw->GetGlyphSource()->SetScale(3.0); + itw->GetGlyphSource()->SetRotationAngle(45.0); + itw->GetGlyphSource()->Modified(); + itw->ProjectToPlaneOn(); + itw->SetProjectionNormalToZAxes(); + itw->SetProjectionPosition( + ( + view->GetImageActor( )->GetBounds( )[ 4 ] + + view->GetImageActor( )->GetBounds( )[ 5 ] + ) / double( 2 ) + ); + itw->SetViewProp( view->GetImageActor( ) ); + itw->SetInputData( image ); + itw->SetInteractor( view->GetInteractor( ) ); + itw->PlaceWidget( ); + itw->SnapToImageOn( ); + itw->AutoCloseOn( ); + + /* TODO + vtkSmartPointer< vtkSplineWidget > isw = + vtkSmartPointer< vtkSplineWidget >::New( ); + isw.SetCurrentRenderer(ren2) + isw.SetDefaultRenderer(ren2) + isw.SetInputConnection(extract.GetOutputPort()) + isw.SetInteractor(iren) + bnds = imageActor2.GetBounds() + isw.PlaceWidget(bnds[0], bnds[1], bnds[2], bnds[3], bnds[4], bnds[5]) + isw.ProjectToPlaneOn() + isw.SetProjectionNormalToXAxes() + isw.SetProjectionPosition(pos) + */ + + itw->On( ); + } + else + { + auto view = new cpExtensions::QT::SimpleMPRWidget( &wnd ); + view->SetImage( image, "image" ); + wdg = view; + + } // fi + + // Start application and show data + wnd.setCentralWidget( wdg ); + wnd.show( ); + return( app.exec( ) ); + } + break; + default: + { + std::cerr << "Unmanaged dimension." << std::endl; + return( 1 ); + } + break; + + } // hctiws +#else // cpExtensions_QT4 + return( 0 ); +#endif // cpExtensions_QT4 +} + +// eof - $RCSfile$ diff --git a/appli/examples/plugins/ShowImage.cxx b/appli/examples/plugins/ShowImage.cxx index a339de2..3b9c9dd 100644 --- a/appli/examples/plugins/ShowImage.cxx +++ b/appli/examples/plugins/ShowImage.cxx @@ -3,6 +3,7 @@ #ifdef cpExtensions_QT4 #include +#include #include #include @@ -18,6 +19,8 @@ int main( int argc, char* argv[] ) { #ifdef cpExtensions_QT4 + typedef cpPlugins::Interface::Plugins _TPlugins; + typedef cpPlugins::Interface::Workspace _TWorkspace; // Manage inputs if( argc < 2 ) @@ -28,12 +31,11 @@ int main( int argc, char* argv[] ) } // fi // Create interface - cpPlugins::Interface::Plugins::Pointer interface = - cpPlugins::Interface::Plugins::New( ); + _TPlugins::Pointer plugins = _TPlugins::New( ); try { - interface->LoadEnvironments( ); - interface->GuessPlugins( ); + plugins->LoadEnvironments( ); + plugins->GuessPlugins( ); } catch( std::exception& err ) { @@ -43,7 +45,6 @@ int main( int argc, char* argv[] ) } // yrt // Create workspace - typedef cpPlugins::Interface::Workspace _TWorkspace; _TWorkspace::Pointer ws = _TWorkspace::New( ); ws->PrintExecutionOn( ); @@ -67,14 +68,10 @@ int main( int argc, char* argv[] ) // Configure viewer auto image = reader->GetOutputData< vtkImageData >( "Output" ); - switch( image->GetDataDimension( ) ) + auto dim = image->GetDataDimension( ); + switch( dim ) { - case 2: - { - return( 0 ); - } - break; - case 3: + case 2: case 3: { // Qt initialization QApplication app( argc, argv ); @@ -82,13 +79,26 @@ int main( int argc, char* argv[] ) wnd.setGeometry( 0, 0, 1024, 768 ); // Create main widget - cpExtensions::QT::SimpleMPRWidget view( &wnd ); - view.SetImage( image, "image" ); + QWidget* wdg = NULL; + if( dim == 2 ) + { + auto view = new cpExtensions::QT::ImageWidget( &wnd ); + view->SetImage( image, 2, "image" ); + wdg = view; + } + else + { + /* TODO + auto view = new cpExtensions::QT::SimpleMPRWidget( &wnd ); + view->SetImage( image, "image" ); + wdg = view; + */ + + } // fi // Start application and show data - wnd.setCentralWidget( &view ); + wnd.setCentralWidget( wdg ); wnd.show( ); - return( app.exec( ) ); } break; @@ -98,7 +108,7 @@ int main( int argc, char* argv[] ) return( 1 ); } break; - + } // hctiws #else // cpExtensions_QT4 return( 0 ); diff --git a/lib/cpExtensions/Interaction/ImageSliceStyle.cxx b/lib/cpExtensions/Interaction/ImageSliceStyle.cxx index a6731ed..0799036 100644 --- a/lib/cpExtensions/Interaction/ImageSliceStyle.cxx +++ b/lib/cpExtensions/Interaction/ImageSliceStyle.cxx @@ -1,7 +1,16 @@ #include +#include #include -#include +#include +#include +#include +#include +#include #include +#include +/* TODO + #include +*/ // ------------------------------------------------------------------------- cpExtensions::Interaction::ImageSliceStyle:: @@ -12,6 +21,40 @@ New( ) } // ------------------------------------------------------------------------- +void cpExtensions::Interaction::ImageSliceStyle:: +OnMouseMove( ) +{ + static bool cursor_visible = false; + + int idx[ 2 ]; + double pnt[ 3 ]; + if( this->_PickPointOnImageActor( idx, pnt ) ) + { + this->m_Cursor->SetCursor( pnt, false ); + if( !cursor_visible ) + { + this->m_Cursor->VisibilityOn( ); + cursor_visible = true; + + } // fi + this->Interactor->Render( ); + } + else + { + if( cursor_visible ) + { + this->m_Cursor->VisibilityOff( ); + cursor_visible = false; + this->Interactor->Render( ); + + } // fi + + } // fi + + this->Superclass::OnMouseMove( ); +} + +/* TODO cpExtensions::Visualization::ImageViewerActors* cpExtensions::Interaction::ImageSliceStyle:: GetActors( ) @@ -110,12 +153,21 @@ void cpExtensions::Interaction::ImageSliceStyle:: OnChar( ) { } +*/ // ------------------------------------------------------------------------- cpExtensions::Interaction::ImageSliceStyle:: ImageSliceStyle( ) : Superclass( ) { + this->SetInteractionModeToImage2D( ); + this->m_PropPicker = vtkSmartPointer< vtkPropPicker >::New( ); + this->m_PropPicker->PickFromListOn( ); + + this->m_Cursor = vtkSmartPointer< TCursor >::New( ); + this->m_Cursor->VisibilityOff( ); + this->m_Cursor->GetProperty( 0 )->SetColor( 1, 1, 0 ); + this->m_Cursor->GetProperty( 1 )->SetColor( 1, 1, 0 ); } // ------------------------------------------------------------------------- @@ -124,10 +176,57 @@ cpExtensions::Interaction::ImageSliceStyle:: { } +// ------------------------------------------------------------------------- +vtkProp* cpExtensions::Interaction::ImageSliceStyle:: +_ImageActor( int i ) +{ + if( !this->CurrentRenderer ) + return( NULL ); + + vtkPropCollection* props = this->CurrentRenderer->GetViewProps( ); + vtkProp* prop = 0; + vtkAssemblyPath* path; + vtkImageSlice* imageProp = NULL; + vtkCollectionSimpleIterator pit; + + for( int k = 0; k < 2; k++ ) + { + int j = 0; + for( props->InitTraversal( pit ); ( prop = props->GetNextProp( pit ) ); ) + { + bool foundImageProp = false; + for( prop->InitPathTraversal( ); ( path = prop->GetNextPath( ) ); ) + { + vtkProp* tryProp = path->GetLastNode( )->GetViewProp( ); + if( ( imageProp = vtkImageSlice::SafeDownCast( tryProp ) ) != 0 ) + { + if( j == i ) + { + foundImageProp = true; + break; + + } // fi + imageProp = 0; + j++; + + } // fi + + } // rof + if( foundImageProp ) + break; + } // rof + if( i < 0 ) + i += j; + + } // rof + return( imageProp ); +} + // ------------------------------------------------------------------------- bool cpExtensions::Interaction::ImageSliceStyle:: -_PickPosition( int idx[ 2 ], double pos[ 3 ] ) +_PickPointOnImageActor( int idx[ 2 ], double pnt[ 3 ] ) { + // Check if data is valid if( this->Interactor == NULL || this->CurrentRenderer == NULL || @@ -140,6 +239,34 @@ _PickPosition( int idx[ 2 ], double pos[ 3 ] ) idx[ 1 ] = this->Interactor->GetEventPosition( )[ 1 ]; this->FindPokedRenderer( double( idx[ 0 ] ), double( idx[ 1 ] ) ); + // Check if the image has changed + this->Interactor->GetPicker( )-> + Pick( idx[ 0 ], idx[ 1 ], 0.0, this->CurrentRenderer ); + auto picker = + vtkAbstractPropPicker::SafeDownCast( this->Interactor->GetPicker( ) ); + if( picker == NULL ) + return( false ); + TWLActor* curr_actor = dynamic_cast< TWLActor* >( picker->GetProp3D( ) ); + if( curr_actor != this->m_WLActor.GetPointer( ) && curr_actor != NULL ) + { + this->m_WLActor = curr_actor; + this->m_PropPicker->GetPickList( )->RemoveAllItems( ); + this->m_PropPicker->AddPickList( curr_actor ); + + this->m_Cursor->SetImageBounds( curr_actor->GetImage( )->GetBounds( ) ); + this->m_Cursor->SetImageOrientation( curr_actor->GetOrientation( ) ); + this->m_Cursor->InitTraversal( ); + while( vtkProp* prop = this->m_Cursor->GetNextProp( ) ) + this->CurrentRenderer->AddViewProp( prop ); + + } // fi + if( this->m_WLActor.GetPointer( ) == NULL ) + { + this->m_PropPicker->GetPickList( )->RemoveAllItems( ); + return( false ); + + } // fi + // Pick a 3D position int r = this->m_PropPicker->Pick( double( idx[ 0 ] ), double( idx[ 1 ] ), double( 0 ), @@ -147,7 +274,7 @@ _PickPosition( int idx[ 2 ], double pos[ 3 ] ) ); if( r == 0 ) return( false ); - this->m_PropPicker->GetPickPosition( pos ); + this->m_PropPicker->GetPickPosition( pnt ); return( true ); } diff --git a/lib/cpExtensions/Interaction/ImageSliceStyle.h b/lib/cpExtensions/Interaction/ImageSliceStyle.h index f98ca28..0fe2581 100644 --- a/lib/cpExtensions/Interaction/ImageSliceStyle.h +++ b/lib/cpExtensions/Interaction/ImageSliceStyle.h @@ -1,7 +1,8 @@ #ifndef __cpExtensions__Interaction__ImageSliceStyle__h__ #define __cpExtensions__Interaction__ImageSliceStyle__h__ -#include +#include +#include #include // ------------------------------------------------------------------------- @@ -10,39 +11,49 @@ class vtkPropPicker; // ------------------------------------------------------------------------- namespace cpExtensions { - namespace Visualization { class ImageViewerActors; } - + namespace Visualization + { + class CursorActors; + class WindowLevelImageActor; + } namespace Interaction { /** */ class cpExtensions_EXPORT ImageSliceStyle - : public BaseStyle + : public vtkInteractorStyleImage { public: typedef ImageSliceStyle Self; + typedef cpExtensions::Visualization::CursorActors TCursor; + typedef cpExtensions::Visualization::WindowLevelImageActor TWLActor; public: - vtkTypeMacro( ImageSliceStyle, BaseStyle ); + vtkTypeMacro( ImageSliceStyle, vtkInteractorStyleImage ); public: static Self* New( ); - cpExtensions::Visualization::ImageViewerActors* GetActors( ); - const cpExtensions::Visualization::ImageViewerActors* GetActors( ) const; - void SetActors( cpExtensions::Visualization::ImageViewerActors* actors ); - - // Events virtual void OnMouseMove( ) cpExtensions_OVERRIDE; - virtual void OnMouseWheelForward( ) cpExtensions_OVERRIDE; - virtual void OnMouseWheelBackward( ) cpExtensions_OVERRIDE; - virtual void OnChar( ) cpExtensions_OVERRIDE; + + /* TODO + cpExtensions::Visualization::ImageViewerActors* GetActors( ); + const cpExtensions::Visualization::ImageViewerActors* GetActors( ) const; + void SetActors( cpExtensions::Visualization::ImageViewerActors* actors ); + + // Events + virtual void OnMouseMove( ) cpExtensions_OVERRIDE; + virtual void OnMouseWheelForward( ) cpExtensions_OVERRIDE; + virtual void OnMouseWheelBackward( ) cpExtensions_OVERRIDE; + virtual void OnChar( ) cpExtensions_OVERRIDE; + */ protected: ImageSliceStyle( ); virtual ~ImageSliceStyle( ); - virtual bool _PickPosition( int idx[ 2 ], double pos[ 3 ] ) cpExtensions_OVERRIDE; + virtual vtkProp* _ImageActor( int i ); + virtual bool _PickPointOnImageActor( int idx[ 2 ], double pnt[ 3 ] ); private: // Purposely not implemented @@ -50,8 +61,12 @@ namespace cpExtensions Self& operator=( const Self& ); protected: - vtkSmartPointer< cpExtensions::Visualization::ImageViewerActors > m_Actors; vtkSmartPointer< vtkPropPicker > m_PropPicker; + vtkSmartPointer< TWLActor > m_WLActor; + vtkSmartPointer< TCursor > m_Cursor; + /* TODO + vtkSmartPointer< cpExtensions::Visualization::ImageViewerActors > m_Actors; + */ }; } // ecapseman diff --git a/lib/cpExtensions/QT/ImageWidget.cxx b/lib/cpExtensions/QT/ImageWidget.cxx index 0978844..af448c1 100644 --- a/lib/cpExtensions/QT/ImageWidget.cxx +++ b/lib/cpExtensions/QT/ImageWidget.cxx @@ -2,25 +2,29 @@ #ifdef cpExtensions_QT4 -#include -#include -#include #include -#include -#include -#include +#include +#include + #include +/* TODO + #include + #include + #include + #include + #include +*/ + // ------------------------------------------------------------------------- cpExtensions::QT::ImageWidget:: ImageWidget( QWidget* parent, Qt::WindowFlags f ) : Superclass( parent, f ), m_ImageName( "" ) { - this->m_ImageSliceStyle = - vtkSmartPointer< cpExtensions::Interaction::ImageSliceStyle >::New( ); - this->m_ImageSliceStyle->SetCurrentRenderer( this->m_Renderer ); - this->SetStyle( this->m_ImageSliceStyle ); + this->m_Style = vtkSmartPointer< TStyle >::New( ); + this->m_Style->SetCurrentRenderer( this->m_Renderer ); + this->SetStyle( this->m_Style ); } // ------------------------------------------------------------------------- @@ -29,6 +33,42 @@ cpExtensions::QT::ImageWidget:: { } +// ------------------------------------------------------------------------- +void cpExtensions::QT::ImageWidget:: +Clear( ) +{ + this->RemoveViewProps( ); + this->m_ImageName = ""; +} + +// ------------------------------------------------------------------------- +void cpExtensions::QT::ImageWidget:: +SetImage( vtkImageData* image, int orientation, const std::string& name ) +{ + if( name == "" ) + return; + if( this->m_ImageName != "" ) + this->Clear( ); + this->m_ImageName = name; + + this->m_WLActor = vtkSmartPointer< TWLActor >::New( ); + this->m_WLActor->SetImage( image ); + this->m_WLActor->SetOrientation( orientation ); + + this->m_OLActor = vtkSmartPointer< TOLActor >::New( ); + this->m_OLActor->SetBounds( + orientation, + this->m_WLActor->GetBounds( )[ orientation ], + this->m_WLActor->GetBounds( ) + ); + + this->AddViewProp( this->m_WLActor, this->m_ImageName ); + this->AddAuxViewProp( this->m_OLActor, this->m_ImageName ); + this->ResetCamera( ); +} + + +/* TODO // ------------------------------------------------------------------------- vtkInteractorStyle* cpExtensions::QT::ImageWidget:: GetInteractorStyle( ) @@ -78,12 +118,10 @@ Add( vtkDataSet* data, const std::string& name ) if( image == NULL ) { - /* TODO if( this->m_ImageName == "" ) this->SetImage( data, name ); { } // fi - */ return; } // fi @@ -302,6 +340,21 @@ SetImageInterpolation( unsigned char i ) } // fi } +// ------------------------------------------------------------------------- +vtkProp* cpExtensions::QT::ImageWidget:: +GetImageActor( ) +{ + return( this->m_ImageViewerActors->GetWindowLevelImageActor( ) ); +} + +// ------------------------------------------------------------------------- +const vtkProp* cpExtensions::QT::ImageWidget:: +GetImageActor( ) const +{ + return( this->m_ImageViewerActors->GetWindowLevelImageActor( ) ); +} +*/ + #endif // cpExtensions_QT4 // eof - $RCSfile$ diff --git a/lib/cpExtensions/QT/ImageWidget.h b/lib/cpExtensions/QT/ImageWidget.h index cbf3885..eeb65d0 100644 --- a/lib/cpExtensions/QT/ImageWidget.h +++ b/lib/cpExtensions/QT/ImageWidget.h @@ -5,14 +5,18 @@ #ifdef cpExtensions_QT4 -class vtkDataSet; +// TODO: class vtkDataSet; namespace cpExtensions { namespace Visualization { - class ImageSliceActors; - class ImageViewerActors; + class ImageOutlineActor; + class WindowLevelImageActor; + /* TODO + class ImageSliceActors; + class ImageViewerActors; + */ } namespace Interaction { class ImageSliceStyle; } @@ -29,40 +33,61 @@ namespace cpExtensions typedef ImageWidget Self; typedef RendererWidget Superclass; + typedef cpExtensions::Visualization::ImageOutlineActor TOLActor; + typedef cpExtensions::Visualization::WindowLevelImageActor TWLActor; + typedef cpExtensions::Interaction::ImageSliceStyle TStyle; + public: explicit ImageWidget( QWidget* parent = NULL, Qt::WindowFlags f = 0 ); virtual ~ImageWidget( ); - vtkInteractorStyle* GetInteractorStyle( ); - const vtkInteractorStyle* GetInteractorStyle( ) const; - + void Clear( ); void SetImage( vtkImageData* image, int orientation, const std::string& name ); - void Add( vtkDataSet* data, const std::string& name ); - // TODO: std::vector< vtkProp* > GetActors( const std::string& name ) const; - int GetOrientation( ) const; - void SetSliceNumber( int slice ); + /* TODO + void SetImage( + vtkImageData* image, int orientation, const std::string& name + ); + void Add( vtkDataSet* data, const std::string& name ); + + // TODO: std::vector< vtkProp* > GetActors( const std::string& name ) const; + int GetOrientation( ) const; + void SetSliceNumber( int slice ); + + virtual void ResetCamera( ) cpExtensions_OVERRIDE; - virtual void ResetCamera( ) cpExtensions_OVERRIDE; + void GetScalarRange( double r[ 2 ] ) const; + void GetWindowLevel( double wl[ 2 ] ) const; + double GetImageOpacity( ) const; + unsigned char GetImageInterpolation( ) const; - void GetScalarRange( double r[ 2 ] ) const; - void GetWindowLevel( double wl[ 2 ] ) const; - double GetImageOpacity( ) const; - unsigned char GetImageInterpolation( ) const; + void SetScalarRange( double r[ 2 ] ); + void SetWindowLevel( double wl[ 2 ] ); + void SetImageOpacity( double o ); + void SetImageInterpolation( unsigned char i ); - void SetScalarRange( double r[ 2 ] ); - void SetWindowLevel( double wl[ 2 ] ); - void SetImageOpacity( double o ); - void SetImageInterpolation( unsigned char i ); + vtkProp* GetImageActor( ); + const vtkProp* GetImageActor( ) const; + */ protected: - vtkSmartPointer< cpExtensions::Visualization::ImageViewerActors > - m_ImageViewerActors; - vtkSmartPointer< cpExtensions::Interaction::ImageSliceStyle > - m_ImageSliceStyle; std::string m_ImageName; + + vtkSmartPointer< TWLActor > m_WLActor; + vtkSmartPointer< TOLActor > m_OLActor; + + vtkSmartPointer< TStyle > m_Style; + + /* TODO + protected: + vtkSmartPointer< cpExtensions::Visualization::ImageViewerActors > + m_ImageViewerActors; + vtkSmartPointer< cpExtensions::Interaction::ImageSliceStyle > + m_ImageSliceStyle; + std::string m_ImageName; + */ }; } // ecapseman diff --git a/lib/cpExtensions/QT/MPRInteractionCommand.cxx b/lib/cpExtensions/QT/MPRInteractionCommand.cxx index bc3b1a5..b65266f 100644 --- a/lib/cpExtensions/QT/MPRInteractionCommand.cxx +++ b/lib/cpExtensions/QT/MPRInteractionCommand.cxx @@ -20,21 +20,24 @@ New( ) void cpExtensions::QT::MPRInteractionCommand:: AddWidget( QWidget* w ) { - typedef cpExtensions::QT::ImageWidget _TImageWidget; - typedef cpExtensions::QT::MPR3DWidget _TMPR3DWidget; + /* + typedef cpExtensions::QT::ImageWidget _TImageWidget; + typedef cpExtensions::QT::MPR3DWidget _TMPR3DWidget; - auto img = dynamic_cast< _TImageWidget* >( w ); - auto ren = dynamic_cast< _TMPR3DWidget* >( w ); - if( img != NULL ) + auto img = dynamic_cast< _TImageWidget* >( w ); + auto ren = dynamic_cast< _TMPR3DWidget* >( w ); + if( img != NULL ) this->m_ImageWidgets.insert( img ); - else if( ren != NULL ) + else if( ren != NULL ) this->m_MPR3DWidgets.insert( ren ); + */ } // ------------------------------------------------------------------------- void cpExtensions::QT::MPRInteractionCommand:: Execute( vtkObject* caller, unsigned long evId, void* data ) { + /* typedef cpExtensions::Interaction::ImageSliceStyle _TStyle; static const unsigned long _SuperCursor = vtkCommand::UserEvent + 1; @@ -80,6 +83,7 @@ Execute( vtkObject* caller, unsigned long evId, void* data ) ( *r )->SetSliceNumber( ori, slice ); } // fi + */ } // ------------------------------------------------------------------------- diff --git a/lib/cpExtensions/QT/RendererWidget.cxx b/lib/cpExtensions/QT/RendererWidget.cxx index 5d44fcd..251ecea 100644 --- a/lib/cpExtensions/QT/RendererWidget.cxx +++ b/lib/cpExtensions/QT/RendererWidget.cxx @@ -3,6 +3,7 @@ #ifdef cpExtensions_QT4 #include +#include #include #include #include @@ -74,11 +75,13 @@ GetRenderer( ) const vtkInteractorStyle* cpExtensions::QT::RendererWidget:: GetStyle( ) { - return( - dynamic_cast< vtkInteractorStyle* >( - this->GetInteractor( )->GetInteractorStyle( ) - ) - ); + auto iren = this->GetInteractor( ); + if( iren != NULL ) + return( + dynamic_cast< vtkInteractorStyle* >( iren->GetInteractorStyle( ) ) + ); + else + return( NULL ); } // ------------------------------------------------------------------------- @@ -88,11 +91,17 @@ GetStyle( ) const // Ugly, but necessary :-( Self* self = const_cast< Self* >( this ); if( self != NULL ) - return( - dynamic_cast< const vtkInteractorStyle* >( - self->GetInteractor( )->GetInteractorStyle( ) - ) - ); + { + auto iren = self->GetInteractor( ); + if( iren != NULL ) + return( + dynamic_cast< const vtkInteractorStyle* >( + iren->GetInteractorStyle( ) + ) + ); + else + return( NULL ); + } else return( NULL ); } @@ -124,15 +133,14 @@ AddViewProp( vtkProp* prop, const std::string& name ) { if( prop != NULL ) { - if( this->m_ViewProps.find( name ) == this->m_ViewProps.end( ) ) - { - vtkSmartPointer< vtkPropCollection > coll = - vtkSmartPointer< vtkPropCollection >::New( ); - coll->AddItem( prop ); - this->m_ViewProps[ name ] = coll; - this->m_Renderer->AddViewProp( prop ); - - } // fi + auto i = this->m_ViewProps.find( name ); + if( i == this->m_ViewProps.end( ) ) + i = + this->m_ViewProps.insert( + TPropCollection::value_type( name, TProps( ) ) + ).first; + i->second.insert( prop ); + this->m_Renderer->AddViewProp( prop ); } // fi } @@ -143,14 +151,19 @@ AddViewProps( vtkPropCollection* props, const std::string& name ) { if( props != NULL ) { - if( this->m_ViewProps.find( name ) == this->m_ViewProps.end( ) ) + auto i = this->m_ViewProps.find( name ); + if( i == this->m_ViewProps.end( ) ) + i = + this->m_ViewProps.insert( + TPropCollection::value_type( name, TProps( ) ) + ).first; + props->InitTraversal( ); + while( vtkProp* prop = props->GetNextProp( ) ) { - this->m_ViewProps[ name ] = props; - props->InitTraversal( ); - while( vtkProp* p = props->GetNextProp( ) ) - this->m_Renderer->AddViewProp( p ); + i->second.insert( prop ); + this->m_Renderer->AddViewProp( prop ); - } // fi + } // elihw } // fi } @@ -161,21 +174,14 @@ AddAuxViewProp( vtkProp* prop, const std::string& name ) { if( prop != NULL ) { - if( this->m_ViewProps.find( name ) != this->m_ViewProps.end( ) ) - { - auto a = this->m_AuxViewProps.find( name ); - vtkSmartPointer< vtkPropCollection > coll; - if( a == this->m_AuxViewProps.end( ) ) - { - coll = vtkSmartPointer< vtkPropCollection >::New( ); - this->m_AuxViewProps[ name ] = coll; - } - else - coll = a->second; - coll->AddItem( prop ); - this->m_Renderer->AddViewProp( prop ); - - } // fi + auto i = this->m_AuxViewProps.find( name ); + if( i == this->m_AuxViewProps.end( ) ) + i = + this->m_AuxViewProps.insert( + TPropCollection::value_type( name, TProps( ) ) + ).first; + i->second.insert( prop ); + this->m_Renderer->AddViewProp( prop ); } // fi } @@ -184,53 +190,81 @@ AddAuxViewProp( vtkProp* prop, const std::string& name ) void cpExtensions::QT::RendererWidget:: AddAuxViewProps( vtkPropCollection* props, const std::string& name ) { - props->InitTraversal( ); - while( auto p = props->GetNextProp( ) ) - this->AddAuxViewProp( p, name ); + if( props != NULL ) + { + auto i = this->m_AuxViewProps.find( name ); + if( i == this->m_AuxViewProps.end( ) ) + i = + this->m_AuxViewProps.insert( + TPropCollection::value_type( name, TProps( ) ) + ).first; + props->InitTraversal( ); + while( vtkProp* prop = props->GetNextProp( ) ) + { + i->second.insert( prop ); + this->m_Renderer->AddViewProp( prop ); + + } // elhiw + + } // fi } // ------------------------------------------------------------------------- -vtkPropCollection* cpExtensions::QT::RendererWidget:: +cpExtensions::QT::RendererWidget:: +TProps& cpExtensions::QT::RendererWidget:: GetViewProps( const std::string& name ) { + static TProps zero; auto i = this->m_ViewProps.find( name ); - if( i != this->m_ViewProps.end( ) ) - return( i->second ); + if( i == this->m_ViewProps.end( ) ) + { + zero.clear( ); + return( zero ); + } else - return( NULL ); + return( i->second ); } // ------------------------------------------------------------------------- -const vtkPropCollection* cpExtensions::QT::RendererWidget:: +const cpExtensions::QT::RendererWidget:: +TProps& cpExtensions::QT::RendererWidget:: GetViewProps( const std::string& name ) const { + static const TProps zero; auto i = this->m_ViewProps.find( name ); - if( i != this->m_ViewProps.end( ) ) - return( i->second ); + if( i == this->m_ViewProps.end( ) ) + return( zero ); else - return( NULL ); + return( i->second ); } // ------------------------------------------------------------------------- -vtkPropCollection* cpExtensions::QT::RendererWidget:: +cpExtensions::QT::RendererWidget:: +TProps& cpExtensions::QT::RendererWidget:: GetAuxViewProps( const std::string& name ) { + static TProps zero; auto i = this->m_AuxViewProps.find( name ); - if( i != this->m_AuxViewProps.end( ) ) - return( i->second ); + if( i == this->m_AuxViewProps.end( ) ) + { + zero.clear( ); + return( zero ); + } else - return( NULL ); + return( i->second ); } // ------------------------------------------------------------------------- -const vtkPropCollection* cpExtensions::QT::RendererWidget:: +const cpExtensions::QT::RendererWidget:: +TProps& cpExtensions::QT::RendererWidget:: GetAuxViewProps( const std::string& name ) const { + static const TProps zero; auto i = this->m_AuxViewProps.find( name ); - if( i != this->m_AuxViewProps.end( ) ) - return( i->second ); + if( i == this->m_AuxViewProps.end( ) ) + return( zero ); else - return( NULL ); + return( i->second ); } // ------------------------------------------------------------------------- @@ -240,20 +274,18 @@ RemoveViewProps( const std::string& name ) auto i = this->m_ViewProps.find( name ); if( i != this->m_ViewProps.end( ) ) { - i->second->InitTraversal( ); - while( auto p = i->second->GetNextProp( ) ) - this->m_Renderer->RemoveViewProp( p ); + for( auto p = i->second.begin( ); p != i->second.end( ); ++p ) + this->m_Renderer->RemoveViewProp( *p ); this->m_ViewProps.erase( i ); - i = this->m_AuxViewProps.find( name ); - if( i != this->m_AuxViewProps.end( ) ) - { - i->second->InitTraversal( ); - while( auto p = i->second->GetNextProp( ) ) - this->m_Renderer->RemoveViewProp( p ); - this->m_AuxViewProps.erase( i ); + } // fi - } // fi + i = this->m_AuxViewProps.find( name ); + if( i != this->m_AuxViewProps.end( ) ) + { + for( auto p = i->second.begin( ); p != i->second.end( ); ++p ) + this->m_Renderer->RemoveViewProp( *p ); + this->m_AuxViewProps.erase( i ); } // fi } @@ -273,21 +305,12 @@ HideViewProps( const std::string& name ) { auto i = this->m_ViewProps.find( name ); if( i != this->m_ViewProps.end( ) ) - { - i->second->InitTraversal( ); - while( auto p = i->second->GetNextProp( ) ) - p->VisibilityOff( ); - - i = this->m_AuxViewProps.find( name ); - if( i != this->m_AuxViewProps.end( ) ) - { - i->second->InitTraversal( ); - while( auto p = i->second->GetNextProp( ) ) - p->VisibilityOff( ); - - } // fi - - } // fi + for( auto p = i->second.begin( ); p != i->second.end( ); ++p ) + ( *p )->VisibilityOff( ); + i = this->m_AuxViewProps.find( name ); + if( i != this->m_AuxViewProps.end( ) ) + for( auto p = i->second.begin( ); p != i->second.end( ); ++p ) + ( *p )->VisibilityOff( ); } // ------------------------------------------------------------------------- @@ -296,178 +319,18 @@ ShowViewProps( const std::string& name ) { auto i = this->m_ViewProps.find( name ); if( i != this->m_ViewProps.end( ) ) - { - i->second->InitTraversal( ); - while( auto p = i->second->GetNextProp( ) ) - p->VisibilityOn( ); - - i = this->m_AuxViewProps.find( name ); - if( i != this->m_AuxViewProps.end( ) ) - { - i->second->InitTraversal( ); - while( auto p = i->second->GetNextProp( ) ) - p->VisibilityOn( ); - - } // fi - - } // fi -} - - -/* -// ------------------------------------------------------------------------- -const cpExtensions::QT::RendererWidget:: -TNamedActors& cpExtensions::QT::RendererWidget:: -GetNamedActors( ) const -{ - return( this->m_NamedActors ); -} - -// ------------------------------------------------------------------------- -cpExtensions::QT::RendererWidget:: -TProps& cpExtensions::QT::RendererWidget:: -GetViewProps( const std::string& name ) -{ - static TProps empty; - auto i = this->m_NamedActors.find( name ); - if( i == this->m_NamedActors.end( ) ) - { - empty = NULL; - return( empty ); - } - else - return( i->second ); -} - -// ------------------------------------------------------------------------- -const cpExtensions::QT::RendererWidget:: -TProps& cpExtensions::QT::RendererWidget:: -GetViewProps( const std::string& name ) const -{ - static const TProps empty = NULL; - auto i = this->m_NamedActors.find( name ); - if( i == this->m_NamedActors.end( ) ) - return( empty ); - else - return( i->second ); -} - -// ------------------------------------------------------------------------- -void cpExtensions::QT::RendererWidget:: -AddViewProp( vtkProp* prop, const std::string& name ) -{ - if( this->m_NamedActors.find( name ) == this->m_NamedActors.end( ) ) - { - TProps coll = TProps::New( ); - coll->AddItem( prop ); - this->m_NamedActors[ name ] = coll; - this->m_Renderer->AddViewProp( prop ); - - } // fi -} - -// ------------------------------------------------------------------------- -void cpExtensions::QT::RendererWidget:: -AddViewProps( vtkPropCollection* coll, const std::string& name ) -{ - if( this->m_NamedActors.find( name ) == this->m_NamedActors.end( ) ) - { - this->m_NamedActors[ name ] = coll; - coll->InitTraversal( ); - while( vtkProp* prop = coll->GetNextProp( ) ) - this->m_Renderer->AddViewProp( prop ); - - } // fi -} - -// ------------------------------------------------------------------------- -void cpExtensions::QT::RendererWidget:: -RemoveViewProps( ) -{ - this->m_Renderer->RemoveAllViewProps( ); - this->m_NamedActors.clear( ); -} - -// ------------------------------------------------------------------------- -void cpExtensions::QT::RendererWidget:: -RemoveViewProps( const std::string& name ) -{ - auto a = this->m_NamedActors.find( name ); - if( a != this->m_NamedActors.end( ) ) - { - a->second->InitTraversal( ); - while( vtkProp* prop = a->second->GetNextProp( ) ) - this->m_Renderer->RemoveViewProp( prop ); - this->m_NamedActors.erase( a ); - - } // fi -} - -// ------------------------------------------------------------------------- -void cpExtensions::QT::RendererWidget:: -HideViewProps( const std::string& name ) -{ - auto a = this->m_NamedActors.find( name ); - if( a != this->m_NamedActors.end( ) ) - { - a->second->InitTraversal( ); - while( vtkProp* prop = a->second->GetNextProp( ) ) - prop->VisibilityOff( ); - - } // fi -} - -// ------------------------------------------------------------------------- -void cpExtensions::QT::RendererWidget:: -ShowViewProps( const std::string& name ) -{ - auto a = this->m_NamedActors.find( name ); - if( a != this->m_NamedActors.end( ) ) - { - a->second->InitTraversal( ); - while( vtkProp* prop = a->second->GetNextProp( ) ) - prop->VisibilityOn( ); - - } // fi + for( auto p = i->second.begin( ); p != i->second.end( ); ++p ) + ( *p )->VisibilityOn( ); + i = this->m_AuxViewProps.find( name ); + if( i != this->m_AuxViewProps.end( ) ) + for( auto p = i->second.begin( ); p != i->second.end( ); ++p ) + ( *p )->VisibilityOn( ); } -*/ // ------------------------------------------------------------------------- void cpExtensions::QT::RendererWidget:: ResetCamera( ) { - /* TODO - double bounds[ 6 ] = { 0, 1, 0, 1, 0, 1 }; - double b[ 6 ]; - bool start = true; - for( - auto props = this->m_ViewProps.begin( ); - props != this->m_ViewProps.end( ); - ++props - ) - { - props->second->InitTraversal( ); - while( - auto prop = dynamic_cast< vtkProp3D* >( props->second->GetNextProp( ) ) - ) - { - if( !start ) - { - prop->GetBounds( b ); - bounds[ 0 ] = ( b[ 0 ] < bounds[ 0 ] )? b[ 0 ]: bounds[ 0 ]; - bounds[ 1 ] = ( bounds[ 1 ] < b[ 1 ] )? b[ 1 ]: bounds[ 1 ]; - bounds[ 2 ] = ( b[ 2 ] < bounds[ 2 ] )? b[ 2 ]: bounds[ 2 ]; - bounds[ 3 ] = ( bounds[ 3 ] < b[ 3 ] )? b[ 3 ]: bounds[ 3 ]; - bounds[ 4 ] = ( b[ 4 ] < bounds[ 4 ] )? b[ 4 ]: bounds[ 4 ]; - bounds[ 5 ] = ( bounds[ 5 ] < b[ 5 ] )? b[ 5 ]: bounds[ 5 ]; - } - else - prop->GetBounds( bounds ); - - } // elihw - - } // rof - */ this->m_Renderer->ResetCamera( ); } diff --git a/lib/cpExtensions/QT/RendererWidget.h b/lib/cpExtensions/QT/RendererWidget.h index b43a3bc..c90803b 100644 --- a/lib/cpExtensions/QT/RendererWidget.h +++ b/lib/cpExtensions/QT/RendererWidget.h @@ -8,6 +8,7 @@ #include #include #include +#include // ------------------------------------------------------------------------- class vtkCamera; @@ -15,7 +16,6 @@ class vtkInteractorStyle; class vtkOrientationMarkerWidget; class vtkProp; class vtkPropCollection; -class vtkRenderer; // ------------------------------------------------------------------------- namespace cpExtensions @@ -33,12 +33,13 @@ namespace cpExtensions typedef RendererWidget Self; typedef cpExtensions_QVTKWidget Superclass; - typedef - std::map< std::string, vtkSmartPointer< vtkPropCollection > > - TProps; + typedef std::set< vtkSmartPointer< vtkProp > > TProps; + typedef std::map< std::string, TProps > TPropCollection; public: - explicit RendererWidget( QWidget* parent = NULL, Qt::WindowFlags f = 0 ); + explicit RendererWidget( + QWidget* parent = NULL, Qt::WindowFlags f = 0 + ); virtual ~RendererWidget( ); int GetQuadrant( ) const; @@ -54,15 +55,19 @@ namespace cpExtensions vtkCamera* GetActiveCamera( ); const vtkCamera* GetActiveCamera( ) const; - void AddViewProp( vtkProp* prop, const std::string& name ); - void AddViewProps( vtkPropCollection* props, const std::string& name ); - void AddAuxViewProp( vtkProp* prop, const std::string& name ); - void AddAuxViewProps( vtkPropCollection* props, const std::string& name ); + void AddViewProp( vtkProp* prop, const std::string& name = "" ); + void AddViewProps( + vtkPropCollection* props, const std::string& name = "" + ); + void AddAuxViewProp( vtkProp* prop, const std::string& name = "" ); + void AddAuxViewProps( + vtkPropCollection* props, const std::string& name = "" + ); - vtkPropCollection* GetViewProps( const std::string& name ); - const vtkPropCollection* GetViewProps( const std::string& name ) const; - vtkPropCollection* GetAuxViewProps( const std::string& name ); - const vtkPropCollection* GetAuxViewProps( const std::string& name ) const; + TProps& GetViewProps( const std::string& name ); + const TProps& GetViewProps( const std::string& name ) const; + TProps& GetAuxViewProps( const std::string& name ); + const TProps& GetAuxViewProps( const std::string& name ) const; void RemoveViewProps( const std::string& name ); void RemoveViewProps( ); @@ -74,12 +79,12 @@ namespace cpExtensions virtual void Render( ); protected: - vtkSmartPointer< vtkRenderer > m_Renderer; + vtkSmartPointer< vtkRenderer > m_Renderer; vtkSmartPointer< vtkOrientationMarkerWidget > m_Marker; int m_Quadrant; - TProps m_ViewProps; - TProps m_AuxViewProps; + TPropCollection m_ViewProps; + TPropCollection m_AuxViewProps; }; } // ecapseman diff --git a/lib/cpExtensions/QT/SimpleMPRWidget.cxx b/lib/cpExtensions/QT/SimpleMPRWidget.cxx index 80390b6..c2382ed 100644 --- a/lib/cpExtensions/QT/SimpleMPRWidget.cxx +++ b/lib/cpExtensions/QT/SimpleMPRWidget.cxx @@ -20,6 +20,7 @@ SimpleMPRWidget( QWidget* parent, Qt::WindowFlags f ) m_UI( new Ui::SimpleMPRWidget ), m_MainImageName( "" ) { +/* this->m_UI->setupUi( this ); // Prepare default configuration @@ -74,6 +75,7 @@ SimpleMPRWidget( QWidget* parent, Qt::WindowFlags f ) this->m_UI->ConfigurationButton, SIGNAL( clicked( ) ), this, SLOT( _ConfigurationButton( ) ) ); +*/ } // ------------------------------------------------------------------------- @@ -180,6 +182,7 @@ bool cpExtensions::QT::SimpleMPRWidget:: Add( vtkDataSet* data, const std::string& name ) { bool success = true; +/* auto image = dynamic_cast< vtkImageData* >( data ); auto pdata = dynamic_cast< vtkPolyData* >( data ); @@ -199,6 +202,7 @@ Add( vtkDataSet* data, const std::string& name ) this->m_3DView->Add( pdata, name ); else success = false; +*/ return( success ); } @@ -207,6 +211,7 @@ cpExtensions::QT::SimpleMPRWidget:: TProps cpExtensions::QT::SimpleMPRWidget:: GetViewProps( const std::string& name ) const { +/* auto x = this->m_XImage->GetViewProps( name ); auto y = this->m_YImage->GetViewProps( name ); auto z = this->m_ZImage->GetViewProps( name ); @@ -218,6 +223,7 @@ GetViewProps( const std::string& name ) const if( z != NULL ) props.insert( z ); if( w != NULL ) props.insert( w ); return( props ); +*/ } // ------------------------------------------------------------------------- @@ -345,88 +351,100 @@ GetWRenderWindow( ) const void cpExtensions::QT::SimpleMPRWidget:: GetScalarRange( double r[ 2 ] ) const { - this->m_XImage->GetScalarRange( r ); +// this->m_XImage->GetScalarRange( r ); } // ------------------------------------------------------------------------- void cpExtensions::QT::SimpleMPRWidget:: GetWindowLevel( double wl[ 2 ] ) const { - this->m_XImage->GetWindowLevel( wl ); +// this->m_XImage->GetWindowLevel( wl ); } // ------------------------------------------------------------------------- double cpExtensions::QT::SimpleMPRWidget:: GetImageOpacity( ) const { - return( this->m_XImage->GetImageOpacity( ) ); +// return( this->m_XImage->GetImageOpacity( ) ); } // ------------------------------------------------------------------------- unsigned char cpExtensions::QT::SimpleMPRWidget:: GetImageInterpolation( ) const { - return( this->m_XImage->GetImageInterpolation( ) ); +// return( this->m_XImage->GetImageInterpolation( ) ); } // ------------------------------------------------------------------------- void cpExtensions::QT::SimpleMPRWidget:: SetScalarRange( double r[ 2 ] ) { +/* this->m_XImage->SetScalarRange( r ); this->m_YImage->SetScalarRange( r ); this->m_ZImage->SetScalarRange( r ); this->m_3DView->SetScalarRange( r ); +*/ } // ------------------------------------------------------------------------- void cpExtensions::QT::SimpleMPRWidget:: SetWindowLevel( double wl[ 2 ] ) { +/* this->m_XImage->SetWindowLevel( wl ); this->m_YImage->SetWindowLevel( wl ); this->m_ZImage->SetWindowLevel( wl ); this->m_3DView->SetWindowLevel( wl ); +*/ } // ------------------------------------------------------------------------- void cpExtensions::QT::SimpleMPRWidget:: SetImageOpacity( double o ) { +/* this->m_XImage->SetImageOpacity( o ); this->m_YImage->SetImageOpacity( o ); this->m_ZImage->SetImageOpacity( o ); this->m_3DView->SetImageOpacity( o ); +*/ } // ------------------------------------------------------------------------- void cpExtensions::QT::SimpleMPRWidget:: SetImageInterpolation( unsigned char i ) { + /* this->m_XImage->SetImageInterpolation( i ); this->m_YImage->SetImageInterpolation( i ); this->m_ZImage->SetImageInterpolation( i ); this->m_3DView->SetImageInterpolation( i ); +*/ } // ------------------------------------------------------------------------- void cpExtensions::QT::SimpleMPRWidget:: ResetCameras( ) { +/* this->m_XImage->ResetCamera( ); this->m_YImage->ResetCamera( ); this->m_ZImage->ResetCamera( ); this->m_3DView->ResetCamera( ); +*/ } // ------------------------------------------------------------------------- void cpExtensions::QT::SimpleMPRWidget:: Render( ) { +/* this->m_XImage->Render( ); this->m_YImage->Render( ); this->m_ZImage->Render( ); this->m_3DView->Render( ); +*/ } // ------------------------------------------------------------------------- diff --git a/lib/cpExtensions/Visualization/ImageActor.cxx b/lib/cpExtensions/Visualization/ImageActor.cxx index 7241cdb..9c19f36 100644 --- a/lib/cpExtensions/Visualization/ImageActor.cxx +++ b/lib/cpExtensions/Visualization/ImageActor.cxx @@ -38,9 +38,6 @@ GetSliceNumber( ) const return( this->m_Mapper->GetSliceNumber( ) ); } -#include -#include - // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageActor:: SetSliceNumber( int slice ) @@ -57,15 +54,6 @@ SetSliceNumber( int slice ) s = this->m_Mapper->GetSliceNumberMaxValue( ); this->m_Mapper->SetSliceNumber( s ); - // Update display extent - /* TODO - int ext[ 6 ]; - image->GetExtent( ext ); - int o = this->m_Mapper->GetOrientation( ); - ext[ o << 1 ] = ext[ ( o << 1 ) + 1 ] = s; - this->SetDisplayExtent( ext ); - */ - // Propagate modifications this->Modified( ); mySlice = slice; diff --git a/lib/cpExtensions/Visualization/ImageOutlineActor.h b/lib/cpExtensions/Visualization/ImageOutlineActor.h index fc7ccec..5ba8c73 100644 --- a/lib/cpExtensions/Visualization/ImageOutlineActor.h +++ b/lib/cpExtensions/Visualization/ImageOutlineActor.h @@ -29,7 +29,7 @@ namespace cpExtensions public: static Self* New( ); - virtual void Modified( ) VTK_OVERRIDE; + virtual void Modified( ) cpExtensions_OVERRIDE; void SetBounds( int orientation, double step, double* bounds ); diff --git a/lib/cpExtensions/Visualization/MPR3DActors.cxx b/lib/cpExtensions/Visualization/MPR3DActors.cxx index a63e272..03778b4 100644 --- a/lib/cpExtensions/Visualization/MPR3DActors.cxx +++ b/lib/cpExtensions/Visualization/MPR3DActors.cxx @@ -132,24 +132,18 @@ AddMesh( vtkPolyData* mesh ) void cpExtensions::Visualization::MPR3DActors:: SetScalarRange( double r[ 2 ] ) { - this->m_Slices[ 0 ]-> - GetWindowLevelImageActor( )->ConfigureWindowLevel( r[ 0 ], r[ 1 ] ); - this->m_Slices[ 1 ]-> - GetWindowLevelImageActor( )->ConfigureWindowLevel( r[ 0 ], r[ 1 ] ); - this->m_Slices[ 2 ]-> - GetWindowLevelImageActor( )->ConfigureWindowLevel( r[ 0 ], r[ 1 ] ); + this->m_Slices[ 0 ]->GetWindowLevelImageActor( )->SetRange( r ); + this->m_Slices[ 1 ]->GetWindowLevelImageActor( )->SetRange( r ); + this->m_Slices[ 2 ]->GetWindowLevelImageActor( )->SetRange( r ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPR3DActors:: SetWindowLevel( double wl[ 2 ] ) { - this->m_Slices[ 0 ]-> - GetWindowLevelImageActor( )->SetWindowLevel( wl[ 0 ], wl[ 1 ] ); - this->m_Slices[ 1 ]-> - GetWindowLevelImageActor( )->SetWindowLevel( wl[ 0 ], wl[ 1 ] ); - this->m_Slices[ 2 ]-> - GetWindowLevelImageActor( )->SetWindowLevel( wl[ 0 ], wl[ 1 ] ); + this->m_Slices[ 0 ]->GetWindowLevelImageActor( )->SetWindowLevel( wl ); + this->m_Slices[ 1 ]->GetWindowLevelImageActor( )->SetWindowLevel( wl ); + this->m_Slices[ 2 ]->GetWindowLevelImageActor( )->SetWindowLevel( wl ); } // ------------------------------------------------------------------------- diff --git a/lib/cpExtensions/Visualization/WindowLevelImageActor.cxx b/lib/cpExtensions/Visualization/WindowLevelImageActor.cxx index 4fe4624..c7cbbd4 100644 --- a/lib/cpExtensions/Visualization/WindowLevelImageActor.cxx +++ b/lib/cpExtensions/Visualization/WindowLevelImageActor.cxx @@ -31,31 +31,51 @@ void cpExtensions::Visualization::WindowLevelImageActor:: SetImage( vtkImageData* image ) { this->m_Mapper->SetInputData( image ); - image->GetScalarRange( this->m_Range ); - this->ResetWindowLevel( ); + this->ResetRange( ); this->Modified( ); } // ------------------------------------------------------------------------- double cpExtensions::Visualization::WindowLevelImageActor:: -GetLevel( ) +GetLevel( ) const { - return( this->GetProperty( )->GetColorLevel( ) ); + Self* self = const_cast< Self* >( this ); + return( self->GetProperty( )->GetColorLevel( ) ); } // ------------------------------------------------------------------------- double cpExtensions::Visualization::WindowLevelImageActor:: -GetWindow( ) +GetWindow( ) const +{ + Self* self = const_cast< Self* >( this ); + return( self->GetProperty( )->GetColorWindow( ) ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::WindowLevelImageActor:: +GetWindowLevel( double wl[ 2 ] ) const { - return( this->GetProperty( )->GetColorWindow( ) ); + Self* self = const_cast< Self* >( this ); + wl[ 0 ] = self->GetProperty( )->GetColorWindow( ); + wl[ 1 ] = self->GetProperty( )->GetColorLevel( ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::WindowLevelImageActor:: +ResetWindowLevel( ) +{ + this->SetWindowLevel( + ( this->m_Range[ 1 ] - this->m_Range[ 0 ] ), + ( this->m_Range[ 1 ] + this->m_Range[ 0 ] ) / double( 2 ) + ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::WindowLevelImageActor:: SetLevel( double l ) { - double old_l = this->GetProperty( )->GetColorLevel( ); - if( l != old_l && this->m_Range[ 0 ] <= l && l <= this->m_Range[ 1 ] ) + double ol = this->GetProperty( )->GetColorLevel( ); + if( l != ol && this->m_Range[ 0 ] <= l && l <= this->m_Range[ 1 ] ) { this->GetProperty( )->SetColorLevel( l ); this->Modified( ); @@ -67,9 +87,9 @@ SetLevel( double l ) void cpExtensions::Visualization::WindowLevelImageActor:: SetWindow( double w ) { - double max_w = this->m_Range[ 1 ] - this->m_Range[ 0 ]; - double old_w = this->GetProperty( )->GetColorWindow( ); - if( w != old_w && double( 0 ) <= w && w <= max_w ) + double mw = this->m_Range[ 1 ] - this->m_Range[ 0 ]; + double ow = this->GetProperty( )->GetColorWindow( ); + if( w != ow && double( 0 ) <= w && w <= mw ) { this->GetProperty( )->SetColorWindow( w ); this->Modified( ); @@ -87,21 +107,24 @@ SetWindowLevel( double w, double l ) // ------------------------------------------------------------------------- void cpExtensions::Visualization::WindowLevelImageActor:: -ResetWindowLevel( ) +SetWindowLevel( double wl[ 2 ] ) { - this->SetWindowLevel( - this->m_Range[ 1 ] - this->m_Range[ 0 ], - ( this->m_Range[ 1 ] + this->m_Range[ 0 ] ) / double( 2 ) - ); + this->SetWindow( wl[ 0 ] ); + this->SetLevel( wl[ 1 ] ); } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::WindowLevelImageActor:: -ConfigureWindowLevel( double min, double max ) +double cpExtensions::Visualization::WindowLevelImageActor:: +GetMinimum( ) const { - this->m_Range[ 0 ] = ( min < max )? min: max; - this->m_Range[ 1 ] = ( min < max )? max: min; - this->ResetWindowLevel( ); + return( this->m_Range[ 0 ] ); +} + +// ------------------------------------------------------------------------- +double cpExtensions::Visualization::WindowLevelImageActor:: +GetMaximum( ) const +{ + return( this->m_Range[ 0 ] ); } // ------------------------------------------------------------------------- @@ -112,12 +135,60 @@ GetRange( double r[ 2 ] ) const r[ 1 ] = this->m_Range[ 1 ]; } +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::WindowLevelImageActor:: +ResetRange( ) +{ + this->GetImage( )->GetScalarRange( this->m_Range ); + this->ResetWindowLevel( ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::WindowLevelImageActor:: +SetMinimum( double a ) +{ + if( this->m_Range[ 0 ] != a ) + { + this->m_Range[ 0 ] = a; + this->ResetWindowLevel( ); + + } // fi +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::WindowLevelImageActor:: +SetMaximum( double b ) +{ + if( this->m_Range[ 1 ] != b ) + { + this->m_Range[ 1 ] = b; + this->ResetWindowLevel( ); + + } // fi +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::WindowLevelImageActor:: +SetRange( double a, double b ) +{ + this->SetMinimum( a ); + this->SetMaximum( b ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::WindowLevelImageActor:: +SetRange( double r[ 2 ] ) +{ + this->SetMinimum( r[ 0 ] ); + this->SetMaximum( r[ 1 ] ); +} + // ------------------------------------------------------------------------- cpExtensions::Visualization::WindowLevelImageActor:: WindowLevelImageActor( ) : Superclass( ) { - this->ConfigureWindowLevel( 0, 0 ); + this->m_Range[ 0 ] = this->m_Range[ 1 ] = double( 0 ); } // ------------------------------------------------------------------------- diff --git a/lib/cpExtensions/Visualization/WindowLevelImageActor.h b/lib/cpExtensions/Visualization/WindowLevelImageActor.h index f3e8277..8af3943 100644 --- a/lib/cpExtensions/Visualization/WindowLevelImageActor.h +++ b/lib/cpExtensions/Visualization/WindowLevelImageActor.h @@ -26,14 +26,23 @@ namespace cpExtensions const vtkImageData* GetImage( ) const; void SetImage( vtkImageData* image ); - double GetLevel( ); - double GetWindow( ); + double GetLevel( ) const; + double GetWindow( ) const; + void GetWindowLevel( double wl[ 2 ] ) const; + void ResetWindowLevel( ); void SetLevel( double l ); void SetWindow( double w ); void SetWindowLevel( double w, double l ); - void ResetWindowLevel( ); - void ConfigureWindowLevel( double min, double max ); + void SetWindowLevel( double wl[ 2 ] ); + + double GetMinimum( ) const; + double GetMaximum( ) const; void GetRange( double r[ 2 ] ) const; + void ResetRange( ); + void SetMinimum( double a ); + void SetMaximum( double b ); + void SetRange( double a, double b ); + void SetRange( double r[ 2 ] ); protected: WindowLevelImageActor( ); -- 2.47.1