Esempio n. 1
0
def createScene(rootNode):

    rootNode.createObject('VisualStyle', displayFlags='showVisualModels showForceFields')

    rootNode.findData('gravity').value=[0.0,0.0,-9810];
    rootNode.findData('dt').value=1

    plugins=["SofaPython","SoftRobots","ModelOrderReduction"]
    for name in plugins:
        rootNode.createObject('RequiredPlugin', name=name, printLog=False)
        
    rootNode.createObject('OglSceneFrame', style="Arrows", alignment="TopRight")

    rootNode.createObject('FreeMotionAnimationLoop')
    rootNode.createObject('GenericConstraintSolver', tolerance="1e-6", maxIterations="1000")


    modelNode = ElasticMaterialObject(
        attachedTo=rootNode,
        volumeMeshFileName=meshPath+'cylinder_real_sparse.vtu',
        # volumeMeshFileName=meshPath+'siliconeV0.vtu',
        name='modelNode',
        # rotation=[90, 0.0, 0.0],
        # translation=[0.0, 0.0, 35],
        rotation=[0.0, 0.0, 0.0],
        translation=[0.0, 0.0, 0],
        totalMass=0.5,
        withConstrain=False,
        surfaceMeshFileName=meshPath+'cylinder.STL',
        surfaceColor=[0.7, 0.7, 0.7, 0.7],
        poissonRatio=0.45,
        youngModulus=450)
    
    modelNode.createObject('GenericConstraintCorrection', solverName='solver')

    FixedBox(
            atPositions=[-15, -5, -20,  15, 25, 10],
            applyTo=modelNode,
            name="box1",   
            doVisualization=True)       
    FixedBox(
            atPositions=[-15, -5, -615, 15, 25, -585],
            applyTo=modelNode,
            name="box2",
            doVisualization=True)

    for i in range(len(actuatorsParam)):
        cable = PullingCable(
                    attachedTo=modelNode,
                    name=actuatorsParam[i]['withName'],
                    cableGeometry=actuatorsParam[i]['withCableGeometry'],
                    pullPointLocation=actuatorsParam[i]['withAPullPointLocation'],
                    valueType="displacement")

    return rootNode
Esempio n. 2
0
def createScene(rootNode):
    """Setting up a simple scene"""

    MainHeader(rootNode, gravity=[0.0, -981.0, 0.0])
    ContactHeader(rootNode, alarmDistance=5, contactDistance=1)

    Cube(rootNode, translation=[0.0, 60.0, 10.0], uniformScale=2.0)

    Floor(rootNode, translation=[0.0, -160.0, 0.0], isAStaticObject=True)

    Prostate = ElasticMaterialObject(
        rootNode,
        name="Prostate",
        volumeMeshFileName="/Users/pedro/Downloads/mac/Data/Prosta_2_2.msh",
        surfaceMeshFileName="/Users/pedro/Downloads/mac/Data/Prosta_2_2.stl",
        collisionMesh="/Users/pedro/Downloads/mac/Data/Prosta_2_2.stl",
        withConstrain=True,
        surfaceColor=[0.0, 0.70, 1.0],
        scale=[0.9, 0.9, 0.9],
        poissonRatio=0.49,
        youngModulus=500,
        translation=[10.0, 0.0, 0.0])

    # Bulbo = ElasticMaterialObject(rootNode, name="Bulbo",
    #                 volumeMeshFileName="/Users/pedro/Downloads/mac/Data/Prosta_16_16.msh",
    #                 surfaceMeshFileName="/Users/pedro/Downloads/mac/Data/Prosta_16_16.stl",
    #                 collisionMesh =	"/Users/pedro/Downloads/mac/Data/Prosta_16_16.stl",
    #                 withConstrain=True,
    #                 surfaceColor=[0.2, 0.9, 0.0],
    #                 scale=[0.9, 0.9, 0.9],
    #                 poissonRatio=0.49,
    #                 youngModulus=90000,
    #                 translation=[0.0,60.0,35.0])

    fixingBox = [0.0, 0.0, 0.0]
    BoxROICoordinates = [-5, 0, -5, 5, 1, 5]
    FixedBox(Prostate,
             atPositions=[-10.0, -1.0, -20.0, 60.0, 60.0, 5.0],
             doVisualization=True)

    # scene = Scene(rootNode, gravity=[0.0, -981.0, 0.0])
    # scene.dt = 0.025
    # scene.VisualStyle.displayFlags = "showBehavior"
    #
    # scene.Config.createObject("MeshSTLLoader", name="loader", filename="/Users/pedro/Downloads/mac/SOFA_v19.06.99_custom_MacOS_v11/plugins/SoftRobots/docs/tutorials/Tripod/details/data/mesh/blueprint.stl")
    # scene.Config.createObject("OglModel", src="@loader")
    # body = ElasticBody(scene.Modelling)
    # fix = FixingBox(scene.Modelling,
    #             body.ElasticMaterialObject,
    #             eulerRotation=[0,0,0],
    #             translation=[0.0, .0, 0.0],
    #             scale=[30., 30., 30.])
    #
    # # Changing the property of the Box ROI so that the constraint area appears on screen.
    # fix.BoxROI.drawBoxes = True
    #
    return rootNode
Esempio n. 3
0
def createBunny(Node,
                Translation=[0, 0, 0],
                ControlType='PressureConstraint',
                Name='Bunny',
                InitialValue=0.0001,
                YoungModulus=18000):

    #Bunny
    #BoxROICoordinates=[-5, -6, -5,  5, -4.5, 5] + [Translation,Translation]
    BoxROICoordinates = [
        -5 + Translation[0], -6 + Translation[1], -5 + Translation[2],
        5 + Translation[0], -4.5 + Translation[1], 5 + Translation[2]
    ]
    Bunny = ElasticMaterialObject(
        name=Name,
        attachedTo=Node,
        volumeMeshFileName=meshpath + 'Hollow_Stanford_Bunny.vtu',
        surfaceMeshFileName=meshpath + 'Hollow_Bunny_Body_Cavity.obj',
        youngModulus=YoungModulus,
        withConstrain=True,
        totalMass=0.5,
        translation=Translation)

    FixedBox(Bunny, doVisualization=True, atPositions=BoxROICoordinates)

    if ControlType == 'PressureConstraint':
        cavity = PneumaticCavity(name='Cavity',
                                 attachedAsAChildOf=Bunny,
                                 surfaceMeshFileName=meshpath +
                                 'Hollow_Bunny_Body_Cavity.obj',
                                 valueType='pressureGrowth',
                                 initialValue=InitialValue,
                                 translation=Translation)
    elif ControlType == 'VolumeConstraint':
        cavity = PneumaticCavity(name='Cavity',
                                 attachedAsAChildOf=Bunny,
                                 surfaceMeshFileName=meshpath +
                                 'Hollow_Bunny_Body_Cavity.obj',
                                 valueType='volumeGrowth',
                                 initialValue=InitialValue,
                                 translation=Translation)

    BunnyVisu = Bunny.createChild('visu')
    BunnyVisu.createObject('TriangleSetTopologyContainer', name='container')
    BunnyVisu.createObject('TriangleSetTopologyModifier')
    BunnyVisu.createObject('TriangleSetTopologyAlgorithms', template='Vec3d')
    BunnyVisu.createObject('TriangleSetGeometryAlgorithms', template='Vec3d')
    BunnyVisu.createObject('Tetra2TriangleTopologicalMapping',
                           name='Mapping',
                           input="@../container",
                           output="@container")
    BunnyVisu.createObject('OglModel',
                           template='ExtVec3f',
                           color='0.3 0.2 0.2 0.6',
                           translation=Translation)
    BunnyVisu.createObject('IdentityMapping')
    return Bunny
Esempio n. 4
0
def Bunny(Node,
          translation=[0, 0, 0],
          controlType='PressureConstraint',
          name='Bunny',
          initialValue=0.0001,
          youngModulus=18000):

    #Bunny
    #boxROICoordinates=[-5, -6, -5,  5, -4.5, 5] + [translation,translation]
    boxROICoordinates = [
        -5 + translation[0], -6 + translation[1], -5 + translation[2],
        5 + translation[0], -4.5 + translation[1], 5 + translation[2]
    ]
    Bunny = ElasticMaterialObject(
        name=name,
        attachedTo=Node,
        volumeMeshFileName=meshpath + 'Hollow_Stanford_Bunny.vtu',
        surfaceMeshFileName=meshpath + 'Hollow_Bunny_Body_Cavity.obj',
        youngModulus=youngModulus,
        withConstrain=True,
        totalMass=0.5,
        translation=translation)

    FixedBox(Bunny, doVisualization=True, atPositions=boxROICoordinates)

    if controlType == 'PressureConstraint':
        cavity = PneumaticCavity(name='Cavity',
                                 attachedAsAChildOf=Bunny,
                                 surfaceMeshFileName=meshpath +
                                 'Hollow_Bunny_Body_Cavity.obj',
                                 valueType='pressureGrowth',
                                 initialValue=initialValue,
                                 translation=translation)
    elif controlType == 'VolumeConstraint':
        cavity = PneumaticCavity(name='Cavity',
                                 attachedAsAChildOf=Bunny,
                                 surfaceMeshFileName=meshpath +
                                 'Hollow_Bunny_Body_Cavity.obj',
                                 valueType='volumeGrowth',
                                 initialValue=initialValue,
                                 translation=translation)

    BunnyVisu = Bunny.addChild('visu')
    BunnyVisu.addObject('TriangleSetTopologyContainer', name='container')
    BunnyVisu.addObject('TriangleSetTopologyModifier')
    BunnyVisu.addObject('Tetra2TriangleTopologicalMapping',
                        name='Mapping',
                        input="@../container",
                        output="@container")
    BunnyVisu.addObject('OglModel',
                        color=[0.3, 0.2, 0.2, 0.6],
                        translation=translation)
    BunnyVisu.addObject('IdentityMapping')
    return Bunny
Esempio n. 5
0
def Finger(parentNode=None,
           name="Finger",
           rotation=[0.0, 0.0, 0.0],
           translation=[0.0, 0.0, 0.0],
           fixingBox=[-5.0, 0.0, 0.0, 10.0, 15.0, 20.0],
           pullPointLocation=[0.0, 0.0, 0.0]):

    finger = Node(parentNode, name)
    eobject = ElasticMaterialObject(finger,
                                    volumeMeshFileName="data/mesh/finger.vtk",
                                    poissonRatio=0.3,
                                    youngModulus=18000,
                                    totalMass=0.5,
                                    surfaceColor=[0.0, 0.8, 0.7],
                                    surfaceMeshFileName="data/mesh/finger.stl",
                                    rotation=rotation,
                                    translation=translation)

    FixedBox(eobject.node, atPositions=fixingBox, doVisualization=True)

    cable = PullingCable(
        eobject.node,
        "PullingCable",
        pullPointLocation=pullPointLocation,
        rotation=rotation,
        translation=translation,
        cableGeometry=loadPointListFromFile("data/mesh/cable.json"))

    FingerController(eobject.node, cable)

    CollisionMesh(eobject.node,
                  name="CollisionMesh",
                  surfaceMeshFileName="data/mesh/finger.stl",
                  rotation=rotation,
                  translation=translation,
                  collisionGroup=[1, 2])

    CollisionMesh(eobject.node,
                  name="CollisionMeshAuto1",
                  surfaceMeshFileName="data/mesh/fingerCollision_part1.stl",
                  rotation=rotation,
                  translation=translation,
                  collisionGroup=[1])

    CollisionMesh(eobject.node,
                  name="CollisionMeshAuto2",
                  surfaceMeshFileName="data/mesh/fingerCollision_part2.stl",
                  rotation=rotation,
                  translation=translation,
                  collisionGroup=[2])

    return finger
Esempio n. 6
0
def createScene(rootNode):
    from stlib.scene import MainHeader
    from stlib.physics.deformable import ElasticMaterialObject
    from stlib.physics.constraints import FixedBox

    MainHeader(rootNode)
    target = ElasticMaterialObject(fromVolumeMesh="mesh/liver.msh",
                                   withTotalMass=0.5,
                                   attachedTo=rootNode)

    FixedBox(atPositions=[-4, 0, 0, 5, 5, 4],
             applyTo=target,
             withVisualization=True)
Esempio n. 7
0
def createScene(rootNode):
    from stlib.scene import MainHeader
    from stlib.physics.deformable import ElasticMaterialObject
    from stlib.physics.constraints import FixedBox

    MainHeader(rootNode)
    target = ElasticMaterialObject(volumeMeshFileName="mesh/liver.msh",
                                   totalMass=0.5,
                                   attachedTo=rootNode)

    FixedBox(atPositions=[-4, 0, 0, 5, 5, 4], applyTo=target,
             doVisualization=True)

    CollisionMesh(surfaceMeshFileName="mesh/liver.obj", attachedTo=target)
Esempio n. 8
0
def createScene(rootNode):
    """Setting up a simple scene"""
    
    MainHeader(rootNode, gravity = [0.0, -981.0, 0.0])
    ContactHeader(rootNode, alarmDistance = 5, contactDistance = 1)
     
    #cube(rootNode, translation = [10.1,60.0,10.0], uniformScale = 1.0)
    
    Floor(rootNode, translation = [0.0,-160.0,0.0], isAStaticObject = True)
    
    
    Prostate = ElasticMaterialObject(rootNode, name="Prostate",
                        volumeMeshFileName="/Users/pedro/Downloads/mac/Data/Prosta_2_2.msh",
                        surfaceMeshFileName="/Users/pedro/Downloads/mac/Data/Prosta_2_2.stl",                     
                        collisionMesh =	"/Users/pedro/Downloads/mac/Data/Prosta_2_2.stl",
                        withConstrain=True,
                        surfaceColor=[0.0, 0.70, 1.0],
                        scale=[0.9, 0.9, 0.9],
                        poissonRatio=0.49,
                        youngModulus=500,
                        translation=[10.0,0.0,0.0])
    
    Bulbo = ElasticMaterialObject(rootNode, name="Bulbo",
                    volumeMeshFileName="/Users/pedro/Downloads/mac/Data/needle_s.msh",
                    surfaceMeshFileName="/Users/pedro/Downloads/mac/Data/needle_s.stl",                     
                    collisionMesh =	"/Users/pedro/Downloads/mac/Data/needle_s.stl",
                    withConstrain=True,
                    surfaceColor=[0.2, 0.9, 0.0],
                    scale=[0.9, 0.9, 0.9],
                    poissonRatio=0.33,
                    youngModulus=100000,
                    translation=[0.0,160.0,60.0],
                    rotation=[90.0,0.0,0.0])
    
    fixingBox=[0.0,0.0,0.0]
    BoxROICoordinates=[-5, 0, -5,  5, 1, 5]
    FixedBox(Prostate, atPositions=[-10.0,-1.0,-20.0,60.0,60.0,5.0], doVisualization=True)
    
    # fixingBox=[0.0,0.0,0.0]
    # BoxROICoordinates=[-5, 0, -5,  5, 1, 5]
    # PartiallyFixedBox(attachedTo=Bulbo, fixedAxis=[1, 0,1], box=[-10.0,140.0,-20.0,10.0,170.0,25.0], drawBoxes = True )
    
    return rootNode
Esempio n. 9
0
def createScene(rootNode):

	rootNode = MainHeader(	rootNode, 
							plugins=["SofaPython","SoftRobots","ModelOrderReduction"],
							dt=1,
							gravity=[0.0,0.0,-9810])

	modelNode = ElasticMaterialObject(
		attachedTo=rootNode,
		volumeMeshFileName=meshPath+'siliconeV0.vtu',
		name='modelNode',
        rotation=[90, 0.0, 0.0],
        translation=[0.0, 0.0, 35],
		totalMass=0.5,
		withConstrain=False,
		# surfaceMeshFileName=meshPath+'surface.stl',
		# surfaceColor=[0.7, 0.7, 0.7, 0.7],
		poissonRatio=0.45,
		youngModulus=450)
	
	modelNode.createObject('GenericConstraintCorrection', solverName='Solver')
	# modelNode.createObject('WriteState', filename="init_myDiamondQuiteFine.vtu.state", period='0.1',writeX="0", writeX0="1", writeV="0") 

	FixedBox(
		atPositions=[-15, -15, -40,  15, 15, 10],
		applyTo=modelNode,
		doVisualization=True) 		

	for i in range(len(actuatorsParam)):
		cable = PullingCable(
					attachedTo=modelNode,
					name=actuatorsParam[i]['withName'],
					cableGeometry=actuatorsParam[i]['withCableGeometry'],
					pullPointLocation=actuatorsParam[i]['withAPullPointLocation'],
					valueType="displacement")

	return rootNode 
def createScene(rootNode):

    rootNode.createObject('VisualStyle',
                          displayFlags='showVisualModels showForceFields')

    rootNode.findData('gravity').value = [0.0, 0.0, -9810]
    rootNode.findData('dt').value = 0.1

    plugins = ["SofaPython", "SoftRobots", "ModelOrderReduction"]
    for name in plugins:
        rootNode.createObject('RequiredPlugin', name=name, printLog=False)

    rootNode.createObject('OglSceneFrame',
                          style="Arrows",
                          alignment="TopRight")

    rootNode.createObject('FreeMotionAnimationLoop')
    rootNode.createObject('GenericConstraintSolver',
                          tolerance="1e-6",
                          maxIterations="1000")

    modelNode = rootNode.createChild('modelNode')
    modelNode.createObject('EulerImplicitSolver',
                           rayleighStiffness='0.1',
                           rayleighMass='0.1')
    modelNode.createObject('SparseLDLSolver', name="solver")
    modelNode.createObject('MeshVTKLoader',
                           name="loader",
                           filename=meshPath + 'siliconeV0.vtu',
                           rotation=[90, 0, 0],
                           translation=[0, 0, 35])
    modelNode.createObject('TetrahedronSetTopologyContainer', src="@loader")
    modelNode.createObject('MechanicalObject',
                           name="tetras",
                           template="Vec3d",
                           showIndices="false",
                           showIndicesScale="4e-5")
    modelNode.createObject('UniformMass', totalMass="0.5")
    poissonRatio = 0.45
    youngModulus = 450
    mu_ = youngModulus / (2 * (1 + poissonRatio))
    lambda_ = youngModulus * poissonRatio / ((1 - 2 * poissonRatio) *
                                             (1 + poissonRatio))
    k0_ = youngModulus / (3 * (1 - 2 * poissonRatio))
    modelNode.createObject('TetrahedronHyperelasticityFEMForceField',
                           materialName="StVenantKirchhoff",
                           ParameterSet=str(mu_) + " " + str(lambda_),
                           AnisotropyDirections="",
                           printLog=False)
    #modelNode.createObject('TetrahedronHyperelasticityFEMForceField',materialName="NeoHookean", ParameterSet=str(mu_) + " " + str(k0_), AnisotropyDirections="")

    modelNode.createObject('GenericConstraintCorrection', solverName='solver')

    FixedBox(atPositions=[-15, -15, -40, 15, 15, 10],
             applyTo=modelNode,
             doVisualization=True)

    for i in range(len(actuatorsParam)):
        cable = PullingCable(
            attachedTo=modelNode,
            name=actuatorsParam[i]['withName'],
            cableGeometry=actuatorsParam[i]['withCableGeometry'],
            pullPointLocation=actuatorsParam[i]['withAPullPointLocation'],
            valueType="displacement")

    return rootNode
Esempio n. 11
0
def Finger(parentNode=None,
           name="Finger",
           rotation=[0.0, 0.0, 0.0],
           translation=[0.0, 0.0, 0.0],
           fixingBox=[0.0, 0.0, 0.0],
           pullPointLocation=[0.0, 0.0, 0.0],
           youngModulus=18000,
           valueType='position'):

    finger = Node(parentNode, name)
    eobject = ElasticMaterialObject(
        finger,
        volumeMeshFileName=os.path.join(
            templatepath,
            "mesh/finger.vtk"),  #MISK need to change the relative file
        poissonRatio=0.3,
        youngModulus=youngModulus,
        totalMass=0.5,
        surfaceColor=[0.0, 0.8, 0.65],
        surfaceMeshFileName=os.path.join(templatepath, "mesh/finger.stl"),
        rotation=rotation,
        translation=translation)

    FixedBox(eobject, atPositions=fixingBox, doVisualization=True)

    cable = PullingCable(eobject,
                         "PullingCable",
                         pullPointLocation=pullPointLocation,
                         rotation=rotation,
                         translation=translation,
                         cableGeometry=loadPointListFromFile(
                             os.path.join(templatepath, "mesh/cable.json")),
                         valueType=valueType)

    #Eulalie.C (21/09/18): this feature does not work, either fix it or remove this comment before SoftRobots v19
    #FingerController(eobject, cable, valueType) #MISK may change to vary variation based on value type

    CollisionMesh(eobject,
                  name="CollisionMesh",
                  surfaceMeshFileName=os.path.join(templatepath,
                                                   "mesh/finger.stl"),
                  rotation=rotation,
                  translation=translation,
                  collisionGroup=[1, 2])

    CollisionMesh(eobject,
                  name="CollisionMeshAuto1",
                  surfaceMeshFileName=os.path.join(
                      templatepath, "mesh/fingerCollision_part1.stl"),
                  rotation=rotation,
                  translation=translation,
                  collisionGroup=[1])

    CollisionMesh(eobject,
                  name="CollisionMeshAuto2",
                  surfaceMeshFileName=os.path.join(
                      templatepath, "mesh/fingerCollision_part2.stl"),
                  rotation=rotation,
                  translation=translation,
                  collisionGroup=[2])

    return finger