mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-22 12:59:07 -06:00
Merge branch 'develop' into feature/remote
This commit is contained in:
@@ -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<int>(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));
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ private:
|
||||
QLabel* _bytes;
|
||||
QProgressBar* _progress;
|
||||
QLabel* _messagesLeft;
|
||||
QLabel* _messagesCenter;
|
||||
QLabel* _messagesRight;
|
||||
|
||||
int _totalBytes;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -37,6 +37,10 @@
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
|
||||
namespace {
|
||||
QByteArray continuousData;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T readFromBuffer(char* buffer, size_t& currentReadLocation) {
|
||||
union {
|
||||
@@ -128,15 +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 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 {
|
||||
@@ -148,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;
|
||||
@@ -161,8 +183,9 @@ void MainWindow::readTcpData() {
|
||||
switch (messageType.value) {
|
||||
case MessageTypeStatus:
|
||||
{
|
||||
if (_hasHongKangTimeline && _hasLabelTimeline)
|
||||
if (_isConnected)
|
||||
handleStatusMessage(data.mid(2));
|
||||
continuousData.clear();
|
||||
break;
|
||||
}
|
||||
case MessageTypePlayBookHongKang:
|
||||
@@ -176,27 +199,36 @@ 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";
|
||||
|
||||
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();
|
||||
continuousData.clear();
|
||||
break;
|
||||
|
||||
default:
|
||||
qDebug() << QString(data);
|
||||
}
|
||||
@@ -242,7 +274,7 @@ std::vector<std::string> instrumentsFromId(uint16_t instrumentId, std::map<uint1
|
||||
return results;
|
||||
}
|
||||
|
||||
void MainWindow::handlePlaybook(QByteArray data) {
|
||||
QByteArray MainWindow::handlePlaybook(QByteArray data) {
|
||||
char* buffer = data.data();
|
||||
size_t currentReadLocation = 0;
|
||||
|
||||
@@ -286,9 +318,15 @@ void MainWindow::handlePlaybook(QByteArray data) {
|
||||
qDebug() << "Instruments were empty";
|
||||
images.push_back(image);
|
||||
}
|
||||
|
||||
_timelineWidget->setData(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) {
|
||||
@@ -330,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<uint16_t>(buffer, currentReadPosition);
|
||||
for (uint16_t i = 0; i < size; ++i) {
|
||||
uint16_t identifier = readFromBuffer<uint16_t>(buffer, currentReadPosition);
|
||||
std::string mapping = readFromBuffer<std::string>(buffer, currentReadPosition);
|
||||
|
||||
qDebug() << identifier << ": " << QString::fromStdString(mapping);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -67,8 +68,7 @@ private:
|
||||
|
||||
QTcpSocket* _socket;
|
||||
|
||||
bool _hasHongKangTimeline = false;
|
||||
bool _hasLabelTimeline = false;
|
||||
bool _isConnected = false;
|
||||
};
|
||||
|
||||
#endif // __MAINWINDOW_H__
|
||||
|
||||
2
data
2
data
Submodule data updated: fa00aaa0c2...e234fc3176
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
@@ -72,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;
|
||||
}
|
||||
@@ -116,21 +120,25 @@ void NetworkEngine::publishStatusMessage() {
|
||||
}
|
||||
|
||||
void NetworkEngine::publishIdentifierMappingMessage() {
|
||||
size_t bufferSize = 0;
|
||||
for (const std::pair<MessageIdentifier, std::string>& i : _identifiers) {
|
||||
size_t bufferSize = sizeof(uint16_t);
|
||||
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));
|
||||
uint16_t size = _identifiers.size();
|
||||
std::memcpy(buffer.data(), &size, sizeof(uint16_t));
|
||||
currentWritingPosition += sizeof(uint16_t);
|
||||
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();
|
||||
buffer[currentWritingPosition] = '\0';
|
||||
currentWritingPosition += 1;
|
||||
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();
|
||||
}
|
||||
|
||||
publishMessage(_identifierMappingIdentifier, std::move(buffer));
|
||||
@@ -138,21 +146,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) {
|
||||
@@ -180,13 +184,14 @@ void NetworkEngine::sendMessages() {
|
||||
m.body.data(),
|
||||
static_cast<int>(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 {
|
||||
@@ -201,10 +206,25 @@ void NetworkEngine::sendInitialInformation() {
|
||||
payload.data(),
|
||||
static_cast<int>(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(4 * 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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user