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 "g-map-vertex.hh"
00026 #include "geometry.hh"
00027 using namespace GMap3d;
00028
00029 void CGMapVertex::applyMatrix(const CTransformationMatrix & AMatrix, CDart * ADart,
00030 TOrbit AOrbit, int ADirectInfoVertex)
00031 {
00032 assert(ADart!=NULL);
00033
00034 int mark= getNewMark();
00035
00036 markOrbit(ADart, AOrbit, mark);
00037 applyMatrix(AMatrix, mark, ADirectInfoVertex);
00038 unmarkOrbit(ADart, AOrbit, mark);
00039
00040 freeMark(mark);
00041 }
00042
00043 void CGMapVertex::applyMatrix(const CTransformationMatrix & AMatrix,
00044 int AMarkNumber, int ADirectInfoVertex)
00045 {
00046 int treated = getNewMark();
00047
00048 for (CDynamicCoverageAll it(this); it.cont(); ++it)
00049 if (!isMarked(*it, treated))
00050 {
00051 if (isMarked(*it, AMarkNumber))
00052 for (CDynamicCoverageVertex cov(this, *it); cov.cont(); ++cov)
00053 {
00054 setMark(*cov, treated);
00055
00056 if (isOrbitUsed(*cov, ORBIT_VERTEX))
00057 {
00058 CVertex * Vdest = getVertex(*cov);
00059 assert(Vdest!=NULL);
00060
00061 CVertex * Vsrce =
00062 ADirectInfoVertex<0 ? Vdest :
00063 getDirectInfoAsVertex(*cov, ADirectInfoVertex);
00064 assert(Vsrce!=NULL);
00065
00066 AMatrix.applyOn(*Vsrce, *Vdest);
00067 }
00068 }
00069 else
00070 setMark(*it, treated);
00071 }
00072
00073 negateMaskMark(treated);
00074 freeMark(treated);
00075 }
00076
00077 #define SET_VALUE(DART, INDEX, VALUE) \
00078 ((* getDirectInfoAsCoord(DART, INDEX)) = (VALUE))
00079
00080 void CGMapVertex::computeDistanceToVertex(int AMarkNumber, int ADirectInfoIndex,
00081 const CVertex & AVertex)
00082 {
00083 int treated = getNewMark();
00084
00085 for (CDynamicCoverageAll it(this); it.cont(); ++it)
00086 if (!isMarked(*it, treated))
00087 {
00088 if (isMarked(*it, AMarkNumber))
00089 for (CDynamicCoverageVertex cov(this, *it); cov.cont(); ++cov)
00090 {
00091 setMark(*cov, treated);
00092
00093 if (isOrbitUsed(*cov, ORBIT_VERTEX))
00094 {
00095 CVertex * vertex = getVertex(*cov);
00096 assert(vertex!=NULL);
00097
00098 SET_VALUE(*cov, ADirectInfoIndex,
00099 CGeometry::distanceToVertex(*vertex, AVertex));
00100 }
00101 }
00102 else
00103 setMark(*it, treated);
00104 }
00105
00106 negateMaskMark(treated);
00107 freeMark(treated);
00108 }
00109
00110 void CGMapVertex::computeDistanceToLine(int AMarkNumber, int ADirectInfoIndex,
00111 const CVertex & ALineVertex,
00112 const CVertex & ALineDirection)
00113 {
00114 assert(!ALineDirection.isNull());
00115
00116 int treated = getNewMark();
00117
00118 for (CDynamicCoverageAll it(this); it.cont(); ++it)
00119 if (!isMarked(*it, treated))
00120 {
00121 if (isMarked(*it, AMarkNumber))
00122 for (CDynamicCoverageVertex cov(this, *it); cov.cont(); ++cov)
00123 {
00124 setMark(*cov, treated);
00125
00126 if (isOrbitUsed(*cov, ORBIT_VERTEX))
00127 {
00128 CVertex * vertex = getVertex(*cov);
00129 assert(vertex!=NULL);
00130
00131 SET_VALUE(*cov, ADirectInfoIndex,
00132 CGeometry::distanceToLine(*vertex,
00133 ALineVertex,
00134 ALineDirection));
00135 }
00136 }
00137 else
00138 setMark(*it, treated);
00139 }
00140
00141 negateMaskMark(treated);
00142 freeMark(treated);
00143 }
00144
00145 void CGMapVertex::computeDistanceToPlane(int AMarkNumber, int ADirectInfoIndex,
00146 const CVertex & APlaneVertex,
00147 const CVertex & APlaneNormal)
00148 {
00149 assert(!APlaneNormal.isNull());
00150
00151 int treated = getNewMark();
00152
00153 for (CDynamicCoverageAll it(this); it.cont(); ++it)
00154 if (!isMarked(*it, treated))
00155 {
00156 if (isMarked(*it, AMarkNumber))
00157 for (CDynamicCoverageVertex cov(this, *it); cov.cont(); ++cov)
00158 {
00159 setMark(*cov, treated);
00160
00161 if (isOrbitUsed(*cov, ORBIT_VERTEX))
00162 {
00163 CVertex * vertex = getVertex(*cov);
00164 assert(vertex!=NULL);
00165
00166 SET_VALUE(*cov, ADirectInfoIndex,
00167 CGeometry::distanceToPlane(*vertex,
00168 APlaneVertex,
00169 APlaneNormal));
00170 }
00171 }
00172 else
00173 setMark(*it, treated);
00174 }
00175
00176 negateMaskMark(treated);
00177 freeMark(treated);
00178 }
00179
00180 #undef SET_VALUE
00181
00182 void CGMapVertex::normalizeParameter(int AMarkNumber, int ADirectInfoIndex,
00183 TCoordinate AMin, TCoordinate AMax)
00184 {
00185 int treated = getNewMark();
00186
00187 bool first = true;
00188
00189
00190
00191 TCoordinate oldMin = 0, oldMax = 0;
00192
00193 CDynamicCoverageAll it(this);
00194
00195 for (; it.cont(); ++it)
00196 if (!isMarked(*it, treated))
00197 {
00198 if (isMarked(*it, AMarkNumber))
00199 for (CDynamicCoverageVertex cov(this, *it); cov.cont(); ++cov)
00200 {
00201 setMark(*cov, treated);
00202
00203 if (isOrbitUsed(*cov, ORBIT_VERTEX))
00204 {
00205 TCoordinate & value =
00206 * getDirectInfoAsCoord(*cov,ADirectInfoIndex);
00207
00208 if (first)
00209 {
00210 first = false;
00211 oldMin = oldMax = value;
00212 }
00213 else
00214 {
00215 if (value < oldMin) oldMin = value;
00216 if (value > oldMax) oldMax = value;
00217 }
00218 }
00219 }
00220 else
00221 setMark(*it, treated);
00222 }
00223
00224 negateMaskMark(treated);
00225
00226 for (it.reinit(); it.cont(); ++it)
00227 if (!isMarked(*it, treated))
00228 {
00229 if (isMarked(*it, AMarkNumber))
00230 for (CDynamicCoverageVertex cov(this, *it); cov.cont(); ++cov)
00231 {
00232 setMark(*cov, treated);
00233
00234 if (isOrbitUsed(*cov, ORBIT_VERTEX))
00235 {
00236 TCoordinate & value =
00237 * getDirectInfoAsCoord(*cov,ADirectInfoIndex);
00238
00239 if (oldMax==oldMin)
00240 value = (AMin+AMax)/2;
00241 else
00242 value = AMin + (AMax-AMin)*(value-oldMin)/(oldMax-oldMin);
00243 }
00244 }
00245 else
00246 setMark(*it, treated);
00247 }
00248
00249 negateMaskMark(treated);
00250 freeMark(treated);
00251 }
00252
00253 void CGMapVertex::applyFunctionOnParameter(int AMarkNumber,
00254 int ADirectInfoIndex,
00255 TFunctionType AFunctionType)
00256 {
00257 if (AFunctionType==FUNCTION_LIN)
00258 return;
00259
00260 int treated = getNewMark();
00261
00262 for (CDynamicCoverageAll it(this); it.cont(); ++it)
00263 if (!isMarked(*it, treated))
00264 {
00265 if (isMarked(*it, AMarkNumber))
00266 for (CDynamicCoverageVertex cov(this, *it); cov.cont(); ++cov)
00267 {
00268 setMark(*cov, treated);
00269
00270 if (isOrbitUsed(*cov, ORBIT_VERTEX))
00271 {
00272 TCoordinate & value =
00273 * getDirectInfoAsCoord(*cov, ADirectInfoIndex);
00274
00275 switch (AFunctionType)
00276 {
00277 case FUNCTION_QUAD: value = value*value ; break;
00278 case FUNCTION_EXP : value = exp(value) ; break;
00279 case FUNCTION_LOG : value = value<=0 ? 0 : log(value); break;
00280 case FUNCTION_SIN : value = sin(value) ; break;
00281 case FUNCTION_COS : value = cos(value) ; break;
00282 default:
00283 assert(false);
00284 }
00285 }
00286 }
00287 else
00288 setMark(*it, treated);
00289 }
00290
00291 negateMaskMark(treated);
00292 freeMark(treated);
00293 }
00294
00295 void CGMapVertex::translate(int AMarkNumber, const CVertex & AVector,
00296 int ADirectInfoVertex, int ADirectInfoParam)
00297 {
00298
00299 if (ADirectInfoParam<0)
00300 {
00301 CTransformationMatrix translationMatrix(CTransformationMatrix::IdentityMatrix);
00302 translationMatrix.translate(AVector);
00303 applyMatrix(translationMatrix, AMarkNumber, ADirectInfoVertex);
00304 return;
00305 }
00306
00307 int treated = getNewMark();
00308
00309 for (CDynamicCoverageAll it(this); it.cont(); ++it)
00310 if (!isMarked(*it, treated))
00311 {
00312 if (isMarked(*it, AMarkNumber))
00313 for (CDynamicCoverageVertex cov(this, *it); cov.cont(); ++cov)
00314 {
00315 setMark(*cov, treated);
00316
00317 if (isOrbitUsed(*cov, ORBIT_VERTEX))
00318 {
00319 CVertex * Vdest = getVertex(*cov);
00320 assert(Vdest!=NULL);
00321
00322 CVertex * Vsrce =
00323 ADirectInfoVertex<0 ? Vdest :
00324 getDirectInfoAsVertex(*cov,ADirectInfoVertex);
00325 assert(Vsrce!=NULL);
00326
00327 TCoordinate param =
00328 * getDirectInfoAsCoord(*cov,ADirectInfoParam);
00329
00330 CTransformationMatrix translationMatrix(CTransformationMatrix::IdentityMatrix);
00331 translationMatrix.translate(param*AVector);
00332
00333 translationMatrix.applyOn(*Vsrce, *Vdest);
00334 }
00335 }
00336 else
00337 setMark(*it, treated);
00338 }
00339
00340 negateMaskMark(treated);
00341 freeMark(treated);
00342 }
00343
00344 void CGMapVertex::rotate(int AMarkNumber,
00345 const CVertex & AAxeVertex,
00346 const CVertex & AAxeDirection,
00347 TCoordinate AAngle,
00348 int ADirectInfoVertex, int ADirectInfoParam)
00349 {
00350 if (ADirectInfoParam<0)
00351 {
00352 CTransformationMatrix
00353 rotationMatrix(CTransformationMatrix::IdentityMatrix);
00354 rotationMatrix.rotate(AAxeVertex, AAxeDirection, AAngle);
00355 applyMatrix(rotationMatrix, AMarkNumber, ADirectInfoVertex);
00356 return;
00357 }
00358
00359 int treated = getNewMark();
00360
00361 for (CDynamicCoverageAll it(this); it.cont(); ++it)
00362 if (!isMarked(*it, treated))
00363 {
00364 if (isMarked(*it, AMarkNumber))
00365 for (CDynamicCoverageVertex cov(this, *it); cov.cont(); ++cov)
00366 {
00367 setMark(*cov, treated);
00368
00369 if (isOrbitUsed(*cov, ORBIT_VERTEX))
00370 {
00371 CVertex * Vdest = getVertex(*cov);
00372 assert(Vdest!=NULL);
00373
00374 CVertex * Vsrce =
00375 ADirectInfoVertex<0 ? Vdest :
00376 getDirectInfoAsVertex(*cov,ADirectInfoVertex);
00377 assert(Vsrce!=NULL);
00378
00379 TCoordinate param =
00380 * getDirectInfoAsCoord(*cov, ADirectInfoParam);
00381
00382 CTransformationMatrix rotationMatrix(CTransformationMatrix::IdentityMatrix);
00383 rotationMatrix.rotate(AAxeVertex, AAxeDirection,
00384 param*AAngle);
00385
00386 rotationMatrix.applyOn(*Vsrce, *Vdest);
00387 }
00388 }
00389 else
00390 setMark(*it, treated);
00391 }
00392
00393 negateMaskMark(treated);
00394 freeMark(treated);
00395 }
00396
00397 void CGMapVertex::scale(int AMarkNumber,
00398 const CVertex & ACenter, const CVertex & ACoef,
00399 int ADirectInfoVertex, int ADirectInfoParam)
00400 {
00401 if (ADirectInfoParam<0)
00402 {
00403 CTransformationMatrix scaleMatrix(CTransformationMatrix::IdentityMatrix);
00404 scaleMatrix.scale(ACenter, ACoef);
00405 applyMatrix(scaleMatrix, AMarkNumber, ADirectInfoVertex);
00406 return;
00407 }
00408
00409 int treated = getNewMark();
00410
00411 for (CDynamicCoverageAll it(this); it.cont(); ++it)
00412 if (!isMarked(*it, treated))
00413 {
00414 if (isMarked(*it, AMarkNumber))
00415 for (CDynamicCoverageVertex cov(this, *it); cov.cont(); ++cov)
00416 {
00417 setMark(*cov, treated);
00418
00419 if (isOrbitUsed(*cov, ORBIT_VERTEX))
00420 {
00421 CVertex * Vdest = getVertex(*cov);
00422 assert(Vdest!=NULL);
00423
00424 CVertex * Vsrce =
00425 ADirectInfoVertex<0 ? Vdest :
00426 getDirectInfoAsVertex(*cov, ADirectInfoVertex);
00427 assert(Vsrce!=NULL);
00428
00429 TCoordinate param =
00430 * getDirectInfoAsCoord(*cov, ADirectInfoParam);
00431
00432 CTransformationMatrix scaleMatrix(CTransformationMatrix::IdentityMatrix);
00433 scaleMatrix.scale(ACenter, param*ACoef);
00434
00435 scaleMatrix.applyOn(*Vsrce, *Vdest);
00436 }
00437 }
00438 else
00439 setMark(*it, treated);
00440 }
00441
00442 negateMaskMark(treated);
00443 freeMark(treated);
00444 }
00445
00446 void CGMapVertex::scale(int AMarkNumber,
00447 const CVertex & ACenter, TCoordinate ACoef,
00448 int ADirectInfoVertex, int ADirectInfoParam)
00449 {
00450 scale(AMarkNumber,
00451 ACenter, CVertex(ACoef, ACoef, ACoef),
00452 ADirectInfoVertex, ADirectInfoParam);
00453 }
00454
00455 void CGMapVertex::axialScale(int AMarkNumber,
00456 const CVertex & AAxeVertex,
00457 const CVertex & AAxeDirection,
00458 TCoordinate ACoef,
00459 int ADirectInfoVertex, int ADirectInfoParam)
00460 {
00461 assert(!AAxeDirection.isNull());
00462
00463 if (ADirectInfoParam<0)
00464 {
00465 CTransformationMatrix scaleMatrix(CTransformationMatrix::IdentityMatrix);
00466 scaleMatrix.axialScale(AAxeVertex, AAxeDirection, ACoef);
00467 applyMatrix(scaleMatrix, AMarkNumber, ADirectInfoVertex);
00468 return;
00469 }
00470
00471 int treated = getNewMark();
00472
00473 for (CDynamicCoverageAll it(this); it.cont(); ++it)
00474 if (!isMarked(*it, treated))
00475 {
00476 if (isMarked(*it, AMarkNumber))
00477 for (CDynamicCoverageVertex cov(this, *it); cov.cont(); ++cov)
00478 {
00479 setMark(*cov, treated);
00480
00481 if (isOrbitUsed(*cov, ORBIT_VERTEX))
00482 {
00483 CVertex * Vdest = getVertex(*cov);
00484 assert(Vdest!=NULL);
00485
00486 CVertex * Vsrce =
00487 ADirectInfoVertex<0 ? Vdest :
00488 getDirectInfoAsVertex(*cov, ADirectInfoVertex);
00489 assert(Vsrce!=NULL);
00490
00491 TCoordinate param =
00492 * getDirectInfoAsCoord(*cov, ADirectInfoParam);
00493
00494 CTransformationMatrix scaleMatrix(CTransformationMatrix::IdentityMatrix);
00495 scaleMatrix.axialScale(AAxeVertex, AAxeDirection,
00496 param*ACoef);
00497
00498 scaleMatrix.applyOn(*Vsrce, *Vdest);
00499 }
00500 }
00501 else
00502 setMark(*it, treated);
00503 }
00504
00505 negateMaskMark(treated);
00506 freeMark(treated);
00507 }
00508
00509 void CGMapVertex::planarScale(int AMarkNumber,
00510 const CVertex & APlaneVertex,
00511 const CVertex & APlaneNormal,
00512 TCoordinate ACoef,
00513 int ADirectInfoVertex, int ADirectInfoParam)
00514 {
00515 assert(!APlaneNormal.isNull());
00516
00517 if (ADirectInfoParam<0)
00518 {
00519 CTransformationMatrix scaleMatrix(CTransformationMatrix::IdentityMatrix);
00520 scaleMatrix.planarScale(APlaneVertex, APlaneNormal, ACoef);
00521 applyMatrix(scaleMatrix, AMarkNumber, ADirectInfoVertex);
00522 return;
00523 }
00524
00525 int treated = getNewMark();
00526
00527 for (CDynamicCoverageAll it(this); it.cont(); ++it)
00528 if (!isMarked(*it, treated))
00529 {
00530 if (isMarked(*it, AMarkNumber))
00531 for (CDynamicCoverageVertex cov(this, *it); cov.cont(); ++cov)
00532 {
00533 setMark(*cov, treated);
00534
00535 if (isOrbitUsed(*cov, ORBIT_VERTEX))
00536 {
00537 CVertex * Vdest = getVertex(*cov);
00538 assert(Vdest!=NULL);
00539
00540 CVertex * Vsrce =
00541 ADirectInfoVertex<0 ? Vdest :
00542 getDirectInfoAsVertex(*cov, ADirectInfoVertex);
00543 assert(Vsrce!=NULL);
00544
00545 TCoordinate param =
00546 * getDirectInfoAsCoord(*cov, ADirectInfoParam);
00547
00548 CTransformationMatrix scaleMatrix(CTransformationMatrix::IdentityMatrix);
00549 scaleMatrix.planarScale(APlaneVertex, APlaneNormal,
00550 param*ACoef);
00551
00552 scaleMatrix.applyOn(*Vsrce, *Vdest);
00553 }
00554 }
00555 else
00556 setMark(*it, treated);
00557 }
00558
00559 negateMaskMark(treated);
00560 freeMark(treated);
00561 }
00562
00563 void CGMapVertex::orthoProjectOnPlane(int AMarkNumber,
00564 TCoordinate AA,
00565 TCoordinate AB,
00566 TCoordinate AC,
00567 TCoordinate AD)
00568 {
00569 int treated = getNewMark();
00570
00571 for (CDynamicCoverageAll it(this); it.cont(); ++it)
00572 if (! isMarked(*it, treated))
00573 {
00574 if (isMarked(*it, AMarkNumber))
00575 {
00576 CVertex & v = * findVertex(*it);
00577
00578 v = CGeometry::orthoProjectVertexOnPlane(v, AA, AB, AC, AD);
00579 }
00580 else
00581 setMark(*it, treated);
00582 }
00583
00584 negateMaskMark(treated);
00585 freeMark(treated);
00586 }
00587