Moka controlers
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
controler-gmap-export-xfig.cc
Go to the documentation of this file.
1 /*
2  * lib-controler-gmap : Le contrôleur de 3-G-cartes, surcouche de lib-controler.
3  * Copyright (C) 2004, Moka Team, Université de Poitiers, Laboratoire SIC
4  * http://www.sic.sp2mi.univ-poitiers.fr/
5  * Copyright (C) 2009, Guillaume Damiand, CNRS, LIRIS,
6  * guillaume.damiand@liris.cnrs.fr, http://liris.cnrs.fr/
7  *
8  * This file is part of lib-controler-gmap
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #include <cmath>
25 #include <cstring>
26 #include "controler-gmap.hh"
27 #include "view-precompile.hh"
28 #include "g-map-vertex.hh"
29 using namespace std;
30 using namespace GMap3d;
31 
32 #define RINT(V) ((double) ((int) (V)))
33 /*************************************************/
34 
35 static TViewId FViewId;
36 
38 bool drawFaces;
39 bool drawSews;
40 bool drawGrid;
42 
43 /*************************************************/
44 
45 static TCoordinate k0; // coefficients for draw the sew
46 static TCoordinate kw[4];
47 static TCoordinate decalageX, decalageY; // the decalage offset in 2D
48 static TCoordinate coefMultProf;
49 static TCoordinate profMin;
50 static bool invertY = true;
51 
52 //******************************************************************************
53 // Windows/mapGlXfig.inc
54 int MAX_PROF =999; // profondeur max accepte par xfig
55 
56 int COUL_DART =0; //le numero de la couleur perso associe aux divers elements
57 
58 int COUL_SEW[4] ={1,2,3,4};
59 
61 
62 int COUL_SEL [NB_SELECTION_LEVELS] = { 6 , 7 , 8 };
63 int COUL_LAST[NB_SELECTION_LEVELS] = { 9 , 10 , 11 };
64 
65 int COUL_VERTEX =12;
66 int COUL_GRID =13;
67 int COUL_AXE_X =14;
68 int COUL_AXE_Y =15;
69 int COUL_AXE_Z =16;
71 int COUL_POINTEL =18;
72 int COUL_LIGNEL =19;
74 
75 int LARG_DART =1; //largeurs des lignes des divers elements
76 int LARG_SEL [NB_SELECTION_LEVELS] = {1,1,1};
78 int LARG_SEW[4] ={1,1,1,1};
79 int LARG_GRID =1;
80 int LARG_AXE_X =1;
81 int LARG_AXE_Y =1;
82 int LARG_AXE_Z =1;
85 int LARG_LIGNEL =3;
87 float COEF_REDUC_LIGNEL=0.75; // coefficient pour homotethie des lignels
88 int COEF_DE_REDUCTION=5; // Car sinon le dessin xfig est beaucoup trop gros
89 float RAYON =100/COEF_DE_REDUCTION; // rayon d'un brin non cousu par alpha0
90 int NB_COUL_USER=21; // Doit être > à 15
91 typedef char coulXfig[8];
93 
94 //******************************************************************************
96 {
97  assert(NB_COUL_USER>15);
98 
99  if ( COUL_USER!=NULL ) delete COUL_USER;
100 
102  for (int i=0;i<NB_COUL_USER;++i) strcpy(COUL_USER[i],"#000000");
103  strcpy(COUL_USER[ 1],"#808080"); // 0-coutures
104  strcpy(COUL_USER[ 2],"#FF0000"); // 1-coutures
105  strcpy(COUL_USER[ 3],"#008000"); // 2-coutures
106  strcpy(COUL_USER[ 4],"#0000FF"); // 3-coutures
107  strcpy(COUL_USER[ COUL_FILL_FACE],"#DDDDDD"); // faces pleines
108  strcpy(COUL_USER[COUL_DART_VERTEX],"#A0A0A0"); // points associés aux brins
109 }
110 
111 //******************************************************************************
112 void CControlerGMap::transfoMmPixel( CVertex & v2d )
113 {
114  // Xfig est en 1200 dpi, et donc le nombre de pixel par mm vaut 1200/25.4
115  // (sachant que 1inch==25.4mm)
116  float dpmX=(1200/25.4);
117  float dpmY=(1200/25.4);
118  v2d.setX(static_cast<TCoordinate>((v2d.getX()*dpmX)/COEF_DE_REDUCTION));
119  v2d.setY(static_cast<TCoordinate>((v2d.getY()*dpmY)/COEF_DE_REDUCTION));
120 }
121 
122 //******************************************************************************
123 void CControlerGMap::sauveEntete ( ofstream &os, int nbCoul )
124 {
125  os<<"#FIG 3.2"<<endl
126  <<"Portrait"<<endl
127  <<"Metric"<<endl
128  <<"A4"<<endl
129  <<"100.00"<<endl
130  <<"Single"<<endl
131  <<"-2"<<endl
132  <<"1200 2"<<endl;
133  // Ici, on definit des couleurs personelles. Cela permet ensuite de
134  // changer une valeur et cela entraine la modif de tous les brins
135  // ayant cette couleur.
136 
137  initConfig();
138 
139  if (COUL_USER==NULL)
140  for (int i=0;i<nbCoul;++i) os<<"0 "<<32+i<<" #000000"<<endl;
141  else
142  for (int i=0;i<nbCoul;++i) os<<"0 "<<32+i<<" "<<COUL_USER[i]<<endl;
143 }
144 //******************************************************************************
145 void CControlerGMap::debutComposante( ofstream &os,
146  const CVertex & min, const CVertex & max )
147 {
148  os<<"6 "
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;
153 }
154 
155 //******************************************************************************
156 int CControlerGMap::computeProf(const CVertex & V)
157 {
158  int p = int(RINT(coefMultProf*(V.getZ()-profMin)));
159 
160  if (p<0)
161  p=0;
162 
163  if (p>MAX_PROF)
164  p=MAX_PROF;
165 
166  return p;
167 }
168 
169 int CControlerGMap::computeProf(const CVertex & V1, const CVertex & V2)
170 {
171  TCoordinate c = (V1.getZ() + V2.getZ())/2;
172 
173  int p = int(RINT(coefMultProf*(c-profMin)));
174 
175  if (p<0)
176  p=0;
177 
178  if (p>MAX_PROF)
179  p=MAX_PROF;
180 
181  return p;
182 }
183 //******************************************************************************
184 void CControlerGMap::sauvePoint(ofstream &os, const CVertex & v,
185  int coul, int larg, int AProf)
186 {
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 ";
190 
191  os<<int(RINT(v.getX()+decalageX))<<" " // Centre x et y
192  <<int(RINT(v.getY()+decalageY))<<" "
193  <<RAYON<<" "<<RAYON<<" " //Rayon en x et en y
194  <<int(RINT(v.getX()+decalageX))<<" " // Premier point == centre
195  <<int(RINT(v.getY()+decalageY))<<" "
196  <<int(RINT(v.getX()+decalageX+RAYON))<<" " // deuxieme point (sur le cercle)
197  <<int(RINT(v.getY()+decalageY+RAYON))<<endl;
198 }
199 //******************************************************************************
200 void CControlerGMap::sauveDartVertex(std::ofstream &os, const CVertex & v,
201  const CVertex & /*v2*/)
202 {
203  int prof = MAX_PROF;
204 
205  os<<"1 3 0 "<<RAYON_DART_VERTEX<<" "<<32+COUL_DART_VERTEX
206  <<" "<<32+COUL_DART_VERTEX<<" "<<prof<<" 0 20 0.000 1 0.0000 ";
207 
208  os<<int(RINT(v.getX()+decalageX))<<" " // Centre x et y
209  <<int(RINT(v.getY()+decalageY))<<" "
210  <<RAYON<<" "<<RAYON<<" " //Rayon en x et en y
211  <<int(RINT(v.getX()+decalageX))<<" " // Premier point == centre
212  <<int(RINT(v.getY()+decalageY))<<" "
213  <<int(RINT(v.getX()+decalageX+RAYON))<<" " // deuxieme point (sur le cercle)
214  <<int(RINT(v.getY()+decalageY+RAYON))<<endl;
215 }
216 //******************************************************************************
217 void CControlerGMap::sauveLine(ofstream &os,
218  const CVertex & p1, const CVertex & p2,
219  int coul, int larg, bool arrow, int AProf)
220 {
221  int prof;
222 
223  if (AProf<0) prof = computeProf(p1,p2);
224  else prof = AProf;
225 
226  os<<"2 1 0 "<<larg<<" "<<32+coul<<" 0 "<< prof <<" 0 -1 0.000 1 0 7 ";
227  if (arrow)
228  {
229  os<<"1 0 2\n"
230  <<" 2 0 1.00 60.00 120.00\n";
231  }
232  else
233  os<<"0 0 2\n";
234 
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;
239 }
240 
241 //******************************************************************************
242 void CControlerGMap::sauveTriangle(ofstream & os, int coulFill, int larg,
243  CVertex & PC, CVertex & P1, CVertex & P2)
244 {
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;
248 
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;
257 }
258 //******************************************************************************
259 void CControlerGMap::sauveFace(ofstream &os, CVertex *p, int nbPts,
260  int coulFill, int larg, int AProf )
261 {
262  assert(nbPts>=3); // 3 => polygone à 2 arêtes...
263 
264  bool compactFaces = isZero(FMap->getBurstCoef(1) - 1.0);
265 
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 "
269  << nbPts << endl;
270 
271  for (int i=0; i<nbPts; ++i)
272  {
273  os << int(RINT(p[i].getX()+decalageX)) << " "
274  << int(RINT(p[i].getY()+decalageY)) << endl;
275  }
276 
277  /* Ancienne version de Fred qui sauvait des triangles => pb de profondeur... */
278  /*
279  CVertex baryFace;
280  int i;
281 
282  for (i=0; i<nbPts-1; ++i)
283  baryFace += p[i];
284 
285  baryFace /= nbPts-1;
286 
287  bool compactFaces = isZero(FMap->getBurstCoef(1) - 1.0);
288 
289  for (i=0; i<nbPts-1; ++i)
290  {
291  if (compactFaces || (i%2==0))
292  {
293  CVertex baryEdge = (p[i]+p[i+1])/2;
294 
295  sauveTriangle(os, coulFill, larg, baryFace, p[i] , baryEdge);
296  sauveTriangle(os, coulFill, larg, baryFace, baryEdge, p[i+1] );
297  }
298 
299  if (!compactFaces && (i%2==1))
300  sauveTriangle(os, coulFill, larg, baryFace, p[i], p[i+1]);
301 
302  }
303  */
304 }
305 
306 //******************************************************************************
307 void CControlerGMap::transfo3dTo2d( const CVertex & v3d, CVertex & v2d )
308 {
309  float res[3];
310 
311  FViews[FViewId]->project( v3d.getX(), v3d.getY(), v3d.getZ(), res);
312 
313  v2d.setX(res[0]); v2d.setY(res[1]); v2d.setZ(res[2]);
314 
315  transfoMmPixel(v2d);
316 
317  if (invertY) v2d.setY(-v2d.getY());
318 }
319 
320 //******************************************************************************
321 void CControlerGMap::updateMinMax2d( const CVertex & pts,
322  CVertex & min, CVertex & max, bool init )
323 {
324  CVertex tmp;
325  transfo3dTo2d(pts,tmp);
326 
327  if (init)
328  { min=tmp; max=tmp; }
329  else
330  {
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());
337  }
338 }
339 
340 //******************************************************************************
341 void CControlerGMap::getIncludingBoxForDarts( CDart* d, TOrbit orb,
342  CVertex & min, CVertex & max )
343 {
344  CCoverage* cov = FMap->getDynamicCoverage(d,orb);
345 
346  if (cov->cont())
347  {
348  transfo3dTo2d(FMap->getBurstVertex(d),min);
349  max=min;
350  ++(*cov);
351  }
352 
353  while(cov->cont())
354  {
355  updateMinMax2d(FMap->getBurstVertex(**cov),min,max);
356  ++(*cov);
357  }
358 
359  delete cov;
360 }
361 
362 #define WEIGHTING(k, v1,v2) ( (1-(k)) * (v1) + (k) * (v2) )
363 //******************************************************************************
364 void CControlerGMap::treatSews( ofstream & fout, CDart * dart,
365  int mark, int /*mark2*/ )
366 {
367  CDart *darti;
368  CVertex vTmp, v2Tmp, v3Tmp, p1, p2;
369 
370  for (int i=0; i<=3; ++i)
371  if (!FMap->isMarked(FMap->alpha(dart,i),mark))
372  {
373  darti= FMap->alpha(dart,i);
374  if (!FMap->isFree(dart,i) &&
375  getParameterSew(FViewId)->getDisplayAlpha(i))
376  {
377  if (i==0)
378  {
379  transfo3dTo2d(FMap->getBurstVertex(dart ), p1);
380  transfo3dTo2d(FMap->getBurstVertex(darti), p2);
381 
382  vTmp = (p1+p2)/2;
383 
384  int prof1 = computeProf(p1, vTmp);
385  int prof2 = computeProf(p2, vTmp);
386 
387  int prof = prof1<prof2 ? prof1 : prof2;
388 
389  if (prof<0) prof=0;
390  if (prof>MAX_PROF) prof=MAX_PROF;
391 
392  vTmp = (FMap->getBurstVertex(dart) +
393  FMap->getBurstVertex(darti))/2;
394 
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);
399 
400  sauveLine(fout,p1,p2,COUL_SEW[i],LARG_SEW[i],false, prof);
401  }
402  else
403  {
404  if ( FMap->isFree0(dart) || kw[i]!=1 || dart<FMap->alpha0(dart) )
405  {
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);
412 
413  sauveLine(fout,p1,p2,COUL_SEW[i],LARG_SEW[i],false);
414  }
415  }
416  }
417  }
418 }
419 
420 //******************************************************************************
421 void CControlerGMap::treatDartWithArrow( ofstream & fout, CDart * dart,
422  int /*mark*/, int mark2, int AProf )
423 {
424  CVertex v1;
425  CVertex v2,p1,p2;
426  int coul = COUL_DART;
427  int larg = LARG_DART;
428 
429  v1= FMap->getBurstVertex(dart);
430  transfo3dTo2d(v1, p1);
431 
432  if (FMap->isFree0(dart))
433  sauvePoint(fout,p1,COUL_DART_NO_SEW0,LARG_DART, AProf);
434  else
435  {
436  CDart *dart0=FMap->alpha0(dart);
437 
438  bool found = false;
439  int i;
440 
441  for (i=0; !found && i<getNbSelectionLevels(); ++i)
442  if (dart==getLastSelectedDart(i) || dart0==getLastSelectedDart(i))
443  {
444  coul=COUL_LAST[i];
445  larg=LARG_LAST[i];
446  found = true;
447  }
448 
449  for (i=0; !found && i<getNbSelectionLevels(); ++i)
450  if (isDartSelected(dart,i) || isDartSelected(dart0, i))
451  {
452  coul=COUL_SEL[i];
453  larg=LARG_SEL[i];
454  found = true;
455  }
456 
457  v1= FMap->getBurstVertex(dart0);
458  transfo3dTo2d(v1, p2);
459 
460  if (FMap->isMarked(dart,mark2))
461  {
462  sauveLine(fout,p1,p2,coul,larg,true, AProf);
463  if ( drawVertices )
464  sauveDartVertex( fout, p1, p2 );
465  }
466  else
467  {
468  sauveLine(fout,p2,p1,coul,larg,true, AProf);
469  if ( drawVertices )
470  sauveDartVertex( fout, p2, p1 );
471  }
472  }
473 }
474 
475 //******************************************************************************
476 void CControlerGMap::treatDartNoArrow( ofstream & fout, CDart * dart,
477  int /*mark*/, int /*mark2*/ )
478 {
479  CVertex v1;
480  CVertex v2,p1,p2;
481  int coul = COUL_DART;
482  int larg = LARG_DART;
483 
484  bool found = false;
485  int i;
486 
487  for (i=0; !found && i<getNbSelectionLevels(); ++i)
488  if (dart==getLastSelectedDart(i))
489  {
490  coul=COUL_LAST[i];
491  larg=LARG_LAST[i];
492  found = true;
493  }
494 
495  for (i=0; !found && i<getNbSelectionLevels(); ++i)
496  if (isDartSelected(dart,i))
497  {
498  coul=COUL_SEL[i];
499  larg=LARG_SEL[i];
500  found = true;
501  }
502 
503  v1= FMap->getBurstVertex(dart);
504  transfo3dTo2d(v1, p1);
505 
506  if (FMap->isFree0(dart))
507  sauvePoint(fout,p1,COUL_DART_NO_SEW0,LARG_DART);
508  else
509  {
510  CDart *dart0 = FMap->alpha0(dart);
511 
512  transfo3dTo2d(FMap->getBurstVertex(dart ), p1);
513  transfo3dTo2d(FMap->getBurstVertex(dart0), p2);
514  CVertex p0 = (p1+p2)/2;
515 
516  v2=FMap->computeBurstExtremity(dart);
517  transfo3dTo2d(v2, p2);
518  sauveLine(fout,p1,p2,coul,larg,false, computeProf(p1,p0));
519 
520  coul=COUL_DART; larg=LARG_DART;
521 
522  bool found = false;
523  int i;
524 
525  for (i=0; !found && i<getNbSelectionLevels(); ++i)
526  if (dart0==getLastSelectedDart(i))
527  {
528  coul=COUL_LAST[i];
529  larg=LARG_LAST[i];
530  found = true;
531  }
532 
533  for (i=0; !found && i<getNbSelectionLevels(); ++i)
534  if (isDartSelected(dart0,i))
535  {
536  coul=COUL_SEL[i];
537  larg=LARG_SEL[i];
538  found = true;
539  }
540 
541  v1= FMap->getBurstVertex(dart0);
542  transfo3dTo2d(v1, p1);
543 
544  v2=FMap->computeBurstExtremity(dart0);
545  transfo3dTo2d(v2, p2);
546  sauveLine(fout,p1,p2,coul,larg,false, computeProf(p1,p0));
547 
548  if ( drawVertices )
549  sauveDartVertex( fout, p1, p2);
550  }
551 }
552 
553 //******************************************************************************
554 void CControlerGMap::treatFace( ofstream & fout, CDart * initDart,
555  int mark, int mark2 )
556 {
557  CDart *dart;
558 
559  // On parcours ici la face
560  CDynamicCoverage01 covF(FMap,initDart);
561  while ( covF.cont() )
562  {
563  if ( !FMap->isMarked(*covF,mark) ) //brin non encore parcouru
565  {
566  assert(!FMap->isMarked(FMap->alpha0(*covF),mark));
567  dart=*covF;
568 
569  if (drawArrows) treatDartWithArrow(fout,dart,mark,mark2);
570  else treatDartNoArrow(fout,dart,mark,mark2);
571 
572  if (drawSews)
573  {
574  treatSews(fout,dart,mark,mark2);
575  if (!FMap->isFree0(dart))
576  treatSews(fout,FMap->alpha0(dart),mark,mark2);
577  }
578 
579  FMap->setMark(dart,mark);
580  FMap->setMark(FMap->alpha0(dart),mark);
581  }
582  ++covF;
583  } // Fin de parcours de face
584 }
585 
586 //******************************************************************************
587 void CControlerGMap::treatFilledFace( ofstream & fout, CDart * dart,
588  int mark, int mark2 )
589 {
590  int nbPts=0;
591  CVertex v1;
592 
593  if (drawArrows && FMap->isMarked(dart,mark2))
594  dart=FMap->alpha0(dart);
595 
596  // On parcours ici la face
597  CDynamicCoverage01 covF(FMap,dart);
598  while ( covF.cont() )
599  {
600  ++nbPts;
601  if (FMap->isFree0(*covF) || FMap->isFree1(*covF))
602  {
603  treatFace(fout,dart,mark,mark2); // si la face n'est pas
604  return; // fermée, on ne peut pas la dessiner pleine !!!
605  }
606  ++covF;
607  }
608 
609  bool compactFaces = isZero(FMap->getBurstCoef(1) - 1.0);
610 
611  if (compactFaces)
612  nbPts/=2; //car en g carte donc on alpha compte les sommets 2 fois
613 
614  CVertex baryFace;
615  CVertex * tabV = new CVertex[nbPts+1];
616  nbPts=0;
617 
618  for (covF.reinit(); covF.cont();)
619  {
620  v1= FMap->getBurstVertex(*covF);
621  transfo3dTo2d(v1, tabV[nbPts++]);
622  baryFace += tabV[nbPts-1];
623 
624  if (compactFaces && covF.cont())
625  ++covF;
626 
627  if (covF.cont())
628  ++covF;
629  }
630 
631  baryFace -= tabV[nbPts-1];
632  baryFace /= nbPts-1;
633 
634  for (covF.reinit(); covF.cont();)
635  {
636  if ( compactFaces ) // Ici on marque, sinon c'est fait dans la méthode treatFace
637  {
638  if (drawArrows)
639  {
640  treatDartWithArrow(fout,*covF,mark,mark2,computeProf(baryFace));
641  }
642 
643  if (drawSews)
644  {
645  treatSews(fout,*covF,mark,mark2);
646  if (!FMap->isFree0(*covF))
647  treatSews(fout,FMap->alpha0(*covF),mark,mark2);
648  }
649 
650  FMap->setMark(*covF,mark);
651  FMap->setMark(FMap->alpha0(*covF),mark);
652  }
653 
654  if (compactFaces && covF.cont())
655  ++covF;
656 
657  if (covF.cont())
658  ++covF;
659  }
660 
661  tabV[nbPts++] = tabV[0];
662 
663  // On commence par sauver la face externe
664  if ( !compactFaces )
665  treatFace(fout,dart,mark,mark2);
666 
667  sauveFace(fout,tabV,nbPts,COUL_FILL_FACE,LARG_FILL_FACE,computeProf(baryFace));
668 
669  delete []tabV;
670 }
671 
672 //******************************************************************************
673 void CControlerGMap::saveGridIncludingBox( ofstream & fout )
674 {
675  CVertex v1, v2, p1, p2;
676  CVertex vmin(0,0,0), vmax(0,0,0);
677  bool init=true;
678 
679  // Axis:
680  {
681  // X
682  v1=CVertex(0,0,0); updateMinMax2d(v1,vmin,vmax,init); init=false;
683  v1=CVertex(1,0,0); updateMinMax2d(v1,vmin,vmax,init);
684  // Y
685  v1=CVertex(0,1,0); updateMinMax2d(v1,vmin,vmax,init);
686  // Z
687  v1=CVertex(0,0,1); updateMinMax2d(v1,vmin,vmax,init);
688  }
689 
690  // Grid:
691  {
692  int size= getParameterGrid(FViewId)->getLGGrid();
693  bool xy = getParameterGrid(FViewId)->getDisplayGridXY();
694  bool xz = getParameterGrid(FViewId)->getDisplayGridXZ();
695  bool yz = getParameterGrid(FViewId)->getDisplayGridYZ();
696  bool px = getParameterGrid(FViewId)->getDisplayPositiveGridX();
697  bool py = getParameterGrid(FViewId)->getDisplayPositiveGridY();
698  bool pz = getParameterGrid(FViewId)->getDisplayPositiveGridZ();
699  int xmin= px ? 0 : -size;
700  int ymin= py ? 0 : -size;
701  int zmin= pz ? 0 : -size;
702 
703  for (int i=-size; i<=+size; ++i)
704  {
705  if (xy)
706  {
707  /* X direction: */
708  if (i>=0 || !py)
709  {
710  v1=CVertex(xmin, i, 0); updateMinMax2d(v1,vmin,vmax,init);
711  init=false;
712  v1=CVertex(size, i, 0); updateMinMax2d(v1,vmin,vmax,init);
713  }
714  /* Y direction: */
715  if (i>=0 || !px)
716  {
717  v1=CVertex(i, ymin, 0); updateMinMax2d(v1,vmin,vmax,init);
718  init=false;
719  v1=CVertex(i, size, 0); updateMinMax2d(v1,vmin,vmax,init);
720  }
721  }
722  if (xz)
723  {
724  /* X direction: */
725  if (i>=0 || !pz)
726  {
727  v1=CVertex(xmin, 0, i); updateMinMax2d(v1,vmin,vmax,init);
728  init=false;
729  v1=CVertex(size, 0, i); updateMinMax2d(v1,vmin,vmax,init);
730  }
731  /* Z direction: */
732  if (i>=0 || !px)
733  {
734  v1=CVertex(i, 0, zmin); updateMinMax2d(v1,vmin,vmax,init);
735  init=false;
736  v1=CVertex(i, 0, size); updateMinMax2d(v1,vmin,vmax,init);
737  }
738  }
739  if (yz)
740  {
741  /* Y direction: */
742  if (i>=0 || !pz)
743  {
744  v1=CVertex(0, ymin, i); updateMinMax2d(v1,vmin,vmax,init);
745  init=false;
746  v1=CVertex(0, size, i);updateMinMax2d(v1,vmin,vmax,init);
747  }
748  /* Z direction: */
749  if (i>=0 || !py)
750  {
751  v1=CVertex(0, i, zmin); updateMinMax2d(v1,vmin,vmax,init);
752  init=false;
753  v1=CVertex(0, i, size); updateMinMax2d(v1,vmin,vmax,init);
754  }
755  }
756  }
757  }
758 
759  debutComposante(fout,vmin,vmax);
760 }
761 
762 //******************************************************************************
763 void CControlerGMap::treatGrid(ofstream & fout)
764 {
765  CVertex v1, v2, p1, p2;
766 
767  saveGridIncludingBox(fout);
768 
769  // Axis:
770  {
771  // X
772  v1=CVertex(0,0,0);
773  v2=CVertex(1,0,0);
774  transfo3dTo2d(v1,p1); transfo3dTo2d(v2,p2);
775  sauveLine(fout,p1,p2,COUL_AXE_X,LARG_AXE_X,false);
776  // Y
777  v2=CVertex(0,1,0);
778  transfo3dTo2d(v2,p2);
779  sauveLine(fout,p1,p2,COUL_AXE_Y,LARG_AXE_Y,false);
780  // Z
781  v2=CVertex(0,0,1);
782  transfo3dTo2d(v2,p2);
783  sauveLine(fout,p1,p2,COUL_AXE_Z,LARG_AXE_Z,false);
784  }
785 
786  // Grid:
787  {
788  int size= getParameterGrid(FViewId)->getLGGrid();
789  bool xy = getParameterGrid(FViewId)->getDisplayGridXY();
790  bool xz = getParameterGrid(FViewId)->getDisplayGridXZ();
791  bool yz = getParameterGrid(FViewId)->getDisplayGridYZ();
792  bool px = getParameterGrid(FViewId)->getDisplayPositiveGridX();
793  bool py = getParameterGrid(FViewId)->getDisplayPositiveGridY();
794  bool pz = getParameterGrid(FViewId)->getDisplayPositiveGridZ();
795  int xmin= px ? 0 : -size;
796  int ymin= py ? 0 : -size;
797  int zmin= pz ? 0 : -size;
798 
799  for (int i=-size; i<=+size; ++i)
800  {
801  if (xy)
802  {
803  /* X direction: */
804  if (i>=0 || !py)
805  {
806  v1=CVertex(xmin, i, 0); v2=CVertex(size, i, 0);
807  transfo3dTo2d(v1,p1); transfo3dTo2d(v2,p2);
808  sauveLine(fout,p1,p2,COUL_GRID,LARG_GRID,false);
809  }
810  /* Y direction: */
811  if (i>=0 || !px)
812  {
813  v1=CVertex(i, ymin, 0); v2=CVertex(i, size, 0);
814  transfo3dTo2d(v1,p1); transfo3dTo2d(v2,p2);
815  sauveLine(fout,p1,p2,COUL_GRID,LARG_GRID,false);
816  }
817  }
818  if (xz)
819  {
820  /* X direction: */
821  if (i>=0 || !pz)
822  {
823  v1=CVertex(xmin, 0, i); v2=CVertex(size, 0, i);
824  transfo3dTo2d(v1,p1); transfo3dTo2d(v2,p2);
825  sauveLine(fout,p1,p2,COUL_GRID,LARG_GRID,false);
826  }
827  /* Z direction: */
828  if (i>=0 || !px)
829  {
830  v1=CVertex(i, 0, zmin); v2=CVertex(i, 0, size);
831  transfo3dTo2d(v1,p1); transfo3dTo2d(v2,p2);
832  sauveLine(fout,p1,p2,COUL_GRID,LARG_GRID,false);
833  }
834  }
835  if (yz)
836  {
837  /* Y direction: */
838  if (i>=0 || !pz)
839  {
840  v1=CVertex(0, ymin, i); v2=CVertex(0, size, i);
841  transfo3dTo2d(v1,p1); transfo3dTo2d(v2,p2);
842  sauveLine(fout,p1,p2,COUL_GRID,LARG_GRID,false);
843  }
844  /* Z direction: */
845  if (i>=0 || !py)
846  {
847  v1=CVertex(0, i, zmin); v2=CVertex(0, i, size);
848  transfo3dTo2d(v1,p1); transfo3dTo2d(v2,p2);
849  sauveLine(fout,p1,p2,COUL_GRID,LARG_GRID,false);
850  }
851  }
852  }
853  }
854  fout<<"-6"<<endl;
855 }
856 
857 //******************************************************************************
858 void CControlerGMap::sauveCarteXfig( TViewId AViewId, ofstream & AFout,
859  bool AArrow, bool AFace, bool ASews,
860  bool AGrid, bool AVertices, bool AInvert )
861 {
862  CVertex min, max, vTmp, v2Tmp, v3Tmp;
863  CVertex v1;
864 
865  FViewId = AViewId;
866  drawArrows = AArrow;
867  drawFaces = AFace;
868  drawSews = ASews;
869  drawGrid = AGrid;
870  drawVertices = AVertices;
871  invertY = AInvert;
872 
873  // Initialisation for draw the sew
874  k0 = FMap->getBurstCoef(0);
875  for (int i=0; i<4; i++) kw[i]= getParameterSew(FViewId)->getSewPosCoef(i);
876 
877 //******************************************************************************
878  sauveEntete(AFout,NB_COUL_USER); //Nombre de couleur ?
879  // une brin, une pour chaque couture...
880  // Pour les 2 selections, pour les 2 last dart, ...
881 
882 //******************************************************************************
883  CDynamicCoverageAll it(FMap);
884 
885  v1 = FMap->getBurstVertex(*it);
886  transfo3dTo2d(v1,min);
887  max = min;
888 
889  while ( it.cont() )
890  {
891  v1= FMap->getBurstVertex(it++);
892  updateMinMax2d(v1,min,max);
893  }
894 
895  // Here min and max define the including box in 2d of the burst map.
896  decalageX=5-min.getX();
897  decalageY=5-min.getY();
898  coefMultProf=MAX_PROF/(max.getZ()-min.getZ());
899  profMin=min.getZ();
900 
902  if (drawGrid)
903  treatGrid(AFout);
904 
905 //******************************************************************************
906  int mark=FMap->getNewMark();
907  int mark2=FMap->getNewMark(); // Used for orientation
908 
909  it.reinit();
910  while ( it.cont() )
911  {
912  if (!FMap->isMarked(*it,mark)) //brin non encore parcouru
913  {
914  // On parcours la composante connexe incidente
915  CDynamicCoverage0123 cov(FMap,*it);
916  while ( cov.cont() )
917  {
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);
924  ++cov;
925  }
926  }
927  ++it;
928  }
929 
930  FMap->negateMaskMark(mark);
931 
932  // On parcours tout les brins
933  it.reinit();
934  while ( it.cont() )
935  {
936  if (!FMap->isMarked(*it,mark)) //brin non encore parcouru
937  {
938  // On parcours la composante connexe incidente
939  getIncludingBoxForDarts(*it,ORBIT_0123,min,max);
940  debutComposante(AFout,min,max);
941 
942  CDynamicCoverage0123 covCc(FMap,*it);
943  while ( covCc.cont() )
944  {
945  if (!FMap->isMarked(*covCc,mark)) //brin non encore parcouru
946  {
947  getIncludingBoxForDarts(*covCc,ORBIT_012,min,max);
948  debutComposante(AFout,min,max);
949 
950  // On parcours le volume incident
951  CDynamicCoverageVolume covV(FMap,*covCc);
952  while ( covV.cont() )
953  {
954  if (!FMap->isMarked(*covV,mark)) //brin non traité
955  {
956  getIncludingBoxForDarts(*covV,ORBIT_01,min,max);
957  debutComposante(AFout,min,max);
958 
959  if (AFace)
960  treatFilledFace(AFout,*covV,mark,mark2);
961  else
962  treatFace(AFout,*covV,mark,mark2);
963 
964  AFout<<"-6\n"; //pour fermer la composante xfig
965  } //Fin du parcours d'une region
966  ++covV;
967  } // Fin du parcours d'un volume
968  AFout<<"-6\n"; //pour fermer la composante xfig
969  }
970  ++covCc;
971  } // Fin du parcours de tout
972  AFout<<"-6\n"; //pour fermer la composante xfig
973  }
974  ++it;
975  }
976 
977  FMap->negateMaskMark(mark);
978  FMap->freeMark(mark);
979  FMap->unmarkAll(mark2);
980  FMap->freeMark(mark2);
981 }
982 //******************************************************************************
983 void CControlerGMap::treatPointel(ofstream &os, CDart *d, int mark)
984 {
985  CDynamicCoverage123 it(FMap,d);
986  while(it.cont()) FMap->setMark(it++,mark);
987 
988  CVertex *v1 = FMap->findVertex(d);
989 
990  CVertex p1;
991  transfo3dTo2d(*v1, p1);
992 
993  sauvePoint(os,p1,COUL_POINTEL,RAYON_POINTEL);
994 }
995 //******************************************************************************
996 void CControlerGMap::treatLignel(ofstream &os, CDart *d, int mark)
997 {
998  CDynamicCoverage023 it(FMap,d);
999  while(it.cont()) FMap->setMark(it++,mark);
1000 
1001  CVertex *v1 = FMap->findVertex(d);
1002  CVertex *v2 = FMap->findVertex(FMap->alpha0(d));
1003 
1004  CVertex edgeBary= (*v1 + *v2)/2;
1005 
1006  CVertex p1 = edgeBary + COEF_REDUC_LIGNEL*(*v1-edgeBary);
1007  CVertex p2 = edgeBary + COEF_REDUC_LIGNEL*(*v2-edgeBary);
1008 
1009  CVertex pp1, pp2;
1010  transfo3dTo2d(p1, pp1);
1011  transfo3dTo2d(p2, pp2);
1012 
1013  sauveLine(os,pp1,pp2,COUL_LIGNEL,LARG_LIGNEL,false);
1014 }
1015 //******************************************************************************
1016 // Ici on sauve toujours en face pleine, sans fleche, mais avec les
1017 // elements intervoxels, cad les lignels et les pointels, et sans
1018 // coutures.
1020  ofstream & AFout,
1021  bool AInvert )
1022 {
1023  CVertex min, max, vTmp, v2Tmp, v3Tmp;
1024  CVertex v1;
1025 
1026  FViewId = AViewId;
1027  invertY = AInvert;
1028 
1029  k0= FMap->getBurstCoef(0);
1030 
1031  drawArrows = false;
1032 
1033 //******************************************************************************
1034  sauveEntete(AFout,NB_COUL_USER); //Nombre de couleur ?
1035  // une brin, une pour chaque couture...
1036  // Pour les 2 selections, pour les 2 last dart, ...
1037 
1038 //******************************************************************************
1039  CDynamicCoverageAll it(FMap);
1040 
1041  v1= FMap->getBurstVertex(*it);
1042  transfo3dTo2d(v1,min);
1043  max=min;
1044 
1045  while ( it.cont() )
1046  {
1047  v1= FMap->getBurstVertex(it++);
1048  updateMinMax2d(v1,min,max);
1049  }
1050 
1051  // Here min and max define the including box in 2d of the burst map.
1052  decalageX=5-min.getX();
1053  decalageY=5-min.getY();
1054  coefMultProf=MAX_PROF/(max.getZ()-min.getZ());
1055  profMin=min.getZ();
1056 
1057 //******************************************************************************
1058  int mark = FMap->getNewMark();
1059  int mark2 = FMap->getNewMark();
1060  int mark3 = FMap->getNewMark();
1061 
1062  // On parcours tout les brins
1063  it.reinit();
1064  while ( it.cont() )
1065  {
1066  if (!FMap->isMarked(*it,mark)) //brin non encore parcouru
1067  {
1068  // On parcours la composante connexe incidente
1069  getIncludingBoxForDarts(*it,ORBIT_0123,min,max);
1070  debutComposante(AFout,min,max);
1071 
1072  CDynamicCoverage0123 covCc(FMap,*it);
1073  while ( covCc.cont() )
1074  {
1075  if (!FMap->isMarked(*covCc,mark)) //brin non encore parcouru
1076  {
1077  getIncludingBoxForDarts(*covCc,ORBIT_012,min,max);
1078  debutComposante(AFout,min,max);
1079 
1080  // On parcours le volume incident
1081  CDynamicCoverageVolume covV(FMap,*covCc);
1082  while ( covV.cont() )
1083  {
1084  if (!FMap->isMarked(*covV,mark)) //brin non traité
1085  {
1086  getIncludingBoxForDarts(*covV,ORBIT_01,min,max);
1087  debutComposante(AFout,min,max);
1088 
1089  treatFilledFace(AFout,*covV,mark,0);
1090 
1091  AFout<<"-6\n"; //pour fermer la composante xfig
1092  } //Fin du parcours d'une region
1093  ++covV;
1094  } // Fin du parcours d'un volume
1095  AFout<<"-6\n"; //pour fermer la composante xfig
1096  }
1097  ++covCc;
1098  } // Fin du parcours de tout
1099  AFout<<"-6\n"; //pour fermer la composante xfig
1100  }
1101 
1102  if (!FMap->isMarked(*it,mark2))
1103  treatLignel(AFout,*it,mark2);
1104 
1105  if (!FMap->isMarked(*it,mark3))
1106  treatPointel(AFout,*it,mark3);
1107 
1108  ++it;
1109  }
1110 
1111  FMap->negateMaskMark(mark);
1112  FMap->freeMark(mark);
1113  FMap->negateMaskMark(mark2);
1114  FMap->freeMark(mark2);
1115  FMap->negateMaskMark(mark3);
1116  FMap->freeMark(mark3);
1117 }
1118 
1119 #undef WEIGHTING
1120 //******************************************************************************