public class OpenSimParser
extends java.lang.Object
.osim
file and associated geometry
folder, and creates the corresponding ArtiSynth components and arranges them
in a MechModel
. The OpenSim component hierarchy is preserved, and
the resulting MechModel components can be queried after using methods
supplied by this parser. Not all OpenSim components are implemented, but
those that are include most of the commonly used components found in "bodyset"
, "jointset"
, "forceset"
, "constraintset"
,
and "markersset"
.Modifier and Type | Field and Description |
---|---|
static boolean |
myFrameGeometryVisible |
static boolean |
myIgnoreFrameGeometry |
Constructor and Description |
---|
OpenSimParser(java.io.File osimFile)
Creates a new OpenSim parser for a specified OpenSim (.osim) file.
|
OpenSimParser(java.io.File osimFile,
java.io.File geometryPath)
Creates a new OpenSim parser for a specified OpenSim (.osim) file and
geometry folder.
|
OpenSimParser(java.io.File file,
java.io.File geometryPath,
OpenSimObjectFactoryStore factories)
Creates a new parser
|
Modifier and Type | Method and Description |
---|---|
CoordinatePanel |
createCoordinatePanel()
Creates a panel to control the coordinates of all the joints located
beneath the
"jointset" (OpenSim 4 models) or beneath the "bodyset" (OpenSim 3 models). |
CoordinatePanel |
createCoordinatePanel(java.util.Collection<JointBase> joints)
Creates a panel to control the coordinates of the specified joints.
|
CoordinatePanel |
createCoordinatePanel(java.lang.String[] coordNames)
Creates a panel to control the named coordinates of the joints located
beneath the
"jointset" (OpenSim 4 models) or beneath the "bodyset" (OpenSim 3 models). |
ControlPanel |
createExcitationPanel()
Creates a control panel for all the muscle excitations.
|
ControlPanel |
createExcitationPanel(java.lang.String[] muscleNames)
Creates a control panel for the excitations of all the names muscles.
|
MechModel |
createModel()
Creates a
MechModel and populates is with ArtiSynth
implementations of components read from the OpenSim file, preserving the
OpenSim names and component hierarchy. |
MechModel |
createModel(MechModel mech)
Populates a
MechModel with ArtiSynth implementations of
components read from the OpenSim file, preserving the OpenSim names and
component hierarchy. |
RigidBody |
findBody(java.lang.String name)
Finds a specific rigid body within the "bodyset" by name.
|
ConstrainerBase |
findConstraint(java.lang.String name)
Finds a specific constraint by name.
|
JointCoordinateHandle |
findCoordinate(java.lang.String name)
Returns a handle for a specific coordinate in one of the joints returned
by
getJoints() . |
ForceComponent |
findForceComponent(java.lang.String name)
Finds a specific force component by name.
|
JointBase |
findJoint(java.lang.String name)
Finds a specific joint by name.
|
Marker |
findMarker(java.lang.String name)
Finds a specific marker by name.
|
PointSpringBase |
findMuscleOrSpring(java.lang.String name)
Finds a specific muscle or line-based spring by name.
|
WrapComponent |
findWrapObject(java.lang.String name)
Finds a specific wrap object by name.
|
RenderableComponentList<RigidBody> |
getBodySet()
Returns the top-level
"bodyset" rigid body list component
contained in the MecModel associated with this parser. |
java.util.ArrayList<WrapComponent> |
getBodyWrapObjects(RigidBody body)
Returns a list of the wrap objects attached to a specific rigid body.
|
ModelComponentMap |
getComponentMap()
Returns the ModelComponentMap for the most recently created model,
or {#code null} if no model has been created yet.
|
RenderableComponentList<ConstrainerBase> |
getConstraintSet()
Returns the top-level
"constraintset" constrainer list component
contained in the MecModel associated with this parser. |
java.util.ArrayList<JointCoordinateHandle> |
getCoordinates()
Returns a list of coordinate handles for all the joints returned
by
getJoints() . |
java.util.ArrayList<ForceComponent> |
getForceComponents()
Returns a list of the all the
ForceComponent located beneath the
"forceset" . |
RenderableComponentList<ModelComponent> |
getForceSet()
Returns the top-level
"forceset" force effector list component
contained in the MecModel associated with this parser. |
boolean |
getFrameGeometryVisible() |
java.io.File |
getGeometryFolder()
Returns the primary geometry folder currently used by this parser.
|
java.io.File |
getGeometryPath()
Deprecated.
Use
getGeometryFolder() instead. |
RigidBody |
getGround()
Returns the top-level
"ground" rigid body contained in the
MecModel associated with this parser. |
boolean |
getIgnoreFrameGeometry() |
java.util.ArrayList<JointBase> |
getJoints()
Returns a list of all the joints located beneath the
"jointset"
(OpenSim 4 models) or beneath the "bodyset" (OpenSim 3 models). |
RenderableComponentList<JointBase> |
getJointSet()
Returns the top-level
"jointset" joint list component contained
in the MecModel associated with this parser. |
PointList<Marker> |
getMarkerSet()
Returns the top-level
"markerset" marker list component
contained in the MecModel associated with this parser. |
MechModel |
getMechModel()
Returns the
MechModel either most recently populated or created
by createModel(MechModel) or createModel() , or set
using setMechModel(artisynth.core.mechmodels.MechModel) . |
java.util.ArrayList<PointSpringBase> |
getMusclesAndSprings()
Returns a list of the all the muscle and and line-based spring components
located beneath the
"forceset" . |
java.util.List<WrapComponent> |
getMuscleWrapObjects(PointSpringBase muscle)
Returns a list of all the wrap objects associated with a specific muscle
or spring.
|
java.util.ArrayList<WrapComponent> |
getWrapObjects()
Returns a list of all wrap objects attached to the rigid bodies located
under the "bodyset".
|
void |
load() |
void |
removeWrapObject(WrapComponent wobj)
Remove a wrap object and its associated attachment from their positions
in the OpenSim component hierarchy.
|
void |
replaceMarker(Marker mkr,
PointAttachable body)
Replace a marker in the OpenSim component hierarchy with a new marker
that is created by attaching to the specified body or frame in the same
location.
|
void |
replaceMusclePoint(PointSpringBase muscle,
Marker pnt,
PointAttachable body)
Replace a muscle path point in the OpenSim component hierarchy with a new
point that is created by attaching to the specified body or frame in the
same location.
|
void |
setBodyFramesVisible(Renderer.AxisDrawStyle style,
double axisLength)
Convenience method to set the visibility of the coordinate frames of the
rigid bodies located beneath the "bodyset", plus "ground".
|
void |
setFrameGeometryVisible(boolean enable) |
void |
setGeometryPath(java.io.File geometryPath)
Sets the geometry folder to be used in subsequent calls to
createModel(artisynth.core.mechmodels.MechModel) or createModel(MechModel) ). |
void |
setIgnoreFrameGeometry(boolean ignore) |
void |
setMechModel(MechModel mech)
Explicitly sets the
MechModel associated with this parser. |
void |
setWrapObjectsVisible(boolean visible)
Convenience method to set the visibility of the all wrap objects attached
to the rigid bodies located under the "bodyset".
|
void |
updateMusclePaths()
Update wrap paths for all muscles.
|
void |
zeroMuscleExcitations()
Convenience method to zero the excitations of all muscle
components located beneath the
"forceset" . |
public static boolean myIgnoreFrameGeometry
public static boolean myFrameGeometryVisible
public OpenSimParser(java.io.File file, java.io.File geometryPath, OpenSimObjectFactoryStore factories)
file
- file to parsegeometryPath
- folder to search for geometriesfactories
- factory storage for generating OpenSim objects from filepublic OpenSimParser(java.io.File osimFile, java.io.File geometryPath)
createModel(artisynth.core.mechmodels.MechModel)
or createModel(MechModel)
.osimFile
- OpenSim file to parsegeometryPath
- folder containing the OpenSim geometrypublic OpenSimParser(java.io.File osimFile)
createModel(artisynth.core.mechmodels.MechModel)
or createModel(MechModel)
). For model
loading to succeed, a geometry folder will most likely need to be
specified first using setGeometryPath(java.io.File)
.osimFile
- OpenSim file to parsepublic void load()
public void setGeometryPath(java.io.File geometryPath)
createModel(artisynth.core.mechmodels.MechModel)
or createModel(MechModel)
).geometryPath
- folder containing the OpenSim geometrypublic java.io.File getGeometryPath()
getGeometryFolder()
instead.public java.io.File getGeometryFolder()
public boolean getFrameGeometryVisible()
public void setFrameGeometryVisible(boolean enable)
public boolean getIgnoreFrameGeometry()
public void setIgnoreFrameGeometry(boolean ignore)
public MechModel createModel(MechModel mech)
MechModel
with ArtiSynth implementations of
components read from the OpenSim file, preserving the OpenSim names and
component hierarchy. Unrecognized or implemented components are indicated
by warning messages printed on the console.mech
- MechModel to populate. If null
, then a new
model will be created.mech
, or the newly created model)public MechModel createModel()
MechModel
and populates is with ArtiSynth
implementations of components read from the OpenSim file, preserving the
OpenSim names and component hierarchy. Unrecognized or implemented
components are indicated by warning messages printed on the console.public ModelComponentMap getComponentMap()
public MechModel getMechModel()
MechModel
either most recently populated or created
by createModel(MechModel)
or createModel()
, or set
using setMechModel(artisynth.core.mechmodels.MechModel)
.public void setMechModel(MechModel mech)
MechModel
associated with this parser.mech
- MechModel to associated with this parserpublic RigidBody getGround()
"ground"
rigid body contained in the
MecModel associated with this parser. For OpenSim 4 models, this returns
separate ground component. For OpenSim 3, the bodyset is searched for a
component named "ground"
.null
if not present.public RenderableComponentList<RigidBody> getBodySet()
"bodyset"
rigid body list component
contained in the MecModel associated with this parser.null
if not present.public RigidBody findBody(java.lang.String name)
name
- name of the requested bodynull
if not foundpublic void setBodyFramesVisible(Renderer.AxisDrawStyle style, double axisLength)
Renderer.AxisDrawStyle
, and the
default value is OFF
.style
- draw style for the coordinate frameaxisLength
- if > 0
, sets the length of the coordinate
frames. Otherwise, the length is unchanged.public java.util.ArrayList<WrapComponent> getWrapObjects()
Wrappable
.public java.util.ArrayList<WrapComponent> getBodyWrapObjects(RigidBody body)
Wrappable
.body
- body for which wrap objects are requestedpublic void setWrapObjectsVisible(boolean visible)
visible
- if true
, wrap objects are set visible.public WrapComponent findWrapObject(java.lang.String name)
name
- name of the wrap objectnull
if not foundpublic RenderableComponentList<JointBase> getJointSet()
"jointset"
joint list component contained
in the MecModel associated with this parser. Note: this component is only
present for OpenSim 4 models. For OpenSim 3 models, one can obtain the
joints using getJoints()
instead.null
if not present.public java.util.ArrayList<JointBase> getJoints()
"jointset"
(OpenSim 4 models) or beneath the "bodyset"
(OpenSim 3 models).null
if not present.public JointBase findJoint(java.lang.String name)
name
- name of the requested jointnull
if not foundpublic java.util.ArrayList<JointCoordinateHandle> getCoordinates()
getJoints()
.public JointCoordinateHandle findCoordinate(java.lang.String name)
getJoints()
.name
- name of the requested coordinatenull
if not foundpublic RenderableComponentList<ModelComponent> getForceSet()
"forceset"
force effector list component
contained in the MecModel associated with this parser. Note: the
components in this list are sometimes composite components that contain
the actual ForceComponent as a descendent. To obtain an explicit
list of the force components, use getForceComponents()
.null
if not present.public java.util.ArrayList<ForceComponent> getForceComponents()
ForceComponent
located beneath the
"forceset"
. If the forceset is not present, an empty list is
returned.public java.util.ArrayList<PointSpringBase> getMusclesAndSprings()
"forceset"
. If the forceset is not present,
an empty list is returned.public ForceComponent findForceComponent(java.lang.String name)
name
- name of the force componentnull
if not foundpublic PointSpringBase findMuscleOrSpring(java.lang.String name)
name
- name of the muscle/springnull
if not foundpublic void zeroMuscleExcitations()
"forceset"
. This is
useful when a newly loaded model contains small bias excitations.public java.util.List<WrapComponent> getMuscleWrapObjects(PointSpringBase muscle)
MultiPointSpring
or MultiPointMuscle
,
then an empty list is returned. All of the returned wrap objectsmuscle
- muscle or line-based spring to querypublic RenderableComponentList<ConstrainerBase> getConstraintSet()
"constraintset"
constrainer list component
contained in the MecModel associated with this parser.null
if not present.public ConstrainerBase findConstraint(java.lang.String name)
name
- name of the constraintnull
if not foundpublic PointList<Marker> getMarkerSet()
"markerset"
marker list component
contained in the MecModel associated with this parser.null
if not present.public Marker findMarker(java.lang.String name)
name
- name of the markernull
if not foundpublic ControlPanel createExcitationPanel()
public ControlPanel createExcitationPanel(java.lang.String[] muscleNames)
muscleNames
- names of the muscles for which excitation controls
should be createdpublic CoordinatePanel createCoordinatePanel()
"jointset"
(OpenSim 4 models) or beneath the "bodyset"
(OpenSim 3 models).public CoordinatePanel createCoordinatePanel(java.util.Collection<JointBase> joints)
joints
- joint for which coordinate controls should be createdpublic CoordinatePanel createCoordinatePanel(java.lang.String[] coordNames)
"jointset"
(OpenSim 4 models) or beneath the "bodyset"
(OpenSim 3 models).coordNames
- names of the coordinates for which controls should be
createdpublic void updateMusclePaths()
public void removeWrapObject(WrapComponent wobj)
ComponentUtils.deleteComponentAndDependencies (wobj)which will remove the wrap object and also delete any references that are being made to it by
MultiPointSpring
objects.
After this method is called, the wrap object should be added back to the MechModel in a suitable location, and a new attachment for it must also be created and added.
wobj
- wrap object to remove from the hierarchy.public void replaceMusclePoint(PointSpringBase muscle, Marker pnt, PointAttachable body)
Marker
since this is always true for this parser's implementation of OpenSim
path points.
This method performs various checks to ensure that the point is located in the expected place within the OpenSim component hierarchy, If it is not, then an exception is thrown.
muscle
- muscle or axial spring whose point should be reassigned.pnt
- path point to replacebody
- to connect the new path point topublic void replaceMarker(Marker mkr, PointAttachable body)
This method checks to ensure that the point is located within the marker set in the OpenSim component hierarchy, If it is not, then an exception is thrown. It also assumes that nothing is connected to the marker; if it is, that application must handle this.
mkr
- marker point to replacebody
- to connect the new marker to