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

mitk::MoveSurfaceInteractor Class Reference
[Interaction Classes]

Interaction to move a surface by the arrow keys. See tutorial step 10 for explanation. More...

#include <mitkMoveSurfaceInteractor.h>

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

List of all members.

Public Types

typedef MoveSurfaceInteractor Self
typedef Interactor Superclass
typedef itk::SmartPointer< SelfPointer
typedef itk::SmartPointer
< const Self
ConstPointer

Public Member Functions

virtual const char * GetClassName () const

Static Public Member Functions

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

Protected Member Functions

 MoveSurfaceInteractor (const char *type, DataNode *dataNode)
 check how good an event can be handled
virtual ~MoveSurfaceInteractor ()
 Default Destructor.
virtual bool ExecuteAction (Action *action, mitk::StateEvent const *stateEvent)
 Convert the given Actions to Operations and send to data and UndoController.

Detailed Description

Interaction to move a surface by the arrow keys. See tutorial step 10 for explanation.

Definition at line 33 of file mitkMoveSurfaceInteractor.h.


Member Typedef Documentation

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

Reimplemented from mitk::Interactor.

Definition at line 36 of file mitkMoveSurfaceInteractor.h.

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

Reimplemented from mitk::Interactor.

Definition at line 36 of file mitkMoveSurfaceInteractor.h.

Reimplemented from mitk::Interactor.

Definition at line 36 of file mitkMoveSurfaceInteractor.h.

Reimplemented from mitk::Interactor.

Definition at line 36 of file mitkMoveSurfaceInteractor.h.


Constructor & Destructor Documentation

mitk::MoveSurfaceInteractor::MoveSurfaceInteractor ( const char *  type,
DataNode dataNode 
) [protected]

check how good an event can be handled

Gets called when mitk::DataNode::SetData() is called

No need to use it here, because the pattern won't be complex and we can take care of unexpected data change Constructor

Examples:
mitkMoveSurfaceInteractor.cpp.

Definition at line 32 of file mitkMoveSurfaceInteractor.cpp.

:Interactor(type, dataNode)
{
}
mitk::MoveSurfaceInteractor::~MoveSurfaceInteractor (  ) [protected, virtual]

Default Destructor.

Examples:
mitkMoveSurfaceInteractor.cpp.

Definition at line 37 of file mitkMoveSurfaceInteractor.cpp.

{
}

Member Function Documentation

bool mitk::MoveSurfaceInteractor::ExecuteAction ( Action action,
mitk::StateEvent const *  stateEvent 
) [protected, virtual]

Convert the given Actions to Operations and send to data and UndoController.

Reimplemented from mitk::StateMachine.

Examples:
mitkMoveSurfaceInteractor.cpp.

Definition at line 42 of file mitkMoveSurfaceInteractor.cpp.

References mitk::AcCHECKELEMENT, mitk::AcDESELECT, mitk::AcDONOTHING, mitk::AcMOVE, mitk::AcSELECT, mitk::EIDNO, mitk::EIDYES, mitk::Action::GetActionId(), mitk::StateEvent::GetEvent(), mitk::TimeSlicedGeometry::GetGeometry3D(), mitk::RenderingManager::GetInstance(), mitk::Action::GetProperty(), mitk::BaseData::GetUpdatedTimeSlicedGeometry(), mitk::GenericProperty< T >::GetValue(), mitk::DisplayPositionEvent::GetWorldPosition(), mitk::Geometry3D::IsInside(), MITK_WARN, mitk::ColorProperty::New(), mitk::BoolProperty::New(), mitk::RenderingManager::RequestUpdateAll(), and mitk::Geometry3D::Translate().

{
  bool ok = false;

  /*Each case must watch the type of the event!*/
  switch (action->GetActionId())
  {
  case AcDONOTHING:
    ok = true;
    break;
  case AcCHECKELEMENT: 
    /*
    * picking: Answer the question if the given position within stateEvent is close enough to select an object
    * send yes if close enough and no if not picked
    */
    {
      mitk::DisplayPositionEvent const *posEvent = dynamic_cast <const mitk::DisplayPositionEvent *> (stateEvent->GetEvent());
      if (posEvent == NULL)
      {
        MITK_WARN<<"Wrong usage of mitkMoveSurfaceInteractor! Aborting interaction!\n";
        return false;
      }

      mitk::Point3D worldPoint = posEvent->GetWorldPosition();
      /* now we have a worldpoint. check if it is inside our object and select/deselect it accordingly */

      mitk::StateEvent* newStateEvent = NULL;
      const Geometry3D* geometry = GetData()->GetUpdatedTimeSlicedGeometry()->GetGeometry3D( m_TimeStep );
      if (geometry->IsInside(worldPoint))
        newStateEvent = new mitk::StateEvent(EIDYES, stateEvent->GetEvent());
      else
        newStateEvent = new mitk::StateEvent(EIDNO, stateEvent->GetEvent());

      /* write new state (selected/not selected) to the property */      
      this->HandleEvent( newStateEvent );
    
    ok = true;
    break;
    }
  case AcSELECT:
    // select the data
    {
      mitk::BoolProperty::Pointer selected = dynamic_cast<mitk::BoolProperty*>(m_DataNode->GetProperty("selected"));
      if ( selected.IsNull() ) 
      {
        selected = mitk::BoolProperty::New();
        m_DataNode->GetPropertyList()->SetProperty("selected", selected);
      }

      mitk::ColorProperty::Pointer color = dynamic_cast<mitk::ColorProperty*>(m_DataNode->GetProperty("color"));
      if ( color.IsNull() ) 
      {
        color = mitk::ColorProperty::New();
        m_DataNode->GetPropertyList()->SetProperty("color", color);
      }

      selected->SetValue(true);
      color->SetColor(1.0, 1.0, 0.0);

      //update rendering
      mitk::RenderingManager::GetInstance()->RequestUpdateAll();

      ok = true;
      break;
    }
  case AcDESELECT:
    //deselect the data
    {
      mitk::BoolProperty::Pointer selected = dynamic_cast<mitk::BoolProperty*>(m_DataNode->GetProperty("selected"));
      if ( selected.IsNull() ) 
      {
        selected = mitk::BoolProperty::New();
        m_DataNode->GetPropertyList()->SetProperty("selected", selected);
      }

      mitk::ColorProperty::Pointer color = dynamic_cast<mitk::ColorProperty*>(m_DataNode->GetProperty("color"));
      if ( color.IsNull() ) 
      {
        color = mitk::ColorProperty::New();
        m_DataNode->GetPropertyList()->SetProperty("color", color);
      }

      selected = mitk::BoolProperty::New(false);
      color->SetColor(0.0, 0.0, 1.0);

      //update rendering
      mitk::RenderingManager::GetInstance()->RequestUpdateAll();

      ok = true;
      break;
    }
  case AcMOVE:
    {
      //modify Geometry from data as given in parameters or in event
      mitk::IntProperty* xP = dynamic_cast<mitk::IntProperty*>(action->GetProperty("DIRECTION_X"));
      mitk::IntProperty* yP = dynamic_cast<mitk::IntProperty*>(action->GetProperty("DIRECTION_Y"));
      mitk::IntProperty* zP = dynamic_cast<mitk::IntProperty*>(action->GetProperty("DIRECTION_Z"));
      if (xP == NULL || yP == NULL || zP == NULL)
      {
        MITK_WARN<<"No properties returned\n!";
        return false;
      }
      mitk::Vector3D movementVector;
      movementVector.SetElement(0, (float) xP->GetValue());
      movementVector.SetElement(1, (float) yP->GetValue());
      movementVector.SetElement(2, (float) zP->GetValue());

      //checking corresponding Data; has to be a surface or a subclass
      mitk::Surface* surface = dynamic_cast<mitk::Surface*>(m_DataNode->GetData());
      if ( surface == NULL )
      {
        MITK_WARN<<"MoveSurfaceInteractor got wrong type of data! Aborting interaction!\n";
        return false;
      }
      Geometry3D* geometry = surface->GetUpdatedTimeSlicedGeometry()->GetGeometry3D( m_TimeStep );
      geometry->Translate(movementVector);

      // indicate modification of data tree node
      m_DataNode->Modified();
      
      //update rendering
      mitk::RenderingManager::GetInstance()->RequestUpdateAll();

      ok = true;
      break;
    }

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

  return ok;
}
virtual const char* mitk::MoveSurfaceInteractor::GetClassName (  ) const [virtual]

Reimplemented from mitk::Interactor.

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

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

Reimplemented from mitk::Interactor.

Examples:
Step10.cpp.

Definition at line 37 of file mitkMoveSurfaceInteractor.h.

Referenced by main().


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