-
Notifications
You must be signed in to change notification settings - Fork 0
/
GW_LinearWavelet.cpp
executable file
·371 lines (337 loc) · 13.3 KB
/
GW_LinearWavelet.cpp
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
/*------------------------------------------------------------------------------*/
/**
* \file GW_LinearWavelet.cpp
* \brief Definition of class \c GW_LinearWavelet
* \author Gabriel Peyré
* \date 10-31-2002
*/
/*------------------------------------------------------------------------------*/
#ifdef GW_SCCSID
static const char* sccsid = "@(#) GW_LinearWavelet.cpp(c) Gabriel Peyré2002";
#endif // GW_SCCSID
#include "stdafx.h"
#include "GW_LinearWavelet.h"
#include "GW_NodeMap.h"
#ifndef GW_USE_INLINE
#include "GW_LinearWavelet.inl"
#endif
using namespace GW;
/*------------------------------------------------------------------------------*/
// Name : GW_LinearWavelet::ForwardPredict
/**
* \param CurNode [GW_QuadTreeNode&] The current node.
* \author Gabriel Peyré
* \date 10-31-2002
*
* Perform a forward step.
*/
/*------------------------------------------------------------------------------*/
void GW_LinearWavelet::ForwardPredict( GW_QuadTreeNode& CurNode, GW_U32 nReverseLevel)
{
/* compute the detail coefficient for the central vertex we are responsible for */
for( GW_U32 i=0; i<3; ++i )
{
if( CurNode.GetResponsabilityForVertex(i) )
{
GW_QuadTreeVertex* pVert = CurNode.GetOwnedVertex( i );
GW_ASSERT( pVert!=NULL );
/* predict stage *************************************/
GW_U32 s = (i+1) % 3;
GW_U32 t = (i+2) % 3;
GW_QuadTreeVertex* pVert1 = CurNode.GetVertex( s );
GW_QuadTreeVertex* pVert2 = CurNode.GetVertex( t );
GW_Float rPredicted = 0.5f*( pVert1->GetValue()+pVert2->GetValue() );
pVert->SetValue( pVert->GetValue()-rPredicted );
}
}
}
/*------------------------------------------------------------------------------*/
// Name : GW_LinearWavelet::ForwardUpdate
/**
* \param CurNode [GW_QuadTreeNode&] The current node.
* \author Gabriel Peyré
* \date 10-31-2002
*
* Perform a forward step.
*/
/*------------------------------------------------------------------------------*/
void GW_LinearWavelet::ForwardUpdate( GW_QuadTreeNode& CurNode, GW_U32 nReverseLevel )
{
GW_ASSERT( nReverseLevel>0 );
/* for each vertex we are responsible for, update the value of it's neighbors */
for( GW_U32 i=0; i<3; ++i )
{
if( CurNode.GetResponsabilityForVertex(i) )
{
GW_QuadTreeVertex* pVert = CurNode.GetOwnedVertex( i );
GW_ASSERT( pVert!=NULL );
GW_U32 s = (i+1) % 3;
GW_U32 t = (i+2) % 3;
/* retrieve the integral of the central scaling function */
GW_IntegralDataChunk* pChunk = (GW_IntegralDataChunk*) pVert->GetDataChunk();
GW_ASSERT( pChunk!=NULL );
GW_ASSERT( pChunk->GetType()==T_IntegralDataChunk );
GW_Float rIntegral_Center = pChunk->GetIntegral( nReverseLevel-1 );
/* retrieve the first vertex scaling function */
GW_QuadTreeVertex* pVert1 = CurNode.GetVertex( s );
pChunk = (GW_IntegralDataChunk*) pVert1->GetDataChunk();
GW_ASSERT( pChunk!=NULL );
GW_ASSERT( pChunk->GetType()==T_IntegralDataChunk );
GW_Float rIntegral = pChunk->GetIntegral( nReverseLevel );
pVert1->SetValue( pVert1->GetValue()+rIntegral_Center/(2*rIntegral)*pVert->GetValue() );
/* retrieve the second vertex scaling function */
pVert1 = CurNode.GetVertex( t );
pChunk = (GW_IntegralDataChunk*) pVert1->GetDataChunk();
GW_ASSERT( pChunk!=NULL );
GW_ASSERT( pChunk->GetType()==T_IntegralDataChunk );
rIntegral = pChunk->GetIntegral( nReverseLevel );
pVert1->SetValue( pVert1->GetValue()+rIntegral_Center/(2*rIntegral)*pVert->GetValue() );
}
}
}
/*------------------------------------------------------------------------------*/
// Name : GW_LinearWavelet::BackwardPredict
/**
* \param CurNode [GW_QuadTreeNode&] The current node.
* \author Gabriel Peyré
* \date 10-31-2002
*
* Perform a Backward step.
*/
/*------------------------------------------------------------------------------*/
void GW_LinearWavelet::BackwardPredict( GW_QuadTreeNode& CurNode, GW_U32 nReverseLevel )
{
/* compute the detail coefficient for the central vertex we are responsible for */
for( GW_U32 i=0; i<3; ++i )
{
if( CurNode.GetResponsabilityForVertex(i) )
{
GW_QuadTreeVertex* pVert = CurNode.GetOwnedVertex( i );
GW_ASSERT( pVert!=NULL );
/* predict stage *************************************/
GW_U32 s = (i+1) % 3;
GW_U32 t = (i+2) % 3;
GW_QuadTreeVertex* pVert1 = CurNode.GetVertex( s );
GW_QuadTreeVertex* pVert2 = CurNode.GetVertex( t );
GW_Float rPredicted = 0.5f*( pVert1->GetValue()+pVert2->GetValue() );
pVert->SetValue( pVert->GetValue() + rPredicted );
}
}
}
/*------------------------------------------------------------------------------*/
// Name : GW_LinearWavelet::ForwardUpdate
/**
* \param CurNode [GW_QuadTreeNode&] The current node.
* \author Gabriel Peyré
* \date 10-31-2002
*
* Perform a forward step.
*/
/*------------------------------------------------------------------------------*/
void GW_LinearWavelet::BackwardUpdate( GW_QuadTreeNode& CurNode, GW_U32 nReverseLevel )
{
GW_ASSERT( nReverseLevel>0 );
/* compute the detail coefficient for the central vertex we are responsible for */
for( GW_U32 i=0; i<3; ++i )
{
if( CurNode.GetResponsabilityForVertex(i) )
{
GW_QuadTreeVertex* pVert = CurNode.GetOwnedVertex( i );
GW_ASSERT( pVert!=NULL );
GW_U32 s = (i+1) % 3;
GW_U32 t = (i+2) % 3;
/* retrieve the integral of the central scaling function */
GW_IntegralDataChunk* pChunk = (GW_IntegralDataChunk*) pVert->GetDataChunk();
GW_ASSERT( pChunk!=NULL );
GW_ASSERT( pChunk->GetType()==T_IntegralDataChunk );
GW_Float rIntegral_Center = pChunk->GetIntegral( nReverseLevel-1 );
/* retrieve the first vertex scaling function */
GW_QuadTreeVertex* pVert1 = CurNode.GetVertex( s );
pChunk = (GW_IntegralDataChunk*) pVert1->GetDataChunk();
GW_ASSERT( pChunk!=NULL );
GW_ASSERT( pChunk->GetType()==T_IntegralDataChunk );
GW_Float rIntegral = pChunk->GetIntegral( nReverseLevel );
pVert1->SetValue( pVert1->GetValue()-rIntegral_Center/(2*rIntegral)*pVert->GetValue() );
/* retrieve the second vertex scaling function */
pVert1 = CurNode.GetVertex( t );
pChunk = (GW_IntegralDataChunk*) pVert1->GetDataChunk();
GW_ASSERT( pChunk!=NULL );
GW_ASSERT( pChunk->GetType()==T_IntegralDataChunk );
rIntegral = pChunk->GetIntegral( nReverseLevel );
pVert1->SetValue( pVert1->GetValue()-rIntegral_Center/(2*rIntegral)*pVert->GetValue() );
}
}
}
/*------------------------------------------------------------------------------*/
// Name : GW_LinearWavelet::UpdateDataChunk
/**
* \param CurNode [GW_QuadTreeNode&] The current node
* \author Gabriel Peyré
* \date 11-12-2002
*
* Compute the integral of the vertex we are responsible for.
*/
/*------------------------------------------------------------------------------*/
void GW_LinearWavelet::UpdateDataChunk( T_NodeMapVector& NodeMapVector )
{
/* first pass to compute the integral at the highest level ********************/
RIT_NodeMapVector it = NodeMapVector.rbegin();
GW_NodeMap* pMap = *it;
GW_ASSERT( pMap!=NULL );
T_QuadTreeNodeMap* pQuadTreeNodeMap = &pMap->GetMap();
for( IT_QuadTreeNodeMap NodeTreeMapIT=pQuadTreeNodeMap->begin(); NodeTreeMapIT!=pQuadTreeNodeMap->end(); ++NodeTreeMapIT )
{
/* get the node */
GW_QuadTreeNode* pNode = NodeTreeMapIT->second;
GW_ASSERT( pNode!=NULL );
this->ComputeIntegral( *pNode );
}
/* from the node just before leaf to root *************************************/
it++;
GW_U32 nLevel = 1;
while( it != NodeMapVector.rend() )
{
pMap = *it;
GW_ASSERT( pMap!=NULL );
pQuadTreeNodeMap = &pMap->GetMap();
/* first, recopy integral from uper level */
for( IT_QuadTreeNodeMap NodeTreeMapIT=pQuadTreeNodeMap->begin(); NodeTreeMapIT!=pQuadTreeNodeMap->end(); ++NodeTreeMapIT )
{
/* get the node */
GW_QuadTreeNode* pNode = NodeTreeMapIT->second;
GW_ASSERT( pNode!=NULL );
this->RecopyIntegral( *pNode, nLevel );
}
/* then use a recursion formula */
for( IT_QuadTreeNodeMap NodeTreeMapIT=pQuadTreeNodeMap->begin(); NodeTreeMapIT!=pQuadTreeNodeMap->end(); ++NodeTreeMapIT )
{
/* get the node */
GW_QuadTreeNode* pNode = NodeTreeMapIT->second;
GW_ASSERT( pNode!=NULL );
this->RecurseIntegral( *pNode, nLevel );
}
it++;
nLevel++;
}
}
/*------------------------------------------------------------------------------*/
// Name : GW_LinearWavelet::ComputeIntegral
/**
* \param CurNode [GW_QuadTreeNode&] Curent node.
* \author Gabriel Peyré
* \date 11-12-2002
*
* Compute the integral of a node at the finest level using
* quadrature formula.
*/
/*------------------------------------------------------------------------------*/
void GW_LinearWavelet::ComputeIntegral( GW_QuadTreeNode& CurNode )
{
/* compute the integral for the 3 vertex (if needed) */
for( GW_U32 i=0; i<3; ++i )
{
GW_QuadTreeVertex* pVert = CurNode.GetVertex( i );
GW_ASSERT( pVert!=NULL );
/* if needed, create a new chunk */
GW_IntegralDataChunk* pChunk = (GW_IntegralDataChunk*) pVert->GetDataChunk();
if( pChunk==NULL )
{
pChunk = new GW_IntegralDataChunk;
pVert->SetDataChunk(*pChunk);
/* we need to compute this integral, au boulot ! */
GW_QuadTreeVertex* pCurDirection = CurNode.GetVertex( (i+1)%3 );
GW_QuadTreeVertex* pNextDirection = CurNode.GetVertex( (i+2)%3 );
GW_QuadTreeNode* pNeighbor = CurNode.GetNeighbor(*pCurDirection);
GW_Float rIntegral = GW_SphericalMaths::FlatTriangleArea(CurNode);
GW_DEBUG_ONLY( GW_U32 nCheck = 0; )
while( pNeighbor!=&CurNode )
{
GW_DEBUG_ONLY( nCheck++; )
GW_Float rArea = GW_SphericalMaths::FlatTriangleArea(*pNeighbor);
GW_ASSERT( rArea>=0 );
rIntegral += rArea;
/* check for new direction */
pCurDirection = pNextDirection;
pNextDirection = pNeighbor->GetCompletionVertex( *pVert, *pCurDirection );
GW_ASSERT( pCurDirection!=NULL );
pNeighbor = pNeighbor->GetNeighbor(*pCurDirection);
}
// GW_ASSERT( nCheck==5 || nCheck==3);
pChunk->SetIntegral( rIntegral/3, 0 ); // we are at level 0 starting from leaf
}
}
}
/*------------------------------------------------------------------------------*/
// Name : GW_LinearWavelet::RecopyIntegral
/**
* \param CurNode [GW_QuadTreeNode&] The current node.
* \param nLevel [GW_U32] The current level.
* \author Gabriel Peyré
* \date 11-13-2002
*
* Just recopy the integral from the level just before.
*/
/*------------------------------------------------------------------------------*/
void GW_LinearWavelet::RecopyIntegral( GW_QuadTreeNode& CurNode, GW_U32 nReverseLevel )
{
GW_ASSERT( nReverseLevel>0 );
/* copy the integral for the 3 vertex */
for( GW_U32 i=0; i<3; ++i )
{
GW_QuadTreeVertex* pVert = CurNode.GetVertex( i );
GW_ASSERT( pVert!=NULL );
/* the chunk should already exist */
GW_IntegralDataChunk* pChunk = (GW_IntegralDataChunk*) pVert->GetDataChunk();
GW_ASSERT( pChunk!=NULL );
GW_ASSERT( pChunk->GetType()==T_IntegralDataChunk );
/* simply recopy integral */
pChunk->SetIntegral( pChunk->GetIntegral(nReverseLevel-1), nReverseLevel );
}
}
/*------------------------------------------------------------------------------*/
// Name : GW_LinearWavelet::RecurseIntegral
/**
* \param CurNode [GW_QuadTreeNode&] Current node.
* \author Gabriel Peyré
* \date 11-12-2002
*
* Compute the integral at a node using recursion.
*/
/*------------------------------------------------------------------------------*/
void GW_LinearWavelet::RecurseIntegral( GW_QuadTreeNode& CurNode, GW_U32 nReverseLevel )
{
/* redistribuate contribution from the 3 owned vertex (the ones that disapear
between current low level and precedent level). */
for( GW_U32 i=0; i<3; ++i )
{
if( CurNode.GetResponsabilityForVertex(i) )
{
GW_QuadTreeVertex* pVert = CurNode.GetOwnedVertex( i );
GW_ASSERT( pVert!=NULL );
/* the chunk should already exist */
GW_IntegralDataChunk* pChunk = (GW_IntegralDataChunk*) pVert->GetDataChunk();
GW_ASSERT( pChunk!=NULL );
GW_ASSERT( pChunk->GetType()==T_IntegralDataChunk );
/* the numbers of the two vertex we should contribute to */
GW_U32 s = (i+1)%3;
GW_U32 t = (i+2)%3;
GW_QuadTreeVertex* pVert1 = CurNode.GetVertex( s );
GW_ASSERT( pVert1!=NULL );
GW_IntegralDataChunk* pChunk1 = (GW_IntegralDataChunk*) pVert1->GetDataChunk();
GW_ASSERT( pChunk1!=NULL );
GW_ASSERT( pChunk1->GetType()==T_IntegralDataChunk );
pChunk1->AddIntegral( 0.5f*pChunk->GetIntegral(nReverseLevel-1), nReverseLevel );
pVert1 = CurNode.GetVertex( t );
GW_ASSERT( pVert1!=NULL );
pChunk1 = (GW_IntegralDataChunk*) pVert1->GetDataChunk();
GW_ASSERT( pChunk1!=NULL );
GW_ASSERT( pChunk1->GetType()==T_IntegralDataChunk );
pChunk1->AddIntegral( 0.5f*pChunk->GetIntegral(nReverseLevel-1), nReverseLevel );
}
}
}
///////////////////////////////////////////////////////////////////////////////
// Copyright (c) Gabriel Peyré
///////////////////////////////////////////////////////////////////////////////
// END OF FILE //
///////////////////////////////////////////////////////////////////////////////