23#if !defined(LSST_AFW_IMAGE_PIXEL_H)
24#define LSST_AFW_IMAGE_PIXEL_H
38template <
typename,
typename,
typename,
typename,
typename>
72template <
typename _ImagePixelT,
typename _MaskPixelT,
typename _VariancePixelT =
double>
75 template <
typename,
typename,
typename>
87 template <
typename rhsExpr>
91 typename std::enable_if_t<!std::is_fundamental_v<rhsExpr>,
void*> =
nullptr)
104 : _image(
std::numeric_limits<_ImagePixelT>::has_quiet_NaN
105 ?
std::numeric_limits<_ImagePixelT>::quiet_NaN()
108 _variance(
std::numeric_limits<_VariancePixelT>::has_quiet_NaN
109 ?
std::numeric_limits<_VariancePixelT>::quiet_NaN()
118template <
typename PixelT>
133template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
140template <
typename _ImagePixelT,
typename _MaskPixelT,
typename _VariancePixelT =
double>
157 : _image(rhs._image), _mask(rhs._mask), _variance(rhs._variance) {}
166 _image = rhs.
image();
176 template <
typename rhsExpr>
178 _variance = rhs.variance();
179 _image = rhs.image();
216 template <
typename T1,
typename T2,
typename T3>
220 template <
typename T1,
typename T2,
typename T3>
226 template <
typename T1>
228 return !(lhs == rhs);
243 template <
typename ExprT>
252 template <
typename ExprT>
261 template <
typename ExprT>
270 template <
typename ExprT>
285template <
typename ExprT>
330template <
typename T1>
340template <
typename T1>
351template <
typename T1>
353 T1
operator()(T1
const&
x, T1
const&
y, T1
const& vx, T1
const& vy)
const {
356 T1
const iy2 = 1.0 / y2;
357 return x2 * vy * iy2 * iy2 + vx * iy2;
360 T1
operator()(T1
const&, T1
const&
y, T1
const& vx)
const {
return vx / (
y *
y); }
368template <
typename T1>
370 T1
operator()(T1
const&
x, T1
const&
y, T1
const& vx, T1
const& vy)
const {
373 return x2 * vy + y2 * vx;
376 T1
operator()(T1
const&, T1
const&
y, T1
const& vx)
const {
return vx *
y *
y; }
384template <
typename T1>
386 T1
operator()(T1
const&, T1
const&, T1
const& vx, T1
const& vy)
const {
return vx + vy; }
388 T1
operator()(T1
const&, T1
const&, T1
const& vx)
const {
return vx; }
392template <
typename ExprT1,
typename ImageBinOp,
typename MaskBinOp,
typename VarianceBinOp>
399 UnaryExpr(ExprT1 e1, ImageBinOp imageOp = ImageBinOp(), MaskBinOp maskOp = MaskBinOp(),
400 VarianceBinOp varOp = VarianceBinOp())
401 : _expr1(e1), _imageOp(imageOp), _maskOp(maskOp), _varOp(varOp) {}
416 VarianceBinOp _varOp;
420template <
typename ExprT1,
typename ExprT2,
typename ImageBinOp,
typename MaskBinOp,
typename VarianceBinOp>
427 BinaryExpr(ExprT1 e1, ExprT2 e2, ImageBinOp imageOp = ImageBinOp(), MaskBinOp maskOp = MaskBinOp(),
428 VarianceBinOp varOp = VarianceBinOp())
429 : _expr1(e1), _expr2(e2), _imageOp(imageOp), _maskOp(maskOp), _varOp(varOp) {}
433 BinaryExpr(ExprT1 e1, ExprT2 e2,
double const alpha, ImageBinOp imageOp = ImageBinOp(),
434 MaskBinOp maskOp = MaskBinOp(), VarianceBinOp = VarianceBinOp())
435 : _expr1(e1), _expr2(e2), _imageOp(imageOp), _maskOp(maskOp), _varOp(VarianceBinOp(alpha)) {}
444 return _varOp(_expr1.image(), _expr2.image(), _expr1.variance(), _expr2.variance());
452 VarianceBinOp _varOp;
459template <
typename ExprT1,
typename ImageBinOp,
typename MaskBinOp,
typename VarianceBinOp>
460class BinaryExpr<ExprT1, double, ImageBinOp, MaskBinOp, VarianceBinOp> final {
466 BinaryExpr(ExprT1 e1,
double e2, ImageBinOp imageOp = ImageBinOp(), MaskBinOp maskOp = MaskBinOp(),
467 VarianceBinOp varOp = VarianceBinOp())
468 : _expr1(e1), _expr2(e2), _imageOp(imageOp), _maskOp(maskOp), _varOp(varOp) {}
472 BinaryExpr(ExprT1 e1,
double e2,
double const alpha, ImageBinOp imageOp = ImageBinOp(),
473 MaskBinOp maskOp = MaskBinOp(), VarianceBinOp = VarianceBinOp())
474 : _expr1(e1), _expr2(e2), _imageOp(imageOp), _maskOp(maskOp), _varOp(VarianceBinOp(alpha)) {}
489 VarianceBinOp _varOp;
493template <
typename ExprT1>
502template <
class T,
template <
class...>
class Template>
505template <
template <
class...>
class Template,
class... Args>
510 std::is_floating_point_v<T> ||
512 is_specialization<T, SinglePixel>{} ||
513 is_specialization<T, Pixel>{};
514template <
typename T1,
typename T2>
517template <
typename T1,
typename T2>
520template <
typename ExprT1,
typename ExprT2,
typename = val
id_operands<ExprT1, ExprT2>>
528template <
typename ExprT1,
typename ExprT2,
typename = val
id_operands<ExprT1, ExprT2>>
540template <
typename ExprT1,
typename ExprT2,
typename = val
id_operands<ExprT1, ExprT2>>
541ExprT1 doPlus(ExprT1 e1, ExprT2 e2,
double const, boost::mpl::true_) {
548template <
typename ExprT1,
typename ExprT2,
typename = val
id_operands<ExprT1, ExprT2>>
559template <
typename ExprT1,
typename ExprT2,
typename = val
id_operands<ExprT1, ExprT2>>
560BinaryExpr<ExprT1, ExprT2, std::minus<typename exprTraits<ExprT1>::ImagePixelT>,
561 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
562 variance_plus<typename exprTraits<ExprT1>::VariancePixelT> >
570template <
typename ExprT1,
typename ExprT2,
typename = val
id_operands<ExprT1, ExprT2>>
580template <
typename ExprT1,
typename ExprT2,
typename = val
id_operands<ExprT1, ExprT2>>
581BinaryExpr<ExprT1, ExprT2, std::multiplies<typename exprTraits<ExprT1>::ImagePixelT>,
582 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
583 variance_multiplies<typename exprTraits<ExprT1>::VariancePixelT> >
591template <
typename ExprT1,
typename ExprT2,
typename = val
id_operands<ExprT1, ExprT2>>
601template <
typename ExprT1,
typename ExprT2,
typename = val
id_operands<ExprT1, ExprT2>>
602BinaryExpr<ExprT1, ExprT2, std::divides<typename exprTraits<ExprT1>::ImagePixelT>,
603 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
604 variance_divides<typename exprTraits<ExprT1>::VariancePixelT> >
612template <
typename ExprT1,
typename ExprT2,
typename = val
id_operands<ExprT1, ExprT2>>
621template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
623 return os <<
"(" << v.
image() <<
", " << v.
mask() <<
", " << v.
variance() <<
")";
627template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
629 return os <<
"(" << v.
image() <<
", " << v.
mask() <<
", " << v.
variance() <<
")";
633template <
typename ExprT1,
typename ExprT2,
typename BinOp,
typename MaskBinOp,
typename VarBinOp>
635 return os <<
"(" << v.
image() <<
", " << v.
mask() <<
", " << v.
variance() <<
")";
643template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
644struct hash<
lsst::afw::image::pixel::Pixel<ImagePixelT, MaskPixelT, VariancePixelT>> {
655template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
656struct hash<
lsst::afw::image::pixel::SinglePixel<ImagePixelT, MaskPixelT, VariancePixelT>> {
663 ImagePixelT
image = obj.image();
664 MaskPixelT
mask = obj.mask();
665 VariancePixelT
variance = obj.variance();
VariancePixelT variance() const
evaluate the variance part of the expression
MaskPixelT mask() const
evaluate the mask part of the expression
BinaryExpr(ExprT1 e1, double e2, double const alpha, ImageBinOp imageOp=ImageBinOp(), MaskBinOp maskOp=MaskBinOp(), VarianceBinOp=VarianceBinOp())
A binary operation, with three functors to represent the image/mask/variance operations and an extra ...
typename exprTraits< ExprT1 >::MaskPixelT MaskPixelT
ImagePixelT image() const
evaluate the image part of the expression
typename exprTraits< ExprT1 >::VariancePixelT VariancePixelT
BinaryExpr(ExprT1 e1, double e2, ImageBinOp imageOp=ImageBinOp(), MaskBinOp maskOp=MaskBinOp(), VarianceBinOp varOp=VarianceBinOp())
A binary operation, with three functors to represent the image/mask/variance operations.
typename exprTraits< ExprT1 >::ImagePixelT ImagePixelT
Class for representing binary operations.
typename exprTraits< ExprT1 >::VariancePixelT VariancePixelT
ImagePixelT image() const
evaluate the image part of the expression
typename exprTraits< ExprT1 >::ImagePixelT ImagePixelT
BinaryExpr(ExprT1 e1, ExprT2 e2, double const alpha, ImageBinOp imageOp=ImageBinOp(), MaskBinOp maskOp=MaskBinOp(), VarianceBinOp=VarianceBinOp())
A binary operation, with three functors to represent the image/mask/variance operations and an extra ...
BinaryExpr(ExprT1 e1, ExprT2 e2, ImageBinOp imageOp=ImageBinOp(), MaskBinOp maskOp=MaskBinOp(), VarianceBinOp varOp=VarianceBinOp())
A binary operation, with three functors to represent the image/mask/variance operations.
typename exprTraits< ExprT1 >::MaskPixelT MaskPixelT
VariancePixelT variance() const
evaluate the variance part of the expression
MaskPixelT mask() const
evaluate the mask part of the expression
A pixel of a MaskedImage.
MaskPixelT mask() const
Return the mask part of a Pixel.
Pixel(ImagePixelT const &image, MaskPixelT const &mask=0x0, VariancePixelT const &variance=0)
Construct a Pixel from references to its image/mask/variance components.
_VariancePixelT VariancePixelT
friend Pixel operator/=(Pixel const &e1, ExprT const &e2)
Evaluate e1 /= e2, and return e1.
Pixel operator=(Pixel const &rhs)
friend Pixel operator-=(Pixel const &e1, ExprT const &e2)
Evaluate e1 -= e2, and return e1.
Pixel(Pixel const &rhs)=default
ImagePixelT image() const
Return the image part of a Pixel.
Pixel(SinglePixel< ImagePixelT, MaskPixelT, VariancePixelT > &rhs)
friend bool operator==(Pixel const &lhs, SinglePixel< T1, T2, T3 > const &rhs)
friend Pixel operator*=(Pixel const &e1, ExprT const &e2)
Evaluate e1 *= e2, and return e1.
Pixel operator=(rhsExpr const &rhs)
Assign a Pixel by evaluating an expression.
friend Pixel operator+=(Pixel const &e1, ExprT const &e2)
Evaluate e1 += e2, and return e1.
friend bool operator==(Pixel const &lhs, Pixel< T1, T2, T3 > const &rhs)
Return true if two pixels are equal (in all three of image, mask, and variance) Fix C++20 compilation...
std::size_t hash_value() const noexcept
Return a hash of this object.
Pixel operator=(double const &rhs_image)
set the image part of a Pixel to rhs_image (the mask and variance are set to 0)
Pixel operator=(int const &rhs_image)
set the image part of a Pixel to rhs_image (the mask and variance are set to 0)
friend bool operator!=(Pixel const &lhs, T1 const &rhs)
Return true iff two pixels are unequal (in at least one of image, mask, and variance)
Pixel(Pixel &&rhs)=default
VariancePixelT variance() const
Return the variance part of a Pixel.
Pixel operator=(Pixel &&rhs)
A single pixel of the same type as a MaskedImage.
VariancePixelT variance() const
SinglePixel(ImagePixelT image, MaskPixelT mask=0, VariancePixelT variance=0)
_VariancePixelT VariancePixelT
ImagePixelT image() const
SinglePixel(rhsExpr const &rhs, typename std::enable_if_t<!std::is_fundamental_v< rhsExpr >, void * >=nullptr)
Class for representing Unary operations.
VariancePixelT variance() const
evaluate the variance part of the expression
MaskPixelT mask() const
evaluate the mask part of the expression
UnaryExpr(ExprT1 e1, ImageBinOp imageOp=ImageBinOp(), MaskBinOp maskOp=MaskBinOp(), VarianceBinOp varOp=VarianceBinOp())
a unary expression, with three functors to represent the image/mask/variance operations
typename exprTraits< ExprT1 >::ImagePixelT ImagePixelT
typename exprTraits< ExprT1 >::VariancePixelT VariancePixelT
ImagePixelT image() const
evaluate the image part of the expression
typename exprTraits< ExprT1 >::MaskPixelT MaskPixelT
ExprT1 operator-=(ExprT1 &e1, ExprT2 e2)
Template to evaluate e1 -= e2.
BinaryExpr< ExprT1, ExprT2, std::divides< typename exprTraits< ExprT1 >::ImagePixelT >, bitwise_or< typename exprTraits< ExprT1 >::MaskPixelT >, variance_divides< typename exprTraits< ExprT1 >::VariancePixelT > > operator/(ExprT1 e1, ExprT2 e2)
Template to evaluate (e1 / e2)
constexpr bool valid_binary_operands
std::ostream & operator<<(std::ostream &os, SinglePixel< ImagePixelT, MaskPixelT, VariancePixelT > const &v)
Print a SinglePixel.
auto operator-(ExprT1 e1)
Template for -e1.
ExprT1 plus(ExprT1 &lhs, ExprT2 const &rhs, float covariance)
Like operator+(), but assume that covariance's 2*alpha*sqrt(vx*vy)
BinaryExpr< ExprT1, ExprT2, std::multiplies< typename exprTraits< ExprT1 >::ImagePixelT >, bitwise_or< typename exprTraits< ExprT1 >::MaskPixelT >, variance_multiplies< typename exprTraits< ExprT1 >::VariancePixelT > > operator*(ExprT1 e1, ExprT2 e2)
Template to evaluate (e1 * e2)
ExprT1 & operator+=(ExprT1 &e1, ExprT2 const &e2)
template for e1 += e2
SinglePixel< ImagePixelT, MaskPixelT, VariancePixelT > makeSinglePixel(ImagePixelT x, MaskPixelT m, VariancePixelT v)
Return a SinglePixel.
ExprT1 operator*=(ExprT1 &e1, ExprT2 e2)
Template to evaluate e1 *= e2.
std::enable_if_t< valid_binary_operands< T1, T2 > > valid_operands
auto operator+(ExprT1 e1, ExprT2 e2)
ExprT1 operator/=(ExprT1 &e1, ExprT2 e2)
Template to evaluate e1 /= e2.
constexpr bool is_valid_operand
std::size_t hashCombine(std::size_t seed) noexcept
Combine hashes.
decltype(sizeof(void *)) size_t
A class used to identify classes that represent MaskedImage pixels.
static const PixelT padValue()
The quantity to use when a pixel value is undefined.
bitwise_or doesn't seem to be in std::
T1 operator()(const T1 &x, const T1 &y) const
T1 operator()(const T1 &x) const
exprTraits< double >::VariancePixelT VariancePixelT
exprTraits< double >::MaskPixelT MaskPixelT
exprTraits< double >::VariancePixelT VariancePixelT
exprTraits< double >::MaskPixelT MaskPixelT
exprTraits< double >::VariancePixelT VariancePixelT
exprTraits< double >::MaskPixelT MaskPixelT
A traits class to return the types of the image/mask/variance.
typename ExprT::ImagePixelT ImagePixelT
typename ExprT::MaskPixelT MaskPixelT
typename ExprT::VariancePixelT VariancePixelT
A noop functor (useful for e.g. masks and variances when changing the sign of the image)
T1 operator()(const T1 &x) const
Calculate the variance when we divide two Pixels.
T1 operator()(T1 const &, T1 const &y, T1 const &vx) const
T1 operator()(T1 const &x, T1 const &y, T1 const &vx, T1 const &vy) const
Calculate the variance when we multiply two Pixels.
T1 operator()(T1 const &x, T1 const &y, T1 const &vx, T1 const &vy) const
T1 operator()(T1 const &, T1 const &y, T1 const &vx) const
Calculate the variance when we add (or subtract) two Pixels.
T1 operator()(T1 const &, T1 const &, T1 const &vx, T1 const &vy) const
T1 operator()(T1 const &, T1 const &, T1 const &vx) const
size_t operator()(argument_type const &obj) const noexcept
size_t operator()(argument_type const &obj) const noexcept