#include "PaperConfig.h" #include "GlobalParams.h" #include PaperConfigManager& PaperConfigManager::getInstance() { static PaperConfigManager instance; return instance; } PaperConfigManager::PaperConfigManager() { initConfigs(); } void PaperConfigManager::initConfigs() { // PST_14_S: 14联, 10mm大定位块 PaperConfig config14s; config14s.type = PaperSpatialType::PST_14_S; config14s.blockItems = BlockItems::BI_14; config14s.locatorType = BigLocatorType::BLT_SHORT; config14s.itemsNum = 14; config14s.slicesNum = 50; config14s.firstPos = 2.25; config14s.step = 3.5; config14s.distTimes = 21.3; config14s.whBigRatio = GlobalParams::BIG_LOCATOR_RATIO_SHORT; configs_[PaperSpatialType::PST_14_S] = config14s; // PST_14_L: 14联, 15mm大定位块 PaperConfig config14l; config14l.type = PaperSpatialType::PST_14_L; config14l.blockItems = BlockItems::BI_14; config14l.locatorType = BigLocatorType::BLT_LONG; config14l.itemsNum = 14; config14l.slicesNum = 50; config14l.firstPos = 2.25; config14l.step = 3.5; config14l.distTimes = 21.8; config14l.whBigRatio = GlobalParams::BIG_LOCATOR_RATIO_LONG; configs_[PaperSpatialType::PST_14_L] = config14l; // PST_11_S: 11联, 10mm大定位块 PaperConfig config11s; config11s.type = PaperSpatialType::PST_11_S; config11s.blockItems = BlockItems::BI_11; config11s.locatorType = BigLocatorType::BLT_SHORT; config11s.itemsNum = 11; config11s.slicesNum = 39; config11s.firstPos = 2.25; config11s.step = 3.5; config11s.distTimes = 17.6; config11s.whBigRatio = GlobalParams::BIG_LOCATOR_RATIO_SHORT; configs_[PaperSpatialType::PST_11_S] = config11s; // PST_11_L: 11联, 15mm大定位块 PaperConfig config11l; config11l.type = PaperSpatialType::PST_11_L; config11l.blockItems = BlockItems::BI_11; config11l.locatorType = BigLocatorType::BLT_LONG; config11l.itemsNum = 11; config11l.slicesNum = 39; config11l.firstPos = 2.25; config11l.step = 3.5; config11l.distTimes = 18.1; config11l.whBigRatio = GlobalParams::BIG_LOCATOR_RATIO_LONG; configs_[PaperSpatialType::PST_11_L] = config11l; // PST_8_S: 8联, 10mm大定位块 PaperConfig config8s; config8s.type = PaperSpatialType::PST_8_S; config8s.blockItems = BlockItems::BI_8; config8s.locatorType = BigLocatorType::BLT_SHORT; config8s.itemsNum = 8; config8s.slicesNum = 29; config8s.firstPos = 2.25; config8s.step = 3.5; config8s.distTimes = 12.9; config8s.whBigRatio = GlobalParams::BIG_LOCATOR_RATIO_SHORT; configs_[PaperSpatialType::PST_8_S] = config8s; // PST_8_L: 8联, 15mm大定位块 PaperConfig config8l; config8l.type = PaperSpatialType::PST_8_L; config8l.blockItems = BlockItems::BI_8; config8l.locatorType = BigLocatorType::BLT_LONG; config8l.itemsNum = 8; config8l.slicesNum = 29; config8l.firstPos = 2.25; config8l.step = 3.5; config8l.distTimes = 13.4; config8l.whBigRatio = GlobalParams::BIG_LOCATOR_RATIO_LONG; configs_[PaperSpatialType::PST_8_L] = config8l; } const PaperConfig* PaperConfigManager::getConfig(PaperSpatialType type) const { auto it = configs_.find(type); if (it != configs_.end()) { return &it->second; } return nullptr; } PaperSpatialType PaperConfigManager::matchConfig(double distRatio, double areaRatio, BigLocatorType locatorType) const { // 参照老代码 ImgLocateDryChemistry::verifyPaperConfig 的逻辑 // 先根据面积比判断大/小规格,再根据距离比判断具体联数 // 面积比范围定义(参照老代码) double Min_AreaRadio_S = 2.6; double Max_AreaRadio_S = 4; double Min_AreaRadio_L = 4.2; double Max_AreaRadio_L = 6.0; // 距离比范围定义(基于实际数据统计) // S型(10mm大定位块) // 14S典型值: 20.5-24.0(考虑不同拍摄距离), 11S典型值: 16.5-18.5 // 临界区域 [18.5, 19.0] 作为空白缓冲,避免误判 double Min_DistRadio_14S = 19.0, Max_DistRadio_14S = 26.5; // 14S: 19.0-26.5(扩大上限覆盖远距离拍摄) double Min_DistRadio_11S = 15.5, Max_DistRadio_11S = 18.5; // 11S: 15.5-18.5(与14S留0.5缓冲) double Min_DistRadio_8S = 11.6, Max_DistRadio_8S = 14.1; // L型(15mm大定位块) double Min_DistRadio_14L = 19.0, Max_DistRadio_14L = 26.98; // 同步调整 double Min_DistRadio_11L = 15.5, Max_DistRadio_11L = 18.5; // 同步调整 double Min_DistRadio_8L = 12.0, Max_DistRadio_8L = 14.5; // 检查面积比是否在有效范围内 if (areaRatio < Min_AreaRadio_S || areaRatio > Max_AreaRadio_L) { return PaperSpatialType::PST_UNKNOWN; } // 空白区间 [4.0, 4.2] 不做判断,避免误判 if (areaRatio > Max_AreaRadio_S && areaRatio < Min_AreaRadio_L) { return PaperSpatialType::PST_UNKNOWN; } // 根据面积比判断大/小规格 bool isSmallType = (areaRatio <= Max_AreaRadio_S); if (isSmallType) { // S型(10mm大定位块) if (distRatio > Min_DistRadio_14S && distRatio < Max_DistRadio_14S) { return PaperSpatialType::PST_14_S; } else if (distRatio > Min_DistRadio_11S && distRatio < Max_DistRadio_11S) { return PaperSpatialType::PST_11_S; } else if (distRatio > Min_DistRadio_8S && distRatio < Max_DistRadio_8S) { return PaperSpatialType::PST_8_S; } } else { // L型(15mm大定位块) if (distRatio > Min_DistRadio_14L && distRatio < Max_DistRadio_14L) { return PaperSpatialType::PST_14_L; } else if (distRatio > Min_DistRadio_11L && distRatio < Max_DistRadio_11L) { return PaperSpatialType::PST_11_L; } else if (distRatio > Min_DistRadio_8L && distRatio < Max_DistRadio_8L) { return PaperSpatialType::PST_8_L; } } return PaperSpatialType::PST_UNKNOWN; }