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 #include <string.h>
00043 #include <stdlib.h>
00044 #include "memvirtu.h"
00045 #include "lowparam.h"
00046 #include "lowmacro.h"
00047 #include "lowsolid.h"
00048 #include "eulerops.h"
00049 #include "lowgeome.h"
00050 #include "vectorop.h"
00051 #include "shpshape.h"
00052 #include "splsplit.h"
00053
00054
00055 void MSD_lowSplitClassify(vector SP)
00056 {
00057 int i;
00058
00059 #ifdef TRACE_SPLIT
00060 #ifdef TRACE_SPLIT2
00061 int j;
00062 static char *ff[] = { "BELOW ", "ON ", "ABOVE" };
00063 #endif
00064
00065 fprintf(trace, "\n\n\n");
00066 fprintf(trace, "*************************************************\n");
00067 fprintf(trace, "* *\n");
00068 fprintf(trace, "* SETSPLITCLASSIFY *\n");
00069 fprintf(trace, "* *\n");
00070 fprintf(trace, "*************************************************\n");
00071 fprintf(trace, "\n");
00072 #endif
00073
00074 for (spl_nedge = i = 0; i < spl_nvtx; ++i)
00075 {
00076 #ifdef TRACE_SPLIT2
00077 fprintf(trace, "\n*** plano = %10.4f %10.4f %10.4f %10.4f ***\n", SP[0], SP[1], SP[2], SP[3]);
00078 trace_v(SplSoov(i));
00079 #endif
00080
00081 MSD_lowGetNeighborhood(SplSoov(i), SP);
00082
00083 #ifdef TRACE_SPLIT2
00084 fprintf(trace, "\n*** getneighborhood ***\n");
00085 for (j = 0; j < spl_nnbr; ++j)
00086 {
00087 trace_nbr(j);
00088 }
00089 #endif
00090
00091 MSD_lowReclassifyOnSectors(SP);
00092
00093 #ifdef TRACE_SPLIT2
00094 fprintf(trace, "\n*** reclassifyonsectors ***\n");
00095 for (j = 0; j < spl_nnbr; ++j)
00096 {
00097 trace_nbr(j);
00098 }
00099 #endif
00100
00101 MSD_lowReclassifyOnEdges();
00102
00103 #ifdef TRACE_SPLIT2
00104 fprintf(trace, "\n*** reclassifyonedges ***\n");
00105 for (j = 0; j < spl_nnbr; ++j)
00106 {
00107 trace_nbr(j);
00108 }
00109 fprintf(trace, "\n");
00110 #endif
00111
00112 MSD_lowInsertNullEdges();
00113 }
00114
00115 #ifdef TRACE_SPLIT
00116 fprintf(trace, "\n");
00117 fprintf(trace, "*** setsplitclassify *** - nedge = %2i\n", spl_nedge);
00118 fprintf(trace, "*** estrutura sone ***\n");
00119 for (i = 0; i < spl_nedge; i++)
00120 {
00121 trace_e(SplSone(i));
00122 }
00123 #endif
00124 }
00125
00126
00127 void MSD_lowGetNeighborhood(VPTYPE v, vector SP)
00128 {
00129 HPTYPE he;
00130 VPTYPE vv;
00131 real dist;
00132
00133 #ifndef __VIRTUAL_MEM
00134 VTYPE bisect;
00135 #else
00136 VPTYPE bisect;
00137
00138 bisect = MSD_getMemVirtual(VERTEX);
00139 #endif
00140
00141 spl_nnbr = 0;
00142 he = VerVEdge(v);
00143 do
00144 {
00145 vv = HalVtx(HalNxt(he));
00146 dist = MSD_lowDistancePlanePoint(SP, vv);
00147 SplNBRC1(spl_nnbr) = comp(dist, 0.0, EPS);
00148 SplNBRSector(spl_nnbr) = he;
00149 spl_nnbr++;
00150 if (MSD_lowCheckWideness(he) == 1)
00151 {
00152 #ifndef __VIRTUAL_MEM
00153 MSD_lowBisector(he, bisect.vcoord);
00154 SplNBRSector(spl_nnbr) = he;
00155 SplNBRC1(spl_nnbr) = SplNBRC1(spl_nnbr - 1);
00156 dist = MSD_lowDistancePlanePoint(SP, &bisect);
00157 SplNBRC1(spl_nnbr - 1) = comp(dist, 0.0, EPS);
00158 spl_nnbr++;
00159 if (spl_nnbr == MAXEDGESFORVERTEX)
00160 {
00161 fprintf(stderr, "spl_nbr: falta memoria!\n");
00162 exit(1);
00163 }
00164 #else
00165 MSD_lowBisector(he, VerVCoord(bisect));
00166 SplNBRSector(spl_nnbr) = he;
00167 SplNBRC1(spl_nnbr) = SplNBRC1(spl_nnbr - 1);
00168 dist = MSD_lowDistancePlanePoint(SP, bisect);
00169 SplNBRC1(spl_nnbr - 1) = comp(dist, 0.0, EPS);
00170 spl_nnbr++;
00171 #endif
00172 }
00173 } while ((he = HalNxt(mate(he))) != VerVEdge(v));
00174
00175 #ifdef __VIRTUAL_MEM
00176 MSD_putMemVirtual(bisect, VERTEX);
00177 #endif
00178 }
00179
00180
00181 void MSD_lowReclassifyOnSectors(vector SP)
00182 {
00183 FPTYPE f;
00184 vector c;
00185 int i, j;
00186
00187 for (i = 0; i < spl_nnbr; ++i)
00188 {
00189 f = LooLFace(HalWLoop(SplNBRSector(i)));
00190 cross(c, FacFeq(f), SP);
00191 if (comp(dot(c, c), 0.0, EPS) == 0)
00192 {
00193 if (comp(dot(FacFeq(f), SP), 0.0, EPS) == 1)
00194 {
00195 SplNBRC1(i) = BELOW;
00196 j = (i + spl_nnbr - 1) % spl_nnbr;
00197 SplNBRC1(j) = BELOW;
00198 }
00199 else
00200 {
00201 SplNBRC1(i) = ABOVE;
00202 j = (i + spl_nnbr - 1) % spl_nnbr;
00203 SplNBRC1(j) = ABOVE;
00204 }
00205 }
00206 }
00207 }
00208
00209
00210 void MSD_lowReclassifyOnEdges(void)
00211 {
00212 int i;
00213
00214 for (i = 0; i < spl_nnbr; ++i)
00215 {
00216 if (SplNBRC1(i) == ON)
00217 {
00218 if (SplNBRC1((spl_nnbr + i - 1) % spl_nnbr) == BELOW)
00219 {
00220 SplNBRC1(i) = SplNBRC1((i + 1) % spl_nnbr) == BELOW ? ABOVE : BELOW;
00221 }
00222 else
00223 {
00224 SplNBRC1(i) = BELOW;
00225 }
00226 }
00227 }
00228 }
00229
00230
00231 void MSD_lowInsertNullEdges(void)
00232 {
00233 int start, i;
00234 HPTYPE head;
00235 HPTYPE tail;
00236
00237 i = 0;
00238 while (!(SplNBRC1(i) == BELOW && SplNBRC1((i + 1) % spl_nnbr) == ABOVE))
00239 {
00240 if (++i == spl_nnbr)
00241 {
00242 return;
00243 }
00244 }
00245 start = i;
00246 head = SplNBRSector((i + 1) % spl_nnbr);
00247 while (1)
00248 {
00249 while (!(SplNBRC1(i) == ABOVE && SplNBRC1((i + 1) % spl_nnbr) == BELOW))
00250 {
00251 i = (i + 1) % spl_nnbr;
00252 }
00253 tail = SplNBRSector((i + 1) % spl_nnbr);
00254
00255 #ifdef TRACE_SPLIT2
00256 fprintf(trace, "*** Aplicando o operador MEV\n");
00257 trace_he(head);
00258 trace_he(tail);
00259 #endif
00260 MSD_lowMEV(head, tail, maxv++, VerVCoord(HalVtx(head))[0],
00261 VerVCoord(HalVtx(head))[1],
00262 VerVCoord(HalVtx(head))[2]);
00263 #ifdef TRACE_SPLIT2
00264 fprintf(trace, "*** Aresta inserida na SONE\n");
00265 trace_e(HalEdg(HalPrv(head)));
00266 #endif
00267 SplSone(spl_nedge) = HalEdg(HalPrv(head));
00268 spl_nedge++;
00269 while (!(SplNBRC1(i) == BELOW && SplNBRC1((i + 1) % spl_nnbr) == ABOVE))
00270 {
00271 if ((i = (i + 1) % spl_nnbr) == start)
00272 {
00273 return;
00274 }
00275 }
00276 head = SplNBRSector((i + 1) % spl_nnbr);
00277 }
00278 }
00279
00280
00281
00282
00283
00284 int MSD_lowCheckWideness(HPTYPE he)
00285 {
00286 vector ref1, ref2, ref12;
00287 vector v1, v2, v3;
00288
00289 veccopy(v1, VerVCoord(HalVtx(HalPrv(he))));
00290 veccopy(v2, VerVCoord(HalVtx(HalNxt(he))));
00291 veccopy(v3, VerVCoord(HalVtx(he)));
00292 vecminus(ref1, v1, v3);
00293 vecminus(ref2, v2, v3);
00294 cross(ref12, ref1, ref2);
00295 if (vecnull(ref12, EPS))
00296 {
00297 return(1);
00298 }
00299 return((dot(ref12, FacFeq(LooLFace(HalWLoop(he)))) > 0.0) ? 1 : 0);
00300 }
00301
00302 void MSD_lowBisector(HPTYPE he, vector bisect)
00303 {
00304 vector aa, bb, cc, vhe;
00305
00306 veccopy(vhe, VerVCoord(HalVtx(he)));
00307 vecminus(aa, VerVCoord(HalVtx(HalPrv(he))), vhe);
00308 vecminus(bb, VerVCoord(HalVtx(HalNxt(he))), vhe);
00309 vecplus(cc, aa, bb);
00310 vecminus(bisect, vhe, cc);
00311 }
00312
00313 double MSD_lowDistancePlanePoint(vector SP, VPTYPE p)
00314 {
00315 double dis;
00316
00317 dis = dot(VerVCoord(p), SP) + SP[3];
00318 if (comp(dis, 0.0, EPS) == 0)
00319 {
00320 return(0.0);
00321 }
00322 return(dis);
00323 }