]> Creatis software - cpPlugins.git/commitdiff
Spline widget added.
authorLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Wed, 14 Sep 2016 23:09:49 +0000 (18:09 -0500)
committerLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Wed, 14 Sep 2016 23:09:49 +0000 (18:09 -0500)
15 files changed:
appli/examples/plugins/ImageTracer.cxx
appli/examples/plugins/ShowImage.cxx
lib/cpExtensions/Interaction/ImageSliceStyle.cxx
lib/cpExtensions/Interaction/ImageSliceStyle.h
lib/cpExtensions/QT/ImageWidget.cxx
lib/cpExtensions/QT/ImageWidget.h
lib/cpExtensions/QT/MPR3DWidget.cxx
lib/cpExtensions/QT/MPR3DWidget.h
lib/cpExtensions/QT/MPRInteractionCommand.cxx
lib/cpExtensions/QT/SimpleMPRWidget.cxx
lib/cpExtensions/Visualization/ImageActor.cxx
lib/cpExtensions/Visualization/OutlineSource.cxx [new file with mode: 0644]
lib/cpExtensions/Visualization/OutlineSource.h [new file with mode: 0644]
plugins/Widgets/SplineWidget.cxx [new file with mode: 0644]
plugins/Widgets/SplineWidget.h [new file with mode: 0644]

index 014d64d1e6cf18aafd8d697519406bfa0eaeaafc..a8624d1b8e75494d4e8f1e2386b29788c2ed518b 100644 (file)
@@ -2,8 +2,8 @@
 
 #ifdef cpExtensions_QT4
 
-#include <cpExtensions/QT/SimpleMPRWidget.h>
 #include <cpExtensions/QT/ImageWidget.h>
+#include <cpExtensions/Visualization/WindowLevelImageActor.h>
 #include <cpPlugins/Interface/Workspace.h>
 
 #include <QApplication>
 #include <QHBoxLayout>
 
 #include <vtkImageData.h>
+#include <vtkPolyData.h>
 
-
-#include <vtkImageTracerWidget.h>
-#include <vtkSmartPointer.h>
-#include <vtkGlyphSource2D.h>
-#include <vtkProp.h>
-
+/* TODO
+   #include <vtkImageTracerWidget.h>
+   #include <vtkSplineWidget.h>
+   #include <vtkSmartPointer.h>
+   #include <vtkGlyphSource2D.h>
+   #include <vtkProp.h>
+*/
 
 #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
index 3b9c9ddf78ab6269c575c22daa4ef7eaf7e28947..c7afea2d63d78b1150189066169fc1e3110ac44c 100644 (file)
@@ -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
 
index 079903646511135f62ae4c5e661ae3a14bf5d92b..a4770c08a0288ae8bce8d8735d8f898bbfe7a513 100644 (file)
@@ -1,3 +1,4 @@
+#include <cpExtensions/Utility.h>
 #include <cpExtensions/Interaction/ImageSliceStyle.h>
 #include <cpExtensions/Visualization/CursorActors.h>
 #include <cpExtensions/Visualization/WindowLevelImageActor.h>
@@ -8,6 +9,10 @@
 #include <vtkPropCollection.h>
 #include <vtkPropPicker.h>
 #include <vtkRenderer.h>
+#include <vtkTextActor.h>
+#include <vtkTextProperty.h>
+#include <sstream>
+
 /* TODO
    #include <cpExtensions/Visualization/ImageViewerActors.h>
 */
@@ -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$
index 0fe25813f5056a6632fe917b8cc9c4a1bdf5e3d7..9fa34499430c1672c0ab5fde7e904f274b14c829 100644 (file)
@@ -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
index af448c1bd53e987f295c67b3d2dd33e72301d8db..60ca9a0ed1760f00dc7cb7f371d38e89dfe2d0a4 100644 (file)
@@ -3,15 +3,18 @@
 #ifdef cpExtensions_QT4
 
 #include <cpExtensions/Interaction/ImageSliceStyle.h>
-#include <cpExtensions/Visualization/ImageOutlineActor.h>
+#include <cpExtensions/Visualization/MeshActor.h>
+#include <cpExtensions/Visualization/OutlineSource.h>
 #include <cpExtensions/Visualization/WindowLevelImageActor.h>
 
+#include <vtkCamera.h>
+#include <vtkImageData.h>
+#include <vtkProperty.h>
 #include <vtkRenderer.h>
 
 /* TODO
    #include <cpExtensions/Visualization/ImageViewerActors.h>
    #include <cpExtensions/Visualization/LUTImageActor.h>
-   #include <vtkCamera.h>
    #include <vtkImageData.h>
    #include <vtkImageProperty.h>
 */
@@ -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
index eeb65d08f8a1a75f7bb18d1a6d10e4631aff3bc0..c27855768d3ca8af6c8b339e5380909ae26559ae 100644 (file)
@@ -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;
 
index f0331c0d287ae404d232d61ed1753dafc2bd30f9..788fb22a44b86ce9015d2ee3426c466ad8a71f20 100644 (file)
@@ -3,13 +3,18 @@
 #ifdef cpExtensions_QT4
 
 #include <cpExtensions/Visualization/ImageOutlineActor.h>
-#include <cpExtensions/Visualization/MPR3DActors.h>
-#include <cpExtensions/Visualization/LUTImageActor.h>
 #include <cpExtensions/Visualization/WindowLevelImageActor.h>
 
-#include <vtkActor.h>
 #include <vtkImageData.h>
-#include <vtkPolyData.h>
+#include <vtkPlane.h>
+
+/* TODO
+   #include <cpExtensions/Visualization/MPR3DActors.h>
+   #include <cpExtensions/Visualization/LUTImageActor.h>
+
+   #include <vtkActor.h>
+   #include <vtkPolyData.h>
+*/
 
 // -------------------------------------------------------------------------
 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
 
index b9f3ef670f8ea9d1befd21bca0a0ae68e03a8686..6dcd86493ee3865f86df6a50f0b6705900b2ed75 100644 (file)
@@ -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
index b65266fbf5280f794c398ce53c5d3bb738ab4273..e19eadbd733060795f2d9db710b65181e62524ef 100644 (file)
@@ -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
-  */
 }
       
 // -------------------------------------------------------------------------
index c2382eda40c08f1c0905e4dd1772218e242fe5cb..95af5ab535561df63f344f260f3bb4e2dec80da6 100644 (file)
@@ -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( ) )
     );
-*/
 }
 
 // -------------------------------------------------------------------------
index 9c19f3638366dace79e4ecfd4dc0327cb749eadc..9ce91cf89f34eba53c05c48a70b48af182e4ecd8 100644 (file)
@@ -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 (file)
index 0000000..a00a221
--- /dev/null
@@ -0,0 +1,50 @@
+#include <cpExtensions/Visualization/OutlineSource.h>
+#include <vtkCellArray.h>
+#include <vtkInformation.h>
+#include <vtkInformationVector.h>
+#include <vtkSmartPointer.h>
+
+// -------------------------------------------------------------------------
+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 (file)
index 0000000..295a5b5
--- /dev/null
@@ -0,0 +1,48 @@
+#ifndef __cpExtensions__Visualization__OutlineSource__h__
+#define __cpExtensions__Visualization__OutlineSource__h__
+
+#include <cpExtensions/Config.h>
+#include <vtkOutlineSource.h>
+
+// -------------------------------------------------------------------------
+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 (file)
index 0000000..c6e7116
--- /dev/null
@@ -0,0 +1,313 @@
+#include <plugins/Widgets/SplineWidget.h>
+#include <cpPlugins/DataObjects/Image.h>
+#include <cpPlugins/DataObjects/Mesh.h>
+#include <cpExtensions/Visualization/WindowLevelImageActor.h>
+
+#include <vtkRenderer.h>
+#include <vtkSplineWidget.h>
+
+// -------------------------------------------------------------------------
+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 (file)
index 0000000..83b57b2
--- /dev/null
@@ -0,0 +1,78 @@
+#ifndef __cpPluginsWidgets__SplineWidget__h__
+#define __cpPluginsWidgets__SplineWidget__h__
+
+#include <plugins/cpPluginsWidgets_Export.h>
+#include <cpPlugins/BaseObjects/Widget.h>
+
+#include <vtkSmartPointer.h>
+
+/* TODO
+   #include <cpExtensions/Interaction/SplineWidget.h>
+   #include <cpExtensions/Interaction/ImageSlicePointPlacer.h>
+   #include <cpExtensions/Visualization/WindowLevelImageActor.h>
+   #include <vtkImageSlice.h>
+   #include <vtkPointHandleRepresentation3D.h>
+   #include <vtkSeedRepresentation.h>
+   #include <map>
+*/
+
+// -------------------------------------------------------------------------
+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$