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 "mesh-generic.hh"
00026 #include "g-map-generic.hh"
00027 #include <cassert>
00028 using namespace GMap3d;
00029
00030 bool CMeshGeneric::canMergeEdgeAndMesh1(CDart* AEdgeDart,
00031 CDart* AMesh1Corners[2])
00032 {
00033 assert(AEdgeDart!=NULL);
00034 assert(AMesh1Corners!=NULL);
00035
00036 return
00037 ! FMap->isFree0(AMesh1Corners[0]) && ! FMap->isFree0(AMesh1Corners[1]) &&
00038 ! FMap->isSameOrbit(AMesh1Corners[0], AMesh1Corners[1], ORBIT_23) &&
00039 isTopoEdge(AEdgeDart, AMesh1Corners[0]) &
00040 isTopoEdge(AEdgeDart, AMesh1Corners[1]);
00041 }
00042
00043 void CMeshGeneric::mergeEdgeAndMesh1(CDart* AEdgeDart,
00044 CDart* AMesh1Extremities[2])
00045 {
00046 assert(canMergeEdgeAndMesh1(AEdgeDart, AMesh1Extremities));
00047
00048 CDart* edges[2] = { AEdgeDart, FMap->alpha0(AEdgeDart) };
00049
00050
00051 FMap->unsew0(AEdgeDart);
00052
00053
00054 for (int i=0; i<2; ++i)
00055 {
00056 CDart* mesh = FMap->alpha0(AMesh1Extremities[i]);
00057
00058 FMap->unsew0(AMesh1Extremities[i]);
00059
00060 for (CStaticCoverage23 cov(FMap, AMesh1Extremities[i]); cov.cont(); ++cov)
00061 FMap->delMapDart(*cov);
00062
00063 FMap->topoSew0(edges[i], mesh);
00064 }
00065 }
00066
00067 bool CMeshGeneric::canMergeSquare1MeshedAndMesh2(CDart* ASquareDart,
00068 CDart* AMesh2Dart,
00069 int ASx, int ASy)
00070 {
00071 assert(ASquareDart!=NULL);
00072 assert(AMesh2Dart!=NULL);
00073 assert(ASx>0);
00074 assert(ASy>0);
00075
00076 bool is3Sewed = ! FMap->isFree3(ASquareDart);
00077
00078 return
00079 isTopoSquare1Meshed(ASquareDart, ASx,ASy, true, is3Sewed) &&
00080 isTopoSquare2Meshed(AMesh2Dart , ASx,ASy, true, is3Sewed);
00081 }
00082
00083 void CMeshGeneric::mergeSquare1MeshedAndMesh2(CDart * ASquareDart,
00084 CDart * AMesh2Dart,
00085 int ASx, int ASy)
00086 {
00087 assert(canMergeSquare1MeshedAndMesh2(ASquareDart, AMesh2Dart, ASx,ASy));
00088
00089 int nbRounds = FMap->isFree3(ASquareDart) ? 1 : 2;
00090
00091 CDart * current1 = ASquareDart;
00092 CDart * current2 = AMesh2Dart;
00093
00094 while (nbRounds > 0)
00095 {
00096 CDart * tmp;
00097
00098 FMap->unlinkAlpha1(current1);
00099
00100 for (int i=2*(ASx+ASy); i>0; --i)
00101 {
00102 tmp = FMap->alpha1(current2);
00103
00104 FMap->unlinkAlpha1(tmp); FMap->linkAlpha1(tmp, current1);
00105
00106 tmp = current2;
00107 current2 = FMap->alpha01(current2);
00108
00109 FMap->unlinkAlpha1(current2);
00110 FMap->delMapDart(FMap->alpha0(tmp));
00111 FMap->delMapDart( tmp );
00112
00113 tmp = FMap->alpha0(current1);
00114 current1 = FMap->alpha1(tmp);
00115
00116 FMap->unlinkAlpha1(tmp); FMap->linkAlpha1(tmp, current2);
00117
00118 if (! FMap->isFree2(current2))
00119 current2 = FMap->alpha21(current2);
00120 }
00121
00122 if (nbRounds-- == 2)
00123 {
00124 current1 = FMap->alpha3(ASquareDart);
00125 current2 = FMap->alpha3(AMesh2Dart );
00126 }
00127 }
00128 }
00129
00130 bool CMeshGeneric::canMergeSquare2MeshedAndMesh3Side(CDart* ASquareDart,
00131 CDart* AMesh3Dart,
00132 int ASx, int ASy)
00133 {
00134 assert(ASquareDart!=NULL);
00135 assert(AMesh3Dart!=NULL);
00136 assert(ASx>0);
00137 assert(ASy>0);
00138
00139 return
00140 isTopoSquare2Meshed(ASquareDart, ASx,ASy) &&
00141 isTopoSquare3Meshed(AMesh3Dart , ASx,ASy);
00142 }
00143
00144 void CMeshGeneric::mergeSquare2MeshedAndMesh3Side(CDart* ASquareDart,
00145 CDart* AMesh3Dart,
00146 int ASx, int ASy,
00147 CDart** ANextSquare,
00148 CDart** ANextMesh3Side)
00149 {
00150 assert(canMergeSquare2MeshedAndMesh3Side(ASquareDart, AMesh3Dart, ASx,ASy));
00151
00152 CDart * currentX1, * currentX2, * currentY1=NULL, * currentY2=NULL;
00153 CDart * nextX1 , * nextX2 , * nextY1 , * nextY2 ;
00154 CDart * tmp1 , * tmp2 ;
00155
00156
00157 currentX1 = ASquareDart;
00158 currentX2 = AMesh3Dart;
00159
00160
00161 for (int i=0; i<ASx; ++i)
00162 {
00163
00164 nextX1 = FMap->alpha0121 (currentX1);
00165 nextX2 = FMap->alpha012321(currentX2);
00166
00167
00168 currentY1 = FMap->alpha1(currentX1);
00169 currentY2 = FMap->alpha1(currentX2);
00170
00171
00172 for (int j=0; j<ASy; ++j)
00173 {
00174
00175 nextY1 = FMap->alpha0121(currentY1);
00176 nextY2 = j<ASy-1 ? FMap->alpha012321(currentY2) : FMap->alpha0121(currentY2);
00177
00178
00179 for (int n=0; n<4; ++n)
00180 {
00181 tmp1 = currentY1;
00182 tmp2 = currentY2;
00183
00184 currentY1 = FMap->alpha01(currentY1);
00185 currentY2 = FMap->alpha01(currentY2);
00186
00187 if ((n==0 && i==0) || n==1 || n==2 || (n==3 && j==0))
00188 {
00189 FMap->unlinkAlpha2(tmp1);
00190 FMap->unlinkAlpha2(FMap->alpha0(tmp1));
00191 }
00192
00193 CDart* tmp2Bis = FMap->alpha2(tmp2);
00194
00195 FMap->unlinkAlpha2(tmp2);
00196 FMap->unlinkAlpha2(FMap->alpha0(tmp2));
00197
00198 FMap->topoSew2(tmp1, tmp2Bis);
00199
00200 FMap->delMapDart(FMap->alpha0(tmp2));
00201 FMap->delMapDart( tmp2 );
00202 }
00203
00204
00205 currentY1 = nextY1;
00206 currentY2 = nextY2;
00207 }
00208
00209
00210 currentX1 = nextX1;
00211 currentX2 = nextX2;
00212 }
00213
00214
00215 if (ANextSquare!=NULL)
00216 * ANextSquare = FMap->alpha10(currentY1);
00217
00218 if (ANextMesh3Side!=NULL)
00219 * ANextMesh3Side = FMap->alpha10(currentY2);
00220 }
00221
00222 bool CMeshGeneric::canMergeCube2MeshedAndMesh3(CDart* ACubeDart,
00223 CDart* AMesh3Dart,
00224 int ASx, int ASy, int ASz)
00225 {
00226 assert(ACubeDart!=NULL);
00227 assert(AMesh3Dart!=NULL);
00228 assert(ASx>0);
00229 assert(ASy>0);
00230 assert(ASz>0);
00231
00232 return
00233 isTopoCube2Meshed(ACubeDart , ASx,ASy,ASz) &&
00234 isTopoCube3Meshed(AMesh3Dart, ASx,ASy,ASz);
00235 }
00236
00237 void CMeshGeneric::mergeCube2MeshedAndMesh3(CDart* ACubeDart, CDart* AMesh3Dart,
00238 int ASx, int ASy, int ASz)
00239 {
00240 assert(canMergeCube2MeshedAndMesh3(ACubeDart, AMesh3Dart, ASx,ASy,ASz));
00241
00242 int s[3] = { ASx, ASy, ASz };
00243
00244 CDart * current1 = ACubeDart;
00245 CDart * current2 = AMesh3Dart;
00246
00247 CDart * next1;
00248 CDart * next2;
00249
00250 for (int i=0; i<3; ++i)
00251 {
00252 next1 = FMap->alpha12(current1);
00253 next2 = FMap->alpha12(current2);
00254
00255 CDart * current1Bis;
00256 CDart * current2Bis;
00257
00258 mergeSquare2MeshedAndMesh3Side(current1, current2,
00259 s[i], s[(i+1)%3],
00260 ¤t1Bis, ¤t2Bis);
00261
00262 mergeSquare2MeshedAndMesh3Side(current1Bis, current2Bis,
00263 s[i], s[(i+2)%3]);
00264
00265 current1 = next1;
00266 current2 = next2;
00267 }
00268 }
00269