BRL-CAD
get_solid_kp.c
Go to the documentation of this file.
1 /* G E T _ S O L I D _ K P . C
2  * BRL-CAD
3  *
4  * Copyright (c) 2008-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 /** @file libged/get_solid_kp.c
21  *
22  * Return the default keypoint for a solid.
23  */
24 
25 #include "common.h"
26 
27 #include <string.h>
28 
29 #include "raytrace.h"
30 #include "wdb.h"
31 #include "nurb.h"
32 #include "./ged_private.h"
33 
34 
35 /*
36  * Default keypoint in model space is established in "pt". Returns
37  * GED_ERROR if unable to determine a keypoint, otherwise returns
38  * GED_OK.
39  */
40 int
41 _ged_get_solid_keypoint(struct ged *const gedp,
42  fastf_t *const pt,
43  const struct rt_db_internal *const ip,
44  const fastf_t *const mat)
45 {
46  point_t mpt;
47 
49 
50  switch (ip->idb_type) {
51  case ID_CLINE:
52  {
53  struct rt_cline_internal *cli =
54  (struct rt_cline_internal *)ip->idb_ptr;
55 
56  RT_CLINE_CK_MAGIC(cli);
57 
58  VMOVE(mpt, cli->v);
59  break;
60  }
61  case ID_PARTICLE:
62  {
63  struct rt_part_internal *part =
64  (struct rt_part_internal *)ip->idb_ptr;
65 
66  RT_PART_CK_MAGIC(part);
67 
68  VMOVE(mpt, part->part_V);
69  break;
70  }
71  case ID_PIPE:
72  {
73  struct rt_pipe_internal *pipeip;
74  struct wdb_pipept *pipe_seg;
75 
76  pipeip = (struct rt_pipe_internal *)ip->idb_ptr;
77 
78  RT_PIPE_CK_MAGIC(pipeip);
79 
80  pipe_seg = BU_LIST_FIRST(wdb_pipept, &pipeip->pipe_segs_head);
81  VMOVE(mpt, pipe_seg->pp_coord);
82  break;
83  }
84  case ID_METABALL:
85  {
86  struct rt_metaball_internal *metaball =
87  (struct rt_metaball_internal *)ip->idb_ptr;
88  struct wdb_metaballpt *metaballpt;
89 
90  RT_METABALL_CK_MAGIC(metaball);
91 
92  VSETALL(mpt, 0.0);
93  metaballpt = BU_LIST_FIRST(wdb_metaballpt,
94  &metaball->metaball_ctrl_head);
95  VMOVE(mpt, metaballpt->coord);
96  break;
97  }
98  case ID_ARBN:
99  {
100  struct rt_arbn_internal *arbn =
101  (struct rt_arbn_internal *)ip->idb_ptr;
102  size_t i, j, k;
103  int good_vert = 0;
104 
105  RT_ARBN_CK_MAGIC(arbn);
106  for (i = 0; i < arbn->neqn; i++) {
107  for (j = i + 1; j < arbn->neqn; j++) {
108  for (k = j + 1; k < arbn->neqn; k++) {
109  if (!bn_mkpoint_3planes(mpt, arbn->eqn[i],
110  arbn->eqn[j],
111  arbn->eqn[k])) {
112  size_t l;
113 
114  good_vert = 1;
115  for (l = 0; l < arbn->neqn; l++) {
116  if (l == i || l == j || l == k)
117  continue;
118 
119  if (DIST_PT_PLANE(mpt,
120  arbn->eqn[l]) >
121  gedp->ged_wdbp->wdb_tol.dist) {
122  good_vert = 0;
123  break;
124  }
125  }
126 
127  if (good_vert)
128  break;
129  }
130  }
131  if (good_vert)
132  break;
133  }
134  if (good_vert)
135  break;
136  }
137 
138  break;
139  }
140  case ID_EBM:
141  {
142  struct rt_ebm_internal *ebm =
143  (struct rt_ebm_internal *)ip->idb_ptr;
144  point_t pnt;
145 
146  RT_EBM_CK_MAGIC(ebm);
147 
148  VSETALL(pnt, 0.0);
149  MAT4X3PNT(mpt, ebm->mat, pnt);
150  break;
151  }
152  case ID_BOT:
153  {
154  struct rt_bot_internal *bot =
155  (struct rt_bot_internal *)ip->idb_ptr;
156 
157  VMOVE(mpt, bot->vertices);
158  break;
159  }
160  case ID_DSP:
161  {
162  struct rt_dsp_internal *dsp =
163  (struct rt_dsp_internal *)ip->idb_ptr;
164  point_t pnt;
165 
166  RT_DSP_CK_MAGIC(dsp);
167 
168  VSETALL(pnt, 0.0);
169  MAT4X3PNT(mpt, dsp->dsp_stom, pnt);
170  break;
171  }
172  case ID_HF:
173  {
174  struct rt_hf_internal *hf =
175  (struct rt_hf_internal *)ip->idb_ptr;
176 
177  RT_HF_CK_MAGIC(hf);
178 
179  VMOVE(mpt, hf->v);
180  break;
181  }
182  case ID_VOL:
183  {
184  struct rt_vol_internal *vol =
185  (struct rt_vol_internal *)ip->idb_ptr;
186  point_t pnt;
187 
188  RT_VOL_CK_MAGIC(vol);
189 
190  VSETALL(pnt, 0.0);
191  MAT4X3PNT(mpt, vol->mat, pnt);
192  break;
193  }
194  case ID_HALF:
195  {
196  struct rt_half_internal *haf =
197  (struct rt_half_internal *)ip->idb_ptr;
198  RT_HALF_CK_MAGIC(haf);
199 
200  VSCALE(mpt, haf->eqn, haf->eqn[H]);
201  break;
202  }
203  case ID_ARB8:
204  {
205  struct rt_arb_internal *arb =
206  (struct rt_arb_internal *)ip->idb_ptr;
207  RT_ARB_CK_MAGIC(arb);
208 
209  VMOVE(mpt, arb->pt[0]);
210  break;
211  }
212  case ID_ELL:
213  case ID_SPH:
214  {
215  struct rt_ell_internal *ell =
216  (struct rt_ell_internal *)ip->idb_ptr;
217  RT_ELL_CK_MAGIC(ell);
218 
219  VMOVE(mpt, ell->v);
220  break;
221  }
222  case ID_SUPERELL:
223  {
224  struct rt_superell_internal *superell =
225  (struct rt_superell_internal *)ip->idb_ptr;
226  RT_SUPERELL_CK_MAGIC(superell);
227 
228  VMOVE(mpt, superell->v);
229  break;
230  }
231  case ID_TOR:
232  {
233  struct rt_tor_internal *tor =
234  (struct rt_tor_internal *)ip->idb_ptr;
235  RT_TOR_CK_MAGIC(tor);
236 
237  VMOVE(mpt, tor->v);
238  break;
239  }
240  case ID_TGC:
241  case ID_REC:
242  {
243  struct rt_tgc_internal *tgc =
244  (struct rt_tgc_internal *)ip->idb_ptr;
245  RT_TGC_CK_MAGIC(tgc);
246 
247  VMOVE(mpt, tgc->v);
248  break;
249  }
250  case ID_GRIP:
251  {
252  struct rt_grip_internal *gip =
253  (struct rt_grip_internal *)ip->idb_ptr;
254  RT_GRIP_CK_MAGIC(gip);
255  VMOVE(mpt, gip->center);
256  break;
257  }
258  case ID_ARS:
259  {
260  struct rt_ars_internal *ars =
261  (struct rt_ars_internal *)ip->idb_ptr;
262  RT_ARS_CK_MAGIC(ars);
263 
264  VMOVE(mpt, &ars->curves[0][0]);
265  break;
266  }
267  case ID_RPC:
268  {
269  struct rt_rpc_internal *rpc =
270  (struct rt_rpc_internal *)ip->idb_ptr;
271  RT_RPC_CK_MAGIC(rpc);
272 
273  VMOVE(mpt, rpc->rpc_V);
274  break;
275  }
276  case ID_RHC:
277  {
278  struct rt_rhc_internal *rhc =
279  (struct rt_rhc_internal *)ip->idb_ptr;
280  RT_RHC_CK_MAGIC(rhc);
281 
282  VMOVE(mpt, rhc->rhc_V);
283  break;
284  }
285  case ID_EPA:
286  {
287  struct rt_epa_internal *epa =
288  (struct rt_epa_internal *)ip->idb_ptr;
289  RT_EPA_CK_MAGIC(epa);
290 
291  VMOVE(mpt, epa->epa_V);
292  break;
293  }
294  case ID_EHY:
295  {
296  struct rt_ehy_internal *ehy =
297  (struct rt_ehy_internal *)ip->idb_ptr;
298  RT_EHY_CK_MAGIC(ehy);
299 
300  VMOVE(mpt, ehy->ehy_V);
301  break;
302  }
303  case ID_HYP:
304  {
305  struct rt_hyp_internal *hyp =
306  (struct rt_hyp_internal *)ip->idb_ptr;
307  RT_HYP_CK_MAGIC(hyp);
308 
309  VMOVE(mpt, hyp->hyp_Vi);
310  break;
311  }
312  case ID_ETO:
313  {
314  struct rt_eto_internal *eto =
315  (struct rt_eto_internal *)ip->idb_ptr;
316  RT_ETO_CK_MAGIC(eto);
317 
318  VMOVE(mpt, eto->eto_V);
319  break;
320  }
321  case ID_POLY:
322  {
323  struct rt_pg_face_internal *_poly;
324  struct rt_pg_internal *pg =
325  (struct rt_pg_internal *)ip->idb_ptr;
326  RT_PG_CK_MAGIC(pg);
327 
328  _poly = pg->poly;
329  VMOVE(mpt, _poly->verts);
330  break;
331  }
332  case ID_SKETCH:
333  {
334  struct rt_sketch_internal *skt =
335  (struct rt_sketch_internal *)ip->idb_ptr;
336  RT_SKETCH_CK_MAGIC(skt);
337 
338  VMOVE(mpt, skt->V);
339  break;
340  }
341  case ID_EXTRUDE:
342  {
343  struct rt_extrude_internal *extr =
344  (struct rt_extrude_internal *)ip->idb_ptr;
345  RT_EXTRUDE_CK_MAGIC(extr);
346 
347  if (extr->skt && extr->skt->verts) {
348  VJOIN2(mpt, extr->V, extr->skt->verts[0][0], extr->u_vec,
349  extr->skt->verts[0][1], extr->v_vec);
350  } else {
351  VMOVE(mpt, extr->V);
352  }
353  break;
354  }
355  case ID_NMG:
356  {
357  struct vertex *v;
358  struct vertexuse *vu;
359  struct edgeuse *eu;
360  struct loopuse *lu;
361  struct faceuse *fu;
362  struct shell *s;
363  struct nmgregion *r;
364  struct model *m =
365  (struct model *) ip->idb_ptr;
366  NMG_CK_MODEL(m);
367 
368  /* set default first */
369  VSETALL(mpt, 0.0);
370 
371  if (BU_LIST_IS_EMPTY(&m->r_hd))
372  break;
373 
374  r = BU_LIST_FIRST(nmgregion, &m->r_hd);
375  if (!r)
376  break;
377  NMG_CK_REGION(r);
378 
379  if (BU_LIST_IS_EMPTY(&r->s_hd))
380  break;
381 
382  s = BU_LIST_FIRST(shell, &r->s_hd);
383  if (!s)
384  break;
385  NMG_CK_SHELL(s);
386 
387  if (BU_LIST_IS_EMPTY(&s->fu_hd))
388  fu = (struct faceuse *)NULL;
389  else
390  fu = BU_LIST_FIRST(faceuse, &s->fu_hd);
391  if (fu) {
392  NMG_CK_FACEUSE(fu);
393  lu = BU_LIST_FIRST(loopuse, &fu->lu_hd);
394  NMG_CK_LOOPUSE(lu);
395  if (BU_LIST_FIRST_MAGIC(&lu->down_hd) == NMG_EDGEUSE_MAGIC) {
396  eu = BU_LIST_FIRST(edgeuse, &lu->down_hd);
397  NMG_CK_EDGEUSE(eu);
398  NMG_CK_VERTEXUSE(eu->vu_p);
399  v = eu->vu_p->v_p;
400  } else {
401  vu = BU_LIST_FIRST(vertexuse, &lu->down_hd);
402  NMG_CK_VERTEXUSE(vu);
403  v = vu->v_p;
404  }
405  NMG_CK_VERTEX(v);
406  if (!v->vg_p)
407  break;
408  VMOVE(mpt, v->vg_p->coord);
409  break;
410  }
411  if (BU_LIST_IS_EMPTY(&s->lu_hd))
412  lu = (struct loopuse *)NULL;
413  else
414  lu = BU_LIST_FIRST(loopuse, &s->lu_hd);
415  if (lu) {
416  NMG_CK_LOOPUSE(lu);
417  if (BU_LIST_FIRST_MAGIC(&lu->down_hd) == NMG_EDGEUSE_MAGIC) {
418  eu = BU_LIST_FIRST(edgeuse, &lu->down_hd);
419  NMG_CK_EDGEUSE(eu);
420  NMG_CK_VERTEXUSE(eu->vu_p);
421  v = eu->vu_p->v_p;
422  } else {
423  vu = BU_LIST_FIRST(vertexuse, &lu->down_hd);
424  NMG_CK_VERTEXUSE(vu);
425  v = vu->v_p;
426  }
427  NMG_CK_VERTEX(v);
428  if (!v->vg_p)
429  break;
430  VMOVE(mpt, v->vg_p->coord);
431  break;
432  }
433  if (BU_LIST_IS_EMPTY(&s->eu_hd))
434  eu = (struct edgeuse *)NULL;
435  else
436  eu = BU_LIST_FIRST(edgeuse, &s->eu_hd);
437  if (eu) {
438  NMG_CK_EDGEUSE(eu);
439  NMG_CK_VERTEXUSE(eu->vu_p);
440  v = eu->vu_p->v_p;
441  NMG_CK_VERTEX(v);
442  if (!v->vg_p)
443  break;
444  VMOVE(mpt, v->vg_p->coord);
445  break;
446  }
447  vu = s->vu_p;
448  if (vu) {
449  NMG_CK_VERTEXUSE(vu);
450  v = vu->v_p;
451  NMG_CK_VERTEX(v);
452  if (!v->vg_p)
453  break;
454  VMOVE(mpt, v->vg_p->coord);
455  break;
456  }
457  }
458  default:
459  VSETALL(mpt, 0.0);
461  "get_solid_keypoint: unrecognized solid type");
462  return GED_ERROR;
463  }
464  MAT4X3PNT(pt, mat, mpt);
465  return GED_OK;
466 }
467 
468 
469 /*
470  * Local Variables:
471  * tab-width: 8
472  * mode: C
473  * indent-tabs-mode: t
474  * c-file-style: "stroustrup"
475  * End:
476  * ex: shiftwidth=4 tabstop=8
477  */
#define GED_OK
Definition: ged.h:55
#define ID_ARS
ARS.
Definition: raytrace.h:463
#define NMG_EDGEUSE_MAGIC
Definition: magic.h:120
#define ID_PIPE
Pipe (wire) solid.
Definition: raytrace.h:473
double dist
>= 0
Definition: tol.h:73
Definition: ged.h:338
#define ID_ARB8
Generalized ARB. V + 7 vectors.
Definition: raytrace.h:462
if lu s
Definition: nmg_mod.c:3860
lu
Definition: nmg_mod.c:3855
#define ID_GRIP
Pseudo Solid Grip.
Definition: raytrace.h:480
#define VSETALL(a, s)
Definition: color.c:54
#define ID_BOT
Bag o' triangles.
Definition: raytrace.h:488
#define BU_LIST_IS_EMPTY(hp)
Definition: list.h:295
#define ID_PARTICLE
Particle system solid.
Definition: raytrace.h:474
struct rt_wdb * ged_wdbp
Definition: ged.h:340
#define ID_HF
Height Field.
Definition: raytrace.h:482
Header file for the BRL-CAD common definitions.
#define ID_TOR
Toroid.
Definition: raytrace.h:459
#define ID_CLINE
FASTGEN4 CLINE solid.
Definition: raytrace.h:487
int bn_mkpoint_3planes(point_t pt, const plane_t a, const plane_t b, const plane_t c)
Given the description of three planes, compute the point of intersection, if any. The direction vecto...
#define GED_ERROR
Definition: ged.h:61
NMG_CK_LOOPUSE(lu)
#define ID_VOL
3-D Volume
Definition: raytrace.h:471
#define ID_METABALL
Metaball.
Definition: raytrace.h:508
#define ID_DSP
Displacement map.
Definition: raytrace.h:483
#define ID_HYP
Hyperboloid of one sheet.
Definition: raytrace.h:510
#define ID_EHY
Elliptical Hyperboloid.
Definition: raytrace.h:478
#define ID_EBM
Extruded bitmap solid.
Definition: raytrace.h:470
#define RT_CK_DB_INTERNAL(_p)
Definition: raytrace.h:207
#define ID_NMG
n-Manifold Geometry solid
Definition: raytrace.h:469
int _ged_get_solid_keypoint(struct ged *const gedp, fastf_t *const pt, const struct rt_db_internal *const ip, const fastf_t *const mat)
Definition: get_solid_kp.c:41
#define ID_SPH
Sphere.
Definition: raytrace.h:468
#define BU_LIST_FIRST_MAGIC(hp)
Definition: list.h:416
#define ID_HALF
Half-space.
Definition: raytrace.h:464
struct bu_vls * ged_result_str
Definition: ged.h:357
#define ID_REC
Right Elliptical Cylinder [TGC special].
Definition: raytrace.h:465
#define ID_RHC
Right Hyperbolic Cylinder.
Definition: raytrace.h:476
#define ID_ARBN
ARB with N faces.
Definition: raytrace.h:472
#define ID_EPA
Elliptical Paraboloid.
Definition: raytrace.h:477
void * idb_ptr
Definition: raytrace.h:195
struct bn_tol wdb_tol
Definition: raytrace.h:1269
#define ID_SUPERELL
Superquadratic ellipsoid.
Definition: raytrace.h:507
#define ID_POLY
Polygonal faceted object.
Definition: raytrace.h:466
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:694
NMG_CK_SHELL(s)
#define ID_EXTRUDE
Solid of extrusion.
Definition: raytrace.h:485
#define ID_RPC
Right Parabolic Cylinder.
Definition: raytrace.h:475
#define ID_TGC
Generalized Truncated General Cone.
Definition: raytrace.h:460
#define ID_ETO
Elliptical Torus.
Definition: raytrace.h:479
double fastf_t
Definition: defines.h:300
#define ID_ELL
Ellipsoid.
Definition: raytrace.h:461
#define ID_SKETCH
2D sketch
Definition: raytrace.h:484
#define BU_LIST_FIRST(structure, hp)
Definition: list.h:312