Interface for an Interactor. More...
#include <mitkInteractor.h>
Public Types | |
enum | SMMode { SMDESELECTED = 0, SMSELECTED, SMSUBSELECTED } |
Enumeration of the different modes an Interactor can be into. See class documentation for further details. More... | |
typedef Interactor | Self |
typedef StateMachine | Superclass |
typedef itk::SmartPointer< Self > | Pointer |
typedef itk::SmartPointer < const Self > | ConstPointer |
typedef SMMode | ModeType |
Public Member Functions | |
virtual const char * | GetClassName () const |
SMMode | GetMode () const |
Get the Mode of the Interactor. Use enum SMMode for return parameter. | |
bool | IsNotSelected () const |
Check the interaction mode. | |
bool | IsSelected () const |
Check the interaction mode. | |
virtual float | CanHandleEvent (StateEvent const *stateEvent) const |
calculates how good the data, this statemachine handles, is hit by the event. | |
bool | HandleEvent (StateEvent const *stateEvent) |
Updates the current TimeStep according to the associated data and calls Superclass::HandleEvent() | |
virtual void | DataChanged () |
Method to call if the associated data has changed by the user (loading of data) This method is called by DataNode::SetData() to tell the interactor to reinitialize. This method should be overwritten by specialized interactors. (e.g. PointSetInteractor: go to the right state according to number of loaded points) Note: It will not be called when the data gets modified (e.g. adding / removing points to a PointSet) | |
Static Public Member Functions | |
static Pointer | New (const char *_arga, DataNode *_argb) |
NewMacro with two parameters for calling itk::Lightobject::New(..) method. | |
Static Public Attributes | |
static const std::string | XML_NODE_NAME = "interactor" |
Protected Member Functions | |
Interactor (const char *type, DataNode *dataNode) | |
Constructor. | |
~Interactor () | |
Destructor. | |
bool | OnModeSelect (Action *action, StateEvent const *) |
bool | OnModeDeselect (Action *action, StateEvent const *) |
bool | OnModeSubSelect (Action *action, StateEvent const *) |
virtual void | ExecuteOperation (Operation *operation) |
adds handling of operations used for mode change. Unrecognized Operations are send to Superclass. | |
virtual const std::string & | GetXMLNodeName () const |
void | CreateModeOperation (ModeType mode) |
creates a ModeOperation with the transmitted mode and sends it to this. Undo supported! | |
BaseData * | GetData () const |
convenience method for accessing the data contained in the node to which this interactor is associated to | |
virtual void | SetDataNode (DataNode *dataNode) |
Used by friend class DataNode. | |
virtual void | UpdateTimeStep (unsigned int timeStep) |
Derived from superclass to also check if enough timesteps are instantiated in m_CurrentStateVector The number of timesteps is read from the dedicated data. | |
Protected Attributes | |
DataNode * | m_DataNode |
Pointer to the data, this object handles the Interaction for. | |
ModeType | m_Mode |
Mode of Selection. | |
Friends | |
class | DataNode |
Interface for an Interactor.
The Interactor is held with a SmartPointer by a DataNode and holds its Node with a Pointer. That way Smartpointer doesn't build a circle. Different Modes: In order to not send Events to all StateMachines, a StateMachine can be in three different modes: DESELECTED: this statemachine doesn't wait for an event SELECTED: this statemachine just has handled an event and waits for the next one SUBSELECTED: depricate; was used for hierarchical statemachines before. Guidelines for the modevalues: Selected if the coresponding data is selected, deselected if deselect of data.
In moving the machine is selected. After a new insert the machine is selected, since the data is also selected In method ExecuteAction(..) the different actions are divided up through switch/case statements. Each block has to check the appropriate type of event to process the actions. Especially in guarding states (a state, that checks certain conditions (e.g. is picked) the according Event must be called to continue in states. No return false here!
Definition at line 50 of file mitkInteractor.h.
typedef itk::SmartPointer<const Self> mitk::Interactor::ConstPointer |
Reimplemented from mitk::StateMachine.
Reimplemented in mitk::AffineInteractor, mitk::MouseMovePointSetInteractor, mitk::MoveSurfaceInteractor, mitk::PointSetInteractor, mitk::AffineInteractor3D, mitk::ConnectPointsInteractor, mitk::ContourInteractor, mitk::DisplayPointSetInteractor, mitk::ExtrudedContourInteractor, mitk::PointInteractor, mitk::PointSelectorInteractor, mitk::SeedsInteractor, mitk::SurfaceDeformationInteractor3D, mitk::SurfaceInteractor, and mitk::PlanarFigureInteractor.
Definition at line 53 of file mitkInteractor.h.
typedef SMMode mitk::Interactor::ModeType |
Definition at line 70 of file mitkInteractor.h.
typedef itk::SmartPointer<Self> mitk::Interactor::Pointer |
Reimplemented from mitk::StateMachine.
Reimplemented in mitk::AffineInteractor, mitk::MouseMovePointSetInteractor, mitk::MoveSurfaceInteractor, mitk::PointSetInteractor, mitk::AffineInteractor3D, mitk::ConnectPointsInteractor, mitk::ContourInteractor, mitk::DisplayPointSetInteractor, mitk::ExtrudedContourInteractor, mitk::PointInteractor, mitk::PointSelectorInteractor, mitk::SeedsInteractor, mitk::SurfaceDeformationInteractor3D, mitk::SurfaceInteractor, and mitk::PlanarFigureInteractor.
Definition at line 53 of file mitkInteractor.h.
typedef Interactor mitk::Interactor::Self |
Reimplemented from mitk::StateMachine.
Reimplemented in mitk::AffineInteractor, mitk::MouseMovePointSetInteractor, mitk::MoveSurfaceInteractor, mitk::PointSetInteractor, mitk::AffineInteractor3D, mitk::ConnectPointsInteractor, mitk::ContourInteractor, mitk::DisplayPointSetInteractor, mitk::ExtrudedContourInteractor, mitk::PointInteractor, mitk::PointSelectorInteractor, mitk::SeedsInteractor, mitk::SurfaceDeformationInteractor3D, mitk::SurfaceInteractor, and mitk::PlanarFigureInteractor.
Definition at line 53 of file mitkInteractor.h.
Reimplemented from mitk::StateMachine.
Reimplemented in mitk::AffineInteractor, mitk::MouseMovePointSetInteractor, mitk::MoveSurfaceInteractor, mitk::PointSetInteractor, mitk::AffineInteractor3D, mitk::ConnectPointsInteractor, mitk::ContourInteractor, mitk::DisplayPointSetInteractor, mitk::ExtrudedContourInteractor, mitk::PointInteractor, mitk::PointSelectorInteractor, mitk::SeedsInteractor, mitk::SurfaceDeformationInteractor3D, mitk::SurfaceInteractor, and mitk::PlanarFigureInteractor.
Definition at line 53 of file mitkInteractor.h.
Enumeration of the different modes an Interactor can be into. See class documentation for further details.
Definition at line 63 of file mitkInteractor.h.
{ SMDESELECTED = 0, SMSELECTED, SMSUBSELECTED };
mitk::Interactor::Interactor | ( | const char * | type, |
DataNode * | dataNode | ||
) | [protected] |
Constructor.
dataNode | is the node, this Interactor is connected to |
type | is the type of StateMachine like declared in the XML-Configure-File |
Interactor connects itself to the DataNode-Interactor-pointer through call of SetInteractor(this)
Definition at line 40 of file mitkInteractor.cpp.
References mitk::AcMODEDESELECT, mitk::AcMODESELECT, mitk::AcMODESUBSELECT, CONNECT_ACTION, m_DataNode, OnModeDeselect(), OnModeSelect(), OnModeSubSelect(), and mitk::DataNode::SetInteractor().
: StateMachine(type), m_DataNode(dataNode), m_Mode(SMDESELECTED) { if (m_DataNode != NULL) m_DataNode->SetInteractor(this); // handle these actions in those Methods CONNECT_ACTION( AcMODEDESELECT, OnModeDeselect ); CONNECT_ACTION( AcMODESELECT, OnModeSelect ); CONNECT_ACTION( AcMODESUBSELECT, OnModeSubSelect ); }
mitk::Interactor::~Interactor | ( | ) | [inline, protected] |
float mitk::Interactor::CanHandleEvent | ( | StateEvent const * | stateEvent ) | const [virtual] |
calculates how good the data, this statemachine handles, is hit by the event.
Returns a value between 0 and 1 where 0 represents not responsible and 1 represents definitive responsible! Standard function to override if needed. (Used by GlobalInteraction to decide which DESELECTED statemachine to send the event to.)
Reimplemented in mitk::AffineInteractor, mitk::MouseMovePointSetInteractor, mitk::PointSetInteractor, mitk::AffineInteractor3D, mitk::ConnectPointsInteractor, mitk::PointInteractor, mitk::PointSelectorInteractor, mitk::SurfaceDeformationInteractor3D, mitk::SurfaceInteractor, and mitk::PlanarFigureInteractor.
Definition at line 123 of file mitkInteractor.cpp.
References mitk::StateEvent::GetEvent(), mitk::StateEvent::GetId(), mitk::Event::GetType(), QuadProgPP::max(), and mitk::Type_MouseMove.
{ //return value for boundingbox float returnvalueBB = 0.0, //return value for a existing transition returnvalueTransition = 0.0, //return value for an existing key transition returnvalueKey = 0.0; //if it is a key event that can be handled in the current state 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) { returnvalueKey = 0.5; } } //Mouse event handling: //on MouseMove do nothing! reimplement if needed differently if (stateEvent->GetEvent()->GetType() == Type_MouseMove) { return 0; } //if the event can be understood and if there is a transition waiting for that event if (this->GetCurrentState()->GetTransition(stateEvent->GetId())!=NULL) { returnvalueTransition = 0.5;//it can be understood } //compute the center of the data taken care of if != NULL if (GetData() != NULL) { const BoundingBox *bBox = GetData()->GetUpdatedTimeSlicedGeometry()->GetBoundingBox(); if (bBox == NULL) return 0; DisplayPositionEvent const *event = dynamic_cast <const DisplayPositionEvent *> (stateEvent->GetEvent()); if (event != NULL) { //transforming the world position to local coordinate system Point3D point; GetData()->GetTimeSlicedGeometry()->WorldToIndex(event->GetWorldPosition(), point); //distance between center and point BoundingBox::PointType center = bBox->GetCenter(); returnvalueBB = point.EuclideanDistanceTo(center); // now check if object bounding box has a non-zero size float bBoxSize = bBox->GetMaximum().EuclideanDistanceTo(bBox->GetMinimum() ); if( bBoxSize < 0.00001 ) return 0; // bounding box too small? //now compared to size of bounding box to get value between 0 and 1; returnvalueBB = returnvalueBB/bBoxSize; //safety: if by now return value is not in [0,1], then return 0! if (returnvalueBB>1 || returnvalueBB<0) returnvalueBB = 0; // A return value of 1 is good, 0 is bad -> reverse value returnvalueBB = 1 - returnvalueBB; //check if the given position lies inside the data object if (bBox->IsInside(point)) { //mapped between 0.5 and 1 returnvalueBB = 0.5 + (returnvalueBB/ 2); } else { //set it in range between 0 and 0.5 returnvalueBB = returnvalueBB / 2; } } } //else // itkWarningMacro("Data of Interactor is NULL! Please check setup of Interactors!"); return std::max(returnvalueBB, std::max(returnvalueKey, returnvalueTransition)); }
void mitk::Interactor::CreateModeOperation | ( | ModeType | mode ) | [protected] |
creates a ModeOperation with the transmitted mode and sends it to this. Undo supported!
Definition at line 77 of file mitkInteractor.cpp.
References mitk::OpMODECHANGE.
{ ModeOperation* doOp = new ModeOperation(OpMODECHANGE, mode); if (m_UndoEnabled) { ModeOperation* undoOp = new ModeOperation(OpMODECHANGE, this->GetMode()); OperationEvent *operationEvent = new OperationEvent(this, doOp, undoOp); m_UndoController->SetOperationEvent(operationEvent); } this->ExecuteOperation(doOp); }
virtual void mitk::Interactor::DataChanged | ( | ) | [inline, virtual] |
Method to call if the associated data has changed by the user (loading of data) This method is called by DataNode::SetData() to tell the interactor to reinitialize. This method should be overwritten by specialized interactors. (e.g. PointSetInteractor: go to the right state according to number of loaded points) Note: It will not be called when the data gets modified (e.g. adding / removing points to a PointSet)
Reimplemented in mitk::PointSetInteractor.
Definition at line 105 of file mitkInteractor.h.
{};
void mitk::Interactor::ExecuteOperation | ( | Operation * | operation ) | [protected, virtual] |
adds handling of operations used for mode change. Unrecognized Operations are send to Superclass.
Reimplemented from mitk::StateMachine.
Definition at line 210 of file mitkInteractor.cpp.
References mitk::ModeOperation::GetMode(), mitk::Operation::GetOperationType(), and mitk::OpMODECHANGE.
{ switch (operation->GetOperationType()) { case OpMODECHANGE: { ModeOperation *modeOp = dynamic_cast<ModeOperation*>(operation); if (modeOp) { m_Mode = modeOp->GetMode(); } } break; default: Superclass::ExecuteOperation(operation); } }
virtual const char* mitk::Interactor::GetClassName | ( | ) | const [virtual] |
Reimplemented from mitk::StateMachine.
Reimplemented in mitk::AffineInteractor, mitk::MouseMovePointSetInteractor, mitk::MoveSurfaceInteractor, mitk::PointSetInteractor, mitk::AffineInteractor3D, mitk::ConnectPointsInteractor, mitk::ContourInteractor, mitk::DisplayPointSetInteractor, mitk::ExtrudedContourInteractor, mitk::PointInteractor, mitk::PointSelectorInteractor, mitk::SeedsInteractor, mitk::SurfaceDeformationInteractor3D, mitk::SurfaceInteractor, and mitk::PlanarFigureInteractor.
mitk::BaseData * mitk::Interactor::GetData | ( | ) | const [protected] |
convenience method for accessing the data contained in the node to which this interactor is associated to
Definition at line 54 of file mitkInteractor.cpp.
{ if (m_DataNode != NULL) return m_DataNode->GetData(); else return NULL; }
mitk::Interactor::SMMode mitk::Interactor::GetMode | ( | ) | const |
Get the Mode of the Interactor. Use enum SMMode for return parameter.
Definition at line 62 of file mitkInteractor.cpp.
Referenced by mitk::GlobalInteraction::AddInteractor().
{ return m_Mode; }
const std::string & mitk::Interactor::GetXMLNodeName | ( | ) | const [protected, virtual] |
Definition at line 228 of file mitkInteractor.cpp.
{ return XML_NODE_NAME; }
bool mitk::Interactor::HandleEvent | ( | StateEvent const * | stateEvent ) | [virtual] |
Updates the current TimeStep according to the associated data and calls Superclass::HandleEvent()
Reimplemented from mitk::StateMachine.
Definition at line 275 of file mitkInteractor.cpp.
References mitk::StateEvent::GetEvent(), and mitk::BaseRenderer::GetTimeStep().
{ //update the Time and then call Superclass if (stateEvent != NULL) { mitk::Event const* event = stateEvent->GetEvent(); if (event != NULL) { mitk::BaseRenderer* sender = event->GetSender(); if (sender != NULL) { //Get the TimeStep according to CurrentWorldGeometry2D unsigned int currentTimeStep = sender->GetTimeStep(); if (currentTimeStep != m_TimeStep) this->UpdateTimeStep(currentTimeStep); } } } return Superclass::HandleEvent(stateEvent); }
bool mitk::Interactor::IsNotSelected | ( | ) | const |
Check the interaction mode.
Definition at line 67 of file mitkInteractor.cpp.
{ return (m_Mode==SMDESELECTED); }
bool mitk::Interactor::IsSelected | ( | ) | const |
Check the interaction mode.
Definition at line 72 of file mitkInteractor.cpp.
{ return (m_Mode!=SMDESELECTED); }
NewMacro with two parameters for calling itk::Lightobject::New(..) method.
Reimplemented in mitk::AffineInteractor, mitk::MouseMovePointSetInteractor, mitk::MoveSurfaceInteractor, mitk::PointSetInteractor, mitk::AffineInteractor3D, mitk::ConnectPointsInteractor, mitk::ContourInteractor, mitk::DisplayPointSetInteractor, mitk::ExtrudedContourInteractor, mitk::PointInteractor, mitk::PointSelectorInteractor, mitk::SeedsInteractor, mitk::SurfaceDeformationInteractor3D, mitk::SurfaceInteractor, and mitk::PlanarFigureInteractor.
Definition at line 58 of file mitkInteractor.h.
Referenced by mitkInteractorTest().
{
bool mitk::Interactor::OnModeDeselect | ( | Action * | action, |
StateEvent const * | |||
) | [protected] |
Definition at line 89 of file mitkInteractor.cpp.
References mitk::GlobalInteraction::GetInstance(), and mitk::GlobalInteraction::RemoveFromSelectedInteractors().
Referenced by Interactor().
{ GlobalInteraction* global = GlobalInteraction::GetInstance(); if (global == NULL) itkWarningMacro("Message from Interactor.cpp: GlobalInteraction == NULL! Check use of Interactor!"); if( this->GetMode() != SMDESELECTED) { this->CreateModeOperation(SMDESELECTED); global->RemoveFromSelectedInteractors(this); } return true; }
bool mitk::Interactor::OnModeSelect | ( | Action * | action, |
StateEvent const * | |||
) | [protected] |
Definition at line 103 of file mitkInteractor.cpp.
References mitk::GlobalInteraction::AddToSelectedInteractors(), and mitk::GlobalInteraction::GetInstance().
Referenced by Interactor().
{ GlobalInteraction* global = GlobalInteraction::GetInstance(); if (global == NULL) itkWarningMacro("Message from Interactor.cpp: GlobalInteraction == NULL! Check use of Interactor!"); if( this->GetMode() != SMSELECTED) { this->CreateModeOperation(SMSELECTED); global->AddToSelectedInteractors(this); } return true; }
bool mitk::Interactor::OnModeSubSelect | ( | Action * | action, |
StateEvent const * | |||
) | [protected] |
Definition at line 117 of file mitkInteractor.cpp.
Referenced by Interactor().
{ //StatusBar::GetInstance()->DisplayText("Error! in XML-Interaction: an simple Interactor can not set in sub selected", 1102); return false; }
void mitk::Interactor::SetDataNode | ( | DataNode * | dataNode ) | [protected, virtual] |
Used by friend class DataNode.
Definition at line 233 of file mitkInteractor.cpp.
References mitk::DataNode::GetData(), and mitk::BaseData::GetTimeSteps().
Referenced by mitk::DataNode::SetInteractor().
{ m_DataNode = dataNode; //check for the number of time steps and initialize the vector of CurrentStatePointer accordingly if (m_DataNode != NULL) { mitk::BaseData* data = dataNode->GetData(); if (data != NULL) { unsigned int timeSteps = data->GetTimeSteps(); //expand the list of StartStates according to the number of timesteps in data if (timeSteps > 1) this->InitializeStartStates(timeSteps); } } }
void mitk::Interactor::UpdateTimeStep | ( | unsigned int | timeStep ) | [protected, virtual] |
Derived from superclass to also check if enough timesteps are instantiated in m_CurrentStateVector The number of timesteps is read from the dedicated data.
[in] | timeStep | The timeStep that the statemachine has to be set to |
Reimplemented from mitk::StateMachine.
Definition at line 251 of file mitkInteractor.cpp.
{ //check if the vector of StartStates contains enough pointers to use timeStep if (timeStep >= 1) { // Make sure that the data (if time-resolved) has enough entries; // if not, create the required extra ones (empty) if (m_DataNode!= NULL) if (m_DataNode->GetData()!= NULL) m_DataNode->GetData()->Expand(timeStep+1); //+1 becuase the vector starts with 0 and the timesteps with 1 //now check for this object this->ExpandStartStateVector(timeStep+1); //nothing is changed if the number of timesteps in data equals the number of startstates held in statemachine } //set the time to the given time Superclass::UpdateTimeStep(timeStep); //time has to be up-to-date //check and throw an exception if not so if (timeStep != m_TimeStep) itkExceptionMacro(<<"Time is invalid. Take care of synchonization!"); }
friend class DataNode [friend] |
Definition at line 165 of file mitkInteractor.h.
DataNode* mitk::Interactor::m_DataNode [protected] |
Pointer to the data, this object handles the Interaction for.
Definition at line 159 of file mitkInteractor.h.
Referenced by mitk::ContourInteractor::ContourInteractor(), mitk::ExtrudedContourInteractor::ExtrudedContourInteractor(), and Interactor().
ModeType mitk::Interactor::m_Mode [protected] |
Mode of Selection.
Definition at line 163 of file mitkInteractor.h.
const std::string mitk::Interactor::XML_NODE_NAME = "interactor" [static] |
Definition at line 105 of file mitkInteractor.h.