Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

lerp.h 11.4 KB
Newer Older
untereiner's avatar
untereiner committed
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
/*******************************************************************************
* 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                                        *
*                                                                              *
*******************************************************************************/

#ifndef __3MR_LERP_FILTER__
#define __3MR_LERP_FILTER__

#include <cmath>
#include "Algo/Geometry/centroid.h"
#include "Algo/Modelisation/tetrahedralization.h"
31
#include "Algo/Modelisation/polyhedron.h"
untereiner's avatar
untereiner committed
32
33
34
35
36
37
38
39
#include "Algo/Multiresolution/filter.h"

namespace CGoGN
{

namespace Algo
{

40
41
42
namespace Volume
{

untereiner's avatar
untereiner committed
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
namespace MR
{

namespace Primal
{

namespace Filters
{

/*********************************************************************************
 *                           SYNTHESIS FILTERS
 *********************************************************************************/

/* Linear Interpolation
 *********************************************************************************/
58
59
60


template <typename PFP>
61
class LerpQuadOddSynthesisFilter : public Algo::MR::Filter
62
63
64
65
66
67
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;

public:
68
	LerpQuadOddSynthesisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p) : m_map(m), m_position(p)
69
70
71
72
	{}

	void operator() ()
	{
73
74
75
		TraversorW<typename PFP::MAP> travW(m_map) ;
		for (Dart d = travW.begin(); d != travW.end(); d = travW.next())
		{
76
			typename PFP::VEC3 vc = Algo::Surface::Geometry::volumeCentroid<PFP>(m_map, d, m_position);
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

			unsigned int count = 0;
			typename PFP::VEC3 ec(0.0);
			Traversor3WE<typename PFP::MAP> travWE(m_map, d);
			for (Dart dit = travWE.begin(); dit != travWE.end(); dit = travWE.next())
			{
				m_map.incCurrentLevel();
				ec += m_position[m_map.phi1(dit)];
				m_map.decCurrentLevel();
				++count;
			}
			ec /= count;
			ec *= 3;

			count = 0;
			typename PFP::VEC3 fc(0.0);
			Traversor3WF<typename PFP::MAP> travWF(m_map, d);
			for (Dart dit = travWF.begin(); dit != travWF.end(); dit = travWF.next())
			{
				m_map.incCurrentLevel();
				fc += m_position[m_map.phi1(m_map.phi1(dit))];
				m_map.decCurrentLevel();
				++count;
			}
			fc /= count;
			fc *= 3;

			m_map.incCurrentLevel() ;
			Dart midV = m_map.phi_1(m_map.phi2(m_map.phi1(d)));
			if(m_position[midV] != typename PFP::VEC3(0.0f,0.0f,0.0f))
			{
				std::cout << "position[midV] = " << m_position[midV] << std::endl;
			}
			else
				m_position[midV] += vc + ec + fc;
			m_map.decCurrentLevel() ;
		}

		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;
			Traversor3FE<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 *= 2.0;

			vf /= count;

			m_map.incCurrentLevel() ;
			Dart midF = m_map.phi1(m_map.phi1(d));
			if(m_position[midF] != typename PFP::VEC3(0.0f,0.0f,0.0f))
			{
				std::cout << "position[midF] = " << m_position[midF] << std::endl;
				//m_position[midF] = vf + ef ;
			}
			else
				m_position[midF] += vf + ef ;
			m_map.decCurrentLevel() ;
		}

untereiner's avatar
untereiner committed
148
149
		TraversorE<typename PFP::MAP> travE(m_map) ;
		for (Dart d = travE.begin(); d != travE.end(); d = travE.next())
150
		{
151
			typename PFP::VEC3 ve = (m_position[d] + m_position[m_map.phi1(d)]) * typename PFP::REAL(0.5);
152
153

			m_map.incCurrentLevel() ;
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
			Dart midE = m_map.phi1(d) ;
			if(m_position[midE] != typename PFP::VEC3(0.0f,0.0f,0.0f))
			{
				std::cout << "position[midE] = " << m_position[midE] << std::endl;
				//m_position[midE] = ve;
			}
			else
				m_position[midE] += ve;
			m_map.decCurrentLevel() ;
		}
	}

};


169
170


171
template <typename PFP>
172
class LerpQuadOddAnalysisFilter : public Algo::MR::Filter
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;

public:
	LerpQuadOddAnalysisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p) : m_map(m), m_position(p)
	{}

	void operator() ()
	{
		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);

			m_map.incCurrentLevel() ;
			Dart midE = m_map.phi1(d) ;
			m_position[midE] -= ve;
192
193
194
			m_map.decCurrentLevel() ;
		}

untereiner's avatar
untereiner committed
195
196
		TraversorF<typename PFP::MAP> travF(m_map) ;
		for (Dart d = travF.begin(); d != travF.end(); d = travF.next())
197
		{
198
199
			typename PFP::VEC3 vf(0.0);
			typename PFP::VEC3 ef(0.0);
200

201
202
203
204
205
206
207
208
209
210
211
212
			unsigned int count = 0;
			Traversor3FE<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 *= 2.0;
213

214
			vf /= count;
215

216
217
218
			m_map.incCurrentLevel() ;
			Dart midF = m_map.phi1(m_map.phi1(d));
			m_position[midF] -= vf;// + ef ;
219
220
221
			m_map.decCurrentLevel() ;
		}

untereiner's avatar
untereiner committed
222
223
		TraversorW<typename PFP::MAP> travW(m_map) ;
		for (Dart d = travW.begin(); d != travW.end(); d = travW.next())
224
		{
225
			typename PFP::VEC3 vc = Algo::Surface::Geometry::volumeCentroid<PFP>(m_map, d, m_position);
226

227
228
229
230
231
232
233
234
235
236
237
238
			unsigned int count = 0;
			typename PFP::VEC3 ec(0.0);
			Traversor3WE<typename PFP::MAP> travWE(m_map, d);
			for (Dart dit = travWE.begin(); dit != travWE.end(); dit = travWE.next())
			{
				m_map.incCurrentLevel();
				ec += m_position[m_map.phi1(dit)];
				m_map.decCurrentLevel();
				++count;
			}
			ec /= count;
			ec *= 3;//12 * m_a * m_a;
239

240
241
242
243
244
245
246
247
248
			count = 0;
			typename PFP::VEC3 fc(0.0);
			Traversor3WF<typename PFP::MAP> travWF(m_map, d);
			for (Dart dit = travWF.begin(); dit != travWF.end(); dit = travWF.next())
			{
				m_map.incCurrentLevel();
				fc += m_position[m_map.phi1(m_map.phi1(dit))];
				m_map.decCurrentLevel();
				++count;
249
			}
250
251
252
253
254
255
256
			fc /= count;
			fc *= 3;//6 * m_a;

			m_map.incCurrentLevel() ;
			Dart midV = m_map.phi_1(m_map.phi2(m_map.phi1(d)));
			m_position[midV] -= vc;// + ec + fc;
			m_map.decCurrentLevel() ;
257
258
259
260
261
262
263
		}
	}

};



264
265
266
267
268
269
270
271
272
273
274
275
276













untereiner's avatar
untereiner committed
277
template <typename PFP>
278
class LerpEdgeSynthesisFilter : public Algo::MR::Filter
untereiner's avatar
untereiner committed
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
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;

public:
	LerpEdgeSynthesisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p) : m_map(m), m_position(p)
	{}

	void operator() ()
	{
		TraversorE<typename PFP::MAP> trav(m_map) ;
		for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
		{
			typename PFP::VEC3 p = (m_position[d] + m_position[m_map.phi2(d)]) * typename PFP::REAL(0.5);

			m_map.incCurrentLevel() ;

			Dart midV = m_map.phi2(d) ;
			m_position[midV] = p ;

			m_map.decCurrentLevel() ;
		}
	}
} ;

template <typename PFP>
306
class LerpFaceSynthesisFilter : public Algo::MR::Filter
untereiner's avatar
untereiner committed
307
308
309
310
311
312
313
314
315
316
317
318
319
320
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;

public:
	LerpFaceSynthesisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p) : m_map(m), m_position(p)
	{}

	void operator() ()
	{
		TraversorF<typename PFP::MAP> trav(m_map) ;
		for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
		{
321
			typename PFP::VEC3 p = Algo::Surface::Geometry::faceCentroid<PFP>(m_map, d, m_position);
untereiner's avatar
untereiner committed
322
323

			m_map.incCurrentLevel() ;
324
325
326
327

			Dart midF = m_map.phi2(m_map.phi1(d));
			m_position[midF] = p ;

untereiner's avatar
untereiner committed
328
329
330
331
332
333
			m_map.decCurrentLevel() ;

		}
	}
} ;

334
template <typename PFP>
335
class LerpTriQuadFaceSynthesisFilter : public Algo::MR::Filter
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;

public:
	LerpTriQuadFaceSynthesisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p) : m_map(m), m_position(p)
	{}

	void operator() ()
	{
		TraversorF<typename PFP::MAP> trav(m_map) ;
		for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
		{
			if(m_map.faceDegree(d) > 3)
			{
352
				typename PFP::VEC3 p = Algo::Surface::Geometry::faceCentroid<PFP>(m_map, d, m_position);
353
354
355
356
357
358
359
360
361
362
363
364
365

				m_map.incCurrentLevel() ;

				Dart midF = m_map.phi2(m_map.phi1(d));
				m_position[midF] = p ;

				m_map.decCurrentLevel() ;
			}
		}
	}
} ;


untereiner's avatar
untereiner committed
366
template <typename PFP>
367
class LerpVolumeSynthesisFilter : public Algo::MR::Filter
untereiner's avatar
untereiner committed
368
369
370
371
372
373
374
375
376
377
378
379
380
381
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;

public:
	LerpVolumeSynthesisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p) : m_map(m), m_position(p)
	{}

	void operator() ()
	{
		TraversorW<typename PFP::MAP> trav(m_map) ;
		for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
		{
382
383
384
			if(!Algo::Volume::Modelisation::Tetrahedralization::isTetrahedron<PFP>(m_map,d)
					&& !Algo::Surface::Modelisation::isPrism<PFP>(m_map,d)
					&& !Algo::Surface::Modelisation::isPyra<PFP>(m_map,d))
385
			{
386
				typename PFP::VEC3 p = Algo::Surface::Geometry::volumeCentroid<PFP>(m_map, d, m_position);
untereiner's avatar
untereiner committed
387

388
				m_map.incCurrentLevel() ;
untereiner's avatar
untereiner committed
389
390
391

				Dart midV = m_map.phi_1(m_map.phi2(m_map.phi1(d)));
				m_position[midV] = p ;
392

393
				m_map.decCurrentLevel() ;
394
			}
395
396
397
398
399
		}
	}
} ;

template <typename PFP>
400
class LerpSqrt3VolumeSynthesisFilter : public Algo::MR::Filter
401
402
403
404
405
406
407
408
409
410
411
412
413
414
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;

public:
	LerpSqrt3VolumeSynthesisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p) : m_map(m), m_position(p)
	{}

	void operator() ()
	{
		TraversorW<typename PFP::MAP> trav(m_map) ;
		for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
		{
415
			typename PFP::VEC3 p = Algo::Surface::Geometry::volumeCentroid<PFP>(m_map, d, m_position);
416
417
418
419
420
421

			m_map.incCurrentLevel() ;

			Dart midV = m_map.phi_1(m_map.phi2(d));
			m_position[midV] = p;

untereiner's avatar
untereiner committed
422
423
424
425
426
427
			m_map.decCurrentLevel() ;

		}
	}
} ;

428

untereiner's avatar
untereiner committed
429
430
431
432
433
434
} // namespace Filters

} // namespace Primal

} // namespace MR

435
436
} // namespace Volume

untereiner's avatar
untereiner committed
437
438
439
440
441
} // namespace Algo

} // namespace CGoGN

#endif /* __3MR_FILTERS_PRIMAL__ */