Пример #1
0
    def test_gui(self):
        pp = Pointset(3)
        pp.append(0, 0, 0)
        pp.append(0, 1, 0)
        pp.append(1, 2, 0)
        pp.append(0, 2, 1)

        # Create all solids
        vv.solidBox((0, 0, 0))
        sphere = vv.solidSphere((3, 0, 0))
        cone = vv.solidCone((6, 0, 0))
        # a cone with 4 faces is a pyramid
        pyramid = vv.solidCone((9, 0, 0), N=4)
        vv.solidCylinder((0, 3, 0), (1, 1, 2))
        ring = vv.solidRing((3, 3, 0))
        vv.solidTeapot((6, 3, 0))
        vv.solidLine(pp+Point(9, 3, 0), radius=0.2)

        # Make the ring green
        ring.faceColor = 'g'

        # Make the sphere dull
        sphere.specular = 0
        sphere.diffuse = 0.4

        # Show lines in yellow pyramid
        pyramid.faceColor = 'r'
        pyramid.edgeShading = 'plain'

        # Colormap example
        N = cone._vertices.shape[0]
        cone.SetValues(np.linspace(0, 1, N))
        cone.colormap = vv.CM_JET
Пример #2
0
the mesh objects.

"""

import numpy as np
import visvis as vv
from visvis import Point, Pointset
vv.figure()
a = vv.gca()

# Define points for the line
pp = Pointset(3)
pp.append(0,0,0); pp.append(0,1,0); pp.append(1,2,0); pp.append(0,2,1)

# Create all solids
box = vv.solidBox((0,0,0))
sphere = vv.solidSphere((3,0,0))
cone = vv.solidCone((6,0,0))
pyramid = vv.solidCone((9,0,0), N=4) # a cone with 4 faces is a pyramid
cylinder = vv.solidCylinder((0,3,0),(1,1,2))
ring = vv.solidRing((3,3,0))
teapot = vv.solidTeapot((6,3,0))
line = vv.solidLine(pp+Point(9,3,0), radius = 0.2)

# Let's put a face on that cylinder
# This works because 2D texture coordinates are automatically generated for
# the sphere, cone, cylinder and ring.
im = vv.imread('astronaut.png')
cylinder.SetTexture(im)

# Make the ring green
Пример #3
0
    # Create mesh and set orientation
    m = vv.OrientableMesh(axes, vertices, None, normals, verticesPerFace=4)
    #
    if translation is not None:
        m.translation = translation
    if scaling is not None:
        m.scaling = scaling
    if direction is not None:
        m.direction = direction
    if rotation is not None:
        m.rotation = rotation

    # Adjust axes
    if axesAdjust:
        if axes.daspectAuto is None:
            axes.daspectAuto = False
        axes.cameraType = '3d'
        axes.SetLimits()

    # Done
    axes.Draw()
    return m


if __name__ == '__main__':
    m1 = vv.solidBox((3, 1, 1), (2, 2, 1), rotation=-20)
    m2 = vv.solidBox((1, 1, 0), (1, 1, 1.5), direction=(1, 0.4, 0.2))
    m1.faceColor = 'r'
    m2.faceColor = 'g'
Пример #4
0
def bar3(data1,
         data2=None,
         data3=None,
         width=0.75,
         axesAdjust=True,
         axes=None):
    """ bar3(*args, width=0.75, axesAdjust=True, axes=None)
    
    Create a 3D bar chart and returns a Bars3D instance that can be
    used to change the appearance of the bars (such as lighting properties
    and color).
    
    Usage
    -----
      * bar3(H, ...) creates bars of specified height.
      * bar3(X, H, ...) also supply their x-coordinates
      * bar3(X, Y, H, ...) supply both x- and y-coordinates
    
    Keyword arguments
    -----------------
    width : scalar
        The width of the bars.
    axesAdjust : bool
        If True, this function will call axes.SetLimits(), and set
        the camera type to 3D. If daspectAuto has not been set yet,
        it is set to False.
    axes : Axes instance
        Display the bars in the given axes, or the current axes if not given.
    
    """

    # Pre check
    if True:
        try:
            if not hasattr(data1, '__len__'):
                raise ValueError
            data1 = [float(val) for val in data1]
        except Exception:
            raise ValueError('bar3 needs a sequence of numbers.')
    if data2 is not None:
        try:
            if not hasattr(data2, '__len__'):
                raise ValueError
            data2 = [float(val) for val in data2]
        except Exception:
            raise ValueError('bar3 needs a sequence of numbers.')
    if data3 is not None:
        try:
            if not hasattr(data3, '__len__'):
                raise ValueError
            data3 = [float(val) for val in data3]
        except Exception:
            raise ValueError('bar3 needs a sequence of numbers.')

    # Parse input
    if data2 is None and data3 is None:
        # Only height given
        hh = data1
        xx = list(range(len(hh)))
        yy = [0] * len(hh)
    elif data3 is None:
        # Height and x given
        xx = data1
        hh = data2
        yy = [0] * len(hh)
    else:
        # All three given
        xx = data1
        yy = data2
        hh = data3

    # Check
    if len(hh) != len(xx) or len(hh) != len(yy):
        raise ValueError('Given arrays for bar3 must be of equal length.')

    # Get axes
    if axes is None:
        axes = vv.gca()

    # Create Bars instance
    bars = Bars3D(axes)

    # Create boxes
    for x, y, h in zip(xx, yy, hh):
        pos = (x, y, h / 2.0)
        scale = (width, width, h)
        m = vv.solidBox(pos, scale, axesAdjust=False, axes=bars)
        m.specular = 0

# Adjust axes
    if axesAdjust:
        if axes.daspectAuto is None:
            axes.daspectAuto = False
        axes.cameraType = '3d'
        axes.SetLimits()

    # Done
    axes.Draw()
    return bars
Пример #5
0
    
    # Create mesh and set orientation
    m = vv.OrientableMesh(axes, vertices, None, normals, verticesPerFace=4)
    #
    if translation is not None:
        m.translation = translation
    if scaling is not None:
        m.scaling = scaling
    if direction is not None:
        m.direction = direction
    if rotation is not None:
        m.rotation = rotation
    
    # Adjust axes
    if axesAdjust:
        if axes.daspectAuto is None:
            axes.daspectAuto = False
        axes.cameraType = '3d'
        axes.SetLimits()
    
    # Done
    axes.Draw()
    return m


if __name__ == '__main__':
    m1 = vv.solidBox((3,1,1), (2,2,1), rotation=-20)
    m2 = vv.solidBox((1,1,0), (1,1,1.5), direction=(1,0.4,0.2))
    m1.faceColor = 'r'
    m2.faceColor = 'g'
Пример #6
0
#!/usr/bin/env python
""" This example shows a ball that bounces on a surface and has
two balls rotating around it. It illustrates the use of timers
and how object hierarchy can be used to build (and move) complex
models consisting of multiple simple objects.
"""

import visvis as vv

# Create floor
floor = vv.solidBox((0,0,-1.5), (6,6,1))

# Create hierachy objects
sun = vv.solidSphere()
earth = vv.solidSphere((2,0,0),(0.3,0.3,0.2))
moon = vv.solidSphere((2,0,0),scaling=(0.2, 0.2, 0.3))
moon.parent = earth
earth.parent = sun

# Add transformations
sunTrans = sun.transformations[0]
earthRot = vv.Transform_Rotate(20)
moonRot = vv.Transform_Rotate(20)
earth.transformations.insert(0,earthRot)
moon.transformations.insert(0,moonRot)

# Set appearance
earth.faceColor = 'b'
moon.faceColor = 'y'
sun.faceColor = 'r'
Пример #7
0
def bar3(data1, data2=None, data3=None, width=0.75, axesAdjust=True, axes=None):
    """ bar3(*args, width=0.75, axesAdjust=True, axes=None)
    
    Create a 3D bar chart and returns a Bars3D instance that can be
    used to change the appearance of the bars (such as lighting properties
    and color).
    
    Usage
    -----
      * bar3(H, ...) creates bars of specified height.
      * bar3(X, H, ...) also supply their x-coordinates
      * bar3(X, Y, H, ...) supply both x- and y-coordinates
    
    Keyword arguments
    -----------------
    width : scalar
        The width of the bars.
    axesAdjust : bool
        If True, this function will call axes.SetLimits(), and set
        the camera type to 3D. If daspectAuto has not been set yet, 
        it is set to False.
    axes : Axes instance
        Display the bars in the given axes, or the current axes if not given.
    
    """

    # Pre check
    if True:
        try:
            if not hasattr(data1, "__len__"):
                raise ValueError
            data1 = [float(val) for val in data1]
        except Exception:
            raise ValueError("bar3 needs a sequence of numbers.")
    if data2 is not None:
        try:
            if not hasattr(data2, "__len__"):
                raise ValueError
            data2 = [float(val) for val in data2]
        except Exception:
            raise ValueError("bar3 needs a sequence of numbers.")
    if data3 is not None:
        try:
            if not hasattr(data3, "__len__"):
                raise ValueError
            data3 = [float(val) for val in data3]
        except Exception:
            raise ValueError("bar3 needs a sequence of numbers.")

    # Parse input
    if data2 is None and data3 is None:
        # Only height given
        hh = data1
        xx = range(len(hh))
        yy = [0] * len(hh)
    elif data3 is None:
        # Height and x given
        xx = data1
        hh = data2
        yy = [0] * len(hh)
    else:
        # All three given
        xx = data1
        yy = data2
        hh = data3

    # Check
    if len(hh) != len(xx) or len(hh) != len(yy):
        raise ValueError("Given arrays for bar3 must be of equal length.")

    # Get axes
    if axes is None:
        axes = vv.gca()

    # Create Bars instance
    bars = Bars3D(axes)

    # Create boxes
    for x, y, h in zip(xx, yy, hh):
        pos = (x, y, h / 2.0)
        scale = (width, width, h)
        m = vv.solidBox(pos, scale, axesAdjust=False, axes=bars)
        m.specular = 0

    # Adjust axes
    if axesAdjust:
        if axes.daspectAuto is None:
            axes.daspectAuto = False
        axes.cameraType = "3d"
        axes.SetLimits()

    # Done
    axes.Draw()
    return bars
Пример #8
0
#!/usr/bin/env python
""" This example shows a ball that bounces on a surface and has
two balls rotating around it. It illustrates the use of timers
and how object hierarchy can be used to build (and move) complex
models consisting of multiple simple objects.
"""

import visvis as vv

# Create floor
floor = vv.solidBox((0, 0, -1.5), (6, 6, 1))

# Create hierachy objects
sun = vv.solidSphere()
earth = vv.solidSphere((2, 0, 0), (0.3, 0.3, 0.2))
moon = vv.solidSphere((2, 0, 0), scaling=(0.2, 0.2, 0.3))
moon.parent = earth
earth.parent = sun

# Add transformations
sunTrans = sun.transformations[0]
earthRot = vv.Transform_Rotate(20)
moonRot = vv.Transform_Rotate(20)
earth.transformations.insert(0, earthRot)
moon.transformations.insert(0, moonRot)

# Set appearance
earth.faceColor = 'b'
moon.faceColor = 'y'
sun.faceColor = 'r'
Пример #9
0
the mesh objects.

"""

import numpy as np
import visvis as vv
from visvis import Point, Pointset
vv.figure()
a = vv.gca()

# Define points for the line
pp = Pointset(3)
pp.append(0,0,0); pp.append(0,1,0); pp.append(1,2,0); pp.append(0,2,1)

# Create all solids
box = vv.solidBox((0,0,0))
sphere = vv.solidSphere((3,0,0))
cone = vv.solidCone((6,0,0))
pyramid = vv.solidCone((9,0,0), N=4) # a cone with 4 faces is a pyramid
cylinder = vv.solidCylinder((0,3,0),(1,1,2))
ring = vv.solidRing((3,3,0))
teapot = vv.solidTeapot((6,3,0))
line = vv.solidLine(pp+Point(9,3,0), radius = 0.2)

# Let's put a face on that cylinder
# This works because 2D texture coordinates are automatically generated for
# the sphere, cone, cylinder and ring. 
im = vv.imread('lena.png')
cylinder.SetTexture(im)

# Make the ring green