fix:读写数据保持一致,时间戳,线号类型改为ulonglong

This commit is contained in:
YangSn 2026-11-04 10:24:08 +08:00
parent 870e057099
commit d1bcece8c7
5 changed files with 60 additions and 72 deletions

View File

@ -15,7 +15,6 @@ win32-msvc {
# 鎸囧畾C++鏍囧噯
CONFIG += c++11
INCLUDEPATH += $$PWD/../../Device/SDK/VzNLSDK/_Inc
INCLUDEPATH += $$PWD/../../Device/SDK/VzNLSDK/Inc
INCLUDEPATH += $$PWD/../VrCommon/Inc

View File

@ -32,17 +32,14 @@ class LaserDataLoader
{
public:
// lineData is valid only while the callback is running. Copy it to retain it.
using LaserLineLoadCallback =
std::function<void(EVzResultDataType, SVzLaserLineData&)>;
using LaserLineLoadCallback = std::function<void(EVzResultDataType, SVzLaserLineData&)>;
// 过滤后仍提供源扫描线点数及每个保留点的原始线内索引。
using LaserLineLoadIndexedCallback =
std::function<void(EVzResultDataType, SVzLaserLineData&, const LaserLineLoadInfo&)>;
using LaserLineLoadIndexedCallback = std::function<void(EVzResultDataType, SVzLaserLineData&, const LaserLineLoadInfo&)>;
// Called exactly once when loading succeeds or fails.
// Arguments: result, lineNum, scanSpeed, maxTimeStamp, clockPerSecond.
using LaserLoadFinishedCallback =
std::function<void(int, int, float, int, int)>;
using LaserLoadFinishedCallback = std::function<void(int, int, float, int, int)>;
LaserDataLoader();
~LaserDataLoader();

View File

@ -101,7 +101,6 @@ struct DatLineScan3DData
static_assert(sizeof(DatLaserScan3DLinesHeader) == 40, "Unexpected dat header layout");
static_assert(sizeof(DatLineScan3DData) == 16, "Unexpected dat line layout");
static_assert(sizeof(Dat3DFeaturePoint) == 112, "Unexpected dat feature point layout");
template <typename T>
bool ReadBinary(std::ifstream& inputFile, T& value)
{
@ -493,10 +492,10 @@ int LaserDataLoader::LoadLaserScanData(const std::string& fileName,
if (SUCCESS != result) return result;
}
int lineIndex = 0;
unsigned int timeStamp = 0;
unsigned long long lineIndex = 0;
unsigned long long timeStamp = 0;
int ptNum = 0;
if (3 != sscanf(line.c_str(), "Line_%d_%u_%d", &lineIndex, &timeStamp, &ptNum) ||
if (3 != sscanf(line.c_str(), "Line_%llu_%llu_%d", &lineIndex, &timeStamp, &ptNum) ||
ptNum < 0 || ptNum > VZ_LASER_LINE_PT_MAX_NUM) {
return failTextLoad(FILE_ERR_FORMAT, "Invalid laser line header: " + line);
}
@ -716,10 +715,10 @@ int LaserDataLoader::LoadLaserScanDataByIndexedCallback(
return finish(result);
}
int lineIndex = 0;
unsigned int timeStamp = 0;
unsigned long long lineIndex = 0;
unsigned long long timeStamp = 0;
int pointCount = 0;
if (sscanf(line.c_str(), "Line_%d_%u_%d", &lineIndex, &timeStamp, &pointCount) != 3 ||
if (sscanf(line.c_str(), "Line_%llu_%llu_%d", &lineIndex, &timeStamp, &pointCount) != 3 ||
pointCount < 0 || pointCount > VZ_LASER_LINE_PT_MAX_NUM) {
m_lastError = "Invalid laser line header: " + line;
LOG_ERROR("%s\n", m_lastError.c_str());
@ -738,10 +737,8 @@ int LaserDataLoader::LoadLaserScanDataByIndexedCallback(
LOG_ERROR("%s\n", m_lastError.c_str());
return finish(ERR_CODE(DATA_ERR_MEM));
}
std::memset(rgbaPoints.get(), 0,
sizeof(SVzNLPointXYZRGBA) * static_cast<size_t>(pointCount));
std::memset(rgba2DPoints.get(), 0,
sizeof(SVzNL2DLRPoint) * static_cast<size_t>(pointCount));
std::memset(rgbaPoints.get(), 0, sizeof(SVzNLPointXYZRGBA) * static_cast<size_t>(pointCount));
std::memset(rgba2DPoints.get(), 0, sizeof(SVzNL2DLRPoint) * static_cast<size_t>(pointCount));
lineData.p3DPoint = rgbaPoints.get();
lineData.p2DPoint = rgba2DPoints.get();
} else if (pointCount > 0 && dataType == keResultDataType_Position) {
@ -752,10 +749,8 @@ int LaserDataLoader::LoadLaserScanDataByIndexedCallback(
LOG_ERROR("%s\n", m_lastError.c_str());
return finish(ERR_CODE(DATA_ERR_MEM));
}
std::memset(positionPoints.get(), 0,
sizeof(SVzNL3DPosition) * static_cast<size_t>(pointCount));
std::memset(position2DPoints.get(), 0,
sizeof(SVzNL2DPosition) * static_cast<size_t>(pointCount));
std::memset(positionPoints.get(), 0, sizeof(SVzNL3DPosition) * static_cast<size_t>(pointCount));
std::memset(position2DPoints.get(), 0, sizeof(SVzNL2DPosition) * static_cast<size_t>(pointCount));
lineData.p3DPoint = positionPoints.get();
lineData.p2DPoint = position2DPoints.get();
}
@ -1051,7 +1046,9 @@ bool LaserDataLoader::WriteLaserScanLine(std::ostream& sw, EVzResultDataType dat
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';
sw << "Line_" << static_cast<unsigned long long>(lineData.llFrameIdx)
<< "_" << static_cast<unsigned long long>(lineData.llTimeStamp)
<< "_" << lineData.nPointCount << '\n';
if (dataType == keResultDataType_Position && lineData.p3DPoint) {
const SVzNL3DPosition* points = static_cast<const SVzNL3DPosition*>(lineData.p3DPoint);
@ -1063,11 +1060,8 @@ bool LaserDataLoader::WriteLaserScanLine(std::ostream& sw, EVzResultDataType dat
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,
points[i].pt3D.x, points[i].pt3D.y, points[i].pt3D.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);
}
@ -1084,7 +1078,7 @@ bool LaserDataLoader::WriteLaserScanLine(std::ostream& sw, EVzResultDataType dat
buffer.reserve(BATCH * PER_POINT);
for (int i = base; i < end; ++i) {
AppendFormattedLine(buffer,
"{ %.9f, %.9f, %.9f } - { %.6f, %.6f } - { %.6f, %.6f }\n",
"{ %.6f, %.6f, %.6f } - { %.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,
@ -1181,12 +1175,6 @@ int LaserDataLoader::SaveLaserScanDataBinary(
m_lastError = "Missing 3D data for binary laser line";
return ERR_CODE(DEV_ARG_INVAILD);
}
if (line.llFrameIdx > static_cast<unsigned long long>((std::numeric_limits<int>::max)()) ||
line.llTimeStamp > (std::numeric_limits<std::uint32_t>::max)())
{
m_lastError = "Frame index or timestamp exceeds legacy binary format range";
return ERR_CODE(DEV_ARG_INVAILD);
}
maxPointCount = std::max(maxPointCount, static_cast<size_t>(line.nPointCount));
}
@ -1885,11 +1873,11 @@ void LaserDataLoader::FreeConvertedData(std::vector<SVzNLXYZRGBDLaserLine>& rgbd
int LaserDataLoader::_ParseLaserScanPoint(const std::string& data, SVzNL3DPosition& sData, SVzNL2DPosition& s2DData)
{
float X = 0.0f, Y = 0.0f, Z = 0.0f;
float leftX = 0.0f, leftY = 0.0f;
float rightX = 0.0f, rightY = 0.0f;
double X = 0.0, Y = 0.0, Z = 0.0;
int leftX = 0, leftY = 0;
int rightX = 0, rightY = 0;
const int parsed = sscanf(data.c_str(),
" { %f , %f , %f } - { %f , %f } - { %f , %f }",
" { %lf , %lf , %lf } - { %d , %d } - { %d , %d }",
&X, &Y, &Z, &leftX, &leftY, &rightX, &rightY);
if (parsed != 7) {
return ERR_CODE(FILE_ERR_FORMAT);
@ -2123,9 +2111,13 @@ int LaserDataLoader::_ParseLaserScanPoint(const std::string& data, SVzNLPointXYZ
sData.y = Y;
sData.z = Z;
int nr = (int)(r * 255);
int ng = (int)(g * 255);
int nb = (int)(b * 255);
const auto toByte = [](float value) {
const float bounded = value < 0.0f ? 0.0f : (value > 1.0f ? 1.0f : value);
return static_cast<unsigned int>(std::lround(bounded * 255.0f));
};
int nr = static_cast<int>(toByte(r));
int ng = static_cast<int>(toByte(g));
int nb = static_cast<int>(toByte(b));
nb <<= 8;
nb += ng;
nb <<= 8;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.5 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB