approximator.h 5.55 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
template <typename PFP>
class ApproximatorGen
{
protected:
74
	typename PFP::MAP& m_map ;
Pierre Kraemer's avatar
Pierre Kraemer committed
75
76

public:
77
	ApproximatorGen(typename PFP::MAP& m) : m_map(m)
Pierre Kraemer's avatar
Pierre Kraemer committed
78
79
80
	{}
	virtual ~ApproximatorGen()
	{}
81
	virtual const std::string& getApproximatedAttributeName() const = 0 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
82
	virtual ApproximatorType getType() const = 0 ;
83

Pierre Kraemer's avatar
Pierre Kraemer committed
84
85
	virtual bool init() = 0 ;
	virtual void approximate(Dart d) = 0 ;
86

Pierre Kraemer's avatar
Pierre Kraemer committed
87
88
	virtual void saveApprox(Dart d) = 0 ;
	virtual void affectApprox(Dart d) = 0 ;
89

Pierre Kraemer's avatar
Pierre Kraemer committed
90
91
	virtual const PredictorGen<PFP>* getPredictor() const = 0 ;
//	virtual REAL detailMagnitude(Dart d) = 0 ;
92
//	virtual void addDetail(Dart d, double amount, bool sign, typename PFP::MATRIX33* detailTransform) = 0 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
93
94
} ;

95
96
97
98
/*!
 * \class Approximator
 * \brief Generic class for approximators
 */
99
template <typename PFP, typename T, unsigned int ORBIT>
Pierre Kraemer's avatar
Pierre Kraemer committed
100
101
102
103
104
class Approximator : public ApproximatorGen<PFP>
{
	typedef typename PFP::MAP MAP ;

protected:
105
106
107
108
	VertexAttribute<T, MAP>& m_attr ;	// vertex attribute to be approximated
	AttributeHandler<T, ORBIT, MAP> m_approx ;	// attribute to store approximation result
	AttributeHandler<T, ORBIT, MAP> m_detail ;	// attribute to store detail information for reconstruction
	T m_app ;
Pierre Kraemer's avatar
Pierre Kraemer committed
109

110
	Predictor<PFP, T>* m_predictor ;
Pierre Kraemer's avatar
Pierre Kraemer committed
111
112

public:
113
	Approximator(MAP& m, VertexAttribute<T, MAP>& attr, Predictor<PFP, T>* predictor) ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
114
	virtual ~Approximator() ;
115
116
117
118
119
120
121

	const VertexAttribute<T, MAP>& getApproximatedAttribute() const ;
	VertexAttribute<T, MAP>& getApproximatedAttribute() ;
	const std::string& getApproximatedAttributeName() const ;

	const AttributeHandler<T, ORBIT, MAP>& getApproximationResultAttribute() const;

122
123
	void saveApprox(Dart d) ;
	void affectApprox(Dart d) ;
124
125
	const T& getApprox(Dart d) const ;

126
	const Predictor<PFP, T>* getPredictor() const ;
127
128
129
130
	const T& getDetail(Dart d) const ;
	void setDetail(Dart d, const T& val) ;
//	REAL detailMagnitude(Dart d) ; // TODO works only for vector types !!
//	void addDetail(Dart d, double amount, bool sign, typename PFP::MATRIX33* detailTransform) ; // TODO works only for vector types !!
Pierre Kraemer's avatar
Pierre Kraemer committed
131
132
} ;

133
134
135
} // namespace Decimation

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

137
} // namespace Algo
138

139
} // namespace CGoGN
Pierre Kraemer's avatar
Pierre Kraemer committed
140

141
#include "Algo/Decimation/approximator.hpp"
Pierre Kraemer's avatar
Pierre Kraemer committed
142
143

#endif