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) {
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 {
104 explicit Bounds(
int step_) : step(step_), min(0), max(0), end(0) {}
107 void reset(
int min_) {
129 template <
typename T,
typename F>
132 while (_y.end < _region->
getEndY()) {
133 _runRow(img, functor);
141 _runRow(img, functor);
147 template <
typename T,
typename F>
150 _z00 = _field->evaluate(_x.min, _y.min);
151 _z01 = _field->evaluate(_x.min, _y.max);
152 while (_x.max < _region->
getEndX()) {
153 _z10 = _field->evaluate(_x.max, _y.min);
154 _z11 = _field->evaluate(_x.max, _y.max);
155 _runCell(img, functor);
165 _z10 = _field->evaluate(_x.max, _y.min);
166 _z11 = _field->evaluate(_x.max, _y.max);
167 _runCell(img, functor);
175 template <
typename T,
typename F>
177 int dy = _y.max - _y.min;
178 int dx = _x.max - _x.min;
185 auto rowIter = img.
x_at(_x.min - img.
getX0(), _y.min - img.
getY0());
187 functor(*rowIter, _z00);
190 for (
int x = _x.min + 1;
x < _x.end; ++
x, ++rowIter) {
191 functor(*rowIter, ((_x.max -
x) * _z00 + (
x - _x.min) * _z10) / dx);
194 for (
int y = _y.min + 1;
y < _y.end; ++
y) {
196 double z0 = ((_y.max -
y) * _z00 + (
y - _y.min) * _z01) / dy;
197 double z1 = ((_y.max -
y) * _z10 + (
y - _y.min) * _z11) / dy;
199 functor(*rowIter, z0);
202 for (
int x = _x.min + 1;
x < _x.end; ++
x, ++rowIter) {
203 functor(*rowIter, ((_x.max -
x) * z0 + (
x - _x.min) * z1) / dx);
212 double _z00, _z01, _z10, _z11;
217 template <
typename T,
typename F>
225 "Image bounding box does not match field bounding box");
228 if (yStep > 1 || xStep > 1) {
229 Interpolator interpolator(&field, ®ion, xStep, yStep);
230 interpolator.run(img, functor);
232 for (
int y = region.getBeginY(), yEnd = region.getEndY();
y < yEnd; ++
y) {
233 auto rowIter = img.
x_at(region.getBeginX() - img.
getX0(),
y - img.
getY0());
234 for (
int x = region.getBeginX(), xEnd = region.getEndX();
x < xEnd; ++
x, ++rowIter) {
235 functor(*rowIter, field.evaluate(
x,
y));
247 template <
typename T>
249 applyToImage(*
this, img, Assign(), overlapOnly, xStep, yStep);
252 template <
typename T>
255 applyToImage(*
this, img, ScaledAdd(scaleBy), overlapOnly, xStep, yStep);
258 template <
typename T>
260 applyToImage(*
this, img, Multiply(), overlapOnly, xStep, yStep);
263 template <
typename T>
265 applyToImage(*
this, img, Divide(), overlapOnly, xStep, yStep);
268 #define INSTANTIATE(T) \ 269 template void BoundedField::fillImage(image::Image<T> &, bool, int, int) const; \ 270 template void BoundedField::addToImage(image::Image<T> &, double, bool, int, int) const; \ 271 template void BoundedField::multiplyImage(image::Image<T> &, bool, int, int) const; \ 272 template void BoundedField::divideImage(image::Image<T> &, bool, int, int) const
virtual double mean() const
Compute the mean of this function over its bounding-box.
virtual std::shared_ptr< BoundedField > operator*(double const scale) const =0
Return a scaled BoundedField.
def scale(algorithm, min, max=None, frame=None)
int getX0() const
Return the image's column-origin.
int getEndY() const noexcept
void multiplyImage(image::Image< T > &image, bool overlapOnly=false, int xStep=1, int yStep=1) const
Multiply an image by the field in-place.
int getBeginY() const noexcept
BoundedField(BoundedField const &)=default
A base class for image defects.
lsst::geom::Box2I getBBox(ImageOrigin origin=PARENT) const
int getMaxY() const noexcept
int getBeginX() const noexcept
def run(suite, exit=True)
int getMaxX() const noexcept
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.
#define LSST_EXCEPT(type,...)
int getY0() const
Return the image's row-origin.
int getEndX() const noexcept
void clip(Box2I const &other) noexcept
x_iterator x_at(int x, int y) const
Return an x_iterator to the point (x, y) in the image.
void divideImage(image::Image< T > &image, bool overlapOnly=false, int xStep=1, int yStep=1) const
Divide an image by the field in-place.
virtual double evaluate(lsst::geom::Point2D const &position) const =0
Evaluate the field at the given point.
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.
A class to represent a 2-dimensional array of pixels.
virtual double integrate() const
Compute the integral of this function over its bounding-box.