示例#1
0
def wpBy3Pts(*args):
    """Direction from pt1 to pt2 sets wDir, pt2 is wpOrigin.
    Direction from pt2 to pt3 sets uDir."""
    prev_uid = win.activeWpUID  # uid of currently active workplane
    if win.ptStack:
        # Finish
        p3 = win.ptStack.pop()
        p2 = win.ptStack.pop()
        p1 = win.ptStack.pop()
        wVec = gp_Vec(p1, p2)
        wDir = gp_Dir(wVec)
        origin = p2
        uVec = gp_Vec(p2, p3)
        uDir = gp_Dir(uVec)
        axis3 = gp_Ax3(origin, wDir, uDir)
        wp = workplane.WorkPlane(100, ax3=axis3)
        new_uid = win.get_wp_uid(wp)
        display_new_active_wp(prev_uid, new_uid)
        win.clearCallback()
    else:
        # Initial setup
        win.registerCallback(wpBy3PtsC)
        display.selected_shape = None
        display.SetSelectionModeVertex()
        statusText = "Pick 3 points. Dir from pt1-pt2 sets wDir, pt2 is origin."
        win.statusBar().showMessage(statusText)
        return
示例#2
0
def get_boundingbox(shape, tol=1e-6, as_vec=False):
    """ return the bounding box of the TopoDS_Shape `shape`

    Parameters
    ----------

    shape : TopoDS_Shape or a subclass such as TopoDS_Face
        the shape to compute the bounding box from

    tol: float
        tolerance of the computed boundingbox

    as_vec : bool
        wether to return the lower and upper point of the bounding box as gp_Vec instances

    Returns
    -------
        if `as_vec` is True, return a tuple of gp_Vec instances
         for the lower and another for the upper X,Y,Z values representing the bounding box

        if `as_vec` is False, return a tuple of lower and then upper X,Y,Z values
         representing the bounding box
    """
    bbox = Bnd_Box()
    bbox.SetGap(tol)
    brepbndlib_Add(shape, bbox)
    xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get()
    if as_vec is False:
        return xmin, ymin, zmin, xmax, ymax, zmax
    else:
        return gp_Vec(xmin, ymin, zmin), gp_Vec(xmax, ymax, zmax)
def brep_feat_rib(event=None):
    mkw = BRepBuilderAPI_MakeWire()

    mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(0., 0., 0.), gp_Pnt(200., 0., 0.)).Edge())
    mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(200., 0., 0.), gp_Pnt(200., 0., 50.)).Edge())
    mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(200., 0., 50.), gp_Pnt(50., 0., 50.)).Edge())
    mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(50., 0., 50.), gp_Pnt(50., 0., 200.)).Edge())
    mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(50., 0., 200.), gp_Pnt(0., 0., 200.)).Edge())
    mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(0., 0., 200.), gp_Pnt(0., 0., 0.)).Edge())

    S = BRepPrimAPI_MakePrism(BRepBuilderAPI_MakeFace(mkw.Wire()).Face(),
                              gp_Vec(gp_Pnt(0., 0., 0.),
                                     gp_Pnt(0., 100., 0.)))
    display.EraseAll()
    #    display.DisplayShape(S.Shape())

    W = BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge(gp_Pnt(50., 45., 100.),
                                                        gp_Pnt(100., 45., 50.)).Edge())

    aplane = Geom_Plane(0., 1., 0., -45.)

    aform = BRepFeat_MakeLinearForm(S.Shape(), W.Wire(), aplane,
                                    gp_Vec(0., 10., 0.), gp_Vec(0., 0., 0.),
                                    1, True)
    aform.Perform()
    display.DisplayShape(aform.Shape())
    display.FitAll()
示例#4
0
def split_compound(compound):
    all_faces = get_faces(compound)
    planar_faces = list(filter(lambda x: Face(x).is_planar(), all_faces))

    p1, v1 = gp_Pnt(50, 50, 25), gp_Vec(0, 0, -1)
    fc1 = make_face(gp_Pln(p1, vec_to_dir(v1)), -1000, 1000, -1000,
                    1000)  # limited, not infinite plane

    bo = BOPAlgo_Builder()
    bo.AddArgument(copy.deepcopy(compound))
    # bo.AddArgument(fc1)

    # display.DisplayShape(fc1, transparency=0.7)
    for f in planar_faces:
        gprop = BRepGProp_Face(f)
        normal_point = gp_Pnt(0, 0, 0)
        normal_vec = gp_Vec(0, 0, 0)
        gprop.Normal(0, 0, normal_point, normal_vec)
        big_face = make_face(gp_Pln(normal_point,
                                    vec_to_dir(normal_vec)), -1000, 1000,
                             -1000, 1000)  # limited, not infinite plane
        bo.AddArgument(big_face)
        # display.DisplayShape(big_face, transparency=0.7)

    bo.Perform()
    # print("error status: {}".format(bo.ErrorStatus()))

    top = Topo(bo.Shape())
    result = [s for s in top.solids()]
    return result
示例#5
0
    def _axis(self, size):

        style = self._axisStyle()

        step = size / 10
        ss = [1, 5, 10, 50, 100, 500, 1000, 5000, 10000]
        for s in ss:
            if step < s:
                step = s / 5
                break

        pnt = gp_Pnt(0, 0, 0)
        dir1 = gp_Dir(gp_Vec(0, 0, 1))
        dir2 = gp_Dir(gp_Vec(1, 0, 0))
        geomAxis = Geom_Axis2Placement(pnt, dir1, dir2)

        trih = AIS_Trihedron(geomAxis)
        trih.SetSize(size)

        self._drawAis(trih, style)

        self._drawPoint(gp_Pnt(0, 0, 0), style)

        cnt = int(size // step)
        for i in range(1, cnt):
            d = i * step
            self._drawPoint(gp_Pnt(d, 0, 0), style)
            self._drawPoint(gp_Pnt(0, d, 0), style)
            self._drawPoint(gp_Pnt(0, 0, d), style)
    def test_surface_from_curves(self):
        '''Test: surfaces from curves'''
        array = []
        array.append(gp_Pnt(-4, 0, 2))
        array.append(gp_Pnt(-7, 2, 2))
        array.append(gp_Pnt(-6, 3, 1))
        array.append(gp_Pnt(-4, 3, -1))
        array.append(gp_Pnt(-3, 5, -2))

        aaa = point_list_to_TColgp_Array1OfPnt(array)
        SPL1 = GeomAPI_PointsToBSpline(aaa).Curve()

        a2 = []
        a2.append(gp_Pnt(-4, 0, 2))
        a2.append(gp_Pnt(-2, 2, 0))
        a2.append(gp_Pnt(2, 3, -1))
        a2.append(gp_Pnt(3, 7, -2))
        a2.append(gp_Pnt(4, 9, -1))
        bbb = point_list_to_TColgp_Array1OfPnt(a2)
        SPL2 = GeomAPI_PointsToBSpline(bbb).Curve()

        aGeomFill1 = GeomFill_BSplineCurves(SPL1, SPL2, GeomFill_StretchStyle)

        SPL3 = Geom_BSplineCurve.DownCast(SPL1.Translated(gp_Vec(10, 0, 0)))
        SPL4 = Geom_BSplineCurve.DownCast(SPL2.Translated(gp_Vec(10, 0, 0)))
        aGeomFill2 = GeomFill_BSplineCurves(SPL3, SPL4, GeomFill_CoonsStyle)

        SPL5 = Geom_BSplineCurve.DownCast(SPL1.Translated(gp_Vec(20, 0, 0)))
        SPL6 = Geom_BSplineCurve.DownCast(SPL2.Translated(gp_Vec(20, 0, 0)))
        aGeomFill3 = GeomFill_BSplineCurves(SPL5, SPL6, GeomFill_CurvedStyle)

        aBSplineSurface1 = aGeomFill1.Surface()
        aBSplineSurface2 = aGeomFill2.Surface()
        aBSplineSurface3 = aGeomFill3.Surface()
 def test_gp_Quaternion(self):
     '''
     Test Interpolate method of qp_QuaternionSLerp.
     This method takes a by ref parameter q.
     '''
     vX = gp_Vec(12, 0, 0)
     vY = gp_Vec(0, 12, 0)
     v45 = (gp_Vec(1, 1, 1).Normalized() * 12)
     q = gp_Quaternion()
     q1 = gp_Quaternion(vX, vX)
     q2 = gp_Quaternion(vX, vY)
     interp = gp_QuaternionSLerp(q1, q2)
     interp.Init(q1, q2)
     for i in range(10):
         i__ = i / 10.
         interp.Interpolate(i__, q)
         if i == 0:
             self.assertEqual(q.X(), 0.)
             self.assertEqual(q.Y(), 0.)
             self.assertEqual(q.Z(), 0.)
             self.assertEqual(q.W(), 1.)
         else:
             self.assertEqual(q.X(), 0.)
             self.assertEqual(q.Y(), 0.)
             assert q.Z() > 0.
             assert q.W() < 1.
示例#8
0
def angle_bw_2_vecs_w_ref(pyvec1, pyvec2, ref_pyvec):
    """
    This function measures the angle between two vectors regards to a reference vector. 
    The reference vector must be perpendicular to both the vectors. The angle is measured in counter-clockwise direction.
 
    Parameters
    ----------
    pyvec1 : tuple of floats
        The first vector to be measured.  A pyvec is a tuple that documents the xyz direction of a vector e.g. (x,y,z)
    
    pyvec2 : tuple of floats
        The second vector to be measured.  A pyvec is a tuple that documents the xyz direction of a vector e.g. (x,y,z)
        
    ref_pyvec : tuple of floats
        The reference vector must be perpendicular to pyvec1 and pyvec2. 
         A pyvec is a tuple that documents the xyz direction of a vector e.g. (x,y,z)

    Returns
    -------
    angle : float
        The measured angle between pyvec1 and pyvec2 regards to ref_pyvec, the angle is measured in counter-clockwise direction.
    """
    vec1 = gp_Vec(pyvec1[0], pyvec1[1], pyvec1[2])
    vec2 = gp_Vec(pyvec2[0], pyvec2[1], pyvec2[2])
    ref_vec = gp_Vec(ref_pyvec[0], ref_pyvec[1], ref_pyvec[2])
    radangle = vec1.AngleWithRef(vec2, ref_vec)
    angle = radangle * (180.0 / math.pi)
    if angle < 0:
        angle = 360 + angle
    #the angle is measured in counter-clockwise direction
    return angle
示例#9
0
def rotate(event=None):
    display.EraseAll()
    origin = gp_Vec(0, 0, 0)
    origin_pt = as_pnt(origin)

    vX = gp_Vec(12, 0, 0)
    vY = gp_Vec(0, 12, 0)
    v45 = (gp_Vec(1, 1, 1).Normalized() * 12)
    q1 = gp_Quaternion(vX, vY)

    p1 = as_pnt(origin + vX)
    p2 = as_pnt(origin + vY)
    p3 = as_pnt(origin + (q1 * vY))
    p4 = as_pnt(origin + (q1 * v45))

    # RED
    e1 = make_edge(origin_pt, p1)
    e2 = make_edge(origin_pt, p2)
    e3 = make_edge(origin_pt, as_pnt(v45))
    # GREEN -> transformed
    e4 = make_edge(origin_pt, p3)
    e5 = make_edge(origin_pt, p4)

    display.DisplayShape([e1, e2, e3])
    display.DisplayColoredShape([e4, e5], 'GREEN')
    display.DisplayMessage(p1, 'e1')
    display.DisplayMessage(p2, 'e2')
    display.DisplayMessage(as_pnt(v45), 'e3')
    display.DisplayMessage(p3, 'q1*vY')
    display.DisplayMessage(p4, 'q1*v45')
    display.DisplayVector((q1 * vY).Normalized(), as_pnt(origin + q1 * vY / 2.))
    display.DisplayVector((q1 * v45).Normalized(), as_pnt(origin + q1 * v45 / 2.))
    display.FitAll()
示例#10
0
    def display_vector(self, origin, direction):
        r"""Display a vector starting at origin and going in direction

        Parameters
        ----------
        origin : tuple(float)
            The origin coordinates (x, y, z) of the vector to display
        direction : tuple(float)
            The direction coordinates (x, y, z) of the vector to display

        """
        xo, yo, zo = origin
        xd, yd, zd = direction
        end = (xo + xd, yo + xd, zo + zd)
        xe, ye, ze = end

        # self.glarea.d3d.DisplayVector(gp_Vec(xd, yd, zd), gp_Pnt(xo, yo, zo))

        presentation = Prs3d_Presentation(self.glarea.occ_context.MainPrsMgr().
                                          GetObject().StructureManager())
        arrow = Prs3d_Arrow()
        arrow.Draw(presentation.GetHandle(), gp_Pnt(xe, ye, ze),
                   gp_Dir(gp_Vec(xd, yd, zd)), _math.radians(20),
                   gp_Vec(xd, yd, zd).Magnitude() / 4.)
        presentation.Display()

        e1 = BRepBuilderAPI_MakeEdge(gp_Pnt(xo, yo, zo), gp_Pnt(xe, ye, ze)).\
            Edge()
        self.display(e1, line_width=4)
示例#11
0
def get_boundingbox(shape, tol=1e-6, as_vec=False):
    """ return the bounding box of the TopoDS_Shape `shape`

    Parameters
    ----------

    shape : TopoDS_Shape or a subclass such as TopoDS_Face
        the shape to compute the bounding box from

    tol: float
        tolerance of the computed boundingbox

    as_vec : bool
        wether to return the lower and upper point of the bounding box as gp_Vec instances

    Returns
    -------
        if `as_vec` is True, return a tuple of gp_Vec instances
         for the lower and another for the upper X,Y,Z values representing the bounding box

        if `as_vec` is False, return a tuple of lower and then upper X,Y,Z values
         representing the bounding box
    """
    bbox = Bnd_Box()
    bbox.SetGap(tol)
    brepbndlib_Add(shape, bbox)
    xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get()
    if as_vec is False:
        return xmin, ymin, zmin, xmax, ymax, zmax
    else:
        return gp_Vec(xmin, ymin, zmin), gp_Vec(xmax, ymax, zmax)
    def test_gp_Quaternion(self):
        '''
        Test Interpolate method of qp_QuaternionSLerp.
        This method takes a by ref parameter q.
        '''
        vX = gp_Vec(12, 0, 0)
        vY = gp_Vec(0, 12, 0)

        q = gp_Quaternion()
        q1 = gp_Quaternion(vX, vX)
        q2 = gp_Quaternion(vX, vY)
        interp = gp_QuaternionSLerp(q1, q2)
        interp.Init(q1, q2)
        for i in range(10):
            i__ = i / 10.
            interp.Interpolate(i__, q)
            if i == 0:
                self.assertEqual(q.X(), 0.)
                self.assertEqual(q.Y(), 0.)
                self.assertEqual(q.Z(), 0.)
                self.assertEqual(q.W(), 1.)
            else:
                self.assertEqual(q.X(), 0.)
                self.assertEqual(q.Y(), 0.)
                self.assertGreater(q.Z(), 0.)
                self.assertLess(q.W(), 1.)
def htransform2(tpnt, tvx, tvy, tvz, pnt, vx, vy, vz):
    tvx = tvy.Crossed(tvz)
    tvy = tvz.Crossed(tvx)
    tvx.Normalize()
    tvy.Normalize()
    tvz.Normalize()
    tpnt = gp_Pnt((gp_Vec(tpnt.XYZ()) + tvz * 0.1).XYZ())
    vx = vy.Crossed(vz)
    vy = vz.Crossed(vx)
    vx.Normalize()
    vy.Normalize()
    vz.Normalize()
    Tt = gp_GTrsf(
        gp_Mat(tvx.X(), tvy.X(), tvz.X(), tvx.Y(), tvy.Y(), tvz.Y(), tvx.Z(),
               tvy.Z(), tvz.Z()), gp_XYZ(tpnt.X(), tpnt.Y(), tpnt.Z()))
    Tt.Invert()
    rott = gp_Mat(tvx.X(), tvy.X(), tvz.X(), tvx.Y(), tvy.Y(), tvz.Y(),
                  tvx.Z(), tvy.Z(), tvz.Z())
    rott.Transpose()
    quatt = gp_Quaternion(rott)
    dispt = gp_Vec(Tt.TranslationPart().X(),
                   Tt.TranslationPart().Y(),
                   Tt.TranslationPart().Z())
    trsft = gp_Trsf()
    trsft.SetTransformation(quatt, dispt)
    rotp = gp_Mat(vx.X(), vy.X(), vz.X(), vx.Y(), vy.Y(), vz.Y(), vx.Z(),
                  vy.Z(), vz.Z())
    quatp = gp_Quaternion(rotp)
    dispp = gp_Vec(gp_Pnt(0, 0, 0), pnt)
    trsfp = gp_Trsf()
    trsfp.SetTransformation(quatp, dispp)
    trsfo = trsfp.Multiplied(trsft)
    loco = TopLoc_Location(trsfo)
    return loco
示例#14
0
def display_anchorable_part(d,
                            ap,
                            color="YELLOW",
                            transparency=0.5,
                            update=True):
    r"""
    
    Parameters
    ----------
    d : display (first return value of a call to
        OCC.Display.SimpleGui.init_display())
    ap : AnchorablePart
    color : str
    transparency : float between 0 and 1
    update : bool

    """
    d.DisplayShape(ap.transformed_shape,
                   color=color,
                   transparency=transparency,
                   update=update)

    for anchor_name, anchor in ap.transformed_anchors.items():
        d.DisplayVector(pnt=gp_Pnt(float(anchor.p[0]), float(anchor.p[1]),
                                   float(anchor.p[2])),
                        vec=gp_Vec(float(anchor.u[0]), float(anchor.u[1]),
                                   float(anchor.u[2])))
        d.DisplayVector(pnt=gp_Pnt(float(anchor.p[0]), float(anchor.p[1]),
                                   float(anchor.p[2])),
                        vec=gp_Vec(float(anchor.v[0]), float(anchor.v[1]),
                                   float(anchor.v[2])))
示例#15
0
def wpBy3Pts(*args):
    """Direction from pt1 to pt2 sets wDir, pt2 is wpOrigin.
    Direction from pt2 to pt3 sets uDir."""
    if win.ptStack:
        # Finish
        p3 = win.ptStack.pop()
        p2 = win.ptStack.pop()
        p1 = win.ptStack.pop()
        wVec = gp_Vec(p1, p2)
        wDir = gp_Dir(wVec)
        origin = p2
        uVec = gp_Vec(p2, p3)
        uDir = gp_Dir(uVec)
        axis3 = gp_Ax3(origin, wDir, uDir)
        wp = workplane.WorkPlane(100, ax3=axis3)
        win.getNewPartUID(wp, typ='w')
        win.clearCallback()
        statusText = "Workplane created."
        win.statusBar().showMessage(statusText)
    else:
        # Initial setup
        win.registerCallback(wpBy3PtsC)
        display.selected_shape = None
        display.SetSelectionModeVertex()
        statusText = "Pick 3 points. Dir from pt1-pt2 sets wDir, pt2 is origin."
        win.statusBar().showMessage(statusText)
        return
示例#16
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
示例#17
0
    def test_constructor(self):
        self.assertEqual(point3(0, 0, 1), point3(gp_Dir(0, 0, 1)))
        self.assertEqual(point3(0, 1, 1), point3(gp_Vec(0, 1, 1)))
        self.assertEqual(point3(1, 0, 1), point3(gp_Pnt(1, 0, 1)))

        self.assertEqual(vector3(0, 0, 1), vector3(gp_Dir(0, 0, 1)))
        self.assertEqual(vector3(0, 1, 1), vector3(gp_Vec(0, 1, 1)))
        self.assertEqual(vector3(1, 0, 1), vector3(gp_Pnt(1, 0, 1)))
示例#18
0
def getPntSectionUp(pnt1, pnt2):
    v1 = gp_Vec(pnt1, pnt2)
    v1.Scale(0.5)
    v2 = gp_Vec(0,0,v1.Magnitude())
    pnt = gp_Pnt(pnt1.XYZ())
    pnt.Translate(v1)
    pnt.Translate(v2)
    return pnt
示例#19
0
def axs_pln(axs):
    pnt = axs.Location()
    vx = dir_to_vec(axs.XDirection()).Scaled(100)
    vy = dir_to_vec(axs.YDirection()).Scaled(200)
    vz = dir_to_vec(axs.Direction()).Scaled(300)
    lx = make_edge(pnt, gp_Pnt((gp_Vec(pnt.XYZ()) + vx).XYZ()))
    ly = make_edge(pnt, gp_Pnt((gp_Vec(pnt.XYZ()) + vy).XYZ()))
    lz = make_edge(pnt, gp_Pnt((gp_Vec(pnt.XYZ()) + vz).XYZ()))
    return lx, ly, lz
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)
示例#21
0
def set_obj(meta, xyz, dx, dy, pln_set=[-200, 200, -200, 200], indx=1):
    vx = gp_Vec(*dx).Normalized()
    vy = gp_Vec(*dy).Normalized()
    vz = vx.Crossed(vy)
    meta["pnt"] = gp_Pnt(*xyz)
    meta["xyz"] = [vx, vy, vz]
    meta["pln"] = make_plane(meta["pnt"], meta["xyz"][2], *pln_set)
    meta["pts"] = shape_to_pts(meta["pln"])
    meta["frm"] = set_wire(meta["pts"])
    meta["idx"] = indx
def get_point(bsurf, u, v):
    pnt = gp_Pnt()
    bx = gp_Vec()
    by = gp_Vec()
    bsurf.D1(u, v, pnt, bx, by)
    bz = bx.Crossed(by)
    bx = bx.Normalized()
    by = by.Normalized()
    bz = bz.Normalized()
    return pnt, bx, by, bz
示例#23
0
def midpoint(pntA, pntB):
    '''
    computes the point that lies in the middle between pntA and pntB
    @param pntA:    gp_Pnt
    @param pntB:    gp_Pnt
    '''
    vec1 = gp_Vec(pntA.XYZ())
    vec2 = gp_Vec(pntB.XYZ())
    veccie = (vec1 + vec2) / 2.
    return gp_Pnt(veccie.XYZ())
示例#24
0
 def read_points(csv_name):
     readCSV = pd.read_csv(csv_name, sep=',', header=None, dtype=float)
     values = readCSV.values
     points = []
     for j in range(0, len(values)):
         points.append([gp_Pnt(values[j][0]+700,values[j][1],values[j][2]+600),\
         gp_Vec(values[j][3],values[j][4],values[j][5]),\
         gp_Vec(values[j][6],values[j][7],values[j][8]),\
         gp_Vec(values[j][9],values[j][10],values[j][11])])
     return points
示例#25
0
    def drawTrihedron(self, objName, size):
        gpPnt = gp_Pnt(0, 0, 0)
        gpDir1 = gp_Dir(gp_Vec(0, 0, 1))
        gpDir2 = gp_Dir(gp_Vec(1, 0, 0))
        geomAxis = Geom_Axis2Placement(gpPnt, gpDir1, gpDir2)

        trih = AIS_Trihedron(geomAxis)
        trih.SetSize(11)

        self._drawNative(objName, trih)
 def get_point_on_curve(bcurve, u):
     point = gp_Pnt()
     tangenty = gp_Vec()
     bcurve.D1(u, point, tangenty)
     vectorz = gp_Vec(0, 0, 1)
     vectorx = tangenty.Crossed(vectorz)
     vectorz = vectorx.Crossed(tangenty)
     vectorx.Normalize()
     tangenty.Normalize()
     vectorz.Normalize()
     return [point, vectorx, tangenty, vectorz]
示例#27
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)
示例#28
0
def second_derivative(h_surf, u=0, v=0):
    p1 = gp_Pnt()
    pu, pv = gp_Vec(), gp_Vec()
    puu, pvv = gp_Vec(), gp_Vec()
    puv = gp_Vec()
    prop = GeomLProp_SLProps(h_surf, u, v, 1, 1)
    GeomLProp_SurfaceTool.D2(h_surf, u, v, p1, pu, pv, puu, pvv, puv)
    e0 = pu.Crossed(pv)
    pu.Normalize()
    pv.Normalize()
    e0.Normalize()
    puu.Normalize()
    pvv.Normalize()
    puv.Normalize()
    print(p1)
    print("pu", pu)
    print("pv", pv)
    print("e0", e0)
    print("puu", puu)
    print("pvv", pvv)
    print("puv", puv)

    first_form = np.array([[pu.Dot(pu), pu.Dot(pv)], [pv.Dot(pu), pv.Dot(pv)]])
    secnd_form = np.array([[e0.Dot(puu), e0.Dot(puv)],
                           [e0.Dot(puv), e0.Dot(pvv)]])

    print(first_form)
    print(secnd_form)
    print(prop.GaussianCurvature())
    print(prop.MeanCurvature())
    d1, d2 = gp_Dir(), gp_Dir()
    prop.CurvatureDirections(d1, d2)
    a1 = gp_Ax3()
    v1 = dir_to_vec(d1)
    v2 = dir_to_vec(d2)
    if pu.IsParallel(v1, 1 / 1000):
        c1 = prop.MaxCurvature()
        c2 = prop.MinCurvature()
        print(v1.Dot(pu), v1.Dot(pv))
        print(v2.Dot(pu), v2.Dot(pv))
    else:
        c1 = prop.MinCurvature()
        c2 = prop.MaxCurvature()
        print(v1.Dot(pu), v1.Dot(pv))
        print(v2.Dot(pu), v2.Dot(pv))
    print(c1, 1 / c1)
    print(c2, 1 / c2)

    px = np.linspace(-1, 1, 100) * 100
    p1_y = px**2 / c1
    p2_y = px**2 / c1
    curv1 = curv_spl(px, p1_y)
    curv2 = curv_spl(px, p2_y)
示例#29
0
def surface_from_curves():
    '''
    @param display:
    '''
    # First spline
    array = []
    array.append(gp_Pnt(-4, 0, 2))
    array.append(gp_Pnt(-7, 2, 2))
    array.append(gp_Pnt(-6, 3, 1))
    array.append(gp_Pnt(-4, 3, -1))
    array.append(gp_Pnt(-3, 5, -2))

    pt_list1 = point_list_to_TColgp_Array1OfPnt(array)
    SPL1 = GeomAPI_PointsToBSpline(pt_list1).Curve()
    SPL1_c = SPL1.GetObject()

    # Second spline
    a2 = []
    a2.append(gp_Pnt(-4, 0, 2))
    a2.append(gp_Pnt(-2, 2, 0))
    a2.append(gp_Pnt(2, 3, -1))
    a2.append(gp_Pnt(3, 7, -2))
    a2.append(gp_Pnt(4, 9, -1))
    pt_list2 = point_list_to_TColgp_Array1OfPnt(a2)
    SPL2 = GeomAPI_PointsToBSpline(pt_list2).Curve()
    SPL2_c = SPL2.GetObject()

    # Fill with StretchStyle
    aGeomFill1 = GeomFill_BSplineCurves(SPL1,
                                        SPL2,
                                        GeomFill_StretchStyle)

    SPL3 = Handle_Geom_BSplineCurve_DownCast(SPL1_c.Translated(gp_Vec(10, 0, 0)))
    SPL4 = Handle_Geom_BSplineCurve_DownCast(SPL2_c.Translated(gp_Vec(10, 0, 0)))
    # Fill with CoonsStyle
    aGeomFill2 = GeomFill_BSplineCurves(SPL3,
                                        SPL4,
                                        GeomFill_CoonsStyle)
    SPL5 = Handle_Geom_BSplineCurve_DownCast(SPL1_c.Translated(gp_Vec(20, 0, 0)))
    SPL6 = Handle_Geom_BSplineCurve_DownCast(SPL2_c.Translated(gp_Vec(20, 0, 0)))
    # Fill with CurvedStyle
    aGeomFill3 = GeomFill_BSplineCurves(SPL5,
                                        SPL6,
                                        GeomFill_CurvedStyle)

    aBSplineSurface1 = aGeomFill1.Surface()
    aBSplineSurface2 = aGeomFill2.Surface()
    aBSplineSurface3 = aGeomFill3.Surface()
    
    display.DisplayShape(make_face(aBSplineSurface1, 1e-6))
    display.DisplayShape(make_face(aBSplineSurface2, 1e-6))
    display.DisplayShape(make_face(aBSplineSurface3, 1e-6), update=True)
示例#30
0
def make_plane(center=gp_Pnt(0, 0, 0),
               vec_normal=gp_Vec(0, 0, 1),
               extent_x_min=-100.,
               extent_x_max=100.,
               extent_y_min=-100.,
               extent_y_max=100.,
               depth=0.):
    if depth != 0:
        center = center.add_vec(gp_Vec(0, 0, depth))
    PL = gp_Pln(center, vec_normal.as_dir())
    face = make_face(PL, extent_x_min, extent_x_max, extent_y_min,
                     extent_y_max)
    return face
示例#31
0
def midpoint(pntA, pntB):
    """ computes the point that lies in the middle between pntA and pntB
    Parameters
    ----------
    pntA, pntB : gp_Pnt
    Returns
    -------
    gp_Pnt
    """
    vec1 = gp_Vec(pntA.XYZ())
    vec2 = gp_Vec(pntB.XYZ())
    veccie = (vec1 + vec2) * 0.5
    return gp_Pnt(veccie.XYZ())
示例#32
0
def reflect(p0, v0, face):
    h_surf = BRep_Tool.Surface(face)
    ray = Geom_Line(gp_Lin(p0, vec_to_dir(v0)))
    uvw = GeomAPI_IntCS(ray.GetHandle(), h_surf).Parameters(1)
    u, v, w = uvw
    p1, vx, vy = gp_Pnt(), gp_Vec(), gp_Vec()
    GeomLProp_SurfaceTool.D1(h_surf, u, v, p1, vx, vy)
    vz = vx.Crossed(vy)
    vx.Normalize()
    vy.Normalize()
    vz.Normalize()
    v1 = v0.Mirrored(gp_Ax2(p1, vec_to_dir(vz)))
    return p1, v1
示例#33
0
def midpoint(pntA, pntB):
    """ computes the point that lies in the middle between pntA and pntB

    Parameters
    ----------

    pntA, pntB : gp_Pnt

    Returns
    -------

    gp_Pnt

    """
    vec1 = gp_Vec(pntA.XYZ())
    vec2 = gp_Vec(pntB.XYZ())
    veccie = (vec1 + vec2) * 0.5
    return gp_Pnt(veccie.XYZ())
示例#34
0
def make_extrusion(face, length, vector=gp_Vec(0., 0., 1.)):
    ''' creates a extrusion from a face, along the vector vector.
    with a distance legnth. Note that the normal vector does not
    necessary be normalized.
    By default, the extrusion is along the z axis.
    '''
    vector.Normalize()
    vector.Scale(length)
    return BRepPrimAPI_MakePrism(face, vector).Shape()
    def test_surface_from_curves(self):
        '''Test: surfaces from curves'''
        array = []
        array.append(gp_Pnt(-4, 0, 2))
        array.append(gp_Pnt(-7, 2, 2))
        array.append(gp_Pnt(-6, 3, 1))
        array.append(gp_Pnt(-4, 3, -1))
        array.append(gp_Pnt(-3, 5, -2))

        aaa = point_list_to_TColgp_Array1OfPnt(array)
        SPL1 = GeomAPI_PointsToBSpline(aaa).Curve()

        a2 = []
        a2.append(gp_Pnt(-4, 0, 2))
        a2.append(gp_Pnt(-2, 2, 0))
        a2.append(gp_Pnt(2, 3, -1))
        a2.append(gp_Pnt(3, 7, -2))
        a2.append(gp_Pnt(4, 9, -1))
        bbb = point_list_to_TColgp_Array1OfPnt(a2)
        SPL2 = GeomAPI_PointsToBSpline(bbb).Curve()

        aGeomFill1 = GeomFill_BSplineCurves(SPL1,
                                            SPL2,
                                            GeomFill_StretchStyle)

        SPL3 = Geom_BSplineCurve.DownCast(SPL1.Translated(gp_Vec(10, 0, 0)))
        SPL4 = Geom_BSplineCurve.DownCast(SPL2.Translated(gp_Vec(10, 0, 0)))
        aGeomFill2 = GeomFill_BSplineCurves(SPL3,
                                            SPL4,
                                            GeomFill_CoonsStyle)

        SPL5 = Geom_BSplineCurve.DownCast(SPL1.Translated(gp_Vec(20, 0, 0)))
        SPL6 = Geom_BSplineCurve.DownCast(SPL2.Translated(gp_Vec(20, 0, 0)))
        aGeomFill3 = GeomFill_BSplineCurves(SPL5,
                                            SPL6,
                                            GeomFill_CurvedStyle)

        aBSplineSurface1 = aGeomFill1.Surface()
        self.assertTrue(aBSplineSurface1 is not None)
        aBSplineSurface2 = aGeomFill2.Surface()
        self.assertTrue(aBSplineSurface2 is not None)
        aBSplineSurface3 = aGeomFill3.Surface()
        self.assertTrue(aBSplineSurface3 is not None)
    def test_pipes(self):
        '''Test: pipes'''
        a1 = []
        a1.append(gp_Pnt(-4, 0, 2))
        a1.append(gp_Pnt(-5, 1, 0))
        a1.append(gp_Pnt(-6, 2, -2))
        a1.append(gp_Pnt(-5, 4, -7))
        a1.append(gp_Pnt(-3, 5, -12))

        xxx = point_list_to_TColgp_Array1OfPnt(a1)
        SPL1 = GeomAPI_PointsToBSpline(xxx).Curve()

        aPipe = GeomFill_Pipe(SPL1, True)
        aPipe.Perform(False, False)
        aSurface = aPipe.Surface()
        self.assertIsNotNone(aSurface)

        E = GC_MakeEllipse(gp_XOY(), 2, 1).Value()
        aPipe2 = GeomFill_Pipe(SPL1, E, GeomFill_IsConstantNormal)
        aPipe2.Perform(False, False)
        aSurface2 = aPipe2.Surface()
        aSurface2.Translate(gp_Vec(5, 0, 0))

        TC1 = GC_MakeSegment(gp_Pnt(1, 1, 1), gp_Pnt(2, 2, 2)).Value()
        TC2 = GC_MakeSegment(gp_Pnt(1, 1, 0), gp_Pnt(3, 2, 1)).Value()
        aPipe3 = GeomFill_Pipe(SPL1, TC1, TC2)
        aPipe3.Perform(False, False)
        aSurface3 = aPipe3.Surface()
        aSurface3.Translate(gp_Vec(10, 0, 0))

        for _, mode in enumerate([GeomFill_IsConstantNormal,
                                  GeomFill_IsCorrectedFrenet,
                                  GeomFill_IsDarboux,
                                  GeomFill_IsFrenet,
                                  GeomFill_IsGuideAC,
                                  GeomFill_IsGuideACWithContact,
                                  GeomFill_IsGuidePlan,
                                  GeomFill_IsGuidePlanWithContact]):
            E = GC_MakeEllipse(gp_XOY(), 2, 1).Value()
            aPipe2 = GeomFill_Pipe(SPL1, TC1, TC2, mode)
            aPipe2.Perform(False, False)
            aSurface2 = aPipe2.Surface()
            aSurface2.Translate(gp_Vec(5, 5, 0))
示例#37
0
    def DisplayVector(self, vec, pnt, update=False):
        """ displays a vector as an arrow
        """
        if self._inited:
            aPresentation = Prs3d_Presentation(self._struc_mgr)

            pnt_as_vec = gp_Vec(pnt.X(), pnt.Y(), pnt.Z())
            start = pnt_as_vec + vec
            pnt_start = gp_Pnt(start.X(), start.Y(), start.Z())

            Prs3d_Arrow.Draw(
                aPresentation.GetHandle(),
                pnt_start,
                gp_Dir(vec),
                math.radians(20),
                vec.Magnitude()
            )
            aPresentation.Display()
            # it would be more coherent if a AIS_InteractiveObject
            # would be returned
            if update:
                self.Repaint()
            return aPresentation
 def test_gp_Vec_operators(self):
     '''
     Test gp_Vec division by a float number or an integer
     This test fails on py3k with SWIG versions older than 3.0.8
     SWIG 3.0.9 fixes this issue.
     See https://github.com/tpaviot/pythonocc-core/issues/257
     '''
     # division by a float
     v1 = gp_Vec(2., 2., 2.)
     v2 = v1 / 2.
     self.assertEqual(v2.Magnitude(), sqrt(3.))
     # division by an integer
     v3 = gp_Vec(4, 4, 4)
     v4 = v3 / 2
     self.assertEqual((v4.X(), v4.Y(), v4.Z()), (2, 2, 2))
     # adding two gp_Vec
     v5 = gp_Vec(1, 2, 3) + gp_Vec(4, 5, 6)
     self.assertEqual((v5.X(), v5.Y(), v5.Z()), (5, 7, 9))
     # substracting two gp_Vec
     v6 = gp_Vec(1, 2, 3) - gp_Vec(6, 5, 4)
     self.assertEqual((v6.X(), v6.Y(), v6.Z()), (-5, -3, -1))
    def test_bezier_surfaces(self):
        '''Test: Bezier surfaces'''
        array1 = TColgp_Array2OfPnt(1, 3, 1, 3)
        array2 = TColgp_Array2OfPnt(1, 3, 1, 3)
        array3 = TColgp_Array2OfPnt(1, 3, 1, 3)
        array4 = TColgp_Array2OfPnt(1, 3, 1, 3)

        array1.SetValue(1, 1, gp_Pnt(1, 1, 1))
        array1.SetValue(1, 2, gp_Pnt(2, 1, 2))
        array1.SetValue(1, 3, gp_Pnt(3, 1, 1))
        array1.SetValue(2, 1, gp_Pnt(1, 2, 1))
        array1.SetValue(2, 2, gp_Pnt(2, 2, 2))
        array1.SetValue(2, 3, gp_Pnt(3, 2, 0))
        array1.SetValue(3, 1, gp_Pnt(1, 3, 2))
        array1.SetValue(3, 2, gp_Pnt(2, 3, 1))
        array1.SetValue(3, 3, gp_Pnt(3, 3, 0))

        array2.SetValue(1, 1, gp_Pnt(3, 1, 1))
        array2.SetValue(1, 2, gp_Pnt(4, 1, 1))
        array2.SetValue(1, 3, gp_Pnt(5, 1, 2))
        array2.SetValue(2, 1, gp_Pnt(3, 2, 0))
        array2.SetValue(2, 2, gp_Pnt(4, 2, 1))
        array2.SetValue(2, 3, gp_Pnt(5, 2, 2))
        array2.SetValue(3, 1, gp_Pnt(3, 3, 0))
        array2.SetValue(3, 2, gp_Pnt(4, 3, 0))
        array2.SetValue(3, 3, gp_Pnt(5, 3, 1))

        array3.SetValue(1, 1, gp_Pnt(1, 3, 2))
        array3.SetValue(1, 2, gp_Pnt(2, 3, 1))
        array3.SetValue(1, 3, gp_Pnt(3, 3, 0))
        array3.SetValue(2, 1, gp_Pnt(1, 4, 1))
        array3.SetValue(2, 2, gp_Pnt(2, 4, 0))
        array3.SetValue(2, 3, gp_Pnt(3, 4, 1))
        array3.SetValue(3, 1, gp_Pnt(1, 5, 1))
        array3.SetValue(3, 2, gp_Pnt(2, 5, 1))
        array3.SetValue(3, 3, gp_Pnt(3, 5, 2))

        array4.SetValue(1, 1, gp_Pnt(3, 3, 0))
        array4.SetValue(1, 2, gp_Pnt(4, 3, 0))
        array4.SetValue(1, 3, gp_Pnt(5, 3, 1))
        array4.SetValue(2, 1, gp_Pnt(3, 4, 1))
        array4.SetValue(2, 2, gp_Pnt(4, 4, 1))
        array4.SetValue(2, 3, gp_Pnt(5, 4, 1))
        array4.SetValue(3, 1, gp_Pnt(3, 5, 2))
        array4.SetValue(3, 2, gp_Pnt(4, 5, 2))
        array4.SetValue(3, 3, gp_Pnt(5, 5, 1))

        BZ1, BZ2, BZ3, BZ4 = map(Geom_BezierSurface, [array1, array2,
                                                      array3, array4])

        bezierarray = TColGeom_Array2OfBezierSurface(1, 2, 1, 2)
        bezierarray.SetValue(1, 1, BZ1)
        bezierarray.SetValue(1, 2, BZ2)
        bezierarray.SetValue(2, 1, BZ3)
        bezierarray.SetValue(2, 2, BZ4)

        BB = GeomConvert_CompBezierSurfacesToBSplineSurface(bezierarray)
        self.assertTrue(BB.IsDone())
        poles = BB.Poles().Array2()
        uknots = BB.UKnots().Array1()
        vknots = BB.VKnots().Array1()
        umult = BB.UMultiplicities().Array1()
        vmult = BB.VMultiplicities().Array1()
        udeg = BB.UDegree()
        vdeg = BB.VDegree()

        BSPLSURF = Geom_BSplineSurface(poles, uknots, vknots, umult, vmult, udeg, vdeg, False, False)
        BSPLSURF.Translate(gp_Vec(0, 0, 2))
示例#40
0
            fp.write("".join(edge_string_list))
            # then write header part 2
            fp.write(BODY_Part2)
            fp.write("</html>\n")

    def render(self, server_port=8080, open_webbrowser=False):
        ''' render the scene into the browser.
        '''
        # generate HTML file
        self.GenerateHTMLFile()
        # then create a simple web server
        start_server(server_port, self._path, open_webbrowser)

if __name__ == "__main__":
    from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox, BRepPrimAPI_MakeTorus
    from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_Transform
    from OCC.Core.gp import gp_Trsf, gp_Vec
    def translate_shp(shp, vec, copy=False):
        trns = gp_Trsf()
        trns.SetTranslation(vec)
        brep_trns = BRepBuilderAPI_Transform(shp, trns, copy)
        brep_trns.Build()
        return brep_trns.Shape()
    box = BRepPrimAPI_MakeBox(100., 200., 300.).Shape()
    torus = BRepPrimAPI_MakeTorus(300., 105).Shape()
    t_torus = translate_shp(torus, gp_Vec(700, 0, 0))
    my_ren = ThreejsRenderer()
    my_ren.DisplayShape(box)
    my_ren.DisplayShape(t_torus)
    my_ren.render()