Coupure prévue mardi 3 Août au matin pour maintenance du serveur. Nous faisons au mieux pour que celle-ci soit la plus brève possible.

decimation.hpp 6.32 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
* Copyright (C) 2009, 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: https://iggservis.u-strasbg.fr/CGoGN/                              *
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

namespace CGoGN
{

namespace Algo
{

namespace Decimation
{

template <typename PFP>
void decimate(
	typename PFP::MAP& map, SelectorType s, ApproximatorType a,
	typename PFP::TVEC3& position, unsigned int nbWantedVertices, const FunctorSelect& selected
)
{
	std::vector<ApproximatorGen<PFP>*> approximators ;
	EdgeSelector<PFP>* selector = NULL ;

	switch(a)
	{
		case A_QEM :
			approximators.push_back(new Approximator_QEM<PFP>(map, position)) ;
			break ;
		case A_MidEdge :
			approximators.push_back(new Approximator_MidEdge<PFP>(map, position)) ;
			break ;
		case A_CornerCutting :
			approximators.push_back(new Approximator_CornerCutting<PFP>(map, position)) ;
			break ;
		case A_TangentPredict1 :
			approximators.push_back(new Approximator_MidEdge<PFP>(map, position)) ;
			break ;
		case A_TangentPredict2 :
			approximators.push_back(new Approximator_MidEdge<PFP>(map, position)) ;
			break ;
		case A_HalfCollapse :
			approximators.push_back(new Approximator_HalfCollapse<PFP>(map, position)) ;
			break ;
		case A_LightfieldFull :
		{
			approximators.push_back(new Approximator_QEM<PFP>(map, position)) ;
			AttributeHandler<Geom::Matrix<3,3,typename PFP::REAL> > frame = map.template getAttribute<Geom::Matrix<3,3,typename PFP::REAL> >(VERTEX_ORBIT, "frame") ;
67
			AttributeHandler<Geom::Matrix<3,6,typename PFP::REAL> > RGBfunctions = map.template getAttribute<Geom::Matrix<3,6,typename PFP::REAL> >(VERTEX_ORBIT, "colorPTM") ;
Pierre Kraemer's avatar
Pierre Kraemer committed
68
69
70
71
			approximators.push_back(new Approximator_Frame<PFP>(map, frame)) ;
			approximators.push_back(new Approximator_RGBfunctions<PFP>(map, RGBfunctions)) ;
			break ;
		}
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
72
73
		case A_LightfieldHalf :
		{
74
			approximators.push_back(new Approximator_HalfCollapse<PFP>(map, position)) ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
75
76
77
			AttributeHandler<Geom::Matrix<3,3,typename PFP::REAL> > frame = map.template getAttribute<Geom::Matrix<3,3,typename PFP::REAL> >(VERTEX_ORBIT, "frame") ;
			AttributeHandler<Geom::Matrix<3,6,typename PFP::REAL> > RGBfunctions = map.template getAttribute<Geom::Matrix<3,6,typename PFP::REAL> >(VERTEX_ORBIT, "colorPTM") ;
			approximators.push_back(new Approximator_FrameHalf<PFP>(map, frame)) ;
78
			approximators.push_back(new Approximator_RGBfunctionsHalf<PFP>(map, RGBfunctions)) ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
79
80
			break ;
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
81
82
83
84
85
86
87
88
89
90
91
92
93
	}

	switch(s)
	{
		case S_MapOrder :
			selector = new EdgeSelector_MapOrder<PFP>(map, position, approximators) ;
			break ;
		case S_Random :
			selector = new EdgeSelector_Random<PFP>(map, position, approximators) ;
			break ;
		case S_EdgeLength :
			selector = new EdgeSelector_Length<PFP>(map, position, approximators) ;
			break ;
94
95
96
		case S_QEMml :
			selector = new EdgeSelector_QEMml<PFP>(map, position, approximators) ;
			break ;
Pierre Kraemer's avatar
Pierre Kraemer committed
97
98
99
100
101
102
		case S_QEM :
			selector = new EdgeSelector_QEM<PFP>(map, position, approximators) ;
			break ;
		case S_Lightfield :
			selector = new EdgeSelector_Lightfield<PFP>(map, position, approximators) ;
			break ;
103
104
105
		case S_LightfieldHalf :
			selector = new HalfEdgeSelector_Lightfield<PFP>(map, position, approximators) ;
			break ;
Pierre Kraemer's avatar
Pierre Kraemer committed
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
		case S_Curvature :
			selector = new EdgeSelector_Curvature<PFP>(map, position, approximators) ;
			break ;
		case S_MinDetail :
			selector = new EdgeSelector_Random<PFP>(map, position, approximators) ;
			break ;
	}

	for(typename std::vector<ApproximatorGen<PFP>*>::iterator it = approximators.begin(); it != approximators.end(); ++it)
		(*it)->init() ;

	if(!selector->init())
		return ;

	unsigned int nbVertices = map.getNbOrbits(VERTEX_ORBIT) ;
	bool finished = false ;
	Dart d ;
123

Pierre Kraemer's avatar
Pierre Kraemer committed
124
125
	while(!finished)
	{
126
127
		if(!selector->nextEdge(d)) {
			std::cout << "out" << std::endl ;
Pierre Kraemer's avatar
Pierre Kraemer committed
128
			break ;
129
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150

		--nbVertices ;

		Dart d2 = map.phi2(map.phi_1(d)) ;
		Dart dd2 = map.phi2(map.phi_1(map.phi2(d))) ;

		for(typename std::vector<ApproximatorGen<PFP>*>::iterator it = approximators.begin(); it != approximators.end(); ++it)
		{
			(*it)->approximate(d) ;				// compute approximated attributes
			(*it)->saveApprox(d) ;
		}

		selector->updateBeforeCollapse(d) ;		// update selector

		map.collapseEdge(d) ;					// collapse edge

		for(typename std::vector<ApproximatorGen<PFP>*>::iterator it = approximators.begin(); it != approximators.end(); ++it)
			(*it)->affectApprox(d2);			// affect data to the resulting vertex

		selector->updateAfterCollapse(d2, dd2) ;// update selector

151
		if(nbVertices <= nbWantedVertices) {
Pierre Kraemer's avatar
Pierre Kraemer committed
152
			finished = true ;
153
154
			std::cout << "done" << std::endl ;
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
155
156
157
158
159
160
161
162
163
164
165
166
	}

	delete selector ;
	for(typename std::vector<ApproximatorGen<PFP>*>::iterator it = approximators.begin(); it != approximators.end(); ++it)
		delete (*it) ;
}

} //namespace Decimation

} //namespace Algo

} //namespace CGoGN