Add functionality to send credits and target data to GUI

This commit is contained in:
Ylva Selling
2021-04-19 14:30:49 +02:00
parent a9b73fa352
commit 05a8580edc
4 changed files with 74 additions and 15 deletions

View File

@@ -11,6 +11,8 @@ namespace openspace {
struct ImageData {
std::string name;
std::string thumbnailUrl;
std::string credits;
std::string creditsUrl;
glm::vec2 celestCoords;
std::string collection;
float zoomLevel;
@@ -41,9 +43,9 @@ namespace openspace {
private:
int loadImage(tinyxml2::XMLElement* imageSet, std::string collectionName);
void setImageDataValues(tinyxml2::XMLElement* node, std::string thumbnail, std::string collectionName, ImageData& img);
void setImageDataValues(tinyxml2::XMLElement* node, std::string credits, std::string creditsUrl, std::string thumbnail, std::string collectionName, ImageData& img);
std::string getURLFromImageSet(tinyxml2::XMLElement* imageSet);
std::string getChildNodeContentFromImageSet(tinyxml2::XMLElement* imageSet, std::string elementName);
std::string getURLFromPlace(tinyxml2::XMLElement* place);
tinyxml2::XMLElement* getDirectChildNode(tinyxml2::XMLElement* node, std::string name);
tinyxml2::XMLElement* getChildNode(tinyxml2::XMLElement* node, std::string name);

View File

@@ -104,6 +104,14 @@ namespace openspace {
"Add one or multiple exoplanet systems to the scene, as specified by the "
"input. An input string should be the name of the system host star"
},
{
"getTargetData",
&skybrowser::luascriptfunctions::getTargetData,
{},
"string or list of strings",
"Add one or multiple exoplanet systems to the scene, as specified by the "
"input. An input string should be the name of the system host star"
},
};
return res;

View File

@@ -55,7 +55,7 @@ namespace openspace::skybrowser::luascriptfunctions {
glm::dvec3 imageCoordsGalactic = icrsToGalacticCartesian(resultImage.celestCoords.x, resultImage.celestCoords.y, 1.0);
browser->getSkyTarget()->lookAtGalacticCoord(imageCoordsGalactic);
// In WWT, VFOV = ZoomLevel / 6
// In WWT, the definition of ZoomLevel is: VFOV = ZoomLevel / 6
browser->setFieldOfView(resultImage.zoomLevel / 6);
}
browser->sendMessageToWWT(browser->createMessageForSettingForegroundOpacityWWT(100));
@@ -121,16 +121,52 @@ namespace openspace::skybrowser::luascriptfunctions {
lua_settable(L, -3);
ghoul::lua::push(L, "Thumbnail", url);
lua_settable(L, -3);
ghoul::lua::push(L, "Ra", images[i].celestCoords.x);
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);
ghoul::lua::push(L, "HasCoords", images[i].hasCoords);
lua_settable(L, -3);
ghoul::lua::push(L, "Credits", images[i].credits);
lua_settable(L, -3);
ghoul::lua::push(L, "CreditsUrl", images[i].creditsUrl);
lua_settable(L, -3);
// Set table for the current ImageData
lua_settable(L, -3);
}
return 1;
}
int getTargetData(lua_State* L) {
// Send image list to GUI
ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::getTargetData");
ScreenSpaceSkyBrowser* browser = dynamic_cast<ScreenSpaceSkyBrowser*>(global::renderEngine->screenSpaceRenderable("SkyBrowser1"));
ScreenSpaceSkyTarget* target = dynamic_cast<ScreenSpaceSkyTarget*>(global::renderEngine->screenSpaceRenderable("SkyTarget1"));
float FOV = browser->fieldOfView();
glm::vec2 coords = target->getCelestialCoords();
lua_newtable(L);
// Index for many browsers
// For now it's only one
ghoul::lua::push(L, 1);
lua_newtable(L);
// Push ("Key", value)
ghoul::lua::push(L, "FOV", FOV);
lua_settable(L, -3);
ghoul::lua::push(L, "RA", coords.x);
lua_settable(L, -3);
ghoul::lua::push(L, "Dec", coords.y);
lua_settable(L, -3);
// Set table for the current ImageData
lua_settable(L, -3);
return 1;
}
int adjustCamera(lua_State* L) {
ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::adjustCamera");

View File

@@ -137,31 +137,42 @@ namespace openspace {
return -1;
std::string url;
// Get url
if (std::string(node->Name()) == "ImageSet") {
url = getURLFromImageSet(node);
std::string credits;
std::string creditsUrl;
tinyxml2::XMLElement* imageSet = nullptr;
// Get url. The thumbnail can be located either in the Place or the ImageSet
if (std::string(node->Name()) == "ImageSet") {
url = getChildNodeContentFromImageSet(node, "ThumbnailUrl");
imageSet = node;
}
else if (std::string(node->Name()) == "Place") {
url = getURLFromPlace(node);
imageSet = getChildNode(node, "ImageSet");
}
// Only load images that have a thumbnail
if (url == "") {
else {
return -1;
}
// Only load images that have a thumbnail
if (url == "" || !imageSet) {
return -1;
}
// The credits are always children nodes of ImageSet
credits = getChildNodeContentFromImageSet(imageSet, "Credits");
creditsUrl = getChildNodeContentFromImageSet(imageSet, "CreditsUrl");
ImageData image{};
setImageDataValues(node, url, collectionName, image);
setImageDataValues(node, credits, creditsUrl, url, collectionName, image);
images.push_back(image);
// Return index of image in vector
return images.size();
}
std::string WWTDataHandler::getURLFromImageSet(tinyxml2::XMLElement* imageSet) {
std::string WWTDataHandler::getChildNodeContentFromImageSet(tinyxml2::XMLElement* imageSet, std::string elementName) {
// FInd the thumbnail image url
// The thumbnail is the last node so traverse backwards for speed
tinyxml2::XMLElement* imageSetChild = imageSet->FirstChildElement("ThumbnailUrl");
tinyxml2::XMLElement* imageSetChild = imageSet->FirstChildElement(elementName.c_str());
return imageSetChild ? imageSetChild->GetText() ? imageSetChild->GetText() : "" : "";
}
@@ -176,7 +187,7 @@ namespace openspace {
tinyxml2::XMLElement* imageSet = getChildNode(place, "ImageSet");
// If it doesn't contain an ImageSet, it doesn't have an url -> return empty string
// If there is an imageSet, collect thumbnail url
return imageSet ? getURLFromImageSet(imageSet) : "";
return imageSet ? getChildNodeContentFromImageSet(imageSet, "ThumbnailUrl") : "";
}
tinyxml2::XMLElement* WWTDataHandler::getDirectChildNode(tinyxml2::XMLElement* node, std::string name) {
@@ -198,7 +209,7 @@ namespace openspace {
return imageSet;
}
void WWTDataHandler::setImageDataValues(tinyxml2::XMLElement* node, std::string thumbnail, std::string collectionName, ImageData& img) {
void WWTDataHandler::setImageDataValues(tinyxml2::XMLElement* node, std::string credits, std::string creditsUrl, std::string thumbnail, std::string collectionName, ImageData& img) {
// Get attributes for the image
img.name = node->FindAttribute("Name") ? node->FindAttribute("Name")->Value() : "";
img.hasCoords = node->FindAttribute("RA") && node->FindAttribute("Dec");
@@ -210,6 +221,8 @@ namespace openspace {
img.collection = collectionName;
img.thumbnailUrl = thumbnail;
img.zoomLevel = node->FindAttribute("ZoomLevel") ? std::stof(node->FindAttribute("ZoomLevel")->Value()) : 0.f;
img.credits = credits;
img.creditsUrl = creditsUrl;
}
const std::vector<ImageData>& WWTDataHandler::getLoadedImages() const {