Added flux scaling method in gui and shader

This commit is contained in:
Christian Adamsson
2020-06-18 11:52:25 +02:00
parent 07c44c57a6
commit 35e0b5967a
3 changed files with 79 additions and 20 deletions

View File

@@ -163,7 +163,12 @@ namespace {
"FilteringUpper",
"Use filtering to show nodes within a given range."
};
constexpr openspace::properties::Property::PropertyInfo ScalingmethodInfo = {
"Scaling flux",
"Scale the flux value with colortable",
"Use scaling to color nodes with a given method."
};
enum class SourceFileType : int {
Json = 0,
Cdf,
@@ -223,6 +228,7 @@ namespace openspace {
: Renderable(dictionary)
, _pColorGroup({ "Color" })
, _pColorMode(ColorModeInfo, OptionProperty::DisplayType::Radio)
, _pScalingmethod(ScalingmethodInfo, OptionProperty::DisplayType::Radio)
//, _pColorFlux(ColorFluxInfo, OptionProperty::DisplayType::Dropdown)
, _pColorFluxMin(ColorFluxMinInfo)
, _pColorFluxMax(ColorFluxMaxInfo)
@@ -239,9 +245,11 @@ namespace openspace {
//, _pThresholdRadius(ThresholdRadiusInfo, 100000000000.f, -500000000000.f, 400000000000.f)
, _pThresholdRadius(ThresholdRadiusInfo, 0.f, -10.f, 10.f)
, _pFiltering(FilteringInfo, 100000.f, 10000000.f, 1000000000000.f)
, _pFilteringUpper(FilteringUpperInfo, 600000000000.f, 1000000.f, 1000000000000.f)
// , _pFiltering(FilteringInfo, 100000.f, 10000000.f, 1000000000000.f)
// , _pFilteringUpper(FilteringUpperInfo, 600000000000.f, 1000000.f, 1000000000000.f)
, _pFiltering(FilteringInfo, 0.f, 0.f, 5.f)
, _pFilteringUpper(FilteringUpperInfo, 5.f, 0.f, 5.f)
{
_dictionary = std::make_unique<ghoul::Dictionary>(dictionary);
@@ -301,7 +309,7 @@ namespace openspace {
//if (!_loadingStatesDynamically) {
// _sourceFiles.clear();
//}
_nStates = 274;
//_nStates = 274;
setupProperties();
extractTriggerTimesFromFileNames();
@@ -400,7 +408,10 @@ namespace openspace {
float ninetyDeToRad = 1.57079633f * 2;
const float pi = 3.14159265359f;
float rTimesFluxValue = rValue * rValue * fluxValue;
//float rTimesFluxValue = rValue * rValue * fluxValue;
float rTimesFluxValue = fluxValue;
_vertexColor.push_back(rTimesFluxValue);
_vertexRadius.push_back(rValue);
rValue = rValue * AuToMeter;
//if(thetaValue > 1.4 && thetaValue < 1.6){
@@ -427,8 +438,7 @@ namespace openspace {
_lineStart.push_back(static_cast<GLsizei>(lineStartIdx));
lineStartIdx += nPoints;
_vertexColor.push_back(rTimesFluxValue);
_vertexRadius.push_back(rValue);
int skipcounter = 0;
int nodeskipn = 10;
@@ -580,6 +590,7 @@ namespace openspace {
addPropertySubOwner(_pColorGroup);
// ------------------------- Add Properties to the groups ------------------------ //
_pColorGroup.addProperty(_pColorMode);
_pColorGroup.addProperty(_pScalingmethod);
//_pColorGroup.addProperty(_pColorFlux);
_pColorGroup.addProperty(_pColorFluxMin);
_pColorGroup.addProperty(_pColorFluxMax);
@@ -592,6 +603,11 @@ namespace openspace {
_pColorMode.addOption(static_cast<int>(ColorMethod::Uniform), "Uniform");
_pColorMode.addOption(static_cast<int>(ColorMethod::ByFluxValue), "By Flux Value");
_pScalingmethod.addOption(static_cast<int>(ScalingMethod::Flux), "Flux");
_pScalingmethod.addOption(static_cast<int>(ScalingMethod::RFlux), "Radius * Flux");
_pScalingmethod.addOption(static_cast<int>(ScalingMethod::R2Flux), "Radius^2 * Flux");
_pScalingmethod.addOption(static_cast<int>(ScalingMethod::log10RFlux), "log10(r) * Flux");
_pScalingmethod.addOption(static_cast<int>(ScalingMethod::lnRFlux), "ln(r) * Flux");
definePropertyCallbackFunctions();
// Set defaults
@@ -699,6 +715,7 @@ namespace openspace {
_shaderProgram->setUniform("colorMode", _pColorMode);
_shaderProgram->setUniform("filterRadius", _pFiltering);
_shaderProgram->setUniform("filterUpper", _pFilteringUpper);
_shaderProgram->setUniform("ScalingMode", _pScalingmethod);
if (_pColorMode == static_cast<int>(ColorMethod::ByFluxValue)) {
ghoul::opengl::TextureUnit textureUnit;
@@ -943,10 +960,13 @@ namespace openspace {
//phiValue = phiValue * (180.f / pi);
//thetaValue = thetaValue + ninetyDeToRad; //(180.f / pi);
//phiValue = phiValue + ninetyDeToRad;
float rTimesFluxValue = rValue * rValue * fluxValue;
//float rTimesFluxValue = rValue * rValue * fluxValue;
float rTimesFluxValue = fluxValue;
_vertexColor.push_back(rTimesFluxValue);
_vertexRadius.push_back(rValue);
rValue = rValue * AuToMeter;
if(thetaValue < 1.6 && thetaValue > 1.4){
//if(thetaValue < 1.6 && thetaValue > 1.4){
//if(rTimesFluxValue > 0)
glm::vec3 sphericalcoordinates =
glm::vec3(rValue, phiValue, thetaValue);
@@ -983,8 +1003,8 @@ namespace openspace {
_lineStart.push_back(static_cast<GLsizei>(lineStartIdx));
lineStartIdx += nPoints;
_vertexColor.push_back(rTimesFluxValue);
_vertexRadius.push_back(rValue);
//_vertexColor.push_back(rTimesFluxValue);
//_vertexRadius.push_back(rValue);
//skipping nodes
int skipcounter = 0;
@@ -994,7 +1014,7 @@ namespace openspace {
++skipcounter;
}
}
}
// }
}
LDEBUG("vertPos size:" + std::to_string(_vertexPositions.size()));

View File

@@ -67,7 +67,14 @@ namespace openspace {
// Used to determine if lines should be colored UNIFORMLY or by an extraQuantity
enum class ColorMethod : int {
Uniform = 0,
ByFluxValue
ByFluxValue = 1
};
enum class ScalingMethod : int {
Flux = 0,
RFlux = 1,
R2Flux = 2,
log10RFlux = 3,
lnRFlux = 4
};
UniformCache(streamColor, usingParticles, nodeSize, thresholdRadius)
@@ -103,7 +110,7 @@ namespace openspace {
// Estimated end of sequence.
double _sequenceEndTime;
// Number of states in the sequence
size_t _nStates = 0;
size_t _nStates = 274;
GLuint _vertexArrayObject = 0;
// OpenGL Vertex Buffer Object containing the vertex positions
@@ -118,6 +125,8 @@ namespace openspace {
properties::PropertyOwner _pColorGroup;
// Uniform/transfer function/topology? //////////////////////?
properties::OptionProperty _pColorMode;
// Scaling options
properties::OptionProperty _pScalingmethod;
// Uniform stream Color
properties::Vec4Property _pStreamColor;
// Index of the flux value to color lines by

View File

@@ -58,6 +58,7 @@ uniform vec4 streamColor;
uniform float thresholdRadius;
uniform float filterRadius;
uniform float filterUpper;
uniform int ScalingMode;
// Inputs
// Should be provided in meters
@@ -65,7 +66,7 @@ layout(location = 0) in vec3 in_position;
// The extra value used to color lines. Location must correspond to _VA_COLOR in
// renderablefieldlinessequence.h
layout(location = 1) in float rTimesFluxValue;
layout(location = 1) in float fluxValue;
// The extra value used to mask out parts of lines. Location must correspond to
// _VA_MASKING in renderablefieldlinessequence.h
@@ -77,6 +78,11 @@ in float rValue;
const int uniformColor = 0;
const int colorByFluxValue = 1;
const int Fluxmode = 0;
const int RFlux = 1;
const int R2Flux = 2;
const int log10RFlux = 3;
const int lnRFlux = 4;
out vec4 vs_color;
out float vs_depth;
//out vec4 vs_gPosition;
@@ -86,8 +92,29 @@ float maxValTableRange = 4;
vec4 getTransferFunctionColor() {
// Remap the color scalar to a [0,1] range
float lookUpVal = (rTimesFluxValue - minValTableRange)/(maxValTableRange - minValTableRange);
float scalevalue = 0;
if(ScalingMode == Fluxmode){
scalevalue = fluxValue;
}
else if(ScalingMode == RFlux){
scalevalue = rValue * fluxValue;
}
else if(ScalingMode == log10RFlux){
//conversion from logbase e to log10 since glsl does not support log10.
float logtoTen = log(rValue) / log(10);
scalevalue = logtoTen * fluxValue;
}
else if(ScalingMode == lnRFlux){
scalevalue = log(rValue) * fluxValue;
}
else if(ScalingMode == R2Flux){
scalevalue = rValue * rValue * fluxValue;
}
if(scalevalue > thresholdRadius){
float lookUpVal = (scalevalue - minValTableRange)/(maxValTableRange - minValTableRange);
return texture(colorTable, lookUpVal);
}
return vec4(0);
}
bool isPartOfParticle(const double time, const int vertexId, const int particleSize,
@@ -100,19 +127,22 @@ void main() {
//vs_color = streamColor;
//if(rValue > filterRadius && rValue filterUpper){
if(rValue > filterRadius){
if(rValue > filterRadius && rValue < filterUpper){
//if(rValue > filterRadius){
if(colorMode == 0){
vs_color = streamColor;
}
else if (colorMode == 1){
vec4 quantityColor = getTransferFunctionColor();
vs_color = vec4(quantityColor.xyz, 1);
vs_color = vec4(quantityColor.xyz, quantityColor.w);
}
else{
vs_color = vec4(0);
}
}
else{
vs_color = vec4(0);
}
//if(rValue > thresholdRadius){
// vs_color = vec4(0);
//}