collector.hpp 40.5 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
/*******************************************************************************
* 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.           *
*                                                                              *
20
* Web site: http://cgogn.unistra.fr/                                  *
Pierre Kraemer's avatar
Pierre Kraemer committed
21
22
23
24
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

25
#include "Topology/generic/traversor/traversor2.h"
26
#include "Algo/Geometry/intersection.h"
27
#include <queue>
28

Pierre Kraemer's avatar
Pierre Kraemer committed
29
30
31
namespace CGoGN
{

32
33
34
namespace Algo
{

Thery Sylvain's avatar
Thery Sylvain committed
35
36
37
namespace Surface
{

Pierre Kraemer's avatar
Pierre Kraemer committed
38
39
40
namespace Selection
{

41
42
43
44
/*********************************************************
 * Generic Collector
 *********************************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
45
template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
46
Collector<PFP>::Collector(MAP& m, unsigned int thread) : map(m), m_thread(thread), isInsideCollected(false)
Pierre Kraemer's avatar
Pierre Kraemer committed
47
48
{}

49
template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
50
inline bool Collector<PFP>::applyOnInsideVertices(FunctorType& f)
51
{
52
	assert(isInsideCollected || !"applyOnInsideVertices: inside cells have not been collected.") ;
53
54
55
56
57
58
	for(std::vector<Dart>::iterator iv = insideVertices.begin(); iv != insideVertices.end(); ++iv)
		if(f(*iv))
			return true ;
	return false ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
59
60
61
template <typename PFP>
inline bool Collector<PFP>::applyOnInsideEdges(FunctorType& f)
{
62
	assert(isInsideCollected || !"applyOnInsideEdges: inside cells have not been collected.") ;
Pierre Kraemer's avatar
Pierre Kraemer committed
63
64
65
66
67
68
69
70
71
	for(std::vector<Dart>::iterator iv = insideEdges.begin(); iv != insideEdges.end(); ++iv)
		if(f(*iv))
			return true ;
	return false ;
}

template <typename PFP>
inline bool Collector<PFP>::applyOnInsideFaces(FunctorType& f)
{
72
	assert(isInsideCollected || !"applyOnInsideFaces: inside cells have not been collected.") ;
Pierre Kraemer's avatar
Pierre Kraemer committed
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
	for(std::vector<Dart>::iterator iv = insideFaces.begin(); iv != insideFaces.end(); ++iv)
		if(f(*iv))
			return true ;
	return false ;
}

template <typename PFP>
inline bool Collector<PFP>::applyOnBorder(FunctorType& f)
{
	for(std::vector<Dart>::iterator iv = border.begin(); iv != border.end(); ++iv)
		if(f(*iv))
			return true ;
	return false ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
88
89
90
91
92
template <typename PPFP>
std::ostream& operator<<(std::ostream &out, const Collector<PPFP>& c)
{
    out << "Collector around " << c.centerDart << std::endl;
    out << "insideVertices (" << c.insideVertices.size() << ") = {";
Pierre Kraemer's avatar
Pierre Kraemer committed
93
    for (unsigned int i = 0; i< c.insideVertices.size(); ++i) out << c.insideVertices[i] << " ";
Pierre Kraemer's avatar
Pierre Kraemer committed
94
95
    out << "}" << std::endl ;
    out << "insideEdges (" << c.insideEdges.size() << ") = {";
Pierre Kraemer's avatar
Pierre Kraemer committed
96
    for (unsigned int i = 0; i< c.insideEdges.size(); ++i) out << c.insideEdges[i] << " ";
Pierre Kraemer's avatar
Pierre Kraemer committed
97
98
    out << "}" << std::endl ;
    out << "insideFaces (" << c.insideFaces.size() << ") = {";
Pierre Kraemer's avatar
Pierre Kraemer committed
99
    for (unsigned int i = 0; i< c.insideFaces.size(); ++i) out << c.insideFaces[i] << " ";
Pierre Kraemer's avatar
Pierre Kraemer committed
100
101
    out << "}" << std::endl ;
    out << "border (" << c.border.size() << ") = {";
Pierre Kraemer's avatar
Pierre Kraemer committed
102
    for (unsigned int i = 0; i< c.border.size(); ++i) out << c.border[i] << " ";
Pierre Kraemer's avatar
Pierre Kraemer committed
103
104
105
106
107
108
109
110
111
    out << "}" << std::endl;
    return out;
}

/*********************************************************
 * Collector One Ring
 *********************************************************/

template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
112
void Collector_OneRing<PFP>::collectAll(Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
113
{
Pierre Kraemer's avatar
Pierre Kraemer committed
114
	this->init(d);
115
	this->isInsideCollected = true;
116
117
118
	this->insideEdges.reserve(16);
	this->insideFaces.reserve(16);
	this->border.reserve(16);
Pierre Kraemer's avatar
Pierre Kraemer committed
119

120
121
122
123
124
125
126
127
	this->insideVertices.push_back(this->centerDart);

	Traversor2VE<typename PFP::MAP> te(this->map, this->centerDart) ;
	for(Dart it = te.begin(); it != te.end(); it = te.next())
		this->insideEdges.push_back(it);

	Traversor2VF<typename PFP::MAP> tf(this->map, this->centerDart) ;
	for(Dart it = tf.begin(); it != tf.end(); it = tf.next())
Pierre Kraemer's avatar
Pierre Kraemer committed
128
	{
129
130
131
		this->insideFaces.push_back(it);
		this->border.push_back(this->map.phi1(it));
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
132
133
134
}

template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
135
void Collector_OneRing<PFP>::collectBorder(Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
136
{
Pierre Kraemer's avatar
Pierre Kraemer committed
137
138
139
	this->init(d);
	this->border.reserve(12);

140
141
142
	Traversor2VF<typename PFP::MAP> t(this->map, this->centerDart) ;
	for(Dart it = t.begin(); it != t.end(); it = t.next())
		this->border.push_back(this->map.phi1(it));
Pierre Kraemer's avatar
Pierre Kraemer committed
143
144
}

145
template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
146
typename PFP::REAL Collector_OneRing<PFP>::computeArea(const VertexAttribute<VEC3, MAP_IMPL>& pos)
147
148
149
150
151
152
{
	assert(this->isInsideCollected || !"computeArea: inside cells have not been collected.") ;

	REAL area = 0;

	for (std::vector<Dart>::const_iterator it = this->insideFaces.begin(); it != this->insideFaces.end(); ++it)
153
		area += Algo::Surface::Geometry::triangleArea<PFP>(this->map, *it, pos);
154
155
156
157
158

	return area;
}

template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
159
void Collector_OneRing<PFP>::computeNormalCyclesTensor (const VertexAttribute<VEC3, MAP_IMPL>& pos, const EdgeAttribute<REAL, MAP_IMPL>& edgeangle, typename PFP::MATRIX33& tensor){
160
161
162
163
164
165
166
	assert(this->isInsideCollected || !"computeNormalCyclesTensor: inside cells have not been collected.") ;

	tensor.zero() ;

	// collect edges inside the neighborhood
	for (std::vector<Dart>::const_iterator it = this->insideEdges.begin(); it != this->insideEdges.end(); ++it)
	{
167
		const VEC3 e = Algo::Surface::Geometry::vectorOutOfDart<PFP>(this->map, *it, pos) ;
168
169
170
		tensor += Geom::transposed_vectors_mult(e,e) * edgeangle[*it] * (1 / e.norm()) ;
	}

171
172
173
174
175
	// collect edges on the border
	// TODO : should be an option ?
	// TODO : not boundary safe
	for (std::vector<Dart>::const_iterator it = this->border.begin(); it != this->border.end(); ++it)
	{
176
		const VEC3 e = Algo::Surface::Geometry::vectorOutOfDart<PFP>(this->map, *it, pos) ;
177
178
179
		tensor += Geom::transposed_vectors_mult(e,e) * edgeangle[*it] * (1 / e.norm()) ;
	}

180
181
182
	tensor /= computeArea(pos) ;
}

183
template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
184
void Collector_OneRing<PFP>::computeNormalCyclesTensor (const VertexAttribute<VEC3, MAP_IMPL>& pos, typename PFP::MATRIX33& tensor){
185
186
187
188
189
190
191
	assert(this->isInsideCollected || !"computeNormalCyclesTensor: inside cells have not been collected.") ;

	tensor.zero() ;

	// collect edges inside the neighborhood
	for (std::vector<Dart>::const_iterator it = this->insideEdges.begin(); it != this->insideEdges.end(); ++it)
	{
192
193
		const VEC3 e = Algo::Surface::Geometry::vectorOutOfDart<PFP>(this->map, *it, pos) ;
		const REAL edgeangle = Algo::Surface::Geometry::computeAngleBetweenNormalsOnEdge<PFP>(this->map, *it, pos) ;
194
195
196
		tensor += Geom::transposed_vectors_mult(e,e) * edgeangle * (1 / e.norm()) ;
	}

197
198
199
200
201
	// collect edges on the border
	// TODO : should be an option ?
	// TODO : not boundary safe
	for (std::vector<Dart>::const_iterator it = this->border.begin(); it != this->border.end(); ++it)
	{
202
203
		const VEC3 e = Algo::Surface::Geometry::vectorOutOfDart<PFP>(this->map, *it, pos) ;
		const REAL edgeangle = Algo::Surface::Geometry::computeAngleBetweenNormalsOnEdge<PFP>(this->map, *it, pos) ;
204
205
206
		tensor += Geom::transposed_vectors_mult(e,e) * edgeangle * (1 / e.norm()) ;
	}

207
208
209
	tensor /= computeArea(pos) ;
}

210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/*********************************************************
 * Collector One Ring aroung edge
 *********************************************************/

template <typename PFP>
void Collector_OneRing_AroundEdge<PFP>::collectAll(Dart d)
{
	// TODO : this collector is not boundary safe

	// init
	this->init(d);
	this->isInsideCollected = true;

	const Dart d2 = this->map.phi2(d);

	this->insideEdges.reserve(16);
	this->insideFaces.reserve(16);
	this->border.reserve(16);

Pierre Kraemer's avatar
Pierre Kraemer committed
229
	CellMarkerStore<MAP, FACE> fm (this->map, this->m_thread);
230
231
232
233
234
235
236
237
	fm.mark(d);
	fm.mark(d2);

	// collect
	this->insideVertices.push_back(d);
	this->insideVertices.push_back(d2);
	this->insideEdges.push_back(d);

Pierre Kraemer's avatar
Pierre Kraemer committed
238
	Traversor2EEaV<MAP> te(this->map, d) ;
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
	for(Dart it = te.begin(); it != te.end(); it = te.next())
	{
		this->insideEdges.push_back(it);
		this->insideFaces.push_back(it);
		if (! fm.isMarked(it)) this->border.push_back(this->map.phi1(it));
	}
}

template <typename PFP>
void Collector_OneRing_AroundEdge<PFP>::collectBorder(Dart d)
{
	// TODO : this collector is not boundary safe

	// init
	this->init(d);
	const Dart d2 = this->map.phi2(d);

	this->border.reserve(16);

Pierre Kraemer's avatar
Pierre Kraemer committed
258
	CellMarkerStore<MAP, FACE> fm (this->map, this->m_thread);
259
260
261
262
	fm.mark(d);
	fm.mark(d2);

	// collect
Pierre Kraemer's avatar
Pierre Kraemer committed
263
	Traversor2EEaV<MAP> te(this->map, d) ;
264
265
266
267
268
269
270
	for(Dart it = te.begin(); it != te.end(); it = te.next())
	{
		if (! fm.isMarked(it)) this->border.push_back(this->map.phi1(it));
	}
}

template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
271
typename PFP::REAL Collector_OneRing_AroundEdge<PFP>::computeArea(const VertexAttribute<VEC3, MAP_IMPL>& pos)
272
273
274
275
276
277
{
	assert(this->isInsideCollected || !"computeArea: inside cells have not been collected.") ;

	REAL area = 0;

	for (std::vector<Dart>::const_iterator it = this->insideFaces.begin(); it != this->insideFaces.end(); ++it)
278
		area += Algo::Surface::Geometry::triangleArea<PFP>(this->map, *it, pos);
279
280
281
282
283

	return area;
}

template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
284
void Collector_OneRing_AroundEdge<PFP>::computeNormalCyclesTensor (const VertexAttribute<VEC3, MAP_IMPL>& pos, const EdgeAttribute<REAL, MAP_IMPL>& edgeangle, typename PFP::MATRIX33& tensor){
285
286
287
288
289
290
291
	assert(this->isInsideCollected || !"computeNormalCyclesTensor: inside cells have not been collected.") ;

	tensor.zero() ;

	// collect edges inside the neighborhood
	for (std::vector<Dart>::const_iterator it = this->insideEdges.begin(); it != this->insideEdges.end(); ++it)
	{
292
		const VEC3 e = Algo::Surface::Geometry::vectorOutOfDart<PFP>(this->map, *it, pos) ;
293
294
295
		tensor += Geom::transposed_vectors_mult(e,e) * edgeangle[*it] * (1 / e.norm()) ;
	}

296
297
298
299
300
	// collect edges on the border
	// TODO : should be an option ?
	// TODO : not boundary safe
	for (std::vector<Dart>::const_iterator it = this->border.begin(); it != this->border.end(); ++it)
	{
301
		const VEC3 e = Algo::Surface::Geometry::vectorOutOfDart<PFP>(this->map, *it, pos) ;
302
303
304
		tensor += Geom::transposed_vectors_mult(e,e) * edgeangle[*it] * (1 / e.norm()) ;
	}

305
306
307
	tensor /= computeArea(pos) ;
}

308
template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
309
void Collector_OneRing_AroundEdge<PFP>::computeNormalCyclesTensor (const VertexAttribute<VEC3, MAP_IMPL>& pos, typename PFP::MATRIX33& tensor){
310
311
312
313
314
315
316
	assert(this->isInsideCollected || !"computeNormalCyclesTensor: inside cells have not been collected.") ;

	tensor.zero() ;

	// collect edges inside the neighborhood
	for (std::vector<Dart>::const_iterator it = this->insideEdges.begin(); it != this->insideEdges.end(); ++it)
	{
317
318
		const VEC3 e = Algo::Surface::Geometry::vectorOutOfDart<PFP>(this->map, *it, pos) ;
		const REAL edgeangle = Algo::Surface::Geometry::computeAngleBetweenNormalsOnEdge<PFP>(this->map, *it, pos) ;
319
320
321
		tensor += Geom::transposed_vectors_mult(e,e) * edgeangle * (1 / e.norm()) ;
	}

322
323
324
325
326
	// collect edges on the border
	// TODO : should be an option ?
	// TODO : not boundary safe
	for (std::vector<Dart>::const_iterator it = this->border.begin(); it != this->border.end(); ++it)
	{
327
328
		const VEC3 e = Algo::Surface::Geometry::vectorOutOfDart<PFP>(this->map, *it, pos) ;
		const REAL edgeangle = Algo::Surface::Geometry::computeAngleBetweenNormalsOnEdge<PFP>(this->map, *it, pos) ;
329
330
331
		tensor += Geom::transposed_vectors_mult(e,e) * edgeangle * (1 / e.norm()) ;
	}

332
333
334
335
	tensor /= computeArea(pos) ;
}


Pierre Kraemer's avatar
Pierre Kraemer committed
336
337
338
339
/*********************************************************
 * Collector Within Sphere
 *********************************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
340
template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
341
void Collector_WithinSphere<PFP>::collectAll(Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
342
{
Pierre Kraemer's avatar
Pierre Kraemer committed
343
	this->init(d);
344
	this->isInsideCollected = true;
345
346
347
	this->insideEdges.reserve(32);
	this->insideFaces.reserve(32);
	this->border.reserve(32);
Pierre Kraemer's avatar
Pierre Kraemer committed
348

Pierre Kraemer's avatar
Pierre Kraemer committed
349
350
351
	CellMarkerStore<MAP, VERTEX> vm(this->map, this->m_thread);	// mark the collected inside-vertices
	CellMarkerStore<MAP, EDGE> em(this->map, this->m_thread);	// mark the collected inside-edges + border-edges
	CellMarkerStore<MAP, FACE> fm(this->map, this->m_thread);	// mark the collected inside-faces + border-faces
Pierre Kraemer's avatar
Pierre Kraemer committed
352
353
354
355

	this->insideVertices.push_back(this->centerDart);
	vm.mark(this->centerDart);

Pierre Kraemer's avatar
Pierre Kraemer committed
356
	VEC3 centerPosition = this->position[d];
Pierre Kraemer's avatar
Pierre Kraemer committed
357
	unsigned int i = 0;
358
//	for(std::vector<Dart>::iterator iv = this->insideVertices.begin(); iv != this->insideVertices.end(); ++iv)
Pierre Kraemer's avatar
Pierre Kraemer committed
359
360
361
362
363
364
365
366
367
368
369
	while (i < this->insideVertices.size())
	{
		Dart end = this->insideVertices[i];
		Dart e = end;
		do
		{
			if (! em.isMarked(e) || ! fm.isMarked(e)) // are both tests useful ?
			{
				const Dart f = this->map.phi1(e);
				const Dart g = this->map.phi1(f);

370
				if (! Geom::isPointInSphere(this->position[f], centerPosition, this->radius))
Pierre Kraemer's avatar
Pierre Kraemer committed
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
				{
					this->border.push_back(e); // add to border
					em.mark(e);
					fm.mark(e); // is it useful ?
				}
				else
				{
					if (! vm.isMarked(f))
					{
						this->insideVertices.push_back(f);
						vm.mark(f);
					}
					if (! em.isMarked(e))
					{
						this->insideEdges.push_back(e);
						em.mark(e);
					}
388
					if (! fm.isMarked(e) && Geom::isPointInSphere(this->position[g], centerPosition, this->radius))
Pierre Kraemer's avatar
Pierre Kraemer committed
389
390
391
392
393
394
					{
						this->insideFaces.push_back(e);
						fm.mark(e);
					}
				}
			}
395
			e = this->map.phi2_1(e);
Pierre Kraemer's avatar
Pierre Kraemer committed
396
397
398
399
400
		} while (e != end);
		++i;
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
401
402
403
404
template <typename PFP>
void Collector_WithinSphere<PFP>::collectBorder(Dart d)
{
	this->init(d);
405
406
	this->border.reserve(128);
	this->insideVertices.reserve(128);
Pierre Kraemer's avatar
Pierre Kraemer committed
407

Pierre Kraemer's avatar
Pierre Kraemer committed
408
409
	CellMarkerStore<MAP, VERTEX> vm(this->map, this->m_thread);	// mark the collected inside-vertices
	CellMarkerStore<MAP, EDGE> em(this->map, this->m_thread);	// mark the collected inside-edges + border-edges
410
411
412

	this->insideVertices.push_back(this->centerDart);
	vm.mark(this->centerDart);
Pierre Kraemer's avatar
Pierre Kraemer committed
413
414
415
416
417
418
419
420
421

	VEC3 centerPosition = this->position[d];
	unsigned int i = 0;
	while (i < this->insideVertices.size())
	{
		Dart end = this->insideVertices[i];
		Dart e = end;
		do
		{
422
			if ( ! em.isMarked(e) )
Pierre Kraemer's avatar
Pierre Kraemer committed
423
424
425
426
427
428
429
			{
				const Dart f = this->map.phi1(e);

				if (! Geom::isPointInSphere(this->position[f], centerPosition, this->radius))
				{
					this->border.push_back(e); // add to border
				}
430
431
432
433
434
435
436
437
438
				else
				{
					if (! vm.isMarked(f))
					{
						this->insideVertices.push_back(f);
						vm.mark(f);
					}
				}
				em.mark(e);
Pierre Kraemer's avatar
Pierre Kraemer committed
439
			}
440
			e = this->map.phi2_1(e);
Pierre Kraemer's avatar
Pierre Kraemer committed
441
442
443
		} while (e != end);
		++i;
	}
444
	this->insideVertices.clear();
Pierre Kraemer's avatar
Pierre Kraemer committed
445
446
}

447

Pierre Kraemer's avatar
Pierre Kraemer committed
448
template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
449
typename PFP::REAL Collector_WithinSphere<PFP>::computeArea(const VertexAttribute<VEC3, MAP_IMPL>& pos)
Pierre Kraemer's avatar
Pierre Kraemer committed
450
{
451
	assert(this->isInsideCollected || !"computeArea: inside cells have not been collected.") ;
452

453
	VEC3 centerPosition = pos[this->centerDart];
454
	REAL area = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
455

Pierre Kraemer's avatar
Pierre Kraemer committed
456
	for (std::vector<Dart>::const_iterator it = this->insideFaces.begin(); it != this->insideFaces.end(); ++it)
457
		area += Geometry::triangleArea<PFP>(this->map, *it, pos);
Pierre Kraemer's avatar
Pierre Kraemer committed
458
459
460
461
462

	for (std::vector<Dart>::const_iterator it = this->border.begin(); it != this->border.end(); ++it)
	{
		const Dart f = this->map.phi1(*it); // we know that f is outside
		const Dart g = this->map.phi1(f);
463
		if (Geom::isPointInSphere(pos[g], centerPosition, this->radius))
Pierre Kraemer's avatar
Pierre Kraemer committed
464
		{ // only f is outside
Pierre Kraemer's avatar
Pierre Kraemer committed
465
			REAL alpha, beta;
466
467
			Geometry::intersectionSphereEdge<PFP>(this->map, centerPosition, this->radius, *it, pos, alpha);
			Geometry::intersectionSphereEdge<PFP>(this->map, centerPosition, this->radius, this->map.phi2(f), pos, beta);
468
			area += (alpha+beta - alpha*beta) * Algo::Surface::Geometry::triangleArea<PFP>(this->map, *it, pos);
Pierre Kraemer's avatar
Pierre Kraemer committed
469
470
471
		}
		else
		{ // f and g are outside
Pierre Kraemer's avatar
Pierre Kraemer committed
472
			REAL alpha, beta;
473
474
			Geometry::intersectionSphereEdge<PFP>(this->map, centerPosition, this->radius, *it, pos, alpha);
			Geometry::intersectionSphereEdge<PFP>(this->map, centerPosition, this->radius, this->map.phi2(g), pos, beta);
475
			area += alpha * beta * Algo::Surface::Geometry::triangleArea<PFP>(this->map, *it, pos);
Pierre Kraemer's avatar
Pierre Kraemer committed
476
477
		}
	}
478
479
480
481
	return area;
}

template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
482
void Collector_WithinSphere<PFP>::computeNormalCyclesTensor (const VertexAttribute<VEC3, MAP_IMPL>& pos, const EdgeAttribute<REAL, MAP_IMPL>& edgeangle, typename PFP::MATRIX33& tensor){
483
484
	assert(this->isInsideCollected || !"computeNormalCyclesTensor: inside cells have not been collected.") ;

485
	VEC3 centerPosition = pos[this->centerDart];
486
487
488
489
490
	tensor.zero() ;

	// collect edges inside the neighborhood
	for (std::vector<Dart>::const_iterator it = this->insideEdges.begin(); it != this->insideEdges.end(); ++it)
	{
491
		const VEC3 e = Algo::Surface::Geometry::vectorOutOfDart<PFP>(this->map, *it, pos) ;
492
493
494
495
496
		tensor += Geom::transposed_vectors_mult(e,e) * edgeangle[*it] * (1 / e.norm()) ;
	}
	// collect edges crossing the neighborhood's border
	for (std::vector<Dart>::const_iterator it = this->border.begin(); it != this->border.end(); ++it)
	{
497
		const VEC3 e = Algo::Surface::Geometry::vectorOutOfDart<PFP>(this->map, *it, pos) ;
498
		REAL alpha ;
499
		Algo::Surface::Geometry::intersectionSphereEdge<PFP>(this->map, centerPosition, radius, *it, pos, alpha) ;
500
501
502
		tensor += Geom::transposed_vectors_mult(e,e) * edgeangle[*it] * (1 / e.norm()) * alpha ;
	}

503
	tensor /= computeArea(pos) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
504
505
}

506
template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
507
void Collector_WithinSphere<PFP>::computeNormalCyclesTensor (const VertexAttribute<VEC3, MAP_IMPL>& pos, typename PFP::MATRIX33& tensor){
508
509
510
511
512
513
514
515
	assert(this->isInsideCollected || !"computeNormalCyclesTensor: inside cells have not been collected.") ;

	VEC3 centerPosition = pos[this->centerDart];
	tensor.zero() ;

	// collect edges inside the neighborhood
	for (std::vector<Dart>::const_iterator it = this->insideEdges.begin(); it != this->insideEdges.end(); ++it)
	{
516
517
		const VEC3 e = Algo::Surface::Geometry::vectorOutOfDart<PFP>(this->map, *it, pos) ;
		const REAL edgeangle = Algo::Surface::Geometry::computeAngleBetweenNormalsOnEdge<PFP>(this->map, *it, pos) ;
518
519
520
521
522
		tensor += Geom::transposed_vectors_mult(e,e) * edgeangle * (1 / e.norm()) ;
	}
	// collect edges crossing the neighborhood's border
	for (std::vector<Dart>::const_iterator it = this->border.begin(); it != this->border.end(); ++it)
	{
523
		const VEC3 e = Algo::Surface::Geometry::vectorOutOfDart<PFP>(this->map, *it, pos) ;
524
		REAL alpha ;
525
526
		Algo::Surface::Geometry::intersectionSphereEdge<PFP>(this->map, centerPosition, radius, *it, pos, alpha) ;
		const REAL edgeangle = Algo::Surface::Geometry::computeAngleBetweenNormalsOnEdge<PFP>(this->map, *it, pos) ;
527
528
529
530
531
532
		tensor += Geom::transposed_vectors_mult(e,e) * edgeangle * (1 / e.norm()) * alpha ;
	}

	tensor /= computeArea(pos) ;
}

533
/*********************************************************
534
 * Collector Normal Angle (Vertices)
535
536
537
538
539
540
 *********************************************************/

template <typename PFP>
void Collector_NormalAngle<PFP>::collectAll(Dart d)
{
	this->init(d);
541
	this->isInsideCollected = true;
542
543
544
545
	this->insideEdges.reserve(32);
	this->insideFaces.reserve(32);
	this->border.reserve(32);

Pierre Kraemer's avatar
Pierre Kraemer committed
546
547
548
	CellMarkerStore<MAP, VERTEX> vm(this->map, this->m_thread);	// mark the collected inside-vertices
	CellMarkerStore<MAP, EDGE> em(this->map, this->m_thread);	// mark the collected inside-edges + border-edges
	CellMarkerStore<MAP, FACE> fm(this->map, this->m_thread);	// mark the collected inside-faces + border-faces
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607

	this->insideVertices.push_back(this->centerDart);
	vm.mark(this->centerDart);

	VEC3 centerNormal = this->normal[d];
	unsigned int i = 0;
	while (i < this->insideVertices.size())
	{
		Dart end = this->insideVertices[i];
		Dart e = end;
		do
		{
			if (! em.isMarked(e) || ! fm.isMarked(e)) // are both tests useful ?
			{
				const Dart f = this->map.phi1(e);
				const Dart g = this->map.phi1(f);

				REAL a = Geom::angle(centerNormal, this->normal[f]);

				if (a > angleThreshold)
				{
					this->border.push_back(e); // add to border
					em.mark(e);
					fm.mark(e); // is it useful ?
				}
				else
				{
					if (! vm.isMarked(f))
					{
						this->insideVertices.push_back(f);
						vm.mark(f);
					}
					if (! em.isMarked(e))
					{
						this->insideEdges.push_back(e);
						em.mark(e);
					}

					REAL b = Geom::angle(centerNormal, this->normal[g]);
					if (! fm.isMarked(e) && b < angleThreshold)
					{
						this->insideFaces.push_back(e);
						fm.mark(e);
					}
				}
			}
			e = this->map.phi2_1(e);
		} while (e != end);
		++i;
	}
}

template <typename PFP>
void Collector_NormalAngle<PFP>::collectBorder(Dart d)
{
	this->init(d);
	this->border.reserve(128);
	this->insideVertices.reserve(128);

Pierre Kraemer's avatar
Pierre Kraemer committed
608
609
	CellMarkerStore<MAP, VERTEX> vm(this->map, this->m_thread);	// mark the collected inside-vertices
	CellMarkerStore<MAP, EDGE> em(this->map, this->m_thread);	// mark the collected inside-edges + border-edges
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642

	this->insideVertices.push_back(this->centerDart);
	vm.mark(this->centerDart);

	VEC3 centerNormal = this->normal[d];
	unsigned int i = 0;
	while (i < this->insideVertices.size())
	{
		Dart end = this->insideVertices[i];
		Dart e = end;
		do
		{
			if ( ! em.isMarked(e) )
			{
				const Dart f = this->map.phi1(e);

				REAL a = Geom::angle(centerNormal, this->normal[f]);

				if (a > angleThreshold)
				{
					this->border.push_back(e); // add to border
				}
				else
				{
					if (! vm.isMarked(f))
					{
						this->insideVertices.push_back(f);
						vm.mark(f);
					}
				}
				em.mark(e);
			}
			e = this->map.phi2_1(e);
Basile Sauvage's avatar
Basile Sauvage committed
643
644
645
646
647
648
		} while (e != end);
		++i;
	}
	this->insideVertices.clear();
}

649
650
651
652
653
654
655
656
/*********************************************************
 * Collector Normal Angle (Triangles)
 *********************************************************/

template <typename PFP>
void Collector_NormalAngle_Triangles<PFP>::collectAll(Dart d)
{
	this->init(d);
657
	this->isInsideCollected = true;
Basile Sauvage's avatar
Basile Sauvage committed
658
	this->insideVertices.reserve(32);
659
660
661
662
	this->insideEdges.reserve(32);
	this->insideFaces.reserve(32);
	this->border.reserve(32);

Pierre Kraemer's avatar
Pierre Kraemer committed
663
664
	CellMarkerStore<MAP, FACE> fm(this->map, this->m_thread);	// mark the collected inside-faces + front-faces
	CellMarkerStore<MAP, FACE> fminside(this->map, this->m_thread);	// mark the collected inside-faces
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681

	std::queue<Dart> front;
	front.push(this->centerDart);
	fm.mark(this->centerDart);
	VEC3 centerNormal = this->normal[this->centerDart];

	while ( !front.empty() ) // collect inside faces
	{
		Dart f = front.front();
		front.pop();
		REAL a = Geom::angle(centerNormal, this->normal[f]);


		if (a < angleThreshold )
		{ // collect this face and add adjacent faces to the front
			this->insideFaces.push_back(f);
			fminside.mark(f);
Pierre Kraemer's avatar
Pierre Kraemer committed
682
			Traversor2FFaE<MAP> t (this->map, f) ;
683
684
685
686
687
688
689
690
691
692
693
			for (Dart it = t.begin(); it != t.end(); it=t.next())
			{
				if (!fm.isMarked(it))
				{
					front.push(it);
					fm.mark(it);
				}
			}
		}
	}

Pierre Kraemer's avatar
Pierre Kraemer committed
694
695
	CellMarkerStore<MAP, VERTEX> vm(this->map, this->m_thread);	// mark inside-vertices and border-vertices
	CellMarkerStore<MAP, EDGE> em(this->map, this->m_thread);	// mark inside-edges and border-edges
696
697
698
	std::vector<Dart>::iterator f_it;
	for (f_it = this->insideFaces.begin(); f_it != this->insideFaces.end(); f_it++)
	{ // collect insideVertices, insideEdges, and border
Pierre Kraemer's avatar
Pierre Kraemer committed
699
		Traversor2FE<MAP> te (this->map, *f_it) ;
700
701
702
703
704
705
706
707
708
709
710
711
712
713
		for (Dart it = te.begin(); it != te.end(); it=te.next())
		{ // collect insideEdges and border
			if (!em.isMarked(it))
			{
				em.mark(it);
				if (this->map.isBoundaryEdge(it))
					this->border.push_back(it);
				else if ( fminside.isMarked(it) && fminside.isMarked(this->map.phi2(it)) )
					this->insideEdges.push_back(it);
				else
					this->border.push_back(it);
			}
		}

Pierre Kraemer's avatar
Pierre Kraemer committed
714
		Traversor2FV<MAP> tv (this->map, *f_it) ;
715
716
717
718
719
		for (Dart it = tv.begin(); it != tv.end(); it=tv.next())
		{ // collect insideVertices
			if (!vm.isMarked(it))
			{
				vm.mark(it);
720
721
722
723
724
725
726
727
728
729
				this->insideVertices.push_back(it);
//				if ( !this->map.isBoundaryVertex(it))
//				{
//					Traversor2VF<typename PFP::MAP> tf (this->map, it);
//					Dart it2 = tf.begin();
//					while ( (it2 != tf.end()) && fminside.isMarked(it2))
//						it2=tf.next();
//					if (it2 == tf.end())
//						this->insideVertices.push_back(it);
//				}
730
731
732
733
734
735
736
737
738
739
740
741
742
			}
		}
	}

}

template <typename PFP>
void Collector_NormalAngle_Triangles<PFP>::collectBorder(Dart d)
{
	this->init(d);
	this->insideFaces.reserve(32);
	this->border.reserve(32);

Pierre Kraemer's avatar
Pierre Kraemer committed
743
744
	CellMarkerStore<MAP, FACE> fm(this->map, this->m_thread);	// mark the collected inside-faces + front-faces
	CellMarkerStore<MAP, FACE> fminside(this->map, this->m_thread);	// mark the collected inside-faces
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760

	std::queue<Dart> front;
	front.push(this->centerDart);
	fm.mark(this->centerDart);
	VEC3 centerNormal = this->normal[this->centerDart];

	while ( !front.empty() ) // collect inside faces
	{
		Dart f = front.front();
		front.pop();
		REAL a = Geom::angle(centerNormal, this->normal[f]);

		if (a < angleThreshold )
		{ // collect this face and add adjacent faces to the front
			this->insideFaces.push_back(f);
			fminside.mark(f);
Pierre Kraemer's avatar
Pierre Kraemer committed
761
			Traversor2FFaE<MAP> t (this->map, f) ;
762
763
764
765
766
767
768
769
770
771
772
			for (Dart it = t.begin(); it != t.end(); it=t.next())
			{
				if (!fm.isMarked(it))
				{
					front.push(it);
					fm.mark(it);
				}
			}
		}
	}

Pierre Kraemer's avatar
Pierre Kraemer committed
773
	CellMarkerStore<MAP, EDGE> em(this->map, this->m_thread);	// mark inside-edges and border-edges
774
775
776
	std::vector<Dart>::iterator f_it;
	for (f_it = this->insideFaces.begin(); f_it != this->insideFaces.end(); f_it++)
	{ // collect border (edges)
Pierre Kraemer's avatar
Pierre Kraemer committed
777
		Traversor2FE<MAP> te (this->map, *f_it) ;
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
		for (Dart it = te.begin(); it != te.end(); it=te.next())
		{
			if (!em.isMarked(it))
			{
				em.mark(it);
				if (this->map.isBoundaryEdge(it))
					this->border.push_back(it);
				else if ( !fminside.isMarked(it) || !fminside.isMarked(this->map.phi2(it)) )
					this->border.push_back(it);
			}
		}
	}
	this->insideFaces.clear();
}

793
794
795
796
797
798
799
800
801
802
803
804
805
806
/*********************************************************
 * Collector Vertices
 *********************************************************/

template <typename PFP>
void Collector_Vertices<PFP>::collectAll(Dart d)
{
	crit.init(d);
	this->init(d);
	this->isInsideCollected = true;
	this->insideEdges.reserve(32);
	this->insideFaces.reserve(32);
	this->border.reserve(32);

Pierre Kraemer's avatar
Pierre Kraemer committed
807
808
809
	CellMarkerStore<MAP, VERTEX> vm(this->map, this->m_thread);	// mark the collected inside-vertices
	CellMarkerStore<MAP, EDGE> em(this->map, this->m_thread);	// mark the collected inside-edges + border-edges
	CellMarkerStore<MAP, FACE> fm(this->map, this->m_thread);	// mark the collected inside-faces + border-faces
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864

	this->insideVertices.push_back(this->centerDart);
	vm.mark(this->centerDart);

	unsigned int i = 0;
	while (i < this->insideVertices.size())
	{
		Dart end = this->insideVertices[i];
		Dart e = end;
		do
		{
			if (! em.isMarked(e) || ! fm.isMarked(e)) // are both tests useful ?
			{
				const Dart f = this->map.phi1(e);
				const Dart g = this->map.phi1(f);

				if (! crit.isInside(f))
				{
					this->border.push_back(e); // add to border
					em.mark(e);
					fm.mark(e); // is it useful ?
				}
				else
				{
					if (! vm.isMarked(f))
					{
						this->insideVertices.push_back(f);
						vm.mark(f);
					}
					if (! em.isMarked(e))
					{
						this->insideEdges.push_back(e);
						em.mark(e);
					}
					if (! fm.isMarked(e) && crit.isInside(g))
					{
						this->insideFaces.push_back(e);
						fm.mark(e);
					}
				}
			}
			e = this->map.phi2_1(e);
		} while (e != end);
		++i;
	}
}

template <typename PFP>
void Collector_Vertices<PFP>::collectBorder(Dart d)
{
	crit.init(d);
	this->init(d);
	this->border.reserve(128);
	this->insideVertices.reserve(128);

Pierre Kraemer's avatar
Pierre Kraemer committed
865
866
	CellMarkerStore<MAP, VERTEX> vm(this->map, this->m_thread);	// mark the collected inside-vertices
	CellMarkerStore<MAP, EDGE> em(this->map, this->m_thread);	// mark the collected inside-edges + border-edges
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902

	this->insideVertices.push_back(this->centerDart);
	vm.mark(this->centerDart);

	unsigned int i = 0;
	while (i < this->insideVertices.size())
	{
		Dart end = this->insideVertices[i];
		Dart e = end;
		do
		{
			if ( ! em.isMarked(e) )
			{
				const Dart f = this->map.phi1(e);

				if (! crit.isInside(f))
				{
					this->border.push_back(e); // add to border
				}
				else
				{
					if (! vm.isMarked(f))
					{
						this->insideVertices.push_back(f);
						vm.mark(f);
					}
				}
				em.mark(e);
			}
			e = this->map.phi2_1(e);
		} while (e != end);
		++i;
	}
	this->insideVertices.clear();
}

Basile Sauvage's avatar
Basile Sauvage committed
903
904
905
906
907
908
909
910
911
/*********************************************************
 * Collector Triangles
 *********************************************************/

template <typename PFP>
void Collector_Triangles<PFP>::collectAll(Dart d)
{
	crit.init(d);
	this->init(d);
912
	this->isInsideCollected = true;
Basile Sauvage's avatar
Basile Sauvage committed
913
914
915
916
917
	this->insideVertices.reserve(32);
	this->insideEdges.reserve(32);
	this->insideFaces.reserve(32);
	this->border.reserve(32);

Pierre Kraemer's avatar
Pierre Kraemer committed
918
919
	CellMarkerStore<MAP, FACE> fm(this->map, this->m_thread);	// mark the collected inside-faces + front-faces
	CellMarkerStore<MAP, FACE> fminside(this->map, this->m_thread);	// mark the collected inside-faces
Basile Sauvage's avatar
Basile Sauvage committed
920
921
922
923
924
925
926
927
928
929
930
931
932
933

	std::queue<Dart> front;
	front.push(this->centerDart);
	fm.mark(this->centerDart);

	while ( !front.empty() ) // collect inside faces
	{
		Dart f = front.front();
		front.pop();

		if (crit.isInside(f))
		{ // collect this face and add adjacent faces to the front
			this->insideFaces.push_back(f);
			fminside.mark(f);
Pierre Kraemer's avatar
Pierre Kraemer committed
934
			Traversor2FFaE<MAP> t (this->map, f) ;
Basile Sauvage's avatar
Basile Sauvage committed
935
936
937
938
939
940
941
942
943
944
945
			for (Dart it = t.begin(); it != t.end(); it=t.next())
			{
				if (!fm.isMarked(it))
				{
					front.push(it);
					fm.mark(it);
				}
			}
		}
	}

Pierre Kraemer's avatar
Pierre Kraemer committed
946
947
	CellMarkerStore<MAP, VERTEX> vm(this->map, this->m_thread);	// mark inside-vertices and border-vertices
	CellMarkerStore<MAP, EDGE> em(this->map, this->m_thread);	// mark inside-edges and border-edges
Basile Sauvage's avatar
Basile Sauvage committed
948
949
950
	std::vector<Dart>::iterator f_it;
	for (f_it = this->insideFaces.begin(); f_it != this->insideFaces.end(); f_it++)
	{ // collect insideVertices, insideEdges, and border
Pierre Kraemer's avatar
Pierre Kraemer committed
951
		Traversor2FE<MAP> te (this->map, *f_it) ;
Basile Sauvage's avatar
Basile Sauvage committed
952
953
954
955
956
957
958
959
960
961
962
963
964
965
		for (Dart it = te.begin(); it != te.end(); it=te.next())
		{ // collect insideEdges and border
			if (!em.isMarked(it))
			{
				em.mark(it);
				if (this->map.isBoundaryEdge(it))
					this->border.push_back(it);
				else if ( fminside.isMarked(it) && fminside.isMarked(this->map.phi2(it)) )
					this->insideEdges.push_back(it);
				else
					this->border.push_back(it);
			}
		}

Pierre Kraemer's avatar
Pierre Kraemer committed
966
		Traversor2FV<MAP> tv (this->map, *f_it) ;
Basile Sauvage's avatar
Basile Sauvage committed
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
		for (Dart it = tv.begin(); it != tv.end(); it=tv.next())
		{ // collect insideVertices
			if (!vm.isMarked(it))
			{
				vm.mark(it);
				this->insideVertices.push_back(it);
			}
		}
	}
}

template <typename PFP>
void Collector_Triangles<PFP>::collectBorder(Dart d)
{
	crit.init(d);
	this->init(d);
	this->insideFaces.reserve(32);
	this->border.reserve(32);

Pierre Kraemer's avatar
Pierre Kraemer committed
986
987
	CellMarkerStore<MAP, FACE> fm(this->map, this->m_thread);	// mark the collected inside-faces + front-faces
	CellMarkerStore<MAP, FACE> fminside(this->map, this->m_thread);	// mark the collected inside-faces
Basile Sauvage's avatar
Basile Sauvage committed
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001

	std::queue<Dart> front;
	front.push(this->centerDart);
	fm.mark(this->centerDart);

	while ( !front.empty() ) // collect inside faces
	{
		Dart f = front.front();
		front.pop();

		if (crit.isInside(f) )
		{ // collect this face and add adjacent faces to the front
			this->insideFaces.push_back(f);
			fminside.mark(f);
Pierre Kraemer's avatar
Pierre Kraemer committed
1002
			Traversor2FFaE<MAP> t (this->map, f) ;
Basile Sauvage's avatar
Basile Sauvage committed
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
			for (Dart it = t.begin(); it != t.end(); it=t.next())
			{
				if (!fm.isMarked(it))
				{
					front.push(it);
					fm.mark(it);
				}
			}
		}
	}

Pierre Kraemer's avatar
Pierre Kraemer committed
1014
	CellMarkerStore<MAP, EDGE> em(this->map, this->m_thread);	// mark inside-edges and border-edges
Basile Sauvage's avatar
Basile Sauvage committed
1015
1016
1017
	std::vector<Dart>::iterator f_it;
	for (f_it = this->insideFaces.begin(); f_it != this->insideFaces.end(); f_it++)
	{ // collect border (edges)
Pierre Kraemer's avatar
Pierre Kraemer committed
1018
		Traversor2FE<MAP> te (this->map, *f_it) ;
Basile Sauvage's avatar
Basile Sauvage committed
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
		for (Dart it = te.begin(); it != te.end(); it=te.next())
		{
			if (!em.isMarked(it))
			{
				em.mark(it);
				if (this->map.isBoundaryEdge(it))
					this->border.push_back(it);
				else if ( !fminside.isMarked(it) || !fminside.isMarked(this->map.phi2(it)) )
					this->border.push_back(it);
			}
		}
	}
	this->insideFaces.clear();
}

Basile Sauvage's avatar
Basile Sauvage committed
1034
/*********************************************************
1035
 * Collector Dijkstra_Vertices
Basile Sauvage's avatar
Basile Sauvage committed
1036
1037
1038
 *********************************************************/

template <typename PFP>
1039
void Collector_Dijkstra_Vertices<PFP>::collectAll(Dart dinit)
1040
{
Basile Sauvage's avatar
Basile Sauvage committed
1041
	init(dinit);
1042
	this->isInsideCollected = true;
Basile Sauvage's avatar
Basile Sauvage committed
1043

Pierre Kraemer's avatar
Pierre Kraemer committed
1044
	CellMarkerStore<MAP, VERTEX> vmReached (this->map, this->m_thread);
Basile Sauvage's avatar
Basile Sauvage committed
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
	vertexInfo[this->centerDart].it = front.insert(std::pair<float,Dart>(0.0, this->centerDart));
	vertexInfo[this->centerDart].valid = true;
	vmReached.mark(this->centerDart);

	while ( !front.empty() && front.begin()->first < this->maxDist)
	{
		Dart e = front.begin()->second;
		float d = front.begin()->first;
		front.erase(vertexInfo[e].it);
		vertexInfo[e].valid=false;
		this->insideVertices.push_back(e);

Pierre Kraemer's avatar
Pierre Kraemer committed
1057
		Traversor2VVaE<MAP> tv (this->map, e);
Basile Sauvage's avatar
Basile Sauvage committed
1058
1059
1060
1061
1062
		for (Dart f = tv.begin(); f != tv.end(); f=tv.next())
		{
			VertexInfo& vi (vertexInfo[f]);
			if (vmReached.isMarked(f))
			{
1063
				if (vi.valid) // probably useless (because of distance test) but faster
Basile Sauvage's avatar
Basile Sauvage committed
1064
				{
1065
					float dist = d + edge_cost[f];
Basile Sauvage's avatar
Basile Sauvage committed
1066
1067
1068
1069
1070
1071
1072
1073
1074
					if (dist < vi.it->first)
					{
						front.erase(vi.it);
						vi.it = front.insert(std::pair<float,Dart>(dist, f));
					}
				}
			}
			else
			{
1075
				vi.it = front.insert(std::pair<float,Dart>(d + edge_cost[f], f));
Basile Sauvage's avatar
Basile Sauvage committed
1076
1077
1078
1079
1080
1081
1082
1083
				vi.valid=true;
				vmReached.mark(f);
			}

		}

	}

1084
1085
1086
1087
1088
1089
	while ( !front.empty())
	{
		vmReached.unmark(front.begin()->second);
		front.erase(front.begin());
	}

Pierre Kraemer's avatar
Pierre Kraemer committed
1090
1091
	CellMarkerStore<MAP, EDGE> em (this->map, this->m_thread);
	CellMarkerStore<MAP, FACE> fm (this->map, this->m_thread);
1092
1093
1094
	for (std::vector<Dart>::iterator e_it = this->insideVertices.begin(); e_it != this->insideVertices.end() ; e_it++)
	{
		// collect insideEdges
Pierre Kraemer's avatar
Pierre Kraemer committed
1095
		Traversor2VE<MAP> te (this->map, *e_it);
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
		for (Dart e = te.begin(); e != te.end(); e=te.next())
		{
			if ( !em.isMarked(e) && vmReached.isMarked(this->map.phi2(e)) )
			{ // opposite vertex is inside -> inside edge
				this->insideEdges.push_back(e);
				em.mark(e);
			}
		}

		// collect insideFaces and border
Pierre Kraemer's avatar
Pierre Kraemer committed
1106
		Traversor2VF<MAP> tf (this->map, *e_it);
1107
1108
1109
1110
1111
		for (Dart f = tf.begin(); f != tf.end(); f=tf.next())
		{
			if ( !fm.isMarked(f) )
			{
				fm.mark(f);
Pierre Kraemer's avatar
Pierre Kraemer committed
1112
				Traversor2FV<MAP> tv (this->map, f);
1113
1114
1115
1116
1117
1118
1119
1120
1121
				Dart v = tv.begin();
				while ( v != tv.end() && vmReached.isMarked(v) ) {v=tv.next();}
				if ( v == tv.end() )
					this->insideFaces.push_back(f);
				else
					this->border.push_back(f);
			}
		}
	}
Basile Sauvage's avatar
Basile Sauvage committed
1122
1123
1124
}

template <typename PFP>
1125
void Collector_Dijkstra_Vertices<PFP>::collectBorder(Dart dinit)
1126
{
1127
	init(dinit);
Basile Sauvage's avatar
Basile Sauvage committed
1128

Pierre Kraemer's avatar
Pierre Kraemer committed
1129
	CellMarkerStore<MAP, VERTEX> vmReached (this->map, this->m_thread);
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
	vertexInfo[this->centerDart].it = front.insert(std::pair<float,Dart>(0.0, this->centerDart));
	vertexInfo[this->centerDart].valid = true;
	vmReached.mark(this->centerDart);

	while ( !front.empty() && front.begin()->first < this->maxDist)
	{
		Dart e = front.begin()->second;
		float d = front.begin()->first;
		front.erase(vertexInfo[e].it);
		vertexInfo[e].valid=false;
		this->insideVertices.push_back(e);

Pierre Kraemer's avatar
Pierre Kraemer committed
1142
		Traversor2VVaE<MAP> tv (this->map, e);
1143
1144
1145
1146
1147
1148
1149
		for (Dart f = tv.begin(); f != tv.end(); f=tv.next())
		{
			VertexInfo& vi (vertexInfo[f]);
			if (vmReached.isMarked(f))
			{
				if (vi.valid) // probably useless (because of distance test) but faster
				{
1150
					float dist = d + edge_cost[f];
1151
1152
1153
1154
1155
1156
1157
1158
1159
					if (dist < vi.it->first)
					{
						front.erase(vi.it);
						vi.it = front.insert(std::pair<float,Dart>(dist, f));
					}
				}
			}
			else
			{
1160
				vi.it = front.insert(std::pair<float,Dart>(d + edge_cost[f], f));
Pierre Kraemer's avatar
Pierre Kraemer committed
1161
				vi.valid = true;
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
				vmReached.mark(f);
			}
		}
	}

	while ( !front.empty())
	{
		vmReached.unmark(front.begin()->second);
		front.erase(front.begin());
	}

Pierre Kraemer's avatar
Pierre Kraemer committed
1173
	CellMarkerStore<MAP, FACE> fm (this->map, this->m_thread);
1174
1175
1176
	for (std::vector<Dart>::iterator e_it = this->insideVertices.begin(); e_it != this->insideVertices.end() ; e_it++)
	{
		// collect border
Pierre Kraemer's avatar
Pierre Kraemer committed
1177
		Traversor2VF<MAP> tf (this->map, *e_it);
1178
1179
1180
1181
1182
		for (Dart f = tf.begin(); f != tf.end(); f=tf.next())
		{
			if ( !fm.isMarked(f) )
			{
				fm.mark(f);
Pierre Kraemer's avatar
Pierre Kraemer committed
1183
				Traversor2FV<MAP> tv (this->map, f);
1184
1185
1186
1187
1188
1189
1190
1191
				Dart v = tv.begin();
				while ( v != tv.end() && vmReached.isMarked(v) ) {v=tv.next();}
				if ( v != tv.end() )
					this->border.push_back(f);
			}
		}
	}
	this->insideVertices.clear();
Basile Sauvage's avatar
Basile Sauvage committed
1192
1193
}

Basile Sauvage's avatar
Basile Sauvage committed
1194
/*********************************************************
1195
 * Collector Dijkstra
Basile Sauvage's avatar
Basile Sauvage committed
1196
1197
1198
 *********************************************************/

template <typename PFP>
1199
void Collector_Dijkstra<PFP>::collectAll(Dart dinit)
Basile Sauvage's avatar
Basile Sauvage committed
1200
1201
{
	init(dinit);
1202
	this->isInsideCollected = true;
Basile Sauvage's avatar
Basile Sauvage committed
1203

Pierre Kraemer's avatar
Pierre Kraemer committed
1204
	CellMarkerStore<MAP, VERTEX> vmReached (this->map, this->m_thread);
Basile Sauvage's avatar
Basile Sauvage committed
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
	vertexInfo[this->centerDart].it = front.insert(std::pair<float,Dart>(0.0, this->centerDart));
	vertexInfo[this->centerDart].valid = true;
	vmReached.mark(this->centerDart);

	while ( !front.empty() && front.begin()->first < this->maxDist)
	{
		Dart e = front.begin()->second;
		float d = front.begin()->first;
		front.erase(vertexInfo[e].it);
		vertexInfo[e].valid=false;
		this->insideVertices.push_back(e);

Pierre Kraemer's avatar
Pierre Kraemer committed
1217
		Traversor2VVaE<MAP> tv (this->map, e);
Basile Sauvage's avatar
Basile Sauvage committed
1218
1219
1220
1221
1222
1223
1224
		for (Dart f = tv.begin(); f != tv.end(); f=tv.next())
		{
			VertexInfo& vi (vertexInfo[f]);
			if (vmReached.isMarked(f))
			{
				if (vi.valid) // probably useless (because of distance test) but faster
				{
1225
					float dist = d + edgeLength(f);
Basile Sauvage's avatar
Basile Sauvage committed
1226
1227
1228
1229
1230
1231
1232
1233
1234
					if (dist < vi.it->first)
					{
						front.erase(vi.it);
						vi.it = front.insert(std::pair<float,Dart>(dist, f));
					}
				}
			}
			else
			{
1235
				vi.it = front.insert(std::pair<float,Dart>(d + edgeLength(f), f));
Pierre Kraemer's avatar
Pierre Kraemer committed
1236
				vi.valid = true;
Basile Sauvage's avatar
Basile Sauvage committed
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
				vmReached.mark(f);
			}
		}
	}

	while ( !front.empty())
	{
		vmReached.unmark(front.begin()->second);
		front.erase(front.begin());
	}

Pierre Kraemer's avatar
Pierre Kraemer committed
1248
1249
	CellMarkerStore<MAP, EDGE> em (this->map, this->m_thread);
	CellMarkerStore<MAP, FACE> fm (this->map, this->m_thread);
Basile Sauvage's avatar
Basile Sauvage committed
1250
1251
1252
	for (std::vector<Dart>::iterator e_it = this->insideVertices.begin(); e_it != this->insideVertices.end() ; e_it++)
	{
		// collect insideEdges
Pierre Kraemer's avatar
Pierre Kraemer committed
1253
		Traversor2VE<MAP> te (this->map, *e_it);
Basile Sauvage's avatar
Basile Sauvage committed
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
		for (Dart e = te.begin(); e != te.end(); e=te.next())
		{
			if ( !em.isMarked(e) && vmReached.isMarked(this->map.phi2(e)) )
			{ // opposite vertex is inside -> inside edge
				this->insideEdges.push_back(e);
				em.mark(e);
			}
		}

		// collect insideFaces and border
Pierre Kraemer's avatar
Pierre Kraemer committed
1264
		Traversor2VF<MAP> tf (this->map, *e_it);
Basile Sauvage's avatar
Basile Sauvage committed
1265
1266
1267
1268
1269
		for (Dart f = tf.begin(); f != tf.end(); f=tf.next())
		{
			if ( !fm.isMarked(f) )
			{
				fm.mark(f);
Pierre Kraemer's avatar
Pierre Kraemer committed
1270
				Traversor2FV<MAP> tv (this->map, f);
Basile Sauvage's avatar
Basile Sauvage committed
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
				Dart v = tv.begin();
				while ( v != tv.end() && vmReached.isMarked(v) ) {v=tv.next();}
				if ( v == tv.end() )
					this->insideFaces.push_back(f);
				else
					this->border.push_back(f);
			}
		}
	}
}

template <typename PFP>
1283
void Collector_Dijkstra<PFP>::collectBorder(Dart dinit)
Basile Sauvage's avatar
Basile Sauvage committed
1284
1285
1286
{
	init(dinit);

Pierre Kraemer's avatar
Pierre Kraemer committed
1287
	CellMarkerStore<MAP, VERTEX> vmReached (this->map, this->m_thread);
Basile Sauvage's avatar
Basile Sauvage committed
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
	vertexInfo[this->centerDart].it = front.insert(std::pair<float,Dart>(0.0, this->centerDart));
	vertexInfo[this->centerDart].valid = true;
	vmReached.mark(this->centerDart);

	while ( !front.empty() && front.begin()->first < this->maxDist)
	{
		Dart e = front.begin()->second;
		float d = front.begin()->first;
		front.erase(vertexInfo[e].it);
		vertexInfo[e].valid=false;
		this->insideVertices.push_back(e);

Pierre Kraemer's avatar
Pierre Kraemer committed
1300
		Traversor2VVaE<MAP> tv (this->map, e);
Basile Sauvage's avatar
Basile Sauvage committed
1301
1302
1303
1304
1305
1306
1307
		for (Dart f = tv.begin(); f != tv.end(); f=tv.next())
		{
			VertexInfo& vi (vertexInfo[f]);
			if (vmReached.isMarked(f))
			{
				if (vi.valid) // probably useless (because of distance test) but faster
				{
1308
					float dist = d + edgeLength(f);
Basile Sauvage's avatar
Basile Sauvage committed
1309
1310
1311
1312
1313
1314
1315
1316
1317
					if (dist < vi.it->first)
					{
						front.erase(vi.it);
						vi.it = front.insert(std::pair<float,Dart>(dist, f));
					}
				}
			}
			else
			{
1318
				vi.it = front.insert(std::pair<float,Dart>(d + edgeLength(f), f));
Pierre Kraemer's avatar
Pierre Kraemer committed
1319
				vi.valid = true;
Basile Sauvage's avatar
Basile Sauvage committed
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
				vmReached.mark(f);
			}
		}
	}

	while ( !front.empty())
	{
		vmReached.unmark(front.begin()->second);
		front.erase(front.begin());
	}

Pierre Kraemer's avatar