Skip to content

Commit

Permalink
refactor boolregion and more alpha ?
Browse files Browse the repository at this point in the history
  • Loading branch information
psauvan committed Jan 7, 2025
1 parent 22ea836 commit 5cdfaaf
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/geouned/GEOUNED/conversion/cell_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions src/geouned/GEOUNED/conversion/cell_definition_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
15 changes: 7 additions & 8 deletions src/geouned/GEOUNED/utils/build_shape_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/geouned/GEOUNED/utils/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/geouned/GEOUNED/utils/geouned_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
57 changes: 47 additions & 10 deletions src/geouned/GEOUNED/utils/meta_surfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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 = []
Expand Down

0 comments on commit 5cdfaaf

Please sign in to comment.