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_VHIERARCHY_HH
00049 #define OPENMESH_VDPROGMESH_VHIERARCHY_HH
00050
00051
00052
00053
00054 #include <vector>
00055 #include <OpenMesh/Tools/VDPM/VHierarchyNode.hh>
00056
00057
00058
00059
00060
00061
00062
00063 namespace OpenMesh {
00064 namespace VDPM {
00065
00066
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_;
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 }
00183 }
00184
00185 #endif // OPENMESH_VDPROGMESH_VHIERARCHY_HH defined
00186