OpenMesh
OpenMesh/Tools/VDPM/VHierarchy.hh
00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                               OpenMesh                                    *
00004  *      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openmesh.org                                *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------* 
00008  *  This file is part of OpenMesh.                                           *
00009  *                                                                           *
00010  *  OpenMesh is free software: you can redistribute it and/or modify         * 
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenMesh is distributed in the hope that it will be useful,              *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenMesh.  If not,                                    *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/ 
00034 
00035 /*===========================================================================*\
00036  *                                                                           *             
00037  *   $Revision: 362 $                                                         *
00038  *   $Date: 2011-01-26 10:21:12 +0100 (Mi, 26 Jan 2011) $                   *
00039  *                                                                           *
00040 \*===========================================================================*/
00041 
00042 //=============================================================================
00043 //
00044 //  CLASS newClass
00045 //
00046 //=============================================================================
00047 
00048 #ifndef OPENMESH_VDPROGMESH_VHIERARCHY_HH
00049 #define OPENMESH_VDPROGMESH_VHIERARCHY_HH
00050 
00051 
00052 //== INCLUDES =================================================================
00053 
00054 #include <vector>
00055 #include <OpenMesh/Tools/VDPM/VHierarchyNode.hh>
00056 
00057 
00058 //== FORWARDDECLARATIONS ======================================================
00059 
00060 
00061 //== NAMESPACES ===============================================================
00062 
00063 namespace OpenMesh {
00064 namespace VDPM {
00065 
00066 //== CLASS DEFINITION =========================================================
00067 
00068               
00071 class VHierarchy
00072 {
00073 public:
00074 
00075   typedef unsigned int    id_t; 
00076 
00077 private:
00078 
00079   VHierarchyNodeContainer nodes_;
00080   unsigned int            n_roots_;
00081   unsigned char           tree_id_bits_; // node_id_bits_ = 32-tree_id_bits_;
00082 
00083 public:
00084   
00085   VHierarchy();
00086 
00087   void clear()                        { nodes_.clear();   n_roots_ = 0; }
00088   unsigned char tree_id_bits() const  { return tree_id_bits_; }
00089   unsigned int num_roots() const      { return n_roots_; }
00090   unsigned int num_nodes() const      { return nodes_.size(); }
00091 
00092   VHierarchyNodeIndex generate_node_index(id_t _tree_id, id_t _node_id)
00093   {
00094     return  VHierarchyNodeIndex(_tree_id, _node_id, tree_id_bits_);
00095   }
00096 
00097 
00098   void set_num_roots(unsigned int _n_roots);
00099   
00100   VHierarchyNodeHandle root_handle(unsigned int i) const
00101   {
00102     return  VHierarchyNodeHandle( (int)i );
00103   }
00104 
00105 
00106   const VHierarchyNode& node(VHierarchyNodeHandle _vhierarchynode_handle) const
00107   {
00108     return nodes_[_vhierarchynode_handle.idx()];
00109   }
00110 
00111 
00112   VHierarchyNode& node(VHierarchyNodeHandle _vhierarchynode_handle)
00113   {
00114     return nodes_[_vhierarchynode_handle.idx()];
00115   }
00116 
00117   VHierarchyNodeHandle add_node();
00118   VHierarchyNodeHandle add_node(const VHierarchyNode &_node);
00119 
00120   void make_children(VHierarchyNodeHandle &_parent_handle);
00121 
00122   bool is_ancestor(VHierarchyNodeIndex _ancestor_index, 
00123                    VHierarchyNodeIndex _descendent_index);
00124   
00125   bool is_leaf_node(VHierarchyNodeHandle _node_handle)  
00126   { return nodes_[_node_handle.idx()].is_leaf(); }
00127 
00128   bool is_root_node(VHierarchyNodeHandle _node_handle)  
00129   { return nodes_[_node_handle.idx()].is_root(); }
00130 
00131 
00132   const OpenMesh::Vec3f& normal(VHierarchyNodeHandle _node_handle) const  
00133   {
00134     return  nodes_[_node_handle.idx()].normal(); 
00135   }
00136 
00137   const VHierarchyNodeIndex& 
00138   node_index(VHierarchyNodeHandle _node_handle) const
00139   { return  nodes_[_node_handle.idx()].node_index(); }
00140 
00141   VHierarchyNodeIndex& node_index(VHierarchyNodeHandle _node_handle)
00142   { return  nodes_[_node_handle.idx()].node_index(); }
00143 
00144   const VHierarchyNodeIndex& 
00145   fund_lcut_index(VHierarchyNodeHandle _node_handle) const
00146   { return  nodes_[_node_handle.idx()].fund_lcut_index(); }
00147 
00148   VHierarchyNodeIndex& fund_lcut_index(VHierarchyNodeHandle _node_handle)
00149   { return  nodes_[_node_handle.idx()].fund_lcut_index(); }
00150 
00151   const VHierarchyNodeIndex& 
00152   fund_rcut_index(VHierarchyNodeHandle _node_handle) const
00153   { return  nodes_[_node_handle.idx()].fund_rcut_index(); }
00154 
00155   VHierarchyNodeIndex& fund_rcut_index(VHierarchyNodeHandle _node_handle)
00156   { return  nodes_[_node_handle.idx()].fund_rcut_index(); }     
00157   
00158   VertexHandle  vertex_handle(VHierarchyNodeHandle _node_handle)
00159   { return  nodes_[_node_handle.idx()].vertex_handle(); }
00160 
00161   VHierarchyNodeHandle  parent_handle(VHierarchyNodeHandle _node_handle)
00162   { return nodes_[_node_handle.idx()].parent_handle(); }
00163 
00164   VHierarchyNodeHandle  lchild_handle(VHierarchyNodeHandle _node_handle)
00165   { return nodes_[_node_handle.idx()].lchild_handle(); }
00166 
00167   VHierarchyNodeHandle  rchild_handle(VHierarchyNodeHandle _node_handle)
00168   { return nodes_[_node_handle.idx()].rchild_handle(); }
00169 
00170   VHierarchyNodeHandle  node_handle(VHierarchyNodeIndex _node_index);
00171 
00172 private:
00173   
00174   VHierarchyNodeHandle compute_dependency(VHierarchyNodeIndex index0, 
00175                                           VHierarchyNodeIndex index1);
00176 
00177 };
00178 
00179 
00180 
00181 //=============================================================================
00182 } // namespace VDPM
00183 } // namespace OpenMesh
00184 //=============================================================================
00185 #endif // OPENMESH_VDPROGMESH_VHIERARCHY_HH defined
00186 //=============================================================================