From 78b827d9d63491cb2d83343094ed421ae17f275e Mon Sep 17 00:00:00 2001 From: Sebastian Piwell Date: Wed, 15 Jun 2016 10:32:59 -0400 Subject: [PATCH 01/14] Histogram with standard score normalization --- modules/iswa/util/dataprocessor.cpp | 76 ++++++++++++++++++----------- modules/iswa/util/dataprocessor.h | 4 +- src/util/histogram.cpp | 20 ++++---- 3 files changed, 60 insertions(+), 40 deletions(-) diff --git a/modules/iswa/util/dataprocessor.cpp b/modules/iswa/util/dataprocessor.cpp index 29cd05a358..6cd3f7f370 100644 --- a/modules/iswa/util/dataprocessor.cpp +++ b/modules/iswa/util/dataprocessor.cpp @@ -48,6 +48,7 @@ DataProcessor::DataProcessor() ,_useHistogram(false) ,_normValues(glm::vec2(1.0)) ,_filterValues(glm::vec2(0.0)) + ,_histNormValues(glm::vec2(10.f, 10.f)) { _coordinateVariables = {"x", "y", "z", "phi", "theta"}; } @@ -90,20 +91,21 @@ float DataProcessor::processDataPoint(float value, int option){ float mean = (1.0 / _numValues[option]) * _sum[option]; float sd = _standardDeviation[option]; + float v; if(_useHistogram){ - sd = histogram->equalize(sd); - mean = histogram->equalize(mean); - value = histogram->equalize(value); + v = histogram->equalize(normalizeWithStandardScore(value, mean, sd, _histNormValues))/(float)512; + }else{ + v = normalizeWithStandardScore(value, mean, sd, _normValues); } - float v = normalizeWithStandardScore(value, mean, sd); + // float v = normalizeWithStandardScore(value, mean, sd, _normValues); return v; } -float DataProcessor::normalizeWithStandardScore(float value, float mean, float sd){ +float DataProcessor::normalizeWithStandardScore(float value, float mean, float sd, glm::vec2 normalizationValues){ - float zScoreMin = _normValues.x; - float zScoreMax = _normValues.y; + float zScoreMin = normalizationValues.x; //10.0f;//_normValues.x; + float zScoreMax = normalizationValues.y; //10.0f;//_normValues.y; float standardScore = ( value - mean ) / sd; // Clamp intresting values standardScore = glm::clamp(standardScore, -zScoreMin, zScoreMax); @@ -130,22 +132,24 @@ void DataProcessor::calculateFilterValues(std::vector selectedOptions){ if(!_histograms.empty()){ for(int option : selectedOptions){ - histogram = _histograms[option]; - mean = (1.0/_numValues[option])*_sum[option]; - standardDeviation = _standardDeviation[option]; - - filterMid = histogram->highestBinValue(_useHistogram); - filterWidth = mean+histogram->binWidth(); - - if(_useHistogram){ - standardDeviation = histogram->equalize(standardDeviation); - mean = histogram->equalize(mean); - filterWidth = mean+1; + if(!_useHistogram){ + mean = (1.0/_numValues[option])*_sum[option]; + standardDeviation = _standardDeviation[option]; + histogram = _histograms[option]; + + filterMid = histogram->highestBinValue(_useHistogram); + filterWidth = mean+histogram->binWidth(); + + filterMid = normalizeWithStandardScore(filterMid, mean, standardDeviation, _normValues); + filterWidth = fabs(0.5-normalizeWithStandardScore(filterWidth, mean, standardDeviation, _normValues)); + }else{ + Histogram hist = _histograms[option]->equalize(); + filterMid = hist.highestBinValue(true); + std::cout << filterMid << std::endl; + filterWidth = 1.f/512.f; } - filterMid = normalizeWithStandardScore(filterMid, mean, standardDeviation); - filterWidth = fabs(0.5-normalizeWithStandardScore(filterWidth, mean, standardDeviation)); - _filterValues += glm::vec2(filterMid, filterWidth); + _filterValues += glm::vec2(filterMid, filterWidth); } _filterValues /= numSelected; @@ -158,12 +162,6 @@ void DataProcessor::add(std::vector>& optionValues, std::vect float mean, value, variance, standardDeviation; for(int i=0; i(_min[i], _max[i], 512); - } - else{ - _histograms[i]->changeRange(_min[i], _max[i]); - } std::vector values = optionValues[i]; numValues = values.size(); @@ -174,7 +172,6 @@ void DataProcessor::add(std::vector>& optionValues, std::vect for(int j=0; jadd(value, 1); } standardDeviation = sqrt(variance/ numValues); @@ -182,9 +179,30 @@ void DataProcessor::add(std::vector>& optionValues, std::vect _sum[i] += sum[i]; _standardDeviation[i] = sqrt(pow(standardDeviation, 2) + pow(_standardDeviation[i], 2)); _numValues[i] += numValues; + + float min = normalizeWithStandardScore(_min[i], mean, _standardDeviation[i], _histNormValues); + float max = normalizeWithStandardScore(_max[i], mean, _standardDeviation[i], _histNormValues); + + if(!_histograms[i]){ + _histograms[i] = std::make_shared(min, max, 512); + } + else{ + _histograms[i]->changeRange(min, max); + } + + for(int j=0; jadd(normalizeWithStandardScore(value, mean, _standardDeviation[i], _histNormValues), 1); + } _histograms[i]->generateEqualizer(); - // _histograms[i]->print(); + + std::cout << std::endl; + _histograms[i]->print(); + std::cout << std::endl; + std::cout << "Eq: "; + Histogram hist = _histograms[i]->equalize(); + hist.print(); } } diff --git a/modules/iswa/util/dataprocessor.h b/modules/iswa/util/dataprocessor.h index fb2be89c71..9cca43eef7 100644 --- a/modules/iswa/util/dataprocessor.h +++ b/modules/iswa/util/dataprocessor.h @@ -53,7 +53,7 @@ public: void clear(); protected: float processDataPoint(float value, int option); - float normalizeWithStandardScore(float value, float mean, float sd); + float normalizeWithStandardScore(float value, float mean, float sd, glm::vec2 normalizationValues = glm::vec2(1.0f, 1.0f)); void initializeVectors(int numOptions); void calculateFilterValues(std::vector selectedOptions); @@ -72,6 +72,8 @@ protected: std::vector _numValues; std::vector> _histograms; std::set _coordinateVariables; + + glm::vec2 _histNormValues; }; } // namespace openspace diff --git a/src/util/histogram.cpp b/src/util/histogram.cpp index 94a8a83718..31600c1b0b 100644 --- a/src/util/histogram.cpp +++ b/src/util/histogram.cpp @@ -296,14 +296,16 @@ float Histogram::entropy(){ } void Histogram::print() const { - std::cout << "number of bins: " << _numBins << std::endl - << "range: " << _minValue << " - " << _maxValue << std::endl << std::endl; + // std::cout << "number of bins: " << _numBins << std::endl + // << "range: " << _minValue << " - " << _maxValue << std::endl << std::endl; for (int i = 0; i < _numBins; i++) { float low = _minValue + float(i) / _numBins * (_maxValue - _minValue); float high = low + (_maxValue - _minValue) / float(_numBins); - std::cout << i << " [" << low << ", " << high << "]" - << " " << _data[i] << std::endl; + // std::cout << i << " [" << low << ", " << high << "]" + // << " " << _data[i] << std::endl; + std::cout << _data[i]/(float)_numValues << ", "; } + std::cout << std::endl; // std::cout << std::endl << std::endl << std::endl<< "==============" << std::endl; } @@ -332,18 +334,16 @@ float Histogram::highestBinValue(bool equalized, int overBins){ highestBin = i; highestValue = value; } - - // if(_data[i] > _data[highestBin]) - // highestBin = i; } - float low = _minValue + float(highestBin) / _numBins * (_maxValue - _minValue); - float high = low + (_maxValue - _minValue) / float(_numBins); if(!equalized){ + float low = _minValue + float(highestBin) / _numBins * (_maxValue - _minValue); + float high = low + (_maxValue - _minValue) / float(_numBins); return (high+low)/2.0; }else{ - return equalize((high+low)/2.0); + return highestBin/(float)_numBins; + // return equalize((high+low)/2.0); } } From 6573a6dfce51ab898bfbe6ddcbe16f4c92562930 Mon Sep 17 00:00:00 2001 From: Michael Nilsson Date: Wed, 15 Jun 2016 11:07:20 -0400 Subject: [PATCH 02/14] add heroku baseurl and key bindings --- config/sgct/single_fisheye.xml | 7 ++++++- modules/iswa/util/iswamanager.cpp | 23 +++++++++++++++++------ modules/iswa/util/iswamanager.h | 1 + modules/iswa/util/iswamanager_lua.inl | 6 ++++++ scripts/bind_keys.lua | 6 ++++++ 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/config/sgct/single_fisheye.xml b/config/sgct/single_fisheye.xml index 893a18a853..b72758eb6c 100644 --- a/config/sgct/single_fisheye.xml +++ b/config/sgct/single_fisheye.xml @@ -1,5 +1,10 @@ + @@ -20,7 +25,7 @@ - + diff --git a/modules/iswa/util/iswamanager.cpp b/modules/iswa/util/iswamanager.cpp index 92a36db128..2c09988a24 100644 --- a/modules/iswa/util/iswamanager.cpp +++ b/modules/iswa/util/iswamanager.cpp @@ -51,6 +51,8 @@ namespace { using json = nlohmann::json; const std::string _loggerCat = "IswaManager"; + std::string baseUrl = "https://iswa-demo-server.herokuapp.com/"; + //const std::string baseUrl = "http://128.183.168.116:3000/"; } namespace openspace{ @@ -145,8 +147,7 @@ void IswaManager::addIswaCygnet(int id, std::string type, std::string group){ // Download metadata DlManager.fetchFile( - "http://128.183.168.116:3000/" + std::to_string(-id), - // "http://localhost:3000/" + std::to_string(-id), + baseUrl + std::to_string(-id), metadataCallback, [id](const std::string& err){ LDEBUG("Download to memory was aborted for data cygnet with id "+ std::to_string(id)+": " + err); @@ -195,8 +196,7 @@ std::future IswaManager::fetchDataCygnet(int id, do std::string IswaManager::iswaUrl(int id, double timestamp, std::string type){ std::string url; if(id < 0){ - url = "http://128.183.168.116:3000/"+type+"/" + std::to_string(-id) + "/"; - // url = "http://localhost:3000/"+type+"/" + std::to_string(-id) + "/"; + url = baseUrl+type+"/" + std::to_string(-id) + "/"; } else{ url = "http://iswa3.ccmc.gsfc.nasa.gov/IswaSystemWebApp/iSWACygnetStreamer?window=-1&cygnetId="+ std::to_string(id) +"×tamp="; } @@ -262,8 +262,7 @@ std::shared_ptr IswaManager::downloadMetadata(int id){ metaFuture->id = id; DlManager.fetchFile( - "http://128.183.168.116:3000/" + std::to_string(-id), - // "http://localhost:3000/" + std::to_string(-id), + baseUrl + std::to_string(-id), [&metaFuture](const DownloadManager::MemoryFile& file){ metaFuture->json = std::string(file.buffer, file.size); metaFuture->isFinished = true; @@ -648,6 +647,11 @@ void IswaManager::addCdfFiles(std::string path){ } } +void IswaManager::setBaseUrl(std::string bUrl){ + LDEBUG("Swapped baseurl to: " + bUrl); + baseUrl = bUrl; +} + scripting::ScriptEngine::LuaLibrary IswaManager::luaLibrary() { return { "iswa", @@ -707,6 +711,13 @@ scripting::ScriptEngine::LuaLibrary IswaManager::luaLibrary() { "int", "Remove a group of Cygnets", true + }, + { + "setBaseUrl", + &luascriptfunctions::iswa_setBaseUrl, + "string", + "sets the base url", + true } } }; diff --git a/modules/iswa/util/iswamanager.h b/modules/iswa/util/iswamanager.h index a88e080576..bab50f2deb 100644 --- a/modules/iswa/util/iswamanager.h +++ b/modules/iswa/util/iswamanager.h @@ -106,6 +106,7 @@ public: } void addCdfFiles(std::string path); + void setBaseUrl(std::string bUrl); private: std::shared_ptr downloadMetadata(int id); std::string jsonPlaneToLuaTable(std::shared_ptr data); diff --git a/modules/iswa/util/iswamanager_lua.inl b/modules/iswa/util/iswamanager_lua.inl index 8e44701ca5..fa46ff0c27 100644 --- a/modules/iswa/util/iswamanager_lua.inl +++ b/modules/iswa/util/iswamanager_lua.inl @@ -164,6 +164,12 @@ int iswa_addKameleonPlanes(lua_State* L){ return 0; } +int iswa_setBaseUrl(lua_State* L){ + std::string url = luaL_checkstring(L, 1); + IswaManager::ref().setBaseUrl(url); + return 0; +} + }// namespace luascriptfunctions }// namespace openspace \ No newline at end of file diff --git a/scripts/bind_keys.lua b/scripts/bind_keys.lua index be68aeff20..3dba610ecf 100644 --- a/scripts/bind_keys.lua +++ b/scripts/bind_keys.lua @@ -16,3 +16,9 @@ openspace.bindKey("e", helper.renderable.toggle('EarthMarker')) openspace.bindKey("x", helper.renderable.toggle('Constellation Bounds')) openspace.bindKey("c", "openspace.parallel.setAddress('130.236.142.51');openspace.parallel.setPassword('newhorizons-20150714');openspace.parallel.connect();") + +openspace.bindKey("h", "openspace.iswa.setBaseUrl('https://iswa-demo-server.herokuapp.com/')"); +openspace.bindKey("g", "openspace.iswa.setBaseUrl('http://128.183.168.116:3000/')"); +openspace.bindKey("l", "openspace.iswa.setBaseUrl('http://localhost:3000/')"); + +openspace.bindKey("v", "openspace.time.setTime('2015-03-15T02:00:00.00')"); \ No newline at end of file From 1ef3c035e369ce163c7e271d61a8f67c528f7516 Mon Sep 17 00:00:00 2001 From: Sebastian Piwell Date: Wed, 15 Jun 2016 11:49:36 -0400 Subject: [PATCH 03/14] Renormalize values in the histogram correctly --- modules/iswa/util/dataprocessor.cpp | 45 ++++++++++++++++++++++++++++- modules/iswa/util/dataprocessor.h | 1 + 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/modules/iswa/util/dataprocessor.cpp b/modules/iswa/util/dataprocessor.cpp index 6cd3f7f370..8bb5ef817c 100644 --- a/modules/iswa/util/dataprocessor.cpp +++ b/modules/iswa/util/dataprocessor.cpp @@ -113,6 +113,22 @@ float DataProcessor::normalizeWithStandardScore(float value, float mean, float s return ( standardScore + zScoreMin )/(zScoreMin + zScoreMax ); } +float DataProcessor::unnormalizeWithStandardScore(float standardScore, float mean, float sd, glm::vec2 normalizationValues){ + float zScoreMin = normalizationValues.x; + float zScoreMax = normalizationValues.y; + + float value = standardScore*(zScoreMax+zScoreMin)-zScoreMin; + value = value*sd+mean; + + // std::cout << value << std::endl; + return value; + // float standardScore = ( value - mean ) / sd; + // // Clamp intresting values + // standardScore = glm::clamp(standardScore, -zScoreMin, zScoreMax); + // //return and normalize + // return ( standardScore + zScoreMin )/(zScoreMin + zScoreMax ); +} + void DataProcessor::initializeVectors(int numOptions){ if(_min.empty()) _min = std::vector(numOptions, std::numeric_limits::max()); if(_max.empty()) _max = std::vector(numOptions, std::numeric_limits::min()); @@ -176,10 +192,15 @@ void DataProcessor::add(std::vector>& optionValues, std::vect standardDeviation = sqrt(variance/ numValues); + float oldStandardDeviation = _standardDeviation[i]; + float oldMean = (1.0f/_numValues[i])*_sum[i]; + _sum[i] += sum[i]; _standardDeviation[i] = sqrt(pow(standardDeviation, 2) + pow(_standardDeviation[i], 2)); _numValues[i] += numValues; + + mean = (1.0f/_numValues[i])*_sum[i]; float min = normalizeWithStandardScore(_min[i], mean, _standardDeviation[i], _histNormValues); float max = normalizeWithStandardScore(_max[i], mean, _standardDeviation[i], _histNormValues); @@ -187,7 +208,29 @@ void DataProcessor::add(std::vector>& optionValues, std::vect _histograms[i] = std::make_shared(min, max, 512); } else{ - _histograms[i]->changeRange(min, max); + + const float* histData = _histograms[i]->data(); + float histMin = _histograms[i]->minValue(); + float histMax = _histograms[i]->maxValue(); + int numBins = _histograms[i]->numBins(); + + float unNormHistMin = unnormalizeWithStandardScore(histMin, oldMean, oldStandardDeviation, _histNormValues); + float unNormHistMax = unnormalizeWithStandardScore(histMax, oldMean, oldStandardDeviation, _histNormValues); + //unnormalize histMin, histMax + // min = std::min(min, histMin) + std::shared_ptr newHist = std::make_shared( + std::min(min, normalizeWithStandardScore(unNormHistMin, mean, _standardDeviation[i], _histNormValues)), + std::min(max, normalizeWithStandardScore(unNormHistMax, mean, _standardDeviation[i], _histNormValues)), + numBins + ); + + for(int j=0; jadd(normalizeWithStandardScore(value, mean, _standardDeviation[i], _histNormValues), histData[j]); + } + // _histograms[i]->changeRange(min, max); + _histograms[i] = newHist; } for(int j=0; j selectedOptions); From db375d310ecada6fb72650ae951dbc5032dc5ca9 Mon Sep 17 00:00:00 2001 From: Sebastian Piwell Date: Wed, 15 Jun 2016 13:42:26 -0400 Subject: [PATCH 04/14] Update kameleonlpane when sliding --- modules/iswa/rendering/kameleonplane.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/iswa/rendering/kameleonplane.cpp b/modules/iswa/rendering/kameleonplane.cpp index 36b63a9429..2779cdf3ae 100644 --- a/modules/iswa/rendering/kameleonplane.cpp +++ b/modules/iswa/rendering/kameleonplane.cpp @@ -222,8 +222,8 @@ std::vector KameleonPlane::textureData() { bool KameleonPlane::updateTextureResource(){ _data->offset[_cut] = _data->gridMin[_cut]+_slice.value()*_scale; - _textureDirty = true; - + // _textureDirty = true; + updateTexture(); return true; } From 9c83dc1135330627b23347223d74774854e6b547 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Wed, 15 Jun 2016 22:59:16 +0200 Subject: [PATCH 05/14] Make TransformationManager work without Kameleon module --- src/util/transformationmanager.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/util/transformationmanager.cpp b/src/util/transformationmanager.cpp index eee4aefb48..0838c1318c 100644 --- a/src/util/transformationmanager.cpp +++ b/src/util/transformationmanager.cpp @@ -54,6 +54,7 @@ std::string to, double ephemerisTime) const { +#ifdef OPENSPACE_MODULE_KAMELEON_ENABLED ccmc::Position in0 = {1.f, 0.f, 0.f}; ccmc::Position in1 = {0.f, 1.f, 0.f}; ccmc::Position in2 = {0.f, 0.f, 1.f}; @@ -70,7 +71,10 @@ out0.c0 , out0.c1 , out0.c2, out1.c0 , out1.c1 , out1.c2, out2.c0 , out2.c1 , out2.c2 - );; + ); +#else + return glm::dmat3(0.0); +#endif } glm::dmat3 TransformationManager::frameTransformationMatrix(std::string from, From 1fb0b40563a4d115454b9728c7abe396fc28fff1 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 16 Jun 2016 00:08:47 +0200 Subject: [PATCH 06/14] Rename cygnetplane to textureplane in CMakeLists --- modules/iswa/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/iswa/CMakeLists.txt b/modules/iswa/CMakeLists.txt index a745fdb920..fabe24c7c9 100644 --- a/modules/iswa/CMakeLists.txt +++ b/modules/iswa/CMakeLists.txt @@ -65,10 +65,10 @@ set(SOURCE_FILES source_group("Source Files" FILES ${SOURCE_FILES}) set(SHADER_FILES - ${CMAKE_CURRENT_SOURCE_DIR}/shaders/cygnetplane_fs.glsl - ${CMAKE_CURRENT_SOURCE_DIR}/shaders/cygnetplane_vs.glsl ${CMAKE_CURRENT_SOURCE_DIR}/shaders/dataplane_fs.glsl ${CMAKE_CURRENT_SOURCE_DIR}/shaders/dataplane_vs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/textureplane_fs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/tetureplane_vs.glsl ) source_group("Shader Files" FILES ${SHADER_FILES}) From d03d484f407bd364a1045d3864d8c3291d342518 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 16 Jun 2016 00:12:22 +0200 Subject: [PATCH 07/14] Actually spell textureplane correctly --- modules/iswa/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/iswa/CMakeLists.txt b/modules/iswa/CMakeLists.txt index fabe24c7c9..c97f1dd0c3 100644 --- a/modules/iswa/CMakeLists.txt +++ b/modules/iswa/CMakeLists.txt @@ -68,7 +68,7 @@ set(SHADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/shaders/dataplane_fs.glsl ${CMAKE_CURRENT_SOURCE_DIR}/shaders/dataplane_vs.glsl ${CMAKE_CURRENT_SOURCE_DIR}/shaders/textureplane_fs.glsl - ${CMAKE_CURRENT_SOURCE_DIR}/shaders/tetureplane_vs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/textureplane_vs.glsl ) source_group("Shader Files" FILES ${SHADER_FILES}) From 7548b5654bdaaaaf171a8a27b894f0015167351f Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 16 Jun 2016 00:24:03 +0200 Subject: [PATCH 08/14] Make iSWA module dependent on Kameleon --- modules/iswa/include.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/iswa/include.cmake b/modules/iswa/include.cmake index 36d16a0e90..4569df0ac7 100644 --- a/modules/iswa/include.cmake +++ b/modules/iswa/include.cmake @@ -1,3 +1,3 @@ set (OPENSPACE_DEPENDENCIES - base + base kameleon ) \ No newline at end of file From f38b8856c1fdb43ad8078b0b4ae2f79989d7acb2 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 16 Jun 2016 00:32:47 +0200 Subject: [PATCH 09/14] Updated Ghoul version --- ext/ghoul | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/ghoul b/ext/ghoul index 9bb5ce6bf4..53fe2859c3 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 9bb5ce6bf45478f933189b98ef05dac17d8a6739 +Subproject commit 53fe2859c3b7f096d28367af9445eedb0f1bbd76 From 5cc278c97f0e982181bf6cf18dc9b37bc0ec55af Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 16 Jun 2016 00:57:31 +0200 Subject: [PATCH 10/14] Add ModelMatrix retrieval to WindowWrapper --- include/openspace/engine/wrapper/sgctwindowwrapper.h | 1 + include/openspace/engine/wrapper/windowwrapper.h | 7 +++++++ src/engine/wrapper/sgctwindowwrapper.cpp | 4 ++++ src/engine/wrapper/windowwrapper.cpp | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/include/openspace/engine/wrapper/sgctwindowwrapper.h b/include/openspace/engine/wrapper/sgctwindowwrapper.h index 6a1c170dd0..3b19931658 100644 --- a/include/openspace/engine/wrapper/sgctwindowwrapper.h +++ b/include/openspace/engine/wrapper/sgctwindowwrapper.h @@ -51,6 +51,7 @@ public: bool isRegularRendering() const override; glm::mat4 viewProjectionMatrix() const override; + glm::mat4 modelMatrix() const override; void setNearFarClippingPlane(float near, float far) override; glm::ivec4 viewportPixelCoordinates() const override; diff --git a/include/openspace/engine/wrapper/windowwrapper.h b/include/openspace/engine/wrapper/windowwrapper.h index d20f5339db..5cc4e430e9 100644 --- a/include/openspace/engine/wrapper/windowwrapper.h +++ b/include/openspace/engine/wrapper/windowwrapper.h @@ -131,6 +131,13 @@ public: * \return The currently employed view-projection matrix */ virtual glm::mat4 viewProjectionMatrix() const; + + /** + * Returns the currently employed model matrix. On default, this method will return + * the identity matrix. + * \return The currently employed model matrix + */ + virtual glm::mat4 modelMatrix() const; /** * Sets the near and far clipping planes of the rendering window. This method defaults diff --git a/src/engine/wrapper/sgctwindowwrapper.cpp b/src/engine/wrapper/sgctwindowwrapper.cpp index b3a3134a22..f566276a39 100644 --- a/src/engine/wrapper/sgctwindowwrapper.cpp +++ b/src/engine/wrapper/sgctwindowwrapper.cpp @@ -115,6 +115,10 @@ bool SGCTWindowWrapper::isRegularRendering() const { glm::mat4 SGCTWindowWrapper::viewProjectionMatrix() const { return sgct::Engine::instance()->getCurrentModelViewProjectionMatrix(); } + +glm::mat4 SGCTWindowWrapper::modelMatrix() const { + return sgct::Engine::instance()->getModelMatrix(); +} void SGCTWindowWrapper::setNearFarClippingPlane(float nearPlane, float farPlane) { sgct::Engine::instance()->setNearAndFarClippingPlanes(nearPlane, farPlane); diff --git a/src/engine/wrapper/windowwrapper.cpp b/src/engine/wrapper/windowwrapper.cpp index 8283edf577..17344d9f8a 100644 --- a/src/engine/wrapper/windowwrapper.cpp +++ b/src/engine/wrapper/windowwrapper.cpp @@ -75,6 +75,10 @@ bool WindowWrapper::isRegularRendering() const { glm::mat4 WindowWrapper::viewProjectionMatrix() const { return glm::mat4(1.f); } + +glm::mat4 WindowWrapper::modelMatrix() const { + return glm::mat4(1.f); +} void WindowWrapper::setNearFarClippingPlane(float near, float far) {} From 4fc838cbaf010a124881f83a262d4b853e139796 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 16 Jun 2016 00:58:31 +0200 Subject: [PATCH 11/14] Compile fix for missing Boost --- modules/iswa/util/dataprocessortext.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/iswa/util/dataprocessortext.cpp b/modules/iswa/util/dataprocessortext.cpp index 552c36d664..de2a19e7f4 100644 --- a/modules/iswa/util/dataprocessortext.cpp +++ b/modules/iswa/util/dataprocessortext.cpp @@ -24,13 +24,13 @@ #include #include #include -#include - -#include -#include -#include -#include -#include +//#include +// +//#include +//#include +//#include +//#include +//#include namespace { const std::string _loggerCat = "DataProcessorText"; From ad1893fd6fb068da8ac04cf6d5bb9bc5fa200b90 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 16 Jun 2016 00:59:06 +0200 Subject: [PATCH 12/14] Cleanup of ScreenSpaceRenderable Add missing includes to other files --- .../rendering/screenspacerenderable.h | 81 ++--- .../base/rendering/screenspaceframebuffer.cpp | 1 + modules/base/rendering/screenspaceimage.cpp | 6 + modules/base/rendering/screenspaceimage.h | 2 + modules/base/shaders/screnspace_fs.glsl | 2 +- modules/iswa/rendering/dataplane.cpp | 2 + modules/iswa/rendering/datasphere.cpp | 7 + modules/iswa/rendering/iswabasegroup.cpp | 1 + modules/iswa/rendering/iswacygnet.cpp | 1 + modules/iswa/rendering/iswadatagroup.cpp | 2 + modules/iswa/rendering/iswakameleongroup.cpp | 1 + modules/iswa/rendering/kameleonplane.cpp | 2 + modules/iswa/rendering/screenspacecygnet.cpp | 1 + .../rendering/renderablemodelprojection.cpp | 1 + .../rendering/renderableplanetprojection.cpp | 6 + src/rendering/renderengine.cpp | 13 +- src/rendering/screenspacerenderable.cpp | 324 +++++++++++------- 17 files changed, 269 insertions(+), 184 deletions(-) diff --git a/include/openspace/rendering/screenspacerenderable.h b/include/openspace/rendering/screenspacerenderable.h index d435d6bf7d..e42605990a 100644 --- a/include/openspace/rendering/screenspacerenderable.h +++ b/include/openspace/rendering/screenspacerenderable.h @@ -24,38 +24,33 @@ #ifndef __SCREENSPACERENDERABLE_H__ #define __SCREENSPACERENDERABLE_H__ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include -#ifdef WIN32 -#define _USE_MATH_DEFINES -#include -#endif +#include + +#include +#include +#include + +#include +#include +#include namespace openspace { + /** - * @brief The base class for screen scape images and screen space framebuffers - * @details This base class handles general functionality specific to planes that - * are rendered infront of the camera. It implements protected methods and properties for converting - * the planes from spherical to euclidean coordinates and back. It also specifies the interface - * that it's children needs to implement. + * The base class for screen space images and screen space framebuffers. + * This base class handles general functionality specific to planes that are rendered in + * front of the camera. It implements protected methods and properties for converting + * the planes from Spherical to Euclidean coordinates and back. It also specifies the + * interface that its children need to implement. */ class ScreenSpaceRenderable : public properties::PropertyOwner { public: - static ScreenSpaceRenderable* createFromDictionary(const ghoul::Dictionary& dictionary); + static ScreenSpaceRenderable* createFromDictionary( + const ghoul::Dictionary& dictionary); + ScreenSpaceRenderable(const ghoul::Dictionary& dictionary); - ~ScreenSpaceRenderable(); + virtual ~ScreenSpaceRenderable(); virtual void render() = 0; virtual bool initialize() = 0; @@ -64,31 +59,30 @@ public: virtual bool isReady() const = 0; bool isEnabled() const; - glm::vec2 euclideanPosition() const {return _euclideanPosition.value();}; - glm::vec2 sphericalPosition() const {return _sphericalPosition.value();}; - float depth() const {return _depth.value();}; + glm::vec3 euclideanPosition() const; + glm::vec3 sphericalPosition() const; + float depth() const; protected: void createPlane(); void useEuclideanCoordinates(bool b); /** - * @brief Converts vec2 polar coordinates to euclidean - * - * @param polar the coordinates theta and phi - * @param radius the radius position value of the plane - * - * @return glm::vec2 with the x and y position value of the plane + * Converts Spherical coordinates to Euclidean. + * \param spherical The coordinates theta and phi + * \param radius The radius position value of the plane + * \return The x and y position value of the plane */ - glm::vec2 toEuclidean(glm::vec2 polar, float radius); + glm::vec2 toEuclidean(const glm::vec2& spherical, float radius); /** - * @brief Converts vec2 euclidean coordinates to sperical - * - * @param euclidean the coordinates x and y - * @return glm::vec2 with the spherical coordinates theta and phi. + * Converts Euclidean coordinates to Spherical. + * \param euclidean The coordinates x and y + * \return The spherical coordinates theta and phi. */ - glm::vec2 toSpherical(glm::vec2 euclidean); + glm::vec2 toSpherical(const glm::vec2& euclidean); + + void registerProperties(); void unregisterProperties(); @@ -109,18 +103,15 @@ protected: GLuint _quad; GLuint _vertexPositionBuffer; - const std::string _rendererPath; - ghoul::Dictionary _rendererData; - const std::string _vertexPath; - const std::string _fragmentPath; std::unique_ptr _texture; std::unique_ptr _shader; bool _useEuclideanCoordinates; - const float _planeDepth = -2.0; glm::vec2 _originalViewportSize; float _radius; }; + } // namespace openspace -#endif // __SCREENSPACERENDERABLE_H__ \ No newline at end of file + +#endif // __SCREENSPACERENDERABLE_H__ diff --git a/modules/base/rendering/screenspaceframebuffer.cpp b/modules/base/rendering/screenspaceframebuffer.cpp index 5ceb89176b..6650a7b9ed 100644 --- a/modules/base/rendering/screenspaceframebuffer.cpp +++ b/modules/base/rendering/screenspaceframebuffer.cpp @@ -30,6 +30,7 @@ #include #include #include +#include namespace openspace { ScreenSpaceFramebuffer::ScreenSpaceFramebuffer(const ghoul::Dictionary& dictionary) diff --git a/modules/base/rendering/screenspaceimage.cpp b/modules/base/rendering/screenspaceimage.cpp index 001b579563..2b38c0029e 100644 --- a/modules/base/rendering/screenspaceimage.cpp +++ b/modules/base/rendering/screenspaceimage.cpp @@ -25,6 +25,12 @@ #include #include +#include + +#include +#include +#include + namespace { const std::string _loggerCat = "ScreenSpaceImage"; } diff --git a/modules/base/rendering/screenspaceimage.h b/modules/base/rendering/screenspaceimage.h index 167911b12e..e157f990a7 100644 --- a/modules/base/rendering/screenspaceimage.h +++ b/modules/base/rendering/screenspaceimage.h @@ -28,6 +28,8 @@ #include #include +#include + namespace openspace { /** diff --git a/modules/base/shaders/screnspace_fs.glsl b/modules/base/shaders/screnspace_fs.glsl index 80ab155593..bd72b4a47f 100644 --- a/modules/base/shaders/screnspace_fs.glsl +++ b/modules/base/shaders/screnspace_fs.glsl @@ -39,7 +39,7 @@ Fragment getFragment(){ // power scale coordinates for depth. w value is set to 1.0. float depth = (1.0 + log(abs(OcclusionDepth) + 1/pow(k, 1.0))/log(k)) / 27.0; - frag.color = texture(texture1, vec2(vs_st.s, 1-vs_st.t)); + frag.color = texture(texture1, vec2(vs_st.s, vs_st.t)); frag.color.a = (frag.color.a != 0.0f) ? Alpha : frag.color.a; if(frag.color.a == 0.0f){ discard; diff --git a/modules/iswa/rendering/dataplane.cpp b/modules/iswa/rendering/dataplane.cpp index c1dcfc8774..1ebf8b06a1 100644 --- a/modules/iswa/rendering/dataplane.cpp +++ b/modules/iswa/rendering/dataplane.cpp @@ -24,6 +24,8 @@ #include #include +#include + namespace { const std::string _loggerCat = "DataPlane"; } diff --git a/modules/iswa/rendering/datasphere.cpp b/modules/iswa/rendering/datasphere.cpp index 8184530338..b96b2f7fee 100644 --- a/modules/iswa/rendering/datasphere.cpp +++ b/modules/iswa/rendering/datasphere.cpp @@ -26,6 +26,13 @@ #include #include +#include + +#ifdef WIN32 +#define _USE_MATH_DEFINES +#include +#endif + namespace { const std::string _loggerCat = "DataSphere"; } diff --git a/modules/iswa/rendering/iswabasegroup.cpp b/modules/iswa/rendering/iswabasegroup.cpp index e7fb9de70d..5f3ebd89cd 100644 --- a/modules/iswa/rendering/iswabasegroup.cpp +++ b/modules/iswa/rendering/iswabasegroup.cpp @@ -34,6 +34,7 @@ #include #include +#include namespace { const std::string _loggerCat = "IswaBaseGroup"; diff --git a/modules/iswa/rendering/iswacygnet.cpp b/modules/iswa/rendering/iswacygnet.cpp index a1afa13653..83937b9249 100644 --- a/modules/iswa/rendering/iswacygnet.cpp +++ b/modules/iswa/rendering/iswacygnet.cpp @@ -27,6 +27,7 @@ #include #include #include +#include namespace { diff --git a/modules/iswa/rendering/iswadatagroup.cpp b/modules/iswa/rendering/iswadatagroup.cpp index fbe7bb9723..b780811545 100644 --- a/modules/iswa/rendering/iswadatagroup.cpp +++ b/modules/iswa/rendering/iswadatagroup.cpp @@ -34,6 +34,8 @@ #include #include +#include + namespace { const std::string _loggerCat = "IswaDataGroup"; using json = nlohmann::json; diff --git a/modules/iswa/rendering/iswakameleongroup.cpp b/modules/iswa/rendering/iswakameleongroup.cpp index 688bba237b..513bd8000a 100644 --- a/modules/iswa/rendering/iswakameleongroup.cpp +++ b/modules/iswa/rendering/iswakameleongroup.cpp @@ -33,6 +33,7 @@ #include #include #include +#include namespace { const std::string _loggerCat = "IswaDataGroup"; diff --git a/modules/iswa/rendering/kameleonplane.cpp b/modules/iswa/rendering/kameleonplane.cpp index 2779cdf3ae..e8d4e71662 100644 --- a/modules/iswa/rendering/kameleonplane.cpp +++ b/modules/iswa/rendering/kameleonplane.cpp @@ -30,6 +30,8 @@ #include #include +#include + namespace { using json = nlohmann::json; const std::string _loggerCat = "KameleonPlane"; diff --git a/modules/iswa/rendering/screenspacecygnet.cpp b/modules/iswa/rendering/screenspacecygnet.cpp index ea6689dd4a..7b493ea866 100644 --- a/modules/iswa/rendering/screenspacecygnet.cpp +++ b/modules/iswa/rendering/screenspacecygnet.cpp @@ -27,6 +27,7 @@ #include #include #include +#include namespace { const std::string _loggerCat = "ScreenSpaceCygnet"; diff --git a/modules/newhorizons/rendering/renderablemodelprojection.cpp b/modules/newhorizons/rendering/renderablemodelprojection.cpp index df13bbcec7..d82683eb49 100644 --- a/modules/newhorizons/rendering/renderablemodelprojection.cpp +++ b/modules/newhorizons/rendering/renderablemodelprojection.cpp @@ -24,6 +24,7 @@ #include +#include #include #include #include diff --git a/modules/newhorizons/rendering/renderableplanetprojection.cpp b/modules/newhorizons/rendering/renderableplanetprojection.cpp index 7a49f76a7e..2d6e0ccb95 100644 --- a/modules/newhorizons/rendering/renderableplanetprojection.cpp +++ b/modules/newhorizons/rendering/renderableplanetprojection.cpp @@ -26,6 +26,7 @@ #include +#include #include #include #include @@ -36,6 +37,11 @@ #include #include +#ifdef WIN32 +#define _USE_MATH_DEFINES +#include +#endif + namespace { const std::string _loggerCat = "RenderablePlanetProjection"; diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index ded090b893..e2f2d788ef 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -1482,11 +1482,14 @@ void RenderEngine::renderScreenLog() { } } -void RenderEngine::sortScreenspaceRenderables(){ - std::sort(_screenSpaceRenderables.begin(), _screenSpaceRenderables.end(), - [](std::shared_ptr j, std::shared_ptr i){ - return i->depth() > j->depth(); - }); +void RenderEngine::sortScreenspaceRenderables() { + std::sort( + _screenSpaceRenderables.begin(), + _screenSpaceRenderables.end(), + [](auto j, auto i) { + return i->depth() > j->depth(); + } + ); } }// namespace openspace diff --git a/src/rendering/screenspacerenderable.cpp b/src/rendering/screenspacerenderable.cpp index f117984b9f..f406644d68 100644 --- a/src/rendering/screenspacerenderable.cpp +++ b/src/rendering/screenspacerenderable.cpp @@ -21,20 +21,40 @@ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include + #include + +#include +#include +#include +#include #include -#include + +#include + + #ifdef WIN32 + #define _USE_MATH_DEFINES + #include + #endif namespace { const std::string _loggerCat = "ScreenSpaceRenderable"; + const std::string KeyType = "Type"; + const std::string KeyFlatScreen = "FlatScreen"; + const std::string KeyPosition = "Position"; + const std::string KeyScale = "Scale"; + const std::string KeyDepth = "Depth"; + const std::string KeyAlpha = "Alpha"; + + const float PlaneDepth = -2.f; } namespace openspace { -ScreenSpaceRenderable* ScreenSpaceRenderable::createFromDictionary(const ghoul::Dictionary& dictionary) { - +ScreenSpaceRenderable* ScreenSpaceRenderable::createFromDictionary( + const ghoul::Dictionary& dictionary) +{ std::string renderableType; bool success = dictionary.getValue(KeyType, renderableType); @@ -43,11 +63,12 @@ ScreenSpaceRenderable* ScreenSpaceRenderable::createFromDictionary(const ghoul:: return nullptr; } - ghoul::TemplateFactory* factory - = FactoryManager::ref().factory(); + auto factory = FactoryManager::ref().factory(); ScreenSpaceRenderable* result = factory->create(renderableType, dictionary); if (result == nullptr) { - LERROR("Failed to create a ScreenSpaceRenderable object of type '" << renderableType << "'"); + LERROR("Failed to create a ScreenSpaceRenderable object of type '" << + renderableType << "'" + ); return nullptr; } @@ -56,150 +77,167 @@ ScreenSpaceRenderable* ScreenSpaceRenderable::createFromDictionary(const ghoul:: ScreenSpaceRenderable::ScreenSpaceRenderable(const ghoul::Dictionary& dictionary) - :_enabled("enabled", "Is Enabled", true) - ,_useFlatScreen("flatScreen", "Flat Screen", true) - ,_euclideanPosition("euclideanPosition", "Euclidean coordinates", glm::vec2(0),glm::vec2(-4),glm::vec2(4)) - ,_sphericalPosition("sphericalPosition", "Spherical coordinates", glm::vec2(0, M_PI_2),glm::vec2(-M_PI),glm::vec2(M_PI)) - ,_depth("depth", "Depth", 0, 0, 1) - ,_scale("scale", "Scale" , 0.25, 0, 2) - ,_alpha("alpha", "Alpha" , 1, 0, 1) - ,_delete("delete", "Delete") - ,_quad(0) - ,_vertexPositionBuffer(0) - ,_rendererPath("${SHADERS}/framebuffer/renderframebuffer.frag") - ,_vertexPath("${MODULE_BASE}/shaders/screnspace_vs.glsl") - ,_fragmentPath("${MODULE_BASE}/shaders/screnspace_fs.glsl") - ,_texture(nullptr) - ,_shader(nullptr) + : _enabled("enabled", "Is Enabled", true) + , _useFlatScreen("flatScreen", "Flat Screen", true) + , _euclideanPosition( + "euclideanPosition", + "Euclidean coordinates", + glm::vec2(0.f), + glm::vec2(-4.f), + glm::vec2(4.f) + ) + , _sphericalPosition( + "sphericalPosition", + "Spherical coordinates", + glm::vec2(0.f, M_PI_2), + glm::vec2(-M_PI), + glm::vec2(M_PI) + ) + , _depth("depth", "Depth", 0.f, 0.f, 1.f) + , _scale("scale", "Scale", 0.25f, 0.f, 2.f) + , _alpha("alpha", "Alpha", 1.f, 0.f, 1.f) + , _delete("delete", "Delete") + , _quad(0) + , _vertexPositionBuffer(0) + , _texture(nullptr) + , _shader(nullptr) + , _radius(PlaneDepth) { addProperty(_enabled); addProperty(_useFlatScreen); - addProperty(_euclideanPosition); - addProperty(_sphericalPosition); addProperty(_depth); addProperty(_scale); addProperty(_alpha); addProperty(_delete); - _rendererData = ghoul::Dictionary(); - _rendererData.setValue("fragmentRendererPath", _rendererPath); - _rendererData.setValue("windowWidth", OsEng.windowWrapper().currentWindowResolution().x); - _rendererData.setValue("windowHeight", OsEng.windowWrapper().currentWindowResolution().y); - _radius = _planeDepth; - - - if(dictionary.hasValue("FlatScreen")){ - bool useFlatScreen; - dictionary.getValue("FlatScreen", useFlatScreen); - - _useFlatScreen.setValue(useFlatScreen); - } - - useEuclideanCoordinates(_useFlatScreen.value()); + dictionary.getValue(KeyFlatScreen, _useFlatScreen); + useEuclideanCoordinates(_useFlatScreen); - if(dictionary.hasValue("Position")){ - glm::vec2 pos; - dictionary.getValue("Position", pos); - if(_useFlatScreen) - _euclideanPosition.setValue(pos); - else - _sphericalPosition.setValue(pos); - } + if (_useFlatScreen) + dictionary.getValue(KeyPosition, _euclideanPosition); + else + dictionary.getValue(KeyPosition, _sphericalPosition); - if(dictionary.hasValue("Scale")){ - float scale; - dictionary.getValue("Scale", scale); - _scale.setValue(scale); - } - - if(dictionary.hasValue("Depth")){ - float depth; - dictionary.getValue("Depth", depth); - _depth.setValue(depth); - } - - if(dictionary.hasValue("Alpha")){ - float alpha; - dictionary.getValue("Scale", alpha); - _alpha.setValue(alpha); - } + dictionary.getValue(KeyScale, _scale); + dictionary.getValue(KeyDepth, _depth); + dictionary.getValue(KeyAlpha, _alpha); // Setting spherical/euclidean onchange handler _useFlatScreen.onChange([this](){ - if(_useFlatScreen.value()){ - OsEng.gui()._screenSpaceProperty.registerProperty(&_euclideanPosition, &_useFlatScreen); + if (_useFlatScreen) { + OsEng.gui()._screenSpaceProperty.registerProperty( + &_euclideanPosition, + &_useFlatScreen + ); + addProperty(_euclideanPosition); + OsEng.gui()._screenSpaceProperty.unregisterProperty(&_sphericalPosition); + removeProperty(_sphericalPosition); } else { OsEng.gui()._screenSpaceProperty.unregisterProperty(&_euclideanPosition); - OsEng.gui()._screenSpaceProperty.registerProperty(&_sphericalPosition, &_useFlatScreen); + removeProperty(_euclideanPosition); + + OsEng.gui()._screenSpaceProperty.registerProperty( + &_sphericalPosition, + &_useFlatScreen + ); + addProperty(_sphericalPosition); } - useEuclideanCoordinates(_useFlatScreen.value()); + useEuclideanCoordinates(_useFlatScreen); }); _delete.onChange([this](){ - std::string script = "openspace.unregisterScreenSpaceRenderable('" + name() + "');"; + std::string script = + "openspace.unregisterScreenSpaceRenderable('" + name() + "');"; OsEng.scriptEngine().queueScript(script); }); } -ScreenSpaceRenderable::~ScreenSpaceRenderable(){} +ScreenSpaceRenderable::~ScreenSpaceRenderable() {} bool ScreenSpaceRenderable::isEnabled() const { return _enabled; } +glm::vec3 ScreenSpaceRenderable::euclideanPosition() const { + return glm::vec3(_euclideanPosition.value(), _depth.value()); +} + +glm::vec3 ScreenSpaceRenderable::sphericalPosition() const { + return glm::vec3(_sphericalPosition.value(), _depth.value()); +} + +float ScreenSpaceRenderable::depth() const { + return _depth; +} + void ScreenSpaceRenderable::createPlane() { - glGenVertexArrays(1, &_quad); // generate array - glGenBuffers(1, &_vertexPositionBuffer); // generate buffer + glGenVertexArrays(1, &_quad); + glGenBuffers(1, &_vertexPositionBuffer); // ============================ // GEOMETRY (quad) // ============================ - const GLfloat vertex_data[] = { // square of two triangles (sigh) + const GLfloat vertex_data[] = { // x y z w s t - -1, -1, 0.0f, 1, 0, 1, - 1, 1, 0.0f, 1, 1, 0, - -1, 1, 0.0f, 1, 0, 0, - -1, -1, 0.0f, 1, 0, 1, - 1, -1, 0.0f, 1, 1, 1, - 1, 1, 0.0f, 1, 1, 0, + -1, -1, 0.0f, 1, 0, 0, + 1, 1, 0.0f, 1, 1, 1, + -1, 1, 0.0f, 1, 0, 1, + -1, -1, 0.0f, 1, 0, 0, + 1, -1, 0.0f, 1, 1, 0, + 1, 1, 0.0f, 1, 1, 1, }; - glBindVertexArray(_quad); // bind array - glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer); // bind buffer + glBindVertexArray(_quad); + glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW); glEnableVertexAttribArray(0); - glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast(0)); + glVertexAttribPointer( + 0, + 4, + GL_FLOAT, + GL_FALSE, + sizeof(GLfloat) * 6, + reinterpret_cast(0) + ); + glEnableVertexAttribArray(1); - glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast(sizeof(GLfloat) * 4)); + glVertexAttribPointer( + 1, + 2, + GL_FLOAT, + GL_FALSE, + sizeof(GLfloat) * 6, + reinterpret_cast(sizeof(GLfloat) * 4) + ); } -void ScreenSpaceRenderable::useEuclideanCoordinates(bool b){ +void ScreenSpaceRenderable::useEuclideanCoordinates(bool b) { _useEuclideanCoordinates = b; - if(_useEuclideanCoordinates){ - _euclideanPosition.set(toEuclidean(_sphericalPosition.value(), _radius)); + if (_useEuclideanCoordinates) { + _euclideanPosition = toEuclidean(_sphericalPosition.value(), _radius); } else { - _sphericalPosition.set(toSpherical(_euclideanPosition.value())); + _sphericalPosition = toSpherical(_euclideanPosition.value()); } } -glm::vec2 ScreenSpaceRenderable::toEuclidean(glm::vec2 polar, float r){ - float x = r*sin(polar[0])*sin(polar[1]); - float y = r*cos(polar[1]); +glm::vec2 ScreenSpaceRenderable::toEuclidean(const glm::vec2& spherical, float r) { + float x = r * sin(spherical[0]) * sin(spherical[1]); + float y = r * cos(spherical[1]); return glm::vec2(x, y); } -glm::vec2 ScreenSpaceRenderable::toSpherical(glm::vec2 euclidean){ - _radius = -sqrt(pow(euclidean[0],2)+pow(euclidean[1],2)+pow(_planeDepth,2)); - float theta = atan2(-_planeDepth,euclidean[0])-M_PI/2.0; +glm::vec2 ScreenSpaceRenderable::toSpherical(const glm::vec2& euclidean) { + _radius = -sqrt(pow(euclidean[0],2)+pow(euclidean[1],2)+pow(PlaneDepth,2)); + float theta = atan2(-PlaneDepth,euclidean[0])-M_PI/2.0; float phi = acos(euclidean[1]/_radius); return glm::vec2(theta, phi); } -void ScreenSpaceRenderable::registerProperties(){ +void ScreenSpaceRenderable::registerProperties() { OsEng.gui()._screenSpaceProperty.registerProperty(&_enabled); OsEng.gui()._screenSpaceProperty.registerProperty(&_useFlatScreen); OsEng.gui()._screenSpaceProperty.registerProperty(&_euclideanPosition); @@ -209,80 +247,98 @@ void ScreenSpaceRenderable::registerProperties(){ OsEng.gui()._screenSpaceProperty.registerProperty(&_delete); } -void ScreenSpaceRenderable::unregisterProperties(){ +void ScreenSpaceRenderable::unregisterProperties() { OsEng.gui()._screenSpaceProperty.unregisterProperties(name()); } -void ScreenSpaceRenderable::createShaders(){ - if(!_shader) { - +void ScreenSpaceRenderable::createShaders() { + if (!_shader) { ghoul::Dictionary dict = ghoul::Dictionary(); - dict.setValue("rendererData", _rendererData); - dict.setValue("fragmentPath", _fragmentPath); - _shader = ghoul::opengl::ProgramObject::Build("ScreenSpaceProgram", - _vertexPath, + auto res = OsEng.windowWrapper().currentWindowResolution(); + ghoul::Dictionary rendererData = { + { "fragmentRendererPath", "${SHADERS}/framebuffer/renderframebuffer.frag" }, + { "windowWidth" , res.x }, + { "windowHeight" , res.y } + }; + + dict.setValue("rendererData", rendererData); + dict.setValue("fragmentPath", "${MODULE_BASE}/shaders/screnspace_fs.glsl"); + _shader = ghoul::opengl::ProgramObject::Build( + "ScreenSpaceProgram", + "${MODULE_BASE}/shaders/screnspace_vs.glsl", "${SHADERS}/render.frag", dict - ); + ); } } -glm::mat4 ScreenSpaceRenderable::scaleMatrix(){ - glm::mat4 scale(1.0); - +glm::mat4 ScreenSpaceRenderable::scaleMatrix() { glm::vec2 resolution = OsEng.windowWrapper().currentWindowResolution(); //to scale the plane - float textureRatio = (float(_texture->height())/float(_texture->width())); - float scalingRatioX = _originalViewportSize[0]/ resolution[0]; - float scalingRatioY = _originalViewportSize[1]/ resolution[1]; - scale = glm::scale(scale, glm::vec3(_scale.value() * scalingRatioX, - _scale.value() * scalingRatioY * textureRatio, - 1)); - return scale; + float textureRatio = + static_cast(_texture->height()) / static_cast(_texture->width()); + + float scalingRatioX = _originalViewportSize.x / resolution.x; + float scalingRatioY = _originalViewportSize.y / resolution.y; + return glm::scale( + glm::mat4(1.f), + glm::vec3( + _scale * scalingRatioX, + _scale * scalingRatioY * textureRatio, + 1.f + ) + ); } -glm::mat4 ScreenSpaceRenderable::rotationMatrix(){ +glm::mat4 ScreenSpaceRenderable::rotationMatrix() { // Get the scene transform - glm::mat4 rotation = sgct::Engine::instance()->getModelMatrix(); - if(!_useEuclideanCoordinates){ + glm::mat4 rotation = OsEng.windowWrapper().modelMatrix(); + if (!_useEuclideanCoordinates) { glm::vec2 position = _sphericalPosition.value(); float theta = position.x; - float phi = position.y - M_PI/2.0; + float phi = position.y - M_PI_2; - rotation = glm::rotate(rotation, position.x, glm::vec3(0.0f, 1.0f, 0.0f)); - rotation = glm::rotate(rotation, (float) (position.y - M_PI/2.0) , glm::vec3(1.0f, 0.0f, 0.0f)); + rotation = glm::rotate(rotation, position.x, glm::vec3(0.f, 1.f, 0.f)); + rotation = glm::rotate( + rotation, + static_cast(position.y - M_PI_2), + glm::vec3(1.f, 0.f, 0.f) + ); } return rotation; } - -glm::mat4 ScreenSpaceRenderable::translationMatrix(){ +glm::mat4 ScreenSpaceRenderable::translationMatrix() { glm::mat4 translation(1.0); - if(!_useEuclideanCoordinates){ - translation = glm::translate(translation, glm::vec3(0.0f, 0.0f, _planeDepth)); - }else{ - translation = glm::translate(glm::mat4(1.f), glm::vec3(_euclideanPosition.value(), _planeDepth)); + if (!_useEuclideanCoordinates) { + translation = glm::translate(translation, glm::vec3(0.0f, 0.0f, PlaneDepth)); + } else { + translation = glm::translate( + glm::mat4(1.f), + glm::vec3(_euclideanPosition.value(), PlaneDepth) + ); } return translation; } - -void ScreenSpaceRenderable::draw(glm::mat4 modelTransform){ - float occlusionDepth = 1-_depth.value(); - +void ScreenSpaceRenderable::draw(glm::mat4 modelTransform) { glEnable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); _shader->activate(); - _shader->setUniform("OcclusionDepth", occlusionDepth); + _shader->setUniform("OcclusionDepth", 1.f - _depth); _shader->setUniform("Alpha", _alpha); - _shader->setUniform("ModelTransform",modelTransform); - _shader->setUniform("ViewProjectionMatrix", OsEng.renderEngine().camera()->viewProjectionMatrix()); + _shader->setUniform("ModelTransform", modelTransform); + _shader->setUniform( + "ViewProjectionMatrix", + OsEng.renderEngine().camera()->viewProjectionMatrix() + ); + ghoul::opengl::TextureUnit unit; unit.activate(); _texture->bind(); @@ -290,8 +346,10 @@ void ScreenSpaceRenderable::draw(glm::mat4 modelTransform){ glBindVertexArray(_quad); glDrawArrays(GL_TRIANGLES, 0, 6); + glEnable(GL_CULL_FACE); _shader->deactivate(); } -}// namespace openspace \ No newline at end of file + +} // namespace openspace From 77c8ecf6dfe1556795de73ca5d559b6fc80b81c4 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 16 Jun 2016 01:02:13 +0200 Subject: [PATCH 13/14] Rename screnspace* to screenspace shaders --- modules/base/CMakeLists.txt | 4 ++-- .../base/shaders/{screnspace_fs.glsl => screenspace_fs.glsl} | 0 .../base/shaders/{screnspace_vs.glsl => screenspace_vs.glsl} | 0 src/rendering/screenspacerenderable.cpp | 4 ++-- 4 files changed, 4 insertions(+), 4 deletions(-) rename modules/base/shaders/{screnspace_fs.glsl => screenspace_fs.glsl} (100%) rename modules/base/shaders/{screnspace_vs.glsl => screenspace_vs.glsl} (100%) diff --git a/modules/base/CMakeLists.txt b/modules/base/CMakeLists.txt index 66a9bea9cc..42bc24c2a2 100644 --- a/modules/base/CMakeLists.txt +++ b/modules/base/CMakeLists.txt @@ -89,8 +89,8 @@ set(SHADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/shaders/star_fs.glsl ${CMAKE_CURRENT_SOURCE_DIR}/shaders/star_ge.glsl ${CMAKE_CURRENT_SOURCE_DIR}/shaders/star_vs.glsl - ${CMAKE_CURRENT_SOURCE_DIR}/shaders/screnspace_fs.glsl - ${CMAKE_CURRENT_SOURCE_DIR}/shaders/screnspace_vs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/screenspace_fs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/screenspace_vs.glsl ) source_group("Shader Files" FILES ${SHADER_FILES}) diff --git a/modules/base/shaders/screnspace_fs.glsl b/modules/base/shaders/screenspace_fs.glsl similarity index 100% rename from modules/base/shaders/screnspace_fs.glsl rename to modules/base/shaders/screenspace_fs.glsl diff --git a/modules/base/shaders/screnspace_vs.glsl b/modules/base/shaders/screenspace_vs.glsl similarity index 100% rename from modules/base/shaders/screnspace_vs.glsl rename to modules/base/shaders/screenspace_vs.glsl diff --git a/src/rendering/screenspacerenderable.cpp b/src/rendering/screenspacerenderable.cpp index f406644d68..6f405090f4 100644 --- a/src/rendering/screenspacerenderable.cpp +++ b/src/rendering/screenspacerenderable.cpp @@ -263,10 +263,10 @@ void ScreenSpaceRenderable::createShaders() { }; dict.setValue("rendererData", rendererData); - dict.setValue("fragmentPath", "${MODULE_BASE}/shaders/screnspace_fs.glsl"); + dict.setValue("fragmentPath", "${MODULE_BASE}/shaders/screenspace_fs.glsl"); _shader = ghoul::opengl::ProgramObject::Build( "ScreenSpaceProgram", - "${MODULE_BASE}/shaders/screnspace_vs.glsl", + "${MODULE_BASE}/shaders/screenspace_vs.glsl", "${SHADERS}/render.frag", dict ); From 78f3b42c3bcaf2f345605d83ce0d631e1df28bcc Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 16 Jun 2016 01:22:30 +0200 Subject: [PATCH 14/14] Started cleanup of ScreenSpaceImage --- modules/base/rendering/screenspaceimage.cpp | 179 +++++++++----------- modules/base/rendering/screenspaceimage.h | 31 ++-- src/rendering/renderengine.cpp | 2 +- 3 files changed, 92 insertions(+), 120 deletions(-) diff --git a/modules/base/rendering/screenspaceimage.cpp b/modules/base/rendering/screenspaceimage.cpp index 2b38c0029e..2c20a33f4f 100644 --- a/modules/base/rendering/screenspaceimage.cpp +++ b/modules/base/rendering/screenspaceimage.cpp @@ -1,80 +1,80 @@ /***************************************************************************************** -* * -* OpenSpace * -* * -* Copyright (c) 2014-2016 * -* * -* Permission is hereby granted, free of charge, to any person obtaining a copy of this * -* software and associated documentation files (the "Software"), to deal in the Software * -* without restriction, including without limitation the rights to use, copy, modify, * -* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * -* permit persons to whom the Software is furnished to do so, subject to the following * -* conditions: * -* * -* The above copyright notice and this permission notice shall be included in all copies * -* or substantial portions of the Software. * -* * -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * -* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * -* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * -* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * -* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * -* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * -****************************************************************************************/ + * * + * OpenSpace * + * * + * Copyright (c) 2014-2016 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + #include -#include -#include #include - -#include #include #include +#include +#include + +#include + namespace { const std::string _loggerCat = "ScreenSpaceImage"; + + const std::string KeyName = "Name"; + const std::string KeyTexturePath = "TexturePath"; + const std::string KeyUrl = "URL"; } namespace openspace { + ScreenSpaceImage::ScreenSpaceImage(const ghoul::Dictionary& dictionary) - :ScreenSpaceRenderable(dictionary) - ,_texturePath("texturePath", "Texture path", "") - ,_downloadImage(false) + : ScreenSpaceRenderable(dictionary) + , _texturePath("texturePath", "Texture path", "") + , _downloadImage(false) { std::string name; - if(dictionary.getValue("Name", name)){ + if (dictionary.getValue(KeyName, name)) { setName(name); - }else{ - _id = id(); - setName("ScreenSpaceImage" + std::to_string(_id)); + } else { + static int id = 0; + setName("ScreenSpaceImage " + std::to_string(id)); + ++id; } addProperty(_texturePath); registerProperties(); std::string texturePath; - bool texturesucces = (dictionary.getValue("TexturePath", texturePath)); - if(texturesucces){ - _texturePath.set(texturePath); + if (dictionary.getValue(KeyTexturePath, texturePath)) { + _texturePath = texturePath; OsEng.gui()._screenSpaceProperty.registerProperty(&_texturePath); _texturePath.onChange([this](){ loadTexture(); }); } - bool urlsucces = dictionary.getValue("URL", _url); - if(urlsucces){ - _downloadImage =true; + if (dictionary.getValue(KeyUrl, _url)) { + _downloadImage = true; } - - //screenspaceCygnet does not have url or texturePath - // if(!texturesucces && !urlsucces){ - // LERROR("Must specify TexturePath or URL"); - // } - } -ScreenSpaceImage::~ScreenSpaceImage(){} +ScreenSpaceImage::~ScreenSpaceImage() {} -bool ScreenSpaceImage::initialize(){ +bool ScreenSpaceImage::initialize() { _originalViewportSize = OsEng.windowWrapper().currentWindowResolution(); createPlane(); @@ -84,7 +84,7 @@ bool ScreenSpaceImage::initialize(){ return isReady(); } -bool ScreenSpaceImage::deinitialize(){ +bool ScreenSpaceImage::deinitialize() { unregisterProperties(); glDeleteVertexArrays(1, &_quad); @@ -96,47 +96,32 @@ bool ScreenSpaceImage::deinitialize(){ _texturePath = ""; _texture = nullptr; - RenderEngine& renderEngine = OsEng.renderEngine(); if (_shader) { - renderEngine.removeRenderProgram(_shader); + OsEng.renderEngine().removeRenderProgram(_shader); _shader = nullptr; } return true; } -void ScreenSpaceImage::render(){ - if(!isReady()) return; - if(!_enabled) return; - - glm::mat4 rotation = rotationMatrix(); - glm::mat4 translation = translationMatrix(); - glm::mat4 scale = scaleMatrix(); - glm::mat4 modelTransform = rotation*translation*scale; - - draw(modelTransform); +void ScreenSpaceImage::render() { + draw(rotationMatrix() * translationMatrix() * scaleMatrix()); } - -void ScreenSpaceImage::update(){ - if(_downloadImage && _futureImage.valid() && DownloadManager::futureReady(_futureImage)){ +void ScreenSpaceImage::update() { + bool futureReady = DownloadManager::futureReady(_futureImage); + if (_downloadImage && _futureImage.valid() && futureReady) { loadTexture(); } } - -bool ScreenSpaceImage::isReady() const{ - bool ready = true; - if (!_shader) - ready &= false; - if(!_texture) - ready &= false; - return ready; +bool ScreenSpaceImage::isReady() const { + return _shader && _texture; } void ScreenSpaceImage::loadTexture() { std::unique_ptr texture = nullptr; - if(!_downloadImage) + if (!_downloadImage) texture = std::move(loadFromDisk()); else texture = std::move(loadFromMemory()); @@ -152,56 +137,54 @@ void ScreenSpaceImage::loadTexture() { } } -void ScreenSpaceImage::updateTexture(){ - if(!_downloadImage){ +void ScreenSpaceImage::updateTexture() { + if (!_downloadImage) { loadTexture(); } else { - if(_futureImage.valid()) + if (_futureImage.valid()) return; std::future future = downloadImageToMemory(_url); - if(future.valid()){ + if (future.valid()) { _futureImage = std::move(future); } } } - std::unique_ptr ScreenSpaceImage::loadFromDisk(){ + std::unique_ptr ScreenSpaceImage::loadFromDisk() { if (_texturePath.value() != "") return (ghoul::io::TextureReader::ref().loadTexture(absPath(_texturePath.value()))); return nullptr; } - std::unique_ptr ScreenSpaceImage::loadFromMemory(){ - - if(_futureImage.valid() && DownloadManager::futureReady(_futureImage) ){ + std::unique_ptr ScreenSpaceImage::loadFromMemory() { + if (_futureImage.valid() && DownloadManager::futureReady(_futureImage)) { DownloadManager::MemoryFile imageFile = _futureImage.get(); - if(imageFile.corrupted) + if (imageFile.corrupted) return nullptr; return (ghoul::io::TextureReader::ref().loadTexture( - (void*) imageFile.buffer, + reinterpret_cast(imageFile.buffer), imageFile.size, - imageFile.format)); + imageFile.format) + ); } } -std::future ScreenSpaceImage::downloadImageToMemory(std::string url){ - return std::move( DlManager.fetchFile( - url, - [url](const DownloadManager::MemoryFile& file){ - LDEBUG("Download to memory finished for screen space image"); - }, - [url](const std::string& err){ - LDEBUG("Download to memory failer for screen space image: " +err); - } - ) ); +std::future ScreenSpaceImage::downloadImageToMemory( + std::string url) +{ + return std::move(DlManager.fetchFile( + url, + [url](const DownloadManager::MemoryFile& file) { + LDEBUG("Download to memory finished for screen space image"); + }, + [url](const std::string& err) { + LDEBUG("Download to memory failer for screen space image: " +err); + } + )); } -int ScreenSpaceImage::id(){ - static int id = 0; - return id++; -} -} \ No newline at end of file +} // namespace openspace diff --git a/modules/base/rendering/screenspaceimage.h b/modules/base/rendering/screenspaceimage.h index e157f990a7..df66d02db7 100644 --- a/modules/base/rendering/screenspaceimage.h +++ b/modules/base/rendering/screenspaceimage.h @@ -21,57 +21,46 @@ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ + #ifndef __SCREENSPACEIMAGE_H__ #define __SCREENSPACEIMAGE_H__ #include -#include -#include +#include #include +#include namespace openspace { -/** - * @brief Creates a textured plane rendered in screenspace - * @details The plane gets the same ratio as the texture. Implements - * the interface that ScreenSpaceImage speciefies. - * - * @param texturePath Path to the image that should be used as texture - */ -class ScreenSpaceImage : public ScreenSpaceRenderable { +class ScreenSpaceImage : public ScreenSpaceRenderable { public: - ScreenSpaceImage(std::string texturePath); ScreenSpaceImage(const ghoul::Dictionary& dictionary); ~ScreenSpaceImage(); bool initialize() override; bool deinitialize() override; void render() override; - virtual void update() override; + void update() override; bool isReady() const override; protected: + void loadTexture(); + void updateTexture(); + std::string _url; bool _downloadImage; std::future _futureImage; - void loadTexture(); - void updateTexture(); private: - - static int id(); std::future downloadImageToMemory(std::string url); std::unique_ptr loadFromDisk(); std::unique_ptr loadFromMemory(); properties::StringProperty _texturePath; - //std::string _memorybuffer; - - - int _id; }; } //namespace openspace -#endif //__SCREENSPACEIMAGE_H__ \ No newline at end of file + +#endif //__SCREENSPACEIMAGE_H__ diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index e2f2d788ef..839b60312f 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -407,7 +407,7 @@ void RenderEngine::render(const glm::mat4 &projectionMatrix, const glm::mat4 &vi } for (auto screenSpaceRenderable : _screenSpaceRenderables) { - if(screenSpaceRenderable->isEnabled()) + if (screenSpaceRenderable->isEnabled() && screenSpaceRenderable->isReady()) screenSpaceRenderable->render(); } }