]> Creatis software - cpPlugins.git/commitdiff
...
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Thu, 29 Oct 2015 23:47:23 +0000 (18:47 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Thu, 29 Oct 2015 23:47:23 +0000 (18:47 -0500)
appli/examples/example_View2DImage.cxx
lib/cpExtensions/Interaction/ImageInteractorStyle.cxx
lib/cpExtensions/Interaction/ImageInteractorStyle.h
lib/cpExtensions/Interaction/SeedWidget.cxx
lib/cpExtensions/Visualization/ImageSliceActors.cxx

index 4e7733b0ac3ebb4b58cfa0c4fb67dea3e03da9d4..cc8a3e6e1eb61869ef1ab76e7177a292f3fd92f9 100644 (file)
@@ -93,6 +93,12 @@ int main( int argc, char* argv[] )
   image_actors->AddInputData( image->GetVTK< vtkImageData >( ), 2 );
   image_actors->PushActorsInto( window );
 
+  // Activate seed widget
+  TSliceActors::TStyle* style =
+    dynamic_cast< TSliceActors::TStyle* >( image_actors->GetStyle( ) );
+  if( style != NULL )
+    style->SeedWidgetOn( );
+
   // Begin interaction
   renderer->ResetCamera( );
   window->Render( );
index d0a313760b8bac6e1c8096b8eed35f85a8b78dda..bf82ba68140b1bb38ef89a2d1193b6240f4c62af 100644 (file)
@@ -1,8 +1,41 @@
 #include <cpExtensions/Interaction/ImageInteractorStyle.h>
 
 #include <vtkImageActor.h>
+#include <vtkPropCollection.h>
+#include <vtkProperty.h>
 #include <vtkRenderWindowInteractor.h>
 
+// -------------------------------------------------------------------------
+cpExtensions::Interaction::ImageInteractorStyle::TSeedWidget::
+TSeedWidget( vtkRenderWindowInteractor* interactor, vtkImageActor* actor )
+{
+  this->Placer = vtkSmartPointer< vtkImageActorPointPlacer >::New( );
+  this->Handle = vtkSmartPointer< vtkPointHandleRepresentation3D >::New( );
+  this->Representation = vtkSmartPointer< vtkSeedRepresentation >::New( );
+  this->Widget = vtkSmartPointer< SeedWidget >::New( );
+
+  this->Placer->SetImageActor( actor );
+  this->Handle->GetProperty( )->SetColor( 1, 0, 0 );
+  this->Handle->SetPointPlacer( this->Placer );
+  this->Representation->SetHandleRepresentation( this->Handle );
+  this->Widget->SetRepresentation( this->Representation );
+  this->Widget->SetInteractor( interactor );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Interaction::ImageInteractorStyle::TSeedWidget::
+On( )
+{
+  this->Widget->On( );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Interaction::ImageInteractorStyle::TSeedWidget::
+Off( )
+{
+  this->Widget->Off( );
+}
+
 // -------------------------------------------------------------------------
 cpExtensions::Interaction::ImageInteractorStyle::
 Self* cpExtensions::Interaction::ImageInteractorStyle::
@@ -23,10 +56,40 @@ AssociateImageActor( vtkImageActor* actor )
   } // fi
 }
 
+// -------------------------------------------------------------------------
+void cpExtensions::Interaction::ImageInteractorStyle::
+SeedWidgetOn( )
+{
+  if( this->m_SeedWidget != NULL ) delete this->m_SeedWidget;
+
+  this->m_PropPicker->GetPickList( )->InitTraversal( );
+  this->m_SeedWidget = new TSeedWidget(
+    this->Interactor,
+    dynamic_cast< vtkImageActor* >(
+      this->m_PropPicker->GetPickList( )->GetNextProp( )
+      )
+    );
+  this->m_SeedWidget->On( );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Interaction::ImageInteractorStyle::
+SeedWidgetOff( )
+{
+  if( this->m_SeedWidget != NULL )
+  {
+    this->m_SeedWidget->Off( );
+    delete this->m_SeedWidget;
+    this->m_SeedWidget = NULL;
+
+  } // fi
+}
+
 // -------------------------------------------------------------------------
 cpExtensions::Interaction::ImageInteractorStyle::
 ImageInteractorStyle( )
-  : Superclass( )
+  : Superclass( ),
+    m_SeedWidget( NULL )
 {
   this->m_PropPicker = vtkSmartPointer< vtkPropPicker >::New( );
   this->m_PropPicker->PickFromListOn( );
@@ -36,6 +99,7 @@ ImageInteractorStyle( )
 cpExtensions::Interaction::ImageInteractorStyle::
 ~ImageInteractorStyle( )
 {
+  if( this->m_SeedWidget != NULL ) delete this->m_SeedWidget;
 }
 
 // -------------------------------------------------------------------------
index 99c0c1f9ff96610b778b94801cd876597aab4118..b63ca90fe65018750a060b412cabf4d8ba9e3476 100644 (file)
@@ -44,36 +44,16 @@ namespace cpExtensions
       // Widgets
       struct TSeedWidget
       {
-        vtkSmartPointer< vtkImageActorPointPlacer >       Placer;
-        vtkSmartPointer< vtkPointHandleRepresentation3D > Handle;
-        vtkSmartPointer< vtkSeedRepresentation >  Representation;
-        vtkSmartPointer< TSeedWidget >                    Widget;
-
-        TSeedWidget( vtkRenderWindowInteractor* interactor, vtkImageActor* actor )
-          {
-            this->Placer = vtkSmartPointer< vtkImageActorPointPlacer >::New( );
-            this->Handle = vtkSmartPointer< vtkPointHandleRepresentation3D >::New( );
-            this->Representation = vtkSmartPointer< vtkSeedRepresentation >::New( );
-            this->Widget = vtkSmartPointer< TSeedWidget >::New( );
-
-            this->Placer->SetImageActor( actor );
-            this->Handle->GetProperty( )->SetColor( 1, 0, 0 );
-            this->Handle->SetPointPlacer( this->Placer );
-            this->Representation->SetHandleRepresentation( this->Handle );
-            this->Widget->SetRepresentation( this->Representation );
-            this->Widget->SetInteractor( interactor );
-          }
-
-        void On( )
-          {
-            this->Widget->On( );
-          }
-
-        void Off( )
-          {
-            this->Widget->Off( );
-          }
-#error ACA VOY
+        vtkSmartPointer< vtkImageActorPointPlacer >              Placer;
+        vtkSmartPointer< vtkPointHandleRepresentation3D >        Handle;
+        vtkSmartPointer< vtkSeedRepresentation >         Representation;
+        vtkSmartPointer< SeedWidget > Widget;
+
+        TSeedWidget(
+          vtkRenderWindowInteractor* interactor, vtkImageActor* actor
+          );
+        void On( );
+        void Off( );
       };
 
     public:
@@ -82,6 +62,10 @@ namespace cpExtensions
       // Data for local picker
       virtual void AssociateImageActor( vtkImageActor* actor );
 
+      // Widgets
+      void SeedWidgetOn( );
+      void SeedWidgetOff( );
+
     protected:
       ImageInteractorStyle( );
       virtual ~ImageInteractorStyle( );
@@ -95,6 +79,8 @@ namespace cpExtensions
 
     protected:
       vtkSmartPointer< vtkPropPicker > m_PropPicker;
+
+      TSeedWidget* m_SeedWidget;
     };
 
   } // ecapseman
index 3460532ba22cbcec8231cdc626de53d370fd18e3..73d13a5b1853320d213bd374f276933946856994 100644 (file)
@@ -20,11 +20,16 @@ void cpExtensions::Interaction::SeedWidget::
 SetInteractor( vtkRenderWindowInteractor* rwi )
 {
   this->Superclass::SetInteractor( rwi );
-  TBaseStyle* s = dynamic_cast< TBaseStyle*>( rwi->GetInteractorStyle( ) );
-  if( s != NULL )
+  if( rwi != NULL )
   {
-    s->AddMouseClickCommand( Self::_Click, this );
-    s->AddMouseDoubleClickCommand( Self::_DoubleClick, this );
+    TBaseStyle* s =
+      dynamic_cast< TBaseStyle* >( rwi->GetInteractorStyle( ) );
+    if( s != NULL )
+    {
+      s->AddMouseClickCommand( Self::_Click, this );
+      s->AddMouseDoubleClickCommand( Self::_DoubleClick, this );
+
+    } // fi
 
   } // fi
 }
@@ -55,6 +60,8 @@ _Click(
   )
 {
   SeedWidget* self = reinterpret_cast< SeedWidget* >( data );
+  if( self == NULL )
+    return;
   if( self->WidgetState == vtkSeedWidget::MovingSeed )
     return;
 
index 450bdb688e129b33390c3ce64fd7069d55fd97fe..0418c3714363d45124a33b0e6f202ac17636bea4 100644 (file)
@@ -318,7 +318,7 @@ PushActorsInto( vtkRenderWindow* window, bool force_style )
     } // fi
 
   } // fi
-  renderer->ResetCamera( );
+  this->ResetCamera( );
   rwi->Render( );
 }
 
@@ -839,13 +839,23 @@ SetSliceNumber( const int& slice )
     return;
 
   // Change visualization extent
+  int axis = this->GetAxis( );
   for( unsigned int i = 0; i < nImages; ++i )
   {
+    // Update mappers and display bounds
     this->m_SliceMappers[ i ]->SetSliceNumber( slice );
     this->m_SliceMappers[ i ]->Modified( );
     this->m_ImageActors[ i ]->Modified( );
     this->m_SliceMappers[ i ]->Update( );
 
+    // Update display extent (this isn't done automatically)
+    vtkImageData* image = this->m_SliceMappers[ i ]->GetInput( );
+    int ext[ 6 ];
+    image->GetExtent( ext );
+    ext[ axis << 1 ] = slice;
+    ext[ ( axis << 1 ) + 1 ] = slice;
+    this->m_ImageActors[ i ]->SetDisplayExtent( ext );
+
   } // rof
 
   double bnds[ 6 ];
@@ -861,7 +871,6 @@ SetSliceNumber( const int& slice )
   plane->GeneralizedProjectPoint( x0[ 0 ], p0[ 0 ] );
   plane->GeneralizedProjectPoint( x0[ 1 ], p0[ 1 ] );
 
-  int axis = this->GetAxis( );
   bnds[ 0 ] = p0[ 0 ][ 0 ];
   bnds[ 1 ] = p0[ 1 ][ 0 ];
   bnds[ 2 ] = p0[ 0 ][ 1 ];
@@ -1051,6 +1060,7 @@ ResetCamera( )
     this->m_Window->GetRenderers( )->GetFirstRenderer( );
   if( renderer != NULL )
     renderer->ResetCamera( );
+#error ACA VOY: reconfigurar la camara alrededor únicamente del plano.
 }
 
 // -------------------------------------------------------------------------