Revision: 7630
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7630&view=rev
Author: mdboom
Date: 2009-09-02 20:48:06 +0000 (Wed, 02 Sep 2009)
Log Message:
-----------
Add Gouraud triangle support to PS backend.
Modified Paths:
--------------
trunk/matplotlib/lib/matplotlib/backends/backend_ps.py
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_ps.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_ps.py 2009-09-02
19:31:32 UTC (rev 7629)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_ps.py 2009-09-02
20:48:06 UTC (rev 7630)
@@ -754,6 +754,57 @@
""" % locals()
self._pswriter.write(ps)
+ def draw_gouraud_triangle(self, gc, points, colors, trans):
+ self.draw_gouraud_triangles(gc, points.reshape((1, 3, 2)),
+ colors.reshape((1, 3, 4)), trans)
+
+ def draw_gouraud_triangles(self, gc, points, colors, trans):
+ assert len(points) == len(colors)
+ assert points.ndim == 3
+ assert points.shape[1] == 3
+ assert points.shape[2] == 2
+ assert colors.ndim == 3
+ assert colors.shape[1] == 3
+ assert colors.shape[2] == 4
+
+ points = trans.transform(points)
+
+ shape = points.shape
+ flat_points = points.reshape((shape[0] * shape[1], 2))
+ flat_colors = colors.reshape((shape[0] * shape[1], 4))
+ points_min = npy.min(flat_points, axis=0) - (1 << 8)
+ points_max = npy.max(flat_points, axis=0) + (1 << 8)
+ factor = float(0xffffffff) / (points_max - points_min)
+
+ xmin, ymin = points_min
+ xmax, ymax = points_max
+
+ streamarr = npy.empty(
+ (shape[0] * shape[1],),
+ dtype=[('flags', 'u1'),
+ ('points', '>u4', (2,)),
+ ('colors', 'u1', (3,))])
+ streamarr['flags'] = 0
+ streamarr['points'] = (flat_points - points_min) * factor
+ streamarr['colors'] = flat_colors[:, :3] * 255.0
+
+ stream = quote_ps_string(streamarr.tostring())
+
+ self._pswriter.write("""
+gsave
+<< /ShadingType 4
+ /ColorSpace [/DeviceRGB]
+ /BitsPerCoordinate 32
+ /BitsPerComponent 8
+ /BitsPerFlag 8
+ /AntiAlias true
+ /Decode [ %(xmin)f %(xmax)f %(ymin)f %(ymax)f 0 1 0 1 0 1 ]
+ /DataSource (%(stream)s)
+>>
+shfill
+grestore
+""" % locals())
+
def _draw_ps(self, ps, gc, rgbFace, fill=True, stroke=True, command=None):
"""
Emit the PostScript sniplet 'ps' with all the attributes from 'gc'
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins