Exemple #1
0
    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())
    bound_poly_1 = proj.Current()
Exemple #2
0
    print(opt, argc)

    px = np.linspace(-1, 1, 100) * 110 / 2
    py = np.linspace(-1, 1, 200) * 110 / 2
    mesh = np.meshgrid(px, py)
    dae_data = uiuc_dae_data()

    obj = plotocc()
    axs = gp_Ax3()
    ax1 = gp_Ax3(gp_Pnt(0, 0, -10), axs.Direction())
    vec = gp_Vec(gp_Pnt(0, 0, -10), gp_Pnt(0, 0, 10))
    face = obj.make_EllipWire(rxy=[50.0, 50.0], axs=ax1, skin=0)
    body = BRepPrimAPI_MakePrism(face, vec).Shape()
    data1 = (mesh[0]**2 / 750 + mesh[1]**2 / 750) + 6.0
    data2 = (mesh[0]**2 / 1000 + mesh[1]**2 / 1000) - 6.0
    face1 = spl_face(*mesh, data1, axs=axs)
    face2 = spl_face(*mesh, data2, axs=axs)

    splitter = BOPAlgo_Splitter()
    splitter.AddArgument(body)
    splitter.AddTool(face1)
    splitter.AddTool(face2)
    splitter.Perform()
    print(splitter.Arguments())
    print(splitter.ShapesSD())
    exp = TopExp_Explorer(splitter.Shape(), TopAbs_SOLID)
    shp = []
    while exp.More():
        print(exp.Current())
        shp.append(exp.Current())
        exp.Next()
Exemple #3
0
from OCC.Extend.DataExchange import write_step_file
from OCCUtils.Construct import make_edge

from src.base import plotocc, spl_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)
    surf = 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, surf, axs=axis)
    trsf = face.Location().Transformation()

    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())
    bound_poly_1 = proj.Current()

    axis_2 = axis.Transformed(trsf)
Exemple #4
0
from OCC.Core.TopLoc import TopLoc_Location
from OCCUtils.Topology import Topo
from OCCUtils.Construct import make_box, make_line, make_wire, make_edge
from OCCUtils.Construct import make_plane, make_polygon
from OCCUtils.Construct import point_to_vector, vector_to_point
from OCCUtils.Construct import dir_to_vec, vec_to_dir

if __name__ == '__main__':
    argvs = sys.argv
    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(view=False)
    if opt.dir != None:
        obj.tmpdir = "./stp_surf/"
    px = np.linspace(-1, 1, 200) * 150
    py = np.linspace(-1, 1, 200) * 150
    mesh = np.meshgrid(px, py)
    for rx in np.linspace(-1, 1, 6) * 1000:
        for ry in np.linspace(-1, 1, 6) * 1000:
            surf = mesh[0]**2 / rx + mesh[1]**2 / ry
            face = spl_face(*mesh, surf)
            obj.export_stp(face)
Exemple #5
0
def trsf_scale(axs=gp_Ax3(), scale=1):
    trf = gp_Trsf()
    trf.SetDisplacement(gp_Ax3(), axs)
    return trf


if __name__ == '__main__':
    obj = plotocc(touch=True)
    obj.show_axs_pln(scale=5)

    px = np.linspace(-1, 1, 100) * 2 * np.pi * 2.5
    py = np.linspace(-1, 1, 150) * 2 * np.pi * 2.5
    mesh = np.meshgrid(px, py)
    surf1 = np.sin(mesh[0] / 4) * 0.5
    surf2 = np.sin(mesh[1] / 2)
    face1 = spl_face(*mesh, surf1)
    face2 = spl_face(*mesh, surf2)

    api = GeomAPI_IntSS(BRep_Tool.Surface(face1), BRep_Tool.Surface(face2),
                        1.0e-7)
    print(api.NbLines())

    obj.display.DisplayShape(face1)
    obj.display.DisplayShape(face2)
    for i in range(api.NbLines()):
        crv = api.Line(i + 1)
        p0 = GeomLProp_CurveTool.FirstParameter(crv)
        p1 = GeomLProp_CurveTool.LastParameter(crv)
        print(p0, p1)
        obj.display.DisplayShape(crv)
Exemple #6
0
    def __init__(self):
        plotocc.__init__(self)
        self.compound = TopoDS_Compound()
        self.builder = BRep_Builder()
        self.builder.MakeCompound(self.compound)

        self.beam = gp_Ax3()
        self.beam.SetLocation(gp_Pnt(0.5, 0.5, 0.0))
        self.beam.SetDirection(gp_Dir(0.0, 0.5, 1.0))
        self.beam_line = line_from_axs(self.beam, length=20)
        self.builder.Add(self.compound, self.beam_line)

        ax = gp_Ax3(gp_Pnt(0, 0, 10), gp_Dir(0, 0, -1))
        px = np.linspace(-1, 1, 10) * 10
        py = np.linspace(-1, 1, 10) * 10
        mesh = np.meshgrid(px, py)
        surf = mesh[0]**2 / 100 + mesh[1]**2 / 150
        self.surf = spl_face(*mesh, surf, ax)
        self.surf_bound = self.make_PolySurf(radi=5, axs=ax)

        self.beam_glin = Geom_Line(self.beam.Location(), self.beam.Direction())
        self.ics = GeomAPI_IntCS(self.beam_glin, BRep_Tool.Surface(self.surf))
        print(self.ics.NbPoints())
        # print(self.ics.Point(1))

        self.ics = GeomAPI_IntCS(self.beam_glin,
                                 BRep_Tool.Surface(self.surf_bound))
        print(self.ics.NbPoints())

        #self.display.DisplayShape(self.surf, transparency=0.7)
        self.display.DisplayShape(self.surf_bound, transparency=0.7)
        self.plns = TopoDS_Shell()
        self.builder.MakeShell(self.plns)
        for ix in np.linspace(0, 1, 5):
            for iy in np.linspace(0, 1, 5):
                p1, vx, vy = gp_Pnt(), gp_Vec(), gp_Vec()
                GeomLProp_SurfaceTool.D1(BRep_Tool.Surface(self.surf), ix, iy,
                                         p1, vx, vy)
                vz = vx.Crossed(vy)
                axs = gp_Ax3(p1, vec_to_dir(vz), vec_to_dir(vx))
                pln = self.make_PolyPlane(axs=axs, radi=2.5, shft=15.0)
                print(pln)

                self.builder.Add(self.compound, make_vertex(p1))
                self.builder.Add(self.plns, pln)
        self.builder.Add(self.compound, self.plns)

        for face in Topo(self.plns).faces():
            self.ics.Perform(self.beam_glin, BRep_Tool.Surface(face))
            uvw = self.ics.Parameters(1)
            u, v, w = uvw
            p1, vx, vy = gp_Pnt(), gp_Vec(), gp_Vec()
            GeomLProp_SurfaceTool.D1(BRep_Tool.Surface(face), u, v, p1, vx, vy)
            vz = vx.Crossed(vy)
            if u > 0 and v > 0:
                print(u, v)
                print(p1)
                print(self.ics.Point(1))
                self.display.DisplayShape(p1)
                self.display.DisplayShape(face, color="BLUE")
            else:
                print(u, v)