OpenMesh

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
VHierarchyWindow.hh
1 /*===========================================================================*\
2 * *
3 * OpenMesh *
4 * Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen *
5 * www.openmesh.org *
6 * *
7 *---------------------------------------------------------------------------*
8 * This file is part of OpenMesh. *
9 * *
10 * OpenMesh is free software: you can redistribute it and/or modify *
11 * it under the terms of the GNU Lesser General Public License as *
12 * published by the Free Software Foundation, either version 3 of *
13 * the License, or (at your option) any later version with the *
14 * following exceptions: *
15 * *
16 * If other files instantiate templates or use macros *
17 * or inline functions from this file, or you compile this file and *
18 * link it with other files to produce an executable, this file does *
19 * not by itself cause the resulting executable to be covered by the *
20 * GNU Lesser General Public License. This exception does not however *
21 * invalidate any other reasons why the executable file might be *
22 * covered by the GNU Lesser General Public License. *
23 * *
24 * OpenMesh is distributed in the hope that it will be useful, *
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27 * GNU Lesser General Public License for more details. *
28 * *
29 * You should have received a copy of the GNU LesserGeneral Public *
30 * License along with OpenMesh. If not, *
31 * see <http://www.gnu.org/licenses/>. *
32 * *
33 \*===========================================================================*/
34
35 /*===========================================================================*\
36 * *
37 * $Revision: 736 $ *
38 * $Date: 2012-10-08 09:30:49 +0200 (Mo, 08 Okt 2012) $ *
39 * *
40 \*===========================================================================*/
41
42 //=============================================================================
43 //
44 // CLASS newClass
45 //
46 //=============================================================================
47
48 #ifndef OPENMESH_VDPROGMESH_VHIERARCHYWINDOWS_HH
49 #define OPENMESH_VDPROGMESH_VHIERARCHYWINDOWS_HH
50
51
52 //== INCLUDES =================================================================
53
54 #include <OpenMesh/Tools/VDPM/VHierarchy.hh>
55
56
57 //== FORWARDDECLARATIONS ======================================================
58
59
60 //== NAMESPACES ===============================================================
61
62 namespace OpenMesh {
63 namespace VDPM {
64
65 //== CLASS DEFINITION =========================================================
66
67
70 class VHierarchyWindow
71 {
72 private:
73
74 // reference of vertex hierarchy
75 VHierarchy *vhierarchy_;
76
77 // bits buffer (byte units)
78 unsigned char *buffer_;
79 int buffer_min_;
80 int buffer_max_;
81 int current_pos_;
82
83 // window (byte units)
84 int window_min_;
85 int window_max_;
86
87
88 // # of right shift (bit units)
89 unsigned char n_shift_; // [0, 7]
90
91 unsigned char flag8(unsigned char n_shift) const
92 { return 0x80 >> n_shift; }
93
94 unsigned char flag8(VHierarchyNodeHandle _node_handle) const
95 {
96 assert(_node_handle.idx() >= 0);
97 return 0x80 >> (unsigned int) (_node_handle.idx() % 8);
98 }
99 int byte_idx(VHierarchyNodeHandle _node_handle) const
100 {
101 assert(_node_handle.idx() >= 0);
102 return _node_handle.idx() / 8;
103 }
104 int buffer_idx(VHierarchyNodeHandle _node_handle) const
105 { return byte_idx(_node_handle) - buffer_min_; }
106
107 bool before_window(VHierarchyNodeHandle _node_handle) const
108 { return (_node_handle.idx()/8 < window_min_) ? true : false; }
109
110 bool after_window(VHierarchyNodeHandle _node_handle) const
111 { return (_node_handle.idx()/8 < window_max_) ? false : true; }
112
113 bool underflow(VHierarchyNodeHandle _node_handle) const
114 { return (_node_handle.idx()/8 < buffer_min_) ? true : false; }
115
116 bool overflow(VHierarchyNodeHandle _node_handle) const
117 { return (_node_handle.idx()/8 < buffer_max_) ? false : true; }
118
119 bool update_buffer(VHierarchyNodeHandle _node_handle);
120
121 public:
122 VHierarchyWindow();
123 VHierarchyWindow(VHierarchy &_vhierarchy);
124 ~VHierarchyWindow(void);
125
126 void set_vertex_hierarchy(VHierarchy &_vhierarchy)
127 { vhierarchy_ = &_vhierarchy; }
128
129 void begin()
130 {
131 int new_window_min = window_min_;
132 for (current_pos_=window_min_-buffer_min_;
133 current_pos_ < window_size(); ++current_pos_)
134 {
135 if (buffer_[current_pos_] == 0)
136 ++new_window_min;
137 else
138 {
139 n_shift_ = 0;
140 while ((buffer_[current_pos_] & flag8(n_shift_)) == 0)
141 ++n_shift_;
142 break;
143 }
144 }
145 window_min_ = new_window_min;
146 }
147
148 void next()
149 {
150 ++n_shift_;
151 if (n_shift_ == 8)
152 {
153 n_shift_ = 0;
154 ++current_pos_;
155 }
156
157 while (current_pos_ < window_max_-buffer_min_)
158 {
159 if (buffer_[current_pos_] != 0) // if the current byte has non-zero bits
160 {
161 while (n_shift_ != 8)
162 {
163 if ((buffer_[current_pos_] & flag8(n_shift_)) != 0)
164 return; // find 1 bit in the current byte
165 ++n_shift_;
166 }
167 }
168 n_shift_ = 0;
169 ++current_pos_;
170 }
171 }
172 bool end() { return !(current_pos_ < window_max_-buffer_min_); }
173
174 int window_size() const { return window_max_ - window_min_; }
175 int buffer_size() const { return buffer_max_ - buffer_min_; }
176
177 VHierarchyNodeHandle node_handle()
178 {
179 return VHierarchyNodeHandle(8*(buffer_min_+current_pos_) + (int)n_shift_);
180 }
181
182 void activate(VHierarchyNodeHandle _node_handle)
183 {
184 update_buffer(_node_handle);
185 buffer_[buffer_idx(_node_handle)] |= flag8(_node_handle);
186 window_min_ = std::min(window_min_, byte_idx(_node_handle));
187 window_max_ = std::max(window_max_, 1+byte_idx(_node_handle));
188 }
189
190
191 void inactivate(VHierarchyNodeHandle _node_handle)
192 {
193 if (is_active(_node_handle) != true) return;
194 buffer_[buffer_idx(_node_handle)] ^= flag8(_node_handle);
195 }
196
197
198 bool is_active(VHierarchyNodeHandle _node_handle) const
199 {
200 if (before_window(_node_handle) == true ||
201 after_window(_node_handle) == true)
202 return false;
203 return ((buffer_[buffer_idx(_node_handle)] & flag8(_node_handle)) > 0);
204 }
205
206 void init(VHierarchyNodeHandleContainer &_roots);
207 void update_with_vsplit(VHierarchyNodeHandle _parent_handle);
208 void update_with_ecol(VHierarchyNodeHandle _parent_handle);
209 };
210
211 //=============================================================================
212 } // namespace VDPM
213 } // namespace OpenMesh
214 //=============================================================================
215 #endif // OPENMESH_VDPROGMESH_VHIERARCHYWINDOWS_HH
216 //=============================================================================
217