Some work on making the TimelineGui work with the new hybrid parsers

This commit is contained in:
Alexander Bock
2015-07-01 23:40:38 +02:00
parent cc5e6074ad
commit bae990babb
10 changed files with 489 additions and 458 deletions
+14 -8
View File
@@ -130,6 +130,7 @@ void MainWindow::readTcpData() {
static const uint16_t MessageTypeStatus = 0;
static const uint16_t MessageTypePlayBookHongKang = 2;
static const uint16_t MessageTypePlayBookLabel = 3;
static const uint16_t MessageTypeInitialMessageFinished = 4;
QByteArray data = _socket->readAll();
@@ -161,7 +162,7 @@ void MainWindow::readTcpData() {
switch (messageType.value) {
case MessageTypeStatus:
{
if (_hasHongKangTimeline && _hasLabelTimeline)
if (_isConnected)
handleStatusMessage(data.mid(2));
break;
}
@@ -186,17 +187,22 @@ void MainWindow::readTcpData() {
//qDebug() << "Finished handling playbook";
if (messageType.value == MessageTypePlayBookHongKang)
_hasHongKangTimeline = true;
if (messageType.value == MessageTypePlayBookLabel)
_hasLabelTimeline = true;
//if (messageType.value == MessageTypePlayBookHongKang)
// _hasHongKangTimeline = true;
//if (messageType.value == MessageTypePlayBookLabel)
// _hasLabelTimeline = true;
if (_hasHongKangTimeline && _hasLabelTimeline) {
fullyConnected();
}
//if (_hasHongKangTimeline && _hasLabelTimeline) {
// fullyConnected();
//}
break;
}
case MessageTypeInitialMessageFinished:
_isConnected = true;
fullyConnected();
break;
default:
qDebug() << QString(data);
}
+1 -2
View File
@@ -67,8 +67,7 @@ private:
QTcpSocket* _socket;
bool _hasHongKangTimeline = false;
bool _hasLabelTimeline = false;
bool _isConnected = false;
};
#endif // __MAINWINDOW_H__
+3 -1
View File
@@ -53,8 +53,9 @@ public:
// Background
MessageIdentifier identifier(std::string name);
private:
std::map<MessageIdentifier, std::string> _identifiers;
std::map<std::string, MessageIdentifier> _identifiers;
MessageIdentifier _lastAssignedIdentifier;
struct Message {
@@ -69,6 +70,7 @@ private:
MessageIdentifier _statusMessageIdentifier;
MessageIdentifier _identifierMappingIdentifier;
MessageIdentifier _initialMessageFinishedIdentifier;
};
} // namespace openspace
@@ -71,461 +71,461 @@ namespace {
namespace openspace {
RenderableModelProjection::RenderableModelProjection(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
, _colorTexturePath("colorTexture", "Color Texture")
, _projectionTexturePath("projectionTexture", "RGB Texture")
, _rotationX("rotationX", "RotationX", 0, 0, 360)
, _rotationY("rotationY", "RotationY", 0, 0, 360)
, _rotationZ("rotationZ", "RotationZ", 0, 0, 360)
, _programObject(nullptr)
, _fboProgramObject(nullptr)
, _texture(nullptr)
, _geometry(nullptr)
, _textureOriginal(nullptr)
, _textureProj(nullptr)
, _textureWhiteSquare(nullptr)
, _alpha(1.f)
, _performShading("performShading", "Perform Shading", true)
, _performProjection("performProjection", "Perform Projections", true)
, _frameCount(0)
, _programIsDirty(false)
{
std::string name;
bool success = dictionary.getValue(constants::scenegraphnode::keyName, name);
ghoul_assert(success, "Name was not passed to RenderableModelProjection");
RenderableModelProjection::RenderableModelProjection(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
, _colorTexturePath("colorTexture", "Color Texture")
, _projectionTexturePath("projectionTexture", "RGB Texture")
, _rotationX("rotationX", "RotationX", 0, 0, 360)
, _rotationY("rotationY", "RotationY", 0, 0, 360)
, _rotationZ("rotationZ", "RotationZ", 0, 0, 360)
, _programObject(nullptr)
, _fboProgramObject(nullptr)
, _texture(nullptr)
, _geometry(nullptr)
, _textureOriginal(nullptr)
, _textureProj(nullptr)
, _textureWhiteSquare(nullptr)
, _alpha(1.f)
, _performShading("performShading", "Perform Shading", true)
, _performProjection("performProjection", "Perform Projections", true)
, _frameCount(0)
, _programIsDirty(false)
{
std::string name;
bool success = dictionary.getValue(constants::scenegraphnode::keyName, name);
ghoul_assert(success, "Name was not passed to RenderableModelProjection");
ghoul::Dictionary geometryDictionary;
success = dictionary.getValue(keyGeometry, geometryDictionary);
if (success) {
geometryDictionary.setValue(constants::scenegraphnode::keyName, name);
_geometry = modelgeometry::ModelGeometry::createFromDictionary(geometryDictionary);
}
ghoul::Dictionary geometryDictionary;
success = dictionary.getValue(keyGeometry, geometryDictionary);
if (success) {
geometryDictionary.setValue(constants::scenegraphnode::keyName, name);
_geometry = modelgeometry::ModelGeometry::createFromDictionary(geometryDictionary);
}
std::string texturePath = "";
success = dictionary.getValue(keyTextureColor, texturePath);
if (success)
_colorTexturePath = absPath(texturePath);
std::string texturePath = "";
success = dictionary.getValue(keyTextureColor, texturePath);
if (success)
_colorTexturePath = absPath(texturePath);
success = dictionary.getValue(keyTextureProject, texturePath);
if (success)
_projectionTexturePath = absPath(texturePath);
success = dictionary.getValue(keyTextureProject, texturePath);
if (success)
_projectionTexturePath = absPath(texturePath);
success = dictionary.getValue(keyTextureDefault, texturePath);
if (success)
_defaultProjImage = absPath(texturePath);
success = dictionary.getValue(keyTextureDefault, texturePath);
if (success)
_defaultProjImage = absPath(texturePath);
addPropertySubOwner(_geometry);
addPropertySubOwner(_geometry);
addProperty(_colorTexturePath);
addProperty(_projectionTexturePath);
_colorTexturePath.onChange(std::bind(&RenderableModelProjection::loadTexture, this));
_projectionTexturePath.onChange(std::bind(&RenderableModelProjection::loadProjectionTexture, this));
addProperty(_colorTexturePath);
addProperty(_projectionTexturePath);
_colorTexturePath.onChange(std::bind(&RenderableModelProjection::loadTexture, this));
_projectionTexturePath.onChange(std::bind(&RenderableModelProjection::loadProjectionTexture, this));
dictionary.getValue(keySource, _source);
dictionary.getValue(keyDestination, _destination);
dictionary.getValue(keyBody, _target);
if (_target != "")
setBody(_target);
dictionary.getValue(keySource, _source);
dictionary.getValue(keyDestination, _destination);
dictionary.getValue(keyBody, _target);
if (_target != "")
setBody(_target);
bool completeSuccess = true;
completeSuccess &= dictionary.getValue(keyInstrument, _instrumentID);
completeSuccess &= dictionary.getValue(keyProjObserver, _projectorID);
completeSuccess &= dictionary.getValue(keyProjTarget, _projecteeID);
completeSuccess &= dictionary.getValue(keyInstrumentFovy, _fovy);
completeSuccess &= dictionary.getValue(keyInstrumentAspect, _aspectRatio);
completeSuccess &= dictionary.getValue(keyInstrumentNear, _nearPlane);
completeSuccess &= dictionary.getValue(keyInstrumentFar, _farPlane);
ghoul_assert(completeSuccess, "All neccessary attributes not found in modfile");
bool completeSuccess = true;
completeSuccess &= dictionary.getValue(keyInstrument, _instrumentID);
completeSuccess &= dictionary.getValue(keyProjObserver, _projectorID);
completeSuccess &= dictionary.getValue(keyProjTarget, _projecteeID);
completeSuccess &= dictionary.getValue(keyInstrumentFovy, _fovy);
completeSuccess &= dictionary.getValue(keyInstrumentAspect, _aspectRatio);
completeSuccess &= dictionary.getValue(keyInstrumentNear, _nearPlane);
completeSuccess &= dictionary.getValue(keyInstrumentFar, _farPlane);
ghoul_assert(completeSuccess, "All neccessary attributes not found in modfile");
completeSuccess = dictionary.getValue(keyProjAberration, _aberration);
if (!completeSuccess)
_aberration = "NONE";
completeSuccess = dictionary.getValue(keyProjAberration, _aberration);
if (!completeSuccess)
_aberration = "NONE";
openspace::SpiceManager::ref().addFrame(_target, _source);
setBoundingSphere(pss(1.f, 9.f));
openspace::SpiceManager::ref().addFrame(_target, _source);
setBoundingSphere(pss(1.f, 9.f));
addProperty(_performShading);
addProperty(_performProjection);
addProperty(_rotationX);
addProperty(_rotationY);
addProperty(_rotationZ);
addProperty(_performShading);
addProperty(_performProjection);
addProperty(_rotationX);
addProperty(_rotationY);
addProperty(_rotationZ);
SequenceParser* parser;
SequenceParser* parser;
bool foundSequence = dictionary.getValue(keySequenceDir, _sequenceSource);
if (foundSequence) {
_sequenceSource = absPath(_sequenceSource);
bool foundSequence = dictionary.getValue(keySequenceDir, _sequenceSource);
if (foundSequence) {
_sequenceSource = absPath(_sequenceSource);
foundSequence = dictionary.getValue(keySequenceType, _sequenceType);
//Important: client must define translation-list in mod file IFF playbook
if (dictionary.hasKey(keyTranslation)) {
ghoul::Dictionary translationDictionary;
//get translation dictionary
dictionary.getValue(keyTranslation, translationDictionary);
if (_sequenceType == sequenceTypeImage) {
parser = new LabelParser(_sequenceSource, translationDictionary);
openspace::ImageSequencer2::ref().runSequenceParser(parser);
foundSequence = dictionary.getValue(keySequenceType, _sequenceType);
//Important: client must define translation-list in mod file IFF playbook
if (dictionary.hasKey(keyTranslation)) {
ghoul::Dictionary translationDictionary;
//get translation dictionary
dictionary.getValue(keyTranslation, translationDictionary);
if (_sequenceType == sequenceTypeImage) {
parser = new LabelParser(name, _sequenceSource, translationDictionary);
openspace::ImageSequencer2::ref().runSequenceParser(parser);
}
}
else {
LWARNING("No translation provided, please make sure all spice calls match playbook!");
}
}
else {
LWARNING("No translation provided, please make sure all spice calls match playbook!");
}
}
bool RenderableModelProjection::isReady() const {
bool ready = true;
ready &= (_programObject != nullptr);
ready &= (_texture != nullptr);
return ready;
}
}
bool RenderableModelProjection::initialize() {
bool completeSuccess = true;
bool RenderableModelProjection::isReady() const {
bool ready = true;
ready &= (_programObject != nullptr);
ready &= (_texture != nullptr);
return ready;
}
bool RenderableModelProjection::initialize() {
bool completeSuccess = true;
if (_programObject == nullptr) {
_programObject = ghoul::opengl::ProgramObject::Build("ModelShader",
"${MODULES}/newhorizons/shaders/modelShader_vs.glsl",
"${MODULES}/newhorizons/shaders/modelShader_fs.glsl");
if (!_programObject)
return false;
}
_programObject->setProgramObjectCallback([&](ghoul::opengl::ProgramObject*) { this->_programIsDirty = true; } );
if (_programObject == nullptr) {
_programObject = ghoul::opengl::ProgramObject::Build("ModelShader",
"${MODULES}/newhorizons/shaders/modelShader_vs.glsl",
"${MODULES}/newhorizons/shaders/modelShader_fs.glsl");
if (!_programObject)
return false;
}
_programObject->setProgramObjectCallback([&](ghoul::opengl::ProgramObject*) { this->_programIsDirty = true; } );
if (_fboProgramObject == nullptr) {
_fboProgramObject = ghoul::opengl::ProgramObject::Build("ProjectionPass",
"${MODULES}/newhorizons/shaders/projectionPass_vs.glsl",
"${MODULES}/newhorizons/shaders/projectionPass_fs.glsl");
if (!_fboProgramObject)
return false;
}
_fboProgramObject->setProgramObjectCallback([&](ghoul::opengl::ProgramObject*) { this->_programIsDirty = true; } );
if (_fboProgramObject == nullptr) {
_fboProgramObject = ghoul::opengl::ProgramObject::Build("ProjectionPass",
"${MODULES}/newhorizons/shaders/projectionPass_vs.glsl",
"${MODULES}/newhorizons/shaders/projectionPass_fs.glsl");
if (!_fboProgramObject)
return false;
}
_fboProgramObject->setProgramObjectCallback([&](ghoul::opengl::ProgramObject*) { this->_programIsDirty = true; } );
loadTexture();
loadProjectionTexture();
loadTexture();
loadProjectionTexture();
completeSuccess &= (_texture != nullptr);
completeSuccess &= (_textureOriginal != nullptr);
completeSuccess &= (_textureProj != nullptr);
completeSuccess &= (_textureWhiteSquare != nullptr);
completeSuccess &= (_texture != nullptr);
completeSuccess &= (_textureOriginal != nullptr);
completeSuccess &= (_textureProj != nullptr);
completeSuccess &= (_textureWhiteSquare != nullptr);
completeSuccess &= _geometry->initialize(this);
completeSuccess &= !_source.empty();
completeSuccess &= !_destination.empty();
completeSuccess &= _geometry->initialize(this);
completeSuccess &= !_source.empty();
completeSuccess &= !_destination.empty();
bool gotverts = _geometry->getVertices(&_geometryVertecies) && _geometry->getIndices(&_geometryIndeces);
if (!gotverts)
LWARNING("Lack of vertex data from geometry for image projection");
bool gotverts = _geometry->getVertices(&_geometryVertecies) && _geometry->getIndices(&_geometryIndeces);
if (!gotverts)
LWARNING("Lack of vertex data from geometry for image projection");
completeSuccess &= auxiliaryRendertarget();
completeSuccess &= auxiliaryRendertarget();
return completeSuccess;
}
return completeSuccess;
}
bool RenderableModelProjection::auxiliaryRendertarget() {
bool completeSuccess = true;
// set FBO to texture to project to
glGenFramebuffers(1, &_fboID);
glBindFramebuffer(GL_FRAMEBUFFER, _fboID);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, *_texture, 0);
// check FBO status
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE)
completeSuccess &= false;
// switch back to window-system-provided framebuffer
glBindFramebuffer(GL_FRAMEBUFFER, 0);
bool RenderableModelProjection::auxiliaryRendertarget() {
bool completeSuccess = true;
// set FBO to texture to project to
glGenFramebuffers(1, &_fboID);
glBindFramebuffer(GL_FRAMEBUFFER, _fboID);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, *_texture, 0);
// check FBO status
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE)
completeSuccess &= false;
// switch back to window-system-provided framebuffer
glBindFramebuffer(GL_FRAMEBUFFER, 0);
int vertexSize = sizeof(modelgeometry::ModelGeometry::Vertex);
int vertexSize = sizeof(modelgeometry::ModelGeometry::Vertex);
glGenVertexArrays(1, &_vaoID);
glGenBuffers(1, &_vbo);
glGenBuffers(1, &_ibo);
glGenVertexArrays(1, &_vaoID);
glGenBuffers(1, &_vbo);
glGenBuffers(1, &_ibo);
glBindVertexArray(_vaoID);
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
glBufferData(GL_ARRAY_BUFFER, _geometryVertecies.size() * vertexSize, &_geometryVertecies[0], GL_STATIC_DRAW);
glBindVertexArray(_vaoID);
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
glBufferData(GL_ARRAY_BUFFER, _geometryVertecies.size() * vertexSize, &_geometryVertecies[0], GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, vertexSize,
reinterpret_cast<const GLvoid*>(offsetof(modelgeometry::ModelGeometry::Vertex, location)));
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, vertexSize,
reinterpret_cast<const GLvoid*>(offsetof(modelgeometry::ModelGeometry::Vertex, tex)));
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, vertexSize,
reinterpret_cast<const GLvoid*>(offsetof(modelgeometry::ModelGeometry::Vertex, normal)));
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, vertexSize,
reinterpret_cast<const GLvoid*>(offsetof(modelgeometry::ModelGeometry::Vertex, location)));
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, vertexSize,
reinterpret_cast<const GLvoid*>(offsetof(modelgeometry::ModelGeometry::Vertex, tex)));
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, vertexSize,
reinterpret_cast<const GLvoid*>(offsetof(modelgeometry::ModelGeometry::Vertex, normal)));
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ibo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, _geometryIndeces.size() * sizeof(int), &_geometryIndeces[0], GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ibo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, _geometryIndeces.size() * sizeof(int), &_geometryIndeces[0], GL_STATIC_DRAW);
glBindVertexArray(0);
glBindVertexArray(0);
return completeSuccess;
return completeSuccess;
}
bool RenderableModelProjection::deinitialize() {
if (_geometry) {
_geometry->deinitialize();
delete _geometry;
}
bool RenderableModelProjection::deinitialize() {
if (_geometry) {
_geometry->deinitialize();
delete _geometry;
}
if (_texture)
delete _texture;
if (_textureProj)
delete _textureProj;
if (_textureOriginal)
delete _textureOriginal;
if (_textureWhiteSquare)
delete _textureWhiteSquare;
_geometry = nullptr;
_texture = nullptr;
_textureProj = nullptr;
_textureOriginal = nullptr;
_textureWhiteSquare = nullptr;
glDeleteBuffers(1, &_vbo);
return true;
}
void RenderableModelProjection::render(const RenderData& data) {
if (!_programObject) return;
if (!_textureProj) return;
_programObject->activate();
_frameCount++;
_camScaling = data.camera.scaling();
_up = data.camera.lookUpVector();
if (_capture && _performProjection)
project();
attitudeParameters(_time);
_imageTimes.clear();
double time = openspace::Time::ref().currentTime();
bool targetPositionCoverage = openspace::SpiceManager::ref().hasSpkCoverage(_target, time);
if (!targetPositionCoverage) {
int frame = _frameCount % 180;
float fadingFactor = static_cast<float>(sin((frame * M_PI) / 180));
_alpha = 0.5f + fadingFactor * 0.5f;
}
else
_alpha = 1.0f;
_programObject->setUniform("ProjectorMatrix", _projectorMatrix);
_programObject->setUniform("boresight", _boresight);
_programObject->setUniform("_performShading", _performShading);
_programObject->setUniform("sun_pos", _sunPosition.vec3());
_viewProjection = data.camera.viewProjectionMatrix();
_programObject->setUniform("ViewProjection", _viewProjection);
_programObject->setUniform("ModelTransform", _transform);
setPscUniforms(_programObject, &data.camera, data.position);
textureBind();
_geometry->render();
// disable shader
_programObject->deactivate();
}
void RenderableModelProjection::update(const UpdateData& data) {
if (_programIsDirty) {
_programObject->rebuildFromFile();
_fboProgramObject->rebuildFromFile();
_programIsDirty = false;
}
_time = data.time;
if (openspace::ImageSequencer2::ref().isReady() && _performProjection) {
openspace::ImageSequencer2::ref().updateSequencer(_time);
_capture = openspace::ImageSequencer2::ref().getImagePaths(_imageTimes, _projecteeID, _instrumentID);
}
// set spice-orientation in accordance to timestamp
if (!_source.empty())
openspace::SpiceManager::ref().getPositionTransformMatrix(_source, _destination, _time, _stateMatrix);
double lt;
openspace::SpiceManager::ref().getTargetPosition("SUN", _target, "GALACTIC", "NONE", _time, _sunPosition, lt);
}
void RenderableModelProjection::imageProjectGPU() {
// keep handle to the current bound FBO
GLint defaultFBO;
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defaultFBO);
GLint m_viewport[4];
glGetIntegerv(GL_VIEWPORT, m_viewport);
glBindFramebuffer(GL_FRAMEBUFFER, _fboID);
// set blend eq
glEnable(GL_BLEND);
glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ZERO);
glViewport(0, 0, static_cast<GLsizei>(_texture->width()), static_cast<GLsizei>(_texture->height()));
_fboProgramObject->activate();
ghoul::opengl::TextureUnit unitFboProject;
unitFboProject.activate();
_textureProj->bind();
_fboProgramObject->setUniform("projectTexture", unitFboProject);
ghoul::opengl::TextureUnit unitFboCurrent;
unitFboCurrent.activate();
_texture->bind();
_fboProgramObject->setUniform("currentTexture", unitFboCurrent);
_fboProgramObject->setUniform("ProjectorMatrix", _projectorMatrix);
_fboProgramObject->setUniform("ModelTransform", _transform);
_fboProgramObject->setUniform("_scaling", _camScaling);
_fboProgramObject->setUniform("boresight", _boresight);
glBindVertexArray(_vaoID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ibo);
glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(_geometryIndeces.size()), GL_UNSIGNED_INT, 0);
glBindVertexArray(0);
_fboProgramObject->deactivate();
glDisable(GL_BLEND);
//bind back to default
glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO);
glViewport(m_viewport[0], m_viewport[1],
m_viewport[2], m_viewport[3]);
}
void RenderableModelProjection::attitudeParameters(double time) {
openspace::SpiceManager::ref().getPositionTransformMatrix(_source, _destination, time, _stateMatrix);
openspace::SpiceManager::ref().getPositionTransformMatrix(_instrumentID, _destination, time, _instrumentMatrix);
_transform = glm::mat4(1);
glm::mat4 rotPropX = glm::rotate(_transform, static_cast<float>(_rotationX), glm::vec3(1, 0, 0));
glm::mat4 rotPropY = glm::rotate(_transform, static_cast<float>(_rotationY), glm::vec3(0, 1, 0));
glm::mat4 rotPropZ = glm::rotate(_transform, static_cast<float>(_rotationZ), glm::vec3(0, 0, 1));
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
_transform[i][j] = static_cast<float>(_stateMatrix[i][j]);
}
}
_transform = _transform * rotPropX * rotPropY * rotPropZ;
std::string shape, instrument;
std::vector<glm::dvec3> bounds;
glm::dvec3 boresight;
bool found = openspace::SpiceManager::ref().getFieldOfView(_instrumentID, shape, instrument, boresight, bounds);
if (!found)
return;
double lightTime;
psc position; //observer target
found = SpiceManager::ref().getTargetPosition(_projectorID, _projecteeID, _destination, _aberration, time, position, lightTime);
position[3] += (3 + _camScaling[1]);
glm::vec3 cpos = position.vec3();
_projectorMatrix = computeProjectorMatrix(cpos, boresight, _up);
}
glm::mat4 RenderableModelProjection::computeProjectorMatrix(const glm::vec3 loc, glm::dvec3 aim, const glm::vec3 up) {
//rotate boresight into correct alignment
_boresight = _instrumentMatrix*aim;
glm::vec3 uptmp(_instrumentMatrix*glm::dvec3(up));
// create view matrix
glm::vec3 e3 = glm::normalize(_boresight);
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);
// create perspective projection matrix
glm::mat4 projProjectionMatrix = glm::perspective(_fovy, _aspectRatio, _nearPlane, _farPlane);
// bias matrix
glm::mat4 projNormalizationMatrix = glm::mat4(0.5f, 0, 0, 0,
0, 0.5f, 0, 0,
0, 0, 0.5f, 0,
0.5f, 0.5f, 0.5f, 1);
return projNormalizationMatrix*projProjectionMatrix*projViewMatrix;
}
void RenderableModelProjection::textureBind() {
ghoul::opengl::TextureUnit unit[2];
unit[0].activate();
_texture->bind();
_programObject->setUniform("currentTexture", unit[0]);
unit[1].activate();
_textureWhiteSquare->bind();
_programObject->setUniform("projectedTexture", unit[1]);
}
void RenderableModelProjection::project() {
for (auto img : _imageTimes) {
std::thread t1(&RenderableModelProjection::attitudeParameters, this, img.startTime);
t1.join();
_projectionTexturePath = img.path;
imageProjectGPU(); //fbopass
}
_capture = false;
}
void RenderableModelProjection::loadTexture() {
if (_texture)
delete _texture;
_texture = nullptr;
if (_colorTexturePath.value() != "") {
_texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath));
if (_texture) {
LDEBUG("Loaded texture from '" << absPath(_colorTexturePath) << "'");
_texture->uploadTexture();
_texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
}
}
delete _textureOriginal;
_textureOriginal = nullptr;
if (_colorTexturePath.value() != "") {
_textureOriginal = ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath));
if (_textureOriginal) {
LDEBUG("Loaded texture from '" << absPath(_colorTexturePath) << "'");
_textureOriginal->uploadTexture();
_textureOriginal->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
}
}
delete _textureWhiteSquare;
_textureWhiteSquare = nullptr;
if (_defaultProjImage != "") {
_textureWhiteSquare = ghoul::io::TextureReader::ref().loadTexture(absPath(_defaultProjImage));
if (_textureWhiteSquare) {
_textureWhiteSquare->uploadTexture();
_textureWhiteSquare->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
}
}
}
void RenderableModelProjection::loadProjectionTexture() {
if (_textureProj)
delete _textureProj;
_textureProj = nullptr;
if (_projectionTexturePath.value() != "") {
_textureProj = ghoul::io::TextureReader::ref().loadTexture(absPath(_projectionTexturePath));
if (_textureProj) {
_textureProj->uploadTexture();
_textureProj->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
_textureProj->setWrapping(ghoul::opengl::Texture::WrappingMode::ClampToBorder);
}
}
if (_textureOriginal)
delete _textureOriginal;
if (_textureWhiteSquare)
delete _textureWhiteSquare;
_geometry = nullptr;
_texture = nullptr;
_textureProj = nullptr;
_textureOriginal = nullptr;
_textureWhiteSquare = nullptr;
glDeleteBuffers(1, &_vbo);
return true;
}
void RenderableModelProjection::render(const RenderData& data) {
if (!_programObject) return;
if (!_textureProj) return;
_programObject->activate();
_frameCount++;
_camScaling = data.camera.scaling();
_up = data.camera.lookUpVector();
if (_capture && _performProjection)
project();
attitudeParameters(_time);
_imageTimes.clear();
double time = openspace::Time::ref().currentTime();
bool targetPositionCoverage = openspace::SpiceManager::ref().hasSpkCoverage(_target, time);
if (!targetPositionCoverage) {
int frame = _frameCount % 180;
float fadingFactor = static_cast<float>(sin((frame * M_PI) / 180));
_alpha = 0.5f + fadingFactor * 0.5f;
}
else
_alpha = 1.0f;
_programObject->setUniform("ProjectorMatrix", _projectorMatrix);
_programObject->setUniform("boresight", _boresight);
_programObject->setUniform("_performShading", _performShading);
_programObject->setUniform("sun_pos", _sunPosition.vec3());
_viewProjection = data.camera.viewProjectionMatrix();
_programObject->setUniform("ViewProjection", _viewProjection);
_programObject->setUniform("ModelTransform", _transform);
setPscUniforms(_programObject, &data.camera, data.position);
textureBind();
_geometry->render();
// disable shader
_programObject->deactivate();
}
void RenderableModelProjection::update(const UpdateData& data) {
if (_programIsDirty) {
_programObject->rebuildFromFile();
_fboProgramObject->rebuildFromFile();
_programIsDirty = false;
}
_time = data.time;
if (openspace::ImageSequencer2::ref().isReady() && _performProjection) {
openspace::ImageSequencer2::ref().updateSequencer(_time);
_capture = openspace::ImageSequencer2::ref().getImagePaths(_imageTimes, _projecteeID, _instrumentID);
}
// set spice-orientation in accordance to timestamp
if (!_source.empty())
openspace::SpiceManager::ref().getPositionTransformMatrix(_source, _destination, _time, _stateMatrix);
double lt;
openspace::SpiceManager::ref().getTargetPosition("SUN", _target, "GALACTIC", "NONE", _time, _sunPosition, lt);
}
void RenderableModelProjection::imageProjectGPU() {
// keep handle to the current bound FBO
GLint defaultFBO;
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defaultFBO);
GLint m_viewport[4];
glGetIntegerv(GL_VIEWPORT, m_viewport);
glBindFramebuffer(GL_FRAMEBUFFER, _fboID);
// set blend eq
glEnable(GL_BLEND);
glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ZERO);
glViewport(0, 0, static_cast<GLsizei>(_texture->width()), static_cast<GLsizei>(_texture->height()));
_fboProgramObject->activate();
ghoul::opengl::TextureUnit unitFboProject;
unitFboProject.activate();
_textureProj->bind();
_fboProgramObject->setUniform("projectTexture", unitFboProject);
ghoul::opengl::TextureUnit unitFboCurrent;
unitFboCurrent.activate();
_texture->bind();
_fboProgramObject->setUniform("currentTexture", unitFboCurrent);
_fboProgramObject->setUniform("ProjectorMatrix", _projectorMatrix);
_fboProgramObject->setUniform("ModelTransform", _transform);
_fboProgramObject->setUniform("_scaling", _camScaling);
_fboProgramObject->setUniform("boresight", _boresight);
glBindVertexArray(_vaoID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ibo);
glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(_geometryIndeces.size()), GL_UNSIGNED_INT, 0);
glBindVertexArray(0);
_fboProgramObject->deactivate();
glDisable(GL_BLEND);
//bind back to default
glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO);
glViewport(m_viewport[0], m_viewport[1],
m_viewport[2], m_viewport[3]);
}
void RenderableModelProjection::attitudeParameters(double time) {
openspace::SpiceManager::ref().getPositionTransformMatrix(_source, _destination, time, _stateMatrix);
openspace::SpiceManager::ref().getPositionTransformMatrix(_instrumentID, _destination, time, _instrumentMatrix);
_transform = glm::mat4(1);
glm::mat4 rotPropX = glm::rotate(_transform, static_cast<float>(_rotationX), glm::vec3(1, 0, 0));
glm::mat4 rotPropY = glm::rotate(_transform, static_cast<float>(_rotationY), glm::vec3(0, 1, 0));
glm::mat4 rotPropZ = glm::rotate(_transform, static_cast<float>(_rotationZ), glm::vec3(0, 0, 1));
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
_transform[i][j] = static_cast<float>(_stateMatrix[i][j]);
}
}
_transform = _transform * rotPropX * rotPropY * rotPropZ;
std::string shape, instrument;
std::vector<glm::dvec3> bounds;
glm::dvec3 boresight;
bool found = openspace::SpiceManager::ref().getFieldOfView(_instrumentID, shape, instrument, boresight, bounds);
if (!found)
return;
double lightTime;
psc position; //observer target
found = SpiceManager::ref().getTargetPosition(_projectorID, _projecteeID, _destination, _aberration, time, position, lightTime);
position[3] += (3 + _camScaling[1]);
glm::vec3 cpos = position.vec3();
_projectorMatrix = computeProjectorMatrix(cpos, boresight, _up);
}
glm::mat4 RenderableModelProjection::computeProjectorMatrix(const glm::vec3 loc, glm::dvec3 aim, const glm::vec3 up) {
//rotate boresight into correct alignment
_boresight = _instrumentMatrix*aim;
glm::vec3 uptmp(_instrumentMatrix*glm::dvec3(up));
// create view matrix
glm::vec3 e3 = glm::normalize(_boresight);
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);
// create perspective projection matrix
glm::mat4 projProjectionMatrix = glm::perspective(_fovy, _aspectRatio, _nearPlane, _farPlane);
// bias matrix
glm::mat4 projNormalizationMatrix = glm::mat4(0.5f, 0, 0, 0,
0, 0.5f, 0, 0,
0, 0, 0.5f, 0,
0.5f, 0.5f, 0.5f, 1);
return projNormalizationMatrix*projProjectionMatrix*projViewMatrix;
}
void RenderableModelProjection::textureBind() {
ghoul::opengl::TextureUnit unit[2];
unit[0].activate();
_texture->bind();
_programObject->setUniform("currentTexture", unit[0]);
unit[1].activate();
_textureWhiteSquare->bind();
_programObject->setUniform("projectedTexture", unit[1]);
}
void RenderableModelProjection::project() {
for (auto img : _imageTimes) {
std::thread t1(&RenderableModelProjection::attitudeParameters, this, img.startTime);
t1.join();
_projectionTexturePath = img.path;
imageProjectGPU(); //fbopass
}
_capture = false;
}
void RenderableModelProjection::loadTexture() {
delete _texture;
_texture = nullptr;
if (_colorTexturePath.value() != "") {
_texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath));
if (_texture) {
LDEBUG("Loaded texture from '" << absPath(_colorTexturePath) << "'");
_texture->uploadTexture();
_texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
}
}
delete _textureOriginal;
_textureOriginal = nullptr;
if (_colorTexturePath.value() != "") {
_textureOriginal = ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath));
if (_textureOriginal) {
LDEBUG("Loaded texture from '" << absPath(_colorTexturePath) << "'");
_textureOriginal->uploadTexture();
_textureOriginal->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
}
}
delete _textureWhiteSquare;
_textureWhiteSquare = nullptr;
if (_defaultProjImage != "") {
_textureWhiteSquare = ghoul::io::TextureReader::ref().loadTexture(absPath(_defaultProjImage));
if (_textureWhiteSquare) {
_textureWhiteSquare->uploadTexture();
_textureWhiteSquare->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
}
}
}
void RenderableModelProjection::loadProjectionTexture() {
delete _textureProj;
_textureProj = nullptr;
if (_projectionTexturePath.value() != "") {
_textureProj = ghoul::io::TextureReader::ref().loadTexture(absPath(_projectionTexturePath));
if (_textureProj) {
_textureProj->uploadTexture();
_textureProj->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
_textureProj->setWrapping(ghoul::opengl::Texture::WrappingMode::ClampToBorder);
}
}
}
} // namespace openspace
@@ -184,20 +184,25 @@ RenderablePlanetProjection::RenderablePlanetProjection(const ghoul::Dictionary&
//get translation dictionary
dictionary.getValue(keyTranslation, translationDictionary);
if (_sequenceType == sequenceTypePlaybook){
parser = new HongKangParser(_sequenceSource,
if (_sequenceType == sequenceTypePlaybook) {
parser = new HongKangParser(name,
_sequenceSource,
_projectorID,
translationDictionary,
_potentialTargets);
openspace::ImageSequencer2::ref().runSequenceParser(parser);
}
else if (_sequenceType == sequenceTypeImage){
parser = new LabelParser(_sequenceSource, translationDictionary);
else if (_sequenceType == sequenceTypeImage) {
parser = new LabelParser(name,
_sequenceSource,
translationDictionary);
openspace::ImageSequencer2::ref().runSequenceParser(parser);
}
else if (_sequenceType == sequenceTypeHybrid){
else if (_sequenceType == sequenceTypeHybrid) {
//first read labels
parser = new LabelParser(_sequenceSource, translationDictionary);
parser = new LabelParser(name,
_sequenceSource,
translationDictionary);
openspace::ImageSequencer2::ref().runSequenceParser(parser);
std::string _eventFile;
@@ -205,7 +210,8 @@ RenderablePlanetProjection::RenderablePlanetProjection(const ghoul::Dictionary&
if (foundEventFile){
//then read playbook
_eventFile = absPath(_eventFile);
parser = new HongKangParser(_eventFile,
parser = new HongKangParser(name,
_eventFile,
_projectorID,
translationDictionary,
_potentialTargets);
+4 -4
View File
@@ -43,12 +43,12 @@ namespace {
}
namespace openspace {
HongKangParser::HongKangParser(const std::string& fileName,
HongKangParser::HongKangParser(std::string name, const std::string& fileName,
std::string spacecraft,
ghoul::Dictionary translationDictionary,
std::vector<std::string> potentialTargets) :
_defaultCaptureImage(absPath("${OPENSPACE_DATA}/scene/common/textures/placeholder.png"))
std::vector<std::string> potentialTargets)
: _name(std::move(name))
, _defaultCaptureImage(absPath("${OPENSPACE_DATA}/scene/common/textures/placeholder.png"))
{
_fileName = fileName;
_spacecraft = spacecraft;
+2 -1
View File
@@ -38,7 +38,7 @@ namespace openspace {
class HongKangParser : public SequenceParser {
public:
HongKangParser();
HongKangParser(const std::string& fileName,
HongKangParser(std::string name, const std::string& fileName,
std::string spacecraft,
ghoul::Dictionary dictionary,
std::vector<std::string> potentialTargets);
@@ -69,6 +69,7 @@ private:
std::string _defaultCaptureImage;
double _metRef = 299180517;
std::string _name;
std::string _fileName;
std::string _spacecraft;
std::map<std::string, Decoder*> _fileTranslation;
+5 -2
View File
@@ -44,8 +44,11 @@ namespace {
}
namespace openspace {
LabelParser::LabelParser(const std::string& fileName,
ghoul::Dictionary translationDictionary) : _badDecoding(false)
LabelParser::LabelParser(std::string name, const std::string& fileName,
ghoul::Dictionary translationDictionary)
: _name(std::move(name))
, _badDecoding(false)
{
_fileName = fileName;
//get the different instrument types
+3 -1
View File
@@ -36,7 +36,8 @@ namespace openspace {
class LabelParser : public SequenceParser{
public:
LabelParser();
LabelParser(const std::string& fileName,
LabelParser(std::string name,
const std::string& fileName,
ghoul::Dictionary translationDictionary);
bool create() override;
@@ -60,6 +61,7 @@ private:
std::vector<std::string> payload,
std::vector<std::string> potentialTargets);
std::string _name;
std::string _fileName;
std::string _spacecraft;
std::map<std::string, Decoder*> _fileTranslation;
+32 -20
View File
@@ -40,6 +40,7 @@ namespace {
const std::string StatusMessageIdentifierName = "StatusMessage";
const std::string MappingIdentifierIdentifierName = "IdentifierMapping";
const std::string InitialMessageFinishedIdentifierName = "InitialMessageFinished";
const char MessageTypeLuaScript = '0';
const char MessageTypeExternalControlConnected = '1';
@@ -57,6 +58,7 @@ NetworkEngine::NetworkEngine()
);
_statusMessageIdentifier = identifier(StatusMessageIdentifierName);
_identifierMappingIdentifier = identifier(MappingIdentifierIdentifierName);
_initialMessageFinishedIdentifier = identifier(InitialMessageFinishedIdentifierName);
}
bool NetworkEngine::handleMessage(const std::string& message) {
@@ -117,18 +119,18 @@ void NetworkEngine::publishStatusMessage() {
void NetworkEngine::publishIdentifierMappingMessage() {
size_t bufferSize = 0;
for (const std::pair<MessageIdentifier, std::string>& i : _identifiers) {
for (const std::pair<std::string, MessageIdentifier>& i : _identifiers) {
bufferSize += sizeof(MessageIdentifier);
bufferSize += i.second.size() + 1; // +1 for \0 terminating character
bufferSize += i.first.size() + 1; // +1 for \0 terminating character
}
std::vector<char> buffer(bufferSize);
size_t currentWritingPosition = 0;
for (const std::pair<MessageIdentifier, std::string>& i : _identifiers) {
std::memcpy(buffer.data() + currentWritingPosition, &(i.first), sizeof(MessageIdentifier));
for (const std::pair<std::string, MessageIdentifier>& i : _identifiers) {
std::memcpy(buffer.data() + currentWritingPosition, &(i.second), sizeof(MessageIdentifier));
currentWritingPosition += sizeof(MessageIdentifier);
std::memcpy(buffer.data() + currentWritingPosition, i.second.data(), i.second.size());
currentWritingPosition += i.second.size();
std::memcpy(buffer.data() + currentWritingPosition, i.first.data(), i.first.size());
currentWritingPosition += i.first.size();
buffer[currentWritingPosition] = '\0';
currentWritingPosition += 1;
}
@@ -138,21 +140,17 @@ void NetworkEngine::publishIdentifierMappingMessage() {
NetworkEngine::MessageIdentifier NetworkEngine::identifier(std::string name) {
#ifdef DEBUG
// Check if name has been assigned already
for (const std::pair<MessageIdentifier, std::string>& p : _identifiers) {
if (p.second == name) {
LERROR("Name '" << name << "' for identifier has been registered before");
return -1;
}
auto i = _identifiers.find(name);
if (i != _identifiers.end())
return i->second;
else {
_lastAssignedIdentifier++;
MessageIdentifier result = _lastAssignedIdentifier;
_identifiers[std::move(name)] = result;
return result;
}
#endif
_lastAssignedIdentifier++;
MessageIdentifier result = _lastAssignedIdentifier;
_identifiers[result] = std::move(name);
return result;
}
void NetworkEngine::publishMessage(MessageIdentifier identifier, std::vector<char> message) {
@@ -205,6 +203,20 @@ void NetworkEngine::sendInitialInformation() {
std::this_thread::sleep_for(std::chrono::milliseconds(SleepTime));
}
std::this_thread::sleep_for(std::chrono::milliseconds(SleepTime));
// Send finished message
union {
MessageIdentifier value;
std::array<char, 2> data;
} identifier;
identifier.value = _initialMessageFinishedIdentifier;
sgct::Engine::instance()->sendMessageToExternalControl(
identifier.data.data(),
2
);
_shouldPublishStatusMessage = true;
}