Skip to content

Commit 28522e9

Browse files
authored
Merge branch 'master' into issue_2047_cdat_info
2 parents be11857 + b3b5576 commit 28522e9

File tree

8 files changed

+2858
-2296
lines changed

8 files changed

+2858
-2296
lines changed

Packages/vcs/vcs/Canvas.py

Lines changed: 1111 additions & 1355 deletions
Large diffs are not rendered by default.

Packages/vcs/vcs/VTKPlots.py

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -688,21 +688,16 @@ def plot(self, data1, data2, template, gtype, gname, bg, *args, **kargs):
688688
self.scaleLogo()
689689

690690
# Decide whether to rasterize background in vector outputs
691-
# Current criteria to rasterize:
691+
# Current limitation to vectorize:
692692
# * if fillarea style is either pattern or hatch
693-
# * if fillarea opacity is less than 100 for solid fill
694693
try:
695694
if gm.style and all(style != 'solid' for style in gm.style):
696695
self._rasterPropsInVectorFormats = True
697-
elif gm.opacity and not all(o == 100 for o in gm.opacity):
698-
self._rasterPropsInVectorFormats = True
699696
except:
700697
pass
701698
try:
702699
if gm.fillareastyle in ['pattern', 'hatch']:
703700
self._rasterPropsInVectorFormats = True
704-
elif not all(o == 100 for o in gm.fillareaopacity):
705-
self._rasterPropsInVectorFormats = True
706701
except:
707702
pass
708703

@@ -1109,6 +1104,7 @@ def vectorGraphics(self, output_type, file, width=None, height=None,
11091104

11101105
# Since the patterns are applied as textures on vtkPolyData, enabling
11111106
# background rasterization is required to write them out
1107+
11121108
if self._rasterPropsInVectorFormats:
11131109
gl.Write3DPropsAsRasterImageOn()
11141110

@@ -1117,9 +1113,10 @@ def vectorGraphics(self, output_type, file, width=None, height=None,
11171113
gl.SetFilePrefix(".".join(file.split(".")[:-1]))
11181114

11191115
if textAsPaths:
1120-
gl.TextAsPathOff()
1121-
else:
11221116
gl.TextAsPathOn()
1117+
else:
1118+
gl.TextAsPathOff()
1119+
11231120
if output_type == "svg":
11241121
gl.SetFileFormatToSVG()
11251122
elif output_type == "ps":
@@ -1243,7 +1240,38 @@ def Animate(self, *args, **kargs):
12431240
return VTKAnimate.VTKAnimate(*args, **kargs)
12441241

12451242
def gettextextent(self, textorientation, texttable):
1246-
warnings.warn("Please implement gettextextent for VTK Backend")
1243+
# Ensure renwin exists
1244+
self.createRenWin()
1245+
1246+
if isinstance(textorientation, (str, unicode)):
1247+
textorientation = vcs.gettextorientation(textorientation)
1248+
if isinstance(texttable, (str, unicode)):
1249+
texttable = vcs.gettexttable(texttable)
1250+
1251+
from vtk_ui.text import text_dimensions
1252+
1253+
text_property = vtk.vtkTextProperty()
1254+
info = self.canvasinfo()
1255+
win_size = info["width"], info["height"]
1256+
vcs2vtk.prepTextProperty(text_property, win_size, to=textorientation, tt=texttable)
1257+
1258+
dpi = self.renWin.GetDPI()
1259+
1260+
length = max(len(texttable.string), len(texttable.x), len(texttable.y))
1261+
1262+
strings = texttable.string + [texttable.string[-1]] * (length - len(texttable.string))
1263+
xs = texttable.x + [texttable.x[-1]] * (length - len(texttable.x))
1264+
ys = texttable.y + [texttable.y[-1]] * (length - len(texttable.y))
1265+
1266+
labels = zip(strings, xs, ys)
1267+
1268+
extents = []
1269+
1270+
for s, x, y in labels:
1271+
width, height = text_dimensions(s, text_property, dpi)
1272+
extents.append([x, x + float(width) / win_size[0], y, y + float(height) / win_size[1]])
1273+
1274+
return extents
12471275

12481276
def getantialiasing(self):
12491277
if self.renWin is None:
@@ -1553,3 +1581,9 @@ def png_dimensions(self, path):
15531581
img = reader.GetOutput()
15541582
size = img.GetDimensions()
15551583
return size[0], size[1]
1584+
1585+
def raisecanvas(self):
1586+
if self.renWin is None:
1587+
warnings.warn("Cannot raise if you did not open the canvas yet.")
1588+
return
1589+
self.renWin.MakeCurrent()

Packages/vcs/vcs/__init__.py

Lines changed: 77 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,48 @@
11
"""
2-
# VCS Visualization and Control System - (VCS) module
3-
#
4-
#################################################################################
5-
# #
6-
# Module: vcs module #
7-
# #
8-
# Authors: PCMDI Software Team #
9-
# support@pcmdi.llnl.gov #
10-
# http://cdat.sf.net/cdat #
11-
# #
12-
# Description: Python command wrapper for VCS's functionality. VCS is computer #
13-
# software for the selection, manipulation, and display of #
14-
# scientific data. By specification of the desired data, the #
15-
# graphics method, and the display template, the VCS user gains #
16-
# virtually complete control of the appearance of the data #
17-
# display and associated text and animation. #
18-
# #
19-
# Upgrade to VTK: #
20-
# Author: Charles Doutriaux #
21-
# Description: Took out all C code and used VTK's python bindings instead #
22-
# #
23-
#################################################################################
2+
=====================================
3+
VCS: Visualization and Control System
4+
=====================================
5+
6+
-------
7+
Authors
8+
-------
9+
10+
Creator: Dean Williams (LLNL, AIMS Team)
11+
12+
Lead Developer: Charles Doutriaux (LLNL, AIMS Team)
13+
14+
Contributors: https://github.com/UV-CDAT/uvcdat/graphs/contributors
15+
16+
Support Email: uvcdat-support@llnl.gov
17+
18+
Project Site: http://uvcdat.llnl.gov/
19+
20+
Project Repo: https://github.com/UV-CDAT/uvcdat/graphs/contributors
21+
22+
-----------
23+
Description
24+
-----------
25+
VCS is a visualization library for scientific data. It has a simple
26+
model for defining a plot, that is decomposed into three parts:
27+
28+
1. **Data**: If it's iterable, we'll plot it... or at least try!
29+
Currently we support numpy arrays, lists (nested and not),
30+
and CDMS2 variables (there's some special support for metadata
31+
from CDMS2 that gives some niceties in your plot, but it's not
32+
mandatory).
33+
2. **Graphics Method**: We have a variety of plot types that we
34+
support out-of-the box; you can easily customize every aspect
35+
of them to create the effect that you're looking for. If you can't,
36+
we also support defining your own graphics methods, which you can
37+
share with other users using standard python infrastructure (conda, pip).
38+
3. **Template**: Templates control the appearance of everything that
39+
*isn't* your data. They position labels, control fonts, adjust borders,
40+
place legends, and more. They're very flexible, and give the fine-grained
41+
control of your plot that is needed for the truly perfect plot. Once you've
42+
customized them, you can also save them out for later use, and distribute
43+
them to other users.
2444
"""
45+
2546
_doValidation = True
2647
next_canvas_id = 1
2748
import cdat_info # noqa
@@ -223,37 +244,45 @@
223244
vcs.scriptrun(user_init)
224245

225246
canvaslist = []
226-
#
227-
#
228-
# Construct a VCS Canvas Object. #
229-
#
230-
#
231247

232248

233249
def init(mode=1, pause_time=0, call_from_gui=0, size=None,
234250
backend="vtk", geometry=None, bg=None):
235251
'''
236-
Function: init # Initialize, Construct a VCS Canvas Object
237-
238-
Description of Function:
239-
Construct the VCS Canas object.
240-
241-
Example of Use:
242-
import vcs,cdms2
243-
244-
file=cdms2.open('filename.nc')
245-
slab=file.getslab('variable')
246-
a=vcs.init() # This examples constructs 4 VCS Canvas
247-
a.plot(slab) # Plot slab using default settings
248-
b=vcs.init() # Construct VCS object
249-
template=b.gettemplate('AMIP') # Get 'example' template object
250-
b.plot(slab,template) # Plot slab using template 'AMIP'
251-
c=vcs.init() # Construct new VCS object
252-
isofill=c.getisofill('quick') # Get 'quick' isofill graphics method
253-
c.plot(slab,template,isofill) # Plot slab using template and isofill objects
254-
d=vcs.init() # Construct new VCS object
255-
isoline=c.getisoline('quick') # Get 'quick' isoline graphics method
256-
c.plot(isoline,slab,template) # Plot slab using isoline and template objects
252+
Initialize and construct a VCS Canvas object.
253+
254+
:Example:
255+
256+
::
257+
258+
import vcs
259+
260+
# Portrait orientation of 1 width per 2 height
261+
portrait = vcs.init(size=.5)
262+
# also accepts "usletter"
263+
letter = vcs.init(size="letter")
264+
a4 = vcs.init(size="a4")
265+
266+
import vtk
267+
# Useful for embedding VCS inside another application
268+
my_win = vtk.vtkRenderWindow()
269+
embedded = vcs.init(backend=my_win)
270+
271+
dict_init = vcs.init(geometry={"width": 1200, "height": 600})
272+
tuple_init = vcs.init(geometry=(1200, 600))
273+
274+
bg_canvas = vcs.init(bg=True)
275+
276+
:param size: Aspect ratio for canvas (width / height)
277+
:param backend: Which VCS backend to use
278+
:param geometry: Size (in pixels) you want the canvas to be.
279+
:param bg: Initialize a canvas to render in "background" mode (without displaying a window)
280+
:type size: float or case-insensitive str
281+
:type backend: str, `vtk.vtkRenderWindow`
282+
:type geometry: dict or tuple
283+
:type bg: bool
284+
:return: an initialized canvas
285+
:rtype: `vcs.Canvas.Canvas`
257286
'''
258287
canvas = Canvas.Canvas(
259288
mode=mode,

0 commit comments

Comments
 (0)