BRL-CAD
Loading...
Searching...
No Matches
vlist.h
Go to the documentation of this file.
1/* V L I S T . H
2 * BRL-CAD
3 *
4 * Copyright (c) 2004-2025 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 bv_vlist
21 *
22 * @brief
23 * Definitions for handling lists of vectors (really vertices, or
24 * points) and polygons in 3-space. Intended for common handling of
25 * wireframe display information, in the full resolution that is
26 * calculated in.
27 *
28 * On 32-bit machines, BV_VLIST_CHUNK of 35 results in bv_vlist
29 * structures just less than 1k bytes.
30 *
31 * The head of the doubly linked list can be just a "struct bu_list"
32 * head.
33 *
34 * To visit all the elements in the vlist:
35 * for (BU_LIST_FOR(vp, bv_vlist, hp)) {
36 * int i;
37 * int nused = vp->nused;
38 * int *cmd = vp->cmd;
39 * point_t *pt = vp->pt;
40 * for (i = 0; i < nused; i++, cmd++, pt++) {
41 * access(*cmd, *pt);
42 * access(vp->cmd[i], vp->pt[i]);
43 * }
44 * }
45 */
46/** @{ */
47/** @file bv/vlist.h */
48
49#ifndef BV_VLIST_H
50#define BV_VLIST_H
51
52#include "common.h"
53#include <stdio.h> /* for FILE */
54#include "vmath.h"
55#include "bu/magic.h"
56#include "bu/list.h"
57#include "bu/malloc.h"
58#include "bu/vls.h"
59#include "bv/defines.h"
60
62
63#define BV_VLIST_CHUNK 35 /**< @brief 32-bit mach => just less than 1k */
64
65struct bv_vlist {
66 struct bu_list l; /**< @brief magic, forw, back */
67 size_t nused; /**< @brief elements 0..nused active */
68 int cmd[BV_VLIST_CHUNK]; /**< @brief VL_CMD_* */
69 point_t pt[BV_VLIST_CHUNK]; /**< @brief associated 3-point/vect */
70};
71#define BV_VLIST_NULL ((struct bv_vlist *)0)
72#define BV_CK_VLIST(_p) BU_CKMAG((_p), BV_VLIST_MAGIC, "bv_vlist")
73
74/* should these be enum? -Erik */
75/* Values for cmd[] */
76#define BV_VLIST_LINE_MOVE 0 /**< @brief specify new line */
77#define BV_VLIST_LINE_DRAW 1 /**< @brief subsequent line vertex */
78#define BV_VLIST_POLY_START 2 /**< @brief pt[] has surface normal */
79#define BV_VLIST_POLY_MOVE 3 /**< @brief move to first poly vertex */
80#define BV_VLIST_POLY_DRAW 4 /**< @brief subsequent poly vertex */
81#define BV_VLIST_POLY_END 5 /**< @brief last vert (repeats 1st), draw poly */
82#define BV_VLIST_POLY_VERTNORM 6 /**< @brief per-vertex normal, for interpolation */
83#define BV_VLIST_TRI_START 7 /**< @brief pt[] has surface normal */
84#define BV_VLIST_TRI_MOVE 8 /**< @brief move to first triangle vertex */
85#define BV_VLIST_TRI_DRAW 9 /**< @brief subsequent triangle vertex */
86#define BV_VLIST_TRI_END 10 /**< @brief last vert (repeats 1st), draw poly */
87#define BV_VLIST_TRI_VERTNORM 11 /**< @brief per-vertex normal, for interpolation */
88#define BV_VLIST_POINT_DRAW 12 /**< @brief Draw a single point */
89#define BV_VLIST_POINT_SIZE 13 /**< @brief specify point pixel size */
90#define BV_VLIST_LINE_WIDTH 14 /**< @brief specify line pixel width */
91#define BV_VLIST_DISPLAY_MAT 15 /**< @brief specify the model matrix */
92#define BV_VLIST_MODEL_MAT 16 /**< @brief specify the display matrix */
93#define BV_VLIST_CMD_MAX 16 /**< @brief Max command number */
94/**
95 * Applications that are going to use BV_ADD_VLIST and BV_GET_VLIST
96 * are required to execute this macro once, on their _free_hd:
97 * BU_LIST_INIT(&_free_hd);
98 *
99 * Note that BV_GET_VLIST and BV_FREE_VLIST are non-PARALLEL.
100 */
101#define BV_GET_VLIST(_free_hd, p) do {\
102 (p) = BU_LIST_FIRST(bv_vlist, (_free_hd)); \
103 if (BU_LIST_IS_HEAD((p), (_free_hd))) { \
104 BU_ALLOC((p), struct bv_vlist); \
105 (p)->l.magic = BV_VLIST_MAGIC; \
106 } else { \
107 BU_LIST_DEQUEUE(&((p)->l)); \
108 } \
109 (p)->nused = 0; \
110 } while (0)
111
112/** Place an entire chain of bv_vlist structs on the freelist _free_hd */
113#define BV_FREE_VLIST(_free_hd, hd) do { \
114 BU_CK_LIST_HEAD((hd)); \
115 BU_LIST_APPEND_LIST((_free_hd), (hd)); \
116 } while (0)
117
118#define BV_ADD_VLIST(_free_hd, _dest_hd, pnt, draw) do { \
119 struct bv_vlist *_vp; \
120 BU_CK_LIST_HEAD(_dest_hd); \
121 _vp = BU_LIST_LAST(bv_vlist, (_dest_hd)); \
122 if (BU_LIST_IS_HEAD(_vp, (_dest_hd)) || _vp->nused >= BV_VLIST_CHUNK) { \
123 BV_GET_VLIST(_free_hd, _vp); \
124 BU_LIST_INSERT((_dest_hd), &(_vp->l)); \
125 } \
126 VMOVE(_vp->pt[_vp->nused], (pnt)); \
127 _vp->cmd[_vp->nused++] = (draw); \
128 } while (0)
129
130/** Change the transformation matrix to display */
131#define BV_VLIST_SET_DISP_MAT(_free_hd, _dest_hd, _ref_pt) do { \
132 struct bv_vlist *_vp; \
133 BU_CK_LIST_HEAD(_dest_hd); \
134 _vp = BU_LIST_LAST(bv_vlist, (_dest_hd)); \
135 if (BU_LIST_IS_HEAD(_vp, (_dest_hd)) || _vp->nused >= BV_VLIST_CHUNK) { \
136 BV_GET_VLIST(_free_hd, _vp); \
137 BU_LIST_INSERT((_dest_hd), &(_vp->l)); \
138 } \
139 VMOVE(_vp->pt[_vp->nused], (_ref_pt)); \
140 _vp->cmd[_vp->nused++] = BV_VLIST_DISPLAY_MAT; \
141 } while (0)
142
143/** Change the transformation matrix to model */
144#define BV_VLIST_SET_MODEL_MAT(_free_hd, _dest_hd) do { \
145 struct bv_vlist *_vp; \
146 BU_CK_LIST_HEAD(_dest_hd); \
147 _vp = BU_LIST_LAST(bv_vlist, (_dest_hd)); \
148 if (BU_LIST_IS_HEAD(_vp, (_dest_hd)) || _vp->nused >= BV_VLIST_CHUNK) { \
149 BV_GET_VLIST(_free_hd, _vp); \
150 BU_LIST_INSERT((_dest_hd), &(_vp->l)); \
151 } \
152 _vp->cmd[_vp->nused++] = BV_VLIST_MODEL_MAT; \
153 } while (0)
154
155/** Set a point size to apply to the vlist elements that follow. */
156#define BV_VLIST_SET_POINT_SIZE(_free_hd, _dest_hd, _size) do { \
157 struct bv_vlist *_vp; \
158 BU_CK_LIST_HEAD(_dest_hd); \
159 _vp = BU_LIST_LAST(bv_vlist, (_dest_hd)); \
160 if (BU_LIST_IS_HEAD(_vp, (_dest_hd)) || _vp->nused >= BV_VLIST_CHUNK) { \
161 BV_GET_VLIST(_free_hd, _vp); \
162 BU_LIST_INSERT((_dest_hd), &(_vp->l)); \
163 } \
164 _vp->pt[_vp->nused][0] = (_size); \
165 _vp->cmd[_vp->nused++] = BV_VLIST_POINT_SIZE; \
166 } while (0)
167
168/** Set a line width to apply to the vlist elements that follow. */
169#define BV_VLIST_SET_LINE_WIDTH(_free_hd, _dest_hd, _width) do { \
170 struct bv_vlist *_vp; \
171 BU_CK_LIST_HEAD(_dest_hd); \
172 _vp = BU_LIST_LAST(bv_vlist, (_dest_hd)); \
173 if (BU_LIST_IS_HEAD(_vp, (_dest_hd)) || _vp->nused >= BV_VLIST_CHUNK) { \
174 BV_GET_VLIST(_free_hd, _vp); \
175 BU_LIST_INSERT((_dest_hd), &(_vp->l)); \
176 } \
177 _vp->pt[_vp->nused][0] = (_width); \
178 _vp->cmd[_vp->nused++] = BV_VLIST_LINE_WIDTH; \
179 } while (0)
180
181
183BV_EXPORT extern int bv_vlist_bbox(struct bu_list *vlistp, point_t *bmin, point_t *bmax, size_t *length, int *dispmode);
184
185
186
187/**
188 * For plotting, a way of separating plots into separate color vlists:
189 * blocks of vlists, each with an associated color.
190 */
193 size_t nused;
194 size_t max;
195 long *rgb; /**< @brief rgb[max] variable size array */
196 struct bu_list *head; /**< @brief head[max] variable size array */
197 struct bu_list *free_vlist_hd; /**< @brief where to get/put free vlists */
198};
199#define BV_CK_VLBLOCK(_p) BU_CKMAG((_p), BV_VLBLOCK_MAGIC, "bv_vlblock")
200
201
202/**
203 * Convert a string to a vlist.
204 *
205 * 'scale' is the width, in mm, of one character.
206 *
207 * @param vhead vhead
208 * @param free_hd source of free vlists
209 * @param string string of chars to be plotted
210 * @param origin lower left corner of 1st char
211 * @param rot Transform matrix (WARNING: may xlate)
212 * @param scale scale factor to change 1x1 char sz
213 *
214 */
216 struct bu_list *free_hd,
217 const char *string,
218 const point_t origin,
219 const mat_t rot,
220 double scale);
221
222/**
223 * Convert string to vlist in 2D
224 *
225 * A simpler interface, for those cases where the text lies in the X-Y
226 * plane.
227 *
228 * @param vhead vhead
229 * @param free_hd source of free vlists
230 * @param string string of chars to be plotted
231 * @param x lower left corner of 1st char
232 * @param y lower left corner of 1st char
233 * @param scale scale factor to change 1x1 char sz
234 * @param theta degrees ccw from X-axis
235 *
236 */
238 struct bu_list *free_hd,
239 const char *string,
240 double x,
241 double y,
242 double scale,
243 double theta);
244
245/**
246 * Returns the description of a vlist cmd. Caller is responsible
247 * for freeing the returned string.
248 */
249BV_EXPORT extern const char *bv_vlist_get_cmd_description(int cmd);
250
251/**
252 * Validate an bv_vlist chain for having reasonable values inside.
253 * Calls bu_bomb() if not.
254 *
255 * Returns -
256 * npts Number of point/command sets in use.
257 */
258BV_EXPORT extern size_t bv_ck_vlist(const struct bu_list *vhead);
259
260
261/**
262 * Duplicate the contents of a vlist. Note that the copy may be more
263 * densely packed than the source.
264 */
266 struct bu_list *dest,
267 const struct bu_list *src);
268
269
270/**
271 * Convert a vlist chain into a blob of network-independent binary,
272 * for transmission to another machine.
273 *
274 * The result is stored in a vls string, so that both the address and
275 * length are available conveniently.
276 */
278 struct bu_list *hp,
279 const char *name);
280
281
282/**
283 * Convert a blob of network-independent binary prepared by
284 * vls_vlist() and received from another machine, into a vlist chain.
285 */
287 struct bu_list *hp,
288 struct bu_vls *namevls,
289 const unsigned char *buf);
290
292
293BV_EXPORT extern struct bv_vlblock *bv_vlblock_init(struct bu_list *free_vlist_hd, /* where to get/put free vlists */
294 int max_ent);
295
297
299 int r,
300 int g,
301 int b);
302
303
304BV_EXPORT void bv_vlist_rpp(struct bu_list *vlists, struct bu_list *hd, const point_t minn, const point_t maxx);
305
306/**
307 * Output a bv_vlblock object in extended UNIX-plot format, including
308 * color.
309 */
310BV_EXPORT extern void bv_plot_vlblock(FILE *fp,
311 const struct bv_vlblock *vbp);
312
314 const char *name_root,
315 struct bv_vlblock *vbp,
316 struct bview *v,
317 struct bv_scene_obj *f,
318 struct bu_list *vlfree);
319
320
321BV_EXPORT extern struct bv_scene_obj *
322bv_vlblock_obj(struct bv_vlblock *vbp, struct bview *v, const char *name);
323
324/**
325 * Output a vlist as an extended 3-D floating point UNIX-Plot file.
326 * You provide the file. Uses libplot3 routines to create the
327 * UNIX-Plot output.
328 */
329BV_EXPORT extern void bv_vlist_to_uplot(FILE *fp,
330 const struct bu_list *vhead);
331
332/** @} */
333
335
336#endif /* BV_VLIST_H */
337
338/*
339 * Local Variables:
340 * mode: C
341 * tab-width: 8
342 * indent-tabs-mode: t
343 * c-file-style: "stroustrup"
344 * End:
345 * ex: shiftwidth=4 tabstop=8
346 */
Definition dvec.h:74
Header file for the BRL-CAD common definitions.
void float int int float float * theta
Definition tig.h:167
void int float float float * scale
Definition tig.h:142
void float float * y
Definition tig.h:73
void int char int * length
Definition tig.h:180
void float * x
Definition tig.h:72
void bv_vlist_export(struct bu_vls *vls, struct bu_list *hp, const char *name)
#define BV_VLIST_CHUNK
32-bit mach => just less than 1k
Definition vlist.h:63
size_t bv_ck_vlist(const struct bu_list *vhead)
void bv_vlist_cleanup(struct bu_list *hd)
const char * bv_vlist_get_cmd_description(int cmd)
void bv_vlist_3string(struct bu_list *vhead, struct bu_list *free_hd, const char *string, const point_t origin, const mat_t rot, double scale)
void bv_vlblock_to_objs(struct bu_ptbl *out, const char *name_root, struct bv_vlblock *vbp, struct bview *v, struct bv_scene_obj *f, struct bu_list *vlfree)
size_t bv_vlist_cmd_cnt(struct bv_vlist *vlist)
void bv_plot_vlblock(FILE *fp, const struct bv_vlblock *vbp)
struct bv_scene_obj * bv_vlblock_obj(struct bv_vlblock *vbp, struct bview *v, const char *name)
int bv_vlist_bbox(struct bu_list *vlistp, point_t *bmin, point_t *bmax, size_t *length, int *dispmode)
void bv_vlist_rpp(struct bu_list *vlists, struct bu_list *hd, const point_t minn, const point_t maxx)
struct bv_vlblock * bv_vlblock_init(struct bu_list *free_vlist_hd, int max_ent)
void bv_vlist_to_uplot(FILE *fp, const struct bu_list *vhead)
void bv_vlist_import(struct bu_list *vlists, struct bu_list *hp, struct bu_vls *namevls, const unsigned char *buf)
void bv_vlblock_free(struct bv_vlblock *vbp)
struct bu_list * bv_vlblock_find(struct bv_vlblock *vbp, int r, int g, int b)
void bv_vlist_2string(struct bu_list *vhead, struct bu_list *free_hd, const char *string, double x, double y, double scale, double theta)
void bv_vlist_copy(struct bu_list *vlists, struct bu_list *dest, const struct bu_list *src)
fastf_t mat_t[ELEMENTS_PER_MAT]
4x4 matrix
Definition vmath.h:370
fastf_t point_t[ELEMENTS_PER_POINT]
3-tuple point
Definition vmath.h:355
Global registry of recognized magic numbers.
Definition ptbl.h:53
Definition vls.h:53
size_t max
Definition vlist.h:194
long * rgb
rgb[max] variable size array
Definition vlist.h:195
uint32_t magic
Definition vlist.h:192
size_t nused
Definition vlist.h:193
struct bu_list * free_vlist_hd
where to get/put free vlists
Definition vlist.h:197
struct bu_list * head
head[max] variable size array
Definition vlist.h:196
size_t nused
elements 0..nused active
Definition vlist.h:67
struct bu_list l
magic, forw, back
Definition vlist.h:66
int cmd[BV_VLIST_CHUNK]
VL_CMD_*.
Definition vlist.h:68
point_t pt[BV_VLIST_CHUNK]
associated 3-point/vect
Definition vlist.h:69
fundamental vector, matrix, quaternion math macros