Skip to content

Commit

Permalink
partial1
Browse files Browse the repository at this point in the history
  • Loading branch information
psauvan committed Dec 16, 2024
1 parent b330b9e commit e10b603
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 40 deletions.
55 changes: 37 additions & 18 deletions src/geouned/GEOUNED/decompose/decom_one.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,13 @@ def gen_plane(pos, normal, diag):
return plane_center


def other_face_edge(current_edge, current_face, Faces):
def other_face_edge(current_edge, current_face, Faces, outer_only=False):
for face in Faces:
if face.isSame(current_face):
continue
for edge in face.Edges:

Edges = face.OuterWire.Edges if outer_only else face.Edges
for edge in Edges:
if current_edge.isSame(edge):
return face

Expand Down Expand Up @@ -356,50 +358,67 @@ def extract_surfaces(solid, kind, universe_box, options, tolerances, numeric_for
def contiguous_face(face1, face2, tolerances):
return face1.distToShape(face2)[0] < tolerances.distance


def get_metaplanes(solid):
planes = []
for f in solid.Faces :
for f in solid.Faces:
if type(f.Surface) is Part.plane:
planes.append(f)

metaplane_list = []
for p in planes:
loop = False
for mp in metaplane_list:
if p in mp:
loop = True
if loop : continue
metap = metaplane(p,planes)
if loop:
continue
metap = [p]
meta_loop([p], metap, planes)
if len(metap) != 1:
metaplane_list.append(metap)

return metaplane_list

def metaplane(p,planes):
return metaplane_list


def meta_loop(adjacents, metalist, planes):
for p in adjacents:
new_adjacents = metaplane(p, planes)
for ap in reversed(new_adjacents):
if ap in metalist:
new_adjacents.remove(ap)
metalist.extend(new_adjacents)
meta_loop(new_adjacents, metalist, planes)


def metaplane(p, planes):
Edges = p.OuterWire.Edges
addplane = [p]
for e in Edges:
try:
curve = str(e.Curve)
except:
curve = "none"
if curve is not "line":
continue

adjacent_plane = other_face_edge(e, p, planes)
adjacent_plane = other_face_edge(e, p, planes, outer_only=True)
if adjacent_plane is not None:
sign = region_sign(p,adjacent_plane,e)
if sign == 'OR':
sign = region_sign(p, adjacent_plane, e)
if sign == "OR":
addplane.append(adjacent_plane)
return addplane
return addplane

def region_sign(p1,p2,e):

def region_sign(p1, p2, e):
normal1 = p1.Surface.Axis
if p1.Orientation == 'Reversed':
if p1.Orientation == "Reversed":
normal1 = -normal1
ecenter = (e.Vertexes[1]+e.Vertexes[0])*0.5
ecenter = (e.Vertexes[1] + e.Vertexes[0]) * 0.5
vect = p2.CenterofMass - ecenter
return 'OR' if vect.dot(normal1) < 0 else 'AND'
return "OR" if vect.dot(normal1) < 0 else "AND"



def same_faces(Faces, tolerances):
Connection = OrderedDict()
if len(Faces) == 1:
Expand Down
46 changes: 24 additions & 22 deletions src/geouned/GEOUNED/utils/boolean_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,22 @@
mix = re.compile(r"(?P<value>([-+]?\d+|\[0+\]))") # identify signed integer or [000...] pattern. Record the value.
TFX = re.compile(r"(?P<value>[FTXo]+)") # identify pattern including F,T,X, or o sequence ( in any order).


class BoolRegion(int):

def __new__(cls, *args, **kwrds):
label = args[0]
return super(BoolRegion,cls).__new__(cls,label)
return super(BoolRegion, cls).__new__(cls, label)

def __init__(self,label,definition=None):
if definition is None :
def __init__(self, label, definition=None):
if definition is None:
self.definition = BoolSequence(str(label))
else:
self.definition = definition
self.surfaces = self.definition.get_surfaces_numbers(self)
self.surfaces = self.definition.get_surfaces_numbers(self)

def __neg__(self):
return BoolRegion(-self.__int__(),self.definition.get_complementary())
return BoolRegion(-self.__int__(), self.definition.get_complementary())

def __pos__(self):
return self
Expand All @@ -36,30 +37,31 @@ def __abs__(self):
else:
return -self

def __add__(self,def2):
newdef = BoolSequence(operator='OR')
newdef.append(self.definition,def2.definition)
def __add__(self, def2):
newdef = BoolSequence(operator="OR")
newdef.append(self.definition, def2.definition)
newdef.group_single()
return BoolRegion(0,newdef)
def __sub__(self,def2):
newdef = BoolSequence(operator='OR')
newdef.append(self.definition,def2.definition.get_complementary())
return BoolRegion(0, newdef)

def __sub__(self, def2):
newdef = BoolSequence(operator="OR")
newdef.append(self.definition, def2.definition.get_complementary())
newdef.group_single()
return BoolRegion(0,newdef)
return BoolRegion(0, newdef)

def __mul__(self,def2):
newdef = BoolSequence(operator='AND')
newdef.append(self.definition,def2)
def __mul__(self, def2):
newdef = BoolSequence(operator="AND")
newdef.append(self.definition, def2)
newdef.group_single()
return BoolRegion(0,newdef)
def setDef(self,definition):
return BoolRegion(0, newdef)

def setDef(self, definition):
self.definition = definition
self.surfaces = self.definition.get_surfaces_numbers(self)

def copy(self,newname):
return BoolRegion(newname,self.definition)
def copy(self, newname):
return BoolRegion(newname, self.definition)


class BoolSequence:
"""Class storing Boolean expression and operating on it"""
Expand Down

0 comments on commit e10b603

Please sign in to comment.