From 2829d726de2f086d9400cd9fc2c56ea8944e5911 Mon Sep 17 00:00:00 2001 From: Ylva Selling Date: Mon, 18 Apr 2022 15:35:56 -0400 Subject: [PATCH] Add functionality to check if the image collection has been loaded and pass that information to the GUI --- modules/server/src/topics/skybrowsertopic.cpp | 1 + modules/skybrowser/include/browser.h | 7 ++--- .../include/screenspaceskybrowser.h | 5 ++-- .../skybrowser/include/targetbrowserpair.h | 3 ++ modules/skybrowser/include/wwtcommunicator.h | 9 +++--- modules/skybrowser/skybrowsermodule.cpp | 9 ++++-- modules/skybrowser/skybrowsermodule_lua.inl | 27 ++++++++++++++++- modules/skybrowser/src/targetbrowserpair.cpp | 14 ++++++++- modules/skybrowser/src/wwtcommunicator.cpp | 30 ++++++++++++------- 9 files changed, 79 insertions(+), 26 deletions(-) diff --git a/modules/server/src/topics/skybrowsertopic.cpp b/modules/server/src/topics/skybrowsertopic.cpp index 6c30e47cf4..8af29926bc 100644 --- a/modules/server/src/topics/skybrowsertopic.cpp +++ b/modules/server/src/topics/skybrowsertopic.cpp @@ -123,6 +123,7 @@ void SkyBrowserTopic::sendBrowserData() { target.setValue("roll", pair->targetRoll()); target.setValue("color", pair->borderColor()); target.setValue("cartesianDirection", cartesian); + target.setValue("isImageCollectionLoaded", pair->isImageCollectionLoaded()); target.setValue("isFacingCamera", pair->isFacingCamera()); target.setValue("isUsingRae", pair->isUsingRadiusAzimuthElevation()); target.setValue("selectedImages", selectedImagesVector); diff --git a/modules/skybrowser/include/browser.h b/modules/skybrowser/include/browser.h index d690169631..90898bad73 100644 --- a/modules/skybrowser/include/browser.h +++ b/modules/skybrowser/include/browser.h @@ -86,6 +86,9 @@ protected: void executeJavascript(const std::string& script) const; + bool _isUrlDirty = false; + bool _isDimensionsDirty = false; + bool _shouldReload = false; private: class RenderHandler : public WebRenderHandler { public: @@ -98,10 +101,6 @@ private: std::unique_ptr _browserInstance; CefRefPtr _renderHandler; CefRefPtr _keyboardHandler; - - bool _isUrlDirty = false; - bool _isDimensionsDirty = false; - bool _shouldReload = false; }; } // namespace openspace diff --git a/modules/skybrowser/include/screenspaceskybrowser.h b/modules/skybrowser/include/screenspaceskybrowser.h index a39b72d8dd..2094c5b423 100644 --- a/modules/skybrowser/include/screenspaceskybrowser.h +++ b/modules/skybrowser/include/screenspaceskybrowser.h @@ -48,15 +48,14 @@ public: float opacity() const; glm::vec2 size() const; + glm::dvec2 fineTuneVector(const glm::dvec2& drag); void setVerticalFovWithScroll(float scroll); void setOpacity(float opacity); void setScreenSpaceSize(glm::vec2 newSize); - void updateScreenSpaceSize(); - - glm::dvec2 fineTuneVector(const glm::dvec2& drag); void setIdInBrowser() const; + void updateScreenSpaceSize(); void updateTextureResolution(); // Copies rendered diff --git a/modules/skybrowser/include/targetbrowserpair.h b/modules/skybrowser/include/targetbrowserpair.h index 1e5a20d59f..1886b93f53 100644 --- a/modules/skybrowser/include/targetbrowserpair.h +++ b/modules/skybrowser/include/targetbrowserpair.h @@ -61,6 +61,7 @@ public: void sendIdToBrowser() const; void updateBrowserSize(); std::vector> renderCopies() const; + bool isImageCollectionLoaded(); // Target void centerTargetOnScreen(); @@ -79,6 +80,7 @@ public: void setBorderColor(const glm::ivec3& color); void setScreenSpaceSize(const glm::vec2& dimensions); void setVerticalFovWithScroll(float scroll); + void setImageCollectionIsLoaded(bool isLoaded); double verticalFov() const; glm::ivec3 borderColor() const; @@ -97,6 +99,7 @@ public: // WorldWide Telescope image handling void setImageOrder(int i, int order); void selectImage(const ImageData& image, int i); + void addImageLayerToWwt(const std::string& url, int i); void removeSelectedImage(int i); void loadImageCollection(const std::string& collection); void setImageOpacity(int i, float opacity); diff --git a/modules/skybrowser/include/wwtcommunicator.h b/modules/skybrowser/include/wwtcommunicator.h index b6fbb7f081..0100bafcde 100644 --- a/modules/skybrowser/include/wwtcommunicator.h +++ b/modules/skybrowser/include/wwtcommunicator.h @@ -44,21 +44,22 @@ public: void update(); // WorldWide Telescope communication - void displayImage(const std::string& url, int i); + void selectImage(const std::string& url, int i); + void addImageLayerToWwt(const std::string& url, int i); void removeSelectedImage(int i); void setImageOrder(int i, int order); void loadImageCollection(const std::string& collection); void setImageOpacity(int i, float opacity) const; void hideChromeInterface(bool shouldHide) const; - bool hasLoadedImages() const; + bool isImageCollectionLoaded() const; double verticalFov() const; glm::ivec3 borderColor() const; glm::dvec2 equatorialAim() const; glm::dvec2 fieldsOfView() const; const std::deque& getSelectedImages() const; - void setHasLoadedImages(bool isLoaded); + void setImageCollectionIsLoaded(bool isLoaded); void setVerticalFov(double vfov); void setIsSyncedWithWwt(bool isSynced); void setEquatorialAim(glm::dvec2 equatorial); @@ -78,7 +79,7 @@ protected: glm::ivec3 _borderColor = glm::ivec3(70); glm::dvec2 _equatorialAim = glm::dvec2(0.0); double _targetRoll = 0.0; - bool _hasLoadedImages = false; + bool _isImageCollectionLoaded = false; std::deque _selectedImages; private: diff --git a/modules/skybrowser/skybrowsermodule.cpp b/modules/skybrowser/skybrowsermodule.cpp index 9323b5af12..e432abca45 100644 --- a/modules/skybrowser/skybrowsermodule.cpp +++ b/modules/skybrowser/skybrowsermodule.cpp @@ -296,7 +296,11 @@ TargetBrowserPair* SkyBrowserModule::getPair(const std::string& id) const { return foundBrowser || foundTarget || foundTargetNode; } ); - return it != _targetsBrowsers.end() ? it->get() : nullptr; + TargetBrowserPair* found = it != _targetsBrowsers.end() ? it->get() : nullptr; + if (found == nullptr) { + LINFO("Identifier " + id + " not found."); + } + return found; } void SkyBrowserModule::startRotatingCamera(glm::dvec3 endAnimation) { @@ -420,7 +424,8 @@ scripting::LuaLibrary SkyBrowserModule::luaLibrary() const { codegen::lua::RemoveRenderCopy, codegen::lua::StartFinetuningTarget, codegen::lua::FinetuneTargetPosition, - codegen::lua::ScrollOverBrowser + codegen::lua::ScrollOverBrowser, + codegen::lua::LoadingImageCollectionComplete } }; } diff --git a/modules/skybrowser/skybrowsermodule_lua.inl b/modules/skybrowser/skybrowsermodule_lua.inl index 862a28a856..9847464152 100644 --- a/modules/skybrowser/skybrowsermodule_lua.inl +++ b/modules/skybrowser/skybrowsermodule_lua.inl @@ -51,14 +51,18 @@ namespace { if (module->isCameraInSolarSystem()) { TargetBrowserPair* selected = module->getPair(module->selectedBrowserId()); if (selected) { + if (!selected->isImageCollectionLoaded()) { + LINFO("Image collection is not yet loaded to AAS WorldWide Telescope"); + return; + } const ImageData& image = module->getWwtDataHandler()->getImage(imageIndex); // Load image into browser std::string str = image.name; + // Check if character is ASCII - if it isn't, remove str.erase( std::remove_if( str.begin(), str.end(), [](char c) { - // Check if character is ASCII - if it isn't, remove return c < 0 || c >= 128; } ), @@ -711,6 +715,27 @@ namespace { } } +/** + * Sets the image collection as loaded in the sky browser + */ +[[codegen::luawrap]] void loadingImageCollectionComplete(std::string identifier) { + using namespace openspace; + + SkyBrowserModule* module = global::moduleEngine->module(); + TargetBrowserPair* pair = module->getPair(identifier); + if (pair) { + LINFO("Image collection is loaded in Screen Space Sky Browser " + identifier); + pair->setImageCollectionIsLoaded(true); + // Add all selected images to WorldWide Telescope + const std::deque& images = pair->selectedImages(); + std::for_each(images.rbegin(), images.rend(), [&](int index) { + const ImageData& image = module->getWwtDataHandler()->getImage(index); + // Index of image is used as layer ID as it is unique in the image data set + pair->browser()->addImageLayerToWwt(image.imageUrl, index); + }); + } +} + #include "skybrowsermodule_lua_codegen.cpp" } // namespace diff --git a/modules/skybrowser/src/targetbrowserpair.cpp b/modules/skybrowser/src/targetbrowserpair.cpp index 2b50212bc0..e44035fc4b 100644 --- a/modules/skybrowser/src/targetbrowserpair.cpp +++ b/modules/skybrowser/src/targetbrowserpair.cpp @@ -186,7 +186,7 @@ const std::deque& TargetBrowserPair::selectedImages() const { void TargetBrowserPair::selectImage(const ImageData& image, int i) { // Load image into browser - _browser->displayImage(image.imageUrl, i); + _browser->selectImage(image.imageUrl, i); // If the image has coordinates, move the target if (image.hasCelestialCoords) { @@ -197,6 +197,10 @@ void TargetBrowserPair::selectImage(const ImageData& image, int i) { } } +void TargetBrowserPair::addImageLayerToWwt(const std::string& url, int i) { + _browser->addImageLayerToWwt(url, i); +} + void TargetBrowserPair::removeSelectedImage(int i) { _browser->removeSelectedImage(i); } @@ -225,6 +229,10 @@ std::vector> TargetBrowserPair::renderCopies( return _browser->renderCopies(); } +bool TargetBrowserPair::isImageCollectionLoaded() { + return _browser->isImageCollectionLoaded(); +} + void TargetBrowserPair::setIsSyncedWithWwt(bool isSynced) { _browser->setIsSyncedWithWwt(isSynced); } @@ -257,6 +265,10 @@ void TargetBrowserPair::setVerticalFovWithScroll(float scroll) { _browser->setVerticalFovWithScroll(scroll); } +void TargetBrowserPair::setImageCollectionIsLoaded(bool isLoaded) { + _browser->setImageCollectionIsLoaded(isLoaded); +} + void TargetBrowserPair::incrementallyAnimateToCoordinate() { // Animate the target before the field of view starts to animate if (_moveTarget.isAnimating()) { diff --git a/modules/skybrowser/src/wwtcommunicator.cpp b/modules/skybrowser/src/wwtcommunicator.cpp index 1a6a6428e1..b214218125 100644 --- a/modules/skybrowser/src/wwtcommunicator.cpp +++ b/modules/skybrowser/src/wwtcommunicator.cpp @@ -42,18 +42,22 @@ WwtCommunicator::WwtCommunicator(const ghoul::Dictionary& dictionary) WwtCommunicator::~WwtCommunicator() {} -void WwtCommunicator::displayImage(const std::string& url, int i) { +void WwtCommunicator::selectImage(const std::string& url, int i) { // Ensure there are no duplicates auto it = std::find(_selectedImages.begin(), _selectedImages.end(), i); if (it == _selectedImages.end()) { // Push newly selected image to front _selectedImages.push_front(i); - // Index of image is used as layer ID as it is unique in the image data set - sendMessageToWwt(addImageMessage(std::to_string(i), url)); - sendMessageToWwt(setImageOpacityMessage(std::to_string(i), 1.0)); + addImageLayerToWwt(url, i); } } +void WwtCommunicator::addImageLayerToWwt(const std::string& url, int i) { + // Index of image is used as layer ID as it is unique in the image data set + sendMessageToWwt(addImageMessage(std::to_string(i), url)); + sendMessageToWwt(setImageOpacityMessage(std::to_string(i), 1.0)); +} + void WwtCommunicator::removeSelectedImage(int i) { // Remove from selected list auto it = std::find(_selectedImages.begin(), _selectedImages.end(), i); @@ -125,8 +129,8 @@ glm::dvec2 WwtCommunicator::fieldsOfView() const { return browserFov; } -bool WwtCommunicator::hasLoadedImages() const { - return _hasLoadedImages; +bool WwtCommunicator::isImageCollectionLoaded() const { + return _isImageCollectionLoaded; } glm::dvec2 WwtCommunicator::equatorialAim() const { @@ -150,8 +154,9 @@ void WwtCommunicator::setImageOrder(int i, int order) { } void WwtCommunicator::loadImageCollection(const std::string& collection) { - sendMessageToWwt(loadCollectionMessage(collection)); - _hasLoadedImages = true; + if (!_isImageCollectionLoaded) { + sendMessageToWwt(loadCollectionMessage(collection)); + } } void WwtCommunicator::setImageOpacity(int i, float opacity) const { @@ -166,7 +171,6 @@ void WwtCommunicator::hideChromeInterface(bool shouldHide) const { } void WwtCommunicator::update() { - Browser::update(); // Cap how messages are passed std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); std::chrono::system_clock::duration timeSinceLastUpdate = now - _lastUpdateTime; @@ -180,12 +184,16 @@ void WwtCommunicator::update() { updateBorderColor(); _borderColorIsDirty = false; } + if (_shouldReload) { + _isImageCollectionLoaded = false; + } _lastUpdateTime = std::chrono::system_clock::now(); } + Browser::update(); } -void WwtCommunicator::setHasLoadedImages(bool isLoaded) { - _hasLoadedImages = isLoaded; +void WwtCommunicator::setImageCollectionIsLoaded(bool isLoaded) { + _isImageCollectionLoaded = isLoaded; } void WwtCommunicator::setIdInBrowser(const std::string& id) const {