diff --git a/modules/skybrowser/skybrowsermodule.cpp b/modules/skybrowser/skybrowsermodule.cpp index a1a2c58c2a..74fa57f026 100644 --- a/modules/skybrowser/skybrowsermodule.cpp +++ b/modules/skybrowser/skybrowsermodule.cpp @@ -65,8 +65,8 @@ namespace openspace { res.name = "skybrowser"; res.functions = { { - "create", - &skybrowser::luascriptfunctions::createBrowser, + "getListOfImages", + &skybrowser::luascriptfunctions::getListOfImages, {}, "string or list of strings", "Add one or multiple exoplanet systems to the scene, as specified by the " @@ -89,8 +89,8 @@ namespace openspace { "input. An input string should be the name of the system host star" }, { - "loadCollection", - &skybrowser::luascriptfunctions::loadImgCollection, + "selectImage", + &skybrowser::luascriptfunctions::selectImage, {}, "string or list of strings", "Add one or multiple exoplanet systems to the scene, as specified by the " diff --git a/modules/skybrowser/skybrowsermodule_lua.inl b/modules/skybrowser/skybrowsermodule_lua.inl index 8e178bb349..c40b3e695e 100644 --- a/modules/skybrowser/skybrowsermodule_lua.inl +++ b/modules/skybrowser/skybrowsermodule_lua.inl @@ -29,9 +29,9 @@ namespace { namespace openspace::skybrowser::luascriptfunctions { - int loadImgCollection(lua_State* L) { + int selectImage(lua_State* L) { // Load image - ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::loadCollection"); + ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::selectImage"); const int i = ghoul::lua::value(L, 1); ScreenSpaceSkyBrowser* browser = dynamic_cast(global::renderEngine->screenSpaceRenderable("SkyBrowser1")); @@ -52,11 +52,10 @@ namespace openspace::skybrowser::luascriptfunctions { if (resultImage.hasCoords) { - // The RA from WWT is in the unit hours: to convert to degrees, multiply with 360 (deg) /24 (h)=15 - glm::dvec3 imageCoordsGalactic = icrsToGalacticCartesian(resultImage.celestCoords.x * 15, resultImage.celestCoords.y, 1.0); + glm::dvec3 imageCoordsGalactic = icrsToGalacticCartesian(resultImage.celestCoords.x, resultImage.celestCoords.y, 1.0); browser->getSkyTarget()->lookAtGalacticCoord(imageCoordsGalactic); - // In WWT, VFOV = ZoomLevel * 6 + // In WWT, VFOV = ZoomLevel / 6 browser->setFieldOfView(resultImage.zoomLevel / 6); } browser->sendMessageToWWT(browser->createMessageForSettingForegroundOpacityWWT(100)); @@ -67,11 +66,11 @@ namespace openspace::skybrowser::luascriptfunctions { // Load images from url ghoul::lua::checkArgumentsAndThrow(L, 2, "lua::followCamera"); - //SkyBrowserModule* module = global::moduleEngine->module(); - //std::string root = "https://raw.githubusercontent.com/WorldWideTelescope/wwt-web-client/master/assets/webclient-explore-root.wtml"; + SkyBrowserModule* module = global::moduleEngine->module(); + std::string root = "https://raw.githubusercontent.com/WorldWideTelescope/wwt-web-client/master/assets/webclient-explore-root.wtml"; - //module->getWWTDataHandler()->loadWTMLCollectionsFromURL(root, "root"); - //LINFO(std::to_string( module->getWWTDataHandler()->loadAllImagesFromXMLs())); + module->getWWTDataHandler()->loadWTMLCollectionsFromURL(root, "root"); + LINFO(std::to_string( module->getWWTDataHandler()->loadAllImagesFromXMLs())); return 1; } @@ -94,29 +93,40 @@ namespace openspace::skybrowser::luascriptfunctions { return 1; } - int createBrowser(lua_State* L) { + int getListOfImages(lua_State* L) { // Send image list to GUI - ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::createBrowser"); + ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::getListOfImages"); SkyBrowserModule* module = global::moduleEngine->module(); // If no data has been loaded yet, load it! if (module->getWWTDataHandler()->getLoadedImages().size() == 0) { + // Read from disc moveBrowser(L); - //followCamera(L); + // Read from URL + // followCamera(L); } - + + // Create Lua table to send to the GUI const std::vector& images = module->getWWTDataHandler()->getLoadedImages(); - - lua_newtable(L); + lua_newtable(L); for (int i = 0; i < images.size(); i++) { - // Push a table { image name, image url } with index : number - lua_newtable(L); - lua_pushstring(L, images[i].name.c_str()); - lua_rawseti(L, -2, 1); - lua_pushstring(L, images[i].thumbnailUrl.c_str()); - lua_rawseti(L, -2, 2); - - lua_rawseti(L, -2, i+1); + std::string name = images[i].name != "" ? images[i].name : "undefined"; + std::string url = images[i].thumbnailUrl != "" ? images[i].thumbnailUrl : "undefined"; + + // Index for current ImageData + ghoul::lua::push(L, i + 1); + lua_newtable(L); + // Push ("Key", value) + ghoul::lua::push(L, "Name", name); + lua_settable(L, -3); + ghoul::lua::push(L, "Thumbnail", url); + lua_settable(L, -3); + ghoul::lua::push(L, "Ra", images[i].celestCoords.x); + lua_settable(L, -3); + ghoul::lua::push(L, "Dec", images[i].celestCoords.y); + lua_settable(L, -3); + // Set table for the current ImageData + lua_settable(L, -3); } return 1; diff --git a/modules/skybrowser/src/wwtdatahandler.cpp b/modules/skybrowser/src/wwtdatahandler.cpp index 08774747aa..70e7b9b7b3 100644 --- a/modules/skybrowser/src/wwtdatahandler.cpp +++ b/modules/skybrowser/src/wwtdatahandler.cpp @@ -203,7 +203,8 @@ namespace openspace { img.name = node->FindAttribute("Name") ? node->FindAttribute("Name")->Value() : ""; img.hasCoords = node->FindAttribute("RA") && node->FindAttribute("Dec"); if (img.hasCoords) { - img.celestCoords.x = std::stof(node->FindAttribute("RA")->Value()); + // The RA from WWT is in the unit hours: to convert to degrees, multiply with 360 (deg) /24 (h) = 15 + img.celestCoords.x = 15.0f * std::stof(node->FindAttribute("RA")->Value()); img.celestCoords.y = std::stof(node->FindAttribute("Dec")->Value()); } img.collection = collectionName;