BRL-CAD
Loading...
Searching...
No Matches
bot.h
Go to the documentation of this file.
1/* B O T . H
2 * BRL-CAD
3 *
4 * Copyright (c) 1993-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 rt_bot */
21/** @{ */
22/** @file rt/primitives/bot.h */
23
24#ifndef RT_PRIMITIVES_BOT_H
25#define RT_PRIMITIVES_BOT_H
26
27#include "common.h"
28#include "vmath.h"
29#include "bu/ptbl.h"
30#include "bn/tol.h"
31#include "nmg.h"
32#include "rt/geom.h"
33#include "rt/defines.h"
34#include "rt/tol.h"
35#include "rt/view.h"
36#include "rt/soltab.h"
37
39#ifdef USE_OPENCL
40/* largest data members first */
41struct clt_bot_specific {
42 cl_ulong offsets[5]; /* header, bvh, tris, norms. */
44 cl_uchar orientation;
45 cl_uchar flags;
46 cl_uchar pad[2];
47};
48
49struct clt_tri_specific {
50 cl_double v0[3];
51 cl_double v1[3];
52 cl_double v2[3];
54 cl_uchar pad[4];
55};
56#endif
57
58/* Shared between bot and ars at the moment */
60 unsigned char bot_mode;
61 unsigned char bot_orientation;
62 unsigned char bot_flags;
63 size_t bot_ntri;
66 void *bot_facelist; /* head of linked list */
67 void **bot_facearray; /* head of face array */
68 void *tie; /* FIXME: horrible blind cast, points to one in rt_bot_internal */
69
70#ifdef USE_OPENCL
74#endif
75};
76
77
78// this is really close to struct tri_specific in plane.h
79// TODO: see if that ever gets serialized, and if it doesn't
80// then change that to this - memory coherency win
81// sizeof(triangle_s) should be 15/16 * (4/8) bytes
82typedef struct _triangle_s {
83 point_t A;
93struct rt_bot_edit {
94 int bot_verts[3]; /* vertices for the BOT solid */
95};
97/* bot.c */
98RT_EXPORT extern size_t rt_bot_get_edge_list(const struct rt_bot_internal *bot,
99 size_t **edge_list);
100RT_EXPORT extern int rt_bot_edge_in_list(const size_t v1,
101 const size_t v2,
102 const size_t edge_list[],
103 const size_t edge_count0);
104RT_EXPORT extern int rt_bot_plot(struct bu_list *vhead,
105 struct rt_db_internal *ip,
106 const struct bg_tess_tol *ttol,
107 const struct bn_tol *tol,
108 const struct bview *info);
109RT_EXPORT extern int rt_bot_plot_poly(struct bu_list *vhead,
110 struct rt_db_internal *ip,
111 const struct bg_tess_tol *ttol,
112 const struct bn_tol *tol);
113RT_EXPORT extern int rt_bot_find_v_nearest_pt2(const struct rt_bot_internal *bot,
114 const point_t pt2,
115 const mat_t mat);
116RT_EXPORT extern int rt_bot_find_e_nearest_pt2(int *vert1, int *vert2, const struct rt_bot_internal *bot, const point_t pt2, const mat_t mat);
118 const char *property);
120 const struct bn_tol *tol);
122RT_EXPORT extern int rt_bot_condense(struct rt_bot_internal *bot);
124 const char *bot_name,
125 struct db_i *dbip,
127RT_EXPORT extern int rt_bot_flip(struct rt_bot_internal *bot);
128RT_EXPORT extern int rt_bot_sync(struct rt_bot_internal *bot);
130/**
131 * Build a compact BOT from replacement faces whose vertex indices reference
132 * the source BOT. face_sources maps every replacement face to its original
133 * source face, allowing thickness, face mode, normals, and texture UVs to be
134 * preserved. Replacement triangles must retain the corner ordering of their
135 * source faces; face_sources identifies faces but does not describe a separate
136 * corner permutation. The caller owns the returned BOT.
137 *
138 * Returns NULL for malformed input or an invalid vertex or face reference.
139 */
140RT_EXPORT extern struct rt_bot_internal *rt_bot_gc(
141 const struct rt_bot_internal *bot, const int *faces,
142 const int *face_sources, size_t face_count);
143
144/**
145 * Build a compact BOT from selected input faces. face_indices identifies the
146 * original faces, in output order, so all per-face and per-corner data can be
147 * preserved and remapped along with the referenced vertices. This is the
148 * convenience form of rt_bot_gc for unchanged source faces. The caller owns
149 * the returned BOT.
150 *
151 * Returns NULL for malformed input or an invalid face reference.
152 */
154 const struct rt_bot_internal *bot, const int *face_indices,
155 size_t face_count);
156
157/**
158 * Split a BOT into edge-connected triangle components. A connected BOT
159 * returns an allocated empty list. On success with multiple components, each
160 * list entry owns a compact BOT preserving all source face-indexed data.
161 * Returns NULL on malformed input or another processing failure.
162 */
163RT_EXPORT extern struct rt_bot_list * rt_bot_split(struct rt_bot_internal *bot);
166/** Free a BOT list. If fbflag is non-zero, also free each contained BOT. */
168 int fbflag);
171
172RT_EXPORT extern int rt_bot_same_orientation(const int *a,
173 const int *b);
175RT_EXPORT extern int rt_bot_tess(struct nmgregion **r,
176 struct model *m,
178 const struct bg_tess_tol *ttol,
179 const struct bn_tol *tol);
180
181RT_EXPORT extern struct rt_bot_internal * rt_bot_merge(size_t num_bots, const struct rt_bot_internal * const *bots);
182
184/* defined in bot.c */
185/* TODO - these global variables need to be rolled in to the rt_i structure */
186RT_EXPORT extern int rt_bot_sort_faces(struct rt_bot_internal *bot,
187 size_t tris_per_piece);
188RT_EXPORT extern int rt_bot_decimate(struct rt_bot_internal *bot,
191 fastf_t min_edge_length);
192
193
194/* Decimate the input Bot using feature_size to determine the target scale of
195 * geometric detail that is preserved in the output mesh.
196 *
197 * Geometrically, it represents the smallest meaningful feature or minimum
198 * detail size that should be retained. During decimation, edges, vertices, and
199 * triangles representing features smaller than feature_size are candidates for
200 * removal or simplification, while larger features are preserved. Thus,
201 * increasing feature_size produces a coarser mesh with fewer, larger
202 * triangles, removing fine details; decreasing it retains more of the original
203 * geometry and fine features. In essence, feature_size acts as a filter for
204 * the geometric fidelity of the simplified mesh.
205 *
206 * feature_size is transformed internally into a collapse cost threshold, so
207 * it does not directly specify the output triangle size. As a safety
208 * postcondition, every referenced output vertex is nevertheless required to
209 * lie within feature_size of the original surface. A candidate that violates
210 * that limit is rejected and the input BOT is left unchanged. The detailed
211 * output topology remains an implementation detail, so calling codes may see
212 * different meshes between library versions for the same feature_size.
213 * Face provenance is retained through the operation so plate thickness, face
214 * mode, normals, and texture UVs remain associated with their source faces.
215 */
216RT_EXPORT extern size_t rt_bot_decimate_gct(struct rt_bot_internal *bot, fastf_t feature_size);
217
218/* Function to convert plate mode BoT to volumetric BoT */
220
221
223/* Container to hold various settings we may need to control the bot repair
224 * process. May also be updated in the future to contain diagnostic info
225 * to report back to the caller - this struct is expected to change in
226 * response to the evolving setting needs of the repair process as various
227 * algorithms are explored.
228 */
229struct rt_bot_repair_info {
234 // Info about generated output
238 unsigned int output_data_loss;
241#define RT_BOT_REPAIR_LOST_NORMALS 0x01
242#define RT_BOT_REPAIR_LOST_UVS 0x02
243
244/* For now the default upper hole size limit will be 5 percent of the mesh
245 * area, but calling codes should not rely on that value to remain consistent
246 * between versions.
247 *
248 * By default, don't return a mesh that can't pass the lint solid raytracing
249 * tests. This isn't always desirable - sometimes manifold is enough even if
250 * the mesh is not otherwise well behaved - so it is an user settable param.
251 */
252#define RT_BOT_REPAIR_INFO_INIT {0.0, 5.0, 1, 0, 0, 0.0, 0};
253
254/* Function to attempt repairing a non-manifold BoT. Returns 1 if ibot was
255 * already manifold (obot will contain NULL), 0 if a manifold BoT was created
256 * (*obot will be the new manifold BoT) and -1 for other cases to indicate
257 * error. Only RT_BOT_SOLID inputs are accepted. Merge-only repairs preserve
258 * source normals and texture UVs. Repairs that create or alter faces cannot
259 * in general map that data to the result; output_data_loss reports which data
260 * was cleared in those cases.
261 */
262RT_EXPORT extern int rt_bot_repair(struct rt_bot_internal **obot, struct rt_bot_internal *ibot, struct rt_bot_repair_info *i);
263
264/* Test whether a bot is "inside-out". This function is aware of
265 * CCW vs CW BoT orientation settings, and will interpret the
266 * results of the test accordingly. The idea is for this function
267 * to return "1" in the same situations that would result in an
268 * OpenGL shaded drawing of the BoT showing black faces due to
269 * incorrect orientation. */
270RT_EXPORT extern int rt_bot_inside_out(struct rt_bot_internal *bot);
271
272/* Test whether a solid BoT has faces that are <tol distance away when shooting
273 * "into" the solid. This is (at the moment) a ray interrogation based test,
274 * so it is not absolutely guaranteed to find all near self-intersections.
275 *
276 * It is intended to catch situations such as boolean operations on meshes
277 * producing exceedingly thin volumes.
278 *
279 * Returns 1 if a problem is found, else 0. If ofaces is non-NULL, store the
280 * indices of the specific faces found to be problematic. */
281RT_EXPORT extern int rt_bot_thin_check(struct bu_ptbl *ofaces, struct rt_bot_internal *bot, struct rt_i *rtip, fastf_t tol, int verbose);
282
283/* Test whether a solid BoT has faces that produce raytrace segments with
284 * thickness in the range [VUNITIZE_TOL, BN_TOL_DIST). Such segments are
285 * returned by the BoT raytracer but would be discarded by the CSG boolweave
286 * tolerance filter, indicating a potential divergence between the BoT and
287 * the original CSG description (the CSG raytracer would report MISS while
288 * the BoT solid reports HIT).
289 *
290 * The typical cause is a subtractor primitive that protrudes just a sub-
291 * tolerance distance past a base face, creating a phantom thin cap in the
292 * facetized mesh that is too thin to survive the CSG boolweave.
293 *
294 * Faces already flagged by rt_bot_thin_check (segment thickness < VUNITIZE_TOL,
295 * i.e. true mesh degeneracies) are in a disjoint thickness range and are not
296 * reported here.
297 *
298 * Returns 1 if a problem is found, else 0. If ofaces is non-NULL, store the
299 * indices of the specific faces found to be problematic. */
300RT_EXPORT extern int rt_bot_csg_miss_check(struct bu_ptbl *ofaces, struct rt_bot_internal *bot, struct rt_i *rtip, int verbose);
301
302/* Function to remove a set of faces from a BoT and produce a new BoT */
305
306/* Function to copy an rt_bot_internal structure */
308rt_bot_dup(const struct rt_bot_internal *bot);
309
310/** @} */
313
314#endif /* RT_PRIMITIVES_BOT_H */
315
316/*
317 * Local Variables:
318 * tab-width: 8
319 * mode: C
320 * indent-tabs-mode: t
321 * c-file-style: "stroustrup"
322 * End:
323 * ex: shiftwidth=4 tabstop=8
324 */
Definition dvec.h:74
Header file for the BRL-CAD common definitions.
int rt_bot_csg_miss_check(struct bu_ptbl *ofaces, struct rt_bot_internal *bot, struct rt_i *rtip, int verbose)
int rt_bot_plate_to_vol(struct rt_bot_internal **obot, struct rt_bot_internal *bot, int round_outer_edges, int quiet_mode, fastf_t max_area_delta, fastf_t min_tri_threshold)
int rt_bot_sync(struct rt_bot_internal *bot)
int rt_bot_repair(struct rt_bot_internal **obot, struct rt_bot_internal *ibot, struct rt_bot_repair_info *i)
struct rt_bot_internal * rt_bot_gc(const struct rt_bot_internal *bot, const int *faces, const int *face_sources, size_t face_count)
fastf_t rt_bot_propget(struct rt_bot_internal *bot, const char *property)
int rt_bot_edge_in_list(const size_t v1, const size_t v2, const size_t edge_list[], const size_t edge_count0)
int rt_bot_decimate(struct rt_bot_internal *bot, fastf_t max_chord_error, fastf_t max_normal_error, fastf_t min_edge_length)
size_t rt_bot_get_edge_list(const struct rt_bot_internal *bot, size_t **edge_list)
int rt_bot_tess(struct nmgregion **r, struct model *m, struct rt_db_internal *ip, const struct bg_tess_tol *ttol, const struct bn_tol *tol)
todo see if that ever gets and if it doesn t struct _triangle_s triangle_s
int rt_bot_sort_faces(struct rt_bot_internal *bot, size_t tris_per_piece)
struct rt_bot_internal * rt_bot_remove_faces(struct bu_ptbl *rm_face_indices, const struct rt_bot_internal *obot)
int rt_bot_smooth(struct rt_bot_internal *bot, const char *bot_name, struct db_i *dbip, fastf_t normal_tolerance_angle)
int rt_bot_condense(struct rt_bot_internal *bot)
struct rt_bot_internal * rt_bot_merge(size_t num_bots, const struct rt_bot_internal *const *bots)
int rt_bot_flip(struct rt_bot_internal *bot)
int rt_bot_plot(struct bu_list *vhead, struct rt_db_internal *ip, const struct bg_tess_tol *ttol, const struct bn_tol *tol, const struct bview *info)
int rt_bot_inside_out(struct rt_bot_internal *bot)
int rt_bot_find_e_nearest_pt2(int *vert1, int *vert2, const struct rt_bot_internal *bot, const point_t pt2, const mat_t mat)
struct rt_bot_internal * rt_bot_subset(const struct rt_bot_internal *bot, const int *face_indices, size_t face_count)
void rt_bot_internal_free(struct rt_bot_internal *bot)
void rt_bot_list_free(struct rt_bot_list *headRblp, int fbflag)
int rt_bot_thin_check(struct bu_ptbl *ofaces, struct rt_bot_internal *bot, struct rt_i *rtip, fastf_t tol, int verbose)
struct rt_bot_list * rt_bot_split(struct rt_bot_internal *bot)
int rt_bot_vertex_fuse(struct rt_bot_internal *bot, const struct bn_tol *tol)
int rt_bot_face_fuse(struct rt_bot_internal *bot)
struct rt_bot_internal * rt_bot_dup(const struct rt_bot_internal *bot)
int rt_bot_same_orientation(const int *a, const int *b)
struct rt_bot_list * rt_bot_patches(struct rt_bot_internal *bot)
int rt_bot_plot_poly(struct bu_list *vhead, struct rt_db_internal *ip, const struct bg_tess_tol *ttol, const struct bn_tol *tol)
int rt_bot_find_v_nearest_pt2(const struct rt_bot_internal *bot, const point_t pt2, const mat_t mat)
size_t rt_bot_decimate_gct(struct rt_bot_internal *bot, fastf_t feature_size)
todo see if that ever gets serialized
Definition bot.h:81
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 point_t[ELEMENTS_PER_POINT]
3-tuple point
Definition vmath.h:357
vect_t face_norm
Definition bot.h:88
fastf_t * norms
Definition bot.h:90
point_t A
Definition bot.h:85
size_t face_id
Definition bot.h:91
vect_t AC
Definition bot.h:87
fastf_t face_norm_scalar
Definition bot.h:89
vect_t AB
Definition bot.h:86
Definition tol.h:72
fastf_t * bot_thickness
Definition bot.h:64
unsigned char bot_flags
Definition bot.h:62
void * bot_facelist
Definition bot.h:66
void * tie
Definition bot.h:68
unsigned char bot_orientation
Definition bot.h:61
size_t bot_ntri
Definition bot.h:63
unsigned char bot_mode
Definition bot.h:60
void ** bot_facearray
Definition bot.h:67
struct bu_bitv * bot_facemode
Definition bot.h:65
Definition bitv.h:95
Definition ptbl.h:53
NMG topological model.
Definition topology.h:289
NMG topological region.
Definition topology.h:277
int bot_verts[3]
Definition bot.h:96
int * faces
array of ints for faces [num_faces*3]
Definition geom.h:801
struct rt_bot_internal * bot
Definition geom.h:858
fastf_t max_hole_area_percent
Definition bot.h:234
int output_nonmanifold
Definition bot.h:238
unsigned int output_data_loss
Definition bot.h:241
fastf_t output_volume
Definition bot.h:240
fastf_t max_hole_area
Definition bot.h:233
int output_lint_fail
Definition bot.h:239
fundamental vector, matrix, quaternion math macros