Skip to content

Commit cbecacc

Browse files
committed
WIP-ADD: point cloud diffCheck working
1 parent d3a1c8a commit cbecacc

File tree

11 files changed

+343
-61
lines changed

11 files changed

+343
-61
lines changed
3.55 MB
Loading

deps/fmt

src/diffCheck.cc

Lines changed: 56 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "diffCheck.hh"
22

3-
// #include <open3d/Open3D.h>
3+
#include <open3d/Open3D.h>
44

55
#include <string>
66
#include <iostream>
@@ -13,26 +13,26 @@ namespace diffCheck {
1313

1414
void testOpen3d()
1515
{
16-
// std::shared_ptr<open3d::geometry::PointCloud> cloud(new open3d::geometry::PointCloud());
17-
// // print the number of points in the point cloud
18-
// std::cout << "Point cloud has " << cloud->points_.size() << " points." << std::endl;
19-
// std::cout << "testOpen3d check." << std::endl;
20-
21-
// // fill the point cloud with random points
22-
// cloud->points_.resize(100);
23-
// for (auto &point : cloud->points_) {
24-
// point = Eigen::Vector3d::Random();
25-
// }
26-
// // set the point cloud color to be light blue
27-
// cloud->colors_.resize(100);
28-
// for (auto &color : cloud->colors_) {
29-
// color = Eigen::Vector3d(0.7, 0.7, 1.0);
30-
// }
31-
// // set the normal of the point cloud
32-
// cloud->normals_.resize(100);
33-
// for (auto &normal : cloud->normals_) {
34-
// normal = Eigen::Vector3d(0.0, 0.0, 1.0);
35-
// }
16+
std::shared_ptr<open3d::geometry::PointCloud> cloud(new open3d::geometry::PointCloud());
17+
// print the number of points in the point cloud
18+
std::cout << "Point cloud has " << cloud->points_.size() << " points." << std::endl;
19+
std::cout << "testOpen3d check." << std::endl;
20+
21+
// fill the point cloud with random points
22+
cloud->points_.resize(100);
23+
for (auto &point : cloud->points_) {
24+
point = Eigen::Vector3d::Random();
25+
}
26+
// set the point cloud color to be light blue
27+
cloud->colors_.resize(100);
28+
for (auto &color : cloud->colors_) {
29+
color = Eigen::Vector3d(0.7, 0.7, 1.0);
30+
}
31+
// set the normal of the point cloud
32+
cloud->normals_.resize(100);
33+
for (auto &normal : cloud->normals_) {
34+
normal = Eigen::Vector3d(0.0, 0.0, 1.0);
35+
}
3636
}
3737

3838
void testLibigl()
@@ -50,35 +50,41 @@ namespace diffCheck {
5050
// viewer.data().set_mesh(V, F);
5151
// viewer.launch();
5252

53-
// ########################################
54-
const Eigen::MatrixXd V= (Eigen::MatrixXd(8,3)<<
55-
0.0,0.0,0.0,
56-
0.0,0.0,1.0,
57-
0.0,1.0,0.0,
58-
0.0,1.0,1.0,
59-
1.0,0.0,0.0,
60-
1.0,0.0,1.0,
61-
1.0,1.0,0.0,
62-
1.0,1.0,1.0).finished();
63-
const Eigen::MatrixXi F = (Eigen::MatrixXi(12,3)<<
64-
0,6,4,
65-
0,2,6,
66-
0,3,2,
67-
0,1,3,
68-
2,7,6,
69-
2,3,7,
70-
4,6,7,
71-
4,7,5,
72-
0,4,5,
73-
0,5,1,
74-
1,5,7,
75-
1,7,3).finished();
76-
77-
// Plot the mesh
78-
igl::opengl::glfw::Viewer viewer;
79-
viewer.data().set_mesh(V, F);
80-
viewer.data().set_face_based(true);
81-
viewer.launch();
53+
// show an example for visualizing a point cloud with libigl viewer
54+
// igl::opengl::glfw::Viewer viewer;
55+
56+
57+
58+
59+
// // ########################################
60+
// const Eigen::MatrixXd V= (Eigen::MatrixXd(8,3)<<
61+
// 0.0,0.0,0.0,
62+
// 0.0,0.0,1.0,
63+
// 0.0,1.0,0.0,
64+
// 0.0,1.0,1.0,
65+
// 1.0,0.0,0.0,
66+
// 1.0,0.0,1.0,
67+
// 1.0,1.0,0.0,
68+
// 1.0,1.0,1.0).finished();
69+
// const Eigen::MatrixXi F = (Eigen::MatrixXi(12,3)<<
70+
// 0,6,4,
71+
// 0,2,6,
72+
// 0,3,2,
73+
// 0,1,3,
74+
// 2,7,6,
75+
// 2,3,7,
76+
// 4,6,7,
77+
// 4,7,5,
78+
// 0,4,5,
79+
// 0,5,1,
80+
// 1,5,7,
81+
// 1,7,3).finished();
82+
83+
// // Plot the mesh
84+
// igl::opengl::glfw::Viewer viewer;
85+
// viewer.data().set_mesh(V, F);
86+
// viewer.data().set_face_based(true);
87+
// viewer.launch();
8288
}
8389

8490
} // namespace diffCheck

src/diffCheck.hh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55

66
#include <open3d/Open3D.h>
77

8+
// diffCheck includes
89
#include "diffCheck/libHeaderTemplate.hh" // This is a dummy include to test the include path
10+
#include "diffCheck/geometry/DFPointCloud.hh"
11+
#include "diffCheck/IOManager.hh"
12+
#include "diffCheck/visualizer.hh"
13+
914

1015
namespace diffCheck {
1116
/// @brief Function 1 of the library
@@ -19,8 +24,4 @@ namespace diffCheck {
1924

2025
/// @brief Testing open3d import
2126
void testOpen3d();
22-
23-
/// @brief Testing libigl import
24-
void testLibigl();
25-
2627
} // namespace diffCheck

src/diffCheck/IOManager.cc

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include "IOManager.hh"
2+
3+
#include <igl/readPLY.h>
4+
5+
6+
7+
namespace diffCheck::io
8+
{
9+
// TODO: return a dggeometry::Mesh object
10+
void ReadPLYMeshFromFile(const std::string &filename)
11+
{
12+
Eigen::MatrixXd V;
13+
Eigen::MatrixXi F;
14+
igl::readPLY(filename, V, F);
15+
}
16+
17+
std::shared_ptr<diffCheck::geometry::DFPointCloud> ReadPLYPointCloud(const std::string &filename)
18+
{
19+
std::shared_ptr<diffCheck::geometry::DFPointCloud> pointCloud = std::make_shared<diffCheck::geometry::DFPointCloud>();
20+
Eigen::MatrixXd V;
21+
Eigen::MatrixXd C;
22+
Eigen::MatrixXd N;
23+
Eigen::MatrixXi F;
24+
25+
igl::readPLY(filename, V, F, C, N);
26+
27+
pointCloud->Points.resize(V.rows());
28+
for (int i = 0; i < V.rows(); i++)
29+
{
30+
pointCloud->Points[i] = V.row(i);
31+
}
32+
pointCloud->Colors.resize(C.rows());
33+
for (int i = 0; i < C.rows(); i++)
34+
{
35+
pointCloud->Colors[i] = C.row(i);
36+
}
37+
pointCloud->Normals.resize(N.rows());
38+
for (int i = 0; i < N.rows(); i++)
39+
{
40+
pointCloud->Normals[i] = N.row(i);
41+
}
42+
return pointCloud;
43+
}
44+
} // namespace diffCheck::io

src/diffCheck/IOManager.hh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#pragma once
2+
3+
#include <string>
4+
#include <filesystem>
5+
6+
#include <igl/readPLY.h>
7+
8+
#include "diffCheck/geometry/DFPointCloud.hh"
9+
10+
namespace diffCheck::io
11+
{
12+
/**
13+
* @brief Read a point cloud from a file
14+
*
15+
* @param filename the path to the file with the extension
16+
*/
17+
std::shared_ptr<diffCheck::geometry::DFPointCloud> ReadPLYPointCloud(const std::string &filename);
18+
19+
// TODO: return a dggeometry::Mesh object
20+
/**
21+
* @brief Read mesh of format file
22+
*
23+
* @param filename the path to the file with the extension
24+
*/
25+
void ReadPLYMeshFromFile(const std::string &filename);
26+
} // namespace diffCheck::io
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include "DFPointCloud.hh"
2+
3+
#include "diffCheck/IOManager.hh"
4+
5+
6+
namespace diffCheck::geometry
7+
{
8+
void DFPointCloud::Cvt2DFPointCloud(const std::shared_ptr<open3d::geometry::PointCloud> &O3DPointCloud)
9+
{
10+
if (O3DPointCloud->points_.size() != 0)
11+
for (auto &point : O3DPointCloud->points_)
12+
this->Points.push_back(point);
13+
if (O3DPointCloud->HasColors())
14+
for (auto &color : O3DPointCloud->colors_)
15+
this->Colors.push_back(color);
16+
if (O3DPointCloud->HasNormals())
17+
for (auto &normal : O3DPointCloud->normals_)
18+
this->Normals.push_back(normal);
19+
}
20+
21+
std::shared_ptr<open3d::geometry::PointCloud> DFPointCloud::Cvt2O3DPointCloud()
22+
{
23+
std::shared_ptr<open3d::geometry::PointCloud> O3DPointCloud(new open3d::geometry::PointCloud());
24+
if (this->Points.size() != 0)
25+
for (auto &point : this->Points)
26+
O3DPointCloud->points_.push_back(point);
27+
if (this->Colors.size() != 0)
28+
for (auto &color : this->Colors)
29+
O3DPointCloud->colors_.push_back(color);
30+
if (this->Normals.size() != 0)
31+
for (auto &normal : this->Normals)
32+
O3DPointCloud->normals_.push_back(normal);
33+
return O3DPointCloud;
34+
}
35+
36+
void DFPointCloud::LoadFromPLY(const std::string &path)
37+
{
38+
auto cloud = diffCheck::io::ReadPLYPointCloud(path);
39+
40+
this->Points = cloud->Points;
41+
this->Colors = cloud->Colors;
42+
this->Normals = cloud->Normals;
43+
}
44+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#pragma once
2+
3+
#include <Eigen/Core>
4+
#include <open3d/Open3D.h>
5+
6+
7+
namespace diffCheck::geometry
8+
{
9+
class DFPointCloud
10+
{
11+
public:
12+
DFPointCloud() = default;
13+
~DFPointCloud() = default;
14+
15+
///< Converters from other point cloud datatypes libraries to our format
16+
public:
17+
/**
18+
* @brief Converter from open3d point cloud to our datatype
19+
*
20+
* @param pointCloud the open3d point cloud
21+
*/
22+
void Cvt2DFPointCloud(const std::shared_ptr<open3d::geometry::PointCloud> &O3DPointCloud);
23+
24+
/**
25+
* @brief Convert the DFPointCloud to open3d point cloud
26+
*
27+
* @return std::shared_ptr<open3d::geometry::PointCloud> the open3d point cloud
28+
*/
29+
std::shared_ptr<open3d::geometry::PointCloud> Cvt2O3DPointCloud();
30+
31+
///< I/O loader
32+
public:
33+
/**
34+
* @brief Read a point cloud from a file
35+
*
36+
* @param filename the path to the file with the extension
37+
*/
38+
void LoadFromPLY(const std::string &path);
39+
40+
///< Getters
41+
public:
42+
/// @brief Number of points in the point cloud
43+
int GetNumPoints() const { return this->Points.size(); }
44+
/// @brief Number of colors in the point cloud
45+
int GetNumColors() const { return this->Colors.size(); }
46+
/// @brief Number of normals in the point cloud
47+
int GetNumNormals() const { return this->Normals.size(); }
48+
49+
///< Basic point cloud data
50+
public:
51+
/// @brief Eigen vector of 3D points
52+
std::vector<Eigen::Vector3d> Points;
53+
/// @brief Eigen vector of 3D colors
54+
std::vector<Eigen::Vector3d> Colors;
55+
/// @brief Eigen vector of 3D normals
56+
std::vector<Eigen::Vector3d> Normals;
57+
};
58+
} // namespace diffCheck::geometry

src/diffCheck/visualizer.cc

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include "visualizer.hh"
2+
3+
4+
namespace diffCheck::visualizer
5+
{
6+
void Visualizer::LoadPointCloud(std::shared_ptr<diffCheck::geometry::DFPointCloud> &pointCloud)
7+
{
8+
Eigen::MatrixXd V(pointCloud->Points.size(), 3);
9+
for (int i = 0; i < pointCloud->Points.size(); i++)
10+
{
11+
V(i, 0) = pointCloud->Points[i](0);
12+
V(i, 1) = pointCloud->Points[i](1);
13+
V(i, 2) = pointCloud->Points[i](2);
14+
}
15+
Eigen::MatrixXd C(pointCloud->Colors.size(), 3);
16+
for (int i = 0; i < pointCloud->Colors.size(); i++)
17+
{
18+
C(i, 0) = pointCloud->Colors[i](0);
19+
C(i, 1) = pointCloud->Colors[i](1);
20+
C(i, 2) = pointCloud->Colors[i](2);
21+
}
22+
this->m_Viewer.data().set_points(V, C);
23+
this->m_Viewer.data().point_size = 10;
24+
}
25+
26+
// TODO: implement the diffCHeck mesh object
27+
void Visualizer::LoadMesh(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F)
28+
{
29+
this->m_Viewer.data().set_mesh(V, F);
30+
this->m_Viewer.data().set_face_based(true);
31+
}
32+
33+
void Visualizer::Run()
34+
{
35+
this->m_Viewer.launch(
36+
false, // fullscreen
37+
"DiffCheck", // window title
38+
1280, // window width
39+
720); // window height
40+
}
41+
} // namespace diffCheck::visualizer

0 commit comments

Comments
 (0)