opensim-core icon indicating copy to clipboard operation
opensim-core copied to clipboard

Marker does not appear in MarkerSet if added via addComponent()

Open tkuchida opened this issue 2 years ago • 2 comments

The doxygen for Component::addComponent() says "addComponent is intended to replace existing addBody(), addJoint, ... on Model or the requirement for specific add###() methods to subcomponents to a Component"; however, a marker added using addComponent() does not end up in the model's MarkerSet (despite the fact that the marker appears in the Navigator and Visualizer when the model is opened in the GUI).

To reproduce

  • open arm26.osim
  • in the ScriptingShell Window:
model = getCurrentModel()
m = modeling.Marker('test', model.getBodySet().get('base'), modeling.Vec3(0))
model.addComponent(m)
model.finalizeConnections()
model.print('test.osim')
  • close arm26 model
  • open test.osim

Expected behavior

New marker appears in Visualizer Window, is listed under "Markers" in Navigator, and appears in the model's MarkerSet.

Actual behavior

New marker appears in Visualizer Window and is listed under "Markers" in Navigator, but does not appear in the model's MarkerSet (getCurrentModel().getMarkerSet().getSize() returns 3 not 4).

Version

OpenSim 4.4-2022-04-22-788d079 (from https://github.com/opensim-org/opensim-gui/pull/1347).

tkuchida avatar Jun 26 '22 11:06 tkuchida

Thanks for reporting @tkuchida I don't think this is surprising or new, it has been the behavior since 4.0. The rationale, we collectively decided to keep the various Sets as a way to group components (BodySet, JointSet, MarkerSet, .....). If you call addMarker() then the Marker is added to the MarkerSet and into the component tree, if you call addComponent() the Marker is added to the component tree and will likely work as expected for code that iterates through the model (e.g. visualization) but not for code that uses the MarkerSet. I agree it's not best and maybe should be better documented, but nothing else to be done about it AFAICT. Though open for suggestions.

aymanhab avatar Jun 27 '22 15:06 aymanhab

Thanks @aymanhab. I think full/consistent adoption of the MCI is a known issue (e.g., #308) so perhaps just a documentation update? The current behavior seems to directly contradict the doxygen for addComponent(): "addComponent is intended to replace existing addBody(), addJoint, ... on Model or the requirement for specific add###() methods to subcomponents to a Component." Alternatively, could give the user a warning if addComponent() is called with a Component of type Body, Joint, Marker, etc., where there's a separate addBody(), addJoint(), addMarker(), etc. method (though probably overkill).

tkuchida avatar Jun 27 '22 17:06 tkuchida