37 ndarray::Array<double, 1, 1> BoundedField::evaluate(ndarray::Array<double const, 1>
const &
x,
38 ndarray::Array<double const, 1>
const &
y)
const {
39 ndarray::Array<double, 1, 1> out = ndarray::allocate(x.getSize<0>());
40 for (
int i = 0, n = x.getSize<0>(); i < n; ++i) {
41 out[i] = evaluate(x[i], y[i]);
60 void operator()(T &out,
double a)
const {
66 explicit ScaledAdd(
double s) :
scaleBy(s) {}
69 void operator()(T &out,
double a)
const {
78 void operator()(T &out,
double a)
const {
85 void operator()(T &out,
double a)
const {
109 explicit Bounds(
int step_) : step(step_), min(0), max(0), end(0) {}
112 void reset(
int min_) {
134 template <
typename T,
typename F>
137 while (_y.end < _region->
getEndY()) {
138 _runRow(img, functor);
146 _runRow(img, functor);
152 template <
typename T,
typename F>
155 _z00 = _field->evaluate(_x.min, _y.min);
156 _z01 = _field->evaluate(_x.min, _y.max);
157 while (_x.max < _region->
getEndX()) {
158 _z10 = _field->evaluate(_x.max, _y.min);
159 _z11 = _field->evaluate(_x.max, _y.max);
160 _runCell(img, functor);
170 _z10 = _field->evaluate(_x.max, _y.min);
171 _z11 = _field->evaluate(_x.max, _y.max);
172 _runCell(img, functor);
180 template <
typename T,
typename F>
182 int dy = _y.max - _y.min;
183 int dx = _x.max - _x.min;
190 auto rowIter = img.
x_at(_x.min - img.
getX0(), _y.min - img.
getY0());
192 functor(*rowIter, _z00);
195 for (
int x = _x.min + 1;
x < _x.end; ++
x, ++rowIter) {
196 functor(*rowIter, ((_x.max -
x) * _z00 + (
x - _x.min) * _z10) / dx);
199 for (
int y = _y.min + 1;
y < _y.end; ++
y) {
201 double z0 = ((_y.max -
y) * _z00 + (
y - _y.min) * _z01) / dy;
202 double z1 = ((_y.max -
y) * _z10 + (
y - _y.min) * _z11) / dy;
204 functor(*rowIter, z0);
207 for (
int x = _x.min + 1;
x < _x.end; ++
x, ++rowIter) {
208 functor(*rowIter, ((_x.max -
x) * z0 + (
x - _x.min) * z1) / dx);
213 BoundedField
const *_field;
217 double _z00, _z01, _z10, _z11;
222 template <
typename T,
typename F>
223 void applyToImage(BoundedField
const &
field,
image::Image<T> &img, F functor,
bool overlapOnly,
int xStep,
230 "Image bounding box does not match field bounding box");
233 if (yStep > 1 || xStep > 1) {
234 Interpolator interpolator(&field, ®ion, xStep, yStep);
235 interpolator.run(img, functor);
237 for (
int y = region.getBeginY(), yEnd = region.getEndY();
y < yEnd; ++
y) {
238 auto rowIter = img.
x_at(region.getBeginX() - img.
getX0(),
y - img.
getY0());
239 for (
int x = region.getBeginX(), xEnd = region.getEndX();
x < xEnd; ++
x, ++rowIter) {
240 functor(*rowIter, field.evaluate(
x,
y));
252 template <
typename T>
253 void BoundedField::fillImage(
image::Image<T> &img,
bool overlapOnly,
int xStep,
int yStep)
const {
254 applyToImage(*
this, img, Assign(), overlapOnly, xStep, yStep);
257 template <
typename T>
260 applyToImage(*
this, img, ScaledAdd(scaleBy), overlapOnly, xStep, yStep);
263 template <
typename T>
264 void BoundedField::multiplyImage(
image::Image<T> &img,
bool overlapOnly,
int xStep,
int yStep)
const {
265 applyToImage(*
this, img, Multiply(), overlapOnly, xStep, yStep);
268 template <
typename T>
269 void BoundedField::divideImage(
image::Image<T> &img,
bool overlapOnly,
int xStep,
int yStep)
const {
270 applyToImage(*
this, img, Divide(), overlapOnly, xStep, yStep);
273 #define INSTANTIATE(T) \ 274 template void BoundedField::fillImage(image::Image<T> &, bool, int, int) const; \ 275 template void BoundedField::addToImage(image::Image<T> &, double, bool, int, int) const; \ 276 template void BoundedField::multiplyImage(image::Image<T> &, bool, int, int) const; \ 277 template void BoundedField::divideImage(image::Image<T> &, bool, int, int) const
std::shared_ptr< Image< PixelT > > operator*(Image< PixelT > const &img, ImageSlice< PixelT > const &slc)
Overload operator*()
def scale(algorithm, min, max=None, frame=None)
static std::shared_ptr< T > dynamicCast(std::shared_ptr< Persistable > const &ptr)
Dynamically cast a shared_ptr.
int getX0() const
Return the image's column-origin.
int getEndY() const noexcept
int getBeginY() const noexcept
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
#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.
A class to represent a 2-dimensional array of pixels.
UnaryFunctionT::result_type integrate(UnaryFunctionT func, typename UnaryFunctionT::argument_type const a, typename UnaryFunctionT::argument_type const b, double eps=1.0e-6)
The 1D integrator.