lsst.sphgeom gafb225b75d+afb4790f61
 
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
153 virtual Relationship relate(Region const &) const = 0;
154 virtual Relationship relate(Box const &) const = 0;
155 virtual Relationship relate(Circle const &) const = 0;
156 virtual Relationship relate(ConvexPolygon const &) const = 0;
157 virtual Relationship relate(Ellipse const &) const = 0;
159
165 virtual TriState overlaps(Region const& other) const = 0;
166 virtual TriState overlaps(Box const &) const = 0;
167 virtual TriState overlaps(Circle const &) const = 0;
168 virtual TriState overlaps(ConvexPolygon const &) const = 0;
169 virtual TriState overlaps(Ellipse const &) const = 0;
171
174 virtual std::vector<std::uint8_t> encode() const = 0;
175
178 static std::unique_ptr<Region> decode(std::vector<std::uint8_t> const & s) {
179 return decode(s.data(), s.size());
180 }
181
182 static std::unique_ptr<Region> decode(std::uint8_t const * buffer, size_t n);
184
192 static std::unique_ptr<Region> decodeBase64(std::string const & s) {
193 return decodeBase64(std::string_view(s));
194 }
195
196 static std::unique_ptr<Region> decodeBase64(std::string_view const & s);
198
206 static TriState decodeOverlapsBase64(std::string const & s) {
207 return decodeOverlapsBase64(std::string_view(s));
208 }
209
210 static TriState decodeOverlapsBase64(std::string_view const & s);
212
214 static std::vector<std::unique_ptr<Region>> getRegions(Region const &region);
216
230 std::string toIvoaStcs(std::string const & frame = "ICRS") const {
231 return toIvoaStcsBody(frame);
232 }
233
234protected:
235
236 // Default transformation of the region Relationship as returned from
237 // `relate` to TriState. Can be used when specific region class cannot
238 // compute more precise overlap relation.
239 static TriState _relationship_to_overlaps(Relationship r) {
240 // `relate` returns exact relation when specific bit is set, if it is
241 // not then relation may be true or not.
242 if ((r & DISJOINT) == DISJOINT) {
243 return TriState(false);
244 }
245 if ((r & (WITHIN | CONTAINS)).any()) {
246 return TriState(true);
247 }
248 return TriState();
249 }
250
251private:
258 virtual std::string toIvoaStcsBody(std::string const & frame = "") const {
259 throw IvoaStcsNotImplemented(
260 "This region can not be converted to an IVOA STC-S string."
261 );
262 }
263};
264
265}} // namespace lsst::sphgeom
266
267#endif // LSST_SPHGEOM_REGION_H_
This file provides a type alias for describing set relationships.
This file declares a class for representing tri-state values.
Definition Box3d.h:49
Definition Box.h:62
Definition Circle.h:54
Definition ConvexPolygon.h:65
Definition Ellipse.h:177
Definition UnitVector3d.h:62
Definition _continue_class.py:109
Definition Angle.h:45
virtual std::string toIvoaStcsBody(std::string const &frame="") const
virtually.
Definition Region.h:258
std::bitset< 3 > Relationship
Relationship describes how two sets are related.
Definition Relationship.h:42