LSSTApplications  19.0.0-14-gb0260a2+72efe9b372,20.0.0+7927753e06,20.0.0+8829bf0056,20.0.0+995114c5d2,20.0.0+b6f4b2abd1,20.0.0+bddc4f4cbe,20.0.0-1-g253301a+8829bf0056,20.0.0-1-g2b7511a+0d71a2d77f,20.0.0-1-g5b95a8c+7461dd0434,20.0.0-12-g321c96ea+23efe4bbff,20.0.0-16-gfab17e72e+fdf35455f6,20.0.0-2-g0070d88+ba3ffc8f0b,20.0.0-2-g4dae9ad+ee58a624b3,20.0.0-2-g61b8584+5d3db074ba,20.0.0-2-gb780d76+d529cf1a41,20.0.0-2-ged6426c+226a441f5f,20.0.0-2-gf072044+8829bf0056,20.0.0-2-gf1f7952+ee58a624b3,20.0.0-20-geae50cf+e37fec0aee,20.0.0-25-g3dcad98+544a109665,20.0.0-25-g5eafb0f+ee58a624b3,20.0.0-27-g64178ef+f1f297b00a,20.0.0-3-g4cc78c6+e0676b0dc8,20.0.0-3-g8f21e14+4fd2c12c9a,20.0.0-3-gbd60e8c+187b78b4b8,20.0.0-3-gbecbe05+48431fa087,20.0.0-38-ge4adf513+a12e1f8e37,20.0.0-4-g97dc21a+544a109665,20.0.0-4-gb4befbc+087873070b,20.0.0-4-gf910f65+5d3db074ba,20.0.0-5-gdfe0fee+199202a608,20.0.0-5-gfbfe500+d529cf1a41,20.0.0-6-g64f541c+d529cf1a41,20.0.0-6-g9a5b7a1+a1cd37312e,20.0.0-68-ga3f3dda+5fca18c6a4,20.0.0-9-g4aef684+e18322736b,w.2020.45
LSSTDataManagementBasePackage
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 
52  Span(int y,
53  int x0,
54  int x1)
55  : _y(y), _x0(x0), _x1(x1) {}
56 
58  Span() noexcept : _y(0), _x0(0), _x1(-1) {}
59 
60  Span(Span const&) noexcept = default;
61  Span(Span&&) noexcept = default;
62  Span& operator=(Span const&) noexcept = default;
63  Span& operator=(Span&&) noexcept = default;
64  ~Span() noexcept = default;
65 
67  Iterator begin() const noexcept { return Iterator(lsst::geom::Point2I(_x0, _y)); }
68 
70  Iterator end() const noexcept { return Iterator(lsst::geom::Point2I(_x1 + 1, _y)); }
71 
72  int getX0() const noexcept { return _x0; }
73  int& getX0() noexcept { return _x0; }
74  int getX1() const noexcept { return _x1; }
75  int& getX1() noexcept { return _x1; }
76  int getY() const noexcept { return _y; }
77  int& getY() noexcept { return _y; }
78  int getWidth() const noexcept { return _x1 - _x0 + 1; }
79  int getMinX() const noexcept { return _x0; }
80  int getMaxX() const noexcept { return _x1; }
81  int getBeginX() const noexcept { return _x0; }
82  int getEndX() const noexcept { return _x1 + 1; }
83  lsst::geom::Point2I const getMin() const noexcept {
84  return lsst::geom::Point2I(_x0, _y);
85  }
86  lsst::geom::Point2I const getMax() const noexcept {
87  return lsst::geom::Point2I(_x1, _y);
88  }
89 
90  bool contains(int x) const noexcept { return (x >= _x0) && (x <= _x1); }
91  bool contains(int x, int y) const noexcept { return (x >= _x0) && (x <= _x1) && (y == _y); }
92  bool contains(lsst::geom::Point2I const& point) const noexcept {
93  return contains(point.getX(), point.getY());
94  }
95 
97  bool isEmpty() const noexcept { return _x1 < _x0; }
98 
100  std::string toString() const;
101 
102  void shift(int dx, int dy) noexcept {
103  _x0 += dx;
104  _x1 += dx;
105  _y += dy;
106  }
107 
109  friend std::ostream& operator<<(std::ostream& os, Span const& span) { return os << span.toString(); }
110 
111  bool operator==(Span const& other) const noexcept {
112  return other.getY() == getY() && other.getMinX() == getMinX() && other.getMaxX() == getMaxX();
113  }
114  bool operator!=(Span const& other) const noexcept { return !(*this == other); }
115 
117  std::size_t hash_value() const noexcept {
118  // Completely arbitrary seed
119  return utils::hashCombine(42, getY(), getMinX(), getMaxX());
120  }
121 
122  /* Required to make Span "LessThanComparable" so they can be used
123  * in sorting, binary search, etc.
124  * http://www.sgi.com/tech/stl/LessThanComparable.html
125  */
126  bool operator<(const Span& b) const noexcept;
127 
128  friend class detection::Footprint;
129 
130 private:
131  int _y;
132  int _x0;
133  int _x1;
134 };
135 } // namespace geom
136 } // namespace afw
137 } // namespace lsst
138 
139 namespace std {
140 template <>
141 struct hash<lsst::afw::geom::Span> {
144  result_type operator()(argument_type const& obj) const noexcept { return obj.hash_value(); }
145 };
146 } // namespace std
147 
148 #endif // LSST_AFW_GEOM_Span_h_INCLUDED
y
int y
Definition: SpanSet.cc:49
lsst::afw::geom::Span::Iterator
SpanPixelIterator Iterator
An iterator over points in the Span.
Definition: Span.h:50
lsst::afw::geom::Span
A range of pixels within one row of an Image.
Definition: Span.h:47
std::string
STL class.
lsst::afw::geom::Span::Span
Span() noexcept
Construct an empty Span with zero width at the origin.
Definition: Span.h:58
lsst::afw::geom::Span::getX1
int getX1() const noexcept
Return the ending x-value.
Definition: Span.h:74
lsst::afw
Definition: imageAlgorithm.dox:1
lsst::afw::geom::Span::getY
int & getY() noexcept
Return the y-value.
Definition: Span.h:77
lsst::afw::geom::Span::getWidth
int getWidth() const noexcept
Return the number of pixels.
Definition: Span.h:78
std::hash< lsst::afw::geom::Span >::operator()
result_type operator()(argument_type const &obj) const noexcept
Definition: Span.h:144
lsst::afw::geom::SpanPixelIterator
An iterator that yields lsst::geom::Point2I and increases in the x direction.
Definition: SpanPixelIterator.h:43
SpanPixelIterator.h
hashCombine.h
lsst::afw::geom::Span::hash_value
std::size_t hash_value() const noexcept
Return a hash of this object.
Definition: Span.h:117
lsst::afw::geom::Span::begin
Iterator begin() const noexcept
Return an iterator to the first pixel in the Span.
Definition: Span.h:67
lsst::afw::geom::Span::toString
std::string toString() const
Return a string-representation of a Span.
Definition: Span.cc:43
base.h
lsst::afw::geom::Span::getY
int getY() const noexcept
Return the y-value.
Definition: Span.h:76
std::ostream
STL class.
lsst::afw::geom::Span::getEndX
int getEndX() const noexcept
End (exclusive) x-value.
Definition: Span.h:82
x
double x
Definition: ChebyshevBoundedField.cc:277
lsst::afw::geom::Span::Span
Span(int y, int x0, int x1)
Definition: Span.h:52
lsst::afw::table::Footprint
lsst::afw::detection::Footprint Footprint
Definition: Source.h:59
other
ItemVariant const * other
Definition: Schema.cc:56
lsst::afw::geom::Span::contains
bool contains(int x) const noexcept
Definition: Span.h:90
lsst::afw::geom::Span::operator==
bool operator==(Span const &other) const noexcept
Definition: Span.h:111
lsst::afw::geom::Span::isEmpty
bool isEmpty() const noexcept
Return true if the span contains no pixels.
Definition: Span.h:97
lsst::afw::geom::Span::operator<<
friend std::ostream & operator<<(std::ostream &os, Span const &span)
Stream output; delegates to toString().
Definition: Span.h:109
lsst::afw::geom::Span::getMinX
int getMinX() const noexcept
Minimum x-value.
Definition: Span.h:79
lsst::afw::geom::Span::getMax
lsst::geom::Point2I const getMax() const noexcept
Point corresponding to maximum x.
Definition: Span.h:86
lsst::afw::geom::Span::getMaxX
int getMaxX() const noexcept
Maximum x-value.
Definition: Span.h:80
b
table::Key< int > b
Definition: TransmissionCurve.cc:467
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
lsst::afw::geom::Span::getX0
int getX0() const noexcept
Return the starting x-value.
Definition: Span.h:72
lsst::afw::geom::Span::end
Iterator end() const noexcept
Return an iterator to one past the last pixel in the Span.
Definition: Span.h:70
lsst::geom
Definition: AffineTransform.h:36
os
std::ostream * os
Definition: Schema.cc:746
lsst::utils::hashCombine
std::size_t hashCombine(std::size_t seed) noexcept
Combine hashes.
Definition: hashCombine.h:35
lsst::afw::geom::Span::operator<
bool operator<(const Span &b) const noexcept
Definition: Span.cc:32
lsst::afw::geom::Span::Span
Span(Span &&) noexcept=default
std
STL namespace.
lsst::geom::Point< int, 2 >
lsst::afw::geom::Span::getBeginX
int getBeginX() const noexcept
Begin (inclusive) x-value.
Definition: Span.h:81
lsst::geom::Point2I
Point< int, 2 > Point2I
Definition: Point.h:321
lsst::afw::geom::Span::shift
void shift(int dx, int dy) noexcept
Definition: Span.h:102
std::size_t
lsst::afw::geom::Span::getX0
int & getX0() noexcept
Return the starting x-value.
Definition: Span.h:73
lsst::afw::geom::Span::contains
bool contains(lsst::geom::Point2I const &point) const noexcept
Definition: Span.h:92
lsst::afw::detection::Footprint
Class to describe the properties of a detected object from an image.
Definition: Footprint.h:63
lsst::afw::geom::Span::Span
Span(Span const &) noexcept=default
lsst::afw::geom::Span::operator!=
bool operator!=(Span const &other) const noexcept
Definition: Span.h:114
lsst::afw::geom::Span::getX1
int & getX1() noexcept
Return the ending x-value.
Definition: Span.h:75
lsst::afw::geom::Span::getMin
lsst::geom::Point2I const getMin() const noexcept
Point corresponding to minimum x.
Definition: Span.h:83
geom.h
lsst::afw::geom::Span::contains
bool contains(int x, int y) const noexcept
Definition: Span.h:91
std::hash