Use a list of models in a CLI

Hello,

I am trying to create a CLI with a variable number of models as input and only one as output.
First, I tried to use a string-vector but when running some C++ code it doesn’t pass OpenVTKFile() if I use a vtkPolyDataReader or doesn’t pass IsFilePolyData() if I use vtkGenericDataObjectReader().

The second option was to use the geometry tag with the “multiple” attribute set as True, but when I assign a list of nodes to the cli input (via python for example), the list is not propagated to the computation part and I so the C++ code return an error because the list is size 0.

Do you have any idea?

One approach is to assign a unique scalar value to the points of each polydata (for example, add a “ComponentID” value, it would be 0 for all the points in the first data set, 1 for all points in the second data set, etc) and append all polydata into one, using vtkAppendPolyData filter. In your CLI you can separate components by thresholding.

Another approach is to choose a model hierarchy node. Model hierarchies can be transferred as a “mini-scene”. You’ll get the filename of a scene and the hierarchy node ID (separated by #). You can load the scene from that file, find the hierarchy node by its ID, and get each child node and their polydata. Example CLI module description XML:

<geometry aggregate="true" fileExtensions=".mrml" multiple="true">
  <name>ModelSceneFileIn</name>
  <channel>input</channel>
  <label>Models</label>
  <longflag>--modelSceneFileIn</longflag>
  <description><![CDATA[Some description.]]></description>
  <default>models.mrml</default>
</geometry>

There is one trick to this: you have to make sure there is a storage node created for your model nodes (for example, you iterate through all model nodes in the scene and call CreateDefaultStorageNode() method; it is not a problem if you call it multiple times - if the model node already has a storage node then the call will simply have no effect).