Exemple #1
0
 def __init__(self,
              node,
              filepath,
              scale3d,
              offset,
              name_suffix='',
              generatedDir=None):
     r = Quaternion.to_euler(offset[3:]) * 180.0 / math.pi
     global idxVisualModel
     self.node = node.createChild('visual' + name_suffix)  # node
     self.model = self.node.createObject('VisualModel',
                                         name='visual' +
                                         str(idxVisualModel),
                                         fileMesh=filepath,
                                         scale3d=concat(scale3d),
                                         translation=concat(offset[:3]),
                                         rotation=concat(r))
     if generatedDir is None:
         self.mapping = self.node.createObject(
             'LinearMapping',
             template='Affine,ExtVec3f',
             name='mapping')
     else:
         serialization.importLinearMapping(
             self.node, generatedDir + "_visualmapping.json")
     idxVisualModel += 1
Exemple #2
0
def transformToData(scale, offset, timeOffset=0, timeScale=1, isPerspective=0):
    """ Returns a transform, formatted to sofa data given voxelsize, rigid position (offset), time and camera parameters
    """
    return concat(offset[:3]) + ' ' + concat(
        quat.to_euler(offset[3:]) * 180. / math.pi) + ' ' + concat(
            scale) + ' ' + str(timeOffset) + ' ' + str(timeScale) + ' ' + str(
                int(isPerspective))
Exemple #3
0
 def __init__(self,
              node,
              filepath,
              scale3d,
              offset,
              name_suffix='',
              generatedDir=None):
     r = Quaternion.to_euler(offset[3:]) * 180.0 / math.pi
     self.node = node.createChild('collision' + name_suffix)  # node
     self.loader = SofaPython.Tools.meshLoader(self.node,
                                               filename=filepath,
                                               name='loader',
                                               scale3d=concat(scale3d),
                                               translation=concat(
                                                   offset[:3]),
                                               rotation=concat(r),
                                               triangulate=True)
     self.topology = self.node.createObject('MeshTopology',
                                            name='topology',
                                            src='@loader')
     self.dofs = self.node.createObject('MechanicalObject',
                                        name='dofs',
                                        template='Vec3' +
                                        template_suffix)
     self.triangles = self.node.createObject('TriangleModel',
                                             name='model')
     if generatedDir is None:
         self.mapping = self.node.createObject('LinearMapping',
                                               template='Affine,Vec3' +
                                               template_suffix,
                                               name='mapping')
     else:
         serialization.importLinearMapping(
             self.node, generatedDir + "_collisionmapping.json")
     self.normals = None
 def __init__(self, node, filepath, scale3d, offset):
     self.node = node.createChild( "collision" )  # node
     r = Quaternion.to_euler(offset[3:])  * 180.0 / math.pi
     self.loader = self.node.createObject("MeshObjLoader", name='loader', filename=filepath, scale3d=concat(scale3d), translation=concat(offset[:3]), rotation=concat(r), triangulate=1 )
     self.topology = self.node.createObject('MeshTopology', name='topology', src="@loader" )
     self.dofs = self.node.createObject('MechanicalObject', name='dofs')
     self.triangles = self.node.createObject('TriangleModel', template='Vec3d', name='model')
     self.mapping = self.node.createObject('RigidMapping', name="mapping")
Exemple #5
0
 def __init__(self, node, filepath, scale3d, offset, name_suffix=''):
     global idxVisualModel
     self.node = node.createChild( "visual"+name_suffix )  # node
     r = Quaternion.to_euler(offset[3:])  * 180.0 / math.pi
     self.model = self.node.createObject('VisualModel', name="visual"+str(idxVisualModel), fileMesh=filepath,
                                         scale3d=concat(scale3d), translation=concat(offset[:3]) , rotation=concat(r),
                                         useNormals=False, updateNormals=True)
     self.mapping = self.node.createObject('RigidMapping', name="mapping")
     idxVisualModel+=1
Exemple #6
0
 def __init__(self, node, filepath, scale3d, offset, name_suffix='', generatedDir=None):
     r = Quaternion.to_euler(offset[3:]) * 180.0 / math.pi
     global idxVisualModel;
     self.node = node.createChild('visual'+name_suffix)  # node
     self.model = self.node.createObject('VisualModel', name='visual'+str(idxVisualModel), fileMesh=filepath, scale3d=concat(scale3d), translation=concat(offset[:3]), rotation=concat(r))
     if generatedDir is None:
         self.mapping = self.node.createObject('LinearMapping', template='Affine,ExtVec3f', name='mapping')
     else:
         serialization.importLinearMapping(self.node, generatedDir+"_visualmapping.json")
     idxVisualModel+=1
Exemple #7
0
 def __init__(self, node, filepath, scale3d, offset, name_suffix=''):
     self.node = node.createChild( "collision"+name_suffix )  # node
     r = Quaternion.to_euler(offset[3:])  * 180.0 / math.pi
     self.loader = SofaPython.Tools.meshLoader(self.node, filename=filepath, name='loader', scale3d=concat(scale3d), translation=concat(offset[:3]) , rotation=concat(r), triangulate=True)
     self.topology = self.node.createObject('MeshTopology', name='topology', src="@loader" )
     self.dofs = self.node.createObject('MechanicalObject', name='dofs', template="Vec3"+template_suffix )
     self.triangles = self.node.createObject('TriangleModel', name='model')
     self.mapping = self.node.createObject('RigidMapping', name="mapping")
     self.normals = None
     self.visual = None
Exemple #8
0
 def __init__(self, node, filepath, scale3d, offset, name_suffix='', generatedDir=None):
     r = Quaternion.to_euler(offset[3:]) * 180.0 / math.pi
     self.node = node.createChild('collision'+name_suffix)  # node
     self.loader = SofaPython.Tools.meshLoader(self.node, filename=filepath, name='loader', scale3d=concat(scale3d), translation=concat(offset[:3]) , rotation=concat(r), triangulate=True)
     self.topology = self.node.createObject('MeshTopology', name='topology', src='@loader')
     self.dofs = self.node.createObject('MechanicalObject', name='dofs', template='Vec3'+template_suffix)
     self.triangles = self.node.createObject('TriangleModel', name='model')
     if generatedDir is None:
         self.mapping = self.node.createObject('LinearMapping', template='Affine,Vec3'+template_suffix, name='mapping')
     else:
         serialization.importLinearMapping(self.node, generatedDir+"_collisionmapping.json")
     self.normals = None
Exemple #9
0
 def __init__(self, node, filepath, scale3d, offset):
     self.node = node.createChild("visual")  # node
     r = Quaternion.to_euler(offset[3:]) * 180.0 / math.pi
     self.model = self.node.createObject('VisualModel',
                                         template='ExtVec3f',
                                         name='model',
                                         fileMesh=filepath,
                                         scale3d=concat(scale3d),
                                         translation=concat(offset[:3]),
                                         rotation=concat(r))
     self.mapping = self.node.createObject('RigidMapping',
                                           name="mapping")
Exemple #10
0
 def loadVisualCylinder(self,
                        meshPath,
                        offset=[0, 0, 0, 0, 0, 0, 1],
                        scale=[1, 1, 1],
                        color=[1, 1, 1, 1],
                        radius=0.01,
                        **kwargs):
     r = Quaternion.to_euler(offset[3:]) * 180.0 / math.pi
     self.visual = self.node.createObject("OglCylinderModel",
                                          radius=radius,
                                          position="@topology.position",
                                          edges="@topology.edges")
     self.normals = self.visual
Exemple #11
0
 def __init__(self, node, filepath, scale3d, offset, name_suffix=''):
     global idxVisualModel
     self.node = node.createChild("visual" + name_suffix)  # node
     r = Quaternion.to_euler(offset[3:]) * 180.0 / math.pi
     self.model = self.node.createObject('VisualModel',
                                         name="visual" +
                                         str(idxVisualModel),
                                         fileMesh=filepath,
                                         scale3d=concat(scale3d),
                                         translation=concat(offset[:3]),
                                         rotation=concat(r),
                                         useNormals=False,
                                         updateNormals=True)
     self.mapping = self.node.createObject('RigidMapping',
                                           name="mapping")
     idxVisualModel += 1
Exemple #12
0
 def loadMesh(self,
              meshPath,
              offset=[0, 0, 0, 0, 0, 0, 1],
              scale=[1, 1, 1],
              triangulate=False):
     r = Quaternion.to_euler(offset[3:]) * 180.0 / math.pi
     self.meshLoader = SofaPython.Tools.meshLoader(self.node,
                                                   meshPath,
                                                   translation=concat(
                                                       offset[:3]),
                                                   rotation=concat(r),
                                                   scale3d=concat(scale),
                                                   triangulate=triangulate)
     self.topology = self.node.createObject("MeshTopology",
                                            name="topology",
                                            src="@" + self.meshLoader.name)
Exemple #13
0
 def __init__(self, node, filepath, scale3d, offset):
     self.node = node.createChild("collision")  # node
     r = Quaternion.to_euler(offset[3:]) * 180.0 / math.pi
     self.loader = self.node.createObject("MeshObjLoader",
                                          name='loader',
                                          filename=filepath,
                                          scale3d=concat(scale3d),
                                          translation=concat(
                                              offset[:3]),
                                          rotation=concat(r),
                                          triangulate=1)
     self.topology = self.node.createObject('MeshTopology',
                                            name='topology',
                                            src="@loader")
     self.dofs = self.node.createObject('MechanicalObject', name='dofs')
     self.triangles = self.node.createObject('TriangleModel',
                                             template='Vec3d',
                                             name='model')
     self.mapping = self.node.createObject('RigidMapping',
                                           name="mapping")
Exemple #14
0
 def loadVisual(self,
                meshPath,
                offset=[0, 0, 0, 0, 0, 0, 1],
                scale=[1, 1, 1],
                color=[1, 1, 1, 1],
                **kwargs):
     r = Quaternion.to_euler(offset[3:]) * 180.0 / math.pi
     self.visual = self.node.createObject("VisualModel",
                                          name="model",
                                          filename=meshPath,
                                          translation=concat(offset[:3]),
                                          rotation=concat(r),
                                          scale3d=concat(scale),
                                          color=concat(color),
                                          putOnlyTexCoords=True,
                                          computeTangents=True,
                                          **kwargs)
     # self.visual =  self.node.createObject("VisualModel", name="model", filename=meshPath, translation=concat(offset[:3]) , rotation=concat(r), scale3d=concat(scale), color=concat(color), **kwargs)
     self.visual.setColor(
         color[0], color[1], color[2], color[3]
     )  # the previous assignement fails when reloading a scene..
     self.normals = self.visual
Exemple #15
0
 def __init__(self, node, filepath, scale3d, offset, name_suffix=''):
     self.node = node.createChild("collision" + name_suffix)  # node
     r = Quaternion.to_euler(offset[3:]) * 180.0 / math.pi
     self.loader = SofaPython.Tools.meshLoader(self.node,
                                               filename=filepath,
                                               name='loader',
                                               scale3d=concat(scale3d),
                                               translation=concat(
                                                   offset[:3]),
                                               rotation=concat(r),
                                               triangulate=True)
     self.topology = self.node.createObject('MeshTopology',
                                            name='topology',
                                            src="@loader")
     self.dofs = self.node.createObject('MechanicalObject',
                                        name='dofs',
                                        template="Vec3" +
                                        template_suffix)
     self.triangles = self.node.createObject('TriangleModel',
                                             name='model')
     self.mapping = self.node.createObject('RigidMapping',
                                           name="mapping")
     self.normals = None
     self.visual = None
Exemple #16
0
 def addMeshLoader(
     self,
     meshFile,
     value,
     insideValue=None,
     closingValue=None,
     roiIndices=list(),
     roiValue=list(),
     name=None,
     offset=[0, 0, 0, 0, 0, 0, 1],
     scale=[1, 1, 1],
 ):
     mesh = Image.Mesh(value, insideValue)
     _name = name if not name is None else os.path.splitext(os.path.basename(meshFile))[0]
     mesh.mesh = SofaPython.Tools.meshLoader(
         self.node,
         meshFile,
         name="meshLoader_" + _name,
         triangulate=True,
         translation=concat(offset[:3]),
         rotation=concat(Quaternion.to_euler(offset[3:]) * 180.0 / math.pi),
         scale3d=concat(scale),
     )
     self.__addMesh(mesh, closingValue, roiIndices, roiValue, _name)
Exemple #17
0
 def addMeshLoader(self, meshFile, value, insideValue=None, closingValue=None, roiIndices=list(), roiValue=list(), name=None, offset = [0,0,0,0,0,0,1], scale=[1,1,1]):
     mesh = Image.Mesh(value, insideValue)
     _name = name if not name is None else os.path.splitext(os.path.basename(meshFile))[0]
     mesh.mesh = SofaPython.Tools.meshLoader(self.node, meshFile, name="meshLoader_"+_name, triangulate=True, translation=concat(offset[:3]) , rotation=concat(Quaternion.to_euler(offset[3:])  * 180.0 / math.pi), scale3d=concat(scale))
     self.__addMesh(mesh,closingValue,roiIndices,roiValue,_name)
Exemple #18
0
 def loadVisual(self, meshPath, offset = [0,0,0,0,0,0,1], scale=[1,1,1], color=[1,1,1,1],**kwargs):
     r = Quaternion.to_euler(offset[3:])  * 180.0 / math.pi
     self.visual =  self.node.createObject("VisualModel", name="model", filename=meshPath, translation=concat(offset[:3]) , rotation=concat(r), scale3d=concat(scale), color=concat(color), putOnlyTexCoords=True,computeTangents=True,**kwargs)
     # self.visual =  self.node.createObject("VisualModel", name="model", filename=meshPath, translation=concat(offset[:3]) , rotation=concat(r), scale3d=concat(scale), color=concat(color), **kwargs)
     self.visual.setColor(color[0],color[1],color[2],color[3]) # the previous assignement fails when reloading a scene..
     self.normals = self.visual
Exemple #19
0
 def loadMesh(self, meshPath, offset = [0,0,0,0,0,0,1], scale=[1,1,1], triangulate=False):
     r = Quaternion.to_euler(offset[3:])  * 180.0 / math.pi
     self.meshLoader = SofaPython.Tools.meshLoader(self.node, meshPath, translation=concat(offset[:3]) , rotation=concat(r), scale3d=concat(scale), triangulate=triangulate)
     self.topology = self.node.createObject("MeshTopology", name="topology", src="@"+self.meshLoader.name )
Exemple #20
0
def transformToData(scale,offset,timeOffset=0,timeScale=1,isPerspective=0):
    """ Returns a transform, formatted to sofa data given voxelsize, rigid position (offset), time and camera parameters
    """
    return concat(offset[:3])+' '+concat(quat.to_euler(offset[3:])*180./math.pi)+' '+concat(scale)+' '+str(timeOffset)+' '+str(timeScale)+' '+str(int(isPerspective))
Exemple #21
0
 def loadVisualCylinder(self, meshPath, offset = [0,0,0,0,0,0,1], scale=[1,1,1], color=[1,1,1,1],radius=0.01,**kwargs):
     r = Quaternion.to_euler(offset[3:])  * 180.0 / math.pi
     self.visual = self.node.createObject("OglCylinderModel", radius=radius, position="@topology.position", edges="@topology.edges" )
     self.normals = self.visual
 def __init__(self, node, filepath, scale3d, offset):
     self.node = node.createChild( "visual" )  # node
     r = Quaternion.to_euler(offset[3:])  * 180.0 / math.pi
     self.model = self.node.createObject('VisualModel', template='ExtVec3f', name='model', fileMesh=filepath, scale3d=concat(scale3d), translation=concat(offset[:3]) , rotation=concat(r) )
     self.mapping = self.node.createObject('RigidMapping', name="mapping")