9#include <kernel/geometry/conformal_mesh.hpp>
12#include <kernel/util/math.hpp>
54 template<
typename Shape_,
typename DataType_>
58 const double width = 100.0,
59 const double height = 100.0,
60 const double stroke = 0.1,
61 const double extra = 0.0)
63 XASSERTM(width >= 1.0,
"invalid bounding box width");
64 XASSERTM(height >= 1.0,
"invalid bounding box height");
65 XASSERTM(stroke > 0.01,
"invalid stroke width");
66 XASSERTM(extra >= 0.0,
"invalid bounding box extra");
70 const auto& idx = mesh.template get_index_set<1,0>();
73 DataType_ x_min, x_max, y_min, y_max;
74 x_min = x_max = vtx[0][0];
75 y_min = y_max = vtx[0][1];
76 for(
Index i(1); i < vtx.get_num_vertices(); ++i)
78 const auto& v = vtx[i];
88 const double x_sc = (72.0 / 25.4) * width /
double(x_max - x_min);
89 const double y_sc = (72.0 / 25.4) * height /
double(y_max - y_min);
92 const double scale =
Math::min(x_sc, y_sc);
95 const int box_x = int(scale *
double(x_max - x_min) + 2.0*extra) + 1;
96 const int box_y = int(scale *
double(y_max - y_min) + 2.0*extra) + 1;
99 const double box_o = 72.0 * extra / 25.4;
102 os <<
"%!!PS-Adobe-3.0 EPSF-3.0\n";
105 os <<
"%%BoundingBox: 0 0 " << box_x <<
" " << box_y <<
'\n';
108 os << (72.0 * stroke / 25.4) <<
" setlinewidth\n";
114 for(
Index i(0); i < idx.get_num_entities(); ++i)
117 const auto& v0 = vtx[idx[i][0]];
118 const auto& v1 = vtx[idx[i][1]];
121 double v0x = box_o + (double(v0[0]) - x_min) * scale;
122 double v0y = box_o + (double(v0[1]) - y_min) * scale;
123 double v1x = box_o + (double(v1[0]) - x_min) * scale;
124 double v1y = box_o + (double(v1[1]) - y_min) * scale;
127 os << v0x <<
" " << v0y <<
" moveto\n";
128 os << v1x <<
" " << v1y <<
" lineto\n";
154 template<
typename Shape_,
typename DataType_>
158 const double width = 100.0,
159 const double height = 100.0,
160 const double stroke = 0.1,
161 const double extra = 0.0)
163 std::ofstream ofs(filename);
164 if(!ofs.is_open() || !ofs.good())
166 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 an EPS 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 an EPS 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.