本文整理汇总了Python中vispy.gloo.IndexBuffer方法的典型用法代码示例。如果您正苦于以下问题:Python gloo.IndexBuffer方法的具体用法?Python gloo.IndexBuffer怎么用?Python gloo.IndexBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vispy.gloo
的用法示例。
在下文中一共展示了gloo.IndexBuffer方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from vispy import gloo [as 别名]
# 或者: from vispy.gloo import IndexBuffer [as 别名]
def __init__(self, vertices, faces, size, K, R, t, clip_near, clip_far,
bg_color=(0.0, 0.0, 0.0, 0.0), ambient_weight=0.1,
render_rgb=True, render_depth=True):
"""
mode is from ['rgb', 'depth', 'rgb+depth']
"""
app.Canvas.__init__(self, show=False, size=size)
#gloo.gl.use_gl('gl2 debug')
self.size = size
self.shape = (self.size[1], self.size[0])
self.bg_color = bg_color
self.ambient_weight = ambient_weight
self.render_rgb = render_rgb
self.render_depth = render_depth
self.rgb = np.array([])
self.depth = np.array([])
# Model matrix
self.mat_model = np.eye(4, dtype=np.float32) # From object space to world space
# View matrix (transforming also the coordinate system from OpenCV to
# OpenGL camera space)
self.mat_view = np.eye(4, dtype=np.float32) # From world space to eye space
self.mat_view[:3, :3], self.mat_view[:3, 3] = R, t.squeeze()
yz_flip = np.eye(4, dtype=np.float32)
yz_flip[1, 1], yz_flip[2, 2] = -1, -1
self.mat_view = yz_flip.dot(self.mat_view) # OpenCV to OpenGL camera system
self.mat_view = self.mat_view.T # OpenGL expects column-wise matrix format
# Projection matrix
self.mat_proj = _compute_calib_proj(K, 0, 0, size[0], size[1], clip_near, clip_far)
# Create buffers
self.vertex_buffer = gloo.VertexBuffer(vertices)
self.index_buffer = gloo.IndexBuffer(faces.flatten().astype(np.uint32))
# We manually draw the hidden canvas
self.update()
示例2: _compute_bbox
# 需要导入模块: from vispy import gloo [as 别名]
# 或者: from vispy.gloo import IndexBuffer [as 别名]
def _compute_bbox(self):
self.bb = []
minx, maxx = min(self.vertices[:, 0]), max(self.vertices[:, 0])
miny, maxy = min(self.vertices[:, 1]), max(self.vertices[:, 1])
minz, maxz = min(self.vertices[:, 2]), max(self.vertices[:, 2])
self.bb.append([minx, miny, minz])
self.bb.append([minx, maxy, minz])
self.bb.append([minx, miny, maxz])
self.bb.append([minx, maxy, maxz])
self.bb.append([maxx, miny, minz])
self.bb.append([maxx, maxy, minz])
self.bb.append([maxx, miny, maxz])
self.bb.append([maxx, maxy, maxz])
self.bb = np.asarray(self.bb, dtype=np.float32)
self.diameter = max(pdist(self.bb, 'euclidean'))
# Set up rendering data
colors = [[1, 0, 0],[1, 1, 0], [0, 1, 0], [0, 1, 1],
[0, 0, 1], [0, 1, 0], [0.5, 0, 0.5], [0, 0.5, 0.5]]
indices = [0, 1, 0, 2, 3, 1, 3, 2,
4, 5, 4, 6, 7, 5, 7, 6,
0, 4, 1, 5, 2, 6, 3, 7]
vertices_type = [('a_position', np.float32, 3), ('a_color', np.float32, 3)]
collated = np.asarray(list(zip(self.bb, colors)), vertices_type)
self.bb_vbuffer = gloo.VertexBuffer(collated)
self.bb_ibuffer = gloo.IndexBuffer(indices)
示例3: initialize_renderer
# 需要导入模块: from vispy import gloo [as 别名]
# 或者: from vispy.gloo import IndexBuffer [as 别名]
def initialize_renderer(self):
self.fbuffer = FrameBuffer()
vertices = np.array([[-1.0, -1.0],
[+1.0, -1.0],
[-1.0, +1.0],
[+1.0, +1.0]],
np.float32)
texcoords = np.array([[0.0, 0.0],
[1.0, 0.0],
[0.0, 1.0],
[1.0, 1.0]],
dtype=np.float32)
self.fbuf_vertices = VertexBuffer(data=vertices)
self.fbuf_texcoords = VertexBuffer(data=texcoords)
self.fbuffer_prog = Program(src_fbuffer.vert, src_fbuffer.frag)
self.fbuffer_prog['texcoord'] = self.fbuf_texcoords
self.fbuffer_prog['position'] = self.fbuf_vertices
self.vertex_buffer = VertexBuffer()
self.index_buffer = IndexBuffer()
self.default_prog = Program(src_default.vert, src_default.frag)
self.texture_prog = Program(src_texture.vert, src_texture.frag)
self.texture_prog['texcoord'] = self.fbuf_texcoords
self.reset_view()
示例4: initialize_renderer
# 需要导入模块: from vispy import gloo [as 别名]
# 或者: from vispy.gloo import IndexBuffer [as 别名]
def initialize_renderer(self):
self.fbuffer = FrameBuffer()
vertices = np.array([[-1.0, -1.0],
[+1.0, -1.0],
[-1.0, +1.0],
[+1.0, +1.0]],
np.float32)
texcoords = np.array([[0.0, 0.0],
[1.0, 0.0],
[0.0, 1.0],
[1.0, 1.0]],
dtype=np.float32)
self.fbuf_vertices = VertexBuffer(data=vertices)
self.fbuf_texcoords = VertexBuffer(data=texcoords)
self.fbuffer_prog = Program(src_fbuffer.vert, src_fbuffer.frag)
self.fbuffer_prog['texcoord'] = self.fbuf_texcoords
self.fbuffer_prog['position'] = self.fbuf_vertices
self.vertex_buffer = VertexBuffer()
self.index_buffer = IndexBuffer()
self.default_prog = Program(src_default.vert, src_default.frag)
self.reset_view()
示例5: __init__
# 需要导入模块: from vispy import gloo [as 别名]
# 或者: from vispy.gloo import IndexBuffer [as 别名]
def __init__(self, size, cam):
app.Canvas.__init__(self, show=False, size=size)
self.shape = (size[1], size[0])
self.yz_flip = np.eye(4, dtype=np.float32)
self.yz_flip[1, 1], self.yz_flip[2, 2] = -1, -1
self.set_cam(cam)
# Set up shader programs
self.program_col = gloo.Program(_vertex_code_colored, _fragment_code_colored)
self.program_bbox = gloo.Program(_vertex_code_colored, _fragment_code_bbox)
self.program_tex = gloo.Program(_vertex_code_textured, _fragment_code_textured)
self.program_bg = gloo.Program(_vertex_code_background, _fragment_code_background)
# Texture where we render the color/depth and its FBO
self.col_tex = gloo.Texture2D(shape=self.shape + (3,))
self.fbo = gloo.FrameBuffer(self.col_tex, gloo.RenderBuffer(self.shape))
self.fbo.activate()
gloo.set_state(depth_test=True, blend=False, cull_face=True)
gl.glEnable(gl.GL_LINE_SMOOTH)
gloo.set_clear_color((0.0, 0.0, 0.0))
gloo.set_viewport(0, 0, *self.size)
# Set up background render quad in NDC
quad = [[-1, -1], [1, -1], [1, 1], [-1, 1]]
tex = [[0, 1], [1, 1], [1, 0], [0, 0]]
vertices_type = [('a_position', np.float32, 2), ('a_texcoord', np.float32, 2)]
collated = np.asarray(list(zip(quad, tex)), vertices_type)
self.bg_vbuffer = gloo.VertexBuffer(collated)
self.bg_ibuffer = gloo.IndexBuffer([0, 1, 2, 0, 2, 3])
示例6: _set_bbox_buffer
# 需要导入模块: from vispy import gloo [as 别名]
# 或者: from vispy.gloo import IndexBuffer [as 别名]
def _set_bbox_buffer(self, colors):
indices = [0, 1, 0, 2, 3, 1, 3, 2,
4, 5, 4, 6, 7, 5, 7, 6,
0, 4, 1, 5, 2, 6, 3, 7]
vertices_type = [('a_position', np.float32, 3), ('a_color', np.float32, 3)]
collated = np.asarray(list(zip(self.bb, colors)), vertices_type)
self.bb_vbuffer = gloo.VertexBuffer(collated)
self.bb_ibuffer = gloo.IndexBuffer(indices)
示例7: _setup_coordinate_system
# 需要导入模块: from vispy import gloo [as 别名]
# 或者: from vispy.gloo import IndexBuffer [as 别名]
def _setup_coordinate_system(self):
self.cs = [[0, 0, 0], [self.diameter * 0.4, 0, 0], [0, 0, 0], [0, self.diameter * 0.45, 0], [0, 0, 0],
[0, 0, self.diameter * 0.4]]
colors = [[0.8, 0, 0], [0.8, 0, 0], [0, 0.8, 0], [0, 0.8, 0], [0, 0, 0.8], [0, 0, 0.8]]
indices = [0, 1, 2, 3, 4, 5]
vertices_type = [('a_position', np.float32, 3), ('a_color', np.float32, 3)]
collated = np.asarray(list(zip(self.cs, colors)), vertices_type)
self.cs_vbuffer = gloo.VertexBuffer(collated)
self.cs_ibuffer = gloo.IndexBuffer(indices)
示例8: _compute_bbox
# 需要导入模块: from vispy import gloo [as 别名]
# 或者: from vispy.gloo import IndexBuffer [as 别名]
def _compute_bbox(self,color_type=0):
self.bb = []
minx, maxx = min(self.vertices[:, 0]), max(self.vertices[:, 0])
miny, maxy = min(self.vertices[:, 1]), max(self.vertices[:, 1])
minz, maxz = min(self.vertices[:, 2]), max(self.vertices[:, 2])
self.bb.append([minx, miny, minz])
self.bb.append([minx, maxy, minz])
self.bb.append([minx, miny, maxz])
self.bb.append([minx, maxy, maxz])
self.bb.append([maxx, miny, minz])
self.bb.append([maxx, maxy, minz])
self.bb.append([maxx, miny, maxz])
self.bb.append([maxx, maxy, maxz])
self.bb = np.asarray(self.bb, dtype=np.float32)
#self.diameter = max(pdist(self.bb, 'euclidean'))
# Set up rendering data
if(color_type==0):
colors = [[1, 0, 0],[1, 1, 0], [0, 1, 0], [0, 1, 1],
[0, 0, 1], [0, 1, 0], [0.5, 0, 0.5], [0, 0.5, 0.5]]
elif(color_type==1):
colors = [[0, 0, 1],[0, 0, 1], [0, 0, 1], [0, 0, 1],
[0, 0, 1], [0, 0, 1], [0, 0, 1], [0, 0, 1]]
elif(color_type==2):
colors = [[0, 1, 0],[0, 1, 0], [0, 1, 0], [0, 1, 0],
[0, 1, 0], [0, 1, 0], [0, 1, 0], [0, 1, 0]]
elif(color_type==3):
colors = [[1, 1, 1],[1, 1, 1], [1, 1, 1], [1, 1, 1],
[1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1]]
else:
colors = [[0, 1,0],[0, 1, 0], [0, 1, 0], [0, 1, 0],
[0, 1, 0], [0, 1, 0], [0, 1, 0], [0, 1, 0]]
indices = [0, 1, 0, 2, 3, 1, 3, 2,
4, 5, 4, 6, 7, 5, 7, 6,
0, 4, 1, 5, 2, 6, 3, 7]
vertices_type = [('a_position', np.float32, 3), ('a_color', np.float32, 3)]
collated = np.asarray(list(zip(self.bb, colors)), vertices_type)
self.bb_vbuffer = gloo.VertexBuffer(collated)
self.bb_ibuffer = gloo.IndexBuffer(indices)
示例9: __init__
# 需要导入模块: from vispy import gloo [as 别名]
# 或者: from vispy.gloo import IndexBuffer [as 别名]
def __init__(self, vol, clim=None, relative_step_size=0.8, threshold=0.8, step=4, cmap='hot',
emulate_texture=False):
tex_cls = TextureEmulated3D if emulate_texture else Texture3D
# Storage of information of volume
self._vol_shape = ()
self._clim = None
self._need_vertex_update = True
# Set the colormap
self._cmap = get_colormap(cmap)
# self._cmap = TransGrays()
# Create gloo objects
self._vertices = VertexBuffer()
self._texcoord = VertexBuffer(
np.array([
[0, 0, 0],
[1, 0, 0],
[0, 1, 0],
[1, 1, 0],
[0, 0, 1],
[1, 0, 1],
[0, 1, 1],
[1, 1, 1],
], dtype=np.float32))
self._tex = tex_cls((10, 10, 10), interpolation='linear',
wrapping='clamp_to_edge')
# Create program
Visual.__init__(self, vcode=VERT_SHADER, fcode=FRAG_SHADER)
self.shared_program['u_volumetex'] = self._tex
self.shared_program['a_position'] = self._vertices
self.shared_program['a_texcoord'] = self._texcoord
self.shared_program['u_threshold'] = threshold
self.shared_program['level'] = step
self._draw_mode = 'triangle_strip'
self._index_buffer = IndexBuffer()
# Only show back faces of cuboid. This is required because if we are
# inside the volume, then the front faces are outside of the clipping
# box and will not be drawn.
self.set_gl_state('translucent', cull_face=False)
# Set data
self.set_data(vol, clim)
# Set params
self.method = 'iso'
self.relative_step_size = relative_step_size
self.threshold = threshold if (threshold is not None) else vol.mean()
self.step = step
self.freeze()