Merge branch 'feature/iSWA' of github.com:OpenSpace/OpenSpace-Development into feature/iSWA

This commit is contained in:
Michael Nilsson
2016-04-06 15:35:00 -04:00
14 changed files with 118 additions and 34 deletions
@@ -77,6 +77,12 @@ public:
DownloadProgressCallback progressCallback = DownloadProgressCallback()
);
std::shared_ptr<FileFuture> downloadToMemory(
const std::string& url, std::string& memoryBuffer,
DownloadFinishedCallback finishedCallback = DownloadFinishedCallback(),
DownloadProgressCallback progressCallback = DownloadProgressCallback()
);
std::vector<std::shared_ptr<FileFuture>> downloadRequestFiles(const std::string& identifier,
const ghoul::filesystem::Directory& destination, int version,
bool overrideFiles = true,
+2 -1
View File
@@ -78,7 +78,8 @@ bool DataPlane::deinitialize(){
_parent = nullptr;
_kw = nullptr;
_memorybuffer = "";
return true;
}
+1 -1
View File
@@ -121,7 +121,7 @@ void ISWAContainer::addISWACygnet(std::shared_ptr<ISWACygnet> cygnet){
}
}
void ISWAContainer::deleteCygnet(std::string name){
void ISWAContainer::deleteISWACygnet(std::string name){
std::shared_ptr<ISWACygnet> c = iSWACygnet(name);
auto it = std::find(
+1 -2
View File
@@ -48,8 +48,7 @@ public:
void addISWACygnet(int id, std::string data);
void addISWACygnet(std::shared_ptr<ISWACygnet> cygnet);
void deleteCygnet(ISWACygnet* cygnet);
void deleteCygnet(std::string name);
void deleteISWACygnet(std::string name);
std::shared_ptr<ISWACygnet> iSWACygnet(std::string name);
+2 -1
View File
@@ -37,12 +37,13 @@ ISWACygnet::ISWACygnet(std::shared_ptr<Metadata> data)
, _shader(nullptr)
, _texture(nullptr)
, _data(data)
, _memorybuffer("")
{
addProperty(_enabled);
addProperty(_updateInterval);
addProperty(_delete);
_delete.onChange([this](){ISWAManager::ref().deleteCygnet(name());});
_delete.onChange([this](){ISWAManager::ref().deleteISWACygnet(name());});
}
ISWACygnet::~ISWACygnet(){}
+2
View File
@@ -72,6 +72,7 @@ protected:
std::unique_ptr<ghoul::opengl::Texture> _texture;
std::shared_ptr<Metadata> _data;
std::string _memorybuffer;
SceneGraphNode* _parent;
glm::dmat3 _stateMatrix;
@@ -79,6 +80,7 @@ protected:
double _time;
double _lastUpdateTime = 0;
int _id;
};
+15 -12
View File
@@ -113,7 +113,7 @@ bool ScreenSpaceCygnet::deinitialize(){
std::remove(absPath(_path).c_str());
_path = "";
_memorybuffer = "";
return true;
}
@@ -133,7 +133,7 @@ void ScreenSpaceCygnet::render(){
void ScreenSpaceCygnet::update(){
_time = Time::ref().currentTime();
float openSpaceUpdateInterval = abs(Time::ref().deltaTime()*_updateInterval);
if(openSpaceUpdateInterval){
if(abs(_time-_lastUpdateTime) >= openSpaceUpdateInterval){
@@ -143,9 +143,7 @@ void ScreenSpaceCygnet::update(){
}
if(_futureTexture && _futureTexture->isFinished){
loadTexture();
_futureTexture = nullptr;
}
@@ -161,7 +159,8 @@ bool ScreenSpaceCygnet::isReady() const{
}
void ScreenSpaceCygnet::updateTexture(){
std::shared_ptr<DownloadManager::FileFuture> future = ISWAManager::ref().downloadImage(_cygnetId, absPath(_path));
// std::shared_ptr<DownloadManager::FileFuture> future = ISWAManager::ref().downloadImage(_cygnetId, absPath(_path));
std::shared_ptr<DownloadManager::FileFuture> future = ISWAManager::ref().downloadImageToMemory(_cygnetId, _memorybuffer);
if(future){
_futureTexture = future;
}
@@ -169,16 +168,20 @@ void ScreenSpaceCygnet::updateTexture(){
void ScreenSpaceCygnet::loadTexture() {
std::unique_ptr<ghoul::opengl::Texture> texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_path));
if(_memorybuffer != ""){
if (texture) {
LDEBUG("Loaded texture from '" << absPath(_path) << "'");
std::unique_ptr<ghoul::opengl::Texture> texture = ghoul::io::TextureReader::ref().loadTextureFromMemory(_memorybuffer);
// std::unique_ptr<ghoul::opengl::Texture> texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_path));
texture->uploadTexture();
// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
if (texture) {
// LDEBUG("Loaded texture from '" << absPath(_path) << "'");
_texture = std::move(texture);
texture->uploadTexture();
// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
_texture = std::move(texture);
}
}
}
+1 -1
View File
@@ -56,7 +56,7 @@ private:
float _lastUpdateTime = 0.0f;
std::shared_ptr<DownloadManager::FileFuture> _futureTexture;
std::string _fileExtension;
std::string _memorybuffer;
int _id;
};
+11 -9
View File
@@ -65,8 +65,8 @@ bool TexturePlane::deinitialize(){
unregisterProperties();
destroyPlane();
destroyShader();
std::remove(absPath(_data->path).c_str());
_memorybuffer = "";
// std::remove(absPath(_data->path).c_str());
return true;
}
@@ -140,23 +140,25 @@ void TexturePlane::update(){
void TexturePlane::loadTexture() {
std::unique_ptr<ghoul::opengl::Texture> texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_data->path));
// std::cout << _data->path << std::endl;
// std::unique_ptr<ghoul::opengl::Texture> texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_data->path));
if(_memorybuffer != ""){
std::unique_ptr<ghoul::opengl::Texture> texture = ghoul::io::TextureReader::ref().loadTextureFromMemory(_memorybuffer);
if (texture) {
LDEBUG("Loaded texture from '" << absPath(_data->path) << "'");
// 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().downloadImage(_data->id, absPath(_data->path));
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;
}
+13 -3
View File
@@ -100,7 +100,7 @@ namespace openspace{
}
}
void ISWAManager::addCygnet(std::string info){
void ISWAManager::addISWACygnet(std::string info){
std::string token;
std::stringstream ss(info);
getline(ss,token,',');
@@ -115,8 +115,8 @@ namespace openspace{
_container->addISWACygnet("${OPENSPACE_DATA}/"+data);
}
void ISWAManager::deleteCygnet(std::string name){
_container->deleteCygnet(name);
void ISWAManager::deleteISWACygnet(std::string name){
_container->deleteISWACygnet(name);
}
std::shared_ptr<DownloadManager::FileFuture> ISWAManager::downloadImage(int id, std::string path){
@@ -130,6 +130,16 @@ namespace openspace{
);
}
std::shared_ptr<DownloadManager::FileFuture> ISWAManager::downloadImageToMemory(int id, std::string& buffer){
return DlManager.downloadToMemory(
iSWAurl(id),
buffer,
[](const DownloadManager::FileFuture& f){
LDEBUG("Download to memory finished");
}
);
}
void ISWAManager::downloadData(){}
std::shared_ptr<ExtensionFuture> ISWAManager::fileExtension(int id){
+3 -2
View File
@@ -61,10 +61,11 @@ public:
~ISWAManager();
std::shared_ptr<ISWACygnet> createISWACygnet(std::shared_ptr<Metadata> metadata);
void addCygnet(std::string info);
void deleteCygnet(std::string);
void addISWACygnet(std::string info);
void deleteISWACygnet(std::string);
std::shared_ptr<DownloadManager::FileFuture> downloadImage(int, std::string);
std::shared_ptr<DownloadManager::FileFuture> downloadImageToMemory(int id, std::string& buffer);
void downloadData();
std::shared_ptr<ExtensionFuture> fileExtension(int);
+1 -1
View File
@@ -434,7 +434,7 @@ void GUI::renderMainWindow() {
ImGui::InputText("addCynget", addCygnetBuffer, addCygnetBufferSize);
if(ImGui::SmallButton("Add Cygnet")){
ISWAManager::ref().addCygnet(std::string(addCygnetBuffer));
ISWAManager::ref().addISWACygnet(std::string(addCygnetBuffer));
}
}
#endif
+59
View File
@@ -202,6 +202,65 @@ std::shared_ptr<DownloadManager::FileFuture> DownloadManager::downloadFile(
return future;
}
std::shared_ptr<DownloadManager::FileFuture> DownloadManager::downloadToMemory(
const std::string& url, std::string& memoryBuffer,
DownloadFinishedCallback finishedCallback, DownloadProgressCallback progressCallback)
{
std::shared_ptr<FileFuture> future = std::make_shared<FileFuture>(std::string("memory"));
LDEBUG("Start downloading file: '" << url << "' into memory");
auto downloadFunction = [url, finishedCallback, progressCallback, future, &memoryBuffer]() {
CURL* curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &memoryBuffer);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeToMemory);
ProgressInformation p = {
future,
std::chrono::system_clock::now(),
&progressCallback
};
curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, xferinfo);
curl_easy_setopt(curl, CURLOPT_XFERINFODATA, &p);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
CURLcode res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
if (res == CURLE_OK)
future->isFinished = true;
else
future->errorMessage = curl_easy_strerror(res);
if (finishedCallback)
finishedCallback(*future);
}
};
if (_useMultithreadedDownload) {
std::thread t = std::thread(downloadFunction);
#ifdef WIN32
std::thread::native_handle_type h = t.native_handle();
SetPriorityClass(h, IDLE_PRIORITY_CLASS);
SetThreadPriority(h, THREAD_PRIORITY_LOWEST);
#else
// TODO: Implement thread priority ---abock
#endif
t.detach();
}
else {
downloadFunction();
}
return future;
}
std::vector<std::shared_ptr<DownloadManager::FileFuture>> DownloadManager::downloadRequestFiles(
const std::string& identifier, const ghoul::filesystem::Directory& destination,
int version, bool overrideFiles, DownloadFinishedCallback finishedCallback,