8#include "lf/base/base.h"
9#include "lf/mesh/mesh.h"
14 return static_cast<TikzOutputCtrl>(
static_cast<unsigned int>(lhs) |
15 static_cast<unsigned int>(rhs));
19 return static_cast<TikzOutputCtrl>(
static_cast<unsigned int>(lhs) &
20 static_cast<unsigned int>(rhs));
27 std::ofstream outfile(filename);
47 using size_type = std::size_t;
49 const Eigen::MatrixXd zero(Eigen::MatrixXd::Zero(0, 1));
53 LF_VERIFY_MSG(dim_mesh == 2,
"writeTikZ() only available for 2D meshes");
56 const dim_t node_codim(dim_mesh);
57 const size_type no_of_nodes =
59 size_type node_count = 0;
63 outfile <<
"\\documentclass[12pt,a4paper]{article}\n\\usepackage{tikz}"
64 "\n\\begin{document}\n"
67 outfile <<
"% TikZ document graphics \n";
70 if (no_of_nodes > 50) {
71 outfile <<
"\\begin{tikzpicture}[scale=6, >= stealth, inner sep=0pt, "
72 "minimum size=0.2cm]\n";
73 outfile <<
"\\tikzstyle{every node}=[font=\\tiny]\n";
75 outfile <<
"\\begin{tikzpicture}[scale=4, >= stealth, inner sep=0pt, "
76 "minimum size=0.35cm]\n";
82 for (
int co_dim = 0; co_dim <= dim_mesh; co_dim++) {
86 size_type obj_idx = mesh.
Index(*obj);
88 int num_nodes_obj = obj_refel.
NumNodes();
90 const Eigen::MatrixXd &obj_corners(obj_refel.
NodeCoords());
91 const Eigen::MatrixXd vertices = obj_geo_ptr->
Global(obj_corners);
92 const Eigen::MatrixXd center =
93 vertices.rowwise().sum() / vertices.cols();
94 Eigen::MatrixXd center_mat(center.rows(), num_nodes_obj);
99 outfile <<
"\\draw[red, fill = white] (" << vertices(0, 0) <<
","
100 << vertices(1, 0) <<
") "
101 <<
"node[draw, circle, fill = white] {" << obj_idx
104 outfile <<
"\\draw[red] (" << vertices(0, 0) <<
","
105 << vertices(1, 0) <<
") "
113 center_mat << center, center;
114 const Eigen::MatrixXd scaled_vertices =
115 vertices * 0.80 + center_mat * 0.2;
116 const Eigen::MatrixXd semi_scaled_vertices =
117 vertices * 0.95 + center_mat * 0.05;
120 if (EdgeNumOn && NodeNumOn) {
121 outfile <<
"\\draw[->] (" << scaled_vertices(0, 0) <<
","
122 << scaled_vertices(1, 0) <<
") -- node[black] {"
124 <<
"(" << scaled_vertices(0, 1) <<
","
125 << scaled_vertices(1, 1) <<
");\n";
126 }
else if (NodeNumOn && !EdgeNumOn) {
127 outfile <<
"\\draw[->] (" << scaled_vertices(0, 0) <<
","
128 << scaled_vertices(1, 0) <<
") -- "
129 <<
"(" << scaled_vertices(0, 1) <<
","
130 << scaled_vertices(1, 1) <<
");\n";
131 }
else if (!NodeNumOn && EdgeNumOn) {
132 outfile <<
"\\draw[->] (" << semi_scaled_vertices(0, 0) <<
","
133 << semi_scaled_vertices(1, 0) <<
") -- node[black] {"
135 <<
"(" << semi_scaled_vertices(0, 1) <<
","
136 << semi_scaled_vertices(1, 1) <<
");\n";
137 }
else if (!NodeNumOn && !EdgeNumOn) {
138 outfile <<
"\\draw[->] (" << semi_scaled_vertices(0, 0) <<
","
139 << semi_scaled_vertices(1, 0) <<
") -- "
140 <<
"(" << semi_scaled_vertices(0, 1) <<
","
141 << semi_scaled_vertices(1, 1) <<
");\n";
143 std::cout <<
"Check EdgeNumOn and NodeNumOn for kSegment "
144 << obj_idx << std::endl;
149 outfile <<
"\\draw[] (" << vertices(0, 0) <<
","
150 << vertices(1, 0) <<
") -- node[black] {" << obj_idx
152 <<
"(" << vertices(0, 1) <<
"," << vertices(1, 1)
154 }
else if (!EdgeNumOn) {
155 outfile <<
"\\draw[] (" << vertices(0, 0) <<
","
156 << vertices(1, 0) <<
") -- "
157 <<
"(" << vertices(0, 1) <<
"," << vertices(1, 1)
160 std::cout <<
"Check EdgeNumOn and NodeNumOn for kSegment "
161 << obj_idx << std::endl;
169 center_mat << center, center, center;
170 const Eigen::MatrixXd scaled_vertices =
171 vertices * 0.70 + center_mat * 0.30;
175 outfile <<
"\\draw[green] (" << scaled_vertices(0, 0) <<
","
176 << scaled_vertices(1, 0) <<
") node[] {0} -- ("
177 << scaled_vertices(0, 1) <<
"," << scaled_vertices(1, 1)
178 <<
") node[] {1} -- (" << scaled_vertices(0, 2) <<
","
179 << scaled_vertices(1, 2) <<
") node[] {2} -- cycle;\n";
181 outfile <<
"\\draw[green] (" << scaled_vertices(0, 0) <<
","
182 << scaled_vertices(1, 0) <<
") -- ("
183 << scaled_vertices(0, 1) <<
"," << scaled_vertices(1, 1)
184 <<
") -- (" << scaled_vertices(0, 2) <<
","
185 << scaled_vertices(1, 2) <<
") -- cycle;\n";
189 outfile <<
"\\draw[green] (" << center(0, 0) <<
","
190 << center(1, 0) <<
") node[] {" << obj_idx <<
"};\n";
198 center_mat << center, center, center, center;
199 const Eigen::MatrixXd scaled_vertices =
200 vertices * 0.70 + center_mat * 0.3;
204 outfile <<
"\\draw[magenta] (" << scaled_vertices(0, 0) <<
","
205 << scaled_vertices(1, 0) <<
") node[] {0} -- ("
206 << scaled_vertices(0, 1) <<
"," << scaled_vertices(1, 1)
207 <<
") node[] {1} -- (" << scaled_vertices(0, 2) <<
","
208 << scaled_vertices(1, 2) <<
") node[] {2} -- ("
209 << scaled_vertices(0, 3) <<
"," << scaled_vertices(1, 3)
210 <<
") node[] {3} -- cycle;\n";
212 outfile <<
"\\draw[magenta] (" << scaled_vertices(0, 0) <<
","
213 << scaled_vertices(1, 0) <<
") -- ("
214 << scaled_vertices(0, 1) <<
"," << scaled_vertices(1, 1)
215 <<
") -- (" << scaled_vertices(0, 2) <<
","
216 << scaled_vertices(1, 2) <<
") -- ("
217 << scaled_vertices(0, 3) <<
"," << scaled_vertices(1, 3)
222 outfile <<
"\\draw[magenta] (" << center(0, 0) <<
","
223 << center(1, 0) <<
") node[] {" << obj_idx <<
"};\n";
232 std::cout <<
"Error for object " << obj_idx <<
" in co-dim "
233 << co_dim << std::endl;
234 std::cout <<
"Object type: " << obj_refel << std::endl;
245 outfile <<
"\\end{tikzpicture}\n";
247 outfile <<
"\n\\end{document}" << std::endl;
A Function Object that can be invoked with any arguments and that always returns the value true.
Represents a reference element with all its properties.
static constexpr RefEl kSegment()
Returns the (1-dimensional) reference segment.
constexpr RefEl(RefElType type) noexcept
Create a RefEl from a lf::base::RefElType enum.
const Eigen::MatrixXd & NodeCoords() const
Get the coordinates of the nodes of this reference element.
static constexpr RefEl kPoint()
Returns the (0-dimensional) reference point.
static constexpr RefEl kTria()
Returns the reference triangle.
constexpr size_type NumNodes() const
The number of nodes of this reference element.
static constexpr RefEl kQuad()
Returns the reference quadrilateral.
Interface class for shape information on a mesh cell in the spirit of parametric finite element metho...
virtual Eigen::MatrixXd Global(const Eigen::MatrixXd &local) const =0
Map a number of points in local coordinates into the global coordinate system.
Interface class representing a topological entity in a cellular complex
Abstract interface for objects representing a single mesh.
virtual size_type NumEntities(unsigned codim) const =0
The number of Entities that have the given codimension.
virtual unsigned DimMesh() const =0
The dimension of the manifold described by the mesh, or equivalently the maximum dimension of the ref...
virtual nonstd::span< const Entity *const > Entities(unsigned codim) const =0
All entities of a given codimension.
virtual size_type Index(const Entity &e) const =0
Acess to the index of a mesh entity of any co-dimension.
unsigned int dim_t
type for dimensions and co-dimensions and numbers derived from them
Mesh input (from file) and output (in various formats) facilities.
TikzOutputCtrl
Enum flags: TikzOutputCtrl for output control of mesh drawn in TikZ.
bool writeTikZ(const lf::mesh::Mesh &mesh, const std::string &filename, std::function< bool(const lf::mesh::Entity &)> &&selector, TikzOutputCtrl output_ctrl)
Writes mesh to file in TikZ Graphics format. File as input in LaTeX will draw the mesh.
TikzOutputCtrl operator&(const TikzOutputCtrl &lhs, const TikzOutputCtrl &rhs)
TikzOutputCtrl operator|(const TikzOutputCtrl &lhs, const TikzOutputCtrl &rhs)