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/traversor2_closed.h"
untereiner's avatar
untereiner committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

namespace CGoGN
{

namespace Algo
{

namespace MR
{

namespace Primal
{

namespace Filters
{

49 50 51 52 53 54 55 56
/*******************************************************************************
 *							Without features preserving
 *******************************************************************************/

//
// Synthesis
//

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

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

	void operator() ()
	{
		TraversorW<typename PFP::MAP> travW(m_map) ;
		for (Dart d = travW.begin(); d != travW.end(); d = travW.next())
		{
			typename PFP::VEC3 vc = Algo::Geometry::volumeCentroid<PFP>(m_map, d, m_position);
76
			vc *= 8 * m_a * m_a * m_a;
untereiner's avatar
untereiner committed
77 78

			unsigned int count = 0;
79
			typename PFP::VEC3 ec(0.0);
untereiner's avatar
untereiner committed
80 81 82 83
			Traversor3WE<typename PFP::MAP> travWE(m_map, d);
			for (Dart dit = travWE.begin(); dit != travWE.end(); dit = travWE.next())
			{
				m_map.incCurrentLevel();
84
				ec += m_position[m_map.phi1(dit)];
untereiner's avatar
untereiner committed
85 86 87 88
				m_map.decCurrentLevel();
				++count;
			}
			ec /= count;
89
			ec *= 12 * m_a * m_a;
untereiner's avatar
untereiner committed
90 91

			count = 0;
92
			typename PFP::VEC3 fc(0.0);
untereiner's avatar
untereiner committed
93 94 95 96
			Traversor3WF<typename PFP::MAP> travWF(m_map, d);
			for (Dart dit = travWF.begin(); dit != travWF.end(); dit = travWF.next())
			{
				m_map.incCurrentLevel();
97
				fc += m_position[m_map.phi1(m_map.phi1(dit))];
untereiner's avatar
untereiner committed
98 99 100 101
				m_map.decCurrentLevel();
				++count;
			}
			fc /= count;
102
			fc *= 6 * m_a;
untereiner's avatar
untereiner committed
103 104 105

			m_map.incCurrentLevel() ;
			Dart midV = m_map.phi_1(m_map.phi2(m_map.phi1(d)));
106
			m_position[midV] += vc + ec + fc;
untereiner's avatar
untereiner committed
107 108 109 110 111 112
			m_map.decCurrentLevel() ;
		}

		TraversorF<typename PFP::MAP> travF(m_map) ;
		for (Dart d = travF.begin(); d != travF.end(); d = travF.next())
		{
113 114
			typename PFP::VEC3 vf(0.0);
			typename PFP::VEC3 ef(0.0);
untereiner's avatar
untereiner committed
115 116 117 118 119

			unsigned int count = 0;
			Traversor3FE<typename PFP::MAP> travFE(m_map, d);
			for (Dart dit = travFE.begin(); dit != travFE.end(); dit = travFE.next())
			{
120
				vf += m_position[dit];
untereiner's avatar
untereiner committed
121
				m_map.incCurrentLevel();
122
				ef += m_position[m_map.phi1(dit)];
untereiner's avatar
untereiner committed
123 124 125 126
				m_map.decCurrentLevel();
				++count;
			}
			ef /= count;
127 128 129 130
			ef *= 4.0 * m_a;

			vf /= count;
			vf *= 4.0 * m_a * m_a;
untereiner's avatar
untereiner committed
131 132

			m_map.incCurrentLevel() ;
133 134
			Dart midF = m_map.phi1(m_map.phi1(d));
			m_position[midF] += vf + ef ;
untereiner's avatar
untereiner committed
135 136 137 138 139 140
			m_map.decCurrentLevel() ;
		}

		TraversorE<typename PFP::MAP> travE(m_map) ;
		for (Dart d = travE.begin(); d != travE.end(); d = travE.next())
		{
141 142
			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
143 144

			m_map.incCurrentLevel() ;
145 146
			Dart midV = m_map.phi1(d) ;
			m_position[midV] += ve;
untereiner's avatar
untereiner committed
147 148 149 150 151 152 153 154 155 156 157 158
			m_map.decCurrentLevel() ;
		}
	}
} ;

// s-lift(a)
template <typename PFP>
class Ber02EvenSynthesisFilter : public Filter
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;
159
	typename PFP::VEC3::DATA_TYPE m_a;
untereiner's avatar
untereiner committed
160 161

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

	void operator() ()
	{
		TraversorV<typename PFP::MAP> travV(m_map);
		for(Dart d = travV.begin() ; d != travV.end() ; d = travV.next())
		{
170 171 172 173 174 175 176 177
			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);

178 179
//				Dart dit = db;
//				do
180 181 182 183 184 185 186 187 188 189
//				{
//					std::cout << "dit = " << dit << std::endl;
//					m_map.incCurrentLevel() ;
//
//					Dart midEdgeV = m_map.phi1(dit);
//					ev += m_position[midEdgeV];
//					fv += m_position[m_map.phi1(midEdgeV)];
//
//					m_map.decCurrentLevel() ;
//					++count;
190 191 192 193 194 195 196 197 198 199 200 201 202 203
//
//					dit = m_map.phi2(m_map.phi_1(dit));
//
//				}while(dit != db);

				//TODO Replace do--while with a Traversor2 on Boundary
				ClosedMap::Traversor2VF<typename PFP::MAP> travVF(m_map,db);
				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)];
204

205 206 207
					m_map.decCurrentLevel() ;
					++count;
				}
208 209 210 211 212 213 214 215 216 217 218

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

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

				m_position[d] += fv + ev;

			}
			else
untereiner's avatar
untereiner committed
219 220
			{
				unsigned int count = 0;
221 222

				typename PFP::VEC3 cv(0.0);
untereiner's avatar
untereiner committed
223 224 225 226 227 228 229 230 231 232
				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;
233
				cv *= 8 * m_a * m_a * m_a;
untereiner's avatar
untereiner committed
234

235
				typename PFP::VEC3 fv(0.0);
untereiner's avatar
untereiner committed
236 237 238 239 240
				count = 0;
				Traversor3VF<typename PFP::MAP> travVF(m_map,d);
				for(Dart dit = travVF.begin(); dit != travVF.end() ; dit = travVF.next())
				{
					m_map.incCurrentLevel() ;
241
					Dart midV = m_map.phi1(m_map.phi1(dit));
untereiner's avatar
untereiner committed
242 243 244 245 246
					fv += m_position[midV];
					m_map.decCurrentLevel() ;
					++count;
				}
				fv /= count;
247
				fv *= 12 * m_a * m_a;
untereiner's avatar
untereiner committed
248

249
				typename PFP::VEC3 ev(0.0);
untereiner's avatar
untereiner committed
250 251 252 253 254
				count = 0;
				Traversor3VE<typename PFP::MAP> travVE(m_map,d);
				for(Dart dit = travVE.begin(); dit != travVE.end() ; dit = travVE.next())
				{
					m_map.incCurrentLevel() ;
255
					Dart midV = m_map.phi1(dit);
untereiner's avatar
untereiner committed
256 257 258 259 260
					ev += m_position[midV];
					m_map.decCurrentLevel() ;
					++count;
				}
				ev /= count;
261
				ev *= 6 * m_a;
untereiner's avatar
untereiner committed
262

263
				m_position[d] += cv + fv + ev;
untereiner's avatar
untereiner committed
264 265 266 267 268 269 270 271 272
			}
		}

		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);
273
				typename PFP::VEC3 fe(0.0);
untereiner's avatar
untereiner committed
274

275 276 277 278 279 280
//				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() ;
untereiner's avatar
untereiner committed
281

282 283 284 285 286 287 288 289 290 291 292
				//TODO Replace do--while with a Traversor2 on Boundary
				unsigned int count = 0;
				ClosedMap::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;
				}
293

294
				fe /= count;
295
				fe *= 2 * m_a;
untereiner's avatar
untereiner committed
296 297

				m_map.incCurrentLevel() ;
298 299
				Dart midE = m_map.phi1(db);
				m_position[midE] += fe;
untereiner's avatar
untereiner committed
300 301 302 303 304
				m_map.decCurrentLevel() ;
			}
			else
			{
				unsigned int count = 0;
305 306

				typename PFP::VEC3 ce(0.0);
untereiner's avatar
untereiner committed
307 308 309 310 311 312 313 314 315 316
				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;
317
				ce *= 4 * m_a * m_a;
untereiner's avatar
untereiner committed
318

319
				typename PFP::VEC3 fe(0.0);
untereiner's avatar
untereiner committed
320
				count = 0;
321 322
				Traversor3EF<typename PFP::MAP> travEF(m_map, d);
				for(Dart dit = travEF.begin() ; dit != travEF.end() ; dit = travEF.next())
untereiner's avatar
untereiner committed
323 324
				{
					m_map.incCurrentLevel() ;
325
					Dart midV = m_map.phi1(m_map.phi1(dit));
untereiner's avatar
untereiner committed
326 327 328 329 330
					fe += m_position[midV];
					m_map.decCurrentLevel() ;
					++count;
				}
				fe /= count;
331
				fe *= 4 * m_a;
untereiner's avatar
untereiner committed
332 333

				m_map.incCurrentLevel() ;
334 335
				Dart midE = m_map.phi1(d);
				m_position[midE] += ce + fe;
untereiner's avatar
untereiner committed
336 337 338 339 340 341 342 343 344
				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))
			{
345
				unsigned int count = 0;
untereiner's avatar
untereiner committed
346

347 348 349 350 351 352 353 354 355 356 357 358
				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;
untereiner's avatar
untereiner committed
359

360 361 362 363 364
				m_map.incCurrentLevel() ;
				Dart midF = m_map.phi1(m_map.phi1(d));
				m_position[midF] += cf;
				m_map.decCurrentLevel() ;
			}
untereiner's avatar
untereiner committed
365 366 367 368 369 370 371 372 373 374 375
		}
	}
} ;

// s-scale(a)
template <typename PFP>
class Ber02ScaleSynthesisFilter : public Filter
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;
376
	typename PFP::VEC3::DATA_TYPE m_a;
untereiner's avatar
untereiner committed
377 378

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

	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))
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459
				m_position[d] *= m_a * m_a;
			else
				m_position[d] *= m_a *m_a * m_a;
		}

		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))
				m_position[midE] *= m_a;
			else
				m_position[midE] *= m_a * m_a;
			m_map.decCurrentLevel() ;

		}

		TraversorF<typename PFP::MAP> travF(m_map) ;
		for (Dart d = travF.begin(); d != travF.end(); d = travF.next())
		{
				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() ;

		}
	}
} ;

//
// Analysis
//

//w-lift(a)
template <typename PFP>
class Ber02OddAnalysisFilter : public Filter
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;
	typename PFP::VEC3::DATA_TYPE m_a;

public:
	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)
	{}

	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);
			ve *= 2.0 * m_a;

			m_map.incCurrentLevel() ;
			Dart midV = m_map.phi1(d) ;
			m_position[midV] -= ve;
			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
460
			{
461 462 463 464 465
				vf += m_position[dit];
				m_map.incCurrentLevel();
				ef += m_position[m_map.phi1(dit)];
				m_map.decCurrentLevel();
				++count;
untereiner's avatar
untereiner committed
466
			}
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501
			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));
			m_position[midF] -= vf + ef ;
			m_map.decCurrentLevel() ;
		}

		TraversorW<typename PFP::MAP> travW(m_map) ;
		for (Dart d = travW.begin(); d != travW.end(); d = travW.next())
		{
			typename PFP::VEC3 vc = Algo::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())
untereiner's avatar
untereiner committed
502
			{
503 504 505 506
				m_map.incCurrentLevel();
				fc += m_position[m_map.phi1(m_map.phi1(dit))];
				m_map.decCurrentLevel();
				++count;
untereiner's avatar
untereiner committed
507
			}
508 509 510 511 512 513 514
			fc /= count;
			fc *= 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() ;
untereiner's avatar
untereiner committed
515
		}
516 517
	}
} ;
untereiner's avatar
untereiner committed
518

519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562
// s-lift(a)
template <typename PFP>
class Ber02EvenAnalysisFilter : public Filter
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;
	typename PFP::VEC3::DATA_TYPE m_a;

public:
	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)
	{}

	void operator() ()
	{
		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())
untereiner's avatar
untereiner committed
563 564 565 566
		{
			if(m_map.isBoundaryEdge(d))
			{
				Dart db = m_map.findBoundaryFaceOfEdge(d);
567 568
				typename PFP::VEC3 fe(0.0);

569 570 571 572 573 574
//				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() ;
575

576 577 578 579 580 581 582 583 584 585 586
				//TODO Replace do--while with a Traversor2 on Boundary
				unsigned int count = 0;
				ClosedMap::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;
				}
587

588
				fe /= count;
589 590
				fe *= 2 * m_a;

untereiner's avatar
untereiner committed
591
				m_map.incCurrentLevel() ;
592 593
				Dart midE = m_map.phi1(db);
				m_position[midE] -= fe;
untereiner's avatar
untereiner committed
594 595 596 597
				m_map.decCurrentLevel() ;
			}
			else
			{
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
				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;

untereiner's avatar
untereiner committed
627
				m_map.incCurrentLevel() ;
628 629
				Dart midE = m_map.phi1(d);
				m_position[midE] -= ce + fe;
untereiner's avatar
untereiner committed
630 631 632 633
				m_map.decCurrentLevel() ;
			}
		}

634 635 636 637 638 639 640 641 642 643 644
		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);

645 646
//				Dart dit = db;
//				do
647 648 649 650 651 652 653 654 655 656
//				{
//					std::cout << "dit = " << dit << std::endl;
//					m_map.incCurrentLevel() ;
//
//					Dart midEdgeV = m_map.phi1(dit);
//					ev += m_position[midEdgeV];
//					fv += m_position[m_map.phi1(midEdgeV)];
//
//					m_map.decCurrentLevel() ;
//					++count;
657 658 659 660
//
//					dit = m_map.phi2(m_map.phi_1(dit));
//
//				}while(dit != db);
661

662 663 664 665 666 667 668 669 670 671 672 673 674
				ClosedMap::Traversor2VF<typename PFP::MAP> travVF(m_map,db);
				for(Dart dit = travVF.begin(); dit != travVF.end() ; dit = travVF.next())
				{
					std::cout << "dit = " << dit << std::endl;
					m_map.incCurrentLevel() ;

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

					m_map.decCurrentLevel() ;
					++count;
				}
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 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750

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

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

				m_position[d] -= fv + ev;

			}
			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;

				m_position[d] -= cv + fv + ev;
			}
		}
	}
} ;

// s-scale(a)
template <typename PFP>
class Ber02ScaleAnalysisFilter : public Filter
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;
	typename PFP::VEC3::DATA_TYPE m_a;

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)
	{}

	void operator() ()
	{
untereiner's avatar
untereiner committed
751 752 753 754
		TraversorF<typename PFP::MAP> travF(m_map) ;
		for (Dart d = travF.begin(); d != travF.end(); d = travF.next())
		{
				m_map.incCurrentLevel() ;
755 756 757
				Dart midF = m_map.phi1(m_map.phi1(d));
				if(!m_map.isBoundaryVertex(midF))
					m_position[midF] /= m_a ;
untereiner's avatar
untereiner committed
758
				m_map.decCurrentLevel() ;
759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782

		}

		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))
				m_position[midE] /= m_a;
			else
				m_position[midE] /= m_a * m_a;
			m_map.decCurrentLevel() ;

		}

		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 * m_a;
			else
				m_position[d] /= m_a *m_a * m_a;
untereiner's avatar
untereiner committed
783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798
		}
	}
} ;

} // namespace Filters

} // namespace Primal

} // namespace MR

} // namespace Algo

} // namespace CGoGN


#endif /* __3MR_FILTERS_PRIMAL__ */