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