Stream data

This commit is contained in:
Sebastian Piwell
2016-04-19 09:07:17 -04:00
parent 02c2ee9ef6
commit 4d487fc810
5 changed files with 59 additions and 68 deletions

View File

@@ -49,6 +49,7 @@ DataPlane::DataPlane(const ghoul::Dictionary& dictionary)
,_tfValues("tfValues", "TF Values", glm::vec2(0.5,0.1), glm::vec2(0), glm::vec2(1))
,_colorbar(nullptr)
,_futureData(nullptr)
,_dataSlice(nullptr)
{
_id = id();
setName("DataPlane" + std::to_string(_id));
@@ -58,7 +59,7 @@ DataPlane::DataPlane(const ghoul::Dictionary& dictionary)
// addProperty(_botColor);
// addProperty(_tfValues);
// registerProperties();
registerProperties();
// OsEng.gui()._iSWAproperty.registerProperty(&_topColor);
// OsEng.gui()._iSWAproperty.registerProperty(&_midColor);
// OsEng.gui()._iSWAproperty.registerProperty(&_botColor);
@@ -118,6 +119,7 @@ bool DataPlane::deinitialize(){
destroyShader();
// _kw = nullptr;
_texture = nullptr;
_memorybuffer = "";
// _colorbar->deinitialize();
@@ -227,63 +229,68 @@ void DataPlane::update(const UpdateData& data){
}
}
void DataPlane::loadTexture() {
std::stringstream ss(_memorybuffer);
std::string line;
void DataPlane::loadTexture() {
if(!_memorybuffer.empty()){
std::stringstream ss(_memorybuffer);
std::string line;
_dimensions = glm::size3_t(61, 61, 1);
float* values = new float[3721];
int i = 0;
ss >> std::ws;
// _dimensions = glm::size3_t(61, 61, 1);
float* values = new float[3721];
// for(int i=0; i<3721; i++){
// values[i] = 0.0f;
// }
int i = 0;
ss >> std::ws;
float min = std::numeric_limits<float>::max();
float max = std::numeric_limits<float>::min();
float min = std::numeric_limits<float>::max();
float max = std::numeric_limits<float>::min();
while(getline(ss,line)){
if(line.find("#") == 0){
// std::cout << line << std::endl;
continue;
while(getline(ss,line)){
if(line.find("#") == 0){
// std::cout << line << std::endl;
continue;
}
float x, y, z, N, V, B;
std::stringstream sl(line);
sl >> std::ws >> x >> y >> z >> N >> V >> B;
values[i] = N;
// std::cout << N << ", ";
min = std::min(min,values[i]);
max = std::max(max,values[i]);
i++;
}
float x, y, z, N, V, B;
std::stringstream sl(line);
// std::cout << min << ", " << max << std::endl;
for(int j=0; j<i; j++){
float normValue = (values[j]-min)/(max-min);
values[j] = glm::clamp(normValue, 0.0f, 1.0f);
}
sl >> std::ws >> x >> y >> z >> N >> V >> B;
values[i] = N;
if (!_texture) {
ghoul::opengl::Texture::FilterMode filtermode = ghoul::opengl::Texture::FilterMode::Linear;
ghoul::opengl::Texture::WrappingMode wrappingmode = ghoul::opengl::Texture::WrappingMode::ClampToEdge;
min = std::min(min,values[i]);
max = std::max(max,values[i]);
std::unique_ptr<ghoul::opengl::Texture> texture =
std::make_unique<ghoul::opengl::Texture>(values,glm::size3_t(61, 61, 1), ghoul::opengl::Texture::Format::Red, GL_RED, GL_FLOAT, filtermode, wrappingmode);
i++;
}
std::cout << min << ", " << max << std::endl;
for(int j=0; j<i; j++){
float normValue = (values[j]-min)/(max-min);
values[j] = glm::clamp(normValue, 0.0f, 1.0f);
}
_dataSlice = values;
ghoul::opengl::Texture::FilterMode filtermode = ghoul::opengl::Texture::FilterMode::Linear;
ghoul::opengl::Texture::WrappingMode wrappingmode = ghoul::opengl::Texture::WrappingMode::ClampToEdge;
std::unique_ptr<ghoul::opengl::Texture> texture =
std::make_unique<ghoul::opengl::Texture>(_dataSlice, _dimensions, ghoul::opengl::Texture::Format::Red, GL_RED, GL_FLOAT, filtermode, wrappingmode);
if (texture) {
// LDEBUG("Loaded texture from '" << absPath(_path) << "'");
texture->uploadTexture();
// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
_texture = std::move(texture);
if(texture){
texture->uploadTexture();
texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
_texture = std::move(texture);
}
}else{
_texture->setPixelData(values);
_texture->uploadTexture();
}
}
}
void DataPlane::updateTexture(){
_memorybuffer = "";
std::shared_ptr<DownloadManager::FileFuture> future = ISWAManager::ref().downloadDataToMemory(2, _memorybuffer);
if(future){

View File

@@ -59,6 +59,8 @@ class DataPlane : public CygnetPlane {
float* _dataSlice;
std::string _var;
std::shared_ptr<float> _values;
std::shared_ptr<ColorBar> _colorbar;
std::shared_ptr<DownloadManager::FileFuture> _futureData;
};

View File

@@ -32,7 +32,7 @@ namespace openspace{
ISWACygnet::ISWACygnet(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
, _updateInterval("updateInterval", "Update Interval", 3, 1, 10)
, _updateInterval("updateInterval", "Update Interval", 0.35, 0.1 , 1.0)
, _delete("delete", "Delete")
, _shader(nullptr)
, _texture(nullptr)

View File

@@ -171,9 +171,9 @@ namespace openspace{
_metaFutures.push_back(extFuture);
}
else {
std::shared_ptr<MetadataFuture> extFuture = downloadMetadata(-2);
std::shared_ptr<MetadataFuture> extFuture = downloadMetadata(-1);
extFuture->type = "DATA";
extFuture->id = -2;
extFuture->id = -1;
// std::shared_ptr<Metadata> mdata = std::make_shared<Metadata>();
// mdata->id = 0;
// mdata->path = absPath("${OPENSPACE_DATA}/"+info);
@@ -229,7 +229,6 @@ namespace openspace{
if(file.is_open()){
std::string json( (std::istreambuf_iterator<char>(file) ),
(std::istreambuf_iterator<char>()));
// std::cout << "This is in the file: " << json << std::endl;
metaFuture->isFinished = true;
metaFuture->json = json;
}
@@ -300,9 +299,6 @@ namespace openspace{
std::stringstream ss(t);
std::string token;
http://localhost:3000/data/1/2029-07-14%2010:00:00
// http://128.183.168.116:3000/data/1/2996-01-23%2000:44:00
std::getline(ss, token, ' ');
url += token + "-";
std::getline(ss, token, ' ');
@@ -438,20 +434,6 @@ namespace openspace{
spatScale*(zmin + (std::abs(zmin)+std::abs(zmax))/2.0f),
scalew
);
// std::string scale = "{"
// + std::to_string(spatScale*(xmax-xmin)) + ","
// + std::to_string(spatScale*(ymax-ymin)) + ","
// + std::to_string(spatScale*(zmax-zmin)) + ","
// + std::to_string(scalew) +
// "}";
// std::string offset ="{"
// + std::to_string(spatScale*(xmin + (std::abs(xmin)+std::abs(xmax))/2.0f)) + ","
// + std::to_string(spatScale*(ymin + (std::abs(ymin)+std::abs(ymax))/2.0f)) + ","
// + std::to_string(spatScale*(zmin + (std::abs(zmin)+std::abs(zmax))/2.0f)) + ","
// + std::to_string(scalew) +
// "}";
std::string table = "{"
"Name = 'TexturePlane "+ std::to_string(id) +"' , "