-
Notifications
You must be signed in to change notification settings - Fork 0
/
GW_QuadTreeNode.h
executable file
·267 lines (228 loc) · 10.2 KB
/
GW_QuadTreeNode.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
/*------------------------------------------------------------------------------*/
/**
* \file GW_QuadTreeNode.h
* \brief Definition of class \c GW_QuadTreeNode
* \author Gabriel Peyré
* \date 10-27-2002
*/
/*------------------------------------------------------------------------------*/
#ifndef _GW_QUADTREENODE_H_
#define _GW_QUADTREENODE_H_
#include "../gw_core/GW_Config.h"
#include "GW_QuadTreeVertex.h"
#include "GW_WaveletTransform_ABC.h"
#include "GW_DataChunk_ABC.h"
GW_BEGIN_NAMESPACE
/** Order of the vertex of the node. */
enum T_QuadTreeVert_Num
{ QT_Vert1, QT_Vert2, QT_Vert3 };
class GW_BaseMesh_ABC;
/*------------------------------------------------------------------------------*/
/**
* \class GW_QuadTreeNode
* \brief A node in a quadtree.
* \author Gabriel Peyré
* \date 10-27-2002
*
* Each node maintains :
* - 4 pointers on the 4 child nodes. They are set to \c NULL in case of a leaf node.
* - 3 pointers on the 3 vertex that define the triangle.
* In case of a non-leaf node, the node is responsible for creating the vextex (x3)
* of its child. They should be located in the middle of each segment that define the triangle.
* Of course, the node is also responsible for assigning these child vertex to its children,
* and desalocating them when needed.
*
* When computation are made on a per-vertex basis, the node is responsible for the computation on
* the vertex of its child, not on its own vertex. That's because the vertex that define the triangle
* of the node are shared with its neighboors triangles.
*
* \b Important : Remember that the name of the 3 vertex are {1,2,3}.
* So never use code as
* \begincode
* aVertex_[0] = NULL;
* \endcode
* But instead :
* \begincode
* aVertex_[QT_Vert1] = NULL;
* \endcode
*/
/*------------------------------------------------------------------------------*/
class GW_QuadTreeNode
{
public:
/*------------------------------------------------------------------------------*/
/** \name Constructor and destructor */
/*------------------------------------------------------------------------------*/
//@{
GW_QuadTreeNode();
virtual ~GW_QuadTreeNode();
//@}
/*------------------------------------------------------------------------------*/
/** \name Hierarchy management. */
/*------------------------------------------------------------------------------*/
//@{
void SetChildNode( GW_QuadTreeNode* pChild0,
GW_QuadTreeNode* pChild1,
GW_QuadTreeNode* pChild2,
GW_QuadTreeNode* pChild3 );
GW_QuadTreeNode* GetChildNode(GW_U32 Num);
GW_U32 GetDepth();
void SetDepth(GW_U32 nDepth);
GW_QuadTreeNode& GetFather();
void SetFather(GW_QuadTreeNode& Father);
GW_Bool IsLeaf();
//@}
/*------------------------------------------------------------------------------*/
/** \name Management of the 3 corner vertex. */
/*------------------------------------------------------------------------------*/
//@{
virtual void SetVertex( GW_QuadTreeVertex* pVert1,
GW_QuadTreeVertex* pVert2,
GW_QuadTreeVertex* pVert3 );
virtual void SetVertex( GW_QuadTreeVertex* pVert, GW_U32 nNum );
virtual void SetVertexNull();
virtual GW_QuadTreeVertex* GetVertex(GW_U32 Num);
virtual GW_QuadTreeVertex* GetVertex( GW_QuadTreeVertex& Vert1, GW_QuadTreeVertex& Vert2 );
virtual const GW_QuadTreeVertex* GetVertexConst(T_QuadTreeVert_Num Num) const;
virtual GW_QuadTreeVertex* GetOwnedVertex(GW_U32 nNum);
virtual void SetVertexNoMoreUsed(T_QuadTreeVert_Num Num);
GW_QuadTreeVertex* GetCompletionVertex( GW_QuadTreeVertex& Vert1, GW_QuadTreeVertex& Vert2 );
GW_QuadTreeVertex* GetVertexBetween( GW_QuadTreeVertex& Vert1, GW_QuadTreeVertex& Vert2 );
GW_I32 GetVertexNumberBetween( GW_QuadTreeVertex& Vert1, GW_QuadTreeVertex& Vert2 );
GW_I32 GetVertexNumber( GW_QuadTreeVertex& Vert );
GW_I32 GetOwnedVertexNumber( GW_QuadTreeVertex& Vert );
//@}
/*------------------------------------------------------------------------------*/
/** \name Management of the 3 central vertex (not our vertex), that we might be
responsible for. */
/*------------------------------------------------------------------------------*/
//@{
void SetResponsabilityForVertex(GW_Bool bResp, GW_U32 nNum);
GW_Bool GetResponsabilityForVertex(GW_U32 nNum);
//@}
/*------------------------------------------------------------------------------*/
/** \name Neighbor management. */
/*------------------------------------------------------------------------------*/
//@{
GW_QuadTreeNode* GetNeighbor(GW_QuadTreeVertex& Direction);
virtual GW_QuadTreeNode* GetRelativeSon(GW_QuadTreeNode& pSon, GW_QuadTreeVertex& Direction);
//@}
/*------------------------------------------------------------------------------*/
/** \name Tree-building and wavelet transform. */
/*------------------------------------------------------------------------------*/
//@{
void BuildTree(GW_BaseMesh_ABC& BaseMesh, const GW_TreeFunction_ABC& Func, GW_U32 nCurLevel, GW_U32 nMaxLevel);
//@}
//-------------------------------------------------------------------------
/** \name Id management. */
//-------------------------------------------------------------------------
//@{
void SetId(GW_U32 nID);
GW_U32 GetId();
//@}
//-------------------------------------------------------------------------
/** \name Data chunk management. */
//-------------------------------------------------------------------------
//@{
GW_DataChunk_ABC* GetDataChunk();
void SetDataChunk(GW_DataChunk_ABC& DataChunk);
//@}
//-------------------------------------------------------------------------
/** \name Value management. Use it for face base wavelets only. */
//-------------------------------------------------------------------------
//@{
void SetValue(GW_Float rVal);
GW_Float GetValue() const;
//@}
/** This is only used by compressor when making distinction
between node already processed and node to be processed */
enum T_NodeCompressionType
{
kTypeA,
kTypeB,
kTypeUndefined // this is for error check (to see if the type has *really* been set)
};
//-------------------------------------------------------------------------
/** \name Compression Type management. */
//-------------------------------------------------------------------------
//@{
T_NodeCompressionType GetCompressionType();
void SetCompressionType(T_NodeCompressionType CompressionType);
//@}
private:
enum T_NodeOrientation
{
QT_Node1, QT_Node2, QT_Node3, QT_Node4
};
/** The sons of this vertex. They are \c NULL in case of a leaf node.
\c Sons[0] is the center sub-triangle. Other triangle are labeled
using the vertex of the main triangle they contain. */
GW_QuadTreeNode* aChildNode_[4];
/**
The father node. If the node is one of the 8 root of the sphere, then the father
is the quadtree itself (that's why the class GW_QuadTree inherit from GW_QuadTreeNode).
This trick allow to use the function call
\begincode
pFather_->GetRelativeSon( this, 1 ); // 1 is the direction in which we search
\endcode
Even if we are a root node (then, it's up to the Tree itself to tell us
which node is our neighbor).
*/
GW_QuadTreeNode* pFather_;
/** The 3 vertex that compose the triangle of this node.
Remember that this node does not hold these vertex, since
they are shared among the neighboor triangle.
Trey are labeled in a counter-clock wise order.
Numbering range from 1 to 3, so use 'QT_VertX'
where X=1,2,3 to name the vertex. */
GW_QuadTreeVertex* aVertex_[3];
/** Each bool is for one of the 3 vertex of our central sub-triangle.
If we have created one of these vertex, it means we are responsible for this
vertex. */
GW_Bool aResponsibleForVertex_[3];
/** Value hold by the face. For face base transform *ONLY* */
GW_Float rVal_;
/** the depth of this node */
GW_U32 nDepth_;
/** The Id of the node in the map reprsenting all node
at a given level in the tree. */
GW_U32 nID_;
/** for face based wavelet transform ONLY :
the data chunk the transform use to store some precomputed values. */
GW_DataChunk_ABC* pDataChunk_;
/** This is only used by compressor when making distinction
between node already processed and node to be processed */
T_NodeCompressionType CompressionType_;
/** a local copy of the owned vertex, used by the destructor when the central node is destroyed */
GW_QuadTreeVertex** aOwnedVertex_;
};
/*------------------------------------------------------------------------------*/
/** \name a list of GW_QuadTreeNode */
/*------------------------------------------------------------------------------*/
//@{
typedef std::list<GW_QuadTreeNode*> T_QuadTreeNodeList;
typedef T_QuadTreeNodeList::iterator IT_QuadTreeNodeList;
typedef T_QuadTreeNodeList::reverse_iterator RIT_QuadTreeNodeList;
typedef T_QuadTreeNodeList::const_iterator CIT_QuadTreeNodeList;
typedef T_QuadTreeNodeList::const_reverse_iterator CRIT_QuadTreeNodeList;
//@}
/*------------------------------------------------------------------------------*/
/** \name a vector of GW_QuadTreeNode */
/*------------------------------------------------------------------------------*/
//@{
typedef std::vector<GW_QuadTreeNode*> T_QuadTreeNodeVector;
typedef T_QuadTreeNodeVector::iterator IT_QuadTreeNodeVector;
typedef T_QuadTreeNodeVector::reverse_iterator RIT_QuadTreeNodeVector;
typedef T_QuadTreeNodeVector::const_iterator CIT_QuadTreeNodeVector;
typedef T_QuadTreeNodeVector::const_reverse_iterator CRIT_QuadTreeNodeVector;
//@}
GW_END_NAMESPACE
#ifdef GW_USE_INLINE
#include "GW_QuadTreeNode.inl"
#endif
#endif // _GW_QUADTREENODE_H_
///////////////////////////////////////////////////////////////////////////////
// Copyright (c) Gabriel Peyré
///////////////////////////////////////////////////////////////////////////////
// END OF FILE //
///////////////////////////////////////////////////////////////////////////////