Ejemplo n.º 1
0
    def reset(self):
        """ Reset. """
        # last key press (it should have a mutex, but visualization is not
        # safety critical, so let's do things wrong)
        self.action = "no"  # no, next, back, quit are the possibilities

        # new canvas prepared for visualizing data
        self.canvas = SceneCanvas(keys='interactive',
                                  show=True,
                                  size=self.canvas_size)
        # interface (n next, b back, q quit, very simple)
        self.canvas.events.key_press.connect(self.key_press)
        self.canvas.events.draw.connect(self.draw)

        # laserscan part
        self.scan_view = vispy.scene.widgets.ViewBox(border_color='white',
                                                     parent=self.canvas.scene)
        self.scan_view.camera = vispy.scene.TurntableCamera(elevation=30,
                                                            azimuth=-90,
                                                            distance=30,
                                                            translate_speed=30,
                                                            up='+z')
        # grid
        self.grid = self.canvas.central_widget.add_grid()
        self.grid.add_widget(self.scan_view)

        self.scan_vis = visuals.Markers(parent=self.scan_view.scene)
        self.scan_vis.antialias = 0
        # self.scan_view.add(self.scan_vis)
        visuals.XYZAxis(parent=self.scan_view.scene)

        self.line = visuals.Line(width=1,
                                 method='gl',
                                 parent=self.scan_view.scene)
        self.text = visuals.Text(color='red',
                                 font_size=600,
                                 bold=True,
                                 parent=self.scan_view.scene)
        self.gt_line = visuals.Line(width=1000, parent=self.scan_view.scene)
        # self.sem_view.camera.link(self.scan_view.camera)

        if self.show_img:
            # img canvas size

            # new canvas for img
            self.img_canvas = SceneCanvas(keys='interactive',
                                          show=True,
                                          size=(1242, 375))
            # grid
            self.img_grid = self.img_canvas.central_widget.add_grid()
            # interface (n next, b back, q quit, very simple)
            self.img_canvas.events.key_press.connect(self.key_press)
            self.img_canvas.events.draw.connect(self.draw)

            # add a view for the depth
            self.img_view = vispy.scene.widgets.ViewBox(
                border_color='white', parent=self.img_canvas.scene)
            self.img_grid.add_widget(self.img_view, 0, 0)
            self.img_vis = visuals.Image(cmap='viridis')
            self.img_view.add(self.img_vis)
Ejemplo n.º 2
0
 def __build_gaze_rays(self):
     self.le_vtx = np.vstack((self.leyeball, self.leyeball))
     self.re_vtx = np.vstack((self.reyeball, self.reyeball))
     le_ray = visuals.Line(self.le_vtx, color='red', width=3)
     re_ray = visuals.Line(self.re_vtx, color='green', width=3)
     self.view.add(le_ray)
     self.view.add(re_ray)
Ejemplo n.º 3
0
    def __init__(self,
                 _xyz=[],
                 c_xyz=None,
                 c_connect=None,
                 c_select=None,
                 c_colorby='strength',
                 c_dynamic=None,
                 c_cmap='viridis',
                 c_vmin=None,
                 c_vmax=None,
                 c_colval=None,
                 c_under=None,
                 c_over=None,
                 c_clim=(0., 1.),
                 c_linewidth=3.,
                 c_dradius=30.,
                 c_blxyz=.1,
                 c_blradius=13.,
                 c_bundling=False,
                 **kwargs):
        """Init."""
        # Initialize elements :
        if (_xyz is not None) and (c_xyz is None):
            warn("No node's coordinates found for connectivity (c_xyz). "
                 "Source's location will be used instead")
            # Connectivity properties :
            self.xyz = _xyz
        else:
            self.xyz = c_xyz
        self.connect = c_connect
        self.select = c_select
        self._lw = c_linewidth
        self.needupdate = True
        # Color :
        self.colorby = c_colorby
        self.dynamic = c_dynamic
        self.colval = c_colval
        # Density :
        self.dradius = c_dradius
        # Bundling :
        self.bl = c_bundling
        self.blradius = c_blradius
        self.blxyz = c_blxyz
        self.blinterp = 100

        # Initialize colormap :
        isvmin, isvmax = c_vmin is not None, c_vmax is not None
        CbarArgs.__init__(self, c_cmap, c_clim, isvmin, c_vmin, isvmax, c_vmax,
                          c_under, c_over)

        # Object creation :
        if (self.xyz is not None) and (self.connect is not None):
            self.mesh = visu.Line(name='Connectivity', antialias=False)
            self.mesh.set_gl_state('translucent')
            self.update()
            self._maskbck = self.connect.mask.copy()
        else:
            self.mesh = visu.Line(name='NoneConnect')
Ejemplo n.º 4
0
 def __init__(self):
     vispy.scene.SceneCanvas.__init__(self,
                                      keys='interactive',
                                      size=(800, 800),
                                      show=True)
     self.line = visuals.Line(pos, color, parent=self.scene)
     self.line.events.update.connect(lambda evt: self.update)
Ejemplo n.º 5
0
    def __init__(self, name, nodes, edges, select=None, line_width=3.,
                 color_by='strength', custom_colors=None, alpha=1.,
                 antialias=False, dynamic=None, dynamic_order=1,
                 dynamic_orientation='ascending', cmap='viridis', clim=None,
                 vmin=None, vmax=None, under='gray', over='red',
                 transform=None, parent=None, verbose=None, _z=-10., **kw):
        """Init."""
        VisbrainObject.__init__(self, name, parent, transform, verbose, **kw)
        self._update_cbar_args(cmap, clim, vmin, vmax, under, over)

        # _______________________ CHECKING _______________________
        # Nodes :
        assert isinstance(nodes, np.ndarray) and nodes.ndim == 2
        sh = nodes.shape
        self._n_nodes = sh[0]
        assert sh[1] >= 2
        pos = nodes if sh[1] == 3 else np.c_[nodes, np.full((len(self),), _z)]
        self._pos = pos.astype(np.float32)
        logger.info("    %i nodes detected" % self._pos.shape[0])
        # Edges :
        if np.ndim(edges) == 3:
            self.time_edges = edges
            edges = edges[:,:,0]
        assert edges.shape == (len(self), len(self))
        if not np.ma.isMA(edges):
            mask = np.zeros(edges.shape, dtype=bool)
            edges = np.ma.masked_array(edges, mask=mask)
        # Select :
        if isinstance(select, np.ndarray):
            assert select.shape == edges.shape and select.dtype == bool
            edges.mask = np.invert(select)
        if color_by is not 'causal':
            edges.mask[np.tril_indices(len(self), 0)] = True
        edges.mask[np.diag_indices(len(self))] = True
        self._edges = edges
        # Colorby :
        assert color_by in ['strength', 'count', 'causal']
        self._color_by = color_by
        # Dynamic :
        if dynamic is not None:
            assert len(dynamic) == 2
        self._dynamic = dynamic
        assert isinstance(dynamic_order, int) and dynamic_order > 0
        self._dyn_order = dynamic_order
        self._dyn_orient = dynamic_orientation
        # Custom color :
        if custom_colors is not None:
            assert isinstance(custom_colors, dict)
        self._custom_colors = custom_colors
        # Alpha :
        assert 0. <= alpha <= 1.
        self._alpha = alpha

        # _______________________ LINE _______________________
        self._connect = visuals.Line(name='ConnectObjLine', width=line_width,
                                     antialias=antialias, parent=self._node,
                                     connect='segments')
        self._connect.set_gl_state('translucent', depth_test=False,
                                   cull_face=False)
        self._build_line()
Ejemplo n.º 6
0
    def init_canvas(self):
        if self.verbose == 1:
            print('init_canvas')
        app.use_app('ipynb_webgl')
        ca = vispy.scene.SceneCanvas(keys='interactive', show=True,size=(self.canvas_width,self.canvas_height),bgcolor=[1,1,1])
        ca.show()
        self.canvas = ca
        view = ca.central_widget.add_view()
        
        self.text = visuals.Text(anchor_x='right')
        view.add(self.text)
        self.label_texts = visuals.Text(anchor_x='right')
        view.add(self.label_texts)
               
        self.camera = CustomPanZoomCamera([self.text,self.label_texts])
        view.camera = self.camera

        axis = visuals.Axis(parent=view.scene)
        
        self.view = view
        
        self.line = visuals.Line()
        self.line.set_data(pos=np.array([[0,0,0]]),color=np.array([[0,0,0,0]]))
        self.line.order = 1
        self.view.add(self.line)
        
        self.mesh = visuals.Mesh()
        self.mesh.order = 0 
        self.view.add(self.mesh)
        
        app.run()
    def __init__(self, keyupdateCB):
        scene.SceneCanvas.__init__(self, keys=None)
        self.size = 800, 600
        self.unfreeze()
        self.view = self.central_widget.add_view()
        self.view.bgcolor = '#ffffff'
        self.view.camera = TurntableCamera(fov=10.0,
                                           distance=30.0,
                                           up='+z',
                                           center=(0.0, 0.0, 0.0))
        self.last_pos = [0, 0, 0]
        self.pos_markers = visuals.Markers()
        self.meas_markers = visuals.Markers()
        self.pos_data = np.array([0, 0, 0], ndmin=2)
        self.meas_data = np.array([0, 0, 0], ndmin=2)
        self.lines = []

        self.view.add(self.pos_markers)
        self.view.add(self.meas_markers)
        for i in range(6):
            line = visuals.Line()
            self.lines.append(line)
            self.view.add(line)

        self.keyCB = keyupdateCB

        self.freeze()

        scene.visuals.XYZAxis(parent=self.view.scene)
Ejemplo n.º 8
0
def plot_line(skel, center=np.asarray([0,0,0])):
    line_color = (1, 0, 0, 1)
    lines = []
    segments = lines_from_skel(skel, center)
    for l in segments:
        line = visuals.Line(l, color=line_color, width=10)
        lines.append(line)
    return lines
Ejemplo n.º 9
0
def make_grid(view, x_span, x_major_tick, y_span, y_major_tick):
    x_count = int(np.ceil(x_span/x_major_tick))
    y_count = int(np.ceil(y_span/y_major_tick))
    x_range = x_count*x_major_tick
    y_range = y_count*y_major_tick

    for k in range(y_count+1):
        y = k*y_major_tick
        line = visuals.Line(
            pos=np.array([[-x_range, y], [x_range, y]]),
            color=(0.0, 1.0, 1.0, 1.0))
        view.add(line)

    for k in range(-x_count, x_count+1):
        x = k*x_major_tick
        line = visuals.Line(
            pos=np.array([[x, 0], [x, y_range]]),
            color=(0.0, 1.0, 1.0, 1.0))
        view.add(line)
Ejemplo n.º 10
0
    def __init__(self,
                 name,
                 data,
                 xyz,
                 select=None,
                 line_width=1.5,
                 color='white',
                 ts_amp=6.,
                 ts_width=20.,
                 alpha=1.,
                 antialias=False,
                 translate=(0., 0., 1.),
                 transform=None,
                 parent=None,
                 verbose=None,
                 _z=-10.,
                 **kw):
        """Init."""
        # Init Visbrain object base class :
        VisbrainObject.__init__(self, name, parent, transform, verbose, **kw)
        # _______________________ CHECKING _______________________
        # Data :
        assert isinstance(data, np.ndarray) and data.ndim == 2
        self._n_nodes, self._n_pts = data.shape
        self._data = data
        # XYZ :
        sh = xyz.shape
        assert sh[1] in [2, 3]
        xyz = xyz if sh[1] == 3 else np.c_[xyz, np.full((len(self), ), _z)]
        self._xyz = xyz.astype(np.float32)
        # Select :
        select = np.arange(len(self)) if select is None else select
        assert isinstance(select, (list, np.ndarray))
        self._select = select
        # Amplitude / width :
        assert isinstance(ts_amp, float) and isinstance(ts_width, float)
        self._ts_amp, self._ts_width = ts_amp, ts_width
        # Translate :
        assert len(translate) == 3
        tr = vist.STTransform(translate=translate)
        self._translate = translate
        # Line width :
        self._line_width = line_width
        # Color :
        self._color = color2vb(color, alpha=alpha)
        self._alpha = alpha

        # _______________________ LINE _______________________
        self._ts = visuals.Line(name='TimeSeriesObjLine',
                                parent=self._node,
                                width=line_width,
                                color=self._color,
                                antialias=antialias)
        self._ts.transform = tr
        self._build_line()
Ejemplo n.º 11
0
Archivo: line.py Proyecto: kod3r/vispy
 def __init__(self):
     vispy.scene.SceneCanvas.__init__(self,
                                      keys='interactive',
                                      size=(800, 800),
                                      show=True)
     # Create several visuals demonstrating different features of Line
     self.lines = [
         # agg-mode lines:
         visuals.Line(pos=pos, color=color, mode='agg'),  # per-vertex color
         visuals.Line(pos=pos, color=(0, 0.5, 0.3, 1), mode='agg'),  # solid
         visuals.Line(pos=pos, color=color, width=5, mode='agg'),  # wide
         # GL-mode lines:
         visuals.Line(pos=pos, color=color, mode='gl'),
         visuals.Line(pos=pos, color=(0, 0.5, 0.3, 1), mode='gl'),
         visuals.Line(pos=pos, color=color, width=5, mode='gl'),
         # GL-mode: "connect" not available in AGG mode yet
         visuals.Line(pos=pos,
                      color=(0, 0.5, 0.3, 1),
                      connect='segments',
                      mode='gl'),  # only connect alternate vert pairs
         visuals.Line(pos=pos,
                      color=(0, 0.5, 0.3, 1),
                      connect=connect,
                      mode='gl'),  # connect specific pairs
     ]
     counts = [0, 0]
     for i, line in enumerate(self.lines):
         # arrange lines in a grid
         tidx = (line.mode == 'agg')
         x = 400 * tidx
         y = 140 * (counts[tidx] + 1)
         counts[tidx] += 1
         line.transform = STTransform(translate=[x, y])
         # redraw the canvas if any visuals request an update
         line.events.update.connect(lambda evt: self.update())
         line.parent = self.central_widget
     self.texts = [
         visuals.Text('GL',
                      bold=True,
                      font_size=24,
                      color='w',
                      pos=(200, 40),
                      parent=self.central_widget),
         visuals.Text('Agg',
                      bold=True,
                      font_size=24,
                      color='w',
                      pos=(600, 40),
                      parent=self.central_widget)
     ]
Ejemplo n.º 12
0
    def line_box(self, box, color=(0, 1, 0, 0.1)):
        p0 = np.array([
            box[1] - float(box[4]) / 2.0,
            box[2] - float(box[5]) / 2.0,
            box[3] - float(box[6]) / 2.0,
        ])
        p1 = np.array([
            box[1] - float(box[4]) / 2.0,
            box[2] + float(box[5]) / 2.0,
            box[3] - float(box[6]) / 2.0,
        ])
        p2 = np.array([
            box[1] + float(box[4]) / 2.0,
            box[2] + float(box[5]) / 2.0,
            box[3] - float(box[6]) / 2.0,
        ])
        p3 = np.array([
            box[1] + float(box[4]) / 2.0,
            box[2] - float(box[5]) / 2.0,
            box[3] - float(box[6]) / 2.0,
        ])

        p4 = np.array([
            box[1] - float(box[4]) / 2.0,
            box[2] - float(box[5]) / 2.0,
            box[3] + float(box[6]) / 2.0,
        ])
        p5 = np.array([
            box[1] - float(box[4]) / 2.0,
            box[2] + float(box[5]) / 2.0,
            box[3] + float(box[6]) / 2.0,
        ])
        p6 = np.array([
            box[1] + float(box[4]) / 2.0,
            box[2] + float(box[5]) / 2.0,
            box[3] + float(box[6]) / 2.0,
        ])
        p7 = np.array([
            box[1] + float(box[4]) / 2.0,
            box[2] - float(box[5]) / 2.0,
            box[3] + float(box[6]) / 2.0,
        ])

        pos = np.vstack(
            (p0, p1, p2, p3, p0, p4, p5, p6, p7, p4, p5, p1, p2, p6, p7, p3))
        lines = visuals.Line(pos=pos,
                             connect='strip',
                             width=1,
                             color=color,
                             method='gl')

        return lines
Ejemplo n.º 13
0
def add_box(view, size=132, offset=54):
    box_coord = np.array(
        [[0, 0, 0], [0, 1, 0], [1, 1, 0], [1, 0, 0], [0, 0, 0], [0, 0, 1],
         [0, 1, 1], [0, 1, 0], [0, 0, 0], [0, 1, 0], [0, 1, 1], [1, 1, 1],
         [1, 1, 0], [0, 1, 0]],
        dtype=np.float32)

    box_pos = box_coord * size + offset

    box = visuals.Line(pos=box_pos,
                       color=(0.7, 0, 0, 1),
                       method='gl',
                       name='unit box',
                       parent=view)
Ejemplo n.º 14
0
def line_box_stand(box, color=(0, 1, 0, 0.1)):
    box_np = np.array([box[1], box[2], box[3], box[4], box[5], box[6]],
                      dtype=np.float32)
    p0, p1, p2, p3, p4, p5, p6, p7 = box3d_2conner(
        box_np, box[7])  # box : x,y,z,l,w,h,rot
    pos = np.vstack(
        (p0, p1, p2, p3, p0, p4, p5, p6, p7, p4, p5, p1, p2, p6, p7, p3))
    lines = visuals.Line(pos=pos,
                         connect='strip',
                         width=1,
                         color=color,
                         antialias=True,
                         method='gl')

    return lines
Ejemplo n.º 15
0
def line_box(box_center, box_size, rot, color=(0, 1, 0, 0.1)):
    box = np.array([
        box_center[0], box_center[1], box_center[2], 2.0, box_size[0],
        box_size[2]
    ],
                   dtype=np.float32)  #box_size[1] #TODO:just for view
    p0, p1, p2, p3, p4, p5, p6, p7 = box3d_2conner(box, rot)
    pos = np.vstack(
        (p0, p1, p2, p3, p0, p4, p5, p6, p7, p4, p5, p1, p2, p6, p7, p3))
    lines = visuals.Line(pos=pos,
                         connect='strip',
                         width=1,
                         color=color,
                         antialias=True,
                         method='gl')

    return lines
Ejemplo n.º 16
0
    def search_button_click(self):
        print('searching object : {}'.format(self.le.text()))
        objects_dict = self.scan.tsdf_vol.node_data

        is_obj_exist = []

        self.clear_searched_items(self.verticalLayoutRight)

        for key, val in objects_dict.items():
            if (val['class'] == self.le.text()):
                print('find {}'.format(self.le.text()))

                thumbnail_path = os.path.join(
                    self.scan.tsdf_vol.bbox_path,
                    'thumbnail_' + str(key) + '_' +
                    str(int(objects_dict[str(key)]['detection_cnt'] / 2)) +
                    '.png')
                cv2_img = cv2.cvtColor(cv2.imread(thumbnail_path),
                                       cv2.COLOR_BGR2RGB)
                image = QImage(cv2_img.data, cv2_img.shape[1],
                               cv2_img.shape[0], cv2_img.strides[0],
                               QImage.Format_RGB888)
                image_frame = QLabel()
                image_frame.setPixmap(QPixmap.fromImage(image))
                self.verticalLayoutRight.addWidget(image_frame)

                checkBox = QCheckBox(val['class'] + str(key))
                self.checkBox_list += [[checkBox, val['class'], str(key)]]

                scan_bbox_3d = visuals.Line()
                self.checkBox_with_3D += [scan_bbox_3d]
                self.scan_view.add(scan_bbox_3d)

                checkBox.stateChanged.connect(self.checkBoxState)

                # searched_obj = QLabel(val['class'] + str(key))
                self.verticalLayoutRight.addWidget(checkBox)
                is_obj_exist += [True]

        if (not is_obj_exist):
            searched_obj = QLabel("Nothing was found!")
            self.verticalLayoutRight.addWidget(searched_obj)
        else:
            searched_obj = QLabel(
                "Check box if you want to find objects in 3D Scene.")
            self.verticalLayoutRight.addWidget(searched_obj)
Ejemplo n.º 17
0
    def clear_searched_items(self, layout):
        # reset rearching results widget
        while layout.count() > 0:
            item = layout.takeAt(0)
            if not item:
                continue

            w = item.widget()
            if w:
                w.deleteLater()

        # reset visuals.Line for 3D BBox of searched objects
        for i, check in enumerate(self.checkBox_list):
            self.checkBox_with_3D[i].parent = None
            self.checkBox_with_3D[i] = visuals.Line()
            self.scan_view.add(self.checkBox_with_3D[i])

        self.checkBox_list = []
        self.checkBox_with_3D = []
Ejemplo n.º 18
0
def plot3d(p, ll, km_):
    canvas = vispy.scene.SceneCanvas(keys='interactive', show=True)
    view = canvas.central_widget.add_view()
    for c in range(max(km_) + 1):
        yes = n.array(km_) == c
        pp = p[yes]
        scatter = visuals.Markers()
        scatter.set_data(pp,
                         edge_color=None,
                         face_color=(c % 2, (c + 1) % 2, (c // 2) % 2, .5),
                         size=5)
        view.add(scatter)
    line = visuals.Line(pos=p[ll],
                        connect='segments',
                        color=(1, 1, 1, 0.4),
                        method='gl')
    view.add(line)
    view.camera = 'turntable'  # or try 'arcball'
    vispy.app.run()
Ejemplo n.º 19
0
 def checkBoxState(self):
     # checkBox_list is composed of [QcheckBox, class_name, class_3D_ID]
     for i, check in enumerate(self.checkBox_list):
         if check[0].isChecked() == True:
             print('checked!!!')
             # Find 3D BBox in 3D Scene Canvas\
             bbox_3d = np.array(self.scan.tsdf_vol.bbox_3ds[check[2]])
             bbox_connect = np.array([[0, 1], [1, 2], [2, 3], [3,
                                                               0], [4, 5],
                                      [5, 6], [6, 7], [7, 4], [0, 4],
                                      [1, 5], [2, 6], [3, 7]])
             self.checkBox_with_3D[i].set_data(bbox_3d,
                                               color='green',
                                               width=3,
                                               connect=bbox_connect)
         else:
             self.checkBox_with_3D[i].parent = None
             self.checkBox_with_3D[i] = visuals.Line()
             self.scan_view.add(self.checkBox_with_3D[i])
Ejemplo n.º 20
0
    def __init__(self):

        # Define several Line visuals that use the same position data
        # but have different colors and transformations
        colors = [color, (1, 0, 0, 1), (0, 1, 0, 1), (0, 0, 1, 1),
                  (1, 1, 0, 1), (1, 1, 1, 1)]

        self.lines = [visuals.Line(pos=pos, color=colors[i])
                      for i in range(6)]

        center = STTransform(translate=(400, 400))

        self.lines[0].transform = center

        self.lines[1].transform = (center * 
                                   STTransform(scale=(1, 0.1, 1)))

        self.lines[2].transform = (center * 
                                   STTransform(translate=(200, 200, 0)) *
                                   STTransform(scale=(0.3, 0.5, 1)))

        self.lines[3].transform = (center * 
                                   STTransform(translate=(-200, -200, 0),
                                               scale=(200, 1)) *
                                   LogTransform(base=(10, 0, 0)) *
                                   STTransform(translate=(1, 0, 0)))

        self.lines[4].transform = AffineTransform()
        self.lines[4].transform.rotate(45, (0, 0, 1))
        self.lines[4].transform.scale((0.3, 0.3, 1))
        self.lines[4].transform.translate((200, 200, 0))

        self.lines[5].transform = (STTransform(translate=(200, 600, 0),
                                               scale=(5, 5)) *
                                   PolarTransform() *
                                   LogTransform(base=(2, 0, 0)) *
                                   STTransform(scale=(0.01, 0.1),
                                               translate=(4, 20)))

        vispy.scene.SceneCanvas.__init__(self, keys='interactive')
        self.size = (800, 800)
        self.show()
Ejemplo n.º 21
0
    def __init__(self):
        self.canvas = SceneCanvas(keys='interactive', show=True)
        self.grid = self.canvas.central_widget.add_grid()
        self.view = vispy.scene.widgets.ViewBox(border_color='white',
                                                parent=self.canvas.scene)
        self.grid.add_widget(self.view, 0, 0)

        # Point Cloud Visualizer
        self.sem_vis = visuals.Markers()
        self.view.camera = vispy.scene.cameras.TurntableCamera(up='z',
                                                               azimuth=90)
        self.view.add(self.sem_vis)
        visuals.XYZAxis(parent=self.view.scene)

        # Object Detection Visualizer
        self.obj_vis = visuals.Line()
        self.view.add(self.obj_vis)
        self.connect = np.asarray([[0, 1], [0, 3], [0, 4], [2, 1], [2, 3],
                                   [2, 6], [5, 1], [5, 4], [5, 6], [7, 3],
                                   [7, 4], [7, 6]])
        self.data = load_data(
            'data/data.p')  # Change to data.p for your final submission
Ejemplo n.º 22
0
    def __init__(self,
                 ts_xyz=None,
                 ts_data=None,
                 ts_color='white',
                 ts_amp=6.,
                 ts_width=20.,
                 ts_lw=1.5,
                 ts_dxyz=(0., 0., 1.),
                 ts_select=None,
                 **kwargs):
        """Init."""
        self.xyz = ts_xyz
        self.data = ts_data
        self.select = ts_select
        self.color = color2vb(ts_color)
        self.amp = ts_amp
        self.width = ts_width
        self.lw = ts_lw
        self.dxyz = ts_dxyz

        self.mesh = visu.Line(name='NoneTimeSeries')
        if (ts_xyz is not None) and (ts_data is not None):
            self._data2xyz()
            self.mesh.name = 'TimeSeries'
Ejemplo n.º 23
0
    def __init__(self, parent=None, **kwargs):
        """Init."""
        # _____________________ INIT _____________________
        self._n = 1000
        self._ratio = 4 / 5
        CbarBase.__init__(self, **kwargs)

        # _____________________ CANVAS _____________________
        if parent is None:
            # Define a canvas :
            self._canvas = scene.SceneCanvas(keys='interactive',
                                             show=False,
                                             resizable=True,
                                             dpi=600,
                                             bgcolor=self._bgcolor,
                                             size=(300, 900))
            self._wc = self._canvas.central_widget.add_view()
            parent = self._wc.scene
            # Define the camera :
            self._camera = FixedCam(rect=(-1.2, -1.2, 2.4, 2.4))
            self._wc.camera = self._camera
        self.parent = parent

        # _____________________ OBJECTS _____________________
        # --------------------- Node ---------------------
        # Define node parent and limit node :
        self._cbNode = Node(name='Colorbar', parent=parent)
        self._limNode = Node(name='Limits', parent=self._cbNode)
        # Rescale between (-1., 1.) :
        self._rsc = vist.STTransform(scale=(self._width, 2 / self._n, 1),
                                     translate=(0, -1., 0))
        # Set transformation to the node :
        self._cbNode.transform = self._rsc

        # --------------------- Image ---------------------
        self._mImage = visuals.Image(parent=self._cbNode, name='image')

        # --------------------- Border ---------------------
        pos = np.array([[0., 0., -3.], [1., 0., -3.], [1., 0., -3.],
                        [1., self._n, -3.], [1., self._n, -3.],
                        [0., self._n, -3.], [0., self._n, -3.], [0., 0., -3.]])
        self._mBorder = visuals.Line(parent=self._cbNode, name='Border')
        self._mBorder.set_data(pos=pos,
                               width=2.,
                               connect='segments',
                               color=self._txtcolor)
        self._mBorder.visible = self._border

        # --------------------- Labels ---------------------
        # Clim labels :
        self._mClimM = visuals.Text(parent=self._limNode,
                                    color=self._txtcolor,
                                    font_size=self._txtsz,
                                    name='Clim_M',
                                    anchor_x='left')
        self._mClimm = visuals.Text(parent=self._limNode,
                                    color=self._txtcolor,
                                    font_size=self._txtsz,
                                    name='Clim_m',
                                    anchor_x='left')

        # Cblabel :
        self._mcblabel = visuals.Text(parent=self._limNode,
                                      name='Cblabel',
                                      color=self._txtcolor,
                                      anchor_x='center',
                                      font_size=self._cbtxtsz)
        self._mcblabel.rotation = -90

        # Vmin/Vmax :
        self._vmMNode = Node(name='VminVmax', parent=self._limNode)
        self._mVm = visuals.Text(parent=self._vmMNode,
                                 color=self._txtcolor,
                                 font_size=self._ratio * self._txtsz,
                                 name='Vmin',
                                 anchor_x='left')
        self._mVM = visuals.Text(parent=self._vmMNode,
                                 color=self._txtcolor,
                                 font_size=self._ratio * self._txtsz,
                                 name='Vmax',
                                 anchor_x='left')

        # Build colorbar :
        self._build(True, 'all')
Ejemplo n.º 24
0
# test = get_rawReps()
######################################################### Draw #########################################################
# Make a canvas and add simple view (copied from https://github.com/vispy/vispy/issues/1257)

canvas = scene.SceneCanvas(keys='interactive', show=True, bgcolor='w')

view = canvas.central_widget.add_view()
view.camera = camera_view
view.camera.fov = 60
view.camera.center = [0, 0, 0]

#plot all reps
if plotReps:
    repsVis = visuals.Line(pos=finalReps['points'],
                           connect=finalReps['connections'],
                           parent=view.scene,
                           width=repetition_line_width,
                           color=finalReps['colors'])
#plot clusters
if plotClusters:
    clusterVis = visuals.Line(pos=clusters['points'],
                              connect=clusters['connections'],
                              parent=view.scene,
                              color=clusters['colors'],
                              width=clusters_line_width)

# cloud scatter
if plotCloud:
    scatter = visuals.Markers(parent=view.scene)
    scatter.antialias = 0
    scatter.set_data(pos=cloudPos,
Ejemplo n.º 25
0
    for y_value in range(-100, 100, 5):
        # 二维插值,求出水平侧影线
        y = np.linspace(y_value, y_value, 100)
        x = np.linspace(-80, 80, 100)
        # y = np.linspace(0, MAX_SIZE , N)
        # x = np.linspace(0, MAX_SIZE * np.cos(theta), N)
        # x = np.linspace(0, MAX_SIZE, N)
        xy = np.linspace(0, 100, 100)
        # print(MAX_SIZE)
        point_grid = np.column_stack((x, y))
        grid_z = griddata(data[:, 0:2], data[:, 2], point_grid, method='cubic')
        # print(grid_z)
        print(grid_z.shape)
        line = np.column_stack((point_grid, grid_z))
        # ax.plot(line[:, 0], line[:, 1], line[:, 2], c='r')
        Line = visuals.Line(color=(1, 0.5, 0.5, 1), width=1,
                 connect='strip', method='gl', antialias=False)
        Line.set_data(line, width = 5)


        # plt.title('point cloud')
        ax.plot(x, grid_z, c='r')
        ax.axis('off')
        ax.axis('scaled')



        # line = np.column_stack((line, grid_z))
        # print(line)
        ######
        # PointCloudVisualization(line)
        view.add(Line)
Ejemplo n.º 26
0
    def __init__(self, exp_df_path, trial_df_path, rig_leds_path):

        exp_df = pd.read_pickle(exp_df_path)
        trial_df = pd.read_pickle(trial_df_path)
        self.df = exp_df.join(trial_df.drop('block', axis=1),
                              on='trial_number')
        self.rig_leds = np.load(rig_leds_path)

        self.precalculate_data()

        verts, faces, normals, nothin = vispy.io.read_mesh(
            os.path.join(fh.PACKAGE_DIR, '../datafiles', 'head.obj'))
        verts = np.einsum('ni,ji->nj', (verts - verts.mean(axis=0)),
                          fh.from_yawpitchroll(180, 90, 0))
        #verts = verts - verts.mean(axis=0)

        # add SceneCanvas first to create QApplication object before widget
        self.vispy_canvas = vispy.scene.SceneCanvas(create_native=True,
                                                    vsync=True,
                                                    show=True,
                                                    bgcolor=(0.2, 0.2, 0.2, 0))

        super(ExperimentVisualization, self).__init__()

        #self.setAttribute(Qt.WA_TranslucentBackground)

        self.timer = vispy.app.Timer(1 / 30,
                                     start=False,
                                     connect=self.advance_frame)

        self.n_trials = len(self.df)
        self.current_trial = 0
        self.i_frame = 0
        self.current_row = self.df.iloc[self.current_trial]
        self.current_R_helmet = None
        self.current_gaze_normals = None
        self.current_ref_points = None

        self.vispy_view = self.vispy_canvas.central_widget.add_view()
        self.vispy_view.camera = 'turntable'
        self.vispy_view.camera.center = self.rig_leds[127, :] + (
            self.rig_leds[0, :] - self.rig_leds[127, :]) + (
                self.rig_leds[254, :] - self.rig_leds[127, :])
        self.vispy_view.camera.fov = 40
        self.vispy_view.camera.distance = 1500

        self.main_layout = QtWidgets.QVBoxLayout()
        self.setLayout(self.main_layout)

        self.frame_slider = QtWidgets.QSlider(Qt.Horizontal)
        self.frame_slider.setMinimum(0)
        self.frame_slider.valueChanged.connect(self.on_slider_change)

        self.trial_picker = QtWidgets.QSpinBox()
        self.trial_picker.setMaximum(self.n_trials)
        self.trial_picker.valueChanged.connect(self.on_picker_change)

        self.trial_changed.connect(self.load_trial)
        self.frame_changed.connect(self.load_frame)

        self.picker_slider_layout = QtWidgets.QHBoxLayout()

        self.main_layout.addWidget(self.vispy_canvas.native)
        self.main_layout.addLayout(self.picker_slider_layout)

        self.animation_button = QtWidgets.QPushButton('Start Animation')
        self.picker_slider_layout.addWidget(self.animation_button)
        self.animation_button.clicked.connect(self.toggle_animation)

        self.frame_label = QtWidgets.QLabel('Frame')
        self.picker_slider_layout.addWidget(self.frame_label)
        self.picker_slider_layout.addWidget(self.frame_slider)
        self.picker_slider_layout.addWidget(QtWidgets.QLabel('Trial'))
        self.picker_slider_layout.addWidget(self.trial_picker)

        self.rig_vis = visuals.Markers()
        self.rig_vis.set_gl_state(depth_test=False)
        self.rig_vis.antialias = 0
        self.vispy_view.add(self.rig_vis)

        self.helmet_vis = visuals.Markers()
        self.vispy_view.add(self.helmet_vis)

        self.gaze_vis = visuals.Line()
        self.vispy_view.add(self.gaze_vis)

        self.head_mesh = visuals.Mesh(vertices=verts,
                                      shading='smooth',
                                      faces=faces,
                                      mode='triangles',
                                      color=(0.5, 0.55, 0.7))
        self.head_mesh.shininess = 0
        self.head_mesh.light_dir = [0, 1, 1]
        # self.head_mesh.light_color = np.array((1, 1, 0.95)) * 0.8
        self.head_mesh.ambient_light_color = np.array((0.98, 0.98, 1)) * 0.2
        self.head_mesh.attach(Alpha(0.3))
        self.head_mesh.set_gl_state(depth_test=True, cull_face=True)
        self.head_mesh_transform = MatrixTransform()
        self.head_mesh.transform = self.head_mesh_transform
        self.vispy_view.add(self.head_mesh)

        self.trial_changed.emit(0)
        self.frame_changed.emit(0)

        self.show()
        vispy.app.run()
Ejemplo n.º 27
0
vb2 = grid.add_view(row=1, col=0)
vb3 = grid.add_view(row=1, col=1)

#
# Top viewbox: Show a plot line containing fine structure with a 1D
# magnification transform.
#

pos = np.empty((100000, 2))
pos[:, 0] = np.arange(100000)
pos[:, 1] = np.random.normal(size=100000, loc=50, scale=10)
pos[:, 1] = filter.gaussian_filter(pos[:, 1], 20)
pos[:, 1] += np.random.normal(size=100000, loc=0, scale=2)
pos[:, 1][pos[:, 1] > 55] += 100
pos[:, 1] = filter.gaussian_filter(pos[:, 1], 2)
line = visuals.Line(pos, color='white', parent=vb1.scene)
line.transform = STTransform(translate=(0, 0, -0.1))

grid1 = visuals.GridLines(parent=vb1.scene)

vb1.camera = Magnify1DCamera(mag=4, size_factor=0.6, radius_ratio=0.6)
vb1.camera.rect = 0, 30, 100000, 100

#
# Bottom-left viewbox: Image with circular magnification lens.
#
size = (100, 100)

img_data = np.random.normal(size=size + (3, ), loc=58,
                            scale=20).astype(np.ubyte)
image = visuals.Image(img_data, parent=vb2.scene, method='impostor')
Ejemplo n.º 28
0
    def __init__(self,
                 xyz=None,
                 channels=None,
                 system='cartesian',
                 unit='degree',
                 title=None,
                 title_color='black',
                 title_size=20.,
                 line_color='black',
                 line_width=4.,
                 chan_size=12.,
                 chan_offset=(0., 0., 0.),
                 chan_mark_color='white',
                 chan_mark_symbol='disc',
                 chan_txt_color='black',
                 bgcolor='white',
                 cbar=True,
                 cb_txt_size=10.,
                 margin=.05,
                 parent=None):
        """Init."""
        # ======================== VARIABLES ========================
        self._bgcolor = color2vb(bgcolor)
        scale = 800.  # fix GL bugs for small plots
        pos = np.zeros((1, 3), dtype=np.float32)
        # Colors :
        title_color = color2vb(title_color)
        line_color = color2vb(line_color)
        chan_txt_color = color2vb(chan_txt_color)
        self._chan_mark_color = color2vb(chan_mark_color)
        self._chan_mark_symbol = chan_mark_symbol
        # Disc interpolation :
        self._interp = .1
        self._pix = 64
        csize = int(self._pix / self._interp) if self._interp else self._pix
        l = csize / 2  # noqa

        # ======================== NODES ========================
        # Main topoplot node :
        self.node = scene.Node(name='Topoplot', parent=parent)
        self.node.transform = vist.STTransform(scale=[scale] * 3)
        # Headset + channels :
        self.node_headfull = scene.Node(name='HeadChan', parent=self.node)
        # Headset node :
        self.node_head = scene.Node(name='Headset', parent=self.node_headfull)
        # Channel node :
        self.node_chan = scene.Node(name='Channels', parent=self.node_headfull)
        self.node_chan.transform = vist.STTransform(translate=(0., 0., -10.))
        # Cbar node :
        self.node_cbar = scene.Node(name='Channels', parent=self.node)
        # Dictionaries :
        kw_line = {
            'width': line_width,
            'color': line_color,
            'parent': self.node_head
        }

        # ======================== PARENT VISUALS ========================
        # Main disc :
        self.disc = visuals.Image(pos=pos,
                                  name='Disc',
                                  parent=self.node_head,
                                  interpolation='bilinear')
        # Title :
        self.title = visuals.Text(text=title,
                                  pos=(0., .6, 0.),
                                  name='Title',
                                  parent=self.node,
                                  font_size=title_size,
                                  color=title_color,
                                  bold=True)
        self.title.font_size *= 1.1

        # ======================== HEAD / NOSE / EAR ========================
        # ------------------ HEAD ------------------
        # Head visual :
        self.head = visuals.Line(pos=pos, name='Head', **kw_line)
        # Head circle :
        theta = np.arange(0, 2 * np.pi, 0.001)
        head = np.full((len(theta), 3), -1., dtype=np.float32)
        head[:, 0] = l * (1. + np.cos(theta))
        head[:, 1] = l * (1. + np.sin(theta))
        self.head.set_data(pos=head)

        # ------------------ NOSE ------------------
        # Nose visual :
        self.nose = visuals.Line(pos=pos, name='Nose', **kw_line)
        # Nose data :
        wn, hn = csize * 50. / 512., csize * 30. / 512.
        nose = np.array([[l - wn, 2 * l - wn, 2.], [l, 2 * l + hn, 2.],
                         [l, 2 * l + hn, 2.], [l + wn, 2 * l - wn, 2.]])
        self.nose.set_data(pos=nose, connect='segments')

        # ------------------ EAR ------------------
        we, he = csize * 10. / 512., csize * 30. / 512.
        ye = l + he * np.sin(theta)
        # Ear left data :
        self.earL = visuals.Line(pos=pos, name='EarLeft', **kw_line)
        # Ear left visual :
        ear_l = np.full((len(theta), 3), 3., dtype=np.float32)
        ear_l[:, 0] = 2 * l + we * np.cos(theta)
        ear_l[:, 1] = ye
        self.earL.set_data(pos=ear_l)

        # Ear right visual :
        self.earR = visuals.Line(pos=pos, name='EarRight', **kw_line)
        # Ear right data :
        ear_r = np.full((len(theta), 3), 3., dtype=np.float32)
        ear_r[:, 0] = 0. + we * np.cos(theta)
        ear_r[:, 1] = ye
        self.earR.set_data(pos=ear_r)

        # ================== CHANNELS ==================
        # Channel's markers :
        self.chanMarkers = visuals.Markers(pos=pos,
                                           name='ChanMarkers',
                                           parent=self.node_chan)
        # Channel's text :
        self.chanText = visuals.Text(pos=pos,
                                     name='ChanText',
                                     parent=self.node_chan,
                                     anchor_x='center',
                                     color=chan_txt_color,
                                     font_size=chan_size)

        # ================== CAMERA ==================
        self.rect = ((-scale / 2) * (1 + margin), (-scale / 2) * (1 + margin),
                     scale * (1. + cbar * .3 + margin),
                     scale * (1.11 + margin))

        # ================== CBAR ==================
        if cbar:
            self.cbar = CbarVisual(cbtxtsz=1.2 * cb_txt_size,
                                   txtsz=cb_txt_size,
                                   txtcolor=title_color,
                                   cbtxtsh=2.,
                                   parent=self.node_cbar)
            self.node_cbar.transform = vist.STTransform(scale=(.6, .4, 1.),
                                                        translate=(.6, 0., 0.))

        # ================== COORDINATES ==================
        auto = self._get_channel_coordinates(xyz, channels, system, unit)
        if auto:
            eucl = np.sqrt(self._xyz[:, 0]**2 + self._xyz[:, 1]**2).max()
            self.node_head.transform = vpnormalize(head, dist=2 * eucl)
            # Rescale between (-1:1, -1:1) = circle :
            circle = vist.STTransform(scale=(.5 / eucl, .5 / eucl, 1.))
            self.node_headfull.transform = circle
            # Text translation :
            tr = np.array([0., .8, 0.]) + np.array(chan_offset)
        else:
            # Get coordinates of references along the x and y-axis :
            ref_x, ref_y = self._get_ref_coordinates()
            # Recenter the topoplot :
            t = vist.ChainTransform()
            t.prepend(vprecenter(head))
            # Rescale (-ref_x:ref_x, -ref_y:ref_y) (ref_x != ref_y => ellipse)
            coef_x = 2 * ref_x / head[:, 0].max()
            coef_y = 2 * ref_y / head[:, 1].max()
            t.prepend(vist.STTransform(scale=(coef_x, coef_y, 1.)))
            self.node_head.transform = t
            # Rescale between (-1:1, -1:1) = circle :
            circle = vist.STTransform(scale=(.5 / ref_x, .5 / ref_y, 1.))
            self.node_headfull.transform = circle
            # Text translation :
            tr = np.array([0., .04, 0.]) + np.array(chan_offset)
        self.chanText.transform = vist.STTransform(translate=tr)

        # ================== GRID INTERPOLATION ==================
        # Interpolation vectors :
        x = y = np.arange(0, self._pix, 1)
        xnew = ynew = np.arange(0, self._pix, self._interp)

        # Grid interpolation function :
        def _grid_interpolation(grid):
            f = interp2d(x, y, grid, kind='linear')
            return f(xnew, ynew)

        self._grid_interpolation = _grid_interpolation
Ejemplo n.º 29
0
def gen_skeleton(blob3d):
    #------------------------------------------------
    # NOTE OUTDATED, keeping only for reference
    #------------------------------------------------

    # Begin by creating a 3d array, with each element either None or the id of the pixel
    # Then create a second 3d array, with the distances from each internal point to the closest edge point
    # Find internals by doing all pixels - edge_pixels

    print("CALLED GEN_SKELETON!!!!")

    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d import Axes3D
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')

    xdim = blob3d.maxx - blob3d.minx + 1
    ydim = blob3d.maxy - blob3d.miny + 1
    zdim = blob3d.highslideheight - blob3d.lowslideheight + 1
    minx = blob3d.minx
    miny = blob3d.miny
    minz = blob3d.lowslideheight

    def pixel_to_pos(pixel):
        # Returns the (x,y,z) location of the pixel in any one of the 3d arrays
        return (pixel.x - minx, pixel.y - miny, pixel.z - minz)

    def distance_from_offset(x_offset, y_offset, z_offset):
        return math.sqrt(
            math.pow(x_offset, 2) + math.pow(y_offset, 2) +
            math.pow(z_offset, 2))

    def inBounds(x, y, z):
        if x >= 0 and y >= 0 and z >= 0 and x < xdim and y < ydim and z < zdim:
            return True
        return False

    def find_nearest_neighbor(x, y, z, arr, recur=1):
        """

        :param x: X coordinate within given arr
        :param y: Y coordinate within given arr
        :param z: Z coordinate within given arr
        :param arr: An array populated by the ids of pixels
        :param recur: How far outwards to extend the 'search cube'
        :return: (x_coor, y_coor, z_coor, distance, pixel_id)
        """
        # print("Finding nearest neighbor of: " + str((x, y, z, recur)))

        possible_coordinates = []  # Contains coordinate tuples (x,y,z)
        # Because am using cube instead of spheres, need to remember all matches and then find the best

        # arr should

        # TODO restrict the ranges so that they don't overlap

        # X restricts Y and Z
        # Y restricts Z
        # Z restricts nothing

        for x_offset in [-recur, recur]:
            curx = x + x_offset
            for y_offset in range(-recur, recur + 1):  # +1 to include endcap
                cury = y + y_offset
                for z_offset in range(-recur,
                                      recur + 1):  # +1 to include endcap
                    curz = z + z_offset

                    if inBounds(curx, cury,
                                curz) and not np.isnan(arr[curx][cury][curz]):
                        possible_coordinates.append(
                            (curx, cury, curz,
                             distance_from_offset(x_offset, y_offset,
                                                  z_offset),
                             int(arr[curx][cury][curz])))
                        # x, y, z, distance, pixel_id

        # print("Coordinates found: " + str(possible_coordinates))

        if len(possible_coordinates) == 0:
            # print("----Making a recursive call!")
            return find_nearest_neighbor(x, y, z, arr, recur + 1)

        # TODO Y and Z

        else:
            # Find the closest coordinate
            possible_coordinates.sort(
                key=lambda x_y_z_dist_id: x_y_z_dist_id[3])  # Sort by distance
            # print("SORTED POSSIBLE COORDINATES: " + str(possible_coordinates))
            return possible_coordinates[0]

    # TODO have an option to create a shell around the blob3d, by taking the highest and lowest levels, and making them all count temporarily as
    # edge pixels. This way, the effects of segmentation will be less dependent on the scan direction

    edge_pixels = blob3d.get_edge_pixels()  # Actual pixels not ids
    all_pixels = blob3d.get_pixels()
    inner_pixels = [
        Pixel.get(cur_pixel)
        for cur_pixel in (set(pixel.id for pixel in all_pixels) -
                          set(pixel.id for pixel in edge_pixels))
    ]

    edge_array = np.empty((xdim, ydim, zdim))  # , dtype=np.int)
    inner_array = np.empty((xdim, ydim, zdim))  # , dtype=np.int)
    distances = np.empty((xdim, ydim, zdim), dtype=np.float)
    edge_array[:] = np.nan
    inner_array[:] = np.nan
    distances[:] = np.nan

    for pixel in edge_pixels:
        x, y, z = pixel_to_pos(pixel)
        edge_array[x][y][z] = pixel.id

    for pixel in inner_pixels:
        x, y, z = pixel_to_pos(pixel)
        inner_array[x][y][z] = pixel.id

    inner_pos = np.zeros([len(inner_pixels), 3])
    near_pos = np.zeros([len(inner_pixels), 3])
    line_endpoints = np.zeros([2 * len(inner_pixels), 3])

    index_distance_id = np.zeros([len(inner_pixels), 3])

    maxdim = max([xdim, ydim, zdim])  # Adjusting z visualization

    pixel_nid_nx_ny_nz_dist = []
    marker_colors = np.zeros((len(inner_pixels), 4))
    mycolors = [
        'r', 'orange', 'yellow', 'white', 'lime', 'g', 'teal', 'blue',
        'purple', 'pink'
    ]

    # HACK
    import vispy
    myrgba = list(
        vispy.color.ColorArray(color_str).rgba for color_str in mycolors)

    for index, pixel in enumerate(inner_pixels):
        # print("Pixel: " + str(pixel))
        x, y, z = pixel_to_pos(pixel)
        inner_pos[index] = x / xdim, y / ydim, z / zdim
        x_y_z_dist_id = find_nearest_neighbor(x, y, z, edge_array)

        pixel_nid_nx_ny_nz_dist.append(
            (pixel, x_y_z_dist_id[4], x_y_z_dist_id[0], x_y_z_dist_id[1],
             x_y_z_dist_id[2], x_y_z_dist_id[3]))

        near_pos[index] = (x_y_z_dist_id[0] / xdim, x_y_z_dist_id[1] / ydim,
                           x_y_z_dist_id[2] / zdim)
        marker_colors[index] = myrgba[int(x_y_z_dist_id[3]) % len(myrgba)]

        line_endpoints[2 * index] = (x_y_z_dist_id[0] / xdim,
                                     x_y_z_dist_id[1] / ydim,
                                     x_y_z_dist_id[2] / zdim)
        line_endpoints[2 * index + 1] = (x / xdim, y / ydim, z / zdim)
        # index_distance_id[index] = [index, x_y_z_dist_id[3], x_y_z_dist_id[4]]

    # Sort distances; need to maintain index for accessing id later
    pixel_nid_nx_ny_nz_dist = sorted(pixel_nid_nx_ny_nz_dist,
                                     key=lambda entry: entry[5],
                                     reverse=True)

    # TODO find ridge
    # Strategy: Iterative, use either the highest n or x percent to find cutoff..?
    ridge = [pixel_nid_nx_ny_nz_dist[0]]
    ridge_ends = [pixel_nid_nx_ny_nz_dist[0]
                  ]  # Preferable to keep at 2 if we can

    # HACK TODO
    for i in pixel_nid_nx_ny_nz_dist:
        print(' ' + str(i))
    # min_threshold = int(pixel_nid_nx_ny_nz_dist[int(.1 * len(pixel_nid_nx_ny_nz_dist))])

    # pixel_costs = dict()
    # for pnnnnd in pixel_nid_nx_ny_nz_dist:
    #     pixel_costs[pnnnnd[0].id] = pnnnnd[5] # Mapping inner pixel's id to its distance (to the closest edge_pixel)
    #
    #
    #
    #
    #
    # n, bins, patches = plt.hist([idi[5] for idi in pixel_nid_nx_ny_nz_dist], bins=np.linspace(0,10,50))
    # # hist = np.histogram( [idi[4] for idi in pixel_nid_nx_ny_nz_dist] , bins=np.arange(10))
    # plt.show()

    import vispy.io
    import vispy.scene
    from vispy.scene import visuals
    from vispy.util import keys

    canvas = vispy.scene.SceneCanvas(size=(1200, 1200),
                                     keys='interactive',
                                     show=True)
    view = canvas.central_widget.add_view()
    view.camera = vispy.scene.cameras.FlyCamera(parent=view.scene,
                                                fov=30,
                                                name='Fly')
    # view.camera = vispy.scene.cameras.TurntableCamera(fov=0, azimuth=80, parent=view.scene, distance=1,
    #                                                   elevation=-55, name='Turntable')
    # view.camera = vispy.scene.cameras.ArcballCamera(parent=view.scene, fov=50, distance=1,
    #                                                    name='Arcball')
    inner_markers = visuals.Markers()
    near_markers = visuals.Markers()
    lines = visuals.Line(method=Config.linemethod)
    lines.set_data(pos=line_endpoints, connect='segments', color='y')

    inner_markers.set_data(inner_pos, face_color=marker_colors, size=10)
    near_markers.set_data(near_pos, face_color='g', size=10)
    print("Inner pos: " + str(inner_pos))
    print("Near pos: " + str(near_pos))

    view.add(inner_markers)
    view.add(near_markers)
    view.add(lines)
    vispy.app.run()

    print('------------')
Ejemplo n.º 30
0
# indexes = np.random.normal(size=100000, loc=centers.shape[0]/2.,
#                            scale=centers.shape[0]/3.)
# indexes = np.clip(indexes, 0, centers.shape[0]-1).astype(int)
# scales = 10**(np.linspace(-2, 0.5, centers.shape[0]))[indexes][:, np.newaxis]
# pos *= scales
# pos += centers[indexes]

# create scatter object and fill in the data
scatter = visuals.Markers()
scatter.set_data(pos, edge_color=None, face_color=(1, 1, 1, .5), size=5)
scatter2 = visuals.Markers()
scatter2.set_data(pos2, edge_color=None, face_color=(1, 0, 1, .5), size=5)

line = visuals.Line(pos=np.array([[2, 4, 5], [3, 7, 1], [0, 0, 0], [2, 2, 2],
                                  [2, 0, 0], [4, 2, 2]]),
                    connect='segments',
                    color=(1, 1, 0, 1),
                    method='gl')

view.add(scatter)
view.add(scatter2)
view.add(line)

view.camera = 'turntable'  # or try 'arcball'

# add a colored 3D axis for orientation
axis = visuals.XYZAxis(parent=view.scene)

if __name__ == '__main__':
    print('banana')
    vispy.app.run()