From cd35cea0ee2cf3301d3dc1b7884fbc7fea6d4911 Mon Sep 17 00:00:00 2001 From: Sebastian Piwell Date: Tue, 17 May 2016 17:18:09 -0400 Subject: [PATCH] Updated Kameleon plane --- modules/iswa/rendering/kameleonplane.cpp | 255 ++++++++++++++--------- modules/iswa/rendering/kameleonplane.h | 60 +++--- modules/iswa/util/iswamanager.h | 1 - 3 files changed, 190 insertions(+), 126 deletions(-) diff --git a/modules/iswa/rendering/kameleonplane.cpp b/modules/iswa/rendering/kameleonplane.cpp index 2e7000e1d8..87bb65724a 100644 --- a/modules/iswa/rendering/kameleonplane.cpp +++ b/modules/iswa/rendering/kameleonplane.cpp @@ -1,71 +1,86 @@ -// // /***************************************************************************************** -// // * * -// // * 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 -// #include -// #include - -// namespace { -// const std::string _loggerCat = "KameleonPlane"; -// } - -// namespace openspace { - -// KameleonPlane::KameleonPlane(const ghoul::Dictionary& dictionary) -// :CygnetPlane(dictionary) -// { -// std::string name; -// dictionary.getValue("Name", name); -// setName(name); - -// registerProperties(); +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -// dictionary.getValue("kwPath", _kwPath); +namespace { + const std::string _loggerCat = "KameleonPlane"; +} -// std::string axis; -// dictionary.getValue("axisCut", axis); +namespace openspace { -// if(axis == "x"){ -// _data->scale.x = 0; -// }else if(axis == "y"){ -// _data->scale.y = 0; -// }else{ -// _data->scale.z = 0; -// } -// } +KameleonPlane::KameleonPlane(const ghoul::Dictionary& dictionary) + :CygnetPlane(dictionary) + ,_backgroundValues("backgroundValues", "Background Values", glm::vec2(0.0), glm::vec2(0), glm::vec2(1.0)) + ,_transferFunctionsFile("transferfunctions", "Transfer Functions", "${SCENE}/iswa/tfs/hot.tf") +{ + std::string name; + dictionary.getValue("Name", name); + setName(name); -// KameleonPlane::~KameleonPlane(){} + registerProperties(); + + + dictionary.getValue("kwPath", _kwPath); + + std::string axis; + dictionary.getValue("axisCut", axis); + + if(axis == "x"){ + _data->scale.x = 0; + }else if(axis == "y"){ + _data->scale.y = 0; + }else{ + _data->scale.z = 0; + } + _kw = std::make_shared(absPath(_kwPath)); + KameleonWrapper::Model model = _kw->model(); + if( model == KameleonWrapper::Model::BATSRUS) + _var = "p"; + else + _var = "rho"; + + _dimensions = glm::size3_t(500,500,1); + float zSlice = 0.5f; + _dataSlice = _kw->getUniformSliceValues(std::string(_var), _dimensions, zSlice); +} + +KameleonPlane::~KameleonPlane(){} // bool KameleonPlane::initialize(){ @@ -73,16 +88,8 @@ // std::cout << "initialize kameleonplane" << std::endl; // // std::string kwPath; -// _kw = std::make_shared(absPath(_kwPath)); // // dictionary.getValue("KW", _kw); -// KameleonWrapper::Model model = _kw->model(); -// if( model == KameleonWrapper::Model::BATSRUS) -// _var = "p"; -// else -// _var = "rho"; - - // createPlane(); // if (_shader == nullptr) { @@ -96,9 +103,7 @@ // return false; // } -// _dimensions = glm::size3_t(500,500,1); -// float zSlice = 0.5f; -// _dataSlice = _kw->getUniformSliceValues(std::string(_var), _dimensions, zSlice); + // loadTexture(); @@ -117,37 +122,91 @@ // } -// bool KameleonPlane::loadTexture() { -// std::cout << "load kameleonplane texture" << std::endl; -// ghoul::opengl::Texture::FilterMode filtermode = ghoul::opengl::Texture::FilterMode::Linear; -// ghoul::opengl::Texture::WrappingMode wrappingmode = ghoul::opengl::Texture::WrappingMode::ClampToEdge; -// std::unique_ptr texture = -// std::make_unique(_dataSlice, _dimensions, ghoul::opengl::Texture::Format::Red, GL_RED, GL_FLOAT, filtermode, wrappingmode); +bool KameleonPlane::loadTexture() { + std::cout << "load kameleonplane texture" << std::endl; + ghoul::opengl::Texture::FilterMode filtermode = ghoul::opengl::Texture::FilterMode::Linear; + ghoul::opengl::Texture::WrappingMode wrappingmode = ghoul::opengl::Texture::WrappingMode::ClampToEdge; + std::unique_ptr texture = + std::make_unique(_dataSlice, _dimensions, ghoul::opengl::Texture::Format::Red, GL_RED, GL_FLOAT, filtermode, wrappingmode); -// if (!texture) -// return false; -// // LDEBUG("Loaded texture from '" << absPath(_path) << "'"); + if (!texture) + return false; + // LDEBUG("Loaded texture from '" << absPath(_path) << "'"); -// texture->uploadTexture(); + texture->uploadTexture(); -// // Textures of planets looks much smoother with AnisotropicMipMap rather than linear -// texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear); + // Textures of planets looks much smoother with AnisotropicMipMap rather than linear + texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear); -// _textures[0] = std::move(texture); + _textures[0] = std::move(texture); -// return true; -// } + return true; +} -// bool KameleonPlane::updateTexture(){ -// return true; -// } +bool KameleonPlane::updateTexture(){ + if(!_textures[0]){ + loadTexture(); + } + return true; +} -// void KameleonPlane::setUniforms(){ -// ghoul::opengl::TextureUnit unit; +bool KameleonPlane::readyToRender(){ + return (_textures[0] != nullptr); +} -// unit.activate(); -// _textures[0]->bind(); -// _shader->setUniform("texture1", unit); -// } +void KameleonPlane::setUniformAndTextures(){ + ghoul::opengl::TextureUnit unit; -// }// namespace openspace \ No newline at end of file + ghoul::opengl::TextureUnit txUnits[10]; + txUnits[0].activate(); + _textures[0]->bind(); + _shader->setUniform("textures[0]", txUnits[0]); + + ghoul::opengl::TextureUnit tfUnits[10]; + tfUnits[0].activate(); + _transferFunctions[0]->bind(); + _shader->setUniform( + "transferFunctions[0]", + tfUnits[0] + ); + + _shader->setUniform("numTextures", 1); + _shader->setUniform("numTransferFunctions", 1); + _shader->setUniform("backgroundValues", _backgroundValues.value()); +} + +bool KameleonPlane::createShader(){ + if (_shader == nullptr) { + // DatePlane Program + RenderEngine& renderEngine = OsEng.renderEngine(); + _shader = renderEngine.buildRenderProgram("DataPlaneProgram", + "${MODULE_ISWA}/shaders/dataplane_vs.glsl", + "${MODULE_ISWA}/shaders/dataplane_fs.glsl" + ); + if (!_shader) return false; + } +} + +void KameleonPlane::setTransferFunctions(std::string tfPath){ + std::string line; + std::ifstream tfFile(absPath(tfPath)); + + std::vector> tfs; + + if(tfFile.is_open()){ + while(getline(tfFile, line)){ + std::shared_ptr tf = std::make_shared(absPath(line)); + if(tf){ + tfs.push_back(tf); + } + } + } + + if(!tfs.empty()){ + _transferFunctions.clear(); + _transferFunctions = tfs; + } + +} + +}// namespace openspace \ No newline at end of file diff --git a/modules/iswa/rendering/kameleonplane.h b/modules/iswa/rendering/kameleonplane.h index 35b0512e89..81db1abd5f 100644 --- a/modules/iswa/rendering/kameleonplane.h +++ b/modules/iswa/rendering/kameleonplane.h @@ -22,36 +22,42 @@ // * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * // *************************************************************************************** -// #ifndef __KAMELEONPLANE_H__ -// #define __KAMELEONPLANE_H__ +#ifndef __KAMELEONPLANE_H__ +#define __KAMELEONPLANE_H__ -// #include -// #include +#include +#include -// namespace openspace{ + namespace openspace{ -// class KameleonPlane : public CygnetPlane { -// public: -// KameleonPlane(const ghoul::Dictionary& dictionary); -// ~KameleonPlane(); + class KameleonPlane : public CygnetPlane { + public: + KameleonPlane(const ghoul::Dictionary& dictionary); + ~KameleonPlane(); -// virtual bool initialize() override; -// virtual bool deinitialize() override; + private: + virtual bool loadTexture() override; + virtual bool updateTexture() override; + + virtual bool readyToRender() override; + virtual void setUniformAndTextures() override; + virtual bool createShader() override; + + void setTransferFunctions(std::string tfPath); + + static int id(); + + properties::StringProperty _transferFunctionsFile; + properties::Vec2Property _backgroundValues; + + std::shared_ptr _kw; + std::string _kwPath; + + glm::size3_t _dimensions; + float* _dataSlice; + std::string _var; + }; -// private: -// virtual bool loadTexture() override; -// virtual bool updateTexture() override; -// virtual void setUniforms() override; + } // namespace openspace -// static int id(); - -// std::shared_ptr _kw; -// std::string _kwPath; -// glm::size3_t _dimensions; -// float* _dataSlice; -// std::string _var; -// }; - -// } // namespace openspace - -// #endif //__KAMELEONPLANE_H__ \ No newline at end of file +#endif //__KAMELEONPLANE_H__ \ No newline at end of file diff --git a/modules/iswa/util/iswamanager.h b/modules/iswa/util/iswamanager.h index a853552b72..c814ca103a 100644 --- a/modules/iswa/util/iswamanager.h +++ b/modules/iswa/util/iswamanager.h @@ -77,7 +77,6 @@ public: ~IswaManager(); void addIswaCygnet(int id, std::string type = "Texture", std::string group = ""); - // void deleteIswaCygnet(std::string); std::future fetchImageCygnet(int id); std::future fetchDataCygnet(int id);