From 5d089f4b86c415c0e85e0a9096ec9fd737b8b512 Mon Sep 17 00:00:00 2001 From: k-a-z-u Date: Tue, 3 Apr 2018 15:03:55 +0200 Subject: [PATCH] added support for multiple obj-pool folders --- wifi/estimate/ray3/OBJPool.h | 56 +++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/wifi/estimate/ray3/OBJPool.h b/wifi/estimate/ray3/OBJPool.h index d76edaf..6e258dc 100644 --- a/wifi/estimate/ray3/OBJPool.h +++ b/wifi/estimate/ray3/OBJPool.h @@ -13,6 +13,8 @@ //#include #include +#include "../../../misc/Debug.h" + namespace Ray3D { @@ -23,6 +25,8 @@ namespace Ray3D { private: + static constexpr const char* name = "OBJ-Pool"; + /** singleton */ OBJPool() {;} @@ -37,32 +41,23 @@ namespace Ray3D { return instance; } - /** data folder */ + /** init with *.obj data folder */ void init(const std::string& folder) { + scanFolder(folder); initDone = true; - // LINUX ONLY! - //DIR* d = opendir(folder.c_str()); - //if (!d) {throw Exception("OBJPool: folder not found: " + folder);} - std::experimental::filesystem::path d(folder); - if (!std::experimental::filesystem::exists(d)) { - throw Exception("OBJPool: folder not found: " + folder); - } + } - //struct dirent *dir; - //while ((dir = readdir(d)) != NULL) { - for (std::experimental::filesystem::directory_entry entry : std::experimental::filesystem::directory_iterator(d)) { - //const std::string absFile = folder + "/" + dir->d_name; - const std::string absFile = entry.path().native(); - if (endsWith(absFile, ".obj")) { - //std::string name = std::string(dir->d_name); - std::string name = entry.path().filename(); - name = name.substr(0, name.length() - 4); // without extension - load(absFile, name); - } + /** init with multiple *.obj data folder */ + void init(const std::initializer_list& folders) { + + for (const std::string& folder : folders) { + try { + scanFolder(folder); + } catch (...) {;} } - //closedir(d); + initDone = true; } @@ -85,6 +80,25 @@ namespace Ray3D { private: + /** scan the given folder for all *.obj files */ + void scanFolder(const std::string& folder) { + + std::experimental::filesystem::path d(folder); + if (!std::experimental::filesystem::exists(d)) { + throw Exception("OBJPool: folder not found: " + folder); + } + + for (std::experimental::filesystem::directory_entry entry : std::experimental::filesystem::directory_iterator(d)) { + const std::string absFile = entry.path().native(); + if (endsWith(absFile, ".obj")) { + std::string name = entry.path().filename(); + name = name.substr(0, name.length() - 4); // without extension + load(absFile, name); + } + } + + } + inline bool endsWith(std::string const & value, std::string const & ending) { if (ending.size() > value.size()) return false; return std::equal(ending.rbegin(), ending.rend(), value.rbegin()); @@ -104,6 +118,8 @@ namespace Ray3D { obs.triangles.push_back(tria); } + Log::add(this->name, "loaded: " + absName + " [" + std::to_string(obs.triangles.size()) + " triangles]", true); + // store cache[name] = obs;