9#include <kernel/geometry/conformal_mesh.hpp> 
   12#include <kernel/util/math.hpp> 
   55      template<
typename Shape_, 
typename DataType_>
 
   59        const double width = 100.0,
 
   60        const double height = 100.0,
 
   61        const double stroke = 0.1,
 
   62        const double extra = 0.0)
 
   64        XASSERTM(width  >= 1.0, 
"invalid bounding box width");
 
   65        XASSERTM(height >= 1.0, 
"invalid bounding box height");
 
   66        XASSERTM(stroke > 0.01, 
"invalid stroke width");
 
   67        XASSERTM(extra >= 0.0, 
"invalid bounding box extra");
 
   71        const auto& idx = mesh.template get_index_set<1,0>();
 
   74        DataType_ x_min, x_max, y_min, y_max;
 
   75        x_min = x_max = vtx[0][0];
 
   76        y_min = y_max = vtx[0][1];
 
   77        for(
Index i(1); i < vtx.get_num_vertices(); ++i)
 
   79          const auto& v = vtx[i];
 
   84        const double x_sc =  width  / double(x_max - x_min);
 
   85        const double y_sc = height / double(y_max - y_min);
 
   88        const double scale = 
Math::min(x_sc, y_sc);
 
   91        os << 
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n";
 
   92        os << 
"<svg version=\"1.1\" id=\"svg2\" ";
 
   94        const double X = double(x_max - x_min);
 
   95        const double Y = double(y_max - y_min);
 
   97        const double adjusted_width = scale * X + 2.0 * extra;
 
   98        const double adjusted_height = scale * Y + 2.0 * extra;
 
  101        os << 
"width=\"" << adjusted_width << 
"mm\" height=\"" << adjusted_height << 
"mm\" ";
 
  104        os << 
"viewBox=\"" << (-extra/scale) << 
" " << (-extra/scale) << 
" ";
 
  105        os << (x_max - x_min + 2.0*extra/scale) << 
" " << (y_max - y_min + 2.0*extra/scale);
 
  106        os << 
"\" xmlns=\"http://www.w3.org/2000/svg\">\n";
 
  109        os << 
"<path style=\"fill:none;stroke:#000000;";
 
  110        os << 
"stroke-width:" << stroke/scale << 
";stroke-opacity:1\" id=\"mesh\" d=\" \n";
 
  113        for(
Index i(0); i < idx.get_num_entities(); ++i)
 
  116          const auto& v0 = vtx[idx[i][0]];
 
  117          const auto& v1 = vtx[idx[i][1]];
 
  120          double v0x = (double(v0[0]) - x_min);
 
  121          double v0y = (y_max - double(v0[1]));
 
  122          double v1x = (double(v1[0]) - x_min);
 
  123          double v1y = (y_max - double(v1[1]));
 
  126          os << 
"M " << v0x << 
" " << v0y;
 
  127          os << 
" L " << v1x << 
" " << v1y << 
"\n";
 
  153      template<
typename Shape_, 
typename DataType_>
 
  157        const double width = 100.0,
 
  158        const double height = 100.0,
 
  159        const double stroke = 0.1,
 
  160        const double extra = 0.0)
 
  162        std::ofstream ofs(filename);
 
  163        if(!ofs.is_open() || !ofs.good())
 
  165        write(ofs, mesh, width, height, stroke, extra);
 
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Base class for file related errors.
static void write(std::ostream &os, const ConformalMesh< Shape_, 2, DataType_ > &mesh, const double width=100.0, const double height=100.0, const double stroke=0.1, const double extra=0.0)
Exports a mesh to a SVG file.
static void write(const String &filename, const ConformalMesh< Shape_, 2, DataType_ > &mesh, const double width=100.0, const double height=100.0, const double stroke=0.1, const double extra=0.0)
Exports a mesh to a SVG file.
String class implementation.
void minimax(T_ x, T_ &a, T_ &b)
Updates the minimum and maximum.
T_ min(T_ a, T_ b)
Returns the minimum of two values.
std::uint64_t Index
Index data type.