BRL-CAD
nirt.h
Go to the documentation of this file.
1 /* N I R T . H
2  * BRL-CAD
3  *
4  * Copyright (c) 2008-2024 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 /** Opaque container to hold NIRT's state */
42 struct nirt_state_impl;
43 struct nirt_state {
44  struct nirt_state_impl *i;
45  struct bu_vls nirt_cmd;
46  struct bu_vls nirt_format_file;
47 };
48 
49 /**
50  * Perform non-database dependent initialization. A newly initialized state
51  * can accept some commands (like updates to the attribute list) but will not
52  * be able to raytrace. To set up a raytracing environment, apply
53  * nirt_init_dbip */
54 ANALYZE_EXPORT int nirt_init(struct nirt_state *ns);
55 
56 /**
57  * Initialize a struct nirt_state state for a particular database. After this
58  * step a nirt instance is ready to raytrace. */
59 ANALYZE_EXPORT int nirt_init_dbip(struct nirt_state *ns, struct db_i *dbip);
60 
61 /**
62  * Clear those aspects of a struct nirt_state state specific to a database
63  * instance. */
64 ANALYZE_EXPORT int nirt_clear_dbip(struct nirt_state *ns);
65 
66 /**
67  * Clean up and free the internals of a NIRT state. */
68 ANALYZE_EXPORT void nirt_destroy(struct nirt_state *ns);
69 
70 /**
71  * Execute nirt commands. Runs either the supplied script.
72  *
73  * Returns -1 if there was any sort of error, 0 if the script executed
74  * successfully without a quit call, and 1 if a quit command was encountered
75  * during execution. See the man(1) nirt manual page for documentation of
76  * valid script commands and options.
77  */
78 ANALYZE_EXPORT int nirt_exec(struct nirt_state *ns, const char *script);
79 
80 /* Flags for clearing/resetting/reporting the struct nirt_state state */
81 #define NIRT_ALL 0x1 /**< @brief reset to initial state or report all state */
82 #define NIRT_OUT 0x2 /**< @brief output log*/
83 #define NIRT_MSG 0x4 /**< @brief output log*/
84 #define NIRT_ERR 0x8 /**< @brief error log */
85 #define NIRT_SEGS 0x10 /**< @brief segment list */
86 #define NIRT_OBJS 0x20 /**< @brief 'active' objects from the scene */
87 #define NIRT_FRMTS 0x40 /**< @brief available pre-defined output formats */
88 #define NIRT_VIEW 0x80 /**< @brief the current view (ae/dir/center/etc.) */
89 
90 /**
91  * Associate a pointer to user data with the struct nirt_state state, unless
92  * u_data is NULL. Returns the current u_data pointer - so to extract the
93  * current struct nirt_state data pointer value, supply a NULL argument to
94  * u_data. If u_data is non-NULL, the current data pointer will be overwritten
95  * - the caller should save the old pointer if they need it before setting the
96  * new one. */
97 ANALYZE_EXPORT void *nirt_udata(struct nirt_state *ns, void *u_data);
98 
99 /**
100  * Mechanism for setting callback hooks executed when the specified state is
101  * changed after a nirt_exec call. struct nirt_state_ALL will be executed
102  * last, and is run if set and if any of the other states change. Hook
103  * functions will be passed the current value of the u_data pointer. */
104 typedef int (*nirt_hook_t)(struct nirt_state *ns, void *u_data);
105 ANALYZE_EXPORT void nirt_hook(struct nirt_state *ns, nirt_hook_t hf, int flag);
106 
107 /**
108  * Reset some or all of the struct nirt_state state, depending on the supplied
109  * flags. If other flags are provided with struct nirt_state_ALL, struct
110  * nirt_state_ALL will skip the clearing step(s) specified by the other
111  * flag(s). So, for example, if a caller wishes to reset the struct nirt_state
112  * state but retain the existing scripts for reuse they could call with
113  * nirt_clear with struct nirt_state_ALL|struct nirt_state_SCRIPTS. Note that
114  * the struct nirt_state_FRMTS, struct nirt_state_OUT and struct nirt_state_ERR
115  * flags are no-ops for nirt_clear. */
116 ANALYZE_EXPORT void nirt_clear(struct nirt_state *ns, int flags);
117 
118 /**
119  * Report command output. For SEGS, SCRIPTS, OBJS and FRMTS reports a textual
120  * list of the output. Unlike clear, which takes the type as combinable flags,
121  * nirt_log expects only one type. Returns -1 if output can't be printed for
122  * any reason (NULL input or unknown output_type) and 0 otherwise. */
123 ANALYZE_EXPORT void nirt_log(struct bu_vls *o, struct nirt_state *ns, int output_type);
124 
125 /**
126  * Reports available commands and their options. Returns -1 if help can't be
127  * printed for any reason (NULL input or unknown output type) and 0 otherwise.
128  */
129 ANALYZE_EXPORT int nirt_help(struct bu_vls *h, struct nirt_state *ns, bu_opt_format_t ofmt);
130 
131 /**
132  * Return any line segments generated by processed commands in segs. Returns
133  * number of line segments in segs, or -1 if there was an error. */
134 ANALYZE_EXPORT int nirt_line_segments(struct bv_vlblock **segs, struct nirt_state *ns);
135 
136 
137 __END_DECLS
138 
139 #endif /* ANALYZE_NIRT_H */
140 
141 /** @} */
142 
143 /*
144  * Local Variables:
145  * tab-width: 8
146  * mode: C
147  * indent-tabs-mode: t
148  * c-file-style: "stroustrup"
149  * End:
150  * ex: shiftwidth=4 tabstop=8
151  */
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_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)
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)
int nirt_clear_dbip(struct nirt_state *ns)
int(* nirt_hook_t)(struct nirt_state *ns, void *u_data)
Definition: nirt.h:104
int nirt_help(struct bu_vls *h, struct nirt_state *ns, bu_opt_format_t ofmt)
void * nirt_udata(struct nirt_state *ns, void *u_data)
Definition: vls.h:53
struct bu_vls nirt_cmd
Definition: nirt.h:45
struct bu_vls nirt_format_file
Definition: nirt.h:46
struct nirt_state_impl * i
Definition: nirt.h:44