From d4944377bd17ebc570ed5a92197dd673890d7eac Mon Sep 17 00:00:00 2001 From: Andriy Date: Thu, 16 Jan 2025 22:08:36 -0500 Subject: [PATCH] initial --- src/nyx/env_features.cpp | 191 ++++++++------------------------ src/nyx/featureset.cpp | 32 ++++-- src/nyx/featureset.h | 14 +-- src/nyx/scan_fastloader_way.cpp | 5 +- 4 files changed, 80 insertions(+), 162 deletions(-) diff --git a/src/nyx/env_features.cpp b/src/nyx/env_features.cpp index 59ac129d..b1334f9f 100644 --- a/src/nyx/env_features.cpp +++ b/src/nyx/env_features.cpp @@ -37,6 +37,7 @@ #include "features/3d_ngldm.h" #include "features/3d_ngtdm.h" #include "features/3d_gldzm.h" +#include "features/3d_glrlm.h" #include "features/3d_glszm.h" #include "features/roi_radius.h" #include "helpers/helpers.h" @@ -131,8 +132,8 @@ bool Environment::spellcheck_raw_featurelist(const std::string& comma_separated_ if (dim() == 3) { - // Is feature found among 2D features? - Fgroup3D afg; + // Is feature found among 3D features? + int afg; // signed Fgroup3D bool gnameExists = theFeatureSet.find_3D_GroupByString (s_uppr, afg); // Intercept an error: 3D feature group exists but requested in the non-3D mode @@ -150,7 +151,7 @@ bool Environment::spellcheck_raw_featurelist(const std::string& comma_separated_ continue; } - Feature3D af; + int af; // signed Feature3D bool fnameExists = theFeatureSet.find_3D_FeatureByString (s_uppr, af); // 3D feature group requested on a non-3D mode ? @@ -353,11 +354,19 @@ bool Environment::expand_2D_featuregroup (const std::string & s) // bool Environment::expand_3D_featuregroup (const std::string& s) { - // mutually exclusive groups: - if (s == Nyxus::theFeatureSet.findGroupNameByCode(Fgroup3D::FG3_ALL)) + int fgcode; + if (!Nyxus::theFeatureSet.find_3D_GroupByString(s, fgcode)) + return false; // 's' is a feature name + bool enable = true; + if (fgcode < 0) { - theFeatureSet.enableAll(false); + fgcode = -fgcode; + enable = false; + } + // mutually exclusive groups: + if ((Fgroup3D)fgcode == Fgroup3D::FG3_ALL) + { auto F = { Feature3D::COV, @@ -439,172 +448,61 @@ bool Environment::expand_3D_featuregroup (const std::string& s) #endif }; - theFeatureSet.enableFeatures (F); - theFeatureSet.enableFeatures (D3_GLCM_feature::featureset); - theFeatureSet.enableFeatures (D3_GLDZM_feature::featureset); - theFeatureSet.enableFeatures (D3_GLSZM_feature::featureset); + theFeatureSet.enableFeatures (F, enable); + theFeatureSet.enableFeatures (D3_GLCM_feature::featureset, enable); + theFeatureSet.enableFeatures (D3_GLDM_feature::featureset, enable); + theFeatureSet.enableFeatures (D3_GLDZM_feature::featureset, enable); + theFeatureSet.enableFeatures (D3_GLRLM_feature::featureset, enable); + theFeatureSet.enableFeatures (D3_GLSZM_feature::featureset, enable); + theFeatureSet.enableFeatures (D3_NGLDM_feature::featureset, enable); + theFeatureSet.enableFeatures (D3_NGTDM_feature::featureset, enable); return true; } - if (s == Nyxus::theFeatureSet.findGroupNameByCode(Fgroup3D::FG3_GLCM)) + if ((Fgroup3D)fgcode == Fgroup3D::FG3_GLCM) { - theFeatureSet.enableAll (false); - theFeatureSet.enableFeatures (D3_GLCM_feature::featureset); + theFeatureSet.enableFeatures (D3_GLCM_feature::featureset, enable); return true; } - if (s == Nyxus::theFeatureSet.findGroupNameByCode (Fgroup3D::FG3_GLDM)) + if ((Fgroup3D)fgcode == Fgroup3D::FG3_GLDM) { - theFeatureSet.enableAll (false); - theFeatureSet.enableFeatures (D3_GLDM_feature::featureset); + theFeatureSet.enableFeatures (D3_GLDM_feature::featureset, enable); return true; } - if (s == Nyxus::theFeatureSet.findGroupNameByCode (Fgroup3D::FG3_NGLDM)) + if ((Fgroup3D)fgcode == Fgroup3D::FG3_NGLDM) { - theFeatureSet.enableAll (false); - theFeatureSet.enableFeatures (D3_NGLDM_feature::featureset); + theFeatureSet.enableFeatures (D3_NGLDM_feature::featureset, enable); return true; } - if (s == Nyxus::theFeatureSet.findGroupNameByCode (Fgroup3D::FG3_NGTDM)) + if ((Fgroup3D)fgcode == Fgroup3D::FG3_NGTDM) { - theFeatureSet.enableAll (false); - theFeatureSet.enableFeatures (D3_NGTDM_feature::featureset); + theFeatureSet.enableFeatures (D3_NGTDM_feature::featureset, enable); return true; } - if (s == Nyxus::theFeatureSet.findGroupNameByCode(Fgroup3D::FG3_GLCM)) + if ((Fgroup3D)fgcode == Fgroup3D::FG3_GLDZM) { - theFeatureSet.enableAll (false); - - auto F = - { - Nyxus::Feature3D::GLCM_ACOR, - Nyxus::Feature3D::GLCM_ASM, - Nyxus::Feature3D::GLCM_CLUPROM, - Nyxus::Feature3D::GLCM_CLUSHADE, - Nyxus::Feature3D::GLCM_CLUTEND, - Nyxus::Feature3D::GLCM_CONTRAST, - Nyxus::Feature3D::GLCM_CORRELATION, - Nyxus::Feature3D::GLCM_DIFAVE, - Nyxus::Feature3D::GLCM_DIFENTRO, - Nyxus::Feature3D::GLCM_DIFVAR, - Nyxus::Feature3D::GLCM_DIS, - Nyxus::Feature3D::GLCM_ENERGY, - Nyxus::Feature3D::GLCM_ENTROPY, - Nyxus::Feature3D::GLCM_HOM1, - Nyxus::Feature3D::GLCM_HOM2, - Nyxus::Feature3D::GLCM_ID, - Nyxus::Feature3D::GLCM_IDN, - Nyxus::Feature3D::GLCM_IDM, - Nyxus::Feature3D::GLCM_IDMN, - Nyxus::Feature3D::GLCM_INFOMEAS1, - Nyxus::Feature3D::GLCM_INFOMEAS2, - Nyxus::Feature3D::GLCM_IV, - Nyxus::Feature3D::GLCM_JAVE, - Nyxus::Feature3D::GLCM_JE, - Nyxus::Feature3D::GLCM_JMAX, - Nyxus::Feature3D::GLCM_JVAR, - Nyxus::Feature3D::GLCM_SUMAVERAGE, - Nyxus::Feature3D::GLCM_SUMENTROPY, - Nyxus::Feature3D::GLCM_SUMVARIANCE, - Nyxus::Feature3D::GLCM_VARIANCE, - Nyxus::Feature3D::GLCM_ASM_AVE, - Nyxus::Feature3D::GLCM_ACOR_AVE, - Nyxus::Feature3D::GLCM_CLUPROM_AVE, - Nyxus::Feature3D::GLCM_CLUSHADE_AVE, - Nyxus::Feature3D::GLCM_CLUTEND_AVE, - Nyxus::Feature3D::GLCM_CONTRAST_AVE, - Nyxus::Feature3D::GLCM_CORRELATION_AVE, - Nyxus::Feature3D::GLCM_DIFAVE_AVE, - Nyxus::Feature3D::GLCM_DIFENTRO_AVE, - Nyxus::Feature3D::GLCM_DIFVAR_AVE, - Nyxus::Feature3D::GLCM_DIS_AVE, - Nyxus::Feature3D::GLCM_ENERGY_AVE, - Nyxus::Feature3D::GLCM_ENTROPY_AVE, - Nyxus::Feature3D::GLCM_HOM1_AVE, - Nyxus::Feature3D::GLCM_ID_AVE, - Nyxus::Feature3D::GLCM_IDN_AVE, - Nyxus::Feature3D::GLCM_IDM_AVE, - Nyxus::Feature3D::GLCM_IDMN_AVE, - Nyxus::Feature3D::GLCM_IV_AVE, - Nyxus::Feature3D::GLCM_JAVE_AVE, - Nyxus::Feature3D::GLCM_JE_AVE, - Nyxus::Feature3D::GLCM_INFOMEAS1_AVE, - Nyxus::Feature3D::GLCM_INFOMEAS2_AVE, - Nyxus::Feature3D::GLCM_VARIANCE_AVE, - Nyxus::Feature3D::GLCM_JMAX_AVE, - Nyxus::Feature3D::GLCM_JVAR_AVE, - Nyxus::Feature3D::GLCM_SUMAVERAGE_AVE, - Nyxus::Feature3D::GLCM_SUMENTROPY_AVE, - Nyxus::Feature3D::GLCM_SUMVARIANCE_AVE - }; - - theFeatureSet.enableFeatures(F); + theFeatureSet.enableFeatures (D3_GLDZM_feature::featureset, enable); return true; } - if (s == Nyxus::theFeatureSet.findGroupNameByCode(Fgroup3D::FG3_GLDZM)) + if ((Fgroup3D)fgcode == Fgroup3D::FG3_GLSZM) { - theFeatureSet.enableAll (false); - theFeatureSet.enableFeatures (D3_GLDZM_feature::featureset); - return true; - } - - if (s == Nyxus::theFeatureSet.findGroupNameByCode(Fgroup3D::FG3_GLSZM)) - { - theFeatureSet.enableAll (false); - theFeatureSet.enableFeatures (D3_GLSZM_feature::featureset); + theFeatureSet.enableFeatures (D3_GLSZM_feature::featureset, enable); return true; } - if (s == Nyxus::theFeatureSet.findGroupNameByCode(Fgroup3D::FG3_GLRLM)) + if ((Fgroup3D)fgcode == Fgroup3D::FG3_GLRLM) { - theFeatureSet.enableAll(false); - - auto F = - { - Nyxus::Feature3D::GLRLM_SRE, - Nyxus::Feature3D::GLRLM_LRE, - Nyxus::Feature3D::GLRLM_GLN, - Nyxus::Feature3D::GLRLM_GLNN, - Nyxus::Feature3D::GLRLM_RLN, - Nyxus::Feature3D::GLRLM_RLNN, - Nyxus::Feature3D::GLRLM_RP, - Nyxus::Feature3D::GLRLM_GLV, - Nyxus::Feature3D::GLRLM_RV, - Nyxus::Feature3D::GLRLM_RE, - Nyxus::Feature3D::GLRLM_LGLRE, - Nyxus::Feature3D::GLRLM_HGLRE, - Nyxus::Feature3D::GLRLM_SRLGLE, - Nyxus::Feature3D::GLRLM_SRHGLE, - Nyxus::Feature3D::GLRLM_LRLGLE, - Nyxus::Feature3D::GLRLM_LRHGLE, - - Nyxus::Feature3D::GLRLM_SRE_AVE, - Nyxus::Feature3D::GLRLM_LRE_AVE, - Nyxus::Feature3D::GLRLM_GLN_AVE, - Nyxus::Feature3D::GLRLM_GLNN_AVE, - Nyxus::Feature3D::GLRLM_RLN_AVE, - Nyxus::Feature3D::GLRLM_RLNN_AVE, - Nyxus::Feature3D::GLRLM_RP_AVE, - Nyxus::Feature3D::GLRLM_GLV_AVE, - Nyxus::Feature3D::GLRLM_RV_AVE, - Nyxus::Feature3D::GLRLM_RE_AVE, - Nyxus::Feature3D::GLRLM_LGLRE_AVE, - Nyxus::Feature3D::GLRLM_HGLRE_AVE, - Nyxus::Feature3D::GLRLM_SRLGLE_AVE, - Nyxus::Feature3D::GLRLM_SRHGLE_AVE, - Nyxus::Feature3D::GLRLM_LRLGLE_AVE, - Nyxus::Feature3D::GLRLM_LRHGLE_AVE - }; - - theFeatureSet.enableFeatures(F); + theFeatureSet.enableFeatures (D3_GLRLM_feature::featureset, enable); return true; } + // unrecognized feature group return false; } @@ -643,6 +541,8 @@ void Environment::expand_featuregroups() continue; } + // try to interpret 's' as a group name + if (dim() == 2) { if (expand_2D_featuregroup (s)) @@ -656,24 +556,25 @@ void Environment::expand_featuregroups() } // 's' is an individual feature name, not feature group name. Process it now + if (dim() == 2) { int fcode; // signed Feature2D - if (!theFeatureSet.find_2D_FeatureByString (s, fcode)) + if (!Nyxus::theFeatureSet.find_2D_FeatureByString (s, fcode)) throw std::invalid_argument("Error: '" + s + "' is not a valid 2D feature name \n"); - theFeatureSet.enableFeature (fcode); + Nyxus::theFeatureSet.enableFeature (fcode); continue; } if (dim() == 3) { - Feature3D a; - if (!theFeatureSet.find_3D_FeatureByString(s, a)) + int a; // signed Feature3D + if (!Nyxus::theFeatureSet.find_3D_FeatureByString(s, a)) throw std::invalid_argument("Error: '" + s + "' is not a valid 3D feature name \n"); - theFeatureSet.enableFeature (int(a)); + Nyxus::theFeatureSet.enableFeature (int(a)); continue; } } diff --git a/src/nyx/featureset.cpp b/src/nyx/featureset.cpp index 217c80e0..a8989002 100644 --- a/src/nyx/featureset.cpp +++ b/src/nyx/featureset.cpp @@ -945,7 +945,6 @@ bool FeatureSet::find_2D_GroupByString ( enable = name[0] == '+' ? 1 : -1; } - // search auto itr = Nyxus::UserFacing2dFeaturegroupNames.find (s); @@ -957,31 +956,47 @@ bool FeatureSet::find_2D_GroupByString ( return true; } -bool FeatureSet::find_3D_FeatureByString (const std::string & name, Feature3D & f) +bool FeatureSet::find_3D_FeatureByString (const std::string & name, int & f) { + int enable = 1; + // strip possible set operation '+' or '-' std::string s = name; - if (name[0] == '-' || name[0] == '+') - s = name.substr(1); + // digest optional unary operator (sign) + if (std::ispunct(name[0])) + if (name[0] == '-' || name[0] == '+') + { + s = name.substr(1); + enable = name[0] == '+' ? 1 : -1; + } + else + return false; // invalid unary operator // search - auto it_f = Nyxus::UserFacing_3D_featureNames.find (s); + auto it_f = Nyxus::UserFacing_3D_featureNames.find(s); if (it_f == Nyxus::UserFacing_3D_featureNames.end()) return false; - f = it_f->second; + f = enable * (int)it_f->second; + return true; } -bool FeatureSet::find_3D_GroupByString (const std::string & name, Fgroup3D & grpCode) +bool FeatureSet::find_3D_GroupByString (const std::string & name, int & grpCode) { + int enable = 1; + // strip possible set operation '+' or '-' std::string s = name; + // digest optional unary operator (sign) if (name[0] == '-' || name[0] == '+') + { s = name.substr(1); + enable = name[0] == '+' ? 1 : -1; + } // search auto itr = Nyxus::UserFacing3dFeaturegroupNames.find (s); @@ -989,7 +1004,8 @@ bool FeatureSet::find_3D_GroupByString (const std::string & name, Fgroup3D & grp if (itr == Nyxus::UserFacing3dFeaturegroupNames.end()) return false; - grpCode = itr->second; + grpCode = enable * (int)itr->second; + return true; } diff --git a/src/nyx/featureset.h b/src/nyx/featureset.h index 7e18abe0..108877aa 100644 --- a/src/nyx/featureset.h +++ b/src/nyx/featureset.h @@ -854,7 +854,7 @@ namespace Nyxus enum class Fgroup2D { FG2_ALL = 0, - FG2_WHOLESLIDE, + FG2_WHOLESLIDE, // FG2_WHOLESLIDE is FG2_ALL for whole slides FG2_INTENSITY, FG2_MORPHOLOGY, FG2_BASIC_MORPHOLOGY, @@ -925,10 +925,10 @@ class FeatureSet for (auto f : F) m_enabledFeatures[(int)f] = enable; } - void enableFeatures(const std::initializer_list& desiredFeatures) + void enableFeatures(const std::initializer_list& F, bool enable = true) { - for (auto f : desiredFeatures) - m_enabledFeatures[(int)f] = true; + for (auto f : F) + m_enabledFeatures[(int)f] = enable; } void enableFeatures(const std::initializer_list& desiredFeatures) { for (auto f : desiredFeatures) @@ -1039,10 +1039,10 @@ class FeatureSet cnt++; return cnt; } - bool find_2D_FeatureByString (const std::string& name, int& f); // 'f' is signed Feature2D + bool find_2D_FeatureByString (const std::string & name, int & f); // 'f' is signed Feature2D bool find_2D_GroupByString (const std::string& group_name, int & group_code); // 'group_code' is signed Nyxus::Fgroup2D - bool find_3D_FeatureByString (const std::string & feature_name, Nyxus::Feature3D & feature_code); - bool find_3D_GroupByString (const std::string & group_name, Nyxus::Fgroup3D & group_code); + bool find_3D_FeatureByString (const std::string & feature_name, int & feature_code); + bool find_3D_GroupByString (const std::string & group_name, int & group_code); bool find_IMQ_FeatureByString (const std::string & feature_name, Nyxus::FeatureIMQ & feature_code); bool find_IMQ_GroupByString (const std::string & group_name, Nyxus::FgroupIMQ & group_code); diff --git a/src/nyx/scan_fastloader_way.cpp b/src/nyx/scan_fastloader_way.cpp index 63e2da7d..3489153f 100644 --- a/src/nyx/scan_fastloader_way.cpp +++ b/src/nyx/scan_fastloader_way.cpp @@ -228,8 +228,9 @@ namespace Nyxus static unsigned long long initial_freeRamAmt = 0; if (initial_freeRamAmt == 0) initial_freeRamAmt = freeRamAmt; - double memDiff = double(freeRamAmt) - double(initial_freeRamAmt); - VERBOSLVL1(std::cout << std::setw(15) << freeRamAmt << " bytes free (" << "consumed=" << memDiff << ") ") + unsigned long long diff = std::max (freeRamAmt, initial_freeRamAmt) - std::min (freeRamAmt, initial_freeRamAmt); + char diffSgn = freeRamAmt > initial_freeRamAmt ? '-' : '+'; + VERBOSLVL1(std::cout << std::setw(15) << virguler(freeRamAmt) << " bytes free (" << "consumed=" << diffSgn << virguler(diff) << ") ") // Display (1) dataset progress info and (2) file pair info int digits = 2, k = std::pow(10.f, digits);