sqrt3.h 8.93 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_SQRT3_FILTER__
#define __MR_SQRT3_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 71 72 73 74 75 76 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
namespace MR
{

namespace Primal
{

namespace Filters
{
/*
	@article{10.1109/TVCG.2007.1031,
		author = {Huawei Wang and Kaihuai Qin and Hanqiu Sun},
		title = {$\sqrt{3}$-Subdivision-Based Biorthogonal Wavelets},
		journal ={IEEE Transactions on Visualization and Computer Graphics},
		volume = {13},
		issn = {1077-2626},
		year = {2007},
		pages = {914-925},
		doi = {http://doi.ieeecomputersociety.org/10.1109/TVCG.2007.1031},
		publisher = {IEEE Computer Society},
		address = {Los Alamitos, CA, USA},
	}
*/

inline double omega12(unsigned int n)
{
	switch(n)
	{
		case 3: return -0.138438 ;
		case 4: return -0.193032 ;
		case 5: return -0.216933 ;
		case 6: return -0.229537 ;
		case 7: return -0.237236 ;
		case 8: return -0.242453 ;
		case 9: return -0.246257 ;
		case 10: return -0.249180 ;
		case 15: return -0.257616 ;
		case 20: return -0.261843 ;
		default: return 0.0;
			//find formulation ?
	}
}

inline double omega0(unsigned int n)
{
	switch(n)
	{
		case 3: return -0.684601 ;
		case 4: return -0.403537 ;
		case 5: return -0.288813 ;
		case 6: return -0.229537 ;
		case 7: return -0.193385 ;
		case 8: return -0.168740 ;
		case 9: return -0.150618 ;
		case 10: return -0.136570 ;
		case 15: return -0.095201 ;
		case 20: return -0.073924 ;
		default: return 0.0;
			//find formulation ?
	}
}

/*********************************************************************************
 *                      	     Lazy Wavelet
 *********************************************************************************/

template <typename PFP>
untereiner's avatar
untereiner committed
106
class Sqrt3FaceSynthesisFilter : public Algo::MR::Filter
107 108 109 110 111 112 113 114 115 116
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;

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

	void operator() ()
117 118 119 120 121
	{

	}

	void operator() (bool filtering)
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
	{
		TraversorF<typename PFP::MAP> trav(m_map) ;
		for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
		{
			Dart d1 = m_map.phi1(d) ;
			Dart d2 = m_map.phi1(d1) ;

			typename PFP::VEC3 p0 = m_position[d] ;
			typename PFP::VEC3 p1 = m_position[d1] ;
			typename PFP::VEC3 p2 = m_position[d2] ;

			p0 *= 1.0 / 3.0 ;
			p1 *= 1.0 / 3.0 ;
			p2 *= 1.0 / 3.0 ;

137 138 139 140 141 142 143 144 145 146 147
			if(m_map.isBoundaryFace(d))
			{
				Dart df = m_map.findBoundaryEdgeOfFace(d);
				m_map.incCurrentLevel() ;
				m_position[m_map.phi_1(m_map.phi2(df))] += p0 + p1 + p2 ;
			}
			else
			{
				m_map.incCurrentLevel() ;
				m_position[m_map.phi2(d)] += p0 + p1 + p2 ;
			}
148 149 150 151

			m_map.decCurrentLevel() ;
		}
	}
untereiner's avatar
untereiner committed
152

153 154 155
} ;

template <typename PFP>
untereiner's avatar
untereiner committed
156
class Sqrt3VertexSynthesisFilter : public Algo::MR::Filter
157 158 159 160 161 162 163 164 165 166
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;

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

	void operator() ()
167 168 169 170 171
	{

	}

	void operator() (bool filtering)
172 173 174 175
	{
		TraversorV<typename PFP::MAP> trav(m_map) ;
		for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
		{
176 177 178
			if(m_map.isBoundaryVertex(d))
			{
				Dart df = m_map.findBoundaryEdgeOfVertex(d);
179

180 181 182 183 184
				if((m_map.getCurrentLevel()%2 == 0))
				{
					typename PFP::VEC3 np(0) ;
					typename PFP::VEC3 nl(0) ;
					typename PFP::VEC3 nr(0) ;
185

186 187 188 189 190 191 192 193 194 195 196 197 198 199
					typename PFP::VEC3 pi = m_position[df];
					typename PFP::VEC3 pi_1 = m_position[m_map.phi_1(df)];
					typename PFP::VEC3 pi1 = m_position[m_map.phi1(df)];

					np += pi_1 * 4 + pi * 19 + pi1 * 4;
					np /= 27;

					nl +=  pi_1 * 10 + pi * 16 + pi1;
					nl /= 27;

					nr += pi_1 + pi * 16 + pi1 * 10;
					nr /= 27;

					m_map.incCurrentLevel() ;
200

201 202 203 204 205 206
					m_position[df] = np;
					m_position[m_map.phi_1(df)] = nl;
					m_position[m_map.phi1(df)] = nr;

					m_map.decCurrentLevel() ;
				}
207
			}
208 209 210 211
			else
			{
				typename PFP::VEC3 nf(0) ;
				unsigned int degree = 0 ;
212

213 214
				m_map.incCurrentLevel() ;
				Dart df = m_map.phi2(m_map.phi1(d));
215

216 217 218 219 220
				Traversor2VVaE<typename PFP::MAP> trav(m_map, df) ;
				for(Dart it = trav.begin(); it != trav.end(); it = trav.next())
				{
					++degree ;
					nf += m_position[it] ;
221

222 223
				}
				m_map.decCurrentLevel() ;
224

225 226 227
				float alpha = 1.0/9.0 * ( 4.0 - 2.0 * cos(2.0 * M_PI / degree));
				float teta = 1 - (3 * alpha) / 2;
				float sigma = (3 * alpha) / (2 * degree);
228

229
				nf *= sigma;
230

231 232
				typename PFP::VEC3 vp = m_position[d] ;
				vp *= teta ;
233

234 235 236 237 238 239
				m_map.incCurrentLevel() ;

				m_position[df] = vp + nf;

				m_map.decCurrentLevel() ;
			}
240 241
		}
	}
untereiner's avatar
untereiner committed
242

243 244 245
} ;

template <typename PFP>
untereiner's avatar
untereiner committed
246
class Sqrt3VertexAnalysisFilter : public Algo::MR::Filter
247 248 249 250 251 252 253 254 255 256
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;

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

	void operator() ()
257 258 259 260 261
	{

	}

	void operator() (bool filtering)
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
	{
		TraversorV<typename PFP::MAP> trav(m_map) ;
		for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
		{
			typename PFP::VEC3 nf(0) ;
			unsigned int degree = 0 ;

			m_map.incCurrentLevel() ;
			Dart df = m_map.phi2(m_map.phi1(d));

			Traversor2VVaE<typename PFP::MAP> trav(m_map, df) ;
			for(Dart it = trav.begin(); it != trav.end(); it = trav.next())
			{
				++degree ;
				nf += m_position[it] ;

			}
			m_map.decCurrentLevel() ;

			float alpha = 1.0/9.0 * ( 4.0 - 2.0 * cos(2.0 * M_PI / degree));
			float teta = 1 - (3 * alpha) / 2;
			float sigma = (3 * alpha) / (2 * degree);

			nf *= sigma;

			typename PFP::VEC3 vp = m_position[d] ;
			vp -= nf ;

			m_map.incCurrentLevel() ;

			m_position[df] = vp * (1.0 / teta) ;

			m_map.decCurrentLevel() ;

		}
	}
untereiner's avatar
untereiner committed
298

299 300 301
} ;

template <typename PFP>
untereiner's avatar
untereiner committed
302
class Sqrt3FaceAnalysisFilter : public Algo::MR::Filter
303 304 305 306 307 308 309 310 311 312
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;

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

	void operator() ()
313 314 315 316 317
	{

	}

	void operator() (bool filtering)
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
	{
		TraversorF<typename PFP::MAP> trav(m_map) ;
		for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
		{
			Dart d1 = m_map.phi1(d) ;
			Dart d2 = m_map.phi1(d1) ;

			typename PFP::VEC3 p0 = m_position[d] ;
			typename PFP::VEC3 p1 = m_position[d1] ;
			typename PFP::VEC3 p2 = m_position[d2] ;

			p0 *= 1.0 / 3.0 ;
			p1 *= 1.0 / 3.0 ;
			p2 *= 1.0 / 3.0 ;

			m_map.incCurrentLevel() ;

			m_position[m_map.phi2(d)] -= p0 + p1 + p2 ;

			m_map.decCurrentLevel() ;

		}
	}
untereiner's avatar
untereiner committed
341

342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
} ;

/*********************************************************************************
 *                          Three-Point Orthogonalization
 *********************************************************************************/


/*********************************************************************************
 *                          Six-Point Orthogonalization
 *********************************************************************************/

} // namespace Filters

} // namespace Primal

} // namespace MR

359 360
} // namespace Surface

361 362 363 364 365 366
} // namespace Algo

} // namespace CGoGN

#endif