BRL-CAD
cdt.h
Go to the documentation of this file.
1/* C D T . H
2 * BRL-CAD
3 *
4 * Copyright (c) 2004-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/** @{ */
21/** @file brep/cdt.h */
22/** @addtogroup brep_util
23 *
24 * @brief
25 * Constrained Delaunay Triangulation of brep solids.
26 *
27 */
28
29#ifndef BREP_CDT_H
30#define BREP_CDT_H
31
32#include "common.h"
33
34#include "bv/vlist.h"
35#include "bn/tol.h"
36#include "bg/defines.h"
37#include "brep/defines.h"
38
39__BEGIN_DECLS
40
41/* Container that holds the state of a triangulation */
42struct ON_Brep_CDT_State;
43
44/* Create and initialize a CDT state with default tolerances. bv
45 * must be a pointer to an ON_Brep object. */
46extern BREP_EXPORT struct ON_Brep_CDT_State *
47ON_Brep_CDT_Create(void *bv, const char *objname);
48
49/* Destroy a CDT state */
50extern BREP_EXPORT void
51ON_Brep_CDT_Destroy(struct ON_Brep_CDT_State *s);
52
53extern BREP_EXPORT const char *
54ON_Brep_CDT_ObjName(struct ON_Brep_CDT_State *s);
55
56/* Set/get the CDT tolerances. */
57extern BREP_EXPORT void
58ON_Brep_CDT_Tol_Set(struct ON_Brep_CDT_State *s, const struct bg_tess_tol *t);
59extern BREP_EXPORT void
60ON_Brep_CDT_Tol_Get(struct bg_tess_tol *t, const struct ON_Brep_CDT_State *s);
61
62/* Return the ON_Brep associated with state s. */
63extern BREP_EXPORT void *
64ON_Brep_CDT_Brep(struct ON_Brep_CDT_State *s);
65
66/* Given a state, produce a triangulation. Returns 0 if a solid, valid
67 * triangulation was produced, 1 if a triangulation was produced but it
68 * isn't solid, and -1 if no triangulation could be produced. If faces is
69 * non-null, the triangulation will only attempt to triangulate the
70 * specified face(s) and the return code will be the number of successfully
71 * triangulated faces. If the CDT tolerances have been updated since the
72 * last Tessellate call, the old tessellation information will be replaced. */
73extern BREP_EXPORT int
74ON_Brep_CDT_Tessellate(struct ON_Brep_CDT_State *s, int face_cnt, int *faces);
75
76/* Given a state, report the status of its triangulation. -3 indicates a
77 * failed attempt to tessellate, -2 indicates a non-solid tessellation is
78 * present after an attempt to tessellate all faces, -1 is a state which
79 * has had no tessellation attempt made, 0 indicates a solid, valid full
80 * brep tessellation is present, and >0 indicates that number of faces has
81 * been tessellated but not the full brep. */
82extern BREP_EXPORT int
83ON_Brep_CDT_Status(struct ON_Brep_CDT_State *s);
84
85/* Construct a vlist plot from the tessellation. Modes are:
86 *
87 * 0 - shaded 3D triangles
88 * 1 - 3D triangle wireframe
89 * 2 - 2D triangle wireframe (from parametric space)
90 *
91 * Returns 0 if vlist was successfully generated, else -1
92 */
93extern BREP_EXPORT int
95 struct bv_vlblock *vbp,
96 struct bu_list *vlfree,
97 struct bu_color *c,
98 int mode,
99 struct ON_Brep_CDT_State *s);
100
101/* Given two or more triangulation states, refine them to clear any face
102 * overlaps introduced by the triangulation. If any of the states are
103 * un-tessellated, first perform the tessellation indicated by the state
104 * settings and then proceed to resolve after all states have an initial
105 * tessellation. Returns 0 if no changes were needed, the number of
106 * updated CDT states if changes were made, and -1 if one or more
107 * unresolvable overlaps were encountered. Individual CDT states may
108 * subsequently be queried for other information about their specific
109 * states with other function calls - this function returns only the
110 * overall result. */
111extern BREP_EXPORT int
112ON_Brep_CDT_Ovlp_Resolve(struct ON_Brep_CDT_State **s_a, int s_cnt, double lthreshold, int timeout);
113
114#if 0
115/* Report the number of other tessellation states which manifest unresolvable
116 * overlaps with state s. If the ovlps argument is non-null, populate with
117 * the problematic states. If no resolve step was performed on s, return -1 */
118extern BREP_EXPORT int
119ON_Brep_CDT_UnResolvable_Ovlps(std::vector<struct ON_Brep_CDT_State *> *ovlps, struct ON_Brep_CDT_State *s);
120#endif
121
122/* Retrieve the face, vertex and normal information from a tessellation state
123 * in the form of integer and fastf_t arrays. */
124/* TODO - need to allow optional specification of specific faces here -
125 * have already hit one scenario where I want triangle information from
126 * specific faces. */
127extern BREP_EXPORT int
129 int **faces, int *fcnt,
130 fastf_t **vertices, int *vcnt,
131 int **face_normals, int *fn_cnt,
132 fastf_t **normals, int *ncnt,
133 struct ON_Brep_CDT_State *s,
134 int exp_face_cnt, int *exp_faces
135 );
136
137#ifdef __cplusplus
138/* Original (fast but not watertight) routine used for plotting */
139extern BREP_EXPORT int
140brep_facecdt_plot(struct bu_vls *vls, const char *solid_name,
141 const struct bg_tess_tol *ttol, const struct bn_tol *tol,
142 const ON_Brep *brep, struct bu_list *p_vhead,
143 struct bv_vlblock *vbp, struct bu_list *vlfree,
144 int index, int plottype, int num_points);
145
146/* Routine to capture the triangles from the fast CDT process
147 * for caching */
148extern BREP_EXPORT int
149brep_cdt_fast(int **faces, int *face_cnt, vect_t **pnt_norms, point_t **pnts, int *pntcnt,
150 const ON_Brep *brep, int index, const struct bg_tess_tol *ttol, const struct bn_tol *tol);
151#endif
152
153/* PImpl exposure of some mesh operations for use in tests - not to be considered public API */
154struct cdt_bmesh_impl;
155struct cdt_bmesh {
156 struct cdt_bmesh_impl *i;
157};
158extern BREP_EXPORT int cdt_bmesh_create(struct cdt_bmesh **m);
159extern BREP_EXPORT void cdt_bmesh_destroy(struct cdt_bmesh *m);
160extern BREP_EXPORT int cdt_bmesh_deserialize(const char *fname, struct cdt_bmesh *m);
161extern BREP_EXPORT int cdt_bmesh_repair(struct cdt_bmesh *m);
162
163__END_DECLS
164
165/** @} */
166
167#endif /* BREP_CDT_H */
168
169/*
170 * Local Variables:
171 * tab-width: 8
172 * mode: C
173 * indent-tabs-mode: t
174 * c-file-style: "stroustrup"
175 * End:
176 * ex: shiftwidth=4 tabstop=8
177 */
void ON_Brep_CDT_Destroy(struct ON_Brep_CDT_State *s)
void * ON_Brep_CDT_Brep(struct ON_Brep_CDT_State *s)
int cdt_bmesh_create(struct cdt_bmesh **m)
void cdt_bmesh_destroy(struct cdt_bmesh *m)
int cdt_bmesh_repair(struct cdt_bmesh *m)
int ON_Brep_CDT_Tessellate(struct ON_Brep_CDT_State *s, int face_cnt, int *faces)
int brep_cdt_fast(int **faces, int *face_cnt, vect_t **pnt_norms, point_t **pnts, int *pntcnt, const ON_Brep *brep, int index, const struct bg_tess_tol *ttol, const struct bn_tol *tol)
int ON_Brep_CDT_Status(struct ON_Brep_CDT_State *s)
struct ON_Brep_CDT_State * ON_Brep_CDT_Create(void *bv, const char *objname)
void ON_Brep_CDT_Tol_Get(struct bg_tess_tol *t, const struct ON_Brep_CDT_State *s)
int ON_Brep_CDT_VList(struct bv_vlblock *vbp, struct bu_list *vlfree, struct bu_color *c, int mode, struct ON_Brep_CDT_State *s)
int ON_Brep_CDT_Mesh(int **faces, int *fcnt, fastf_t **vertices, int *vcnt, int **face_normals, int *fn_cnt, fastf_t **normals, int *ncnt, struct ON_Brep_CDT_State *s, int exp_face_cnt, int *exp_faces)
void ON_Brep_CDT_Tol_Set(struct ON_Brep_CDT_State *s, const struct bg_tess_tol *t)
const char * ON_Brep_CDT_ObjName(struct ON_Brep_CDT_State *s)
int cdt_bmesh_deserialize(const char *fname, struct cdt_bmesh *m)
int ON_Brep_CDT_Ovlp_Resolve(struct ON_Brep_CDT_State **s_a, int s_cnt, double lthreshold, int timeout)
int brep_facecdt_plot(struct bu_vls *vls, const char *solid_name, const struct bg_tess_tol *ttol, const struct bn_tol *tol, const ON_Brep *brep, struct bu_list *p_vhead, struct bv_vlblock *vbp, struct bu_list *vlfree, int index, int plottype, int num_points)
Header file for the BRL-CAD common definitions.
void int char * mode
Definition: tig.h:179
void int * c
Definition: tig.h:139
fastf_t vect_t[ELEMENTS_PER_VECT]
3-tuple vector
Definition: vmath.h:345
double fastf_t
fastest 64-bit (or larger) floating point type
Definition: vmath.h:330
fastf_t point_t[ELEMENTS_PER_POINT]
3-tuple point
Definition: vmath.h:351
Definition: tol.h:72
Definition: color.h:54
Definition: list.h:131
Definition: vls.h:53
Definition: cdt.h:155
struct cdt_bmesh_impl * i
Definition: cdt.h:156