def test_axis(self):
     '''Test: axis'''
     P1 = gp_Pnt(2, 3, 4)
     D = gp_Dir(4, 5, 6)
     A = gp_Ax3(P1, D)
     IsDirectA = A.Direct()
     self.assertTrue(IsDirectA)
     AXDirection = A.XDirection()
     self.assertIsInstance(AXDirection, gp_Dir)
     AYDirection = A.YDirection()
     self.assertIsInstance(AXDirection, gp_Dir)
     P2 = gp_Pnt(5, 3, 4)
     A2 = gp_Ax3(P2, D)
     A2.YReverse()
     # axis3 is now left handed
     IsDirectA2 = A2.Direct()
     self.assertFalse(IsDirectA2)
     A2XDirection = A2.XDirection()
     self.assertTrue(isinstance(A2XDirection, gp_Dir))
     A2YDirection = A2.YDirection()
     self.assertTrue(isinstance(A2YDirection, gp_Dir))
Beispiel #2
0
def occ_to_grasp_rim(axs, pts, filename="pln.rim", name="name", nxy=5):
    pnt = axs.Location()
    trf = gp_Trsf()
    trf.SetTransformation(gp_Ax3(), axs)
    px, py = [], []
    for i in range(len(pts)):
        i0, i1 = i, (i + 1) % len(pts)
        p0, p1 = pts[i0].Transformed(trf), pts[i1].Transformed(trf)
        p_x = np.delete(np.linspace(p0.X(), p1.X(), nxy), -1)
        p_y = np.delete(np.linspace(p0.Y(), p1.Y(), nxy), -1)
        px.extend(p_x), py.extend(p_y)

    fp = open(filename, "w")
    fp.write(' {:s}\n'.format(name))
    fp.write('{:12d}{:12d}{:12d}\n'.format(len(px), 1, 1))
    #fp.write(' {:s}\n'.format("mm"))
    for i in range(len(px)):
        data = [px[i], py[i]]
        fp.write(''.join([float_to_string(val) for val in data]) + '\n')
Beispiel #3
0
 def export_sfc2_axs(self,
                     nxy=[200, 200],
                     rx=[-250, 250],
                     ry=[-250, 250],
                     sfcfile="pln1_mat.sfc"):
     trsf = set_trf(gp_Ax3(), self.axs)
     nx, ny = nxy
     xs, xe = rx
     ys, ye = ry
     plnx = np.linspace(xs, xe, nx)
     plny = np.linspace(ys, ye, ny)
     mesh = np.meshgrid(plnx, plny)
     data = np.zeros_like(mesh[0])
     for (ix, iy), x in np.ndenumerate(data):
         px, py = mesh[0][ix, iy], mesh[1][ix, iy]
         p0 = gp_Pnt(px, py, 0).Transformed(trsf)
         p1 = dispocc.proj_pnt_pln(self, p0, self.surf, self.axs)
         z = p0.Distance(p1)
         data[ix, iy] = z
     grasp_sfc(mesh, data, sfcfile)
Beispiel #4
0
    def __init__(self, pnt=gp_Pnt(-10, 0, -10), vec=gp_Vec(10, 20, 100)):
        plotocc.__init__(self)
        self.solver = ode(self.newton).set_integrator('dopri5')
        self.initial_conditions = self.gen_condition(pnt, vec)
        self.m = 10.0
        self.k = 0.0
        ray = spl_2pnt()

        px = np.linspace(-1, 1, 50) * 750
        py = np.linspace(-1, 1, 50) * 750
        mesh = np.meshgrid(px, py)
        surf = mesh[0]**2 / 500 + mesh[1]**2 / 750

        self.grd_axs = gp_Ax3(gp_Pnt(0, 0, 0), gp_Dir(-0.25, 0, 1))
        #self.grd = pln_for_axs(self.grd_axs, [500, 500])
        self.grd = spl_face(*mesh, surf)
        self.h_surf = BRep_Tool.Surface(self.grd)
        self.p_trce = GeomAPI_IntCS(ray, self.h_surf)

        self.pts, self.vel = [], []
Beispiel #5
0
 def test_point_from_projections(self):
     '''Test: point from projections'''
     P = gp_Pnt(7., 8., 9.)
     radius = 5
     SP = Geom_SphericalSurface(gp_Ax3(gp_XOY()), radius)
     PPS = GeomAPI_ProjectPointOnSurf(P, SP)
     N = PPS.NearestPoint()
     self.assertTrue(isinstance(N, gp_Pnt))
     NbResults = PPS.NbPoints()
     if NbResults > 0:
         for i in range(1, NbResults + 1):
             Q = PPS.Point(i)
             self.assertTrue(isinstance(Q, gp_Pnt))
             distance = PPS.Distance(i)
     pstring = "N  : at Distance : " + repr(PPS.LowerDistance())
     if NbResults > 0:
         for i in range(1, NbResults + 1):
             Q = PPS.Point(i)
             distance = PPS.Distance(i)
             pstring = "Q" + repr(i) + ": at Distance :" + repr(
                 PPS.Distance(i))
Beispiel #6
0
 def test_points_from_intersection(self):
     '''Test: points from intersection'''
     PL = gp_Pln(gp_Ax3(gp_XOY()))
     MinorRadius, MajorRadius = 5, 8
     EL = gp_Elips(gp_YOZ(), MajorRadius, MinorRadius)
     ICQ = IntAna_IntConicQuad(EL, PL, precision_Angular(),
                               precision_Confusion())
     if ICQ.IsDone():
         NbResults = ICQ.NbPoints()
         if NbResults > 0:
             for i in range(1, NbResults + 1):
                 P = ICQ.Point(i)
     aPlane = GC_MakePlane(PL).Value()
     aSurface = Geom_RectangularTrimmedSurface(aPlane, -8., 8., -12., 12.,
                                               True, True)
     anEllips = GC_MakeEllipse(EL).Value()
     if ICQ.IsDone():
         NbResults = ICQ.NbPoints()
         if NbResults > 0:
             for i in range(1, NbResults + 1):
                 P = ICQ.Point(i)
                 pstring = "P%i" % i
Beispiel #7
0
    def mirrorInPlane(self, listOfShapes, axis="X"):

        local_coord_system = gp_Ax3(self.origin.toPnt(), self.zDir.toDir(),
                                    self.xDir.toDir())
        T = gp_Trsf()

        if axis == "X":
            T.SetMirror(
                gp_Ax1(self.origin.toPnt(), local_coord_system.XDirection()))
        elif axis == "Y":
            T.SetMirror(
                gp_Ax1(self.origin.toPnt(), local_coord_system.YDirection()))
        else:
            raise NotImplementedError

        resultWires = []
        for w in listOfShapes:
            mirrored = w.transformShape(Matrix(T))

            # attemp stitching of the wires
            resultWires.append(mirrored)

        return resultWires
Beispiel #8
0
 def check_ground(self):
     if len(self.pts) != 1:
         ray = spl_2pnt(self.pts[-2], self.pts[-1])
         vec = gp_Vec(self.pts[-2], self.pts[-1])
         self.p_trce.Perform(ray, self.h_surf)
         if self.p_trce.NbPoints() != 0 and vec.Z() < 0:
             print()
             uvw = self.p_trce.Parameters(1)
             u, v, w = uvw
             p0, v0 = gp_Pnt(), gp_Vec()
             GeomLProp_CurveTool.D1(ray, w, p0, v0)
             p1, vx, vy = gp_Pnt(), gp_Vec(), gp_Vec()
             GeomLProp_SurfaceTool.D1(self.h_surf, u, v, p1, vx, vy)
             vz = vx.Crossed(vy)
             self.pts[-1] = p0
             print(self.r.t, w, p0)
             print(v0)
             print(gp_Vec(self.pts[-2], self.pts[-1]))
             norm = gp_Ax3(p1, vec_to_dir(vz), vec_to_dir(vx))
             v1 = v0
             v1.Mirror(norm.Ax2())
             self.r.set_initial_value(self.gen_condition(p0, v1),
                                      self.r.t + self.dt)
 def test_point_from_projections(self):
     '''Test: point from projections'''
     P = gp_Pnt(7., 8., 9.)
     radius = 5
     SP = Geom_SphericalSurface(gp_Ax3(gp_XOY()), radius)
     PPS = GeomAPI_ProjectPointOnSurf(P, SP)
     N = PPS.NearestPoint()
     self.assertTrue(isinstance(N, gp_Pnt))
     NbResults = PPS.NbPoints()
     if NbResults > 0:
         for i in range(1, NbResults+1):
             Q = PPS.Point(i)
             self.assertTrue(isinstance(Q, gp_Pnt))
             distance = PPS.Distance(i)
             # in any case, it should be > 1
             self.assertGreater(distance, 1.)
     lower_d = PPS.LowerDistance()
     self.assertGreater(lower_d, 1.)
     if NbResults > 0:
         for i in range(1, NbResults+1):
             Q = PPS.Point(i)
             distance = PPS.Distance(i)
             pstring = "Q" + repr(i) + ": at Distance :" + repr(PPS.Distance(i))
Beispiel #10
0
    def Reflect(self):
        h_surf = BRep_Tool.Surface(self.tar.srf)
        g_line = gp_Lin(self.ini.beam.Location(), self.ini.beam.Direction())
        ray = Geom_Line(g_line)
        if GeomAPI_IntCS(ray, h_surf).NbPoints():
            self.tar.beam = reflect(self.ini.beam, self.tar.srf)
        else:
            pln = make_plane(self.tar.axs.Location(),
                             dir_to_vec(self.tar.axs.Direction()), 500, -500,
                             500, -500)
            h_surf = BRep_Tool.Surface(pln)
            self.tar.beam = reflect(self.ini.beam, pln)

        print(self.ini.beam.Location())
        print(self.tar.beam.Location())

        GeomAPI_IntCS(ray, h_surf).IsDone()
        uvw = GeomAPI_IntCS(ray, h_surf).Parameters(1)
        u, v, w = uvw
        print(u, v, w)
        vz, v1, v2, r1, r2 = axs_curvature(h_surf, u, v)

        tar_surf_axs = gp_Ax3(self.tar.beam.Location(), vec_to_dir(vz),
                              vec_to_dir(v1))
        tar_surf = wavefront([r1, r2], tar_surf_axs)
        self.display.DisplayShape(tar_surf, color="BLUE")
        self.display.DisplayShape(axs_pln(tar_surf_axs))

        self.GO_Prop(w)

        h_tar_wave = BRep_Tool.Surface(self.ini_wave)
        vz, v1, v2, r1, r2 = axs_curvature(h_tar_wave, u, v)
        tar_wave_axs = self.tar.beam.Translated(gp_Vec(0, 0, 0))
        tar_wave_axs.SetXDirection(vec_to_dir(v1))
        self.tar.wave = wavefront([r1, r2], tar_wave_axs)
        self.display.DisplayShape(self.tar.wave, color="RED")
        self.display.DisplayShape(axs_pln(tar_wave_axs))
Beispiel #11
0
    def __init__(self):
        plotocc.__init__(self)
        self.axis = gp_Ax3(gp_Pnt(1000, 1000, 1000), gp_Dir(0, 0, 1))
        self.trsf = set_trf(ax2=self.axis)

        ax1 = gp_Ax3(gp_Pnt(0, 0, 0), gp_Dir(0, 0, -1))
        ax1.Transform(self.trsf)
        self.surf1 = Face(ax1)
        self.surf1.face = surf_curv(lxy=[400, 300], rxy=[3000, 3000])
        self.surf1.MoveSurface(ax2=self.surf1.axis)
        self.surf1.rot_axs(rxyz=[0, 50, 0])

        ax2 = gp_Ax3(gp_Pnt(-1000, 0, 200), gp_Dir(0, 0, 1))
        ax2.Transform(self.trsf)
        self.surf2 = Face(ax2)
        self.surf2.face = surf_curv(lxy=[300, 200], rxy=[3000, -3000])
        self.surf2.MoveSurface(ax2=self.surf2.axis)
        self.surf2.rot_axs(pxyz=[0, -50, 10], rxyz=[20, 60, 0])

        ax3 = gp_Ax3(gp_Pnt(-750, 0, 1500), gp_Dir(0, 0, 1))
        ax3.Transform(self.trsf)
        self.surf3 = Face(ax3)
        self.surf3.face = surf_curv(lxy=[2500, 2500], rxy=[0, 0])
        self.surf3.MoveSurface(ax2=self.surf3.axis)

        self.beam1 = gp_Ax3()
        rot_axs(self.beam1, [100, 100, -500], [0, 0, 0])
        self.beam1.Transform(self.trsf)
        self.beam1, self.ray1 = self.run_beam(self.beam1)

        self.beam2 = gp_Ax3()
        rot_axs(self.beam2, [0, 0, -500], [0, 1, 0])
        self.beam2.Transform(self.trsf)
        self.beam2, self.ray2 = self.run_beam(self.beam2)

        self.beam3 = gp_Ax3()
        rot_axs(self.beam3, [-100, -100, -500], [0, 2, 0])
        self.beam3.Transform(self.trsf)
        self.beam3, self.ray3 = self.run_beam(self.beam3)
Beispiel #12
0
 def Display_Shape(self, colors=["BLUE", "YELLOW"]):
     self.display.DisplayShape(axs_pln(gp_Ax3()))
     self.display.DisplayShape(axs_pln(self.ini.axs), color=colors[0])
     self.display.DisplayShape(axs_pln(self.tar.axs), color=colors[1])
     self.display.DisplayShape(self.ini.srf, color=colors[0])
     self.display.DisplayShape(self.tar.srf)
     self.display.DisplayShape(self.ini.beam.Location(), color=colors[0])
     self.display.DisplayShape(self.tar.beam.Location(), color=colors[1])
     self.display.DisplayShape(make_line(self.ini.beam.Location(),
                                         self.tar.beam.Location()),
                               color=colors[0])
     self.display.DisplayShape(make_line(self.ini.beam_rght.Location(),
                                         self.tar.beam_rght.Location()),
                               color=colors[0])
     self.display.DisplayShape(make_line(self.ini.beam_left.Location(),
                                         self.tar.beam_left.Location()),
                               color=colors[0])
     self.display.DisplayShape(make_line(self.ini.beam_uppr.Location(),
                                         self.tar.beam_uppr.Location()),
                               color=colors[0])
     self.display.DisplayShape(make_line(self.ini.beam_bott.Location(),
                                         self.tar.beam_bott.Location()),
                               color=colors[0])
     self.display.FitAll()
Beispiel #13
0
 def reflect_b2(self, num=1):
     h_surf = BRep_Tool.Surface(self.b2)
     ray = Geom_Line(self.beam.Axis())
     self.RayTrace.Perform(ray, h_surf)
     if self.RayTrace.NbPoints() == 0:
         beam = self.beam
     else:
         self.num += 1
         uvw = self.RayTrace.Parameters(num)
         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).Reversed()
         norm = gp_Ax3(p1, vec_to_dir(vz), vec_to_dir(vx))
         self.show_axs_pln(norm, scale=10)
         beam = self.beam
         beam.SetLocation(p1)
         beam.SetDirection(beam.Direction().Reversed())
         beam.Mirror(norm.Axis())
         print(self.num, self.b2, p1)
         self.pts.append(p1)
         # self.beam.XReverse()
         # self.beam.Mirror(norm.Ax2())
     return beam
Beispiel #14
0
    def __init__(self):
        self.data = []
        self.curHilightedObj = None
        self.ProjectOnCurve = Geom2dAPI_ProjectPointOnCurve()

        self.curCoordinateSystem = gp_Ax3(gp.XOY())
        self.FirstEdge = TopoDS_Edge()
        self.SecondEdge = TopoDS_Edge()

        self.curPnt2d = gp.Origin2d()
        self.objectPnt2d = gp.Origin2d()
        self.bestPnt2d = gp.Origin2d()
        self.findbestPnt2d = False

        self.firstDisplay = True
        self.myGeom_Point = Geom_CartesianPoint(gp.Origin())
        self.myAIS_Point = AIS_Point(self.myGeom_Point)
        self.myAIS_Point.SetColor(Quantity_Color(Quantity_NOC_CYAN1))

        self.minimumSnapDistance = MINIMUMSNAP
        self.minDistance = 0
        self.curDistance = 0
        self.curGeom2d_Point = Geom2d_CartesianPoint(self.curPnt2d)
        self.myPlane = Geom_Plane(self.curCoordinateSystem)
 def test_points_from_intersection(self):
     '''Test: points from intersection'''
     PL = gp_Pln(gp_Ax3(gp_XOY()))
     MinorRadius, MajorRadius = 5, 8
     EL = gp_Elips(gp_YOZ(), MajorRadius, MinorRadius)
     ICQ = IntAna_IntConicQuad(EL, PL, precision_Angular(), precision_Confusion())
     if ICQ.IsDone():
         NbResults = ICQ.NbPoints()
         if NbResults > 0:
             for i in range(1, NbResults + 1):
                 P = ICQ.Point(i)
                 self.assertIsInstance(P, gp_Pnt)
     aPlane = GC_MakePlane(PL).Value()
     aSurface = Geom_RectangularTrimmedSurface(aPlane, - 8., 8., - 12., 12., True, True)
     self.assertIsNotNone(aSurface)
     self.assertFalse(aSurface.IsNull())
     anEllips = GC_MakeEllipse(EL).Value()
     self.assertIsInstance(anEllips, Geom_Ellipse)
     if ICQ.IsDone():
         NbResults = ICQ.NbPoints()
         if NbResults > 0:
             for i in range(1, NbResults + 1):
                 P = ICQ.Point(i)
                 self.assertIsInstance(P, gp_Pnt)
Beispiel #16
0
import numpy as np

from OCC.Core.gp import gp_Ax1, gp_Ax2, gp_Ax3, gp_XY
from OCC.Core.gp import gp_Pnt, gp_Vec, gp_Dir, gp_XYZ
from OCC.Core.gp import gp_Trsf, gp_Quaternion

axs = gp_Ax3()

#ax1 = gp_Ax3(gp_Pnt(1, 2, 3), gp_Dir(0.5, 1.0, 1.5))
#ax1 = gp_Ax3(gp_Pnt(1, 2, 3), gp_Dir(1.0, 1.0, 0.0))
ax1 = gp_Ax3(gp_Pnt(0, 0, 0), gp_Dir(0.5, 1.0, 1.5))
trf = gp_Trsf()
trf.SetTransformation(ax1, axs)
print(trf)
print(trf.DumpJsonToString())
print(trf.GetRotation(gp_XYZ(*axs.Direction().Coord())))
print(trf.GetRotation(gp_XYZ(*axs.XDirection().Coord())))
print(trf.GetRotation(gp_XYZ(*axs.YDirection().Coord())))

#ax2 = gp_Ax3(gp_Pnt(-1, -2, -3), gp_Dir(0, 0, 1))
#ax2 = gp_Ax3(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1))
ax2 = gp_Ax3(gp_Pnt(0, 0, 1), gp_Dir(0, 0, 1))
trf2 = gp_Trsf()
trf2.SetTransformation(ax2, axs)
print(trf2.DumpJsonToString())

ax2.Transform(trf)
trf2 = gp_Trsf()
trf2.SetTransformation(ax2, axs)
print(trf2.DumpJsonToString())
Beispiel #17
0
##the Free Software Foundation, either version 3 of the License, or
##(at your option) any later version.
##
##pythonOCC is distributed in the hope that it will be useful,
##but WITHOUT ANY WARRANTY; without even the implied warranty of
##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##GNU Lesser General Public License for more details.
##
##You should have received a copy of the GNU Lesser General Public License
##along with pythonOCC.  If not, see <http://www.gnu.org/licenses/>.
from math import pi

from OCC.Core.gp import gp_Pnt2d, gp_XOY, gp_Lin2d, gp_Ax3, gp_Dir2d
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeEdge
from OCC.Core.Geom import Geom_CylindricalSurface
from OCC.Core.GCE2d import GCE2d_MakeSegment

from OCC.Display.WebGl import threejs_renderer

# First build a helix
aCylinder = Geom_CylindricalSurface(gp_Ax3(gp_XOY()), 6.0)
aLine2d = gp_Lin2d(gp_Pnt2d(0.0, 0.0), gp_Dir2d(1.0, 1.0))
aSegment = GCE2d_MakeSegment(aLine2d, 0.0, pi * 2.0)

helix_edge = BRepBuilderAPI_MakeEdge(aSegment.Value(), aCylinder, 0.0,
                                     6.0 * pi).Edge()

display = threejs_renderer.ThreejsRenderer()
display.DisplayShape(helix_edge, color=(1, 0, 0), line_width=1.)
display.render()
Beispiel #18
0
    p1_y = px**2 / c1
    p2_y = px**2 / c1
    curv1 = curv_spl(px, p1_y)
    curv2 = curv_spl(px, p2_y)


if __name__ == "__main__":
    argvs = sys.argv
    parser = argparse.ArgumentParser()
    parser.add_argument("--dir", dest="dir", default="./")
    opt = parser.parse_args()
    print(opt, argvs)

    display, start_display, add_menu, add_function_to_menu = init_display()

    axs = gp_Ax3()
    deg = 30
    rad = 0
    obj = Geom_ConicalSurface(axs, np.deg2rad(deg), rad)
    surf = BRepBuilderAPI_MakeFace(obj, -np.pi / 2, np.pi / 2, -100, 100,
                                   1e-6).Face()

    display.DisplayShape(surf)
    display.DisplayShape(obj)
    #display.DisplayShape(axs_pln(axs))

    display.FitAll()
    start_display()

    init = "surf1"
    surf = ["surf2", "surf3", "surf4"]
Beispiel #19
0
def move_pnt_to_dir(axs=gp_Ax3(), scale=100):
    vec = point_to_vector(axs.Location()) + dir_to_vec(axs.Direction()) * scale
    return vector_to_point(vec)
 def show_plane(self, axs=gp_Ax3(), scale=100):
     pnt = axs.Location()
     vec = dir_to_vec(axs.Direction())
     pln = make_plane(pnt, vec, -scale, scale, -scale, scale)
     self.display.DisplayShape(pln)
 def show_ellipsoid(self, axs=gp_Ax3(), rxyz=[10., 10., 10.], trans=0.5):
     shape = gen_ellipsoid(axs, rxyz)
     self.display.DisplayShape(shape, transparency=trans, color="BLUE")
     return shape
 def show_vec(self, beam=gp_Ax3(), scale=1.0):
     pnt = beam.Location()
     vec = dir_to_vec(beam.Direction()).Scaled(scale)
     print(vec.Magnitude())
     self.display.DisplayVector(vec, pnt)
 def __init__(self):
     self.display, self.start_display, self.add_menu, self.add_function = init_display(
     )
     self.base_axs = gp_Ax3()
     SetDir.__init__(self)
def trsf_scale(axs=gp_Ax3(), scale=1):
    trf = gp_Trsf()
    trf.SetDisplacement(gp_Ax3(), axs)
    return trf
def set_loc(ax1=gp_Ax3(), ax2=gp_Ax3()):
    trf = set_trf(ax1, ax2)
    loc = TopLoc_Location(trf)
    return loc
def set_trf(ax1=gp_Ax3(), ax2=gp_Ax3()):
    trf = gp_Trsf()
    trf.SetTransformation(ax2, ax1)
    return trf
def line_from_axs(axs=gp_Ax3(), length=100):
    return make_edge(axs.Location(), pnt_from_axs(axs, length))
def face():
    p1 = gp_Pnt()
    p2 = gp_Pnt()
    p3 = gp_Pnt()
    p4 = gp_Pnt()
    p5 = gp_Pnt()
    p6 = gp_Pnt()

    # The white Face
    sphere = gp_Sphere(gp_Ax3(gp_Pnt(0, 0, 0), gp_Dir(1, 0, 0)), 150)
    green_face = BRepBuilderAPI_MakeFace(sphere, 0.1, 0.7, 0.2, 0.9)

    # The red face
    p1.SetCoord(-15, 200, 10)
    p2.SetCoord(5, 204, 0)
    p3.SetCoord(15, 200, 0)
    p4.SetCoord(-15, 20, 15)
    p5.SetCoord(-5, 20, 0)
    p6.SetCoord(15, 20, 35)
    array = TColgp_Array2OfPnt(1, 3, 1, 2)
    array.SetValue(1, 1, p1)
    array.SetValue(2, 1, p2)
    array.SetValue(3, 1, p3)
    array.SetValue(1, 2, p4)
    array.SetValue(2, 2, p5)
    array.SetValue(3, 2, p6)
    curve = GeomAPI_PointsToBSplineSurface(array, 3, 8, GeomAbs_C2,
                                           0.001).Surface()
    red_face = BRepBuilderAPI_MakeFace(curve, 1e-6)

    #The brown face
    circle = gp_Circ(gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(1, 0, 0)), 80)
    Edge1 = BRepBuilderAPI_MakeEdge(circle, 0, math.pi)
    Edge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(0, 0, -80), gp_Pnt(0, -10, 40))
    Edge3 = BRepBuilderAPI_MakeEdge(gp_Pnt(0, -10, 40), gp_Pnt(0, 0, 80))

    ##TopoDS_Wire YellowWire
    MW1 = BRepBuilderAPI_MakeWire(Edge1.Edge(), Edge2.Edge(), Edge3.Edge())
    assert MW1.IsDone()
    yellow_wire = MW1.Wire()
    brown_face = BRepBuilderAPI_MakeFace(yellow_wire)

    #The pink face
    p1.SetCoord(35, -200, 40)
    p2.SetCoord(50, -204, 30)
    p3.SetCoord(65, -200, 30)
    p4.SetCoord(35, -20, 45)
    p5.SetCoord(45, -20, 30)
    p6.SetCoord(65, -20, 65)
    array2 = TColgp_Array2OfPnt(1, 3, 1, 2)
    array2.SetValue(1, 1, p1)
    array2.SetValue(2, 1, p2)
    array2.SetValue(3, 1, p3)
    array2.SetValue(1, 2, p4)
    array2.SetValue(2, 2, p5)
    array2.SetValue(3, 2, p6)
    BSplineSurf = GeomAPI_PointsToBSplineSurface(array2, 3, 8, GeomAbs_C2,
                                                 0.001)
    aFace = BRepBuilderAPI_MakeFace(BSplineSurf.Surface(), 1e-6).Face()
    ##
    ##//2d lines
    P12d = gp_Pnt2d(0.9, 0.1)
    P22d = gp_Pnt2d(0.2, 0.7)
    P32d = gp_Pnt2d(0.02, 0.1)
    ##
    line1 = Geom2d_Line(P12d, gp_Dir2d((0.2 - 0.9), (0.7 - 0.1)))
    line2 = Geom2d_Line(P22d, gp_Dir2d((0.02 - 0.2), (0.1 - 0.7)))
    line3 = Geom2d_Line(P32d, gp_Dir2d((0.9 - 0.02), (0.1 - 0.1)))
    ##
    ##//Edges are on the BSpline surface
    Edge1 = BRepBuilderAPI_MakeEdge(line1, BSplineSurf.Surface(), 0,
                                    P12d.Distance(P22d)).Edge()
    Edge2 = BRepBuilderAPI_MakeEdge(line2, BSplineSurf.Surface(), 0,
                                    P22d.Distance(P32d)).Edge()
    Edge3 = BRepBuilderAPI_MakeEdge(line3, BSplineSurf.Surface(), 0,
                                    P32d.Distance(P12d)).Edge()
    ##
    Wire1 = BRepBuilderAPI_MakeWire(Edge1, Edge2, Edge3).Wire()
    Wire1.Reverse()
    pink_face = BRepBuilderAPI_MakeFace(aFace, Wire1).Face()
    breplib_BuildCurves3d(pink_face)

    display.DisplayColoredShape(green_face.Face(), 'GREEN')
    display.DisplayColoredShape(red_face.Face(), 'RED')
    display.DisplayColoredShape(pink_face, Quantity_Color(Quantity_NOC_PINK))
    display.DisplayColoredShape(brown_face.Face(), 'BLUE')
    display.DisplayColoredShape(yellow_wire, 'YELLOW', update=True)
Beispiel #29
0
def print_axs(ax=gp_Ax3()):
    print(ax.Location())
Beispiel #30
0
 def __init__(self):
     ax = gp_Ax3()
     print(ax.Location())
Beispiel #31
0
    # return surface.Face()
    face = BRepBuilderAPI_MakeFace(surf, 1e-6).Face()
    face.Location(set_loc(gp_Ax3(), axs))
    return face


# https://www.opencascade.com/doc/occt-7.4.0/refman/html/class_b_rep_builder_a_p_i___make_face.html
if __name__ == '__main__':
    obj = plotocc()
    obj.show_axs_pln(obj.base_axs, scale=1)

    px = np.linspace(-1, 1, 10) * 5
    py = np.linspace(-1, 1, 10) * 5
    mesh = np.meshgrid(px, py)
    data = mesh[0]**2 / 10 + mesh[1]**2 / 20
    axis = gp_Ax3(gp_Pnt(0.5, 0.0, 0.0), gp_Dir(0, 0, 1))
    face = spl_face(*mesh, data, axs=axis)
    #face = bez_face(*mesh, data, axs=axis)
    trsf = face.Location().Transformation()
    surf = BRep_Tool.Surface(face)

    axis_0 = axis.Transformed(trsf)
    axis_0.Translate(gp_Pnt(0, 0, 0), gp_Pnt(2, 0, 0))
    poly_0 = obj.make_EllipWire(rxy=[1.1, 1.0], axs=axis_0)
    proj = BRepProj_Projection(poly_0, face, axis.Direction())
    bound_poly_0 = proj.Current()

    axis_1 = axis.Transformed(trsf)
    axis_1.Translate(gp_Pnt(0, 0, 0), gp_Pnt(-2, 0, 0))
    poly_1 = obj.make_PolyWire(num=6, axs=axis_1)
    proj = BRepProj_Projection(poly_1, face, axis.Direction())
Beispiel #32
0
def startBottle(startOnly=True):  # minus the neck fillet, shelling & threads
    partName = "Bottle-start"
    # The points we'll use to create the profile of the bottle's body
    aPnt1 = gp_Pnt(-width / 2.0, 0, 0)
    aPnt2 = gp_Pnt(-width / 2.0, -thickness / 4.0, 0)
    aPnt3 = gp_Pnt(0, -thickness / 2.0, 0)
    aPnt4 = gp_Pnt(width / 2.0, -thickness / 4.0, 0)
    aPnt5 = gp_Pnt(width / 2.0, 0, 0)

    aArcOfCircle = GC_MakeArcOfCircle(aPnt2, aPnt3, aPnt4)
    aSegment1 = GC_MakeSegment(aPnt1, aPnt2)
    aSegment2 = GC_MakeSegment(aPnt4, aPnt5)

    # Could also construct the line edges directly using the points
    # instead of the resulting line.
    aEdge1 = BRepBuilderAPI_MakeEdge(aSegment1.Value())
    aEdge2 = BRepBuilderAPI_MakeEdge(aArcOfCircle.Value())
    aEdge3 = BRepBuilderAPI_MakeEdge(aSegment2.Value())

    # Create a wire out of the edges
    aWire = BRepBuilderAPI_MakeWire(aEdge1.Edge(), aEdge2.Edge(),
                                    aEdge3.Edge())

    # Quick way to specify the X axis
    xAxis = gp_OX()

    # Set up the mirror
    aTrsf = gp_Trsf()
    aTrsf.SetMirror(xAxis)

    # Apply the mirror transformation
    aBRespTrsf = BRepBuilderAPI_Transform(aWire.Wire(), aTrsf)

    # Get the mirrored shape back out of the transformation
    # and convert back to a wire
    aMirroredShape = aBRespTrsf.Shape()

    # A wire instead of a generic shape now
    aMirroredWire = topods.Wire(aMirroredShape)

    # Combine the two constituent wires
    mkWire = BRepBuilderAPI_MakeWire()
    mkWire.Add(aWire.Wire())
    mkWire.Add(aMirroredWire)
    myWireProfile = mkWire.Wire()

    # The face that we'll sweep to make the prism
    myFaceProfile = BRepBuilderAPI_MakeFace(myWireProfile)

    # We want to sweep the face along the Z axis to the height
    aPrismVec = gp_Vec(0, 0, height)
    myBody = BRepPrimAPI_MakePrism(myFaceProfile.Face(), aPrismVec)

    # Add fillets to all edges through the explorer
    mkFillet = BRepFilletAPI_MakeFillet(myBody.Shape())
    anEdgeExplorer = TopExp_Explorer(myBody.Shape(), TopAbs_EDGE)

    while anEdgeExplorer.More():
        anEdge = topods.Edge(anEdgeExplorer.Current())
        mkFillet.Add(thickness / 12.0, anEdge)

        anEdgeExplorer.Next()

    myBody = mkFillet.Shape()

    # Create the neck of the bottle
    neckLocation = gp_Pnt(0, 0, height)
    neckAxis = gp_DZ()
    neckAx2 = gp_Ax2(neckLocation, neckAxis)

    myNeckRadius = thickness / 4.0
    myNeckHeight = height / 10.0

    mkCylinder = BRepPrimAPI_MakeCylinder(neckAx2, myNeckRadius, myNeckHeight)
    myBody = BRepAlgoAPI_Fuse(myBody, mkCylinder.Shape())
    if startOnly:  # quit here
        uid = win.getNewPartUID(myBody.Shape(), name=partName)
        win.redraw()
        return

    partName = "Bottle-complete"
    # Our goal is to find the highest Z face and remove it
    faceToRemove = None
    zMax = -1

    # We have to work our way through all the faces to find the highest Z face
    aFaceExplorer = TopExp_Explorer(myBody.Shape(), TopAbs_FACE)
    while aFaceExplorer.More():
        aFace = topods.Face(aFaceExplorer.Current())

        if face_is_plane(aFace):
            aPlane = geom_plane_from_face(aFace)

            # We want the highest Z face, so compare this to the previous faces
            aPnt = aPlane.Location()
            aZ = aPnt.Z()
            if aZ > zMax:
                zMax = aZ
                faceToRemove = aFace

        aFaceExplorer.Next()

    facesToRemove = TopTools_ListOfShape()
    facesToRemove.Append(faceToRemove)

    myBody = BRepOffsetAPI_MakeThickSolid(myBody.Shape(), facesToRemove,
                                          -thickness / 50.0, 0.001)

    # Set up our surfaces for the threading on the neck
    neckAx2_Ax3 = gp_Ax3(neckLocation, gp_DZ())
    aCyl1 = Geom_CylindricalSurface(neckAx2_Ax3, myNeckRadius * 0.99)
    aCyl2 = Geom_CylindricalSurface(neckAx2_Ax3, myNeckRadius * 1.05)

    # Set up the curves for the threads on the bottle's neck
    aPnt = gp_Pnt2d(2.0 * math.pi, myNeckHeight / 2.0)
    aDir = gp_Dir2d(2.0 * math.pi, myNeckHeight / 4.0)
    anAx2d = gp_Ax2d(aPnt, aDir)

    aMajor = 2.0 * math.pi
    aMinor = myNeckHeight / 10.0

    anEllipse1 = Geom2d_Ellipse(anAx2d, aMajor, aMinor)
    anEllipse2 = Geom2d_Ellipse(anAx2d, aMajor, aMinor / 4.0)

    anArc1 = Geom2d_TrimmedCurve(anEllipse1, 0, math.pi)
    anArc2 = Geom2d_TrimmedCurve(anEllipse2, 0, math.pi)

    anEllipsePnt1 = anEllipse1.Value(0)
    anEllipsePnt2 = anEllipse1.Value(math.pi)

    aSegment = GCE2d_MakeSegment(anEllipsePnt1, anEllipsePnt2)

    # Build edges and wires for threading
    anEdge1OnSurf1 = BRepBuilderAPI_MakeEdge(anArc1, aCyl1)
    anEdge2OnSurf1 = BRepBuilderAPI_MakeEdge(aSegment.Value(), aCyl1)
    anEdge1OnSurf2 = BRepBuilderAPI_MakeEdge(anArc2, aCyl2)
    anEdge2OnSurf2 = BRepBuilderAPI_MakeEdge(aSegment.Value(), aCyl2)

    threadingWire1 = BRepBuilderAPI_MakeWire(anEdge1OnSurf1.Edge(),
                                             anEdge2OnSurf1.Edge())
    threadingWire2 = BRepBuilderAPI_MakeWire(anEdge1OnSurf2.Edge(),
                                             anEdge2OnSurf2.Edge())

    # Compute the 3D representations of the edges/wires
    breplib.BuildCurves3d(threadingWire1.Shape())
    breplib.BuildCurves3d(threadingWire2.Shape())

    # Create the surfaces of the threading
    aTool = BRepOffsetAPI_ThruSections(True)
    aTool.AddWire(threadingWire1.Wire())
    aTool.AddWire(threadingWire2.Wire())
    aTool.CheckCompatibility(False)
    myThreading = aTool.Shape()

    # Build the resulting compound
    aRes = TopoDS_Compound()
    aBuilder = BRep_Builder()
    aBuilder.MakeCompound(aRes)
    aBuilder.Add(aRes, myBody.Shape())
    aBuilder.Add(aRes, myThreading)
    uid = win.getNewPartUID(aRes, name=partName)
    win.redraw()
def pnt_from_axs(axs=gp_Ax3(), length=100):
    vec = point_to_vector(axs.Location()) + \
        dir_to_vec(axs.Direction()) * length
    return vector_to_point(vec)