diff --git a/src/app/SettingsDialog.ui b/src/app/SettingsDialog.ui index 1c7f7869b..d02b1cdce 100644 --- a/src/app/SettingsDialog.ui +++ b/src/app/SettingsDialog.ui @@ -398,11 +398,14 @@ The minimum deviation to be highlighted. + + 1 + - 45.000000000000000 + 999.000000000000000 - 0.100000000000000 + 1.000000000000000 diff --git a/src/core/DeviationProvider.h b/src/core/DeviationProvider.h index 29c1b66cf..148e19d9f 100644 --- a/src/core/DeviationProvider.h +++ b/src/core/DeviationProvider.h @@ -18,7 +18,7 @@ class DeviationProvider { explicit DeviationProvider(const std::function& computeValueByKey); - bool isDeviant(const K& key, double coefficient = 1.0, double threshold = 0.0) const; + bool isDeviant(const K& key, double coefficient = 1.0, double threshold = 0.0, bool defaultVal = false) const; double getDeviationValue(const K& key) const; @@ -51,7 +51,7 @@ DeviationProvider::DeviationProvider(const std::function -bool DeviationProvider::isDeviant(const K& key, const double coefficient, const double threshold) const { +bool DeviationProvider::isDeviant(const K& key, double coefficient, double threshold, bool defaultVal) const { if (m_keyValueMap.find(key) == m_keyValueMap.end()) { return false; } @@ -59,19 +59,30 @@ bool DeviationProvider::isDeviant(const K& key, const double coefficien return false; } + double value = m_keyValueMap.at(key); + if (std::isnan(value)) { + return defaultVal; + } + update(); - return (std::abs(m_keyValueMap.at(key) - m_meanValue) > std::max((coefficient * m_standardDeviation), threshold)); + return (std::abs(value - m_meanValue) + > std::max((coefficient * m_standardDeviation), (threshold / 100) * m_meanValue)); } template double DeviationProvider::getDeviationValue(const K& key) const { if (m_keyValueMap.find(key) == m_keyValueMap.end()) { - return .0; + return -1.0; } if (m_keyValueMap.size() < 2) { return .0; } + double value = m_keyValueMap.at(key); + if (std::isnan(value)) { + return -1.0; + } + update(); return std::abs(m_keyValueMap.at(key) - m_meanValue); } @@ -97,7 +108,6 @@ void DeviationProvider::remove(const K& key) { if (m_keyValueMap.find(key) == m_keyValueMap.end()) { return; } - m_keyValueMap.erase(key); } @@ -110,20 +120,26 @@ void DeviationProvider::update() const { return; } + int count = 0; { double sum = .0; - for (const std::pair& keyAndValue : m_keyValueMap) { - sum += keyAndValue.second; + for (const auto& [key, value] : m_keyValueMap) { + if (!std::isnan(value)) { + sum += value; + count++; + } } - m_meanValue = sum / m_keyValueMap.size(); + m_meanValue = sum / count; } { double differencesSum = .0; - for (const std::pair& keyAndValue : m_keyValueMap) { - differencesSum += std::pow(keyAndValue.second - m_meanValue, 2); + for (const auto& [key, value] : m_keyValueMap) { + if (!std::isnan(value)) { + differencesSum += std::pow(value - m_meanValue, 2); + } } - m_standardDeviation = std::sqrt(differencesSum / (m_keyValueMap.size() - 1)); + m_standardDeviation = std::sqrt(differencesSum / (count - 1)); } m_needUpdate = false; diff --git a/src/core/filters/deskew/Settings.cpp b/src/core/filters/deskew/Settings.cpp index 2a4345d76..656ff1f6e 100644 --- a/src/core/filters/deskew/Settings.cpp +++ b/src/core/filters/deskew/Settings.cpp @@ -16,9 +16,8 @@ Settings::Settings() { if (it != m_perPageParams.end()) { const Params& params = it->second; return params.deskewAngle(); - } else { - return .0; - }; + } + return NAN; }); } diff --git a/src/core/filters/page_layout/Settings.cpp b/src/core/filters/page_layout/Settings.cpp index d9bc655be..fe06320cd 100644 --- a/src/core/filters/page_layout/Settings.cpp +++ b/src/core/filters/page_layout/Settings.cpp @@ -351,16 +351,14 @@ Settings::Impl::Impl() m_autoMarginsDefault(false), m_showMiddleRect(true) { m_deviationProvider.setComputeValueByKey([this](const PageId& pageId) -> double { - auto it(m_items.find(pageId)); + auto it = m_items.find(pageId); if (it != m_items.end()) { - if (it->alignment.isNull()) { - return std::sqrt(it->hardWidthMM() * it->hardHeightMM() / 4 / 25.4); - } else { - return .0; - } - } else { - return .0; - }; + const Margins& marginsMm = it->hardMarginsMM; + double horHardMargins = marginsMm.left() + marginsMm.right(); + double vertHardMargins = marginsMm.top() + marginsMm.bottom(); + return std::sqrt(std::pow(horHardMargins, 2) * std::pow(vertHardMargins, 2)); + } + return NAN; }); } diff --git a/src/core/filters/select_content/CacheDrivenTask.cpp b/src/core/filters/select_content/CacheDrivenTask.cpp index 492d22c8e..46d4d99db 100644 --- a/src/core/filters/select_content/CacheDrivenTask.cpp +++ b/src/core/filters/select_content/CacheDrivenTask.cpp @@ -53,10 +53,10 @@ void CacheDrivenTask::process(const PageInfo& pageInfo, const double deviationThreshold = settings.getSelectContentDeviationThreshold(); if (auto* thumbCol = dynamic_cast(collector)) { - thumbCol->processThumbnail(std::unique_ptr( - new Thumbnail(thumbCol->thumbnailCache(), thumbCol->maxLogicalThumbSize(), pageInfo.imageId(), xform, - params->contentRect(), params->pageRect(), params->pageDetectionMode() != MODE_DISABLED, - m_settings->deviationProvider().isDeviant(pageInfo.id(), deviationCoef, deviationThreshold)))); + thumbCol->processThumbnail(std::unique_ptr(new Thumbnail( + thumbCol->thumbnailCache(), thumbCol->maxLogicalThumbSize(), pageInfo.imageId(), xform, params->contentRect(), + params->pageRect(), params->pageDetectionMode() != MODE_DISABLED, + m_settings->deviationProvider().isDeviant(pageInfo.id(), deviationCoef, deviationThreshold, true)))); } } // CacheDrivenTask::process } // namespace select_content \ No newline at end of file diff --git a/src/core/filters/select_content/Settings.cpp b/src/core/filters/select_content/Settings.cpp index bdeb99647..5098f8fe7 100644 --- a/src/core/filters/select_content/Settings.cpp +++ b/src/core/filters/select_content/Settings.cpp @@ -18,10 +18,10 @@ Settings::Settings() : m_pageDetectionBox(0.0, 0.0), m_pageDetectionTolerance(0. if (it != m_pageParams.end()) { const Params& params = it->second; const QSizeF& contentSizeMM = params.contentSizeMM(); - return std::sqrt(contentSizeMM.width() * contentSizeMM.height() / 4 / 25.4); - } else { - return .0; - }; + if (!contentSizeMM.toSize().isEmpty()) + return std::sqrt(std::pow(contentSizeMM.width(), 2) + std::pow(contentSizeMM.height(), 2)); + } + return NAN; }); }