LSST Applications g063fba187b+cac8b7c890,g0f08755f38+6aee506743,g1653933729+a8ce1bb630,g168dd56ebc+a8ce1bb630,g1a2382251a+b4475c5878,g1dcb35cd9c+8f9bc1652e,g20f6ffc8e0+6aee506743,g217e2c1bcf+73dee94bd0,g28da252d5a+1f19c529b9,g2bbee38e9b+3f2625acfc,g2bc492864f+3f2625acfc,g3156d2b45e+6e55a43351,g32e5bea42b+1bb94961c2,g347aa1857d+3f2625acfc,g35bb328faa+a8ce1bb630,g3a166c0a6a+3f2625acfc,g3e281a1b8c+c5dd892a6c,g3e8969e208+a8ce1bb630,g414038480c+5927e1bc1e,g41af890bb2+8a9e676b2a,g7af13505b9+809c143d88,g80478fca09+6ef8b1810f,g82479be7b0+f568feb641,g858d7b2824+6aee506743,g89c8672015+f4add4ffd5,g9125e01d80+a8ce1bb630,ga5288a1d22+2903d499ea,gb58c049af0+d64f4d3760,gc28159a63d+3f2625acfc,gcab2d0539d+b12535109e,gcf0d15dbbd+46a3f46ba9,gda6a2b7d83+46a3f46ba9,gdaeeff99f8+1711a396fd,ge79ae78c31+3f2625acfc,gef2f8181fd+0a71e47438,gf0baf85859+c1f95f4921,gfa517265be+6aee506743,gfa999e8aa5+17cd334064,w.2024.51
LSST Data Management Base Package
Loading...
Searching...
No Matches
CompoundRegion.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_COMPOUND_REGION_H_
31#define LSST_SPHGEOM_COMPOUND_REGION_H_
32
36
37#include <iosfwd>
38#include <iterator>
39#include <vector>
40#include <cstdint>
41
42#include "Region.h"
43#include "UnitVector3d.h"
44
45namespace lsst {
46namespace sphgeom {
47
48class Box;
49class Circle;
50class ConvexPolygon;
51class Ellipse;
52
55class CompoundRegion : public Region {
56public:
58
61
63 CompoundRegion(CompoundRegion &&) noexcept = default;
64
65 // Disable assignment (including for subclasses) because it makes it hard
66 // to guarantee memory safety for operand accessors in Python.
67 CompoundRegion &operator=(CompoundRegion const &) = delete;
68 CompoundRegion &operator=(CompoundRegion &&) = delete;
69
70 // Return number of operands
71 size_t nOperands() const { return _operands.size(); }
72
73 // Return references to the operands.
74 Region const & getOperand(std::size_t n) const {
75 return *_operands[n];
76 }
77
78 // Region interface.
79 virtual Relationship relate(Region const &r) const = 0; // still unimplemented; avoid shadowing
80 Relationship relate(Box const &b) const override;
81 Relationship relate(Circle const &c) const override;
82 Relationship relate(ConvexPolygon const &p) const override;
83 Relationship relate(Ellipse const &e) const override;
84
89 return decode(s.data(), s.size());
90 }
91 static std::unique_ptr<CompoundRegion> decode(std::uint8_t const *buffer, size_t n);
93
94protected:
95
96 // Implementation helper for encode().
98
99 // Implementation helper for decode().
101 std::uint8_t tc, std::uint8_t const *buffer, std::size_t nBytes);
102
103 // Provide read access to all operands for quick iteration.
104 std::vector<std::unique_ptr<Region>> const& operands() const { return _operands; }
105
106 // Flatten vector of regions in-place.
107 template <typename Compound>
108 void flatten_operands();
109
110private:
112};
113
119public:
120 static constexpr std::uint8_t TYPE_CODE = 'u';
121
124
125 // Region interface.
126 std::unique_ptr<Region> clone() const override { return std::make_unique<UnionRegion>(*this); }
127 bool isEmpty() const override;
128 Box getBoundingBox() const override;
129 Box3d getBoundingBox3d() const override;
130 Circle getBoundingCircle() const override;
131 using Region::contains;
132 bool contains(UnitVector3d const &v) const override;
133 Relationship relate(Region const &r) const override;
134 TriState overlaps(Region const& other) const override;
135 TriState overlaps(Box const &) const override;
136 TriState overlaps(Circle const &) const override;
137 TriState overlaps(ConvexPolygon const &) const override;
138 TriState overlaps(Ellipse const &) const override;
139 std::vector<std::uint8_t> encode() const override { return _encode(TYPE_CODE); }
140
145 return decode(s.data(), s.size());
146 }
147 static std::unique_ptr<UnionRegion> decode(std::uint8_t const *buffer, size_t n) {
148 return std::make_unique<UnionRegion>(_decode(TYPE_CODE, buffer, n));
149 }
151
152};
153
159public:
160 static constexpr std::uint8_t TYPE_CODE = 'i';
161
164
165 // Region interface.
166 std::unique_ptr<Region> clone() const override { return std::make_unique<IntersectionRegion>(*this); }
167 bool isEmpty() const override;
168 Box getBoundingBox() const override;
169 Box3d getBoundingBox3d() const override;
170 Circle getBoundingCircle() const override;
171 using Region::contains;
172 bool contains(UnitVector3d const &v) const override;
173 Relationship relate(Region const &r) const override;
174 TriState overlaps(Region const& other) const override;
175 TriState overlaps(Box const &) const override;
176 TriState overlaps(Circle const &) const override;
177 TriState overlaps(ConvexPolygon const &) const override;
178 TriState overlaps(Ellipse const &) const override;
179 std::vector<std::uint8_t> encode() const override { return _encode(TYPE_CODE); }
180
185 return decode(s.data(), s.size());
186 }
188 return std::make_unique<IntersectionRegion>(_decode(TYPE_CODE, buffer, n));
189 }
191
192};
193
194} // namespace sphgeom
195} // namespace lsst
196
197#endif // LSST_SPHGEOM_COMPOUND_REGION_H_
This file defines an interface for spherical regions.
table::Key< int > b
This file declares a class for representing unit vectors in ℝ³.
Box3d represents a box in ℝ³.
Definition Box3d.h:49
Box represents a rectangle in spherical coordinate space that contains its boundary.
Definition Box.h:62
Circle is a circular region on the unit sphere that contains its boundary.
Definition Circle.h:54
CompoundRegion is an intermediate base class for spherical regions that are comprised of a point-set ...
virtual Relationship relate(Region const &r) const =0
Region const & getOperand(std::size_t n) const
std::vector< std::unique_ptr< Region > > const & operands() const
std::vector< std::uint8_t > _encode(std::uint8_t tc) const
CompoundRegion(CompoundRegion &&) noexcept=default
CompoundRegion(std::vector< std::unique_ptr< Region > > operands) noexcept
Construct by taking ownership of operands.
static std::unique_ptr< CompoundRegion > decode(std::vector< std::uint8_t > const &s)
static std::vector< std::unique_ptr< Region > > _decode(std::uint8_t tc, std::uint8_t const *buffer, std::size_t nBytes)
ConvexPolygon is a closed convex polygon on the unit sphere.
Ellipse is an elliptical region on the sphere.
Definition Ellipse.h:177
IntersectionRegion is a lazy point-set inersection of its operands.
Relationship relate(Region const &r) const override
IntersectionRegion(std::vector< std::unique_ptr< Region > > operands)
Construct by taking ownership of operands.
static std::unique_ptr< IntersectionRegion > decode(std::vector< std::uint8_t > const &s)
std::unique_ptr< Region > clone() const override
clone returns a deep copy of this region.
static constexpr std::uint8_t TYPE_CODE
Circle getBoundingCircle() const override
getBoundingCircle returns a bounding-circle for this region.
bool isEmpty() const override
isEmpty returns true when a region does not contain any points.
Box3d getBoundingBox3d() const override
getBoundingBox3d returns a 3-dimensional bounding-box for this region.
bool contains(UnitVector3d const &v) const override
contains tests whether the given unit vector is inside this region.
Box getBoundingBox() const override
getBoundingBox returns a bounding-box for this region.
static std::unique_ptr< IntersectionRegion > decode(std::uint8_t const *buffer, size_t n)
std::vector< std::uint8_t > encode() const override
encode serializes this region into an opaque byte string.
TriState overlaps(Region const &other) const override
Region is a minimal interface for 2-dimensional regions on the unit sphere.
Definition Region.h:89
virtual bool contains(UnitVector3d const &) const =0
contains tests whether the given unit vector is inside this region.
TriState represents a boolean value with additional unknown state.
Definition TriState.h:46
UnionRegion is a lazy point-set union of its operands.
Box getBoundingBox() const override
getBoundingBox returns a bounding-box for this region.
static constexpr std::uint8_t TYPE_CODE
std::vector< std::uint8_t > encode() const override
encode serializes this region into an opaque byte string.
TriState overlaps(Region const &other) const override
static std::unique_ptr< UnionRegion > decode(std::uint8_t const *buffer, size_t n)
bool isEmpty() const override
isEmpty returns true when a region does not contain any points.
Relationship relate(Region const &r) const override
bool contains(UnitVector3d const &v) const override
contains tests whether the given unit vector is inside this region.
UnionRegion(std::vector< std::unique_ptr< Region > > operands)
Construct by taking ownership of operands.
std::unique_ptr< Region > clone() const override
clone returns a deep copy of this region.
Circle getBoundingCircle() const override
getBoundingCircle returns a bounding-circle for this region.
static std::unique_ptr< UnionRegion > decode(std::vector< std::uint8_t > const &s)
Box3d getBoundingBox3d() const override
getBoundingBox3d returns a 3-dimensional bounding-box for this region.
UnitVector3d is a unit vector in ℝ³ with components stored in double precision.