Go to the documentation of this file.
17 #ifndef IGNITION_COMMON_IMAGEHEIGHTMAPDATA_HH_
18 #define IGNITION_COMMON_IMAGEHEIGHTMAPDATA_HH_
23 #include <gz/math/Vector3.hh>
25 #include <gz/common/config.hh>
26 #include <gz/common/graphics/Export.hh>
45 public:
int Load(
const std::string &_filename =
"");
48 public:
void FillHeightMap(
int _subSampling,
unsigned int _vertSize,
58 public:
unsigned int Height()
const;
61 public:
unsigned int Width()
const;
64 public:
float MaxElevation()
const;
79 private:
template <
typename T>
80 void FillHeights(T *_data,
int _imgHeight,
int _imgWidth,
81 unsigned int _pitch,
int _subSampling,
unsigned int _vertSize,
87 const unsigned int bpp = _pitch / _imgWidth;
89 const unsigned int channels = bpp /
sizeof(T);
91 const unsigned int pitchInPixels = _pitch / bpp;
93 const double maxPixelValue =
97 for (
unsigned int y = 0; y < _vertSize; ++y)
100 const double yf = y /
static_cast<double>(_subSampling);
101 const int y1 =
static_cast<int>(
std::floor(yf));
102 int y2 =
static_cast<int>(
std::ceil(yf));
103 if (y2 >= _imgHeight)
105 const double dy = yf - y1;
107 for (
unsigned int x = 0; x < _vertSize; ++x)
109 const double xf = x /
static_cast<double>(_subSampling);
110 const int x1 =
static_cast<int>(
std::floor(xf));
111 int x2 =
static_cast<int>(
std::ceil(xf));
114 const double dx = xf - x1;
116 const double px1 =
static_cast<int>(
117 _data[(y1 * pitchInPixels + x1) * channels]) / maxPixelValue;
118 const double px2 =
static_cast<int>(
119 _data[(y1 * pitchInPixels + x2) * channels]) / maxPixelValue;
120 const float h1 = (px1 - ((px1 - px2) * dx));
122 const double px3 =
static_cast<int>(
123 _data[(y2 * pitchInPixels + x1) * channels]) / maxPixelValue;
124 const double px4 =
static_cast<int>(
125 _data[(y2 * pitchInPixels + x2) * channels]) / maxPixelValue;
126 const float h2 = (px3 - ((px3 - px4) * dx));
127 float h = (h1 - ((h1 - h2) * dy)) * _scale.
Z();
137 _heights[y * _vertSize + x] = h;
139 _heights[(_vertSize - y - 1) * _vertSize + x] = h;
Forward declarations for the common classes.
Encapsulates an image that will be interpreted as a heightmap.
Definition: gz/common/ImageHeightmap.hh:35
Encapsulates a generic heightmap data file.
Definition: gz/common/HeightmapData.hh:31
Encapsulates an image.
Definition: gz/common/Image.hh:63