LSST Applications 27.0.0,g0265f82a02+469cd937ee,g02d81e74bb+21ad69e7e1,g1470d8bcf6+cbe83ee85a,g2079a07aa2+e67c6346a6,g212a7c68fe+04a9158687,g2305ad1205+94392ce272,g295015adf3+81dd352a9d,g2bbee38e9b+469cd937ee,g337abbeb29+469cd937ee,g3939d97d7f+72a9f7b576,g487adcacf7+71499e7cba,g50ff169b8f+5929b3527e,g52b1c1532d+a6fc98d2e7,g591dd9f2cf+df404f777f,g5a732f18d5+be83d3ecdb,g64a986408d+21ad69e7e1,g858d7b2824+21ad69e7e1,g8a8a8dda67+a6fc98d2e7,g99cad8db69+f62e5b0af5,g9ddcbc5298+d4bad12328,ga1e77700b3+9c366c4306,ga8c6da7877+71e4819109,gb0e22166c9+25ba2f69a1,gb6a65358fc+469cd937ee,gbb8dafda3b+69d3c0e320,gc07e1c2157+a98bf949bb,gc120e1dc64+615ec43309,gc28159a63d+469cd937ee,gcf0d15dbbd+72a9f7b576,gdaeeff99f8+a38ce5ea23,ge6526c86ff+3a7c1ac5f1,ge79ae78c31+469cd937ee,gee10cc3b42+a6fc98d2e7,gf1cff7945b+21ad69e7e1,gfbcc870c63+9a11dc8c8f
LSST Data Management Base Package
Loading...
Searching...
No Matches
Box3d.h
Go to the documentation of this file.
1/*
2 * This file is part of sphgeom.
3 *
4 * Developed for the LSST Data Management System.
5 * This product includes software developed by the LSST Project
6 * (http://www.lsst.org).
7 * See the COPYRIGHT file at the top-level directory of this distribution
8 * for details of code ownership.
9 *
10 * This software is dual licensed under the GNU General Public License and also
11 * under a 3-clause BSD license. Recipients may choose which of these licenses
12 * to use; please see the files gpl-3.0.txt and/or bsd_license.txt,
13 * respectively. If you choose the GPL option then the following text applies
14 * (but note that there is still no warranty even if you opt for BSD instead):
15 *
16 * This program is free software: you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 */
29
30#ifndef LSST_SPHGEOM_BOX3D_H_
31#define LSST_SPHGEOM_BOX3D_H_
32
36
37#include <iosfwd>
38
39#include "Interval1d.h"
40#include "Relationship.h"
41#include "Vector3d.h"
42
43
44namespace lsst {
45namespace sphgeom {
46
49class Box3d {
50public:
51 // Factory functions
52 static Box3d empty() {
53 return Box3d();
54 }
55
56 static Box3d full() {
57 return Box3d(Interval1d::full(),
60 }
61
64 return Box3d(Interval1d(-1.0, 1.0),
65 Interval1d(-1.0, 1.0),
66 Interval1d(-1.0, 1.0));
67 }
68
70 Box3d() {}
71
73 explicit Box3d(Vector3d const & v)
74 {
75 _intervals[0] = Interval1d(v.x());
76 _intervals[1] = Interval1d(v.y());
77 _intervals[2] = Interval1d(v.z());
78 _enforceInvariants();
79 }
80
83 Box3d(Vector3d const & v1, Vector3d const & v2)
84 {
85 _intervals[0] = Interval1d(v1.x(), v2.x());
86 _intervals[1] = Interval1d(v1.y(), v2.y());
87 _intervals[2] = Interval1d(v1.z(), v2.z());
88 _enforceInvariants();
89 }
90
93 Box3d(Vector3d const & v, double w, double h, double d)
94 {
95 _intervals[0] = Interval1d(v.x()).dilatedBy(w);
96 _intervals[1] = Interval1d(v.y()).dilatedBy(h);
97 _intervals[2] = Interval1d(v.z()).dilatedBy(d);
98 _enforceInvariants();
99 }
100
104 Interval1d const & y,
105 Interval1d const & z)
106 {
107 _intervals[0] = Interval1d(x);
108 _intervals[1] = Interval1d(y);
109 _intervals[2] = Interval1d(z);
110 _enforceInvariants();
111 }
112
114 bool operator==(Box3d const & b) const {
115 return _intervals[0] == b._intervals[0] &&
116 _intervals[1] == b._intervals[1] &&
117 _intervals[2] == b._intervals[2];
118 }
119
120 bool operator!=(Box3d const & b) const { return !(*this == b); }
121
123 bool operator==(Vector3d const & v) const { return *this == Box3d(v); }
124
125 bool operator!=(Vector3d const & v) const { return !(*this == v); }
126
128 Interval1d operator()(int i) const { return _intervals[i]; }
129
130 Interval1d const & x() const { return _intervals[0]; }
131 Interval1d const & y() const { return _intervals[1]; }
132 Interval1d const & z() const { return _intervals[2]; }
133
135 bool isEmpty() const {
136 return x().isEmpty();
137 }
138
140 bool isFull() const {
141 return x().isFull() && y().isFull() && z().isFull();
142 }
143
147 return Vector3d(x().getCenter(), y().getCenter(), z().getCenter());
148 }
149
152 double getWidth() const { return x().getSize(); }
153
156 double getHeight() const { return y().getSize(); }
157
160 double getDepth() const { return z().getSize(); }
161
165 bool contains(Vector3d const & b) const {
166 return x().contains(b.x()) &&
167 y().contains(b.y()) &&
168 z().contains(b.z());
169 }
170
171 bool contains(Box3d const & b) const {
172 return x().contains(b.x()) &&
173 y().contains(b.y()) &&
174 z().contains(b.z());
175 }
176
177 bool contains(double x_, double y_, double z_) const {
178 return x().contains(x_) && y().contains(y_) && z().contains(z_);
179 }
181
185 bool isDisjointFrom(Vector3d const & b) const { return !intersects(b); }
186
187 bool isDisjointFrom(Box3d const & b) const { return !intersects(b); }
189
193 bool intersects(Vector3d const & b) const {
194 return x().intersects(b.x()) &&
195 y().intersects(b.y()) &&
196 z().intersects(b.z());
197 }
198
199 bool intersects(Box3d const & b) const {
200 return x().intersects(b.x()) &&
201 y().intersects(b.y()) &&
202 z().intersects(b.z());
203 }
205
209 bool isWithin(Vector3d const & b) const {
210 return x().isWithin(b.x()) &&
211 y().isWithin(b.y()) &&
212 z().isWithin(b.z());
213 }
214
215 bool isWithin(Box3d const & b) const {
216 return x().isWithin(b.x()) &&
217 y().isWithin(b.y()) &&
218 z().isWithin(b.z());
219 }
221
224 Box3d & clipTo(Vector3d const & b) {
225 _intervals[0].clipTo(b.x());
226 _intervals[1].clipTo(b.y());
227 _intervals[2].clipTo(b.z());
228 _enforceInvariants();
229 return *this;
230 }
231
232 Box3d & clipTo(Box3d const & b) {
233 _intervals[0].clipTo(b.x());
234 _intervals[1].clipTo(b.y());
235 _intervals[2].clipTo(b.z());
236 _enforceInvariants();
237 return *this;
238 }
240
243 Box3d clippedTo(Vector3d const & b) const {
244 return Box3d(*this).clipTo(b);
245 }
246
247 Box3d clippedTo(Box3d const & b) const {
248 return Box3d(*this).clipTo(b);
249 }
251
255 _intervals[0].expandTo(b.x());
256 _intervals[1].expandTo(b.y());
257 _intervals[2].expandTo(b.z());
258 return *this;
259 }
260
261 Box3d & expandTo(Box3d const & b) {
262 _intervals[0].expandTo(b.x());
263 _intervals[1].expandTo(b.y());
264 _intervals[2].expandTo(b.z());
265 return *this;
266 }
268
272 Box3d expandedTo(Vector3d const & b) const {
273 return Box3d(*this).expandTo(b);
274 }
275
276 Box3d expandedTo(Box3d const & b) const {
277 return Box3d(*this).expandTo(b);
278 }
280
287 Box3d & dilateBy(double r) { return dilateBy(r, r, r); }
288 Box3d dilatedBy(double r) const { return Box3d(*this).dilateBy(r); }
289
297 Box3d & dilateBy(double w, double h, double d) {
298 _intervals[0].dilateBy(w);
299 _intervals[1].dilateBy(h);
300 _intervals[2].dilateBy(d);
301 _enforceInvariants();
302 return *this;
303 }
304 Box3d dilatedBy(double w, double h, double d) const {
305 return Box3d(*this).dilateBy(w, h, d);
306 }
307 Box3d & erodeBy(double r) { return dilateBy(-r); }
308 Box3d erodedBy(double r) const { return dilatedBy(-r); }
309 Box3d & erodeBy(double w, double h, double d) {
310 return dilateBy(-w, -h, -d);
311 }
312 Box3d erodedBy(double w, double h, double d) const {
313 return dilatedBy(-w, -h, -d);
314 }
315
316 Relationship relate(Vector3d const & v) const { return relate(Box3d(v)); }
317
318 Relationship relate(Box3d const & b) const {
319 Relationship xr = x().relate(b.x());
320 Relationship yr = y().relate(b.y());
321 Relationship zr = z().relate(b.z());
322 // If the box x, y, or z intervals are disjoint, then so are the
323 // boxes. The other relationships must hold for all constituent
324 // intervals in order to hold for the boxes.
325 return ((xr & yr & zr) & (CONTAINS | WITHIN)) |
326 ((xr | yr | zr) & DISJOINT);
327 }
328
329
330private:
331 void _enforceInvariants() {
332 // Make sure that all intervals are empty, or none are. This
333 // simplifies the implementation of relate and dilateBy.
334 if (x().isEmpty() || y().isEmpty() || z().isEmpty()) {
335 _intervals[0] = Interval1d();
336 _intervals[1] = Interval1d();
337 _intervals[2] = Interval1d();
338 }
339 }
340
341 Interval1d _intervals[3];
342};
343
344std::ostream & operator<<(std::ostream &, Box3d const &);
345
346}} // namespace lsst::sphgeom
347
348#endif // LSST_SPHGEOM_BOX3D_H_
This file defines a class for representing intervals of ℝ.
This file provides a type alias for describing set relationships.
table::Key< int > b
This file declares a class for representing vectors in ℝ³.
Box3d represents a box in ℝ³.
Definition Box3d.h:49
Box3d & erodeBy(double w, double h, double d)
Definition Box3d.h:309
double getHeight() const
getHeight returns the height (y-axis extent) of this box.
Definition Box3d.h:156
bool isEmpty() const
isEmpty returns true if this box does not contain any points.
Definition Box3d.h:135
static Box3d empty()
Definition Box3d.h:52
bool isFull() const
isFull returns true if this box contains all points in ℝ³.
Definition Box3d.h:140
Box3d erodedBy(double w, double h, double d) const
Definition Box3d.h:312
bool intersects(Vector3d const &b) const
Definition Box3d.h:193
Box3d erodedBy(double r) const
Definition Box3d.h:308
double getDepth() const
getDepth returns the depth (z-axis extent) of this box.
Definition Box3d.h:160
bool isDisjointFrom(Box3d const &b) const
Definition Box3d.h:187
bool contains(double x_, double y_, double z_) const
Definition Box3d.h:177
Relationship relate(Box3d const &b) const
Definition Box3d.h:318
bool operator==(Box3d const &b) const
Two 3D boxes are equal if they contain the same points.
Definition Box3d.h:114
Interval1d const & x() const
Definition Box3d.h:130
Box3d(Vector3d const &v1, Vector3d const &v2)
This constructor creates a box spanning the intervals [v1.x(), v2.x()], [v1.y(), v2....
Definition Box3d.h:83
Box3d & dilateBy(double r)
dilateBy minimally expands or shrinks this Box to include or remove all points within distance |r| of...
Definition Box3d.h:287
Box3d & clipTo(Box3d const &b)
Definition Box3d.h:232
Box3d dilatedBy(double w, double h, double d) const
Definition Box3d.h:304
Box3d(Vector3d const &v, double w, double h, double d)
This constructor creates a box with center v, half-width w, half-height h, and half-depth d.
Definition Box3d.h:93
Box3d & expandTo(Box3d const &b)
Definition Box3d.h:261
bool intersects(Box3d const &b) const
Definition Box3d.h:199
Box3d & dilateBy(double w, double h, double d)
dilateBy morphologically dilates or erodes the x, y, and z intervals of this box by w,...
Definition Box3d.h:297
Box3d & expandTo(Vector3d const &b)
Definition Box3d.h:254
Interval1d const & y() const
Definition Box3d.h:131
bool isDisjointFrom(Vector3d const &b) const
Definition Box3d.h:185
Interval1d operator()(int i) const
The function call operator returns the i-th interval of this box.
Definition Box3d.h:128
bool isWithin(Box3d const &b) const
Definition Box3d.h:215
bool isWithin(Vector3d const &b) const
Definition Box3d.h:209
Box3d & clipTo(Vector3d const &b)
Definition Box3d.h:224
Box3d()
This constructor creates an empty 3D box.
Definition Box3d.h:70
Box3d dilatedBy(double r) const
Definition Box3d.h:288
bool contains(Box3d const &b) const
Definition Box3d.h:171
bool operator==(Vector3d const &v) const
A box is equal to a point if it contains only that point.
Definition Box3d.h:123
Box3d clippedTo(Box3d const &b) const
Definition Box3d.h:247
Box3d expandedTo(Vector3d const &b) const
Definition Box3d.h:272
static Box3d full()
Definition Box3d.h:56
Box3d(Vector3d const &v)
This constructor creates a box containing a single point.
Definition Box3d.h:73
double getWidth() const
getWidth returns the width (x-axis extent) of this box.
Definition Box3d.h:152
Box3d & erodeBy(double r)
Definition Box3d.h:307
Box3d clippedTo(Vector3d const &b) const
Definition Box3d.h:243
static Box3d aroundUnitSphere()
aroundUnitSphere returns a minimal Box3d containing the unit sphere.
Definition Box3d.h:63
Vector3d getCenter() const
getCenter returns the center of this box.
Definition Box3d.h:146
Box3d expandedTo(Box3d const &b) const
Definition Box3d.h:276
Interval1d const & z() const
Definition Box3d.h:132
bool operator!=(Vector3d const &v) const
Definition Box3d.h:125
bool operator!=(Box3d const &b) const
Definition Box3d.h:120
bool contains(Vector3d const &b) const
Definition Box3d.h:165
Relationship relate(Vector3d const &v) const
Definition Box3d.h:316
Box3d(Interval1d const &x, Interval1d const &y, Interval1d const &z)
This constructor creates a box spanning the given x, y, and z intervals.
Definition Box3d.h:103
Interval1d represents closed intervals of ℝ.
Definition Interval1d.h:47
bool isFull() const
isFull returns true if this interval = ℝ.
Definition Interval1d.h:70
static Interval1d full()
Definition Interval1d.h:55
bool isWithin(Scalar x) const
Definition Interval.h:147
Derived dilatedBy(Scalar x) const
Definition Interval.h:246
Interval & dilateBy(Scalar x)
For positive x, dilateBy morphologically dilates this interval by [-x,x], which is equivalent to the ...
Definition Interval.h:237
Scalar getSize() const
getSize returns the size (length, width) of this interval.
Definition Interval.h:100
Interval & clipTo(Scalar x)
Definition Interval.h:166
bool isEmpty() const
isEmpty returns true if this interval does not contain any points.
Definition Interval.h:90
Relationship relate(Scalar x) const
Definition Interval.h:256
bool intersects(Scalar x) const
Definition Interval.h:137
Interval & expandTo(Scalar x)
Definition Interval.h:199
bool contains(Scalar x) const
Definition Interval.h:105
Vector3d is a vector in ℝ³ with components stored in double precision.
Definition Vector3d.h:51
double x() const
Definition Vector3d.h:73
double y() const
Definition Vector3d.h:75
double z() const
Definition Vector3d.h:77
std::ostream & operator<<(std::ostream &, Angle const &)
Definition Angle.cc:41
double w
Definition CoaddPsf.cc:69