mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-05 03:00:58 -06:00
Lua script to add cygnet
This commit is contained in:
@@ -42,27 +42,26 @@ namespace openspace{
|
||||
ISWAContainer::ISWAContainer(const ghoul::Dictionary& dictionary)
|
||||
:Renderable(dictionary)
|
||||
{
|
||||
ISWAManager::initialize();
|
||||
std::string textureCygnets;
|
||||
std::string dataCygnets;
|
||||
dictionary.getValue("TextureCygnets", textureCygnets);
|
||||
dictionary.getValue("DataCygnets", dataCygnets);
|
||||
std::cout << textureCygnets << std::endl;
|
||||
std::cout << dataCygnets << std::endl;
|
||||
// std::string textureCygnets;
|
||||
// std::string dataCygnets;
|
||||
// dictionary.getValue("TextureCygnets", textureCygnets);
|
||||
// dictionary.getValue("DataCygnets", dataCygnets);
|
||||
// std::cout << textureCygnets << std::endl;
|
||||
// std::cout << dataCygnets << std::endl;
|
||||
|
||||
if(textureCygnets != ""){
|
||||
json j = json::parse(textureCygnets);
|
||||
for (auto& id : j) {
|
||||
ISWAManager::ref().addISWACygnet(id, "TEXTURE");
|
||||
}
|
||||
}
|
||||
// if(textureCygnets != ""){
|
||||
// json j = json::parse(textureCygnets);
|
||||
// for (auto& id : j) {
|
||||
// ISWAManager::ref().addISWACygnet(id, "TEXTURE");
|
||||
// }
|
||||
// }
|
||||
|
||||
if(dataCygnets != ""){
|
||||
json j = json::parse(dataCygnets);
|
||||
for (auto& id : j) {
|
||||
ISWAManager::ref().addISWACygnet(id, "DATA");
|
||||
}
|
||||
}
|
||||
// if(dataCygnets != ""){
|
||||
// json j = json::parse(dataCygnets);
|
||||
// for (auto& id : j) {
|
||||
// ISWAManager::ref().addISWACygnet(id, "DATA");
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
ISWAContainer::~ISWAContainer(){}
|
||||
|
||||
@@ -32,359 +32,383 @@
|
||||
#include <modules/iswa/rendering/screenspacecygnet.h>
|
||||
#include <modules/iswa/ext/json/json.hpp>
|
||||
#include <fstream>
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
#include <openspace/scripting/script_helper.h>
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
#include <ghoul/lua/lua_helper.h>
|
||||
#include <modules/iswa/rendering/iswacygnet.h>
|
||||
#include <modules/iswa/rendering/iswagroup.h>
|
||||
|
||||
#include "iswamanager_lua.inl";
|
||||
|
||||
namespace {
|
||||
using json = nlohmann::json;
|
||||
const std::string _loggerCat = "ISWAManager";
|
||||
}
|
||||
|
||||
namespace openspace{
|
||||
ISWAManager::ISWAManager()
|
||||
{
|
||||
_month["JAN"] = "01";
|
||||
_month["FEB"] = "02";
|
||||
_month["MAR"] = "03";
|
||||
_month["APR"] = "04";
|
||||
_month["MAY"] = "05";
|
||||
_month["JUN"] = "06";
|
||||
_month["JUL"] = "07";
|
||||
_month["AUG"] = "08";
|
||||
_month["SEP"] = "09";
|
||||
_month["OCT"] = "10";
|
||||
_month["NOV"] = "11";
|
||||
_month["DEC"] = "12";
|
||||
|
||||
_type[CygnetType::Texture] = "Texture";
|
||||
_type[CygnetType::Data] = "Data";
|
||||
_type[CygnetType::Kameleon] = "Kameleon";
|
||||
ISWAManager::ISWAManager()
|
||||
{
|
||||
_month["JAN"] = "01";
|
||||
_month["FEB"] = "02";
|
||||
_month["MAR"] = "03";
|
||||
_month["APR"] = "04";
|
||||
_month["MAY"] = "05";
|
||||
_month["JUN"] = "06";
|
||||
_month["JUL"] = "07";
|
||||
_month["AUG"] = "08";
|
||||
_month["SEP"] = "09";
|
||||
_month["OCT"] = "10";
|
||||
_month["NOV"] = "11";
|
||||
_month["DEC"] = "12";
|
||||
|
||||
_geom[CygnetGeometry::Plane] = "Plane";
|
||||
_geom[CygnetGeometry::Sphere] = "Sphere";
|
||||
}
|
||||
_type[CygnetType::Texture] = "Texture";
|
||||
_type[CygnetType::Data] = "Data";
|
||||
_type[CygnetType::Kameleon] = "Kameleon";
|
||||
|
||||
ISWAManager::~ISWAManager(){}
|
||||
_geom[CygnetGeometry::Plane] = "Plane";
|
||||
_geom[CygnetGeometry::Sphere] = "Sphere";
|
||||
}
|
||||
|
||||
void ISWAManager::addISWACygnet(std::string info){
|
||||
std::string token;
|
||||
std::stringstream ss(info);
|
||||
ISWAManager::~ISWAManager(){}
|
||||
|
||||
void ISWAManager::addISWACygnet(std::string info){
|
||||
std::string token;
|
||||
std::stringstream ss(info);
|
||||
getline(ss,token,',');
|
||||
int cygnetId = std::stoi(token);
|
||||
|
||||
if(!ss.eof()){
|
||||
getline(ss,token,',');
|
||||
int cygnetId = std::stoi(token);
|
||||
std::string data = token;
|
||||
|
||||
if(!ss.eof()){
|
||||
getline(ss,token,',');
|
||||
std::string data = token;
|
||||
|
||||
if(!ss.eof()){
|
||||
getline(ss, token, ',');
|
||||
int group = std::stoi(token);
|
||||
addISWACygnet(cygnetId, data, group);
|
||||
return;
|
||||
}
|
||||
|
||||
addISWACygnet(cygnetId, data);
|
||||
getline(ss, token, ',');
|
||||
int group = std::stoi(token);
|
||||
addISWACygnet(cygnetId, data, group);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
addISWACygnet(cygnetId);
|
||||
addISWACygnet(cygnetId, data);
|
||||
return;
|
||||
}
|
||||
|
||||
addISWACygnet(cygnetId);
|
||||
|
||||
/*if(data == "")
|
||||
else*/
|
||||
|
||||
/*if(data == "")
|
||||
else*/
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void ISWAManager::addISWACygnet(int id, std::string info, int group){
|
||||
if(id > 0){
|
||||
createScreenSpace(id);
|
||||
}else if(id < 0){
|
||||
//download metadata to texture plane
|
||||
std::shared_ptr<MetadataFuture> metadataFuture = downloadMetadata(id);
|
||||
metadataFuture->guiType = info;
|
||||
metadataFuture->id = id;
|
||||
metadataFuture->group = group;
|
||||
_metadataFutures.push_back(metadataFuture);
|
||||
}else{
|
||||
//create kameleonplane
|
||||
createKameleonPlane(info);
|
||||
}
|
||||
}
|
||||
void ISWAManager::addISWACygnet(int id, std::string info, int group){
|
||||
if(id > 0){
|
||||
createScreenSpace(id);
|
||||
}else if(id < 0){
|
||||
//download metadata to texture plane
|
||||
std::shared_ptr<MetadataFuture> metadataFuture = downloadMetadata(id);
|
||||
metadataFuture->guiType = info;
|
||||
metadataFuture->id = id;
|
||||
metadataFuture->group = group;
|
||||
_metadataFutures.push_back(metadataFuture);
|
||||
}else{
|
||||
//create kameleonplane
|
||||
createKameleonPlane(info);
|
||||
}
|
||||
}
|
||||
|
||||
void ISWAManager::deleteISWACygnet(std::string name){
|
||||
OsEng.scriptEngine().queueScript("openspace.removeSceneGraphNode('" + name + "')");
|
||||
}
|
||||
void ISWAManager::deleteISWACygnet(std::string name){
|
||||
OsEng.scriptEngine().queueScript("openspace.removeSceneGraphNode('" + name + "')");
|
||||
}
|
||||
|
||||
// std::shared_ptr<DownloadManager::FileFuture> ISWAManager::downloadImage(int id, std::string path){
|
||||
// return DlManager.downloadFile(
|
||||
// iSWAurl(id),
|
||||
// path,
|
||||
// true,
|
||||
// [path](const DownloadManager::FileFuture& f){
|
||||
// LDEBUG("Download finished: " << path);
|
||||
// }
|
||||
// );
|
||||
// }
|
||||
// std::shared_ptr<DownloadManager::FileFuture> ISWAManager::downloadImage(int id, std::string path){
|
||||
// return DlManager.downloadFile(
|
||||
// iSWAurl(id),
|
||||
// path,
|
||||
// true,
|
||||
// [path](const DownloadManager::FileFuture& f){
|
||||
// LDEBUG("Download finished: " << path);
|
||||
// }
|
||||
// );
|
||||
// }
|
||||
|
||||
std::shared_ptr<DownloadManager::FileFuture> ISWAManager::downloadImageToMemory(int id, std::string& buffer){
|
||||
return DlManager.downloadToMemory(
|
||||
iSWAurl(id, "image"),
|
||||
buffer,
|
||||
[](const DownloadManager::FileFuture& f){
|
||||
LDEBUG("Download to memory finished");
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
std::shared_ptr<DownloadManager::FileFuture> ISWAManager::downloadDataToMemory(int id, std::string& buffer){
|
||||
return DlManager.downloadToMemory(
|
||||
iSWAurl(id, "data"),
|
||||
buffer,
|
||||
[](const DownloadManager::FileFuture& f){
|
||||
LDEBUG("Download data finished");
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void ISWAManager::update(){
|
||||
for (auto it = _metadataFutures.begin(); it != _metadataFutures.end(); ){
|
||||
if((*it)->isFinished) {
|
||||
if((*it)->guiType == "TEXTURE"){
|
||||
(*it)->type = CygnetType::Texture;
|
||||
(*it)->geom = CygnetGeometry::Plane;
|
||||
// (*it)->group = -1;
|
||||
}else if ((*it)->guiType == "DATA"){
|
||||
(*it)->type = CygnetType::Data;
|
||||
(*it)->geom = CygnetGeometry::Plane;
|
||||
// (*it)->group = 1;
|
||||
} else {
|
||||
LERROR("\""+ (*it)->guiType + "\" is not a valid type");
|
||||
return;
|
||||
}
|
||||
createPlane((*it));
|
||||
it = _metadataFutures.erase( it );
|
||||
}else{
|
||||
++it;
|
||||
std::shared_ptr<DownloadManager::FileFuture> ISWAManager::downloadImageToMemory(int id, std::string& buffer){
|
||||
return DlManager.downloadToMemory(
|
||||
iSWAurl(id, "image"),
|
||||
buffer,
|
||||
[](const DownloadManager::FileFuture& f){
|
||||
LDEBUG("Download to memory finished");
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
std::shared_ptr<DownloadManager::FileFuture> ISWAManager::downloadDataToMemory(int id, std::string& buffer){
|
||||
return DlManager.downloadToMemory(
|
||||
iSWAurl(id, "data"),
|
||||
buffer,
|
||||
[](const DownloadManager::FileFuture& f){
|
||||
LDEBUG("Download data finished");
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void ISWAManager::update(){
|
||||
for (auto it = _metadataFutures.begin(); it != _metadataFutures.end(); ){
|
||||
if((*it)->isFinished) {
|
||||
if((*it)->guiType == "TEXTURE"){
|
||||
(*it)->type = CygnetType::Texture;
|
||||
(*it)->geom = CygnetGeometry::Plane;
|
||||
// (*it)->group = -1;
|
||||
}else if ((*it)->guiType == "DATA"){
|
||||
(*it)->type = CygnetType::Data;
|
||||
(*it)->geom = CygnetGeometry::Plane;
|
||||
// (*it)->group = 1;
|
||||
} else {
|
||||
LERROR("\""+ (*it)->guiType + "\" is not a valid type");
|
||||
return;
|
||||
}
|
||||
createPlane((*it));
|
||||
it = _metadataFutures.erase( it );
|
||||
}else{
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string ISWAManager::iSWAurl(int id, std::string type){
|
||||
std::string url;
|
||||
if(id < 0){
|
||||
url = "http://128.183.168.116:3000/"+type+"/" + std::to_string(-id) + "/";
|
||||
// url = "http://10.0.0.76:3000/"+type+"/" + std::to_string(-id) + "/";
|
||||
} else{
|
||||
url = "http://iswa2.ccmc.gsfc.nasa.gov/IswaSystemWebApp/iSWACygnetStreamer?window=-1&cygnetId="+ std::to_string(id) +"×tamp=";
|
||||
}
|
||||
|
||||
std::string t = Time::ref().currentTimeUTC();
|
||||
std::stringstream ss(t);
|
||||
std::string token;
|
||||
|
||||
std::getline(ss, token, ' ');
|
||||
url += token + "-";
|
||||
std::getline(ss, token, ' ');
|
||||
url += _month[token] + "-";
|
||||
std::getline(ss, token, 'T');
|
||||
url += token + "%20";
|
||||
std::getline(ss, token, '.');
|
||||
url += token;
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
std::shared_ptr<MetadataFuture> ISWAManager::downloadMetadata(int id){
|
||||
std::shared_ptr<MetadataFuture> metaFuture = std::make_shared<MetadataFuture>();
|
||||
|
||||
metaFuture->id = id;
|
||||
DlManager.downloadToMemory(
|
||||
"http://128.183.168.116:3000/" + std::to_string(-id),
|
||||
// "http://10.0.0.76:3000/" + std::to_string(-id),
|
||||
metaFuture->json,
|
||||
[metaFuture](const DownloadManager::FileFuture& f){
|
||||
LDEBUG("Download to memory finished");
|
||||
metaFuture->isFinished = true;
|
||||
}
|
||||
);
|
||||
return metaFuture;
|
||||
}
|
||||
|
||||
void ISWAManager::createScreenSpace(int id){
|
||||
OsEng.renderEngine().registerScreenSpaceRenderable(std::make_shared<ScreenSpaceCygnet>(id));
|
||||
}
|
||||
|
||||
void ISWAManager::createPlane(std::shared_ptr<MetadataFuture> data){
|
||||
// check if this plane already exist
|
||||
std::string name = _type[data->type] + _geom[data->geom] + std::to_string(data->id);
|
||||
if(data->group > 0)
|
||||
name += "_Group" + std::to_string(data->group);
|
||||
|
||||
data->name = name;
|
||||
|
||||
if( OsEng.renderEngine().scene()->sceneGraphNode(name) ){
|
||||
LERROR("A node with name \"" + name +"\" already exist");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string ISWAManager::iSWAurl(int id, std::string type){
|
||||
std::string url;
|
||||
if(id < 0){
|
||||
url = "http://128.183.168.116:3000/"+type+"/" + std::to_string(-id) + "/";
|
||||
// url = "http://10.0.0.76:3000/"+type+"/" + std::to_string(-id) + "/";
|
||||
} else{
|
||||
url = "http://iswa2.ccmc.gsfc.nasa.gov/IswaSystemWebApp/iSWACygnetStreamer?window=-1&cygnetId="+ std::to_string(id) +"×tamp=";
|
||||
}
|
||||
|
||||
std::string t = Time::ref().currentTimeUTC();
|
||||
std::stringstream ss(t);
|
||||
std::string token;
|
||||
|
||||
std::getline(ss, token, ' ');
|
||||
url += token + "-";
|
||||
std::getline(ss, token, ' ');
|
||||
url += _month[token] + "-";
|
||||
std::getline(ss, token, 'T');
|
||||
url += token + "%20";
|
||||
std::getline(ss, token, '.');
|
||||
url += token;
|
||||
|
||||
return url;
|
||||
std::string luaTable = parseJSONToLuaTable(data);
|
||||
if(luaTable != ""){
|
||||
std::string script = "openspace.addSceneGraphNode(" + luaTable + ");";
|
||||
OsEng.scriptEngine().queueScript(script);
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<MetadataFuture> ISWAManager::downloadMetadata(int id){
|
||||
std::shared_ptr<MetadataFuture> metaFuture = std::make_shared<MetadataFuture>();
|
||||
std::string ISWAManager::parseJSONToLuaTable(std::shared_ptr<MetadataFuture> data){
|
||||
if(data->json != ""){
|
||||
json j = json::parse(data->json);
|
||||
|
||||
metaFuture->id = id;
|
||||
DlManager.downloadToMemory(
|
||||
"http://128.183.168.116:3000/" + std::to_string(-id),
|
||||
// "http://10.0.0.76:3000/" + std::to_string(-id),
|
||||
metaFuture->json,
|
||||
[metaFuture](const DownloadManager::FileFuture& f){
|
||||
LDEBUG("Download to memory finished");
|
||||
metaFuture->isFinished = true;
|
||||
}
|
||||
);
|
||||
return metaFuture;
|
||||
}
|
||||
std::string parent = j["Central Body"];
|
||||
std::string frame = j["Coordinates"];
|
||||
std::string coordinateType = j["Coordinate Type"];
|
||||
int updateTime = j["ISWA_UPDATE_SECONDS"];
|
||||
|
||||
void ISWAManager::createScreenSpace(int id){
|
||||
OsEng.renderEngine().registerScreenSpaceRenderable(std::make_shared<ScreenSpaceCygnet>(id));
|
||||
}
|
||||
glm::vec3 max(
|
||||
j["Plot XMAX"],
|
||||
j["Plot YMAX"],
|
||||
j["Plot ZMAX"]
|
||||
);
|
||||
|
||||
void ISWAManager::createPlane(std::shared_ptr<MetadataFuture> data){
|
||||
// check if this plane already exist
|
||||
std::string name = _type[data->type] + _geom[data->geom] + std::to_string(data->id);
|
||||
if(data->group > 0)
|
||||
name += "_Group" + std::to_string(data->group);
|
||||
glm::vec3 min(
|
||||
j["Plot XMIN"],
|
||||
j["Plot YMIN"],
|
||||
j["Plot ZMIN"]
|
||||
);
|
||||
|
||||
data->name = name;
|
||||
|
||||
if( OsEng.renderEngine().scene()->sceneGraphNode(name) ){
|
||||
LERROR("A node with name \"" + name +"\" already exist");
|
||||
return;
|
||||
glm::vec4 spatialScale(1, 1, 1, 10);
|
||||
std::string spatial = j["Spatial Scale (Custom)"];
|
||||
if(spatial == "R_E"){
|
||||
spatialScale.x = 6.371f;
|
||||
spatialScale.y = 6.371f;
|
||||
spatialScale.z = 6.371f;
|
||||
spatialScale.w = 6;
|
||||
}
|
||||
|
||||
std::string luaTable = parseJSONToLuaTable(data);
|
||||
if(luaTable != ""){
|
||||
|
||||
std::string table = "{"
|
||||
"Name = '" + data->name +"' , "
|
||||
"Parent = '" + parent + "', "
|
||||
"Renderable = {"
|
||||
"Type = '" + _type[data->type] + _geom[data->geom] + "', "
|
||||
"Id = " + std::to_string(data->id) + ", "
|
||||
"Frame = '" + frame + "' , "
|
||||
"GridMin = " + std::to_string(min) + ", "
|
||||
"GridMax = " + std::to_string(max) + ", "
|
||||
"SpatialScale = " + std::to_string(spatialScale) + ", "
|
||||
"UpdateTime = " + std::to_string(updateTime) + ", "
|
||||
"CoordinateType = '" + coordinateType + "', "
|
||||
"Group = "+ std::to_string(data->group) + " ,"
|
||||
"}"
|
||||
"}";
|
||||
|
||||
return table;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
void ISWAManager::createKameleonPlane(std::string kwPath, int group){
|
||||
kwPath = "${OPENSPACE_DATA}/" + kwPath;
|
||||
const std::string& extension = ghoul::filesystem::File(absPath(kwPath)).fileExtension();
|
||||
|
||||
if(FileSys.fileExists(absPath(kwPath)) && extension == "cdf"){
|
||||
std::string luaTable = parseKWToLuaTable(kwPath, group);
|
||||
if(!luaTable.empty()){
|
||||
std::cout << luaTable << std::endl;
|
||||
std::string script = "openspace.addSceneGraphNode(" + luaTable + ");";
|
||||
OsEng.scriptEngine().queueScript(script);
|
||||
}
|
||||
}else{
|
||||
LWARNING( kwPath + " is not a cdf file or can't be found.");
|
||||
}
|
||||
}
|
||||
|
||||
std::string ISWAManager::parseJSONToLuaTable(std::shared_ptr<MetadataFuture> data){
|
||||
if(data->json != ""){
|
||||
json j = json::parse(data->json);
|
||||
std::string ISWAManager::parseKWToLuaTable(std::string kwPath, int group){
|
||||
if(kwPath != ""){
|
||||
const std::string& extension = ghoul::filesystem::File(absPath(kwPath)).fileExtension();
|
||||
if(extension == "cdf"){
|
||||
KameleonWrapper kw = KameleonWrapper(absPath(kwPath));
|
||||
|
||||
std::string parent = kw.getParent();
|
||||
std::string frame = kw.getFrame();
|
||||
glm::vec3 min = kw.getGridMin();
|
||||
glm::vec3 max = kw.getGridMax();
|
||||
|
||||
std::string parent = j["Central Body"];
|
||||
std::string frame = j["Coordinates"];
|
||||
std::string coordinateType = j["Coordinate Type"];
|
||||
int updateTime = j["ISWA_UPDATE_SECONDS"];
|
||||
glm::vec4 spatialScale;
|
||||
std::string coordinateType;
|
||||
|
||||
glm::vec3 max(
|
||||
j["Plot XMAX"],
|
||||
j["Plot YMAX"],
|
||||
j["Plot ZMAX"]
|
||||
);
|
||||
|
||||
glm::vec3 min(
|
||||
j["Plot XMIN"],
|
||||
j["Plot YMIN"],
|
||||
j["Plot ZMIN"]
|
||||
);
|
||||
|
||||
glm::vec4 spatialScale(1, 1, 1, 10);
|
||||
std::string spatial = j["Spatial Scale (Custom)"];
|
||||
if(spatial == "R_E"){
|
||||
std::tuple < std::string, std::string, std::string > gridUnits = kw.getGridUnits();
|
||||
if (std::get<0>(gridUnits) == "R" && std::get<1>(gridUnits) == "R" && std::get<2>(gridUnits) == "R") {
|
||||
spatialScale.x = 6.371f;
|
||||
spatialScale.y = 6.371f;
|
||||
spatialScale.z = 6.371f;
|
||||
spatialScale.w = 6;
|
||||
|
||||
coordinateType = "Cartesian";
|
||||
}else{
|
||||
spatialScale = glm::vec4(1.0);
|
||||
spatialScale.w = 1; //-log10(1.0f/max.x);
|
||||
|
||||
coordinateType = "Polar";
|
||||
}
|
||||
|
||||
|
||||
std::string table = "{"
|
||||
"Name = '" + data->name +"' , "
|
||||
"Parent = '" + parent + "', "
|
||||
"Renderable = {"
|
||||
"Type = '" + _type[data->type] + _geom[data->geom] + "', "
|
||||
"Id = " + std::to_string(data->id) + ", "
|
||||
"Frame = '" + frame + "' , "
|
||||
"GridMin = " + std::to_string(min) + ", "
|
||||
"GridMax = " + std::to_string(max) + ", "
|
||||
"SpatialScale = " + std::to_string(spatialScale) + ", "
|
||||
"UpdateTime = " + std::to_string(updateTime) + ", "
|
||||
"CoordinateType = '" + coordinateType + "', "
|
||||
"Group = "+ std::to_string(data->group) + " ,"
|
||||
"Name = 'KameleonPlane0',"
|
||||
// "Parent = 'Earth', "
|
||||
"Parent = '" + parent + "', "
|
||||
"Renderable = {"
|
||||
"Type = 'KameleonPlane', "
|
||||
"Id = 0 ,"
|
||||
"Frame = '" + frame + "' , "
|
||||
"GridMin = " + std::to_string(min) + ", "
|
||||
"GridMax = " + std::to_string(max) + ", "
|
||||
"SpatialScale = " + std::to_string(spatialScale) + ", "
|
||||
"UpdateTime = 0, "
|
||||
"kwPath = '" + kwPath + "' ,"
|
||||
"axisCut = 'y' ,"
|
||||
"CoordinateType = '" + coordinateType + "', "
|
||||
"Group = "+ std::to_string(group) + " ,"
|
||||
"}"
|
||||
"}"
|
||||
"}";
|
||||
|
||||
;
|
||||
// std::cout << table << std::endl;
|
||||
return table;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
void ISWAManager::registerToGroup(int id, ISWACygnet* cygnet, CygnetType type){
|
||||
if(_groups.find(id) != _groups.end()){
|
||||
_groups[id]->registerCygnet(cygnet, type);
|
||||
}else{
|
||||
_groups.insert(std::pair<int, std::shared_ptr<ISWAGroup>>(id, std::make_shared<ISWAGroup>(id, type)));
|
||||
_groups[id]->registerCygnet(cygnet, type);
|
||||
}
|
||||
|
||||
void ISWAManager::createKameleonPlane(std::string kwPath, int group){
|
||||
kwPath = "${OPENSPACE_DATA}/" + kwPath;
|
||||
const std::string& extension = ghoul::filesystem::File(absPath(kwPath)).fileExtension();
|
||||
}
|
||||
|
||||
if(FileSys.fileExists(absPath(kwPath)) && extension == "cdf"){
|
||||
std::string luaTable = parseKWToLuaTable(kwPath, group);
|
||||
if(!luaTable.empty()){
|
||||
std::cout << luaTable << std::endl;
|
||||
std::string script = "openspace.addSceneGraphNode(" + luaTable + ");";
|
||||
OsEng.scriptEngine().queueScript(script);
|
||||
}
|
||||
}else{
|
||||
LWARNING( kwPath + " is not a cdf file or can't be found.");
|
||||
void ISWAManager::unregisterFromGroup(int id, ISWACygnet* cygnet){
|
||||
if(_groups.find(id) != _groups.end()){
|
||||
_groups[id]->unregisterCygnet(cygnet);
|
||||
}
|
||||
}
|
||||
|
||||
void ISWAManager::registerOptionsToGroup(int id, const std::vector<properties::SelectionProperty::Option>& options){
|
||||
if(_groups.find(id) != _groups.end()){
|
||||
_groups[id]->registerOptions(options);
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<ISWAGroup> ISWAManager::iSWAGroup(std::string name){
|
||||
for(auto group : _groups){
|
||||
if(group.second->name() == name){
|
||||
return group.second;
|
||||
}
|
||||
}
|
||||
|
||||
std::string ISWAManager::parseKWToLuaTable(std::string kwPath, int group){
|
||||
if(kwPath != ""){
|
||||
const std::string& extension = ghoul::filesystem::File(absPath(kwPath)).fileExtension();
|
||||
if(extension == "cdf"){
|
||||
KameleonWrapper kw = KameleonWrapper(absPath(kwPath));
|
||||
|
||||
std::string parent = kw.getParent();
|
||||
std::string frame = kw.getFrame();
|
||||
glm::vec3 min = kw.getGridMin();
|
||||
glm::vec3 max = kw.getGridMax();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
glm::vec4 spatialScale;
|
||||
std::string coordinateType;
|
||||
|
||||
std::tuple < std::string, std::string, std::string > gridUnits = kw.getGridUnits();
|
||||
if (std::get<0>(gridUnits) == "R" && std::get<1>(gridUnits) == "R" && std::get<2>(gridUnits) == "R") {
|
||||
spatialScale.x = 6.371f;
|
||||
spatialScale.y = 6.371f;
|
||||
spatialScale.z = 6.371f;
|
||||
spatialScale.w = 6;
|
||||
|
||||
coordinateType = "Cartesian";
|
||||
}else{
|
||||
spatialScale = glm::vec4(1.0);
|
||||
spatialScale.w = 1; //-log10(1.0f/max.x);
|
||||
|
||||
coordinateType = "Polar";
|
||||
}
|
||||
std::string table = "{"
|
||||
"Name = 'KameleonPlane0',"
|
||||
// "Parent = 'Earth', "
|
||||
"Parent = '" + parent + "', "
|
||||
"Renderable = {"
|
||||
"Type = 'KameleonPlane', "
|
||||
"Id = 0 ,"
|
||||
"Frame = '" + frame + "' , "
|
||||
"GridMin = " + std::to_string(min) + ", "
|
||||
"GridMax = " + std::to_string(max) + ", "
|
||||
"SpatialScale = " + std::to_string(spatialScale) + ", "
|
||||
"UpdateTime = 0, "
|
||||
"kwPath = '" + kwPath + "' ,"
|
||||
"axisCut = 'y' ,"
|
||||
"CoordinateType = '" + coordinateType + "', "
|
||||
"Group = "+ std::to_string(group) + " ,"
|
||||
"}"
|
||||
"}"
|
||||
;
|
||||
// std::cout << table << std::endl;
|
||||
return table;
|
||||
scripting::ScriptEngine::LuaLibrary ISWAManager::luaLibrary() {
|
||||
return {
|
||||
"iswa",
|
||||
{
|
||||
{
|
||||
"addCygnet",
|
||||
&luascriptfunctions::iswa_addCygnet,
|
||||
"string",
|
||||
"Sets a property identified by the URI in "
|
||||
"the first argument. The second argument can be any type, but it has to "
|
||||
" agree with the type that the property expects",
|
||||
true
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
void ISWAManager::registerToGroup(int id, ISWACygnet* cygnet, CygnetType type){
|
||||
if(_groups.find(id) != _groups.end()){
|
||||
_groups[id]->registerCygnet(cygnet, type);
|
||||
}else{
|
||||
_groups.insert(std::pair<int, std::shared_ptr<ISWAGroup>>(id, std::make_shared<ISWAGroup>(id, type)));
|
||||
_groups[id]->registerCygnet(cygnet, type);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ISWAManager::unregisterFromGroup(int id, ISWACygnet* cygnet){
|
||||
if(_groups.find(id) != _groups.end()){
|
||||
_groups[id]->unregisterCygnet(cygnet);
|
||||
}
|
||||
}
|
||||
|
||||
void ISWAManager::registerOptionsToGroup(int id, const std::vector<properties::SelectionProperty::Option>& options){
|
||||
if(_groups.find(id) != _groups.end()){
|
||||
_groups[id]->registerOptions(options);
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<ISWAGroup> ISWAManager::iSWAGroup(std::string name){
|
||||
for(auto group : _groups){
|
||||
if(group.second->name() == name){
|
||||
return group.second;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}// namsepace openspace
|
||||
@@ -32,6 +32,8 @@
|
||||
#include <modules/kameleon/include/kameleonwrapper.h>
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <openspace/properties/selectionproperty.h>
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
|
||||
// #include <modules/iswa/rendering/iswacygnet.h>
|
||||
// #include <modules/iswa/rendering/iswagroup.h>
|
||||
|
||||
@@ -78,6 +80,8 @@ public:
|
||||
void registerOptionsToGroup(int id, const std::vector<properties::SelectionProperty::Option>& options);
|
||||
std::shared_ptr<ISWAGroup> iSWAGroup(std::string name);
|
||||
|
||||
static scripting::ScriptEngine::LuaLibrary luaLibrary();
|
||||
|
||||
private:
|
||||
std::string iSWAurl(int id, std::string type = "image");
|
||||
std::shared_ptr<MetadataFuture> downloadMetadata(int id);
|
||||
|
||||
39
modules/iswa/util/iswamanager_lua.inl
Normal file
39
modules/iswa/util/iswamanager_lua.inl
Normal file
@@ -0,0 +1,39 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
namespace openspace {
|
||||
|
||||
namespace luascriptfunctions {
|
||||
|
||||
int iswa_addCygnet(lua_State* L) {
|
||||
std::string s = luaL_checkstring(L, -1);
|
||||
// LERROR("String" << s);
|
||||
// std::cout << "String is: " << s << std::endl;
|
||||
ISWAManager::ref().addISWACygnet(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
}// namespace luascriptfunctions
|
||||
|
||||
}// namespace openspace
|
||||
@@ -437,7 +437,7 @@ void GUI::renderMainWindow() {
|
||||
ImGui::InputText("addCynget", addCygnetBuffer, addCygnetBufferSize);
|
||||
|
||||
if(ImGui::SmallButton("Add Cygnet")){
|
||||
ISWAManager::ref().addISWACygnet(std::string(addCygnetBuffer));
|
||||
OsEng.scriptEngine().queueScript("openspace.iswa.addCygnet('"+std::string(addCygnetBuffer)+"');");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -37,7 +37,8 @@ return {
|
||||
Light = "${FONTS}/Roboto/Roboto-Regular.ttf"
|
||||
},
|
||||
StartupScripts = {
|
||||
"${SCRIPTS}/default_startup.lua"
|
||||
"${SCRIPTS}/default_startup.lua",
|
||||
"${SCRIPTS}/iswa_startup.lua"
|
||||
},
|
||||
SettingsScripts = {
|
||||
"${SCRIPTS}/default_settings.lua"
|
||||
|
||||
6
scripts/iswa_startup.lua
Normal file
6
scripts/iswa_startup.lua
Normal file
@@ -0,0 +1,6 @@
|
||||
--[[ OpenSpace startup script ]]--
|
||||
-- This Lua script get executed once at the start of the application
|
||||
|
||||
openspace.iswa.addCygnet("-1,DATA,1");
|
||||
openspace.iswa.addCygnet("-2,DATA,1");
|
||||
openspace.iswa.addCygnet("-3,DATA,1");
|
||||
@@ -66,6 +66,10 @@
|
||||
#include <modules/onscreengui/include/gui.h>
|
||||
#endif
|
||||
|
||||
#ifdef OPENSPACE_MODULE_ISWA_ENABLED
|
||||
#include <modules/iswa/util/iswamanager.h>
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#ifdef OPENSPACE_ENABLE_VLD
|
||||
#include <vld.h>
|
||||
@@ -134,6 +138,10 @@ OpenSpaceEngine::OpenSpaceEngine(std::string programName,
|
||||
SpiceManager::initialize();
|
||||
Time::initialize();
|
||||
ghoul::systemcapabilities::SystemCapabilities::initialize();
|
||||
#ifdef OPENSPACE_MODULE_ISWA_ENABLED
|
||||
ISWAManager::initialize();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
OpenSpaceEngine::~OpenSpaceEngine() {
|
||||
@@ -355,6 +363,10 @@ bool OpenSpaceEngine::initialize() {
|
||||
_scriptEngine->addLibrary(gui::GUI::luaLibrary());
|
||||
_scriptEngine->addLibrary(network::ParallelConnection::luaLibrary());
|
||||
|
||||
#ifdef OPENSPACE_MODULE_ISWA_ENABLED
|
||||
_scriptEngine->addLibrary(ISWAManager::luaLibrary());
|
||||
#endif
|
||||
|
||||
// TODO: Maybe move all scenegraph and renderengine stuff to initializeGL
|
||||
scriptEngine().initialize();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user