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
Bounds.h
Go to the documentation of this file.
1 #ifndef MeasAlgoShapeletBounds_H
2 #define MeasAlgoShapeletBounds_H
3 
4 #include <vector>
5 #include <complex>
6 
7 namespace lsst {
8 namespace meas {
9 namespace algorithms {
10 namespace shapelet {
11 
12  class Position
13  {
14 
15  public:
16 
17  Position() : _z(0.,0.) {}
18 
19  Position(const Position& rhs) : _z(rhs._z) {}
20 
21  Position(const std::complex<double>& rhs) : _z(rhs) {}
22 
23  ~Position() {}
24 
25  Position(double x, double y) : _z(x,y) {}
26 
27  Position& operator=(const Position& rhs)
28  { _z = rhs._z; return *this; }
29 
30  Position& operator=(const std::complex<double>& rhs)
31  { _z=rhs; return *this; }
32 
33  operator std::complex<double>() { return _z; }
34 
35  std::complex<double> operator-(const Position& p2) const
36  { return _z - p2._z; }
37 
38  //std::complex<double> operator-(const std::complex<double>& z2) const
39  //{ return _z - z2; }
40 
41  Position& operator*=(double x)
42  { _z *= x; return *this; }
43 
44  Position& operator/=(double x)
45  { _z /= x; return *this; }
46 
47  Position& operator+=(const std::complex<double>& z2)
48  { _z += z2; return *this; }
49  Position operator+(const std::complex<double>& z2) const
50  { return Position(*this) += z2; }
51  Position& operator-=(const std::complex<double>& z2)
52  { _z -= z2; return *this; }
53  Position operator-(const std::complex<double>& z2) const
54  { return Position(*this) -= z2; }
55 
56  double getX() const { return(_z.real()); }
57 
58  double getY() const { return(_z.imag()); }
59 
60  void read(std::istream& fin);
61 
62  void write(std::ostream& fout) const;
63 
64  private :
65 
66  std::complex<double> _z;
67 
68  }; // Position
69 
70  inline std::complex<double> operator-(
71  const std::complex<double>& z1, const Position& p2)
72  { return (p2-z1); }
73 
74  inline std::complex<double> operator/(
75  const Position& p1, double x)
76  { Position p2 = p1; p2 /= x; return p2; }
77 
78  inline std::ostream& operator<<(std::ostream& os, const Position& pos)
79  { pos.write(os); return os; }
80 
81  inline std::istream& operator>>(std::istream& os, Position& pos)
82  { pos.read(os); return os; }
83 
84  class Bounds
85  {
86  // Basically just a rectangle. This is used to keep track of the bounds of
87  // catalogs and fields. You can set values, but generally you just keep
88  // including positions of each galaxy or the bounds of each catalog
89  // respectively using the += operators
90 
91  public:
92 
93  Bounds(double x1, double x2, double y1, double y2) :
94  _isDefined(true),_xMin(x1),_xMax(x2),_yMin(y1),_yMax(y2) {}
95 
96  Bounds(const Position& pos) :
97  _isDefined(true), _xMin(pos.getX()), _xMax(pos.getX()),
98  _yMin(pos.getY()), _yMax(pos.getY()) {}
99 
100  Bounds(): _isDefined(false),_xMin(0.),_xMax(0.),_yMin(0.),_yMax(0.) {}
101 
102  ~Bounds() {}
103 
104  void setXMin(double x) { _xMin = x; _isDefined = true; }
105 
106  void setXMax(double x) { _xMax = x; _isDefined = true; }
107 
108  void setYMin(double y) { _yMin = y; _isDefined = true; }
109 
110  void setYMax(double y) { _yMax = y; _isDefined = true; }
111 
112  double getXMin() const { return _xMin; }
113 
114  double getXMax() const { return _xMax; }
115 
116  double getYMin() const { return _yMin; }
117 
118  double getYMax() const { return _yMax; }
119 
120  bool isDefined() const { return _isDefined; }
121 
122  Position getCenter() const;
123 
124  void operator+=(const Position& pos);
125 
126  void operator+=(const Bounds& rec);
127 
128  bool operator==(const Bounds& rhs) const;
129 
130  void snap(double d);
131 
132  void addBorder(double d);
133 
134  void addXBorder(double d);
135 
136  void addYBorder(double d);
137 
138  Bounds operator&(const Bounds& rhs) const; // Finds intersection
139 
140  bool includes(const Position& pos) const;
141 
142  bool includes(double x, double y) const;
143 
144  bool includes(const Bounds& b2) const;
145 
146  bool intersects(const Bounds& b2) const;
147 
148  double getArea() const;
149 
150  std::vector<Bounds> quarter() const;
151 
152  std::vector<Bounds> divide(int nx, int ny) const;
153 
154  void write(std::ostream& fout) const;
155 
156  void read(std::istream& fin);
157 
158  Position get00() const { return Position(_xMin,_yMin); }
159 
160  Position get01() const { return Position(_xMin,_yMax); }
161 
162  Position get10() const { return Position(_xMax,_yMin); }
163 
164  Position get11() const { return Position(_xMax,_yMax); }
165 
166  bool isWide() const { return (_xMax-_xMin > _yMax-_yMin); }
167 
168  bool isTall() const { return (_xMax-_xMin < _yMax-_yMin); }
169 
170  private:
171 
174 
175  };
176 
177  inline std::ostream& operator<<(std::ostream& fout, const Bounds& b)
178  { b.write(fout); return fout;}
179 
180  inline std::istream& operator>>(std::istream& fin, Bounds& b)
181  { b.read(fin); return fin;}
182 
183 
184 }}}}
185 
186 #endif
int y
std::vector< Bounds > divide(int nx, int ny) const
Definition: Bounds.cc:152
Position & operator=(const std::complex< double > &rhs)
Definition: Bounds.h:30
bool operator==(const Bounds &rhs) const
Definition: Bounds.cc:70
void operator+=(const Position &pos)
Definition: Bounds.cc:40
Bounds(double x1, double x2, double y1, double y2)
Definition: Bounds.h:93
std::vector< Bounds > quarter() const
Definition: Bounds.cc:149
void read(std::istream &fin)
Definition: Bounds.cc:34
Position operator+(const std::complex< double > &z2) const
Definition: Bounds.h:49
std::ostream & operator<<(std::ostream &os, const Position &pos)
Definition: Bounds.h:78
std::complex< double > operator-(const std::complex< double > &z1, const Position &p2)
Definition: Bounds.h:70
Position operator-(const std::complex< double > &z2) const
Definition: Bounds.h:53
bool intersects(const Bounds &b2) const
Definition: Bounds.cc:136
void write(std::ostream &fout) const
Definition: Bounds.cc:170
Position & operator-=(const std::complex< double > &z2)
Definition: Bounds.h:51
void write(std::ostream &fout) const
Definition: Bounds.cc:37
std::complex< double > operator/(const Position &p1, double x)
Definition: Bounds.h:74
double x
bool includes(const Position &pos) const
Definition: Bounds.cc:118
Bounds operator&(const Bounds &rhs) const
Definition: Bounds.cc:83
Position & operator=(const Position &rhs)
Definition: Bounds.h:27
Position(const std::complex< double > &rhs)
Definition: Bounds.h:21
std::istream & operator>>(std::istream &os, Position &pos)
Definition: Bounds.h:81
Position & operator+=(const std::complex< double > &z2)
Definition: Bounds.h:47
std::complex< double > operator-(const Position &p2) const
Definition: Bounds.h:35
afw::table::Key< double > b
void read(std::istream &fin)
Definition: Bounds.cc:173