some fbo testing

This commit is contained in:
Sovanny Huy
2019-05-13 16:54:10 -04:00
parent 8351ec2108
commit bf7575856b
14 changed files with 495 additions and 8 deletions
+40
View File
@@ -0,0 +1,40 @@
local assetHelper = asset.require("util/asset_helper")
local sunTransforms = asset.require('scene/solarsystem/sun/transforms')
local densityDirectory = asset.syncedResource({
Name = "Bastille Day MAS Density",
Type = "HttpSynchronization",
Identifier = "bastille_day_mas_density",
Version = 1
})
local sunRadius = 695508000
local densityVolume = {
Identifier = "MAS_MHD_density",
Parent = sunTransforms.SolarSystemBarycenter.Identifier,
Renderable = {
Type = "RenderableTimeVaryingVolume",
StepSize = 0.003,
Opacity = 0.3,
TransferFunction = asset.localResource("transferfunctions/mas_mhd_r_squared.txt"),
SourceDirectory = densityDirectory,
LowerValueBound = 0,
UpperValueBound = 1,
GridType = "Spherical",
SecondsBefore = 24*60*60,
SecondsAfter = 24*60*60
},
Transform = {
Scale = {
Type = "StaticScale",
Scale = sunRadius
}
},
GUI = {
Name = "MAS Density",
Path = "/Solar System/Heliosphere"
}
}
assetHelper.registerSceneGraphNodesAndExport(asset, { densityVolume })
+57
View File
@@ -0,0 +1,57 @@
local assetHelper = asset.require('util/asset_helper')
local transforms = asset.require('./transforms')
local transferFunctions = asset.localResource("transferfunctions")
local masVelocityColorTable = transferFunctions .. "/velocity_fieldlines.txt"
local masDensityColorTable = transferFunctions .. "/density_fieldlines.txt"
local fieldlinesDirectory = asset.syncedResource({
Name = "Bastille Day MAS Fieldlies",
Type = "HttpSynchronization",
Identifier = "bastille_day_mas_fieldlines",
Version = 1
})
local sunRadius = 695508000
-- Fieldlies from binaries
local fieldlines = {
Identifier = "MAS_MHD_Fieldlines",
Parent = transforms.HNMReferenceFrame.Identifier,
Renderable = {
Type = "RenderableFieldlinesSequence",
SourceFolder = fieldlinesDirectory,
FlowEnabled = false,
AlphaBlendlingEnabled = false,
InputFileType = "osfls",
ColorTablePaths = {
masDensityColorTable,
masVelocityColorTable,
},
ColorTableMinMax = {
{ 0, 1000000 },
{ 100, 2000 }
},
LoadAtRuntime = true,
ScaleToMeters = 1.0,
SecondsBefore = 24*60*60,
SecondsAfter = 24*60*60,
SimulationModel = "mas",
Color = {
Uniform = {0, 0.725, 0.75, 1}
}
},
GUI = {
Path = "/Solar System/Heliosphere",
Name = "MAS Fieldlines"
},
Transform = {
Scale = {
Type = "StaticScale",
Scale = sunRadius
},
}
}
assetHelper.registerSceneGraphNodesAndExport(asset, { fieldlines })
+33
View File
@@ -0,0 +1,33 @@
Geocentric Solar Magnetospheric (GSM) frame:
Used by the BATSRUS model
This Kernel's ID is not a valid ID!
+X is parallel to the geometric earth-sun position vector.
+Z axis is normalized component of north centered geomagnetic dipole
vector orthogonal to GSM +X axis.
+Y completes the right-handed frame.
\begindata
FRAME_GSM = 13371333
FRAME_13371333_NAME = 'GSM'
FRAME_13371333_CLASS = 5
FRAME_13371333_CLASS_ID = 13371333
FRAME_13371333_CENTER = 399
FRAME_13371333_RELATIVE = 'GALACTIC'
FRAME_13371333_DEF_STYLE = 'PARAMETERIZED'
FRAME_13371333_FAMILY = 'TWO-VECTOR'
FRAME_13371333_PRI_AXIS = 'X'
FRAME_13371333_PRI_VECTOR_DEF = 'OBSERVER_TARGET_POSITION'
FRAME_13371333_PRI_OBSERVER = 'EARTH'
FRAME_13371333_PRI_TARGET = 'SUN'
FRAME_13371333_PRI_ABCORR = 'NONE'
FRAME_13371333_SEC_AXIS = 'Z'
FRAME_13371333_SEC_VECTOR_DEF = 'CONSTANT'
FRAME_13371333_SEC_FRAME = 'ECLIPJ2000'
FRAME_13371333_SEC_SPEC = 'LATITUDINAL'
FRAME_13371333_SEC_UNITS = 'DEGREES'
FRAME_13371333_SEC_LONGITUDE = 288.43
FRAME_13371333_SEC_LATITUDE = 79.54
+42
View File
@@ -0,0 +1,42 @@
\begintext
Heliocentric Earth Equatorial (HEEQ+180) Frame
Used by the BATSRUS model
This Kernel's ID is not a valid ID!
Definition of the Heliocentric Earth Equatorial frame:
All vectors are geometric: no aberration corrections are
used.
The solar rotation axis is the primary vector: the Z axis points
in the solar north direction.
The position of the sun relative to the earth is the secondary
vector: the X axis is the component of this position vector
orthogonal to the Z axis.
The Y axis is Z cross X, completing the right-handed
reference frame.
\begindata
FRAME_HEEQ180 = 6666666
FRAME_6666666_NAME = 'HEEQ180'
FRAME_6666666_CLASS = 5
FRAME_6666666_CLASS_ID = 6666666
FRAME_6666666_CENTER = 10
FRAME_6666666_RELATIVE = 'J2000'
FRAME_6666666_DEF_STYLE = 'PARAMETERIZED'
FRAME_6666666_FAMILY = 'TWO-VECTOR'
FRAME_6666666_PRI_AXIS = 'Z'
FRAME_6666666_PRI_VECTOR_DEF = 'CONSTANT'
FRAME_6666666_PRI_FRAME = 'IAU_SUN'
FRAME_6666666_PRI_SPEC = 'RECTANGULAR'
FRAME_6666666_PRI_VECTOR = ( 0, 0, 1 )
FRAME_6666666_SEC_AXIS = 'X'
FRAME_6666666_SEC_VECTOR_DEF = 'OBSERVER_TARGET_POSITION'
FRAME_6666666_SEC_OBSERVER = 'EARTH'
FRAME_6666666_SEC_TARGET = 'SUN'
FRAME_6666666_SEC_ABCORR = 'NONE'
FRAME_6666666_SEC_FRAME = 'IAU_SUN'
+25
View File
@@ -0,0 +1,25 @@
local assetHelper = asset.require('util/asset_helper')
local transforms = asset.require('./transforms')
local sun = asset.require('scene/solarsystem/sun/sun')
local magnetogramDirectory = asset.syncedResource({
Name = "Bastille Day Magnetogram",
Type = "HttpSynchronization",
Identifier = "bastille_day_magnetogram",
Version = 1
})
local defaultSunTexture
local texturePropertyUri = "Scene.Sun.Renderable.ColorTexture"
asset.onInitialize(function ()
openspace.globebrowsing.addLayer("Sun", "ColorLayers", {
Identifier = "Magnetogram100G",
FilePath = magnetogramDirectory .. "/br_bas05_100G_inv_redblue.png",
Enabled = true
})
end)
asset.onDeinitialize(function ()
openspace.globebrowsing.deleteLayer("Sun", "ColorLayers", "Magnetogram100G")
end)
@@ -0,0 +1,9 @@
width 6
lower 0.0
upper 1.0
mappingkey 0.0 0 0 255 250
mappingkey 0.075 0 0 255 250
mappingkey 0.4 0 255 255 250
mappingkey 0.58 0 255 0 250
mappingkey 0.73 255 255 0 250
mappingkey 1.0 255 0 0 250
@@ -0,0 +1,18 @@
width 2048
lower 0.0
upper 1.0
mappingkey 0.005 0 54 135 0
mappingkey 0.06 0 145 255 15
mappingkey 0.1 0 130 255 70
mappingkey 0.13 0 200 255 120
mappingkey 0.16 0 255 255 255
mappingkey 0.2 90 210 255 130
mappingkey 0.3 90 200 255 250
mappingkey 0.4 200 200 230 150
mappingkey 0.5 92 177 242 200
mappingkey 0.6 137 223 255 0
mappingkey 0.7 94 255 214 0
mappingkey 0.8 255 200 180 0
mappingkey 0.9 249 199 150 0
mappingkey 1.0 255 140 100 0
@@ -0,0 +1,9 @@
width 5
lower 0.0
upper 1.0
mappingkey 0.0 0 0 0 255
mappingkey 0.25 255 0 0 255
mappingkey 0.5 255 140 0 255
mappingkey 0.75 255 255 0 255
mappingkey 1.0 255 255 255 255
+41
View File
@@ -0,0 +1,41 @@
local assetHelper = asset.require('util/asset_helper')
local sunTransforms = asset.require('scene/solarsystem/sun/transforms')
local earthTransforms = asset.require('scene/solarsystem/planets/earth/transforms')
local HNMKernel = asset.localResource("kernels/HNM.tf")
local GSMKernel = asset.localResource("kernels/GSM.ti")
local HNMReferenceFrame = {
Identifier = "HNMReferenceFrame",
Parent = sunTransforms.SolarSystemBarycenter.Identifier,
Transform = {
Rotation = {
Type = "SpiceRotation",
SourceFrame = "HEEQ180",
DestinationFrame = "GALACTIC",
Kernels = HNMKernel
}
},
GUI = {
Name = "HNM Reference Frame"
}
}
local GSMReferenceFrame = {
Identifier = "GSMReferenceFrame",
Parent = earthTransforms.EarthBarycenter.Identifier,
Transform = {
Rotation = {
Type = "SpiceRotation",
SourceFrame = "GSM",
DestinationFrame = "GALACTIC",
Kernels = GSMKernel
}
},
GUI = {
Name = "GSM Reference Frame"
}
}
local objects = { HNMReferenceFrame, GSMReferenceFrame }
assetHelper.registerSceneGraphNodesAndExport(asset, objects)
+73
View File
@@ -0,0 +1,73 @@
local assetHelper = asset.require('util/asset_helper')
local sceneHelper = asset.require('util/scene_helper')
local propertyHelper = asset.require('util/property_helper')
-- Specifying which other assets should be loaded in this scene
asset.require('spice/base')
assetHelper.requestAll(asset, 'scene/solarsystem/sun')
asset.require('scene/solarsystem/planets')
-- asset.require('scene/solarsystem/planets/mars/moons/phobos')
-- asset.require('scene/solarsystem/planets/mars/moons/deimos')
-- asset.require('scene/solarsystem/dwarf_planets/pluto/system')
assetHelper.requestAll(asset, 'scene/digitaluniverse')
-- Load default key bindings applicable to most scenes
asset.require('util/default_keybindings')
asset.require('util/default_dashboard')
-- asset.require('util/default_joystick')
-- asset.require('util/webgui')
asset.request('customization/globebrowsing')
local earthAsset = asset.require('scene/solarsystem/planets/earth/earth')
local sunAsset = asset.require('scene/solarsystem/sun/sun')
local sunRadius = 695508000
-- The actual fieldlines
asset.require('./bastille_day/fieldlines')
asset.onInitialize(function ()
local now = openspace.time.currentWallTime()
-- Jump to bastille day
openspace.time.setTime("2000 JUL 14 08:33:37.100")
openspace.setDefaultGuiSorting()
openspace.globebrowsing.loadWMSServersFromFile(
openspace.absPath("${DATA}/globebrowsing_servers.lua")
)
openspace.addVirtualProperty(
"BoolProperty",
"Show Trails",
"Scene.*Trail.Renderable.Enabled",
"Disable or enable all trails of the scene at the same time",
true,
nil,
nil
)
openspace.markInterestingNodes({
"Earth", "Sun", "Moon", "MAS_MHD_Fieldlines"
})
openspace.setPropertyValue("Scene.Sun.Renderable.Enabled", true)
-- openspace.setPropertyValue("Scene.SunGlare.Renderable.Enabled", false)
-- Place by the sun
openspace.navigation.setCameraState({
Anchor = sunAsset.Sun.Identifier,
Position = { 80*sunRadius, 80*sunRadius, 0 },
Rotation = { 0.0, 0.0, 0.7, 0.0 },
})
end)
asset.onDeinitialize(function ()
openspace.removeVirtualProperty("*Trail.Renderable.Enabled")
end)
@@ -24,17 +24,29 @@
#include <modules/base/rendering/renderableplaneimagelocal.h>
// Included for testing purposes
#include <modules/fitsfilereader/include/fitsfilereader.h>
//#include <filesystem>
#include <ghoul/opengl/framebufferobject.h>
#include <cctype>
// <- End of experimental includes
#include <modules/base/basemodule.h>
#include <openspace/documentation/documentation.h>
#include <openspace/documentation/verifier.h>
#include <ghoul/filesystem/file.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/filesystem/directory.h>
#include <ghoul/io/texture/texturereader.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/crc32.h>
#include <ghoul/opengl/texture.h>
#include <fstream>
namespace {
constexpr const char* _loggerCat = "RenderableImagePlaneLocal";
} // namespace
namespace {
constexpr openspace::properties::Property::PropertyInfo TextureInfo = {
"Texture",
@@ -121,7 +133,7 @@ void RenderablePlaneImageLocal::loadTexture() {
_texture = BaseModule::TextureManager.request(
std::to_string(hash),
[path = _texturePath]() -> std::unique_ptr<ghoul::opengl::Texture> {
std::unique_ptr<ghoul::opengl::Texture> texture =
/* std::unique_ptr<ghoul::opengl::Texture> texture =
ghoul::io::TextureReader::ref().loadTexture(absPath(path));
LDEBUGC(
@@ -132,7 +144,97 @@ void RenderablePlaneImageLocal::loadTexture() {
texture->setFilter(ghoul::opengl::Texture::FilterMode::LinearMipMap);
return texture;
// return texture; */
// Testing out the FitsFileReader:
FitsFileReader fitsFileReader(false);
std::unique_ptr<ghoul::opengl::FramebufferObject> testFBO = std::make_unique<ghoul::opengl::FramebufferObject>();
// Given that the node-part is located just outside the openspace-directory
const std::string fitsDir = "../../../../../../node/FITSdata/mrzqs190501/";
std::string testpath = absPath(fitsDir + "mrzqs190501t0114c2216_006.fits");
GLenum oneTexture;
// All the files in the given directory
for (const auto & entry : ghoul::filesystem::Directory(fitsDir).readFiles()) {
LERROR("Starting to upload texture");
// To get a handle to the regular framebuffer, that we can switch back to once we have uploaded all textures
GLint defaultFBO = testFBO->getActiveObject();
testFBO->activate();
LERROR("Initial framebufferobject status: " + testFBO->errorChecking((glCheckFramebufferStatus(GL_FRAMEBUFFER))));
// Mapkey is to get a handle of the timestep of the texture
std::string mapKey ="";
const auto tempBild = fitsFileReader.readImageFloat(entry);
int magicalCounter = -6;
for (char c : entry) {
if (std::isdigit(c)) {
if (magicalCounter >= 0 && magicalCounter < 10) {
mapKey += c;
}
magicalCounter++;
}
}
const float minvalue = *fitsFileReader.readHeaderValueFloat("IMGMIN01");
const float maxvalue = *fitsFileReader.readHeaderValueFloat("IMGMAX01");
const int imageHeight = tempBild->height;
const int imageWidth = tempBild->width;
GLuint fitsImage[360][180];
/*auto texture = std::make_unique<ghoul::opengl::Texture>(glm::uvec3(
imageHeight,
imageWidth,
1
)); */
// Commented this to see if it accepts an empty texture
for (int i = 0; i < 360; i++) {
for (int j = 0; j < 180; j++) {
float color = tempBild->contents[(i * 180) + j];
color = (color - minvalue) / (maxvalue - minvalue);
fitsImage[i][j] = (GLuint)(color * 255);
}
}
auto textureFits = std::make_unique<ghoul::opengl::Texture>(fitsImage, glm::uvec3(360, 180, 1));
LERROR(std::to_string(fitsImage[100][100]));
textureFits->uploadTexture();
oneTexture = static_cast<GLenum>(std::stol(mapKey));
//texture->uploadTexture();
testFBO->attachTexture(textureFits.get(), oneTexture);
LERROR("After texture upload: " + testFBO->errorChecking((glCheckFramebufferStatus(GL_FRAMEBUFFER))));
LERROR("Uploaded one texture! " + mapKey);
//LERROR(std::to_string(testFBO->getActiveObject()));
testFBO->deactivate();
glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO);
}
//auto testbild = fitsFileReader.readImageFloat(testpath);
//const float minvalue = *fitsFileReader.readHeaderValueFloat("IMGMIN01");
//const float maxvalue = *fitsFileReader.readHeaderValueFloat("IMGMAX01");
//LERROR(testpath);
//LERROR("Min / Max respectively: " + std::to_string(minvalue) + " / " + std::to_string(maxvalue) + " -- Width: " + std::to_string(imageWidth) + " -- Height: " + std::to_string(imageHeight) + " size: "+ std::to_string(testbild->contents.size()));
auto texture = testFBO->texture(oneTexture);
//set interpolation method
//textureFits->setFilter(ghoul::opengl::Texture::FilterMode::Nearest); */
return std::make_unique<ghoul::opengl::Texture>(texture, glm::uvec3(360, 180, 1));
}
);
@@ -65,12 +65,16 @@ public:
template<typename T>
std::shared_ptr<ImageData<T>> readImage(const std::string& path);
std::shared_ptr<ImageData<float>> readImageFloat(const std::string& path);
template<typename T>
std::shared_ptr<std::unordered_map<std::string, T>> readHeader(
std::vector<std::string>& keywords);
template<typename T>
std::shared_ptr<T> readHeaderValue(const std::string key);
std::shared_ptr<float> readHeaderValueFloat(const std::string key);
/**
* Read specified table columns from fits file.
* If <code>readAll</code> is set to true the entire table will be read before the
+38 -5
View File
@@ -72,6 +72,24 @@ std::shared_ptr<ImageData<T>> FitsFileReader::readImage(const std::string& path)
return nullptr;
}
std::shared_ptr<ImageData<float>> FitsFileReader::readImageFloat(const std::string& path) {
try {
_infile = std::make_unique<FITS>(path, Read, true);
// Primary HDU Object
if (isPrimaryHDU()) {
return readImageInternal<float>(_infile->pHDU());
}
else{
// Extension HDU Object
return readImageInternal<float>(_infile->currentExtension());
}
} catch (const FitsException& e){
LERROR("Could not read FITS image from table. " + e.message() );
}
}
template <typename T>
std::shared_ptr<std::unordered_map<std::string, T>> FitsFileReader::readHeader(
std::vector<std::string>& keywords)
@@ -122,6 +140,21 @@ std::shared_ptr<T> FitsFileReader::readHeaderValue(const std::string key) {
return nullptr;
}
std::shared_ptr<float> FitsFileReader::readHeaderValueFloat(const std::string key) {
try {
HDU& image = isPrimaryHDU() ?
static_cast<HDU&>(_infile->pHDU()) :
static_cast<HDU&>(_infile->currentExtension());
float value;
image.readKey(key, value);
return std::make_unique<float>(value);
} catch (FitsException& e) {
LERROR("Could not read FITS key. " + e.message() );
}
return nullptr;
}
template<typename T>
std::shared_ptr<TableData<T>> FitsFileReader::readTable(std::string& path,
const std::vector<std::string>& columnNames,
@@ -140,8 +173,8 @@ std::shared_ptr<TableData<T>> FitsFileReader::readTable(std::string& path,
// Make sure FITS file is not a Primary HDU Object (aka an image).
if (!isPrimaryHDU()) {
ExtHDU& table = _infile->extension(hduIdx);
int numCols = static_cast<int>(columnNames.size());
int numRowsInTable = static_cast<int>(table.rows());
int numCols = columnNames.size();
int numRowsInTable = table.rows();
std::unordered_map<string, std::vector<T>> contents;
//LINFO("Read file: " + _infile->name());
@@ -238,8 +271,8 @@ std::vector<float> FitsFileReader::readFitsFile(std::string filePath, int& nValu
int nStars = table->readRows - firstRow + 1;
int nNullArr = 0;
int nColumnsRead = static_cast<int>(allColumnNames.size());
int defaultCols = 17; // Number of columns that are copied by predefined code.
size_t nColumnsRead = allColumnNames.size();
size_t defaultCols = 17; // Number of columns that are copied by predefined code.
if (nColumnsRead != defaultCols) {
LINFO("Additional columns will be read! Consider add column in code for "
"significant speedup!");
@@ -330,7 +363,7 @@ std::vector<float> FitsFileReader::readFitsFile(std::string filePath, int& nValu
values[idx++] = vecData[i];
}
for (int j = 0; j < nValuesPerStar; ++j) {
for (size_t j = 0; j < nValuesPerStar; ++j) {
// The astronomers in Vienna use -999 as default value. Change it to 0.
if (values[j] == -999) {
values[j] = 0.f;
+2 -1
View File
@@ -37,7 +37,7 @@ SGCTConfig = sgct.config.single{}
-- Sets the scene that is to be loaded by OpenSpace. A scene file is a description
-- of all entities that will be visible during an instance of OpenSpace
Asset = "default"
--Asset = "default"
-- Asset = "default_full"
-- Asset = "newhorizons"
-- Asset = "rosetta"
@@ -46,6 +46,7 @@ Asset = "default"
-- Asset = "gaia"
-- Asset = "juno"
-- Asset = "messenger"
Asset = "bastille_test"
-- These scripts are executed after the initialization of each scene, thus making
-- it possible to have global overrides to default values or execute other scripts