From a5175799ba9542508ebcd498042de994d0281f38 Mon Sep 17 00:00:00 2001 From: David Vereb Date: Sat, 13 Mar 2021 18:55:00 -0500 Subject: [PATCH] t --- main.cpp | 137 +++++++++++++++++++++++++++---------------------------- 1 file changed, 66 insertions(+), 71 deletions(-) diff --git a/main.cpp b/main.cpp index 6ae7c06..f36998c 100644 --- a/main.cpp +++ b/main.cpp @@ -1,3 +1,5 @@ +#include "rapidxml.hpp" + #include #include @@ -20,6 +22,65 @@ struct Point { static std::vector > tracks; +bool ParseFile(std::vector> &out_tracks, + const std::string &file_and_path) +{ + std::ifstream ifs(file_and_path); + if(!ifs.is_open()) + { + std::cerr << "Couldn't open " << file_and_path << "." << std::endl; + return -2; + } + + std::string line = ""; + bool first = true; + float diff_lat, diff_lon, diff_ele; + std::vector track; + while(std::getline(ifs, line)) + { + // get starting position of field NAME + auto lat = line.find("lat=\""); + if(lat == std::string::npos) + continue; + // get ending position of field DATA + auto lat_to = line.find("\"", lat); + if(lat_to == std::string::npos) + continue; + + // get starting position of field NAME + auto lon = line.find("lon=\"", lat_to); + if(lon == std::string::npos) + continue; + // get ending position of field DATA + auto lon_to = line.find("\"", lon); + if(lon_to == std::string::npos) + continue; + + auto ele = line.find("", lon_to); + if(ele == std::string::npos) + continue; + auto ele_to = line.find("", ele); + if(ele_to == std::string::npos) + continue; + + Point p; + try { + p.lat = std::atof(line.substr(lat + 5, lat_to).c_str()) * 200; + p.lon = std::atof(line.substr(lon + 5, lon_to).c_str()) * 200; + p.ele = std::atof(line.substr(ele + 5, ele_to).c_str()) * 0.1; + } catch (const std::exception &e) { + std::cerr << "Error in file " << file_and_path + << ", line \"" << line << "\"." + << std::endl; + continue; + } + + track.push_back(p); + } + out_tracks.push_back(track); + ifs.close(); +} + // TODO(dev): // As per https://www.opengl.org/resources/libraries/glut/spec3/node11.html // "Therefore, GLUT programs should not assume the window was created at the specified size or position. @@ -135,80 +196,14 @@ int main(int argc, char *argv[]) files.push_back(entry.path().string()); } - float file_diff_lat = -8; - float file_diff_lon = -8; for(auto file : files) { - std::ifstream ifs(file); - if(!ifs.is_open()) - { - std::cerr << "Couldn't open " << file << "." << std::endl; - return -2; - } + // NOTE(dev): OLD: + if(!ParseFile(tracks, file)) + return -3; // couldn't parse file - std::string line = ""; - bool first = true; - float diff_lat, diff_lon, diff_ele; - std::vector track; - while(std::getline(ifs, line)) - { - // get starting position of field NAME - auto lat = line.find("lat=\""); - if(lat == std::string::npos) - continue; - // get ending position of field DATA - auto lat_to = line.find("\"", lat); - if(lat_to == std::string::npos) - continue; - - // get starting position of field NAME - auto lon = line.find("lon=\"", lat_to); - if(lon == std::string::npos) - continue; - // get ending position of field DATA - auto lon_to = line.find("\"", lon); - if(lon_to == std::string::npos) - continue; - - auto ele = line.find("", lon_to); - if(ele == std::string::npos) - continue; - auto ele_to = line.find("", ele); - if(ele_to == std::string::npos) - continue; - - Point p; - try { - p.lat = std::atof(line.substr(lat + 5, lat_to).c_str()) * 200; - p.lon = std::atof(line.substr(lon + 5, lon_to).c_str()) * 200; - p.ele = std::atof(line.substr(ele + 5, ele_to).c_str()) * 0.1; - } catch (const std::exception &e) { - std::cerr << "Error in file " << file << ", line \"" << line << "\"." << std::endl; - continue; - } - - if(first) - { - first = false; - diff_lat = p.lat; - diff_lon = p.lon; - diff_ele = p.ele; - } - - p.lat -= diff_lat + file_diff_lat; - p.lon -= diff_lon + file_diff_lon; - p.ele -= diff_ele; - track.push_back(p); - } - tracks.push_back(track); - file_diff_lat += 4; - if(file_diff_lat > 5) - { - file_diff_lat = -8; - file_diff_lon += 4; - } - - ifs.close(); + // NOTE(dev): NEW: + // TODO(dev): Xml Parser } glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH | GLUT_ALPHA | GLUT_MULTISAMPLE);