Medical Imaging Interaction Toolkit  2023.12.99-b884b24c
Medical Imaging Interaction Toolkit
Interaction Related Examples in MITK

How to disable/re-enable/modify Display Interaction using Microservices

Display Interaction is implemented as EventObservers that are registered as Microservices. This allows them to be queried and modified from anywhere in the code. Application scenarios are e.g. wanting to disable certain interaction during a task, to avoid any conflicting actions, or to adapt the behavior to a special tool that is selected. One example in the MITK Workbench are the measurement tools. They are designed to operate on a single slice, such that we do not want the user to move the cross-hair once he started a measurement. Once he finished the measurement the usual interaction should be restored. The following code demonstrates how this is done.

To change the mitk::DisplayActionEventBroadcast behavior, we first need to set up MicroService capabilities in the module by adding:

Furthermore, following includes are needed for the code snipped to work:

The first code snippet queries the us for the DisplayActionEventBroadcast and then exchanges its configuration for a minimal version, that does not allow cross-hair actions. The original configuration is stored in a member that allows restoration of the original behavior once we're done with our action.

m_DisplayInteractorConfigs.clear();
for (const auto& eventObserver : eventObservers)
{
auto displayActionEventBroadcast = dynamic_cast<mitk::DisplayActionEventBroadcast*>(
if (nullptr != displayActionEventBroadcast)
{
// remember the original configuration
m_DisplayInteractorConfigs.insert(std::make_pair(eventObserver, displayActionEventBroadcast->GetEventConfig()));
// here the alternative configuration is loaded
displayActionEventBroadcast->AddEventConfig("DisplayConfigBlockLMB.xml");
}
}

To restore the old configuration, query the DisplayActionEventBroadcast again and then restore the saved configuration:

for (const auto& displayInteractorConfig : m_DisplayInteractorConfigs)
{
if (displayInteractorConfig.first)
{
auto displayActionEventBroadcast = static_cast<mitk::DisplayActionEventBroadcast *>(
us::GetModuleContext()->GetService<mitk::InteractionEventObserver>(displayInteractorConfig.first));
if (nullptr != displayActionEventBroadcast)
{
// here the regular configuration is loaded again
displayActionEventBroadcast->SetEventConfig(displayInteractorConfig.second);
}
}
}
m_DisplayInteractorConfigs.clear();

Member declaration:

// holds configuration objects that have been deactivated
std::map<us::ServiceReferenceU, mitk::EventConfig> m_DisplayInteractorConfigs;
mitkEventConfig.h
US_INITIALIZE_MODULE
#define US_INITIALIZE_MODULE
Creates initialization code for a module.
Definition: usModuleInitialization.h:57
mitk::InteractionEventObserver
Base class to implement InteractionEventObservers.
Definition: mitkInteractionEventObserver.h:33
us::GetModuleContext
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
Definition: usGetModuleContext.h:50
ModuleContext::GetService
void * GetService(const ServiceReferenceBase &reference)
mitkInteractionEventObserver.h
usModuleInitialization.h
mitk::DisplayActionEventBroadcast
This class serves as an event state machine while simultaneously observing interaction events....
Definition: mitkDisplayActionEventBroadcast.h:32
mitk::InteractionEventHandler::AddEventConfig
bool AddEventConfig(const std::string &filename, const us::Module *module=nullptr)
This method extends the configuration.
usServiceRegistration.h
usModuleContext.h
mitk::InteractionEventHandler::SetEventConfig
bool SetEventConfig(const std::string &filename, const us::Module *module=nullptr)
Loads a configuration from an XML resource.
usGetModuleContext.h
ModuleContext::GetServiceReferences
std::vector< ServiceReferenceU > GetServiceReferences(const std::string &clazz, const std::string &filter=std::string())
mitkDisplayActionEventBroadcast.h