@@ -156,7 +156,7 @@ void MainWindow::load_scene(const std::string& path)
156156// Constructor.
157157MainWindow::MainWindow ()
158158 : m_query_point_max_serach_radius(10 .0f )
159- , m_query_point_pos(0 . 0f , 2 . 8f , 0 . 4f )
159+ , m_query_point_pos(- 1 . 2f , 1 . 6f , 2 . 8f )
160160{}
161161
162162// Singleton instance.
@@ -170,6 +170,7 @@ void MainWindow::process_glfw_window_inputs()
170170void MainWindow::imgui_draw ()
171171{
172172 static bool show_window = true ;
173+ static bool first_display = true ;
173174
174175 // Top bar
175176 if (ImGui::BeginMainMenuBar ())
@@ -183,6 +184,7 @@ void MainWindow::imgui_draw()
183184 {
184185 ImGui::Begin (" Controls" , &show_window);
185186
187+ if (first_display) ImGui::SetNextTreeNodeOpen (true );
186188 if (ImGui::TreeNode (" Closest point query settings" ))
187189 {
188190 ImGui::Text (" Position" );
@@ -193,6 +195,7 @@ void MainWindow::imgui_draw()
193195 ImGui::TreePop ();
194196 }
195197
198+ if (first_display) ImGui::SetNextTreeNodeOpen (true );
196199 if (ImGui::TreeNode (" Closest point result" ))
197200 {
198201 ImGui::Text (" Position" );
@@ -202,6 +205,7 @@ void MainWindow::imgui_draw()
202205 ImGui::TreePop ();
203206 }
204207
208+ if (first_display) ImGui::SetNextTreeNodeOpen (true );
205209 if (ImGui::TreeNode (" Debug" ))
206210 {
207211 ImGui::Text (
@@ -215,6 +219,8 @@ void MainWindow::imgui_draw()
215219
216220 ImGui::End ();
217221 }
222+
223+ first_display = false ;
218224}
219225
220226void MainWindow::imgui_draw_main_menu_bar ()
@@ -287,15 +293,14 @@ void MainWindow::opengl_draw()
287293
288294void MainWindow::find_closest_point ()
289295{
290- // Invalid search radius, cancel.
291- if (m_query_point_max_serach_radius <= 0 .0f )
292- return ;
296+ // Invalid search radius, don't run.
297+ bool run = m_query_point_max_serach_radius > 0 .0f ;
293298
294299 // Start a timer to know how long it takes.
295300 auto timer_start = std::chrono::high_resolution_clock::now ();
296301
297302 // Run the query.
298- m_closest_point_query->get_closest_point (
303+ bool found = run && m_closest_point_query->get_closest_point (
299304 m_query_point_pos,
300305 m_query_point_max_serach_radius,
301306 m_closest_point_pos);
@@ -304,16 +309,19 @@ void MainWindow::find_closest_point()
304309 m_closest_point_query_time = std::chrono::duration_cast<std::chrono::milliseconds>(timer_stop - timer_start).count ();
305310
306311 // Push the points in a buffer ready to be rendered.
307- std::vector<RasterizedPoints::Point> points = {
308- {
309- m_query_point_pos,
310- { 1.0 , 0.4 , 1.0 , 1.0 } // color
311- },
312- {
312+ std::vector<RasterizedPoints::Point> points;
313+ // Add the query point (in grey).
314+ points.push_back ({
315+ m_query_point_pos,
316+ { 0.8 , 0.8 , 0.8 , 1.0 }
317+ });
318+ // Add the closest result point (in green).
319+ if (found)
320+ points.push_back ({
313321 m_closest_point_pos,
314- { 1 .0 , 0.0 , 1.0 , 0.5 } // color
315- }
316- };
322+ { 0.1 , 1 .0 , 0.1 , 1.0 }
323+ });
324+
317325 m_scene_points.set_points (points);
318326}
319327
0 commit comments