Skip to content

Commit 2e6df00

Browse files
committed
Merge branch 'pc' of github.com:resibots/robot_dart into pc
2 parents 03096ef + 3aa154f commit 2e6df00

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

src/examples/cameras.cpp

+9-6
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ int main()
7676
simu.add_robot(robot_dart::Robot::create_ellipsoid({0.2, 0.2, 0.2}, pose, "free", 1., dart::Color::Red(1.), "sphere"));
7777
simu.add_sensor(camera);
7878

79+
simu.set_graphics_freq(20);
80+
7981
simu.run(10.);
8082

8183
// a nested std::vector (w*h*3) of the last image taken can be retrieved
@@ -99,10 +101,9 @@ int main()
99101
auto depth_image = camera->depth_array();
100102

101103
auto small_box = robot_dart::Robot::create_box({0.01, 0.01, 0.01}, Eigen::Vector6d::Zero(), "fixed", 1., dart::Color::Blue(1.), "box_pc");
102-
std::vector<double> data = robot_dart::gui::point_cloud_from_depth_array(depth_image, camera->camera_intrinsic_matrix(), camera->camera_extrinsic_matrix(), camera->camera().far_plane());
103-
Eigen::MatrixXd point_cloud = Eigen::MatrixXd::Map(data.data(), 3, data.size() / 3);
104+
Eigen::MatrixXd point_cloud = robot_dart::gui::point_cloud_from_depth_array(depth_image, camera->camera_intrinsic_matrix(), camera->camera_extrinsic_matrix(), camera->camera().far_plane());
104105
for (int i = 0; i < point_cloud.cols(); i++) {
105-
if (i % 30 == 0) { // do not display all the points in the cloud
106+
if (i % 100 == 0) { // do not display all the points in the cloud
106107
Eigen::Vector6d pose;
107108
pose << 0., 0., 0., point_cloud.col(i);
108109
auto bbox = small_box->clone_ghost("box_" + std::to_string(i), dart::Color::Blue(1.));
@@ -112,16 +113,18 @@ int main()
112113
}
113114
}
114115

115-
simu.set_graphics_freq(20);
116116
simu.world()->setTime(0.);
117117
simu.scheduler().reset(simu.timestep(), true);
118118
while (true) {
119119
if (simu.step())
120120
break;
121121
if (simu.schedule(simu.graphics_freq())) {
122+
auto start = std::chrono::high_resolution_clock::now();
122123
auto depth_image = camera->depth_array();
123-
std::vector<double> data = robot_dart::gui::point_cloud_from_depth_array(depth_image, camera->camera_intrinsic_matrix(), camera->camera_extrinsic_matrix(), camera->camera().far_plane());
124-
std::cout << simu.scheduler().current_time() << ": " << (data.size() / 3) << std::endl;
124+
Eigen::MatrixXd data = robot_dart::gui::point_cloud_from_depth_array(depth_image, camera->camera_intrinsic_matrix(), camera->camera_extrinsic_matrix(), camera->camera().far_plane());
125+
auto end = std::chrono::high_resolution_clock::now();
126+
std::chrono::duration<double, std::milli> t_pc = (end - start);
127+
std::cout << simu.scheduler().current_time() << ": " << (data.cols()) << " -> " << t_pc.count() << "ms" << std::endl;
125128
}
126129
}
127130

src/python/gui.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ namespace robot_dart {
293293
sm.def("save_png_image", static_cast<void (*)(const std::string&, const gui::Image&)>(&gui::save_png_image));
294294
sm.def("save_png_image", static_cast<void (*)(const std::string&, const gui::GrayscaleImage&)>(&gui::save_png_image));
295295
sm.def("convert_rgb_to_grayscale", gui::convert_rgb_to_grayscale);
296-
sm.def("point_cloud_from_depth_array", gui::point_cloud_from_depth_array,
296+
sm.def("point_cloud_from_depth_array", gui::point_cloud_from_depth_array_vector,
297297
py::arg("depth_image"),
298298
py::arg("intrinsic_matrix"),
299299
py::arg("tf"),

src/robot_dart/gui/helper.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ namespace robot_dart {
5858
return gray;
5959
}
6060

61-
std::vector<double> point_cloud_from_depth_array(const DepthImage& depth_image, const Eigen::Matrix3d& intrinsic_matrix, const Eigen::Matrix4d& tf, double far_plane)
61+
std::vector<double> point_cloud_from_depth_array_vector(const DepthImage& depth_image, const Eigen::Matrix3d& intrinsic_matrix, const Eigen::Matrix4d& tf, double far_plane)
6262
{
6363
// This is assuming that K is normal intrisinc matrix (i.e., camera pointing to +Z),
6464
// but an OpenGL camera (i.e., pointing to -Z). Thus it transforms the points accordingly
@@ -102,5 +102,11 @@ namespace robot_dart {
102102

103103
return point_cloud;
104104
}
105+
106+
Eigen::MatrixXd point_cloud_from_depth_array(const DepthImage& depth_image, const Eigen::Matrix3d& intrinsic_matrix, const Eigen::Matrix4d& tf, double far_plane)
107+
{
108+
auto v = point_cloud_from_depth_array_vector(depth_image, intrinsic_matrix, tf, far_plane);
109+
return Eigen::MatrixXd::Map(v.data(), 3, v.size() / 3);
110+
}
105111
} // namespace gui
106112
} // namespace robot_dart

src/robot_dart/gui/helper.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ namespace robot_dart {
2929

3030
GrayscaleImage convert_rgb_to_grayscale(const Image& rgb);
3131

32-
std::vector<double> point_cloud_from_depth_array(const DepthImage& depth_image, const Eigen::Matrix3d& intrinsic_matrix, const Eigen::Matrix4d& tf, double far_plane = 1000.);
32+
std::vector<double> point_cloud_from_depth_array_vector(const DepthImage& depth_image, const Eigen::Matrix3d& intrinsic_matrix, const Eigen::Matrix4d& tf, double far_plane = 1000.);
33+
Eigen::MatrixXd point_cloud_from_depth_array(const DepthImage& depth_image, const Eigen::Matrix3d& intrinsic_matrix, const Eigen::Matrix4d& tf, double far_plane = 1000.);
3334
} // namespace gui
3435
} // namespace robot_dart
3536

0 commit comments

Comments
 (0)