loop.h 7.38 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
/*******************************************************************************
* 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                                        *
*                                                                              *
*******************************************************************************/

untereiner's avatar
untereiner committed
25 26
#ifndef __2MR_LOOP_FILTER__
#define __2MR_LOOP_FILTER__
untereiner's avatar
untereiner committed
27 28 29 30 31 32 33 34 35 36

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

namespace CGoGN
{

namespace Algo
{

37 38 39
namespace Surface
{

untereiner's avatar
untereiner committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
namespace MR
{

namespace Primal
{

namespace Filters
{


/*********************************************************************************
 *                           LOOP BASIC FUNCTIONS
 *********************************************************************************/

template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
55 56
typename PFP::VEC3 loopOddVertex(
	typename PFP::MAP& map,
Sylvain Thery's avatar
Sylvain Thery committed
57
	const VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& position,
Pierre Kraemer's avatar
Pierre Kraemer committed
58
	Dart d1)
untereiner's avatar
untereiner committed
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
{
	Dart d2 = map.phi2(d1) ;
	Dart d3 = map.phi_1(d1) ;
	Dart d4 = map.phi_1(d2) ;

	typename PFP::VEC3 p1 = position[d1] ;
	typename PFP::VEC3 p2 = position[d2] ;
	typename PFP::VEC3 p3 = position[d3] ;
	typename PFP::VEC3 p4 = position[d4] ;

	p1 *= 3.0 / 8.0 ;
	p2 *= 3.0 / 8.0 ;
	p3 *= 1.0 / 8.0 ;
	p4 *= 1.0 / 8.0 ;

	return p1 + p2 + p3 + p4 ;
}

template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
78 79
typename PFP::VEC3 loopEvenVertex(
	typename PFP::MAP& map,
Sylvain Thery's avatar
Sylvain Thery committed
80
	const VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& position,
Pierre Kraemer's avatar
Pierre Kraemer committed
81
	Dart d)
untereiner's avatar
untereiner committed
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
{
	map.incCurrentLevel() ;

	typename PFP::VEC3 np(0) ;
	unsigned int degree = 0 ;
	Traversor2VVaE<typename PFP::MAP> trav(map, d) ;
	for(Dart it = trav.begin(); it != trav.end(); it = trav.next())
	{
		++degree ;
		np += position[it] ;
	}

	map.decCurrentLevel() ;

	float mu = 3.0/8.0 + 1.0/4.0 * cos(2.0 * M_PI / degree) ;
	mu = (5.0/8.0 - (mu * mu)) / degree ;
	np *= 8.0/5.0 * mu ;

	return np ;
}

/*********************************************************************************
 *                           ANALYSIS FILTERS
 *********************************************************************************/

template <typename PFP>
untereiner's avatar
untereiner committed
108
class LoopOddAnalysisFilter : public Algo::MR::Filter
untereiner's avatar
untereiner committed
109
{
Pierre Kraemer's avatar
Pierre Kraemer committed
110 111 112
	typedef typename PFP::MAP MAP;
	typedef typename PFP::VEC3 VEC3;

untereiner's avatar
untereiner committed
113
protected:
Pierre Kraemer's avatar
Pierre Kraemer committed
114
	MAP& m_map ;
115
	VertexAttribute<VEC3, MAP>& m_position ;
untereiner's avatar
untereiner committed
116 117

public:
118
	LoopOddAnalysisFilter(MAP& m, VertexAttribute<VEC3, MAP>& p) : m_map(m), m_position(p)
untereiner's avatar
untereiner committed
119 120 121 122
	{}

	void operator() ()
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
123
		TraversorE<MAP> trav(m_map) ;
untereiner's avatar
untereiner committed
124 125
		for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
126
			VEC3 p = loopOddVertex<PFP>(m_map, m_position, d) ;
untereiner's avatar
untereiner committed
127 128 129 130 131 132 133 134 135 136 137 138

			m_map.incCurrentLevel() ;

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

			m_map.decCurrentLevel() ;
		}
	}
} ;

template <typename PFP>
untereiner's avatar
untereiner committed
139
class LoopEvenAnalysisFilter : public Algo::MR::Filter
untereiner's avatar
untereiner committed
140
{
Pierre Kraemer's avatar
Pierre Kraemer committed
141 142 143
	typedef typename PFP::MAP MAP;
	typedef typename PFP::VEC3 VEC3;

untereiner's avatar
untereiner committed
144
protected:
Pierre Kraemer's avatar
Pierre Kraemer committed
145
	MAP& m_map ;
146
	VertexAttribute<VEC3, MAP>& m_position;
untereiner's avatar
untereiner committed
147 148

public:
149
	LoopEvenAnalysisFilter(MAP& m, VertexAttribute<VEC3, MAP>& p) : m_map(m), m_position(p)
untereiner's avatar
untereiner committed
150 151 152 153
	{}

	void operator() ()
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
154
		TraversorV<MAP> trav(m_map) ;
untereiner's avatar
untereiner committed
155 156
		for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
157
			VEC3 p = loopEvenVertex<PFP>(m_map, m_position, d) ;
untereiner's avatar
untereiner committed
158 159 160 161 162 163
			m_position[d] -= p ;
		}
	}
} ;

template <typename PFP>
untereiner's avatar
untereiner committed
164
class LoopNormalisationAnalysisFilter : public Algo::MR::Filter
untereiner's avatar
untereiner committed
165
{
Pierre Kraemer's avatar
Pierre Kraemer committed
166 167 168
	typedef typename PFP::MAP MAP;
	typedef typename PFP::VEC3 VEC3;

untereiner's avatar
untereiner committed
169
protected:
Pierre Kraemer's avatar
Pierre Kraemer committed
170
	MAP& m_map ;
171
	VertexAttribute<VEC3, MAP>& m_position;
untereiner's avatar
untereiner committed
172 173

public:
174
	LoopNormalisationAnalysisFilter(MAP& m, VertexAttribute<VEC3, MAP>& p) : m_map(m), m_position(p)
untereiner's avatar
untereiner committed
175 176 177 178
	{}

	void operator() ()
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
179
		TraversorV<MAP> trav(m_map) ;
untereiner's avatar
untereiner committed
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
		for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
		{
			unsigned int degree = m_map.vertexDegree(d) ;
			float n = 3.0/8.0 + 1.0/4.0 * cos(2.0 * M_PI / degree) ;
			n = 8.0/5.0 * (n * n) ;

			m_position[d] /= n ;
		}
	}
} ;

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

template <typename PFP>
untereiner's avatar
untereiner committed
196
class LoopOddSynthesisFilter : public Algo::MR::Filter
untereiner's avatar
untereiner committed
197
{
Pierre Kraemer's avatar
Pierre Kraemer committed
198 199 200
	typedef typename PFP::MAP MAP;
	typedef typename PFP::VEC3 VEC3;

untereiner's avatar
untereiner committed
201
protected:
Pierre Kraemer's avatar
Pierre Kraemer committed
202
	MAP& m_map ;
203
	VertexAttribute<VEC3, MAP>& m_position;
untereiner's avatar
untereiner committed
204 205

public:
206
	LoopOddSynthesisFilter(MAP& m, VertexAttribute<VEC3, MAP>& p) : m_map(m), m_position(p)
untereiner's avatar
untereiner committed
207 208 209 210
	{}

	void operator() ()
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
211
		TraversorE<MAP> trav(m_map) ;
untereiner's avatar
untereiner committed
212 213
		for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
214
			VEC3 p = loopOddVertex<PFP>(m_map, m_position, d) ;
untereiner's avatar
untereiner committed
215 216 217 218 219 220 221 222 223 224 225 226

			m_map.incCurrentLevel() ;

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

			m_map.decCurrentLevel() ;
		}
	}
} ;

template <typename PFP>
untereiner's avatar
untereiner committed
227
class LoopEvenSynthesisFilter : public Algo::MR::Filter
untereiner's avatar
untereiner committed
228
{
Pierre Kraemer's avatar
Pierre Kraemer committed
229 230 231
	typedef typename PFP::MAP MAP;
	typedef typename PFP::VEC3 VEC3;

untereiner's avatar
untereiner committed
232
protected:
Pierre Kraemer's avatar
Pierre Kraemer committed
233
	MAP& m_map ;
234
	VertexAttribute<VEC3, MAP>& m_position ;
untereiner's avatar
untereiner committed
235 236

public:
237
	LoopEvenSynthesisFilter(MAP& m, VertexAttribute<VEC3, MAP>& p) : m_map(m), m_position(p)
untereiner's avatar
untereiner committed
238 239 240 241
	{}

	void operator() ()
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
242
		TraversorV<MAP> trav(m_map) ;
untereiner's avatar
untereiner committed
243 244
		for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
245
			VEC3 p = loopEvenVertex<PFP>(m_map, m_position, d) ;
untereiner's avatar
untereiner committed
246 247 248 249 250 251
			m_position[d] += p ;
		}
	}
} ;

template <typename PFP>
untereiner's avatar
untereiner committed
252
class LoopNormalisationSynthesisFilter : public Algo::MR::Filter
untereiner's avatar
untereiner committed
253
{
Pierre Kraemer's avatar
Pierre Kraemer committed
254 255 256
	typedef typename PFP::MAP MAP;
	typedef typename PFP::VEC3 VEC3;

untereiner's avatar
untereiner committed
257
protected:
Pierre Kraemer's avatar
Pierre Kraemer committed
258
	MAP& m_map ;
259
	VertexAttribute<VEC3, MAP>& m_position ;
untereiner's avatar
untereiner committed
260 261

public:
262
	LoopNormalisationSynthesisFilter(MAP& m, VertexAttribute<VEC3, MAP>& p) : m_map(m), m_position(p)
untereiner's avatar
untereiner committed
263 264 265 266
	{}

	void operator() ()
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
267
		TraversorV<MAP> trav(m_map) ;
untereiner's avatar
untereiner committed
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
		for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
		{
			unsigned int degree = m_map.vertexDegree(d) ;
			float n = 3.0/8.0 + 1.0/4.0 * cos(2.0 * M_PI / degree) ;
			n = 8.0/5.0 * (n * n) ;

			m_position[d] *= n ;
		}
	}
} ;

} // namespace Filters

} // namespace Primal

} // namespace MR

285 286
} // namespace Surface

untereiner's avatar
untereiner committed
287 288 289 290 291 292
} // namespace Algo

} // namespace CGoGN

#endif