Example #1
0
    def __init__(self,
                 position,
                 width,
                 height,
                 depth,
                 color,
                 shader_manager=None):
        box_mesh, box_faces, _ = geometry.create_box(
            width,
            height,
            depth,
            width_segments=int(width * 5),
            height_segments=int(height * 5),
            depth_segments=int(depth * 5))

        box_buffer = np.zeros(len(box_mesh['position']),
                              dtype=[('a_position', np.float32, 3),
                                     ('a_normal', np.float32, 3)])

        box_buffer['a_position'] = box_mesh['position']
        box_buffer['a_normal'] = box_mesh['normal']
        # No textures for now
        # vertex_buffer['a_texcoord'] = box_buffer['texcoord']

        super(self.__class__, self).__init__(gloo.VertexBuffer(box_buffer),
                                             faces=box_faces,
                                             position=position,
                                             color=color)
Example #2
0
    def __init__(self):
        app.Canvas.__init__(self, keys='interactive', size=(800, 550))

        vertices, faces, outline = create_box(width=1, height=1, depth=1,
                                              width_segments=4,
                                              height_segments=8,
                                              depth_segments=16)

        self.box = visuals.BoxVisual(width=1, height=1, depth=1,
                                     width_segments=4,
                                     height_segments=8,
                                     depth_segments=16,
                                     vertex_colors=vertices['color'],
                                     edge_color='b')

        self.theta = 0
        self.phi = 0

        self.transform = MatrixTransform()

        self.box.transform = self.transform
        self.show()

        self.timer = app.Timer(connect=self.rotate)
        self.timer.start(0.016)
Example #3
0
    def __init__(self):
        app.Canvas.__init__(self, keys='interactive', size=(800, 550))

        vertices, faces, outline = create_box(width=1, height=1, depth=1,
                                              width_segments=4,
                                              height_segments=8,
                                              depth_segments=16)

        self.box = visuals.BoxVisual(width=1, height=1, depth=1,
                                     width_segments=4,
                                     height_segments=8,
                                     depth_segments=16,
                                     vertex_colors=vertices['color'],
                                     edge_color='b')

        self.theta = 0
        self.phi = 0

        self.transform = MatrixTransform()

        self.box.transform = self.transform
        self.show()

        self.timer = app.Timer(connect=self.rotate)
        self.timer.start(0.016)
    def reset(self, sem_color_dict=None):
        """ Reset. """
        # new canvas prepared for visualizing data
        self.map_color(sem_color_dict=sem_color_dict)
        self.canvas = SceneCanvas(keys='interactive', show=True)
        # grid
        self.grid = self.canvas.central_widget.add_grid()

        # laserscan part
        self.scan_view = vispy.scene.widgets.ViewBox(border_color='white',
                                                     parent=self.canvas.scene)
        self.grid.add_widget(self.scan_view, 0, 0)
        self.scan_view.camera = 'turntable'

        self.scan_vis = visuals.Markers()
        self.scan_view.add(self.scan_vis)

        if self.viz_joint:
            self.joint_vis = visuals.Arrow(connect='segments',
                                           arrow_size=18,
                                           color='blue',
                                           width=10,
                                           arrow_type='angle_60')
            self.arrow_length = 10
            self.scan_view.add(self.joint_vis)
        if self.viz_box:
            vertices, faces, outline = create_box(width=1,
                                                  height=1,
                                                  depth=1,
                                                  width_segments=1,
                                                  height_segments=1,
                                                  depth_segments=1)
            vertices['color'][:, 3] = 0.2
            # breakpoint()
            self.box = visuals.Box(vertex_colors=vertices['color'],
                                   edge_color='b')
            self.box.transform = STTransform(translate=[-2.5, 0, 0])
            self.theta = 0
            self.phi = 0
            self.scan_view.add(self.box)
        visuals.XYZAxis(parent=self.scan_view.scene)

        # add nocs
        if self.viz_label:
            print("Using nocs in visualizer")
            self.nocs_view = vispy.scene.widgets.ViewBox(
                border_color='white', parent=self.canvas.scene)
            self.grid.add_widget(self.nocs_view, 0, 1)
            self.label_vis = visuals.Markers()
            self.nocs_view.camera = 'turntable'
            self.nocs_view.add(self.label_vis)
            visuals.XYZAxis(parent=self.nocs_view.scene)
            self.nocs_view.camera.link(self.scan_view.camera)
Example #5
0
    def __init__(self, position, width, height, depth, color):
        box_mesh, box_faces, _ = geometry.create_box(
            width, height, depth,
            width_segments=int(width * 5),
            height_segments=int(height * 5),
            depth_segments=int(depth * 5)
        )

        box_buffer = np.zeros(
            len(box_mesh['position']),
            dtype=[
                ('a_position', np.float32, 3),
                ('a_normal', np.float32, 3)
            ]
        )

        box_buffer['a_position'] = box_mesh['position']
        box_buffer['a_normal'] = box_mesh['normal']
        # No textures for now
        # vertex_buffer['a_texcoord'] = box_buffer['texcoord']

        super(self.__class__, self).__init__(gloo.VertexBuffer(box_buffer), faces=box_faces, position=position, color=color)
Example #6
0
def test_box():
    """Test box function"""
    vertices, filled, outline = create_box()
    assert_array_equal(np.arange(len(vertices)), np.unique(filled))
    assert_array_equal(np.arange(len(vertices)), np.unique(outline))
Example #7
0
"""
Simple demonstration of the box geometry.
"""

import sys

from vispy import scene
from vispy import geometry

canvas = scene.SceneCanvas(keys='interactive', size=(800, 600), show=True)

view = canvas.central_widget.add_view()

vertices, faces, outline = geometry.create_box(width=2, height=4, depth=8,
                                               width_segments=4,
                                               height_segments=8,
                                               depth_segments=16)

box = scene.visuals.Box(width=4, height=4, depth=8, width_segments=4,
                        height_segments=8, depth_segments=16,
                        vertex_colors=vertices['color'],
                        edge_color='k',
                        parent=view.scene)

camera = scene.cameras.TurntableCamera(fov=45, azimuth=60, parent=view.scene)
view.camera = camera

if __name__ == '__main__' and sys.flags.interactive == 0:
    canvas.app.run()