lsst.sphgeom
gdcc65144bf+d801c9999e
Toggle main menu visibility
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
46
namespace
lsst {
47
namespace
sphgeom
{
48
49
// Forward declarations
50
class
Box
;
51
class
Box3d
;
52
class
Circle
;
53
class
ConvexPolygon
;
54
class
Ellipse
;
55
class
UnitVector3d
;
56
63
class
64
#if defined(__GNUC__) || defined(__clang__)
65
__attribute__((visibility(
"default"
)))
66
#endif
67
IvoaStcsNotImplemented
:
public
std::runtime_error {
68
public
:
69
using
std::runtime_error::runtime_error;
70
};
71
105
class
Region
{
106
public
:
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
®ion);
216
230
std::string
toIvoaStcs
(std::string
const
& frame =
"ICRS"
)
const
{
231
return
toIvoaStcsBody(frame);
232
}
233
234
protected
:
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
251
private
:
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_
lsst::sphgeom::Box3d
Definition
Box3d.h:49
lsst::sphgeom::Box
Definition
Box.h:62
lsst::sphgeom::Circle
Definition
Circle.h:54
lsst::sphgeom::ConvexPolygon
Definition
ConvexPolygon.h:65
lsst::sphgeom::Ellipse
Definition
Ellipse.h:177
lsst::sphgeom::IvoaStcsNotImplemented
Definition
Region.h:67
lsst::sphgeom::Region
Definition
Region.h:105
lsst::sphgeom::Region::toIvoaStcs
std::string toIvoaStcs(std::string const &frame="ICRS") const
Definition
Region.h:230
lsst::sphgeom::Region::decodeBase64
static std::unique_ptr< Region > decodeBase64(std::string const &s)
Definition
Region.h:192
lsst::sphgeom::Region::getBoundingCircle
virtual Circle getBoundingCircle() const =0
getBoundingCircle returns a bounding-circle for this region.
lsst::sphgeom::Region::relate
virtual Relationship relate(Region const &) const =0
lsst::sphgeom::Region::encode
virtual std::vector< std::uint8_t > encode() const =0
lsst::sphgeom::Region::getBoundingBox
virtual Box getBoundingBox() const =0
getBoundingBox returns a bounding-box for this region.
lsst::sphgeom::Region::getRegions
static std::vector< std::unique_ptr< Region > > getRegions(Region const ®ion)
getRegions returns a vector of Region.
Definition
Region.cc:145
lsst::sphgeom::Region::contains
virtual bool contains(UnitVector3d const &) const =0
contains tests whether the given unit vector is inside this region.
lsst::sphgeom::Region::clone
virtual std::unique_ptr< Region > clone() const =0
clone returns a deep copy of this region.
lsst::sphgeom::Region::decode
static std::unique_ptr< Region > decode(std::vector< std::uint8_t > const &s)
Definition
Region.h:178
lsst::sphgeom::Region::overlaps
virtual TriState overlaps(Region const &other) const =0
Definition
Region.cc:59
lsst::sphgeom::Region::isEmpty
virtual bool isEmpty() const =0
isEmpty returns true when a region does not contain any points.
lsst::sphgeom::Region::decodeOverlapsBase64
static TriState decodeOverlapsBase64(std::string const &s)
Definition
Region.h:206
lsst::sphgeom::Region::getBoundingBox3d
virtual Box3d getBoundingBox3d() const =0
getBoundingBox3d returns a 3-dimensional bounding-box for this region.
lsst::sphgeom::TriState
Definition
TriState.h:46
lsst::sphgeom::UnitVector3d
Definition
UnitVector3d.h:62
lsst::sphgeom
Definition
Angle.h:45
lsst::sphgeom::Relationship
std::bitset< 3 > Relationship
Relationship describes how two sets are related.
Definition
Relationship.h:42
Relationship.h
This file provides a type alias for describing set relationships.
TriState.h
This file declares a class for representing tri-state values.
include
lsst
sphgeom
Region.h
Generated by
1.17.0