Skip to content

Commit

Permalink
Add mass downloading around a specific point
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGreatRambler committed Apr 8, 2023
1 parent caf1cc8 commit 851f528
Show file tree
Hide file tree
Showing 5 changed files with 254 additions and 43 deletions.
16 changes: 14 additions & 2 deletions src/download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ sk_sp<SkImage> download_panorama(CURL* curl_handle, std::string panorama_id, int
sk_sp<SkSurface> tile_surface
= SkSurface::MakeRasterN32Premul(tiles_width * 512, tiles_height * 512);

fmt::print("Downloading {} tiles\n", tiles_width * tiles_height);

// Start processing
tile_surface->getCanvas()->clear(SK_ColorWHITE);
for(int y = 0; y < tiles_height; y++) {
Expand Down Expand Up @@ -142,4 +140,18 @@ sk_sp<SkImage> download_panorama(CURL* curl_handle, std::string panorama_id, int
}

return tile_surface->makeImageSnapshot();
}

std::vector<Panorama> get_infos(
CURL* curl_handle, std::string client_id, std::vector<std::string>& ids) {
std::vector<Panorama> infos;
for(auto& id : ids) {
// Get photometa
auto photometa_document = download_photometa(curl_handle, client_id, id);

// Get info
auto panorama_info = extract_info(photometa_document);
infos.push_back(panorama_info);
}
return infos;
}
6 changes: 5 additions & 1 deletion src/download.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include <string>

#include "extract.hpp"

std::string download_from_url(
std::string url, CURL* curl_handle, CURLcode* res, curl_slist* headers);
std::string download_client_id(CURL* curl_handle);
Expand All @@ -15,4 +17,6 @@ rapidjson::Document download_preview_document(
rapidjson::Document download_photometa(
CURL* curl_handle, std::string client_id, std::string panorama_id);
sk_sp<SkImage> download_panorama(CURL* curl_handle, std::string panorama_id, int streetview_zoom,
rapidjson::Document& photmeta_document);
rapidjson::Document& photmeta_document);
std::vector<Panorama> get_infos(
CURL* curl_handle, std::string client_id, std::vector<std::string>& ids);
48 changes: 39 additions & 9 deletions src/extract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,33 @@ Panorama extract_info(rapidjson::Document& photometa_document) {
auto& id = photometa_document[1][0][1][1];
auto& lat_long = photometa_document[1][0][5][0][1][0];
auto& yaw_pitch_roll = photometa_document[1][0][5][0][1][2];
auto& year_month = photometa_document[1][0][6][7];
return Panorama {
.id = id.GetString(),
.lat = lat_long[2].GetDouble(),
.lng = lat_long[3].GetDouble(),
.yaw = yaw_pitch_roll[0].GetDouble() * DEG_RAD,
.pitch = yaw_pitch_roll[1].GetDouble() * DEG_RAD,
.roll = yaw_pitch_roll[2].GetDouble() * DEG_RAD,
.month = year_month[1].GetInt(),
.year = year_month[0].GetInt(),
};
}

Location extract_location(rapidjson::Document& photometa_document) {
Location location;
auto& outer_location = photometa_document[1][0][3][2];
if(outer_location.Size() == 1) {
// No address, just city
location.city_and_state = std::string(outer_location[0].GetString());
} else if(outer_location.Size() == 2) {
// Address and city
location.street = std::string(outer_location[0].GetString());
location.city_and_state = std::string(outer_location[1].GetString());
// Can segfault
if(photometa_document[1][0][3].Size() > 2) {
auto& outer_location = photometa_document[1][0][3][2];
if(outer_location.Size() == 1) {
// No address, just city
location.city_and_state = std::string(outer_location[0].GetString());
} else if(outer_location.Size() == 2) {
// Address and city
location.street = std::string(outer_location[0].GetString());
location.city_and_state = std::string(outer_location[1].GetString());
}
}

return location;
}

Expand Down Expand Up @@ -80,4 +85,29 @@ std::pair<double, double> extract_tiles_dimensions(
double tiles_width = tiles_dimensions[1].GetInt() / 512 / pow(2, 5 - streetview_zoom);
double tiles_height = tiles_dimensions[0].GetInt() / 512 / pow(2, 5 - streetview_zoom);
return std::make_pair(tiles_width, tiles_height);
}

bool valid_photometa(rapidjson::Document& photometa_document) {
// For starters
return photometa_document.Size() > 0;
}

double center_distance(double lat, double lng, Panorama& panorama) {
return std::sqrt(std::pow(panorama.lat - lat, 2) + std::pow(panorama.lng - lng, 2));
}

int num_within_distance(double lat, double lng, double radius, std::vector<Panorama>& panoramas) {
int num = 0;
for(auto& panorama : panoramas) {
if(center_distance(lat, lng, panorama) <= radius) {
num++;
}
}
return num;
}

void sort_by_distance(double lat, double lng, std::vector<Panorama>& panoramas) {
std::sort(panoramas.begin(), panoramas.end(), [&](Panorama& a, Panorama& b) {
return center_distance(lat, lng, a) < center_distance(lat, lng, b);
});
}
8 changes: 7 additions & 1 deletion src/extract.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ struct Panorama {
double yaw;
double pitch;
double roll;
int month = 0;
int year = 0;
std::string id;
};

Expand All @@ -25,4 +27,8 @@ Panorama extract_info(rapidjson::Document& photometa_document);
Location extract_location(rapidjson::Document& photometa_document);
std::vector<Panorama> extract_adjacent_panoramas(rapidjson::Document& photometa_document);
std::pair<double, double> extract_tiles_dimensions(
rapidjson::Document& photometa_document, int streetview_zoom);
rapidjson::Document& photometa_document, int streetview_zoom);
bool valid_photometa(rapidjson::Document& photometa_document);
double center_distance(double lat, double lng, Panorama& panorama);
int num_within_distance(double lat, double lng, double radius, std::vector<Panorama>& panoramas);
void sort_by_distance(double lat, double lng, std::vector<Panorama>& panoramas);
Loading

0 comments on commit 851f528

Please sign in to comment.