58 public:
unsigned int Width()
const;
76 private:
template <
typename T>
77 void FillHeights(T *_data,
int _imgHeight,
int _imgWidth,
78 unsigned int _pitch,
int _subSampling,
unsigned int _vertSize,
84 const unsigned int bpp = _pitch / _imgWidth;
86 const unsigned int channels = bpp /
sizeof(T);
88 const unsigned int pitchInPixels = _pitch / bpp;
90 const double maxPixelValue =
94 for (
unsigned int y = 0; y < _vertSize; ++y)
97 const double yf = y /
static_cast<double>(_subSampling);
98 const int y1 =
static_cast<int>(
std::floor(yf));
100 if (y2 >= _imgHeight)
102 const double dy = yf - y1;
104 for (
unsigned int x = 0; x < _vertSize; ++x)
106 const double xf = x /
static_cast<double>(_subSampling);
107 const int x1 =
static_cast<int>(
std::floor(xf));
108 int x2 =
static_cast<int>(
std::ceil(xf));
111 const double dx = xf - x1;
113 const double px1 =
static_cast<int>(
114 _data[(y1 * pitchInPixels + x1) * channels]) / maxPixelValue;
115 const double px2 =
static_cast<int>(
116 _data[(y1 * pitchInPixels + x2) * channels]) / maxPixelValue;
117 const float h1 = (px1 - ((px1 - px2) * dx));
119 const double px3 =
static_cast<int>(
120 _data[(y2 * pitchInPixels + x1) * channels]) / maxPixelValue;
121 const double px4 =
static_cast<int>(
122 _data[(y2 * pitchInPixels + x2) * channels]) / maxPixelValue;
123 const float h2 = (px3 - ((px3 - px4) * dx));
124 float h = (h1 - ((h1 - h2) * dy)) * _scale.
Z();
134 _heights[y * _vertSize + x] = h;
136 _heights[(_vertSize - y - 1) * _vertSize + x] = h;