Utils/CloudView/Inc/PointCloudConverter.h

170 lines
5.2 KiB
C
Raw Permalink Normal View History

2026-02-19 00:45:00 +08:00
#ifndef POINT_CLOUD_CONVERTER_H
#define POINT_CLOUD_CONVERTER_H
2026-07-13 18:56:01 +08:00
#include <string>
#include <vector>
#include <memory>
#include "CloudView3DTypes.h"
/**
* @brief
2026-07-03 12:46:19 +08:00
* txt/datpcdply
2026-02-19 00:45:00 +08:00
*/
class PointCloudConverter
{
public:
PointCloudConverter();
~PointCloudConverter();
/**
2026-07-03 12:46:19 +08:00
* @brief txt/dat 使 CloudUtils
2026-02-19 00:45:00 +08:00
*/
int loadFromTxt(const std::string& fileName, PointCloudXYZ& cloud);
int loadFromTxt(const std::string& fileName, PointCloudXYZRGB& cloud);
/**
* @brief pcd ASCII/Binary
*/
int loadFromPcd(const std::string& fileName, PointCloudXYZ& cloud);
int loadFromPcd(const std::string& fileName, PointCloudXYZRGB& cloud);
/**
* @brief ply ASCII / Binary Little-Endian / Binary Big-Endian
*/
int loadFromPly(const std::string& fileName, PointCloudXYZ& cloud);
int loadFromPly(const std::string& fileName, PointCloudXYZRGB& cloud);
2026-02-19 00:45:00 +08:00
/**
* @brief
*/
int loadFromFile(const std::string& fileName, PointCloudXYZ& cloud);
int loadFromFile(const std::string& fileName, PointCloudXYZRGB& cloud);
/**
* @brief txt 使 CloudUtils
*/
int saveToTxt(const std::string& fileName, const PointCloudXYZ& cloud, int lineNum, int linePtNum);
/**
* @brief PLY ASCII
* @param fileName
* @param cloud
* @return 0=, -1=
*/
int saveToPly(const std::string& fileName, const PointCloudXYZ& cloud);
/**
* @brief PCD ASCII PCL
* @param fileName
* @param cloud
* @return 0=, -1=
*/
int saveToPcd(const std::string& fileName, const PointCloudXYZ& cloud);
2026-02-19 00:45:00 +08:00
/**
* @brief + XY
* @param cloud
* @param rotatedCloud
* @param lineNum 线
* @param linePtNum 线
* @param newLineNum 线
* @param newLinePtNum 线
*/
int rotateCloud(const PointCloudXYZ& cloud, PointCloudXYZ& rotatedCloud,
int lineNum, int linePtNum, int& newLineNum, int& newLinePtNum);
/**
* @brief
*/
std::string getLastError() const { return m_lastError; }
/**
* @brief
*/
size_t getLoadedPointCount() const { return m_loadedPointCount; }
/**
* @brief 线
*/
int getLoadedLineCount() const { return m_loadedLineCount; }
/**
* @brief loadFromTxt(PointCloudXYZRGB&)
*/
bool lastLoadHadColor() const { return m_lastLoadHadColor; }
private:
/**
* @brief
*/
std::string getFileExtension(const std::string& fileName);
/**
* @brief PCD
*/
struct PcdHeader
{
int width = 0;
int height = 1;
int points = 0;
bool isBinary = false;
bool hasRgb = false;
std::vector<std::string> fields;
std::vector<int> fieldSizes;
std::vector<char> fieldTypes;
int pointSize = 0;
};
bool parsePcdHeader(std::ifstream& file, PcdHeader& header);
/**
* @brief PLY
*/
struct PlyProperty
{
std::string name; // 属性名 (x, y, z, red, green, blue, alpha, nx, ny, nz ...)
std::string type; // 数据类型 (float, double, uchar, int, short ...)
int byteSize = 0; // 字节数
bool isList = false; // 是否是 list 类型(如 face 的 vertex_indices
std::string listCountType; // list 的计数类型
std::string listValueType; // list 的值类型
};
/**
* @brief PLY
*/
struct PlyElement
{
std::string name; // 元素名 (vertex, face ...)
int count = 0; // 元素数量
std::vector<PlyProperty> properties;
};
/**
* @brief PLY
*/
struct PlyHeader
{
enum Format { ASCII, BINARY_LE, BINARY_BE };
Format format = ASCII;
std::vector<PlyElement> elements;
int vertexElementIndex = -1; // vertex 元素在 elements 中的索引
};
bool parsePlyHeader(std::ifstream& file, PlyHeader& header);
int getPlyTypeByteSize(const std::string& type);
/**
* @brief PLY list
*/
int calcPlyElementStride(const PlyElement& element);
2026-02-19 00:45:00 +08:00
std::string m_lastError;
size_t m_loadedPointCount;
int m_loadedLineCount;
bool m_lastLoadHadColor;
};
#endif // POINT_CLOUD_CONVERTER_H