Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

VHierarchyWindow.hh

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                               OpenMesh                                    *
00004  *      Copyright (C) 2001-2005 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openmesh.org                                *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------* 
00008  *                                                                           *
00009  *                                License                                    *
00010  *                                                                           *
00011  *  This library is free software; you can redistribute it and/or modify it  *
00012  *  under the terms of the GNU Library General Public License as published   *
00013  *  by the Free Software Foundation, version 2.                              *
00014  *                                                                           *
00015  *  This library is distributed in the hope that it will be useful, but      *
00016  *  WITHOUT ANY WARRANTY; without even the implied warranty of               *
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        *
00018  *  Library General Public License for more details.                         *
00019  *                                                                           *
00020  *  You should have received a copy of the GNU Library General Public        *
00021  *  License along with this library; if not, write to the Free Software      *
00022  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                *
00023  *                                                                           *
00024 \*===========================================================================*/
00025 
00026 //=============================================================================
00027 //
00028 //  CLASS newClass
00029 //
00030 //=============================================================================
00031 
00032 #ifndef OPENMESH_VDPROGMESH_VHIERARCHYWINDOWS_HH
00033 #define OPENMESH_VDPROGMESH_VHIERARCHYWINDOWS_HH
00034 
00035 
00036 //== INCLUDES =================================================================
00037 
00038 #include <OpenMesh/Tools/VDPM/VHierarchy.hh>
00039 
00040 
00041 //== FORWARDDECLARATIONS ======================================================
00042 
00043 
00044 //== NAMESPACES ===============================================================
00045 
00046 namespace OpenMesh {
00047 namespace VDPM {
00048 
00049 //== CLASS DEFINITION =========================================================
00050 
00051               
00054 class VHierarchyWindow
00055 {
00056 private:
00057 
00058   // reference of vertex hierarchy
00059   VHierarchy    *vhierarchy_;
00060 
00061   // bits buffer (byte units)
00062   unsigned char *buffer_;
00063   int           buffer_min_;
00064   int           buffer_max_;
00065   int           current_pos_;
00066 
00067   // window (byte units)
00068   int           window_min_;
00069   int           window_max_;
00070   
00071 
00072   // # of right shift (bit units)
00073   unsigned char n_shift_;           // [0, 7]
00074 
00075   unsigned char flag8(unsigned char n_shift) const
00076   { return 0x80 >> n_shift; }  
00077 
00078   unsigned char flag8(VHierarchyNodeHandle _node_handle) const
00079   {
00080     assert(_node_handle.idx() >= 0);
00081     return  0x80 >> (unsigned int) (_node_handle.idx() % 8);
00082   }
00083   int byte_idx(VHierarchyNodeHandle _node_handle) const
00084   {
00085     assert(_node_handle.idx() >= 0);
00086     return  _node_handle.idx() / 8;
00087   }
00088   int buffer_idx(VHierarchyNodeHandle _node_handle) const
00089   { return  byte_idx(_node_handle) - buffer_min_; } 
00090 
00091   bool before_window(VHierarchyNodeHandle _node_handle) const
00092   { return (_node_handle.idx()/8 < window_min_) ? true : false; }
00093 
00094   bool after_window(VHierarchyNodeHandle _node_handle) const
00095   { return (_node_handle.idx()/8 < window_max_) ? false : true; }
00096 
00097   bool underflow(VHierarchyNodeHandle _node_handle) const
00098   { return (_node_handle.idx()/8 < buffer_min_) ? true : false; }
00099 
00100   bool overflow(VHierarchyNodeHandle _node_handle) const
00101   { return (_node_handle.idx()/8 < buffer_max_) ? false : true; }  
00102 
00103   bool update_buffer(VHierarchyNodeHandle _node_handle);
00104 
00105 public:
00106   VHierarchyWindow();
00107   VHierarchyWindow(VHierarchy &_vhierarchy);
00108   ~VHierarchyWindow(void);
00109   
00110   void set_vertex_hierarchy(VHierarchy &_vhierarchy)
00111   { vhierarchy_ = &_vhierarchy; }
00112 
00113   void begin()
00114   {
00115     int new_window_min = window_min_;
00116     for (current_pos_=window_min_-buffer_min_; 
00117          current_pos_ < window_size(); ++current_pos_)
00118     {
00119       if (buffer_[current_pos_] == 0)   
00120         ++new_window_min;
00121       else
00122       {
00123         n_shift_ = 0;
00124         while ((buffer_[current_pos_] & flag8(n_shift_)) == 0)
00125           ++n_shift_;
00126         break;
00127       }
00128     }
00129     window_min_ = new_window_min;
00130   }
00131 
00132   void next()
00133   {
00134     ++n_shift_;
00135     if (n_shift_ == 8)
00136     {
00137       n_shift_ = 0;
00138       ++current_pos_;
00139     }
00140 
00141     while (current_pos_ < window_max_-buffer_min_)
00142     {
00143       if (buffer_[current_pos_] != 0) // if the current byte has non-zero bits
00144       {
00145         while (n_shift_ != 8)
00146         {
00147           if ((buffer_[current_pos_] & flag8(n_shift_)) != 0)
00148             return;                     // find 1 bit in the current byte
00149           ++n_shift_;
00150         }
00151       }
00152       n_shift_ = 0;
00153       ++current_pos_;
00154     }
00155   }
00156   bool end() { return !(current_pos_ < window_max_-buffer_min_); }
00157 
00158   int window_size() const      { return  window_max_ - window_min_; }
00159   int buffer_size() const      { return  buffer_max_ - buffer_min_; }
00160 
00161   VHierarchyNodeHandle node_handle()
00162   {
00163     return  VHierarchyNodeHandle(8*(buffer_min_+current_pos_) + (int)n_shift_);
00164   }
00165 
00166   void activate(VHierarchyNodeHandle _node_handle)
00167   {
00168     update_buffer(_node_handle);
00169     buffer_[buffer_idx(_node_handle)] |= flag8(_node_handle);
00170     window_min_ = std::min(window_min_, byte_idx(_node_handle));
00171     window_max_ = std::max(window_max_, 1+byte_idx(_node_handle));
00172   }
00173 
00174 
00175   void inactivate(VHierarchyNodeHandle _node_handle)
00176   {
00177     if (is_active(_node_handle) != true)  return;
00178     buffer_[buffer_idx(_node_handle)] ^= flag8(_node_handle);
00179   }
00180 
00181 
00182   bool is_active(VHierarchyNodeHandle _node_handle) const
00183   {
00184     if (before_window(_node_handle) == true ||
00185         after_window(_node_handle) == true)
00186       return  false;
00187     return ((buffer_[buffer_idx(_node_handle)] & flag8(_node_handle)) > 0);
00188   }
00189 
00190   void init(VHierarchyNodeHandleContainer &_roots);
00191   void update_with_vsplit(VHierarchyNodeHandle _parent_handle);
00192   void update_with_ecol(VHierarchyNodeHandle _parent_handle);
00193 };
00194 
00195 //=============================================================================
00196 } // namespace VDPM
00197 } // namespace OpenMesh
00198 //=============================================================================
00199 #endif // OPENMESH_VDPROGMESH_VHIERARCHYWINDOWS_HH
00200 //=============================================================================
00201 

acg pic Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .