lsst.sphgeom
g8f490195a6+663e2227e0
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
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
®ion);
231
245
std::string
toIvoaStcs
(std::string
const
& frame =
"ICRS"
)
const
{
246
return
toIvoaStcsBody(frame);
247
}
248
249
protected
:
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
266
private
:
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_
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:245
lsst::sphgeom::Region::decodeBase64
static std::unique_ptr< Region > decodeBase64(std::string const &s)
Definition
Region.h:207
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:149
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:193
lsst::sphgeom::Region::overlaps
virtual TriState overlaps(Region const &other) const =0
Definition
Region.cc:63
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:221
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