Loading [MathJax]/extensions/tex2jax.js
LSST Applications 28.0.2,g0fba68d861+5b923b673a,g1fd858c14a+7a7b9dd5ed,g2c84ff76c0+5548bfee71,g30358e5240+f0e04ebe90,g35bb328faa+fcb1d3bbc8,g436fd98eb5+bdc6fcdd04,g4af146b050+742274f7cd,g4d2262a081+3efd3f8190,g4e0f332c67+cb09b8a5b6,g53246c7159+fcb1d3bbc8,g5a012ec0e7+477f9c599b,g5edb6fd927+826dfcb47f,g60b5630c4e+bdc6fcdd04,g67b6fd64d1+2218407a0c,g78460c75b0+2f9a1b4bcd,g786e29fd12+cf7ec2a62a,g7b71ed6315+fcb1d3bbc8,g87b7deb4dc+f9ac2ab1bd,g8852436030+ebf28f0d95,g89139ef638+2218407a0c,g9125e01d80+fcb1d3bbc8,g989de1cb63+2218407a0c,g9f33ca652e+42fb53f4c8,g9f7030ddb1+11b9b6f027,ga2b97cdc51+bdc6fcdd04,gab72ac2889+bdc6fcdd04,gabe3b4be73+1e0a283bba,gabf8522325+3210f02652,gb1101e3267+9c79701da9,gb58c049af0+f03b321e39,gb89ab40317+2218407a0c,gcf25f946ba+ebf28f0d95,gd6cbbdb0b4+e8f9c9c900,gd9a9a58781+fcb1d3bbc8,gde0f65d7ad+a08f294619,ge278dab8ac+3ef3db156b,ge410e46f29+2218407a0c,gf67bdafdda+2218407a0c
LSST Data Management Base Package
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 <vector>
38#include <cstdint>
39#include <string>
40
41#include "Relationship.h"
42#include "TriState.h"
43
44
45namespace lsst {
46namespace sphgeom {
47
48// Forward declarations
49class Box;
50class Box3d;
51class Circle;
52class ConvexPolygon;
53class Ellipse;
54class UnitVector3d;
55
89class Region {
90public:
91 virtual ~Region() = default;
92
94 virtual std::unique_ptr<Region> clone() const = 0;
95
97 virtual Box getBoundingBox() const = 0;
98
100 virtual Box3d getBoundingBox3d() const = 0;
101
103 virtual Circle getBoundingCircle() const = 0;
104
106 virtual bool isEmpty() const = 0;
107
109 virtual bool contains(UnitVector3d const &) const = 0;
110
113 bool contains(double x, double y, double z) const;
114
117 bool contains(double lon, double lat) const;
118
137 virtual Relationship relate(Region const &) const = 0;
138 virtual Relationship relate(Box const &) const = 0;
139 virtual Relationship relate(Circle const &) const = 0;
140 virtual Relationship relate(ConvexPolygon const &) const = 0;
141 virtual Relationship relate(Ellipse const &) const = 0;
143
149 virtual TriState overlaps(Region const& other) const = 0;
150 virtual TriState overlaps(Box const &) const = 0;
151 virtual TriState overlaps(Circle const &) const = 0;
152 virtual TriState overlaps(ConvexPolygon const &) const = 0;
153 virtual TriState overlaps(Ellipse const &) const = 0;
155
159
163 return decode(s.data(), s.size());
164 }
165
166 static std::unique_ptr<Region> decode(std::uint8_t const * buffer, size_t n);
168
177 return decodeBase64(s);
178 }
179
180 static std::unique_ptr<Region> decodeBase64(std::string_view const & s);
182
191 return decodeOverlapsBase64(s);
192 }
193
194 static TriState decodeOverlapsBase64(std::string_view const & s);
196
200
201protected:
202
203 // Default transformation of the region Relationship as returned from
204 // `relate` to TriState. Can be used when specific region class cannot
205 // compute more precise overlap relation.
207 // `relate` returns exact relation when specific bit is set, if it is
208 // not then relation may be true or not.
209 if ((r & DISJOINT) == DISJOINT) {
210 return TriState(false);
211 }
212 if ((r & (WITHIN | CONTAINS)).any()) {
213 return TriState(true);
214 }
215 return TriState();
216 }
217
218};
219
220}} // namespace lsst::sphgeom
221
222#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.
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
ConvexPolygon is a closed convex polygon on the unit sphere.
Ellipse is an elliptical region on the sphere.
Definition Ellipse.h:177
Region is a minimal interface for 2-dimensional regions on the unit sphere.
Definition Region.h:89
static std::unique_ptr< Region > decodeBase64(std::string const &s)
Definition Region.h:176
virtual Relationship relate(Circle const &) const =0
virtual Relationship relate(Ellipse const &) const =0
static TriState _relationship_to_overlaps(Relationship r)
Definition Region.h:206
virtual Circle getBoundingCircle() const =0
getBoundingCircle returns a bounding-circle for this region.
virtual TriState overlaps(Ellipse const &) const =0
virtual Relationship relate(Region const &) const =0
virtual Relationship relate(Box const &) const =0
virtual std::vector< std::uint8_t > encode() const =0
encode serializes this region into an opaque byte string.
virtual ~Region()=default
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:145
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:162
virtual TriState overlaps(Region const &other) const =0
Definition Region.cc:59
virtual bool isEmpty() const =0
isEmpty returns true when a region does not contain any points.
virtual TriState overlaps(ConvexPolygon const &) const =0
static TriState decodeOverlapsBase64(std::string const &s)
Definition Region.h:190
virtual TriState overlaps(Circle const &) const =0
virtual Box3d getBoundingBox3d() const =0
getBoundingBox3d returns a 3-dimensional bounding-box for this region.
virtual Relationship relate(ConvexPolygon const &) const =0
virtual TriState overlaps(Box const &) const =0
TriState represents a boolean value with additional unknown state.
Definition TriState.h:46
UnitVector3d is a unit vector in ℝ³ with components stored in double precision.
std::bitset< 3 > Relationship
Relationship describes how two sets are related.