BRL-CAD
vertex.h
Go to the documentation of this file.
1/* V E R T E X . 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/*----------------------------------------------------------------------*/
22/** @addtogroup nmg_vertex */
23/** @{ */
24/** @file nmg/vertex.h */
25
26#ifndef NMG_VERTEX_H
27#define NMG_VERTEX_H
28
29#include "common.h"
30
31#include "vmath.h"
32#include "bu/list.h"
33#include "nmg/defines.h"
34#include "nmg/topology.h"
35
36__BEGIN_DECLS
37
38#define NMG_CK_VERTEX(_p) NMG_CKMAG(_p, NMG_VERTEX_MAGIC, "vertex")
39#define NMG_CK_VERTEX_G(_p) NMG_CKMAG(_p, NMG_VERTEX_G_MAGIC, "vertex_g")
40#define NMG_CK_VERTEXUSE(_p) NMG_CKMAG(_p, NMG_VERTEXUSE_MAGIC, "vertexuse")
41#define NMG_CK_VERTEXUSE_A_PLANE(_p) NMG_CKMAG(_p, NMG_VERTEXUSE_A_PLANE_MAGIC, "vertexuse_a_plane")
42
43#define GET_VERTEX(p, m) {NMG_GETSTRUCT(p, vertex); NMG_INCR_INDEX(p, m);}
44#define GET_VERTEX_G(p, m) {NMG_GETSTRUCT(p, vertex_g); NMG_INCR_INDEX(p, m);}
45#define GET_VERTEXUSE(p, m) {NMG_GETSTRUCT(p, vertexuse); NMG_INCR_INDEX(p, m);}
46#define GET_VERTEXUSE_A_PLANE(p, m) {NMG_GETSTRUCT(p, vertexuse_a_plane); NMG_INCR_INDEX(p, m);}
47#define GET_VERTEXUSE_A_CNURB(p, m) {NMG_GETSTRUCT(p, vertexuse_a_cnurb); NMG_INCR_INDEX(p, m);}
48#define FREE_VERTEX(p) NMG_FREESTRUCT(p, vertex)
49#define FREE_VERTEX_G(p) NMG_FREESTRUCT(p, vertex_g)
50#define FREE_VERTEXUSE(p) NMG_FREESTRUCT(p, vertexuse)
51#define FREE_VERTEXUSE_A_PLANE(p) NMG_FREESTRUCT(p, vertexuse_a_plane)
52#define FREE_VERTEXUSE_A_CNURB(p) NMG_FREESTRUCT(p, vertexuse_a_cnurb)
53
54/**
55 * @brief Given a vertex \b v, set the coordinates of the vertex
56 * geometry associated with \b v to \b pt
57 *
58 * If a vertex has no associated vertex_g structure, one is created,
59 * associated with v and added to v's parent nmg model.
60 */
61NMG_EXPORT extern void nmg_vertex_gv(struct vertex *v,
62 const point_t pt);
63
64/**
65 * @brief Given a vertex \b v, set the coordinates of the vertex
66 * geometry associated with \b v to (\b x,\b y,\b z)
67 *
68 * Works like nmg_vertex_gv, except it doesn't require the data to be
69 * in a point_t container. (Mostly useful for quick and dirty
70 * programs.)
71 */
72NMG_EXPORT extern void nmg_vertex_g(struct vertex *v,
73 fastf_t x,
74 fastf_t y,
75 fastf_t z);
76/**
77 * @brief Given a vertex use \b vu, associate a normal vector \b norm
78 * with that use
79 *
80 * If the vertexuse does not already have a vertexuse_a_plane
81 * attribute associated with it, this routine will add one.
82 *
83 * Remember that only vertexuse instances may have an associated
84 * normal - because a vertex may be used multiple times in different
85 * faces with different normals, we cannot reliably associate a normal
86 * uniquely with a vertex definition. Only when the vertex is used in
87 * some particular application (i.e. a vertexuse as part of a face)
88 * can we associate a normal.
89 */
90NMG_EXPORT extern void nmg_vertexuse_nv(struct vertexuse *vu,
91 const vect_t norm);
92
93/**
94 * @brief Given a vertex use \b vu, change its vertex association from
95 * it's current vertex to \b v
96 *
97 * This has the effect of "relocating" the vertexuse to the position
98 * associated with \b v.
99 *
100 * If the vertex previously used by \b vu has no more associated
101 * vertexuse structures (i.e. the vertex is no longer referenced by
102 * the NMG model), this routine will free the old vertex structure.
103 */
104NMG_EXPORT extern void nmg_movevu(struct vertexuse *vu,
105 struct vertex *v);
106
107/**
108 * @brief Kill vertexuse \b vu, and null out parent's vu_p.
109 *
110 * This routine is not intended for general use by applications,
111 * because it requires cooperation on the part of the caller to
112 * properly dispose of or fix the now *quite* illegal parent.
113 * (Illegal because the parent's vu_p is NULL). It exists primarily
114 * as a support routine for "mopping up" after nmg_klu(), nmg_keu(),
115 * nmg_ks(), and nmg_mv_vu_between_shells().
116 *
117 * It is also used in a particularly ugly way in nmg_cut_loop() and
118 * nmg_split_lu_at_vu() as part of their method for obtaining an
119 * "empty" loopuse/loop set.
120 *
121 * It is worth noting that all these callers ignore the return code,
122 * because they *all* exist to intentionally empty out the parent, but
123 * the return code is provided anyway, in the name of [CTJ] symmetry.
124 *
125 * @retval 0 If all is well in the parent
126 * @retval 1 If parent is empty, and is thus "illegal"
127 */
128NMG_EXPORT extern int nmg_kvu(struct vertexuse *vu);
129
130/**
131 * @brief Join two vertexes into one.
132 *
133 * \b v1 inherits all the vertexuses presently pointing to \b v2, and
134 * \b v2 is then destroyed.
135 *
136 * Note that this is not a "joining" in the geometric sense; the
137 * position of v1 is not adjusted in any way to make it closer to that
138 * of v2. The merge is strictly topological, and all vertexuses that
139 * referenced v2 will now have a new geometric position, if the x,y,z
140 * coordinates of v1 differed from those of v2.
141 */
142NMG_EXPORT extern void nmg_jv(struct vertex *v1,
143 struct vertex *v2);
144
145/**
146 * @brief Build the set of pointers to all vertex structures in an NMG
147 * model that are "below" the data structure pointed to by magic_p,
148 * where magic_p is a pointer to the magic entry of any NMG data
149 * structure in the model.
150 *
151 * For "raw" geometric structs, the magic entry will be the first
152 * entry in the struct - for example, a loop pointed to by l would
153 * have a magic_p key of &l->magic. For the use structures, the magic
154 * key is found within the leading bu_list - for example, a faceuse
155 * pointed to by *fu would have a magic_p key at &fu->l.magic
156 *
157 * Each vertex pointer will be listed exactly once - i.e. uniqueness
158 * within the table may be assumed.
159 *
160 * This set provides the caller with an easy way to answer the
161 * question "which vertices are used by this part of the model".
162 *
163 * @param[out] tab a bu_ptbl holding struct vertex pointers.
164 *
165 * @param magic_p pointer to an NMG data structure's magic entry.
166 *
167 * @param vlfree list of available vlist segments to be reused by
168 * debug drawing routines.
169 */
170NMG_EXPORT extern void nmg_vertex_tabulate(struct bu_ptbl *tab,
171 const uint32_t *magic_p,
172 struct bu_list *vlfree);
173
174/**
175 * @brief Build the set of pointers to all vertexuse normal structures
176 * in an NMG model that are "below" the data structure pointed to by
177 * magic_p, where magic_p is a pointer to the magic entry of any NMG
178 * data structure in the model.
179 *
180 * The return type for vertexuse normals in the output table is struct
181 * vertexuse_a_plane *
182 *
183 * For "raw" geometric struts, the magic entry will be the first entry
184 * in the struct - for example, a loop pointed to by l would have a
185 * magic_p key of &l->magic. For the use structures, the magic key is
186 * found within the leading bu_list - for example, a faceuse pointed
187 * to by *fu would have a magic_p key at &fu->l.magic
188 *
189 * Each vertexuse_a_plane pointer will be listed exactly once -
190 * i.e. uniqueness within the table may be assumed.
191 *
192 * @param[out] tab a bu_ptbl holding struct vertexuse_plane_a
193 * pointers.
194 *
195 * @param magic_p pointer to an NMG data structure's magic entry.
196 *
197 * @param vlfree list of available vlist segments to be reused by
198 * debug drawing routines.
199 */
200NMG_EXPORT extern void nmg_vertexuse_normal_tabulate(struct bu_ptbl *tab,
201 const uint32_t *magic_p,
202 struct bu_list *vlfree);
203
204/**
205 * @brief Check if the given vertexuse \b vu is in the table given by
206 * \b b or if \b vu references a vertex which is referenced by a
207 * vertexuse in the table
208 *
209 * @retval 1 Match found
210 * @retval 0 No match found
211 */
212NMG_EXPORT extern int nmg_in_or_ref(struct vertexuse *vu,
213 struct bu_ptbl *b);
214
215
216/**
217 * @brief Given a vertex and a list of faces (not more than three)
218 * that should intersect at the vertex, calculate a new location for
219 * the vertex and modify the vertex_g geometry associated with the
220 * vertex to the new location.
221 *
222 * @retval 0 Success
223 * @retval 1 Failure
224 */
225NMG_EXPORT extern int nmg_simple_vertex_solve(struct vertex *new_v,
226 const struct bu_ptbl *faces,
227 const struct bn_tol *tol);
228
229/**
230 * @brief Move vertex so it is at the intersection of the newly
231 * created faces.
232 *
233 * This routine is used by "nmg_extrude_shell" to move vertices. Each
234 * plane has already been moved a distance inward and the surface
235 * normals have been reversed.
236 *
237 * If approximate is non-zero, then the coordinates of the new vertex
238 * may be calculated as the point with minimum distance to all the
239 * faces that intersect at the vertex for vertices where more than
240 * three faces intersect.
241 *
242 * @retval 0 Success
243 * @retval 1 Failure
244 */
245NMG_EXPORT extern int nmg_in_vert(struct vertex *new_v,
246 const int approximate,
247 struct bu_list *vlfree,
248 const struct bn_tol *tol);
249
250/**
251 * @brief Fuse together any vertices that are geometrically identical,
252 * within distance tolerance.
253 *
254 * This function may be passed a pointer to an NMG object's magic
255 * entry or a pointer to a bu_ptbl structure containing a list of
256 * pointers to NMG vertex structures.
257 *
258 * For "raw" geometric struts, the magic entry will be the first entry
259 * in the struct - for example, a loop pointed to by l would have a
260 * magic_p key of &l->magic. For the use structures, the magic key is
261 * found within the leading bu_list - for example, a faceuse pointed
262 * to by *fu would have a magic_p key at &fu->l.magic
263 *
264 * If a pointer to a bu_ptbl structure was passed into this function,
265 * the calling function is responsible for freeing the table.
266 *
267 * @param magic_p pointer to either an NMG data structure's magic
268 * entry or to a bu_ptbl.
269 *
270 * @param vlfree list of available vlist segments to be reused by
271 * debug drawing routines.
272 *
273 * @param tol distance tolerances to use when fusing vertices.
274 */
275NMG_EXPORT extern int nmg_vertex_fuse(const uint32_t *magic_p, struct bu_list *vlfree,
276 const struct bn_tol *tol);
277
278
279__END_DECLS
280
281#endif /* NMG_VERTEX_H */
282/** @} */
283/*
284 * Local Variables:
285 * mode: C
286 * tab-width: 8
287 * indent-tabs-mode: t
288 * c-file-style: "stroustrup"
289 * End:
290 * ex: shiftwidth=4 tabstop=8
291 */
Header file for the BRL-CAD common definitions.
void float float * y
Definition: tig.h:73
void float float float * z
Definition: tig.h:90
void float * x
Definition: tig.h:72
void nmg_vertex_g(struct vertex *v, fastf_t x, fastf_t y, fastf_t z)
Given a vertex v, set the coordinates of the vertex geometry associated with v to (x,...
int nmg_simple_vertex_solve(struct vertex *new_v, const struct bu_ptbl *faces, const struct bn_tol *tol)
Given a vertex and a list of faces (not more than three) that should intersect at the vertex,...
int nmg_in_or_ref(struct vertexuse *vu, struct bu_ptbl *b)
Check if the given vertexuse vu is in the table given by b or if vu references a vertex which is refe...
int nmg_vertex_fuse(const uint32_t *magic_p, struct bu_list *vlfree, const struct bn_tol *tol)
Fuse together any vertices that are geometrically identical, within distance tolerance.
void nmg_vertex_tabulate(struct bu_ptbl *tab, const uint32_t *magic_p, struct bu_list *vlfree)
Build the set of pointers to all vertex structures in an NMG model that are "below" the data structur...
void nmg_movevu(struct vertexuse *vu, struct vertex *v)
Given a vertex use vu, change its vertex association from it's current vertex to v.
void nmg_vertexuse_normal_tabulate(struct bu_ptbl *tab, const uint32_t *magic_p, struct bu_list *vlfree)
Build the set of pointers to all vertexuse normal structures in an NMG model that are "below" the dat...
int nmg_kvu(struct vertexuse *vu)
Kill vertexuse vu, and null out parent's vu_p.
void nmg_jv(struct vertex *v1, struct vertex *v2)
Join two vertexes into one.
int nmg_in_vert(struct vertex *new_v, const int approximate, struct bu_list *vlfree, const struct bn_tol *tol)
Move vertex so it is at the intersection of the newly created faces.
void nmg_vertexuse_nv(struct vertexuse *vu, const vect_t norm)
Given a vertex use vu, associate a normal vector norm with that use.
void nmg_vertex_gv(struct vertex *v, const point_t pt)
Given a vertex v, set the coordinates of the vertex geometry associated with v to pt.
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: list.h:131
Definition: ptbl.h:53
NMG topological vertex - the simplest element of the topology system.
Definition: topology.h:98
NMG topological vertex usage.
Definition: topology.h:109
fundamental vector, matrix, quaternion math macros