geostat/heat.cpp

44 wiersze
1.4 KiB
C++

#include "heat.h"
#include "cache.h"
#include <heatmap.h>
#include <colorschemes/Spectral.h>
#include <Magick++.h>
#include <set>
#include <vector>
#include <string>
Heat::Heat(Caches* cc) : points(cc) {
#ifdef graphicsmagick
Magick::InitializeMagick(nullptr);
#endif
}
void Heat::generate(std::string filename, int size, bool relief, std::string theme) {
heatmap_t* hm = heatmap_new(size_x, size_y);
heatmap_stamp_t* stamp = heatmap_stamp_gen(size);
std::vector<unsigned char> image(size_x * size_y * 4);
for (auto el : *points) {
if (el.pos.lon >= lon_min && el.pos.lon <= lon_max && el.pos.lat >= lat_min && el.pos.lat <= lat_max)
heatmap_add_point_with_stamp(hm, (el.pos.lon - lon_min) / (lon_max - lon_min) * size_x, size_y - static_cast<int>((el.pos.lat - lat_min) / (lat_max - lat_min) * size_y), stamp);
// Debug(2) << static_cast<int>((el.pos.lon - lon_min) / (lon_max - lon_min) * size_x) << " " << size_y - static_cast<int>((el.pos.lat - lat_min) / (lat_max - lat_min) * size_y) << "\n";
}
heatmap_render_to(hm, heatmap_cs_Spectral_soft, &image[0]);
heatmap_free(hm);
Magick::Image contour;
if (relief)
contour.read(relief_file);
else
contour.read(contour_file);
Magick::Image heatmap(size_x, size_y, "RGBA", Magick::CharPixel, &image[0]);
contour.composite(heatmap, 0, 0, Magick::OverCompositeOp);
contour.write(filename);
// heatmap.write("geostat_heat.png");
}