28 #include "g-map-vertex.hh"
30 using namespace GMap3d;
32 #define RINT(V) ((double) ((int) (V)))
45 static TCoordinate k0;
46 static TCoordinate kw[4];
47 static TCoordinate decalageX, decalageY;
48 static TCoordinate coefMultProf;
49 static TCoordinate profMin;
50 static bool invertY =
true;
112 void CControlerGMap::transfoMmPixel( CVertex & v2d )
116 float dpmX=(1200/25.4);
117 float dpmY=(1200/25.4);
123 void CControlerGMap::sauveEntete ( ofstream &os,
int nbCoul )
140 for (
int i=0;i<nbCoul;++i) os<<
"0 "<<32+i<<
" #000000"<<endl;
142 for (
int i=0;i<nbCoul;++i) os<<
"0 "<<32+i<<
" "<<
COUL_USER[i]<<endl;
145 void CControlerGMap::debutComposante( ofstream &os,
146 const CVertex & min,
const CVertex & max )
149 <<int(
RINT(min.getX()+decalageX))<<
" "
150 <<int(
RINT(min.getY()+decalageY))<<
" "
151 <<int(
RINT(max.getX()+decalageX))<<
" "
152 <<int(
RINT(max.getY()+decalageY))<<endl;
156 int CControlerGMap::computeProf(
const CVertex & V)
158 int p = int(
RINT(coefMultProf*(V.getZ()-profMin)));
169 int CControlerGMap::computeProf(
const CVertex & V1,
const CVertex & V2)
171 TCoordinate c = (V1.getZ() + V2.getZ())/2;
173 int p = int(
RINT(coefMultProf*(c-profMin)));
184 void CControlerGMap::sauvePoint(ofstream &os,
const CVertex & v,
185 int coul,
int larg,
int AProf)
187 os<<
"1 4 0 "<<larg<<
" "<<32+coul<<
" "<<32+coul<<
" ";
188 if ( AProf==-1 ) os<<computeProf(v);
else os << AProf;
189 os <<
" 0 20 0.000 1 0.0000 ";
191 os<<int(
RINT(v.getX()+decalageX))<<
" "
192 <<int(
RINT(v.getY()+decalageY))<<
" "
194 <<int(
RINT(v.getX()+decalageX))<<
" "
195 <<int(
RINT(v.getY()+decalageY))<<
" "
196 <<int(
RINT(v.getX()+decalageX+
RAYON))<<
" "
197 <<int(
RINT(v.getY()+decalageY+
RAYON))<<endl;
200 void CControlerGMap::sauveDartVertex(std::ofstream &os,
const CVertex & v,
208 os<<int(
RINT(v.getX()+decalageX))<<
" "
209 <<int(
RINT(v.getY()+decalageY))<<
" "
211 <<int(
RINT(v.getX()+decalageX))<<
" "
212 <<int(
RINT(v.getY()+decalageY))<<
" "
213 <<int(
RINT(v.getX()+decalageX+
RAYON))<<
" "
214 <<int(
RINT(v.getY()+decalageY+
RAYON))<<endl;
217 void CControlerGMap::sauveLine(ofstream &os,
218 const CVertex & p1,
const CVertex & p2,
219 int coul,
int larg,
bool arrow,
int AProf)
223 if (AProf<0) prof = computeProf(p1,p2);
226 os<<
"2 1 0 "<<larg<<
" "<<32+coul<<
" 0 "<< prof <<
" 0 -1 0.000 1 0 7 ";
230 <<
" 2 0 1.00 60.00 120.00\n";
235 os<<int(
RINT(p1.getX()+decalageX))<<
" "
236 <<int(
RINT(p1.getY()+decalageY))<<
" "
237 <<int(
RINT(p2.getX()+decalageX))<<
" "
238 <<int(
RINT(p2.getY()+decalageY))<<endl;
242 void CControlerGMap::sauveTriangle(ofstream & os,
int coulFill,
int larg,
243 CVertex & PC, CVertex & P1, CVertex & P2)
245 os <<
"2 1 0 " << larg <<
" -1 "
246 << 32+coulFill <<
" "
247 << (1+computeProf((PC+P1+P2)/3)) <<
" 0 20 0.000 1 0 7 0 0 " << 4 << endl;
249 os << int(
RINT(PC.getX()+decalageX)) <<
" "
250 << int(
RINT(PC.getY()+decalageY)) << endl;
251 os << int(
RINT(P1.getX()+decalageX)) <<
" "
252 << int(
RINT(P1.getY()+decalageY)) << endl;
253 os << int(
RINT(P2.getX()+decalageX)) <<
" "
254 << int(
RINT(P2.getY()+decalageY)) << endl;
255 os << int(
RINT(PC.getX()+decalageX)) <<
" "
256 << int(
RINT(PC.getY()+decalageY)) << endl;
259 void CControlerGMap::sauveFace(ofstream &os, CVertex *p,
int nbPts,
260 int coulFill,
int larg,
int AProf )
264 bool compactFaces = isZero(FMap->getBurstCoef(1) - 1.0);
266 os<<
"2 1 0 " << (compactFaces&&!
drawArrows?larg:0) <<
" "
267 << 32+
COUL_DART <<
" " << 32+coulFill <<
" "
268 << (1+AProf) <<
" 0 20 0.000 1 0 7 0 0 "
271 for (
int i=0; i<nbPts; ++i)
273 os << int(
RINT(p[i].getX()+decalageX)) <<
" "
274 << int(
RINT(p[i].getY()+decalageY)) << endl;
307 void CControlerGMap::transfo3dTo2d(
const CVertex & v3d, CVertex & v2d )
311 FViews[FViewId]->project( v3d.getX(), v3d.getY(), v3d.getZ(), res);
313 v2d.setX(res[0]); v2d.setY(res[1]); v2d.setZ(res[2]);
317 if (invertY) v2d.setY(-v2d.getY());
321 void CControlerGMap::updateMinMax2d(
const CVertex & pts,
322 CVertex & min, CVertex & max,
bool init )
325 transfo3dTo2d(pts,tmp);
328 { min=tmp; max=tmp; }
331 if (tmp.getX()<min.getX()) min.setX(tmp.getX());
332 if (tmp.getY()<min.getY()) min.setY(tmp.getY());
333 if (tmp.getZ()<min.getZ()) min.setZ(tmp.getZ());
334 if (tmp.getX()>max.getX()) max.setX(tmp.getX());
335 if (tmp.getY()>max.getY()) max.setY(tmp.getY());
336 if (tmp.getZ()>max.getZ()) max.setZ(tmp.getZ());
341 void CControlerGMap::getIncludingBoxForDarts( CDart* d, TOrbit orb,
342 CVertex & min, CVertex & max )
344 CCoverage* cov = FMap->getDynamicCoverage(d,orb);
348 transfo3dTo2d(FMap->getBurstVertex(d),min);
355 updateMinMax2d(FMap->getBurstVertex(**cov),min,max);
362 #define WEIGHTING(k, v1,v2) ( (1-(k)) * (v1) + (k) * (v2) )
364 void CControlerGMap::treatSews( ofstream & fout, CDart * dart,
368 CVertex vTmp, v2Tmp, v3Tmp, p1, p2;
370 for (
int i=0; i<=3; ++i)
371 if (!FMap->isMarked(FMap->alpha(dart,i),mark))
373 darti= FMap->alpha(dart,i);
374 if (!FMap->isFree(dart,i) &&
379 transfo3dTo2d(FMap->getBurstVertex(dart ), p1);
380 transfo3dTo2d(FMap->getBurstVertex(darti), p2);
384 int prof1 = computeProf(p1, vTmp);
385 int prof2 = computeProf(p2, vTmp);
387 int prof = prof1<prof2 ? prof1 : prof2;
392 vTmp = (FMap->getBurstVertex(dart) +
393 FMap->getBurstVertex(darti))/2;
395 v2Tmp=
WEIGHTING(kw[0],vTmp, FMap->computeBurstExtremity(dart ));
396 v3Tmp=
WEIGHTING(kw[0],vTmp, FMap->computeBurstExtremity(darti));
397 transfo3dTo2d(v2Tmp,p1);
398 transfo3dTo2d(v3Tmp,p2);
404 if ( FMap->isFree0(dart) || kw[i]!=1 || dart<FMap->alpha0(dart) )
406 vTmp =
WEIGHTING(kw[i],FMap->getBurstVertex(dart ),
407 FMap->computeBurstExtremity(dart ));
408 v2Tmp=
WEIGHTING(kw[i],FMap->getBurstVertex(darti),
409 FMap->computeBurstExtremity(darti));
410 transfo3dTo2d(v2Tmp,p1);
411 transfo3dTo2d(vTmp,p2);
421 void CControlerGMap::treatDartWithArrow( ofstream & fout, CDart * dart,
422 int ,
int mark2,
int AProf )
429 v1= FMap->getBurstVertex(dart);
430 transfo3dTo2d(v1, p1);
432 if (FMap->isFree0(dart))
436 CDart *dart0=FMap->alpha0(dart);
457 v1= FMap->getBurstVertex(dart0);
458 transfo3dTo2d(v1, p2);
460 if (FMap->isMarked(dart,mark2))
462 sauveLine(fout,p1,p2,coul,larg,
true, AProf);
464 sauveDartVertex( fout, p1, p2 );
468 sauveLine(fout,p2,p1,coul,larg,
true, AProf);
470 sauveDartVertex( fout, p2, p1 );
476 void CControlerGMap::treatDartNoArrow( ofstream & fout, CDart * dart,
503 v1= FMap->getBurstVertex(dart);
504 transfo3dTo2d(v1, p1);
506 if (FMap->isFree0(dart))
510 CDart *dart0 = FMap->alpha0(dart);
512 transfo3dTo2d(FMap->getBurstVertex(dart ), p1);
513 transfo3dTo2d(FMap->getBurstVertex(dart0), p2);
514 CVertex p0 = (p1+p2)/2;
516 v2=FMap->computeBurstExtremity(dart);
517 transfo3dTo2d(v2, p2);
518 sauveLine(fout,p1,p2,coul,larg,
false, computeProf(p1,p0));
541 v1= FMap->getBurstVertex(dart0);
542 transfo3dTo2d(v1, p1);
544 v2=FMap->computeBurstExtremity(dart0);
545 transfo3dTo2d(v2, p2);
546 sauveLine(fout,p1,p2,coul,larg,
false, computeProf(p1,p0));
549 sauveDartVertex( fout, p1, p2);
554 void CControlerGMap::treatFace( ofstream & fout, CDart * initDart,
555 int mark,
int mark2 )
560 CDynamicCoverage01 covF(FMap,initDart);
561 while ( covF.cont() )
563 if ( !FMap->isMarked(*covF,mark) )
566 assert(!FMap->isMarked(FMap->alpha0(*covF),mark));
569 if (
drawArrows) treatDartWithArrow(fout,dart,mark,mark2);
570 else treatDartNoArrow(fout,dart,mark,mark2);
574 treatSews(fout,dart,mark,mark2);
575 if (!FMap->isFree0(dart))
576 treatSews(fout,FMap->alpha0(dart),mark,mark2);
579 FMap->setMark(dart,mark);
580 FMap->setMark(FMap->alpha0(dart),mark);
587 void CControlerGMap::treatFilledFace( ofstream & fout, CDart * dart,
588 int mark,
int mark2 )
594 dart=FMap->alpha0(dart);
597 CDynamicCoverage01 covF(FMap,dart);
598 while ( covF.cont() )
601 if (FMap->isFree0(*covF) || FMap->isFree1(*covF))
603 treatFace(fout,dart,mark,mark2);
609 bool compactFaces = isZero(FMap->getBurstCoef(1) - 1.0);
615 CVertex * tabV =
new CVertex[nbPts+1];
618 for (covF.reinit(); covF.cont();)
620 v1= FMap->getBurstVertex(*covF);
621 transfo3dTo2d(v1, tabV[nbPts++]);
622 baryFace += tabV[nbPts-1];
624 if (compactFaces && covF.cont())
631 baryFace -= tabV[nbPts-1];
634 for (covF.reinit(); covF.cont();)
640 treatDartWithArrow(fout,*covF,mark,mark2,computeProf(baryFace));
645 treatSews(fout,*covF,mark,mark2);
646 if (!FMap->isFree0(*covF))
647 treatSews(fout,FMap->alpha0(*covF),mark,mark2);
650 FMap->setMark(*covF,mark);
651 FMap->setMark(FMap->alpha0(*covF),mark);
654 if (compactFaces && covF.cont())
661 tabV[nbPts++] = tabV[0];
665 treatFace(fout,dart,mark,mark2);
673 void CControlerGMap::saveGridIncludingBox( ofstream & fout )
675 CVertex v1, v2, p1, p2;
676 CVertex vmin(0,0,0), vmax(0,0,0);
682 v1=CVertex(0,0,0); updateMinMax2d(v1,vmin,vmax,init); init=
false;
683 v1=CVertex(1,0,0); updateMinMax2d(v1,vmin,vmax,init);
685 v1=CVertex(0,1,0); updateMinMax2d(v1,vmin,vmax,init);
687 v1=CVertex(0,0,1); updateMinMax2d(v1,vmin,vmax,init);
699 int xmin= px ? 0 : -size;
700 int ymin= py ? 0 : -size;
701 int zmin= pz ? 0 : -size;
703 for (
int i=-size; i<=+size; ++i)
710 v1=CVertex(xmin, i, 0); updateMinMax2d(v1,vmin,vmax,init);
712 v1=CVertex(size, i, 0); updateMinMax2d(v1,vmin,vmax,init);
717 v1=CVertex(i, ymin, 0); updateMinMax2d(v1,vmin,vmax,init);
719 v1=CVertex(i, size, 0); updateMinMax2d(v1,vmin,vmax,init);
727 v1=CVertex(xmin, 0, i); updateMinMax2d(v1,vmin,vmax,init);
729 v1=CVertex(size, 0, i); updateMinMax2d(v1,vmin,vmax,init);
734 v1=CVertex(i, 0, zmin); updateMinMax2d(v1,vmin,vmax,init);
736 v1=CVertex(i, 0, size); updateMinMax2d(v1,vmin,vmax,init);
744 v1=CVertex(0, ymin, i); updateMinMax2d(v1,vmin,vmax,init);
746 v1=CVertex(0, size, i);updateMinMax2d(v1,vmin,vmax,init);
751 v1=CVertex(0, i, zmin); updateMinMax2d(v1,vmin,vmax,init);
753 v1=CVertex(0, i, size); updateMinMax2d(v1,vmin,vmax,init);
759 debutComposante(fout,vmin,vmax);
763 void CControlerGMap::treatGrid(ofstream & fout)
765 CVertex v1, v2, p1, p2;
767 saveGridIncludingBox(fout);
774 transfo3dTo2d(v1,p1); transfo3dTo2d(v2,p2);
778 transfo3dTo2d(v2,p2);
782 transfo3dTo2d(v2,p2);
795 int xmin= px ? 0 : -size;
796 int ymin= py ? 0 : -size;
797 int zmin= pz ? 0 : -size;
799 for (
int i=-size; i<=+size; ++i)
806 v1=CVertex(xmin, i, 0); v2=CVertex(size, i, 0);
807 transfo3dTo2d(v1,p1); transfo3dTo2d(v2,p2);
813 v1=CVertex(i, ymin, 0); v2=CVertex(i, size, 0);
814 transfo3dTo2d(v1,p1); transfo3dTo2d(v2,p2);
823 v1=CVertex(xmin, 0, i); v2=CVertex(size, 0, i);
824 transfo3dTo2d(v1,p1); transfo3dTo2d(v2,p2);
830 v1=CVertex(i, 0, zmin); v2=CVertex(i, 0, size);
831 transfo3dTo2d(v1,p1); transfo3dTo2d(v2,p2);
840 v1=CVertex(0, ymin, i); v2=CVertex(0, size, i);
841 transfo3dTo2d(v1,p1); transfo3dTo2d(v2,p2);
847 v1=CVertex(0, i, zmin); v2=CVertex(0, i, size);
848 transfo3dTo2d(v1,p1); transfo3dTo2d(v2,p2);
859 bool AArrow,
bool AFace,
bool ASews,
860 bool AGrid,
bool AVertices,
bool AInvert )
862 CVertex min, max, vTmp, v2Tmp, v3Tmp;
874 k0 = FMap->getBurstCoef(0);
883 CDynamicCoverageAll it(FMap);
885 v1 = FMap->getBurstVertex(*it);
886 transfo3dTo2d(v1,min);
891 v1= FMap->getBurstVertex(it++);
892 updateMinMax2d(v1,min,max);
896 decalageX=5-min.getX();
897 decalageY=5-min.getY();
898 coefMultProf=
MAX_PROF/(max.getZ()-min.getZ());
906 int mark=FMap->getNewMark();
907 int mark2=FMap->getNewMark();
912 if (!FMap->isMarked(*it,mark))
915 CDynamicCoverage0123 cov(FMap,*it);
918 FMap->setMark(*cov,mark);
919 if (!FMap->isMarked(FMap->alpha0(*cov),mark2) &&
920 !FMap->isMarked(FMap->alpha1(*cov),mark2) &&
921 !FMap->isMarked(FMap->alpha3(*cov),mark2) &&
922 !FMap->isMarked(FMap->alpha2(*cov),mark2) )
923 FMap->setMark(*cov,mark2);
930 FMap->negateMaskMark(mark);
936 if (!FMap->isMarked(*it,mark))
939 getIncludingBoxForDarts(*it,ORBIT_0123,min,max);
940 debutComposante(AFout,min,max);
942 CDynamicCoverage0123 covCc(FMap,*it);
943 while ( covCc.cont() )
945 if (!FMap->isMarked(*covCc,mark))
947 getIncludingBoxForDarts(*covCc,ORBIT_012,min,max);
948 debutComposante(AFout,min,max);
951 CDynamicCoverageVolume covV(FMap,*covCc);
952 while ( covV.cont() )
954 if (!FMap->isMarked(*covV,mark))
956 getIncludingBoxForDarts(*covV,ORBIT_01,min,max);
957 debutComposante(AFout,min,max);
960 treatFilledFace(AFout,*covV,mark,mark2);
962 treatFace(AFout,*covV,mark,mark2);
977 FMap->negateMaskMark(mark);
978 FMap->freeMark(mark);
979 FMap->unmarkAll(mark2);
980 FMap->freeMark(mark2);
983 void CControlerGMap::treatPointel(ofstream &os, CDart *d,
int mark)
985 CDynamicCoverage123 it(FMap,d);
986 while(it.cont()) FMap->setMark(it++,mark);
988 CVertex *v1 = FMap->findVertex(d);
991 transfo3dTo2d(*v1, p1);
996 void CControlerGMap::treatLignel(ofstream &os, CDart *d,
int mark)
998 CDynamicCoverage023 it(FMap,d);
999 while(it.cont()) FMap->setMark(it++,mark);
1001 CVertex *v1 = FMap->findVertex(d);
1002 CVertex *v2 = FMap->findVertex(FMap->alpha0(d));
1004 CVertex edgeBary= (*v1 + *v2)/2;
1010 transfo3dTo2d(p1, pp1);
1011 transfo3dTo2d(p2, pp2);
1023 CVertex min, max, vTmp, v2Tmp, v3Tmp;
1029 k0= FMap->getBurstCoef(0);
1039 CDynamicCoverageAll it(FMap);
1041 v1= FMap->getBurstVertex(*it);
1042 transfo3dTo2d(v1,min);
1047 v1= FMap->getBurstVertex(it++);
1048 updateMinMax2d(v1,min,max);
1052 decalageX=5-min.getX();
1053 decalageY=5-min.getY();
1054 coefMultProf=
MAX_PROF/(max.getZ()-min.getZ());
1058 int mark = FMap->getNewMark();
1059 int mark2 = FMap->getNewMark();
1060 int mark3 = FMap->getNewMark();
1066 if (!FMap->isMarked(*it,mark))
1069 getIncludingBoxForDarts(*it,ORBIT_0123,min,max);
1070 debutComposante(AFout,min,max);
1072 CDynamicCoverage0123 covCc(FMap,*it);
1073 while ( covCc.cont() )
1075 if (!FMap->isMarked(*covCc,mark))
1077 getIncludingBoxForDarts(*covCc,ORBIT_012,min,max);
1078 debutComposante(AFout,min,max);
1081 CDynamicCoverageVolume covV(FMap,*covCc);
1082 while ( covV.cont() )
1084 if (!FMap->isMarked(*covV,mark))
1086 getIncludingBoxForDarts(*covV,ORBIT_01,min,max);
1087 debutComposante(AFout,min,max);
1089 treatFilledFace(AFout,*covV,mark,0);
1102 if (!FMap->isMarked(*it,mark2))
1103 treatLignel(AFout,*it,mark2);
1105 if (!FMap->isMarked(*it,mark3))
1106 treatPointel(AFout,*it,mark3);
1111 FMap->negateMaskMark(mark);
1112 FMap->freeMark(mark);
1113 FMap->negateMaskMark(mark2);
1114 FMap->freeMark(mark2);
1115 FMap->negateMaskMark(mark3);
1116 FMap->freeMark(mark3);