void utils::SvgWriter::writeIaPath(const char* zone1Name, const char* zone2Name, float x, float y ) { if (svg().isActive(utils::Level::INFO)) { svg().info() << "</g>"<< utils::end; //symbols svg().info() << "<defs><symbol id=\"iaPath"<< zone1Name << "-" << zone2Name << "\" >" << "<circle cx='" << x << "' cy='" << y << "' r='15' fill='none' stroke='green' />" << "<text x='" << x + 30 << "' y='" << y + 10<< "' font-size='30' fill='green'>" << zone1Name << "-" << zone2Name << "</text>" << "</symbol></defs>" << utils::end; //en mode jaune puis rouge svg().info() << " <g transform=\"translate(200,2200)\"> <use x=\"0\" y=\"0\" xlink:href=\"#iaPath"<< zone1Name << "-" << zone2Name << "\" /> </g>" << " <g transform=\"translate(200,2200) scale(1,-1) \"> <use x=\"0\" y=\"0\" xlink:href=\"#iaPath"<< zone1Name << "-" << zone2Name << "\" /> </g>" << utils::end; svg().info() << "<g transform=\"translate(200,2200)\">" << utils::end; } }
static void svg_top_ten_cpu(void) { struct ps_struct *top[10]; struct ps_struct emptyps; struct ps_struct *ps; int n, m; memset(&emptyps, 0, sizeof(struct ps_struct)); for (n=0; n < 10; n++) top[n] = &emptyps; /* walk all ps's and setup ptrs */ ps = ps_first; while ((ps = get_next_ps(ps))) { for (n = 0; n < 10; n++) { if (ps->total <= top[n]->total) continue; /* cascade insert */ for (m = 9; m > n; m--) top[m] = top[m-1]; top[n] = ps; break; } } svg("<text class=\"t2\" x=\"20\" y=\"0\">Top CPU consumers:</text>\n"); for (n = 0; n < 10; n++) svg("<text class=\"t3\" x=\"20\" y=\"%d\">%3.03fs - %s[%d]</text>\n", 20 + (n * 13), top[n]->total, top[n]->name, top[n]->pid); }
void utils::SvgWriter::writeZone(const char* name, float minX, float minY, float width, float height, float startX, float startY, float startAngle ) //angle en radian { if (svg().isActive(utils::Level::INFO)) { svg().info() << "</g>"<< utils::end; //symbols svg().info() << "<defs><symbol id=\"iaZones"<< name << "\" ><rect x=\""<< minX << "\" y=\""<< minY <<"\" width=\""<< width<<"\" height=\""<< height <<"\" fill=\"none\" stroke=\"blue\" stroke-width=\"4\" />" "<circle cx='" << startX << "' cy='" << startY << "' r='3' fill='none' stroke='blue' />" << "<line x1 = \""<<startX<<"\" y1 = \""<<startY<<"\" x2 = \""<< startX + 25 * cos(startAngle)<<"\" y2 = \""<< startY + 25 * sin(startAngle)<< "\" stroke = \"blue\" stroke-width = \"4\"/>" << "<text x='" << startX + 30 << "' y='" << startY + 40<< "' font-size='30' fill='blue'>" << name << "</text>" << "</symbol></defs>" << utils::end; //en mode jaune puis rouge svg().info() << " <g transform=\"translate(200,2200)\"> <use x=\"0\" y=\"0\" xlink:href=\"#iaZones"<< name << "\" /> </g>" << " <g transform=\"translate(200,2200) scale(1,-1) \"> <use x=\"0\" y=\"0\" xlink:href=\"#iaZones"<< name << "\" /> </g>" << utils::end; svg().info() << "<g transform=\"translate(200,2200)\">" << utils::end; } }
void utils::SvgWriter::writePawn(double x, double y) { if (svg().isActive(utils::Level::INFO)) { // inversion du y pour affichage dans le bon sens dans le SVG svg().info() << "<circle cx='" << x << "' cy='" << -y << "' r='100' fill='green' stroke='yellow' />" << utils::end; } }
void utils::SvgWriter::writeTextCustom(double x, double y, std::string text, std::string color, std::string fontsize) { if (svg().isActive(utils::Level::INFO)) { // inversion du y pour affichage dans le bon sens dans le SVG svg().info() << "<text x='" << x << "' y='" << -y << "' font-size='" << fontsize << "' fill='" << color << "'>" << text << "</text>" << utils::end; } }
void test_intersects(int count_x, int count_y, int width_x, p_q_settings const& settings) { MultiPolygon mp; make_polygon(mp, count_x, count_y, 0, width_x); bool const b = bg::intersects(mp); if (b) { std::cout << " YES"; } if(settings.svg) { typedef typename bg::coordinate_type<MultiPolygon>::type coordinate_type; typedef typename bg::point_type<MultiPolygon>::type point_type; std::ostringstream filename; filename << "intersects_" << string_from_type<coordinate_type>::name() << ".svg"; std::ofstream svg(filename.str().c_str()); bg::svg_mapper<point_type> mapper(svg, 500, 500); mapper.add(mp); mapper.map(mp, "fill-opacity:0.5;fill:rgb(153,204,0);" "stroke:rgb(153,204,0);stroke-width:3"); } }
int main() { // Specify the basic type typedef boost::geometry::model::d2::point_xy<double> point_type; // Declare some geometries and set their values point_type a; boost::geometry::assign_values(a, 3, 6); boost::geometry::model::polygon<point_type> b; boost::geometry::read_wkt("POLYGON((0 0,0 7,4 2,2 0,0 0))", b); boost::geometry::model::linestring<point_type> c; c.push_back(point_type(3, 4)); c.push_back(point_type(4, 5)); // Declare a stream and an SVG mapper std::ofstream svg("my_map.svg"); boost::geometry::svg_mapper<point_type> mapper(svg, 400, 400); // Add geometries such that all these geometries fit on the map mapper.add(a); mapper.add(b); mapper.add(c); // Draw the geometries on the SVG map, using a specific SVG style mapper.map(a, "fill-opacity:0.5;fill:rgb(153,204,0);stroke:rgb(153,204,0);stroke-width:2", 5); mapper.map(b, "fill-opacity:0.3;fill:rgb(51,51,153);stroke:rgb(51,51,153);stroke-width:2"); mapper.map(c, "opacity:0.4;fill:none;stroke:rgb(212,0,0);stroke-width:5"); // Destructor of map will be called - adding </svg> // Destructor of stream will be called, closing the file return 0; }
void svg_simplify_country() { typedef boost::geometry::point_xy<double> point_type; std::ofstream svg("simplify_country.svg"); svg_mapper<point_type> mapper(svg, 300, 300); boost::geometry::multi_polygon<boost::geometry::polygon<point_type> > original[wkt_countries_count] , simplified[wkt_countries_count]; for (int i = 0; i < wkt_countries_count; i++) { boost::geometry::read_wkt(wkt_countries[i], original[i]); boost::geometry::simplify(original[i], simplified[i], 0.1); mapper.add(original[i]); mapper.add(simplified[i]); std::cout << "original: " << boost::geometry::num_points(original[i]) << " simplified: " << boost::geometry::num_points(simplified[i]) << std::endl; } for (int i = 0; i < wkt_countries_count; i++) { mapper.map(original[i], "opacity:0.8;fill:none;stroke:rgb(0,0,255);stroke-width:3"); mapper.map(simplified[i], "opacity:0.8;fill:none;stroke:rgb(0,255,0);stroke-width:2"); } }
Py::Object removeSvgTags(const Py::Tuple& args) { const char* svgcode; if (!PyArg_ParseTuple(args.ptr(), "s",&svgcode)) throw Py::Exception(); std::string svg(svgcode); std::string empty = ""; std::string endline = "--endOfLine--"; std::string linebreak = "\\n"; // removing linebreaks for regex to work boost::regex e1 ("\\n"); svg = boost::regex_replace(svg, e1, endline); // removing starting xml definition boost::regex e2 ("<\\?xml.*?\\?>"); svg = boost::regex_replace(svg, e2, empty); // removing starting svg tag boost::regex e3 ("<svg.*?>"); svg = boost::regex_replace(svg, e3, empty); // removing sodipodi tags -- DANGEROUS, some sodipodi tags are single, better leave it //boost::regex e4 ("<sodipodi.*?>"); //svg = boost::regex_replace(svg, e4, empty); // removing metadata tags boost::regex e5 ("<metadata.*?</metadata>"); svg = boost::regex_replace(svg, e5, empty); // removing closing svg tags boost::regex e6 ("</svg>"); svg = boost::regex_replace(svg, e6, empty); // restoring linebreaks boost::regex e7 ("--endOfLine--"); svg = boost::regex_replace(svg, e7, linebreak); Py::String result(svg); return result; }
std::string getSvg(const ShapeCollection &collection) { std::string svg( "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n" "<svg xmlns=\"http://www.w3.org/2000/svg\"\n" "xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:ev=\"http://www.w3.org/2001/xml-events\"\n" "version=\"1.1\" baseProfile=\"full\"\n"); svg += "width=\"800mm\" height=\"600mm\">\n"; for (const Shape &shape : collection.shapes) { svg += "<polygon points=\""; for (const std::array<float, 2> &pt : shape.polygon) { svg += std::to_string(static_cast<int>(pt[0])) + " "; svg += std::to_string(static_cast<int>(pt[1])) + " "; } svg.erase(--svg.end()); //svgString += QString("\" fill=\"rgb(%1,%2,%3)\" opacity=\"%4\" />\n") svg += "\" fill=\"rgb("; for (int i = 0; i < 3; i++) { svg += std::to_string(shape.rgba[i]) + (i < 2 ? "," : ""); } svg += ")\" opacity=\""; svg += std::to_string(shape.rgba[3] / 255.f); if (*svg.rbegin() == ' ') { svg.erase(--svg.end()); } svg += "\" />\n"; } svg += "</svg>\n"; return svg; }
void svg_convex_hull_cities() { typedef boost::geometry::point_xy<double> point_type; std::ofstream svg("convex_hull_cities.svg"); svg_mapper<point_type> mapper(svg, 300, 300); boost::geometry::multi_point<point_type> original[wkt_cities_count]; boost::geometry::linear_ring<point_type> hull[wkt_cities_count]; for (int i = 0; i < wkt_cities_count; i++) { boost::geometry::read_wkt(wkt_cities[i], original[i]); boost::geometry::convex_hull_inserter(original[i], std::back_inserter(hull[i])); mapper.add(original[i]); mapper.add(hull[i]); std::cout << "original: " << boost::geometry::num_points(original[i]) << " hull: " << boost::geometry::num_points(hull[i]) << std::endl; } for (int i = 0; i < wkt_cities_count; i++) { mapper.map(original[i], "fill:rgb(255,255,0);stroke:rgb(0,0,100);stroke-width:1", 3); mapper.map(hull[i], "opacity:0.8;fill:none;stroke:rgb(255,0,0);stroke-width:3"); } }
void TrackDashboard::paintEvent( QPaintEvent* e ) { QPainter p( this ); p.setClipRect( e->rect() ); p.setPen( QColor( 0x161616 ) ); p.drawLine( 0, 0, width(), 0 ); p.setPen( QColor( 0x101010 ) ); p.drawLine( 0, 1, width(), 1 ); if (!m_track.isNull()) return; p.setClipRect( e->rect() ); p.setRenderHint( QPainter::Antialiasing ); p.setRenderHint( QPainter::SmoothPixmapTransform ); QSvgRenderer svg( QString(":/lastfm/as.svg") ); QSize s = svg.defaultSize() * 5; s.scale( 120, 0, Qt::KeepAspectRatioByExpanding ); QRect r = QRect( rect().center() - QRect( QPoint(), s ).center(), s ); p.setOpacity( qreal(40)/255 ); svg.render( &p, r ); }
std::string Toolkit::RenderToSvg( int pageNo, bool xml_declaration ) { // Page number is one-based - correction to 0-based first pageNo--; // Get the current system for the SVG clipping size m_view.SetPage( pageNo ); // Adjusting page width and height according to the options int width = m_pageWidth; if ( m_noLayout ) { width = m_doc.GetAdjustedDrawingPageWidth(); } int height = m_pageHeight; if ( m_adjustPageHeight || m_noLayout ) { height = m_doc.GetAdjustedDrawingPageHeight(); } // Create the SVG object, h & w come from the system // We will need to set the size of the page after having drawn it depending on the options SvgDeviceContext svg( width, height ); // set scale and border from user options svg.SetUserScale((double)m_scale / 100, (double)m_scale / 100); // debug BB? svg.SetDrawBoundingBoxes(m_showBoundingBoxes); // render the page m_view.DrawCurrentPage( &svg, false ); std::string out_str = svg.GetStringSVG( xml_declaration ); return out_str; }
void create_svg(std::string const& filename , Geometry1 const& mp , Geometry2 const& buffer ) { typedef typename boost::geometry::point_type<Geometry1>::type point_type; std::ofstream svg(filename.c_str()); boost::geometry::svg_mapper<point_type> mapper(svg, 800, 800); boost::geometry::model::box<point_type> box; bg::envelope(mp, box); bg::buffer(box, box, 1.0); mapper.add(box); if (bg::num_points(buffer) > 0) { bg::envelope(buffer, box); bg::buffer(box, box, 1.0); mapper.add(box); } mapper.map(mp, "fill-opacity:0.5;fill:rgb(153,204,0);stroke:rgb(153,204,0);stroke-width:3"); mapper.map(buffer, "stroke-opacity:0.9;stroke:rgb(0,0,0);fill:none;stroke-width:1"); //mapper.map(intersection,"opacity:0.6;stroke:rgb(0,128,0);stroke-width:5"); }
void test_geometry(std::string const& id, std::string const& wkt, double expected_area, double expected_perimeter) { Geometry geometry; bg::read_wkt(wkt, geometry); bg::correct(geometry); boost::variant<Geometry> v(geometry); #if defined(TEST_WITH_SVG) std::ostringstream filename; filename << "remove_spikes_" << id; if (! bg::closure<Geometry>::value) { filename << "_open"; } filename << ".svg"; std::ofstream svg(filename.str().c_str()); bg::svg_mapper<typename bg::point_type<Geometry>::type> mapper(svg, 500, 500); mapper.add(geometry); mapper.map(geometry, "fill-opacity:0.3;opacity:0.6;fill:rgb(51,51,153);stroke:rgb(0,0,255);stroke-width:2"); #endif test_remove_spikes(id, geometry, expected_area, expected_perimeter); test_remove_spikes(id, v, expected_area, expected_perimeter); #if defined(TEST_WITH_SVG) mapper.map(geometry, "opacity:0.6;fill:none;stroke:rgb(255,0,0);stroke-width:3"); #endif }
void SVG::export_expolygons(const char *path, const BoundingBox &bbox, const Slic3r::ExPolygons &expolygons, std::string stroke_outer, std::string stroke_holes, coordf_t stroke_width) { SVG svg(path, bbox); svg.draw(expolygons); svg.draw_outline(expolygons, stroke_outer, stroke_holes, stroke_width); svg.Close(); }
void SdLostFoundMsgSupportCanvas::draw(QPainter & p) { if (! visible()) return; QRect r = rect(); if (selected()) p.fillRect(r, ::Qt::black); else { QBrush brsh = p.brush(); p.setBrush(::Qt::black); p.drawEllipse(r.left(), r.top(), LOSTFOUND_SIZE, LOSTFOUND_SIZE); p.setBrush(brsh); } FILE * fp = svg(); if (fp != 0) { const float rr = LOSTFOUND_SIZE / (float) 2.0; fprintf(fp, "<ellipse fill=\"black\" stroke=\"none\" cx=\"%g\" cy=\"%g\" rx=\"%g\" ry=\"%g\" />\n", (float)(r.left() + rr), (float)(r.top() + rr), rr, rr); } // don't use show_mark is selected : too small }
void ParameterSetCanvas::draw(QPainter & p) { if (! visible()) return; QBrush brsh = p.brush(); QColor bckgrnd = p.backgroundColor(); p.setBackgroundMode((used_color == UmlTransparent) ? ::Qt::TransparentMode : ::Qt::OpaqueMode); QColor co = color(used_color); QRect r = rect(); FILE * fp = svg(); p.setBackgroundColor(co); if (used_color != UmlTransparent) p.setBrush(co); if (fp != 0) fprintf(fp, "<g>\n" "\t<rect fill=\"%s\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\"" " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n" "</g>\n", svg_color(used_color), r.x(), r.y(), r.width() - 1, r.height() - 1); p.drawRect(r); p.setBackgroundColor(bckgrnd); p.setBrush(brsh); if (selected()) show_mark(p, r); }
void hullBoost(polygon& poly1, std::string path) { polygon poly_hull; boost::geometry::convex_hull(poly1, poly_hull); std::ofstream svg(path.c_str()); boost::geometry::svg_mapper<point_type> mapper_hull(svg, 400, 400); SVGCreater(poly_hull, mapper_hull, "77,200,42"); }
void ArrowJunctionCanvas::draw(QPainter & p) { if (!visible()) return; ArrowCanvas * a; FILE * fp = svg(); for (a = lines.first(); a != 0; a = lines.next()) { switch (a->type()) { case UmlRequired: { QRect r = rect(); int wh = r.width() - 2; int startangle = a->get_point(1).x(); // degree * 16 p.drawArc(r.x() + 1, r.y() + 1, wh, wh, startangle, 180 * 16); if (fp != 0) { int radius = r.width() / 2; QPoint ce = r.center(); double r_startangle = startangle * 3.1415927 / 180 / 16; double dx = cos(r_startangle) * radius; double dy = sin(r_startangle) * radius; fprintf(fp, "<path fill=\"none\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" d=\"M%lg,%lg a%d,%d 0 0,1 %lg,%lg\" />\n", ce.x() - dx, ce.y() + dy, radius, radius, dx + dx, -dy - dy); } } break; case UmlProvided: p.drawPixmap(QPoint((int) x(), (int) y()), *providedPixmap); if (fp != 0) fprintf(fp, "<ellipse fill=\"none\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" cx=\"%d\" cy=\"%d\" rx=\"%d\" ry=\"%d\" />\n", // 4 is the margin inside the pixmap (int)(x() + PROVIDED_RADIUS + 4), (int)(y() + PROVIDED_RADIUS + 4), (int) PROVIDED_RADIUS, (int) PROVIDED_RADIUS); break; default: // to avoid compiler warning break; } } if (selected()) show_mark(p, rect()); }
void simplifyPolygon(polygon& poly1, double simplify_coefficient, std::string path) { polygon simplified_polygon; boost::geometry::simplify(poly1, simplified_polygon, simplify_coefficient); std::ofstream svg(path.c_str()); boost::geometry::svg_mapper<point_type> mapper_simplify(svg, 400, 400); SVGCreater(simplified_polygon, mapper_simplify, "17,20,92"); }
static void svg_entropy_bar(void) { int i; svg("<!-- entropy pool graph -->\n"); svg("<text class=\"t2\" x=\"5\" y=\"-15\">Entropy pool size</text>\n"); /* surrounding box */ svg_graph_box(5); /* bars for each sample, scale 0-4096 */ for (i = 1; i < samples; i++) { /* svg("<!-- entropy %.03f %i -->\n", sampletime[i], entropy_avail[i]); */ svg("<rect class=\"cpu\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n", time_to_graph(sampletime[i - 1] - graph_start), ((arg_scale_y * 5) - ((entropy_avail[i] / 4096.) * (arg_scale_y * 5))), time_to_graph(sampletime[i] - sampletime[i - 1]), (entropy_avail[i] / 4096.) * (arg_scale_y * 5)); } }
double test_growth(Geometry const& geometry, int n, int d, double distance) { typedef typename bg::coordinate_type<Geometry>::type coordinate_type; typedef typename bg::point_type<Geometry>::type point_type; // extern int point_buffer_count; std::ostringstream complete; complete << "point_growth" << "_" << "r" << "_" << n << "_" << d // << "_" << point_buffer_count ; //std::cout << complete.str() << std::endl; std::ostringstream filename; filename << "buffer_" << complete.str() << ".svg"; std::ofstream svg(filename.str().c_str()); #ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER bg::svg_mapper<point_type> mapper(svg, 500, 500); { bg::model::box<point_type> box; bg::envelope(geometry, box); bg::buffer(box, box, distance * 1.01); mapper.add(box); } #endif bg::strategy::buffer::join_round join_strategy(100); bg::strategy::buffer::end_flat end_strategy; bg::strategy::buffer::point_circle point_strategy; bg::strategy::buffer::side_straight side_strategy; typedef bg::strategy::buffer::distance_symmetric<coordinate_type> distance_strategy_type; distance_strategy_type distance_strategy(distance); std::vector<GeometryOut> buffered; bg::buffer(geometry, buffered, distance_strategy, side_strategy, join_strategy, end_strategy, point_strategy); typename bg::default_area_result<GeometryOut>::type area = 0; BOOST_FOREACH(GeometryOut const& polygon, buffered) { area += bg::area(polygon); }
static void apply(std::string const& id, boost::tuple<int, std::string> const& expected_count_and_center, G1 const& g1, G2 const& g2, double precision) { //std::cout << "#" << id << std::endl; typedef bg::detail::intersection::intersection_point <typename bg::point_type<G2>::type> ip; typedef typename boost::range_const_iterator<std::vector<ip> >::type iterator; std::vector<ip> ips; bg::get_intersection_points(g1, g2, ips); bg::merge_intersection_points(ips); bg::enrich_intersection_points(ips, true); std::ostringstream out; out << std::setprecision(2); bool first = true; for (iterator it = boost::begin(ips); it != boost::end(ips); ++it, first = false) { out << (first ? "" : ","); for (unsigned int i = 0; i < it->info.size(); i++) { out << dir(it->info[i].direction); } } int n = boost::size(ips); //std::cout << n << " " << out.str() << std::endl; BOOST_CHECK_EQUAL(expected_count_and_center.get<0>(), n); BOOST_CHECK_EQUAL(expected_count_and_center.get<1>(), out.str()); #if defined(TEST_WITH_SVG) { std::ostringstream filename; filename << "enrich_ip" << id << ".svg"; std::ofstream svg(filename.str().c_str()); bg::svg_mapper<typename bg::point_type<G2>::type> mapper(svg, 500, 500); mapper.add(g1); mapper.add(g2); mapper.map(g1, "fill:rgb(0,255,0);stroke:rgb(0,0,0);stroke-width:1"); mapper.map(g2, "opacity:0.8;fill:rgb(0,0,255);stroke:rgb(0,0,0);stroke-width:1"); for (iterator it = boost::begin(ips); it != boost::end(ips); ++it) { mapper.map(it->point, "fill:rgb(255,128,0);stroke:rgb(0,0,100);stroke-width:1"); } } #endif }
void test_offset(std::string const& caseid, Geometry const& geometry, double distance, double expected_length, double percentage) { typedef typename bg::coordinate_type<Geometry>::type coordinate_type; typedef typename bg::point_type<Geometry>::type point_type; typedef bg::strategy::buffer::join_round < point_type, point_type > join_strategy; GeometryOut moved_by_offset; bg::offset(geometry, moved_by_offset, join_strategy(2), distance); typename bg::default_length_result<Geometry>::type length = bg::length(moved_by_offset); /* std::size_t count = bg::num_points(moved_by_offset); BOOST_CHECK_MESSAGE(count == expected_point_count, "offset: " << caseid << " #points expected: " << expected_point_count << " detected: " << count << " type: " << string_from_type<coordinate_type>::name() ); */ //BOOST_CHECK_EQUAL(holes, expected_hole_count); BOOST_CHECK_CLOSE(length, expected_length, percentage); #if defined(TEST_WITH_SVG) { std::ostringstream filename; filename << "offset_" << caseid << "_" << string_from_type<coordinate_type>::name() << ".svg"; std::ofstream svg(filename.str().c_str()); bg::svg_mapper < typename bg::point_type<Geometry>::type > mapper(svg, 500, 500); mapper.add(geometry); mapper.add(moved_by_offset); mapper.map(geometry, "opacity:0.6;fill:rgb(0,0,255);stroke:rgb(0,0,0);stroke-width:1"); mapper.map(moved_by_offset, "opacity:0.6;fill:none;stroke:rgb(255,0,0);stroke-width:5"); } #endif }
int main(void) { namespace bg = boost::geometry; typedef bg::model::d2::point_xy<double> point_2d; typedef bg::model::polygon<point_2d> polygon_2d; #if defined(HAVE_SVG) std::ofstream stream("05_a_intersection_polygon_example.svg"); bg::svg_mapper<point_2d> svg(stream, 500, 500); #endif // Define a polygons and fill the outer rings. polygon_2d a; { const double c[][2] = { {160, 330}, {60, 260}, {20, 150}, {60, 40}, {190, 20}, {270, 130}, {260, 250}, {160, 330} }; bg::assign_points(a, c); } bg::correct(a); std::cout << "A: " << bg::dsv(a) << std::endl; polygon_2d b; { const double c[][2] = { {300, 330}, {190, 270}, {150, 170}, {150, 110}, {250, 30}, {380, 50}, {380, 250}, {300, 330} }; bg::assign_points(b, c); } bg::correct(b); std::cout << "B: " << bg::dsv(b) << std::endl; #if defined(HAVE_SVG) svg.add(a); svg.add(b); svg.map(a, "opacity:0.6;fill:rgb(0,255,0);"); svg.map(b, "opacity:0.6;fill:rgb(0,0,255);"); #endif // Calculate interesection(s) std::vector<polygon_2d> intersection; bg::intersection(a, b, intersection); std::cout << "Intersection of polygons A and B" << std::endl; BOOST_FOREACH(polygon_2d const& polygon, intersection) { std::cout << bg::dsv(polygon) << std::endl; #if defined(HAVE_SVG) svg.map(polygon, "opacity:0.5;fill:none;stroke:rgb(255,0,0);stroke-width:6"); #endif }
void offset2(const Slic3r::Polygons &polygons, ClipperLib::Paths* retval, const float delta1, const float delta2, const ClipperLib::JoinType joinType, const double miterLimit) { if (delta1 * delta2 >= 0) { // Both deltas are the same signum offset(polygons, retval, delta1 + delta2, joinType, miterLimit); return; } #ifdef CLIPPER_UTILS_DEBUG BoundingBox bbox = get_extents(polygons); coordf_t stroke_width = scale_(0.005); static int iRun = 0; ++ iRun; bool flipY = false; SVG svg(debug_out_path("offset2-%d.svg", iRun), bbox, scale_(1.), flipY); for (Slic3r::Polygons::const_iterator it = polygons.begin(); it != polygons.end(); ++ it) svg.draw(it->lines(), "gray", stroke_width); #endif /* CLIPPER_UTILS_DEBUG */ // read input ClipperLib::Paths input; Slic3rMultiPoints_to_ClipperPaths(polygons, &input); // scale input scaleClipperPolygons(input); // prepare ClipperOffset object ClipperLib::ClipperOffset co; if (joinType == jtRound) { co.ArcTolerance = miterLimit * double(CLIPPER_OFFSET_SCALE); } else { co.MiterLimit = miterLimit; } // perform first offset ClipperLib::Paths output1; co.AddPaths(input, joinType, ClipperLib::etClosedPolygon); co.Execute(output1, delta1 * float(CLIPPER_OFFSET_SCALE)); #ifdef CLIPPER_UTILS_DEBUG svg.draw(output1, 1. / double(CLIPPER_OFFSET_SCALE), "red", stroke_width); #endif /* CLIPPER_UTILS_DEBUG */ // perform second offset co.Clear(); co.AddPaths(output1, joinType, ClipperLib::etClosedPolygon); co.Execute(*retval, delta2 * float(CLIPPER_OFFSET_SCALE)); #ifdef CLIPPER_UTILS_DEBUG svg.draw(*retval, 1. / double(CLIPPER_OFFSET_SCALE), "green", stroke_width); #endif /* CLIPPER_UTILS_DEBUG */ // unscale output unscaleClipperPolygons(*retval); }
static void svg_wait_bar(void) { int i; svg("<!-- Wait time aggregation box -->\n"); svg("<text class=\"t2\" x=\"5\" y=\"-15\">CPU wait</text>\n"); /* surrounding box */ svg_graph_box(5); /* bars for each sample, proportional to the CPU util. */ for (i = 1; i < samples; i++) { int c; double twt; double ptwt; ptwt = twt = 0.0; for (c = 0; c < cpus; c++) twt += cpustat[c].sample[i].waittime - cpustat[c].sample[i - 1].waittime; twt = twt / 1000000000.0; twt = twt / (double)cpus; if (twt > 0.0) ptwt = twt / (sampletime[i] - sampletime[i - 1]); if (ptwt > 1.0) ptwt = 1.0; if (ptwt > 0.001) { svg("<rect class=\"wait\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n", time_to_graph(sampletime[i - 1] - graph_start), ((scale_y * 5) - (ptwt * (scale_y * 5))), time_to_graph(sampletime[i] - sampletime[i - 1]), ptwt * (scale_y * 5)); } } }
void create_svg(std::string const& filename, Geometry1 const& a, Geometry2 const& b) { typedef typename boost::geometry::point_type<Geometry1>::type point_type; std::ofstream svg(filename.c_str()); boost::geometry::svg_mapper<point_type> mapper(svg, 400, 400); mapper.add(a); mapper.add(b); mapper.map(a, "fill-opacity:0.5;fill:rgb(153,204,0);stroke:rgb(153,204,0);stroke-width:0.01"); mapper.map(b, "opacity:0.8;fill:none;stroke:rgb(255,128,0);stroke-width:0.01;stroke-linecap:round"); }
static void svg_graph_box(int height) { double d = 0.0; int i = 0; /* outside box, fill */ svg("<rect class=\"box\" x=\"%.03f\" y=\"0\" width=\"%.03f\" height=\"%.03f\" />\n", time_to_graph(0.0), time_to_graph(sampletime[samples-1] - graph_start), ps_to_graph(height)); for (d = graph_start; d <= sampletime[samples-1]; d += (scale_x < 2.0 ? 60.0 : scale_x < 10.0 ? 1.0 : 0.1)) { /* lines for each second */ if (i % 50 == 0) svg(" <line class=\"sec5\" x1=\"%.03f\" y1=\"0\" x2=\"%.03f\" y2=\"%.03f\" />\n", time_to_graph(d - graph_start), time_to_graph(d - graph_start), ps_to_graph(height)); else if (i % 10 == 0) svg(" <line class=\"sec1\" x1=\"%.03f\" y1=\"0\" x2=\"%.03f\" y2=\"%.03f\" />\n", time_to_graph(d - graph_start), time_to_graph(d - graph_start), ps_to_graph(height)); else svg(" <line class=\"sec01\" x1=\"%.03f\" y1=\"0\" x2=\"%.03f\" y2=\"%.03f\" />\n", time_to_graph(d - graph_start), time_to_graph(d - graph_start), ps_to_graph(height)); /* time label */ if (i % 10 == 0) svg(" <text class=\"sec\" x=\"%.03f\" y=\"%.03f\" >%.01fs</text>\n", time_to_graph(d - graph_start), -5.0, d - graph_start); i++; } }