BRL-CAD
space_partition.h
Go to the documentation of this file.
1/* S P A C E _ P A R T I T I O N . H
2 * BRL-CAD
3 *
4 * Copyright (c) 1993-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/** @file space_partition.h
21 *
22 */
23
24#ifndef RT_SPACE_PARTITION_H
25#define RT_SPACE_PARTITION_H
26
27#include "common.h"
28#include "vmath.h"
29#include "bn/tol.h"
30#include "rt/defines.h"
31#include "rt/soltab.h"
32
33__BEGIN_DECLS
34
35struct rt_piecelist; /* forward declaration */
36
37/**
38 * Structures for space subdivision.
39 *
40 * cut_type is an integer for efficiency of access in rt_shootray() on
41 * non-word addressing machines.
42 *
43 * If a solid has 'pieces', it will be listed either in bn_list
44 * (initially), or in bn_piecelist, but not both.
45 */
46struct cutnode {
48 int cn_axis; /**< @brief 0, 1, 2 = cut along X, Y, Z */
49 fastf_t cn_point; /**< @brief cut through axis==point */
50 union cutter * cn_l; /**< @brief val < point */
51 union cutter * cn_r; /**< @brief val >= point */
52};
53
54struct boxnode {
58 struct soltab **bn_list; /**< @brief bn_list[bn_len] */
59 size_t bn_len; /**< @brief # of solids in list */
60 size_t bn_maxlen; /**< @brief # of ptrs allocated to list */
61 struct rt_piecelist *bn_piecelist; /**< @brief [] solids with pieces */
62 size_t bn_piecelen; /**< @brief # of piecelists used */
63 size_t bn_maxpiecelen; /**< @brief # of piecelists allocated */
64};
65
66
67#define CUT_CUTNODE 1
68#define CUT_BOXNODE 2
69#define CUT_MAXIMUM 2
70union cutter {
72 union cutter *cut_forw; /**< @brief Freelist forward link */
73 struct cutnode cn;
74 struct boxnode bn;
75};
76
77
78#define CUTTER_NULL ((union cutter *)0)
79
80/**
81 * Print out a cut tree.
82 *
83 * lvl is recursion level.
84 */
85RT_EXPORT extern void rt_pr_cut(const union cutter *cutp,
86 int lvl);
87
88struct rt_i; /*forward declaration */
89struct resource; /*forward declaration */
90struct soltab; /*forward declaration */
91RT_EXPORT extern void rt_pr_cut_info(const struct rt_i *rtip,
92 const char *str);
93RT_EXPORT extern void remove_from_bsp(struct soltab *stp,
94 union cutter *cutp,
95 struct bn_tol *tol);
96RT_EXPORT extern void insert_in_bsp(struct soltab *stp,
97 union cutter *cutp);
98RT_EXPORT extern void fill_out_bsp(struct rt_i *rtip,
99 union cutter *cutp,
100 struct resource *resp,
101 fastf_t bb[6]);
102
103struct bvh_build_node; /*forward declaration */
104RT_EXPORT extern struct bvh_build_node *
105hlbvh_create(long max_prims_in_node, struct bu_pool *pool, const fastf_t *centroids_prims,
106 const fastf_t *bounds_prims, long *total_nodes,
107 const long n_primitives, long **ordered_prims);
108
109
110/**
111 * Add a solid into a given boxnode, extending the lists there. This
112 * is used only for building the root node, which will then be
113 * subdivided.
114 *
115 * Solids with pieces go onto a special list.
116 */
117RT_EXPORT extern void rt_cut_extend(union cutter *cutp,
118 struct soltab *stp,
119 const struct rt_i *rtip);
120
121/**
122 * Return pointer to cell 'n' along a given ray. Used for debugging
123 * of how space partitioning interacts with shootray. Intended to
124 * mirror the operation of rt_shootray(). The first cell is 0.
125 */
126RT_EXPORT extern const union cutter *rt_cell_n_on_ray(struct application *ap,
127 int n);
128/*
129 * The rtip->rti_CutFree list can not be freed directly because is
130 * bulk allocated. Fortunately, we have a list of all the
131 * bu_malloc()'ed blocks. This routine may be called before the first
132 * frame is done, so it must be prepared for uninitialized items.
133 */
134RT_EXPORT extern void rt_cut_clean(struct rt_i *rtip);
135
136
137#ifdef USE_OPENCL
138struct clt_bvh_bounds {
139 cl_double p_min[3], p_max[3];
140};
141
142struct clt_linear_bvh_node {
143 struct clt_bvh_bounds bounds;
144 union {
145 cl_int primitives_offset; /* leaf */
146 cl_int second_child_offset; /* interior */
147 } u;
148 cl_ushort n_primitives; /* 0 -> interior node */
149 cl_uchar axis; /* interior node: xyz */
150 cl_uchar pad[1]; /* ensure 32 byte total size */
151};
152
153
154RT_EXPORT extern void
155clt_linear_bvh_create(long n_primitives, struct clt_linear_bvh_node **nodes_p,
156 long **ordered_prims, const fastf_t *centroids_prims,
157 const fastf_t *bounds_prims, cl_int *total_nodes);
158#endif
159
160
161__END_DECLS
162
163#endif /* RT_SPACE_PARTITION_H */
164
165/*
166 * Local Variables:
167 * tab-width: 8
168 * mode: C
169 * indent-tabs-mode: t
170 * c-file-style: "stroustrup"
171 * End:
172 * ex: shiftwidth=4 tabstop=8
173 */
Header file for the BRL-CAD common definitions.
void float float int * n
Definition: tig.h:74
double fastf_t
fastest 64-bit (or larger) floating point type
Definition: vmath.h:330
void rt_cut_clean(struct rt_i *rtip)
struct bvh_build_node * hlbvh_create(long max_prims_in_node, struct bu_pool *pool, const fastf_t *centroids_prims, const fastf_t *bounds_prims, long *total_nodes, const long n_primitives, long **ordered_prims)
void rt_pr_cut_info(const struct rt_i *rtip, const char *str)
void rt_cut_extend(union cutter *cutp, struct soltab *stp, const struct rt_i *rtip)
const union cutter * rt_cell_n_on_ray(struct application *ap, int n)
void rt_pr_cut(const union cutter *cutp, int lvl)
void insert_in_bsp(struct soltab *stp, union cutter *cutp)
void remove_from_bsp(struct soltab *stp, union cutter *cutp, struct bn_tol *tol)
void fill_out_bsp(struct rt_i *rtip, union cutter *cutp, struct resource *resp, fastf_t bb[6])
Definition: tol.h:72
struct rt_piecelist * bn_piecelist
[] solids with pieces
fastf_t bn_max[3]
struct soltab ** bn_list
bn_list[bn_len]
fastf_t bn_min[3]
size_t bn_len
# of solids in list
size_t bn_maxpiecelen
# of piecelists allocated
size_t bn_maxlen
# of ptrs allocated to list
size_t bn_piecelen
# of piecelists used
fastf_t cn_point
cut through axis==point
int cn_axis
0, 1, 2 = cut along X, Y, Z
union cutter * cn_r
val >= point
union cutter * cn_l
val < point
Definition: soltab.h:56
int cut_type
union cutter * cut_forw
Freelist forward link.
struct boxnode bn
struct cutnode cn
fundamental vector, matrix, quaternion math macros