From 13985f31aa16e05fe872c4c1f5822a9e55f66659 Mon Sep 17 00:00:00 2001 From: chenzenghui <3045316072@qq.com> Date: Tue, 17 Jun 2025 02:57:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BA=86=20=E5=9B=BE?= =?UTF-8?q?=E5=83=8F=E5=AE=9A=E6=A0=87=E4=B8=8Exml=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E6=96=87=E4=BB=B6=20=E5=8A=9F=E8=83=BD=E7=BC=96=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BaseTool/BaseConstVariable.h | 1 - BaseTool/BaseTool.cpp | 26 ++++++++++- BaseTool/BaseTool.h | 90 ++++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+), 3 deletions(-) diff --git a/BaseTool/BaseConstVariable.h b/BaseTool/BaseConstVariable.h index 33ffd61..3e971b5 100644 --- a/BaseTool/BaseConstVariable.h +++ b/BaseTool/BaseConstVariable.h @@ -124,7 +124,6 @@ enum SIGMATYPE { LINEARVALUE }; - /*********************************************** 基础结构体区域 ********************************************************************/ /// diff --git a/BaseTool/BaseTool.cpp b/BaseTool/BaseTool.cpp index 1bd39f3..25bcb81 100644 --- a/BaseTool/BaseTool.cpp +++ b/BaseTool/BaseTool.cpp @@ -43,6 +43,29 @@ #include #include + + +QString PolarTypeEnumToString(POLARTYPEENUM type) +{ + switch (type) { + case POLARHH: return "HH"; + case POLARHV: return "HV"; + case POLARVH: return "VH"; + case POLARVV: return "VV"; + default: return "UNKOWN"; + } +} + +POLARTYPEENUM StringToPolarTypeEnum(const QString& str) +{ + if (str.compare("HH", Qt::CaseInsensitive) == 0) return POLARHH; + if (str.compare("HV", Qt::CaseInsensitive) == 0) return POLARHV; + if (str.compare("VH", Qt::CaseInsensitive) == 0) return POLARVH; + if (str.compare("VV", Qt::CaseInsensitive) == 0) return POLARVV; + return POLARUNKOWN; +} + + QString longDoubleToQStringScientific(long double value) { std::ostringstream stream; @@ -136,8 +159,6 @@ double Bilinear_interpolation(Landpoint p0, Landpoint p11, Landpoint p21, Land p22.ati * p0.lon * p0.lat; } - - bool onSegment(Point3 Pi, Point3 Pj, Point3 Q) { if ((Q.x - Pi.x) * (Pj.y - Pi.y) == (Pj.x - Pi.x) * (Q.y - Pi.y) //叉乘 @@ -260,6 +281,7 @@ QString JoinPath(const QString& path, const QString& filename) return dir.filePath(filename); } + std::vector convertQStringListToStdVector(const QStringList& qStringList) { std::vector stdVector; diff --git a/BaseTool/BaseTool.h b/BaseTool/BaseTool.h index 7e4550d..874dbec 100644 --- a/BaseTool/BaseTool.h +++ b/BaseTool/BaseTool.h @@ -33,6 +33,18 @@ #include #include #include +#include +#include +#include +#include +#include +#include + + +///////////////////////////////////// 基础类型转换函数 ///////////////////////////////////////////////////////////// +QString BASECONSTVARIABLEAPI PolarTypeEnumToString(POLARTYPEENUM type); +POLARTYPEENUM BASECONSTVARIABLEAPI StringToPolarTypeEnum(const QString& str); + ///////////////////////////////////// 基础数学函数 ///////////////////////////////////////////////////////////// @@ -47,6 +59,84 @@ QString BASECONSTVARIABLEAPI getCurrentShortTimeString(); std::vector BASECONSTVARIABLEAPI splitString(const QString& str, char delimiter); std::vector BASECONSTVARIABLEAPI convertQStringListToStdVector(const QStringList& qStringList); + + + + +// 解析ISO 8601格式时间字符串到time_point +template +inline typename Clock::time_point parse_iso8601(const std::string& timestamp) { + std::tm tm = {}; + std::istringstream ss(timestamp); + char sep; + + // 解析日期部分 + ss >> tm.tm_year >> sep; // sep是'-' + ss >> tm.tm_mon >> sep; // sep是'-' + ss >> tm.tm_mday; + + // 解析时间部分 + ss >> sep; // 'T' + ss >> tm.tm_hour >> sep; // ':' + ss >> tm.tm_min >> sep; // ':' + ss >> tm.tm_sec; + + // 调整tm结构的值(年份从1900开始,月份0-11) + tm.tm_year -= 1900; + tm.tm_mon -= 1; + + // 转换为time_t + std::time_t tt = std::mktime(&tm); + if (tt == -1) { + throw std::runtime_error("Invalid time"); + } + + // 解析毫秒和纳秒部分 + double fractional_seconds = 0.0; + if (ss.peek() == '.') { + ss >> sep; // '.' + ss >> fractional_seconds; + } + + // 转换为time_point + auto tp = Clock::from_time_t(tt); + + // 添加纳秒部分 + auto duration_since_epoch = tp.time_since_epoch(); + auto seconds = std::chrono::duration_cast(duration_since_epoch); + auto nanoseconds = std::chrono::duration_cast( + duration_since_epoch - seconds + + std::chrono::duration_cast( + std::chrono::duration(fractional_seconds))); + + return typename Clock::time_point(seconds + nanoseconds); +}; + +// 格式化输出时间(带纳秒精度) +template +inline std::string format_iso8601_nano(typename Clock::time_point tp) { + using namespace std::chrono; + + // 转换为time_t + auto tt = Clock::to_time_t(tp); + std::tm tm = *std::gmtime(&tt); // 使用UTC时间 + + // 获取毫秒和纳秒部分 + auto since_epoch = tp.time_since_epoch(); + auto sec = duration_cast(since_epoch); + auto ns = duration_cast(since_epoch - sec); + + // 格式化为字符串 + std::ostringstream oss; + oss << std::put_time(&tm, "%Y-%m-%dT%H:%M:%S"); + + // 添加纳秒部分(9位小数) + oss << "." << std::setfill('0') << std::setw(9) << ns.count(); + + return oss.str(); +}; + + /////////////////////////////// 基本图像类 结束 /////////////////////////////////////////////////////////////