geostat/heat.cpp

45 wiersze
1.4 KiB
C++
Czysty Zwykły widok Historia

2019-09-08 16:42:10 +00:00
#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, const Map* m) : points(cc), mp(m) {
2019-09-08 16:42:10 +00:00
#ifdef graphicsmagick
Magick::InitializeMagick(nullptr);
#endif
}
void Heat::generate(std::string filename, int size, std::string theme) {
heatmap_t* hm = heatmap_new(mp->size_x, mp->size_y);
2019-09-08 16:42:10 +00:00
heatmap_stamp_t* stamp = heatmap_stamp_gen(size);
std::vector<unsigned char> image(mp->size_x * mp->size_y * 4);
2019-09-08 16:42:10 +00:00
for (auto el : *points) {
if (mp->contains(Position(el.pos.lat, el.pos.lon))) {
heatmap_add_point_with_stamp(hm, mp->coordinate_x(Position(el.pos.lat, el.pos.lon)), mp->coordinate_y(Position(el.pos.lat, el.pos.lon)), stamp);
2019-09-10 12:03:01 +00:00
// std::cout << mp->coordinate_x(Position(el.pos.lon, el.pos.lat)) << '\t' << mp->coordinate_y(Position(el.pos.lon, el.pos.lat)) << '\n';
}
2019-09-08 16:42:10 +00:00
}
2019-09-12 12:07:46 +00:00
if (theme == "soft")
heatmap_render_to(hm, heatmap_cs_Spectral_soft, &image[0]);
else if (theme == "exp")
heatmap_render_to(hm, heatmap_cs_Spectral_mixed_exp, &image[0]);
else
throw 0;
2019-09-08 16:42:10 +00:00
heatmap_free(hm);
Magick::Image contour(mp->map_file);
Magick::Image heatmap(mp->size_x, mp->size_y, "RGBA", Magick::CharPixel, &image[0]);
2019-09-08 16:42:10 +00:00
contour.composite(heatmap, 0, 0, Magick::OverCompositeOp);
contour.write(filename);
// heatmap.write("geostat_heat.png");
}