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