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-2014 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 /* @file vert_tree.h */
23 /** @addtogroup vtree */
24 /** @{ */
25 
26 /**
27  * @brief
28  * Vertex tree support
29  * Routines to manage a binary search tree of vertices.
30  *
31  * The actual vertices are stored in an array
32  * for convenient use by routines such as "mk_bot".
33  * The binary search tree stores indices into the array.
34  *
35  */
36 
37 #ifndef BN_VERT_TREE_H
38 #define BN_VERT_TREE_H
39 
40 #include "common.h"
41 #include "bn/defines.h"
42 #include "bu/magic.h"
43 
45 
46 /**
47  * packaging structure
48  * holds all the required info for a single vertex tree
49  */
50 struct vert_root {
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 TREE_TYPE_VERTS 1
60 #define TREE_TYPE_VERTS_AND_NORMS 2
61 
62 #define VERT_BLOCK 512 /**< @brief number of vertices to malloc per call when building the array */
63 
64 #define BN_CK_VERT_TREE(_p) BU_CKMAG(_p, VERT_TREE_MAGIC, "vert_tree")
65 
66 
67 /**
68  *@brief
69  * routine to create a vertex tree.
70  *
71  * Possible refinements include specifying an initial size
72  */
73 BN_EXPORT extern struct vert_root *create_vert_tree(void);
74 
75 /**
76  *@brief
77  * routine to create a vertex tree.
78  *
79  * Possible refinements include specifying an initial size
80  */
81 BN_EXPORT extern struct vert_root *create_vert_tree_w_norms(void);
82 
83 /**
84  *@brief
85  * Routine to free a vertex tree and all associated dynamic memory
86  */
87 BN_EXPORT extern void free_vert_tree(struct vert_root *tree_root);
88 
89 /**
90  *@brief
91  * Routine to add a vertex to the current list of part vertices.
92  * The array is re-alloc'd if needed.
93  * Returns index into the array of vertices where this vertex is stored
94  */
95 BN_EXPORT extern int Add_vert(double x,
96  double y,
97  double z,
98  struct vert_root *tree_root,
99  fastf_t local_tol_sq);
100 
101 /**
102  *@brief
103  * Routine to add a vertex and a normal to the current list of part vertices.
104  * The array is re-alloc'd if needed.
105  * Returns index into the array of vertices where this vertex and normal is stored
106  */
107 BN_EXPORT extern int Add_vert_and_norm(double x,
108  double y,
109  double z,
110  double nx,
111  double ny,
112  double nz,
113  struct vert_root *tree_root,
114  fastf_t local_tol_sq);
115 
116 /**
117  *@brief
118  * Routine to free the binary search tree and reset the current number of vertices.
119  * The vertex array is left untouched, for re-use later.
120  */
121 BN_EXPORT extern void clean_vert_tree(struct vert_root *tree_root);
122 
123 
125 
126 #endif /* BN_VERT_TREE_H */
127 /** @} */
128 /*
129  * Local Variables:
130  * mode: C
131  * tab-width: 8
132  * indent-tabs-mode: t
133  * c-file-style: "stroustrup"
134  * End:
135  * ex: shiftwidth=4 tabstop=8
136  */
Header file for the BRL-CAD common definitions.
struct vert_root * create_vert_tree_w_norms(void)
routine to create a vertex tree.
Definition: vert_tree.c:96
union vert_tree * the_tree
the actual vertex tree
Definition: vert_tree.h:53
void free_vert_tree(struct vert_root *tree_root)
Routine to free a vertex tree and all associated dynamic memory.
Definition: vert_tree.c:155
int Add_vert_and_norm(double x, double y, double z, double nx, double ny, double nz, struct vert_root *tree_root, 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...
Definition: vert_tree.c:300
struct vert_root * create_vert_tree(void)
routine to create a vertex tree.
Definition: vert_tree.c:80
int tree_type
vertices or vertices with normals
Definition: vert_tree.h:52
#define __BEGIN_DECLS
Definition: common.h:73
int Add_vert(double x, double y, double z, struct vert_root *tree_root, 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...
Definition: vert_tree.c:181
uint32_t magic
Definition: vert_tree.h:51
size_t max_vert
the current maximum capacity of the array
Definition: vert_tree.h:56
Vertex tree support Routines to manage a binary search tree of vertices.
Definition: vert_tree.h:50
size_t curr_vert
the number of vertices currently in the array
Definition: vert_tree.h:55
void clean_vert_tree(struct vert_root *tree_root)
Routine to free the binary search tree and reset the current number of vertices. The vertex array is ...
Definition: vert_tree.c:128
fastf_t * the_array
the array of vertices
Definition: vert_tree.h:54
#define __END_DECLS
Definition: common.h:74
double fastf_t
Definition: defines.h:300