Open3D - C++: how to animate 3D point cloud
- Dominant language
- C++
- Stars
- 14k
- Forks
- 2.6k
- Avg merge
- 5d 18h
- Merged PRs (30d)
- 6
Description
### Checklist
- [X] I have searched for [similar issues](https://github.com/isl-org/Open3D/issues).
- [X] For Python issues, I have tested with the [latest development wheel](http://www.open3d.org/docs/latest/getting_started.html#development-version-pip).
- [X] I have checked the [release documentation](http://www.open3d.org/docs/release/) and the [latest documentation](http://www.open3d.org/docs/latest/) (for `master` branch).
### My Question
In Open3D, with **C++**, how to animate 3D point cloud: same question that this one in python https://stackoverflow.com/questions/65112433/open3d-how-to-update-point-cloud-during-window-running but can't get this to work.
The following code (inspired from github repo example `examples/cpp/PointCloud.cpp`) compile, run (the viewer and point appears), but animation is not rendered
```
>> cat ../examples/cpp/PtCloud.cpp
#include
#include
#include
#include "open3d/Open3D.h"
#include // sleep
using namespace open3d;
void PrintPointCloud(const std::shared_ptr &pointcloud) {
using namespace open3d;
bool pointcloud_has_normal = pointcloud->HasNormals();
utility::LogInfo("Pointcloud has %d points.",
(int)pointcloud->points_.size());
Eigen::Vector3d min_bound = pointcloud->GetMinBound();
Eigen::Vector3d max_bound = pointcloud->GetMaxBound();
utility::LogInfo(
"Bounding box is: ({:.4f}, {:.4f}, {:.4f}) - ({:.4f}, {:.4f}, "
"{:.4f})",
min_bound(0), min_bound(1), min_bound(2), max_bound(0),
max_bound(1), max_bound(2));
for (size_t i = 0; i < pointcloud->points_.size(); i++) {
if (pointcloud_has_normal) {
const Eigen::Vector3d &point = pointcloud->points_[i];
const Eigen::Vector3d &normal = pointcloud->normals_[i];
utility::LogInfo("{:.6f} {:.6f} {:.6f} {:.6f} {:.6f} {:.6f}",
point(0), point(1), point(2), normal(0), normal(1),
normal(2));
} else {
const Eigen::Vector3d &point = pointcloud->points_[i];
utility::LogInfo("{:.6f} {:.6f} {:.6f}", point(0), point(1),
point(2));
}
}
utility::LogInfo("End of the list.");
}
std::shared_ptr pointcloud(new geometry::PointCloud);
bool AnimatePointCloud(visualization::Visualizer * visualizer) {
if (!visualizer) return false;
for (int i = 0; i < 10; i++) {
sleep(2);
pointcloud->points_.push_back(Eigen::Vector3d(0.0, 0.0, i+1.0));
pointcloud->points_.push_back(Eigen::Vector3d(1.0, 0.0, i+1.0));
pointcloud->points_.push_back(Eigen::Vector3d(0.0, 1.0, i+1.0));
PrintPointCloud(pointcloud);
visualizer->UpdateGeometry(pointcloud);
visualizer->PollEvents();
visualizer->UpdateRender();
visualizer->Run();
}
return true;
}
int main(int argc, char *argv[]) {
// 1. test basic pointcloud functions.
pointcloud->points_.push_back(Eigen::Vector3d(0.0, 0.0, 0.0));
pointcloud->points_.push_back(Eigen::Vector3d(1.0, 0.0, 0.0));
pointcloud->points_.push_back(Eigen::Vector3d(0.0, 1.0, 0.0));
PrintPointCloud(pointcloud);
// 2. test pointcloud visualization
visualization::Visualizer visualizer;
visualizer.CreateVisualizerWindow("Open3D", 1600, 900);
visualizer.AddGeometry(pointcloud);
visualizer.RegisterAnimationCallback(AnimatePointCloud);
visualizer.Run();
visualizer.DestroyVisualizerWindow();
return 0;
}
```
The code is supposed to animate points that stack up in animated way: the viewer seems to freeze. Didn't find any C++ example. What's wrong? Is this supported?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.