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

Fixed formatting, fixed bug in line data extraction, plotting works now

parent 07858f66
No related branches found
No related tags found
No related merge requests found
......@@ -156,15 +156,15 @@ Heightmap::Heightmap(std::string filename): _filename(filename) {
/*Setup Framebuffer*/
_framebuffer_ptr = std::make_shared<Framebuffer>();
/*Setup plotting vectors*/
_plotAlongX_y = _minX + (_maxY-_minY)/2.f;
_plotAlongY_x = _minX + (_maxX-_minX)/2.f;
_last_plotAlongX_y = -99999.f;
_last_plotAlongY_x = -99999.f;
_plotAlongX_data_x.resize(_Nx);
_plotAlongX_data_h.resize(_Nx);
_plotAlongY_data_y.resize(_Ny);
_plotAlongY_data_h.resize(_Ny);
/*Setup plotting vectors*/
_plotAlongX_y = _minY + (_maxY-_minY)/2.f;
_plotAlongY_x = _minX + (_maxX-_minX)/2.f;
_last_plotAlongX_y = -99999.f;
_last_plotAlongY_x = -99999.f;
_plotAlongX_data_x.resize(_Nx);
_plotAlongX_data_h.resize(_Nx);
_plotAlongY_data_y.resize(_Ny);
_plotAlongY_data_h.resize(_Ny);
}
else {
throw Nt1100_exception("Heightmap::Heightmap(std::string): File " + filename + " contents are empty.");
......@@ -222,76 +222,90 @@ float Heightmap::getSurfaceHeight(unsigned x, unsigned y, glm::mat4 projection,
}
void Heightmap::updatePlotWindow(){
ImGui::Begin("Height Profiles", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
ImGui::SliderFloat("x", &_plotAlongY_x, _minX, _maxX, "%.3f mm");
ImGui::SliderFloat("y", &_plotAlongX_y, _minY, _maxY, "%.3f mm");
_plotHeightLineAlongX(_plotAlongX_y);
_plotHeightLineAlongY(_plotAlongY_x);
ImGui::End();
ImGui::Begin("Height Profiles", nullptr);
ImGui::SliderFloat("Offset y", &_plotAlongX_y, _minY, _maxY, "%.3f mm");
ImGui::SliderFloat("Offset x", &_plotAlongY_x, _minX, _maxX, "%.3f mm");
_plotHeightLineAlongX(_plotAlongX_y);
_plotHeightLineAlongY(_plotAlongY_x);
ImGui::End();
}
void Heightmap::_plotHeightLineAlongX(const float y){
if(y != _last_plotAlongX_y){
_last_plotAlongX_y = y;
if(y > _maxY || y < _minY){
return;
}
//find correct i (row)
//TODO: This has to change when _data changes
size_t stride = 3;
size_t i = 0;
for(; i < _Ny; ++i){
if(_data[stride*i + 1] >= y){
break;
}
}
if(i >= _Ny){
return;
}
//traverse the row, push xs and zs to the plotting vectors
for(size_t j = 0; j < _Nx; ++j){
_plotAlongX_data_x[j] = _data[stride*j*_Ny + i];
_plotAlongX_data_h[j] = _data[stride*j*_Ny + i+2];
}
}
//plot data
if(ImPlot::BeginPlot("Heightplot along x")){
ImPlot::SetupAxes("Position [mm]", "Height [um]");
ImPlot::SetNextLineStyle(ImVec4(0.f,0.5f,1.f,1.f));
ImPlot::PlotLine("Height along x", _plotAlongX_data_x.data(), _plotAlongX_data_h.data(), _Nx);
ImPlot::EndPlot()
}
if(y != _last_plotAlongX_y){
_last_plotAlongX_y = y;
if(y > _maxY || y < _minY){
return;
}
//find correct i (row)
//TODO: This has to change when _data changes
size_t stride = 3;
size_t i = 0;
for(; i < _Ny; ++i){
if(_data[stride*i + 1] >= y){
break;
}
}
if(i >= _Ny){
std::cout << "_plotHeightLineAlongX: Data not found." << std::endl;
return;
}
std::cout << "_plotHeightLineAlongX: Found element " << i << ", y = " << _data[stride * i + 1] << std::endl;
//traverse the row, push xs and zs to the plotting vectors
for(size_t j = 0; j < _Nx; ++j){
_plotAlongX_data_x[j] = _data[stride * j * _Ny + stride * i];
if (_data[stride * j * _Ny + stride * i + 2] != BAD_Z_VALUE) {
_plotAlongX_data_h[j] = _minZ + _zRangeUm * _data[stride * j * _Ny + stride * i + 2];
}
else {
_plotAlongX_data_h[j] = NAN;
}
}
}
//plot data
if(ImPlot::BeginPlot("Heightplot along x")){
ImPlot::SetupAxes("Position [mm]", "Height [um]");
ImPlot::SetNextLineStyle(ImVec4(1.f,0.f,1.f,1.f));
ImPlot::PlotLine("Height along x", _plotAlongX_data_x.data(), _plotAlongX_data_h.data(), _Nx);
ImPlot::EndPlot();
}
}
void Heightmap::_plotHeightLineAlongY(const float x){
if(x != _last_plotAlongY_x){
_last_plotAlongY_x = x;
if(x > _maxX || x < _minX){
return;
}
//find correct i (column)
//TODO: This has to change when _data changes
size_t stride = 3;
size_t i = 0;
for(; i < _Nx; ++i){
if(_data[stride*_Ny*i] >= x){
break;
}
}
if(i >= _Nx){
return;
}
//traverse the column, push ys and zs to the plotting vectors
for(size_t j = 0; j < _Ny; ++j){
_plotAlongY_data_y[j] = _data[i + stride*j + 1];
_plotAlongY_data_h[j] = _data[i + stride*j + 2];
}
}
//plot data
if(ImPlot::BeginPlot("Heightplot along y")){
ImPlot::SetupAxes("Position [mm]", "Height [um]");
ImPlot::SetNextLineStyle(ImVec4(0.f,0.5f,1.f,1.f));
ImPlot::PlotLine("Height along y", _plotAlongY_data_y.data(), _plotAlongY_data_h.data(), _Nx);
ImPlot::EndPlot()
}
if(x != _last_plotAlongY_x){
_last_plotAlongY_x = x;
if(x > _maxX || x < _minX){
return;
}
//find correct i (column)
//TODO: This has to change when _data changes
size_t stride = 3;
size_t i = 0;
for(; i < _Nx; ++i){
if(_data[stride*_Ny*i] >= x){
break;
}
}
if(i >= _Nx){
std::cout << "_plotHeightLineAlongY: Data not found." << std::endl;
return;
}
std::cout << "_plotHeightLineAlongY: Found element " << i << ", x = " << _data[stride * _Ny * i] << std::endl;
//traverse the column, push ys and zs to the plotting vectors
for(size_t j = 0; j < _Ny; ++j){
_plotAlongY_data_y[j] = _data[stride * _Ny * i + stride * j + 1];
if (_data[stride * _Ny * i + stride * j + 2] != BAD_Z_VALUE) {
_plotAlongY_data_h[j] = _minZ + _zRangeUm * _data[stride * _Ny * i + stride * j + 2];
}
else {
_plotAlongY_data_h[j] = NAN;
}
}
}
//plot data
if(ImPlot::BeginPlot("Heightplot along y")){
ImPlot::SetupAxes("Position [mm]", "Height [um]");
ImPlot::SetNextLineStyle(ImVec4(1.f,0.f,0.f,1.f));
ImPlot::PlotLine("Height along y", _plotAlongY_data_y.data(), _plotAlongY_data_h.data(), _Ny);
ImPlot::EndPlot();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment