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

Skip to content

Commit 87a1ae3

Browse files
committed
New version of Gouraud quadmesh shader with 4 triangles per quad.
svn path=/trunk/matplotlib/; revision=7478
1 parent dcf8645 commit 87a1ae3

3 files changed

Lines changed: 31 additions & 23 deletions

File tree

examples/pylab_examples/quadmesh_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#cmap.set_bad('r', 1.0)
3939
#ax.pcolormesh(Qx,Qz,Zm, cmap=cmap)
4040
# Or use the default, which is transparent:
41-
col = ax.pcolormesh(Qx,Qz,Zm)
41+
col = ax.pcolormesh(Qx,Qz,Zm,shading='gouraud')
4242
ax.set_title('With masked values')
4343

4444

lib/matplotlib/collections.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,40 +1132,44 @@ def convert_mesh_to_paths(meshWidth, meshHeight, coordinates):
11321132
def convert_mesh_to_triangles(self, meshWidth, meshHeight, coordinates):
11331133
"""
11341134
Converts a given mesh into a sequence of triangles, each point
1135-
with its own color
1136-
:class:`matplotlib.path.Path` objects for easier rendering by
1137-
backends that do not directly support quadmeshes.
1138-
1139-
This function is primarily of use to backend implementers.
1135+
with its own color. This is useful for experiments using
1136+
`draw_qouraud_triangle`.
11401137
"""
11411138
Path = mpath.Path
11421139

11431140
if ma.isMaskedArray(coordinates):
1144-
c = coordinates.data
1141+
p = coordinates.data
11451142
else:
1146-
c = coordinates
1143+
p = coordinates
1144+
1145+
p_a = p[0:-1, 0:-1]
1146+
p_b = p[0:-1, 1: ]
1147+
p_c = p[1: , 1: ]
1148+
p_d = p[1: , 0:-1]
1149+
p_center = (p_a + p_b + p_c + p_d) / 4.0
11471150

11481151
triangles = np.concatenate((
1149-
c[0:-1, 0:-1],
1150-
c[0:-1, 1: ],
1151-
c[1: , 1: ],
1152-
c[1: , 1: ],
1153-
c[1: , 0:-1],
1154-
c[0:-1, 0:-1]
1152+
p_a, p_b, p_center,
1153+
p_b, p_c, p_center,
1154+
p_c, p_d, p_center,
1155+
p_d, p_a, p_center,
11551156
), axis=2)
1156-
triangles = triangles.reshape((meshWidth * meshHeight * 2, 3, 2))
1157+
triangles = triangles.reshape((meshWidth * meshHeight * 4, 3, 2))
11571158

11581159
c = self.get_facecolor().reshape((meshHeight + 1, meshWidth + 1, 4))
1160+
c_a = c[0:-1, 0:-1]
1161+
c_b = c[0:-1, 1: ]
1162+
c_c = c[1: , 1: ]
1163+
c_d = c[1: , 0:-1]
1164+
c_center = (c_a + c_b + c_c + c_d) / 4.0
1165+
11591166
colors = np.concatenate((
1160-
c[0:-1, 0:-1],
1161-
c[0:-1, 1: ],
1162-
c[1: , 1: ],
1163-
c[1: , 1: ],
1164-
c[1: , 0:-1],
1165-
c[0:-1, 0:-1]
1167+
c_a, c_b, c_center,
1168+
c_b, c_c, c_center,
1169+
c_c, c_d, c_center,
1170+
c_d, c_a, c_center,
11661171
), axis=2)
1167-
1168-
colors = colors.reshape((meshWidth * meshHeight * 2, 3, 4))
1172+
colors = colors.reshape((meshWidth * meshHeight * 4, 3, 4))
11691173

11701174
return triangles, colors
11711175

src/_backend_agg.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,6 +1470,10 @@ RendererAgg::draw_gouraud_triangle(const Py::Tuple& args) {
14701470
Py::Object colors_obj = args[2];
14711471
agg::trans_affine trans = py_to_agg_transformation_matrix(args[3].ptr());
14721472

1473+
theRasterizer.reset_clipping();
1474+
rendererBase.reset_clipping(true);
1475+
set_clipbox(gc.cliprect, theRasterizer);
1476+
14731477
trans *= agg::trans_affine_scaling(1.0, -1.0);
14741478
trans *= agg::trans_affine_translation(0.0, (double)height);
14751479

0 commit comments

Comments
 (0)