27 #ifndef _VIGRA_EXT_IMAGETRANSFORMSGPU_H
28 #define _VIGRA_EXT_IMAGETRANSFORMSGPU_H
35 #include <vigra/basicimage.hxx>
38 #include <vigra/accessor.hxx>
45 using vigra::NumericTraits;
53 const std::string& interpolatorGLSL,
54 const int interpolatorSize,
55 const std::string& photometricGLSL,
56 const std::vector<double>& invLut,
57 const std::vector<double>& destLut,
58 const vigra::Diff2D srcSize,
59 const void*
const srcBuffer,
60 const int srcGLInternalFormat,
const int srcGLTransferFormat,
const int srcGLFormat,
const int srcGLType,
61 const void*
const srcAlphaBuffer,
62 const int srcAlphaGLType,
63 const vigra::Diff2D destUL,
64 const vigra::Diff2D destSize,
65 void*
const destBuffer,
66 const int destGLInternalFormat,
const int destGLTransferFormat,
const int destGLFormat,
const int destGLType,
67 void*
const destAlphaBuffer,
68 const int destAlphaGLType,
69 const bool warparound);
94 #define DEFINE_GPUNUMERICTRAITS(IMAGECOMPONENT, GLFORMAT, GLFORMATRGB, GLTRANSFER, GLTRANSFERRGB, GLTYPE) \
96 struct GpuNumericTraits<IMAGECOMPONENT> { \
97 typedef IMAGECOMPONENT ImagePixelComponentType; \
98 enum {NumBands = 1}; \
99 enum {ImageGLInternalFormat = GLFORMAT}; \
100 enum {ImageGLTransferFormat = GLTRANSFER}; \
101 enum {ImageGLFormat = XGL_LUMINANCE}; \
102 enum {ImagePixelComponentGLType = GLTYPE}; \
105 struct GpuNumericTraits<vigra::RGBValue<IMAGECOMPONENT, 0, 1, 2> > { \
106 typedef IMAGECOMPONENT ImagePixelComponentType; \
107 enum {NumBands = 3}; \
108 enum {ImageGLInternalFormat = GLFORMATRGB}; \
109 enum {ImageGLTransferFormat = GLTRANSFERRGB}; \
110 enum {ImageGLFormat = XGL_RGB}; \
111 enum {ImagePixelComponentGLType = GLTYPE}; \
114 struct GpuNumericTraits<vigra::TinyVector<IMAGECOMPONENT, 2> > { \
115 typedef IMAGECOMPONENT ImagePixelComponentType; \
116 enum {NumBands = 2}; \
117 enum {ImageGLInternalFormat = GLFORMAT}; \
118 enum {ImageGLTransferFormat = GLFORMAT}; \
119 enum {ImageGLFormat = XGL_LUMINANCE_ALPHA}; \
120 enum {ImagePixelComponentGLType = GLTYPE}; \
123 struct GpuNumericTraits<vigra::TinyVector<IMAGECOMPONENT, 4> > { \
124 typedef IMAGECOMPONENT ImagePixelComponentType; \
125 enum {NumBands = 4}; \
126 enum {ImageGLInternalFormat = GLFORMATRGB}; \
127 enum {ImageGLTransferFormat = GLFORMATRGB}; \
128 enum {ImageGLFormat = XGL_RGBA}; \
129 enum {ImagePixelComponentGLType = GLTYPE}; \
170 template <
class SrcImageIterator,
class SrcAccessor,
171 class DestImageIterator,
class DestAccessor,
173 class PixelTransform,
174 class AlphaImageIterator,
class AlphaAccessor,
177 vigra::triple<DestImageIterator, DestImageIterator, DestAccessor> dest,
178 std::pair<AlphaImageIterator, AlphaAccessor> alpha,
179 TRANSFORM & transform,
180 PixelTransform & pixelTransform,
181 vigra::Diff2D destUL,
186 typedef typename SrcAccessor::value_type SrcValueType;
187 typedef typename DestAccessor::value_type DestValueType;
188 typedef typename AlphaAccessor::value_type AlphaValueType;
190 vigra::Diff2D srcSize = src.second - src.first;
191 vigra::Diff2D destSize = dest.second - dest.first;
194 interpol (src, interp, warparound);
198 std::ostringstream coordXformOss;
199 coordXformOss << std::setprecision(20) << std::showpoint;
200 transform.emitGLSL(coordXformOss);
202 std::ostringstream interpolatorOss;
203 interpolatorOss << std::setprecision(20) << std::showpoint;
206 std::ostringstream photometricOss;
207 std::vector<double> invLut;
208 std::vector<double> destLut;
209 photometricOss << std::setprecision(20) << std::showpoint;
210 pixelTransform.emitGLSL(photometricOss, invLut, destLut);
217 interpolatorOss.str(),
219 photometricOss.str(),
245 template <
class SrcImageIterator,
class SrcAccessor,
246 class SrcAlphaIterator,
class SrcAlphaAccessor,
247 class DestImageIterator,
class DestAccessor,
249 class PixelTransform,
250 class AlphaImageIterator,
class AlphaAccessor,
253 std::pair<SrcAlphaIterator, SrcAlphaAccessor> srcAlpha,
254 vigra::triple<DestImageIterator, DestImageIterator, DestAccessor> dest,
255 std::pair<AlphaImageIterator, AlphaAccessor> alpha,
256 TRANSFORM & transform,
257 PixelTransform & pixelTransform,
258 vigra::Diff2D destUL,
263 typedef typename SrcAccessor::value_type SrcValueType;
264 typedef typename SrcAlphaAccessor::value_type SrcAlphaType;
265 typedef typename DestAccessor::value_type DestValueType;
266 typedef typename AlphaAccessor::value_type DestAlphaType;
268 vigra::Diff2D srcSize = src.second - src.first;
269 vigra::Diff2D destSize = dest.second - dest.first;
273 interpol (src, interp, warparound);
277 std::ostringstream coordXformOss;
278 coordXformOss << std::setprecision(20) << std::showpoint;
279 if(!transform.emitGLSL(coordXformOss))
281 std::cerr <<
"nona: Found unsupported transformation in stack." << std::endl
282 <<
" This geometric transformation is not supported by GPU." << std::endl
283 <<
" Remove -g switch and try with CPU transformation." << std::endl;
287 std::ostringstream interpolatorOss;
288 interpolatorOss << std::setprecision(20) << std::showpoint;
291 std::ostringstream photometricOss;
292 std::vector<double> invLut;
293 std::vector<double> destLut;
294 photometricOss << std::setprecision(20) << std::showpoint;
295 pixelTransform.emitGLSL(photometricOss, invLut, destLut);
341 interpolatorOss.str(),
343 photometricOss.str(),
368 vigra::FVector4Image phonyDest(destSize);
369 vigra::FImage phonyDestAlpha(destSize);
370 vigra::FRGBImage phonySrc(srcSize);
371 vigra::FImage phonySrcAlpha(srcSize);
380 int xstart = destUL.x;
381 int xend = destUL.x + destSize.x;
382 int ystart = destUL.y;
383 int yend = destUL.y + destSize.y;
385 double samples = 0.0;
386 double sumError = 0.0;
387 double sumErrorSq = 0.0;
391 vigra::FVector4Image::traverser yd = phonyDest.upperLeft();
392 vigra::FImage::traverser ydm = phonyDestAlpha.upperLeft();
393 DestImageIterator ydest(dest.first);
394 AlphaImageIterator ydesta(alpha.first);
398 for(
int y=ystart; y < yend; ++y, ++yd.y, ++ydm.y, ++ydest.y, ++ydesta.y)
402 vigra::FVector4Image::traverser xd(yd);
403 vigra::FImage::traverser xdm(ydm);
404 DestImageIterator xdest(ydest);
405 AlphaImageIterator xdesta(ydesta);
407 for(
int x=xstart; x < xend; ++x, ++xd.x, ++xdm.x, ++xdest.x, ++xdesta.x)
410 bool result = transform.transformImgCoordPartial(sx,sy,x,y);
411 float errorX = (*xd)[2] -
static_cast<float>(sx);
412 float errorY = (*xd)[1] -
static_cast<float>(sy);
413 double error = sqrt(errorX * errorX + errorY * errorY);
415 if (error != 0.0 && numMessages < 150) {
416 std::cout << std::setprecision(20) <<
"pos=[" << x <<
", " << y <<
"] shouldBe=[" << sx <<
", " << sy <<
" is=[" << (*xd)[2] <<
", " << (*xd)[1] <<
"] error=" << error << std::endl;
421 sumErrorSq += (error * error);
425 dest.third.set(NumericTraits<DestValueType>::fromRealPromote(
std::min(255.0,
std::max(0.0, 255.0 * 10.0 * error))), xdest);
426 alpha.second.set(255, xdesta);
430 double avgError = sumError/samples;
432 std::cout <<
"numSamples=" << samples << std::endl
433 <<
"average error=" << avgError << std::endl
434 <<
"stddev=" << (sumErrorSq/samples - avgError*avgError) << std::endl;
466 template <
class SrcImageIterator,
class SrcAccessor,
467 class DestImageIterator,
class DestAccessor,
468 class AlphaImageIterator,
class AlphaAccessor,
470 class PixelTransform>
472 vigra::triple<DestImageIterator, DestImageIterator, DestAccessor> dest,
473 std::pair<AlphaImageIterator, AlphaAccessor> alpha,
474 vigra::Diff2D destUL,
475 TRANSFORM & transform,
476 PixelTransform & pixelTransform,
531 template <
class SrcImageIterator,
class SrcAccessor,
532 class SrcAlphaIterator,
class SrcAlphaAccessor,
533 class DestImageIterator,
class DestAccessor,
534 class AlphaImageIterator,
class AlphaAccessor,
535 class TRANSFORM,
class PixelTransform>
537 std::pair<SrcAlphaIterator, SrcAlphaAccessor> srcAlpha,
538 vigra::triple<DestImageIterator, DestImageIterator, DestAccessor> dest,
539 std::pair<AlphaImageIterator, AlphaAccessor> alpha,
540 vigra::Diff2D destUL,
541 TRANSFORM & transform,
542 PixelTransform & pixelTransform,
598 #endif // _VIGRA_EXT_IMAGETRANSFORMSGPU_H
simple bilinear interpolation
misc math function & classes used by other parts of the program
"wrapper" for efficient interpolation access to an image
sinc interpolation, with variable width
void transformImageGPU(vigra::triple< SrcImageIterator, SrcImageIterator, SrcAccessor > src, vigra::triple< DestImageIterator, DestImageIterator, DestAccessor > dest, std::pair< AlphaImageIterator, AlphaAccessor > alpha, vigra::Diff2D destUL, TRANSFORM &transform, PixelTransform &pixelTransform, bool warparound, Interpolator interpol, AppBase::ProgressDisplay *progress)
Transform an image into the panorama.
void transformImageAlphaGPUIntern(vigra::triple< SrcImageIterator, SrcImageIterator, SrcAccessor > src, std::pair< SrcAlphaIterator, SrcAlphaAccessor > srcAlpha, vigra::triple< DestImageIterator, DestImageIterator, DestAccessor > dest, std::pair< AlphaImageIterator, AlphaAccessor > alpha, TRANSFORM &transform, PixelTransform &pixelTransform, vigra::Diff2D destUL, Interpolator interp, bool warparound, AppBase::ProgressDisplay *progress)
transform input images with alpha channel
DEFINE_GPUNUMERICTRAITS(vigra::Int8, XGL_LUMINANCE8_ALPHA8, XGL_RGBA8, XGL_LUMINANCE8, XGL_RGB8, XGL_BYTE)
void SetGPUDebugMessages(const bool doPrint)
several classes to calculate interpolator weights,
bool transformImageGPUIntern(const std::string &coordXformGLSL, const std::string &interpolatorGLSL, const int interpolatorSize, const std::string &photometricGLSL, const vector< double > &invLut, const vector< double > &destLut, const vigra::Diff2D srcSize, const void *const srcBuffer, const int srcGLInternalFormat, const int srcGLTransferFormat, const int srcGLFormat, const int srcGLType, const void *const srcAlphaBuffer, const int srcAlphaGLType, const vigra::Diff2D destUL, const vigra::Diff2D destSize, void *const destBuffer, const int destGLInternalFormat, const int destGLTransferFormat, const int destGLFormat, const int destGLType, void *const destAlphaBuffer, const int destAlphaGLType, const bool warparound)
void emitGLSL(std::ostringstream &oss) const
Error_GpuNumericTraits_not_specialized_for_this_case ImagePixelComponentType
The pano tools interpolators ported to vigra.
Interpolator
enum with all interpolation methods
void transformImageAlphaGPU(vigra::triple< SrcImageIterator, SrcImageIterator, SrcAccessor > src, std::pair< SrcAlphaIterator, SrcAlphaAccessor > srcAlpha, vigra::triple< DestImageIterator, DestImageIterator, DestAccessor > dest, std::pair< AlphaImageIterator, AlphaAccessor > alpha, vigra::Diff2D destUL, TRANSFORM &transform, PixelTransform &pixelTransform, bool warparound, Interpolator interpol, AppBase::ProgressDisplay *progress)
Transform image, and respect a possible alpha channel.