BRL-CAD
Loading...
Searching...
No Matches
wdb.h
Go to the documentation of this file.
1/* W D B . H
2 * BRL-CAD
3 *
4 * Copyright (c) 1988-2026 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 libwdb
21 *
22 * @brief
23 * Interface structures and routines for libwdb
24
25 * Library for writing MGED database objects from arbitrary procedures.
26 * Assumes that some of the structure of such databases are known by
27 * the calling routines.
28 *
29 * It is expected that this library will grow as experience is gained.
30 * Routines for writing every permissible solid do not yet exist.
31 *
32 * Note that routines which are passed point_t or vect_t or mat_t
33 * parameters (which are call-by-address) must be VERY careful to
34 * leave those parameters unmodified (e.g., by scaling), so that the
35 * calling routine is not surprised.
36 *
37 * Return codes of 0 are OK, -1 signal an error.
38 *
39 * Note - Rather than using a stdio (FILE *), we now use a (struct rt_wdb *)
40 * parameter. Rather than calling fopen(), call wdb_fopen();
41 */
42
43#ifndef WDB_H
44#define WDB_H
45
46#include "common.h"
47
48#include "bu/magic.h"
49#include "bu/bitv.h"
50#include "bu/list.h"
51#include "bn.h"
52#include "raytrace.h"
53#include "rt/geom.h"
54
55
57
58#ifndef WDB_EXPORT
59# if defined(WDB_DLL_EXPORTS) && defined(WDB_DLL_IMPORTS)
60# error "Only WDB_DLL_EXPORTS or WDB_DLL_IMPORTS can be defined, not both."
61# elif defined(WDB_DLL_EXPORTS)
62# define WDB_EXPORT COMPILER_DLLEXPORT
63# elif defined(WDB_DLL_IMPORTS)
64# define WDB_EXPORT COMPILER_DLLIMPORT
65# else
66# define WDB_EXPORT
67# endif
68#endif
69
70/** @addtogroup libwdb */
71/** @{ */
72/** @file include/wdb.h */
73
74/**
75 * In-memory form of database combinations
76 */
77struct wmember {
78 struct bu_list l;
79 int wm_op; /**< @brief Boolean operation */
80 mat_t wm_mat; /**< @brief FIXME: Should be a matp_t */
81 char *wm_name;
82};
83
84
85#define WMEMBER_INIT_ZERO { BU_LIST_INIT_ZERO, 0, MAT_INIT_IDN, NULL }
86#define WMEMBER_INIT(x) { BU_LIST_INIT(&((x)->l)); (x)->wm_op = 0; MAT_IDN((x)->wm_mat); (x)->wm_name = NULL; }
87#define WMEMBER_NULL ((struct wmember *)0)
88#define WDB_CK_WMEMBER(_p) BU_CKMAG(_p, WMEMBER_MAGIC, "wmember");
90/**
91 * Make a database header (ID) record.
92 */
93WDB_EXPORT extern int mk_id(struct rt_wdb *fp, const char *title);
95/**
96 * Make a database header (ID) record, and note the user's preferred
97 * editing units (specified as a string).
98 *
99 * @return <0 error, 0 success
100 */
101WDB_EXPORT extern int mk_id_units(struct rt_wdb *fp, const char *title, const char *units);
103
104/**
105 * Make a database header (ID) record, and note the user's preferred
106 * editing units (specified as a conversion factor).
107 *
108 * Note that the v4 database format offers only a limited number of
109 * choices for the preferred editing units. If the user is editing in
110 * unusual units (like 2.5feet), don't fail to create the database
111 * header.
112 *
113 * In the v5 database, the conversion factor will be stored intact.
114 *
115 * Note that the database-layer header record will have already been
116 * written by db_create(). All we have to do here is update it.
117 *
118 * @return <0 error, 0 success
119 */
121 struct rt_wdb *fp,
122 const char *title,
123 double local2mm);
124
125/**
126 * Make a halfspace. Specified by distance from origin, and outward
127 * pointing normal vector.
128 */
129WDB_EXPORT extern int mk_half(struct rt_wdb *fp, const char *name, const vect_t norm, fastf_t d);
131/**
132 * Make a grip pseudo solid. Specified by a center, normal vector,
133 * and magnitude.
134 */
136 struct rt_wdb *wdbp,
137 const char *name,
138 const point_t center,
139 const vect_t normal,
140 const fastf_t magnitude);
141
142/**
143 * Make a right parallelepiped. Specified by minXYZ, maxXYZ.
144 */
145WDB_EXPORT extern int mk_rpp(struct rt_wdb *fp, const char *name, const point_t min, const point_t max);
147/**
148 * Makes a right angular wedge given a starting vertex located in the,
149 * lower left corner, an x and a z direction vector, x, y, and z
150 * lengths, and an x length for the top. The y direction vector is x
151 * cross z.
152 */
153WDB_EXPORT extern int mk_wedge(struct rt_wdb *fp, const char *name, const point_t vert,
154 const vect_t xdirv, const vect_t zdirv,
155 fastf_t xlen, fastf_t ylen, fastf_t zlen,
157
158WDB_EXPORT extern int mk_arb4(struct rt_wdb *fp, const char *name, const fastf_t *pts4);
160WDB_EXPORT extern int mk_arb5(struct rt_wdb *fp, const char *name, const fastf_t *pts5);
162WDB_EXPORT extern int mk_arb6(struct rt_wdb *fp, const char *name, const fastf_t *pts6);
164WDB_EXPORT extern int mk_arb7(struct rt_wdb *fp, const char *name, const fastf_t *pts7);
166/**
167 * All plates with 4 points must be co-planar. If there are
168 * degeneracies (i.e., all 8 vertices are not distinct), then certain
169 * requirements must be met. If we think of the ARB8 as having a top
170 * and a bottom plate, the first four points listed must lie on one
171 * plate, and the second four points listed must lie on the other
172 * plate.
173 */
174WDB_EXPORT extern int mk_arb8(struct rt_wdb *fp, const char *name, const fastf_t *pts8);
176/**
177 * Make a sphere with the given center point and radius.
178 */
179WDB_EXPORT extern int mk_sph(struct rt_wdb *fp, const char *name, const point_t center,
180 fastf_t radius);
181
182/**
183 * Make an ellipsoid at the given center point with 3 perp. radius
184 * vectors. The eccentricity of the ellipsoid is controlled by the
185 * relative lengths of the three radius vectors.
186 */
187WDB_EXPORT extern int mk_ell(struct rt_wdb *fp, const char *name, const point_t center,
188 const vect_t a, const vect_t b, const vect_t c);
189
190/**
191 * Make a torus. Specify center, normal, r1: distance from center
192 * point to center of solid part, r2: radius of solid part.
193 */
194WDB_EXPORT extern int mk_tor(struct rt_wdb *fp, const char *name, const point_t center,
195 const vect_t inorm, double r1, double r2);
196
197/**
198 * Make a Right Circular Cylinder (special case of the TGC).
199 */
200WDB_EXPORT extern int mk_rcc(struct rt_wdb *fp, const char *name, const point_t base,
201 const vect_t height, fastf_t radius);
202
203/**
204 * Make a Truncated General Cylinder.
205 */
206WDB_EXPORT extern int mk_tgc(struct rt_wdb *fp, const char *name, const point_t base,
207 const vect_t height, const vect_t a, const vect_t b,
208 const vect_t c, const vect_t d);
209
210/**
211 * Makes a right circular cone given the center point of the base
212 * circle, a direction vector, a scalar height, and the radii at each
213 * end of the cone.
214 */
215WDB_EXPORT extern int mk_cone(struct rt_wdb *fp, const char *name, const point_t base, const vect_t dirv, fastf_t height, fastf_t base_radius, fastf_t nose_radius);
217/**
218 * Make a truncated right cylinder, with base and height. Not just
219 * called mk_trc() to avoid conflict with a previous routine of that
220 * name with different calling sequence.
221 */
222WDB_EXPORT extern int mk_trc_h(struct rt_wdb *fp, const char *name, const point_t base,
224
225/**
226 * Convenience wrapper for mk_trc_h().
227 */
228WDB_EXPORT extern int mk_trc_top(struct rt_wdb *fp, const char *name, const point_t ibase,
230
231/**
232 * Makes a right parabolic cylinder given the origin, or main vertex,
233 * a height vector, a breadth vector (B . H must be 0), and a scalar
234 * rectangular half-width (for the top of the rpc).
235 */
237 struct rt_wdb *wdbp,
238 const char *name,
239 const point_t vert,
240 const vect_t height,
241 const vect_t breadth,
242 double half_w);
243
244/**
245 * Makes a right hyperbolic cylinder given the origin, or main vertex,
246 * a height vector, a breadth vector (B . H must be 0), a scalar
247 * rectangular half-width (for the top of the rpc), and the scalar
248 * distance from the tip of the hyperbola to the intersection of the
249 * asymptotes.
250 */
252 struct rt_wdb *wdbp,
253 const char *name,
254 const point_t vert,
255 const vect_t height,
256 const vect_t breadth,
258 fastf_t asymp);
259
260/**
261 * Makes an elliptical paraboloid given the origin, a height vector H,
262 * a unit vector A along the semi-major axis (A . H must equal 0), and
263 * the scalar lengths, r1 and r2, of the semi-major and -minor axes.
264 */
266 struct rt_wdb *wdbp,
267 const char *name,
268 const point_t vert,
269 const vect_t height,
270 const vect_t breadth,
271 fastf_t r1,
272 fastf_t r2);
273
274/**
275 * Makes an elliptical hyperboloid given the origin, a height vector
276 * H, a unit vector A along the semi-major axis (A . H must equal 0),
277 * the scalar lengths, r1 and r2, of the semi-major and -minor axes,
278 * and the distance c between the tip of the hyperboloid and the
279 * vertex of the asymptotic cone.
280 */
282 struct rt_wdb *wdbp,
283 const char *name,
284 const point_t vert,
285 const vect_t height,
286 const vect_t breadth,
287 fastf_t r1,
288 fastf_t r2,
289 fastf_t c);
290
291/**
292 * Make a hyperboloid at the given center point with a vertex, height
293 * vector, A vector, magnitude of the B vector, and neck to base
294 * ratio.
295 */
297 struct rt_wdb *wdbp,
298 const char *name,
299 const point_t vert,
300 const vect_t height_vector,
301 const vect_t vectA,
304
305/**
306 * Makes an elliptical torus given the origin, a plane normal vector
307 * N, a vector C along the semi-major axis of the elliptical
308 * cross-section, the scalar lengths r and rd, of the radius of
309 * revolution and length of semi-minor axis of the elliptical cross
310 * section.
311 */
313 struct rt_wdb *wdbp,
314 const char *name,
315 const point_t vert,
316 const vect_t norm,
317 const vect_t smajor,
320
321
322/**
323 * Makes a metaball.
324 */
326 struct rt_wdb *wdbp,
327 const char *name,
328 const size_t nctlpt, /* number of control points */
329 const int method, /* metaball rendering method */
330 const fastf_t threshold,
331 const fastf_t *verts[5]); /* X, Y, Z, field_strength, blobbiness */
332
333/**
334 * Caller is responsible for freeing eqn[]
335 *
336 * @return <0 error, 0 success
337 */
338WDB_EXPORT extern int mk_arbn(struct rt_wdb *fp, const char *name, size_t neqn, const plane_t *eqn);
340WDB_EXPORT extern int mk_ars(struct rt_wdb *fp, const char *name, size_t ncurves, size_t pts_per_curve, fastf_t *curves[]);
342/**
343 * Given the appropriate parameters, makes the non-geometric
344 * constraint object and writes it to the database using
345 * wdb_put_internal. Only supported on database version 5 or above
346 */
347WDB_EXPORT extern int mk_constraint(struct rt_wdb *wdbp, const char *name, const char *expr);
349
350WDB_EXPORT extern int mk_material(struct rt_wdb *wdbp,
351 const char *db_name,
352 const char *name,
353 const char *parent,
354 const char *source,
355 struct bu_attribute_value_set *physicalProperties,
356 struct bu_attribute_value_set *mechanicalProperties,
357 struct bu_attribute_value_set *opticalProperties,
358 struct bu_attribute_value_set *thermalProperties);
359
360
361/* FIXME: are the variable-sized types actually necessary? should be
362 * able to rely on stdint types. the file+nonfile duplication seems
363 * silly too.
364 */
365typedef enum {
409#define WDB_BINUNIF_TYPE_MASK 0x00ffu
410
411/**
412 * File data has network byte order. File data is assumed to have host byte
413 * order when this flag is absent. In-memory data must have host byte order.
414 */
415#define WDB_BINUNIF_NETWORK_ORDER 0x0100u
416
418/**
419 * Make a uniform binary data object from an array or a data file.
420 * Read 'count' values from 'data'. If 'data_type' is a file, 'count'
421 * may be used to only read a subset of a file's contents. If 'data'
422 * is already an in-memory buffer of memory, 'count' values will be
423 * copied (which is count * sizeof(data_type) bytes).
424 *
425 * Files can use a non-positive 'count' to mean "read the whole file",
426 * pre-loaded data, however, must provide a positive 'count' otherwise
427 * an empty binunif will be created. File input is assumed to have host byte
428 * order unless WDB_BINUNIF_NETWORK_ORDER is combined with a file data type.
429 * In-memory input is always host order. C++ callers must cast a combined
430 * type and flag back to wdb_binunif. BINUNIF database objects are always
431 * serialized in network byte order.
432 *
433 * Example: (wdb_binunif)(WDB_BINUNIF_FILE_UINT16 |
434 * WDB_BINUNIF_NETWORK_ORDER)
435 */
436WDB_EXPORT extern int mk_binunif(struct rt_wdb *fp, const char *name, const void *data, wdb_binunif data_type, long count);
437
439/**
440 * Create a BOT (Bag O'Triangles) solid
441 */
443 struct rt_wdb *fp, /**< database file pointer to write to */
444 const char *name, /**< name of bot object to write out */
445 unsigned char mode, /**< bot mode */
446 unsigned char orientation, /**< bot orientation */
447 unsigned char error_mode, /**< may be used to indicate error handling (ignored for now) */
448 size_t num_vertices, /**< number of vertices */
449 size_t num_faces, /**< number of faces */
450 fastf_t *vertices, /**< array of floats for vertices [num_vertices*3] */
451 int *faces, /**< array of ints for faces [num_faces*3] */
452 fastf_t *thickness, /**< array of plate mode
453 * thicknesses (corresponds to
454 * array of faces) NULL for
455 * modes RT_BOT_SURFACE and
456 * RT_BOT_SOLID.
457 */
458 struct bu_bitv *face_mode /**< a flag for each face
459 * indicating thickness is
460 * appended to hit point,
461 * otherwise thickness is
462 * centered about hit point
463 */
464 );
465
466/**
467 * Create a BOT (Bag O'Triangles) solid with face normals
468 */
470 struct rt_wdb *fp, /**< database file pointer to write to */
471 const char *name, /**< name of bot object to write out */
472 unsigned char mode, /**< bot mode */
473 unsigned char orientation, /**< bot orientation */
474 unsigned char flags, /**< additional bot flags */
475 size_t num_vertices, /**< number of bot vertices */
476 size_t num_faces, /**< number of bot faces */
477 const fastf_t *vertices, /**< array of floats for vertices [num_vertices*3] */
478 const int *faces, /**< array of ints for faces [num_faces*3] */
479 const fastf_t *thickness, /**< array of plate mode
480 * thicknesses (corresponds to
481 * array of faces) NULL for
482 * modes RT_BOT_SURFACE and
483 * RT_BOT_SOLID.
484 */
485 struct bu_bitv *face_mode, /**< a flag for each face
486 * indicating thickness is
487 * appended to hit point,
488 * otherwise thickness is
489 * centered about hit point
490 */
491 size_t num_normals, /**< number of unit normals in normals array */
492 fastf_t *normals, /**< array of floats for normals [num_normals*3] */
493 int *face_normals /**< array of ints (indices
494 * into normals array), must
495 * have 3*num_faces entries
496 */
497 );
498
499/**
500 * Create a BOT (Bag O'Triangles) solid with face normals and uv texture coordinates
501 */
503 struct rt_wdb *fp, /**< database file pointer to write to */
504 const char *name, /**< name of bot object to write out */
505 unsigned char mode, /**< bot mode */
506 unsigned char orientation, /**< bot orientation */
507 unsigned char flags, /**< additional bot flags */
508 size_t num_vertices, /**< number of bot vertices */
509 size_t num_faces, /**< number of bot faces */
510 const fastf_t *vertices, /**< array of floats for vertices [num_vertices*3] */
511 const int *faces, /**< array of ints for faces [num_faces*3] */
512 const fastf_t *thickness, /**< array of plate mode
513 * thicknesses (corresponds to
514 * array of faces) NULL for
515 * modes RT_BOT_SURFACE and
516 * RT_BOT_SOLID.
517 */
518 struct bu_bitv *face_mode, /**< a flag for each face
519 * indicating thickness is
520 * appended to hit point,
521 * otherwise thickness is
522 * centered about hit point
523 */
524 size_t num_normals, /**< number of unit normals in normals array */
525 fastf_t *normals, /**< array of floats for normals [num_normals*3] */
526 int *face_normals, /**< array of ints (indices
527 * into normals array), must
528 * have 3*num_faces entries
529 */
530 size_t num_uvs, /**< number of uv texture coordinates in uvs array */
531 fastf_t *uvs, /**< array of floats for uv texture coordinates [num_uvs*3] */
532 int *face_uvs /**< array of ints (indices into uvs array), must have 3*num_faces entries */
533 );
534
535/**
536 * Create a brep in the geometry file. vbrep must be a void cast pointer to
537 * an ON_Brep shape.
538 */
539WDB_EXPORT int mk_brep(struct rt_wdb* wdbp, const char* name, void* vbrep);
540
541/**
542 * Output an array of B-spline (NURBS) surfaces which comprise a
543 * solid. The surface is freed when it is written.
544 *
545 * Note: unless there is a specific need to work with the older BRL-CAD
546 * NURBS objects, mk_brep should be used instead of this routine.
547 */
548WDB_EXPORT int mk_bspline(struct rt_wdb *wdbp, const char *name, struct face_g_snurb **surfs);
549
550/**
551 * The NMG is freed after being written.
552 *
553 * @return <0 error, 0 success
554 */
555WDB_EXPORT int mk_nmg(struct rt_wdb *filep, const char *name, struct model *m);
556
557/**
558 * For ray-tracing speed, many database conversion routines like to
559 * offer the option of converting NMG objects to bags of triangles
560 * (BoT). Here is a convenience routine to replace the old routine
561 * write_shell_as_polysolid. (obsolete since BRL-CAD 6.0)
562 */
563WDB_EXPORT int mk_bot_from_nmg(struct rt_wdb *ofp, const char *name, struct shell *s);
564
566/**
567 * Make a sketch
568 */
570 struct rt_wdb *fp,
571 const char *name,
572 const struct rt_sketch_internal *skt);
573
574/**
575 * Make a annotation
576 */
578 struct rt_wdb *fp,
579 const char *name,
580 const struct rt_annot_internal *ann);
581
582/**
583 * Make a script
584 */
586 struct rt_wdb *fp,
587 const char *name,
588 const struct rt_script_internal *scr );
589
590/**
591 * Make an extrusion solid
592 */
594 struct rt_wdb *fp,
595 const char *name,
596 const char *sketch_name,
597 const point_t V,
598 const vect_t h,
599 const vect_t u_vec,
600 const vect_t v_vec,
601 int keypoint);
602
603/**
604 * Support for cline solids (kludges from FASTGEN)
605 *
606 * Note: cline should not be used in .g models unless specifically needed for
607 * FASTGEN compatibility.
608 */
610 struct rt_wdb *fp,
611 const char *name,
612 const point_t V,
613 const vect_t height,
614 fastf_t radius,
615 fastf_t thickness);
616
617/**
618 * Make a particle primitive.
619 *
620 * @return <0 error, 0 success
621 */
622WDB_EXPORT extern int mk_particle(struct rt_wdb *fp, const char *name, point_t vertex,
623 vect_t height, double vradius, double hradius);
625/**
626 * Make a pipe primitive.
627 *
628 * Note that the linked list of pipe segments headed by 'headp' must
629 * be freed by the caller. mk_pipe_free() can be used.
630 *
631 * @return <0 error, 0 success
632 */
633WDB_EXPORT extern int mk_pipe(struct rt_wdb *fp, const char *name, struct bu_list *headp);
634
635/**
636 * Release the storage from a list of pipe segments. The head is left
637 * in initialized state (i.e., forward & back point to head).
638 */
640
641/**
642 * Add another pipe segment to the linked list of pipe segments.
643 */
645 struct bu_list *headp,
646 const point_t coord,
647 double od,
648 double id,
649 double bendradius);
650
651/**
652 * initialize a linked list of pipe segments with the first segment
653 */
655
656/**
657 * Make a point set (pnts) primitive of the given rt_pnt_type from count
658 * points. verts is count*3 coordinates; colors (count*3 unsigned char
659 * RGB), scales (count), and normals (count*3) are required iff the type
660 * carries that attribute, else NULL. scale sets the default display scale.
661 *
662 * @return <0 error, 0 success
663 */
664WDB_EXPORT int mk_pnts(struct rt_wdb *fp, const char *name, rt_pnt_type type,
665 double scale, size_t count, const fastf_t *verts,
666 const unsigned char *colors, const fastf_t *scales,
667 const fastf_t *normals);
668
669/**
670 * Make a datum object from a caller-built, NULL-terminated next-linked
671 * chain of rt_datum_internal elements (point: dir=0,w=0; line: pnt+dir,w=0;
672 * plane: w!=0). The chain is duplicated internally; the caller retains
673 * ownership of head.
674 *
675 * @return <0 error, 0 success
676 */
677WDB_EXPORT int mk_datums(struct rt_wdb *fp, const char *name,
678 struct rt_datum_internal *head);
680
681/**
682 * Displacement map primitive.
683 */
684WDB_EXPORT extern int mk_dsp(struct rt_wdb *fp, const char *name, const char *file,
685 size_t xdim, size_t ydim, const matp_t mat);
687/**
688 * Displacement map primitive sourced from an in-database BINUNIF object
689 * (created via mk_binunif) rather than an external file.
690 */
691WDB_EXPORT extern int mk_dsp_obj(struct rt_wdb *fp, const char *name, const char *binunif,
692 size_t xcnt, size_t ycnt, const matp_t stom);
694/**
695 * Extruded bitmap primitive.
696 */
697WDB_EXPORT extern int mk_ebm(struct rt_wdb *fp, const char *name, const char *file,
698 size_t xdim, size_t ydim, fastf_t tallness, const matp_t mat);
700/**
701 * Extruded bitmap primitive sourced from an in-database BINUNIF object
702 * (created via mk_binunif) rather than an external file.
703 */
704WDB_EXPORT extern int mk_ebm_obj(struct rt_wdb *fp, const char *name, const char *binunif,
705 size_t xdim, size_t ydim, fastf_t tallness, const matp_t mat);
707/**
708 * Heart primitive.
709 */
710WDB_EXPORT extern int mk_hrt(struct rt_wdb *fp, const char *name, const point_t center,
711 const vect_t x, const vect_t y, const vect_t z, const fastf_t dist);
713/**
714 * 3-D Volume primitive.
715 */
716WDB_EXPORT extern int mk_vol(struct rt_wdb *fp, const char *name, char datasrc, const char *file,
717 size_t xdim, size_t ydim, size_t zdim, size_t lo, size_t hi,
718 const vect_t cellsize, const matp_t mat);
719
720
721/**
722 * Create a submodel solid. If file is NULL or "", the treetop refers
723 * to the current database. Treetop is the name of a single database
724 * object in 'file'. meth is normally 0 (RT_PART_NUBSPT) and unused.
725 */
726WDB_EXPORT extern int mk_submodel(struct rt_wdb *fp, const char *name, const char *file,
727 const char *treetop, int meth);
729/**
730 * Interface for writing region-id-based color tables to the database.
731 * Given that the color table has been built up by successive calls to
732 * db_mater_add(), write it into the database.
733 *
734 */
736
737/**
738 * Obtain dynamic storage for a new wmember structure, fill in the
739 * name, default the operation and matrix, and add to doubly linked
740 * list. In typical use, a one-line call is sufficient. To change
741 * the defaults, catch the pointer that is returned, and adjust the
742 * structure to taste.
743 *
744 * The name must be a non-zero length string.
745 *
746 * The caller is responsible for initializing the header structures
747 * forward and backward links.
748 */
749WDB_EXPORT extern struct wmember *mk_addmember(const char *name,
750 struct bu_list *headp,
751 mat_t mat,
752 int op);
753
754#define mk_lcomb(_fp, _name, _headp, _rf, _shadername, _shaderargs, _rgb, _inh) \
755 mk_comb(_fp, _name, &((_headp)->l), _rf, _shadername, _shaderargs, \
756 _rgb, 0, 0, 0, 0, _inh, 0, 0)
757
758/* mk_lrcomb() would not append, and did not have GIFT semantics
759 mk_lrcomb() had (struct wmember *) head, need (struct bu_list *) */
760#define mk_lrcomb(fp, name, _headp, region_flag, shadername, shaderargs, rgb, id, air, material, los, inherit_flag) \
761 mk_comb(fp, name, &((_headp)->l), region_flag, shadername, shaderargs, \
762 rgb, id, air, material, los, inherit_flag, 0, 0)
763
764
765/**
766 * @brief
767 * Combination (region and group) construction: first you build a list of nodes with mk_addmember,
768 * then you output the combination.
769 *
770 * The members are described by a linked list of wmember structs.
771 *
772 * The linked list is freed when it has been output.
773 *
774 * Has many operating modes.
775 *
776 * @return <0 error, 0 success
777 */
779 struct rt_wdb *wdbp, /**< database to write to */
780 const char *combname, /**< name of the combination */
781 struct bu_list *headp, /**< Made by mk_addmember() */
782 int region_kind, /**< 1 => region. 'P' and 'V' for FASTGEN */
783 const char *shadername, /**< shader name, or NULL */
784 const char *shaderargs, /**< shader args, or NULL */
785 const unsigned char *rgb, /**< NULL => no color */
786 int id, /**< region_id */
787 int air, /**< aircode */
788 int material, /**< GIFTmater */
789 int los, /**< line-of-sight thickness equivalence */
790 int inherit, /**< whether objects below inherit from this comb */
791 int append_ok, /**< 0 = obj must not exit */
792 int gift_semantics /**< 0 = pure, 1 = gift */
793 );
794
795/**
796 * Convenience interface to make a combination with a single member.
797 */
798WDB_EXPORT int mk_comb1(struct rt_wdb *fp,
799 const char *combname,
800 const char *membname,
801 int regflag);
802
803
804/**
805 * Convenience routine to make a region with shader and rgb possibly
806 * set.
807 */
809 struct rt_wdb *fp,
810 const char *combname,
811 const char *membname,
812 const char *shadername,
813 const char *shaderargs,
814 const unsigned char *rgb);
815
816#define WMOP_INTERSECT DB_OP_INTERSECT /**< @brief must track db.h */
817#define WMOP_SUBTRACT DB_OP_SUBTRACT /**< @brief must track db.h */
818#define WMOP_UNION DB_OP_UNION /**< @brief must track db.h */
820/* Convenient definitions */
821#define mk_lfcomb(fp, name, headp, region) \
822 mk_lcomb(fp, name, headp, region, (char *)0, (char *)0, (unsigned char *)0, 0);
824/**
825 * Given a string conversion value, find the appropriate factor, and
826 * establish it.
827 *
828 * @return -1 error, 0 OK
829 */
830WDB_EXPORT extern int mk_conversion(const char *units_string);
831
832/**
833 * Establish a new conversion factor for LIBWDB routines.
834 *
835 * @return -1 error, 0 success
836 */
837WDB_EXPORT extern int mk_set_conversion(double val);
838
839/**
840 * This internal variable should not be directly modified;
841 * call mk_conversion() or mk_set_conversion() instead.
842 */
843WDB_EXPORT extern double mk_conv2mm; /**< @brief Conversion factor to mm */
844
845/**
846 * Set this variable to either 4 or 5, depending on which version of
847 * the database you wish to write.
848 */
849WDB_EXPORT extern int mk_version; /**< @brief Which version database to write */
850
851/**
852 * TODO - document this...
853 */
855
856#define mk_export_fwrite(wdbp, name, gp, id) wdb_export(wdbp, name, gp, id, mk_conv2mm)
858/**
859 * @brief
860 * This routine is intended to be used to make a hole in some
861 * geometry.
862 *
863 * The hole is described using the same parameters as an
864 * RCC, and the hole is represented as an RCC. The objects to be
865 * "holed" are passed in as a list of "struct directory" pointers. The
866 * objects pointed at by this list must be combinations. The "struct
867 * rt_wdb" pointer passed in indicates what model this hole should
868 * appear in.
869 *
870 * The end state after this routine runs is a modified model with a
871 * new RCC primitive having a name of the form "make_hole_X" (where X
872 * is some integer). The combinations specified in the list will be
873 * modified as follows:
874 *
875 * before after
876 * | /\
877 * u u -
878 * orig_comb_tree orig_comb_tree make_hole_X
879 *
880 * The modified combination is written to the struct rt_wdb. Note that
881 * to do dynamic geometry a "wdb_dbopen" would normally be called on
882 * an already existing (and possibly prepped) model. Using the
883 * RT_WDB_TYPE_DB_INMEM parameter in this call will result in geometry
884 * changes that only exist in memory and will not be permanently
885 * stored in the original database.
886 *
887 * This routine should be preceded by a call to "rt_unprep" and
888 * followed by a call to "rt_reprep".
889 */
890WDB_EXPORT extern int make_hole(struct rt_wdb *wdbp,
894 int num_objs,
895 struct directory **dp);
896
897
898/**
899 * @brief
900 * This routine provides a quick approach to simply adding a hole to existing
901 * prepped geometry.
902 *
903 * The geometry must already be prepped prior to calling this routine. After
904 * calling this routine, the geometry is ready for raytracing (no other routine
905 * need to be called).
906 *
907 * A new RCC primitive is created and written to the database (wdbp). Note that
908 * this will be temporary if the wdbp pointer was created by a call to
909 * wdb_dbopen with the RT_WDB_TYPE_DB_INMEM flag.
910 *
911 * The "regions" parameter is a list of "struct region" pointers (prepped
912 * regions) to get holed. The regions structures are modified, but the on disk
913 * region records are never modified, so the actual holes will never be
914 * permanent regardless of how "wdbp" was opened.
915 *
916 * There is no need to call "rt_unprep" nor "rt_reprep" with this routine.
917 */
919 struct rt_i *rtip,
922 fastf_t radius,
923 struct bu_ptbl *regions);
924
925
927
928#endif /* WDB_H */
929
930/** @} */
931
932/*
933 * Local Variables:
934 * mode: C
935 * tab-width: 8
936 * indent-tabs-mode: t
937 * c-file-style: "stroustrup"
938 * End:
939 * ex: shiftwidth=4 tabstop=8
940 */
Header file for the BRL-CAD Numerical Computation Library, LIBBN.
Definition dvec.h:74
Header file for the BRL-CAD common definitions.
int mk_arb7(struct rt_wdb *fp, const char *name, const fastf_t *pts7)
int mk_sketch(struct rt_wdb *fp, const char *name, const struct rt_sketch_internal *skt)
int mk_arb6(struct rt_wdb *fp, const char *name, const fastf_t *pts6)
int mk_bot_from_nmg(struct rt_wdb *ofp, const char *name, struct shell *s)
int mk_extrusion(struct rt_wdb *fp, const char *name, const char *sketch_name, const point_t V, const vect_t h, const vect_t u_vec, const vect_t v_vec, int keypoint)
int mk_rpp(struct rt_wdb *fp, const char *name, const point_t min, const point_t max)
int mk_annot(struct rt_wdb *fp, const char *name, const struct rt_annot_internal *ann)
int mk_script(struct rt_wdb *fp, const char *name, const struct rt_script_internal *scr)
int mk_brep(struct rt_wdb *wdbp, const char *name, void *vbrep)
int mk_bot_w_normals_and_uvs(struct rt_wdb *fp, const char *name, unsigned char mode, unsigned char orientation, unsigned char flags, size_t num_vertices, size_t num_faces, const fastf_t *vertices, const int *faces, const fastf_t *thickness, struct bu_bitv *face_mode, size_t num_normals, fastf_t *normals, int *face_normals, size_t num_uvs, fastf_t *uvs, int *face_uvs)
void mk_pipe_free(struct bu_list *headp)
int mk_id_units(struct rt_wdb *fp, const char *title, const char *units)
int mk_ebm(struct rt_wdb *fp, const char *name, const char *file, size_t xdim, size_t ydim, fastf_t tallness, const matp_t mat)
struct wmember * mk_addmember(const char *name, struct bu_list *headp, mat_t mat, int op)
int mk_grip(struct rt_wdb *wdbp, const char *name, const point_t center, const vect_t normal, const fastf_t magnitude)
int mk_conversion(const char *units_string)
int mk_hrt(struct rt_wdb *fp, const char *name, const point_t center, const vect_t x, const vect_t y, const vect_t z, const fastf_t dist)
int mk_ell(struct rt_wdb *fp, const char *name, const point_t center, const vect_t a, const vect_t b, const vect_t c)
int mk_trc_top(struct rt_wdb *fp, const char *name, const point_t ibase, const point_t itop, fastf_t radbase, fastf_t radtop)
int mk_tgc(struct rt_wdb *fp, const char *name, const point_t base, const vect_t height, const vect_t a, const vect_t b, const vect_t c, const vect_t d)
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])
int make_hole_in_prepped_regions(struct rt_wdb *wdbp, struct rt_i *rtip, point_t hole_start, vect_t hole_depth, fastf_t radius, struct bu_ptbl *regions)
This routine provides a quick approach to simply adding a hole to existing prepped geometry.
int mk_comb(struct rt_wdb *wdbp, const char *combname, struct bu_list *headp, int region_kind, const char *shadername, const char *shaderargs, const unsigned char *rgb, int id, int air, int material, int los, int inherit, int append_ok, int gift_semantics)
Combination (region and group) construction: first you build a list of nodes with mk_addmember,...
int mk_arb5(struct rt_wdb *fp, const char *name, const fastf_t *pts5)
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)
double mk_conv2mm
Conversion factor to mm.
wdb_binunif
Definition wdb.h:367
int mk_arb8(struct rt_wdb *fp, const char *name, const fastf_t *pts8)
int mk_material(struct rt_wdb *wdbp, const char *db_name, const char *name, const char *parent, const char *source, struct bu_attribute_value_set *physicalProperties, struct bu_attribute_value_set *mechanicalProperties, struct bu_attribute_value_set *opticalProperties, struct bu_attribute_value_set *thermalProperties)
int mk_version
Which version database to write.
int make_hole(struct rt_wdb *wdbp, point_t hole_start, vect_t hole_depth, fastf_t hole_radius, int num_objs, struct directory **dp)
This routine is intended to be used to make a hole in some geometry.
int mk_bot_w_normals(struct rt_wdb *fp, const char *name, unsigned char mode, unsigned char orientation, unsigned char flags, size_t num_vertices, size_t num_faces, const fastf_t *vertices, const int *faces, const fastf_t *thickness, struct bu_bitv *face_mode, size_t num_normals, fastf_t *normals, int *face_normals)
int mk_region1(struct rt_wdb *fp, const char *combname, const char *membname, const char *shadername, const char *shaderargs, const unsigned char *rgb)
int mk_comb1(struct rt_wdb *fp, const char *combname, const char *membname, int regflag)
int mk_arbn(struct rt_wdb *fp, const char *name, size_t neqn, const plane_t *eqn)
int mk_ebm_obj(struct rt_wdb *fp, const char *name, const char *binunif, size_t xdim, size_t ydim, fastf_t tallness, const matp_t mat)
int mk_submodel(struct rt_wdb *fp, const char *name, const char *file, const char *treetop, int meth)
int mk_set_conversion(double val)
int mk_id_editunits(struct rt_wdb *fp, const char *title, double local2mm)
int mk_rcc(struct rt_wdb *fp, const char *name, const point_t base, const vect_t height, fastf_t radius)
int mk_datums(struct rt_wdb *fp, const char *name, struct rt_datum_internal *head)
int mk_hyp(struct rt_wdb *wdbp, const char *name, const point_t vert, const vect_t height_vector, const vect_t vectA, fastf_t magB, fastf_t base_neck_ratio)
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)
void mk_add_pipe_pnt(struct bu_list *headp, const point_t coord, double od, double id, double bendradius)
int mk_dsp(struct rt_wdb *fp, const char *name, const char *file, size_t xdim, size_t ydim, const matp_t mat)
int mk_arb4(struct rt_wdb *fp, const char *name, const fastf_t *pts4)
int mk_sph(struct rt_wdb *fp, const char *name, const point_t center, fastf_t radius)
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)
int mk_dsp_obj(struct rt_wdb *fp, const char *name, const char *binunif, size_t xcnt, size_t ycnt, const matp_t stom)
int mk_cone(struct rt_wdb *fp, const char *name, const point_t base, const vect_t dirv, fastf_t height, fastf_t base_radius, fastf_t nose_radius)
int mk_half(struct rt_wdb *fp, const char *name, const vect_t norm, fastf_t d)
int mk_particle(struct rt_wdb *fp, const char *name, point_t vertex, vect_t height, double vradius, double hradius)
int mk_constraint(struct rt_wdb *wdbp, const char *name, const char *expr)
int mk_bot(struct rt_wdb *fp, const char *name, unsigned char mode, unsigned char orientation, unsigned char error_mode, size_t num_vertices, size_t num_faces, fastf_t *vertices, int *faces, fastf_t *thickness, struct bu_bitv *face_mode)
int mk_pnts(struct rt_wdb *fp, const char *name, rt_pnt_type type, double scale, size_t count, const fastf_t *verts, const unsigned char *colors, const fastf_t *scales, const fastf_t *normals)
int mk_write_color_table(struct rt_wdb *ofp)
int mk_bspline(struct rt_wdb *wdbp, const char *name, struct face_g_snurb **surfs)
int mk_trc_h(struct rt_wdb *fp, const char *name, const point_t base, const vect_t height, fastf_t radbase, fastf_t radtop)
int mk_pipe(struct rt_wdb *fp, const char *name, struct bu_list *headp)
int mk_wedge(struct rt_wdb *fp, const char *name, const point_t vert, const vect_t xdirv, const vect_t zdirv, fastf_t xlen, fastf_t ylen, fastf_t zlen, fastf_t x_top_len)
int mk_vol(struct rt_wdb *fp, const char *name, char datasrc, const char *file, size_t xdim, size_t ydim, size_t zdim, size_t lo, size_t hi, const vect_t cellsize, const matp_t mat)
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)
int mk_binunif(struct rt_wdb *fp, const char *name, const void *data, wdb_binunif data_type, long count)
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)
void mk_freemembers(struct bu_list *headp)
int mk_cline(struct rt_wdb *fp, const char *name, const point_t V, const vect_t height, fastf_t radius, fastf_t thickness)
int mk_nmg(struct rt_wdb *filep, const char *name, struct model *m)
void mk_pipe_init(struct bu_list *headp)
int mk_id(struct rt_wdb *fp, const char *title)
int mk_ars(struct rt_wdb *fp, const char *name, size_t ncurves, size_t pts_per_curve, fastf_t *curves[])
int mk_tor(struct rt_wdb *fp, const char *name, const point_t center, const vect_t inorm, double r1, double r2)
@ WDB_BINUNIF_FILE_FLOAT
Definition wdb.h:388
@ WDB_BINUNIF_INT
Definition wdb.h:374
@ WDB_BINUNIF_UINT
Definition wdb.h:375
@ WDB_BINUNIF_FILE_UCHAR
Definition wdb.h:391
@ WDB_BINUNIF_FILE_INT
Definition wdb.h:394
@ WDB_BINUNIF_ULONG
Definition wdb.h:377
@ WDB_BINUNIF_USHORT
Definition wdb.h:373
@ WDB_BINUNIF_UINT16
Definition wdb.h:383
@ WDB_BINUNIF_FILE_ULONG
Definition wdb.h:397
@ WDB_BINUNIF_LONGLONG
Definition wdb.h:378
@ WDB_BINUNIF_INT8
Definition wdb.h:380
@ WDB_BINUNIF_FLOAT
Definition wdb.h:368
@ WDB_BINUNIF_INT64
Definition wdb.h:386
@ WDB_BINUNIF_FILE_CHAR
Definition wdb.h:390
@ WDB_BINUNIF_UINT32
Definition wdb.h:385
@ WDB_BINUNIF_FILE_LONG
Definition wdb.h:396
@ WDB_BINUNIF_FILE_INT64
Definition wdb.h:406
@ WDB_BINUNIF_FILE_UINT16
Definition wdb.h:403
@ WDB_BINUNIF_FILE_UINT
Definition wdb.h:395
@ WDB_BINUNIF_SHORT
Definition wdb.h:372
@ WDB_BINUNIF_FILE_UINT8
Definition wdb.h:401
@ WDB_BINUNIF_FILE_USHORT
Definition wdb.h:393
@ WDB_BINUNIF_FILE_UINT32
Definition wdb.h:405
@ WDB_BINUNIF_UCHAR
Definition wdb.h:371
@ WDB_BINUNIF_FILE_INT32
Definition wdb.h:404
@ WDB_BINUNIF_ULONGLONG
Definition wdb.h:379
@ WDB_BINUNIF_FILE_UINT64
Definition wdb.h:407
@ WDB_BINUNIF_LONG
Definition wdb.h:376
@ WDB_BINUNIF_FILE_INT16
Definition wdb.h:402
@ WDB_BINUNIF_DOUBLE
Definition wdb.h:369
@ WDB_BINUNIF_FILE_INT8
Definition wdb.h:400
@ WDB_BINUNIF_CHAR
Definition wdb.h:370
@ WDB_BINUNIF_UINT8
Definition wdb.h:381
@ WDB_BINUNIF_INT16
Definition wdb.h:382
@ WDB_BINUNIF_FILE_SHORT
Definition wdb.h:392
@ WDB_BINUNIF_UINT64
Definition wdb.h:387
@ WDB_BINUNIF_FILE_DOUBLE
Definition wdb.h:389
@ WDB_BINUNIF_FILE_ULONGLONG
Definition wdb.h:399
@ WDB_BINUNIF_FILE_LONGLONG
Definition wdb.h:398
@ WDB_BINUNIF_INT32
Definition wdb.h:384
rt_pnt_type
Definition geom.h:917
fastf_t vect_t[ELEMENTS_PER_VECT]
3-tuple vector
Definition vmath.h:351
double fastf_t
fastest 64-bit (or larger) floating point type
Definition vmath.h:336
fastf_t mat_t[ELEMENTS_PER_MAT]
4x4 matrix
Definition vmath.h:372
fastf_t plane_t[ELEMENTS_PER_PLANE]
Definition of a plane equation.
Definition vmath.h:399
fastf_t * matp_t
pointer to a 4x4 matrix
Definition vmath.h:375
fastf_t point_t[ELEMENTS_PER_POINT]
3-tuple point
Definition vmath.h:357
Global registry of recognized magic numbers.
Definition bitv.h:95
Definition ptbl.h:53
Face NURBS surface geometry.
Definition topology.h:392
NMG topological model.
Definition topology.h:289
Definition wdb.h:60
NMG topological shell.
Definition topology.h:261
NMG topological vertex - the simplest element of the topology system.
Definition topology.h:98
Definition wdb.h:77
char * wm_name
Definition wdb.h:82
int wm_op
Boolean operation.
Definition wdb.h:79
struct bu_list l
Definition wdb.h:78
mat_t wm_mat
Definition wdb.h:80