|
@@ -0,0 +1,90 @@
|
|
|
+#include <QCoreApplication>
|
|
|
+
|
|
|
+
|
|
|
+//sudo apt install libopen3d-dev
|
|
|
+
|
|
|
+#include <open3d/Open3D.h>
|
|
|
+#include <open3d/core/TensorFunction.h>
|
|
|
+#include <open3d/visualization/visualizer/RenderOption.h>
|
|
|
+
|
|
|
+#include <pcl/io/pcd_io.h>
|
|
|
+#include <pcl/common/io.h>
|
|
|
+
|
|
|
+#include <QFile>
|
|
|
+
|
|
|
+bool readpcd(std::string strpcdpath,open3d::t::geometry::PointCloud &cloud)
|
|
|
+{
|
|
|
+ open3d::core::Dtype dtype_f{open3d::core::Dtype::Float32};
|
|
|
+ open3d::core::Device device_type{open3d::core::Device::DeviceType::CPU, 0};
|
|
|
+ std::vector<float> intensities_buffer;
|
|
|
+ std::vector<Eigen::Vector3d> points_buffer;
|
|
|
+
|
|
|
+ pcl::PointCloud<pcl::PointXYZI>::Ptr point_cloud(
|
|
|
+ new pcl::PointCloud<pcl::PointXYZI>());
|
|
|
+
|
|
|
+ pcl::io::loadPCDFile<pcl::PointXYZI>(strpcdpath,*point_cloud);
|
|
|
+
|
|
|
+ int i;
|
|
|
+ int nsize = static_cast<int>(point_cloud->width);
|
|
|
+ for(i=0;i<nsize;i++)
|
|
|
+ {
|
|
|
+ float x,y,z,intens;
|
|
|
+ x = point_cloud->points[i].x;
|
|
|
+ y = point_cloud->points[i].y;
|
|
|
+ z = point_cloud->points[i].z;
|
|
|
+ intens = point_cloud->points[i].intensity;
|
|
|
+ points_buffer.push_back(Eigen::Vector3d(x, y, z));
|
|
|
+ intensities_buffer.push_back(intens);
|
|
|
+ }
|
|
|
+
|
|
|
+ std::vector<float> times_buffer(points_buffer.size(), 0.0f);
|
|
|
+ open3d::core::Tensor positions =
|
|
|
+ open3d::core::eigen_converter::EigenVector3dVectorToTensor(
|
|
|
+ points_buffer, dtype_f, device_type);
|
|
|
+ cloud.SetPointPositions(positions);
|
|
|
+ auto intensity = open3d::core::Tensor(
|
|
|
+ intensities_buffer, {1, static_cast<int>(intensities_buffer.size())},
|
|
|
+ open3d::core::Dtype::Float32);
|
|
|
+ auto time = open3d::core::Tensor(times_buffer,
|
|
|
+ {1, static_cast<int>(times_buffer.size())},
|
|
|
+ open3d::core::Dtype::Float32);
|
|
|
+ cloud.SetPointAttr("intensity", intensity);
|
|
|
+ cloud.SetPointAttr("time", time);
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+void test()
|
|
|
+{
|
|
|
+ auto cloud_ptr = std::make_shared<open3d::t::geometry::PointCloud>();
|
|
|
+ if (readpcd(std::string("/home/nvidia/1.pcd"), *cloud_ptr)) {
|
|
|
+ auto positions = cloud_ptr->GetPointPositions();
|
|
|
+ auto intensities = cloud_ptr->GetPointAttr("intensity").Reshape({-1, 1});
|
|
|
+ auto times = cloud_ptr->GetPointAttr("time").Reshape({-1, 1});
|
|
|
+ auto concat = open3d::core::Concatenate({positions, intensities, times}, 1);
|
|
|
+ float *d_points = nullptr;
|
|
|
+ int num_points = cloud_ptr->ToLegacy().points_.size();
|
|
|
+ float *tmp = (float *)concat.GetDataPtr();
|
|
|
+ open3d::visualization::VisualizerWithKeyCallback vis;
|
|
|
+ vis.CreateVisualizerWindow("Point Cloud Viewer", 1600, 900);
|
|
|
+ vis.GetRenderOption().background_color_ = {0.0, 0.0, 0.0};
|
|
|
+ vis.GetRenderOption().point_color_option_ =
|
|
|
+ open3d::visualization::RenderOption::PointColorOption::Color;
|
|
|
+ vis.GetRenderOption().point_size_ = 1.0;
|
|
|
+ vis.AddGeometry(std::make_shared<open3d::geometry::PointCloud>(
|
|
|
+ cloud_ptr->ToLegacy().PaintUniformColor({1.0, 1.0, 1.0})));
|
|
|
+
|
|
|
+ vis.AddGeometry(std::make_shared<open3d::geometry::PointCloud>(
|
|
|
+ cloud_ptr->ToLegacy().PaintUniformColor({1.0, 1.0, 1.0})));
|
|
|
+
|
|
|
+ vis.Run();
|
|
|
+ vis.DestroyVisualizerWindow();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+int main(int argc, char *argv[])
|
|
|
+{
|
|
|
+ QCoreApplication a(argc, argv);
|
|
|
+
|
|
|
+ test();
|
|
|
+ return a.exec();
|
|
|
+}
|