Thank you for sharing this.
It is an important design principle that all processing must be implemented in a module’s logic class, and not in the user interface. This decoupling of GUI from logic allows performing batch processing (without instantiating GUI) or using a module from another module. There are a few more similar principles - see development tutorial here.
Therefore, a few suggestions:
- Do not retreive or use cliWidget. A module’s widget should never be used from another module.
- Node ID gets assigned automatically when a node is added to the scene and must not be get or set manually. To create an output model node, add it to the scene, and retrieve the object point, use
vtkMRMLNode* outputModelNode = scene->AddNewNodeByClass("vtkMRMLModelNode");
(this single line replaces 5-10 lines in your code) - All data processing should happen in your module logic, not in the GUI (widget) class, so move
Generate3dModel
method to your module logic and call that method from the GUI. See for example how it is done in Crop Volume module. If you need progress bar or execution in the background then you can return the created CLI module node to the caller.
Trivial: There is no “Name” parameter of Grayscale Model Maker module, so you can remove setting of that parameter.