BRL-CAD
nmg_junk.c
Go to the documentation of this file.
1 /* N M G _ J U N K . C
2  * BRL-CAD
3  *
4  * Copyright (c) 2004-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 /** @addtogroup nmg */
21 /** @{ */
22 /** @file primitives/nmg/nmg_junk.c
23  *
24  * This module is a resting place for unfinished subroutines that are
25  * NOT a part of the current NMG library, but which were sufficiently
26  * far along as to be worth saving.
27  *
28  * THESE ROUTINES ARE ALL MARKED STATIC AS THEY ARE EXPERIMENTAL AND
29  * NOT YET INTENDED TO BE USED. ASK A BRL-CAD DEVELOPER IF YOU NEED
30  * SOMETHING IN HERE WHAT IT WILL TAKE TO ENABLE THE ROUTINE.
31  *
32  * NOTE: THIS FILE SHOULD BE ENABLED FOR COMPILATION SO THAT IT CAN
33  * CONTINUE TO BE MAINTAINED UNTIL MIGRATION TO LIBNMG.
34  *
35  */
36 /** @} */
37 
38 #include "common.h"
39 
40 #include <string.h>
41 #include "bio.h"
42 
43 
44 #include "bn.h"
45 #include "vmath.h"
46 #include "raytrace.h"
47 
48 
49 /**
50  * Read a polygon file and convert it to an NMG shell
51  *
52  * A polygon file consists of the following:
53  *
54  * The first line consists of two integer numbers: the number of
55  * points (vertices) in the file, followed by the number of polygons
56  * in the file. This line is followed by lines for each of the
57  * vertices. Each vertex is listed on its own line, as the 3tuple "X
58  * Y Z". After the list of vertices comes the list of polygons.
59  * each polygon is represented by a line containing 1) the number of
60  * vertices in the polygon, followed by 2) the indices of the
61  * vertices that make up the polygon.
62  *
63  * Implicitly returns r->s_p which is a new shell containing all the
64  * faces from the polygon file.
65  *
66  * XXX This is a horrible way to do this. Lee violates his own rules
67  * about not creating fundamental structures on his own... :-)
68  * Retired in favor of more modern tessellation strategies.
69  */
70 struct shell *
71 nmg_polytonmg(FILE *fp, struct nmgregion *r, const struct bn_tol *tol)
72 {
73  int i, j, num_pts, num_facets, pts_this_face, facet;
74  int vl_len;
75  struct vertex **v; /* list of all vertices */
76  struct vertex **vl; /* list of vertices for this polygon*/
77  point_t p;
78  struct shell *s;
79  struct faceuse *fu;
80  struct loopuse *lu;
81  struct edgeuse *eu;
82  plane_t plane;
83  struct model *m;
84 
85  s = nmg_msv(r);
86  m = s->r_p->m_p;
87  nmg_kvu(s->vu_p);
88 
89  /* get number of points & number of facets in file */
90  if (fscanf(fp, "%d %d", &num_pts, &num_facets) != 2)
91  bu_bomb("polytonmg() Error in first line of poly file\n");
92  else
93  if (RTG.NMG_debug & DEBUG_POLYTO)
94  bu_log("points: %d facets: %d\n",
95  num_pts, num_facets);
96 
97 
98  v = (struct vertex **) bu_calloc(num_pts, sizeof (struct vertex *),
99  "vertices");
100 
101  /* build the vertices */
102  for (i = 0; i < num_pts; ++i) {
103  GET_VERTEX(v[i], m);
104  v[i]->magic = NMG_VERTEX_MAGIC;
105  }
106 
107  /* read in the coordinates of the vertices */
108  for (i=0; i < num_pts; ++i) {
109  if (fscanf(fp, "%lg %lg %lg", &p[0], &p[1], &p[2]) != 3)
110  bu_bomb("polytonmg() Error reading point");
111  else
112  if (RTG.NMG_debug & DEBUG_POLYTO)
113  bu_log("read vertex #%d (%g %g %g)\n",
114  i, p[0], p[1], p[2]);
115 
116  nmg_vertex_gv(v[i], p);
117  }
118 
119  vl = (struct vertex **)bu_calloc(vl_len=8, sizeof (struct vertex *),
120  "vertex parameter list");
121 
122  for (facet = 0; facet < num_facets; ++facet) {
123  if (fscanf(fp, "%d", &pts_this_face) != 1)
124  bu_bomb("polytonmg() error getting pt count for this face");
125 
126  if (RTG.NMG_debug & DEBUG_POLYTO)
127  bu_log("facet %d pts in face %d\n",
128  facet, pts_this_face);
129 
130  if (pts_this_face > vl_len) {
131  while (vl_len < pts_this_face) vl_len *= 2;
132  vl = (struct vertex **)bu_realloc((char *)vl,
133  vl_len*sizeof(struct vertex *),
134  "vertex parameter list (realloc)");
135  }
136 
137  for (i=0; i < pts_this_face; ++i) {
138  if (fscanf(fp, "%d", &j) != 1)
139  bu_bomb("polytonmg() error getting point index for v in f");
140  vl[i] = v[j-1];
141  }
142 
143  fu = nmg_cface(s, vl, pts_this_face);
144  lu = BU_LIST_FIRST(loopuse, &fu->lu_hd);
145  /* XXX should check for vertex-loop */
146  eu = BU_LIST_FIRST(edgeuse, &lu->down_hd);
147  NMG_CK_EDGEUSE(eu);
148  if (bn_mk_plane_3pts(plane, eu->vu_p->v_p->vg_p->coord,
149  BU_LIST_PNEXT(edgeuse, eu)->vu_p->v_p->vg_p->coord,
150  BU_LIST_PLAST(edgeuse, eu)->vu_p->v_p->vg_p->coord,
151  tol)) {
152  bu_log("At %d in %s\n", __LINE__, __FILE__);
153  bu_bomb("polytonmg() cannot make plane equation\n");
154  } else nmg_face_g(fu, plane);
155  }
156 
157  for (i=0; i < num_pts; ++i) {
158  if (BU_LIST_IS_EMPTY(&v[i]->vu_hd)) continue;
159  FREE_VERTEX(v[i]);
160  }
161  bu_free((char *)v, "vertex array");
162  return s;
163 }
164 
165 
166 /**
167  * Intersect all the edges in fu1 that don't lie on any of the faces
168  * of shell s2 with s2, i.e. "interior" edges, where the endpoints lie
169  * on s2, but the edge is not shared with a face of s2. Such edges
170  * wouldn't have been processed by the NEWLINE version of
171  * nmg_isect_two_generic_faces(), so intersections need to be looked
172  * for here. Fortunately, it's easy to reject everything except edges
173  * that need processing using only the topology structures.
174  *
175  * The "_int" at the end of the name is to signify that this routine
176  * does only "interior" edges, and is not a general face/shell
177  * intersector.
178  */
179 void
180 nmg_isect_face3p_shell_int(struct nmg_inter_struct *is, struct faceuse *fu1, struct shell *s2)
181 {
182  struct shell *s1;
183  struct loopuse *lu1;
184  struct edgeuse *eu1;
185 
187  NMG_CK_FACEUSE(fu1);
188  NMG_CK_SHELL(s2);
189  s1 = fu1->s_p;
190  NMG_CK_SHELL(s1);
191 
192  if (RTG.NMG_debug & DEBUG_POLYSECT)
193  bu_log("nmg_isect_face3p_shell_int(, fu1=x%x, s2=x%x) START\n", fu1, s2);
194 
195  for (BU_LIST_FOR (lu1, loopuse, &fu1->lu_hd)) {
196  NMG_CK_LOOPUSE(lu1);
197  if (BU_LIST_FIRST_MAGIC(&lu1->down_hd) == NMG_VERTEXUSE_MAGIC)
198  continue;
199  for (BU_LIST_FOR (eu1, edgeuse, &lu1->down_hd)) {
200  struct edgeuse *eu2;
201 
202  eu2 = nmg_find_matching_eu_in_s(eu1, s2);
203  if (eu2) {
204  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);
205  /* Whether the edgeuse is in a face, or a wire
206  * edgeuse, the other guys will isect it.
207  */
208  continue;
209  }
210  /* vu2a and vu2b are in shell s2, but there is no edge
211  * running between them in shell s2. Create a line of
212  * intersection, and go to it!.
213  */
214  bu_log("nmg_isect_face3p_shell_int(, s2=x%x) eu1=x%x, no eu2\n", s2, eu1);
215 /* XXX eso no existe todavia */
216 /* nmg_isect_edge3p_shell(is, eu1, s2); */
217  }
218  }
219 
220  if (RTG.NMG_debug & DEBUG_POLYSECT)
221  bu_log("nmg_isect_face3p_shell_int(, fu1=x%x, s2=x%x) END\n", fu1, s2);
222 }
223 
224 
225 /*
226  * Local Variables:
227  * mode: C
228  * tab-width: 8
229  * indent-tabs-mode: t
230  * c-file-style: "stroustrup"
231  * End:
232  * ex: shiftwidth=4 tabstop=8
233  */
#define BU_LIST_FOR(p, structure, hp)
Definition: list.h:365
void bu_log(const char *,...) _BU_ATTR_PRINTF12
Definition: log.c:176
struct faceuse * nmg_cface(struct shell *s, struct vertex **verts, int n)
Definition: nmg_mod.c:1130
#define NMG_VERTEX_MAGIC
Definition: magic.h:147
if lu s
Definition: nmg_mod.c:3860
lu
Definition: nmg_mod.c:3855
#define BU_LIST_IS_EMPTY(hp)
Definition: list.h:295
void nmg_vertex_gv(struct vertex *v, const fastf_t *pt)
Definition: nmg_mk.c:1668
void nmg_isect_face3p_shell_int(struct nmg_inter_struct *is, struct faceuse *fu1, struct shell *s2)
Definition: nmg_junk.c:180
void nmg_face_g(struct faceuse *fu, const fastf_t *p)
Definition: nmg_mk.c:2235
Header file for the BRL-CAD common definitions.
int nmg_kvu(struct vertexuse *vu)
Definition: nmg_mk.c:1095
NMG_CK_LOOPUSE(lu)
BU_LIST_DEQUEUE & eu1
Definition: nmg_mod.c:3839
#define BU_LIST_PLAST(structure, p)
Definition: list.h:424
uint32_t NMG_debug
debug bits for NMG's see nmg.h
Definition: raytrace.h:1699
void * bu_calloc(size_t nelem, size_t elsize, const char *str)
Definition: malloc.c:321
#define BU_LIST_PNEXT(structure, p)
Definition: list.h:422
struct shell * nmg_polytonmg(FILE *fp, struct nmgregion *r, const struct bn_tol *tol)
Definition: nmg_junk.c:71
void * bu_realloc(void *ptr, size_t siz, const char *str)
Support for uniform tolerances.
Definition: tol.h:71
struct shell * nmg_msv(struct nmgregion *r)
Definition: nmg_mk.c:423
#define BU_LIST_FIRST_MAGIC(hp)
Definition: list.h:416
#define NMG_VERTEXUSE_MAGIC
Definition: magic.h:145
struct edgeuse * nmg_find_matching_eu_in_s(const struct edgeuse *eu1, const struct shell *s2)
Definition: nmg_info.c:641
void bu_free(void *ptr, const char *str)
Definition: malloc.c:328
NMG_CK_SHELL(s)
#define NMG_CK_INTER_STRUCT(_p)
Definition: raytrace.h:2536
void bu_bomb(const char *str) _BU_ATTR_NORETURN
Definition: bomb.c:91
eu2
Definition: nmg_mod.c:3875
int bn_mk_plane_3pts(plane_t plane, const point_t a, const point_t b, const point_t c, const struct bn_tol *tol)
#define BU_LIST_FIRST(structure, hp)
Definition: list.h:312
struct rt_g RTG
Definition: globals.c:39