00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "rounding-interface.hh"
00026 #include "g-map-vertex.hh"
00027 #include "geometry.hh"
00028 #include <list>
00029 #include <cstdlib>
00030 #include <cassert>
00031 using namespace GMap3d;
00032 using namespace std;
00033
00034 CRoundingInterface::CRoundingInterface(CGMapVertex* AMap) :
00035 FMap(AMap),
00036 FRounding(AMap)
00037 {
00038 assert(FMap != NULL);
00039 }
00040
00041 CRoundingInterface::~CRoundingInterface()
00042 {
00043 }
00044
00045 void CRoundingInterface::setRoundingCoefOfMarkedDarts(int AMarkNumber,
00046 int ADimension,
00047 const TCoordinate& ACoef)
00048 {
00049 assert(ADimension==0 || ADimension==1);
00050
00051 int selection = FMap->getNewMark();
00052 static const TOrbit propag[2] = { ORBIT_23, ORBIT_3 };
00053 FMap->markIncidentCells(propag[ADimension], AMarkNumber, selection);
00054
00055 for (CDynamicCoverageAll it(FMap); it.cont(); ++it)
00056 if (FMap->isMarked(*it, selection))
00057 {
00058 FRounding.setDartRoundingCoef(*it, ADimension, ACoef);
00059 FMap->unsetMark(*it, selection);
00060 }
00061
00062 FMap->freeMark(selection);
00063 }
00064
00065 bool CRoundingInterface::getRoundingCoefOfMarkedDarts(int AMarkNumber,
00066 int ADimension,
00067 TCoordinate& AAverage)
00068 {
00069 AAverage = 0.0;
00070 int nb = 0;
00071
00072 TCoordinate value=0;
00073 bool found = false;
00074 bool same = true;
00075
00076 for (CDynamicCoverageAll it(FMap); it.cont(); ++it)
00077 if (FMap->isMarked(*it, AMarkNumber))
00078 {
00079 TCoordinate coef = FRounding.getDartRoundingCoef(*it, ADimension);
00080
00081 ++nb;
00082 AAverage += coef;
00083
00084 if (found)
00085 {
00086 if (same && !areEqual(coef, value))
00087 same = false;
00088 }
00089 else
00090 {
00091 value = coef;
00092 found = true;
00093 }
00094 }
00095
00096 if (nb==0)
00097 same = false;
00098
00099 AAverage = nb==0 ? 0.0 : AAverage / nb;
00100 return same;
00101 }
00102
00103 TCoordinate CRoundingInterface::selectNextRoundingCoef(int AMarkNumber,
00104 int ADimension)
00105 {
00106
00107
00108
00109 list<CDart*> coefs;
00110 CDart* firstSelected = NULL;
00111 int treated = FMap->getNewMark();
00112 CDynamicCoverageAll it(FMap);
00113
00114 for (; it.cont(); ++it)
00115 {
00116 if (firstSelected == NULL && FMap->isMarked(*it, AMarkNumber))
00117 firstSelected = *it;
00118
00119 if (!FMap->isMarked(*it, treated))
00120 {
00121 TCoordinate coef = FRounding.getDartRoundingCoef(*it, ADimension);
00122 coefs.push_back(*it);
00123
00124 for (CDynamicCoverageAll all(FMap); all.cont(); ++all)
00125 if (areEqual(FRounding.getDartRoundingCoef(*all, ADimension), coef))
00126 FMap->setMark(*all, treated);
00127 }
00128 }
00129
00130 FMap->negateMaskMark(treated);
00131 FMap->freeMark(treated);
00132
00133 if (coefs.size() == 0)
00134 return 0.0;
00135
00136 list<CDart*>::iterator itCoefs = coefs.begin();
00137
00138 if (firstSelected != NULL)
00139 {
00140
00141 TCoordinate actu =
00142 FRounding.getDartRoundingCoef(firstSelected, ADimension);
00143
00144 while (! areEqual(FRounding.getDartRoundingCoef(*itCoefs, ADimension),
00145 actu))
00146 {
00147 ++itCoefs;
00148 assert(itCoefs != coefs.end());
00149 }
00150
00151
00152 ++itCoefs;
00153
00154 if (itCoefs == coefs.end())
00155 itCoefs = coefs.begin();
00156 }
00157
00158 TCoordinate newValue = FRounding.getDartRoundingCoef(*itCoefs, ADimension);
00159
00160 for (it.reinit(); it.cont(); ++it)
00161 FMap->setMarkTo(*it, AMarkNumber,
00162 areEqual(FRounding.getDartRoundingCoef(*it, ADimension),
00163 newValue));
00164
00165 return newValue;
00166 }
00167
00168 int CRoundingInterface::roundMarkedVertices(int AMarkNumber, bool ADig)
00169 {
00170 return FRounding.roundMarkedVertices(AMarkNumber, ADig);
00171 }
00172
00173 int CRoundingInterface::roundMarkedEdges(int AMarkNumber,
00174 bool A3D, bool ADig, bool ASetback)
00175 {
00176 return FRounding.roundMarkedEdges(AMarkNumber, A3D, ADig, ASetback);
00177 }
00178