Skip to content
Snippets Groups Projects
Commit 52602b8e authored by Pascal Engeler's avatar Pascal Engeler
Browse files

Added framebuffer, surface height lookup

parent 0dad947a
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@
#include <glad/glad.h>
#include <SDL.h>
#include <colorscheme.hpp>
#include <framebuffer.hpp>
#include <string>
#include <vector>
......@@ -22,6 +23,9 @@ public:
virtual void upload() override;
virtual void unload() override;
//get deformation height in um at screen coordinate
float getSurfaceHeight(unsigned x, unsigned y, glm::mat4 projection, glm::mat4 view, glm::mat4 model);
private:
//filename of origin
std::string _filename;
......@@ -40,4 +44,5 @@ private:
float _scale;
GLuint _numElements;
std::shared_ptr<Colorscheme> _colorscheme_ptr;
std::shared_ptr<Framebuffer> _framebuffer_ptr;
};
\ No newline at end of file
......@@ -57,6 +57,7 @@ Heightmap::Heightmap(std::string filename): _filename(filename) {
_minZ = min(_data, 2, 3);
_maxZ = max(_data, 2, 3);
_zRangeUm = (_maxZ - _minZ) / 10.; //in um
std::cout << "Identified z range: " << _zRangeUm << " um (" << _minZ << " - " << _maxZ << ")" << std::endl;
/*Throw if _zRange is less than 1 A (i.e. it's probably 0)*/
if (_zRangeUm < 1e-4) {
throw Nt1100_exception("Heightmap::Heightmap(std::string): z range is too close to zero (" + std::to_string(_zRangeUm) + ")");
......@@ -71,8 +72,8 @@ Heightmap::Heightmap(std::string filename): _filename(filename) {
}
}
//recalculate _minZ, maxZ
_minZ = min(_data, 2, 3);
_maxZ = max(_data, 2, 3);
_minZ = min(_data, 2, 3); //should be 0
_maxZ = max(_data, 2, 3); //should be 1
/*Initialize Renderer Infrastructure*/
glGenBuffers(1, &_vbo);
......@@ -150,6 +151,9 @@ Heightmap::Heightmap(std::string filename): _filename(filename) {
_shader_ptr->setFloat("bad_z_value", static_cast<float>(BAD_Z_VALUE));
_shader_ptr->setInt("colorscheme", 0);
_shader_ptr->unuse();
/*Setup Framebuffer*/
_framebuffer_ptr = std::make_shared<Framebuffer>();
}
else {
throw Nt1100_exception("Heightmap::Heightmap(std::string): File " + filename + " contents are empty.");
......@@ -183,4 +187,25 @@ void Heightmap::unload() {
bool Heightmap::is(const std::string filename) const {
return _filename == filename;
}
float Heightmap::getSurfaceHeight(unsigned x, unsigned y, glm::mat4 projection, glm::mat4 view, glm::mat4 model) {
_framebuffer_ptr->bind();
glClearColor(0.f, 0.f, 0.f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
draw(projection, view, model);
auto color = _framebuffer_ptr->getPixel(x, y);
float defo_um = _colorscheme_ptr->color2value(color[0], color[1], color[2]);
_framebuffer_ptr->unbind();
if (defo_um != -1.) {
return defo_um * _zRangeUm;
}
else {
return -1.;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment