You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
frombuild123dimport*frombuild123dimportShape, TOLERANCEfromocp_vscodeimportshowfromOCP.TopToolsimportTopTools_IndexedDataMapOfShapeListOfShapeimportOCP.TopAbsastafromOCP.TopExpimportTopExpfromOCP.TopoDSimportTopoDSfromOCP.BRepOffsetimportBRepOffset_MakeOffsetfromOCP.BRepAlgoAPIimportBRepAlgoAPI_SectionfromOCP.TopExpimportTopExp, TopExp_ExplorerfromOCP.TopoDSimportTopoDS, TopoDS_Face, TopoDS_Shapedeftopo_explore_connected_faces(edge: Edge, parent: Shape=None) ->list[TopoDS_Face]:
"""Given an edge extracted from a Shape, return the topods_faces connected to it"""parent=parentifparentisnotNoneelseedge.topo_parent# make a edge --> faces mappingedge_face_map=TopTools_IndexedDataMapOfShapeListOfShape()
TopExp.MapShapesAndAncestors_s(
parent.wrapped, ta.TopAbs_EDGE, ta.TopAbs_FACE, edge_face_map
)
# Query the mapfaces= []
ifedge_face_map.Contains(edge.wrapped):
face_list=edge_face_map.FindFromKey(edge.wrapped)
forfaceinface_list:
faces.append(TopoDS.Face_s(face))
iflen(faces) !=2:
raiseRuntimeError("Invalid # of faces connected to this edge")
returnfacesdefoffset_topods_face(face: TopoDS_Face, amount: float) ->TopoDS_Shape:
"""Offset a topods_face"""offsetor=BRepOffset_MakeOffset()
offsetor.Initialize(face, Offset=amount, Tol=TOLERANCE)
offsetor.MakeOffsetShape()
returnoffsetor.Shape()
@propertydefis_interior(self) ->bool:
""" Check if the edge is an interior edge. An interior edge lies between surfaces that are part of the body (internal to the geometry) and does not form part of the exterior boundary. Returns: bool: True if the edge is an interior edge, False otherwise. """# Find the faces connected to this edge and offset themtopods_face_pair=topo_explore_connected_faces(self)
offset_face_pair= [
offset_topods_face(f, self.length/100) forfintopods_face_pair
]
# Intersect the offset facessectionor=BRepAlgoAPI_Section(
offset_face_pair[0], offset_face_pair[1], PerformNow=False
)
sectionor.Build()
face_intersection_result=sectionor.Shape()
# If an edge was created the faces intersect and the edge is interiorexplorer=TopExp_Explorer(face_intersection_result, ta.TopAbs_EDGE)
returnexplorer.More()
Edge.is_interior=is_interior# target = Box(2, 2, 1) - Box(1, 1, 1, align=(Align.MIN, Align.MIN, Align.CENTER))path=RegularPolygon(5, 5).face().outer_wire()
profile=path.location_at(0) * (Circle(0.6) &Rectangle(2, 1))
target=sweep(profile, path, transition=Transition.RIGHT)
target_edges=target.edges()
inside_edges= [eforeintarget_edgesife.is_interior]
outside_edges=target_edges-inside_edgesinsides=Compound(inside_edges)
insides.color=Color("White")
outsides=Compound(outside_edges)
outsides.color=Color("Black")
show(target, insides, outsides)
The text was updated successfully, but these errors were encountered:
Why not simply compare the face normals at the edge? Your implementation would also break for this case:
Would you share the code for this shape, I'd like to try it out. I spent a lot of time comparing face normals along the edge (even integrating them for non-planar surfaces) but I found it impossible to get a consistent edge direction in order to differentiate crossing normals from diverging normals. I think this implementation is actually quite robust - but we'll see.
Here a single face has both interior and exterior edges and the algorithm sees the intersection of both ends and makes the wrong conclusion. A partial solution is to trim the face to just around the edge being tested to avoid this. However, the current algorithm is going to work on the vast majority of shapes so this enhancement could be done in a follow on change.
The text was updated successfully, but these errors were encountered: