LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Span.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 /*
3  * LSST Data Management System
4  * Copyright 2008, 2009, 2010 LSST Corporation.
5  *
6  * This product includes software developed by the
7  * LSST Project (http://www.lsst.org/).
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the LSST License Statement and
20  * the GNU General Public License along with this program. If not,
21  * see <http://www.lsstcorp.org/LegalNotices/>.
22  */
23 
24 #ifndef LSST_AFW_GEOM_Span_h_INCLUDED
25 #define LSST_AFW_GEOM_Span_h_INCLUDED
26 
27 #include <string>
28 #include <iostream>
29 
30 #include "lsst/base.h"
31 #include "lsst/utils/hashCombine.h"
32 #include "lsst/geom.h"
34 
35 namespace lsst {
36 namespace afw {
37 
38 namespace detection {
39 class Footprint;
40 } // namespace detection
41 
42 namespace geom {
43 
47 class Span final {
48 public:
51 
53 
54  Span(int y,
55  int x0,
56  int x1)
57  : _y(y), _x0(x0), _x1(x1) {}
58 
59  Span(Interval const & x, int y) : _y(y), _x0(x.getMin()), _x1(x.getMax()) {}
60 
62  Span() noexcept : _y(0), _x0(0), _x1(-1) {}
63 
64  Span(Span const&) noexcept = default;
65  Span(Span&&) noexcept = default;
66  Span& operator=(Span const&) noexcept = default;
67  Span& operator=(Span&&) noexcept = default;
68  ~Span() noexcept = default;
69 
71  Iterator begin() const noexcept { return Iterator(lsst::geom::Point2I(_x0, _y)); }
72 
74  Iterator end() const noexcept { return Iterator(lsst::geom::Point2I(_x1 + 1, _y)); }
75 
76  int getX0() const noexcept { return _x0; }
77  int& getX0() noexcept { return _x0; }
78  int getX1() const noexcept { return _x1; }
79  int& getX1() noexcept { return _x1; }
80  Interval getX() const noexcept { return Interval::fromMinMax(_x0, _x1); }
81  int getY() const noexcept { return _y; }
82  int& getY() noexcept { return _y; }
83  int getWidth() const noexcept { return _x1 - _x0 + 1; }
84  int getMinX() const noexcept { return _x0; }
85  int getMaxX() const noexcept { return _x1; }
86  int getBeginX() const noexcept { return _x0; }
87  int getEndX() const noexcept { return _x1 + 1; }
88  lsst::geom::Point2I const getMin() const noexcept {
89  return lsst::geom::Point2I(_x0, _y);
90  }
91  lsst::geom::Point2I const getMax() const noexcept {
92  return lsst::geom::Point2I(_x1, _y);
93  }
94 
95  bool contains(int x) const noexcept { return (x >= _x0) && (x <= _x1); }
96  bool contains(int x, int y) const noexcept { return (x >= _x0) && (x <= _x1) && (y == _y); }
97  bool contains(lsst::geom::Point2I const& point) const noexcept {
98  return contains(point.getX(), point.getY());
99  }
100 
102  bool isEmpty() const noexcept { return _x1 < _x0; }
103 
105  std::string toString() const;
106 
107  void shift(int dx, int dy) noexcept {
108  _x0 += dx;
109  _x1 += dx;
110  _y += dy;
111  }
112 
114  friend std::ostream& operator<<(std::ostream& os, Span const& span) { return os << span.toString(); }
115 
116  bool operator==(Span const& other) const noexcept {
117  return other.getY() == getY() && other.getMinX() == getMinX() && other.getMaxX() == getMaxX();
118  }
119  bool operator!=(Span const& other) const noexcept { return !(*this == other); }
120 
122  std::size_t hash_value() const noexcept {
123  // Completely arbitrary seed
124  return utils::hashCombine(42, getY(), getMinX(), getMaxX());
125  }
126 
127  /* Required to make Span "LessThanComparable" so they can be used
128  * in sorting, binary search, etc.
129  * http://www.sgi.com/tech/stl/LessThanComparable.html
130  */
131  bool operator<(const Span& b) const noexcept;
132 
133  friend class detection::Footprint;
134 
135 private:
136  int _y;
137  int _x0;
138  int _x1;
139 };
140 } // namespace geom
141 } // namespace afw
142 } // namespace lsst
143 
144 namespace std {
145 template <>
146 struct hash<lsst::afw::geom::Span> {
149  result_type operator()(argument_type const& obj) const noexcept { return obj.hash_value(); }
150 };
151 } // namespace std
152 
153 #endif // LSST_AFW_GEOM_Span_h_INCLUDED
double x
std::ostream * os
Definition: Schema.cc:557
int y
Definition: SpanSet.cc:48
table::Key< int > b
Basic LSST definitions.
Class to describe the properties of a detected object from an image.
Definition: Footprint.h:63
A range of pixels within one row of an Image.
Definition: Span.h:47
bool isEmpty() const noexcept
Return true if the span contains no pixels.
Definition: Span.h:102
int getBeginX() const noexcept
Begin (inclusive) x-value.
Definition: Span.h:86
bool operator==(Span const &other) const noexcept
Definition: Span.h:116
int getMinX() const noexcept
Minimum x-value.
Definition: Span.h:84
int getMaxX() const noexcept
Maximum x-value.
Definition: Span.h:85
int & getX1() noexcept
Return the ending x-value.
Definition: Span.h:79
SpanPixelIterator Iterator
An iterator over points in the Span.
Definition: Span.h:50
lsst::geom::Point2I const getMax() const noexcept
Point corresponding to maximum x.
Definition: Span.h:91
lsst::geom::Point2I const getMin() const noexcept
Point corresponding to minimum x.
Definition: Span.h:88
friend std::ostream & operator<<(std::ostream &os, Span const &span)
Stream output; delegates to toString().
Definition: Span.h:114
int & getY() noexcept
Return the y-value.
Definition: Span.h:82
Span() noexcept
Construct an empty Span with zero width at the origin.
Definition: Span.h:62
Span(Span &&) noexcept=default
bool operator!=(Span const &other) const noexcept
Definition: Span.h:119
int getEndX() const noexcept
End (exclusive) x-value.
Definition: Span.h:87
std::size_t hash_value() const noexcept
Return a hash of this object.
Definition: Span.h:122
Span(int y, int x0, int x1)
Definition: Span.h:54
int & getX0() noexcept
Return the starting x-value.
Definition: Span.h:77
Iterator begin() const noexcept
Return an iterator to the first pixel in the Span.
Definition: Span.h:71
Interval getX() const noexcept
Definition: Span.h:80
bool contains(int x) const noexcept
Definition: Span.h:95
bool operator<(const Span &b) const noexcept
Definition: Span.cc:32
std::string toString() const
Return a string-representation of a Span.
Definition: Span.cc:43
int getY() const noexcept
Return the y-value.
Definition: Span.h:81
int getX0() const noexcept
Return the starting x-value.
Definition: Span.h:76
bool contains(int x, int y) const noexcept
Definition: Span.h:96
bool contains(lsst::geom::Point2I const &point) const noexcept
Definition: Span.h:97
Iterator end() const noexcept
Return an iterator to one past the last pixel in the Span.
Definition: Span.h:74
int getWidth() const noexcept
Return the number of pixels.
Definition: Span.h:83
Span(Span const &) noexcept=default
void shift(int dx, int dy) noexcept
Definition: Span.h:107
Span(Interval const &x, int y)
Definition: Span.h:59
int getX1() const noexcept
Return the ending x-value.
Definition: Span.h:78
An iterator that yields lsst::geom::Point2I and increases in the x direction.
A 1-d integer coordinate range.
Definition: Interval.h:50
static IntervalI fromMinMax(Element min, Element max)
Construct an interval from its lower and upper bounds.
Definition: Interval.cc:53
class[[deprecated("Removed with no replacement (but see lsst::afw::image::TransmissionCurve). Will be " "removed after v22.")]] FilterProperty final
Describe the properties of a Filter (e.g.
Definition: Filter.h:53
lsst::afw::detection::Footprint Footprint
Definition: Source.h:57
std::size_t hashCombine(std::size_t seed) noexcept
Combine hashes.
Definition: hashCombine.h:35
Point< int, 2 > Point2I
Definition: Point.h:321
A base class for image defects.
STL namespace.
result_type operator()(argument_type const &obj) const noexcept
Definition: Span.h:149