colorPerVertexApproximator.h 5.12 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
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

25
26
#ifndef __COLOR_APPROXIMATOR_H__
#define __COLOR_APPROXIMATOR_H__
Pierre Kraemer's avatar
Pierre Kraemer committed
27
28
29
30
31
32
33
34
35

#include "Algo/Decimation/approximator.h"

namespace CGoGN
{

namespace Algo
{

36
37
38
namespace Surface
{

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

42
template <typename PFP>
43
class Approximator_ColorNaive : public Approximator<PFP, typename PFP::VEC3, EDGE>
44
45
46
47
48
49
{
public:
	typedef typename PFP::MAP MAP ;
	typedef typename PFP::VEC3 VEC3 ;
	typedef typename PFP::REAL REAL ;

50
protected:
51
52
	VertexAttribute<VEC3> m_position ;
	EdgeAttribute<VEC3> m_approxposition ;
53

54
	VertexAttribute<VEC3> *m_color ;
55
56

public:
57
	Approximator_ColorNaive(MAP& m, std::vector<VertexAttribute<VEC3>* >& attr, Predictor<PFP, VEC3>* pred = NULL) :
58
		Approximator<PFP, VEC3, EDGE>(m, attr, pred)
59
60
61
	{
		m_color = this->m_attrV[0] ;
	}
62
	~Approximator_ColorNaive()
63
64
	{}

65
66
	ApproximatorType getType() const
	{
67
		return A_ColorNaive ;
68
	}
69

70
71
	bool init()
	{
72
73
74
75
76
77
78
79
80
		assert(m_color->isValid() || !"Approximator_ColorNaive: the approximated attribute is not valid") ;

		m_position = this->m_map.template getAttribute<VEC3, VERTEX>("position") ;
		assert(m_position.isValid() || !"Approximator_ColorNaive::init: the position attribute is not valid") ;

		m_approxposition = this->m_map.template getAttribute<VEC3, EDGE>("approx_position") ;
		assert(m_approxposition.isValid() || !"Approximator_ColorNaive::init: the approx_position attribute is not valid") ;

		return m_color->isValid() && m_position.isValid() && m_approxposition.isValid() ;
81
	}
82
83
84
85

	void approximate(Dart d) ;
} ;

Pierre Kraemer's avatar
Pierre Kraemer committed
86
template <typename PFP>
87
class Approximator_ColorQEMext : public Approximator<PFP, typename PFP::VEC3, EDGE>
Pierre Kraemer's avatar
Pierre Kraemer committed
88
89
90
91
{
public:
	typedef typename PFP::MAP MAP ;
	typedef typename PFP::REAL REAL ;
92
93
94
95
	typedef typename PFP::VEC3 VEC3 ;
	typedef Geom::Vector<6,REAL> VEC6 ;

protected:
96
	VertexAttribute<Utils::QuadricNd<REAL,6> > m_quadric ;
97
98
	VertexAttribute<VEC3> *m_position ;
	VertexAttribute<VEC3> *m_color ;
Pierre Kraemer's avatar
Pierre Kraemer committed
99
100

public:
101
	Approximator_ColorQEMext(MAP& m, std::vector<VertexAttribute<VEC3>* >& attr, Predictor<PFP, VEC3>* pred = NULL) :
102
		Approximator<PFP, VEC3, EDGE>(m, attr, pred)
103
	{
104
		assert(attr.size() > 1 || !"Approximator_ColorQEMext: there are not sufficient attributes provided") ;
105

106
107
		m_position = this->m_attrV[0] ;
		m_color = this->m_attrV[1] ;
108
	}
109

110
	~Approximator_ColorQEMext()
111
112
113
114
	{}

	ApproximatorType getType() const
	{
115
		return A_ColorQEMext ;
116
117
	}

118
	bool init() ;
119

Pierre Kraemer's avatar
Pierre Kraemer committed
120
121
	void approximate(Dart d) ;
} ;
122

123
template <typename PFP>
124
class Approximator_GeomColOpt : public Approximator<PFP, typename PFP::VEC3, EDGE>
125
126
127
128
129
130
131
{
public:
	typedef typename PFP::MAP MAP ;
	typedef typename PFP::REAL REAL ;
	typedef typename PFP::VEC3 VEC3 ;

protected:
132
	VertexAttribute<Utils::Quadric<REAL> > m_quadric ;
133
134
135
136
	VertexAttribute<VEC3> *m_position ;
	VertexAttribute<VEC3> *m_color ;

public:
137
138
	Approximator_GeomColOpt(MAP& m, std::vector<VertexAttribute<VEC3>* >& attr, Predictor<PFP, VEC3>* pred = NULL) :
		Approximator<PFP, VEC3, EDGE>(m, attr, pred)
139
	{
140
		assert(attr.size() > 1 || !"Approximator_GeomColOpt: there are not sufficient attributes provided") ;
141
142
143
144
145

		m_position = this->m_attrV[0] ;
		m_color = this->m_attrV[1] ;
	}

146
	~Approximator_GeomColOpt()
147
148
149
150
	{}

	ApproximatorType getType() const
	{
151
		return A_GeomColorOpt ;
152
153
154
155
156
157
	}

	bool init() ;

	void approximate(Dart d) ;
} ;
158

159

Pierre Kraemer's avatar
Pierre Kraemer committed
160
161
} //namespace Decimation

162
} // namespace Surface
163

Pierre Kraemer's avatar
Pierre Kraemer committed
164
165
166
167
} //namespace Algo

} //namespace CGoGN

168
#include "Algo/Decimation/colorPerVertexApproximator.hpp"
Pierre Kraemer's avatar
Pierre Kraemer committed
169
170

#endif