Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit db82b78

Browse files
committed
Refactor some backend methods for consistency and to reduce explosion of the number of arguments. A first crack at Gouraud shading in the Agg backend (not hooked up to anything).
svn path=/trunk/matplotlib/; revision=7417
1 parent 45634de commit db82b78

21 files changed

+342
-206
lines changed

CHANGELOG

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,41 @@
1+
2009-08-07 In an effort to simplify the backend API, all clipping rectangles
2+
and paths are now passed in using GraphicsContext objects, even
3+
on collections and images. Therefore:
4+
5+
draw_path_collection(self, master_transform, cliprect, clippath,
6+
clippath_trans, paths, all_transforms, offsets,
7+
offsetTrans, facecolors, edgecolors, linewidths,
8+
linestyles, antialiaseds, urls)
9+
10+
becomes:
11+
12+
draw_path_collection(self, gc, master_transform, paths, all_transforms,
13+
offsets, offsetTrans, facecolors, edgecolors,
14+
linewidths, linestyles, antialiaseds, urls)
15+
16+
17+
18+
draw_quad_mesh(self, master_transform, cliprect, clippath,
19+
clippath_trans, meshWidth, meshHeight, coordinates,
20+
offsets, offsetTrans, facecolors, antialiased,
21+
showedges)
22+
23+
becomes:
24+
25+
draw_quad_mesh(self, gc, master_transform, meshWidth, meshHeight,
26+
coordinates, offsets, offsetTrans, facecolors,
27+
antialiased, showedges)
28+
29+
30+
31+
draw_image(self, x, y, im, bbox, clippath=None, clippath_trans=None)
32+
33+
becomes:
34+
35+
draw_image(self, gc, x, y, im)
36+
37+
- MGD
38+
139
2009-08-06 Tagging the 0.99.0 release at svn r7397 - JDH
240

341
* fixed an alpha colormapping bug posted on sf 2832575
@@ -30,7 +68,6 @@
3068

3169
* apply sf patches 2830233 and 2823885 for osx setup and 64 bit; thanks Michiel
3270

33-
3471
2009-08-04 Made cbook.get_sample_data make use of the ETag and Last-Modified
3572
headers of mod_dav_svn. - JKS
3673

doc/api/api_changes.rst

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,43 @@ list may help describe what changes may be necessary in your code.
1818
.. _configobj: http://www.voidspace.org.uk/python/configobj.html
1919
.. _`enthought.traits`: http://code.enthought.com/projects/traits
2020

21+
Changes beyond 0.99.x
22+
=====================
23+
24+
In an effort to simplify the backend API, all clipping rectangles
25+
and paths are now passed in using GraphicsContext objects, even
26+
on collections and images. Therefore::
27+
28+
draw_path_collection(self, master_transform, cliprect, clippath,
29+
clippath_trans, paths, all_transforms, offsets,
30+
offsetTrans, facecolors, edgecolors, linewidths,
31+
linestyles, antialiaseds, urls)
32+
33+
# is now
34+
35+
draw_path_collection(self, gc, master_transform, paths, all_transforms,
36+
offsets, offsetTrans, facecolors, edgecolors,
37+
linewidths, linestyles, antialiaseds, urls)
38+
39+
40+
draw_quad_mesh(self, master_transform, cliprect, clippath,
41+
clippath_trans, meshWidth, meshHeight, coordinates,
42+
offsets, offsetTrans, facecolors, antialiased,
43+
showedges)
44+
45+
# is now
46+
47+
draw_quad_mesh(self, gc, master_transform, meshWidth, meshHeight,
48+
coordinates, offsets, offsetTrans, facecolors,
49+
antialiased, showedges)
50+
51+
52+
draw_image(self, x, y, im, bbox, clippath=None, clippath_trans=None)
53+
54+
# is now
55+
56+
draw_image(self, gc, x, y, im)
57+
2158
Changes in 0.99
2259
======================
2360

examples/pylab_examples/quadmesh_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from matplotlib import cm, colors
1212
from numpy import ma
1313

14-
n = 56
14+
n = 12
1515
x = np.linspace(-1.5,1.5,n)
1616
y = np.linspace(-1.5,1.5,n*2)
1717
X,Y = np.meshgrid(x,y);

lib/matplotlib/axes.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,12 +1705,14 @@ def draw(self, renderer=None, inframe=False):
17051705
l, b, w, h = self.bbox.bounds
17061706
# composite images need special args so they will not
17071707
# respect z-order for now
1708-
renderer.draw_image(
1709-
round(l), round(b), im, self.bbox,
1710-
self.patch.get_path(),
1711-
self.patch.get_transform())
17121708

1709+
gc = renderer.new_gc()
1710+
gc.set_clip_rectangle(self.bbox)
1711+
gc.set_clip_path(mtransforms.TransformedPath(
1712+
self.patch.get_path(),
1713+
self.patch.get_transform()))
17131714

1715+
renderer.draw_image(gc, round(l), round(b), im)
17141716

17151717
if dsu_rasterized:
17161718
for zorder, i, a in dsu_rasterized:

lib/matplotlib/backend_bases.py

Lines changed: 38 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -108,24 +108,23 @@ def draw_markers(self, gc, marker_path, marker_trans, path, trans, rgbFace=None)
108108
marker_trans + transforms.Affine2D().translate(x, y),
109109
rgbFace)
110110

111-
def draw_path_collection(self, master_transform, cliprect, clippath,
112-
clippath_trans, paths, all_transforms, offsets,
113-
offsetTrans, facecolors, edgecolors, linewidths,
114-
linestyles, antialiaseds, urls):
111+
def draw_path_collection(self, gc, master_transform, paths, all_transforms,
112+
offsets, offsetTrans, facecolors, edgecolors,
113+
linewidths, linestyles, antialiaseds, urls):
115114
"""
116-
Draws a collection of paths, selecting drawing properties from
115+
Draws a collection of paths selecting drawing properties from
117116
the lists *facecolors*, *edgecolors*, *linewidths*,
118117
*linestyles* and *antialiaseds*. *offsets* is a list of
119118
offsets to apply to each of the paths. The offsets in
120-
*offsets* are first transformed by *offsetTrans* before
121-
being applied.
119+
*offsets* are first transformed by *offsetTrans* before being
120+
applied.
122121
123122
This provides a fallback implementation of
124123
:meth:`draw_path_collection` that makes multiple calls to
125-
draw_path. Some backends may want to override this in order
126-
to render each set of path data only once, and then reference
127-
that path multiple times with the different offsets, colors,
128-
styles etc. The generator methods
124+
:meth:`draw_path`. Some backends may want to override this in
125+
order to render each set of path data only once, and then
126+
reference that path multiple times with the different offsets,
127+
colors, styles etc. The generator methods
129128
:meth:`_iter_collection_raw_paths` and
130129
:meth:`_iter_collection` are provided to help with (and
131130
standardize) the implementation across backends. It is highly
@@ -137,18 +136,16 @@ def draw_path_collection(self, master_transform, cliprect, clippath,
137136
master_transform, paths, all_transforms):
138137
path_ids.append((path, transform))
139138

140-
for xo, yo, path_id, gc, rgbFace in self._iter_collection(
141-
path_ids, cliprect, clippath, clippath_trans,
142-
offsets, offsetTrans, facecolors, edgecolors,
139+
for xo, yo, path_id, gc0, rgbFace in self._iter_collection(
140+
gc, path_ids, offsets, offsetTrans, facecolors, edgecolors,
143141
linewidths, linestyles, antialiaseds, urls):
144142
path, transform = path_id
145143
transform = transforms.Affine2D(transform.get_matrix()).translate(xo, yo)
146-
self.draw_path(gc, path, transform, rgbFace)
144+
self.draw_path(gc0, path, transform, rgbFace)
147145

148-
def draw_quad_mesh(self, master_transform, cliprect, clippath,
149-
clippath_trans, meshWidth, meshHeight, coordinates,
150-
offsets, offsetTrans, facecolors, antialiased,
151-
showedges):
146+
def draw_quad_mesh(self, gc, master_transform, meshWidth, meshHeight,
147+
coordinates, offsets, offsetTrans, facecolors,
148+
antialiased, showedges):
152149
"""
153150
This provides a fallback implementation of
154151
:meth:`draw_quad_mesh` that generates paths and then calls
@@ -166,11 +163,11 @@ def draw_quad_mesh(self, master_transform, cliprect, clippath,
166163
linewidths = np.array([0.0], np.float_)
167164

168165
return self.draw_path_collection(
169-
master_transform, cliprect, clippath, clippath_trans,
170-
paths, [], offsets, offsetTrans, facecolors, edgecolors,
171-
linewidths, [], [antialiased], [None])
166+
gc, master_transform, paths, [], offsets, offsetTrans, facecolors,
167+
edgecolors, linewidths, [], [antialiased], [None])
172168

173-
def _iter_collection_raw_paths(self, master_transform, paths, all_transforms):
169+
def _iter_collection_raw_paths(self, master_transform, paths,
170+
all_transforms):
174171
"""
175172
This is a helper method (along with :meth:`_iter_collection`) to make
176173
it easier to write a space-efficent :meth:`draw_path_collection`
@@ -200,9 +197,9 @@ def _iter_collection_raw_paths(self, master_transform, paths, all_transforms):
200197
transform = all_transforms[i % Ntransforms]
201198
yield path, transform + master_transform
202199

203-
def _iter_collection(self, path_ids, cliprect, clippath, clippath_trans,
204-
offsets, offsetTrans, facecolors, edgecolors,
205-
linewidths, linestyles, antialiaseds, urls):
200+
def _iter_collection(self, gc, path_ids, offsets, offsetTrans, facecolors,
201+
edgecolors, linewidths, linestyles, antialiaseds,
202+
urls):
206203
"""
207204
This is a helper method (along with
208205
:meth:`_iter_collection_raw_paths`) to make it easier to write
@@ -243,18 +240,14 @@ def _iter_collection(self, path_ids, cliprect, clippath, clippath_trans,
243240
if Noffsets:
244241
toffsets = offsetTrans.transform(offsets)
245242

246-
gc = self.new_gc()
247-
248-
gc.set_clip_rectangle(cliprect)
249-
if clippath is not None:
250-
clippath = transforms.TransformedPath(clippath, clippath_trans)
251-
gc.set_clip_path(clippath)
243+
gc0 = self.new_gc()
244+
gc0.copy_properties(gc)
252245

253246
if Nfacecolors == 0:
254247
rgbFace = None
255248

256249
if Nedgecolors == 0:
257-
gc.set_linewidth(0.0)
250+
gc0.set_linewidth(0.0)
258251

259252
xo, yo = 0, 0
260253
for i in xrange(N):
@@ -264,20 +257,20 @@ def _iter_collection(self, path_ids, cliprect, clippath, clippath_trans,
264257
if Nfacecolors:
265258
rgbFace = facecolors[i % Nfacecolors]
266259
if Nedgecolors:
267-
gc.set_foreground(edgecolors[i % Nedgecolors])
260+
gc0.set_foreground(edgecolors[i % Nedgecolors])
268261
if Nlinewidths:
269-
gc.set_linewidth(linewidths[i % Nlinewidths])
262+
gc0.set_linewidth(linewidths[i % Nlinewidths])
270263
if Nlinestyles:
271-
gc.set_dashes(*linestyles[i % Nlinestyles])
264+
gc0.set_dashes(*linestyles[i % Nlinestyles])
272265
if rgbFace is not None and len(rgbFace)==4:
273-
gc.set_alpha(rgbFace[-1])
266+
gc0.set_alpha(rgbFace[-1])
274267
rgbFace = rgbFace[:3]
275-
gc.set_antialiased(antialiaseds[i % Naa])
268+
gc0.set_antialiased(antialiaseds[i % Naa])
276269
if Nurls:
277-
gc.set_url(urls[i % Nurls])
270+
gc0.set_url(urls[i % Nurls])
278271

279-
yield xo, yo, path_id, gc, rgbFace
280-
gc.restore()
272+
yield xo, yo, path_id, gc0, rgbFace
273+
gc0.restore()
281274

282275
def get_image_magnification(self):
283276
"""
@@ -287,10 +280,13 @@ def get_image_magnification(self):
287280
"""
288281
return 1.0
289282

290-
def draw_image(self, x, y, im, bbox, clippath=None, clippath_trans=None):
283+
def draw_image(self, gc, x, y, im):
291284
"""
292285
Draw the image instance into the current axes;
293286
287+
*gc*
288+
a GraphicsContext containing clipping information
289+
294290
*x*
295291
is the distance in pixels from the left hand side of the canvas.
296292
@@ -301,11 +297,6 @@ def draw_image(self, x, y, im, bbox, clippath=None, clippath_trans=None):
301297
302298
*im*
303299
the :class:`matplotlib._image.Image` instance
304-
305-
*bbox*
306-
a :class:`matplotlib.transforms.Bbox` instance for clipping, or
307-
None
308-
309300
"""
310301
raise NotImplementedError
311302

lib/matplotlib/backends/backend_agg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def restore_region(self, region, bbox=None, xy=None):
250250
>>> x1, y1, x2, y2 = region.get_extents()
251251
>>> renderer.restore_region(region, bbox=(x1+dx, y1, x2, y2),
252252
xy=(x1-dx, y1))
253-
253+
254254
"""
255255
if bbox is not None or xy is not None:
256256
if bbox is None:

lib/matplotlib/backends/backend_cairo.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,12 @@ def draw_path(self, gc, path, transform, rgbFace=None):
151151

152152
self._fill_and_stroke(ctx, rgbFace, gc.get_alpha())
153153

154-
def draw_image(self, x, y, im, bbox, clippath=None, clippath_trans=None):
154+
def draw_image(self, gc, x, y, im):
155155
# bbox - not currently used
156156
if _debug: print '%s.%s()' % (self.__class__.__name__, _fn_name())
157157

158+
clippath, clippath_trans = gc.get_clip_path()
159+
158160
im.flipud_out()
159161

160162
rows, cols, buf = im.color_conv (BYTE_FORMAT)

lib/matplotlib/backends/backend_gdk.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ def draw_path(self, gc, path, transform, rgbFace=None):
9797
if gc.gdkGC.line_width > 0:
9898
self.gdkDrawable.draw_lines(gc.gdkGC, polygon)
9999

100-
def draw_image(self, x, y, im, bbox, clippath=None, clippath_trans=None):
100+
def draw_image(self, gc, x, y, im):
101+
bbox = gc.get_clip_rectangle()
102+
101103
if bbox != None:
102104
l,b,w,h = bbox.bounds
103105
#rectangle = (int(l), self.height-int(b+h),

0 commit comments

Comments
 (0)