OpenMesh

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

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
VHierarchy.hh
1 /*===========================================================================*\
2 * *
3 * OpenMesh *
4 * Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen *
5 * www.openmesh.org *
6 * *
7 *---------------------------------------------------------------------------*
8 * This file is part of OpenMesh. *
9 * *
10 * OpenMesh is free software: you can redistribute it and/or modify *
11 * it under the terms of the GNU Lesser General Public License as *
12 * published by the Free Software Foundation, either version 3 of *
13 * the License, or (at your option) any later version with the *
14 * following exceptions: *
15 * *
16 * If other files instantiate templates or use macros *
17 * or inline functions from this file, or you compile this file and *
18 * link it with other files to produce an executable, this file does *
19 * not by itself cause the resulting executable to be covered by the *
20 * GNU Lesser General Public License. This exception does not however *
21 * invalidate any other reasons why the executable file might be *
22 * covered by the GNU Lesser General Public License. *
23 * *
24 * OpenMesh is distributed in the hope that it will be useful, *
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27 * GNU Lesser General Public License for more details. *
28 * *
29 * You should have received a copy of the GNU LesserGeneral Public *
30 * License along with OpenMesh. If not, *
31 * see <http://www.gnu.org/licenses/>. *
32 * *
33 \*===========================================================================*/
34
35 /*===========================================================================*\
36 * *
37 * $Revision: 736 $ *
38 * $Date: 2012-10-08 09:30:49 +0200 (Mo, 08 Okt 2012) $ *
39 * *
40 \*===========================================================================*/
41
42 //=============================================================================
43 //
44 // CLASS newClass
45 //
46 //=============================================================================
47
48 #ifndef OPENMESH_VDPROGMESH_VHIERARCHY_HH
49 #define OPENMESH_VDPROGMESH_VHIERARCHY_HH
50
51
52 //== INCLUDES =================================================================
53
54 #include <vector>
55 #include <OpenMesh/Tools/VDPM/VHierarchyNode.hh>
56
57
58 //== FORWARDDECLARATIONS ======================================================
59
60
61 //== NAMESPACES ===============================================================
62
63 namespace OpenMesh {
64 namespace VDPM {
65
66 //== CLASS DEFINITION =========================================================
67
68
71 class OPENMESHDLLEXPORT VHierarchy
72 {
73 public:
74
75 typedef unsigned int id_t;
76
77 private:
78
79 VHierarchyNodeContainer nodes_;
80 unsigned int n_roots_;
81 unsigned char tree_id_bits_; // node_id_bits_ = 32-tree_id_bits_;
82
83 public:
84
85 VHierarchy();
86
87 void clear() { nodes_.clear(); n_roots_ = 0; }
88 unsigned char tree_id_bits() const { return tree_id_bits_; }
89 unsigned int num_roots() const { return n_roots_; }
90 unsigned int num_nodes() const { return nodes_.size(); }
91
92 VHierarchyNodeIndex generate_node_index(id_t _tree_id, id_t _node_id)
93 {
94 return VHierarchyNodeIndex(_tree_id, _node_id, tree_id_bits_);
95 }
96
97
98 void set_num_roots(unsigned int _n_roots);
99
100 VHierarchyNodeHandle root_handle(unsigned int i) const
101 {
102 return VHierarchyNodeHandle( (int)i );
103 }
104
105
106 const VHierarchyNode& node(VHierarchyNodeHandle _vhierarchynode_handle) const
107 {
108 return nodes_[_vhierarchynode_handle.idx()];
109 }
110
111
112 VHierarchyNode& node(VHierarchyNodeHandle _vhierarchynode_handle)
113 {
114 return nodes_[_vhierarchynode_handle.idx()];
115 }
116
117 VHierarchyNodeHandle add_node();
118 VHierarchyNodeHandle add_node(const VHierarchyNode &_node);
119
120 void make_children(VHierarchyNodeHandle &_parent_handle);
121
122 bool is_ancestor(VHierarchyNodeIndex _ancestor_index,
123 VHierarchyNodeIndex _descendent_index);
124
125 bool is_leaf_node(VHierarchyNodeHandle _node_handle)
126 { return nodes_[_node_handle.idx()].is_leaf(); }
127
128 bool is_root_node(VHierarchyNodeHandle _node_handle)
129 { return nodes_[_node_handle.idx()].is_root(); }
130
131
132 const OpenMesh::Vec3f& normal(VHierarchyNodeHandle _node_handle) const
133 {
134 return nodes_[_node_handle.idx()].normal();
135 }
136
137 const VHierarchyNodeIndex&
138 node_index(VHierarchyNodeHandle _node_handle) const
139 { return nodes_[_node_handle.idx()].node_index(); }
140
141 VHierarchyNodeIndex& node_index(VHierarchyNodeHandle _node_handle)
142 { return nodes_[_node_handle.idx()].node_index(); }
143
144 const VHierarchyNodeIndex&
145 fund_lcut_index(VHierarchyNodeHandle _node_handle) const
146 { return nodes_[_node_handle.idx()].fund_lcut_index(); }
147
148 VHierarchyNodeIndex& fund_lcut_index(VHierarchyNodeHandle _node_handle)
149 { return nodes_[_node_handle.idx()].fund_lcut_index(); }
150
151 const VHierarchyNodeIndex&
152 fund_rcut_index(VHierarchyNodeHandle _node_handle) const
153 { return nodes_[_node_handle.idx()].fund_rcut_index(); }
154
155 VHierarchyNodeIndex& fund_rcut_index(VHierarchyNodeHandle _node_handle)
156 { return nodes_[_node_handle.idx()].fund_rcut_index(); }
157
158 VertexHandle vertex_handle(VHierarchyNodeHandle _node_handle)
159 { return nodes_[_node_handle.idx()].vertex_handle(); }
160
161 VHierarchyNodeHandle parent_handle(VHierarchyNodeHandle _node_handle)
162 { return nodes_[_node_handle.idx()].parent_handle(); }
163
164 VHierarchyNodeHandle lchild_handle(VHierarchyNodeHandle _node_handle)
165 { return nodes_[_node_handle.idx()].lchild_handle(); }
166
167 VHierarchyNodeHandle rchild_handle(VHierarchyNodeHandle _node_handle)
168 { return nodes_[_node_handle.idx()].rchild_handle(); }
169
170 VHierarchyNodeHandle node_handle(VHierarchyNodeIndex _node_index);
171
172 private:
173
174 VHierarchyNodeHandle compute_dependency(VHierarchyNodeIndex index0,
175 VHierarchyNodeIndex index1);
176
177 };
178
179
180
181 //=============================================================================
182 } // namespace VDPM
183 } // namespace OpenMesh
184 //=============================================================================
185 #endif // OPENMESH_VDPROGMESH_VHIERARCHY_HH defined
186 //=============================================================================