LSSTApplications  16.0+12,16.0+13,16.0-1-g16dcc35+1,16.0-1-g44ebaf5+1,16.0-1-g4515a79+10,16.0-1-g928b041+1,16.0-1-g943889d+1,16.0-1-g9884240+1,16.0-1-g98efed3+9,16.0-1-gce273f5+1,16.0-19-g2da375352+1,16.0-2-g568a347+8,16.0-2-g839ba83+2,16.0-2-g8827b2c+1,16.0-2-g934b51e+2,16.0-2-g9d5294e+1,16.0-3-g06ec41f+2,16.0-3-g30bbe86+2,16.0-3-g3806c63+1,16.0-3-g5dc86b7+2,16.0-3-gc6a11d1+2,16.0-4-g4dc7b79+2,16.0-4-g50d071e+1,16.0-4-gd6aeece+1,16.0-4-gedb2a3a+2,16.0-5-g0fa37f0+1,16.0-5-g188214f+1,16.0-5-g81851deb+3,16.0-5-gb866ac2+2,16.0-6-g44ca919+1,16.0-6-gce2b4a7+2,16.0-6-gf89f2d9+2,16.0-7-g1411911+2,16.0-7-g2664ab2+1,16.0-7-ge62bbd2a+2,16.0-8-g2ce35ff+2,16.0-8-g7a94e69+2,w.2018.29
LSSTDataManagementBasePackage
Frame.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 // $Id: frame.cc,v 1.2 2006/12/22 13:35:41 guy Exp $
3 //
4 //
5 //
6 // Last Modified: $Date: 2006/12/22 13:35:41 $
7 // By: $Author: guy $
8 //
9 #include <iostream>
10 
11 #include "lsst/jointcal/Frame.h"
12 
13 namespace lsst {
14 namespace jointcal {
15 
16 using namespace std;
17 
18 /****************** Frame class methods ***********************/
19 Frame::Frame(const Point &lowerLeft, const Point &upperRight) {
20  *this = Frame(lowerLeft.x, lowerLeft.y, upperRight.x, upperRight.y);
21 }
22 
23 Frame::Frame(double xmin, double ymin, double xmax, double ymax) {
24  xMin = min(xmin, xmax);
25  xMax = max(xmin, xmax);
26  yMin = min(ymin, ymax);
27  yMax = max(ymin, ymax);
28 }
29 
30 Frame::Frame() { xMin = xMax = yMin = yMax = 0; }
31 
32 /* positive if inside, negative if outside */
33 double Frame::minDistToEdges(const Point &point) const {
34  return min(min(point.x - xMin, xMax - point.x) /* minx */,
35  min(point.y - yMin, yMax - point.y) /* miny */);
36 }
37 
38 Frame Frame::operator*(const Frame &right) const {
39  Frame result = *this;
40  result *= right;
41  return result;
42 }
43 
44 Frame &Frame::operator*=(const Frame &right) {
45  Frame rightCopy = right;
46  // make sure that coordinates are properly ordered
47  order();
48  rightCopy.order();
49  xMin = max(xMin, rightCopy.xMin);
50  xMax = min(xMax, right.xMax);
51  yMin = max(yMin, right.yMin);
52  yMax = min(yMax, right.yMax);
53  // check for an actual overlap. Why was this check added?
54  if (xMin > xMax || yMin > yMax) *this = Frame();
55  return *this;
56 }
57 
58 Frame Frame::operator+(const Frame &right) const {
59  Frame result = *this;
60  result += right;
61  return result;
62 }
63 
64 Frame &Frame::operator+=(const Frame &right) {
65  Frame rightCopy = right;
66  // make sure that coordinates are properly ordered
67  order();
68  rightCopy.order();
69  xMin = min(xMin, rightCopy.xMin);
70  xMax = max(xMax, right.xMax);
71  yMin = min(yMin, right.yMin);
72  yMax = max(yMax, right.yMax);
73  return *this;
74 }
75 
76 void Frame::order() {
77  if (xMin > xMax) swap(xMin, xMax);
78  if (yMin > yMax) swap(yMin, yMax);
79 }
80 
81 bool Frame::operator==(const Frame &right) const {
82  return ((xMin == right.xMin) && (xMax == right.xMax) && (yMin == right.yMin) && (yMax == right.yMax));
83 }
84 
85 void Frame::cutMargin(const double marginX, const double marginY) {
86  xMin += marginX;
87  yMin += marginY;
88  xMax -= marginX;
89  yMax -= marginY;
90 }
91 
92 void Frame::cutMargin(const double marginSize) { cutMargin(marginSize, marginSize); }
93 
94 Frame Frame::rescale(const double factor) const {
95  double hxsize = fabs(factor * 0.5 * (xMax - xMin));
96  double xcenter = 0.5 * (xMax + xMin);
97  double hysize = fabs(factor * 0.5 * (yMax - yMin));
98  double ycenter = 0.5 * (yMax + yMin);
99  return Frame(xcenter - hxsize, ycenter - hysize, xcenter + hxsize, ycenter + hysize);
100 }
101 
102 double Frame::getArea() const { return fabs((xMax - xMin) * (yMax - yMin)); }
103 
104 bool Frame::inFrame(double x, double y) const {
105  return ((x <= xMax) && (y <= yMax) && (x >= xMin) && (y >= yMin));
106 }
107 
108 void Frame::dump(ostream &stream) const {
109  stream << "xmin ymin " << xMin << ' ' << yMin << " xmax ymax " << xMax << ' ' << yMax << endl;
110 }
111 } // namespace jointcal
112 } // namespace lsst
int xmax
Definition: SpanSet.cc:44
A point in a plane.
Definition: Point.h:13
double getArea() const
Definition: Frame.cc:102
Frame operator+(const Frame &right) const
union of Frames
Definition: Frame.cc:58
T endl(T... args)
py::object result
Definition: schema.cc:284
int y
Definition: SpanSet.cc:44
int min
Definition: Coord.cc:82
void cutMargin(const double marginSize)
shrinks the frame (if marginSize>0), enlarges it (if marginSize<0).
Definition: Frame.cc:92
STL namespace.
double xMin
coordinate of boundary.
Definition: Frame.h:18
Frame()
Default constructor.
Definition: Frame.cc:30
Frame rescale(const double factor) const
rescale it. The center does not move.
Definition: Frame.cc:94
double x
coordinate
Definition: Point.h:18
rectangle with sides parallel to axes.
Definition: Frame.h:15
void dump(std::ostream &stream=std::cout) const
Definition: Frame.cc:108
A base class for image defects.
Definition: cameraGeom.dox:3
int max
Definition: BoundedField.cc:98
int xmin
Definition: SpanSet.cc:44
double minDistToEdges(const Point &point) const
distance to closest boundary.
Definition: Frame.cc:33
T fabs(T... args)
double x
bool inFrame(double x, double y) const
inside?
Definition: Frame.cc:104
void swap(Image< PixelT > &a, Image< PixelT > &b)
Definition: Image.cc:473
Frame & operator*=(const Frame &right)
intersection of Frame&#39;s
Definition: Frame.cc:44
bool operator==(const Frame &right) const
necessary for comparisons (!= is defined from this one implicitely)
Definition: Frame.cc:81
Frame operator*(const Frame &right) const
intersection of Frame&#39;s.
Definition: Frame.cc:38
STL class.
Frame & operator+=(const Frame &right)
union of Frames
Definition: Frame.cc:64