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 #if 0
00034
00035
00036
00037
00038
00039 struct groupie {
00040 struct bu_list l;
00041 struct loopuse *lu;
00042 }
00043
00044 struct loopgroup {
00045 struct bu_list l;
00046 struct bu_list groupies;
00047 } groups;
00048
00049
00050 struct loopgroup *
00051 group(lu, groups)
00052 struct loopuse *lu;
00053 struct bu_list *groups;
00054 {
00055 struct loopgroup *group;
00056 struct groupie *groupie;
00057
00058 for (BU_LIST_FOR(group, loopgroup, groups)) {
00059 for (BU_LIST_FOR(groupie, groupie, &groupies)) {
00060 if (groupie->lu == lu)
00061 return(group);
00062 }
00063 }
00064 return NULL;
00065 }
00066
00067 void
00068 new_loop_group(lu, groups)
00069 struct loopuse *lu;
00070 struct bu_list *groups;
00071 {
00072 struct loopgroup *lg;
00073 struct groupie *groupie;
00074
00075 lg = (struct loopgroup *)bu_calloc(sizeof(struct loopgroup), "loopgroup");
00076 groupie = (struct groupie *)bu_calloc(sizeof(struct groupie), "groupie");
00077 groupie->lu = lu;
00078
00079 BU_LIST_INIT(&lg->groupies);
00080 BU_LIST_APPEND(&lg->groupies, &groupie->l);
00081 BU_LIST_APPEND(groups, &lg.l);
00082 }
00083
00084 void
00085 merge_groups(lg1, lg2);
00086 struct loopgroup *lg1, *lg2;
00087 {
00088 struct groupie *groupie;
00089
00090 while (BU_LIST_WHILE(groupie, groupie, &lg2->groupies)) {
00091 BU_LIST_DEQUEUE(&(groupie->l));
00092 BU_LIST_APPEND(&(lg1->groupies), &(groupie->l))
00093 }
00094 RT_DEQUEUE(&(lg2->l));
00095 bu_free((char *)lg2, "free loopgroup 2 of merge");
00096 }
00097 void
00098 free_groups(head)
00099 struct bu_list *head;
00100 {
00101 while
00102 }
00103
00104 BU_LIST_INIT(&groups);
00105
00106 for (BU_LIST_FOR(lu, loopuse, &fu->lu_hd)) {
00107
00108
00109 if (lu->orientation == OT_OPPOSITE)
00110 continue;
00111
00112 if (group(lu) == NULL)
00113 new_loop_group(lu, &groups);
00114
00115 for (BU_LIST_FOR(lu2, loopuse, &fu->lu_hd)) {
00116 if (lu == lu2 ||
00117 group(lu, &groups) == group(lu2, &groups))
00118 continue;
00119 if (loops_touch_or_overlap(lu, lu2))
00120 merge_groups(group(lu), group(lu2));
00121 }
00122
00123
00124
00125 }
00126 #endif
00127
00128 #if 0
00129
00130
00131
00132
00133
00134
00135
00136
00137 nmg_eu_sq(eu)
00138 struct edgeuse *eu;
00139 {
00140 struct edgeuse *matenext;
00141 NMG_CK_EDGEUSE(eu);
00142 NMG_CK_EDGEUSE(eu->eumate_p);
00143
00144
00145
00146
00147
00148
00149
00150
00151 matenext = BU_LIST_PNEXT_CIRC(eu->eumate_p);
00152 NMG_CK_EDGEUSE(matenext);
00153
00154 BU_LIST_DEQUEUE(eu);
00155 BU_LIST_DEQUEUE(matenext);
00156
00157 }
00158 #endif
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183 struct shell *
00184 nmg_polytonmg(fp, r, tol)
00185 FILE *fp;
00186 struct nmgregion *r;
00187 const struct bn_tol *tol;
00188 {
00189 int i, j, num_pts, num_facets, pts_this_face, facet;
00190 int vl_len;
00191 struct vertex **v;
00192 struct vertex **vl;
00193 point_t p;
00194 struct shell *s;
00195 struct faceuse *fu;
00196 struct loopuse *lu;
00197 struct edgeuse *eu;
00198 plane_t plane;
00199 struct model *m;
00200
00201 s = nmg_msv(r);
00202 m = s->r_p->m_p;
00203 nmg_kvu(s->vu_p);
00204
00205
00206 if (fscanf(fp, "%d %d", &num_pts, &num_facets) != 2)
00207 rt_bomb("polytonmg() Error in first line of poly file\n");
00208 else
00209 if (rt_g.NMG_debug & DEBUG_POLYTO)
00210 bu_log("points: %d facets: %d\n",
00211 num_pts, num_facets);
00212
00213
00214 v = (struct vertex **) bu_calloc(num_pts, sizeof (struct vertex *),
00215 "vertices");
00216
00217
00218 for (i = 0 ; i < num_pts ; ++i) {
00219 GET_VERTEX(v[i], m);
00220 v[i]->magic = NMG_VERTEX_MAGIC;
00221 }
00222
00223
00224 for (i=0 ; i < num_pts ; ++i) {
00225 if (fscanf(fp, "%lg %lg %lg", &p[0], &p[1], &p[2]) != 3)
00226 rt_bomb("polytonmg() Error reading point");
00227 else
00228 if (rt_g.NMG_debug & DEBUG_POLYTO)
00229 bu_log("read vertex #%d (%g %g %g)\n",
00230 i, p[0], p[1], p[2]);
00231
00232 nmg_vertex_gv(v[i], p);
00233 }
00234
00235 vl = (struct vertex **)bu_calloc(vl_len=8, sizeof (struct vertex *),
00236 "vertex parameter list");
00237
00238 for (facet = 0 ; facet < num_facets ; ++facet) {
00239 if (fscanf(fp, "%d", &pts_this_face) != 1)
00240 rt_bomb("polytonmg() error getting pt count for this face");
00241
00242 if (rt_g.NMG_debug & DEBUG_POLYTO)
00243 bu_log("facet %d pts in face %d\n",
00244 facet, pts_this_face);
00245
00246 if (pts_this_face > vl_len) {
00247 while (vl_len < pts_this_face) vl_len *= 2;
00248 vl = (struct vertex **)rt_realloc( (char *)vl,
00249 vl_len*sizeof(struct vertex *),
00250 "vertex parameter list (realloc)");
00251 }
00252
00253 for (i=0 ; i < pts_this_face ; ++i) {
00254 if (fscanf(fp, "%d", &j) != 1)
00255 rt_bomb("polytonmg() error getting point index for v in f");
00256 vl[i] = v[j-1];
00257 }
00258
00259 fu = nmg_cface(s, vl, pts_this_face);
00260 lu = BU_LIST_FIRST( loopuse, &fu->lu_hd );
00261
00262 eu = BU_LIST_FIRST( edgeuse, &lu->down_hd );
00263 NMG_CK_EDGEUSE(eu);
00264 if (bn_mk_plane_3pts(plane, eu->vu_p->v_p->vg_p->coord,
00265 BU_LIST_PNEXT(edgeuse,eu)->vu_p->v_p->vg_p->coord,
00266 BU_LIST_PLAST(edgeuse,eu)->vu_p->v_p->vg_p->coord,
00267 tol ) ) {
00268 bu_log("At %d in %s\n", __LINE__, __FILE__);
00269 rt_bomb("polytonmg() cannot make plane equation\n");
00270 }
00271 else nmg_face_g(fu, plane);
00272 }
00273
00274 for (i=0 ; i < num_pts ; ++i) {
00275 if( BU_LIST_IS_EMPTY( &v[i]->vu_hd ) ) continue;
00276 FREE_VERTEX(v[i]);
00277 }
00278 bu_free( (char *)v, "vertex array");
00279 return(s);
00280 }
00281
00282
00283 int heap_find(), heap_insert();
00284 struct vertex **init_heap();
00285 void heap_increase();
00286 int heap_cur_sz;
00287
00288 main()
00289 {
00290 sz = 1000;
00291 verts[0] = init_heap(sz);
00292 }
00293
00294
00295
00296
00297
00298
00299
00300
00301 struct vertex **
00302 init_heap(n)
00303 int n;
00304 {
00305 extern int heap_cur_sz;
00306 struct vertex **heap;
00307
00308 heap_cur_sz = 1;
00309 heap = (struct vertex **)
00310 bu_malloc(1 + n*sizeof(struct vertex *), "heap");
00311 if (heap == (struct vertex **)NULL) {
00312 bu_log("init_heap: no mem\n");
00313 rt_bomb("");
00314 }
00315 return(heap);
00316 }
00317
00318
00319
00320
00321
00322
00323 void
00324 heap_increase(h, n)
00325 struct vertex **h[1];
00326 int *n;
00327 {
00328 struct vertex **big_heap;
00329 int i;
00330
00331 big_heap = (struct vertex **)
00332 bu_malloc(1 + 3 * (*n) * sizeof(struct vertex *), "heap");
00333 if (big_heap == (struct vertex **)NULL)
00334 rt_bomb("heap_increase: no mem\n");
00335 for (i = 1; i <= *n; i++)
00336 big_heap[i] = h[0][i];
00337 *n *= 3;
00338 bu_free((char *)h[0], "heap");
00339 h[0] = big_heap;
00340 }
00341
00342
00343
00344
00345
00346
00347
00348 int
00349 heap_insert(h, n, i)
00350 struct vertex **h[1];
00351 int *n;
00352 struct vertex *i;
00353 {
00354 extern int heap_cur_sz;
00355 struct vertex **new_heap, *tmp;
00356 int cur, done;
00357
00358 if (heap_find(h[0], heap_cur_sz, i, 1))
00359 return(heap_cur_sz);
00360
00361 if (heap_cur_sz > *n)
00362 heap_increase(h, n);
00363
00364 cur = heap_cur_sz;
00365 h[0][cur] = i;
00366
00367
00368 done = 0;
00369 while (cur > 1 && !done)
00370 if (h[0][cur] < h[0][cur>>1]) {
00371 tmp = h[0][cur>>1];
00372 h[0][cur>>1] = h[0][cur];
00373 h[0][cur] = tmp;
00374 cur >>= 1;
00375 } else
00376 done = 1;
00377 heap_cur_sz++;
00378 return(heap_cur_sz);
00379 }
00380
00381
00382
00383
00384
00385
00386
00387 int
00388 heap_find(h, n, i, loc)
00389 struct vertex **h;
00390 int n;
00391 struct vertex *i;
00392 int loc;
00393 {
00394 int retval;
00395
00396 if (loc > n || h[loc] > i)
00397 retval = 0;
00398 else if (h[loc] == i)
00399 retval = loc;
00400 else {
00401 loc <<= 1;
00402 retval = heap_find(h, n, i, loc);
00403 if (!retval)
00404 retval = heap_find(h, n, i, loc+1);
00405 }
00406 return(retval);
00407 }
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426 void
00427 nmg_isect_face3p_shell_int( is, fu1, s2 )
00428 struct nmg_inter_struct *is;
00429 struct faceuse *fu1;
00430 struct shell *s2;
00431 {
00432 struct shell *s1;
00433 struct loopuse *lu1;
00434 struct edgeuse *eu1;
00435
00436 NMG_CK_INTER_STRUCT(is);
00437 NMG_CK_FACEUSE(fu1);
00438 NMG_CK_SHELL(s2);
00439 s1 = fu1->s_p;
00440 NMG_CK_SHELL(s1);
00441
00442 if (rt_g.NMG_debug & DEBUG_POLYSECT)
00443 bu_log("nmg_isect_face3p_shell_int(, fu1=x%x, s2=x%x) START\n", fu1, s2 );
00444
00445 for( BU_LIST_FOR( lu1, loopuse, &fu1->lu_hd ) ) {
00446 NMG_CK_LOOPUSE(lu1);
00447 if( BU_LIST_FIRST_MAGIC( &lu1->down_hd ) == NMG_VERTEXUSE_MAGIC)
00448 continue;
00449 for( BU_LIST_FOR( eu1, edgeuse, &lu1->down_hd ) ) {
00450 struct edgeuse *eu2;
00451
00452 eu2 = nmg_find_matching_eu_in_s( eu1, s2 );
00453 if( eu2 ) {
00454 bu_log("nmg_isect_face3p_shell_int() eu1=x%x, e1=x%x, eu2=x%x, e2=x%x (nothing to do)\n", eu1, eu1->e_p, eu2, eu2->e_p);
00455
00456
00457
00458 continue;
00459 }
00460
00461
00462
00463
00464 bu_log("nmg_isect_face3p_shell_int(, s2=x%x) eu1=x%x, no eu2\n", s2, eu1);
00465 nmg_isect_edge3p_shell( is, eu1, s2 );
00466 }
00467 }
00468
00469 if (rt_g.NMG_debug & DEBUG_POLYSECT)
00470 bu_log("nmg_isect_face3p_shell_int(, fu1=x%x, s2=x%x) END\n", fu1, s2 );
00471 }
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481