counter.h
1 /* This file is part of the Gudhi Library. The Gudhi library
2  * (Geometric Understanding in Higher Dimensions) is a generic C++
3  * library for computational topology.
4  *
5  * Author(s): Pawel Dlotko
6  *
7  * Copyright (C) 2015 Inria
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #ifndef BITMAP_CUBICAL_COMPLEX_COUNTER_H_
24 #define BITMAP_CUBICAL_COMPLEX_COUNTER_H_
25 
26 #include <iostream>
27 #include <vector>
28 #include <cstddef>
29 
30 namespace Gudhi {
31 
32 namespace cubical_complex {
33 
44 class counter {
45  public:
50  counter(const std::vector<unsigned>& endd) : begin(endd.size(), 0), end(endd), current(endd.size(), 0) { }
51 
56  counter(const std::vector< unsigned >& beginn, const std::vector< unsigned >& endd) : begin(beginn), end(endd), current(endd.size(), 0) {
57  if (beginn.size() != endd.size())
58  throw "In constructor of a counter, begin and end vectors do not have the same size. Program terminate";
59  }
60 
66  bool increment() {
67  std::size_t i = 0;
68  while ((i != this->end.size()) && (this->current[i] == this->end[i])) {
69  ++i;
70  }
71 
72  if (i == this->end.size())return false;
73  ++this->current[i];
74  for (std::size_t j = 0; j != i; ++j) {
75  this->current[j] = this->begin[j];
76  }
77  return true;
78  }
79 
83  bool isFinal() {
84  for (std::size_t i = 0; i != this->current.size(); ++i) {
85  if (this->current[i] == this->end[i])return true;
86  }
87  return false;
88  }
89 
95  std::vector< unsigned > find_opposite(const std::vector< bool >& directionsForPeriodicBCond) {
96  std::vector< unsigned > result;
97  for (std::size_t i = 0; i != this->current.size(); ++i) {
98  if ((this->current[i] == this->end[i]) && (directionsForPeriodicBCond[i] == true)) {
99  result.push_back(this->begin[i]);
100  } else {
101  result.push_back(this->current[i]);
102  }
103  }
104  return result;
105  }
106 
110  std::vector< bool > directions_of_finals() {
111  std::vector< bool > result;
112  for (std::size_t i = 0; i != this->current.size(); ++i) {
113  if (this->current[i] == this->end[i]) {
114  result.push_back(true);
115  } else {
116  result.push_back(false);
117  }
118  }
119  return result;
120  }
121 
125  friend std::ostream& operator<<(std::ostream& out, const counter& c) {
126  // std::cerr << "c.current.size() : " << c.current.size() << endl;
127  for (std::size_t i = 0; i != c.current.size(); ++i) {
128  out << c.current[i] << " ";
129  }
130  return out;
131  }
132 
133  private:
134  std::vector< unsigned > begin;
135  std::vector< unsigned > end;
136  std::vector< unsigned > current;
137 };
138 
139 } // namespace cubical_complex
140 
141 namespace Cubical_complex = cubical_complex;
142 
143 } // namespace Gudhi
144 
145 #endif // BITMAP_CUBICAL_COMPLEX_COUNTER_H_
bool isFinal()
Definition: counter.h:83
bool increment()
Definition: counter.h:66
std::vector< unsigned > find_opposite(const std::vector< bool > &directionsForPeriodicBCond)
Definition: counter.h:95
Definition: SimplicialComplexForAlpha.h:26
This is an implementation of a counter being a vector of integers.
Definition: counter.h:44
counter(const std::vector< unsigned > &endd)
Definition: counter.h:50
friend std::ostream & operator<<(std::ostream &out, const counter &c)
Definition: counter.h:125
std::vector< bool > directions_of_finals()
Definition: counter.h:110
counter(const std::vector< unsigned > &beginn, const std::vector< unsigned > &endd)
Definition: counter.h:56
GUDHI  Version 2.2.0  - C++ library for Topological Data Analysis (TDA) and Higher Dimensional Geometry Understanding.  - Copyright : GPL v3 Generated on Thu Jun 14 2018 15:00:54 for GUDHI by Doxygen 1.8.13