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 Sophia-Saclay (France)
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 
29 namespace Gudhi {
30 
31 namespace cubical_complex {
32 
43 class counter {
44  public:
49  counter(const std::vector<unsigned>& endd) : begin(endd.size(), 0), end(endd), current(endd.size(), 0) { }
50 
55  counter(const std::vector< unsigned >& beginn, const std::vector< unsigned >& endd) : begin(beginn), end(endd), current(endd.size(), 0) {
56  if (beginn.size() != endd.size())
57  throw "In constructor of a counter, begin and end vectors do not have the same size. Program terminate";
58  }
59 
65  bool increment() {
66  size_t i = 0;
67  while ((i != this->end.size()) && (this->current[i] == this->end[i])) {
68  ++i;
69  }
70 
71  if (i == this->end.size())return false;
72  ++this->current[i];
73  for (size_t j = 0; j != i; ++j) {
74  this->current[j] = this->begin[j];
75  }
76  return true;
77  }
78 
82  bool isFinal() {
83  for (size_t i = 0; i != this->current.size(); ++i) {
84  if (this->current[i] == this->end[i])return true;
85  }
86  return false;
87  }
88 
94  std::vector< unsigned > find_opposite(const std::vector< bool >& directionsForPeriodicBCond) {
95  std::vector< unsigned > result;
96  for (size_t i = 0; i != this->current.size(); ++i) {
97  if ((this->current[i] == this->end[i]) && (directionsForPeriodicBCond[i] == true)) {
98  result.push_back(this->begin[i]);
99  } else {
100  result.push_back(this->current[i]);
101  }
102  }
103  return result;
104  }
105 
109  std::vector< bool > directions_of_finals() {
110  std::vector< bool > result;
111  for (size_t i = 0; i != this->current.size(); ++i) {
112  if (this->current[i] == this->end[i]) {
113  result.push_back(true);
114  } else {
115  result.push_back(false);
116  }
117  }
118  return result;
119  }
120 
124  friend std::ostream& operator<<(std::ostream& out, const counter& c) {
125  // std::cerr << "c.current.size() : " << c.current.size() << endl;
126  for (size_t i = 0; i != c.current.size(); ++i) {
127  out << c.current[i] << " ";
128  }
129  return out;
130  }
131 
132  private:
133  std::vector< unsigned > begin;
134  std::vector< unsigned > end;
135  std::vector< unsigned > current;
136 };
137 
138 } // namespace cubical_complex
139 
140 namespace Cubical_complex = cubical_complex;
141 
142 } // namespace Gudhi
143 
144 #endif // BITMAP_CUBICAL_COMPLEX_COUNTER_H_
bool isFinal()
Definition: counter.h:82
bool increment()
Definition: counter.h:65
std::vector< unsigned > find_opposite(const std::vector< bool > &directionsForPeriodicBCond)
Definition: counter.h:94
Definition: SimplicialComplexForAlpha.h:26
This is an implementation of a counter being a vector of integers.
Definition: counter.h:43
counter(const std::vector< unsigned > &endd)
Definition: counter.h:49
friend std::ostream & operator<<(std::ostream &out, const counter &c)
Definition: counter.h:124
std::vector< bool > directions_of_finals()
Definition: counter.h:109
counter(const std::vector< unsigned > &beginn, const std::vector< unsigned > &endd)
Definition: counter.h:55
GUDHI  Version 2.0.1  - C++ library for Topological Data Analysis (TDA) and Higher Dimensional Geometry Understanding. Generated on Mon Oct 2 2017 10:20:49 for GUDHI by doxygen 1.8.11