00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 #ifndef OPENMESH_VDPROGMESH_VHIERARCHYWINDOWS_HH
00049 #define OPENMESH_VDPROGMESH_VHIERARCHYWINDOWS_HH
00050
00051
00052
00053
00054 #include <OpenMesh/Tools/VDPM/VHierarchy.hh>
00055
00056
00057
00058
00059
00060
00061
00062 namespace OpenMesh {
00063 namespace VDPM {
00064
00065
00066
00067
00070 class VHierarchyWindow
00071 {
00072 private:
00073
00074
00075 VHierarchy *vhierarchy_;
00076
00077
00078 unsigned char *buffer_;
00079 int buffer_min_;
00080 int buffer_max_;
00081 int current_pos_;
00082
00083
00084 int window_min_;
00085 int window_max_;
00086
00087
00088
00089 unsigned char n_shift_;
00090
00091 unsigned char flag8(unsigned char n_shift) const
00092 { return 0x80 >> n_shift; }
00093
00094 unsigned char flag8(VHierarchyNodeHandle _node_handle) const
00095 {
00096 assert(_node_handle.idx() >= 0);
00097 return 0x80 >> (unsigned int) (_node_handle.idx() % 8);
00098 }
00099 int byte_idx(VHierarchyNodeHandle _node_handle) const
00100 {
00101 assert(_node_handle.idx() >= 0);
00102 return _node_handle.idx() / 8;
00103 }
00104 int buffer_idx(VHierarchyNodeHandle _node_handle) const
00105 { return byte_idx(_node_handle) - buffer_min_; }
00106
00107 bool before_window(VHierarchyNodeHandle _node_handle) const
00108 { return (_node_handle.idx()/8 < window_min_) ? true : false; }
00109
00110 bool after_window(VHierarchyNodeHandle _node_handle) const
00111 { return (_node_handle.idx()/8 < window_max_) ? false : true; }
00112
00113 bool underflow(VHierarchyNodeHandle _node_handle) const
00114 { return (_node_handle.idx()/8 < buffer_min_) ? true : false; }
00115
00116 bool overflow(VHierarchyNodeHandle _node_handle) const
00117 { return (_node_handle.idx()/8 < buffer_max_) ? false : true; }
00118
00119 bool update_buffer(VHierarchyNodeHandle _node_handle);
00120
00121 public:
00122 VHierarchyWindow();
00123 VHierarchyWindow(VHierarchy &_vhierarchy);
00124 ~VHierarchyWindow(void);
00125
00126 void set_vertex_hierarchy(VHierarchy &_vhierarchy)
00127 { vhierarchy_ = &_vhierarchy; }
00128
00129 void begin()
00130 {
00131 int new_window_min = window_min_;
00132 for (current_pos_=window_min_-buffer_min_;
00133 current_pos_ < window_size(); ++current_pos_)
00134 {
00135 if (buffer_[current_pos_] == 0)
00136 ++new_window_min;
00137 else
00138 {
00139 n_shift_ = 0;
00140 while ((buffer_[current_pos_] & flag8(n_shift_)) == 0)
00141 ++n_shift_;
00142 break;
00143 }
00144 }
00145 window_min_ = new_window_min;
00146 }
00147
00148 void next()
00149 {
00150 ++n_shift_;
00151 if (n_shift_ == 8)
00152 {
00153 n_shift_ = 0;
00154 ++current_pos_;
00155 }
00156
00157 while (current_pos_ < window_max_-buffer_min_)
00158 {
00159 if (buffer_[current_pos_] != 0)
00160 {
00161 while (n_shift_ != 8)
00162 {
00163 if ((buffer_[current_pos_] & flag8(n_shift_)) != 0)
00164 return;
00165 ++n_shift_;
00166 }
00167 }
00168 n_shift_ = 0;
00169 ++current_pos_;
00170 }
00171 }
00172 bool end() { return !(current_pos_ < window_max_-buffer_min_); }
00173
00174 int window_size() const { return window_max_ - window_min_; }
00175 int buffer_size() const { return buffer_max_ - buffer_min_; }
00176
00177 VHierarchyNodeHandle node_handle()
00178 {
00179 return VHierarchyNodeHandle(8*(buffer_min_+current_pos_) + (int)n_shift_);
00180 }
00181
00182 void activate(VHierarchyNodeHandle _node_handle)
00183 {
00184 update_buffer(_node_handle);
00185 buffer_[buffer_idx(_node_handle)] |= flag8(_node_handle);
00186 window_min_ = std::min(window_min_, byte_idx(_node_handle));
00187 window_max_ = std::max(window_max_, 1+byte_idx(_node_handle));
00188 }
00189
00190
00191 void inactivate(VHierarchyNodeHandle _node_handle)
00192 {
00193 if (is_active(_node_handle) != true) return;
00194 buffer_[buffer_idx(_node_handle)] ^= flag8(_node_handle);
00195 }
00196
00197
00198 bool is_active(VHierarchyNodeHandle _node_handle) const
00199 {
00200 if (before_window(_node_handle) == true ||
00201 after_window(_node_handle) == true)
00202 return false;
00203 return ((buffer_[buffer_idx(_node_handle)] & flag8(_node_handle)) > 0);
00204 }
00205
00206 void init(VHierarchyNodeHandleContainer &_roots);
00207 void update_with_vsplit(VHierarchyNodeHandle _parent_handle);
00208 void update_with_ecol(VHierarchyNodeHandle _parent_handle);
00209 };
00210
00211
00212 }
00213 }
00214
00215 #endif // OPENMESH_VDPROGMESH_VHIERARCHYWINDOWS_HH
00216
00217