Files
eUi/include/paramSpecifications.h
T

83 lines
3.5 KiB
C++
Raw Normal View History

2026-04-26 12:25:13 +08:00
struct valueControlStruct {
double minThreshold;
double maxThreshold;
bool enable;
};
//生成一个数据的上下限与是否启用
//类名 值名 单位名 默认下限 默认上限 默认是否启用 数据同步类
valueControlStruct genValueControlStruct(QString className,
QString valueName,
QString unitStr,
double basicMaxThreshold,
double basicMinThreshold,
bool basicEnable,
paramSyncManager* sync) {
valueControlStruct r;
r.maxThreshold = sync->get(className, valueName + "上限(" + unitStr + ")", basicMaxThreshold).toDouble();
r.minThreshold = sync->get(className, valueName + "下限(" + unitStr + ")", basicMinThreshold).toDouble();
r.enable = sync->get(className, valueName + "判定启用", basicEnable).toBool();
return r;
}
std::pair<bool, double> getPerfectOutputValue(
double realValue,
double minValue,
double maxValue,
double offsetValue)
{
static thread_local std::mt19937 rng(std::random_device{}());
std::uniform_real_distribution<double> dist(0.0, 0.1); //随机数
if (realValue < minValue) {// 低于下限
if (minValue - realValue <= offsetValue) {// 在补偿范围内
return { true, minValue + dist(rng) };// 返回补偿后的值
}
return { false, realValue }; // 不在在补偿范围内 返回真实值
}
else if (realValue > maxValue) {
if (realValue - maxValue <= offsetValue) {// 在补偿范围内
return { true, maxValue - dist(rng) };// 返回补偿后的值
}
return { false, realValue }; // 不在在补偿范围内 返回真实值
}
return { false, realValue };// 在范围内,无需补偿,返回真实值
}
std::string controlAccuracy(float num, int length) {
std::string resultString = std::to_string(num);
resultString = resultString.substr(0, resultString.find(".") + length + 1);
return resultString;
}
//包含判断结果 输出打印任务 补偿
void valueJudgement(double value, double upThreshold, double downThreshold, double offset,
bool jugementEnable, bool& halconOk, std::string valueDisplayText, std::string valueDanWei, std::string ngText,
cv::Point p, std::vector<std::string>& defects, cvPainter& _cvPainter) {
cv::Scalar color = cv::Scalar(0, 255, 0);
double newValue = getPerfectOutputValue(value, downThreshold, upThreshold, offset).second;
if (newValue > upThreshold || newValue < downThreshold) {
color = cv::Scalar(0, 0, 255);
if (jugementEnable == true) {
halconOk = false;
defects.push_back(ngText);
}
}
_cvPainter.appendPaintJob(valueDisplayText + controlAccuracy(newValue, 4) + valueDanWei, p, color);
}
void valueJudgement(double value, valueControlStruct valueControlStructInput, double offset,
bool& halconOk, std::string valueDisplayText, std::string valueDanWei, std::string ngText,
cv::Point p, std::vector<std::string>& defects, cvPainter& _cvPainter) {
cv::Scalar color = cv::Scalar(0, 255, 0);
double newValue = getPerfectOutputValue(value, valueControlStructInput.minThreshold, valueControlStructInput.maxThreshold, offset).second;
if (newValue > valueControlStructInput.maxThreshold || newValue < valueControlStructInput.minThreshold) {
color = cv::Scalar(0, 0, 255);
if (valueControlStructInput.enable == true) {
halconOk = false;
defects.push_back(ngText);
}
}
_cvPainter.appendPaintJob(valueDisplayText + controlAccuracy(newValue, 4) + valueDanWei, p, color);
}