Skip to content

Commit

Permalink
replace CONST_PTR and PTR macros by std::shared
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Wittgen committed Aug 3, 2021
1 parent ba590ab commit 79b4980
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 34 deletions.
8 changes: 4 additions & 4 deletions include/lsst/meas/base/SincCoeffs.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ class SincCoeffs {
*
* Coefficients are retrieved from the cache, if available; otherwise they will be generated.
*/
static PTR(CoeffT const)
static std::shared_ptr<CoeffT const>
get(afw::geom::ellipses::Axes const& outerEllipse, float const innerRadiusFactor = 0.0);

/// Calculate the coefficients for an aperture
static PTR(CoeffT)
static std::shared_ptr<CoeffT>
calculate(afw::geom::ellipses::Axes const& outerEllipse, double const innerFactor = 0.0);

private:
Expand All @@ -78,7 +78,7 @@ class SincCoeffs {
bool isEqual(T x, T y) const { return ::fabs(x - y) < std::numeric_limits<T>::epsilon(); }
};

typedef std::map<float, PTR(CoeffT), FuzzyCompare<float> > CoeffMap;
typedef std::map<float, std::shared_ptr<CoeffT>, FuzzyCompare<float> > CoeffMap;
typedef std::map<float, CoeffMap, FuzzyCompare<float> > CoeffMapMap;
SincCoeffs() : _cache(){};
SincCoeffs(SincCoeffs const&); // unimplemented: singleton
Expand All @@ -91,7 +91,7 @@ class SincCoeffs {
*
* If the coefficients are not cached, a null shared_ptr will be returned.
*/
PTR(CoeffT const)
std::shared_ptr<CoeffT const>
_lookup(afw::geom::ellipses::Axes const& outerEllipse, double const innerRadiusFactor = 0.0) const;

CoeffMapMap _cache; //< Cache of coefficients
Expand Down
8 changes: 4 additions & 4 deletions src/ApertureFlux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ namespace {
// Helper function for computeSincFlux get Sinc instFlux coefficients, and handle cases where the coeff
// image needs to be clipped to fit in the measurement image
template <typename T>
CONST_PTR(afw::image::Image<T>)
std::shared_ptr<afw::image::Image<T> const>
getSincCoeffs(geom::Box2I const &bbox, // measurement image bbox we need to fit inside
afw::geom::ellipses::Ellipse const &ellipse, // ellipse that defines the aperture
ApertureFluxAlgorithm::Result &result, // result object where we set flags if we do clip
ApertureFluxAlgorithm::Control const &ctrl // configuration
) {
CONST_PTR(afw::image::Image<T>) cImage = SincCoeffs<T>::get(ellipse.getCore(), 0.0);
std::shared_ptr<afw::image::Image<T> const> cImage = SincCoeffs<T>::get(ellipse.getCore(), 0.0);
cImage = afw::math::offsetImage(*cImage, ellipse.getCenter().getX(), ellipse.getCenter().getY(),
ctrl.shiftKernel);
if (!bbox.contains(cImage->getBBox())) {
Expand Down Expand Up @@ -146,7 +146,7 @@ template <typename T>
ApertureFluxAlgorithm::Result ApertureFluxAlgorithm::computeSincFlux(
afw::image::Image<T> const &image, afw::geom::ellipses::Ellipse const &ellipse, Control const &ctrl) {
Result result;
CONST_PTR(afw::image::Image<T>) cImage = getSincCoeffs<T>(image.getBBox(), ellipse, result, ctrl);
std::shared_ptr<afw::image::Image<T> const> cImage = getSincCoeffs<T>(image.getBBox(), ellipse, result, ctrl);
if (result.getFlag(APERTURE_TRUNCATED.number)) return result;
afw::image::Image<T> subImage(image, cImage->getBBox());
result.instFlux =
Expand All @@ -159,7 +159,7 @@ ApertureFluxAlgorithm::Result ApertureFluxAlgorithm::computeSincFlux(
afw::image::MaskedImage<T> const &image, afw::geom::ellipses::Ellipse const &ellipse,
Control const &ctrl) {
Result result;
CONST_PTR(afw::image::Image<T>) cImage = getSincCoeffs<T>(image.getBBox(), ellipse, result, ctrl);
std::shared_ptr<afw::image::Image<T> const> cImage = getSincCoeffs<T>(image.getBBox(), ellipse, result, ctrl);
if (result.getFlag(APERTURE_TRUNCATED.number)) return result;
afw::image::MaskedImage<T> subImage(image, cImage->getBBox(afw::image::PARENT), afw::image::PARENT);
result.instFlux = (ndarray::asEigenArray(subImage.getImage()->getArray()) *
Expand Down
4 changes: 2 additions & 2 deletions src/Blendedness.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ FlagDefinitionList const& BlendednessAlgorithm::getFlagDefinitions() { return fl

namespace {

double computeOldBlendedness(PTR(afw::detection::Footprint const) childFootprint,
double computeOldBlendedness(std::shared_ptr<afw::detection::Footprint const> childFootprint,
afw::image::Image<float> const& parentImage) {
if (!childFootprint) {
throw LSST_EXCEPT(pex::exceptions::LogicError, "blendedness_old requires a Footprint.");
}

PTR(afw::detection::HeavyFootprint<float> const)
std::shared_ptr<afw::detection::HeavyFootprint<float> const>
childHeavy = std::dynamic_pointer_cast<afw::detection::HeavyFootprint<float> const>(childFootprint);

if (!childHeavy) {
Expand Down
2 changes: 1 addition & 1 deletion src/CentroidUtilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ bool CentroidChecker::operator()(afw::table::SourceRecord &record) const {
}

// Check that the centroid has a footprint that we can validate; otherwise, give up.
PTR(afw::detection::Footprint) footprint = record.getFootprint();
std::shared_ptr<afw::detection::Footprint> footprint = record.getFootprint();
if (!footprint) {
throw LSST_EXCEPT(pex::exceptions::RuntimeError, "No Footprint attached to record");
}
Expand Down
2 changes: 1 addition & 1 deletion src/CircularApertureFlux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ CircularApertureFluxAlgorithm::CircularApertureFluxAlgorithm(Control const& ctrl
void CircularApertureFluxAlgorithm::measure(afw::table::SourceRecord& measRecord,
afw::image::Exposure<float> const& exposure) const {
afw::geom::ellipses::Ellipse ellipse(afw::geom::ellipses::Axes(1.0, 1.0, 0.0));
PTR(afw::geom::ellipses::Axes)
std::shared_ptr<afw::geom::ellipses::Axes>
axes = std::static_pointer_cast<afw::geom::ellipses::Axes>(ellipse.getCorePtr());
for (std::size_t i = 0; i < _ctrl.radii.size(); ++i) {
// Each call to _centroidExtractor within this loop goes through exactly the same error-checking
Expand Down
2 changes: 1 addition & 1 deletion src/InputUtilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace {

geom::Point2D extractPeak(afw::table::SourceRecord const& record, std::string const& name) {
geom::Point2D result;
PTR(afw::detection::Footprint) footprint = record.getFootprint();
std::shared_ptr<afw::detection::Footprint> footprint = record.getFootprint();
if (!footprint) {
throw LSST_EXCEPT(
pex::exceptions::RuntimeError,
Expand Down
14 changes: 7 additions & 7 deletions src/PeakLikelihoodFlux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,20 @@ class PsfAttributes {
BICKERTON ///< Weight \<r^2> by I^2 to avoid negative instFluxes
};

PsfAttributes(CONST_PTR(afw::detection::Psf) psf, int const iX, int const iY);
PsfAttributes(CONST_PTR(afw::detection::Psf) psf, geom::Point2I const &cen);
PsfAttributes(std::shared_ptr<afw::detection::Psf const> psf, int const iX, int const iY);
PsfAttributes(std::shared_ptr<afw::detection::Psf const> psf, geom::Point2I const &cen);

double computeGaussianWidth(Method how = ADAPTIVE_MOMENT) const;
double computeEffectiveArea() const;

private:
PTR(afw::image::Image<double>) _psfImage;
std::shared_ptr<afw::image::Image<double>> _psfImage;
};

/**
* @brief Constructor for PsfAttributes
*/
PsfAttributes::PsfAttributes(CONST_PTR(afw::detection::Psf) psf, ///< The psf whose attributes we want
PsfAttributes::PsfAttributes(std::shared_ptr<afw::detection::Psf const> psf, ///< The psf whose attributes we want
int const iX, ///< the x position in the frame we want the attributes at
int const iY ///< the y position in the frame we want the attributes at
) {
Expand All @@ -98,7 +98,7 @@ PsfAttributes::PsfAttributes(CONST_PTR(afw::detection::Psf) psf, ///< The psf w
* @brief Constructor for PsfAttributes
*/
PsfAttributes::PsfAttributes(
CONST_PTR(afw::detection::Psf) psf, ///< The psf whose attributes we want
std::shared_ptr<afw::detection::Psf const> psf, ///< The psf whose attributes we want
geom::Point2I const &cen ///< the position in the frame we want the attributes at
)
: // N.b. cen is a PointI so that we know this image is centered in the central pixel of _psfImage
Expand Down Expand Up @@ -140,7 +140,7 @@ typename afw::image::MaskedImage<T>::SinglePixel computeShiftedValue(
typedef typename afw::image::Exposure<T>::MaskedImageT MaskedImageT;
typedef typename afw::image::Image<double> KernelImageT;

PTR(afw::math::SeparableKernel) warpingKernelPtr = afw::math::makeWarpingKernel(warpingKernelName);
std::shared_ptr<afw::math::SeparableKernel> warpingKernelPtr = afw::math::makeWarpingKernel(warpingKernelName);

if ((std::abs(fracShift[0]) >= 1) || (std::abs(fracShift[1]) >= 1)) {
std::ostringstream os;
Expand Down Expand Up @@ -206,7 +206,7 @@ void PeakLikelihoodFluxAlgorithm::measure(afw::table::SourceRecord &measRecord,
if (!exposure.hasPsf()) {
throw LSST_EXCEPT(pex::exceptions::InvalidParameterError, "exposure has no PSF");
}
PTR(afw::detection::Psf const) psfPtr = exposure.getPsf();
std::shared_ptr<afw::detection::Psf const> psfPtr = exposure.getPsf();
if (!geom::Box2D(mimage.getBBox()).contains(center)) {
std::ostringstream os;
os << "Center = " << center << " not in exposure bbox" << mimage.getBBox();
Expand Down
2 changes: 1 addition & 1 deletion src/PixelFlags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void PixelFlagsAlgorithm::measure(afw::table::SourceRecord& measRecord,
// footprint (supplied by the measurement framework) should be the
// highest peak so that one will be used as a proxy for the central
// tendency of the distribution of flux for the record.
PTR(afw::detection::Footprint) footprint = measRecord.getFootprint();
std::shared_ptr<afw::detection::Footprint> footprint = measRecord.getFootprint();
// If there is no footprint or the footprint contains no peaks, throw
// a runtime error.
if (!footprint || footprint->getPeaks().empty()) {
Expand Down
4 changes: 2 additions & 2 deletions src/PsfFlux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ PsfFluxAlgorithm::PsfFluxAlgorithm(Control const& ctrl, std::string const& name,

void PsfFluxAlgorithm::measure(afw::table::SourceRecord& measRecord,
afw::image::Exposure<float> const& exposure) const {
PTR(afw::detection::Psf const) psf = exposure.getPsf();
std::shared_ptr<afw::detection::Psf const> psf = exposure.getPsf();
if (!psf) {
LOGL_ERROR(getLogName(), "PsfFlux: no psf attached to exposure");
throw LSST_EXCEPT(FatalAlgorithmError, "PsfFlux algorithm requires a Psf with every exposure");
}
geom::Point2D position = _centroidExtractor(measRecord, _flagHandler);
PTR(afw::detection::Psf::Image) psfImage = psf->computeImage(position);
std::shared_ptr<afw::detection::Psf::Image> psfImage = psf->computeImage(position);
geom::Box2I fitBBox = psfImage->getBBox();
fitBBox.clip(exposure.getBBox());
if (fitBBox != psfImage->getBBox()) {
Expand Down
8 changes: 4 additions & 4 deletions src/SdssCentroid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ void doMeasureCentroidImpl(double *xCenter, // output; x-positio
}

template <typename MaskedImageT>
std::pair<MaskedImageT, double> smoothAndBinImage(CONST_PTR(afw::detection::Psf) psf, int const x,
std::pair<MaskedImageT, double> smoothAndBinImage(std::shared_ptr<afw::detection::Psf const> psf, int const x,
const int y, MaskedImageT const &mimage, int binX, int binY,
FlagHandler _flagHandler) {
geom::Point2D const center(x + mimage.getX0(), y + mimage.getY0());
Expand All @@ -377,14 +377,14 @@ std::pair<MaskedImageT, double> smoothAndBinImage(CONST_PTR(afw::detection::Psf)
geom::ExtentI(binX * (3 + kWidth + 1), binY * (3 + kHeight + 1)));

// image to smooth, a shallow copy
PTR(MaskedImageT) subImage;
std::shared_ptr<MaskedImageT> subImage;
try {
subImage.reset(new MaskedImageT(mimage, bbox, afw::image::LOCAL));
} catch (pex::exceptions::LengthError &err) {
throw LSST_EXCEPT(MeasurementError, SdssCentroidAlgorithm::EDGE.doc,
SdssCentroidAlgorithm::EDGE.number);
}
PTR(MaskedImageT) binnedImage = afw::math::binImage(*subImage, binX, binY, afw::math::MEAN);
std::shared_ptr<MaskedImageT> binnedImage = afw::math::binImage(*subImage, binX, binY, afw::math::MEAN);
binnedImage->setXY0(subImage->getXY0());
// image to smooth into, a deep copy.
MaskedImageT smoothedImage = MaskedImageT(*binnedImage, true);
Expand Down Expand Up @@ -428,7 +428,7 @@ void SdssCentroidAlgorithm::measure(afw::table::SourceRecord &measRecord,

MaskedImageT const &mimage = exposure.getMaskedImage();
ImageT const &image = *mimage.getImage();
CONST_PTR(afw::detection::Psf) psf = exposure.getPsf();
std::shared_ptr<afw::detection::Psf const> psf = exposure.getPsf();

int const x = image.positionToIndex(center.getX(), afw::image::X).first;
int const y = image.positionToIndex(center.getY(), afw::image::Y).first;
Expand Down
2 changes: 1 addition & 1 deletion src/SdssShape.cc
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ void SdssShapeAlgorithm::measure(afw::table::SourceRecord &measRecord,
// by making the measurements stored with shape.sdss always computed via the
// SdssShapeAlgorithm instead of delegating to the Psf class.
try {
PTR(afw::detection::Psf const) psf = exposure.getPsf();
std::shared_ptr<afw::detection::Psf const> psf = exposure.getPsf();
if (!psf) {
result.flags[PSF_SHAPE_BAD.number] = true;
} else {
Expand Down
12 changes: 6 additions & 6 deletions src/SincCoeffs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -495,27 +495,27 @@ void SincCoeffs<PixelT>::cache(float r1, float r2) {
double const innerFactor = r1 / r2;
afw::geom::ellipses::Axes axes(r2, r2, 0.0);
if (!getInstance()._lookup(axes, innerFactor)) {
PTR(typename SincCoeffs<PixelT>::CoeffT) coeff = calculate(axes, innerFactor);
std::shared_ptr<typename SincCoeffs<PixelT>::CoeffT> coeff = calculate(axes, innerFactor);
getInstance()._cache[r2][innerFactor] = coeff;
}
}

template <typename PixelT>
CONST_PTR(typename SincCoeffs<PixelT>::CoeffT)
std::shared_ptr<typename SincCoeffs<PixelT>::CoeffT const>
SincCoeffs<PixelT>::get(afw::geom::ellipses::Axes const& axes, float const innerFactor) {
CONST_PTR(CoeffT) coeff = getInstance()._lookup(axes, innerFactor);
std::shared_ptr<CoeffT const> coeff = getInstance()._lookup(axes, innerFactor);
return coeff ? coeff : calculate(axes, innerFactor);
}

template <typename PixelT>
CONST_PTR(typename SincCoeffs<PixelT>::CoeffT)
std::shared_ptr<typename SincCoeffs<PixelT>::CoeffT const>
SincCoeffs<PixelT>::_lookup(afw::geom::ellipses::Axes const& axes, double const innerFactor) const {
if (innerFactor < 0.0 || innerFactor > 1.0) {
throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
(boost::format("innerFactor = %f is not between 0 and 1") % innerFactor).str());
}

CONST_PTR(typename SincCoeffs<PixelT>::CoeffT) const null = CONST_PTR(SincCoeffs<PixelT>::CoeffT)();
std::shared_ptr<typename SincCoeffs<PixelT>::CoeffT const> const null = std::shared_ptr<SincCoeffs<PixelT>::CoeffT const>();

// We only cache circular apertures
if (!FuzzyCompare<float>().isEqual(axes.getA(), axes.getB())) {
Expand All @@ -530,7 +530,7 @@ SincCoeffs<PixelT>::_lookup(afw::geom::ellipses::Axes const& axes, double const
}

template <typename PixelT>
PTR(typename SincCoeffs<PixelT>::CoeffT)
std::shared_ptr<typename SincCoeffs<PixelT>::CoeffT>
SincCoeffs<PixelT>::calculate(afw::geom::ellipses::Axes const& axes, double const innerFactor) {
if (innerFactor < 0.0 || innerFactor > 1.0) {
throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
Expand Down

0 comments on commit 79b4980

Please sign in to comment.