put changes in new class

This commit is contained in:
Sovanny Huy
2019-05-24 14:18:42 -04:00
parent e2dbbe6ccd
commit 950df71c73
5 changed files with 237 additions and 174 deletions
+2
View File
@@ -65,6 +65,7 @@ set(HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/scale/timedependentscale.h
${CMAKE_CURRENT_SOURCE_DIR}/timeframe/timeframeinterval.h
${CMAKE_CURRENT_SOURCE_DIR}/timeframe/timeframeunion.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/suntexturemanager.h
)
source_group("Header Files" FILES ${HEADER_FILES})
@@ -109,6 +110,7 @@ set(SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/scale/timedependentscale.cpp
${CMAKE_CURRENT_SOURCE_DIR}/timeframe/timeframeinterval.cpp
${CMAKE_CURRENT_SOURCE_DIR}/timeframe/timeframeunion.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/suntexturemanager.cpp
)
source_group("Source Files" FILES ${SOURCE_FILES})
+3 -165
View File
@@ -39,13 +39,6 @@
#include <ghoul/opengl/textureunit.h>
#include <ghoul/opengl/programobject.h>
#include <modules/fitsfilereader/include/fitsfilereader.h>
#include <openspace/engine/globals.h>
#include <openspace/util/timemanager.h>
#include <openspace/util/httprequest.h>
#include <modules/sync/syncs/httpsynchronization.h>
namespace {
constexpr const char* _loggerCat = "RenderableSphere";
} // namespace
@@ -307,6 +300,8 @@ RenderableSphere::RenderableSphere(const ghoul::Dictionary& dictionary)
setRenderBin(Renderable::RenderBin::Background);
}
}
_sunTexMgr = SunTextureManager();
}
bool RenderableSphere::isReady() const {
@@ -424,42 +419,7 @@ void RenderableSphere::render(const RenderData& data, RendererTasks&) {
if(_texturePath.fullyQualifiedIdentifier() == "Scene.Sun.Renderable.Texture"){
std::string current = global::timeManager.time().ISO8601();
current.erase(4, 1);
current.erase(6, 1);
current.erase(8, 1);
current.erase(10, 1);
current.erase(12);
if(_textureList.find(current) != _textureList.end()){
_textureList[_activeTextureDate] = std::move(_texture);
_texture = std::move(_textureList[current]);
_activeTextureDate = current;
}
_counter++;
if(_counter == 800){
startUploadTexture();
}
// if(_counter == 1000){
// LERROR(_texturePath);
// LERROR("just before thread starts");
// _dldthread = std::thread([this](){this->startDownloadTexture();});
//
// }
// //LERROR("just after thread starts");
//
// if(_counter == 1200){
// if(_dldthread.joinable()){
// LERROR("it's joinable. counter: " + std::to_string(_counter));
// _dldthread.join();
// startUploadTexture();
// }
// }
_sunTexMgr.update(_texture);
}
ghoul::opengl::TextureUnit unit;
@@ -539,128 +499,6 @@ void RenderableSphere::loadTexture() {
}
}
}
void RenderableSphere::startDownloadTexture(){
std::string url = "http://localhost:3000/getmeafitsimage";
std::string testpath = absPath("../../../../../../httpdownload/FITSdata/iam.fits.gz");
AsyncHttpFileDownload ashd = AsyncHttpFileDownload(url, testpath, HttpFileDownload::Overwrite::Yes);
HttpRequest::RequestOptions opt = {};
opt.requestTimeoutSeconds = 0;
ashd.start(opt);
LERROR("nedladdning startad");
ashd.wait();
LERROR("efter wait");
}
void RenderableSphere::startUploadTexture(){
// FitsFileReader fitsFileReader(false);
//
// std::string dateID ="";
// std::string testpath = absPath("../../../../../../httpdownload/FITSdata/iam.fits.gz");
// const auto tempBild = fitsFileReader.readImageFloat(testpath);
// // const auto tempBild = fitsFileReader.readImageFloat(testpath);
//
// const std::string datestring = *fitsFileReader.readHeaderValueString("DATE");
//
// int magicalCounter = 0;
// for (char c : datestring) {
// if (std::isdigit(c)) {
// if (magicalCounter >= 0 && magicalCounter < 12) {
// dateID += c;
// }
// magicalCounter++;
// }
// }
//
//
// const float stdvalue = *fitsFileReader.readHeaderValueFloat("IMGRMS01");
//
// GLfloat fitsImage[360 * 180];
// for (int i = 0; i < 360; i++) {
// for (int j = 0; j < 180; j++) {
// float color = tempBild->contents[(i * 180) + j];
// color = (color+stdvalue)/stdvalue; //some semirandom operation to actually se something in the texture
// fitsImage[(i * 180) + j] = static_cast<GLfloat>(color);
// }
// }
//
// auto textureFits = std::make_unique<ghoul::opengl::Texture>(fitsImage, glm::vec3(360, 180, 1),ghoul::opengl::Texture::Format::Red, GL_R32F,GL_FLOAT);
// textureFits->uploadTexture();
//
// LERROR("laddat ner och laddar upp: " + dateID);
// if(_textureList.find(dateID) != _textureList.end()){
// _textureList[dateID].release();
// }
//
// _textureList[dateID] = std::move(textureFits);
// Above is for when serving a fits file from node server
// Below is for a directory of fits files on disk
// Given that the node-part is located just outside the openspace-directory
const std::string fitsDir = "../../../../../../node/FITSdata/"; //Mac
//const std::string fitsDir = "../../../node/FITSdata/"; //PC
// All the files in the given directory
std::vector<std::string> fitsFiles = ghoul::filesystem::Directory(fitsDir).readFiles();
std::sort(fitsFiles.begin(), fitsFiles.end());
LERROR("antal filer: " + std::to_string(fitsFiles.size()));
for (const auto & entry : fitsFiles) {
LERROR(absPath(entry));
FitsFileReader fitsFileReader(false);
std::string dateID ="";
const auto tempBild = fitsFileReader.readImageFloat(entry);
// const auto tempBild = fitsFileReader.readImageFloat(testpath);
const std::string datestring = *fitsFileReader.readHeaderValueString("DATE");
int magicalCounter = 0;
for (char c : datestring) {
if (std::isdigit(c)) {
if (magicalCounter >= 0 && magicalCounter < 12) {
dateID += c;
}
magicalCounter++;
}
}
const float stdvalue = *fitsFileReader.readHeaderValueFloat("IMGRMS01");
GLfloat fitsImage[360 * 180];
for (int i = 0; i < 360; i++) {
for (int j = 0; j < 180; j++) {
float color = tempBild->contents[(i * 180) + j];
color = (color+stdvalue)/stdvalue; //some semirandom operation to actually se something in the texture
fitsImage[(i * 180) + j] = static_cast<GLfloat>(color);
}
}
LERROR(dateID + " pixelvärde på position 100 100: " + std::to_string(fitsImage[10000]));
auto textureFits = std::make_unique<ghoul::opengl::Texture>(fitsImage, glm::vec3(360, 180, 1),ghoul::opengl::Texture::Format::Red, GL_R32F,GL_FLOAT);
textureFits->uploadTexture();
LERROR(std::to_string(static_cast<int>(*textureFits)));
if(_textureList.find(dateID) != _textureList.end()){
_textureList[dateID].release();
}
_textureList[dateID] = std::move(textureFits);
}
_activeTextureDate = _textureList.begin()->first;
_texture.release();
_texture = std::move(_textureList.begin()->second);
}
} // namespace openspace
+4 -9
View File
@@ -32,7 +32,8 @@
#include <openspace/properties/scalar/intproperty.h>
#include <openspace/properties/scalar/floatproperty.h>
#include <ghoul/opengl/uniformcache.h>
#include <thread>
#include <modules/base/rendering/suntexturemanager.h>
namespace ghoul::opengl {
@@ -65,14 +66,6 @@ public:
private:
void loadTexture();
void startUploadTexture();
void startDownloadTexture();
std::unordered_map<std::string, std::unique_ptr<ghoul::opengl::Texture>> _textureList;
int _counter = 0;
int _counter2 = 0;
std::thread _dldthread;
std::string _activeTextureDate;
properties::StringProperty _texturePath;
properties::OptionProperty _orientation;
@@ -96,6 +89,8 @@ private:
_mirrorTexture) _uniformCache;
bool _sphereIsDirty = false;
SunTextureManager _sunTexMgr;
};
} // namespace openspace
@@ -0,0 +1,164 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2019 *
* *
* 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 <modules/base/rendering/suntexturemanager.h>
#include <openspace/util/timemanager.h>
#include <openspace/engine/globals.h>
#include <modules/fitsfilereader/include/fitsfilereader.h>
#include <openspace/util/httprequest.h>
#include <modules/sync/syncs/httpsynchronization.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/logging/logmanager.h>
namespace {
constexpr const char* _loggerCat = "SunTextureManager";
} // namespace
namespace openspace {
SunTextureManager::SunTextureManager(){
}
void SunTextureManager::update(std::unique_ptr<ghoul::opengl::Texture>& texture){
std::string current = global::timeManager.time().ISO8601();
current.erase(4, 1);
current.erase(6, 1);
current.erase(8, 1);
current.erase(10, 1);
current.erase(12);
if(_textureList.find(current) != _textureList.end()){
_textureList[_activeTextureDate] = std::move(texture);
texture = std::move(_textureList[current]);
_activeTextureDate = current;
}
_counter++;
if(_counter == 800){
startUploadTexture();
}
// if(_counter == 1000){
// LERROR(_texturePath);
// LERROR("just before thread starts");
// _dldthread = std::thread([this](){this->startDownloadTexture();});
//
// }
// //LERROR("just after thread starts");
//
// if(_counter == 1200){
// if(_dldthread.joinable()){
// LERROR("it's joinable. counter: " + std::to_string(_counter));
// _dldthread.join();
// startUploadTexture();
// }
// }
}
void SunTextureManager::startDownloadTexture(){
std::string url = "http://localhost:3000/getmeafitsimage";
std::string testpath = absPath("../../../../../../httpdownload/FITSdata/iam.fits.gz");
AsyncHttpFileDownload ashd = AsyncHttpFileDownload(url, testpath, HttpFileDownload::Overwrite::Yes);
HttpRequest::RequestOptions opt = {};
opt.requestTimeoutSeconds = 0;
ashd.start(opt);
LERROR("nedladdning startad");
ashd.wait();
LERROR("efter wait");
}
void SunTextureManager::startUploadTexture(){
// Given that the node-part is located just outside the openspace-directory
const std::string fitsDir = "../../../../../../node/FITSdata/"; //Mac
//const std::string fitsDir = "../../../node/FITSdata/"; //PC
// All the files in the given directory
std::vector<std::string> fitsFiles = ghoul::filesystem::Directory(fitsDir).readFiles();
std::sort(fitsFiles.begin(), fitsFiles.end());
LERROR("antal filer: " + std::to_string(fitsFiles.size()));
for (const auto & entry : fitsFiles) {
//LERROR(absPath(entry));
FitsFileReader fitsFileReader(false);
std::string dateID ="";
const auto tempBild = fitsFileReader.readImageFloat(entry);
// const auto tempBild = fitsFileReader.readImageFloat(testpath);
const std::string datestring = *fitsFileReader.readHeaderValueString("DATE");
int magicalCounter = 0;
for (char c : datestring) {
if (std::isdigit(c)) {
if (magicalCounter >= 0 && magicalCounter < 12) {
dateID += c;
}
magicalCounter++;
}
}
const float stdvalue = *fitsFileReader.readHeaderValueFloat("IMGRMS01");
GLfloat fitsImage[360 * 180];
for (int i = 0; i < 360; i++) {
for (int j = 0; j < 180; j++) {
float color = tempBild->contents[(i * 180) + j];
color = (color+stdvalue)/stdvalue; //some semirandom operation to actually se something in the texture
fitsImage[(i * 180) + j] = static_cast<GLfloat>(color);
}
}
//LERROR(dateID + " pixelvärde på position 100 100: " + std::to_string(fitsImage[10000]));
auto textureFits = std::make_unique<ghoul::opengl::Texture>(fitsImage, glm::vec3(360, 180, 1),ghoul::opengl::Texture::Format::Red, GL_R32F,GL_FLOAT);
textureFits->uploadTexture();
//LERROR(std::to_string(static_cast<int>(*textureFits)));
if(_textureList.find(dateID) != _textureList.end()){
_textureList[dateID].release();
}
_textureList[dateID] = std::move(textureFits);
}
LERROR("Laddat upp texturerna till GPU:n");
// _activeTextureDate = _textureList.begin()->first;
// _texture.release();
// _texture = std::move(_textureList.begin()->second);
}
}
@@ -0,0 +1,64 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2019 *
* *
* 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 __OPENSPACE_MODULE_BASE___SUNTEXTUREMANAGER___H__
#define __OPENSPACE_MODULE_BASE___SUNTEXTUREMANAGER___H__
//#include <thread>
#include <ghoul/opengl/texture.h>
#include <thread>
namespace ghoul::opengl {
class Texture;
} // namespace ghoul::opengl
namespace openspace {
class SunTextureManager {
public:
SunTextureManager();
void update(std::unique_ptr<ghoul::opengl::Texture>& texture);
private:
void startUploadTexture();
void startDownloadTexture();
int _counter = 0;
int _counter2 = 0;
std::thread _dldthread;
std::string _activeTextureDate = "NODATE";
std::unordered_map<std::string, std::unique_ptr<ghoul::opengl::Texture>> _textureList;
};
} // namespace openspace
#endif // __OPENSPACE_MODULE_BASE___SUNTEXTUREMANAGER___H__