LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
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 <string>
39 
40 #include "boost/shared_ptr.hpp"
41 
42 #include "lsst/base.h"
43 #include "lsst/pex/exceptions.h"
44 #include "lsst/afw/geom.h"
49 #include "lsst/afw/math/Function.h"
51 #include "lsst/afw/math/Kernel.h"
52 
53 namespace lsst {
54 namespace afw {
55 namespace image {
56  class Wcs;
57 }
58 namespace math {
59 
73  public:
75  int order
76  )
77  :
78  SeparableKernel(2 * order, 2 * order,
80  {}
81 
82  virtual ~LanczosWarpingKernel() {}
83 
84  virtual PTR(Kernel) clone() const;
85 
86  int getOrder() const;
87 
88  protected:
89  virtual void setKernelParameter(unsigned int ind, double value) const;
90  };
91 
102  public:
104  :
105  SeparableKernel(2, 2, BilinearFunction1(0.0), BilinearFunction1(0.0))
106  {}
107 
109 
110  virtual PTR(Kernel) clone() const;
111 
120  public:
122 
127  double fracPos)
128  :
129  Function1<Kernel::Pixel>(1)
130  {
131  this->_params[0] = fracPos;
132  }
133  virtual ~BilinearFunction1() {}
134 
135  virtual Function1Ptr clone() const {
136  return Function1Ptr(new BilinearFunction1(this->_params[0]));
137  }
138 
139  virtual Kernel::Pixel operator() (double x) const;
140 
141  virtual std::string toString(std::string const& ="") const;
142  };
143 
144  protected:
145  virtual void setKernelParameter(unsigned int ind, double value) const;
146  };
147 
158  public:
160  :
162  {}
163 
165 
166  virtual PTR(Kernel) clone() const;
167 
176  public:
178 
183  double fracPos)
184  :
185  Function1<Kernel::Pixel>(1)
186  {
187  this->_params[0] = fracPos;
188  }
189  virtual ~NearestFunction1() {}
190 
191  virtual Function1Ptr clone() const {
192  return Function1Ptr(new NearestFunction1(this->_params[0]));
193  }
194 
195  virtual Kernel::Pixel operator() (double x) const;
196 
197  virtual std::string toString(std::string const& ="") const;
198  };
199 
200  protected:
201  virtual void setKernelParameter(unsigned int ind, double value) const;
202  };
203 
229 
240  public:
253  explicit WarpingControl(
254  std::string const &warpingKernelName,
255  std::string const &maskWarpingKernelName = "",
257  int cacheSize = 0,
262  int interpLength = 0,
266  lsst::afw::image::MaskPixel growFullMask = 0
268  ) :
269  _warpingKernelPtr(makeWarpingKernel(warpingKernelName)),
270  _maskWarpingKernelPtr(),
271  _cacheSize(cacheSize),
272  _interpLength(interpLength),
273  _devicePreference(devicePreference),
274  _growFullMask(growFullMask)
275  {
276  setMaskWarpingKernelName(maskWarpingKernelName);
277  _testDevicePreference(_devicePreference, _warpingKernelPtr);
278  }
279 
283  explicit WarpingControl(
284  SeparableKernel &warpingKernel,
285  int interpLength = 0,
291  ) :
292  _warpingKernelPtr(boost::dynamic_pointer_cast<SeparableKernel>(warpingKernel.clone())),
293  _maskWarpingKernelPtr(),
294  _cacheSize(warpingKernel.getCacheSize()),
295  _interpLength(interpLength),
296  _devicePreference(devicePreference),
297  _growFullMask(lsst::afw::image::Mask<lsst::afw::image::MaskPixel>::getPlaneBitMask("EDGE") |
298  lsst::afw::image::Mask<lsst::afw::image::MaskPixel>::getPlaneBitMask("NO_DATA"))
299  {
300  _testDevicePreference(_devicePreference, _warpingKernelPtr);
301  }
302 
303 
304  virtual ~WarpingControl() {};
305 
309  int getCacheSize() const { return _cacheSize; };
310 
320  int cacheSize
321  ) { _cacheSize = cacheSize; };
322 
326  int getInterpLength() const { return _interpLength; };
327 
337  int interpLength
338  ) { _interpLength = interpLength; };
339 
343  lsst::afw::gpu::DevicePreference getDevicePreference() const { return _devicePreference; };
344 
349  lsst::afw::gpu::DevicePreference devicePreference
350  ) {
351  _testDevicePreference(devicePreference, _warpingKernelPtr);
352  _devicePreference = devicePreference;
353  }
354 
358  PTR(SeparableKernel) getWarpingKernel() const;
359 
363  void setWarpingKernelName(
364  std::string const &warpingKernelName
365  );
366 
372  void setWarpingKernel(
373  SeparableKernel const &warpingKernel
374  );
375 
379  PTR(SeparableKernel) getMaskWarpingKernel() const;
380 
384  bool hasMaskWarpingKernel() const { return static_cast<bool>(_maskWarpingKernelPtr); }
385 
389  void setMaskWarpingKernelName(
390  std::string const &maskWarpingKernelName
392  );
393 
399  void setMaskWarpingKernel(
400  SeparableKernel const &maskWarpingKernel
401  );
402 
406  lsst::afw::image::MaskPixel getGrowFullMask() const { return _growFullMask; };
407 
412  lsst::afw::image::MaskPixel growFullMask
413  ) { _growFullMask = growFullMask; }
414 
415  private:
422  void _testWarpingKernels(
423  SeparableKernel const &warpingKernel,
424  SeparableKernel const &maskWarpingKernel
425  ) const;
426 
432  void _testDevicePreference(
433  lsst::afw::gpu::DevicePreference const &devicePreference,
434  CONST_PTR(SeparableKernel) const &warpingKernelPtr
435  ) const;
436 
437  PTR(SeparableKernel) _warpingKernelPtr;
438  PTR(SeparableKernel) _maskWarpingKernelPtr;
439  int _cacheSize;
440  int _interpLength;
441  lsst::afw::gpu::DevicePreference _devicePreference;
442  lsst::afw::image::MaskPixel _growFullMask;
443  };
444 
445 
451  template<typename DestExposureT, typename SrcExposureT>
452  int warpExposure(
453  DestExposureT &destExposure,
454  SrcExposureT const &srcExposure,
457  WarpingControl const &control,
458  typename DestExposureT::MaskedImageT::SinglePixel padValue =
459  lsst::afw::math::edgePixel<typename DestExposureT::MaskedImageT>(
460  typename lsst::afw::image::detail::image_traits<
461  typename DestExposureT::MaskedImageT>::image_category())
463  );
464 
470  template<typename DestExposureT, typename SrcExposureT>
471  int warpExposure(
472  DestExposureT &destExposure,
473  SrcExposureT const &srcExposure,
476  SeparableKernel &warpingKernel,
477  int const interpLength=0,
478  typename DestExposureT::MaskedImageT::SinglePixel padValue =
479  lsst::afw::math::edgePixel<typename DestExposureT::MaskedImageT>(
480  typename lsst::afw::image::detail::image_traits<typename DestExposureT::MaskedImageT>::image_category()),
482  lsst::afw::gpu::DevicePreference devPref = lsst::afw::gpu::DEFAULT_DEVICE_PREFERENCE
484  );
485 
530  template<typename DestImageT, typename SrcImageT>
531  int warpImage(
532  DestImageT &destImage,
533  lsst::afw::image::Wcs const &destWcs,
534  SrcImageT const &srcImage,
535  lsst::afw::image::Wcs const &srcWcs,
536  WarpingControl const &control,
537  typename DestImageT::SinglePixel padValue = lsst::afw::math::edgePixel<DestImageT>(
538  typename lsst::afw::image::detail::image_traits<DestImageT>::image_category())
540  );
541 
545  template<typename DestImageT, typename SrcImageT>
546  int warpImage(
547  DestImageT &destImage,
548  lsst::afw::image::Wcs const &destWcs,
549  SrcImageT const &srcImage,
550  lsst::afw::image::Wcs const &srcWcs,
551  SeparableKernel &warpingKernel,
552  int const interpLength=0,
553  typename DestImageT::SinglePixel padValue = lsst::afw::math::edgePixel<DestImageT>(
556  typename lsst::afw::image::detail::image_traits<DestImageT>::image_category()),
558  lsst::afw::gpu::DevicePreference devPref = lsst::afw::gpu::DEFAULT_DEVICE_PREFERENCE
560  );
561 
566  template<typename DestImageT, typename SrcImageT>
567  int warpImage(
568  DestImageT &destImage,
569  SrcImageT const &srcImage,
570  lsst::afw::geom::AffineTransform const &affineTransform,
571  WarpingControl const &control,
572  typename DestImageT::SinglePixel padValue = lsst::afw::math::edgePixel<DestImageT>(
573  typename lsst::afw::image::detail::image_traits<DestImageT>::image_category())
575  );
576 
580  template<typename DestImageT, typename SrcImageT>
581  int warpImage(
582  DestImageT &destImage,
583  SrcImageT const &srcImage,
584  SeparableKernel &warpingKernel,
585  lsst::afw::geom::AffineTransform const &affineTransform,
586  int const interpLength = 0,
587  typename DestImageT::SinglePixel padValue = lsst::afw::math::edgePixel<DestImageT>(
590  typename lsst::afw::image::detail::image_traits<DestImageT>::image_category()),
592  lsst::afw::gpu::DevicePreference devPref = lsst::afw::gpu::DEFAULT_DEVICE_PREFERENCE
594  );
595 
596 
601  template<typename DestImageT, typename SrcImageT>
602  int warpCenteredImage(
603  DestImageT &destImage,
604  SrcImageT const &srcImage,
605  lsst::afw::geom::LinearTransform const &linearTransform,
606  lsst::afw::geom::Point2D const &centerPosition,
607  WarpingControl const &control,
608  typename DestImageT::SinglePixel padValue = lsst::afw::math::edgePixel<DestImageT>(
609  typename lsst::afw::image::detail::image_traits<DestImageT>::image_category())
611  );
612 
616  template<typename DestImageT, typename SrcImageT>
617  int warpCenteredImage(
618  DestImageT &destImage,
619  SrcImageT const &srcImage,
620  SeparableKernel &warpingKernel,
621  lsst::afw::geom::LinearTransform const &linearTransform,
622  lsst::afw::geom::Point2D const &centerPosition,
623  int const interpLength = 0,
624  typename DestImageT::SinglePixel padValue = lsst::afw::math::edgePixel<DestImageT>(
627  typename lsst::afw::image::detail::image_traits<DestImageT>::image_category()),
629  lsst::afw::gpu::DevicePreference devPref = lsst::afw::gpu::DEFAULT_DEVICE_PREFERENCE
631  );
632 
633  namespace details {
634  template <typename A, typename B>
635  bool isSameObject(A const&, B const&) { return false; }
636 
637  template <typename A>
638  bool isSameObject(A const& a, A const& b) { return &a == &b; }
639  }
640 
641 }}} // lsst::afw::math
642 
643 #endif // !defined(LSST_AFW_MATH_WARPEXPOSURE_H)
An include file to include the header files for lsst::afw::geom.
Declare the Kernel class and subclasses.
virtual int getCacheSize() const
Get the current cache size (0 if none)
table::Key< std::string > name
Definition: ApCorrMap.cc:71
1-dimensional Lanczos function
Include files required for standard LSST Exception handling.
void setDevicePreference(lsst::afw::gpu::DevicePreference devicePreference)
set the GPU device preference
Definition: warpExposure.h:348
boost::uint16_t MaskPixel
boost::shared_ptr< SeparableKernel > makeWarpingKernel(std::string name)
Return a warping kernel given its name.
A kernel described by a pair of functions: func(x, y) = colFunc(x) * rowFunc(y)
Definition: Kernel.h:986
#define PTR(...)
Definition: base.h:41
Point< double, 2 > Point2D
Definition: Point.h:286
Define a collection of useful Functions.
Parameters to control convolution.
Definition: warpExposure.h:239
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:319
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...
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:326
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:253
void setInterpLength(int interpLength)
set the interpolation length
Definition: warpExposure.h:336
void setGrowFullMask(lsst::afw::image::MaskPixel growFullMask)
set mask bits to grow to full width of image/variance kernel
Definition: warpExposure.h:411
1-dimensional bilinear interpolation function.
Definition: warpExposure.h:119
bool isSameObject(A const &, B const &)
Definition: warpExposure.h:635
A Function taking one argument.
Definition: Function.h:229
boost::shared_ptr< Function1< Kernel::Pixel > > Function1Ptr
Definition: warpExposure.h:177
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:101
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:121
int getCacheSize() const
get the cache size for the interpolation kernel(s)
Definition: warpExposure.h:309
const DevicePreference DEFAULT_DEVICE_PREFERENCE
Default DevicePreference value.
virtual void setKernelParameter(unsigned int ind, double value) const
Set one kernel parameter.
Nearest neighbor warping: fast; good for undersampled data.
Definition: warpExposure.h:157
Define the basic Function classes.
virtual Function1Ptr clone() const
Return a pointer to a deep copy of this function.
Definition: warpExposure.h:191
#define CONST_PTR(...)
Definition: base.h:47
afw::table::Key< double > b
Lanczos warping: accurate but slow and can introduce ringing artifacts.
Definition: warpExposure.h:72
1-dimensional nearest neighbor interpolation function.
Definition: warpExposure.h:175
lsst::afw::image::MaskPixel getGrowFullMask() const
get mask bits to grow to full width of image/variance kernel
Definition: warpExposure.h:406
lsst::afw::gpu::DevicePreference getDevicePreference() const
get the GPU device preference
Definition: warpExposure.h:343
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:134
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:135
WarpingControl(SeparableKernel &warpingKernel, int interpLength=0, lsst::afw::gpu::DevicePreference devicePreference=lsst::afw::gpu::DEFAULT_DEVICE_PREFERENCE)
This constructor supports the deprecated legacy warping API.
Definition: warpExposure.h:283