def __init__(self, radius, length, rows=16, cols=16, vertex_colors=None, face_colors=None, color=(0.5, 0.5, 1, 1), edge_color=None, **kwargs): mesh_data = create_cylinder(rows, cols, radius, length, offset=False) self._mesh = MeshVisual( mesh_data.get_vertices() + np.array([0, 0, -length * 0.5]), mesh_data.get_faces(), vertex_colors, face_colors, color) if edge_color: self._border = MeshVisual(mesh_data.get_vertices() + np.array([0, 0, -length * 0.5]), mesh_data.get_faces(), color=edge_color, mode='lines') else: self._border = MeshVisual() CompoundVisual.__init__(self, [self._mesh, self._border], **kwargs) self.mesh.set_gl_state(polygon_offset_fill=True, polygon_offset=(1, 1), depth_test=True)
def __init__(self, cue_file, edge_color=None, **kwargs): # super(CueVisual, self).__init__() EventEmitter.__init__(self) (vertices, faces, vertex_colors, _) = read_mesh(cue_file) vertex_colors = rgb2gray(vertex_colors) self._name = None self._mesh = scene.visuals.Mesh(vertices, faces, vertex_colors, shading=None) #color='gray' self._border = scene.visuals.Mesh() self._origin = np.array([0, 0, 0]) self._center = np.array([0, 0, 0]) self._xy_center = np.array([0, 0, 0]) self._pos = np.array([0, 0, 0]) self._z = 0 self._z_floor = 0 self._transform = None self._scale_factor = 1 self._vib_flag = False CompoundVisual.__init__(self, [self._mesh, self._border], **kwargs) self.mesh.set_gl_state(polygon_offset_fill=True, polygon_offset=(1, 1), depth_test=True)
def __init__(self, fx, fy, u0, v0, length=1, nW=0, nH=0, rot=0, trans=0, image=0): self.fx = fx self.fy = fy self.u0 = u0 self.v0 = v0 self.length = length self.nW = nW self.nH = nH self.rot = rot self.trans = trans self.image = image self.lines = vispy.visuals.LineVisual() self.lines2 = vispy.visuals.LineVisual() front_vertices = self.set_data(fx, fy, u0, v0, length, nW, nH, rot, trans) if (isinstance(image, np.ndarray)): self.image_visual = ImageVisual3D() self.image_visual.set_data(front_vertices, image) CompoundVisual.__init__(self, [self.lines, self.image_visual]) else: CompoundVisual.__init__(self, [self.lines, self.lines2])
def __init__(self, vertices=None, simplices=None, vertex_colors=None, edge_color=None, edge_width=1, markers=None, marker_colors=None, marker_size=1, **kwargs): """ a mesh visualization toolkit that can also plot edges or markers Parameters ---------- Notes ----- """ self._mesh = MeshVisual() self._edge = LineVisual() self._edge_color = Color(edge_color) self._marker = MarkersVisual() # self._vertex_colors = vertex_colors self._update() # initialize visuals CompoundVisual.__init__(self, [self._mesh, self._edge, self._marker], **kwargs) # set default state, 'opaque', 'translucent' or 'additive' self._mesh.set_gl_state( preset="translucent", blend=True, depth_test=False, cull_face=False, polygon_offset_fill=True, polygon_offset=(1, 1), ) # end self.freeze() def _update(self): """ update parameters to visuals """ raise NotImplementedError() @property def edge_color(self): """ get """ return self._edge_color @edge_color.setter def edge_color(self, edge_color): """ set """ self._edge_color = Color(edge_color) self._update()
def __init__(self, line_width=1, triangulation='gpc', layers=3, pool=None, **kwargs): """ Represents collection of shapes to draw on VisPy scene :param line_width: float Width of lines/edges :param triangulation: str Triangulation method used for polygons translation 'vispy' - VisPy lib triangulation 'gpc' - Polygon2 lib :param layers: int Layers count Each layer adds 2 visuals on VisPy scene. Be careful: more layers cause less fps :param kwargs: """ self.data = {} self.last_key = -1 # Thread locks self.key_lock = threading.Lock() self.results_lock = threading.Lock() self.update_lock = threading.Lock() # Process pool self.pool = pool self.results = {} self._meshes = [MeshVisual() for _ in range(0, layers)] self._lines = [LineVisual(antialias=True) for _ in range(0, layers)] self._line_width = line_width self._triangulation = triangulation visuals_ = [ self._lines[i / 2] if i % 2 else self._meshes[i / 2] for i in range(0, layers * 2) ] CompoundVisual.__init__(self, visuals_, **kwargs) for m in self._meshes: pass m.set_gl_state(polygon_offset_fill=True, polygon_offset=(1, 1), cull_face=False) for l in self._lines: pass l.set_gl_state(blend=True) self.freeze()
def __init__(self, vertices=None, simplices=None, vertex_colors=None, edge_color=None, edge_width=1, markers=None, marker_colors=None, marker_size=1, **kwargs): """ a mesh visualization toolkit that can also plot edges or markers Parameters ---------- Notes ----- """ self._mesh = MeshVisual() self._edge = LineVisual() self._edge_color = Color(edge_color) self._marker = MarkersVisual() # self._vertex_colors = vertex_colors self._update() # initialize visuals CompoundVisual.__init__(self, [self._mesh, self._edge, self._marker], **kwargs) # set default state, 'opaque', 'translucent' or 'additive' self._mesh.set_gl_state(preset='translucent', blend=True, depth_test=False, cull_face=False, polygon_offset_fill=True, polygon_offset=(1, 1)) # end self.freeze() def _update(self): """ update parameters to visuals """ pass @property def edge_color(self): """ get """ return self._edge_color @edge_color.setter def edge_color(self, edge_color): """ set """ self._edge_color = Color(edge_color) self._update()
def __init__(self, pos=None, domain=(0., 1.), tick_direction=(-1., 0.), scale_type="linear", axis_color=(1, 1, 1), tick_color=(0.7, 0.7, 0.7), text_color='w', minor_tick_length=5, major_tick_length=10, tick_width=2, tick_label_margin=5, tick_font_size=8, axis_width=3, axis_label=None, axis_label_margin=35, axis_font_size=10, font_size=None, anchors=None): if scale_type not in ('linear', 'logarithmic'): raise NotImplementedError('only linear scaling is currently ' 'supported') if font_size is not None: tick_font_size = font_size axis_font_size = font_size self._pos = None self._domain = None # If True, then axis stops at the first / last major tick. # If False, then axis extends to edge of *pos* # (private until we come up with a better name for this) self._stop_at_major = (False, False) self.ticker = ExtTicker(self, anchors=anchors) self.tick_direction = np.array(tick_direction, float) self.tick_direction = self.tick_direction self.scale_type = scale_type self.axis_color = axis_color self.tick_color = tick_color self.minor_tick_length = minor_tick_length # px self.major_tick_length = major_tick_length # px self.tick_label_margin = tick_label_margin # px self.axis_label_margin = axis_label_margin # px self.axis_label = axis_label self._need_update = True self._line = LineVisual(method='gl', width=axis_width) self._ticks = LineVisual(method='gl', width=tick_width, connect='segments') self._text = TextVisual(font_size=tick_font_size, color=text_color) self._axis_label = TextVisual(font_size=axis_font_size, color=text_color) CompoundVisual.__init__(self, [self._line, self._text, self._ticks, self._axis_label]) if pos is not None: self.pos = pos self.domain = domain
def __init__(self, radius=1.0, directions=None, colors=None): # Convert spherical to cartesian points = np.array([util.tp2xyz(*x) for x in directions]) # Create mesh import scipy.spatial ch = scipy.spatial.ConvexHull(points) mesh = MeshData(vertices=ch.points, faces=ch.simplices) self._mesh = MeshVisual(vertices=mesh.get_vertices(), faces=mesh.get_faces(), vertex_colors=colors) CompoundVisual.__init__(self, [self._mesh]) self.mesh.set_gl_state(depth_test=True)
def __init__(self, line_width=1, triangulation="gpc", layers=3, pool=None, **kwargs): """ Represents collection of shapes to draw on VisPy scene :param line_width: float Width of lines/edges :param triangulation: str Triangulation method used for polygons translation 'vispy' - VisPy lib triangulation 'gpc' - Polygon2 lib :param layers: int Layers count Each layer adds 2 visuals on VisPy scene. Be careful: more layers cause less fps :param kwargs: """ self.data = {} self.last_key = -1 # Thread locks self.key_lock = threading.Lock() self.results_lock = threading.Lock() self.update_lock = threading.Lock() # Process pool self.pool = pool self.results = {} self._meshes = [MeshVisual() for _ in range(0, layers)] self._lines = [LineVisual(antialias=True) for _ in range(0, layers)] self._line_width = line_width self._triangulation = triangulation visuals_ = [self._lines[i / 2] if i % 2 else self._meshes[i / 2] for i in range(0, layers * 2)] CompoundVisual.__init__(self, visuals_, **kwargs) for m in self._meshes: pass m.set_gl_state(polygon_offset_fill=True, polygon_offset=(1, 1), cull_face=False) for l in self._lines: pass l.set_gl_state(blend=True) self.freeze()
def __init__(self, maze_file, maze_coord_file=None, edge_color=None, **kwargs): (vertices, faces, vertex_colors, _) = read_mesh(maze_file) vertex_colors = rgb2gray(vertex_colors) self._mesh = scene.visuals.Mesh(vertices, faces, vertex_colors, shading=None) #color='gray' self._border = scene.visuals.Mesh() self._coord = load_maze_coord(maze_coord_file) CompoundVisual.__init__(self, [self._mesh, self._border], **kwargs) self.mesh.set_gl_state(polygon_offset_fill=True, polygon_offset=(1, 1), depth_test=True)
def __init__(self, colorup="#00ff00ff", colordown="#ff0000ff", log: bool = False, align="m", padding=.05, borderwidth: float = .5, antialias=False): """ Args: colorup: the color of the lines where close >= open colordown:the color of the lines where close < open antialias: log: y log scale padding: bar padding-left and padding-right, % borderwidth: border width align: 'r','l','m' """ assert align in ['r', 'l', 'm'] self._line_visual = _GLLine2Visual(self) self._changed = { 'pos': False, } self._pos = None self._color = None self._border_width = borderwidth self._bounds = None self._antialias = antialias self._log = log self._data = None self._colorup = Color(colorup).rgba self._colordown = Color(colordown).rgba self._align = align self._padding = padding CompoundVisual.__init__(self, [ self._line_visual, ])
def __init__(self, radius=1.0, cols=30, rows=30, depth=30, subdivisions=3, method='latitude', vertex_colors=None, face_colors=None, color=(0.5, 0.5, 1, 1), edge_color=None, **kwargs): EventEmitter.__init__(self) self._origin = np.array([0, 0, 0]) self._pos = np.array([0, 0, 0]) self._scale_factor = scale mesh = create_sphere(cols, rows, depth, radius=radius, subdivisions=subdivisions, method=method) self._mesh = MeshVisual(vertices=mesh.get_vertices(), faces=mesh.get_faces(), vertex_colors=vertex_colors, face_colors=face_colors, color=color) if edge_color: self._border = MeshVisual(vertices=mesh.get_vertices(), faces=mesh.get_edges(), color=edge_color, mode='lines') else: self._border = MeshVisual() CompoundVisual.__init__(self, [self._mesh, self._border], **kwargs) self.mesh.set_gl_state(polygon_offset_fill=True, polygon_offset=(1, 1), depth_test=True)
def __init__(self, pos, color="black", labels=None): self.pos = np.zeros((pos.shape[0] * 2, 3)) for i in range(pos.shape[0]): self.pos[2 * i + 1] = pos[i] self._lines = LineVisual(pos=self.pos, method="gl", color=color, connect="segments", antialias=True) self._text = TextVisual(text=labels, color=color, bold=True, italic=True, pos=pos * 1.1, font_size=14, method="gpu") CompoundVisual.__init__(self, [self._lines, self._text])
def __init__(self, origin=[0, 0, 0], length=1): verts = origin + np.array([[0, 0, 0], [length, 0, 0], [0, 0, 0], [0, length, 0], [0, 0, 0], [0, 0, length]]) line = LineVisual(pos=verts, color=np.array([0, 0, 0, 1]), connect='segments', method='gl') x = TextVisual('x', font_size=12, pos=origin + np.array([1.25 * length, 0, 0])) y = TextVisual('y', font_size=12, pos=origin + np.array([0, 1.25 * length, 0])) z = TextVisual('z', font_size=12, pos=origin + np.array([0, 0, 1.25 * length])) CompoundVisual.__init__(self, [line, x, y, z])