Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

approximator.h 5.96 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
2
3
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
4
* Copyright (C) 2009-2013, IGG Team, ICube, University of Strasbourg           *
Pierre Kraemer's avatar
Pierre Kraemer committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
*                                                                              *
* 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.           *
*                                                                              *
20
* Web site: http://cgogn.unistra.fr/                                           *
Pierre Kraemer's avatar
Pierre Kraemer committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#include "Algo/Decimation/predictor.h"

#ifndef __APPROXIMATOR_H__
#define __APPROXIMATOR_H__

namespace CGoGN
{

namespace Algo
{

36
37
38
namespace Surface
{

Pierre Kraemer's avatar
Pierre Kraemer committed
39
40
41
42
43
namespace Decimation
{

enum ApproximatorType
{
44
45
	// One approx per edge
	// Geometry approximators
46
47
	A_QEM = 0, /**< Approximates the geometry of an edge collapse by quadric error metric minimization [GH97]. */
	A_MidEdge = 1, /**< Approximates the geometry of an edge collapse by placing the resulting vertex in its middle. */
48
49
50
	A_CornerCutting = 2,
	A_TangentPredict1 = 3,
	A_TangentPredict2 = 4,
51
	A_NormalArea = 5, /**< EXPERIMENTAL Approximates the geometry of an edge collapse by minimization of its normal times area measure [Sauvage] */
52
	// Geometry + color approximators
53
54
55
	A_ColorNaive = 6, /**< Approximates the color of the resulting vertex by linear interpolation (based on the approximated position) of its two predecessors. */
	A_ColorQEMext = 7, /**< Approximates both geometry and color of the resulting vertex by minimization of the extended (R^6) quadric error metric [GH98]. */
	A_GeomColorOpt = 8, /**< EXPERIMENTAL. */
56
57
58

	// One approx per half-edge
	// Generic (considers all provided attributes) approximator
59
	A_hHalfCollapse = 9, /**< Approximates all provided attributes of a half-edge collapse by keeping the attributes of the first of two vertices. */
60
	// Geometry approximator
61
	A_hQEM = 10, /**< Approximates the geometry of a full-edge collapse by quadric error metric minimization [GH97]. Compatible version for half-edge selectors. */
62

63
	A_OTHER /**< Can be used for extensions. */
Pierre Kraemer's avatar
Pierre Kraemer committed
64
65
} ;

66
67
68
69
/*!
 * \class ApproximatorGen
 * \brief Generic class holder for approximators
 */
Pierre Kraemer's avatar
Pierre Kraemer committed
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
template <typename PFP>
class ApproximatorGen
{
public:
	typedef typename PFP::MAP MAP ;
	typedef typename PFP::VEC3 VEC3 ;
	typedef typename PFP::REAL REAL ;

protected:
	MAP& m_map ;

public:
	ApproximatorGen(MAP& m) : m_map(m)
	{}
	virtual ~ApproximatorGen()
	{}
86
	virtual const std::string& getApproximatedAttributeName(unsigned int index = 0) const = 0 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
87
	virtual ApproximatorType getType() const = 0 ;
88
	virtual unsigned int getNbApproximated() const = 0 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
89
90
91
92
93
94
95
96
97
	virtual bool init() = 0 ;
	virtual void approximate(Dart d) = 0 ;
	virtual void saveApprox(Dart d) = 0 ;
	virtual void affectApprox(Dart d) = 0 ;
	virtual const PredictorGen<PFP>* getPredictor() const = 0 ;
//	virtual REAL detailMagnitude(Dart d) = 0 ;
	virtual void addDetail(Dart d, double amount, bool sign, typename PFP::MATRIX33* detailTransform) = 0 ;
} ;

98

99
100
101
102
/*!
 * \class Approximator
 * \brief Generic class for approximators
 */
103
template <typename PFP, typename T, unsigned int ORBIT>
Pierre Kraemer's avatar
Pierre Kraemer committed
104
105
106
107
108
109
110
111
112
113
class Approximator : public ApproximatorGen<PFP>
{
public:
	typedef typename PFP::MAP MAP ;
	typedef typename PFP::VEC3 VEC3 ;
	typedef typename PFP::REAL REAL ;

protected:
	Predictor<PFP, T>* m_predictor ;

114
	std::vector<VertexAttribute<T>* > m_attrV ;	// vertex attributes to be approximated
115
116
	std::vector<AttributeHandler<T,ORBIT> > m_approx ;	// attributes to store approximation result
	std::vector<AttributeHandler<T,ORBIT> > m_detail ;	// attributes to store detail information for reconstruction
117
	std::vector<T> m_app ;
Pierre Kraemer's avatar
Pierre Kraemer committed
118
119

public:
120
	Approximator(MAP& m, std::vector<VertexAttribute<T>* > va, Predictor<PFP, T> * predictor) ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
121
	virtual ~Approximator() ;
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
	const std::string& getApproximatedAttributeName(unsigned int index = 0) const ;
	unsigned int getNbApproximated() const ;
	void saveApprox(Dart d) ;
	void affectApprox(Dart d) ;
	const T& getApprox(Dart d, unsigned int index = 0) const ;
	const VertexAttribute<T>& getAttr(unsigned int index = 0) const ;
	VertexAttribute<T>& getAttr(unsigned int index = 0) ;
	std::vector<T> getAllApprox(Dart d) const ;
	const Predictor<PFP, T>* getPredictor() const ;
	const T& getDetail(Dart d, unsigned int index = 0) const ;
	std::vector<T> getAllDetail(Dart d) const ;
	void setDetail(Dart d, unsigned int index, T& val) ;
	void setDetail(Dart d, std::vector<T>& val) ;
	// REAL detailMagnitude(Dart d) ; // TODO works only for vector types !!
	void addDetail(Dart d, double amount, bool sign, typename PFP::MATRIX33* detailTransform) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
137
138
} ;

139
140
141
} // namespace Decimation

} // namespace surface
Pierre Kraemer's avatar
Pierre Kraemer committed
142

143
} // namespace Algo
144

145
} // namespace CGoGN
Pierre Kraemer's avatar
Pierre Kraemer committed
146

147
#include "Algo/Decimation/approximator.hpp"
Pierre Kraemer's avatar
Pierre Kraemer committed
148
149

#endif