collector.hpp 33.8 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>
Sylvain Thery's avatar
Sylvain Thery committed
46
Collector<PFP>::Collector(MAP& m) : map(m), isInsideCollected(false)
Pierre Kraemer's avatar
Pierre Kraemer committed
47 48
{}

49
template <typename PFP>
50
template <typename FUNC>
51
inline void Collector<PFP>::applyOnInsideVertices(FUNC& func)
52
{
53
	assert(isInsideCollected || !"applyOnInsideVertices: inside cells have not been collected.") ;
54 55
	for (Vertex v : insideVertices)
		func(v.dart);
56 57
}

Pierre Kraemer's avatar
Pierre Kraemer committed
58
template <typename PFP>
59
template <typename FUNC>
60
inline void Collector<PFP>::applyOnInsideEdges(FUNC& func)
Pierre Kraemer's avatar
Pierre Kraemer committed
61
{
62
	assert(isInsideCollected || !"applyOnInsideEdges: inside cells have not been collected.") ;
63 64
	for (Edge e : insideEdges)
		func(e.dart);
Pierre Kraemer's avatar
Pierre Kraemer committed
65 66 67
}

template <typename PFP>
68
template <typename FUNC>
69
inline void Collector<PFP>::applyOnInsideFaces(FUNC& func)
Pierre Kraemer's avatar
Pierre Kraemer committed
70
{
71
	assert(isInsideCollected || !"applyOnInsideFaces: inside cells have not been collected.") ;
72 73
	for (Face f : insideFaces)
		func(f.dart);
Pierre Kraemer's avatar
Pierre Kraemer committed
74 75 76
}

template <typename PFP>
77
template <typename FUNC>
78
inline void Collector<PFP>::applyOnBorder(FUNC& func)
Pierre Kraemer's avatar
Pierre Kraemer committed
79
{
80 81
	for (Dart d : border)
		func(d);
Pierre Kraemer's avatar
Pierre Kraemer committed
82 83
}

Pierre Kraemer's avatar
Pierre Kraemer committed
84 85 86 87 88
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
89
    for (unsigned int i = 0; i< c.insideVertices.size(); ++i) out << c.insideVertices[i] << " ";
Pierre Kraemer's avatar
Pierre Kraemer committed
90 91
    out << "}" << std::endl ;
    out << "insideEdges (" << c.insideEdges.size() << ") = {";
Pierre Kraemer's avatar
Pierre Kraemer committed
92
    for (unsigned int i = 0; i< c.insideEdges.size(); ++i) out << c.insideEdges[i] << " ";
Pierre Kraemer's avatar
Pierre Kraemer committed
93 94
    out << "}" << std::endl ;
    out << "insideFaces (" << c.insideFaces.size() << ") = {";
Pierre Kraemer's avatar
Pierre Kraemer committed
95
    for (unsigned int i = 0; i< c.insideFaces.size(); ++i) out << c.insideFaces[i] << " ";
Pierre Kraemer's avatar
Pierre Kraemer committed
96 97
    out << "}" << std::endl ;
    out << "border (" << c.border.size() << ") = {";
Pierre Kraemer's avatar
Pierre Kraemer committed
98
    for (unsigned int i = 0; i< c.border.size(); ++i) out << c.border[i] << " ";
Pierre Kraemer's avatar
Pierre Kraemer committed
99 100 101 102 103 104 105 106 107
    out << "}" << std::endl;
    return out;
}

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

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

Pierre Kraemer's avatar
Pierre Kraemer committed
116
	this->insideVertices.push_back(d);
117

118
    foreach_incident2<EDGE>(this->map, Vertex(d), [&] (Edge e)
Pierre Kraemer's avatar
Pierre Kraemer committed
119
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
120 121 122 123
		this->insideEdges.push_back(e);
		this->insideFaces.push_back(e.dart);
		this->border.push_back(this->map.phi1(e.dart));
	});
Pierre Kraemer's avatar
Pierre Kraemer committed
124 125 126
}

template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
127
void Collector_OneRing<PFP>::collectBorder(Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
128
{
Pierre Kraemer's avatar
Pierre Kraemer committed
129 130 131
	this->init(d);
	this->border.reserve(12);

132
    foreach_incident2<FACE>(this->map, Vertex(d), [&] (Face f)
Pierre Kraemer's avatar
Pierre Kraemer committed
133 134 135
	{
		this->border.push_back(this->map.phi1(f.dart));
	});
Pierre Kraemer's avatar
Pierre Kraemer committed
136 137
}

138
template <typename PFP>
139
typename PFP::REAL Collector_OneRing<PFP>::computeArea(const VertexAttribute<VEC3, MAP>& pos)
140 141 142 143 144
{
	assert(this->isInsideCollected || !"computeArea: inside cells have not been collected.") ;

	REAL area = 0;

145 146
	for (Face f : this->insideFaces)
		area += Algo::Surface::Geometry::triangleArea<PFP>(this->map, f, pos);
147 148 149 150 151

	return area;
}

template <typename PFP>
152
typename PFP::REAL Collector_OneRing<PFP>::computeArea(const VertexAttribute<VEC3, MAP>& /*pos*/, const EdgeAttribute<REAL, MAP>& edgearea)
Pierre Kraemer's avatar
Pierre Kraemer committed
153
{
154
	assert(this->isInsideCollected || !"computeArea: inside cells have not been collected.") ;
155

156
	REAL area = 0;
157

158 159
	for (Edge e : this->insideEdges)
		area += edgearea[e];
160

161 162
	for (Dart d : this->border)
		area += edgearea[d];
163

164 165 166 167 168 169 170
	return area;
}

template <typename PFP>
typename PFP::REAL Collector_OneRing<PFP>::borderEdgeRatio(Dart /*d*/, const VertexAttribute<VEC3, MAP>& /*pos*/)
{
	return 1.0;
171 172
}

173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
/*********************************************************
 * 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);

Sylvain Thery's avatar
Sylvain Thery committed
192
	CellMarkerStore<MAP, FACE> fm(this->map);
193 194 195 196 197 198 199 200
	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
201
	foreach_adjacent2<VERTEX>(this->map, Edge(d), [&] (Edge e)
202
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
203 204 205 206 207
		this->insideEdges.push_back(e);
		this->insideFaces.push_back(e.dart);
		if (! fm.isMarked(e.dart))
			this->border.push_back(this->map.phi1(e.dart));
	});
208 209 210 211 212 213 214 215 216 217 218 219 220
}

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);

Sylvain Thery's avatar
Sylvain Thery committed
221
	CellMarkerStore<MAP, FACE> fm (this->map);
222 223 224
	fm.mark(d);
	fm.mark(d2);

Pierre Kraemer's avatar
Pierre Kraemer committed
225
	foreach_adjacent2<VERTEX>(this->map, Edge(d), [&] (Edge e)
226
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
227 228 229
		if (! fm.isMarked(e.dart))
			this->border.push_back(this->map.phi1(e.dart));
	});
230 231 232
}

template <typename PFP>
233
typename PFP::REAL Collector_OneRing_AroundEdge<PFP>::computeArea(const VertexAttribute<VEC3, MAP>& pos)
234 235 236 237 238
{
	assert(this->isInsideCollected || !"computeArea: inside cells have not been collected.") ;

	REAL area = 0;

239 240
	for (Face f : this->insideFaces)
		area += Algo::Surface::Geometry::triangleArea<PFP>(this->map, f, pos);
241 242 243 244 245

	return area;
}

template <typename PFP>
246
typename PFP::REAL Collector_OneRing_AroundEdge<PFP>::computeArea(const VertexAttribute<VEC3, MAP>& /*pos*/, const EdgeAttribute<REAL, MAP>& edgearea)
Pierre Kraemer's avatar
Pierre Kraemer committed
247
{
248
	assert(this->isInsideCollected || !"computeArea: inside cells have not been collected.") ;
249

250
	REAL area = 0;
251

252 253
	for (Edge e : this->insideEdges)
		area += edgearea[e];
254

255 256
	for (Dart d : this->border)
		area += edgearea[d];
257

258 259 260 261 262 263 264
	return area;
}

template <typename PFP>
typename PFP::REAL Collector_OneRing_AroundEdge<PFP>::borderEdgeRatio(Dart /*d*/, const VertexAttribute<VEC3, MAP>& /*pos*/)
{
	return 1.0;
265 266
}

Pierre Kraemer's avatar
Pierre Kraemer committed
267 268 269 270
/*********************************************************
 * Collector Within Sphere
 *********************************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
271
template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
272
void Collector_WithinSphere<PFP>::collectAll(Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
273
{
Pierre Kraemer's avatar
Pierre Kraemer committed
274
	this->init(d);
275
	this->isInsideCollected = true;
276 277 278
	this->insideEdges.reserve(32);
	this->insideFaces.reserve(32);
	this->border.reserve(32);
Pierre Kraemer's avatar
Pierre Kraemer committed
279

Sylvain Thery's avatar
Sylvain Thery committed
280 281 282
	CellMarkerStore<MAP, VERTEX> vm(this->map);	// mark the collected inside-vertices
	CellMarkerStore<MAP, EDGE> em(this->map);	// mark the collected inside-edges + border-edges
	CellMarkerStore<MAP, FACE> fm(this->map);	// mark the collected inside-faces + border-faces
Pierre Kraemer's avatar
Pierre Kraemer committed
283

Pierre Kraemer's avatar
Pierre Kraemer committed
284 285
	this->insideVertices.push_back(d);
	vm.mark(d);
Pierre Kraemer's avatar
Pierre Kraemer committed
286

Pierre Kraemer's avatar
Pierre Kraemer committed
287
	VEC3 centerPosition = this->position[d];
Pierre Kraemer's avatar
Pierre Kraemer committed
288 289 290 291 292 293 294 295 296 297 298 299
	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);

300
				if (! Geom::isPointInSphere(this->position[f], centerPosition, this->radius))
Pierre Kraemer's avatar
Pierre Kraemer committed
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
				{
					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);
					}
318
					if (! fm.isMarked(e) && Geom::isPointInSphere(this->position[g], centerPosition, this->radius))
Pierre Kraemer's avatar
Pierre Kraemer committed
319 320 321 322 323 324
					{
						this->insideFaces.push_back(e);
						fm.mark(e);
					}
				}
			}
325
			e = this->map.phi2_1(e);
Pierre Kraemer's avatar
Pierre Kraemer committed
326 327 328 329 330
		} while (e != end);
		++i;
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
331 332 333 334
template <typename PFP>
void Collector_WithinSphere<PFP>::collectBorder(Dart d)
{
	this->init(d);
335 336
	this->border.reserve(128);
	this->insideVertices.reserve(128);
Pierre Kraemer's avatar
Pierre Kraemer committed
337

Sylvain Thery's avatar
Sylvain Thery committed
338 339
	CellMarkerStore<MAP, VERTEX> vm(this->map);	// mark the collected inside-vertices
	CellMarkerStore<MAP, EDGE> em(this->map);	// mark the collected inside-edges + border-edges
340

Pierre Kraemer's avatar
Pierre Kraemer committed
341 342
	this->insideVertices.push_back(d);
	vm.mark(d);
Pierre Kraemer's avatar
Pierre Kraemer committed
343 344 345 346 347 348 349 350 351

	VEC3 centerPosition = this->position[d];
	unsigned int i = 0;
	while (i < this->insideVertices.size())
	{
		Dart end = this->insideVertices[i];
		Dart e = end;
		do
		{
352
			if ( ! em.isMarked(e) )
Pierre Kraemer's avatar
Pierre Kraemer committed
353 354 355 356 357 358 359
			{
				const Dart f = this->map.phi1(e);

				if (! Geom::isPointInSphere(this->position[f], centerPosition, this->radius))
				{
					this->border.push_back(e); // add to border
				}
360 361 362 363 364 365 366 367 368
				else
				{
					if (! vm.isMarked(f))
					{
						this->insideVertices.push_back(f);
						vm.mark(f);
					}
				}
				em.mark(e);
Pierre Kraemer's avatar
Pierre Kraemer committed
369
			}
370
			e = this->map.phi2_1(e);
Pierre Kraemer's avatar
Pierre Kraemer committed
371 372 373
		} while (e != end);
		++i;
	}
374
	this->insideVertices.clear();
Pierre Kraemer's avatar
Pierre Kraemer committed
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
template <typename PFP>
typename PFP::REAL Collector_WithinSphere<PFP>::computeArea(const VertexAttribute<VEC3, MAP>& pos)
{
	assert(this->isInsideCollected || !"computeArea: inside cells have not been collected.") ;

	const VEC3& centerPosition = pos[this->centerDart];
	REAL area = 0;

	for (Face f : this->insideFaces)
		area += Algo::Surface::Geometry::triangleArea<PFP>(this->map, f, pos);

	for (Dart d : this->border)
	{
		const Dart f = this->map.phi1(d); // we know that f is outside
		const Dart g = this->map.phi1(f);
		if (Geom::isPointInSphere(pos[g], centerPosition, this->radius))
		{ // only f is outside
			REAL alpha, beta;
			Geometry::intersectionSphereEdge<PFP>(this->map, centerPosition, this->radius, d, pos, alpha);
			Geometry::intersectionSphereEdge<PFP>(this->map, centerPosition, this->radius, this->map.phi2(f), pos, beta);
			area += (alpha+beta - alpha*beta) * Algo::Surface::Geometry::triangleArea<PFP>(this->map, d, pos);
		}
		else
		{ // f and g are outside
			REAL alpha, beta;
			Geometry::intersectionSphereEdge<PFP>(this->map, centerPosition, this->radius, d, pos, alpha);
			Geometry::intersectionSphereEdge<PFP>(this->map, centerPosition, this->radius, this->map.phi2(g), pos, beta);
			area += alpha * beta * Algo::Surface::Geometry::triangleArea<PFP>(this->map, d, pos);
		}
	}

	return area;
}
410

Pierre Kraemer's avatar
Pierre Kraemer committed
411
template <typename PFP>
412
typename PFP::REAL Collector_WithinSphere<PFP>::computeArea(const VertexAttribute<VEC3, MAP>& pos, const EdgeAttribute<REAL, MAP>& edgearea)
Pierre Kraemer's avatar
Pierre Kraemer committed
413
{
414
	assert(this->isInsideCollected || !"computeArea: inside cells have not been collected.") ;
415

416
	const VEC3& centerPosition = pos[this->centerDart];
417
	REAL area = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
418

419 420
	for (Edge e : this->insideEdges)
		area += edgearea[e];
Pierre Kraemer's avatar
Pierre Kraemer committed
421

422
	for (Dart d : this->border)
Pierre Kraemer's avatar
Pierre Kraemer committed
423
	{
424 425 426
		REAL alpha;
		Geometry::intersectionSphereEdge<PFP>(this->map, centerPosition, this->radius, d, pos, alpha);
		area += alpha * edgearea[d];
Pierre Kraemer's avatar
Pierre Kraemer committed
427
	}
428

429 430 431 432
	return area;
}

template <typename PFP>
433
typename PFP::REAL Collector_WithinSphere<PFP>::borderEdgeRatio(Dart d, const VertexAttribute<VEC3, MAP>& pos)
Pierre Kraemer's avatar
Pierre Kraemer committed
434
{
435 436 437 438
	const VEC3& centerPosition = pos[this->centerDart];
	REAL alpha;
	Algo::Surface::Geometry::intersectionSphereEdge<PFP>(this->map, centerPosition, radius, d, pos, alpha) ;
	return alpha;
439 440
}

441
/*********************************************************
442
 * Collector Normal Angle (Vertices)
443 444 445 446 447 448
 *********************************************************/

template <typename PFP>
void Collector_NormalAngle<PFP>::collectAll(Dart d)
{
	this->init(d);
449
	this->isInsideCollected = true;
450 451 452 453
	this->insideEdges.reserve(32);
	this->insideFaces.reserve(32);
	this->border.reserve(32);

Sylvain Thery's avatar
Sylvain Thery committed
454 455 456
	CellMarkerStore<MAP, VERTEX> vm(this->map);	// mark the collected inside-vertices
	CellMarkerStore<MAP, EDGE> em(this->map);	// mark the collected inside-edges + border-edges
	CellMarkerStore<MAP, FACE> fm(this->map);	// mark the collected inside-faces + border-faces
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 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 510 511 512 513 514 515

	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);

Sylvain Thery's avatar
Sylvain Thery committed
516 517
	CellMarkerStore<MAP, VERTEX> vm(this->map);	// mark the collected inside-vertices
	CellMarkerStore<MAP, EDGE> em(this->map);	// mark the collected inside-edges + border-edges
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550

	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
551 552 553 554 555 556
		} while (e != end);
		++i;
	}
	this->insideVertices.clear();
}

557 558 559 560 561 562 563 564
/*********************************************************
 * Collector Normal Angle (Triangles)
 *********************************************************/

template <typename PFP>
void Collector_NormalAngle_Triangles<PFP>::collectAll(Dart d)
{
	this->init(d);
565
	this->isInsideCollected = true;
Basile Sauvage's avatar
Basile Sauvage committed
566
	this->insideVertices.reserve(32);
567 568 569 570
	this->insideEdges.reserve(32);
	this->insideFaces.reserve(32);
	this->border.reserve(32);

Sylvain Thery's avatar
Sylvain Thery committed
571 572
	CellMarkerStore<MAP, FACE> fm(this->map);	// mark the collected inside-faces + front-faces
	CellMarkerStore<MAP, FACE> fminside(this->map);	// mark the collected inside-faces
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589

	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
590
			Traversor2FFaE<MAP> t (this->map, f) ;
591 592 593 594 595 596 597 598 599 600 601
			for (Dart it = t.begin(); it != t.end(); it=t.next())
			{
				if (!fm.isMarked(it))
				{
					front.push(it);
					fm.mark(it);
				}
			}
		}
	}

Sylvain Thery's avatar
Sylvain Thery committed
602 603
	CellMarkerStore<MAP, VERTEX> vm(this->map);	// mark inside-vertices and border-vertices
	CellMarkerStore<MAP, EDGE> em(this->map);	// mark inside-edges and border-edges
604 605 606
	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
607
		Traversor2FE<MAP> te (this->map, *f_it) ;
608 609 610 611 612 613 614 615 616 617 618 619 620 621
		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
622
		Traversor2FV<MAP> tv (this->map, *f_it) ;
623 624 625 626 627
		for (Dart it = tv.begin(); it != tv.end(); it=tv.next())
		{ // collect insideVertices
			if (!vm.isMarked(it))
			{
				vm.mark(it);
628 629 630 631 632 633 634 635 636 637
				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);
//				}
638 639 640 641 642 643 644 645 646 647 648 649 650
			}
		}
	}

}

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

Sylvain Thery's avatar
Sylvain Thery committed
651 652
	CellMarkerStore<MAP, FACE> fm(this->map);	// mark the collected inside-faces + front-faces
	CellMarkerStore<MAP, FACE> fminside(this->map);	// mark the collected inside-faces
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668

	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
669
			Traversor2FFaE<MAP> t (this->map, f) ;
670 671 672 673 674 675 676 677 678 679 680
			for (Dart it = t.begin(); it != t.end(); it=t.next())
			{
				if (!fm.isMarked(it))
				{
					front.push(it);
					fm.mark(it);
				}
			}
		}
	}

Sylvain Thery's avatar
Sylvain Thery committed
681
	CellMarkerStore<MAP, EDGE> em(this->map);	// mark inside-edges and border-edges
682 683 684
	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
685
		Traversor2FE<MAP> te (this->map, *f_it) ;
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700
		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();
}

701 702 703 704 705 706 707 708 709 710 711 712 713 714
/*********************************************************
 * 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);

Sylvain Thery's avatar
Sylvain Thery committed
715 716 717
	CellMarkerStore<MAP, VERTEX> vm(this->map);	// mark the collected inside-vertices
	CellMarkerStore<MAP, EDGE> em(this->map);	// mark the collected inside-edges + border-edges
	CellMarkerStore<MAP, FACE> fm(this->map);	// mark the collected inside-faces + border-faces
718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772

	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);

Sylvain Thery's avatar
Sylvain Thery committed
773 774
	CellMarkerStore<MAP, VERTEX> vm(this->map);	// mark the collected inside-vertices
	CellMarkerStore<MAP, EDGE> em(this->map);	// mark the collected inside-edges + border-edges
775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810

	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
811 812 813 814 815 816 817 818 819
/*********************************************************
 * Collector Triangles
 *********************************************************/

template <typename PFP>
void Collector_Triangles<PFP>::collectAll(Dart d)
{
	crit.init(d);
	this->init(d);
820
	this->isInsideCollected = true;
Basile Sauvage's avatar
Basile Sauvage committed
821 822 823 824 825
	this->insideVertices.reserve(32);
	this->insideEdges.reserve(32);
	this->insideFaces.reserve(32);
	this->border.reserve(32);

Sylvain Thery's avatar
Sylvain Thery committed
826 827
	CellMarkerStore<MAP, FACE> fm(this->map);	// mark the collected inside-faces + front-faces
	CellMarkerStore<MAP, FACE> fminside(this->map);	// mark the collected inside-faces
Basile Sauvage's avatar
Basile Sauvage committed
828 829 830 831 832 833 834 835 836 837 838 839 840 841

	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
842
			Traversor2FFaE<MAP> t (this->map, f) ;
Basile Sauvage's avatar
Basile Sauvage committed
843 844 845 846 847 848 849 850 851 852
			for (Dart it = t.begin(); it != t.end(); it=t.next())
			{
				if (!fm.isMarked(it))
				{
					front.push(it);
					fm.mark(it);
				}
			}
		}
	}
Sylvain Thery's avatar
Sylvain Thery committed
853 854
	CellMarkerStore<MAP, VERTEX> vm(this->map);	// mark inside-vertices and border-vertices
	CellMarkerStore<MAP, EDGE> em(this->map);	// mark inside-edges and border-edges
855
	std::vector<Face>::iterator f_it;
Basile Sauvage's avatar
Basile Sauvage committed
856 857
	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
858
		Traversor2FE<MAP> te (this->map, *f_it) ;
Basile Sauvage's avatar
Basile Sauvage committed
859 860 861 862 863 864 865 866 867 868 869 870 871 872
		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
873
		Traversor2FV<MAP> tv (this->map, *f_it) ;
Basile Sauvage's avatar
Basile Sauvage committed
874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892
		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);

Sylvain Thery's avatar
Sylvain Thery committed
893 894
	CellMarkerStore<MAP, FACE> fm(this->map);	// mark the collected inside-faces + front-faces
	CellMarkerStore<MAP, FACE> fminside(this->map);	// mark the collected inside-faces
Basile Sauvage's avatar
Basile Sauvage committed
895 896 897 898 899 900 901 902 903 904 905 906 907 908

	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
909
			Traversor2FFaE<MAP> t (this->map, f) ;
Basile Sauvage's avatar
Basile Sauvage committed
910 911 912 913 914 915 916 917 918 919
			for (Dart it = t.begin(); it != t.end(); it=t.next())
			{
				if (!fm.isMarked(it))
				{
					front.push(it);
					fm.mark(it);
				}
			}
		}
	}
Sylvain Thery's avatar
Sylvain Thery committed
920
	CellMarkerStore<MAP, EDGE> em(this->map);	// mark inside-edges and border-edges
Sauvage's avatar
Sauvage committed
921
	std::vector<Face>::iterator f_it;
Basile Sauvage's avatar
Basile Sauvage committed
922 923
	for (f_it = this->insideFaces.begin(); f_it != this->insideFaces.end(); f_it++)
	{ // collect border (edges)
Pierre Kraemer's avatar
Pierre Kraemer committed
924
		Traversor2FE<MAP> te (this->map, *f_it) ;
Basile Sauvage's avatar
Basile Sauvage committed
925 926 927 928 929 930 931 932 933 934 935 936 937 938 939
		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
940
/*********************************************************
941
 * Collector Dijkstra_Vertices
Basile Sauvage's avatar
Basile Sauvage committed
942 943 944
 *********************************************************/

template <typename PFP>
945
void Collector_Dijkstra_Vertices<PFP>::collectAll(Dart dinit)
946
{
Basile Sauvage's avatar
Basile Sauvage committed
947
	init(dinit);
948
	this->isInsideCollected = true;
Basile Sauvage's avatar
Basile Sauvage committed
949

Sylvain Thery's avatar
Sylvain Thery committed
950
	CellMarkerStore<MAP, VERTEX> vmReached (this->map);
Basile Sauvage's avatar
Basile Sauvage committed
951 952 953 954 955 956 957 958 959 960 961 962
	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
963
		Traversor2VVaE<MAP> tv (this->map, e);
Basile Sauvage's avatar
Basile Sauvage committed
964 965 966 967 968
		for (Dart f = tv.begin(); f != tv.end(); f=tv.next())
		{
			VertexInfo& vi (vertexInfo[f]);
			if (vmReached.isMarked(f))
			{
969
				if (vi.valid) // probably useless (because of distance test) but faster
Basile Sauvage's avatar
Basile Sauvage committed
970
				{
971
					float dist = d + edge_cost[f];
Basile Sauvage's avatar
Basile Sauvage committed
972 973 974 975 976 977 978 979 980
					if (dist < vi.it->first)
					{
						front.erase(vi.it);
						vi.it = front.insert(std::pair<float,Dart>(dist, f));
					}
				}
			}
			else
			{
981
				vi.it = front.insert(std::pair<float,Dart>(d + edge_cost[f], f));
Basile Sauvage's avatar
Basile Sauvage committed
982 983 984 985 986 987 988 989
				vi.valid=true;
				vmReached.mark(f);
			}

		}

	}

990 991 992 993 994 995
	while ( !front.empty())
	{
		vmReached.unmark(front.begin()->second);
		front.erase(front.begin());
	}

Sylvain Thery's avatar
Sylvain Thery committed
996 997
	CellMarkerStore<MAP, EDGE> em (this->map);
	CellMarkerStore<MAP, FACE> fm (this->map);
998
	for (std::vector<Vertex>::iterator e_it = this->insideVertices.begin(); e_it != this->insideVertices.end() ; e_it++)
999 1000
	{
		// collect insideEdges
Pierre Kraemer's avatar
Pierre Kraemer committed
1001
		Traversor2VE<MAP> te (this->map, *e_it);
1002 1003 1004 1005 1006 1007 1008 1009 1010 1011
		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
1012
		Traversor2VF<MAP> tf (this->map, *e_it);
1013 1014 1015 1016 1017
		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
1018
				Traversor2FV<MAP> tv (this->map, f);
1019 1020 1021 1022 1023 1024 1025 1026 1027
				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
1028 1029 1030
}

template <typename PFP>
1031
void Collector_Dijkstra_Vertices<PFP>::collectBorder(Dart dinit)
1032
{
1033
	init(dinit);
Basile Sauvage's avatar
Basile Sauvage committed
1034

Sylvain Thery's avatar
Sylvain Thery committed
1035
	CellMarkerStore<MAP, VERTEX> vmReached (this->map);
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047
	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
1048
		Traversor2VVaE<MAP> tv (this->map, e);
1049 1050 1051 1052 1053 1054 1055
		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
				{
1056
					float dist = d + edge_cost[f];
1057 1058 1059 1060 1061 1062 1063 1064 1065
					if (dist < vi.it->first)
					{
						front.erase(vi.it);
						vi.it = front.insert(std::pair<float,Dart>(dist, f));
					}
				}
			}
			else
			{
1066
				vi.it = front.insert(std::pair<float,Dart>(d + edge_cost[f], f));
Pierre Kraemer's avatar
Pierre Kraemer committed
1067
				vi.valid = true;
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077
				vmReached.mark(f);
			}
		}
	}

	while ( !front.empty())
	{
		vmReached.unmark(front.begin()->second);
		front.erase(front.begin());
	}
Sylvain Thery's avatar
Sylvain Thery committed
1078
	CellMarkerStore<MAP, FACE> fm (this->map);
Sauvage's avatar
Sauvage committed
1079
	for (std::vector<Vertex>::iterator e_it = this->insideVertices.begin(); e_it != this->insideVertices.end() ; e_it++)
1080 1081
	{
		// collect border
Pierre Kraemer's avatar
Pierre Kraemer committed
1082
		Traversor2VF<MAP> tf (this->map, *e_it);
1083 1084 1085 1086 1087
		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
1088
				Traversor2FV<MAP> tv (this->map, f);
1089 1090 1091 1092 1093 1094 1095 1096
				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
1097 1098
}

Basile Sauvage's avatar
Basile Sauvage committed
1099
/*********************************************************
1100
 * Collector Dijkstra
Basile Sauvage's avatar
Basile Sauvage committed
1101 1102 1103
 *********************************************************/

template <typename PFP>
1104
void Collector_Dijkstra<PFP>::collectAll(Dart dinit)
Basile Sauvage's avatar
Basile Sauvage committed
1105 1106
{
	init(dinit);
1107
	this->isInsideCollected = true;
Basile Sauvage's avatar
Basile Sauvage committed
1108

Sylvain Thery's avatar
Sylvain Thery committed
1109
	CellMarkerStore<MAP, VERTEX> vmReached (this->map);
Basile Sauvage's avatar
Basile Sauvage committed
1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121
	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
1122
		Traversor2VVaE<MAP> tv (this->map, e);
Basile Sauvage's avatar
Basile Sauvage committed
1123 1124 1125 1126 1127 1128 1129
		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
				{
1130
					float dist = d + edgeLength(f);
Basile Sauvage's avatar
Basile Sauvage committed
1131 1132 1133 1134 1135 1136 1137 1138 1139
					if (dist < vi.it->first)
					{
						front.erase(vi.it);
						vi.it = front.insert(std::pair<float,Dart>(dist, f));
					}
				}
			}
			else
			{
1140
				vi.it = front.insert(std::pair<float,Dart>(d + edgeLength(f), f));
Pierre Kraemer's avatar
Pierre Kraemer committed
1141
				vi.valid = true;
Basile Sauvage's avatar
Basile Sauvage committed
1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152
				vmReached.mark(f);
			}
		}
	}

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

Sylvain Thery's avatar
Sylvain Thery committed
1153 1154
	CellMarkerStore<MAP, EDGE> em (this->map);
	CellMarkerStore<MAP, FACE> fm (this->map);
Basile Sauvage's avatar
Basile Sauvage committed
1155 1156 1157
	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
1158
		Traversor2VE<MAP> te (this->map, *e_it);
Basile Sauvage's avatar
Basile Sauvage committed
1159 1160 1161 1162 1163 1164 1165 1166 1167 1168
		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
1169
		Traversor2VF<MAP> tf (this->map, *e_it);
Basile Sauvage's avatar
Basile Sauvage committed
1170 1171 1172 1173 1174
		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
1175
				Traversor2FV<MAP> tv (this->map, f);
Basile Sauvage's avatar
Basile Sauvage committed
1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187
				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>
1188
void Collector_Dijkstra<PFP>::collectBorder(Dart dinit)
Basile Sauvage's avatar
Basile Sauvage committed
1189 1190 1191
{
	init(dinit);

Sylvain Thery's avatar
Sylvain Thery committed
1192
	CellMarkerStore<MAP, VERTEX> vmReached (this->map);
Basile Sauvage's avatar
Basile Sauvage committed
1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204
	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
1205
		Traversor2VVaE<MAP> tv (this->map, e);
Basile Sauvage's avatar
Basile Sauvage committed
1206 1207 1208 1209 1210 1211 1212
		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