34 namespace algorithms {
38 inline double min4(
double a,
double b,
double c,
double d) {
42 inline double max4(
double a,
double b,
double c,
double d) {
49 int nx = im.getWidth();
50 int ny = im.getHeight();
53 out = std::make_shared<afw::detection::Psf::Image>(nx + 2 * xPad, ny + 2 * yPad);
54 out->setXY0(im.getX0() - xPad, im.getY0() - yPad);
62 geom::Box2I computeBBoxFromTransform(geom::Box2I
const bbox, geom::AffineTransform
const &t) {
63 static const int dst_padding = 0;
69 static const double maxTransformCoeff = 200.0;
71 if (t.getLinear().getMatrix().lpNorm<Eigen::Infinity>() > maxTransformCoeff) {
72 throw LSST_EXCEPT(pex::exceptions::RangeError,
"Unexpectedly large transform passed to WarpedPsf");
76 int in_xlo =
bbox.getMinX();
77 int in_xhi =
bbox.getMinX() +
bbox.getWidth() - 1;
78 int in_ylo =
bbox.getMinY();
79 int in_yhi =
bbox.getMinY() +
bbox.getHeight() - 1;
90 int out_xlo =
floor(min4(c00.getX(), c01.getX(), c10.getX(), c11.getX())) - dst_padding;
91 int out_ylo =
floor(min4(c00.getY(), c01.getY(), c10.getY(), c11.getY())) - dst_padding;
92 int out_xhi =
ceil(max4(c00.getX(), c01.getX(), c10.getX(), c11.getX())) + dst_padding;
93 int out_yhi =
ceil(max4(c00.getY(), c01.getY(), c10.getY(), c11.getY())) + dst_padding;
95 geom::Box2I ret = geom::Box2I(
geom::Point2I(out_xlo, out_ylo),
115 afw::math::WarpingControl
const &wc) {
119 afw::math::SeparableKernel
const &kernel = *wc.getWarpingKernel();
121 int const xPad =
std::max(center.getX(), kernel.getWidth() - center.getX());
122 int const yPad =
std::max(center.getY(), kernel.getHeight() - center.getY());
125 geom::Box2I
bbox = computeBBoxFromTransform(im.getBBox(), srcToDest);
142 _undistortedPsf(undistortedPsf),
143 _distortion(distortion),
144 _warpingControl(control) {
152 _undistortedPsf(undistortedPsf),
153 _distortion(distortion),
154 _warpingControl(new afw::math::WarpingControl(kernelName,
"", cache)) {
158 void WarpedPsf::_init() {
161 "Undistorted Psf passed to WarpedPsf must not be None/NULL");
166 if (!_warpingControl) {
168 "WarpingControl passed to WarpedPsf must not be None/NULL");
188 WarpedPsf::doComputeKernelImage(geom::
Point2D const &position, afw::image::Color const &color)
const {
192 PTR(
Image) im = _undistortedPsf->computeKernelImage(tp, color);
196 PTR(afw::detection::Psf::Psf::Image) ret = warpAffine(*im, srcToDest, *_warpingControl);
198 double normFactor = 1.0;
204 for (
int y = 0;
y != ret->getHeight(); ++
y) {
207 normFactor += *imPtr;
210 if (normFactor == 0.0) {