lerp.h 8.06 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
/*******************************************************************************
* 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_LERP_FILTER__
#define __2MR_LERP_FILTER__
27

untereiner's avatar
untereiner committed
28 29
#include <cmath>
#include "Algo/Multiresolution/filter.h"
30 31 32 33

namespace CGoGN
{

untereiner's avatar
untereiner committed
34
namespace Algo
35
{
untereiner's avatar
untereiner committed
36

37 38 39
namespace Surface
{

untereiner's avatar
untereiner committed
40 41 42 43 44 45
namespace MR
{

namespace Primal
{

untereiner's avatar
untereiner committed
46
namespace Filters
untereiner's avatar
untereiner committed
47 48
{

untereiner's avatar
untereiner committed
49 50 51
/*********************************************************************************
 *                           SYNTHESIS FILTERS
 *********************************************************************************/
52 53

// Quad refinement
untereiner's avatar
untereiner committed
54
template <typename PFP>
untereiner's avatar
untereiner committed
55
class LerpQuadOddSynthesisFilter : public Algo::MR::Filter
untereiner's avatar
untereiner committed
56 57 58 59
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;
60 61

public:
62
	LerpQuadOddSynthesisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p) : m_map(m), m_position(p)
untereiner's avatar
untereiner committed
63
	{}
64

untereiner's avatar
untereiner committed
65 66
	void operator() ()
	{
67 68
		TraversorF<typename PFP::MAP> travF(m_map) ;
		for (Dart d = travF.begin(); d != travF.end(); d = travF.next())
untereiner's avatar
untereiner committed
69
		{
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
			typename PFP::VEC3 vf(0.0);
			typename PFP::VEC3 ef(0.0);

			unsigned int count = 0;
			Traversor2FE<typename PFP::MAP> travFE(m_map, d);
			for (Dart dit = travFE.begin(); dit != travFE.end(); dit = travFE.next())
			{
				vf += m_position[dit];
				m_map.incCurrentLevel();
				ef += m_position[m_map.phi1(dit)];
				m_map.decCurrentLevel();
				++count;
			}
			ef /= count;
			ef *= 2.0;

			vf /= count;
87

untereiner's avatar
untereiner committed
88
			m_map.incCurrentLevel() ;
89 90 91 92
			Dart midF = m_map.phi1(m_map.phi1(d));
			m_position[midF] += vf + ef ;
			m_map.decCurrentLevel() ;
		}
93

94 95 96 97
		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);
98

99 100 101
			m_map.incCurrentLevel() ;
			Dart midV = m_map.phi1(d) ;
			m_position[midV] += ve ;
untereiner's avatar
untereiner committed
102 103 104
			m_map.decCurrentLevel() ;
		}
	}
105
};
106

107
// Tri/quad refinement
untereiner's avatar
untereiner committed
108
template <typename PFP>
untereiner's avatar
untereiner committed
109
class LerpTriQuadOddSynthesisFilter : public Algo::MR::Filter
untereiner's avatar
untereiner committed
110 111 112 113
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;
114

untereiner's avatar
untereiner committed
115
public:
116
	LerpTriQuadOddSynthesisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p) : m_map(m), m_position(p)
untereiner's avatar
untereiner committed
117 118 119 120
	{}

	void operator() ()
	{
121 122
		TraversorF<typename PFP::MAP> travF(m_map) ;
		for (Dart d = travF.begin(); d != travF.end(); d = travF.next())
untereiner's avatar
untereiner committed
123 124 125
		{
			if(m_map.faceDegree(d) != 3)
			{
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
				typename PFP::VEC3 vf(0.0);
				typename PFP::VEC3 ef(0.0);

				unsigned int count = 0;
				Traversor2FE<typename PFP::MAP> travFE(m_map, d);
				for (Dart dit = travFE.begin(); dit != travFE.end(); dit = travFE.next())
				{
					vf += m_position[dit];
					m_map.incCurrentLevel();
					ef += m_position[m_map.phi1(dit)];
					m_map.decCurrentLevel();
					++count;
				}
				ef /= count;
				ef *= 2.0;

				vf /= count;

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

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

			m_map.incCurrentLevel() ;
			Dart midV = m_map.phi1(d) ;
			m_position[midV] += ve ;
untereiner's avatar
untereiner committed
159
			m_map.decCurrentLevel() ;
160 161 162 163 164 165 166 167 168 169
		}
	}
};

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

// Quad refinement
template <typename PFP>
untereiner's avatar
untereiner committed
170
class LerpQuadOddAnalysisFilter : public Algo::MR::Filter
171 172 173 174 175 176 177 178
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;

public:
	LerpQuadOddAnalysisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p) : m_map(m), m_position(p)
	{}
untereiner's avatar
untereiner committed
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 213 214 215 216 217
	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);

			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;
			Traversor2FE<typename PFP::MAP> travFE(m_map, d);
			for (Dart dit = travFE.begin(); dit != travFE.end(); dit = travFE.next())
			{
				vf += m_position[dit];
				m_map.incCurrentLevel();
				ef += m_position[m_map.phi1(dit)];
				m_map.decCurrentLevel();
				++count;
			}
			ef /= count;
			ef *= 2.0;

			vf /= count;

			m_map.incCurrentLevel() ;
			Dart midF = m_map.phi1(m_map.phi1(d));
			m_position[midF] -= vf + ef ;
			m_map.decCurrentLevel() ;
untereiner's avatar
untereiner committed
218 219
		}
	}
220 221 222 223
};

// Tri/quad refinement
template <typename PFP>
untereiner's avatar
untereiner committed
224
class LerpTriQuadOddAnalysisFilter : public Algo::MR::Filter
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;

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

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

			m_map.incCurrentLevel() ;
			Dart midV = m_map.phi1(d) ;
			m_position[midV] -= ve ;
			m_map.decCurrentLevel() ;
		}
246

247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
		TraversorF<typename PFP::MAP> travF(m_map) ;
		for (Dart d = travF.begin(); d != travF.end(); d = travF.next())
		{
			if(m_map.faceDegree(d) != 3)
			{
				typename PFP::VEC3 vf(0.0);
				typename PFP::VEC3 ef(0.0);

				unsigned int count = 0;
				Traversor2FE<typename PFP::MAP> travFE(m_map, d);
				for (Dart dit = travFE.begin(); dit != travFE.end(); dit = travFE.next())
				{
					vf += m_position[dit];
					m_map.incCurrentLevel();
					ef += m_position[m_map.phi1(dit)];
					m_map.decCurrentLevel();
					++count;
				}
				ef /= count;
				ef *= 2.0;

				vf /= count;

				m_map.incCurrentLevel() ;
				Dart midF = m_map.phi1(m_map.phi1(d));
				m_position[midF] -= vf + ef ;
				m_map.decCurrentLevel() ;
			}
		}
	}
};
untereiner's avatar
untereiner committed
278 279

} // namespace Filters
untereiner's avatar
untereiner committed
280 281 282 283 284

} // namespace Primal

} // namespace MR

285 286
} // namespace Surface

untereiner's avatar
untereiner committed
287 288
} // namespace Algo

289 290 291
} // namespace CGoGN

#endif
untereiner's avatar
untereiner committed
292