15#define _USE_MATH_DEFINES
18#include "arcane/core/SimpleSVGMeshExporter.h"
20#include "arcane/utils/Iostream.h"
21#include "arcane/core/ItemGroup.h"
22#include "arcane/core/IMesh.h"
23#include "arcane/core/VariableTypes.h"
51 double m_font_size = 3.0;
57void SimpleSVGMeshExporter::Impl::
62 m_ofile <<
"<text x='" << x <<
"' y='" << y <<
"' dominant-baseline='central' text-anchor='middle'"
63 <<
" style='stroke:white; stroke-width:0.6em'";
65 m_ofile <<
" transform='rotate(" << rotation <<
"," << x <<
"," << y <<
")'";
66 m_ofile <<
" font-size='" << m_font_size <<
"'>" << text <<
"</text>\n";
68 m_ofile <<
"<text x='" << x <<
"' y='" << y <<
"' dominant-baseline='central' text-anchor='middle'"
69 <<
" fill='" << color <<
"'";
71 m_ofile <<
" transform='rotate(" << rotation <<
"," << x <<
"," << y <<
")'";
72 m_ofile <<
" font-size='" << m_font_size <<
"'>" << text <<
"</text>\n";
78void SimpleSVGMeshExporter::Impl::
83 IMesh* mesh = cells.mesh();
84 Int32 mesh_dim = mesh->dimension();
86 ARCANE_FATAL(
"Invalid dimension ({0}) for mesh. Only 2D mesh is allowed", mesh_dim);
94 ostream& ofile = m_ofile;
95 Real mul_value = 1000.0;
96 const Real min_val = std::numeric_limits<Real>::lowest();
97 const Real max_val = std::numeric_limits<Real>::max();
98 Real2 min_bbox(max_val, max_val);
99 Real2 max_bbox(min_val, min_val);
101 std::map<Int32, Real2> cells_center;
105 Integer nb_node = cell.nbNode();
107 for (
Integer i = 0; i < nb_node; ++i) {
108 Real3 node_coord_3d = nodes_coord[cell.node(i)] * mul_value;
109 Real2 node_coord(node_coord_3d.x, -node_coord_3d.y);
110 min_bbox =
math::min(min_bbox, node_coord);
111 max_bbox =
math::max(max_bbox, node_coord);
112 center += node_coord_3d;
116 Real2 center_2d(center.x, -center.y);
117 cells_center[cell.localId()] = center_2d;
120 Real bbox_width = math::abs(max_bbox.x - min_bbox.x);
121 Real bbox_height = math::abs(max_bbox.y - min_bbox.y);
123 m_font_size = max_dim / 80.0;
127 ofile <<
"<?xml version=\"1.0\"?>\n";
129 <<
" viewBox='" << min_bbox.x - bbox_width * 0.1 <<
"," << min_bbox.y - bbox_height * 0.1 <<
"," << bbox_width * 1.2 <<
"," << bbox_height * 1.2 <<
"'"
130 <<
" xmlns='http://www.w3.org/2000/svg' version='1.1'>\n";
131 ofile <<
"<!-- V3 bbox min_x=" << min_bbox.x <<
" min_y=" << min_bbox.y <<
" max_x=" << max_bbox.x <<
" max_y=" << max_bbox.y <<
" -->";
132 ofile <<
"<title>Mesh</title>\n";
133 ofile <<
"<desc>MeshExample</desc>\n";
142 Real2 cell_pos = cells_center[cell.localId()];
143 Integer nb_node = cell.nbNode();
144 ofile <<
"<path d='";
145 nb_node = cell.typeInfo()->linearTypeInfo()->nbLocalNode();
146 for (
Integer i = 0; i < nb_node; ++i) {
147 Real3 node_coord_3d = nodes_coord[cell.node(i)];
148 Real2 node_coord(node_coord_3d.x, -node_coord_3d.y);
149 node_coord *= mul_value;
155 Real2 coord = cell_pos + (node_coord - cell_pos) * 0.98;
156 ofile << coord.x <<
" " << coord.y <<
" ";
160 ofile <<
" fill='yellow'";
162 ofile <<
" fill='orange'";
163 ofile <<
" stroke='black'";
164 ofile <<
" stroke-width='1'/>\n";
165 _writeText(cell_pos.x, cell_pos.y,
"blue", String::fromNumber(cell.uniqueId().asInt64()), 0.0,
false);
171 std::set<Int32> nodes_done;
174 Integer nb_node = cell.nbNode();
175 for (
Integer i = 0; i < nb_node; ++i) {
176 Node node = cell.node(i);
177 Int32 lid = node.localId();
178 if (nodes_done.find(lid) != nodes_done.end())
180 nodes_done.insert(lid);
181 Real3 coord_3d = nodes_coord[node];
182 Real2 coord(coord_3d.x, -coord_3d.y);
184 _writeText(coord.x, coord.y,
"green", String::fromNumber(node.uniqueId().asInt64()), 0.0,
true);
194 std::set<Int32> faces_done;
197 Integer nb_face = cell.nbFace();
198 for (
Integer i = 0; i < nb_face; ++i) {
199 Face face = cell.face(i);
200 Int32 lid = face.localId();
201 if (faces_done.find(lid) != faces_done.end())
203 faces_done.insert(lid);
206 if (face.nbNode() < 2)
208 Real3 node0_coord = nodes_coord[face.node(0)];
209 Real3 node1_coord = nodes_coord[face.node(1)];
210 Real3 face_coord_3d = (node0_coord + node1_coord) / 2.0;
212 Real2 face_coord(face_coord_3d.x, -face_coord_3d.y);
213 face_coord *= mul_value;
214 Real3 direction = node1_coord - node0_coord;
215 direction = direction.normalize();
219 double angle = math::abs(std::asin(direction.y)) / M_PI * 180.0;
220 Real2 cell_center = cells_center[cell.localId()];
221 Real2 coord = cell_center + (face_coord - cell_center) * 0.92;
222 _writeText(coord.x, coord.y,
"red", String::fromNumber(face.uniqueId().asInt64()), angle,
true);
236: m_p(new
Impl(ofile))
243SimpleSVGMeshExporter::
244~SimpleSVGMeshExporter()
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
SimpleSVGMeshExporter(std::ostream &ofile)
Create an instance associated with the ofile stream.
void write(const CellGroup &cells)
Exports the entities of the cells group.
View of a UTF-8 character string.
__host__ __device__ Real2 min(Real2 a, Real2 b)
Returns the minimum of two Real2.
T max(const T &a, const T &b, const T &c)
Returns the maximum of three elements.
ItemGroupT< Cell > CellGroup
Group of cells.
MeshVariableScalarRefT< Node, Real3 > VariableNodeReal3
Coordinate type quantity at node.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
double Real
Type representing a real number.
@ Cell
The mesh is AMR by cell.
std::int32_t Int32
Signed integer type of 32 bits.