LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
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 "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 namespace lsst {
43 namespace afw {
44 
45 namespace detection {
46 class Footprint;
47 } // namespace detection
48 
49 namespace geom {
50 
54 class Span {
55 public:
56 
57  typedef boost::shared_ptr<Span> Ptr;
58  typedef boost::shared_ptr<Span const> ConstPtr;
59 
62 
63  Span(int y,
64  int x0,
65  int x1)
66  : _y(y), _x0(x0), _x1(x1) {}
67 
69  Span() : _y(0), _x0(0), _x1(-1) {}
70 
72  Iterator begin() const { return Iterator(Point2I(_x0, _y)); }
73 
75  Iterator end() const { return Iterator(Point2I(_x1+1, _y)); }
76 
77  int getX0() const { return _x0; }
78  int& getX0() { return _x0; }
79  int getX1() const { return _x1; }
80  int& getX1() { return _x1; }
81  int getY() const { return _y; }
82  int& getY() { return _y; }
83  int getWidth() const { return _x1 - _x0 + 1; }
84  int getMinX() const { return _x0; }
85  int getMaxX() const { return _x1; }
86  int getBeginX() const { return _x0; }
87  int getEndX() const { return _x1+1; }
88  Point2I const getMin() const { return Point2I(_x0, _y); }
89  Point2I const getMax() const { return Point2I(_x1, _y); }
90 
91  bool contains(int x) const { return (x >= _x0) && (x <= _x1); }
92  bool contains(int x, int y) const { return (x >= _x0) && (x <= _x1) && (y == _y); }
93  bool contains(Point2I const & point) const { return contains(point.getX(), point.getY()); }
94 
96  bool isEmpty() const { return _x1 < _x0; }
97 
99  std::string toString() const;
100 
101  void shift(int dx, int dy) { _x0 += dx; _x1 += dx; _y += dy; }
102 
104  friend std::ostream & operator<<(std::ostream & os, Span const & span) { return os << span.toString(); }
105 
106  bool operator==(Span const & other) const {
107  return other.getY() == getY() && other.getMinX() == getMinX() && other.getMaxX() == getMaxX();
108  }
109  bool operator!=(Span const & other) const { return !(*this == other); }
110 
111  /* Required to make Span "LessThanComparable" so they can be used
112  * in sorting, binary search, etc.
113  * http://www.sgi.com/tech/stl/LessThanComparable.html
114  */
115  bool operator<(const Span& b) const;
116 
117  friend class detection::Footprint;
118 private:
119 
121  template <typename Archive>
122  void serialize(Archive & ar, const unsigned int version) {
123  ar & boost::serialization::make_nvp("y", _y)
124  & boost::serialization::make_nvp("x0", _x0)
125  & boost::serialization::make_nvp("x1", _x1);
126  }
127 
128  int _y;
129  int _x0;
130  int _x1;
131 };
132 
133 }}} // lsst::afw::geom
134 
135 #endif // LSST_AFW_GEOM_Span_h_INCLUDED
int y
int getEndX() const
End (exclusive) x-value.
Definition: Span.h:87
An iterator that yields Point2I and increases in the x direction.
int getMaxX() const
Maximum x-value.
Definition: Span.h:85
int _x0
Starting column (inclusive)
Definition: Span.h:129
A coordinate class intended to represent absolute positions.
int getWidth() const
Return the number of pixels.
Definition: Span.h:83
int getX0() const
Return the starting x-value.
Definition: Span.h:77
std::string toString() const
Return a string-representation of a Span.
friend std::ostream & operator<<(std::ostream &os, Span const &span)
Stream output; delegates to toString().
Definition: Span.h:104
A range of pixels within one row of an Image.
Definition: Span.h:54
bool operator!=(Span const &other) const
Definition: Span.h:109
Point< int, 2 > Point2I
Definition: Point.h:283
boost::shared_ptr< Span const > ConstPtr
Definition: Span.h:58
int const x0
Definition: saturated.cc:45
int getMinX() const
Minimum x-value.
Definition: Span.h:84
int & getX1()
Return the ending x-value.
Definition: Span.h:80
bool operator==(Span const &other) const
Definition: Span.h:106
Iterator begin() const
Return an iterator to the first pixel in the Span.
Definition: Span.h:72
int _x1
Ending column (inclusive)
Definition: Span.h:130
int getY() const
Return the y-value.
Definition: Span.h:81
int & getY()
Return the y-value.
Definition: Span.h:82
void shift(int dx, int dy)
Definition: Span.h:101
int _y
Row that Span&#39;s in.
Definition: Span.h:128
bool isEmpty() const
Return true if the span contains no pixels.
Definition: Span.h:96
bool contains(int x, int y) const
Definition: Span.h:92
double x
A set of pixels in an Image.
Definition: Footprint.h:62
boost::shared_ptr< Span > Ptr
Definition: Span.h:57
int getBeginX() const
Begin (inclusive) x-value.
Definition: Span.h:86
int & getX0()
Return the starting x-value.
Definition: Span.h:78
friend class boost::serialization::access
Definition: Span.h:120
lsst::afw::detection::Footprint Footprint
Definition: Source.h:61
bool contains(Point2I const &point) const
Definition: Span.h:93
afw::table::Key< double > b
Span()
Construct an empty Span with zero width at the origin.
Definition: Span.h:69
Point2I const getMax() const
Point corresponding to maximum x.
Definition: Span.h:89
int getX1() const
Return the ending x-value.
Definition: Span.h:79
SpanPixelIterator Iterator
An iterator over points in the Span.
Definition: Span.h:61
A coordinate class intended to represent offsets and dimensions.
void serialize(Archive &ar, const unsigned int version)
Definition: Span.h:122
Span(int y, int x0, int x1)
Definition: Span.h:63
Iterator end() const
Return an iterator to one past the last pixel in the Span.
Definition: Span.h:75
bool contains(int x) const
Definition: Span.h:91
bool operator<(const Span &b) const
Point2I const getMin() const
Point corresponding to minimum x.
Definition: Span.h:88