Merging models with keeping labels

Hello all,
How should I merge two models so that each of them has a specific label in the merged model?
I tried merge models module but it does not work and I think it is because one of my models is volumetric.

Array values that can be found in all input meshes will be available in the output mesh, too. To merge volumetric meshes, you need to use vtkAppendFilter instead of vtkAppendPolyData.

It would be nice if you could update MergeModels module to be able to load and merge volumetric meshes (unstructure grids) and not just surface meshes (polydata). But if you are not familiar with C++ then you can implement appending in your own script/module in a few lines of Python code.

1 Like

Thank you very much for your answer. I am not very good with c++ but if I want to use the python codes, what resources can I use to find how to code such a command?
The other question is whether this way assigns a specific label to each model after they merged. Because I want a single merged model in which different parts have different labels.

Append operation preserves scalar values. You can assign constant scalar values before append.

1 Like

Thank you very much. I think there is no module for assigning label to a pre-existing model and I should use the following command.
modelNode.GetDisplayNode().SetActiveScalar(“selection”, vtk.vtkAssignAttribute.CELL_DATA)
Am I right?

To assign a point scalar array with a constant value for all the points, you can either manipulate the VTK data object (add an array, set the size to the number of points/cells, and fill with a constant) or use VTK filters (such as vtkArrayCalculator)

You can learn VTK from the VTK textbook, the huge collection of tests and examples, and API documentation.

You can find lots of examples of how to use VTK for processing MRML nodes in Slicer in the Slicer script repository. For example, adding a cell array with a constant value is shown here.

1 Like

Thank you very much for your help.

1 Like