From 5cdfaaff66995e3ba463f66ec3111a21ee8c49eb Mon Sep 17 00:00:00 2001 From: Patrick Sauvan Date: Tue, 7 Jan 2025 21:36:55 +0100 Subject: [PATCH] refactor boolregion and more alpha ? --- .../GEOUNED/conversion/cell_definition.py | 4 +- .../conversion/cell_definition_functions.py | 10 ++-- .../GEOUNED/utils/build_shape_functions.py | 15 +++-- src/geouned/GEOUNED/utils/functions.py | 4 +- src/geouned/GEOUNED/utils/geouned_classes.py | 2 +- src/geouned/GEOUNED/utils/meta_surfaces.py | 57 +++++++++++++++---- 6 files changed, 64 insertions(+), 28 deletions(-) diff --git a/src/geouned/GEOUNED/conversion/cell_definition.py b/src/geouned/GEOUNED/conversion/cell_definition.py index 6af9dd19..706f9fea 100644 --- a/src/geouned/GEOUNED/conversion/cell_definition.py +++ b/src/geouned/GEOUNED/conversion/cell_definition.py @@ -90,10 +90,10 @@ def simple_solid_definition(solid, Surfaces): component_definition.append(cylinder_region) elif isinstance(face.Surface, GU.ConeGu): - cone = gen_cone(face, orient) + cone = gen_cone(face) cone_region = Surfaces.add_cone(cone, orient) - apex_plane = cone_apex_plane(face, orient) + apex_plane = cone_apex_plane(face, orient, Surfaces.tolerances) if apex_plane is not None: if orient == "Forward": cone_region = BoolRegion.mult(cone_region, auxillary_plane(apex_plane, Surfaces), label=cone_region) diff --git a/src/geouned/GEOUNED/conversion/cell_definition_functions.py b/src/geouned/GEOUNED/conversion/cell_definition_functions.py index 77bda81d..af5f9857 100644 --- a/src/geouned/GEOUNED/conversion/cell_definition_functions.py +++ b/src/geouned/GEOUNED/conversion/cell_definition_functions.py @@ -71,14 +71,14 @@ def gen_torus(face, tolerances): def cone_apex_plane(cone, orientation, tolerances): if ( - is_parallel(cone.Surf.Axis, FreeCAD.Vector(1, 0, 0), tolerances.angle) - or is_parallel(cone.Surf.Axis, FreeCAD.Vector(0, 1, 0), tolerances.angle) - or is_parallel(cone.Surf.Axis, FreeCAD.Vector(0, 0, 1), tolerances.angle) + is_parallel(cone.Surface.Axis, FreeCAD.Vector(1, 0, 0), tolerances.angle) + or is_parallel(cone.Surface.Axis, FreeCAD.Vector(0, 1, 0), tolerances.angle) + or is_parallel(cone.Surface.Axis, FreeCAD.Vector(0, 0, 1), tolerances.angle) ): return None - normal = cone.Axis if orientation == "Forward" else -cone.Axis - return GeounedSurface(("Plane", (cone.Apex, normal, 1, 1))) + normal = cone.Surface.Axis if orientation == "Forward" else -cone.Surface.Axis + return GeounedSurface(("Plane", (cone.Surface.Apex, normal, 1, 1))) def V_torus_surfaces(face, v_params, Surfaces): diff --git a/src/geouned/GEOUNED/utils/build_shape_functions.py b/src/geouned/GEOUNED/utils/build_shape_functions.py index 72cd5523..06d5e2cc 100644 --- a/src/geouned/GEOUNED/utils/build_shape_functions.py +++ b/src/geouned/GEOUNED/utils/build_shape_functions.py @@ -136,15 +136,14 @@ def makeReverseCan(cylinder, plane_list, Box): orto = abs(axisnorm) > 1 - 1e-8 if len(plane_list) == 2 and orto: orto = abs(axis.dot(normal2)) > 1 - 1e-8 - + + dmin = axis.dot(Box.getPoint(0) - pt1) + dmax = dmin + for i in range(1, 8): + d = axis.dot(Box.getPoint(i) - pt1) + dmin = min(d, dmin) + dmax = max(d, dmax) if not orto: - dmin = axis.dot(Box.getPoint(0) - pt1) - dmax = dmin - for i in range(1, 8): - d = axis.dot(Box.getPoint(i) - pt1) - dmin = min(d, dmin) - dmax = max(d, dmax) - height = dmax - dmin dmin -= 0.1 * height dmax += 0.1 * height diff --git a/src/geouned/GEOUNED/utils/functions.py b/src/geouned/GEOUNED/utils/functions.py index 11e9c73d..7a319fc0 100644 --- a/src/geouned/GEOUNED/utils/functions.py +++ b/src/geouned/GEOUNED/utils/functions.py @@ -145,7 +145,7 @@ def build_roundC_params(rc): def build_revcan_params(cs): - cyl, p1 = cs[0:2] + cyl,p1 = reversed(cs[-2:]) if isinstance(cyl, GeounedSurface): gcyl = cyl else: @@ -158,7 +158,7 @@ def build_revcan_params(cs): params = [gcyl, gp1] if len(cs) == 3: - p2 = cs[2] + p2 = cs[-3] if isinstance(p2, GeounedSurface): gp2 = p2 else: diff --git a/src/geouned/GEOUNED/utils/geouned_classes.py b/src/geouned/GEOUNED/utils/geouned_classes.py index 0827035e..58c7c251 100644 --- a/src/geouned/GEOUNED/utils/geouned_classes.py +++ b/src/geouned/GEOUNED/utils/geouned_classes.py @@ -521,7 +521,7 @@ def add_roundCorner(self, roundC): p = self.primitive_surfaces.get_surface(pid) if is_opposite(roundC.Surf.AddPlane.Surf.Axis, roundC.Surf.AddPlane.Surf.Axis, self.tolerances.pln_angle): pid = -pid - roundC_surfaces = [f"({cid}:{pid})"] + roundC_surfaces = [f"({-cid}:{pid})"] for cp in roundC.Surf.Planes: pid, exist = self.primitive_surfaces.add_plane(cp, True) diff --git a/src/geouned/GEOUNED/utils/meta_surfaces.py b/src/geouned/GEOUNED/utils/meta_surfaces.py index 7a2cf006..d710d8f4 100644 --- a/src/geouned/GEOUNED/utils/meta_surfaces.py +++ b/src/geouned/GEOUNED/utils/meta_surfaces.py @@ -183,8 +183,34 @@ def commonEdge(face1, face2, outer_only=True): return e1 return None - def get_revcan_surfaces(cylinder, solid): + adjacent_planes = get_adjacent_cylplane(cylinder, solid.Faces, cornerPlanes=False) + if len(adjacent_planes) not in (1, 2): + return None, None + + surfaces = [] + faceindex = set() + p1 = adjacent_planes[0] + r1 = region_sign(p1, cylinder) + if r1 == "OR": + surfaces.append(p1) + faceindex.add(p1.Index) + + if len(adjacent_planes) == 2: + p2 = adjacent_planes[1] + r2 = region_sign(p2, cylinder) + if r2 == "OR": + surfaces.append(p2) + faceindex.add(p2.Index) + + if len(surfaces) > 0 : + surfaces.append(cylinder) + faceindex.add(cylinder.Index) + return surfaces,faceindex + else: + return None,None + +def get_revcan_surfaces_old(cylinder, solid): same_cylinder_faces, cylindex = get_adjacent_cylinder_faces(cylinder, solid.Faces) if not is_closed_cylinder(same_cylinder_faces): @@ -224,16 +250,27 @@ def get_roundcorner_surfaces(cylinder, solid): return faces, face_index -def get_adjacent_cylplane(cyl, Faces): +def get_adjacent_cylplane(cyl, Faces, cornerPlanes = True): planes = [] - for e in cyl.OuterWire.Edges: - if not isinstance(e.Curve, Part.Line): - continue - otherface = other_face_edge(e, cyl, Faces, outer_only=True) - if otherface is None : - continue - if isinstance(otherface.Surface, PlaneGu): - if abs(otherface.Surface.Axis.dot(cyl.Surface.Axis)) < 1.0e-5: + + if cornerPlanes: + for e in cyl.OuterWire.Edges: + if not isinstance(e.Curve, Part.Line): + continue + otherface = other_face_edge(e, cyl, Faces, outer_only=True) + if otherface is None : + continue + if isinstance(otherface.Surface, PlaneGu): + if abs(otherface.Surface.Axis.dot(cyl.Surface.Axis)) < 1.0e-5: + planes.append(otherface) + else: + for e in cyl.OuterWire.Edges: + if isinstance(e.Curve, Part.Line): + continue + otherface = other_face_edge(e, cyl, Faces, outer_only=False) + if otherface is None : + continue + if isinstance(otherface.Surface, PlaneGu): planes.append(otherface) delindex = []