コード例 #1
0
def attachGeometryWithOffset(frame, geometry):
    """Attach geometry to provided frame. This function adds an
	intermediate offset frame between the geometry and the provided frame
	to permit editing its properties to move the geometry around.
	
	This function returns the intermediate offset frame so that you can
	modify its location and orientation.
	"""
    offset = modeling.PhysicalOffsetFrame()
    offset.setName(frame.getName() + '_offset')
    offset.set_translation(modeling.Vec3(0.))
    offset.set_orientation(modeling.Vec3(0.))
    frame.addComponent(offset)
    bf = modeling.PhysicalFrame.safeDownCast(frame)
    offset.connectSocket_parent(bf)
    offset.attachGeometry(geometry)
    return offset
コード例 #2
0
ファイル: ModelBuilder.py プロジェクト: jaehyek/opensim-gui
 def addMuscle(model, muscleName, muscleType):
     """Add a muscle to the provided model, with the provided muscleName.
     muscleType is either 'Thelen2003Muscle' or
     'Millard2012EquilibriumMuscle'.
     """
     validMuscleTypes = ['Thelen2003Muscle', 'Millard2012EquilibriumMuscle']
     if not muscleType in validMuscleTypes:
         raise Exception('Provided muscleType %s is not valid.' %
                         muscleType)
     module = sys.modules['org.opensim.modeling']
     MuscleClass = getattr(module, muscleType)
     # Instantiate the requested muscle class.
     muscle = MuscleClass()
     muscle.setName(muscleName)
     muscle.addNewPathPoint("muscle-pt1", model.getGround(),
                            modeling.Vec3(0, 0, 0))
     muscle.addNewPathPoint("muscle-pt2", model.getGround(),
                            modeling.Vec3(0, 1, 0))
     model.addForce(muscle)
コード例 #3
0
    def marker_error_for_frame(model, state, data, marker_names, trc):
        for mname in marker_names:
            marker = model.getMarkerSet().get(mname)
            modelMarkerPosInGround = osm.Vec3()
            engine.transformPosition(state, marker.getBody(),
                                     marker.getOffset(), model.getGroundBody(),
                                     modelMarkerPosInGround)
            expMarkerPosInGround = trc.marker_at(mname, state.getTime())

            a = modelMarkerPosInGround
            b = np.array(expMarkerPosInGround) * 0.001
            distance = np.sqrt((a.get(0) - b[0])**2 + (a.get(1) - b[1])**2 +
                               (a.get(2) - b[2])**2)
            data[mname].append(distance)
コード例 #4
0
ファイル: ModelBuilder.py プロジェクト: jaehyek/opensim-gui
    def addBody(model, bodyName):
        """Create a Body, with the provided bodyName, and add it to the
        provided model.
        The Body has a mass of 1 and inertia (1,1,1,0,0,0).
        If a body with the same name already exists in the model, then this
        body will be automatically renamed, and a warning will appear in the
        Scripting Shell.

        This function returns the new body added to the model.
        """
        body = modeling.Body(bodyName, 1.0, modeling.Vec3(1.0),
                             modeling.Inertia(1, 1, 1, 0, 0, 0))
        model.addBody(body)
        return body
コード例 #5
0
    def __init__(self, body_name, x, y, z, scale_set=None):
        """
        Parameters
        ----------
        body_name : str
            org.opensim.modeling.Scale.setSegmentName(body_name)
        x, y, z : float
            org.opensim.modeling.Scale.setScaleFactors([x, y, z])
        scaleset : org.opensim.modeling.ScaleSet, optional
            A ScaleSet to adopt-and-append the org.opensim.modeling.Scale to.

        """
        self.scale = osm.Scale()
        self.scale.setName(body_name)
        self.scale.setSegmentName(body_name)
        self.scale.setScaleFactors(osm.Vec3(x, y, z))
        if scale_set:
            scale_set.cloneAndAppend(self.scale)