update:数据加载保存优化
This commit is contained in:
parent
8d831c08b0
commit
db52f11dd0
@ -4,6 +4,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <iosfwd>
|
||||||
#include "VZNL_Types.h"
|
#include "VZNL_Types.h"
|
||||||
#include "VrError.h"
|
#include "VrError.h"
|
||||||
#include "PointCloudXYZRange.h"
|
#include "PointCloudXYZRange.h"
|
||||||
@ -102,6 +103,9 @@ public:
|
|||||||
int maxTimeStamp,
|
int maxTimeStamp,
|
||||||
int clockPerSecond);
|
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);
|
||||||
int DebugSaveLaser(std::string fileName, std::vector<std::vector<SVzNL3DPosition>> xyzData,
|
int DebugSaveLaser(std::string fileName, std::vector<std::vector<SVzNL3DPosition>> xyzData,
|
||||||
ISaveProgressCallback* callback);
|
ISaveProgressCallback* callback);
|
||||||
|
|||||||
@ -1017,104 +1017,12 @@ int LaserDataLoader::SaveLaserScanData(const std::string& fileName,
|
|||||||
sw << "PointAdjust: 1" << '\n';
|
sw << "PointAdjust: 1" << '\n';
|
||||||
sw << "MaxTimeStamp:" << maxTimeStamp << "_" << clockPerSecond << '\n';
|
sw << "MaxTimeStamp:" << maxTimeStamp << "_" << clockPerSecond << '\n';
|
||||||
|
|
||||||
// 写入每条扫描线数据
|
|
||||||
for (const auto& linePair : laserLines) {
|
for (const auto& linePair : laserLines) {
|
||||||
|
if (!WriteLaserScanLine(sw, linePair.first, linePair.second)) {
|
||||||
EVzResultDataType dataType = linePair.first;
|
m_lastError = "Failed while writing laser line";
|
||||||
const SVzLaserLineData& lineData = linePair.second;
|
return ERR_CODE(FILE_ERR_WRITE);
|
||||||
|
|
||||||
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;
|
|
||||||
constexpr int PER_POINT = 128;
|
|
||||||
for (int base = 0; base < lineData.nPointCount; base += BATCH) {
|
|
||||||
int end = (base + BATCH < lineData.nPointCount) ? (base + BATCH) : lineData.nPointCount;
|
|
||||||
std::string buffer;
|
|
||||||
buffer.reserve(BATCH * PER_POINT);
|
|
||||||
for (int i = base; i < end; ++i) {
|
|
||||||
float x = static_cast<float>(points[i].pt3D.x);
|
|
||||||
float y = static_cast<float>(points[i].pt3D.y);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
sw.write(buffer.data(), static_cast<std::streamsize>(buffer.size()));
|
|
||||||
}
|
|
||||||
} else if (dataType == keResultDataType_PositionF && lineData.p3DPoint) {
|
|
||||||
const SVzNL3DPosition* points = static_cast<const SVzNL3DPosition*>(lineData.p3DPoint);
|
|
||||||
const SVzNL2DPositionF* points2D = static_cast<const SVzNL2DPositionF*>(lineData.p2DPoint);
|
|
||||||
constexpr int BATCH = 256;
|
|
||||||
constexpr int PER_POINT = 160;
|
|
||||||
for (int base = 0; base < lineData.nPointCount; base += BATCH) {
|
|
||||||
int end = (base + BATCH < lineData.nPointCount) ? (base + BATCH) : lineData.nPointCount;
|
|
||||||
std::string buffer;
|
|
||||||
buffer.reserve(BATCH * PER_POINT);
|
|
||||||
for (int i = base; i < end; ++i) {
|
|
||||||
AppendFormattedLine(buffer,
|
|
||||||
"{ %.9f, %.9f, %.9f } - { %.6f, %.6f } - { %.6f, %.6f }\n",
|
|
||||||
points[i].pt3D.x, points[i].pt3D.y, points[i].pt3D.z,
|
|
||||||
points2D ? points2D[i].ptLeft2D.x : 0.0f,
|
|
||||||
points2D ? points2D[i].ptLeft2D.y : 0.0f,
|
|
||||||
points2D ? points2D[i].ptRight2D.x : 0.0f,
|
|
||||||
points2D ? points2D[i].ptRight2D.y : 0.0f);
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
constexpr int PER_POINT = 80;
|
|
||||||
char buf[BATCH * PER_POINT];
|
|
||||||
for (int base = 0; base < n; base += BATCH)
|
|
||||||
{
|
|
||||||
int end = (base + BATCH < n) ? (base + BATCH) : n;
|
|
||||||
char* p = buf;
|
|
||||||
for (int i = base; i < end; ++i)
|
|
||||||
{
|
|
||||||
p += snprintf(p, PER_POINT, "{ %.6f, %.6f, %.6f } - { 0, 0 } - { 0, 0 }\n",
|
|
||||||
points[i].fData[0], points[i].fData[1], points[i].fData[2]);
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
constexpr int PER_POINT = 160;
|
|
||||||
for (int base = 0; base < lineData.nPointCount; base += BATCH) {
|
|
||||||
int end = (base + BATCH < lineData.nPointCount) ? (base + BATCH) : lineData.nPointCount;
|
|
||||||
std::string buffer;
|
|
||||||
buffer.reserve(BATCH * PER_POINT);
|
|
||||||
for (int i = base; i < end; ++i) {
|
|
||||||
float x = static_cast<float>(points[i].x);
|
|
||||||
float y = static_cast<float>(points[i].y);
|
|
||||||
float z = static_cast<float>(points[i].z);
|
|
||||||
int r = (points[i].nRGB >> 16) & 0xFF;
|
|
||||||
int g = (points[i].nRGB >> 8) & 0xFF;
|
|
||||||
int b = points[i].nRGB & 0xFF;
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
sw.write(buffer.data(), static_cast<std::streamsize>(buffer.size()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sw.flush();
|
sw.flush();
|
||||||
if (!sw.good()) {
|
if (!sw.good()) {
|
||||||
m_lastError = "Failed while writing file: " + fileName;
|
m_lastError = "Failed while writing file: " + fileName;
|
||||||
@ -1137,6 +1045,101 @@ int LaserDataLoader::SaveLaserScanData(const std::string& fileName,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
const SVzNL3DPosition* points = static_cast<const SVzNL3DPosition*>(lineData.p3DPoint);
|
||||||
|
const SVzNL2DPosition* points2D = static_cast<const SVzNL2DPosition*>(lineData.p2DPoint);
|
||||||
|
constexpr int BATCH = 256;
|
||||||
|
constexpr int PER_POINT = 128;
|
||||||
|
for (int base = 0; base < lineData.nPointCount; base += BATCH) {
|
||||||
|
int end = (base + BATCH < lineData.nPointCount) ? (base + BATCH) : lineData.nPointCount;
|
||||||
|
std::string buffer;
|
||||||
|
buffer.reserve(BATCH * PER_POINT);
|
||||||
|
for (int i = base; i < end; ++i) {
|
||||||
|
float x = static_cast<float>(points[i].pt3D.x);
|
||||||
|
float y = static_cast<float>(points[i].pt3D.y);
|
||||||
|
float z = static_cast<float>(points[i].pt3D.z);
|
||||||
|
AppendFormattedLine(buffer, "{ %.6f,%.6f,%.6f }-{ %d,%d }-{ %d,%d }\n",
|
||||||
|
x, y, z,
|
||||||
|
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()));
|
||||||
|
}
|
||||||
|
} else if (dataType == keResultDataType_PositionF && lineData.p3DPoint) {
|
||||||
|
const SVzNL3DPosition* points = static_cast<const SVzNL3DPosition*>(lineData.p3DPoint);
|
||||||
|
const SVzNL2DPositionF* points2D = static_cast<const SVzNL2DPositionF*>(lineData.p2DPoint);
|
||||||
|
constexpr int BATCH = 256;
|
||||||
|
constexpr int PER_POINT = 160;
|
||||||
|
for (int base = 0; base < lineData.nPointCount; base += BATCH) {
|
||||||
|
int end = (base + BATCH < lineData.nPointCount) ? (base + BATCH) : lineData.nPointCount;
|
||||||
|
std::string buffer;
|
||||||
|
buffer.reserve(BATCH * PER_POINT);
|
||||||
|
for (int i = base; i < end; ++i) {
|
||||||
|
AppendFormattedLine(buffer,
|
||||||
|
"{ %.9f, %.9f, %.9f } - { %.6f, %.6f } - { %.6f, %.6f }\n",
|
||||||
|
points[i].pt3D.x, points[i].pt3D.y, points[i].pt3D.z,
|
||||||
|
points2D ? points2D[i].ptLeft2D.x : 0.0f,
|
||||||
|
points2D ? points2D[i].ptLeft2D.y : 0.0f,
|
||||||
|
points2D ? points2D[i].ptRight2D.x : 0.0f,
|
||||||
|
points2D ? points2D[i].ptRight2D.y : 0.0f);
|
||||||
|
}
|
||||||
|
sw.write(buffer.data(), static_cast<std::streamsize>(buffer.size()));
|
||||||
|
}
|
||||||
|
} else if (dataType == keResultDataType_PointXYZI && lineData.p3DPoint) {
|
||||||
|
const SVzNLPointXYZI* points = static_cast<const SVzNLPointXYZI*>(lineData.p3DPoint);
|
||||||
|
const int n = lineData.nPointCount;
|
||||||
|
constexpr int BATCH = 256;
|
||||||
|
constexpr int PER_POINT = 80;
|
||||||
|
char buf[BATCH * PER_POINT];
|
||||||
|
for (int base = 0; base < n; base += BATCH)
|
||||||
|
{
|
||||||
|
int end = (base + BATCH < n) ? (base + BATCH) : n;
|
||||||
|
char* p = buf;
|
||||||
|
for (int i = base; i < end; ++i)
|
||||||
|
{
|
||||||
|
p += snprintf(p, PER_POINT, "{ %.6f, %.6f, %.6f } - { 0, 0 } - { 0, 0 }\n",
|
||||||
|
points[i].fData[0], points[i].fData[1], points[i].fData[2]);
|
||||||
|
}
|
||||||
|
sw.write(buf, p - buf);
|
||||||
|
}
|
||||||
|
} else if (dataType == keResultDataType_PointXYZRGBA && lineData.p3DPoint) {
|
||||||
|
const SVzNLPointXYZRGBA* points = static_cast<const SVzNLPointXYZRGBA*>(lineData.p3DPoint);
|
||||||
|
const SVzNL2DLRPoint* points2D = static_cast<const SVzNL2DLRPoint*>(lineData.p2DPoint);
|
||||||
|
constexpr int BATCH = 256;
|
||||||
|
constexpr int PER_POINT = 160;
|
||||||
|
for (int base = 0; base < lineData.nPointCount; base += BATCH) {
|
||||||
|
int end = (base + BATCH < lineData.nPointCount) ? (base + BATCH) : lineData.nPointCount;
|
||||||
|
std::string buffer;
|
||||||
|
buffer.reserve(BATCH * PER_POINT);
|
||||||
|
for (int i = base; i < end; ++i) {
|
||||||
|
float x = static_cast<float>(points[i].x);
|
||||||
|
float y = static_cast<float>(points[i].y);
|
||||||
|
float z = static_cast<float>(points[i].z);
|
||||||
|
int r = (points[i].nRGB >> 16) & 0xFF;
|
||||||
|
int g = (points[i].nRGB >> 8) & 0xFF;
|
||||||
|
int b = points[i].nRGB & 0xFF;
|
||||||
|
|
||||||
|
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 ? 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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sw.good();
|
||||||
|
}
|
||||||
|
|
||||||
int LaserDataLoader::SaveLaserScanDataBinary(
|
int LaserDataLoader::SaveLaserScanDataBinary(
|
||||||
const std::string& fileName,
|
const std::string& fileName,
|
||||||
const std::vector<std::pair<EVzResultDataType, SVzLaserLineData>>& laserLines,
|
const std::vector<std::pair<EVzResultDataType, SVzLaserLineData>>& laserLines,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user