|
6 | 6 |
|
7 | 7 | import Sofa |
8 | 8 | from Sofa.Core import Node |
9 | | -from functools import partial |
10 | 9 |
|
11 | 10 |
|
12 | 11 | class ExtractInternalDataProvider(InternalDataProvider): |
| 12 | + destinationType : ElementType |
| 13 | + sourceType : ElementType |
| 14 | + sourceName : str |
13 | 15 |
|
14 | | - def __init__(self): |
15 | | - super().__init__() |
| 16 | + def __init__(self, destinationType : ElementType, sourceType : ElementType, sourceName : str): |
| 17 | + self.destinationType = destinationType |
| 18 | + self.sourceType = sourceType |
| 19 | + self.sourceName = sourceName |
16 | 20 |
|
17 | | - def generateAttribute(self, parent : Geometry): |
18 | | - self.position = parent.parents[0].parents[0].getChild("Geometry").container.position.linkpath |
| 21 | + def __post_init__(self): |
| 22 | + if(not (self.sourceType == ElementType.TETRAHEDRA and self.destinationType == ElementType.TRIANGLES) |
| 23 | + and not (self.sourceType == ElementType.HEXAHEDRA and self.destinationType == ElementType.QUADS) ): |
| 24 | + raise ValueError("Only configuration possible are 'Tetrahedra to Triangles' and 'Hexahedra to Quads'") |
19 | 25 |
|
| 26 | + InternalDataProvider.__init__(self) |
| 27 | + |
| 28 | + def generateAttribute(self, parent : Geometry): |
| 29 | + node = parent.addChild("ExtractedGeometry") |
20 | 30 |
|
21 | | -def extractGeometry(sourceType : ElementType, parent : Geometry): |
22 | | - #TODO: Specify somewhere in the doc that this should only be used for mapped topologies that extract parent topology surface |
23 | | - # fromLink = parent.parents[0].parents[0].getChild(self.SourceName).container.linkpath |
24 | | - # TODO: the line above cannot work if the nodes and objects are not added to the graph prior the end of __init__() call |
25 | | - # !!! also, on a fail, nothing is added to the graph, which makes things harder to debug |
26 | | - # !!! also, does not work because of the function canCreate(), which checks the input (not yet created?) |
27 | | - # this is all related |
28 | | - fromLink = parent.parents[0].parents[0].getChild("Geometry").container.linkpath # TODO: can we do better than this? |
29 | | - if sourceType == ElementType.TETRAHEDRA: |
30 | | - parent.addObject("Tetra2TriangleTopologicalMapping", input=fromLink, output=parent.container.linkpath) |
31 | | - elif sourceType == ElementType.HEXAHEDRA: |
32 | | - parent.addObject("Hexa2QuadTopologicalMapping", input=fromLink, output=parent.container.linkpath) |
33 | | - else: |
34 | | - Sofa.msg_error("[stlib/geometry/exctrat.py]", "Element type: " + str(sourceType) + " not supported.") |
| 31 | + #TODO: Specify somewhere in the doc that this should only be used for mapped topologies that extract parent topology surface |
| 32 | + # fromLink = parent.parents[0].parents[0].getChild(self.SourceName).container.linkpath |
| 33 | + # TODO: the line above cannot work if the nodes and objects are not added to the graph prior the end of __init__() call |
| 34 | + # !!! also, on a fail, nothing is added to the graph, which makes things harder to debug |
| 35 | + # !!! also, does not work because of the function canCreate(), which checks the input (not yet created?) |
| 36 | + # this is all related |
| 37 | + fromLink = "@../../../Geometry/container" # TODO: can we do better than this? |
| 38 | + addDynamicTopology(node, elementType=self.destinationType, container={"position" : fromLink + ".position"}) |
| 39 | + if self.sourceType == ElementType.TETRAHEDRA: |
| 40 | + node.addObject("Tetra2TriangleTopologicalMapping", input=fromLink, output=node.container.linkpath) |
| 41 | + elif self.sourceType == ElementType.HEXAHEDRA: |
| 42 | + node.addObject("Hexa2QuadTopologicalMapping", input=fromLink, output=node.container.linkpath) |
| 43 | + else: |
| 44 | + Sofa.msg_error("[stlib/geometry/exctrat.py]", "Element type: " + str(self.sourceType) + " not supported.") |
35 | 45 |
|
| 46 | + self.position = node.container.position.linkpath |
| 47 | + if node.container.findData("edges") is not None: |
| 48 | + self.edges = node.container.edges.linkpath |
| 49 | + if node.container.findData("triangles") is not None: |
| 50 | + self.triangles = node.container.triangles.linkpath |
| 51 | + if node.container.findData("quads") is not None: |
| 52 | + self.quads = node.container.quads.linkpath |
| 53 | + if node.container.findData("hexahedra") is not None: |
| 54 | + self.hexahedra = node.container.hexahedra.linkpath |
| 55 | + if node.container.findData("tetras") is not None: |
| 56 | + self.tetrahedra = node.container.tetras.linkpath |
36 | 57 |
|
37 | 58 |
|
38 | 59 |
|
39 | 60 | class ExtractParameters(GeometryParameters): |
40 | | - def __init__(self, |
41 | | - sourceParameters : GeometryParameters, |
42 | | - destinationType : ElementType, |
43 | | - dynamicTopology : bool = False): |
| 61 | + def __init__(self, |
| 62 | + sourceParameters : GeometryParameters, |
| 63 | + destinationType : ElementType,): |
44 | 64 | GeometryParameters.__init__(self, |
45 | | - data = ExtractInternalDataProvider(), |
46 | | - dynamicTopology = dynamicTopology, |
| 65 | + data = ExtractInternalDataProvider(destinationType = destinationType, |
| 66 | + sourceType = sourceParameters.elementType, |
| 67 | + sourceName = sourceParameters.name), |
| 68 | + dynamicTopology = True, |
47 | 69 | elementType = destinationType) |
48 | | - |
49 | | - self.postInitExec = partial(extractGeometry, sourceParameters.elementType) |
50 | | - |
51 | | - if(not (sourceParameters.elementType == ElementType.TETRAHEDRA and destinationType == ElementType.TRIANGLES) |
52 | | - and not (sourceParameters.elementType == ElementType.HEXAHEDRA and destinationType == ElementType.QUADS) ): |
53 | | - raise ValueError("Only configuration possible are 'Tetrahedra to Triangles' and 'Hexahedra to Quads'") |
54 | | - |
| 70 | + |
0 commit comments