当前位置: 首页 > news >正文

STL与PLY格式转化

一、STL转化为PLY

利用PCL库中vtk_lib_io实现,#include <pcl/io/vtk_lib_io.h>,C++语言。

提供一个用于测试的数据:

通过网盘分享的文件:ply_stl
链接: https://pan.baidu.com/s/1xnO5s2kiUf0Cs35XVyfTHA?pwd=xmax 提取码: xmax

#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#include <pcl/io/ply_io.h>
#include <pcl/io/vtk_io.h>
#include <pcl/io/vtk_lib_io.h>
#include <pcl/search/kdtree.h>
#include <pcl/features/normal_3d.h>
#include <pcl/surface/gp3.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <boost/thread/thread.hpp>
#include <vector>
#include <iostream>using namespace pcl;
using namespace std;int main()
{// 读取STL文件vtkSmartPointer<vtkSTLReader> reader4 = vtkSmartPointer<vtkSTLReader>::New();reader4->SetFileName("mesh.stl");reader4->Update();// stl 格式 转出到 ply 格式vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();polydata = reader4->GetOutput();polydata->GetNumberOfPoints();// 展示stlboost::shared_ptr<visualization::PCLVisualizer> stl_viewer(new visualization::PCLVisualizer("STL Viewer"));stl_viewer->addModelFromPolyData(polydata, "mesh");// 创建新的线程显示STL窗口boost::thread stl_thread([&stl_viewer]() {while (!stl_viewer->wasStopped()) {stl_viewer->spinOnce(100);boost::this_thread::sleep(boost::posix_time::microseconds(100000));}});// 保存ply数据vtkSmartPointer<vtkPLYWriter> plyWriter = vtkSmartPointer<vtkPLYWriter>::New();plyWriter->SetFileName("stl2plyData.ply");plyWriter->SetInputConnection(reader4->GetOutputPort());plyWriter->SetFileTypeToASCII();plyWriter->SetColorModeToOff();plyWriter->Update();plyWriter->Write();// 从 ply 格式 转为 pcd 格式PointCloud<PointXYZ>::Ptr cloudPcd(new PointCloud<PointXYZ>());io::vtkPolyDataToPointCloud(polydata, *cloudPcd);// 保存pcd数据io::savePCDFileASCII("ply2PcdData.pcd", *cloudPcd);visualization::PCLVisualizer vis("cloud visualization");vis.getRenderWindow()->GlobalWarningDisplayOff();vis.addCoordinateSystem(5.0);vis.addPointCloud(cloudPcd);while (!vis.wasStopped()){vis.spinOnce();}return 0;
}

二、PLY转化为STL

利用python语言,需要安装numpy-stl安装包。

提供一个用于测试的数据:

通过网盘分享的文件:ply_stl
链接: https://pan.baidu.com/s/1xnO5s2kiUf0Cs35XVyfTHA?pwd=xmax 提取码: xmax

import numpy as np
from stl import meshdef read_ply(file_path):with open(file_path, 'rb') as f:header = f.readline()while not header.startswith(b'element vertex'):header = f.readline()vertex_count = int(header.split()[-1])print("vertex_count = ", vertex_count)while not header.startswith(b'element face'):header = f.readline()face_count = int(header.split()[-1])print("face_count = ", face_count)while not header.startswith(b'end_header'):header = f.readline()# 读取顶点数据vertices = []for i in range(vertex_count):header = f.readline()header = header.split()[:3]for j in range(len(header)):vertices.append(float(header[j]))vertices = np.array(vertices).reshape(-1, 3)# 读取面数据faces = []for i in range(face_count):header = f.readline()header = header.split()[1:]for j in range(len(header)):faces.append(int(header[j]))faces = np.array(faces).reshape(-1, 3)return vertices, facesdef create_stl(vertices, faces, output_file):cube = mesh.Mesh(np.zeros(faces.shape[0], dtype=mesh.Mesh.dtype))for i, f in enumerate(faces):for j in range(3):cube.vectors[i][j] = vertices[f[j], :]# save stl filecube.save(output_file)if __name__ == '__main__':vertice, face = read_ply('mesh.ply')print(vertice.shape)print(face.shape)create_stl(vertice, face, 'mesh.stl')

ply数据格式展示

相关文章:

  • 基于Spring Boot+Vue的减肥健康管理系统设计和实现【原创】(BMI算法,协同过滤算法、图形化分析)
  • Redis 介绍
  • 修复: Flux女生脸不再油光满面, 屁股下巴 -- 超实用Comfyui小技巧
  • css 中 ~ 符号、text-indent、ellipsis、ellipsis-2、text-overflow: ellipsis、::before的使用
  • Day28笔记-Python自动化操作Word
  • 优选驾考系统小程序的设计
  • 工作日志:ruoyi-vue-plus echarts根据窗口大小变化
  • 自己做个国庆75周年头像生成器
  • 基于微信小程序的美食推荐系统
  • 数据结构-栈(理解版)
  • 数据结构之链表(2),双向链表
  • C语言——动态内存分配
  • linux部署redis,整合ansible和redis
  • 前端工程规范-2:JS代码规范(Prettier + ESLint)
  • Python 时间占位符:毫秒的使用
  • 2018天猫双11|这就是阿里云!不止有新技术,更有温暖的社会力量
  • 8年软件测试工程师感悟——写给还在迷茫中的朋友
  • ES6核心特性
  • Java 9 被无情抛弃,Java 8 直接升级到 Java 10!!
  • mysql innodb 索引使用指南
  • Python学习之路16-使用API
  • spark本地环境的搭建到运行第一个spark程序
  • Spring Boot MyBatis配置多种数据库
  • VUE es6技巧写法(持续更新中~~~)
  • Vue2.0 实现互斥
  • vue-router的history模式发布配置
  • XML已死 ?
  • 分享自己折腾多时的一套 vue 组件 --we-vue
  • 机器人定位导航技术 激光SLAM与视觉SLAM谁更胜一筹?
  • 记录一下第一次使用npm
  • 优化 Vue 项目编译文件大小
  • 大数据全解:定义、价值及挑战
  • 树莓派用上kodexplorer也能玩成私有网盘
  • ​Distil-Whisper:比Whisper快6倍,体积小50%的语音识别模型
  • ​力扣解法汇总1802. 有界数组中指定下标处的最大值
  • ​业务双活的数据切换思路设计(下)
  • #### golang中【堆】的使用及底层 ####
  • #Datawhale AI夏令营第4期#多模态大模型复盘
  • #java学习笔记(面向对象)----(未完结)
  • #数据结构 笔记三
  • #我与Java虚拟机的故事#连载14:挑战高薪面试必看
  • (附源码)springboot 基于HTML5的个人网页的网站设计与实现 毕业设计 031623
  • (附源码)基于SSM多源异构数据关联技术构建智能校园-计算机毕设 64366
  • (汇总)os模块以及shutil模块对文件的操作
  • (七)Knockout 创建自定义绑定
  • (十七)Flink 容错机制
  • (四)JPA - JQPL 实现增删改查
  • (未解决)macOS matplotlib 中文是方框
  • (转载)微软数据挖掘算法:Microsoft 时序算法(5)
  • (自适应手机端)响应式新闻博客知识类pbootcms网站模板 自媒体运营博客网站源码下载
  • *算法训练(leetcode)第四十天 | 647. 回文子串、516. 最长回文子序列
  • .md即markdown文件的基本常用编写语法
  • .net core webapi 大文件上传到wwwroot文件夹
  • .NET Core 将实体类转换为 SQL(ORM 映射)
  • .net core 外观者设计模式 实现,多种支付选择