From: grahambenharper Date: Mon, 3 Feb 2020 18:30:35 +0000 (-0700) Subject: Update write_svg to support boundary ids X-Git-Tag: v9.2.0-rc1~536^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5ac97a123522377d65882842259a8184e6cd0ec9;p=dealii.git Update write_svg to support boundary ids --- diff --git a/doc/news/changes/minor/20200202Harper b/doc/news/changes/minor/20200202Harper new file mode 100644 index 0000000000..5e5ddd213c --- /dev/null +++ b/doc/news/changes/minor/20200202Harper @@ -0,0 +1,4 @@ +Changed: The GridOutFlags::Svg constructor may now take an additional +argument supporting the output of boundary ids on faces. +
+(Graham Harper, 2020/02/02) diff --git a/include/deal.II/grid/grid_out.h b/include/deal.II/grid/grid_out.h index 958f06e3c6..0c42225823 100644 --- a/include/deal.II/grid/grid_out.h +++ b/include/deal.II/grid/grid_out.h @@ -796,6 +796,15 @@ namespace GridOutFlags */ bool label_level_subdomain_id; + /** + * Write boundary id of each boundary face in a circle on the + * corresponding boundary edge. Defaults to false. + * + * Note: Depending on the choice of image viewer, the boundary id + * labels may not appear to be centered in the circle. + */ + bool label_boundary_id; + /** * Draw a colorbar next to the plotted grid with respect to the chosen * coloring of the cells. @@ -824,7 +833,8 @@ namespace GridOutFlags const bool label_material_id = false, const bool label_subdomain_id = false, const bool draw_colorbar = false, - const bool draw_legend = false); + const bool draw_legend = false, + const bool label_boundary_id = false); }; /** diff --git a/source/grid/grid_out.cc b/source/grid/grid_out.cc index df8328fac0..c8d9551d79 100644 --- a/source/grid/grid_out.cc +++ b/source/grid/grid_out.cc @@ -437,7 +437,8 @@ namespace GridOutFlags const bool label_material_id, const bool label_subdomain_id, const bool draw_colorbar, - const bool draw_legend) + const bool draw_legend, + const bool label_boundary_id) : height(1000) , width(0) , line_thickness(line_thickness) @@ -455,6 +456,7 @@ namespace GridOutFlags , label_material_id(label_material_id) , label_subdomain_id(label_subdomain_id) , label_level_subdomain_id(false) + , label_boundary_id(label_boundary_id) , draw_colorbar(draw_colorbar) , draw_legend(draw_legend) {} @@ -1963,6 +1965,7 @@ GridOut::write_svg(const Triangulation<2, 2> &tria, std::ostream &out) const << svg_flags.boundary_line_thickness << '}' << '\n' << " path{fill:none; stroke:rgb(25,25,25); stroke-width:" << svg_flags.line_thickness << '}' << '\n' + << " circle{fill:white; stroke:black; stroke-width:2}" << '\n' << '\n'; // polygon styles with respect to the chosen cell coloring @@ -2290,11 +2293,11 @@ GridOut::write_svg(const Triangulation<2, 2> &tria, std::ostream &out) const std::max(x_dimension, y_dimension); } - float distance_to_camera = + const double distance_to_camera = std::sqrt(std::pow(point[0] - camera_position[0], 2.) + std::pow(point[1] - camera_position[1], 2.) + std::pow(point[2] - camera_position[2], 2.)); - float distance_factor = + const double distance_factor = distance_to_camera / (2. * std::max(x_dimension, y_dimension)); projection_decomposition = svg_project_point(point, @@ -2303,10 +2306,11 @@ GridOut::write_svg(const Triangulation<2, 2> &tria, std::ostream &out) const camera_horizontal, camera_focus); - const auto font_size_this_cell = static_cast( - .5 + - cell_label_font_size * - std::pow(.5, cell->level() - 4. + 3.5 * distance_factor)); + const unsigned int font_size_this_cell = + static_cast( + .5 + + cell_label_font_size * + std::pow(.5, cell->level() - 4. + 3.5 * distance_factor)); out << " &tria, std::ostream &out) const (height - (height / 100.) * 2. * margin_in_percent)) << "\"/>" << '\n'; + + + if (svg_flags.label_boundary_id) + { + const double distance_to_camera = std::sqrt( + std::pow(point[0] - camera_position[0], 2.) + + std::pow(point[1] - camera_position[1], 2.) + + std::pow(point[2] - camera_position[2], 2.)); + const double distance_factor = + distance_to_camera / + (2. * std::max(x_dimension, y_dimension)); + + const unsigned int font_size_this_edge = + static_cast( + .5 + .5 * cell_label_font_size * + std::pow(.5, + cell->level() - 4. + + 3.5 * distance_factor)); + + point[0] = cell->face(faceIndex)->center()[0]; + point[1] = cell->face(faceIndex)->center()[1]; + point[2] = 0; + + if (svg_flags.convert_level_number_to_height) + { + point[2] = svg_flags.level_height_factor * + (static_cast(cell->level()) / + static_cast(n_levels)) * + std::max(x_dimension, y_dimension); + } + + projection_decomposition = + svg_project_point(point, + camera_position, + camera_direction, + camera_horizontal, + camera_focus); + + const unsigned int xc = static_cast( + .5 + + ((projection_decomposition[0] - x_min_perspective) / + x_dimension_perspective) * + (width - + (width / 100.) * 2. * margin_in_percent) + + ((width / 100.) * margin_in_percent)); + const unsigned int yc = static_cast( + .5 + height - (height / 100.) * margin_in_percent - + ((projection_decomposition[1] - y_min_perspective) / + y_dimension_perspective) * + (height - + (height / 100.) * 2. * margin_in_percent)); + + out << " " + << '\n'; + + out << " " + << static_cast( + cell->face(faceIndex)->boundary_id()) + << "" << '\n'; + } } } } @@ -2467,6 +2534,7 @@ GridOut::write_svg(const Triangulation<2, 2> &tria, std::ostream &out) const } + // draw the legend if (svg_flags.draw_legend) out << '\n' << " " << '\n'; @@ -2479,7 +2547,7 @@ GridOut::write_svg(const Triangulation<2, 2> &tria, std::ostream &out) const if (svg_flags.draw_legend && (svg_flags.label_level_number || svg_flags.label_cell_index || svg_flags.label_material_id || svg_flags.label_subdomain_id || - svg_flags.label_level_subdomain_id)) + svg_flags.label_level_subdomain_id || svg_flags.label_boundary_id)) { unsigned int line_offset = 0; out << " &tria, std::ostream &out) const << "\" width=\"" << static_cast(.5 + (height / 100.) * (40. - margin_in_percent)) - << "\" height=\"" << static_cast(.5 + height * .165) + << "\" height=\"" << static_cast(.5 + height * .215) << "\"/>" << '\n'; out << " &tria, std::ostream &out) const << "level_subdomain_id" << "" << '\n'; } + + if (svg_flags.label_boundary_id) + { + out << " (.5 + (height / 100.) * 1.25) + << "\" y=\"" + << static_cast(.5 + + (height / 100.) * margin_in_percent + + (++line_offset) * 1.5 * font_size) + << "\" style=\"text-anchor:start; font-weight:bold; font-size:" + << font_size << "px\">" + << "edge label" + << "" << '\n'; + + out << " (.5 + (height / 100.) * 2.) + << "\" y=\"" + << static_cast(.5 + + (height / 100.) * margin_in_percent + + (++line_offset) * 1.5 * font_size) + << "\" style=\"text-anchor:start; font-style:oblique; font-size:" + << font_size << "px\">" + << "boundary_id" + << "" << '\n'; + } } // show azimuth angle and polar angle as text below the explanation of the @@ -2604,7 +2699,7 @@ GridOut::write_svg(const Triangulation<2, 2> &tria, std::ostream &out) const { out << " ( - .5 + (height / 100.) * margin_in_percent + 10.75 * font_size) + .5 + (height / 100.) * margin_in_percent + 13.75 * font_size) << "\" style=\"text-anchor:start; font-size:" << font_size << "px\">" << "azimuth: " << svg_flags.azimuth_angle << "°, polar: " << svg_flags.polar_angle << "°" << '\n';