Merge from feature/globebrowsing

This commit is contained in:
Erik Broberg
2016-08-02 19:25:23 -04:00
104 changed files with 2204 additions and 625 deletions
+4
View File
@@ -33,6 +33,7 @@ set(HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablepath.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplane.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplanet.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablerings.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablesphere.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablesphericalgrid.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablestars.h
@@ -54,6 +55,7 @@ set(SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablepath.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplane.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplanet.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablerings.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablesphere.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablesphericalgrid.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablestars.cpp
@@ -84,6 +86,8 @@ set(SHADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/shaders/plane_vs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/pscstandard_fs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/pscstandard_vs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/rings_vs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/rings_fs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/sphere_fs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/sphere_vs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/star_fs.glsl
+7 -5
View File
@@ -35,6 +35,7 @@
#include <modules/base/rendering/renderablestars.h>
#include <modules/base/rendering/renderabletrail.h>
#include <modules/base/rendering/renderablepath.h>
#include <modules/base/rendering/renderablerings.h>
#include <modules/base/rendering/renderablesphere.h>
#include <modules/base/rendering/renderablesphericalgrid.h>
#include <modules/base/rendering/renderableplanet.h>
@@ -71,15 +72,16 @@ void BaseModule::internalInitialize() {
auto fRenderable = FactoryManager::ref().factory<Renderable>();
ghoul_assert(fRenderable, "Renderable factory was not created");
fRenderable->registerClass<RenderablePlanet>("RenderablePlanet");
fRenderable->registerClass<RenderableStars>("RenderableStars");
fRenderable->registerClass<RenderableConstellationBounds>("RenderableConstellationBounds");
fRenderable->registerClass<RenderableModel>("RenderableModel");
fRenderable->registerClass<RenderablePath>("RenderablePath");
fRenderable->registerClass<RenderableTrail>("RenderableTrail");
fRenderable->registerClass<RenderablePlane>("RenderablePlane");
fRenderable->registerClass<RenderablePlanet>("RenderablePlanet");
fRenderable->registerClass<RenderableRings>("RenderableRings");
fRenderable->registerClass<RenderableSphere>("RenderableSphere");
fRenderable->registerClass<RenderableSphericalGrid>("RenderableSphericalGrid");
fRenderable->registerClass<RenderableModel>("RenderableModel");
fRenderable->registerClass<RenderablePlane>("RenderablePlane");
fRenderable->registerClass<RenderableStars>("RenderableStars");
fRenderable->registerClass<RenderableTrail>("RenderableTrail");
auto fEphemeris = FactoryManager::ref().factory<Ephemeris>();
ghoul_assert(fEphemeris, "Ephemeris factory was not created");
+4 -9
View File
@@ -54,24 +54,19 @@ PlanetGeometry* PlanetGeometry::createFromDictionary(const ghoul::Dictionary& di
}
PlanetGeometry::PlanetGeometry()
//: _parent(nullptr)
: _parent(nullptr)
{
setName("PlanetGeometry");
}
PlanetGeometry::~PlanetGeometry()
{
}
PlanetGeometry::~PlanetGeometry() {}
bool PlanetGeometry::initialize(Renderable* parent)
{
bool PlanetGeometry::initialize(Renderable* parent) {
_parent = parent;
return true;
}
void PlanetGeometry::deinitialize()
{
}
void PlanetGeometry::deinitialize() {}
} // namespace planetgeometry
} // namespace openspace
+1 -3
View File
@@ -109,9 +109,7 @@ bool RenderablePath::initialize() {
bool intervalSet = hasTimeInterval();
if (intervalSet) {
getInterval(_start, _stop);
std::string start = SpiceManager::ref().dateFromEphemerisTime(_start);
std::string stop = SpiceManager::ref().dateFromEphemerisTime(_stop);
completeSuccess &= getInterval(_start, _stop);
}
return completeSuccess;
+1 -1
View File
@@ -99,7 +99,7 @@ public:
const unsigned int NU_SAMPLES = 16;*/
public:
RenderablePlanet(const ghoul::Dictionary& dictionary);
explicit RenderablePlanet(const ghoul::Dictionary& dictionary);
~RenderablePlanet();
bool initialize() override;
+279
View File
@@ -0,0 +1,279 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2016 *
* *
* 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 <modules/base/rendering/renderablerings.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/util/spicemanager.h>
#include <ghoul/filesystem/filesystem>
#include <ghoul/io/texture/texturereader.h>
#include <ghoul/opengl/programobject.h>
#include <ghoul/opengl/texture.h>
#include <ghoul/opengl/textureunit.h>
namespace {
const std::string _loggerCat = "RenderableRings";
const std::string KeySize = "Size";
const std::string KeyTexture = "Texture";
const std::string KeyBody = "Body";
const std::string KeyFrame = "Frame";
const std::string KeyOrientation = "Orientation";
const std::string KeyOffset = "Offset";
const std::string KeyNightFactor = "NightFactor";
const std::string KeyTransparency = "Transparency";
}
namespace openspace {
RenderableRings::RenderableRings(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
, _texturePath("texture", "Texture")
, _size("size", "Size", glm::vec2(1.f, 1.f), glm::vec2(0.f), glm::vec2(1.f, 25.f))
, _offset("offset", "Texture Offset", glm::vec2(0.f, 1.f), glm::vec2(0.f), glm::vec2(1.f))
, _nightFactor("nightFactor", "Night Factor", 0.33f, 0.f, 1.f)
, _transparency("transparency", "Transparency", 0.15f, 0.f, 1.f)
, _shader(nullptr)
, _texture(nullptr)
, _textureFile(nullptr)
, _textureIsDirty(false)
, _quad(0)
, _vertexPositionBuffer(0)
, _planeIsDirty(false)
, _hasSunPosition(false)
{
glm::vec2 size;
dictionary.getValue(KeySize, size);
_size = size;
if (dictionary.hasKeyAndValue<std::string>(KeyBody)) {
_body = dictionary.value<std::string>(KeyBody);
_hasSunPosition = true;
}
if (dictionary.hasKeyAndValue<std::string>(KeyFrame)) {
_frame = dictionary.value<std::string>(KeyFrame);
}
if (dictionary.hasKeyAndValue<glm::mat3>(KeyOrientation)) {
_orientation = dictionary.value<glm::mat3>(KeyOrientation);
}
if (dictionary.hasKeyAndValue<std::string>(KeyTexture)) {
_texturePath = absPath(dictionary.value<std::string>(KeyTexture));
_textureFile = std::make_unique<ghoul::filesystem::File>(_texturePath);
}
if (dictionary.hasKeyAndValue<glm::vec2>(KeyOffset)) {
glm::vec2 off = dictionary.value<glm::vec2>(KeyOffset);
_offset = off;
}
if (dictionary.hasKeyAndValue<float>(KeyNightFactor)) {
float v = dictionary.value<float>(KeyNightFactor);
_nightFactor = v;
}
if (dictionary.hasKeyAndValue<float>(KeyTransparency)) {
float v = dictionary.value<float>(KeyTransparency);
_transparency = v;
}
addProperty(_offset);
addProperty(_size);
_size.onChange([&](){ _planeIsDirty = true; });
addProperty(_texturePath);
_texturePath.onChange([&](){ loadTexture(); });
_textureFile->setCallback(
[&](const ghoul::filesystem::File&) { _textureIsDirty = true; }
);
addProperty(_nightFactor);
addProperty(_transparency);
setBoundingSphere(_size.value());
}
bool RenderableRings::isReady() const {
return _shader && _texture;
}
bool RenderableRings::initialize() {
if (!_shader) {
RenderEngine& renderEngine = OsEng.renderEngine();
_shader = renderEngine.buildRenderProgram("RingProgram",
"${MODULE_BASE}/shaders/rings_vs.glsl",
"${MODULE_BASE}/shaders/rings_fs.glsl"
);
if (!_shader)
return false;
_shader->setIgnoreUniformLocationError(
ghoul::opengl::ProgramObject::IgnoreError::Yes
);
}
glGenVertexArrays(1, &_quad); // generate array
glGenBuffers(1, &_vertexPositionBuffer); // generate buffer
createPlane();
loadTexture();
return isReady();
}
bool RenderableRings::deinitialize() {
glDeleteVertexArrays(1, &_quad);
_quad = 0;
glDeleteBuffers(1, &_vertexPositionBuffer);
_vertexPositionBuffer = 0;
_textureFile = nullptr;
_texture = nullptr;
RenderEngine& renderEngine = OsEng.renderEngine();
if (_shader) {
renderEngine.removeRenderProgram(_shader);
_shader = nullptr;
}
return true;
}
void RenderableRings::render(const RenderData& data) {
_shader->activate();
_shader->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
_shader->setUniform("ModelTransform", glm::mat4(_orientation * _state));
_shader->setUniform("textureOffset", _offset);
_shader->setUniform("transparency", _transparency);
_shader->setUniform("hasSunPosition", _hasSunPosition);
if (_hasSunPosition) {
_shader->setUniform("_nightFactor", _nightFactor);
_shader->setUniform("sunPosition", _sunPosition);
}
setPscUniforms(*_shader.get(), data.camera, data.position);
ghoul::opengl::TextureUnit unit;
unit.activate();
_texture->bind();
_shader->setUniform("texture1", unit);
glDisable(GL_CULL_FACE);
glBindVertexArray(_quad);
glDrawArrays(GL_TRIANGLES, 0, 6);
glEnable(GL_CULL_FACE);
_shader->deactivate();
}
void RenderableRings::update(const UpdateData& data) {
if (_shader->isDirty()) {
_shader->rebuildFromFile();
}
if (_planeIsDirty) {
createPlane();
_planeIsDirty = false;
}
if (_textureIsDirty) {
loadTexture();
_textureIsDirty = false;
}
if (!_frame.empty()) {
_state = SpiceManager::ref().positionTransformMatrix(_frame, "GALACTIC", data.time);
}
if (!_body.empty()) {
double lt;
_sunPosition = SpiceManager::ref().targetPosition(
"SUN",
_body,
"GALACTIC",
{},
data.time,
lt
);
}
}
void RenderableRings::loadTexture() {
if (_texturePath.value() != "") {
std::unique_ptr<ghoul::opengl::Texture> texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_texturePath));
if (texture) {
LDEBUG("Loaded texture from '" << absPath(_texturePath) << "'");
_texture = std::move(texture);
// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
// _texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
_texture->uploadTexture();
_texture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
_textureFile = std::make_unique<ghoul::filesystem::File>(_texturePath);
_textureFile->setCallback(
[&](const ghoul::filesystem::File&) { _textureIsDirty = true; }
);
}
}
}
void RenderableRings::createPlane() {
// ============================
// GEOMETRY (quad)
// ============================
const GLfloat size = _size.value()[0];
const GLfloat w = _size.value()[1];
const GLfloat vertex_data[] = {
// x y z w s t
-size, -size, 0.f, w, 0.f, 0.f,
size, size, 0.f, w, 1.f, 1.f,
-size, size, 0.f, w, 0.f, 1.f,
-size, -size, 0.f, w, 0.f, 0.f,
size, -size, 0.f, w, 1.f, 0.f,
size, size, 0.f, w, 1.f, 1.f,
};
glBindVertexArray(_quad); // bind array
glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer); // bind buffer
glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast<void*>(0));
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast<void*>(sizeof(GLfloat) * 4));
}
} // namespace openspace
+87
View File
@@ -0,0 +1,87 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2016 *
* *
* 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 __RENDERABLERINGS_H__
#define __RENDERABLERINGS_H__
#include <openspace/rendering/renderable.h>
#include <openspace/properties/stringproperty.h>
#include <openspace/properties/vectorproperty.h>
#include <openspace/util/updatestructures.h>
namespace ghoul {
namespace filesystem {
class File;
}
namespace opengl {
class ProgramObject;
class Texture;
}
}
namespace openspace {
class RenderableRings : public Renderable {
public:
RenderableRings(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:
void loadTexture();
void createPlane();
properties::StringProperty _texturePath;
properties::Vec2Property _size;
properties::Vec2Property _offset;
properties::FloatProperty _nightFactor;
properties::FloatProperty _transparency;
std::unique_ptr<ghoul::opengl::ProgramObject> _shader;
std::unique_ptr<ghoul::opengl::Texture> _texture;
std::unique_ptr<ghoul::filesystem::File> _textureFile;
bool _textureIsDirty;
GLuint _quad;
GLuint _vertexPositionBuffer;
bool _planeIsDirty;
std::string _frame;
glm::mat3 _orientation;
glm::mat3 _state;
std::string _body;
glm::vec3 _sunPosition;
bool _hasSunPosition;
};
} // namespace openspace
#endif // __RENDERABLERINGS_H__
+5 -3
View File
@@ -552,14 +552,16 @@ void RenderableStars::createDataSlice(ColorOption option) {
position[0], position[1], position[2], position[3]
} };
layout.value.bvColor = _fullData[i + 3];
layout.value.luminance = _fullData[i + 4];
layout.value.absoluteMagnitude = _fullData[i + 5];
#ifdef USING_STELLAR_TEST_GRID
layout.value.bvColor = _fullData[i + 3];
layout.value.luminance = _fullData[i + 3];
layout.value.absoluteMagnitude = _fullData[i + 3];
#else
layout.value.bvColor = _fullData[i + 3];
layout.value.luminance = _fullData[i + 4];
layout.value.absoluteMagnitude = _fullData[i + 5];
#endif
_slicedData.insert(_slicedData.end(),
+1 -1
View File
@@ -37,7 +37,7 @@ namespace openspace {
class RenderableStars : public Renderable {
public:
RenderableStars(const ghoul::Dictionary& dictionary);
explicit RenderableStars(const ghoul::Dictionary& dictionary);
~RenderableStars();
bool initialize() override;
@@ -71,6 +71,10 @@ RenderableTrail::RenderableTrail(const ghoul::Dictionary& dictionary)
, _vBufferID(0)
, _needsSweep(true)
, _oldTime(std::numeric_limits<double>::max())
, _tropic(0.f)
, _ratio(0.f)
, _day(0.f)
, _increment(0.f)
{
_successfullDictionaryFetch &= dictionary.getValue(keyBody, _target);
_successfullDictionaryFetch &= dictionary.getValue(keyObserver, _observer);
+1 -1
View File
@@ -42,7 +42,7 @@ namespace openspace {
class RenderableTrail : public Renderable {
public:
RenderableTrail(const ghoul::Dictionary& dictionary);
explicit RenderableTrail(const ghoul::Dictionary& dictionary);
bool initialize() override;
bool deinitialize() override;
+93
View File
@@ -0,0 +1,93 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2016 *
* *
* 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 "PowerScaling/powerScaling_fs.hglsl"
#include "fragment.glsl"
in vec2 vs_st;
in vec4 vs_position;
uniform sampler1D texture1;
uniform vec2 textureOffset;
uniform float transparency;
uniform bool hasSunPosition;
uniform vec3 sunPosition;
uniform float _nightFactor;
Fragment getFragment() {
vec4 position = vs_position;
float depth = pscDepth(position);
// Moving the origin to the center
vec2 st = (vs_st - vec2(0.5)) * 2.0;
// The length of the texture coordinates vector is our distance from the center
float radius = length(st);
// We only want to consider ring-like objects so we need to discard everything else
if (radius > 1.0)
discard;
// Remapping the texture coordinates
// Radius \in [0,1], texCoord \in [textureOffset.x, textureOffset.y]
// textureOffset.x -> 0
// textureOffset.y -> 1
float texCoord = (radius - textureOffset.x) / (textureOffset.y - textureOffset.x);
if (texCoord < 0.f || texCoord > 1.f)
discard;
vec4 diffuse = texture(texture1, texCoord);
float colorValue = length(diffuse.rgb);
// times 3 as length of vec3(1.0, 1.0, 1.0) will return 3 and we want
// to normalize the transparency value to [0,1]
if (colorValue < 3*transparency) {
diffuse.a = pow(colorValue / (3*transparency), 1);
}
if (hasSunPosition) {
// The normal for the one plane depends on whether we are dealing
// with a front facing or back facing fragment
vec3 normal;
// The plane is oriented on the xz plane
// WARNING: This might not be the case for Uranus
if (gl_FrontFacing) {
normal = vec3(0.0, 1.0, 0.0);
}
else {
normal = vec3(0.0, -1.0, 0.0);
}
// Reduce the color of the fragment by the user factor
// if we are facing away from the Sun
if (dot(sunPosition, normal) < 0)
diffuse.xyz *= _nightFactor;
}
Fragment frag;
frag.color = diffuse;
frag.depth = depth;
return frag;
}
+47
View File
@@ -0,0 +1,47 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2016 *
* *
* 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__
#include "PowerScaling/powerScaling_vs.hglsl"
layout(location = 0) in vec4 in_position;
layout(location = 1) in vec2 in_st;
out vec2 vs_st;
out vec4 vs_position;
uniform mat4 ViewProjection;
uniform mat4 ModelTransform;
void main() {
vec4 tmp = in_position;
vec4 position = pscTransform(tmp, ModelTransform);
vs_position = tmp;
vs_st = in_st;
position = ViewProjection * position;
gl_Position = z_normalization(position);
}
@@ -59,9 +59,11 @@ namespace openspace {
DebugRenderer::~DebugRenderer()
{
// nothing to do
}
const DebugRenderer& DebugRenderer::ref() {
if (_reference == nullptr) {
try {
@@ -102,6 +104,7 @@ namespace openspace {
&clippingSpacePoints[0],
GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(clippingSpacePoints[0]), 0);
@@ -121,6 +124,7 @@ namespace openspace {
_programObject->deactivate();
}
void DebugRenderer::renderBoxFaces(const Vertices& clippingSpaceBoxCorners, RGBA rgba) const {
ghoul_assert(clippingSpaceBoxCorners.size() == 8, "Box must have 8 vertices");
const Vertices& V = clippingSpaceBoxCorners;
@@ -131,6 +135,7 @@ namespace openspace {
T.push_back(V[1]); T.push_back(V[0]); T.push_back(V[4]);
T.push_back(V[4]); T.push_back(V[5]); T.push_back(V[1]);
T.push_back(V[3]); T.push_back(V[1]); T.push_back(V[5]);
T.push_back(V[5]); T.push_back(V[7]); T.push_back(V[3]);
@@ -167,6 +172,7 @@ namespace openspace {
lineVertices.push_back(V[1]); lineVertices.push_back(V[3]);
lineVertices.push_back(V[4]); lineVertices.push_back(V[6]);
lineVertices.push_back(V[5]); lineVertices.push_back(V[7]);
DebugRenderer::ref().renderVertices(lineVertices, GL_LINES, rgba);
}
@@ -245,4 +251,5 @@ namespace openspace {
}
} // namespace openspace
} // namespace openspace
@@ -146,6 +146,7 @@ namespace openspace {
protected:
std::unique_ptr<ProgramObject> _programObject;
// A raw pointer for the reason that it should not be deleted by the static
// destructor and the normal destructor. This class has ownership
static DebugRenderer* _reference;
+1 -1
View File
@@ -158,7 +158,7 @@ else (WIN32)
target_include_directories(
openspace-module-globebrowsing
SYSTEM PUBLIC
${GDAL_INCLUDE}
${GDAL_INCLUDE_DIR}
)
target_link_libraries(
+2
View File
@@ -26,6 +26,8 @@
#define __CHUNK_INDEX_H__
#include <glm/glm.hpp>
#include <string>
#include <vector>
#include <stdint.h>
@@ -30,13 +30,6 @@
#include "PowerScaling/powerScaling_fs.hglsl"
// The heightmaps is only used in the fragment shader visually debugging
// the alignment and resolution of the heightmaps
#include <${MODULE_GLOBEBROWSING}/shaders/tilevertexheight.hglsl>
// Below are all the tiles that are used for contributing
// the actual fragment color
@@ -88,6 +81,54 @@ in vec3 ellipsoidNormalCameraSpace;
in LevelWeights levelWeights;
/////////////////////////////////////////////////////////////////////
// The heightmaps is only used in the fragment shader visually debugging
// the alignment and resolution of the heightmaps
#if USE_HEIGHTMAP
uniform Tile HeightMaps[NUMLAYERS_HEIGHTMAP];
uniform Tile HeightMapsParent1[NUMLAYERS_HEIGHTMAP];
uniform Tile HeightMapsParent2[NUMLAYERS_HEIGHTMAP];
#endif // USE_HEIGHTMAP
#if USE_HEIGHTMAP_OVERLAY
uniform Tile HeightMapOverlays[NUMLAYERS_HEIGHTMAP_OVERLAY];
uniform Tile HeightMapOverlaysParent1[NUMLAYERS_HEIGHTMAP_OVERLAY];
uniform Tile HeightMapOverlaysParent2[NUMLAYERS_HEIGHTMAP_OVERLAY];
#endif // USE_HEIGHTMAP_OVERLAY
float getUntransformedTileVertexHeight(vec2 uv, LevelWeights levelWeights){
float height = CHUNK_DEFAULT_HEIGHT;
#if USE_HEIGHTMAP
// Calculate desired level based on distance to the vertex on the ellipsoid
// Before any heightmapping is done
height = calculateUntransformedHeight(
uv,
levelWeights, // Variable to determine which texture to sample from
HeightMaps, HeightMapsParent1, HeightMapsParent2); // Three textures to sample from
#endif // USE_HEIGHTMAP
#if USE_HEIGHTMAP_OVERLAY
height = calculateUntransformedHeightOverlay(
height,
uv,
levelWeights, // Variable to determine which texture to sample from
HeightMapOverlays, HeightMapOverlaysParent1, HeightMapOverlaysParent2); // Three textures to sample from
#endif // USE_HEIGHTMAP_OVERLAY
return height;
}
/////////////////////////////////////////////////////////////////////
/**
* This method defines the fragment color pipeline which is used in both
* the local and global chunk rendering.
@@ -193,4 +234,5 @@ vec4 getTileFragColor(){
return color;
}
#endif ///TILE_FRAG_COLOR_HGLSL
+1 -1
View File
@@ -25,7 +25,7 @@
#ifndef __TILE_PROVIDER_H__
#define __TILE_PROVIDER_H__
#include "gdal_priv.h"
#include <gdal_priv.h>
#include <openspace/engine/downloadmanager.h>
#include <set>
@@ -54,7 +54,7 @@ namespace openspace {
struct TileProviderGroup {
void update();
const std::vector<std::shared_ptr<TileProvider>> TileProviderGroup::getActiveTileProviders() const;
const std::vector<std::shared_ptr<TileProvider>> getActiveTileProviders() const;
std::vector<NamedTileProvider> tileProviders;
@@ -52,6 +52,8 @@ RenderableCrawlingLine::RenderableCrawlingLine(const ghoul::Dictionary& dictiona
, _imageSequenceTime(-1.f)
, _vao(0)
, _vbo(0)
, _frameCounter(0)
, _drawLine(false)
{
dictionary.getValue(KeySource, _source);
dictionary.getValue(KeyTarget, _target);
@@ -75,7 +77,6 @@ bool RenderableCrawlingLine::isReady() const {
}
bool RenderableCrawlingLine::initialize() {
_frameCounter = 0;
bool completeSuccess = true;
RenderEngine& renderEngine = OsEng.renderEngine();
+98 -99
View File
@@ -24,30 +24,20 @@
#include <modules/newhorizons/rendering/renderablefov.h>
#include <openspace/engine/configurationmanager.h>
#include <modules/newhorizons/util/imagesequencer.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/util/spicemanager.h>
#include <modules/newhorizons/util/imagesequencer.h>
#include <openspace/util/time.h>
#include <ghoul/opengl/programobject.h>
#include <ghoul/io/texture/texturereader.h>
#include <ghoul/opengl/textureunit.h>
#include <ghoul/filesystem/filesystem.h>
#include <openspace/query/query.h>
#include <glm/gtx/projection.hpp>
#include <openspace/util/spicemanager.h>
#include <iomanip>
#include <utility>
#include <chrono>
#include <openspace/performance/performancemeasurement.h>
namespace {
const std::string _loggerCat = "RenderableFov";
//constants
const std::string keyBody = "Body";
const std::string keyFrame = "Frame";
const std::string keyPathModule = "ModulePath";
@@ -56,6 +46,9 @@ namespace {
const std::string keyInstrumentMethod = "Instrument.Method";
const std::string keyInstrumentAberration = "Instrument.Aberration";
const std::string keyPotentialTargets = "PotentialTargets";
const int InterpolationSteps = 10;
const int Stride = 8;
}
namespace openspace {
@@ -68,6 +61,10 @@ RenderableFov::RenderableFov(const ghoul::Dictionary& dictionary)
, _texture(nullptr)
, _drawFOV(false)
, _mode(GL_LINES)
//, _interceptTag{false, false, false, false, false, false, false, false}
, _withinFOV(false)
, _vBoundsSize(0)
, _vPlaneSize(40)
{
bool success = dictionary.getValue(keyBody, _spacecraft);
ghoul_assert(success, "");
@@ -109,16 +106,12 @@ void RenderableFov::allocateData() {
_bounds = std::move(res.bounds);
_boresight = std::move(res.boresightVector);
_stride = 8;
_projectionBounds.resize(_bounds.size());
int initBoundPoints = 2 * (_bounds.size() + 1);
_fovBounds.resize(initBoundPoints*_stride);
_fovBounds.resize(initBoundPoints * Stride);
_vBoundsSize = static_cast<unsigned int>(_fovBounds.size());
// allocate second vbo data
_fovPlane.resize(40);
_vPlaneSize = 40;
_isteps = 10; // Interpolation steps per intersecting segment
_fovPlane.resize(_vPlaneSize);
}
catch (const SpiceManager::SpiceException& e) {
@@ -126,10 +119,6 @@ void RenderableFov::allocateData() {
}
}
RenderableFov::~RenderableFov() {
deinitialize();
}
bool RenderableFov::initialize() {
bool completeSuccess = true;
if (_programObject == nullptr) {
@@ -172,7 +161,7 @@ void RenderableFov::sendToGPU() {
glBufferData(GL_ARRAY_BUFFER, _vBoundsSize * sizeof(GLfloat), NULL, GL_STATIC_DRAW); // orphaning the buffer, sending NULL data.
glBufferSubData(GL_ARRAY_BUFFER, 0, _vBoundsSize * sizeof(GLfloat), _fovBounds.data());
GLsizei st = sizeof(GLfloat) * _stride;
GLsizei st = sizeof(GLfloat) * Stride;
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
@@ -199,20 +188,22 @@ void RenderableFov::sendToGPU() {
}
void RenderableFov::updateGPU() {
PerfMeasure("updateGPU");
glBindBuffer(GL_ARRAY_BUFFER, _fovBoundsVBO);
glBufferSubData(GL_ARRAY_BUFFER, 0, _vBoundsSize * sizeof(GLfloat), _fovBounds.data());
if (!_rebuild){
if (!_rebuild) {
// no new points
glBindBuffer(GL_ARRAY_BUFFER, _fovPlaneVBO);
glBufferSubData(GL_ARRAY_BUFFER, 0, _vPlaneSize * sizeof(GLfloat), _fovPlane.data());
}else{
}
else {
// new points - memory change
glBindVertexArray(_fovPlaneVAO);
glBindBuffer(GL_ARRAY_BUFFER, _fovPlaneVBO);
glBufferData(GL_ARRAY_BUFFER, _vPlaneSize * sizeof(GLfloat), NULL, GL_STATIC_DRAW); // orphaning the buffer, sending NULL data.
glBufferSubData(GL_ARRAY_BUFFER, 0, _vPlaneSize * sizeof(GLfloat), _fovPlane.data());
GLsizei st = sizeof(GLfloat) * _stride;
GLsizei st = sizeof(GLfloat) * Stride;
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, st, (void*)0);
@@ -268,8 +259,9 @@ psc RenderableFov::checkForIntercept(glm::dvec3 ray) {
}
// Orthogonal projection next to planets surface
psc RenderableFov::orthogonalProjection(glm::dvec3 vecFov) {
double lt;
glm::dvec3 vecToTarget =
SpiceManager::ref().targetPosition(_fovTarget, _spacecraft, _frame, _aberrationCorrection, _time, _lt);
SpiceManager::ref().targetPosition(_fovTarget, _spacecraft, _frame, _aberrationCorrection, _time, lt);
vecFov = SpiceManager::ref().frameTransformationMatrix(_instrumentID, _frame, _time) * vecFov;
glm::dvec3 p = glm::proj(vecToTarget, vecFov);
@@ -279,7 +271,9 @@ psc RenderableFov::orthogonalProjection(glm::dvec3 vecFov) {
return projection;
}
// Bisection method, simple recurtion
glm::dvec3 RenderableFov::bisection(glm::dvec3 p1, glm::dvec3 p2, double tolerance) {
glm::dvec3 RenderableFov::bisection(glm::dvec3 p1, glm::dvec3 p2) {
const double Tolerance = 0.000000001; // very low tolerance factor
//check if point is on surface
glm::dvec3 half = interpolate(p1, p2, 0.5f);
@@ -302,53 +296,52 @@ glm::dvec3 RenderableFov::bisection(glm::dvec3 p1, glm::dvec3 p2, double toleran
ivec = result.surfaceVector;
bool intercepted = result.interceptFound;
if (glm::distance(_previousHalf, half) < tolerance){
if (glm::distance(_previousHalf, half) < Tolerance) {
_previousHalf = glm::dvec3(0);
return half;
}
_previousHalf = half;
//recursive search
if (!intercepted){
return bisection(p1, half, tolerance);
if (!intercepted) {
return bisection(p1, half);
}
else{
return bisection(half, p2, tolerance);
else {
return bisection(half, p2);
}
}
void RenderableFov::fovSurfaceIntercept(bool H[], std::vector<glm::dvec3> bounds) {
_nrInserted = 0;
_fovPlane.clear();// empty the array
double tolerance = 0.000000001; // very low tolerance factor
_fovPlane.clear(); // empty the array
glm::dvec3 mid;
glm::dvec3 interpolated;
glm::dvec3 current;
glm::dvec3 next;
glm::vec4 tmp(1);
if (bounds.size() > 1){
for (int i = 0; i < bounds.size(); i++){
if (bounds.size() > 1) {
for (int i = 0; i < bounds.size(); ++i) {
int k = (i + 1 > bounds.size() - 1) ? 0 : i + 1;
current = bounds[i];
next = bounds[k];
if (H[i] == false){ // If point is non-interceptive, project it.
if (H[i] == false) { // If point is non-interceptive, project it.
insertPoint(_fovPlane, orthogonalProjection(current).vec4(), tmp);
if (H[i + 1] == false && _withinFOV){
if (H[i + 1] == false && _withinFOV) {
// IFF incident point is also non-interceptive BUT something is within FOV
// we need then to check if this segment makes contact with surface
glm::dvec3 half = interpolate(current, next, 0.5f);
std::string bodyfixed = "IAU_";
bool convert = (_frame.find(bodyfixed) == std::string::npos);
if (convert)
if (convert) {
bodyfixed = SpiceManager::ref().frameFromBody(_fovTarget);
else
}
else {
bodyfixed = _frame;
}
SpiceManager::SurfaceInterceptResult res =
SpiceManager::ref().surfaceIntercept(_fovTarget, _spacecraft,
@@ -362,15 +355,14 @@ void RenderableFov::fovSurfaceIntercept(bool H[], std::vector<glm::dvec3> bounds
ivec = res.surfaceVector;
bool intercepted = res.interceptFound;
if (intercepted){
if (intercepted) {
// find the two outer most points of intersection
glm::dvec3 root1 = bisection(half, current, tolerance);
glm::dvec3 root2 = bisection(half, next, tolerance);
glm::dvec3 root1 = bisection(half, current);
glm::dvec3 root2 = bisection(half, next);
insertPoint(_fovPlane, orthogonalProjection(root1).vec4(), col_sq);
for (int j = 1; j < _isteps; j++){
float t = (static_cast<float>(j) / _isteps);
for (int j = 1; j < InterpolationSteps; ++j) {
float t = (static_cast<float>(j) / InterpolationSteps);
interpolated = interpolate(root1, root2, t);
_interceptVector = checkForIntercept(interpolated);
insertPoint(_fovPlane, _interceptVector.vec4(), col_sq);
@@ -379,28 +371,28 @@ void RenderableFov::fovSurfaceIntercept(bool H[], std::vector<glm::dvec3> bounds
}
}
}
if (H[i] == true && H[i + 1] == false){ // current point is interceptive, next is not
if (H[i] == true && H[i + 1] == false) { // current point is interceptive, next is not
// find outer most point for interpolation
mid = bisection(current, next, tolerance);
for (int j = 1; j <= _isteps; j++){
float t = (static_cast<float>(j) / _isteps);
mid = bisection(current, next);
for (int j = 1; j <= InterpolationSteps; ++j) {
float t = (static_cast<float>(j) / InterpolationSteps);
interpolated = interpolate(current, mid, t);
_interceptVector = (j < _isteps) ? checkForIntercept(interpolated) : orthogonalProjection(interpolated);
_interceptVector = (j < InterpolationSteps) ? checkForIntercept(interpolated) : orthogonalProjection(interpolated);
insertPoint(_fovPlane, _interceptVector.vec4(), col_sq);
}
}
if (H[i] == false && H[i + 1] == true){ // current point is non-interceptive, next is
mid = bisection(next, current, tolerance);
for (int j = 1; j <= _isteps; j++){
float t = (static_cast<float>(j) / _isteps);
mid = bisection(next, current);
for (int j = 1; j <= InterpolationSteps; ++j) {
float t = (static_cast<float>(j) / InterpolationSteps);
interpolated = interpolate(mid, next, t);
_interceptVector = (j > 1) ? checkForIntercept(interpolated) : orthogonalProjection(interpolated);
insertPoint(_fovPlane, _interceptVector.vec4(), col_sq);
}
}
if (H[i] == true && H[i + 1] == true){ // both points intercept
for (int j = 0; j <= _isteps; j++){
float t = (static_cast<float>(j) / _isteps);
for (int j = 0; j <= InterpolationSteps; ++j) {
float t = (static_cast<float>(j) / InterpolationSteps);
interpolated = interpolate(current, next, t);
_interceptVector = checkForIntercept(interpolated);
insertPoint(_fovPlane, _interceptVector.vec4(), col_sq);
@@ -408,7 +400,7 @@ void RenderableFov::fovSurfaceIntercept(bool H[], std::vector<glm::dvec3> bounds
}
}
}
if (_nrInserted == 0){
if (_nrInserted == 0) {
_rebuild = false;
}
else {
@@ -428,7 +420,8 @@ void RenderableFov::computeColors() {
if (diff <= interpolationStart)
t = static_cast<float>(1.0 - (diff / interpolationStart));
if (diff < 0.0) t = 0.f;
if (diff < 0.0)
t = 0.f;
// This is a bit hardcoded - either we go for color tables
// or make these properties.
@@ -451,35 +444,39 @@ void RenderableFov::computeColors() {
col_end.w = alpha;
}
void RenderableFov::determineTarget(){
void RenderableFov::determineTarget() {
PerfMeasure("determineTarget");
_fovTarget = _potentialTargets[0]; //default;
for (int i = 0; i < _potentialTargets.size(); i++){
for (int i = 0; i < _potentialTargets.size(); ++i) {
_withinFOV = openspace::SpiceManager::ref().isTargetInFieldOfView(
_potentialTargets[i], _spacecraft,
_potentialTargets[i],
_spacecraft,
_instrumentID,
SpiceManager::FieldOfViewMethod::Ellipsoid,
_aberrationCorrection,
SpiceManager::FieldOfViewMethod::Ellipsoid,
_aberrationCorrection,
_time
);
if (_withinFOV){
);
if (_withinFOV) {
_fovTarget = _potentialTargets[i];
break;
}
}
}
void RenderableFov::computeIntercepts(const RenderData& data){
void RenderableFov::computeIntercepts(const RenderData& data) {
PerfMeasure("computeIntercepts");
// for each FOV vector
_fovBounds.clear();
for (int i = 0; i <= _bounds.size(); i++){
for (int i = 0; i <= _bounds.size(); ++i) {
int r = (i == _bounds.size()) ? 0 : i;
std::string bodyfixed = "IAU_";
bool convert = (_frame.find(bodyfixed) == std::string::npos);
if (convert)
if (convert) {
bodyfixed = SpiceManager::ref().frameFromBody(_fovTarget);
else
}
else {
bodyfixed = _frame;
}
SpiceManager::SurfaceInterceptResult res =
SpiceManager::ref().surfaceIntercept(_fovTarget, _spacecraft,
@@ -494,23 +491,25 @@ void RenderableFov::computeIntercepts(const RenderData& data){
_interceptTag[r] = res.interceptFound;
// if not found, use the orthogonal projected point
if (!_interceptTag[r]) _projectionBounds[r] = orthogonalProjection(_bounds[r]);
if (!_interceptTag[r]) {
_projectionBounds[r] = orthogonalProjection(_bounds[r]);
}
glm::vec4 fovOrigin = glm::vec4(0); //This will have to be fixed once spacecraft is 1:1!
if (_interceptTag[r]){
if (_interceptTag[r]) {
_interceptVector = PowerScaledCoordinate::CreatePowerScaledCoordinate(ivec[0], ivec[1], ivec[2]);
_interceptVector[3] += 3;
// INTERCEPTIONS
insertPoint(_fovBounds, fovOrigin, col_start);
insertPoint(_fovBounds, _interceptVector.vec4(), col_end);
}
else if (_withinFOV){
else if (_withinFOV) {
// OBJECT IN FOV, NO INTERCEPT FOR THIS FOV-RAY
insertPoint(_fovBounds, fovOrigin, glm::vec4(0, 0, 1, 1));
insertPoint(_fovBounds, _projectionBounds[r].vec4(), col_blue);
}
else{
else {
glm::vec4 corner(_bounds[r][0], _bounds[r][1], _bounds[r][2], data.position[3] + 2);
corner = _spacecraftRotation*corner;
// NONE OF THE FOV-RAYS INTERCEPT AND NO OBJECT IN FOV
@@ -522,13 +521,16 @@ void RenderableFov::computeIntercepts(const RenderData& data){
fovSurfaceIntercept(_interceptTag, _bounds);
glm::vec3 aim = (_spacecraftRotation * glm::vec4(_boresight, 1)).xyz();
double lt;
glm::dvec3 position =
SpiceManager::ref().targetPosition(_fovTarget,
_spacecraft,
_frame,
_aberrationCorrection,
_time,
_lt);
SpiceManager::ref().targetPosition(
_fovTarget,
_spacecraft,
_frame,
_aberrationCorrection,
_time,
lt
);
psc p = PowerScaledCoordinate::CreatePowerScaledCoordinate(position.x, position.y, position.z);
pss length = p.length();
if (length[0] < DBL_EPSILON) {
@@ -536,7 +538,7 @@ void RenderableFov::computeIntercepts(const RenderData& data){
return;
}
//if aimed 80 deg away from target, dont draw white square
if (glm::dot(glm::normalize(aim), glm::normalize(p.vec3())) < 0.2){
if (glm::dot(glm::normalize(aim), glm::normalize(p.vec3())) < 0.2) {
_drawFOV = false;
}
}
@@ -551,12 +553,14 @@ void RenderableFov::render(const RenderData& data) {
_programObject->setUniform("ModelTransform", glm::mat4(1));
setPscUniforms(*_programObject.get(), data.camera, data.position);
if (openspace::ImageSequencer::ref().isReady())
if (openspace::ImageSequencer::ref().isReady()) {
_drawFOV = ImageSequencer::ref().instrumentActive(_instrumentID);
}
if (_drawFOV){
if (_drawFOV) {
// update only when time progresses.
if (_oldTime != _time){
if (_oldTime != _time) {
PerfMeasure("Total");
determineTarget();
computeColors();
computeIntercepts(data);
@@ -567,13 +571,13 @@ void RenderableFov::render(const RenderData& data) {
glLineWidth(_lineWidth);
glBindVertexArray(_fovBoundsVAO);
glDrawArrays(_mode, 0, static_cast<int>(_vBoundsSize / _stride));
glDrawArrays(_mode, 0, static_cast<int>(_vBoundsSize / Stride));
glBindVertexArray(0);
if (_drawFOV){
if (_drawFOV) {
glLineWidth(2.f);
glBindVertexArray(_fovPlaneVAO);
glDrawArrays(GL_LINE_LOOP, 0, static_cast<int>(_vPlaneSize / _stride));
glDrawArrays(GL_LINE_LOOP, 0, static_cast<int>(_vPlaneSize / Stride));
glBindVertexArray(0);
}
glLineWidth(1.f);
@@ -584,12 +588,7 @@ void RenderableFov::render(const RenderData& data) {
void RenderableFov::update(const UpdateData& data) {
_time = data.time;
_stateMatrix = SpiceManager::ref().positionTransformMatrix(_instrumentID, _frame, data.time);
_spacecraftRotation = glm::mat4(1);
for (int i = 0; i < 3; i++){
for (int j = 0; j < 3; j++){
_spacecraftRotation[i][j] = static_cast<float>(_stateMatrix[i][j]);
}
}
_spacecraftRotation = glm::mat4(_stateMatrix);
}
} // namespace openspace
+28 -30
View File
@@ -22,28 +22,30 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __RenderableFov_H__
#define __RenderableFov_H__
#ifndef __RENDERABLEFOV_H__
#define __RENDERABLEFOV_H__
// open space includes
#include <openspace/rendering/renderable.h>
#include <openspace/properties/stringproperty.h>
#include <openspace/query/query.h>
// ghoul includes
#include <ghoul/opengl/programobject.h>
#include <ghoul/opengl/texture.h>
//#include <openspace/util/runtimedata.h>
#include <openspace/util/powerscaledcoordinate.h>
#include <openspace/util/spicemanager.h>
#include <ghoul/glm.h>
namespace ghoul {
namespace opengl {
class ProgramObject;
class Texture;
} // namespace opengl
} // namespace ghoul
namespace openspace {
class RenderableFov : public Renderable{
class RenderableFov : public Renderable {
public:
RenderableFov(const ghoul::Dictionary& dictionary);
~RenderableFov();
bool initialize() override;
bool deinitialize() override;
@@ -53,14 +55,6 @@ public:
void update(const UpdateData& data) override;
private:
// properties
properties::FloatProperty _lineWidth;
properties::BoolProperty _drawSolid;
std::unique_ptr<ghoul::opengl::ProgramObject> _programObject;
ghoul::opengl::Texture* _texture;
openspace::SceneGraphNode* _targetNode;
// class methods
void loadTexture();
void allocateData();
void insertPoint(std::vector<float>& arr, glm::vec4 p, glm::vec4 c);
@@ -70,18 +64,23 @@ public:
void sendToGPU();
// helper methods
void computeColors();
void computeIntercepts(const RenderData& data);
psc orthogonalProjection(glm::dvec3 camvec);
psc checkForIntercept(glm::dvec3 ray);
psc pscInterpolate(psc p0, psc p1, float t);
glm::dvec3 interpolate(glm::dvec3 p0, glm::dvec3 p1, float t);
glm::dvec3 bisection(glm::dvec3 p1, glm::dvec3 p2, double tolerance);
glm::dvec3 bisection(glm::dvec3 p1, glm::dvec3 p2);
// properties
properties::FloatProperty _lineWidth;
properties::BoolProperty _drawSolid;
std::unique_ptr<ghoul::opengl::ProgramObject> _programObject;
ghoul::opengl::Texture* _texture;
// instance variables
int _nrInserted = 0;
int _isteps;
bool _rebuild = false;
bool _interceptTag[8];
bool _withinFOV;
@@ -106,7 +105,6 @@ public:
std::vector<glm::dvec3> _bounds;
std::vector<std::string> _potentialTargets;
bool _drawFOV;
double _lt;
// GPU
GLuint _fovBoundsVAO;
@@ -116,7 +114,6 @@ public:
GLuint _fovPlaneVBO;
unsigned int _vPlaneSize;
GLenum _mode;
unsigned int _stride;
// time
double _time = 0;
@@ -129,7 +126,8 @@ public:
glm::vec4 col_end; // intersection end color
glm::vec4 col_blue; // withinFov color
glm::vec4 col_gray; // no intersection color
};
}
#endif
} // namespace openspace
#endif // __RENDERABLEFOV_H__
@@ -207,7 +207,7 @@ void RenderablePlaneProjection::loadTexture() {
}
}
void RenderablePlaneProjection::updatePlane(const Image img, double currentTime) {
void RenderablePlaneProjection::updatePlane(const Image& img, double currentTime) {
std::string frame;
std::vector<glm::dvec3> bounds;
@@ -68,7 +68,7 @@ public:
private:
void loadTexture();
void updatePlane(const Image img, double currentTime);
void updatePlane(const Image& img, double currentTime);
std::string findClosestTarget(double currentTime);
void setTarget(std::string body);
@@ -22,33 +22,31 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <openspace/engine/configurationmanager.h>
#include <modules/newhorizons/rendering/renderableshadowcylinder.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/util/powerscaledcoordinate.h>
#include <openspace/util/spicemanager.h>
#include <ghoul/filesystem/filesystem>
#include <ghoul/io/texture/texturereader.h>
#include <ghoul/opengl/programobject.h>
#include <ghoul/opengl/texture.h>
#include <ghoul/opengl/textureunit.h>
namespace {
const std::string _loggerCat = "RenderablePlane";
const std::string _keyType = "TerminatorType";
const std::string _keyLightSource = "LightSource";
const std::string _keyObserver = "Observer";
const std::string _keyBody = "Body";
const std::string _keyBodyFrame = "BodyFrame";
const std::string _keyMainFrame = "MainFrame";
const std::string _keyAberration = "Aberration";
const std::string KeyType = "TerminatorType";
const std::string KeyLightSource = "LightSource";
const std::string KeyObserver = "Observer";
const std::string KeyBody = "Body";
const std::string KeyBodyFrame = "BodyFrame";
const std::string KeyMainFrame = "MainFrame";
const std::string KeyAberration = "Aberration";
}
namespace openspace {
RenderableShadowCylinder::RenderableShadowCylinder(const ghoul::Dictionary& dictionary)
RenderableShadowCylinder::RenderableShadowCylinder(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
, _numberOfPoints("amountOfPoints", "Points", 190, 1, 300)
, _shadowLength("shadowLength", "Shadow Length", 0.1, 0.0, 0.5)
@@ -62,49 +60,32 @@ namespace openspace {
addProperty(_shadowLength);
addProperty(_shadowColor);
bool success = dictionary.getValue(_keyType, _terminatorType);
ghoul_assert(success, "");
success = dictionary.getValue(_keyLightSource, _lightSource);
ghoul_assert(success, "");
success = dictionary.getValue(_keyObserver, _observer);
ghoul_assert(success, "");
success = dictionary.getValue(_keyBody, _body);
ghoul_assert(success, "");
success = dictionary.getValue(_keyBodyFrame, _bodyFrame);
ghoul_assert(success, "");
success = dictionary.getValue(_keyMainFrame, _mainFrame);
ghoul_assert(success, "");
std::string a = "NONE";
success = dictionary.getValue(_keyAberration, a);
_aberration = SpiceManager::AberrationCorrection(a);
ghoul_assert(success, "");
}
RenderableShadowCylinder::~RenderableShadowCylinder() {}
bool RenderableShadowCylinder::isReady() const {
bool ready = true;
if (!_shader)
ready &= false;
return ready;
_terminatorType = dictionary.value<std::string>(KeyType);
_lightSource = dictionary.value<std::string>(KeyLightSource);
_observer = dictionary.value<std::string>(KeyObserver);
_body = dictionary.value<std::string>(KeyBody);
_bodyFrame = dictionary.value<std::string>(KeyBodyFrame);
_mainFrame = dictionary.value<std::string>(KeyMainFrame);
_aberration = SpiceManager::AberrationCorrection(dictionary.value<std::string>(KeyAberration));
}
bool RenderableShadowCylinder::initialize() {
glGenVertexArrays(1, &_vao); // generate array
glGenBuffers(1, &_vbo); // generate buffer
bool completeSuccess = true;
glGenVertexArrays(1, &_vao);
glGenBuffers(1, &_vbo);
RenderEngine& renderEngine = OsEng.renderEngine();
_shader = renderEngine.buildRenderProgram("ShadowProgram",
_shader = renderEngine.buildRenderProgram(
"ShadowProgram",
"${MODULE_NEWHORIZONS}/shaders/terminatorshadow_vs.glsl",
"${MODULE_NEWHORIZONS}/shaders/terminatorshadow_fs.glsl");
"${MODULE_NEWHORIZONS}/shaders/terminatorshadow_fs.glsl"
);
if (!_shader)
return false;
return completeSuccess;
return true;
}
bool RenderableShadowCylinder::deinitialize() {
@@ -122,20 +103,16 @@ bool RenderableShadowCylinder::deinitialize() {
return true;
}
bool RenderableShadowCylinder::isReady() const {
return true;
}
void RenderableShadowCylinder::render(const RenderData& data){
glm::mat4 _transform = glm::mat4(1.0);
for (int i = 0; i < 3; i++){
for (int j = 0; j < 3; j++){
_transform[i][j] = static_cast<float>(_stateMatrix[i][j]);
}
}
glDepthMask(false);
// Activate shader
_shader->activate();
_shader->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
_shader->setUniform("ModelTransform", _transform);
_shader->setUniform("ModelTransform", glm::mat4(_stateMatrix));
_shader->setUniform("shadowColor", _shadowColor);
setPscUniforms(*_shader.get(), data.camera, data.position);
@@ -150,10 +127,10 @@ void RenderableShadowCylinder::render(const RenderData& data){
void RenderableShadowCylinder::update(const UpdateData& data) {
_stateMatrix = SpiceManager::ref().positionTransformMatrix(_bodyFrame, _mainFrame, data.time);
_time = data.time;
if (_shader->isDirty())
if (_shader->isDirty()) {
_shader->rebuildFromFile();
createCylinder();
}
createCylinder(data.time);
}
glm::vec4 psc_addition(glm::vec4 v1, glm::vec4 v2) {
@@ -169,52 +146,51 @@ glm::vec4 psc_addition(glm::vec4 v1, glm::vec4 v2) {
}
}
void RenderableShadowCylinder::createCylinder() {
double targetEpoch;
glm::dvec3 observerPosition;
void RenderableShadowCylinder::createCylinder(double time) {
auto res = SpiceManager::ref().terminatorEllipse(
_body,
_observer,
_bodyFrame,
_lightSource,
SpiceManager::terminatorTypeFromString(_terminatorType),
_aberration,
time,
_numberOfPoints
);
std::vector<psc> terminatorPoints;
SpiceManager::TerminatorType t = SpiceManager::terminatorTypeFromString(_terminatorType);
// if (_terminatorType == "UMBRAL")
// t = SpiceManager::TerminatorType::Umbral;
// else if (_terminatorType == "PENUMBRAL")
// t = SpiceManager::TerminatorType::Penumbral;
auto res = SpiceManager::ref().terminatorEllipse(_body, _observer, _bodyFrame,
_lightSource, t, _aberration, _time, _numberOfPoints);
targetEpoch = res.targetEphemerisTime;
observerPosition = std::move(res.observerPosition);
std::vector<glm::dvec3> ps = std::move(res.terminatorPoints);
for (auto&& p : ps) {
PowerScaledCoordinate psc = PowerScaledCoordinate::CreatePowerScaledCoordinate(p.x, p.y, p.z);
psc[3] += 3;
terminatorPoints.push_back(psc);
}
std::transform(
res.terminatorPoints.begin(),
res.terminatorPoints.end(),
std::back_inserter(terminatorPoints),
[](const glm::dvec3& p) {
PowerScaledCoordinate psc = PowerScaledCoordinate::CreatePowerScaledCoordinate(p.x, p.y, p.z);
psc[3] += 3;
return psc;
}
);
double lt;
glm::dvec3 vecLightSource =
SpiceManager::ref().targetPosition(_body, _lightSource, _mainFrame, _aberration, _time, lt);
SpiceManager::ref().targetPosition(_body, _lightSource, _mainFrame, _aberration, time, lt);
glm::dmat3 _stateMatrix = glm::inverse(SpiceManager::ref().positionTransformMatrix(_bodyFrame, _mainFrame, _time));
vecLightSource = _stateMatrix * vecLightSource;
vecLightSource = glm::inverse(_stateMatrix) * vecLightSource;
vecLightSource *= _shadowLength;
_vertices.clear();
psc endpoint = psc::CreatePowerScaledCoordinate(vecLightSource.x, vecLightSource.y, vecLightSource.z);
for (auto v : terminatorPoints){
_vertices.push_back(CylinderVBOLayout(v[0], v[1], v[2], v[3]));
for (const auto& v : terminatorPoints) {
_vertices.push_back({ v[0], v[1], v[2], v[3] });
glm::vec4 f = psc_addition(v.vec4(), endpoint.vec4());
_vertices.push_back(CylinderVBOLayout(f[0], f[1], f[2], f[3]));
_vertices.push_back({ f[0], f[1], f[2], f[3] });
}
_vertices.push_back(_vertices[0]);
_vertices.push_back(_vertices[1]);
glBindVertexArray(_vao); // bind array
glBindBuffer(GL_ARRAY_BUFFER, _vbo); // bind buffer
glBufferData(GL_ARRAY_BUFFER, _vertices.size() * sizeof(CylinderVBOLayout), NULL, GL_DYNAMIC_DRAW); // orphaning the buffer, sending NULL data.
glBindVertexArray(_vao);
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
glBufferData(GL_ARRAY_BUFFER, _vertices.size() * sizeof(CylinderVBOLayout), NULL, GL_DYNAMIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, _vertices.size() * sizeof(CylinderVBOLayout), &_vertices[0]);
glEnableVertexAttribArray(0);
@@ -22,8 +22,8 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef RENDERABLESHADOWCYLINDER_H_
#define RENDERABLESHADOWCYLINDER_H_
#ifndef __RENDERABLESHADOWCYLINDER_H__
#define __RENDERABLESHADOWCYLINDER_H__
#include <openspace/rendering/renderable.h>
@@ -33,67 +33,52 @@
#include <openspace/util/spicemanager.h>
namespace ghoul {
namespace filesystem {
class File;
}
namespace opengl {
class ProgramObject;
class Texture;
}
namespace opengl {
class ProgramObject;
}
}
namespace openspace {
struct LinePoint;
class RenderableShadowCylinder : public Renderable {
class RenderableShadowCylinder : public Renderable {
public:
RenderableShadowCylinder(const ghoul::Dictionary& dictionary);
public:
RenderableShadowCylinder(const ghoul::Dictionary& dictionary);
~RenderableShadowCylinder();
bool initialize() override;
bool deinitialize() override;
bool initialize() override;
bool deinitialize() override;
bool isReady() const override;
void render(const RenderData& data) override;
void update(const UpdateData& data) override;
bool isReady() const override;
void render(const RenderData& data) override;
void update(const UpdateData& data) override;
private:
struct CylinderVBOLayout {
CylinderVBOLayout(double a1, double a2, double a3, double a4){
x = a1;
y = a2;
z = a3;
e = a4;
}
float x, y, z, e;
};
void createCylinder();
properties::IntProperty _numberOfPoints;
properties::FloatProperty _shadowLength;
properties::Vec4Property _shadowColor;
std::unique_ptr<ghoul::opengl::ProgramObject> _shader;
glm::dmat3 _stateMatrix;
GLuint _vao;
GLuint _vbo;
std::vector<CylinderVBOLayout> _vertices;
std::string _terminatorType;
std::string _lightSource;
std::string _observer;
std::string _body;
std::string _bodyFrame;
std::string _mainFrame;
SpiceManager::AberrationCorrection _aberration;
double _time;
private:
struct CylinderVBOLayout {
float x, y, z, e;
};
} // namespace openspace
#endif // RENDERABLESHADOWCYLINDER_H_
void createCylinder(double time);
properties::IntProperty _numberOfPoints;
properties::FloatProperty _shadowLength;
properties::Vec4Property _shadowColor;
std::unique_ptr<ghoul::opengl::ProgramObject> _shader;
glm::dmat3 _stateMatrix;
GLuint _vao;
GLuint _vbo;
std::vector<CylinderVBOLayout> _vertices;
std::string _terminatorType;
std::string _lightSource;
std::string _observer;
std::string _body;
std::string _bodyFrame;
std::string _mainFrame;
SpiceManager::AberrationCorrection _aberration;
};
} // namespace openspace
#endif // __RENDERABLESHADOWCYLINDER_H__
+1 -1
View File
@@ -32,7 +32,7 @@ const std::string _loggerCat = "Decoder";
namespace openspace {
Decoder* Decoder::createFromDictionary(const ghoul::Dictionary& dictionary, const std::string type)
Decoder* Decoder::createFromDictionary(const ghoul::Dictionary& dictionary, const std::string& type)
{
ghoul::TemplateFactory<Decoder>* factory
= FactoryManager::ref().factory<Decoder>();
+1 -1
View File
@@ -32,7 +32,7 @@ namespace openspace {
class Decoder {
public:
static Decoder* createFromDictionary(const ghoul::Dictionary& dictionary, const std::string type);
static Decoder* createFromDictionary(const ghoul::Dictionary& dictionary, const std::string& type);
Decoder(const ghoul::Dictionary& dictionary);
virtual ~Decoder();
+67 -69
View File
@@ -22,17 +22,22 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <modules/newhorizons/util/hongkangparser.h>
#include <modules/newhorizons/util/imagesequencer.h>
#include <modules/newhorizons/util/instrumentdecoder.h>
#include <openspace/util/time.h>
#include <openspace/util/spicemanager.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/filesystem/directory.h>
#include <openspace/util/time.h>
#include <openspace/util/spicemanager.h>
#include <fstream>
#include <iterator>
#include <iomanip>
#include <limits>
#include <modules/newhorizons/util/hongkangparser.h>
#include <modules/newhorizons/util/instrumentdecoder.h>
namespace {
@@ -43,35 +48,34 @@ namespace {
}
namespace openspace {
HongKangParser::HongKangParser(std::string name, const std::string& fileName,
HongKangParser::HongKangParser(std::string name, std::string fileName,
std::string spacecraft,
ghoul::Dictionary translationDictionary,
std::vector<std::string> potentialTargets)
: _name(std::move(name))
, _defaultCaptureImage(absPath("${OPENSPACE_DATA}/scene/common/textures/placeholder.png"))
, _fileName(std::move(fileName))
, _spacecraft(std::move(spacecraft))
, _potentialTargets(std::move(potentialTargets))
{
_fileName = fileName;
_spacecraft = spacecraft;
_potentialTargets = potentialTargets;
//get the different instrument types
const std::vector<std::string>& decoders = translationDictionary.keys();
//for each decoder (assuming might have more if hong makes changes)
for (int i = 0; i < decoders.size(); i++){
for (int i = 0; i < decoders.size(); ++i) {
//create dictionary containing all {playbookKeys , spice IDs}
if (decoders[i] == "Instrument"){
if (decoders[i] == "Instrument") {
ghoul::Dictionary typeDictionary;
translationDictionary.getValue(decoders[i], typeDictionary);
//for each playbook call -> create a Decoder object
const std::vector<std::string>& keys = typeDictionary.keys();
//std::string abort = decoders[i] + "." + keyStopCommand;
for (int j = 0; j < keys.size(); j++){
for (int j = 0; j < keys.size(); ++j) {
std::string currentKey = decoders[i] + "." + keys[j];
ghoul::Dictionary decoderDictionary;
translationDictionary.getValue(currentKey, decoderDictionary);
Decoder *decoder = Decoder::createFromDictionary(decoderDictionary, decoders[i]);
Decoder* decoder = Decoder::createFromDictionary(decoderDictionary, decoders[i]);
//insert decoder to map - this will be used in the parser to determine
//behavioral characteristics of each instrument
_fileTranslation[keys[j]] = decoder;
@@ -81,43 +85,26 @@ HongKangParser::HongKangParser(std::string name, const std::string& fileName,
}
}
void HongKangParser::findPlaybookSpecifiedTarget(std::string line, std::string& target){
void HongKangParser::findPlaybookSpecifiedTarget(std::string line, std::string& target) {
//remembto add this lua later...
std::transform(line.begin(), line.end(), line.begin(), toupper);
std::vector<std::string> ptarg = _potentialTargets;
for (auto p : ptarg){
for (const auto& p : ptarg) {
// loop over all targets and determine from 4th col which target this instrument points to
std::transform(line.begin(), line.end(), line.begin(), toupper);
if (line.find(p) != std::string::npos){
target = p;
break;
}
else{
else {
// not found - we set void until we have more info.
target = "VOID";
}
}
}
void HongKangParser::writeUTCEventFile(const Image image){
std::string time_beg = SpiceManager::ref().dateFromEphemerisTime(image.startTime);
std::string time_end = SpiceManager::ref().dateFromEphemerisTime(image.stopTime);
_eventsAsUTCFile << std::fixed
<< std::setw(10) << time_beg << "->"
<< std::setw(10) << time_end
<< std::setw(10) << (int)getMetFromET(image.startTime) << "->"
<< std::setw(10) << (int)getMetFromET(image.stopTime)
<< std::setw(10) << image.target << std::setw(10);
for (auto instrument : image.activeInstruments){
_eventsAsUTCFile << " " << instrument;
}
}
bool HongKangParser::create(){
bool HongKangParser::create() {
//check input for errors.
int tmp;
bool hasObserver = SpiceManager::ref().hasNaifId(_spacecraft);
tmp = SpiceManager::ref().naifId(_spacecraft);
if (!hasObserver){
LERROR("SPICE navigation system has no pooled observer: '" << _spacecraft << "' in kernel" <<
"Please check that all necessary kernels are loaded"<<
@@ -129,8 +116,6 @@ bool HongKangParser::create(){
<< "please check modfile");
}
_eventsAsUTCFile.open("utcEvents.txt");
if (size_t position = _fileName.find_last_of(".") + 1){
if (position != std::string::npos){
std::string extension = ghoul::filesystem::File(_fileName).fileExtension();
@@ -149,7 +134,6 @@ bool HongKangParser::create(){
std::string previousTarget;
std::string previousCamera;
std::string previousScanner;
TimeRange cameraRange;
TimeRange scanRange;
@@ -176,8 +160,6 @@ bool HongKangParser::create(){
std::string met = line.substr(25, 9);
double time = getETfromMet(met);
Image image;
if (foundEvent){
//store the time, this is used for getNextCaptureTime()
_captureProgression.push_back(time);
@@ -194,8 +176,17 @@ bool HongKangParser::create(){
findPlaybookSpecifiedTarget(line, cameraTarget);
//fill image
createImage(image, time, time + shutter, cameraSpiceID, cameraTarget, _defaultCaptureImage);
writeUTCEventFile(image);
Image image;
image.startTime = time;
image.stopTime = time + shutter;
image.path = _defaultCaptureImage;
image.activeInstruments = cameraSpiceID;
image.target = cameraTarget;
image.isPlaceholder = true;
image.projected = false;
//createImage(image, time, time + shutter, cameraSpiceID, cameraTarget, _defaultCaptureImage);
//IFF spaccraft has decided to switch target, store in target map (used for: 'next observation focus')
if (previousTarget != image.target){
previousTarget = image.target;
@@ -234,11 +225,17 @@ bool HongKangParser::create(){
_instrumentTimes.push_back(std::make_pair(it->first, scanRange));
//store individual image
createImage(image, scan_start, scan_stop, scannerSpiceID, scannerTarget, _defaultCaptureImage);
writeUTCEventFile(image);
Image image;
image.startTime = scan_start;
image.stopTime = scan_stop;
image.path = _defaultCaptureImage;
image.activeInstruments = scannerSpiceID;
image.target = cameraTarget;
image.isPlaceholder = true;
image.projected = false;
_subsetMap[image.target]._subset.push_back(image);
_subsetMap[image.target]._range.setRange(scan_start);
_subsetMap[scannerTarget]._subset.push_back(image);
_subsetMap[scannerTarget]._range.setRange(scan_start);
}
}
//go back to stored position in file
@@ -256,7 +253,6 @@ bool HongKangParser::create(){
capture_start = -1;
}
}
_eventsAsUTCFile << std::endl;
}
}
}
@@ -270,31 +266,33 @@ bool HongKangParser::create(){
bool HongKangParser::augmentWithSpice(Image& image,
std::string spacecraft,
std::vector<std::string> payload,
std::vector<std::string> potentialTargets){
std::vector<std::string> potentialTargets)
{
image.target = "VOID";
// we have (?) to cast to int, unfortunately
// Why? --abock
// because: old comment --m
int exposureTime = image.stopTime - image.startTime;
if (exposureTime == 0)
if (exposureTime == 0) {
exposureTime = 1;
}
for (int i = 0; i < potentialTargets.size(); i++){
bool success = false;
for (int i = 0; i < potentialTargets.size(); ++i) {
bool _withinFOV = false;
for (int j = 0; j < image.activeInstruments.size(); j++){
for (int j = 0; j < image.activeInstruments.size(); ++j) {
double time = image.startTime;
for (int k = 0; k < exposureTime; k++){
time += k;
_withinFOV = SpiceManager::ref().isTargetInFieldOfView(
potentialTargets[i],
spacecraft,
potentialTargets[i],
spacecraft,
image.activeInstruments[j],
SpiceManager::FieldOfViewMethod::Ellipsoid,
{},
SpiceManager::FieldOfViewMethod::Ellipsoid,
{},
time
);
if (_withinFOV){
);
if (_withinFOV) {
image.target = potentialTargets[i];
_withinFOV = false;
}
@@ -304,17 +302,17 @@ bool HongKangParser::augmentWithSpice(Image& image,
return false;
}
void HongKangParser::createImage(Image& image, double startTime, double stopTime, std::vector<std::string> instr, std::string targ, std::string path) {
image.startTime = startTime;
image.stopTime = stopTime;
image.path = path;
for (int i = 0; i < instr.size(); i++){
image.activeInstruments.push_back(instr[i]);
}
image.target = targ;
image.projected = false;
image.isPlaceholder = true;
}
//Image HongKangParser::createImage(double startTime, double stopTime, std::vector<std::string> instr, std::string targ, std::string path) {
// image.startTime = startTime;
// image.stopTime = stopTime;
// image.path = path;
// for (int i = 0; i < instr.size(); i++){
// image.activeInstruments.push_back(instr[i]);
// }
// image.target = targ;
// image.projected = false;
// image.isPlaceholder = true;
//}
double HongKangParser::getETfromMet(std::string line){
std::string::size_type sz;
+8 -11
View File
@@ -28,17 +28,18 @@
#include <modules/newhorizons/util/imagesequencer.h>
#include <modules/newhorizons/util/sequenceparser.h>
#include <ghoul/misc/dictionary.h>
#include <map>
#include <string>
#include <vector>
#include <fstream>
namespace openspace {
class HongKangParser : public SequenceParser {
public:
HongKangParser();
HongKangParser(std::string name, const std::string& fileName,
HongKangParser(std::string name, std::string fileName,
std::string spacecraft,
ghoul::Dictionary dictionary,
std::vector<std::string> potentialTargets);
@@ -47,19 +48,16 @@ public:
void findPlaybookSpecifiedTarget(std::string line, std::string& target);
virtual std::map<std::string, Decoder*> getTranslation(){ return _fileTranslation; };
void writeUTCEventFile(const Image image);
private:
double getMetFromET(double et);
double getETfromMet(std::string timestr);
double getETfromMet(double met);
void createImage(Image& image,
double startTime,
double stopTime,
std::vector<std::string> instr,
std::string targ,
std::string pot);
//Image createImage(double startTime,
// double stopTime,
// std::vector<std::string> instr,
// std::string targ,
// std::string pot);
bool augmentWithSpice(Image& image,
std::string spacecraft,
@@ -74,7 +72,6 @@ private:
std::string _spacecraft;
std::map<std::string, Decoder*> _fileTranslation;
std::vector<std::string> _potentialTargets;
std::ofstream _eventsAsUTCFile;
};
}
+13 -10
View File
@@ -46,6 +46,10 @@ ImageSequencer* ImageSequencer::_instance = nullptr;
ImageSequencer::ImageSequencer()
: _hasData(false)
, _currentTime(0.0)
, _previousTime(0.0)
, _intervalLength(0.0)
, _nextCapture(0.0)
{}
ImageSequencer& ImageSequencer::ref() {
@@ -63,22 +67,22 @@ void ImageSequencer::deinitialize() {
_instance = nullptr;
}
bool ImageSequencer::isReady(){
bool ImageSequencer::isReady() {
return _hasData;
}
void ImageSequencer::updateSequencer(double time){
if (Time::ref().timeJumped() && Time::ref().deltaTime() == 0){
void ImageSequencer::updateSequencer(double time) {
if (Time::ref().timeJumped() && Time::ref().deltaTime() == 0) {
Time::ref().setDeltaTime(0.1);
} // Time is not properly updated when time jump with dt = 0
if (_currentTime != time){
if (_currentTime != time) {
_previousTime = _currentTime;
_currentTime = time;
}
}
std::pair<double, std::string> ImageSequencer::getNextTarget(){
std::pair<double, std::string> ImageSequencer::getNextTarget() {
auto compareTime = [](const std::pair<double, std::string> &a,
const std::pair<double, std::string> &b)->bool{
return a.first < b.first;
@@ -93,7 +97,7 @@ std::pair<double, std::string> ImageSequencer::getNextTarget(){
return std::make_pair(0.0, "");
}
std::pair<double, std::string> ImageSequencer::getCurrentTarget(){
std::pair<double, std::string> ImageSequencer::getCurrentTarget() {
auto compareTime = [](const std::pair<double, std::string> &a,
const std::pair<double, std::string> &b)->bool{
return a.first < b.first;
@@ -109,7 +113,7 @@ std::pair<double, std::string> ImageSequencer::getCurrentTarget(){
return std::make_pair(0.0, "No Target");
}
std::pair<double, std::vector<std::string>> ImageSequencer::getIncidentTargetList(int range){
std::pair<double, std::vector<std::string>> ImageSequencer::getIncidentTargetList(int range) {
std::pair<double, std::vector<std::string>> incidentTargets;
auto compareTime = [](const std::pair<double, std::string> &a,
@@ -158,7 +162,7 @@ double ImageSequencer::getNextCaptureTime(){
return nextCaptureTime;
}
const Image ImageSequencer::getLatestImageForInstrument(const std::string _instrumentID){
Image ImageSequencer::getLatestImageForInstrument(const std::string& _instrumentID){
auto it = _latestImages.find(_instrumentID);
if (it != _latestImages.end())
return _latestImages[_instrumentID];
@@ -369,14 +373,13 @@ void ImageSequencer::runSequenceParser(SequenceParser* parser){
// find the smallest separation of images in time
double epsilon;
epsilon = findMin(source);
//epsilon = findMin(source);
epsilon = findMin(destination);
// set epsilon as 1% smaller than min
epsilon -= min*0.01;
// IFF images have same time as mission planned capture, erase that event from
// 'predicted event file' (mission-playbook)
std::vector<Image> tmp;
for (int i = 0; i < source.size(); i++){
for (int j = 0; j < destination.size(); j++){
double diff = abs(source[i].startTime - destination[j].startTime);
+2 -1
View File
@@ -136,7 +136,8 @@ public:
/*
* returns latest captured image
*/
const Image getLatestImageForInstrument(const std::string _instrumentID);
Image getLatestImageForInstrument(const std::string& instrumentID);
private:
void sortData();
@@ -48,7 +48,6 @@ InstrumentDecoder::InstrumentDecoder(const ghoul::Dictionary& dictionary)
dictionary.getValue(keyStopCommand, _stopCommand);
}
std::vector<std::string> spice;
ghoul::Dictionary spiceDictionary;
success = dictionary.getValue(keySpice, spiceDictionary);
ghoul_assert(success, "Instrument did not provide spice ids");
+11 -9
View File
@@ -45,12 +45,12 @@ namespace {
namespace openspace {
LabelParser::LabelParser(std::string name, const std::string& fileName,
ghoul::Dictionary translationDictionary)
LabelParser::LabelParser(std::string name, std::string fileName,
const ghoul::Dictionary& translationDictionary)
: _name(std::move(name))
, _badDecoding(false)
, _fileName(std::move(fileName))
{
_fileName = fileName;
//get the different instrument types
const std::vector<std::string>& decoders = translationDictionary.keys();
//for each decoder (assuming might have more if hong makes changes)
@@ -167,9 +167,10 @@ bool LabelParser::create() {
// open up label files
std::string line = "";
std::string previousSequence;
TimeRange instrumentRange;
double startTime = 0.0;
double stopTime = 0.0;
do {
std::getline(file, line);
@@ -204,10 +205,11 @@ bool LabelParser::create() {
// return false;
// }
if (read == "START_TIME"){
std::string start = line.substr(line.find("=") + 2);
start.erase(std::remove(start.begin(), start.end(), ' '), start.end());
_startTime = SpiceManager::ref().ephemerisTimeFromDate(start);
startTime = SpiceManager::ref().ephemerisTimeFromDate(start);
count++;
getline(file, line);
@@ -222,7 +224,7 @@ bool LabelParser::create() {
),
stop.end()
);
_stopTime = SpiceManager::ref().ephemerisTimeFromDate(stop);
stopTime = SpiceManager::ref().ephemerisTimeFromDate(stop);
count++;
}
else{
@@ -244,12 +246,12 @@ bool LabelParser::create() {
Image image;
std::vector<std::string> spiceInstrument;
spiceInstrument.push_back(_instrumentID);
createImage(image, _startTime, _startTime, spiceInstrument, _target, path);
createImage(image, startTime, stopTime, spiceInstrument, _target, path);
_subsetMap[image.target]._subset.push_back(image);
_subsetMap[image.target]._range.setRange(_startTime);
_subsetMap[image.target]._range.setRange(startTime);
_captureProgression.push_back(_startTime);
_captureProgression.push_back(startTime);
std::stable_sort(_captureProgression.begin(), _captureProgression.end());
}
+2 -4
View File
@@ -37,8 +37,8 @@ class LabelParser : public SequenceParser{
public:
LabelParser();
LabelParser(std::string name,
const std::string& fileName,
ghoul::Dictionary translationDictionary);
std::string fileName,
const ghoul::Dictionary& translationDictionary);
bool create() override;
@@ -72,8 +72,6 @@ private:
std::string _instrumentHostID;
std::string _detectorType;
std::string _sequenceID;
double _startTime;
double _stopTime;
bool _badDecoding;
};
}
@@ -39,6 +39,9 @@ void renderOptionProperty(properties::Property* prop, const std::string& ownerNa
void renderSelectionProperty(properties::Property* prop, const std::string& ownerName);
void renderStringProperty(properties::Property* prop, const std::string& ownerName);
void renderIntProperty(properties::Property* prop, const std::string& ownerName);
void renderIVec2Property(properties::Property* prop, const std::string& ownerName);
void renderIVec3Property(properties::Property* prop, const std::string& ownerName);
void renderIVec4Property(properties::Property* prop, const std::string& ownerName);
void renderFloatProperty(properties::Property* prop, const std::string& ownerName);
void renderVec2Property(properties::Property* prop, const std::string& ownerName);
void renderVec3Property(properties::Property* prop, const std::string& ownerName);
@@ -135,6 +135,9 @@ void GuiPropertyComponent::renderProperty(properties::Property* prop, properties
static std::map<std::string, Func> FunctionMapping = {
{ "BoolProperty", &renderBoolProperty },
{ "IntProperty", &renderIntProperty },
{ "IVec2Property", &renderIVec2Property },
{ "IVec3Property", &renderIVec3Property },
{ "IVec4Property", &renderIVec4Property },
{ "FloatProperty", &renderFloatProperty },
{ "Vec2Property", &renderVec2Property },
{ "Vec3Property", &renderVec3Property },
+99 -7
View File
@@ -71,13 +71,24 @@ void renderOptionProperty(Property* prop, const std::string& ownerName) {
int value = *p;
std::vector<OptionProperty::Option> options = p->options();
for (const OptionProperty::Option& o : options) {
ImGui::RadioButton(name.c_str(), &value, o.value);
ImGui::SameLine();
ImGui::Text(o.description.c_str());
renderTooltip(prop);
switch (p->displayType()) {
case OptionProperty::DisplayType::RADIO: {
for (const OptionProperty::Option& o : options) {
ImGui::RadioButton(name.c_str(), &value, o.value);
ImGui::SameLine();
ImGui::Text(o.description.c_str());
renderTooltip(prop);
}
break;
}
case OptionProperty::DisplayType::DROPDOWN: {
std::string nodeNames = "";
for (const OptionProperty::Option& o : options) {
nodeNames += o.description + '\0';
}
ImGui::Combo(name.c_str(), &value, nodeNames.c_str());
break;
}
}
if (value != p->value())
executeScript(p->fullyQualifiedIdentifier(), std::to_string(value));
@@ -161,6 +172,87 @@ void renderIntProperty(Property* prop, const std::string& ownerName) {
ImGui::PopID();
}
void renderIVec2Property(Property* prop, const std::string& ownerName) {
IVec2Property* p = static_cast<IVec2Property*>(prop);
std::string name = p->guiName();
ImGui::PushID((ownerName + "." + name).c_str());
IVec2Property::ValueType value = *p;
float min = std::min(p->minValue().x, p->minValue().y);
float max = std::max(p->maxValue().x, p->maxValue().y);
ImGui::SliderInt2(
name.c_str(),
&value.x,
min,
max
);
renderTooltip(prop);
if (value != p->value()) {
executeScript(p->fullyQualifiedIdentifier(),
"{" + std::to_string(value.x) + "," + std::to_string(value.y) + "}"
);
}
ImGui::PopID();
}
void renderIVec3Property(Property* prop, const std::string& ownerName) {
IVec3Property* p = static_cast<IVec3Property*>(prop);
std::string name = p->guiName();
ImGui::PushID((ownerName + "." + name).c_str());
IVec3Property::ValueType value = *p;
float min = std::min(std::min(p->minValue().x, p->minValue().y), p->minValue().z);
float max = std::max(std::max(p->maxValue().x, p->maxValue().y), p->maxValue().z);
ImGui::SliderInt3(
name.c_str(),
&value.x,
min,
max
);
renderTooltip(prop);
if (value != p->value())
executeScript(p->fullyQualifiedIdentifier(),
"{" + std::to_string(value.x) + "," +
std::to_string(value.y) + "," +
std::to_string(value.z) + "}");
ImGui::PopID();
}
void renderIVec4Property(Property* prop, const std::string& ownerName) {
IVec4Property* p = static_cast<IVec4Property*>(prop);
std::string name = p->guiName();
ImGui::PushID((ownerName + "." + name).c_str());
IVec4Property::ValueType value = *p;
float min = std::min(std::min(std::min(
p->minValue().x, p->minValue().y), p->minValue().z), p->minValue().w);
float max = std::max(std::max(std::max(
p->maxValue().x, p->maxValue().y), p->maxValue().z), p->maxValue().w);
ImGui::SliderInt4(
name.c_str(),
&value.x,
min,
max
);
renderTooltip(prop);
if (value != p->value())
executeScript(p->fullyQualifiedIdentifier(),
"{" + std::to_string(value.x) + "," +
std::to_string(value.y) + "," +
std::to_string(value.z) + "," +
std::to_string(value.w) + "}");
ImGui::PopID();
}
void renderFloatProperty(Property* prop, const std::string& ownerName) {
FloatProperty* p = static_cast<FloatProperty*>(prop);
std::string name = p->guiName();