LSST Applications g04e9c324dd+8c5ae1fdc5,g134cb467dc+1b3060144d,g18429d2f64+f642bf4753,g199a45376c+0ba108daf9,g1fd858c14a+2dcf163641,g262e1987ae+7b8c96d2ca,g29ae962dfc+3bd6ecb08a,g2cef7863aa+aef1011c0b,g35bb328faa+8c5ae1fdc5,g3fd5ace14f+53e1a9e7c5,g4595892280+fef73a337f,g47891489e3+2efcf17695,g4d44eb3520+642b70b07e,g53246c7159+8c5ae1fdc5,g67b6fd64d1+2efcf17695,g67fd3c3899+b70e05ef52,g74acd417e5+317eb4c7d4,g786e29fd12+668abc6043,g87389fa792+8856018cbb,g89139ef638+2efcf17695,g8d7436a09f+3be3c13596,g8ea07a8fe4+9f5ccc88ac,g90f42f885a+a4e7b16d9b,g97be763408+ad77d7208f,g9dd6db0277+b70e05ef52,ga681d05dcb+a3f46e7fff,gabf8522325+735880ea63,gac2eed3f23+2efcf17695,gb89ab40317+2efcf17695,gbf99507273+8c5ae1fdc5,gd8ff7fe66e+b70e05ef52,gdab6d2f7ff+317eb4c7d4,gdc713202bf+b70e05ef52,gdfd2d52018+b10e285e0f,ge365c994fd+310e8507c4,ge410e46f29+2efcf17695,geaed405ab2+562b3308c0,gffca2db377+8c5ae1fdc5,w.2025.35
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 }
150
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 }
190
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.
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
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
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
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.
std::bitset< 3 > Relationship
Relationship describes how two sets are related.