mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-17 18:39:17 -06:00
Add KameleonPlanes again
This commit is contained in:
@@ -30,7 +30,8 @@ function postInitialization()
|
||||
|
||||
openspace.printInfo("Done setting default values")
|
||||
|
||||
openspace.iswa.addCygnet(-4,"Data");
|
||||
openspace.iswa.addCygnet(0);
|
||||
--openspace.iswa.addCygnet(-4,"Data");
|
||||
--openspace.iswa.addCygnet(-1,"Data","GM");
|
||||
--openspace.iswa.addCygnet(-2,"Data","GM");
|
||||
--openspace.iswa.addCygnet(-3,"Data","GM");
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace openspace {
|
||||
|
||||
fRenderable->registerClass<TexturePlane>("TexturePlane");
|
||||
fRenderable->registerClass<DataPlane>("DataPlane");
|
||||
// fRenderable->registerClass<KameleonPlane>("KameleonPlane");
|
||||
fRenderable->registerClass<KameleonPlane>("KameleonPlane");
|
||||
fRenderable->registerClass<DataSphere>("DataSphere");
|
||||
|
||||
auto fScreenSpaceRenderable = FactoryManager::ref().factory<ScreenSpaceRenderable>();
|
||||
|
||||
@@ -116,7 +116,7 @@ void DataPlane::transferFunctionsFile(std::string tfPath){ _transferFunctionsFil
|
||||
void DataPlane::backgroundValues(glm::vec2 backgroundValues){ _backgroundValues.setValue(backgroundValues); };
|
||||
|
||||
bool DataPlane::loadTexture() {
|
||||
|
||||
|
||||
// if The future is done then get the new dataFile
|
||||
if(_futureObject.valid() && DownloadManager::futureReady(_futureObject)){
|
||||
DownloadManager::MemoryFile dataFile = _futureObject.get();
|
||||
@@ -294,7 +294,6 @@ void DataPlane::setTransferFunctions(std::string tfPath){
|
||||
_transferFunctions.clear();
|
||||
_transferFunctions = tfs;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}// namespace openspace
|
||||
@@ -36,11 +36,7 @@ IswaCygnet::IswaCygnet(const ghoul::Dictionary& dictionary)
|
||||
: Renderable(dictionary)
|
||||
, _delete("delete", "Delete")
|
||||
, _shader(nullptr)
|
||||
// , _texture(nullptr)
|
||||
//, _memorybuffer("")
|
||||
,_type(IswaManager::CygnetType::NoType)
|
||||
//,_futureObject(nullptr)
|
||||
// ,_transferFunction(nullptr)
|
||||
{
|
||||
_data = std::make_shared<Metadata>();
|
||||
|
||||
@@ -114,7 +110,6 @@ bool IswaCygnet::initialize(){
|
||||
if(!_data->groupName.empty())
|
||||
IswaManager::ref().registerToGroup(_data->groupName, _type, this);
|
||||
|
||||
// return isReady();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -125,7 +120,6 @@ bool IswaCygnet::deinitialize(){
|
||||
unregisterProperties();
|
||||
destroyGeometry();
|
||||
destroyShader();
|
||||
//_memorybuffer = "";
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -173,14 +167,11 @@ void IswaCygnet::render(const RenderData& data){
|
||||
void IswaCygnet::update(const UpdateData& data){
|
||||
_openSpaceTime = Time::ref().currentTime();
|
||||
_realTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch());
|
||||
|
||||
|
||||
_stateMatrix = TransformationManager::ref().frameTransformationMatrix(_data->frame, "GALACTIC", _openSpaceTime);
|
||||
// glm::dmat3 spiceMatrix = SpiceManager::ref().positionTransformMatrix("J2000", "GALACTIC", _openSpaceTime);
|
||||
// = spiceMatrix*kameleonMatrix;
|
||||
|
||||
bool timeToUpdate = (fabs(_openSpaceTime-_lastUpdateOpenSpaceTime) >= _data->updateTime &&
|
||||
(_realTime.count()-_lastUpdateRealTime.count()) > _minRealTimeUpdateInterval);
|
||||
|
||||
if( _data->updateTime != 0 && (Time::ref().timeJumped() || timeToUpdate )){
|
||||
updateTexture();
|
||||
|
||||
|
||||
@@ -39,56 +39,50 @@
|
||||
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "KameleonPlane";
|
||||
const std::string _loggerCat = "KameleonPlane";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
KameleonPlane::KameleonPlane(const ghoul::Dictionary& dictionary)
|
||||
:CygnetPlane(dictionary)
|
||||
,_backgroundValues("backgroundValues", "Background Values", glm::vec2(0.0), glm::vec2(0), glm::vec2(1.0))
|
||||
:CygnetPlane(dictionary)
|
||||
,_backgroundValues("backgroundValues", "Background Values", glm::vec2(0.0), glm::vec2(0), glm::vec2(1.0))
|
||||
,_transferFunctionsFile("transferfunctions", "Transfer Functions", "${SCENE}/iswa/tfs/hot.tf")
|
||||
{
|
||||
std::string name;
|
||||
{
|
||||
std::string name;
|
||||
dictionary.getValue("Name", name);
|
||||
setName(name);
|
||||
|
||||
registerProperties();
|
||||
registerProperties();
|
||||
|
||||
addProperty(_backgroundValues);
|
||||
addProperty(_transferFunctionsFile);
|
||||
|
||||
dictionary.getValue("kwPath", _kwPath);
|
||||
setTransferFunctions(_transferFunctionsFile.value());
|
||||
|
||||
std::string axis;
|
||||
dictionary.getValue("axisCut", axis);
|
||||
dictionary.getValue("kwPath", _kwPath);
|
||||
|
||||
if(axis == "x"){
|
||||
_data->scale.x = 0;
|
||||
}else if(axis == "y"){
|
||||
_data->scale.y = 0;
|
||||
}else{
|
||||
_data->scale.z = 0;
|
||||
}
|
||||
_kw = std::make_shared<KameleonWrapper>(absPath(_kwPath));
|
||||
KameleonWrapper::Model model = _kw->model();
|
||||
if( model == KameleonWrapper::Model::BATSRUS)
|
||||
_var = "p";
|
||||
else
|
||||
_var = "rho";
|
||||
std::string axis;
|
||||
dictionary.getValue("axisCut", axis);
|
||||
|
||||
_dimensions = glm::size3_t(500,500,1);
|
||||
float zSlice = 0.5f;
|
||||
_dataSlice = _kw->getUniformSliceValues(std::string(_var), _dimensions, zSlice);
|
||||
if(axis == "x"){
|
||||
_data->scale.x = 0;
|
||||
}else if(axis == "y"){
|
||||
_data->scale.y = 0;
|
||||
}else{
|
||||
_data->scale.z = 0;
|
||||
}
|
||||
}
|
||||
|
||||
KameleonPlane::~KameleonPlane(){}
|
||||
|
||||
|
||||
// bool KameleonPlane::initialize(){
|
||||
// _textures.push_back(nullptr);
|
||||
// _textures.push_back(nullptr);
|
||||
|
||||
// std::cout << "initialize kameleonplane" << std::endl;
|
||||
// // std::string kwPath;
|
||||
// // dictionary.getValue("KW", _kw);
|
||||
// std::cout << "initialize kameleonplane" << std::endl;
|
||||
// // std::string kwPath;
|
||||
// // dictionary.getValue("KW", _kw);
|
||||
|
||||
// createPlane();
|
||||
|
||||
@@ -114,44 +108,58 @@ KameleonPlane::~KameleonPlane(){}
|
||||
// unregisterProperties();
|
||||
// destroyPlane();
|
||||
// destroyShader();
|
||||
|
||||
// _kw = nullptr;
|
||||
// _memorybuffer = "";
|
||||
|
||||
// return true;
|
||||
|
||||
// _kw = nullptr;
|
||||
// _memorybuffer = "";
|
||||
|
||||
// return true;
|
||||
// }
|
||||
|
||||
|
||||
bool KameleonPlane::loadTexture() {
|
||||
std::cout << "load kameleonplane texture" << std::endl;
|
||||
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);
|
||||
std::cout << "load kameleonplane texture" << std::endl;
|
||||
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)
|
||||
return false;
|
||||
// LDEBUG("Loaded texture from '" << absPath(_path) << "'");
|
||||
if (!texture){
|
||||
std::cout << "Could not create texture" << std::endl;
|
||||
return false;
|
||||
}
|
||||
// LDEBUG("Loaded texture from '" << absPath(_path) << "'");
|
||||
|
||||
texture->uploadTexture();
|
||||
texture->uploadTexture();
|
||||
|
||||
// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
|
||||
texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
|
||||
// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
|
||||
texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
|
||||
|
||||
_textures[0] = std::move(texture);
|
||||
|
||||
return true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool KameleonPlane::updateTexture(){
|
||||
if(!_textures[0]){
|
||||
loadTexture();
|
||||
}
|
||||
return true;
|
||||
if(!_textures[0]){
|
||||
|
||||
_kw = std::make_shared<KameleonWrapper>(absPath(_kwPath));
|
||||
KameleonWrapper::Model model = _kw->model();
|
||||
if( model == KameleonWrapper::Model::BATSRUS)
|
||||
_var = "p";
|
||||
else
|
||||
_var = "rho";
|
||||
|
||||
_dimensions = glm::size3_t(500,500,1);
|
||||
float zSlice = 0.5f;
|
||||
_dataSlice = _kw->getUniformSliceValues(std::string(_var), _dimensions, zSlice);
|
||||
|
||||
loadTexture();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool KameleonPlane::readyToRender(){
|
||||
return (_textures[0] != nullptr);
|
||||
return (_textures[0] != nullptr && !_transferFunctions.empty());
|
||||
}
|
||||
|
||||
void KameleonPlane::setUniformAndTextures(){
|
||||
@@ -166,7 +174,7 @@ void KameleonPlane::setUniformAndTextures(){
|
||||
tfUnits[0].activate();
|
||||
_transferFunctions[0]->bind();
|
||||
_shader->setUniform(
|
||||
"transferFunctions[0]",
|
||||
"transferFunctions[0]",
|
||||
tfUnits[0]
|
||||
);
|
||||
|
||||
|
||||
@@ -143,7 +143,13 @@ void IswaManager::addIswaCygnet(int id, std::string type, std::string group){
|
||||
);
|
||||
}else{
|
||||
// Kameleonplane?
|
||||
LERROR("No cygnet with id 0");
|
||||
// LERROR("No cygnet with id 0");
|
||||
std::string kwPath = "BATSRUS.cdf";
|
||||
if(type == "x" || type == "y" || type == "z")
|
||||
createKameleonPlane(kwPath, type, group);
|
||||
else
|
||||
createKameleonPlane(kwPath, "z", group);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -309,6 +315,61 @@ std::string IswaManager::jsonPlaneToLuaTable(std::shared_ptr<MetadataFuture> dat
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string IswaManager::parseKWToLuaTable(std::string kwPath, std::string cut, std::string 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();
|
||||
|
||||
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::cout << cut << std::endl;
|
||||
|
||||
std::string table = "{"
|
||||
"Name = 'KameleonPlane',"
|
||||
"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 = '"+cut+"',"
|
||||
"CoordinateType = '" + coordinateType + "', "
|
||||
"Group = '"+ group + "',"
|
||||
"}"
|
||||
"}"
|
||||
;
|
||||
// std::cout << table << std::endl;
|
||||
return table;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string IswaManager::jsonSphereToLuaTable(std::shared_ptr<MetadataFuture> data){
|
||||
if(data->json == ""){
|
||||
LWARNING("jsonSphereToLuaTable: no content in metadata json");
|
||||
@@ -410,6 +471,22 @@ void IswaManager::createSphere(std::shared_ptr<MetadataFuture> data){
|
||||
}
|
||||
}
|
||||
|
||||
void IswaManager::createKameleonPlane(std::string kwPath, std::string cut, std::string 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, cut, 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::fillCygnetInfo(std::string jsonString){
|
||||
if(jsonString != ""){
|
||||
json j = json::parse(jsonString);
|
||||
|
||||
@@ -96,10 +96,12 @@ private:
|
||||
std::shared_ptr<MetadataFuture> downloadMetadata(int id);
|
||||
std::string jsonPlaneToLuaTable(std::shared_ptr<MetadataFuture> data);
|
||||
std::string jsonSphereToLuaTable(std::shared_ptr<MetadataFuture> data);
|
||||
std::string parseKWToLuaTable(std::string kwPath, std::string cut="z", std::string group="");
|
||||
|
||||
void createScreenSpace(int id);
|
||||
void createPlane(std::shared_ptr<MetadataFuture> data);
|
||||
void createSphere(std::shared_ptr<MetadataFuture> data);
|
||||
void createKameleonPlane(std::string kwPath, std::string cut="z", std::string group="");
|
||||
|
||||
void fillCygnetInfo(std::string jsonString);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user