LSST Applications g0b6bd0c080+a72a5dd7e6,g1182afd7b4+2a019aa3bb,g17e5ecfddb+2b8207f7de,g1d67935e3f+06cf436103,g38293774b4+ac198e9f13,g396055baef+6a2097e274,g3b44f30a73+6611e0205b,g480783c3b1+98f8679e14,g48ccf36440+89c08d0516,g4b93dc025c+98f8679e14,g5c4744a4d9+a302e8c7f0,g613e996a0d+e1c447f2e0,g6c8d09e9e7+25247a063c,g7271f0639c+98f8679e14,g7a9cd813b8+124095ede6,g9d27549199+a302e8c7f0,ga1cf026fa3+ac198e9f13,ga32aa97882+7403ac30ac,ga786bb30fb+7a139211af,gaa63f70f4e+9994eb9896,gabf319e997+ade567573c,gba47b54d5d+94dc90c3ea,gbec6a3398f+06cf436103,gc6308e37c7+07dd123edb,gc655b1545f+ade567573c,gcc9029db3c+ab229f5caf,gd01420fc67+06cf436103,gd877ba84e5+06cf436103,gdb4cecd868+6f279b5b48,ge2d134c3d5+cc4dbb2e3f,ge448b5faa6+86d1ceac1d,gecc7e12556+98f8679e14,gf3ee170dca+25247a063c,gf4ac96e456+ade567573c,gf9f5ea5b4d+ac198e9f13,gff490e6085+8c2580be5c,w.2022.27
LSST Data Management Base Package
Box3d.h
Go to the documentation of this file.
1/*
2 * LSST Data Management System
3 * See COPYRIGHT file at the top of the source tree.
4 *
5 * This product includes software developed by the
6 * LSST Project (http://www.lsst.org/).
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the LSST License Statement and
19 * the GNU General Public License along with this program. If not,
20 * see <https://www.lsstcorp.org/LegalNotices/>.
21 */
22
23#ifndef LSST_SPHGEOM_BOX3D_H_
24#define LSST_SPHGEOM_BOX3D_H_
25
29
30#include <iosfwd>
31
32#include "Interval1d.h"
33#include "Relationship.h"
34#include "Vector3d.h"
35
36
37namespace lsst {
38namespace sphgeom {
39
42class Box3d {
43public:
44 // Factory functions
45 static Box3d empty() {
46 return Box3d();
47 }
48
49 static Box3d full() {
50 return Box3d(Interval1d::full(),
53 }
54
57 return Box3d(Interval1d(-1.0, 1.0),
58 Interval1d(-1.0, 1.0),
59 Interval1d(-1.0, 1.0));
60 }
61
63 Box3d() {}
64
66 explicit Box3d(Vector3d const & v)
67 {
68 _intervals[0] = Interval1d(v.x());
69 _intervals[1] = Interval1d(v.y());
70 _intervals[2] = Interval1d(v.z());
71 _enforceInvariants();
72 }
73
76 Box3d(Vector3d const & v1, Vector3d const & v2)
77 {
78 _intervals[0] = Interval1d(v1.x(), v2.x());
79 _intervals[1] = Interval1d(v1.y(), v2.y());
80 _intervals[2] = Interval1d(v1.z(), v2.z());
81 _enforceInvariants();
82 }
83
86 Box3d(Vector3d const & v, double w, double h, double d)
87 {
88 _intervals[0] = Interval1d(v.x()).dilatedBy(w);
89 _intervals[1] = Interval1d(v.y()).dilatedBy(h);
90 _intervals[2] = Interval1d(v.z()).dilatedBy(d);
91 _enforceInvariants();
92 }
93
97 Interval1d const & y,
98 Interval1d const & z)
99 {
100 _intervals[0] = Interval1d(x);
101 _intervals[1] = Interval1d(y);
102 _intervals[2] = Interval1d(z);
103 _enforceInvariants();
104 }
105
107 bool operator==(Box3d const & b) const {
108 return _intervals[0] == b._intervals[0] &&
109 _intervals[1] == b._intervals[1] &&
110 _intervals[2] == b._intervals[2];
111 }
112
113 bool operator!=(Box3d const & b) const { return !(*this == b); }
114
116 bool operator==(Vector3d const & v) const { return *this == Box3d(v); }
117
118 bool operator!=(Vector3d const & v) const { return !(*this == v); }
119
121 Interval1d operator()(int i) const { return _intervals[i]; }
122
123 Interval1d const & x() const { return _intervals[0]; }
124 Interval1d const & y() const { return _intervals[1]; }
125 Interval1d const & z() const { return _intervals[2]; }
126
128 bool isEmpty() const {
129 return x().isEmpty();
130 }
131
133 bool isFull() const {
134 return x().isFull() && y().isFull() && z().isFull();
135 }
136
140 return Vector3d(x().getCenter(), y().getCenter(), z().getCenter());
141 }
142
145 double getWidth() const { return x().getSize(); }
146
149 double getHeight() const { return y().getSize(); }
150
153 double getDepth() const { return z().getSize(); }
154
158 bool contains(Vector3d const & b) const {
159 return x().contains(b.x()) &&
160 y().contains(b.y()) &&
161 z().contains(b.z());
162 }
163
164 bool contains(Box3d const & b) const {
165 return x().contains(b.x()) &&
166 y().contains(b.y()) &&
167 z().contains(b.z());
168 }
169
170 bool contains(double x_, double y_, double z_) const {
171 return x().contains(x_) && y().contains(y_) && z().contains(z_);
172 }
174
178 bool isDisjointFrom(Vector3d const & b) const { return !intersects(b); }
179
180 bool isDisjointFrom(Box3d const & b) const { return !intersects(b); }
182
186 bool intersects(Vector3d const & b) const {
187 return x().intersects(b.x()) &&
188 y().intersects(b.y()) &&
189 z().intersects(b.z());
190 }
191
192 bool intersects(Box3d const & b) const {
193 return x().intersects(b.x()) &&
194 y().intersects(b.y()) &&
195 z().intersects(b.z());
196 }
198
202 bool isWithin(Vector3d const & b) const {
203 return x().isWithin(b.x()) &&
204 y().isWithin(b.y()) &&
205 z().isWithin(b.z());
206 }
207
208 bool isWithin(Box3d const & b) const {
209 return x().isWithin(b.x()) &&
210 y().isWithin(b.y()) &&
211 z().isWithin(b.z());
212 }
214
217 Box3d & clipTo(Vector3d const & b) {
218 _intervals[0].clipTo(b.x());
219 _intervals[1].clipTo(b.y());
220 _intervals[2].clipTo(b.z());
221 _enforceInvariants();
222 return *this;
223 }
224
225 Box3d & clipTo(Box3d const & b) {
226 _intervals[0].clipTo(b.x());
227 _intervals[1].clipTo(b.y());
228 _intervals[2].clipTo(b.z());
229 _enforceInvariants();
230 return *this;
231 }
233
236 Box3d clippedTo(Vector3d const & b) const {
237 return Box3d(*this).clipTo(b);
238 }
239
240 Box3d clippedTo(Box3d const & b) const {
241 return Box3d(*this).clipTo(b);
242 }
244
248 _intervals[0].expandTo(b.x());
249 _intervals[1].expandTo(b.y());
250 _intervals[2].expandTo(b.z());
251 return *this;
252 }
253
254 Box3d & expandTo(Box3d const & b) {
255 _intervals[0].expandTo(b.x());
256 _intervals[1].expandTo(b.y());
257 _intervals[2].expandTo(b.z());
258 return *this;
259 }
261
265 Box3d expandedTo(Vector3d const & b) const {
266 return Box3d(*this).expandTo(b);
267 }
268
269 Box3d expandedTo(Box3d const & b) const {
270 return Box3d(*this).expandTo(b);
271 }
273
280 Box3d & dilateBy(double r) { return dilateBy(r, r, r); }
281 Box3d dilatedBy(double r) const { return Box3d(*this).dilateBy(r); }
282
290 Box3d & dilateBy(double w, double h, double d) {
291 _intervals[0].dilateBy(w);
292 _intervals[1].dilateBy(h);
293 _intervals[2].dilateBy(d);
294 _enforceInvariants();
295 return *this;
296 }
297 Box3d dilatedBy(double w, double h, double d) const {
298 return Box3d(*this).dilateBy(w, h, d);
299 }
300 Box3d & erodeBy(double r) { return dilateBy(-r); }
301 Box3d erodedBy(double r) const { return dilatedBy(-r); }
302 Box3d & erodeBy(double w, double h, double d) {
303 return dilateBy(-w, -h, -d);
304 }
305 Box3d erodedBy(double w, double h, double d) const {
306 return dilatedBy(-w, -h, -d);
307 }
308
309 Relationship relate(Vector3d const & v) const { return relate(Box3d(v)); }
310
311 Relationship relate(Box3d const & b) const {
312 Relationship xr = x().relate(b.x());
313 Relationship yr = y().relate(b.y());
314 Relationship zr = z().relate(b.z());
315 // If the box x, y, or z intervals are disjoint, then so are the
316 // boxes. The other relationships must hold for all constituent
317 // intervals in order to hold for the boxes.
318 return ((xr & yr & zr) & (CONTAINS | WITHIN)) |
319 ((xr | yr | zr) & DISJOINT);
320 }
321
322
323private:
324 void _enforceInvariants() {
325 // Make sure that all intervals are empty, or none are. This
326 // simplifies the implementation of relate and dilateBy.
327 if (x().isEmpty() || y().isEmpty() || z().isEmpty()) {
328 _intervals[0] = Interval1d();
329 _intervals[1] = Interval1d();
330 _intervals[2] = Interval1d();
331 }
332 }
333
334 Interval1d _intervals[3];
335};
336
337std::ostream & operator<<(std::ostream &, Box3d const &);
338
339}} // namespace lsst::sphgeom
340
341#endif // LSST_SPHGEOM_BOX3D_H_
This file defines a class for representing intervals of ℝ.
table::Key< int > b
This file declares a class for representing vectors in ℝ³.
Box3d represents a box in ℝ³.
Definition: Box3d.h:42
Box3d & erodeBy(double w, double h, double d)
Definition: Box3d.h:302
double getHeight() const
getHeight returns the height (y-axis extent) of this box.
Definition: Box3d.h:149
bool isEmpty() const
isEmpty returns true if this box does not contain any points.
Definition: Box3d.h:128
static Box3d empty()
Definition: Box3d.h:45
bool isFull() const
isFull returns true if this box contains all points in ℝ³.
Definition: Box3d.h:133
Box3d erodedBy(double w, double h, double d) const
Definition: Box3d.h:305
bool intersects(Vector3d const &b) const
Definition: Box3d.h:186
Box3d erodedBy(double r) const
Definition: Box3d.h:301
double getDepth() const
getDepth returns the depth (z-axis extent) of this box.
Definition: Box3d.h:153
bool isDisjointFrom(Box3d const &b) const
Definition: Box3d.h:180
bool contains(double x_, double y_, double z_) const
Definition: Box3d.h:170
Relationship relate(Box3d const &b) const
Definition: Box3d.h:311
bool operator==(Box3d const &b) const
Two 3D boxes are equal if they contain the same points.
Definition: Box3d.h:107
Interval1d const & x() const
Definition: Box3d.h:123
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:76
Box3d & dilateBy(double r)
dilateBy minimally expands or shrinks this Box to include or remove all points within distance |r| of...
Definition: Box3d.h:280
Box3d & clipTo(Box3d const &b)
Definition: Box3d.h:225
Box3d dilatedBy(double w, double h, double d) const
Definition: Box3d.h:297
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:86
Box3d & expandTo(Box3d const &b)
Definition: Box3d.h:254
bool intersects(Box3d const &b) const
Definition: Box3d.h:192
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:290
Box3d & expandTo(Vector3d const &b)
Definition: Box3d.h:247
Interval1d const & y() const
Definition: Box3d.h:124
bool isDisjointFrom(Vector3d const &b) const
Definition: Box3d.h:178
Interval1d operator()(int i) const
The function call operator returns the i-th interval of this box.
Definition: Box3d.h:121
bool isWithin(Box3d const &b) const
Definition: Box3d.h:208
bool isWithin(Vector3d const &b) const
Definition: Box3d.h:202
Box3d & clipTo(Vector3d const &b)
Definition: Box3d.h:217
Box3d()
This constructor creates an empty 3D box.
Definition: Box3d.h:63
Box3d dilatedBy(double r) const
Definition: Box3d.h:281
bool contains(Box3d const &b) const
Definition: Box3d.h:164
bool operator==(Vector3d const &v) const
A box is equal to a point if it contains only that point.
Definition: Box3d.h:116
Box3d clippedTo(Box3d const &b) const
Definition: Box3d.h:240
Box3d expandedTo(Vector3d const &b) const
Definition: Box3d.h:265
static Box3d full()
Definition: Box3d.h:49
Box3d(Vector3d const &v)
This constructor creates a box containing a single point.
Definition: Box3d.h:66
double getWidth() const
getWidth returns the width (x-axis extent) of this box.
Definition: Box3d.h:145
Box3d & erodeBy(double r)
Definition: Box3d.h:300
Box3d clippedTo(Vector3d const &b) const
Definition: Box3d.h:236
static Box3d aroundUnitSphere()
aroundUnitSphere returns a minimal Box3d containing the unit sphere.
Definition: Box3d.h:56
Vector3d getCenter() const
getCenter returns the center of this box.
Definition: Box3d.h:139
Box3d expandedTo(Box3d const &b) const
Definition: Box3d.h:269
Interval1d const & z() const
Definition: Box3d.h:125
bool operator!=(Vector3d const &v) const
Definition: Box3d.h:118
bool operator!=(Box3d const &b) const
Definition: Box3d.h:113
bool contains(Vector3d const &b) const
Definition: Box3d.h:158
Relationship relate(Vector3d const &v) const
Definition: Box3d.h:309
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:96
Interval1d represents closed intervals of ℝ.
Definition: Interval1d.h:40
bool isFull() const
isFull returns true if this interval = ℝ.
Definition: Interval1d.h:63
static Interval1d full()
Definition: Interval1d.h:48
bool isWithin(Scalar x) const
Definition: Interval.h:140
Derived dilatedBy(Scalar x) const
Definition: Interval.h:239
Interval & dilateBy(Scalar x)
For positive x, dilateBy morphologically dilates this interval by [-x,x], which is equivalent to the ...
Definition: Interval.h:230
Scalar getSize() const
getSize returns the size (length, width) of this interval.
Definition: Interval.h:93
Interval & clipTo(Scalar x)
Definition: Interval.h:159
bool isEmpty() const
isEmpty returns true if this interval does not contain any points.
Definition: Interval.h:83
Relationship relate(Scalar x) const
Definition: Interval.h:249
bool intersects(Scalar x) const
Definition: Interval.h:130
Interval & expandTo(Scalar x)
Definition: Interval.h:192
bool contains(Scalar x) const
Definition: Interval.h:98
Vector3d is a vector in ℝ³ with components stored in double precision.
Definition: Vector3d.h:44
double x() const
Definition: Vector3d.h:66
double y() const
Definition: Vector3d.h:68
double z() const
Definition: Vector3d.h:70
std::ostream & operator<<(std::ostream &, Angle const &)
Definition: Angle.cc:34
A base class for image defects.
This file provides a type alias for describing set relationships.
double w
Definition: CoaddPsf.cc:69