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
Namespaces | Classes | Typedefs | Enumerations | Functions
lsst::afw::math::detail Namespace Reference

Namespaces

 ConvolveGpuStatus
 
 gpu
 
 WarpImageGpuStatus
 

Classes

class  KernelImagesForRegion
 
class  RowOfKernelImagesForRegion
 A row of KernelImagesForRegion. More...
 
struct  ConvolveWithInterpolationWorkingImages
 kernel images used by convolveRegionWithInterpolation More...
 
class  PositionFunctor
 Base class to transform pixel position for a destination image to its position in the original source image. More...
 
class  WcsPositionFunctor
 Derived functor class to transform pixel position for a destination image to its position in the source image. The transform is from one WCS to another. More...
 
class  AffineTransformPositionFunctor
 Derived functor class to transform pixel position for a destination image to its position in the source image via an AffineTransform. More...
 
class  Spline
 
class  TautSpline
 
class  SmoothedSpline
 
struct  TrapezoidalPacker
 
class  WarpAtOnePoint
 A functor that computes one warped pixel. More...
 

Typedefs

typedef
lsst::afw::image::VariancePixel 
VarPixel
 
typedef lsst::afw::image::MaskPixel MskPixel
 
typedef double KerPixel
 

Enumerations

enum  SpatialFunctionType_t { sftChebyshev, sftPolynomial }
 

Functions

template<typename OutImageT , typename InImageT >
void assertDimensionsOK (OutImageT const &convolvedImage, InImageT const &inImage, lsst::afw::math::Kernel const &kernel)
 
template<typename OutImageT , typename InImageT >
void basicConvolve (OutImageT &convolvedImage, InImageT const &inImage, lsst::afw::math::Kernel const &kernel, lsst::afw::math::ConvolutionControl const &convolutionControl)
 Low-level convolution function that does not set edge pixels. More...
 
template<typename OutImageT , typename InImageT >
void basicConvolve (OutImageT &convolvedImage, InImageT const &inImage, lsst::afw::math::DeltaFunctionKernel const &kernel, lsst::afw::math::ConvolutionControl const &)
 A version of basicConvolve that should be used when convolving delta function kernels. More...
 
template<typename OutImageT , typename InImageT >
void basicConvolve (OutImageT &convolvedImage, InImageT const &inImage, lsst::afw::math::LinearCombinationKernel const &kernel, lsst::afw::math::ConvolutionControl const &convolutionControl)
 A version of basicConvolve that should be used when convolving a LinearCombinationKernel. More...
 
template<typename OutImageT , typename InImageT >
void basicConvolve (OutImageT &convolvedImage, InImageT const &inImage, lsst::afw::math::SeparableKernel const &kernel, lsst::afw::math::ConvolutionControl const &convolutionControl)
 A version of basicConvolve that should be used when convolving separable kernels. More...
 
template<typename OutImageT , typename InImageT >
void convolveWithBruteForce (OutImageT &convolvedImage, InImageT const &inImage, lsst::afw::math::Kernel const &kernel, lsst::afw::math::ConvolutionControl const &convolutionControl)
 Convolve an Image or MaskedImage with a Kernel by computing the kernel image at every point. (If the kernel is not spatially varying then only compute it once). More...
 
template<typename OutImageT , typename InImageT >
void convolveWithInterpolation (OutImageT &outImage, InImageT const &inImage, lsst::afw::math::Kernel const &kernel, ConvolutionControl const &convolutionControl)
 Convolve an Image or MaskedImage with a spatially varying Kernel using linear interpolation. More...
 
template<typename OutImageT , typename InImageT >
void convolveRegionWithInterpolation (OutImageT &outImage, InImageT const &inImage, KernelImagesForRegion const &region, ConvolveWithInterpolationWorkingImages &workingImages)
 Convolve a region of an Image or MaskedImage with a spatially varying Kernel using interpolation. More...
 
template<typename OutImageT , typename InImageT >
ConvolveGpuStatus::ReturnCode basicConvolveGPU (OutImageT &convolvedImage, InImageT const &inImage, lsst::afw::math::Kernel const &kernel, lsst::afw::math::ConvolutionControl const &convolutionControl)
 
template<typename OutPixelT , typename InPixelT >
ConvolveGpuStatus::ReturnCode convolveLinearCombinationGPU (lsst::afw::image::MaskedImage< OutPixelT, lsst::afw::image::MaskPixel, lsst::afw::image::VariancePixel > &convolvedImage, lsst::afw::image::MaskedImage< InPixelT, lsst::afw::image::MaskPixel, lsst::afw::image::VariancePixel > const &inImage, lsst::afw::math::LinearCombinationKernel const &kernel, lsst::afw::math::ConvolutionControl const &convolutionControl)
 
template<typename OutPixelT , typename InPixelT >
ConvolveGpuStatus::ReturnCode convolveLinearCombinationGPU (lsst::afw::image::Image< OutPixelT > &convolvedImage, lsst::afw::image::Image< InPixelT > const &inImage, lsst::afw::math::LinearCombinationKernel const &kernel, lsst::afw::math::ConvolutionControl const &convolutionControl)
 
template<typename OutPixelT , typename InPixelT >
ConvolveGpuStatus::ReturnCode convolveSpatiallyInvariantGPU (lsst::afw::image::MaskedImage< OutPixelT, lsst::afw::image::MaskPixel, lsst::afw::image::VariancePixel > &convolvedImage, lsst::afw::image::MaskedImage< InPixelT, lsst::afw::image::MaskPixel, lsst::afw::image::VariancePixel > const &inImage, lsst::afw::math::Kernel const &kernel, lsst::afw::math::ConvolutionControl const &convolutionControl)
 
template<typename OutPixelT , typename InPixelT >
ConvolveGpuStatus::ReturnCode convolveSpatiallyInvariantGPU (lsst::afw::image::Image< OutPixelT > &convolvedImage, lsst::afw::image::Image< InPixelT > const &inImage, lsst::afw::math::Kernel const &kernel, lsst::afw::math::ConvolutionControl const &convolutionControl)
 
bool IsSufficientSharedMemoryAvailable_ForImgBlock (int filterW, int filterH, int pixSize)
 
bool IsSufficientSharedMemoryAvailable_ForImgAndMaskBlock (int filterW, int filterH, int pixSize)
 
bool IsSufficientSharedMemoryAvailable_ForSfn (int order, int kernelN)
 
template<typename DestImageT , typename SrcImageT >
std::pair< int,
WarpImageGpuStatus::ReturnCode
warpImageGPU (DestImageT &destImage, SrcImageT const &srcImage, lsst::afw::math::LanczosWarpingKernel const &warpingKernel, lsst::afw::math::SeparableKernel const &maskWarpingKernel, PositionFunctor const &computeSrcPos, int const interpLength, typename DestImageT::SinglePixel padValue, const bool forceProcessing=true)
 GPU accelerated image warping using Lanczos resampling. More...
 
void TestGpuKernel (int &ret1, int &ret2)
 

Typedef Documentation

Definition at line 46 of file convCUDA.h.

Definition at line 45 of file convCUDA.h.

Definition at line 44 of file convCUDA.h.

Enumeration Type Documentation

Enumerator
sftChebyshev 
sftPolynomial 

Definition at line 45 of file cudaConvWrapper.h.

Function Documentation

template<typename OutImageT , typename InImageT >
void lsst::afw::math::detail::assertDimensionsOK ( OutImageT const &  convolvedImage,
InImageT const &  inImage,
lsst::afw::math::Kernel const &  kernel 
)

Definition at line 59 of file convCpuGpuShared.cc.

63  {
64  if (convolvedImage.getDimensions() != inImage.getDimensions()) {
65  std::ostringstream os;
66  os << "convolvedImage dimensions = ( "
67  << convolvedImage.getWidth() << ", " << convolvedImage.getHeight()
68  << ") != (" << inImage.getWidth() << ", " << inImage.getHeight() << ") = inImage dimensions";
69  throw LSST_EXCEPT(pexExcept::InvalidParameterError, os.str());
70  }
71  if (inImage.getWidth() < kernel.getWidth() || inImage.getHeight() < kernel.getHeight()) {
72  std::ostringstream os;
73  os << "inImage dimensions = ( "
74  << inImage.getWidth() << ", " << inImage.getHeight()
75  << ") smaller than (" << kernel.getWidth() << ", " << kernel.getHeight()
76  << ") = kernel dimensions in width and/or height";
77  throw LSST_EXCEPT(pexExcept::InvalidParameterError, os.str());
78  }
79  if ((kernel.getWidth() < 1) || (kernel.getHeight() < 1)) {
80  std::ostringstream os;
81  os << "kernel dimensions = ( "
82  << kernel.getWidth() << ", " << kernel.getHeight()
83  << ") smaller than (1, 1) in width and/or height";
84  throw LSST_EXCEPT(pexExcept::InvalidParameterError, os.str());
85  }
86 }
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
template<typename OutImageT , typename InImageT >
ConvolveGpuStatus::ReturnCode lsst::afw::math::detail::basicConvolveGPU ( OutImageT &  convolvedImage,
InImageT const &  inImage,
lsst::afw::math::Kernel const &  kernel,
lsst::afw::math::ConvolutionControl const &  convolutionControl 
)
template<typename OutPixelT , typename InPixelT >
ConvolveGpuStatus::ReturnCode lsst::afw::math::detail::convolveLinearCombinationGPU ( lsst::afw::image::MaskedImage< OutPixelT, lsst::afw::image::MaskPixel, lsst::afw::image::VariancePixel > &  convolvedImage,
lsst::afw::image::MaskedImage< InPixelT, lsst::afw::image::MaskPixel, lsst::afw::image::VariancePixel > const &  inImage,
lsst::afw::math::LinearCombinationKernel const &  kernel,
lsst::afw::math::ConvolutionControl const &  convolutionControl 
)
Parameters
convolvedImageconvolved image
inImageimage to convolve
template<typename OutPixelT , typename InPixelT >
ConvolveGpuStatus::ReturnCode lsst::afw::math::detail::convolveLinearCombinationGPU ( lsst::afw::image::Image< OutPixelT > &  convolvedImage,
lsst::afw::image::Image< InPixelT > const &  inImage,
lsst::afw::math::LinearCombinationKernel const &  kernel,
lsst::afw::math::ConvolutionControl const &  convolutionControl 
)
Parameters
convolvedImageconvolved image
inImageimage to convolve
template<typename OutImageT , typename InImageT >
void lsst::afw::math::detail::convolveRegionWithInterpolation ( OutImageT &  outImage,
InImageT const &  inImage,
KernelImagesForRegion const &  region,
ConvolveWithInterpolationWorkingImages &  workingImages 
)

Convolve a region of an Image or MaskedImage with a spatially varying Kernel using interpolation.

This is a low-level convolution function that does not set edge pixels.

Warning
: this is a low-level routine that performs no bounds checking.
Parameters
outImageconvolved image = inImage convolved with kernel
inImageinput image
regionkernel image region over which to convolve
workingImagesworking kernel images

Definition at line 132 of file ConvolveWithInterpolation.cc.

137 {
138  typedef typename OutImageT::xy_locator OutLocator;
139  typedef typename InImageT::const_xy_locator InConstLocator;
140  typedef KernelImagesForRegion::Image KernelImage;
141  typedef KernelImage::const_xy_locator KernelConstLocator;
142 
143  CONST_PTR(afwMath::Kernel) kernelPtr = region.getKernel();
144  geom::Extent2I const kernelDimensions(kernelPtr->getDimensions());
145  workingImages.leftImage <<= *region.getImage(KernelImagesForRegion::BOTTOM_LEFT);
146  workingImages.rightImage <<= *region.getImage(KernelImagesForRegion::BOTTOM_RIGHT);
147  workingImages.kernelImage <<= workingImages.leftImage;
148 
149  afwGeom::Box2I const goodBBox = region.getBBox();
150  afwGeom::Box2I const fullBBox = kernelPtr->growBBox(goodBBox);
151 
152  // top and right images are computed one beyond bbox boundary,
153  // so the distance between edge images is bbox width/height pixels
154  double xfrac = 1.0 / static_cast<double>(goodBBox.getWidth());
155  double yfrac = 1.0 / static_cast<double>(goodBBox.getHeight());
156  afwMath::scaledPlus(workingImages.leftDeltaImage,
157  yfrac, *region.getImage(KernelImagesForRegion::TOP_LEFT),
158  -yfrac, workingImages.leftImage);
159  afwMath::scaledPlus(workingImages.rightDeltaImage,
160  yfrac, *region.getImage(KernelImagesForRegion::TOP_RIGHT),
161  -yfrac, workingImages.rightImage);
162 
163  KernelConstLocator const kernelLocator = workingImages.kernelImage.xy_at(0, 0);
164 
165  // The loop is a bit odd for efficiency: the initial value of workingImages.kernelImage
166  // and related kernel images are set when they are allocated,
167  // so they are not computed in the loop until after the convolution; to save cpu cycles
168  // they are not computed at all for the last iteration.
169  InConstLocator inLocator = inImage.xy_at(fullBBox.getMinX(), fullBBox.getMinY());
170  OutLocator outLocator = outImage.xy_at(goodBBox.getMinX(), goodBBox.getMinY());
171  for (int j = 0; ; ) {
173  workingImages.deltaImage, xfrac, workingImages.rightImage, -xfrac, workingImages.leftImage);
174  for (int i = 0; ; ) {
175  *outLocator = afwMath::convolveAtAPoint<OutImageT, InImageT>(
176  inLocator, kernelLocator, kernelDimensions.getX(), kernelDimensions.getY());
177  ++outLocator.x();
178  ++inLocator.x();
179  ++i;
180  if (i >= goodBBox.getWidth()) {
181  break;
182  }
183  workingImages.kernelImage += workingImages.deltaImage;
184  }
185 
186  ++j;
187  if (j >= goodBBox.getHeight()) {
188  break;
189  }
190  workingImages.leftImage += workingImages.leftDeltaImage;
191  workingImages.rightImage += workingImages.rightDeltaImage;
192  workingImages.kernelImage <<= workingImages.leftImage;
193  inLocator += lsst::afw::image::detail::difference_type(-goodBBox.getWidth(), 1);
194  outLocator += lsst::afw::image::detail::difference_type(-goodBBox.getWidth(), 1);
195  }
196 }
void scaledPlus(OutImageT &outImage, double c1, InImageT const &inImage1, double c2, InImageT const &inImage2)
for(FootprintList::const_iterator ptr=feet->begin(), end=feet->end();ptr!=end;++ptr)
Definition: saturated.cc:82
Extent< int, 2 > Extent2I
Definition: Extent.h:355
#define CONST_PTR(...)
Definition: base.h:47
Kernels are used for convolution with MaskedImages and (eventually) Images.
Definition: Kernel.h:134
template<typename OutPixelT , typename InPixelT >
ConvolveGpuStatus::ReturnCode lsst::afw::math::detail::convolveSpatiallyInvariantGPU ( lsst::afw::image::MaskedImage< OutPixelT, lsst::afw::image::MaskPixel, lsst::afw::image::VariancePixel > &  convolvedImage,
lsst::afw::image::MaskedImage< InPixelT, lsst::afw::image::MaskPixel, lsst::afw::image::VariancePixel > const &  inImage,
lsst::afw::math::Kernel const &  kernel,
lsst::afw::math::ConvolutionControl const &  convolutionControl 
)
Parameters
convolvedImageconvolved image
inImageimage to convolve
kernelconvolution kernel
template<typename OutPixelT , typename InPixelT >
ConvolveGpuStatus::ReturnCode lsst::afw::math::detail::convolveSpatiallyInvariantGPU ( lsst::afw::image::Image< OutPixelT > &  convolvedImage,
lsst::afw::image::Image< InPixelT > const &  inImage,
lsst::afw::math::Kernel const &  kernel,
lsst::afw::math::ConvolutionControl const &  convolutionControl 
)
Parameters
convolvedImageconvolved image
inImageimage to convolve
kernelconvolution kernel
template<typename OutImageT , typename InImageT >
void lsst::afw::math::detail::convolveWithInterpolation ( OutImageT &  outImage,
InImageT const &  inImage,
lsst::afw::math::Kernel const &  kernel,
ConvolutionControl const &  convolutionControl 
)

Convolve an Image or MaskedImage with a spatially varying Kernel using linear interpolation.

This is a low-level convolution function that does not set edge pixels.

The algorithm is as follows:

  • divide the image into regions whose size is no larger than maxInterpolationDistance
  • for each region:
    • convolve it using convolveRegionWithInterpolation (which see)

Note that this routine will also work with spatially invariant kernels, but not efficiently.

Exceptions
lsst::pex::exceptions::InvalidParameterErrorif outImage is not the same size as inImage
Parameters
outImageconvolved image = inImage convolved with kernel
inImageinput image
kernelconvolution kernel
convolutionControlconvolution control parameters

Definition at line 71 of file ConvolveWithInterpolation.cc.

76 {
77  if (outImage.getDimensions() != inImage.getDimensions()) {
78  std::ostringstream os;
79  os << "outImage dimensions = ( "
80  << outImage.getWidth() << ", " << outImage.getHeight()
81  << ") != (" << inImage.getWidth() << ", " << inImage.getHeight() << ") = inImage dimensions";
82  throw LSST_EXCEPT(pexExcept::InvalidParameterError, os.str());
83  }
84 
85  // compute region covering good area of output image
86  afwGeom::Box2I fullBBox = afwGeom::Box2I(
87  afwGeom::Point2I(0, 0),
88  afwGeom::Extent2I(outImage.getWidth(), outImage.getHeight()));
89  afwGeom::Box2I goodBBox = kernel.shrinkBBox(fullBBox);
90  KernelImagesForRegion goodRegion(KernelImagesForRegion(
91  kernel.clone(),
92  goodBBox,
93  inImage.getXY0(),
94  convolutionControl.getDoNormalize()));
95  pexLog::TTrace<6>("lsst.afw.math.convolve",
96  "convolveWithInterpolation: full bbox minimum=(%d, %d), extent=(%d, %d)",
97  fullBBox.getMinX(), fullBBox.getMinY(),
98  fullBBox.getWidth(), fullBBox.getHeight());
99  pexLog::TTrace<6>("lsst.afw.math.convolve",
100  "convolveWithInterpolation: goodRegion bbox minimum=(%d, %d), extent=(%d, %d)",
101  goodRegion.getBBox().getMinX(), goodRegion.getBBox().getMinY(),
102  goodRegion.getBBox().getWidth(), goodRegion.getBBox().getHeight());
103 
104  // divide good region into subregions small enough to interpolate over
105  int nx = 1 + (goodBBox.getWidth() / convolutionControl.getMaxInterpolationDistance());
106  int ny = 1 + (goodBBox.getHeight() / convolutionControl.getMaxInterpolationDistance());
107  pexLog::TTrace<4>("lsst.afw.math.convolve",
108  "convolveWithInterpolation: divide into %d x %d subregions", nx, ny);
109 
110  ConvolveWithInterpolationWorkingImages workingImages(kernel.getDimensions());
111  RowOfKernelImagesForRegion regionRow(nx, ny);
112  while (goodRegion.computeNextRow(regionRow)) {
113  for (RowOfKernelImagesForRegion::ConstIterator rgnIter = regionRow.begin(), rgnEnd = regionRow.end();
114  rgnIter != rgnEnd; ++rgnIter) {
115  pexLog::TTrace<6>("lsst.afw.math.convolve",
116  "convolveWithInterpolation: bbox minimum=(%d, %d), extent=(%d, %d)",
117  (*rgnIter)->getBBox().getMinX(), (*rgnIter)->getBBox().getMinY(),
118  (*rgnIter)->getBBox().getWidth(), (*rgnIter)->getBBox().getHeight());
119  convolveRegionWithInterpolation(outImage, inImage, **rgnIter, workingImages);
120  }
121  }
122 }
void convolveRegionWithInterpolation(OutImageT &outImage, InImageT const &inImage, KernelImagesForRegion const &region, ConvolveWithInterpolationWorkingImages &workingImages)
Convolve a region of an Image or MaskedImage with a spatially varying Kernel using interpolation...
An integer coordinate rectangle.
Definition: Box.h:53
int getMinY() const
Definition: Box.h:125
int getMinX() const
Definition: Box.h:124
int getWidth() const
Definition: Box.h:154
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
int getHeight() const
Definition: Box.h:155
bool lsst::afw::math::detail::IsSufficientSharedMemoryAvailable_ForImgAndMaskBlock ( int  filterW,
int  filterH,
int  pixSize 
)

Definition at line 55 of file cudaConvWrapper.cc.

56 {
57  return false;
58 }
bool lsst::afw::math::detail::IsSufficientSharedMemoryAvailable_ForImgBlock ( int  filterW,
int  filterH,
int  pixSize 
)

Definition at line 51 of file cudaConvWrapper.cc.

52 {
53  return false;
54 }
bool lsst::afw::math::detail::IsSufficientSharedMemoryAvailable_ForSfn ( int  order,
int  kernelN 
)

Definition at line 59 of file cudaConvWrapper.cc.

60 {
61  return false;
62 }
void lsst::afw::math::detail::TestGpuKernel ( int &  ret1,
int &  ret2 
)

Definition at line 46 of file cudaConvWrapper.cc.

46  {
47  ret1 = 0;
48  ret2 = 0;
49 }
template<typename DestImageT , typename SrcImageT >
std::pair< int, WarpImageGpuStatus::ReturnCode > lsst::afw::math::detail::warpImageGPU ( DestImageT &  destImage,
SrcImageT const &  srcImage,
lsst::afw::math::LanczosWarpingKernel const &  warpingKernel,
lsst::afw::math::SeparableKernel const &  maskWarpingKernel,
PositionFunctor const &  computeSrcPos,
int const  interpLength,
typename DestImageT::SinglePixel  padValue,
const bool  forceProcessing = true 
)

GPU accelerated image warping using Lanczos resampling.

Returns
a std::pair<int,WarpImageGpuStatus::ReturnValue> containing: 1) the number of valid pixels in destImage (those that are not edge pixels). 2) whether the warping was performed successfully, or error code (if not OK, then the first value is not defined)

This function requires a Lanczos warping kernel to perform the source value estimation.

This function will not perform the warping if kernel size is too large. (currently, when the order of the Lanczos kernel is >50) If warping is not performed, the second elemnt of return value will not equal OK. If forceProcessing is true:

  • this function will throw exceptions if a GPU device cannot be selected or used If forceProcessing is false:
  • the warping will not be performed if the GPU code path is estimated to be slower than the CPU code path. That might happen if interpLength is too small (less than 3).
  • the warping will not be performed if a GPU device cannot be selected or used
Precondition
maskWarpingKernel must not be greater in size than warpingKernel

Also see lsst::afw::math::warpImage()

Implementation: Calculates values of the coordinate transform function at some points, which are spaced by interpLength intervals. Calls CalculateInterpolationData() to calculate interpolation data from values of coordinate transformation fn. Calls WarpImageGpuWrapper() to perform the wapring.

Exceptions
lsst::pex::exceptions::InvalidParameterErrorif interpLength < 1
lsst::pex::exceptions::InvalidParameterErrorif maskWarpingKernel is neither Lanczos, bilinear nor nearest neighbor
lsst::pex::exceptions::MemoryErrorwhen allocation of CPU memory fails
lsst::afw::gpu::GpuMemoryErrorwhen allocation or transfer to/from GPU memory fails
lsst::afw::gpu::GpuRuntimeErrorwhen GPU code run fails
Parameters
destImageremapped image
srcImagesource image
warpingKernelwarping kernel
maskWarpingKernelmask warping kernel (can be the same as warping kernel)
computeSrcPosFunctor to compute source position
interpLengthDistance over which WCS can be linearily interpolated must be >0
padValuevalue to use for undefined pixels
forceProcessingif true, this function will perform the warping even when it is slower then the CPU code path

Definition at line 395 of file cudaLanczosWrapper.cc.

405 {
406  if (interpLength < 1) {
407  throw LSST_EXCEPT(pexExcept::InvalidParameterError,
408  "GPU accelerated warping must use interpolation");
409  }
410 
411  int const srcWidth = srcImage.getWidth();
412  int const srcHeight = srcImage.getHeight();
413  pexLog::TTrace<3>("lsst.afw.math.warp", "(GPU) source image width=%d; height=%d", srcWidth, srcHeight);
414 
416  throw LSST_EXCEPT(afwGpu::GpuRuntimeError, "Afw not compiled with GPU support");
417  }
418 
419 #ifdef GPU_BUILD
420  gpu::KernelType maskKernelType;
421  {
422  if (dynamic_cast<afwMath::LanczosWarpingKernel const*>(&maskWarpingKernel)) {
423  maskKernelType = gpu::KERNEL_TYPE_LANCZOS;
424  } else if (dynamic_cast<afwMath::BilinearWarpingKernel const*>(&maskWarpingKernel)) {
425  maskKernelType = gpu::KERNEL_TYPE_BILINEAR;
426  } else if (dynamic_cast<afwMath::NearestWarpingKernel const*>(&maskWarpingKernel)) {
427  maskKernelType = gpu::KERNEL_TYPE_NEAREST_NEIGHBOR;
428  } else {
429  throw LSST_EXCEPT(pexExcept::InvalidParameterError, "unknown type of mask warping kernel");
430  }
431  }
432 #endif
433 
434  if (gpuDetail::TryToSelectCudaDevice(!forceProcessing) == false) {
435  return std::pair<int, WarpImageGpuStatus::ReturnCode>(-1, WarpImageGpuStatus::NO_GPU);
436  }
437 
438  int const mainKernelSize = 2 * lanczosKernel.getOrder();
439  //do not process if the kernel is too large for allocated GPU local memory
440  if (mainKernelSize * 2 > gpu::SIZE_MAX_WARPING_KERNEL) {
441  return std::pair<int, WarpImageGpuStatus::ReturnCode>(-1, WarpImageGpuStatus::KERNEL_TOO_LARGE);
442  }
443 
444  //do not process if the interpolation data is too large to make any speed gains
445  if (!forceProcessing && interpLength < 3) {
446  return std::pair<int, WarpImageGpuStatus::ReturnCode>(-1, WarpImageGpuStatus::INTERP_LEN_TOO_SMALL);
447  }
448 
449  int const destWidth = destImage.getWidth();
450  int const destHeight = destImage.getHeight();
451  pexLog::TTrace<3>("lsst.afw.math.warp", "(GPU) remap image width=%d; height=%d", destWidth, destHeight);
452 
453  int const maxCol = destWidth - 1;
454  int const maxRow = destHeight - 1;
455 
456 #ifdef GPU_BUILD
457  // Compute borders; use to prevent applying kernel outside of srcImage
458  afwGeom::Box2I srcGoodBBox = lanczosKernel.shrinkBBox(srcImage.getBBox(afwImage::LOCAL));
459 #endif
460 
461  int const interpBlkNX = InterpBlkN(destWidth , interpLength);
462  int const interpBlkNY = InterpBlkN(destHeight, interpLength);
463  //GPU kernel input, will contain: for each interpolation block, all interpolation parameters
464  gpuDetail::GpuBuffer2D<gpu::BilinearInterp> srcPosInterp(interpBlkNX, interpBlkNY);
465 
466  // calculate values of coordinate transform function
467  for (int rowBand = 0; rowBand < interpBlkNY; rowBand++) {
468  int row = min(maxRow, (rowBand * interpLength - 1));
469  for (int colBand = 0; colBand < interpBlkNX; colBand++) {
470  int col = min(maxCol, (colBand * interpLength - 1));
471  afwGeom::Point2D srcPos = computeSrcPos(col, row);
472  SPoint2 sSrcPos(srcPos);
473  sSrcPos = MovePoint(sSrcPos, SVec2(-srcImage.getX0(), -srcImage.getY0()));
474  srcPosInterp.Pixel(colBand, rowBand).o = sSrcPos;
475  }
476  }
477 
478  CalculateInterpolationData(/*in,out*/srcPosInterp, interpLength, destWidth, destHeight);
479 
480  int numGoodPixels = 0;
481 
482  pexLog::TTrace<3>("lsst.afw.math.warp", "using GPU acceleration, remapping masked image");
483 
484 #ifdef GPU_BUILD
485  int maskKernelSize;
486  if (maskKernelType == gpu::KERNEL_TYPE_LANCZOS) {
487  maskKernelSize = 2 * dynamic_cast<afwMath::LanczosWarpingKernel const*>(&maskWarpingKernel)->getOrder();
488  } else {
489  maskKernelSize = 2;
490  }
491  numGoodPixels = WarpImageGpuWrapper(destImage,
492  srcImage,
493  mainKernelSize,
494  maskKernelType,
495  maskKernelSize,
496  srcGoodBBox,
497  srcPosInterp, interpLength, padValue
498  );
499 #endif
500  return std::pair<int, WarpImageGpuStatus::ReturnCode>(numGoodPixels, WarpImageGpuStatus::OK);
501 }
Class for representing an image or 2D array in general)
Definition: GpuBuffer2D.h:54
SPoint2 MovePoint(SPoint2 p, SVec2 v)
Definition: CudaLanczos.h:94
bool TryToSelectCudaDevice(bool noExceptions, bool reselect=false)
An integer coordinate rectangle.
Definition: Box.h:53
Simple 2D point (suitable for use on a GPU)
Definition: CudaLanczos.h:56
bool isGpuBuild()
Inline function which returns true only when GPU_BUILD macro is defined.
Definition: IsGpuBuild.h:45
Simple 2D vector (suitable for use on a GPU)
Definition: CudaLanczos.h:69
int row
Definition: CR.cc:153
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
Lanczos warping: accurate but slow and can introduce ringing artifacts.
Definition: warpExposure.h:72
int col
Definition: CR.cc:152