Merge branch 'feature/timelinegui' into develop

This commit is contained in:
Alexander Bock
2015-05-05 14:22:56 +02:00
87 changed files with 5661 additions and 593 deletions

4
.gitignore vendored
View File

@@ -30,3 +30,7 @@ shaders/ABuffer/constants.hglsl
LuaScripting.txt
Properties.txt
log.html
gui/externaltimecontrol/CMakeLists.txt
gui/externaltimecontrol/main.cpp
gui/externaltimecontrol/mainwindow.cpp
gui/externaltimecontrol/mainwindow.h

View File

@@ -145,8 +145,7 @@ endif ()
#########################################################################################
add_subdirectory(src)
#add_subdirectory(tests)
#add_subdirectory(gui)
add_subdirectory(gui)
#########################################################################################
# File Fetch

View File

@@ -31,6 +31,6 @@
</Window>
</Node>
<User eyeSeparation="0.065">
<Pos x="0.0" y="0.0" z="4.0" />
<Pos x="0.0" y="0.0" z="2.0" />
</User>
</Cluster>

View File

@@ -1,3 +1,4 @@
cmake_minimum_required(VERSION 2.8.11)
add_subdirectory(luascriptexternalcontrol)
add_subdirectory(luascriptexternalcontrol)
add_subdirectory(timelineview)

View File

@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 2.8.11)
project(TimelineView)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
find_package(Qt5Widgets)
find_package(Qt5Network)
add_executable(TimelineView main.cpp mainwindow.cpp configurationwidget.cpp informationwidget.cpp controlwidget.cpp timelinewidget.cpp)
target_link_libraries(TimelineView Qt5::Widgets Qt5::Network)

37
gui/timelineview/common.h Normal file
View File

@@ -0,0 +1,37 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2015 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __COMMON_H__
#define __COMMON_H__
struct Image {
double beginning;
double ending;
std::string beginningString;
std::string endingString;
std::string target;
std::vector<std::string> instruments;
};
#endif // __COMMON_H__

View File

@@ -0,0 +1,54 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2015 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include "configurationwidget.h"
#include <QGridLayout>
ConfigurationWidget::ConfigurationWidget(QWidget* parent)
: QWidget(parent)
, _ipAddress(new QLineEdit("localhost"))
, _port(new QLineEdit("20500"))
, _connect(new QPushButton("Connect"))
{
QGridLayout* layout = new QGridLayout;
layout->addWidget(_ipAddress, 0, 0);
layout->addWidget(_port, 0, 1);
layout->addWidget(_connect, 0, 2);
setLayout(layout);
QObject::connect(_connect, SIGNAL(clicked()), this, SLOT(onConnectButton()));
}
void ConfigurationWidget::onConnectButton() {
emit connect(_ipAddress->text(), _port->text());
}
void ConfigurationWidget::socketConnected() {
}
void ConfigurationWidget::socketDisconnected() {
}

View File

@@ -0,0 +1,52 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2015 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __CONFIGURATIONWIDGET_H__
#define __CONFIGURATIONWIDGET_H__
#include <QWidget>
#include <QLineEdit>
#include <QPushButton>
class ConfigurationWidget : public QWidget {
Q_OBJECT
public:
ConfigurationWidget(QWidget* parent);
void socketConnected();
void socketDisconnected();
signals:
void connect(QString host, QString port);
private slots:
void onConnectButton();
private:
QLineEdit* _ipAddress;
QLineEdit* _port;
QPushButton* _connect;
};
#endif // __CONFIGURATIONWIDGET_H__

View File

@@ -0,0 +1,222 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2015 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include "controlwidget.h"
#include <QComboBox>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QSlider>
namespace {
struct ImportantDate {
QString date;
QString focus;
QString coordinateSystem;
};
const ImportantDate ImportantDates[] = {
{ "2007-02-27T16:40:00.00", "JupiterProjection", "Jupiter" },
{ "2015-07-14T10:50:00.00", "PlutoProjection", "Pluto" },
{ "2015-07-14T11:22:00.00", "PlutoProjection", "Pluto" },
{ "2015-07-14T11:36:40.00", "PlutoProjection", "Pluto" },
{ "2015-07-14T11:48:43.00", "PlutoProjection", "Pluto" },
{ "2015-07-14T12:04:35.00", "PlutoProjection", "Pluto" },
{ "2015-07-14T15:02:46.00", "PlutoProjection", "Pluto" }
};
struct FocusNode {
QString guiName;
QString name;
QString coordinateSystem;
};
const FocusNode FocusNodes[] = {
{ "Earth", "Earth", "Sun" },
{ "Sun", "Sun", "Sun" },
{ "Pluto", "PlutoProjection", "Pluto" },
{ "Charon", "Charon", "Pluto" },
{ "Jupiter", "JupiterProjection", "Jupiter" },
{ "New Horizons", "NewHorizons", ""}
};
}
ControlWidget::ControlWidget(QWidget* parent)
: QWidget(parent)
, _currentTime(new QLabel("Current Time"))
, _setTime(new QComboBox)
, _currentDelta(new QLabel("Current Delta"))
, _setDelta(new QSlider(Qt::Horizontal))
, _rewind(new QPushButton("<<"))
, _pause(new QPushButton("||"))
, _play(new QPushButton("|>"))
, _forward(new QPushButton(">>"))
, _focusNode(new QComboBox)
{
for (const ImportantDate& d : ImportantDates)
_setTime->addItem(d.date);
QObject::connect(
_setTime,
SIGNAL(currentIndexChanged(int)),
this,
SLOT(onDateChange())
);
for (const FocusNode& f : FocusNodes)
_focusNode->addItem(f.guiName);
QObject::connect(
_focusNode,
SIGNAL(currentIndexChanged(int)),
this,
SLOT(onFocusChange())
);
_setDelta->setMinimum(-100);
_setDelta->setMaximum(100);
_setDelta->setValue(0);
QObject::connect(
_setDelta,
SIGNAL(valueChanged(int)),
this,
SLOT(onValueChange())
);
QObject::connect(
_rewind,
SIGNAL(clicked()),
this,
SLOT(onRewindButton())
);
QObject::connect(
_pause,
SIGNAL(clicked()),
this,
SLOT(onPauseButton())
);
QObject::connect(
_play,
SIGNAL(clicked()),
this,
SLOT(onPlayButton())
);
QObject::connect(
_forward,
SIGNAL(clicked()),
this,
SLOT(onForwardButton())
);
QGridLayout* layout = new QGridLayout;
layout->addWidget(_currentTime, 0, 0);
layout->addWidget(_setTime, 0, 1);
layout->addWidget(_currentDelta, 1, 0);
layout->addWidget(_setDelta, 2, 0, 1, 2);
QWidget* controlContainer = new QWidget;
QHBoxLayout* controlContainerLayout = new QHBoxLayout;
controlContainerLayout->addWidget(_rewind);
controlContainerLayout->addWidget(_pause);
controlContainerLayout->addWidget(_play);
controlContainerLayout->addWidget(_forward);
controlContainer->setLayout(controlContainerLayout);
layout->addWidget(controlContainer, 3, 0, 1, 2);
layout->addWidget(_focusNode, 4, 0, 1, 2);
setLayout(layout);
}
void ControlWidget::update(QString currentTime, QString currentDelta) {
_currentTime->setText(currentTime);
_currentDelta->setText(currentDelta);
}
void ControlWidget::onValueChange() {
QString script = "openspace.time.setDeltaTime(" + QString::number(_setDelta->value()) + ");";
emit scriptActivity(script);
}
void ControlWidget::onRewindButton() {
QString script = "openspace.time.setDeltaTime(-openspace.time.deltaTime());";
emit scriptActivity(script);
}
void ControlWidget::onPauseButton() {
QString script = "openspace.time.setPause(true);";
emit scriptActivity(script);
}
void ControlWidget::onPlayButton() {
QString script = "openspace.time.setPause(false);";
emit scriptActivity(script);
}
void ControlWidget::onForwardButton() {
QString script = "openspace.time.setDeltaTime(-openspace.time.deltaTime());";
emit scriptActivity(script);
}
void ControlWidget::onDateChange() {
int index = _setTime->currentIndex();
QString date = ImportantDates[index].date;
QString focus = ImportantDates[index].focus;
QString coordinateSystem = ImportantDates[index].coordinateSystem;
QString script =
"openspace.time.setTime('" + date + "');\
openspace.setOrigin('" + focus + "');\
openspace.changeCoordinateSystem('" + coordinateSystem + "');";
emit scriptActivity(script);
}
void ControlWidget::onFocusChange() {
int index = _focusNode->currentIndex();
QString name = FocusNodes[index].name;
QString coordinateSystem = FocusNodes[index].coordinateSystem;
if (coordinateSystem.isEmpty()) {
int date = _currentTime->text().left(4).toInt();
if (date < 2008)
coordinateSystem = "Jupiter";
else if (date < 2014)
coordinateSystem = "Sun";
else
coordinateSystem = "Pluto";
}
QString script = "openspace.setOrigin('" + name + "');openspace.changeCoordinateSystem('" + coordinateSystem + "');";
emit scriptActivity(script);
}
void ControlWidget::socketConnected() {
setDisabled(false);
}
void ControlWidget::socketDisconnected() {
setDisabled(true);
}

View File

@@ -0,0 +1,69 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2015 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __CONTROLWIDGET_H__
#define __CONTROLWIDGET_H__
#include <QWidget>
class QComboBox;
class QLabel;
class QPushButton;
class QSlider;
class ControlWidget : public QWidget {
Q_OBJECT
public:
ControlWidget(QWidget* parent);
void update(QString currentTime, QString currentDelta);
void socketConnected();
void socketDisconnected();
signals:
void scriptActivity(QString script);
private slots:
void onValueChange();
void onDateChange();
void onFocusChange();
void onRewindButton();
void onPauseButton();
void onPlayButton();
void onForwardButton();
private:
QLabel* _currentTime;
QComboBox* _setTime;
QLabel* _currentDelta;
QSlider* _setDelta;
QPushButton* _rewind;
QPushButton* _pause;
QPushButton* _play;
QPushButton* _forward;
QComboBox* _focusNode;
};
#endif // __CONTROLWIDGET_H__

View File

@@ -0,0 +1,41 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2015 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include "informationwidget.h"
#include <QLayout>
#include <QTextEdit>
InformationWidget::InformationWidget(QWidget* parent)
: QTextEdit(parent)
{
}
void InformationWidget::socketConnected() {
setDisabled(false);
}
void InformationWidget::socketDisconnected() {
setDisabled(true);
}

View File

@@ -0,0 +1,38 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2015 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __INFORMATIONWIDGET_H__
#define __INFORMATIONWIDGET_H__
#include <QTextEdit>
class InformationWidget : public QTextEdit {
Q_OBJECT
public:
InformationWidget(QWidget* parent);
void socketConnected();
void socketDisconnected();
};
#endif // __INFORMATIONWIDGET_H__

35
gui/timelineview/main.cpp Normal file
View File

@@ -0,0 +1,35 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <QApplication>
#include "mainwindow.h"
int main(int argc, char** argv) {
QApplication app(argc, argv);
MainWindow window;
window.show();
return app.exec();
}

View File

@@ -0,0 +1,268 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include "mainwindow.h"
#include "configurationwidget.h"
#include "controlwidget.h"
#include "informationwidget.h"
#include "timelinewidget.h"
#include <QGridLayout>
#include <QPushButton>
#include <QTextEdit>
#include <array>
#include <cstdint>
template <typename T>
T readFromBuffer(char* buffer, size_t& currentReadLocation) {
union {
T value;
std::array<char, sizeof(T)> data;
} b;
std::memmove(b.data.data(), buffer + currentReadLocation, sizeof(T));
currentReadLocation += sizeof(T);
return b.value;
}
template <>
std::string readFromBuffer(char* buffer, size_t& currentReadLocation) {
uint8_t size = readFromBuffer<uint8_t>(buffer, currentReadLocation);
std::string result(buffer + currentReadLocation, buffer + currentReadLocation + size);
currentReadLocation += size;
return result;
}
MainWindow::MainWindow()
: QWidget(nullptr)
, _configurationWidget(nullptr)
, _timeControlWidget(nullptr)
, _informationWidget(nullptr)
, _timelineWidget(nullptr)
, _socket(nullptr)
{
setWindowTitle("OpenSpace Timeline");
_configurationWidget = new ConfigurationWidget(this);
_timeControlWidget = new ControlWidget(this);
_informationWidget = new InformationWidget(this);
_timelineWidget = new TimelineWidget(this);
QGridLayout* layout = new QGridLayout;
layout->addWidget(_configurationWidget, 0, 0);
layout->addWidget(_timeControlWidget, 1, 0);
layout->addWidget(_informationWidget, 2, 0);
layout->addWidget(_timelineWidget, 0, 1, 3, 1);
QObject::connect(
_configurationWidget, SIGNAL(connect(QString, QString)),
this, SLOT(onConnect(QString, QString))
);
QObject::connect(
_timeControlWidget, SIGNAL(scriptActivity(QString)),
this, SLOT(sendScript(QString))
);
setLayout(layout);
_configurationWidget->socketDisconnected();
_timeControlWidget->socketDisconnected();
_informationWidget->socketDisconnected();
_timelineWidget->socketDisconnected();
}
MainWindow::~MainWindow() {
delete _socket;
}
void MainWindow::onConnect(QString host, QString port) {
delete _socket;
_socket = new QTcpSocket(this);
QObject::connect(_socket, SIGNAL(readyRead()), SLOT(readTcpData()));
QObject::connect(_socket, SIGNAL(connected()), SLOT(onSocketConnected()));
QObject::connect(_socket, SIGNAL(disconnected()), SLOT(onSocketDisconnected()));
_socket->connectToHost(host, port.toUInt());
}
void MainWindow::readTcpData() {
static const uint16_t MessageTypeStatus = 0;
static const uint16_t MessageTypePlayBook = 2;
QByteArray data = _socket->readAll();
//QString debug(data);
//qDebug() << debug;
if (QString(data) == "Connected to SGCT!\r\n")
return;
if (QString(data) == "OK\r\n")
return;
QByteArray messageTypeData = data.left(2);
union {
uint16_t value;
std::array<char, 2> data;
} messageType;
std::memcpy(messageType.data.data(), messageTypeData.data(), sizeof(uint16_t));
switch (messageType.value) {
case MessageTypeStatus:
handleStatusMessage(data.mid(2));
break;
case MessageTypePlayBook:
{
const char* payloadDebug = data.mid(2).data();
size_t beginning = 0;
uint32_t size = readFromBuffer<uint32_t>(data.mid(2).data(), beginning);
while (_socket->waitForReadyRead() && data.size() < size) {
//while (data.size() < size) {
data = data.append(_socket->readAll());
}
handlePlaybook(data.mid(2));
break;
}
default:
qDebug() << "Unknown message of type '" << messageType.value << "'";
}
}
void MainWindow::handleStatusMessage(QByteArray data) {
const char* buffer = data.data();
union {
double value;
std::array<char, 8> buffer;
} et;
std::memmove(et.buffer.data(), buffer, sizeof(double));
std::vector<char> timeString(24);
std::memmove(timeString.data(), buffer + sizeof(double), 24);
union {
double value;
std::array<char, 8> buffer;
} delta;
std::memmove(delta.buffer.data(), buffer + sizeof(double) + 24, sizeof(double));
_timeControlWidget->update(
QString::fromStdString(std::string(timeString.begin(), timeString.end())),
QString::number(delta.value)
);
_timelineWidget->setCurrentTime(std::string(timeString.begin(), timeString.end()), et.value);
}
std::vector<std::string> instrumentsFromId(uint16_t instrumentId, std::map<uint16_t, std::string> instrumentMap) {
std::vector<std::string> results;
for (int i = 0; i < 16; ++i) {
uint16_t testValue = 1 << i;
if ((testValue & instrumentId) != 0) {
std::string t = instrumentMap.at(testValue);
if (t.empty())
qDebug() << "Empty instrument";
results.push_back(t);
}
}
return results;
}
void MainWindow::handlePlaybook(QByteArray data) {
char* buffer = data.data();
size_t currentReadLocation = 0;
uint32_t totalData = readFromBuffer<uint32_t>(buffer, currentReadLocation);
uint8_t nTargets = readFromBuffer<uint8_t>(buffer, currentReadLocation);
qDebug() << "Targets: " << nTargets;
std::map<uint8_t, std::string> targetMap;
for (uint8_t i = 0; i < nTargets; ++i) {
uint8_t id = readFromBuffer<uint8_t>(buffer, currentReadLocation);
std::string value = readFromBuffer<std::string>(buffer, currentReadLocation);
qDebug() << QString::fromStdString(value);
targetMap[id] = value;
}
uint8_t nInstruments = readFromBuffer<uint8_t>(buffer, currentReadLocation);
qDebug() << "Instruments: " << nInstruments;
std::map<uint16_t, std::string> instrumentMap;
for (uint8_t i = 0; i < nInstruments; ++i) {
uint16_t id = readFromBuffer<uint16_t>(buffer, currentReadLocation);
std::string value = readFromBuffer<std::string>(buffer, currentReadLocation);
qDebug() << QString::fromStdString(value);
instrumentMap[id] = value;
}
uint32_t nImages = readFromBuffer<uint32_t>(buffer, currentReadLocation);
std::vector<Image> images;
for (uint32_t i = 0; i < nImages; ++i) {
Image image;
image.beginning = readFromBuffer<double>(buffer, currentReadLocation);
image.ending = readFromBuffer<double>(buffer, currentReadLocation);
image.beginningString = readFromBuffer<std::string>(buffer, currentReadLocation);
image.endingString = readFromBuffer<std::string>(buffer, currentReadLocation);
uint8_t targetId = readFromBuffer<uint8_t>(buffer, currentReadLocation);
uint16_t instrumentId = readFromBuffer<uint16_t>(buffer, currentReadLocation);
image.target = targetMap[targetId];
image.instruments = instrumentsFromId(instrumentId, instrumentMap);
if (image.instruments.empty())
qDebug() << "Instruments were empty";
images.push_back(image);
}
_timelineWidget->setData(std::move(images), std::move(targetMap), std::move(instrumentMap));
_configurationWidget->socketConnected();
_timeControlWidget->socketConnected();
_informationWidget->socketConnected();
_timelineWidget->socketConnected();
}
void MainWindow::sendScript(QString script) {
if (_socket)
_socket->write(("0" + script + "\r\n").toLatin1());
}
void MainWindow::onSocketConnected() {
_socket->write(QString("1\r\n").toLatin1());
}
void MainWindow::onSocketDisconnected() {
_configurationWidget->socketDisconnected();
_timeControlWidget->socketDisconnected();
_informationWidget->socketDisconnected();
_timelineWidget->socketDisconnected();
}

View File

@@ -0,0 +1,68 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __MAINWINDOW_H__
#define __MAINWINDOW_H__
#include <QWidget>
#include <QTcpSocket>
#include "common.h"
class ConfigurationWidget;
class ControlWidget;
class InformationWidget;
class TimelineWidget;
class MainWindow : public QWidget {
Q_OBJECT
public:
MainWindow();
~MainWindow();
public slots:
void sendScript(QString script);
private slots:
void onConnect(QString host, QString port);
void onSocketConnected();
void onSocketDisconnected();
//void onConnectButton();
//void sendCommandButton();
void readTcpData();
void handleStatusMessage(QByteArray data);
void handlePlaybook(QByteArray data);
private:
ConfigurationWidget* _configurationWidget;
ControlWidget* _timeControlWidget;
InformationWidget* _informationWidget;
TimelineWidget* _timelineWidget;
QTcpSocket* _socket;
};
#endif // __MAINWINDOW_H__

View File

@@ -0,0 +1,260 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2015 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include "timelinewidget.h"
#include <QDebug>
#include <QPainter>
#include <QPaintEvent>
#include <iostream>
#include <set>
namespace {
static const int LegendHeight = 105;
static const int TimeWidth = 200;
static const int TextOffset = 5;
//const QColor targetColors[] = {
// QColor(251, 180, 174),
// QColor(179, 205, 227),
// QColor(204, 235, 197),
// QColor(222, 203, 228),
// QColor(254, 217, 166),
// QColor(255, 255, 204)
//};
const QColor instrumentColors[] = {
QColor(228, 26, 28),
QColor(55, 126, 184),
QColor(77, 175, 74),
QColor(152, 78, 163),
QColor(255, 127, 0),
QColor(255, 255, 51),
QColor(166, 86, 40),
QColor(247, 129, 191),
QColor(153, 153, 153),
};
const double etSpread = 100.0;
}
TimelineWidget::TimelineWidget(QWidget* parent)
: QWidget(parent)
{
setMinimumWidth(600);
setMinimumHeight(600);
}
void TimelineWidget::paintEvent(QPaintEvent* event) {
QPainter painter(this);
QRectF fullRect = contentsRect();
QRectF contentRect(0, 0, fullRect.width() - 1, fullRect.height() - LegendHeight);
QRectF legendRect(0, fullRect.bottom() - LegendHeight, fullRect.right(), fullRect.bottom());
painter.save();
drawContent(painter, contentRect);
painter.restore();
painter.save();
painter.translate(0, fullRect.height() - LegendHeight);
drawLegend(painter, QRectF(legendRect));
painter.restore();
}
void TimelineWidget::setData(std::vector<Image> images, std::map<uint8_t, std::string> targetMap, std::map<uint16_t, std::string> instrumentMap) {
_images = std::move(images);
std::sort(_images.begin(), _images.end(), [](const Image& a, const Image& b) { return a.beginning < b.beginning; });
_targetMap = std::move(targetMap);
_instrumentMap = std::move(instrumentMap);
_instruments.clear();
std::set<std::string> instruments;
for (auto p : _instrumentMap)
instruments.insert(p.second);
std::copy(instruments.begin(), instruments.end(), std::back_inserter(_instruments));
_targets.clear();
std::set<std::string> targets;
for (auto p : _targetMap)
targets.insert(p.second);
std::copy(targets.begin(), targets.end(), std::back_inserter(_targets));
repaint();
}
void TimelineWidget::drawContent(QPainter& painter, QRectF rect) {
QRectF timelineRect(0, 0, rect.width() - TimeWidth, rect.height());
QRectF dateRect(rect.width() - TimeWidth, 0, TimeWidth, rect.height());
// Draw background
painter.setBrush(QBrush(Qt::white)); painter.drawRect(timelineRect);
painter.setBrush(QBrush(Qt::gray)); painter.drawRect(dateRect);
const double lowerTime = _currentTime.et - etSpread;
const double upperTime = _currentTime.et + etSpread;
std::vector<Image*> images;
for (Image& i : _images) {
if (i.beginning <= upperTime && i.ending >= lowerTime)
images.push_back(&i);
}
//std::vector<Image>::const_iterator lower = std::lower_bound(_images.begin(), _images.end(), lowerTime, [](const Image& i, double time) { return i.beginning < time; });
//std::vector<Image>::const_iterator upper = std::lower_bound(_images.begin(), _images.end(), upperTime, [](const Image& i, double time) { return i.ending < time; });
//if (lower != _images.end() && upper != _images.end())
// drawImages(painter, timelineRect, std::vector<Image>(lower, upper), lowerTime, upperTime);
drawImages(painter, timelineRect, images, lowerTime, upperTime);
// Draw current time
painter.setBrush(QBrush(Qt::black));
painter.setPen(QPen(Qt::black));
painter.drawLine(QPointF(0, timelineRect.height() / 2), QPointF(timelineRect.width(), timelineRect.height() / 2));
painter.drawText(timelineRect.width(), timelineRect.height() / 2 + TextOffset, QString::fromStdString(_currentTime.time));
}
void TimelineWidget::drawLegend(QPainter& painter, QRectF rect) {
static const int HalfHeight = LegendHeight / 2;
static const int Padding = 5;
static const int BoxSize = 20;
// Draw Targets
int currentHorizontalPosition = Padding;
int currentVerticalPosition = Padding;
//for (int i = 0; i < _targets.size(); ++i) {
// const std::string& target = _targets[i];
//
// painter.setBrush(QBrush(targetColors[i]));
// painter.drawRect(currentHorizontalPosition, currentVerticalPosition, BoxSize, BoxSize);
// currentHorizontalPosition += BoxSize + Padding;
// painter.drawText(currentHorizontalPosition, currentVerticalPosition + BoxSize / 2 + TextOffset, QString::fromStdString(target));
// int textWidth = painter.boundingRect(QRect(), QString::fromStdString(target)).width();
// currentHorizontalPosition += std::max(textWidth, 25) + Padding;
//}
// Draw Instruments
currentHorizontalPosition = Padding;
currentVerticalPosition = Padding + BoxSize + Padding;
for (int i = 0; i < _instruments.size(); ++i) {
if (i == _instruments.size() / 3 || i == _instruments.size() * 2 / 3) {
currentVerticalPosition += BoxSize + Padding;
currentHorizontalPosition = Padding;
}
const std::string& instrument = _instruments[i];
//painter.setBrush(QBrush(instrumentColors[i]));
painter.setBrush(QBrush(instrumentColors[i]));
painter.setPen(QPen(instrumentColors[i]));
painter.drawRect(currentHorizontalPosition, currentVerticalPosition, BoxSize, BoxSize);
currentHorizontalPosition += BoxSize + Padding;
painter.setPen(QPen(Qt::black));
painter.drawText(currentHorizontalPosition, currentVerticalPosition + BoxSize / 2 + TextOffset, QString::fromStdString(instrument));
int textWidth = painter.boundingRect(QRect(), QString::fromStdString(instrument)).width();
currentHorizontalPosition += std::max(textWidth, 25) + Padding;
}
}
void TimelineWidget::setCurrentTime(std::string currentTime, double et) {
_currentTime.time = std::move(currentTime);
_currentTime.et = std::move(et);
repaint();
}
void TimelineWidget::drawImages(
QPainter& painter,
QRectF timelineRect,
std::vector<Image*> images,
double minimumTime, double maximumTime)
{
int width = timelineRect.width();
int nInstruments = 0;
std::set<std::string> instrumentSet;
for (Image* i : images) {
for (std::string instrument : i->instruments)
instrumentSet.insert(instrument);
}
std::map<std::string, int> instruments;
for (std::set<std::string>::const_iterator it = instrumentSet.begin(); it != instrumentSet.end(); ++it)
instruments[*it] = std::distance(instrumentSet.begin(), it);
for (Image* i : images) {
double tBeg = (i->beginning - minimumTime) / (maximumTime - minimumTime);
tBeg = std::max(tBeg, 0.0);
double tEnd = (i->ending - minimumTime) / (maximumTime - minimumTime);
tEnd = std::min(tEnd, 1.0);
int loc = timelineRect.top() + timelineRect.height() * tBeg;
int height = (timelineRect.top() + timelineRect.height() * tEnd) - loc;
height = std::max(height, 5);
std::string target = i->target;
auto it = std::find(_targets.begin(), _targets.end(), target);
int iTarget = std::distance(_targets.begin(), it);
//std::vector<QColor> colors;
for (std::string instrument : i->instruments) {
auto it = std::find(_instruments.begin(), _instruments.end(), instrument);
if (it == _instruments.end())
qDebug() << "Instrument not found";
int i = std::distance(_instruments.begin(), it);
painter.setBrush(QBrush(instrumentColors[i]));
double width = timelineRect.width() / instruments.size();
double pos = instruments[instrument] * width;
painter.drawRect(pos, loc, width, height);
}
painter.setBrush(QBrush(Qt::black));
painter.setPen(QPen(Qt::black));
QString line = QString::fromStdString(i->beginningString) + QString(" (") + QString::fromStdString(i->target) + QString(")");
painter.drawText(timelineRect.width(), loc + height / 2 + TextOffset, line);
}
}
void TimelineWidget::socketConnected() {
setDisabled(false);
}
void TimelineWidget::socketDisconnected() {
setDisabled(true);
_images.clear();
_instruments.clear();
_targets.clear();
}

View File

@@ -0,0 +1,68 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2015 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __TIMELINEWIDGET_H__
#define __TIMELINEWIDGET_H__
#include <QWidget>
#include "common.h"
#include <stdint.h>
#include <map>
#include <vector>
class QPaintEvent;
class TimelineWidget : public QWidget {
Q_OBJECT
public:
TimelineWidget(QWidget* parent);
void setData(std::vector<Image> images, std::map<uint8_t, std::string> targetMap, std::map<uint16_t, std::string> instrumentMap);
void setCurrentTime(std::string currentTime, double et);
void socketConnected();
void socketDisconnected();
protected:
void paintEvent(QPaintEvent* event);
void drawContent(QPainter& painter, QRectF rect);
void drawLegend(QPainter& painter, QRectF rect);
void drawImages(QPainter& painter, QRectF timelineRect, std::vector<Image*> images, double minimumTime, double maximumTime);
private:
std::vector<Image> _images;
std::map<uint8_t, std::string> _targetMap;
std::map<uint16_t, std::string> _instrumentMap;
std::vector<std::string> _targets;
std::vector<std::string> _instruments;
struct {
std::string time;
double et;
} _currentTime;
};
#endif // __TIMELINEWIDGET_H__

View File

@@ -40,6 +40,7 @@ namespace openspace {
class ConfigurationManager;
class LuaConsole;
class NetworkEngine;
class GUI;
class RenderEngine;
class SyncBuffer;
@@ -68,6 +69,7 @@ public:
interaction::InteractionHandler* interactionHandler();
RenderEngine* renderEngine();
scripting::ScriptEngine* scriptEngine();
NetworkEngine* networkEngine();
LuaConsole* console();
gui::GUI* gui();
@@ -111,6 +113,7 @@ private:
interaction::InteractionHandler* _interactionHandler;
RenderEngine* _renderEngine;
scripting::ScriptEngine* _scriptEngine;
NetworkEngine* _networkEngine;
ghoul::cmdparser::CommandlineParser* _commandlineParser;
LuaConsole* _console;
gui::GUI* _gui;

View File

@@ -0,0 +1,76 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2015 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __NETWORKENGINE_H__
#define __NETWORKENGINE_H__
#include <cstdint>
#include <map>
#include <string>
#include <vector>
namespace openspace {
class NetworkEngine {
public:
typedef uint16_t MessageIdentifier;
NetworkEngine();
// Receiving messages
bool handleMessage(const std::string& message);
// Sending messages
void publishStatusMessage();
void publishIdentifierMappingMessage();
void publishMessage(MessageIdentifier identifier, std::vector<char> message);
void sendMessages();
// Initial Connection Messages
void setInitialConnectionMessage(MessageIdentifier identifier, std::vector<char> message);
void sendInitialInformation();
// Background
MessageIdentifier identifier(std::string name);
private:
std::map<MessageIdentifier, std::string> _identifiers;
MessageIdentifier _lastAssignedIdentifier;
struct Message {
MessageIdentifier identifer;
std::vector<char> body;
};
std::vector<Message> _messagesToSend;
std::vector<Message> _initialConnectionMessages;
MessageIdentifier _statusMessageIdentifier;
MessageIdentifier _identifierMappingIdentifier;
};
} // namespace openspace
#endif // __NETWORKENGINE_H__

View File

@@ -43,6 +43,7 @@ public:
virtual void deinitialize();
void render();
virtual bool loadModel(const std::string& filename) = 0;
void changeRenderMode(const GLenum mode);
protected:
RenderableModel* _parent;
@@ -59,6 +60,7 @@ protected:
GLuint _vaoID;
GLuint _vbo;
GLuint _ibo;
GLenum _mode;
std::vector<Vertex> _vertices;
std::vector<int> _indices;

View File

@@ -57,6 +57,8 @@ protected:
private:
properties::StringProperty _colorTexturePath;
properties::BoolProperty _performFade;
properties::FloatProperty _fading;
ghoul::opengl::ProgramObject* _programObject;
ghoul::opengl::Texture* _texture;
@@ -69,6 +71,7 @@ private:
std::string _destination;
std::string _target;
bool _isGhost;
psc _sunPosition;

View File

@@ -64,15 +64,17 @@ private:
properties::StringProperty _colorTexturePath;
ghoul::opengl::ProgramObject* _programObject;
ghoul::opengl::Texture* _texture;
ghoul::opengl::Texture* _nightTexture;
planetgeometry::PlanetGeometry* _geometry;
properties::BoolProperty _performShading;
properties::IntProperty _rotation;
float _alpha;
glm::dmat3 _stateMatrix;
std::string _nightTexturePath;
std::string _frame;
std::string _target;
bool _hasNightTexture;
double _time;
};

View File

@@ -28,7 +28,13 @@
// open space includes
#include <openspace/rendering/renderable.h>
#include <openspace/util/imagesequencer.h>
#include <openspace/util/imagesequencer2.h>
#include <openspace/util/sequenceparser.h>
#include <openspace/util/hongkangparser.h>
#include <openspace/util/labelparser.h>
#include <openspace/util/decoder.h>
#include <openspace/properties/stringproperty.h>
#include <openspace/properties/triggerproperty.h>
@@ -71,15 +77,18 @@ protected:
private:
void imageProjectGPU();
std::map<std::string, Decoder*> _fileTranslation;
properties::StringProperty _colorTexturePath;
properties::StringProperty _projectionTexturePath;
properties::TriggerProperty _imageTrigger;
properties::IntProperty _rotation;
properties::FloatProperty _fadeProjection;
ghoul::opengl::ProgramObject* _programObject;
ghoul::opengl::ProgramObject* _fboProgramObject;
ghoul::opengl::Texture* _texture;
ghoul::opengl::Texture* _textureOriginal;
ghoul::opengl::Texture* _textureProj;
planetgeometryprojection::PlanetGeometryProjection* _geometry;
@@ -88,12 +97,19 @@ private:
glm::mat4 _transform;
glm::mat4 _projectorMatrix;
//sequenceloading
std::string _sequenceSource;
std::string _sequenceType;
bool _foundSequence;
// spice
std::string _instrumentID;
std::string _projectorID;
std::string _projecteeID;
std::string _aberration;
std::vector<std::string> _potentialTargets; // @TODO copy-n-paste from renderablefov
float _fovy;
float _aspectRatio;
float _nearPlane;
@@ -103,18 +119,27 @@ private:
glm::dmat3 _instrumentMatrix;
glm::vec3 _boresight;
double _time[2];
double _time;
double _previousTime;
double _previousCapture;
double lightTime;
std::vector<Image> _imageTimes;
int _sequenceID;
std::string _target;
std::string _frame;
std::string _defaultProjImage;
std::string _next;
bool _capture;
// FBO stuff
GLuint _fboID;
GLuint _quad;
GLuint _vertexPositionBuffer;
bool _once; //fml
};
} // namespace openspace

View File

@@ -69,8 +69,13 @@ public:
virtual void update(const UpdateData& data);
bool isVisible() const;
bool hasTimeInterval();
bool getInterval(double& start, double& end);
bool hasBody();
bool getBody(std::string& body);
void setBody(std::string& body);
protected:
std::string findPath(const std::string& path);
@@ -83,6 +88,8 @@ private:
std::string _relativePath;
std::string _startTime;
std::string _endTime;
std::string _targetBody;
bool _hasBody;
bool _hasTimeInterval;
};

View File

@@ -53,6 +53,7 @@ public:
private:
properties::FloatProperty _lineWidth;
properties::BoolProperty _drawSolid;
ghoul::opengl::ProgramObject* _programObject;
ghoul::opengl::Texture* _texture;
openspace::SceneGraphNode* _targetNode;
@@ -76,9 +77,9 @@ public:
int _nrInserted = 0;
int _isteps;
bool _rebuild = false;
bool _interceptTag[5];
bool _interceptTag[9];
bool _withinFOV;
psc _projectionBounds[4];
psc _projectionBounds[8];
psc _interceptVector;
// spice
@@ -124,59 +125,3 @@ public:
};
}
#endif
// Scrap stuff i need to keep for now (michal)
/* // idk how we will compute the aberrated state.
double RenderableFov::computeTargetLocalTime(PowerScaledScalar d){
double c = 299792456.075; // m/s
double dt = ( (d[0]*pow(10, d[1])) / c );
double t_local = _time - dt*86400;
std::string localTime;
std::string currentTime;
openspace::SpiceManager::ref().getDateFromET(t_local, localTime);
openspace::SpiceManager::ref().getDateFromET(_time , currentTime);
std::cout << "time at jupiter : " << localTime << "\time at NH" << currentTime << std::endl;
return t_local;
}*/
/*
psc RenderableFov::sphericalInterpolate(glm::dvec3 p0, glm::dvec3 p1, float t){
double targetEt, lt;
glm::dvec3 ip, iv;
psc targetPos;
SpiceManager::ref().getTargetPosition("JUPITER", _spacecraft, _frame, _aberrationCorrection, _time, targetPos, lt);
openspace::SpiceManager::ref().getSurfaceIntercept(_fovTarget, _spacecraft, _instrumentID,
_frame, _method, _aberrationCorrection, _time, targetEt, p0, ip, iv);
psc psc0 = PowerScaledCoordinate::CreatePowerScaledCoordinate(iv[0], iv[1], iv[2]);
openspace::SpiceManager::ref().getSurfaceIntercept(_fovTarget, _spacecraft, _instrumentID,
_frame, _method, _aberrationCorrection, _time, targetEt, p1, ip, iv);
psc psc1 = PowerScaledCoordinate::CreatePowerScaledCoordinate(iv[0], iv[1], iv[2]);
psc0[3] += 3;
psc1[3] += 3;
psc0 -= targetPos;
psc1 -= targetPos;
double angle = psc0.angle(psc1);
std::cout << angle << std::endl;
double sin_a = sin(angle); // opt
double l[2] = { sin((1.f - t)*angle) / sin_a, sin((t)*angle) / sin_a };
std::cout << l[0] << " " << l[1] << std::endl;
float s = ((t-1)*psc0[3] + (t)*psc1[3]);
float x = (l[0]*psc0[0] + l[1]*psc1[0]);
float y = (l[0]*psc0[1] + l[1]*psc1[1]);
float z = (l[0]*psc0[2] + l[1]*psc1[2]);
psc interpolated = PowerScaledCoordinate::PowerScaledCoordinate(x, y, z, 10);
return interpolated;
}
*/

View File

@@ -0,0 +1,98 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2015 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef _RENDERABLEPLANEPROJECTION_H_
#define _RENDERABLEPLANEPROJECTION_H_
#include <openspace/rendering/renderable.h>
#include <openspace/properties/stringproperty.h>
#include <openspace/util/imagesequencer2.h>
#include <openspace/properties/vectorproperty.h>
#include <openspace/util/updatestructures.h>
namespace ghoul {
namespace filesystem {
class File;
}
namespace opengl {
class ProgramObject;
class Texture;
}
}
namespace openspace {
struct LinePoint;
struct target {
std::string body;
std::string frame;
std::string node;
};
class RenderablePlaneProjection : public Renderable {
public:
RenderablePlaneProjection(const ghoul::Dictionary& dictionary);
~RenderablePlaneProjection();
bool initialize() override;
bool deinitialize() override;
bool isReady() const override;
void render(const RenderData& data) override;
void update(const UpdateData& data) override;
private:
void loadTexture();
void updatePlane(const Image* img, double currentTime);
std::string findClosestTarget(double currentTime);
void setTarget(std::string body);
std::string _texturePath;
bool _planeIsDirty;
glm::dmat3 _stateMatrix;
std::string _frame;
ghoul::opengl::ProgramObject* _shader;
bool _programIsDirty;
bool _textureIsDirty;
ghoul::opengl::Texture* _texture;
ghoul::filesystem::File* _textureFile;
GLuint _quad;
GLuint _vertexPositionBuffer;
std::string _spacecraft;
std::string _instrument;
target _target;
std::string _name;
bool _moving;
};
} // namespace openspace
#endif

View File

@@ -63,6 +63,7 @@ private:
properties::Vec3Property _lineColor;
properties::FloatProperty _lineFade;
properties::FloatProperty _lineWidth;
properties::BoolProperty _showTimestamps;
ghoul::opengl::ProgramObject* _programObject;
bool _programIsDirty;
@@ -86,6 +87,8 @@ private:
float _increment;
float _oldTime = 0;
float _time;
float _distanceFade;
};
} // namespace openspace

View File

@@ -0,0 +1,46 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2015 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __DYNAMICEPHEMERIS_H__
#define __DYNAMICEPHEMERIS_H__
#include "ephemeris.h"
namespace openspace {
class DynamicEphemeris: public Ephemeris {
public:
DynamicEphemeris(const ghoul::Dictionary& dictionary
= ghoul::Dictionary());
virtual ~DynamicEphemeris();
virtual const psc& position() const;
virtual void update(const UpdateData& data) override;
void setPosition(psc pos);
private:
psc _position;
};
} // namespace openspace
#endif // __DYNAMICEPHEMERIS_H__

View File

@@ -65,10 +65,10 @@ public:
void render(const RenderData& data);
void updateCamera(Camera* camera) const;
void addNode(SceneGraphNode* child);
//void addNode(SceneGraphNode* child);
void setParent(SceneGraphNode* parent);
bool abandonChild(SceneGraphNode* child);
//bool abandonChild(SceneGraphNode* child);
const psc& position() const;
psc worldPosition() const;

View File

@@ -42,6 +42,8 @@ private:
std::string _originName;
psc _position;
bool _kernelsLoadedSuccessfully;
std::string _ghosting;
std::string _name;
};
} // namespace openspace

View File

@@ -89,6 +89,15 @@ namespace renderablemodel {
const std::string keyGeometry = "Geometry";
} // namespace renderablemodel
namespace renderableplaneprojection {
const std::string keySpacecraft = "Spacecraft";
const std::string keyInstrument = "Instrument";
const std::string keyMoving = "Moving";
const std::string keyTexture = "Texture";
const std::string keyName = "Name";
const std::string galacticFrame = "GALACTIC";
} // namespace renderableplaneprojection
namespace renderablestars {
const std::string keyFile = "File";
const std::string keyTexture = "Texture";
@@ -122,6 +131,10 @@ namespace staticephemeris {
const std::string keyPosition = "Position";
} // namespace staticephemeris
namespace dynamicephemeris {
const std::string keyPosition = "Position";
} // namespace dynamicephemeris
namespace spiceephemeris {
const std::string keyBody = "Body";
const std::string keyOrigin = "Observer";

View File

@@ -0,0 +1,47 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2015 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __DECODER_H__
#define __DECODER_H__
#include <ghoul/misc/dictionary.h>
#include <openspace/util/updatestructures.h>
namespace openspace {
class Decoder {
public:
static Decoder* createFromDictionary(const ghoul::Dictionary& dictionary, const std::string type);
Decoder(const ghoul::Dictionary& dictionary);
virtual ~Decoder();
virtual std::string getDecoderType() = 0;
virtual std::vector<std::string> getTranslation() = 0;
protected:
Decoder();
};
} // namespace openspace
#endif // __DECODER_H__

View File

@@ -0,0 +1,86 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2015 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __HONGKANGPARSER_H__
#define __HONGKANGPARSER_H__
#include <openspace/util/ImageSequencer2.h>
#include <openspace/util/sequenceparser.h>
#include <map>
#include <string>
#include <vector>
namespace openspace {
class HongKangParser : public SequenceParser{
public:
HongKangParser();
HongKangParser(const std::string& fileName,
std::string spacecraft,
ghoul::Dictionary dictionary,
std::vector<std::string> potentialTargets);
virtual void create();
virtual std::map<std::string, ImageSubset> getSubsetMap();
virtual std::vector<std::pair<std::string, TimeRange>> getIstrumentTimes();
virtual std::vector<std::pair<double, std::string>> getTargetTimes();
// temporary need to figure this out
virtual std::map<std::string, Decoder*> getTranslation(){ return _fileTranslation; };
virtual std::vector<double> getCaptureProgression();
private:
double getMetFromET(double et);
double getETfromMet(std::string timestr);
double getETfromMet(double met);
void createImage(Image& image,
double startTime,
double stopTime,
std::vector<std::string> instr,
std::string targ,
std::string pot);
bool augmentWithSpice(Image& image,
std::string spacecraft,
std::vector<std::string> payload,
std::vector<std::string> potentialTargets);
void sendPlaybookInformation();
std::string _defaultCaptureImage;
double _metRef = 299180517;
std::string _fileName;
std::string _spacecraft;
std::map<std::string, Decoder*> _fileTranslation;
std::vector<std::string> _potentialTargets;
//returnable
std::map<std::string, ImageSubset> _subsetMap;
std::vector<std::pair<std::string, TimeRange>> _instrumentTimes;
std::vector<std::pair<double, std::string>> _targetTimes;
std::vector<double> _captureProgression;
};
}
#endif //__HONGKANGPARSER_H__

View File

@@ -37,43 +37,102 @@ namespace openspace {
class ImageSequencer {
public:
ImageSequencer();
/**
* Singelton instantiation
*/
static ImageSequencer& ref();
bool loadSequence(const std::string& dir);
bool parsePlaybook(const std::string& dir, const std::string& type, std::string year = "2015");
bool parsePlaybookFile(const std::string& fileName, std::string year = "2015");
void testStartTimeMap();
static void initialize();
static void deinitialize();
bool sequenceReset();
bool getImagePath(double& _currentTime, std::string& path, bool closedInterval = false);
/**
* Updates current time and initializes the previous time member
*/
void update(double initTime);
/**
* When the a projectable class loads its sequence it also has to request an ID
* which is set by reference and returned to the projectable. This ID is later
* used to access whatever data ImageSequencer loads.
*/
void setSequenceId(int& id);
//bool sequenceReset();
/**
* Based on sequenceID and unique projectee name, the ImageSequencer determines which subset of data is to be filled to _imageTimes
* which can be used in a projecable class for projections.
*/
bool getImagePath(std::vector<std::pair<double, std::string>>& _imageTimes, int sequenceID, std::string projectee, bool withinFOV);
/*
* Returns the time until next capture in seconds.
*
*/
double getNextCaptureTime();
double getIntervalLength(){ return _intervalLength; };
std::string& getActiveInstrument(){ return _activeInstrument; };
std::string findActiveInstrument(double time);
/*
* Returns the time until next capture in seconds.
*/
double getIntervalLength(){ return _intervalLength; };
/*
* Returns next active instrument
*/
std::string& getActiveInstrument(){ return _activeInstrument; };
/*
* Performs search to find next consective instrument thats active
*/
std::string findActiveInstrument(double time, int sequenceID);
/*
* Performs search to find next consecutive projection image.
*/
double nextCaptureTime(double _time, int sequenceID);
/*
* Load (from *.fit converted) jpg image sequence based on corresponding *.lbl header files
*/
bool loadSequence(const std::string& dir, int& sequenceID);
/*
* Load sequence file of either *.csv type (excel) or preparsed *.txt type
*/
bool parsePlaybook(const std::string& dir, const std::string& type, std::string year = "2015");
bool parsePlaybookFile(const std::string& fileName, int& sequenceID, std::string year = "2015");
/*
* These three methods augment the playbook
*/
void augumentSequenceWithTargets(int sequenceID);
void addSequenceObserver(int sequenceID, std::string name, std::vector<std::string> payload);
void registerTargets(std::vector<std::string>& potential);
static ImageSequencer* _sequencer;
protected:
bool getMultipleImages(std::vector<std::pair<double, std::string>>& _imageTimes, int sequenceID, std::string projectee);
bool getSingleImage(std::vector<std::pair<double, std::string>>& _imageTimes, int sequenceID, std::string projectee);
private:
double getMissionElapsedTime(std::string timestr);
double nextCaptureTime(double _time);
std::map<std::string, double> _projectableTargets;
std::map <int, std::string> _observers;
std::map <std::string, std::vector<std::string>> _instruments;
void createImage(double t1, double t2, std::string instrument, std::string path = "dummypath");
double _nextCapture;
double _intervalLength;
double _metRef = 299180517;
double _currentTime;
int _sequenceIDs;
std::string _defaultCaptureImage;
std::string _activeInstrument;
bool _targetsAdded;
};
} // namespace openspace

View File

@@ -0,0 +1,205 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __ImageSequencer2_H__
#define __ImageSequencer2_H__
// open space includes
#include <ghoul/opengl/ghoul_gl.h>
#include <openspace/util/powerscaledcoordinate.h>
#include <openspace/util/powerscaledscalar.h>
#include <unordered_map>
#include <map>
#include <vector>
#include <openspace/util/sequenceparser.h>
namespace openspace {
/**
* The ImageSequencer singleton main function is to manage the timekeeping and
* distribution of large image data-sets across all openspace renderable instances,
* both for past and future unmanned-spacecraft missions. To load the instance with
* data the client must provide a parser inherited from the abstract base class
* SequenceParser. Hence, there is no restriction imposed on data input, whether its
* data in the form of existing images or in the form of a planned observation schedule.
* Notably, in order for the sequencer to function the client must provide or write a
* parser that fills the ImageSequencers private members.
* \see SequenceParser
* \see ImageSequencer2::runSequenceParser(SequenceParser* parser)
* std::map<std::string, bool>
*/
class ImageSequencer2 {
public:
ImageSequencer2();
/**
* Singelton instantiation
*/
static ImageSequencer2* _instance;
/**
* Returns the reference to the singleton ImageSequencer object that must have been
* initialized by a call to the initialize method earlier.
* \return The ImageSequencer singleton
*/
static ImageSequencer2& ref();
/**
* Initializer that initializes the static member.
*/
static void initialize();
/**
* Deinitializes that deinitializes the static member.
*/
static void deinitialize();
/**
* Returns true if sequencer has been loaded with data.
*/
bool isReady();
/**
* Updates sequencer with current <code>time</code>. This is used internally for keeping
* track of both current simulation time and the time of the previously rendered frame.
*/
void updateSequencer(double time);
/**
* Runs parser and recieves the datastructures filled by it.
* \see SequenceParser
*/
void runSequenceParser(SequenceParser* parser);
/**
* Retrieves the next upcoming target in time.
*/
std::pair<double, std::string> getNextTarget();
/**
* Retrieves the most current target in time.
*/
std::pair<double, std::string> getCurrentTarget();
/**
* Retrieves current target and (in the list) adjacent targets, the number to retrieve is user set
*/
std::pair<double, std::vector<std::string>> getIncidentTargetList(int range = 2);
/**
* Retrieves the next upcoming time of image capture.
*/
double getNextCaptureTime();
/**
* Retrieves the time interval length between the current time and an upcoming capture.
*/
double getIntervalLength();
/*
* Returns a map with key instrument names whose value indicate whether
* an instrument is active or not.
*/
std::map<std::string, bool> getActiveInstruments();
/*
* Retrieves the relevant data from a specific subset based on the what instance
* makes the request. If an instance is not registered in the class then the singleton
* returns false and no projections will occur.
*/
bool ImageSequencer2::getImagePaths(std::vector<Image>& captures,
std::string projectee,
std::string instrumentID);
bool ImageSequencer2::getImagePaths(std::vector<Image>& captures,
std::string projectee);
/*
* returns true if instrumentID is within a capture range.
*/
bool instumentActive(std::string instrumentID);
/*
* returns latest captured image
*/
const Image* getLatestImageForInstrument(const std::string _instrumentID);
private:
void sortData();
/*
* _fileTranslation handles any types of ambiguities between the data and
* spice/openspace -calls. This map is composed of a key that is a string in
* the data to be translated and a Decoder that holds the corresponding
* translation provided through a modfile.
* \see Decoder
* \see (projection mod files)
*/
std::map<std::string, Decoder*> _fileTranslation;
/*
* This is the main container of image data. The key is the target name,
* the value is a subset of images.
* \see SequenceParser
*/
std::map<std::string, ImageSubset> _subsetMap;
/*
* In order for the simulation to know when to turn on/off any instrument within
* all instruments in the spacecraft payload, the key is the data-file given
* instrument name.
*/
std::map<std::string, bool> _switchingMap;
/*
* This datastructure holds the specific times when the spacecraft switches from
* observing one inertial body to the next. This happens a lot in such missions
* and the coupling of target with specific time is usually therefore not 1:1.
*/
std::vector<std::pair<double, std::string>> _targetTimes;
/*
* Holds the time ranges of each instruments on and off periods. An instrument
* rendering class may ask the ImageSequencer whether or not it
*/
std::vector<std::pair<std::string, TimeRange>> _instrumentTimes;
/*
* Each consecutive images capture time, for easier traversal.
*/
std::vector<double> _captureProgression;
// current simulation time
double _currentTime;
// simulation time of previous frame
double _previousTime;
// time between current simulation time and an upcoming capture
double _intervalLength;
// next consecutive capture in time
double _nextCapture;
// default capture image
std::string _defaultCaptureImage;
Image* _latestImage;
// if no data, no run
bool _hasData;
};
} // namespace openspace
#endif // __ImageSequencer2_H__

View File

@@ -0,0 +1,48 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2015 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __INSTRUMENTDECODER_H__
#define __INSTRUMENTDECODER_H__
#include <openspace/util/decoder.h>
#include <openspace/util/powerscaledcoordinate.h>
namespace openspace {
class InstrumentDecoder : public Decoder {
public:
InstrumentDecoder(const ghoul::Dictionary& dictionary);
virtual std::string getDecoderType();
virtual std::vector<std::string> getTranslation();
std::string getStopCommand();
private:
std::string _type;
std::string _stopCommand;
std::vector<std::string> _spiceIDs;
};
} // namespace openspace
#endif // __INSTRUMENTDECODER_H__

View File

@@ -0,0 +1,87 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2015 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __LABELPARSER_H__
#define __LABELPARSER_H__
#include <openspace/util/ImageSequencer2.h>
#include <openspace/util/sequenceparser.h>
#include <map>
#include <string>
#include <vector>
namespace openspace {
class LabelParser : public SequenceParser{
public:
LabelParser();
LabelParser(const std::string& fileName,
ghoul::Dictionary translationDictionary);
virtual void create();
virtual std::map<std::string, ImageSubset> getSubsetMap();
virtual std::vector<std::pair<std::string, TimeRange>> getIstrumentTimes();
virtual std::vector<std::pair<double, std::string>> getTargetTimes();
// temporary need to figure this out
std::map<std::string, Decoder*> getTranslation(){ return _fileTranslation; };
virtual std::vector<double> getCaptureProgression(){ return _captureProgression; };
private:
void createImage(Image& image,
double startTime,
double stopTime,
std::vector<std::string> instr,
std::string targ,
std::string path);
std::string decode(std::string line);
std::string encode(std::string line);
bool augmentWithSpice(Image& image,
std::string spacecraft,
std::vector<std::string> payload,
std::vector<std::string> potentialTargets);
std::string _fileName;
std::string _spacecraft;
std::map<std::string, Decoder*> _fileTranslation;
std::vector<std::string> _specsOfInterest;
//returnable
std::map<std::string, ImageSubset> _subsetMap;
std::vector<std::pair<std::string, TimeRange>> _instrumentTimes;
std::vector<std::pair<double, std::string>> _targetTimes;
std::vector<double> _captureProgression;
std::string _target;
std::string _instrumentID;
std::string _instrumentHostID;
std::string _detectorType;
std::string _sequenceID;
double _startTime;
double _stopTime;
};
}
#endif //__LABELPARSER_H__

View File

@@ -0,0 +1,48 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2015 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __SCANNERDECODER_H__
#define __SCANNERDECODER_H__
#include <openspace/util/decoder.h>
#include <openspace/util/powerscaledcoordinate.h>
namespace openspace {
class ScannerDecoder : public Decoder {
public:
ScannerDecoder(const ghoul::Dictionary& dictionary);
virtual std::string getDecoderType();
virtual std::vector<std::string> getSpiceIDs();
std::string getStopCommand();
void setStopCommand(std::string stopCommand);
private:
std::string _type;
std::string _abort;
std::vector<std::string> _spiceIDs;
};
} // namespace openspace
#endif // __SCANNERDECODER_H__

View File

@@ -0,0 +1,74 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2015 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __SEQUENCEPARSER_H__
#define __SEQUENCEPARSER_H__
#include <openspace/util/decoder.h>
#include <map>
#include <string>
#include <vector>
namespace openspace {
struct Image{
double startTime;
double stopTime;
std::string path;
std::vector<std::string> activeInstruments;
std::string target;
bool projected;
};
struct TimeRange{
TimeRange() : _min(-1), _max(-1){};
void setRange(double val){
if (_min > val) _min = val;
if (_max < val) _max = val;
};
bool inRange(double min, double max){
return (min >= _min && max <= _max);
}
bool inRange(double val){
return (val >= _min && val <= _max);
}
double _min;
double _max;
};
struct ImageSubset{
TimeRange _range;
std::vector < Image > _subset;
};
class SequenceParser{
public:
virtual void create() = 0;
virtual std::map<std::string, ImageSubset> getSubsetMap() = 0;
virtual std::vector<std::pair<std::string, TimeRange>> getIstrumentTimes() = 0;
virtual std::vector<std::pair<double, std::string>> getTargetTimes() = 0;
virtual std::map<std::string, Decoder*> getTranslation() = 0;
virtual std::vector<double> getCaptureProgression() = 0;
};
}
#endif //__SEQUENCEPARSER_H__

View File

@@ -630,6 +630,22 @@ public:
*/
bool getFieldOfView(int instrument, std::string& fovShape, std::string& frameName,
glm::dvec3& boresightVector, std::vector<glm::dvec3>& bounds) const;
/**
* This function adds a frame to a body
* \param body - the name of the body
* \param frame - the name of the frame
* \return false if the arguments are empty
*/
bool addFrame(const std::string body, const std::string frame);
/**
* This function returns the frame of a body if defined, otherwise it returns
* IAU_ + body (most frames are known by the International Astronomical Union)
* \param body - the name of the body
* \return the frame of the body
*/
std::string frameFromBody(const std::string body) const;
/**
* This method checks if one of the previous SPICE methods has failed. If it has, the
@@ -673,6 +689,10 @@ private:
std::map<int, std::vector< std::pair<double, double> > > _spkIntervals;
std::map<int, std::set<double> > _ckCoverageTimes;
std::map<int, std::set<double> > _spkCoverageTimes;
// Vector of pairs: Body, Frame
std::vector< std::pair<std::string, std::string> > _frameByBody;
const static bool _showErrors = false;
/// The last assigned kernel-id, used to determine the next free kernel id
KernelIdentifier _lastAssignedKernel;

View File

@@ -0,0 +1,46 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2015 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __TARGETDECODER_H__
#define __TARGETDECODER_H__
#include <openspace/util/decoder.h>
#include <openspace/util/powerscaledcoordinate.h>
namespace openspace {
class TargetDecoder : public Decoder {
public:
TargetDecoder(const ghoul::Dictionary& dictionary);
virtual std::string getDecoderType();
virtual std::vector<std::string> getTranslation();
private:
std::string _type;
std::vector<std::string> _names;
};
} // namespace openspace
#endif // __TARGETDECODER_H__

View File

@@ -51,7 +51,7 @@ namespace openspace {
* equal to the frame time.
*/
class SyncBuffer;
class SyncBuffer;
class Time {
public:

View File

@@ -45,5 +45,5 @@ return {
SGCTConfig = "${SGCT}/single.xml",
--SGCTConfig = "${SGCT}/single_fisheye.xml",
--SGCTConfig = "${SGCT}/two_nodes.xml",
Scene = "${OPENSPACE_DATA}/scene/default.scene",
Scene = "${OPENSPACE_DATA}/scene/default_nh.scene",
}

View File

@@ -26,4 +26,29 @@ openspace.bindKey("7", "openspace.time.setTime('2015-07-14T15:02:46.00'); opensp
openspace.bindKey("q", "local b = openspace.getPropertyValue('SunMarker.renderable.enabled'); openspace.setPropertyValue('SunMarker.renderable.enabled', not b)")
openspace.bindKey("e", "local b = openspace.getPropertyValue('EarthMarker.renderable.enabled'); openspace.setPropertyValue('EarthMarker.renderable.enabled', not b)")
openspace.bindKey("k", "local b = openspace.getPropertyValue('HydraText.renderable.enabled'); openspace.setPropertyValue('HydraText.renderable.enabled', not b)")
openspace.bindKey("k", "local b = openspace.getPropertyValue('CharonText.renderable.enabled'); openspace.setPropertyValue('CharonText.renderable.enabled', not b)")
openspace.bindKey("k", "local b = openspace.getPropertyValue('NixText.renderable.enabled'); openspace.setPropertyValue('NixText.renderable.enabled', not b)")
openspace.bindKey("k", "local b = openspace.getPropertyValue('KerberosText.renderable.enabled'); openspace.setPropertyValue('KerberosText.renderable.enabled', not b)")
openspace.bindKey("k", "local b = openspace.getPropertyValue('StyxText.renderable.enabled'); openspace.setPropertyValue('StyxText.renderable.enabled', not b)")
openspace.bindKey("j", "local b = openspace.getPropertyValue('PlutoText.renderable.enabled'); openspace.setPropertyValue('PlutoText.renderable.enabled', not b)")
openspace.bindKey("l", "local b = openspace.getPropertyValue('Labels.renderable.performFading'); openspace.setPropertyValue('Labels.renderable.performFading', not b)")
openspace.bindKey("m", "local b = openspace.getPropertyValue('NH_LORRI.renderable.solidDraw'); openspace.setPropertyValue('NH_LORRI.renderable.solidDraw', not b)")
openspace.bindKey("m", "local b = openspace.getPropertyValue('NH_RALPH_LEISA.renderable.solidDraw'); openspace.setPropertyValue('NH_RALPH_LEISA.renderable.solidDraw', not b)")
openspace.bindKey("m", "local b = openspace.getPropertyValue('NH_RALPH_MVIC_PAN1.renderable.solidDraw'); openspace.setPropertyValue('NH_RALPH_MVIC_PAN1.renderable.solidDraw', not b)")
openspace.bindKey("m", "local b = openspace.getPropertyValue('NH_RALPH_MVIC_PAN2.renderable.solidDraw'); openspace.setPropertyValue('NH_RALPH_MVIC_PAN2.renderable.solidDraw', not b)")
openspace.bindKey("m", "local b = openspace.getPropertyValue('NH_RALPH_MVIC_RED.renderable.solidDraw'); openspace.setPropertyValue('NH_RALPH_MVIC_RED.renderable.solidDraw', not b)")
openspace.bindKey("m", "local b = openspace.getPropertyValue('NH_RALPH_MVIC_BLUE.renderable.solidDraw'); openspace.setPropertyValue('NH_RALPH_MVIC_BLUE.renderable.solidDraw', not b)")
openspace.bindKey("m", "local b = openspace.getPropertyValue('NH_RALPH_MVIC_FT.renderable.solidDraw'); openspace.setPropertyValue('NH_RALPH_MVIC_FT.renderable.solidDraw', not b)")
openspace.bindKey("m", "local b = openspace.getPropertyValue('NH_RALPH_MVIC_METHANE.renderable.solidDraw'); openspace.setPropertyValue('NH_RALPH_MVIC_METHANE.renderable.solidDraw', not b)")
openspace.bindKey("m", "local b = openspace.getPropertyValue('NH_RALPH_MVIC_NIR.renderable.solidDraw'); openspace.setPropertyValue('NH_RALPH_MVIC_NIR.renderable.solidDraw', not b)")
openspace.bindKey("m", "local b = openspace.getPropertyValue('NH_ALICE_AIRGLOW.renderable.solidDraw'); openspace.setPropertyValue('NH_ALICE_AIRGLOW.renderable.solidDraw', not b)")
openspace.bindKey("PAUSE", "openspace.printInfo('F5: Toogle to Sun, F6: Toggle to Jupiter, F7: Toggle to Pluto'); openspace.printInfo('Bookmarks: 1: Jupter, 2-7: Pluto');")

View File

@@ -5,8 +5,13 @@
openspace.setInvertRoll(true);
--openspace.setInteractionSensitivity(10) -- This is the default value for the sensitivity (the higher, the more sensitive)
openspace.time.setTime("2007 FEB 27 16:40:00") -- This is the start time for a Jupiter run of New Horizons
--openspace.time.setTime("2007 FEB 27 16:30:00") -- This is the start time for a Jupiter run of New Horizons
--openspace.time.setTime("2007 FEB 28 03:45:00") -- Io Capture!
--openspace.time.setTime("2011 AUG 6 07:15:00") -- Dawn @ Vestaprojection
--openspace.time.setTime("2014 AUG 28 03:45:00") -- Rosetta Travels 67p in triangular shape
openspace.time.setDeltaTime(10) -- How many seconds pass per second of realtime, changeable in the GUI
@@ -14,7 +19,7 @@ dofile(openspace.absPath('${SCRIPTS}/bind_keys.lua')) -- Load the default keyb
-- openspace.time.setDeltaTime(50);
--openspace.time.setTime("2015-07-14T10:50:00.00") -- PLUTO
openspace.time.setTime("2015-07-14T10:50:00.00") -- PLUTO
-- NH takes series of images from visible to dark side (across terminator)
-- Sequence lasts ~10 mins, (recommended dt = 10)

View File

@@ -25,12 +25,15 @@
#version __CONTEXT__
uniform sampler2D texture1;
uniform sampler2D texture2;
uniform mat4 ProjectorMatrix;
uniform mat4 ModelTransform;
uniform vec2 _scaling;
uniform vec4 radius;
flat in uint vs_segments;
uniform float projectionFading;
in vec4 vs_position;
uniform vec3 boresight;
@@ -78,7 +81,9 @@ void main() {
dot(v_b, normal) < 0 ) {
color = texture(texture1, projected.xy);
}else{
color = vec4(1,1,1,0);
color = texture(texture2, uv);
color.a = projectionFading;
}
// color.a = 0.1f;//1.f - abs(uv.x - 0.55) / (0.6 - 0.5); // blending
}

93
shaders/model_fs.glsl Normal file
View File

@@ -0,0 +1,93 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#version __CONTEXT__
uniform vec4 campos;
uniform vec4 objpos;
uniform vec3 cam_dir; // add this for specular
uniform vec3 sun_pos;
uniform bool _performShading = true;
uniform float transparency;
uniform int shadows;
uniform float fading;
uniform float time;
uniform sampler2D texture1;
in vec2 vs_st;
in vec4 vs_normal;
in vec4 vs_position;
#include "ABuffer/abufferStruct.hglsl"
#include "ABuffer/abufferAddToBuffer.hglsl"
#include "PowerScaling/powerScaling_fs.hglsl"
//#include "PowerScaling/powerScaling_vs.hglsl"
void main()
{
vec4 position = vs_position;
float depth = pscDepth(position);
vec4 diffuse = texture(texture1, vs_st);
diffuse[3] = fading;
if (_performShading) {
vec4 spec = vec4(0.0);
vec3 n = normalize(vs_normal.xyz);
vec3 l_pos = vec3(sun_pos); // sun.
vec3 l_dir = normalize(l_pos-objpos.xyz);
float intensity = min(max(1*dot(n,l_dir), 0.0), 1);
float shine = 100;
vec4 specular = vec4(1.0);
vec4 ambient =diffuse*0.4;
ambient[3] = transparency;
if(intensity > 0.0f){
// halfway vector
vec3 h = normalize(l_dir + normalize(cam_dir));
// specular factor
float intSpec = max(dot(n,h),0.0);
spec = specular * pow(intSpec, shine);
}
diffuse = vec4(max(intensity * diffuse , ambient).xyz,1) +spec*1.5*diffuse ;
diffuse[3] = fading*transparency;
ABufferStruct_t frag = createGeometryFragment(diffuse, position, depth);
addToBuffer(frag);
}
else {
diffuse[3] = fading*transparency;
ABufferStruct_t frag = createGeometryFragment(diffuse, position, depth);
addToBuffer(frag);
}
}

57
shaders/model_vs.glsl Normal file
View File

@@ -0,0 +1,57 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#version __CONTEXT__
uniform mat4 ViewProjection;
uniform mat4 ModelTransform;
layout(location = 0) in vec4 in_position;
//in vec3 in_position;
layout(location = 1) in vec2 in_st;
layout(location = 2) in vec3 in_normal;
out vec2 vs_st;
out vec4 vs_normal;
out vec4 vs_position;
out float s;
#include "PowerScaling/powerScaling_vs.hglsl"
void main()
{
// set variables
vs_st = in_st;
//vs_stp = in_position.xyz;
vs_position = in_position;
vec4 tmp = in_position;
// this is wrong for the normal. The normal transform is the transposed inverse of the model transform
vs_normal = normalize(ModelTransform * vec4(in_normal,0));
vec4 position = pscTransform(tmp, ModelTransform);
vs_position = tmp;
position = ViewProjection * position;
gl_Position = z_normalization(position);
}

View File

@@ -0,0 +1,50 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#version __CONTEXT__
uniform float time;
uniform sampler2D texture1;
in vec2 vs_st;
in vec4 vs_position;
#include "ABuffer/abufferStruct.hglsl"
#include "ABuffer/abufferAddToBuffer.hglsl"
#include "PowerScaling/powerScaling_fs.hglsl"
void main()
{
vec4 position = vs_position;
float depth = pscDepth(position);
vec4 diffuse;
if (gl_FrontFacing)
diffuse = texture(texture1, vs_st);
else {
diffuse = vec4(0.8);
}
ABufferStruct_t frag = createGeometryFragment(diffuse, position, depth);
addToBuffer(frag);
}

View File

@@ -0,0 +1,49 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#version __CONTEXT__
uniform mat4 ViewProjection;
uniform mat4 ModelTransform;
layout(location = 0) in vec4 in_position;
layout(location = 1) in vec2 in_st;
out vec2 vs_st;
out vec4 vs_position;
out float s;
#include "PowerScaling/powerScaling_vs.hglsl"
void main()
{
vec4 tmp = in_position;
vec4 position = pscTransform(tmp, ModelTransform);
vs_position = tmp;
vs_st = in_st;
position = ViewProjection * position;
gl_Position = z_normalization(position);
}

View File

@@ -27,6 +27,7 @@
in vec4 vs_point_position;
in vec4 vs_point_velocity;
in float fade;
uniform float forceFade;
uniform vec3 color;
@@ -38,7 +39,7 @@ void main() {
vec4 position = vs_point_position;
float depth = pscDepth(position);
vec4 c = vec4(color, fade);
vec4 c = vec4(color, fade*forceFade);
ABufferStruct_t frag = createGeometryFragment(c, position, depth);
addToBuffer(frag);
}

View File

@@ -0,0 +1,87 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#version __CONTEXT__
uniform vec4 campos;
uniform vec4 objpos;
uniform vec3 sun_pos;
uniform bool _performShading = true;
uniform float transparency;
uniform int shadows;
uniform float time;
uniform sampler2D texture1;
uniform sampler2D nightTex;
in vec2 vs_st;
in vec2 vs_nightTex;
in vec4 vs_normal;
in vec4 vs_position;
#include "ABuffer/abufferStruct.hglsl"
#include "ABuffer/abufferAddToBuffer.hglsl"
#include "PowerScaling/powerScaling_fs.hglsl"
void main()
{
vec4 position = vs_position;
float depth = pscDepth(position);
vec4 diffuse = texture(texture1, vs_st);
vec4 diffuse2 = texture(nightTex, vs_st);
if (_performShading) {
// directional lighting
vec3 origin = vec3(0.0);
vec4 spec = vec4(0.0);
vec3 n = normalize(vs_normal.xyz);
//vec3 e = normalize(camdir);
vec3 l_pos = vec3(sun_pos); // sun.
vec3 l_dir = normalize(l_pos-objpos.xyz);
float intensity = min(max(5*dot(n,l_dir), 0.0), 1);
float darkSide = min(max(5*dot(n,-l_dir), 0.0), 1);
float shine = 0.0001;
vec4 specular = vec4(0.5);
vec4 ambient = vec4(0.0,0.0,0.0,transparency);
vec4 daytex = max(intensity * diffuse, ambient);
vec4 mixtex = mix(diffuse, diffuse2, (1+dot(n,-l_dir))/2);
diffuse = (daytex*2 + mixtex)/3;
diffuse[3] = transparency;
ABufferStruct_t frag = createGeometryFragment(diffuse, position, depth);
addToBuffer(frag);
}
else {
diffuse[3] = transparency;
ABufferStruct_t frag = createGeometryFragment(diffuse, position, depth);
addToBuffer(frag);
}
}

View File

@@ -0,0 +1,57 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#version __CONTEXT__
uniform mat4 ViewProjection;
uniform mat4 ModelTransform;
layout(location = 0) in vec4 in_position;
layout(location = 1) in vec2 in_st;
layout(location = 2) in vec3 in_normal;
//layout(location = 3) in vec2 in_nightTex;
out vec2 vs_st;
out vec4 vs_normal;
out vec4 vs_position;
out float s;
#include "PowerScaling/powerScaling_vs.hglsl"
void main()
{
// set variables
vs_st = in_st;
vs_position = in_position;
vec4 tmp = in_position;
// this is wrong for the normal. The normal transform is the transposed inverse of the model transform
vs_normal = normalize(ModelTransform * vec4(in_normal,0));
vec4 position = pscTransform(tmp, ModelTransform);
vs_position = tmp;
position = ViewProjection * position;
gl_Position = z_normalization(position);
}

View File

@@ -60,7 +60,7 @@ void main()
//vec3 e = normalize(camdir);
vec3 l_pos = sun_pos; // sun.
vec3 l_dir = normalize(l_pos-objpos.xyz);
float terminatorBright = 0.4;
float terminatorBright = 0.1;
float intensity = min(max(5*dot(n,l_dir), terminatorBright), 1);
float shine = 0.0001;

View File

@@ -77,8 +77,8 @@ void main()
}
*/
diffuse = max(intensity * diffuse, ambient);
diffuse[3] = transparency;
ABufferStruct_t frag = createGeometryFragment(diffuse, position, depth);
addToBuffer(frag);
}

View File

@@ -48,6 +48,12 @@ file(GLOB ENGINE_HEADER ${HEADER_ROOT_DIR}/openspace/engine/*.h)
set(OPENSPACE_HEADER ${OPENSPACE_HEADER} ${ENGINE_HEADER})
source_group(Engine FILES ${ENGINE_SOURCE} ${ENGINE_HEADER})
file(GLOB NETWORK_SOURCE ${SOURCE_ROOT_DIR}/network/*.cpp)
set(OPENSPACE_SOURCE ${OPENSPACE_SOURCE} ${NETWORK_SOURCE})
file(GLOB NETWORK_HEADER ${HEADER_ROOT_DIR}/openspace/network/*.h)
set(OPENSPACE_HEADER ${OPENSPACE_HEADER} ${NETWORK_HEADER})
source_group(Network FILES ${NETWORK_SOURCE} ${NETWORK_HEADER})
file(GLOB GUI_SOURCE ${SOURCE_ROOT_DIR}/gui/*.cpp)
set(OPENSPACE_SOURCE ${OPENSPACE_SOURCE} ${GUI_SOURCE})
file(GLOB GUI_HEADER ${HEADER_ROOT_DIR}/openspace/gui/*.h)

View File

@@ -35,6 +35,7 @@
#include <openspace/interaction/keyboardcontroller.h>
#include <openspace/interaction/luaconsole.h>
#include <openspace/interaction/mousecontroller.h>
#include <openspace/network/networkengine.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/scripting/scriptengine.h>
#include <openspace/scene/scene.h>
@@ -44,7 +45,8 @@
#include <openspace/util/constants.h>
#include <openspace/util/spicemanager.h>
#include <openspace/util/syncbuffer.h>
#include <openspace/util/imagesequencer.h>
#include <openspace/util/imagesequencer2.h> // testing
#include <ghoul/cmdparser/commandlineparser.h>
@@ -92,6 +94,7 @@ OpenSpaceEngine::OpenSpaceEngine(std::string programName)
, _interactionHandler(new interaction::InteractionHandler)
, _renderEngine(new RenderEngine)
, _scriptEngine(new scripting::ScriptEngine)
, _networkEngine(new NetworkEngine)
, _commandlineParser(new ghoul::cmdparser::CommandlineParser(programName, true))
, _console(new LuaConsole)
, _gui(new gui::GUI)
@@ -100,6 +103,7 @@ OpenSpaceEngine::OpenSpaceEngine(std::string programName)
{
SpiceManager::initialize();
Time::initialize();
ImageSequencer2::initialize();
FactoryManager::initialize();
ghoul::systemcapabilities::SystemCapabilities::initialize();
}
@@ -111,6 +115,7 @@ OpenSpaceEngine::~OpenSpaceEngine() {
delete _interactionHandler;
delete _renderEngine;
delete _scriptEngine;
delete _networkEngine;
delete _commandlineParser;
delete _console;
delete _gui;
@@ -206,8 +211,6 @@ bool OpenSpaceEngine::create(
}
}
ImageSequencer::initialize();
// Create the cachemanager
FileSys.createCacheManager(absPath("${" + constants::configurationmanager::keyCache + "}"));
_engine->_console->initialize();
@@ -698,6 +701,8 @@ void OpenSpaceEngine::encode() {
_syncBuffer->write();
}
_networkEngine->publishStatusMessage();
_networkEngine->sendMessages();
}
void OpenSpaceEngine::decode() {
@@ -707,7 +712,6 @@ void OpenSpaceEngine::decode() {
Time::ref().deserialize(_syncBuffer);
_scriptEngine->deserialize(_syncBuffer);
_renderEngine->deserialize(_syncBuffer);
}
}
@@ -717,17 +721,7 @@ void OpenSpaceEngine::externalControlCallback(const char* receivedChars,
if (size == 0)
return;
// The first byte determines the type of message
const char type = receivedChars[0];
switch (type) {
case '0': // LuaScript
{
std::string script = std::string(receivedChars + 1);
LINFO("Received Lua Script: '" << script << "'");
//_scriptEngine->runScript(script);
_scriptEngine->queueScript(script);
}
}
_networkEngine->handleMessage(std::string(receivedChars));
}
void OpenSpaceEngine::enableBarrier() {
@@ -738,4 +732,8 @@ void OpenSpaceEngine::disableBarrier() {
sgct::SGCTWindow::setBarrier(false);
}
NetworkEngine* OpenSpaceEngine::networkEngine() {
return _networkEngine;
}
} // namespace openspace

View File

@@ -556,7 +556,12 @@ void InteractionHandler::setFocusNode(SceneGraphNode* node) {
glm::vec3 cameraView = glm::normalize(_camera->viewDirection());
//set new focus position
_camera->setFocusPosition(node->worldPosition());
if (viewDir != cameraView) {
float dot = glm::dot(viewDir, cameraView);
//static const float Epsilon = 0.001f;
if (dot < 1.f && dot > -1.f) {
//if (glm::length(viewDir - cameraView) < 0.001) {
//if (viewDir != cameraView) {
glm::vec3 rotAxis = glm::normalize(glm::cross(viewDir, cameraView));
float angle = glm::angle(viewDir, cameraView);
glm::quat q = glm::angleAxis(angle, rotAxis);

View File

@@ -79,7 +79,6 @@ int main(int argc, char** argv) {
sgct::MessageHandler::instance()->setLogToCallback(true);
sgct::MessageHandler::instance()->setLogCallback(mainLogCallback);
LDEBUG("Creating SGCT Engine");
_sgctEngine = new sgct::Engine(newArgc, newArgv);

View File

@@ -0,0 +1,199 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2015 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <openspace/network/networkengine.h>
#include <openspace/util/time.h>
#include <openspace/engine/openspaceengine.h>
#include <array>
#include "sgct.h"
namespace {
const std::string _loggerCat = "NetworkEngine";
const std::string StatusMessageIdentifierName = "StatusMessage";
const std::string MappingIdentifierIdentifierName = "IdentifierMapping";
const char MessageTypeLuaScript = '0';
const char MessageTypeExternalControlConnected = '1';
}
namespace openspace {
NetworkEngine::NetworkEngine()
: _lastAssignedIdentifier(-1) // -1 is okay as we assign one identifier in this ctor
{
static_assert(
sizeof(MessageIdentifier) == 2,
"MessageIdentifier has to be 2 bytes or dependent applications will break"
);
_statusMessageIdentifier = identifier(StatusMessageIdentifierName);
_identifierMappingIdentifier = identifier(MappingIdentifierIdentifierName);
}
bool NetworkEngine::handleMessage(const std::string& message) {
// The first byte determines the type of message
const char type = message[0];
switch (type) {
case MessageTypeLuaScript: // LuaScript
{
std::string script = message.substr(1);
//LINFO("Received Lua Script: '" << script << "'");
OsEng.scriptEngine()->queueScript(script);
return true;
}
case MessageTypeExternalControlConnected:
{
sendInitialInformation();
return true;
}
default:
LERROR("Unknown type '" << type << "'");
return false;
}
}
void NetworkEngine::publishStatusMessage() {
if (!sgct::Engine::instance()->isExternalControlConnected())
return;
// Protocol:
// 8 bytes: time as a ET double
// 24 bytes: time as a UTC string
// 8 bytes: delta time as double
// Total: 40
uint16_t messageSize = 0;
double time = Time::ref().currentTime();
std::string timeString = Time::ref().currentTimeUTC();
double delta = Time::ref().deltaTime();
messageSize += sizeof(time);
messageSize += timeString.length();
messageSize += sizeof(delta);
ghoul_assert(messageSize == 40, "Message size is not correct");
unsigned int currentLocation = 0;
std::vector<char> buffer(messageSize);
std::memmove(buffer.data() + currentLocation, &time, sizeof(time));
currentLocation += sizeof(time);
std::memmove(buffer.data() + currentLocation, timeString.c_str(), timeString.length());
currentLocation += timeString.length();
std::memmove(buffer.data() + currentLocation, &delta, sizeof(delta));
publishMessage(_statusMessageIdentifier, std::move(buffer));
}
void NetworkEngine::publishIdentifierMappingMessage() {
size_t bufferSize = 0;
for (const std::pair<MessageIdentifier, std::string>& i : _identifiers) {
bufferSize += sizeof(MessageIdentifier);
bufferSize += i.second.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));
currentWritingPosition += sizeof(MessageIdentifier);
std::memcpy(buffer.data() + currentWritingPosition, i.second.data(), i.second.size());
currentWritingPosition += i.second.size();
buffer[currentWritingPosition] = '\0';
currentWritingPosition += 1;
}
publishMessage(_identifierMappingIdentifier, std::move(buffer));
}
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;
}
}
#endif
_lastAssignedIdentifier++;
MessageIdentifier result = _lastAssignedIdentifier;
_identifiers[result] = std::move(name);
return result;
}
void NetworkEngine::publishMessage(MessageIdentifier identifier, std::vector<char> message) {
_messagesToSend.push_back({ std::move(identifier), std::move(message) });
}
void NetworkEngine::sendMessages() {
if (!sgct::Engine::instance()->isExternalControlConnected())
return;
for (Message& m : _messagesToSend) {
// Protocol:
// 2 bytes: type of message as uint16_t
// Rest of payload depending on the message type
union {
MessageIdentifier value;
std::array<char, 2> data;
} identifier;
identifier.value = m.identifer;
// Prepending the message identifier to the front
m.body.insert(m.body.begin(), identifier.data.begin(), identifier.data.end());
sgct::Engine::instance()->sendMessageToExternalControl(m.body.data(), m.body.size());
}
_messagesToSend.clear();
}
void NetworkEngine::sendInitialInformation() {
for (const Message& m : _initialConnectionMessages) {
union {
MessageIdentifier value;
std::array<char, 2> data;
} identifier;
identifier.value = m.identifer;
std::vector<char> payload = m.body;
payload.insert(payload.begin(), identifier.data.begin(), identifier.data.end());
sgct::Engine::instance()->sendMessageToExternalControl(payload.data(), payload.size());
}
}
void NetworkEngine::setInitialConnectionMessage(MessageIdentifier identifier, std::vector<char> message) {
// Add check if a MessageIdentifier already exists ---abock
_initialConnectionMessages.push_back({std::move(identifier), std::move(message)});
}
} // namespace openspace

View File

@@ -64,6 +64,7 @@ ModelGeometry* ModelGeometry::createFromDictionary(const ghoul::Dictionary& dict
ModelGeometry::ModelGeometry(const ghoul::Dictionary& dictionary)
: _parent(nullptr)
, _mode(GL_TRIANGLES)
{
setName("ModelGeometry");
using constants::scenegraphnode::keyName;
@@ -90,10 +91,14 @@ ModelGeometry::~ModelGeometry() {
void ModelGeometry::render() {
glBindVertexArray(_vaoID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ibo);
glDrawElements(GL_TRIANGLES, _indices.size(), GL_UNSIGNED_INT, 0);
glDrawElements(_mode, _indices.size(), GL_UNSIGNED_INT, 0);
glBindVertexArray(0);
}
void ModelGeometry::changeRenderMode(const GLenum mode){
_mode = mode;
}
bool ModelGeometry::initialize(RenderableModel* parent) {
_parent = parent;
PowerScaledScalar ps = PowerScaledScalar(1.0, 0.0); // will set proper bounding soon.
@@ -152,7 +157,7 @@ bool ModelGeometry::loadObj(const std::string& filename){
else {
LINFO("Cache for Model'" << filename << "' not found");
}
LINFO("Loading OBJ file '" << filename << "'");
LINFO("Loading Model file '" << filename << "'");
bool success = loadModel(filename);
if (!success)
//return false;

View File

@@ -37,18 +37,22 @@
#include <openspace/util/time.h>
#include <openspace/util/spicemanager.h>
#include <openspace/util/imagesequencer2.h>
#include <openspace/engine/openspaceengine.h>
#include <sgct.h>
#include "imgui.h"
namespace {
const std::string _loggerCat = "RenderableModel";
namespace {
const std::string _loggerCat = "RenderableModel";
const std::string keySource = "Rotation.Source";
const std::string keyDestination = "Rotation.Destination";
const std::string keyBody = "Body";
const std::string keyStart = "StartTime";
const std::string keyEnd = "EndTime";
const std::string keyBody = "Body";
const std::string keyStart = "StartTime";
const std::string keyEnd = "EndTime";
const std::string keyFading = "Shading.Fadeable";
const std::string keyGhosting = "Shading.Ghosting";
}
namespace openspace {
@@ -59,8 +63,11 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary)
, _programObject(nullptr)
, _texture(nullptr)
, _geometry(nullptr)
, _isGhost(false)
, _performShading("performShading", "Perform Shading", true)
, _alpha(1.f)
, _fading("fading", "Fade", 0)
, _performFade("performFading", "Perform Fading", false)
{
std::string name;
bool success = dictionary.getValue(constants::scenegraphnode::keyName, name);
@@ -92,8 +99,23 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary)
dictionary.getValue(keyDestination, _destination);
dictionary.getValue(keyBody, _target);
openspace::SpiceManager::ref().addFrame(_target, _source);
setBoundingSphere(pss(1.f, 9.f));
addProperty(_performShading);
if (dictionary.hasKeyAndValue<bool>(keyFading)) {
bool fading;
dictionary.getValue(keyFading, fading);
_performFade = fading;
}
addProperty(_performFade);
if (dictionary.hasKeyAndValue<bool>(keyGhosting)) {
bool ghosting;
dictionary.getValue(keyGhosting, ghosting);
_isGhost = ghosting;
}
}
bool RenderableModel::isReady() const {
@@ -107,7 +129,7 @@ bool RenderableModel::initialize() {
bool completeSuccess = true;
if (_programObject == nullptr)
completeSuccess
&= OsEng.ref().configurationManager()->getValue("pscShader", _programObject);
&= OsEng.ref().configurationManager()->getValue("GenericModelShader", _programObject);
loadTexture();
@@ -135,6 +157,7 @@ bool RenderableModel::deinitialize() {
void RenderableModel::render(const RenderData& data) {
_programObject->activate();
double lt;
glm::mat4 transform = glm::mat4(1);
glm::mat4 tmp = glm::mat4(1);
@@ -155,6 +178,11 @@ void RenderableModel::render(const RenderData& data) {
}
else
_alpha = 1.0f;
psc tmppos;
SpiceManager::ref().getTargetPosition(_target, "SUN", "GALACTIC", "NONE", time, tmppos, lt);
glm::vec3 cam_dir = glm::normalize(data.camera.position().vec3() - tmppos.vec3());
_programObject->setUniform("cam_dir", cam_dir);
_programObject->setUniform("transparency", _alpha);
_programObject->setUniform("sun_pos", _sunPosition.vec3());
_programObject->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
@@ -163,6 +191,16 @@ void RenderableModel::render(const RenderData& data) {
_programObject->setUniform("_performShading", _performShading);
if (_performFade && _fading > 0.f){
_fading = _fading - 0.01f;
}
else if (!_performFade && _fading < 1.f){
_fading = _fading + 0.01f;
}
_programObject->setUniform("fading", _fading);
// Bind texture
ghoul::opengl::TextureUnit unit;
unit.activate();
@@ -176,12 +214,34 @@ void RenderableModel::render(const RenderData& data) {
}
void RenderableModel::update(const UpdateData& data) {
double _time = data.time;
double futureTime;
if (_isGhost){
futureTime = openspace::ImageSequencer2::ref().getNextCaptureTime();
double remaining = openspace::ImageSequencer2::ref().getNextCaptureTime() - data.time;
double interval = openspace::ImageSequencer2::ref().getIntervalLength();
double t = 1.f - remaining / openspace::ImageSequencer2::ref().getIntervalLength();
if (interval > 60){
if (t < 0.8){
_fading = t;
}
else if (t >= 0.95f){
_fading = _fading - 0.5f;
}
}
else{
_fading = 0.0f;
}
_time = futureTime;
}
// set spice-orientation in accordance to timestamp
if (!_source.empty())
openspace::SpiceManager::ref().getPositionTransformMatrix(_source, _destination, data.time, _stateMatrix);
openspace::SpiceManager::ref().getPositionTransformMatrix(_source, _destination, _time, _stateMatrix);
double lt;
openspace::SpiceManager::ref().getTargetPosition("SUN", _target, "GALACTIC", "NONE", data.time, _sunPosition, lt);
openspace::SpiceManager::ref().getTargetPosition("SUN", _target, "GALACTIC", "NONE", _time, _sunPosition, lt);
}
void RenderableModel::loadTexture() {

View File

@@ -105,7 +105,7 @@ bool WavefrontGeometry::loadModel(const std::string& filename) {
_vertices[j + currentPosition].tex[0] = shapes[i].mesh.texcoords[2 * j + 0];
_vertices[j + currentPosition].tex[1] = shapes[i].mesh.texcoords[2 * j + 1];
}
}
currentPosition += shapes[i].mesh.positions.size() / 3;
@@ -117,7 +117,7 @@ bool WavefrontGeometry::loadModel(const std::string& filename) {
p += shapes[i].mesh.indices.size();
}
return true;
return true;
}

View File

@@ -56,11 +56,14 @@ namespace openspace {
RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
, _colorTexturePath("colorTexture", "Color Texture")
, _nightTexturePath("")
, _programObject(nullptr)
, _texture(nullptr)
, _nightTexture(nullptr)
, _geometry(nullptr)
, _performShading("performShading", "Perform Shading", true)
, _rotation("rotation", "Rotation", 0, 0, 360)
, _hasNightTexture(false)
, _alpha(1.f)
{
std::string name;
@@ -68,8 +71,8 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
ghoul_assert(success,
"RenderablePlanet need the '" <<constants::scenegraphnode::keyName<<"' be specified");
//std::string path;
//success = dictionary.getValue(constants::scenegraph::keyPathModule, path);
std::string path;
success = dictionary.getValue(constants::scenegraph::keyPathModule, path);
//ghoul_assert(success,
// "RenderablePlanet need the '"<<constants::scenegraph::keyPathModule<<"' be specified");
@@ -82,17 +85,26 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
}
dictionary.getValue(keyFrame, _frame);
dictionary.getValue(keyBody, _target);
//assert(b1 == true);
if (_target != "")
setBody(_target);
// TODO: textures need to be replaced by a good system similar to the geometry as soon
// as the requirements are fixed (ab)
std::string texturePath = "";
success = dictionary.getValue("Textures.Color", texturePath);
_colorTexturePath = absPath(texturePath);
//if (success)
//_colorTexturePath = path + "/" + texturePath;
if (success)
_colorTexturePath = path + "/" + texturePath;
std::string nightTexturePath = "";
dictionary.getValue("Textures.Night", nightTexturePath);
if (nightTexturePath != ""){
_hasNightTexture = true;
_nightTexturePath = absPath(nightTexturePath);
_nightTexturePath = path + "/" + nightTexturePath;
}
addPropertySubOwner(_geometry);
@@ -114,8 +126,10 @@ RenderablePlanet::~RenderablePlanet() {
}
bool RenderablePlanet::initialize() {
if (_programObject == nullptr)
OsEng.ref().configurationManager()->getValue("pscShader", _programObject);
if (_programObject == nullptr && _hasNightTexture)
OsEng.ref().configurationManager()->getValue("nightTextureProgram", _programObject);
else if (_programObject == nullptr)
OsEng.ref().configurationManager()->getValue("pscShader", _programObject);
loadTexture();
_geometry->initialize(this);
@@ -128,11 +142,14 @@ bool RenderablePlanet::deinitialize() {
_geometry->deinitialize();
delete _geometry;
}
if(_texture)
if (_texture)
delete _texture;
if (_nightTexture)
delete _nightTexture;
_geometry = nullptr;
_texture = nullptr;
_nightTexture = nullptr;
return true;
}
@@ -181,11 +198,18 @@ void RenderablePlanet::render(const RenderData& data)
_programObject->setUniform("_performShading", _performShading);
// Bind texture
ghoul::opengl::TextureUnit unit;
unit.activate();
ghoul::opengl::TextureUnit dayUnit;
dayUnit.activate();
_texture->bind();
_programObject->setUniform("texture1", unit);
_programObject->setUniform("texture1", dayUnit);
// Bind possible night texture
if (_hasNightTexture) {
ghoul::opengl::TextureUnit nightUnit;
nightUnit.activate();
_nightTexture->bind();
_programObject->setUniform("nightTex", nightUnit);
}
// render
_geometry->render();
@@ -202,8 +226,8 @@ void RenderablePlanet::update(const UpdateData& data){
void RenderablePlanet::loadTexture() {
delete _texture;
_texture = nullptr;
if (_colorTexturePath.value() != "") {
_texture = ghoul::io::TextureReader::ref().loadTexture(_colorTexturePath);
if (_colorTexturePath.value() != "") {
_texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath));
if (_texture) {
LDEBUG("Loaded texture from '" << _colorTexturePath << "'");
_texture->uploadTexture();
@@ -212,6 +236,18 @@ void RenderablePlanet::loadTexture() {
_texture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
}
}
if (_hasNightTexture) {
delete _nightTexture;
_nightTexture = nullptr;
if (_nightTexturePath != "") {
_nightTexture = ghoul::io::TextureReader::ref().loadTexture(absPath(_nightTexturePath));
if (_nightTexture) {
LDEBUG("Loaded texture from '" << _nightTexturePath << "'");
_nightTexture->uploadTexture();
_nightTexture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
}
}
}
}
} // namespace openspace

View File

@@ -36,6 +36,8 @@
#include <openspace/util/time.h>
#include <openspace/util/spicemanager.h>
#include <openspace/util/factorymanager.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/engine/configurationmanager.h>
#include <sgct.h>
@@ -48,17 +50,21 @@
namespace {
const std::string _loggerCat = "RenderablePlanetProjection";
const std::string keyProjObserver = "Projection.Observer";
const std::string keyProjTarget = "Projection.Target";
const std::string keyProjAberration = "Projection.Aberration";
const std::string keyInstrument = "Instrument.Name";
const std::string keyInstrumentFovy = "Instrument.Fovy";
const std::string keyInstrumentAspect = "Instrument.Aspect";
const std::string keyInstrumentNear = "Instrument.Near";
const std::string keyInstrumentFar = "Instrument.Far";
const std::string keySequenceDir = "Projection.Sequence";
const std::string keySequenceType = "Projection.SequenceType";
const std::string keyProjObserver = "Projection.Observer";
const std::string keyProjTarget = "Projection.Target";
const std::string keyProjAberration = "Projection.Aberration";
const std::string keyInstrument = "Instrument.Name";
const std::string keyInstrumentFovy = "Instrument.Fovy";
const std::string keyInstrumentAspect = "Instrument.Aspect";
const std::string keyInstrumentNear = "Instrument.Near";
const std::string keyInstrumentFar = "Instrument.Far";
const std::string keySequenceDir = "Projection.Sequence";
const std::string keySequenceType = "Projection.SequenceType";
const std::string keyPotentialTargets = "PotentialTargets";
const std::string keyTranslation = "DataInputTranslation";
const std::string keyFrame = "Frame";
const std::string keyGeometry = "Geometry";
const std::string keyShading = "PerformShading";
@@ -73,18 +79,21 @@ namespace {
namespace openspace {
//#define ORIGINAL_SEQUENCER
RenderablePlanetProjection::RenderablePlanetProjection(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
, _colorTexturePath("planetTexture", "RGB Texture")
, _projectionTexturePath("projectionTexture", "RGB Texture")
, _imageTrigger("clearProjections", "Clear Projections")
//, _sequencer(nullptr)
, _fadeProjection("fadeProjections", "Image Fading Factor", 0.f, 0.f, 1.f)
, _programObject(nullptr)
, _fboProgramObject(nullptr)
, _texture(nullptr)
, _textureProj(nullptr)
, _textureOriginal(nullptr)
, _geometry(nullptr)
, _rotation("rotation", "Rotation", 0, 0, 360)
, _once(false)
{
std::string name;
bool success = dictionary.getValue(constants::scenegraphnode::keyName, name);
@@ -105,15 +114,17 @@ RenderablePlanetProjection::RenderablePlanetProjection(const ghoul::Dictionary&
_geometry = planetgeometryprojection::PlanetGeometryProjection::createFromDictionary(geometryDictionary);
}
dictionary.getValue(keyFrame, _target);
dictionary.getValue(keyFrame, _frame);
dictionary.getValue(keyBody, _target);
if (_target != "")
setBody(_target);
bool b1 = dictionary.getValue(keyInstrument, _instrumentID);
bool b2 = dictionary.getValue(keyProjObserver, _projectorID);
bool b3 = dictionary.getValue(keyProjTarget, _projecteeID);
bool b4 = dictionary.getValue(keyProjAberration, _aberration);
bool b5 = dictionary.getValue(keyInstrumentFovy, _fovy);
bool b6 = dictionary.getValue(keyInstrumentAspect, _aspectRatio);
bool b5 = dictionary.getValue(keyInstrumentFovy, _fovy);
bool b6 = dictionary.getValue(keyInstrumentAspect, _aspectRatio);
bool b7 = dictionary.getValue(keyInstrumentNear, _nearPlane);
bool b8 = dictionary.getValue(keyInstrumentFar, _farPlane);
@@ -151,34 +162,43 @@ RenderablePlanetProjection::RenderablePlanetProjection(const ghoul::Dictionary&
}
addPropertySubOwner(_geometry);
addProperty(_rotation);
addProperty(_imageTrigger);
_imageTrigger.onChange(std::bind(&RenderablePlanetProjection::loadTexture, this));
addProperty(_fadeProjection);
addProperty(_colorTexturePath);
_colorTexturePath.onChange(std::bind(&RenderablePlanetProjection::loadTexture, this));
addProperty(_projectionTexturePath);
_projectionTexturePath.onChange(std::bind(&RenderablePlanetProjection::loadProjectionTexture, this));
std::string sequenceSource;
bool found = dictionary.getValue(keySequenceDir, sequenceSource);
if (found) {
//LERROR("RenderablePlanetProjection '" << name << "' did not contain a sequence source");
sequenceSource = absPath(sequenceSource);
//sequenceSource = path + ghoul::filesystem::FileSystem::PathSeparator + sequenceSource;
SequenceParser* parser;
std::string sequenceType;
found = dictionary.getValue(keySequenceType, sequenceType);
if (found) {
if (sequenceType == sequenceTypeImage) {
openspace::ImageSequencer::ref().loadSequence(sequenceSource);
}
else if (sequenceType == sequenceTypePlaybook) {
openspace::ImageSequencer::ref().parsePlaybookFile(sequenceSource);
}
else {
LERROR("RenderablePlanetProjection '" << name << "' had unknown sequence type '" << sequenceType << "'");
}
}
// std::string 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 == sequenceTypePlaybook){
parser = new HongKangParser(_sequenceSource,
"NEW HORIZONS",
translationDictionary,
_potentialTargets);
openspace::ImageSequencer2::ref().runSequenceParser(parser);
}
else if (_sequenceType == sequenceTypeImage){
parser = new LabelParser(_sequenceSource, translationDictionary);
openspace::ImageSequencer2::ref().runSequenceParser(parser);
}
}
else{
LWARNING("No playbook translation provided, please make sure all spice calls match playbook!");
}
}
}
@@ -281,6 +301,13 @@ void RenderablePlanetProjection::imageProjectGPU(){
unitFbo.activate();
_textureProj->bind();
_fboProgramObject->setUniform("texture1" , unitFbo);
ghoul::opengl::TextureUnit unitFbo2;
unitFbo2.activate();
_textureOriginal->bind();
_fboProgramObject->setUniform("texture2", unitFbo2);
_fboProgramObject->setUniform("projectionFading", _fadeProjection);
_fboProgramObject->setUniform("ProjectorMatrix", _projectorMatrix);
_fboProgramObject->setUniform("ModelTransform" , _transform);
_fboProgramObject->setUniform("_scaling" , _camScaling);
@@ -314,7 +341,7 @@ void RenderablePlanetProjection::imageProjectGPU(){
m_viewport[2], m_viewport[3]);
}
#include <math.h>
glm::mat4 RenderablePlanetProjection::computeProjectorMatrix(const glm::vec3 loc, glm::dvec3 aim, const glm::vec3 up){
//rotate boresight into correct alignment
_boresight = _instrumentMatrix*aim;
@@ -340,7 +367,7 @@ glm::mat4 RenderablePlanetProjection::computeProjectorMatrix(const glm::vec3 loc
void RenderablePlanetProjection::attitudeParameters(double time){
// precomputations for shader
openspace::SpiceManager::ref().getPositionTransformMatrix(_target, _mainFrame, time, _stateMatrix);
openspace::SpiceManager::ref().getPositionTransformMatrix(_frame, _mainFrame, time, _stateMatrix);
openspace::SpiceManager::ref().getPositionTransformMatrix(_instrumentID, _mainFrame, time, _instrumentMatrix);
_transform = glm::mat4(1);
@@ -366,7 +393,6 @@ void RenderablePlanetProjection::attitudeParameters(double time){
psc position; //observer target
found = SpiceManager::ref().getTargetPosition(_projectorID, _projecteeID, _mainFrame, _aberration, time, position, lightTime);
//if (!found) LERROR("Could not locate target position");
//change to KM and add psc camera scaling.
position[3] += (3 + _camScaling[1]);
@@ -380,21 +406,25 @@ void RenderablePlanetProjection::render(const RenderData& data){
if (!_programObject) return;
if (!_textureProj) return;
_camScaling = data.camera.scaling();
_up = data.camera.lookUpVector();
#ifdef GPU_PROJ
if (_capture){
attitudeParameters(_time[0]);
imageProjectGPU();
for (auto img : _imageTimes){
attitudeParameters(img.startTime); // compute projector viewmatrix
_projectionTexturePath = img.path; // path to current images
imageProjectGPU(); //fbopass
}
_capture = false;
}
#endif
attitudeParameters(_time[1]);
attitudeParameters(_time);
_projectionTexturePath = _defaultProjImage;
psc sun_pos;
double lt;
openspace::SpiceManager::ref().getTargetPosition("SUN", _projecteeID, "GALACTIC", "NONE", _time[1], sun_pos, lt);
openspace::SpiceManager::ref().getTargetPosition("SUN", _projecteeID, "GALACTIC", "NONE", _time, sun_pos, lt);
// Main renderpass
_programObject->activate();
@@ -405,7 +435,7 @@ void RenderablePlanetProjection::render(const RenderData& data){
_programObject->setUniform("ModelTransform" , _transform);
_programObject->setUniform("boresight" , _boresight);
setPscUniforms(_programObject, &data.camera, data.position);
// Bind texture
ghoul::opengl::TextureUnit unit[2];
unit[0].activate();
@@ -414,6 +444,7 @@ void RenderablePlanetProjection::render(const RenderData& data){
unit[1].activate();
_textureProj->bind();
_programObject->setUniform("texture2", unit[1]);
// render geometry
_geometry->render();
// disable shader
@@ -422,34 +453,15 @@ void RenderablePlanetProjection::render(const RenderData& data){
void RenderablePlanetProjection::update(const UpdateData& data){
// set spice-orientation in accordance to timestamp
_time[0] = data.time;
_time[1] = _time[0];
_time = data.time;
_capture = false;
bool _withinFOV;
std::string _fovTarget = "";
for (int i = 0; i < _potentialTargets.size(); i++){
bool success = openspace::SpiceManager::ref().targetWithinFieldOfView(
_instrumentID,
_potentialTargets[i],
_projectorID,
"ELLIPSOID",
_aberration,
_time[0],
_withinFOV);
if (success && _withinFOV){
_fovTarget = _potentialTargets[i];
break;
}
}
if (_projecteeID == _fovTarget){
_next = _defaultProjImage;
if (_time[0] >= openspace::ImageSequencer::ref().getNextCaptureTime()){
_capture = openspace::ImageSequencer::ref().getImagePath(_time[0], _next);
}
_projectionTexturePath = _next;
if (openspace::ImageSequencer2::ref().isReady()){
openspace::ImageSequencer2::ref().updateSequencer(_time);
_capture = openspace::ImageSequencer2::ref().getImagePaths(_imageTimes, _projecteeID, _instrumentID);
}
//floor fading to decimal
//_fadeProjection = floorf(_fadeProjection * 10) / 10;
}
void RenderablePlanetProjection::loadProjectionTexture(){
@@ -458,12 +470,11 @@ void RenderablePlanetProjection::loadProjectionTexture(){
if (_colorTexturePath.value() != "") {
_textureProj = ghoul::io::TextureReader::ref().loadTexture(absPath(_projectionTexturePath));
if (_textureProj) {
_textureProj->uploadTexture();
_textureProj->uploadTexture();
_textureProj->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
_textureProj->setWrapping(ghoul::opengl::Texture::WrappingMode::ClampToBorder);
}
}
//_sequencer->sequenceReset();
}
void RenderablePlanetProjection::loadTexture(){
@@ -476,5 +487,14 @@ void RenderablePlanetProjection::loadTexture(){
_texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
}
}
delete _textureOriginal;
_textureOriginal = nullptr;
if (_colorTexturePath.value() != "") {
_textureOriginal = ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath));
if (_textureOriginal) {
_textureOriginal->uploadTexture();
_textureOriginal->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
}
}
}
} // namespace openspace

View File

@@ -74,7 +74,9 @@ Renderable::Renderable(const ghoul::Dictionary& dictionary)
: _enabled("enabled", "Is Enabled", true),
_hasTimeInterval(false),
_startTime(""),
_endTime("")
_endTime(""),
_targetBody(""),
_hasBody(false)
{
setName("renderable");
#ifndef NDEBUG
@@ -152,6 +154,10 @@ bool Renderable::hasTimeInterval() {
return _hasTimeInterval;
}
bool Renderable::hasBody() {
return _hasBody;
}
bool Renderable::getInterval(double& start, double& end) {
if (_startTime != "" && _endTime != "") {
bool successStart = openspace::SpiceManager::ref().getETfromDate(_startTime, start);
@@ -162,6 +168,20 @@ bool Renderable::getInterval(double& start, double& end) {
return false;
}
bool Renderable::getBody(std::string& body) {
if (_hasBody) {
body = _targetBody;
return true;
}
else
return false;
}
void Renderable::setBody(std::string& body) {
_targetBody = body;
_hasBody = true;
}
bool Renderable::isReady() const {
return true;
}

View File

@@ -29,7 +29,9 @@
#include <openspace/util/constants.h>
#include <openspace/util/spicemanager.h>
#include <openspace/util/imagesequencer.h>
#include <openspace/util/imagesequencer2.h> // testing
#include <openspace/util/time.h>
#include <ghoul/io/texture/texturereader.h>
#include <ghoul/opengl/textureunit.h>
@@ -69,6 +71,7 @@ namespace openspace{
, _lineWidth("lineWidth", "Line Width", 1.f, 1.f, 20.f)
, _programObject(nullptr)
, _texture(nullptr)
, _drawSolid("solidDraw", "Draw as Quads", false)
, _mode(GL_LINES){
bool success = dictionary.getValue(keyBody, _spacecraft);
@@ -98,12 +101,13 @@ namespace openspace{
}
addProperty(_lineWidth);
addProperty(_drawSolid);
}
void RenderableFov::allocateData(){
int points = 8;
int points = 20;
_stride[0] = points;
_isize[0] = points;
_isize[0] = points;
_iarray1[0] = new int[_isize[0]];
for (int i = 0; i < points; i++){
for (int j = 0; j < 4; j++){
@@ -120,7 +124,7 @@ void RenderableFov::allocateData(){
_vtotal[0] = static_cast<int>(_vsize[0] / _stride[0]);
// allocate second vbo data
int cornerPoints = 5;
int cornerPoints = 12;
_isize[1] = cornerPoints;
_iarray1[1] = new int[_isize[1]];
for (int i = 0; i < _isize[1]; i++){
@@ -210,14 +214,6 @@ void RenderableFov::insertPoint(std::vector<float>& arr, psc p, glm::vec4 c){
_nrInserted++;
}
psc RenderableFov::pscInterpolate(psc p0, psc p1, float t){
assert(t >= 0 && t <= 1);
float t2 = (1.f - t);
return PowerScaledCoordinate(t2*p0[0] + t*p1[0],
t2*p0[1] + t*p1[1],
t2*p0[2] + t*p1[2],
t2*p0[3] + t*p1[3]);
}
glm::dvec3 RenderableFov::interpolate(glm::dvec3 p0, glm::dvec3 p1, float t){
assert(t >= 0 && t <= 1);
float t2 = (1.f - t);
@@ -297,49 +293,48 @@ void RenderableFov::fovProjection(bool H[], std::vector<glm::dvec3> bounds){
glm::dvec3 current;
glm::dvec3 next;
glm::vec4 tmp(1);
for (int i = 0; i < 4; i++){
int k = (i + 1 > 3) ? 0 : i + 1;
current = bounds[i];
next = bounds[k];
if (H[i] == false){ // If point is non-interceptive, project it.
insertPoint(_varray2, orthogonalProjection(current), tmp);
}
if (H[i] == true && H[i + 1] == false){ // current point is interceptive, next is not
// find outer most point for interpolation
mid = bisection(current, next, tolerance);
for (int j = 1; j <= _isteps; j++){
t = ((double)j / _isteps);
// TODO: change the interpolate scheme to place points not on a straight line but instead
// using either slerp or some other viable method (goal: eliminate checkForIntercept -method)
interpolated = interpolate(current, mid, t);
_interceptVector = (j < _isteps) ? checkForIntercept(interpolated) : orthogonalProjection(interpolated);
insertPoint(_varray2, _interceptVector, col_sq);
if (bounds.size() > 1){
for (int i = 0; i < bounds.size(); i++){
int k = (i + 1 > bounds.size() - 1) ? 0 : i + 1;
current = bounds[i];
next = bounds[k];
if (H[i] == false){ // If point is non-interceptive, project it.
insertPoint(_varray2, orthogonalProjection(current), tmp);
}
if (H[i] == true && H[i + 1] == false){ // current point is interceptive, next is not
// find outer most point for interpolation
mid = bisection(current, next, tolerance);
for (int j = 1; j <= _isteps; j++){
t = ((double)j / _isteps);
interpolated = interpolate(current, mid, t);
_interceptVector = (j < _isteps) ? checkForIntercept(interpolated) : orthogonalProjection(interpolated);
insertPoint(_varray2, _interceptVector, col_sq);
}
}
if (H[i] == false && H[i + 1] == true){ // current point is non-interceptive, next is
mid = bisection(next, current, tolerance);
for (int j = 1; j <= _isteps; j++){
t = ((double)j / _isteps);
interpolated = interpolate(mid, next, t);
_interceptVector = (j > 1) ? checkForIntercept(interpolated) : orthogonalProjection(interpolated);
insertPoint(_varray2, _interceptVector, col_sq);
}
}
if (H[i] == true && H[i + 1] == true){ // both points intercept
for (int j = 0; j <= _isteps; j++){
t = ((double)j / _isteps);
interpolated = interpolate(current, next, t);
_interceptVector = checkForIntercept(interpolated);
insertPoint(_varray2, _interceptVector, col_sq);
}
}
}
if (H[i] == false && H[i+1] == true){ // current point is non-interceptive, next is
mid = bisection(next, current, tolerance);
for (int j = 1; j <= _isteps; j++){
t = ((double)j / _isteps);
interpolated = interpolate(mid, next, t);
_interceptVector = (j > 1) ? checkForIntercept(interpolated) : orthogonalProjection(interpolated);
insertPoint(_varray2, _interceptVector, col_sq);
}
}
if (H[i] == true && H[i + 1] == true){ // both points intercept
for (int j = 0; j <= _isteps; j++){
t = ((double)j / _isteps);
interpolated = interpolate(current, next, t);
_interceptVector = checkForIntercept(interpolated);
insertPoint(_varray2, _interceptVector, col_sq);
}
}
}
// only if new points are inserted are we interested in rebuilding the
// vbo. Note that this can be optimized but is left as is for now.
}
if (_nrInserted == 0){
_rebuild = false;
}else{
}
else {
_rebuild = true;
//update size etc;
_vtotal[1] = _nrInserted;
@@ -349,7 +344,7 @@ void RenderableFov::fovProjection(bool H[], std::vector<glm::dvec3> bounds){
for (int i = 0; i < _isize[1]; i++)
_iarray1[1][i] = i;
}
}
void RenderableFov::updateData(){
@@ -378,17 +373,17 @@ void RenderableFov::updateData(){
}
}
void RenderableFov::computeColors(){
double t2 = openspace::ImageSequencer::ref().getNextCaptureTime();
double t2 = openspace::ImageSequencer2::ref().getNextCaptureTime();
double diff = (t2 - _time);
double t = 0.0;
if (diff <= 7.0) t = 1.f - diff / 7.0;
if (diff < 0) t = 0.0;
// i need to add an *.h file with colortables....
c_project = glm::vec4(0.0, 1.0, 0.00,1);
col_end = glm::vec4(1.00, 0.29, 0.00, 1);
blue = glm::vec4(0, 0.5, 0.7, 1);
col_gray = glm::vec4(0.3, 0.3, 0.3, 1);
col_gray = glm::vec4(0.7);
col_start = glm::vec4(1.00, 0.89, 0.00, 1);
col_sq = glm::vec4(1.00, 0.29, 0.00, 1);
@@ -403,6 +398,10 @@ void RenderableFov::computeColors(){
col_sq.x = c_project.x*t + col_sq.x*(1 - t);
col_sq.y = c_project.y*t + col_sq.y*(1 - t);
col_sq.z = c_project.z*t + col_sq.z*(1 - t);
blue.w = 0.5;
c_project.w = 0.5;
col_end.w = 0.5;
}
void RenderableFov::render(const RenderData& data){
@@ -411,36 +410,24 @@ void RenderableFov::render(const RenderData& data){
// fetch data
glm::mat4 transform(1);
glm::mat4 tmp = glm::mat4(1);
glm::mat4 spacecraftRot = glm::mat4(1);
for (int i = 0; i < 3; i++){
for (int j = 0; j < 3; j++){
tmp[i][j] = _stateMatrix[i][j];
spacecraftRot[i][j] = _stateMatrix[i][j];
}
}
bool drawFOV = false;
// setup the data to the shader
_programObject->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
_programObject->setUniform("ModelTransform", transform);
setPscUniforms(_programObject, &data.camera, data.position);
ImageSequencer::ref().findActiveInstrument(_time);
std::string instrument = ImageSequencer::ref().getActiveInstrument();
bool drawFOV = false;
if (instrument == "MVIC"){
if (_instrumentID == "NH_RALPH_MVIC_PAN1" ||
_instrumentID == "NH_RALPH_MVIC_PAN2" ||
_instrumentID == "NH_RALPH_MVIC_RED" ||
_instrumentID == "NH_RALPH_MVIC_BLUE" ||
_instrumentID == "NH_RALPH_MVIC_FT"){
drawFOV = true;
}
}
else if (instrument == _instrumentID){
drawFOV = true;
if (openspace::ImageSequencer2::ref().isReady()){
drawFOV = ImageSequencer2::ref().instumentActive(_instrumentID);
}
if (drawFOV){
// update only when time progresses.
if (_oldTime != _time){
@@ -477,19 +464,20 @@ void RenderableFov::render(const RenderData& data){
double targetEpoch;
// for each FOV vector
for (int i = 0; i < 4; i++){
for (int i = 0; i <= bounds.size(); i++){
int r = (i == bounds.size()) ? 0 : i;
// compute surface intercept
openspace::SpiceManager::ref().getSurfaceIntercept(_fovTarget, _spacecraft, _instrumentID,
_frame, _method, _aberrationCorrection,
_time, targetEpoch, bounds[i], ipoint, ivec, _interceptTag[i]);
_time, targetEpoch, bounds[r], ipoint, ivec, _interceptTag[r]);
// if not found, use the orthogonal projected point
if (!_interceptTag[i]) _projectionBounds[i] = orthogonalProjection(bounds[i]);
if (!_interceptTag[r]) _projectionBounds[r] = orthogonalProjection(bounds[r]);
// VBO1 : draw vectors representing outer points of FOV.
if (_interceptTag[i]){
if (_interceptTag[r]){
_interceptVector = PowerScaledCoordinate::CreatePowerScaledCoordinate(ivec[0], ivec[1], ivec[2]);
_interceptVector[3] += 3;
//_interceptVector = pscInterpolate(_interceptVector, bsvec, t);
// INTERCEPTIONS
memcpy(&_varray1[indx], glm::value_ptr(glm::vec4(0)), size);
indx += 4;
@@ -506,14 +494,14 @@ void RenderableFov::render(const RenderData& data){
indx += 4;
memcpy(&_varray1[indx], glm::value_ptr(glm::vec4(0, 0, 1, 1)), size);
indx += 4;
memcpy(&_varray1[indx], glm::value_ptr(_projectionBounds[i].vec4()), size);
memcpy(&_varray1[indx], glm::value_ptr(_projectionBounds[r].vec4()), size);
indx += 4;
memcpy(&_varray1[indx], glm::value_ptr(blue), size);
indx += 4;
}
else{
glm::vec4 corner(bounds[i][0], bounds[i][1], bounds[i][2], data.position[3] + 1);
corner = tmp*corner;
glm::vec4 corner(bounds[r][0], bounds[r][1], bounds[r][2], data.position[3] + 2);
corner = spacecraftRot*corner;
// "INFINITE" FOV
memcpy(&_varray1[indx], glm::value_ptr(glm::vec4(0)), size);
indx += 4;
@@ -525,37 +513,53 @@ void RenderableFov::render(const RenderData& data){
indx += 4;
}
}
_interceptTag[4] = _interceptTag[0]; // 0 & 5 same point
fovProjection(_interceptTag, bounds);
_interceptTag[bounds.size()] = _interceptTag[0];
if (!(_instrumentID == "NH_LORRI")) // image plane replaces fov square
fovProjection(_interceptTag, bounds);
updateData();
glm::vec3 aim = (spacecraftRot * glm::vec4(boresight, 1)).xyz;
psc position;
double lt;
SpiceManager::ref().getTargetPosition(_fovTarget,
_spacecraft,
_frame,
_aberrationCorrection,
_time,
position,
lt);
//if aimed 80 deg away from target, dont draw white square
if (glm::dot(glm::normalize(aim), glm::normalize(position.vec3())) < 0.2){
drawFOV = false;
}
}
_oldTime = _time;
if (!_drawSolid) _mode = GL_LINES;
else _mode = GL_TRIANGLE_STRIP;
glLineWidth(_lineWidth);
glBindVertexArray(_vaoID[0]);
glDrawArrays(_mode, 0, _vtotal[0]);
glBindVertexArray(0);
//render points
glPointSize(2.f);
glLineWidth(_lineWidth);
glBindVertexArray(_vaoID[0]);
glDrawArrays(GL_POINTS, 0, _vtotal[0]);
glDrawArrays(GL_LINES, 0, _vtotal[0]);
glBindVertexArray(0);
//second vbo
if (_withinFOV){
if (drawFOV){
glLineWidth(1.f);
glBindVertexArray(_vaoID[1]);
glDrawArrays(GL_LINE_LOOP, 0, _vtotal[1]);
glBindVertexArray(0);
}
glLineWidth(1.f);
/*glPointSize(5.f);
glBindVertexArray(_vaoID2);
glDrawArrays(GL_POINTS, 0, _vtotal2);
glBindVertexArray(0);
*/
}
_programObject->deactivate();
}

View File

@@ -22,6 +22,7 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <openspace/engine/configurationmanager.h>
#include <openspace/rendering/renderableplane.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/util/powerscaledcoordinate.h>
@@ -125,14 +126,10 @@ bool RenderablePlane::initialize() {
glGenBuffers(1, &_vertexPositionBuffer); // generate buffer
createPlane();
// Plane program
_shader = ghoul::opengl::ProgramObject::Build("Plane",
"${SHADERS}/modules/plane/plane_vs.glsl",
"${SHADERS}/modules/plane/plane_fs.glsl");
if (!_shader)
return false;
_shader->setProgramObjectCallback([&](ghoul::opengl::ProgramObject*){ _programIsDirty = true; });
if (_shader == nullptr)
OsEng.ref().configurationManager()->getValue("planeProgram", _shader);
_shader->setProgramObjectCallback([&](ghoul::opengl::ProgramObject*){ _programIsDirty = true; });
loadTexture();
return isReady();
@@ -144,7 +141,6 @@ bool RenderablePlane::deinitialize() {
glDeleteBuffers(1, &_vertexPositionBuffer);
_vertexPositionBuffer = 0;
delete _texture;
delete _shader;
return true;
}
@@ -196,7 +192,7 @@ void RenderablePlane::loadTexture() {
texture->uploadTexture();
// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
texture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
if (_texture)
delete _texture;

View File

@@ -0,0 +1,328 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2015 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <openspace/rendering/renderableplaneprojection.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/engine/configurationmanager.h>
#include <openspace/util/constants.h>
#include <openspace/scene/scenegraphnode.h>
#include <openspace/util/spicemanager.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/scene/staticephemeris.h>
#include <openspace/scene/dynamicephemeris.h>
#include <ghoul/filesystem/filesystem>
#include <ghoul/io/texture/texturereader.h>
#include <ghoul/opengl/programobject.h>
#include <ghoul/opengl/texture.h>
#include <ghoul/opengl/textureunit.h>
#include <openspace/util/time.h>
namespace {
const std::string _loggerCat = "RenderablePlaneProjection";
}
namespace openspace {
using namespace constants::renderableplaneprojection;
RenderablePlaneProjection::RenderablePlaneProjection(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
, _shader(nullptr)
, _programIsDirty(false)
, _texture(nullptr)
, _textureIsDirty(false)
, _quad(0)
, _vertexPositionBuffer(0)
, _name("ImagePlane")
, _texturePath("")
, _planeIsDirty(false)
{
dictionary.getValue(keySpacecraft, _spacecraft);
dictionary.getValue(keyInstrument, _instrument);
dictionary.getValue(keyMoving, _moving);
dictionary.getValue(keyName, _name);
std::string texturePath = "";
bool success = dictionary.getValue(keyTexture, _texturePath);
if (success) {
_texturePath = findPath(_texturePath);
_textureFile = new ghoul::filesystem::File(_texturePath);
}
loadTexture();
}
RenderablePlaneProjection::~RenderablePlaneProjection() {
delete _textureFile;
}
bool RenderablePlaneProjection::isReady() const {
bool ready = true;
if (!_shader)
ready &= false;
if (!_texture)
ready &= false;
return ready;
}
bool RenderablePlaneProjection::initialize() {
glGenVertexArrays(1, &_quad); // generate array
glGenBuffers(1, &_vertexPositionBuffer); // generate buffer
// Plane program
if (_shader == nullptr)
OsEng.ref().configurationManager()->getValue("imagePlaneProgram", _shader);
setTarget("JUPITER");
loadTexture();
return isReady();
}
bool RenderablePlaneProjection::deinitialize() {
glDeleteVertexArrays(1, &_quad);
_quad = 0;
glDeleteBuffers(1, &_vertexPositionBuffer);
_vertexPositionBuffer = 0;
delete _texture;
return true;
}
void RenderablePlaneProjection::render(const RenderData& data) {
glm::mat4 transform = glm::mat4(1.0);
for (int i = 0; i < 3; i++){
for (int j = 0; j < 3; j++){
transform[i][j] = static_cast<float>(_stateMatrix[i][j]);
}
}
// Activate shader
_shader->activate();
_shader->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
_shader->setUniform("ModelTransform", transform);
setPscUniforms(_shader, &data.camera, data.position);
data.position;
ghoul::opengl::TextureUnit unit;
unit.activate();
_texture->bind();
_shader->setUniform("texture1", unit);
glBindVertexArray(_quad);
glDrawArrays(GL_TRIANGLES, 0, 6);
_shader->deactivate();
}
void RenderablePlaneProjection::update(const UpdateData& data) {
double time = data.time;
const Image* img = openspace::ImageSequencer2::ref().getLatestImageForInstrument(_instrument);
openspace::SpiceManager::ref().getPositionTransformMatrix(_target.frame, galacticFrame, time, _stateMatrix);
std::string tex = _texturePath;
if (_moving || _planeIsDirty)
updatePlane(img, time);
else if (img != nullptr && img->path != tex) {
time = img->startTime;
updatePlane(img, time);
}
if (_programIsDirty) {
_shader->rebuildFromFile();
_programIsDirty = false;
}
if (_textureIsDirty) {
loadTexture();
_textureIsDirty = false;
}
}
void RenderablePlaneProjection::loadTexture() {
if (_texturePath != "") {
ghoul::opengl::Texture* texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_texturePath));
if (texture) {
texture->uploadTexture();
texture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
if (_texture)
delete _texture;
_texture = texture;
delete _textureFile;
_textureFile = new ghoul::filesystem::File(_texturePath);
_textureFile->setCallback([&](const ghoul::filesystem::File&) { _textureIsDirty = true; });
}
}
}
void RenderablePlaneProjection::updatePlane(const Image* img, double currentTime) {
std::string shape, frame;
std::vector<glm::dvec3> bounds;
glm::dvec3 boresight;
std::string target = "JUPITER"; //default
if (!_moving) {
// target = findClosestTarget(currentTime);
}
if (img != nullptr)
target = img->target;
setTarget(target);
bool found = openspace::SpiceManager::ref().getFieldOfView(_instrument, shape, frame, boresight, bounds);
if (!found) {
LERROR("Could not locate instrument");
return;
}
glm::dvec3 vecToTarget;
double lt;
psc projection[4];
SpiceManager::ref().getTargetPosition(_target.body, _spacecraft, galacticFrame, "CN+S", currentTime, vecToTarget, lt);
// The apparent position, CN+S, makes image align best with target
for (int j = 0; j < bounds.size(); ++j) {
openspace::SpiceManager::ref().frameConversion(bounds[j], frame, galacticFrame, currentTime);
glm::dvec3 cornerPosition = openspace::SpiceManager::ref().orthogonalProjection(vecToTarget, bounds[j]);
if (!_moving) {
cornerPosition -= vecToTarget;
}
openspace::SpiceManager::ref().frameConversion(cornerPosition, galacticFrame, _target.frame, currentTime);
projection[j] = PowerScaledCoordinate::CreatePowerScaledCoordinate(cornerPosition[0], cornerPosition[1], cornerPosition[2]);
projection[j][3] += 3;
}
if (!_moving) {
SceneGraphNode* thisNode = OsEng.renderEngine()->scene()->sceneGraphNode(_name);
SceneGraphNode* newParent = OsEng.renderEngine()->scene()->sceneGraphNode(_target.node);
if (thisNode != nullptr && newParent != nullptr)
thisNode->setParent(newParent);
}
const GLfloat vertex_data[] = { // square of two triangles drawn within fov in target coordinates
// x y z w s t
projection[1][0], projection[1][1], projection[1][2], projection[1][3], 0, 1, // Lower left 1
projection[3][0], projection[3][1], projection[3][2], projection[3][3], 1, 0, // Upper right 2
projection[2][0], projection[2][1], projection[2][2], projection[2][3], 0, 0, // Upper left 3
projection[1][0], projection[1][1], projection[1][2], projection[1][3], 0, 1, // Lower left 4 = 1
projection[0][0], projection[0][1], projection[0][2], projection[0][3], 1, 1, // Lower right 5
projection[3][0], projection[3][1], projection[3][2], projection[3][3], 1, 0, // Upper left 6 = 2
};
glBindVertexArray(_quad); // bind array
glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer); // bind buffer
glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast<void*>(0));
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast<void*>(sizeof(GLfloat) * 4));
if (!_moving && img != nullptr) {
_texturePath = img->path;
loadTexture();
}
}
void RenderablePlaneProjection::setTarget(std::string body) {
if (body == "")
return;
std::vector<SceneGraphNode*> nodes = OsEng.renderEngine()->scene()->allSceneGraphNodes();
Renderable* possibleTarget;
bool hasBody, found = false;
std::string targetBody;
for (auto node : nodes)
{
possibleTarget = node->renderable();
if (possibleTarget != nullptr) {
hasBody = possibleTarget->hasBody();
if (hasBody && possibleTarget->getBody(targetBody) && (targetBody == body)) {
_target.node = node->name(); // get name from propertyOwner
found = true;
break;
}
}
}
if (found) {
_target.body = body;
_target.frame = openspace::SpiceManager::ref().frameFromBody(body);
}
}
std::string RenderablePlaneProjection::findClosestTarget(double currentTime) {
std::vector<std::string> targets;
std::vector<SceneGraphNode*> nodes = OsEng.renderEngine()->scene()->allSceneGraphNodes();
Renderable* possibleTarget;
std::string targetBody;
bool hasBody, found = false;
PowerScaledScalar min = PowerScaledScalar::CreatePSS(9999999999999);
PowerScaledScalar distance = PowerScaledScalar::CreatePSS(0.0);
std::string closestTarget = "";
psc spacecraftPos;
double lt;
SpiceManager::ref().getTargetPosition(_spacecraft, "SSB", galacticFrame, "NONE", currentTime, spacecraftPos, lt);
for (auto node : nodes)
{
possibleTarget = node->renderable();
if (possibleTarget != nullptr) {
hasBody = possibleTarget->hasBody();
if (hasBody && possibleTarget->getBody(targetBody)) {
openspace::SpiceManager::ref().targetWithinFieldOfView(_instrument, targetBody, _spacecraft, "ELLIPSOID", "NONE", currentTime, found);
if (found){
targets.push_back(node->name()); // get name from propertyOwner
distance = (node->worldPosition() - spacecraftPos).length();
if (distance < min)
closestTarget = targetBody;
}
}
}
}
return closestTarget;
}
} // namespace openspace

View File

@@ -30,6 +30,9 @@
#include <openspace/util/updatestructures.h>
#include <ghoul/opengl/programobject.h>
#include <ghoul/misc/highresclock.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/interaction/interactionhandler.h>
/* TODO for this class:
* In order to add geometry shader (for pretty-draw),
@@ -40,6 +43,7 @@
namespace {
const std::string _loggerCat = "RenderableTrail";
//constants
const std::string keyName = "Name";
const std::string keyBody = "Body";
const std::string keyObserver = "Observer";
const std::string keyFrame = "Frame";
@@ -48,6 +52,7 @@ namespace {
const std::string keyTropicalOrbitPeriod = "TropicalOrbitPeriod";
const std::string keyEarthOrbitRatio = "EarthOrbitRatio";
const std::string keyDayLength = "DayLength";
const std::string keyStamps = "Timestamps";
}
namespace openspace {
@@ -56,7 +61,7 @@ RenderableTrail::RenderableTrail(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
, _lineColor("lineColor", "Line Color")
, _lineFade("lineFade", "Line Fade", 0.75f, 0.f, 5.f)
, _lineWidth("lineWidth", "Line Width", 1.f, 1.f, 20.f)
, _lineWidth("lineWidth", "Line Width", 2.f, 1.f, 20.f)
, _programObject(nullptr)
, _programIsDirty(true)
, _vaoID(0)
@@ -64,6 +69,7 @@ RenderableTrail::RenderableTrail(const ghoul::Dictionary& dictionary)
, _oldTime(std::numeric_limits<float>::max())
, _successfullDictionaryFetch(true)
, _needsSweep(true)
, _showTimestamps("timestamps", "Show Timestamps", false)
{
_successfullDictionaryFetch &= dictionary.getValue(keyBody, _target);
_successfullDictionaryFetch &= dictionary.getValue(keyObserver, _observer);
@@ -78,13 +84,19 @@ RenderableTrail::RenderableTrail(const ghoul::Dictionary& dictionary)
glm::vec3 color(0.f);
if (dictionary.hasKeyAndValue<glm::vec3>(keyColor))
dictionary.getValue(keyColor, color);
_lineColor = color;
_lineColor.setViewOption(properties::Property::ViewOptions::Color);
_lineColor = color;
if (dictionary.hasKeyAndValue<bool>(keyStamps))
dictionary.getValue(keyStamps, _showTimestamps);
addProperty(_showTimestamps);
_lineColor.setViewOption(properties::Property::ViewOptions::Color);
addProperty(_lineColor);
addProperty(_lineFade);
addProperty(_lineWidth);
_distanceFade = 1.0;
}
bool RenderableTrail::initialize() {
@@ -138,6 +150,19 @@ void RenderableTrail::render(const RenderData& data) {
_programObject->setUniform("nVertices", static_cast<unsigned int>(_vertexArray.size()));
_programObject->setUniform("lineFade", _lineFade);
const psc& position = data.camera.position();
const psc& origin = openspace::OpenSpaceEngine::ref().interactionHandler()->focusNode()->worldPosition();
const PowerScaledScalar& pssl = (position - origin).length();
if (pssl[0] < 0.000001){
if (_distanceFade > 0.0f) _distanceFade -= 0.05f;
_programObject->setUniform("forceFade", _distanceFade);
}
else{
if (_distanceFade < 1.0f) _distanceFade += 0.05f;
_programObject->setUniform("forceFade", _distanceFade);
}
glLineWidth(_lineWidth);
glBindVertexArray(_vaoID);
@@ -146,6 +171,13 @@ void RenderableTrail::render(const RenderData& data) {
glLineWidth(1.f);
if (_showTimestamps){
glPointSize(5.f);
glBindVertexArray(_vaoID);
glDrawArrays(GL_POINTS, 0, _vertexArray.size());
glBindVertexArray(0);
}
_programObject->deactivate();
}
@@ -247,7 +279,7 @@ void RenderableTrail::fullYearSweep(double time) {
_oldTime = time;
psc pscPos, pscVel;
psc pscPos;
bool validPosition = true;
_vertexArray.resize(segments+2);
for (int i = 0; i < segments+2; i++) {

View File

@@ -24,6 +24,9 @@
#include <openspace/rendering/renderengine.h>
#include <openspace/util/imagesequencer2.h>
#include <openspace/abuffer/abuffervisualizer.h>
#include <openspace/abuffer/abuffer.h>
#include <openspace/abuffer/abufferframebuffer.h>
@@ -39,7 +42,6 @@
#include <openspace/util/screenlog.h>
#include <openspace/util/spicemanager.h>
#include <openspace/util/syncbuffer.h>
#include <openspace/util/imagesequencer.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/lua/lua_helper.h>
#include <ghoul/misc/sharedmemory.h>
@@ -430,8 +432,6 @@ namespace openspace {
Time::ref().deltaTime(),
_doPerformanceMeasurements
});
_sceneGraph->evaluate(_mainCamera);
// clear the abuffer before rendering the scene
@@ -507,56 +507,6 @@ namespace openspace {
sgct::Engine::instance()->getActiveWindowPtr()->getCurrentViewportPixelCoords(x1, y1, xSize, ySize);
int startY = ySize - 2 * font_size_mono;
double currentTime = Time::ref().currentTime();
ImageSequencer::ref().findActiveInstrument(currentTime);
double remaining = openspace::ImageSequencer::ref().getNextCaptureTime() - currentTime;
double t = 1.f - remaining / openspace::ImageSequencer::ref().getIntervalLength();
std::string progress = "|";
int g = ((t)* 20) + 1;
for (int i = 0; i < g; i++) progress.append("-"); progress.append(">");
for (int i = 0; i < 21 - g; i++) progress.append(" ");
std::string str = "";
openspace::SpiceManager::ref().getDateFromET(openspace::ImageSequencer::ref().getNextCaptureTime(), str);
Freetype::print(font,
_onScreenInformation._position.x * xSize,
_onScreenInformation._position.y * ySize,
"Date: %s",
Time::ref().currentTimeUTC().c_str()
);
progress.append("|");
if (remaining > 0){
glm::vec4 g1(0, t, 0, 1);
glm::vec4 g2(1 - t);
Freetype::print(font,
_onScreenInformation._position.x * xSize,
_onScreenInformation._position.y * ySize - font_size_mono * 2,
g1 + g2,
"Next projection in | %.0f seconds",
remaining
);
Freetype::print(font,
_onScreenInformation._position.x * xSize,
_onScreenInformation._position.y * ySize - font_size_mono * 2 * 2,
g1 + g2,
"%s %.1f %%",
progress.c_str(), t * 100
);
}
std::string active = ImageSequencer::ref().getActiveInstrument();
Freetype::print(font,
_onScreenInformation._position.x * xSize,
_onScreenInformation._position.y * ySize - font_size_mono * 3 * 2,
glm::vec4(0.3, 0.6, 1, 1),
"Active Instrument : %s",
active.c_str()
);
}
}
@@ -583,46 +533,106 @@ namespace openspace {
// Next 2 lines neccesary for instrument switching to work.
double currentTime = Time::ref().currentTime();
ImageSequencer::ref().findActiveInstrument(currentTime);
// GUI PRINT
// Using a macro to shorten line length and increase readability
int i = 0;
PrintText(i++, "Date: %s", Time::ref().currentTimeUTC().c_str());
PrintText(i++, "Avg. Frametime: %.5f", sgct::Engine::instance()->getAvgDt());
PrintText(i++, "Drawtime: %.5f", sgct::Engine::instance()->getDrawTime());
PrintText(i++, "Frametime: %.5f", sgct::Engine::instance()->getDt());
/*
PrintText(i++, "Origin: (% .5f, % .5f, % .5f, % .5f)", origin[0], origin[1], origin[2], origin[3]);
PrintText(i++, "Cam pos: (% .5f, % .5f, % .5f, % .5f)", position[0], position[1], position[2], position[3]);
PrintText(i++, "View dir: (% .5f, % .5f, % .5f)", viewdirection[0], viewdirection[1], viewdirection[2]);
PrintText(i++, "Cam->origin: (% .15f, % .4f)", pssl[0], pssl[1]);
PrintText(i++, "Scaling: (% .5f, % .5f)", scaling[0], scaling[1]);
*/
if (openspace::ImageSequencer2::ref().isReady()) {
double remaining = openspace::ImageSequencer2::ref().getNextCaptureTime() - currentTime;
double t = 1.f - remaining / openspace::ImageSequencer2::ref().getIntervalLength();
std::string progress = "|";
int g = ((t)* 30) + 1;
for (int i = 0; i < g; i++) progress.append("-"); progress.append(">");
for (int i = 0; i < 31 - g; i++) progress.append(" ");
double remaining = openspace::ImageSequencer::ref().getNextCaptureTime() - currentTime;
double t = 1.f - remaining / openspace::ImageSequencer::ref().getIntervalLength();
std::string progress = "|";
int g = ((t)* 20) + 1;
for (int i = 0; i < g; i++) progress.append("-"); progress.append(">");
for (int i = 0; i < 21 - g; i++) progress.append(" ");
std::string str = "";
openspace::SpiceManager::ref().getDateFromET(openspace::ImageSequencer2::ref().getNextCaptureTime(), str);
std::string str = "";
openspace::SpiceManager::ref().getDateFromET(openspace::ImageSequencer::ref().getNextCaptureTime(), str);
progress.append("|");
if (remaining > 0){
glm::vec4 g1(0, t, 0, 1);
glm::vec4 g2(1 - t);
PrintColorText(i++, "Next projection in:", 10, g1 + g2);
PrintColorText(i++, "%.0f sec %s %.1f %%", 10, g1 + g2, remaining, progress.c_str(), t * 100);
}
glm::vec4 w(1);
PrintColorText(i++, "Ucoming capture : %s", 10, w, str.c_str());
std::pair<double, std::string> nextTarget = ImageSequencer2::ref().getNextTarget();
std::pair<double, std::string> currentTarget = ImageSequencer2::ref().getCurrentTarget();
progress.append("|");
if (remaining > 0){
glm::vec4 g1(0, t, 0, 1);
glm::vec4 g2(1 - t);
PrintColorText(i++, "Next projection in | %.0f seconds", 10, g1 + g2, remaining);
PrintColorText(i++, "%s %.1f %%", 10, g1 + g2, progress.c_str(), t * 100);
if (currentTarget.first > 0.0) {
int timeleft = nextTarget.first - currentTime;
int hour = timeleft / 3600;
int second = timeleft % 3600;
int minute = second / 60;
second = second % 60;
std::string hh, mm, ss, coundtown;
if (hour < 10) hh.append("0");
if (minute < 10) mm.append("0");
if (second < 10) ss.append("0");
hh.append(std::to_string(hour));
mm.append(std::to_string(minute));
ss.append(std::to_string(second));
glm::vec4 b2(1.00, 0.51, 0.00, 1);
PrintColorText(i++, "Switching observation focus in : [%s:%s:%s]", 10, b2, hh.c_str(), mm.c_str(), ss.c_str());
std::pair<double, std::vector<std::string>> incidentTargets = ImageSequencer2::ref().getIncidentTargetList(2);
std::string space;
glm::vec4 color;
int isize = incidentTargets.second.size();
for (int p = 0; p < isize; p++){
double t = (double)(p + 1) / (double)(isize+1);
t = (p > isize / 2) ? 1-t : t;
t += 0.3;
color = (p == isize / 2) ? glm::vec4(1.00, 0.51, 0.00, 1) : glm::vec4(t, t, t, 1);
PrintColorText(i, "%s%s", 10, color, space.c_str(), incidentTargets.second[p].c_str());
for (int k = 0; k < 10; k++){ space += " "; }
}
i++;
std::map<std::string, bool> activeMap = ImageSequencer2::ref().getActiveInstruments();
glm::vec4 active(0.58, 1, 0.00, 1);
glm::vec4 firing(0.58-t, 1-t, 1-t, 1);
glm::vec4 notFiring(0.5, 0.5, 0.5, 1);
PrintColorText(i++, "Active Instruments : ", 10, active);
for (auto t : activeMap){
if (t.second == false){
PrintColorText(i, "| |", 10, glm::vec4(0.3, 0.3, 0.3, 1));
PrintColorText(i++, " %5s", 10, glm::vec4(0.3, 0.3, 0.3, 1), t.first.c_str());
}
else{
PrintColorText(i, "|", 10, glm::vec4(0.3, 0.3, 0.3, 1));
if (t.first == "NH_LORRI"){
PrintColorText(i, " + ", 10, firing);
}
PrintColorText(i, " |", 10, glm::vec4(0.3, 0.3, 0.3, 1));
PrintColorText(i++, " %5s", 10, active, t.first.c_str());
}
}
}
}
glm::vec4 w(1);
glm::vec4 b(0.3, 0.6, 1, 1);
PrintColorText(i++, "Ucoming : %s", 10, w, str.c_str());
std::string active = ImageSequencer::ref().getActiveInstrument();
PrintColorText(i++, "Active Instrument : %s", 10, b, active.c_str());
#undef PrintText
}
@@ -965,41 +975,53 @@ void RenderEngine::changeViewPoint(std::string origin) {
SceneGraphNode* solarSystemBarycenterNode = scene()->sceneGraphNode("SolarSystemBarycenter");
SceneGraphNode* plutoBarycenterNode = scene()->sceneGraphNode("PlutoBarycenter");
SceneGraphNode* newHorizonsNode = scene()->sceneGraphNode("NewHorizons");
SceneGraphNode* newHorizonsTrailNode = scene()->sceneGraphNode("NewHorizonsTrail");
SceneGraphNode* jupiterBarycenterNode = scene()->sceneGraphNode("JupiterBarycenter");
//SceneGraphNode* newHorizonsGhostNode = scene()->sceneGraphNode("NewHorizonsGhost");
//SceneGraphNode* dawnNode = scene()->sceneGraphNode("Dawn");
//SceneGraphNode* vestaNode = scene()->sceneGraphNode("Vesta");
if (solarSystemBarycenterNode == nullptr || plutoBarycenterNode == nullptr ||
newHorizonsNode == nullptr || jupiterBarycenterNode == nullptr
//|| dawnNode == nullptr
//|| vestaNode == nullptr
//|| vestaNode == nullptr
) {
LERROR("Necessary nodes does not exist");
return;
}
if (origin == "Pluto") {
ghoul::Dictionary solarDictionary =
{
{ std::string("Type"), std::string("Spice") },
{ std::string("Body") , std::string("SUN") },
{ std::string("Reference"), std::string("ECLIPJ2000") },
{ std::string("Observer") , std::string("PLUTO BARYCENTER") },
{ std::string("Kernels") , ghoul::Dictionary() }
};
plutoBarycenterNode->setParent(scene()->sceneGraphNode("SolarSystem"));
plutoBarycenterNode->setEphemeris(new StaticEphemeris);
solarSystemBarycenterNode->setParent(plutoBarycenterNode);
newHorizonsNode->setParent(plutoBarycenterNode);
//newHorizonsGhostNode->setParent(plutoBarycenterNode);
//dawnNode->setParent(plutoBarycenterNode);
//vestaNode->setParent(plutoBarycenterNode);
//newHorizonsTrailNode->setParent(plutoBarycenterNode);
ghoul::Dictionary solarDictionary =
{
{ std::string("Type"), std::string("Spice") },
{ std::string("Body"), std::string("SUN") },
{ std::string("Reference"), std::string("GALACTIC") },
{ std::string("Observer"), std::string("PLUTO BARYCENTER") },
{ std::string("Kernels"), ghoul::Dictionary() }
};
ghoul::Dictionary jupiterDictionary =
{
{ std::string("Type"), std::string("Spice") },
{ std::string("Body"), std::string("JUPITER BARYCENTER") },
{ std::string("Reference"), std::string("ECLIPJ2000") },
{ std::string("Observer"), std::string("SUN") },
{ std::string("Reference"), std::string("GALACTIC") },
{ std::string("Observer"), std::string("PLUTO BARYCENTER") },
{ std::string("Kernels"), ghoul::Dictionary() }
};
solarSystemBarycenterNode->setEphemeris(new SpiceEphemeris(solarDictionary));
jupiterBarycenterNode->setEphemeris(new SpiceEphemeris(jupiterDictionary));
plutoBarycenterNode->setEphemeris(new StaticEphemeris);
ghoul::Dictionary newHorizonsDictionary =
{
{ std::string("Type"), std::string("Spice") },
@@ -1008,7 +1030,12 @@ void RenderEngine::changeViewPoint(std::string origin) {
{ std::string("Observer"), std::string("PLUTO BARYCENTER") },
{ std::string("Kernels"), ghoul::Dictionary() }
};
solarSystemBarycenterNode->setEphemeris(new SpiceEphemeris(solarDictionary));
jupiterBarycenterNode->setEphemeris(new SpiceEphemeris(jupiterDictionary));
newHorizonsNode->setEphemeris(new SpiceEphemeris(newHorizonsDictionary));
//newHorizonsTrailNode->setEphemeris(new SpiceEphemeris(newHorizonsDictionary));
//ghoul::Dictionary dawnDictionary =
//{
@@ -1030,14 +1057,37 @@ void RenderEngine::changeViewPoint(std::string origin) {
//};
//vestaNode->setEphemeris(new SpiceEphemeris(vestaDictionary));
//ghoul::Dictionary newHorizonsGhostDictionary =
//{
// { std::string("Type"), std::string("Spice") },
// { std::string("Body"), std::string("NEW HORIZONS") },
// { std::string("EphmerisGhosting"), std::string("TRUE") },
// { std::string("Reference"), std::string("GALACTIC") },
// { std::string("Observer"), std::string("PLUTO BARYCENTER") },
// { std::string("Kernels"), ghoul::Dictionary() }
//};
//newHorizonsGhostNode->setEphemeris(new SpiceEphemeris(newHorizonsGhostDictionary));
return;
}
if (origin == "Sun") {
solarSystemBarycenterNode->setParent(scene()->sceneGraphNode("SolarSystem"));
plutoBarycenterNode->setParent(solarSystemBarycenterNode);
jupiterBarycenterNode->setParent(solarSystemBarycenterNode);
newHorizonsNode->setParent(solarSystemBarycenterNode);
//newHorizonsGhostNode->setParent(solarSystemBarycenterNode);
//newHorizonsTrailNode->setParent(solarSystemBarycenterNode);
//dawnNode->setParent(solarSystemBarycenterNode);
//vestaNode->setParent(solarSystemBarycenterNode);
ghoul::Dictionary plutoDictionary =
{
{ std::string("Type"), std::string("Spice") },
{ std::string("Body"), std::string("PLUTO BARYCENTER") },
{ std::string("Reference"), std::string("ECLIPJ2000") },
{ std::string("Reference"), std::string("GALACTIC") },
{ std::string("Observer"), std::string("SUN") },
{ std::string("Kernels"), ghoul::Dictionary() }
};
@@ -1045,7 +1095,7 @@ void RenderEngine::changeViewPoint(std::string origin) {
{
{ std::string("Type"), std::string("Spice") },
{ std::string("Body"), std::string("JUPITER BARYCENTER") },
{ std::string("Reference"), std::string("ECLIPJ2000") },
{ std::string("Reference"), std::string("GALACTIC") },
{ std::string("Observer"), std::string("SUN") },
{ std::string("Kernels"), ghoul::Dictionary() }
};
@@ -1059,10 +1109,12 @@ void RenderEngine::changeViewPoint(std::string origin) {
{ std::string("Type"), std::string("Spice") },
{ std::string("Body"), std::string("NEW HORIZONS") },
{ std::string("Reference"), std::string("GALACTIC") },
{ std::string("Observer"), std::string("JUPITER BARYCENTER") },
{ std::string("Observer"), std::string("SUN") },
{ std::string("Kernels"), ghoul::Dictionary() }
};
newHorizonsNode->setEphemeris(new SpiceEphemeris(newHorizonsDictionary));
//newHorizonsTrailNode->setEphemeris(new SpiceEphemeris(newHorizonsDictionary));
//ghoul::Dictionary dawnDictionary =
//{
@@ -1084,39 +1136,64 @@ void RenderEngine::changeViewPoint(std::string origin) {
//};
//vestaNode->setEphemeris(new SpiceEphemeris(vestaDictionary));
return;
//ghoul::Dictionary newHorizonsGhostDictionary =
//{
// { std::string("Type"), std::string("Spice") },
// { std::string("Body"), std::string("NEW HORIZONS") },
// { std::string("EphmerisGhosting"), std::string("TRUE") },
// { std::string("Reference"), std::string("GALACTIC") },
// { std::string("Observer"), std::string("JUPITER BARYCENTER") },
// { std::string("Kernels"), ghoul::Dictionary() }
//};
//newHorizonsGhostNode->setEphemeris(new SpiceEphemeris(newHorizonsGhostDictionary));
return;
}
if (origin == "Jupiter") {
ghoul::Dictionary plutoDictionary =
{
{ std::string("Type"), std::string("Spice") },
{ std::string("Body"), std::string("PLUTO BARYCENTER") },
{ std::string("Reference"), std::string("ECLIPJ2000") },
{ std::string("Observer"), std::string("JUPITER BARYCENTER") },
{ std::string("Kernels"), ghoul::Dictionary() }
};
ghoul::Dictionary solarDictionary =
{
{ std::string("Type"), std::string("Spice") },
{ std::string("Body"), std::string("SUN") },
{ std::string("Reference"), std::string("ECLIPJ2000") },
{ std::string("Observer"), std::string("JUPITER BARYCENTER") },
{ std::string("Kernels"), ghoul::Dictionary() }
};
solarSystemBarycenterNode->setEphemeris(new SpiceEphemeris(solarDictionary));
plutoBarycenterNode->setEphemeris(new SpiceEphemeris(plutoDictionary));
jupiterBarycenterNode->setEphemeris(new StaticEphemeris);
jupiterBarycenterNode->setParent(scene()->sceneGraphNode("SolarSystem"));
jupiterBarycenterNode->setEphemeris(new StaticEphemeris);
solarSystemBarycenterNode->setParent(jupiterBarycenterNode);
newHorizonsNode->setParent(jupiterBarycenterNode);
//newHorizonsTrailNode->setParent(jupiterBarycenterNode);
//dawnNode->setParent(jupiterBarycenterNode);
//vestaNode->setParent(jupiterBarycenterNode);
ghoul::Dictionary solarDictionary =
{
{ std::string("Type"), std::string("Spice") },
{ std::string("Body"), std::string("SUN") },
{ std::string("Reference"), std::string("GALACTIC") },
{ std::string("Observer"), std::string("JUPITER BARYCENTER") },
{ std::string("Kernels"), ghoul::Dictionary() }
};
ghoul::Dictionary plutoDictionary =
{
{ std::string("Type"), std::string("Spice") },
{ std::string("Body"), std::string("PlUTO BARYCENTER") },
{ std::string("Reference"), std::string("GALACTIC") },
{ std::string("Observer"), std::string("JUPITER BARYCENTER") },
{ std::string("Kernels"), ghoul::Dictionary() }
};
ghoul::Dictionary newHorizonsDictionary =
{
{ std::string("Type"), std::string("Spice") },
{ std::string("Body"), std::string("NEW HORIZONS") },
{ std::string("Reference"), std::string("GALACTIC") },
{ std::string("Observer"), std::string("JUPITER BARYCENTER") },
{ std::string("Kernels"), ghoul::Dictionary() }
};
solarSystemBarycenterNode->setEphemeris(new SpiceEphemeris(solarDictionary));
plutoBarycenterNode->setEphemeris(new SpiceEphemeris(plutoDictionary));
newHorizonsNode->setEphemeris(new SpiceEphemeris(newHorizonsDictionary));
//newHorizonsGhostNode->setParent(jupiterBarycenterNode);
//newHorizonsTrailNode->setEphemeris(new SpiceEphemeris(newHorizonsDictionary));
ghoul::Dictionary newHorizonsDictionary =
{
{ std::string("Type"), std::string("Spice") },
{ std::string("Body"), std::string("NEW HORIZONS") },
{ std::string("Reference"), std::string("GALACTIC") },
{ std::string("Observer"), std::string("JUPITER BARYCENTER") },
{ std::string("Kernels"), ghoul::Dictionary() }
};
newHorizonsNode->setEphemeris(new SpiceEphemeris(newHorizonsDictionary));
//ghoul::Dictionary dawnDictionary =
//{
@@ -1138,14 +1215,40 @@ void RenderEngine::changeViewPoint(std::string origin) {
//};
//vestaNode->setEphemeris(new SpiceEphemeris(vestaDictionary));
//ghoul::Dictionary newHorizonsGhostDictionary =
//{
// { std::string("Type"), std::string("Spice") },
// { std::string("Body"), std::string("NEW HORIZONS") },
// { std::string("EphmerisGhosting"), std::string("TRUE") },
// { std::string("Reference"), std::string("GALACTIC") },
// { std::string("Observer"), std::string("JUPITER BARYCENTER") },
// { std::string("Kernels"), ghoul::Dictionary() }
//};
//newHorizonsGhostNode->setEphemeris(new SpiceEphemeris(newHorizonsGhostDictionary));
//newHorizonsGhostNode->setParent(jupiterBarycenterNode);
return;
}
//if (origin == "Vesta") {
//
// vestaNode->setParent(scene()->sceneGraphNode("SolarSystem"));
// vestaNode->setEphemeris(new StaticEphemeris);
//
// solarSystemBarycenterNode->setParent(vestaNode);
// newHorizonsNode->setParent(vestaNode);
//
// dawnNode->setParent(vestaNode);
// plutoBarycenterNode->setParent(vestaNode);
//
//
// ghoul::Dictionary plutoDictionary =
// {
// { std::string("Type"), std::string("Spice") },
// { std::string("Body"), std::string("PLUTO BARYCENTER") },
// { std::string("Reference"), std::string("ECLIPJ2000") },
// { std::string("Reference"), std::string("GALACTIC") },
// { std::string("Observer"), std::string("VESTA") },
// { std::string("Kernels"), ghoul::Dictionary() }
// };
@@ -1153,7 +1256,7 @@ void RenderEngine::changeViewPoint(std::string origin) {
// {
// { std::string("Type"), std::string("Spice") },
// { std::string("Body"), std::string("SUN") },
// { std::string("Reference"), std::string("ECLIPJ2000") },
// { std::string("Reference"), std::string("GALACTIC") },
// { std::string("Observer"), std::string("VESTA") },
// { std::string("Kernels"), ghoul::Dictionary() }
// };
@@ -1162,7 +1265,7 @@ void RenderEngine::changeViewPoint(std::string origin) {
// {
// { std::string("Type"), std::string("Spice") },
// { std::string("Body"), std::string("JUPITER BARYCENTER") },
// { std::string("Reference"), std::string("ECLIPJ2000") },
// { std::string("Reference"), std::string("GALACTIC") },
// { std::string("Observer"), std::string("VESTA") },
// { std::string("Kernels"), ghoul::Dictionary() }
// };

View File

@@ -0,0 +1,58 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2015 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <openspace/scene/dynamicephemeris.h>
#include <openspace/util/constants.h>
namespace openspace {
using namespace constants::dynamicephemeris;
DynamicEphemeris::DynamicEphemeris(const ghoul::Dictionary& dictionary)
: _position(0.f, 0.f, 0.f, 0.f)
{
const bool hasPosition = dictionary.hasKeyAndValue<glm::vec4>(keyPosition);
if (hasPosition) {
glm::vec4 tmp;
dictionary.getValue(keyPosition, tmp);
_position = tmp;
}
}
DynamicEphemeris::~DynamicEphemeris() {}
const psc& DynamicEphemeris::position() const {
return _position;
}
void DynamicEphemeris::setPosition(psc pos) {
_position = pos;
}
void DynamicEphemeris::update(const UpdateData&) {
}
} // namespace openspace

View File

@@ -183,6 +183,7 @@ bool Scene::initialize() {
tmpProgram->setProgramObjectCallback(cb);
_programs.push_back(tmpProgram);
OsEng.ref().configurationManager()->setValue("fboPassProgram", tmpProgram);
// projection program
tmpProgram = ProgramObject::Build("projectiveProgram",
"${SHADERS}/projectiveTexture_vs.glsl",
@@ -198,11 +199,29 @@ bool Scene::initialize() {
"${SHADERS}/pscstandard_fs.glsl");
if( ! tmpProgram) return false;
tmpProgram->setProgramObjectCallback(cb);
_programs.push_back(tmpProgram);
OsEng.ref().configurationManager()->setValue("pscShader", tmpProgram);
// pscstandard
// NH shader
tmpProgram = ProgramObject::Build("ModelProgram",
"${SHADERS}/model_vs.glsl",
"${SHADERS}/model_fs.glsl");
if (!tmpProgram) return false;
tmpProgram->setProgramObjectCallback(cb);
_programs.push_back(tmpProgram);
OsEng.ref().configurationManager()->setValue("GenericModelShader", tmpProgram);
// Night texture program
tmpProgram = ProgramObject::Build("nightTextureProgram",
"${SHADERS}/nighttexture_vs.glsl",
"${SHADERS}/nighttexture_fs.glsl");
if (!tmpProgram) return false;
tmpProgram->setProgramObjectCallback(cb);
_programs.push_back(tmpProgram);
OsEng.ref().configurationManager()->setValue("nightTextureProgram", tmpProgram);
// Fov Program
tmpProgram = ProgramObject::Build("FovProgram",
"${SHADERS}/fov_vs.glsl",
"${SHADERS}/fov_fs.glsl");
@@ -211,6 +230,24 @@ bool Scene::initialize() {
_programs.push_back(tmpProgram);
OsEng.ref().configurationManager()->setValue("FovProgram", tmpProgram);
// Plane Program
tmpProgram = ProgramObject::Build("planeProgram",
"${SHADERS}/modules/plane/plane_vs.glsl",
"${SHADERS}/modules/plane/plane_fs.glsl");
if (!tmpProgram) return false;
tmpProgram->setProgramObjectCallback(cb);
_programs.push_back(tmpProgram);
OsEng.ref().configurationManager()->setValue("planeProgram", tmpProgram);
// Image Plane Program
tmpProgram = ProgramObject::Build("imagePlaneProgram",
"${SHADERS}/modules/imageplane/imageplane_vs.glsl",
"${SHADERS}/modules/imageplane/imageplane_fs.glsl");
if (!tmpProgram) return false;
tmpProgram->setProgramObjectCallback(cb);
_programs.push_back(tmpProgram);
OsEng.ref().configurationManager()->setValue("imagePlaneProgram", tmpProgram);
// RaycastProgram
tmpProgram = ProgramObject::Build("RaycastProgram",
"${SHADERS}/exitpoints.vert",

View File

@@ -252,7 +252,7 @@ void SceneGraphNode::evaluate(const Camera* camera, const psc& parentPosition) {
}
void SceneGraphNode::render(const RenderData& data) {
const psc thisPosition = data.position + _ephemeris->position();
const psc thisPosition = worldPosition();
RenderData newData = {data.camera, thisPosition, data.doPerformanceMeasurement};
@@ -278,29 +278,30 @@ void SceneGraphNode::render(const RenderData& data) {
// child->render(newData);
}
// set & get
void SceneGraphNode::addNode(SceneGraphNode* child)
{
// add a child node and set this node to be the parent
child->setParent(this);
_children.push_back(child);
}
// not used anymore @AA
//void SceneGraphNode::addNode(SceneGraphNode* child)
//{
// // add a child node and set this node to be the parent
// child->setParent(this);
// _children.push_back(child);
//}
void SceneGraphNode::setParent(SceneGraphNode* parent)
{
_parent = parent;
}
bool SceneGraphNode::abandonChild(SceneGraphNode* child) {
std::vector < SceneGraphNode* >::iterator it = std::find(_children.begin(), _children.end(), child);
if (it != _children.end()){
_children.erase(it);
return true;
}
return false;
}
//not used anymore @AA
//bool SceneGraphNode::abandonChild(SceneGraphNode* child) {
// std::vector < SceneGraphNode* >::iterator it = std::find(_children.begin(), _children.end(), child);
//
// if (it != _children.end()){
// _children.erase(it);
// return true;
// }
//
// return false;
//}
const psc& SceneGraphNode::position() const
{

View File

@@ -27,9 +27,11 @@
#include <openspace/util/constants.h>
#include <openspace/util/spicemanager.h>
#include <openspace/util/time.h>
#include <openspace/util/imagesequencer2.h>
namespace {
const std::string _loggerCat = "SpiceEphemeris";
const std::string keyGhosting = "EphmerisGhosting";
}
namespace openspace {
@@ -50,6 +52,8 @@ SpiceEphemeris::SpiceEphemeris(const ghoul::Dictionary& dictionary)
if (!hasObserver)
LERROR("SpiceEphemeris does not contain the key '" << keyOrigin << "'");
dictionary.getValue(keyGhosting, _ghosting);
ghoul::Dictionary kernels;
dictionary.getValue(keyKernels, kernels);
for (size_t i = 1; i <= kernels.size(); ++i) {
@@ -75,13 +79,13 @@ void SpiceEphemeris::update(const UpdateData& data) {
double lightTime = 0.0;
SpiceManager::ref().getTargetPosition(_targetName, _originName,
"GALACTIC", "NONE", data.time, position, lightTime);
/*if (_targetName == "NEW HORIZONS"){
// In order to properly draw the viewfrustrum, the craft might have to be
// positioned using the X-variations of aberration methods (ongoing investigation).
double interval = openspace::ImageSequencer2::ref().getIntervalLength();
if (_ghosting == "TRUE" && interval > 60){
double _time = openspace::ImageSequencer2::ref().getNextCaptureTime();
SpiceManager::ref().getTargetPosition(_targetName, _originName,
"GALACTIC", "NONE", data.time, position, lightTime);
}*/
"GALACTIC", "NONE", _time, position, lightTime);
}
_position = psc::CreatePowerScaledCoordinate(position.x, position.y, position.z);
_position[3] += 3;

59
src/util/decoder.cpp Normal file
View File

@@ -0,0 +1,59 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2015 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <openspace/util/decoder.h>
#include <openspace/util/factorymanager.h>
namespace {
const std::string _loggerCat = "Decoder";
}
namespace openspace {
Decoder* Decoder::createFromDictionary(const ghoul::Dictionary& dictionary, const std::string type)
{
ghoul::TemplateFactory<Decoder>* factory
= FactoryManager::ref().factory<Decoder>();
Decoder* result = factory->create(type, dictionary);
if (result == nullptr) {
LERROR("Failed creating Payload object of type '" << type << "'");
return nullptr;
}
return result;
}
Decoder::Decoder()
{
}
Decoder::Decoder(const ghoul::Dictionary& dictionary)
{
}
Decoder::~Decoder()
{
}
} // namespace openspace

View File

@@ -37,6 +37,7 @@
#include <openspace/rendering/planets/renderableplanet.h>
#include <openspace/rendering/planets/simplespheregeometry.h>
#include <openspace/rendering/renderableplane.h>
#include <openspace/rendering/renderableplaneprojection.h>
#include <openspace/rendering/renderablevolumegl.h>
#include <openspace/rendering/planets/simplespheregeometry.h>
#include <openspace/rendering/model/modelgeometry.h>
@@ -44,6 +45,7 @@
// positioninformation
#include <openspace/scene/staticephemeris.h>
#include <openspace/scene/dynamicephemeris.h>
#include <openspace/scene/spiceephemeris.h>
// projection
@@ -51,6 +53,10 @@
#include <openspace/rendering/planets/simplespheregeometryprojection.h>
#include <openspace/rendering/planets/planetgeometryprojection.h>
#include <openspace/util/decoder.h>
#include <openspace/util/instrumentdecoder.h>
#include <openspace/util/targetdecoder.h>
// std
#include <cassert>
@@ -89,6 +95,8 @@ void FactoryManager::initialize()
"RenderableModel");
_manager->factory<Renderable>()->registerClass<RenderablePlane>(
"RenderablePlane");
_manager->factory<Renderable>()->registerClass<RenderablePlaneProjection>(
"RenderablePlaneProjection");
_manager->factory<Renderable>()->registerClass<RenderableVolumeGL>(
"RenderableVolumeGL");
_manager->factory<Renderable>()->registerClass<RenderableFieldlines>(
@@ -97,8 +105,14 @@ void FactoryManager::initialize()
// Add Ephimerides
_manager->addFactory(new ghoul::TemplateFactory<Ephemeris>);
_manager->factory<Ephemeris>()->registerClass<StaticEphemeris>("Static");
_manager->factory<Ephemeris>()->registerClass<StaticEphemeris>("Dynamic");
_manager->factory<Ephemeris>()->registerClass<SpiceEphemeris>("Spice");
_manager->addFactory(new ghoul::TemplateFactory<Decoder>);
_manager->factory<Decoder>()->registerClass<InstrumentDecoder>("Instrument");
_manager->factory<Decoder>()->registerClass<TargetDecoder>("Target");
// Add PlanetGeometry
_manager->addFactory(new ghoul::TemplateFactory<planetgeometry::PlanetGeometry>);
_manager->factory<planetgeometry::PlanetGeometry>()

502
src/util/hongkangparser.cpp Normal file
View File

@@ -0,0 +1,502 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <openspace/util/ImageSequencer2.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/filesystem/directory.h>
#include <openspace/util/time.h>
#include <openspace/util/spicemanager.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/network/networkengine.h>
#include <fstream>
#include <iterator>
#include <iomanip>
#include <limits>
#include <openspace/util/hongkangparser.h>
#include <openspace/util/instrumentdecoder.h>
namespace {
const std::string _loggerCat = "HongKangParser";
const std::string keyTranslation = "DataInputTranslation";
const std::string PlaybookIdentifierName = "Playbook";
}
namespace openspace {
HongKangParser::HongKangParser(const std::string& fileName,
std::string spacecraft,
ghoul::Dictionary translationDictionary,
std::vector<std::string> potentialTargets) :
_defaultCaptureImage(absPath("${OPENSPACE_DATA}/scene/common/textures/placeholder_blank.png"))
{
_fileName = fileName;
_spacecraft = spacecraft;
_potentialTargets = potentialTargets;
//get the different instrument types
const std::vector<std::string>& decoders = translationDictionary.keys();
//for each decoder (assuming might have more if hong makes changes)
for (int i = 0; i < decoders.size(); i++){
//create dictionary containing all {playbookKeys , spice IDs}
if (decoders[i] == "Instrument"){
ghoul::Dictionary typeDictionary;
translationDictionary.getValue(decoders[i], typeDictionary);
//for each playbook call -> create a Decoder object
const std::vector<std::string>& keys = typeDictionary.keys();
//std::string abort = decoders[i] + "." + keyStopCommand;
for (int j = 0; j < keys.size(); j++){
std::string currentKey = decoders[i] + "." + keys[j];
ghoul::Dictionary decoderDictionary;
translationDictionary.getValue(currentKey, decoderDictionary);
Decoder *decoder = Decoder::createFromDictionary(decoderDictionary, decoders[i]);
//insert decoder to map - this will be used in the parser to determine
//behavioral characteristics of each instrument
_fileTranslation[keys[j]] = decoder;
}
}
//Hong's playbook needs _only_ instrument translation though.
}
}
void findPlaybookSpecifiedTarget(std::string line, std::string& target){
//remembto add this lua later...
std::vector<std::string> ptarg = { "PLUTO", "CHARON", "NIX", "HYDRA", "P5", "P4" };
for (auto p : ptarg){
// loop over all targets and determine from 4th col which target this instrument points to
std::transform(line.begin(), line.end(), line.begin(), toupper);
if (line.find(p) != std::string::npos){
target = p;
break;
}
else{
// not found - we set void until we have more info.
target = "VOID";
}
}
}
void HongKangParser::create(){
if (size_t position = _fileName.find_last_of(".") + 1){
if (position != std::string::npos){
std::string extension = ghoul::filesystem::File(_fileName).fileExtension();
if (extension == "txt"){// Hong Kang. pre-parsed playbook
LINFO("Using Preparsed Playbook V9H");
std::ifstream file(_fileName , std::ios::binary);
if (!file.good()) LERROR("Failed to open txt file '" << _fileName << "'");
std::string line = "";
double shutter = 0.01;
double startTime, stopTime;
std::string previousTarget;
std::string previousCamera;
std::string previousScanner;
TimeRange cameraRange;
TimeRange scanRange;
std::vector<std::string> scannerSpiceID;
std::vector<std::string> cameraSpiceID;
double capture_start = -1;
double capture_stop = -1;
double scan_start = -1;
double scan_stop = -1;
std::string cameraTarget = "VOID";
std::string scannerTarget = "VOID";
int counter = 0;
while (!file.eof()){//only while inte do, FIX
std::getline(file, line);
std::string event = line.substr(0, line.find_first_of(" "));
auto it = _fileTranslation.find(event);
bool foundEvent = (it != _fileTranslation.end());
std::string met = line.substr(25, 9);
double time = getETfromMet(met);
Image image;
if (foundEvent){
//store the time, this is used for getNextCaptureTime()
_captureProgression.push_back(time);
if (it->second->getDecoderType() == "CAMERA"){
if (capture_start == -1){
//encountered new camera sequence- store start time
capture_start = time;
previousCamera = it->first;
}
//always store individual image for camera
cameraSpiceID = it->second->getTranslation();
//rely on playboook mdl column to determine target
findPlaybookSpecifiedTarget(line, cameraTarget);
//fill image
createImage(image, time, time + shutter, cameraSpiceID, cameraTarget, _defaultCaptureImage);
//IFF spaccraft has decided to switch target, store in target map (used for: 'next observation focus')
if (previousTarget != image.target){
previousTarget = image.target;
std::pair<double, std::string> v_target = std::make_pair(time, image.target);
_targetTimes.push_back(v_target);
}
//store actual image in map. All targets get _only_ their corresp. subset.
_subsetMap[image.target]._subset.push_back(image);
//compute and store the range for each subset
_subsetMap[image.target]._range.setRange(time);
}
if (it->second->getDecoderType() == "SCANNER"){ // SCANNER START
scan_start = time;
InstrumentDecoder* scanner = static_cast<InstrumentDecoder*>(it->second);
std::string endNominal = scanner->getStopCommand();
// store current position in file
int len = file.tellg();
std::string linePeek;
bool foundstop = false;
while (!file.eof() && !foundstop){
//continue grabbing next line until we find what we need
getline(file, linePeek);
if (linePeek.find(endNominal) != std::string::npos){
foundstop = true;
met = linePeek.substr(25, 9);
scan_stop = getETfromMet(met);
findPlaybookSpecifiedTarget(line, scannerTarget);
scannerSpiceID = it->second->getTranslation();
scanRange._min = scan_start;
scanRange._max = scan_stop;
_instrumentTimes.push_back(std::make_pair(it->first, scanRange));
//store individual image
createImage(image, scan_start, scan_stop, scannerSpiceID, scannerTarget, _defaultCaptureImage);
_subsetMap[image.target]._subset.push_back(image);
_subsetMap[image.target]._range.setRange(scan_start);
}
}
//go back to stored position in file
file.seekg(len, std::ios_base::beg);
/*//scanner works like state-machine -only store start time now
scan_start = time;
previousScanner = it->first;
//store scanning instrument - store image once stopTime is found!
findPlaybookSpecifiedTarget(line, scannerTarget);
scannerSpiceID = it->second->getTranslation();*/
}
}
else{ // we have reached the end of a scan or consecutive capture sequence!
if (capture_start != -1){
//end of capture sequence for camera, store end time of this sequence
capture_stop = time;
cameraRange._min = capture_start;
cameraRange._max = capture_stop;
_instrumentTimes.push_back(std::make_pair(previousCamera, cameraRange));
capture_start = -1;
}
/*if (line.find("END_NOM") != std::string::npos){
assert(scan_start != -1, "SCAN end occured before SCAN call!");
//end of scan, store end time of this scan + store the scan image
scan_stop = time;
scanRange._min = scan_start;
scanRange._max = scan_stop;
_instrumentTimes.push_back(std::make_pair(previousScanner, scanRange));
//store individual image
createImage(image, scan_start, scan_stop, scannerSpiceID, scannerTarget, _defaultCaptureImage);
_subsetMap[image.target]._subset.push_back(image);
_subsetMap[image.target]._range.setRange(scan_start);
scan_start = -1;
}*/
}
}
}
}
}
sendPlaybookInformation();
std::ofstream myfile;
myfile.open("HongKangOutput.txt");
//print all
for (auto target : _subsetMap){
std::string min, max;
SpiceManager::ref().getDateFromET(target.second._range._min, min);
SpiceManager::ref().getDateFromET(target.second._range._max, max);
myfile << std::endl;
for (auto image : target.second._subset){
std::string time_beg;
std::string time_end;
SpiceManager::ref().getDateFromET(image.startTime, time_beg);
SpiceManager::ref().getDateFromET(image.stopTime, time_end);
myfile << std::fixed
<< std::setw(10) << time_beg
<< std::setw(10) << time_end
<< std::setw(10) << (int)getMetFromET(image.startTime)
<< std::setw(10) << image.target << std::setw(10);
for (auto instrument : image.activeInstruments){
myfile << " " << instrument;
}
myfile << std::endl;
}
}
myfile.close();
}
bool HongKangParser::augmentWithSpice(Image& image,
std::string spacecraft,
std::vector<std::string> payload,
std::vector<std::string> potentialTargets){
image.target = "VOID";
// we have (?) to cast to int, unfortunately
int exposureTime = image.stopTime - image.startTime;
if (exposureTime == 0) exposureTime = 1;
double et;
for (int i = 0; i < potentialTargets.size(); i++){
bool success = false;
bool _withinFOV = false;
for (int j = 0; j < image.activeInstruments.size(); j++){
double time = image.startTime;
for (int k = 0; k < exposureTime; k++){
time += k;
success = openspace::SpiceManager::ref().targetWithinFieldOfView(
image.activeInstruments[j],
potentialTargets[i],
spacecraft,
"ELLIPSOID",
"NONE",
time,
_withinFOV);
if (_withinFOV){
image.target = potentialTargets[i];
_withinFOV = false;
}
}
}
}
return false;
}
void HongKangParser::createImage(Image& image, double startTime, double stopTime, std::vector<std::string> instr, std::string targ, std::string path) {
image.startTime = startTime;
image.stopTime = stopTime;
image.path = path;
for (int i = 0; i < instr.size(); i++){
image.activeInstruments.push_back(instr[i]);
}
image.target = targ;
image.projected = false;
}
double HongKangParser::getETfromMet(std::string line){
std::string::size_type sz;
return getETfromMet(std::stod(line, &sz));
}
double HongKangParser::getETfromMet(double met){
double diff;
double referenceET;
double et;
openspace::SpiceManager::ref().getETfromDate("2015-07-14T11:50:00.00", referenceET);
double missionLaunch = referenceET - _metRef;
diff = abs(met - _metRef);
if (met > _metRef){
et = referenceET + diff;
}else if (met < _metRef){
et = referenceET - diff;
}
return et;
}
double HongKangParser::getMetFromET(double et){
double met;
double referenceET;
openspace::SpiceManager::ref().getETfromDate("2015-07-14T11:50:00.00", referenceET);
if (et >= referenceET){
met = _metRef + (et - referenceET);
}else{
met = _metRef - (referenceET - et);
}
return met;
}
std::map<std::string, ImageSubset> HongKangParser::getSubsetMap(){
return _subsetMap;
}
std::vector<std::pair<std::string, TimeRange>> HongKangParser::getIstrumentTimes(){
return _instrumentTimes;
}
std::vector<std::pair<double, std::string>> HongKangParser::getTargetTimes(){
return _targetTimes;
}
std::vector<double> HongKangParser::getCaptureProgression(){
return _captureProgression;
};
template <typename T>
void writeToBuffer(std::vector<char>& buffer, size_t& currentWriteLocation, T value) {
if ((currentWriteLocation + sizeof(T)) > buffer.size())
buffer.resize(2 * buffer.size());
std::memmove(buffer.data() + currentWriteLocation, reinterpret_cast<const void*>(&value), sizeof(T));
currentWriteLocation += sizeof(T);
}
template <>
void writeToBuffer<std::string>(std::vector<char>& buffer, size_t& currentWriteLocation, std::string value) {
if ((currentWriteLocation + sizeof(uint8_t) + value.size()) > buffer.size())
buffer.resize(2 * buffer.size());
uint8_t length = value.size();
std::memcpy(buffer.data() + currentWriteLocation, &length, sizeof(uint8_t));
currentWriteLocation += sizeof(uint8_t);
std::memmove(buffer.data() + currentWriteLocation, value.data(), length);
currentWriteLocation += length;
}
void HongKangParser::sendPlaybookInformation() {
static const NetworkEngine::MessageIdentifier PlaybookIdentifier = OsEng.networkEngine()->identifier(PlaybookIdentifierName);
std::vector<char> buffer(1024);
size_t currentWriteLocation = 0;
// Protocol:
// 4 bytes: Total number of bytes sent
// 1 byte : Number of Targets (i)
// i times: 1 byte (id), 1 byte (length j of name), j bytes (name)
// 1 byte : Number of Instruments (i)
// i times: 1 byte (id), 1 byte (length j of name), j bytes (name)
// 4 byte: Number (n) of images
// n times: 8 byte (beginning time), 8 byte (ending time), 1 byte (target id), 2 byte (instrument id)
std::map<std::string, uint8_t> targetMap;
uint8_t currentTargetId = 0;
for (auto target : _subsetMap) {
if (targetMap.find(target.first) == targetMap.end())
targetMap[target.first] = currentTargetId++;
}
std::map<std::string, uint16_t> instrumentMap;
uint16_t currentInstrumentId = 1;
for (auto target : _subsetMap) {
for (auto image : target.second._subset) {
for (auto instrument : image.activeInstruments) {
if (instrumentMap.find(instrument) == instrumentMap.end()) {
instrumentMap[instrument] = currentInstrumentId;
currentInstrumentId = currentInstrumentId << 1;
}
}
}
}
writeToBuffer(buffer, currentWriteLocation, uint8_t(targetMap.size()));
for (const std::pair<std::string, uint8_t>& p : targetMap) {
writeToBuffer(buffer, currentWriteLocation, p.second);
writeToBuffer(buffer, currentWriteLocation, p.first);
}
writeToBuffer(buffer, currentWriteLocation, uint8_t(instrumentMap.size()));
for (const std::pair<std::string, uint16_t>& p : instrumentMap) {
writeToBuffer(buffer, currentWriteLocation, p.second);
writeToBuffer(buffer, currentWriteLocation, p.first);
}
uint32_t allImages = 0;
for (auto target : _subsetMap)
allImages += target.second._subset.size();
writeToBuffer(buffer, currentWriteLocation, allImages);
for (auto target : _subsetMap){
for (auto image : target.second._subset){
writeToBuffer(buffer, currentWriteLocation, image.startTime);
writeToBuffer(buffer, currentWriteLocation, image.stopTime);
std::string timeBegin;
std::string timeEnd;
SpiceManager::ref().getDateFromET(image.startTime, timeBegin);
SpiceManager::ref().getDateFromET(image.stopTime, timeEnd);
writeToBuffer(buffer, currentWriteLocation, timeBegin);
writeToBuffer(buffer, currentWriteLocation, timeEnd);
uint8_t targetId = targetMap[target.first];
writeToBuffer(buffer, currentWriteLocation, targetId);
uint16_t totalInstrumentId = 0;
if (image.activeInstruments.empty()) {
LERROR("Image had no active instruments");
}
for (auto instrument : image.activeInstruments) {
uint16_t thisInstrumentId = instrumentMap[instrument];
totalInstrumentId |= thisInstrumentId;
}
writeToBuffer(buffer, currentWriteLocation, totalInstrumentId);
}
}
union {
uint32_t value;
std::array<char, sizeof(uint32_t)> data;
} sizeBuffer;
sizeBuffer.value = currentWriteLocation;
buffer.insert(buffer.begin(), sizeBuffer.data.begin(), sizeBuffer.data.end());
currentWriteLocation += sizeof(uint32_t);
buffer.resize(currentWriteLocation);
//OsEng.networkEngine()->publishMessage(PlaybookIdentifier, buffer);
OsEng.networkEngine()->setInitialConnectionMessage(PlaybookIdentifier, buffer);
}
}

View File

@@ -46,21 +46,40 @@ ImageSequencer* ImageSequencer::_sequencer = nullptr;
struct ImageParams{
double startTime;
double stopTime;
std::string path;
std::string activeInstrument;
std::string target;
bool projected;
};
auto cmp = [](const ImageParams &a, const ImageParams &b)->bool{
std::vector<std::vector<ImageParams>> _timeStamps;
void createImage(std::vector<ImageParams>& vec, double t1, std::string instrument, std::string target, std::string path = "dummypath");
auto imageComparer = [](const ImageParams &a, const ImageParams &b)->bool{
return a.startTime < b.startTime;
};
std::vector<ImageParams> _timeStamps;
std::vector<ImageParams>::iterator binary_find(std::vector<ImageParams>::iterator begin,
std::vector<ImageParams>::iterator end,
const ImageParams &val,
bool(*imageComparer)(const ImageParams &a, const ImageParams &b)){
// Finds the lower bound in at most log(last - first) + 1 comparisons
std::vector<ImageParams>::iterator it = std::lower_bound(begin, end, val, imageComparer);
if (it != begin){
return it;
}
return end;
}
ImageSequencer::ImageSequencer()
: _nextCapture(0.0)
, _defaultCaptureImage(absPath("${OPENSPACE_DATA}/scene/common/textures/placeholder.png"))
: _nextCapture(-1.0)
, _currentTime(-1.0)
, _sequenceIDs(0)
, _targetsAdded(false)
, _defaultCaptureImage(absPath("${OPENSPACE_DATA}/scene/common/textures/placeholder_blank.png"))
{}
@@ -78,93 +97,256 @@ void ImageSequencer::deinitialize() {
_sequencer = nullptr;
}
void ImageSequencer::createImage(double t1, double t2, std::string instrument, std::string path) {
void ImageSequencer::setSequenceId(int& id){
id = _sequenceIDs;
_sequenceIDs++;
}
void ImageSequencer::addSequenceObserver(int sequenceID, std::string name, std::vector<std::string> payload){
if (sequenceID >= 0){
_observers.insert(std::make_pair(sequenceID, name));
_instruments.insert(std::make_pair(name, payload));
}
}
void ImageSequencer::registerTargets(std::vector<std::string>& potential){
for (auto p : potential){
if (_projectableTargets.find(p) == _projectableTargets.end()){
_projectableTargets[p] = _currentTime;
}
}
}
void ImageSequencer::update(double time){
_currentTime = time;
static bool time_initialized;
if (!time_initialized){
for (auto &it : _projectableTargets) {
it.second = _currentTime;
assert(it.second > 0.0);
}
time_initialized = true;
}
}
void createImage(std::vector<ImageParams>& vec, double t1, std::string instrument, std::string target, std::string path) {
// insert
ImageParams image;
image.startTime = t1;
image.stopTime = t2;
image.path = path;
image.activeInstrument = instrument;
image.target = target;
image.projected = false;
_timeStamps.push_back(image);
// sort
vec.push_back(image);
}
double ImageSequencer::getNextCaptureTime(){
return _nextCapture;
}
double ImageSequencer::nextCaptureTime(double _time){
auto binary_find = [](std::vector<ImageParams>::iterator begin,
std::vector<ImageParams>::iterator end,
const ImageParams &val,
bool(*cmp)(const ImageParams &a, const ImageParams &b))->std::vector<ImageParams>::iterator{
// Finds the lower bound in at most log(last - first) + 1 comparisons
std::vector<ImageParams>::iterator it = std::lower_bound(begin, end, val, cmp);
if (it != begin){
return it;
}
return end;
};
auto it = binary_find(_timeStamps.begin(), _timeStamps.end(), { _time, 0, "", "", false }, cmp);
if (it == _timeStamps.end() || _time < _nextCapture) return _nextCapture;
double ImageSequencer::nextCaptureTime(double time, int sequenceID){
if (time < _nextCapture) return _nextCapture;
auto it = binary_find(_timeStamps[sequenceID].begin(), _timeStamps[sequenceID].end(), { time, "", "", "", false }, imageComparer);
if (it == _timeStamps[sequenceID].end()) return _nextCapture;
return it->startTime;
}
std::string ImageSequencer::findActiveInstrument(double time){
auto binary_find = [](std::vector<ImageParams>::iterator begin,
std::vector<ImageParams>::iterator end,
const ImageParams &val,
bool(*cmp)(const ImageParams &a, const ImageParams &b))->std::vector<ImageParams>::iterator{
// Finds the lower bound in at most log(last - first) + 1 comparisons
std::vector<ImageParams>::iterator it = std::lower_bound(begin, end, val, cmp);
if (it != begin){
return it;
}
return end;
};
auto it = binary_find(_timeStamps.begin(), _timeStamps.end(), { time, 0, "", "", false }, cmp);
if ((it == _timeStamps.end())){
std::string ImageSequencer::findActiveInstrument(double time, int sequenceID){
auto it = binary_find(_timeStamps[sequenceID].begin(), _timeStamps[sequenceID].end(), { time, "", "", "",false }, imageComparer);
if ((it == _timeStamps[sequenceID].end())){
_activeInstrument = "Not found, incufficient playbook-data";
}else{
_activeInstrument = std::prev(it)->activeInstrument;
}
return _activeInstrument;
}
bool ImageSequencer::getImagePath(double& currentTime, std::string& path, bool closedInterval){
auto binary_find = [](std::vector<ImageParams>::iterator begin,
std::vector<ImageParams>::iterator end,
const ImageParams &val,
bool(*cmp)(const ImageParams &a, const ImageParams &b))->std::vector<ImageParams>::iterator{
void ImageSequencer::augumentSequenceWithTargets(int sequenceID){
if (!_targetsAdded){
// if there is an registered observer for this sequence
if (_observers.count(sequenceID) > 0) {
// find observer
std::string observer = _observers.at(sequenceID);
// find its instruments
std::map <std::string, std::vector<std::string>>::iterator it2 = _instruments.find(observer);
if (it2 != _instruments.end()){
std::string _targetFOV;
bool _withinFOV;
// for each image taken
for (std::vector<ImageParams>::iterator image = _timeStamps[sequenceID].begin(); image != _timeStamps[sequenceID].end(); ++image) {
// traverse potential targets...
for (auto t : _projectableTargets){
// ... and potential instruments
for (auto i : it2->second){
//register precisely which target is being projected to upon image-capture
bool success = openspace::SpiceManager::ref().targetWithinFieldOfView(
i, // Instrumnet
t.first, // projectables
observer, // new horizons
"ELLIPSOID",
"NONE",
image->startTime,
_withinFOV);
//if (!_withinFOV) image->target = "VOID";
if (success && _withinFOV){
image->target = t.first;
//once we find it abort search, break the loop.
break;
}
}
}
}
}else{
LERROR("Spacecraft payload not provided, cannot write playbook");
}
}
else{
LERROR("Did not find observing spacecraft for sequence, cannot write playbook");
}
_targetsAdded = true;
}
}
bool ImageSequencer::getImagePath(std::vector<std::pair<double, std::string>>& _imageTimes, int sequenceID, std::string projectee, bool withinFOV){
/*if (withinFOV && !Time::ref().timeJumped()){
getSingleImage(_imageTimes, sequenceID, projectee);
}else{*/
getMultipleImages(_imageTimes, sequenceID, projectee);
//}
return true;
}
bool ImageSequencer::getMultipleImages(std::vector<std::pair<double, std::string>>& _imageTimes, int sequenceID, std::string projectee){
double previousTime;
std::map<std::string, double>::iterator it = _projectableTargets.find(projectee);
if (it != _projectableTargets.end()){
previousTime = it->second;
it->second = _currentTime;
}
auto it1 = binary_find(_timeStamps[sequenceID].begin(), _timeStamps[sequenceID].end(), { previousTime, "", "", "", false }, imageComparer);
auto it2 = binary_find(_timeStamps[sequenceID].begin(), _timeStamps[sequenceID].end(), { _currentTime, "", "", "", false }, imageComparer);
if (it1 != _timeStamps[sequenceID].end() && it2 != _timeStamps[sequenceID].end() && it1 != it2){
std::transform(it1, it2, std::back_inserter(_imageTimes),
[](const ImageParams& i) {
return std::make_pair(i.startTime, i.path);
});
}
std::reverse(_imageTimes.begin(), _imageTimes.end());
double upcoming = nextCaptureTime(_currentTime, sequenceID);
if (_nextCapture != upcoming){
_nextCapture = upcoming;
_intervalLength = upcoming - _currentTime;
}
return true;
}
bool ImageSequencer::getSingleImage(std::vector<std::pair<double, std::string>>& _imageTimes, int sequenceID, std::string projectee){
auto bfind = [](std::vector<ImageParams>::iterator begin,
std::vector<ImageParams>::iterator end,
const ImageParams &val,
bool(*imageComparer)(const ImageParams &a, const ImageParams &b))->std::vector<ImageParams>::iterator{
// Finds the lower bound in at most log(last - first) + 1 comparisons
std::vector<ImageParams>::iterator it = std::lower_bound(begin, end, val, cmp);
std::vector<ImageParams>::iterator it = std::lower_bound(begin, end, val, imageComparer);
if (it != begin){
return std::prev(it);
}
return end;
};
auto it = binary_find(_timeStamps.begin(), _timeStamps.end(), { currentTime, 0, "", "", false }, cmp);
auto it = bfind(_timeStamps[sequenceID].begin(), _timeStamps[sequenceID].end(), { _currentTime, "", "", "", false }, imageComparer);
if (it != _timeStamps[sequenceID].end() && !it->projected){
it->projected = true;
_imageTimes.push_back(std::make_pair(it->startTime, it->path));
}
double upcoming = nextCaptureTime(_currentTime, sequenceID);
if (_nextCapture != upcoming){
_nextCapture = upcoming;
_intervalLength = upcoming - _currentTime;
}
return true;
}
/*
bool ImageSequencer::getImagePath(std::vector<std::pair<double, std::string>>& _imageTimes, int sequenceID, std::string projectee, bool closedInterval){
double t = _currentTime;
double ptime;
std::map<std::string, double>::iterator it = _previous.find(projectee);
if (it != _previous.end()){
ptime = it->second;
it->second = _currentTime;
}
while (t > ptime){
auto binary_find = [](std::vector<ImageParams>::iterator begin,
std::vector<ImageParams>::iterator end,
const ImageParams &val,
bool(*imageComparer)(const ImageParams &a, const ImageParams &b))->std::vector<ImageParams>::iterator{
// Finds the lower bound in at most log(last - first) + 1 comparisons
std::vector<ImageParams>::iterator it = std::lower_bound(begin, end, val, imageComparer);
if (it != begin){
return std::prev(it);
}
return end;
};
auto it = binary_find(_timeStamps[sequenceID].begin(), _timeStamps[sequenceID].end(), { t, 0, "", "", false }, imageComparer);
if (it == _timeStamps[sequenceID].end() || it->startTime < ptime) break;
if (!it->projected || it != _timeStamps[sequenceID].end()){
_imageTimes.push_back(std::make_pair(it->startTime, it->path));
}
t = it->startTime - 1;
//it->projected = true;
}
std::reverse(_imageTimes.begin(), _imageTimes.end());
double upcoming = nextCaptureTime(_currentTime, sequenceID);
if (_nextCapture != upcoming){
_nextCapture = upcoming;
_intervalLength = upcoming - _currentTime;
}
return true;
}*/
/*
bool ImageSequencer::getImagePath(double& currentTime, std::string& path, bool closedInterval){
auto binary_find = [](std::vector<ImageParams>::iterator begin,
std::vector<ImageParams>::iterator end,
const ImageParams &val,
bool(*imageComparer)(const ImageParams &a, const ImageParams &b))->std::vector<ImageParams>::iterator{
// Finds the lower bound in at most log(last - first) + 1 comparisons
std::vector<ImageParams>::iterator it = std::lower_bound(begin, end, val, imageComparer);
if (it != begin){
return std::prev(it);
}
return end;
};
auto it = binary_find(_timeStamps.begin(), _timeStamps.end(), { currentTime, 0, "", "", false }, imageComparer);
//check [start, stop]
if (closedInterval && (it == _timeStamps.end() || it->stopTime < currentTime || it->projected)){
return false;
}else if (!closedInterval && (it == _timeStamps.end() || it->projected)){
return false;
}
double upcoming = nextCaptureTime(currentTime);
if (_nextCapture != upcoming){
_nextCapture = upcoming;
_intervalLength = upcoming - currentTime;
}
it->projected = true;
path = it->path;
currentTime = it->startTime;
@@ -178,6 +360,9 @@ bool ImageSequencer::sequenceReset(){
}
return true;
}
*/
// ----------------- LOAD-DATA RELATED STUFF --------------------------------------
bool replace(std::string& str, const std::string& from, const std::string& to) {
size_t start_pos = str.find(from);
@@ -187,17 +372,6 @@ bool replace(std::string& str, const std::string& from, const std::string& to) {
return true;
}
bool ImageSequencer::parsePlaybook(const std::string& dir, const std::string& type, std::string year){
ghoul::filesystem::Directory playbookDir(dir, true);
std::vector<std::string> dirlist = playbookDir.read(true, false);
for (auto path : dirlist) {
bool success = parsePlaybookFile(path, year);
if (!success)
return false;
}
return true; // add check
}
double ImageSequencer::getMissionElapsedTime(std::string timestr){
std::string::size_type sz; // alias of size_t
double met = std::stod(timestr, &sz);
@@ -213,11 +387,13 @@ double ImageSequencer::getMissionElapsedTime(std::string timestr){
else if (met < _metRef){
et -= diff;
}
return et;
}
bool ImageSequencer::parsePlaybookFile(const std::string& fileName, std::string year) {
bool ImageSequencer::parsePlaybookFile(const std::string& fileName, int& sequenceID, std::string year) {
setSequenceId(sequenceID);
std::vector<ImageParams> tmp;
if (size_t position = fileName.find_last_of(".") + 1){
if (position != std::string::npos){
std::string extension = ghoul::filesystem::File(fileName).fileExtension();
@@ -272,7 +448,7 @@ bool ImageSequencer::parsePlaybookFile(const std::string& fileName, std::string
}
} while (!file.eof());
std::sort(_timeStamps.begin(), _timeStamps.end(), cmp);
std::sort(_timeStamps.begin(), _timeStamps.end(), imageComparer);
std::ofstream cachedFileStream(cachedFile);
cachedFileStream << std::setprecision(64);
@@ -305,19 +481,23 @@ bool ImageSequencer::parsePlaybookFile(const std::string& fileName, std::string
if (pos != std::string::npos){
timestr = timestr.substr(24, 9);
et = getMissionElapsedTime(timestr);
createImage(et, et + shutter, id[i], _defaultCaptureImage);
createImage(tmp, et, id[i], "", _defaultCaptureImage);
std::sort(tmp.begin(), tmp.end(), imageComparer);
}
}
} while (!file.eof());
std::sort(_timeStamps.begin(), _timeStamps.end(), cmp);
}
}
}
_timeStamps.push_back(tmp);
return true;
}
bool ImageSequencer::loadSequence(const std::string& dir) {
bool ImageSequencer::loadSequence(const std::string& dir, int& sequenceID) {
setSequenceId(sequenceID);
std::vector<ImageParams> tmp;
ghoul::filesystem::Directory sequenceDir(dir, true);
std::vector<std::string> sequencePaths = sequenceDir.read(true, false); // check inputs
for (auto path : sequencePaths){
@@ -333,27 +513,25 @@ bool ImageSequencer::loadSequence(const std::string& dir) {
// open up label files
std::string line = "";
std::string specsOfInterest[2] = { "START_TIME", "STOP_TIME" };
double timestamps[2] = { 0.0, 0.0 };
std::string specsOfInterest = "START_TIME"; // can be extended
double timestamp= 0.0;
bool found = false;
do {
std::getline(file, line);
for (int i = 0; i < 2; i++){
auto pos = line.find(specsOfInterest[i]);
auto pos = line.find(specsOfInterest);
if (pos != std::string::npos){
std::string time = line.substr(line.find("=") + 2);
time.erase(std::remove(time.begin(), time.end(), ' '), time.end());
openspace::SpiceManager::ref().getETfromDate(time, timestamps[i]);
openspace::SpiceManager::ref().getETfromDate(time, timestamp);
}
}
if (timestamps[0] != 0.0 && timestamps[1] != 0.0){
if (timestamp != 0.0){
found = true;
std::string ext = "jpg";
path.replace(path.begin() + position, path.end(), ext);
bool fileExists = FileSys.fileExists(path);
if (fileExists) {
createImage(timestamps[0], timestamps[1], "NH_LORRI", path); /// fix active instrument!
std::sort(_timeStamps.begin(), _timeStamps.end(), cmp);
createImage(tmp, timestamp, "NH_LORRI", "", path); /// fix active instrument!
std::sort(tmp.begin(), tmp.end(), imageComparer);
}
}
} while (!file.eof() && found == false);
@@ -361,6 +539,7 @@ bool ImageSequencer::loadSequence(const std::string& dir) {
}
}
}
_timeStamps.push_back(tmp);
return !_timeStamps.empty();
}

View File

@@ -0,0 +1,314 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
// open space includes
#include <openspace/util/ImageSequencer2.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/filesystem/directory.h>
#include <openspace/util/time.h>
#include <ghoul/filesystem/cachemanager.h>
#include <openspace/util/spicemanager.h>
#include <fstream>
#include <iterator>
#include <iomanip>
#include <limits>
namespace {
const std::string _loggerCat = "ImageSequencer2";
}
namespace openspace {
ImageSequencer2* ImageSequencer2::_instance = nullptr;
ImageSequencer2::ImageSequencer2() :
_hasData(false),
_latestImage(nullptr),
_defaultCaptureImage(absPath("${OPENSPACE_DATA}/scene/common/textures/placeholder_blank.png"))
{}
ImageSequencer2& ImageSequencer2::ref() {
assert(_instance != nullptr);
return *_instance;
}
void ImageSequencer2::initialize() {
assert(_instance == nullptr);
_instance = new ImageSequencer2;
}
void ImageSequencer2::deinitialize() {
delete _instance;
_instance = nullptr;
}
bool ImageSequencer2::isReady(){
return _hasData;
}
void ImageSequencer2::updateSequencer(double time){
if (_currentTime != time){
_previousTime = _currentTime;
_currentTime = time;
}
}
std::pair<double, std::string> ImageSequencer2::getNextTarget(){
auto compareTime = [](const std::pair<double, std::string> &a,
const std::pair<double, std::string> &b)->bool{
return a.first < b.first;
};
std::pair<double, std::string> findEqualToThis;
findEqualToThis.first = _currentTime;
auto it = std::lower_bound(_targetTimes.begin(), _targetTimes.end(), findEqualToThis, compareTime);
if (it != _targetTimes.end() && it != _targetTimes.begin()){
return (*it);
}
}
std::pair<double, std::string> ImageSequencer2::getCurrentTarget(){
auto compareTime = [](const std::pair<double, std::string> &a,
const std::pair<double, std::string> &b)->bool{
return a.first < b.first;
};
std::pair<double, std::string> findEqualToThis;
findEqualToThis.first = _currentTime;
auto it = std::lower_bound(_targetTimes.begin(), _targetTimes.end(), findEqualToThis, compareTime);
if (it != _targetTimes.end() && it != _targetTimes.begin()){
return *std::prev(it);
}
else
return std::make_pair(0.0, "No Target");
}
std::pair<double, std::vector<std::string>> ImageSequencer2::getIncidentTargetList(int range){
std::pair<double, std::vector<std::string>> incidentTargets;
auto compareTime = [](const std::pair<double, std::string> &a,
const std::pair<double, std::string> &b)->bool{
return a.first < b.first;
};
// what to look for
std::pair<double, std::string> findEqualToThis;
findEqualToThis.first = _currentTime;
auto it = std::lower_bound(_targetTimes.begin(), _targetTimes.end(), findEqualToThis, compareTime);
if (it != _targetTimes.end() && it != _targetTimes.begin()){
// move the iterator to the first element of the range
std::advance(it, -(range + 1));
// now extract incident range
for (int i = 0; i < 2 * range + 1; i++){
incidentTargets.first = it->first;
incidentTargets.second.push_back(it->second);
it++;
if (it == _targetTimes.end())
break;
}
}
return incidentTargets;
}
double ImageSequencer2::getIntervalLength(){
double upcoming = getNextCaptureTime();
if (_nextCapture != upcoming){
_nextCapture = upcoming;
_intervalLength = upcoming - _currentTime;
}
return _intervalLength;
}
double ImageSequencer2::getNextCaptureTime(){
auto compareTime = [](const double &a, const double &b)->bool{
return a < b;
};
double nextCaptureTime = 0;
auto it = std::lower_bound(_captureProgression.begin(), _captureProgression.end(), _currentTime, compareTime);
if (it != _captureProgression.end())
nextCaptureTime = *it;
return nextCaptureTime;
}
const Image* ImageSequencer2::getLatestImageForInstrument(const std::string _instrumentID){
return _latestImage;
}
std::map<std::string, bool> ImageSequencer2::getActiveInstruments(){
// first set all instruments to off
for (auto i : _switchingMap)
_switchingMap[i.first] = false;
// go over the filetranslation map
for (auto key : _fileTranslation){
// for each spice-instrument
for (auto instrumentID : key.second->getTranslation()){
// check if the spice-instrument is active
if (instumentActive(instrumentID)){
// go over switching map
for (auto instrument : _switchingMap){
// if instrument is present in switching map
if (instrumentID == instrument.first){
// set as active
_switchingMap[instrumentID] = true;
}
}
}
}
}
// return entire map, seen in GUI.
return _switchingMap;
}
bool ImageSequencer2::instumentActive(std::string instrumentID){
for (auto i : _instrumentTimes){
//check if this instrument is in range
if (i.second.inRange(_currentTime)){
//if so, then get the corresponding spiceID
std::vector<std::string> spiceIDs = _fileTranslation[i.first]->getTranslation();
//check which specific subinstrument is firing
for (auto s : spiceIDs){
if (s == instrumentID){
return true;
}
}
}
}
return false;
}
bool ImageSequencer2::getImagePaths(std::vector<Image>& captures,
std::string projectee,
std::string instrumentID){
if (!instumentActive(instrumentID) && !Time::ref().timeJumped()) return false;
// dev. note: this is only due to LORRI being the only instrument implemented so far.
return getImagePaths(captures, projectee);
}
bool ImageSequencer2::getImagePaths(std::vector<Image>& captures,
std::string projectee){
// check if this instance is either in range or
// a valid candidate to recieve data
//if (!Time::ref().timeJumped() && projectee == getCurrentTarget().second)
if (_subsetMap[projectee]._range.inRange(_currentTime) ||
_subsetMap[projectee]._range.inRange(_previousTime)){
auto compareTime = [](const Image &a,
const Image &b)->bool{
return a.startTime < b.startTime;
};
// for readability we store the iterators
auto begin = _subsetMap[projectee]._subset.begin();
auto end = _subsetMap[projectee]._subset.end();
// create temporary storage
std::vector<Image> captureTimes;
// what to look for
Image findPrevious, findCurrent;
findPrevious.startTime = _previousTime;
findCurrent.startTime = _currentTime;
// find the two iterators that correspond to the latest time jump
auto curr = std::lower_bound(begin, end, findCurrent, compareTime);
auto prev = std::lower_bound(begin, end, findPrevious, compareTime);
if (curr != begin && curr != end && prev != begin && prev != end && prev < curr){
if (curr->startTime >= prev->startTime){
std::transform(prev, curr, std::back_inserter(captureTimes),
[](const Image& i) {
return i;
});
std::reverse(captureTimes.begin(), captureTimes.end());
captures = captureTimes;
if (!captures.empty())
_latestImage = &captures.back();
return true;
}
}
}
return false;
}
void ImageSequencer2::sortData(){
auto targetComparer = [](const std::pair<double, std::string> &a,
const std::pair<double, std::string> &b)->bool{
return a.first < b.first;
};
auto imageComparer = [](const Image &a, const Image &b)->bool{
return a.startTime < b.startTime;
};
std::sort(_targetTimes.begin(), _targetTimes.end(), targetComparer);
std::stable_sort(_captureProgression.begin(), _captureProgression.end());
for (auto sub : _subsetMap){
std::sort(_subsetMap[sub.first]._subset.begin(),
_subsetMap[sub.first]._subset.end(), imageComparer);
}
}
void ImageSequencer2::runSequenceParser(SequenceParser* parser){
parser->create();
// get new data
std::map<std::string, Decoder*> in1 = parser->getTranslation();
std::map<std::string, ImageSubset> in2 = parser->getSubsetMap();
std::vector<std::pair<std::string, TimeRange>> in3 = parser->getIstrumentTimes();
std::vector<std::pair<double, std::string>> in4 = parser->getTargetTimes();
std::vector<double> in5 = parser->getCaptureProgression();
// check for sanity
assert(in1.size() > 0, "Sequencer failed to load Translation" );
assert(in2.size() > 0, "Sequencer failed to load Image data" );
assert(in3.size() > 0, "Sequencer failed to load Instrument Switching schedule");
assert(in4.size() > 0, "Sequencer failed to load Target Switching schedule" );
assert(in5.size() > 0, "Sequencer failed to load Capture progression" );
// append data
_fileTranslation.insert ( in1.begin(), in1.end());
_subsetMap.insert ( in2.begin(), in2.end());
_instrumentTimes.insert ( _instrumentTimes.end(), in3.begin(), in3.end());
_targetTimes.insert ( _targetTimes.end(), in4.begin(), in4.end());
_captureProgression.insert(_captureProgression.end(), in5.begin(), in5.end());
// sorting of data _not_ optional
sortData();
// extract payload from _fileTranslation
for (auto t : _fileTranslation){
if (t.second->getDecoderType() == "CAMERA" ||
t.second->getDecoderType() == "SCANNER" ){
std::vector<std::string> spiceIDs = t.second->getTranslation();
for (auto id : spiceIDs){
_switchingMap[id] = false;
}
}
}
_hasData = true;
}
} // namespace openspace

View File

@@ -0,0 +1,74 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2015 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <openspace/util/instrumentdecoder.h>
namespace {
const std::string _loggerCat = "InstrumentDecoder";
const std::string keyDetector = "DetectorType";
const std::string keySpice = "Spice";
const std::string keyStopCommand = "StopCommand";
}
namespace openspace {
InstrumentDecoder::InstrumentDecoder(const ghoul::Dictionary& dictionary)
{
bool success = dictionary.getValue(keyDetector, _type);
ghoul_assert(success, "Instrument has not provided detector type");
for_each(_type.begin(), _type.end(), [](char& in){ in = ::toupper(in); });
if (!dictionary.hasKeyAndValue<std::string>(keyStopCommand) && _type == "SCANNER"){
LWARNING("Scanner must provide stop command, please check mod file.");
}else{
dictionary.getValue(keyStopCommand, _stopCommand);
}
std::vector<std::string> spice;
ghoul::Dictionary spiceDictionary;
success = dictionary.getValue(keySpice, spiceDictionary);
ghoul_assert(success, "Instrument did not provide spice ids");
_spiceIDs.resize(spiceDictionary.size());
for (int i = 0; i < _spiceIDs.size(); ++i) {
std::string id;
spiceDictionary.getValue(std::to_string(i + 1), id);
_spiceIDs[i] = id;
}
}
std::string InstrumentDecoder::getStopCommand(){
return _stopCommand;
}
std::string InstrumentDecoder::getDecoderType(){
return _type;
}
std::vector<std::string> InstrumentDecoder::getTranslation(){
return _spiceIDs;
}
} // namespace openspace

298
src/util/labelparser.cpp Normal file
View File

@@ -0,0 +1,298 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <openspace/util/ImageSequencer2.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/filesystem/directory.h>
#include <openspace/util/time.h>
#include <openspace/util/spicemanager.h>
#include <fstream>
#include <iterator>
#include <iomanip>
#include <limits>
#include <openspace/util/labelparser.h>
namespace {
const std::string _loggerCat = "LabelParser";
const std::string keySpecs = "Read";
const std::string keyConvert = "Convert";
}
namespace openspace {
LabelParser::LabelParser(const std::string& fileName,
ghoul::Dictionary translationDictionary)
{
_fileName = fileName;
//get the different instrument types
const std::vector<std::string>& decoders = translationDictionary.keys();
//for each decoder (assuming might have more if hong makes changes)
for (int i = 0; i < decoders.size(); i++){
ghoul::Dictionary typeDictionary;
translationDictionary.getValue(decoders[i], typeDictionary);
//create dictionary containing all {playbookKeys , spice IDs}
if (decoders[i] == "Instrument"){
//for each playbook call -> create a Decoder object
const std::vector<std::string>& keys = typeDictionary.keys();
for (int j = 0; j < keys.size(); j++){
std::string currentKey = decoders[i] + "." + keys[j];
ghoul::Dictionary decoderDictionary;
translationDictionary.getValue(currentKey, decoderDictionary);
Decoder *decoder = Decoder::createFromDictionary(decoderDictionary, decoders[i]);
//insert decoder to map - this will be used in the parser to determine
//behavioral characteristics of each instrument
_fileTranslation[keys[j]] = decoder;
}
}
if (decoders[i] == "Target"){
ghoul::Dictionary specsOfInterestDictionary;
typeDictionary.getValue(keySpecs, specsOfInterestDictionary);
_specsOfInterest.resize(specsOfInterestDictionary.size());
for (int n = 0; n < _specsOfInterest.size(); ++n) {
std::string readMe;
specsOfInterestDictionary.getValue(std::to_string(n + 1), readMe);
_specsOfInterest[n] = readMe;
}
ghoul::Dictionary convertDictionary;
typeDictionary.getValue(keyConvert, convertDictionary);
const std::vector<std::string>& keys = convertDictionary.keys();
for (int j = 0; j < keys.size(); j++){
ghoul::Dictionary itemDictionary;
convertDictionary.getValue(keys[j], itemDictionary);
Decoder *decoder = Decoder::createFromDictionary(itemDictionary, decoders[i]);
//insert decoder to map - this will be used in the parser to determine
//behavioral characteristics of each instrument
_fileTranslation[keys[j]] = decoder;
};
}
}
}
std::string LabelParser::decode(std::string line){
for (auto key : _fileTranslation){
std::size_t value = line.find(key.first);
if (value != std::string::npos){
std::string toTranslate = line.substr(value);
return _fileTranslation[toTranslate]->getTranslation()[0]; //lbls always 1:1 -> single value return.
}
}
return "";
}
std::string LabelParser::encode(std::string line) {
for (auto key : _fileTranslation) {
std::size_t value = line.find(key.first);
if (value != std::string::npos) {
//std::cout << line.substr(value) << std::endl;
return line.substr(value);
}
}
return "";
}
void LabelParser::create(){
auto imageComparer = [](const Image &a, const Image &b)->bool{
return a.startTime < b.startTime;
};
auto targetComparer = [](const std::pair<double, std::string> &a,
const std::pair<double, std::string> &b)->bool{
return a.first < b.first;
};
std::string previousTarget;
std::string lblName = "";
ghoul::filesystem::Directory sequenceDir(_fileName, true);
std::vector<std::string> sequencePaths = sequenceDir.read(true, false); // check inputs
for (auto path : sequencePaths){
//std::cout << path << std::endl;
if (size_t position = path.find_last_of(".") + 1){
if (position != std::string::npos){
ghoul::filesystem::File currentFile(path);
std::string extension = currentFile.fileExtension();
if (extension == "lbl" || extension == "LBL"){ // discovered header file
std::ifstream file(currentFile.path());
if (!file.good()) LERROR("Failed to open label file '" << currentFile.path() << "'");
int count = 0;
// open up label files
std::string line = "";
std::string previousSequence;
TimeRange instrumentRange;
do {
std::getline(file, line);
std::string read = line.substr(0, line.find_first_of(" "));
line.erase(std::remove(line.begin(), line.end(), '"'), line.end());
line.erase(std::remove(line.begin(), line.end(), ' '), line.end());
/* Add more */
if (read == "TARGET_NAME"){
_target = decode(line);
count++;
}
if (read == "INSTRUMENT_HOST_NAME"){
_instrumentHostID = decode(line);
count++;
}
if (read == "INSTRUMENT_ID"){
_instrumentID = decode(line);
lblName = encode(line);
count++;
}
if (read == "DETECTOR_TYPE"){
_detectorType = decode(line);
count++;
}
if (read == "START_TIME"){
std::string start = line.substr(line.find("=") + 2);
start.erase(std::remove(start.begin(), start.end(), ' '), start.end());
openspace::SpiceManager::ref().getETfromDate(start, _startTime);
count++;
getline(file, line);
read = line.substr(0, line.find_first_of(" "));
if (read == "STOP_TIME"){
std::string stop = line.substr(line.find("=") + 2);
stop.erase(std::remove(stop.begin(), stop.end(), ' '), stop.end());
openspace::SpiceManager::ref().getETfromDate(stop, _stopTime);
count++;
}
else{
LERROR("Label file " + _fileName + " deviates from generic standard!");
LINFO("Please make sure input data adheres to format https://pds.jpl.nasa.gov/documents/qs/labels.html");
}
}
if (count == _specsOfInterest.size()){
count = 0;
std::string ext = "jpg";
path.replace(path.begin() + position, path.end(), ext);
bool fileExists = FileSys.fileExists(path);
if (!fileExists) {
ext = "JPG";
path.replace(path.begin() + position, path.end(), ext);
fileExists = FileSys.fileExists(path);
}
if (fileExists) {
Image image;
std::vector<std::string> spiceInstrument;
spiceInstrument.push_back(_instrumentID);
createImage(image, _startTime, _startTime, spiceInstrument, _target, path);
_subsetMap[image.target]._subset.push_back(image);
_subsetMap[image.target]._range.setRange(_startTime);
_captureProgression.push_back(_startTime);
std::stable_sort(_captureProgression.begin(), _captureProgression.end());
}
}
} while (!file.eof());
}
}
}
}
std::vector<Image> tmp;
for (auto key : _subsetMap){
for (auto image : key.second._subset){
tmp.push_back(image);
}
}
std::sort(tmp.begin(), tmp.end(), imageComparer);
for (auto image : tmp){
if (previousTarget != image.target){
previousTarget = image.target;
std::pair<double, std::string> v_target = std::make_pair(image.startTime, image.target);
_targetTimes.push_back(v_target);
std::sort(_targetTimes.begin(), _targetTimes.end(), targetComparer);
}
}
std::ofstream myfile;
myfile.open("LabelFileOutput.txt");
//print all
for (auto target : _subsetMap){
_instrumentTimes.push_back(std::make_pair(lblName, _subsetMap[target.first]._range));
std::string min, max;
SpiceManager::ref().getDateFromET(target.second._range._min, min);
SpiceManager::ref().getDateFromET(target.second._range._max, max);
myfile << std::endl;
for (auto image : target.second._subset){
std::string time_beg;
std::string time_end;
SpiceManager::ref().getDateFromET(image.startTime, time_beg);
SpiceManager::ref().getDateFromET(image.stopTime, time_end);
myfile << std::fixed
<< " " << time_beg
<< "-->" << time_end
<< " [ " << image.startTime
<< " ] " << image.target << std::setw(10);
for (auto instrument : image.activeInstruments){
myfile << " " << instrument;
}
myfile << std::endl;
}
}
myfile.close();
}
void LabelParser::createImage(Image& image, double startTime, double stopTime, std::vector<std::string> instr, std::string targ, std::string pot) {
image.startTime = startTime;
image.stopTime = stopTime;
image.path = pot;
for (int i = 0; i < instr.size(); i++){
image.activeInstruments.push_back(instr[i]);
}
image.target = targ;
image.projected = false;
}
std::map<std::string, ImageSubset> LabelParser::getSubsetMap(){
return _subsetMap;
}
std::vector<std::pair<std::string, TimeRange>> LabelParser::getIstrumentTimes(){
return _instrumentTimes;
}
std::vector<std::pair<double, std::string>> LabelParser::getTargetTimes(){
return _targetTimes;
}
}

View File

@@ -0,0 +1,53 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2015 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <openspace/util/scannerdecoder.h>
namespace {
const std::string _loggerCat = "ScannerDecoder";
}
namespace openspace {
ScannerDecoder::ScannerDecoder(const ghoul::Dictionary& dictionary) : _type("SCANNER")
{
std::string value;
for (int k = 0; k < dictionary.size(); k++){
dictionary.getValue(std::to_string(k + 1), value);
_spiceIDs.push_back(value);
}
}
std::string ScannerDecoder::getDecoderType(){
return _type;
}
std::vector<std::string> ScannerDecoder::getSpiceIDs(){
return _spiceIDs;
}
void ScannerDecoder::setStopCommand(std::string stopCommand){
_abort = stopCommand;
}
} // namespace openspace

View File

@@ -575,21 +575,19 @@ bool SpiceManager::getEstimatedPosition(const double time, const std::string tar
targetPosition = PowerScaledCoordinate::CreatePowerScaledCoordinate(pos[0], pos[1], pos[2]);
checkForError("Error estimating positin for target: " + target + ", or observer: " + observer);
return targetFound && observerFound;
}
// do NOT remove this method.
bool SpiceManager::frameConversion(glm::dvec3& v, const std::string& from, const std::string& to, double ephemerisTime) const{
glm::dmat3 transform;
if (from == to)
return true;
// get rotation matrix from frame A - frame B
pxform_c(from.c_str(), to.c_str(), ephemerisTime, (double(*)[3])glm::value_ptr(transform));
bool success = !failed_c();
if (!success){
reset_c();
return false;
}
bool hasError = checkForError("Error converting from frame '" + from +
"' to frame '" + to + "' at time " + std::to_string(ephemerisTime));
if (hasError)
@@ -626,12 +624,6 @@ bool SpiceManager::targetWithinFieldOfView(const std::string& instrument,
&visible);
isVisible = (visible == SPICETRUE);
bool success = !failed_c();
if (!success){
reset_c();
return false;
}
bool hasError = checkForError("Checking if target '" + target +
"' is in view of instrument '" + instrument + "' failed");
@@ -649,25 +641,18 @@ bool SpiceManager::targetWithinFieldOfView(const std::string& instrument,
int visible;
std::string bodyfixed = "IAU_";
bodyfixed += target;
std::string frame = frameFromBody(target);
fovtrg_c(instrument.c_str(),
target.c_str(),
method.c_str(),
bodyfixed.c_str(),
frame.c_str(),
aberrationCorrection.c_str(),
observer.c_str(),
&targetEpoch,
&visible);
isVisible = (visible == SPICETRUE);
bool success = !failed_c();
if (!success){
reset_c();
return false;
}
bool hasError = checkForError("Checking if target '" + target +
"' is in view of instrument '" + instrument + "' failed");
@@ -702,9 +687,9 @@ bool SpiceManager::getSurfaceIntercept(const std::string& target,
// allow client specify non-inertial frame.
std::string bodyfixed = "IAU_";
convert = (referenceFrame.find(bodyfixed) == std::string::npos);
if (convert){
bodyfixed += target;
}else{
if (convert) {
bodyfixed = frameFromBody(target);
} else {
bodyfixed = referenceFrame;
}
@@ -723,12 +708,6 @@ bool SpiceManager::getSurfaceIntercept(const std::string& target,
isVisible = (found == SPICETRUE);
bool success = !failed_c();
if (!success){
reset_c();
return false;
}
bool hasError = checkForError("Error retrieving surface intercept on target '" + target + "'" +
"viewed from observer '" + observer + "' in " +
"reference frame '" + bodyfixed + "' at time '" +
@@ -828,7 +807,7 @@ bool SpiceManager::getPositionTransformMatrix(const std::string& fromFrame,
double ephemerisTime,
glm::dmat3& positionMatrix) const
{
bool success, estimated = false;
bool success = false, estimated = false;
pxform_c(fromFrame.c_str(), toFrame.c_str(),
ephemerisTime, (double(*)[3])glm::value_ptr(positionMatrix));
@@ -837,6 +816,11 @@ bool SpiceManager::getPositionTransformMatrix(const std::string& fromFrame,
reset_c();
estimated = getEstimatedTransformMatrix(ephemerisTime, fromFrame, toFrame, positionMatrix);
}
if (_showErrors) {
bool hasError = checkForError("Error retrieving position transform matrix from "
"frame '" + fromFrame + "' to frame '" + toFrame +
"' at time '" + std::to_string(ephemerisTime));
}
positionMatrix = glm::transpose(positionMatrix);
@@ -910,8 +894,10 @@ bool SpiceManager::getEstimatedTransformMatrix(const double time, const std::str
}
}
}
bool hasError = checkForError("Error estimating transform matrix from frame: "
+ fromFrame + ", to frame: " + toFrame);
return true;
return !hasError;
}
@@ -953,12 +939,6 @@ bool SpiceManager::getFieldOfView(int instrument,
(double(*)[3])boundsArr // the bounds
);
bool success = !failed_c();
if (!success){
reset_c();
return false;
}
bool hasError = checkForError("Error getting Field-of-View parameters for "
"instrument '" + std::to_string(instrument) + "'");
if (hasError)
@@ -977,10 +957,38 @@ bool SpiceManager::getFieldOfView(int instrument,
return true;
}
std::string SpiceManager::frameFromBody(const std::string body) const {
for (auto pair : _frameByBody) {
if (pair.first == body) {
return pair.second;
}
}
std::string unionPrefix = "IAU_";
std::string frame = "";
if (body.find(unionPrefix) == std::string::npos)
frame = unionPrefix + body;
else
frame = body;
return frame;
}
bool SpiceManager::addFrame(const std::string body, const std::string frame) {
if (body == "" || frame == "")
return false;
else {
_frameByBody.push_back(std::make_pair(body, frame));
return true;
}
}
bool SpiceManager::checkForError(std::string errorMessage) {
int failed = failed_c();
if (failed) {
if (failed && _showErrors) {
static char msg[1024];
if (!errorMessage.empty()) {
getmsg_c("LONG", 1024, msg);
@@ -990,6 +998,11 @@ bool SpiceManager::checkForError(std::string errorMessage) {
reset_c();
return true;
}
else if (failed) {
reset_c();
return false;
}
else
return false;
}

View File

@@ -0,0 +1,51 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2015 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <openspace/util/targetdecoder.h>
namespace {
const std::string _loggerCat = "TargetDecoder";
}
namespace openspace {
TargetDecoder::TargetDecoder(const ghoul::Dictionary& dictionary) :_type("TARGET")
{
_names.resize(dictionary.size());
for (int i = 0; i < _names.size(); ++i) {
std::string readMe;
dictionary.getValue(std::to_string(i + 1), readMe);
_names[i] = readMe;
}
}
std::string TargetDecoder::getDecoderType(){
return _type;
}
std::vector<std::string> TargetDecoder::getTranslation(){
return _names;
}
} // namespace openspace