Skip to content

Commit bcf2bfc

Browse files
committed
docs: add comments everywhere
1 parent 64d598b commit bcf2bfc

14 files changed

+84
-35
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ set (CMAKE_CXX_EXTENSIONS OFF)
1818
# Automatically managed dependencies
1919
#
2020
# glm and imgui are git submodules of this project.
21+
#
22+
# nanoflann and GLAD are directly sored in the repository (src/thirdparties)
2123

2224
set(WEB_ROOT "${CMAKE_SOURCE_DIR}/distant/web")
2325
set(GLM_ROOT "${CMAKE_SOURCE_DIR}/distant/glm")

src/core/closest_point_query.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,17 @@ bool ClosestPointQuery::get_closest_point(
3838
{
3939
assert(max_distance > 0.0f);
4040

41+
// nanoflann (the KDTree library) use squared distance. We do the same.
4142
const float max_distance2 = max_distance * max_distance;
4243

43-
// Define how many points we take from the tree to find the closest point in the mesh.
44+
// Define how many points we take from the tree to find the closest point on the mesh.
4445
// A number that is too low will generate incorrect results when the mesh density is high.
45-
// The points we process are the closest points to the query point.
46+
// The points we process are the nearest points in the cloud to the query point.
4647
const std::size_t point_to_process_max_count = 2000;
4748
std::vector<std::size_t> ret_index(point_to_process_max_count);
4849
std::vector<float> out_dist_sqr(point_to_process_max_count);
4950

50-
// Use the KDTree to find the closest points.
51+
// Use the KDTree to find the nearest points to the `query_point`.
5152
const std::size_t num_results =
5253
m_tree_index.knnSearch(
5354
glm::value_ptr(query_point),
@@ -59,24 +60,24 @@ bool ClosestPointQuery::get_closest_point(
5960
float closest_distance2 = 0.0f;
6061

6162
// Find the closest point on the mesh using all points near to `query_point`.
62-
// To do so, we use the triangle on which each point is laying and compute the closest
63-
// point to the quer_point that is on the triangle.
64-
// For all these "triangles points", we keep the L2 closest one to the query point.
63+
// To do so, we use the triangle on which each point is and compute the closest
64+
// point to query_point that is on the triangle.
65+
// For all these "triangles points", we keep the closest one to the query point.
6566
// FIXME: We analyse the same triangles multiple times.
6667
for (std::size_t i = 0; i < num_results; ++i)
6768
{
68-
// Ask the triangle to the point cloud.
69+
// Ask to the point cloud which triangle is this point on.
6970
glm::vec3 v1, v2, v3;
7071
m_mesh_point_cloud.get_triangle(ret_index[i], v1, v2, v3);
7172

72-
// Compute the point on the triangle.
73+
// Compute the closest point to `query_point` that is on the triangle.
7374
glm::vec3 p = closest_point_in_triangle(
7475
query_point,
7576
v1,
7677
v2,
7778
v3);
7879

79-
// Keep the best.
80+
// From all triangles, keep the closest one.
8081
const float distance2_to_triangle = distance2(p, query_point);
8182

8283
if (distance2_to_triangle < max_distance2

src/core/closest_point_query.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ namespace core
1111
{
1212

1313
/**
14-
* @brief Fast closest point to mesh.
14+
* @brief Fast closest point to mesh algortihm implementation.
1515
*
1616
* After creating the query object, just call
1717
* `get_closest_point`.
18-
*
19-
* When creating the query object, a tree will
20-
* be generated to speed up look up time.
18+
*
19+
* This implementation require a point cloud and not a mesh.
2120
*/
2221
class ClosestPointQuery
2322
{

src/core/mesh_point_cloud.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ namespace core
1313

1414
/**
1515
* @brief Create a point cloud using a mesh.
16-
* TODO: Allow to generate points on the mesh to
17-
* increase precision.
16+
* FIXME: To get a better representation of the mesh surface,
17+
* we should generate points on the mesh. At the moment, we
18+
* only use the mesh vertices.
1819
*/
1920
class MeshPointCloud
2021
{

src/core/rasterized_mesh.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ namespace core
1010
{
1111

1212
/**
13-
* @brief Mesh wrapper that can be rendered with OpenGL.
13+
* @brief Mesh wrapper that do everything necessary to
14+
* render the mesh with OpenGL.
1415
*/
1516
class RasterizedMesh
1617
{

src/core/scene.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ std::size_t Scene::get_mesh_count() const
2727
return m_meshes.size();
2828
}
2929

30-
const Mesh& Scene::get_mesh() const
30+
const Mesh& Scene::get_mesh(const std::size_t index) const
3131
{
32-
assert(m_meshes.size() > 0);
33-
return m_meshes[0];
32+
assert(index < m_meshes.size());
33+
return m_meshes[index];
3434
}
3535

3636
void Scene::render() const

src/core/scene.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ class Scene
1818

1919
std::size_t get_mesh_count() const;
2020

21-
// FIXME: Multiple mesh usage is not supported.
22-
const Mesh& get_mesh() const;
21+
const Mesh& get_mesh(const std::size_t index) const;
2322

2423
void render() const;
2524

src/gui/file_system.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ namespace gui
1515
// File system utilities.
1616
//
1717

18+
/**
19+
* @brief Open a window using zenity to let the user choose a file.
20+
*/
1821
inline std::string linux_open_file(
1922
const std::string title,
2023
const std::vector<std::string> file_filters = {});

src/gui/main.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@ int main()
88
gui::MainWindow& window = gui::MainWindow::get_instance();
99

1010
window.init(800, 600);
11+
12+
// Load an asset by default.
1113
window.load_scene("resources/models/teapot.obj");
14+
1215
window.run();
16+
17+
// Close the window.
1318
window.release();
1419

1520
return 0;

src/gui/mainwindow.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
#include <iostream>
2626
#include <string>
2727

28+
// FIXME: This is not the cleanest code from this project.
29+
// Here are some refactoring ideas:
30+
// - Split IMGUI and OpenGL drawing in 2 separate classes.
31+
// - Store algorithm related data in a separate class.
32+
2833
namespace gui
2934
{
3035

@@ -173,7 +178,7 @@ void MainWindow::load_scene(const std::string& path)
173178
}
174179

175180
// Build a point cloud of the mesh.
176-
m_mesh_point_cloud.reset(new core::MeshPointCloud(m_scene->get_mesh()));
181+
m_mesh_point_cloud.reset(new core::MeshPointCloud(m_scene->get_mesh(0)));
177182

178183
// Prepare closest point queries.
179184
m_closest_point_query.reset(new core::ClosestPointQuery(*m_mesh_point_cloud));

0 commit comments

Comments
 (0)