From 4e55e875e42fe56e3fb92a38015ffa035ac9d0bb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leonardo=20Fl=C3=B3rez-Valencia?= Date: Wed, 14 Sep 2016 18:09:49 -0500 Subject: [PATCH] Spline widget added. --- appli/examples/plugins/ImageTracer.cxx | 122 ++----- appli/examples/plugins/ShowImage.cxx | 8 +- .../Interaction/ImageSliceStyle.cxx | 218 +++++++++--- .../Interaction/ImageSliceStyle.h | 25 +- lib/cpExtensions/QT/ImageWidget.cxx | 185 ++++++----- lib/cpExtensions/QT/ImageWidget.h | 14 +- lib/cpExtensions/QT/MPR3DWidget.cxx | 107 +++++- lib/cpExtensions/QT/MPR3DWidget.h | 37 ++- lib/cpExtensions/QT/MPRInteractionCommand.cxx | 64 ++-- lib/cpExtensions/QT/SimpleMPRWidget.cxx | 14 +- lib/cpExtensions/Visualization/ImageActor.cxx | 3 - .../Visualization/OutlineSource.cxx | 50 +++ .../Visualization/OutlineSource.h | 48 +++ plugins/Widgets/SplineWidget.cxx | 313 ++++++++++++++++++ plugins/Widgets/SplineWidget.h | 78 +++++ 15 files changed, 997 insertions(+), 289 deletions(-) create mode 100644 lib/cpExtensions/Visualization/OutlineSource.cxx create mode 100644 lib/cpExtensions/Visualization/OutlineSource.h create mode 100644 plugins/Widgets/SplineWidget.cxx create mode 100644 plugins/Widgets/SplineWidget.h diff --git a/appli/examples/plugins/ImageTracer.cxx b/appli/examples/plugins/ImageTracer.cxx index 014d64d..a8624d1 100644 --- a/appli/examples/plugins/ImageTracer.cxx +++ b/appli/examples/plugins/ImageTracer.cxx @@ -2,8 +2,8 @@ #ifdef cpExtensions_QT4 -#include #include +#include #include #include @@ -12,13 +12,15 @@ #include #include +#include - -#include -#include -#include -#include - +/* TODO + #include + #include + #include + #include + #include +*/ #endif // cpExtensions_QT4 @@ -55,8 +57,10 @@ int main( int argc, char* argv[] ) _TWorkspace::Pointer ws = _TWorkspace::New( ); ws->PrintExecutionOn( ); - // Configure reader + // Configure filters auto reader = ws->CreateFilter( "IO", "ImageReader", "reader" ); + auto widget = ws->CreateFilter( "Widgets", "SplineWidget", "spline" ); + ws->Connect( "reader", "spline", "Output", "Input" ); auto params = reader->GetParameters( ); for( int i = 1; i < argc; ++i ) params->AddToOpenFileNameList( "FileNames", argv[ i ] ); @@ -73,89 +77,25 @@ int main( int argc, char* argv[] ) } // 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 + // Qt initialization + QApplication app( argc, argv ); + QMainWindow wnd; + wnd.setGeometry( 0, 0, 1024, 768 ); + cpExtensions::QT::ImageWidget view( &wnd ); + view.SetImage( + reader->GetOutputData< vtkImageData >( "Output" ), 2, "image" + ); + widget->AddInteractor( view.GetInteractor( ) ); + widget->Update( ); + + // Start application and show data + wnd.setCentralWidget( &view ); + wnd.show( ); + int r = app.exec( ); + widget->Modified( ); + widget->Update( ); + widget->GetOutputData< vtkPolyData >( "Output" )->Print( std::cout ); + return( r ); #else // cpExtensions_QT4 return( 0 ); #endif // cpExtensions_QT4 diff --git a/appli/examples/plugins/ShowImage.cxx b/appli/examples/plugins/ShowImage.cxx index 3b9c9dd..c7afea2 100644 --- a/appli/examples/plugins/ShowImage.cxx +++ b/appli/examples/plugins/ShowImage.cxx @@ -88,11 +88,9 @@ int main( int argc, char* argv[] ) } else { - /* TODO - auto view = new cpExtensions::QT::SimpleMPRWidget( &wnd ); - view->SetImage( image, "image" ); - wdg = view; - */ + auto view = new cpExtensions::QT::SimpleMPRWidget( &wnd ); + view->SetImage( image, "image" ); + wdg = view; } // fi diff --git a/lib/cpExtensions/Interaction/ImageSliceStyle.cxx b/lib/cpExtensions/Interaction/ImageSliceStyle.cxx index 0799036..a4770c0 100644 --- a/lib/cpExtensions/Interaction/ImageSliceStyle.cxx +++ b/lib/cpExtensions/Interaction/ImageSliceStyle.cxx @@ -1,3 +1,4 @@ +#include #include #include #include @@ -8,6 +9,10 @@ #include #include #include +#include +#include +#include + /* TODO #include */ @@ -20,6 +25,26 @@ New( ) return( new Self( ) ); } +// ------------------------------------------------------------------------- +int cpExtensions::Interaction::ImageSliceStyle:: +GetSliceNumber( ) const +{ + if( this->m_WLActor.GetPointer( ) != NULL ) + return( this->m_WLActor->GetSliceNumber( ) ); + else + return( -1 ); +} + +// ------------------------------------------------------------------------- +int cpExtensions::Interaction::ImageSliceStyle:: +GetOrientation( ) const +{ + if( this->m_WLActor.GetPointer( ) != NULL ) + return( this->m_WLActor->GetOrientation( ) ); + else + return( -1 ); +} + // ------------------------------------------------------------------------- void cpExtensions::Interaction::ImageSliceStyle:: OnMouseMove( ) @@ -31,9 +56,11 @@ OnMouseMove( ) if( this->_PickPointOnImageActor( idx, pnt ) ) { this->m_Cursor->SetCursor( pnt, false ); + this->_ShowText( pnt ); if( !cursor_visible ) { this->m_Cursor->VisibilityOn( ); + this->m_Text->VisibilityOn( ); cursor_visible = true; } // fi @@ -44,6 +71,7 @@ OnMouseMove( ) if( cursor_visible ) { this->m_Cursor->VisibilityOff( ); + this->m_Text->VisibilityOff( ); cursor_visible = false; this->Interactor->Render( ); @@ -51,7 +79,61 @@ OnMouseMove( ) } // fi - this->Superclass::OnMouseMove( ); + this->Overclass::OnMouseMove( ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::ImageSliceStyle:: +OnMouseWheelForward( ) +{ + static int s = 0; + if( this->m_WLActor.GetPointer( ) == NULL ) + return; + s = this->m_WLActor->GetSliceNumber( ); + s += ( this->Interactor->GetShiftKey( ) == 1 )? 10: 1; + this->m_WLActor->SetSliceNumber( s ); + s = this->m_WLActor->GetSliceNumber( ); + this->InvokeEvent( vtkCommand::UserEvent + 2, &s ); + this->Interactor->Render( ); + this->OnMouseMove( ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::ImageSliceStyle:: +OnMouseWheelBackward( ) +{ + static int s = 0; + if( this->m_WLActor.GetPointer( ) == NULL ) + return; + s = this->m_WLActor->GetSliceNumber( ); + s -= ( this->Interactor->GetShiftKey( ) == 1 )? 10: 1; + this->m_WLActor->SetSliceNumber( s ); + s = this->m_WLActor->GetSliceNumber( ); + this->InvokeEvent( vtkCommand::UserEvent + 2, &s ); + this->Interactor->Render( ); + this->OnMouseMove( ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::ImageSliceStyle:: +OnChar( ) +{ + switch( this->Interactor->GetKeyCode( ) ) + { + case 'r': case 'R': + { + this->FindPokedRenderer( + this->Interactor->GetEventPosition( )[ 0 ], + this->Interactor->GetEventPosition( )[ 1 ] + ); + this->CurrentRenderer->ResetCamera( ); + this->Interactor->Render( ); + } + break; + default: + break; + + } // hctiws } /* TODO @@ -168,6 +250,24 @@ ImageSliceStyle( ) this->m_Cursor->VisibilityOff( ); this->m_Cursor->GetProperty( 0 )->SetColor( 1, 1, 0 ); this->m_Cursor->GetProperty( 1 )->SetColor( 1, 1, 0 ); + + // Prepare text + this->m_TextBuffer[ 0 ] = '\0'; + this->m_Text = vtkSmartPointer< vtkTextActor >::New( ); + this->m_Text->SetTextScaleModeToNone( ); + auto textprop = this->m_Text->GetTextProperty( ); + textprop->SetColor( 1, 1, 0 ); + textprop->SetFontFamilyToCourier( ); + textprop->SetFontSize( 12 ); + textprop->BoldOff( ); + textprop->ItalicOff( ); + textprop->ShadowOff( ); + textprop->SetJustificationToLeft( ); + textprop->SetVerticalJustificationToBottom( ); + auto coord = this->m_Text->GetPositionCoordinate( ); + coord->SetCoordinateSystemToNormalizedViewport( ); + coord->SetValue( 0.01, 0.02 ); + this->m_Text->VisibilityOff( ); } // ------------------------------------------------------------------------- @@ -176,52 +276,6 @@ 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:: _PickPointOnImageActor( int idx[ 2 ], double pnt[ 3 ] ) @@ -258,6 +312,7 @@ _PickPointOnImageActor( int idx[ 2 ], double pnt[ 3 ] ) this->m_Cursor->InitTraversal( ); while( vtkProp* prop = this->m_Cursor->GetNextProp( ) ) this->CurrentRenderer->AddViewProp( prop ); + this->CurrentRenderer->AddViewProp( this->m_Text ); } // fi if( this->m_WLActor.GetPointer( ) == NULL ) @@ -278,4 +333,73 @@ _PickPointOnImageActor( int idx[ 2 ], double pnt[ 3 ] ) return( true ); } +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::ImageSliceStyle:: +_CorrectPosition( double pos[ 3 ], int ijk[ 3 ] ) +{ + if( this->m_WLActor.GetPointer( ) == NULL ) + return; + auto image = this->m_WLActor->GetImage( ); + if( image == NULL ) + return; + + // Approximate image index + double pcoords[ 3 ]; + image->ComputeStructuredCoordinates( pos, ijk, pcoords ); + + // Manually correct index + int ext[ 6 ]; + image->GetExtent( ext ); + for( int i = 0; i < 3; ++i ) + { + if( ijk[ i ] < ext[ i << 1 ] ) + ijk[ i ] = ext[ i << 1 ]; + if( ext[ ( i << 1 ) + 1 ] < ijk[ i ] ) + ijk[ i ] = ext[ ( i << 1 ) + 1 ]; + + } // rof + + // Get real coordinates + int o = this->m_WLActor->GetOrientation( ); + ijk[ o ] = this->m_WLActor->GetSliceNumber( ); + image->GetPoint( image->ComputePointId( ijk ), pos ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::ImageSliceStyle:: +_ShowText( double pos[ 3 ] ) +{ + if( this->m_WLActor.GetPointer( ) == NULL ) + return; + auto image = this->m_WLActor->GetImage( ); + if( image == NULL ) + return; + + int ijk[ 3 ]; + this->_CorrectPosition( pos, ijk ); + int o = this->m_WLActor->GetOrientation( ); + + std::stringstream buffer; + buffer << "Axis: " << char( 'X' + char( o ) ) << std::endl; + int nScl = image->GetNumberOfScalarComponents( ); + buffer + << "Pixel: [" << ijk[ 0 ] + << "," << ijk[ 1 ] + << "," << ijk[ 2 ] << "] = < " + << image->GetScalarComponentAsFloat( ijk[ 0 ], ijk[ 1 ], ijk[ 2 ], 0 ); + for( int n = 1; n < nScl; ++n ) + buffer + << " : " + << image->GetScalarComponentAsFloat( ijk[ 0 ], ijk[ 1 ], ijk[ 2 ], n ); + buffer << " >" << std::endl; + buffer + << "Point: (" + << pos[ 0 ] << ", " << pos[ 1 ] << ", " << pos[ 2 ] + << ")"; + cpExtensions_SPRINTF( this->m_TextBuffer, 1024, buffer.str( ).c_str( ) ); + this->m_Text->SetInput( this->m_TextBuffer ); + this->m_Text->VisibilityOn( ); + this->m_Text->Modified( ); +} + // eof - $RCSfile$ diff --git a/lib/cpExtensions/Interaction/ImageSliceStyle.h b/lib/cpExtensions/Interaction/ImageSliceStyle.h index 0fe2581..9fa3449 100644 --- a/lib/cpExtensions/Interaction/ImageSliceStyle.h +++ b/lib/cpExtensions/Interaction/ImageSliceStyle.h @@ -7,6 +7,7 @@ // ------------------------------------------------------------------------- class vtkPropPicker; +class vtkTextActor; // ------------------------------------------------------------------------- namespace cpExtensions @@ -30,11 +31,19 @@ namespace cpExtensions public: vtkTypeMacro( ImageSliceStyle, vtkInteractorStyleImage ); + typedef vtkInteractorStyleImage::Superclass Overclass; public: static Self* New( ); + int GetSliceNumber( ) const; + int GetOrientation( ) const; + 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( ); @@ -43,8 +52,6 @@ namespace cpExtensions // Events virtual void OnMouseMove( ) cpExtensions_OVERRIDE; - virtual void OnMouseWheelForward( ) cpExtensions_OVERRIDE; - virtual void OnMouseWheelBackward( ) cpExtensions_OVERRIDE; virtual void OnChar( ) cpExtensions_OVERRIDE; */ @@ -52,8 +59,9 @@ namespace cpExtensions ImageSliceStyle( ); virtual ~ImageSliceStyle( ); - virtual vtkProp* _ImageActor( int i ); - virtual bool _PickPointOnImageActor( int idx[ 2 ], double pnt[ 3 ] ); + bool _PickPointOnImageActor( int idx[ 2 ], double pnt[ 3 ] ); + void _CorrectPosition( double pos[ 3 ], int ijk[ 3 ] ); + void _ShowText( double pos[ 3 ] ); private: // Purposely not implemented @@ -62,11 +70,10 @@ namespace cpExtensions protected: vtkSmartPointer< vtkPropPicker > m_PropPicker; - vtkSmartPointer< TWLActor > m_WLActor; - vtkSmartPointer< TCursor > m_Cursor; - /* TODO - vtkSmartPointer< cpExtensions::Visualization::ImageViewerActors > m_Actors; - */ + vtkSmartPointer< TWLActor > m_WLActor; + vtkSmartPointer< TCursor > m_Cursor; + vtkSmartPointer< vtkTextActor > m_Text; + char m_TextBuffer[ 1024 ]; }; } // ecapseman diff --git a/lib/cpExtensions/QT/ImageWidget.cxx b/lib/cpExtensions/QT/ImageWidget.cxx index af448c1..60ca9a0 100644 --- a/lib/cpExtensions/QT/ImageWidget.cxx +++ b/lib/cpExtensions/QT/ImageWidget.cxx @@ -3,15 +3,18 @@ #ifdef cpExtensions_QT4 #include -#include +#include +#include #include +#include +#include +#include #include /* TODO #include #include - #include #include #include */ @@ -20,7 +23,8 @@ cpExtensions::QT::ImageWidget:: ImageWidget( QWidget* parent, Qt::WindowFlags f ) : Superclass( parent, f ), - m_ImageName( "" ) + m_ImageName( "" ), + m_OutlineActor( NULL ) { this->m_Style = vtkSmartPointer< TStyle >::New( ); this->m_Style->SetCurrentRenderer( this->m_Renderer ); @@ -31,6 +35,8 @@ ImageWidget( QWidget* parent, Qt::WindowFlags f ) cpExtensions::QT::ImageWidget:: ~ImageWidget( ) { + if( this->m_OutlineActor != NULL ) + delete this->m_OutlineActor; } // ------------------------------------------------------------------------- @@ -55,18 +61,113 @@ SetImage( vtkImageData* image, int orientation, const std::string& name ) 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->m_Outline = vtkSmartPointer< TOutline >::New( ); + this->m_Outline->SetBounds( image->GetBounds( ) ); + this->m_Outline->Update( ); + + if( this->m_OutlineActor != NULL ) + delete this->m_OutlineActor; + this->m_OutlineActor = new TActor( ); + this->m_OutlineActor->SetMesh( this->m_Outline->GetOutput( ) ); + + double cr = double( 0 ); + double cg = double( 0 ); + double cb = double( 0 ); + switch( this->m_WLActor->GetOrientation( ) ) + { + case 0: cr = double( 1 ); break; + case 1: cg = double( 1 ); break; + case 2: cb = double( 1 ); break; + default: cr = double( 1 ); break; + } // hctiws + this->m_OutlineActor->GetActor( )->GetProperty( )->SetColor( cr, cg, cb ); this->AddViewProp( this->m_WLActor, this->m_ImageName ); - this->AddAuxViewProp( this->m_OLActor, this->m_ImageName ); + this->AddAuxViewProp( this->m_OutlineActor->GetActor( ), this->m_ImageName ); this->ResetCamera( ); } +// ------------------------------------------------------------------------- +void cpExtensions::QT::ImageWidget:: +ResetCamera( ) +{ + if( this->m_WLActor.GetPointer( ) != NULL ) + { + auto image = this->m_WLActor->GetImage( ); + if( image != NULL ) + { + double bounds[ 6 ]; + image->GetBounds( bounds ); + + // Compute camera properties + double center[ 3 ]; + center[ 0 ] = ( bounds[ 1 ] + bounds[ 0 ] ) / double( 2 ); + center[ 1 ] = ( bounds[ 3 ] + bounds[ 2 ] ) / double( 2 ); + center[ 2 ] = ( bounds[ 5 ] + bounds[ 4 ] ) / double( 2 ); + + int ori = this->m_WLActor->GetOrientation( ); + double pos[ 3 ] = { double( 0 ) }; + pos[ ori ] = double( 1 ); + pos[ 0 ] += center[ 0 ]; + pos[ 1 ] += center[ 1 ]; + pos[ 2 ] += center[ 2 ]; + + double up[ 3 ] = { double( 0 ) }; + if( ori == 0 ) + { + if ( this->m_Quadrant == 0 ) up[ 2 ] = double( 1 ); + else if( this->m_Quadrant == 1 ) up[ 2 ] = double( 1 ); + else if( this->m_Quadrant == 2 ) up[ 2 ] = double( 1 ); + else if( this->m_Quadrant == 3 ) up[ 2 ] = double( 1 ); + } + else if( ori == 1 ) + { + if ( this->m_Quadrant == 0 ) up[ 2 ] = double( 1 ); + else if( this->m_Quadrant == 1 ) up[ 2 ] = double( 1 ); + else if( this->m_Quadrant == 2 ) up[ 2 ] = double( 1 ); + else if( this->m_Quadrant == 3 ) up[ 2 ] = double( 1 ); + } + else if( ori == 2 ) + { + if ( this->m_Quadrant == 0 ) up[ 1 ] = double( 1 ); + else if( this->m_Quadrant == 1 ) up[ 1 ] = double( 1 ); + else if( this->m_Quadrant == 2 ) up[ 1 ] = double( 1 ); + else if( this->m_Quadrant == 3 ) up[ 1 ] = double( 1 ); + pos[ 2 ] *= double( -1 ); + + } // fi + + // Reconfigure camera and return + auto camera = this->m_Renderer->GetActiveCamera( ); + camera->ParallelProjectionOn( ); + camera->SetFocalPoint( center ); + camera->SetPosition( pos ); + camera->SetViewUp( up ); + this->m_Renderer->ResetCamera( bounds ); + } + else + this->Superclass::ResetCamera( ); + } + else + this->Superclass::ResetCamera( ); +} + +// ------------------------------------------------------------------------- +cpExtensions::QT::ImageWidget:: +TWLActor* cpExtensions::QT::ImageWidget:: +GetImageActor( ) +{ + return( this->m_WLActor ); +} + +// ------------------------------------------------------------------------- +const cpExtensions::QT::ImageWidget:: +TWLActor* cpExtensions::QT::ImageWidget:: +GetImageActor( ) const +{ + return( this->m_WLActor ); +} + /* TODO // ------------------------------------------------------------------------- @@ -159,70 +260,6 @@ SetSliceNumber( int slice ) this->Render( ); } -// ------------------------------------------------------------------------- -void cpExtensions::QT::ImageWidget:: -ResetCamera( ) -{ - if( this->m_ImageViewerActors.GetPointer( ) != NULL ) - { - auto image = this->m_ImageViewerActors->GetImage( ); - if( image != NULL ) - { - double bounds[ 6 ]; - image->GetBounds( bounds ); - - // Compute camera properties - double center[ 3 ]; - center[ 0 ] = ( bounds[ 1 ] + bounds[ 0 ] ) / double( 2 ); - center[ 1 ] = ( bounds[ 3 ] + bounds[ 2 ] ) / double( 2 ); - center[ 2 ] = ( bounds[ 5 ] + bounds[ 4 ] ) / double( 2 ); - - int ori = this->m_ImageViewerActors->GetOrientation( ); - double pos[ 3 ] = { double( 0 ) }; - pos[ ori ] = double( 1 ); - pos[ 0 ] += center[ 0 ]; - pos[ 1 ] += center[ 1 ]; - pos[ 2 ] += center[ 2 ]; - - double up[ 3 ] = { double( 0 ) }; - if( ori == 0 ) - { - if ( this->m_Quadrant == 0 ) up[ 2 ] = double( 1 ); - else if( this->m_Quadrant == 1 ) up[ 2 ] = double( 1 ); - else if( this->m_Quadrant == 2 ) up[ 2 ] = double( 1 ); - else if( this->m_Quadrant == 3 ) up[ 2 ] = double( 1 ); - } - else if( ori == 1 ) - { - if ( this->m_Quadrant == 0 ) up[ 2 ] = double( 1 ); - else if( this->m_Quadrant == 1 ) up[ 2 ] = double( 1 ); - else if( this->m_Quadrant == 2 ) up[ 2 ] = double( 1 ); - else if( this->m_Quadrant == 3 ) up[ 2 ] = double( 1 ); - } - else if( ori == 2 ) - { - if ( this->m_Quadrant == 0 ) up[ 1 ] = double( 1 ); - else if( this->m_Quadrant == 1 ) up[ 1 ] = double( 1 ); - else if( this->m_Quadrant == 2 ) up[ 1 ] = double( 1 ); - else if( this->m_Quadrant == 3 ) up[ 1 ] = double( 1 ); - pos[ 2 ] *= double( -1 ); - - } // fi - - // Reconfigure camera and return - auto camera = this->m_Renderer->GetActiveCamera( ); - camera->SetFocalPoint( center ); - camera->SetPosition( pos ); - camera->SetViewUp( up ); - this->m_Renderer->ResetCamera( bounds ); - } - else - this->Superclass::ResetCamera( ); - } - else - this->Superclass::ResetCamera( ); -} - // ------------------------------------------------------------------------- void cpExtensions::QT::ImageWidget:: GetScalarRange( double r[ 2 ] ) const diff --git a/lib/cpExtensions/QT/ImageWidget.h b/lib/cpExtensions/QT/ImageWidget.h index eeb65d0..c278557 100644 --- a/lib/cpExtensions/QT/ImageWidget.h +++ b/lib/cpExtensions/QT/ImageWidget.h @@ -11,8 +11,9 @@ namespace cpExtensions { namespace Visualization { - class ImageOutlineActor; + class OutlineSource; class WindowLevelImageActor; + class MeshActor; /* TODO class ImageSliceActors; class ImageViewerActors; @@ -33,7 +34,8 @@ namespace cpExtensions typedef ImageWidget Self; typedef RendererWidget Superclass; - typedef cpExtensions::Visualization::ImageOutlineActor TOLActor; + typedef cpExtensions::Visualization::OutlineSource TOutline; + typedef cpExtensions::Visualization::MeshActor TActor; typedef cpExtensions::Visualization::WindowLevelImageActor TWLActor; typedef cpExtensions::Interaction::ImageSliceStyle TStyle; @@ -45,6 +47,10 @@ namespace cpExtensions void SetImage( vtkImageData* image, int orientation, const std::string& name ); + virtual void ResetCamera( ) cpExtensions_OVERRIDE; + + TWLActor* GetImageActor( ); + const TWLActor* GetImageActor( ) const; /* TODO void SetImage( @@ -56,7 +62,6 @@ namespace cpExtensions int GetOrientation( ) const; void SetSliceNumber( int slice ); - virtual void ResetCamera( ) cpExtensions_OVERRIDE; void GetScalarRange( double r[ 2 ] ) const; void GetWindowLevel( double wl[ 2 ] ) const; @@ -76,7 +81,8 @@ namespace cpExtensions std::string m_ImageName; vtkSmartPointer< TWLActor > m_WLActor; - vtkSmartPointer< TOLActor > m_OLActor; + vtkSmartPointer< TOutline > m_Outline; + TActor* m_OutlineActor; vtkSmartPointer< TStyle > m_Style; diff --git a/lib/cpExtensions/QT/MPR3DWidget.cxx b/lib/cpExtensions/QT/MPR3DWidget.cxx index f0331c0..788fb22 100644 --- a/lib/cpExtensions/QT/MPR3DWidget.cxx +++ b/lib/cpExtensions/QT/MPR3DWidget.cxx @@ -3,13 +3,18 @@ #ifdef cpExtensions_QT4 #include -#include -#include #include -#include #include -#include +#include + +/* TODO + #include + #include + + #include + #include +*/ // ------------------------------------------------------------------------- cpExtensions::QT::MPR3DWidget:: @@ -17,8 +22,10 @@ MPR3DWidget( QWidget* parent, Qt::WindowFlags f ) : Superclass( parent, f ), m_ImageName( "" ) { - this->m_Actors = - vtkSmartPointer< cpExtensions::Visualization::MPR3DActors >::New( ); + /* TODO + this->m_Actors = + vtkSmartPointer< cpExtensions::Visualization::MPR3DActors >::New( ); + */ } // ------------------------------------------------------------------------- @@ -27,9 +34,94 @@ cpExtensions::QT::MPR3DWidget:: { } +// ------------------------------------------------------------------------- +void cpExtensions::QT::MPR3DWidget:: +Clear( ) +{ + this->RemoveViewProps( ); + this->m_ImageName = ""; +} + // ------------------------------------------------------------------------- void cpExtensions::QT::MPR3DWidget:: SetImage( vtkImageData* image, const std::string& name ) +{ + if( name == "" ) + return; + if( this->m_ImageName != "" ) + this->Clear( ); + this->m_ImageName = name; + + for( unsigned int o = 0; o < 3; ++o ) + { + this->m_WLActors[ o ] = vtkSmartPointer< TWLActor >::New( ); + this->m_WLActors[ o ]->SetImage( image ); + this->m_WLActors[ o ]->SetOrientation( o ); + + this->m_OLActors[ o ] = vtkSmartPointer< TOLActor >::New( ); + this->m_OLActors[ o ]->SetBounds( + o, image->GetBounds( )[ o << 1 ], image->GetBounds( ) + ); + + this->AddViewProp( this->m_WLActors[ o ], this->m_ImageName ); + this->AddAuxViewProp( this->m_OLActors[ o ], this->m_ImageName ); + this->ResetCamera( ); + + } // rof +} + +// ------------------------------------------------------------------------- +cpExtensions::QT::MPR3DWidget:: +TWLActor* cpExtensions::QT::MPR3DWidget:: +GetImageActor( int o ) +{ + return( this->m_WLActors[ o % 3 ] ); +} + +// ------------------------------------------------------------------------- +const cpExtensions::QT::MPR3DWidget:: +TWLActor* cpExtensions::QT::MPR3DWidget:: +GetImageActor( int o ) const +{ + return( this->m_WLActors[ o % 3 ] ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::QT::MPR3DWidget:: +SetSliceNumber( int orientation, int slice ) +{ + int o = orientation % 3; + this->m_WLActors[ o ]->SetSliceNumber( slice ); + this->m_OLActors[ o ]->SetBounds( + o, + this->m_WLActors[ o ]->GetSlicePlane( )->GetOrigin( )[ o ], + this->m_WLActors[ o ]->GetImage( )->GetBounds( ) + ); + this->Render( ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::QT::MPR3DWidget:: +SetSlicesNumbers( int x, int y, int z ) +{ + int s[] = { x, y, z }; + for( int o = 0; o < 3; ++o ) + { + this->m_WLActors[ o ]->SetSliceNumber( s[ o ] ); + this->m_OLActors[ o ]->SetBounds( + o, + this->m_WLActors[ o ]->GetSlicePlane( )->GetOrigin( )[ o ], + this->m_WLActors[ o ]->GetImage( )->GetBounds( ) + ); + + } // rof + this->Render( ); +} + +// ------------------------------------------------------------------------- +/* +void cpExtensions::QT::MPR3DWidget:: +SetImage( vtkImageData* image, const std::string& name ) { if( this->m_ImageName != "" ) { @@ -76,7 +168,6 @@ Add( vtkDataSet* data, const std::string& name ) } // fi - /* TODO return; auto image = dynamic_cast< vtkImageData* >( data ); @@ -96,7 +187,6 @@ Add( vtkDataSet* data, const std::string& name ) { } // fi - */ } // ------------------------------------------------------------------------- @@ -148,6 +238,7 @@ SetImageInterpolation( unsigned char i ) this->m_Actors->SetImageInterpolation( i ); this->Render( ); } + */ #endif // cpExtensions_QT4 diff --git a/lib/cpExtensions/QT/MPR3DWidget.h b/lib/cpExtensions/QT/MPR3DWidget.h index b9f3ef6..6dcd864 100644 --- a/lib/cpExtensions/QT/MPR3DWidget.h +++ b/lib/cpExtensions/QT/MPR3DWidget.h @@ -11,7 +11,11 @@ class vtkDataSet; // ------------------------------------------------------------------------- namespace cpExtensions { - namespace Visualization { class MPR3DActors; } + namespace Visualization + { + class ImageOutlineActor; + class WindowLevelImageActor; + } namespace QT { @@ -26,24 +30,43 @@ namespace cpExtensions typedef MPR3DWidget Self; typedef cpExtensions::QT::RendererWidget Superclass; + typedef cpExtensions::Visualization::ImageOutlineActor TOLActor; + typedef cpExtensions::Visualization::WindowLevelImageActor TWLActor; + public: explicit MPR3DWidget( QWidget* parent = NULL, Qt::WindowFlags f = 0 ); virtual ~MPR3DWidget( ); + void Clear( ); void SetImage( vtkImageData* image, const std::string& name ); - void Add( vtkDataSet* data, const std::string& name ); + + TWLActor* GetImageActor( int o ); + const TWLActor* GetImageActor( int o ) const; void SetSliceNumber( int orientation, int slice ); void SetSlicesNumbers( int x, int y, int z ); - void SetScalarRange( double r[ 2 ] ); - void SetWindowLevel( double wl[ 2 ] ); - void SetImageOpacity( double o ); - void SetImageInterpolation( unsigned char i ); + /* TODO + void SetImage( vtkImageData* image, const std::string& name ); + void Add( vtkDataSet* data, const std::string& name ); + + + void SetScalarRange( double r[ 2 ] ); + void SetWindowLevel( double wl[ 2 ] ); + void SetImageOpacity( double o ); + void SetImageInterpolation( unsigned char i ); + */ protected: - vtkSmartPointer< cpExtensions::Visualization::MPR3DActors > m_Actors; std::string m_ImageName; + + vtkSmartPointer< TWLActor > m_WLActors[ 3 ]; + vtkSmartPointer< TOLActor > m_OLActors[ 3 ]; + + /* TODO + vtkSmartPointer< cpExtensions::Visualization::MPR3DActors > m_Actors; + std::string m_ImageName; + */ }; } // ecapseman diff --git a/lib/cpExtensions/QT/MPRInteractionCommand.cxx b/lib/cpExtensions/QT/MPRInteractionCommand.cxx index b65266f..e19eadb 100644 --- a/lib/cpExtensions/QT/MPRInteractionCommand.cxx +++ b/lib/cpExtensions/QT/MPRInteractionCommand.cxx @@ -20,24 +20,21 @@ 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; @@ -49,41 +46,42 @@ Execute( vtkObject* caller, unsigned long evId, void* data ) return; if( evId == _SuperCursor ) { - auto ori = src->GetActors( )->GetOrientation( ); - auto img = src->GetActors( )->GetImage( ); - auto pos = reinterpret_cast< double* >( data ); - int ijk[ 3 ]; - double pcoords[ 3 ]; - img->ComputeStructuredCoordinates( pos, ijk, pcoords ); + /* TODO + auto ori = src->GetActors( )->GetOrientation( ); + auto img = src->GetActors( )->GetImage( ); + auto pos = reinterpret_cast< double* >( data ); + int ijk[ 3 ]; + double pcoords[ 3 ]; + img->ComputeStructuredCoordinates( pos, ijk, pcoords ); - for( - auto i = this->m_ImageWidgets.begin( ); - i != this->m_ImageWidgets.end( ); - ++i - ) - if( ( *i )->GetInteractorStyle( ) != src ) - ( *i )->SetSliceNumber( ijk[ ( *i )->GetOrientation( ) ] ); + for( + auto i = this->m_ImageWidgets.begin( ); + i != this->m_ImageWidgets.end( ); + ++i + ) + if( ( *i )->GetInteractorStyle( ) != src ) + ( *i )->SetSliceNumber( ijk[ ( *i )->GetOrientation( ) ] ); - for( - auto r = this->m_MPR3DWidgets.begin( ); - r != this->m_MPR3DWidgets.end( ); - ++r - ) - ( *r )->SetSlicesNumbers( ijk[ 0 ], ijk[ 1 ], ijk[ 2 ] ); + for( + auto r = this->m_MPR3DWidgets.begin( ); + r != this->m_MPR3DWidgets.end( ); + ++r + ) + ( *r )->SetSlicesNumbers( ijk[ 0 ], ijk[ 1 ], ijk[ 2 ] ); + */ } else if( evId == _Slice ) { - auto slice = *( reinterpret_cast< int* >( data ) ); - auto ori = src->GetActors( )->GetOrientation( ); + int slc = src->GetSliceNumber( ); + int ori = src->GetOrientation( ); for( auto r = this->m_MPR3DWidgets.begin( ); r != this->m_MPR3DWidgets.end( ); ++r ) - ( *r )->SetSliceNumber( ori, slice ); - + ( *r )->SetSliceNumber( ori, slc ); + } // fi - */ } // ------------------------------------------------------------------------- diff --git a/lib/cpExtensions/QT/SimpleMPRWidget.cxx b/lib/cpExtensions/QT/SimpleMPRWidget.cxx index c2382ed..95af5ab 100644 --- a/lib/cpExtensions/QT/SimpleMPRWidget.cxx +++ b/lib/cpExtensions/QT/SimpleMPRWidget.cxx @@ -20,7 +20,6 @@ SimpleMPRWidget( QWidget* parent, Qt::WindowFlags f ) m_UI( new Ui::SimpleMPRWidget ), m_MainImageName( "" ) { -/* this->m_UI->setupUi( this ); // Prepare default configuration @@ -55,12 +54,12 @@ SimpleMPRWidget( QWidget* parent, Qt::WindowFlags f ) cmd->AddWidget( this->m_YImage ); cmd->AddWidget( this->m_ZImage ); cmd->AddWidget( this->m_3DView ); - this->m_XImage->GetInteractorStyle( )->AddObserver( ev1, cmd ); - this->m_YImage->GetInteractorStyle( )->AddObserver( ev1, cmd ); - this->m_ZImage->GetInteractorStyle( )->AddObserver( ev1, cmd ); - this->m_XImage->GetInteractorStyle( )->AddObserver( ev2, cmd ); - this->m_YImage->GetInteractorStyle( )->AddObserver( ev2, cmd ); - this->m_ZImage->GetInteractorStyle( )->AddObserver( ev2, cmd ); + this->m_XImage->GetStyle( )->AddObserver( ev1, cmd ); + this->m_YImage->GetStyle( )->AddObserver( ev1, cmd ); + this->m_ZImage->GetStyle( )->AddObserver( ev1, cmd ); + this->m_XImage->GetStyle( )->AddObserver( ev2, cmd ); + this->m_YImage->GetStyle( )->AddObserver( ev2, cmd ); + this->m_ZImage->GetStyle( )->AddObserver( ev2, cmd ); // Connect slots this->connect( @@ -75,7 +74,6 @@ SimpleMPRWidget( QWidget* parent, Qt::WindowFlags f ) this->m_UI->ConfigurationButton, SIGNAL( clicked( ) ), this, SLOT( _ConfigurationButton( ) ) ); -*/ } // ------------------------------------------------------------------------- diff --git a/lib/cpExtensions/Visualization/ImageActor.cxx b/lib/cpExtensions/Visualization/ImageActor.cxx index 9c19f36..9ce91cf 100644 --- a/lib/cpExtensions/Visualization/ImageActor.cxx +++ b/lib/cpExtensions/Visualization/ImageActor.cxx @@ -42,7 +42,6 @@ GetSliceNumber( ) const void cpExtensions::Visualization::ImageActor:: SetSliceNumber( int slice ) { - static int mySlice; auto image = this->m_Mapper->GetInput( ); if( image != NULL ) { @@ -56,8 +55,6 @@ SetSliceNumber( int slice ) // Propagate modifications this->Modified( ); - mySlice = slice; - this->InvokeEvent( vtkCommand::InteractionEvent, &mySlice ); } // fi } diff --git a/lib/cpExtensions/Visualization/OutlineSource.cxx b/lib/cpExtensions/Visualization/OutlineSource.cxx new file mode 100644 index 0000000..a00a221 --- /dev/null +++ b/lib/cpExtensions/Visualization/OutlineSource.cxx @@ -0,0 +1,50 @@ +#include +#include +#include +#include +#include + +// ------------------------------------------------------------------------- +cpExtensions::Visualization::OutlineSource:: +Self* cpExtensions::Visualization::OutlineSource:: +New( ) +{ + return( new Self( ) ); +} + +// ------------------------------------------------------------------------- +cpExtensions::Visualization::OutlineSource:: +OutlineSource( ) + : Superclass( ) +{ +} + +// ------------------------------------------------------------------------- +cpExtensions::Visualization::OutlineSource:: +~OutlineSource( ) +{ +} + +// ------------------------------------------------------------------------- +int cpExtensions::Visualization::OutlineSource:: +RequestData( + vtkInformation* request, + vtkInformationVector** inputVector, + vtkInformationVector* outputVector + ) +{ + int r = this->Superclass::RequestData( request, inputVector, outputVector ); + + // Complete polydatas to avoid bizarre rendering errors (multi-thread) + vtkInformation *outInfo = outputVector->GetInformationObject( 0 ); + vtkPolyData *output = vtkPolyData::SafeDownCast( + outInfo->Get( vtkDataObject::DATA_OBJECT( ) ) + ); + output->SetVerts( vtkSmartPointer< vtkCellArray >::New( ) ); + output->SetStrips( vtkSmartPointer< vtkCellArray >::New( ) ); + if( this->GenerateFaces != 1 ) + output->SetPolys( vtkSmartPointer< vtkCellArray >::New( ) ); + return( r ); +} + +// eof - $RCSfile$ diff --git a/lib/cpExtensions/Visualization/OutlineSource.h b/lib/cpExtensions/Visualization/OutlineSource.h new file mode 100644 index 0000000..295a5b5 --- /dev/null +++ b/lib/cpExtensions/Visualization/OutlineSource.h @@ -0,0 +1,48 @@ +#ifndef __cpExtensions__Visualization__OutlineSource__h__ +#define __cpExtensions__Visualization__OutlineSource__h__ + +#include +#include + +// ------------------------------------------------------------------------- +namespace cpExtensions +{ + namespace Visualization + { + /** + */ + class cpExtensions_EXPORT OutlineSource + : public vtkOutlineSource + { + public: + typedef OutlineSource Self; + + public: + vtkTypeMacro( OutlineSource, vtkOutlineSource ); + + public: + static Self* New( ); + + protected: + OutlineSource( ); + virtual ~OutlineSource( ); + + virtual int RequestData( + vtkInformation* request, + vtkInformationVector** inputVector, + vtkInformationVector* outputVector + ) cpExtensions_OVERRIDE; + + private: + // Purposely not implemented + OutlineSource( const Self& ); + Self& operator=( const Self& ); + }; + + } // ecapseman + +} // ecapseman + +#endif // __cpExtensions__Visualization__OutlineSource__h__ + +// eof - $RCSfile$ diff --git a/plugins/Widgets/SplineWidget.cxx b/plugins/Widgets/SplineWidget.cxx new file mode 100644 index 0000000..c6e7116 --- /dev/null +++ b/plugins/Widgets/SplineWidget.cxx @@ -0,0 +1,313 @@ +#include +#include +#include +#include + +#include +#include + +// ------------------------------------------------------------------------- +cpPluginsWidgets::SplineWidget:: +SplineWidget( ) + : Superclass( ), + m_Configured( false ) +{ + typedef cpPlugins::BaseObjects::DataObject _TData; + typedef cpPlugins::DataObjects::Mesh _TMesh; + + this->_ConfigureInput< _TData >( "Input", false, false ); + this->_ConfigureOutput< _TMesh >( "Output" ); + this->m_Contour = vtkSmartPointer< vtkPolyData >::New( ); + this->m_Contour->SetPoints( vtkSmartPointer< vtkPoints >::New( ) ); + this->m_Contour->SetVerts( vtkSmartPointer< vtkCellArray >::New( ) ); + this->m_Contour->SetLines( vtkSmartPointer< vtkCellArray >::New( ) ); + this->m_Contour->SetPolys( vtkSmartPointer< vtkCellArray >::New( ) ); + this->m_Contour->SetStrips( vtkSmartPointer< vtkCellArray >::New( ) ); + this->GetOutput( "Output" )->SetVTK( this->m_Contour ); +} + +// ------------------------------------------------------------------------- +cpPluginsWidgets::SplineWidget:: +~SplineWidget( ) +{ +} + +// ------------------------------------------------------------------------- +void cpPluginsWidgets::SplineWidget:: +_GenerateData( ) +{ + typedef cpExtensions::Visualization::WindowLevelImageActor _TActor; + + auto image = this->GetInputData< vtkImageData >( "Input" ); + if( image == NULL ) + this->_Error( "Invalid input image." ); + if( this->m_Interactors.size( ) == 0 ) + this->_Error( "Give at least one interactor." ); + + auto wdg = this->_CreateVTK< vtkSplineWidget >( ); + if( this->m_Configured ) + { + wdg->GetPolyData( this->m_Contour.GetPointer( ) ); + wdg->Off( ); + } + else + { + auto iIt = this->m_Interactors.begin( ); + vtkRenderWindowInteractor* iren = NULL; + vtkRenderer* ren = NULL; + _TActor* actor = NULL; + for( ; iIt != this->m_Interactors.end( ); ++iIt ) + { + auto r = ( *iIt )->GetInteractorStyle( )->GetCurrentRenderer( ); + if( r != NULL ) + { + auto props = r->GetViewProps( ); + if( props != NULL ) + { + props->InitTraversal( ); + while( vtkProp* prop = props->GetNextProp( ) ) + { + auto a = dynamic_cast< _TActor* >( prop ); + if( a != NULL ) + if( a->GetImage( ) == image ) + { + iren = *iIt; + actor = a; + ren = r; + + } // fi + + } // elihw + + } // fi + + } // fi + + } // rof + if( actor == NULL || ren == NULL || iren == NULL ) + this->_Error( "Invalid actor and/or renderer." ); + + // Widget configuration + wdg->SetCurrentRenderer( ren ); + wdg->SetDefaultRenderer( ren ); + wdg->SetInputData( image ); + wdg->SetProp3D( actor ); + wdg->SetInteractor( iren ); + double bnds[ 6 ]; + image->GetBounds( bnds ); + wdg->PlaceWidget( + bnds[ 0 ], bnds[ 1 ], + bnds[ 2 ], bnds[ 3 ], + bnds[ 4 ], bnds[ 5 ] + ); + wdg->ProjectToPlaneOn( ); + wdg->SetProjectionNormalToZAxes( ); + wdg->SetProjectionPosition( + ( + actor->GetBounds( )[ 4 ] + + actor->GetBounds( )[ 5 ] + ) / double( 2 ) + ); + wdg->SetHandleSize( 0.005 ); + wdg->SetNumberOfHandles( 3 ); + wdg->On( ); + this->m_Configured = true; + + } // fi + + /* TODO + + if( this->m_Configured ) + { + if( points->GetNumberOfPoints( ) == 0 ) + { + std::stringstream text; + bool start = true; + for( auto w = this->m_Widgets.begin( ); w != this->m_Widgets.end( ); ++w ) + { + for( auto r = ( *w )->Widgets.begin( ); r != ( *w )->Widgets.end( ); ++r ) + { + auto rep = + dynamic_cast< vtkSeedRepresentation* >( + ( *r )->GetRepresentation( ) + ); + if( rep != NULL ) + { + double pos[ 3 ]; + for( unsigned int i = 0; i < rep->GetNumberOfSeeds( ); ++i ) + { + rep->GetSeedWorldPosition( i, pos ); + if( !start ) + text << "#"; + start = false; + text << pos[ 0 ] << " " << pos[ 1 ] << " " << pos[ 2 ]; + points->InsertNextPoint( pos ); + + } // rof + + } // rof + ( *r )->EnabledOff( ); + + } // rof + + } // rof + this->m_Parameters.SetString( "Text", text.str( ) ); + + } // fi + } + else + { + auto init_seeds = this->m_Parameters.GetString( "Text" ); + std::vector< std::string > tokens; + cpExtensions::Tokenize( tokens, init_seeds, "#" ); + for( auto tIt = tokens.begin( ); tIt != tokens.end( ); ++tIt ) + { + std::vector< std::string > coords; + cpExtensions::Tokenize( coords, *tIt, " \t" ); + int dim = ( coords.size( ) < 3 )? coords.size( ): 3; + double pos[ 3 ]; + for( unsigned int d = 0; d < 3; ++d ) + { + pos[ d ] = double( 0 ); + if( d < dim ) + { + std::istringstream value( coords[ d ] ); + value >> pos[ d ]; + + } // fi + + } // rof + verts->InsertNextCell( 1 ); + verts->InsertCellPoint( points->GetNumberOfPoints( ) ); + points->InsertNextPoint( pos ); + + } // rof + this->_Configure( ); + this->Modified( ); + this->m_Configured = true; + + } // fi + this->GetOutput( "Output" )->SetVTK( pdata ); + */ +} + +// ------------------------------------------------------------------------- +/* TODO +void cpPluginsWidgets::SplineWidget:: +_Configure( ) +{ + typedef cpPlugins::DataObjects::Image _TImage; + + auto image = this->GetInput< _TImage >( "Input" ); + if( image != NULL ) + { + // Update actors + auto vtk_image = image->GetVTK< vtkImageData >( ); + auto iIt = this->m_Interactors.begin( ); + for( ; iIt != this->m_Interactors.end( ); ++iIt ) + { + auto ren = ( *iIt )->GetInteractorStyle( )->GetCurrentRenderer( ); + if( ren != NULL ) + { + auto props = ren->GetViewProps( ); + if( props != NULL ) + { + props->InitTraversal( ); + while( vtkProp* prop = props->GetNextProp( ) ) + { + auto actor = dynamic_cast< TImageActor* >( prop ); + if( actor != NULL ) + if( actor->GetImage( ) == vtk_image ) + this->m_Props[ actor ] = *iIt; + + } // elihw + + } // fi + + } // fi + + } // rof + + // Process image + if( this->m_Props.size( ) > 0 ) + { + cpPlugins_Demangle_ImageVisualDims( image->GetITK( ), _GD0_Image ); + else this->_Error( "Invalid input image." ); + } + else + this->_Error( "Could not create a valid widget: no actors." ); + } + else + this->_Error( "Could not create a valid widget: no input." ); +} + +// ------------------------------------------------------------------------- +template< class _TImage > +void cpPluginsWidgets::SplineWidget:: +_GD0_Image( _TImage* image ) +{ + for( auto p = this->m_Props.begin( ); p != this->m_Props.end( ); ++p ) + { + TWidgetData* d = + new TWidgetData( + this, dynamic_cast< TImageActor* >( p->first ), p->second + ); + this->m_Widgets.push_back( d ); + + } // rof +} + +// ------------------------------------------------------------------------- +cpPluginsWidgets::SplineWidget::TWidgetData:: +TWidgetData( + SplineWidget* seedWidget, + TImageActor* actor, + vtkRenderWindowInteractor* iren + ) +{ + auto cb = vtkSmartPointer< SplineWidgetCallback >::New( ); + cb->Widget = seedWidget; + cb->Data = this; + this->Command = cb; + actor->AddObserver( vtkCommand::InteractionEvent, cb ); + + auto image = actor->GetImage( ); + int ori = actor->GetOrientation( ); + int ext[ 6 ]; + image->GetExtent( ext ); + for( int i = ext[ ori << 1 ]; i <= ext[ ( ori << 1 ) + 1 ]; ++i ) + { + auto placer = vtkSmartPointer< _TPlacer >::New( ); + auto handle = vtkSmartPointer< vtkPointHandleRepresentation3D >::New( ); + auto rep = vtkSmartPointer< vtkSeedRepresentation >::New( ); + auto wdg = vtkSmartPointer< _TWidget >::New( ); + + placer->SetImageSlice( actor ); + handle->GetProperty( )->SetColor( 1, 0, 0 ); + handle->SetPointPlacer( placer ); + rep->SetHandleRepresentation( handle ); + wdg->SetRepresentation( rep ); + wdg->SetInteractor( iren ); + wdg->AddObserver( vtkCommand::PlacePointEvent, cb ); + wdg->AddObserver( vtkCommand::CursorChangedEvent, cb ); + wdg->EnabledOff( ); + + this->Widgets.push_back( wdg ); + this->Placers.push_back( placer ); + this->Handles.push_back( handle ); + this->Representations.push_back( rep ); + + } // rof + + this->ActualWidgetId = actor->GetSliceNumber( ); + this->Widgets[ this->ActualWidgetId ]->EnabledOn( ); +} + +// ------------------------------------------------------------------------- +cpPluginsWidgets::SplineWidget::TWidgetData:: +~TWidgetData( ) +{ +} +*/ + +// eof - $RCSfile$ diff --git a/plugins/Widgets/SplineWidget.h b/plugins/Widgets/SplineWidget.h new file mode 100644 index 0000000..83b57b2 --- /dev/null +++ b/plugins/Widgets/SplineWidget.h @@ -0,0 +1,78 @@ +#ifndef __cpPluginsWidgets__SplineWidget__h__ +#define __cpPluginsWidgets__SplineWidget__h__ + +#include +#include + +#include + +/* TODO + #include + #include + #include + #include + #include + #include + #include +*/ + +// ------------------------------------------------------------------------- +class vtkPolyData; + +// ------------------------------------------------------------------------- +namespace cpPluginsWidgets +{ + /** + */ + class cpPluginsWidgets_EXPORT SplineWidget + : public cpPlugins::BaseObjects::Widget + { + cpPluginsObject( SplineWidget, cpPlugins::BaseObjects::Widget, Widgets ); + + protected: + bool m_Configured; + vtkSmartPointer< vtkPolyData > m_Contour; + + /* TODO: + public: + typedef cpExtensions::Visualization::WindowLevelImageActor TImageActor; + + public: + struct TWidgetData + { + typedef cpExtensions::Interaction::SplineWidget _TWidget; + typedef cpExtensions::Interaction::ImageSlicePointPlacer _TPlacer; + + std::vector< vtkSmartPointer< _TWidget > > Widgets; + std::vector< vtkSmartPointer< _TPlacer > > Placers; + std::vector< vtkSmartPointer< vtkPointHandleRepresentation3D > > Handles; + std::vector< vtkSmartPointer< vtkSeedRepresentation > > Representations; + unsigned int ActualWidgetId; + vtkSmartPointer< vtkCommand > Command; + + TWidgetData( + SplineWidget* seedWidget, + TImageActor* actor, + vtkRenderWindowInteractor* iren + ); + virtual ~TWidgetData( ); + }; + + protected: + void _Configure( ); + + template< class _TImage > + inline void _GD0_Image( _TImage* image ); + + protected: + std::map< vtkProp*, vtkRenderWindowInteractor* > m_Props; + std::vector< TWidgetData* > m_Widgets; + bool m_Configured; + */ + }; + +} // ecapseman + +#endif // __cpPluginsWidgets__SplineWidget__h__ + +// eof - $RCSfile$ -- 2.45.1