LSST Applications g0f08755f38+82efc23009,g12f32b3c4e+e7bdf1200e,g1653933729+a8ce1bb630,g1a0ca8cf93+50eff2b06f,g28da252d5a+52db39f6a5,g2bbee38e9b+37c5a29d61,g2bc492864f+37c5a29d61,g2cdde0e794+c05ff076ad,g3156d2b45e+41e33cbcdc,g347aa1857d+37c5a29d61,g35bb328faa+a8ce1bb630,g3a166c0a6a+37c5a29d61,g3e281a1b8c+fb992f5633,g414038480c+7f03dfc1b0,g41af890bb2+11b950c980,g5fbc88fb19+17cd334064,g6b1c1869cb+12dd639c9a,g781aacb6e4+a8ce1bb630,g80478fca09+72e9651da0,g82479be7b0+04c31367b4,g858d7b2824+82efc23009,g9125e01d80+a8ce1bb630,g9726552aa6+8047e3811d,ga5288a1d22+e532dc0a0b,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+37c5a29d61,gcf0d15dbbd+2acd6d4d48,gd7358e8bfb+778a810b6e,gda3e153d99+82efc23009,gda6a2b7d83+2acd6d4d48,gdaeeff99f8+1711a396fd,ge2409df99d+6b12de1076,ge79ae78c31+37c5a29d61,gf0baf85859+d0a5978c5a,gf3967379c6+4954f8c433,gfb92a5be7c+82efc23009,gfec2e1e490+2aaed99252,w.2024.46
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 <array>
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
59 CompoundRegion(Region const &first, Region const &second);
60 explicit CompoundRegion(std::array<std::unique_ptr<Region>, 2> operands) noexcept;
62
64 CompoundRegion(CompoundRegion &&) noexcept = default;
65
66 // Disable assignment (including for subclasses) because it makes it hard
67 // to guarantee memory safety for operand accessors in Python.
68 CompoundRegion &operator=(CompoundRegion const &) = delete;
69 CompoundRegion &operator=(CompoundRegion &&) = delete;
70
71 // Return references to the operands.
72 Region const & getOperand(std::size_t n) const {
73 return *_operands[n];
74 }
75
76 // Region interface.
77 virtual Relationship relate(Region const &r) const = 0; // still unimplemented; avoid shadowing
78 Relationship relate(Box const &b) const override;
79 Relationship relate(Circle const &c) const override;
80 Relationship relate(ConvexPolygon const &p) const override;
81 Relationship relate(Ellipse const &e) const override;
82
87 return decode(s.data(), s.size());
88 }
89 static std::unique_ptr<CompoundRegion> decode(std::uint8_t const *buffer, size_t n);
91
92protected:
93
94 // Implementation helper for encode().
96
97 // Implementation helper for decode().
99 std::uint8_t tc, std::uint8_t const *buffer, std::size_t nBytes);
100
101private:
103};
104
110public:
111 static constexpr std::uint8_t TYPE_CODE = 'u';
112
114
115 // Region interface.
116 std::unique_ptr<Region> clone() const override { return std::make_unique<UnionRegion>(*this); }
117 Box getBoundingBox() const override;
118 Box3d getBoundingBox3d() const override;
119 Circle getBoundingCircle() const override;
120 using Region::contains;
121 bool contains(UnitVector3d const &v) const override;
122 Relationship relate(Region const &r) const override;
123 std::vector<std::uint8_t> encode() const override { return _encode(TYPE_CODE); }
124
129 return decode(s.data(), s.size());
130 }
131 static std::unique_ptr<UnionRegion> decode(std::uint8_t const *buffer, size_t n) {
132 return std::make_unique<UnionRegion>(_decode(TYPE_CODE, buffer, n));
133 }
135
136};
137
143public:
144 static constexpr std::uint8_t TYPE_CODE = 'i';
145
147
148 // Region interface.
149 std::unique_ptr<Region> clone() const override { return std::make_unique<IntersectionRegion>(*this); }
150 Box getBoundingBox() const override;
151 Box3d getBoundingBox3d() const override;
152 Circle getBoundingCircle() const override;
153 using Region::contains;
154 bool contains(UnitVector3d const &v) const override;
155 Relationship relate(Region const &r) const override;
156 std::vector<std::uint8_t> encode() const override { return _encode(TYPE_CODE); }
157
162 return decode(s.data(), s.size());
163 }
165 return std::make_unique<IntersectionRegion>(_decode(TYPE_CODE, buffer, n));
166 }
168
169};
170
171} // namespace sphgeom
172} // namespace lsst
173
174#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::uint8_t > _encode(std::uint8_t tc) const
CompoundRegion(Region const &first, Region const &second)
Construct by copying or taking ownership of operands.
CompoundRegion(CompoundRegion &&) noexcept=default
static std::array< std::unique_ptr< Region >, 2 > _decode(std::uint8_t tc, std::uint8_t const *buffer, std::size_t nBytes)
static std::unique_ptr< CompoundRegion > decode(std::vector< std::uint8_t > const &s)
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
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.
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.
Region is a minimal interface for 2-dimensional regions on the unit sphere.
Definition Region.h:87
virtual bool contains(UnitVector3d const &) const =0
contains tests whether the given unit vector is inside this region.
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.
static std::unique_ptr< UnionRegion > decode(std::uint8_t const *buffer, size_t n)
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.
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.
STL namespace.