lerp.h 4.14 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_LERP_MASK__
#define __MR_LERP_MASK__
27

untereiner's avatar
untereiner committed
28 29
#include <cmath>
//#include "Algo/Decimation/decimation.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 40 41 42

namespace MR
{

namespace Primal
{

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

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

public:
54
	LerpVertexVertexFunctor(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& p) : m_map(m), m_position(p)
untereiner's avatar
untereiner committed
55 56 57 58
	{}

	bool operator() (Dart d)
	{
59
		std::cout << "dartIndex(d) = " << m_map.dartIndex(d) << std::endl;
untereiner's avatar
untereiner committed
60
		m_map.decCurrentLevel() ;
61
		std::cout << "dartIndex(d) = " << m_map.dartIndex(d) << std::endl;
untereiner's avatar
untereiner committed
62
		typename PFP::VEC3 p = m_position[d] ;
63
		std::cout << "p = " << p << std::endl;
untereiner's avatar
untereiner committed
64 65 66 67 68 69 70
		m_map.incCurrentLevel() ;

		m_position[d] = p ;

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

untereiner's avatar
untereiner committed
72 73 74
template <typename PFP>
class LerpEdgeVertexFunctor : public FunctorType
{
75
protected:
untereiner's avatar
untereiner committed
76
	typename PFP::MAP& m_map ;
77
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& m_position ;
untereiner's avatar
untereiner committed
78 79

public:
80
	LerpEdgeVertexFunctor(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& p) : m_map(m), m_position(p)
untereiner's avatar
untereiner committed
81
	{}
82

untereiner's avatar
untereiner committed
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
	bool operator() (Dart d)
	{
		Dart d1 = m_map.phi2(d) ;

		m_map.decCurrentLevel() ;
		Dart d2 = m_map.phi2(d1) ;
		typename PFP::VEC3 p = (m_position[d1] + m_position[d2]) / 2.0 ;
		m_map.incCurrentLevel() ;

		m_position[d] = p ;

		return false ;
	}
} ;

template <typename PFP>
class LerpFaceVertexFunctor : public FunctorType
{
protected:
	typename PFP::MAP& m_map ;
103
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& m_position ;
104 105

public:
106
	LerpFaceVertexFunctor(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& p) : m_map(m), m_position(p)
untereiner's avatar
untereiner committed
107
	{}
108

untereiner's avatar
untereiner committed
109 110
	bool operator() (Dart d)
	{
111 112
        Dart df = m_map.phi1(m_map.phi1(d)) ;
        //Dart df = m_map.phi1(d) ;
113

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

untereiner's avatar
untereiner committed
116 117 118 119 120 121 122 123 124
		typename PFP::VEC3 p(0) ;
		unsigned int degree = 0 ;
		Traversor2FV<typename PFP::MAP> trav(m_map, df) ;
		for(Dart it = trav.begin(); it != trav.end(); it = trav.next())
		{
			++degree ;
			p += m_position[it] ;
		}
		p /= degree ;
125

untereiner's avatar
untereiner committed
126
		m_map.incCurrentLevel() ;
127

untereiner's avatar
untereiner committed
128
		m_position[d] = p ;
129

untereiner's avatar
untereiner committed
130 131
		return false ;
	}
132 133
} ;

untereiner's avatar
untereiner committed
134
} // namespace Masks
untereiner's avatar
untereiner committed
135 136 137 138 139 140 141

} // namespace Primal

} // namespace MR

} // namespace Algo

142 143 144
} // namespace CGoGN

#endif
untereiner's avatar
untereiner committed
145