BRL-CAD
Loading...
Searching...
No Matches
nirt.h
Go to the documentation of this file.
1/* N I R T . H
2 * BRL-CAD
3 *
4 * Copyright (c) 2008-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 libanalyze
21 *
22 * A library implementation of functionality originally developed in
23 * Natalie's Interactive Ray Tracer (NIRT)
24 *
25 */
26/** @{ */
27/** @file analyze/nirt.h */
28
29#ifndef ANALYZE_NIRT_H
30#define ANALYZE_NIRT_H
31
32#include "common.h"
33#include "analyze/defines.h"
34
35#include "bu/opt.h"
36#include "bu/vls.h"
37#include "raytrace.h"
38
39__BEGIN_DECLS
40
41#define NIRT_SILENT_UNSET 0
42#define NIRT_SILENT_YES 1
43#define NIRT_SILENT_NO -1
44
45/** Allowed VALUES FOR overlap_claims in nirt_opt_vals */
46#define NIRT_OVLP_RESOLVE 0
47#define NIRT_OVLP_REBUILD_FASTGEN 1
48#define NIRT_OVLP_REBUILD_ALL 2
49#define NIRT_OVLP_RETAIN 3
50
51/** Container to hold results of nirt option parsing */
78
79#define NIRT_OPT_INIT {0, 0, 1, NIRT_OVLP_RESOLVE, 0, 0, 0, NIRT_SILENT_UNSET, 0, 0, BU_PTBL_INIT_ZERO, 0, 0, BU_PTBL_INIT_ZERO, BU_VLS_INIT_ZERO, BU_VLS_INIT_ZERO, VINIT_ZERO, BU_VLS_INIT_ZERO, BU_COLOR_CYAN, BU_COLOR_YELLOW, BU_COLOR_PURPLE, BU_COLOR_WHITE}
80
81/**
82 * Given a nirt_opt_vals container, set up and return a bu_opt_desc that can
83 * parse options from an argv array. Caller is responsible for freeing the
84 * resulting bu_opt_desc array. */
85ANALYZE_EXPORT struct bu_opt_desc *nirt_opt_desc(struct nirt_opt_vals *o);
86
87/**
88 * Reset a nirt_opt_vals structure to its initial state. Structure is still
89 * usable after this operation. */
90ANALYZE_EXPORT void nirt_opt_vals_reset(struct nirt_opt_vals *o);
91
92/**
93 * Free all contents of a nirt_opt_vals structure. Structure is unusable
94 * after this operation. */
95ANALYZE_EXPORT void nirt_opt_vals_free(struct nirt_opt_vals *o);
96
97/**
98 * Generate argv style options that attempts to generate an argv that will make
99 * the option values in tgt look like those in src. argv strings will be
100 * inserted into tbl - caller is responsible for freeing them.
101 *
102 * There are a few caveats - options like silent or verbose that have only an
103 * enabling flag will be turned on if they are off in tgt, but if they are off
104 * in src and on in tgt there is no command line option to disable them once
105 * set.
106 *
107 * Operations on init_scripts, performed if add_scripts is non-zero, are
108 * additive ONLY - because it is legitimate to have multiple scripts and
109 * settings with the same values, it can only add what is present in src to
110 * what is already in tgt.
111 */
112ANALYZE_EXPORT void nirt_opt_mk_args(struct bu_ptbl *tbl, struct nirt_opt_vals *tgt, struct nirt_opt_vals *src, int add_scripts);
113
114
115/** Opaque container to hold NIRT's state */
116struct nirt_state_impl;
118 struct nirt_state_impl *i;
126};
127
128/**
129 * Perform non-database dependent initialization. A newly initialized state
130 * can accept some commands (like updates to the attribute list) but will not
131 * be able to raytrace. To set up a raytracing environment, apply
132 * nirt_init_dbip */
133ANALYZE_EXPORT int nirt_init(struct nirt_state *ns);
134
135/**
136 * Initialize a struct nirt_state state for a particular database. After this
137 * step a nirt instance is ready to raytrace. */
138ANALYZE_EXPORT int nirt_init_dbip(struct nirt_state *ns, struct db_i *dbip);
139
140/**
141 * Clear those aspects of a struct nirt_state state specific to a database
142 * instance. */
143ANALYZE_EXPORT int nirt_clear_dbip(struct nirt_state *ns);
144
145/**
146 * Clean up and free the internals of a NIRT state. */
147ANALYZE_EXPORT void nirt_destroy(struct nirt_state *ns);
148
149/**
150 * Execute nirt commands. Runs either the supplied script.
151 *
152 * Returns -1 if there was any sort of error, 0 if the script executed
153 * successfully without a quit call, and 1 if a quit command was encountered
154 * during execution. See the man(1) nirt manual page for documentation of
155 * valid script commands and options.
156 */
157ANALYZE_EXPORT int nirt_exec(struct nirt_state *ns, const char *script);
158
159/* Flags for clearing/resetting/reporting the struct nirt_state state */
160#define NIRT_ALL 0x1 /**< @brief reset to initial state or report all state */
161#define NIRT_OUT 0x2 /**< @brief output log*/
162#define NIRT_MSG 0x4 /**< @brief output log*/
163#define NIRT_ERR 0x8 /**< @brief error log */
164#define NIRT_SEGS 0x10 /**< @brief segment list */
165#define NIRT_OBJS 0x20 /**< @brief 'active' objects from the scene */
166#define NIRT_FRMTS 0x40 /**< @brief available pre-defined output formats */
167#define NIRT_VIEW 0x80 /**< @brief the current view (ae/dir/center/etc.) */
168
169/**
170 * Associate a pointer to user data with the struct nirt_state state, unless
171 * u_data is NULL. Returns the current u_data pointer - so to extract the
172 * current struct nirt_state data pointer value, supply a NULL argument to
173 * u_data. If u_data is non-NULL, the current data pointer will be overwritten
174 * - the caller should save the old pointer if they need it before setting the
175 * new one. */
176ANALYZE_EXPORT void *nirt_udata(struct nirt_state *ns, void *u_data);
177
178/**
179 * Mechanism for setting callback hooks executed when the specified state is
180 * changed after a nirt_exec call. struct nirt_state_ALL will be executed
181 * last, and is run if set and if any of the other states change. Hook
182 * functions will be passed the current value of the u_data pointer. */
183typedef int (*nirt_hook_t)(struct nirt_state *ns, void *u_data);
184ANALYZE_EXPORT void nirt_hook(struct nirt_state *ns, nirt_hook_t hf, int flag);
185
186/**
187 * Reset some or all of the struct nirt_state state, depending on the supplied
188 * flags. If other flags are provided with struct nirt_state_ALL, struct
189 * nirt_state_ALL will skip the clearing step(s) specified by the other
190 * flag(s). So, for example, if a caller wishes to reset the struct nirt_state
191 * state but retain the existing scripts for reuse they could call with
192 * nirt_clear with struct nirt_state_ALL|struct nirt_state_SCRIPTS. Note that
193 * the struct nirt_state_FRMTS, struct nirt_state_OUT and struct nirt_state_ERR
194 * flags are no-ops for nirt_clear. */
195ANALYZE_EXPORT void nirt_clear(struct nirt_state *ns, int flags);
196
197/**
198 * Report command output. For SEGS, SCRIPTS, OBJS and FRMTS reports a textual
199 * list of the output. Unlike clear, which takes the type as combinable flags,
200 * nirt_log expects only one type. Returns -1 if output can't be printed for
201 * any reason (NULL input or unknown output_type) and 0 otherwise. */
202ANALYZE_EXPORT void nirt_log(struct bu_vls *o, struct nirt_state *ns, int output_type);
203
204/**
205 * Reports available commands and their options. Returns -1 if help can't be
206 * printed for any reason (NULL input or unknown output type) and 0 otherwise.
207 */
208ANALYZE_EXPORT int nirt_help(struct bu_vls *h, struct nirt_state *ns, bu_opt_format_t ofmt);
209
210/**
211 * Return any line segments generated by processed commands in segs. Returns
212 * number of line segments in segs, or -1 if there was an error. */
213ANALYZE_EXPORT int nirt_line_segments(struct bv_vlblock **segs, struct nirt_state *ns);
214
215
216__END_DECLS
217
218#endif /* ANALYZE_NIRT_H */
219
220/** @} */
221
222/*
223 * Local Variables:
224 * tab-width: 8
225 * mode: C
226 * indent-tabs-mode: t
227 * c-file-style: "stroustrup"
228 * End:
229 * ex: shiftwidth=4 tabstop=8
230 */
Header file for the BRL-CAD common definitions.
bu_opt_format_t
Definition opt.h:230
void float float int int * flag
Definition tig.h:129
int nirt_init_dbip(struct nirt_state *ns, struct db_i *dbip)
int nirt_init(struct nirt_state *ns)
void nirt_clear(struct nirt_state *ns, int flags)
void nirt_opt_vals_reset(struct nirt_opt_vals *o)
void * nirt_udata(struct nirt_state *ns, void *u_data)
void nirt_destroy(struct nirt_state *ns)
int nirt_exec(struct nirt_state *ns, const char *script)
void nirt_hook(struct nirt_state *ns, nirt_hook_t hf, int flag)
void nirt_opt_vals_free(struct nirt_opt_vals *o)
int nirt_line_segments(struct bv_vlblock **segs, struct nirt_state *ns)
void nirt_log(struct bu_vls *o, struct nirt_state *ns, int output_type)
struct bu_opt_desc * nirt_opt_desc(struct nirt_opt_vals *o)
void nirt_opt_mk_args(struct bu_ptbl *tbl, struct nirt_opt_vals *tgt, struct nirt_opt_vals *src, int add_scripts)
int nirt_clear_dbip(struct nirt_state *ns)
int(* nirt_hook_t)(struct nirt_state *ns, void *u_data)
Definition nirt.h:183
int nirt_help(struct bu_vls *h, struct nirt_state *ns, bu_opt_format_t ofmt)
fastf_t vect_t[ELEMENTS_PER_VECT]
3-tuple vector
Definition vmath.h:349
"Option description" structure.
Definition opt.h:170
Definition ptbl.h:53
Definition vls.h:53
struct bu_vls plotfile
Definition nirt.h:71
int current_center
Definition nirt.h:53
int verbose_mode
Definition nirt.h:62
vect_t center_model
Definition nirt.h:69
struct bu_color color_even
Definition nirt.h:73
int file_cnt
Definition nirt.h:54
struct bu_color color_odd
Definition nirt.h:72
int silent_mode
Definition nirt.h:60
int fmt_set
Definition nirt.h:64
struct bu_ptbl init_scripts
Definition nirt.h:66
int use_air
Definition nirt.h:61
struct bu_vls nirt_debug
Definition nirt.h:68
struct bu_color color_ovlp
Definition nirt.h:75
int overlap_claims
Definition nirt.h:56
struct bu_ptbl attrs
Definition nirt.h:63
int read_matrix
Definition nirt.h:58
int print_help
Definition nirt.h:57
int show_formats
Definition nirt.h:59
struct bu_color color_gap
Definition nirt.h:74
int header_mode
Definition nirt.h:55
struct bu_vls filename
Definition nirt.h:67
int script_set
Definition nirt.h:65
struct bu_vls plotfile
Definition nirt.h:121
struct bu_vls nirt_cmd
Definition nirt.h:119
struct bu_vls nirt_format_file
Definition nirt.h:120
struct bu_color color_even
Definition nirt.h:123
struct bu_color color_odd
Definition nirt.h:122
struct bu_color color_ovlp
Definition nirt.h:125
struct nirt_state_impl * i
Definition nirt.h:118
struct bu_color color_gap
Definition nirt.h:124