loop.h 3.79 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 __MR_LOOP_MASK__
#define __MR_LOOP_MASK__
27

untereiner's avatar
untereiner committed
28
#include <cmath>
29 30 31 32

namespace CGoGN
{

untereiner's avatar
untereiner committed
33
namespace Algo
34
{
untereiner's avatar
untereiner committed
35 36 37 38 39 40 41

namespace MR
{

namespace Primal
{

untereiner's avatar
untereiner committed
42
namespace Masks
untereiner's avatar
untereiner committed
43 44 45
{

template <typename PFP>
untereiner's avatar
untereiner committed
46
class LoopVertexVertexFunctor : public FunctorType
untereiner's avatar
untereiner committed
47
{
untereiner's avatar
untereiner committed
48 49
protected:
	typename PFP::MAP& m_map ;
50
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& m_position ;
untereiner's avatar
untereiner committed
51 52

public:
53
	LoopVertexVertexFunctor(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& p) : m_map(m), m_position(p)
untereiner's avatar
untereiner committed
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
	{}

	bool operator() (Dart d)
	{
		m_map.decCurrentLevel() ;

		typename PFP::VEC3 np(0) ;
		unsigned int degree = 0 ;
		Traversor2VVaE<typename PFP::MAP> trav(m_map, d) ;
		for(Dart it = trav.begin(); it != trav.end(); it = trav.next())
		{
			++degree ;
			np += m_position[it] ;
		}
		float tmp = 3.0 + 2.0 * cos(2.0 * M_PI / degree) ;
		float beta = (5.0 / 8.0) - ( tmp * tmp / 64.0 ) ;
		np *= beta / degree ;

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

		m_map.incCurrentLevel() ;

		m_position[d] = np + vp ;

		return false ;
	}
} ;
untereiner's avatar
untereiner committed
82

untereiner's avatar
untereiner committed
83 84 85
template <typename PFP>
class LoopEdgeVertexFunctor : public FunctorType
{
86
protected:
untereiner's avatar
untereiner committed
87
	typename PFP::MAP& m_map ;
88
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& m_position ;
89 90

public:
91
	LoopEdgeVertexFunctor(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& p) : m_map(m), m_position(p)
untereiner's avatar
untereiner committed
92 93 94 95 96 97 98
	{}

	bool operator() (Dart d)
	{
		Dart d1 = m_map.phi2(d) ;

		m_map.decCurrentLevel() ;
99

untereiner's avatar
untereiner committed
100 101 102
		Dart d2 = m_map.phi2(d1) ;
		Dart d3 = m_map.phi_1(d1) ;
		Dart d4 = m_map.phi_1(d2) ;
103

untereiner's avatar
untereiner committed
104 105 106 107
		typename PFP::VEC3 p1 = m_position[d1] ;
		typename PFP::VEC3 p2 = m_position[d2] ;
		typename PFP::VEC3 p3 = m_position[d3] ;
		typename PFP::VEC3 p4 = m_position[d4] ;
108

untereiner's avatar
untereiner committed
109 110 111 112
		p1 *= 3.0 / 8.0 ;
		p2 *= 3.0 / 8.0 ;
		p3 *= 1.0 / 8.0 ;
		p4 *= 1.0 / 8.0 ;
113

untereiner's avatar
untereiner committed
114
		m_map.incCurrentLevel() ;
115

untereiner's avatar
untereiner committed
116
		m_position[d] = p1 + p2 + p3 + p4 ;
117

untereiner's avatar
untereiner committed
118 119
		return false ;
	}
120 121
} ;

untereiner's avatar
untereiner committed
122
} // namespace Masks
untereiner's avatar
untereiner committed
123 124 125 126 127 128 129

} // namespace Primal

} // namespace MR

} // namespace Algo

130 131 132
} // namespace CGoGN

#endif
untereiner's avatar
untereiner committed
133