Right scale and read from cdf file

This commit is contained in:
Sebastian Piwell
2016-03-22 16:15:46 -04:00
parent 1a47008694
commit 7712dd0190
4 changed files with 40 additions and 33 deletions

1
.gitignore vendored
View File

@@ -112,3 +112,4 @@ data/scene/vestaprojection/textures/projectMe.png
data/spice/MAR063.BSP
data/spice/de430_1850-2150.bsp
data/spice/jup260.bsp
data/BATSRUS.cdf

View File

@@ -60,20 +60,13 @@ RenderableDataPlane::~RenderableDataPlane(){
bool RenderableDataPlane::initialize() {
KameleonWrapper kw(absPath("${OPENSPACE_DATA}/OpenGGCM.cdf"));
KameleonWrapper kw(absPath("${OPENSPACE_DATA}/BATSRUS.cdf"));
_dimensions = glm::size3_t(1000,1000,1);
float zSlice = 0.5f;
float* _dataSlice = kw.getUniformSliceValues(std::string("p"), _dimensions, zSlice);
/*
for (int i = 0; i < _dimensions.x; ++i)
{
for (int k = 0; k < _dimensions.y; ++k){
std::cout << _dataSlice[k] << " ";
}
std::cout << std::endl;
}*/
_dataSlice = kw.getUniformSliceValues(std::string("p"), _dimensions, zSlice);
_modelScale = kw.getModelScaleScaled();
_pscOffset = kw.getModelBarycenterOffsetScaled();
@@ -147,10 +140,11 @@ void RenderableDataPlane::render(const RenderData& data)
// Activate shader
_shader->activate();
glEnable(GL_ALPHA_TEST);
glDisable(GL_CULL_FACE);
auto psc = _parentPos;
glm::dvec4 dpc = psc.dvec4();
psc += glm::vec4(_pscOffset);
psc += glm::vec4(-_pscOffset.x, _pscOffset.y, _pscOffset.z, _pscOffset.w);
_shader->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
_shader->setUniform("ModelTransform", transform);
@@ -163,7 +157,7 @@ void RenderableDataPlane::render(const RenderData& data)
glBindVertexArray(_quad);
glDrawArrays(GL_TRIANGLES, 0, 6);
glEnable(GL_CULL_FACE);
_shader->deactivate();
};
void RenderableDataPlane::update(const UpdateData& data){
@@ -197,8 +191,8 @@ void RenderableDataPlane::createPlane() {
// ============================
// GEOMETRY (quad)
// ============================
const GLfloat x = _modelScale.x;
const GLfloat y = _modelScale.y;
const GLfloat x = _modelScale.x/2.0;
const GLfloat y = _modelScale.y/2.0;
const GLfloat w = _modelScale.w;
const GLfloat vertex_data[] = { // square of two triangles (sigh)
// x y z w s t

View File

@@ -35,10 +35,7 @@ Fragment getFragment() {
vec4 position = vs_position;
float depth = pscDepth(position);
vec4 diffuse;
if(gl_FrontFacing)
diffuse = texture(texture1, vs_st);
else
diffuse = texture(texture1, vec2(1-vs_st.s,vs_st.t));
diffuse = texture(texture1, vs_st);
//vec4 diffuse = vec4(1,vs_st,1);
//vec4 diffuse = vec4(1,0,0,1);
@@ -46,7 +43,7 @@ Fragment getFragment() {
// diffuse = vec4(1,0,0,1);
// }
if (diffuse.a == 0.0)
if (diffuse.r <= 0.1)
discard;
Fragment frag;

View File

@@ -374,7 +374,7 @@ float* KameleonWrapper::getUniformSliceValues(
float* data = new float[size];
double* doubleData = new double[size];
//_model->loadVariable(var);
_model->loadVariable(var);
double varMin = _model->getVariableAttribute(var, "actual_min").getAttributeFloat();
double varMax = _model->getVariableAttribute(var, "actual_max").getAttributeFloat();
@@ -387,41 +387,52 @@ float* KameleonWrapper::getUniformSliceValues(
double maxValue=0.0;
double minValue=10000.0;
float missingValue = _model->getMissingValue();
for (int x = 0; x < outDimensions.x; ++x) {
for (int y = 0; y < outDimensions.y; ++y) {
unsigned int index = static_cast<unsigned int>(x + y*outDimensions.x);
double xPos = _xMin + stepX*x;
double xPos = _xMax - stepX*x;
double yPos = _yMin + stepY*y;
double zPos = (_zMin + (_zMax-_zMin)*zSlice);
// Should y and z be flipped?
double value = _interpolator->interpolate(
var,
static_cast<float>(-xPos),
static_cast<float>(xPos),
static_cast<float>(yPos),
static_cast<float>(zPos));
doubleData[index] = value;
if(value > maxValue){
maxValue = value;
if(value != missingValue){
doubleData[index] = value;
if(value > maxValue){
maxValue = value;
}
if(value < minValue){
minValue = value;
}
}else{
std::cout << "value missing" << std::endl;
doubleData[index] = 0;
}
if(value < minValue){
minValue = value;
}
//std::cout << "x: " << xPos << " y: " << yPos << " z: " << zPos << " val: " << value << std::endl;
}
}
for(size_t i = 0; i < size; ++i) {
//double normalizedVal = (doubleData[i]-varMin)/(varMax-varMin);
// std::cout << varMin << ", " << varMax << ", " << minValue << ", " << maxValue << ", " << doubleData[i] << ", ";
// double normalizedVal = (doubleData[i]-varMin)/(varMax-varMin);
double normalizedVal = (doubleData[i]-minValue)/(maxValue-minValue);
// std::cout << normalizedVal << ", ";
data[i] = glm::clamp(normalizedVal, 0.0, 1.0);
// std::cout << data[i] << " ";
}
delete[] doubleData;
std::cout << std::endl << std::endl;
// return doubleData;
return data;
}
@@ -612,6 +623,10 @@ glm::vec3 KameleonWrapper::getModelBarycenterOffset() {
offset.x = _xMin+(std::abs(_xMin)+std::abs(_xMax))/2.0f;
offset.y = _yMin+(std::abs(_yMin)+std::abs(_yMax))/2.0f;
offset.z = _zMin+(std::abs(_zMin)+std::abs(_zMax))/2.0f;
std::cout << "_x_Min: " << _xMin << ", _xMax:" << _xMax << std::endl;
std::cout << "_y_Min: " << _yMin << ", _yMax:" << _yMax << std::endl;
std::cout << "_z_Min: " << _zMin << ", _zMax:" << _zMax << std::endl;
std::cout << "offset: " << offset.x << ", " << offset.y << ", " << offset.z << std::endl;
return offset;
}