lsst.afw  16.0-43-gaa65a4573+1
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/geom.h"
33 
34 namespace lsst {
35 namespace afw {
36 
37 namespace detection {
38 class Footprint;
39 } // namespace detection
40 
41 namespace geom {
42 
46 class Span final {
47 public:
50 
51  Span(int y,
52  int x0,
53  int x1)
54  : _y(y), _x0(x0), _x1(x1) {}
55 
57  Span() noexcept : _y(0), _x0(0), _x1(-1) {}
58 
59  Span(Span const&) noexcept = default;
60  Span(Span&&) noexcept = default;
61  Span& operator=(Span const&) noexcept = default;
62  Span& operator=(Span&&) noexcept = default;
63  ~Span() noexcept = default;
64 
66  Iterator begin() const noexcept { return Iterator(lsst::geom::Point2I(_x0, _y)); }
67 
69  Iterator end() const noexcept { return Iterator(lsst::geom::Point2I(_x1 + 1, _y)); }
70 
71  int getX0() const noexcept { return _x0; }
72  int& getX0() noexcept { return _x0; }
73  int getX1() const noexcept { return _x1; }
74  int& getX1() noexcept { return _x1; }
75  int getY() const noexcept { return _y; }
76  int& getY() noexcept { return _y; }
77  int getWidth() const noexcept { return _x1 - _x0 + 1; }
78  int getMinX() const noexcept { return _x0; }
79  int getMaxX() const noexcept { return _x1; }
80  int getBeginX() const noexcept { return _x0; }
81  int getEndX() const noexcept { return _x1 + 1; }
82  lsst::geom::Point2I const getMin() const noexcept {
83  return lsst::geom::Point2I(_x0, _y);
84  }
85  lsst::geom::Point2I const getMax() const noexcept {
86  return lsst::geom::Point2I(_x1, _y);
87  }
88 
89  bool contains(int x) const noexcept { return (x >= _x0) && (x <= _x1); }
90  bool contains(int x, int y) const noexcept { return (x >= _x0) && (x <= _x1) && (y == _y); }
91  bool contains(lsst::geom::Point2I const& point) const noexcept {
92  return contains(point.getX(), point.getY());
93  }
94 
96  bool isEmpty() const noexcept { return _x1 < _x0; }
97 
99  std::string toString() const;
100 
101  void shift(int dx, int dy) noexcept {
102  _x0 += dx;
103  _x1 += dx;
104  _y += dy;
105  }
106 
108  friend std::ostream& operator<<(std::ostream& os, Span const& span) { return os << span.toString(); }
109 
110  bool operator==(Span const& other) const noexcept {
111  return other.getY() == getY() && other.getMinX() == getMinX() && other.getMaxX() == getMaxX();
112  }
113  bool operator!=(Span const& other) const noexcept { return !(*this == other); }
114 
115  /* Required to make Span "LessThanComparable" so they can be used
116  * in sorting, binary search, etc.
117  * http://www.sgi.com/tech/stl/LessThanComparable.html
118  */
119  bool operator<(const Span& b) const noexcept;
120 
121  friend class detection::Footprint;
122 
123 private:
124  int _y;
125  int _x0;
126  int _x1;
127 };
128 } // namespace geom
129 } // namespace afw
130 } // namespace lsst
131 
132 #endif // LSST_AFW_GEOM_Span_h_INCLUDED
int getBeginX() const noexcept
Begin (inclusive) x-value.
Definition: Span.h:80
lsst::geom::Point2I const getMin() const noexcept
Point corresponding to minimum x.
Definition: Span.h:82
An iterator that yields lsst::geom::Point2I and increases in the x direction.
Iterator end() const noexcept
Return an iterator to one past the last pixel in the Span.
Definition: Span.h:69
friend std::ostream & operator<<(std::ostream &os, Span const &span)
Stream output; delegates to toString().
Definition: Span.h:108
A range of pixels within one row of an Image.
Definition: Span.h:46
int getMaxX() const noexcept
Maximum x-value.
Definition: Span.h:79
Span() noexcept
Construct an empty Span with zero width at the origin.
Definition: Span.h:57
ItemVariant const * other
Definition: Schema.cc:55
int & getX1() noexcept
Return the ending x-value.
Definition: Span.h:74
lsst::geom::Point2I const getMax() const noexcept
Point corresponding to maximum x.
Definition: Span.h:85
bool contains(int x) const noexcept
Definition: Span.h:89
bool contains(lsst::geom::Point2I const &point) const noexcept
Definition: Span.h:91
int & getX0() noexcept
Return the starting x-value.
Definition: Span.h:72
STL class.
int & getY() noexcept
Return the y-value.
Definition: Span.h:76
A base class for image defects.
int getWidth() const noexcept
Return the number of pixels.
Definition: Span.h:77
Iterator begin() const noexcept
Return an iterator to the first pixel in the Span.
Definition: Span.h:66
table::Key< int > b
int getEndX() const noexcept
End (exclusive) x-value.
Definition: Span.h:81
void shift(int dx, int dy) noexcept
Definition: Span.h:101
double x
Point< int, 2 > Point2I
Class to describe the properties of a detected object from an image.
Definition: Footprint.h:63
int getMinX() const noexcept
Minimum x-value.
Definition: Span.h:78
bool operator!=(Span const &other) const noexcept
Definition: Span.h:113
lsst::afw::detection::Footprint Footprint
Definition: Source.h:61
bool isEmpty() const noexcept
Return true if the span contains no pixels.
Definition: Span.h:96
bool contains(int x, int y) const noexcept
Definition: Span.h:90
int getX1() const noexcept
Return the ending x-value.
Definition: Span.h:73
int getY() const noexcept
Return the y-value.
Definition: Span.h:75
SpanPixelIterator Iterator
An iterator over points in the Span.
Definition: Span.h:49
std::string toString() const
Return a string-representation of a Span.
Definition: Span.cc:43
std::ostream * os
Definition: Schema.cc:737
STL class.
int y
Definition: SpanSet.cc:49
bool operator==(Span const &other) const noexcept
Definition: Span.h:110
Span(int y, int x0, int x1)
Definition: Span.h:51
int getX0() const noexcept
Return the starting x-value.
Definition: Span.h:71