bertram.h 20.7 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 31
/*******************************************************************************
* 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_BERTRAM_FILTER__
#define __3MR_BERTRAM_FILTER__

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

namespace CGoGN
{

namespace Algo
{

40 41 42
namespace Volume
{

untereiner's avatar
untereiner committed
43 44 45 46 47 48 49 50 51
namespace MR
{

namespace Primal
{

namespace Filters
{

52 53 54 55 56
/*******************************************************************************
 *							Without features preserving
 *******************************************************************************/

//
untereiner's avatar
untereiner committed
57
// Analysis
58 59
//

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

public:
untereiner's avatar
untereiner committed
70
	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)
untereiner's avatar
untereiner committed
71 72 73 74
	{}

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

			m_map.incCurrentLevel() ;
untereiner's avatar
untereiner committed
82 83
			Dart midV = m_map.phi1(d) ;
			m_position[midV] -= ve;
untereiner's avatar
untereiner committed
84 85 86 87 88 89
			m_map.decCurrentLevel() ;
		}

		TraversorF<typename PFP::MAP> travF(m_map) ;
		for (Dart d = travF.begin(); d != travF.end(); d = travF.next())
		{
90 91
			typename PFP::VEC3 vf(0.0);
			typename PFP::VEC3 ef(0.0);
untereiner's avatar
untereiner committed
92 93 94 95 96

			unsigned int count = 0;
			Traversor3FE<typename PFP::MAP> travFE(m_map, d);
			for (Dart dit = travFE.begin(); dit != travFE.end(); dit = travFE.next())
			{
97
				vf += m_position[dit];
untereiner's avatar
untereiner committed
98
				m_map.incCurrentLevel();
99
				ef += m_position[m_map.phi1(dit)];
untereiner's avatar
untereiner committed
100 101 102 103
				m_map.decCurrentLevel();
				++count;
			}
			ef /= count;
104 105 106 107
			ef *= 4.0 * m_a;

			vf /= count;
			vf *= 4.0 * m_a * m_a;
untereiner's avatar
untereiner committed
108 109

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

untereiner's avatar
untereiner committed
115 116
		TraversorW<typename PFP::MAP> travW(m_map) ;
		for (Dart d = travW.begin(); d != travW.end(); d = travW.next())
untereiner's avatar
untereiner committed
117
		{
untereiner's avatar
untereiner committed
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
			typename PFP::VEC3 vc = Algo::Surface::Geometry::volumeCentroid<PFP>(m_map, d, m_position);
			vc *= 8 * m_a * m_a * m_a;

			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 *= 12 * m_a * m_a;

			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 *= 6 * m_a;
untereiner's avatar
untereiner committed
146 147

			m_map.incCurrentLevel() ;
untereiner's avatar
untereiner committed
148 149
			Dart midV = m_map.phi_1(m_map.phi2(m_map.phi1(d)));
			m_position[midV] -= vc + ec + fc;
untereiner's avatar
untereiner committed
150 151 152 153 154 155 156
			m_map.decCurrentLevel() ;
		}
	}
} ;

// s-lift(a)
template <typename PFP>
untereiner's avatar
untereiner committed
157
class Ber02EvenAnalysisFilter : public Algo::MR::Filter
untereiner's avatar
untereiner committed
158 159 160 161
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;
162
	typename PFP::VEC3::DATA_TYPE m_a;
untereiner's avatar
untereiner committed
163 164

public:
untereiner's avatar
untereiner committed
165
	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)
untereiner's avatar
untereiner committed
166 167 168 169
	{}

	void operator() ()
	{
untereiner's avatar
untereiner committed
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
		TraversorF<typename PFP::MAP> travF(m_map) ;
		for (Dart d = travF.begin(); d != travF.end(); d = travF.next())
		{
			if(!m_map.isBoundaryFace(d))
			{
				unsigned int count = 0;

				typename PFP::VEC3 cf(0.0);
				Traversor3FW<typename PFP::MAP> travFW(m_map, d);
				for(Dart dit = travFW.begin() ; dit != travFW.end() ; dit = travFW.next())
				{
					m_map.incCurrentLevel();
					Dart midV = m_map.phi_1(m_map.phi2(m_map.phi1(dit)));
					cf += m_position[midV];
					m_map.decCurrentLevel();
					++count;
				}
				cf /= count;
				cf *= 2 * m_a;

				m_map.incCurrentLevel() ;
				Dart midF = m_map.phi1(m_map.phi1(d));
				m_position[midF] -= cf;
				m_map.decCurrentLevel() ;
			}
		}

		TraversorE<typename PFP::MAP> travE(m_map);
		for(Dart d = travE.begin() ; d != travE.end() ; d = travE.next())
		{
			if(m_map.isBoundaryEdge(d))
			{
				Dart db = m_map.findBoundaryFaceOfEdge(d);
				typename PFP::VEC3 fe(0.0);

//				unsigned int count = 2;
//				m_map.incCurrentLevel() ;
//				Dart midV = m_map.phi1(m_map.phi1(db));
//				fe += m_position[midV];
//				midV = m_map.phi_1(m_map.phi2(db));
//				fe += m_position[midV];
//				m_map.decCurrentLevel() ;

				//TODO Replace do--while with a Traversor2 on Boundary
				unsigned int count = 0;
				Traversor2EF<typename PFP::MAP> travEF(m_map, db);
				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 midE = m_map.phi1(db);
				m_position[midE] -= fe;
				m_map.decCurrentLevel() ;
			}
			else
			{
				unsigned int count = 0;

				typename PFP::VEC3 ce(0.0);
				Traversor3EW<typename PFP::MAP> travEW(m_map, d);
				for(Dart dit = travEW.begin() ; dit != travEW.end() ; dit = travEW.next())
				{
					m_map.incCurrentLevel() ;
					Dart midV = m_map.phi_1(m_map.phi2(m_map.phi1(dit)));
					ce += m_position[midV];
					m_map.decCurrentLevel() ;
					++count;
				}
				ce /= count;
				ce *= 4 * m_a * m_a;

				typename PFP::VEC3 fe(0.0);
				count = 0;
				Traversor3EF<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 *= 4 * m_a;

				m_map.incCurrentLevel() ;
				Dart midE = m_map.phi1(d);
				m_position[midE] -= ce + fe;
				m_map.decCurrentLevel() ;
			}
		}

untereiner's avatar
untereiner committed
271 272 273
		TraversorV<typename PFP::MAP> travV(m_map);
		for(Dart d = travV.begin() ; d != travV.end() ; d = travV.next())
		{
274 275 276 277 278 279 280 281
			if(m_map.isBoundaryVertex(d))
			{
				Dart db = m_map.findBoundaryFaceOfVertex(d);

				unsigned int count = 0;
				typename PFP::VEC3 ev(0.0);
				typename PFP::VEC3 fv(0.0);

282 283
//				Dart dit = db;
//				do
284 285 286 287 288 289 290 291 292
//				{
//					m_map.incCurrentLevel() ;
//
//					Dart midEdgeV = m_map.phi1(dit);
//					ev += m_position[midEdgeV];
//					fv += m_position[m_map.phi1(midEdgeV)];
//
//					m_map.decCurrentLevel() ;
//					++count;
293 294 295 296 297
//
//					dit = m_map.phi2(m_map.phi_1(dit));
//
//				}while(dit != db);

298
				Traversor2VF<typename PFP::MAP> travVF(m_map,db);
299 300 301 302 303 304 305
				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)];
306

307 308 309
					m_map.decCurrentLevel() ;
					++count;
				}
310 311 312 313 314 315 316

				fv /= count;
				fv *= 4 * m_a * m_a;

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

untereiner's avatar
untereiner committed
317
				m_position[d] -= fv + ev;
318 319 320

			}
			else
untereiner's avatar
untereiner committed
321 322
			{
				unsigned int count = 0;
323 324

				typename PFP::VEC3 cv(0.0);
untereiner's avatar
untereiner committed
325 326 327 328 329 330 331 332 333 334
				Traversor3VW<typename PFP::MAP> travVW(m_map,d);
				for(Dart dit = travVW.begin(); dit != travVW.end() ; dit = travVW.next())
				{
					m_map.incCurrentLevel() ;
					Dart midV = m_map.phi_1(m_map.phi2(m_map.phi1(dit)));
					cv += m_position[midV];
					m_map.decCurrentLevel() ;
					++count;
				}
				cv /= count;
335
				cv *= 8 * m_a * m_a * m_a;
untereiner's avatar
untereiner committed
336

337
				typename PFP::VEC3 fv(0.0);
untereiner's avatar
untereiner committed
338 339 340 341 342
				count = 0;
				Traversor3VF<typename PFP::MAP> travVF(m_map,d);
				for(Dart dit = travVF.begin(); dit != travVF.end() ; dit = travVF.next())
				{
					m_map.incCurrentLevel() ;
343
					Dart midV = m_map.phi1(m_map.phi1(dit));
untereiner's avatar
untereiner committed
344 345 346 347 348
					fv += m_position[midV];
					m_map.decCurrentLevel() ;
					++count;
				}
				fv /= count;
349
				fv *= 12 * m_a * m_a;
untereiner's avatar
untereiner committed
350

351
				typename PFP::VEC3 ev(0.0);
untereiner's avatar
untereiner committed
352 353 354 355 356
				count = 0;
				Traversor3VE<typename PFP::MAP> travVE(m_map,d);
				for(Dart dit = travVE.begin(); dit != travVE.end() ; dit = travVE.next())
				{
					m_map.incCurrentLevel() ;
357
					Dart midV = m_map.phi1(dit);
untereiner's avatar
untereiner committed
358 359 360 361 362
					ev += m_position[midV];
					m_map.decCurrentLevel() ;
					++count;
				}
				ev /= count;
363
				ev *= 6 * m_a;
untereiner's avatar
untereiner committed
364

untereiner's avatar
untereiner committed
365
				m_position[d] -= cv + fv + ev;
untereiner's avatar
untereiner committed
366 367
			}
		}
untereiner's avatar
untereiner committed
368 369
	}
} ;
untereiner's avatar
untereiner committed
370

untereiner's avatar
untereiner committed
371 372 373 374 375 376 377 378
// s-scale(a)
template <typename PFP>
class Ber02ScaleAnalysisFilter : public Algo::MR::Filter
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;
	typename PFP::VEC3::DATA_TYPE m_a;
379

untereiner's avatar
untereiner committed
380 381 382
public:
	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)
	{}
untereiner's avatar
untereiner committed
383

untereiner's avatar
untereiner committed
384 385 386 387 388
	void operator() ()
	{
		TraversorF<typename PFP::MAP> travF(m_map) ;
		for (Dart d = travF.begin(); d != travF.end(); d = travF.next())
		{
untereiner's avatar
untereiner committed
389
				m_map.incCurrentLevel() ;
untereiner's avatar
untereiner committed
390 391 392
				Dart midF = m_map.phi1(m_map.phi1(d));
				if(!m_map.isBoundaryVertex(midF))
					m_position[midF] /= m_a ;
untereiner's avatar
untereiner committed
393
				m_map.decCurrentLevel() ;
394 395 396 397 398 399 400 401 402 403

		}

		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
404
				m_position[midE] /= m_a;
405
			else
untereiner's avatar
untereiner committed
406
				m_position[midE] /= m_a * m_a;
407 408 409 410
			m_map.decCurrentLevel() ;

		}

untereiner's avatar
untereiner committed
411 412
		TraversorV<typename PFP::MAP> travV(m_map) ;
		for (Dart d = travV.begin(); d != travV.end(); d = travV.next())
413
		{
untereiner's avatar
untereiner committed
414 415 416 417
			if(m_map.isBoundaryVertex(d))
				m_position[d] /= m_a * m_a;
			else
				m_position[d] /= m_a *m_a * m_a;
418 419 420 421
		}
	}
} ;

untereiner's avatar
untereiner committed
422

423
//
untereiner's avatar
untereiner committed
424
// Synthesis
425 426 427 428
//

//w-lift(a)
template <typename PFP>
untereiner's avatar
untereiner committed
429
class Ber02OddSynthesisFilter : public Algo::MR::Filter
430 431 432 433 434 435 436
{
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
437
	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)
438 439 440 441
	{}

	void operator() ()
	{
untereiner's avatar
untereiner committed
442 443
		TraversorW<typename PFP::MAP> travW(m_map) ;
		for (Dart d = travW.begin(); d != travW.end(); d = travW.next())
444
		{
untereiner's avatar
untereiner committed
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
			typename PFP::VEC3 vc = Algo::Surface::Geometry::volumeCentroid<PFP>(m_map, d, m_position);
			vc *= 8 * m_a * m_a * m_a;

			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 *= 12 * m_a * m_a;

			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 *= 6 * m_a;
473 474

			m_map.incCurrentLevel() ;
untereiner's avatar
untereiner committed
475 476
			Dart midV = m_map.phi_1(m_map.phi2(m_map.phi1(d)));
			m_position[midV] += vc + ec + fc;
477 478 479 480 481 482 483 484 485 486 487 488
			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())
untereiner's avatar
untereiner committed
489
			{
490 491 492 493 494
				vf += m_position[dit];
				m_map.incCurrentLevel();
				ef += m_position[m_map.phi1(dit)];
				m_map.decCurrentLevel();
				++count;
untereiner's avatar
untereiner committed
495
			}
496 497 498 499 500 501 502 503
			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
504
			m_position[midF] += vf + ef ;
505 506 507
			m_map.decCurrentLevel() ;
		}

untereiner's avatar
untereiner committed
508 509
		TraversorE<typename PFP::MAP> travE(m_map) ;
		for (Dart d = travE.begin(); d != travE.end(); d = travE.next())
510
		{
untereiner's avatar
untereiner committed
511 512
			typename PFP::VEC3 ve = (m_position[d] + m_position[m_map.phi1(d)]) * typename PFP::REAL(0.5);
			ve *= 2.0 * m_a;
513 514

			m_map.incCurrentLevel() ;
untereiner's avatar
untereiner committed
515 516
			Dart midV = m_map.phi1(d) ;
			m_position[midV] += ve;
517
			m_map.decCurrentLevel() ;
untereiner's avatar
untereiner committed
518
		}
519 520
	}
} ;
untereiner's avatar
untereiner committed
521

522 523
// s-lift(a)
template <typename PFP>
untereiner's avatar
untereiner committed
524
class Ber02EvenSynthesisFilter : public Algo::MR::Filter
525 526 527 528 529 530 531
{
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
532
	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)
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547
	{}

	void operator() ()
	{
		TraversorV<typename PFP::MAP> travV(m_map);
		for(Dart d = travV.begin() ; d != travV.end() ; d = travV.next())
		{
			if(m_map.isBoundaryVertex(d))
			{
				Dart db = m_map.findBoundaryFaceOfVertex(d);

				unsigned int count = 0;
				typename PFP::VEC3 ev(0.0);
				typename PFP::VEC3 fv(0.0);

548 549
//				Dart dit = db;
//				do
550 551 552 553 554 555 556 557 558
//				{
//					m_map.incCurrentLevel() ;
//
//					Dart midEdgeV = m_map.phi1(dit);
//					ev += m_position[midEdgeV];
//					fv += m_position[m_map.phi1(midEdgeV)];
//
//					m_map.decCurrentLevel() ;
//					++count;
559 560 561 562
//
//					dit = m_map.phi2(m_map.phi_1(dit));
//
//				}while(dit != db);
563

untereiner's avatar
untereiner committed
564
				//TODO Replace do--while with a Traversor2 on Boundary
565
				Traversor2VF<typename PFP::MAP> travVF(m_map,db);
566 567 568 569 570 571 572 573 574 575 576
				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;
				}
577 578 579 580 581 582 583

				fv /= count;
				fv *= 4 * m_a * m_a;

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

untereiner's avatar
untereiner committed
584
				m_position[d] += fv + ev;
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631

			}
			else
			{
				unsigned int count = 0;

				typename PFP::VEC3 cv(0.0);
				Traversor3VW<typename PFP::MAP> travVW(m_map,d);
				for(Dart dit = travVW.begin(); dit != travVW.end() ; dit = travVW.next())
				{
					m_map.incCurrentLevel() ;
					Dart midV = m_map.phi_1(m_map.phi2(m_map.phi1(dit)));
					cv += m_position[midV];
					m_map.decCurrentLevel() ;
					++count;
				}
				cv /= count;
				cv *= 8 * m_a * m_a * m_a;

				typename PFP::VEC3 fv(0.0);
				count = 0;
				Traversor3VF<typename PFP::MAP> travVF(m_map,d);
				for(Dart dit = travVF.begin(); dit != travVF.end() ; dit = travVF.next())
				{
					m_map.incCurrentLevel() ;
					Dart midV = m_map.phi1(m_map.phi1(dit));
					fv += m_position[midV];
					m_map.decCurrentLevel() ;
					++count;
				}
				fv /= count;
				fv *= 12 * m_a * m_a;

				typename PFP::VEC3 ev(0.0);
				count = 0;
				Traversor3VE<typename PFP::MAP> travVE(m_map,d);
				for(Dart dit = travVE.begin(); dit != travVE.end() ; dit = travVE.next())
				{
					m_map.incCurrentLevel() ;
					Dart midV = m_map.phi1(dit);
					ev += m_position[midV];
					m_map.decCurrentLevel() ;
					++count;
				}
				ev /= count;
				ev *= 6 * m_a;

untereiner's avatar
untereiner committed
632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733
				m_position[d] += cv + fv + ev;
			}
		}

		TraversorE<typename PFP::MAP> travE(m_map);
		for(Dart d = travE.begin() ; d != travE.end() ; d = travE.next())
		{
			if(m_map.isBoundaryEdge(d))
			{
				Dart db = m_map.findBoundaryFaceOfEdge(d);
				typename PFP::VEC3 fe(0.0);

//				unsigned int count = 2;
//				m_map.incCurrentLevel() ;
//				Dart midV = m_map.phi1(m_map.phi1(db));
//				fe += m_position[midV];
//				midV = m_map.phi_1(m_map.phi2(db));
//				fe += m_position[midV];
//				m_map.decCurrentLevel() ;

				//TODO Replace do--while with a Traversor2 on Boundary
				unsigned int count = 0;
				Traversor2EF<typename PFP::MAP> travEF(m_map, db);
				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 midE = m_map.phi1(db);
				m_position[midE] += fe;
				m_map.decCurrentLevel() ;
			}
			else
			{
				unsigned int count = 0;

				typename PFP::VEC3 ce(0.0);
				Traversor3EW<typename PFP::MAP> travEW(m_map, d);
				for(Dart dit = travEW.begin() ; dit != travEW.end() ; dit = travEW.next())
				{
					m_map.incCurrentLevel() ;
					Dart midV = m_map.phi_1(m_map.phi2(m_map.phi1(dit)));
					ce += m_position[midV];
					m_map.decCurrentLevel() ;
					++count;
				}
				ce /= count;
				ce *= 4 * m_a * m_a;

				typename PFP::VEC3 fe(0.0);
				count = 0;
				Traversor3EF<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 *= 4 * m_a;

				m_map.incCurrentLevel() ;
				Dart midE = m_map.phi1(d);
				m_position[midE] += ce + fe;
				m_map.decCurrentLevel() ;
			}
		}

		TraversorF<typename PFP::MAP> travF(m_map) ;
		for (Dart d = travF.begin(); d != travF.end(); d = travF.next())
		{
			if(!m_map.isBoundaryFace(d))
			{
				unsigned int count = 0;

				typename PFP::VEC3 cf(0.0);
				Traversor3FW<typename PFP::MAP> travFW(m_map, d);
				for(Dart dit = travFW.begin() ; dit != travFW.end() ; dit = travFW.next())
				{
					m_map.incCurrentLevel();
					Dart midV = m_map.phi_1(m_map.phi2(m_map.phi1(dit)));
					cf += m_position[midV];
					m_map.decCurrentLevel();
					++count;
				}
				cf /= count;
				cf *= 2 * m_a;

				m_map.incCurrentLevel() ;
				Dart midF = m_map.phi1(m_map.phi1(d));
				m_position[midF] += cf;
				m_map.decCurrentLevel() ;
734 735 736 737 738 739 740
			}
		}
	}
} ;

// s-scale(a)
template <typename PFP>
untereiner's avatar
untereiner committed
741
class Ber02ScaleSynthesisFilter : public Algo::MR::Filter
742 743 744 745 746 747 748
{
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
749
	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)
750 751 752 753
	{}

	void operator() ()
	{
untereiner's avatar
untereiner committed
754 755
		TraversorV<typename PFP::MAP> travV(m_map) ;
		for (Dart d = travV.begin(); d != travV.end(); d = travV.next())
untereiner's avatar
untereiner committed
756
		{
untereiner's avatar
untereiner committed
757 758 759 760
			if(m_map.isBoundaryVertex(d))
				m_position[d] *= m_a * m_a;
			else
				m_position[d] *= m_a *m_a * m_a;
761 762 763 764 765 766 767 768 769
		}

		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
770
				m_position[midE] *= m_a;
771
			else
untereiner's avatar
untereiner committed
772
				m_position[midE] *= m_a * m_a;
773 774 775 776
			m_map.decCurrentLevel() ;

		}

untereiner's avatar
untereiner committed
777 778
		TraversorF<typename PFP::MAP> travF(m_map) ;
		for (Dart d = travF.begin(); d != travF.end(); d = travF.next())
779
		{
untereiner's avatar
untereiner committed
780 781 782 783 784 785
				m_map.incCurrentLevel() ;
				Dart midF = m_map.phi1(m_map.phi1(d));
				if(!m_map.isBoundaryVertex(midF))
					m_position[midF] *= m_a ;
				m_map.decCurrentLevel() ;

untereiner's avatar
untereiner committed
786 787 788 789
		}
	}
} ;

untereiner's avatar
untereiner committed
790 791


untereiner's avatar
untereiner committed
792 793 794 795 796 797
} // namespace Filters

} // namespace Primal

} // namespace MR

798 799
} // namespace Volume

untereiner's avatar
untereiner committed
800 801 802 803 804 805
} // namespace Algo

} // namespace CGoGN


#endif /* __3MR_FILTERS_PRIMAL__ */