-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDigitalTwin.py
98 lines (69 loc) · 3.15 KB
/
DigitalTwin.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import Sofa
import SofaCaribou
import SofaRuntime
import Sofa.Gui
import os, sys
dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'src')
sys.path.append(os.path.abspath(dir))
# Source code importation
from vessel import VGraph
from BaseDigitalTwin import BaseDigitalTwin
# Solvers, parenchyma, vessels and mapping parameters included in the digitaltwin dictionnary
from parameters import digitaltwin
class ControlFrame(Sofa.Core.Controller, BaseDigitalTwin):
def __init__(self, node):
super().__init__(self)
self.root = self.CreateGraph(node)
def CreateGraph(self, node):
node = self.required(node)
# Solver
node = self.addSolver(node, digitaltwin['solver'])
# Add parenchyma
node = self.addParenchyma(node, digitaltwin['parenchyma'])
# Add vessels
node = self.addVessels(node, digitaltwin['vessels'])
# Structuring centerlines into a list of polylines
points = self.getSkeletonData(digitaltwin['vessels']['skeleton_output'])
# Creating the Graph data structure
vessel = VGraph(points,digitaltwin['vessels']['sampling_rate'])
graph = vessel.graph
# Display the Vessels graph data structure
print("\n")
print("============== The Graph =================")
print(graph)
print("=========== End of the Graph =============")
print("\n")
# Sofa graph node
vaisseau = node.getChild("vessels")
graph_node = vaisseau.addChild('Graphe_node')
# Modeling vessels with beams
graph_node = self.VesselMechanicalModeling(graph_node, vessel, digitaltwin['vessels'], bc=False)
# Display somme infos about the Vessels Graph
print('Total number of branch ', len(graph))
print("The sampling rate is: ", digitaltwin['vessels']['sampling_rate'])
# Coupling Beams
graph_node = self.VesselMechanicalCoupling(graph_node, vessel, digitaltwin['vessels'])
# Mapping between the Parenchyma and Vessels: BeamRigid <-> BeamVec <-> Parenchyma
node = self.LiverToVesselMapping(node, vessel, digitaltwin['parenchyma'], digitaltwin['vessels'], digitaltwin['mapping'])
def createScene(node):
node.addObject(ControlFrame(node))
def main():
SofaRuntime.importPlugin("SofaOpenglVisual")
SofaRuntime.importPlugin("SofaImplicitOdeSolver")
SofaRuntime.importPlugin("SofaLoader")
root = Sofa.Core.Node("root")
createScene(root)
Sofa.Simulation.init(root)
Sofa.Gui.GUIManager.Init("Scene", "qglviewer")
Sofa.Gui.GUIManager.createGUI(root, __file__)
Sofa.Gui.GUIManager.SetDimension(1080, 1080)
Sofa.Gui.GUIManager.MainLoop(root)
Sofa.Gui.GUIManager.closeGUI(root, __file__)
Sofa.Gui.GUIManager.MainLoop(root)
Sofa.Gui.GUIManager.closeGUI()
if __name__ == '__main__':
# Storing the centeralines in the given text file
baseDT = BaseDigitalTwin()
baseDT.get_centerlines(digitaltwin['vessels']['meshFile'], digitaltwin['vessels']['skeleton_output'])
# Mechanical modeling and coupling of the vessels
main()