diff --git a/modules/skybrowser/include/wwtdatahandler.h b/modules/skybrowser/include/wwtdatahandler.h index fc93c3954b..4d292580fd 100644 --- a/modules/skybrowser/include/wwtdatahandler.h +++ b/modules/skybrowser/include/wwtdatahandler.h @@ -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& getAllImageCollectionUrls() const; - std::vector < std::pair < std::string, std::string> > getAllThumbnailUrls(); const std::vector& getLoadedImages() const; private: diff --git a/modules/skybrowser/skybrowsermodule_lua.inl b/modules/skybrowser/skybrowsermodule_lua.inl index b3df686425..6f612f24e1 100644 --- a/modules/skybrowser/skybrowsermodule_lua.inl +++ b/modules/skybrowser/skybrowsermodule_lua.inl @@ -1,15 +1,11 @@ #include - - #include #include #include #include #include - #include #include - #include #include #include @@ -22,9 +18,8 @@ #include #include #include - +#include #include -#include 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(L, 1); - - ScreenSpaceSkyBrowser* browser = dynamic_cast(global::renderEngine->screenSpaceRenderable("SkyBrowser1")); + const int i = ghoul::lua::value(L, 1); + + ScreenSpaceSkyBrowser* browser = dynamic_cast(global::renderEngine->screenSpaceRenderable("SkyBrowser1")); + SkyBrowserModule* module = global::moduleEngine->module(); + 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(global::renderEngine->screenSpaceRenderable("SkyBrowser1")); - const std::vector& imageUrls = module->getWWTDataHandler()->getAllImageCollectionUrls(); - for (const std::string url : imageUrls) { - browser->sendMessageToWWT(browser->createMessageForLoadingWWTImgColl(url)); - } + //const std::vector& 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> names = module->getWWTDataHandler()->getAllThumbnailUrls(); + const std::vector& images = module->getWWTDataHandler()->getLoadedImages(); lua_newtable(L); - int number = 1; - for (const std::pair& 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; diff --git a/modules/skybrowser/src/wwtdatahandler.cpp b/modules/skybrowser/src/wwtdatahandler.cpp index 9b3cff79d7..01413700e7 100644 --- a/modules/skybrowser/src/wwtdatahandler.cpp +++ b/modules/skybrowser/src/wwtdatahandler.cpp @@ -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& WWTDataHandler::getLoadedImages() const {