|
Shinya Kitaoka |
810553 |
#pragma once
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef WARP_H
|
|
Toshihiro Shimizu |
890ddd |
#define WARP_H
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tfxparam.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "trop.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "trasterfx.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
struct WarpParams {
|
|
Shinya Kitaoka |
120a6e |
int m_shrink;
|
|
Shinya Kitaoka |
120a6e |
double m_warperScale;
|
|
Shinya Kitaoka |
120a6e |
double m_intensity;
|
|
Shinya Kitaoka |
120a6e |
bool m_sharpen;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
struct LPoint {
|
|
Shinya Kitaoka |
120a6e |
TPointD s; // Warped lattice point
|
|
Shinya Kitaoka |
120a6e |
TPointD d; // Original lattice point
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
struct Lattice {
|
|
Shinya Kitaoka |
120a6e |
int m_width; // Number of lattice columns
|
|
Shinya Kitaoka |
120a6e |
int m_height; // Number of lattice rows
|
|
Shinya Kitaoka |
120a6e |
LPoint *coords; // Grid vertex coordinates
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
Lattice() : coords(0) {}
|
|
Shinya Kitaoka |
120a6e |
~Lattice() {
|
|
Shinya Kitaoka |
120a6e |
if (coords) delete[] coords;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
namespace // Ugly...
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
120a6e |
inline int myCeil(double x) {
|
|
Shinya Kitaoka |
120a6e |
return ((x - (int)(x)) > TConsts::epsilon ? (int)(x) + 1 : (int)(x));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
inline TRect convert(const TRectD &r, TPointD &dp) {
|
|
Shinya Kitaoka |
120a6e |
TRect ri(tfloor(r.x0), tfloor(r.y0), myCeil(r.x1), myCeil(r.y1));
|
|
Shinya Kitaoka |
120a6e |
dp.x = r.x0 - ri.x0;
|
|
Shinya Kitaoka |
120a6e |
dp.y = r.y0 - ri.y0;
|
|
Shinya Kitaoka |
120a6e |
assert(dp.x >= 0 && dp.y >= 0);
|
|
Shinya Kitaoka |
120a6e |
return ri;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
inline double getWarpRadius(const WarpParams ¶ms) {
|
|
Shinya Kitaoka |
120a6e |
return 2.55 * 1.5 * 1.5 * fabs(params.m_intensity);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
inline double getWarperEnlargement(const WarpParams ¶ms) {
|
|
Shinya Kitaoka |
120a6e |
// It accounts for:
|
|
Shinya Kitaoka |
120a6e |
// * Resample factor (1 - due to triangle filtering)
|
|
Shinya Kitaoka |
120a6e |
// * Eventual grid smoothening (6 - as the blur radius applied after
|
|
Shinya Kitaoka |
120a6e |
// resampling)
|
|
Shinya Kitaoka |
120a6e |
// * grid interpolation (2 - for the shepard interpolant radius)
|
|
Shinya Kitaoka |
120a6e |
int enlargement = 3;
|
|
Shinya Kitaoka |
120a6e |
if (!params.m_sharpen) enlargement += 6;
|
|
Shinya Kitaoka |
120a6e |
return enlargement;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void getWarpComputeRects(TRectD &outputComputeRect, TRectD &warpedComputeRect,
|
|
Shinya Kitaoka |
120a6e |
const TRectD &warpedBox, const TRectD &requestedRect,
|
|
Shinya Kitaoka |
120a6e |
const WarpParams ¶ms);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
//! Deals with raster tiles and invokes warper functions
|
|
Toshihiro Shimizu |
890ddd |
void warp(TRasterP &tileRas, const TRasterP &rasIn, TRasterP &warper,
|
|
Shinya Kitaoka |
120a6e |
TPointD rasInPos, TPointD warperPos, const WarpParams ¶ms);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif
|