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