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