-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathreduced_caduceusNG.py
More file actions
193 lines (157 loc) · 11.6 KB
/
Copy pathreduced_caduceusNG.py
File metadata and controls
193 lines (157 loc) · 11.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# -*- coding: utf-8 -*-
import os
import Sofa
from numpy import add,subtract,multiply
try:
from splib3.numerics import *
except:
raise ImportError("ModelOrderReduction plugin depend on SPLIB"\
+"Please install it : https://github.com/SofaDefrost/STLIB")
path = os.path.dirname(os.path.abspath(__file__))
pathMesh = path + "/.."
def TRSinOrigin(positions,modelPosition,translation,rotation,scale=[1.0,1.0,1.0]):
posOrigin = subtract(positions , modelPosition)
if any(isinstance(el, list) for el in positions):
posOriginTRS = transformPositions(posOrigin,translation,eulerRotation=rotation,scale=scale)
else:
posOriginTRS = transformPosition(posOrigin,TRS_to_matrix(translation,eulerRotation=rotation,scale=scale))
return add(posOriginTRS,modelPosition).tolist()
def newBox(positions,modelPosition,translation,rotation,offset,scale=[1.0,1.0,1.0]):
pos = TRSinOrigin(positions,modelPosition,translation,rotation,scale)
offset =transformPositions([offset],eulerRotation=rotation,scale=scale)[0]
return add(pos,offset).tolist()
def Reduced_test(
attachedTo=None,
name="Reduced_test",
rotation=[0.0, 0.0, 0.0],
translation=[0.0, 0.0, 0.0],
scale=[1.0, 1.0, 1.0],
surfaceMeshFileName=False,
surfaceColor=[1.0, 1.0, 1.0],
nbrOfModes=8,
hyperReduction=True):
"""
Object with an elastic deformation law.
+---------------------+-----------+-------------------------------------------------------------------------------------------------+
| argument | type | definition |
+=====================+===========+=================================================================================================+
| attachedTo | Sofa.Node | Where the node is created; |
+---------------------+-----------+-------------------------------------------------------------------------------------------------+
| name | str | name of the Sofa.Node it will |
+---------------------+-----------+-------------------------------------------------------------------------------------------------+
| rotation | vec3f | Apply a 3D rotation to the object in Euler angles. |
+---------------------+-----------+-------------------------------------------------------------------------------------------------+
| translation | vec3f | Apply a 3D translation to the object. |
+---------------------+-----------+-------------------------------------------------------------------------------------------------+
| scale | vec3f | Apply a 3D scale to the object. |
+---------------------+-----------+-------------------------------------------------------------------------------------------------+
| surfaceMeshFileName | str | Filepath to a surface mesh (STL, OBJ). If missing there is no visual properties to this object. |
+---------------------+-----------+-------------------------------------------------------------------------------------------------+
| surfaceColor | vec3f | The default color used for the rendering of the object. |
+---------------------+-----------+-------------------------------------------------------------------------------------------------+
| nbrOfModes | int | Number of modes we want our reduced model to work with |
+---------------------+-----------+-------------------------------------------------------------------------------------------------+
| hyperReduction | Bool | Controlled if we have the simple reduction or the hyper-reduction |
+---------------------+-----------+-------------------------------------------------------------------------------------------------+
"""
modelRoot = attachedTo.addChild(name)
Snake_MOR = modelRoot.addChild('Snake_MOR')
Snake_MOR.addObject('EulerImplicitIntegrationScheme' , rayleighStiffness = '0.1', rayleighMass = '0.1')
Snake_MOR.addObject('SparseLDLSolver' , name = 'preconditioner')
Snake_MOR.addObject('GenericConstraintCorrection' , linearSolver = '@preconditioner')
Snake_MOR.addObject('MechanicalObject' , template = 'Vec1d', position = [0]*nbrOfModes)
Snake = Snake_MOR.addChild('Snake')
Snake.addObject('MeshVTKLoader' , name = 'loader', filename = pathMesh + r'/mesh/snake0.vtu', rotation = add(rotation,[-90, 0, 0]), translation = add(translation,[0, 5, 0]), scale3d = multiply(scale,[1.0, 1.0, 1.0]))
Snake.addObject('TetrahedronSetTopologyContainer' , src = '@loader')
Snake.addObject('MechanicalObject')
Snake.addObject('UniformMass' , totalMass = '1.0')
Snake.addObject('HyperReducedTetrahedronFEMForceField' , name = 'reducedFF_Snake_0', youngModulus = '10000.0', poissonRatio = '0.4', method = 'large', nbModes = nbrOfModes, performECSW = hyperReduction, modesPath = path + r'/data/modes.txt', RIDPath = path + r'/data/reducedFF_Snake_0_RID.txt', weightsPath = path + r'/data/reducedFF_Snake_0_weight.txt')
Snake.addObject('ModelOrderReductionMapping' , input = '@../MechanicalObject', modesPath = path + r'/data/modes.txt', output = '@./MechanicalObject')
collis = Snake.addChild('collis')
collis.addObject('MeshOBJLoader' , name = 'loader', filename = pathMesh + r'/mesh/meca_snake_900tri.obj', translation = add(translation,[0, 5, 0]), rotation = add(rotation,[0.0, 0.0, 0.0]), scale3d = multiply(scale,[1.0, 1.0, 1.0]))
collis.addObject('MeshTopology' , src = '@loader', name = 'topo')
collis.addObject('MechanicalObject' , name = 'CollisModel')
collis.addObject('TriangleCollisionModel' , selfCollision = False)
collis.addObject('LineCollisionModel' , selfCollision = False)
collis.addObject('PointCollisionModel' , selfCollision = False)
collis.addObject('BarycentricMapping')
VisuBody = Snake.addChild('VisuBody')
VisuBody.addObject('MeshOBJLoader' , name = 'loader', filename = pathMesh + r'/mesh/snake_body.obj', translation = add(translation,[0.0, 0.0, 0.0]), rotation = add(rotation,[0.0, 0.0, 0.0]), scale3d = multiply(scale,[1.0, 1.0, 1.0]))
VisuBody.addObject('OglModel' , name = 'VisualBody', src = '@loader', texturename = 'textures/snakeColorMap.png', color = [1, 1, 1, 0.6], translation = [0, 5, 0])
VisuBody.addObject('BarycentricMapping')
VisuCornea = Snake.addChild('VisuCornea')
VisuCornea.addObject('MeshOBJLoader' , name = 'loader', filename = pathMesh + r'/mesh/snake_cornea.obj', translation = add(translation,[0.0, 0.0, 0.0]), rotation = add(rotation,[0.0, 0.0, 0.0]), scale3d = multiply(scale,[1.0, 1.0, 1.0]))
VisuCornea.addObject('OglModel' , name = 'VisuCornea', src = '@loader', translation = [0, 5, 0])
VisuCornea.addObject('BarycentricMapping')
VisualEye = Snake.addChild('VisualEye')
VisualEye.addObject('MeshOBJLoader' , name = 'loader', filename = pathMesh + r'/mesh/snake_yellowEye.obj', translation = add(translation,[0.0, 0.0, 0.0]), rotation = add(rotation,[0.0, 0.0, 0.0]), scale3d = multiply(scale,[1.0, 1.0, 1.0]))
VisualEye.addObject('OglModel' , name = 'VisualEye', src = '@loader', translation = [0, 5, 0])
VisualEye.addObject('BarycentricMapping')
base = modelRoot.addChild("base")
stick = base.addChild("stick")
stick.addObject('MeshOBJLoader',name="loader", filename="mesh/collision_batons.obj")
stick.addObject('MeshTopology', src='@loader', name='topo')
stick.addObject('MechanicalObject', name='stickCollisModel')
stick.addObject('LineCollisionModel',simulated="false", moving="false")
stick.addObject('PointCollisionModel',simulated="false", moving="false")
blobs = base.addChild("blobs")
blobs.addObject('MeshOBJLoader',name="loader", filename="mesh/collision_boules_V3.obj")
blobs.addObject('MeshTopology', src='@loader', name='topo')
blobs.addObject('MechanicalObject', name='blobsCollisModel')
blobs.addObject('TriangleCollisionModel',simulated="false", moving="false")
blobs.addObject('LineCollisionModel',simulated="false", moving="false")
blobs.addObject('PointCollisionModel',simulated="false", moving="false")
foot = base.addChild("foot")
foot.addObject('MeshOBJLoader',name="loader", filename="mesh/collision_pied.obj")
foot.addObject('MeshTopology', src='@loader', name='topo')
foot.addObject('MechanicalObject', name='footCollisModel')
foot.addObject('TriangleCollisionModel',simulated="false", moving="false")
foot.addObject('LineCollisionModel',simulated="false", moving="false")
foot.addObject('PointCollisionModel',simulated="false", moving="false")
visu = base.addChild("visu")
visu.addObject('MeshOBJLoader', name="SOFA_pod", filename="mesh/SOFA_pod.obj", handleSeams="1" )
visu.addObject('OglModel' , src = '@SOFA_pod', name = 'VisuPOD',color=[1,69.0/255.0,0])
return Snake
# STLIB IMPORT
from stlib3.scene import MainHeader
def createScene(rootNode):
surfaceMeshFileName = False
MainHeader(rootNode,plugins=["ModelOrderReduction"],
dt=0.02,
gravity=[0.0, -981.0, 0.0])
rootNode.VisualStyle.displayFlags="showForceFields"
rootNode.addObject('FreeMotionAnimationLoop')
rootNode.addObject('BlockGaussSeidelConstraintSolver', printLog='0', tolerance="1e-6", maxIterations="500")
rootNode.addObject('CollisionPipeline', verbose="0")
rootNode.addObject('BruteForceBroadPhase', name="N2")
rootNode.addObject('BVHNarrowPhase')
rootNode.addObject('CollisionResponse', response="FrictionContactConstraint", responseParams="mu=0.7")
rootNode.addObject('LocalMinDistance', name="Proximity", alarmDistance="2.5", contactDistance="0.1", angleCone="0.05")
Reduced_test(rootNode,
name="Reduced_test",
surfaceMeshFileName=surfaceMeshFileName)
# translate = 300
# rotationBlue = 60.0
# rotationWhite = 80
# rotationRed = 70
# for i in range(3):
# Reduced_test(rootNode,
# name="Reduced_test_blue_"+str(i),
# rotation=[rotationBlue*i, 0.0, 0.0],
# translation=[i*translate, 0.0, 0.0],
# surfaceColor=[0.0, 0.0, 1, 0.5],
# surfaceMeshFileName=surfaceMeshFileName)
# for i in range(3):
# Reduced_test(rootNode,
# name="Reduced_test_white_"+str(i),
# rotation=[0.0, rotationWhite*i, 0.0],
# translation=[i*translate, translate, -translate],
# surfaceColor=[0.5, 0.5, 0.5, 0.5],
# surfaceMeshFileName=surfaceMeshFileName)
# for i in range(3):
# Reduced_test(rootNode,
# name="Reduced_test_red_"+str(i),
# rotation=[0.0, 0.0, i*rotationRed],
# translation=[i*translate, 2*translate, -2*translate],
# surfaceColor=[1, 0.0, 0.0, 0.5],
# surfaceMeshFileName=surfaceMeshFileName)