Added functionality to color specific nodes close to Earth

with different color tables
This commit is contained in:
Emilie
2020-07-01 11:38:43 +02:00
parent 5b25c00b73
commit b4d413338a
5 changed files with 82 additions and 47 deletions

View File

@@ -17,15 +17,14 @@ openspace.setPropertyValueSingle("Modules.Space.ShowExceptions", false)
--openspace.setPropertyValueSingle("Scene.SaturnTrail.Renderable.Enabled", false)
local transferFunctions = asset.localResource("transferfunctions")
-- local masVelocityColorTable = transferFunctions .. "/velocity_fieldlines.txt"
-- local masDensityColorTable = transferFunctions .. "/density_fieldlines.txt"
local streamnodeDensityColorTable = transferFunctions .. "/stream_nodes.txt"
local streamnodeColorTable = transferFunctions .. "/stream_nodes.txt"
local streamnodeColorTableEarth = transferFunctions .. "/stream_nodes10.txt"
local streamnodesDirectory = asset.syncedResource({
Name = "Bastille Day Stream nodes",
Type = "HttpSynchronization",
Identifier = "bastille_day_streamnodes",
Version = 3
Version = 2
})
@@ -46,9 +45,8 @@ local Streamnodes = {
-- AlphaBlendlingEnabled = false,
InputFileType = "json",
ColorTablePaths = {
streamnodeDensityColorTable,
-- masDensityColorTable,
-- masVelocityColorTable,
streamnodeColorTable,
streamnodeColorTableEarth,
},
--ColorTableMinMax = {
-- { 0, 1000000 },

View File

@@ -0,0 +1,12 @@
width 6
lower 0.0
upper 1.0
mappingkey 0.0 45 45 45 255
mappingkey 0.166 64 64 64 255
mappingkey 0.332 96 96 96 255
mappingkey 0.498 128 128 128 255
mappingkey 0.664 160 160 160 255
mappingkey 0.830 192 192 192 255
mappingkey 1.0 224 224 224 255

View File

@@ -103,16 +103,16 @@ namespace {
"Color lines uniformly or using color tables based on specific values on nodes,"
"for examples flux values."
};
constexpr openspace::properties::Property::PropertyInfo ColorFluxInfo = {
"colorFlux",
"Flux value to Color By",
"Flux values used to color lines if the 'By Flux value' color method is selected."
};
constexpr openspace::properties::Property::PropertyInfo ColorTablePathInfo = {
"colorTablePath",
"Path to Color Table",
"Color Table/Transfer Function to use for 'By Flux Value' coloring."
};
constexpr openspace::properties::Property::PropertyInfo ColorTablePathEarthInfo = {
"colorTablePathEarth",
"Path to Color Table for nodes close to Earth",
"Color Table/Transfer Function for nodes around Earth."
};
constexpr openspace::properties::Property::PropertyInfo StreamColorInfo = {
"color",
"Color",
@@ -267,9 +267,9 @@ namespace openspace {
, _pColorMode(ColorModeInfo, OptionProperty::DisplayType::Radio)
, _pScalingmethod(ScalingmethodInfo, OptionProperty::DisplayType::Radio)
, _pNodeskipMethod(NodeskipMethodInfo, OptionProperty::DisplayType::Radio)
, _pColorFlux(ColorFluxInfo, OptionProperty::DisplayType::Dropdown)
, _pDistancemethod(DistanceMethodInfo, OptionProperty::DisplayType::Dropdown)
, _pColorTablePath(ColorTablePathInfo)
, _pColorTablePathEarth(ColorTablePathEarthInfo)
, _pStreamColor(StreamColorInfo,
glm::vec4(0.96f, 0.88f, 0.8f, 0.5f),
glm::vec4(0.f),
@@ -291,7 +291,6 @@ namespace openspace {
, _pRadiusNodeSkipThreshold(RadiusNodeSkipThresholdInfo, 0.f, 0.f, 5.f)
, _pDistanceThreshold(DistanceThresholdInfo, 0.0f, 0.0f, 700000000000.0f)
, _pActiveStreamNumber(FluxNodeskipThresholdInfo, 0, 0, 383)
{
_dictionary = std::make_unique<ghoul::Dictionary>(dictionary);
@@ -299,14 +298,18 @@ namespace openspace {
void RenderableStreamNodes::definePropertyCallbackFunctions() {
// Add Property Callback Functions
_pColorFlux.onChange([this] {
_pColorTablePath = _colorTablePaths[_pColorFlux];
});
_pColorTablePath.onChange([this] {
_transferFunction->setPath(_pColorTablePath);
_colorTablePaths[_pColorFlux] = _pColorTablePath;
});
_colorTablePaths[0] = _pColorTablePath;
});
_pColorTablePathEarth.onChange([this] {
_transferFunctionEarth->setPath(_pColorTablePathEarth);
_colorTablePathsEarth[0] = _pColorTablePathEarth;
});
_pGoesEnergyBins.onChange([this] {
if (_pGoesEnergyBins == 1) {
_isLoadingNewEnergyBin = true;
@@ -360,11 +363,13 @@ namespace openspace {
if (!extractMandatoryInfoFromDictionary(sourceFileType)) {
return;
}
// Set a default color table, just in case the (optional) user defined paths are
// corrupt or not provided!
_colorTablePaths.push_back(FieldlinesSequenceModule::DefaultTransferFunctionFile);
_colorTablePathsEarth.push_back(FieldlinesSequenceModule::DefaultTransferFunctionFile);
_transferFunction = std::make_unique<TransferFunction>(absPath(_colorTablePaths[0]));
_transferFunctionEarth = std::make_unique<TransferFunction>(absPath(_colorTablePathsEarth[0]));
// EXTRACT OPTIONAL INFORMATION FROM DICTIONARY
std::string outputFolderPath;
@@ -383,10 +388,13 @@ namespace openspace {
if (nProvidedPaths > 0) {
// Clear the default! It is already specified in the transferFunction
_colorTablePaths.clear();
for (size_t i = 1; i <= nProvidedPaths; ++i) {
_colorTablePaths.push_back(
colorTablesPathsDictionary.value<std::string>(std::to_string(i)));
}
_colorTablePathsEarth.clear();
_colorTablePaths.push_back(
colorTablesPathsDictionary.value<std::string>(std::to_string(1)));
_colorTablePathsEarth.push_back(
colorTablesPathsDictionary.value<std::string>(std::to_string(2)));
}
}
@@ -451,8 +459,6 @@ namespace openspace {
reinterpret_cast<const char*>(&CurrentCacheVersion),
sizeof(int8_t)
);
}
std::string cachedFile = FileSys.cacheManager()->cachedFilename(
_file,
@@ -887,6 +893,7 @@ namespace openspace {
_pColorGroup.addProperty(_pScalingmethod);
_pColorGroup.addProperty(_pColorTableRange);
_pColorGroup.addProperty(_pColorTablePath);
_pColorGroup.addProperty(_pColorTablePathEarth);
_pColorGroup.addProperty(_pStreamColor);
_pColorGroup.addProperty(_pFluxColorAlpha);
@@ -929,6 +936,7 @@ namespace openspace {
// Set default
_pColorTablePath = _colorTablePaths[0];
_pColorTablePathEarth = _colorTablePathsEarth[0];
}
void RenderableStreamNodes::deinitializeGL() {
@@ -1051,11 +1059,17 @@ namespace openspace {
_shaderProgram->setUniform("DistanceThreshold", _pDistanceThreshold);
_shaderProgram->setUniform("DistanceMethod", _pDistancemethod);
_shaderProgram->setUniform("activestreamnumber", _pActiveStreamNumber);
if (_pColorMode == static_cast<int>(ColorMethod::ByFluxValue)) {
ghoul::opengl::TextureUnit textureUnit;
textureUnit.activate();
_transferFunction->bind(); // Calls update internally
_shaderProgram->setUniform("colorTable", textureUnit);
ghoul::opengl::TextureUnit textureUnitEarth;
textureUnitEarth.activate();
_transferFunctionEarth->bind(); // Calls update internally
_shaderProgram->setUniform("colorTableEarth", textureUnitEarth);
}
const std::vector<glm::vec3>& vertPos = _vertexPositions;

View File

@@ -149,10 +149,14 @@ namespace openspace {
std::unique_ptr<ghoul::opengl::ProgramObject> _shaderProgram;
// Transfer function used to color lines when _pColorMethod is set to BY_FLUX_VALUE
std::unique_ptr<TransferFunction> _transferFunction;
// Transfer function used to color lines /////////////
std::unique_ptr<TransferFunction> _transferFunctionEarth;
// ------------------------------------ VECTORS ----------------------------------- //
// Paths to color tables. One for each 'ColorFlux'
std::vector<std::string> _colorTablePaths;
// Paths to Earth color tables
std::vector<std::string> _colorTablePathsEarth;
// Values represents min & max values represented in the color table
std::vector<glm::vec2> _colorTableRanges;
// Contains the _triggerTimes for all FieldlineStates in the sequence
@@ -186,12 +190,12 @@ namespace openspace {
properties::OptionProperty _pColorMode;
// Uniform stream Color
properties::Vec4Property _pStreamColor;
// Index of the flux value to color lines by
properties::OptionProperty _pColorFlux;
// Chose different distant measurements:
properties::OptionProperty _pDistancemethod;
// Color table/transfer function for "By Flux value" coloring
properties::StringProperty _pColorTablePath;
// Color table/transfer function for Earth
properties::StringProperty _pColorTablePathEarth;
// Valid range for the color table
properties::Vec2Property _pColorTableRange;
// The value of alpha for the flux color mode

View File

@@ -31,6 +31,7 @@ uniform mat4 modelViewProjection;
// Uniforms needed to color by quantity
uniform int colorMode;
uniform sampler1D colorTable;
uniform sampler1D colorTableEarth;
uniform vec2 colorTableRange;
// Uniforms needed for Particle Flow
@@ -133,11 +134,20 @@ vec4 getTransferFunctionColor() {
scalevalue = rValue * rValue * fluxValue;
}
//if(scalevalue > thresholdFlux){
float lookUpVal = (scalevalue - colorTableRange.x)/(colorTableRange.y - colorTableRange.x);
return texture(colorTable, lookUpVal);
//}
// return vec4(0);
float lookUpVal = (scalevalue - colorTableRange.x)/(colorTableRange.y - colorTableRange.x);
return texture(colorTable, lookUpVal);
}
vec4 getTransferFunctionColor2() {
// Remap the color scalar to a [0,1] range
float scalevalueEarth = 0;
if(ScalingMode == Fluxmode){
scalevalueEarth = fluxValue;
}
float lookUpValEarth = (scalevalueEarth - colorTableRange.x)/(colorTableRange.y - colorTableRange.x);
return texture(colorTableEarth, lookUpValEarth);
}
bool isPartOfParticle(const double time, const int vertexId, const int particleSize,
@@ -149,24 +159,24 @@ bool CheckvertexIndex(){
if(NodeskipMethod == uniformskip){
if(mod(nodeIndex, Nodeskip) == 0){
return true;
return true;
}
}
else if(NodeskipMethod == Fluxskip){
if(fluxValue > NodeskipFluxThreshold && mod(nodeIndex, Nodeskip) == 0){
return true;
return true;
}
if(fluxValue < NodeskipFluxThreshold && mod(nodeIndex, Nodeskipdefault) == 0){
return true;
return true;
}
}
else if(NodeskipMethod == Radiusskip){
if(rValue < NodeskipRadiusThreshold && mod(nodeIndex, Nodeskip) == 0){
return true;
return true;
}
if(rValue > NodeskipRadiusThreshold && mod(nodeIndex, Nodeskipdefault) == 0){
return true;
return true;
}
}
return false;
@@ -181,14 +191,14 @@ void main() {
if(colorMode == 0){
vs_color = streamColor;
}
else{ //else if (colorMode == 1){
else{
vec4 fluxColor = getTransferFunctionColor();
if(fluxValue > thresholdFlux){
vs_color = vec4(fluxColor.xyz, fluxColor.w);
vs_color = vec4(fluxColor.xyz, fluxColor.w);
}
else{
vs_color = vec4(fluxColor.xyz, fluxColorAlpha);
vs_color = vec4(fluxColor.xyz, fluxColorAlpha);
}
}
}
@@ -216,13 +226,10 @@ void main() {
if(DistanceMethod == 0){
if(distance(earthPos, in_position) < DistanceThreshold){
//gl_PointSize = 10;
if(!firstrender && vs_color.x != 0 && vs_color.y != 0){
gl_PointSize = gl_PointSize + 2;
vs_color = vec4(1,1,1,fluxColorAlpha);
}
vec4 fluxColor2 = getTransferFunctionColor2();
vs_color = vec4(fluxColor2.xyz, fluxColor2.w);
//gl_PointSize = 1;
}
}
else if(DistanceMethod == 1){
if(distance(earthPos.x, in_position.x) < DistanceThreshold){