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 #include "splsplit.h"
00054
00055 extern SPTYPE sola;
00056 extern SPTYPE solb;
00057
00058 #ifdef TRACE_BOOLEAN
00059 void trace_he(HPTYPE h)
00060 {
00061 HPTYPE hm;
00062 HPTYPE hn;
00063 EPTYPE e;
00064 LPTYPE lo;
00065 LPTYPE lm;
00066 VPTYPE vv;
00067 extern FILE *trace;
00068
00069 e = HalEdg(h);
00070 hm = e == ENIL ? HNIL : mate(h);
00071 lo = HalWLoop(h);
00072 lm = e == ENIL ? LNIL : HalWLoop(hm);
00073 hn = e == ENIL ? HNIL : HalNxt(h);
00074 vv = HalVtx(h);
00075
00076 fprintf(trace, "*** halfedge f%3d-%3d v%3d-%3d %10.4f %10.4f %10.4f \n",
00077 FacFaceNo(LooLFace(lo)), e == ENIL ? -1 : FacFaceNo(LooLFace(lm)),
00078 VerVertexNo(HalVtx(h)), e == ENIL ? -1 : VerVertexNo(HalVtx(hn)),
00079 VerVCoord(vv)[0], VerVCoord(vv)[1], VerVCoord(vv)[2]);
00080 fprintf(trace, " %10.4f %10.4f %10.4f \n",
00081 e == ENIL ? 9999 : VerVCoord(HalVtx(hn))[0],
00082 e == ENIL ? 9999 : VerVCoord(HalVtx(hn))[1],
00083 e == ENIL ? 9999 : VerVCoord(HalVtx(hn))[2]);
00084 }
00085
00086 void trace_e(EPTYPE e)
00087 {
00088 HPTYPE he1;
00089 HPTYPE he2;
00090 VPTYPE v1;
00091 VPTYPE v2;
00092 LPTYPE l1;
00093 LPTYPE l2;
00094 extern FILE *trace;
00095
00096 he1 = EdgHe1(e);
00097 he2 = EdgHe2(e);
00098 v1 = HalVtx(he1);
00099 v2 = HalVtx(he2);
00100 l1 = HalWLoop(he1);
00101 l2 = HalWLoop(he2);
00102 fprintf(trace, "*** edge %3d f%3d-%3d v%3d-%3d %10.4f %10.4f %10.4f \n",
00103 EdgEdgeNo(e), FacFaceNo(LooLFace(l1)), FacFaceNo(LooLFace(l2)), \
00104 VerVertexNo(v1), VerVertexNo(v2),
00105 VerVCoord(v1)[0], VerVCoord(v1)[1], VerVCoord(v1)[2]);
00106 fprintf(trace, " %10.4f %10.4f %10.4f \n",
00107 VerVCoord(v2)[0], VerVCoord(v2)[1], VerVCoord(v2)[2]);
00108 }
00109
00110 void trace_nbr(int x)
00111 {
00112 HPTYPE he;
00113 HPTYPE hm;
00114 LPTYPE lo;
00115 LPTYPE lm;
00116 extern FILE *trace;
00117 static char *ff[] = { "OUT", "ON ", "IN " };
00118
00119 he = SetNBRSector(x);
00120 hm = HalEdg(he) == ENIL ? HNIL : mate(he);
00121 lo = HalWLoop(he);
00122 lm = hm == HNIL ? LNIL : HalWLoop(hm);
00123 fprintf(trace, "*** nbr[%2i] = f%3d-%3d v%3d-%3d %4s\n",
00124 x, FacFaceNo(LooLFace(lo)),
00125 lm == LNIL ? -1 : FacFaceNo(LooLFace(lm)),
00126 VerVertexNo(HalVtx(he)),
00127 hm == HNIL ? -1 : VerVertexNo(HalVtx(hm)),
00128 ff[SetNBRC1(x) + 1]);
00129 }
00130
00131 void trace_nba(int h)
00132 {
00133 extern FILE *trace;
00134 EPTYPE e;
00135 HPTYPE he;
00136 HPTYPE hnxt;
00137
00138 he = SetANBHe(h);
00139 e = HalEdg(he);
00140 hnxt = HalNxt(he);
00141 fprintf(trace, "*** nba[%2d].he f%3d-%3d v%3d-%3d %10.4f %10.4f %10.4f ***\n",
00142 h, e == ENIL ? -1 : FacFaceNo(LooLFace(HalWLoop(mate(he)))),
00143 FacFaceNo(LooLFace(HalWLoop(he))),
00144 VerVertexNo(HalVtx(he)),
00145 e == ENIL ? -1 : VerVertexNo(HalVtx(hnxt)),
00146 VerVCoord(HalVtx(he))[0],
00147 VerVCoord(HalVtx(he))[1],
00148 VerVCoord(HalVtx(he))[2]);
00149 fprintf(trace, " %10.4f %10.4f %10.4f \n",
00150 e == ENIL ? 9999 : VerVCoord(HalVtx(hnxt))[0],
00151 e == ENIL ? 9999 : VerVCoord(HalVtx(hnxt))[1],
00152 e == ENIL ? 9999 : VerVCoord(HalVtx(hnxt))[2]);
00153 fprintf(trace, " ref1 %10.4f %10.4f %10.4f \n",
00154 SetANB1(h) [0], SetANB1(h) [1], SetANB1(h) [2]);
00155 fprintf(trace, " ref2 %10.4f %10.4f %10.4f \n",
00156 SetANB2(h) [0], SetANB2(h) [1], SetANB2(h) [2]);
00157 fprintf(trace, " ref12 %10.4f %10.4f %10.4f \n",
00158 SetANB12(h)[0], SetANB12(h)[1], SetANB12(h)[2]);
00159 }
00160
00161 void trace_nbb(int h)
00162 {
00163 extern FILE *trace;
00164 EPTYPE e;
00165 HPTYPE he;
00166 HPTYPE hnxt;
00167
00168 he = SetBNBHe(h);
00169 e = HalEdg(he);
00170 hnxt = HalNxt(he);
00171 fprintf(trace, "*** nbb[%2d].he f%3d-%3d v%3d-%3d %10.4f %10.4f %10.4f ***\n",
00172 h, e == ENIL ? -1 : FacFaceNo(LooLFace(HalWLoop(mate(he)))),
00173 FacFaceNo(LooLFace(HalWLoop(he))),
00174 VerVertexNo(HalVtx(he)),
00175 e == ENIL ? -1 : VerVertexNo(HalVtx(hnxt)),
00176 VerVCoord(HalVtx(he))[0],
00177 VerVCoord(HalVtx(he))[1],
00178 VerVCoord(HalVtx(he))[2]);
00179 fprintf(trace, " %10.4f %10.4f %10.4f \n",
00180 e == ENIL ? 9999 : VerVCoord(HalVtx(hnxt))[0],
00181 e == ENIL ? 9999 : VerVCoord(HalVtx(hnxt))[1],
00182 e == ENIL ? 9999 : VerVCoord(HalVtx(hnxt))[2]);
00183 fprintf(trace, " ref1 %10.4f %10.4f %10.4f \n",
00184 SetBNB1(h) [0], SetBNB1(h) [1], SetBNB1(h) [2]);
00185 fprintf(trace, " ref2 %10.4f %10.4f %10.4f \n",
00186 SetBNB2(h) [0], SetBNB2(h) [1], SetBNB2(h) [2]);
00187 fprintf(trace, " ref12 %10.4f %10.4f %10.4f \n",
00188 SetANB12(h)[0], SetANB12(h)[1], SetANB12(h)[2]);
00189 }
00190
00191 int MSD_booleanBorderFace(FPTYPE f, int flag)
00192 {
00193 int i;
00194
00195 for (i = 0; i < (flag == 1 ? nfaca : nfacb); i++)
00196 {
00197 if (flag == 1)
00198 {
00199 if (f == SetSonfa(i))
00200 {
00201 return(TRUE);
00202 }
00203 }
00204 else
00205 if (f == SetSonfb(i))
00206 {
00207 return(TRUE);
00208 }
00209 }
00210 return(FALSE);
00211 }
00212
00213 int MSD_checkSetLoopShell(FPTYPE f, int flag)
00214 {
00215 FPTYPE f2;
00216 LPTYPE l;
00217 HPTYPE he;
00218
00219 if (MSD_booleanBorderFace(f, flag))
00220 {
00221 return(0);
00222 }
00223 if (!FaceBitNOK1(f))
00224 {
00225 return(1);
00226 }
00227 if (!FaceBitNOK2(f))
00228 {
00229 return(0);
00230 }
00231 SetFaceBitOK2(f);
00232 for (AllLoopsFace(f, l))
00233 {
00234 he = LooLEdg(l);
00235 do
00236 {
00237 f2 = LooLFace(HalWLoop(mate(he)));
00238 if (FaceBitNOK2(f2))
00239 {
00240 if (MSD_checkSetLoopShell(f2, flag) == 1)
00241 {
00242 return(1);
00243 }
00244 }
00245 } while ((he = HalNxt(he)) != LooLEdg(l));
00246 }
00247 return(0);
00248 }
00249
00250 void MSD_setLoopShell(FPTYPE f, int flag)
00251 {
00252 FPTYPE f2;
00253 LPTYPE l;
00254 HPTYPE he;
00255
00256 if (MSD_booleanBorderFace(f, flag))
00257 {
00258 return;
00259 }
00260 if (!FaceBitNOK1(f))
00261 {
00262 return;
00263 }
00264 SetFaceBitOK1(f);
00265 for (AllLoopsFace(f, l))
00266 {
00267 he = LooLEdg(l);
00268 do
00269 {
00270 f2 = LooLFace(HalWLoop(mate(he)));
00271 if (FaceBitNOK1(f2))
00272 {
00273 MSD_setLoopShell(f2, flag);
00274 }
00275 } while ((he = HalNxt(he)) != LooLEdg(l));
00276 }
00277 }
00278
00279 int MSD_checkBoolean(void)
00280 {
00281 DPTYPE d;
00282 FPTYPE f;
00283 LPTYPE l;
00284 HPTYPE he;
00285 int i;
00286
00287 fprintf(trace, "SOLID A: ------------------------>\n");
00288 for (i = 0; i < nfaca; i++)
00289 {
00290
00291 for (AllShellsSolid(sola, d))
00292 {
00293 for (AllFacesShell(d, f))
00294 {
00295 SetFaceBitNOK1(f);
00296 SetFaceBitNOK2(f);
00297 }
00298 }
00299 d = FacFShell(SetSonfa(i));
00300
00301
00302 l = InnerLoop(SetSonfa(i));
00303 SetFaceBitOK1(SetSonfa(i));
00304
00305
00306 he = LooLEdg(l);
00307 do
00308 {
00309 f = LooLFace(HalWLoop(mate(he)));
00310 MSD_setLoopShell(f, 1);
00311 } while ((he = HalNxt(he)) != LooLEdg(l));
00312
00313
00314 l = FacFLOut(SetSonfa(i));
00315 SetFaceBitOK2(SetSonfa(i));
00316
00317
00318 he = LooLEdg(l);
00319 do
00320 {
00321 f = LooLFace(HalWLoop(mate(he)));
00322 if (MSD_checkSetLoopShell(f, 1) == 1)
00323 {
00324 return(1);
00325 }
00326 } while ((he = HalNxt(he)) != LooLEdg(l));
00327 }
00328
00329 fprintf(trace, "SOLID B: ------------------------>\n");
00330 for (i = 0; i < nfacb; i++)
00331 {
00332
00333 for (AllShellsSolid(solb, d))
00334 {
00335 for (AllFacesShell(d, f))
00336 {
00337 SetFaceBitNOK1(f);
00338 SetFaceBitNOK2(f);
00339 }
00340 }
00341 d = FacFShell(SetSonfb(i));
00342
00343
00344 l = InnerLoop(SetSonfb(i));
00345 SetFaceBitOK1(SetSonfb(i));
00346
00347
00348 he = LooLEdg(l);
00349 do
00350 {
00351 f = LooLFace(HalWLoop(mate(he)));
00352 MSD_setLoopShell(f, 2);
00353 } while ((he = HalNxt(he)) != LooLEdg(l));
00354
00355
00356 l = FacFLOut(SetSonfb(i));
00357 SetFaceBitOK2(SetSonfb(i));
00358
00359
00360 he = LooLEdg(l);
00361 do
00362 {
00363 f = LooLFace(HalWLoop(mate(he)));
00364 if (MSD_checkSetLoopShell(f, 2) == 1)
00365 {
00366 return(1);
00367 }
00368 } while ((he = HalNxt(he)) != LooLEdg(l));
00369 }
00370 return(0);
00371 }
00372
00373 #endif