Esempio n. 1
0
def flood(RESOLUTION, THRESHOLD):
    occupiedCubes = []
    #load all the models with the same grid
    models = load_json.load_folder('models', RESOLUTION)

    # an empty list for holding chair models
    voxel_matrix = np.zeros((RESOLUTION, RESOLUTION, RESOLUTION))
    # adding up chairs
    for chair in models:
        #for each vox written in json file
        for c in chair:
            voxel_matrix[c[0], c[1], c[2]] += 1
    voxel_matrix = np.array(voxel_matrix) / (len(models))
    print("Averaging {} chairs".format(len(models)))

    neighbor_dict = {}
    max_ind = np.unravel_index(voxel_matrix.argmax(), voxel_matrix.shape)
    build_neighbor_dict(voxel_matrix, max_ind, neighbor_dict)
    ## todo exclude the ones that are already added to the occupideCubes list
    while len(occupiedCubes) < 1000:
        s = [
            (k, neighbor_dict[k])
            for k in sorted(neighbor_dict, key=neighbor_dict.get, reverse=True)
        ]
        t = next(iter(neighbor_dict))
        if voxel_matrix[t] > 0.1:
            occupiedCubes.append(t)
            print("total neighbor length {}".format(len(neighbor_dict)))
            print("Adding voxel {}. value {}".format(t, voxel_matrix[t]))
            build_neighbor_dict(voxel_matrix, t, neighbor_dict)
        else:
            break

    return occupiedCubes
Esempio n. 2
0
def single_cell(RESOLUTION, THRESHOLD):
    occupiedCubes = []
    #load all the models with the same grid
    models = load_json.load_folder('models', RESOLUTION)

    # an empty list for holding chair models
    voxel_matrix = np.zeros((RESOLUTION, RESOLUTION, RESOLUTION))
    # adding up chairs
    for chair in models:
        #for each vox written in json file
        for c in chair:
            voxel_matrix[c[0], c[1], c[2]] += 1
    voxel_matrix = np.array(voxel_matrix) / (len(models))
    print("averaging {} chairs".format(len(models)))

    ##create a list of solid cells
    for x in range(RESOLUTION):
        for y in range(RESOLUTION):
            for z in range(RESOLUTION):
                ## if this voxel is occupied by most models
                v = voxel_matrix[x, y, z]
                if v > THRESHOLD:
                    occupiedCubes.append([x, y, z])

    return occupiedCubes
Esempio n. 3
0
def neighbors(RESOLUTION, THRESHOLD):

    occupiedCubes = []
    #load all the models with the same grid
    models = load_json.load_folder('models', RESOLUTION)

    # an empty list for holding chair models
    voxel_matrix = np.zeros((RESOLUTION, RESOLUTION, RESOLUTION))
    # adding up chairs
    for chair in models:
        #for each vox written in json file
        for c in chair:
            voxel_matrix[c[0], c[1], c[2]] += 1
    voxel_matrix = np.array(voxel_matrix) / (len(models))
    print("averaging {} chairs".format(len(models)))

    for x in range(1, RESOLUTION - 1):
        for y in range(1, RESOLUTION - 1):
            for z in range(1, RESOLUTION - 1):
                ## counting neighbors
                neighour_sum = 0
                for n in SIX_NEIGHBORS:
                    p = np.array([x, y, z]) + n
                    neighour_sum += voxel_matrix[p[0], p[1], p[2]]
                neighour_sum += voxel_matrix[x, y, z]
                # print("{}\t{}\t{}\t{}".format(x,y,z,neighour_sum))
                if neighour_sum > THRESHOLD:
                    occupiedCubes.append([x, y, z])

    return occupiedCubes
Esempio n. 4
0
def generate_average_voxel_matrix (resolution):

    # load models
    models = load_json.load_folder('models', resolution)

    # empty 3d matrix of ints to hold value sums
    voxel_matrix = np.zeros((resolution, resolution, resolution), np.int8)

    # sum chair voxels into matrix
    voxel_count = 0
    for chair in models:
        for vox in chair:
            voxel_matrix[vox[0], vox[1], vox[2]] += 1
            voxel_count += 1

    return voxel_matrix, floor(voxel_count / len(models))
Esempio n. 5
0
def main():

    models = load_json.load_folder('models', RESOLUTION)

    # Initialize the library
    if not glfw.init():
        return

    display = [480, 480]
    # Create a windowed mode window and its OpenGL context
    window = glfw.create_window(display[0], display[1], "super normal", None,
                                None)
    if not window:
        glfw.terminate()
        return

    # Make the window's context current
    glfw.make_context_current(window)

    glu.gluPerspective(45, (display[0] / display[1]), 0.1, RESOLUTION * 6)
    # glu.gluLookAt(- RESOLUTION*CUBE_SIZE/2, RESOLUTION*CUBE_SIZE/2, RESOLUTION*CUBE_SIZE*2, RESOLUTION*CUBE_SIZE/2 , RESOLUTION*CUBE_SIZE/2 ,0, 0,1,0)
    glu.gluLookAt(RESOLUTION * CUBE_SIZE * 1.2,
                  RESOLUTION * CUBE_SIZE / 2 * 1.2,
                  RESOLUTION * CUBE_SIZE * 2 * 1.2, 0,
                  RESOLUTION * CUBE_SIZE / 2, 0, 0, 1, 0)

    # gl.glRotatef(-math.radians(90), 0.0, 1.0, 0.0);
    # glRotatef(-xAngle, 1.0f, 0.0f, 0.0f);
    # gl.glTranslatef(- RESOLUTION*CUBE_SIZE/2, -RESOLUTION*CUBE_SIZE/2, - RESOLUTION*CUBE_SIZE*2) #-60-RESOLUTION*4
    gl.glColor4f(1, 1, 1, 1)

    print("Rendering...")

    ind = 0
    # Loop until the user closes the window
    while not glfw.window_should_close(window):

        # gl.glRotatef(glfw.get_time() , 0, 1, 1)
        # gl.glRotatef(math.radians(45), 1, 1, 0)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        # render the chairs as is

        # for chair in models:
        for c in models[ind]:
            gl.glTranslate(CUBE_SIZE * c[0], CUBE_SIZE * c[1],
                           CUBE_SIZE * c[2])
            drawCube()
            gl.glTranslate(-CUBE_SIZE * c[0], -CUBE_SIZE * c[1],
                           -CUBE_SIZE * c[2])

        #rendered the averaged chairs
        # for c in cubes:

        #     gl.glTranslate( CUBE_SIZE*c[0] , CUBE_SIZE*c[1] , CUBE_SIZE*c[2] )
        #     drawCube()
        #     gl.glTranslate( -CUBE_SIZE*c[0] , -CUBE_SIZE*c[1] , -CUBE_SIZE*c[2] )

        ind += 1
        time.sleep(5)
        # Swap front and back buffers
        glfw.swap_buffers(window)

        # Poll for and process events
        glfw.poll_events()

    glfw.terminate()