25 #include "bounding-box.hh"
29 #include "message-macros.hh"
32 using namespace GMap3d;
36 #define PROD(V1, V2) ((V1).getX() * (V2).getY() - (V1).getY() * (V2).getX())
38 #define a0 FMap->alpha0
39 #define a1 FMap->alpha1
40 #define a2 FMap->alpha2
41 #define a3 FMap->alpha3
43 #define VTX(d) (AVertexDI < 0 ? FMap->findVertex(d) : \
44 (CAttributeVertex*)FMap->getDirectInfo(d, AVertexDI))
48 CCorefine2dTools::CCorefine2dTools(CGMapVertex * AMap, TCoordinate AEpsilon)
49 : CGeneralTools(AMap,AEpsilon)
56 const CVertex & ASectorVector1,
57 const CVertex & ASectorVector2)
59 if (
PROD(ASectorVector1, ASectorVector2) < 0.0)
60 return (
PROD(ASectorVector1, AVector) >= 0 ||
61 PROD(ASectorVector2, AVector) <= 0);
63 return (
PROD(ASectorVector1, AVector) >= 0 &&
64 PROD(ASectorVector2, AVector) <= 0);
70 CDart * ASector,
int AVertexDI)
72 CVertex center = *
VTX(ASector);
74 CVertex v1 = *
VTX(FMap->alpha0(ASector)) - center;
75 CVertex v2 = *
VTX(FMap->alpha0(FMap->alpha1(ASector))) - center;
83 const CVertex & AVector2)
90 CVertex v1 = normalizeVector(AVector1);
91 CVertex v2 = normalizeVector(AVector2);
96 return arePointsEqual(v1, v2);
102 const CVertex & ALineVertex1,
103 const CVertex & ALineVertex2)
106 CVertex v = ALineVertex2 - ALineVertex1;
108 #ifdef WARNING_MESSAGES
110 WARN_BB(
"<CGeneralTools::pointParameterOnLine> "
111 <<
"Le vecteur est de longueur nulle : " << v);
114 if (fabs(v.getX()) > fabs(v.getY()))
115 res = (APoint.getX() - ALineVertex1.getX()) / v.getX();
117 res = (APoint.getY() - ALineVertex1.getY()) / v.getY();
125 CDart * AVertex,
int AVertexDI)
186 list<CDart*> * l =
new list<CDart*>;
187 list<CDart*>::iterator it;
190 if (
a1(AVertex1) ==
a2(AVertex1)) {
191 l->push_back(AVertex1);
193 AVertex2, AVertexDI)));
200 while (d != AVertex2);
203 else if (
a1(AVertex2) ==
a2(AVertex2)) {
204 l->push_back(AVertex2);
206 AVertex1, AVertexDI)));
213 while (d != AVertex1);
217 int mark = FMap->getNewMark();
218 CVertex center = *
VTX(AVertex1);
221 CVertex v = *
VTX(
a0(d)) - center;
225 CDart *d1 =
a2(
a1(AVertex1));
226 CDart *d2 =
a2(
a1(AVertex2));
228 CVertex v1 = *
VTX(
a0(d1)) - center;
229 CVertex v2 = *
VTX(
a0(d2)) - center;
231 #define INSERT(dart) (l->push_back(dart), FMap->setMark(dart, mark))
239 MSG(
"v = " << center <<
" --> " << center + v);
240 MSG(
"v1 = " << center <<
" --> " << center + v1);
241 MSG(
"v2 = " << center <<
" --> " << center + v2);
244 MSG(
"v1 entre v et v2 : " << test1);
245 MSG(
"v2 entre v et v1 : " << test2);
248 MSG(
"v et v2 sont colinéaires");
252 v2 = *
VTX(
a0(d2)) - center;
256 MSG(
"v1 et v2 sont colinéaires");
261 if (!FMap->isMarked(d2, mark)) {
268 v1 = *
VTX(
a0(d1)) - center;
269 v2 = *
VTX(
a0(d2)) - center;
271 else if (test1 && !test2) {
272 MSG(
"v1 est entre v et v2");
277 v1 = *
VTX(
a0(d1)) - center;
279 else if (!test1 && test2) {
280 MSG(
"v2 est entre v et v1");
285 v2 = *
VTX(
a0(d2)) - center;
288 assert(test1 != test2);
291 while (!FMap->isMarked(d, mark));
295 bool problem =
false;
300 if (FMap->isMarked(d2, mark))
301 FMap->unsetMark(d2, mark);
303 WARN_BR(
"<CCorefine2dTools::sortVerticesEdges> "
304 <<
"Brin du deuxième sommet non marqué !");
310 while (d2 != AVertex2);
315 if (FMap->isMarked(d1, mark))
316 FMap->unsetMark(d1, mark);
318 WARN_BR(
"<CCorefine2dTools::sortVerticesEdges> "
319 <<
"Brin du premier sommet non marqué !");
325 while (d1 != AVertex1);
327 FMap->freeMark(mark);
331 <<
"Tri angulaire autour du sommet " << center << endl;
332 for (it = l->begin() ; it != l->end() ; it++) {
333 cout << *
VTX(
a0(*it)) << endl;
349 const list<CDart*> & AVertices,
352 int mark = FMap->getNewMark();
353 list<CDart*> * l =
new list<CDart*>;
354 list<CDart*>::const_iterator it;
355 int size = AVertices.size();
356 CDart **darts =
new CDart*[size];
357 CDart **tmp_darts =
new CDart*[size];
358 CVertex *vectors =
new CVertex[size];
361 CVertex center = *
VTX(AVertex1);
364 CVertex v = *
VTX(
a0(d)) - center;
366 CDart *d1 =
a2(
a1(AVertex1));
367 CVertex v1 = *
VTX(
a0(d1)) - center;
369 for (it = AVertices.begin() ; it != AVertices.end() ; it++) {
371 tmp_darts[i] =
a2(
a1(darts[i]));
372 vectors[i] = *
VTX(
a0(tmp_darts[i])) - center;
376 #define INSERT(dart) (l->push_back(dart), FMap->setMark(dart, mark))
384 for (i = 1 ; i < size ; i++)
392 for (i = 0 ; i < size ; i++)
394 if(!FMap->isMarked(tmp_darts[i], mark)) {
398 tmp_darts[i] =
a2(
a1(tmp_darts[i]));
399 vectors[i] = *
VTX(
a0(tmp_darts[i])) - center;
403 v1 = *
VTX(
a0(d1)) - center;
409 for (i = 0 ; i < size ; i++)
411 if(!FMap->isMarked(tmp_darts[i], mark)) {
415 tmp_darts[i] =
a2(
a1(tmp_darts[i]));
416 vectors[i] = *
VTX(
a0(tmp_darts[i])) - center;
419 tmp_darts[j] =
a2(
a1(tmp_darts[j]));
420 vectors[j] = *
VTX(
a0(tmp_darts[j])) - center;
426 v1 = *
VTX(
a0(d1)) - center;
429 while ( !FMap->isMarked(d, mark));
433 bool problem =
false;
436 for (i = 0 ; i < size ; i++) {
437 tmp_darts[i] = darts[i];
440 if (FMap->isMarked(tmp_darts[i], mark))
441 FMap->unsetMark(tmp_darts[i], mark);
443 WARN_BR(
"<CCorefine2dTools::sortMultipleVerticesEdges> "
444 <<
"Brin du sommet n°" << i <<
" non marqué !");
448 tmp_darts[i] =
a2(
a1(tmp_darts[i]));
450 while (tmp_darts[i] != darts[i]);
456 if (FMap->isMarked(d1, mark))
457 FMap->unsetMark(d1, mark);
459 WARN_BR(
"<CCorefine2dTools::sortMultipleVerticesEdges> "
460 <<
"Brin du premier sommet non marqué !");
466 while (d1 != AVertex1);
468 FMap->freeMark(mark);
475 #ifdef WARNING_MESSAGES
476 cout <<
"\033[1;34m" <<
"Tri angulaire autour du sommet " << center << endl;
477 for (it = l->begin() ; it != l->end() ; it++)
478 cout << *
VTX(
a0(*it)) << endl;
496 v1 = faceNormalVector(AVertex, AVertexDI);
497 v2 = faceNormalVector(
a2(AVertex), AVertexDI);
499 if ((v1.getZ() < 0.0 && v2.getZ() < 0.0) ||
500 (v1.getZ() > 0.0 && v2.getZ() > 0.0)) {
504 CBoundingBox bb1, bb2;
506 bb1 = orbitBoundingBox(AVertex, ORBIT_FACE, AVertexDI);
507 bb2 = orbitBoundingBox(
a2(AVertex), ORBIT_FACE, AVertexDI);
509 if (bb1.getSurface() <= bb2.getSurface()) {
511 if (v1.getZ() < 0.0) {
512 AVertex =
a1(AVertex);
517 if (v1.getZ() > 0.0) {
518 AVertex =
a1(AVertex);
522 else if (v1.getZ() < 0.0) {
523 AVertex =
a1(AVertex);
533 const CVertex & AVertex1,
534 const CVertex & AVertex2,
535 TCoordinate * AParam)
537 assert(AParam != NULL);
539 if (arePointsEqual(APoint, AVertex2)) {
544 if (arePointsEqual(APoint, AVertex1)) {
549 if (isPointOnLine(APoint, AVertex1, AVertex2)) {
552 if (*AParam >= 0.0 && *AParam <= 1.0)
563 const CVertex & ALinePoint2,
564 const CVertex & AEdgePoint1,
565 const CVertex & AEdgePoint2,
566 TCoordinate * ALineParam,
567 TCoordinate * AEdgeParam)
569 assert(AEdgeParam != NULL && ALineParam != NULL);
584 CVertex v[2] = {ALinePoint2 - ALinePoint1, AEdgePoint2 - AEdgePoint1};
585 TCoordinate d = v[0].getY() * v[1].getX() - v[0].getX() * v[1].getY();
587 #ifdef WARNING_MESSAGES
588 if (isVectorNull(v[0]) || isVectorNull(v[1]))
589 WARN_BB(
"<localizeEdgesIntersection>"
590 <<
"Une des arêtes est de longueur nulle !");
596 *ALineParam = (v[1].getY() * (ALinePoint1.getX() - AEdgePoint1.getX()) -
597 v[1].getX() * (ALinePoint1.getY() - AEdgePoint1.getY())) / d;
599 if (fabs(v[1].getX()) > fabs(v[1].getY()))
600 *AEdgeParam = (ALinePoint1.getX() + *ALineParam * v[0].getX() -
601 AEdgePoint1.getX()) / v[1].getX();
603 *AEdgeParam = (ALinePoint1.getY() + *ALineParam * v[0].getY() -
604 AEdgePoint1.getY()) / v[1].getY();
614 if (*AEdgeParam >= 0.0 && *AEdgeParam <= 1.0)
624 const CVertex & AVertex2,
631 int edge_mark = FMap->getNewMark();
633 TCoordinate t1 = 0.0, t2 = 0.0, best_t2 = 1.0;
637 if (AVertex1 == AVertex2) {
638 FMap->freeMark(edge_mark);
646 if ((pos ==
EP_OnEdge && t2 < best_t2) ||
656 FMap->setMark(d, edge_mark);
657 FMap->setMark(
a0(d), edge_mark);
658 FMap->setMark(
a1(d), edge_mark);
659 FMap->setMark(
a0(
a1(d)), edge_mark);
671 if (FMap->isMarked(d, edge_mark)) {
672 FMap->unsetMark(d, edge_mark);
673 FMap->unsetMark(
a0(d), edge_mark);
675 else if (fabs((*pt2 - *pt1).norm()) > FEps / 2.0) {
678 if ((t1 >= 0.0 && t1 <= 1.0) &&
682 d != AFace && d !=
a0(
a1(AFace))) ||
696 FMap->freeMark(edge_mark);
699 inter.
setPoint(AVertex1 + best_t2 * (AVertex2 - AVertex1));
707 CDart * AMesh,
int AVertexDI)
737 while (inter.
getCell() != NULL);
746 CDart *d, *to_link[4], *edge[4], *to_remove[4];
747 int remove_mark = FMap->getNewMark();
750 for (CStaticCoverageCC scc(FMap, AMesh1) ; scc.cont() ; scc++) {
753 if (!FMap->isMarked(
a1(d), remove_mark)) {
756 edge[1] =
a0(edge[0]);
757 edge[2] =
a2(edge[1]);
758 edge[3] =
a0(edge[2]);
760 to_remove[0] =
a2(
a1(d));
761 to_remove[1] =
a0(to_remove[0]);
762 to_remove[2] =
a2(to_remove[1]);
763 to_remove[3] =
a0(to_remove[2]);
768 to_link[2] =
a1(to_remove[0]);
769 to_link[3] =
a1(to_remove[1]);
773 to_link[1] =
a0(
a2(d));
774 to_link[2] =
a1(to_remove[0]);
775 to_link[3] =
a1(to_remove[2]);
778 for (
int i=0 ; i<4 ; i++) {
779 if (!FMap->isFree1(to_link[i]))
780 FMap->dartUnsew1(to_link[i]);
782 FMap->setMark(to_remove[i], remove_mark);
784 if (AMesh1 == to_remove[i])
786 if (AMesh2 == to_remove[i])
789 for (
int j = 0; j < NB_MARKS; j++)
790 if (ACopyMarks[j] && FMap->isMarked(to_remove[i], j))
791 FMap->setMark(edge[i], j);
794 FMap->dartSew1(to_link[0], to_link[2]);
795 FMap->dartSew1(to_link[1], to_link[3]);
797 if (AVertexDI >= 0) {
798 FMap->pointDirectInfoToAttributeVertex(AVertexDI, to_link[0]);
799 FMap->pointDirectInfoToAttributeVertex(AVertexDI, to_link[1]);
805 FMap->deleteMarkedDarts(remove_mark);
807 FMap->freeMark(remove_mark);