Py::Object RendererAgg::draw_regpoly_collection(const Py::Tuple& args) { theRasterizer->reset_clipping(); _VERBOSE("RendererAgg::draw_regpoly_collection"); args.verify_length(9); set_clip_from_bbox(args[0]); Py::SeqBase<Py::Object> offsets = args[1]; // this is throwing even though the instance is a Transformation! //if (!Transformation::check(args[2])) // throw Py::TypeError("RendererAgg::draw_regpoly_collection(clipbox, offsets, transOffset, verts, ...) expected a Transformation instance for transOffset"); Transformation* transOffset = static_cast<Transformation*>(args[2].ptr()); transOffset->eval_scalars(); Py::SeqBase<Py::Object> verts = args[3]; Py::SeqBase<Py::Object> sizes = args[4]; Py::SeqBase<Py::Object> facecolors = args[5]; Py::SeqBase<Py::Object> edgecolors = args[6]; Py::SeqBase<Py::Object> linewidths = args[7]; Py::SeqBase<Py::Object> antialiaseds = args[8]; size_t Noffsets = offsets.length(); size_t Nverts = verts.length(); size_t Nsizes = sizes.length(); size_t Nface = facecolors.length(); size_t Nedge = edgecolors.length(); size_t Nlw = linewidths.length(); size_t Naa = antialiaseds.length(); double thisx, thisy; // dump the x.y vertices into a double array for faster access double xverts[Nverts]; double yverts[Nverts]; Py::Tuple xy; for (size_t i=0; i<Nverts; ++i) { xy = Py::Tuple(verts[i]); xverts[i] = Py::Float(xy[0]); yverts[i] = Py::Float(xy[1]); } std::pair<double, double> offsetPair; for (size_t i=0; i<Noffsets; ++i) { Py::Tuple pos = Py::Tuple(offsets[i]); double xo = Py::Float(pos[0]); double yo = Py::Float(pos[1]); offsetPair = transOffset->operator()(xo, yo); double scale = Py::Float(sizes[i%Nsizes]); agg::path_storage path; for (size_t j=0; j<Nverts; ++j) { thisx = scale*xverts[j] + offsetPair.first; thisy = scale*yverts[j] + offsetPair.second; thisy = height - thisy; if (j==0) path.move_to(thisx, thisy); else path.line_to(thisx, thisy); } path.close_polygon(); int isaa = Py::Int(antialiaseds[i%Naa]); // get the facecolor and render Py::Tuple rgba = Py::Tuple(facecolors[ i%Nface]); double r = Py::Float(rgba[0]); double g = Py::Float(rgba[1]); double b = Py::Float(rgba[2]); double a = Py::Float(rgba[3]); if (a>0) { //only render if alpha>0 agg::rgba facecolor(r, g, b, a); theRasterizer->add_path(path); if (isaa) { rendererAA->color(facecolor); agg::render_scanlines(*theRasterizer, *slineP8, *rendererAA); } else { rendererBin->color(facecolor); agg::render_scanlines(*theRasterizer, *slineBin, *rendererBin); } } //renderer face // get the edgecolor and render rgba = Py::Tuple(edgecolors[ i%Nedge]); r = Py::Float(rgba[0]); g = Py::Float(rgba[1]); b = Py::Float(rgba[2]); a = Py::Float(rgba[3]); if (a>0) { //only render if alpha>0 agg::rgba edgecolor(r, g, b, a); agg::conv_stroke<agg::path_storage> stroke(path); //stroke.line_cap(cap); //stroke.line_join(join); double lw = points_to_pixels ( Py::Float( linewidths[i%Nlw] ) ); stroke.width(lw); theRasterizer->add_path(stroke); // render antialiased or not if ( isaa ) { rendererAA->color(edgecolor); agg::render_scanlines(*theRasterizer, *slineP8, *rendererAA); } else { rendererBin->color(edgecolor); agg::render_scanlines(*theRasterizer, *slineBin, *rendererBin); } } //rendered edge } // for every poly return Py::Object(); }
Py::Object RendererAgg::draw_poly_collection(const Py::Tuple& args) { theRasterizer->reset_clipping(); _VERBOSE("RendererAgg::draw_poly_collection"); args.verify_length(9); Py::SeqBase<Py::Object> verts = args[0]; //todo: fix transformation check Transformation* transform = static_cast<Transformation*>(args[1].ptr()); transform->eval_scalars(); set_clip_from_bbox(args[2]); Py::SeqBase<Py::Object> facecolors = args[3]; Py::SeqBase<Py::Object> edgecolors = args[4]; Py::SeqBase<Py::Object> linewidths = args[5]; Py::SeqBase<Py::Object> antialiaseds = args[6]; Py::SeqBase<Py::Object> offsets; Transformation* transOffset = NULL; bool usingOffsets = args[7].ptr() != Py_None; if (usingOffsets) { offsets = args[7]; //todo: fix transformation check transOffset = static_cast<Transformation*>(args[8].ptr()); transOffset->eval_scalars(); } size_t Noffsets = offsets.length(); size_t Nverts = verts.length(); size_t Nface = facecolors.length(); size_t Nedge = edgecolors.length(); size_t Nlw = linewidths.length(); size_t Naa = antialiaseds.length(); size_t N = (Noffsets>Nverts) ? Noffsets : Nverts; std::pair<double, double> xyo, xy; Py::Tuple thisverts; for (size_t i=0; i<N; ++i) { thisverts = verts[i % Nverts]; if (usingOffsets) { Py::Tuple pos = Py::Tuple(offsets[i]); double xo = Py::Float(pos[0]); double yo = Py::Float(pos[1]); xyo = transOffset->operator()(xo, yo); } size_t Nverts = thisverts.length(); agg::path_storage path; Py::Tuple thisvert; // dump the verts to double arrays so we can do more efficient // look aheads and behinds when doing snapto pixels double xs[Nverts], ys[Nverts]; for (size_t j=0; j<Nverts; ++j) { thisvert = Py::Tuple(thisverts[j]); double x = Py::Float(thisvert[0]); double y = Py::Float(thisvert[1]); xy = transform->operator()(x, y); if (usingOffsets) { xy.first += xyo.first; xy.second += xyo.second; } xy.second = height - xy.second; xs[j] = xy.first; ys[j] = xy.second; } for (size_t j=0; j<Nverts; ++j) { double x = xs[j]; double y = ys[j]; if (j==0) { if (xs[j] == xs[Nverts-1]) x = (int)xs[j] + 0.5; if (ys[j] == ys[Nverts-1]) y = (int)ys[j] + 0.5; } else if (j==Nverts-1) { if (xs[j] == xs[0]) x = (int)xs[j] + 0.5; if (ys[j] == ys[0]) y = (int)ys[j] + 0.5; } if (j < Nverts-1) { if (xs[j] == xs[j+1]) x = (int)xs[j] + 0.5; if (ys[j] == ys[j+1]) y = (int)ys[j] + 0.5; } if (j>0) { if (xs[j] == xs[j-1]) x = (int)xs[j] + 0.5; if (ys[j] == ys[j-1]) y = (int)ys[j] + 0.5; } if (j==0) path.move_to(x,y); else path.line_to(x,y); } path.close_polygon(); int isaa = Py::Int(antialiaseds[i%Naa]); // get the facecolor and render Py::Tuple rgba = Py::Tuple(facecolors[ i%Nface]); double r = Py::Float(rgba[0]); double g = Py::Float(rgba[1]); double b = Py::Float(rgba[2]); double a = Py::Float(rgba[3]); if (a>0) { //only render if alpha>0 agg::rgba facecolor(r, g, b, a); theRasterizer->add_path(path); if (isaa) { rendererAA->color(facecolor); agg::render_scanlines(*theRasterizer, *slineP8, *rendererAA); } else { rendererBin->color(facecolor); agg::render_scanlines(*theRasterizer, *slineBin, *rendererBin); } } //renderer face // get the edgecolor and render rgba = Py::Tuple(edgecolors[ i%Nedge]); r = Py::Float(rgba[0]); g = Py::Float(rgba[1]); b = Py::Float(rgba[2]); a = Py::Float(rgba[3]); if (a>0) { //only render if alpha>0 agg::rgba edgecolor(r, g, b, a); agg::conv_stroke<agg::path_storage> stroke(path); //stroke.line_cap(cap); //stroke.line_join(join); double lw = points_to_pixels ( Py::Float( linewidths[i%Nlw] ) ); stroke.width(lw); theRasterizer->add_path(stroke); // render antialiased or not if ( isaa ) { rendererAA->color(edgecolor); agg::render_scanlines(*theRasterizer, *slineP8, *rendererAA); } else { rendererBin->color(edgecolor); agg::render_scanlines(*theRasterizer, *slineBin, *rendererBin); } } //rendered edge } // for every poly return Py::Object(); }