26 #include "g-map-vertex.hh"
27 #include "geometry.hh"
30 using namespace GMap3d;
38 FCoefs[0] = FMap->getNewDirectInfo();
39 FCoefs[1] = FMap->getNewDirectInfo();
44 FMap->freeDirectInfo(FCoefs[0]);
45 FMap->freeDirectInfo(FCoefs[1]);
48 #define GET_KV(DART) ((FMap->isMarked((DART), AMarkNumber)) \
49 ? getDartRoundingCoef((DART), 0) \
56 int directIndex = FMap->getNewDirectInfo();
58 int treated = FMap->getNewMark();
59 int original = FMap->getNewMark();
60 int newdarts = FMap->getNewMark(); FMap->negateMaskMark(newdarts);
62 CDynamicCoverageAll it(FMap);
65 FMap->negateMaskMark(original);
70 FMap->pointDirectInfoToAttributeVertex(directIndex);
73 for (; it.cont(); ++it)
74 if (!FMap->isMarked(*it, treated))
76 if (FMap->isMarked(*it, AMarkNumber))
78 FMap->markOrbit(*it, ORBIT_VERTEX, treated);
83 CAttributeVertex* oldVertex = FMap->removeVertex(*it);
85 CStaticCoverageVertex cov(FMap, *it);
98 else if (roundingDim==3)
106 if (!ADig && closureLevel==3)
110 for (CDynamicCoverageVolume cov(FMap, FMap->alpha123(*it));
111 !stop && cov.cont(); ++cov)
112 if (FMap->isFree2(*cov))
114 FMap->stopUp(*cov, 2);
120 for ( ; cov.cont(); ++cov)
122 if (!FMap->isMarked(FMap->alpha1(*cov), treated))
124 CDart* d0 = FMap->alpha0(*cov);
126 CAttributeVertex* vertex0;
128 if (FMap->isMarked(d0, original))
130 FMap->getDirectInfoAsAttributeVertex(d0, directIndex);
133 vertex0 = FMap->findVertex(d0);
136 TCoordinate u =
GET_KV(*cov);
137 FMap->setVertex(*cov, (1-u) * *oldVertex + u * *vertex0);
140 FMap->markOrbit(*cov, ORBIT_VERTEX, treated);
149 FMap->setMark(*it, treated);
153 for (it.reinit(); it.cont(); ++it)
154 if (!FMap->isMarked(*it, treated))
156 delete FMap->getDirectInfoAsAttributeVertex(*it, directIndex);
157 FMap->setMark(*it, treated);
161 FMap->negateMaskMark(treated);
162 FMap->freeMark(treated);
164 FMap->unmarkAll(original);
165 FMap->freeMark(original);
167 FMap->freeDirectInfo(directIndex);
169 FMap->negateMaskMark(newdarts);
170 FMap->markIncidentCells(ORBIT_EDGE , newdarts);
171 FMap->markIncidentCells(ORBIT_VERTEX, newdarts);
173 FMap->deleteMarkedNullLengthEdges(newdarts);
174 FMap->deleteMarkedFlatFaces (newdarts);
175 FMap->deleteMarkedFlatVolumes (newdarts);
177 FMap->unmarkAll(newdarts);
178 FMap->freeMark(newdarts);
186 bool A3D,
bool ADig,
bool ASetback)
188 assert(!ADig || A3D);
192 int selected = FMap->getNewMark();
193 int treated = FMap->getNewMark();
194 int initial = FMap->getNewMark();
195 int newdarts = FMap->getNewMark(); FMap->negateMaskMark(newdarts);
197 int vertexToDestroy = FMap->getNewMark();
199 int directOldVertex = FMap->getNewDirectInfo();
200 int directNewVertex = FMap->getNewDirectInfo();
202 CDynamicCoverageAll it(FMap);
207 FMap->pointDirectInfoToAttributeVertex(directOldVertex);
213 vertexToDestroy, &it);
222 int max = FMap->getNewMark();
224 doMinMaxCalcul(FCoefs[1], selected, treated, initial, max, A3D, &it);
235 directNewVertex, ASetback, A3D, &it);
242 for (it.reinit(); it.cont(); ++it)
243 if (!FMap->isMarked(*it, treated))
245 if (FMap->isMarked(*it, selected))
247 CDart* d101 = FMap->alpha101(*it);
249 FMap->setMark(FMap->alpha3(*it ), treated);
250 FMap->setMark( d101 , treated);
251 FMap->setMark(FMap->alpha3(d101), treated);
253 if ((*it!=d101) && FMap->isMarked(*it, max) &&
254 FMap->isMarked(d101, max) &&
255 !FMap->isMarked(FMap->alpha1(*it), selected))
262 FMap->setMark(*it, treated);
265 FMap->negateMaskMark(treated);
268 for (it.reinit(); it.cont(); ++it)
269 if (!FMap->isMarked(*it, treated))
271 if (FMap->isMarked(*it, selected))
273 assert(FMap->findVertex(*it) == NULL);
276 CAttributeVertex* vertex =
277 FMap->getDirectInfoAsAttributeVertex(*it, directNewVertex);
278 FMap->setVertex(*it, vertex);
280 FMap->unsetMark(*it, selected);
285 for (CDynamicCoverageVertex cov(FMap, *it); cov.cont(); ++cov)
286 if (FMap->isMarked(*cov, selected))
288 FMap->unsetMark(*it, selected);
289 delete FMap->getDirectInfoAsAttributeVertex(*cov,
293 FMap->markOrbit(*it, ORBIT_VERTEX, treated);
296 FMap->setMark(*it, treated);
299 FMap->negateMaskMark(treated);
302 for (it.reinit(); it.cont(); ++it)
303 if (FMap->isMarked(*it, vertexToDestroy))
305 delete FMap->getDirectInfoAsAttributeVertex(*it, directOldVertex);
306 FMap->unsetMark(*it, vertexToDestroy);
310 FMap->unmarkAll(max);
313 FMap->unmarkAll(initial);
314 FMap->freeMark(initial);
316 FMap->unmarkAll(selected);
317 FMap->freeMark(selected);
319 FMap->freeMark(treated);
321 FMap->freeMark(vertexToDestroy);
322 FMap->freeDirectInfo(directOldVertex);
323 FMap->freeDirectInfo(directNewVertex);
325 FMap->negateMaskMark(newdarts);
326 FMap->markIncidentCells(ORBIT_EDGE , newdarts);
327 FMap->markIncidentCells(ORBIT_VERTEX, newdarts);
329 FMap->deleteMarkedNullLengthEdges(newdarts);
330 FMap->deleteMarkedFlatFaces (newdarts);
331 FMap->deleteMarkedFlatVolumes (newdarts);
333 FMap->unmarkAll(newdarts);
334 FMap->freeMark(newdarts);
340 int AMarkSelected,
int AMarkTreated,
341 int AMarkVertexToDestroy, CCoverage* ACov)
343 FMap->markIncidentCells(ORBIT_EDGE, AMarkNumber, AMarkInitial );
344 FMap->markIncidentCells(ORBIT_EDGE, AMarkNumber, AMarkSelected);
346 for ( ; ACov->cont(); ++(*ACov))
347 if (!FMap->isMarked(**ACov, AMarkTreated))
349 if (FMap->isMarked(**ACov, AMarkSelected))
351 for (CDynamicCoverageVertex cov(FMap, **ACov); cov.cont(); ++cov)
353 if (FMap->getVertex(*cov) != NULL)
355 FMap->removeVertex(*cov);
356 FMap->setMark(*cov, AMarkVertexToDestroy);
359 FMap->setMark(*cov, AMarkSelected);
360 FMap->setMark(*cov, AMarkTreated );
364 FMap->setMark(**ACov, AMarkTreated);
367 FMap->negateMaskMark(AMarkTreated);
370 #define GET_KE(DART) ((FMap->isMarked((DART), AMarkInitial)) \
371 ? (getDartRoundingCoef((DART), 1)) \
375 int AMarkSelected,
int AMarkTreated,
376 int AMarkInitial,
int AMarkMax,
377 bool A3D, CCoverage* ACov)
381 for (ACov->reinit(); ACov->cont(); ++(*ACov))
382 if (!FMap->isMarked(**ACov, AMarkTreated))
384 if (FMap->isMarked(**ACov, AMarkSelected))
386 CDartVertex* d = (CDartVertex*) **ACov ;
387 CDartVertex* d121 = (CDartVertex*) FMap->alpha121(**ACov);
393 TCoordinate val =
GET_KE(d );
394 TCoordinate val121 =
GET_KE(d121);
396 if (isPositive(val-val121)) FMap->setMark(d , AMarkMax);
397 if (isPositive(val121-val)) FMap->setMark(d121, AMarkMax);
399 FMap->setMark(d121, AMarkTreated);
402 FMap->setMark(**ACov, AMarkTreated);
409 for (ACov->reinit(); ACov->cont(); ++(*ACov))
410 if (!FMap->isMarked(**ACov, AMarkTreated))
412 if (FMap->isMarked(**ACov, AMarkSelected))
417 for (CDynamicCoverage23 cov1(FMap, FMap->alpha1(**ACov));
420 TCoordinate cVal =
GET_KE(FMap->alpha1(*cov1));
422 if (isPositive(cVal-maxVal))
427 for (CDynamicCoverage23 cov2(FMap, FMap->alpha1(**ACov));
430 if (isPositive(
GET_KE(FMap->alpha1(*cov2)) - maxVal))
431 FMap->setMark(FMap->alpha1(*cov2), AMarkMax);
433 FMap->setMark(FMap->alpha1(*cov2), AMarkTreated);
437 FMap->setMark(**ACov, AMarkTreated);
441 FMap->negateMaskMark(AMarkTreated);
446 #define GET_KV(DART) (getDartRoundingCoef((DART), 0))
447 #define GET_KE(DART) ((FMap->isMarked(DART, AMarkInitial)) \
448 ? (getDartRoundingCoef((DART), 1)) \
453 int AMarkInitial,
int AMarkMax,
454 int ADirectIndexOld,
int ADirectIndexNew,
455 bool ASetback,
bool A3D, CCoverage* ACov)
457 for (ACov->reinit(); ACov->cont(); ++(*ACov))
458 if (!FMap->isMarked(**ACov,AMarkTreated))
460 if (FMap->isMarked(**ACov, AMarkSelected))
462 CDartVertex* d = (CDartVertex*) **ACov ;
463 CDartVertex* d0 = (CDartVertex*) FMap->alpha0 (d );
464 CDartVertex* d1 = (CDartVertex*) FMap->alpha1 (d );
465 CDartVertex* d10 = (CDartVertex*) FMap->alpha10(d );
466 CDartVertex* d010 = (CDartVertex*) FMap->alpha10(d0 );
467 CDartVertex* d1010 = (CDartVertex*) FMap->alpha10(d10);
469 #define GET_V(DART) (* FMap-> \
470 getDirectInfoAsAttributeVertex((DART), ADirectIndexOld))
471 CAttributeVertex& V1 =
GET_V(d );
472 CAttributeVertex& V2 =
GET_V(d10 );
473 CAttributeVertex& V3 =
GET_V(d0 );
474 CAttributeVertex& V4 =
GET_V(d1010);
475 CAttributeVertex& V5 =
GET_V(d010 );
479 TCoordinate u =
GET_KE(d );
480 TCoordinate u0 =
GET_KE(d0 );
481 TCoordinate u10 =
GET_KE(d10);
482 TCoordinate u1 =
GET_KE(d1 );
485 TCoordinate usb =
GET_KV(d);
487 CVertex V6 = (1-u )*V1 + u *V2;
488 CVertex V7 = (1-u0)*V3 + u0*V5;
492 if (FMap->isMarked(d1, AMarkMax))
494 if (ASetback && isPositive(usb-u1) && !areEqual(usb,u1))
500 FMap->unsetMark(d1, AMarkMax);
502 V8 = (1-usb )*V1 + usb*V3;
503 V9 = (1-(u10+usb-u1))*V2 + (u10+usb-u1)*V4;
507 V8 = (1-u1 )*V1 + u1 *V3;
508 V9 = (1-u10)*V2 + u10*V4;
517 CDynamicCoverage23 cov2(FMap, d);
519 while (cov2.cont() &&
520 ! FMap->isMarked(FMap->alpha1(*cov2), AMarkMax))
523 u2 =
GET_KE(FMap->alpha1(*cov2));
527 u2 =
GET_KE(FMap->alpha21(d));
530 TCoordinate ui = u10 + u2 - u1;
532 if (ASetback && isPositive(usb-u2) && !areEqual(usb,u2))
535 V8 = (1-usb)*V1 + usb*V3;
536 V9 = (1-(u10+usb-u2))*V2 + (u10+usb-u2)*V4;
540 V8 = (1-u2)*V1 + u2*V3;
541 V9 = (1-ui)*V2 + ui*V4;
545 CVertex newVertex = CGeometry::getLinesIntersection(V6,V7, V8,V9);
547 FMap->setDirectInfo(d, ADirectIndexNew,
548 new CAttributeVertex(newVertex));
550 if (FMap->isMarked(d1, AMarkMax) && FMap->isMarked(d,AMarkMax))
552 FMap->setDirectInfo(d1, ADirectIndexNew,
553 new CAttributeVertex(newVertex));
558 FMap->setMark(**ACov,AMarkTreated);
561 FMap->negateMaskMark(AMarkTreated);
570 bool ADig,
bool A3D, CCoverage* ACov)
576 for (ACov->reinit(); ACov->cont(); ++(*ACov))
577 if (! FMap->isMarked(**ACov, AMarkTreated))
579 if (FMap->isMarked(**ACov, AMarkInitial))
581 CDartVertex* d = (CDartVertex*) **ACov;
584 FMap->markOrbit(**ACov, ORBIT_EDGE, AMarkTreated);
586 FMap->negateMaskMark(AMarkTreated);
607 if (A3D && !ADig && closureLevel==3)
611 for (CDynamicCoverageVolume cov(FMap, FMap->alpha23(d));
612 !stop && cov.cont(); ++cov)
613 if (FMap->isFree2(*cov))
615 FMap->stopUp(*cov, 2);
620 FMap->negateMaskMark(AMarkTreated);
624 FMap->setMark(**ACov, AMarkTreated);
627 FMap->negateMaskMark(AMarkTreated);
640 for (ACov->reinit(); ACov->cont(); ++(*ACov))
641 if (!FMap->isMarked(**ACov, AMarkTreated))
643 if (FMap->isMarked(**ACov, AMarkInitial))
646 FMap->markOrbit(**ACov, ORBIT_VERTEX, AMarkTreated);
651 FMap->negateMaskMark(AMarkTreated);
661 if (A3D && !ADig && closureLevel==3)
665 for (CDynamicCoverageVolume cov(FMap, FMap->alpha123(**ACov));
666 !stop && cov.cont(); ++cov)
667 if (FMap->isFree2(*cov))
669 FMap->stopUp(*cov, 2);
674 else if (!ADig && closureLevel==2)
678 for (CDynamicCoverageVolume cov(FMap, FMap->alpha123(**ACov));
679 !stop && cov.cont(); ++cov)
680 if (FMap->isFree1(*cov))
682 FMap->stopUp(*cov, 1);
687 FMap->negateMaskMark(AMarkTreated);
690 FMap->setMark(**ACov, AMarkTreated);
693 FMap->negateMaskMark(AMarkTreated);
697 int ADimension)
const
699 assert(ADimension == 0 || ADimension == 1);
700 return ((
long int) (ADart->getDirectInfo(FCoefs[ADimension]))) / 1000.0;
704 TCoordinate AValue)
const
706 assert(ADimension == 0 || ADimension == 1);
707 ADart->setDirectInfo(FCoefs[ADimension], (
void*) (
long int) (1000 * AValue));