这里写自定义目录标题

  • 1 soidworks转.obj
  • 2 .obj文件转.pcd

soidworks 生成PCD点云文件

1 soidworks转.obj

1.1打开soidworks插件
菜单栏–工具—插件—scanto3d
注意:每次重启soildworks都需要重新选择插件

图1 打开scan to 3d

1.2
打开需要转为点云的三维图,将其另存为.stl文件

1.3
再次打开.stl文件,注意:需以网格文件形式打开,参考图3图4

图三

图4

2 .obj文件转.pcd

2.1打开VS
使用以下源码

//   调试》属性》调试>选项》命令参数》中   输入文件名.obj 输出文件名.pcd -no_vis_result
//注意输入文件要放在  工程项目文件夹中//#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/io/pcd_io.h>
#include <pcl/io/vtk_lib_io.h>
#include <pcl/common/transforms.h>
#include <vtkVersion.h>
#include <vtkPLYReader.h>
#include <vtkOBJReader.h>
#include <vtkTriangle.h>
#include <vtkTriangleFilter.h>
#include <vtkPolyDataMapper.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/console/print.h>
#include <pcl/console/parse.h>inline double
uniform_deviate(int seed)
{double ran = seed * (1.0 / (RAND_MAX + 1.0));return ran;
}inline void
randomPointTriangle(float a1, float a2, float a3, float b1, float b2, float b3, float c1, float c2, float c3,float r1, float r2, Eigen::Vector3f& p)
{float r1sqr = std::sqrt(r1);float OneMinR1Sqr = (1 - r1sqr);float OneMinR2 = (1 - r2);a1 *= OneMinR1Sqr;a2 *= OneMinR1Sqr;a3 *= OneMinR1Sqr;b1 *= OneMinR2;b2 *= OneMinR2;b3 *= OneMinR2;c1 = r1sqr * (r2 * c1 + b1) + a1;c2 = r1sqr * (r2 * c2 + b2) + a2;c3 = r1sqr * (r2 * c3 + b3) + a3;p[0] = c1;p[1] = c2;p[2] = c3;
}inline void
randPSurface(vtkPolyData* polydata, std::vector<double>* cumulativeAreas, double totalArea, Eigen::Vector3f& p, bool calcNormal, Eigen::Vector3f& n, bool calcColor, Eigen::Vector3f& c)
{float r = static_cast<float> (uniform_deviate(rand()) * totalArea);std::vector<double>::iterator low = std::lower_bound(cumulativeAreas->begin(), cumulativeAreas->end(), r);vtkIdType el = vtkIdType(low - cumulativeAreas->begin());double A[3], B[3], C[3];vtkIdType npts = 0;vtkIdType* ptIds = nullptr;polydata->GetCellPoints(el, npts, ptIds);polydata->GetPoint(ptIds[0], A);polydata->GetPoint(ptIds[1], B);polydata->GetPoint(ptIds[2], C);if (calcNormal){// OBJ: Vertices are stored in a counter-clockwise order by defaultEigen::Vector3f v1 = Eigen::Vector3f(A[0], A[1], A[2]) - Eigen::Vector3f(C[0], C[1], C[2]);Eigen::Vector3f v2 = Eigen::Vector3f(B[0], B[1], B[2]) - Eigen::Vector3f(C[0], C[1], C[2]);n = v1.cross(v2);n.normalize();}float r1 = static_cast<float> (uniform_deviate(rand()));float r2 = static_cast<float> (uniform_deviate(rand()));randomPointTriangle(float(A[0]), float(A[1]), float(A[2]),float(B[0]), float(B[1]), float(B[2]),float(C[0]), float(C[1]), float(C[2]), r1, r2, p);if (calcColor){vtkUnsignedCharArray* const colors = vtkUnsignedCharArray::SafeDownCast(polydata->GetPointData()->GetScalars());if (colors && colors->GetNumberOfComponents() == 3){double cA[3], cB[3], cC[3];colors->GetTuple(ptIds[0], cA);colors->GetTuple(ptIds[1], cB);colors->GetTuple(ptIds[2], cC);randomPointTriangle(float(cA[0]), float(cA[1]), float(cA[2]),float(cB[0]), float(cB[1]), float(cB[2]),float(cC[0]), float(cC[1]), float(cC[2]), r1, r2, c);}else{static bool printed_once = false;if (!printed_once)PCL_WARN("Mesh has no vertex colors, or vertex colors are not RGB!\n");printed_once = true;}}
}void
uniform_sampling(vtkSmartPointer<vtkPolyData> polydata, std::size_t n_samples, bool calc_normal, bool calc_color, pcl::PointCloud<pcl::PointXYZRGBNormal>& cloud_out)
{polydata->BuildCells();vtkSmartPointer<vtkCellArray> cells = polydata->GetPolys();double p1[3], p2[3], p3[3], totalArea = 0;std::vector<double> cumulativeAreas(cells->GetNumberOfCells(), 0);vtkIdType npts = 0, * ptIds = nullptr;std::size_t cellId = 0;for (cells->InitTraversal(); cells->GetNextCell(npts, ptIds); cellId++){polydata->GetPoint(ptIds[0], p1);polydata->GetPoint(ptIds[1], p2);polydata->GetPoint(ptIds[2], p3);totalArea += vtkTriangle::TriangleArea(p1, p2, p3);cumulativeAreas[cellId] = totalArea;}cloud_out.resize(n_samples);cloud_out.width = static_cast<std::uint32_t> (n_samples);cloud_out.height = 1;for (std::size_t i = 0; i < n_samples; i++){Eigen::Vector3f p;Eigen::Vector3f n(0, 0, 0);Eigen::Vector3f c(0, 0, 0);randPSurface(polydata, &cumulativeAreas, totalArea, p, calc_normal, n, calc_color, c);cloud_out[i].x = p[0];cloud_out[i].y = p[1];cloud_out[i].z = p[2];if (calc_normal){cloud_out[i].normal_x = n[0];cloud_out[i].normal_y = n[1];cloud_out[i].normal_z = n[2];}if (calc_color){cloud_out[i].r = static_cast<std::uint8_t>(c[0]);cloud_out[i].g = static_cast<std::uint8_t>(c[1]);cloud_out[i].b = static_cast<std::uint8_t>(c[2]);}}
}using namespace pcl;
using namespace pcl::io;
using namespace pcl::console;const int default_number_samples = 100000;
const float default_leaf_size = 0.01f;void
printHelp(int, char** argv)
{print_error("Syntax is: %s input.{ply,obj} output.pcd <options>\n", argv[0]);print_info("  where options are:\n");print_info("                     -n_samples X      = number of samples (default: ");print_value("%d", default_number_samples);print_info(")\n");print_info("                     -leaf_size X  = the XYZ leaf size for the VoxelGrid -- for data reduction (default: ");print_value("%f", default_leaf_size);print_info(" m)\n");print_info("                     -write_normals = flag to write normals to the output pcd\n");print_info("                     -write_colors  = flag to write colors to the output pcd\n");print_info("                     -no_vis_result = flag to stop visualizing the generated pcd\n");
}/* ---[ */
int
main(int argc, char** argv)
{print_info("Convert a CAD model to a point cloud using uniform sampling. For more information, use: %s -h\n",argv[0]);if (argc < 3){printHelp(argc, argv);return (-1);}// Parse command line argumentsint SAMPLE_POINTS_ = default_number_samples;parse_argument(argc, argv, "-n_samples", SAMPLE_POINTS_);float leaf_size = default_leaf_size;parse_argument(argc, argv, "-leaf_size", leaf_size);bool vis_result = !find_switch(argc, argv, "-no_vis_result");const bool write_normals = find_switch(argc, argv, "-write_normals");const bool write_colors = find_switch(argc, argv, "-write_colors");// Parse the command line arguments for .ply and PCD filesstd::vector<int> pcd_file_indices = parse_file_extension_argument(argc, argv, ".pcd");if (pcd_file_indices.size() != 1){print_error("Need a single output PCD file to continue.\n");return (-1);}std::vector<int> ply_file_indices = parse_file_extension_argument(argc, argv, ".ply");std::vector<int> obj_file_indices = parse_file_extension_argument(argc, argv, ".obj");if (ply_file_indices.size() != 1 && obj_file_indices.size() != 1){print_error("Need a single input PLY/OBJ file to continue.\n");return (-1);}vtkSmartPointer<vtkPolyData> polydata1 = vtkSmartPointer<vtkPolyData>::New();if (ply_file_indices.size() == 1){pcl::PolygonMesh mesh;pcl::io::loadPolygonFilePLY(argv[ply_file_indices[0]], mesh);pcl::io::mesh2vtk(mesh, polydata1);}else if (obj_file_indices.size() == 1){vtkSmartPointer<vtkOBJReader> readerQuery = vtkSmartPointer<vtkOBJReader>::New();readerQuery->SetFileName(argv[obj_file_indices[0]]);readerQuery->Update();polydata1 = readerQuery->GetOutput();}//make sure that the polygons are triangles!vtkSmartPointer<vtkTriangleFilter> triangleFilter = vtkSmartPointer<vtkTriangleFilter>::New();triangleFilter->SetInputData(polydata1);triangleFilter->Update();vtkSmartPointer<vtkPolyDataMapper> triangleMapper = vtkSmartPointer<vtkPolyDataMapper>::New();triangleMapper->SetInputConnection(triangleFilter->GetOutputPort());triangleMapper->Update();polydata1 = triangleMapper->GetInput();pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr cloud_1(new pcl::PointCloud<pcl::PointXYZRGBNormal>);uniform_sampling(polydata1, SAMPLE_POINTS_, write_normals, write_colors, *cloud_1);// VoxelgridVoxelGrid<PointXYZRGBNormal> grid_;grid_.setInputCloud(cloud_1);grid_.setLeafSize(leaf_size, leaf_size, leaf_size);pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr voxel_cloud(new pcl::PointCloud<pcl::PointXYZRGBNormal>);grid_.filter(*voxel_cloud);if (vis_result){visualization::PCLVisualizer vis3("VOXELIZED SAMPLES CLOUD");vis3.addPointCloud<pcl::PointXYZRGBNormal>(voxel_cloud);if (write_normals)vis3.addPointCloudNormals<pcl::PointXYZRGBNormal>(voxel_cloud, 1, 0.02f, "cloud_normals");vis3.spin();}if (write_normals && write_colors){savePCDFileASCII(argv[pcd_file_indices[0]], *voxel_cloud);}else if (write_normals){pcl::PointCloud<pcl::PointNormal>::Ptr cloud_xyzn(new pcl::PointCloud<pcl::PointNormal>);// Strip uninitialized colors from cloud:pcl::copyPointCloud(*voxel_cloud, *cloud_xyzn);savePCDFileASCII(argv[pcd_file_indices[0]], *cloud_xyzn);}else if (write_colors){pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_xyzrgb(new pcl::PointCloud<pcl::PointXYZRGB>);// Strip uninitialized normals from cloud:pcl::copyPointCloud(*voxel_cloud, *cloud_xyzrgb);savePCDFileASCII(argv[pcd_file_indices[0]], *cloud_xyzrgb);}else // !write_normals && !write_colors{pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_xyz(new pcl::PointCloud<pcl::PointXYZ>);// Strip uninitialized normals and colors from cloud:pcl::copyPointCloud(*voxel_cloud, *cloud_xyz);savePCDFileASCII(argv[pcd_file_indices[0]], *cloud_xyz);}
}

2.2
预先需要将.obj文件放置于工程项目文件夹
修改以下 调试》属性》调试>选项》命令参数》以下内容》
输入文件名.obj 输出文件名.pcd -no_vis_result
注意:输入文件要放在 工程项目文件夹中//

2.3
完成后显示以下

图5

soidworks 生成PCD点云文件相关推荐

  1. Open3d读写pcd点云文件

    1 Open3d 安装 Open3d是由Intel发布的一个开源库,支持快速开发和处理3D数据.Open3D在c++和Python中公开了一组精心选择的数据结构和算法.后端是高度优化的,并且是为并行化 ...

  2. 航片ply点云文件转pcd点云文件 debug流程

    20210508 地图组航片转点云debug过程(一) PLY文件转pcd点云文件debug方法 环境准备 ply转pcd代码 依赖关系的配置 ply数据文件处理 运行成功后的pcd头文件 PLY文件 ...

  3. 生成,保存和转换pcd点云文件

    原文:http://www.voycn.com/article/jiguangslamshengchengpcddianyundetubaocunhegeshizhuanhuan 关于生成和保存的过程 ...

  4. 基恩士CSV点云文件转PCD文件 PYTHON版

    简介 将点云文件从矩阵形式存储的csv点云文件(CloudCompare 称为Matrix CSV)文件转换为PCD格式的点云文件 运行环境 Python3 运行需要的库 numpy open3d f ...

  5. Kitti点云文件bin转pcd

    前言 代码是网上找的(基于ubuntu的),我改成了windows可用的,更改输入输出目录后,可直接用在kitti的点云文件上,将bin格式转成pcd格式. 需要用到pcl库. 运行环境 window ...

  6. 激光SLAM生成并保存pcd点云地图

    本文使用kitti数据集,利用a-loam算法建图 第一步,启动a-loam roslaunch aloam_velodyne aloam_velodyne_HDL_64.launch 第二步,播放k ...

  7. python处理点云数据_python将指定点云文件(asc)转换为PCD格式

    起因 由于自己大部分的点云文件都是.asc格式的,但最近用pcl做点云方面的研究,从asc文件到pcd文件手动转化太麻烦,而且效率较低,故此写一个不太成熟的python脚本实现从asc文件到pcd格式 ...

  8. 从bag包中提取图片和点云数据为pcd格式点云文件

    从bag包中提取图片和点云数据为pcd格式点云文件 1 开始提取bag包之前的准备工作 2 从bag包中提取图片和点云数据 首先说明一下我运行的系统环境: python2 Ubuntu18.04 RO ...

  9. python 从深度相机realsense生成pcl点云

    简单说下步骤: 一.通过realsense取得深度信息和彩色信息 二.获取坐标和色彩信息 三.通过pcl可视化点云 一.通过realsense取得深度信息和彩色信息 ubuntu下intel real ...

最新文章

  1. Android平滑图片加载和缓存库Glide使用详解
  2. Go学习笔记—锁(sync包)
  3. Flask 应用的文件结构
  4. uiuc计算机课程,UIUC计算机科学专业解读
  5. 疫情下远程办公的第二天,躺下来刷刷手机
  6. mysql 延时update_转 MySQL延迟更新索引(delay_key_write)
  7. 磁盘和文件系统的管理
  8. GT-suite v2016的下载和安装
  9. 扫外部二维码进入小程序,并且在小程序内获取二维码链接
  10. Mantle Introduce
  11. 年龄到底怎么算才对_怎么算年龄才是正确的
  12. 思科模拟器 --- 路由器RIP动态路由配置
  13. 产品读书《支付战争:互联网金融创世纪》
  14. (信贷风控八)行为评分卡模型(B卡)的介绍
  15. HttpWebRequest.Create
  16. php+点击图片跳转网页,怎么在图片上加超链接 点击图片跳转到指定网页
  17. pyecharts渲染图片的三种方法
  18. 华为、百度这些大公司都青睐哪些编程语言呢?
  19. TOI2008 大数运算
  20. 人机融合系统的休谟之问到工业智能的成熟应用的联想

热门文章

  1. jquery ajax post 传递数组 ,多checkbox 取值
  2. UVa-10382 Watering Grass **
  3. 教你怎样做好计划 将愿望慢慢实现
  4. linux+free参数类型,linux的free命令
  5. Redis持久化方式之RDB
  6. android窗口动画体系,Android 7.1 GUI系统-窗口管理WMS-动画的执行(七)
  7. cation,validation,qualification有何区别
  8. Ripple_vJZ
  9. 20180321选择排序-简单选择排序
  10. Hoshin Kanri在丰田的应用