File: isocurve_for_trisurface.py

package info (click to toggle)
python-vispy 0.15.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,868 kB
  • sloc: python: 59,799; javascript: 6,800; makefile: 69; sh: 6
file content (48 lines) | stat: -rw-r--r-- 1,395 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright (c) Vispy Development Team. All Rights Reserved.
# Distributed under the (new) BSD License. See LICENSE.txt for more info.
# -----------------------------------------------------------------------------
# vispy: gallery 2
"""
Isocurve for Triangular Mesh 
============================

This example demonstrates isocurve for triangular mesh with vertex data.
"""

import numpy as np

from vispy import app, scene

from vispy.geometry.generation import create_sphere

import sys

# Create a canvas with a 3D viewport
canvas = scene.SceneCanvas(keys='interactive',
                           title='Isocurve for Triangular Mesh Example')
canvas.show()
view = canvas.central_widget.add_view()

cols = 10
rows = 10
radius = 2
nbr_level = 20
mesh = create_sphere(cols, rows, radius=radius)
vertices = mesh.get_vertices()
tris = mesh.get_faces()

cl = np.linspace(-radius, radius, nbr_level+2)[1:-1]

scene.visuals.Isoline(vertices=vertices, tris=tris, data=vertices[:, 2],
                      levels=cl, color_lev='winter', parent=view.scene)

# Add a 3D axis to keep us oriented
scene.visuals.XYZAxis(parent=view.scene)

view.camera = scene.TurntableCamera()
view.camera.set_range((-1, 1), (-1, 1), (-1, 1))

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