kopia lustrzana https://gitlab.com/tomaszg/geostat
45 wiersze
1.4 KiB
C++
45 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, const Map* m) : points(cc), mp(m) {
|
|
#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);
|
|
heatmap_stamp_t* stamp = heatmap_stamp_gen(size);
|
|
std::vector<unsigned char> image(mp->size_x * mp->size_y * 4);
|
|
|
|
for (auto el : *points) {
|
|
if (mp->contains(Position(el.pos.lat, el.pos.lon)) && el.type != "Moving" && el.type != "Own") {
|
|
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);
|
|
// std::cout << mp->coordinate_x(Position(el.pos.lon, el.pos.lat)) << '\t' << mp->coordinate_y(Position(el.pos.lon, el.pos.lat)) << '\n';
|
|
}
|
|
}
|
|
|
|
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;
|
|
heatmap_free(hm);
|
|
|
|
Magick::Image contour(mp->map_file);
|
|
Magick::Image heatmap(mp->size_x, mp->size_y, "RGBA", Magick::CharPixel, &image[0]);
|
|
|
|
contour.composite(heatmap, 0, 0, Magick::OverCompositeOp);
|
|
contour.write(filename);
|
|
// heatmap.write("geostat_heat.png");
|
|
}
|