可视化包含自定义双点结构的PCD

问题描述 投票:0回答:1

我创建了一个自定义的双点类型,用于将点位置存储在PCD文件中。我需要双精度数据类型,因为我的点位于全局坐标中,并且具有非常大的值(从10 ^ 6到10 ^ 7的阶数),并且需要良好的精度。由于值很大,并且默认的FLOAT32精度受到限制,因此存在相当大的数据近似值,在可视化期间也可以看到。

我通过使用我拥有的数据包中来自GPS的初始全局参考坐标转换原始点云来创建此PCD。我使用的是15点精度。

我创建了一个单独的脚本来可视化此自定义点型PCD。但是通过视觉比较,我看不到FLOAT32和双数据类型PCD之间有任何显着差异。

Raw_float_pcd_visualization

Transformed_float_pcd_visualization

Transformed_double_pcd_visualization

您可以看到,transformd_double和transformd_float PCD非常相似且近似。与这两个相比,raw_float PCD相当不错。

我将附加PCD文件以供参考:

raw_float

transformed_float

transformed_double

[我认为我在加载点云时跳过了一些事情,还需要做一些其他更改才能以双点精度显示点。

我使用了pcl_tools的“ pcl_viewer”来可视化FLOAT类型的PCD。

可视化自定义双点结构PCD的代码:

#define PCL_NO_PRECOMPILE
#include <iostream>

// #include "double_viz/pcl_double.h"
#include <pcl-1.7/pcl/common/common.h>
#include <pcl-1.7/pcl/io/pcd_io.h>
#include <pcl-1.7/pcl/visualization/pcl_visualizer.h>
#include <pcl-1.7/pcl/console/parse.h>
#include <pcl-1.7/pcl/point_cloud.h>
#include <pcl-1.7/pcl/point_types.h>

namespace pcl
{
  #define PCL_ADD_UNION_POINT4D_DOUBLE \
    union EIGEN_ALIGN16 { \
      double data[4]; \
      struct { \
        double x; \
        double y; \
        double z; \
      }; \
    };

  struct _PointXYZDouble
  {
    PCL_ADD_UNION_POINT4D_DOUBLE; // This adds the members x,y,z which can also be accessed using the point (which is float[4])

    EIGEN_MAKE_ALIGNED_OPERATOR_NEW
  };

  struct EIGEN_ALIGN16 PointXYZDouble : public _PointXYZDouble
  {
    inline PointXYZDouble (const _PointXYZDouble &p)
    {
      x = p.x; y = p.y; z = p.z; data[3] = 1.0;
    }

    inline PointXYZDouble ()
    {
      x = y = z = 0.0;
      data[3] = 1.0;
    }

    inline PointXYZDouble (double _x, double _y, double _z)
    {
      x = _x; y = _y; z = _z;
      data[3] = 1.0;
    }

    EIGEN_MAKE_ALIGNED_OPERATOR_NEW
  };
}

  POINT_CLOUD_REGISTER_POINT_STRUCT (pcl::_PointXYZDouble,
    (double, x, x)
    (double, y, y)
    (double, z, z)
  )
  POINT_CLOUD_REGISTER_POINT_WRAPPER(pcl::PointXYZDouble, pcl::_PointXYZDouble)


// This function displays the help
void
showHelp(char * program_name)
{
  std::cout << std::endl;
  std::cout << "Usage: " << program_name << " cloud_filename.[pcd]" << std::endl;
  std::cout << "-h:  Show this help." << std::endl;
}

// This is the main function
int
main (int argc, char** argv)
{

  // Show help
  if (pcl::console::find_switch (argc, argv, "-h") || pcl::console::find_switch (argc, argv, "--help")) 
  {
    showHelp (argv[0]);
    return 0;
  }

  // Fetch point cloud filename in arguments | Works with PCD
  std::vector<int> filenames;

  if (filenames.size () != 1)  
  {
    filenames = pcl::console::parse_file_extension_argument (argc, argv, ".pcd");

    if (filenames.size () != 1) 
    {
      showHelp (argv[0]);
      return -1;
    } 
  }

  // Load file | Works with PCD and PLY files
  pcl::PointCloud<pcl::PointXYZDouble>::Ptr source_cloud (new pcl::PointCloud<pcl::PointXYZDouble> ());

    if (pcl::io::loadPCDFile (argv[filenames[0]], *source_cloud) < 0)  
    {
      std::cout << "Error loading point cloud " << argv[filenames[0]] << std::endl << std::endl;
      showHelp (argv[0]);
      return -1;
    }
  // Visualization
//   printf(  "\nPoint cloud colors :  white  = original point cloud\n"
//       "                        red  = transformed point cloud\n");
  pcl::visualization::PCLVisualizer viewer ("Visualize double PCL");

   // Define R,G,B colors for the point cloud
  pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZDouble> source_cloud_color_handler (source_cloud, 100, 100, 100);
  // We add the point cloud to the viewer and pass the color handler
  viewer.addPointCloud (source_cloud, source_cloud_color_handler, "original_cloud");

  viewer.addCoordinateSystem (1.0, "cloud", 0);
  viewer.setBackgroundColor(0.05, 0.05, 0.05, 0); // Setting background to a dark grey
  viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_OPACITY, 1, "original_cloud");
  viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "original_cloud");
  viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_LINE_WIDTH, 1, "original_cloud");
  //viewer.setPosition(800, 400); // Setting visualiser window position

  while (!viewer.wasStopped ()) // Display the visualiser until 'q' key is pressed
  { 
    viewer.spinOnce ();
  }

  return 0;
}

我创建了一个自定义的双点类型,用于将点位置存储在PCD文件中。我需要双精度数据类型,因为我的点位于全局坐标中,并且具有非常大的值(顺序...

double visualization precision point-cloud-library point-clouds
1个回答
0
投票

raw_float文件中,大小字段已定义为每个4个字节:SIZE 4 4 4 4,读取为两倍应为SIZE 8 8 8 8

© www.soinside.com 2019 - 2024. All rights reserved.