LSSTApplications  11.0-24-g0a022a1,14.0+77,15.0,15.0+1
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
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)
int min
Definition: Coord.cc:160
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:22
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:19
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:99
double x
double minDistToEdges(const Point &point) const
distance to closest boundary.
Definition: Frame.cc:33
T fabs(T... args)
bool inFrame(double x, double y) const
inside?
Definition: Frame.cc:104
void swap(Image< PixelT > &a, Image< PixelT > &b)
Definition: Image.cc:458
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