优化pair的点

This commit is contained in:
MaJunwei 2026-04-01 20:26:24 +08:00
parent 567765b702
commit dbccb48411

View File

@ -480,62 +480,46 @@ bool HasConsistentAdjacentPair(
int curRangeEnd = 0;
GetPairRangeOnLine(pair, useColRange, curRangeStart, curRangeEnd);
const float curCenter = 0.5f * static_cast<float>(curRangeStart + curRangeEnd);
const float curIndexSpan = static_cast<float>(curRangeEnd - curRangeStart);
const float curSpanXY = ComputePairSpanXY(pair);
bool sawComparableNeighbor = false;
bool hasConsistentNeighbor = false;
// 搜索窗口 ±3 行/列,覆盖圆形孔洞边缘处可能跳行/列出现 pair 的情况
const int kWindow = 3;
// 范围重叠容差(索引单位)
const int kOverlapTolerance = 2;
for (int lineOffset = -1; lineOffset <= 1; lineOffset += 2) {
for (int lineOffset = -kWindow; lineOffset <= kWindow; lineOffset++) {
if (lineOffset == 0) continue;
int neighborLine = lineIndex + lineOffset;
if (neighborLine < 0 || neighborLine >= static_cast<int>(allLinePairs.size())) {
continue;
}
for (const auto& neighborPair : allLinePairs[neighborLine]) {
int neighborRangeStart = 0;
int neighborRangeEnd = 0;
GetPairRangeOnLine(neighborPair, useColRange, neighborRangeStart, neighborRangeEnd);
int nRangeStart = 0;
int nRangeEnd = 0;
GetPairRangeOnLine(neighborPair, useColRange, nRangeStart, nRangeEnd);
const float neighborCenter = 0.5f * static_cast<float>(neighborRangeStart + neighborRangeEnd);
const float neighborIndexSpan = static_cast<float>(neighborRangeEnd - neighborRangeStart);
const float overlap = static_cast<float>(
std::min(curRangeEnd, neighborRangeEnd) - std::max(curRangeStart, neighborRangeStart)
);
const float centerDiff = std::abs(curCenter - neighborCenter);
const float maxIndexSpan = std::max(curIndexSpan, neighborIndexSpan);
const bool hasPositionMatch =
(overlap >= -1.0f) ||
(centerDiff <= std::max(2.0f, maxIndexSpan * 0.5f + 1.0f));
if (!hasPositionMatch) {
// 范围重叠检查(带容差):两个 pair 的列/行范围必须有交集
if (curRangeEnd + kOverlapTolerance < nRangeStart ||
nRangeEnd + kOverlapTolerance < curRangeStart) {
continue;
}
sawComparableNeighbor = true;
// 物理跨度一致性:圆形孔洞相邻行/列的 pair 跨度渐变,
// 差异不应超过较大者的 50%(兼顾孔洞边缘处的快速变化)
const float neighborSpanXY = ComputePairSpanXY(neighborPair);
const float maxSpanXY = std::max(curSpanXY, neighborSpanXY);
const float spanDiff = std::abs(curSpanXY - neighborSpanXY);
const float allowedSpanDiff = std::max(params.minFeatureSpan * 2.0f, maxSpanXY * 0.45f);
const float allowedSpanDiff = std::max(params.minFeatureSpan * 2.0f, maxSpanXY * 0.5f);
if (spanDiff <= allowedSpanDiff) {
hasConsistentNeighbor = true;
break;
return true;
}
}
if (hasConsistentNeighbor) {
break;
}
}
if (!sawComparableNeighbor) {
return true;
}
return hasConsistentNeighbor;
// 在 ±kWindow 范围内找不到范围重叠且跨度一致的邻居 → 孤立噪声,丢弃
return false;
}
void FilterPairsByAdjacentConsistency(