mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-25 06:19:02 -06:00
Only send skybrowser topic message if data changed
Maybe a little ugly to check the jsonString, but it does the job for now. Later we should probably make a nicer implementation
This commit is contained in:
@@ -46,6 +46,8 @@ private:
|
||||
int _targetDataCallbackHandle = UnsetOnChangeHandle;
|
||||
bool _isDone = false;
|
||||
std::chrono::system_clock::time_point _lastUpdateTime;
|
||||
std::string _lastUpdateJsonString;
|
||||
|
||||
std::chrono::milliseconds _skyBrowserUpdateTime = std::chrono::milliseconds(100);
|
||||
};
|
||||
|
||||
|
||||
@@ -107,49 +107,25 @@ void SkyBrowserTopic::sendBrowserData() {
|
||||
ghoul::Dictionary targets;
|
||||
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);
|
||||
|
||||
ghoul::Dictionary target;
|
||||
// Set ("Key", value)
|
||||
target.setValue("id", id);
|
||||
target.setValue("name", pair->browserGuiName());
|
||||
target.setValue("fov", static_cast<double>(pair->verticalFov()));
|
||||
target.setValue("ra", spherical.x);
|
||||
target.setValue("dec", spherical.y);
|
||||
target.setValue("roll", pair->targetRoll());
|
||||
target.setValue("color", pair->borderColor());
|
||||
target.setValue("cartesianDirection", cartesian);
|
||||
target.setValue("ratio", static_cast<double>(pair->browserRatio()));
|
||||
target.setValue("isFacingCamera", pair->isFacingCamera());
|
||||
target.setValue("isUsingRae", pair->isUsingRadiusAzimuthElevation());
|
||||
target.setValue("selectedImages", selectedImagesVector);
|
||||
|
||||
std::vector<std::pair<std::string, glm::dvec3>> copies = pair->renderCopies();
|
||||
ghoul::Dictionary copiesData;
|
||||
for (size_t i = 0; i < copies.size(); i++) {
|
||||
copiesData.setValue(copies[i].first, copies[i].second);
|
||||
}
|
||||
// Set table for the current target
|
||||
target.setValue("renderCopies", copiesData);
|
||||
ghoul::Dictionary target = pair->dataAsDictionary();
|
||||
targets.setValue(id, target);
|
||||
}
|
||||
data.setValue("browsers", targets);
|
||||
}
|
||||
|
||||
std::string jsonString = ghoul::formatJson(data);
|
||||
json jsonData = json::parse(jsonString.begin(), jsonString.end());
|
||||
_connection->sendJson(wrappedPayload(jsonData));
|
||||
|
||||
// Only send message if data actually changed
|
||||
if (jsonString != _lastUpdateJsonString) {
|
||||
json jsonData = json::parse(jsonString.begin(), jsonString.end());
|
||||
_connection->sendJson(wrappedPayload(jsonData));
|
||||
}
|
||||
|
||||
// @TODO (2022-04-28, emmbr) The message is stills ent every time the camera moves,
|
||||
// because this changes the "roll" parameter of the browser. This is the update that
|
||||
// occurs most often. Maybe it could be separated into it's own topic?
|
||||
|
||||
_lastUpdateJsonString = jsonString;
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <deque>
|
||||
|
||||
namespace ghoul { class Dictionary; }
|
||||
|
||||
namespace openspace {
|
||||
|
||||
struct ImageData;
|
||||
@@ -64,7 +66,7 @@ public:
|
||||
|
||||
// Target
|
||||
void centerTargetOnScreen();
|
||||
double targetRoll();
|
||||
double targetRoll() const;
|
||||
|
||||
bool isFacingCamera() const;
|
||||
bool isUsingRadiusAzimuthElevation() const;
|
||||
@@ -94,6 +96,8 @@ public:
|
||||
ScreenSpaceSkyBrowser* browser() const;
|
||||
const std::deque<int>& selectedImages() const;
|
||||
|
||||
ghoul::Dictionary dataAsDictionary() const;
|
||||
|
||||
// WorldWide Telescope image handling
|
||||
void setImageOrder(int i, int order);
|
||||
void selectImage(const ImageData& image, int i);
|
||||
|
||||
@@ -191,6 +191,42 @@ const std::deque<int>& TargetBrowserPair::selectedImages() const {
|
||||
return _browser->getSelectedImages();
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
ghoul::Dictionary res;
|
||||
res.setValue("id", browserId());
|
||||
res.setValue("name", browserGuiName());
|
||||
res.setValue("fov", static_cast<double>(verticalFov()));
|
||||
res.setValue("ra", spherical.x);
|
||||
res.setValue("dec", spherical.y);
|
||||
res.setValue("roll", targetRoll());
|
||||
res.setValue("color", borderColor());
|
||||
res.setValue("cartesianDirection", cartesian);
|
||||
res.setValue("ratio", static_cast<double>(browserRatio()));
|
||||
res.setValue("isFacingCamera", isFacingCamera());
|
||||
res.setValue("isUsingRae", isUsingRadiusAzimuthElevation());
|
||||
res.setValue("selectedImages", selectedImagesVector);
|
||||
|
||||
std::vector<std::pair<std::string, glm::dvec3>> copies = renderCopies();
|
||||
ghoul::Dictionary copiesData;
|
||||
for (size_t i = 0; i < copies.size(); i++) {
|
||||
copiesData.setValue(copies[i].first, copies[i].second);
|
||||
}
|
||||
// Set table for the current target
|
||||
res.setValue("renderCopies", copiesData);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void TargetBrowserPair::selectImage(const ImageData& image, int i) {
|
||||
// Load image into browser
|
||||
_browser->selectImage(image.imageUrl, i);
|
||||
@@ -327,7 +363,7 @@ void TargetBrowserPair::centerTargetOnScreen() {
|
||||
startAnimation(viewDirection, currentFov);
|
||||
}
|
||||
|
||||
double TargetBrowserPair::targetRoll() {
|
||||
double TargetBrowserPair::targetRoll() const {
|
||||
// To remove the lag effect when moving the camera while having a locked
|
||||
// target, send the locked coordinates to wwt
|
||||
glm::dvec3 normal = glm::normalize(
|
||||
|
||||
Reference in New Issue
Block a user