Medical Imaging Interaction Toolkit  2018.4.99-f51274ea
Medical Imaging Interaction Toolkit

Base class of all tools used by mitk::ToolManager. More...

#include <mitkTool.h>

Inheritance diagram for mitk::Tool:
Collaboration diagram for mitk::Tool:

Public Types

typedef mitk::Label::PixelType DefaultSegmentationDataType
- Public Types inherited from mitk::EventStateMachine
typedef EventStateMachine Self
typedef InteractionEventHandler Superclass
typedef itk::SmartPointer< SelfPointer
typedef itk::SmartPointer< const SelfConstPointer
typedef std::map< std::string, TActionFunctor * > ActionFunctionsMapType
typedef itk::SmartPointer< StateMachineStateStateMachineStateType
- Public Types inherited from mitk::InteractionEventHandler
typedef InteractionEventHandler Self
typedef itk::Object Superclass
typedef itk::SmartPointer< SelfPointer
typedef itk::SmartPointer< const SelfConstPointer

Public Member Functions

 mitkClassMacro (Tool, EventStateMachine)
virtual const char ** GetXPM () const =0
 Returns an icon in the XPM format. More...
virtual std::string GetIconPath () const
 Returns the path of an icon. More...
virtual us::ModuleResource GetCursorIconResource () const
 Returns the path of a cursor icon. More...
virtual us::ModuleResource GetIconResource () const
 Returns the tool button icon of the tool wrapped by a usModuleResource. More...
virtual const char * GetName () const =0
 Returns the name of this tool. Make it short! More...
virtual const char * GetGroup () const
 Name of a group. More...
virtual void InitializeStateMachine ()
virtual itk::Object::Pointer GetGUI (const std::string &toolkitPrefix, const std::string &toolkitPostfix)
 Interface for GUI creation. More...
virtual NodePredicateBase::ConstPointer GetReferenceDataPreference () const
virtual NodePredicateBase::ConstPointer GetWorkingDataPreference () const
DataNode::Pointer CreateEmptySegmentationNode (const Image *original, const std::string &organName, const mitk::Color &color)
DataNode::Pointer CreateSegmentationNode (Image *image, const std::string &organName, const mitk::Color &color)
virtual bool CanHandle (BaseData *referenceData) const
- Public Member Functions inherited from mitk::EventStateMachine
virtual std::vector< std::string > GetClassHierarchy () const override
virtual const char * GetClassName () const
bool LoadStateMachine (const std::string &filename, const us::Module *module=nullptr)
 Loads XML resource. More...
bool HandleEvent (InteractionEvent *event, DataNode *dataNode)
void EnableUndo (bool enable)
 Enables or disabled Undo. More...
void EnableInteraction (bool enable)
 Enables/disables the state machine. In un-enabled state it won't react to any events. More...
- Public Member Functions inherited from mitk::InteractionEventHandler
bool SetEventConfig (const std::string &filename, const us::Module *module=nullptr)
 Loads a configuration from an XML resource. More...
bool SetEventConfig (const EventConfig &config)
 Loads a configuration from an EventConfig object. More...
EventConfig GetEventConfig () const
 Returns the current configuration. More...
bool AddEventConfig (const std::string &filename, const us::Module *module=nullptr)
 This method extends the configuration. More...
bool AddEventConfig (const EventConfig &config)
 This method extends the configuration. The configuration from the EventConfig object is loaded and only the ones conflicting are replaced by the new one. This way several configurations can be combined. More...
- Public Member Functions inherited from mitk::InteractionEventObserver
 InteractionEventObserver ()
virtual ~InteractionEventObserver ()
void Disable ()
void Enable ()
bool IsEnabled () const

Public Attributes

Message GUIProcessEventsMessage
 To let GUI process new events (e.g. qApp->processEvents() ) More...
Message1< std::string > ErrorMessage
 To send error messages (to be shown by some GUI) More...
Message1< bool > CurrentlyBusy
 To send whether the tool is busy (to be shown by some GUI) More...
Message1< std::string > GeneralMessage
 To send general messages (to be shown by some GUI) More...

Protected Member Functions

virtual void SetToolManager (ToolManager *)
void ConnectActionsAndFunctions () override
virtual void Activated ()
 Called when the tool gets activated. More...
virtual void Deactivated ()
 Called when the tool gets deactivated. More...
 Tool ()
 Tool (const char *, const us::Module *interactorModule=nullptr)
 ~Tool () override
void Notify (InteractionEvent *interactionEvent, bool isHandled) override
bool FilterEvents (InteractionEvent *, DataNode *) override
- Protected Member Functions inherited from mitk::EventStateMachine
 EventStateMachine ()
 ~EventStateMachine () override
void AddActionFunction (const std::string &action, TActionFunctor *functor)
void AddActionFunction (const std::string &action, const ActionFunctionDelegate &delegate)
void AddConditionFunction (const std::string &condition, const ConditionFunctionDelegate &delegate)
StateMachineStateGetCurrentState () const
void ResetToStartState ()
 ResetToStartState Reset state machine to it initial starting state. More...
virtual bool CheckCondition (const StateMachineCondition &condition, const InteractionEvent *interactionEvent)
virtual void ExecuteAction (StateMachineAction *action, InteractionEvent *interactionEvent)
void SetMouseCursor (const char *xpm[], int hotspotX, int hotspotY)
 Sets the specified mouse cursor. More...
void ResetMouseCursor ()
 Resets the mouse cursor (if modified by the SlicesCoordinator) to its original state. More...
StateMachineTransitionGetExecutableTransition (InteractionEvent *event)
 Returns the executable transition for the given event. More...
- Protected Member Functions inherited from mitk::InteractionEventHandler
 InteractionEventHandler ()
 ~InteractionEventHandler () override
PropertyList::Pointer GetAttributes () const
std::string MapToEventVariant (InteractionEvent *interactionEvent)
virtual void ConfigurationChanged ()

Protected Attributes

std::string m_EventConfig
 Let subclasses change their event configuration. More...
- Protected Attributes inherited from mitk::EventStateMachine
bool m_IsActive
bool m_UndoEnabled

Additional Inherited Members

- Static Public Member Functions inherited from mitk::EventStateMachine
static const char * GetStaticNameOfClass ()
- Static Public Member Functions inherited from mitk::InteractionEventHandler
static const char * GetStaticNameOfClass ()
- Protected Types inherited from mitk::EventStateMachine
typedef MessageAbstractDelegate2< StateMachineAction *, InteractionEvent *, void > ActionFunctionDelegate
typedef MessageAbstractDelegate1< const InteractionEvent *, bool > ConditionFunctionDelegate

Detailed Description

Base class of all tools used by mitk::ToolManager.

See also

Every tool is a mitk::StateMachine, which can follow any transition pattern that it likes. One important thing to know is, that every derived tool should always call SuperClass::Deactivated() at the end of its own implementation of Deactivated, because mitk::Tool resets the StateMachine in this method. Only if you are very sure that you covered all possible things that might happen to your own tool, you should consider not to reset the StateMachine from time to time.

To learn about the MITK implementation of state machines in general, have a look at Interaction and Undo/Redo Concepts.

To derive a non-abstract tool, you inherit from mitk::Tool (or some other base class further down the inheritance tree), and in your own parameterless constructor (that is called from the itkFactorylessNewMacro that you use) you pass a StateMachine pattern name to the superclass. Names for valid patterns can be found in StateMachine.xml (which might be enhanced by you).

You have to implement at least GetXPM() and GetName() to provide some identification.

Each Tool knows its ToolManager, which can provide the data that the tool should work on.

Only to be instantiated by mitk::ToolManager (because SetToolManager has to be called). All other uses are unsupported.


Definition at line 86 of file mitkTool.h.

Member Typedef Documentation

◆ DefaultSegmentationDataType

Constructor & Destructor Documentation

◆ Tool() [1/2]

mitk::Tool::Tool ( )

◆ Tool() [2/2]

mitk::Tool::Tool ( const char *  type,
const us::Module interactorModule = nullptr 

Definition at line 33 of file mitkTool.cpp.

◆ ~Tool()

mitk::Tool::~Tool ( )

Definition at line 58 of file mitkTool.cpp.

Member Function Documentation

◆ Activated()

◆ CanHandle()

bool mitk::Tool::CanHandle ( BaseData referenceData) const

◆ ConnectActionsAndFunctions()

void mitk::Tool::ConnectActionsAndFunctions ( )

Is called after loading a statemachine. Overwrite this function in specific interactor implementations. Connect actions and functions using the CONNECT_FUNCTION macro within this function.

Reimplemented from mitk::EventStateMachine.

Definition at line 99 of file mitkTool.cpp.

◆ CreateEmptySegmentationNode()

mitk::DataNode::Pointer mitk::Tool::CreateEmptySegmentationNode ( const Image original,
const std::string &  organName,
const mitk::Color color 

◆ CreateSegmentationNode()

◆ Deactivated()

◆ FilterEvents()

bool mitk::Tool::FilterEvents ( InteractionEvent interactionEvent,
DataNode dataNode 

Implements filter scheme for events. Standard implementation accepts events from 2d and 3d windows, and rejects events if DataNode is not visible.

true if event is accepted, else false

Overwrite this function to adapt for your own needs, for example to filter out events from 3d windows like this:

bool mitk::EventStateMachine::FilterEvents(InteractionEvent* interactionEvent, DataNode*dataNode)
return interactionEvent->GetSender()->GetMapperID() == BaseRenderer::Standard2D; // only 2D mappers

or to enforce that the interactor only reacts when the corresponding DataNode is selected in the DataManager view..

Reimplemented from mitk::EventStateMachine.

Definition at line 103 of file mitkTool.cpp.

◆ GetCursorIconResource()

◆ GetGroup()

const char * mitk::Tool::GetGroup ( ) const

Name of a group.

You can group several tools by assigning a group name. Graphical tool selectors might use this information to group tools. (What other reason could there be?)

Reimplemented in mitk::AutoSegmentationTool, and mitk::SegmentationsProcessingTool.

Definition at line 108 of file mitkTool.cpp.

Referenced by QmitkToolSelectionBox::RecreateButtons(), and QmitkToolSelectionBox::SetOrUnsetButtonForActiveTool().

◆ GetGUI()

itk::Object::Pointer mitk::Tool::GetGUI ( const std::string &  toolkitPrefix,
const std::string &  toolkitPostfix 

Interface for GUI creation.

This is the basic interface for creation of a GUI object belonging to one tool.

Tools that support a GUI (e.g. for display/editing of parameters) should follow some rules:

  • A Tool and its GUI are two separate classes
  • There may be several instances of a GUI at the same time.
  • mitk::Tool is toolkit (Qt, wxWidgets, etc.) independent, the GUI part is of course dependent
  • The GUI part inherits both from itk::Object and some GUI toolkit class
  • The GUI class name HAS to be constructed like "toolkitPrefix" tool->GetClassName() + "toolkitPostfix", e.g. MyTool -> wxMyToolGUI
  • For each supported toolkit there is a base class for tool GUIs, which contains some convenience methods
  • Tools notify the GUI about changes using ITK events. The GUI must observe interesting events.
  • The GUI base class may convert all ITK events to the GUI toolkit's favoured messaging system (Qt -> signals)
  • Calling methods of a tool by its GUI is done directly. In some cases GUIs don't want to be notified by the tool when they cause a change in a tool. There is a macro CALL_WITHOUT_NOTICE(method()), which will temporarily disable all notifications during a method call.

Definition at line 175 of file mitkTool.cpp.

References MITK_ERROR.

Referenced by QmitkToolSelectionBox::SetOrUnsetButtonForActiveTool().

◆ GetIconPath()

virtual std::string mitk::Tool::GetIconPath ( ) const

Returns the path of an icon.

This icon is preferred to the XPM icon.

Definition at line 130 of file mitkTool.h.

References GetName(), and image.

◆ GetIconResource()

us::ModuleResource mitk::Tool::GetIconResource ( ) const

◆ GetName()

◆ GetReferenceDataPreference()

mitk::NodePredicateBase::ConstPointer mitk::Tool::GetReferenceDataPreference ( ) const

Definition at line 200 of file mitkTool.cpp.

◆ GetWorkingDataPreference()

mitk::NodePredicateBase::ConstPointer mitk::Tool::GetWorkingDataPreference ( ) const

Definition at line 205 of file mitkTool.cpp.

◆ GetXPM()

virtual const char** mitk::Tool::GetXPM ( ) const
pure virtual

◆ InitializeStateMachine()

void mitk::Tool::InitializeStateMachine ( )

◆ mitkClassMacro()

mitk::Tool::mitkClassMacro ( Tool  ,

◆ Notify()

void mitk::Tool::Notify ( InteractionEvent interactionEvent,
bool  isHandled 

By this method all registered EventObersers are notified about every InteractionEvent, the isHandled flag indicates if a DataInteractor has already handled that event. InteractionEventObserver that trigger an action when observing an event may consider this in order to not confuse the user by, triggering several independent action with one single user event (such as a mouse click)

If you want to use the InteractionEventObserver as a state machine give the event to the state machine by implementing, e.g.

if (!isHandled) {
this->HandleEvent(interactionEvent, nullptr);

This overwrites the FilterEvents function of the EventStateMachine to ignore the DataNode, since InteractionEventObservers are not associated with one. virtual bool FilterEvents(InteractionEvent* interactionEvent, DataNode* dataNode);

Implements mitk::InteractionEventObserver.

Definition at line 89 of file mitkTool.cpp.

References mitk::EventStateMachine::HandleEvent().

◆ SetToolManager()

void mitk::Tool::SetToolManager ( ToolManager manager)

Definition at line 113 of file mitkTool.cpp.

References m_ToolManager.

Member Data Documentation

◆ CurrentlyBusy

Message1<bool> mitk::Tool::CurrentlyBusy

To send whether the tool is busy (to be shown by some GUI)

Definition at line 104 of file mitkTool.h.

Referenced by mitk::FastMarchingTool3D::Update(), and mitk::FastMarchingTool::Update().

◆ ErrorMessage

◆ GeneralMessage

Message1<std::string> mitk::Tool::GeneralMessage

To send general messages (to be shown by some GUI)

Definition at line 109 of file mitkTool.h.

Referenced by QmitkToolSelectionBox::RecreateButtons().

◆ GUIProcessEventsMessage

Message mitk::Tool::GUIProcessEventsMessage

To let GUI process new events (e.g. qApp->processEvents() )

Definition at line 94 of file mitkTool.h.

Referenced by QmitkToolSelectionBox::RecreateButtons().

◆ m_EventConfig

std::string mitk::Tool::m_EventConfig

Let subclasses change their event configuration.

Definition at line 218 of file mitkTool.h.

Referenced by Activated(), and mitk::SegTool2D::SegTool2D().

◆ m_ToolManager

ToolManager* mitk::Tool::m_ToolManager

Definition at line 228 of file mitkTool.h.

Referenced by mitk::BinaryThresholdTool::AcceptCurrentThresholdValue(), mitk::BinaryThresholdULTool::AcceptCurrentThresholdValue(), mitk::PixelManipulationTool::Activated(), mitk::SegmentationsProcessingTool::Activated(), mitk::BinaryThresholdTool::Activated(), mitk::BinaryThresholdULTool::Activated(), mitk::PaintbrushTool::Activated(), mitk::FastMarchingTool3D::Activated(), mitk::FastMarchingTool::Activated(), mitk::SegTool2D::AddContourmarker(), mitk::PixelManipulationTool::AddImageToDataStorage(), mitk::PixelManipulationTool::CalculateImage(), mitk::BinaryThresholdTool::CancelThresholding(), mitk::BinaryThresholdULTool::CancelThresholding(), mitk::PaintbrushTool::CheckIfCurrentSliceHasChanged(), mitk::LiveWireTool2D::ClearSegmentation(), mitk::LiveWireTool2D::ConfirmSegmentation(), mitk::FastMarchingTool3D::ConfirmSegmentation(), mitk::FastMarchingTool::ConfirmSegmentation(), mitk::BinaryThresholdTool::CreateNewSegmentationFromThreshold(), mitk::BinaryThresholdULTool::CreateNewSegmentationFromThreshold(), mitk::PixelManipulationTool::Deactivated(), mitk::BinaryThresholdTool::Deactivated(), mitk::BinaryThresholdULTool::Deactivated(), mitk::PaintbrushTool::Deactivated(), mitk::FeedbackContourTool::Deactivated(), mitk::FastMarchingTool3D::Deactivated(), mitk::FastMarchingTool::Deactivated(), mitk::WatershedTool::DoIt(), mitk::SegTool2D::GetAffectedReferenceSlice(), mitk::SegTool2D::GetAffectedWorkingSlice(), mitk::AutoSegmentationTool::GetCurrentSegmentationName(), mitk::PickingTool::GetDataStorage(), mitk::PickingTool::GetReferenceData(), mitk::AutoSegmentationTool::GetTargetSegmentationNode(), mitk::PickingTool::GetWorkingData(), mitk::FastMarchingTool3D::Initialize(), mitk::FastMarchingTool::Initialize(), mitk::PaintbrushTool::MouseMoved(), mitk::SetRegionTool::OnMousePressed(), mitk::PaintbrushTool::OnMousePressed(), mitk::RegionGrowingTool::OnMousePressedOutside(), mitk::SetRegionTool::OnMouseReleased(), mitk::ContourTool::OnMouseReleased(), mitk::CorrectorTool2D::OnMouseReleased(), mitk::RegionGrowingTool::OnMouseReleased(), mitk::PickingTool::OnPointAdded(), mitk::BinaryThresholdTool::OnRoiDataChanged(), mitk::BinaryThresholdULTool::OnRoiDataChanged(), mitk::SegmentationsProcessingTool::ProcessAllObjects(), mitk::FeedbackContourTool::SetFeedbackContourVisible(), SetToolManager(), mitk::BinaryThresholdTool::SetupPreviewNode(), mitk::BinaryThresholdULTool::SetupPreviewNode(), mitk::SegTool2D::WriteBackSegmentationResult(), mitk::SegTool2D::WriteSliceToVolume(), and mitk::LiveWireTool2D::~LiveWireTool2D().

The documentation for this class was generated from the following files: