update:数据加载保存优化
This commit is contained in:
parent
8d831c08b0
commit
db52f11dd0
@ -4,6 +4,7 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <iosfwd>
|
||||
#include "VZNL_Types.h"
|
||||
#include "VrError.h"
|
||||
#include "PointCloudXYZRange.h"
|
||||
@ -102,6 +103,9 @@ public:
|
||||
int maxTimeStamp,
|
||||
int clockPerSecond);
|
||||
|
||||
static bool WriteLaserScanLine(std::ostream& stream, EVzResultDataType dataType,
|
||||
const SVzLaserLineData& lineData);
|
||||
|
||||
int DebugSaveLaser(std::string fileName, std::vector<std::vector<SVzNL3DPosition>> xyzData);
|
||||
int DebugSaveLaser(std::string fileName, std::vector<std::vector<SVzNL3DPosition>> xyzData,
|
||||
ISaveProgressCallback* callback);
|
||||
|
||||
@ -1017,17 +1017,43 @@ int LaserDataLoader::SaveLaserScanData(const std::string& fileName,
|
||||
sw << "PointAdjust: 1" << '\n';
|
||||
sw << "MaxTimeStamp:" << maxTimeStamp << "_" << clockPerSecond << '\n';
|
||||
|
||||
// 写入每条扫描线数据
|
||||
for (const auto& linePair : laserLines) {
|
||||
if (!WriteLaserScanLine(sw, linePair.first, linePair.second)) {
|
||||
m_lastError = "Failed while writing laser line";
|
||||
return ERR_CODE(FILE_ERR_WRITE);
|
||||
}
|
||||
}
|
||||
sw.flush();
|
||||
if (!sw.good()) {
|
||||
m_lastError = "Failed while writing file: " + fileName;
|
||||
LOG_ERROR("Failed while writing file: %s\n", fileName.c_str());
|
||||
return ERR_CODE(FILE_ERR_WRITE);
|
||||
}
|
||||
sw.close();
|
||||
// 关闭文件时也可能提交写入失败,不能让调用方误以为现场已保存完整。
|
||||
if (!sw.good())
|
||||
{
|
||||
m_lastError = "Failed while closing file: " + fileName;
|
||||
return ERR_CODE(FILE_ERR_WRITE);
|
||||
}
|
||||
return SUCCESS;
|
||||
|
||||
EVzResultDataType dataType = linePair.first;
|
||||
const SVzLaserLineData& lineData = linePair.second;
|
||||
} catch (const std::exception& e) {
|
||||
m_lastError = "Error saving unified file: " + std::string(e.what());
|
||||
LOG_ERROR("Error saving unified laser data to file: %s\n", e.what());
|
||||
return ERR_CODE(FILE_ERR_WRITE);
|
||||
}
|
||||
}
|
||||
|
||||
bool LaserDataLoader::WriteLaserScanLine(std::ostream& sw, EVzResultDataType dataType,
|
||||
const SVzLaserLineData& lineData)
|
||||
{
|
||||
if (lineData.nPointCount < 0 || (lineData.nPointCount > 0 && !lineData.p3DPoint)) return false;
|
||||
if (dataType != keResultDataType_Position && dataType != keResultDataType_PositionF &&
|
||||
dataType != keResultDataType_PointXYZI && dataType != keResultDataType_PointXYZRGBA) return false;
|
||||
sw << "Line_" << lineData.llFrameIdx << "_" << lineData.llTimeStamp << "_" << lineData.nPointCount << '\n';
|
||||
|
||||
// 根据数据类型写入点云数据
|
||||
if (dataType == keResultDataType_Position && lineData.p3DPoint) {
|
||||
// 写入XYZ格式数据
|
||||
const SVzNL3DPosition* points = static_cast<const SVzNL3DPosition*>(lineData.p3DPoint);
|
||||
const SVzNL2DPosition* points2D = static_cast<const SVzNL2DPosition*>(lineData.p2DPoint);
|
||||
constexpr int BATCH = 256;
|
||||
@ -1042,8 +1068,8 @@ int LaserDataLoader::SaveLaserScanData(const std::string& fileName,
|
||||
float z = static_cast<float>(points[i].pt3D.z);
|
||||
AppendFormattedLine(buffer, "{ %.6f,%.6f,%.6f }-{ %d,%d }-{ %d,%d }\n",
|
||||
x, y, z,
|
||||
points2D[i].ptLeft2D.x, points2D[i].ptLeft2D.y,
|
||||
points2D[i].ptRight2D.x, points2D[i].ptRight2D.y);
|
||||
points2D ? points2D[i].ptLeft2D.x : 0, points2D ? points2D[i].ptLeft2D.y : 0,
|
||||
points2D ? points2D[i].ptRight2D.x : 0, points2D ? points2D[i].ptRight2D.y : 0);
|
||||
}
|
||||
sw.write(buffer.data(), static_cast<std::streamsize>(buffer.size()));
|
||||
}
|
||||
@ -1068,8 +1094,6 @@ int LaserDataLoader::SaveLaserScanData(const std::string& fileName,
|
||||
sw.write(buffer.data(), static_cast<std::streamsize>(buffer.size()));
|
||||
}
|
||||
} else if (dataType == keResultDataType_PointXYZI && lineData.p3DPoint) {
|
||||
// LiDAR 点云:snprintf 批量写入,每 256 点 flush
|
||||
// 坐标 mm 范围可达 ±200000 → "%.6f" 最长 14 字符 → 整行 ≤73 字符
|
||||
const SVzNLPointXYZI* points = static_cast<const SVzNLPointXYZI*>(lineData.p3DPoint);
|
||||
const int n = lineData.nPointCount;
|
||||
constexpr int BATCH = 256;
|
||||
@ -1087,7 +1111,6 @@ int LaserDataLoader::SaveLaserScanData(const std::string& fileName,
|
||||
sw.write(buf, p - buf);
|
||||
}
|
||||
} else if (dataType == keResultDataType_PointXYZRGBA && lineData.p3DPoint) {
|
||||
// 写入RGBD格式数据
|
||||
const SVzNLPointXYZRGBA* points = static_cast<const SVzNLPointXYZRGBA*>(lineData.p3DPoint);
|
||||
const SVzNL2DLRPoint* points2D = static_cast<const SVzNL2DLRPoint*>(lineData.p2DPoint);
|
||||
constexpr int BATCH = 256;
|
||||
@ -1107,34 +1130,14 @@ int LaserDataLoader::SaveLaserScanData(const std::string& fileName,
|
||||
AppendFormattedLine(buffer, "{%.6f,%.6f,%.6f,%.6f,%.6f,%.6f}-{ %d,%d }-{ %d,%d }\n",
|
||||
x, y, z,
|
||||
b * 1.0f / 255, g * 1.0f / 255, r * 1.0f / 255,
|
||||
points2D[i].sLeft.x, points2D[i].sLeft.y,
|
||||
points2D[i].sRight.x, points2D[i].sRight.y);
|
||||
points2D ? points2D[i].sLeft.x : 0, points2D ? points2D[i].sLeft.y : 0,
|
||||
points2D ? points2D[i].sRight.x : 0, points2D ? points2D[i].sRight.y : 0);
|
||||
}
|
||||
sw.write(buffer.data(), static_cast<std::streamsize>(buffer.size()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sw.flush();
|
||||
if (!sw.good()) {
|
||||
m_lastError = "Failed while writing file: " + fileName;
|
||||
LOG_ERROR("Failed while writing file: %s\n", fileName.c_str());
|
||||
return ERR_CODE(FILE_ERR_WRITE);
|
||||
}
|
||||
sw.close();
|
||||
// 关闭文件时也可能提交写入失败,不能让调用方误以为现场已保存完整。
|
||||
if (!sw.good())
|
||||
{
|
||||
m_lastError = "Failed while closing file: " + fileName;
|
||||
return ERR_CODE(FILE_ERR_WRITE);
|
||||
}
|
||||
return SUCCESS;
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
m_lastError = "Error saving unified file: " + std::string(e.what());
|
||||
LOG_ERROR("Error saving unified laser data to file: %s\n", e.what());
|
||||
return ERR_CODE(FILE_ERR_WRITE);
|
||||
}
|
||||
return sw.good();
|
||||
}
|
||||
|
||||
int LaserDataLoader::SaveLaserScanDataBinary(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user