From bae990babbe0fc55410f83a8b39d829155455450 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Wed, 1 Jul 2015 23:40:38 +0200 Subject: [PATCH 1/4] Some work on making the TimelineGui work with the new hybrid parsers --- apps/TimelineView/mainwindow.cpp | 22 +- apps/TimelineView/mainwindow.h | 3 +- include/openspace/network/networkengine.h | 4 +- .../rendering/renderablemodelprojection.cpp | 824 +++++++++--------- .../rendering/renderableplanetprojection.cpp | 20 +- modules/newhorizons/util/hongkangparser.cpp | 8 +- modules/newhorizons/util/hongkangparser.h | 3 +- modules/newhorizons/util/labelparser.cpp | 7 +- modules/newhorizons/util/labelparser.h | 4 +- src/network/networkengine.cpp | 52 +- 10 files changed, 489 insertions(+), 458 deletions(-) diff --git a/apps/TimelineView/mainwindow.cpp b/apps/TimelineView/mainwindow.cpp index 87c030c662..9a59501fd7 100644 --- a/apps/TimelineView/mainwindow.cpp +++ b/apps/TimelineView/mainwindow.cpp @@ -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); } diff --git a/apps/TimelineView/mainwindow.h b/apps/TimelineView/mainwindow.h index c998082e39..a8d9b9efbf 100644 --- a/apps/TimelineView/mainwindow.h +++ b/apps/TimelineView/mainwindow.h @@ -67,8 +67,7 @@ private: QTcpSocket* _socket; - bool _hasHongKangTimeline = false; - bool _hasLabelTimeline = false; + bool _isConnected = false; }; #endif // __MAINWINDOW_H__ diff --git a/include/openspace/network/networkengine.h b/include/openspace/network/networkengine.h index 4df8b2158d..1ca77d9210 100644 --- a/include/openspace/network/networkengine.h +++ b/include/openspace/network/networkengine.h @@ -53,8 +53,9 @@ public: // Background MessageIdentifier identifier(std::string name); + private: - std::map _identifiers; + std::map _identifiers; MessageIdentifier _lastAssignedIdentifier; struct Message { @@ -69,6 +70,7 @@ private: MessageIdentifier _statusMessageIdentifier; MessageIdentifier _identifierMappingIdentifier; + MessageIdentifier _initialMessageFinishedIdentifier; }; } // namespace openspace diff --git a/modules/newhorizons/rendering/renderablemodelprojection.cpp b/modules/newhorizons/rendering/renderablemodelprojection.cpp index af0244403c..573cff0d7e 100644 --- a/modules/newhorizons/rendering/renderablemodelprojection.cpp +++ b/modules/newhorizons/rendering/renderablemodelprojection.cpp @@ -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(offsetof(modelgeometry::ModelGeometry::Vertex, location))); - glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, vertexSize, - reinterpret_cast(offsetof(modelgeometry::ModelGeometry::Vertex, tex))); - glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, vertexSize, - reinterpret_cast(offsetof(modelgeometry::ModelGeometry::Vertex, normal))); + glEnableVertexAttribArray(0); + glEnableVertexAttribArray(1); + glEnableVertexAttribArray(2); + glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, vertexSize, + reinterpret_cast(offsetof(modelgeometry::ModelGeometry::Vertex, location))); + glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, vertexSize, + reinterpret_cast(offsetof(modelgeometry::ModelGeometry::Vertex, tex))); + glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, vertexSize, + reinterpret_cast(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(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(_texture->width()), static_cast(_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(_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(_rotationX), glm::vec3(1, 0, 0)); - glm::mat4 rotPropY = glm::rotate(_transform, static_cast(_rotationY), glm::vec3(0, 1, 0)); - glm::mat4 rotPropZ = glm::rotate(_transform, static_cast(_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(_stateMatrix[i][j]); - } - } - _transform = _transform * rotPropX * rotPropY * rotPropZ; - - std::string shape, instrument; - std::vector 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(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(_texture->width()), static_cast(_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(_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(_rotationX), glm::vec3(1, 0, 0)); + glm::mat4 rotPropY = glm::rotate(_transform, static_cast(_rotationY), glm::vec3(0, 1, 0)); + glm::mat4 rotPropZ = glm::rotate(_transform, static_cast(_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(_stateMatrix[i][j]); + } + } + _transform = _transform * rotPropX * rotPropY * rotPropZ; + + std::string shape, instrument; + std::vector 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 \ No newline at end of file diff --git a/modules/newhorizons/rendering/renderableplanetprojection.cpp b/modules/newhorizons/rendering/renderableplanetprojection.cpp index 8f1cf3badf..a734d25496 100644 --- a/modules/newhorizons/rendering/renderableplanetprojection.cpp +++ b/modules/newhorizons/rendering/renderableplanetprojection.cpp @@ -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); diff --git a/modules/newhorizons/util/hongkangparser.cpp b/modules/newhorizons/util/hongkangparser.cpp index 7f898f82c3..38687886a3 100644 --- a/modules/newhorizons/util/hongkangparser.cpp +++ b/modules/newhorizons/util/hongkangparser.cpp @@ -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 potentialTargets) : - - _defaultCaptureImage(absPath("${OPENSPACE_DATA}/scene/common/textures/placeholder.png")) + std::vector potentialTargets) + : _name(std::move(name)) + , _defaultCaptureImage(absPath("${OPENSPACE_DATA}/scene/common/textures/placeholder.png")) { _fileName = fileName; _spacecraft = spacecraft; diff --git a/modules/newhorizons/util/hongkangparser.h b/modules/newhorizons/util/hongkangparser.h index 9d827a03de..a91b6d14ef 100644 --- a/modules/newhorizons/util/hongkangparser.h +++ b/modules/newhorizons/util/hongkangparser.h @@ -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 potentialTargets); @@ -69,6 +69,7 @@ private: std::string _defaultCaptureImage; double _metRef = 299180517; + std::string _name; std::string _fileName; std::string _spacecraft; std::map _fileTranslation; diff --git a/modules/newhorizons/util/labelparser.cpp b/modules/newhorizons/util/labelparser.cpp index 7ca299ac99..565fc53329 100644 --- a/modules/newhorizons/util/labelparser.cpp +++ b/modules/newhorizons/util/labelparser.cpp @@ -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 diff --git a/modules/newhorizons/util/labelparser.h b/modules/newhorizons/util/labelparser.h index d4f7ada971..abfd58ba64 100644 --- a/modules/newhorizons/util/labelparser.h +++ b/modules/newhorizons/util/labelparser.h @@ -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 payload, std::vector potentialTargets); + std::string _name; std::string _fileName; std::string _spacecraft; std::map _fileTranslation; diff --git a/src/network/networkengine.cpp b/src/network/networkengine.cpp index cc32a43418..dbf4359c28 100644 --- a/src/network/networkengine.cpp +++ b/src/network/networkengine.cpp @@ -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& i : _identifiers) { + for (const std::pair& 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 buffer(bufferSize); size_t currentWritingPosition = 0; - for (const std::pair& i : _identifiers) { - std::memcpy(buffer.data() + currentWritingPosition, &(i.first), sizeof(MessageIdentifier)); + for (const std::pair& 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& 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 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 data; + } identifier; + identifier.value = _initialMessageFinishedIdentifier; + + sgct::Engine::instance()->sendMessageToExternalControl( + identifier.data.data(), + 2 + ); + _shouldPublishStatusMessage = true; } From 0e4dbbb1cc22da19c3d3061aadc3af661b76ec66 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 2 Jul 2015 15:53:25 +0200 Subject: [PATCH 2/4] Some work on the Launcher --- apps/Launcher/infowidget.cpp | 6 ++++++ apps/Launcher/infowidget.h | 1 + apps/Launcher/syncwidget.cpp | 6 +++--- data | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/apps/Launcher/infowidget.cpp b/apps/Launcher/infowidget.cpp index 45395903bc..11ea196638 100644 --- a/apps/Launcher/infowidget.cpp +++ b/apps/Launcher/infowidget.cpp @@ -36,6 +36,7 @@ InfoWidget::InfoWidget(QString name, int totalBytes) , _bytes(nullptr) , _progress(nullptr) , _messagesLeft(nullptr) + , _messagesCenter(nullptr) , _messagesRight(nullptr) , _totalBytes(totalBytes) { @@ -56,9 +57,11 @@ InfoWidget::InfoWidget(QString name, int totalBytes) layout->addWidget(_progress, 1, 1); _messagesLeft = new QLabel(""); + _messagesCenter = new QLabel(""); _messagesRight = new QLabel(""); layout->addWidget(_messagesLeft, 2, 0, 1, 2); + layout->addWidget(_messagesCenter, 2, 0, 1, 2, Qt::AlignCenter); layout->addWidget(_messagesRight, 2, 0, 1, 2, Qt::AlignRight); setLayout(layout); @@ -99,6 +102,9 @@ void InfoWidget::update(libtorrent::torrent_status s) { QString left = "Time remaining %1 s"; _messagesLeft->setText(left.arg(static_cast(seconds))); + QString center = "Peers: %1 (%2) | Seeds: %3 (%4)"; + _messagesCenter->setText(center.arg(s.num_peers).arg(s.list_peers).arg(s.num_seeds).arg(s.list_seeds)); + QString right = "Download Rate: %1 KiB/s"; _messagesRight->setText(right.arg(bytesPerSecond / 1024)); } diff --git a/apps/Launcher/infowidget.h b/apps/Launcher/infowidget.h index e2d42f9e4a..2cf9d1f5da 100644 --- a/apps/Launcher/infowidget.h +++ b/apps/Launcher/infowidget.h @@ -52,6 +52,7 @@ private: QLabel* _bytes; QProgressBar* _progress; QLabel* _messagesLeft; + QLabel* _messagesCenter; QLabel* _messagesRight; int _totalBytes; diff --git a/apps/Launcher/syncwidget.cpp b/apps/Launcher/syncwidget.cpp index 7f6540f696..6ad5409e4f 100644 --- a/apps/Launcher/syncwidget.cpp +++ b/apps/Launcher/syncwidget.cpp @@ -117,7 +117,7 @@ SyncWidget::SyncWidget(QWidget* parent, Qt::WindowFlags f) openspace::DownloadManager::initialize("http://openspace.itn.liu.se/data/request", DownloadApplicationVersion); libtorrent::error_code ec; - _session->listen_on(std::make_pair(20285, 20285), ec); + _session->listen_on(std::make_pair(20280, 20290), ec); if (ec) { LFATAL("Failed to open socket: " << ec.message()); return; @@ -125,9 +125,9 @@ SyncWidget::SyncWidget(QWidget* parent, Qt::WindowFlags f) _session->start_upnp(); _session->start_dht(); - _session->add_dht_router({ "dht.transmissionbt.com", 6881}); - _session->add_dht_router({ "router.bittorrent.com", 6881}); _session->add_dht_router({ "router.utorrent.com", 6881 }); + _session->add_dht_router({ "dht.transmissionbt.com", 6881 }); + _session->add_dht_router({ "router.bittorrent.com", 6881 }); _session->add_dht_router({ "router.bitcomet.com", 6881 }); QTimer* timer = new QTimer(this); diff --git a/data b/data index fa00aaa0c2..e234fc3176 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit fa00aaa0c244e8e5709877a344c3007d2244e9ec +Subproject commit e234fc317660bf8b593a23ca505892a44a17d70e From 304a328cdee0e3791c8791852db80bfd4eec7745 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Fri, 3 Jul 2015 00:00:48 +0200 Subject: [PATCH 3/4] Let TimelineView handle multiple instances of Labelparser and HongkangParsers --- apps/TimelineView/mainwindow.cpp | 64 +++++++++++++++++++++++++++----- apps/TimelineView/mainwindow.h | 3 +- src/network/networkengine.cpp | 20 +++++++--- 3 files changed, 71 insertions(+), 16 deletions(-) diff --git a/apps/TimelineView/mainwindow.cpp b/apps/TimelineView/mainwindow.cpp index 9a59501fd7..6fdc04fc4e 100644 --- a/apps/TimelineView/mainwindow.cpp +++ b/apps/TimelineView/mainwindow.cpp @@ -37,6 +37,10 @@ #include #include +namespace { + QByteArray continuousData; +} + template T readFromBuffer(char* buffer, size_t& currentReadLocation) { union { @@ -128,16 +132,25 @@ void MainWindow::onDisconnect() { void MainWindow::readTcpData() { static const uint16_t MessageTypeStatus = 0; - static const uint16_t MessageTypePlayBookHongKang = 2; + static const uint16_t MessageTypeMappingIdentifier = 1; + static const uint16_t MessageTypeInitialMessageFinished = 2; static const uint16_t MessageTypePlayBookLabel = 3; - static const uint16_t MessageTypeInitialMessageFinished = 4; + static const uint16_t MessageTypePlayBookHongKang = 4; - QByteArray data = _socket->readAll(); + QByteArray data = continuousData.append(_socket->readAll()); + int d = data.size(); - if (QString(data) == "Connected to SGCT!\r\n") + if (data.size() != 42) + qDebug() << QString(data); + + if (QString(data) == "Connected to SGCT!\r\n") { + continuousData.clear(); return; - if (QString(data) == "OK\r\n") + } + if (QString(data) == "OK\r\n") { + continuousData.clear(); return; + } QByteArray messageTypeData = data.left(2); union { @@ -149,6 +162,14 @@ void MainWindow::readTcpData() { switch (messageType.value) { case MessageTypeStatus: break; + case MessageTypeMappingIdentifier: + qDebug() << "Mapping Identifier received"; + printMapping(data.mid(2)); + continuousData.clear(); + break; + case MessageTypeInitialMessageFinished: + qDebug() << "InitialMessageFinished received"; + break; case MessageTypePlayBookHongKang: qDebug() << "Hong Kang Playbook received"; break; @@ -164,6 +185,7 @@ void MainWindow::readTcpData() { { if (_isConnected) handleStatusMessage(data.mid(2)); + continuousData.clear(); break; } case MessageTypePlayBookHongKang: @@ -177,13 +199,16 @@ void MainWindow::readTcpData() { //qDebug() << "Begin reading data"; while (_socket->waitForReadyRead() && data.size() < int(size)) { //qDebug() << "."; + //_socket->read + //data = data.append(_socket->re) data = data.append(_socket->readAll()); //data = data.append(_socket->read(int(size) - data.size())); - QThread::msleep(50); + //QThread::msleep(50); } //qDebug() << "Finished reading data. Handling playbook"; - handlePlaybook(data.mid(2)); + continuousData = handlePlaybook(data.mid(2)); + //qDebug() << "Finished handling playbook"; @@ -201,6 +226,7 @@ void MainWindow::readTcpData() { case MessageTypeInitialMessageFinished: _isConnected = true; fullyConnected(); + continuousData.clear(); break; default: @@ -248,7 +274,7 @@ std::vector instrumentsFromId(uint16_t instrumentId, std::mapsetData(std::move(images), std::move(targetMap), std::move(instrumentMap)); + auto dataSize = data.size(); + auto readSize = currentReadLocation; + auto extraBytes = dataSize - readSize; + if (extraBytes > 0) + return data.mid(currentReadLocation); + else + return QByteArray(); } void MainWindow::sendScript(QString script) { @@ -336,3 +368,17 @@ void MainWindow::fullyConnected() { _informationWidget->socketConnected(); _timelineWidget->socketConnected(); } + +void MainWindow::printMapping(QByteArray data) { + char* buffer = data.data(); + size_t currentReadPosition = 0; + + uint16_t size = readFromBuffer(buffer, currentReadPosition); + for (uint16_t i = 0; i < size; ++i) { + uint16_t identifier = readFromBuffer(buffer, currentReadPosition); + std::string mapping = readFromBuffer(buffer, currentReadPosition); + + qDebug() << identifier << ": " << QString::fromStdString(mapping); + + } +} diff --git a/apps/TimelineView/mainwindow.h b/apps/TimelineView/mainwindow.h index a8d9b9efbf..126dc314cf 100644 --- a/apps/TimelineView/mainwindow.h +++ b/apps/TimelineView/mainwindow.h @@ -55,7 +55,8 @@ private slots: void readTcpData(); void handleStatusMessage(QByteArray data); - void handlePlaybook(QByteArray data); + QByteArray handlePlaybook(QByteArray data); + void printMapping(QByteArray data); void fullyConnected(); diff --git a/src/network/networkengine.cpp b/src/network/networkengine.cpp index dbf4359c28..747a78083a 100644 --- a/src/network/networkengine.cpp +++ b/src/network/networkengine.cpp @@ -74,6 +74,8 @@ bool NetworkEngine::handleMessage(const std::string& message) { } case MessageTypeExternalControlConnected: { + publishIdentifierMappingMessage(); + std::this_thread::sleep_for(std::chrono::milliseconds(250)); sendInitialInformation(); return true; } @@ -118,7 +120,7 @@ void NetworkEngine::publishStatusMessage() { } void NetworkEngine::publishIdentifierMappingMessage() { - size_t bufferSize = 0; + size_t bufferSize = sizeof(uint16_t); for (const std::pair& i : _identifiers) { bufferSize += sizeof(MessageIdentifier); bufferSize += i.first.size() + 1; // +1 for \0 terminating character @@ -126,13 +128,17 @@ void NetworkEngine::publishIdentifierMappingMessage() { std::vector buffer(bufferSize); size_t currentWritingPosition = 0; + uint16_t size = _identifiers.size(); + std::memcpy(buffer.data(), &size, sizeof(uint16_t)); + currentWritingPosition += sizeof(uint16_t); for (const std::pair& i : _identifiers) { std::memcpy(buffer.data() + currentWritingPosition, &(i.second), sizeof(MessageIdentifier)); currentWritingPosition += sizeof(MessageIdentifier); - std::memcpy(buffer.data() + currentWritingPosition, i.first.data(), i.first.size()); + uint8_t stringSize = i.first.size(); + std::memcpy(buffer.data() + currentWritingPosition, &stringSize, sizeof(uint8_t)); + currentWritingPosition += sizeof(uint8_t); + std::memcpy(buffer.data() + currentWritingPosition, i.first.data(), stringSize); currentWritingPosition += i.first.size(); - buffer[currentWritingPosition] = '\0'; - currentWritingPosition += 1; } publishMessage(_identifierMappingIdentifier, std::move(buffer)); @@ -178,13 +184,14 @@ void NetworkEngine::sendMessages() { m.body.data(), static_cast(m.body.size()) ); + //LINFO("Sent message: (s=" << m.body.size() << "): " << std::string(m.body.begin(), m.body.end())); } _messagesToSend.clear(); } void NetworkEngine::sendInitialInformation() { - static const int SleepTime = 100; + static const int SleepTime = 250; _shouldPublishStatusMessage = false; for (const Message& m : _initialConnectionMessages) { union { @@ -199,11 +206,12 @@ void NetworkEngine::sendInitialInformation() { payload.data(), static_cast(payload.size()) ); + LINFO("Sent initial message: (s=" << m.body.size() << ") [i=" << identifier.value << "]"); std::this_thread::sleep_for(std::chrono::milliseconds(SleepTime)); } - std::this_thread::sleep_for(std::chrono::milliseconds(SleepTime)); + std::this_thread::sleep_for(std::chrono::milliseconds(4 * SleepTime)); // Send finished message union { From 2397a28d49c52865d139f843fa7ebbb75426dd1f Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Fri, 3 Jul 2015 00:40:49 +0200 Subject: [PATCH 4/4] Set Launcher's information widget to readonly --- apps/Launcher/mainwindow.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/Launcher/mainwindow.cpp b/apps/Launcher/mainwindow.cpp index c186e6c36c..53f08c04f3 100644 --- a/apps/Launcher/mainwindow.cpp +++ b/apps/Launcher/mainwindow.cpp @@ -90,6 +90,7 @@ MainWindow::MainWindow() _informationWidget = new QTextEdit(this); _informationWidget->setReadOnly(true); + _informationWidget->setEnabled(false); layout->addWidget(_informationWidget, 1, 0, 2, 1); QWidget* container = new QWidget;