BRL-CAD
bot.h
Go to the documentation of this file.
1 /* B O T . H
2  * BRL-CAD
3  *
4  * Copyright (c) 1993-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 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 
38 __BEGIN_DECLS
39 #ifdef USE_OPENCL
40 /* largest data members first */
41 struct clt_bot_specific {
42  cl_ulong offsets[5]; /* header, bvh, tris, norms. */
43  cl_uint ntri;
44  cl_uchar orientation;
45  cl_uchar flags;
46  cl_uchar pad[2];
47 };
48 
49 struct clt_tri_specific {
50  cl_double v0[3];
51  cl_double v1[3];
52  cl_double v2[3];
53  cl_int surfno;
54  cl_uchar pad[4];
55 };
56 #endif
57 
58 /* Shared between bot and ars at the moment */
59 struct bot_specific {
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  size_t bot_tri_per_piece; /* log # tri per piece. 1 << bot_ltpp is tri per piece */
69  void *tie; /* FIXME: horrible blind cast, points to one in rt_bot_internal */
70 
71 #ifdef USE_OPENCL
72  struct clt_bot_specific clt_header;
73  struct clt_tri_specific *clt_triangles;
74  cl_double *clt_normals;
75 #endif
76 };
77 
78 
79 // this is really close to struct tri_specific in plane.h
80 // TODO: see if that ever gets serialized, and if it doesn't
81 // then change that to this - memory coherency win
82 // sizeof(triangle_s) should be 15/16 * (4/8) bytes
83 typedef struct _triangle_s {
84  point_t A;
90  size_t face_id;
92 
93 
94 /* bot.c */
95 RT_EXPORT extern size_t rt_bot_get_edge_list(const struct rt_bot_internal *bot,
96  size_t **edge_list);
97 RT_EXPORT extern int rt_bot_edge_in_list(const size_t v1,
98  const size_t v2,
99  const size_t edge_list[],
100  const size_t edge_count0);
101 RT_EXPORT extern int rt_bot_plot(struct bu_list *vhead,
102  struct rt_db_internal *ip,
103  const struct bg_tess_tol *ttol,
104  const struct bn_tol *tol,
105  const struct bview *info);
106 RT_EXPORT extern int rt_bot_plot_poly(struct bu_list *vhead,
107  struct rt_db_internal *ip,
108  const struct bg_tess_tol *ttol,
109  const struct bn_tol *tol);
110 RT_EXPORT extern int rt_bot_find_v_nearest_pt2(const struct rt_bot_internal *bot,
111  const point_t pt2,
112  const mat_t mat);
113 RT_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);
114 RT_EXPORT extern fastf_t rt_bot_propget(struct rt_bot_internal *bot,
115  const char *property);
116 RT_EXPORT extern int rt_bot_vertex_fuse(struct rt_bot_internal *bot,
117  const struct bn_tol *tol);
118 RT_EXPORT extern int rt_bot_face_fuse(struct rt_bot_internal *bot);
119 RT_EXPORT extern int rt_bot_condense(struct rt_bot_internal *bot);
120 RT_EXPORT extern int rt_bot_smooth(struct rt_bot_internal *bot,
121  const char *bot_name,
122  struct db_i *dbip,
123  fastf_t normal_tolerance_angle);
124 RT_EXPORT extern int rt_bot_flip(struct rt_bot_internal *bot);
125 RT_EXPORT extern int rt_bot_sync(struct rt_bot_internal *bot);
126 RT_EXPORT extern struct rt_bot_list * rt_bot_split(struct rt_bot_internal *bot);
127 RT_EXPORT extern struct rt_bot_list * rt_bot_patches(struct rt_bot_internal *bot);
128 RT_EXPORT extern void rt_bot_list_free(struct rt_bot_list *headRblp,
129  int fbflag);
130 
131 RT_EXPORT extern void rt_bot_internal_free(struct rt_bot_internal *bot);
132 
133 RT_EXPORT extern int rt_bot_same_orientation(const int *a,
134  const int *b);
135 
136 RT_EXPORT extern int rt_bot_tess(struct nmgregion **r,
137  struct model *m,
138  struct rt_db_internal *ip,
139  const struct bg_tess_tol *ttol,
140  const struct bn_tol *tol);
141 
142 RT_EXPORT extern struct rt_bot_internal * rt_bot_merge(size_t num_bots, const struct rt_bot_internal * const *bots);
143 
144 
145 /* defined in bot.c */
146 /* TODO - these global variables need to be rolled in to the rt_i structure */
147 RT_EXPORT extern size_t rt_bot_minpieces;
148 RT_EXPORT extern size_t rt_bot_tri_per_piece;
149 RT_EXPORT extern int rt_bot_sort_faces(struct rt_bot_internal *bot,
150  size_t tris_per_piece);
151 RT_EXPORT extern int rt_bot_decimate(struct rt_bot_internal *bot,
152  fastf_t max_chord_error,
153  fastf_t max_normal_error,
154  fastf_t min_edge_length);
155 RT_EXPORT extern size_t rt_bot_decimate_gct(struct rt_bot_internal *bot, fastf_t feature_size);
156 
157 /* Function to convert plate mode BoT to volumetric BoT */
158 RT_EXPORT extern int rt_bot_plate_to_vol(struct rt_bot_internal **obot, struct rt_bot_internal *bot, int round_outer_edges, int quiet_mode);
159 
160 
161 
162 /* Container to hold various settings we may need to control the bot repair
163  * process. May also be updated in the future to contain diagnostic info
164  * to report back to the caller - this struct is expected to change in
165  * response to the evolving setting needs of the repair process as various
166  * algorithms are explored.
167  */
168 struct rt_bot_repair_info {
171 };
172 
173 /* For now the default upper hole size limit will be 5 percent of the mesh
174  * area, but calling codes should not rely on that value to remain consistent
175  * between versions.
176  */
177 #define RT_BOT_REPAIR_INFO_INIT {0.0, 5.0};
178 
179 /* Function to attempt repairing a non-manifold BoT. Returns 1 if ibot was
180  * already manifold (obot will contain NULL), 0 if a manifold BoT was created
181  * (*obot will be the new manifold BoT) and -1 for other cases to indicate
182  * error.
183  */
184 RT_EXPORT extern int rt_bot_repair(struct rt_bot_internal **obot, struct rt_bot_internal *ibot, struct rt_bot_repair_info *i);
185 
186 /* Test whether a bot is "inside-out". This function is aware of
187  * CCW vs CW BoT orientation settings, and will interpret the
188  * results of the test accordingly. The idea is for this function
189  * to return "1" in the same situations that would result in an
190  * OpenGL shaded drawing of the BoT showing black faces due to
191  * incorrect orientation. */
192 RT_EXPORT extern int rt_bot_inside_out(struct rt_bot_internal *bot);
193 
194 /* Test whether a solid BoT has faces that are <tol distance away when shooting
195  * "into" the solid. This is (at the moment) a ray interrogation based test,
196  * so it is not absolutely guaranteed to find all near self-intersections.
197  *
198  * It is intended to catch situations such as boolean operations on meshes
199  * producing exceedingly thin volumes.
200  *
201  * Returns 1 if a problem is found, else 0. If ofaces is non-NULL, store the
202  * indices of the specific faces found to be problematic. */
203 RT_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);
204 
205 /* Function to remove a set of faces from a BoT and produce a new BoT */
206 RT_EXPORT struct rt_bot_internal *
207 rt_bot_remove_faces(struct bu_ptbl *rm_face_indices, const struct rt_bot_internal *obot);
208 
209 /* Function to copy an rt_bot_internal structure */
210 RT_EXPORT struct rt_bot_internal *
211 rt_bot_dup(const struct rt_bot_internal *bot);
212 
213 /** @} */
214 
215 __END_DECLS
216 
217 #endif /* RT_PRIMITIVES_BOT_H */
218 
219 /*
220  * Local Variables:
221  * tab-width: 8
222  * mode: C
223  * indent-tabs-mode: t
224  * c-file-style: "stroustrup"
225  * End:
226  * ex: shiftwidth=4 tabstop=8
227  */
Header file for the BRL-CAD common definitions.
struct rt_bot_internal * rt_bot_merge(size_t num_bots, const struct rt_bot_internal *const *bots)
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)
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)
struct rt_bot_list * rt_bot_split(struct rt_bot_internal *bot)
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_dup(const struct rt_bot_internal *bot)
struct rt_bot_internal * rt_bot_remove_faces(struct bu_ptbl *rm_face_indices, const struct rt_bot_internal *obot)
size_t rt_bot_minpieces
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)
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_plate_to_vol(struct rt_bot_internal **obot, struct rt_bot_internal *bot, int round_outer_edges, int quiet_mode)
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)
void rt_bot_internal_free(struct rt_bot_internal *bot)
void rt_bot_list_free(struct rt_bot_list *headRblp, int fbflag)
struct rt_bot_list * rt_bot_patches(struct rt_bot_internal *bot)
int rt_bot_thin_check(struct bu_ptbl *ofaces, struct rt_bot_internal *bot, struct rt_i *rtip, fastf_t tol, int verbose)
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)
int rt_bot_same_orientation(const int *a, const int *b)
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_tri_per_piece
size_t rt_bot_decimate_gct(struct rt_bot_internal *bot, fastf_t feature_size)
fastf_t vect_t[ELEMENTS_PER_VECT]
3-tuple vector
Definition: vmath.h:349
double fastf_t
fastest 64-bit (or larger) floating point type
Definition: vmath.h:334
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
vect_t face_norm
Definition: bot.h:89
fastf_t * norms
Definition: bot.h:91
point_t A
Definition: bot.h:86
size_t face_id
Definition: bot.h:92
vect_t AC
Definition: bot.h:88
fastf_t face_norm_scalar
Definition: bot.h:90
vect_t AB
Definition: bot.h:87
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:69
unsigned char bot_orientation
Definition: bot.h:61
size_t bot_ntri
Definition: bot.h:63
size_t bot_tri_per_piece
Definition: bot.h:68
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:108
Definition: list.h:132
Definition: ptbl.h:53
Definition: defines.h:489
NMG topological model.
Definition: topology.h:289
NMG topological region.
Definition: topology.h:277
struct rt_bot_internal * bot
Definition: geom.h:843
fastf_t max_hole_area_percent
Definition: bot.h:173
fastf_t max_hole_area
Definition: bot.h:172
fundamental vector, matrix, quaternion math macros