Loading...
Searching...
No Matches
Cell_complex.h
1/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
2 * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
3 * Author(s): Siargey Kachanovich
4 *
5 * Copyright (C) 2019 Inria
6 *
7 * Modification(s):
8 * - YYYY/MM Author: Description of the modification
9 */
10
11#ifndef CELL_COMPLEX_H_
12#define CELL_COMPLEX_H_
13
14#include <Eigen/Dense>
15
16#include <vector>
17#include <map>
18#include <utility> // for std::make_pair
19
20#include <gudhi/IO/output_debug_traces_to_html.h> // for DEBUG_TRACES
21#include <gudhi/Permutahedral_representation/Simplex_comparator.h>
22#include <gudhi/Coxeter_triangulation/Cell_complex/Hasse_diagram_cell.h> // for Hasse_cell
23
24namespace Gudhi {
25
26namespace coxeter_triangulation {
27
40template <class Out_simplex_map_>
42 public:
46 using Simplex_handle = typename Out_simplex_map_::key_type;
57 using Simplex_cell_map = std::map<Simplex_handle, Hasse_cell*, Simplex_comparator<Simplex_handle> >;
61 using Simplex_cell_maps = std::vector<Simplex_cell_map>;
62
66 using Cell_simplex_map = std::map<Hasse_cell*, Simplex_handle>;
67
71 using Cell_point_map = std::map<Hasse_cell*, Eigen::VectorXd>;
72
73 private:
74 Hasse_cell* insert_cell(const Simplex_handle& simplex, std::size_t cell_d, bool is_boundary) {
75 Simplex_cell_maps& simplex_cell_maps = (is_boundary ? boundary_simplex_cell_maps_ : interior_simplex_cell_maps_);
76#ifdef DEBUG_TRACES
77 CC_detail_list& cc_detail_list =
78 (is_boundary ? cc_boundary_detail_lists[cell_d] : cc_interior_detail_lists[cell_d]);
79 cc_detail_list.emplace_back(simplex);
80#endif
81 Simplex_cell_map& simplex_cell_map = simplex_cell_maps[cell_d];
82 auto map_it = simplex_cell_map.find(simplex);
83 if (map_it == simplex_cell_map.end()) {
84 hasse_cells_.push_back(new Hasse_cell(is_boundary, cell_d));
85 Hasse_cell* new_cell = hasse_cells_.back();
86 simplex_cell_map.emplace(simplex, new_cell);
87 cell_simplex_map_.emplace(new_cell, simplex);
88#ifdef DEBUG_TRACES
89 cc_detail_list.back().status_ = CC_detail_info::Result_type::inserted;
90#endif
91 return new_cell;
92 }
93#ifdef DEBUG_TRACES
94 CC_detail_info& cc_info = cc_detail_list.back();
95 cc_info.trigger_ = to_string(map_it->first);
96 cc_info.status_ = CC_detail_info::Result_type::self;
97#endif
98 return map_it->second;
99 }
100
101 void expand_level(std::size_t cell_d) {
102 bool is_manifold_with_boundary = boundary_simplex_cell_maps_.size() > 0;
103 for (auto& sc_pair : interior_simplex_cell_maps_[cell_d - 1]) {
104 const Simplex_handle& simplex = sc_pair.first;
105 Hasse_cell* cell = sc_pair.second;
106 for (Simplex_handle coface : simplex.coface_range(cod_d_ + cell_d)) {
107 Hasse_cell* new_cell = insert_cell(coface, cell_d, false);
108 new_cell->get_boundary().emplace_back(cell, 1);
109 }
110 }
111
112 if (is_manifold_with_boundary) {
113 for (auto& sc_pair : boundary_simplex_cell_maps_[cell_d - 1]) {
114 const Simplex_handle& simplex = sc_pair.first;
115 Hasse_cell* cell = sc_pair.second;
116 if (cell_d != intr_d_)
117 for (Simplex_handle coface : simplex.coface_range(cod_d_ + cell_d + 1)) {
118 Hasse_cell* new_cell = insert_cell(coface, cell_d, true);
119 new_cell->get_boundary().emplace_back(cell, 1);
120 }
121 auto map_it = interior_simplex_cell_maps_[cell_d].find(simplex);
122 if (map_it == interior_simplex_cell_maps_[cell_d].end())
123 std::cerr << "Cell_complex::expand_level error: A boundary cell does not have an interior counterpart.\n";
124 else {
125 Hasse_cell* i_cell = map_it->second;
126 i_cell->get_boundary().emplace_back(cell, 1);
127 }
128 }
129 }
130 }
131
132 void construct_complex_(const Out_simplex_map_& out_simplex_map) {
133#ifdef DEBUG_TRACES
134 cc_interior_summary_lists.resize(interior_simplex_cell_maps_.size());
135 cc_interior_prejoin_lists.resize(interior_simplex_cell_maps_.size());
136 cc_interior_detail_lists.resize(interior_simplex_cell_maps_.size());
137#endif
138 for (auto& os_pair : out_simplex_map) {
139 const Simplex_handle& simplex = os_pair.first;
140 const Eigen::VectorXd& point = os_pair.second;
141 Hasse_cell* new_cell = insert_cell(simplex, 0, false);
142 cell_point_map_.emplace(new_cell, point);
143 }
144 for (std::size_t cell_d = 1;
145 cell_d < interior_simplex_cell_maps_.size() && !interior_simplex_cell_maps_[cell_d - 1].empty(); ++cell_d) {
146 expand_level(cell_d);
147 }
148 }
149
150 void construct_complex_(const Out_simplex_map_& interior_simplex_map, const Out_simplex_map_& boundary_simplex_map) {
151#ifdef DEBUG_TRACES
152 cc_interior_summary_lists.resize(interior_simplex_cell_maps_.size());
153 cc_interior_prejoin_lists.resize(interior_simplex_cell_maps_.size());
154 cc_interior_detail_lists.resize(interior_simplex_cell_maps_.size());
155 cc_boundary_summary_lists.resize(boundary_simplex_cell_maps_.size());
156 cc_boundary_prejoin_lists.resize(boundary_simplex_cell_maps_.size());
157 cc_boundary_detail_lists.resize(boundary_simplex_cell_maps_.size());
158#endif
159 for (auto& os_pair : boundary_simplex_map) {
160 const Simplex_handle& simplex = os_pair.first;
161 const Eigen::VectorXd& point = os_pair.second;
162 Hasse_cell* new_cell = insert_cell(simplex, 0, true);
163 cell_point_map_.emplace(new_cell, point);
164 }
165 for (auto& os_pair : interior_simplex_map) {
166 const Simplex_handle& simplex = os_pair.first;
167 const Eigen::VectorXd& point = os_pair.second;
168 Hasse_cell* new_cell = insert_cell(simplex, 0, false);
169 cell_point_map_.emplace(new_cell, point);
170 }
171#ifdef DEBUG_TRACES
172 for (const auto& sc_pair : interior_simplex_cell_maps_[0])
173 cc_interior_summary_lists[0].push_back(CC_summary_info(sc_pair));
174 for (const auto& sc_pair : boundary_simplex_cell_maps_[0])
175 cc_boundary_summary_lists[0].push_back(CC_summary_info(sc_pair));
176#endif
177
178 for (std::size_t cell_d = 1;
179 cell_d < interior_simplex_cell_maps_.size() && !interior_simplex_cell_maps_[cell_d - 1].empty(); ++cell_d) {
180 expand_level(cell_d);
181
182#ifdef DEBUG_TRACES
183 for (const auto& sc_pair : interior_simplex_cell_maps_[cell_d])
184 cc_interior_summary_lists[cell_d].push_back(CC_summary_info(sc_pair));
185 if (cell_d < boundary_simplex_cell_maps_.size())
186 for (const auto& sc_pair : boundary_simplex_cell_maps_[cell_d])
187 cc_boundary_summary_lists[cell_d].push_back(CC_summary_info(sc_pair));
188#endif
189 }
190 }
191
192 public:
202 void construct_complex(const Out_simplex_map_& out_simplex_map) {
203 interior_simplex_cell_maps_.resize(intr_d_ + 1);
204 if (!out_simplex_map.empty()) cod_d_ = out_simplex_map.begin()->first.dimension();
205 construct_complex_(out_simplex_map);
206 }
207
219 void construct_complex(const Out_simplex_map_& out_simplex_map, std::size_t limit_dimension) {
220 interior_simplex_cell_maps_.resize(limit_dimension + 1);
221 if (!out_simplex_map.empty()) cod_d_ = out_simplex_map.begin()->first.dimension();
222 construct_complex_(out_simplex_map);
223 }
224
237 void construct_complex(const Out_simplex_map_& interior_simplex_map, const Out_simplex_map_& boundary_simplex_map) {
238 interior_simplex_cell_maps_.resize(intr_d_ + 1);
239 boundary_simplex_cell_maps_.resize(intr_d_);
240 if (!interior_simplex_map.empty()) cod_d_ = interior_simplex_map.begin()->first.dimension();
241 construct_complex_(interior_simplex_map, boundary_simplex_map);
242 }
243
258 void construct_complex(const Out_simplex_map_& interior_simplex_map, const Out_simplex_map_& boundary_simplex_map,
259 std::size_t limit_dimension) {
260 interior_simplex_cell_maps_.resize(limit_dimension + 1);
261 boundary_simplex_cell_maps_.resize(limit_dimension);
262 if (!interior_simplex_map.empty()) cod_d_ = interior_simplex_map.begin()->first.dimension();
263 construct_complex_(interior_simplex_map, boundary_simplex_map);
264 }
265
269 std::size_t intrinsic_dimension() const { return intr_d_; }
270
276 const Simplex_cell_maps& interior_simplex_cell_maps() const { return interior_simplex_cell_maps_; }
277
283 const Simplex_cell_maps& boundary_simplex_cell_maps() const { return boundary_simplex_cell_maps_; }
284
292 const Simplex_cell_map& interior_simplex_cell_map(std::size_t cell_d) const {
293 return interior_simplex_cell_maps_[cell_d];
294 }
295
303 const Simplex_cell_map& boundary_simplex_cell_map(std::size_t cell_d) const {
304 return boundary_simplex_cell_maps_[cell_d];
305 }
306
312 const Cell_simplex_map& cell_simplex_map() const { return cell_simplex_map_; }
313
318 const Cell_point_map& cell_point_map() const { return cell_point_map_; }
319
326
327 ~Cell_complex() {
328 for (Hasse_cell* hs_ptr : hasse_cells_) delete hs_ptr;
329 }
330
331 private:
332 std::size_t intr_d_, cod_d_;
333 Simplex_cell_maps interior_simplex_cell_maps_, boundary_simplex_cell_maps_;
334 Cell_simplex_map cell_simplex_map_;
335 Cell_point_map cell_point_map_;
336 std::vector<Hasse_cell*> hasse_cells_;
337};
338
339} // namespace coxeter_triangulation
340
341} // namespace Gudhi
342
343#endif
Data structure to store a cell in a Hasse diagram.
Definition Hasse_diagram_cell.h:49
A class that constructs the cell complex from the output provided by the class Gudhi::coxeter_triangu...
Definition Cell_complex.h:41
const Cell_point_map & cell_point_map() const
Returns a map from the vertex cells in the cell complex of type Gudhi::Hasse_cell to their Cartesian ...
Definition Cell_complex.h:318
std::map< Hasse_cell *, Eigen::VectorXd > Cell_point_map
Type of a map from vertex cells in the cell complex to the permutahedral representations of their Car...
Definition Cell_complex.h:71
void construct_complex(const Out_simplex_map_ &out_simplex_map, std::size_t limit_dimension)
Constructs the skeleton of the cell complex that approximates an -dimensional manifold without bounda...
Definition Cell_complex.h:219
const Simplex_cell_maps & interior_simplex_cell_maps() const
Returns a vector of maps from the cells of various dimensions in the interior of the cell complex of ...
Definition Cell_complex.h:276
std::map< Hasse_cell *, Simplex_handle > Cell_simplex_map
Type of a map from cells in the cell complex to the permutahedral representations of the correspondin...
Definition Cell_complex.h:66
const Simplex_cell_map & interior_simplex_cell_map(std::size_t cell_d) const
Returns a map from the cells of a given dimension in the interior of the cell complex of type Gudhi::...
Definition Cell_complex.h:292
Cell_complex(std::size_t intrinsic_dimension)
Constructor for the class Cell_complex.
Definition Cell_complex.h:325
void construct_complex(const Out_simplex_map_ &interior_simplex_map, const Out_simplex_map_ &boundary_simplex_map)
Constructs the the cell complex that approximates an -dimensional manifold with boundary embedded in ...
Definition Cell_complex.h:237
const Simplex_cell_maps & boundary_simplex_cell_maps() const
Returns a vector of maps from the cells of various dimensions on the boundary of the cell complex of ...
Definition Cell_complex.h:283
Gudhi::Hasse_diagram::Hasse_diagram_cell< int, double, bool > Hasse_cell
Type of a cell in the cell complex. Always is Gudhi::Hasse_cell from the Hasse diagram module....
Definition Cell_complex.h:52
void construct_complex(const Out_simplex_map_ &out_simplex_map)
Constructs the the cell complex that approximates an -dimensional manifold without boundary embedded ...
Definition Cell_complex.h:202
const Cell_simplex_map & cell_simplex_map() const
Returns a map from the cells in the cell complex of type Gudhi::Hasse_cell to the permutahedral repre...
Definition Cell_complex.h:312
std::vector< Simplex_cell_map > Simplex_cell_maps
Type of a vector of maps from permutahedral representations of simplices in the ambient triangulation...
Definition Cell_complex.h:61
typename Out_simplex_map_::key_type Simplex_handle
Type of a simplex in the ambient triangulation. Is a model of the concept SimplexInCoxeterTriangulati...
Definition Cell_complex.h:46
void construct_complex(const Out_simplex_map_ &interior_simplex_map, const Out_simplex_map_ &boundary_simplex_map, std::size_t limit_dimension)
Constructs the skeleton of the cell complex that approximates an -dimensional manifold with boundary ...
Definition Cell_complex.h:258
std::map< Simplex_handle, Hasse_cell *, Simplex_comparator< Simplex_handle > > Simplex_cell_map
Type of a map from permutahedral representations of simplices in the ambient triangulation to the cor...
Definition Cell_complex.h:57
const Simplex_cell_map & boundary_simplex_cell_map(std::size_t cell_d) const
Returns a map from the cells of a given dimension on the boundary of the cell complex of type Gudhi::...
Definition Cell_complex.h:303
std::size_t intrinsic_dimension() const
Returns the dimension of the cell complex.
Definition Cell_complex.h:269
Gudhi namespace.
Definition SimplicialComplexForAlpha.h:14