Beispiel #1
0
class StatusWindow(Window):
    def __init__(self, parent):
        global nomix_set_status
        super(StatusWindow, self).__init__(parent, 'Status')
        # self.setLayout(GridLayout(orientation=Orientation.Vertical))
        self.setSize((1410, 90))
        self.setPosition((15, 750))
        self.label = Label(self, '', 'sans-bold')
        self.label.setFixedSize((1400, 50))
        self.label.setPosition((15, 50))
        nomix_set_status = self.set_status

    def set_status(self, status):
        self.label.setCaption(status)
Beispiel #2
0
class VoxelGridViewer(ViewerApp):
    """Viewer to visualize a given fixed voxelgrid"""
    def __init__(self, voxel_grids, normals=None, mesh_file=None):
        super(VoxelGridViewer, self).__init__()
        self.disp_idx = 0
        self.voxel_grids = voxel_grids
        self.normals = normals

        if mesh_file is not None:
            self.mesh = TriangleMesh(mesh_file)
        else:
            self.mesh = None

        window = Window(self, "VoxelGridViewer")
        window.setPosition((15, 15))
        window.setLayout(GroupLayout())

        tools = Widget(window)
        tools.setLayout(
            BoxLayout(Orientation.Horizontal, Alignment.Middle, 0, 5))

        self.label = Label(window, self.voxel_grids[self.disp_idx][0])

        self.selected_voxel = None
        self.performLayout()

    def keyboardEvent(self, key, scancode, action, modifiers):
        if super(VoxelGridViewer, self).keyboardEvent(key, scancode, action,
                                                      modifiers):
            return True

        num_keys = [
            glfw.KEY_1, glfw.KEY_2, glfw.KEY_3, glfw.KEY_4, glfw.KEY_5,
            glfw.KEY_6, glfw.KEY_7, glfw.KEY_8, glfw.KEY_9, glfw.KEY_0
        ]

        if action == glfw.PRESS and key in num_keys:
            idx = num_keys.index(key)
            self.disp_idx = np.minimum(len(self.voxel_grids) - 1, idx)
            self.label.setCaption(self.voxel_grids[self.disp_idx][0])
            self.performLayout()
            return True
        return False

    def update_displayed_scattering(self, p):
        d = get_view_ray_dir(p, self.size(), self.camera)
        if self.mesh:
            intersector = self.mesh.mesh.ray
            its_loc, ray_idx, tri_idx = intersector.intersects_location(
                self.camera.pos[np.newaxis, :], d[np.newaxis, :])
            if len(its_loc) > 0:
                dist_to_cam = np.sum((its_loc - self.camera.pos)**2, axis=1)
                its_loc = np.array(its_loc[np.argmin(dist_to_cam), :],
                                   dtype=np.float32)
                voxel_idx = self.voxel_grids[0][1].point_to_vox_idx(its_loc)

                # Update displayed voxel
                self.render_context.its_loc = its_loc
                self.selected_voxel = voxel_idx

                print('Voxel Index: {}'.format(voxel_idx))
                print('Selected point {}'.format(its_loc))

    def mouseButtonEvent(self, p, button, action, modifier):
        if super(VoxelGridViewer,
                 self).mouseButtonEvent(p, button, action, modifier):
            return True
        if button == 0 and action == glfw.PRESS and modifier == 0 and self.mesh is not None:
            self.update_displayed_scattering(p)
            return True
        return False

    def drawContents(self):
        super(VoxelGridViewer, self).drawContents()

        self.render_context.shader.bind()
        gl.Enable(gl.DEPTH_TEST)
        draw_box(self.render_context.shader,
                 self.voxel_grids[self.disp_idx][1].vxbb_min,
                 self.voxel_grids[self.disp_idx][1].vxbb_max,
                 self.camera.viewproj, np.array([1, 1, 0], dtype=np.float32))

        if self.mesh is not None:
            self.mesh.draw_contents(self.camera, self.render_context,
                                    self.voxel_grids[self.disp_idx][1])
        self.voxel_grids[self.disp_idx][1].draw_contents(
            self.camera, self.render_context)
        if self.normals is not None:
            self.normals.draw_contents(self.camera, self.render_context)

        if self.selected_voxel is not None:
            vxgrid = self.voxel_grids[0][1]
            voxel_diag_ws = (vxgrid.vxbb_max -
                             vxgrid.vxbb_min) / vxgrid.voxel_grid_res
            # Round position to index

            minvox = (self.selected_voxel / vxgrid.voxel_grid_res) * \
                (vxgrid.vxbb_max - vxgrid.vxbb_min) + vxgrid.vxbb_min

            maxvox = minvox + voxel_diag_ws
            draw_box(self.render_context.shader, minvox, maxvox,
                     self.camera.viewproj, np.array([1, 0, 0],
                                                    dtype=np.float32))