Skip to content

Commit

Permalink
Torus envelope fix (partially) (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
psauvan authored Dec 9, 2024
1 parent 749ec0b commit bc3829a
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 18 deletions.
35 changes: 28 additions & 7 deletions src/geouned/GEOUNED/decompose/decom_one.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def cut_full_cylinder(solid, options, tolerances, numeric_format):
surfaces.add_cylinder(cylinder, options, tolerances, numeric_format, False)

# add planes if cylinder axis is cut by a plane (plane quasi perpedicular to axis)
for p in cyl_bound_planes(face, universe_box):
for p in cyl_bound_planes(solid_gu, face, universe_box):
p.build_surface()
surfaces.add_plane(p, options, tolerances, numeric_format, False)
break
Expand Down Expand Up @@ -131,7 +131,16 @@ def gen_plane(pos, normal, diag):
return plane_center


def cyl_bound_planes(face, boundBox):
def other_face_edge(current_edge, current_face, solid):
for face in solid.Faces:
if face.isSame(current_face):
continue
for edge in face.Edges:
if current_edge.isSame(edge):
return face


def cyl_bound_planes(solid, face, boundBox):
Edges = face.OuterWire.Edges
planes = []
for e in Edges:
Expand All @@ -140,6 +149,13 @@ def cyl_bound_planes(face, boundBox):
except:
curve = "none"

adjacent_face = other_face_edge(e, face, solid)
if adjacent_face is not None:
if type(adjacent_face.Surface) is GU.TorusGu:
continue # doesn't create plane if other face is a torus
if face.Surface.isSameSurface(adjacent_face.Surface):
continue # doesn't create plane if other face has same surface

if curve[0:6] == "Circle":
dir = e.Curve.Axis
center = e.Curve.Center
Expand All @@ -159,7 +175,7 @@ def cyl_bound_planes(face, boundBox):
return planes


def torus_bound_planes(face, boundBox, tolerances):
def torus_bound_planes(solid, face, boundBox, tolerances):
params = face.ParameterRange
planes = []
if is_same_value(params[1] - params[0], twoPi, tolerances.value):
Expand All @@ -173,6 +189,11 @@ def torus_bound_planes(face, boundBox, tolerances):
except:
curve = "none"

adjacent_face = other_face_edge(e, face, solid)
if adjacent_face is not None:
if face.Surface.isSameSurface(adjacent_face.Surface):
continue # doesn't create plane if other face has same surface

if curve[0:6] == "Circle":
dir = e.Curve.Axis
if not is_parallel(dir, face.Surface.Axis, tolerances.angle):
Expand Down Expand Up @@ -262,7 +283,7 @@ def extract_surfaces(solid, kind, universe_box, options, tolerances, numeric_for

if kind in ["Planes", "All"]:
# add planes if cylinder axis is cut by a plane (plane quasi perpedicular to axis)
for p in cyl_bound_planes(face, universe_box):
for p in cyl_bound_planes(solid_GU, face, universe_box):
if MakeObj:
p.build_surface()
surfaces.add_plane(p, options, tolerances, numeric_format, False)
Expand All @@ -280,7 +301,7 @@ def extract_surfaces(solid, kind, universe_box, options, tolerances, numeric_for
surfaces.add_cone(cone, tolerances)

if kind in ["Planes", "All"]:
for p in cyl_bound_planes(face, universe_box):
for p in cyl_bound_planes(solid_GU, face, universe_box):
if MakeObj:
p.build_surface()
surfaces.add_plane(p, options, tolerances, numeric_format, False)
Expand All @@ -294,7 +315,7 @@ def extract_surfaces(solid, kind, universe_box, options, tolerances, numeric_for
surfaces.add_sphere(sphere, tolerances)

if kind in ["Planes", "All"]:
for p in cyl_bound_planes(face, universe_box):
for p in cyl_bound_planes(solid_GU, face, universe_box):
if MakeObj:
p.build_surface()
surfaces.add_plane(p, options, tolerances, numeric_format, False)
Expand All @@ -311,7 +332,7 @@ def extract_surfaces(solid, kind, universe_box, options, tolerances, numeric_for
surfaces.add_torus(torus, tolerances)

if kind in ["Planes", "All"]:
for p in torus_bound_planes(face, universe_box, tolerances):
for p in torus_bound_planes(solid_GU, face, universe_box, tolerances):
if MakeObj:
p.build_surface()
surfaces.add_plane(p, options, tolerances, numeric_format, False)
Expand Down
4 changes: 2 additions & 2 deletions src/geouned/GEOUNED/utils/data_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ class NumericFormat:
C_r (str, optional): Cylinder radius. Defaults to "12f".
C_xyz (str, optional): Cylinder center. Defaults to "12f".
K_xyz (str, optional): Cone apex. Defaults to "13.6e".
K_tan2 (str, optional): Cone tan^2 value. Defaults to "12f".
K_tan2 (str, optional): Cone tan^2 value. Defaults to "13.6e".
T_r (str, optional): Torus radii. Defaults to "14.7e".
T_xyz (str, optional): Torus center. Defaults to "14.7e".
GQ_1to6 (str, optional): GQ 1 to 6 coefficients (order 2 x2,y2,z2,xy,...). Defaults to "18.15f".
Expand All @@ -426,7 +426,7 @@ def __init__(
C_r: str = "12f",
C_xyz: str = "12f",
K_xyz: str = "13.6e",
K_tan2: str = "12f",
K_tan2: str = "13.6e",
T_r: str = "14.7e",
T_xyz: str = "14.7e",
GQ_1to6: str = "18.15f",
Expand Down
77 changes: 68 additions & 9 deletions src/geouned/GEOUNED/utils/geometry_gu.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ def __init__(self, face, plane3Pts=False):
self.dim1 = face.ParameterRange[1] - face.ParameterRange[0]
self.dim2 = face.ParameterRange[3] - face.ParameterRange[2]

def isSameSurface(self, surface):
if type(surface) is not PlaneGu:
return False
if abs(self.Axis.dot(surface.Axis)) < 0.99999:
return False
if abs(self.Axis.dot(self.Position) - surface.Axis.dot(surface.Position)) > 1e-5:
return False
return True


class CylinderGu(SurfacesGu):
"""GEOUNED Cylinder Class"""
Expand All @@ -61,6 +70,18 @@ def __init__(self, face):
self.Center = face.Surface.Center
self.dimL = face.ParameterRange[3] - face.ParameterRange[2]

def isSameSurface(self, surface):
if type(surface) is not CylinderGu:
return False
if abs(self.Radius - surface.Radius) > 1e-5:
return False
d = self.Center - surface.Center
if d.Length > 1e-5:
return False
if abs(self.Axis.dot(surface.Axis)) < 0.99999:
return False
return True


class ConeGu(SurfacesGu):
"""GEOUNED Cone Class"""
Expand All @@ -74,6 +95,18 @@ def __init__(self, face):
self.dimR = face.Surface.Radius
self.Radius = face.Surface.Radius

def isSameSurface(self, surface):
if type(surface) is not ConeGu:
return False
if abs(self.SemiAngle - surface.SemiAngle) > 1e-5:
return False
d = self.Apex - surface.Apex
if d.Length > 1e-5:
return False
if abs(self.Axis.dot(surface.Axis)) < 0.99999:
return False
return True


class SphereGu(SurfacesGu):
"""GEOUNED Sphere Class"""
Expand All @@ -84,6 +117,16 @@ def __init__(self, face):
self.Center = face.Surface.Center
self.Radius = face.Surface.Radius

def isSameSurface(self, surface):
if type(surface) is not SphereGu:
return False
if abs(self.Radius - surface.Radius) > 1e-5:
return False
d = self.Center - surface.Center
if d.Length > 1e-5:
return False
return True


class TorusGu(SurfacesGu):
"""GEOUNED Torus Class"""
Expand All @@ -95,6 +138,20 @@ def __init__(self, face):
self.MajorRadius = face.Surface.MajorRadius
self.MinorRadius = face.Surface.MinorRadius

def isSameSurface(self, surface):
if type(surface) is not TorusGu:
return False
if abs(self.MajorRadius - surface.MajorRadius) > 1e-5:
return False
if abs(self.MinorRadius - surface.MinorRadius) > 1e-5:
return False
d = self.Center - surface.Center
if d.Length > 1e-5:
return False
if abs(self.Axis.dot(surface.Axis)) < 0.99999:
return False
return True


class SolidGu:
"""GEOUNED Solid Class"""
Expand All @@ -112,9 +169,8 @@ def __init__(self, solid, tolerances, plane3Pts=False):

toroidIndex = []
for i, face in enumerate(self.Faces):
if str(face.Surface) != "<Toroid object>":
continue
toroidIndex.append(i)
if type(face.Surface) is TorusGu:
toroidIndex.append(i)

if len(toroidIndex) != 0:
tFaces = self.same_torus_surf(toroidIndex)
Expand Down Expand Up @@ -259,6 +315,9 @@ def getUVNodes(self):
def isEqual(self, face):
return self.__face__.isEqual(face.__face__)

def isSame(self, face):
return self.__face__.isSame(face.__face__)

def valueAt(self, u, v):
return self.__face__.valueAt(u, v)

Expand Down Expand Up @@ -286,16 +345,16 @@ def define_list_face_gu(face_list, plane3Pts=False):


def define_surface(face, plane3Pts):
kind_surf = str(face.Surface)
if kind_surf == "<Plane object>":
kind_surf = type(face.Surface)
if kind_surf is Part.Plane:
Surf_GU = PlaneGu(face, plane3Pts)
elif kind_surf == "<Cylinder object>":
elif kind_surf is Part.Cylinder:
Surf_GU = CylinderGu(face)
elif kind_surf == "<Cone object>":
elif kind_surf is Part.Cone:
Surf_GU = ConeGu(face)
elif kind_surf[0:6] == "Sphere":
elif kind_surf is Part.Sphere:
Surf_GU = SphereGu(face)
elif kind_surf == "<Toroid object>":
elif kind_surf is Part.Toroid:
Surf_GU = TorusGu(face)
else:
logger.info(f"bad Surface type {kind_surf}")
Expand Down

0 comments on commit bc3829a

Please sign in to comment.