Skip to content

Commit 0a640e4

Browse files
authored
Make vertex rendering scale changeable (#46)
* set up for scaling keyframe size in the shader * adjust the rendered keyframe scale * scale the graph edges with the keyframe scale
1 parent 7d80d4b commit 0a640e4

File tree

7 files changed

+27
-3
lines changed

7 files changed

+27
-3
lines changed

data/shader/rainbow.vert

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#version 330
22
uniform float point_size;
33
uniform float point_scale;
4+
uniform bool apply_keyframe_scale;
5+
uniform float keyframe_scale;
46
uniform mat4 model_matrix;
57
uniform mat4 view_matrix;
68
uniform mat4 projection_matrix;
@@ -44,7 +46,13 @@ vec4 rainbow(vec3 position) {
4446
}
4547

4648
void main() {
47-
vec4 world_position = model_matrix * vec4(vert_position, 1.0);
49+
vec4 world_position;
50+
if(apply_keyframe_scale){
51+
world_position = model_matrix * vec4(keyframe_scale * vert_position, 1.0);
52+
}
53+
else{
54+
world_position = model_matrix * vec4(vert_position, 1.0);
55+
}
4856
frag_world_position = world_position.xyz;
4957
gl_Position = projection_matrix * view_matrix * world_position;
5058

include/glk/glsl_shader.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ class GLSLShader {
5050
return mat;
5151
}
5252

53+
float get_uniform1f(const std::string& name){
54+
float res;
55+
glGetUniformfv(shader_program, uniform(name), &res);
56+
return res;
57+
}
58+
5359
void set_uniform(const std::string& name, int value) { glUniform1i(uniform(name), value); }
5460
void set_uniform(const std::string& name, float value) { glUniform1f(uniform(name), value); }
5561
void set_uniform(const std::string& name, const Eigen::Vector2f& vector) { glUniform2fv(uniform(name), 1, vector.data()); }

include/guik/gl_canvas.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class GLCanvas {
4949

5050
private:
5151
float point_size;
52+
float keyframe_scale;
5253
float min_z;
5354
float max_z;
5455
bool z_clipping;

include/hdl_graph_slam/view/keyframe_view.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ class KeyFrameView : public VertexView {
4545
shader.set_uniform("material_color", Eigen::Vector4f(1.0f, 0.0f, 0.0f, 1.0f));
4646
shader.set_uniform("info_values", Eigen::Vector4i(VERTEX | KEYFRAME, kf->id(), 0, 0));
4747

48+
shader.set_uniform("apply_keyframe_scale", true);
4849
model_matrix.block<3, 3>(0, 0) *= 0.35;
4950
shader.set_uniform("model_matrix", model_matrix);
5051
const auto& sphere = glk::Primitives::instance()->primitive(glk::Primitives::SPHERE);
5152
sphere.draw(shader);
53+
shader.set_uniform("apply_keyframe_scale", false);
5254
}
5355

5456
virtual void draw(const DrawFlags& flags, glk::GLSLShader& shader, const Eigen::Vector4f& color, const Eigen::Matrix4f& model_matrix) override {
@@ -68,8 +70,10 @@ class KeyFrameView : public VertexView {
6870

6971
shader.set_uniform("color_mode", 1);
7072
shader.set_uniform("info_values", Eigen::Vector4i(VERTEX | KEYFRAME, kf->id(), 0, 0));
73+
shader.set_uniform("apply_keyframe_scale", true);
7174
const auto& sphere = glk::Primitives::instance()->primitive(glk::Primitives::SPHERE);
7275
sphere.draw(shader);
76+
shader.set_uniform("apply_keyframe_scale", false);
7377
}
7478

7579
private:

include/hdl_graph_slam/view/line_buffer.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class LineBuffer {
3131
shader.set_uniform("color_mode", 2);
3232
shader.set_uniform("model_matrix", Eigen::Matrix4f::Identity().eval());
3333

34-
glk::Lines lines(0.1f, vertices, colors, infos);
34+
float line_width = 0.1f * shader.get_uniform1f("keyframe_scale");
35+
glk::Lines lines(line_width, vertices, colors, infos);
3536
lines.draw(shader);
3637
}
3738

src/guik/gl_canvas.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace guik {
2525
* @param data_directory
2626
* @param size
2727
*/
28-
GLCanvas::GLCanvas(const std::string& data_directory, const Eigen::Vector2i& size) : size(size), point_size(50.0f), min_z(-1.5f), max_z(5.0f), z_clipping(true) {
28+
GLCanvas::GLCanvas(const std::string& data_directory, const Eigen::Vector2i& size) : size(size), point_size(50.0f), keyframe_scale(1.0f), min_z(-1.5f), max_z(5.0f), z_clipping(true) {
2929
frame_buffer.reset(new glk::FrameBuffer(size));
3030
frame_buffer->add_color_buffer(GL_RGBA32I, GL_RGBA_INTEGER, GL_INT);
3131

@@ -94,6 +94,7 @@ void GLCanvas::bind(bool clear_buffers) {
9494
shader->set_uniform("color_mode", 0);
9595
shader->set_uniform("point_scale", 1.0f);
9696
shader->set_uniform("point_size", point_size);
97+
shader->set_uniform("keyframe_scale", keyframe_scale);
9798

9899
glEnable(GL_DEPTH_TEST);
99100
}
@@ -237,6 +238,7 @@ Eigen::Vector3f GLCanvas::unproject(const Eigen::Vector2i& p, float depth) const
237238
void GLCanvas::draw_ui() {
238239
ImGui::Begin("shader setting", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
239240
ImGui::DragFloat("point_size", &point_size, 10.0f);
241+
ImGui::DragFloat("keyframe_scale", &keyframe_scale, 0.1f);
240242
ImGui::DragFloat("min_z", &min_z, 0.1f);
241243
ImGui::DragFloat("max_z", &max_z, 0.1f);
242244
ImGui::Checkbox("z_clipping", &z_clipping);

src/odometry2graph.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ struct OdometryFrame {
100100

101101
shader.set_uniform("color_mode", 1);
102102
shader.set_uniform("material_color", Eigen::Vector4f(1.0f, 0.0f, 0.0f, 1.0f));
103+
shader.set_uniform("apply_keyframe_scale", true);
103104
auto& sphere = glk::Primitives::instance()->primitive(glk::Primitives::SPHERE);
104105
sphere.draw(shader);
106+
shader.set_uniform("apply_keyframe_scale", false);
105107
}
106108
private:
107109
pcl::PointCloud<pcl::PointXYZI>::Ptr load_cloud(const std::string& filename) const {

0 commit comments

Comments
 (0)