diff --git a/CloudUtils/CloudUtils.pro b/CloudUtils/CloudUtils.pro index 048317e..7801875 100644 --- a/CloudUtils/CloudUtils.pro +++ b/CloudUtils/CloudUtils.pro @@ -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 diff --git a/CloudUtils/Inc/LaserDataLoader.h b/CloudUtils/Inc/LaserDataLoader.h index 1551de2..960e5dd 100644 --- a/CloudUtils/Inc/LaserDataLoader.h +++ b/CloudUtils/Inc/LaserDataLoader.h @@ -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; + using LaserLineLoadCallback = std::function; // 过滤后仍提供源扫描线点数及每个保留点的原始线内索引。 - using LaserLineLoadIndexedCallback = - std::function; + using LaserLineLoadIndexedCallback = std::function; // Called exactly once when loading succeeds or fails. // Arguments: result, lineNum, scanSpeed, maxTimeStamp, clockPerSecond. - using LaserLoadFinishedCallback = - std::function; + using LaserLoadFinishedCallback = std::function; LaserDataLoader(); ~LaserDataLoader(); diff --git a/CloudUtils/Src/LaserDataLoader.cpp b/CloudUtils/Src/LaserDataLoader.cpp index f603323..c51f95b 100644 --- a/CloudUtils/Src/LaserDataLoader.cpp +++ b/CloudUtils/Src/LaserDataLoader.cpp @@ -91,17 +91,16 @@ struct DatLaserScan3DLinesHeader std::uint64_t scanLineList; }; -struct DatLineScan3DData -{ - int lineIndex; - std::uint32_t timeStamp; - double lineStepping; -}; - -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"); - +struct DatLineScan3DData +{ + int lineIndex; + std::uint32_t timeStamp; + double lineStepping; +}; + +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 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; } -bool ReadDatLineRecord(std::ifstream& inputFile, int recordSize, DatLineScan3DData& lineData) -{ - char buffer[40] = {}; +bool ReadDatLineRecord(std::ifstream& inputFile, int recordSize, DatLineScan3DData& lineData) +{ + char buffer[40] = {}; if (recordSize <= 0 || recordSize > static_cast(sizeof(buffer))) { return false; } @@ -151,11 +150,11 @@ bool ReadDatLineRecord(std::ifstream& inputFile, int recordSize, DatLineScan3DDa return false; } - std::memcpy(&lineData.lineIndex, buffer, sizeof(lineData.lineIndex)); - std::memcpy(&lineData.timeStamp, buffer + 4, sizeof(lineData.timeStamp)); - std::memcpy(&lineData.lineStepping, buffer + 8, sizeof(lineData.lineStepping)); - return true; -} + std::memcpy(&lineData.lineIndex, buffer, sizeof(lineData.lineIndex)); + std::memcpy(&lineData.timeStamp, buffer + 4, sizeof(lineData.timeStamp)); + std::memcpy(&lineData.lineStepping, buffer + 8, sizeof(lineData.lineStepping)); + return true; +} void AppendFormattedLine(std::string& output, const char* format, ...) { @@ -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(pointCount)); - std::memset(rgba2DPoints.get(), 0, - sizeof(SVzNL2DLRPoint) * static_cast(pointCount)); + std::memset(rgbaPoints.get(), 0, sizeof(SVzNLPointXYZRGBA) * static_cast(pointCount)); + std::memset(rgba2DPoints.get(), 0, sizeof(SVzNL2DLRPoint) * static_cast(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(pointCount)); - std::memset(position2DPoints.get(), 0, - sizeof(SVzNL2DPosition) * static_cast(pointCount)); + std::memset(positionPoints.get(), 0, sizeof(SVzNL3DPosition) * static_cast(pointCount)); + std::memset(position2DPoints.get(), 0, sizeof(SVzNL2DPosition) * static_cast(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(lineData.llFrameIdx) + << "_" << static_cast(lineData.llTimeStamp) + << "_" << lineData.nPointCount << '\n'; if (dataType == keResultDataType_Position && lineData.p3DPoint) { const SVzNL3DPosition* points = static_cast(lineData.p3DPoint); @@ -1059,17 +1056,14 @@ bool LaserDataLoader::WriteLaserScanLine(std::ostream& sw, EVzResultDataType dat 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(points[i].pt3D.x); - float y = static_cast(points[i].pt3D.y); - float z = static_cast(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); + 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, "{ %.6f,%.6f,%.6f }-{ %d,%d }-{ %d,%d }\n", + 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); } sw.write(buffer.data(), static_cast(buffer.size())); } @@ -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((std::numeric_limits::max)()) || - line.llTimeStamp > (std::numeric_limits::max)()) - { - m_lastError = "Frame index or timestamp exceeds legacy binary format range"; - return ERR_CODE(DEV_ARG_INVAILD); - } maxPointCount = std::max(maxPointCount, static_cast(line.nPointCount)); } @@ -1885,22 +1873,22 @@ void LaserDataLoader::FreeConvertedData(std::vector& 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; - const int parsed = sscanf(data.c_str(), - " { %f , %f , %f } - { %f , %f } - { %f , %f }", - &X, &Y, &Z, &leftX, &leftY, &rightX, &rightY); + 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(), + " { %lf , %lf , %lf } - { %d , %d } - { %d , %d }", + &X, &Y, &Z, &leftX, &leftY, &rightX, &rightY); if (parsed != 7) { return ERR_CODE(FILE_ERR_FORMAT); } sData.pt3D.x = X; sData.pt3D.y = Y; sData.pt3D.z = Z; - s2DData.ptLeft2D.x = leftX; - s2DData.ptLeft2D.y = leftY; - s2DData.ptRight2D.x = rightX; - s2DData.ptRight2D.y = rightY; + s2DData.ptLeft2D.x = leftX; + s2DData.ptLeft2D.y = leftY; + s2DData.ptRight2D.x = rightX; + s2DData.ptRight2D.y = rightY; return SUCCESS; } @@ -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(std::lround(bounded * 255.0f)); + }; + int nr = static_cast(toByte(r)); + int ng = static_cast(toByte(g)); + int nb = static_cast(toByte(b)); nb <<= 8; nb += ng; nb <<= 8; diff --git a/CloudViewApp/resource/logo.ico b/CloudViewApp/resource/logo.ico index cd0e408..e85eeaa 100644 Binary files a/CloudViewApp/resource/logo.ico and b/CloudViewApp/resource/logo.ico differ diff --git a/CloudViewApp/resource/logo.png b/CloudViewApp/resource/logo.png index 2b3b2e2..a13c1c3 100644 Binary files a/CloudViewApp/resource/logo.png and b/CloudViewApp/resource/logo.png differ