@@ -1455,28 +1455,58 @@ RendererAgg::draw_quad_mesh(const Py::Tuple& args) {
14551455 return Py::Object ();
14561456}
14571457
1458- Py::Object
1459- RendererAgg::draw_gouraud_triangle (const Py::Tuple& args) {
1460- _VERBOSE (" RendererAgg::draw_quad_mesh" );
1461- args.verify_length (4 );
1458+ void
1459+ RendererAgg::_draw_gouraud_triangle (const GCAgg& gc,
1460+ const double * points, const double * colors, agg::trans_affine trans) {
14621461
14631462 typedef agg::rgba8 color_t ;
14641463 typedef agg::span_gouraud_rgba<color_t > span_gen_t ;
14651464 typedef agg::span_allocator<color_t > span_alloc_t ;
14661465
1467- // segments, trans, clipbox, colors, linewidths, antialiaseds
1468- GCAgg gc (args[0 ], dpi);
1469- Py::Object points_obj = args[1 ];
1470- Py::Object colors_obj = args[2 ];
1471- agg::trans_affine trans = py_to_agg_transformation_matrix (args[3 ].ptr ());
1472-
14731466 theRasterizer.reset_clipping ();
14741467 rendererBase.reset_clipping (true );
14751468 set_clipbox (gc.cliprect , theRasterizer);
14761469
14771470 trans *= agg::trans_affine_scaling (1.0 , -1.0 );
14781471 trans *= agg::trans_affine_translation (0.0 , (double )height);
14791472
1473+ double tpoints[6 ];
1474+
1475+ for (int i = 0 ; i < 6 ; i += 2 ) {
1476+ tpoints[i] = points[i];
1477+ tpoints[i+1 ] = points[i+1 ];
1478+ trans.transform (&tpoints[i], &tpoints[i+1 ]);
1479+ }
1480+
1481+ span_alloc_t span_alloc;
1482+ span_gen_t span_gen;
1483+
1484+ span_gen.colors (
1485+ agg::rgba (colors[0 ], colors[1 ], colors[2 ], colors[3 ]),
1486+ agg::rgba (colors[4 ], colors[5 ], colors[6 ], colors[7 ]),
1487+ agg::rgba (colors[8 ], colors[9 ], colors[10 ], colors[11 ]));
1488+ span_gen.triangle (
1489+ tpoints[0 ], tpoints[1 ],
1490+ tpoints[2 ], tpoints[3 ],
1491+ tpoints[4 ], tpoints[5 ],
1492+ 0.5 );
1493+
1494+ theRasterizer.add_path (span_gen);
1495+ agg::render_scanlines_aa (
1496+ theRasterizer, slineP8, rendererBase, span_alloc, span_gen);
1497+ }
1498+
1499+ Py::Object
1500+ RendererAgg::draw_gouraud_triangle (const Py::Tuple& args) {
1501+ _VERBOSE (" RendererAgg::draw_gouraud_triangle" );
1502+ args.verify_length (4 );
1503+
1504+ // segments, trans, clipbox, colors, linewidths, antialiaseds
1505+ GCAgg gc (args[0 ], dpi);
1506+ Py::Object points_obj = args[1 ];
1507+ Py::Object colors_obj = args[2 ];
1508+ agg::trans_affine trans = py_to_agg_transformation_matrix (args[3 ].ptr ());
1509+
14801510 PyArrayObject* points = (PyArrayObject*)PyArray_ContiguousFromAny
14811511 (points_obj.ptr (), PyArray_DOUBLE, 2 , 2 );
14821512 if (!points ||
@@ -1490,32 +1520,57 @@ RendererAgg::draw_gouraud_triangle(const Py::Tuple& args) {
14901520 throw Py::ValueError (" colors must be a 3x4 numpy array" );
14911521
14921522 try {
1493- double * opoints = (double *)PyArray_DATA (points);
1494- double * c = (double *)PyArray_DATA (colors);
1495- double tpoints[6 ];
1496-
1497- for (int i = 0 ; i < 6 ; i += 2 ) {
1498- tpoints[i] = opoints[i];
1499- tpoints[i+1 ] = opoints[i+1 ];
1500- trans.transform (&tpoints[i], &tpoints[i+1 ]);
1501- }
1523+ _draw_gouraud_triangle (
1524+ gc, (double *)PyArray_DATA (points), (double *)PyArray_DATA (colors), trans);
1525+ } catch (...) {
1526+ Py_DECREF (points);
1527+ Py_DECREF (colors);
1528+
1529+ throw ;
1530+ }
1531+
1532+ Py_DECREF (points);
1533+ Py_DECREF (colors);
1534+
1535+ return Py::Object ();
1536+ }
15021537
1503- span_alloc_t span_alloc;
1504- span_gen_t span_gen;
1505-
1506- span_gen.colors (
1507- agg::rgba (c[0 ], c[1 ], c[2 ], c[3 ]),
1508- agg::rgba (c[4 ], c[5 ], c[6 ], c[7 ]),
1509- agg::rgba (c[8 ], c[9 ], c[10 ], c[11 ]));
1510- span_gen.triangle (
1511- tpoints[0 ], tpoints[1 ],
1512- tpoints[2 ], tpoints[3 ],
1513- tpoints[4 ], tpoints[5 ],
1514- 0.5 );
1515-
1516- theRasterizer.add_path (span_gen);
1517- agg::render_scanlines_aa (
1518- theRasterizer, slineP8, rendererBase, span_alloc, span_gen);
1538+ Py::Object
1539+ RendererAgg::draw_gouraud_triangles (const Py::Tuple& args) {
1540+ _VERBOSE (" RendererAgg::draw_gouraud_triangles" );
1541+ args.verify_length (4 );
1542+
1543+ typedef agg::rgba8 color_t ;
1544+ typedef agg::span_gouraud_rgba<color_t > span_gen_t ;
1545+ typedef agg::span_allocator<color_t > span_alloc_t ;
1546+
1547+ // segments, trans, clipbox, colors, linewidths, antialiaseds
1548+ GCAgg gc (args[0 ], dpi);
1549+ Py::Object points_obj = args[1 ];
1550+ Py::Object colors_obj = args[2 ];
1551+ agg::trans_affine trans = py_to_agg_transformation_matrix (args[3 ].ptr ());
1552+
1553+ PyArrayObject* points = (PyArrayObject*)PyArray_ContiguousFromAny
1554+ (points_obj.ptr (), PyArray_DOUBLE, 3 , 3 );
1555+ if (!points ||
1556+ PyArray_DIM (points, 1 ) != 3 || PyArray_DIM (points, 2 ) != 2 )
1557+ throw Py::ValueError (" points must be a Nx3x2 numpy array" );
1558+
1559+ PyArrayObject* colors = (PyArrayObject*)PyArray_ContiguousFromAny
1560+ (colors_obj.ptr (), PyArray_DOUBLE, 3 , 3 );
1561+ if (!colors ||
1562+ PyArray_DIM (colors, 1 ) != 3 || PyArray_DIM (colors, 2 ) != 4 )
1563+ throw Py::ValueError (" colors must be a Nx3x4 numpy array" );
1564+
1565+ if (PyArray_DIM (points, 0 ) != PyArray_DIM (colors, 0 )) {
1566+ throw Py::ValueError (" points and colors arrays must be the same length" );
1567+ }
1568+
1569+ try {
1570+ for (int i = 0 ; i < PyArray_DIM (points, 0 ); ++i) {
1571+ _draw_gouraud_triangle (
1572+ gc, (double *)PyArray_GETPTR1 (points, i), (double *)PyArray_GETPTR1 (colors, i), trans);
1573+ }
15191574 } catch (...) {
15201575 Py_DECREF (points);
15211576 Py_DECREF (colors);
@@ -1870,6 +1925,8 @@ void RendererAgg::init_type()
18701925 " draw_quad_mesh(gc, master_transform, meshWidth, meshHeight, coordinates, offsets, offsetTrans, facecolors, antialiaseds, showedges)\n " );
18711926 add_varargs_method (" draw_gouraud_triangle" , &RendererAgg::draw_gouraud_triangle,
18721927 " draw_gouraud_triangle(gc, points, colors, master_transform)\n " );
1928+ add_varargs_method (" draw_gouraud_triangles" , &RendererAgg::draw_gouraud_triangles,
1929+ " draw_gouraud_triangles(gc, points, colors, master_transform)\n " );
18731930 add_varargs_method (" draw_markers" , &RendererAgg::draw_markers,
18741931 " draw_markers(gc, marker_path, marker_trans, path, rgbFace)\n " );
18751932 add_varargs_method (" draw_text_image" , &RendererAgg::draw_text_image,
0 commit comments