Merge branch 'master' into feature/loadingscreen-refactor

# Conflicts:
#	modules/galaxy/rendering/renderablegalaxy.cpp
This commit is contained in:
Alexander Bock
2017-11-09 10:51:56 -05:00
37 changed files with 1002 additions and 365 deletions

View File

@@ -68,12 +68,12 @@ void BaseModule::internalInitialize() {
"ScreenSpaceRenderable"
);
auto fScreenSpaceRenderable = FactoryManager::ref().factory<ScreenSpaceRenderable>();
ghoul_assert(fScreenSpaceRenderable, "ScreenSpaceRenderable factory was not created");
auto fSsRenderable = FactoryManager::ref().factory<ScreenSpaceRenderable>();
ghoul_assert(fSsRenderable, "ScreenSpaceRenderable factory was not created");
fScreenSpaceRenderable->registerClass<ScreenSpaceImageLocal>("ScreenSpaceImageLocal");
fScreenSpaceRenderable->registerClass<ScreenSpaceImageOnline>("ScreenSpaceImageOnline");
fScreenSpaceRenderable->registerClass<ScreenSpaceFramebuffer>("ScreenSpaceFramebuffer");
fSsRenderable->registerClass<ScreenSpaceImageLocal>("ScreenSpaceImageLocal");
fSsRenderable->registerClass<ScreenSpaceImageOnline>("ScreenSpaceImageOnline");
fSsRenderable->registerClass<ScreenSpaceFramebuffer>("ScreenSpaceFramebuffer");
auto fRenderable = FactoryManager::ref().factory<Renderable>();
ghoul_assert(fRenderable, "Renderable factory was not created");
@@ -103,9 +103,9 @@ void BaseModule::internalInitialize() {
fScale->registerClass<LuaScale>("LuaScale");
fScale->registerClass<StaticScale>("StaticScale");
auto fModelGeometry = FactoryManager::ref().factory<modelgeometry::ModelGeometry>();
ghoul_assert(fModelGeometry, "Model geometry factory was not created");
fModelGeometry->registerClass<modelgeometry::MultiModelGeometry>("MultiModelGeometry");
auto fGeometry = FactoryManager::ref().factory<modelgeometry::ModelGeometry>();
ghoul_assert(fGeometry, "Model geometry factory was not created");
fGeometry->registerClass<modelgeometry::MultiModelGeometry>("MultiModelGeometry");
}
std::vector<documentation::Documentation> BaseModule::documentations() const {

View File

@@ -113,7 +113,12 @@ double ModelGeometry::boundingRadius() const {
void ModelGeometry::render() {
glBindVertexArray(_vaoID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ibo);
glDrawElements(_mode, static_cast<GLsizei>(_indices.size()), GL_UNSIGNED_INT, nullptr);
glDrawElements(
_mode,
static_cast<GLsizei>(_indices.size()),
GL_UNSIGNED_INT,
nullptr
);
glBindVertexArray(0);
}
@@ -245,8 +250,14 @@ bool ModelGeometry::saveCachedFile(const std::string& filename) {
int64_t iSize = _indices.size();
fileStream.write(reinterpret_cast<const char*>(&iSize), sizeof(int64_t));
fileStream.write(reinterpret_cast<const char*>(_vertices.data()), sizeof(Vertex) * vSize);
fileStream.write(reinterpret_cast<const char*>(_indices.data()), sizeof(int) * iSize);
fileStream.write(
reinterpret_cast<const char*>(_vertices.data()),
sizeof(Vertex) * vSize
);
fileStream.write(
reinterpret_cast<const char*>(_indices.data()),
sizeof(int) * iSize
);
return fileStream.good();
}
@@ -280,7 +291,10 @@ bool ModelGeometry::loadCachedFile(const std::string& filename) {
_vertices.resize(vSize);
_indices.resize(iSize);
fileStream.read(reinterpret_cast<char*>(_vertices.data()), sizeof(Vertex) * vSize);
fileStream.read(
reinterpret_cast<char*>(_vertices.data()),
sizeof(Vertex) * vSize
);
fileStream.read(reinterpret_cast<char*>(_indices.data()), sizeof(int) * iSize);
return fileStream.good();

View File

@@ -188,11 +188,14 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) {
glm::dmat4 modelTransform =
glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * // Translation
glm::dmat4(data.modelTransform.rotation) * // Spice rotation
glm::scale(glm::dmat4(_modelTransform.value()), glm::dvec3(data.modelTransform.scale));
glm::scale(
glm::dmat4(_modelTransform.value()), glm::dvec3(data.modelTransform.scale)
);
glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform;
glm::vec3 directionToSun = glm::normalize(_sunPos - data.modelTransform.translation);
glm::vec3 directionToSunViewSpace = glm::mat3(data.camera.combinedViewMatrix()) * directionToSun;
glm::vec3 directionToSunViewSpace =
glm::mat3(data.camera.combinedViewMatrix()) * directionToSun;
_programObject->setUniform("directionToSunViewSpace", directionToSunViewSpace);
_programObject->setUniform("modelViewTransform", glm::mat4(modelViewTransform));
@@ -223,7 +226,9 @@ void RenderableModel::update(const UpdateData&) {
void RenderableModel::loadTexture() {
_texture = nullptr;
if (_colorTexturePath.value() != "") {
_texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath));
_texture = ghoul::io::TextureReader::ref().loadTexture(
absPath(_colorTexturePath)
);
if (_texture) {
LDEBUGC(
"RenderableModel",

View File

@@ -211,9 +211,13 @@ void RenderablePlane::render(const RenderData& data, RendererTasks&) {
_shader->activate();
//if (_projectionListener){
// //get parent node-texture and set with correct dimensions
// SceneGraphNode* textureNode = OsEng.renderEngine().scene()->sceneGraphNode(_nodeName)->parent();
// SceneGraphNode* textureNode = OsEng.renderEngine().scene()->sceneGraphNode(
// _nodeName
// )->parent();
// if (textureNode != nullptr){
// RenderablePlanetProjection* t = static_cast<RenderablePlanetProjection*>(textureNode->renderable());
// RenderablePlanetProjection* t = static_cast<RenderablePlanetProjection*>(
// textureNode->renderable()
// );
// _texture = std::unique_ptr<ghoul::opengl::Texture>(&(t->baseTexture()));
// unsigned int h = _texture->height();
// unsigned int w = _texture->width();
@@ -232,7 +236,8 @@ void RenderablePlane::render(const RenderData& data, RendererTasks&) {
rotationTransform *
glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale)) *
glm::dmat4(1.0);
const glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform;
const glm::dmat4 modelViewTransform =
data.camera.combinedViewMatrix() * modelTransform;
_shader->setUniform("modelViewProjectionTransform",
data.camera.projectionMatrix() * glm::mat4(modelViewTransform));
@@ -243,10 +248,12 @@ void RenderablePlane::render(const RenderData& data, RendererTasks&) {
_shader->setUniform("texture1", unit);
bool usingFramebufferRenderer =
OsEng.renderEngine().rendererImplementation() == RenderEngine::RendererImplementation::Framebuffer;
OsEng.renderEngine().rendererImplementation() ==
RenderEngine::RendererImplementation::Framebuffer;
bool usingABufferRenderer =
OsEng.renderEngine().rendererImplementation() == RenderEngine::RendererImplementation::ABuffer;
OsEng.renderEngine().rendererImplementation() ==
RenderEngine::RendererImplementation::ABuffer;
if (usingABufferRenderer) {
_shader->setUniform("additiveBlending", _blendMode == BlendModeAdditive);
@@ -294,13 +301,16 @@ void RenderablePlane::loadTexture() {
);
texture->uploadTexture();
// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
// Textures of planets looks much smoother with AnisotropicMipMap rather than
// linear
texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
_texture = std::move(texture);
_textureFile = std::make_unique<ghoul::filesystem::File>(_texturePath);
_textureFile->setCallback([&](const ghoul::filesystem::File&) { _textureIsDirty = true; });
_textureFile->setCallback(
[&](const ghoul::filesystem::File&) { _textureIsDirty = true; }
);
}
}
}

View File

@@ -209,7 +209,9 @@ RenderableSphere::RenderableSphere(const ghoul::Dictionary& dictionary)
_texturePath.onChange([this]() { loadTexture(); });
if (dictionary.hasKey(FadeOutThreshouldInfo.identifier)) {
_fadeOutThreshold = static_cast<float>(dictionary.value<double>(FadeOutThreshouldInfo.identifier));
_fadeOutThreshold = static_cast<float>(
dictionary.value<double>(FadeOutThreshouldInfo.identifier)
);
}
}
@@ -257,10 +259,18 @@ void RenderableSphere::render(const RenderData& data, RendererTasks&) {
setPscUniforms(*_shader.get(), data.camera, data.position);
if (_fadeOutThreshold > -1.0) {
float distCamera = glm::distance(data.camera.positionVec3(), data.position.dvec3());
double term = std::exp((-distCamera + _size * _fadeOutThreshold) / (_size * _fadeOutThreshold));
float distCamera = glm::distance(
data.camera.positionVec3(),
data.position.dvec3()
);
double term = std::exp(
(-distCamera + _size * _fadeOutThreshold) / (_size * _fadeOutThreshold)
);
_shader->setUniform("alpha", _transparency * static_cast<float>(term / (term + 1.0)));
_shader->setUniform(
"alpha",
_transparency * static_cast<float>(term / (term + 1.0))
);
}
else {
_shader->setUniform("alpha", _transparency);
@@ -275,10 +285,12 @@ void RenderableSphere::render(const RenderData& data, RendererTasks&) {
glCullFace(GL_BACK);
bool usingFramebufferRenderer =
OsEng.renderEngine().rendererImplementation() == RenderEngine::RendererImplementation::Framebuffer;
OsEng.renderEngine().rendererImplementation() ==
RenderEngine::RendererImplementation::Framebuffer;
bool usingABufferRenderer =
OsEng.renderEngine().rendererImplementation() == RenderEngine::RendererImplementation::ABuffer;
OsEng.renderEngine().rendererImplementation() ==
RenderEngine::RendererImplementation::ABuffer;
if (usingABufferRenderer) {
_shader->setUniform("additiveBlending", true);
@@ -314,7 +326,10 @@ void RenderableSphere::update(const UpdateData&) {
void RenderableSphere::loadTexture() {
if (_texturePath.value() != "") {
std::unique_ptr<ghoul::opengl::Texture> texture = ghoul::io::TextureReader::ref().loadTexture(_texturePath);
using TR = ghoul::io::TextureReader;
std::unique_ptr<ghoul::opengl::Texture> texture = TR::ref().loadTexture(
_texturePath
);
if (texture) {
LDEBUGC(
"RenderableSphere",
@@ -322,7 +337,8 @@ void RenderableSphere::loadTexture() {
);
texture->uploadTexture();
// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
// Textures of planets looks much smoother with AnisotropicMipMap rather than
// linear
// TODO: AnisotropicMipMap crashes on ATI cards ---abock
//texture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);

View File

@@ -111,7 +111,7 @@ documentation::Documentation RenderableSphericalGrid::Documentation() {
}
RenderableSphericalGrid::RenderableSphericalGrid(const ghoul::Dictionary& dictionary)
RenderableSphericalGrid::RenderableSphericalGrid(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
, _gridProgram(nullptr)
, _gridMatrix(GridMatrixInfo, glm::mat4(1.f))
@@ -254,7 +254,7 @@ void RenderableSphericalGrid::update(const UpdateData&) {
// inclination angle (north to south)
const float theta = fi * glm::pi<float>() / fsegments * 2.f; // 0 -> PI
// azimuth angle (east to west)
// azimuth angle (east to west)
const float phi = fj * glm::pi<float>() * 2.0f / fsegments; // 0 -> 2*PI
const float x = r * sin(phi) * sin(theta); //
@@ -266,7 +266,11 @@ void RenderableSphericalGrid::update(const UpdateData&) {
normal = glm::normalize(normal);
glm::vec4 tmp(x, y, z, 1);
glm::mat4 rot = glm::rotate(glm::mat4(1), glm::half_pi<float>(), glm::vec3(1, 0, 0));
glm::mat4 rot = glm::rotate(
glm::mat4(1),
glm::half_pi<float>(),
glm::vec3(1, 0, 0)
);
tmp = glm::vec4(_gridMatrix.value() * glm::dmat4(rot) * glm::dvec4(tmp));
for (int i = 0; i < 3; i++) {
@@ -290,7 +294,12 @@ void RenderableSphericalGrid::update(const UpdateData&) {
glBindVertexArray(_vaoID);
glBindBuffer(GL_ARRAY_BUFFER, _vBufferID);
glBufferData(GL_ARRAY_BUFFER, _vsize * sizeof(Vertex), _varray.data(), GL_STATIC_DRAW);
glBufferData(
GL_ARRAY_BUFFER,
_vsize * sizeof(Vertex),
_varray.data(),
GL_STATIC_DRAW
);
glVertexAttribPointer(
0,
@@ -302,7 +311,12 @@ void RenderableSphericalGrid::update(const UpdateData&) {
);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iBufferID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, _isize * sizeof(int), _iarray.data(), GL_STATIC_DRAW);
glBufferData(
GL_ELEMENT_ARRAY_BUFFER,
_isize * sizeof(int),
_iarray.data(),
GL_STATIC_DRAW
);
_gridIsDirty = false;
}

View File

@@ -229,7 +229,10 @@ void RenderableTrailOrbit::update(const UpdateData& data) {
if (_indexBufferDirty) {
// We only need to upload the index buffer if it has been invalidated
// by changing the number of values we want to represent
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _primaryRenderInformation._iBufferID);
glBindBuffer(
GL_ELEMENT_ARRAY_BUFFER,
_primaryRenderInformation._iBufferID
);
glBufferData(
GL_ELEMENT_ARRAY_BUFFER,
_indexArray.size() * sizeof(unsigned int),
@@ -411,7 +414,8 @@ RenderableTrailOrbit::UpdateReport RenderableTrailOrbit::updateTrails(
_primaryRenderInformation.first = 0;
}
else {
// Move the current pointer fowards one step to be used as the new floating
// Move the current pointer fowards one step to be used as the new
// floating
++_primaryRenderInformation.first;
}
}

View File

@@ -273,7 +273,9 @@ void RenderableTrailTrajectory::update(const UpdateData& data) {
// If we are inside the valid time, we additionally want to draw a line from the last
// correct point to the current location of the object
if (data.time.j2000Seconds() >= _start && data.time.j2000Seconds() <= _end && !_renderFullTrail) {
if (data.time.j2000Seconds() >= _start &&
data.time.j2000Seconds() <= _end && !_renderFullTrail)
{
// Copy the last valid location
glm::dvec3 v0(
_vertexArray[_primaryRenderInformation.count - 1].x,

View File

@@ -113,7 +113,8 @@ void ScreenSpaceImageLocal::update() {
texture->uploadTexture();
// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
// Textures of planets looks much smoother with AnisotropicMipMap rather than
// linear
texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
_texture = std::move(texture);

View File

@@ -106,7 +106,9 @@ ScreenSpaceImageOnline::ScreenSpaceImageOnline(const ghoul::Dictionary& dictiona
void ScreenSpaceImageOnline::update() {
if (_textureIsDirty) {
if (!_imageFuture.valid()) {
std::future<DownloadManager::MemoryFile> future = downloadImageToMemory(_texturePath);
std::future<DownloadManager::MemoryFile> future = downloadImageToMemory(
_texturePath
);
if (future.valid()) {
_imageFuture = std::move(future);
}
@@ -137,7 +139,8 @@ void ScreenSpaceImageOnline::update() {
texture->uploadTexture();
// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
// Textures of planets looks much smoother with AnisotropicMipMap rather
// than linear
texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
_texture = std::move(texture);

View File

@@ -53,7 +53,13 @@ bool WavefrontGeometry::loadModel(const std::string& filename) {
std::vector<tinyobj::shape_t> shapes;
std::vector<tinyobj::material_t> materials;
std::string err;
bool success = tinyobj::LoadObj(shapes, materials, err, filename.c_str(), filename.c_str());
bool success = tinyobj::LoadObj(
shapes,
materials,
err,
filename.c_str(),
filename.c_str()
);
if (!success) {
LERROR(err);
@@ -89,10 +95,11 @@ bool WavefrontGeometry::loadModel(const std::string& filename) {
psc tmp;
for (int i = 0; i < shapes.size(); ++i) {
for (int j = 0; j < shapes[i].mesh.positions.size() / 3; ++j) {
tmp = PowerScaledCoordinate::CreatePowerScaledCoordinate(shapes[i].mesh.positions[3 * j + 0],
tmp = PowerScaledCoordinate::CreatePowerScaledCoordinate(
shapes[i].mesh.positions[3 * j + 0],
shapes[i].mesh.positions[3 * j + 1],
shapes[i].mesh.positions[3 * j + 2]
);
);
_vertices[j + currentPosition].location[0] = tmp[0];
_vertices[j + currentPosition].location[1] = tmp[1];
@@ -104,8 +111,8 @@ bool WavefrontGeometry::loadModel(const std::string& filename) {
_vertices[j + currentPosition].normal[2] = shapes[i].mesh.normals[3 * j + 2];
if (2 * j + 1 < shapes[i].mesh.texcoords.size()) {
_vertices[j + currentPosition].tex[0] = shapes[i].mesh.texcoords[2 * j + 0];
_vertices[j + currentPosition].tex[1] = shapes[i].mesh.texcoords[2 * j + 1];
_vertices[j + currentPosition].tex[0] = shapes[i].mesh.texcoords[2*j + 0];
_vertices[j + currentPosition].tex[1] = shapes[i].mesh.texcoords[2*j + 1];
}
}
currentPosition += shapes[i].mesh.positions.size() / 3;

View File

@@ -274,7 +274,14 @@ void RenderableDebugPlane::createPlane() {
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, nullptr);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast<void*>(sizeof(GLfloat) * 4));
glVertexAttribPointer(
1,
2,
GL_FLOAT,
GL_FALSE,
sizeof(GLfloat) * 6,
reinterpret_cast<void*>(sizeof(GLfloat) * 4)
);
}
} // namespace openspace

View File

@@ -58,7 +58,9 @@ void GalaxyRaycaster::initialize() {
void GalaxyRaycaster::deinitialize() {
}
void GalaxyRaycaster::renderEntryPoints(const RenderData& data, ghoul::opengl::ProgramObject& program) {
void GalaxyRaycaster::renderEntryPoints(const RenderData& data,
ghoul::opengl::ProgramObject& program)
{
program.setUniform("modelTransform", _modelTransform);
program.setUniform("viewProjection", data.camera.viewProjectionMatrix());
program.setUniform("blendMode", static_cast<unsigned int>(1));
@@ -73,7 +75,9 @@ void GalaxyRaycaster::renderEntryPoints(const RenderData& data, ghoul::opengl::P
_boundingBox.render();
}
void GalaxyRaycaster::renderExitPoints(const RenderData& data, ghoul::opengl::ProgramObject& program) {
void GalaxyRaycaster::renderExitPoints(const RenderData& data,
ghoul::opengl::ProgramObject& program)
{
// Uniforms
program.setUniform("modelTransform", _modelTransform);
program.setUniform("viewProjection", data.camera.viewProjectionMatrix());
@@ -91,12 +95,15 @@ void GalaxyRaycaster::renderExitPoints(const RenderData& data, ghoul::opengl::Pr
glCullFace(GL_BACK);
}
void GalaxyRaycaster::preRaycast(const RaycastData& data, ghoul::opengl::ProgramObject& program) {
void GalaxyRaycaster::preRaycast(const RaycastData& data,
ghoul::opengl::ProgramObject& program)
{
std::string colorUniformName = "color" + std::to_string(data.id);
std::string stepSizeUniformName = "maxStepSize" + std::to_string(data.id);
std::string galaxyTextureUniformName = "galaxyTexture" + std::to_string(data.id);
std::string volumeAspectUniformName = "aspect" + std::to_string(data.id);
std::string opacityCoefficientUniformName = "opacityCoefficient" + std::to_string(data.id);
std::string opacityCoefficientUniformName =
"opacityCoefficient" + std::to_string(data.id);
program.setUniform(volumeAspectUniformName, _aspect);
program.setUniform(stepSizeUniformName, _stepSize);
@@ -108,7 +115,9 @@ void GalaxyRaycaster::preRaycast(const RaycastData& data, ghoul::opengl::Program
program.setUniform(galaxyTextureUniformName, *_textureUnit);
}
void GalaxyRaycaster::postRaycast(const RaycastData& data, ghoul::opengl::ProgramObject& program) {
void GalaxyRaycaster::postRaycast(const RaycastData& data,
ghoul::opengl::ProgramObject& program)
{
_textureUnit = nullptr; // release texture unit.
}
@@ -134,7 +143,9 @@ bool GalaxyRaycaster::cameraIsInside(const RenderData& data, glm::vec3& localPos
glm::vec4 modelPos = (glm::inverse(scaledModelTransform) / divisor) * camWorldPos;
localPosition = (glm::vec3(modelPos) + glm::vec3(0.5));
return (localPosition.x > 0 && localPosition.y > 0 && localPosition.z > 0 && localPosition.x < 1 && localPosition.y < 1 && localPosition.z < 1);
return (localPosition.x > 0 && localPosition.y > 0 &&
localPosition.z > 0 && localPosition.x < 1 &&
localPosition.y < 1 && localPosition.z < 1);
}
std::string GalaxyRaycaster::getBoundsVsPath() const {

View File

@@ -158,7 +158,10 @@ void RenderableGalaxy::initializeGL() {
_aspect = static_cast<glm::vec3>(_volumeDimensions);
_aspect = _aspect / std::max(std::max(_aspect.x, _aspect.y), _aspect.z);
volume::RawVolumeReader<glm::tvec4<GLfloat>> reader(_volumeFilename, _volumeDimensions);
volume::RawVolumeReader<glm::tvec4<GLfloat>> reader(
_volumeFilename,
_volumeDimensions
);
_volume = reader.read();
_texture = std::make_unique<ghoul::opengl::Texture>(
@@ -168,8 +171,12 @@ void RenderableGalaxy::initializeGL() {
GL_FLOAT,
ghoul::opengl::Texture::FilterMode::Linear,
ghoul::opengl::Texture::WrappingMode::Clamp);
_texture->setPixelData(reinterpret_cast<char*>(_volume->data()), ghoul::opengl::Texture::TakeOwnership::No);
_texture->setPixelData(reinterpret_cast<char*>(
_volume->data()),
ghoul::opengl::Texture::TakeOwnership::No
);
_texture->setDimensions(_volume->dimensions());
_texture->uploadTexture();
@@ -258,7 +265,9 @@ void RenderableGalaxy::initializeGL() {
"${MODULE_GALAXY}/shaders/points.fs",
ghoul::Dictionary());
_pointsProgram->setIgnoreUniformLocationError(ghoul::opengl::ProgramObject::IgnoreError::Yes);
_pointsProgram->setIgnoreUniformLocationError(
ghoul::opengl::ProgramObject::IgnoreError::Yes
);
GLint positionAttrib = _pointsProgram->attributeLocation("inPosition");
GLint colorAttrib = _pointsProgram->attributeLocation("inColor");
@@ -291,12 +300,18 @@ void RenderableGalaxy::update(const UpdateData& data) {
//glm::mat4 transform = glm::translate(, static_cast<glm::vec3>(_translation));
glm::vec3 eulerRotation = static_cast<glm::vec3>(_rotation);
glm::mat4 transform = glm::rotate(glm::mat4(1.0), eulerRotation.x, glm::vec3(1, 0, 0));
glm::mat4 transform = glm::rotate(
glm::mat4(1.0),
eulerRotation.x,
glm::vec3(1, 0, 0)
);
transform = glm::rotate(transform, eulerRotation.y, glm::vec3(0, 1, 0));
transform = glm::rotate(transform, eulerRotation.z, glm::vec3(0, 0, 1));
glm::mat4 volumeTransform = glm::scale(transform, static_cast<glm::vec3>(_volumeSize));
glm::mat4 volumeTransform = glm::scale(
transform,
static_cast<glm::vec3>(_volumeSize)
);
_pointTransform = glm::scale(transform, static_cast<glm::vec3>(_pointScaling));
glm::vec4 translation = glm::vec4(static_cast<glm::vec3>(_translation), 0.0);
@@ -340,13 +355,17 @@ void RenderableGalaxy::render(const RenderData& data, RendererTasks& tasks) {
} else if (length < upperRampStart) {
opacityCoefficient = 1.0; // sweet spot (max)
} else if (length < upperRampEnd) {
opacityCoefficient = 1.0 - (length - upperRampStart) / (upperRampEnd - upperRampStart); //fade out
opacityCoefficient = 1.0 - (length - upperRampStart) /
(upperRampEnd - upperRampStart); //fade out
} else {
opacityCoefficient = 0;
}
_opacityCoefficient = opacityCoefficient;
ghoul_assert(_opacityCoefficient >= 0.0 && _opacityCoefficient <= 1.0, "Opacity coefficient was not between 0 and 1");
ghoul_assert(
_opacityCoefficient >= 0.0 && _opacityCoefficient <= 1.0,
"Opacity coefficient was not between 0 and 1"
);
if (opacityCoefficient > 0) {
_raycaster->setOpacityCoefficient(_opacityCoefficient);
tasks.raycasterTasks.push_back(task);
@@ -354,7 +373,9 @@ void RenderableGalaxy::render(const RenderData& data, RendererTasks& tasks) {
}
float RenderableGalaxy::safeLength(const glm::vec3& vector) {
float maxComponent = std::max(std::max(std::abs(vector.x), std::abs(vector.y)), std::abs(vector.z));
float maxComponent = std::max(
std::max(std::abs(vector.x), std::abs(vector.y)), std::abs(vector.z)
);
return glm::length(vector / maxComponent) * maxComponent;
}

View File

@@ -86,7 +86,9 @@ void MilkywayConversionTask::perform(const Task::ProgressCallback& progressCallb
std::vector<std::string> filenames;
for (int i = 0; i < _inNSlices; i++) {
filenames.push_back(_inFilenamePrefix + std::to_string(i + _inFirstIndex) + _inFilenameSuffix);
filenames.push_back(
_inFilenamePrefix + std::to_string(i + _inFirstIndex) + _inFilenameSuffix
);
}
TextureSliceVolumeReader<glm::tvec4<GLfloat>> sliceReader(filenames, _inNSlices, 10);
@@ -96,14 +98,20 @@ void MilkywayConversionTask::perform(const Task::ProgressCallback& progressCallb
rawWriter.setDimensions(_outDimensions);
glm::vec3 resolutionRatio =
static_cast<glm::vec3>(sliceReader.dimensions()) / static_cast<glm::vec3>(rawWriter.dimensions());
static_cast<glm::vec3>(sliceReader.dimensions()) /
static_cast<glm::vec3>(rawWriter.dimensions());
VolumeSampler<TextureSliceVolumeReader<glm::tvec4<GLfloat>>> sampler(sliceReader, resolutionRatio);
std::function<glm::tvec4<GLfloat>(glm::ivec3)> sampleFunction = [&](glm::ivec3 outCoord) {
glm::vec3 inCoord = ((glm::vec3(outCoord) + glm::vec3(0.5)) * resolutionRatio) - glm::vec3(0.5);
glm::tvec4<GLfloat> value = sampler.sample(inCoord);
return value;
};
VolumeSampler<TextureSliceVolumeReader<glm::tvec4<GLfloat>>> sampler(
sliceReader,
resolutionRatio
);
std::function<glm::tvec4<GLfloat>(glm::ivec3)> sampleFunction =
[&](glm::ivec3 outCoord) {
glm::vec3 inCoord = ((glm::vec3(outCoord) + glm::vec3(0.5)) *
resolutionRatio) - glm::vec3(0.5);
glm::tvec4<GLfloat> value = sampler.sample(inCoord);
return value;
};
rawWriter.write(sampleFunction, progressCallback);
}

View File

@@ -174,7 +174,7 @@ openspace.globebrowsing.parseInfoFile = function (file)
local height = nil
if HeightFile then
local height = {
height = {
Name = Name,
Description = Description or "",
FilePath = dir .. '/' .. HeightFile,
@@ -193,9 +193,11 @@ openspace.globebrowsing.addBlendingLayersFromDirectory = function (dir, node_nam
c, h = openspace.globebrowsing.parseInfoFile(file)
if c then
openspace.printInfo("Adding color layer '" .. c["Name"] .. "'")
openspace.globebrowsing.addLayer(node_name, "ColorLayers", c)
end
if h then
openspace.printInfo("Adding height layer '" .. h["Name"] .. "'")
openspace.globebrowsing.addLayer(node_name, "HeightLayers", h)
end
end

View File

@@ -116,27 +116,29 @@ bool DataCygnet::updateTexture(){
bool texturesReady = false;
std::vector<int> selectedOptions = _dataOptions.value();
for(int option: selectedOptions){
for (int option : selectedOptions) {
float* values = data[option];
if(!values) continue;
if (!values) {
continue;
}
if(!_textures[option]){
std::unique_ptr<ghoul::opengl::Texture> texture = std::make_unique<ghoul::opengl::Texture>(
values,
_textureDimensions,
ghoul::opengl::Texture::Format::Red,
GL_RED,
GL_FLOAT,
ghoul::opengl::Texture::FilterMode::Linear,
ghoul::opengl::Texture::WrappingMode::ClampToEdge
);
if (!_textures[option]) {
auto texture = std::make_unique<ghoul::opengl::Texture>(
values,
_textureDimensions,
ghoul::opengl::Texture::Format::Red,
GL_RED,
GL_FLOAT,
ghoul::opengl::Texture::FilterMode::Linear,
ghoul::opengl::Texture::WrappingMode::ClampToEdge
);
if(texture){
if (texture) {
texture->uploadTexture();
texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
_textures[option] = std::move(texture);
}
}else{
} else {
_textures[option]->setPixelData(values);
_textures[option]->uploadTexture();
}
@@ -149,7 +151,10 @@ bool DataCygnet::downloadTextureResource(double timestamp){
if(_futureObject.valid())
return false;
std::future<DownloadManager::MemoryFile> future = IswaManager::ref().fetchDataCygnet(_data->id, timestamp);
std::future<DownloadManager::MemoryFile> future = IswaManager::ref().fetchDataCygnet(
_data->id,
timestamp
);
if(future.valid()){
_futureObject = std::move(future);
@@ -176,14 +181,14 @@ bool DataCygnet::readyToRender() const{
}
/**
* Set both transfer function textures and data textures in same function so that they bind to
* the right texture units. If separate in to two functions a list of ghoul::TextureUnit
* needs to be passed as an argument to both.
* Set both transfer function textures and data textures in same function so that they
* bind to the right texture units. If separate in to two functions a list of
* ghoul::TextureUnit needs to be passed as an argument to both.
*/
void DataCygnet::setTextureUniforms(){
std::vector<int> selectedOptions = _dataOptions.value();
int activeTextures = std::min((int)selectedOptions.size(), MAX_TEXTURES);
int activeTransferfunctions = std::min((int)_transferFunctions.size(), MAX_TEXTURES);
int activeTransferfunctions = std::min((int)_transferFunctions.size(), MAX_TEXTURES);
// Set Textures
ghoul::opengl::TextureUnit txUnits[MAX_TEXTURES];
@@ -243,10 +248,12 @@ void DataCygnet::readTransferFunctions(std::string tfPath){
std::vector<std::shared_ptr<TransferFunction>> tfs;
if(tfFile.is_open()){
while(getline(tfFile, line)){
std::shared_ptr<TransferFunction> tf = std::make_shared<TransferFunction>(absPath(line));
if(tf){
if (tfFile.is_open()) {
while (getline(tfFile, line)) {
std::shared_ptr<TransferFunction> tf = std::make_shared<TransferFunction>(
absPath(line)
);
if (tf) {
tfs.push_back(tf);
}
}
@@ -254,23 +261,30 @@ void DataCygnet::readTransferFunctions(std::string tfPath){
tfFile.close();
}
if(!tfs.empty()){
if (!tfs.empty()) {
_transferFunctions.clear();
_transferFunctions = tfs;
}
}
void DataCygnet::fillOptions(std::string& source){
std::vector<std::string> options = _dataProcessor->readMetadata(source, _textureDimensions);
void DataCygnet::fillOptions(std::string& source) {
std::vector<std::string> options = _dataProcessor->readMetadata(
source,
_textureDimensions
);
for(int i=0; i<options.size(); i++){
for (int i = 0; i < options.size(); i++) {
_dataOptions.addOption({i, options[i]});
_textures.push_back(nullptr);
}
if(_group){
std::dynamic_pointer_cast<IswaDataGroup>(_group)->registerOptions(_dataOptions.options());
_dataOptions.setValue(std::dynamic_pointer_cast<IswaDataGroup>(_group)->dataOptionsValue());
if (_group) {
std::dynamic_pointer_cast<IswaDataGroup>(_group)->registerOptions(
_dataOptions.options()
);
_dataOptions.setValue(
std::dynamic_pointer_cast<IswaDataGroup>(_group)->dataOptionsValue()
);
} else {
_dataOptions.setValue(std::vector<int>(1,0));
}
@@ -326,7 +340,7 @@ void DataCygnet::subscribeToGroup(){
}
});
groupEvent->subscribe(name(), "backgroundValuesChanged", [&](ghoul::Dictionary dict){
groupEvent->subscribe(name(), "backgroundValuesChanged", [&](ghoul::Dictionary dict) {
LDEBUG(name() + " Event backgroundValuesChanged");
glm::vec2 values;
bool success = dict.getValue("backgroundValues", values);
@@ -335,27 +349,28 @@ void DataCygnet::subscribeToGroup(){
}
});
groupEvent->subscribe(name(), "transferFunctionsChanged", [&](ghoul::Dictionary dict){
groupEvent->subscribe(name(), "transferFunctionsChanged", [&](ghoul::Dictionary dict)
{
LDEBUG(name() + " Event transferFunctionsChanged");
_transferFunctionsFile.setValue(dict.value<std::string>("transferFunctions"));
});
groupEvent->subscribe(name(), "useLogChanged", [&](const ghoul::Dictionary& dict){
groupEvent->subscribe(name(), "useLogChanged", [&](const ghoul::Dictionary& dict) {
LDEBUG(name() + " Event useLogChanged");
_useLog.setValue(dict.value<bool>("useLog"));
});
groupEvent->subscribe(name(), "useHistogramChanged", [&](ghoul::Dictionary dict){
groupEvent->subscribe(name(), "useHistogramChanged", [&](ghoul::Dictionary dict) {
LDEBUG(name() + " Event useHistogramChanged");
_useHistogram.setValue(dict.value<bool>("useHistogram"));
});
groupEvent->subscribe(name(), "autoFilterChanged", [&](ghoul::Dictionary dict){
groupEvent->subscribe(name(), "autoFilterChanged", [&](ghoul::Dictionary dict) {
LDEBUG(name() + " Event autoFilterChanged");
_autoFilter.setValue(dict.value<bool>("autoFilter"));
});
groupEvent->subscribe(name(), "updateGroup", [&](ghoul::Dictionary dict){
groupEvent->subscribe(name(), "updateGroup", [&](ghoul::Dictionary dict) {
LDEBUG(name() + " Event updateGroup");
if(_autoFilter.value())
_backgroundValues.setValue(_dataProcessor->filterValues());

View File

@@ -170,7 +170,10 @@ void IswaCygnet::render(const RenderData& data, RendererTasks&){
}
transform = transform*_rotation;
position += transform*glm::vec4(_data->spatialScale.x*_data->offset, _data->spatialScale.w);
position += transform * glm::vec4(
_data->spatialScale.x * _data->offset,
_data->spatialScale.w
);
// Activate shader
_shader->activate();
@@ -199,11 +202,18 @@ void IswaCygnet::update(const UpdateData&) {
// now if we are going backwards or forwards
double clockwiseSign = (OsEng.timeManager().time().deltaTime()>0) ? 1.0 : -1.0;
_openSpaceTime = OsEng.timeManager().time().j2000Seconds();
_realTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch());
_stateMatrix = TransformationManager::ref().frameTransformationMatrix(_data->frame, "GALACTIC", _openSpaceTime);
_realTime = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch()
);
_stateMatrix = TransformationManager::ref().frameTransformationMatrix(
_data->frame,
"GALACTIC",
_openSpaceTime
);
bool timeToUpdate = (fabs(_openSpaceTime-_lastUpdateOpenSpaceTime) >= _data->updateTime &&
(_realTime.count()-_lastUpdateRealTime.count()) > _minRealTimeUpdateInterval);
bool timeToUpdate =
(fabs(_openSpaceTime - _lastUpdateOpenSpaceTime) >= _data->updateTime &&
(_realTime.count()-_lastUpdateRealTime.count()) > _minRealTimeUpdateInterval);
if (_futureObject.valid() && DownloadManager::futureReady(_futureObject)) {
bool success = updateTextureResource();
@@ -245,7 +255,9 @@ void IswaCygnet::initializeTime() {
_openSpaceTime = OsEng.timeManager().time().j2000Seconds();
_lastUpdateOpenSpaceTime = 0.0;
_realTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch());
_realTime = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch()
);
_lastUpdateRealTime = _realTime;
_minRealTimeUpdateInterval = 100;
@@ -270,12 +282,12 @@ void IswaCygnet::initializeGroup() {
//Subscribe to enable and delete property
auto groupEvent = _group->groupEvent();
groupEvent->subscribe(name(), "enabledChanged", [&](const ghoul::Dictionary& dict){
groupEvent->subscribe(name(), "enabledChanged", [&](const ghoul::Dictionary& dict) {
LDEBUG(name() + " Event enabledChanged");
_enabled.setValue(dict.value<bool>("enabled"));
});
groupEvent->subscribe(name(), "alphaChanged", [&](const ghoul::Dictionary& dict){
groupEvent->subscribe(name(), "alphaChanged", [&](const ghoul::Dictionary& dict) {
LDEBUG(name() + " Event alphaChanged");
_alpha.setValue(dict.value<float>("alpha"));
});

View File

@@ -77,13 +77,15 @@ std::vector<int> IswaKameleonGroup::fieldlineValue(){
return _fieldlines.value();
}
void IswaKameleonGroup::setFieldlineInfo(std::string fieldlineIndexFile, std::string kameleonPath){
if(fieldlineIndexFile != _fieldlineIndexFile){
void IswaKameleonGroup::setFieldlineInfo(std::string fieldlineIndexFile,
std::string kameleonPath
{
if (fieldlineIndexFile != _fieldlineIndexFile) {
_fieldlineIndexFile = fieldlineIndexFile;
readFieldlinePaths(_fieldlineIndexFile);
}
if(kameleonPath != _kameleonPath){
if (kameleonPath != _kameleonPath) {
_kameleonPath = kameleonPath;
clearFieldlines();
updateFieldlineSeeds();
@@ -91,13 +93,16 @@ void IswaKameleonGroup::setFieldlineInfo(std::string fieldlineIndexFile, std::st
}
void IswaKameleonGroup::registerProperties(){
void IswaKameleonGroup::registerProperties() {
//OsEng.gui()._iswa.registerProperty(&_resolution);
//OsEng.gui()._iswa.registerProperty(&_fieldlines);
_resolution.onChange([this]{
LDEBUG("Group " + name() + " published resolutionChanged");
_groupEvent->publish("resolutionChanged", ghoul::Dictionary({{"resolution", _resolution.value()}}));
_groupEvent->publish(
"resolutionChanged",
ghoul::Dictionary({{"resolution", _resolution.value()}})
);
});
_fieldlines.onChange([this]{
@@ -105,7 +110,7 @@ void IswaKameleonGroup::registerProperties(){
});
}
void IswaKameleonGroup::readFieldlinePaths(std::string indexFile){
void IswaKameleonGroup::readFieldlinePaths(std::string indexFile) {
LINFO("Reading seed points paths from file '" << indexFile << "'");
// Read the index file from disk
@@ -119,7 +124,7 @@ void IswaKameleonGroup::readFieldlinePaths(std::string indexFile){
fileContent += line;
}
try{
try {
//Parse and add each fieldline as an selection
json fieldlines = json::parse(fileContent);
int i = 0;
@@ -134,8 +139,11 @@ void IswaKameleonGroup::readFieldlinePaths(std::string indexFile){
i++;
}
} catch(const std::exception& e) {
LERROR("Error when reading json file with paths to seedpoints: " + std::string(e.what()));
} catch (const std::exception& e) {
LERROR(
"Error when reading json file with paths to seedpoints: " +
std::string(e.what())
);
}
}
}
@@ -146,7 +154,7 @@ void IswaKameleonGroup::updateFieldlineSeeds(){
// SeedPath == map<int selectionValue, tuple< string name, string path, bool active > >
for (auto& seedPath: _fieldlineState) {
// if this option was turned off
if( std::find(selectedOptions.begin(), selectedOptions.end(), seedPath.first)==selectedOptions.end() && std::get<2>(seedPath.second)){
if (std::find(selectedOptions.begin(), selectedOptions.end(), seedPath.first)==selectedOptions.end() && std::get<2>(seedPath.second)){
LDEBUG("Removed fieldlines: " + std::get<0>(seedPath.second));
OsEng.scriptEngine().queueScript(
"openspace.removeSceneGraphNode('" + std::get<0>(seedPath.second) + "')",

View File

@@ -413,9 +413,20 @@ void RenderablePlanet::render(const RenderData& data, RendererTasks&) {
//glm::mat4 transform = glm::mat4(1);
//earth needs to be rotated for that to work.
glm::dmat4 rot = glm::rotate(glm::dmat4(1.0), glm::half_pi<double>(), glm::dvec3(1, 0, 0));
glm::dmat4 roty = glm::rotate(glm::dmat4(1.0), glm::half_pi<double>(), glm::dvec3(0, -1, 0));
//glm::dmat4 rotProp = glm::rotate(glm::dmat4(1.0), glm::radians(static_cast<double>(_rotation)), glm::dvec3(0, 1, 0));
glm::dmat4 rot = glm::rotate(
glm::dmat4(1.0),
glm::half_pi<double>(),
glm::dvec3(1, 0, 0)
);
glm::dmat4 roty = glm::rotate(
glm::dmat4(1.0),
glm::half_pi<double>(),
glm::dvec3(0, -1, 0)
);
//glm::dmat4 rotProp = glm::rotate(
// glm::dmat4(1.0),
// glm::radians(static_cast<double>(_rotation)), glm::dvec3(0, 1, 0)
//);
modelTransform = modelTransform * rot * roty /** rotProp*/;
glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform;
@@ -429,7 +440,10 @@ void RenderablePlanet::render(const RenderData& data, RendererTasks&) {
// Normal Transformation
//glm::mat4 translateObjTrans = glm::translate(glm::mat4(1.0), data.position.vec3());
//glm::mat4 translateCamTrans = glm::translate(glm::mat4(1.0), -data.camera.position().vec3());
//glm::mat4 translateCamTrans = glm::translate(
// glm::mat4(1.0),
// -data.camera.position().vec3()
//);
//float scaleFactor = data.camera.scaling().x * powf(10.0, data.camera.scaling().y);
//glm::mat4 scaleCamTrans = glm::scale(glm::mat4(1.0), glm::vec3(scaleFactor));
@@ -477,22 +491,48 @@ void RenderablePlanet::render(const RenderData& data, RendererTasks&) {
shadowDataArray.reserve(_shadowConfArray.size());
for (const auto & shadowConf : _shadowConfArray) {
// TO REMEMBER: all distances and lengths in world coordinates are in meters!!! We need to move this to view space...
// TO REMEMBER: all distances and lengths in world coordinates are in meters!!
// We need to move this to view space...
// Getting source and caster:
glm::dvec3 sourcePos = SpiceManager::ref().targetPosition(shadowConf.source.first, "SUN", "GALACTIC", {}, _time, lt);
glm::dvec3 sourcePos = SpiceManager::ref().targetPosition(
shadowConf.source.first,
"SUN",
"GALACTIC",
{},
_time,
lt
);
sourcePos *= 1000.0; // converting to meters
glm::dvec3 casterPos = SpiceManager::ref().targetPosition(shadowConf.caster.first, "SUN", "GALACTIC", {}, _time, lt);
glm::dvec3 casterPos = SpiceManager::ref().targetPosition(
shadowConf.caster.first,
"SUN",
"GALACTIC",
{},
_time,
lt
);
casterPos *= 1000.0; // converting to meters
psc caster_pos = PowerScaledCoordinate::CreatePowerScaledCoordinate(casterPos.x, casterPos.y, casterPos.z);
psc caster_pos = PowerScaledCoordinate::CreatePowerScaledCoordinate(
casterPos.x,
casterPos.y,
casterPos.z
);
// First we determine if the caster is shadowing the current planet (all calculations in World Coordinates):
glm::vec3 planetCasterVec = (caster_pos - data.position).vec3();
glm::vec3 sourceCasterVec = glm::vec3(casterPos - sourcePos);
float sc_length = glm::length(sourceCasterVec);
glm::vec3 planetCaster_proj = (glm::dot(planetCasterVec, sourceCasterVec) / (sc_length*sc_length)) * sourceCasterVec;
float d_test = glm::length(planetCasterVec - planetCaster_proj);
float xp_test = shadowConf.caster.second * sc_length / (shadowConf.source.second + shadowConf.caster.second);
float rp_test = shadowConf.caster.second * (glm::length(planetCaster_proj) + xp_test) / xp_test;
// First we determine if the caster is shadowing the current planet (all
// calculations in World Coordinates):
glm::vec3 planetCasterVec = (caster_pos - data.position).vec3();
glm::vec3 sourceCasterVec = glm::vec3(casterPos - sourcePos);
float sc_length = glm::length(sourceCasterVec);
glm::vec3 planetCaster_proj =
(glm::dot(planetCasterVec, sourceCasterVec) /
(sc_length*sc_length)) * sourceCasterVec;
float d_test = glm::length(planetCasterVec - planetCaster_proj);
float xp_test =
shadowConf.caster.second * sc_length /
(shadowConf.source.second + shadowConf.caster.second);
float rp_test =
shadowConf.caster.second * (glm::length(planetCaster_proj) + xp_test) /
xp_test;
double casterDistSun = glm::length(casterPos);
float planetDistSun = glm::length(data.position.vec3());
@@ -503,12 +543,13 @@ void RenderablePlanet::render(const RenderData& data, RendererTasks&) {
if (((d_test - rp_test) < _planetRadius) &&
(casterDistSun < planetDistSun) ) {
// The current caster is shadowing the current planet
shadowData.isShadowing = true;
shadowData.rs = shadowConf.source.second;
shadowData.rc = shadowConf.caster.second;
shadowData.sourceCasterVec = sourceCasterVec;
shadowData.xp = xp_test;
shadowData.xu = shadowData.rc * sc_length / (shadowData.rs - shadowData.rc);
shadowData.isShadowing = true;
shadowData.rs = shadowConf.source.second;
shadowData.rc = shadowConf.caster.second;
shadowData.sourceCasterVec = sourceCasterVec;
shadowData.xp = xp_test;
shadowData.xu =
shadowData.rc * sc_length / (shadowData.rs - shadowData.rc);
shadowData.casterPositionVec = glm::vec3(casterPos);
}
shadowDataArray.push_back(shadowData);
@@ -555,14 +596,20 @@ void RenderablePlanet::render(const RenderData& data, RendererTasks&) {
void RenderablePlanet::update(const UpdateData& data) {
// set spice-orientation in accordance to timestamp
_stateMatrix = data.modelTransform.rotation;
//_stateMatrix = SpiceManager::ref().positionTransformMatrix(_frame, "GALACTIC", data.time);
//_stateMatrix = SpiceManager::ref().positionTransformMatrix(
// _frame,
// "GALACTIC",
// data.time
//);
_time = data.time.j2000Seconds();
}
void RenderablePlanet::loadTexture() {
_texture = nullptr;
if (_colorTexturePath.value() != "") {
_texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath));
_texture = ghoul::io::TextureReader::ref().loadTexture(
absPath(_colorTexturePath)
);
if (_texture) {
if (_texture->numberOfChannels() == 1) {
_texture->setSwizzleMask({ GL_RED, GL_RED, GL_RED, GL_RED });
@@ -571,7 +618,8 @@ void RenderablePlanet::loadTexture() {
LDEBUG("Loaded texture from '" << _colorTexturePath << "'");
_texture->uploadTexture();
// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
// Textures of planets looks much smoother with AnisotropicMipMap rather than
// linear
// TODO: AnisotropicMipMap crashes on ATI cards ---abock
//_texture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
_texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
@@ -581,12 +629,16 @@ void RenderablePlanet::loadTexture() {
if (_hasNightTexture) {
_nightTexture = nullptr;
if (_nightTexturePath.value() != "") {
_nightTexture = ghoul::io::TextureReader::ref().loadTexture(absPath(_nightTexturePath));
_nightTexture = ghoul::io::TextureReader::ref().loadTexture(
absPath(_nightTexturePath)
);
if (_nightTexture) {
LDEBUG("Loaded texture from '" << _nightTexturePath << "'");
_nightTexture->uploadTexture();
_nightTexture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
//_nightTexture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
//_nightTexture->setFilter(
// ghoul::opengl::Texture::FilterMode::AnisotropicMipMap
//);
}
}
}
@@ -594,12 +646,16 @@ void RenderablePlanet::loadTexture() {
if (_hasHeightTexture) {
_heightMapTexture = nullptr;
if (_heightMapTexturePath.value() != "") {
_heightMapTexture = ghoul::io::TextureReader::ref().loadTexture(absPath(_heightMapTexturePath));
_heightMapTexture = ghoul::io::TextureReader::ref().loadTexture(
absPath(_heightMapTexturePath)
);
if (_heightMapTexture) {
LDEBUG("Loaded texture from '" << _heightMapTexturePath << "'");
_heightMapTexture->uploadTexture();
_heightMapTexture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
//_nightTexture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
//_nightTexture->setFilter(
// ghoul::opengl::Texture::FilterMode::AnisotropicMipMap
//);
}
}
}

View File

@@ -339,7 +339,10 @@ void RenderableStars::render(const RenderData& data, RendererTasks&) {
_program->setUniform("alphaValue", _alphaValue);
_program->setUniform("scaleFactor", _scaleFactor);
_program->setUniform("minBillboardSize", _minBillboardSize);
_program->setUniform("screenSize", glm::vec2(OsEng.renderEngine().renderingResolution()));
_program->setUniform(
"screenSize",
glm::vec2(OsEng.renderEngine().renderingResolution())
);
setPscUniforms(*_program.get(), data.camera, data.position);
_program->setUniform("scaling", scaling);
@@ -507,7 +510,9 @@ void RenderableStars::update(const UpdateData&) {
);
_pointSpreadFunctionTexture->uploadTexture();
}
_pointSpreadFunctionTexture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
_pointSpreadFunctionTexture->setFilter(
ghoul::opengl::Texture::FilterMode::AnisotropicMipMap
);
_pointSpreadFunctionFile = std::make_unique<ghoul::filesystem::File>(
_pointSpreadFunctionTexturePath
@@ -525,7 +530,9 @@ void RenderableStars::update(const UpdateData&) {
LDEBUG("Reloading Color Texture");
_colorTexture = nullptr;
if (_colorTexturePath.value() != "") {
_colorTexture = ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath));
_colorTexture = ghoul::io::TextureReader::ref().loadTexture(
absPath(_colorTexturePath)
);
if (_colorTexture) {
LDEBUG("Loaded texture from '" << absPath(_colorTexturePath) << "'");
_colorTexture->uploadTexture();

View File

@@ -56,7 +56,9 @@ void SpaceModule::internalInitialize() {
auto fRenderable = FactoryManager::ref().factory<Renderable>();
ghoul_assert(fRenderable, "Renderable factory was not created");
fRenderable->registerClass<RenderableConstellationBounds>("RenderableConstellationBounds");
fRenderable->registerClass<RenderableConstellationBounds>(
"RenderableConstellationBounds"
);
fRenderable->registerClass<RenderablePlanet>("RenderablePlanet");
fRenderable->registerClass<RenderableRings>("RenderableRings");
fRenderable->registerClass<RenderableStars>("RenderableStars");
@@ -73,9 +75,9 @@ void SpaceModule::internalInitialize() {
fRotation->registerClass<SpiceRotation>("SpiceRotation");
auto fPlanetGeometry = FactoryManager::ref().factory<planetgeometry::PlanetGeometry>();
ghoul_assert(fPlanetGeometry, "Planet geometry factory was not created");
fPlanetGeometry->registerClass<planetgeometry::SimpleSphereGeometry>("SimpleSphere");
auto fGeometry = FactoryManager::ref().factory<planetgeometry::PlanetGeometry>();
ghoul_assert(fGeometry, "Planet geometry factory was not created");
fGeometry->registerClass<planetgeometry::SimpleSphereGeometry>("SimpleSphere");
}
std::vector<documentation::Documentation> SpaceModule::documentations() const {

View File

@@ -280,7 +280,8 @@ double KeplerTranslation::eccentricAnomaly(double meanAnomaly) const {
double f = x - s - meanAnomaly;
double f1 = 1 - c;
double f2 = s;
return x + (-5 * f / (f1 + sign(f1) * sqrt(std::abs(16 * f1 * f1 - 20 * f * f2))));
return x + (-5 * f / (f1 + sign(f1) *
sqrt(std::abs(16 * f1 * f1 - 20 * f * f2))));
};
return solveIteration(solver, e, 0.0, 8);
}

View File

@@ -235,7 +235,11 @@ void RenderableCrawlingLine::update(const UpdateData& data) {
// data.time.j2000Seconds()
// );
glm::dmat3 tm = SpiceManager::ref().frameTransformationMatrix(_instrumentName, "ECLIPJ2000", data.time.j2000Seconds());
glm::dmat3 tm = SpiceManager::ref().frameTransformationMatrix(
_instrumentName,
"ECLIPJ2000",
data.time.j2000Seconds()
);
//_positions[SourcePosition] = { 0.f, 0.f, 0.f, 0.f };
@@ -267,7 +271,11 @@ void RenderableCrawlingLine::update(const UpdateData& data) {
{ _lineColorBegin.r, _lineColorBegin.g, _lineColorBegin.b, _lineColorBegin.a }
},
{
{ target.x * powf(10, target.w), target.y * powf(10, target.w), target.z * powf(10, target.w) },
{
target.x * powf(10, target.w),
target.y * powf(10, target.w),
target.z * powf(10, target.w)
},
{ _lineColorEnd.r, _lineColorEnd.g, _lineColorEnd.b, _lineColorEnd.a }
}
};

View File

@@ -306,7 +306,9 @@ void RenderableFov::initializeGL() {
);
// Fetch information about the specific instrument
SpiceManager::FieldOfViewResult res = SpiceManager::ref().fieldOfView(_instrument.name);
SpiceManager::FieldOfViewResult res = SpiceManager::ref().fieldOfView(
_instrument.name
);
// Right now, we can only deal with rectangles or polygons. Circles and ellipses only
// return one or two bound vectors that have to used to construct an approximation
@@ -365,7 +367,7 @@ void RenderableFov::initializeGL() {
GL_FLOAT,
GL_FALSE,
sizeof(RenderInformation::VBOData),
nullptr // = reinterpret_cast<void*>(offsetof(RenderInformation::VBOData, position))
nullptr
);
glEnableVertexAttribArray(1);
glVertexAttribIPointer(
@@ -395,7 +397,7 @@ void RenderableFov::initializeGL() {
GL_FLOAT,
GL_FALSE,
sizeof(RenderInformation::VBOData),
nullptr // = reinterpret_cast<void*>(offsetof(RenderInformation::VBOData, position))
nullptr
);
glEnableVertexAttribArray(1);
glVertexAttribIPointer(
@@ -425,16 +427,28 @@ bool RenderableFov::isReady() const {
}
// Orthogonal projection next to planets surface
glm::dvec3 RenderableFov::orthogonalProjection(const glm::dvec3& vecFov, double time, const std::string& target) const {
glm::dvec3 vecToTarget = SpiceManager::ref().targetPosition(target, _instrument.spacecraft, _instrument.referenceFrame, _instrument.aberrationCorrection, time);
glm::dvec3 fov = SpiceManager::ref().frameTransformationMatrix(_instrument.name, _instrument.referenceFrame, time) * vecFov;
glm::dvec3 RenderableFov::orthogonalProjection(const glm::dvec3& vecFov, double time,
const std::string& target) const
{
glm::dvec3 vecToTarget = SpiceManager::ref().targetPosition(
target,
_instrument.spacecraft,
_instrument.referenceFrame,
_instrument.aberrationCorrection,
time
);
glm::dvec3 fov = SpiceManager::ref().frameTransformationMatrix(
_instrument.name,
_instrument.referenceFrame,
time
) * vecFov;
glm::dvec3 p = glm::proj(vecToTarget, fov);
return p * 1000.0; // km -> m
}
template <typename Func>
double bisect(const glm::dvec3& p1, const glm::dvec3& p2, Func testFunction,
const glm::dvec3& previousHalf = glm::dvec3(std::numeric_limits<double>::max()))
const glm::dvec3& previousHalf = glm::dvec3(std::numeric_limits<double>::max()))
{
const double Tolerance = 0.00000001;
const glm::dvec3 half = glm::mix(p1, p2, 0.5);
@@ -450,8 +464,12 @@ double bisect(const glm::dvec3& p1, const glm::dvec3& p2, Func testFunction,
}
}
void RenderableFov::computeIntercepts(const UpdateData& data, const std::string& target, bool isInFov) {
auto makeBodyFixedReferenceFrame = [&target](std::string ref) -> std::pair<std::string, bool> {
void RenderableFov::computeIntercepts(const UpdateData& data, const std::string& target,
bool isInFov)
{
auto makeBodyFixedReferenceFrame =
[&target](std::string ref) -> std::pair<std::string, bool>
{
bool convert = (ref.find("IAU_") == std::string::npos);
if (convert) {
return { SpiceManager::ref().frameFromBody(target), true };
@@ -487,7 +505,8 @@ void RenderableFov::computeIntercepts(const UpdateData& data, const std::string&
second = {
{ o.x, o.y, o.z },
RenderInformation::VertexColorTypeDefaultEnd // This had a different color (0.4) before ---abock
// This had a different color (0.4) before ---abock
RenderInformation::VertexColorTypeDefaultEnd
};
}
else {
@@ -533,7 +552,11 @@ void RenderableFov::computeIntercepts(const UpdateData& data, const std::string&
}
else {
// This point did not intersect the target though others did
glm::vec3 o = orthogonalProjection(bound, data.time.j2000Seconds(), target);
glm::vec3 o = orthogonalProjection(
bound,
data.time.j2000Seconds(),
target
);
second = {
{ o.x, o.y, o.z },
RenderInformation::VertexColorTypeInFieldOfView
@@ -597,15 +620,16 @@ void RenderableFov::computeIntercepts(const UpdateData& data, const std::string&
// the intercept vector is in meter and contains a standoff distance offset
auto interceptVector = [&](const glm::dvec3& probe) -> glm::dvec3 {
auto ref = makeBodyFixedReferenceFrame(_instrument.referenceFrame);
SpiceManager::SurfaceInterceptResult r = SpiceManager::ref().surfaceIntercept(
target,
_instrument.spacecraft,
_instrument.name,
ref.first,
_instrument.aberrationCorrection,
data.time.j2000Seconds(),
probe
);
SpiceManager::SurfaceInterceptResult r =
SpiceManager::ref().surfaceIntercept(
target,
_instrument.spacecraft,
_instrument.name,
ref.first,
_instrument.aberrationCorrection,
data.time.j2000Seconds(),
probe
);
if (ref.second) {
r.surfaceVector = SpiceManager::ref().frameTransformationMatrix(
@@ -633,7 +657,11 @@ void RenderableFov::computeIntercepts(const UpdateData& data, const std::string&
};
}
else {
const glm::vec3 o = orthogonalProjection(tBound, data.time.j2000Seconds(), target);
const glm::vec3 o = orthogonalProjection(
tBound,
data.time.j2000Seconds(),
target
);
_orthogonalPlane.data[indexForBounds(i) + m] = {
{ o.x, o.y, o.z },
@@ -698,8 +726,12 @@ void RenderableFov::computeIntercepts(const UpdateData& data, const std::string&
// OBS: i and j are in bounds-space, p1, p2 are in
// _orthogonalPlane-space
const size_t p1 = static_cast<size_t>(indexForBounds(i) + t1 * InterpolationSteps);
const size_t p2 = static_cast<size_t>(indexForBounds(i) + t2 * InterpolationSteps);
const size_t p1 = static_cast<size_t>(
indexForBounds(i) + t1 * InterpolationSteps
);
const size_t p2 = static_cast<size_t>(
indexForBounds(i) + t2 * InterpolationSteps
);
// We can copy the non-intersecting parts
copyFieldOfViewValues(i, indexForBounds(i), p1);
@@ -717,7 +749,11 @@ void RenderableFov::computeIntercepts(const UpdateData& data, const std::string&
}
}
else {
copyFieldOfViewValues(i, indexForBounds(i), indexForBounds(i + 1));
copyFieldOfViewValues(
i,
indexForBounds(i),
indexForBounds(i + 1)
);
}
break;
}
@@ -741,15 +777,24 @@ void RenderableFov::computeIntercepts(const UpdateData& data, const std::string&
//if (intercepts[i] == false) { // If point is non-interceptive, project it.
// insertPoint(_fovPlane, glm::vec4(orthogonalProjection(current, data.time, target), 0.0), tmp);
// insertPoint(
// _fovPlane,
// glm::vec4(
// orthogonalProjection(current, data.time, target),
// 0.0
// ),
// tmp
// );
// _rebuild = true;
// if (intercepts[i + 1] == false) {
// // IFF incident point is also non-interceptive BUT something is within FOV
// // 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 = (_instrument.referenceFrame.find(bodyfixed) == std::string::npos);
// bool convert = (_instrument.referenceFrame.find(bodyfixed) ==
// std::string::npos);
// if (convert) {
// bodyfixed = SpiceManager::ref().frameFromBody(target);
// }
@@ -758,11 +803,23 @@ void RenderableFov::computeIntercepts(const UpdateData& data, const std::string&
// }
// SpiceManager::SurfaceInterceptResult res =
// SpiceManager::ref().surfaceIntercept(target, _instrument.spacecraft,
// _instrument.name, bodyfixed, _instrument.aberrationCorrection, data.time, half);
// SpiceManager::ref().surfaceIntercept(
// target,
// _instrument.spacecraft,
// _instrument.name,
// bodyfixed,
// _instrument.aberrationCorrection,
// data.time,
// half
// );
// if (convert) {
// res.surfaceVector = SpiceManager::ref().frameTransformationMatrix(bodyfixed, _instrument.referenceFrame, data.time) * res.surfaceVector;
// res.surfaceVector =
// SpiceManager::ref().frameTransformationMatrix(
// bodyfixed,
// _instrument.referenceFrame,
// data.time
// ) * res.surfaceVector;
// }
// bool intercepted = res.interceptFound;
@@ -772,43 +829,81 @@ void RenderableFov::computeIntercepts(const UpdateData& data, const std::string&
// glm::dvec3 root1 = bisection(half, current, data.time, target);
// glm::dvec3 root2 = bisection(half, next, data.time, target);
// insertPoint(_fovPlane, glm::vec4(orthogonalProjection(root1, data.time, target), 0.0), squareColor(diffTime));
// insertPoint(
// _fovPlane,
// glm::vec4(
// orthogonalProjection(
// root1,
// data.time,
// target
// ),
// 0.0
// ),
// squareColor(diffTime)
// );
// for (int j = 1; j < InterpolationSteps; ++j) {
// float t = (static_cast<float>(j) / InterpolationSteps);
// interpolated = interpolate(root1, root2, t);
// glm::dvec3 ivec = checkForIntercept(interpolated, data.time, target);
// insertPoint(_fovPlane, glm::vec4(ivec, 0.0), squareColor(diffTime));
// glm::dvec3 ivec = checkForIntercept(
// interpolated,
// data.time,
// target
// );
// insertPoint(
// _fovPlane,
// glm::vec4(ivec, 0.0),
// squareColor(diffTime)
// );
// }
// insertPoint(_fovPlane, glm::vec4(orthogonalProjection(root2, data.time, target), 0.0), squareColor(diffTime));
// insertPoint(
// _fovPlane,
// glm::vec4(
// orthogonalProjection(root2, data.time, target), 0.0
// ),
// squareColor(diffTime)
// );
// }
// }
//}
//if (interceptTag[i] == true && interceptTag[i + 1] == false) { // current point is interceptive, next is not
// // find outer most point for interpolation
//if (interceptTag[i] == true && interceptTag[i + 1] == false) {
// // current point is interceptive, next is not
// // find outer most point for interpolation
// mid = bisection(current, next, data.time, target);
// for (int j = 1; j <= InterpolationSteps; ++j) {
// float t = (static_cast<float>(j) / InterpolationSteps);
// interpolated = interpolate(current, mid, t);
// glm::dvec3 ivec = (j < InterpolationSteps) ? checkForIntercept(interpolated, data.time, target) : orthogonalProjection(interpolated, data.time, target);
// glm::dvec3 ivec =
// (j < InterpolationSteps) ?
// checkForIntercept(interpolated, data.time, target) :
// orthogonalProjection(interpolated, data.time, target);
// insertPoint(_fovPlane, glm::vec4(ivec, 0.0), squareColor(diffTime));
// _rebuild = true;
// }
//}
//if (interceptTag[i] == false && interceptTag[i + 1] == true) { // current point is non-interceptive, next is
//if (interceptTag[i] == false && interceptTag[i + 1] == true) {
// // current point is non-interceptive, next is
// mid = bisection(next, current, data.time, target);
// for (int j = 1; j <= InterpolationSteps; ++j) {
// float t = (static_cast<float>(j) / InterpolationSteps);
// interpolated = interpolate(mid, next, t);
// glm::dvec3 ivec = (j > 1) ? checkForIntercept(interpolated, data.time, target) : orthogonalProjection(interpolated, data.time, target);
// glm::dvec3 ivec =
// (j > 1) ?
// checkForIntercept(interpolated, data.time, target) :
// orthogonalProjection(interpolated, data.time, target);
// insertPoint(_fovPlane, glm::vec4(ivec, 0.0), squareColor(diffTime));
// _rebuild = true;
// }
//}
//if (interceptTag[i] == true && interceptTag[i + 1] == true) { // both points intercept
//if (interceptTag[i] == true && interceptTag[i + 1] == true) {
// // both points intercept
// for (int j = 0; j <= InterpolationSteps; ++j) {
// float t = (static_cast<float>(j) / InterpolationSteps);
// interpolated = interpolate(current, next, t);
// glm::dvec3 ivec = checkForIntercept(interpolated, data.time, target);
// glm::dvec3 ivec = checkForIntercept(
// interpolated,
// data.time,
// target
// );
// insertPoint(_fovPlane, glm::vec4(ivec, 0.0), squareColor(diffTime));
// _rebuild = true;
// }
@@ -821,7 +916,9 @@ void RenderableFov::computeIntercepts(const UpdateData& data, const std::string&
}
#if 0
void RenderableFov::computeIntercepts(const UpdateData& data, const std::string& target, bool inFOV) {
void RenderableFov::computeIntercepts(const UpdateData& data, const std::string& target,
bool inFOV)
{
double t2 = (openspace::ImageSequencer::ref().getNextCaptureTime());
double diff = (t2 - data.time);
float diffTime = 0.0;
@@ -849,11 +946,22 @@ void RenderableFov::computeIntercepts(const UpdateData& data, const std::string&
}
SpiceManager::SurfaceInterceptResult res =
SpiceManager::ref().surfaceIntercept(target, _instrument.spacecraft,
_instrument.name, bodyfixed, _instrument.aberrationCorrection, data.time, _instrument.bounds[r]);
SpiceManager::ref().surfaceIntercept(
target,
_instrument.spacecraft,
_instrument.name,
bodyfixed,
_instrument.aberrationCorrection,
data.time,
_instrument.bounds[r]
);
if (convert) {
res.surfaceVector = SpiceManager::ref().frameTransformationMatrix(bodyfixed, _instrument.referenceFrame, data.time) * res.surfaceVector;
res.surfaceVector = SpiceManager::ref().frameTransformationMatrix(
bodyfixed,
_instrument.referenceFrame,
data.time
) * res.surfaceVector;
}
interceptTag[r] = res.interceptFound;
@@ -863,13 +971,17 @@ void RenderableFov::computeIntercepts(const UpdateData& data, const std::string&
if (!interceptTag[r]) {
b = orthogonalProjection(_instrument.bounds[r], data.time, target);
}
glm::vec4 fovOrigin = glm::vec4(0); //This will have to be fixed once spacecraft is 1:1!
//This will have to be fixed once spacecraft is 1:1!
glm::vec4 fovOrigin = glm::vec4(0);
if (interceptTag[r]) {
// INTERCEPTIONS
insertPoint(_fovBounds, fovOrigin, _colors.intersectionStart);
insertPoint(_fovBounds, glm::vec4(res.surfaceVector, 0.0), endColor(diffTime));
insertPoint(
_fovBounds,
glm::vec4(res.surfaceVector, 0.0),
endColor(diffTime)
);
}
else if (inFOV) {
// OBJECT IN FOV, NO INTERCEPT FOR THIS FOV-RAY
@@ -908,15 +1020,21 @@ void RenderableFov::computeIntercepts(const UpdateData& data, const std::string&
next = bounds[k];
if (interceptTag[i] == false) { // If point is non-interceptive, project it.
insertPoint(_fovPlane, glm::vec4(orthogonalProjection(current, data.time, target), 0.0), tmp);
insertPoint(
_fovPlane,
glm::vec4(orthogonalProjection(current, data.time, target), 0.0),
tmp
);
_rebuild = true;
if (interceptTag[i + 1] == false && inFOV) {
// IFF incident point is also non-interceptive BUT something is within FOV
// 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 = (_instrument.referenceFrame.find(bodyfixed) == std::string::npos);
bool convert = (_instrument.referenceFrame.find(bodyfixed) ==
std::string::npos);
if (convert) {
bodyfixed = SpiceManager::ref().frameFromBody(target);
}
@@ -925,11 +1043,22 @@ void RenderableFov::computeIntercepts(const UpdateData& data, const std::string&
}
SpiceManager::SurfaceInterceptResult res =
SpiceManager::ref().surfaceIntercept(target, _instrument.spacecraft,
_instrument.name, bodyfixed, _instrument.aberrationCorrection, data.time, half);
SpiceManager::ref().surfaceIntercept(
target,
_instrument.spacecraft,
_instrument.name,
bodyfixed,
_instrument.aberrationCorrection,
data.time,
half
);
if (convert) {
res.surfaceVector = SpiceManager::ref().frameTransformationMatrix(bodyfixed, _instrument.referenceFrame, data.time) * res.surfaceVector;
res.surfaceVector = SpiceManager::ref().frameTransformationMatrix(
bodyfixed,
_instrument.referenceFrame,
data.time
) * res.surfaceVector;
}
bool intercepted = res.interceptFound;
@@ -939,39 +1068,70 @@ void RenderableFov::computeIntercepts(const UpdateData& data, const std::string&
glm::dvec3 root1 = bisection(half, current, data.time, target);
glm::dvec3 root2 = bisection(half, next, data.time, target);
insertPoint(_fovPlane, glm::vec4(orthogonalProjection(root1, data.time, target), 0.0), squareColor(diffTime));
insertPoint(
_fovPlane,
glm::vec4(
orthogonalProjection(root1, data.time, target),
0.0
),
squareColor(diffTime)
);
for (int j = 1; j < InterpolationSteps; ++j) {
float t = (static_cast<float>(j) / InterpolationSteps);
interpolated = interpolate(root1, root2, t);
glm::dvec3 ivec = checkForIntercept(interpolated, data.time, target);
insertPoint(_fovPlane, glm::vec4(ivec,0.0) , squareColor(diffTime));
glm::dvec3 ivec = checkForIntercept(
interpolated,
data.time,
target
);
insertPoint(
_fovPlane,
glm::vec4(ivec,0.0),
squareColor(diffTime)
);
}
insertPoint(_fovPlane, glm::vec4(orthogonalProjection(root2, data.time, target), 0.0), squareColor(diffTime));
insertPoint(
_fovPlane,
glm::vec4(
orthogonalProjection(root2, data.time, target),
0.0
),
squareColor(diffTime)
);
}
}
}
if (interceptTag[i] == true && interceptTag[i + 1] == false) { // current point is interceptive, next is not
// find outer most point for interpolation
if (interceptTag[i] == true && interceptTag[i + 1] == false) {
// current point is interceptive, next is not
// find outer most point for interpolation
mid = bisection(current, next, data.time, target);
for (int j = 1; j <= InterpolationSteps; ++j) {
float t = (static_cast<float>(j) / InterpolationSteps);
interpolated = interpolate(current, mid, t);
glm::dvec3 ivec = (j < InterpolationSteps) ? checkForIntercept(interpolated, data.time, target) : orthogonalProjection(interpolated, data.time, target);
glm::dvec3 ivec =
(j < InterpolationSteps) ?
checkForIntercept(interpolated, data.time, target) :
orthogonalProjection(interpolated, data.time, target);
insertPoint(_fovPlane, glm::vec4(ivec, 0.0), squareColor(diffTime));
_rebuild = true;
}
}
if (interceptTag[i] == false && interceptTag[i + 1] == true) { // current point is non-interceptive, next is
if (interceptTag[i] == false && interceptTag[i + 1] == true) {
// current point is non-interceptive, next is
mid = bisection(next, current, data.time, target);
for (int j = 1; j <= InterpolationSteps; ++j) {
float t = (static_cast<float>(j) / InterpolationSteps);
interpolated = interpolate(mid, next, t);
glm::dvec3 ivec = (j > 1) ? checkForIntercept(interpolated, data.time, target) : orthogonalProjection(interpolated, data.time, target);
glm::dvec3 ivec =
(j > 1) ?
checkForIntercept(interpolated, data.time, target) :
orthogonalProjection(interpolated, data.time, target);
insertPoint(_fovPlane, glm::vec4(ivec, 0.0), squareColor(diffTime));
_rebuild = true;
}
}
if (interceptTag[i] == true && interceptTag[i + 1] == true) { // both points intercept
if (interceptTag[i] == true && interceptTag[i + 1] == true) {
// both points intercept
for (int j = 0; j <= InterpolationSteps; ++j) {
float t = (static_cast<float>(j) / InterpolationSteps);
interpolated = interpolate(current, next, t);
@@ -989,7 +1149,11 @@ void RenderableFov::computeIntercepts(const UpdateData& data, const std::string&
//
glm::mat4 spacecraftRotation = glm::mat4(
SpiceManager::ref().positionTransformMatrix(_instrument.name, _instrument.referenceFrame, data.time)
SpiceManager::ref().positionTransformMatrix(
_instrument.name,
_instrument.referenceFrame,
data.time
)
);
glm::vec3 aim = (spacecraftRotation * glm::vec4(_instrument.boresight, 1));
@@ -1003,7 +1167,11 @@ void RenderableFov::computeIntercepts(const UpdateData& data, const std::string&
data.time,
lt
);
psc p = PowerScaledCoordinate::CreatePowerScaledCoordinate(position.x, position.y, position.z);
psc p = PowerScaledCoordinate::CreatePowerScaledCoordinate(
position.x,
position.y,
position.z
);
pss length = p.length();
if (length[0] < DBL_EPSILON) {
_drawFOV = false;
@@ -1022,7 +1190,7 @@ void RenderableFov::render(const RenderData& data, RendererTasks&) {
// Model transform and view transform needs to be in double precision
glm::dmat4 modelTransform =
glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * // Translation
glm::translate(glm::dmat4(1.0), data.modelTransform.translation) *
glm::dmat4(data.modelTransform.rotation) *
glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale));
@@ -1031,12 +1199,18 @@ void RenderableFov::render(const RenderData& data, RendererTasks&) {
glm::mat4(data.camera.combinedViewMatrix() *
modelTransform);
_programObject->setUniform("modelViewProjectionTransform", modelViewProjectionTransform);
_programObject->setUniform(
"modelViewProjectionTransform",
modelViewProjectionTransform
);
_programObject->setUniform("defaultColorStart", _colors.defaultStart);
_programObject->setUniform("defaultColorEnd", _colors.defaultEnd);
_programObject->setUniform("activeColor", _colors.active);
_programObject->setUniform("targetInFieldOfViewColor", _colors.targetInFieldOfView);
_programObject->setUniform(
"targetInFieldOfViewColor",
_colors.targetInFieldOfView
);
_programObject->setUniform("intersectionStartColor", _colors.intersectionStart);
_programObject->setUniform("intersectionEndColor", _colors.intersectionEnd);
_programObject->setUniform("squareColor", _colors.square);
@@ -1118,7 +1292,9 @@ std::pair<std::string, bool> RenderableFov::determineTarget(double time) {
_instrument.potentialTargets.begin(),
_instrument.potentialTargets.end(),
distances.begin(),
[&o = _instrument.spacecraft, &f = _instrument.referenceFrame, &t = time](const std::string& pt) {
[&o = _instrument.spacecraft, &f = _instrument.referenceFrame, &t = time]
(const std::string& pt)
{
double lt;
glm::dvec3 p = SpiceManager::ref().targetPosition(pt, o, f, {}, t, lt);
return glm::length(p);
@@ -1157,27 +1333,54 @@ void RenderableFov::updateGPU() {
//glBindBuffer(GL_ARRAY_BUFFER, _bounds.vbo);
//glBufferSubData(GL_ARRAY_BUFFER, 0, _bounds.size * sizeof(GLfloat), _fovBounds.data());
//glBufferSubData(
// GL_ARRAY_BUFFER,
// 0,
// _bounds.size * sizeof(GLfloat),
// _fovBounds.data()
//);
////LINFOC(_instrument, _boundsV.size);
//if (!_rebuild) {
// // no new points
// glBindBuffer(GL_ARRAY_BUFFER, _orthogonalPlane.vbo);
// glBufferSubData(GL_ARRAY_BUFFER, 0, _orthogonalPlane.size * sizeof(GLfloat), _fovPlane.data());
// glBufferSubData(
// GL_ARRAY_BUFFER,
// 0,
// _orthogonalPlane.size * sizeof(GLfloat),
// _fovPlane.data()
// );
//}
//else {
// // new points - memory change
// glBindVertexArray(_orthogonalPlane.vao);
// glBindBuffer(GL_ARRAY_BUFFER, _orthogonalPlane.vbo);
// glBufferData(GL_ARRAY_BUFFER, _orthogonalPlane.size * sizeof(GLfloat), NULL, GL_STATIC_DRAW); // orphaning the buffer, sending NULL data.
// glBufferSubData(GL_ARRAY_BUFFER, 0, _orthogonalPlane.size * sizeof(GLfloat), _fovPlane.data());
// glBufferData(
// GL_ARRAY_BUFFER,
// _orthogonalPlane.size * sizeof(GLfloat),
// NULL,
// GL_STATIC_DRAW
// ); // orphaning the buffer, sending NULL data.
// glBufferSubData(
// GL_ARRAY_BUFFER,
// 0,
// _orthogonalPlane.size * sizeof(GLfloat),
// _fovPlane.data()
// );
// GLsizei st = sizeof(GLfloat) * Stride;
// glEnableVertexAttribArray(0);
// glEnableVertexAttribArray(1);
// glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, st, (void*)0);
// glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, st, (void*)(4 * sizeof(GLfloat)));
// glVertexAttribPointer(
// 1,
// 4,
// GL_FLOAT,
// GL_FALSE,
// st,
// (void*)(4 * sizeof(GLfloat))
// );
//}
//glBindVertexArray(0);

View File

@@ -250,14 +250,21 @@ void RenderableModelProjection::render(const RenderData& data, RendererTasks&) {
glm::dmat4(data.modelTransform.rotation) * // Rotation
glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale)); // Scale
glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform;
glm::vec3 directionToSun = glm::normalize(_sunPosition.vec3() - glm::vec3(bodyPosition));
glm::vec3 directionToSunViewSpace = glm::mat3(data.camera.combinedViewMatrix()) * directionToSun;
glm::vec3 directionToSun = glm::normalize(
_sunPosition.vec3() - glm::vec3(bodyPosition)
);
glm::vec3 directionToSunViewSpace = glm::mat3(
data.camera.combinedViewMatrix()
) * directionToSun;
_programObject->setUniform("_performShading", _performShading);
_programObject->setUniform("directionToSunViewSpace", directionToSunViewSpace);
_programObject->setUniform("modelViewTransform", glm::mat4(modelViewTransform));
_programObject->setUniform("projectionTransform", data.camera.projectionMatrix());
_programObject->setUniform("_projectionFading", _projectionComponent.projectionFading());
_programObject->setUniform(
"_projectionFading",
_projectionComponent.projectionFading()
);
_geometry->setUniforms(*_programObject);

View File

@@ -155,14 +155,20 @@ void RenderablePlaneProjection::render(const RenderData& data, RendererTasks&) {
void RenderablePlaneProjection::update(const UpdateData& data) {
double time = data.time.j2000Seconds();
const Image img = openspace::ImageSequencer::ref().getLatestImageForInstrument(_instrument);
const Image img = openspace::ImageSequencer::ref().getLatestImageForInstrument(
_instrument
);
if (img.path == "")
return;
else
_hasImage = true;
_stateMatrix = SpiceManager::ref().positionTransformMatrix(_target.frame, GalacticFrame, time);
_stateMatrix = SpiceManager::ref().positionTransformMatrix(
_target.frame,
GalacticFrame,
time
);
double timePast = std::abs(img.timeRange.start - _previousTime);
@@ -186,7 +192,10 @@ void RenderablePlaneProjection::update(const UpdateData& data) {
void RenderablePlaneProjection::loadTexture() {
if (_texturePath != "") {
std::unique_ptr<ghoul::opengl::Texture> texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_texturePath));
using TR = ghoul::io::TextureReader;
std::unique_ptr<ghoul::opengl::Texture> texture = TR::ref().loadTexture(
absPath(_texturePath)
);
if (texture) {
if (texture->format() == ghoul::opengl::Texture::Format::Red)
texture->setSwizzleMask({ GL_RED, GL_RED, GL_RED, GL_ONE });
@@ -198,7 +207,9 @@ void RenderablePlaneProjection::loadTexture() {
delete _textureFile;
_textureFile = new ghoul::filesystem::File(_texturePath);
_textureFile->setCallback([&](const ghoul::filesystem::File&) { _textureIsDirty = true; });
_textureFile->setCallback(
[&](const ghoul::filesystem::File&) { _textureIsDirty = true; }
);
}
}
}
@@ -221,11 +232,11 @@ void RenderablePlaneProjection::updatePlane(const Image& img, double currentTime
setTarget(target);
try {
SpiceManager::FieldOfViewResult res = SpiceManager::ref().fieldOfView(_instrument);
SpiceManager::FieldOfViewResult r = SpiceManager::ref().fieldOfView(_instrument);
frame = std::move(res.frameName);
bounds = std::move(res.bounds);
boresight = std::move(res.boresightVector);
frame = std::move(r.frameName);
bounds = std::move(r.bounds);
boresight = std::move(r.boresightVector);
}
catch (const SpiceManager::SpiceException& e) {
LERROR(e.what());
@@ -238,56 +249,66 @@ void RenderablePlaneProjection::updatePlane(const Image& img, double currentTime
_target.body,
_spacecraft,
GalacticFrame,
{ SpiceManager::AberrationCorrection::Type::ConvergedNewtonianStellar, SpiceManager::AberrationCorrection::Direction::Reception },
{
SpiceManager::AberrationCorrection::Type::ConvergedNewtonianStellar,
SpiceManager::AberrationCorrection::Direction::Reception
},
currentTime,
lt
);
// The apparent position, CN+S, makes image align best with target
for (size_t j = 0; j < bounds.size(); ++j) {
bounds[j] = SpiceManager::ref().frameTransformationMatrix(frame, GalacticFrame, currentTime) * bounds[j];
bounds[j] = SpiceManager::ref().frameTransformationMatrix(
frame,
GalacticFrame,
currentTime
) * bounds[j];
glm::dvec3 cornerPosition = glm::proj(vecToTarget, bounds[j]);
if (!_moving) {
cornerPosition -= vecToTarget;
}
cornerPosition = SpiceManager::ref().frameTransformationMatrix(GalacticFrame, _target.frame, currentTime) * cornerPosition;
cornerPosition = SpiceManager::ref().frameTransformationMatrix(
GalacticFrame,
_target.frame,
currentTime
) * cornerPosition;
projection[j] = PowerScaledCoordinate::CreatePowerScaledCoordinate(cornerPosition[0], cornerPosition[1], cornerPosition[2]);
projection[j] = PowerScaledCoordinate::CreatePowerScaledCoordinate(
cornerPosition[0],
cornerPosition[1],
cornerPosition[2]
);
projection[j][3] += 3;
}
if (!_moving) {
SceneGraphNode* thisNode = OsEng.renderEngine().scene()->sceneGraphNode(_name);
SceneGraphNode* newParent = OsEng.renderEngine().scene()->sceneGraphNode(_target.node);
SceneGraphNode* newParent = OsEng.renderEngine().scene()->sceneGraphNode(
_target.node
);
if (thisNode && newParent) {
thisNode->setParent(*newParent);
}
}
const GLfloat vertex_data[] = { // square of two triangles drawn within fov in target coordinates
const GLfloat vertex_data[] = {
// square of two triangles drawn within fov in target coordinates
// x y z w s t
projection[1][0], projection[1][1], projection[1][2], projection[1][3], 0, 0, // Lower left 1
projection[3][0], projection[3][1], projection[3][2], projection[3][3], 1, 1, // Upper right 2
projection[2][0], projection[2][1], projection[2][2], projection[2][3], 0, 1, // Upper left 3
projection[1][0], projection[1][1], projection[1][2], projection[1][3], 0, 0, // Lower left 4 = 1
projection[0][0], projection[0][1], projection[0][2], projection[0][3], 1, 0, // Lower right 5
projection[3][0], projection[3][1], projection[3][2], projection[3][3], 1, 1, // Upper left 6 = 2
//projection[1][0], projection[1][1], projection[1][2], projection[1][3], 0, 1, // Lower left 1
//projection[3][0], projection[3][1], projection[3][2], projection[3][3], 1, 0, // Upper right 2
//projection[2][0], projection[2][1], projection[2][2], projection[2][3], 0, 0, // Upper left 3
//projection[1][0], projection[1][1], projection[1][2], projection[1][3], 0, 1, // Lower left 4 = 1
//projection[0][0], projection[0][1], projection[0][2], projection[0][3], 1, 1, // Lower right 5
//projection[3][0], projection[3][1], projection[3][2], projection[3][3], 1, 0, // Upper left 6 = 2
// Lower left 1
projection[1][0], projection[1][1], projection[1][2], projection[1][3], 0, 0,
// Upper right 2
projection[3][0], projection[3][1], projection[3][2], projection[3][3], 1, 1,
// Upper left 3
projection[2][0], projection[2][1], projection[2][2], projection[2][3], 0, 1,
// Lower left 4 = 1
projection[1][0], projection[1][1], projection[1][2], projection[1][3], 0, 0,
// Lower right 5
projection[0][0], projection[0][1], projection[0][2], projection[0][3], 1, 0,
// Upper left 6 = 2
projection[3][0], projection[3][1], projection[3][2], projection[3][3], 1, 1,
};
//projection[1][0], projection[1][1], projection[1][2], projection[1][3], 0, 1, // Lower left 1
// projection[3][0], projection[3][1], projection[3][2], projection[3][3], 1, 0, // Upper right 2
// projection[2][0], projection[2][1], projection[2][2], projection[2][3], 0, 0, // Upper left 3
// projection[1][0], projection[1][1], projection[1][2], projection[1][3], 0, 1, // Lower left 4 = 1
// projection[0][0], projection[0][1], projection[0][2], projection[0][3], 1, 1, // Lower right 5
// projection[3][0], projection[3][1], projection[3][2], projection[3][3], 1, 0, // Upper left 6 = 2
glBindVertexArray(_quad); // bind array
glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer); // bind buffer
@@ -295,7 +316,14 @@ void RenderablePlaneProjection::updatePlane(const Image& img, double currentTime
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, nullptr);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast<void*>(sizeof(GLfloat) * 4));
glVertexAttribPointer(
1,
2,
GL_FLOAT,
GL_FALSE,
sizeof(GLfloat) * 6,
reinterpret_cast<void*>(sizeof(GLfloat) * 4)
);
if (!_moving && img.path != "") {
_texturePath = img.path;
@@ -304,10 +332,9 @@ void RenderablePlaneProjection::updatePlane(const Image& img, double currentTime
}
void RenderablePlaneProjection::setTarget(std::string body) {
if (body == "")
if (body == "") {
return;
std::vector<SceneGraphNode*> nodes = OsEng.renderEngine().scene()->allSceneGraphNodes();
}
_target.body = body;
_target.frame = openspace::SpiceManager::ref().frameFromBody(body);

View File

@@ -147,8 +147,8 @@ documentation::Documentation RenderablePlanetProjection::Documentation() {
};
}
RenderablePlanetProjection::RenderablePlanetProjection(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
RenderablePlanetProjection::RenderablePlanetProjection(const ghoul::Dictionary& dict)
: Renderable(dict)
, _colorTexturePath(ColorTextureInfo)
, _heightMapTexturePath(HeightTextureInfo)
, _programObject(nullptr)
@@ -161,44 +161,44 @@ RenderablePlanetProjection::RenderablePlanetProjection(const ghoul::Dictionary&
{
documentation::testSpecificationAndThrow(
Documentation(),
dictionary,
dict,
"RenderablePlanetProjection"
);
std::string name;
bool success = dictionary.getValue(SceneGraphNode::KeyName, name);
bool success = dict.getValue(SceneGraphNode::KeyName, name);
ghoul_assert(success, "");
ghoul::Dictionary geometryDictionary;
success = dictionary.getValue(KeyGeometry, geometryDictionary);
success = dict.getValue(KeyGeometry, geometryDictionary);
if (success) {
geometryDictionary.setValue(SceneGraphNode::KeyName, name);
using planetgeometry::PlanetGeometry;
_geometry = PlanetGeometry::createFromDictionary(geometryDictionary);
}
_projectionComponent.initialize(dictionary.value<ghoul::Dictionary>(KeyProjection));
_projectionComponent.initialize(dict.value<ghoul::Dictionary>(KeyProjection));
// TODO: textures need to be replaced by a good system similar to the geometry as soon
// as the requirements are fixed (ab)
std::string texturePath = "";
success = dictionary.getValue(ColorTextureInfo.identifier, texturePath);
success = dict.getValue(ColorTextureInfo.identifier, texturePath);
if (success) {
_colorTexturePath = absPath(texturePath);
}
std::string heightMapPath = "";
success = dictionary.getValue(HeightTextureInfo.identifier, heightMapPath);
success = dict.getValue(HeightTextureInfo.identifier, heightMapPath);
if (success) {
_heightMapTexturePath = absPath(heightMapPath);
}
if (dictionary.hasKeyAndValue<bool>(MeridianShiftInfo.identifier)) {
_meridianShift = dictionary.value<bool>(MeridianShiftInfo.identifier);
if (dict.hasKeyAndValue<bool>(MeridianShiftInfo.identifier)) {
_meridianShift = dict.value<bool>(MeridianShiftInfo.identifier);
}
float radius = std::pow(10.f, 9.f);
dictionary.getValue(KeyRadius, radius);
dict.getValue(KeyRadius, radius);
setBoundingSphere(radius);
addPropertySubOwner(_geometry.get());
@@ -210,9 +210,9 @@ RenderablePlanetProjection::RenderablePlanetProjection(const ghoul::Dictionary&
addProperty(_heightMapTexturePath);
_heightMapTexturePath.onChange([&]() { loadTextures(); });
if (dictionary.hasKey(HeightExaggerationInfo.identifier)) {
if (dict.hasKey(HeightExaggerationInfo.identifier)) {
_heightExaggeration = static_cast<float>(
dictionary.value<double>(HeightExaggerationInfo.identifier)
dict.value<double>(HeightExaggerationInfo.identifier)
);
}
@@ -355,7 +355,9 @@ void RenderablePlanetProjection::attitudeParameters(double time) {
glm::dvec3 bs;
try {
SpiceManager::FieldOfViewResult res = SpiceManager::ref().fieldOfView(_projectionComponent.instrumentId());
SpiceManager::FieldOfViewResult res = SpiceManager::ref().fieldOfView(
_projectionComponent.instrumentId()
);
bs = std::move(res.boresightVector);
}
catch (const SpiceManager::SpiceException& e) {
@@ -417,8 +419,14 @@ void RenderablePlanetProjection::render(const RenderData& data, RendererTasks&)
_imageTimes.clear();
double lt;
glm::dvec3 p =
SpiceManager::ref().targetPosition("SUN", _projectionComponent.projecteeId(), "GALACTIC", {}, _time, lt);
glm::dvec3 p = SpiceManager::ref().targetPosition(
"SUN",
_projectionComponent.projecteeId(),
"GALACTIC",
{},
_time,
lt
);
psc sun_pos = PowerScaledCoordinate::CreatePowerScaledCoordinate(p.x, p.y, p.z);
// Main renderpass
@@ -452,11 +460,10 @@ void RenderablePlanetProjection::render(const RenderData& data, RendererTasks&)
_programObject->setUniform("_hasHeightMap", _heightMapTexture != nullptr);
_programObject->setUniform("_heightExaggeration", _heightExaggeration);
_programObject->setUniform("_meridianShift", _meridianShift);
_programObject->setUniform("_projectionFading", _projectionComponent.projectionFading());
//_programObject->setUniform("debug_projectionTextureRotation", glm::radians(_debugProjectionTextureRotation.value()));
//setPscUniforms(*_programObject.get(), data.camera, data.position);
_programObject->setUniform(
"_projectionFading",
_projectionComponent.projectionFading()
);
ghoul::opengl::TextureUnit unit[3];
unit[0].activate();

View File

@@ -365,7 +365,8 @@ void RenderableShadowCylinder::createCylinder(double time) {
res.terminatorPoints.end(),
std::back_inserter(terminatorPoints),
[](const glm::dvec3& p) {
PowerScaledCoordinate coord = PowerScaledCoordinate::CreatePowerScaledCoordinate(p.x, p.y, p.z);
PowerScaledCoordinate coord =
PowerScaledCoordinate::CreatePowerScaledCoordinate(p.x, p.y, p.z);
coord[3] += 3;
return coord;
}
@@ -389,7 +390,11 @@ void RenderableShadowCylinder::createCylinder(double time) {
vecLightSource *= _shadowLength;
_vertices.clear();
psc endpoint = psc::CreatePowerScaledCoordinate(vecLightSource.x, vecLightSource.y, vecLightSource.z);
psc endpoint = psc::CreatePowerScaledCoordinate(
vecLightSource.x,
vecLightSource.y,
vecLightSource.z
);
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());
@@ -400,8 +405,18 @@ void RenderableShadowCylinder::createCylinder(double time) {
glBindVertexArray(_vao);
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
glBufferData(GL_ARRAY_BUFFER, _vertices.size() * sizeof(CylinderVBOLayout), nullptr, GL_DYNAMIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, _vertices.size() * sizeof(CylinderVBOLayout), &_vertices[0]);
glBufferData(
GL_ARRAY_BUFFER,
_vertices.size() * sizeof(CylinderVBOLayout),
nullptr,
GL_DYNAMIC_DRAW
);
glBufferSubData(
GL_ARRAY_BUFFER,
0,
_vertices.size() * sizeof(CylinderVBOLayout),
&_vertices[0]
);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, nullptr);

View File

@@ -45,7 +45,9 @@ HongKangParser::HongKangParser(std::string name, std::string fileName,
std::string spacecraft,
ghoul::Dictionary translationDictionary,
std::vector<std::string> potentialTargets)
: _defaultCaptureImage(absPath("${OPENSPACE_DATA}/scene/common/textures/placeholder.png"))
: _defaultCaptureImage(
absPath("${OPENSPACE_DATA}/scene/common/textures/placeholder.png")
)
, _name(std::move(name))
, _fileName(std::move(fileName))
, _spacecraft(std::move(spacecraft))
@@ -68,7 +70,10 @@ HongKangParser::HongKangParser(std::string name, std::string fileName,
ghoul::Dictionary decoderDictionary;
translationDictionary.getValue(currentKey, decoderDictionary);
auto decoder = Decoder::createFromDictionary(decoderDictionary, decoders[i]);
auto 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]] = std::move(decoder);
@@ -88,7 +93,8 @@ void HongKangParser::findPlaybookSpecifiedTarget(std::string line, std::string&
);
std::vector<std::string> ptarg = _potentialTargets;
for (const auto& p : ptarg) {
// loop over all targets and determine from 4th col which target this instrument points to
// loop over all targets and determine from 4th col which target this instrument
// points to
if (line.find(p) != std::string::npos) {
target = p;
break;
@@ -186,24 +192,38 @@ bool HongKangParser::create() {
image.target = cameraTarget;
image.isPlaceholder = true;
image.projected = false;
//createImage(image, time, time + shutter, cameraSpiceID, cameraTarget, _defaultCaptureImage);
//createImage(
// image,
// time,
// time + shutter,
// cameraSpiceID,
// cameraTarget,
// _defaultCaptureImage
//);
//IFF spaccraft has decided to switch target, store in target map (used for: 'next observation focus')
//IFF spaccraft has decided to switch target, store in target
//map (used for: 'next observation focus')
if (previousTarget != image.target) {
previousTarget = image.target;
std::pair<double, std::string> v_target = std::make_pair(time, image.target);
std::pair<double, std::string> v_target = std::make_pair(
time,
image.target
);
_targetTimes.push_back(v_target);
}
//store actual image in map. All targets get _only_ their corresp. subset.
// store actual image in map. All targets get _only_ their
// corresp. subset.
_subsetMap[image.target]._subset.push_back(image);
//compute and store the range for each subset
// compute and store the range for each subset
_subsetMap[image.target]._range.include(time);
}
if (it->second->getDecoderType() == "SCANNER") { // SCANNER START
scan_start = time;
InstrumentDecoder* scanner = static_cast<InstrumentDecoder*>(it->second.get());
InstrumentDecoder* scanner = static_cast<InstrumentDecoder*>(
it->second.get()
);
std::string endNominal = scanner->getStopCommand();
// store current position in file
@@ -222,8 +242,13 @@ bool HongKangParser::create() {
scannerSpiceID = it->second->getTranslation();
scanRange = { scan_start, scan_stop };
ghoul_assert(scanRange.isDefined(), "Invalid time range!");
_instrumentTimes.push_back(std::make_pair(it->first, scanRange));
ghoul_assert(
scanRange.isDefined(),
"Invalid time range!"
);
_instrumentTimes.push_back(
std::make_pair(it->first, scanRange)
);
//store individual image
Image image;
@@ -242,13 +267,18 @@ bool HongKangParser::create() {
file.seekg(len, std::ios_base::beg);
}
}
else { // we have reached the end of a scan or consecutive capture sequence!
else {
// we have reached the end of a scan or consecutive capture
// sequence!
if (capture_start != -1) {
//end of capture sequence for camera, store end time of this sequence
// end of capture sequence for camera, store end time of this
// sequence
capture_stop = time;
cameraRange = { capture_start, capture_stop };
ghoul_assert(cameraRange.isDefined(), "Invalid time range!");
_instrumentTimes.push_back(std::make_pair(previousCamera, cameraRange));
_instrumentTimes.push_back(
std::make_pair(previousCamera, cameraRange)
);
capture_start = -1;
}

View File

@@ -70,9 +70,16 @@ InstrumentTimesParser::InstrumentTimesParser(const std::string& name,
ghoul::Dictionary instruments = inputDict.value<ghoul::Dictionary>(KeyInstruments);
for (const auto& instrumentKey : instruments.keys()) {
ghoul::Dictionary instrument = instruments.value<ghoul::Dictionary>(instrumentKey);
ghoul::Dictionary files = instrument.value<ghoul::Dictionary>(KeyInstrumentFiles);
_fileTranslation[instrumentKey] = Decoder::createFromDictionary(instrument, KeyInstrument);
ghoul::Dictionary instrument = instruments.value<ghoul::Dictionary>(
instrumentKey
);
ghoul::Dictionary files = instrument.value<ghoul::Dictionary>(
KeyInstrumentFiles
);
_fileTranslation[instrumentKey] = Decoder::createFromDictionary(
instrument,
KeyInstrument
);
for (size_t i = 0; i < files.size(); i++) {
std::string filename = files.value<std::string>(std::to_string(i + 1));
_instrumentFiles[instrumentKey].push_back(filename);
@@ -97,7 +104,10 @@ bool InstrumentTimesParser::create() {
for (auto it = _instrumentFiles.begin(); it != _instrumentFiles.end(); it++) {
std::string instrumentID = it->first;
for (std::string filename: it->second) {
std::string filepath = FileSys.pathByAppendingComponent(sequenceDir.path(), filename);
std::string filepath = FileSys.pathByAppendingComponent(
sequenceDir.path(),
filename
);
if (!FileSys.fileExists(filepath)) {
LERROR("Unable to read file " << filepath << ". Skipping file.");
@@ -113,8 +123,10 @@ bool InstrumentTimesParser::create() {
while (std::getline(inFile, line)) {
if (std::regex_match(line, matches, _pattern)) {
if (matches.size() != 3) {
LERROR("Bad event data formatting. Must \
have regex 3 matches (source string, start time, stop time).");
LERROR(
"Bad event data formatting. Must \
have regex 3 matches (source string, start time, stop time)."
);
successfulRead = false;
break;
}
@@ -123,8 +135,10 @@ bool InstrumentTimesParser::create() {
try { // parse date strings
std::string start = matches[1].str();
std::string stop = matches[2].str();
captureTimeRange.start = SpiceManager::ref().ephemerisTimeFromDate(start);
captureTimeRange.end = SpiceManager::ref().ephemerisTimeFromDate(stop);
captureTimeRange.start =
SpiceManager::ref().ephemerisTimeFromDate(start);
captureTimeRange.end =
SpiceManager::ref().ephemerisTimeFromDate(stop);
}
catch (const SpiceManager::SpiceException& e){
LERROR(e.what());

View File

@@ -79,7 +79,10 @@ LabelParser::LabelParser(std::string name, std::string fileName,
ghoul::Dictionary decoderDictionary =
translationDictionary.value<ghoul::Dictionary>(currentKey);
auto decoder = Decoder::createFromDictionary(decoderDictionary, decoders[i]);
auto 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]] = std::move(decoder);
@@ -124,7 +127,8 @@ std::string LabelParser::decode(std::string line){
// "\nPlease check label files");
// return "";
//}
return _fileTranslation[toTranslate]->getTranslation()[0]; //lbls always 1:1 -> single value return
// //lbls always 1:1 -> single value return
return _fileTranslation[toTranslate]->getTranslation()[0];
}
}
@@ -170,7 +174,9 @@ bool LabelParser::create() {
std::ifstream file(currentFile.path());
if (!file.good()){
LERROR("Failed to open label file '" << currentFile.path() << "'");
LERROR(
"Failed to open label file '" << currentFile.path() << "'"
);
return false;
}
@@ -186,9 +192,17 @@ bool LabelParser::create() {
std::getline(file, line);
line.erase(std::remove(line.begin(), line.end(), '"'), line.end());
line.erase(std::remove(line.begin(), line.end(), ' '), line.end());
line.erase(std::remove(line.begin(), line.end(), '\r'), line.end());
line.erase(
std::remove(line.begin(), line.end(), '"'),
line.end()
);
line.erase(
std::remove(line.begin(), line.end(), ' '),
line.end()
);
line.erase(
std::remove(line.begin(), line.end(), '\r'), line.end()
);
std::string read = line.substr(0, line.find_first_of("="));
@@ -220,14 +234,26 @@ bool LabelParser::create() {
if (read == "START_TIME"){
std::string start = line.substr(line.find("=") + 1);
start.erase(std::remove(start.begin(), start.end(), ' '), start.end());
start.erase(
std::remove(start.begin(), start.end(), ' '),
start.end()
);
startTime = SpiceManager::ref().ephemerisTimeFromDate(start);
count++;
getline(file, line);
line.erase(std::remove(line.begin(), line.end(), '"'), line.end());
line.erase(std::remove(line.begin(), line.end(), ' '), line.end());
line.erase(std::remove(line.begin(), line.end(), '\r'), line.end());
line.erase(
std::remove(line.begin(), line.end(), '"'),
line.end()
);
line.erase(
std::remove(line.begin(), line.end(), ' '),
line.end()
);
line.erase(
std::remove(line.begin(), line.end(), '\r'),
line.end()
);
read = line.substr(0, line.find_first_of("="));
if (read == "STOP_TIME"){
@@ -244,8 +270,14 @@ bool LabelParser::create() {
count++;
}
else{
LERROR("Label file " + currentFile.path() + " deviates from generic standard!");
LINFO("Please make sure input data adheres to format https://pds.jpl.nasa.gov/documents/qs/labels.html");
LERROR(
"Label file " + currentFile.path() +
" deviates from generic standard!"
);
LINFO(
"Please make sure input data adheres to format \
https://pds.jpl.nasa.gov/documents/qs/labels.html"
);
}
}
if (count == static_cast<int>(_specsOfInterest.size())) {
@@ -262,13 +294,23 @@ bool LabelParser::create() {
Image image;
std::vector<std::string> spiceInstrument;
spiceInstrument.push_back(_instrumentID);
createImage(image, startTime, stopTime, spiceInstrument, _target, path);
createImage(
image,
startTime,
stopTime,
spiceInstrument,
_target,
path
);
_subsetMap[image.target]._subset.push_back(image);
_subsetMap[image.target]._range.include(startTime);
_captureProgression.push_back(startTime);
std::stable_sort(_captureProgression.begin(), _captureProgression.end());
std::stable_sort(
_captureProgression.begin(),
_captureProgression.end()
);
break;
}
@@ -291,14 +333,20 @@ bool LabelParser::create() {
for (auto image : tmp){
if (previousTarget != image.target){
previousTarget = image.target;
std::pair<double, std::string> v_target = std::make_pair(image.timeRange.start, image.target);
std::pair<double, std::string> v_target = std::make_pair(
image.timeRange.start,
image.target
);
_targetTimes.push_back(v_target);
std::sort(_targetTimes.begin(), _targetTimes.end(), targetComparer);
}
}
for (auto target : _subsetMap){
_instrumentTimes.push_back(std::make_pair(lblName, _subsetMap[target.first]._range));
_instrumentTimes.push_back(std::make_pair(
lblName,
_subsetMap[target.first]._range
));
// std::string min, max;
// SpiceManager::ref().getDateFromET(target.second._range._min, min);
@@ -326,7 +374,10 @@ bool LabelParser::create() {
return true;
}
void LabelParser::createImage(Image& image, double startTime, double stopTime, std::vector<std::string> instr, std::string targ, std::string pot) {
void LabelParser::createImage(Image& image, double startTime, double stopTime,
std::vector<std::string> instr, std::string targ,
std::string pot)
{
image.timeRange = { startTime , stopTime };
ghoul_assert(image.timeRange.isDefined(), "Invalid time range!");
image.path = pot;

View File

@@ -336,7 +336,10 @@ void ProjectionComponent::initialize(const ghoul::Dictionary& dictionary) {
}
}
else {
LWARNING("No playbook translation provided, please make sure all spice calls match playbook!");
LWARNING(
"No playbook translation provided, please make sure \
all spice calls match playbook!"
);
}
}
}
@@ -369,7 +372,9 @@ bool ProjectionComponent::initializeGL() {
using ghoul::opengl::Texture;
using ghoul::io::TextureReader;
unique_ptr<Texture> texture = TextureReader::ref().loadTexture(absPath(placeholderFile));
unique_ptr<Texture> texture = TextureReader::ref().loadTexture(
absPath(placeholderFile)
);
if (texture) {
texture->uploadTexture();
// TODO: AnisotropicMipMap crashes on ATI cards ---abock
@@ -814,12 +819,16 @@ glm::mat4 ProjectionComponent::computeProjectorMatrix(const glm::vec3 loc, glm::
glm::vec3 e1 = glm::normalize(glm::cross(uptmp, e3));
glm::vec3 e2 = glm::normalize(glm::cross(e3, e1));
glm::mat4 projViewMatrix = glm::mat4(e1.x, e2.x, e3.x, 0.f,
e1.y, e2.y, e3.y, 0.f,
e1.z, e2.z, e3.z, 0.f,
glm::dot(e1, -loc), glm::dot(e2, -loc), glm::dot(e3, -loc), 1.f);
glm::mat4 projViewMatrix = glm::mat4(
e1.x, e2.x, e3.x, 0.f,
e1.y, e2.y, e3.y, 0.f,
e1.z, e2.z, e3.z, 0.f,
glm::dot(e1, -loc), glm::dot(e2, -loc), glm::dot(e3, -loc), 1.f
);
// create perspective projection matrix
glm::mat4 projProjectionMatrix = glm::perspective(glm::radians(fieldOfViewY), aspectRatio, nearPlane, farPlane);
glm::mat4 projProjectionMatrix = glm::perspective(
glm::radians(fieldOfViewY), aspectRatio, nearPlane, farPlane
);
return projProjectionMatrix*projViewMatrix;
}
@@ -877,7 +886,12 @@ void ProjectionComponent::clearAllProjections() {
GLint m_viewport[4];
glGetIntegerv(GL_VIEWPORT, m_viewport);
//counter = 0;
glViewport(0, 0, static_cast<GLsizei>(_projectionTexture->width()), static_cast<GLsizei>(_projectionTexture->height()));
glViewport(
0,
0,
static_cast<GLsizei>(_projectionTexture->width()),
static_cast<GLsizei>(_projectionTexture->height())
);
glBindFramebuffer(GL_FRAMEBUFFER, _fboID);
@@ -933,7 +947,9 @@ bool ProjectionComponent::generateProjectionLayerTexture(const ivec2& size) {
);
if (_projectionTexture) {
_projectionTexture->uploadTexture();
//_projectionTexture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
//_projectionTexture->setFilter(
// ghoul::opengl::Texture::FilterMode::AnisotropicMipMap
//);
}
if (_dilation.isEnabled) {
@@ -944,7 +960,9 @@ bool ProjectionComponent::generateProjectionLayerTexture(const ivec2& size) {
if (_dilation.texture) {
_dilation.texture->uploadTexture();
//_dilation.texture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
//_dilation.texture->setFilter(
// ghoul::opengl::Texture::FilterMode::AnisotropicMipMap
//);
}
_dilation.stencilTexture = std::make_unique<ghoul::opengl::Texture>(
@@ -956,7 +974,9 @@ bool ProjectionComponent::generateProjectionLayerTexture(const ivec2& size) {
if (_dilation.stencilTexture) {
_dilation.stencilTexture->uploadTexture();
//_dilation.texture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
//_dilation.texture->setFilter(
// ghoul::opengl::Texture::FilterMode::AnisotropicMipMap
//);
}
}

View File

@@ -61,12 +61,18 @@ void writeToBuffer(std::vector<char>& buffer, size_t& currentWriteLocation, T va
if ((currentWriteLocation + sizeof(T)) > buffer.size())
buffer.resize(2 * buffer.size());
std::memmove(buffer.data() + currentWriteLocation, reinterpret_cast<const void*>(&value), sizeof(T));
std::memmove(
buffer.data() + currentWriteLocation,
reinterpret_cast<const void*>(&value),
sizeof(T)
);
currentWriteLocation += sizeof(T);
}
template <>
void writeToBuffer<std::string>(std::vector<char>& buffer, size_t& currentWriteLocation, std::string value) {
void writeToBuffer<std::string>(std::vector<char>& buffer, size_t& currentWriteLocation,
std::string value)
{
if ((currentWriteLocation + sizeof(uint8_t) + value.size()) > buffer.size())
buffer.resize(2 * buffer.size());
@@ -92,7 +98,8 @@ void SequenceParser::sendPlaybookInformation(const std::string& name) {
// 1 byte : Number of Instruments (i)
// i times: 1 byte (id), 1 byte (length j of name), j bytes (name)
// 4 byte: Number (n) of images
// n times: 8 byte (beginning time), 8 byte (ending time), 1 byte (target id), 2 byte (instrument id)
// n times: 8 byte (beginning time), 8 byte (ending time), 1 byte (target id),
// 2 byte (instrument id)
std::map<std::string, uint8_t> targetMap;
uint8_t currentTargetId = 0;
@@ -136,8 +143,12 @@ void SequenceParser::sendPlaybookInformation(const std::string& name) {
writeToBuffer(buffer, currentWriteLocation, image.timeRange.start);
writeToBuffer(buffer, currentWriteLocation, image.timeRange.end);
std::string timeBegin = SpiceManager::ref().dateFromEphemerisTime(image.timeRange.start);
std::string timeEnd = SpiceManager::ref().dateFromEphemerisTime(image.timeRange.end);
std::string timeBegin = SpiceManager::ref().dateFromEphemerisTime(
image.timeRange.start
);
std::string timeEnd = SpiceManager::ref().dateFromEphemerisTime(
image.timeRange.end
);
writeToBuffer(buffer, currentWriteLocation, timeBegin);
writeToBuffer(buffer, currentWriteLocation, timeEnd);

View File

@@ -32,7 +32,8 @@ namespace volume {
VolumeClipPlanes::VolumeClipPlanes(const ghoul::Dictionary& dictionary)
: properties::PropertyOwner({ "" }) // @TODO Missing name
, _nClipPlanes({ "nClipPlanes", "Number of clip planes", "" }, 0, 0, 10) // @TODO Missing documentation
// @TODO Missing documentation
, _nClipPlanes({ "nClipPlanes", "Number of clip planes", "" }, 0, 0, 10)
{
std::vector<std::string> keys = dictionary.keys();
for (const std::string& key : keys) {

View File

@@ -37,9 +37,9 @@ using namespace volume;
VolumeModule::VolumeModule() : OpenSpaceModule(Name) {}
void VolumeModule::internalInitialize() {
auto fRenderable = FactoryManager::ref().factory<Renderable>();
ghoul_assert(fRenderable, "No renderable factory existed");
fRenderable->registerClass<RenderableTimeVaryingVolume>("RenderableTimeVaryingVolume");
auto factory = FactoryManager::ref().factory<Renderable>();
ghoul_assert(factory, "No renderable factory existed");
factory->registerClass<RenderableTimeVaryingVolume>("RenderableTimeVaryingVolume");
}
} // namespace openspace

View File

@@ -308,6 +308,19 @@ def check_line_length(lines):
def check_line_length(lines):
# Disable this check in non-strict mode
if not is_strict_mode:
return ''
index = [i + 1 for i, s in enumerate(lines) if len(s) > (90 + 1)]
if len(index) > 0:
return index
else:
return ''
previousSymbols = {}
def check_header_file(file, component):
with open(file, 'r+') as f:
@@ -434,6 +447,10 @@ def check_inline_file(file, component):
if using_namespaces:
print(file, '\t', 'Using namespace found in inline file')
line_length = check_line_length(lines)
if line_length:
print(file, '\t', 'Line length exceeded: ', line_length)
def check_source_file(file, component):