LSSTApplications  11.0-13-gbb96280,12.1.rc1,12.1.rc1+1,12.1.rc1+2,12.1.rc1+5,12.1.rc1+8,12.1.rc1-1-g06d7636+1,12.1.rc1-1-g253890b+5,12.1.rc1-1-g3d31b68+7,12.1.rc1-1-g3db6b75+1,12.1.rc1-1-g5c1385a+3,12.1.rc1-1-g83b2247,12.1.rc1-1-g90cb4cf+6,12.1.rc1-1-g91da24b+3,12.1.rc1-2-g3521f8a,12.1.rc1-2-g39433dd+4,12.1.rc1-2-g486411b+2,12.1.rc1-2-g4c2be76,12.1.rc1-2-gc9c0491,12.1.rc1-2-gda2cd4f+6,12.1.rc1-3-g3391c73+2,12.1.rc1-3-g8c1bd6c+1,12.1.rc1-3-gcf4b6cb+2,12.1.rc1-4-g057223e+1,12.1.rc1-4-g19ed13b+2,12.1.rc1-4-g30492a7
LSSTDataManagementBasePackage
warpExposure.h
Go to the documentation of this file.
1 // -*- LSST-C++ -*- // fixed format comment for emacs
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
35 #ifndef LSST_AFW_MATH_WARPEXPOSURE_H
36 #define LSST_AFW_MATH_WARPEXPOSURE_H
37 
38 #include <memory>
39 #include <string>
40 
41 #include "lsst/base.h"
42 #include "lsst/pex/exceptions.h"
43 #include "lsst/afw/geom.h"
48 #include "lsst/afw/math/Function.h"
50 #include "lsst/afw/math/Kernel.h"
51 
52 namespace lsst {
53 namespace afw {
54 namespace image {
55  class Wcs;
56 }
57 namespace math {
58 
72  public:
74  int order
75  )
76  :
77  SeparableKernel(2 * order, 2 * order,
79  {}
80 
81  virtual ~LanczosWarpingKernel() {}
82 
83  virtual PTR(Kernel) clone() const;
84 
85  int getOrder() const;
86 
87  protected:
88  virtual void setKernelParameter(unsigned int ind, double value) const;
89  };
90 
101  public:
103  :
104  SeparableKernel(2, 2, BilinearFunction1(0.0), BilinearFunction1(0.0))
105  {}
106 
108 
109  virtual PTR(Kernel) clone() const;
110 
119  public:
121 
126  double fracPos)
127  :
128  Function1<Kernel::Pixel>(1)
129  {
130  this->_params[0] = fracPos;
131  }
132  virtual ~BilinearFunction1() {}
133 
134  virtual Function1Ptr clone() const {
135  return Function1Ptr(new BilinearFunction1(this->_params[0]));
136  }
137 
138  virtual Kernel::Pixel operator() (double x) const;
139 
140  virtual std::string toString(std::string const& ="") const;
141  };
142 
143  protected:
144  virtual void setKernelParameter(unsigned int ind, double value) const;
145  };
146 
157  public:
159  :
161  {}
162 
164 
165  virtual PTR(Kernel) clone() const;
166 
175  public:
177 
182  double fracPos)
183  :
184  Function1<Kernel::Pixel>(1)
185  {
186  this->_params[0] = fracPos;
187  }
188  virtual ~NearestFunction1() {}
189 
190  virtual Function1Ptr clone() const {
191  return Function1Ptr(new NearestFunction1(this->_params[0]));
192  }
193 
194  virtual Kernel::Pixel operator() (double x) const;
195 
196  virtual std::string toString(std::string const& ="") const;
197  };
198 
199  protected:
200  virtual void setKernelParameter(unsigned int ind, double value) const;
201  };
202 
228 
239  public:
252  explicit WarpingControl(
253  std::string const &warpingKernelName,
254  std::string const &maskWarpingKernelName = "",
256  int cacheSize = 0,
261  int interpLength = 0,
265  lsst::afw::image::MaskPixel growFullMask = 0
267  ) :
268  _warpingKernelPtr(makeWarpingKernel(warpingKernelName)),
269  _maskWarpingKernelPtr(),
270  _cacheSize(cacheSize),
271  _interpLength(interpLength),
272  _devicePreference(devicePreference),
273  _growFullMask(growFullMask)
274  {
275  setMaskWarpingKernelName(maskWarpingKernelName);
276  _testDevicePreference(_devicePreference, _warpingKernelPtr);
277  }
278 
279 
280  virtual ~WarpingControl() {};
281 
285  int getCacheSize() const { return _cacheSize; };
286 
296  int cacheSize
297  ) { _cacheSize = cacheSize; };
298 
302  int getInterpLength() const { return _interpLength; };
303 
313  int interpLength
314  ) { _interpLength = interpLength; };
315 
319  lsst::afw::gpu::DevicePreference getDevicePreference() const { return _devicePreference; };
320 
325  lsst::afw::gpu::DevicePreference devicePreference
326  ) {
327  _testDevicePreference(devicePreference, _warpingKernelPtr);
328  _devicePreference = devicePreference;
329  }
330 
334  PTR(SeparableKernel) getWarpingKernel() const;
335 
339  void setWarpingKernelName(
340  std::string const &warpingKernelName
341  );
342 
348  void setWarpingKernel(
349  SeparableKernel const &warpingKernel
350  );
351 
355  PTR(SeparableKernel) getMaskWarpingKernel() const;
356 
360  bool hasMaskWarpingKernel() const { return static_cast<bool>(_maskWarpingKernelPtr); }
361 
365  void setMaskWarpingKernelName(
366  std::string const &maskWarpingKernelName
368  );
369 
375  void setMaskWarpingKernel(
376  SeparableKernel const &maskWarpingKernel
377  );
378 
382  lsst::afw::image::MaskPixel getGrowFullMask() const { return _growFullMask; };
383 
388  lsst::afw::image::MaskPixel growFullMask
389  ) { _growFullMask = growFullMask; }
390 
391  private:
398  void _testWarpingKernels(
399  SeparableKernel const &warpingKernel,
400  SeparableKernel const &maskWarpingKernel
401  ) const;
402 
408  void _testDevicePreference(
409  lsst::afw::gpu::DevicePreference const &devicePreference,
410  CONST_PTR(SeparableKernel) const &warpingKernelPtr
411  ) const;
412 
413  PTR(SeparableKernel) _warpingKernelPtr;
414  PTR(SeparableKernel) _maskWarpingKernelPtr;
415  int _cacheSize;
416  int _interpLength;
417  lsst::afw::gpu::DevicePreference _devicePreference;
418  lsst::afw::image::MaskPixel _growFullMask;
419  };
420 
421 
427  template<typename DestExposureT, typename SrcExposureT>
428  int warpExposure(
429  DestExposureT &destExposure,
430  SrcExposureT const &srcExposure,
433  WarpingControl const &control,
434  typename DestExposureT::MaskedImageT::SinglePixel padValue =
435  lsst::afw::math::edgePixel<typename DestExposureT::MaskedImageT>(
436  typename lsst::afw::image::detail::image_traits<
437  typename DestExposureT::MaskedImageT>::image_category())
439  );
440 
485  template<typename DestImageT, typename SrcImageT>
486  int warpImage(
487  DestImageT &destImage,
488  lsst::afw::image::Wcs const &destWcs,
489  SrcImageT const &srcImage,
490  lsst::afw::image::Wcs const &srcWcs,
491  WarpingControl const &control,
492  typename DestImageT::SinglePixel padValue = lsst::afw::math::edgePixel<DestImageT>(
493  typename lsst::afw::image::detail::image_traits<DestImageT>::image_category())
495  );
496 
501  template<typename DestImageT, typename SrcImageT>
502  int warpImage(
503  DestImageT &destImage,
504  SrcImageT const &srcImage,
505  lsst::afw::geom::XYTransform const &xyTransform,
506  WarpingControl const &control,
508  typename DestImageT::SinglePixel padValue = lsst::afw::math::edgePixel<DestImageT>(
509  typename lsst::afw::image::detail::image_traits<DestImageT>::image_category())
511  );
512 
513 
518  template<typename DestImageT, typename SrcImageT>
519  int warpCenteredImage(
520  DestImageT &destImage,
521  SrcImageT const &srcImage,
522  lsst::afw::geom::LinearTransform const &linearTransform,
523  lsst::afw::geom::Point2D const &centerPosition,
524  WarpingControl const &control,
525  typename DestImageT::SinglePixel padValue = lsst::afw::math::edgePixel<DestImageT>(
526  typename lsst::afw::image::detail::image_traits<DestImageT>::image_category())
528  );
529 
530  namespace details {
531  template <typename A, typename B>
532  bool isSameObject(A const&, B const&) { return false; }
533 
534  template <typename A>
535  bool isSameObject(A const& a, A const& b) { return &a == &b; }
536  }
537 
538 }}} // lsst::afw::math
539 
540 #endif // !defined(LSST_AFW_MATH_WARPEXPOSURE_H)
std::uint16_t MaskPixel
An include file to include the header files for lsst::afw::geom.
Declare the Kernel class and subclasses.
boost::shared_ptr< SeparableKernel > makeWarpingKernel(std::string name)
Return a warping kernel given its name.
table::Key< std::string > name
Definition: ApCorrMap.cc:71
1-dimensional Lanczos function
void setDevicePreference(lsst::afw::gpu::DevicePreference devicePreference)
set the GPU device preference
Definition: warpExposure.h:324
A kernel described by a pair of functions: func(x, y) = colFunc(x) * rowFunc(y)
Definition: Kernel.h:983
Point< double, 2 > Point2D
Definition: Point.h:288
Define a collection of useful Functions.
Parameters to control convolution.
Definition: warpExposure.h:238
Implementation of the WCS standard for a any projection.
Definition: Wcs.h:107
void setCacheSize(int cacheSize)
set the cache size for the interpolation kernel(s)
Definition: warpExposure.h:295
int warpCenteredImage(DestImageT &destImage, SrcImageT const &srcImage, lsst::afw::geom::LinearTransform const &linearTransform, lsst::afw::geom::Point2D const &centerPosition, WarpingControl const &control, typename DestImageT::SinglePixel padValue=lsst::afw::math::edgePixel< DestImageT >(typename lsst::afw::image::detail::image_traits< DestImageT >::image_category()))
Warp an image with a LinearTranform about a specified point. This enables warping an image of e...
#define CONST_PTR(...)
Definition: base.h:47
DevicePreference
A type used to select whether to use CPU or GPU device.
tbl::Key< int > cacheSize
Definition: CoaddPsf.cc:327
int warpImage(DestImageT &destImage, lsst::afw::image::Wcs const &destWcs, SrcImageT const &srcImage, lsst::afw::image::Wcs const &srcWcs, WarpingControl const &control, typename DestImageT::SinglePixel padValue=lsst::afw::math::edgePixel< DestImageT >(typename lsst::afw::image::detail::image_traits< DestImageT >::image_category()))
Warp an Image or MaskedImage to a new Wcs. See also convenience function warpExposure() to warp an Ex...
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
int getOrder() const
get the order of the kernel
int getInterpLength() const
get the interpolation length (pixels)
Definition: warpExposure.h:302
int warpExposure(DestExposureT &destExposure, SrcExposureT const &srcExposure, WarpingControl const &control, typename DestExposureT::MaskedImageT::SinglePixel padValue=lsst::afw::math::edgePixel< typename DestExposureT::MaskedImageT >(typename lsst::afw::image::detail::image_traits< typename DestExposureT::MaskedImageT >::image_category()))
Warp (remap) one exposure to another.
WarpingControl(std::string const &warpingKernelName, std::string const &maskWarpingKernelName="", int cacheSize=0, int interpLength=0, lsst::afw::gpu::DevicePreference devicePreference=lsst::afw::gpu::DEFAULT_DEVICE_PREFERENCE, lsst::afw::image::MaskPixel growFullMask=0)
Construct a WarpingControl object.
Definition: warpExposure.h:252
void setInterpLength(int interpLength)
set the interpolation length
Definition: warpExposure.h:312
void setGrowFullMask(lsst::afw::image::MaskPixel growFullMask)
set mask bits to grow to full width of image/variance kernel
Definition: warpExposure.h:387
1-dimensional bilinear interpolation function.
Definition: warpExposure.h:118
bool isSameObject(A const &, B const &)
Definition: warpExposure.h:532
A Function taking one argument.
Definition: Function.h:229
boost::shared_ptr< Function1< Kernel::Pixel > > Function1Ptr
Definition: warpExposure.h:176
SeparableKernel()
Construct an empty spatially invariant SeparableKernel of size 0x0.
Interface for CPU/GPU device selection.
ImageT::SinglePixel edgePixel(lsst::afw::image::detail::Image_tag)
Return an off-the-edge pixel appropriate for a given Image type.
double x
Bilinear warping: fast; good for undersampled data.
Definition: warpExposure.h:100
Convolve and convolveAtAPoint functions for Image and Kernel.
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
tbl::Key< std::string > warpingKernelName
Definition: CoaddPsf.cc:329
boost::shared_ptr< Function1< Kernel::Pixel > > Function1Ptr
Definition: warpExposure.h:120
int getCacheSize() const
get the cache size for the interpolation kernel(s)
Definition: warpExposure.h:285
const DevicePreference DEFAULT_DEVICE_PREFERENCE
Default DevicePreference value.
#define PTR(...)
Definition: base.h:41
virtual void setKernelParameter(unsigned int ind, double value) const
Set one kernel parameter.
Nearest neighbor warping: fast; good for undersampled data.
Definition: warpExposure.h:156
Define the basic Function classes.
virtual Function1Ptr clone() const
Return a pointer to a deep copy of this function.
Definition: warpExposure.h:190
afw::table::Key< double > b
Lanczos warping: accurate but slow and can introduce ringing artifacts.
Definition: warpExposure.h:71
1-dimensional nearest neighbor interpolation function.
Definition: warpExposure.h:174
lsst::afw::image::MaskPixel getGrowFullMask() const
get mask bits to grow to full width of image/variance kernel
Definition: warpExposure.h:382
Include files required for standard LSST Exception handling.
lsst::afw::gpu::DevicePreference getDevicePreference() const
get the GPU device preference
Definition: warpExposure.h:319
virtual boost::shared_ptr< Kernel > clone() const
Return a pointer to a deep copy of this kernel.
Kernels are used for convolution with MaskedImages and (eventually) Images.
Definition: Kernel.h:131
Definition of default types for Masks and Variance Images.
virtual Function1Ptr clone() const
Return a pointer to a deep copy of this function.
Definition: warpExposure.h:134