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
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include <stdio.h>
00042 #ifndef __UNIX_
00043 #include <stdlib.h>
00044 #endif
00045 #include <math.h>
00046 #include "memvirtu.h"
00047 #include "lowparam.h"
00048 #include "lowmacro.h"
00049 #include "lowsolid.h"
00050 #include "eulerops.h"
00051 #include "vectorop.h"
00052 #include "sethmain.h"
00053
00054 #ifdef _Windows
00055 using namespace USPDesigner;
00056 #endif
00057
00058
00059 void MSD_lowSetOpVVGetNeighborhood(VPTYPE va, VPTYPE vb)
00060 {
00061 HPTYPE ha;
00062 HPTYPE hb;
00063 double d1, d2, d3, d4;
00064 int i, j;
00065
00066 #ifdef ESP
00067 int s1a, s2a, s1b, s2b;
00068 vector dir;
00069 #endif
00070
00071 nnba = MSD_lowSetOpNbaPreProcess(va);
00072 nnbb = MSD_lowSetOpNbbPreProcess(vb);
00073
00074 #ifdef TRACE_BOOLEAN2
00075 fprintf(trace, "\n*** sgetneighborhood ***\n");
00076 for (i = 0; i < nnba; ++i)
00077 {
00078 trace_nba(i);
00079 }
00080 for (i = 0; i < nnbb; ++i)
00081 {
00082 trace_nbb(i);
00083 }
00084 #endif
00085
00086 nsectors = 0;
00087 for (i = 0; i < nnba; ++i)
00088 {
00089 for (j = 0; j < nnbb; ++j)
00090 {
00091 #ifdef TRACE_BOOLEAN21
00092 fprintf(trace, "*** setopgetneighborhood ***\n");
00093 fprintf(trace, " sector (solida) --> %2d\n", i);
00094 fprintf(trace, " sector (solidb) --> %2d\n", j);
00095 #endif
00096
00097 if (MSD_lowSetOpSectorTest(i, j))
00098 {
00099 #ifdef TRACE_BOOLEAN21
00100 fprintf(trace, " criado par de sectors --> %2d\n", nsectors);
00101 #endif
00102
00103 ha = SetANBHe(i);
00104 hb = SetBNBHe(j);
00105 SetSecA(nsectors) = i;
00106 SetSecB(nsectors) = j;
00107 d1 = dot(FacFeq(LooLFace(HalWLoop(hb))), SetANB1(i));
00108 d2 = dot(FacFeq(LooLFace(HalWLoop(hb))), SetANB2(i));
00109 d3 = dot(FacFeq(LooLFace(HalWLoop(ha))), SetBNB1(j));
00110 d4 = dot(FacFeq(LooLFace(HalWLoop(ha))), SetBNB2(j));
00111
00112 SetSecs1a(nsectors) = -comp(d1, 0.0, EPS);
00113 SetSecs2a(nsectors) = -comp(d2, 0.0, EPS);
00114 SetSecs1b(nsectors) = -comp(d3, 0.0, EPS);
00115 SetSecs2b(nsectors) = -comp(d4, 0.0, EPS);
00116
00117 SetSecInter(nsectors) = 1;
00118 SetSecOnOn(nsectors) = 0;
00119 if (SetSecs1a(nsectors) == USP_ON)
00120 {
00121 SetSecOnOn(nsectors) = 1;
00122 }
00123 if (SetSecs1b(nsectors) == USP_ON)
00124 {
00125 SetSecOnOn(nsectors) = SetSecOnOn(nsectors) + 2;
00126 }
00127 if (SetSecs2a(nsectors) == USP_ON)
00128 {
00129 SetSecOnOn(nsectors) = SetSecOnOn(nsectors) + 4;
00130 }
00131 if (SetSecs2b(nsectors) == USP_ON)
00132 {
00133 SetSecOnOn(nsectors) = SetSecOnOn(nsectors) + 8;
00134 }
00135 nsectors++;
00136
00137 #ifndef __VIRTUAL_MEM
00138 if (nsectors == MAXSECTORS)
00139 {
00140 fprintf(stderr, "sectors: falta memoria!\n");
00141 exit(1);
00142 }
00143 #endif
00144 }
00145 #ifdef ESP
00146 else
00147 {
00148 #ifdef TRACE_BOOLEAN21
00149 fprintf(trace, " criado par de sectors --> %2d\n", nsectors);
00150 #endif
00151
00152 ha = SetANBHe(i);
00153 hb = SetBNBHe(j);
00154 SetSecA(nsectors) = i;
00155 SetSecB(nsectors) = j;
00156
00157 veccopy(dir, SetANB1(i));
00158 s1a = MSD_lowSetOpSectorWithin(dir, SetBNB1(j),
00159 SetBNB2(j), SetBNB12(j)) ? USP_ON : USP_OUT;
00160
00161 veccopy(dir, SetANB2(i));
00162 s2a = MSD_lowSetOpSectorWithin(dir, SetBNB1(j),
00163 SetBNB2(j), SetBNB12(j)) ? USP_ON : USP_OUT;
00164 SetSecs1a(nsectors) = s1a;
00165 SetSecs2a(nsectors) = s2a;
00166
00167 veccopy(dir, SetBNB1(i));
00168 s1b = MSD_lowSetOpSectorWithin(dir, SetANB1(j),
00169 SetANB2(j), SetANB12(j)) ? USP_ON : USP_OUT;
00170
00171 veccopy(dir, SetBNB2(i));
00172 s2b = MSD_lowSetOpSectorWithin(dir, SetANB1(j),
00173 SetANB2(j), SetANB12(j)) ? USP_ON : USP_OUT;
00174 SetSecs1b(nsectors) = s1b;
00175 SetSecs2b(nsectors) = s2b;
00176
00177 SetSecInter(nsectors) = 0;
00178 nsectors++;
00179 }
00180 #endif
00181 }
00182 }
00183 }
00184
00185
00186 int MSD_lowSetOpNbaPreProcess(VPTYPE v)
00187 {
00188 HPTYPE he;
00189 vector v1, v2, v3, vv, bisec;
00190 int i, j;
00191
00192 i = 0;
00193 he = VerVEdge(v);
00194 do
00195 {
00196 SetANBHe(i) = he;
00197 veccopy(v1, VerVCoord(HalVtx(HalPrv(he))));
00198 veccopy(v2, VerVCoord(HalVtx(he)));
00199 veccopy(v3, VerVCoord(HalVtx(HalNxt(he))));
00200 vecminus(SetANB1(i), v1, v2);
00201 vecminus(SetANB2(i), v3, v2);
00202 cross(SetANB12(i), SetANB1(i), SetANB2(i));
00203 if (vecnull(SetANB12(i), EPS) ||
00204 (dot(SetANB12(i), FacFeq(LooLFace(HalWLoop(he)))) > 0.0))
00205 {
00206 if (vecnull(SetANB12(i), EPS))
00207 {
00208 MSD_lowSetOpInside(he, bisec);
00209 }
00210 else
00211 {
00212 vecplus(bisec, SetANB1(i), SetANB2(i));
00213 bisec[0] = -bisec[0];
00214 bisec[1] = -bisec[1];
00215 bisec[2] = -bisec[2];
00216 }
00217 j = i + 1;
00218 SetANBHe(j) = he;
00219 veccopy(vv, SetANB2(i));
00220 veccopy(SetANB2(j), vv);
00221 veccopy(SetANB2(i), bisec);
00222 veccopy(SetANB1(j), bisec);
00223 cross(SetANB12(i), SetANB1(i), SetANB2(i));
00224 cross(SetANB12(j), SetANB1(j), SetANB2(j));
00225 ++i;
00226
00227 #ifndef __VIRTUAL_MEM
00228 if (i == MAXSECTORS)
00229 {
00230 fprintf(stderr, "nb: falta memoria!\n");
00231 exit(1);
00232 }
00233 #endif
00234 }
00235 ++i;
00236
00237 #ifndef __VIRTUAL_MEM
00238 if (i == MAXSECTORS)
00239 {
00240 fprintf(stderr, "nb: falta memoria!\n");
00241 exit(1);
00242 }
00243 #endif
00244 } while ((he = HalNxt(mate(he))) != VerVEdge(v));
00245 return(i);
00246 }
00247
00248
00249 int MSD_lowSetOpNbbPreProcess(VPTYPE v)
00250 {
00251 HPTYPE he;
00252 vector v1, v2, v3, vv, bisec;
00253 int i, j;
00254
00255 i = 0;
00256 he = VerVEdge(v);
00257 do
00258 {
00259 SetBNBHe(i) = he;
00260 veccopy(v1, VerVCoord(HalVtx(HalPrv(he))));
00261 veccopy(v2, VerVCoord(HalVtx(he)));
00262 veccopy(v3, VerVCoord(HalVtx(HalNxt(he))));
00263 vecminus(SetBNB1(i), v1, v2);
00264 vecminus(SetBNB2(i), v3, v2);
00265 cross(SetBNB12(i), SetBNB1(i), SetBNB2(i));
00266 if (vecnull(SetBNB12(i), EPS) ||
00267 (dot(SetBNB12(i), FacFeq(LooLFace(HalWLoop(he)))) > 0.0))
00268 {
00269 if (vecnull(SetBNB12(i), EPS))
00270 {
00271 MSD_lowSetOpInside(he, bisec);
00272 }
00273 else
00274 {
00275 vecplus(bisec, SetBNB1(i), SetBNB2(i));
00276 bisec[0] = -bisec[0];
00277 bisec[1] = -bisec[1];
00278 bisec[2] = -bisec[2];
00279 }
00280 j = i + 1;
00281 SetBNBHe(j) = he;
00282 veccopy(vv, SetBNB2(i));
00283 veccopy(SetBNB2(j), vv);
00284 veccopy(SetBNB2(i), bisec);
00285 veccopy(SetBNB1(j), bisec);
00286 cross(SetBNB12(i), SetBNB1(i), SetBNB2(i));
00287 cross(SetBNB12(j), SetBNB1(j), SetBNB2(j));
00288 ++i;
00289
00290 #ifndef __VIRTUAL_MEM
00291 if (i == MAXSECTORS)
00292 {
00293 fprintf(stderr, "nb: falta memoria!\n");
00294 exit(1);
00295 }
00296 #endif
00297 }
00298 ++i;
00299
00300 #ifndef __VIRTUAL_MEM
00301 if (i == MAXSECTORS)
00302 {
00303 fprintf(stderr, "nb: falta memoria!\n");
00304 exit(1);
00305 }
00306 #endif
00307 } while ((he = HalNxt(mate(he))) != VerVEdge(v));
00308 return(i);
00309 }
00310
00311
00312 int MSD_lowSetOpSectorTest(int i, int j)
00313 {
00314 HPTYPE h1;
00315 HPTYPE h2;
00316 vector intrs, nh1, nh2;
00317 int c1, c2;
00318
00319 h1 = SetANBHe(i);
00320 h2 = SetBNBHe(j);
00321 veccopy(nh1, FacFeq(LooLFace(HalWLoop(h1))));
00322 veccopy(nh2, FacFeq(LooLFace(HalWLoop(h2))));
00323 cross(intrs, nh1, nh2);
00324 if (vecnull(intrs, EPS))
00325 {
00326 #ifdef TRACE_BOOLEAN21
00327 fprintf(trace, " Sectors overlap!\n");
00328 #endif
00329
00330 return(MSD_lowSetOpOverlap(h1, h2));
00331 }
00332
00333 #ifdef TRACE_BOOLEAN21
00334 fprintf(trace, "--- Analise da interseccao e solida!\n");
00335 #endif
00336
00337 c1 = MSD_lowSetOpSectorWithin(intrs, SetANB1(i), SetANB2(i), SetANB12(i));
00338
00339 #ifdef TRACE_BOOLEAN21
00340 fprintf(trace, "--- Analise da interseccao e solidb!\n");
00341 #endif
00342
00343 c2 = MSD_lowSetOpSectorWithin(intrs, SetBNB1(j), SetBNB2(j), SetBNB12(j));
00344
00345 if (c1 && c2)
00346 {
00347 #ifdef TRACE_BOOLEAN21
00348 fprintf(trace, " Interseccao interna aos sectores dos solida e solidb!\n");
00349 #endif
00350
00351 return(TRUE);
00352 }
00353 else
00354 {
00355 intrs[0] = -intrs[0];
00356 intrs[1] = -intrs[1];
00357 intrs[2] = -intrs[2];
00358
00359 #ifdef TRACE_BOOLEAN21
00360 fprintf(trace, "--- Analise da interseccao (invertida) e solida!\n");
00361 #endif
00362
00363 c1 = MSD_lowSetOpSectorWithin(intrs, SetANB1(i), SetANB2(i), SetANB12(i));
00364
00365 #ifdef TRACE_BOOLEAN21
00366 fprintf(trace, "--- Analise da interseccao (invertida) e solidb!\n");
00367 #endif
00368
00369 c2 = MSD_lowSetOpSectorWithin(intrs, SetBNB1(j), SetBNB2(j), SetBNB12(j));
00370 if (c1 && c2)
00371 {
00372 #ifdef TRACE_BOOLEAN21
00373 fprintf(trace, " Interseccao interna aos sectores dos solida e solidb!\n");
00374 #endif
00375
00376 return(TRUE);
00377 }
00378 }
00379
00380 #ifdef TRACE_BOOLEAN21
00381 fprintf(trace, " Interseccao nao e interna a ambos os sectores dos solida e solidb.\n");
00382 #endif
00383
00384 return(FALSE);
00385 }
00386
00387 int MSD_lowSetOpSectorWithin(vector dir, vector ref1, vector ref2, vector ref12)
00388 {
00389 vector c1, c2;
00390 int t1, t2;
00391
00392 cross(c1, ref1, dir);
00393 if (vecnull(c1, EPS))
00394 {
00395 if (dot(ref1, dir) > 0.0)
00396 {
00397 #ifdef TRACE_BOOLEAN21
00398 fprintf(trace, " Interseccao coincide com uma aresta do setor\n");
00399 #endif
00400
00401 return(TRUE);
00402 }
00403 else
00404 {
00405 #ifdef TRACE_BOOLEAN21
00406 fprintf(trace, " ref1 = %f %f %f\n", ref1[0], ref1[1], ref1[2]);
00407 fprintf(trace, " dir = %f %f %f\n", dir[0], dir[1], dir[2]);
00408 fprintf(trace, " Interseccao e aresta sao colineares, mas de direcoes distintas\n");
00409 #endif
00410
00411 return(FALSE);
00412 }
00413 }
00414
00415 cross(c2, dir, ref2);
00416 if (vecnull(c2, EPS))
00417 {
00418 if (dot(ref2, dir) > 0.0)
00419 {
00420 #ifdef TRACE_BOOLEAN21
00421 fprintf(trace, " Interseccao coincide com uma aresta do setor\n");
00422 #endif
00423
00424 return(TRUE);
00425 }
00426 else
00427 {
00428 #ifdef TRACE_BOOLEAN21
00429 fprintf(trace, " ref2 = %f %f %f\n", ref2[0], ref2[1], ref2[2]);
00430 fprintf(trace, " dir = %f %f %f\n", dir[0], dir[1], dir[2]);
00431 fprintf(trace, " Interseccao e aresta sao colineares, mas de direcoes distintas\n");
00432 #endif
00433
00434 return(FALSE);
00435 }
00436 }
00437 t1 = comp(dot(c1, ref12), 0.0, EPS);
00438 t2 = comp(dot(c2, ref12), 0.0, EPS);
00439 if ((t1 > 0) && (t2 > 0))
00440 {
00441 #ifdef TRACE_BOOLEAN21
00442 fprintf(trace, " Interseccao e interna ao setor\n");
00443 #endif
00444
00445 return(TRUE);
00446 }
00447
00448 #ifdef TRACE_BOOLEAN21
00449 fprintf(trace, " ref12 = %f %f %f\n", ref12[0], ref12[1], ref12[2]);
00450 fprintf(trace, " c1 = %f %f %f\n", c1[0], c1[1], c1[2]);
00451 fprintf(trace, " c2 = %f %f %f\n", c2[0], c2[1], c2[2]);
00452 fprintf(trace, " Interseccao e externa ao setor\n");
00453 #endif
00454
00455 return(FALSE);
00456 }
00457
00458 int MSD_lowSetOpOverlap(HPTYPE he1, HPTYPE he2)
00459 {
00460 MSD_lowNaoUtilizado(he2);
00461 MSD_lowNaoUtilizado(he1);
00462
00463 return(TRUE);
00464 }
00465
00466 void MSD_lowSetOpInside(HPTYPE he, vector in)
00467 {
00468 vector v1, v2, eq, dir;
00469
00470 veccopy(v1, VerVCoord(HalVtx(HalNxt(he))));
00471 veccopy(v2, VerVCoord(HalVtx(he)));
00472 vecminus(dir, v1, v2);
00473 MSD_lowFaceEq(FacFLOut(LooLFace(HalWLoop(he))), eq);
00474 cross(in, eq, dir);
00475 }