Browse Source

add pointcloudviewer_open3d. not complete.

yuchuli 2 months ago
parent
commit
1392f430bc

+ 39 - 5
src/tool/pcd2bin/main.cpp

@@ -88,10 +88,37 @@ int  GetOptLong(int argc, char *argv[]) {
 
 
 
+void test()
+{
+    QFile xFile;
+    xFile.setFileName("/home/nvidia/CUDA-TransFusion/sample/1.bin");
+    if(xFile.open(QIODevice::ReadOnly))
+    {
+        while(1)
+        {
+        float x,y,z,i,ring;
+        int nread;
+        nread = xFile.read((char *)&x,sizeof(float));
+        if(nread < 1)break;
+        xFile.read((char *)&y,sizeof(float));
+        xFile.read((char *)&z,sizeof(float));
+        xFile.read((char *)&i,sizeof(float));
+        xFile.read((char *)&ring,sizeof(float));
+        std::cout<<x<<" "<<y<<" "<<z<<" "<<i<<std::endl;
+        }
+    }
+    xFile.close();
+}
+
+
+
 int main(int argc, char *argv[])
 {
     QCoreApplication a(argc, argv);
 
+//    test();
+//    return 1;
+
     snprintf(gstrpcdpath,255,"");
     snprintf(gstrbinpath,255,"");
 
@@ -134,15 +161,22 @@ int main(int argc, char *argv[])
     for(i=0;i<nPCount;i++)
     {
         pcl::PointXYZI xp = point_cloud->points[i];
-        double x,y,z,intesi;
+        float x,y,z,intesi;
         x = xp.x;
         y = xp.y;
         z = xp.z;
+
+        if((fabs(x)<1e-3) &&(fabs(y)<1e-3))
+        {
+            continue;
+        }
         intesi = xp.intensity;
-        xFile.write((char *)&x,sizeof(double));
-        xFile.write((char *)&y,sizeof(double));
-        xFile.write((char *)&z,sizeof(double));
-        xFile.write((char *)&intesi,sizeof(double));
+        float ring = 1.0;
+        xFile.write((char *)&x,sizeof(float));
+        xFile.write((char *)&y,sizeof(float));
+        xFile.write((char *)&z,sizeof(float));
+        xFile.write((char *)&intesi,sizeof(float));
+ //       xFile.write((char *)&ring,sizeof(float));
 
     }
     xFile.close();

+ 73 - 0
src/tool/pointcloudviewer_open3d/.gitignore

@@ -0,0 +1,73 @@
+# This file is used to ignore files which are generated
+# ----------------------------------------------------------------------------
+
+*~
+*.autosave
+*.a
+*.core
+*.moc
+*.o
+*.obj
+*.orig
+*.rej
+*.so
+*.so.*
+*_pch.h.cpp
+*_resource.rc
+*.qm
+.#*
+*.*#
+core
+!core/
+tags
+.DS_Store
+.directory
+*.debug
+Makefile*
+*.prl
+*.app
+moc_*.cpp
+ui_*.h
+qrc_*.cpp
+Thumbs.db
+*.res
+*.rc
+/.qmake.cache
+/.qmake.stash
+
+# qtcreator generated files
+*.pro.user*
+
+# xemacs temporary files
+*.flc
+
+# Vim temporary files
+.*.swp
+
+# Visual Studio generated files
+*.ib_pdb_index
+*.idb
+*.ilk
+*.pdb
+*.sln
+*.suo
+*.vcproj
+*vcproj.*.*.user
+*.ncb
+*.sdf
+*.opensdf
+*.vcxproj
+*vcxproj.*
+
+# MinGW generated files
+*.Debug
+*.Release
+
+# Python byte code
+*.pyc
+
+# Binaries
+# --------
+*.dll
+*.exe
+

+ 90 - 0
src/tool/pointcloudviewer_open3d/main.cpp

@@ -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();
+}

+ 46 - 0
src/tool/pointcloudviewer_open3d/pointcloudviewer_open3d.pro

@@ -0,0 +1,46 @@
+QT -= gui
+
+CONFIG += c++14 console
+CONFIG -= app_bundle
+
+# You can make your code fail to compile if it uses deprecated APIs.
+# In order to do so, uncomment the following line.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
+
+SOURCES += \
+        main.cpp
+
+# Default rules for deployment.
+qnx: target.path = /tmp/$${TARGET}/bin
+else: unix:!android: target.path = /opt/$${TARGET}/bin
+!isEmpty(target.path): INSTALLS += target
+
+INCLUDEPATH += /usr/include/eigen3
+
+!include(../../../include/ivpcl.pri ) {
+    error( "Couldn't find the ivpcl.pri file!" )
+}
+
+
+LIBS += -lboost_system -lboost_program_options
+
+unix:LIBS +=  -lpcl_common\
+        -lpcl_features\
+        -lpcl_filters\
+        -lpcl_io\
+        -lpcl_io_ply\
+        -lpcl_kdtree\
+        -lpcl_keypoints\
+        -lpcl_octree\
+        -lpcl_outofcore\
+        -lpcl_people\
+        -lpcl_recognition\
+        -lpcl_registration\
+        -lpcl_sample_consensus\
+        -lpcl_search\
+        -lpcl_segmentation\
+        -lpcl_surface\
+        -lpcl_tracking\
+        -lpcl_visualization
+
+LIBS += -lOpen3D