catmullClark.h 11.7 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 25 26 27 28 29 30 31 32 33 34 35 36
/*******************************************************************************
* 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 __MR_CC_FILTER__
#define __MR_CC_FILTER__

#include <cmath>
#include "Algo/Multiresolution/filter.h"

namespace CGoGN
{

namespace Algo
{

37 38 39
namespace Surface
{

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
namespace MR
{

namespace Primal
{

namespace Filters
{

/*
	@article {springerlink:10.1007/s00371-006-0074-7,
	   author = {Wang, Huawei and Qin, Kaihuai and Tang, Kai},
	   affiliation = {Hong Kong University of Science & Technology Department of Mechanical Engineering Hong Kong China},
	   title = {Efficient wavelet construction with Catmull–Clark subdivision},
	   journal = {The Visual Computer},
	   publisher = {Springer Berlin / Heidelberg},
	   issn = {0178-2789},
	   keyword = {Computer Science},
	   pages = {874-884},
	   volume = {22},
	   issue = {9},
	   url = {http://dx.doi.org/10.1007/s00371-006-0074-7},
	   note = {10.1007/s00371-006-0074-7},
	   year = {2006}
	}
*/

/*********************************************************************************
 *                      	     Lazy Wavelet
 *********************************************************************************/
template <typename PFP>
untereiner's avatar
untereiner committed
71
class CCInitEdgeSynthesisFilter : public Algo::MR::Filter
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;
	bool first;

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

	void operator() ()
	{
		if(first)
		{
			TraversorE<typename PFP::MAP> trav(m_map) ;
			for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
			{
				m_map.incCurrentLevel() ;
				m_position[m_map.phi1(d)] = typename PFP::VEC3(0.0);
				m_map.decCurrentLevel() ;
			}
			first = false;
		}
	}
untereiner's avatar
untereiner committed
96 97 98 99 100

	void operator() (bool filtering)
	{

	}
101 102 103
} ;

template <typename PFP>
untereiner's avatar
untereiner committed
104
class CCInitFaceSynthesisFilter : public Algo::MR::Filter
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;
	bool first;

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

	void operator() ()
	{
		if(first)
		{
			TraversorF<typename PFP::MAP> trav(m_map) ;
			for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
			{
				m_map.incCurrentLevel() ;
				m_position[m_map.phi2(m_map.phi1(d))] = typename PFP::VEC3(0.0); // ou phi2(d)
				m_map.decCurrentLevel() ;
			}
			first = false;
		}
	}
untereiner's avatar
untereiner committed
129 130 131 132 133

	void operator() (bool filtering)
	{

	}
134 135 136
} ;

template <typename PFP>
untereiner's avatar
untereiner committed
137
class CCEdgeSynthesisFilter : public Algo::MR::Filter
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;

public:
	CCEdgeSynthesisFilter(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 ei =  (m_position[d] + m_position[m_map.phi1(d)]) * typename PFP::REAL(0.5);

			m_map.incCurrentLevel() ;
			Dart midV = m_map.phi1(d) ;
			m_position[midV] += ei ;
			m_map.decCurrentLevel() ;
		}
	}
untereiner's avatar
untereiner committed
160 161 162 163 164

	void operator() (bool filtering)
	{

	}
165 166 167
} ;

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

public:
	CCFaceSynthesisFilter(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())
		{
			float u = 1.0/2.0;

			typename PFP::VEC3 v(0.0);
			typename PFP::VEC3 e(0.0);
			unsigned int degree = 0;

			Dart dit = d;
			do
			{
				v += m_position[dit];

				m_map.incCurrentLevel() ;
				e += m_position[m_map.phi1(dit)];
				m_map.decCurrentLevel() ;

				++degree;

				dit = m_map.phi1(dit);
			}
			while(dit != d);

			v *= (1.0 - u) / degree;
			e *= u / degree;

			m_map.incCurrentLevel() ;
			m_position[m_map.phi2(m_map.phi1(d))] += v + e ;
			m_map.decCurrentLevel() ;
		}

	}
untereiner's avatar
untereiner committed
213 214 215 216 217

	void operator() (bool filtering)
	{

	}
218 219 220
} ;

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

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

	void operator() ()
	{
		TraversorV<typename PFP::MAP> trav(m_map) ;
		for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
		{
			typename PFP::VEC3 np1(0) ;
			typename PFP::VEC3 np2(0) ;
			unsigned int degree1 = 0 ;
			unsigned int degree2 = 0 ;
			Dart it = d ;
			do
			{
				++degree1 ;
				Dart dd = m_map.phi1(it) ;
				np1 += m_position[dd] ;
				Dart end = m_map.phi_1(it) ;
				dd = m_map.phi1(dd) ;
				do
				{
					++degree2 ;
					np2 += m_position[dd] ;
					dd = m_map.phi1(dd) ;
				} while(dd != end) ;
				it = m_map.alpha1(it) ;
			} while(it != d) ;

			float beta = 3.0 / (2.0 * degree1) ;
			float gamma = 1.0 / (4.0 * degree2) ;
			np1 *= beta / degree1 ;
			np2 *= gamma / degree2 ;

			typename PFP::VEC3 vp = m_position[d] ;
			vp *= 1.0 - beta - gamma ;

			m_map.incCurrentLevel() ;
			m_position[d] = np1 + np2 + vp ;
			m_map.decCurrentLevel() ;
		}
	}
untereiner's avatar
untereiner committed
270 271 272 273 274

	void operator() (bool filtering)
	{

	}
275 276 277
} ;

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

public:
	CCScalingSynthesisFilter(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())
		{
			m_map.incCurrentLevel() ;

			typename PFP::VEC3 ei = m_position[m_map.phi1(d)];

			typename PFP::VEC3 f = m_position[m_map.phi2(m_map.phi1(d))];
			f += m_position[m_map.phi_1(m_map.phi2(d))];
			f *= 1.0 / 2.0;

			ei += f;
			ei *= 1.0 / 2.0;

			m_position[m_map.phi1(d)] = ei;
			m_map.decCurrentLevel() ;
		}
	}
untereiner's avatar
untereiner committed
308 309 310 311 312

	void operator() (bool filtering)
	{

	}
313 314 315
} ;

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

public:
	CCScalingAnalysisFilter(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())
		{
			m_map.incCurrentLevel() ;

			typename PFP::VEC3 ei = m_position[m_map.phi1(d)];

			typename PFP::VEC3 f = m_position[m_map.phi2(m_map.phi1(d))];
			f += m_position[m_map.phi_1(m_map.phi2(d))];
			f *= 1.0 / 2.0;

			ei *= 2.0;
			ei -= f;

			m_position[m_map.phi1(d)] = ei;
			m_map.decCurrentLevel() ;
		}
	}
untereiner's avatar
untereiner committed
346 347 348 349 350

	void operator() (bool filtering)
	{

	}
351 352 353
} ;

template <typename PFP>
untereiner's avatar
untereiner committed
354
class CCVertexAnalysisFilter : public Algo::MR::Filter
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;

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

	void operator() ()
	{
		TraversorV<typename PFP::MAP> trav(m_map) ;
		for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
		{
			m_map.incCurrentLevel() ;
			typename PFP::VEC3 np1(0) ;
			typename PFP::VEC3 np2(0) ;
			unsigned int degree1 = 0 ;
			unsigned int degree2 = 0 ;
			Dart it = d ;
			do
			{
				++degree1 ;
				Dart dd = m_map.phi1(it) ;
				np1 += m_position[dd] ;
				Dart end = m_map.phi_1(it) ;
				dd = m_map.phi1(dd) ;
				do
				{
					++degree2 ;
					np2 += m_position[dd] ;
					dd = m_map.phi1(dd) ;
				} while(dd != end) ;
				it = m_map.alpha1(it) ;
			} while(it != d) ;

			float beta = 3.0 / (2.0 * degree1) ;
			float gamma = 1.0 / (4.0 * degree2) ;
			np1 *= beta / degree1 ;
			np2 *= gamma / degree2 ;

			typename PFP::VEC3 vd = m_position[d] ;

			m_map.decCurrentLevel() ;

			m_position[d] = vd - np1 - np2;
			m_position[d] /= 1.0 - beta - gamma ;

		}
	}
untereiner's avatar
untereiner committed
405 406 407 408 409

	void operator() (bool filtering)
	{

	}
410 411 412
} ;

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

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

			float u = 1.0/2.0;

			typename PFP::VEC3 v(0.0);
			typename PFP::VEC3 e(0.0);
			unsigned int degree = 0;

			Dart dit = d;
			do
			{
				v += m_position[dit];

				m_map.incCurrentLevel() ;
				e += m_position[m_map.phi1(dit)];
				m_map.decCurrentLevel() ;

				++degree;

				dit = m_map.phi1(dit);
			}
			while(dit != d);

			v *= (1.0 - u) / degree;
			e *= u / degree;

			m_map.incCurrentLevel() ;
454
			m_position[m_map.phi2(m_map.phi1(d))] = m_position[m_map.phi2(m_map.phi1(d))] - v - e ;
455 456
			m_map.decCurrentLevel() ;
		}
untereiner's avatar
untereiner committed
457 458 459 460
	}

	void operator() (bool filtering)
	{
461 462 463 464 465

	}
} ;

template <typename PFP>
untereiner's avatar
untereiner committed
466
class CCEdgeAnalysisFilter : public Algo::MR::Filter
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;

public:
	CCEdgeAnalysisFilter(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 ei =  (m_position[d] + m_position[m_map.phi1(d)]) * typename PFP::REAL(0.5);

			m_map.incCurrentLevel() ;
			Dart midV = m_map.phi1(d) ;
			m_position[midV] -= ei ;
			m_map.decCurrentLevel() ;
		}
	}
untereiner's avatar
untereiner committed
489 490 491 492 493

	void operator() (bool filtering)
	{

	}
494 495 496 497 498 499 500 501
} ;

} // namespace Filters

} // namespace Primal

} // namespace MR

502 503
} // namespace Surface

504 505 506 507 508 509
} // namespace Algo

} // namespace CGoGN

#endif