nmg_junk.c

Go to the documentation of this file.
00001 /*                      N M G _ J U N K . C
00002  * BRL-CAD
00003  *
00004  * Copyright (c) 2004-2006 United States Government as represented by
00005  * the U.S. Army Research Laboratory.
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public License
00009  * as published by the Free Software Foundation; either version 2 of
00010  * the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Library General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this file; see the file named COPYING for more
00019  * information.
00020  */
00021 
00022 /** @addtogroup nmg */
00023 /*@{*/
00024 /** @file nmg_junk.c
00025  *  This module is a resting place for unfinished subroutines
00026  *  that are NOT a part of the current NMG library, but which
00027  *  were sufficiently far along as to be worth saving.
00028  */
00029 /*@}*/
00030 
00031 
00032 
00033 #if 0
00034 /*XXX   Group sets of loops within a face into overlapping units.
00035  *      This will allow us to separate dis-associated groups into separate
00036  *      (but equal ;-) faces
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                 /* build loops out of exterior loops only */
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 /**                     N M G _ E U _ S Q
00130  *
00131  *      squeeze an edgeuse out of a list
00132  *
00133  *      All uses of the edge being "Squeezed" must be followed by
00134  *      the same "next" edge
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         /* foreach use of this edge, there must be exactly one use of the
00145          * previous edge.  There may not be any "extra" uses of the
00146          * previous edge
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  *                      N M G _ P O L Y T O N M G
00162  *
00163  *      Read a polygon file and convert it to an NMG shell
00164  *
00165  *      A polygon file consists of the following:
00166  *      The first line consists of two integer numbers: the number of points
00167  *      (vertices) in the file, followed by the number of polygons in the file.
00168  *      This line is followed by lines for each of the
00169  *      verticies.  Each vertex is listed on its own line, as the 3tuple
00170  *      "X Y Z".  After the list of verticies comes the list of polygons.
00171  *      each polygon is represented by a line containing 1) the number of
00172  *      verticies in the polygon, followed by 2) the indicies of the verticies
00173  *      that make up the polygon.
00174  *
00175  *      Implicit return:
00176  *              r->s_p  A new shell containing all the faces from the
00177  *                      polygon file
00178  *
00179  *  XXX This is a horrible way to do this.  Lee violates his own rules
00180  *  about not creating fundamental structures on his own...  :-)
00181  *  Retired in favor of more modern tessellation strategies.
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;              /* list of all vertices */
00192         struct vertex **vl;     /* list of vertices for this polygon*/
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         /* get number of points & number of facets in file */
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         /* build the vertices */
00218         for (i = 0 ; i < num_pts ; ++i) {
00219                 GET_VERTEX(v[i], m);
00220                 v[i]->magic = NMG_VERTEX_MAGIC;
00221         }
00222 
00223         /* read in the coordinates of the vertices */
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                 /* XXX should check for vertex-loop */
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;    /* Next free spot in heap. */
00287 
00288 main()
00289 {
00290         sz = 1000;
00291         verts[0] = init_heap(sz);
00292 }
00293 
00294 
00295 /**
00296 *       I N I T _ H E A P
00297 *
00298 *       Initialize an array-based implementation of a heap of vertex structs.
00299 *       (Heap: Binary tree w/value of parent > than that of children.)
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 *       H E A P _ I N C R E A S E
00320 *
00321 *       Make a heap bigger to make room for new entries.
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 *       H E A P _ I N S E R T
00344 *
00345 *       Insert a vertex struct into the heap (only if it is
00346 *       not already there).
00347 */
00348 int
00349 heap_insert(h, n, i)
00350 struct vertex   **h[1]; /* Heap of vertices. */
00351 int             *n;     /* Max size of heap. */
00352 struct vertex   *i;     /* Item to insert. */
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)) /* Already in heap. */
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;  /* Put at bottom of heap. */
00366 
00367         /* Bubble item up in heap. */
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 *       H E A P _ F I N D
00383 *
00384 *       See if a given vertex struct is in the heap.  If so,
00385 *       return its location in the heap array.
00386 */
00387 int
00388 heap_find(h, n, i, loc)
00389 struct vertex   **h;    /* Heap of vertexs. */
00390 int             n;      /* Max size of heap. */
00391 struct vertex   *i;     /* Item to search for. */
00392 int             loc;    /* Location to start search at. */
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  *                      N M G _ I S E C T _ F A C E 3 P _ S H E L L _ I N T
00413  *
00414  *  Intersect all the edges in fu1 that don't lie on any of the faces
00415  *  of shell s2 with s2, i.e. "interior" edges, where the
00416  *  endpoints lie on s2, but the edge is not shared with a face of s2.
00417  *  Such edges wouldn't have been processed by
00418  *  the NEWLINE version of nmg_isect_two_generic_faces(), so
00419  *  intersections need to be looked for here.
00420  *  Fortunately, it's easy to reject everything except edges that need
00421  *  processing using only the topology structures.
00422  *
00423  *  The "_int" at the end of the name is to signify that this routine
00424  *  does only "interior" edges, and is not a general face/shell intersector.
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                                 /*  Whether the edgeuse is in a face, or a
00456                                  *  wire edgeuse, the other guys will isect it.
00457                                  */
00458                                 continue;
00459                         }
00460                         /*  vu2a and vu2b are in shell s2, but there is no
00461                          *  edge running between them in shell s2.
00462                          *  Create a line of intersection, and go to it!.
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  * Local Variables:
00475  * mode: C
00476  * tab-width: 8
00477  * c-basic-offset: 4
00478  * indent-tabs-mode: t
00479  * End:
00480  * ex: shiftwidth=4 tabstop=8
00481  */

Generated on Mon Sep 18 01:24:53 2006 for BRL-CAD by  doxygen 1.4.6