mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-05 11:09:37 -06:00
DataPlane reads from server
This commit is contained in:
@@ -36,50 +36,50 @@
|
||||
#include <openspace/util/time.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "DataPlane";
|
||||
const std::string _loggerCat = "DataPlane";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
DataPlane::DataPlane(const ghoul::Dictionary& dictionary)
|
||||
:CygnetPlane(dictionary)
|
||||
,_topColor("topColor", "Top Color", glm::vec4(1,0,0,1), glm::vec4(0), glm::vec4(1))
|
||||
,_midColor("midColor", "Mid Color", glm::vec4(0,0,0,0), glm::vec4(0), glm::vec4(1))
|
||||
,_botColor("botColor", "Bot Color", glm::vec4(0,0,1,1), glm::vec4(0), glm::vec4(1))
|
||||
,_tfValues("tfValues", "TF Values", glm::vec2(0.5,0.1), glm::vec2(0), glm::vec2(1))
|
||||
,_colorbar(nullptr)
|
||||
,_futureData(nullptr)
|
||||
{
|
||||
_id = id();
|
||||
setName("DataPlane" + std::to_string(_id));
|
||||
:CygnetPlane(dictionary)
|
||||
,_topColor("topColor", "Top Color", glm::vec4(1,0,0,1), glm::vec4(0), glm::vec4(1))
|
||||
,_midColor("midColor", "Mid Color", glm::vec4(0,0,0,0), glm::vec4(0), glm::vec4(1))
|
||||
,_botColor("botColor", "Bot Color", glm::vec4(0,0,1,1), glm::vec4(0), glm::vec4(1))
|
||||
,_tfValues("tfValues", "TF Values", glm::vec2(0.5,0.1), glm::vec2(0), glm::vec2(1))
|
||||
,_colorbar(nullptr)
|
||||
,_futureData(nullptr)
|
||||
{
|
||||
_id = id();
|
||||
setName("DataPlane" + std::to_string(_id));
|
||||
|
||||
addProperty(_topColor);
|
||||
addProperty(_midColor);
|
||||
addProperty(_botColor);
|
||||
addProperty(_tfValues);
|
||||
// addProperty(_topColor);
|
||||
// addProperty(_midColor);
|
||||
// addProperty(_botColor);
|
||||
// addProperty(_tfValues);
|
||||
|
||||
registerProperties();
|
||||
OsEng.gui()._iSWAproperty.registerProperty(&_topColor);
|
||||
OsEng.gui()._iSWAproperty.registerProperty(&_midColor);
|
||||
OsEng.gui()._iSWAproperty.registerProperty(&_botColor);
|
||||
OsEng.gui()._iSWAproperty.registerProperty(&_tfValues);
|
||||
// registerProperties();
|
||||
// OsEng.gui()._iSWAproperty.registerProperty(&_topColor);
|
||||
// OsEng.gui()._iSWAproperty.registerProperty(&_midColor);
|
||||
// OsEng.gui()._iSWAproperty.registerProperty(&_botColor);
|
||||
// OsEng.gui()._iSWAproperty.registerProperty(&_tfValues);
|
||||
|
||||
dictionary.getValue("kwPath", _kwPath);
|
||||
// dictionary.getValue("kwPath", _kwPath);
|
||||
}
|
||||
|
||||
DataPlane::~DataPlane(){}
|
||||
|
||||
|
||||
bool DataPlane::initialize(){
|
||||
// std::string kwPath;
|
||||
_kw = std::make_shared<KameleonWrapper>(_kwPath);
|
||||
// dictionary.getValue("KW", _kw);
|
||||
// std::string kwPath;
|
||||
// _kw = std::make_shared<KameleonWrapper>(_kwPath);
|
||||
// dictionary.getValue("KW", _kw);
|
||||
|
||||
KameleonWrapper::Model model = _kw->model();
|
||||
if( model == KameleonWrapper::Model::BATSRUS)
|
||||
_var = "p";
|
||||
else
|
||||
_var = "rho";
|
||||
// KameleonWrapper::Model model = _kw->model();
|
||||
// if( model == KameleonWrapper::Model::BATSRUS)
|
||||
// _var = "p";
|
||||
// else
|
||||
// _var = "rho";
|
||||
|
||||
|
||||
createPlane();
|
||||
@@ -95,17 +95,19 @@ bool DataPlane::initialize(){
|
||||
return false;
|
||||
}
|
||||
|
||||
_dimensions = glm::size3_t(500,500,1);
|
||||
float zSlice = 0.5f;
|
||||
_dataSlice = _kw->getUniformSliceValues(std::string(_var), _dimensions, zSlice);
|
||||
// _dimensions = glm::size3_t(500,500,1);
|
||||
// float zSlice = 0.5f;
|
||||
// _dataSlice = _kw->getUniformSliceValues(std::string(_var), _dimensions, zSlice);
|
||||
|
||||
loadTexture();
|
||||
// loadTexture();
|
||||
updateTexture();
|
||||
|
||||
std::cout << "Creating Colorbar" << std::endl;
|
||||
_colorbar = std::make_shared<ColorBar>();
|
||||
if(_colorbar){
|
||||
_colorbar->initialize();
|
||||
}
|
||||
|
||||
// std::cout << "Creating Colorbar" << std::endl;
|
||||
// _colorbar = std::make_shared<ColorBar>();
|
||||
// if(_colorbar){
|
||||
// _colorbar->initialize();
|
||||
// }
|
||||
|
||||
return isReady();
|
||||
}
|
||||
@@ -114,143 +116,183 @@ bool DataPlane::deinitialize(){
|
||||
unregisterProperties();
|
||||
destroyPlane();
|
||||
destroyShader();
|
||||
|
||||
_kw = nullptr;
|
||||
_memorybuffer = "";
|
||||
|
||||
_colorbar->deinitialize();
|
||||
_colorbar = nullptr;
|
||||
|
||||
// _kw = nullptr;
|
||||
_memorybuffer = "";
|
||||
|
||||
// _colorbar->deinitialize();
|
||||
// _colorbar = nullptr;
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void DataPlane::render(const RenderData& data){
|
||||
if(_texture){
|
||||
psc position = data.position;
|
||||
glm::mat4 transform = glm::mat4(1.0);
|
||||
if(_texture){
|
||||
psc position = data.position;
|
||||
glm::mat4 transform = glm::mat4(1.0);
|
||||
|
||||
glm::mat4 rotx = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(1, 0, 0));
|
||||
glm::mat4 roty = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(0, -1, 0));
|
||||
glm::mat4 rotz = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(0, 0, 1));
|
||||
glm::mat4 rotx = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(1, 0, 0));
|
||||
glm::mat4 roty = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(0, -1, 0));
|
||||
glm::mat4 rotz = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(0, 0, 1));
|
||||
|
||||
glm::mat4 rot = 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]);
|
||||
}
|
||||
}
|
||||
glm::mat4 rot = 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]);
|
||||
}
|
||||
}
|
||||
|
||||
transform = transform * rotz * roty; //BATSRUS
|
||||
transform = transform * rotz * roty; //BATSRUS
|
||||
|
||||
if(_data->frame == "GSM"){
|
||||
glm::vec4 v(1,0,0,1);
|
||||
glm::vec3 xVec = glm::vec3(transform*v);
|
||||
xVec = glm::normalize(xVec);
|
||||
if(_data->frame == "GSM"){
|
||||
glm::vec4 v(1,0,0,1);
|
||||
glm::vec3 xVec = glm::vec3(transform*v);
|
||||
xVec = glm::normalize(xVec);
|
||||
|
||||
double lt;
|
||||
glm::vec3 sunVec =
|
||||
SpiceManager::ref().targetPosition("SUN", "Earth", "GALACTIC", {}, _time, lt);
|
||||
sunVec = glm::normalize(sunVec);
|
||||
double lt;
|
||||
glm::vec3 sunVec =
|
||||
SpiceManager::ref().targetPosition("SUN", "Earth", "GALACTIC", {}, _time, lt);
|
||||
sunVec = glm::normalize(sunVec);
|
||||
|
||||
float angle = acos(glm::dot(xVec, sunVec));
|
||||
glm::vec3 ref = glm::cross(xVec, sunVec);
|
||||
float angle = acos(glm::dot(xVec, sunVec));
|
||||
glm::vec3 ref = glm::cross(xVec, sunVec);
|
||||
|
||||
glm::mat4 rotation = glm::rotate(glm::mat4(1.0f), angle, ref);
|
||||
transform = rotation * transform;
|
||||
}
|
||||
glm::mat4 rotation = glm::rotate(glm::mat4(1.0f), angle, ref);
|
||||
transform = rotation * transform;
|
||||
}
|
||||
|
||||
position += transform*glm::vec4(_data->offset.x, _data->offset.z, _data->offset.y, _data->offset.w);
|
||||
position += transform*glm::vec4(_data->offset.x, _data->offset.z, _data->offset.y, _data->offset.w);
|
||||
|
||||
// Activate shader
|
||||
_shader->activate();
|
||||
glEnable(GL_ALPHA_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
// Activate shader
|
||||
_shader->activate();
|
||||
glEnable(GL_ALPHA_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
_shader->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
|
||||
_shader->setUniform("ModelTransform", transform);
|
||||
_shader->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
|
||||
_shader->setUniform("ModelTransform", transform);
|
||||
|
||||
_shader->setUniform("top", _topColor.value());
|
||||
_shader->setUniform("mid", _midColor.value());
|
||||
_shader->setUniform("bot", _botColor.value());
|
||||
_shader->setUniform("tfValues", _tfValues.value());
|
||||
// _shader->setUniform("top", _topColor.value());
|
||||
// _shader->setUniform("mid", _midColor.value());
|
||||
// _shader->setUniform("bot", _botColor.value());
|
||||
// _shader->setUniform("tfValues", _tfValues.value());
|
||||
|
||||
setPscUniforms(*_shader.get(), data.camera, position);
|
||||
setPscUniforms(*_shader.get(), data.camera, position);
|
||||
|
||||
ghoul::opengl::TextureUnit unit;
|
||||
unit.activate();
|
||||
_texture->bind();
|
||||
_shader->setUniform("texture1", unit);
|
||||
ghoul::opengl::TextureUnit unit;
|
||||
unit.activate();
|
||||
_texture->bind();
|
||||
_shader->setUniform("texture1", unit);
|
||||
|
||||
glBindVertexArray(_quad);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
glEnable(GL_CULL_FACE);
|
||||
_shader->deactivate();
|
||||
glBindVertexArray(_quad);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
glEnable(GL_CULL_FACE);
|
||||
_shader->deactivate();
|
||||
|
||||
position += transform*(glm::vec4(0.5f*_data->scale.x+100.0f ,-0.5f*_data->scale.y, 0.0f, _data->scale.w));
|
||||
// RenderData data = { *_camera, psc(), doPerformanceMeasurements };
|
||||
ColorBarData cbdata = { data.camera,
|
||||
position,
|
||||
transform,
|
||||
_topColor.value(),
|
||||
_midColor.value(),
|
||||
_botColor.value(),
|
||||
_tfValues.value()
|
||||
// transform
|
||||
};
|
||||
_colorbar->render(cbdata);
|
||||
}
|
||||
// position += transform*(glm::vec4(0.5f*_data->scale.x+100.0f ,-0.5f*_data->scale.y, 0.0f, _data->scale.w));
|
||||
// // RenderData data = { *_camera, psc(), doPerformanceMeasurements };
|
||||
// ColorBarData cbdata = { data.camera,
|
||||
// position,
|
||||
// transform,
|
||||
// _topColor.value(),
|
||||
// _midColor.value(),
|
||||
// _botColor.value(),
|
||||
// _tfValues.value()
|
||||
// // transform
|
||||
// };
|
||||
// _colorbar->render(cbdata);
|
||||
}
|
||||
}
|
||||
|
||||
void DataPlane::update(const UpdateData& data){
|
||||
if(_planeIsDirty)
|
||||
createPlane();
|
||||
if(_planeIsDirty)
|
||||
createPlane();
|
||||
|
||||
_time = Time::ref().currentTime();
|
||||
_stateMatrix = SpiceManager::ref().positionTransformMatrix("GALACTIC", _data->frame, _time);
|
||||
_time = Time::ref().currentTime();
|
||||
_stateMatrix = SpiceManager::ref().positionTransformMatrix("GALACTIC", _data->frame, _time);
|
||||
|
||||
float openSpaceUpdateInterval = abs(Time::ref().deltaTime()*_updateInterval);
|
||||
if(openSpaceUpdateInterval){
|
||||
if(abs(_time-_lastUpdateTime) >= openSpaceUpdateInterval){
|
||||
updateTexture();
|
||||
_lastUpdateTime = _time;
|
||||
}
|
||||
if(abs(_time-_lastUpdateTime) >= openSpaceUpdateInterval){
|
||||
updateTexture();
|
||||
_lastUpdateTime = _time;
|
||||
}
|
||||
}
|
||||
|
||||
if(_futureData && _futureData->isFinished){
|
||||
std::cout << _memorybuffer << std::endl;
|
||||
_futureData = nullptr;
|
||||
// std::cout << _memorybuffer << std::endl;
|
||||
loadTexture();
|
||||
_futureData = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void DataPlane::loadTexture() {
|
||||
ghoul::opengl::Texture::FilterMode filtermode = ghoul::opengl::Texture::FilterMode::Linear;
|
||||
ghoul::opengl::Texture::WrappingMode wrappingmode = ghoul::opengl::Texture::WrappingMode::ClampToEdge;
|
||||
std::unique_ptr<ghoul::opengl::Texture> texture =
|
||||
std::make_unique<ghoul::opengl::Texture>(_dataSlice, _dimensions, ghoul::opengl::Texture::Format::Red, GL_RED, GL_FLOAT, filtermode, wrappingmode);
|
||||
void DataPlane::loadTexture() {
|
||||
std::stringstream ss(_memorybuffer);
|
||||
std::string line;
|
||||
|
||||
if (texture) {
|
||||
// LDEBUG("Loaded texture from '" << absPath(_path) << "'");
|
||||
_dimensions = glm::size3_t(61, 61, 1);
|
||||
float* values = new float[3721];
|
||||
int i = 0;
|
||||
ss >> std::ws;
|
||||
|
||||
texture->uploadTexture();
|
||||
float min = std::numeric_limits<float>::max();
|
||||
float max = std::numeric_limits<float>::min();
|
||||
|
||||
// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
|
||||
texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
|
||||
while(getline(ss,line)){
|
||||
if(line.find("#") == 0){
|
||||
// std::cout << line << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
_texture = std::move(texture);
|
||||
}
|
||||
float x, y, z, N, V, B;
|
||||
std::stringstream sl(line);
|
||||
|
||||
sl >> std::ws >> x >> y >> z >> N >> V >> B;
|
||||
values[i] = N;
|
||||
|
||||
min = std::min(min,values[i]);
|
||||
max = std::max(max,values[i]);
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
std::cout << min << ", " << max << std::endl;
|
||||
for(int j=0; j<i; j++){
|
||||
float normValue = (values[j]-min)/(max-min);
|
||||
values[j] = glm::clamp(normValue, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
_dataSlice = values;
|
||||
|
||||
|
||||
ghoul::opengl::Texture::FilterMode filtermode = ghoul::opengl::Texture::FilterMode::Linear;
|
||||
ghoul::opengl::Texture::WrappingMode wrappingmode = ghoul::opengl::Texture::WrappingMode::ClampToEdge;
|
||||
std::unique_ptr<ghoul::opengl::Texture> texture =
|
||||
std::make_unique<ghoul::opengl::Texture>(_dataSlice, _dimensions, ghoul::opengl::Texture::Format::Red, GL_RED, GL_FLOAT, filtermode, wrappingmode);
|
||||
|
||||
if (texture) {
|
||||
// LDEBUG("Loaded texture from '" << absPath(_path) << "'");
|
||||
|
||||
texture->uploadTexture();
|
||||
|
||||
// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
|
||||
texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
|
||||
|
||||
_texture = std::move(texture);
|
||||
}
|
||||
}
|
||||
|
||||
void DataPlane::updateTexture(){
|
||||
std::shared_ptr<DownloadManager::FileFuture> future = ISWAManager::ref().downloadImageToMemory(-_data->id, _memorybuffer);
|
||||
if(future){
|
||||
_futureData = future;
|
||||
}
|
||||
std::shared_ptr<DownloadManager::FileFuture> future = ISWAManager::ref().downloadDataToMemory(2, _memorybuffer);
|
||||
|
||||
if(future){
|
||||
_futureData = future;
|
||||
}
|
||||
}
|
||||
|
||||
int DataPlane::id(){
|
||||
static int id = 0;
|
||||
return id++;
|
||||
static int id = 0;
|
||||
return id++;
|
||||
}
|
||||
}// namespace openspace
|
||||
@@ -37,21 +37,21 @@
|
||||
#include <openspace/util/time.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "TexutePlane";
|
||||
const std::string _loggerCat = "TexutePlane";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
TexturePlane::TexturePlane(const ghoul::Dictionary& dictionary)
|
||||
:CygnetPlane(dictionary)
|
||||
,_futureTexture(nullptr)
|
||||
:CygnetPlane(dictionary)
|
||||
,_futureTexture(nullptr)
|
||||
{
|
||||
_id = id();
|
||||
std::string name;
|
||||
dictionary.getValue("Name", name);
|
||||
setName(name);
|
||||
//setName("TexturePlane" + std::to_string(_id));
|
||||
registerProperties();
|
||||
_id = id();
|
||||
std::string name;
|
||||
dictionary.getValue("Name", name);
|
||||
setName(name);
|
||||
//setName("TexturePlane" + std::to_string(_id));
|
||||
registerProperties();
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ TexturePlane::~TexturePlane(){}
|
||||
bool TexturePlane::initialize(){
|
||||
createPlane();
|
||||
createShader();
|
||||
updateTexture();
|
||||
updateTexture();
|
||||
return isReady();
|
||||
}
|
||||
|
||||
@@ -71,153 +71,141 @@ bool TexturePlane::deinitialize(){
|
||||
_memorybuffer = "";
|
||||
// std::remove(absPath(_data->path).c_str());
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void TexturePlane::render(const RenderData& data){
|
||||
if(_texture){
|
||||
// psc position = data.position;
|
||||
// glm::mat4 transform = glm::mat4(1.0);
|
||||
// // transform = glm::inverse(OsEng.renderEngine().camera()->viewRotationMatrix());
|
||||
if(_texture){
|
||||
// psc position = data.position;
|
||||
// glm::mat4 transform = glm::mat4(1.0);
|
||||
// // transform = glm::inverse(OsEng.renderEngine().camera()->viewRotationMatrix());
|
||||
|
||||
// float textureRatio = (float (_texture->height()/float(_texture->width())));
|
||||
// transform = glm::scale(transform, glm::vec3(1, textureRatio, 1));
|
||||
// float textureRatio = (float (_texture->height()/float(_texture->width())));
|
||||
// transform = glm::scale(transform, glm::vec3(1, textureRatio, 1));
|
||||
|
||||
// glm::mat4 rotx = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(1, 0, 0));
|
||||
// glm::mat4 roty = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(0, 1, 0));
|
||||
// // glm::mat4 rot = 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]);
|
||||
// }
|
||||
// }*/
|
||||
// glm::mat4 rotx = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(1, 0, 0));
|
||||
// glm::mat4 roty = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(0, 1, 0));
|
||||
// // glm::mat4 rot = 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]);
|
||||
// }
|
||||
// }*/
|
||||
|
||||
// //transform = transform * roty * rotx;
|
||||
// position += transform*glm::vec4(-_pscOffset.x, _pscOffset.z, _pscOffset.y, _pscOffset.w);
|
||||
// //transform = transform * roty * rotx;
|
||||
// position += transform*glm::vec4(-_pscOffset.x, _pscOffset.z, _pscOffset.y, _pscOffset.w);
|
||||
|
||||
// // transform = glm::rotate(transform, _roatation.value()[0], glm::vec3(1,0,0));
|
||||
// // transform = glm::rotate(transform, _roatation.value()[1], glm::vec3(0,1,0));
|
||||
// // transform = glm::rotate(transform, _roatation.value()[2], glm::vec3(0,0,1));
|
||||
// // transform = glm::rotate(transform, _roatation.value()[0], glm::vec3(1,0,0));
|
||||
// // transform = glm::rotate(transform, _roatation.value()[1], glm::vec3(0,1,0));
|
||||
// // transform = glm::rotate(transform, _roatation.value()[2], glm::vec3(0,0,1));
|
||||
|
||||
psc position = data.position;
|
||||
glm::mat4 transform = glm::mat4(1.0);
|
||||
psc position = data.position;
|
||||
glm::mat4 transform = glm::mat4(1.0);
|
||||
|
||||
glm::mat4 rotx = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(1, 0, 0));
|
||||
glm::mat4 roty = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(0, -1, 0));
|
||||
glm::mat4 rotz = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(0, 0, 1));
|
||||
glm::mat4 rotx = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(1, 0, 0));
|
||||
glm::mat4 roty = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(0, -1, 0));
|
||||
glm::mat4 rotz = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(0, 0, 1));
|
||||
|
||||
glm::mat4 rot = 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]);
|
||||
}
|
||||
}
|
||||
glm::mat4 rot = 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]);
|
||||
}
|
||||
}
|
||||
|
||||
transform = transform * rotz * roty; //BATSRUS
|
||||
transform = transform * rotz * roty; //BATSRUS
|
||||
|
||||
if(_data->frame == "GSM"){
|
||||
glm::vec4 v(1,0,0,1);
|
||||
glm::vec3 xVec = glm::vec3(transform*v);
|
||||
xVec = glm::normalize(xVec);
|
||||
if(_data->frame == "GSM"){
|
||||
glm::vec4 v(1,0,0,1);
|
||||
glm::vec3 xVec = glm::vec3(transform*v);
|
||||
xVec = glm::normalize(xVec);
|
||||
|
||||
double lt;
|
||||
glm::vec3 sunVec =
|
||||
SpiceManager::ref().targetPosition("SUN", "Earth", "GALACTIC", {}, _time, lt);
|
||||
sunVec = glm::normalize(sunVec);
|
||||
double lt;
|
||||
glm::vec3 sunVec =
|
||||
SpiceManager::ref().targetPosition("SUN", "Earth", "GALACTIC", {}, _time, lt);
|
||||
sunVec = glm::normalize(sunVec);
|
||||
|
||||
float angle = acos(glm::dot(xVec, sunVec));
|
||||
glm::vec3 ref = glm::cross(xVec, sunVec);
|
||||
float angle = acos(glm::dot(xVec, sunVec));
|
||||
glm::vec3 ref = glm::cross(xVec, sunVec);
|
||||
|
||||
glm::mat4 rotation = glm::rotate(glm::mat4(1.0f), angle, ref);
|
||||
transform = rotation * transform;
|
||||
}
|
||||
glm::mat4 rotation = glm::rotate(glm::mat4(1.0f), angle, ref);
|
||||
transform = rotation * transform;
|
||||
}
|
||||
|
||||
position += transform*glm::vec4(_data->offset.x, _data->offset.z, _data->offset.y, _data->offset.w);
|
||||
position += transform*glm::vec4(_data->offset.x, _data->offset.z, _data->offset.y, _data->offset.w);
|
||||
|
||||
// Activate shader
|
||||
_shader->activate();
|
||||
glEnable(GL_ALPHA_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
_shader->setUniform("ViewProjection", OsEng.renderEngine().camera()->viewProjectionMatrix());
|
||||
_shader->setUniform("ModelTransform", transform);
|
||||
setPscUniforms(*_shader.get(), *OsEng.renderEngine().camera(), position);
|
||||
// Activate shader
|
||||
_shader->activate();
|
||||
glEnable(GL_ALPHA_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
_shader->setUniform("ViewProjection", OsEng.renderEngine().camera()->viewProjectionMatrix());
|
||||
_shader->setUniform("ModelTransform", transform);
|
||||
setPscUniforms(*_shader.get(), *OsEng.renderEngine().camera(), position);
|
||||
|
||||
ghoul::opengl::TextureUnit unit;
|
||||
unit.activate();
|
||||
_texture->bind();
|
||||
_shader->setUniform("texture1", unit);
|
||||
ghoul::opengl::TextureUnit unit;
|
||||
unit.activate();
|
||||
_texture->bind();
|
||||
_shader->setUniform("texture1", unit);
|
||||
|
||||
glBindVertexArray(_quad);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glBindVertexArray(_quad);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
glEnable(GL_CULL_FACE);
|
||||
|
||||
_shader->deactivate();
|
||||
}
|
||||
_shader->deactivate();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void TexturePlane::update(const UpdateData& data){
|
||||
if(_planeIsDirty)
|
||||
createPlane();
|
||||
if(_planeIsDirty)
|
||||
createPlane();
|
||||
|
||||
_time = Time::ref().currentTime();
|
||||
_stateMatrix = SpiceManager::ref().positionTransformMatrix("GALACTIC", _data->frame, _time);
|
||||
_time = Time::ref().currentTime();
|
||||
_stateMatrix = SpiceManager::ref().positionTransformMatrix("GALACTIC", _data->frame, _time);
|
||||
|
||||
float openSpaceUpdateInterval = abs(Time::ref().deltaTime()*_updateInterval);
|
||||
if(openSpaceUpdateInterval){
|
||||
if(abs(_time-_lastUpdateTime) >= openSpaceUpdateInterval){
|
||||
updateTexture();
|
||||
_lastUpdateTime = _time;
|
||||
}
|
||||
if(abs(_time-_lastUpdateTime) >= openSpaceUpdateInterval){
|
||||
updateTexture();
|
||||
_lastUpdateTime = _time;
|
||||
}
|
||||
}
|
||||
|
||||
if(_futureTexture && _futureTexture->isFinished){
|
||||
loadTexture();
|
||||
_futureTexture = nullptr;
|
||||
}
|
||||
|
||||
|
||||
if(_futureData && _futureData->isFinished){
|
||||
std::cout << _databuffer << std::endl;
|
||||
_futureData = nullptr;
|
||||
if(_futureTexture && _futureTexture->isFinished){
|
||||
loadTexture();
|
||||
_futureTexture = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void TexturePlane::loadTexture() {
|
||||
// std::cout << _data->path << std::endl;
|
||||
// std::unique_ptr<ghoul::opengl::Texture> texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_data->path));
|
||||
std::unique_ptr<ghoul::opengl::Texture> texture = ghoul::io::TextureReader::ref().loadTexture(absPath("${OPENSPACE_DATA}/GM_openspace_Z0_20150315_000000.png"));
|
||||
// if(_memorybuffer != ""){
|
||||
// std::unique_ptr<ghoul::opengl::Texture> texture = ghoul::io::TextureReader::ref().loadTextureFromMemory(_memorybuffer);
|
||||
if (texture) {
|
||||
// LDEBUG("Loaded texture from '" << absPath(_data->path) << "'");
|
||||
texture->uploadTexture();
|
||||
// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
|
||||
texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
|
||||
// std::cout << _data->path << std::endl;
|
||||
// std::unique_ptr<ghoul::opengl::Texture> texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_data->path));
|
||||
std::unique_ptr<ghoul::opengl::Texture> texture = ghoul::io::TextureReader::ref().loadTexture(absPath("${OPENSPACE_DATA}/GM_openspace_Z0_20150315_000000.png"));
|
||||
// if(_memorybuffer != ""){
|
||||
// std::unique_ptr<ghoul::opengl::Texture> texture = ghoul::io::TextureReader::ref().loadTextureFromMemory(_memorybuffer);
|
||||
if (texture) {
|
||||
// LDEBUG("Loaded texture from '" << absPath(_data->path) << "'");
|
||||
texture->uploadTexture();
|
||||
// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
|
||||
texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
|
||||
|
||||
_texture = std::move(texture);
|
||||
}
|
||||
// }
|
||||
_texture = std::move(texture);
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
void TexturePlane::updateTexture(){
|
||||
std::shared_ptr<DownloadManager::FileFuture> future = ISWAManager::ref().downloadImageToMemory(_data->id, _memorybuffer);
|
||||
std::shared_ptr<DownloadManager::FileFuture> dataFuture = ISWAManager::ref().downloadDataToMemory(1, _databuffer);
|
||||
std::shared_ptr<DownloadManager::FileFuture> future = ISWAManager::ref().downloadImageToMemory(_data->id, _memorybuffer);
|
||||
|
||||
// std::shared_ptr<DownloadManager::FileFuture> future = ISWAManager::ref().downloadImage(_data->id, absPath(_data->path));
|
||||
if(future){
|
||||
_futureTexture = future;
|
||||
}
|
||||
|
||||
if(dataFuture)
|
||||
_futureData = dataFuture;
|
||||
// std::shared_ptr<DownloadManager::FileFuture> future = ISWAManager::ref().downloadImage(_data->id, absPath(_data->path));
|
||||
if(future){
|
||||
_futureTexture = future;
|
||||
}
|
||||
}
|
||||
|
||||
int TexturePlane::id(){
|
||||
static int id = 0;
|
||||
return id++;
|
||||
static int id = 0;
|
||||
return id++;
|
||||
}
|
||||
|
||||
}// namespace openspace
|
||||
@@ -45,12 +45,10 @@
|
||||
private:
|
||||
virtual void loadTexture() override;
|
||||
virtual void updateTexture() override;
|
||||
|
||||
|
||||
static int id();
|
||||
|
||||
std::shared_ptr<DownloadManager::FileFuture> _futureTexture;
|
||||
std::shared_ptr<DownloadManager::FileFuture> _futureData;
|
||||
std::string _databuffer;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -46,8 +46,8 @@ Fragment getFragment() {
|
||||
//diffuse.a = diffuse.r;
|
||||
float tot = diffuse.r + diffuse.g + diffuse.b;
|
||||
tot /= 3.0;
|
||||
if (tot >= 0.5 || tot <= 0.05)
|
||||
discard;
|
||||
//if (tot >= 0.5 || tot <= 0.05)
|
||||
// discard;
|
||||
|
||||
Fragment frag;
|
||||
frag.color = diffuse;
|
||||
|
||||
@@ -41,33 +41,33 @@ Fragment getFragment() {
|
||||
float depth = pscDepth(position);
|
||||
vec4 diffuse;
|
||||
// diffuse = top;
|
||||
// diffuse = texture(texture1, vs_st);
|
||||
float v = texture(texture1, vs_st).r;
|
||||
float x = tfValues.x;
|
||||
float y = tfValues.y;
|
||||
diffuse = texture(texture1, vs_st);
|
||||
//float v = texture(texture1, vs_st).r;
|
||||
//float x = tfValues.x;
|
||||
//float y = tfValues.y;
|
||||
|
||||
if(v > (x+y)){
|
||||
v = v - (x+y);
|
||||
v = v / (x-y);
|
||||
diffuse = mix(mid, top, v);
|
||||
}else if( v < (x-y)){
|
||||
v = v / (x-y);
|
||||
diffuse = mix(bot, mid, v);
|
||||
}else{
|
||||
diffuse = mid;
|
||||
}
|
||||
|
||||
// vec4 diffuse = vec4(1,vs_st,1);
|
||||
//vec4 diffuse = vec4(1,0,0,1);
|
||||
// if(position.w > 9.0) {
|
||||
// diffuse = vec4(1,0,0,1);
|
||||
//if(v > (x+y)){
|
||||
// v = v - (x+y);
|
||||
// v = v / (x-y);
|
||||
// diffuse = mix(mid, top, v);
|
||||
// }else if( v < (x-y)){
|
||||
// v = v / (x-y);
|
||||
// diffuse = mix(bot, mid, v);
|
||||
// }else{
|
||||
// diffuse = mid;
|
||||
// }
|
||||
|
||||
//diffuse.a = diffuse.r;
|
||||
// float tot = diffuse.r + diffuse.g + diffuse.b;
|
||||
// tot /= 3.0;
|
||||
if (diffuse.a <= 0.05)
|
||||
discard;
|
||||
// // vec4 diffuse = vec4(1,vs_st,1);
|
||||
// //vec4 diffuse = vec4(1,0,0,1);
|
||||
// // if(position.w > 9.0) {
|
||||
// // diffuse = vec4(1,0,0,1);
|
||||
// // }
|
||||
|
||||
// //diffuse.a = diffuse.r;
|
||||
// // float tot = diffuse.r + diffuse.g + diffuse.b;
|
||||
// // tot /= 3.0;
|
||||
// if (diffuse.a <= 0.05)
|
||||
// discard;
|
||||
|
||||
Fragment frag;
|
||||
frag.color = diffuse;
|
||||
|
||||
@@ -161,19 +161,25 @@ namespace openspace{
|
||||
// _container->addISWACygnet(cygnetId, data);
|
||||
createScreenSpace(id);
|
||||
}else if(id < 0){
|
||||
//download metadata to texture plane
|
||||
// std::shared_ptr<ExtensionFuture> extFuture = fileExtension(id);
|
||||
//download metadata to texture plane
|
||||
std::shared_ptr<MetadataFuture> extFuture = downloadMetadata(id);
|
||||
extFuture->type = "TEXTURE";
|
||||
extFuture->id = -id;
|
||||
// extFuture->parent = info;
|
||||
// _extFutures.push_back(extFuture);
|
||||
// std::shared_ptr<ExtensionFuture> extFuture
|
||||
_metaFutures.push_back(downloadMetadata(id));
|
||||
_metaFutures.push_back(extFuture);
|
||||
}
|
||||
else {
|
||||
std::shared_ptr<MetadataFuture> extFuture = downloadMetadata(-2);
|
||||
extFuture->type = "DATA";
|
||||
extFuture->id = -2;
|
||||
// std::shared_ptr<Metadata> mdata = std::make_shared<Metadata>();
|
||||
// mdata->id = 0;
|
||||
// mdata->path = absPath("${OPENSPACE_DATA}/"+info);
|
||||
// createISWACygnet(mdata);
|
||||
createDataPlane(absPath("${OPENSPACE_DATA}/"+info));
|
||||
_metaFutures.push_back(extFuture);
|
||||
// createDataPlane(absPath("${OPENSPACE_DATA}/"+info));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,7 +229,7 @@ namespace openspace{
|
||||
if(file.is_open()){
|
||||
std::string json( (std::istreambuf_iterator<char>(file) ),
|
||||
(std::istreambuf_iterator<char>()));
|
||||
std::cout << "This is in the file: " << json << std::endl;
|
||||
// std::cout << "This is in the file: " << json << std::endl;
|
||||
metaFuture->isFinished = true;
|
||||
metaFuture->json = json;
|
||||
}
|
||||
@@ -320,7 +326,6 @@ namespace openspace{
|
||||
data->path = path;
|
||||
data->parent = (*it)->parent;
|
||||
|
||||
//createTexturePlane(id, json)
|
||||
createISWACygnet(data);
|
||||
it = _extFutures.erase( it );
|
||||
}
|
||||
@@ -331,7 +336,12 @@ namespace openspace{
|
||||
|
||||
for (auto it = _metaFutures.begin(); it != _metaFutures.end(); ){
|
||||
if((*it)->isFinished) {
|
||||
createTexturePlane(7,(*it)->json);
|
||||
if((*it)->type == "TEXTURE"){
|
||||
createPlane((*it)->id,(*it)->json,std::string("TexturePlane"));
|
||||
}else{
|
||||
createPlane((*it)->id,(*it)->json,std::string("DataPlane"));
|
||||
|
||||
}
|
||||
it = _metaFutures.erase( it );
|
||||
}else{
|
||||
++it;
|
||||
@@ -395,7 +405,7 @@ namespace openspace{
|
||||
return table;
|
||||
}
|
||||
|
||||
std::string ISWAManager::parseJSONToLuaTable(int id, std::string jsonString){
|
||||
std::string ISWAManager::parseJSONToLuaTable(int id, std::string jsonString, std::string type){
|
||||
if(jsonString != ""){
|
||||
json j = json::parse(jsonString);
|
||||
|
||||
@@ -442,11 +452,12 @@ namespace openspace{
|
||||
// + std::to_string(scalew) +
|
||||
// "}";
|
||||
|
||||
|
||||
std::string table = "{"
|
||||
"Name = 'TexturePlane "+ std::to_string(id) +"' , "
|
||||
"Parent = '" + parent + "', "
|
||||
"Renderable = {"
|
||||
"Type = 'TexturePlane', "
|
||||
"Type = '" + type + "', "
|
||||
"Id = " + std::to_string(id) + ", "
|
||||
"Frame = '" + frame + "' , "
|
||||
"Scale = " + std::to_string(scale) + ", "
|
||||
@@ -455,7 +466,7 @@ namespace openspace{
|
||||
"}"
|
||||
;
|
||||
|
||||
// std::cout << table << std::endl;
|
||||
std::cout << table << std::endl;
|
||||
// ghoul::Dictionary dic;
|
||||
return table;
|
||||
}
|
||||
@@ -494,22 +505,32 @@ namespace openspace{
|
||||
return "";
|
||||
}
|
||||
|
||||
void ISWAManager::createDataPlane(std::string kwPath){
|
||||
std::string luaTable = parseKWToLuaTable(kwPath);
|
||||
//Create KameleonPlane?
|
||||
// void ISWAManager::createDataPlane(std::string kwPath){
|
||||
// std::string luaTable = parseKWToLuaTable(kwPath);
|
||||
// if(luaTable != ""){
|
||||
// std::string script = "openspace.addSceneGraphNode(" + luaTable + ");";
|
||||
// OsEng.scriptEngine().queueScript(script);
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// void ISWAManager::createTexturePlane(int id, std::string json){
|
||||
// std::string luaTable = parseJSONToLuaTable(id, json);
|
||||
// if(luaTable != ""){
|
||||
// std::string script = "openspace.addSceneGraphNode(" + parseJSONToLuaTable(id, json) + ");";
|
||||
// OsEng.scriptEngine().queueScript(script);
|
||||
// }
|
||||
// }
|
||||
|
||||
void ISWAManager::createPlane(int id, std::string json, std::string type){
|
||||
std::string luaTable = parseJSONToLuaTable(id, json, type);
|
||||
if(luaTable != ""){
|
||||
std::string script = "openspace.addSceneGraphNode(" + luaTable + ");";
|
||||
OsEng.scriptEngine().queueScript(script);
|
||||
}
|
||||
}
|
||||
|
||||
void ISWAManager::createTexturePlane(int id, std::string json){
|
||||
std::string luaTable = parseJSONToLuaTable(id, json);
|
||||
if(luaTable != ""){
|
||||
std::string script = "openspace.addSceneGraphNode(" + parseJSONToLuaTable(id, json) + ");";
|
||||
OsEng.scriptEngine().queueScript(script);
|
||||
}
|
||||
}
|
||||
|
||||
void ISWAManager::createScreenSpace(int id){
|
||||
OsEng.renderEngine().registerScreenSpaceRenderable(std::make_shared<ScreenSpaceCygnet>(id));
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ struct Metadata {
|
||||
struct MetadataFuture {
|
||||
int id;
|
||||
std::string json;
|
||||
std::string type;
|
||||
bool isFinished;
|
||||
};
|
||||
|
||||
@@ -86,15 +87,16 @@ public:
|
||||
void update();
|
||||
|
||||
private:
|
||||
std::string iSWAurl(int);
|
||||
std::string iSWADataUrl(int);
|
||||
std::string iSWAurl(int id);
|
||||
std::string iSWADataUrl(int id);
|
||||
std::shared_ptr<MetadataFuture> downloadMetadata(int id);
|
||||
std::string getDictionaryTable(int id, std::string path);
|
||||
std::string parseJSONToLuaTable(int id, std::string json);
|
||||
std::string parseJSONToLuaTable(int id, std::string json, std::string type);
|
||||
std::string parseKWToLuaTable(std::string kwPath);
|
||||
|
||||
void createDataPlane(std::string kwPath);
|
||||
void createTexturePlane(int id, std::string json);
|
||||
// void createDataPlane(std::string kwPath);
|
||||
// void createTexturePlane(int id, std::string json);
|
||||
void createPlane(int id, std::string json, std::string type);
|
||||
void createScreenSpace(int id);
|
||||
|
||||
std::map<std::string, std::string> _month;
|
||||
|
||||
Reference in New Issue
Block a user