Developer Documentation

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

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
VHierarchyWindow.hh
1 /* ========================================================================= *
2 * *
3 * OpenMesh *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openmesh.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenMesh. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 * ========================================================================= */
41
42 /*===========================================================================*\
43 * *
44 * $Revision$ *
45 * $Date$ *
46 * *
47 \*===========================================================================*/
48
49 //=============================================================================
50 //
51 // CLASS newClass
52 //
53 //=============================================================================
54
55 #ifndef OPENMESH_VDPROGMESH_VHIERARCHYWINDOWS_HH
56 #define OPENMESH_VDPROGMESH_VHIERARCHYWINDOWS_HH
57
58
59 //== INCLUDES =================================================================
60
61 #include <OpenMesh/Tools/VDPM/VHierarchy.hh>
62 #include <algorithm>
63
64 //== FORWARDDECLARATIONS ======================================================
65
66
67 //== NAMESPACES ===============================================================
68
69 namespace OpenMesh {
70 namespace VDPM {
71
72 //== CLASS DEFINITION =========================================================
73
74
77 class VHierarchyWindow
78 {
79 private:
80
81 // reference of vertex hierarchy
82 VHierarchy *vhierarchy_;
83
84 // bits buffer (byte units)
85 unsigned char *buffer_;
86 int buffer_min_;
87 size_t buffer_max_;
88 int current_pos_;
89
90 // window (byte units)
91 int window_min_;
92 int window_max_;
93
94
95 // # of right shift (bit units)
96 unsigned char n_shift_; // [0, 7]
97
98 unsigned char flag8(unsigned char n_shift) const
99 { return 0x80 >> n_shift; }
100
101 unsigned char flag8(VHierarchyNodeHandle _node_handle) const
102 {
103 assert(_node_handle.idx() >= 0);
104 return 0x80 >> (unsigned int) (_node_handle.idx() % 8);
105 }
106 int byte_idx(VHierarchyNodeHandle _node_handle) const
107 {
108 assert(_node_handle.idx() >= 0);
109 return _node_handle.idx() / 8;
110 }
111 int buffer_idx(VHierarchyNodeHandle _node_handle) const
112 { return byte_idx(_node_handle) - buffer_min_; }
113
114 bool before_window(VHierarchyNodeHandle _node_handle) const
115 { return (_node_handle.idx()/8 < window_min_) ? true : false; }
116
117 bool after_window(VHierarchyNodeHandle _node_handle) const
118 { return (_node_handle.idx()/8 < window_max_) ? false : true; }
119
120 bool underflow(VHierarchyNodeHandle _node_handle) const
121 { return (_node_handle.idx()/8 < buffer_min_) ? true : false; }
122
123 bool overflow(VHierarchyNodeHandle _node_handle) const
124 { return (_node_handle.idx()/8 < int(buffer_max_) ) ? false : true; }
125
126 bool update_buffer(VHierarchyNodeHandle _node_handle);
127
128 public:
129 VHierarchyWindow();
130 VHierarchyWindow(VHierarchy &_vhierarchy);
131 ~VHierarchyWindow(void);
132
133 void set_vertex_hierarchy(VHierarchy &_vhierarchy)
134 { vhierarchy_ = &_vhierarchy; }
135
136 void begin()
137 {
138 int new_window_min = window_min_;
139 for (current_pos_=window_min_-buffer_min_;
140 current_pos_ < window_size(); ++current_pos_)
141 {
142 if (buffer_[current_pos_] == 0)
143 ++new_window_min;
144 else
145 {
146 n_shift_ = 0;
147 while ((buffer_[current_pos_] & flag8(n_shift_)) == 0)
148 ++n_shift_;
149 break;
150 }
151 }
152 window_min_ = new_window_min;
153 }
154
155 void next()
156 {
157 ++n_shift_;
158 if (n_shift_ == 8)
159 {
160 n_shift_ = 0;
161 ++current_pos_;
162 }
163
164 while (current_pos_ < window_max_-buffer_min_)
165 {
166 if (buffer_[current_pos_] != 0) // if the current byte has non-zero bits
167 {
168 while (n_shift_ != 8)
169 {
170 if ((buffer_[current_pos_] & flag8(n_shift_)) != 0)
171 return; // find 1 bit in the current byte
172 ++n_shift_;
173 }
174 }
175 n_shift_ = 0;
176 ++current_pos_;
177 }
178 }
179 bool end() { return !(current_pos_ < window_max_-buffer_min_); }
180
181 int window_size() const { return window_max_ - window_min_; }
182 size_t buffer_size() const { return buffer_max_ - buffer_min_; }
183
184 VHierarchyNodeHandle node_handle()
185 {
186 return VHierarchyNodeHandle(8*(buffer_min_+current_pos_) + (int)n_shift_);
187 }
188
189 void activate(VHierarchyNodeHandle _node_handle)
190 {
191 update_buffer(_node_handle);
192 buffer_[buffer_idx(_node_handle)] |= flag8(_node_handle);
193 window_min_ = std::min(window_min_, byte_idx(_node_handle));
194 window_max_ = std::max(window_max_, 1+byte_idx(_node_handle));
195 }
196
197
198 void inactivate(VHierarchyNodeHandle _node_handle)
199 {
200 if (is_active(_node_handle) != true) return;
201 buffer_[buffer_idx(_node_handle)] ^= flag8(_node_handle);
202 }
203
204
205 bool is_active(VHierarchyNodeHandle _node_handle) const
206 {
207 if (before_window(_node_handle) == true ||
208 after_window(_node_handle) == true)
209 return false;
210 return ((buffer_[buffer_idx(_node_handle)] & flag8(_node_handle)) > 0);
211 }
212
213 void init(VHierarchyNodeHandleContainer &_roots);
214 void update_with_vsplit(VHierarchyNodeHandle _parent_handle);
215 void update_with_ecol(VHierarchyNodeHandle _parent_handle);
216 };
217
218 //=============================================================================
219 } // namespace VDPM
220 } // namespace OpenMesh
221 //=============================================================================
222 #endif // OPENMESH_VDPROGMESH_VHIERARCHYWINDOWS_HH
223 //=============================================================================
224
OpenMesh
Definition: MeshItems.hh:64
OpenMesh::BaseHandle::idx
int idx() const
Get the underlying index of this handle.
Definition: Handles.hh:74
OpenMesh::VDPM::VHierarchyWindow
Definition: VHierarchyWindow.hh:77
OpenMesh::VDPM::VHierarchy
Definition: VHierarchy.hh:78
OpenMesh::VDPM::VHierarchyNodeHandle
Definition: VHierarchyNode.hh:82
OpenMesh::VDPM::VHierarchyNodeHandleContainer
std::vector< VHierarchyNodeHandle > VHierarchyNodeHandleContainer
Container for vertex hierarchy node handles.
Definition: VHierarchyNode.hh:188