fix:读写数据保持一致,时间戳,线号类型改为ulonglong
This commit is contained in:
parent
870e057099
commit
d1bcece8c7
@ -15,7 +15,6 @@ win32-msvc {
|
|||||||
# 鎸囧畾C++鏍囧噯
|
# 鎸囧畾C++鏍囧噯
|
||||||
CONFIG += c++11
|
CONFIG += c++11
|
||||||
|
|
||||||
INCLUDEPATH += $$PWD/../../Device/SDK/VzNLSDK/_Inc
|
|
||||||
INCLUDEPATH += $$PWD/../../Device/SDK/VzNLSDK/Inc
|
INCLUDEPATH += $$PWD/../../Device/SDK/VzNLSDK/Inc
|
||||||
|
|
||||||
INCLUDEPATH += $$PWD/../VrCommon/Inc
|
INCLUDEPATH += $$PWD/../VrCommon/Inc
|
||||||
|
|||||||
@ -32,17 +32,14 @@ class LaserDataLoader
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// lineData is valid only while the callback is running. Copy it to retain it.
|
// lineData is valid only while the callback is running. Copy it to retain it.
|
||||||
using LaserLineLoadCallback =
|
using LaserLineLoadCallback = std::function<void(EVzResultDataType, SVzLaserLineData&)>;
|
||||||
std::function<void(EVzResultDataType, SVzLaserLineData&)>;
|
|
||||||
|
|
||||||
// 过滤后仍提供源扫描线点数及每个保留点的原始线内索引。
|
// 过滤后仍提供源扫描线点数及每个保留点的原始线内索引。
|
||||||
using LaserLineLoadIndexedCallback =
|
using LaserLineLoadIndexedCallback = std::function<void(EVzResultDataType, SVzLaserLineData&, const LaserLineLoadInfo&)>;
|
||||||
std::function<void(EVzResultDataType, SVzLaserLineData&, const LaserLineLoadInfo&)>;
|
|
||||||
|
|
||||||
// Called exactly once when loading succeeds or fails.
|
// Called exactly once when loading succeeds or fails.
|
||||||
// Arguments: result, lineNum, scanSpeed, maxTimeStamp, clockPerSecond.
|
// Arguments: result, lineNum, scanSpeed, maxTimeStamp, clockPerSecond.
|
||||||
using LaserLoadFinishedCallback =
|
using LaserLoadFinishedCallback = std::function<void(int, int, float, int, int)>;
|
||||||
std::function<void(int, int, float, int, int)>;
|
|
||||||
|
|
||||||
LaserDataLoader();
|
LaserDataLoader();
|
||||||
~LaserDataLoader();
|
~LaserDataLoader();
|
||||||
|
|||||||
@ -91,17 +91,16 @@ struct DatLaserScan3DLinesHeader
|
|||||||
std::uint64_t scanLineList;
|
std::uint64_t scanLineList;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DatLineScan3DData
|
struct DatLineScan3DData
|
||||||
{
|
{
|
||||||
int lineIndex;
|
int lineIndex;
|
||||||
std::uint32_t timeStamp;
|
std::uint32_t timeStamp;
|
||||||
double lineStepping;
|
double lineStepping;
|
||||||
};
|
};
|
||||||
|
|
||||||
static_assert(sizeof(DatLaserScan3DLinesHeader) == 40, "Unexpected dat header layout");
|
static_assert(sizeof(DatLaserScan3DLinesHeader) == 40, "Unexpected dat header layout");
|
||||||
static_assert(sizeof(DatLineScan3DData) == 16, "Unexpected dat line layout");
|
static_assert(sizeof(DatLineScan3DData) == 16, "Unexpected dat line layout");
|
||||||
static_assert(sizeof(Dat3DFeaturePoint) == 112, "Unexpected dat feature point layout");
|
static_assert(sizeof(Dat3DFeaturePoint) == 112, "Unexpected dat feature point layout");
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool ReadBinary(std::ifstream& inputFile, T& value)
|
bool ReadBinary(std::ifstream& inputFile, T& value)
|
||||||
{
|
{
|
||||||
@ -139,9 +138,9 @@ bool LooksLikeTextLaserFile(const std::string& fileName)
|
|||||||
return inputFile.gcount() == sizeof(header) && std::memcmp(header, "LineNum:", sizeof(header)) == 0;
|
return inputFile.gcount() == sizeof(header) && std::memcmp(header, "LineNum:", sizeof(header)) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ReadDatLineRecord(std::ifstream& inputFile, int recordSize, DatLineScan3DData& lineData)
|
bool ReadDatLineRecord(std::ifstream& inputFile, int recordSize, DatLineScan3DData& lineData)
|
||||||
{
|
{
|
||||||
char buffer[40] = {};
|
char buffer[40] = {};
|
||||||
if (recordSize <= 0 || recordSize > static_cast<int>(sizeof(buffer))) {
|
if (recordSize <= 0 || recordSize > static_cast<int>(sizeof(buffer))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -151,11 +150,11 @@ bool ReadDatLineRecord(std::ifstream& inputFile, int recordSize, DatLineScan3DDa
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::memcpy(&lineData.lineIndex, buffer, sizeof(lineData.lineIndex));
|
std::memcpy(&lineData.lineIndex, buffer, sizeof(lineData.lineIndex));
|
||||||
std::memcpy(&lineData.timeStamp, buffer + 4, sizeof(lineData.timeStamp));
|
std::memcpy(&lineData.timeStamp, buffer + 4, sizeof(lineData.timeStamp));
|
||||||
std::memcpy(&lineData.lineStepping, buffer + 8, sizeof(lineData.lineStepping));
|
std::memcpy(&lineData.lineStepping, buffer + 8, sizeof(lineData.lineStepping));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppendFormattedLine(std::string& output, const char* format, ...)
|
void AppendFormattedLine(std::string& output, const char* format, ...)
|
||||||
{
|
{
|
||||||
@ -493,10 +492,10 @@ int LaserDataLoader::LoadLaserScanData(const std::string& fileName,
|
|||||||
if (SUCCESS != result) return result;
|
if (SUCCESS != result) return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int lineIndex = 0;
|
unsigned long long lineIndex = 0;
|
||||||
unsigned int timeStamp = 0;
|
unsigned long long timeStamp = 0;
|
||||||
int ptNum = 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) {
|
ptNum < 0 || ptNum > VZ_LASER_LINE_PT_MAX_NUM) {
|
||||||
return failTextLoad(FILE_ERR_FORMAT, "Invalid laser line header: " + line);
|
return failTextLoad(FILE_ERR_FORMAT, "Invalid laser line header: " + line);
|
||||||
}
|
}
|
||||||
@ -716,10 +715,10 @@ int LaserDataLoader::LoadLaserScanDataByIndexedCallback(
|
|||||||
return finish(result);
|
return finish(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
int lineIndex = 0;
|
unsigned long long lineIndex = 0;
|
||||||
unsigned int timeStamp = 0;
|
unsigned long long timeStamp = 0;
|
||||||
int pointCount = 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) {
|
pointCount < 0 || pointCount > VZ_LASER_LINE_PT_MAX_NUM) {
|
||||||
m_lastError = "Invalid laser line header: " + line;
|
m_lastError = "Invalid laser line header: " + line;
|
||||||
LOG_ERROR("%s\n", m_lastError.c_str());
|
LOG_ERROR("%s\n", m_lastError.c_str());
|
||||||
@ -738,10 +737,8 @@ int LaserDataLoader::LoadLaserScanDataByIndexedCallback(
|
|||||||
LOG_ERROR("%s\n", m_lastError.c_str());
|
LOG_ERROR("%s\n", m_lastError.c_str());
|
||||||
return finish(ERR_CODE(DATA_ERR_MEM));
|
return finish(ERR_CODE(DATA_ERR_MEM));
|
||||||
}
|
}
|
||||||
std::memset(rgbaPoints.get(), 0,
|
std::memset(rgbaPoints.get(), 0, sizeof(SVzNLPointXYZRGBA) * static_cast<size_t>(pointCount));
|
||||||
sizeof(SVzNLPointXYZRGBA) * static_cast<size_t>(pointCount));
|
std::memset(rgba2DPoints.get(), 0, sizeof(SVzNL2DLRPoint) * static_cast<size_t>(pointCount));
|
||||||
std::memset(rgba2DPoints.get(), 0,
|
|
||||||
sizeof(SVzNL2DLRPoint) * static_cast<size_t>(pointCount));
|
|
||||||
lineData.p3DPoint = rgbaPoints.get();
|
lineData.p3DPoint = rgbaPoints.get();
|
||||||
lineData.p2DPoint = rgba2DPoints.get();
|
lineData.p2DPoint = rgba2DPoints.get();
|
||||||
} else if (pointCount > 0 && dataType == keResultDataType_Position) {
|
} else if (pointCount > 0 && dataType == keResultDataType_Position) {
|
||||||
@ -752,10 +749,8 @@ int LaserDataLoader::LoadLaserScanDataByIndexedCallback(
|
|||||||
LOG_ERROR("%s\n", m_lastError.c_str());
|
LOG_ERROR("%s\n", m_lastError.c_str());
|
||||||
return finish(ERR_CODE(DATA_ERR_MEM));
|
return finish(ERR_CODE(DATA_ERR_MEM));
|
||||||
}
|
}
|
||||||
std::memset(positionPoints.get(), 0,
|
std::memset(positionPoints.get(), 0, sizeof(SVzNL3DPosition) * static_cast<size_t>(pointCount));
|
||||||
sizeof(SVzNL3DPosition) * static_cast<size_t>(pointCount));
|
std::memset(position2DPoints.get(), 0, sizeof(SVzNL2DPosition) * static_cast<size_t>(pointCount));
|
||||||
std::memset(position2DPoints.get(), 0,
|
|
||||||
sizeof(SVzNL2DPosition) * static_cast<size_t>(pointCount));
|
|
||||||
lineData.p3DPoint = positionPoints.get();
|
lineData.p3DPoint = positionPoints.get();
|
||||||
lineData.p2DPoint = position2DPoints.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 (lineData.nPointCount < 0 || (lineData.nPointCount > 0 && !lineData.p3DPoint)) return false;
|
||||||
if (dataType != keResultDataType_Position && dataType != keResultDataType_PositionF &&
|
if (dataType != keResultDataType_Position && dataType != keResultDataType_PositionF &&
|
||||||
dataType != keResultDataType_PointXYZI && dataType != keResultDataType_PointXYZRGBA) return false;
|
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) {
|
if (dataType == keResultDataType_Position && lineData.p3DPoint) {
|
||||||
const SVzNL3DPosition* points = static_cast<const SVzNL3DPosition*>(lineData.p3DPoint);
|
const SVzNL3DPosition* points = static_cast<const SVzNL3DPosition*>(lineData.p3DPoint);
|
||||||
@ -1059,17 +1056,14 @@ bool LaserDataLoader::WriteLaserScanLine(std::ostream& sw, EVzResultDataType dat
|
|||||||
constexpr int BATCH = 256;
|
constexpr int BATCH = 256;
|
||||||
constexpr int PER_POINT = 128;
|
constexpr int PER_POINT = 128;
|
||||||
for (int base = 0; base < lineData.nPointCount; base += BATCH) {
|
for (int base = 0; base < lineData.nPointCount; base += BATCH) {
|
||||||
int end = (base + BATCH < lineData.nPointCount) ? (base + BATCH) : lineData.nPointCount;
|
int end = (base + BATCH < lineData.nPointCount) ? (base + BATCH) : lineData.nPointCount;
|
||||||
std::string buffer;
|
std::string buffer;
|
||||||
buffer.reserve(BATCH * PER_POINT);
|
buffer.reserve(BATCH * PER_POINT);
|
||||||
for (int i = base; i < end; ++i) {
|
for (int i = base; i < end; ++i) {
|
||||||
float x = static_cast<float>(points[i].pt3D.x);
|
AppendFormattedLine(buffer, "{ %.6f,%.6f,%.6f }-{ %d,%d }-{ %d,%d }\n",
|
||||||
float y = static_cast<float>(points[i].pt3D.y);
|
points[i].pt3D.x, points[i].pt3D.y, points[i].pt3D.z,
|
||||||
float z = static_cast<float>(points[i].pt3D.z);
|
points2D ? points2D[i].ptLeft2D.x : 0, points2D ? points2D[i].ptLeft2D.y : 0,
|
||||||
AppendFormattedLine(buffer, "{ %.6f,%.6f,%.6f }-{ %d,%d }-{ %d,%d }\n",
|
points2D ? points2D[i].ptRight2D.x : 0, points2D ? points2D[i].ptRight2D.y : 0);
|
||||||
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()));
|
sw.write(buffer.data(), static_cast<std::streamsize>(buffer.size()));
|
||||||
}
|
}
|
||||||
@ -1084,7 +1078,7 @@ bool LaserDataLoader::WriteLaserScanLine(std::ostream& sw, EVzResultDataType dat
|
|||||||
buffer.reserve(BATCH * PER_POINT);
|
buffer.reserve(BATCH * PER_POINT);
|
||||||
for (int i = base; i < end; ++i) {
|
for (int i = base; i < end; ++i) {
|
||||||
AppendFormattedLine(buffer,
|
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,
|
points[i].pt3D.x, points[i].pt3D.y, points[i].pt3D.z,
|
||||||
points2D ? points2D[i].ptLeft2D.x : 0.0f,
|
points2D ? points2D[i].ptLeft2D.x : 0.0f,
|
||||||
points2D ? points2D[i].ptLeft2D.y : 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";
|
m_lastError = "Missing 3D data for binary laser line";
|
||||||
return ERR_CODE(DEV_ARG_INVAILD);
|
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));
|
maxPointCount = std::max(maxPointCount, static_cast<size_t>(line.nPointCount));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1885,22 +1873,22 @@ void LaserDataLoader::FreeConvertedData(std::vector<SVzNLXYZRGBDLaserLine>& rgbd
|
|||||||
|
|
||||||
int LaserDataLoader::_ParseLaserScanPoint(const std::string& data, SVzNL3DPosition& sData, SVzNL2DPosition& s2DData)
|
int LaserDataLoader::_ParseLaserScanPoint(const std::string& data, SVzNL3DPosition& sData, SVzNL2DPosition& s2DData)
|
||||||
{
|
{
|
||||||
float X = 0.0f, Y = 0.0f, Z = 0.0f;
|
double X = 0.0, Y = 0.0, Z = 0.0;
|
||||||
float leftX = 0.0f, leftY = 0.0f;
|
int leftX = 0, leftY = 0;
|
||||||
float rightX = 0.0f, rightY = 0.0f;
|
int rightX = 0, rightY = 0;
|
||||||
const int parsed = sscanf(data.c_str(),
|
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);
|
&X, &Y, &Z, &leftX, &leftY, &rightX, &rightY);
|
||||||
if (parsed != 7) {
|
if (parsed != 7) {
|
||||||
return ERR_CODE(FILE_ERR_FORMAT);
|
return ERR_CODE(FILE_ERR_FORMAT);
|
||||||
}
|
}
|
||||||
sData.pt3D.x = X;
|
sData.pt3D.x = X;
|
||||||
sData.pt3D.y = Y;
|
sData.pt3D.y = Y;
|
||||||
sData.pt3D.z = Z;
|
sData.pt3D.z = Z;
|
||||||
s2DData.ptLeft2D.x = leftX;
|
s2DData.ptLeft2D.x = leftX;
|
||||||
s2DData.ptLeft2D.y = leftY;
|
s2DData.ptLeft2D.y = leftY;
|
||||||
s2DData.ptRight2D.x = rightX;
|
s2DData.ptRight2D.x = rightX;
|
||||||
s2DData.ptRight2D.y = rightY;
|
s2DData.ptRight2D.y = rightY;
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2123,9 +2111,13 @@ int LaserDataLoader::_ParseLaserScanPoint(const std::string& data, SVzNLPointXYZ
|
|||||||
sData.y = Y;
|
sData.y = Y;
|
||||||
sData.z = Z;
|
sData.z = Z;
|
||||||
|
|
||||||
int nr = (int)(r * 255);
|
const auto toByte = [](float value) {
|
||||||
int ng = (int)(g * 255);
|
const float bounded = value < 0.0f ? 0.0f : (value > 1.0f ? 1.0f : value);
|
||||||
int nb = (int)(b * 255);
|
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 <<= 8;
|
||||||
nb += ng;
|
nb += ng;
|
||||||
nb <<= 8;
|
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 |
Loading…
x
Reference in New Issue
Block a user