diff --git a/data/dataplane.png b/data/dataplane.png deleted file mode 100644 index c1f2ce1a14..0000000000 Binary files a/data/dataplane.png and /dev/null differ diff --git a/data/scene/datasurface/datasurface.mod b/data/scene/datasurface/datasurface.mod new file mode 100644 index 0000000000..ddc8b9c7e9 --- /dev/null +++ b/data/scene/datasurface/datasurface.mod @@ -0,0 +1,17 @@ +return { + { + Name = "DataSurfaces", + Parent = "Root", + Renderable = { + Type = "DataSurfaceContainer" + }, + Ephemeris = { + Type = "Spice", + Body = "Earth", + Observer = "Sun", + Kernels = { + "${SPICE}/GSM.ti" + } + } + } +} \ No newline at end of file diff --git a/data/scene/default.scene b/data/scene/default.scene index da737c5c01..0fe2775cea 100644 --- a/data/scene/default.scene +++ b/data/scene/default.scene @@ -28,6 +28,7 @@ return { --"gridGalactic", --"gridEcliptic", --"gridEquatorial", + "datasurface", } } diff --git a/data/scene/earth/earth.mod b/data/scene/earth/earth.mod index 487891577a..987ed1f0be 100644 --- a/data/scene/earth/earth.mod +++ b/data/scene/earth/earth.mod @@ -86,17 +86,6 @@ return { Type = "Static", Position = {0, 0, 0, 5} } - }, - { - Name = "EarthPlane", - Parent = "Earth", - Renderable = { - Type = "RenderableDataPlane" - }, - Ephemeris = { - Type = "Static", - Position = {10, 0, 0, 1} - } } -- Plane -- { diff --git a/data/spice/GSM.ti b/data/spice/GSM.ti new file mode 100644 index 0000000000..e887e59bc3 --- /dev/null +++ b/data/spice/GSM.ti @@ -0,0 +1,31 @@ +Geocentric Solar Magnetospheric (GSM) frame: + + +X is parallel to the geometric earth-sun position vector. + + +Z axis is normalized component of north centered geomagnetic dipole + vector orthogonal to GSM +X axis. + + +Y completes the right-handed frame. + +\begindata + + FRAME_GSM = 1 + FRAME_1_NAME = 'GSM' + FRAME_1_CLASS = 5 + FRAME_1_CLASS_ID = 1 + FRAME_1_CENTER = 399 + FRAME_1_RELATIVE = 'J2000' + FRAME_1_DEF_STYLE = 'PARAMETERIZED' + FRAME_1_FAMILY = 'TWO-VECTOR' + FRAME_1_PRI_AXIS = 'X' + FRAME_1_PRI_VECTOR_DEF = 'OBSERVER_TARGET_POSITION' + FRAME_1_PRI_OBSERVER = 'EARTH' + FRAME_1_PRI_TARGET = 'SUN' + FRAME_1_PRI_ABCORR = 'NONE' + FRAME_1_SEC_AXIS = 'Z' + FRAME_1_SEC_VECTOR_DEF = 'CONSTANT' + FRAME_1_SEC_FRAME = 'IAU_EARTH' + FRAME_1_SEC_SPEC = 'LATITUDINAL' + FRAME_1_SEC_UNITS = 'DEGREES' + FRAME_1_SEC_LONGITUDE = 288.43 + FRAME_1_SEC_LATITUDE = 79.54 \ No newline at end of file diff --git a/modules/datasurface/CMakeLists.txt b/modules/datasurface/CMakeLists.txt index ff9ea8694d..55772d2ebb 100644 --- a/modules/datasurface/CMakeLists.txt +++ b/modules/datasurface/CMakeLists.txt @@ -25,12 +25,18 @@ include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake) set(HEADER_FILES - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderabledataplane.h + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/datasurfacecontainer.h + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/datasurface.h + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/dataplane.h + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/textureplane.h ) source_group("Header Files" FILES ${HEADER_FILES}) set(SOURCE_FILES - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderabledataplane.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/datasurfacecontainer.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/datasurface.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/dataplane.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/textureplane.cpp ) source_group("Source Files" FILES ${SOURCE_FILES}) diff --git a/modules/datasurface/datasurfacemodule.cpp b/modules/datasurface/datasurfacemodule.cpp index a06f06acf8..71d5e0f161 100644 --- a/modules/datasurface/datasurfacemodule.cpp +++ b/modules/datasurface/datasurfacemodule.cpp @@ -29,7 +29,7 @@ #include - #include + #include namespace openspace { @@ -41,6 +41,6 @@ auto fRenderable = FactoryManager::ref().factory(); ghoul_assert(fRenderable, "No renderable factory existed"); - fRenderable->registerClass("RenderableDataPlane"); + fRenderable->registerClass("DataSurfaceContainer"); } } \ No newline at end of file diff --git a/modules/datasurface/rendering/dataplane.cpp b/modules/datasurface/rendering/dataplane.cpp new file mode 100644 index 0000000000..49c28de0b0 --- /dev/null +++ b/modules/datasurface/rendering/dataplane.cpp @@ -0,0 +1,211 @@ +// /***************************************************************************************** +// * * +// * 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 +#include + + + +namespace openspace { + +DataPlane::DataPlane(std::shared_ptr kw, std::string path) + :DataSurface(path) + , _kw(kw) + , _texture(nullptr) + , _quad(0) + , _vertexPositionBuffer(0) +{} + + +DataPlane::~DataPlane(){} + + +bool DataPlane::initialize(){ + DataSurface::initialize(); + + _modelScale = _kw->getModelScaleScaled(); + _pscOffset = _kw->getModelBarycenterOffsetScaled(); + + _dimensions = glm::size3_t(500,500,1); + float zSlice = 0.5f; + + _dataSlice = _kw->getUniformSliceValues(std::string("p"), _dimensions, zSlice); + + glGenVertexArrays(1, &_quad); // generate array + glGenBuffers(1, &_vertexPositionBuffer); // generate buffer + createPlane(); + + if (_shader == nullptr) { + // Plane Program + + RenderEngine& renderEngine = OsEng.renderEngine(); + _shader = renderEngine.buildRenderProgram("PlaneProgram", + "${MODULE_DATASURFACE}/shaders/dataplane_vs.glsl", + "${MODULE_DATASURFACE}/shaders/dataplane_fs.glsl" + ); + if (!_shader) + return false; + } + + loadTexture(); + + return isReady(); +} + +bool DataPlane::deinitialize(){ + DataSurface::deinitialize(); + + glDeleteVertexArrays(1, &_quad); + _quad = 0; + + glDeleteBuffers(1, &_vertexPositionBuffer); + _vertexPositionBuffer = 0; + + RenderEngine& renderEngine = OsEng.renderEngine(); + if (_shader) { + renderEngine.removeRenderProgram(_shader); + _shader = nullptr; + } + + return true; +} + + +bool DataPlane::isReady() const { + bool ready = true; + if (!_shader) + ready &= false; + if(!_texture) + ready &= false; + return ready; +}; + +void DataPlane::render(){ + psc position = _parent->worldPosition(); + + glm::mat4 transform = glm::mat4(1.0); + + glm::mat4 rotx = glm::rotate(transform, static_cast(M_PI_2), glm::vec3(1, 0, 0)); + glm::mat4 roty = glm::rotate(transform, static_cast(M_PI_2), glm::vec3(0, 1, 0)); + + // glm::mat4 rot = glm::mat4(1.0); + for (int i = 0; i < 3; i++){ + for (int j = 0; j < 3; j++){ + transform[i][j] = static_cast(_stateMatrix[i][j]); + } + } + + transform = transform * roty * rotx; + position += transform*glm::vec4(-_pscOffset.x, _pscOffset.z, _pscOffset.y, _pscOffset.w); + + // transform = glm::rotate(transform, _roatation.value()[0], glm::vec3(1,0,0)); + // transform = glm::rotate(transform, _roatation.value()[1], glm::vec3(0,1,0)); + // transform = glm::rotate(transform, _roatation.value()[2], glm::vec3(0,0,1)); + + // Activate shader + _shader->activate(); + glEnable(GL_ALPHA_TEST); + glDisable(GL_CULL_FACE); + + _shader->setUniform("ViewProjection", OsEng.renderEngine().camera()->viewProjectionMatrix()); + _shader->setUniform("ModelTransform", transform); + setPscUniforms(_shader.get(), OsEng.renderEngine().camera(), position); + + ghoul::opengl::TextureUnit unit; + unit.activate(); + _texture->bind(); + _shader->setUniform("texture1", unit); + + glBindVertexArray(_quad); + glDrawArrays(GL_TRIANGLES, 0, 6); + glEnable(GL_CULL_FACE); + _shader->deactivate(); + + +} + +void DataPlane::update(){ + _stateMatrix = SpiceManager::ref().positionTransformMatrix("GALACTIC", "GSM", Time::ref().currentTime()); + +} + +void DataPlane::loadTexture() { + + //std::unique_ptr texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_texturePath)); + 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) { + // std::cout << "texture path: " << absPath(_texturePath) << std::endl; + // LDEBUG("Loaded texture from '" << absPath(_texturePath) << "'"); + + texture->uploadTexture(); + + // Textures of planets looks much smoother with AnisotropicMipMap rather than linear + texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear); + + _texture = std::move(texture); + } + +} + +void DataPlane::createPlane() { + // ============================ + // GEOMETRY (quad) + // ============================ + 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 + -x, -y, 0.0f, w, 0, 1, + x, y, 0.0f, w, 1, 0, + -x, y, 0.0f, w, 0, 0, + -x, -y, 0.0f, w, 0, 1, + x, -y, 0.0f, w, 1, 1, + x, y, 0.0f, w, 1, 0, + }; + + glBindVertexArray(_quad); // bind array + glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer); // bind buffer + 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)); + glEnableVertexAttribArray(1); + glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast(sizeof(GLfloat) * 4)); +} + +}// namespace openspace \ No newline at end of file diff --git a/modules/datasurface/rendering/dataplane.h b/modules/datasurface/rendering/dataplane.h new file mode 100644 index 0000000000..de51b2d82b --- /dev/null +++ b/modules/datasurface/rendering/dataplane.h @@ -0,0 +1,77 @@ +/***************************************************************************************** +* * +* OpenSpace * +* * +* Copyright (c) 2014-2015 * +* * +* 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. * +****************************************************************************************/ + +#ifndef __DATAPLANE_H__ +#define __DATAPLANE_H__ + +// #include +#include +#include +#include +#include +#include +#include + + namespace openspace{ + + class DataPlane : public DataSurface { + public: + DataPlane(std::shared_ptr kw, std::string path); + ~DataPlane(); + + virtual bool initialize(); + virtual bool deinitialize(); + + bool isReady() const; + + virtual void render(); + virtual void update(); + + private: + + void loadTexture(); + void createPlane(); + + // properties::StringProperty _texturePath; + // properties::Vec3Property _roatation; + + // std::unique_ptr _shader; + glm::vec4 _pscOffset; + glm::vec4 _modelScale; + std::shared_ptr _kw; + std::unique_ptr _texture; + + float* _dataSlice; + glm::size3_t _dimensions; + + GLuint _quad; + GLuint _vertexPositionBuffer; + + glm::dmat3 _stateMatrix; + // bool _planeIsDirty; + }; + + } // namespace openspace + +#endif \ No newline at end of file diff --git a/modules/datasurface/rendering/datasurface.cpp b/modules/datasurface/rendering/datasurface.cpp new file mode 100644 index 0000000000..9c520b17b2 --- /dev/null +++ b/modules/datasurface/rendering/datasurface.cpp @@ -0,0 +1,64 @@ +/***************************************************************************************** +* * +* OpenSpace * +* * +* Copyright (c) 2014-2015 * +* * +* 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 + +namespace openspace{ +DataSurface::DataSurface(std::string path) + :_path("path", "Path", path) + ,_shader(nullptr) +{} + +DataSurface::~DataSurface(){} + +bool DataSurface::initialize(){ + _parent = OsEng.renderEngine().scene()->sceneGraphNode("Earth"); + + return true; +} + +bool DataSurface::deinitialize(){ + _parent = nullptr; +} + +void DataSurface::render(){ + +} + +void DataSurface::update(){} + +void DataSurface::setPscUniforms( + ghoul::opengl::ProgramObject* program, + const Camera* camera, + const PowerScaledCoordinate& position) +{ + program->setUniform("campos", camera->position().vec4()); + program->setUniform("objpos", position.vec4()); + program->setUniform("camrot", camera->viewRotationMatrix()); + program->setUniform("scaling", camera->scaling()); +} +}//namespace openspac \ No newline at end of file diff --git a/modules/datasurface/rendering/datasurface.h b/modules/datasurface/rendering/datasurface.h new file mode 100644 index 0000000000..bf95a161b3 --- /dev/null +++ b/modules/datasurface/rendering/datasurface.h @@ -0,0 +1,55 @@ +/***************************************************************************************** +* * +* OpenSpace * +* * +* Copyright (c) 2014-2015 * +* * +* 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. * +****************************************************************************************/ + +#ifndef __DATASURFACE_H__ +#define __DATASURFACE_H__ +#include +#include +#include +#include +#include + +namespace openspace{ +class DataSurface : public properties::PropertyOwner{ +public: + DataSurface(std::string path); + ~DataSurface(); + + virtual bool initialize(); + virtual bool deinitialize(); + + virtual void render(); + virtual void update(); + +protected: + void setPscUniforms(ghoul::opengl::ProgramObject* program, const Camera* camera, const PowerScaledCoordinate& position); + + properties::StringProperty _path; + std::unique_ptr _shader; + + SceneGraphNode* _parent; +}; + +}//namespace openspace +#endif \ No newline at end of file diff --git a/modules/datasurface/rendering/datasurfacecontainer.cpp b/modules/datasurface/rendering/datasurfacecontainer.cpp new file mode 100644 index 0000000000..88f59f5a00 --- /dev/null +++ b/modules/datasurface/rendering/datasurfacecontainer.cpp @@ -0,0 +1,89 @@ +/***************************************************************************************** +* * +* OpenSpace * +* * +* Copyright (c) 2014-2015 * +* * +* 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 + +namespace openspace{ + DataSurfaceContainer::DataSurfaceContainer(const ghoul::Dictionary& dictionary) + :Renderable(dictionary) + { + std::cout << "Created datasurface container" << std::endl; + } + + DataSurfaceContainer::~DataSurfaceContainer(){} + + bool DataSurfaceContainer::initialize(){ + std::cout << "Initialized datasurface container" << std::endl; + + addDataSurface("${OPENSPACE_DATA}/BATSRUS.cdf"); + //addTextureSurface("${OPENSPACE_DATA}/test.png"); + } + bool DataSurfaceContainer::deinitialize(){} + bool DataSurfaceContainer::isReady() const {} + + void DataSurfaceContainer::render(const RenderData& data){ + for(dataSurface : _dataSurfaces) + dataSurface->render(); + } + + void DataSurfaceContainer::update(const UpdateData& data){ + for(dataSurface : _dataSurfaces) + dataSurface->update(); + } + + void DataSurfaceContainer::addDataSurface(std::string path){ + if(FileSys.fileExists(absPath(path))) { + std::shared_ptr ds; + std::shared_ptr kw = std::make_shared(absPath(path)); + + //find out what class to create + ds = std::make_shared(kw, path); + + + ds->initialize(); + _dataSurfaces.push_back(ds); + }else{ + std::cout << "file does not exist"; + } + } + + void DataSurfaceContainer::addTextureSurface(std::string path){ + if(FileSys.fileExists(absPath(path))) { + std::shared_ptr ts; + + //find out what class to create + ts = std::make_shared(path); + std::cout<<"before initialize"<initialize(); + _dataSurfaces.push_back(ts); + }else{ + std::cout << "file does not exist"; + } + } +} \ No newline at end of file diff --git a/modules/datasurface/rendering/datasurfacecontainer.h b/modules/datasurface/rendering/datasurfacecontainer.h new file mode 100644 index 0000000000..d35b0f6282 --- /dev/null +++ b/modules/datasurface/rendering/datasurfacecontainer.h @@ -0,0 +1,54 @@ +/***************************************************************************************** +* * +* OpenSpace * +* * +* Copyright (c) 2014-2015 * +* * +* 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. * +****************************************************************************************/ + +#ifndef __DATASURFACECONTAINER_H__ +#define __DATASURFACECONTAINER_H__ +#include + +namespace openspace{ +class DataSurface; + +class DataSurfaceContainer : public Renderable { +public: + DataSurfaceContainer(const ghoul::Dictionary& dictionary); + ~DataSurfaceContainer(); + + bool initialize() override; + bool deinitialize() override; + + bool isReady() const override; + + virtual void render(const RenderData& data) override; + virtual void update(const UpdateData& data) override; + + void addDataSurface(std::string path); + void addTextureSurface(std::string path); + +private: +std::vector> _dataSurfaces; + +}; +}//namespace openspace + +#endif \ No newline at end of file diff --git a/modules/datasurface/rendering/renderabledataplane.cpp b/modules/datasurface/rendering/renderabledataplane.cpp deleted file mode 100644 index 069d72c6b5..0000000000 --- a/modules/datasurface/rendering/renderabledataplane.cpp +++ /dev/null @@ -1,246 +0,0 @@ -/***************************************************************************************** - * * - * 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 - - -namespace openspace { - -RenderableDataPlane::RenderableDataPlane(const ghoul::Dictionary& dictionary) - : Renderable(dictionary) - ,_texturePath("texture", "Texture", "${OPENSPACE_DATA}/test.png") - ,_roatation("rotation", "Roatation", glm::vec3(0), glm::vec3(0), glm::vec3(2*M_PI)) - , _shader(nullptr) - , _texture(nullptr) - , _quad(0) - , _vertexPositionBuffer(0) -{ - - addProperty(_texturePath); - addProperty(_roatation); - - _texturePath.onChange(std::bind(&RenderableDataPlane::loadTexture, this)); - -} - - -RenderableDataPlane::~RenderableDataPlane(){ -} - -void RenderableDataPlane::updateTexture(){ - int imageSize = 1024; - DownloadManager::FileFuture* future; - while(true) { - std::this_thread::sleep_for(std::chrono::milliseconds(6000)); - future = DlManager.downloadFile( - std::string("http://placehold.it/" + std::to_string(imageSize) + "x" + std::to_string(imageSize)), - absPath("${OPENSPACE_DATA}/dataplane.png"), - true, - [](const DownloadManager::FileFuture& f){ - std::cout<<" =====Download finished===== " << std::endl; - } - ); - - if(future){ - _futureTexture = future; - imageSize-=1; - } - } -} - -bool RenderableDataPlane::initialize() { - - std::thread t = std::thread(std::bind(&RenderableDataPlane::updateTexture, this)); - t.detach(); - - KameleonWrapper kw(absPath("${OPENSPACE_DATA}/BATSRUS.cdf")); - - _dimensions = glm::size3_t(1000,1000,1); - float zSlice = 0.5f; - - _dataSlice = kw.getUniformSliceValues(std::string("p"), _dimensions, zSlice); - - _modelScale = kw.getModelScaleScaled(); - _pscOffset = kw.getModelBarycenterOffsetScaled(); - - std::cout << "Scale: " << _modelScale.x << ", " << _modelScale.y << ", " << _modelScale.z << ", " << _modelScale.w << std::endl; - std::cout << "Offset: " << _pscOffset.x << ", " << _pscOffset.y << ", " << _pscOffset.z << ", " << _pscOffset.w << std::endl; - - glGenVertexArrays(1, &_quad); // generate array - glGenBuffers(1, &_vertexPositionBuffer); // generate buffer - createPlane(); - - if (_shader == nullptr) { - // Plane Program - - RenderEngine& renderEngine = OsEng.renderEngine(); - _shader = renderEngine.buildRenderProgram("PlaneProgram", - "${MODULE_DATASURFACE}/shaders/dataplane_vs.glsl", - "${MODULE_DATASURFACE}/shaders/dataplane_fs.glsl" - ); - if (!_shader) - return false; - } - - loadTexture(); - - return isReady(); -}; - -bool RenderableDataPlane::deinitialize() { - glDeleteVertexArrays(1, &_quad); - _quad = 0; - - glDeleteBuffers(1, &_vertexPositionBuffer); - _vertexPositionBuffer = 0; - - RenderEngine& renderEngine = OsEng.renderEngine(); - if (_shader) { - renderEngine.removeRenderProgram(_shader); - _shader = nullptr; - } - - return true; -}; - -bool RenderableDataPlane::isReady() const { - bool ready = true; - if (!_shader) - ready &= false; - if(!_texture) - ready &= false; - return ready; -}; - -void RenderableDataPlane::render(const RenderData& data) -{ - - auto parent = OsEng.renderEngine().scene()->sceneGraphNode("Earth"); - psc _parentPos = parent->worldPosition(); - glm::dvec4 pos = _parentPos.dvec4(); - // std::cout << pos.x << ", " << pos.y << ", " << pos.z << ", " << pos.w << std::endl; - // std::cout << parent->name() << std::endl; - - float w = (float)_texture->width(); - float h = (float)_texture->height(); - float textureRatio = h/w; - - glm::mat4 transform = glm::mat4(1.0); - transform = glm::rotate(transform, _roatation.value()[0], glm::vec3(1,0,0)); - transform = glm::rotate(transform, _roatation.value()[1], glm::vec3(0,1,0)); - transform = glm::rotate(transform, _roatation.value()[2], glm::vec3(0,0,1)); - - // Activate shader - _shader->activate(); - glEnable(GL_ALPHA_TEST); - glDisable(GL_CULL_FACE); - auto psc = _parentPos; - glm::dvec4 dpc = psc.dvec4(); - psc += glm::vec4(-_pscOffset.x, _pscOffset.y, _pscOffset.z, _pscOffset.w); - - _shader->setUniform("ViewProjection", data.camera.viewProjectionMatrix()); - _shader->setUniform("ModelTransform", transform); - setPscUniforms(_shader.get(), &data.camera, psc); - - ghoul::opengl::TextureUnit unit; - unit.activate(); - _texture->bind(); - _shader->setUniform("texture1", unit); - - glBindVertexArray(_quad); - glDrawArrays(GL_TRIANGLES, 0, 6); - glEnable(GL_CULL_FACE); - _shader->deactivate(); -}; -void RenderableDataPlane::update(const UpdateData& data){ - if (_planeIsDirty) - createPlane(); - - if(_futureTexture && _futureTexture->isFinished){ - _texturePath.set(absPath("${OPENSPACE_DATA}/"+_futureTexture->filePath)); - loadTexture(); - delete _futureTexture; - _futureTexture = nullptr; - } -}; - - -void RenderableDataPlane::loadTexture() { - if (_texturePath.value() != "") { - std::unique_ptr texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_texturePath)); -/* 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) { - std::cout << "texture path: " << absPath(_texturePath) << std::endl; - // LDEBUG("Loaded texture from '" << absPath(_texturePath) << "'"); - - texture->uploadTexture(); - - // Textures of planets looks much smoother with AnisotropicMipMap rather than linear - texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear); - - _texture = std::move(texture); - } - } -} - -void RenderableDataPlane::createPlane() { - // ============================ - // GEOMETRY (quad) - // ============================ - 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 - -x, -y, 0.0f, w, 0, 1, - x, y, 0.0f, w, 1, 0, - -x, y, 0.0f, w, 0, 0, - -x, -y, 0.0f, w, 0, 1, - x, -y, 0.0f, w, 1, 1, - x, y, 0.0f, w, 1, 0, - }; - - glBindVertexArray(_quad); // bind array - glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer); // bind buffer - 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)); - glEnableVertexAttribArray(1); - glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast(sizeof(GLfloat) * 4)); - _planeIsDirty = false; -} -}// namespace openspace \ No newline at end of file diff --git a/modules/datasurface/rendering/textureplane.cpp b/modules/datasurface/rendering/textureplane.cpp new file mode 100644 index 0000000000..096aada5ac --- /dev/null +++ b/modules/datasurface/rendering/textureplane.cpp @@ -0,0 +1,223 @@ +// /***************************************************************************************** +// * * +// * 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 +#include + + + +namespace openspace { + +TexturePlane::TexturePlane(std::string path) + :DataSurface(path) + ,_texture(nullptr) + , _quad(0) + , _vertexPositionBuffer(0) + , _futureTexture(nullptr) +{} + + +TexturePlane::~TexturePlane(){} + + +bool TexturePlane::initialize(){ + DataSurface::initialize(); + std::thread t = std::thread(std::bind(&TexturePlane::updateTexture, this)); + t.detach(); + glGenVertexArrays(1, &_quad); // generate array + glGenBuffers(1, &_vertexPositionBuffer); // generate buffer + createPlane(); + + if (_shader == nullptr) { + // Plane Program + + RenderEngine& renderEngine = OsEng.renderEngine(); + _shader = renderEngine.buildRenderProgram("PlaneProgram", + "${MODULE_DATASURFACE}/shaders/dataplane_vs.glsl", + "${MODULE_DATASURFACE}/shaders/dataplane_fs.glsl" + ); + if (!_shader) + return false; + } + + loadTexture(); + + return isReady(); +} + +bool TexturePlane::deinitialize(){ + DataSurface::deinitialize(); + + glDeleteVertexArrays(1, &_quad); + _quad = 0; + + glDeleteBuffers(1, &_vertexPositionBuffer); + _vertexPositionBuffer = 0; + + RenderEngine& renderEngine = OsEng.renderEngine(); + if (_shader) { + renderEngine.removeRenderProgram(_shader); + _shader = nullptr; + } + + return true; +} + + +bool TexturePlane::isReady() const { + bool ready = true; + if (!_shader) + ready &= false; + if(!_texture) + ready &= false; + return ready; +}; + +void TexturePlane::render(){ + psc position = _parent->worldPosition(); + + glm::mat4 transform = glm::mat4(1.0); + + glm::mat4 rotx = glm::rotate(transform, static_cast(M_PI_2), glm::vec3(1, 0, 0)); + glm::mat4 roty = glm::rotate(transform, static_cast(M_PI_2), glm::vec3(0, 1, 0)); + // glm::mat4 rot = glm::mat4(1.0); +/* for (int i = 0; i < 3; i++){ + for (int j = 0; j < 3; j++){ + transform[i][j] = static_cast(_stateMatrix[i][j]); + } + }*/ + + //transform = transform * roty * rotx; + //position += transform*glm::vec4(-_pscOffset.x, _pscOffset.z, _pscOffset.y, _pscOffset.w); + + // transform = glm::rotate(transform, _roatation.value()[0], glm::vec3(1,0,0)); + // transform = glm::rotate(transform, _roatation.value()[1], glm::vec3(0,1,0)); + // transform = glm::rotate(transform, _roatation.value()[2], glm::vec3(0,0,1)); + + // Activate shader + _shader->activate(); + glEnable(GL_ALPHA_TEST); + glDisable(GL_CULL_FACE); + _shader->setUniform("ViewProjection", OsEng.renderEngine().camera()->viewProjectionMatrix()); + _shader->setUniform("ModelTransform", transform); + setPscUniforms(_shader.get(), OsEng.renderEngine().camera(), position); + ghoul::opengl::TextureUnit unit; + unit.activate(); + _texture->bind(); + _shader->setUniform("texture1", unit); + glBindVertexArray(_quad); + glDrawArrays(GL_TRIANGLES, 0, 6); + glEnable(GL_CULL_FACE); + _shader->deactivate(); + +} + +void TexturePlane::update(){ + _stateMatrix = SpiceManager::ref().positionTransformMatrix("GALACTIC", "GSM", Time::ref().currentTime()); + if(_futureTexture && _futureTexture->isFinished){ + + _path.set(absPath("${OPENSPACE_DATA}/"+_futureTexture->filePath)); + loadTexture(); + + delete _futureTexture; + _futureTexture = nullptr; + } +} + +void TexturePlane::updateTexture(){ + int imageSize = 1024; + DownloadManager::FileFuture* future; + while(true) { + std::this_thread::sleep_for(std::chrono::milliseconds(6000)); + future = DlManager.downloadFile( + std::string("http://placehold.it/" + std::to_string(imageSize) + "x" + std::to_string(imageSize)), + absPath("${OPENSPACE_DATA}/dataplane.png"), + true, + [](const DownloadManager::FileFuture& f){ + std::cout<<"download finished"< texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_path)); + + 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); + } + +} + +void TexturePlane::createPlane() { + // ============================ + // GEOMETRY (quad) + // ============================ + const GLfloat x = 1.0;//_modelScale.x/2.0; + const GLfloat y = 1.0;//_modelScale.y/2.0; + const GLfloat w = 7.0;//_modelScale.w; + const GLfloat vertex_data[] = { // square of two triangles (sigh) + // x y z w s t + -x, -y, 0.0f, w, 0, 1, + x, y, 0.0f, w, 1, 0, + -x, y, 0.0f, w, 0, 0, + -x, -y, 0.0f, w, 0, 1, + x, -y, 0.0f, w, 1, 1, + x, y, 0.0f, w, 1, 0, + }; + + glBindVertexArray(_quad); // bind array + glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer); // bind buffer + 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)); + glEnableVertexAttribArray(1); + glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast(sizeof(GLfloat) * 4)); +} + +}// namespace openspace \ No newline at end of file diff --git a/modules/datasurface/rendering/renderabledataplane.h b/modules/datasurface/rendering/textureplane.h similarity index 79% rename from modules/datasurface/rendering/renderabledataplane.h rename to modules/datasurface/rendering/textureplane.h index b874537ff0..9f5c84faeb 100644 --- a/modules/datasurface/rendering/renderabledataplane.h +++ b/modules/datasurface/rendering/textureplane.h @@ -22,53 +22,49 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#ifndef __RENDERABLEDATAPLANE_H__ -#define __RENDERABLEDATAPLANE_H__ +#ifndef __TEXTUREPLANE_H__ +#define __TEXTUREPLANE_H__ -#include +// #include +#include #include #include #include #include #include +#include namespace openspace{ - class RenderableDataPlane : public Renderable { + class TexturePlane : public DataSurface { public: - RenderableDataPlane(const ghoul::Dictionary& dictionary); - ~RenderableDataPlane(); + TexturePlane(std::string path); + ~TexturePlane(); - bool initialize() override; - bool deinitialize() override; + virtual bool initialize(); + virtual bool deinitialize(); - bool isReady() const override; + bool isReady() const; - virtual void render(const RenderData& data) override; - virtual void update(const UpdateData& data) override; + virtual void render(); + virtual void update(); private: + void loadTexture(); void createPlane(); void updateTexture(); - properties::StringProperty _texturePath; - properties::Vec3Property _roatation; - - std::unique_ptr _shader; std::unique_ptr _texture; - float* _dataSlice; glm::size3_t _dimensions; - glm::vec4 _pscOffset; - glm::vec4 _modelScale; - psc _parentPos; DownloadManager::FileFuture* _futureTexture; GLuint _quad; GLuint _vertexPositionBuffer; - bool _planeIsDirty; + glm::dmat3 _stateMatrix; + // bool _planeIsDirty; }; } // namespace openspace diff --git a/modules/datasurface/shaders/dataplane_vs.glsl b/modules/datasurface/shaders/dataplane_vs.glsl index dc845c65cd..911f770991 100644 --- a/modules/datasurface/shaders/dataplane_vs.glsl +++ b/modules/datasurface/shaders/dataplane_vs.glsl @@ -26,7 +26,6 @@ uniform mat4 ViewProjection; uniform mat4 ModelTransform; -uniform mat4 Translate; layout(location = 0) in vec4 in_position; layout(location = 1) in vec2 in_st; @@ -40,7 +39,6 @@ out float s; void main() { vec4 tmp = in_position; - vec4 position = pscTransform(tmp, ModelTransform); vs_position = tmp; diff --git a/modules/kameleon/src/kameleonwrapper.cpp b/modules/kameleon/src/kameleonwrapper.cpp index 4d1b89615c..b961add8fe 100644 --- a/modules/kameleon/src/kameleonwrapper.cpp +++ b/modules/kameleon/src/kameleonwrapper.cpp @@ -419,6 +419,7 @@ float* KameleonWrapper::getUniformSliceValues( } std::cout << std::endl << std::endl; + delete[] doubleData; return data; }