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

Skip to content

Commit 133a95f

Browse files
committed
Add Gouraud triangle support to PS backend.
svn path=/trunk/matplotlib/; revision=7630
1 parent 89c1c26 commit 133a95f

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

lib/matplotlib/backends/backend_ps.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,57 @@ def draw_mathtext(self, gc,
754754
""" % locals()
755755
self._pswriter.write(ps)
756756

757+
def draw_gouraud_triangle(self, gc, points, colors, trans):
758+
self.draw_gouraud_triangles(gc, points.reshape((1, 3, 2)),
759+
colors.reshape((1, 3, 4)), trans)
760+
761+
def draw_gouraud_triangles(self, gc, points, colors, trans):
762+
assert len(points) == len(colors)
763+
assert points.ndim == 3
764+
assert points.shape[1] == 3
765+
assert points.shape[2] == 2
766+
assert colors.ndim == 3
767+
assert colors.shape[1] == 3
768+
assert colors.shape[2] == 4
769+
770+
points = trans.transform(points)
771+
772+
shape = points.shape
773+
flat_points = points.reshape((shape[0] * shape[1], 2))
774+
flat_colors = colors.reshape((shape[0] * shape[1], 4))
775+
points_min = npy.min(flat_points, axis=0) - (1 << 8)
776+
points_max = npy.max(flat_points, axis=0) + (1 << 8)
777+
factor = float(0xffffffff) / (points_max - points_min)
778+
779+
xmin, ymin = points_min
780+
xmax, ymax = points_max
781+
782+
streamarr = npy.empty(
783+
(shape[0] * shape[1],),
784+
dtype=[('flags', 'u1'),
785+
('points', '>u4', (2,)),
786+
('colors', 'u1', (3,))])
787+
streamarr['flags'] = 0
788+
streamarr['points'] = (flat_points - points_min) * factor
789+
streamarr['colors'] = flat_colors[:, :3] * 255.0
790+
791+
stream = quote_ps_string(streamarr.tostring())
792+
793+
self._pswriter.write("""
794+
gsave
795+
<< /ShadingType 4
796+
/ColorSpace [/DeviceRGB]
797+
/BitsPerCoordinate 32
798+
/BitsPerComponent 8
799+
/BitsPerFlag 8
800+
/AntiAlias true
801+
/Decode [ %(xmin)f %(xmax)f %(ymin)f %(ymax)f 0 1 0 1 0 1 ]
802+
/DataSource (%(stream)s)
803+
>>
804+
shfill
805+
grestore
806+
""" % locals())
807+
757808
def _draw_ps(self, ps, gc, rgbFace, fill=True, stroke=True, command=None):
758809
"""
759810
Emit the PostScript sniplet 'ps' with all the attributes from 'gc'

0 commit comments

Comments
 (0)