17 #ifndef IGNITION_COMMON_IMAGEHEIGHTMAPDATA_HH_ 18 #define IGNITION_COMMON_IMAGEHEIGHTMAPDATA_HH_ 25 #include <ignition/common/graphics/Export.hh> 44 public:
int Load(
const std::string &_filename =
"");
47 public:
void FillHeightMap(
int _subSampling,
unsigned int _vertSize,
57 public:
unsigned int Height()
const;
60 public:
unsigned int Width()
const;
63 public:
float MaxElevation()
const;
78 private:
template <
typename T>
79 void FillHeights(T *_data,
int _imgHeight,
int _imgWidth,
80 unsigned int _pitch,
int _subSampling,
unsigned int _vertSize,
86 const unsigned int bpp = _pitch / _imgWidth;
88 const unsigned int channels = bpp /
sizeof(T);
90 const unsigned int pitchInPixels = _pitch / bpp;
92 const double maxPixelValue =
96 for (
unsigned int y = 0; y < _vertSize; ++y)
99 const double yf = y /
static_cast<double>(_subSampling);
100 const int y1 =
static_cast<int>(
std::floor(yf));
101 int y2 =
static_cast<int>(
std::ceil(yf));
102 if (y2 >= _imgHeight)
104 const double dy = yf - y1;
106 for (
unsigned int x = 0; x < _vertSize; ++x)
108 const double xf = x /
static_cast<double>(_subSampling);
109 const int x1 =
static_cast<int>(
std::floor(xf));
110 int x2 =
static_cast<int>(
std::ceil(xf));
113 const double dx = xf - x1;
115 const double px1 =
static_cast<int>(
116 _data[(y1 * pitchInPixels + x1) * channels]) / maxPixelValue;
117 const double px2 =
static_cast<int>(
118 _data[(y1 * pitchInPixels + x2) * channels]) / maxPixelValue;
119 const float h1 = (px1 - ((px1 - px2) * dx));
121 const double px3 =
static_cast<int>(
122 _data[(y2 * pitchInPixels + x1) * channels]) / maxPixelValue;
123 const double px4 =
static_cast<int>(
124 _data[(y2 * pitchInPixels + x2) * channels]) / maxPixelValue;
125 const float h2 = (px3 - ((px3 - px4) * dx));
126 float h = (h1 - ((h1 - h2) * dy)) * _scale.
Z();
136 _heights[y * _vertSize + x] = h;
138 _heights[(_vertSize - y - 1) * _vertSize + x] = h;
Encapsulates a generic heightmap data file.
Definition: HeightmapData.hh:29
Encapsulates an image that will be interpreted as a heightmap.
Definition: ImageHeightmap.hh:34
Forward declarations for the common classes.
Encapsulates an image.
Definition: Image.hh:60