Coupure prévue mardi 3 Août au matin pour maintenance du serveur. Nous faisons au mieux pour que celle-ci soit la plus brève possible.

bertram.h 11.5 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg           *
*                                                                              *
* This library is free software; you can redistribute it and/or modify it      *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your     *
* option) any later version.                                                   *
*                                                                              *
* This library is distributed in the hope that it will be useful, but WITHOUT  *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or        *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License  *
* for more details.                                                            *
*                                                                              *
* You should have received a copy of the GNU Lesser General Public License     *
* along with this library; if not, write to the Free Software Foundation,      *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
*                                                                              *
* Web site: http://cgogn.unistra.fr/                                           *
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

untereiner's avatar
untereiner committed
25
26
#ifndef __2MR_BERTRAM_FILTER__
#define __2MR_BERTRAM_FILTER__
27
28
29
30
31
32
33
34
35
36
37
38

#include <cmath>
#include "Algo/Geometry/centroid.h"
#include "Algo/Modelisation/tetrahedralization.h"
#include "Algo/Multiresolution/filter.h"

namespace CGoGN
{

namespace Algo
{

39
40
41
namespace Surface
{

42
43
44
45
46
47
48
49
50
namespace MR
{

namespace Primal
{

namespace Filters
{

untereiner's avatar
untereiner committed
51
52
53
/*********************************************************************************
 *                           ANALYSIS FILTERS
 *********************************************************************************/
54
55
56

//w-lift(a)
template <typename PFP>
untereiner's avatar
untereiner committed
57
class Ber02OddAnalysisFilter : public Algo::MR::Filter
58
59
60
61
62
63
64
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;
	typename PFP::VEC3::DATA_TYPE m_a;

public:
untereiner's avatar
untereiner committed
65
	Ber02OddAnalysisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p, typename PFP::VEC3::DATA_TYPE a) : m_map(m), m_position(p), m_a(a)
66
67
68
	{}

	void operator() ()
untereiner's avatar
untereiner committed
69
	{
70
71
72
73
74
75
76
77
		TraversorE<typename PFP::MAP> travE(m_map) ;
		for (Dart d = travE.begin(); d != travE.end(); d = travE.next())
		{
			typename PFP::VEC3 ve = (m_position[d] + m_position[m_map.phi1(d)]) * typename PFP::REAL(0.5);
			ve *= 2.0 * m_a;

			m_map.incCurrentLevel() ;
			Dart midV = m_map.phi1(d) ;
untereiner's avatar
untereiner committed
78
			m_position[midV] -= ve;
79
80
			m_map.decCurrentLevel() ;
		}
untereiner's avatar
untereiner committed
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

		TraversorF<typename PFP::MAP> travF(m_map) ;
		for (Dart d = travF.begin(); d != travF.end(); d = travF.next())
		{
			typename PFP::VEC3 vf(0.0);
			typename PFP::VEC3 ef(0.0);

			unsigned int count = 0;
			Traversor2FE<typename PFP::MAP> travFE(m_map, d);
			for (Dart dit = travFE.begin(); dit != travFE.end(); dit = travFE.next())
			{
				vf += m_position[dit];
				m_map.incCurrentLevel();
				ef += m_position[m_map.phi1(dit)];
				m_map.decCurrentLevel();
				++count;
			}
			ef /= count;
			ef *= 4.0 * m_a;

			vf /= count;
			vf *= 4.0 * m_a * m_a;

			m_map.incCurrentLevel() ;
			Dart midF = m_map.phi1(m_map.phi1(d));
untereiner's avatar
untereiner committed
106
			m_position[midF] -= vf + ef ;
untereiner's avatar
untereiner committed
107
108
109
			m_map.decCurrentLevel() ;
		}
	}
untereiner's avatar
untereiner committed
110
};
111
112
113

// s-lift(a)
template <typename PFP>
untereiner's avatar
untereiner committed
114
class Ber02EvenAnalysisFilter : public Algo::MR::Filter
115
116
117
118
119
120
121
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;
	typename PFP::VEC3::DATA_TYPE m_a;

public:
untereiner's avatar
untereiner committed
122
	Ber02EvenAnalysisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p, typename PFP::VEC3::DATA_TYPE a) : m_map(m), m_position(p), m_a(a)
123
124
125
	{}

	void operator() ()
untereiner's avatar
untereiner committed
126
	{
127
128
129
		TraversorE<typename PFP::MAP> travE(m_map);
		for(Dart d = travE.begin() ; d != travE.end() ; d = travE.next())
		{
untereiner's avatar
untereiner committed
130
131
			if(!m_map.isBoundaryEdge(d))
			{
132
133
				unsigned int count = 0;

untereiner's avatar
untereiner committed
134
				typename PFP::VEC3 fe(0);
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
				Traversor2EF<typename PFP::MAP> travEF(m_map, d);
				for(Dart dit = travEF.begin() ; dit != travEF.end() ; dit = travEF.next())
				{
					m_map.incCurrentLevel() ;
					Dart midV = m_map.phi1(m_map.phi1(dit));
					fe += m_position[midV];
					m_map.decCurrentLevel() ;
					++count;
				}

				fe /= count;
				fe *= 2 * m_a;

				m_map.incCurrentLevel() ;
				Dart midF = m_map.phi1(d);
untereiner's avatar
untereiner committed
150
				m_position[midF] -= fe;
151
				m_map.decCurrentLevel() ;
untereiner's avatar
untereiner committed
152
			}
153
		}
untereiner's avatar
untereiner committed
154
155
156
157
158
159
160
161
162
163

		TraversorV<typename PFP::MAP> travV(m_map);
		for(Dart d = travV.begin() ; d != travV.end() ; d = travV.next())
		{
			typename PFP::VEC3 ev(0.0);
			typename PFP::VEC3 fv(0.0);
			if(m_map.isBoundaryVertex(d))
			{
				Dart db = m_map.findBoundaryEdgeOfVertex(d);
				m_map.incCurrentLevel() ;
untereiner's avatar
untereiner committed
164
165
				ev += (m_position[m_map.phi1(db)] + m_position[m_map.phi_1(db)]) * typename PFP::REAL(0.5);
				//ev = (m_position[m_map.phi1(db)] + m_position[m_map.phi_1(db)]);
untereiner's avatar
untereiner committed
166
				m_map.decCurrentLevel() ;
untereiner's avatar
untereiner committed
167
168
				ev *= 2 * m_a;
				//ev *= m_a;
untereiner's avatar
untereiner committed
169

untereiner's avatar
untereiner committed
170
				m_position[d] -= ev;
untereiner's avatar
untereiner committed
171
172
173
174
			}
			else
			{
				unsigned int count = 0;
untereiner's avatar
untereiner committed
175

untereiner's avatar
untereiner committed
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
				Traversor2VF<typename PFP::MAP> travVF(m_map,d);
				for(Dart dit = travVF.begin(); dit != travVF.end() ; dit = travVF.next())
				{
					m_map.incCurrentLevel() ;

					Dart midEdgeV = m_map.phi1(dit);
					ev += m_position[midEdgeV];
					fv += m_position[m_map.phi1(midEdgeV)];

					m_map.decCurrentLevel() ;
					++count;
				}
				fv /= count;
				fv *= 4 * m_a * m_a;

				ev /= count;
				ev *= 4 * m_a;

untereiner's avatar
untereiner committed
194
				m_position[d] -= fv + ev;
untereiner's avatar
untereiner committed
195
196
197
			}
		}
	}
untereiner's avatar
untereiner committed
198
};
199
200
201

// s-scale(a)
template <typename PFP>
untereiner's avatar
untereiner committed
202
class Ber02ScaleAnalysisFilter : public Algo::MR::Filter
203
204
205
206
207
208
209
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;
	typename PFP::VEC3::DATA_TYPE m_a;

public:
untereiner's avatar
untereiner committed
210
	Ber02ScaleAnalysisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p, typename PFP::VEC3::DATA_TYPE a) : m_map(m), m_position(p), m_a(a)
211
212
213
214
	{}

	void operator() ()
	{
untereiner's avatar
untereiner committed
215
216
217
218
219
220
		TraversorE<typename PFP::MAP> travE(m_map) ;
		for (Dart d = travE.begin(); d != travE.end(); d = travE.next())
		{
			m_map.incCurrentLevel() ;
			Dart midE = m_map.phi1(d);
			if(!m_map.isBoundaryVertex(midE))
untereiner's avatar
untereiner committed
221
				m_position[midE] /= m_a ;
untereiner's avatar
untereiner committed
222
223
			m_map.decCurrentLevel() ;
		}
untereiner's avatar
untereiner committed
224
225
226
227
228
229
230
231
232

		TraversorV<typename PFP::MAP> travV(m_map) ;
		for (Dart d = travV.begin(); d != travV.end(); d = travV.next())
		{
			if(m_map.isBoundaryVertex(d))
				m_position[d] /= m_a;
			else
				m_position[d] /= m_a * m_a;
		}
untereiner's avatar
untereiner committed
233
	}
untereiner's avatar
untereiner committed
234
235
236
};


237

untereiner's avatar
untereiner committed
238
239
240
/*********************************************************************************
 *                           SYNTHESIS FILTERS
 *********************************************************************************/
241
242
243

//w-lift(a)
template <typename PFP>
untereiner's avatar
untereiner committed
244
class Ber02OddSynthesisFilter : public Algo::MR::Filter
245
246
247
248
249
250
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;
	typename PFP::VEC3::DATA_TYPE m_a;

untereiner's avatar
untereiner committed
251

252
public:
untereiner's avatar
untereiner committed
253
	Ber02OddSynthesisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p, typename PFP::VEC3::DATA_TYPE a) : m_map(m), m_position(p), m_a(a)
254
255
	{}

untereiner's avatar
untereiner committed
256
	void operator() ()
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
	{
		TraversorF<typename PFP::MAP> travF(m_map) ;
		for (Dart d = travF.begin(); d != travF.end(); d = travF.next())
		{
			typename PFP::VEC3 vf(0.0);
			typename PFP::VEC3 ef(0.0);

			unsigned int count = 0;
			Traversor2FE<typename PFP::MAP> travFE(m_map, d);
			for (Dart dit = travFE.begin(); dit != travFE.end(); dit = travFE.next())
			{
				vf += m_position[dit];
				m_map.incCurrentLevel();
				ef += m_position[m_map.phi1(dit)];
				m_map.decCurrentLevel();
				++count;
			}
			ef /= count;
			ef *= 4.0 * m_a;

			vf /= count;
			vf *= 4.0 * m_a * m_a;

			m_map.incCurrentLevel() ;
			Dart midF = m_map.phi1(m_map.phi1(d));
untereiner's avatar
untereiner committed
282
			m_position[midF] += vf + ef ;
untereiner's avatar
untereiner committed
283
284
285
286
287
288
289
290
291
292
293
			m_map.decCurrentLevel() ;

		}

		TraversorE<typename PFP::MAP> travE(m_map) ;
		for (Dart d = travE.begin(); d != travE.end(); d = travE.next())
		{
			typename PFP::VEC3 ve = (m_position[d] + m_position[m_map.phi1(d)]) * typename PFP::REAL(0.5);
			ve *= 2.0 * m_a;

			m_map.incCurrentLevel() ;
untereiner's avatar
untereiner committed
294
295
			Dart midE = m_map.phi1(d) ;
			m_position[midE] += ve;
296
297
298
			m_map.decCurrentLevel() ;
		}
	}
untereiner's avatar
untereiner committed
299
} ;
300
301
302

// s-lift(a)
template <typename PFP>
untereiner's avatar
untereiner committed
303
class Ber02EvenSynthesisFilter : public Algo::MR::Filter
304
305
306
307
308
309
310
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;
	typename PFP::VEC3::DATA_TYPE m_a;

public:
untereiner's avatar
untereiner committed
311
	Ber02EvenSynthesisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p, typename PFP::VEC3::DATA_TYPE a) : m_map(m), m_position(p), m_a(a)
312
313
	{}

untereiner's avatar
untereiner committed
314
	void operator() ()
315
316
317
318
319
320
321
322
323
324
	{
		TraversorV<typename PFP::MAP> travV(m_map);
		for(Dart d = travV.begin() ; d != travV.end() ; d = travV.next())
		{
			typename PFP::VEC3 ev(0.0);
			typename PFP::VEC3 fv(0.0);
			if(m_map.isBoundaryVertex(d))
			{
				Dart db = m_map.findBoundaryEdgeOfVertex(d);
				m_map.incCurrentLevel() ;
untereiner's avatar
untereiner committed
325
				ev += (m_position[m_map.phi1(db)] + m_position[m_map.phi_1(db)]) * typename PFP::REAL(0.5);
326
				m_map.decCurrentLevel() ;
untereiner's avatar
untereiner committed
327
				ev *= 2 * m_a;
328

untereiner's avatar
untereiner committed
329
				m_position[db] += ev;
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
			}
			else
			{
				unsigned int count = 0;
				Traversor2VF<typename PFP::MAP> travVF(m_map,d);
				for(Dart dit = travVF.begin(); dit != travVF.end() ; dit = travVF.next())
				{
					m_map.incCurrentLevel() ;

					Dart midEdgeV = m_map.phi1(dit);
					ev += m_position[midEdgeV];
					fv += m_position[m_map.phi1(midEdgeV)];

					m_map.decCurrentLevel() ;
					++count;
				}
				fv /= count;
				fv *= 4 * m_a * m_a;

				ev /= count;
				ev *= 4 * m_a;
untereiner's avatar
untereiner committed
351
				m_position[d] += fv + ev;
untereiner's avatar
untereiner committed
352
353
			}
		}
354

untereiner's avatar
untereiner committed
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
		TraversorE<typename PFP::MAP> travE(m_map);
		for(Dart d = travE.begin() ; d != travE.end() ; d = travE.next())
		{
			if(!m_map.isBoundaryEdge(d))
			{
				unsigned int count = 0;

				typename PFP::VEC3 fe(0.0);
				Traversor2EF<typename PFP::MAP> travEF(m_map, d);
				for(Dart dit = travEF.begin() ; dit != travEF.end() ; dit = travEF.next())
				{
					m_map.incCurrentLevel() ;
					Dart midV = m_map.phi1(m_map.phi1(dit));
					fe += m_position[midV];
					m_map.decCurrentLevel() ;
					++count;
				}

				fe /= count;
				fe *= 2 * m_a;

				m_map.incCurrentLevel() ;
				Dart midF = m_map.phi1(d);
untereiner's avatar
untereiner committed
378
				m_position[midF] += fe;
untereiner's avatar
untereiner committed
379
				m_map.decCurrentLevel() ;
380
381
			}
		}
untereiner's avatar
untereiner committed
382

383
	}
untereiner's avatar
untereiner committed
384
} ;
385
386
387

// s-scale(a)
template <typename PFP>
untereiner's avatar
untereiner committed
388
class Ber02ScaleSynthesisFilter : public Algo::MR::Filter
389
390
391
392
393
394
395
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;
	typename PFP::VEC3::DATA_TYPE m_a;

public:
untereiner's avatar
untereiner committed
396
	Ber02ScaleSynthesisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p, typename PFP::VEC3::DATA_TYPE a) : m_map(m), m_position(p), m_a(a)
397
398
	{}

untereiner's avatar
untereiner committed
399
	void operator() ()
400
401
402
403
404
	{
		TraversorV<typename PFP::MAP> travV(m_map) ;
		for (Dart d = travV.begin(); d != travV.end(); d = travV.next())
		{
			if(m_map.isBoundaryVertex(d))
untereiner's avatar
untereiner committed
405
				m_position[d] *= m_a;
406
			else
untereiner's avatar
untereiner committed
407
				m_position[d] *= m_a * m_a;
408
409
410
411
412
413
414
415
		}

		TraversorE<typename PFP::MAP> travE(m_map) ;
		for (Dart d = travE.begin(); d != travE.end(); d = travE.next())
		{
			m_map.incCurrentLevel() ;
			Dart midE = m_map.phi1(d);
			if(!m_map.isBoundaryVertex(midE))
untereiner's avatar
untereiner committed
416
				m_position[midE] *= m_a ;
417
418
419
			m_map.decCurrentLevel() ;
		}
	}
untereiner's avatar
untereiner committed
420
421
} ;

422
423
424
425
426
427
428
429


} // namespace Filters

} // namespace Primal

} // namespace MR

430
431
} // namespace Surface

432
433
434
435
436
} // namespace Algo

} // namespace CGoGN


untereiner's avatar
untereiner committed
437
#endif /* __2MR_FILTERS_PRIMAL__ */