示例#1
0
def occ_triangle_mesh(event=None):
    #
    # Mesh the shape
    #
    BRepMesh_IncrementalMesh(aShape, 0.1)
    builder = BRep_Builder()
    Comp = TopoDS_Compound()
    builder.MakeCompound(Comp)

    ex = TopExp_Explorer(aShape, TopAbs_FACE)
    while ex.More():
        F = topods_Face(ex.Current())
        L = TopLoc_Location()
        facing = (BRep_Tool().Triangulation(F, L))
        tab = facing.Nodes()
        tri = facing.Triangles()
        for i in range(1, facing.NbTriangles() + 1):
            trian = tri.Value(i)
            #print trian
            index1, index2, index3 = trian.Get()
            for j in range(1, 4):
                if j == 1:
                    M = index1
                    N = index2
                elif j == 2:
                    N = index3
                elif j == 3:
                    M = index2
                ME = BRepBuilderAPI_MakeEdge(tab.Value(M), tab.Value(N))
                if ME.IsDone():
                    builder.Add(Comp, ME.Edge())
        ex.Next()
    display.DisplayShape(Comp, update=True)
示例#2
0
def brep_feat_local_revolution(event=None):
    S = BRepPrimAPI_MakeBox(400., 250., 300.).Shape()
    faces = list(TopologyExplorer(S).faces())
    F1 = faces[2]
    surf = BRep_Tool_Surface(F1)

    D = gp_OX()

    MW1 = BRepBuilderAPI_MakeWire()
    p1 = gp_Pnt2d(100., 100.)
    p2 = gp_Pnt2d(200., 100.)
    aline = GCE2d_MakeLine(p1, p2).Value()
    MW1.Add(BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)).Edge())

    p1 = gp_Pnt2d(200., 100.)
    p2 = gp_Pnt2d(150., 200.)
    aline = GCE2d_MakeLine(p1, p2).Value()
    MW1.Add(BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)).Edge())

    p1 = gp_Pnt2d(150., 200.)
    p2 = gp_Pnt2d(100., 100.)
    aline = GCE2d_MakeLine(p1, p2).Value()
    MW1.Add(BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)).Edge())

    MKF1 = BRepBuilderAPI_MakeFace()
    MKF1.Init(surf, False, 1e-6)
    MKF1.Add(MW1.Wire())
    FP = MKF1.Face()
    breplib_BuildCurves3d(FP)
    MKrev = BRepFeat_MakeRevol(S, FP, F1, D, 1, True)
    F2 = faces[4]
    MKrev.Perform(F2)
    display.EraseAll()
    display.DisplayShape(MKrev.Shape())
    display.FitAll()
示例#3
0
    def __init__(self, crv1, crv2, itol=1.0e-7):
        super(IntersectCurveCurve, self).__init__(crv1, crv2)

        # Build edges from curve
        e1 = BRepBuilderAPI_MakeEdge(crv1.object).Edge()
        e2 = BRepBuilderAPI_MakeEdge(crv2.object).Edge()

        # Set tolerance to be half intersection tolerance
        shp_tol = ShapeFix_ShapeTolerance()
        tol = itol / 2.
        shp_tol.SetTolerance(e1, tol)
        shp_tol.SetTolerance(e2, tol)

        # Perform edge-edge intersection
        cci = IntTools_EdgeEdge(e1, e2)
        cci.Perform()

        # Gather results of point intersection only
        results = []
        common_parts = cci.CommonParts()
        for i in range(1, common_parts.Length() + 1):
            common_part = common_parts.Value(i)
            if not common_part.Type() == TopAbs_VERTEX:
                continue
            u1 = common_part.VertexParameter1()
            u2 = common_part.VertexParameter2()
            p1 = crv1.eval(u1)
            p2 = crv2.eval(u2)
            pi = mean([p1, p2], axis=0)
            pi = Point(*pi)
            results.append([(u1, u2), pi])

        npts = len(results)
        self._set_results(npts, results)
示例#4
0
def prism():
    # the bspline profile
    array = TColgp_Array1OfPnt(1, 5)
    array.SetValue(1, gp_Pnt(0, 0, 0))
    array.SetValue(2, gp_Pnt(1, 2, 0))
    array.SetValue(3, gp_Pnt(2, 3, 0))
    array.SetValue(4, gp_Pnt(4, 3, 0))
    array.SetValue(5, gp_Pnt(5, 5, 0))
    bspline = GeomAPI_PointsToBSpline(array).Curve()
    profile = BRepBuilderAPI_MakeEdge(bspline).Edge()

    # the linear path
    starting_point = gp_Pnt(0., 0., 0.)
    end_point = gp_Pnt(0., 0., 6.)
    vec = gp_Vec(starting_point, end_point)
    path = BRepBuilderAPI_MakeEdge(starting_point, end_point).Edge()

    # extrusion
    prism = BRepPrimAPI_MakePrism(profile, vec).Shape()

    display.DisplayShape(profile, update=False)
    display.DisplayShape(starting_point, update=False)
    display.DisplayShape(end_point, update=False)
    display.DisplayShape(path, update=False)
    display.DisplayShape(prism, update=True)
示例#5
0
def trimedge(lbound, ubound, occedge):
    """
    This function trims the OCCedge according to the specified lower and upper bound.
 
    Parameters
    ----------
    lbound : float
        The lower bound of the OCCedge.
        
    ubound : float
        The upper bound of the OCCedge.
        
    occedge : OCCedge
        The edge to be trimmed.

    Returns
    -------
    trimmed edge : OCCedge
        The trimmed OCCedge.
    """
    adaptor = BRepAdaptor_Curve(occedge)
    tr = Geom_TrimmedCurve(adaptor.Curve().Curve(), lbound, ubound)
    tr.SetTrim(lbound, ubound)
    bspline_handle = geomconvert_CurveToBSplineCurve(tr.BasisCurve())
    tr_edge = BRepBuilderAPI_MakeEdge(bspline_handle)

    return tr_edge.Edge()
示例#6
0
    def write_edge(points_edge, topo_edge):
        """
        Method to recreate an Edge associated to a geometric curve
        after the modification of its points.
        :param points_edge: the deformed points array.
        :param topo_edge: the Edge to be modified
        :return: Edge (Shape)

        :rtype: TopoDS_Edge

        """
        # convert Edge to Geom B-spline Curve
        nurbs_converter = BRepBuilderAPI_NurbsConvert(topo_edge)
        nurbs_converter.Perform(topo_edge)
        nurbs_curve = nurbs_converter.Shape()
        topo_curve = topods_Edge(nurbs_curve)
        h_geomcurve = BRep_Tool.Curve(topo_curve)[0]
        h_bcurve = geomconvert_CurveToBSplineCurve(h_geomcurve)
        bspline_edge_curve = h_bcurve

        # Edge geometric properties
        nb_cpt = bspline_edge_curve.NbPoles()
        # check consistency
        if points_edge.shape[0] != nb_cpt:
            raise ValueError("Input control points do not have not have the "
                             "same number as the geometric edge!")

        else:
            for i in range(1, nb_cpt + 1):
                cpt = points_edge[i - 1]
                bspline_edge_curve.SetPole(i, gp_Pnt(cpt[0], cpt[1], cpt[2]))

        new_edge = BRepBuilderAPI_MakeEdge(bspline_edge_curve)

        return new_edge.Edge()
示例#7
0
 def CancelEvent(self):
     if self.myBSplineCurveAction == BSplineCurveAction.Nothing:
         pass
     elif self.myBSplineCurveAction == BSplineCurveAction.Input_1Point:
         pass
     elif self.myBSplineCurveAction == BSplineCurveAction.Input_2Point:
         self.bspline.RemoveLabel()
         del self.bspline
     elif self.myBSplineCurveAction == BSplineCurveAction.Input_OtherPoints:
         if len(self.Poles) <= 3:
             self.bspline.RemoveLabel()
             del self.bspline
             self.myContext.Remove(self.myRubberAIS_Shape, True)
         # remove the last pole
         del self.Poles2d[-1]
         del self.Poles[-1]
         self.Multi, self.Knots = setQuasiUniformKnots(
             len(self.Poles), self.myDegree)
         self.CreateBspline()
         ME = BRepBuilderAPI_MakeEdge(self.myGeom_BSplineCurve)
         if ME.IsDone():
             self.curEdge = ME.Edge()
             self.closeBSpline()
             self.IndexCounter -= 1
     self.myBSplineCurveAction = BSplineCurveAction.Nothing
示例#8
0
def thicken_spline(event=None):
    # Creation of points for the spine
    array = TColgp_Array1OfPnt(1, 5)
    array.SetValue(1, gp_Pnt(1, 4, 0))
    array.SetValue(2, gp_Pnt(2, 2, 0))
    array.SetValue(3, gp_Pnt(3, 3, 0))
    array.SetValue(4, gp_Pnt(4, 3, 0))
    array.SetValue(5, gp_Pnt(5, 5, 0))

    # Creation of a Bezier Curve as the spine
    bz_curv = Geom_BezierCurve(array)
    bz_curv_edge = BRepBuilderAPI_MakeEdge(bz_curv).Edge()
    bz_curv_wire = BRepBuilderAPI_MakeWire(bz_curv_edge).Wire()
    display.DisplayShape(bz_curv_wire)

    # Creation of profile to sweep along the spine
    circle = gp_Circ(gp_ZOX(), 1)
    circle.SetLocation(array[0])
    circle_edge = BRepBuilderAPI_MakeEdge(circle).Edge()
    circle_wire = BRepBuilderAPI_MakeWire(circle_edge).Wire()

    # Creation of the law to dictate the evolution of the profile
    brep1 = BRepOffsetAPI_MakePipeShell(bz_curv_wire)
    law_f = Law_Linear()
    law_f.Set(0, 0.5, 1, 1)
    brep1.SetLaw(circle_wire, law_f, False, True)
    return brep1.Shape()
示例#9
0
 def MouseMoveEvent(self, thePnt2d: gp_Pnt2d, buttons, modifiers):
     self.curPnt2d = self.myAnalyserSnap.MouseMove(thePnt2d)
     if self.myBSplineCurveAction == BSplineCurveAction.Nothing:
         pass
     elif self.myBSplineCurveAction == BSplineCurveAction.Input_1Point:
         pass
     elif self.myBSplineCurveAction == BSplineCurveAction.Input_2Point:
         # self.mySecondPoint.SetPnt(elclib.To3d(self.curCoordinateSystem.Ax2(), self.curPnt2d))
         # self.myRubberLine.SetPoints(self.myFirstPoint, self.mySecondPoint)
         # self.myContext.Redisplay(self.myRubberLine, True)
         pass
     elif self.myBSplineCurveAction == BSplineCurveAction.Input_OtherPoints:
         self.myGeom2d_BSplineCurve.SetPole(self.IndexCounter,
                                            self.curPnt2d)
         self.mySecondPoint.SetPnt(
             elclib.To3d(self.curCoordinateSystem.Ax2(), self.curPnt2d))
         self.myGeom_BSplineCurve.SetPole(self.IndexCounter,
                                          self.mySecondPoint.Pnt())
         ME = BRepBuilderAPI_MakeEdge(self.myGeom_BSplineCurve)
         if ME.IsDone():
             self.curEdge = ME.Edge()
             self.myRubberAIS_Shape.Set(self.curEdge)
             self.myContext.Redisplay(self.myRubberAIS_Shape, True)
         else:
             self.IndexCounter -= 1
def pipe():
    # the bspline path, must be a wire
    array2 = TColgp_Array1OfPnt(1, 3)
    array2.SetValue(1, gp_Pnt(0, 0, 0))
    array2.SetValue(2, gp_Pnt(0, 1, 2))
    array2.SetValue(3, gp_Pnt(0, 2, 3))
    bspline2 = GeomAPI_PointsToBSpline(array2).Curve()
    path_edge = BRepBuilderAPI_MakeEdge(bspline2).Edge()
    path_wire = BRepBuilderAPI_MakeWire(path_edge).Wire()

    # the bspline profile. Profile mist be a wire
    array = TColgp_Array1OfPnt(1, 5)
    array.SetValue(1, gp_Pnt(0, 0, 0))
    array.SetValue(2, gp_Pnt(1, 2, 0))
    array.SetValue(3, gp_Pnt(2, 3, 0))
    array.SetValue(4, gp_Pnt(4, 3, 0))
    array.SetValue(5, gp_Pnt(5, 5, 0))
    bspline = GeomAPI_PointsToBSpline(array).Curve()
    profile_edge = BRepBuilderAPI_MakeEdge(bspline).Edge()

    # pipe
    pipe = BRepOffsetAPI_MakePipe(path_wire, profile_edge).Shape()

    display.DisplayShape(profile_edge, update=False)
    display.DisplayShape(path_wire, update=False)
    display.DisplayShape(pipe, update=True)
示例#11
0
def face_mesh_triangle(comp=TopoDS_Shape(), isR=0.1, thA=0.1):
    # Mesh the shape
    BRepMesh_IncrementalMesh(comp, isR, True, thA, True)
    bild1 = BRep_Builder()
    comp1 = TopoDS_Compound()
    bild1.MakeCompound(comp1)
    bt = BRep_Tool()
    ex = TopExp_Explorer(comp, TopAbs_FACE)
    while ex.More():
        face = topods_Face(ex.Current())
        location = TopLoc_Location()
        facing = bt.Triangulation(face, location)
        tab = facing.Nodes()
        tri = facing.Triangles()
        print(facing.NbTriangles(), facing.NbNodes())
        for i in range(1, facing.NbTriangles() + 1):
            trian = tri.Value(i)
            index1, index2, index3 = trian.Get()
            for j in range(1, 4):
                if j == 1:
                    m = index1
                    n = index2
                elif j == 2:
                    n = index3
                elif j == 3:
                    m = index2
                me = BRepBuilderAPI_MakeEdge(tab.Value(m), tab.Value(n))
                if me.IsDone():
                    bild1.Add(comp1, me.Edge())
        ex.Next()
    return comp1
示例#12
0
文件: __init__.py 项目: ocastrup/OCX
 def __init__(self, controlpoints: numpy, knots: numpy, m: int, degree: int,
              periodic: bool):
     super().__init__()
     self.edge = TopAbs_EDGE
     array = []
     for pnt in controlpoints:
         p = OccPoint(pnt)
         array.append(p.Value())
     poles = point_list_to_TColgp_Array1OfPnt(array)
     # Normalise the knots and find multiplicities
     multp = OCCWrapper.OccMultiplicities(knots)
     uknots = multp.knots()
     multiplicity = multp.multiplcity()
     knotvector = TColStd_Array1OfReal(1, len(uknots))
     i = 1
     for v in uknots:
         knotvector.SetValue(i, v)
         i = i + 1
     mult = TColStd_Array1OfInteger(1, len(multiplicity))
     i = 1
     for m in multiplicity:
         mult.SetValue(i, int(m))
         i = i + 1
     mknurbs = Geom_BSplineCurve(poles, knotvector, mult, degree, periodic)
     mkedge = BRepBuilderAPI_MakeEdge(mknurbs)
     if not mkedge.IsDone():
         OCCWrapper.OccError(type(self), mkedge)
     else:
         self.done = True
         self.edge = mkedge.Edge()
     return
示例#13
0
def _make_edge(crv, interval=None) -> Shape:
    aCurve = crv.Curve()
    if interval is None:
        return Shape(BRepBuilderAPI_MakeEdge(aCurve).Edge())
    else:
        return Shape(
            BRepBuilderAPI_MakeEdge(aCurve, interval[0], interval[1]).Edge())
示例#14
0
  def generate_tool_targets(self):
    ba = BRepAdaptor_Curve(self.helix_edge)
    u_min = ba.FirstParameter()
    u_max = ba.LastParameter()
    u_step = 0.1
    u_now = u_min
    while u_now <= u_max:
      v_contact = gp_Vec(ba.Value(u_now).XYZ())
      if self.inside: # cut inside
        v_contact_to_ball_center = -gp_Vec(v_contact.X(),v_contact.Y(),0).Normalized()*self.ball_radius
      else: # cut outside
        v_contact_to_ball_center =  gp_Vec(v_contact.X(),v_contact.Y(),0).Normalized()*self.ball_radius
      trsf = gp_Trsf()
      trsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1)),pi/2)
      v_rotation_axis = v_contact_to_ball_center.Transformed(trsf)
      trsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(v_rotation_axis.XYZ())),radians(self.cutting_angle))
      v_ball_center_to_tool_tip = gp_Vec(0,0,-self.ball_radius)
      v_ball_center_to_tool_tip.Transform(trsf)
      v_tool_tip = v_contact+v_contact_to_ball_center+v_ball_center_to_tool_tip
      v_tool_orientation = - v_ball_center_to_tool_tip.Normalized() * (0.500+1e-8)

      if self.create_target_vis_edges:
        me = BRepBuilderAPI_MakeEdge(gp_Pnt(v_tool_tip.XYZ()),gp_Pnt((v_tool_tip+v_tool_orientation).XYZ()))
        self.target_edges.append(me.Edge())

      I = v_tool_tip.X() / 1000
      J = v_tool_tip.Y() / 1000
      K = v_tool_tip.Z() / 1000

      U = v_tool_orientation.X()
      V = v_tool_orientation.Y()
      W = v_tool_orientation.Z()


      x,y,z,a,b = self.ikSolver.solve((I,J,K,U,V,W),1e-6,False)

      x += self.output_offset[0]
      y += self.output_offset[1]
      z += self.output_offset[2]
      a += self.output_offset[3]
      b += self.output_offset[4]

      if self.v_previous_contact_point:
        cut_distance = (v_contact - self.v_previous_contact_point).Magnitude()
        f = self.feedrate / cut_distance
        self.gcode += "G01 X{:.6f} Y{:.6f} Z{:.6f} A{:.6f} B{:.6f} F{:.6f}\n".format(x,y,z,a,b,f)
      else:
        f = 0
        self.gcode += "G0 X{:.6f} Y{:.6f} Z{:.6f} A{:.6f} B{:.6f}\n".format(x,y,z,a,b)
      self.v_previous_contact_point = v_contact

      print(x,y,z,a,b)

      if u_now == u_max:
        break
      u_next = u_now + u_step
      if u_next > u_max:
        u_next = u_max
      u_now = u_next
示例#15
0
 def __init__(self, p1, p2):
     # Build
     p1 = CheckGeom.to_point(p1)
     p2 = CheckGeom.to_point(p2)
     builder = BRepBuilderAPI_MakeEdge(p1, p2)
     self._e = Edge(builder.Edge())
     self._v1 = Vertex(builder.Vertex1())
     self._v2 = Vertex(builder.Vertex2())
def display_coord(pnt, vecx, vecy, vecz):
    rayx = BRepBuilderAPI_MakeEdge(
        pnt, gp_Pnt((gp_Vec(pnt.XYZ()) + vecx * 10).XYZ())).Edge()
    rayy = BRepBuilderAPI_MakeEdge(
        pnt, gp_Pnt((gp_Vec(pnt.XYZ()) + vecy * 10).XYZ())).Edge()
    rayz = BRepBuilderAPI_MakeEdge(
        pnt, gp_Pnt((gp_Vec(pnt.XYZ()) + vecz * 10).XYZ())).Edge()
    display.DisplayShape(rayx, color='RED', update=False)
    display.DisplayShape(rayy, color='GREEN', update=False)
    display.DisplayShape(rayz, color='BLUE1', update=False)
示例#17
0
def spline_from_polyline(pol):
    from OCC.Extend.ShapeFactory import point_list_to_TColgp_Array1OfPnt, make_face
    from OCC.Core.GeomAPI import GeomAPI_PointsToBSpline
    array = []
    for p in pol:
        array.append(gp_Pnt(p[0], p[1], p[2]))
    pt_list1 = point_list_to_TColgp_Array1OfPnt(array)
    SPL1 = GeomAPI_PointsToBSpline(pt_list1).Curve()
    SPL1 = GeomAPI_PointsToBSpline(pt_list1)
    edge = BRepBuilderAPI_MakeEdge(SPL1.Curve())
    wire = BRepBuilderAPI_MakeWire(edge.Edge())
    return edge.Shape(), wire
示例#18
0
 def display_coord(frames):
     for frame in frames:
         [pnt, vecx, vecy, vecz] = frame
         rayx = BRepBuilderAPI_MakeEdge(pnt, gp_Pnt((gp_Vec(pnt.XYZ()) +\
         vecx*30).XYZ())).Edge()
         rayy = BRepBuilderAPI_MakeEdge(pnt, gp_Pnt((gp_Vec(pnt.XYZ()) +\
          vecy*30).XYZ())).Edge()
         rayz = BRepBuilderAPI_MakeEdge(pnt, gp_Pnt((gp_Vec(pnt.XYZ()) +\
          vecz*30).XYZ())).Edge()
         display.DisplayShape(rayx, color='RED', update=False)
         display.DisplayShape(rayy, color='GREEN', update=False)
         display.DisplayShape(rayz, color='BLUE1', update=False)
示例#19
0
文件: __init__.py 项目: ocastrup/OCX
 def __init__(self, p1: numpy, p2: numpy):
     super().__init__()
     self.done = False
     self.edge = None
     gp1 = gp_Pnt(p1[0], p1[1], p1[2])
     gp2 = gp_Pnt(p2[0], p2[1], p2[2])
     edge = BRepBuilderAPI_MakeEdge(gp1, gp2)
     if not edge.IsDone():
         OCCWrapper.OccError('OccEdge', edge)
     else:
         self.done = True
     self.edge = edge.Edge()
示例#20
0
    def display_assembly(self, assembly, transparency=0.):
        r"""Display an assembly of parts and assemblies

        Parameters
        ----------
        assembly : AssemblyGeometryNode
        transparency : float from 0 to 1

        """
        assembly.build()

        for i, node in enumerate(assembly.nodes()):

            # display a sphere at the barycentre
            from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeSphere
            sphere = BRepPrimAPI_MakeSphere(
                _centre_of_mass(node.node_shape.shape),
                _characteristic_dimension(node.node_shape.shape) / 10.)
            sphere.Build()
            self.display_shape(
                sphere.Shape(),
                # color_=colour_wx_to_occ((randint(0, 255),
                #                          randint(0, 255),
                #                          randint(0, 255))),
                color_=colour_wx_to_occ(color_from_sequence(i, "colors")),
                transparency=transparency)

            # self._display_anchors(assembly.anchors)

        for edge in assembly.edges(data=True):
            start = _centre_of_mass(edge[0].node_shape.shape)  # gp_Pnt
            end = _centre_of_mass(edge[1].node_shape.shape)  # gp_Pnt

            vec = gp_Vec(end.X() - start.X(),
                         end.Y() - start.Y(),
                         end.Z() - start.Z())
            from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeEdge
            e = BRepBuilderAPI_MakeEdge(start, end)

            self.display_shape(e.Shape())

            edge_constraint = assembly.get_edge_data(edge[0],
                                                     edge[1])["object"]

            self.display_message(
                gp_Pnt((start.X() + 2 * end.X()) / 3,
                       (start.Y() + 2 * end.Y()) / 3,
                       (start.Z() + 2 * end.Z()) / 3),
                text_to_write=edge_constraint.__class__.__name__,
                height=13,
                message_color=(0, 0, 0))  # black
        self.viewer_display.FitAll()
示例#21
0
 def circ(self, cntr, rad, constr=False):
     """Create a construction circle """
     cx, cy = cntr
     cntrPt = gp_Pnt(cx, cy, 0)
     ax2 = gp_Ax2(cntrPt, gp_Dir(0, 0, 1))
     geomCirc = Geom_Circle(ax2, rad)
     geomCirc.Transform(self.Trsf)
     if constr:
         self.ccircList.append(geomCirc)
     else:
         edge = BRepBuilderAPI_MakeEdge(Geom_Curve(geomCirc))
         self.wire = BRepBuilderAPI_MakeWire(edge.Edge()).Wire()
         self.wireList.append(self.wire)
示例#22
0
def dao_01_scene(r):

    #compute primitives

    r2 = r/2

    gpPntMinC = gp_Pnt(0,r2,0)

    p0 = gp_Pnt(0,0,0)
    p1 = getPntRotate(gpPntMinC , p0, -pi/4)
    p2 = gp_Pnt(-r2,r2,0)
    p3 = getPntRotate(gpPntMinC , p0, -pi/4*3)
    p4 = gp_Pnt(0,r,0)
    p5 = gp_Pnt(r,0,0)
    p6 = gp_Pnt(0,-r,0)
    p7 = gp_Pnt(r2,-r2,0)

    arc1 =  GC_MakeArcOfCircle(p0,p1,p2).Value()
    arc2 =  GC_MakeArcOfCircle(p2,p3,p4).Value()
    arc3 =  GC_MakeArcOfCircle(p4,p5,p6).Value()
    arc4 =  GC_MakeArcOfCircle(p6,p7,p0).Value()

    edge1 = BRepBuilderAPI_MakeEdge(arc1).Edge()
    edge2 = BRepBuilderAPI_MakeEdge(arc2).Edge()
    edge3 = BRepBuilderAPI_MakeEdge(arc3).Edge()
    edge4 = BRepBuilderAPI_MakeEdge(arc4).Edge()

    daoWire =  BRepBuilderAPI_MakeWire(edge1, edge2, edge3, edge4).Wire()

    # scene template
    sc = new Scene

    # scene transform
    sc.Circle('baseCircle',gp_Pnt(r,0,0), gp_Pnt(0,r,0), gp_Pnt(-r,0,0), 'stInfo')

    sc.Point('p0', p0)
    sc.Point('p1', p0)
    sc.Point('p2', p0)
    sc.Point('p3', p0)
    sc.Point('p4', p0)
    sc.Point('p5', p0)
    sc.Point('p6', p0)
    sc.Point('p7', p0)

    sc.Wire('daoWire', daoWire)

    # styling
    sc.Styling('baseCircle','stInfo')

    return sc
def display_coord(pnts, vecx, vecy, vecz):
    for i in range(0, len(pnts)):
        rayx = BRepBuilderAPI_MakeEdge(
            pnts[i], gp_Pnt(
                (gp_Vec(pnts[i].XYZ()) + vecx[i] * 10).XYZ())).Edge()
        rayy = BRepBuilderAPI_MakeEdge(
            pnts[i], gp_Pnt(
                (gp_Vec(pnts[i].XYZ()) + vecy[i] * 10).XYZ())).Edge()
        rayz = BRepBuilderAPI_MakeEdge(
            pnts[i], gp_Pnt(
                (gp_Vec(pnts[i].XYZ()) + vecz[i] * 10).XYZ())).Edge()
        display.DisplayShape(rayx, color='RED', update=False)
        display.DisplayShape(rayy, color='GREEN', update=False)
        display.DisplayShape(rayz, color='BLUE1', update=False)
示例#24
0
def makeLines():
    global aEdge1, aEdge2, aEdge3
    # Make type 'Geom_TrimmedCurve' from type 'gp_Pnt'
    aArcOfCircle = GC_MakeArcOfCircle(aPnt2, aPnt3, aPnt4)
    aSegment1 = GC_MakeSegment(aPnt1, aPnt2)
    aSegment2 = GC_MakeSegment(aPnt4, aPnt5)
    # Make type 'TopoDS_Edge' from type 'Geom_TrimmedCurve'
    aEdge1 = BRepBuilderAPI_MakeEdge(aSegment1.Value())
    aEdge2 = BRepBuilderAPI_MakeEdge(aArcOfCircle.Value())
    aEdge3 = BRepBuilderAPI_MakeEdge(aSegment2.Value())
    return (aEdge1.Edge(), aEdge2.Edge(), aEdge3.Edge())
    def Compute(self):
        # self.myGeometry = Geom_SurfaceOfRevolution(self.myCurve, self.myRevolveAxis)
        # face = BRepBuilderAPI_MakeFace()
        # face.Init(self.myGeometry, True, 1.0e-6)
        # face.Build()
        profile = self.myCurve.GetGeometry()
        axis = self.myRevolveAxis.GetGeometry().Position()
        edge = BRepBuilderAPI_MakeEdge(profile)
        shape = BRepPrimAPI_MakeRevol(edge.Edge(), axis,
                                      math.radians(self.myAngle)).Shape()

        self.myAIS_InteractiveObject = AIS_Shape(shape)
        self.myContext.Display(self.myAIS_InteractiveObject, True)
        self.SetCenter(shape)
        self.InitClippingPlane()
def constrained_filling(event=None):

    # left
    pts1 = point_list_to_TColgp_Array1OfPnt((gp_Pnt(0, 0, 0.0),
                                             gp_Pnt(0, 1, 0.3),
                                             gp_Pnt(0, 2, -0.3),
                                             gp_Pnt(0, 3, 0.15),
                                             gp_Pnt(0, 4, 0)))
    # front
    pts2 = point_list_to_TColgp_Array1OfPnt((gp_Pnt(0, 0, 0.0),
                                             gp_Pnt(1, 0, -0.3),
                                             gp_Pnt(2, 0, 0.15),
                                             gp_Pnt(3, 0, 0),
                                             gp_Pnt(4, 0, 0)))
    # back
    pts3 = point_list_to_TColgp_Array1OfPnt((gp_Pnt(0, 4, 0),
                                             gp_Pnt(1, 4, 0.3),
                                             gp_Pnt(2, 4, -0.15),
                                             gp_Pnt(3, 4, 0),
                                             gp_Pnt(4, 4, 1)))
    # rechts
    pts4 = point_list_to_TColgp_Array1OfPnt((gp_Pnt(4, 0, 0),
                                             gp_Pnt(4, 1, 0),
                                             gp_Pnt(4, 2, 2),
                                             gp_Pnt(4, 3, -0.15),
                                             gp_Pnt(4, 4, 1)))

    spl1, b1 = get_simple_bound(pts1)
    spl2, b2 = get_simple_bound(pts2)
    spl3, b3 = get_simple_bound(pts3)
    spl4, b4 = get_simple_bound(pts4)

    # build the constrained surface
    bConstrainedFilling = GeomFill_ConstrainedFilling(8, 2)
    bConstrainedFilling.Init(b1, b2, b3, b4, False)
    srf1 = bConstrainedFilling.Surface()

    display.EraseAll()
    for i in [spl1, spl2, spl3, spl4]:
        edg = BRepBuilderAPI_MakeEdge(i)
        edg.Build()
        _edg = edg.Shape()
        display.DisplayShape(_edg)

    f = BRepBuilderAPI_MakeFace(srf1, 1e-6)
    f.Build()
    shp = f.Shape()
    return shp
示例#27
0
def split_edge_with_face(event=None):
    display.EraseAll()
    p0 = gp_Pnt()
    vnorm = gp_Dir(1, 0, 0)
    pln = gp_Pln(p0, vnorm)
    face = BRepBuilderAPI_MakeFace(pln, -10, 10, -10, 10).Face()
    p1 = gp_Pnt(0, 0, 15)
    p2 = gp_Pnt(0, 0, -15)
    edge = BRepBuilderAPI_MakeEdge(p1, p2).Edge()
    # Initialize splitter
    splitter = BOPAlgo_Splitter()
    # Add the edge as an argument and the face as a tool. This will split
    # the edge with the face.
    splitter.AddArgument(edge)
    splitter.AddTool(face)
    splitter.Perform()

    edges = []
    exp = TopExp_Explorer(splitter.Shape(), TopAbs_EDGE)
    while exp.More():
        edges.append(exp.Current())
        exp.Next()
    print('Number of edges in split shape: ', len(edges))
    display.DisplayShape(edges[0], color='red')
    display.DisplayShape(edges[1], color='green')
    display.DisplayShape(edges[2], color='yellow')
    display.FitAll()
示例#28
0
 def display_path(lay, col):
     wire = BRepBuilderAPI_MakeWire()
     for i in range(1, len(lay)):
         if lay[i - 1][0].Distance(lay[i][0]) < 50:
             ray = BRepBuilderAPI_MakeEdge(lay[i - 1][0], lay[i][0]).Edge()
             wire.Add(ray)
     display.DisplayShape(wire.Wire(), color=col, update=False)
示例#29
0
def make_revolved_cylinder(pnt, height, revolve_angle, rotation, wall_thick):
    """
    This method demonstrates how to create a revolved shape from a drawn closed edge.
    It currently creates a hollow cylinder

    adapted from algotopia.com's opencascade_basic tutorial:
    http://www.algotopia.com/contents/opencascade/opencascade_basic

    :param pnt:
    :param height:
    :param revolve_angle:
    :param rotation:
    :param wall_thick:
    :type pnt: dict
    :type height: float
    :type revolve_angle: float
    :type rotation: float
    :type wall_thick: float
    """
    from OCC.Core.BRepBuilderAPI import (
        BRepBuilderAPI_MakeEdge,
        BRepBuilderAPI_MakeFace,
        BRepBuilderAPI_MakeWire,
    )
    from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeRevol
    from OCC.Core.gp import gp_Ax1, gp_Dir, gp_Pnt

    face_inner_radius = pnt["X"] + (17.0 - wall_thick / 2) * 1000
    face_outer_radius = pnt["X"] + (17.0 + wall_thick / 2) * 1000

    # point to create an edge from
    edg_points = [
        gp_Pnt(face_inner_radius, pnt["Y"], pnt["Z"]),
        gp_Pnt(face_inner_radius, pnt["Y"], pnt["Z"] + height),
        gp_Pnt(face_outer_radius, pnt["Y"], pnt["Z"] + height),
        gp_Pnt(face_outer_radius, pnt["Y"], pnt["Z"]),
        gp_Pnt(face_inner_radius, pnt["Y"], pnt["Z"]),
    ]

    # aggregate edges in wire
    hexwire = BRepBuilderAPI_MakeWire()

    for i in range(len(edg_points) - 1):
        hexedge = BRepBuilderAPI_MakeEdge(edg_points[i],
                                          edg_points[i + 1]).Edge()
        hexwire.Add(hexedge)

    hexwire_wire = hexwire.Wire()
    # face from wire
    hexface = BRepBuilderAPI_MakeFace(hexwire_wire).Face()
    revolve_axis = gp_Ax1(gp_Pnt(pnt["X"], pnt["Y"], pnt["Z"]),
                          gp_Dir(0, 0, 1))
    # create revolved shape
    revolved_shape_ = BRepPrimAPI_MakeRevol(hexface, revolve_axis,
                                            np.radians(
                                                float(revolve_angle))).Shape()
    revolved_shape_ = rotate_shp_3_axis(revolved_shape_, revolve_axis,
                                        rotation)

    return revolved_shape_
    def test_inherit_topods_shape(self):
        at = self.assertTrue
        af = self.assertFalse

        class InheritEdge(TopoDS_Edge):
            def __init__(self, edge):
                # following constructor creates an empy TopoDS_Edge
                super(InheritEdge, self).__init__()
                # we need to copy the base shape using the following three
                # lines
                at(self.IsNull())
                self.TShape(edge.TShape())
                self.Location(edge.Location())
                self.Orientation(edge.Orientation())
                af(self.IsNull())
                # then it becomes possible to extend the base class

        # create a line, compute its length
        base_edge = BRepBuilderAPI_MakeEdge(gp_Pnt(100., 0., 0.),
                                            gp_Pnt(150., 0., 0.)).Edge()
        inherited_edge = InheritEdge(base_edge)
        g1 = GProp_GProps()
        brepgprop_LinearProperties(inherited_edge, g1)
        length = g1.Mass()
        self.assertEqual(length, 50.)