Added property for color mode + swapping theta and phi value

This commit is contained in:
Emilie
2020-06-15 09:39:10 +02:00
parent 4c0970436e
commit 01d7f7ade4
3 changed files with 58 additions and 49 deletions

View File

@@ -94,6 +94,12 @@ namespace {
//properties::PropertyOwner _pStreamGroup;
constexpr openspace::properties::Property::PropertyInfo ColorModeInfo = {
"colorMode",
"Color Mode",
"Color lines uniformly or using color tables based on specific values on nodes,"
"for examples flux values."
};
// Size of simulated flow particles
constexpr openspace::properties::Property::PropertyInfo StreamColorInfo = {
"color",
@@ -168,18 +174,11 @@ namespace {
//LDEBUG("spherical R:" + std::to_string(position.x));
//ρsinφcosθ
//prolly correct:
cartesianPosition.x = position.x * sin(position.y) * cos(position.z);
//cartesianPosition.x = position.x * sin(position.z) * cos(position.y);
cartesianPosition.x = position.x * sin(position.z) * cos(position.y);
//ρsinφsinθ
// prolly correct:
cartesianPosition.y = position.x * sin(position.y) * sin(position.z);
//cartesianPosition.y = position.x * sin(position.z) * sin(position.y);
cartesianPosition.y = position.x * sin(position.z) * sin(position.y);
//ρcosφ
//prolly correct:
cartesianPosition.z = position.x * cos(position.y);
//cartesianPosition.z = position.x * cos(position.z);
cartesianPosition.z = position.x * cos(position.z);
//LDEBUG("cartesian position x: " + std::to_string(cartesianPosition.x));
//cartesian position x : 0.002175
@@ -193,6 +192,7 @@ namespace openspace {
: Renderable(dictionary)
, _pColorGroup({ "Color" })
, _pColorMode(ColorModeInfo, OptionProperty::DisplayType::Radio)
, _pStreamColor(StreamColorInfo,
glm::vec4(0.96f, 0.88f, 0.8f, 0.5f),
glm::vec4(0.f),
@@ -202,7 +202,7 @@ namespace openspace {
, _pNodeSize(NodeSizeInfo, 2.f, 1.f, 20.f)
, _pLineWidth(LineWidthInfo, 1.f, 1.f, 20.f)
//, _pThresholdRadius(ThresholdRadiusInfo, -2.f, -5.f, 5.f)
, _pThresholdRadius(ThresholdRadiusInfo, 100000000000.f, 500000000.f, 400000000000.f)
, _pThresholdRadius(ThresholdRadiusInfo, 100000000000.f, -500000000000.f, 400000000000.f)
, _pFiltering(FilteringInfo, 100000.f, 500000000.f, 400000000000.f)
{
@@ -389,11 +389,15 @@ namespace openspace {
addPropertySubOwner(_pStreamGroup);
addPropertySubOwner(_pColorGroup);
// ------------------------- Add Properties to the groups ------------------------ //
_pColorGroup.addProperty(_pColorMode);
_pColorGroup.addProperty(_pStreamColor);
_pStreamGroup.addProperty(_pNodeSize);
_pStreamGroup.addProperty(_pThresholdRadius);
}
// --------------------- Add Options to OptionProperties --------------------- //
_pColorMode.addOption(static_cast<int>(ColorMethod::Uniform), "Uniform");
_pColorMode.addOption(static_cast<int>(ColorMethod::ByFluxValue), "By Flux Value");
}
void RenderableStreamNodes::deinitializeGL() {
glDeleteVertexArrays(1, &_vertexArrayObject);
@@ -484,6 +488,16 @@ namespace openspace {
_shaderProgram->setUniform(_uniformCache.nodeSize, 1);
_shaderProgram->setUniform(_uniformCache.thresholdRadius, _pThresholdRadius);
//if (_pColorMode == static_cast<int>(ColorMethod::ByFluxValue)) {
//ghoul::opengl::TextureUnit textureUnit;
//textureUnit.activate();
//_transferFunction->bind(); // Calls update internally
//_shaderProgram->setUniform("colorTable", textureUnit);
//_shaderProgram->setUniform("colorTableRange",
// _colorTableRanges[_pColorQuantity]);
//}
const std::vector<glm::vec3>& vertPos = _vertexPositions;
glBindVertexArray(_vertexArrayObject);
glLineWidth(_pLineWidth);
@@ -504,8 +518,6 @@ namespace openspace {
temp,
static_cast<GLsizei>(_lineCount.size())
);
glBindVertexArray(0);
_shaderProgram->deactivate();
@@ -596,8 +608,8 @@ namespace openspace {
_needsUpdate = false;
_newStateIsReady = false;
updateVertexColorBuffer();
updateVertexFilteringBuffer();
//updateVertexColorBuffer();
//updateVertexFilteringBuffer();
unbindGL();
}
@@ -639,7 +651,7 @@ namespace openspace {
size_t lineStartIdx = 0;
//Loop through all the nodes
const int numberofStreams = 15;
const int numberofStreams = 150;
constexpr const float AuToMeter = 149597870700.f; // Astronomical Units
//constexpr const float ReToMeter = 6371000.f; // Earth radius
//constexpr const float RsToMeter = 695700000.f; // Sun radius
@@ -680,15 +692,17 @@ namespace openspace {
thetavalue = thetavalue * (180 / pi);
rvalue = rvalue * AuToMeter;
*/
//--------FLOAT
float rValue = stringToFloat(r);
float phiValue = stringToFloat(phi);
float thetaValue = stringToFloat(theta);
float fluxValue = stringToFloat(flux);
const float pi = 3.14159265359f;
phiValue = phiValue * (180.f / pi);
thetaValue = thetaValue * (180.0f / pi);
//phiValue = phiValue * (180.f / pi);
//thetaValue = thetaValue + 1.57079633; //(180.f / pi);
rValue = rValue * AuToMeter;
float rTimesFluxValue = rValue * fluxValue;
glm::vec3 sphericalcoordinates =
glm::vec3(rValue, phiValue, thetaValue);
@@ -704,6 +718,10 @@ namespace openspace {
//((*lineIter)["R"].get<std::string>())));
//sphericalcoordinates.x = sphericalcoordinates.x * AuToMeter;
glm::vec3 position = sphericalToCartesianCoord(sphericalcoordinates);
//KOLLA OM DEN KONVERTATION FROM DEGREE
//Look in to convertion
//Roterar åt fel håll counter clockwise
//position.x = position.x * AuToMeter;
//position.y = position.y * AuToMeter;
//position.z = position.z * AuToMeter;
@@ -721,19 +739,9 @@ namespace openspace {
_lineStart.push_back(static_cast<GLsizei>(lineStartIdx));
lineStartIdx += nPoints;
//glm::vec4 red(1.0f, 0.3f, 0.3f, 0.5f);
//glm::vec4 blue(0.3f, 0.3f, 1.0f, 0.5f);
//float red = 0.1;
//float blue = 1;
//if (rValue >= _pThresholdRadius) {
// _vertexRadius.push_back(rValue);
//}
_vertexColor.push_back(fluxValue);
_vertexColor.push_back(rTimesFluxValue);
_vertexRadius.push_back(rValue);
}
}

View File

@@ -67,7 +67,7 @@ namespace openspace {
// Used to determine if lines should be colored UNIFORMLY or by an extraQuantity
enum class ColorMethod : int {
Uniform = 0,
ByQuantity
ByFluxValue
};
UniformCache(streamColor, usingParticles, nodeSize, thresholdRadius)
@@ -129,7 +129,8 @@ namespace openspace {
properties::FloatProperty _pThresholdRadius;
// Filtering nodes within a range
properties::FloatProperty _pFiltering;
// Uniform/transfer function/topology? //////////////////////?
properties::OptionProperty _pColorMode;
// initialization
std::vector<std::string> _sourceFiles;

View File

@@ -29,7 +29,7 @@ uniform vec4 lineColor;
uniform mat4 modelViewProjection;
// Uniforms needed to color by quantity
uniform int colorMethod;
uniform int colorMode;
uniform sampler1D colorTable;
uniform vec2 colorTableRange;
@@ -63,7 +63,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 fluxValue;
layout(location = 1) in float rTimesFluxValue;
// The extra value used to mask out parts of lines. Location must correspond to
// _VA_MASKING in renderablefieldlinessequence.h
@@ -71,9 +71,9 @@ layout(location = 2)
in float rValue;
// These should correspond to the enum 'ColorMethod' in renderablefieldlinesequence.cpp
// These should correspond to the enum 'ColorMode' in renderablestreamnodes.cpp
const int uniformColor = 0;
const int colorByQuantity = 1;
const int colorByFluxValue = 1;
out vec4 vs_color;
out float vs_depth;
@@ -81,7 +81,7 @@ out float vs_depth;
vec4 getTransferFunctionColor() {
// Remap the color scalar to a [0,1] range
float lookUpVal = (fluxValue - colorTableRange.x) /
float lookUpVal = (rTimesFluxValue - colorTableRange.x) /
(colorTableRange.y - colorTableRange.x);
return texture(colorTable, lookUpVal);
}
@@ -94,25 +94,25 @@ bool isPartOfParticle(const double time, const int vertexId, const int particleS
void main() {
//vs_color = vec4(1.0, 0.3, 0.3, 1.0);
vec4 temp = streamColor;
//vs_color = streamColor;
const int largerFlux = -2;
const float largerFlux = -2;
//if(thresholdRadius > fluxValue){
if(fluxValue > largerFlux){
temp.x = 0.8 * streamColor.x;
vs_color = temp;
vs_color = vec4(8.0, 0.3, 0.3, 1.0);
if(rTimesFluxValue > largerFlux){
vs_color = vec4(0.9, 0.4, 0.95, 1.0);
}
else{
vs_color = vec4(0.3, 0.7, 0.3, 1.0);
vs_color = vec4(0.4, 0.0, 0.4, 1.0);
}
if(rValue > thresholdRadius){
vs_color = vec4(0);
}
//if (colorMethod == colorByFluxValue) {
// vec4 quantityColor = getTransferFunctionColor();
// vs_color = vec4(quantityColor.xyz, vs_color.a * quantityColor.a);
//}
//if(rValue > thresholdRadius){
// vs_color = vec4(0);
//}
vec4 position_in_meters = vec4(in_position, 1);
vec4 positionClipSpace = modelViewProjection * position_in_meters;