-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
80 lines (64 loc) · 2.06 KB
/
config.py
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
import toml
import sys
def getRequired():
required = """
[Simulation]
CPUMultithreading=true
GUI=true
ROS=false
friction=0.0
[Scene]
sideViewSize=[750, 450]
[EndoscopeWagons]
number=1
position=[[-600,-1000,0]]
translation=[[0,0,0]]
height=[0]
inclination=[0]
endoscopeTranslation=[0]
endoscopeRotation=[0]
instrumentsHead=["gripper","gripper"] # options are "gripper" or "hook"
hysteresis=[0, 0, 0, 0] # in mm, cables' play
# hysteresis: [up/down flexion endoscope,
# left/right flexion endoscope,
# flexion left instrument,
# flexion right instrument]
"""
return required
def getDefault():
default = """
[Item]
number=1
position=[[0,0,0]]
rotation=[[0,0,0]]
scale=[[1,1,1]]
density=[7.5e-6]
color=[[1,1,1,1]]
withSolver=false
withCollision=false
collisionGroup=1
"""
return default
def loadConfig():
configFilename = 'configs/default.toml'
if len(sys.argv[1:]) == 0:
print('\033[93m' + '\033[1m' + "scene.py/config.py/loadConfig():" + '\033[0m')
print('\033[93m' + " You can provide a toml config file from the configs directory. " + '\033[0m')
print('\033[93m' + " ex: runSofa scene.py --argv configs/scenario1.toml" + '\033[0m')
print('\033[93m' + " If none is provided the default configuration is being used." + '\033[0m')
print()
else:
configFilename = sys.argv[1:][0]
requiredConfig = toml.loads(getRequired())
config = toml.load(configFilename)
for objectKey in requiredConfig:
if objectKey in config:
for key in requiredConfig[objectKey]:
if key not in config[objectKey]:
config[objectKey][key] = requiredConfig[objectKey][key]
else:
config[objectKey] = requiredConfig[objectKey]
print('\033[92m' + "Current simulation config:" + '\033[0m')
print(toml.dumps(config["Simulation"]))
print()
return config