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 {
85 template <
typename T,
typename F>
86 void applyToImage(BoundedField
const &
field,
image::Image<T> &img, F functor,
bool overlapOnly) {
87 geom::Box2I region(field.getBBox());
91 throw LSST_EXCEPT(pex::exceptions::RuntimeError,
92 "Image bounding box does not match field bounding box");
94 for (
int y = region.getBeginY(), yEnd = region.getEndY(); y < yEnd; ++y) {
97 for (
int x = region.getBeginX(), xEnd = region.getEndX();
x < xEnd; ++
x, ++rowIter) {
98 functor(*rowIter, field.evaluate(
x, y));
105 std::shared_ptr<BoundedField>
operator*(
double const scale, std::shared_ptr<BoundedField const> bf) {
109 template <
typename T>
111 applyToImage(*
this, img, Assign(), overlapOnly);
114 template <
typename T>
116 applyToImage(*
this, img, ScaledAdd(scaleBy), overlapOnly);
119 template <
typename T>
121 applyToImage(*
this, img, Multiply(), overlapOnly);
124 template <
typename T>
126 applyToImage(*
this, img, Divide(), overlapOnly);
129 #define INSTANTIATE(T) \
130 template void BoundedField::fillImage(image::Image<T> &, bool) const; \
131 template void BoundedField::addToImage(image::Image<T> &, double, bool) const; \
132 template void BoundedField::multiplyImage(image::Image<T> &, bool) const; \
133 template void BoundedField::divideImage(image::Image<T> &, bool) const
x_iterator x_at(int x, int y) const
Return an x_iterator to the point (x, y) in the image.
void multiplyImage(image::Image< T > &image, bool overlapOnly=false) const
Multiply an image by the field in-place.
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.
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) const
Divide an image by the field in-place.
void fillImage(image::Image< T > &image, bool overlapOnly=false) const
Assign the field to an image, overwriting values already present.
std::shared_ptr< BoundedField > operator*(double const scale, std::shared_ptr< BoundedField const > bf)
A class to represent a 2-dimensional array of pixels.
void addToImage(image::Image< T > &image, double scaleBy=1.0, bool overlapOnly=false) const
Add the field or a constant multiple of it to an image in-place.
int getY0() const
Return the image's row-origin.