Skip to content

Commit 7701dc5

Browse files
friskluftsameeul
andauthored
POL5645 Combinable 3D features
Co-authored-by: Sameeul Samee <[email protected]>
1 parent a8de931 commit 7701dc5

File tree

4 files changed

+80
-162
lines changed

4 files changed

+80
-162
lines changed

src/nyx/env_features.cpp

Lines changed: 46 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "features/3d_ngldm.h"
3838
#include "features/3d_ngtdm.h"
3939
#include "features/3d_gldzm.h"
40+
#include "features/3d_glrlm.h"
4041
#include "features/3d_glszm.h"
4142
#include "features/roi_radius.h"
4243
#include "helpers/helpers.h"
@@ -131,8 +132,8 @@ bool Environment::spellcheck_raw_featurelist(const std::string& comma_separated_
131132

132133
if (dim() == 3)
133134
{
134-
// Is feature found among 2D features?
135-
Fgroup3D afg;
135+
// Is feature found among 3D features?
136+
int afg; // signed Fgroup3D
136137
bool gnameExists = theFeatureSet.find_3D_GroupByString (s_uppr, afg);
137138

138139
// 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_
150151
continue;
151152
}
152153

153-
Feature3D af;
154+
int af; // signed Feature3D
154155
bool fnameExists = theFeatureSet.find_3D_FeatureByString (s_uppr, af);
155156

156157
// 3D feature group requested on a non-3D mode ?
@@ -353,11 +354,19 @@ bool Environment::expand_2D_featuregroup (const std::string & s)
353354
//
354355
bool Environment::expand_3D_featuregroup (const std::string& s)
355356
{
356-
// mutually exclusive groups:
357-
if (s == Nyxus::theFeatureSet.findGroupNameByCode(Fgroup3D::FG3_ALL))
357+
int fgcode;
358+
if (!Nyxus::theFeatureSet.find_3D_GroupByString(s, fgcode))
359+
return false; // 's' is a feature name
360+
bool enable = true;
361+
if (fgcode < 0)
358362
{
359-
theFeatureSet.enableAll(false);
363+
fgcode = -fgcode;
364+
enable = false;
365+
}
360366

367+
// mutually exclusive groups:
368+
if ((Fgroup3D)fgcode == Fgroup3D::FG3_ALL)
369+
{
361370
auto F =
362371
{
363372
Feature3D::COV,
@@ -439,172 +448,61 @@ bool Environment::expand_3D_featuregroup (const std::string& s)
439448
#endif
440449
};
441450

442-
theFeatureSet.enableFeatures (F);
443-
theFeatureSet.enableFeatures (D3_GLCM_feature::featureset);
444-
theFeatureSet.enableFeatures (D3_GLDZM_feature::featureset);
445-
theFeatureSet.enableFeatures (D3_GLSZM_feature::featureset);
451+
theFeatureSet.enableFeatures (F, enable);
452+
theFeatureSet.enableFeatures (D3_GLCM_feature::featureset, enable);
453+
theFeatureSet.enableFeatures (D3_GLDM_feature::featureset, enable);
454+
theFeatureSet.enableFeatures (D3_GLDZM_feature::featureset, enable);
455+
theFeatureSet.enableFeatures (D3_GLRLM_feature::featureset, enable);
456+
theFeatureSet.enableFeatures (D3_GLSZM_feature::featureset, enable);
457+
theFeatureSet.enableFeatures (D3_NGLDM_feature::featureset, enable);
458+
theFeatureSet.enableFeatures (D3_NGTDM_feature::featureset, enable);
446459

447460
return true;
448461
}
449462

450-
if (s == Nyxus::theFeatureSet.findGroupNameByCode(Fgroup3D::FG3_GLCM))
463+
if ((Fgroup3D)fgcode == Fgroup3D::FG3_GLCM)
451464
{
452-
theFeatureSet.enableAll (false);
453-
theFeatureSet.enableFeatures (D3_GLCM_feature::featureset);
465+
theFeatureSet.enableFeatures (D3_GLCM_feature::featureset, enable);
454466
return true;
455467
}
456468

457-
if (s == Nyxus::theFeatureSet.findGroupNameByCode (Fgroup3D::FG3_GLDM))
469+
if ((Fgroup3D)fgcode == Fgroup3D::FG3_GLDM)
458470
{
459-
theFeatureSet.enableAll (false);
460-
theFeatureSet.enableFeatures (D3_GLDM_feature::featureset);
471+
theFeatureSet.enableFeatures (D3_GLDM_feature::featureset, enable);
461472
return true;
462473
}
463474

464-
if (s == Nyxus::theFeatureSet.findGroupNameByCode (Fgroup3D::FG3_NGLDM))
475+
if ((Fgroup3D)fgcode == Fgroup3D::FG3_NGLDM)
465476
{
466-
theFeatureSet.enableAll (false);
467-
theFeatureSet.enableFeatures (D3_NGLDM_feature::featureset);
477+
theFeatureSet.enableFeatures (D3_NGLDM_feature::featureset, enable);
468478
return true;
469479
}
470480

471-
if (s == Nyxus::theFeatureSet.findGroupNameByCode (Fgroup3D::FG3_NGTDM))
481+
if ((Fgroup3D)fgcode == Fgroup3D::FG3_NGTDM)
472482
{
473-
theFeatureSet.enableAll (false);
474-
theFeatureSet.enableFeatures (D3_NGTDM_feature::featureset);
483+
theFeatureSet.enableFeatures (D3_NGTDM_feature::featureset, enable);
475484
return true;
476485
}
477486

478-
if (s == Nyxus::theFeatureSet.findGroupNameByCode(Fgroup3D::FG3_GLCM))
487+
if ((Fgroup3D)fgcode == Fgroup3D::FG3_GLDZM)
479488
{
480-
theFeatureSet.enableAll (false);
481-
482-
auto F =
483-
{
484-
Nyxus::Feature3D::GLCM_ACOR,
485-
Nyxus::Feature3D::GLCM_ASM,
486-
Nyxus::Feature3D::GLCM_CLUPROM,
487-
Nyxus::Feature3D::GLCM_CLUSHADE,
488-
Nyxus::Feature3D::GLCM_CLUTEND,
489-
Nyxus::Feature3D::GLCM_CONTRAST,
490-
Nyxus::Feature3D::GLCM_CORRELATION,
491-
Nyxus::Feature3D::GLCM_DIFAVE,
492-
Nyxus::Feature3D::GLCM_DIFENTRO,
493-
Nyxus::Feature3D::GLCM_DIFVAR,
494-
Nyxus::Feature3D::GLCM_DIS,
495-
Nyxus::Feature3D::GLCM_ENERGY,
496-
Nyxus::Feature3D::GLCM_ENTROPY,
497-
Nyxus::Feature3D::GLCM_HOM1,
498-
Nyxus::Feature3D::GLCM_HOM2,
499-
Nyxus::Feature3D::GLCM_ID,
500-
Nyxus::Feature3D::GLCM_IDN,
501-
Nyxus::Feature3D::GLCM_IDM,
502-
Nyxus::Feature3D::GLCM_IDMN,
503-
Nyxus::Feature3D::GLCM_INFOMEAS1,
504-
Nyxus::Feature3D::GLCM_INFOMEAS2,
505-
Nyxus::Feature3D::GLCM_IV,
506-
Nyxus::Feature3D::GLCM_JAVE,
507-
Nyxus::Feature3D::GLCM_JE,
508-
Nyxus::Feature3D::GLCM_JMAX,
509-
Nyxus::Feature3D::GLCM_JVAR,
510-
Nyxus::Feature3D::GLCM_SUMAVERAGE,
511-
Nyxus::Feature3D::GLCM_SUMENTROPY,
512-
Nyxus::Feature3D::GLCM_SUMVARIANCE,
513-
Nyxus::Feature3D::GLCM_VARIANCE,
514-
Nyxus::Feature3D::GLCM_ASM_AVE,
515-
Nyxus::Feature3D::GLCM_ACOR_AVE,
516-
Nyxus::Feature3D::GLCM_CLUPROM_AVE,
517-
Nyxus::Feature3D::GLCM_CLUSHADE_AVE,
518-
Nyxus::Feature3D::GLCM_CLUTEND_AVE,
519-
Nyxus::Feature3D::GLCM_CONTRAST_AVE,
520-
Nyxus::Feature3D::GLCM_CORRELATION_AVE,
521-
Nyxus::Feature3D::GLCM_DIFAVE_AVE,
522-
Nyxus::Feature3D::GLCM_DIFENTRO_AVE,
523-
Nyxus::Feature3D::GLCM_DIFVAR_AVE,
524-
Nyxus::Feature3D::GLCM_DIS_AVE,
525-
Nyxus::Feature3D::GLCM_ENERGY_AVE,
526-
Nyxus::Feature3D::GLCM_ENTROPY_AVE,
527-
Nyxus::Feature3D::GLCM_HOM1_AVE,
528-
Nyxus::Feature3D::GLCM_ID_AVE,
529-
Nyxus::Feature3D::GLCM_IDN_AVE,
530-
Nyxus::Feature3D::GLCM_IDM_AVE,
531-
Nyxus::Feature3D::GLCM_IDMN_AVE,
532-
Nyxus::Feature3D::GLCM_IV_AVE,
533-
Nyxus::Feature3D::GLCM_JAVE_AVE,
534-
Nyxus::Feature3D::GLCM_JE_AVE,
535-
Nyxus::Feature3D::GLCM_INFOMEAS1_AVE,
536-
Nyxus::Feature3D::GLCM_INFOMEAS2_AVE,
537-
Nyxus::Feature3D::GLCM_VARIANCE_AVE,
538-
Nyxus::Feature3D::GLCM_JMAX_AVE,
539-
Nyxus::Feature3D::GLCM_JVAR_AVE,
540-
Nyxus::Feature3D::GLCM_SUMAVERAGE_AVE,
541-
Nyxus::Feature3D::GLCM_SUMENTROPY_AVE,
542-
Nyxus::Feature3D::GLCM_SUMVARIANCE_AVE
543-
};
544-
545-
theFeatureSet.enableFeatures(F);
489+
theFeatureSet.enableFeatures (D3_GLDZM_feature::featureset, enable);
546490
return true;
547491
}
548492

549-
if (s == Nyxus::theFeatureSet.findGroupNameByCode(Fgroup3D::FG3_GLDZM))
493+
if ((Fgroup3D)fgcode == Fgroup3D::FG3_GLSZM)
550494
{
551-
theFeatureSet.enableAll (false);
552-
theFeatureSet.enableFeatures (D3_GLDZM_feature::featureset);
553-
return true;
554-
}
555-
556-
if (s == Nyxus::theFeatureSet.findGroupNameByCode(Fgroup3D::FG3_GLSZM))
557-
{
558-
theFeatureSet.enableAll (false);
559-
theFeatureSet.enableFeatures (D3_GLSZM_feature::featureset);
495+
theFeatureSet.enableFeatures (D3_GLSZM_feature::featureset, enable);
560496
return true;
561497
}
562498

563-
if (s == Nyxus::theFeatureSet.findGroupNameByCode(Fgroup3D::FG3_GLRLM))
499+
if ((Fgroup3D)fgcode == Fgroup3D::FG3_GLRLM)
564500
{
565-
theFeatureSet.enableAll(false);
566-
567-
auto F =
568-
{
569-
Nyxus::Feature3D::GLRLM_SRE,
570-
Nyxus::Feature3D::GLRLM_LRE,
571-
Nyxus::Feature3D::GLRLM_GLN,
572-
Nyxus::Feature3D::GLRLM_GLNN,
573-
Nyxus::Feature3D::GLRLM_RLN,
574-
Nyxus::Feature3D::GLRLM_RLNN,
575-
Nyxus::Feature3D::GLRLM_RP,
576-
Nyxus::Feature3D::GLRLM_GLV,
577-
Nyxus::Feature3D::GLRLM_RV,
578-
Nyxus::Feature3D::GLRLM_RE,
579-
Nyxus::Feature3D::GLRLM_LGLRE,
580-
Nyxus::Feature3D::GLRLM_HGLRE,
581-
Nyxus::Feature3D::GLRLM_SRLGLE,
582-
Nyxus::Feature3D::GLRLM_SRHGLE,
583-
Nyxus::Feature3D::GLRLM_LRLGLE,
584-
Nyxus::Feature3D::GLRLM_LRHGLE,
585-
586-
Nyxus::Feature3D::GLRLM_SRE_AVE,
587-
Nyxus::Feature3D::GLRLM_LRE_AVE,
588-
Nyxus::Feature3D::GLRLM_GLN_AVE,
589-
Nyxus::Feature3D::GLRLM_GLNN_AVE,
590-
Nyxus::Feature3D::GLRLM_RLN_AVE,
591-
Nyxus::Feature3D::GLRLM_RLNN_AVE,
592-
Nyxus::Feature3D::GLRLM_RP_AVE,
593-
Nyxus::Feature3D::GLRLM_GLV_AVE,
594-
Nyxus::Feature3D::GLRLM_RV_AVE,
595-
Nyxus::Feature3D::GLRLM_RE_AVE,
596-
Nyxus::Feature3D::GLRLM_LGLRE_AVE,
597-
Nyxus::Feature3D::GLRLM_HGLRE_AVE,
598-
Nyxus::Feature3D::GLRLM_SRLGLE_AVE,
599-
Nyxus::Feature3D::GLRLM_SRHGLE_AVE,
600-
Nyxus::Feature3D::GLRLM_LRLGLE_AVE,
601-
Nyxus::Feature3D::GLRLM_LRHGLE_AVE
602-
};
603-
604-
theFeatureSet.enableFeatures(F);
501+
theFeatureSet.enableFeatures (D3_GLRLM_feature::featureset, enable);
605502
return true;
606503
}
607504

505+
// unrecognized feature group
608506
return false;
609507
}
610508

@@ -643,6 +541,8 @@ void Environment::expand_featuregroups()
643541
continue;
644542
}
645543

544+
// try to interpret 's' as a group name
545+
646546
if (dim() == 2)
647547
{
648548
if (expand_2D_featuregroup (s))
@@ -656,24 +556,25 @@ void Environment::expand_featuregroups()
656556
}
657557

658558
// 's' is an individual feature name, not feature group name. Process it now
559+
659560
if (dim() == 2)
660561
{
661562
int fcode; // signed Feature2D
662-
if (!theFeatureSet.find_2D_FeatureByString (s, fcode))
563+
if (!Nyxus::theFeatureSet.find_2D_FeatureByString (s, fcode))
663564
throw std::invalid_argument("Error: '" + s + "' is not a valid 2D feature name \n");
664565

665-
theFeatureSet.enableFeature (fcode);
566+
Nyxus::theFeatureSet.enableFeature (fcode);
666567

667568
continue;
668569
}
669570

670571
if (dim() == 3)
671572
{
672-
Feature3D a;
673-
if (!theFeatureSet.find_3D_FeatureByString(s, a))
573+
int a; // signed Feature3D
574+
if (!Nyxus::theFeatureSet.find_3D_FeatureByString(s, a))
674575
throw std::invalid_argument("Error: '" + s + "' is not a valid 3D feature name \n");
675576

676-
theFeatureSet.enableFeature (int(a));
577+
Nyxus::theFeatureSet.enableFeature (int(a));
677578
continue;
678579
}
679580
}

src/nyx/featureset.cpp

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,6 @@ bool FeatureSet::find_2D_GroupByString (
945945
enable = name[0] == '+' ? 1 : -1;
946946
}
947947

948-
949948
// search
950949
auto itr = Nyxus::UserFacing2dFeaturegroupNames.find (s);
951950

@@ -957,39 +956,56 @@ bool FeatureSet::find_2D_GroupByString (
957956
return true;
958957
}
959958

960-
bool FeatureSet::find_3D_FeatureByString (const std::string & name, Feature3D & f)
959+
bool FeatureSet::find_3D_FeatureByString (const std::string & name, int & f)
961960
{
961+
int enable = 1;
962+
962963
// strip possible set operation '+' or '-'
963964
std::string s = name;
964965

965-
if (name[0] == '-' || name[0] == '+')
966-
s = name.substr(1);
966+
// digest optional unary operator (sign)
967+
if (std::ispunct(name[0]))
968+
if (name[0] == '-' || name[0] == '+')
969+
{
970+
s = name.substr(1);
971+
enable = name[0] == '+' ? 1 : -1;
972+
}
973+
else
974+
return false; // invalid unary operator
967975

968976
// search
969-
auto it_f = Nyxus::UserFacing_3D_featureNames.find (s);
977+
auto it_f = Nyxus::UserFacing_3D_featureNames.find(s);
970978

971979
if (it_f == Nyxus::UserFacing_3D_featureNames.end())
972980
return false;
973981

974-
f = it_f->second;
982+
f = enable * (int)it_f->second;
983+
975984
return true;
976985
}
977986

978-
bool FeatureSet::find_3D_GroupByString (const std::string & name, Fgroup3D & grpCode)
987+
bool FeatureSet::find_3D_GroupByString (const std::string & name, int & grpCode)
979988
{
989+
int enable = 1;
990+
980991
// strip possible set operation '+' or '-'
981992
std::string s = name;
982993

994+
// digest optional unary operator (sign)
983995
if (name[0] == '-' || name[0] == '+')
996+
{
984997
s = name.substr(1);
998+
enable = name[0] == '+' ? 1 : -1;
999+
}
9851000

9861001
// search
9871002
auto itr = Nyxus::UserFacing3dFeaturegroupNames.find (s);
9881003

9891004
if (itr == Nyxus::UserFacing3dFeaturegroupNames.end())
9901005
return false;
9911006

992-
grpCode = itr->second;
1007+
grpCode = enable * (int)itr->second;
1008+
9931009
return true;
9941010
}
9951011

src/nyx/featureset.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ namespace Nyxus
854854
enum class Fgroup2D
855855
{
856856
FG2_ALL = 0,
857-
FG2_WHOLESLIDE,
857+
FG2_WHOLESLIDE, // FG2_WHOLESLIDE is FG2_ALL for whole slides
858858
FG2_INTENSITY,
859859
FG2_MORPHOLOGY,
860860
FG2_BASIC_MORPHOLOGY,
@@ -925,10 +925,10 @@ class FeatureSet
925925
for (auto f : F)
926926
m_enabledFeatures[(int)f] = enable;
927927
}
928-
void enableFeatures(const std::initializer_list<Nyxus::Feature3D>& desiredFeatures)
928+
void enableFeatures(const std::initializer_list<Nyxus::Feature3D>& F, bool enable = true)
929929
{
930-
for (auto f : desiredFeatures)
931-
m_enabledFeatures[(int)f] = true;
930+
for (auto f : F)
931+
m_enabledFeatures[(int)f] = enable;
932932
}
933933
void enableFeatures(const std::initializer_list<Nyxus::FeatureIMQ>& desiredFeatures) {
934934
for (auto f : desiredFeatures)
@@ -1039,10 +1039,10 @@ class FeatureSet
10391039
cnt++;
10401040
return cnt;
10411041
}
1042-
bool find_2D_FeatureByString (const std::string& name, int& f); // 'f' is signed Feature2D
1042+
bool find_2D_FeatureByString (const std::string & name, int & f); // 'f' is signed Feature2D
10431043
bool find_2D_GroupByString (const std::string& group_name, int & group_code); // 'group_code' is signed Nyxus::Fgroup2D
1044-
bool find_3D_FeatureByString (const std::string & feature_name, Nyxus::Feature3D & feature_code);
1045-
bool find_3D_GroupByString (const std::string & group_name, Nyxus::Fgroup3D & group_code);
1044+
bool find_3D_FeatureByString (const std::string & feature_name, int & feature_code);
1045+
bool find_3D_GroupByString (const std::string & group_name, int & group_code);
10461046
bool find_IMQ_FeatureByString (const std::string & feature_name, Nyxus::FeatureIMQ & feature_code);
10471047
bool find_IMQ_GroupByString (const std::string & group_name, Nyxus::FgroupIMQ & group_code);
10481048

0 commit comments

Comments
 (0)