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 {
105 explicit Bounds(
int step_) : step(step_), min(0), max(0), end(0) {}
108 void reset(
int min_) {
118 geom::Box2I
const * region,
136 template <
typename T,
typename F>
138 _y.reset(_region->getBeginY());
139 while (_y.end < _region->getEndY()) {
140 _runRow(img, functor);
146 _y.max = _region->getMaxY();
147 _y.end = _region->getEndY();
148 _runRow(img, functor);
155 template <
typename T,
typename F>
157 _x.reset(_region->getBeginX());
158 _z00 = _field->evaluate(_x.min, _y.min);
159 _z01 = _field->evaluate(_x.min, _y.max);
160 while (_x.max < _region->getEndX()) {
161 _z10 = _field->evaluate(_x.max, _y.min);
162 _z11 = _field->evaluate(_x.max, _y.max);
163 _runCell(img, functor);
171 _x.max = _region->getMaxX();
172 _x.end = _region->getEndX();
173 _z10 = _field->evaluate(_x.max, _y.min);
174 _z11 = _field->evaluate(_x.max, _y.max);
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) {
200 functor(*rowIter, ((_x.max -
x)*_z00 + (
x - _x.min)*_z10)/dx);
203 for (
int y = _y.min + 1; y < _y.end; ++y) {
206 double z0 = ((_y.max - y)*_z00 + (y - _y.min)*_z01)/dy;
207 double z1 = ((_y.max - y)*_z10 + (y - _y.min)*_z11)/dy;
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);
219 geom::Box2I
const * _region;
222 double _z00, _z01, _z10, _z11;
228 template <
typename T,
typename F>
231 geom::Box2I region(field.getBBox());
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));
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
geom::Box2I getBBox(ImageOrigin origin=PARENT) const
virtual double mean() const
Compute the mean of this function over its bounding-box.
virtual double evaluate(geom::Point2D const &position) const =0
Evaluate the field at the given point.
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.
void multiplyImage(image::Image< T > &image, bool overlapOnly=false, int xStep=1, int yStep=1) const
Multiply an image by the field in-place.
BoundedField(BoundedField const &)=default
A base class for image defects.
def run(suite, exit=True)
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.
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.
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.