fixed edge display for volume cells
[engrid-github.git] / src / libengrid / checkerboardgraphiterator.h
blobff0973e35a07192a08b657726ce597d3c039d64a
1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 // + +
3 // + This file is part of enGrid. +
4 // + +
5 // + Copyright 2008-2014 enGits GmbH +
6 // + +
7 // + enGrid is free software: you can redistribute it and/or modify +
8 // + it under the terms of the GNU General Public License as published by +
9 // + the Free Software Foundation, either version 3 of the License, or +
10 // + (at your option) any later version. +
11 // + +
12 // + enGrid is distributed in the hope that it will be useful, +
13 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
14 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
15 // + GNU General Public License for more details. +
16 // + +
17 // + You should have received a copy of the GNU General Public License +
18 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
19 // + +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22 #ifndef CHECKERBOARDGRAPHITERATOR_H
23 #define CHECKERBOARDGRAPHITERATOR_H
25 #include <vector>
27 using namespace std;
29 template <typename TGraph>
30 class CheckerBoardGraphIterator
33 typedef typename TGraph::index_type index_t;
35 TGraph* m_Graph;
36 index_t m_CurrentIndex;
37 index_t m_DoneCount;
38 vector<bool> m_Available;
39 vector<bool> m_Done;
40 bool m_UpdateRequired;
42 public:
44 CheckerBoardGraphIterator() { m_Graph = NULL; }
45 CheckerBoardGraphIterator(TGraph* graph) { m_Graph = graph; }
46 void setGraph(TGraph* graph) { m_Graph = graph; }
47 bool updateRequired();
48 void operator=(index_t i);
49 bool operator==(index_t i) { return m_CurrentIndex == i; }
50 bool operator<(index_t i) { return m_CurrentIndex < i; }
51 index_t operator++();
52 index_t operator*() { return m_CurrentIndex; }
56 template <typename TGraph>
57 void CheckerBoardGraphIterator<TGraph>::operator=(index_t i)
59 m_CurrentIndex = i;
60 m_Available.resize(m_Graph->size(), true);
61 m_Done.resize(m_Graph->size(), false);
62 m_DoneCount = 0;
63 m_UpdateRequired = false;
66 template <typename TGraph>
67 bool CheckerBoardGraphIterator<TGraph>::updateRequired()
69 bool update_required = m_UpdateRequired;
70 m_UpdateRequired = false;
71 return update_required;
74 template <typename TGraph>
75 typename CheckerBoardGraphIterator<TGraph>::index_t CheckerBoardGraphIterator<TGraph>::operator++()
77 if (m_Graph->size() > 0) {
78 m_Done[m_CurrentIndex] = true;
79 ++m_DoneCount;
80 for (int i = 0; i < m_Graph->getNumLinks(m_CurrentIndex); ++i) {
81 m_Available[m_Graph->getLink(m_CurrentIndex,i)] = false;
83 do {
84 ++m_CurrentIndex;
85 if (m_CurrentIndex >= m_Graph->size()) {
86 if (m_DoneCount == m_Graph->size()) {
87 break;
89 for (size_t i = 0; i < m_Available.size(); ++i) {
90 m_Available[i] = !m_Done[i];
92 m_CurrentIndex = 0;
93 m_UpdateRequired = true;
95 } while (!m_Available[m_CurrentIndex]);
97 return m_CurrentIndex;
102 #endif // CHECKERBOARDGRAPHITERATOR_H