<commit_before>## @package StructuralAPI
# An alternative high(mid?)-level python API to describe a Compliant scene.
#
# With this API, the SOFA structure is not hidden and must be known by the user.
# But the obscure python-based structures (like Frame) are hidden.
#
# An important advantage is that a pointer is accessible for any created node and component
# (simplifying component customization, manual sub-scene creation, etc.)
#
# Note that both python APIs and manual creation can be used together.
#
# see Compliant/examples/StructuralAPI.py for a basic example.

import Frame
import Tools
from Tools import cat as concat
import numpy
import Sofa
from SofaPython import Quaternion
import SofaPython.Tools
import SofaPython.mass
import math
import sys

# to specify the floating point encoding:
# "d" to force double
# "f" to force float
# "" to let the template aliases mechanism chose according sofa compilation option (USE_FLOAT and USE_DOUBLE)
template_suffix=""

# global variable to give a different name to each visual model
idxVisualModel = 0

# to use geometric_stiffness of rigid mappings
# @warning WIP, the API will change
geometric_stiffness = 0

def scaleOffset(scale, offset):
    """ scale the translation part of an offset
    """
    return (scale*numpy.asarray(offset[0:3])).tolist() + offset[3:]

class RigidBody:
    ## Generic Rigid Body


    def __init__(self, node, name):
        self.node = node.createChild( name )  # node
        self.collision = None # the added collision mesh if any
        self.visual = None # the added visual model if any
        self.dofs = None   # dofs
        self.mass = None   # mass
        self.frame = Frame.Frame()
        self.framecom = Frame.Frame()
        self.fixedConstraint = None # to fix the RigidBody

    def setFromMesh(self, filepath, density = 1000, offset = [0,0,0,0,0,0,1], scale3d=[1,1,1], inertia_forces = False ):
        ## create the rigid body from a mesh (inertia and com are automatically computed)
        massInfo = SofaPython.mass.RigidMassInfo()
        massInfo.setFromMesh(filepath, density, scale3d)
        self.setFromRigidInfo(massInfo, offset, inertia_forces)

    def setFromRigidInfo(self, info, offset = [0,0,0,0,0,0,1], inertia_forces = False) :
        self.framecom = Frame.Frame()
        self.framecom.rotation = info.inertia_rotation
        self.framecom.translation = info.com

        self.frame = Frame.Frame(offset) * self.framecom

        self.dofs = self.frame.insert( self.node, name = 'dofs', template="Rigid3"+template_suffix )
        self.mass = self.node.createObject('RigidMass',<commit_msg>[Compliant] API: fix scaling when offset is already an array<commit_after>## @package StructuralAPI
# An alternative high(mid?)-level python API to describe a Compliant scene.
#
# With this API, the SOFA structure is not hidden and must be known by the user.
# But the obscure python-based structures (like Frame) are hidden.
#
# An important advantage is that a pointer is accessible for any created node and component
# (simplifying component customization, manual sub-scene creation, etc.)
#
# Note that both python APIs and manual creation can be used together.
#
# see Compliant/examples/StructuralAPI.py for a basic example.

import Frame
import Tools
from Tools import cat as concat
import numpy
import Sofa
from SofaPython import Quaternion
import SofaPython.Tools
import SofaPython.mass
import math
import sys

# to specify the floating point encoding:
# "d" to force double
# "f" to force float
# "" to let the template aliases mechanism chose according sofa compilation option (USE_FLOAT and USE_DOUBLE)
template_suffix=""

# global variable to give a different name to each visual model
idxVisualModel = 0

# to use geometric_stiffness of rigid mappings
# @warning WIP, the API will change
geometric_stiffness = 0

def scaleOffset(scale, offset):
    """ scale the translation part of an offset
    """
    return (scale*numpy.asarray(offset[0:3])).tolist() + numpy.asarray(offset[3:]).tolist()

class RigidBody:
    ## Generic Rigid Body


    def __init__(self, node, name):
        self.node = node.createChild( name )  # node
        self.collision = None # the added collision mesh if any
        self.visual = None # the added visual model if any
        self.dofs = None   # dofs
        self.mass = None   # mass
        self.frame = Frame.Frame()
        self.framecom = Frame.Frame()
        self.fixedConstraint = None # to fix the RigidBody

    def setFromMesh(self, filepath, density = 1000, offset = [0,0,0,0,0,0,1], scale3d=[1,1,1], inertia_forces = False ):
        ## create the rigid body from a mesh (inertia and com are automatically computed)
        massInfo = SofaPython.mass.RigidMassInfo()
        massInfo.setFromMesh(filepath, density, scale3d)
        self.setFromRigidInfo(massInfo, offset, inertia_forces)

    def setFromRigidInfo(self, info, offset = [0,0,0,0,0,0,1], inertia_forces = False) :
        self.framecom = Frame.Frame()
        self.framecom.rotation = info.inertia_rotation
        self.framecom.translation = info.com

        self.frame = Frame.Frame(offset) * self.framecom

        self.dofs = self.frame.insert( self.node, name = 'dofs', template="Rigid3"+template_suffix )
        self.mass = self.node.createObject('RigidMass',
{'fraction_non_alphanumeric': 0.08902691511387163, 'fraction_numerical': 0.010916619612271786, 'mean_word_length': 3.6289198606271778, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1087588', 'n_tokens_mistral': 1607, 'n_tokens_neox': 1525, 'n_words': 554}