-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy path__geometry__.py
More file actions
78 lines (62 loc) · 3.04 KB
/
__geometry__.py
File metadata and controls
78 lines (62 loc) · 3.04 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
from stlib.core.basePrefab import BasePrefab
from stlib.core.baseParameters import BaseParameters, Optional, Any
from splib.topology.dynamic import addDynamicTopology
from splib.topology.static import addStaticTopology
from splib.core.enum_types import ElementType
from splib.core.utils import DEFAULT_VALUE
from Sofa.Core import Object
import numpy as np
class Geometry(BasePrefab):...
class InternalDataProvider(BaseParameters):
position : Any = None
# Topology information
edges : Any = DEFAULT_VALUE
triangles : Any = DEFAULT_VALUE
quads : Any = DEFAULT_VALUE
tetrahedra : Any = DEFAULT_VALUE
hexahedra : Any = DEFAULT_VALUE
@classmethod
def generateAttribute(self, parent : Geometry):
pass
class GeometryParameters(BaseParameters):
mytype : type = BaseParameters
name : str = "Geometry"
# Type of the highest degree element
elementType : Optional[ElementType] = None
data : Optional[InternalDataProvider] = None
dynamicTopology : bool = False
class Geometry(BasePrefab):
# container : Object # This should be more specialized into the right SOFA type
# modifier : Optional[Object]
parameters : GeometryParameters
def __init__(self, parameters: GeometryParameters):
BasePrefab.__init__(self, parameters)
def init(self):
# Generate attribute (positions, edges, triangles, quads, tetrahedra, hexahedra) from the internal data provider
if isinstance(self.parameters.data, InternalDataProvider) :
self.parameters.data.generateAttribute(self)
if self.parameters.dynamicTopology :
if self.parameters.elementType is not None :
addDynamicTopology(self,
elementType=self.parameters.elementType,
container = {
"position": self.parameters.data.position,
"edges": self.parameters.data.edges,
"triangles": self.parameters.data.triangles,
"quads": self.parameters.data.quads,
"tetrahedra": self.parameters.data.tetrahedra,
"hexahedra": self.parameters.data.hexahedra
})
else:
raise ValueError
else:
addStaticTopology(self,
container =
{
"position": self.parameters.data.position,
"edges": self.parameters.data.edges,
"triangles": self.parameters.data.triangles,
"quads": self.parameters.data.quads,
"tetrahedra": self.parameters.data.tetrahedra,
"hexahedra": self.parameters.data.hexahedra
})