lsst.sphgeom g08ab6a953b+663e2227e0
Loading...
Searching...
No Matches
Region.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_REGION_H_
31#define LSST_SPHGEOM_REGION_H_
32
35
36#include <memory>
37#include <stdexcept>
38#include <vector>
39#include <cstdint>
40#include <string>
41
42#include "Relationship.h"
43#include "TriState.h"
44
45
46namespace lsst {
47namespace sphgeom {
48
49// Forward declarations
50class Box;
51class Box3d;
52class Circle;
53class ConvexPolygon;
54class Ellipse;
55class UnitVector3d;
56
63class
64#if defined(__GNUC__) || defined(__clang__)
65__attribute__((visibility("default")))
66#endif
67IvoaStcsNotImplemented : public std::runtime_error {
68public:
69 using std::runtime_error::runtime_error;
70};
71
105class Region {
106public:
107 virtual ~Region() = default;
108
110 virtual std::unique_ptr<Region> clone() const = 0;
111
113 virtual Box getBoundingBox() const = 0;
114
116 virtual Box3d getBoundingBox3d() const = 0;
117
119 virtual Circle getBoundingCircle() const = 0;
120
122 virtual bool isEmpty() const = 0;
123
125 virtual bool contains(UnitVector3d const &) const = 0;
126
129 bool contains(double x, double y, double z) const;
130
133 bool contains(double lon, double lat) const;
134
148 virtual bool contains(Region const &) const;
149
168 virtual Relationship relate(Region const &) const = 0;
169 virtual Relationship relate(Box const &) const = 0;
170 virtual Relationship relate(Circle const &) const = 0;
171 virtual Relationship relate(ConvexPolygon const &) const = 0;
172 virtual Relationship relate(Ellipse const &) const = 0;
174
180 virtual TriState overlaps(Region const& other) const = 0;
181 virtual TriState overlaps(Box const &) const = 0;
182 virtual TriState overlaps(Circle const &) const = 0;
183 virtual TriState overlaps(ConvexPolygon const &) const = 0;
184 virtual TriState overlaps(Ellipse const &) const = 0;
186
189 virtual std::vector<std::uint8_t> encode() const = 0;
190
193 static std::unique_ptr<Region> decode(std::vector<std::uint8_t> const & s) {
194 return decode(s.data(), s.size());
195 }
196
197 static std::unique_ptr<Region> decode(std::uint8_t const * buffer, size_t n);
199
207 static std::unique_ptr<Region> decodeBase64(std::string const & s) {
208 return decodeBase64(std::string_view(s));
209 }
210
211 static std::unique_ptr<Region> decodeBase64(std::string_view const & s);
213
221 static TriState decodeOverlapsBase64(std::string const & s) {
222 return decodeOverlapsBase64(std::string_view(s));
223 }
224
225 static TriState decodeOverlapsBase64(std::string_view const & s);
227
229 static std::vector<std::unique_ptr<Region>> getRegions(Region const &region);
231
245 std::string toIvoaStcs(std::string const & frame = "ICRS") const {
246 return toIvoaStcsBody(frame);
247 }
248
249protected:
250
251 // Default transformation of the region Relationship as returned from
252 // `relate` to TriState. Can be used when specific region class cannot
253 // compute more precise overlap relation.
254 static TriState _relationship_to_overlaps(Relationship r) {
255 // `relate` returns exact relation when specific bit is set, if it is
256 // not then relation may be true or not.
257 if ((r & DISJOINT) == DISJOINT) {
258 return TriState(false);
259 }
260 if ((r & (WITHIN | CONTAINS)).any()) {
261 return TriState(true);
262 }
263 return TriState();
264 }
265
266private:
273 virtual std::string toIvoaStcsBody(std::string const & frame = "") const {
274 throw IvoaStcsNotImplemented(
275 "This region can not be converted to an IVOA STC-S string."
276 );
277 }
278};
279
280}} // namespace lsst::sphgeom
281
282#endif // LSST_SPHGEOM_REGION_H_
Definition Box3d.h:49
Definition Box.h:62
Definition Circle.h:54
Definition ConvexPolygon.h:65
Definition Ellipse.h:177
Definition Region.h:105
std::string toIvoaStcs(std::string const &frame="ICRS") const
Definition Region.h:245
static std::unique_ptr< Region > decodeBase64(std::string const &s)
Definition Region.h:207
virtual Circle getBoundingCircle() const =0
getBoundingCircle returns a bounding-circle for this region.
virtual Relationship relate(Region const &) const =0
virtual std::vector< std::uint8_t > encode() const =0
virtual Box getBoundingBox() const =0
getBoundingBox returns a bounding-box for this region.
static std::vector< std::unique_ptr< Region > > getRegions(Region const &region)
getRegions returns a vector of Region.
Definition Region.cc:149
virtual bool contains(UnitVector3d const &) const =0
contains tests whether the given unit vector is inside this region.
virtual std::unique_ptr< Region > clone() const =0
clone returns a deep copy of this region.
static std::unique_ptr< Region > decode(std::vector< std::uint8_t > const &s)
Definition Region.h:193
virtual TriState overlaps(Region const &other) const =0
Definition Region.cc:63
virtual bool isEmpty() const =0
isEmpty returns true when a region does not contain any points.
static TriState decodeOverlapsBase64(std::string const &s)
Definition Region.h:221
virtual Box3d getBoundingBox3d() const =0
getBoundingBox3d returns a 3-dimensional bounding-box for this region.
Definition TriState.h:46
Definition UnitVector3d.h:62
Definition Angle.h:45
std::bitset< 3 > Relationship
Relationship describes how two sets are related.
Definition Relationship.h:42
This file provides a type alias for describing set relationships.
This file declares a class for representing tri-state values.