mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-07 03:49:43 -05:00
request file extension
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" ?>
|
||||
<Cluster masterAddress="127.0.0.1">
|
||||
<Node address="127.0.0.1" port="20401">
|
||||
<Window fullScreen="false" numberOfSamples="0" border="true">
|
||||
<Window fullScreen="false" numberOfSamples="8" border="true">
|
||||
<Pos x="10" y="100" />
|
||||
<Size x="320" y="480" />
|
||||
<Viewport>
|
||||
@@ -17,7 +17,7 @@
|
||||
</Viewplane>
|
||||
</Viewport>
|
||||
</Window>
|
||||
<Window fullScreen="false" numberOfSamples="0" border="false">
|
||||
<Window fullScreen="false" numberOfSamples="8" border="false">
|
||||
<Pos x="340" y="100" />
|
||||
<Size x="320" y="480" />
|
||||
<Viewport>
|
||||
|
||||
@@ -62,6 +62,7 @@ public:
|
||||
|
||||
using DownloadProgressCallback = std::function<void(const FileFuture&)>;
|
||||
using DownloadFinishedCallback = std::function<void(const FileFuture&)>;
|
||||
using RequestFinishedCallback = std::function<void(std::string)>;
|
||||
using AsyncDownloadFinishedCallback =
|
||||
std::function<void(const std::vector<FileFuture*>&)>;
|
||||
|
||||
@@ -76,12 +77,6 @@ public:
|
||||
DownloadProgressCallback progressCallback = DownloadProgressCallback()
|
||||
);
|
||||
|
||||
FileFuture* getToMemory(
|
||||
const std::string& url, std::string& memory,
|
||||
DownloadFinishedCallback finishedCallback = DownloadFinishedCallback(),
|
||||
DownloadProgressCallback progressCallback = DownloadProgressCallback()
|
||||
);
|
||||
|
||||
std::vector<FileFuture*> downloadRequestFiles(const std::string& identifier,
|
||||
const ghoul::filesystem::Directory& destination, int version,
|
||||
bool overrideFiles = true,
|
||||
@@ -94,6 +89,9 @@ public:
|
||||
bool overrideFiles, AsyncDownloadFinishedCallback callback
|
||||
);
|
||||
|
||||
void getFileExtension(const std::string& url,
|
||||
RequestFinishedCallback finishedCallback = RequestFinishedCallback());
|
||||
|
||||
private:
|
||||
std::vector<std::string> _requestURL;
|
||||
int _applicationVersion;
|
||||
|
||||
@@ -49,13 +49,13 @@ DataPlane::DataPlane(std::shared_ptr<KameleonWrapper> kw)
|
||||
setName("DataPlane" + std::to_string(_id));
|
||||
registerProperties();
|
||||
|
||||
_fileExtension = ISWAManager::ref().fileExtension(_cygnetId.value());
|
||||
_path = "${OPENSPACE_DATA}/"+ name()+_fileExtension;
|
||||
|
||||
_fileExtension = "";
|
||||
_path = "";
|
||||
_cygnetId.onChange([this](){
|
||||
_fileExtension = ISWAManager::ref().fileExtension(_cygnetId.value());
|
||||
_path = "${OPENSPACE_DATA}/"+ name()+_fileExtension;
|
||||
updateTexture(); });
|
||||
_fileExtension = "";
|
||||
_path = "";
|
||||
ISWAManager::ref().fileExtension(_cygnetId.value(), &_fileExtension);
|
||||
});
|
||||
|
||||
|
||||
KameleonWrapper::Model model = _kw->model();
|
||||
@@ -79,6 +79,8 @@ bool DataPlane::initialize(){
|
||||
// std::cout << _modelScale.x << ", " << _modelScale.y << ", " << _modelScale.z << ", " << _modelScale.w << std::endl;
|
||||
// std::cout << _pscOffset.x << ", " << _pscOffset.y << ", " << _pscOffset.z << ", " << _pscOffset.w << std::endl;
|
||||
|
||||
ISWAManager::ref().fileExtension(_cygnetId.value(), &_fileExtension);
|
||||
|
||||
_dimensions = glm::size3_t(500,500,1);
|
||||
float zSlice = 0.5f;
|
||||
_dataSlice = _kw->getUniformSliceValues(std::string(_var), _dimensions, zSlice);
|
||||
@@ -156,7 +158,17 @@ void DataPlane::render(){
|
||||
}
|
||||
|
||||
void DataPlane::update(){
|
||||
CygnetPlane::update();
|
||||
|
||||
if(_path != ""){
|
||||
CygnetPlane::update();
|
||||
} else {
|
||||
if(_fileExtension == ""){
|
||||
//send new request
|
||||
} else{
|
||||
_path = "${OPENSPACE_DATA}/"+ name()+_fileExtension;
|
||||
updateTexture();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DataPlane::setParent(){
|
||||
|
||||
@@ -48,13 +48,15 @@ ScreenSpaceCygnet::ScreenSpaceCygnet(int cygnetId)
|
||||
OsEng.gui()._property.registerProperty(&_cygnetId);
|
||||
OsEng.gui()._property.registerProperty(&_updateInterval);
|
||||
|
||||
_fileExtension = ISWAManager::ref().fileExtension(_cygnetId.value());
|
||||
_path = "${OPENSPACE_DATA}/"+ name()+_fileExtension;
|
||||
_fileExtension = "";
|
||||
_path = "";
|
||||
|
||||
_cygnetId.onChange([this](){
|
||||
_fileExtension = ISWAManager::ref().fileExtension(_cygnetId.value());
|
||||
_path = "${OPENSPACE_DATA}/"+ name()+_fileExtension;
|
||||
updateTexture(); });
|
||||
std::remove(absPath(_path).c_str());
|
||||
_fileExtension = "";
|
||||
_path = "";
|
||||
ISWAManager::ref().fileExtension(_cygnetId.value(), &_fileExtension);
|
||||
});
|
||||
}
|
||||
|
||||
ScreenSpaceCygnet::~ScreenSpaceCygnet(){}
|
||||
@@ -64,9 +66,7 @@ bool ScreenSpaceCygnet::initialize(){
|
||||
|
||||
createPlane();
|
||||
createShaders();
|
||||
|
||||
updateTexture();
|
||||
|
||||
ISWAManager::ref().fileExtension(_cygnetId.value(), &_fileExtension);
|
||||
// Setting spherical/euclidean onchange handler
|
||||
_useFlatScreen.onChange([this](){
|
||||
useEuclideanCoordinates(_useFlatScreen.value());
|
||||
@@ -109,19 +109,28 @@ void ScreenSpaceCygnet::render(){
|
||||
}
|
||||
|
||||
void ScreenSpaceCygnet::update(){
|
||||
_time = Time::ref().currentTime();
|
||||
|
||||
if((_time-_lastUpdateTime) >= _updateInterval){
|
||||
updateTexture();
|
||||
_lastUpdateTime = _time;
|
||||
}
|
||||
|
||||
if(_futureTexture && _futureTexture->isFinished){
|
||||
_path = absPath("${OPENSPACE_DATA}/"+_futureTexture->filePath);
|
||||
loadTexture();
|
||||
if(_path != ""){
|
||||
_time = Time::ref().currentTime();
|
||||
if((_time-_lastUpdateTime) >= _updateInterval){
|
||||
updateTexture();
|
||||
_lastUpdateTime = _time;
|
||||
}
|
||||
if(_futureTexture && _futureTexture->isFinished){
|
||||
_path = absPath("${OPENSPACE_DATA}/"+_futureTexture->filePath);
|
||||
loadTexture();
|
||||
|
||||
delete _futureTexture;
|
||||
_futureTexture = nullptr;
|
||||
delete _futureTexture;
|
||||
_futureTexture = nullptr;
|
||||
}
|
||||
} else {
|
||||
if(_fileExtension == ""){
|
||||
//send new request
|
||||
} else{
|
||||
_path = "${OPENSPACE_DATA}/"+ name()+_fileExtension;
|
||||
updateTexture();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,14 +49,15 @@ TexturePlane::TexturePlane()
|
||||
setName("TexturePlane" + std::to_string(_id));
|
||||
registerProperties();
|
||||
|
||||
_fileExtension = ISWAManager::ref().fileExtension(_cygnetId.value());
|
||||
_path = "${OPENSPACE_DATA}/"+ name()+_fileExtension;
|
||||
|
||||
_fileExtension = "";
|
||||
_path = "";
|
||||
|
||||
_cygnetId.onChange([this](){
|
||||
_fileExtension = ISWAManager::ref().fileExtension(_cygnetId.value());
|
||||
_path = "${OPENSPACE_DATA}/"+ name()+_fileExtension;
|
||||
updateTexture(); });
|
||||
std::remove(absPath(_path).c_str());
|
||||
_fileExtension = "";
|
||||
_path = "";
|
||||
ISWAManager::ref().fileExtension(_cygnetId.value(), &_fileExtension);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +72,7 @@ bool TexturePlane::initialize(){
|
||||
|
||||
CygnetPlane::initialize();
|
||||
|
||||
updateTexture();
|
||||
ISWAManager::ref().fileExtension(_cygnetId.value(), &_fileExtension);
|
||||
|
||||
return isReady();
|
||||
}
|
||||
@@ -143,14 +144,22 @@ void TexturePlane::render(){
|
||||
}
|
||||
|
||||
void TexturePlane::update(){
|
||||
CygnetPlane::update();
|
||||
if(_path != ""){
|
||||
CygnetPlane::update();
|
||||
if(_futureTexture && _futureTexture->isFinished){
|
||||
_path = absPath("${OPENSPACE_DATA}/"+_futureTexture->filePath);
|
||||
loadTexture();
|
||||
|
||||
if(_futureTexture && _futureTexture->isFinished){
|
||||
_path = absPath("${OPENSPACE_DATA}/"+_futureTexture->filePath);
|
||||
loadTexture();
|
||||
|
||||
delete _futureTexture;
|
||||
_futureTexture = nullptr;
|
||||
delete _futureTexture;
|
||||
_futureTexture = nullptr;
|
||||
}
|
||||
} else {
|
||||
if(_fileExtension == ""){
|
||||
//send new request
|
||||
} else{
|
||||
_path = "${OPENSPACE_DATA}/"+ name()+_fileExtension;
|
||||
updateTexture();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -84,8 +84,22 @@ namespace openspace{
|
||||
|
||||
void ISWAManager::downloadData(){}
|
||||
|
||||
std::string ISWAManager::fileExtension(int id){
|
||||
return ".jpg";
|
||||
void ISWAManager::fileExtension(int id, std::string* ext){
|
||||
DlManager.getFileExtension(
|
||||
iSWAurl(id),
|
||||
[ext](std::string extension){
|
||||
std::stringstream ss(extension);
|
||||
std::string token;
|
||||
std::getline(ss, token, '/');
|
||||
std::getline(ss, token);
|
||||
|
||||
if(token == "jpeg"){
|
||||
token = "jpg";
|
||||
}
|
||||
|
||||
*ext = "."+token;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
std::string ISWAManager::iSWAurl(int id){
|
||||
@@ -107,7 +121,7 @@ namespace openspace{
|
||||
url += "&window=-1&cygnetId=";
|
||||
url += std::to_string(id);
|
||||
|
||||
std::cout << url << std::endl;
|
||||
//std::cout << url << std::endl;
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
std::shared_ptr<ISWACygnet> createISWACygnet(std::string);
|
||||
DownloadManager::FileFuture* downloadImage(int, std::string);
|
||||
void downloadData();
|
||||
std::string fileExtension(int);
|
||||
void fileExtension(int, std::string*);
|
||||
private:
|
||||
std::string iSWAurl(int);
|
||||
std::map<std::string, std::string> _month;
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <ghoul/misc/assert.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <chrono>
|
||||
#include <fstream>
|
||||
#include <thread>
|
||||
@@ -202,64 +202,6 @@ DownloadManager::FileFuture* DownloadManager::downloadFile(
|
||||
return future;
|
||||
}
|
||||
|
||||
DownloadManager::FileFuture* DownloadManager::getToMemory(
|
||||
const std::string& url, std::string& memoryBuffer,
|
||||
DownloadFinishedCallback finishedCallback, DownloadProgressCallback progressCallback)
|
||||
{
|
||||
FileFuture* future = new 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<DownloadManager::FileFuture*> DownloadManager::downloadRequestFiles(
|
||||
const std::string& identifier, const ghoul::filesystem::Directory& destination,
|
||||
@@ -353,4 +295,49 @@ void DownloadManager::downloadRequestFilesAsync(const std::string& identifier,
|
||||
downloadFunction();
|
||||
}
|
||||
|
||||
void DownloadManager::getFileExtension(const std::string& url,
|
||||
RequestFinishedCallback finishedCallback){
|
||||
|
||||
auto requestFunction = [url, finishedCallback]() {
|
||||
CURL* curl = curl_easy_init();
|
||||
if (curl) {
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||
//USING CURLOPT NOBODY
|
||||
curl_easy_setopt(curl, CURLOPT_NOBODY,1);
|
||||
CURLcode res = curl_easy_perform(curl);
|
||||
if(CURLE_OK == res) {
|
||||
char *ct;
|
||||
// ask for the content-type
|
||||
res = curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &ct);
|
||||
if ((res == CURLE_OK) && ct){
|
||||
|
||||
if (finishedCallback)
|
||||
finishedCallback(std::string(ct));
|
||||
}
|
||||
}
|
||||
|
||||
/* else
|
||||
future->errorMessage = curl_easy_strerror(res);*/
|
||||
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
};
|
||||
if (_useMultithreadedDownload) {
|
||||
std::thread t = std::thread(requestFunction);
|
||||
|
||||
#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 {
|
||||
requestFunction();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
Reference in New Issue
Block a user