|
| 1 | +from stlib.geometry import GeometryParameters, InternalDataProvider, Geometry |
| 2 | +from stlib.core.baseParameters import dataclasses |
| 3 | +from splib.topology.dynamic import addDynamicTopology |
| 4 | +from splib.topology.loader import loadMesh |
| 5 | +from splib.core.enum_types import ElementType |
| 6 | + |
| 7 | +from Sofa.Core import Node |
| 8 | + |
| 9 | + |
| 10 | +class ExtractInternalDataProvider(InternalDataProvider): |
| 11 | + destElemType : ElementType |
| 12 | + fromElemType : ElementType |
| 13 | + fromNodeName : str |
| 14 | + |
| 15 | + def __post_init__(self): |
| 16 | + if(not (self.fromElemType == ElementType.TETRA and self.destElemType == ElementType.TRIANGLES) |
| 17 | + and not (self.fromElemType == ElementType.HEXA and self.destElemType == ElementType.QUAD) ): |
| 18 | + raise ValueError("Only configuration possible are 'Tetra to Triangle' and 'Hexa to quad'") |
| 19 | + |
| 20 | + InternalDataProvider.__init__(self) |
| 21 | + |
| 22 | + |
| 23 | + def generateAttribute(self, parent : Geometry): |
| 24 | + tmn = parent.addChild("topologicalMappingNode") |
| 25 | + |
| 26 | + #TODO: Specify somewhere in the doc that this should only be used for mapped topologies that extract parent topology surface |
| 27 | + fromLink = parent.parents[0].parents[0].getChild(self.fromNodeName).container.linkpath |
| 28 | + addDynamicTopology(tmn, type=self.destElemType) |
| 29 | + if self.fromElemType == ElementType.TETRA: |
| 30 | + tmn.addObject("Tetra2TriangleTopologicalMapping", input=fromLink, output=tmn.container.linkpath) |
| 31 | + elif self.fromElemType == ElementType.HEXA: |
| 32 | + tmn.addObject("Hexa2QuadTopologicalMapping", input=fromLink, output=tmn.container.linkpath) |
| 33 | + |
| 34 | + self.positions = tmn.container.position.linkpath |
| 35 | + self.edges = tmn.container.edges.linkpath |
| 36 | + self.triangles = tmn.container.triangles.linkpath |
| 37 | + self.quads = tmn.container.quads.linkpath |
| 38 | + self.hexaedra = tmn.container.hexaedra.linkpath |
| 39 | + self.tetrahedra = tmn.container.tetras.linkpath |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | +class ExtractParameters(GeometryParameters): |
| 44 | + def __init__(self, fromGeometry : GeometryParameters, destElementType : ElementType, dynamicTopology = False, ): |
| 45 | + GeometryParameters.__init__(data = ExtractInternalDataProvider(destElemType = destElementType, fromElemType = fromGeometry.elementType,fromNodeName = fromGeometry.name), dynamicTopology = dynamicTopology, elementType = destElementType) |
| 46 | + |
0 commit comments