BRL-CAD
Loading...
Searching...
No Matches
boolweave.h
Go to the documentation of this file.
1/* B O O L W E A V E . 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/** @addtogroup rt_boolweave
21 * @brief Boolean weaving of raytracing segments
22 */
23/** @{ */
24/** @file rt/boolweave.h */
25
26#ifndef RT_BOOLWEAVE_H
27#define RT_BOOLWEAVE_H
28
29#include "common.h"
30#include "vmath.h"
31#include "bu/bitv.h"
32#include "bu/ptbl.h"
33#include "rt/application.h"
34#include "rt/seg.h"
35#include "rt/ray_partition.h"
36
38
39/*****************************************************************
40 * *
41 * Internal routines in the RT library. *
42 * These routines are *not* intended for Applications to use. *
43 * The interface to these routines may change significantly *
44 * from release to release of this software. *
45 * *
46 *****************************************************************/
47
48/**
49 * @brief
50 * Weave segs into partitions
51 *
52 * Weave a chain of segments into an existing set of partitions. The
53 * edge of each partition is an inhit or outhit of some solid (seg).
54 *
55 * NOTE: When the final partitions are completed, it is the user's
56 * responsibility to honor the inflip and outflip flags. They can not
57 * be flipped here because an outflip=1 edge and an inflip=0 edge
58 * following it may in fact be the same edge. This could be dealt
59 * with by giving the partition struct a COPY of the inhit and outhit
60 * rather than a pointer, but that's more cycles than the neatness is
61 * worth.
62 *
63 * Inputs -
64 * Pointer to first segment in seg chain.
65 * Pointer to head of circular doubly-linked list of
66 * partitions of the original ray.
67 *
68 * Outputs -
69 * Partitions, queued on doubly-linked list specified.
70 *
71 * Notes -
72 * It is the responsibility of the CALLER to free the seg chain, as
73 * well as the partition list that we return.
74 */
75RT_EXPORT extern void rt_boolweave(struct seg *out_hd,
76 struct seg *in_hd,
77 struct partition *PartHeadp,
78 struct application *ap);
79
80/**
81 * @brief
82 * Eval booleans over partitions
83 *
84 * Consider each partition on the sorted & woven input partition list.
85 * If the partition ends before this box's start, discard it
86 * immediately. If the partition begins beyond this box's end,
87 * return.
88 *
89 * Next, evaluate the boolean expression tree for all regions that
90 * have some presence in the partition.
91 *
92 * If 0 regions result, continue with next partition.
93 *
94 * If 1 region results, a valid hit has occurred, so transfer the
95 * partition from the Input list to the Final list.
96 *
97 * If 2 or more regions claim the partition, then an overlap exists.
98 *
99 * If the overlap handler gives a non-zero return, then the
100 * overlapping partition is kept, with the region ID being the first
101 * one encountered.
102 *
103 * Otherwise, the partition is eliminated from further consideration.
104 *
105 * All partitions in the indicated range of the ray are evaluated.
106 * All partitions which really exist (booleval is true) are appended
107 * to the Final partition list. All partitions on the Final partition
108 * list have completely valid entry and exit information, except for
109 * the last partition's exit information when a_onehit!=0 and a_onehit
110 * is odd.
111 *
112 * The flag a_onehit is interpreted as follows:
113 *
114 * If a_onehit = 0, then the ray is traced to +infinity, and all hit
115 * points in the final partition list are valid.
116 *
117 * If a_onehit != 0, the ray is traced through a_onehit hit points.
118 * (Recall that each partition has 2 hit points, entry and exit).
119 * Thus, if a_onehit is odd, the value of pt_outhit.hit_dist in the
120 * last partition may be incorrect; this should not matter because the
121 * application specifically said it only wanted pt_inhit there. This
122 * is most commonly seen when a_onehit = 1, which is useful for
123 * lighting models. Not having to correctly determine the exit point
124 * can result in a significant savings of computer time.
125 *
126 * If a_onehit is negative, it indicates the number of non-air hits
127 * needed.
128 *
129 * Returns -
130 * 0 If more partitions need to be done
131 * 1 Requested number of hits are available in FinalHdp
132 *
133 * The caller must free whatever is in both partition chains.
134 *
135 * NOTES for code improvements -
136 *
137 * With a_onehit != 0, it is difficult to stop at the 'enddist' value
138 * (or the a_ray_length value), and always get correct results. Need
139 * to take into account some additional factors:
140 *
141 * 1) A region shouldn't be evaluated until all its solids have been
142 * intersected, to prevent the "CERN" problem of out points being
143 * wrong because subtracted solids aren't intersected yet.
144 *
145 * Maybe "all" solids don't have to be intersected, but some strong
146 * statements are needed along these lines.
147 *
148 * A region is definitely ready to be evaluated IF all its solids
149 * have been intersected.
150 *
151 * 2) A partition shouldn't be evaluated until all the regions within
152 * it are ready to be evaluated.
153 */
155 struct partition *FinalHdp,
158 struct bu_ptbl *regionbits,
159 struct application *ap,
160 const struct bu_bitv *solidbits);
161
162/**
163 * Increase the size of re_boolstack to double the previous size.
164 * Depend on bu_realloc() to copy the previous data to the new area
165 * when the size is increased.
166 *
167 * Return the new pointer for what was previously the last element.
168 *
169 * NOTE - this is DEPRECATED as a public facing header. Resource
170 * management is librt's responsibility, and this level of detail
171 * exposure needs to go away.
172 */
174
175
177
178#endif /* RT_BOOLWEAVE_H */
179
180/** @} */
181
182/*
183 * Local Variables:
184 * tab-width: 8
185 * mode: C
186 * indent-tabs-mode: t
187 * c-file-style: "stroustrup"
188 * End:
189 * ex: shiftwidth=4 tabstop=8
190 */
Definition dvec.h:74
Header file for the BRL-CAD common definitions.
#define DEPRECATED
Definition common.h:433
void rt_boolweave(struct seg *out_hd, struct seg *in_hd, struct partition *PartHeadp, struct application *ap)
Weave segs into partitions.
DEPRECATED void rt_bool_growstack(struct resource *res)
int rt_boolfinal(struct partition *InputHdp, struct partition *FinalHdp, fastf_t startdist, fastf_t enddist, struct bu_ptbl *regionbits, struct application *ap, const struct bu_bitv *solidbits)
Eval booleans over partitions.
double fastf_t
fastest 64-bit (or larger) floating point type
Definition vmath.h:333
Definition bitv.h:95
Definition ptbl.h:53
Definition seg.h:59
fundamental vector, matrix, quaternion math macros