1 |
\chapter{The module \pyvisi} |
\chapter{The module \pyvisi} |
2 |
|
\label{PYVISI CHAP} |
|
\declaremodule{extension}{pyvisi} |
|
|
\modulesynopsis{visualization interface} |
|
|
|
|
|
The idea behind is to provide an easy to use interface and unified to a variety of |
|
|
visualization tools like \VTK, \OpenDX and \GnuPlot. |
|
|
|
|
|
The following script illustartes the usage of \pyvisi together with the |
|
|
\VTK library: |
|
|
\begin{python} |
|
|
from esys.pyvisi import * # base level visualisation stuff |
|
|
from esys.pyvisi.renderers.vtk import * # vtk renderer module |
|
|
from esys.escript import * |
|
|
from esys.finley import Brick |
|
|
# now make some data of some kind |
|
|
domain = Brick(3,5,7) # a Finley domain |
|
|
vectorData = domain.getX() # get vector data from the domain nodes |
|
|
# define the scene object |
|
|
scene = Scene() |
|
|
# create an ArrowPlot object |
|
|
plot = ArrowPlot(scene) |
|
|
# add the plot to the scene |
|
|
scene.add(plot) |
|
|
# assign some data to the plot |
|
|
plot.setData(vectorData) |
|
|
# render the scene |
|
|
scene.render() |
|
|
# saving a scene |
|
|
scene.save(file="example.jpg", format="jpeg") |
|
|
\begin{python} |
|
|
A \Scene is a container for all of the kinds of things you want to put into your plot, |
|
|
for instance, images, domaines, arrow plots, contour plots, spheres etc. |
|
|
The renderer is specified in the scene initialisation. In fact the |
|
|
\code{from esys.pyvisi.renderers.vtk import *} provides the specific implementation for |
|
|
\VTK |
|
|
|
|
|
|
|
|
\begin{verbose} |
|
|
class ArrowPlot3D(Plot): |
|
|
""" |
|
|
Arrow field plot in three dimensions |
|
|
""" |
|
|
def __init__(self, scene): |
|
|
""" |
|
|
Initialisation of the ArrowPlot3D class |
|
|
|
|
|
@param scene: The Scene to render the plot in |
|
|
@type scene: Scene object |
|
|
def setData(self, *dataList, **options): |
|
|
""" |
|
|
Set data to the plot |
|
|
|
|
|
@param dataList: List of data to set to the plot |
|
|
@type dataList: tuple |
|
|
|
|
|
@param options: Dictionary of extra options |
|
|
@type options: dict |
|
|
|
|
|
@param fname: Filename of the input vtk file |
|
|
@type fname: string |
|
|
|
|
|
@param format: Format of the input vtk file ('vtk' or 'vtk-xml') |
|
|
@type format: string |
|
|
|
|
|
@param vectors: the name of the vector data in the vtk file to use |
|
|
@type vectors: string |
|
|
""" |
|
|
class ArrowPlot(Plot): |
|
|
""" |
|
|
Arrow field plot |
|
|
""" |
|
|
def __init__(self, scene): |
|
|
""" |
|
|
Initialisation of the ArrowPlot class |
|
|
|
|
|
@param scene: The Scene to render the plot in |
|
|
@type scene: Scene object |
|
|
""" |
|
|
def setData(self, *dataList, **options): |
|
|
""" |
|
|
Set data to the plot |
|
|
|
|
|
@param dataList: List of data to set to the plot |
|
|
@type dataList: tuple |
|
|
|
|
|
@param options: Dictionary of extra options |
|
|
@type options: dict |
|
|
|
|
|
@param fname: the name of the input vtk file |
|
|
@type fname: string |
|
|
|
|
|
@param format: the format of the input vtk file ('vtk' or 'vtk-xml') |
|
|
@type format: string |
|
|
|
|
|
@param vectors: the name of the vector data in the vtk file to use |
|
|
@type vectors: string |
|
|
""" |
|
|
class Axes(Plot): |
|
|
""" |
|
|
Axes class |
|
|
""" |
|
|
def __init__(self): |
|
|
""" |
|
|
Initialisation of Axes object |
|
|
""" |
|
|
debugMsg("Called Axes.__init__()") |
|
|
Plot.__init__(self) |
|
|
|
|
|
class BallPlot(Plot): |
|
|
""" |
|
|
Ball plot |
|
|
""" |
|
|
def __init__(self, scene): |
|
|
|
|
|
def setData(self, points=None, |
|
|
fname=None, format=None, |
|
|
radii=None, colors=None, tags=None): |
|
|
""" |
|
|
Set data to the plot |
|
|
@param points: the array to use for the points of the sphere |
|
|
locations in space |
|
|
@type points: float array |
|
|
|
|
|
@param fname: the name of the input vtk file |
|
|
@type fname: string |
|
|
|
|
|
@param format: the format of the input vtk file ('vtk' or 'vtk-xml') |
|
|
@type format: string |
|
|
|
|
|
@param radii: the name of the scalar array in the vtk unstructured |
|
|
grid to use as the radii of the balls |
|
|
@type radii: float array |
|
|
|
|
|
@param colors: the name of the scalar array in the vtk unstructured |
|
|
grid to use as the colour tags of the balls |
|
|
@type colors: string |
|
|
|
|
|
@param tags: the name of the scalar array in the vtk unstructured |
|
|
grid to use as the colour of the tags of the balls |
|
|
@type tags: integer array |
|
|
""" |
|
|
|
|
|
class Box(Item): |
|
|
""" |
|
|
Generic class for Box objects |
|
|
|
|
|
To define a box one specify one of three groups of things: |
|
|
- The bounds of the box: xmin, xmax, ymin, ymax, zmin, zmax |
|
|
- The dimensions and origin: width, height, depth and origin |
|
|
- The bottom left front and top right back corners: blf, trb |
|
|
""" |
|
|
|
|
|
def __init__(self): |
|
|
""" |
|
|
Initialisation of the Box object |
|
|
""" |
|
|
debugMsg("Called Box.__init__()") |
|
|
Item.__init__(self) |
|
|
|
|
|
# define a box in many ways, either by its centre and width, height |
|
|
# and depth, or by its bounds, xmin, xmax, ymin, ymax, zmin, zmax, |
|
|
# or by its bottom left front and top right back points. |
|
|
|
|
|
# set the default bounds |
|
|
self.xmin = -0.5 |
|
|
self.xmax = 0.5 |
|
|
self.ymin = -0.5 |
|
|
self.ymax = 0.5 |
|
|
self.zmin = -0.5 |
|
|
self.zmax = 0.5 |
|
|
|
|
|
# set the default origin (the centre of the box) |
|
|
self.origin = ((self.xmin + self.xmax)/2.0, |
|
|
(self.ymin + self.ymax)/2.0, |
|
|
(self.zmin + self.zmax)/2.0) |
|
|
|
|
|
# set the default dimensions |
|
|
self.width = self.xmax - self.xmin |
|
|
self.height = self.ymax - self.ymin |
|
|
self.depth = self.zmax - self.zmin |
|
|
|
|
|
# set the default blf and trb points |
|
|
self.blf = (self.xmin, self.ymin, self.zmin) |
|
|
self.trb = (self.xmax, self.ymax, self.zmax) |
|
|
|
|
|
# tolerance for calculated variables checking purposes |
|
|
self.tolerance = 1e-8 |
|
|
|
|
|
def setBounds(self, xmin, xmax, ymin, ymax, zmin, zmax): |
|
|
""" |
|
|
Set the bounds of the box |
|
|
""" |
|
|
def getBounds(self): |
|
|
""" |
|
|
Get the current bounds of the box |
|
|
""" |
|
|
|
|
|
def setOrigin(self, xo, yo, zo): |
|
|
""" |
|
|
Set the origin of the box |
|
|
""" |
|
|
def getOrigin(self): |
|
|
""" |
|
|
Get the current origin of the box |
|
|
""" |
|
|
debugMsg("Called Box.getOrigin()") |
|
|
return self.origin |
|
|
|
|
|
def setWidth(self, width): |
|
|
""" |
|
|
Set the width of the box |
|
|
""" |
|
|
def getWidth(self): |
|
|
""" |
|
|
Get the current box width |
|
|
""" |
|
|
debugMsg("Called Box.getWidth()") |
|
|
return self.width |
|
|
|
|
|
def setHeight(self, height): |
|
|
""" |
|
|
Set the box height |
|
|
""" |
|
|
|
|
|
def getHeight(self): |
|
|
""" |
|
|
Get the current box height |
|
|
""" |
|
|
debugMsg("Called Box.getHeight()") |
|
|
return self.height |
|
|
|
|
|
def setDepth(self, depth): |
|
|
""" |
|
|
Set the box depth |
|
|
""" |
|
|
|
|
|
def getDepth(self): |
|
|
""" |
|
|
Get the current box depth |
|
|
""" |
|
|
debugMsg("Called Box.getDepth()") |
|
|
return self.depth |
|
|
|
|
|
def setBLF(self, bottom, left, front): |
|
|
""" |
|
|
Set the position of the bottom, left, front corner |
|
|
""" |
|
|
|
|
|
def getBLF(self): |
|
|
""" |
|
|
Get the current position of the bottom, left, front corner |
|
|
""" |
|
|
debugMsg("Called Box.getBLF()") |
|
|
return self.blf |
|
|
|
|
|
def setTRB(self, top, right, back): |
|
|
""" |
|
|
Set the position of the top, right, back corner |
|
|
""" |
|
|
|
|
|
def getTRB(self): |
|
|
""" |
|
|
Get the current position of the top, right, back corner |
|
|
""" |
|
|
debugMsg("Called Box.getTRB()") |
|
|
return self.trb |
|
|
|
|
|
|
|
|
class ClipBox(Box): |
|
|
""" |
|
|
Clip box class: used to clip data sets with a box |
|
|
|
|
|
A box in this sense means three planes at right angles to one another |
|
|
""" |
|
|
|
|
|
def __init__(self, plot): |
|
|
""" |
|
|
Intialisation of the ClipBox object |
|
|
""" |
|
|
|
|
|
def setInsideOut(self, insideOut): |
|
|
""" |
|
|
Set the inside out flag |
|
|
""" |
|
|
|
|
|
def getInsideOut(self): |
|
|
""" |
|
|
Get the current value of the inside out flag |
|
|
""" |
|
|
|
|
|
class Camera(Item): |
|
|
""" |
|
|
Camera class |
|
|
""" |
|
|
def __init__(self, scene): |
|
|
""" |
|
|
Initialisation of the Camera object |
|
|
|
|
|
@param scene: The Scene object to add the Camera object to |
|
|
@type scene: Scene object |
|
|
""" |
|
|
def setPosition(self, *pos): |
|
|
""" |
|
|
Set position of camera within scene |
|
|
|
|
|
@param pos: Position to set camera in terms of x,y,z coordinates |
|
|
@type pos: tuple |
|
|
""" |
|
|
|
|
|
def getPosition(self): |
|
|
""" |
|
|
Get the position of Camera within Scene |
|
|
|
|
|
Returns the position in a tuple of form (xPos, yPos, zPos) |
|
|
""" |
|
|
debugMsg("Called Camera.getPosition()") |
|
|
|
|
|
return (self.xPos, self.yPos, self.zPos) |
|
|
|
|
|
def setFocalPoint(self, *pos): |
|
|
""" |
|
|
Sets the focal point of the Camera with the Scene |
|
|
|
|
|
@param pos: Position to set the focal point |
|
|
@type pos: tuple |
|
|
""" |
|
|
|
|
|
def getFocalPoint(self): |
|
|
""" |
|
|
Get the position of the focal point of the Camera |
|
|
|
|
|
Returns the position of the focal point in a tuple of form |
|
|
(xPos, yPos, zPos) |
|
|
""" |
|
|
|
|
|
def setElevation(self, elevation): |
|
|
""" |
|
|
Set the elevation angle (in degrees) of the Camera |
|
|
|
|
|
@param elevation: The elevation angle (in degrees) of the Camera |
|
|
@type elevation: float |
|
|
""" |
|
|
|
|
|
return |
|
|
|
|
|
def getElevation(self): |
|
|
""" |
|
|
Gets the elevation angle (in degrees) of the Camera |
|
|
""" |
|
|
|
|
|
def setAzimuth(self, azimuth): |
|
|
""" |
|
|
Set the azimuthal angle (in degrees) of the Camera |
|
|
|
|
|
@param azimuth: The azimuthal angle (in degrees) of the Camera |
|
|
@type azimuth: float |
|
|
""" |
|
|
|
|
|
def getAzimuth(self): |
|
|
""" |
|
|
Get the azimuthal angle (in degrees) of the Camera |
|
|
""" |
|
|
class ContourPlot(Plot): |
|
|
""" |
|
|
Contour plot |
|
|
""" |
|
|
def __init__(self, scene): |
|
|
""" |
|
|
Initialisation of the ContourPlot class |
|
|
|
|
|
@param scene: The Scene to render the plot in |
|
|
@type scene: Scene object |
|
|
""" |
|
|
def setData(self, *dataList, **options): |
|
|
""" |
|
|
Set data to the plot |
|
|
|
|
|
@param dataList: List of data to set to the plot |
|
|
@type dataList: tuple |
|
|
|
|
|
@param options: Dictionary of extra options |
|
|
@type options: dict |
|
|
|
|
|
@param fname: the name of the input vtk file |
|
|
@type fname: string |
|
|
|
|
|
@param format: the format of the input vtk file ('vtk' or 'vtk-xml') |
|
|
@type format: string |
|
|
|
|
|
@param scalars: the scalar data in the vtk file to use |
|
|
@type scalars: string |
|
|
""" |
|
|
|
|
|
class EllipsoidPlot(Plot): |
|
|
""" |
|
|
Ellipsoid plot |
|
|
""" |
|
|
def __init__(self, scene): |
|
|
""" |
|
|
Initialisation of the EllipsoidPlot class |
|
|
|
|
|
@param scene: The Scene to render the plot in |
|
|
@type scene: Scene object |
|
|
""" |
|
|
debugMsg("Called EllipsoidPlot.__init__()") |
|
|
Plot.__init__(self, scene) |
|
|
|
|
|
self.renderer = scene.renderer |
|
|
self.renderer.addToInitStack("# EllipsoidPlot.__init__()") |
|
|
|
|
|
# labels and stuff |
|
|
self.title = None |
|
|
self.xlabel = None |
|
|
self.ylabel = None |
|
|
self.zlabel = None |
|
|
|
|
|
# default values for fname, format and tensors |
|
|
self.fname = None |
|
|
self.format = None |
|
|
self.tensors = None |
|
|
|
|
|
# default values for shared info |
|
|
self.escriptData = False |
|
|
self.otherData = False |
|
|
|
|
|
# add the plot to the scene |
|
|
scene.add(self) |
|
|
|
|
|
def setData(self, *dataList, **options): |
|
|
""" |
|
|
Set data to the plot |
|
|
|
|
|
@param dataList: List of data to set to the plot |
|
|
@type dataList: tuple |
|
|
|
|
|
@param options: Dictionary of keyword options to the method |
|
|
@type options: dict |
|
|
|
|
|
@param fname: the name of the input vtk file |
|
|
@type fname: string |
|
|
|
|
|
@param format: the format of the input vtk file ('vtk' or 'vtk-xml') |
|
|
@type format: string |
|
|
|
|
|
@param tensors: the name of the tensor data in the vtk file to use |
|
|
@type tensors: string |
|
|
""" |
|
|
|
|
|
class Image(Item): |
|
|
""" |
|
|
Image class. Generic class to handle image data. |
|
|
""" |
|
|
def __init__(self, scene=None): |
|
|
""" |
|
|
Initialises the Image class object |
|
|
|
|
|
@param scene: The Scene object to add to |
|
|
@type scene: Scene object |
|
|
""" |
|
|
debugMsg("Called Image.__init__()") |
|
|
Item.__init__(self) |
|
3 |
|
|
4 |
if scene is not None: |
\section{Introduction} |
|
self.renderer = scene.renderer |
|
|
|
|
|
def load(self, fname): |
|
|
""" |
|
|
Loads image data from file. |
|
|
|
|
|
@param fname: The filename from which to load image data |
|
|
@type fname: string |
|
|
""" |
|
|
debugMsg("Called Image.load()") |
|
|
|
|
|
fileCheck(fname) |
|
|
|
|
|
return |
|
|
|
|
|
class JpegImage(Image): |
|
|
""" |
|
|
Subclass of Image class to explicitly handle jpeg images |
|
|
""" |
|
|
def __init__(self, scene=None): |
|
|
""" |
|
|
Initialises the JpegImage class object |
|
|
|
|
|
@param scene: The Scene object to add to |
|
|
@type scene: Scene object |
|
|
""" |
|
|
|
|
|
def load(self, fname): |
|
|
""" |
|
|
Loads jpeg image data from file. |
|
|
|
|
|
@param fname: The filename from which to load jpeg image data |
|
|
@type fname: string |
|
|
""" |
|
|
|
|
|
class PngImage(Image): |
|
|
""" |
|
|
Subclass of Image class to explicitly handle png images |
|
|
""" |
|
|
def __init__(self, scene=None): |
|
|
""" |
|
|
Initialises the PngImage class object |
|
|
|
|
|
@param scene: The Scene object to add to |
|
|
@type scene: Scene object |
|
|
""" |
|
|
|
|
|
def load(self, fname): |
|
|
""" |
|
|
Loads png image data from file. |
|
|
|
|
|
@param fname: The filename from which to load png image data |
|
|
@type fname: string |
|
|
""" |
|
|
class BmpImage(Image): |
|
|
""" |
|
|
Subclass of Image class to explicitly handle bmp images |
|
|
""" |
|
|
def __init__(self, scene=None): |
|
|
""" |
|
|
Initialises the BmpImage class object |
|
|
|
|
|
@param scene: The Scene object to add to |
|
|
@type scene: Scene object |
|
|
""" |
|
|
def load(self, fname): |
|
|
""" |
|
|
Loads bmp image data from file. |
|
|
|
|
|
@param fname: The filename from which to load bmp image data |
|
|
@type fname: string |
|
|
""" |
|
|
|
|
|
class TiffImage(Image): |
|
|
""" |
|
|
Subclass of Image class to explicitly handle tiff images |
|
|
""" |
|
|
def __init__(self, scene=None): |
|
|
""" |
|
|
Initialises the TiffImage class object |
|
|
|
|
|
@param scene: The Scene object to add to |
|
|
@type scene: Scene object |
|
|
""" |
|
|
def load(self, fname): |
|
|
""" |
|
|
Loads tiff image data from file. |
|
|
|
|
|
@param fname: The filename from which to load tiff image data |
|
|
@type fname: string |
|
|
""" |
|
|
class PnmImage(Image): |
|
|
""" |
|
|
Subclass of Image class to explicitly handle pnm (ppm, pgm, pbm) images |
|
|
""" |
|
|
def __init__(self, scene=None): |
|
|
""" |
|
|
Initialises the PnmImage class object |
|
|
|
|
|
@param scene: The Scene object to add to |
|
|
@type scene: Scene object |
|
|
""" |
|
|
|
|
|
def load(self, fname): |
|
|
""" |
|
|
Loads pnm (ppm, pgm, pbm) image data from file. |
|
|
|
|
|
@param fname: The filename from which to load pnm image data |
|
|
@type fname: string |
|
|
""" |
|
|
|
|
|
class PsImage(Image): |
|
|
""" |
|
|
Subclass of Image class to explicitly handle ps images |
|
|
""" |
|
|
def __init__(self, scene=None): |
|
|
""" |
|
|
Initialises the PsImage class object |
|
|
|
|
|
This object is B{only} used for generating postscript output |
|
|
|
|
|
@param scene: The Scene object to add to |
|
|
@type scene: Scene object |
|
|
""" |
|
|
|
|
|
def load(self, fname): |
|
|
""" |
|
|
Loads ps image data from file. |
|
|
|
|
|
B{NOT} supported by this renderer module |
|
|
|
|
|
@param fname: The filename from which to load ps image data |
|
|
@type fname: string |
|
|
""" |
|
|
debugMsg("Called PsImage.load()") |
|
5 |
|
|
6 |
# need to check if the file exists |
\pyvisi provides an easy to use interface to the \VTK visualization |
7 |
fileCheck(fname) |
tool. |
8 |
|
|
9 |
# this ability not handled by this renderer module |
\section{Rendering} |
10 |
unsupportedError() |
same word on rendering, off-line, on-line, how to rotate, zoom, close the window, ... |
11 |
|
|
12 |
return |
\section{How to Make a Movie} |
13 |
|
|
14 |
|
\section{\pyvisi Classes} |
15 |
|
\declaremodule{extension}{esys.pyvisi} |
16 |
|
\modulesynopsis{A simple Python visualization interface for \VTK} |
17 |
|
|
18 |
|
In this section we give a brief overview over the important classes and their methods. Please |
19 |
|
check the \ReferenceGuide on details. |
20 |
|
%===================================================================================== |
21 |
|
\subsection{Scene Classes} |
22 |
|
\begin{classdesc}{Scene}{} |
23 |
|
Displays a scene in which objects are to be rendered on. |
24 |
|
\end{classdesc} |
25 |
|
|
26 |
|
\begin{classdesc}{Camera}{} |
27 |
|
Controls the camera manipulation. |
28 |
|
\end{classdesc} |
29 |
|
|
30 |
|
\begin{classdesc}{Light}{} |
31 |
|
Controls the light manipulation. |
32 |
|
\end{classdesc} |
33 |
|
|
34 |
|
%============================================================================================================ |
35 |
|
\subsection{Input Classes} |
36 |
|
|
37 |
|
\begin{classdesc}{Image}{} |
38 |
|
Displays an image. |
39 |
|
\end{classdesc} |
40 |
|
|
41 |
|
\begin{classdesc}{Text}{} |
42 |
|
Shows some 2D text. |
43 |
|
\end{classdesc} |
44 |
|
|
45 |
|
\begin{classdesc}{DataCollector}{} |
46 |
|
Deals with the source of data for visualization. |
47 |
|
\end{classdesc} |
48 |
|
|
49 |
|
%============================================================================================================ |
50 |
|
\subsection{Data Visualization} |
51 |
|
\begin{classdesc}{Map}{} |
52 |
|
Displays a scalar field using a domain surface. |
53 |
|
\end{classdesc} |
54 |
|
|
55 |
|
\begin{classdesc}{MapOnPlaneCut}{} |
56 |
|
Displays a scalar field using a domain surface cut on a plane. |
57 |
|
\end{classdesc} |
58 |
|
|
59 |
|
\begin{classdesc}{MapOnPlaneClip}{} |
60 |
|
Displays a scalar field using a domain surface clipped |
61 |
|
on a plane. |
62 |
|
\end{classdesc} |
63 |
|
|
64 |
|
\begin{classdesc}{MapOnScalarClip}{} |
65 |
|
Displays a scalar field using a domain surface clipped |
66 |
|
using a scalar value. |
67 |
|
\end{classdesc} |
68 |
|
|
69 |
|
\begin{classdesc}{Velocity}{} |
70 |
|
Displays a vector field using arrows. |
71 |
|
\end{classdesc} |
72 |
|
|
73 |
|
\begin{classdesc}{VelocityOnPlaneCut}{} |
74 |
|
Displays a vector field using arrows cut on a plane. |
75 |
|
\end{classdesc} |
76 |
|
|
77 |
|
\begin{classdesc}{VelocityOnPlaneClip}{} |
78 |
|
Displays a vector field using arrows clipped on a |
79 |
|
plane. |
80 |
|
\end{classdesc} |
81 |
|
|
82 |
|
\begin{classdesc}{Ellipsoid}{} |
83 |
|
Displays a tensor field using spheres. |
84 |
|
\end{classdesc} |
85 |
|
|
86 |
|
\begin{classdesc}{EllipsoidOnPlaneCut}{} |
87 |
|
Displays a tensor field using spheres cut on a |
88 |
|
plane. |
89 |
|
\end{classdesc} |
90 |
|
|
91 |
|
\begin{classdesc}{EllipsoidOnPlaneClip}{} |
92 |
|
Displays a tensor field using spheres clipped |
93 |
|
on a plane. |
94 |
|
\end{classdesc} |
95 |
|
|
96 |
|
|
97 |
|
\begin{classdesc}{Contour}{} |
98 |
|
Shows a scalar field by contour surfaces. |
99 |
|
\end{classdesc} |
100 |
|
|
101 |
|
\begin{classdesc}{ContourOnPlane}{} |
102 |
|
Shows a scalar field by contour surfaces on |
103 |
|
a given plane. |
104 |
|
\end{classdesc} |
105 |
|
|
106 |
|
\begin{classdesc}{ContourOnClip}{} |
107 |
|
Shows a scalar field by contour surfaces on |
108 |
|
a given clip. |
109 |
|
\end{classdesc} |
110 |
|
|
111 |
|
\begin{classdesc}{IsoSurface}{} |
112 |
|
Shows a scalar field for a given value by |
113 |
|
an isosurface. |
114 |
|
\end{classdesc} |
115 |
|
|
116 |
|
\begin{classdesc}{IsoSurfaceOnPlane}{} |
117 |
|
Shows a scalar field for a given value by |
118 |
|
an isosurfaceon a given plane. |
119 |
|
\end{classdesc} |
120 |
|
|
121 |
|
\begin{classdesc}{IsoSurfaceOnClip}{} |
122 |
|
Shows a scalar field for a given vlaue by |
123 |
|
an isosurface on a given clip. |
124 |
|
\end{classdesc} |
125 |
|
|
126 |
|
\begin{classdesc}{StreamLines}{} |
127 |
|
Shows the path of particles in a vector field. |
128 |
|
\end{classdesc} |
129 |
|
|
130 |
|
\begin{classdesc}{Carpet}{} |
131 |
|
Shows a scalar field as plane deformated along |
132 |
|
the plane normal. |
133 |
|
\end{classdesc} |
134 |
|
|
135 |
|
\section{Geometry} |
136 |
|
\begin{classdesc}{Position}{} |
137 |
|
Defines the x,y and z coordinates rendered object. |
138 |
|
\end{classdesc} |
139 |
|
|
140 |
|
\begin{classdesc}{Transform}{} |
141 |
|
Defines the orientation of rendered object. |
142 |
|
\end{classdesc} |
143 |
|
|
144 |
|
\begin{classdesc}{Plane}{} |
145 |
|
Defines the cutting/clipping of rendered objects. |
146 |
|
\end{classdesc} |
147 |
|
|
148 |
|
|
149 |
|
\subsection{Beautification} |
150 |
|
\begin{classdesc}{Style}{} |
151 |
|
Defines the style of text. |
152 |
|
\end{classdesc} |
153 |
|
|
154 |
|
\begin{classdesc}{BlueToRed}{} |
155 |
|
Defines a map spectrum from blue to red. |
156 |
|
\end{classdesc} |
157 |
|
|
158 |
|
\begin{classdesc}{RedToBlue}{} |
159 |
|
Defines a map spectrum from red to blue. |
160 |
|
\end{classdesc} |
161 |
|
|
|
def render(self): |
|
|
""" |
|
|
Does PsImage object specific (pre)rendering stuff |
|
|
""" |
|
|
debugMsg("Called PsImage.render()") |
|
|
|
|
|
return |
|
|
|
|
|
class PdfImage(Image): |
|
|
""" |
|
|
Subclass of Image class to explicitly handle pdf images |
|
|
""" |
|
|
def __init__(self, scene=None): |
|
|
""" |
|
|
Initialises the PdfImage class object |
|
|
|
|
|
This object is B{only} used for generating pdf output |
|
|
|
|
|
@param scene: The Scene object to add to |
|
|
@type scene: Scene object |
|
|
""" |
|
|
|
|
|
def load(self, fname): |
|
|
""" |
|
|
Loads pdf image data from file. |
|
|
|
|
|
B{NOT} supported by this renderer module |
|
|
|
|
|
@param fname: The filename from which to load pdf image data |
|
|
@type fname: string |
|
|
""" |
|
|
|
|
|
class IsosurfacePlot(Plot): |
|
|
""" |
|
|
Isosurface plot |
|
|
""" |
|
|
def __init__(self, scene): |
|
|
""" |
|
|
Initialisation of the IsosurfacePlot class |
|
|
|
|
|
@param scene: The Scene to render the plot in |
|
|
@type scene: Scene object |
|
|
""" |
|
|
def setData(self, *dataList, **options): |
|
|
""" |
|
|
Set data to the plot |
|
|
|
|
|
@param dataList: List of data to set to the plot |
|
|
@type dataList: tuple |
|
|
|
|
|
@param options: Dictionary of keyword options to the method |
|
|
@type options: dict |
|
|
|
|
|
@param fname: the name of the input vtk file |
|
|
@type fname: string |
|
|
|
|
|
@param format: the format of the input vtk file ('vtk' or 'vtk-xml') |
|
|
@type format: string |
|
|
|
|
|
@param scalars: the name of the scalar data in the vtk file to use |
|
|
@type scalars: string |
|
|
""" |
|
|
|
|
|
class LinePlot(Plot): |
|
|
""" |
|
|
Line plot |
|
|
""" |
|
|
def __init__(self, scene): |
|
|
""" |
|
|
Initialisation of the LinePlot class |
|
|
|
|
|
@param scene: The Scene to render the plot in |
|
|
@type scene: Scene object |
|
|
""" |
|
|
|
|
|
def setData(self, *dataList, **options): |
|
|
""" |
|
|
Set data to the plot |
|
|
|
|
|
@param dataList: List of data to set to the plot |
|
|
@type dataList: tuple |
|
|
|
|
|
@param options: Dictionary of extra options |
|
|
@type options: dict |
|
|
|
|
|
@param offset: whether or not to offset the lines from one another |
|
|
@type offset: boolean |
|
|
|
|
|
@param fname: Filename of the input vtk file |
|
|
@type fname: string |
|
|
|
|
|
@param format: format of the input vtk file ('vtk' or 'vtk-xml') |
|
|
@type format: string |
|
|
|
|
|
@param scalars: the name of the scalar data in the vtk file to use |
|
|
@type scalars: string |
|
|
""" |
|
|
|
|
|
class OffsetPlot(Plot): |
|
|
""" |
|
|
Offset plot |
|
|
""" |
|
|
def __init__(self, scene): |
|
|
""" |
|
|
Initialisation of the OffsetPlot class |
|
|
|
|
|
@param scene: The Scene to render the plot in |
|
|
@type scene: Scene object |
|
|
""" |
|
|
|
|
|
def setData(self, *dataList, **options): |
|
|
""" |
|
|
Set data to the plot |
|
|
|
|
|
@param dataList: List of data to set to the plot |
|
|
@type dataList: tuple |
|
|
|
|
|
@param options: Dictionary of extra options |
|
|
@type options: dict |
|
|
|
|
|
@param fname: Filename of the input vtk file |
|
|
@type fname: string |
|
|
|
|
|
@param format: Format of the input vtk file ('vtk' or 'vtk-xml') |
|
|
@type format: string |
|
|
|
|
|
@param scalars: the name of the scalar data in the vtk file to use |
|
|
@type scalars: string |
|
|
""" |
|
|
class Plane(Item): |
|
|
""" |
|
|
Generic class for Plane objects |
|
|
""" |
|
|
|
|
|
def __init__(self, scene): |
|
|
""" |
|
|
Initialisation of the Plane object |
|
|
""" |
|
|
|
|
|
def setOrigin(self, x, y, z): |
|
|
""" |
|
|
Set the origin of the plane |
|
|
""" |
|
|
|
|
|
def getOrigin(self): |
|
|
""" |
|
|
Get the current origin of the plane |
|
|
""" |
|
|
|
|
|
def setNormal(self, vx, vy, vz): |
|
|
""" |
|
|
Set the normal vector to the plane |
|
|
""" |
|
|
|
|
|
def getNormal(self): |
|
|
""" |
|
|
Get the current normal vector to the plane |
|
|
""" |
|
|
|
|
|
def mapImageToPlane(self, image): |
|
|
# this really needs to go somewhere else!!! |
|
|
""" |
|
|
Maps an Image object onto a Plane object |
|
|
""" |
|
|
|
|
|
class CutPlane(Plane): |
|
|
""" |
|
|
Cut plane class: used to cut data sets with a plane |
|
|
|
|
|
Cut plane objects define a plane to cut a data set or plot by and return |
|
|
the data along the intersection between the data set or plot with the |
|
|
defined plane. |
|
|
""" |
|
|
|
|
|
def __init__(self): |
|
|
""" |
|
|
Intialisation of the CutPlane object |
|
|
""" |
|
|
|
|
|
|
|
|
class ClipPlane(Plane): |
|
|
""" |
|
|
Class for planes used to clip datasets |
|
|
""" |
|
|
|
|
|
def __init__(self): |
|
|
""" |
|
|
Intialisation of the ClipPlane object |
|
|
""" |
|
|
|
|
|
def setInsideOut(self, insideOut): |
|
|
""" |
|
|
Set the inside out flag |
|
|
""" |
|
|
|
|
|
def getInsideOut(self): |
|
|
""" |
|
|
Get the current value of the inside out flag |
|
|
""" |
|
|
|
|
|
class Plot(Item): |
|
|
""" |
|
|
Abstract plot class |
|
|
""" |
|
|
def __init__(self, scene): |
|
|
""" |
|
|
Initialisation of the abstract Plot class |
|
|
|
|
|
@param scene: The Scene to render the plot in |
|
|
@type scene: Scene object |
|
|
""" |
|
|
|
|
|
def setData(self, *dataList, **options): |
|
|
""" |
|
|
Set data to the plot |
|
|
|
|
|
@param dataList: List of data to set to the plot |
|
|
@type dataList: tuple |
|
|
|
|
|
@param options: Dictionary of extra options |
|
|
@type options: dict |
|
|
""" |
|
|
|
|
|
def setTitle(self, title): |
|
|
""" |
|
|
Set the plot title |
|
|
|
|
|
@param title: the string holding the title to the plot |
|
|
@type title: string |
|
|
""" |
|
|
debugMsg("Called setTitle() in Plot()") |
|
|
|
|
|
|
|
|
def setXLabel(self, label): |
|
|
""" |
|
|
Set the label of the x-axis |
|
|
|
|
|
@param label: the string holding the label of the x-axis |
|
|
@type label: string |
|
|
""" |
|
|
|
|
|
def setYLabel(self, label): |
|
|
""" |
|
|
Set the label of the y-axis |
|
|
|
|
|
@param label: the string holding the label of the y-axis |
|
|
@type label: string |
|
|
""" |
|
|
|
|
|
def setZLabel(self, label): |
|
|
""" |
|
|
Set the label of the z-axis |
|
|
|
|
|
@param label: the string holding the label of the z-axis |
|
|
@type label: string |
|
|
""" |
|
|
|
|
|
def setLabel(self, axis, label): |
|
|
""" |
|
|
Set the label of a given axis |
|
|
|
|
|
@param axis: string (Axis object maybe??) of the axis (e.g. x, y, z) |
|
|
@type axis: string or Axis object |
|
|
|
|
|
@param label: string of the label to set for the axis |
|
|
@type label: string |
|
|
""" |
|
|
|
|
|
class Renderer(BaseRenderer): |
|
|
""" |
|
|
A generic object holding a renderer of a Scene(). |
|
|
""" |
|
|
|
|
|
def __init__(self): |
|
|
""" |
|
|
Initialisation of Renderer() class |
|
|
""" |
|
|
debugMsg("Called Renderer.__init__()") |
|
|
BaseRenderer.__init__(self) |
|
|
|
|
|
# initialise some attributes |
|
|
self.renderWindowWidth = 640 |
|
|
self.renderWindowHeight = 480 |
|
|
|
|
|
# what is the name of my renderer? |
|
|
self.name = _rendererName |
|
|
|
|
|
# the namespace to run the exec code |
|
|
self.renderDict = {} |
|
|
|
|
|
# initialise the evalstack |
|
|
self._evalStack = "" |
|
|
|
|
|
# keep the initial setup of the module for later reuse |
|
|
self._initStack = "" |
|
|
|
|
|
# initialise the renderer module |
|
|
self.runString("# Renderer._initRendererModule") |
|
|
self.addToInitStack("import vtk") |
|
|
self.addToInitStack("from numarray import *") |
|
|
|
|
|
__revision__ = '$Revision: 1.33 $' |
|
|
|
|
|
class Scene(BaseScene): |
|
|
""" |
|
|
The main object controlling the scene. |
|
|
|
|
|
Scene object methods and classes overriding the BaseScene class. |
|
|
""" |
|
|
|
|
|
def __init__(self): |
|
|
""" |
|
|
The init function |
|
|
""" |
|
|
|
|
|
def add(self, obj): |
|
|
""" |
|
|
Add a new item to the scene |
|
|
|
|
|
@param obj: The object to add to the scene |
|
|
@type obj: object |
|
|
""" |
|
|
|
|
|
def place(self, obj): |
|
|
""" |
|
|
Place an object within a scene |
|
|
|
|
|
@param obj: The object to place within the scene |
|
|
@type obj: object |
|
|
""" |
|
|
|
|
|
def render(self, pause=False, interactive=False): |
|
|
""" |
|
|
Render (or re-render) the scene |
|
|
|
|
|
Render the scene, either to screen, or to a buffer waiting for a save |
|
|
|
|
|
@param pause: Flag to wait at end of script evaluation for user input |
|
|
@type pause: boolean |
|
162 |
|
|
|
@param interactive: Whether or not to have interactive use of the output |
|
|
@type interactive: boolean |
|
|
""" |
|
|
|
|
|
def save(self, fname, format): |
|
|
""" |
|
|
Save the scene to a file |
|
|
|
|
|
Possible formats are: |
|
|
- Postscript |
|
|
- PNG |
|
|
- JPEG |
|
|
- TIFF |
|
|
- BMP |
|
|
- PNM |
|
|
|
|
|
@param fname: Name of output file |
|
|
@type fname: string |
|
|
|
|
|
@param format: Graphics format of output file |
|
|
@type format: Image object or string |
|
|
""" |
|
|
|
|
|
def setBackgroundColor(self, *color): |
|
|
""" |
|
|
Sets the background color of the Scene |
|
|
|
|
|
@param color: The color to set the background to. Can be RGB or CMYK |
|
|
@type color: tuple |
|
|
""" |
|
|
|
|
|
def getBackgroundColor(self): |
|
|
""" |
|
|
Gets the current background color setting of the Scene |
|
|
""" |
|
|
|
|
|
def setSize(self, xSize, ySize): |
|
|
""" |
|
|
Sets the size of the scene. |
|
|
|
|
|
This size is effectively the renderer window size. |
|
|
|
|
|
@param xSize: the size to set the x dimension |
|
|
@type xSize: float |
|
|
|
|
|
@param ySize: the size to set the y dimension |
|
|
@type ySize: float |
|
|
""" |
|
|
|
|
|
def getSize(self): |
|
|
""" |
|
|
Gets the current size of the scene |
|
|
|
|
|
This size is effectively the renderer window size. Returns a tuple |
|
|
of the x and y dimensions respectively, in pixel units(??). |
|
|
""" |
|
|
class SurfacePlot(Plot): |
|
|
""" |
|
|
Surface plot |
|
|
""" |
|
|
def __init__(self, scene): |
|
|
""" |
|
|
Initialisation of the SurfacePlot class |
|
|
|
|
|
@param scene: The Scene to render the plot in |
|
|
@type scene: Scene object |
|
|
""" |
|
|
|
|
|
def setData(self, *dataList, **options): |
|
|
""" |
|
|
Set data to the plot |
|
|
|
|
|
@param dataList: List of data to set to the plot |
|
|
@type dataList: tuple |
|
|
|
|
|
@param options: Dictionary of extra options |
|
|
@type options: dict |
|
|
|
|
|
@param fname: the name of the input vtk file |
|
|
@type fname: string |
|
|
|
|
|
@param format: the format of the input vtk file ('vtk' or 'vtk-xml') |
|
|
@type format: string |
|
|
|
|
|
@param scalars: the scalar data in the vtk file to use |
|
|
@type scalars: string |
|
|
""" |
|
|
|
|
|
class Text(Item): |
|
|
""" |
|
|
Text |
|
|
""" |
|
|
def __init__(self, scene): |
|
|
""" |
|
|
Initialisation of the Text object |
|
|
|
|
|
@param scene: the scene with which to associate the Text object |
|
|
@type scene: Scene object |
|
|
""" |
|
|
|
|
|
def setFont(self, font): |
|
|
""" |
|
|
Set the current font |
|
|
|
|
|
@param font: the font to set |
|
|
@type font: string |
|
|
""" |
|
|
|
|
|
def getFont(self): |
|
|
""" |
|
|
\end{verbose} |
|