diff options
author | ROUVREAU Vincent <vincent.rouvreau@inria.fr> | 2020-09-22 16:43:54 +0200 |
---|---|---|
committer | ROUVREAU Vincent <vincent.rouvreau@inria.fr> | 2020-09-22 16:43:54 +0200 |
commit | e0041b766b647f3906b52f861e97edba1f089312 (patch) | |
tree | 693206fa60c757346750461922e107e5f16f5c0a /src/Coxeter_triangulation/include/gudhi/IO | |
parent | cba4b7047cc8665a3f20e2334358a4ca28bf021a (diff) |
include what you use
Diffstat (limited to 'src/Coxeter_triangulation/include/gudhi/IO')
3 files changed, 58 insertions, 39 deletions
diff --git a/src/Coxeter_triangulation/include/gudhi/IO/Mesh_medit.h b/src/Coxeter_triangulation/include/gudhi/IO/Mesh_medit.h index 2cceeac1..28276bf7 100644 --- a/src/Coxeter_triangulation/include/gudhi/IO/Mesh_medit.h +++ b/src/Coxeter_triangulation/include/gudhi/IO/Mesh_medit.h @@ -15,6 +15,11 @@ namespace Gudhi { namespace coxeter_triangulation { +#include <Eigen/Dense> + +#include <vector> +#include <utility> // for std::pair + /* \class Mesh_medit * \brief Structure to store a mesh that can be output in Medit .mesh file format * using the output_meshes_to_medit method. diff --git a/src/Coxeter_triangulation/include/gudhi/IO/build_mesh_from_cell_complex.h b/src/Coxeter_triangulation/include/gudhi/IO/build_mesh_from_cell_complex.h index a96d12ba..abe6cdbf 100644 --- a/src/Coxeter_triangulation/include/gudhi/IO/build_mesh_from_cell_complex.h +++ b/src/Coxeter_triangulation/include/gudhi/IO/build_mesh_from_cell_complex.h @@ -13,34 +13,42 @@ #include <gudhi/IO/Mesh_medit.h> +#include <Eigen/Dense> + +#include <cstdlib> // for std::size_t +#include <map> +#include <set> +#include <string> +#include <utility> // for std::make_pair +#include <algorithm> // for std::min + namespace Gudhi { namespace coxeter_triangulation { struct Configuration { + Configuration(bool t_edges, bool t_triangles, bool t_tetrahedra, + std::size_t r_edges, std::size_t r_triangles, std::size_t r_tetrahedra) + : toggle_edges(t_edges), toggle_triangles(t_triangles), toggle_tetrahedra(t_tetrahedra), + ref_edges(r_edges), ref_triangles(r_triangles), ref_tetrahedra(r_tetrahedra) {} + + Configuration() {} + bool toggle_edges = true, toggle_triangles = true, toggle_tetrahedra = true; std::size_t ref_edges = 1, ref_triangles = 1, ref_tetrahedra = 1; - - Configuration(bool t_edges, bool t_triangles, bool t_tetrahedra, - std::size_t r_edges, std::size_t r_triangles, std::size_t r_tetrahedra) - : toggle_edges(t_edges), toggle_triangles(t_triangles), toggle_tetrahedra(t_tetrahedra), - ref_edges(r_edges), ref_triangles(r_triangles), ref_tetrahedra(r_tetrahedra) {} - - Configuration() {} }; -template <class Hasse_cell, - class Simplex_cell_map> +template <class Hasse_cell, class Simplex_cell_map> void populate_mesh(Mesh_medit& output, - Simplex_cell_map& sc_map, - Configuration configuration, - std::size_t amb_d, - std::map<Hasse_cell*, std::size_t> vi_map) { + Simplex_cell_map& sc_map, + Configuration configuration, + std::size_t amb_d, + std::map<Hasse_cell*, std::size_t> vi_map) { using Mesh_element_vertices = Mesh_medit::Mesh_elements::value_type::first_type; std::map<Hasse_cell*, std::size_t> ci_map; std::size_t index = vi_map.size() + 1; // current size of output.vertex_points @@ -50,16 +58,16 @@ void populate_mesh(Mesh_medit& output, std::set<std::size_t> vertex_indices; Hasse_cell* cell = sc_pair.second; for (const auto& ei_pair: cell->get_boundary()) - for (const auto& vi_pair: ei_pair.first->get_boundary()) - vertex_indices.emplace(vi_map[vi_pair.first]); + for (const auto& vi_pair: ei_pair.first->get_boundary()) + vertex_indices.emplace(vi_map[vi_pair.first]); for (const std::size_t& v: vertex_indices) - barycenter += output.vertex_points[v-1]; + barycenter += output.vertex_points[v-1]; ci_map.emplace(std::make_pair(cell, index++)); output.vertex_points.emplace_back((1./vertex_indices.size()) * barycenter); #ifdef GUDHI_COX_OUTPUT_TO_HTML std::string vlist = " (" + std::to_string(index-1) + ")"; for (const std::size_t& v: vertex_indices) - vlist += " " + std::to_string(v); + vlist += " " + std::to_string(v); cell_vlist_map.emplace(std::make_pair(to_string(cell), vlist)); #endif } @@ -69,12 +77,12 @@ void populate_mesh(Mesh_medit& output, Hasse_cell* edge_cell = sc_map.second; Mesh_element_vertices edge; for (const auto& vi_pair: edge_cell->get_boundary()) - edge.push_back(vi_map[vi_pair.first]); + edge.push_back(vi_map[vi_pair.first]); output.edges.emplace_back(std::make_pair(edge, configuration.ref_edges)); #ifdef GUDHI_COX_OUTPUT_TO_HTML std::string vlist; for (const std::size_t& v: edge) - vlist += " " + std::to_string(v); + vlist += " " + std::to_string(v); cell_vlist_map.emplace(std::make_pair(to_string(edge_cell), vlist)); #endif } @@ -82,10 +90,10 @@ void populate_mesh(Mesh_medit& output, if (configuration.toggle_triangles && sc_map.size() >= 3) for (const auto& sc_pair: sc_map[2]) { for (const auto& ei_pair: sc_pair.second->get_boundary()) { - Mesh_element_vertices triangle(1, ci_map[sc_pair.second]); - for (const auto& vi_pair: ei_pair.first->get_boundary()) - triangle.push_back(vi_map[vi_pair.first]); - output.triangles.emplace_back(std::make_pair(triangle, configuration.ref_triangles)); + Mesh_element_vertices triangle(1, ci_map[sc_pair.second]); + for (const auto& vi_pair: ei_pair.first->get_boundary()) + triangle.push_back(vi_map[vi_pair.first]); + output.triangles.emplace_back(std::make_pair(triangle, configuration.ref_triangles)); } } @@ -95,34 +103,34 @@ void populate_mesh(Mesh_medit& output, std::set<std::size_t> vertex_indices; Hasse_cell* cell = sc_pair.second; for (const auto& ci_pair: cell->get_boundary()) - for (const auto& ei_pair: ci_pair.first->get_boundary()) - for (const auto& vi_pair: ei_pair.first->get_boundary()) - vertex_indices.emplace(vi_map[vi_pair.first]); - for (const std::size_t& v: vertex_indices) - barycenter += output.vertex_points[v-1]; + for (const auto& ei_pair: ci_pair.first->get_boundary()) + for (const auto& vi_pair: ei_pair.first->get_boundary()) + vertex_indices.emplace(vi_map[vi_pair.first]); + for (const std::size_t& v: vertex_indices) + barycenter += output.vertex_points[v-1]; output.vertex_points.emplace_back((1./vertex_indices.size()) * barycenter); #ifdef GUDHI_COX_OUTPUT_TO_HTML std::string vlist = " (" + std::to_string(index) + ")"; for (const std::size_t& v: vertex_indices) - vlist += " " + std::to_string(v); + vlist += " " + std::to_string(v); cell_vlist_map.emplace(std::make_pair(to_string(cell), vlist)); #endif for (const auto& ci_pair: cell->get_boundary()) - for (const auto& ei_pair: ci_pair.first->get_boundary()) { - Mesh_element_vertices tetrahedron = {index, ci_map[sc_pair.second]}; - for (const auto& vi_pair: ei_pair.first->get_boundary()) - tetrahedron.push_back(vi_map[vi_pair.first]); - output.tetrahedra.emplace_back(std::make_pair(tetrahedron, configuration.ref_tetrahedra)); - } + for (const auto& ei_pair: ci_pair.first->get_boundary()) { + Mesh_element_vertices tetrahedron = {index, ci_map[sc_pair.second]}; + for (const auto& vi_pair: ei_pair.first->get_boundary()) + tetrahedron.push_back(vi_map[vi_pair.first]); + output.tetrahedra.emplace_back(std::make_pair(tetrahedron, configuration.ref_tetrahedra)); + } index++; } } template <class Cell_complex> Mesh_medit build_mesh_from_cell_complex(const Cell_complex& cell_complex, - Configuration i_configuration = Configuration(), - Configuration b_configuration = Configuration()) { + Configuration i_configuration = Configuration(), + Configuration b_configuration = Configuration()) { using Hasse_cell = typename Cell_complex::Hasse_cell; Mesh_medit output; std::map<Hasse_cell*, std::size_t> vi_map; // one for vertices, other for 2d-cells @@ -142,7 +150,6 @@ Mesh_medit build_mesh_from_cell_complex(const Cell_complex& cell_complex, output.vertex_points.push_back(cp_pair.second); output.vertex_points.back().conservativeResize(amb_d); } - populate_mesh(output, cell_complex.interior_simplex_cell_maps(), i_configuration, amb_d, vi_map); #ifdef GUDHI_COX_OUTPUT_TO_HTML diff --git a/src/Coxeter_triangulation/include/gudhi/IO/output_meshes_to_medit.h b/src/Coxeter_triangulation/include/gudhi/IO/output_meshes_to_medit.h index b40593ba..850736e9 100644 --- a/src/Coxeter_triangulation/include/gudhi/IO/output_meshes_to_medit.h +++ b/src/Coxeter_triangulation/include/gudhi/IO/output_meshes_to_medit.h @@ -12,8 +12,15 @@ #define IO_OUTPUT_MESHES_TO_MEDIT_H_ #include <gudhi/IO/Mesh_medit.h> + #include <Eigen/Dense> -#include <fstream> + +#include <cstdlib> // for std::size_t +#include <fstream> // for std::ofstream +#include <vector> +#include <type_traits> // for std::enable_if +#include <tuple> // for std::get +#include <utility> // for std::make_pair namespace Gudhi { |