mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-24 04:58:59 -05:00
solve merge conflict
This commit is contained in:
@@ -28,6 +28,8 @@
|
||||
#include "ghoul/io/model/modelreadermultiformat.h"
|
||||
#include "ghoul/opengl/vertexbufferobject.h"
|
||||
|
||||
#include <openspace/util/powerscaledcoordinate.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "MultiModelGeometry";
|
||||
}
|
||||
@@ -65,9 +67,16 @@ namespace openspace {
|
||||
_vertices.reserve(vertices.size());
|
||||
for (const auto & v : vertices)
|
||||
{
|
||||
psc p = PowerScaledCoordinate::CreatePowerScaledCoordinate(
|
||||
v.location[0],
|
||||
v.location[1],
|
||||
v.location[2]
|
||||
);
|
||||
|
||||
Vertex vv;
|
||||
memcpy(vv.location, v.location, sizeof(GLfloat) * 3);
|
||||
vv.location[3] = 1.0;
|
||||
//memcpy(vv.location, v.location, sizeof(GLfloat) * 3);
|
||||
memcpy(vv.location, glm::value_ptr(p.vec4()), sizeof(GLfloat) * 4);
|
||||
//vv.location[3] = 1.0;
|
||||
memcpy(vv.tex, v.tex, sizeof(GLfloat) * 2);
|
||||
memcpy(vv.normal, v.normal, sizeof(GLfloat) * 3);
|
||||
_vertices.push_back(vv);
|
||||
|
||||
@@ -257,7 +257,7 @@ void RenderablePlane::createPlane() {
|
||||
// ============================
|
||||
const GLfloat size = _size.value()[0];
|
||||
const GLfloat w = _size.value()[1];
|
||||
const GLfloat vertex_data[] = { // square of two triangles (sigh)
|
||||
const GLfloat vertex_data[] = {
|
||||
// x y z w s t
|
||||
-size, -size, 0.f, w, 0.f, 0.f,
|
||||
size, size, 0.f, w, 1.f, 1.f,
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
#########################################################################################
|
||||
# #
|
||||
# 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(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake)
|
||||
|
||||
set(HEADER_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderabledebugplane.h
|
||||
)
|
||||
source_group("Header Files" FILES ${HEADER_FILES})
|
||||
|
||||
set(SOURCE_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderabledebugplane.cpp
|
||||
)
|
||||
source_group("Source Files" FILES ${SOURCE_FILES})
|
||||
|
||||
set(SHADER_FILES
|
||||
)
|
||||
source_group("Shader Files" FILES ${SHADER_FILES})
|
||||
|
||||
create_new_module(
|
||||
"Debugging"
|
||||
debugging_module
|
||||
${HEADER_FILES} ${SOURCE_FILES} ${SHADER_FILES}
|
||||
)
|
||||
@@ -0,0 +1,48 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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 <modules/debugging/debuggingmodule.h>
|
||||
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <openspace/util/factorymanager.h>
|
||||
|
||||
#include <ghoul/misc/assert.h>
|
||||
|
||||
#include <modules/debugging/rendering/renderabledebugplane.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
DebuggingModule::DebuggingModule()
|
||||
: OpenSpaceModule("Debugging")
|
||||
{}
|
||||
|
||||
void DebuggingModule::internalInitialize() {
|
||||
auto fRenderable = FactoryManager::ref().factory<Renderable>();
|
||||
ghoul_assert(fRenderable, "No renderable factory existed");
|
||||
|
||||
fRenderable->registerClass<RenderableDebugPlane>("RenderableDebugPlane");
|
||||
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
+12
-46
@@ -2,7 +2,7 @@
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2015 *
|
||||
* 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 *
|
||||
@@ -22,55 +22,21 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __HISTOGRAM_H__
|
||||
#define __HISTOGRAM_H__
|
||||
#ifndef __DEBUGGINGMODULE_H__
|
||||
#define __DEBUGGINGMODULE_H__
|
||||
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <openspace/util/openspacemodule.h>
|
||||
|
||||
namespace openspace {
|
||||
class Histogram {
|
||||
|
||||
class DebuggingModule : public OpenSpaceModule {
|
||||
public:
|
||||
Histogram();
|
||||
Histogram(float minBin, float maxBin, int numBins);
|
||||
Histogram(float minBin, float maxBin, int numBins, float *data);
|
||||
Histogram(Histogram&& other);
|
||||
~Histogram();
|
||||
DebuggingModule();
|
||||
|
||||
protected:
|
||||
void internalInitialize() override;
|
||||
};
|
||||
|
||||
Histogram& operator=(Histogram&& other);
|
||||
} // namespace openspace
|
||||
|
||||
int numBins() const;
|
||||
float minBin() const;
|
||||
float maxBin() const;
|
||||
bool isValid() const;
|
||||
|
||||
bool add(float bin, float value);
|
||||
bool add(const Histogram& histogram);
|
||||
bool addRectangle(float lowBin, float highBin, float value);
|
||||
|
||||
float interpolate(float bin) const;
|
||||
float sample(int binIndex) const;
|
||||
const float* data() const;
|
||||
std::vector<std::pair<float,float>> getDecimated(int numBins) const;
|
||||
|
||||
void normalize();
|
||||
void print() const;
|
||||
void generateEqualizer();
|
||||
Histogram equalize();
|
||||
float equalize (float);
|
||||
float entropy();
|
||||
|
||||
private:
|
||||
int _numBins;
|
||||
float _minBin;
|
||||
float _maxBin;
|
||||
|
||||
float* _data;
|
||||
std::vector<float> _equalizer;
|
||||
int _numValues;
|
||||
|
||||
}; // class Histogram
|
||||
} // namespace openspace
|
||||
|
||||
#endif //__HISTOGRAM_H__
|
||||
#endif // __DEBUGGINGMODULE_H__
|
||||
@@ -0,0 +1 @@
|
||||
set(DEFAULT_MODULE ON)
|
||||
@@ -0,0 +1,206 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
// @TODO: Clean up this class and make it not copy much code from RenderablePlane ---abock
|
||||
|
||||
#include <modules/debugging/rendering/renderabledebugplane.h>
|
||||
|
||||
|
||||
#include <openspace/engine/configurationmanager.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/util/powerscaledcoordinate.h>
|
||||
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <modules/newhorizons/rendering/renderableplanetprojection.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem>
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "RenderablePlaneTexture";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
RenderableDebugPlane::RenderableDebugPlane(const ghoul::Dictionary& dictionary)
|
||||
: Renderable(dictionary)
|
||||
, _texture("texture", "Texture", -1, -1, 255)
|
||||
, _billboard("billboard", "Billboard", false)
|
||||
, _size("size", "Size", glm::vec2(1,1), glm::vec2(0.f), glm::vec2(1.f, 25.f))
|
||||
, _origin(Origin::Center)
|
||||
, _shader(nullptr)
|
||||
, _quad(0)
|
||||
, _vertexPositionBuffer(0)
|
||||
{
|
||||
glm::vec2 size;
|
||||
dictionary.getValue("Size", size);
|
||||
_size = size;
|
||||
|
||||
if (dictionary.hasKey("Name")){
|
||||
dictionary.getValue("Name", _nodeName);
|
||||
}
|
||||
|
||||
std::string origin;
|
||||
if (dictionary.getValue("Origin", origin)) {
|
||||
if (origin == "LowerLeft") {
|
||||
_origin = Origin::LowerLeft;
|
||||
}
|
||||
else if (origin == "LowerRight") {
|
||||
_origin = Origin::LowerRight;
|
||||
}
|
||||
else if (origin == "UpperLeft") {
|
||||
_origin = Origin::UpperLeft;
|
||||
}
|
||||
else if (origin == "UpperRight") {
|
||||
_origin = Origin::UpperRight;
|
||||
}
|
||||
else if (origin == "Center") {
|
||||
_origin = Origin::Center;
|
||||
}
|
||||
}
|
||||
|
||||
// Attempt to get the billboard value
|
||||
bool billboard = false;
|
||||
if (dictionary.getValue("Billboard", billboard)) {
|
||||
_billboard = billboard;
|
||||
}
|
||||
|
||||
addProperty(_texture);
|
||||
|
||||
addProperty(_billboard);
|
||||
|
||||
addProperty(_size);
|
||||
_size.onChange([this](){ _planeIsDirty = true; });
|
||||
|
||||
setBoundingSphere(_size.value());
|
||||
}
|
||||
|
||||
RenderableDebugPlane::~RenderableDebugPlane() {
|
||||
}
|
||||
|
||||
bool RenderableDebugPlane::isReady() const {
|
||||
bool ready = true;
|
||||
if (!_shader)
|
||||
ready &= false;
|
||||
return ready;
|
||||
}
|
||||
|
||||
bool RenderableDebugPlane::initialize() {
|
||||
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_BASE}/shaders/plane_vs.glsl",
|
||||
"${MODULE_BASE}/shaders/plane_fs.glsl"
|
||||
);
|
||||
if (!_shader)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return isReady();
|
||||
}
|
||||
|
||||
bool RenderableDebugPlane::deinitialize() {
|
||||
glDeleteVertexArrays(1, &_quad);
|
||||
_quad = 0;
|
||||
|
||||
glDeleteBuffers(1, &_vertexPositionBuffer);
|
||||
_vertexPositionBuffer = 0;
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_shader) {
|
||||
renderEngine.removeRenderProgram(_shader);
|
||||
_shader = nullptr;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RenderableDebugPlane::render(const RenderData& data) {
|
||||
glm::mat4 transform = glm::mat4(1.0);
|
||||
if (_billboard)
|
||||
transform = glm::inverse(data.camera.viewRotationMatrix());
|
||||
|
||||
// Activate shader
|
||||
_shader->activate();
|
||||
|
||||
_shader->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
|
||||
_shader->setUniform("ModelTransform", transform);
|
||||
setPscUniforms(*_shader.get(), data.camera, data.position);
|
||||
|
||||
ghoul::opengl::TextureUnit unit;
|
||||
unit.activate();
|
||||
glBindTexture(GL_TEXTURE_2D, _texture);
|
||||
_shader->setUniform("texture1", unit);
|
||||
|
||||
glBindVertexArray(_quad);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
|
||||
_shader->deactivate();
|
||||
}
|
||||
|
||||
void RenderableDebugPlane::update(const UpdateData& data) {
|
||||
if (_shader->isDirty())
|
||||
_shader->rebuildFromFile();
|
||||
|
||||
if (_planeIsDirty)
|
||||
createPlane();
|
||||
}
|
||||
|
||||
void RenderableDebugPlane::createPlane() {
|
||||
// ============================
|
||||
// GEOMETRY (quad)
|
||||
// ============================
|
||||
const GLfloat size = _size.value()[0];
|
||||
const GLfloat w = _size.value()[1];
|
||||
const GLfloat vertex_data[] = {
|
||||
// x y z w s t
|
||||
-size, -size, 0.f, w, 0.f, 0.f,
|
||||
size, size, 0.f, w, 1.f, 1.f,
|
||||
-size, size, 0.f, w, 0.f, 1.f,
|
||||
-size, -size, 0.f, w, 0.f, 0.f,
|
||||
size, -size, 0.f, w, 1.f, 0.f,
|
||||
size, size, 0.f, w, 1.f, 1.f,
|
||||
};
|
||||
|
||||
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<void*>(0));
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast<void*>(sizeof(GLfloat) * 4));
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,85 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __RENDERABLEDEBUGPLANE_H__
|
||||
#define __RENDERABLEDEBUGPLANE_H__
|
||||
|
||||
#include <openspace/rendering/renderable.h>
|
||||
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/properties/vectorproperty.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
namespace ghoul {
|
||||
namespace filesystem {
|
||||
class File;
|
||||
}
|
||||
namespace opengl {
|
||||
class ProgramObject;
|
||||
class Texture;
|
||||
}
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
struct LinePoint;
|
||||
|
||||
class RenderableDebugPlane: public Renderable {
|
||||
|
||||
enum class Origin {
|
||||
LowerLeft, LowerRight, UpperLeft, UpperRight, Center
|
||||
};
|
||||
|
||||
public:
|
||||
RenderableDebugPlane(const ghoul::Dictionary& dictionary);
|
||||
~RenderableDebugPlane();
|
||||
|
||||
bool initialize() override;
|
||||
bool deinitialize() override;
|
||||
|
||||
bool isReady() const override;
|
||||
|
||||
void render(const RenderData& data) override;
|
||||
void update(const UpdateData& data) override;
|
||||
|
||||
private:
|
||||
void createPlane();
|
||||
|
||||
properties::IntProperty _texture;
|
||||
properties::BoolProperty _billboard;
|
||||
properties::Vec2Property _size;
|
||||
|
||||
Origin _origin;
|
||||
std::string _nodeName;
|
||||
|
||||
bool _planeIsDirty;
|
||||
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _shader;
|
||||
|
||||
GLuint _quad;
|
||||
GLuint _vertexPositionBuffer;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __RENDERABLEDEBUGPLANE_H__
|
||||
@@ -37,7 +37,6 @@ set(HEADER_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/simpletfbrickselector.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablemultiresvolume.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/tsp.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/histogram.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/histogrammanager.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/errorhistogrammanager.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/localerrorhistogrammanager.h
|
||||
@@ -54,7 +53,6 @@ set(SOURCE_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/simpletfbrickselector.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablemultiresvolume.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/tsp.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/histogram.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/histogrammanager.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/errorhistogrammanager.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/localerrorhistogrammanager.cpp
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include <cmath>
|
||||
|
||||
#include <modules/multiresvolume/rendering/errorhistogrammanager.h>
|
||||
#include <modules/multiresvolume/rendering/histogram.h>
|
||||
#include <openspace/util/histogram.h>
|
||||
|
||||
#include <openspace/util/progressbar.h>
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
#include <fstream>
|
||||
#include <modules/multiresvolume/rendering/tsp.h>
|
||||
#include <modules/multiresvolume/rendering/histogram.h>
|
||||
#include <openspace/util/histogram.h>
|
||||
#include <map>
|
||||
|
||||
#include <ghoul/glm.h>
|
||||
|
||||
@@ -1,285 +0,0 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 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 <modules/multiresvolume/rendering/histogram.h>
|
||||
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <cassert>
|
||||
namespace {
|
||||
const std::string _loggerCat = "Histogram";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
Histogram::Histogram()
|
||||
: _minBin(0)
|
||||
, _maxBin(0)
|
||||
, _numBins(-1)
|
||||
, _numValues(0)
|
||||
, _data(nullptr) {}
|
||||
|
||||
Histogram::Histogram(float minBin, float maxBin, int numBins)
|
||||
: _minBin(minBin)
|
||||
, _maxBin(maxBin)
|
||||
, _numBins(numBins)
|
||||
, _numValues(0)
|
||||
, _data(nullptr) {
|
||||
|
||||
_data = new float[numBins];
|
||||
for (int i = 0; i < numBins; ++i) {
|
||||
_data[i] = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
Histogram::Histogram(float minBin, float maxBin, int numBins, float *data)
|
||||
: _minBin(minBin)
|
||||
, _maxBin(maxBin)
|
||||
, _numBins(numBins)
|
||||
, _numValues(0)
|
||||
, _data(data) {}
|
||||
|
||||
Histogram::Histogram(Histogram&& other) {
|
||||
_minBin = other._minBin;
|
||||
_maxBin = other._maxBin;
|
||||
_numBins = other._numBins;
|
||||
_numValues = other._numValues;
|
||||
_data = other._data;
|
||||
other._data = nullptr;
|
||||
}
|
||||
|
||||
Histogram& Histogram::operator=(Histogram&& other) {
|
||||
_minBin = other._minBin;
|
||||
_maxBin = other._maxBin;
|
||||
_numBins = other._numBins;
|
||||
_numValues = other._numValues;
|
||||
_data = other._data;
|
||||
other._data = nullptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Histogram::~Histogram() {
|
||||
if (_data) {
|
||||
delete[] _data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int Histogram::numBins() const {
|
||||
return _numBins;
|
||||
}
|
||||
|
||||
float Histogram::minBin() const {
|
||||
return _minBin;
|
||||
}
|
||||
|
||||
float Histogram::maxBin() const {
|
||||
return _maxBin;
|
||||
}
|
||||
|
||||
bool Histogram::isValid() const {
|
||||
return _numBins != -1;
|
||||
}
|
||||
|
||||
|
||||
bool Histogram::add(float bin, float value) {
|
||||
if (bin < _minBin || bin > _maxBin) {
|
||||
// Out of range
|
||||
return false;
|
||||
}
|
||||
|
||||
float normalizedBin = (bin - _minBin) / (_maxBin - _minBin); // [0.0, 1.0]
|
||||
int binIndex = floor(normalizedBin * _numBins); // [0, _numBins]
|
||||
if (binIndex == _numBins) binIndex--; // [0, _numBins[
|
||||
|
||||
_data[binIndex] += value;
|
||||
_numValues++;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Histogram::add(const Histogram& histogram) {
|
||||
if (_minBin == histogram.minBin() && _maxBin == histogram.maxBin() && _numBins == histogram.numBins()) {
|
||||
|
||||
const float* data = histogram.data();
|
||||
for (int i = 0; i < _numBins; i++) {
|
||||
|
||||
_data[i] += data[i];
|
||||
|
||||
}
|
||||
_numValues += histogram._numValues;
|
||||
return true;
|
||||
} else {
|
||||
LERROR("Dimension mismatch");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool Histogram::addRectangle(float lowBin, float highBin, float value) {
|
||||
if (lowBin == highBin) return true;
|
||||
if (lowBin > highBin) {
|
||||
std::swap(lowBin, highBin);
|
||||
}
|
||||
if (lowBin < _minBin || highBin > _maxBin) {
|
||||
// Out of range
|
||||
return false;
|
||||
}
|
||||
|
||||
float normalizedLowBin = (lowBin - _minBin) / (_maxBin - _minBin);
|
||||
float normalizedHighBin = (highBin - _minBin) / (_maxBin - _minBin);
|
||||
|
||||
float lowBinIndex = normalizedLowBin * _numBins;
|
||||
float highBinIndex = normalizedHighBin * _numBins;
|
||||
|
||||
int fillLow = floor(lowBinIndex);
|
||||
int fillHigh = ceil(highBinIndex);
|
||||
|
||||
for (int i = fillLow; i < fillHigh; i++) {
|
||||
_data[i] += value;
|
||||
}
|
||||
|
||||
if (lowBinIndex > fillLow) {
|
||||
float diff = lowBinIndex - fillLow;
|
||||
_data[fillLow] -= diff * value;
|
||||
}
|
||||
if (highBinIndex < fillHigh) {
|
||||
float diff = -highBinIndex + fillHigh;
|
||||
_data[fillHigh - 1] -= diff * value;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
float Histogram::interpolate(float bin) const {
|
||||
float normalizedBin = (bin - _minBin) / (_maxBin - _minBin);
|
||||
float binIndex = normalizedBin * _numBins - 0.5; // Center
|
||||
|
||||
float interpolator = binIndex - floor(binIndex);
|
||||
int binLow = floor(binIndex);
|
||||
int binHigh = ceil(binIndex);
|
||||
|
||||
// Clamp bins
|
||||
if (binLow < 0) binLow = 0;
|
||||
if (binHigh >= _numBins) binHigh = _numBins - 1;
|
||||
|
||||
return (1.0 - interpolator) * _data[binLow] + interpolator * _data[binHigh];
|
||||
}
|
||||
|
||||
float Histogram::sample(int binIndex) const {
|
||||
assert(binIndex >= 0 && binIndex < _numBins);
|
||||
return _data[binIndex];
|
||||
}
|
||||
|
||||
|
||||
const float* Histogram::data() const {
|
||||
return _data;
|
||||
}
|
||||
|
||||
std::vector<std::pair<float,float>> Histogram::getDecimated(int numBins) const {
|
||||
// Return a copy of _data decimated as in Ljung 2004
|
||||
return std::vector<std::pair<float,float>>();
|
||||
}
|
||||
|
||||
|
||||
void Histogram::normalize() {
|
||||
float sum = 0.0;
|
||||
for (int i = 0; i < _numBins; i++) {
|
||||
sum += _data[i];
|
||||
}
|
||||
for (int i = 0; i < _numBins; i++) {
|
||||
_data[i] /= sum;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Will create an internal array for histogram equalization.
|
||||
* Old histogram value is the index of the array, and the new equalized
|
||||
* value will be the value at the index.
|
||||
*/
|
||||
void Histogram::generateEqualizer(){
|
||||
float previousCdf = 0.0f;
|
||||
_equalizer = std::vector<float>(_numBins, 0.0f);
|
||||
for(int i = 0; i < _numBins; i++){
|
||||
|
||||
float probability = _data[i] / (float)_numValues;
|
||||
float cdf = previousCdf + probability;
|
||||
cdf = std::min(1.0f, cdf);
|
||||
_equalizer[i] = cdf * (_numBins-1);
|
||||
previousCdf = cdf;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Will return a equalized histogram
|
||||
*/
|
||||
Histogram Histogram::equalize(){
|
||||
Histogram equalizedHistogram(_minBin, _maxBin, _numBins);
|
||||
|
||||
for(int i = 0; i < _numBins; i++){
|
||||
equalizedHistogram._data[(int)_equalizer[i]] += _data[i];
|
||||
}
|
||||
equalizedHistogram._numValues = _numValues;
|
||||
return std::move(equalizedHistogram);
|
||||
}
|
||||
|
||||
/*
|
||||
* Given a value within the domain of this histogram (_minBin < value < maxBin),
|
||||
* this method will use its equalizer to return a histogram equalized result.
|
||||
*/
|
||||
float Histogram::equalize(float value){
|
||||
if (value < _minBin || value > _maxBin) {
|
||||
LWARNING("Equalized value is is not within domain of histogram. min: " + std::to_string(_minBin) + " max: " + std::to_string(_maxBin) + " val: " + std::to_string(value));
|
||||
}
|
||||
float normalizedValue = (value-_minBin)/(_maxBin-_minBin);
|
||||
int bin = floor(normalizedValue * _numBins);
|
||||
// If value == _maxBins then bin == _numBins, which is a invalid index.
|
||||
bin = std::min(_numBins-1, bin);
|
||||
|
||||
return _equalizer[bin];
|
||||
}
|
||||
|
||||
float Histogram::entropy(){
|
||||
float entropy;
|
||||
for(int i = 0; i < _numBins; i++){
|
||||
if(_data[i] != 0)
|
||||
entropy -= ((float)_data[i]/_numValues) * log2((float)_data[i]/_numValues);
|
||||
}
|
||||
return entropy;
|
||||
}
|
||||
|
||||
void Histogram::print() const {
|
||||
std::cout << "number of bins: " << _numBins << std::endl
|
||||
<< "range: " << _minBin << " - " << _maxBin << std::endl << std::endl;
|
||||
for (int i = 0; i < _numBins; i++) {
|
||||
float low = _minBin + float(i) / _numBins * (_maxBin - _minBin);
|
||||
float high = low + (_maxBin - _minBin) / float(_numBins);
|
||||
std::cout << i << " [" << low << ", " << high << "]"
|
||||
<< " " << _data[i] << std::endl;
|
||||
}
|
||||
std::cout << std::endl << std::endl << std::endl<< "==============" << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,7 +28,7 @@
|
||||
#include <cassert>
|
||||
|
||||
#include <modules/multiresvolume/rendering/histogrammanager.h>
|
||||
#include <modules/multiresvolume/rendering/histogram.h>
|
||||
#include <openspace/util/histogram.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "HistogramManager";
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
#include <fstream>
|
||||
#include <modules/multiresvolume/rendering/tsp.h>
|
||||
#include <modules/multiresvolume/rendering/histogram.h>
|
||||
#include <openspace/util/histogram.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include <cmath>
|
||||
|
||||
#include <modules/multiresvolume/rendering/localerrorhistogrammanager.h>
|
||||
#include <modules/multiresvolume/rendering/histogram.h>
|
||||
#include <openspace/util/histogram.h>
|
||||
|
||||
#include <openspace/util/progressbar.h>
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
#include <fstream>
|
||||
#include <modules/multiresvolume/rendering/tsp.h>
|
||||
#include <modules/multiresvolume/rendering/histogram.h>
|
||||
#include <openspace/util/histogram.h>
|
||||
#include <map>
|
||||
|
||||
#include <ghoul/glm.h>
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include <modules/multiresvolume/rendering/tsp.h>
|
||||
#include <modules/multiresvolume/rendering/localtfbrickselector.h>
|
||||
#include <modules/multiresvolume/rendering/localerrorhistogrammanager.h>
|
||||
#include <modules/multiresvolume/rendering/histogram.h>
|
||||
#include <openspace/util/histogram.h>
|
||||
#include <openspace/rendering/transferfunction.h>
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include <modules/multiresvolume/rendering/tsp.h>
|
||||
#include <modules/multiresvolume/rendering/simpletfbrickselector.h>
|
||||
#include <modules/multiresvolume/rendering/histogrammanager.h>
|
||||
#include <modules/multiresvolume/rendering/histogram.h>
|
||||
#include <openspace/util/histogram.h>
|
||||
#include <openspace/rendering/transferfunction.h>
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include <modules/multiresvolume/rendering/tsp.h>
|
||||
#include <modules/multiresvolume/rendering/tfbrickselector.h>
|
||||
#include <modules/multiresvolume/rendering/errorhistogrammanager.h>
|
||||
#include <modules/multiresvolume/rendering/histogram.h>
|
||||
#include <openspace/util/histogram.h>
|
||||
#include <openspace/rendering/transferfunction.h>
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
@@ -192,8 +192,8 @@ bool RenderableModelProjection::initialize() {
|
||||
if (_programObject == nullptr) {
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
_programObject = renderEngine.buildRenderProgram("ModelShader",
|
||||
"${MODULES}/newhorizons/shaders/modelShader_vs.glsl",
|
||||
"${MODULES}/newhorizons/shaders/modelShader_fs.glsl");
|
||||
"${MODULE_NEWHORIZONS}/shaders/modelShader_vs.glsl",
|
||||
"${MODULE_NEWHORIZONS}/shaders/modelShader_fs.glsl");
|
||||
|
||||
if (!_programObject)
|
||||
return false;
|
||||
@@ -202,8 +202,8 @@ bool RenderableModelProjection::initialize() {
|
||||
|
||||
if (_fboProgramObject == nullptr) {
|
||||
_fboProgramObject = ghoul::opengl::ProgramObject::Build("ProjectionPass",
|
||||
"${MODULES}/newhorizons/shaders/projectionPass_vs.glsl",
|
||||
"${MODULES}/newhorizons/shaders/projectionPass_fs.glsl");
|
||||
"${MODULE_NEWHORIZONS}/shaders/projectionPass_vs.glsl",
|
||||
"${MODULE_NEWHORIZONS}/shaders/projectionPass_fs.glsl");
|
||||
if (!_fboProgramObject)
|
||||
return false;
|
||||
}
|
||||
@@ -336,7 +336,9 @@ void RenderableModelProjection::render(const RenderData& data) {
|
||||
_viewProjection = data.camera.viewProjectionMatrix();
|
||||
_programObject->setUniform("ViewProjection", _viewProjection);
|
||||
_programObject->setUniform("ModelTransform", _transform);
|
||||
setPscUniforms(*_programObject.get(), data.camera, data.position);
|
||||
setPscUniforms(*_programObject, data.camera, data.position);
|
||||
|
||||
_geometry->setUniforms(*_programObject);
|
||||
|
||||
textureBind();
|
||||
_geometry->render();
|
||||
|
||||
@@ -276,6 +276,13 @@ void RenderablePlaneProjection::updatePlane(const Image img, double currentTime)
|
||||
projection[1][0], projection[1][1], projection[1][2], projection[1][3], 0, 0, // Lower left 4 = 1
|
||||
projection[0][0], projection[0][1], projection[0][2], projection[0][3], 1, 0, // Lower right 5
|
||||
projection[3][0], projection[3][1], projection[3][2], projection[3][3], 1, 1, // Upper left 6 = 2
|
||||
//projection[1][0], projection[1][1], projection[1][2], projection[1][3], 0, 1, // Lower left 1
|
||||
//projection[3][0], projection[3][1], projection[3][2], projection[3][3], 1, 0, // Upper right 2
|
||||
//projection[2][0], projection[2][1], projection[2][2], projection[2][3], 0, 0, // Upper left 3
|
||||
//projection[1][0], projection[1][1], projection[1][2], projection[1][3], 0, 1, // Lower left 4 = 1
|
||||
//projection[0][0], projection[0][1], projection[0][2], projection[0][3], 1, 1, // Lower right 5
|
||||
//projection[3][0], projection[3][1], projection[3][2], projection[3][3], 1, 0, // Upper left 6 = 2
|
||||
|
||||
};
|
||||
//projection[1][0], projection[1][1], projection[1][2], projection[1][3], 0, 1, // Lower left 1
|
||||
// projection[3][0], projection[3][1], projection[3][2], projection[3][3], 1, 0, // Upper right 2
|
||||
|
||||
Reference in New Issue
Block a user