Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions

mitk::AffineInteractor3D Class Reference
[Interaction Classes]

Affine interaction with objects in 3D windows. More...

#include <mitkAffineInteractor3D.h>

Inheritance diagram for mitk::AffineInteractor3D:
Inheritance graph
[legend]
Collaboration diagram for mitk::AffineInteractor3D:
Collaboration graph
[legend]

List of all members.

Public Types

enum  { INTERACTION_MODE_TRANSLATION, INTERACTION_MODE_ROTATION }
typedef AffineInteractor3D Self
typedef Interactor Superclass
typedef itk::SmartPointer< SelfPointer
typedef itk::SmartPointer
< const Self
ConstPointer

Public Member Functions

virtual const char * GetClassName () const
void SetInteractionMode (unsigned int interactionMode)
void SetInteractionModeToTranslation ()
void SetInteractionModeToRotation ()
unsigned int GetInteractionMode () const
void SetPrecision (ScalarType precision)
 Sets the amount of precision.
virtual float CanHandleEvent (StateEvent const *stateEvent) const
 calculates how good the data, this statemachine handles, is hit by the event.

Static Public Member Functions

static Pointer New (const char *_arga, DataNode *_argb, int _argc)
static Pointer New (const char *_arga, DataNode *_argb)
 NewMacro with two parameters for calling itk::Lightobject::New(..) method.

Protected Member Functions

 AffineInteractor3D (const char *type, DataNode *dataNode, int n=-1)
 Constructor with Param n for limited Set of Points.
virtual ~AffineInteractor3D ()
 Default Destructor.
virtual bool ExecuteAction (Action *action, mitk::StateEvent const *stateEvent)
 Method called in HandleEvent after Statechange.
bool ColorizeSurface (vtkPolyData *polyData, const Point3D &pickedPoint, double scalar=0.0)

Detailed Description

Affine interaction with objects in 3D windows.

NOTE: The interaction mechanism is similar to that of vtkPlaneWidget

Definition at line 42 of file mitkAffineInteractor3D.h.


Member Typedef Documentation

typedef itk::SmartPointer<const Self> mitk::AffineInteractor3D::ConstPointer

Reimplemented from mitk::Interactor.

Definition at line 47 of file mitkAffineInteractor3D.h.

typedef itk::SmartPointer<Self> mitk::AffineInteractor3D::Pointer

Reimplemented from mitk::Interactor.

Definition at line 47 of file mitkAffineInteractor3D.h.

Reimplemented from mitk::Interactor.

Definition at line 47 of file mitkAffineInteractor3D.h.

Reimplemented from mitk::Interactor.

Definition at line 47 of file mitkAffineInteractor3D.h.


Member Enumeration Documentation

anonymous enum
Enumerator:
INTERACTION_MODE_TRANSLATION 
INTERACTION_MODE_ROTATION 

Definition at line 45 of file mitkAffineInteractor3D.h.


Constructor & Destructor Documentation

mitk::AffineInteractor3D::AffineInteractor3D ( const char *  type,
DataNode dataNode,
int  n = -1 
) [protected]

Constructor with Param n for limited Set of Points.

if no n is set, then the number of points is unlimited*

Definition at line 25 of file mitkAffineInteractor3D.cpp.

{
mitk::AffineInteractor3D::~AffineInteractor3D (  ) [protected, virtual]

Default Destructor.

Definition at line 39 of file mitkAffineInteractor3D.cpp.

{

Member Function Documentation

float mitk::AffineInteractor3D::CanHandleEvent ( StateEvent const *  stateEvent ) const [virtual]

calculates how good the data, this statemachine handles, is hit by the event.

overwritten, cause we don't look at the boundingbox, we look at each point

Reimplemented from mitk::Interactor.

Definition at line 75 of file mitkAffineInteractor3D.cpp.

References INTERACTION_MODE_TRANSLATION.

{
  m_InteractionMode = INTERACTION_MODE_TRANSLATION;
}


void AffineInteractor3D::SetInteractionModeToRotation()
{
  m_InteractionMode = INTERACTION_MODE_ROTATION;
}


unsigned int AffineInteractor3D::GetInteractionMode() const
{
  return m_InteractionMode;
}


void AffineInteractor3D::SetPrecision( ScalarType precision )
{
  m_Precision = precision;
}

// Overwritten since this class can handle it better!
float AffineInteractor3D
::CanHandleEvent(StateEvent const* stateEvent) const
{
  float returnValue = 0.5;
  

  // If it is a key event that can be handled in the current state,
  // then return 0.5
  DisplayPositionEvent const *disPosEvent =
    dynamic_cast <const DisplayPositionEvent *> (stateEvent->GetEvent());

  // Key event handling:
  if (disPosEvent == NULL)
  {
    // Check if the current state has a transition waiting for that key event.
    if (this->GetCurrentState()->GetTransition(stateEvent->GetId())!=NULL)
    {
      return 0.5;
    }
    else
    {
      return 0.0;
    }
  }

  //on MouseMove do nothing!
  //if (stateEvent->GetEvent()->GetType() == Type_MouseMove)
  //{
  //  return 0.0;
  //}

  //if the event can be understood and if there is a transition waiting for that event
  if (this->GetCurrentState()->GetTransition(stateEvent->GetId())!=NULL)
bool mitk::AffineInteractor3D::ColorizeSurface ( vtkPolyData *  polyData,
const Point3D &  pickedPoint,
double  scalar = 0.0 
) [protected]

Definition at line 431 of file mitkAffineInteractor3D.cpp.

         :
    return Superclass::ExecuteAction( action, stateEvent );
  }

  return ok;
}

bool AffineInteractor3D::ColorizeSurface( vtkPolyData *polyData, 
  const Point3D & /*pickedPoint*/, double scalar )
{
  if ( polyData == NULL )
  {
bool mitk::AffineInteractor3D::ExecuteAction ( Action action,
mitk::StateEvent const *  stateEvent 
) [protected, virtual]

Method called in HandleEvent after Statechange.

look up which object method is associated to the given action and call the method

Each statechange has actions, which can be assigned by it's number. If you are developing a new statemachine, declare all your operations here and send them to Undo-Controller and to the Data. Object- and group-EventId can also be accessed through static methods from OperationEvent

Reimplemented from mitk::StateMachine.

Definition at line 136 of file mitkAffineInteractor3D.cpp.

    {
  //  // Get the Geometry2D of the window the user interacts with (for 2D point 
  //  // projection)
  //  BaseRenderer *renderer = stateEvent->GetEvent()->GetSender();
  //  const Geometry2D *projectionPlane = renderer->GetCurrentWorldGeometry2D();

  //  // For reading on the points, Ids etc
  //  //CurveModel::PointSetType *pointSet = curveModel->GetPointSet( timeStep );
  //  //if ( pointSet == NULL )
  //  //{
  //  //  return 0.0;
  //  //}

  //}
  return returnValue;
}


bool AffineInteractor3D
::ExecuteAction( Action *action, StateEvent const *stateEvent )
{
  bool ok = false;

  // Get data object
  BaseData *data = m_DataNode->GetData();
  if ( data == NULL )
  {
    MITK_ERROR << "No data object present!";
    return ok;
  }

  // Get Event and extract renderer
  const Event *event = stateEvent->GetEvent();
  BaseRenderer *renderer = NULL;
  vtkRenderWindow *renderWindow = NULL;
  vtkRenderWindowInteractor *renderWindowInteractor = NULL;
  vtkRenderer *currentVtkRenderer = NULL;
  vtkCamera *camera = NULL;

  if ( event != NULL )
  {
    renderer = event->GetSender();
    if ( renderer != NULL )
    {
      renderWindow = renderer->GetRenderWindow();
      if ( renderWindow != NULL )
      {
        renderWindowInteractor = renderWindow->GetInteractor();
        if ( renderWindowInteractor != NULL )
        {
          currentVtkRenderer = renderWindowInteractor
            ->GetInteractorStyle()->GetCurrentRenderer();
          if ( currentVtkRenderer != NULL )
          {
            camera = currentVtkRenderer->GetActiveCamera();
          }
        }
      }
    }
  }

  // Check if we have a DisplayPositionEvent
  const DisplayPositionEvent *dpe = 
    dynamic_cast< const DisplayPositionEvent * >( stateEvent->GetEvent() );     
  if ( dpe != NULL )
  {
    m_CurrentPickedPoint = dpe->GetWorldPosition();
    m_CurrentPickedDisplayPoint = dpe->GetDisplayPosition();
  }

  // Get the timestep to also support 3D+t
  int timeStep = 0;
  ScalarType timeInMS = 0.0;
  if ( renderer != NULL )
  {
    timeStep = renderer->GetTimeStep( data );
    timeInMS = renderer->GetTime();
  }

  // If data is an mitk::Surface, extract it
  Surface *surface = dynamic_cast< Surface * >( data );
  vtkPolyData *polyData = NULL;
  if ( surface != NULL )
  {
    polyData = surface->GetVtkPolyData( timeStep );

    // Extract surface normal from surface (if existent, otherwise use default)
    vtkPointData *pointData = polyData->GetPointData();
    if ( pointData != NULL )
    {
      vtkDataArray *normal = polyData->GetPointData()->GetVectors( "planeNormal" );
      if ( normal != NULL )
      {
        m_ObjectNormal[0] = normal->GetComponent( 0, 0 );
        m_ObjectNormal[1] = normal->GetComponent( 0, 1 );
        m_ObjectNormal[2] = normal->GetComponent( 0, 2 );
      }
    }
  }

  // Get geometry object
  m_Geometry = data->GetGeometry( timeStep );


  // Make sure that the data (if time-resolved) has enough entries;
  // if not, create the required extra ones (empty)
  data->Expand( timeStep+1 );


  switch (action->GetActionId())
  {
  case AcDONOTHING:
    ok = true;
    break;


  case AcCHECKOBJECT:
    {
      // Re-enable VTK interactor (may have been disabled previously)
      if ( renderWindowInteractor != NULL )
      {
        renderWindowInteractor->Enable();
      }

      // Check if we have a DisplayPositionEvent
      const DisplayPositionEvent *dpe = 
        dynamic_cast< const DisplayPositionEvent * >( stateEvent->GetEvent() );     
      if ( dpe == NULL )
      {
        ok = true;
        break;
      }

      // Check if an object is present at the current mouse position
      DataNode *pickedNode = dpe->GetPickedObjectNode();
      StateEvent *newStateEvent;
      if ( pickedNode == m_DataNode )
      {
        // Yes: object will be selected
        newStateEvent = new StateEvent( EIDYES );
      }
      else
      {
        // No: back to start state
        newStateEvent = new StateEvent( EIDNO );
      }

      this->HandleEvent( newStateEvent );

      ok = true;
      break;
    }

  case AcDESELECTOBJECT:
    {
      // Color object white
      m_DataNode->SetColor( 1.0, 1.0, 1.0 );
      RenderingManager::GetInstance()->RequestUpdateAll();
  
      // Colorize surface / wireframe as inactive
      this->ColorizeSurface( polyData,
        m_CurrentPickedPoint, -1.0 );

      ok = true;
      break;
    }

  case AcSELECTPICKEDOBJECT:
    {
      // Color object red
      m_DataNode->SetColor( 1.0, 0.0, 0.0 );
      RenderingManager::GetInstance()->RequestUpdateAll();

      // Colorize surface / wireframe dependend on distance from picked point
      this->ColorizeSurface( polyData,
        m_CurrentPickedPoint, 0.0 );

      ok = true;  
      break;
    }

  case AcINITMOVE:
    {
      // Disable VTK interactor until MITK interaction has been completed
      if ( renderWindowInteractor != NULL )
      {
        renderWindowInteractor->Disable();
      }

      // Check if we have a DisplayPositionEvent
      const DisplayPositionEvent *dpe = 
        dynamic_cast< const DisplayPositionEvent * >( stateEvent->GetEvent() );     
      if ( dpe == NULL )
      {
        ok = true;
        break;
      }

      //DataNode *pickedNode = dpe->GetPickedObjectNode();
      
      m_InitialPickedPoint = m_CurrentPickedPoint;
      m_InitialPickedDisplayPoint = m_CurrentPickedDisplayPoint;

      if ( currentVtkRenderer != NULL )
      {
        vtkInteractorObserver::ComputeDisplayToWorld(
          currentVtkRenderer,
          m_InitialPickedDisplayPoint[0],
          m_InitialPickedDisplayPoint[1],
          0.0, //m_InitialInteractionPickedPoint[2],
          m_InitialPickedPointWorld );
      }


      // Make deep copy of current Geometry3D of the plane
      data->UpdateOutputInformation(); // make sure that the Geometry is up-to-date
      m_OriginalGeometry = static_cast< Geometry3D * >( 
        data->GetGeometry( timeStep )->Clone().GetPointer() );

      ok = true;
      break;
    }

  case AcMOVE:
    {
      // Check if we have a DisplayPositionEvent
      const DisplayPositionEvent *dpe = 
        dynamic_cast< const DisplayPositionEvent * >( stateEvent->GetEvent() );     
      if ( dpe == NULL )
      {
        ok = true;
        break;
      }

      if ( currentVtkRenderer != NULL )
      {
        vtkInteractorObserver::ComputeDisplayToWorld(
          currentVtkRenderer,
          m_CurrentPickedDisplayPoint[0],
          m_CurrentPickedDisplayPoint[1],
          0.0, //m_InitialInteractionPickedPoint[2],
          m_CurrentPickedPointWorld );
      }


      Vector3D interactionMove;
      interactionMove[0] = m_CurrentPickedPointWorld[0] - m_InitialPickedPointWorld[0];
      interactionMove[1] = m_CurrentPickedPointWorld[1] - m_InitialPickedPointWorld[1];
      interactionMove[2] = m_CurrentPickedPointWorld[2] - m_InitialPickedPointWorld[2];

      if ( m_InteractionMode == INTERACTION_MODE_TRANSLATION )
      {
        Point3D origin = m_OriginalGeometry->GetOrigin();

        Vector3D transformedObjectNormal;
        data->GetGeometry( timeStep )->IndexToWorld(
          origin, m_ObjectNormal, transformedObjectNormal );

        data->GetGeometry( timeStep )->SetOrigin(
          origin + transformedObjectNormal * (interactionMove * transformedObjectNormal) );
      }
      else if ( m_InteractionMode == INTERACTION_MODE_ROTATION )
      {
        if ( camera )
        {
          vtkFloatingPointType vpn[3];
          camera->GetViewPlaneNormal( vpn );

          Vector3D viewPlaneNormal;
          viewPlaneNormal[0] = vpn[0];
          viewPlaneNormal[1] = vpn[1];
          viewPlaneNormal[2] = vpn[2];

          Vector3D rotationAxis = 
            itk::CrossProduct( viewPlaneNormal, interactionMove );
          rotationAxis.Normalize();

          int *size = currentVtkRenderer->GetSize();
          double l2 =
            (m_CurrentPickedDisplayPoint[0] - m_InitialPickedDisplayPoint[0]) *
            (m_CurrentPickedDisplayPoint[0] - m_InitialPickedDisplayPoint[0]) +
            (m_CurrentPickedDisplayPoint[1] - m_InitialPickedDisplayPoint[1]) *
            (m_CurrentPickedDisplayPoint[1] - m_InitialPickedDisplayPoint[1]);

          double rotationAngle = 360.0 * sqrt(l2/(size[0]*size[0]+size[1]*size[1]));

          // Use center of data bounding box as center of rotation
virtual const char* mitk::AffineInteractor3D::GetClassName (  ) const [virtual]

Reimplemented from mitk::Interactor.

unsigned int mitk::AffineInteractor3D::GetInteractionMode (  ) const

Definition at line 62 of file mitkAffineInteractor3D.cpp.

{
static Pointer mitk::AffineInteractor3D::New ( const char *  _arga,
DataNode _argb,
int  _argc 
) [inline, static]

Definition at line 48 of file mitkAffineInteractor3D.h.

:
static Pointer mitk::AffineInteractor3D::New ( const char *  _arga,
DataNode _argb 
) [inline, static]

NewMacro with two parameters for calling itk::Lightobject::New(..) method.

Reimplemented from mitk::Interactor.

Definition at line 49 of file mitkAffineInteractor3D.h.

:
void mitk::AffineInteractor3D::SetInteractionMode ( unsigned int  interactionMode )

Definition at line 44 of file mitkAffineInteractor3D.cpp.

{
  
void mitk::AffineInteractor3D::SetInteractionModeToRotation (  )

Definition at line 56 of file mitkAffineInteractor3D.cpp.

void mitk::AffineInteractor3D::SetInteractionModeToTranslation (  )

Definition at line 50 of file mitkAffineInteractor3D.cpp.

: Interactor( type, dataNode ),
  m_Precision( 6.5 ),
void mitk::AffineInteractor3D::SetPrecision ( ScalarType  precision )

Sets the amount of precision.

Definition at line 68 of file mitkAffineInteractor3D.cpp.

{

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines