BRL-CAD
api.h
Go to the documentation of this file.
1/* G C V _ A P I . H
2 * BRL-CAD
3 *
4 * Copyright (c) 2008-2023 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/** @file gcv/api.h
21 *
22 * Main public API of the LIBGCV geometry conversion library.
23 *
24 */
25
26#ifndef GCV_API_H
27#define GCV_API_H
28
29#include "common.h"
30#include "vmath.h"
31
32#include "bu/avs.h"
33#include "bu/opt.h"
34#include "bu/mime.h"
35#include "bn/tol.h"
36#include "rt/defines.h"
37#include "rt/tol.h"
38#include "gcv/defines.h"
39
40__BEGIN_DECLS
41
42
43/**
44 * The big kahuna.
45 */
46struct gcv_context_internal;
48{
49 struct db_i *dbip;
51 struct gcv_context_internal *i; // Internal information
52};
53
54
55/**
56 * Initialize a conversion context.
57 */
58GCV_EXPORT void
60
61
62/**
63 * Release a conversion context, freeing all memory internally
64 * allocated by the library. Caller is responsible for freeing the
65 * context pointer itself, if necessary.
66 */
67GCV_EXPORT void
69
70
75};
76
77
82};
83
84
85/**
86 * Conversion options.
87 */
89{
90 /* debug flags, applied via bitwise-OR
91 * original flags are restored after conversion */
93 uint32_t rt_debug_flag;
95
96 /* print debugging info if debug_mode == 1 */
97 unsigned debug_mode;
98
99 /* 0 is quiet, printing only errors */
101
102 /* max cpus; 0 for automatic */
103 unsigned max_cpus;
104
108
109 /* conversion to units */
111
112 /* default name for nameless objects */
113 const char *default_name;
114
115 /* number of elements in object_names
116 * if 0, convert all top-level objects */
118
119 /* objects to convert */
120 const char * const *object_names;
121
122 /* Apply color randomization */
124};
125
126
127/**
128 * Assign default option values.
129 */
130GCV_EXPORT void
131gcv_opts_default(struct gcv_opts *gcv_options);
132
133
134/**
135 * Input/Output/Translation filter.
136 */
138 /* name allowing unique identification by users */
139 const char * const name;
140
141 /* operation type */
143
144 /* If we have a specific model type this converter is known to
145 * handle, call it out here. Use BU_MIME_MODEL_UNKNOWN if
146 * 'filter_type' is GCV_FILTER_FILTER or if the plugin is a
147 * multi-format I/O plugin.
148 *
149 * FIXME: input/output plugins conceivably could be something
150 * other than geometry (e.g., png input or csv output).
151 */
152 const bu_mime_model_t mime_type;
153
154 /* For plugins supporting multiple file types, call this to
155 * process them.
156 *
157 * Return 1 if the input data can be processed by this filter.
158 * (for example: is the file readable by this plugin? Return
159 * 1 if yes, 0 if no. Later we should incorporate some notion
160 * of quality of support into this return value...) */
161 int (* const data_supported)(const char *data);
162
163 /**
164 * PRIVATE
165 *
166 * Allocate and initialize a bu_opt_desc block and associated memory for
167 * storing the option data.
168 *
169 * Must set *options_desc and *options_data.
170 *
171 * May be NULL.
172 */
173 void (* const create_opts_fn)(struct bu_opt_desc **options_desc, void **options_data);
174
175 /**
176 * PRIVATE
177 *
178 * Free the filter-specific opaque pointer returned by create_opts_fn().
179 * NULL if and only if 'create_opts_fn' is NULL.
180 */
181 void (* const free_opts_fn)(void *options_data);
182
183 /*
184 * PRIVATE
185 *
186 * Perform the filter operation.
187 *
188 * For filters of type GCV_FILTER_WRITE, context->dbip is marked read-only
189 * (the pointer is to a non-const struct db_i due to in-memory data that
190 * may be modified). Filters of type GCV_FILTER_FILTER receive a NULL target.
191 * For other filters, 'target' is the input or output file path.
192 *
193 * 'gcv_options' will always be a pointer to a valid struct gcv_opts.
194 * 'options_data' is NULL if and only if 'create_opts_fn' is NULL.
195 */
196 int (* const filter_fn)(struct gcv_context *context, const struct gcv_opts *gcv_options, const void *options_data, const char *target);
197
198};
199
200
202 const struct gcv_filter * const * const filters;
203};
204
205
206/*
207 * Return a pointer to a bu_ptbl listing all registered filters as
208 * const struct gcv_filter pointers.
209 */
210GCV_EXPORT const struct bu_ptbl *gcv_list_filters(struct gcv_context *context);
211
212/* Returns a pointer to a gcv_filter if it exists within the registered filters
213 * returns NULL if no matching filter can be found
214 */
215 GCV_EXPORT const struct gcv_filter*
216 find_filter(enum gcv_filter_type filter_type, bu_mime_model_t mime_type, const char *data, struct gcv_context *context);
217
218/**
219 * Perform a filtering operation on a gcv_context.
220 *
221 * If 'gcv_options' is NULL, defaults will be used as set by gcv_opts_default().
222 * The parameters 'argc' and 'argv' are used for option processing as specified by
223 * the filter.
224 *
225 * Returns 1 on success and 0 on failure.
226 */
227GCV_EXPORT int
228gcv_execute(struct gcv_context *context, const struct gcv_filter *filter, const struct gcv_opts *gcv_options, size_t argc, const char * const *argv, const char *target);
229
230
231__END_DECLS
232
233#endif /* GCV_API_H */
234
235/*
236 * Local Variables:
237 * tab-width: 8
238 * mode: C
239 * indent-tabs-mode: t
240 * c-file-style: "stroustrup"
241 * End:
242 * ex: shiftwidth=4 tabstop=8
243 */
void gcv_context_init(struct gcv_context *cxt)
gcv_tessellation_algorithm
Definition: api.h:71
@ GCV_TESS_DEFAULT
Definition: api.h:72
@ GCV_TESS_MARCHING_CUBES
Definition: api.h:74
@ GCV_TESS_BOTTESS
Definition: api.h:73
void gcv_opts_default(struct gcv_opts *gcv_options)
void gcv_context_destroy(struct gcv_context *cxt)
gcv_filter_type
Definition: api.h:78
@ GCV_FILTER_WRITE
Definition: api.h:81
@ GCV_FILTER_FILTER
Definition: api.h:79
@ GCV_FILTER_READ
Definition: api.h:80
int gcv_execute(struct gcv_context *context, const struct gcv_filter *filter, const struct gcv_opts *gcv_options, size_t argc, const char *const *argv, const char *target)
const struct gcv_filter * find_filter(enum gcv_filter_type filter_type, bu_mime_model_t mime_type, const char *data, struct gcv_context *context)
const struct bu_ptbl * gcv_list_filters(struct gcv_context *context)
Header file for the BRL-CAD common definitions.
double fastf_t
fastest 64-bit (or larger) floating point type
Definition: vmath.h:330
Definition: tol.h:72
"Option description" structure.
Definition: opt.h:170
Definition: ptbl.h:53
bu_avs_t messages
Definition: api.h:50
struct db_i * dbip
Definition: api.h:49
struct gcv_context_internal * i
Definition: api.h:51
const bu_mime_model_t mime_type
Definition: api.h:152
int(*const data_supported)(const char *data)
Definition: api.h:161
void(*const free_opts_fn)(void *options_data)
Definition: api.h:181
enum gcv_filter_type filter_type
Definition: api.h:142
const char *const name
Definition: api.h:139
void(*const create_opts_fn)(struct bu_opt_desc **options_desc, void **options_data)
Definition: api.h:173
int(*const filter_fn)(struct gcv_context *context, const struct gcv_opts *gcv_options, const void *options_data, const char *target)
Definition: api.h:196
Definition: api.h:89
const char * default_name
Definition: api.h:113
const char *const * object_names
Definition: api.h:120
uint32_t nmg_debug_flag
Definition: api.h:94
unsigned verbosity_level
Definition: api.h:100
enum gcv_tessellation_algorithm tessellation_algorithm
Definition: api.h:107
unsigned max_cpus
Definition: api.h:103
struct bg_tess_tol tessellation_tolerance
Definition: api.h:106
fastf_t scale_factor
Definition: api.h:110
size_t num_objects
Definition: api.h:117
uint32_t rt_debug_flag
Definition: api.h:93
unsigned randomize_colors
Definition: api.h:123
unsigned debug_mode
Definition: api.h:97
struct bn_tol calculational_tolerance
Definition: api.h:105
int bu_debug_flag
Definition: api.h:92
const struct gcv_filter *const *const filters
Definition: api.h:202
fundamental vector, matrix, quaternion math macros