mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-07 04:00:37 -06:00
Store opacities for the selected images and pass to GUI in topic
This commit is contained in:
@@ -94,7 +94,7 @@ public:
|
||||
|
||||
SceneGraphNode* targetNode() const;
|
||||
ScreenSpaceSkyBrowser* browser() const;
|
||||
const std::deque<int>& selectedImages() const;
|
||||
std::vector<int> selectedImages() const;
|
||||
|
||||
ghoul::Dictionary dataAsDictionary() const;
|
||||
|
||||
|
||||
@@ -49,15 +49,17 @@ public:
|
||||
void removeSelectedImage(int i);
|
||||
void setImageOrder(int i, int order);
|
||||
void loadImageCollection(const std::string& collection);
|
||||
void setImageOpacity(int i, float opacity) const;
|
||||
void setImageOpacity(int i, float opacity);
|
||||
void hideChromeInterface(bool shouldHide) const;
|
||||
|
||||
bool isImageCollectionLoaded() const;
|
||||
|
||||
double verticalFov() const;
|
||||
glm::ivec3 borderColor() const;
|
||||
glm::dvec2 equatorialAim() const;
|
||||
glm::dvec2 fieldsOfView() const;
|
||||
const std::deque<int>& getSelectedImages() const;
|
||||
std::vector<int> selectedImages() const;
|
||||
std::vector<double> opacities() const;
|
||||
|
||||
void setImageCollectionIsLoaded(bool isLoaded);
|
||||
void setVerticalFov(double vfov);
|
||||
@@ -73,13 +75,14 @@ public:
|
||||
|
||||
protected:
|
||||
void setIdInBrowser(const std::string& id) const;
|
||||
std::deque<std::pair<int, double>>::iterator findSelectedImage(int i);
|
||||
|
||||
double _verticalFov = 10.0f;
|
||||
glm::ivec3 _borderColor = glm::ivec3(70);
|
||||
glm::dvec2 _equatorialAim = glm::dvec2(0.0);
|
||||
double _targetRoll = 0.0;
|
||||
bool _isImageCollectionLoaded = false;
|
||||
std::deque<int> _selectedImages;
|
||||
std::deque<std::pair<int, double>> _selectedImages;
|
||||
|
||||
private:
|
||||
void setWebpageBorderColor(glm::ivec3 color) const;
|
||||
|
||||
@@ -321,16 +321,6 @@ namespace {
|
||||
|
||||
for (const std::unique_ptr<TargetBrowserPair>& pair : pairs) {
|
||||
std::string id = pair->browserId();
|
||||
// Convert deque to vector so ghoul can read it
|
||||
std::vector<int> selectedImagesVector;
|
||||
const std::deque<int> selectedImages = pair->selectedImages();
|
||||
std::for_each(
|
||||
selectedImages.begin(),
|
||||
selectedImages.end(),
|
||||
[&](int i) {
|
||||
selectedImagesVector.push_back(i);
|
||||
}
|
||||
);
|
||||
|
||||
glm::dvec2 spherical = pair->targetDirectionEquatorial();
|
||||
glm::dvec3 cartesian = skybrowser::sphericalToCartesian(spherical);
|
||||
@@ -340,7 +330,7 @@ namespace {
|
||||
target.setValue("id", id);
|
||||
target.setValue("name", pair->browserGuiName());
|
||||
target.setValue("FOV", static_cast<double>(pair->verticalFov()));
|
||||
target.setValue("selectedImages", selectedImagesVector);
|
||||
target.setValue("selectedImages", pair->selectedImages());
|
||||
target.setValue("cartesianDirection", cartesian);
|
||||
target.setValue("ra", spherical.x);
|
||||
target.setValue("dec", spherical.y);
|
||||
@@ -728,7 +718,7 @@ namespace {
|
||||
LINFO("Image collection is loaded in Screen Space Sky Browser " + identifier);
|
||||
pair->setImageCollectionIsLoaded(true);
|
||||
// Add all selected images to WorldWide Telescope
|
||||
const std::deque<int>& images = pair->selectedImages();
|
||||
const std::vector<int>& images = pair->selectedImages();
|
||||
std::for_each(
|
||||
images.rbegin(), images.rend(),
|
||||
[&](int index) {
|
||||
|
||||
@@ -187,18 +187,11 @@ double TargetBrowserPair::verticalFov() const {
|
||||
return _browser->verticalFov();
|
||||
}
|
||||
|
||||
const std::deque<int>& TargetBrowserPair::selectedImages() const {
|
||||
return _browser->getSelectedImages();
|
||||
std::vector<int> TargetBrowserPair::selectedImages() const {
|
||||
return _browser->selectedImages();
|
||||
}
|
||||
|
||||
ghoul::Dictionary TargetBrowserPair::dataAsDictionary() const {
|
||||
// Convert deque to vector so ghoul can read it
|
||||
std::vector<int> selectedImagesVector;
|
||||
const std::deque<int> selectedImagesDeque = selectedImages();
|
||||
for (int i : selectedImagesDeque) {
|
||||
selectedImagesVector.push_back(i);
|
||||
}
|
||||
|
||||
glm::dvec2 spherical = targetDirectionEquatorial();
|
||||
glm::dvec3 cartesian = skybrowser::sphericalToCartesian(spherical);
|
||||
|
||||
@@ -214,8 +207,9 @@ ghoul::Dictionary TargetBrowserPair::dataAsDictionary() const {
|
||||
res.setValue("ratio", static_cast<double>(browserRatio()));
|
||||
res.setValue("isFacingCamera", isFacingCamera());
|
||||
res.setValue("isUsingRae", isUsingRadiusAzimuthElevation());
|
||||
res.setValue("selectedImages", selectedImagesVector);
|
||||
|
||||
res.setValue("selectedImages", selectedImages());
|
||||
res.setValue("opacities", _browser->opacities());
|
||||
|
||||
std::vector<std::pair<std::string, glm::dvec3>> copies = renderCopies();
|
||||
ghoul::Dictionary copiesData;
|
||||
for (size_t i = 0; i < copies.size(); i++) {
|
||||
|
||||
@@ -44,10 +44,11 @@ WwtCommunicator::~WwtCommunicator() {}
|
||||
|
||||
void WwtCommunicator::selectImage(const std::string& url, int i) {
|
||||
// Ensure there are no duplicates
|
||||
auto it = std::find(_selectedImages.begin(), _selectedImages.end(), i);
|
||||
auto it = findSelectedImage(i);
|
||||
|
||||
if (it == _selectedImages.end()) {
|
||||
// Push newly selected image to front
|
||||
_selectedImages.push_front(i);
|
||||
_selectedImages.push_front(std::pair<int, double>(i, 1.0));
|
||||
|
||||
// If wwt has not loaded the collection yet, wait with passing the message
|
||||
if (_isImageCollectionLoaded) {
|
||||
@@ -64,7 +65,7 @@ void WwtCommunicator::addImageLayerToWwt(const std::string& url, int i) {
|
||||
|
||||
void WwtCommunicator::removeSelectedImage(int i) {
|
||||
// Remove from selected list
|
||||
auto it = std::find(_selectedImages.begin(), _selectedImages.end(), i);
|
||||
auto it = findSelectedImage(i);
|
||||
|
||||
if (it != _selectedImages.end()) {
|
||||
_selectedImages.erase(it);
|
||||
@@ -77,8 +78,20 @@ void WwtCommunicator::sendMessageToWwt(const ghoul::Dictionary& msg) const {
|
||||
executeJavascript(script);
|
||||
}
|
||||
|
||||
const std::deque<int>& WwtCommunicator::getSelectedImages() const {
|
||||
return _selectedImages;
|
||||
std::vector<int> WwtCommunicator::selectedImages() const {
|
||||
std::vector<int> selectedImagesVector;
|
||||
for (const std::pair<int, double>& image : _selectedImages) {
|
||||
selectedImagesVector.push_back(image.first);
|
||||
}
|
||||
return selectedImagesVector;
|
||||
}
|
||||
|
||||
std::vector<double> WwtCommunicator::opacities() const {
|
||||
std::vector<double> opacities;
|
||||
for (const std::pair<int, double>& image : _selectedImages) {
|
||||
opacities.push_back(image.second);
|
||||
}
|
||||
return opacities;
|
||||
}
|
||||
|
||||
void WwtCommunicator::setTargetRoll(double roll) {
|
||||
@@ -133,13 +146,21 @@ bool WwtCommunicator::isImageCollectionLoaded() const {
|
||||
return _isImageCollectionLoaded;
|
||||
}
|
||||
|
||||
std::deque<std::pair<int, double>>::iterator WwtCommunicator::findSelectedImage(int i) {
|
||||
auto it = std::find_if(_selectedImages.begin(), _selectedImages.end(),
|
||||
[i](std::pair<int, double>& pair) {
|
||||
return (pair.first == i);
|
||||
});
|
||||
return it;
|
||||
}
|
||||
|
||||
glm::dvec2 WwtCommunicator::equatorialAim() const {
|
||||
return _equatorialAim;
|
||||
}
|
||||
|
||||
void WwtCommunicator::setImageOrder(int i, int order) {
|
||||
// Find in selected images list
|
||||
auto current = std::find(_selectedImages.begin(), _selectedImages.end(), i);
|
||||
auto current = findSelectedImage(i);
|
||||
auto target = _selectedImages.begin() + order;
|
||||
|
||||
// Make sure the image was found in the list
|
||||
@@ -159,7 +180,10 @@ void WwtCommunicator::loadImageCollection(const std::string& collection) {
|
||||
}
|
||||
}
|
||||
|
||||
void WwtCommunicator::setImageOpacity(int i, float opacity) const {
|
||||
void WwtCommunicator::setImageOpacity(int i, float opacity) {
|
||||
auto it = findSelectedImage(i);
|
||||
it->second = opacity;
|
||||
|
||||
ghoul::Dictionary msg = setImageOpacityMessage(std::to_string(i), opacity);
|
||||
sendMessageToWwt(msg);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user