25 #include "lsst/pex/exceptions.h"
33 ndarray::Array<double const, 1>
const &y)
const {
34 ndarray::Array<double, 1, 1> out = ndarray::allocate(x.getSize<0>());
35 for (
int i = 0,
n = x.getSize<0>(); i <
n; ++i) {
43 double BoundedField::mean()
const {
throw LSST_EXCEPT(pex::exceptions::LogicError,
"Not Implemented"); }
55 void operator()(T &out,
double a)
const {
61 explicit ScaledAdd(
double s) :
scaleBy(s) {}
64 void operator()(T &out,
double a)
const {
73 void operator()(T &out,
double a)
const {
80 void operator()(T &out,
double a)
const {
105 explicit Bounds(
int step_) :
step(step_),
min(0),
max(0),
end(0) {}
108 void reset(
int min_) {
117 BoundedField
const *
field,
118 geom::Box2I
const * region,
126 _z00(std::numeric_limits<double>::quiet_NaN()),
127 _z01(std::numeric_limits<double>::quiet_NaN()),
128 _z10(std::numeric_limits<double>::quiet_NaN()),
129 _z11(std::numeric_limits<double>::quiet_NaN())
136 template <
typename T,
typename F>
140 _runRow(img, functor);
148 _runRow(img, functor);
155 template <
typename T,
typename F>
163 _runCell(img, functor);
175 _runCell(img, functor);
183 template <
typename T,
typename F>
185 int dy =
_y.max -
_y.min;
186 int dx =
_x.max -
_x.min;
196 functor(*rowIter,
_z00);
199 for (
int x =
_x.min + 1;
x <
_x.end; ++
x, ++rowIter) {
203 for (
int y =
_y.min + 1; y <
_y.end; ++y) {
209 functor(*rowIter, z0);
212 for (
int x =
_x.min + 1;
x <
_x.end; ++
x, ++rowIter) {
213 functor(*rowIter, ((
_x.max -
x)*z0 + (
x -
_x.min)*z1)/dx);
228 template <
typename T,
typename F>
229 void applyToImage(BoundedField
const &
field,
image::Image<T> &img, F functor,
bool overlapOnly,
int xStep,
231 geom::Box2I region(field.getBBox());
235 throw LSST_EXCEPT(pex::exceptions::RuntimeError,
236 "Image bounding box does not match field bounding box");
239 if (yStep > 1 || xStep > 1) {
240 Interpolator interpolator(&field, ®ion, xStep, yStep);
241 interpolator.run(img, functor);
243 for (
int y = region.getBeginY(), yEnd=region.getEndY(); y < yEnd; ++y) {
244 auto rowIter = img.
x_at(region.getBeginX() - img.
getX0(), y - img.
getY0());
245 for (
int x = region.getBeginX(), xEnd=region.getEndX();
x < xEnd; ++
x, ++rowIter) {
246 functor(*rowIter, field.evaluate(
x, y));
254 std::shared_ptr<BoundedField>
operator*(
double const scale, std::shared_ptr<BoundedField const> bf) {
258 template <
typename T>
260 applyToImage(*
this, img, Assign(), overlapOnly, xStep, yStep);
263 template <
typename T>
265 int xStep,
int yStep)
const {
266 applyToImage(*
this, img, ScaledAdd(scaleBy), overlapOnly, xStep, yStep);
269 template <
typename T>
271 applyToImage(*
this, img, Multiply(), overlapOnly, xStep, yStep);
274 template <
typename T>
276 applyToImage(*
this, img, Divide(), overlapOnly, xStep, yStep);
279 #define INSTANTIATE(T) \
280 template void BoundedField::fillImage(image::Image<T> &, bool, int, int) const; \
281 template void BoundedField::addToImage(image::Image<T> &, double, bool, int, int) const; \
282 template void BoundedField::multiplyImage(image::Image<T> &, bool, int, int) const; \
283 template void BoundedField::divideImage(image::Image<T> &, bool, int, int) const
x_iterator x_at(int x, int y) const
Return an x_iterator to the point (x, y) in the image.
void fillImage(image::Image< T > &image, bool overlapOnly=false, int xStep=1, int yStep=1) const
Assign the field to an image, overwriting values already present.
virtual double evaluate(geom::Point2D const &position) const =0
Evaluate the field at the given point.
virtual double integrate() const
Compute the integral of this function over its bounding-box.
void addToImage(image::Image< T > &image, double scaleBy=1.0, bool overlapOnly=false, int xStep=1, int yStep=1) const
Add the field or a constant multiple of it to an image in-place.
geom::Box2I getBBox(ImageOrigin origin=PARENT) const
virtual double mean() const
Compute the mean of this function over its bounding-box.
int getX0() const
Return the image's column-origin.
void divideImage(image::Image< T > &image, bool overlapOnly=false, int xStep=1, int yStep=1) const
Divide an image by the field in-place.
metadata import lsst afw display as afwDisplay n
void multiplyImage(image::Image< T > &image, bool overlapOnly=false, int xStep=1, int yStep=1) const
Multiply an image by the field in-place.
std::shared_ptr< BoundedField > operator*(double const scale, std::shared_ptr< BoundedField const > bf)
BoundedField const * _field
geom::Box2I const * _region
A class to represent a 2-dimensional array of pixels.
int getY0() const
Return the image's row-origin.