Esempio n. 1
0
    def __init__(self, pdbdata, mode='cpk'):

        #Mode selection
        if mode not in VisPyViewer.visualization_modes:
            raise Exception('Not recognized visualization mode %s' % mode)
        self.mode = mode

        #Data selection
        atom_information(pdbdata, self.mode)

        self.radius = max(abs(np.concatenate(coordinates)))

        #Canvas + camera
        canvas = scene.SceneCanvas(keys='interactive',
                                   app='pyqt4',
                                   bgcolor='white',
                                   size=(1200, 800),
                                   show=True)
        view = canvas.central_widget.add_view()
        view.camera = scene.ArcballCamera(fov=70, distance=(self.radius + 40))

        #Load visual and apply it
        Spheres = scene.visuals.create_visual_node(SpheresVisual)
        Lines = scene.visuals.create_visual_node(visuals.LinePlotVisual)
        vis_atoms = [Spheres(coordinates, color, radius, parent=view.scene)]
        vis_chains = []
        if self.mode in ['backbone', 'dssp']:
            for i in range(len(chains)):
                vis_chains.append(
                    Lines(chain_coords[i],
                          color=chain_colors[i],
                          parent=view.scene))

        #Run the program
        canvas.app.run()
Esempio n. 2
0
    def __init__(   self,
                    data,
                    boundary=False,
                    visual="cell",
                    animation=None):
        ModularCanvas.__init__(self)

        self.unfreeze()

        self.dimensions = len(data["center"][0])
        self.boundary   = boundary
        self.visual     = visual
        self.animation  = animation
        self._timer     = app.Timer('auto', connect=self.on_timer, start='true')
        self.t0         = default_timer()
        self.t          = 0

        pos             = np.empty( (1,3), dtype=np.float32 )
        if self.visual is "cell" and self.dimensions > 1:
            self.addVisualObject(0,scene.visuals.Line(  pos=np.asarray(pos,dtype=np.float32),
                                                        connect="segments"))
        elif self.visual is "point" or self.dimensions==1:
            self.addVisualObject(0,scene.visuals.Markers(   pos=np.asarray(pos,dtype=np.float32),
                                                            size=3))
        else:
            raise ValueError("Invalid visual type!")

        self.updateData(data)

        if self.dimensions > 2:
            self.view.camera = scene.ArcballCamera(fov=0)

        self.freeze()
Esempio n. 3
0
def plot_line_vispy(points,
                    clf=True,
                    tube_radius=1.,
                    colour=None,
                    zero_centroid=True,
                    closed=False,
                    mus=None,
                    cmap=None,
                    tube_points=8,
                    **kwargs):
    # Add an extra point to fix tube drawing bug
    last_tangent = points[-1] - points[-2]
    points = n.vstack([points, points[-1] + 0.0001 * last_tangent])

    ensure_vispy_canvas()
    if clf:
        clear_vispy_canvas()
    canvas = vispy_canvas
    from vispy import app, scene, color

    if isinstance(cmap, str):
        from matplotlib.cm import get_cmap
        mpl_cmap = get_cmap(cmap)
        cmap = lambda v: n.array(mpl_cmap(v))
    cmap = cmap or (lambda c: hsv_to_rgb(c, 1, 1))

    if colour is None:
        colours = n.linspace(0, 1, len(points))
        colours = n.array([cmap(c) for c in colours])
    else:
        colours = color.ColorArray(colour)

    if mus is not None:
        colours = n.array([hsv_to_rgb(c, 1, 1) for c in mus])

    l = scene.visuals.Tube(points,
                           color=colours,
                           shading='smooth',
                           radius=tube_radius,
                           tube_points=tube_points,
                           closed=closed)

    canvas.view.add(l)
    # canvas.view.camera = 'arcball'
    canvas.view.camera = scene.ArcballCamera(fov=30,
                                             distance=7.5 *
                                             n.max(n.abs(points)))
    #canvas.view.camera = scene.TurntableCamera(fov=30)
    if zero_centroid:
        l.transform = MatrixTransform()
        # l.transform = scene.transforms.AffineTransform()
        l.transform.translate(-1 * n.average(points, axis=0))

    canvas.show()
    # import ipdb
    # ipdb.set_trace()
    return canvas
Esempio n. 4
0
def plot_vispy_cube():
    ensure_vispy_canvas()
    clear_vispy_canvas()
    canvas = vispy_canvas

    from vispy import app, scene, color

    c = scene.visuals.Cube((5, 2, 10), color='blue', edge_color='red')
    canvas.view.add(c)
    canvas.view.camera = scene.ArcballCamera(fov=30, distance=20)
    canvas.show()
Esempio n. 5
0
def initialize_plot(canvas={},
                    view=None,
                    cam={},
                    elements=None,
                    title='BEEF Element plot'):
    if elements is not None:
        nodes = list(set([a for b in [el.nodes for el in elements]
                          for a in b]))  #flat list of unique nodes
        node_pos = np.vstack([node.coordinates for node in nodes])
        global_cog = np.mean(node_pos, axis=0)
    else:
        global_cog = np.array([0, 0, 0])

    cam_settings = dict(up='z', fov=0, distance=2000,
                        center=global_cog)  #standard values

    if type(canvas) is not scene.SceneCanvas:
        sc_settings = dict(bgcolor='white', title=title)
        sc_settings.update(**canvas)
        canvas = scene.SceneCanvas(**sc_settings)

    if view == None:
        view = canvas.central_widget.add_view()
    else:
        cam = view.camera

    if type(cam) in [
            scene.cameras.TurntableCamera, scene.cameras.BaseCamera,
            scene.cameras.FlyCamera, scene.cameras.ArcballCamera,
            scene.cameras.PanZoomCamera, scene.cameras.Magnify1DCamera
    ]:
        view.camera = cam
    else:  # still a dict
        cam_settings.update(**cam)
        view.camera = scene.ArcballCamera(**cam_settings)

    return view, canvas, view.camera
Esempio n. 6
0
        view.view_program.vert['visual_to_framebuffer'] = view.get_transform(
            'visual', 'framebuffer')
        view.view_program.vert['framebuffer_to_visual'] = view.get_transform(
            'framebuffer', 'visual')
        view.view_program.vert['framebuffer_to_render'] = view.get_transform(
            'framebuffer', 'render')


Spheres = scene.visuals.create_visual_node(SpheresVisual)

if __name__ == '__main__':
    from vispy import scene

    canvas = scene.SceneCanvas(keys='interactive',
                               app='pyqt4',
                               bgcolor='white',
                               size=(1000, 800),
                               show=True)
    view = canvas.central_widget.add_view()
    view.camera = scene.ArcballCamera(fov=70, distance=50)

    N = 2000
    coordinates = np.random.normal(size=(N, 3), scale=10)
    color = np.random.random(size=(N, 4))
    color[:, 3] = 1.0
    radius = np.random.normal(size=N, loc=4.0, scale=0.5)
    print radius
    spheres = [Spheres(coordinates, color, radius, parent=view.scene)]

    canvas.app.run()
Esempio n. 7
0
                    '-c',
                    default='camera_calib.yml',
                    help='the camera calibration results')
parser.add_argument('--rgb', required=True, help='the RGB image')
parser.add_argument('--disp',
                    required=True,
                    help='the disparity data (*.png, *.data)')
parser.add_argument('--output',
                    '-o',
                    default='pointcloud.ply',
                    help='the output point cloud file')
args = parser.parse_args()

canvas = scene.SceneCanvas(keys='interactive', show=True)
view = canvas.central_widget.add_view()
view.camera = scene.ArcballCamera(fov=60)
visuals.XYZAxis(parent=view.scene)

if __name__ == '__main__':
    rgb = cv2.imread(args.rgb)
    fs = cv2.FileStorage(args.calib, cv2.FileStorage_READ)
    calib_height = fs.getNode('image_size').mat()[1][0]
    height = rgb.shape[0]
    roi = (0, 0, rgb.shape[1], rgb.shape[0])

    if args.disp:
        if args.disp.endswith('.png'):
            disp = cv2.imread(args.disp, cv2.IMREAD_GRAYSCALE)
        elif args.disp.endswith('.data'):
            disp = utils.load_disparity_binary(args.disp).reshape(
                height, -1).astype(np.float32)
Esempio n. 8
0
    def __init__(self, picking=False, **kwargs):
        # Update some defaults as necessary
        defaults = dict(keys=None,
                        show=True,
                        title='navis Viewer',
                        bgcolor='black')
        defaults.update(kwargs)

        if getattr(config, 'headless'):
            defaults['show'] = False

        # Set border rim -> this depends on how the framework (e.g. QT5)
        # renders the window
        self._rim_bot = 15
        self._rim_top = 20
        self._rim_left = 10
        self._rim_right = 10

        # Generate canvas
        self.canvas = scene.SceneCanvas(**defaults)

        # Add and setup 3d view
        self.view3d = self.canvas.central_widget.add_view()
        self.camera3d = scene.ArcballCamera()
        self.view3d.camera = self.camera3d

        # Add permanent overlays
        self.overlay = self._draw_overlay()

        self.canvas.unfreeze()
        self.canvas._overlay = self.overlay
        self.canvas._view3d = self.view3d
        self.canvas._wrapper = self
        self.canvas.freeze()

        # Add picking functionality
        if picking:
            self.picking = True
        else:
            self.picking = False

        # Set cursor_pos to None
        self.cursor_pos = None

        # Add keyboard shortcuts
        self.canvas.connect(on_key_press)

        # Add resize control to keep overlay in position
        self.canvas.connect(on_resize)

        # Legend settings
        self.__show_legend = False
        self.__selected = []
        self._cycle_index = -1
        self.__legend_font_size = 7

        # Color to use when selecting neurons
        self.highlight_color = (1, .9, .6)

        # Keep track of initial camera position
        self._camera_default = self.view3d.camera.get_state()

        # Cycle mode can be 'hide' or 'alpha'
        self._cycle_mode = 'alpha'

        # Cursors
        self._cursor = None
        self._picking_radius = 20