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

pmesh.hpp 18.6 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-2012, IGG Team, LSIIT, 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
36
37
38
39
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#include "Algo/Geometry/localFrame.h"

namespace CGoGN
{

namespace Algo
{

namespace PMesh
{

template <typename PFP>
ProgressiveMesh<PFP>::ProgressiveMesh(
		MAP& map, DartMarker& inactive,
		Algo::Decimation::SelectorType s, Algo::Decimation::ApproximatorType a,
40
		VertexAttribute<typename PFP::VEC3>& position
Pierre Kraemer's avatar
Pierre Kraemer committed
41
42
43
	) :
	m_map(map), positionsTable(position), inactiveMarker(inactive), dartSelect(inactiveMarker)
{
44
	CGoGNout << "  creating approximator and predictor.." << CGoGNflush ;
45
46
47

	std::vector<VertexAttribute< typename PFP::VEC3>* > pos_v ;
	pos_v.push_back(&positionsTable) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
48
49
50
	switch(a)
	{
		case Algo::Decimation::A_QEM : {
51
			m_approximators.push_back(new Algo::Decimation::Approximator_QEM<PFP>(m_map, pos_v)) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
52
53
			break ; }
		case Algo::Decimation::A_MidEdge : {
54
			m_approximators.push_back(new Algo::Decimation::Approximator_MidEdge<PFP>(m_map, pos_v)) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
55
			break ; }
56
		case Algo::Decimation::A_hHalfCollapse : {
Pierre Kraemer's avatar
Pierre Kraemer committed
57
58
			Algo::Decimation::Predictor_HalfCollapse<PFP>* pred = new Algo::Decimation::Predictor_HalfCollapse<PFP>(m_map, positionsTable) ;
			m_predictors.push_back(pred) ;
59
			m_approximators.push_back(new Algo::Decimation::Approximator_HalfCollapse<PFP>(m_map, pos_v, pred)) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
60
61
62
63
			break ; }
		case Algo::Decimation::A_CornerCutting : {
			Algo::Decimation::Predictor_CornerCutting<PFP>* pred = new Algo::Decimation::Predictor_CornerCutting<PFP>(m_map, positionsTable) ;
			m_predictors.push_back(pred) ;
64
			m_approximators.push_back(new Algo::Decimation::Approximator_CornerCutting<PFP>(m_map, pos_v, pred)) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
65
66
67
68
			break ; }
		case Algo::Decimation::A_TangentPredict1 : {
			Algo::Decimation::Predictor_TangentPredict1<PFP>* pred = new Algo::Decimation::Predictor_TangentPredict1<PFP>(m_map, positionsTable) ;
			m_predictors.push_back(pred) ;
69
			m_approximators.push_back(new Algo::Decimation::Approximator_MidEdge<PFP>(m_map, pos_v, pred)) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
70
71
72
73
			break ; }
		case Algo::Decimation::A_TangentPredict2 : {
			Algo::Decimation::Predictor_TangentPredict2<PFP>* pred = new Algo::Decimation::Predictor_TangentPredict2<PFP>(m_map, positionsTable) ;
			m_predictors.push_back(pred) ;
74
			m_approximators.push_back(new Algo::Decimation::Approximator_MidEdge<PFP>(m_map, pos_v, pred)) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
75
76
			break ; }
	}
77
	CGoGNout << "..done" << CGoGNendl ;
Pierre Kraemer's avatar
Pierre Kraemer committed
78

79
	CGoGNout << "  creating selector.." << CGoGNflush ;
Pierre Kraemer's avatar
Pierre Kraemer committed
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
	switch(s)
	{
		case Algo::Decimation::S_MapOrder : {
			m_selector = new Algo::Decimation::EdgeSelector_MapOrder<PFP>(m_map, positionsTable, m_approximators, dartSelect) ;
			break ; }
		case Algo::Decimation::S_Random : {
			m_selector = new Algo::Decimation::EdgeSelector_Random<PFP>(m_map, positionsTable, m_approximators, dartSelect) ;
			break ; }
		case Algo::Decimation::S_EdgeLength : {
			m_selector = new Algo::Decimation::EdgeSelector_Length<PFP>(m_map, positionsTable, m_approximators, dartSelect) ;
			break ; }
		case Algo::Decimation::S_QEM : {
			m_selector = new Algo::Decimation::EdgeSelector_QEM<PFP>(m_map, positionsTable, m_approximators, dartSelect) ;
			break ; }
		case Algo::Decimation::S_MinDetail : {
			m_selector = new Algo::Decimation::EdgeSelector_MinDetail<PFP>(m_map, positionsTable, m_approximators, dartSelect) ;
			break ; }
		case Algo::Decimation::S_Curvature : {
			m_selector = new Algo::Decimation::EdgeSelector_Curvature<PFP>(m_map, positionsTable, m_approximators, dartSelect) ;
			break ; }
	}
101
	CGoGNout << "..done" << CGoGNendl ;
Pierre Kraemer's avatar
Pierre Kraemer committed
102
103
104

	m_initOk = true ;

105
	CGoGNout << "  initializing approximators.." << CGoGNflush ;
Pierre Kraemer's avatar
Pierre Kraemer committed
106
107
108
109
110
111
112
	for(typename std::vector<Algo::Decimation::ApproximatorGen<PFP>*>::iterator it = m_approximators.begin(); it != m_approximators.end(); ++it)
	{
		if(! (*it)->init())
			m_initOk = false ;
		if((*it)->getApproximatedAttributeName() == "position")
			m_positionApproximator = reinterpret_cast<Algo::Decimation::Approximator<PFP, VEC3>*>(*it) ;
	}
113
	CGoGNout << "..done" << CGoGNendl ;
Pierre Kraemer's avatar
Pierre Kraemer committed
114

115
	CGoGNout << "  initializing predictors.." << CGoGNflush ;
Pierre Kraemer's avatar
Pierre Kraemer committed
116
117
118
	for(typename std::vector<Algo::Decimation::PredictorGen<PFP>*>::iterator it = m_predictors.begin(); it != m_predictors.end(); ++it)
		if(! (*it)->init())
			m_initOk = false ;
119
	CGoGNout << "..done" << CGoGNendl ;
Pierre Kraemer's avatar
Pierre Kraemer committed
120

121
	CGoGNout << "  initializing selector.." << CGoGNflush ;
Pierre Kraemer's avatar
Pierre Kraemer committed
122
	m_initOk = m_selector->init() ;
123
	CGoGNout << "..done" << CGoGNendl ;
Pierre Kraemer's avatar
Pierre Kraemer committed
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148

	m_detailAmount = REAL(1) ;
	m_localFrameDetailVectors = false ;
	quantizationInitialized = false ;
	quantizationApplied = false ;
}

template <typename PFP>
ProgressiveMesh<PFP>::~ProgressiveMesh()
{
	for(unsigned int i = 0; i < m_splits.size(); ++i)
		delete m_splits[i] ;
	if(m_selector)
		delete m_selector ;
	for(typename std::vector<Algo::Decimation::ApproximatorGen<PFP>*>::iterator it = m_approximators.begin(); it != m_approximators.end(); ++it)
		delete (*it) ;
	for(typename std::vector<Algo::Decimation::PredictorGen<PFP>*>::iterator it = m_predictors.begin(); it != m_predictors.end(); ++it)
		delete (*it) ;
	if(quantizationInitialized)
		delete q ;
}

template <typename PFP>
void ProgressiveMesh<PFP>::createPM(unsigned int percentWantedVertices)
{
149
	unsigned int nbVertices = m_map.template getNbOrbits<VERTEX>() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
150
	unsigned int nbWantedVertices = nbVertices * percentWantedVertices / 100 ;
151
	CGoGNout << "  creating PM (" << nbVertices << " vertices).." << /* flush */ CGoGNendl ;
Pierre Kraemer's avatar
Pierre Kraemer committed
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176

	bool finished = false ;
	Dart d ;
	while(!finished)
	{
		if(!m_selector->nextEdge(d))
			break ;

		--nbVertices ;
		Dart d2 = m_map.phi2(m_map.phi_1(d)) ;
		Dart dd2 = m_map.phi2(m_map.phi_1(m_map.phi2(d))) ;

		VSplit<PFP>* vs = new VSplit<PFP>(m_map, d, dd2, d2) ;	// create new VSplit node
		m_splits.push_back(vs) ;								// and store it

		for(typename std::vector<Algo::Decimation::ApproximatorGen<PFP>*>::iterator it = m_approximators.begin(); it != m_approximators.end(); ++it)
		{
			(*it)->approximate(d) ;					// compute approximated attributes with its associated detail
			(*it)->saveApprox(d) ;
		}

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

		edgeCollapse(vs) ;							// collapse edge

177
178
179
		unsigned int newV = m_map.template embedNewCell<VERTEX>(d2) ;
		unsigned int newE1 = m_map.template embedNewCell<EDGE>(d2) ;
		unsigned int newE2 = m_map.template embedNewCell<EDGE>(dd2) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
		vs->setApproxV(newV) ;
		vs->setApproxE1(newE1) ;
		vs->setApproxE2(newE2) ;

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

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

		if(nbVertices <= nbWantedVertices)
			finished = true ;
	}
	delete m_selector ;
	m_selector = NULL ;

	m_cur = m_splits.size() ;
196
	CGoGNout << "..done (" << nbVertices << " vertices)" << CGoGNendl ;
Pierre Kraemer's avatar
Pierre Kraemer committed
197
198
199
200
201
202
203
204
205
206

	initQuantization() ;
}

template <typename PFP>
void ProgressiveMesh<PFP>::edgeCollapse(VSplit<PFP>* vs)
{
	Dart d = vs->getEdge() ;
	Dart dd = m_map.phi2(d) ;

Pierre Kraemer's avatar
Pierre Kraemer committed
207
208
	inactiveMarker.markOrbit<FACE>(d) ;
	inactiveMarker.markOrbit<FACE>(dd) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
209
210
211
212
213
214
215
216
217
218
219
220
221
222

	m_map.extractTrianglePair(d) ;
}

template <typename PFP>
void ProgressiveMesh<PFP>::vertexSplit(VSplit<PFP>* vs)
{
	Dart d = vs->getEdge() ;
	Dart dd = m_map.phi2(d) ;
	Dart d2 = vs->getLeftEdge() ;
	Dart dd2 = vs->getRightEdge() ;

	m_map.insertTrianglePair(d, d2, dd2) ;

Pierre Kraemer's avatar
Pierre Kraemer committed
223
224
	inactiveMarker.unmarkOrbit<FACE>(d) ;
	inactiveMarker.unmarkOrbit<FACE>(dd) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
225
226
227
228
229
230
231
232
233
234
235
}

template <typename PFP>
void ProgressiveMesh<PFP>::coarsen()
{
	if(m_cur == m_splits.size())
		return ;

	VSplit<PFP>* vs = m_splits[m_cur] ; // get the split node
	++m_cur ;

236
237
	// Dart d = vs->getEdge() ;
	// Dart dd = m_map.phi2(d) ;		// get some darts
Pierre Kraemer's avatar
Pierre Kraemer committed
238
239
240
241
242
	Dart d2 = vs->getLeftEdge() ;
	Dart dd2 = vs->getRightEdge() ;

	edgeCollapse(vs) ;	// collapse edge

243
244
245
	m_map.template embedOrbit<VERTEX>(d2, vs->getApproxV()) ;
	m_map.template embedOrbit<EDGE>(d2, vs->getApproxE1()) ;
	m_map.template embedOrbit<EDGE>(dd2, vs->getApproxE2()) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
}

template <typename PFP>
void ProgressiveMesh<PFP>::refine()
{
	if(m_cur == 0)
		return ;

	--m_cur ;
	VSplit<PFP>* vs = m_splits[m_cur] ; // get the split node

	Dart d = vs->getEdge() ;
	Dart dd = m_map.phi2(d) ; 		// get some darts
	Dart dd2 = vs->getRightEdge() ;
	Dart d2 = vs->getLeftEdge() ;
	Dart d1 = m_map.phi2(d2) ;
	Dart dd1 = m_map.phi2(dd2) ;

264
265
266
267
268
269
	unsigned int v1 = m_map.template getEmbedding<VERTEX>(d) ;				// get the embedding
	unsigned int v2 = m_map.template getEmbedding<VERTEX>(dd) ;			// of the new vertices
	unsigned int e1 = m_map.template getEmbedding<EDGE>(m_map.phi1(d)) ;
	unsigned int e2 = m_map.template getEmbedding<EDGE>(m_map.phi_1(d)) ;	// and new edges
	unsigned int e3 = m_map.template getEmbedding<EDGE>(m_map.phi1(dd)) ;
	unsigned int e4 = m_map.template getEmbedding<EDGE>(m_map.phi_1(dd)) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289

	if(!m_predictors.empty())
	{
		for(typename std::vector<Algo::Decimation::PredictorGen<PFP>*>::iterator pit = m_predictors.begin();
			pit != m_predictors.end();
			++pit)
		{
			(*pit)->predict(d2, dd2) ;
		}
	}

	typename PFP::MATRIX33 invLocalFrame ;
	if(m_localFrameDetailVectors)
	{
		typename PFP::MATRIX33 localFrame = Algo::Geometry::vertexLocalFrame<PFP>(m_map, dd2, positionsTable) ;
		localFrame.invert(invLocalFrame) ;
	}

	vertexSplit(vs) ; // split vertex

290
291
292
293
294
295
	m_map.template embedOrbit<VERTEX>(d, v1) ;		// embed the
	m_map.template embedOrbit<VERTEX>(dd, v2) ;	// new vertices
	m_map.template embedOrbit<EDGE>(d1, e1) ;
	m_map.template embedOrbit<EDGE>(d2, e2) ;		// and new edges
	m_map.template embedOrbit<EDGE>(dd1, e3) ;
	m_map.template embedOrbit<EDGE>(dd2, e4) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
296
297
298
299
300
301
302
303
304
305
306
307
308
309

	if(!m_predictors.empty())
	{
		typename std::vector<Algo::Decimation::PredictorGen<PFP>*>::iterator pit ;
		typename std::vector<Algo::Decimation::ApproximatorGen<PFP>*>::iterator ait ;
		for(pit = m_predictors.begin(), ait = m_approximators.begin();
			pit != m_predictors.end();
			++pit, ++ait)
		{
			typename PFP::MATRIX33* detailTransform = NULL ;
			if(m_localFrameDetailVectors)
				detailTransform = &invLocalFrame ;

			(*pit)->affectPredict(d) ;
310
			if((*ait)->getType() == Algo::Decimation::A_hHalfCollapse)
Pierre Kraemer's avatar
Pierre Kraemer committed
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
			{
				(*ait)->addDetail(dd, m_detailAmount, true, detailTransform) ;
			}
			else
			{
				(*ait)->addDetail(d, m_detailAmount, true, detailTransform) ;
				(*ait)->addDetail(dd, m_detailAmount, false, detailTransform) ;
			}
		}
	}
}

template <typename PFP>
void ProgressiveMesh<PFP>::gotoLevel(unsigned int l)
{
	if(l == m_cur || l > m_splits.size() || l < 0)
		return ;

	if(l > m_cur)
		while(m_cur != l)
			coarsen() ;
	else
		while(m_cur != l)
			refine() ;
}

template <typename PFP>
void ProgressiveMesh<PFP>::recomputeApproxAndDetails()
{
//	if(!m_predictors.empty())
//	{
//		gotoLevel(0) ;
//		while(m_cur < nbSplits())
//		{
//			VSplit<PFP>* vs = m_splits[m_cur] ;
//			++m_cur ;
//			unsigned int e = vs->getApprox() ;
//			m_approximator->approximate(vs, e) ;
//			edgeCollapse(vs, e) ;
//		}
//	}
}

template <typename PFP>
void ProgressiveMesh<PFP>::setDetailAmount(double a)
{
	m_detailAmount = a ;
	unsigned int c = m_cur ;
	gotoLevel(nbSplits()) ;
	gotoLevel(c) ;
}

template <typename PFP>
void ProgressiveMesh<PFP>::localizeDetailVectors()
{
	if(m_positionApproximator->getPredictor() && !m_localFrameDetailVectors)
	{
		bool quantizationWasApplied = quantizationApplied ;
		unsigned int nbCodeVectors = 0 ;
		if(quantizationWasApplied)
		{
			nbCodeVectors = q->getNbCodeVectors() ;
			resetDetailVectors() ;
		}
		m_localFrameDetailVectors = true ;
		gotoLevel(nbSplits()) ;
		while(m_cur > 0)
		{
			Dart d = m_splits[m_cur-1]->getEdge() ;
			Dart dd2 = m_splits[m_cur-1]->getRightEdge() ;
			typename PFP::MATRIX33 localFrame = Algo::Geometry::vertexLocalFrame<PFP>(m_map, dd2, positionsTable) ;
			VEC3 det = m_positionApproximator->getDetail(d) ;
			det = localFrame * det ;
			m_positionApproximator->setDetail(d, det) ;
			refine() ;
		}
		quantizationInitialized = false ;
		initQuantization() ;
		if(quantizationWasApplied)
			quantizeDetailVectors(nbCodeVectors) ;
	}
}

template <typename PFP>
void ProgressiveMesh<PFP>::globalizeDetailVectors()
{
	if(!m_predictors.empty() && m_localFrameDetailVectors)
	{
		bool quantizationWasApplied = quantizationApplied ;
		unsigned int nbCodeVectors = 0 ;
		if(quantizationWasApplied)
		{
			nbCodeVectors = q->getNbCodeVectors() ;
			resetDetailVectors() ;
		}
		m_localFrameDetailVectors = false ;
		gotoLevel(nbSplits()) ;
		while(m_cur > 0)
		{
			Dart d = m_splits[m_cur-1]->getEdge() ;
			Dart dd2 = m_splits[m_cur-1]->getRightEdge() ;
			typename PFP::MATRIX33 localFrame = Algo::Geometry::vertexLocalFrame<PFP>(m_map, dd2, positionsTable) ;
			typename PFP::MATRIX33 invLocalFrame ;
			localFrame.invert(invLocalFrame) ;
			VEC3 det = m_positionApproximator->getDetail(d) ;
			det = invLocalFrame * det ;
			m_positionApproximator->setDetail(d, det) ;
			refine() ;
		}
		quantizationInitialized = false ;
		initQuantization() ;
		if(quantizationWasApplied)
			quantizeDetailVectors(nbCodeVectors) ;
	}
}

template <typename PFP>
void ProgressiveMesh<PFP>::initQuantization()
{
	if(m_positionApproximator->getPredictor() && !quantizationInitialized)
	{
		gotoLevel(nbSplits()) ;
		originalDetailVectors.resize(m_splits.size()) ;
		for(unsigned int i = 0; i < m_splits.size(); ++i)
435
			originalDetailVectors[i] = m_positionApproximator->getDetail(m_splits[i]->getEdge(),0) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
436
437
		q = new Quantization<VEC3>(originalDetailVectors) ;
		quantizationInitialized = true ;
438
		CGoGNout << "  Differential Entropy -> " << q->getDifferentialEntropy() << CGoGNendl ;
Pierre Kraemer's avatar
Pierre Kraemer committed
439
440
441
442
443
444
445
446
447
448
449
450
451
	}
}

template <typename PFP>
void ProgressiveMesh<PFP>::quantizeDetailVectors(unsigned int nbClasses)
{
	initQuantization() ;
	if(quantizationInitialized)
	{
		gotoLevel(nbSplits()) ;
		std::vector<VEC3> resultat;
		q->vectorQuantizationNbRegions(nbClasses, resultat) ;
		for(unsigned int i = 0; i < m_splits.size(); ++i)
452
			m_positionApproximator->setDetail(m_splits[i]->getEdge(), 0, resultat[i]) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
453
454
		quantizationApplied = true ;
		gotoLevel(0) ;
455
		CGoGNout << "Discrete Entropy -> " << q->getDiscreteEntropy() << " (codebook size : " << q->getNbCodeVectors() << ")" << CGoGNendl ;
Pierre Kraemer's avatar
Pierre Kraemer committed
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
/*
		Point p;
		p.x = q->getEntropieDiscrete() ;
		p.y = computeDistance2() ;
		p.nbClasses = q->getNbClasses() ;
		courbe.push_back(p) ;
*/
	}
}

template <typename PFP>
void ProgressiveMesh<PFP>::quantizeDetailVectors(float distortion)
{
	initQuantization() ;
	if(quantizationInitialized)
	{
		gotoLevel(nbSplits()) ;
		std::vector<typename PFP::VEC3> resultat;
		q->vectorQuantizationDistortion(distortion, resultat) ;
		for(unsigned int i = 0; i < m_splits.size(); ++i)
			m_positionApproximator->setDetail(m_splits[i]->getEdge(), resultat[i]) ;
		quantizationApplied = true ;
		gotoLevel(0) ;
479
		CGoGNout << "Discrete Entropy -> " << q->getDiscreteEntropy() << " (codebook size : " << q->getNbCodeVectors() << ")" << CGoGNendl ;
Pierre Kraemer's avatar
Pierre Kraemer committed
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
	}
}

template <typename PFP>
void ProgressiveMesh<PFP>::resetDetailVectors()
{
	if(quantizationInitialized)
	{
		gotoLevel(nbSplits()) ;
		for(unsigned int i = 0; i < m_splits.size(); ++i)
			m_positionApproximator->setDetail(m_splits[i]->getEdge(), originalDetailVectors[i]) ;
		delete q ;
		quantizationInitialized = false ;
		quantizationApplied = false ;
		gotoLevel(0) ;
	}
}

/*
template <typename PFP>
float ProgressiveMesh<PFP>::computeDistance2()
{
	float distance = 0; // sum of 2-distance between original vertices and new vertices

	gotoLevel(0) ; // mesh reconstruction from detail vectors
	DartMarker mUpdate(m_map) ;
	for(Dart d = m_map.begin(); d != m_map.end(); m_map.next(d)) // vertices loop
	{
		if(!mUpdate.isMarked(d))
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
510
			mUpdate.markOrbit<VERTEX>(d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
			EMB* dEmb = reinterpret_cast<EMB*>(m_map.getVertexEmb(d)) ;
			// computes the 2-distance between original vertex and new vertex
			dEmb->updateDistance2() ;
			distance += dEmb->getDistance2() ;
		}
	}

	return distance ;
}

template <typename PFP>
void ProgressiveMesh<PFP>::calculCourbeDebitDistortion()
{
	Dart d;
	EMB* dEmb;
	std::vector<Vector3f> source;
	std::vector<Vector3f> resultat;
	float distance;
	Point p;

531
	CGoGNout << "calcul de la courbe débit distortion " << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568

	// get original detail vectors
	for(unsigned int i = 0; i < m_splits.size(); ++i)
	{
		source.push_back(Vector3f(*(m_splits.at(i)->getDetailDown())));
		source.push_back(Vector3f(*(m_splits.at(i)->getDetailUp())));
	}

	// vector quantization initialisation
	Quantization<Vector3f> q (source);
	q.vectorQuantizationInit();
	entropieDifferentielle = q.getEntropieDifferentielle();
	determinantSigma = q.getDeterminantSigma();
	traceSigma = q.getTraceSigma();


	// several quantizations of the same detail vectors to compute the curve
	for(unsigned int i = 8 ; i < m_splits.size() ; i *= 2)
	{
		q.vectorQuantization(i, resultat);

		// insert new vectors into the model to compute the distance
		for(unsigned int j = 0; j < m_splits.size(); ++j)
		{
			gmtl::Vec3f* v = resultat.at(j*2).getGmtl();
			m_splits.at(j)->setDetailDown(v);
			v = resultat.at(j*2+1).getGmtl();
			m_splits.at(j)->setDetailUp(v);
		}
		distance = computeDistance2();

		p.x = q.getEntropieDiscrete();
		p.y = distance;
		p.nbClasses = q.getNbClasses();
		courbe.push_back(p);
		// returns to coarse mesh
		gotoLevel(nbSplits());
569
		CGoGNout << "..." << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
570
571
572
573
574
575
576
577
578
579
	}
	q.erase();
}
*/

} //namespace PMesh

} //namespace Algo

} //namespace CGoGN