c++实习项目3D模型显示系统

        通过调用pcl相关库及函数,将pcd、obj、las、ply格式3D文件统一转换成ply点云格式文件进行存储及显示,调用OpenGL相关函数进行三维显示及鼠标、键盘的简单操作。

1、transform.h(建立一个抽象类Modelloader,由三个子类分别继承,使其读取转换不同的3D文件)

#include <iostream>
#include <cstdlib>
#include<string>
#include <liblas/liblas.hpp>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/io/ply_io.h>
#include<pcl/PCLPointCloud2.h>
#include <pcl/io/obj_io.h>


using namespace pcl;
using namespace pcl::io;
using namespace std;

class ModelLoader {

public:
	string filename;
	string savefilename;
	ModelLoader(string filename="", string savefilename="") {

		this->filename = filename;
		this->savefilename = savefilename;

	}
	virtual void  TO_PLY(){}
	~ModelLoader() {

		this->filename = "";

	}

};

class LasLoader:public ModelLoader {

public:
	LasLoader(string filename="",string savefilename="") :ModelLoader(filename,savefilename) {}
	void TO_PLY();

};
class PCDLoader :public ModelLoader {

public:
	PCDLoader(string filename = "", string savefilename = "") :ModelLoader(filename, savefilename) {}
	void TO_PLY();

};
class OBJLoader :public ModelLoader {
public:
	OBJLoader(string filename = "", string savefilename = "") :ModelLoader(filename, savefilename) {}
	void TO_PLY();
};

2、LAS_to_PLY.cpp

#include "transform.h"
void LasLoader::TO_PLY()
{
	
	std::ifstream ifs; 
	ifs.open(this->filename, ios::in | ios::binary);
	liblas::ReaderFactory f;
	liblas::Reader reader = f.CreateWithStream(ifs);

	unsigned long int nbPoints = reader.GetHeader().GetPointRecordsCount();

	pcl::PointCloud<pcl::PointXYZRGB> cloud;
	cloud.width = nbPoints;
	cloud.height = 1;
	cloud.is_dense = false;
	cloud.points.resize(cloud.width * cloud.height);

	int i = 0;
	uint16_t r1, g1, b1;
	int r2, g2, b2;
	uint32_t rgb;

	while (reader.ReadNextPoint())
	{
		
		cloud.points[i].x = (reader.GetPoint().GetX());
		cloud.points[i].y = (reader.GetPoint().GetY());
		cloud.points[i].z = (reader.GetPoint().GetZ());


		r1 = (reader.GetPoint().GetColor().GetRed());
		g1 = (reader.GetPo
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

东北大马猴

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值