Beispiel #1
0
            pnt = gp_Pnt(px[i, j], py[i, j], pz[i, j])
            pnt_2d.SetValue(row, col, pnt)
            #print (i, j, px[i, j], py[i, j], pz[i, j])

    surf = Geom_BezierSurface(pnt_2d)
    # api.Interpolate(pnt_2d)
    #surface = BRepBuilderAPI_MakeFace(curve, 1e-6)
    # 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)
Beispiel #2
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)
Beispiel #3
0
            i, j = row - 1, col - 1
            pnt = gp_Pnt(px[i, j], py[i, j], pz[i, j])
            pnt_2d.SetValue(row, col, pnt)
            #print (i, j, px[i, j], py[i, j], pz[i, j])

    surf = Geom_BezierSurface(pnt_2d)
    surf.Transform(set_trf(gp_Ax3(), axs))
    # api.Interpolate(pnt_2d)
    #surface = BRepBuilderAPI_MakeFace(curve, 1e-6)
    # return surface.Face()
    face = BRepBuilderAPI_MakeFace(surf, 1e-6).Face()
    return surf, face


if __name__ == '__main__':
    obj = plotocc(touch=True)
    obj.show_axs_pln(obj.base_axs, scale=1)

    # OCCT dev
    # https://dev.opencascade.org/doc/overview/html/occt_user_guides__modeling_data.html
    #
    # BRepBuilderAPI_MakeFace
    # https://www.opencascade.com/doc/occt-7.5.0/refman/html/class_b_rep_builder_a_p_i___make_face.html
    #
    # Bezier
    # https://old.opencascade.com/doc/occt-7.5.0/refman/html/class_geom___bezier_surface.html#details
    # the degree for a Geom_BezierSurface is limited to a value of (25) which is defined and controlled by the system

    px = np.linspace(-1, 1, 100) * 300
    py = np.linspace(-1, 1, 100) * 300
    mesh = np.meshgrid(px, py)
Beispiel #4
0
def run(n_procs, compare_by_number_of_processors=False):
    shape = get_brep()
    x_min, y_min, z_min, x_max, y_max, z_max = get_boundingbox(shape)
    z_delta = abs(z_min - z_max)

    init_time = time.time()  # for total time computation

    def get_z_coords_for_n_procs(n_slices, n_procs):
        z_slices = drange(z_min, z_max, z_delta / n_slices)

        slices = []
        n = len(z_slices) // n_procs
        print('number of slices:', len(z_slices))

        _str_slices = []
        for i in range(1, n_procs + 1):
            if i == 1:
                slices.append(z_slices[:i * n])
                _str_slices.append(':' + str(i * n) + ' ')
            elif i == n_procs:
                # does a little extra work if the number of slices
                # isnt divisible by n_procs
                slices.append(z_slices[(i - 1) * n:])
                _str_slices.append(str((i - 1) * n) + ': ')
                print('last slice', len(z_slices[(i - 1) * n:]))
            else:
                slices.append(z_slices[(i - 1) * n:i * n])
                _str_slices.append(' %s:%s ' % ((i - 1) * n, i * n))
        print(
            'the z-index array is sliced over %s processors like this: \n %s' %
            (n_procs, _str_slices))
        return slices

    def arguments(n_slices, n_procs):
        _tmp = []
        slices = get_z_coords_for_n_procs(n_slices, n_procs)
        for i in slices:
            _tmp.append([i, shape])
        return _tmp

    n_slice = 50

    if not compare_by_number_of_processors:
        _results = []
        P = multiprocessing.Pool(n_procs)
        _results = P.map(vectorized_slicer, arguments(n_slice, n_procs))

    else:
        # run a few tests from 1 to 9 processors
        for i in range(1, 9):
            tA = time.time()
            _results = []
            if i == 1:
                _results = vectorized_slicer(
                    [drange(z_min, z_max, z_delta / n_slice), shape])
            else:
                P = multiprocessing.Pool(n_procs)
                _results = P.map(vectorized_slicer, arguments(n_slice, i))
            print('slicing took %s seconds for %s processors' %
                  (time.time() - tA, i))
        sys.exit()

    print('\n\n\n done slicing on %i cores \n\n\n' % nprocs)

    # Display result
    obj = plotocc()
    obj.create_tempdir(flag=-1)
    print('displaying original shape')
    obj.display.DisplayShape(shape)
    obj.display.DisplayShape(gp_Pnt(x_min, y_min, z_min))
    obj.display.DisplayShape(gp_Pnt(x_min, y_min, z_max))
    obj.display.DisplayShape(gp_Pnt(x_min, y_max, z_min))
    obj.display.DisplayShape(gp_Pnt(x_min, y_max, z_max))
    obj.display.DisplayShape(gp_Pnt(x_max, y_min, z_min))
    obj.display.DisplayShape(gp_Pnt(x_max, y_min, z_max))
    obj.display.DisplayShape(gp_Pnt(x_max, y_max, z_min))
    obj.display.DisplayShape(gp_Pnt(x_max, y_max, z_max))
    for n, result_shp in enumerate(_results):
        print('displaying results from process {0}'.format(n))
        obj.display.DisplayShape(result_shp)
        print(result_shp)
        obj.export_stp(result_shp[0])

    # update viewer when all is added:
    obj.display.Repaint()
    total_time = time.time() - init_time
    print("%s necessary to perform slice with %s processor(s)." %
          (total_time, n_procs))
    obj.show()