mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-03 09:20:26 -05:00
Cleanup
This commit is contained in:
@@ -47,30 +47,35 @@ namespace openspace {
|
||||
RenderableSkyBrowser(const ghoul::Dictionary& dictionary);
|
||||
virtual ~RenderableSkyBrowser() = default;
|
||||
|
||||
// Inherited from RenderablePlane
|
||||
void initializeGL() override;
|
||||
void deinitializeGL() override;
|
||||
|
||||
void update(const UpdateData& data) override;
|
||||
|
||||
// Web page communication
|
||||
void executeJavascript(std::string script) const;
|
||||
bool sendMessageToWWT(const ghoul::Dictionary& msg);
|
||||
void connectToWwt();
|
||||
void stopConnectingToWwt();
|
||||
void setIdInBrowser(std::string id);
|
||||
|
||||
// WorldWide Telescope communication
|
||||
void displayImage(ImageData& image, int i);
|
||||
void removeSelectedImage(ImageData& image, int i);
|
||||
void setIdInBrowser(std::string id);
|
||||
float fieldOfView() const;
|
||||
std::deque<int>& selectedImages();
|
||||
bool sendMessageToWwt(const ghoul::Dictionary& msg);
|
||||
void syncWwtView();
|
||||
void stopSyncingWwtView();
|
||||
|
||||
// Getters
|
||||
float verticalFov() const;
|
||||
std::deque<int>& getSelectedImages();
|
||||
|
||||
// Setters
|
||||
void setImageLayerOrder(int i, int order, int version);
|
||||
|
||||
protected:
|
||||
|
||||
properties::Vec2Property _dimensions;
|
||||
std::unique_ptr<BrowserInstance> _browserInstance;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _texture;
|
||||
|
||||
|
||||
private:
|
||||
// Properties
|
||||
properties::Vec2Property _dimensions;
|
||||
properties::StringProperty _url;
|
||||
properties::TriggerProperty _reload;
|
||||
|
||||
class ScreenSpaceRenderHandler : public WebRenderHandler {
|
||||
public:
|
||||
void draw() override;
|
||||
@@ -79,23 +84,21 @@ namespace openspace {
|
||||
void setTexture(GLuint t);
|
||||
};
|
||||
|
||||
CefRefPtr<ScreenSpaceRenderHandler> _renderHandler;
|
||||
|
||||
void bindTexture() override;
|
||||
|
||||
properties::StringProperty _url;
|
||||
|
||||
properties::TriggerProperty _reload;
|
||||
|
||||
// Browser variables
|
||||
std::unique_ptr<BrowserInstance> _browserInstance;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _texture;
|
||||
CefRefPtr<ScreenSpaceRenderHandler> _renderHandler;
|
||||
CefRefPtr<WebKeyboardHandler> _keyboardHandler;
|
||||
|
||||
// Flags
|
||||
bool _isUrlDirty = false;
|
||||
bool _isDimensionsDirty = false;
|
||||
bool _syncViewWithWwt;
|
||||
|
||||
float _fov;
|
||||
bool _connectToWwt;
|
||||
float _verticalFov;
|
||||
std::thread _threadWwtMessages;
|
||||
|
||||
std::deque<int> _selectedImages;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -13,63 +13,88 @@ namespace openspace {
|
||||
class ScreenSpaceSkyBrowser : public ScreenSpaceBrowser
|
||||
{
|
||||
public:
|
||||
// Constructor and destructor
|
||||
ScreenSpaceSkyBrowser(const ghoul::Dictionary& dictionary);
|
||||
virtual ~ScreenSpaceSkyBrowser();
|
||||
|
||||
// Inherited functions
|
||||
bool initializeGL() override;
|
||||
bool deinitializeGL() override;
|
||||
bool setConnectedTarget();
|
||||
glm::mat4 scaleMatrix() override;
|
||||
|
||||
// Target - browser connection
|
||||
bool connectToSkyTarget();
|
||||
void initializeBrowser();
|
||||
void setIdInBrowser();
|
||||
|
||||
// Getters returning values
|
||||
bool hasLoadedImages() const;
|
||||
glm::vec2 browserPixelDimensions() const;
|
||||
glm::ivec3 borderColor() const;
|
||||
float verticalFov() const;
|
||||
|
||||
// Communication with the webpage and WWT
|
||||
void executeJavascript(std::string script) const;
|
||||
bool sendMessageToWWT(const ghoul::Dictionary& msg);
|
||||
void WWTfollowCamera();
|
||||
float fieldOfView() const;
|
||||
void setVerticalFieldOfView(float fov);
|
||||
void scrollZoom(float scroll);
|
||||
// Getters returning references
|
||||
ScreenSpaceSkyTarget* getSkyTarget();
|
||||
bool hasLoadedCollections();
|
||||
void setHasLoadedCollections(bool isLoaded);
|
||||
std::deque<int>& getSelectedImages();
|
||||
properties::FloatProperty& getOpacity();
|
||||
std::deque<int>& selectedImages();
|
||||
|
||||
// Setters
|
||||
void setHasLoadedImages(bool isLoaded);
|
||||
void setVerticalFov(float vfov);
|
||||
void setVerticalFovWithScroll(float scroll);
|
||||
void setScale(glm::vec2 scalingFactor);
|
||||
void setScale(float scalingFactor);
|
||||
void setWebpageBorderColor(glm::ivec3 color);
|
||||
|
||||
// Communication with the web page
|
||||
void executeJavascript(std::string script);
|
||||
void sendIdToBrowser();
|
||||
|
||||
// Communication with WorldWide Telescope
|
||||
void addSelectedImage(ImageData& image, int i);
|
||||
void removeSelectedImage(ImageData& image, int i);
|
||||
void setImageLayerOrder(int i, int order, int version);
|
||||
void setImageOrder(int i, int order, int version);
|
||||
void sendMessageToWwt(const ghoul::Dictionary& msg);
|
||||
void syncWwtView();
|
||||
|
||||
// Mouse interaction with the browser. Returns 1 or -1 at the coordinate in
|
||||
// image if the mouse is on a side of the browser
|
||||
// __1__
|
||||
// y| -1 |_____|1
|
||||
// |__x -1
|
||||
glm::vec2 isOnResizeArea(glm::vec2 screenSpaceCoord);
|
||||
|
||||
// Resize functions
|
||||
void saveResizeStartSize();
|
||||
void updateBrowserSize();
|
||||
|
||||
// Translation
|
||||
//void translate(glm::vec2 translation);
|
||||
|
||||
// Position and dimension and corners
|
||||
glm::vec2 getBrowserPixelDimensions();
|
||||
glm::vec2 coordIsOnResizeArea(glm::vec2 coord);
|
||||
// Scaling
|
||||
void scale(glm::vec2 scalingFactor);
|
||||
void scale(float scalingFactor);
|
||||
glm::mat4 scaleMatrix() override;
|
||||
// Resizing
|
||||
void saveResizeStartSize();
|
||||
void updateBrowserSize();
|
||||
void setBorderColor(glm::ivec3 addColor);
|
||||
glm::ivec3 getColor();
|
||||
// Flag for dimensions
|
||||
bool _browserDimIsDirty;
|
||||
properties::FloatProperty _vfieldOfView;
|
||||
properties::StringProperty _skyTargetID;
|
||||
properties::Vec3Property _borderColor;
|
||||
|
||||
private:
|
||||
glm::vec2 _startDimensionsSize;
|
||||
float _startScale;
|
||||
// Properties
|
||||
properties::FloatProperty _verticalFov;
|
||||
properties::StringProperty _skyTargetId;
|
||||
properties::Vec2Property _browserDimensions;
|
||||
bool _camIsSyncedWWT;
|
||||
ScreenSpaceSkyTarget* _skyTarget;
|
||||
std::thread _threadWWTMessages;
|
||||
// For capping the calls to change the zoom from scrolling
|
||||
constexpr static const std::chrono::milliseconds TimeUpdateInterval{ 10 };
|
||||
std::chrono::system_clock::time_point _lastUpdateTime;
|
||||
bool _hasLoadedCollections{ false };
|
||||
properties::Vec3Property _borderColor;
|
||||
|
||||
// Flags
|
||||
bool _hasLoadedImages{ false };
|
||||
bool _syncViewWithWwt{ false };
|
||||
|
||||
// Resizing of browser
|
||||
glm::vec2 _originalDimensions;
|
||||
float _originalScale;
|
||||
float _resizeAreaPercentage{ 0.1f };
|
||||
|
||||
// Target & images
|
||||
ScreenSpaceSkyTarget* _skyTarget{ nullptr };
|
||||
std::thread _threadWwtMessages;
|
||||
std::deque<int> _selectedImages;
|
||||
|
||||
// Time variables
|
||||
// For capping the calls to change the zoom from scrolling
|
||||
constexpr static const std::chrono::milliseconds _timeUpdateInterval{ 10 };
|
||||
std::chrono::system_clock::time_point _lastUpdateTime;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -19,64 +19,77 @@ namespace openspace {
|
||||
class ScreenSpaceSkyTarget : public ScreenSpaceRenderable {
|
||||
|
||||
public:
|
||||
// Constructor & destructor
|
||||
ScreenSpaceSkyTarget(const ghoul::Dictionary& dictionary);
|
||||
virtual ~ScreenSpaceSkyTarget();
|
||||
|
||||
// ScreenSpaceRenderable inherited functions
|
||||
bool initializeGL() override;
|
||||
bool isReady() const override;
|
||||
void render() override;
|
||||
glm::mat4 scaleMatrix() override;
|
||||
void bindTexture() override; // Empty function but has to be defined
|
||||
|
||||
void createShaders();
|
||||
void initializeWithBrowser();
|
||||
|
||||
// Sky browser functionality
|
||||
bool findSkyBrowser();
|
||||
void matchAppearanceToSkyBrowser();
|
||||
|
||||
// Getters
|
||||
ScreenSpaceSkyBrowser* getSkyBrowser();
|
||||
|
||||
void setVerticalFOV(float VFOV);
|
||||
glm::ivec3 borderColor() const;
|
||||
float opacity() const;
|
||||
|
||||
// Setters
|
||||
void setScale(float verticalFov);
|
||||
void setDimensions(glm::vec2 dimensions);
|
||||
void setColor(glm::ivec3 color);
|
||||
glm::ivec3 getColor();
|
||||
properties::FloatProperty& getOpacity();
|
||||
void setOpacity(float opacity);
|
||||
|
||||
// Target directions
|
||||
glm::dvec3 getTargetDirectionGalactic();
|
||||
glm::dvec2 getTargetDirectionCelestial();
|
||||
glm::dvec3 targetDirectionGalactic() const;
|
||||
glm::dvec3 targetDirectionEquatorial() const;
|
||||
|
||||
// Locking functionality
|
||||
void unlock();
|
||||
void lock();
|
||||
void unlock();
|
||||
bool isLocked();
|
||||
|
||||
// Animations
|
||||
void startAnimation(glm::dvec2 coordsEnd, float FOVEnd, bool lockAfterwards = true);
|
||||
void animateToCoord(double deltaTime);
|
||||
bool animateToFOV(float endFOV, float deltaTime);
|
||||
void startAnimation(glm::dvec3 coordsEnd, float FOVEnd, bool lockAfter = true);
|
||||
void animateToCoordinate(double deltaTime);
|
||||
bool animateToFov(float endFOV, float deltaTime);
|
||||
|
||||
properties::StringProperty _skyBrowserID;
|
||||
private:
|
||||
// Properties
|
||||
properties::StringProperty _skyBrowserId;
|
||||
properties::FloatProperty _showCrosshairThreshold;
|
||||
properties::FloatProperty _showRectangleThreshold;
|
||||
|
||||
private:
|
||||
// Flags
|
||||
bool _isAnimated{ false };
|
||||
bool _lockAfterAnimation{ false };
|
||||
bool _isLocked{ false };
|
||||
|
||||
// Shader
|
||||
UniformCache(modelTransform, viewProj, showCrosshair, showRectangle, lineWidth, dimensions, lineColor) _uniformCache;
|
||||
GLuint _vertexArray = 0;
|
||||
GLuint _vertexBuffer = 0;
|
||||
glm::ivec3 _color;
|
||||
float _verticalFOV = 100.f;
|
||||
ScreenSpaceSkyBrowser* _skyBrowser;
|
||||
|
||||
// Locking target to a coordinate on the sky
|
||||
bool _isLocked;
|
||||
glm::dvec2 _lockedCoords; // Spherical celestial coords
|
||||
std::thread _lockTargetThread;
|
||||
// Sky browser
|
||||
ScreenSpaceSkyBrowser* _skyBrowser;
|
||||
glm::ivec3 _color;
|
||||
|
||||
// Lock target to a coordinate on the sky
|
||||
glm::dvec3 _lockedCoordinates; // Spherical celestial coordinates
|
||||
std::thread _lockTarget;
|
||||
|
||||
// Animating the target
|
||||
bool _isAnimated = false;
|
||||
glm::dvec3 _coordsEndAnimation; // Cartesian celestial coords
|
||||
glm::dvec3 _coordsStartAnimation; // Cartesian celestial coords
|
||||
// Animation of target
|
||||
glm::dvec3 _animationEnd; // Cartesian celestial coordinates
|
||||
glm::dvec3 _animationStart; // Cartesian celestial coordinates
|
||||
double _animationTime = 1.0;
|
||||
float _FOVEndAnimation;
|
||||
bool _lockAfterAnimation;
|
||||
float _vfovEndAnimation;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -10,45 +10,49 @@
|
||||
|
||||
namespace openspace {
|
||||
namespace skybrowser {
|
||||
const double SCREENSPACE_Z = -2.1;
|
||||
const double RAD_TO_DEG = 180.0 / M_PI;
|
||||
const double DEG_TO_RAD = M_PI / 180.0;
|
||||
const glm::dvec3 NORTH_POLE = { 0.0 , 0.0 , 1.0 };
|
||||
constexpr double infinity = std::numeric_limits<float>::max();
|
||||
// Constants
|
||||
constexpr const double ScreenSpaceZ = -2.1;
|
||||
constexpr const glm::dvec3 NorthPole = { 0.0 , 0.0 , 1.0 };
|
||||
constexpr const double CelestialSphereRadius = std::numeric_limits<float>::max();
|
||||
|
||||
// Conversion matrix from this paper: https://arxiv.org/abs/1010.3773v1
|
||||
// Conversion matrix - J2000 equatorial <-> galactic
|
||||
// https://arxiv.org/abs/1010.3773v1
|
||||
const glm::dmat3 conversionMatrix = glm::dmat3({
|
||||
-0.054875539390, 0.494109453633, -0.867666135681, // col 0
|
||||
-0.873437104725, -0.444829594298, -0.198076389622, // col 1
|
||||
-0.483834991775, 0.746982248696, 0.455983794523 // col 2
|
||||
});
|
||||
|
||||
// J2000 to galactic conversion and vice versa
|
||||
glm::dvec2 cartesianToSpherical(glm::dvec3 cartesianCoords);
|
||||
glm::dvec3 sphericalToCartesian(glm::dvec2 sphericalCoords);
|
||||
glm::dvec3 galacticCartesianToJ2000Cartesian(glm::dvec3 rGal);
|
||||
glm::dvec2 galacticCartesianToJ2000Spherical(glm::dvec3 rGal);
|
||||
glm::dvec3 galacticCartesianToCameraLocalCartesian(glm::dvec3 galCoords);
|
||||
glm::dvec3 J2000SphericalToGalacticCartesian(glm::dvec2 coords,
|
||||
double distance = infinity);
|
||||
glm::dvec3 J2000CartesianToGalacticCartesian(glm::dvec3 coords,
|
||||
double distance = infinity);
|
||||
// Convert J2000, spherical or Cartesian, to screen space
|
||||
glm::dvec3 J2000SphericalToScreenSpace(glm::dvec2 coords);
|
||||
glm::dvec3 J2000CartesianToScreenSpace(glm::dvec3 coords);
|
||||
glm::dvec3 galacticToScreenSpace(glm::dvec3 galacticCoord);
|
||||
double calculateRoll(glm::dvec3 upWorld, glm::dvec3 forwardWorld);
|
||||
glm::dvec3 cameraDirectionJ2000Cartesian();
|
||||
// Conversion spherical <-> Cartesian
|
||||
glm::dvec2 cartesianToSpherical(glm::dvec3 coords);
|
||||
glm::dvec3 sphericalToCartesian(glm::dvec2 coords);
|
||||
|
||||
// Conversion J2000 equatorial <-> galactic
|
||||
glm::dvec3 galacticToEquatorial(glm::dvec3 coords);
|
||||
glm::dvec3 galacticToCameraLocal(glm::dvec3 coords);
|
||||
glm::dvec3 equatorialToGalactic(glm::dvec3 coords);
|
||||
|
||||
// Conversion J2000 equatorial / galactic <-> screen space
|
||||
glm::dvec3 equatorialToScreenSpace(glm::dvec3 coords);
|
||||
glm::dvec3 galacticToScreenSpace(glm::dvec3 coords);
|
||||
glm::dvec3 screenSpaceToGalactic(glm::dvec3 coords);
|
||||
glm::dvec3 screenSpaceToEquatorial(glm::dvec3 coords);
|
||||
|
||||
// Camera roll and direction
|
||||
// Camera roll is with respect to the equatorial North Pole
|
||||
double cameraRoll();
|
||||
glm::dvec3 cameraDirectionGalactic();
|
||||
glm::dvec3 cameraDirectionEquatorial();
|
||||
}
|
||||
// WorldWide Telescope messages
|
||||
namespace wwtmessage {
|
||||
// WWT messages
|
||||
ghoul::Dictionary moveCamera(const glm::dvec2 celestCoords,
|
||||
const double fov, const double roll, const bool moveInstantly = true);
|
||||
ghoul::Dictionary loadCollection(const std::string& url);
|
||||
ghoul::Dictionary setForeground(const std::string& name);
|
||||
ghoul::Dictionary createImageLayer(const std::string& id, const std::string& url);
|
||||
ghoul::Dictionary removeImageLayer(const std::string& id);
|
||||
ghoul::Dictionary setLayerOpacity(const std::string& id, double opacity);
|
||||
ghoul::Dictionary addImage(const std::string& id, const std::string& url);
|
||||
ghoul::Dictionary removeImage(const std::string& id);
|
||||
ghoul::Dictionary setImageOpacity(const std::string& id, double opacity);
|
||||
ghoul::Dictionary setForegroundOpacity(double val);
|
||||
ghoul::Dictionary setLayerOrder(const std::string& id, int order, int version);
|
||||
}
|
||||
|
||||
@@ -57,12 +57,12 @@ namespace openspace {
|
||||
std::string name;
|
||||
std::string thumbnailUrl;
|
||||
std::string imageUrl;
|
||||
std::string credits;
|
||||
std::string creditsUrl;
|
||||
glm::dvec2 celestCoords;
|
||||
std::string credits;
|
||||
glm::dvec2 celestialCoords;
|
||||
std::string collection;
|
||||
float fov;
|
||||
bool hasCelestCoords{ false };
|
||||
bool hasCelestialCoords{ false };
|
||||
bool has3dCoords{ false };
|
||||
glm::dvec3 position3d;
|
||||
};
|
||||
@@ -73,24 +73,31 @@ namespace openspace {
|
||||
bool loaded = false;
|
||||
};
|
||||
|
||||
class WWTDataHandler {
|
||||
class WwtDataHandler {
|
||||
|
||||
public:
|
||||
WWTDataHandler() = default;
|
||||
~WWTDataHandler();
|
||||
// Image downloading and xml parsing
|
||||
bool downloadFile(std::string& url, std::string& fileDestination);
|
||||
void loadWTMLCollectionsFromURL(std::string directory, std::string url, std::string fileName);
|
||||
bool loadWTMLCollectionsFromDirectory(std::string directory);
|
||||
int loadImagesFromLoadedXMLs();
|
||||
// Constructor and destructor
|
||||
WwtDataHandler() = default;
|
||||
~WwtDataHandler();
|
||||
|
||||
// Image downloading and xml parsing
|
||||
bool loadWtmlCollectionsFromUrl(std::string directory, std::string url,
|
||||
std::string fileName);
|
||||
bool loadWtmlCollectionsFromDirectory(std::string directory);
|
||||
int loadImagesFromLoadedXmls();
|
||||
|
||||
// Loading speck files
|
||||
void loadSpeckData(speck::Dataset& dataset);
|
||||
|
||||
// Getters
|
||||
const std::vector<ImageCollection>& getAllImageCollectionUrls() const;
|
||||
std::vector<ImageData>& getLoadedImages();
|
||||
void loadSpeckData(speck::Dataset& dataset);
|
||||
std::string createSearchableString(std::string name);
|
||||
|
||||
private:
|
||||
void loadImagesFromXML(tinyxml2::XMLElement* node,
|
||||
|
||||
// Parsing and downloading of wtml files
|
||||
bool downloadFile(std::string& url, std::string& fileDestination);
|
||||
void loadImagesFromXml(tinyxml2::XMLElement* node,
|
||||
std::string collectionName);
|
||||
int loadImageFromXmlNode(tinyxml2::XMLElement* imageSet,
|
||||
std::string collectionName);
|
||||
@@ -105,17 +112,22 @@ namespace openspace {
|
||||
|
||||
std::string getChildNodeContentFromImageSet(tinyxml2::XMLElement* imageSet,
|
||||
std::string elementName);
|
||||
std::string getURLFromPlace(tinyxml2::XMLElement* place);
|
||||
std::string getUrlFromPlace(tinyxml2::XMLElement* place);
|
||||
tinyxml2::XMLElement* getDirectChildNode(tinyxml2::XMLElement* node,
|
||||
std::string name);
|
||||
tinyxml2::XMLElement* getChildNode(tinyxml2::XMLElement* node, std::string name);
|
||||
|
||||
std::vector<ImageData> images;
|
||||
std::vector<ImageCollection> imageUrls;
|
||||
std::vector<tinyxml2::XMLDocument*> xmls;
|
||||
// Used for matching names
|
||||
std::string createSearchableString(std::string name);
|
||||
|
||||
// Images
|
||||
std::vector<ImageData> _images;
|
||||
std::vector<ImageCollection> _imageUrls;
|
||||
std::vector<tinyxml2::XMLDocument*> _xmls;
|
||||
|
||||
// 3D position data loaded from speck files
|
||||
std::unordered_map<std::string, glm::dvec3> _3dPositions;
|
||||
int nImagesWith3dPositions = 0;
|
||||
int _nImagesWith3dPositions = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user