Page MenuHomePhabricator

ToolManager should not instantiate every Tool class automatically
Closed, WontfixPublic

Description

We have a segmentation plugin that uses the MITK tool framework, but provides different tool and tool gui classes. I noticed that even if the MITK segmentation plugin is not turned on, the MITK segmentation tools, e.g. LiveWireTool2D are active. For instance, when I close the application it requests an update on all the render windows.

The source of the problem is the mitk::ToolManager::InitializeTools() function that creates an instance of every tool whose class is registered in the object factory.

I created a patch that defines a RegisterTool and UnregisterTool function in mitk::ToolManager and makes the InitializeTools function deprecated. With the patch the current tools should be registered from somewhere else, e.g. the the plugin activator of the segmentation plugin or the tool selection box.

This does not affect the MITK_TOOL_MACRO. The factories are created for the tools in the same way, and the tool managers create the tools using these factories, just not for all of them automatically but only for those that are registered by hand.

Event Timeline

https://github.com/NifTK/MITK/commit/c6729e72ca2d0cdd657d9492c4d914a057a0e178

The commit is not ready to merge, you would also need to call ToolManager::RegisterTool() for the needed tool classes from the segmentation plugin and the tests.

I updated the branch. Also registered all the MITK tools for the segmentation plugin. The list is probably longer than it needs to be. Remove the tools that are not needed by the plugin.

A similar change is needed for the tests, but I do not know which tools they need.

The latest commits are here:

https://github.com/NifTK/MITK/tree/bug-19266-toolmanager-register-tools

Do you agree with the concept of this fix?

Hi Miklos, thank you for having a look at this.
I totally agree that the current behaviour is not good, e.g. the renderwindow update of the "live wire" tool even if it is not used in your application.

I have one concern regarding the proposed fix:
One feature of the tool framework is that it can be extended with external tools using the ITK_AUTOLOAD_PATH.
For details, have a look at: http://docs.mitk.org/2015.05/toolextensions.html

With the proposed fix, this flexible extension won't work, you will always have to register new tools explicitly.

Another point is, that we are planning to migrate the segmentation tools from using the toolframework to a micro service based approach, which will most likely make you fix obsolete.

We will discuss this in the next MITK meeting and I will let you know about the result.

Good, I am fine with that. I leave the patch on our fork then. The microservice based approach sounds good. Please try to find a solution that does not automatically registers unneeded tools. Thanks so much!

kislinsk added subscribers: nolden, kislinsk.

@nolden Do you think it is a good idea for an introductionary project to switch to a micro service based tool architecture or is it too scary for newbies?
@espak Are you okay with closing the PR?

Do you want to switch to a microservice-based tool framework and retire the old tools at the same time?

Until the old framework there, this is a problem. It loads all the tools automatically, and e.g. the live wire tool updates the renderers in the background even if you never used it and you did not even open the MITK Segmentation view. On top of that it can cause a crash. This is just wrong.

So, if you do not accept the PR in this form, you can close it, but the issue is valid until the old framework is available, and it should be taken care of. What do you think would be a better way to handle this?

And if you move to the microservice-based approach, it should be checked if it does not have the same problem. The tools should be loaded on demand and they should be unloaded when they are not needed any more. This could be done e.g. in the Activated and Deactivated function of the Segmentation View.

Yes, sorry, this doesn't solve the problem for now, I know, but unfortunately the PR will break other stuff (see the comment of @fetzer above). We don't have the capacity at the moment for a fully working intermediate fix before the next release. Hence I would postpone the solution to this issue until we eventually improve the tool architecture.

kislinsk claimed this task.
kislinsk added a project: Auto-closed.

Hi there! 🙂

This task was auto-closed according to our Task Lifecycle Management.
Please follow this link for more information and don't forget that you are encouraged to reasonable re-open tasks to revive them. 🚑

Best wishes,
The MITK devs

kislinsk removed kislinsk as the assignee of this task.May 26 2020, 12:05 PM
kislinsk removed a subscriber: kislinsk.