]> Creatis software - cpMesh.git/blobdiff - appli/InteractiveDeformableMeshSegmentation/InteractorStyleImage.cxx
New plugin added
[cpMesh.git] / appli / InteractiveDeformableMeshSegmentation / InteractorStyleImage.cxx
diff --git a/appli/InteractiveDeformableMeshSegmentation/InteractorStyleImage.cxx b/appli/InteractiveDeformableMeshSegmentation/InteractorStyleImage.cxx
deleted file mode 100644 (file)
index f192117..0000000
+++ /dev/null
@@ -1,493 +0,0 @@
-#include "InteractorStyleImage.h"
-#include "VolumeActors.h"
-
-#include <cmath>
-
-#include <vtkAbstractPropPicker.h>
-#include <vtkAnnotatedCubeActor.h>
-#include <vtkAxesActor.h>
-#include <vtkCamera.h>
-#include <vtkCommand.h>
-#include <vtkImageData.h>
-#include <vtkPropAssembly.h>
-#include <vtkProperty.h>
-#include <vtkRendererCollection.h>
-#include <vtkRenderWindow.h>
-#include <vtkRenderWindowInteractor.h>
-
-// -------------------------------------------------------------------------
-int idms::InteractorStyleImage::SliceEvent = vtkCommand::UserEvent + 1;
-
-// -------------------------------------------------------------------------
-idms::InteractorStyleImage::
-Self* idms::InteractorStyleImage::
-New( )
-{
-  return( new Self( ) );
-}
-
-// -------------------------------------------------------------------------
-void idms::InteractorStyleImage::
-Configure( VolumeActors* actors, const int& axis )
-{
-  this->Actors = actors;
-  this->Axis = axis;
-  this->SetModeToNavigation( );
-
-  if( axis == 0 )
-    this->PropPicker->AddPickList( actors->GetXPlaneActor( ) );
-  else if( axis == 1 )
-    this->PropPicker->AddPickList( actors->GetYPlaneActor( ) );
-  else // if( axis == 2 )
-    this->PropPicker->AddPickList( actors->GetZPlaneActor( ) );
-
-  this->Modified( );
-}
-
-// -------------------------------------------------------------------------
-void idms::InteractorStyleImage::
-SetModeToNavigation( )
-{
-  this->Mode = Self::NavigationMode;
-}
-
-// -------------------------------------------------------------------------
-void idms::InteractorStyleImage::
-SetModeToDeformation( )
-{
-  this->Mode = Self::DeformationMode;
-}
-
-// -------------------------------------------------------------------------
-void idms::InteractorStyleImage::
-SetInteractor( vtkRenderWindowInteractor* rwi )
-{
-  this->Superclass::SetInteractor( rwi );
-  this->OrientationWidget->SetInteractor( rwi );
-  this->LineWdg->SetInteractor( rwi );
-  if( rwi == NULL )
-    return;
-
-  rwi->SetPicker( this->PropPicker );
-
-  // Enable 2D orientation widget
-  this->OrientationWidget->SetEnabled( 1 );
-  this->OrientationWidget->InteractiveOff( );
-
-  // Disable line widget
-  this->LineWdg->SetEnabled( 0 );
-
-  // Get camera, avoiding segfaults
-  vtkRenderer* ren =
-    rwi->GetRenderWindow( )->GetRenderers( )->GetFirstRenderer( );
-  if( ren == NULL )
-    return;
-  vtkCamera* cam = ren->GetActiveCamera( );
-  if( cam == NULL )
-    return;
-
-  // Parallel projections are better when displaying 2D images
-  cam->ParallelProjectionOn( );
-  cam->SetFocalPoint( double( 0 ), double( 0 ), double( 0 ) );
-  this->Plane->SetOrigin( double( 0 ), double( 0 ), double( 0 ) );
-  if( this->Axis == 0 )
-  {
-    cam->SetPosition( double( 1 ), double( 0 ), double( 0 ) );
-    cam->SetViewUp  ( double( 0 ), double( 1 ), double( 0 ) );
-    this->Plane->SetNormal( double( 1 ), double( 0 ), double( 0 ) );
-  }
-  else if( this->Axis == 1 )
-  {
-    cam->SetPosition( double( 0 ), double( 1 ), double(  0 ) );
-    cam->SetViewUp  ( double( 0 ), double( 0 ), double( -1 ) );
-    this->Plane->SetNormal( double( 0 ), double( 1 ), double( 0 ) );
-  }
-  else // if( this->Axis == 2 )
-  {
-    cam->SetPosition( double( 0 ), double( 0 ), double( 1 ) );
-    cam->SetViewUp  ( double( 0 ), double( 1 ), double( 0 ) );
-    this->Plane->SetNormal( double( 0 ), double( 0 ), double( 1 ) );
-
-  } // fi
-}
-
-// -------------------------------------------------------------------------
-void idms::InteractorStyleImage::
-OnMouseMove( )
-{
-  if( this->Mode == Self::DeformationMode )
-    this->_UpdateCursor( );
-
-  // Propagate event
-  this->Superclass::OnMouseMove( );
-}
-
-// -------------------------------------------------------------------------
-void idms::InteractorStyleImage::
-OnLeftButtonDown( )
-{
-  if( this->Mode == Self::DeformationMode )
-  {
-    vtkRenderWindowInteractor* rwi = this->GetInteractor( );
-    if( this->Actors != NULL && rwi != NULL )
-    {
-      if( rwi->GetShiftKey( ) == 1 )
-      {
-        this->Actors->GetRegionActor( )->GetProperty( )->SetOpacity( 0.3 );
-        this->UpdatingRegion = true;
-      }
-      else
-        this->Superclass::OnLeftButtonDown( );
-    }
-    else
-      this->Superclass::OnLeftButtonDown( );
-  }
-  else if( this->Mode == Self::NavigationMode )
-    this->Superclass::OnLeftButtonDown( );
-}
-
-// -------------------------------------------------------------------------
-void idms::InteractorStyleImage::
-OnLeftButtonUp( )
-{
-  if( this->Mode == Self::DeformationMode )
-  {
-    vtkRenderWindowInteractor* rwi = this->GetInteractor( );
-    if( this->Actors != NULL && rwi != NULL )
-    {
-      if( rwi->GetShiftKey( ) == 1 )
-      {
-        this->Actors->GetRegionActor( )->GetProperty( )->SetOpacity( 0 );
-        this->UpdatingRegion = false;
-      }
-      else
-        this->Superclass::OnLeftButtonUp( );
-    }
-    else
-      this->Superclass::OnLeftButtonUp( );
-  }
-  else if( this->Mode == Self::NavigationMode )
-    this->Superclass::OnLeftButtonUp( );
-}
-
-// -------------------------------------------------------------------------
-void idms::InteractorStyleImage::
-OnMouseWheelForward( )
-{
-  vtkRenderWindowInteractor* rwi = this->GetInteractor( );
-  if( this->Actors == NULL || rwi == NULL )
-    return;
-  int off = 1;
-  if( rwi->GetShiftKey( ) == 1 )
-    off *= 10;
-  int s = this->Actors->GetSlice( this->Axis ) + off;
-  int maxs = this->Actors->GetSliceNumberMaxValue( this->Axis );
-  this->Actors->SetSlice( this->Axis, ( s < maxs )? s: maxs );
-  this->Actors->Render( );
-
-  if( this->Mode == Self::DeformationMode )
-    this->_UpdateCursor( );
-
-  this->InvokeEvent( Self::SliceEvent, &( this->Axis ) );
-}
-
-// -------------------------------------------------------------------------
-void idms::InteractorStyleImage::
-OnMouseWheelBackward( )
-{
-  vtkRenderWindowInteractor* rwi = this->GetInteractor( );
-  if( this->Actors == NULL || rwi == NULL )
-    return;
-  int off = 1;
-  if( rwi->GetShiftKey( ) == 1 )
-    off *= 10;
-  int s = this->Actors->GetSlice( this->Axis ) - off;
-  int mins = this->Actors->GetSliceNumberMinValue( this->Axis );
-  this->Actors->SetSlice( this->Axis, ( s < mins )? mins: s );
-  this->Actors->Render( );
-
-  if( this->Mode == Self::DeformationMode )
-    this->_UpdateCursor( );
-
-  this->InvokeEvent( Self::SliceEvent, &( this->Axis ) );
-}
-
-// -------------------------------------------------------------------------
-void idms::InteractorStyleImage::
-OnChar( )
-{
-  vtkRenderWindowInteractor* rwi = this->GetInteractor( );
-  if( rwi == NULL )
-    return;
-
-  switch( rwi->GetKeyCode( ) )
-  {
-  case 'r': case 'R':
-  {
-    vtkRenderer* ren =
-      rwi->GetRenderWindow( )->GetRenderers( )->GetFirstRenderer( );
-    if( ren != NULL )
-    {
-      double bounds[ 6 ];
-      this->Actors->GetImageBounds( bounds );
-      ren->ResetCamera( bounds );
-      rwi->Render( );
-      
-    } // fi
-  }
-  break;
-  case 'l': case 'L':
-  {
-    this->Actors->ResetWindowLevel( );
-    this->Actors->Render( );
-  }
-  break;
-  case 's': case 'S':
-  {
-    int idx[ 3 ];
-    idx[ 0 ] = this->Actors->GetSlice( 0 );
-    idx[ 1 ] = this->Actors->GetSlice( 1 );
-    idx[ 2 ] = this->Actors->GetSlice( 2 );
-    this->Actors->AddSeed( idx );
-  }
-  break;
-  default:
-    break;
-  } // hctiws
-}
-
-// -------------------------------------------------------------------------
-void idms::InteractorStyleImage::
-Pan( )
-{
-  if( this->Mode == Self::DeformationMode )
-  {
-    this->Actors->Render( ); 
-  }
-  else if( this->Mode == Self::NavigationMode )
-    this->Superclass::Pan( );
-}
-
-// -------------------------------------------------------------------------
-void idms::InteractorStyleImage::
-Spin( )
-{
-  if( this->Mode == Self::NavigationMode )
-  {
-    double pos[ 3 ];
-    if( this->_PickPosition( pos ) )
-    {
-      if( this->Axis != 0 ) this->Actors->SetSlice( 0, pos[ 0 ] );
-      if( this->Axis != 1 ) this->Actors->SetSlice( 1, pos[ 1 ] );
-      if( this->Axis != 2 ) this->Actors->SetSlice( 2, pos[ 2 ] );
-      this->Actors->Render( );
-
-    } // fi
-  }
-  else if( this->Mode == Self::DeformationMode )
-  {
-    // TODO
-
-  } // fi
-}
-
-// -------------------------------------------------------------------------
-void idms::InteractorStyleImage::
-StartWindowLevel( )
-{
-  if( this->Mode == Self::NavigationMode )
-  {
-    if( this->State != VTKIS_NONE )
-      return;
-    this->StartState( VTKIS_WINDOW_LEVEL );
-
-    this->WindowLevelInitial[ 0 ] = this->Actors->GetWindow( );
-    this->WindowLevelInitial[ 1 ] = this->Actors->GetLevel( );
-  }
-  else if( this->Mode == Self::DeformationMode )
-  {
-    // TODO
-
-  } // fi
-}
-
-// -------------------------------------------------------------------------
-void idms::InteractorStyleImage::
-WindowLevel( )
-{
-  if( this->Mode == Self::NavigationMode )
-  {
-    vtkRenderWindowInteractor* rwi = this->GetInteractor( );
-    if( rwi == NULL )
-      return;
-    vtkRenderer* ren =
-      rwi->GetRenderWindow( )->GetRenderers( )->GetFirstRenderer( );
-    if( ren == NULL )
-      return;
-
-    // Compute scales
-    this->WindowLevelCurrentPosition[ 0 ] = rwi->GetEventPosition( )[ 0 ];
-    this->WindowLevelCurrentPosition[ 1 ] = rwi->GetEventPosition( )[ 1 ];
-    int* size = ren->GetSize( );
-    double sw = double(
-      this->WindowLevelCurrentPosition[ 0 ] -
-      this->WindowLevelStartPosition[ 0 ]
-      ) / double( size[ 0 ] );
-    double sl = (
-      this->WindowLevelStartPosition[ 1 ] -
-      this->WindowLevelCurrentPosition[ 1 ]
-      ) / double( size[ 1 ] );
-
-    double w = this->WindowLevelInitial[ 0 ] * ( double( 1 ) + sw );
-    double l = this->WindowLevelInitial[ 1 ] * ( double( 1 ) + sl );
-    double minw = this->Actors->GetMinWindow( );
-    double maxw = this->Actors->GetMaxWindow( );
-    double minl = this->Actors->GetMinLevel( );
-    double maxl = this->Actors->GetMaxLevel( );
-
-    if( w < minw ) w = minw;
-    if( maxw < w ) w = maxw;
-    if( l < minl ) l = minl;
-    if( maxl < l ) l = maxl;
-
-    this->Actors->SetWindowLevel( w, l );
-    this->Actors->Render( );
-  }
-  else if( this->Mode == Self::DeformationMode )
-  {
-    // TODO
-
-  } // fi
-}
-
-// -------------------------------------------------------------------------
-idms::InteractorStyleImage::
-InteractorStyleImage( )
-  : Superclass( ),
-    Mode( Self::NavigationMode ),
-    Actors( NULL ),
-    Axis( 2 )
-{
-  // Orientation marks
-  vtkSmartPointer< vtkAnnotatedCubeActor > cube =
-    vtkSmartPointer< vtkAnnotatedCubeActor >::New( );
-  cube->GetCubeProperty( )->SetColor( 0.9, 0.7, 0.2 );
-  cube->GetTextEdgesProperty( )->SetLineWidth( 1 );
-  cube->GetTextEdgesProperty( )->SetDiffuse( 0 );
-  cube->GetTextEdgesProperty( )->SetAmbient( 1 );
-  cube->GetTextEdgesProperty( )->SetColor( 0.18, 0.28, 0.23 );
-  cube->GetXPlusFaceProperty( )->SetColor( 1, 0, 0 );
-  cube->GetXPlusFaceProperty( )->SetInterpolationToFlat( );
-  cube->GetXMinusFaceProperty( )->SetColor( 1, 0, 0 );
-  cube->GetXMinusFaceProperty( )->SetInterpolationToFlat( );
-  cube->GetYPlusFaceProperty( )->SetColor( 0, 1, 0 );
-  cube->GetYPlusFaceProperty( )->SetInterpolationToFlat( );
-  cube->GetYMinusFaceProperty( )->SetColor( 0, 1, 0 );
-  cube->GetYMinusFaceProperty( )->SetInterpolationToFlat( );
-  cube->GetZPlusFaceProperty( )->SetColor( 0, 0, 1 );
-  cube->GetZPlusFaceProperty( )->SetInterpolationToFlat( );
-  cube->GetZMinusFaceProperty( )->SetColor( 0, 0, 1 );
-  cube->GetZMinusFaceProperty( )->SetInterpolationToFlat( );
-
-  vtkSmartPointer< vtkAxesActor > axes =
-    vtkSmartPointer< vtkAxesActor >::New( );
-  axes->AxisLabelsOff( );
-  axes->SetShaftTypeToCylinder( );
-  axes->SetTotalLength( 2, 2, 2 );
-
-  vtkSmartPointer< vtkPropAssembly > actors =
-    vtkSmartPointer< vtkPropAssembly >::New( );
-  actors->AddPart( cube );
-  actors->AddPart( axes );
-
-  this->OrientationWidget =
-    vtkSmartPointer< vtkOrientationMarkerWidget >::New( );
-  this->OrientationWidget->SetOutlineColor( 0.93, 0.57, 0.13 );
-  this->OrientationWidget->SetOrientationMarker( actors );
-  this->OrientationWidget->SetViewport( 0.0, 0.0, 0.2, 0.2 );
-
-  this->Plane = vtkSmartPointer< vtkPlane >::New( );
-
-  this->PropPicker = vtkSmartPointer< vtkPropPicker >::New( );
-  this->PropPicker->PickFromListOn( );
-
-  this->LineRep = vtkSmartPointer< vtkLineRepresentation >::New( );
-  this->LineWdg = vtkSmartPointer< vtkLineWidget2 >::New( );
-
-  this->LineWdg->SetRepresentation( this->LineRep );
-}
-
-// -------------------------------------------------------------------------
-idms::InteractorStyleImage::
-~InteractorStyleImage( )
-{
-}
-
-// -------------------------------------------------------------------------
-bool idms::InteractorStyleImage::
-_PickPosition( double pos[ 3 ] )
-{
-  vtkRenderWindowInteractor* rwi = this->GetInteractor( );
-  if( this->Actors == NULL || rwi == NULL )
-    return( false );
-  this->FindPokedRenderer(
-    rwi->GetEventPosition( )[ 0 ],
-    rwi->GetEventPosition( )[ 1 ]
-    );
-  int success = rwi->GetPicker( )->Pick(
-    rwi->GetEventPosition( )[ 0 ],
-    rwi->GetEventPosition( )[ 1 ],
-    0.0,
-    this->CurrentRenderer
-    );
-  if( success == 0 )
-    return( false );
-
-  /*
-    vtkAbstractPropPicker* picker =
-    vtkAbstractPropPicker::SafeDownCast( rwi->GetPicker( ) );
-    if( picker != NULL )
-    {
-  */
-  this->PropPicker->GetPickPosition( pos );
-  return( true );
-  /*
-    }
-    else
-    return( false );
-  */
-}
-
-// -------------------------------------------------------------------------
-void idms::InteractorStyleImage::
-_UpdateCursor( )
-{
-  double p[ 3 ];
-  if( this->_PickPosition( p ) )
-  {
-    this->Actors->SetCursorPosition( p );
-    if( this->UpdatingRegion )
-      this->Actors->SetRegionRadius( p );
-    else
-      this->Actors->SetRegionPosition( p );
-    this->Actors->RenderAuxiliaryInteractors( );
-
-    /* TODO
-       double c[ 3 ];
-       int i[ 3 ];
-       vtkImageData* img = this->Actors->GetImage( );
-       bool inside = ( img->ComputeStructuredCoordinates( p, i, c ) != 0 );
-       if( inside )
-       {
-       std::cout
-       << i[ 0 ] << " "
-       << i[ 1 ] << " "
-       << i[ 2 ]
-       << std::endl;
-
-       } // fi
-    */
-  } // fi
-}
-
-// eof - $RCSfile$