59 public:
unsigned int Width()
const;
77 private:
template <
typename T>
78 void FillHeights(T *_data,
int _imgHeight,
int _imgWidth,
79 unsigned int _pitch,
int _subSampling,
unsigned int _vertSize,
85 const unsigned int bpp = _pitch / _imgWidth;
87 const unsigned int channels = bpp /
sizeof(T);
89 const unsigned int pitchInPixels = _pitch / bpp;
91 const double maxPixelValue =
95 for (
unsigned int y = 0; y < _vertSize; ++y)
98 const double yf = y /
static_cast<double>(_subSampling);
99 const int y1 =
static_cast<int>(
std::floor(yf));
100 int y2 =
static_cast<int>(
std::ceil(yf));
101 if (y2 >= _imgHeight)
103 const double dy = yf - y1;
105 for (
unsigned int x = 0; x < _vertSize; ++x)
107 const double xf = x /
static_cast<double>(_subSampling);
108 const int x1 =
static_cast<int>(
std::floor(xf));
109 int x2 =
static_cast<int>(
std::ceil(xf));
112 const double dx = xf - x1;
114 const double px1 =
static_cast<int>(
115 _data[(y1 * pitchInPixels + x1) * channels]) / maxPixelValue;
116 const double px2 =
static_cast<int>(
117 _data[(y1 * pitchInPixels + x2) * channels]) / maxPixelValue;
118 const float h1 = (px1 - ((px1 - px2) * dx));
120 const double px3 =
static_cast<int>(
121 _data[(y2 * pitchInPixels + x1) * channels]) / maxPixelValue;
122 const double px4 =
static_cast<int>(
123 _data[(y2 * pitchInPixels + x2) * channels]) / maxPixelValue;
124 const float h2 = (px3 - ((px3 - px4) * dx));
125 float h = (h1 - ((h1 - h2) * dy)) * _scale.
Z();
135 _heights[y * _vertSize + x] = h;
137 _heights[(_vertSize - y - 1) * _vertSize + x] = h;