counter.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): Pawel Dlotko
4  *
5  * Copyright (C) 2015 Inria
6  *
7  * Modification(s):
8  * - YYYY/MM Author: Description of the modification
9  */
10 
11 #ifndef BITMAP_CUBICAL_COMPLEX_COUNTER_H_
12 #define BITMAP_CUBICAL_COMPLEX_COUNTER_H_
13 
14 #include <iostream>
15 #include <vector>
16 #include <cstddef>
17 
18 namespace Gudhi {
19 
20 namespace cubical_complex {
21 
32 class counter {
33  public:
38  counter(const std::vector<unsigned>& endd) : begin(endd.size(), 0), end(endd), current(endd.size(), 0) { }
39 
44  counter(const std::vector< unsigned >& beginn, const std::vector< unsigned >& endd) : begin(beginn), end(endd), current(endd.size(), 0) {
45  if (beginn.size() != endd.size())
46  throw "In constructor of a counter, begin and end vectors do not have the same size. Program terminate";
47  }
48 
54  bool increment() {
55  std::size_t i = 0;
56  while ((i != this->end.size()) && (this->current[i] == this->end[i])) {
57  ++i;
58  }
59 
60  if (i == this->end.size())return false;
61  ++this->current[i];
62  for (std::size_t j = 0; j != i; ++j) {
63  this->current[j] = this->begin[j];
64  }
65  return true;
66  }
67 
71  bool isFinal() {
72  for (std::size_t i = 0; i != this->current.size(); ++i) {
73  if (this->current[i] == this->end[i])return true;
74  }
75  return false;
76  }
77 
83  std::vector< unsigned > find_opposite(const std::vector< bool >& directionsForPeriodicBCond) {
84  std::vector< unsigned > result;
85  for (std::size_t i = 0; i != this->current.size(); ++i) {
86  if ((this->current[i] == this->end[i]) && (directionsForPeriodicBCond[i] == true)) {
87  result.push_back(this->begin[i]);
88  } else {
89  result.push_back(this->current[i]);
90  }
91  }
92  return result;
93  }
94 
98  std::vector< bool > directions_of_finals() {
99  std::vector< bool > result;
100  for (std::size_t i = 0; i != this->current.size(); ++i) {
101  if (this->current[i] == this->end[i]) {
102  result.push_back(true);
103  } else {
104  result.push_back(false);
105  }
106  }
107  return result;
108  }
109 
113  friend std::ostream& operator<<(std::ostream& out, const counter& c) {
114  // std::cerr << "c.current.size() : " << c.current.size() << endl;
115  for (std::size_t i = 0; i != c.current.size(); ++i) {
116  out << c.current[i] << " ";
117  }
118  return out;
119  }
120 
121  private:
122  std::vector< unsigned > begin;
123  std::vector< unsigned > end;
124  std::vector< unsigned > current;
125 };
126 
127 } // namespace cubical_complex
128 
129 namespace Cubical_complex = cubical_complex;
130 
131 } // namespace Gudhi
132 
133 #endif // BITMAP_CUBICAL_COMPLEX_COUNTER_H_
bool isFinal()
Definition: counter.h:71
bool increment()
Definition: counter.h:54
std::vector< unsigned > find_opposite(const std::vector< bool > &directionsForPeriodicBCond)
Definition: counter.h:83
Definition: SimplicialComplexForAlpha.h:14
This is an implementation of a counter being a vector of integers.
Definition: counter.h:32
counter(const std::vector< unsigned > &endd)
Definition: counter.h:38
friend std::ostream & operator<<(std::ostream &out, const counter &c)
Definition: counter.h:113
std::vector< bool > directions_of_finals()
Definition: counter.h:98
counter(const std::vector< unsigned > &beginn, const std::vector< unsigned > &endd)
Definition: counter.h:44
GUDHI  Version 3.1.1  - C++ library for Topological Data Analysis (TDA) and Higher Dimensional Geometry Understanding.  - Copyright : MIT Generated on Fri Feb 7 2020 16:35:36 for GUDHI by Doxygen 1.8.13