Beispiel #1
0
    def make_Wire_pts(self, dat=[], axs=gp_Ax3()):
        num = dat.shape
        pts = []
        if num[1] == 2:
            for p in dat:
                pts.append(gp_Pnt(p[0], p[1], 0))
        elif num[1] == 3:
            for p in dat:
                pts.append(gp_Pnt(p[0], p[1], p[2]))
        else:
            for p in dat:
                pts.append(gp_Pnt(p[0], p[1], p[2]))
        pts = np.array(pts)
        #cov = ConvexHull(pts, qhull_options='QJ')

        #pts_ord = []
        # print(cov)
        # print(cov.simplices)
        # print(cov.vertices)
        # for idx in cov.vertices:
        #    print(idx, pnt[idx])
        #    pts_ord.append(gp_Pnt(*pnt[idx]))

        #poly = make_polygon(pts_ord)
        poly = make_polygon(pts)
        poly.Location(set_loc(gp_Ax3(), axs))
        #n_sided = BRepFill_Filling()
        # for e in Topo(poly).edges():
        #    n_sided.Add(e, GeomAbs_C0)
        # n_sided.Build()
        #face = n_sided.Face()
        return poly
    def make_StarWire(self,
                      num=5,
                      radi=[2.0, 1.0],
                      shft=0.0,
                      axs=gp_Ax3(),
                      skin=None):
        lxy = radi
        pnts = []
        angl = 360 / num
        for i in range(num):
            a_thet = np.deg2rad(i * angl) + np.deg2rad(shft)
            ax, ay = radi[0] * np.sin(a_thet), radi[0] * np.cos(a_thet)
            pnts.append(gp_Pnt(ax, ay, 0))
            b_thet = a_thet + np.deg2rad(angl) / 2
            bx, by = radi[1] * np.sin(b_thet), radi[1] * np.cos(b_thet)
            pnts.append(gp_Pnt(bx, by, 0))
        pnts.append(pnts[0])
        poly = make_polygon(pnts)
        poly.Location(set_loc(gp_Ax3(), axs))

        n_sided = BRepFill_Filling()
        for e in Topo(poly).edges():
            n_sided.Add(e, GeomAbs_C0)
        n_sided.Build()
        face = n_sided.Face()
        if skin == None:
            return poly
        elif skin == 0:
            return face
        else:
            solid = BRepOffset_MakeOffset(face, skin, 1.0E-5, BRepOffset_Skin,
                                          False, True, GeomAbs_Arc, True, True)
            return solid.Shape()
Beispiel #3
0
 def export_file(self):
     builder = BRep_Builder()
     compound = TopoDS_Compound()
     builder.MakeCompound(compound)
     builder.Add(compound, self.b1)
     builder.Add(compound, self.b2)
     builder.Add(compound, make_polygon(self.pts))
     self.export_stp(compound)
Beispiel #4
0
 def export_file(self):
     builder = BRep_Builder()
     compound = TopoDS_Compound()
     builder.MakeCompound(compound)
     builder.Add(compound, self.b1)
     builder.Add(compound, self.b2)
     builder.Add(compound, make_polygon(self.pts))
     write_step_file(compound, "./tmp/test.stp")
Beispiel #5
0
 def make_PolyWire(self, num=6, radi=1.0, shft=0.0, axs=gp_Ax3()):
     lxy = radi - 0.1
     pnts = []
     angl = 360 / num
     for i in range(num):
         thet = np.deg2rad(i * angl) + np.deg2rad(shft)
         x, y = radi * np.sin(thet), radi * np.cos(thet)
         pnts.append(gp_Pnt(x, y, 0))
     pnts.append(pnts[0])
     poly = make_polygon(pnts)
     poly.Location(set_loc(gp_Ax3(), axs))
     return poly
Beispiel #6
0
 def make_PolyPlane(self, num=6, radi=1.0, shft=0.0, axs=gp_Ax3()):
     lxy = radi - 0.1
     pnts = []
     angl = 360 / num
     for i in range(num):
         thet = np.deg2rad(i * angl) + np.deg2rad(shft)
         x, y = radi * np.sin(thet), radi * np.cos(thet)
         pnts.append(gp_Pnt(x, y, 0))
     pnts.append(pnts[0])
     poly = make_polygon(pnts)
     brep = BRepBuilderAPI_MakeFace(gp_Pln(), poly)
     brep.Add(poly)
     face = brep.Face()
     face.Location(set_loc(gp_Ax3(), axs))
     return face
Beispiel #7
0
    def run_beam(self, beam=gp_Ax3()):
        pts = [beam.Location()]

        print(beam.Location(), dir_to_vec(beam.Direction()))
        beam = self.Reflect(beam, self.surf1.face)
        pts.append(beam.Location())

        print(beam.Location(), dir_to_vec(beam.Direction()))
        beam = self.Reflect(beam, self.surf2.face)
        pts.append(beam.Location())

        pnt = move_pnt_to_dir(beam, 2500)
        pts.append(pnt)

        beam_ray = make_polygon(pts)
        return beam, beam_ray
Beispiel #8
0
 def make_PolySurf(self, num=6, radi=1.0, shft=0.0, axs=gp_Ax3()):
     lxy = radi - 0.1
     pnts = []
     angl = 360 / num
     for i in range(num):
         thet = np.deg2rad(i * angl) + np.deg2rad(shft)
         x, y = radi * np.sin(thet), radi * np.cos(thet)
         pnts.append(gp_Pnt(x, y, 0))
     pnts.append(pnts[0])
     poly = make_polygon(pnts)
     proj = BRepProj_Projection(poly, self.surf, gp_Pnt(0, 0, 10))
     # print(proj.Current())
     brep = BRepBuilderAPI_MakeFace(self.surf, poly)
     # brep.Add(poly)
     face = brep.Face()
     face.Location(set_loc(gp_Ax3(), axs))
     return face
Beispiel #9
0
    def __init__(self):
        plotocc.__init__(self)

        print(gxyz.shape)
        for i, xyz in enumerate(gxyz):
            print(i, *xyz)
            self.display.DisplayShape(gp_Pnt(*xyz))

        e_array = []
        for e in xyz_max:
            x, y, z = e
            e = gp_Pnt(float(x), float(y), float(z))
            e_array.append(e)
        e_array.append(e_array[0])
        poly = make_polygon(e_array)

        n_sided = BRepFill_Filling()
        for e in Topo(poly).edges():
            n_sided.Add(e, GeomAbs_C0)
        for pt in gxyz:
            x, y, z = pt
            if (x < xmax) and (x > xmin) and (y < ymax) and (y > ymin) and (
                    z < zmax) and (z > zmin):
                n_sided.Add(gp_Pnt(x, y, z))
        n_sided.Build()
        face = n_sided.Face()

        #face = make_n_sided(edges, p_array)

        # THICKEN SURFACE
        thickness = 0.15
        solid = BRepOffset_MakeOffset(face, thickness, 1.0E-5, BRepOffset_Skin,
                                      False, False, GeomAbs_Intersection, True)
        # The last True is important to make solid
        # solid.MakeOffsetShape()
        # solid.MakeThickSolid()
        #aShape = solid.Shape()

        self.display.DisplayShape(poly)
        self.display.DisplayShape(face)
        #display.DisplayShape(aShape, update=True)
        #write_step_file(aShape, "./tmp/gyroid.stp")

        self.export_stp(solid.Shape())
Beispiel #10
0
    def __init__(self, meta={"name": "name"}):
        super().__init__()
        self.meta = meta
        self.name = meta["name"]

        if "axs" in meta.keys():
            pnt = gp_Pnt(*meta["axs"]["xyz"])
            dir_x = gp_Dir(*meta["axs"]["dir_x"])
            dir_y = gp_Dir(*meta["axs"]["dir_y"])
            dir_z = gp_Dir(*meta["axs"]["dir_z"])
            self.axs = gp_Ax3(pnt, dir_z, dir_x)
        else:
            self.axs = gp_Ax3()

        self.dat = np.loadtxt(basepath + "model_dat.txt")
        self.pts = []
        for xyz in self.dat:
            self.pts.append(gp_Pnt(*xyz))
        self.rim = make_polygon(self.pts, closed=True)
    def compute_trajectory(self, t0=0.0, t1=100):
        r = ode(self.newton).set_integrator('dopri5')
        r.set_initial_value(self.initial_conditions, t0)
        positions = []
        t1 = 10
        dt = 0.01
        while r.successful() and r.t < t1:
            txt = "{:03.2f} / {:03.2f} ".format(r.t, t1)
            txt += "| {:03.2f} {:03.2f} {:03.2f} ".format(*r.y[:3])
            txt += "| {:03.2f} {:03.2f} {:03.2f} ".format(*r.y[3:])
            sys.stdout.write("\r" + txt)
            sys.stdout.flush()
            #r.set_f_params(m, q, 1.0, self.e_of_x(r.y[0]))
            r.integrate(r.t + dt)
            self.pts.append(gp_Pnt(*r.y[:3]))

        print()
        poly = make_polygon(self.pts)
        self.display.DisplayShape(poly)
        for pnt in self.pts[::20]:
            self.display.DisplayShape(pnt)
Beispiel #12
0
    def compute_trajectory(self, t0=0.0, t1=10.0):
        self.r = ode(self.newton).set_integrator('dopri5')
        self.r.set_initial_value(self.initial_conditions, t0)
        positions = []
        self.dt = 0.5
        self.pts, self.vel = [], []
        while self.r.successful() and self.r.t < t1:
            txt = "{:03.2f} / {:03.2f} ".format(self.r.t, t1)
            txt += "| {:03.2f} {:03.2f} {:03.2f} ".format(*self.r.y[:3])
            txt += "| {:03.2f} {:03.2f} {:03.2f} ".format(*self.r.y[3:])
            sys.stdout.write("\r" + txt)
            sys.stdout.flush()
            self.pts.append(gp_Pnt(*self.r.y[:3]))
            self.vel.append(gp_Vec(*self.r.y[3:]))
            self.check_ground()
            self.r.integrate(self.r.t + self.dt)

        print()
        poly = make_polygon(self.pts)
        self.display.DisplayShape(poly)
        for pnt in self.pts[::10]:
            self.display.DisplayShape(pnt)
        self.display.DisplayShape(self.grd, transparency=0.8, color="BLUE")
    def make_FaceByOrder(self, pts=[]):
        pnt = []
        for p in pts:
            pnt.append([p.X(), p.Y(), p.Z()])

        pnt = np.array(pnt)
        cov = ConvexHull(pnt, qhull_options='QJ')

        #pts_ord = []
        # print(cov)
        # print(cov.simplices)
        # print(cov.vertices)
        # for idx in cov.vertices:
        #    print(idx, pnt[idx])
        #    pts_ord.append(gp_Pnt(*pnt[idx]))

        #poly = make_polygon(pts_ord)
        poly = make_polygon(pts)
        n_sided = BRepFill_Filling()
        for e in Topo(poly).edges():
            n_sided.Add(e, GeomAbs_C0)
        n_sided.Build()
        face = n_sided.Face()
        return face
Beispiel #14
0
 def load_rim(self, rimfile="pln.rim"):
     data = np.loadtxt(rimfile, skiprows=2)
     pts = []
     for xy in data:
         pts.append(gp_Pnt(*xy, 0))
     self.rim = make_polygon(pts, closed=True)
    pts = []
    for xyz in dat + [pts[0]]:
        pts.append(gp_Pnt(*xyz))
    face = plotocc.make_FaceByOrder(pts)


if __name__ == '__main__':
    obj = plotocc()

    ax1 = gp_Ax3()
    pt1 = np.loadtxt(obj.rootname + "_pln1.txt")
    print(pt1)
    pts = []
    for xyz in pt1 + [pt1[0]]:
        pts.append(gp_Pnt(*xyz))
    br1 = make_polygon(pts, closed=True)
    br1.Location(set_loc(gp_Ax3(), ax1))
    fc1 = obj.make_FaceByOrder(pts)
    fc1.Location(set_loc(gp_Ax3(), ax1))
    print(fc1)
    obj.display.DisplayShape(br1)
    obj.display.DisplayShape(fc1)

    ax2 = gp_Ax3()
    ax2.SetLocation(gp_Pnt(0, 0, 25))
    pt2 = np.loadtxt(obj.rootname + "_pln2.txt")
    print(pt2)
    pts = []
    for xyz in pt2 + [pt2[0]]:
        pts.append(gp_Pnt(*xyz))
    br2 = make_polygon(pts, closed=True)
 def show_pts(self, pts=[gp_Pnt()], num=1):
     for p in pts[::num]:
         self.display.DisplayShape(p)
     self.display.DisplayShape(make_polygon(pts))
    parser = OptionParser()
    parser.add_option("--dir", dest="dir", default="./")
    parser.add_option("--pxyz", dest="pxyz",
                      default=[0.0, 0.0, 0.0], type="float", nargs=3)
    opt, argc = parser.parse_args(argvs)
    print(opt, argc)

    obj = plotocc(touch=True)
    dae_data = uiuc_database()

    axs = gp_Ax3()
    uic = "dae51"
    pnt = gp_Pnt(0, 10, 0)
    ax1 = gp_Ax3(pnt, axs.YDirection(),
                 axs.XDirection().Reversed())
    ui1 = make_polygon([gp_Pnt(*100 * xy, 0)
                        for xy in uiuc_database(uic)], closed=True)
    ui1.Location(set_loc(gp_Ax3(), ax1))
    obj.display.DisplayShape(ui1)
    obj.display.DisplayMessage(pnt, uic)

    uic = "geminism"
    pnt = gp_Pnt(0, 20, 0)
    ax1.SetLocation(pnt)
    ui1 = make_polygon([gp_Pnt(*100 * xy, 0)
                        for xy in uiuc_database(uic)], closed=True)
    ui1.Location(set_loc(gp_Ax3(), ax1))
    obj.display.DisplayShape(ui1)
    obj.display.DisplayMessage(pnt, uic)

    uic = "naca0006"
    pnt = gp_Pnt(0, 30, 0)
Beispiel #18
0
def get_aligned_boundingbox_ratio(shape, tol=1e-6, optimal_BB=True, ratio=1):
    """ 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

    use_triangulation : bool, True by default
        This makes the computation more accurate

    ratio : float, 1.0 by default.

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

        if `as_pnt` is False, return a tuple of lower and then upper X,Y,Z values
         representing the bounding box
    """
    bbox = Bnd_Box()
    bbox.SetGap(tol)

    # note: useTriangulation is True by default, we set it explicitely, but t's not necessary
    if optimal_BB:
        use_triangulation = True
        use_shapetolerance = True
        brepbndlib_AddOptimal(shape, bbox, use_triangulation,
                              use_shapetolerance)
    else:
        brepbndlib_Add(shape, bbox)

    xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get()
    dx, mx = (xmax - xmin) * ratio, (xmax + xmin) / 2
    dy, my = (ymax - ymin) * ratio, (ymax + ymin) / 2
    dz, mz = (zmax - zmin) * ratio, (zmax + zmin) / 2
    x0, x1 = mx - dx / 2, mx + dx / 2
    y0, y1 = my - dy / 2, my + dy / 2
    z0, z1 = mz - dz / 2, mz + dz / 2
    corner1 = gp_Pnt(x0, y0, z0)
    corner2 = gp_Pnt(x1, y1, z1)
    center = midpoint(corner1, corner2)

    rim0 = make_polygon([
        gp_Pnt(x0, y0, z0),
        gp_Pnt(x1, y0, z0),
        gp_Pnt(x1, y1, z0),
        gp_Pnt(x0, y1, z0)
    ],
                        closed=True)

    rim1 = make_polygon([
        gp_Pnt(x0, y0, z1),
        gp_Pnt(x1, y0, z1),
        gp_Pnt(x1, y1, z1),
        gp_Pnt(x0, y1, z1)
    ],
                        closed=True)
    api = BRepOffsetAPI_ThruSections(True, False, 1.0E-9)
    api.AddWire(rim0)
    api.AddWire(rim1)
    box_shp = api.Shape()
    #box_shp = BRepPrimAPI_MakeBox(corner1, corner2).Shape()
    return center, [dx, dy, dz], box_shp
Beispiel #19
0
    px = np.linspace(-1, 1, 100) * 300
    py = np.linspace(-1, 1, 100) * 300
    mesh = np.meshgrid(px, py)
    data1 = mesh[0]**2 / 2000 + mesh[1]**2 / 1000

    px = np.linspace(-1, 1, 25) * 150
    py = np.linspace(-1, 1, 25) * 150
    mesh = np.meshgrid(px, py)
    data2 = mesh[0]**2 / 1000 + mesh[1]**2 / 2000

    pts = []
    pts.append(gp_Pnt(-50, -60, 0))
    pts.append(gp_Pnt(-60, +70, 0))
    pts.append(gp_Pnt(+70, +80, 0))
    pts.append(gp_Pnt(+80, -90, 0))
    poly = make_polygon(pts, closed=True)

    axis1 = gp_Ax3(gp_Pnt(-150, +50.0, 0.0), gp_Dir(0, 0, 1))
    surf1, face1 = spl_face(*mesh, data1, axs=axis1)
    poly1 = poly.Located(set_loc(gp_Ax3(), axis1))
    poly1_proj = obj.proj_rim_pln(poly1, face1, axis1)
    print(face1)

    #split = BRepFeat_SplitShape(face1)
    #split.Add(poly1_proj, face1)
    # split.Build()
    #surf1_trim1 = split.Left()
    #surf1_trim2 = split.DirectLeft()
    # print(split.Check())
    #print(surf1_trim1.Size(), surf1_trim2.Size())
Beispiel #20
0
if __name__ == '__main__':
    argvs = sys.argv
    parser = argparse.ArgumentParser()
    parser.add_argument("--dir", dest="dir", default="./")
    parser.add_argument("--pxyz",
                        dest="pxyz",
                        default=[0.0, 0.0, 0.0],
                        type=float,
                        nargs=3)
    opt = parser.parse_args()
    print(opt, argvs)

    obj = dispocc(touch=True)
    torus = obj.make_torus(gp_Ax3(), r0=3000, r1=2000)
    beam0 = gp_Ax3(gp_Pnt(7500, 1100, 0), gp_Dir(-1, 0, 0.1),
                   gp_Dir(0, 0.1, 1))
    beam1 = obj.run_beam_face(beam0, torus, tr=1)
    pts = [beam0.Location(), beam1.Location()]
    for i in range(100):
        beam1 = obj.run_beam_face(beam1, torus, tr=0)
        pts.append(beam1.Location())
    ray = make_polygon(pts)

    obj.show_axs_pln(beam0, scale=100)
    obj.show_axs_pln(beam1, scale=100)
    obj.display.DisplayShape(torus, color="BLUE", transparency=0.9)
    obj.display.DisplayShape(ray)
    obj.show_axs_pln()
    obj.show()