11 #ifndef BITMAP_CUBICAL_COMPLEX_PERIODIC_BOUNDARY_CONDITIONS_BASE_H_ 12 #define BITMAP_CUBICAL_COMPLEX_PERIODIC_BOUNDARY_CONDITIONS_BASE_H_ 14 #include <gudhi/Bitmap_cubical_complex_base.h> 24 namespace cubical_complex {
56 const std::vector<unsigned>& sizes,
57 const std::vector<bool>& directions_in_which_periodic_b_cond_are_to_be_imposed);
71 const std::vector<unsigned>& dimensions,
const std::vector<T>& topDimensionalCells,
72 const std::vector<bool>& directions_in_which_periodic_b_cond_are_to_be_imposed);
119 std::vector<unsigned> coface_counter = this->compute_counter_for_given_cell(coface);
120 std::vector<unsigned> face_counter = this->compute_counter_for_given_cell(face);
123 int number_of_position_in_which_counters_do_not_agree = -1;
124 std::size_t number_of_full_faces_that_comes_before = 0;
125 for (std::size_t i = 0; i != coface_counter.size(); ++i) {
126 if ((coface_counter[i] % 2 == 1) && (number_of_position_in_which_counters_do_not_agree == -1)) {
127 ++number_of_full_faces_that_comes_before;
129 if (coface_counter[i] != face_counter[i]) {
130 if (number_of_position_in_which_counters_do_not_agree != -1) {
131 std::cout <<
"Cells given to compute_incidence_between_cells procedure do not form a pair of coface-face.\n";
132 throw std::logic_error(
133 "Cells given to compute_incidence_between_cells procedure do not form a pair of coface-face.");
135 number_of_position_in_which_counters_do_not_agree = i;
140 if (number_of_full_faces_that_comes_before % 2) incidence = -1;
142 if ((coface_counter[number_of_position_in_which_counters_do_not_agree] + 1 ==
143 face_counter[number_of_position_in_which_counters_do_not_agree]) ||
144 ((coface_counter[number_of_position_in_which_counters_do_not_agree] != 1) &&
145 (face_counter[number_of_position_in_which_counters_do_not_agree] == 0))) {
153 std::vector<bool> directions_in_which_periodic_b_cond_are_to_be_imposed;
155 void set_up_containers(
const std::vector<unsigned>& sizes) {
156 unsigned multiplier = 1;
157 for (std::size_t i = 0; i != sizes.size(); ++i) {
158 this->sizes.push_back(sizes[i]);
159 this->multipliers.push_back(multiplier);
161 if (directions_in_which_periodic_b_cond_are_to_be_imposed[i]) {
162 multiplier *= 2 * sizes[i];
164 multiplier *= 2 * sizes[i] + 1;
168 this->data = std::vector<T>(multiplier, std::numeric_limits<T>::infinity());
169 this->total_number_of_cells = multiplier;
173 const std::vector<T>& topDimensionalCells);
178 void construct_complex_based_on_top_dimensional_cells(
179 const std::vector<unsigned>& dimensions,
const std::vector<T>& topDimensionalCells,
180 const std::vector<bool>& directions_in_which_periodic_b_cond_are_to_be_imposed);
183 template <
typename T>
185 const std::vector<unsigned>& dimensions,
const std::vector<T>& topDimensionalCells,
186 const std::vector<bool>& directions_in_which_periodic_b_cond_are_to_be_imposed) {
187 this->directions_in_which_periodic_b_cond_are_to_be_imposed = directions_in_which_periodic_b_cond_are_to_be_imposed;
188 this->set_up_containers(dimensions);
198 template <
typename T>
200 const std::vector<unsigned>& sizes,
201 const std::vector<bool>& directions_in_which_periodic_b_cond_are_to_be_imposed) {
202 this->directions_in_which_periodic_b_cond_are_to_be_imposed(directions_in_which_periodic_b_cond_are_to_be_imposed);
203 this->set_up_containers(sizes);
206 template <
typename T>
208 const char* perseus_style_file) {
212 std::ifstream inFiltration;
213 inFiltration.open(perseus_style_file);
214 unsigned dimensionOfData;
215 inFiltration >> dimensionOfData;
217 this->directions_in_which_periodic_b_cond_are_to_be_imposed = std::vector<bool>(dimensionOfData,
false);
219 std::vector<unsigned> sizes;
220 sizes.reserve(dimensionOfData);
221 for (std::size_t i = 0; i != dimensionOfData; ++i) {
222 int size_in_this_dimension;
223 inFiltration >> size_in_this_dimension;
224 if (size_in_this_dimension < 0) {
225 this->directions_in_which_periodic_b_cond_are_to_be_imposed[i] =
true;
227 sizes.push_back(abs(size_in_this_dimension));
229 this->set_up_containers(sizes);
234 while (!inFiltration.eof()) {
235 double filtrationLevel;
236 inFiltration >> filtrationLevel;
237 if (inFiltration.eof())
break;
240 std::cerr <<
"Cell of an index : " << it.compute_index_in_bitmap()
242 <<
" get the value : " << filtrationLevel << std::endl;
247 inFiltration.close();
251 template <
typename T>
253 const std::vector<unsigned>& sizes) {
254 this->directions_in_which_periodic_b_cond_are_to_be_imposed = std::vector<bool>(sizes.size(),
false);
255 this->set_up_containers(sizes);
258 template <
typename T>
260 const std::vector<unsigned>& dimensions,
const std::vector<T>& topDimensionalCells) {
261 std::vector<bool> directions_in_which_periodic_b_cond_are_to_be_imposed = std::vector<bool>(dimensions.size(),
false);
262 this->construct_complex_based_on_top_dimensional_cells(dimensions, topDimensionalCells,
263 directions_in_which_periodic_b_cond_are_to_be_imposed);
266 template <
typename T>
268 const std::vector<unsigned>& dimensions,
const std::vector<T>& topDimensionalCells,
269 const std::vector<bool>& directions_in_which_periodic_b_cond_are_to_be_imposed) {
270 this->construct_complex_based_on_top_dimensional_cells(dimensions, topDimensionalCells,
271 directions_in_which_periodic_b_cond_are_to_be_imposed);
276 template <
typename T>
278 std::size_t cell)
const {
281 std::cerr <<
"Computations of boundary of a cell : " << cell << std::endl;
284 std::vector<std::size_t> boundary_elements;
285 boundary_elements.reserve(this->
dimension() * 2);
286 std::size_t cell1 = cell;
287 std::size_t sum_of_dimensions = 0;
289 for (std::size_t i = this->multipliers.size(); i != 0; --i) {
290 unsigned position = cell1 / this->multipliers[i - 1];
292 if (position % 2 == 1) {
294 if (!directions_in_which_periodic_b_cond_are_to_be_imposed[i - 1]) {
296 if (sum_of_dimensions % 2) {
297 boundary_elements.push_back(cell - this->multipliers[i - 1]);
298 boundary_elements.push_back(cell + this->multipliers[i - 1]);
300 boundary_elements.push_back(cell + this->multipliers[i - 1]);
301 boundary_elements.push_back(cell - this->multipliers[i - 1]);
304 std::cerr << cell - this->multipliers[i - 1] <<
" " << cell + this->multipliers[i - 1] <<
" ";
308 if (position != 2 * this->sizes[i - 1] - 1) {
310 if (sum_of_dimensions % 2) {
311 boundary_elements.push_back(cell - this->multipliers[i - 1]);
312 boundary_elements.push_back(cell + this->multipliers[i - 1]);
314 boundary_elements.push_back(cell + this->multipliers[i - 1]);
315 boundary_elements.push_back(cell - this->multipliers[i - 1]);
318 std::cerr << cell - this->multipliers[i - 1] <<
" " << cell + this->multipliers[i - 1] <<
" ";
322 if (sum_of_dimensions % 2) {
323 boundary_elements.push_back(cell - this->multipliers[i - 1]);
324 boundary_elements.push_back(cell - (2 * this->sizes[i - 1] - 1) * this->multipliers[i - 1]);
326 boundary_elements.push_back(cell - (2 * this->sizes[i - 1] - 1) * this->multipliers[i - 1]);
327 boundary_elements.push_back(cell - this->multipliers[i - 1]);
330 std::cerr << cell - this->multipliers[i - 1] <<
" " 331 << cell - (2 * this->sizes[i - 1] - 1) * this->multipliers[i - 1] <<
" ";
337 cell1 = cell1 % this->multipliers[i - 1];
339 return boundary_elements;
342 template <
typename T>
344 std::size_t cell)
const {
345 std::vector<unsigned>
counter = this->compute_counter_for_given_cell(cell);
346 std::vector<std::size_t> coboundary_elements;
347 std::size_t cell1 = cell;
348 for (std::size_t i = this->multipliers.size(); i != 0; --i) {
349 unsigned position = cell1 / this->multipliers[i - 1];
351 if (position % 2 == 0) {
352 if (!this->directions_in_which_periodic_b_cond_are_to_be_imposed[i - 1]) {
354 if ((counter[i - 1] != 0) && (cell > this->multipliers[i - 1])) {
355 coboundary_elements.push_back(cell - this->multipliers[i - 1]);
357 if ((counter[i - 1] != 2 * this->sizes[i - 1]) && (cell + this->multipliers[i - 1] < this->data.size())) {
358 coboundary_elements.push_back(cell + this->multipliers[i - 1]);
362 if (counter[i - 1] != 0) {
363 coboundary_elements.push_back(cell - this->multipliers[i - 1]);
364 coboundary_elements.push_back(cell + this->multipliers[i - 1]);
367 coboundary_elements.push_back(cell + this->multipliers[i - 1]);
368 coboundary_elements.push_back(cell + (2 * this->sizes[i - 1] - 1) * this->multipliers[i - 1]);
373 cell1 = cell1 % this->multipliers[i - 1];
375 return coboundary_elements;
380 namespace Cubical_complex = cubical_complex;
384 #endif // BITMAP_CUBICAL_COMPLEX_PERIODIC_BOUNDARY_CONDITIONS_BASE_H_ void impose_lower_star_filtration()
Definition: Bitmap_cubical_complex_base.h:784
unsigned dimension() const
Definition: Bitmap_cubical_complex_base.h:195
T & get_cell_data(std::size_t cell)
Definition: Bitmap_cubical_complex_base.h:779
Cubical complex with periodic boundary conditions represented as a bitmap.
Definition: Bitmap_cubical_complex_periodic_boundary_conditions_base.h:40
Cubical complex represented as a bitmap, class with basic implementation.
Definition: Bitmap_cubical_complex_base.h:51
unsigned get_dimension_of_a_cell(std::size_t cell) const
Definition: Bitmap_cubical_complex_base.h:755
Definition: SimplicialComplexForAlpha.h:14
virtual int compute_incidence_between_cells(std::size_t coface, std::size_t face)
Definition: Bitmap_cubical_complex_periodic_boundary_conditions_base.h:117
This is an implementation of a counter being a vector of integers.
Definition: counter.h:32
Bitmap_cubical_complex_periodic_boundary_conditions_base()
Definition: Bitmap_cubical_complex_periodic_boundary_conditions_base.h:47
Top_dimensional_cells_iterator top_dimensional_cells_iterator_end()
Definition: Bitmap_cubical_complex_base.h:432
Top_dimensional_cells_iterator top_dimensional_cells_iterator_begin()
Definition: Bitmap_cubical_complex_base.h:424
virtual std::vector< std::size_t > get_boundary_of_a_cell(std::size_t cell) const
Definition: Bitmap_cubical_complex_periodic_boundary_conditions_base.h:277
virtual ~Bitmap_cubical_complex_periodic_boundary_conditions_base()
Definition: Bitmap_cubical_complex_periodic_boundary_conditions_base.h:77
virtual std::vector< std::size_t > get_coboundary_of_a_cell(std::size_t cell) const
Definition: Bitmap_cubical_complex_periodic_boundary_conditions_base.h:343
Iterator through top dimensional cells of the complex. The cells appear in order they are stored in t...
Definition: Bitmap_cubical_complex_base.h:346