From c003b4a54150cac30073c315708034b70b47e939 Mon Sep 17 00:00:00 2001 From: Elias Dejene Date: Fri, 23 Oct 2020 10:23:26 +0200 Subject: [PATCH] Extend GridOut::write_svg() for simplices Add output for ctest. Replace forgotten write_eps by write_svg. Add comment for quad-case. Avoid writing extra point in case of simplices. Update ctest source-file. Replace post-increment by pre-increment. --- source/grid/grid_out.cc | 82 ++++++++++--------- tests/simplex/grid_out_svg.cc | 60 ++++++++++++++ ...rid_out_svg.with_simplex_support=on.output | 30 +++++++ 3 files changed, 134 insertions(+), 38 deletions(-) create mode 100644 tests/simplex/grid_out_svg.cc create mode 100644 tests/simplex/grid_out_svg.with_simplex_support=on.output diff --git a/source/grid/grid_out.cc b/source/grid/grid_out.cc index 16e1a7f5e8..73e2ea34b7 100644 --- a/source/grid/grid_out.cc +++ b/source/grid/grid_out.cc @@ -1584,7 +1584,8 @@ GridOut::write_svg(const Triangulation<2, 2> &tria, std::ostream &out) const // (, and level subdomain id). for (const auto &cell : tria.cell_iterators()) { - for (unsigned int vertex_index = 0; vertex_index < 4; vertex_index++) + for (unsigned int vertex_index = 0; vertex_index < cell->n_vertices(); + ++vertex_index) { if (cell->vertex(vertex_index)[0] < x_min) x_min = cell->vertex(vertex_index)[0]; @@ -1834,24 +1835,27 @@ GridOut::write_svg(const Triangulation<2, 2> &tria, std::ostream &out) const if (y_min_perspective > projection_decomposition[1]) y_min_perspective = projection_decomposition[1]; - point[0] = cell->vertex(3)[0]; - point[1] = cell->vertex(3)[1]; + if (cell->n_vertices() == 4) // in case of quadrilateral + { + point[0] = cell->vertex(3)[0]; + point[1] = cell->vertex(3)[1]; - projection_decomposition = svg_project_point(point, - camera_position, - camera_direction, - camera_horizontal, - camera_focus); + projection_decomposition = svg_project_point(point, + camera_position, + camera_direction, + camera_horizontal, + camera_focus); - if (x_max_perspective < projection_decomposition[0]) - x_max_perspective = projection_decomposition[0]; - if (x_min_perspective > projection_decomposition[0]) - x_min_perspective = projection_decomposition[0]; + if (x_max_perspective < projection_decomposition[0]) + x_max_perspective = projection_decomposition[0]; + if (x_min_perspective > projection_decomposition[0]) + x_min_perspective = projection_decomposition[0]; - if (y_max_perspective < projection_decomposition[1]) - y_max_perspective = projection_decomposition[1]; - if (y_min_perspective > projection_decomposition[1]) - y_min_perspective = projection_decomposition[1]; + if (y_max_perspective < projection_decomposition[1]) + y_max_perspective = projection_decomposition[1]; + if (y_min_perspective > projection_decomposition[1]) + y_min_perspective = projection_decomposition[1]; + } if (static_cast(cell->level()) == min_level) min_level_min_vertex_distance = cell->minimum_vertex_distance(); @@ -2175,29 +2179,32 @@ GridOut::write_svg(const Triangulation<2, 2> &tria, std::ostream &out) const out << " L "; - point[0] = cell->vertex(3)[0]; - point[1] = cell->vertex(3)[1]; + if (cell->n_vertices() == 4) // in case of quadrilateral + { + point[0] = cell->vertex(3)[0]; + point[1] = cell->vertex(3)[1]; - projection_decomposition = svg_project_point(point, - camera_position, - camera_direction, - camera_horizontal, - camera_focus); + projection_decomposition = svg_project_point(point, + camera_position, + camera_direction, + camera_horizontal, + camera_focus); - out << static_cast( - .5 + - ((projection_decomposition[0] - x_min_perspective) / - x_dimension_perspective) * - (width - (width / 100.) * 2. * margin_in_percent) + - ((width / 100.) * margin_in_percent)) - << ' ' - << 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 << static_cast( + .5 + + ((projection_decomposition[0] - x_min_perspective) / + x_dimension_perspective) * + (width - (width / 100.) * 2. * margin_in_percent) + + ((width / 100.) * margin_in_percent)) + << ' ' + << 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 << " L "; + out << " L "; + } point[0] = cell->vertex(2)[0]; point[1] = cell->vertex(2)[1]; @@ -2354,8 +2361,7 @@ GridOut::write_svg(const Triangulation<2, 2> &tria, std::ostream &out) const // the additional boundary line if (svg_flags.boundary_line_thickness) { - for (const unsigned int faceIndex : - GeometryInfo<2>::face_indices()) + for (auto faceIndex : cell->face_indices()) { if (cell->at_boundary(faceIndex)) { diff --git a/tests/simplex/grid_out_svg.cc b/tests/simplex/grid_out_svg.cc new file mode 100644 index 0000000000..73c795f821 --- /dev/null +++ b/tests/simplex/grid_out_svg.cc @@ -0,0 +1,60 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2020 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + + +// Write a file in the SVG format with (linear) triangular and tetrahedral +// elements created by the GMSH program. + +#include +#include +#include + +#include + +#include "../tests.h" + +template +void +check_file(const std::string &file_name) +{ + Triangulation tria; + + GridIn grid_in; + grid_in.attach_triangulation(tria); + std::ifstream input_file(file_name); + grid_in.read_vtk(input_file); + + GridOut grid_out; +#if false + std::ofstream out("mesh-" + std::to_string(spacedim) + ".svg"); + grid_out.write_svg(tria, out); +#else + grid_out.write_svg(tria, deallog.get_file_stream()); +#endif + + deallog << "OK!" << std::endl; +} + + +int +main() +{ + initlog(); + // TRIANGULAR ELEMENTS + // dim = spacedim = 2 + deallog.push("triangluar_elements_dim2_spacedim2: "); + check_file<2, 2>(std::string(SOURCE_DIR "/grid_in_vtk/tri.vtk")); + deallog.pop(); +} diff --git a/tests/simplex/grid_out_svg.with_simplex_support=on.output b/tests/simplex/grid_out_svg.with_simplex_support=on.output new file mode 100644 index 0000000000..92f3b86f61 --- /dev/null +++ b/tests/simplex/grid_out_svg.with_simplex_support=on.output @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + +DEAL:triangluar_elements_dim2_spacedim2: ::OK! -- 2.39.5