Moka libraries
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
rounding-interface.cc
Go to the documentation of this file.
1 /*
2  * lib-rounding : Opérations de chamfreinage.
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-rounding
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 //******************************************************************************
25 #include "rounding-interface.hh"
26 #include "g-map-vertex.hh"
27 #include "geometry.hh"
28 #include <list>
29 #include <cstdlib>
30 #include <cassert>
31 using namespace GMap3d;
32 using namespace std;
33 //******************************************************************************
35  FMap(AMap),
36  FRounding(AMap)
37 {
38  assert(FMap != NULL);
39 }
40 //------------------------------------------------------------------------------
42 {
43 }
44 //******************************************************************************
46  int ADimension,
47  const TCoordinate& ACoef)
48 {
49  assert(ADimension==0 || ADimension==1);
50 
51  int selection = FMap->getNewMark();
52  static const TOrbit propag[2] = { ORBIT_23, ORBIT_3 };
53  FMap->markIncidentCells(propag[ADimension], AMarkNumber, selection);
54 
55  for (CDynamicCoverageAll it(FMap); it.cont(); ++it)
56  if (FMap->isMarked(*it, selection))
57  {
58  FRounding.setDartRoundingCoef(*it, ADimension, ACoef);
59  FMap->unsetMark(*it, selection);
60  }
61 
62  FMap->freeMark(selection);
63 }
64 //------------------------------------------------------------------------------
66  int ADimension,
67  TCoordinate& AAverage)
68 {
69  AAverage = 0.0;
70  int nb = 0;
71 
72  TCoordinate value=0;
73  bool found = false;
74  bool same = true;
75 
76  for (CDynamicCoverageAll it(FMap); it.cont(); ++it)
77  if (FMap->isMarked(*it, AMarkNumber))
78  {
79  TCoordinate coef = FRounding.getDartRoundingCoef(*it, ADimension);
80 
81  ++nb;
82  AAverage += coef;
83 
84  if (found)
85  {
86  if (same && !areEqual(coef, value))
87  same = false;
88  }
89  else
90  {
91  value = coef;
92  found = true;
93  }
94  }
95 
96  if (nb==0)
97  same = false;
98 
99  AAverage = nb==0 ? 0.0 : AAverage / nb;
100  return same;
101 }
102 //------------------------------------------------------------------------------
103 TCoordinate CRoundingInterface::selectNextRoundingCoef(int AMarkNumber,
104  int ADimension)
105 {
106  /* Lister les coefficients actuels (en o(n^2), mais bon...) et
107  * trouver le premier brin marqué avec la marque AMarkNumber :
108  */
109  list<CDart*> coefs;
110  CDart* firstSelected = NULL;
111  int treated = FMap->getNewMark();
112  CDynamicCoverageAll it(FMap);
113 
114  for (; it.cont(); ++it)
115  {
116  if (firstSelected == NULL && FMap->isMarked(*it, AMarkNumber))
117  firstSelected = *it;
118 
119  if (!FMap->isMarked(*it, treated))
120  {
121  TCoordinate coef = FRounding.getDartRoundingCoef(*it, ADimension);
122  coefs.push_back(*it);
123 
124  for (CDynamicCoverageAll all(FMap); all.cont(); ++all)
125  if (areEqual(FRounding.getDartRoundingCoef(*all, ADimension), coef))
126  FMap->setMark(*all, treated);
127  }
128  }
129 
130  FMap->negateMaskMark(treated);
131  FMap->freeMark(treated);
132 
133  if (coefs.size() == 0)
134  return 0.0; // Cas où la carte est vide.
135 
136  list<CDart*>::iterator itCoefs = coefs.begin();
137 
138  if (firstSelected != NULL)
139  {
140  // Chercher le coefficient actuel :
141  TCoordinate actu =
142  FRounding.getDartRoundingCoef(firstSelected, ADimension);
143 
144  while (! areEqual(FRounding.getDartRoundingCoef(*itCoefs, ADimension),
145  actu))
146  {
147  ++itCoefs;
148  assert(itCoefs != coefs.end());
149  }
150 
151  // Passer au coefficient suivant :
152  ++itCoefs;
153 
154  if (itCoefs == coefs.end())
155  itCoefs = coefs.begin();
156  }
157 
158  TCoordinate newValue = FRounding.getDartRoundingCoef(*itCoefs, ADimension);
159 
160  for (it.reinit(); it.cont(); ++it)
161  FMap->setMarkTo(*it, AMarkNumber,
162  areEqual(FRounding.getDartRoundingCoef(*it, ADimension),
163  newValue));
164 
165  return newValue;
166 }
167 //******************************************************************************
168 int CRoundingInterface::roundMarkedVertices(int AMarkNumber, bool ADig)
169 {
170  return FRounding.roundMarkedVertices(AMarkNumber, ADig);
171 }
172 //------------------------------------------------------------------------------
174  bool A3D, bool ADig, bool ASetback)
175 {
176  return FRounding.roundMarkedEdges(AMarkNumber, A3D, ADig, ASetback);
177 }
178 //******************************************************************************