LSSTApplications  18.1.0
LSSTDataManagementBasePackage
PixelRegion.cc
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 #include <cmath>
27 
28 namespace lsst {
29 namespace afw {
30 namespace geom {
31 namespace ellipses {
32 
34  : _center(ellipse.getCenter()), _bbox(ellipse.computeBBox(), lsst::geom::Box2I::EXPAND) {
35  Quadrupole::Matrix q = Quadrupole(ellipse.getCore()).getMatrix();
36  _detQ = q(0, 0) * q(1, 1) - q(0, 1) * q(0, 1);
37  _invQxx = q(1, 1) / _detQ;
38  _alpha = q(0, 1) / _detQ / _invQxx; // == -invQxy / invQxx
39  if (std::isnan(_alpha)) {
40  _alpha = 0.0;
41  }
42 }
43 
44 Span const PixelRegion::getSpanAt(int y) const {
45  double yt = y - _center.getY();
46  double d = _invQxx - yt * yt / _detQ;
47  double x0 = _center.getX() + yt * _alpha;
48  double x1 = x0;
49  if (d > 0.0) {
50  d = std::sqrt(d) / _invQxx;
51  x0 -= d;
52  x1 += d;
53  } // Note that we return an empty span when d <= 0.0 or d is NaN.
54  return Span(y, std::ceil(x0), std::floor(x1));
55 }
56 } // namespace ellipses
57 } // namespace geom
58 } // namespace afw
59 } // namespace lsst
An ellipse core with quadrupole moments as parameters.
Definition: Quadrupole.h:47
T ceil(T... args)
A range of pixels within one row of an Image.
Definition: Span.h:47
int y
Definition: SpanSet.cc:49
BaseCore const & getCore() const
Return the ellipse core.
Definition: Ellipse.h:71
T floor(T... args)
A base class for image defects.
An ellipse defined by an arbitrary BaseCore and a center point.
Definition: Ellipse.h:51
Eigen::Matrix< double, 2, 2, Eigen::DontAlign > Matrix
Matrix type for the matrix representation of Quadrupole parameters.
Definition: Quadrupole.h:52
PixelRegion(Ellipse const &ellipse)
Definition: PixelRegion.cc:33
T isnan(T... args)
T sqrt(T... args)
Span const getSpanAt(int y) const
Definition: PixelRegion.cc:44
An integer coordinate rectangle.
Definition: Box.h:54