Exemplo n.º 1
0
    def create(set_name, rotations):
        idx = 0
        triangles = dl.load_off_file(os.path.join(inpath, filename))
        data_filename = filename.split(".")[0]
        for rot in rotations:
            xrot, yrot = rot
            tris = np.copy(triangles)
            tris = rotatePoints(tris, eulerToMatrix([0, yrot, 0]))
            tris = rotatePoints(tris, eulerToMatrix([xrot, 0, 0]))
            mins, maxs = getAABB(tris)
            tris = np.transpose(tris)
            tree = octree.Octree(tris, mins, maxs, 4)
            X = np.array(tree.get_occlussion())
            # hash it to the regular grid
            mins, maxs = getAABB(np.transpose(X))
            X = (insize - 1) * (X - mins) / (maxs - mins)
            X = X.astype(int)
            occ_grid = np.zeros((insize, insize, insize), dtype=np.int)
            for i in range(0, X.shape[0]):
                x, y, z = X[i, :]
                occ_grid[x, y, z] = 1

            name = os.path.join(outpath, set_name, data_filename + "_%d" % idx)
            with open(name, "wb") as f:
                np.save(f, occ_grid)
            idx = idx + 1
Exemplo n.º 2
0
def subdivide(positions):

    MAXV = float('inf')
    MINV = -float('inf')

    xmax = MINV
    xmin = MAXV
    ymax = MINV
    ymin = MAXV
    zmax = MINV
    zmin = MAXV

    for point in positions:
        if point[0] < xmin:
            xmin = point[0]
        if point[0] > xmax:
            xmax = point[0]

        if point[1] < ymin:
            ymin = point[1]
        if point[1] > ymax:
            ymax = point[1]

        if point[2] < zmin:
            zmin = point[2]
        if point[2] > zmax:
            zmax = point[2]

    xc = (xmax + xmin) / 2
    yc = (ymax + ymin) / 2
    zc = (zmax + zmin) / 2

    tree = octree.Octree(xmax, ymax, zmax, xmin, ymin, zmin, (xc, yc, zc), 7)

    for i in range(0, len(positions)):
        tree.addItem(i, positions[i])

    # return tree.getLeafNodes()
    return tree.getNodesWithAvgChildCount(900)
Exemplo n.º 3
0
    scounts = None
    sdispls = None
    counts = None

# tell the processors how much data is coming
counts = comm.scatter(counts, root=0)
keys_sorted_local = np.zeros(counts, dtype=np.int32)
print "process %d counts %s" % (rank, counts)

# send keys
comm.Scatterv([sorted_keys, scounts, sdispls, MPI.INT],
              [keys_sorted_local, MPI.INT])
print "processor %d has keys: %s" % (rank, keys_sorted_local)

# create octree
tree = octree.Octree(sorted_keys, 4, order)
tree.partial_build()
#
## create plot
#current_axis = plt.gca()
#for node in tree.dump_data():
#    x = node[0]/2.0**order
#    y = node[1]/2.0**order
#    w = node[2]/2.0**order
#    current_axis.add_patch(Rectangle((x-.5*w, y-.5*w), w, w, fill=None))
#
##key_index = random.choice(range(sorted_keys.shape[0]))
#key_index = 68
#key = sorted_keys[key_index]
#node = tree.find_oct(key)
#