Exposed exaggeration factor when rendering heightmap.

Added checkbox to select whether to run autoleveled program or not.
Heightmap can handle non integer from_x and to_x.
This commit is contained in:
2023-05-23 14:28:08 +03:00
parent 4e7e059e22
commit b7b9fed0dd
8 changed files with 118 additions and 143 deletions
+1 -81
View File
@@ -349,85 +349,6 @@ GLsizei grbl::program_renderer::update_model_vbo(const grbl::program &pgm) {
min_pos = glm::vec3(std::numeric_limits<float>::max());
max_pos = glm::vec3(std::numeric_limits<float>::min());
min_pos = max_pos = glm::vec3(0);
/*
static auto movement_re = std::regex(R"(([gG]0*1?\s+|[xXyYzZ]\s*[0-9\.\-]+))");
bool is_tool_on = false;
glm::vec3 tool_pos;
min_pos = max_pos = tool_pos = glm::vec3(0);
std::vector<float> buffer_data;
for (auto& i: pgm.instructions) {
if (i.type == grbl::instruction_type::gcode) {
std::vector<std::string> tokens;
std::smatch res;
std::string::const_iterator start(i.command.cbegin());
while (std::regex_search(start, i.command.cend(), res, movement_re)) {
auto str = res[0].str();
// make upper case
std::transform(str.begin(), str.end(), str.begin(), ::toupper);
// remove whitespace from things like "X 123.1234"
str.erase(remove_if(str.begin(), str.end(), isspace), str.end());
tokens.push_back(str);
start = res.suffix().first;
}
if (!tokens.empty()) {
auto new_pos = tool_pos;
for (auto& t: tokens) {
if (t[0] == 'X') {
new_pos.x = std::stof(t.substr(1));
} else if (t[0] == 'Y') {
new_pos.y = std::stof(t.substr(1));
} else if (t[0] == 'Z') {
new_pos.z = std::stof(t.substr(1));
}
}
bool has_g1 = tokens[0][0] == 'G' && std::stoi(tokens[0].substr(1)) == 1;
bool has_g0 = tokens[0][0] == 'G' && std::stoi(tokens[0].substr(1)) == 0;
bool is_plunge = has_g1 && tokens.size() > 1 && tokens[1][0] == 'Z';
bool is_retract = has_g0 && tokens.size() > 1 && tokens[1][0] == 'Z';
is_tool_on = has_g1 || (is_retract ? false : is_tool_on);
auto from_color = glm::vec4(1.0f);
auto to_color = glm::vec4(1.0f);
if (is_tool_on) {
from_color = glm::vec4(1, 0.6, 0.6, 1);
to_color = glm::vec4(1, 0.6, 0.6, 1);
}
if (is_plunge) {
to_color = glm::vec4(1, 0.6, 0.6, 1);
} else if (is_retract) {
to_color = glm::vec4(0.6, 1, 0.6, 1);
}
add_line(buffer_data, tool_pos, from_color, new_pos, to_color);
// calculate extents
min_pos.x = std::min(min_pos.x, new_pos.x);
min_pos.y = std::min(min_pos.y, new_pos.y);
min_pos.z = std::min(min_pos.z, new_pos.z);
max_pos.x = std::max(max_pos.x, new_pos.x);
max_pos.y = std::max(max_pos.y, new_pos.y);
max_pos.z = std::max(max_pos.z, new_pos.z);
tool_pos = new_pos;
}
}
}
*/
std::vector<float> buffer_data;
grbl::grbl_parser parser;
@@ -475,7 +396,7 @@ GLsizei grbl::program_renderer::update_model_vbo(const grbl::program &pgm) {
}
void grbl::program_renderer::update_grid(const grbl::heightmap &grid) {
void grbl::program_renderer::update_grid(const grbl::heightmap &grid, float exaggeration_factor) {
glm::vec4 color = {0.5, 0.3, 0, 1};
@@ -496,7 +417,6 @@ void grbl::program_renderer::update_grid(const grbl::heightmap &grid) {
auto p3 = grid.vertices[next];
// exaggerate Z
auto exaggeration_factor = 100.0f;
p1.z *= exaggeration_factor;
p2.z *= exaggeration_factor;
p3.z *= exaggeration_factor;