Add amount of data to Image and make image sending process more efficient

This commit is contained in:
Ylva Selling
2021-04-09 15:03:18 +02:00
parent 4e358fe122
commit 03cb84c0e2
3 changed files with 28 additions and 39 deletions

View File

@@ -13,6 +13,8 @@ namespace openspace {
std::string thumbnailUrl;
glm::vec2 celestCoords;
std::string collection;
float zoomLevel;
bool hasCoords;
};
class WWTDataHandler {
@@ -28,7 +30,6 @@ namespace openspace {
int loadAllImagesFromXMLs();
const std::vector<std::string>& getAllImageCollectionUrls() const;
std::vector < std::pair < std::string, std::string> > getAllThumbnailUrls();
const std::vector<ImageData>& getLoadedImages() const;
private:

View File

@@ -1,15 +1,11 @@
#include <openspace/util/openspacemodule.h>
#include <openspace/documentation/documentation.h>
#include <modules/skybrowser/skybrowsermodule.h>
#include <openspace/engine/globals.h>
#include <openspace/engine/moduleengine.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/scripting/scriptengine.h>
#include <ghoul/misc/dictionaryluaformatter.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/fmt.h>
#include <ghoul/glm.h>
@@ -22,9 +18,8 @@
#include <openspace/interaction/navigationhandler.h>
#include <openspace/util/camera.h>
#include <thread>
#include <glm/gtx/string_cast.hpp>
#include <openspace/util/coordinateconversion.h>
#include <glm/gtx/rotate_vector.hpp>
namespace {
@@ -37,13 +32,14 @@ namespace openspace::skybrowser::luascriptfunctions {
int loadImgCollection(lua_State* L) {
// Load image
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::loadCollection");
const std::string& imageName = ghoul::lua::value<std::string>(L, 1);
ScreenSpaceSkyBrowser* browser = dynamic_cast<ScreenSpaceSkyBrowser*>(global::renderEngine->screenSpaceRenderable("SkyBrowser1"));
const int i = ghoul::lua::value<int>(L, 1);
ScreenSpaceSkyBrowser* browser = dynamic_cast<ScreenSpaceSkyBrowser*>(global::renderEngine->screenSpaceRenderable("SkyBrowser1"));
SkyBrowserModule* module = global::moduleEngine->module<SkyBrowserModule>();
const ImageData& resultImage = module->getWWTDataHandler()->getLoadedImages()[i];
browser->sendMessageToWWT(browser->createMessageForSettingForegroundWWT(resultImage.name));
LINFO("Loading image " + resultImage.name);
browser->sendMessageToWWT(browser->createMessageForSettingForegroundWWT(imageName));
LINFO("Loading image " + imageName);
// browser->sendMessageToWWT(browser->createMessageForMovingWWTCamera(glm::vec2(0.712305533333333, 41.269167), 24.0f));
browser->sendMessageToWWT(browser->createMessageForSettingForegroundOpacityWWT(100));
return 1;
}
@@ -70,10 +66,12 @@ namespace openspace::skybrowser::luascriptfunctions {
LINFO("Loaded " + noOfLoadedImgs + " WorldWide Telescope images.");
ScreenSpaceSkyBrowser* browser = dynamic_cast<ScreenSpaceSkyBrowser*>(global::renderEngine->screenSpaceRenderable("SkyBrowser1"));
const std::vector<std::string>& imageUrls = module->getWWTDataHandler()->getAllImageCollectionUrls();
for (const std::string url : imageUrls) {
browser->sendMessageToWWT(browser->createMessageForLoadingWWTImgColl(url));
}
//const std::vector<std::string>& imageUrls = module->getWWTDataHandler()->getAllImageCollectionUrls();
//for (const std::string url : imageUrls) {
// browser->sendMessageToWWT(browser->createMessageForLoadingWWTImgColl(url));
//}
std::string root = "https://raw.githubusercontent.com/WorldWideTelescope/wwt-web-client/master/assets/webclient-explore-root.wtml";
browser->sendMessageToWWT(browser->createMessageForLoadingWWTImgColl(root));
return 1;
}
@@ -86,21 +84,19 @@ namespace openspace::skybrowser::luascriptfunctions {
moveBrowser(L);
}
std::vector<std::pair<std::string, std::string>> names = module->getWWTDataHandler()->getAllThumbnailUrls();
const std::vector<ImageData>& images = module->getWWTDataHandler()->getLoadedImages();
lua_newtable(L);
int number = 1;
for (const std::pair<std::string, std::string>& s : names) {
for (int i = 0; i < images.size(); i++) {
// Push a table { image name, image url } with index : number
lua_newtable(L);
lua_pushstring(L, s.first.c_str());
lua_pushstring(L, images[i].name.c_str());
lua_rawseti(L, -2, 1);
lua_pushstring(L, s.second.c_str());
lua_pushstring(L, images[i].thumbnailUrl.c_str());
lua_rawseti(L, -2, 2);
lua_rawseti(L, -2, number);
++number;
lua_rawseti(L, -2, i+1);
}
return 1;

View File

@@ -66,7 +66,7 @@ namespace openspace {
for (const auto& entry : std::filesystem::directory_iterator(directory)) {
tinyxml2::XMLDocument* doc = new tinyxml2::XMLDocument();
std::cout << entry.path().u8string().c_str() << std::endl;
if (doc->LoadFile(entry.path().u8string().c_str()) == tinyxml2::XMLError::XML_SUCCESS) {
xmls.push_back(doc);
}
@@ -87,10 +87,6 @@ namespace openspace {
std::string collectionName = root->FindAttribute("Name") ? root->FindAttribute("Name")->Value() : "";
loadImagesFromXML(root, collectionName);
}
for (ImageData img : images) {
std::cout << img;
}
return images.size();
}
@@ -192,21 +188,17 @@ namespace openspace {
return imageSet;
}
std::vector < std::pair < std::string, std::string> > WWTDataHandler::getAllThumbnailUrls() {
std::vector < std::pair < std::string, std::string> > imgResult;
std::for_each(images.begin(), images.end(), [&](ImageData obj) {
imgResult.push_back(std::pair(obj.name, obj.thumbnailUrl));
});
return imgResult;
}
void WWTDataHandler::setImageDataValues(tinyxml2::XMLElement* node, std::string thumbnail, std::string collectionName, ImageData& img) {
// Get attributes for the image
img.name = node->FindAttribute("Name") ? node->FindAttribute("Name")->Value() : "";
img.celestCoords.x = node->FindAttribute("RA") ? std::stof(node->FindAttribute("RA")->Value()) : 0.f;
img.celestCoords.y = node->FindAttribute("Dec") ? std::stof(node->FindAttribute("Dec")->Value()) : 0.f;
img.hasCoords = node->FindAttribute("RA") && node->FindAttribute("Dec");
if (img.hasCoords) {
img.celestCoords.x = std::stof(node->FindAttribute("RA")->Value());
img.celestCoords.y = std::stof(node->FindAttribute("Dec")->Value());
}
img.collection = collectionName;
img.thumbnailUrl = thumbnail;
img.zoomLevel = node->FindAttribute("ZoomLevel") ? std::stof(node->FindAttribute("ZoomLevel")->Value()) : 0.f;
}
const std::vector<ImageData>& WWTDataHandler::getLoadedImages() const {