Ejemplo n.º 1
0
def intersection(shp1: TopoDS_Shape,
                 shp2: Union[TopoDS_Shape, gp.GP3d]) -> TopoDS_Shape:
    """
    Most Robust TopoDS intersection

    BRepAlgoAPI_Common will only return if the intersection is solid.
    BRepAlgoAPI_Section will work for face-on-face

    similar issue with GeomAPI is documented here:
        https://www.opencascade.com/content/use-brepalgosection-instead-brepalgoapisection

    :param: shp1 - TopoDS_Shape1
    :param: shp2 - TopoDS_Shape2

    BRepAlgoAPI_Section(TopoDS_Shape const &,TopoDS_Shape const &,BOPAlgo_PaveFiller const &,Standard_Boolean const)
    BRepAlgoAPI_Section(TopoDS_Shape const &,TopoDS_Shape const &,Standard_Boolean const)
    BRepAlgoAPI_Section(TopoDS_Shape const &,gp_Pln const &,Standard_Boolean const)
    BRepAlgoAPI_Section(TopoDS_Shape const &,Handle_Geom_Surface const &,Standard_Boolean const)
    BRepAlgoAPI_Section(Handle_Geom_Surface const &,TopoDS_Shape const &,Standard_Boolean const)
    BRepAlgoAPI_Section(Handle_Geom_Surface const &,Handle_Geom_Surface const &,Standard_Boolean const)

    returns wires representing the intersection
    """
    intrs = BRepAlgoAPI_Section(shp1, shp2)
    if intrs.BuilderCanWork() is True:
        intrs.Build()
        # todo add isDone check (maybe ??)
        # intrs.FuseEdges()
        intrs.RefineEdges()
        shp = intrs.Shape()
        intrs.Destroy()
        return shp
Ejemplo n.º 2
0
    def __call__(self, plane: gp.gp_Pln, vertex=None, edge_dict=None, **kwargs):
        splt = BRepFeat_SplitShape()
        if isinstance(self._base, TopoDS_Shape):
            base_shape = self._base
        else:
            base_shape = self._base.Shape()

        splt.Init(base_shape)

        sect = BRepAlgoAPI_Section(base_shape, plane, False)
        sect.ComputePCurveOn1(True)
        sect.Approximation(True)
        sect.Build()

        self.cutting_edge = sect.Shape()

        ancestors = set()
        new_faces = []
        edge_iter = TopExp_Explorer(self.cutting_edge, TopAbs_EDGE)

        while edge_iter.More():
            base_iter = TopExp_Explorer(base_shape, TopAbs_FACE)
            curr_edge = edge_iter.Current()

            while base_iter.More():

                curr_face = base_iter.Current()

                if sect.HasAncestorFaceOn1(curr_edge, curr_face):
                    k, v = hash(curr_face), hash(curr_edge)
                    if (k, v) not in self.ancestors:
                        ancestors.add((k, v))
                        e = topods.Edge(curr_edge)
                        f = topods.Face(curr_face)
                        splt.Add(e, f)
                        # todo - only add the closest one !!!!
                        new_faces.append(f)
                        self.added.append(e)
                        break
                # if sect.HasAncestorFaceOn2(curr_edge, curr_face):
                    # print('has2', curr_edge, curr_face)
                #     pass
                base_iter.Next()
            edge_iter.Next()

        # -------------------------------------
        splt.Build()
        new_shape = splt.Shape()
        sect.Destroy()

        return new_shape
Ejemplo n.º 3
0
def vectorized_slicer(li):
    # Create Plane defined by a point and the perpendicular direction
    z_values, shape = li
    _slices = []
    for z in z_values:
        #print 'slicing index:', z, 'sliced by process:', os.getpid()
        plane = gp_Pln(gp_Pnt(0., 0., z), gp_Dir(0., 0., 1.))
        face = BRepBuilderAPI_MakeFace(plane).Shape()
        # Computes Shape/Plane intersection
        section = BRepAlgoAPI_Section(shape, face)
        section.Build()
        if section.IsDone():
            _slices.append(section.Shape())
        section.Destroy()
    return _slices