BRL-CAD
wdb.c
Go to the documentation of this file.
1 /* W D B . C
2  * BRL-CAD
3  *
4  * Copyright (c) 1987-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 
21 /** @file libwdb/wdb.c
22  *
23  * Library for writing MGED databases from arbitrary procedures.
24  * Assumes that some of the structure of such databases are known by
25  * the calling routines.
26  *
27  * It is expected that this library will grow as experience is gained.
28  * Routines for writing every permissible solid do not yet exist.
29  *
30  * Note that routines which are passed point_t or vect_t or mat_t
31  * parameters (which are call-by-address) must be VERY careful to
32  * leave those parameters unmodified (e.g., by scaling), so that the
33  * calling routine is not surprised.
34  *
35  * Return codes of 0 are OK, -1 signal an error.
36  *
37  */
38 
39 #include "common.h"
40 
41 #include <math.h>
42 #include <string.h>
43 #include "bio.h"
44 
45 #include "vmath.h"
46 #include "bn.h"
47 #include "rtgeom.h"
48 #include "raytrace.h"
49 #include "wdb.h"
50 
51 
52 int
53 mk_half(struct rt_wdb *wdbp, const char *name, const fastf_t *norm, fastf_t d)
54 {
55  struct rt_half_internal *half;
56 
57  BU_ALLOC(half, struct rt_half_internal);
58  half->magic = RT_HALF_INTERNAL_MAGIC;
59  VMOVE(half->eqn, norm);
60  half->eqn[3] = d;
61 
62  return wdb_export(wdbp, name, (void *)half, ID_HALF, mk_conv2mm);
63 }
64 
65 
66 int
68  struct rt_wdb *wdbp,
69  const char *name,
70  const point_t center,
71  const vect_t normal,
72  const fastf_t magnitude)
73 {
74  struct rt_grip_internal *grip;
75 
76  BU_ALLOC(grip, struct rt_grip_internal);
77  grip->magic = RT_GRIP_INTERNAL_MAGIC;
78  VMOVE(grip->center, center);
79  VMOVE(grip->normal, normal);
80  grip->mag = magnitude;
81 
82  return wdb_export(wdbp, name, (void *)grip, ID_GRIP, mk_conv2mm);
83 }
84 
85 
86 int
87 mk_rpp(struct rt_wdb *wdbp, const char *name, const fastf_t *min, const fastf_t *max)
88 {
89  point_t pt8[8];
90 
91  VSET(pt8[0], max[X], min[Y], min[Z]);
92  VSET(pt8[1], max[X], max[Y], min[Z]);
93  VSET(pt8[2], max[X], max[Y], max[Z]);
94  VSET(pt8[3], max[X], min[Y], max[Z]);
95 
96  VSET(pt8[4], min[X], min[Y], min[Z]);
97  VSET(pt8[5], min[X], max[Y], min[Z]);
98  VSET(pt8[6], min[X], max[Y], max[Z]);
99  VSET(pt8[7], min[X], min[Y], max[Z]);
100 
101  return mk_arb8(wdbp, name, &pt8[0][X]);
102 }
103 
104 
105 int
106 mk_wedge(struct rt_wdb *wdbp, const char *name, const fastf_t *vert, const fastf_t *xdirv, const fastf_t *zdirv, fastf_t xlen, fastf_t ylen, fastf_t zlen, fastf_t x_top_len)
107 {
108  point_t pts[8]; /* vertices for the wedge */
109  vect_t xvec; /* x_axis vector */
110  vect_t txvec; /* top x_axis vector */
111  vect_t yvec; /* y-axis vector */
112  vect_t zvec; /* z-axix vector */
113  vect_t x_unitv; /* x-axis unit vector*/
114  vect_t z_unitv; /* z-axis unit vector */
115  vect_t y_unitv;
116 
117  VMOVE(x_unitv, xdirv);
118  VUNITIZE(x_unitv);
119  VMOVE(z_unitv, zdirv);
120  VUNITIZE(z_unitv);
121 
122  /* Make y_unitv */
123  VCROSS(y_unitv, x_unitv, z_unitv);
124 
125  /* Scale all vectors. */
126  VSCALE(xvec, x_unitv, xlen);
127  VSCALE(txvec, x_unitv, x_top_len);
128  VSCALE(zvec, z_unitv, zlen);
129  VSCALE(yvec, y_unitv, ylen);
130 
131  /* Make bottom face */
132 
133  VMOVE(pts[0], vert); /* Move given vertex into pts[0] */
134  VADD2(pts[1], pts[0], xvec); /* second vertex. */
135  VADD2(pts[2], pts[1], yvec); /* third vertex */
136  VADD2(pts[3], pts[0], yvec); /* fourth vertex */
137 
138  /* Make top face by extruding bottom face vertices */
139 
140  VADD2(pts[4], pts[0], zvec); /* fifth vertex */
141  VADD2(pts[5], pts[4], txvec); /* sixth vertex */
142  VADD2(pts[6], pts[5], yvec); /* seventh vertex */
143  VADD2(pts[7], pts[4], yvec); /* eighth vertex */
144 
145  return mk_arb8(wdbp, name, &pts[0][X]);
146 }
147 
148 
149 int
150 mk_arb4(struct rt_wdb *wdbp, const char *name, const fastf_t *pts)
151 
152 
153  /* [4*3] */
154 {
155  point_t pt8[8];
156 
157  VMOVE(pt8[0], &pts[0*3]);
158  VMOVE(pt8[1], &pts[1*3]);
159  VMOVE(pt8[2], &pts[2*3]);
160  VMOVE(pt8[3], &pts[2*3]); /* shared point for base */
161 
162  VMOVE(pt8[4], &pts[3*3]); /* top point */
163  VMOVE(pt8[5], &pts[3*3]);
164  VMOVE(pt8[6], &pts[3*3]);
165  VMOVE(pt8[7], &pts[3*3]);
166 
167  return mk_arb8(wdbp, name, &pt8[0][X]);
168 }
169 
170 
171 int
172 mk_arb5(struct rt_wdb *wdbp, const char *name, const fastf_t *pts)
173 
174 
175  /* [5*3] */
176 {
177  point_t pt8[8];
178 
179  VMOVE(pt8[0], &pts[0*3]);
180  VMOVE(pt8[1], &pts[1*3]);
181  VMOVE(pt8[2], &pts[2*3]);
182  VMOVE(pt8[3], &pts[3*3]);
183  VMOVE(pt8[4], &pts[4*3]);
184  VMOVE(pt8[5], &pts[4*3]);
185  VMOVE(pt8[6], &pts[4*3]);
186  VMOVE(pt8[7], &pts[4*3]);
187 
188  return mk_arb8(wdbp, name, &pt8[0][X]);
189 }
190 
191 
192 int
193 mk_arb6(struct rt_wdb *wdbp, const char *name, const fastf_t *pts)
194 
195  /* [6*3] */
196 {
197  point_t pt8[8];
198 
199  VMOVE(pt8[0], &pts[0*3]);
200  VMOVE(pt8[1], &pts[1*3]);
201  VMOVE(pt8[2], &pts[2*3]);
202  VMOVE(pt8[3], &pts[3*3]);
203  VMOVE(pt8[4], &pts[4*3]);
204  VMOVE(pt8[5], &pts[4*3]);
205  VMOVE(pt8[6], &pts[5*3]);
206  VMOVE(pt8[7], &pts[5*3]);
207 
208  return mk_arb8(wdbp, name, &pt8[0][X]);
209 }
210 
211 
212 int
213 mk_arb7(struct rt_wdb *wdbp, const char *name, const fastf_t *pts)
214 
215  /* [7*3] */
216 {
217  point_t pt8[8];
218 
219  VMOVE(pt8[0], &pts[0*3]);
220  VMOVE(pt8[1], &pts[1*3]);
221  VMOVE(pt8[2], &pts[2*3]);
222  VMOVE(pt8[3], &pts[3*3]);
223  VMOVE(pt8[4], &pts[4*3]);
224  VMOVE(pt8[5], &pts[5*3]);
225  VMOVE(pt8[6], &pts[6*3]);
226  VMOVE(pt8[7], &pts[4*3]); /* Shared with point 5, per g_arb.c*/
227 
228  return mk_arb8(wdbp, name, &pt8[0][X]);
229 }
230 
231 
232 int
233 mk_arb8(struct rt_wdb *wdbp, const char *name, const fastf_t *pts)
234 
235 
236  /* [24] */
237 {
238  int i;
239  struct rt_arb_internal *arb;
240 
241  BU_ALLOC(arb, struct rt_arb_internal);
242  arb->magic = RT_ARB_INTERNAL_MAGIC;
243  for (i=0; i < 8; i++) {
244  VMOVE(arb->pt[i], &pts[i*3]);
245  }
246 
247  return wdb_export(wdbp, name, (void *)arb, ID_ARB8, mk_conv2mm);
248 }
249 
250 
251 int
252 mk_sph(struct rt_wdb *wdbp, const char *name, const fastf_t *center, fastf_t radius)
253 {
254  struct rt_ell_internal *ell;
255 
256  BU_ALLOC(ell, struct rt_ell_internal);
257  ell->magic = RT_ELL_INTERNAL_MAGIC;
258  VMOVE(ell->v, center);
259  VSET(ell->a, radius, 0, 0);
260  VSET(ell->b, 0, radius, 0);
261  VSET(ell->c, 0, 0, radius);
262 
263  return wdb_export(wdbp, name, (void *)ell, ID_ELL, mk_conv2mm);
264 }
265 
266 
267 int
268 mk_ell(struct rt_wdb *wdbp, const char *name, const fastf_t *center, const fastf_t *a, const fastf_t *b, const fastf_t *c)
269 {
270  struct rt_ell_internal *ell;
271 
272  BU_ALLOC(ell, struct rt_ell_internal);
273  ell->magic = RT_ELL_INTERNAL_MAGIC;
274  VMOVE(ell->v, center);
275  VMOVE(ell->a, a);
276  VMOVE(ell->b, b);
277  VMOVE(ell->c, c);
278 
279  return wdb_export(wdbp, name, (void *)ell, ID_ELL, mk_conv2mm);
280 }
281 
282 
283 int
284 mk_hyp(struct rt_wdb *wdbp, const char *name, const point_t vertex, const vect_t height_vector, const vect_t vectA, fastf_t magB, fastf_t base_neck_ratio)
285 {
286  struct rt_hyp_internal *hyp;
287 
288  BU_ALLOC(hyp, struct rt_hyp_internal);
289  hyp->hyp_magic = RT_HYP_INTERNAL_MAGIC;
290 
291 
292  if ((MAGNITUDE(vectA) <= SQRT_SMALL_FASTF) || (magB <= SQRT_SMALL_FASTF))
293  return -2;
294 
295  hyp->hyp_bnr = base_neck_ratio;
296  hyp->hyp_b = magB;
297  VMOVE(hyp->hyp_Hi, height_vector);
298  VMOVE(hyp->hyp_Vi, vertex);
299  VMOVE(hyp->hyp_A, vectA);
300 
301  if (MAGNITUDE(hyp->hyp_Hi) < RT_LEN_TOL
302  || MAGNITUDE(hyp->hyp_A) < RT_LEN_TOL
303  || hyp->hyp_b < RT_LEN_TOL
304  || hyp->hyp_bnr < RT_LEN_TOL) {
305  bu_log("ERROR, height, axes, and distance to asymptotes must be greater than zero!\n");
306  return -1;
307  }
308 
309  if (!NEAR_ZERO (VDOT(hyp->hyp_Hi, hyp->hyp_A), RT_DOT_TOL)) {
310  bu_log("ERROR, major axis must be perpendicular to height vector!\n");
311  return -1;
312  }
313 
314  if (base_neck_ratio >= 1 || base_neck_ratio <= 0) {
315  bu_log("ERROR, neck to base ratio must be between 0 and 1!\n");
316  return -1;
317  }
318 
319  if (hyp->hyp_b > MAGNITUDE(hyp->hyp_A)) {
320  vect_t majorAxis;
321  fastf_t minorLen;
322 
323  minorLen = MAGNITUDE(hyp->hyp_A);
324  VCROSS(majorAxis, hyp->hyp_Hi, hyp->hyp_A);
325  VSCALE(hyp->hyp_A, majorAxis, hyp->hyp_b);
326  hyp->hyp_b = minorLen;
327  }
328 
329  return wdb_export(wdbp, name, (void *)hyp, ID_HYP, mk_conv2mm);
330 }
331 
332 
333 int
334 mk_tor(struct rt_wdb *wdbp, const char *name, const fastf_t *center, const fastf_t *inorm, double r1, double r2)
335 {
336  struct rt_tor_internal *tor;
337 
338  BU_ALLOC(tor, struct rt_tor_internal);
339  tor->magic = RT_TOR_INTERNAL_MAGIC;
340  VMOVE(tor->v, center);
341  VMOVE(tor->h, inorm);
342  tor->r_a = r1;
343  tor->r_h = r2;
344 
345  return wdb_export(wdbp, name, (void *)tor, ID_TOR, mk_conv2mm);
346 }
347 
348 
349 int
350 mk_rcc(struct rt_wdb *wdbp, const char *name, const fastf_t *base, const fastf_t *height, fastf_t radius)
351 {
352  vect_t cross1, cross2;
353  vect_t a, b;
354 
355  if (MAGSQ(height) <= SQRT_SMALL_FASTF)
356  return -2;
357 
358  /* Create two mutually perpendicular vectors, perpendicular to H */
359  bn_vec_ortho(cross1, height);
360  VCROSS(cross2, cross1, height);
361  VUNITIZE(cross2);
362 
363  VSCALE(a, cross1, radius);
364  VSCALE(b, cross2, radius);
365 
366  return mk_tgc(wdbp, name, base, height, a, b, a, b);
367 }
368 
369 
370 int
371 mk_tgc(struct rt_wdb *wdbp, const char *name, const fastf_t *base, const fastf_t *height, const fastf_t *a, const fastf_t *b, const fastf_t *c, const fastf_t *d)
372 {
373  struct rt_tgc_internal *tgc;
374 
375  BU_ALLOC(tgc, struct rt_tgc_internal);
376  tgc->magic = RT_TGC_INTERNAL_MAGIC;
377  VMOVE(tgc->v, base);
378  VMOVE(tgc->h, height);
379  VMOVE(tgc->a, a);
380  VMOVE(tgc->b, b);
381  VMOVE(tgc->c, c);
382  VMOVE(tgc->d, d);
383 
384  return wdb_export(wdbp, name, (void *)tgc, ID_TGC, mk_conv2mm);
385 }
386 
387 
388 int
389 mk_cone(struct rt_wdb *wdbp, const char *name, const fastf_t *base, const fastf_t *dirv, fastf_t height, fastf_t rad1, fastf_t rad2)
390 {
391  vect_t a, avec; /* one base radius vector */
392  vect_t b, bvec; /* another base radius vector */
393  vect_t cvec; /* nose radius vector */
394  vect_t dvec; /* another nose radius vector */
395  vect_t h_unitv; /* local copy of dirv */
396  vect_t hgtv; /* height vector */
397  fastf_t f;
398 
399  if ((f = MAGNITUDE(dirv)) <= SQRT_SMALL_FASTF)
400  return -2;
401  f = 1/f;
402  VSCALE(h_unitv, dirv, f);
403  VSCALE(hgtv, h_unitv, height);
404 
405  /* Now make a, b, c, and d vectors. */
406 
407  bn_vec_ortho(a, h_unitv);
408  VUNITIZE(a);
409  VCROSS(b, h_unitv, a);
410  VSCALE(avec, a, rad1);
411  VSCALE(bvec, b, rad1);
412  VSCALE(cvec, a, rad2);
413  VSCALE(dvec, b, rad2);
414 
415  return mk_tgc(wdbp, name, base, hgtv, avec, bvec, cvec, dvec);
416 }
417 
418 
419 int
420 mk_trc_h(struct rt_wdb *wdbp, const char *name, const fastf_t *base, const fastf_t *height, fastf_t radbase, fastf_t radtop)
421 {
422  vect_t cross1, cross2;
423  vect_t a, b, c, d;
424 
425  if (MAGSQ(height) <= SQRT_SMALL_FASTF)
426  return -2;
427 
428  /* Create two mutually perpendicular vectors, perpendicular to H */
429  bn_vec_ortho(cross1, height);
430  VCROSS(cross2, cross1, height);
431  VUNITIZE(cross2);
432 
433  VSCALE(a, cross1, radbase);
434  VSCALE(b, cross2, radbase);
435 
436  VSCALE(c, cross1, radtop);
437  VSCALE(d, cross2, radtop);
438 
439  return mk_tgc(wdbp, name, base, height, a, b, c, d);
440 }
441 
442 
443 int
444 mk_trc_top(struct rt_wdb *wdbp, const char *name, const fastf_t *ibase, const fastf_t *itop, fastf_t radbase, fastf_t radtop)
445 {
446  vect_t height;
447 
448  VSUB2(height, itop, ibase);
449  return mk_trc_h(wdbp, name, ibase, height, radbase, radtop);
450 }
451 
452 
453 int
455  struct rt_wdb *wdbp,
456  const char *name,
457  const point_t vert,
458  const vect_t height,
459  const vect_t breadth,
460  double half_w)
461 {
462  struct rt_rpc_internal *rpc;
463 
464  BU_ALLOC(rpc, struct rt_rpc_internal);
465  rpc->rpc_magic = RT_RPC_INTERNAL_MAGIC;
466 
467  VMOVE(rpc->rpc_V, vert);
468  VMOVE(rpc->rpc_H, height);
469  VMOVE(rpc->rpc_B, breadth);
470  rpc->rpc_r = half_w;
471 
472  return wdb_export(wdbp, name, (void *)rpc, ID_RPC, mk_conv2mm);
473 }
474 
475 
476 int
478  struct rt_wdb *wdbp,
479  const char *name,
480  const point_t vert,
481  const vect_t height,
482  const vect_t breadth,
483  fastf_t half_w,
484  fastf_t asymp)
485 {
486  struct rt_rhc_internal *rhc;
487 
488  BU_ALLOC(rhc, struct rt_rhc_internal);
489  rhc->rhc_magic = RT_RHC_INTERNAL_MAGIC;
490 
491  VMOVE(rhc->rhc_V, vert);
492  VMOVE(rhc->rhc_H, height);
493  VMOVE(rhc->rhc_B, breadth);
494  rhc->rhc_r = half_w;
495  rhc->rhc_c = asymp;
496 
497  return wdb_export(wdbp, name, (void *)rhc, ID_RHC, mk_conv2mm);
498 }
499 
500 
501 int
503  struct rt_wdb *wdbp,
504  const char *name,
505  const point_t vert,
506  const vect_t height,
507  const vect_t breadth,
508  fastf_t r1,
509  fastf_t r2)
510 {
511  struct rt_epa_internal *epa;
512 
513  BU_ALLOC(epa, struct rt_epa_internal);
514  epa->epa_magic = RT_EPA_INTERNAL_MAGIC;
515 
516  VMOVE(epa->epa_V, vert);
517  VMOVE(epa->epa_H, height);
518  VMOVE(epa->epa_Au, breadth);
519  epa->epa_r1 = r1;
520  epa->epa_r2 = r2;
521 
522  return wdb_export(wdbp, name, (void *)epa, ID_EPA, mk_conv2mm);
523 }
524 
525 
526 int
528  struct rt_wdb *wdbp,
529  const char *name,
530  const point_t vert,
531  const vect_t height,
532  const vect_t breadth,
533  fastf_t r1,
534  fastf_t r2,
535  fastf_t c)
536 {
537  struct rt_ehy_internal *ehy;
538 
539  BU_ALLOC(ehy, struct rt_ehy_internal);
540  ehy->ehy_magic = RT_EHY_INTERNAL_MAGIC;
541 
542  VMOVE(ehy->ehy_V, vert);
543  VMOVE(ehy->ehy_H, height);
544  VMOVE(ehy->ehy_Au, breadth);
545  ehy->ehy_r1 = r1;
546  ehy->ehy_r2 = r2;
547  ehy->ehy_c = c;
548 
549  return wdb_export(wdbp, name, (void *)ehy, ID_EHY, mk_conv2mm);
550 }
551 
552 
553 int mk_hrt(struct rt_wdb *wdbp, const char *name, const point_t center, const vect_t x, const vect_t y, const vect_t z, const fastf_t dist)
554 {
555  struct rt_hrt_internal *hrt;
556 
557  BU_ALLOC(hrt, struct rt_hrt_internal);
558  hrt->hrt_magic = RT_HRT_INTERNAL_MAGIC;
559 
560  VMOVE(hrt->v, center);
561  VMOVE(hrt->xdir, x);
562  VMOVE(hrt->ydir, y);
563  VMOVE(hrt->zdir, z);
564  hrt->d = dist;
565 
566  return wdb_export(wdbp, name, (void *)hrt, ID_HRT, mk_conv2mm);
567 }
568 
569 
570 int
572  struct rt_wdb *wdbp,
573  const char *name,
574  const point_t vert,
575  const vect_t norm,
576  const vect_t smajor,
577  fastf_t rrot,
578  fastf_t sminor)
579 {
580  struct rt_eto_internal *eto;
581 
582  BU_ALLOC(eto, struct rt_eto_internal);
583  eto->eto_magic = RT_ETO_INTERNAL_MAGIC;
584 
585  VMOVE(eto->eto_V, vert);
586  VMOVE(eto->eto_N, norm);
587  VMOVE(eto->eto_C, smajor);
588  eto->eto_r = rrot;
589  eto->eto_rd = sminor;
590 
591  return wdb_export(wdbp, name, (void *)eto, ID_ETO, mk_conv2mm);
592 }
593 
594 
595 int
597  struct rt_wdb *wdbp,
598  const char *name,
599  const size_t nctlpt, /* number of control points */
600  const int method,
601  const fastf_t threshold,
602  const fastf_t *verts[5])
603 {
604  struct rt_metaball_internal *mb;
605  size_t i;
606 
607  BU_ALLOC(mb, struct rt_metaball_internal);
608  mb->magic = RT_METABALL_INTERNAL_MAGIC;
609  mb->threshold = threshold > 0 ? threshold : 1.0;
610  mb->method = method >= 0 ? method : 2; /* default to Blinn blob */
611  BU_LIST_INIT(&mb->metaball_ctrl_head);
612 
613  for (i = 0; i < nctlpt; i++) {
614  if (rt_metaball_add_point (mb, (const point_t *)verts[i], verts[i][3], verts[i][4]) != 0) {
615  bu_log("something is fishy here in mk_metaball");
616  bu_bomb("AIIEEEEEEE");
617  }
618  }
619 
620  return wdb_export(wdbp, name, (void *)mb, ID_METABALL, mk_conv2mm);
621 }
622 
623 
624 int
626  struct rt_wdb *wdbp,
627  const char *name,
628  const void *data,
629  wdb_binunif data_type,
630  long count)
631 {
632  struct rt_binunif_internal *binunif;
633  unsigned int minor_type = 0;
634  int from_file = 0;
635  size_t bytes = 0;
636  int nosign = 0;
637 
638  switch (data_type) {
640  from_file = 1;
641  case WDB_BINUNIF_FLOAT:
642  bytes = sizeof(float);
643  minor_type = DB5_MINORTYPE_BINU_FLOAT;
644  break;
646  from_file = 1;
647  case WDB_BINUNIF_DOUBLE:
648  bytes = sizeof(double);
649  minor_type = DB5_MINORTYPE_BINU_DOUBLE;
650  break;
651 
653  from_file = 1;
654  case WDB_BINUNIF_INT8:
655  bytes = 1;
656  break;
658  from_file = 1;
659  case WDB_BINUNIF_UINT8:
660  nosign = 1;
661  bytes = 1;
662  break;
664  from_file = 1;
665  case WDB_BINUNIF_INT16:
666  bytes = 2;
667  break;
669  from_file = 1;
670  case WDB_BINUNIF_UINT16:
671  nosign = 1;
672  bytes = 2;
673  break;
675  from_file = 1;
676  case WDB_BINUNIF_INT32:
677  bytes = 4;
678  break;
680  from_file = 1;
681  case WDB_BINUNIF_UINT32:
682  nosign = 1;
683  bytes = 4;
684  break;
686  from_file = 1;
687  case WDB_BINUNIF_INT64:
688  bytes = 8;
689  break;
691  from_file = 1;
692  case WDB_BINUNIF_UINT64:
693  nosign = 1;
694  bytes = 8;
695  break;
696 
698  from_file = 1;
699  case WDB_BINUNIF_CHAR:
700  bytes = sizeof(char);
701  break;
703  from_file = 1;
704  case WDB_BINUNIF_UCHAR:
705  nosign = 1;
706  bytes = sizeof(unsigned char);
707  break;
709  from_file = 1;
710  case WDB_BINUNIF_SHORT:
711  bytes = sizeof(short);
712  break;
714  from_file = 1;
715  case WDB_BINUNIF_USHORT:
716  nosign = 1;
717  bytes = sizeof(unsigned short);
718  break;
720  from_file = 1;
721  case WDB_BINUNIF_INT:
722  bytes = sizeof(int);
723  break;
725  from_file = 1;
726  case WDB_BINUNIF_UINT:
727  nosign = 1;
728  bytes = sizeof(unsigned int);
729  break;
731  from_file = 1;
732  case WDB_BINUNIF_LONG:
733  bytes = sizeof(long);
734  break;
736  from_file = 1;
737  case WDB_BINUNIF_ULONG:
738  nosign = 1;
739  bytes = sizeof(unsigned long);
740  break;
742  from_file = 1;
744 #if defined(_WIN32) && !defined(__CYGWIN__)
745  bytes = sizeof(__int64);
746 #else
747  bytes = sizeof(long long);
748 #endif
749  break;
751  from_file = 1;
753  nosign = 1;
754 #if defined(_WIN32) && !defined(__CYGWIN__)
755  bytes = sizeof(unsigned __int64);
756 #else
757  bytes = sizeof(unsigned long long);
758 #endif
759  break;
760  default:
761  bu_log("Unknown binunif data source type: %d", data_type);
762  return 1;
763  }
764 
765  /* the floating point types already have their minor type set */
766  if (!minor_type) {
767  switch (bytes) {
768  case 1:
769  if (nosign) {
770  minor_type = DB5_MINORTYPE_BINU_8BITINT_U;
771  } else {
772  minor_type = DB5_MINORTYPE_BINU_8BITINT;
773  }
774  break;
775  case 2:
776  if (nosign) {
777  minor_type = DB5_MINORTYPE_BINU_16BITINT_U;
778  } else {
779  minor_type = DB5_MINORTYPE_BINU_16BITINT;
780  }
781  break;
782  case 4:
783  if (nosign) {
784  minor_type = DB5_MINORTYPE_BINU_32BITINT_U;
785  } else {
786  minor_type = DB5_MINORTYPE_BINU_32BITINT;
787  }
788  break;
789  case 8:
790  if (nosign) {
791  minor_type = DB5_MINORTYPE_BINU_64BITINT_U;
792  } else {
793  minor_type = DB5_MINORTYPE_BINU_64BITINT;
794  }
795  break;
796  }
797  }
798 
799  /* sanity check that our sizes are correct */
800  if (bytes != db5_type_sizeof_h_binu(minor_type)) {
801  bu_log("mk_binunif: size inconsistency found, bytes=%zu expecting bytes=%zu\n",
802  bytes, db5_type_sizeof_h_binu(minor_type));
803  bu_log("Warning: the uniform-array binary data object was NOT created");
804  return -1;
805  }
806 
807  /* use the librt load-from-file routine? */
808  if (from_file) {
809  return rt_mk_binunif (wdbp, name, (char *)data, minor_type, count);
810  }
811 
812  /* count must be non-negative */
813  if (count < 0) {
814  count = 0;
815  }
816 
817  /* loading from data already in memory */
818  BU_ALLOC(binunif, struct rt_binunif_internal);
819  binunif->magic = RT_BINUNIF_INTERNAL_MAGIC;
820  binunif->type = minor_type;
821  binunif->count = count;
822  memcpy(binunif->u.int8, data, count * bytes);
823  return wdb_export(wdbp, name, (void *)binunif, ID_BINUNIF, mk_conv2mm);
824 }
825 
826 
827 /*
828  * Local Variables:
829  * mode: C
830  * tab-width: 8
831  * indent-tabs-mode: t
832  * c-file-style: "stroustrup"
833  * End:
834  * ex: shiftwidth=4 tabstop=8
835  */
#define RT_TGC_INTERNAL_MAGIC
Definition: magic.h:111
#define RT_BINUNIF_INTERNAL_MAGIC
Definition: magic.h:84
int mk_arb7(struct rt_wdb *wdbp, const char *name, const fastf_t *pts)
Definition: wdb.c:213
#define RT_LEN_TOL
Definition: raytrace.h:169
void bu_log(const char *,...) _BU_ATTR_PRINTF12
Definition: log.c:176
int mk_tgc(struct rt_wdb *wdbp, const char *name, const fastf_t *base, const fastf_t *height, const fastf_t *a, const fastf_t *b, const fastf_t *c, const fastf_t *d)
Definition: wdb.c:371
#define RT_DOT_TOL
Definition: raytrace.h:170
int mk_tor(struct rt_wdb *wdbp, const char *name, const fastf_t *center, const fastf_t *inorm, double r1, double r2)
Definition: wdb.c:334
#define ID_ARB8
Generalized ARB. V + 7 vectors.
Definition: raytrace.h:462
Definition: clone.c:90
int mk_wedge(struct rt_wdb *wdbp, const char *name, const fastf_t *vert, const fastf_t *xdirv, const fastf_t *zdirv, fastf_t xlen, fastf_t ylen, fastf_t zlen, fastf_t x_top_len)
Definition: wdb.c:106
#define VSET(a, b, c, d)
Definition: color.c:53
#define ID_GRIP
Pseudo Solid Grip.
Definition: raytrace.h:480
int mk_arb5(struct rt_wdb *wdbp, const char *name, const fastf_t *pts)
Definition: wdb.c:172
Header file for the BRL-CAD common definitions.
int mk_rcc(struct rt_wdb *wdbp, const char *name, const fastf_t *base, const fastf_t *height, fastf_t radius)
Definition: wdb.c:350
int mk_hyp(struct rt_wdb *wdbp, const char *name, const point_t vertex, const vect_t height_vector, const vect_t vectA, fastf_t magB, fastf_t base_neck_ratio)
Definition: wdb.c:284
#define ID_TOR
Toroid.
Definition: raytrace.h:459
union rt_binunif_internal::@9 u
#define RT_EPA_INTERNAL_MAGIC
Definition: magic.h:92
#define ID_BINUNIF
Uniform-array binary.
Definition: raytrace.h:501
int mk_rpp(struct rt_wdb *wdbp, const char *name, const fastf_t *min, const fastf_t *max)
Definition: wdb.c:87
int mk_half(struct rt_wdb *wdbp, const char *name, const fastf_t *norm, fastf_t d)
Definition: wdb.c:53
#define RT_HYP_INTERNAL_MAGIC
Definition: magic.h:98
#define ID_METABALL
Metaball.
Definition: raytrace.h:508
int mk_sph(struct rt_wdb *wdbp, const char *name, const fastf_t *center, fastf_t radius)
Definition: wdb.c:252
Definition: color.c:49
COMPLEX data[64]
Definition: fftest.c:34
int wdb_export(struct rt_wdb *wdbp, const char *name, void *gp, int id, double local2mm)
Definition: wdb.c:265
int mk_arb8(struct rt_wdb *wdbp, const char *name, const fastf_t *pts)
Definition: wdb.c:233
#define ID_HYP
Hyperboloid of one sheet.
Definition: raytrace.h:510
#define ID_EHY
Elliptical Hyperboloid.
Definition: raytrace.h:478
#define RT_ELL_INTERNAL_MAGIC
Definition: magic.h:91
int mk_rhc(struct rt_wdb *wdbp, const char *name, const point_t vert, const vect_t height, const vect_t breadth, fastf_t half_w, fastf_t asymp)
Definition: wdb.c:477
#define BU_ALLOC(_ptr, _type)
Definition: malloc.h:223
int mk_ell(struct rt_wdb *wdbp, const char *name, const fastf_t *center, const fastf_t *a, const fastf_t *b, const fastf_t *c)
Definition: wdb.c:268
#define RT_EHY_INTERNAL_MAGIC
Definition: magic.h:90
#define RT_TOR_INTERNAL_MAGIC
Definition: magic.h:112
#define RT_GRIP_INTERNAL_MAGIC
Definition: magic.h:95
int mk_trc_h(struct rt_wdb *wdbp, const char *name, const fastf_t *base, const fastf_t *height, fastf_t radbase, fastf_t radtop)
Definition: wdb.c:420
#define RT_HALF_INTERNAL_MAGIC
Definition: magic.h:96
#define NEAR_ZERO(val, epsilon)
Definition: color.c:55
#define SQRT_SMALL_FASTF
Definition: defines.h:346
int mk_epa(struct rt_wdb *wdbp, const char *name, const point_t vert, const vect_t height, const vect_t breadth, fastf_t r1, fastf_t r2)
Definition: wdb.c:502
#define RT_RPC_INTERNAL_MAGIC
Definition: magic.h:107
double mk_conv2mm
Conversion factor to mm.
Definition: units.c:37
int mk_binunif(struct rt_wdb *wdbp, const char *name, const void *data, wdb_binunif data_type, long count)
Definition: wdb.c:625
#define ID_HALF
Half-space.
Definition: raytrace.h:464
#define RT_HRT_INTERNAL_MAGIC
Definition: magic.h:116
#define ID_RHC
Right Hyperbolic Cylinder.
Definition: raytrace.h:476
int mk_rpc(struct rt_wdb *wdbp, const char *name, const point_t vert, const vect_t height, const vect_t breadth, double half_w)
Definition: wdb.c:454
int mk_arb6(struct rt_wdb *wdbp, const char *name, const fastf_t *pts)
Definition: wdb.c:193
#define ID_EPA
Elliptical Paraboloid.
Definition: raytrace.h:477
int mk_trc_top(struct rt_wdb *wdbp, const char *name, const fastf_t *ibase, const fastf_t *itop, fastf_t radbase, fastf_t radtop)
Definition: wdb.c:444
#define BU_LIST_INIT(_hp)
Definition: list.h:148
size_t db5_type_sizeof_h_binu(const int minor)
Definition: db5_types.c:228
#define RT_ETO_INTERNAL_MAGIC
Definition: magic.h:93
int mk_ehy(struct rt_wdb *wdbp, const char *name, const point_t vert, const vect_t height, const vect_t breadth, fastf_t r1, fastf_t r2, fastf_t c)
Definition: wdb.c:527
void bn_vec_ortho(vect_t out, const vect_t in)
wdb_binunif
Definition: wdb.h:412
Definition: color.c:51
int mk_cone(struct rt_wdb *wdbp, const char *name, const fastf_t *base, const fastf_t *dirv, fastf_t height, fastf_t rad1, fastf_t rad2)
Definition: wdb.c:389
#define ID_RPC
Right Parabolic Cylinder.
Definition: raytrace.h:475
#define ID_HRT
Heart.
Definition: raytrace.h:514
#define ID_TGC
Generalized Truncated General Cone.
Definition: raytrace.h:460
int mk_metaball(struct rt_wdb *wdbp, const char *name, const size_t nctlpt, const int method, const fastf_t threshold, const fastf_t *verts[5])
Definition: wdb.c:596
void bu_bomb(const char *str) _BU_ATTR_NORETURN
Definition: bomb.c:91
#define ID_ETO
Elliptical Torus.
Definition: raytrace.h:479
double fastf_t
Definition: defines.h:300
#define RT_ARB_INTERNAL_MAGIC
Definition: magic.h:82
int mk_grip(struct rt_wdb *wdbp, const char *name, const point_t center, const vect_t normal, const fastf_t magnitude)
Definition: wdb.c:67
int mk_eto(struct rt_wdb *wdbp, const char *name, const point_t vert, const vect_t norm, const vect_t smajor, fastf_t rrot, fastf_t sminor)
Definition: wdb.c:571
#define ID_ELL
Ellipsoid.
Definition: raytrace.h:461
int rt_mk_binunif(struct rt_wdb *wdbp, const char *obj_name, const char *file_name, unsigned int minor_type, size_t max_count)
Definition: binunif.c:55
int mk_hrt(struct rt_wdb *wdbp, const char *name, const point_t center, const vect_t x, const vect_t y, const vect_t z, const fastf_t dist)
Definition: wdb.c:553
#define RT_METABALL_INTERNAL_MAGIC
Definition: magic.h:100
#define RT_RHC_INTERNAL_MAGIC
Definition: magic.h:106
Definition: color.c:50
int rt_metaball_add_point(struct rt_metaball_internal *, const point_t *loc, const fastf_t fldstr, const fastf_t goo)
Definition: metaball.c:854
int mk_arb4(struct rt_wdb *wdbp, const char *name, const fastf_t *pts)
Definition: wdb.c:150