Skip to content

Commit

Permalink
clean up Image.cc, use PixelT for calculations, don't use double inte…
Browse files Browse the repository at this point in the history
…rnally
  • Loading branch information
Matthias Wittgen committed May 23, 2021
1 parent 68b03cc commit 1c109dd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
8 changes: 4 additions & 4 deletions include/lsst/afw/image/Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ class Image : public ImageBase<PixelT> {
*/
Image& operator+=(lsst::afw::math::Function2<double> const& function);
/// Add Image c*rhs to lhs
void scaledPlus(double const c, Image<PixelT> const& rhs);
void scaledPlus(PixelT const c, Image<PixelT> const& rhs);
/// Subtract scalar rhs from lhs
Image& operator-=(PixelT const rhs);
/// Subtract Image rhs from lhs
Expand All @@ -356,13 +356,13 @@ class Image : public ImageBase<PixelT> {
*/
Image& operator-=(lsst::afw::math::Function2<double> const& function);
/// Subtract Image c*rhs from lhs
void scaledMinus(double const c, Image<PixelT> const& rhs);
void scaledMinus(PixelT const c, Image<PixelT> const& rhs);
/// Multiply lhs by scalar rhs
Image& operator*=(PixelT const rhs);
/// Multiply lhs by Image rhs (i.e. %pixel-by-%pixel multiplication)
Image& operator*=(Image<PixelT> const& rhs);
/// Multiply lhs by Image c*rhs (i.e. %pixel-by-%pixel multiplication)
void scaledMultiplies(double const c, Image<PixelT> const& rhs);
void scaledMultiplies(PixelT const c, Image<PixelT> const& rhs);
/**
* Divide lhs by scalar rhs
*
Expand All @@ -372,7 +372,7 @@ class Image : public ImageBase<PixelT> {
/// Divide lhs by Image rhs (i.e. %pixel-by-%pixel division)
Image& operator/=(Image<PixelT> const& rhs);
/// Divide lhs by Image c*rhs (i.e. %pixel-by-%pixel division)
void scaledDivides(double const c, Image<PixelT> const& rhs);
void scaledDivides(PixelT const c, Image<PixelT> const& rhs);

// In-place per-pixel sqrt(). Useful when handling variance planes.
void sqrt();
Expand Down
21 changes: 8 additions & 13 deletions src/image/Image.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,11 @@
* Implementation for ImageBase and Image
*/
#include <cstdint>
#include <iostream>
#include <functional>
#include <type_traits>
#include "boost/mpl/vector.hpp"
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-variable"
#pragma clang diagnostic pop
#include "boost/format.hpp"
#include "boost/filesystem/path.hpp"

#include "boost/version.hpp"
#if BOOST_VERSION < 106900
Expand Down Expand Up @@ -449,7 +445,6 @@ template <typename PixelT>
void Image<PixelT>::swap(Image& rhs) {
using std::swap; // See Meyers, Effective C++, Item 25
ImageBase<PixelT>::swap(rhs);
; // no private variables to swap
}

template <typename PixelT>
Expand Down Expand Up @@ -497,7 +492,7 @@ Image<PixelT>& Image<PixelT>::operator+=(math::Function2<double> const& function
}

template <typename PixelT>
void Image<PixelT>::scaledPlus(double const c, Image<PixelT> const& rhs) {
void Image<PixelT>::scaledPlus(PixelT const c, Image<PixelT> const& rhs) {
if (this->getDimensions() != rhs.getDimensions()) {
throw LSST_EXCEPT(pex::exceptions::LengthError,
(boost::format("Images are of different size, %dx%d v %dx%d") % this->getWidth() %
Expand All @@ -506,7 +501,7 @@ void Image<PixelT>::scaledPlus(double const c, Image<PixelT> const& rhs) {
}
transform_pixels(
_getRawView(), rhs._getRawView(), _getRawView(),
[&c](PixelT const& l, PixelT const& r) -> PixelT { return l + static_cast<PixelT>(c * r); });
[&c](PixelT const& l, PixelT const& r) -> PixelT { return l + (c * r); });
}

template <typename PixelT>
Expand All @@ -529,7 +524,7 @@ Image<PixelT>& Image<PixelT>::operator-=(Image<PixelT> const& rhs) {
}

template <typename PixelT>
void Image<PixelT>::scaledMinus(double const c, Image<PixelT> const& rhs) {
void Image<PixelT>::scaledMinus(PixelT const c, Image<PixelT> const& rhs) {
if (this->getDimensions() != rhs.getDimensions()) {
throw LSST_EXCEPT(pex::exceptions::LengthError,
(boost::format("Images are of different size, %dx%d v %dx%d") % this->getWidth() %
Expand All @@ -538,7 +533,7 @@ void Image<PixelT>::scaledMinus(double const c, Image<PixelT> const& rhs) {
}
transform_pixels(
_getRawView(), rhs._getRawView(), _getRawView(),
[&c](PixelT const& l, PixelT const& r) -> PixelT { return l - static_cast<PixelT>(c * r); });
[&c](PixelT const& l, PixelT const& r) -> PixelT { return l - (c * r); });
}

template <typename PixelT>
Expand Down Expand Up @@ -574,7 +569,7 @@ Image<PixelT>& Image<PixelT>::operator*=(Image<PixelT> const& rhs) {
}

template <typename PixelT>
void Image<PixelT>::scaledMultiplies(double const c, Image<PixelT> const& rhs) {
void Image<PixelT>::scaledMultiplies(PixelT c, Image<PixelT> const& rhs) {
if (this->getDimensions() != rhs.getDimensions()) {
throw LSST_EXCEPT(pex::exceptions::LengthError,
(boost::format("Images are of different size, %dx%d v %dx%d") % this->getWidth() %
Expand All @@ -583,7 +578,7 @@ void Image<PixelT>::scaledMultiplies(double const c, Image<PixelT> const& rhs) {
}
transform_pixels(
_getRawView(), rhs._getRawView(), _getRawView(),
[&c](PixelT const& l, PixelT const& r) -> PixelT { return l * static_cast<PixelT>(c * r); });
[&c](PixelT const& l, PixelT const& r) -> PixelT { return l * (c * r); });
}

template <typename PixelT>
Expand Down Expand Up @@ -622,7 +617,7 @@ Image<PixelT>& Image<PixelT>::operator/=(Image<PixelT> const& rhs) {
}

template <typename PixelT>
void Image<PixelT>::scaledDivides(double const c, Image<PixelT> const& rhs) {
void Image<PixelT>::scaledDivides(PixelT c, Image<PixelT> const& rhs) {
if (this->getDimensions() != rhs.getDimensions()) {
throw LSST_EXCEPT(pex::exceptions::LengthError,
(boost::format("Images are of different size, %dx%d v %dx%d") % this->getWidth() %
Expand All @@ -631,7 +626,7 @@ void Image<PixelT>::scaledDivides(double const c, Image<PixelT> const& rhs) {
}
transform_pixels(
_getRawView(), rhs._getRawView(), _getRawView(),
[&c](PixelT const& l, PixelT const& r) -> PixelT { return l / static_cast<PixelT>(c * r); });
[&c](PixelT const& l, PixelT const& r) -> PixelT { return l / (c * r); });
}

namespace {
Expand Down

0 comments on commit 1c109dd

Please sign in to comment.