loop.h 7.59 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 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_LOOP_FILTER__
#define __MR_LOOP_FILTER__

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

namespace Primal
{

namespace Filters
{


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

template <typename PFP>
typename PFP::VEC3 loopOddVertex(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, Dart d1)
{
	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>
typename PFP::VEC3 loopEvenVertex(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, Dart d)
{
	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
102
class LoopOddAnalysisFilter : public Algo::MR::Filter
untereiner's avatar
untereiner committed
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;

public:
	LoopOddAnalysisFilter(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 p = loopOddVertex<PFP>(m_map, m_position, d) ;

			m_map.incCurrentLevel() ;

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

			m_map.decCurrentLevel() ;
		}
	}
untereiner's avatar
untereiner committed
127 128 129 130 131

	void operator() (bool filtering)
	{

	}
untereiner's avatar
untereiner committed
132 133 134
} ;

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

public:
	LoopEvenAnalysisFilter(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 p = loopEvenVertex<PFP>(m_map, m_position, d) ;
			m_position[d] -= p ;
		}
	}
untereiner's avatar
untereiner committed
154 155 156 157 158

	void operator() (bool filtering)
	{

	}
untereiner's avatar
untereiner committed
159 160 161
} ;

template <typename PFP>
untereiner's avatar
untereiner committed
162
class LoopNormalisationAnalysisFilter : public Algo::MR::Filter
untereiner's avatar
untereiner committed
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position;

public:
	LoopNormalisationAnalysisFilter(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())
		{
			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 ;
		}
	}
untereiner's avatar
untereiner committed
184 185 186 187 188

	void operator() (bool filtering)
	{

	}
untereiner's avatar
untereiner committed
189 190 191 192 193 194 195
} ;

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

template <typename PFP>
untereiner's avatar
untereiner committed
196
class LoopOddSynthesisFilter : public Algo::MR::Filter
untereiner's avatar
untereiner committed
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position;

public:
	LoopOddSynthesisFilter(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 p = loopOddVertex<PFP>(m_map, m_position, d) ;

			m_map.incCurrentLevel() ;

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

			m_map.decCurrentLevel() ;
		}
	}
untereiner's avatar
untereiner committed
221 222 223 224 225

	void operator() (bool filtering)
	{

	}
untereiner's avatar
untereiner committed
226 227 228
} ;

template <typename PFP>
untereiner's avatar
untereiner committed
229
class LoopEvenSynthesisFilter : public Algo::MR::Filter
untereiner's avatar
untereiner committed
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;

public:
	LoopEvenSynthesisFilter(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 p = loopEvenVertex<PFP>(m_map, m_position, d) ;
			m_position[d] += p ;
		}
	}
untereiner's avatar
untereiner committed
248 249 250 251 252

	void operator() (bool filtering)
	{

	}
untereiner's avatar
untereiner committed
253 254 255
} ;

template <typename PFP>
untereiner's avatar
untereiner committed
256
class LoopNormalisationSynthesisFilter : public Algo::MR::Filter
untereiner's avatar
untereiner committed
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;

public:
	LoopNormalisationSynthesisFilter(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())
		{
			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 ;
		}
	}
untereiner's avatar
untereiner committed
278 279 280 281 282

	void operator() (bool filtering)
	{

	}
untereiner's avatar
untereiner committed
283 284 285 286 287 288 289 290
} ;

} // namespace Filters

} // namespace Primal

} // namespace MR

291 292
} // namespace Surface

untereiner's avatar
untereiner committed
293 294 295 296 297 298
} // namespace Algo

} // namespace CGoGN

#endif