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