BRL-CAD
vert_tree.h
Go to the documentation of this file.
1/* V E R T _ T R E E . 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 bg_vert_tree
23 *
24 * Routines to manage a binary search tree of vertices.
25 *
26 * The actual vertices are stored in an array
27 * for convenient use by routines such as "mk_bot".
28 * The binary search tree stores indices into the array.
29 *
30 */
31/** @{ */
32/** @file vert_tree.h */
33
34#ifndef BN_VERT_TREE_H
35#define BN_VERT_TREE_H
36
37#include "common.h"
38
39#include "vmath.h"
40
41#include "bu/magic.h"
42#include "bg/defines.h"
43
44__BEGIN_DECLS
45
46/**
47 * packaging structure
48 * holds all the required info for a single vertex tree
49 */
51 uint32_t magic;
52 int tree_type; /**< @brief vertices or vertices with normals */
53 union vert_tree *the_tree; /**< @brief the actual vertex tree */
54 fastf_t *the_array; /**< @brief the array of vertices */
55 size_t curr_vert; /**< @brief the number of vertices currently in the array */
56 size_t max_vert; /**< @brief the current maximum capacity of the array */
57};
58
59#define BN_VERT_TREE_TYPE_VERTS 1
60#define BN_VERT_TREE_TYPE_VERTS_AND_NORMS 2
61
62#define BN_CK_VERT_TREE(_p) BU_CKMAG(_p, BN_VERT_TREE_MAGIC, "vert_tree")
63
64
65/**
66 *@brief
67 * routine to create a vertex tree.
68 *
69 * Possible refinements include specifying an initial size
70 */
71BG_EXPORT extern struct bg_vert_tree *bg_vert_tree_create(void);
72
73/**
74 *@brief
75 * routine to create a vertex tree.
76 *
77 * Possible refinements include specifying an initial size
78 */
79BG_EXPORT extern struct bg_vert_tree *bg_vert_tree_create_w_norms(void);
80
81/**
82 *@brief
83 * Routine to free a vertex tree and all associated dynamic memory
84 */
85BG_EXPORT extern void bg_vert_tree_destroy(struct bg_vert_tree *tree);
86
87/**
88 *@brief
89 * Routine to add a vertex to the current list of part vertices.
90 * The array is re-alloc'd if needed.
91 * Returns index into the array of vertices where this vertex is stored
92 */
93BG_EXPORT extern size_t bg_vert_tree_add(struct bg_vert_tree *tree,
94 double x,
95 double y,
96 double z,
97 fastf_t local_tol_sq);
98
99/**
100 *@brief
101 * Routine to add a vertex and a normal to the current list of part vertices.
102 * The array is re-alloc'd if needed.
103 * Returns index into the array of vertices where this vertex and normal is stored
104 */
105BG_EXPORT extern size_t bg_vert_tree_add_w_norm(struct bg_vert_tree *tree,
106 double x,
107 double y,
108 double z,
109 double nx,
110 double ny,
111 double nz,
112 fastf_t local_tol_sq);
113
114/**
115 *@brief
116 * Routine to free the binary search tree and reset the current number of vertices.
117 * The vertex array is left untouched, for re-use later.
118 */
119BG_EXPORT extern void bg_vert_tree_clean(struct bg_vert_tree *tree);
120
121
122__END_DECLS
123
124#endif /* BN_VERT_TREE_H */
125/** @} */
126/*
127 * Local Variables:
128 * mode: C
129 * tab-width: 8
130 * indent-tabs-mode: t
131 * c-file-style: "stroustrup"
132 * End:
133 * ex: shiftwidth=4 tabstop=8
134 */
Header file for the BRL-CAD common definitions.
void bg_vert_tree_destroy(struct bg_vert_tree *tree)
Routine to free a vertex tree and all associated dynamic memory.
struct bg_vert_tree * bg_vert_tree_create_w_norms(void)
routine to create a vertex tree.
size_t bg_vert_tree_add(struct bg_vert_tree *tree, double x, double y, double z, fastf_t local_tol_sq)
Routine to add a vertex to the current list of part vertices. The array is re-alloc'd if needed....
struct bg_vert_tree * bg_vert_tree_create(void)
routine to create a vertex tree.
size_t bg_vert_tree_add_w_norm(struct bg_vert_tree *tree, double x, double y, double z, double nx, double ny, double nz, fastf_t local_tol_sq)
Routine to add a vertex and a normal to the current list of part vertices. The array is re-alloc'd if...
void bg_vert_tree_clean(struct bg_vert_tree *tree)
Routine to free the binary search tree and reset the current number of vertices. The vertex array is ...
void float float * y
Definition: tig.h:73
void float float float * z
Definition: tig.h:90
void float * x
Definition: tig.h:72
double fastf_t
fastest 64-bit (or larger) floating point type
Definition: vmath.h:330
Global registry of recognized magic numbers.
fastf_t * the_array
the array of vertices
Definition: vert_tree.h:54
uint32_t magic
Definition: vert_tree.h:51
int tree_type
vertices or vertices with normals
Definition: vert_tree.h:52
size_t max_vert
the current maximum capacity of the array
Definition: vert_tree.h:56
size_t curr_vert
the number of vertices currently in the array
Definition: vert_tree.h:55
union vert_tree * the_tree
the actual vertex tree
Definition: vert_tree.h:53
Definition: tree.h:147
fundamental vector, matrix, quaternion math macros