mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-22 11:18:22 -05:00
Merge branch 'feature/constallationbounds' into develop
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __RENDERABLECONSTELLATIONBOUNDS_H__
|
||||
#define __RENDERABLECONSTELLATIONBOUNDS_H__
|
||||
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <openspace/properties/scalarproperty.h>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <array>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
/**
|
||||
* This class renders the constellation bounds as defined in
|
||||
* http://cdsarc.u-strasbg.fr/viz-bin/Cat?cat=VI%2F49. It contains the bounds on the
|
||||
* celestial sky for the different constellations and is used to determine in which region
|
||||
* of the sky a specific object is located.
|
||||
* The bounds are drawn as lines on a sphere with variable radius, set by the
|
||||
* <code>_distance</code> property. Currently, all constellation bounds are lines, which
|
||||
* leads to artifacts if the radius is very small.
|
||||
* Renderable configuration attributes:
|
||||
* <code>File</code> [string] (required): The file that contains the bounds and the
|
||||
* abbreviations for the different constellations
|
||||
* <code>ReferenceFrame</code> [string]: The reference frame in which the points contained
|
||||
* in the <code>File</code> are stored in. Defaults to <code>J2000</code>
|
||||
*
|
||||
* @TODO Add a method to load (and access) a table translating from abbreviations to
|
||||
* full names ---abock
|
||||
* @TODO Make it possible to only show a subset of constellation bounds ---abock
|
||||
*/
|
||||
class RenderableConstellationBounds : public Renderable {
|
||||
public:
|
||||
RenderableConstellationBounds(const ghoul::Dictionary& dictionary);
|
||||
|
||||
bool initialize() override;
|
||||
bool deinitialize() override;
|
||||
|
||||
bool isReady() const override;
|
||||
|
||||
void render(const RenderData& data) override;
|
||||
void update(const UpdateData& data) override;
|
||||
|
||||
private:
|
||||
/// Stores the constellation bounds
|
||||
struct ConstellationBound {
|
||||
std::string constellation; ///< The abbreviation of the constellation
|
||||
size_t startIndex; ///< The index of the first vertex describing the bounds
|
||||
size_t nVertices; ///< The number of vertices describing the bounds
|
||||
};
|
||||
|
||||
/**
|
||||
* Loads the file specified in <code>_filename</code> and fills the
|
||||
* <code>_constellationBounds</code> variable, as well as the
|
||||
* <code>_vertexValues</code> list. If this method fails, the content of either
|
||||
* destination is undefined.
|
||||
* \return <code>true</code> if the loading succeeded, <code>false</code> otherwise
|
||||
*/
|
||||
bool loadFile();
|
||||
|
||||
std::string _filename; ///< The filename containing the constellation bounds
|
||||
|
||||
ghoul::opengl::ProgramObject* _program;
|
||||
bool _programIsDirty;
|
||||
|
||||
/// The list of all loaded constellation bounds
|
||||
std::vector<ConstellationBound> _constellationBounds;
|
||||
|
||||
typedef std::array<float, 3> Vertex;
|
||||
std::vector<Vertex> _vertexValues; ///< A list of all vertices of all bounds
|
||||
|
||||
/// The radius of the celestial sphere onto which the bounds are drawn
|
||||
properties::FloatProperty _distance;
|
||||
|
||||
std::string _originReferenceFrame; ///< Reference frame in which bounds are defined
|
||||
|
||||
/// Used to translate between the origin reference frame and the target frame
|
||||
glm::dmat3 _stateMatrix;
|
||||
|
||||
GLuint _vao;
|
||||
GLuint _vbo;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __RENDERABLECONSTELLATIONBOUNDS_H__
|
||||
+1
-1
Submodule openspace-data updated: d098f15135...20da238d5a
@@ -0,0 +1,45 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#version __CONTEXT__
|
||||
|
||||
uniform vec4 campos;
|
||||
uniform vec4 objpos;
|
||||
//uniform vec3 camdir; // add this for specular
|
||||
|
||||
in vec4 vs_position;
|
||||
|
||||
#include "ABuffer/abufferStruct.hglsl"
|
||||
#include "ABuffer/abufferAddToBuffer.hglsl"
|
||||
#include "PowerScaling/powerScaling_fs.hglsl"
|
||||
|
||||
//#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
void main()
|
||||
{
|
||||
vec4 position = vs_position;
|
||||
float depth = pscDepth(position);
|
||||
|
||||
ABufferStruct_t frag = createGeometryFragment(vec4(1.0, 0.0, 0.0, 1.0), position, depth);
|
||||
addToBuffer(frag);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#version __CONTEXT__
|
||||
|
||||
uniform mat4 ViewProjection;
|
||||
uniform mat4 ModelTransform;
|
||||
|
||||
uniform float exponent;
|
||||
|
||||
layout(location = 0) in vec3 in_position;
|
||||
out vec4 vs_position;
|
||||
|
||||
#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 tmp = vec4(in_position, exponent);
|
||||
vs_position = tmp;
|
||||
|
||||
vec4 position = pscTransform(tmp, ModelTransform);
|
||||
vs_position = tmp;
|
||||
position = ViewProjection * position;
|
||||
gl_Position = z_normalization(position);
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <openspace/rendering/stars/renderableconstellationbounds.h>
|
||||
|
||||
#include <openspace/util/spicemanager.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <SpiceUsr.h>
|
||||
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "RenderableConstellationBounds";
|
||||
|
||||
const std::string keyFile = "File";
|
||||
const std::string keyReferenceFrame = "ReferenceFrame";
|
||||
|
||||
const std::string defaultReferenceFrame = "J2000";
|
||||
|
||||
float deg2rad(float deg) {
|
||||
return static_cast<float>((deg / 360.f) * 2.f * M_PI);
|
||||
}
|
||||
float convertHrsToRadians(float rightAscension) {
|
||||
// 360 degrees / 24h = 15 degrees/h
|
||||
return deg2rad(rightAscension * 15);
|
||||
}
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
RenderableConstellationBounds::RenderableConstellationBounds(
|
||||
const ghoul::Dictionary& dictionary)
|
||||
: Renderable(dictionary)
|
||||
, _filename("")
|
||||
, _programIsDirty(false)
|
||||
, _distance("distance", "Distance to the celestial Sphere", 15.f, 0.f, 30.f)
|
||||
, _originReferenceFrame("")
|
||||
, _vao(0)
|
||||
, _vbo(0)
|
||||
{
|
||||
bool success = dictionary.getValue(keyFile, _filename);
|
||||
if (!success) {
|
||||
LERROR("RenderableConstellationBounds did not contain a key '" <<
|
||||
keyFile << "'");
|
||||
}
|
||||
|
||||
success = dictionary.getValue(keyReferenceFrame, _originReferenceFrame);
|
||||
if (!success) {
|
||||
_originReferenceFrame = defaultReferenceFrame;
|
||||
}
|
||||
|
||||
addProperty(_distance);
|
||||
}
|
||||
|
||||
bool RenderableConstellationBounds::initialize() {
|
||||
_program = ghoul::opengl::ProgramObject::Build("ConstellationBounds",
|
||||
"${SHADERS}/constellationbounds_vs.glsl",
|
||||
"${SHADERS}/constellationbounds_fs.glsl");
|
||||
if (!_program)
|
||||
return false;
|
||||
_program->setProgramObjectCallback([&](ghoul::opengl::ProgramObject*){ this->_programIsDirty = true; });
|
||||
|
||||
|
||||
if (_vao == 0) {
|
||||
glGenVertexArrays(1, &_vao);
|
||||
LDEBUG("Generating Vertex Array id '" << _vao << "'");
|
||||
}
|
||||
if (_vbo == 0) {
|
||||
glGenBuffers(1, &_vbo);
|
||||
LDEBUG("Generating Vertex Buffer Object id '" << _vbo << "'");
|
||||
}
|
||||
|
||||
bool loadSuccess = loadFile();
|
||||
if (!loadSuccess)
|
||||
return false;
|
||||
|
||||
glBindVertexArray(_vao);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER,
|
||||
_vertexValues.size() * 3 * sizeof(float),
|
||||
&_vertexValues[0],
|
||||
GL_STATIC_DRAW
|
||||
);
|
||||
|
||||
GLint positionAttrib = _program->attributeLocation("in_position");
|
||||
glEnableVertexAttribArray(positionAttrib);
|
||||
glVertexAttribPointer(positionAttrib, 3, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RenderableConstellationBounds::deinitialize() {
|
||||
glDeleteBuffers(1, &_vbo);
|
||||
_vbo = 0;
|
||||
glDeleteVertexArrays(1, &_vao);
|
||||
_vao = 0;
|
||||
|
||||
delete _program;
|
||||
_program = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RenderableConstellationBounds::isReady() const {
|
||||
return (_vao != 0) && (_vbo != 0);
|
||||
}
|
||||
|
||||
void RenderableConstellationBounds::render(const RenderData& data) {
|
||||
_program->activate();
|
||||
|
||||
glm::mat4 modelMatrix = data.camera.modelMatrix();
|
||||
glm::mat4 viewMatrix = data.camera.viewMatrix();
|
||||
glm::mat4 projectionMatrix = data.camera.projectionMatrix();
|
||||
|
||||
setPscUniforms(_program, &data.camera, data.position);
|
||||
|
||||
_program->setUniform("exponent", _distance);
|
||||
_program->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
|
||||
_program->setUniform("ModelTransform", glm::mat4(glm::dmat4(_stateMatrix)));
|
||||
|
||||
glBindVertexArray(_vao);
|
||||
for (auto bound : _constellationBounds)
|
||||
glDrawArrays(
|
||||
GL_LINE_STRIP,
|
||||
static_cast<GLsizei>(bound.startIndex),
|
||||
static_cast<GLsizei>(bound.nVertices)
|
||||
);
|
||||
glBindVertexArray(0);
|
||||
_program->deactivate();
|
||||
}
|
||||
|
||||
void RenderableConstellationBounds::update(const UpdateData& data) {
|
||||
if (_programIsDirty) {
|
||||
_program->rebuildFromFile();
|
||||
_programIsDirty = false;
|
||||
}
|
||||
|
||||
SpiceManager::ref().getPositionTransformMatrix(
|
||||
_originReferenceFrame,
|
||||
"GALACTIC",
|
||||
data.time,
|
||||
_stateMatrix
|
||||
);
|
||||
}
|
||||
|
||||
bool RenderableConstellationBounds::loadFile() {
|
||||
if (_filename.empty())
|
||||
return false;
|
||||
|
||||
std::string fileName = absPath(_filename);
|
||||
std::ifstream file(fileName);
|
||||
if (!file.good()) {
|
||||
LERROR("Could not open file '" << fileName << "' for reading");
|
||||
return false;
|
||||
}
|
||||
|
||||
ConstellationBound currentBound;
|
||||
currentBound.constellation = "";
|
||||
|
||||
std::string currentLine;
|
||||
int currentLineNumber = 1;
|
||||
|
||||
float ra;
|
||||
float dec;
|
||||
std::string constellationName;
|
||||
SpiceDouble rectangularValues[3];
|
||||
|
||||
// Overview of the reading algorithm:
|
||||
// We keep an active ConstellationBound (currentBound) and update it until we read
|
||||
// a new constellation name, at which point the currentBound is stored away, a new,
|
||||
// empty ConstellationBound is created and set at the currentBound
|
||||
while (file.good()) {
|
||||
std::getline(file, currentLine);
|
||||
if (currentLine.empty())
|
||||
continue;
|
||||
|
||||
// @CHECK: Is this the best way of doing this? ---abock
|
||||
std::stringstream s(currentLine);
|
||||
s >> ra;
|
||||
s >> dec;
|
||||
s >> constellationName;
|
||||
|
||||
if (!s.good()) {
|
||||
// If this evaluates to true, the stream was not completely filled, which
|
||||
// means that the line was incomplete, so there was an error
|
||||
LERROR("Error reading file '" << fileName << "' at line #" << currentLineNumber);
|
||||
break;
|
||||
}
|
||||
|
||||
// Did we arrive at a new constellation?
|
||||
if (constellationName != currentBound.constellation) {
|
||||
// Store how many vertices we read during the active time of the constellation
|
||||
currentBound.nVertices = (_vertexValues.size() - currentBound.startIndex);
|
||||
// Store the constellation and start a new one
|
||||
_constellationBounds.push_back(currentBound);
|
||||
currentBound = ConstellationBound();
|
||||
currentBound.constellation = constellationName;
|
||||
currentBound.startIndex = _vertexValues.size();
|
||||
}
|
||||
|
||||
// The file format stores the right ascension in hours, while SPICE expects them
|
||||
// to be in radians
|
||||
ra = convertHrsToRadians(ra);
|
||||
|
||||
// Likewise, the declination is stored in degrees and needs to be converted
|
||||
dec = deg2rad(dec);
|
||||
|
||||
// Convert the (right ascension, declination) to rectangular coordinates)
|
||||
// The 1.0 is the distance of the celestial sphere, we will scale that in the
|
||||
// render function
|
||||
radrec_c(1.0, ra, dec, rectangularValues);
|
||||
|
||||
// Add the new vertex to our list of vertices
|
||||
_vertexValues.push_back({{
|
||||
static_cast<float>(rectangularValues[0]),
|
||||
static_cast<float>(rectangularValues[1]),
|
||||
static_cast<float>(rectangularValues[2])
|
||||
}});
|
||||
++currentLineNumber;
|
||||
}
|
||||
|
||||
// Due to the way we read the file, the first (empty) constellation bounds will not
|
||||
// contain any valid values. So we have to remove it
|
||||
_constellationBounds.erase(_constellationBounds.begin());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
// renderables
|
||||
#include <openspace/rendering/model/renderablemodel.h>
|
||||
#include <openspace/rendering/stars/renderableconstellationbounds.h>
|
||||
#include <openspace/rendering/stars/renderablestars.h>
|
||||
#include <openspace/rendering/renderableephemeris.h>
|
||||
#include <openspace/rendering/renderabletrail.h>
|
||||
@@ -62,10 +63,10 @@ void FactoryManager::initialize()
|
||||
// TODO: This has to be moved into a sort of module structure (ab)
|
||||
// Add Renderables
|
||||
_manager->addFactory(new ghoul::TemplateFactory<Renderable>);
|
||||
_manager->factory<Renderable>()->registerClass<RenderablePlanet>(
|
||||
"RenderablePlanet");
|
||||
_manager->factory<Renderable>()->registerClass<RenderableStars>(
|
||||
"RenderableStars");
|
||||
_manager->factory<Renderable>()->registerClass<RenderablePlanet>("RenderablePlanet");
|
||||
_manager->factory<Renderable>()->registerClass<RenderableStars>("RenderableStars");
|
||||
_manager->factory<Renderable>()->registerClass<RenderableConstellationBounds>
|
||||
("RenderableConstellationBounds");
|
||||
_manager->factory<Renderable>()->registerClass<RenderableEphemeris>(
|
||||
"RenderableEphemeris");
|
||||
//will replace ephemeris class soon...
|
||||
|
||||
Reference in New Issue
Block a user