diff --git a/src/nyx/abs_tile_loader.h b/src/nyx/abs_tile_loader.h index c4f509c60..d185fb86e 100644 --- a/src/nyx/abs_tile_loader.h +++ b/src/nyx/abs_tile_loader.h @@ -106,19 +106,19 @@ class AbstractTileLoader /// @param level Level asked [default 0] /// @return Number tiles in height for a level [[nodiscard]] size_t numberTileHeight(size_t level = 0) const { - return (size_t) std::ceil((double) (fullHeight(level)) / tileHeight(level)); + return static_cast(std::ceil(static_cast((fullHeight(level)) )/ tileHeight(level))); } /// @brief Number tiles in width accessor for a level /// @param level Level asked [default 0] /// @return Number tiles in width for a level [[nodiscard]] size_t numberTileWidth(size_t level = 0) const { - return (size_t) std::ceil((double) (fullWidth(level)) / tileWidth(level)); + return static_cast(std::ceil(static_cast((fullWidth(level)) )/ tileWidth(level))); } /// @brief Number tiles in depth accessor for a level /// @param level Level asked [default 0] /// @return Number tiles in depth for a level [[nodiscard]] size_t numberTileDepth(size_t level = 0) const { - return (size_t) std::ceil((double) (fullDepth(level)) / tileDepth(level)); + return static_cast(std::ceil(static_cast((fullDepth(level)) )/ tileDepth(level))); } }; \ No newline at end of file diff --git a/src/nyx/cache.cpp b/src/nyx/cache.cpp index 880687328..a87fe7de4 100644 --- a/src/nyx/cache.cpp +++ b/src/nyx/cache.cpp @@ -193,17 +193,17 @@ using_moments = true; // moments / real intensities - OKDETL(allocate_on_device((void**)realintens, sizeof(RealPixIntens) * batch_roi_cloud_len), "allocate_on_device(moments1)"); + OKDETL(allocate_on_device(reinterpret_cast(realintens), sizeof(RealPixIntens) * batch_roi_cloud_len), "allocate_on_device(moments1)"); // moments / pre-reduce - OKDETL(allocate_on_device((void**)prereduce, sizeof(double) * batch_roi_cloud_len * 16), "allocate_on_device(moments2)"); // 16 is the max number of simultaneous totals calculated by a kernel, e.g. RM00-33 + OKDETL(allocate_on_device(reinterpret_cast(prereduce), sizeof(double) * batch_roi_cloud_len * 16), "allocate_on_device(moments2)"); // 16 is the max number of simultaneous totals calculated by a kernel, e.g. RM00-33 // moments / intermediate OKDETL(intermediate.alloc(GpusideState::__COUNT__, batch_len), "allocate_on_device(moments3)"); // moments / CUB DeviceReduce's temp buffer OKDETL(devicereduce_evaluate_buffer_szb(devicereduce_buf_szb, batch_roi_cloud_len), "allocate_on_device(moments4)"); - OKDETL(allocate_on_device((void**)devicereduce_buf, devicereduce_buf_szb), "allocate_on_device(moments5)"); + OKDETL(allocate_on_device(reinterpret_cast(devicereduce_buf), devicereduce_buf_szb), "allocate_on_device(moments5)"); } // erosion / image matrices 1 and 2 @@ -214,9 +214,9 @@ // imat1 is shared by erosion and Gabor if (!*imat1) - OKDETL(allocate_on_device((void**)imat1, sizeof(imat1[0]) * roi_w * roi_h), "allocate_on_device(eros1)"); + OKDETL(allocate_on_device(reinterpret_cast(imat1), sizeof(imat1[0]) * roi_w * roi_h), "allocate_on_device(eros1)"); - OKDETL(allocate_on_device((void**)imat2, sizeof(imat2[0]) * roi_w * roi_h), "allocate_on_device(eros2)"); + OKDETL(allocate_on_device(reinterpret_cast(imat2), sizeof(imat2[0]) * roi_w * roi_h), "allocate_on_device(eros2)"); } // Gabor @@ -227,7 +227,7 @@ // imat1 is shared by erosion and Gabor if (!*imat1) - OKDETL(allocate_on_device((void**)imat1, sizeof(imat1[0]) * roi_w * roi_h), "allocate_on_device(gabor)"); + OKDETL(allocate_on_device(reinterpret_cast(imat1), sizeof(imat1[0]) * roi_w * roi_h), "allocate_on_device(gabor)"); size_t gabTotlen = (roi_w + gabor_ker_side - 1) * (roi_h + gabor_ker_side - 1) * n_gabFilters; OKDETL(gabor_linear_image.alloc(gabTotlen, 1), "gabor_linear_image.alloc()"); diff --git a/src/nyx/common_stats.cpp b/src/nyx/common_stats.cpp index 4ccda6296..7c407cba6 100644 --- a/src/nyx/common_stats.cpp +++ b/src/nyx/common_stats.cpp @@ -31,14 +31,14 @@ Statistics ComputeCommonStatistics2 (std::vector & Data) output.stdev = sqrt(sumSqrd / Data.size()); //Make a Histogram - int intMax = (int)ceil(output.max); - int intMin = (int)floor(output.min); + int intMax = static_cast(ceil(output.max)); + int intMin = static_cast(floor(output.min)); int binCounts = intMax - intMin + 1; std::vector histBins(binCounts, 0); //--Avoid pointers-- int* histBins = new int[binCounts]; for (int i = 0; i < binCounts; ++i) histBins[i] = 0; - for (int i = 0; i < Data.size(); i++) ++histBins[(int)Data[i] - intMin]; + for (int i = 0; i < Data.size(); i++) ++histBins[static_cast(Data[i] )- intMin]; double MaxValue = 0; int maxBinIndex = -1; diff --git a/src/nyx/env_features.cpp b/src/nyx/env_features.cpp index cf05b8cea..27b9c9ee1 100644 --- a/src/nyx/env_features.cpp +++ b/src/nyx/env_features.cpp @@ -208,15 +208,15 @@ bool Environment::expand_2D_featuregroup (const std::string & s) enable = false; } - if ((Fgroup2D)fgcode == Fgroup2D::FG2_ALL) + if (static_cast(fgcode )== Fgroup2D::FG2_ALL) { // enable just the 2D part of the feature set - for (int i = (int) Nyxus::Feature2D::_FIRST_; i < (int) Nyxus::Feature2D::_COUNT_; i++) + for (int i = static_cast(Nyxus::Feature2D::_FIRST_); i < static_cast(Nyxus::Feature2D::_COUNT_); i++) theFeatureSet.enableFeature (i); return true; } - if ((Fgroup2D)fgcode == Fgroup2D::FG2_WHOLESLIDE) + if (static_cast(fgcode )== Fgroup2D::FG2_WHOLESLIDE) { theFeatureSet.enableFeatures (ContourFeature::featureset, enable); theFeatureSet.enableFeatures (PixelIntensityFeatures::featureset, enable); @@ -233,25 +233,25 @@ bool Environment::expand_2D_featuregroup (const std::string & s) return true; } - if ((Fgroup2D) fgcode == Fgroup2D::FG2_NEIG) + if (static_cast(fgcode )== Fgroup2D::FG2_NEIG) { theFeatureSet.enableFeatures (NeighborsFeature::featureset, enable); return true; } - if ((Fgroup2D) fgcode == Fgroup2D::FG2_INTENSITY) + if (static_cast(fgcode )== Fgroup2D::FG2_INTENSITY) { theFeatureSet.enableFeatures (PixelIntensityFeatures::featureset, enable); return true; } - if ((Fgroup2D) fgcode == Fgroup2D::FG2_IH) + if (static_cast(fgcode )== Fgroup2D::FG2_IH) { // IBSI intensity-histogram family. Requested here; if IBSI mode is off it // gets stripped at the end of expand_featuregroups() (available only in IBSI mode). theFeatureSet.enableFeatures (IntensityHistogramFeatures::featureset, enable); return true; } - if ((Fgroup2D) fgcode == Fgroup2D::FG2_MORPHOLOGY) + if (static_cast(fgcode )== Fgroup2D::FG2_MORPHOLOGY) { theFeatureSet.enableFeatures (BasicMorphologyFeatures::featureset, enable); theFeatureSet.enableFeatures (EnclosingInscribingCircumscribingCircleFeature::featureset, enable); @@ -272,61 +272,61 @@ bool Environment::expand_2D_featuregroup (const std::string & s) return true; } - if ((Fgroup2D)fgcode == Fgroup2D::FG2_BASIC_MORPHOLOGY) + if (static_cast(fgcode )== Fgroup2D::FG2_BASIC_MORPHOLOGY) { theFeatureSet.enableFeatures (BasicMorphologyFeatures::featureset, enable); return true; } - if ((Fgroup2D)fgcode == Fgroup2D::FG2_GLCM) + if (static_cast(fgcode )== Fgroup2D::FG2_GLCM) { theFeatureSet.enableFeatures (GLCMFeature::featureset, enable); return true; } - if ((Fgroup2D)fgcode == Fgroup2D::FG2_GLRLM) + if (static_cast(fgcode )== Fgroup2D::FG2_GLRLM) { theFeatureSet.enableFeatures (GLRLMFeature::featureset, enable); return true; } - if ((Fgroup2D)fgcode == Fgroup2D::FG2_GLDZM) + if (static_cast(fgcode )== Fgroup2D::FG2_GLDZM) { theFeatureSet.enableFeatures (GLDZMFeature::featureset, enable); return true; } - if ((Fgroup2D)fgcode == Fgroup2D::FG2_GLSZM) + if (static_cast(fgcode )== Fgroup2D::FG2_GLSZM) { theFeatureSet.enableFeatures (GLSZMFeature::featureset, enable); return true; } - if ((Fgroup2D)fgcode == Fgroup2D::FG2_GLDM) + if (static_cast(fgcode )== Fgroup2D::FG2_GLDM) { theFeatureSet.enableFeatures(GLDMFeature::featureset, enable); return true; } - if ((Fgroup2D)fgcode == Fgroup2D::FG2_NGLDM) + if (static_cast(fgcode )== Fgroup2D::FG2_NGLDM) { theFeatureSet.enableFeatures (NGLDMfeature::featureset, enable); return true; } - if ((Fgroup2D)fgcode == Fgroup2D::FG2_NGTDM) + if (static_cast(fgcode )== Fgroup2D::FG2_NGTDM) { theFeatureSet.enableFeatures (NGTDMFeature::featureset, enable); return true; } - if ((Fgroup2D)fgcode == Fgroup2D::FG2_GEOMOMENTS) + if (static_cast(fgcode )== Fgroup2D::FG2_GEOMOMENTS) { theFeatureSet.enableFeatures (Smoms2D_feature::featureset, enable); theFeatureSet.enableFeatures (Imoms2D_feature::featureset, enable); return true; } - if ((Fgroup2D)fgcode == Fgroup2D::FG2_GEOMOMENTS_I) + if (static_cast(fgcode )== Fgroup2D::FG2_GEOMOMENTS_I) { theFeatureSet.enableFeatures (Imoms2D_feature::featureset, enable); return true; } - if ((Fgroup2D)fgcode == Fgroup2D::FG2_GEOMOMENTS_S) + if (static_cast(fgcode )== Fgroup2D::FG2_GEOMOMENTS_S) { theFeatureSet.enableFeatures (Smoms2D_feature::featureset, enable); return true; @@ -353,7 +353,7 @@ bool Environment::expand_3D_featuregroup (const std::string& s) } // mutually exclusive groups: - if ((Fgroup3D)fgcode == Fgroup3D::FG3_ALL) + if (static_cast(fgcode )== Fgroup3D::FG3_ALL) { theFeatureSet.enableFeatures (D3_VoxelIntensityFeatures::featureset, enable); theFeatureSet.enableFeatures (D3_SurfaceFeature::featureset, enable); @@ -368,19 +368,19 @@ bool Environment::expand_3D_featuregroup (const std::string& s) return true; } - if ((Fgroup3D)fgcode == Fgroup3D::FG3_INTENSITY) + if (static_cast(fgcode )== Fgroup3D::FG3_INTENSITY) { theFeatureSet.enableFeatures (D3_VoxelIntensityFeatures::featureset, enable); return true; } - if ((Fgroup3D)fgcode == Fgroup3D::FG3_MORPHOLOGY) + if (static_cast(fgcode )== Fgroup3D::FG3_MORPHOLOGY) { theFeatureSet.enableFeatures (D3_SurfaceFeature::featureset, enable); return true; } - if ((Fgroup3D)fgcode == Fgroup3D::FG3_TEXTURE) + if (static_cast(fgcode )== Fgroup3D::FG3_TEXTURE) { theFeatureSet.enableFeatures (D3_GLCM_feature::featureset, enable); theFeatureSet.enableFeatures (D3_GLDM_feature::featureset, enable); @@ -392,43 +392,43 @@ bool Environment::expand_3D_featuregroup (const std::string& s) return true; } - if ((Fgroup3D)fgcode == Fgroup3D::FG3_GLCM) + if (static_cast(fgcode )== Fgroup3D::FG3_GLCM) { theFeatureSet.enableFeatures (D3_GLCM_feature::featureset, enable); return true; } - if ((Fgroup3D)fgcode == Fgroup3D::FG3_GLDM) + if (static_cast(fgcode )== Fgroup3D::FG3_GLDM) { theFeatureSet.enableFeatures (D3_GLDM_feature::featureset, enable); return true; } - if ((Fgroup3D)fgcode == Fgroup3D::FG3_NGLDM) + if (static_cast(fgcode )== Fgroup3D::FG3_NGLDM) { theFeatureSet.enableFeatures (D3_NGLDM_feature::featureset, enable); return true; } - if ((Fgroup3D)fgcode == Fgroup3D::FG3_NGTDM) + if (static_cast(fgcode )== Fgroup3D::FG3_NGTDM) { theFeatureSet.enableFeatures (D3_NGTDM_feature::featureset, enable); return true; } - if ((Fgroup3D)fgcode == Fgroup3D::FG3_GLDZM) + if (static_cast(fgcode )== Fgroup3D::FG3_GLDZM) { theFeatureSet.enableFeatures (D3_GLDZM_feature::featureset, enable); return true; } - if ((Fgroup3D)fgcode == Fgroup3D::FG3_GLSZM) + if (static_cast(fgcode )== Fgroup3D::FG3_GLSZM) { theFeatureSet.enableFeatures (D3_GLSZM_feature::featureset, enable); return true; } - if ((Fgroup3D)fgcode == Fgroup3D::FG3_GLRLM) + if (static_cast(fgcode )== Fgroup3D::FG3_GLRLM) { theFeatureSet.enableFeatures (D3_GLRLM_feature::featureset, enable); return true; @@ -713,26 +713,26 @@ void Environment::compile_feature_settings() { auto& s = wrapd_s.get(); s.clear(); - s.resize((int)NyxSetting::__COUNT__); - s[(int)NyxSetting::SOFTNAN].rval = resultOptions.noval(); - s[(int)NyxSetting::TINY].rval = resultOptions.tiny(); - s[(int)NyxSetting::SINGLEROI].bval = singleROI; - s[(int)NyxSetting::GREYDEPTH].ival = get_coarse_gray_depth(); - s[(int)NyxSetting::PIXELSIZEUM].rval = pixelSizeUm; - s[(int)NyxSetting::PIXELDISTANCE].ival = get_pixel_distance(); - s[(int)NyxSetting::USEGPU].bval = using_gpu(); - s[(int)NyxSetting::VERBOSLVL].ival = get_verbosity_level(); - s[(int)NyxSetting::IBSI].bval = ibsi_compliance; + s.resize(static_cast(NyxSetting::__COUNT__)); + s[static_cast(NyxSetting::SOFTNAN)].rval = resultOptions.noval(); + s[static_cast(NyxSetting::TINY)].rval = resultOptions.tiny(); + s[static_cast(NyxSetting::SINGLEROI)].bval = singleROI; + s[static_cast(NyxSetting::GREYDEPTH)].ival = get_coarse_gray_depth(); + s[static_cast(NyxSetting::PIXELSIZEUM)].rval = pixelSizeUm; + s[static_cast(NyxSetting::PIXELDISTANCE)].ival = get_pixel_distance(); + s[static_cast(NyxSetting::USEGPU)].bval = using_gpu(); + s[static_cast(NyxSetting::VERBOSLVL)].ival = get_verbosity_level(); + s[static_cast(NyxSetting::IBSI)].bval = ibsi_compliance; // GLCM-specific defaults (otherwise zero-initialised). GLCM_OFFSET=0 would make // dx=dy=0 -> every pixel co-occurs with itself -> degenerate diagonal matrix // (CONTRAST=0). Default the co-occurrence distance to 1 (IBSI delta=1). - s[(int)NyxSetting::GLCM_OFFSET].ival = 1; - s[(int)NyxSetting::GLCM_GREYDEPTH].ival = get_coarse_gray_depth(); - s[(int)NyxSetting::GLCM_NUMANG].ival = (int)GLCMFeature::angles.size(); - s[(int)NyxSetting::FPIMG_TARGET_DR].rval = fpimageOptions.target_dyn_range(); - s[(int)NyxSetting::FPIMG_MIN].rval = fpimageOptions.min_intensity(); - s[(int)NyxSetting::FPIMG_MAX].rval = fpimageOptions.max_intensity(); - s[(int)NyxSetting::FPIMG_ACTIVE].bval = ! fpimageOptions.empty(); + s[static_cast(NyxSetting::GLCM_OFFSET)].ival = 1; + s[static_cast(NyxSetting::GLCM_GREYDEPTH)].ival = get_coarse_gray_depth(); + s[static_cast(NyxSetting::GLCM_NUMANG)].ival = static_cast(GLCMFeature::angles.size()); + s[static_cast(NyxSetting::FPIMG_TARGET_DR)].rval = fpimageOptions.target_dyn_range(); + s[static_cast(NyxSetting::FPIMG_MIN)].rval = fpimageOptions.min_intensity(); + s[static_cast(NyxSetting::FPIMG_MAX)].rval = fpimageOptions.max_intensity(); + s[static_cast(NyxSetting::FPIMG_ACTIVE)].bval = ! fpimageOptions.empty(); } } @@ -742,7 +742,7 @@ void Environment::refresh_feature_settings_singleroi() { auto& s = wrapd_s.get(); if (!s.empty()) - s[(int)NyxSetting::SINGLEROI].bval = singleROI; + s[static_cast(NyxSetting::SINGLEROI)].bval = singleROI; } } diff --git a/src/nyx/env_metaparams.cpp b/src/nyx/env_metaparams.cpp index 081d196e6..8d42844a3 100644 --- a/src/nyx/env_metaparams.cpp +++ b/src/nyx/env_metaparams.cpp @@ -264,13 +264,13 @@ std::optional Environment::get_metaparam (double & p_val, const std { // interpret eq_sides[1] as int int ival = STNGS_GLCM_GREYDEPTH(fsett_GLCM); - p_val = (double)ival; + p_val = static_cast(ival); } else if (ppath[1] == "offset") { // interpret eq_sides[1] as int int ival = STNGS_GLCM_OFFSET(fsett_GLCM); - p_val = (double)ival; + p_val = static_cast(ival); } else { @@ -285,25 +285,25 @@ std::optional Environment::get_metaparam (double & p_val, const std { // interpret eq_sides[1] as int int ival = STNGS_GLCM_GREYDEPTH(fsett_GLCM); - p_val = (double) ival; + p_val = static_cast(ival); } else if (ppath[1] == "offset") { // interpret eq_sides[1] as int int ival = STNGS_GLCM_OFFSET(fsett_GLCM); - p_val = (double)ival; + p_val = static_cast(ival); } else if (ppath[1] == "numang") { // interpret eq_sides[1] as int int ival = STNGS_GLCM_NUMANG(fsett_GLCM); - p_val = (double)ival; + p_val = static_cast(ival); } else if (ppath[1] == "sparseintensities") { // interpret eq_sides[1] as boolean bool bval = STNGS_GLCM_SPARSEINTENS(fsett_GLCM); - p_val = (double)bval; + p_val = static_cast(bval); } else { @@ -317,7 +317,7 @@ std::optional Environment::get_metaparam (double & p_val, const std { // interpret eq_sides[1] as int int ival = STNGS_GLDM_GREYDEPTH (fsett_D3_GLDM); - p_val = (double)ival; + p_val = static_cast(ival); } else { @@ -331,14 +331,14 @@ std::optional Environment::get_metaparam (double & p_val, const std { // interpret eq_sides[1] as int int ival = STNGS_NGTDM_GREYDEPTH (fsett_D3_NGTDM); - p_val = (double)ival; + p_val = static_cast(ival); } else if (ppath[1] == "radius") { // interpret eq_sides[1] as int int ival = STNGS_NGTDM_RADIUS (fsett_D3_NGTDM); - p_val = (double)ival; + p_val = static_cast(ival); } else { @@ -352,7 +352,7 @@ std::optional Environment::get_metaparam (double & p_val, const std { // interpret eq_sides[1] as int int ival = STNGS_GLRLM_GREYDEPTH (fsett_D3_GLRLM); - p_val = (double)ival; + p_val = static_cast(ival); } else { @@ -366,7 +366,7 @@ std::optional Environment::get_metaparam (double & p_val, const std { // interpret eq_sides[1] as int int ival = STNGS_GLSZM_GREYDEPTH (fsett_D3_GLSZM); - p_val = (double)ival; + p_val = static_cast(ival); } else { diff --git a/src/nyx/feature_method.cpp b/src/nyx/feature_method.cpp index c5740309f..ced39c74e 100644 --- a/src/nyx/feature_method.cpp +++ b/src/nyx/feature_method.cpp @@ -10,37 +10,37 @@ FeatureMethod::~FeatureMethod(){} void FeatureMethod::provide_features (const std::initializer_list & F) { for (auto f : F) - provided_features.push_back((int)f); + provided_features.push_back(static_cast(f)); } void FeatureMethod::provide_features (const std::initializer_list & F) { for (auto f : F) - provided_features.push_back((int)f); + provided_features.push_back(static_cast(f)); } void FeatureMethod::provide_features (const std::initializer_list & F) { for (auto f : F) - provided_features.push_back((int)f); + provided_features.push_back(static_cast(f)); } void FeatureMethod::add_dependencies (const std::initializer_list& F) { for (auto f : F) - dependencies.push_back((int)f); + dependencies.push_back(static_cast(f)); } void FeatureMethod::add_dependencies (const std::initializer_list& F) { for (auto f : F) - dependencies.push_back((int)f); + dependencies.push_back(static_cast(f)); } void FeatureMethod::add_dependencies(const std::initializer_list& F) { for (auto f : F) - dependencies.push_back((int)f); + dependencies.push_back(static_cast(f)); } void FeatureMethod::osized_scan_whole_image (LR& r, const Fsettings& s, ImageLoader& ldr) @@ -51,20 +51,20 @@ void FeatureMethod::osized_scan_whole_image (LR& r, const Fsettings& s, ImageLoa bool FeatureMethod::provides (int fcode) const { - return std::find(provided_features.begin(), provided_features.end(), (int)fcode) != provided_features.end(); + return std::find(provided_features.begin(), provided_features.end(), static_cast(fcode)) != provided_features.end(); } bool FeatureMethod::depends (Nyxus::Feature2D fcode) { - return std::find (dependencies.begin(), dependencies.end(), (int)fcode) != dependencies.end(); + return std::find (dependencies.begin(), dependencies.end(), static_cast(fcode)) != dependencies.end(); } bool FeatureMethod::depends (Nyxus::FeatureIMQ fcode) { - return std::find (dependencies.begin(), dependencies.end(), (int)fcode) != dependencies.end(); + return std::find (dependencies.begin(), dependencies.end(), static_cast(fcode)) != dependencies.end(); } bool FeatureMethod::depends (Nyxus::Feature3D fcode) { - return std::find(dependencies.begin(), dependencies.end(), (int)fcode) != dependencies.end(); + return std::find(dependencies.begin(), dependencies.end(), static_cast(fcode)) != dependencies.end(); } diff --git a/src/nyx/feature_mgr.cpp b/src/nyx/feature_mgr.cpp index a47e4cea2..57b49b843 100644 --- a/src/nyx/feature_mgr.cpp +++ b/src/nyx/feature_mgr.cpp @@ -39,7 +39,7 @@ bool FeatureManager::compile() // After compiling, returns the number of user-requested features int FeatureManager::get_num_requested_features() { - return (int) user_requested_features.size(); + return static_cast(user_requested_features.size()); } // Returns the pointer to a feature method instance @@ -60,7 +60,7 @@ bool FeatureManager::check_11_correspondence() bool success = true; // check the 2D featureset //xxxx what about 3D and IMQ? - for (int i_fcode = 0; i_fcode < (int) Nyxus::Feature2D::_COUNT_; i_fcode++) + for (int i_fcode = 0; i_fcode < static_cast(Nyxus::Feature2D::_COUNT_); i_fcode++) { int nProviders = 0; for (const auto fm : full_featureset) @@ -75,12 +75,12 @@ bool FeatureManager::check_11_correspondence() if (nProviders > 1) // error - ambiguous provider (as a class 'XYZ_feature') of a feature (as a code) { success = false; - std::cout << "Error: ambiguous provider of feature " << fset.findFeatureNameByCode((Feature2D)i_fcode) << " (code " << i_fcode << "). (Feature is provided by multiple feature methods.) \n"; + std::cout << "Error: ambiguous provider of feature " << fset.findFeatureNameByCode(static_cast(i_fcode)) << " (code " << i_fcode << "). (Feature is provided by multiple feature methods.) \n"; } else // error - no providers { success = false; - std::cout << "Error: feature " << fset.findFeatureNameByCode((Feature2D)i_fcode) << " (code " << i_fcode << ") is not provided by any feature method. Check constructor of class FeatureManager\n"; + std::cout << "Error: feature " << fset.findFeatureNameByCode(static_cast(i_fcode)) << " (code " << i_fcode << ") is not provided by any feature method. Check constructor of class FeatureManager\n"; } } @@ -116,7 +116,7 @@ bool FeatureManager::gather_dependencies () // Show the user method's extended dependencies for (auto fcode : extendedDependencies) { - std::string fn = fcode < (int)Feature2D::_COUNT_ ? fset.findFeatureNameByCode((Feature2D)fcode) : fset.findFeatureNameByCode((Feature3D)fcode); + std::string fn = fcode < static_cast(Feature2D::_COUNT_ )? fset.findFeatureNameByCode(static_cast(fcode)) : fset.findFeatureNameByCode(static_cast(fcode)); std::cout << "\t" << fn << "\n"; } #endif @@ -167,7 +167,7 @@ int FeatureManager::get_num_fmethods_dependencies (const FeatureMethod * fm, std // No provider? if (providerFM == nullptr) { - std::cout << "Error: no registered provider for feature " << (int)fcode << " referenced as dependency by feature method " << fm->feature_info << "\n"; + std::cout << "Error: no registered provider for feature " << static_cast(fcode )<< " referenced as dependency by feature method " << fm->feature_info << "\n"; } // Analyze the child @@ -212,10 +212,10 @@ void FeatureManager::build_user_requested_set (FeatureSet & fset) // first, save feature methods of fm's dependencies for (auto depend_fc : fm->dependencies) { - FeatureMethod* depend_fm = get_feature_method_by_code ((int)depend_fc); + FeatureMethod* depend_fm = get_feature_method_by_code (static_cast(depend_fc)); if (depend_fm == nullptr) - throw (std::runtime_error("Feature " + std::to_string((int)depend_fc) + " is not provided by any feature method. Check constructor of class FeatureManager")); + throw (std::runtime_error("Feature " + std::to_string(static_cast(depend_fc)) + " is not provided by any feature method. Check constructor of class FeatureManager")); // save this fm if it's not yet saved if (std::find(user_requested_features.begin(), user_requested_features.end(), depend_fm) == user_requested_features.end()) diff --git a/src/nyx/feature_settings.h b/src/nyx/feature_settings.h index f0cd6ba43..ad3995aa8 100644 --- a/src/nyx/feature_settings.h +++ b/src/nyx/feature_settings.h @@ -54,29 +54,29 @@ enum class NyxSetting : int }; // common settings -#define STNGS_MISSING(obj) (obj.size() < (int)NyxSetting::__COUNT__) -#define STNGS_NAN(obj) (obj[(int)NyxSetting::SOFTNAN].rval) -#define STNGS_TINY(obj) (obj[(int)NyxSetting::TINY].rval) -#define STNGS_NGREYS(obj) (obj[(int)NyxSetting::GREYDEPTH].ival) -#define STNGS_IBSI(obj) (obj[(int)NyxSetting::IBSI].bval) -#define STNGS_USEGPU(obj) (obj[(int)NyxSetting::USEGPU].bval) -#define STNGS_SINGLEROI(obj) (obj[(int)NyxSetting::SINGLEROI].bval) -#define STNGS_PIXELDISTANCE(obj) (obj[(int)NyxSetting::PIXELDISTANCE].ival) -#define STNGS_VERBOSLVL(obj) (obj[(int)NyxSetting::VERBOSLVL].ival) -#define STNGS_FPIMG_DR(obj) (obj[(int)NyxSetting::FPIMG_TARGET_DR].rval) -#define STNGS_FPIMG_MIN(obj) (obj[(int)NyxSetting::FPIMG_MIN].rval) -#define STNGS_FPIMG_MAX(obj) (obj[(int)NyxSetting::FPIMG_MAX].rval) -#define STNGS_FPIMG_ACTIVE(obj) (obj[(int)NyxSetting::FPIMG_ACTIVE].bval) +#define STNGS_MISSING(obj) (obj.size() < static_cast(NyxSetting::__COUNT__)) +#define STNGS_NAN(obj) (obj[static_cast(NyxSetting::SOFTNAN)].rval) +#define STNGS_TINY(obj) (obj[static_cast(NyxSetting::TINY)].rval) +#define STNGS_NGREYS(obj) (obj[static_cast(NyxSetting::GREYDEPTH)].ival) +#define STNGS_IBSI(obj) (obj[static_cast(NyxSetting::IBSI)].bval) +#define STNGS_USEGPU(obj) (obj[static_cast(NyxSetting::USEGPU)].bval) +#define STNGS_SINGLEROI(obj) (obj[static_cast(NyxSetting::SINGLEROI)].bval) +#define STNGS_PIXELDISTANCE(obj) (obj[static_cast(NyxSetting::PIXELDISTANCE)].ival) +#define STNGS_VERBOSLVL(obj) (obj[static_cast(NyxSetting::VERBOSLVL)].ival) +#define STNGS_FPIMG_DR(obj) (obj[static_cast(NyxSetting::FPIMG_TARGET_DR)].rval) +#define STNGS_FPIMG_MIN(obj) (obj[static_cast(NyxSetting::FPIMG_MIN)].rval) +#define STNGS_FPIMG_MAX(obj) (obj[static_cast(NyxSetting::FPIMG_MAX)].rval) +#define STNGS_FPIMG_ACTIVE(obj) (obj[static_cast(NyxSetting::FPIMG_ACTIVE)].bval) // feature-specific settings -#define STNGS_GLCM_GREYDEPTH(obj) (obj[(int)NyxSetting::GLCM_GREYDEPTH].ival) -#define STNGS_GLCM_OFFSET(obj) (obj[(int)NyxSetting::GLCM_OFFSET].ival) -#define STNGS_GLCM_NUMANG(obj) (obj[(int)NyxSetting::GLCM_NUMANG].ival) -#define STNGS_GLCM_SPARSEINTENS(obj) (obj[(int)NyxSetting::GLCM_SPARSEINTENS].ival) -#define STNGS_GLDM_GREYDEPTH(obj) (obj[(int)NyxSetting::GLDM_GREYDEPTH].ival) -#define STNGS_GLRLM_GREYDEPTH(obj) (obj[(int)NyxSetting::GLRLM_GREYDEPTH].ival) -#define STNGS_GLSZM_GREYDEPTH(obj) (obj[(int)NyxSetting::GLSZM_GREYDEPTH].ival) -#define STNGS_NGTDM_GREYDEPTH(obj) (obj[(int)NyxSetting::NGTDM_GREYDEPTH].ival) -#define STNGS_NGTDM_RADIUS(obj) (obj[(int)NyxSetting::NGTDM_RADIUS].ival) +#define STNGS_GLCM_GREYDEPTH(obj) (obj[static_cast(NyxSetting::GLCM_GREYDEPTH)].ival) +#define STNGS_GLCM_OFFSET(obj) (obj[static_cast(NyxSetting::GLCM_OFFSET)].ival) +#define STNGS_GLCM_NUMANG(obj) (obj[static_cast(NyxSetting::GLCM_NUMANG)].ival) +#define STNGS_GLCM_SPARSEINTENS(obj) (obj[static_cast(NyxSetting::GLCM_SPARSEINTENS)].ival) +#define STNGS_GLDM_GREYDEPTH(obj) (obj[static_cast(NyxSetting::GLDM_GREYDEPTH)].ival) +#define STNGS_GLRLM_GREYDEPTH(obj) (obj[static_cast(NyxSetting::GLRLM_GREYDEPTH)].ival) +#define STNGS_GLSZM_GREYDEPTH(obj) (obj[static_cast(NyxSetting::GLSZM_GREYDEPTH)].ival) +#define STNGS_NGTDM_GREYDEPTH(obj) (obj[static_cast(NyxSetting::NGTDM_GREYDEPTH)].ival) +#define STNGS_NGTDM_RADIUS(obj) (obj[static_cast(NyxSetting::NGTDM_RADIUS)].ival) diff --git a/src/nyx/features/2d_geomoments.cpp b/src/nyx/features/2d_geomoments.cpp index 8a0ae6f03..3b05408c3 100644 --- a/src/nyx/features/2d_geomoments.cpp +++ b/src/nyx/features/2d_geomoments.cpp @@ -55,104 +55,104 @@ void Imoms2D_feature::parallel_process_1_batch (size_t start, size_t end, std::v void Imoms2D_feature::save_value(std::vector>& fvals) { - fvals[(int)Nyxus::Feature2D::IMOM_RM_00][0] = m00; - fvals[(int)Nyxus::Feature2D::IMOM_RM_01][0] = m01; - fvals[(int)Nyxus::Feature2D::IMOM_RM_02][0] = m02; - fvals[(int)Nyxus::Feature2D::IMOM_RM_03][0] = m03; - fvals[(int)Nyxus::Feature2D::IMOM_RM_10][0] = m10; - fvals[(int)Nyxus::Feature2D::IMOM_RM_11][0] = m11; - fvals[(int)Nyxus::Feature2D::IMOM_RM_12][0] = m12; - fvals[(int)Nyxus::Feature2D::IMOM_RM_13][0] = m13; - fvals[(int)Nyxus::Feature2D::IMOM_RM_20][0] = m20; - fvals[(int)Nyxus::Feature2D::IMOM_RM_21][0] = m21; - fvals[(int)Nyxus::Feature2D::IMOM_RM_22][0] = m22; - fvals[(int)Nyxus::Feature2D::IMOM_RM_23][0] = m23; - fvals[(int)Nyxus::Feature2D::IMOM_RM_30][0] = m30; - - fvals[(int)Nyxus::Feature2D::IMOM_WRM_00][0] = wm00; - fvals[(int)Nyxus::Feature2D::IMOM_WRM_01][0] = wm01; - fvals[(int)Nyxus::Feature2D::IMOM_WRM_02][0] = wm02; - fvals[(int)Nyxus::Feature2D::IMOM_WRM_03][0] = wm03; - fvals[(int)Nyxus::Feature2D::IMOM_WRM_10][0] = wm10; - fvals[(int)Nyxus::Feature2D::IMOM_WRM_11][0] = wm11; - fvals[(int)Nyxus::Feature2D::IMOM_WRM_12][0] = wm12; - fvals[(int)Nyxus::Feature2D::IMOM_WRM_20][0] = wm20; - fvals[(int)Nyxus::Feature2D::IMOM_WRM_21][0] = wm21; - fvals[(int)Nyxus::Feature2D::IMOM_WRM_30][0] = wm30; - - fvals[(int)Nyxus::Feature2D::IMOM_CM_00][0] = mu00; - fvals[(int)Nyxus::Feature2D::IMOM_CM_01][0] = mu01; - fvals[(int)Nyxus::Feature2D::IMOM_CM_02][0] = mu02; - fvals[(int)Nyxus::Feature2D::IMOM_CM_03][0] = mu03; - fvals[(int)Nyxus::Feature2D::IMOM_CM_10][0] = mu10; - fvals[(int)Nyxus::Feature2D::IMOM_CM_11][0] = mu11; - fvals[(int)Nyxus::Feature2D::IMOM_CM_12][0] = mu12; - fvals[(int)Nyxus::Feature2D::IMOM_CM_13][0] = mu13; - fvals[(int)Nyxus::Feature2D::IMOM_CM_20][0] = mu20; - fvals[(int)Nyxus::Feature2D::IMOM_CM_21][0] = mu21; - fvals[(int)Nyxus::Feature2D::IMOM_CM_22][0] = mu22; - fvals[(int)Nyxus::Feature2D::IMOM_CM_23][0] = mu23; - fvals[(int)Nyxus::Feature2D::IMOM_CM_30][0] = mu30; - fvals[(int)Nyxus::Feature2D::IMOM_CM_31][0] = mu31; - fvals[(int)Nyxus::Feature2D::IMOM_CM_32][0] = mu32; - fvals[(int)Nyxus::Feature2D::IMOM_CM_33][0] = mu33; - - fvals[(int)Nyxus::Feature2D::IMOM_WCM_02][0] = wmu02; - fvals[(int)Nyxus::Feature2D::IMOM_WCM_03][0] = wmu03; - fvals[(int)Nyxus::Feature2D::IMOM_WCM_11][0] = wmu11; - fvals[(int)Nyxus::Feature2D::IMOM_WCM_12][0] = wmu12; - fvals[(int)Nyxus::Feature2D::IMOM_WCM_20][0] = wmu20; - fvals[(int)Nyxus::Feature2D::IMOM_WCM_21][0] = wmu21; - fvals[(int)Nyxus::Feature2D::IMOM_WCM_30][0] = wmu30; - - fvals[(int)Nyxus::Feature2D::IMOM_NCM_02][0] = nu02; - fvals[(int)Nyxus::Feature2D::IMOM_NCM_03][0] = nu03; - fvals[(int)Nyxus::Feature2D::IMOM_NCM_11][0] = nu11; - fvals[(int)Nyxus::Feature2D::IMOM_NCM_12][0] = nu12; - fvals[(int)Nyxus::Feature2D::IMOM_NCM_20][0] = nu20; - fvals[(int)Nyxus::Feature2D::IMOM_NCM_21][0] = nu21; - fvals[(int)Nyxus::Feature2D::IMOM_NCM_30][0] = nu30; - - fvals[(int)Nyxus::Feature2D::IMOM_NRM_00][0] = w00; - fvals[(int)Nyxus::Feature2D::IMOM_NRM_01][0] = w01; - fvals[(int)Nyxus::Feature2D::IMOM_NRM_02][0] = w02; - fvals[(int)Nyxus::Feature2D::IMOM_NRM_03][0] = w03; - fvals[(int)Nyxus::Feature2D::IMOM_NRM_10][0] = w10; - fvals[(int)Nyxus::Feature2D::IMOM_NRM_11][0] = w11; - fvals[(int)Nyxus::Feature2D::IMOM_NRM_12][0] = w12; - fvals[(int)Nyxus::Feature2D::IMOM_NRM_13][0] = w13; - fvals[(int)Nyxus::Feature2D::IMOM_NRM_20][0] = w20; - fvals[(int)Nyxus::Feature2D::IMOM_NRM_21][0] = w21; - fvals[(int)Nyxus::Feature2D::IMOM_NRM_22][0] = w22; - fvals[(int)Nyxus::Feature2D::IMOM_NRM_23][0] = w23; - fvals[(int)Nyxus::Feature2D::IMOM_NRM_30][0] = w30; - fvals[(int)Nyxus::Feature2D::IMOM_NRM_31][0] = w31; - fvals[(int)Nyxus::Feature2D::IMOM_NRM_32][0] = w32; - fvals[(int)Nyxus::Feature2D::IMOM_NRM_33][0] = w33; - - fvals[(int)Nyxus::Feature2D::IMOM_HU1][0] = hm1; - fvals[(int)Nyxus::Feature2D::IMOM_HU2][0] = hm2; - fvals[(int)Nyxus::Feature2D::IMOM_HU3][0] = hm3; - fvals[(int)Nyxus::Feature2D::IMOM_HU4][0] = hm4; - fvals[(int)Nyxus::Feature2D::IMOM_HU5][0] = hm5; - fvals[(int)Nyxus::Feature2D::IMOM_HU6][0] = hm6; - fvals[(int)Nyxus::Feature2D::IMOM_HU7][0] = hm7; - - fvals[(int)Nyxus::Feature2D::IMOM_WNCM_02][0] = wncm02; - fvals[(int)Nyxus::Feature2D::IMOM_WNCM_03][0] = wncm03; - fvals[(int)Nyxus::Feature2D::IMOM_WNCM_11][0] = wncm11; - fvals[(int)Nyxus::Feature2D::IMOM_WNCM_12][0] = wncm12; - fvals[(int)Nyxus::Feature2D::IMOM_WNCM_20][0] = wncm20; - fvals[(int)Nyxus::Feature2D::IMOM_WNCM_21][0] = wncm21; - fvals[(int)Nyxus::Feature2D::IMOM_WNCM_30][0] = wncm30; - - fvals[(int)Nyxus::Feature2D::IMOM_WHU1][0] = whm1; - fvals[(int)Nyxus::Feature2D::IMOM_WHU2][0] = whm2; - fvals[(int)Nyxus::Feature2D::IMOM_WHU3][0] = whm3; - fvals[(int)Nyxus::Feature2D::IMOM_WHU4][0] = whm4; - fvals[(int)Nyxus::Feature2D::IMOM_WHU5][0] = whm5; - fvals[(int)Nyxus::Feature2D::IMOM_WHU6][0] = whm6; - fvals[(int)Nyxus::Feature2D::IMOM_WHU7][0] = whm7; + fvals[static_cast(Nyxus::Feature2D::IMOM_RM_00)][0] = m00; + fvals[static_cast(Nyxus::Feature2D::IMOM_RM_01)][0] = m01; + fvals[static_cast(Nyxus::Feature2D::IMOM_RM_02)][0] = m02; + fvals[static_cast(Nyxus::Feature2D::IMOM_RM_03)][0] = m03; + fvals[static_cast(Nyxus::Feature2D::IMOM_RM_10)][0] = m10; + fvals[static_cast(Nyxus::Feature2D::IMOM_RM_11)][0] = m11; + fvals[static_cast(Nyxus::Feature2D::IMOM_RM_12)][0] = m12; + fvals[static_cast(Nyxus::Feature2D::IMOM_RM_13)][0] = m13; + fvals[static_cast(Nyxus::Feature2D::IMOM_RM_20)][0] = m20; + fvals[static_cast(Nyxus::Feature2D::IMOM_RM_21)][0] = m21; + fvals[static_cast(Nyxus::Feature2D::IMOM_RM_22)][0] = m22; + fvals[static_cast(Nyxus::Feature2D::IMOM_RM_23)][0] = m23; + fvals[static_cast(Nyxus::Feature2D::IMOM_RM_30)][0] = m30; + + fvals[static_cast(Nyxus::Feature2D::IMOM_WRM_00)][0] = wm00; + fvals[static_cast(Nyxus::Feature2D::IMOM_WRM_01)][0] = wm01; + fvals[static_cast(Nyxus::Feature2D::IMOM_WRM_02)][0] = wm02; + fvals[static_cast(Nyxus::Feature2D::IMOM_WRM_03)][0] = wm03; + fvals[static_cast(Nyxus::Feature2D::IMOM_WRM_10)][0] = wm10; + fvals[static_cast(Nyxus::Feature2D::IMOM_WRM_11)][0] = wm11; + fvals[static_cast(Nyxus::Feature2D::IMOM_WRM_12)][0] = wm12; + fvals[static_cast(Nyxus::Feature2D::IMOM_WRM_20)][0] = wm20; + fvals[static_cast(Nyxus::Feature2D::IMOM_WRM_21)][0] = wm21; + fvals[static_cast(Nyxus::Feature2D::IMOM_WRM_30)][0] = wm30; + + fvals[static_cast(Nyxus::Feature2D::IMOM_CM_00)][0] = mu00; + fvals[static_cast(Nyxus::Feature2D::IMOM_CM_01)][0] = mu01; + fvals[static_cast(Nyxus::Feature2D::IMOM_CM_02)][0] = mu02; + fvals[static_cast(Nyxus::Feature2D::IMOM_CM_03)][0] = mu03; + fvals[static_cast(Nyxus::Feature2D::IMOM_CM_10)][0] = mu10; + fvals[static_cast(Nyxus::Feature2D::IMOM_CM_11)][0] = mu11; + fvals[static_cast(Nyxus::Feature2D::IMOM_CM_12)][0] = mu12; + fvals[static_cast(Nyxus::Feature2D::IMOM_CM_13)][0] = mu13; + fvals[static_cast(Nyxus::Feature2D::IMOM_CM_20)][0] = mu20; + fvals[static_cast(Nyxus::Feature2D::IMOM_CM_21)][0] = mu21; + fvals[static_cast(Nyxus::Feature2D::IMOM_CM_22)][0] = mu22; + fvals[static_cast(Nyxus::Feature2D::IMOM_CM_23)][0] = mu23; + fvals[static_cast(Nyxus::Feature2D::IMOM_CM_30)][0] = mu30; + fvals[static_cast(Nyxus::Feature2D::IMOM_CM_31)][0] = mu31; + fvals[static_cast(Nyxus::Feature2D::IMOM_CM_32)][0] = mu32; + fvals[static_cast(Nyxus::Feature2D::IMOM_CM_33)][0] = mu33; + + fvals[static_cast(Nyxus::Feature2D::IMOM_WCM_02)][0] = wmu02; + fvals[static_cast(Nyxus::Feature2D::IMOM_WCM_03)][0] = wmu03; + fvals[static_cast(Nyxus::Feature2D::IMOM_WCM_11)][0] = wmu11; + fvals[static_cast(Nyxus::Feature2D::IMOM_WCM_12)][0] = wmu12; + fvals[static_cast(Nyxus::Feature2D::IMOM_WCM_20)][0] = wmu20; + fvals[static_cast(Nyxus::Feature2D::IMOM_WCM_21)][0] = wmu21; + fvals[static_cast(Nyxus::Feature2D::IMOM_WCM_30)][0] = wmu30; + + fvals[static_cast(Nyxus::Feature2D::IMOM_NCM_02)][0] = nu02; + fvals[static_cast(Nyxus::Feature2D::IMOM_NCM_03)][0] = nu03; + fvals[static_cast(Nyxus::Feature2D::IMOM_NCM_11)][0] = nu11; + fvals[static_cast(Nyxus::Feature2D::IMOM_NCM_12)][0] = nu12; + fvals[static_cast(Nyxus::Feature2D::IMOM_NCM_20)][0] = nu20; + fvals[static_cast(Nyxus::Feature2D::IMOM_NCM_21)][0] = nu21; + fvals[static_cast(Nyxus::Feature2D::IMOM_NCM_30)][0] = nu30; + + fvals[static_cast(Nyxus::Feature2D::IMOM_NRM_00)][0] = w00; + fvals[static_cast(Nyxus::Feature2D::IMOM_NRM_01)][0] = w01; + fvals[static_cast(Nyxus::Feature2D::IMOM_NRM_02)][0] = w02; + fvals[static_cast(Nyxus::Feature2D::IMOM_NRM_03)][0] = w03; + fvals[static_cast(Nyxus::Feature2D::IMOM_NRM_10)][0] = w10; + fvals[static_cast(Nyxus::Feature2D::IMOM_NRM_11)][0] = w11; + fvals[static_cast(Nyxus::Feature2D::IMOM_NRM_12)][0] = w12; + fvals[static_cast(Nyxus::Feature2D::IMOM_NRM_13)][0] = w13; + fvals[static_cast(Nyxus::Feature2D::IMOM_NRM_20)][0] = w20; + fvals[static_cast(Nyxus::Feature2D::IMOM_NRM_21)][0] = w21; + fvals[static_cast(Nyxus::Feature2D::IMOM_NRM_22)][0] = w22; + fvals[static_cast(Nyxus::Feature2D::IMOM_NRM_23)][0] = w23; + fvals[static_cast(Nyxus::Feature2D::IMOM_NRM_30)][0] = w30; + fvals[static_cast(Nyxus::Feature2D::IMOM_NRM_31)][0] = w31; + fvals[static_cast(Nyxus::Feature2D::IMOM_NRM_32)][0] = w32; + fvals[static_cast(Nyxus::Feature2D::IMOM_NRM_33)][0] = w33; + + fvals[static_cast(Nyxus::Feature2D::IMOM_HU1)][0] = hm1; + fvals[static_cast(Nyxus::Feature2D::IMOM_HU2)][0] = hm2; + fvals[static_cast(Nyxus::Feature2D::IMOM_HU3)][0] = hm3; + fvals[static_cast(Nyxus::Feature2D::IMOM_HU4)][0] = hm4; + fvals[static_cast(Nyxus::Feature2D::IMOM_HU5)][0] = hm5; + fvals[static_cast(Nyxus::Feature2D::IMOM_HU6)][0] = hm6; + fvals[static_cast(Nyxus::Feature2D::IMOM_HU7)][0] = hm7; + + fvals[static_cast(Nyxus::Feature2D::IMOM_WNCM_02)][0] = wncm02; + fvals[static_cast(Nyxus::Feature2D::IMOM_WNCM_03)][0] = wncm03; + fvals[static_cast(Nyxus::Feature2D::IMOM_WNCM_11)][0] = wncm11; + fvals[static_cast(Nyxus::Feature2D::IMOM_WNCM_12)][0] = wncm12; + fvals[static_cast(Nyxus::Feature2D::IMOM_WNCM_20)][0] = wncm20; + fvals[static_cast(Nyxus::Feature2D::IMOM_WNCM_21)][0] = wncm21; + fvals[static_cast(Nyxus::Feature2D::IMOM_WNCM_30)][0] = wncm30; + + fvals[static_cast(Nyxus::Feature2D::IMOM_WHU1)][0] = whm1; + fvals[static_cast(Nyxus::Feature2D::IMOM_WHU2)][0] = whm2; + fvals[static_cast(Nyxus::Feature2D::IMOM_WHU3)][0] = whm3; + fvals[static_cast(Nyxus::Feature2D::IMOM_WHU4)][0] = whm4; + fvals[static_cast(Nyxus::Feature2D::IMOM_WHU5)][0] = whm5; + fvals[static_cast(Nyxus::Feature2D::IMOM_WHU6)][0] = whm6; + fvals[static_cast(Nyxus::Feature2D::IMOM_WHU7)][0] = whm7; } #ifdef USE_GPU @@ -221,104 +221,104 @@ void Imoms2D_feature::save_values_from_gpu_buffer( size_t offs = i * GpusideState::__COUNT__; const gpureal* ptrBuf = &intermediate_already_hostside.hobuffer[offs]; - fvals[(int)Nyxus::Feature2D::IMOM_RM_00][0] = ptrBuf[GpusideState::RM00]; - fvals[(int)Nyxus::Feature2D::IMOM_RM_01][0] = ptrBuf[GpusideState::RM01]; - fvals[(int)Nyxus::Feature2D::IMOM_RM_02][0] = ptrBuf[GpusideState::RM02]; - fvals[(int)Nyxus::Feature2D::IMOM_RM_03][0] = ptrBuf[GpusideState::RM03]; - fvals[(int)Nyxus::Feature2D::IMOM_RM_10][0] = ptrBuf[GpusideState::RM10]; - fvals[(int)Nyxus::Feature2D::IMOM_RM_11][0] = ptrBuf[GpusideState::RM11]; - fvals[(int)Nyxus::Feature2D::IMOM_RM_12][0] = ptrBuf[GpusideState::RM12]; - fvals[(int)Nyxus::Feature2D::IMOM_RM_13][0] = ptrBuf[GpusideState::RM13]; - fvals[(int)Nyxus::Feature2D::IMOM_RM_20][0] = ptrBuf[GpusideState::RM20]; - fvals[(int)Nyxus::Feature2D::IMOM_RM_21][0] = ptrBuf[GpusideState::RM21]; - fvals[(int)Nyxus::Feature2D::IMOM_RM_22][0] = ptrBuf[GpusideState::RM22]; - fvals[(int)Nyxus::Feature2D::IMOM_RM_23][0] = ptrBuf[GpusideState::RM23]; - fvals[(int)Nyxus::Feature2D::IMOM_RM_30][0] = ptrBuf[GpusideState::RM30]; - - fvals[(int)Nyxus::Feature2D::IMOM_CM_00][0] = ptrBuf[GpusideState::CM00]; - fvals[(int)Nyxus::Feature2D::IMOM_CM_01][0] = ptrBuf[GpusideState::CM01]; - fvals[(int)Nyxus::Feature2D::IMOM_CM_02][0] = ptrBuf[GpusideState::CM02]; - fvals[(int)Nyxus::Feature2D::IMOM_CM_03][0] = ptrBuf[GpusideState::CM03]; - fvals[(int)Nyxus::Feature2D::IMOM_CM_10][0] = ptrBuf[GpusideState::CM10]; - fvals[(int)Nyxus::Feature2D::IMOM_CM_11][0] = ptrBuf[GpusideState::CM11]; - fvals[(int)Nyxus::Feature2D::IMOM_CM_12][0] = ptrBuf[GpusideState::CM12]; - fvals[(int)Nyxus::Feature2D::IMOM_CM_13][0] = ptrBuf[GpusideState::CM13]; - fvals[(int)Nyxus::Feature2D::IMOM_CM_20][0] = ptrBuf[GpusideState::CM20]; - fvals[(int)Nyxus::Feature2D::IMOM_CM_21][0] = ptrBuf[GpusideState::CM21]; - fvals[(int)Nyxus::Feature2D::IMOM_CM_22][0] = ptrBuf[GpusideState::CM22]; - fvals[(int)Nyxus::Feature2D::IMOM_CM_23][0] = ptrBuf[GpusideState::CM23]; - fvals[(int)Nyxus::Feature2D::IMOM_CM_30][0] = ptrBuf[GpusideState::CM30]; - fvals[(int)Nyxus::Feature2D::IMOM_CM_31][0] = ptrBuf[GpusideState::CM31]; - fvals[(int)Nyxus::Feature2D::IMOM_CM_32][0] = ptrBuf[GpusideState::CM32]; - fvals[(int)Nyxus::Feature2D::IMOM_CM_33][0] = ptrBuf[GpusideState::CM33]; - - fvals[(int)Nyxus::Feature2D::IMOM_NRM_00][0] = ptrBuf[GpusideState::W00]; - fvals[(int)Nyxus::Feature2D::IMOM_NRM_01][0] = ptrBuf[GpusideState::W01]; - fvals[(int)Nyxus::Feature2D::IMOM_NRM_02][0] = ptrBuf[GpusideState::W02]; - fvals[(int)Nyxus::Feature2D::IMOM_NRM_03][0] = ptrBuf[GpusideState::W03]; - fvals[(int)Nyxus::Feature2D::IMOM_NRM_10][0] = ptrBuf[GpusideState::W10]; - fvals[(int)Nyxus::Feature2D::IMOM_NRM_11][0] = ptrBuf[GpusideState::W11]; - fvals[(int)Nyxus::Feature2D::IMOM_NRM_12][0] = ptrBuf[GpusideState::W12]; - fvals[(int)Nyxus::Feature2D::IMOM_NRM_13][0] = ptrBuf[GpusideState::W13]; - fvals[(int)Nyxus::Feature2D::IMOM_NRM_20][0] = ptrBuf[GpusideState::W20]; - fvals[(int)Nyxus::Feature2D::IMOM_NRM_21][0] = ptrBuf[GpusideState::W21]; - fvals[(int)Nyxus::Feature2D::IMOM_NRM_22][0] = ptrBuf[GpusideState::W22]; - fvals[(int)Nyxus::Feature2D::IMOM_NRM_23][0] = ptrBuf[GpusideState::W23]; - fvals[(int)Nyxus::Feature2D::IMOM_NRM_30][0] = ptrBuf[GpusideState::W30]; - fvals[(int)Nyxus::Feature2D::IMOM_NRM_31][0] = ptrBuf[GpusideState::W31]; - fvals[(int)Nyxus::Feature2D::IMOM_NRM_32][0] = ptrBuf[GpusideState::W32]; - fvals[(int)Nyxus::Feature2D::IMOM_NRM_33][0] = ptrBuf[GpusideState::W33]; - - fvals[(int)Nyxus::Feature2D::IMOM_NCM_02][0] = ptrBuf[GpusideState::NU02]; - fvals[(int)Nyxus::Feature2D::IMOM_NCM_03][0] = ptrBuf[GpusideState::NU03]; - fvals[(int)Nyxus::Feature2D::IMOM_NCM_11][0] = ptrBuf[GpusideState::NU11]; - fvals[(int)Nyxus::Feature2D::IMOM_NCM_12][0] = ptrBuf[GpusideState::NU12]; - fvals[(int)Nyxus::Feature2D::IMOM_NCM_20][0] = ptrBuf[GpusideState::NU20]; - fvals[(int)Nyxus::Feature2D::IMOM_NCM_21][0] = ptrBuf[GpusideState::NU21]; - fvals[(int)Nyxus::Feature2D::IMOM_NCM_30][0] = ptrBuf[GpusideState::NU30]; - - fvals[(int)Nyxus::Feature2D::IMOM_HU1][0] = ptrBuf[GpusideState::H1]; - fvals[(int)Nyxus::Feature2D::IMOM_HU2][0] = ptrBuf[GpusideState::H2]; - fvals[(int)Nyxus::Feature2D::IMOM_HU3][0] = ptrBuf[GpusideState::H3]; - fvals[(int)Nyxus::Feature2D::IMOM_HU4][0] = ptrBuf[GpusideState::H4]; - fvals[(int)Nyxus::Feature2D::IMOM_HU5][0] = ptrBuf[GpusideState::H5]; - fvals[(int)Nyxus::Feature2D::IMOM_HU6][0] = ptrBuf[GpusideState::H6]; - fvals[(int)Nyxus::Feature2D::IMOM_HU7][0] = ptrBuf[GpusideState::H7]; - - fvals[(int)Nyxus::Feature2D::IMOM_WRM_00][0] = ptrBuf[GpusideState::WRM00]; - fvals[(int)Nyxus::Feature2D::IMOM_WRM_01][0] = ptrBuf[GpusideState::WRM01]; - fvals[(int)Nyxus::Feature2D::IMOM_WRM_02][0] = ptrBuf[GpusideState::WRM02]; - fvals[(int)Nyxus::Feature2D::IMOM_WRM_03][0] = ptrBuf[GpusideState::WRM03]; - fvals[(int)Nyxus::Feature2D::IMOM_WRM_10][0] = ptrBuf[GpusideState::WRM10]; - fvals[(int)Nyxus::Feature2D::IMOM_WRM_11][0] = ptrBuf[GpusideState::WRM11]; - fvals[(int)Nyxus::Feature2D::IMOM_WRM_12][0] = ptrBuf[GpusideState::WRM12]; - fvals[(int)Nyxus::Feature2D::IMOM_WRM_20][0] = ptrBuf[GpusideState::WRM20]; - fvals[(int)Nyxus::Feature2D::IMOM_WRM_21][0] = ptrBuf[GpusideState::WRM21]; - fvals[(int)Nyxus::Feature2D::IMOM_WRM_30][0] = ptrBuf[GpusideState::WRM30]; - - fvals[(int)Nyxus::Feature2D::IMOM_WCM_02][0] = ptrBuf[GpusideState::WCM02]; - fvals[(int)Nyxus::Feature2D::IMOM_WCM_03][0] = ptrBuf[GpusideState::WCM03]; - fvals[(int)Nyxus::Feature2D::IMOM_WCM_11][0] = ptrBuf[GpusideState::WCM11]; - fvals[(int)Nyxus::Feature2D::IMOM_WCM_12][0] = ptrBuf[GpusideState::WCM12]; - fvals[(int)Nyxus::Feature2D::IMOM_WCM_20][0] = ptrBuf[GpusideState::WCM20]; - fvals[(int)Nyxus::Feature2D::IMOM_WCM_21][0] = ptrBuf[GpusideState::WCM21]; - fvals[(int)Nyxus::Feature2D::IMOM_WCM_30][0] = ptrBuf[GpusideState::WCM30]; - - fvals[(int)Nyxus::Feature2D::IMOM_WNCM_02][0] = ptrBuf[GpusideState::WNU02]; - fvals[(int)Nyxus::Feature2D::IMOM_WNCM_03][0] = ptrBuf[GpusideState::WNU03]; - fvals[(int)Nyxus::Feature2D::IMOM_WNCM_11][0] = ptrBuf[GpusideState::WNU11]; - fvals[(int)Nyxus::Feature2D::IMOM_WNCM_12][0] = ptrBuf[GpusideState::WNU12]; - fvals[(int)Nyxus::Feature2D::IMOM_WNCM_20][0] = ptrBuf[GpusideState::WNU20]; - fvals[(int)Nyxus::Feature2D::IMOM_WNCM_21][0] = ptrBuf[GpusideState::WNU21]; - fvals[(int)Nyxus::Feature2D::IMOM_WNCM_30][0] = ptrBuf[GpusideState::WNU30]; - - fvals[(int)Nyxus::Feature2D::IMOM_WHU1][0] = ptrBuf[GpusideState::WH1]; - fvals[(int)Nyxus::Feature2D::IMOM_WHU2][0] = ptrBuf[GpusideState::WH2]; - fvals[(int)Nyxus::Feature2D::IMOM_WHU3][0] = ptrBuf[GpusideState::WH3]; - fvals[(int)Nyxus::Feature2D::IMOM_WHU4][0] = ptrBuf[GpusideState::WH4]; - fvals[(int)Nyxus::Feature2D::IMOM_WHU5][0] = ptrBuf[GpusideState::WH5]; - fvals[(int)Nyxus::Feature2D::IMOM_WHU6][0] = ptrBuf[GpusideState::WH6]; - fvals[(int)Nyxus::Feature2D::IMOM_WHU7][0] = ptrBuf[GpusideState::WH7]; + fvals[static_cast(Nyxus::Feature2D::IMOM_RM_00)][0] = ptrBuf[GpusideState::RM00]; + fvals[static_cast(Nyxus::Feature2D::IMOM_RM_01)][0] = ptrBuf[GpusideState::RM01]; + fvals[static_cast(Nyxus::Feature2D::IMOM_RM_02)][0] = ptrBuf[GpusideState::RM02]; + fvals[static_cast(Nyxus::Feature2D::IMOM_RM_03)][0] = ptrBuf[GpusideState::RM03]; + fvals[static_cast(Nyxus::Feature2D::IMOM_RM_10)][0] = ptrBuf[GpusideState::RM10]; + fvals[static_cast(Nyxus::Feature2D::IMOM_RM_11)][0] = ptrBuf[GpusideState::RM11]; + fvals[static_cast(Nyxus::Feature2D::IMOM_RM_12)][0] = ptrBuf[GpusideState::RM12]; + fvals[static_cast(Nyxus::Feature2D::IMOM_RM_13)][0] = ptrBuf[GpusideState::RM13]; + fvals[static_cast(Nyxus::Feature2D::IMOM_RM_20)][0] = ptrBuf[GpusideState::RM20]; + fvals[static_cast(Nyxus::Feature2D::IMOM_RM_21)][0] = ptrBuf[GpusideState::RM21]; + fvals[static_cast(Nyxus::Feature2D::IMOM_RM_22)][0] = ptrBuf[GpusideState::RM22]; + fvals[static_cast(Nyxus::Feature2D::IMOM_RM_23)][0] = ptrBuf[GpusideState::RM23]; + fvals[static_cast(Nyxus::Feature2D::IMOM_RM_30)][0] = ptrBuf[GpusideState::RM30]; + + fvals[static_cast(Nyxus::Feature2D::IMOM_CM_00)][0] = ptrBuf[GpusideState::CM00]; + fvals[static_cast(Nyxus::Feature2D::IMOM_CM_01)][0] = ptrBuf[GpusideState::CM01]; + fvals[static_cast(Nyxus::Feature2D::IMOM_CM_02)][0] = ptrBuf[GpusideState::CM02]; + fvals[static_cast(Nyxus::Feature2D::IMOM_CM_03)][0] = ptrBuf[GpusideState::CM03]; + fvals[static_cast(Nyxus::Feature2D::IMOM_CM_10)][0] = ptrBuf[GpusideState::CM10]; + fvals[static_cast(Nyxus::Feature2D::IMOM_CM_11)][0] = ptrBuf[GpusideState::CM11]; + fvals[static_cast(Nyxus::Feature2D::IMOM_CM_12)][0] = ptrBuf[GpusideState::CM12]; + fvals[static_cast(Nyxus::Feature2D::IMOM_CM_13)][0] = ptrBuf[GpusideState::CM13]; + fvals[static_cast(Nyxus::Feature2D::IMOM_CM_20)][0] = ptrBuf[GpusideState::CM20]; + fvals[static_cast(Nyxus::Feature2D::IMOM_CM_21)][0] = ptrBuf[GpusideState::CM21]; + fvals[static_cast(Nyxus::Feature2D::IMOM_CM_22)][0] = ptrBuf[GpusideState::CM22]; + fvals[static_cast(Nyxus::Feature2D::IMOM_CM_23)][0] = ptrBuf[GpusideState::CM23]; + fvals[static_cast(Nyxus::Feature2D::IMOM_CM_30)][0] = ptrBuf[GpusideState::CM30]; + fvals[static_cast(Nyxus::Feature2D::IMOM_CM_31)][0] = ptrBuf[GpusideState::CM31]; + fvals[static_cast(Nyxus::Feature2D::IMOM_CM_32)][0] = ptrBuf[GpusideState::CM32]; + fvals[static_cast(Nyxus::Feature2D::IMOM_CM_33)][0] = ptrBuf[GpusideState::CM33]; + + fvals[static_cast(Nyxus::Feature2D::IMOM_NRM_00)][0] = ptrBuf[GpusideState::W00]; + fvals[static_cast(Nyxus::Feature2D::IMOM_NRM_01)][0] = ptrBuf[GpusideState::W01]; + fvals[static_cast(Nyxus::Feature2D::IMOM_NRM_02)][0] = ptrBuf[GpusideState::W02]; + fvals[static_cast(Nyxus::Feature2D::IMOM_NRM_03)][0] = ptrBuf[GpusideState::W03]; + fvals[static_cast(Nyxus::Feature2D::IMOM_NRM_10)][0] = ptrBuf[GpusideState::W10]; + fvals[static_cast(Nyxus::Feature2D::IMOM_NRM_11)][0] = ptrBuf[GpusideState::W11]; + fvals[static_cast(Nyxus::Feature2D::IMOM_NRM_12)][0] = ptrBuf[GpusideState::W12]; + fvals[static_cast(Nyxus::Feature2D::IMOM_NRM_13)][0] = ptrBuf[GpusideState::W13]; + fvals[static_cast(Nyxus::Feature2D::IMOM_NRM_20)][0] = ptrBuf[GpusideState::W20]; + fvals[static_cast(Nyxus::Feature2D::IMOM_NRM_21)][0] = ptrBuf[GpusideState::W21]; + fvals[static_cast(Nyxus::Feature2D::IMOM_NRM_22)][0] = ptrBuf[GpusideState::W22]; + fvals[static_cast(Nyxus::Feature2D::IMOM_NRM_23)][0] = ptrBuf[GpusideState::W23]; + fvals[static_cast(Nyxus::Feature2D::IMOM_NRM_30)][0] = ptrBuf[GpusideState::W30]; + fvals[static_cast(Nyxus::Feature2D::IMOM_NRM_31)][0] = ptrBuf[GpusideState::W31]; + fvals[static_cast(Nyxus::Feature2D::IMOM_NRM_32)][0] = ptrBuf[GpusideState::W32]; + fvals[static_cast(Nyxus::Feature2D::IMOM_NRM_33)][0] = ptrBuf[GpusideState::W33]; + + fvals[static_cast(Nyxus::Feature2D::IMOM_NCM_02)][0] = ptrBuf[GpusideState::NU02]; + fvals[static_cast(Nyxus::Feature2D::IMOM_NCM_03)][0] = ptrBuf[GpusideState::NU03]; + fvals[static_cast(Nyxus::Feature2D::IMOM_NCM_11)][0] = ptrBuf[GpusideState::NU11]; + fvals[static_cast(Nyxus::Feature2D::IMOM_NCM_12)][0] = ptrBuf[GpusideState::NU12]; + fvals[static_cast(Nyxus::Feature2D::IMOM_NCM_20)][0] = ptrBuf[GpusideState::NU20]; + fvals[static_cast(Nyxus::Feature2D::IMOM_NCM_21)][0] = ptrBuf[GpusideState::NU21]; + fvals[static_cast(Nyxus::Feature2D::IMOM_NCM_30)][0] = ptrBuf[GpusideState::NU30]; + + fvals[static_cast(Nyxus::Feature2D::IMOM_HU1)][0] = ptrBuf[GpusideState::H1]; + fvals[static_cast(Nyxus::Feature2D::IMOM_HU2)][0] = ptrBuf[GpusideState::H2]; + fvals[static_cast(Nyxus::Feature2D::IMOM_HU3)][0] = ptrBuf[GpusideState::H3]; + fvals[static_cast(Nyxus::Feature2D::IMOM_HU4)][0] = ptrBuf[GpusideState::H4]; + fvals[static_cast(Nyxus::Feature2D::IMOM_HU5)][0] = ptrBuf[GpusideState::H5]; + fvals[static_cast(Nyxus::Feature2D::IMOM_HU6)][0] = ptrBuf[GpusideState::H6]; + fvals[static_cast(Nyxus::Feature2D::IMOM_HU7)][0] = ptrBuf[GpusideState::H7]; + + fvals[static_cast(Nyxus::Feature2D::IMOM_WRM_00)][0] = ptrBuf[GpusideState::WRM00]; + fvals[static_cast(Nyxus::Feature2D::IMOM_WRM_01)][0] = ptrBuf[GpusideState::WRM01]; + fvals[static_cast(Nyxus::Feature2D::IMOM_WRM_02)][0] = ptrBuf[GpusideState::WRM02]; + fvals[static_cast(Nyxus::Feature2D::IMOM_WRM_03)][0] = ptrBuf[GpusideState::WRM03]; + fvals[static_cast(Nyxus::Feature2D::IMOM_WRM_10)][0] = ptrBuf[GpusideState::WRM10]; + fvals[static_cast(Nyxus::Feature2D::IMOM_WRM_11)][0] = ptrBuf[GpusideState::WRM11]; + fvals[static_cast(Nyxus::Feature2D::IMOM_WRM_12)][0] = ptrBuf[GpusideState::WRM12]; + fvals[static_cast(Nyxus::Feature2D::IMOM_WRM_20)][0] = ptrBuf[GpusideState::WRM20]; + fvals[static_cast(Nyxus::Feature2D::IMOM_WRM_21)][0] = ptrBuf[GpusideState::WRM21]; + fvals[static_cast(Nyxus::Feature2D::IMOM_WRM_30)][0] = ptrBuf[GpusideState::WRM30]; + + fvals[static_cast(Nyxus::Feature2D::IMOM_WCM_02)][0] = ptrBuf[GpusideState::WCM02]; + fvals[static_cast(Nyxus::Feature2D::IMOM_WCM_03)][0] = ptrBuf[GpusideState::WCM03]; + fvals[static_cast(Nyxus::Feature2D::IMOM_WCM_11)][0] = ptrBuf[GpusideState::WCM11]; + fvals[static_cast(Nyxus::Feature2D::IMOM_WCM_12)][0] = ptrBuf[GpusideState::WCM12]; + fvals[static_cast(Nyxus::Feature2D::IMOM_WCM_20)][0] = ptrBuf[GpusideState::WCM20]; + fvals[static_cast(Nyxus::Feature2D::IMOM_WCM_21)][0] = ptrBuf[GpusideState::WCM21]; + fvals[static_cast(Nyxus::Feature2D::IMOM_WCM_30)][0] = ptrBuf[GpusideState::WCM30]; + + fvals[static_cast(Nyxus::Feature2D::IMOM_WNCM_02)][0] = ptrBuf[GpusideState::WNU02]; + fvals[static_cast(Nyxus::Feature2D::IMOM_WNCM_03)][0] = ptrBuf[GpusideState::WNU03]; + fvals[static_cast(Nyxus::Feature2D::IMOM_WNCM_11)][0] = ptrBuf[GpusideState::WNU11]; + fvals[static_cast(Nyxus::Feature2D::IMOM_WNCM_12)][0] = ptrBuf[GpusideState::WNU12]; + fvals[static_cast(Nyxus::Feature2D::IMOM_WNCM_20)][0] = ptrBuf[GpusideState::WNU20]; + fvals[static_cast(Nyxus::Feature2D::IMOM_WNCM_21)][0] = ptrBuf[GpusideState::WNU21]; + fvals[static_cast(Nyxus::Feature2D::IMOM_WNCM_30)][0] = ptrBuf[GpusideState::WNU30]; + + fvals[static_cast(Nyxus::Feature2D::IMOM_WHU1)][0] = ptrBuf[GpusideState::WH1]; + fvals[static_cast(Nyxus::Feature2D::IMOM_WHU2)][0] = ptrBuf[GpusideState::WH2]; + fvals[static_cast(Nyxus::Feature2D::IMOM_WHU3)][0] = ptrBuf[GpusideState::WH3]; + fvals[static_cast(Nyxus::Feature2D::IMOM_WHU4)][0] = ptrBuf[GpusideState::WH4]; + fvals[static_cast(Nyxus::Feature2D::IMOM_WHU5)][0] = ptrBuf[GpusideState::WH5]; + fvals[static_cast(Nyxus::Feature2D::IMOM_WHU6)][0] = ptrBuf[GpusideState::WH6]; + fvals[static_cast(Nyxus::Feature2D::IMOM_WHU7)][0] = ptrBuf[GpusideState::WH7]; } } @@ -370,104 +370,104 @@ void Smoms2D_feature::parallel_process_1_batch (size_t start, size_t end, std::v void Smoms2D_feature::save_value(std::vector>& fvals) { - fvals[(int)Nyxus::Feature2D::SPAT_MOMENT_00][0] = m00; - fvals[(int)Nyxus::Feature2D::SPAT_MOMENT_01][0] = m01; - fvals[(int)Nyxus::Feature2D::SPAT_MOMENT_02][0] = m02; - fvals[(int)Nyxus::Feature2D::SPAT_MOMENT_03][0] = m03; - fvals[(int)Nyxus::Feature2D::SPAT_MOMENT_10][0] = m10; - fvals[(int)Nyxus::Feature2D::SPAT_MOMENT_11][0] = m11; - fvals[(int)Nyxus::Feature2D::SPAT_MOMENT_12][0] = m12; - fvals[(int)Nyxus::Feature2D::SPAT_MOMENT_13][0] = m13; - fvals[(int)Nyxus::Feature2D::SPAT_MOMENT_20][0] = m20; - fvals[(int)Nyxus::Feature2D::SPAT_MOMENT_21][0] = m21; - fvals[(int)Nyxus::Feature2D::SPAT_MOMENT_22][0] = m22; - fvals[(int)Nyxus::Feature2D::SPAT_MOMENT_23][0] = m23; - fvals[(int)Nyxus::Feature2D::SPAT_MOMENT_30][0] = m30; - - fvals[(int)Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_00][0] = wm00; - fvals[(int)Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_01][0] = wm01; - fvals[(int)Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_02][0] = wm02; - fvals[(int)Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_03][0] = wm03; - fvals[(int)Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_10][0] = wm10; - fvals[(int)Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_11][0] = wm11; - fvals[(int)Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_12][0] = wm12; - fvals[(int)Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_20][0] = wm20; - fvals[(int)Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_21][0] = wm21; - fvals[(int)Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_30][0] = wm30; - - fvals[(int)Nyxus::Feature2D::CENTRAL_MOMENT_00][0] = mu00; - fvals[(int)Nyxus::Feature2D::CENTRAL_MOMENT_01][0] = mu01; - fvals[(int)Nyxus::Feature2D::CENTRAL_MOMENT_02][0] = mu02; - fvals[(int)Nyxus::Feature2D::CENTRAL_MOMENT_03][0] = mu03; - fvals[(int)Nyxus::Feature2D::CENTRAL_MOMENT_10][0] = mu10; - fvals[(int)Nyxus::Feature2D::CENTRAL_MOMENT_11][0] = mu11; - fvals[(int)Nyxus::Feature2D::CENTRAL_MOMENT_12][0] = mu12; - fvals[(int)Nyxus::Feature2D::CENTRAL_MOMENT_13][0] = mu13; - fvals[(int)Nyxus::Feature2D::CENTRAL_MOMENT_20][0] = mu20; - fvals[(int)Nyxus::Feature2D::CENTRAL_MOMENT_21][0] = mu21; - fvals[(int)Nyxus::Feature2D::CENTRAL_MOMENT_22][0] = mu22; - fvals[(int)Nyxus::Feature2D::CENTRAL_MOMENT_23][0] = mu23; - fvals[(int)Nyxus::Feature2D::CENTRAL_MOMENT_30][0] = mu30; - fvals[(int)Nyxus::Feature2D::CENTRAL_MOMENT_31][0] = mu31; - fvals[(int)Nyxus::Feature2D::CENTRAL_MOMENT_32][0] = mu32; - fvals[(int)Nyxus::Feature2D::CENTRAL_MOMENT_33][0] = mu33; - - fvals[(int)Nyxus::Feature2D::WEIGHTED_CENTRAL_MOMENT_02][0] = wmu02; - fvals[(int)Nyxus::Feature2D::WEIGHTED_CENTRAL_MOMENT_03][0] = wmu03; - fvals[(int)Nyxus::Feature2D::WEIGHTED_CENTRAL_MOMENT_11][0] = wmu11; - fvals[(int)Nyxus::Feature2D::WEIGHTED_CENTRAL_MOMENT_12][0] = wmu12; - fvals[(int)Nyxus::Feature2D::WEIGHTED_CENTRAL_MOMENT_20][0] = wmu20; - fvals[(int)Nyxus::Feature2D::WEIGHTED_CENTRAL_MOMENT_21][0] = wmu21; - fvals[(int)Nyxus::Feature2D::WEIGHTED_CENTRAL_MOMENT_30][0] = wmu30; - - fvals[(int)Nyxus::Feature2D::NORM_CENTRAL_MOMENT_02][0] = nu02; - fvals[(int)Nyxus::Feature2D::NORM_CENTRAL_MOMENT_03][0] = nu03; - fvals[(int)Nyxus::Feature2D::NORM_CENTRAL_MOMENT_11][0] = nu11; - fvals[(int)Nyxus::Feature2D::NORM_CENTRAL_MOMENT_12][0] = nu12; - fvals[(int)Nyxus::Feature2D::NORM_CENTRAL_MOMENT_20][0] = nu20; - fvals[(int)Nyxus::Feature2D::NORM_CENTRAL_MOMENT_21][0] = nu21; - fvals[(int)Nyxus::Feature2D::NORM_CENTRAL_MOMENT_30][0] = nu30; - - fvals[(int)Nyxus::Feature2D::NORM_SPAT_MOMENT_00][0] = w00; - fvals[(int)Nyxus::Feature2D::NORM_SPAT_MOMENT_01][0] = w01; - fvals[(int)Nyxus::Feature2D::NORM_SPAT_MOMENT_02][0] = w02; - fvals[(int)Nyxus::Feature2D::NORM_SPAT_MOMENT_03][0] = w03; - fvals[(int)Nyxus::Feature2D::NORM_SPAT_MOMENT_10][0] = w10; - fvals[(int)Nyxus::Feature2D::NORM_SPAT_MOMENT_11][0] = w11; - fvals[(int)Nyxus::Feature2D::NORM_SPAT_MOMENT_12][0] = w12; - fvals[(int)Nyxus::Feature2D::NORM_SPAT_MOMENT_13][0] = w13; - fvals[(int)Nyxus::Feature2D::NORM_SPAT_MOMENT_20][0] = w20; - fvals[(int)Nyxus::Feature2D::NORM_SPAT_MOMENT_21][0] = w21; - fvals[(int)Nyxus::Feature2D::NORM_SPAT_MOMENT_22][0] = w22; - fvals[(int)Nyxus::Feature2D::NORM_SPAT_MOMENT_23][0] = w23; - fvals[(int)Nyxus::Feature2D::NORM_SPAT_MOMENT_30][0] = w30; - fvals[(int)Nyxus::Feature2D::NORM_SPAT_MOMENT_31][0] = w31; - fvals[(int)Nyxus::Feature2D::NORM_SPAT_MOMENT_32][0] = w32; - fvals[(int)Nyxus::Feature2D::NORM_SPAT_MOMENT_33][0] = w33; - - fvals[(int)Nyxus::Feature2D::HU_M1][0] = hm1; - fvals[(int)Nyxus::Feature2D::HU_M2][0] = hm2; - fvals[(int)Nyxus::Feature2D::HU_M3][0] = hm3; - fvals[(int)Nyxus::Feature2D::HU_M4][0] = hm4; - fvals[(int)Nyxus::Feature2D::HU_M5][0] = hm5; - fvals[(int)Nyxus::Feature2D::HU_M6][0] = hm6; - fvals[(int)Nyxus::Feature2D::HU_M7][0] = hm7; - - fvals[(int)Nyxus::Feature2D::WT_NORM_CTR_MOM_02][0] = wncm02; - fvals[(int)Nyxus::Feature2D::WT_NORM_CTR_MOM_03][0] = wncm03; - fvals[(int)Nyxus::Feature2D::WT_NORM_CTR_MOM_11][0] = wncm11; - fvals[(int)Nyxus::Feature2D::WT_NORM_CTR_MOM_12][0] = wncm12; - fvals[(int)Nyxus::Feature2D::WT_NORM_CTR_MOM_20][0] = wncm20; - fvals[(int)Nyxus::Feature2D::WT_NORM_CTR_MOM_21][0] = wncm21; - fvals[(int)Nyxus::Feature2D::WT_NORM_CTR_MOM_30][0] = wncm30; - - fvals[(int)Nyxus::Feature2D::WEIGHTED_HU_M1][0] = whm1; - fvals[(int)Nyxus::Feature2D::WEIGHTED_HU_M2][0] = whm2; - fvals[(int)Nyxus::Feature2D::WEIGHTED_HU_M3][0] = whm3; - fvals[(int)Nyxus::Feature2D::WEIGHTED_HU_M4][0] = whm4; - fvals[(int)Nyxus::Feature2D::WEIGHTED_HU_M5][0] = whm5; - fvals[(int)Nyxus::Feature2D::WEIGHTED_HU_M6][0] = whm6; - fvals[(int)Nyxus::Feature2D::WEIGHTED_HU_M7][0] = whm7; + fvals[static_cast(Nyxus::Feature2D::SPAT_MOMENT_00)][0] = m00; + fvals[static_cast(Nyxus::Feature2D::SPAT_MOMENT_01)][0] = m01; + fvals[static_cast(Nyxus::Feature2D::SPAT_MOMENT_02)][0] = m02; + fvals[static_cast(Nyxus::Feature2D::SPAT_MOMENT_03)][0] = m03; + fvals[static_cast(Nyxus::Feature2D::SPAT_MOMENT_10)][0] = m10; + fvals[static_cast(Nyxus::Feature2D::SPAT_MOMENT_11)][0] = m11; + fvals[static_cast(Nyxus::Feature2D::SPAT_MOMENT_12)][0] = m12; + fvals[static_cast(Nyxus::Feature2D::SPAT_MOMENT_13)][0] = m13; + fvals[static_cast(Nyxus::Feature2D::SPAT_MOMENT_20)][0] = m20; + fvals[static_cast(Nyxus::Feature2D::SPAT_MOMENT_21)][0] = m21; + fvals[static_cast(Nyxus::Feature2D::SPAT_MOMENT_22)][0] = m22; + fvals[static_cast(Nyxus::Feature2D::SPAT_MOMENT_23)][0] = m23; + fvals[static_cast(Nyxus::Feature2D::SPAT_MOMENT_30)][0] = m30; + + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_00)][0] = wm00; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_01)][0] = wm01; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_02)][0] = wm02; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_03)][0] = wm03; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_10)][0] = wm10; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_11)][0] = wm11; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_12)][0] = wm12; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_20)][0] = wm20; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_21)][0] = wm21; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_30)][0] = wm30; + + fvals[static_cast(Nyxus::Feature2D::CENTRAL_MOMENT_00)][0] = mu00; + fvals[static_cast(Nyxus::Feature2D::CENTRAL_MOMENT_01)][0] = mu01; + fvals[static_cast(Nyxus::Feature2D::CENTRAL_MOMENT_02)][0] = mu02; + fvals[static_cast(Nyxus::Feature2D::CENTRAL_MOMENT_03)][0] = mu03; + fvals[static_cast(Nyxus::Feature2D::CENTRAL_MOMENT_10)][0] = mu10; + fvals[static_cast(Nyxus::Feature2D::CENTRAL_MOMENT_11)][0] = mu11; + fvals[static_cast(Nyxus::Feature2D::CENTRAL_MOMENT_12)][0] = mu12; + fvals[static_cast(Nyxus::Feature2D::CENTRAL_MOMENT_13)][0] = mu13; + fvals[static_cast(Nyxus::Feature2D::CENTRAL_MOMENT_20)][0] = mu20; + fvals[static_cast(Nyxus::Feature2D::CENTRAL_MOMENT_21)][0] = mu21; + fvals[static_cast(Nyxus::Feature2D::CENTRAL_MOMENT_22)][0] = mu22; + fvals[static_cast(Nyxus::Feature2D::CENTRAL_MOMENT_23)][0] = mu23; + fvals[static_cast(Nyxus::Feature2D::CENTRAL_MOMENT_30)][0] = mu30; + fvals[static_cast(Nyxus::Feature2D::CENTRAL_MOMENT_31)][0] = mu31; + fvals[static_cast(Nyxus::Feature2D::CENTRAL_MOMENT_32)][0] = mu32; + fvals[static_cast(Nyxus::Feature2D::CENTRAL_MOMENT_33)][0] = mu33; + + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_CENTRAL_MOMENT_02)][0] = wmu02; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_CENTRAL_MOMENT_03)][0] = wmu03; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_CENTRAL_MOMENT_11)][0] = wmu11; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_CENTRAL_MOMENT_12)][0] = wmu12; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_CENTRAL_MOMENT_20)][0] = wmu20; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_CENTRAL_MOMENT_21)][0] = wmu21; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_CENTRAL_MOMENT_30)][0] = wmu30; + + fvals[static_cast(Nyxus::Feature2D::NORM_CENTRAL_MOMENT_02)][0] = nu02; + fvals[static_cast(Nyxus::Feature2D::NORM_CENTRAL_MOMENT_03)][0] = nu03; + fvals[static_cast(Nyxus::Feature2D::NORM_CENTRAL_MOMENT_11)][0] = nu11; + fvals[static_cast(Nyxus::Feature2D::NORM_CENTRAL_MOMENT_12)][0] = nu12; + fvals[static_cast(Nyxus::Feature2D::NORM_CENTRAL_MOMENT_20)][0] = nu20; + fvals[static_cast(Nyxus::Feature2D::NORM_CENTRAL_MOMENT_21)][0] = nu21; + fvals[static_cast(Nyxus::Feature2D::NORM_CENTRAL_MOMENT_30)][0] = nu30; + + fvals[static_cast(Nyxus::Feature2D::NORM_SPAT_MOMENT_00)][0] = w00; + fvals[static_cast(Nyxus::Feature2D::NORM_SPAT_MOMENT_01)][0] = w01; + fvals[static_cast(Nyxus::Feature2D::NORM_SPAT_MOMENT_02)][0] = w02; + fvals[static_cast(Nyxus::Feature2D::NORM_SPAT_MOMENT_03)][0] = w03; + fvals[static_cast(Nyxus::Feature2D::NORM_SPAT_MOMENT_10)][0] = w10; + fvals[static_cast(Nyxus::Feature2D::NORM_SPAT_MOMENT_11)][0] = w11; + fvals[static_cast(Nyxus::Feature2D::NORM_SPAT_MOMENT_12)][0] = w12; + fvals[static_cast(Nyxus::Feature2D::NORM_SPAT_MOMENT_13)][0] = w13; + fvals[static_cast(Nyxus::Feature2D::NORM_SPAT_MOMENT_20)][0] = w20; + fvals[static_cast(Nyxus::Feature2D::NORM_SPAT_MOMENT_21)][0] = w21; + fvals[static_cast(Nyxus::Feature2D::NORM_SPAT_MOMENT_22)][0] = w22; + fvals[static_cast(Nyxus::Feature2D::NORM_SPAT_MOMENT_23)][0] = w23; + fvals[static_cast(Nyxus::Feature2D::NORM_SPAT_MOMENT_30)][0] = w30; + fvals[static_cast(Nyxus::Feature2D::NORM_SPAT_MOMENT_31)][0] = w31; + fvals[static_cast(Nyxus::Feature2D::NORM_SPAT_MOMENT_32)][0] = w32; + fvals[static_cast(Nyxus::Feature2D::NORM_SPAT_MOMENT_33)][0] = w33; + + fvals[static_cast(Nyxus::Feature2D::HU_M1)][0] = hm1; + fvals[static_cast(Nyxus::Feature2D::HU_M2)][0] = hm2; + fvals[static_cast(Nyxus::Feature2D::HU_M3)][0] = hm3; + fvals[static_cast(Nyxus::Feature2D::HU_M4)][0] = hm4; + fvals[static_cast(Nyxus::Feature2D::HU_M5)][0] = hm5; + fvals[static_cast(Nyxus::Feature2D::HU_M6)][0] = hm6; + fvals[static_cast(Nyxus::Feature2D::HU_M7)][0] = hm7; + + fvals[static_cast(Nyxus::Feature2D::WT_NORM_CTR_MOM_02)][0] = wncm02; + fvals[static_cast(Nyxus::Feature2D::WT_NORM_CTR_MOM_03)][0] = wncm03; + fvals[static_cast(Nyxus::Feature2D::WT_NORM_CTR_MOM_11)][0] = wncm11; + fvals[static_cast(Nyxus::Feature2D::WT_NORM_CTR_MOM_12)][0] = wncm12; + fvals[static_cast(Nyxus::Feature2D::WT_NORM_CTR_MOM_20)][0] = wncm20; + fvals[static_cast(Nyxus::Feature2D::WT_NORM_CTR_MOM_21)][0] = wncm21; + fvals[static_cast(Nyxus::Feature2D::WT_NORM_CTR_MOM_30)][0] = wncm30; + + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_HU_M1)][0] = whm1; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_HU_M2)][0] = whm2; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_HU_M3)][0] = whm3; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_HU_M4)][0] = whm4; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_HU_M5)][0] = whm5; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_HU_M6)][0] = whm6; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_HU_M7)][0] = whm7; } #ifdef USE_GPU @@ -536,104 +536,104 @@ void Smoms2D_feature::save_values_from_gpu_buffer( size_t offs = i * GpusideState::__COUNT__; const gpureal* ptrBuf = &intermediate_already_hostside.hobuffer[offs]; - fvals[(int)Nyxus::Feature2D::SPAT_MOMENT_00][0] = ptrBuf[GpusideState::RM00]; - fvals[(int)Nyxus::Feature2D::SPAT_MOMENT_01][0] = ptrBuf[GpusideState::RM01]; - fvals[(int)Nyxus::Feature2D::SPAT_MOMENT_02][0] = ptrBuf[GpusideState::RM02]; - fvals[(int)Nyxus::Feature2D::SPAT_MOMENT_03][0] = ptrBuf[GpusideState::RM03]; - fvals[(int)Nyxus::Feature2D::SPAT_MOMENT_10][0] = ptrBuf[GpusideState::RM10]; - fvals[(int)Nyxus::Feature2D::SPAT_MOMENT_11][0] = ptrBuf[GpusideState::RM11]; - fvals[(int)Nyxus::Feature2D::SPAT_MOMENT_12][0] = ptrBuf[GpusideState::RM12]; - fvals[(int)Nyxus::Feature2D::SPAT_MOMENT_13][0] = ptrBuf[GpusideState::RM13]; - fvals[(int)Nyxus::Feature2D::SPAT_MOMENT_20][0] = ptrBuf[GpusideState::RM20]; - fvals[(int)Nyxus::Feature2D::SPAT_MOMENT_21][0] = ptrBuf[GpusideState::RM21]; - fvals[(int)Nyxus::Feature2D::SPAT_MOMENT_22][0] = ptrBuf[GpusideState::RM22]; - fvals[(int)Nyxus::Feature2D::SPAT_MOMENT_23][0] = ptrBuf[GpusideState::RM23]; - fvals[(int)Nyxus::Feature2D::SPAT_MOMENT_30][0] = ptrBuf[GpusideState::RM30]; - - fvals[(int)Nyxus::Feature2D::CENTRAL_MOMENT_00][0] = ptrBuf[GpusideState::CM00]; - fvals[(int)Nyxus::Feature2D::CENTRAL_MOMENT_01][0] = ptrBuf[GpusideState::CM01]; - fvals[(int)Nyxus::Feature2D::CENTRAL_MOMENT_02][0] = ptrBuf[GpusideState::CM02]; - fvals[(int)Nyxus::Feature2D::CENTRAL_MOMENT_03][0] = ptrBuf[GpusideState::CM03]; - fvals[(int)Nyxus::Feature2D::CENTRAL_MOMENT_10][0] = ptrBuf[GpusideState::CM10]; - fvals[(int)Nyxus::Feature2D::CENTRAL_MOMENT_11][0] = ptrBuf[GpusideState::CM11]; - fvals[(int)Nyxus::Feature2D::CENTRAL_MOMENT_12][0] = ptrBuf[GpusideState::CM12]; - fvals[(int)Nyxus::Feature2D::CENTRAL_MOMENT_13][0] = ptrBuf[GpusideState::CM13]; - fvals[(int)Nyxus::Feature2D::CENTRAL_MOMENT_20][0] = ptrBuf[GpusideState::CM20]; - fvals[(int)Nyxus::Feature2D::CENTRAL_MOMENT_21][0] = ptrBuf[GpusideState::CM21]; - fvals[(int)Nyxus::Feature2D::CENTRAL_MOMENT_22][0] = ptrBuf[GpusideState::CM22]; - fvals[(int)Nyxus::Feature2D::CENTRAL_MOMENT_23][0] = ptrBuf[GpusideState::CM23]; - fvals[(int)Nyxus::Feature2D::CENTRAL_MOMENT_30][0] = ptrBuf[GpusideState::CM30]; - fvals[(int)Nyxus::Feature2D::CENTRAL_MOMENT_31][0] = ptrBuf[GpusideState::CM31]; - fvals[(int)Nyxus::Feature2D::CENTRAL_MOMENT_32][0] = ptrBuf[GpusideState::CM32]; - fvals[(int)Nyxus::Feature2D::CENTRAL_MOMENT_33][0] = ptrBuf[GpusideState::CM33]; - - fvals[(int)Nyxus::Feature2D::NORM_SPAT_MOMENT_00][0] = ptrBuf[GpusideState::W00]; - fvals[(int)Nyxus::Feature2D::NORM_SPAT_MOMENT_01][0] = ptrBuf[GpusideState::W01]; - fvals[(int)Nyxus::Feature2D::NORM_SPAT_MOMENT_02][0] = ptrBuf[GpusideState::W02]; - fvals[(int)Nyxus::Feature2D::NORM_SPAT_MOMENT_03][0] = ptrBuf[GpusideState::W03]; - fvals[(int)Nyxus::Feature2D::NORM_SPAT_MOMENT_10][0] = ptrBuf[GpusideState::W10]; - fvals[(int)Nyxus::Feature2D::NORM_SPAT_MOMENT_11][0] = ptrBuf[GpusideState::W11]; - fvals[(int)Nyxus::Feature2D::NORM_SPAT_MOMENT_12][0] = ptrBuf[GpusideState::W12]; - fvals[(int)Nyxus::Feature2D::NORM_SPAT_MOMENT_13][0] = ptrBuf[GpusideState::W13]; - fvals[(int)Nyxus::Feature2D::NORM_SPAT_MOMENT_20][0] = ptrBuf[GpusideState::W20]; - fvals[(int)Nyxus::Feature2D::NORM_SPAT_MOMENT_21][0] = ptrBuf[GpusideState::W21]; - fvals[(int)Nyxus::Feature2D::NORM_SPAT_MOMENT_22][0] = ptrBuf[GpusideState::W22]; - fvals[(int)Nyxus::Feature2D::NORM_SPAT_MOMENT_23][0] = ptrBuf[GpusideState::W23]; - fvals[(int)Nyxus::Feature2D::NORM_SPAT_MOMENT_30][0] = ptrBuf[GpusideState::W30]; - fvals[(int)Nyxus::Feature2D::NORM_SPAT_MOMENT_31][0] = ptrBuf[GpusideState::W31]; - fvals[(int)Nyxus::Feature2D::NORM_SPAT_MOMENT_32][0] = ptrBuf[GpusideState::W32]; - fvals[(int)Nyxus::Feature2D::NORM_SPAT_MOMENT_33][0] = ptrBuf[GpusideState::W33]; - - fvals[(int)Nyxus::Feature2D::NORM_CENTRAL_MOMENT_02][0] = ptrBuf[GpusideState::NU02]; - fvals[(int)Nyxus::Feature2D::NORM_CENTRAL_MOMENT_03][0] = ptrBuf[GpusideState::NU03]; - fvals[(int)Nyxus::Feature2D::NORM_CENTRAL_MOMENT_11][0] = ptrBuf[GpusideState::NU11]; - fvals[(int)Nyxus::Feature2D::NORM_CENTRAL_MOMENT_12][0] = ptrBuf[GpusideState::NU12]; - fvals[(int)Nyxus::Feature2D::NORM_CENTRAL_MOMENT_20][0] = ptrBuf[GpusideState::NU20]; - fvals[(int)Nyxus::Feature2D::NORM_CENTRAL_MOMENT_21][0] = ptrBuf[GpusideState::NU21]; - fvals[(int)Nyxus::Feature2D::NORM_CENTRAL_MOMENT_30][0] = ptrBuf[GpusideState::NU30]; - - fvals[(int)Nyxus::Feature2D::HU_M1][0] = ptrBuf[GpusideState::H1]; - fvals[(int)Nyxus::Feature2D::HU_M2][0] = ptrBuf[GpusideState::H2]; - fvals[(int)Nyxus::Feature2D::HU_M3][0] = ptrBuf[GpusideState::H3]; - fvals[(int)Nyxus::Feature2D::HU_M4][0] = ptrBuf[GpusideState::H4]; - fvals[(int)Nyxus::Feature2D::HU_M5][0] = ptrBuf[GpusideState::H5]; - fvals[(int)Nyxus::Feature2D::HU_M6][0] = ptrBuf[GpusideState::H6]; - fvals[(int)Nyxus::Feature2D::HU_M7][0] = ptrBuf[GpusideState::H7]; - - fvals[(int)Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_00][0] = ptrBuf[GpusideState::WRM00]; - fvals[(int)Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_01][0] = ptrBuf[GpusideState::WRM01]; - fvals[(int)Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_02][0] = ptrBuf[GpusideState::WRM02]; - fvals[(int)Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_03][0] = ptrBuf[GpusideState::WRM03]; - fvals[(int)Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_10][0] = ptrBuf[GpusideState::WRM10]; - fvals[(int)Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_11][0] = ptrBuf[GpusideState::WRM11]; - fvals[(int)Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_12][0] = ptrBuf[GpusideState::WRM12]; - fvals[(int)Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_20][0] = ptrBuf[GpusideState::WRM20]; - fvals[(int)Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_21][0] = ptrBuf[GpusideState::WRM21]; - fvals[(int)Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_30][0] = ptrBuf[GpusideState::WRM30]; - - fvals[(int)Nyxus::Feature2D::WEIGHTED_CENTRAL_MOMENT_02][0] = ptrBuf[GpusideState::WCM02]; - fvals[(int)Nyxus::Feature2D::WEIGHTED_CENTRAL_MOMENT_03][0] = ptrBuf[GpusideState::WCM03]; - fvals[(int)Nyxus::Feature2D::WEIGHTED_CENTRAL_MOMENT_11][0] = ptrBuf[GpusideState::WCM11]; - fvals[(int)Nyxus::Feature2D::WEIGHTED_CENTRAL_MOMENT_12][0] = ptrBuf[GpusideState::WCM12]; - fvals[(int)Nyxus::Feature2D::WEIGHTED_CENTRAL_MOMENT_20][0] = ptrBuf[GpusideState::WCM20]; - fvals[(int)Nyxus::Feature2D::WEIGHTED_CENTRAL_MOMENT_21][0] = ptrBuf[GpusideState::WCM21]; - fvals[(int)Nyxus::Feature2D::WEIGHTED_CENTRAL_MOMENT_30][0] = ptrBuf[GpusideState::WCM30]; - - fvals[(int)Nyxus::Feature2D::WT_NORM_CTR_MOM_02][0] = ptrBuf[GpusideState::WNU02]; - fvals[(int)Nyxus::Feature2D::WT_NORM_CTR_MOM_03][0] = ptrBuf[GpusideState::WNU03]; - fvals[(int)Nyxus::Feature2D::WT_NORM_CTR_MOM_11][0] = ptrBuf[GpusideState::WNU11]; - fvals[(int)Nyxus::Feature2D::WT_NORM_CTR_MOM_12][0] = ptrBuf[GpusideState::WNU12]; - fvals[(int)Nyxus::Feature2D::WT_NORM_CTR_MOM_20][0] = ptrBuf[GpusideState::WNU20]; - fvals[(int)Nyxus::Feature2D::WT_NORM_CTR_MOM_21][0] = ptrBuf[GpusideState::WNU21]; - fvals[(int)Nyxus::Feature2D::WT_NORM_CTR_MOM_30][0] = ptrBuf[GpusideState::WNU30]; - - fvals[(int)Nyxus::Feature2D::WEIGHTED_HU_M1][0] = ptrBuf[GpusideState::WH1]; - fvals[(int)Nyxus::Feature2D::WEIGHTED_HU_M2][0] = ptrBuf[GpusideState::WH2]; - fvals[(int)Nyxus::Feature2D::WEIGHTED_HU_M3][0] = ptrBuf[GpusideState::WH3]; - fvals[(int)Nyxus::Feature2D::WEIGHTED_HU_M4][0] = ptrBuf[GpusideState::WH4]; - fvals[(int)Nyxus::Feature2D::WEIGHTED_HU_M5][0] = ptrBuf[GpusideState::WH5]; - fvals[(int)Nyxus::Feature2D::WEIGHTED_HU_M6][0] = ptrBuf[GpusideState::WH6]; - fvals[(int)Nyxus::Feature2D::WEIGHTED_HU_M7][0] = ptrBuf[GpusideState::WH7]; + fvals[static_cast(Nyxus::Feature2D::SPAT_MOMENT_00)][0] = ptrBuf[GpusideState::RM00]; + fvals[static_cast(Nyxus::Feature2D::SPAT_MOMENT_01)][0] = ptrBuf[GpusideState::RM01]; + fvals[static_cast(Nyxus::Feature2D::SPAT_MOMENT_02)][0] = ptrBuf[GpusideState::RM02]; + fvals[static_cast(Nyxus::Feature2D::SPAT_MOMENT_03)][0] = ptrBuf[GpusideState::RM03]; + fvals[static_cast(Nyxus::Feature2D::SPAT_MOMENT_10)][0] = ptrBuf[GpusideState::RM10]; + fvals[static_cast(Nyxus::Feature2D::SPAT_MOMENT_11)][0] = ptrBuf[GpusideState::RM11]; + fvals[static_cast(Nyxus::Feature2D::SPAT_MOMENT_12)][0] = ptrBuf[GpusideState::RM12]; + fvals[static_cast(Nyxus::Feature2D::SPAT_MOMENT_13)][0] = ptrBuf[GpusideState::RM13]; + fvals[static_cast(Nyxus::Feature2D::SPAT_MOMENT_20)][0] = ptrBuf[GpusideState::RM20]; + fvals[static_cast(Nyxus::Feature2D::SPAT_MOMENT_21)][0] = ptrBuf[GpusideState::RM21]; + fvals[static_cast(Nyxus::Feature2D::SPAT_MOMENT_22)][0] = ptrBuf[GpusideState::RM22]; + fvals[static_cast(Nyxus::Feature2D::SPAT_MOMENT_23)][0] = ptrBuf[GpusideState::RM23]; + fvals[static_cast(Nyxus::Feature2D::SPAT_MOMENT_30)][0] = ptrBuf[GpusideState::RM30]; + + fvals[static_cast(Nyxus::Feature2D::CENTRAL_MOMENT_00)][0] = ptrBuf[GpusideState::CM00]; + fvals[static_cast(Nyxus::Feature2D::CENTRAL_MOMENT_01)][0] = ptrBuf[GpusideState::CM01]; + fvals[static_cast(Nyxus::Feature2D::CENTRAL_MOMENT_02)][0] = ptrBuf[GpusideState::CM02]; + fvals[static_cast(Nyxus::Feature2D::CENTRAL_MOMENT_03)][0] = ptrBuf[GpusideState::CM03]; + fvals[static_cast(Nyxus::Feature2D::CENTRAL_MOMENT_10)][0] = ptrBuf[GpusideState::CM10]; + fvals[static_cast(Nyxus::Feature2D::CENTRAL_MOMENT_11)][0] = ptrBuf[GpusideState::CM11]; + fvals[static_cast(Nyxus::Feature2D::CENTRAL_MOMENT_12)][0] = ptrBuf[GpusideState::CM12]; + fvals[static_cast(Nyxus::Feature2D::CENTRAL_MOMENT_13)][0] = ptrBuf[GpusideState::CM13]; + fvals[static_cast(Nyxus::Feature2D::CENTRAL_MOMENT_20)][0] = ptrBuf[GpusideState::CM20]; + fvals[static_cast(Nyxus::Feature2D::CENTRAL_MOMENT_21)][0] = ptrBuf[GpusideState::CM21]; + fvals[static_cast(Nyxus::Feature2D::CENTRAL_MOMENT_22)][0] = ptrBuf[GpusideState::CM22]; + fvals[static_cast(Nyxus::Feature2D::CENTRAL_MOMENT_23)][0] = ptrBuf[GpusideState::CM23]; + fvals[static_cast(Nyxus::Feature2D::CENTRAL_MOMENT_30)][0] = ptrBuf[GpusideState::CM30]; + fvals[static_cast(Nyxus::Feature2D::CENTRAL_MOMENT_31)][0] = ptrBuf[GpusideState::CM31]; + fvals[static_cast(Nyxus::Feature2D::CENTRAL_MOMENT_32)][0] = ptrBuf[GpusideState::CM32]; + fvals[static_cast(Nyxus::Feature2D::CENTRAL_MOMENT_33)][0] = ptrBuf[GpusideState::CM33]; + + fvals[static_cast(Nyxus::Feature2D::NORM_SPAT_MOMENT_00)][0] = ptrBuf[GpusideState::W00]; + fvals[static_cast(Nyxus::Feature2D::NORM_SPAT_MOMENT_01)][0] = ptrBuf[GpusideState::W01]; + fvals[static_cast(Nyxus::Feature2D::NORM_SPAT_MOMENT_02)][0] = ptrBuf[GpusideState::W02]; + fvals[static_cast(Nyxus::Feature2D::NORM_SPAT_MOMENT_03)][0] = ptrBuf[GpusideState::W03]; + fvals[static_cast(Nyxus::Feature2D::NORM_SPAT_MOMENT_10)][0] = ptrBuf[GpusideState::W10]; + fvals[static_cast(Nyxus::Feature2D::NORM_SPAT_MOMENT_11)][0] = ptrBuf[GpusideState::W11]; + fvals[static_cast(Nyxus::Feature2D::NORM_SPAT_MOMENT_12)][0] = ptrBuf[GpusideState::W12]; + fvals[static_cast(Nyxus::Feature2D::NORM_SPAT_MOMENT_13)][0] = ptrBuf[GpusideState::W13]; + fvals[static_cast(Nyxus::Feature2D::NORM_SPAT_MOMENT_20)][0] = ptrBuf[GpusideState::W20]; + fvals[static_cast(Nyxus::Feature2D::NORM_SPAT_MOMENT_21)][0] = ptrBuf[GpusideState::W21]; + fvals[static_cast(Nyxus::Feature2D::NORM_SPAT_MOMENT_22)][0] = ptrBuf[GpusideState::W22]; + fvals[static_cast(Nyxus::Feature2D::NORM_SPAT_MOMENT_23)][0] = ptrBuf[GpusideState::W23]; + fvals[static_cast(Nyxus::Feature2D::NORM_SPAT_MOMENT_30)][0] = ptrBuf[GpusideState::W30]; + fvals[static_cast(Nyxus::Feature2D::NORM_SPAT_MOMENT_31)][0] = ptrBuf[GpusideState::W31]; + fvals[static_cast(Nyxus::Feature2D::NORM_SPAT_MOMENT_32)][0] = ptrBuf[GpusideState::W32]; + fvals[static_cast(Nyxus::Feature2D::NORM_SPAT_MOMENT_33)][0] = ptrBuf[GpusideState::W33]; + + fvals[static_cast(Nyxus::Feature2D::NORM_CENTRAL_MOMENT_02)][0] = ptrBuf[GpusideState::NU02]; + fvals[static_cast(Nyxus::Feature2D::NORM_CENTRAL_MOMENT_03)][0] = ptrBuf[GpusideState::NU03]; + fvals[static_cast(Nyxus::Feature2D::NORM_CENTRAL_MOMENT_11)][0] = ptrBuf[GpusideState::NU11]; + fvals[static_cast(Nyxus::Feature2D::NORM_CENTRAL_MOMENT_12)][0] = ptrBuf[GpusideState::NU12]; + fvals[static_cast(Nyxus::Feature2D::NORM_CENTRAL_MOMENT_20)][0] = ptrBuf[GpusideState::NU20]; + fvals[static_cast(Nyxus::Feature2D::NORM_CENTRAL_MOMENT_21)][0] = ptrBuf[GpusideState::NU21]; + fvals[static_cast(Nyxus::Feature2D::NORM_CENTRAL_MOMENT_30)][0] = ptrBuf[GpusideState::NU30]; + + fvals[static_cast(Nyxus::Feature2D::HU_M1)][0] = ptrBuf[GpusideState::H1]; + fvals[static_cast(Nyxus::Feature2D::HU_M2)][0] = ptrBuf[GpusideState::H2]; + fvals[static_cast(Nyxus::Feature2D::HU_M3)][0] = ptrBuf[GpusideState::H3]; + fvals[static_cast(Nyxus::Feature2D::HU_M4)][0] = ptrBuf[GpusideState::H4]; + fvals[static_cast(Nyxus::Feature2D::HU_M5)][0] = ptrBuf[GpusideState::H5]; + fvals[static_cast(Nyxus::Feature2D::HU_M6)][0] = ptrBuf[GpusideState::H6]; + fvals[static_cast(Nyxus::Feature2D::HU_M7)][0] = ptrBuf[GpusideState::H7]; + + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_00)][0] = ptrBuf[GpusideState::WRM00]; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_01)][0] = ptrBuf[GpusideState::WRM01]; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_02)][0] = ptrBuf[GpusideState::WRM02]; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_03)][0] = ptrBuf[GpusideState::WRM03]; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_10)][0] = ptrBuf[GpusideState::WRM10]; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_11)][0] = ptrBuf[GpusideState::WRM11]; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_12)][0] = ptrBuf[GpusideState::WRM12]; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_20)][0] = ptrBuf[GpusideState::WRM20]; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_21)][0] = ptrBuf[GpusideState::WRM21]; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_SPAT_MOMENT_30)][0] = ptrBuf[GpusideState::WRM30]; + + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_CENTRAL_MOMENT_02)][0] = ptrBuf[GpusideState::WCM02]; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_CENTRAL_MOMENT_03)][0] = ptrBuf[GpusideState::WCM03]; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_CENTRAL_MOMENT_11)][0] = ptrBuf[GpusideState::WCM11]; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_CENTRAL_MOMENT_12)][0] = ptrBuf[GpusideState::WCM12]; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_CENTRAL_MOMENT_20)][0] = ptrBuf[GpusideState::WCM20]; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_CENTRAL_MOMENT_21)][0] = ptrBuf[GpusideState::WCM21]; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_CENTRAL_MOMENT_30)][0] = ptrBuf[GpusideState::WCM30]; + + fvals[static_cast(Nyxus::Feature2D::WT_NORM_CTR_MOM_02)][0] = ptrBuf[GpusideState::WNU02]; + fvals[static_cast(Nyxus::Feature2D::WT_NORM_CTR_MOM_03)][0] = ptrBuf[GpusideState::WNU03]; + fvals[static_cast(Nyxus::Feature2D::WT_NORM_CTR_MOM_11)][0] = ptrBuf[GpusideState::WNU11]; + fvals[static_cast(Nyxus::Feature2D::WT_NORM_CTR_MOM_12)][0] = ptrBuf[GpusideState::WNU12]; + fvals[static_cast(Nyxus::Feature2D::WT_NORM_CTR_MOM_20)][0] = ptrBuf[GpusideState::WNU20]; + fvals[static_cast(Nyxus::Feature2D::WT_NORM_CTR_MOM_21)][0] = ptrBuf[GpusideState::WNU21]; + fvals[static_cast(Nyxus::Feature2D::WT_NORM_CTR_MOM_30)][0] = ptrBuf[GpusideState::WNU30]; + + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_HU_M1)][0] = ptrBuf[GpusideState::WH1]; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_HU_M2)][0] = ptrBuf[GpusideState::WH2]; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_HU_M3)][0] = ptrBuf[GpusideState::WH3]; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_HU_M4)][0] = ptrBuf[GpusideState::WH4]; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_HU_M5)][0] = ptrBuf[GpusideState::WH5]; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_HU_M6)][0] = ptrBuf[GpusideState::WH6]; + fvals[static_cast(Nyxus::Feature2D::WEIGHTED_HU_M7)][0] = ptrBuf[GpusideState::WH7]; } } diff --git a/src/nyx/features/2d_geomoments.h b/src/nyx/features/2d_geomoments.h index 49d2b4a7a..72a1dda18 100644 --- a/src/nyx/features/2d_geomoments.h +++ b/src/nyx/features/2d_geomoments.h @@ -114,7 +114,7 @@ class Imoms2D_feature : public BasicGeomoms2D, public FeatureMethod { public: - const constexpr static std::initializer_list featureset = + static constexpr std::initializer_list featureset = { // -- intensity raw moments Nyxus::Feature2D::IMOM_RM_00, @@ -262,7 +262,7 @@ class Smoms2D_feature : public BasicGeomoms2D, public FeatureMethod { public: - const constexpr static std::initializer_list featureset = + static constexpr std::initializer_list featureset = { // Spatial (raw) moments Nyxus::Feature2D::SPAT_MOMENT_00, diff --git a/src/nyx/features/2d_geomoments_basic_nt.cpp b/src/nyx/features/2d_geomoments_basic_nt.cpp index bb39f4f20..c49372b25 100644 --- a/src/nyx/features/2d_geomoments_basic_nt.cpp +++ b/src/nyx/features/2d_geomoments_basic_nt.cpp @@ -31,7 +31,7 @@ void BasicGeomoms2D::osized_calculate (LR& r, const Fsettings& s, ImageLoader&) double dist = std::sqrt(mind2); // adjusted intensity - PixIntens wi = PixIntens((double)p.inten / (dist + weighting_epsilon)); + PixIntens wi = PixIntens(static_cast(p.inten )/ (dist + weighting_epsilon)); // save Pixel2 p_weighted = p; @@ -76,7 +76,7 @@ double BasicGeomoms2D::normRawMom(const pixcloud_NT& cloud, int p, int q) { double stddev = centralMom(cloud, 2, 2); int w = std::max(q, p); - double normCoef = pow(stddev, (double)w); + double normCoef = pow(stddev, static_cast(w)); double cmPQ = centralMom(cloud, p, q); double retval = cmPQ / normCoef; return retval; diff --git a/src/nyx/features/3d_glcm.cpp b/src/nyx/features/3d_glcm.cpp index 08ebb27fa..50a846e60 100644 --- a/src/nyx/features/3d_glcm.cpp +++ b/src/nyx/features/3d_glcm.cpp @@ -113,66 +113,66 @@ void D3_GLCM_feature::copyfvals(AngledFeatures& dst, const AngledFeatures& src) void D3_GLCM_feature::save_value(std::vector>& fvals) { - copyfvals(fvals[(int)Feature3D::GLCM_ASM], fvals_ASM); - copyfvals(fvals[(int)Feature3D::GLCM_ACOR], fvals_acor); - copyfvals(fvals[(int)Feature3D::GLCM_CLUPROM], fvals_cluprom); - copyfvals(fvals[(int)Feature3D::GLCM_CLUSHADE], fvals_clushade); - copyfvals(fvals[(int)Feature3D::GLCM_CLUTEND], fvals_clutend); - copyfvals(fvals[(int)Feature3D::GLCM_CONTRAST], fvals_contrast); - copyfvals(fvals[(int)Feature3D::GLCM_CORRELATION], fvals_correlation); - copyfvals(fvals[(int)Feature3D::GLCM_DIFAVE], fvals_diff_avg); - copyfvals(fvals[(int)Feature3D::GLCM_DIFVAR], fvals_diff_var); - copyfvals(fvals[(int)Feature3D::GLCM_DIFENTRO], fvals_diff_entropy); - copyfvals(fvals[(int)Feature3D::GLCM_DIS], fvals_dis); - copyfvals(fvals[(int)Feature3D::GLCM_ENERGY], fvals_energy); - copyfvals(fvals[(int)Feature3D::GLCM_ENTROPY], fvals_entropy); - copyfvals(fvals[(int)Feature3D::GLCM_HOM1], fvals_homo); - copyfvals(fvals[(int)Feature3D::GLCM_HOM2], fvals_hom2); - copyfvals(fvals[(int)Feature3D::GLCM_ID], fvals_id); - copyfvals(fvals[(int)Feature3D::GLCM_IDN], fvals_idn); - copyfvals(fvals[(int)Feature3D::GLCM_IDM], fvals_IDM); - copyfvals(fvals[(int)Feature3D::GLCM_IDMN], fvals_idmn); - copyfvals(fvals[(int)Feature3D::GLCM_INFOMEAS1], fvals_meas_corr1); - copyfvals(fvals[(int)Feature3D::GLCM_INFOMEAS2], fvals_meas_corr2); - copyfvals(fvals[(int)Feature3D::GLCM_IV], fvals_iv); - copyfvals(fvals[(int)Feature3D::GLCM_JAVE], fvals_jave); - copyfvals(fvals[(int)Feature3D::GLCM_JE], fvals_je); - copyfvals(fvals[(int)Feature3D::GLCM_JMAX], fvals_jmax); - copyfvals(fvals[(int)Feature3D::GLCM_JVAR], fvals_jvar); - copyfvals(fvals[(int)Feature3D::GLCM_SUMAVERAGE], fvals_sum_avg); - copyfvals(fvals[(int)Feature3D::GLCM_SUMVARIANCE], fvals_sum_var); - copyfvals(fvals[(int)Feature3D::GLCM_SUMENTROPY], fvals_sum_entropy); - copyfvals(fvals[(int)Feature3D::GLCM_VARIANCE], fvals_variance); - - fvals[(int)Feature3D::GLCM_ASM_AVE][0] = calc_ave(fvals_ASM); - fvals[(int)Feature3D::GLCM_ACOR_AVE][0] = calc_ave(fvals_acor); - fvals[(int)Feature3D::GLCM_CLUPROM_AVE][0] = calc_ave(fvals_cluprom); - fvals[(int)Feature3D::GLCM_CLUSHADE_AVE][0] = calc_ave(fvals_clushade); - fvals[(int)Feature3D::GLCM_CLUTEND_AVE][0] = calc_ave(fvals_clutend); - fvals[(int)Feature3D::GLCM_CONTRAST_AVE][0] = calc_ave(fvals_contrast); - fvals[(int)Feature3D::GLCM_CORRELATION_AVE][0] = calc_ave(fvals_correlation); - fvals[(int)Feature3D::GLCM_DIFAVE_AVE][0] = calc_ave(fvals_diff_avg); - fvals[(int)Feature3D::GLCM_DIFVAR_AVE][0] = calc_ave(fvals_diff_var); - fvals[(int)Feature3D::GLCM_DIFENTRO_AVE][0] = calc_ave(fvals_diff_entropy); - fvals[(int)Feature3D::GLCM_DIS_AVE][0] = calc_ave(fvals_dis); - fvals[(int)Feature3D::GLCM_ENERGY_AVE][0] = calc_ave(fvals_energy); - fvals[(int)Feature3D::GLCM_ENTROPY_AVE][0] = calc_ave(fvals_entropy); - fvals[(int)Feature3D::GLCM_HOM1_AVE][0] = calc_ave(fvals_homo); - fvals[(int)Feature3D::GLCM_ID_AVE][0] = calc_ave(fvals_id); - fvals[(int)Feature3D::GLCM_IDN_AVE][0] = calc_ave(fvals_idn); - fvals[(int)Feature3D::GLCM_IDM_AVE][0] = calc_ave(fvals_IDM); - fvals[(int)Feature3D::GLCM_IDMN_AVE][0] = calc_ave(fvals_idmn); - fvals[(int)Feature3D::GLCM_IV_AVE][0] = calc_ave(fvals_iv); - fvals[(int)Feature3D::GLCM_JAVE_AVE][0] = calc_ave(fvals_jave); - fvals[(int)Feature3D::GLCM_JE_AVE][0] = calc_ave(fvals_je); - fvals[(int)Feature3D::GLCM_INFOMEAS1_AVE][0] = calc_ave(fvals_meas_corr1); - fvals[(int)Feature3D::GLCM_INFOMEAS2_AVE][0] = calc_ave(fvals_meas_corr2); - fvals[(int)Feature3D::GLCM_VARIANCE_AVE][0] = calc_ave(fvals_variance); - fvals[(int)Feature3D::GLCM_JMAX_AVE][0] = calc_ave(fvals_jmax); - fvals[(int)Feature3D::GLCM_JVAR_AVE][0] = calc_ave(fvals_jvar); - fvals[(int)Feature3D::GLCM_SUMAVERAGE_AVE][0] = calc_ave(fvals_sum_avg); - fvals[(int)Feature3D::GLCM_SUMVARIANCE_AVE][0] = calc_ave(fvals_sum_var); - fvals[(int)Feature3D::GLCM_SUMENTROPY_AVE][0] = calc_ave(fvals_sum_entropy); + copyfvals(fvals[static_cast(Feature3D::GLCM_ASM)], fvals_ASM); + copyfvals(fvals[static_cast(Feature3D::GLCM_ACOR)], fvals_acor); + copyfvals(fvals[static_cast(Feature3D::GLCM_CLUPROM)], fvals_cluprom); + copyfvals(fvals[static_cast(Feature3D::GLCM_CLUSHADE)], fvals_clushade); + copyfvals(fvals[static_cast(Feature3D::GLCM_CLUTEND)], fvals_clutend); + copyfvals(fvals[static_cast(Feature3D::GLCM_CONTRAST)], fvals_contrast); + copyfvals(fvals[static_cast(Feature3D::GLCM_CORRELATION)], fvals_correlation); + copyfvals(fvals[static_cast(Feature3D::GLCM_DIFAVE)], fvals_diff_avg); + copyfvals(fvals[static_cast(Feature3D::GLCM_DIFVAR)], fvals_diff_var); + copyfvals(fvals[static_cast(Feature3D::GLCM_DIFENTRO)], fvals_diff_entropy); + copyfvals(fvals[static_cast(Feature3D::GLCM_DIS)], fvals_dis); + copyfvals(fvals[static_cast(Feature3D::GLCM_ENERGY)], fvals_energy); + copyfvals(fvals[static_cast(Feature3D::GLCM_ENTROPY)], fvals_entropy); + copyfvals(fvals[static_cast(Feature3D::GLCM_HOM1)], fvals_homo); + copyfvals(fvals[static_cast(Feature3D::GLCM_HOM2)], fvals_hom2); + copyfvals(fvals[static_cast(Feature3D::GLCM_ID)], fvals_id); + copyfvals(fvals[static_cast(Feature3D::GLCM_IDN)], fvals_idn); + copyfvals(fvals[static_cast(Feature3D::GLCM_IDM)], fvals_IDM); + copyfvals(fvals[static_cast(Feature3D::GLCM_IDMN)], fvals_idmn); + copyfvals(fvals[static_cast(Feature3D::GLCM_INFOMEAS1)], fvals_meas_corr1); + copyfvals(fvals[static_cast(Feature3D::GLCM_INFOMEAS2)], fvals_meas_corr2); + copyfvals(fvals[static_cast(Feature3D::GLCM_IV)], fvals_iv); + copyfvals(fvals[static_cast(Feature3D::GLCM_JAVE)], fvals_jave); + copyfvals(fvals[static_cast(Feature3D::GLCM_JE)], fvals_je); + copyfvals(fvals[static_cast(Feature3D::GLCM_JMAX)], fvals_jmax); + copyfvals(fvals[static_cast(Feature3D::GLCM_JVAR)], fvals_jvar); + copyfvals(fvals[static_cast(Feature3D::GLCM_SUMAVERAGE)], fvals_sum_avg); + copyfvals(fvals[static_cast(Feature3D::GLCM_SUMVARIANCE)], fvals_sum_var); + copyfvals(fvals[static_cast(Feature3D::GLCM_SUMENTROPY)], fvals_sum_entropy); + copyfvals(fvals[static_cast(Feature3D::GLCM_VARIANCE)], fvals_variance); + + fvals[static_cast(Feature3D::GLCM_ASM_AVE)][0] = calc_ave(fvals_ASM); + fvals[static_cast(Feature3D::GLCM_ACOR_AVE)][0] = calc_ave(fvals_acor); + fvals[static_cast(Feature3D::GLCM_CLUPROM_AVE)][0] = calc_ave(fvals_cluprom); + fvals[static_cast(Feature3D::GLCM_CLUSHADE_AVE)][0] = calc_ave(fvals_clushade); + fvals[static_cast(Feature3D::GLCM_CLUTEND_AVE)][0] = calc_ave(fvals_clutend); + fvals[static_cast(Feature3D::GLCM_CONTRAST_AVE)][0] = calc_ave(fvals_contrast); + fvals[static_cast(Feature3D::GLCM_CORRELATION_AVE)][0] = calc_ave(fvals_correlation); + fvals[static_cast(Feature3D::GLCM_DIFAVE_AVE)][0] = calc_ave(fvals_diff_avg); + fvals[static_cast(Feature3D::GLCM_DIFVAR_AVE)][0] = calc_ave(fvals_diff_var); + fvals[static_cast(Feature3D::GLCM_DIFENTRO_AVE)][0] = calc_ave(fvals_diff_entropy); + fvals[static_cast(Feature3D::GLCM_DIS_AVE)][0] = calc_ave(fvals_dis); + fvals[static_cast(Feature3D::GLCM_ENERGY_AVE)][0] = calc_ave(fvals_energy); + fvals[static_cast(Feature3D::GLCM_ENTROPY_AVE)][0] = calc_ave(fvals_entropy); + fvals[static_cast(Feature3D::GLCM_HOM1_AVE)][0] = calc_ave(fvals_homo); + fvals[static_cast(Feature3D::GLCM_ID_AVE)][0] = calc_ave(fvals_id); + fvals[static_cast(Feature3D::GLCM_IDN_AVE)][0] = calc_ave(fvals_idn); + fvals[static_cast(Feature3D::GLCM_IDM_AVE)][0] = calc_ave(fvals_IDM); + fvals[static_cast(Feature3D::GLCM_IDMN_AVE)][0] = calc_ave(fvals_idmn); + fvals[static_cast(Feature3D::GLCM_IV_AVE)][0] = calc_ave(fvals_iv); + fvals[static_cast(Feature3D::GLCM_JAVE_AVE)][0] = calc_ave(fvals_jave); + fvals[static_cast(Feature3D::GLCM_JE_AVE)][0] = calc_ave(fvals_je); + fvals[static_cast(Feature3D::GLCM_INFOMEAS1_AVE)][0] = calc_ave(fvals_meas_corr1); + fvals[static_cast(Feature3D::GLCM_INFOMEAS2_AVE)][0] = calc_ave(fvals_meas_corr2); + fvals[static_cast(Feature3D::GLCM_VARIANCE_AVE)][0] = calc_ave(fvals_variance); + fvals[static_cast(Feature3D::GLCM_JMAX_AVE)][0] = calc_ave(fvals_jmax); + fvals[static_cast(Feature3D::GLCM_JVAR_AVE)][0] = calc_ave(fvals_jvar); + fvals[static_cast(Feature3D::GLCM_SUMAVERAGE_AVE)][0] = calc_ave(fvals_sum_avg); + fvals[static_cast(Feature3D::GLCM_SUMVARIANCE_AVE)][0] = calc_ave(fvals_sum_var); + fvals[static_cast(Feature3D::GLCM_SUMENTROPY_AVE)][0] = calc_ave(fvals_sum_entropy); //xxxx deprecated in PyR xxxx fvals[(int)Feature3D::GLCM_VARIANCE_AVE][0] = calc_ave(fvals_variance); } @@ -291,7 +291,7 @@ void D3_GLCM_feature::calculateCoocMatAtAngle( I.assign(U.begin(), U.end()); std::sort(I.begin(), I.end()); - GLCM.allocate((int)I.size(), (int)I.size()); + GLCM.allocate(static_cast(I.size()), static_cast(I.size())); } else if (matlab_grey_binning(greyInfo)) @@ -819,7 +819,7 @@ double D3_GLCM_feature::f_homogeneity() for (int r = 0; r < Ng; r++) for (int c = 0; c < Ng; c++) - homogeneity += P_matrix.yx(r, c) / sum_p / (1.0 + (double)std::abs(r - c)); + homogeneity += P_matrix.yx(r, c) / sum_p / (1.0 + static_cast(std::abs(r - c))); return homogeneity; } @@ -834,10 +834,10 @@ double D3_GLCM_feature::f_GLCM_ACOR(const SimpleMatrix& P) for (int x = 0; x < Ng; x++) { - double xval = (double)I[x]; + double xval = static_cast(I[x]); for (int y = 0; y < Ng; y++) { - double yval = (double)I[y]; + double yval = static_cast(I[y]); f += P.xy(x, y) * xval * yval; } } @@ -940,7 +940,7 @@ double D3_GLCM_feature::f_GLCM_HOM2(const SimpleMatrix& P_matrix) for (int y = 0; y < n_levels; y++) // FIX: normalize by sum_p (joint probability), matching f_idm/f_GLCM_JE. Was summing the // UNNORMALIZED co-occurrence counts -> homogeneity > 1 (same bug as 2D glcm.cpp). - hom2 += (P_matrix.xy(x, y) / sum_p) / (1.0 + (double)std::abs(x - y) * (double)std::abs(x - y)); + hom2 += (P_matrix.xy(x, y) / sum_p) / (1.0 + static_cast(std::abs(x - y) )* static_cast(std::abs(x - y))); return hom2; } diff --git a/src/nyx/features/3d_glcm.h b/src/nyx/features/3d_glcm.h index 82c7290ea..8def46192 100644 --- a/src/nyx/features/3d_glcm.h +++ b/src/nyx/features/3d_glcm.h @@ -14,7 +14,7 @@ class D3_GLCM_feature : public FeatureMethod, public TextureFeature // Codes of features implemented by this class. Used in feature manager's mechanisms, // in the feature group nickname expansion, and in the feature value output - const constexpr static std::initializer_list featureset = + static constexpr std::initializer_list featureset = { Nyxus::Feature3D::GLCM_ACOR, // Autocorrelation, IBSI # QWB0 Nyxus::Feature3D::GLCM_ASM, // Angular second moment IBSI # 8ZQL @@ -78,7 +78,7 @@ class D3_GLCM_feature : public FeatureMethod, public TextureFeature }; // Features implemented by this class that do not require vector-like angled output. Instead, they are output as a single values - const constexpr static std::initializer_list nonAngledFeatures = + static constexpr std::initializer_list nonAngledFeatures = { Nyxus::Feature3D::GLCM_ASM_AVE, Nyxus::Feature3D::GLCM_ACOR_AVE, @@ -164,7 +164,7 @@ class D3_GLCM_feature : public FeatureMethod, public TextureFeature static inline int cast_to_range(PixIntens orig_I, PixIntens min_orig_I, PixIntens max_orig_I, int min_target_I, int max_target_I) { - int target_I = (int)(double(orig_I - min_orig_I) / double(max_orig_I - min_orig_I) * double(max_target_I - min_target_I) + min_target_I); + int target_I = static_cast((double(orig_I - min_orig_I) / double(max_orig_I - min_orig_I) * double(max_target_I - min_target_I) + min_target_I)); return target_I; } diff --git a/src/nyx/features/3d_gldm.cpp b/src/nyx/features/3d_gldm.cpp index 663b2d4fb..8a0d1a9b3 100644 --- a/src/nyx/features/3d_gldm.cpp +++ b/src/nyx/features/3d_gldm.cpp @@ -150,7 +150,7 @@ void D3_GLDM_feature::calculate (LR& r, const Fsettings& s) } //==== Fill the matrix - Ng = greyInfo == 0 ? *std::max_element(I.begin(), I.end()) : (int)I.size(); + Ng = greyInfo == 0 ? *std::max_element(I.begin(), I.end()) : static_cast(I.size()); Nd = nsh + 1; // (z +1, 0, -1) * (xy N, NE, E, SE, S, SW, W, NW) + zero // --allocate the matrix @@ -251,20 +251,20 @@ void D3_GLDM_feature::osized_calculate(LR& r, const Fsettings& s, ImageLoader&) void D3_GLDM_feature::save_value(std::vector>& fvals) { - fvals[(int)Feature3D::GLDM_SDE][0] = fv_SDE; - fvals[(int)Feature3D::GLDM_LDE][0] = fv_LDE; - fvals[(int)Feature3D::GLDM_GLN][0] = fv_GLN; - fvals[(int)Feature3D::GLDM_DN][0] = fv_DN; - fvals[(int)Feature3D::GLDM_DNN][0] = fv_DNN; - fvals[(int)Feature3D::GLDM_GLV][0] = fv_GLV; - fvals[(int)Feature3D::GLDM_DV][0] = fv_DV; - fvals[(int)Feature3D::GLDM_DE][0] = fv_DE; - fvals[(int)Feature3D::GLDM_LGLE][0] = fv_LGLE; - fvals[(int)Feature3D::GLDM_HGLE][0] = fv_HGLE; - fvals[(int)Feature3D::GLDM_SDLGLE][0] = fv_SDLGLE; - fvals[(int)Feature3D::GLDM_SDHGLE][0] = fv_SDHGLE; - fvals[(int)Feature3D::GLDM_LDLGLE][0] = fv_LDLGLE; - fvals[(int)Feature3D::GLDM_LDHGLE][0] = fv_LDHGLE; + fvals[static_cast(Feature3D::GLDM_SDE)][0] = fv_SDE; + fvals[static_cast(Feature3D::GLDM_LDE)][0] = fv_LDE; + fvals[static_cast(Feature3D::GLDM_GLN)][0] = fv_GLN; + fvals[static_cast(Feature3D::GLDM_DN)][0] = fv_DN; + fvals[static_cast(Feature3D::GLDM_DNN)][0] = fv_DNN; + fvals[static_cast(Feature3D::GLDM_GLV)][0] = fv_GLV; + fvals[static_cast(Feature3D::GLDM_DV)][0] = fv_DV; + fvals[static_cast(Feature3D::GLDM_DE)][0] = fv_DE; + fvals[static_cast(Feature3D::GLDM_LGLE)][0] = fv_LGLE; + fvals[static_cast(Feature3D::GLDM_HGLE)][0] = fv_HGLE; + fvals[static_cast(Feature3D::GLDM_SDLGLE)][0] = fv_SDLGLE; + fvals[static_cast(Feature3D::GLDM_SDHGLE)][0] = fv_SDHGLE; + fvals[static_cast(Feature3D::GLDM_LDLGLE)][0] = fv_LDLGLE; + fvals[static_cast(Feature3D::GLDM_LDHGLE)][0] = fv_LDHGLE; } // 1. Small Dependence Emphasis(SDE) @@ -363,7 +363,7 @@ double D3_GLDM_feature::calc_GLV() double mu = 0.0; for (int i = 1; i <= Ng; i++) { - double inten = (double)I[i - 1]; + double inten = static_cast(I[i - 1]); for (int j = 1; j <= Nd; j++) { mu += P.matlab(i, j) / double(Nz) * inten; @@ -373,7 +373,7 @@ double D3_GLDM_feature::calc_GLV() double f = 0.0; for (int i = 1; i <= Ng; i++) { - double inten = (double)I[i - 1]; + double inten = static_cast(I[i - 1]); for (int j = 1; j <= Nd; j++) { double mu2 = (inten - mu) * (inten - mu); @@ -430,7 +430,7 @@ double D3_GLDM_feature::calc_LGLE() double sum_i = 0; for (int i = 1; i <= Ng; i++) { - double inten2 = (double)I[i - 1]; + double inten2 = static_cast(I[i - 1]); inten2 *= inten2; double sum_j = 0; for (int j = 1; j <= Nd; j++) @@ -457,7 +457,7 @@ double D3_GLDM_feature::calc_HGLE() double f = 0.0; for (int i = 1; i <= Ng; i++) { - double inten = (double)I[i - 1]; + double inten = static_cast(I[i - 1]); f += si[i - 1] * inten * inten; } @@ -471,7 +471,7 @@ double D3_GLDM_feature::calc_SDLGLE() double f = 0.0; for (int i = 1; i <= Ng; i++) { - double inten = (double)I[i - 1]; + double inten = static_cast(I[i - 1]); for (int j = 1; j <= Nd; j++) { f += P.matlab(i, j) / double(inten * inten * j * j); @@ -487,7 +487,7 @@ double D3_GLDM_feature::calc_SDHGLE() double f = 0.0; for (int i = 1; i <= Ng; i++) { - double inten = (double)I[i - 1]; + double inten = static_cast(I[i - 1]); for (int j = 1; j <= Nd; j++) { f += P.matlab(i, j) * (inten * inten) / double(j * j); @@ -503,7 +503,7 @@ double D3_GLDM_feature::calc_LDLGLE() double f = 0.0; for (int i = 1; i <= Ng; i++) { - double inten = (double)I[i - 1]; + double inten = static_cast(I[i - 1]); for (int j = 1; j <= Nd; j++) { f += P.matlab(i, j) * double(j * j) / (inten * inten); @@ -519,7 +519,7 @@ double D3_GLDM_feature::calc_LDHGLE() double f = 0.0; for (int i = 1; i <= Ng; i++) { - double inten = (double)I[i - 1]; + double inten = static_cast(I[i - 1]); for (int j = 1; j <= Nd; j++) { f += P.matlab(i, j) * double(inten * inten * j * j); diff --git a/src/nyx/features/3d_gldm.h b/src/nyx/features/3d_gldm.h index f57df54c9..cc7afcf09 100644 --- a/src/nyx/features/3d_gldm.h +++ b/src/nyx/features/3d_gldm.h @@ -19,7 +19,7 @@ class D3_GLDM_feature : public FeatureMethod, public TextureFeature // Codes of features implemented by this class. Used in feature manager's mechanisms, // in the feature group nickname expansion, and in the feature value output - const constexpr static std::initializer_list featureset = + static constexpr std::initializer_list featureset = { Nyxus::Feature3D::GLDM_SDE, // Small Dependence Emphasis Nyxus::Feature3D::GLDM_LDE, // Large Dependence Emphasis diff --git a/src/nyx/features/3d_gldzm.cpp b/src/nyx/features/3d_gldzm.cpp index 6fda05530..9b510d49a 100644 --- a/src/nyx/features/3d_gldzm.cpp +++ b/src/nyx/features/3d_gldzm.cpp @@ -293,7 +293,7 @@ void D3_GLDZM_feature::prepare_GLDZM_matrix_kit (SimpleMatrix& GLD //==== Fill the zonal metric matrix // -- number of discrete intensity values in the image - Ng = (int)I.size(); + Ng = static_cast(I.size()); // -- max zone distance to ROI or image border Nd = 0; @@ -319,7 +319,7 @@ void D3_GLDZM_feature::calc_gldzm_matrix (SimpleMatrix& GLDZM, con { // row. Gray tones are sparse so we need to find indices of tones in 'Z' and use them as rows of P-matrix auto iter = std::find(I.begin(), I.end(), std::get<0>(z)); - int row = (int)(iter - I.begin()); + int row = static_cast((iter - I.begin())); // column (a distance). Distances are dense \in [1,Nd] int col = std::get<1>(z) - 1; // 0-based => -1 auto& k = GLDZM.yx(row, col); @@ -421,7 +421,7 @@ template void D3_GLDZM_feature::calc_features (const std::vecto for (int d_ = 0; d_ < Nd; d_++) { - double d = (double)(d_ + 1); + double d = static_cast((d_ + 1)); double m = Md[d_]; f_SDE += m / d / d; // Small Distance Emphasis = \frac{1}{N_s} \sum_d \frac{m_d}{d^2} f_LDE += d * d * m; // Large Distance Emphasis = \frac{1}{N_s} \sum_d d^2 m_d @@ -440,7 +440,7 @@ template void D3_GLDZM_feature::calc_features (const std::vecto if (greysLUT[g] == 0) continue; - double g_ = (double)greysLUT[g]; + double g_ = static_cast(greysLUT[g]); double x = Mx[g]; f_LGLZE += x / (g_ * g_); // Low Grey Level Emphasis = \frac{1}{N_s} \sum_x \frac{m_x}{x^2} f_HGLZE += (g_ * g_) * x; // High Grey Level Emphasis = \frac{1}{N_s} \sum_x x^2 m_x @@ -458,7 +458,7 @@ template void D3_GLDZM_feature::calc_features (const std::vecto if (greysLUT[g] == 0) continue; - double g_ = (double)greysLUT[g], + double g_ = static_cast(greysLUT[g]), d_ = double(d + 1); double p = P.yx(g, d); f_SDLGLE += p / g_ / g_ / d_ / d_; // Small Distance Low Grey Level Emphasis = \frac{1}{N_s} \sum_x \sum_d \frac{ m_{x,d}}{x^2 d^2} @@ -490,12 +490,12 @@ template void D3_GLDZM_feature::calc_features (const std::vecto // Grey Level Variance = \sum_x \sum_d \left(x - \mu_x \right)^2 p_{x,d} double p = P.yx(g, d) / Ns, - x = (double)greysLUT[g], + x = static_cast(greysLUT[g]), dif = x - f_GLM; f_GLV += dif * dif * p; // Zone Distance Variance} = \sum_x \sum_d \left(d - \mu_d \right)^2 p_{x,d} - double d_ = (double)(d + 1); + double d_ = static_cast((d + 1)); dif = d_ - f_ZDM; f_ZDV += dif * dif * p; } @@ -549,24 +549,24 @@ void D3_GLDZM_feature::calculate (LR& r, const Fsettings& s) void D3_GLDZM_feature::save_value (std::vector> & fvals) { - fvals[(int)Nyxus::Feature3D::GLDZM_SDE][0] = f_SDE; - fvals[(int)Nyxus::Feature3D::GLDZM_LDE][0] = f_LDE; - fvals[(int)Nyxus::Feature3D::GLDZM_LGLZE][0] = f_LGLZE; - fvals[(int)Nyxus::Feature3D::GLDZM_HGLZE][0] = f_HGLZE; - fvals[(int)Nyxus::Feature3D::GLDZM_SDLGLE][0] = f_SDLGLE; - fvals[(int)Nyxus::Feature3D::GLDZM_SDHGLE][0] = f_SDHGLE; - fvals[(int)Nyxus::Feature3D::GLDZM_LDLGLE][0] = f_LDLGLE; - fvals[(int)Nyxus::Feature3D::GLDZM_LDHGLE][0] = f_LDHGLE; - fvals[(int)Nyxus::Feature3D::GLDZM_GLNU][0] = f_GLNU; - fvals[(int)Nyxus::Feature3D::GLDZM_GLNUN][0] = f_GLNUN; - fvals[(int)Nyxus::Feature3D::GLDZM_ZDNU][0] = f_ZDNU; - fvals[(int)Nyxus::Feature3D::GLDZM_ZDNUN][0] = f_ZDNUN; - fvals[(int)Nyxus::Feature3D::GLDZM_ZP][0] = f_ZP; - fvals[(int)Nyxus::Feature3D::GLDZM_GLM][0] = f_GLM; - fvals[(int)Nyxus::Feature3D::GLDZM_GLV][0] = f_GLV; - fvals[(int)Nyxus::Feature3D::GLDZM_ZDM][0] = f_ZDM; - fvals[(int)Nyxus::Feature3D::GLDZM_ZDV][0] = f_ZDV; - fvals[(int)Nyxus::Feature3D::GLDZM_ZDE][0] = f_ZDE; + fvals[static_cast(Nyxus::Feature3D::GLDZM_SDE)][0] = f_SDE; + fvals[static_cast(Nyxus::Feature3D::GLDZM_LDE)][0] = f_LDE; + fvals[static_cast(Nyxus::Feature3D::GLDZM_LGLZE)][0] = f_LGLZE; + fvals[static_cast(Nyxus::Feature3D::GLDZM_HGLZE)][0] = f_HGLZE; + fvals[static_cast(Nyxus::Feature3D::GLDZM_SDLGLE)][0] = f_SDLGLE; + fvals[static_cast(Nyxus::Feature3D::GLDZM_SDHGLE)][0] = f_SDHGLE; + fvals[static_cast(Nyxus::Feature3D::GLDZM_LDLGLE)][0] = f_LDLGLE; + fvals[static_cast(Nyxus::Feature3D::GLDZM_LDHGLE)][0] = f_LDHGLE; + fvals[static_cast(Nyxus::Feature3D::GLDZM_GLNU)][0] = f_GLNU; + fvals[static_cast(Nyxus::Feature3D::GLDZM_GLNUN)][0] = f_GLNUN; + fvals[static_cast(Nyxus::Feature3D::GLDZM_ZDNU)][0] = f_ZDNU; + fvals[static_cast(Nyxus::Feature3D::GLDZM_ZDNUN)][0] = f_ZDNUN; + fvals[static_cast(Nyxus::Feature3D::GLDZM_ZP)][0] = f_ZP; + fvals[static_cast(Nyxus::Feature3D::GLDZM_GLM)][0] = f_GLM; + fvals[static_cast(Nyxus::Feature3D::GLDZM_GLV)][0] = f_GLV; + fvals[static_cast(Nyxus::Feature3D::GLDZM_ZDM)][0] = f_ZDM; + fvals[static_cast(Nyxus::Feature3D::GLDZM_ZDV)][0] = f_ZDV; + fvals[static_cast(Nyxus::Feature3D::GLDZM_ZDE)][0] = f_ZDE; } void D3_GLDZM_feature::osized_add_online_pixel (size_t x, size_t y, uint32_t intensity) {} diff --git a/src/nyx/features/3d_gldzm.h b/src/nyx/features/3d_gldzm.h index ddb0df478..a8c8239f6 100644 --- a/src/nyx/features/3d_gldzm.h +++ b/src/nyx/features/3d_gldzm.h @@ -14,7 +14,7 @@ class D3_GLDZM_feature : public FeatureMethod, public TextureFeature public: // features implemented by this class - const constexpr static std::initializer_list featureset = + static constexpr std::initializer_list featureset = { Nyxus::Feature3D::GLDZM_SDE, // Small Distance Emphasis Nyxus::Feature3D::GLDZM_LDE, // Large Distance Emphasis diff --git a/src/nyx/features/3d_glrlm.cpp b/src/nyx/features/3d_glrlm.cpp index b52e2eb74..cb3be6946 100644 --- a/src/nyx/features/3d_glrlm.cpp +++ b/src/nyx/features/3d_glrlm.cpp @@ -190,7 +190,7 @@ void D3_GLRLM_feature::calculate (LR& r, const Fsettings& s) int Ng = STNGS_IBSI(s) ? *std::max_element(I.begin(), I.end()) : I.size(); int Nr = maxZoneArea; - int Nz = (int) Zones.size(); + int Nz = static_cast(Zones.size()); size_t Np = r.raw_pixels_3D.size(); // --allocate the matrix @@ -286,40 +286,40 @@ void D3_GLRLM_feature::osized_add_online_pixel(size_t x, size_t y, uint32_t inte void D3_GLRLM_feature::save_value(std::vector>& fvals) { - fvals[(int)Feature3D::GLRLM_SRE] = angled_SRE; - fvals[(int)Feature3D::GLRLM_LRE] = angled_LRE; - fvals[(int)Feature3D::GLRLM_GLN] = angled_GLN; - fvals[(int)Feature3D::GLRLM_GLNN] = angled_GLNN; - fvals[(int)Feature3D::GLRLM_RLN] = angled_RLN; - fvals[(int)Feature3D::GLRLM_RLNN] = angled_RLNN; - fvals[(int)Feature3D::GLRLM_RP] = angled_RP; - fvals[(int)Feature3D::GLRLM_GLV] = angled_GLV; - fvals[(int)Feature3D::GLRLM_RV] = angled_RV; - fvals[(int)Feature3D::GLRLM_RE] = angled_RE; - fvals[(int)Feature3D::GLRLM_LGLRE] = angled_LGLRE; - fvals[(int)Feature3D::GLRLM_HGLRE] = angled_HGLRE; - fvals[(int)Feature3D::GLRLM_SRLGLE] = angled_SRLGLE; - fvals[(int)Feature3D::GLRLM_SRHGLE] = angled_SRHGLE; - fvals[(int)Feature3D::GLRLM_LRLGLE] = angled_LRLGLE; - fvals[(int)Feature3D::GLRLM_LRHGLE] = angled_LRHGLE; + fvals[static_cast(Feature3D::GLRLM_SRE)] = angled_SRE; + fvals[static_cast(Feature3D::GLRLM_LRE)] = angled_LRE; + fvals[static_cast(Feature3D::GLRLM_GLN)] = angled_GLN; + fvals[static_cast(Feature3D::GLRLM_GLNN)] = angled_GLNN; + fvals[static_cast(Feature3D::GLRLM_RLN)] = angled_RLN; + fvals[static_cast(Feature3D::GLRLM_RLNN)] = angled_RLNN; + fvals[static_cast(Feature3D::GLRLM_RP)] = angled_RP; + fvals[static_cast(Feature3D::GLRLM_GLV)] = angled_GLV; + fvals[static_cast(Feature3D::GLRLM_RV)] = angled_RV; + fvals[static_cast(Feature3D::GLRLM_RE)] = angled_RE; + fvals[static_cast(Feature3D::GLRLM_LGLRE)] = angled_LGLRE; + fvals[static_cast(Feature3D::GLRLM_HGLRE)] = angled_HGLRE; + fvals[static_cast(Feature3D::GLRLM_SRLGLE)] = angled_SRLGLE; + fvals[static_cast(Feature3D::GLRLM_SRHGLE)] = angled_SRHGLE; + fvals[static_cast(Feature3D::GLRLM_LRLGLE)] = angled_LRLGLE; + fvals[static_cast(Feature3D::GLRLM_LRHGLE)] = angled_LRHGLE; // -- averages -- - fvals[(int)Feature3D::GLRLM_SRE_AVE][0] = calc_ave(angled_SRE); - fvals[(int)Feature3D::GLRLM_LRE_AVE][0] = calc_ave(angled_LRE); - fvals[(int)Feature3D::GLRLM_GLN_AVE][0] = calc_ave(angled_GLN); - fvals[(int)Feature3D::GLRLM_GLNN_AVE][0] = calc_ave(angled_GLNN); - fvals[(int)Feature3D::GLRLM_RLN_AVE][0] = calc_ave(angled_RLN); - fvals[(int)Feature3D::GLRLM_RLNN_AVE][0] = calc_ave(angled_RLNN); - fvals[(int)Feature3D::GLRLM_RP_AVE][0] = calc_ave(angled_RP); - fvals[(int)Feature3D::GLRLM_GLV_AVE][0] = calc_ave(angled_GLV); - fvals[(int)Feature3D::GLRLM_RV_AVE][0] = calc_ave(angled_RV); - fvals[(int)Feature3D::GLRLM_RE_AVE][0] = calc_ave(angled_RE); - fvals[(int)Feature3D::GLRLM_LGLRE_AVE][0] = calc_ave(angled_LGLRE); - fvals[(int)Feature3D::GLRLM_HGLRE_AVE][0] = calc_ave(angled_HGLRE); - fvals[(int)Feature3D::GLRLM_SRLGLE_AVE][0] = calc_ave(angled_SRLGLE); - fvals[(int)Feature3D::GLRLM_SRHGLE_AVE][0] = calc_ave(angled_SRHGLE); - fvals[(int)Feature3D::GLRLM_LRLGLE_AVE][0] = calc_ave(angled_LRLGLE); - fvals[(int)Feature3D::GLRLM_LRHGLE_AVE][0] = calc_ave(angled_LRHGLE); + fvals[static_cast(Feature3D::GLRLM_SRE_AVE)][0] = calc_ave(angled_SRE); + fvals[static_cast(Feature3D::GLRLM_LRE_AVE)][0] = calc_ave(angled_LRE); + fvals[static_cast(Feature3D::GLRLM_GLN_AVE)][0] = calc_ave(angled_GLN); + fvals[static_cast(Feature3D::GLRLM_GLNN_AVE)][0] = calc_ave(angled_GLNN); + fvals[static_cast(Feature3D::GLRLM_RLN_AVE)][0] = calc_ave(angled_RLN); + fvals[static_cast(Feature3D::GLRLM_RLNN_AVE)][0] = calc_ave(angled_RLNN); + fvals[static_cast(Feature3D::GLRLM_RP_AVE)][0] = calc_ave(angled_RP); + fvals[static_cast(Feature3D::GLRLM_GLV_AVE)][0] = calc_ave(angled_GLV); + fvals[static_cast(Feature3D::GLRLM_RV_AVE)][0] = calc_ave(angled_RV); + fvals[static_cast(Feature3D::GLRLM_RE_AVE)][0] = calc_ave(angled_RE); + fvals[static_cast(Feature3D::GLRLM_LGLRE_AVE)][0] = calc_ave(angled_LGLRE); + fvals[static_cast(Feature3D::GLRLM_HGLRE_AVE)][0] = calc_ave(angled_HGLRE); + fvals[static_cast(Feature3D::GLRLM_SRLGLE_AVE)][0] = calc_ave(angled_SRLGLE); + fvals[static_cast(Feature3D::GLRLM_SRHGLE_AVE)][0] = calc_ave(angled_SRHGLE); + fvals[static_cast(Feature3D::GLRLM_LRLGLE_AVE)][0] = calc_ave(angled_LRLGLE); + fvals[static_cast(Feature3D::GLRLM_LRHGLE_AVE)][0] = calc_ave(angled_LRHGLE); } // 1. Short Run Emphasis diff --git a/src/nyx/features/3d_glrlm.h b/src/nyx/features/3d_glrlm.h index f0a2bd00d..051897d68 100644 --- a/src/nyx/features/3d_glrlm.h +++ b/src/nyx/features/3d_glrlm.h @@ -21,7 +21,7 @@ class D3_GLRLM_feature : public FeatureMethod, public TextureFeature // Codes of features implemented by this class. Used in feature manager's mechanisms, // in the feature group nickname expansion, and in the feature value output - const constexpr static std::initializer_list featureset = + static constexpr std::initializer_list featureset = { Nyxus::Feature3D::GLRLM_SRE, // Short Run Emphasis Nyxus::Feature3D::GLRLM_LRE, // Long Run Emphasis @@ -59,7 +59,7 @@ class D3_GLRLM_feature : public FeatureMethod, public TextureFeature }; // Features implemented by this class that do not require vector-like angled output. Instead, they are output as a single values - const constexpr static std::initializer_list nonAngledFeatures = + static constexpr std::initializer_list nonAngledFeatures = { Nyxus::Feature3D::GLRLM_SRE_AVE, Nyxus::Feature3D::GLRLM_LRE_AVE, diff --git a/src/nyx/features/3d_glszm.cpp b/src/nyx/features/3d_glszm.cpp index 3b740e2b9..3af1ee43c 100644 --- a/src/nyx/features/3d_glszm.cpp +++ b/src/nyx/features/3d_glszm.cpp @@ -532,7 +532,7 @@ void D3_GLSZM_feature::calculate (LR& r, const Fsettings& s) Ng = STNGS_IBSI(s) ? *std::max_element (I.begin(), I.end()) : I.size(); // former Environment::ibsi_compliance Ns = maxZoneArea; - Nz = (int) Zones.size(); + Nz = static_cast(Zones.size()); Np = nnzVoxels; // --allocate GLSZ-matrix @@ -606,7 +606,7 @@ void D3_GLSZM_feature::calc_sums_of_P() // Aggregate by grayscale level for (int i = 1; i <= Ng; ++i) { - double inten = (double)I[i - 1]; + double inten = static_cast(I[i - 1]); double sum = 0; for (int j = 1; j <= /*Ns*/P.width(); ++j) { @@ -646,22 +646,22 @@ void D3_GLSZM_feature::calc_sums_of_P() void D3_GLSZM_feature::save_value(std::vector>& fvals) { - fvals[(int)Feature3D::GLSZM_SAE][0] = fv_SAE; - fvals[(int)Feature3D::GLSZM_LAE][0] = fv_LAE; - fvals[(int)Feature3D::GLSZM_GLN][0] = fv_GLN; - fvals[(int)Feature3D::GLSZM_GLNN][0] = fv_GLNN; - fvals[(int)Feature3D::GLSZM_SZN][0] = fv_SZN; - fvals[(int)Feature3D::GLSZM_SZNN][0] = fv_SZNN; - fvals[(int)Feature3D::GLSZM_ZP][0] = fv_ZP; - fvals[(int)Feature3D::GLSZM_GLV][0] = fv_GLV; - fvals[(int)Feature3D::GLSZM_ZV][0] = fv_ZV; - fvals[(int)Feature3D::GLSZM_ZE][0] = fv_ZE; - fvals[(int)Feature3D::GLSZM_LGLZE][0] = fv_LGLZE; - fvals[(int)Feature3D::GLSZM_HGLZE][0] = fv_HGLZE; - fvals[(int)Feature3D::GLSZM_SALGLE][0] = fv_SALGLE; - fvals[(int)Feature3D::GLSZM_SAHGLE][0] = fv_SAHGLE; - fvals[(int)Feature3D::GLSZM_LALGLE][0] = fv_LALGLE; - fvals[(int)Feature3D::GLSZM_LAHGLE][0] = fv_LAHGLE; + fvals[static_cast(Feature3D::GLSZM_SAE)][0] = fv_SAE; + fvals[static_cast(Feature3D::GLSZM_LAE)][0] = fv_LAE; + fvals[static_cast(Feature3D::GLSZM_GLN)][0] = fv_GLN; + fvals[static_cast(Feature3D::GLSZM_GLNN)][0] = fv_GLNN; + fvals[static_cast(Feature3D::GLSZM_SZN)][0] = fv_SZN; + fvals[static_cast(Feature3D::GLSZM_SZNN)][0] = fv_SZNN; + fvals[static_cast(Feature3D::GLSZM_ZP)][0] = fv_ZP; + fvals[static_cast(Feature3D::GLSZM_GLV)][0] = fv_GLV; + fvals[static_cast(Feature3D::GLSZM_ZV)][0] = fv_ZV; + fvals[static_cast(Feature3D::GLSZM_ZE)][0] = fv_ZE; + fvals[static_cast(Feature3D::GLSZM_LGLZE)][0] = fv_LGLZE; + fvals[static_cast(Feature3D::GLSZM_HGLZE)][0] = fv_HGLZE; + fvals[static_cast(Feature3D::GLSZM_SALGLE)][0] = fv_SALGLE; + fvals[static_cast(Feature3D::GLSZM_SAHGLE)][0] = fv_SAHGLE; + fvals[static_cast(Feature3D::GLSZM_LALGLE)][0] = fv_LALGLE; + fvals[static_cast(Feature3D::GLSZM_LAHGLE)][0] = fv_LAHGLE; } // 1. Small Area Emphasis @@ -787,7 +787,7 @@ double D3_GLSZM_feature::calc_GLV() double f = 0.0; for (int i = 1; i <= Ng; i++) { - double inten = (double)I[i - 1]; + double inten = static_cast(I[i - 1]); for (int j = 1; j <= Ns; j++) { double d2 = (inten - mu_GLV) * (inten - mu_GLV); @@ -828,7 +828,7 @@ double D3_GLSZM_feature::calc_LGLZE() double f = 0.0; for (int i = 1; i <= Ng; i++) { - double inten = (double)I[i - 1]; + double inten = static_cast(I[i - 1]); f += si[i] / (inten * inten); } @@ -843,7 +843,7 @@ double D3_GLSZM_feature::calc_HGLZE() double f = 0.0; for (int i = 1; i <= Ng; i++) { - double inten = (double)I[i - 1]; + double inten = static_cast(I[i - 1]); f += si[i] * (inten * inten); } diff --git a/src/nyx/features/3d_glszm.h b/src/nyx/features/3d_glszm.h index 192dcfe37..1b69a6dd8 100644 --- a/src/nyx/features/3d_glszm.h +++ b/src/nyx/features/3d_glszm.h @@ -14,7 +14,7 @@ class D3_GLSZM_feature : public FeatureMethod, public TextureFeature // Codes of features implemented by this class. Used in feature manager's mechanisms, // in the feature group nickname expansion, and in the feature value output - const constexpr static std::initializer_list featureset = + static constexpr std::initializer_list featureset = { Nyxus::Feature3D::GLSZM_SAE, // Small Area Emphasis Nyxus::Feature3D::GLSZM_LAE, // Large Area Emphasis diff --git a/src/nyx/features/3d_intensity.cpp b/src/nyx/features/3d_intensity.cpp index 2777609fb..8ffb62187 100644 --- a/src/nyx/features/3d_intensity.cpp +++ b/src/nyx/features/3d_intensity.cpp @@ -25,7 +25,7 @@ PixIntens to_grayscale_radiomix(PixIntens x, PixIntens min__, PixIntens max__, i if (x) { double binW = double(max__ - min__) / double(binCount); - PixIntens y = (PixIntens)(double(x - min__) / binW + 1); + PixIntens y = static_cast((double(x - min__) / binW + 1)); if (y > binCount) y = binCount; // the last bin is +1 unit wider return y; @@ -316,43 +316,43 @@ void D3_VoxelIntensityFeatures::osized_calculate (LR & r, const Fsettings & s, c void D3_VoxelIntensityFeatures::save_value(std::vector>& fvals) { - fvals[(int)Feature3D::INTEGRATED_INTENSITY][0] = val_INTEGRATED_INTENSITY; - fvals[(int)Feature3D::MEAN][0] = val_MEAN; - fvals[(int)Feature3D::MEDIAN][0] = val_MEDIAN; - fvals[(int)Feature3D::MIN][0] = val_MIN; - fvals[(int)Feature3D::MAX][0] = val_MAX; - fvals[(int)Feature3D::RANGE][0] = val_RANGE; - fvals[(int)Feature3D::COVERED_IMAGE_INTENSITY_RANGE][0] = val_COVERED_IMAGE_INTENSITY_RANGE; - fvals[(int)Feature3D::STANDARD_DEVIATION][0] = val_STANDARD_DEVIATION; - fvals[(int)Feature3D::STANDARD_ERROR][0] = val_STANDARD_ERROR; - fvals[(int)Feature3D::SKEWNESS][0] = val_SKEWNESS; - fvals[(int)Feature3D::KURTOSIS][0] = val_KURTOSIS; - fvals[(int)Feature3D::EXCESS_KURTOSIS][0] = val_EXCESS_KURTOSIS; - fvals[(int)Feature3D::HYPERSKEWNESS][0] = val_HYPERSKEWNESS; - fvals[(int)Feature3D::HYPERFLATNESS][0] = val_HYPERFLATNESS; - fvals[(int)Feature3D::MEAN_ABSOLUTE_DEVIATION][0] = val_MEAN_ABSOLUTE_DEVIATION; - fvals[(int)Feature3D::MEDIAN_ABSOLUTE_DEVIATION][0] = val_MEDIAN_ABSOLUTE_DEVIATION; - fvals[(int)Feature3D::ENERGY][0] = val_ENERGY; - fvals[(int)Feature3D::ROOT_MEAN_SQUARED][0] = val_ROOT_MEAN_SQUARED; - fvals[(int)Feature3D::ENTROPY][0] = val_ENTROPY; - fvals[(int)Feature3D::MODE][0] = val_MODE; - fvals[(int)Feature3D::UNIFORMITY][0] = val_UNIFORMITY; - fvals[(int)Feature3D::UNIFORMITY_PIU][0] = val_UNIFORMITY_PIU; - fvals[(int)Feature3D::P01][0] = val_P01; - fvals[(int)Feature3D::P10][0] = val_P10; - fvals[(int)Feature3D::P25][0] = val_P25; - fvals[(int)Feature3D::P75][0] = val_P75; - fvals[(int)Feature3D::P90][0] = val_P90; - fvals[(int)Feature3D::P99][0] = val_P99; - fvals[(int)Feature3D::QCOD][0] = val_QCOD; - fvals[(int)Feature3D::INTERQUARTILE_RANGE][0] = val_INTERQUARTILE_RANGE; - fvals[(int)Feature3D::QCOD][0] = val_QCOD; - fvals[(int)Feature3D::ROBUST_MEAN][0] = val_ROBUST_MEAN; - fvals[(int)Feature3D::ROBUST_MEAN_ABSOLUTE_DEVIATION][0] = val_ROBUST_MEAN_ABSOLUTE_DEVIATION; - fvals[(int)Feature3D::COV][0] = val_COV; - fvals[(int)Feature3D::STANDARD_DEVIATION_BIASED][0] = val_STANDARD_DEVIATION_BIASED; - fvals[(int)Feature3D::VARIANCE][0] = val_VARIANCE; - fvals[(int)Feature3D::VARIANCE_BIASED][0] = val_VARIANCE_BIASED; + fvals[static_cast(Feature3D::INTEGRATED_INTENSITY)][0] = val_INTEGRATED_INTENSITY; + fvals[static_cast(Feature3D::MEAN)][0] = val_MEAN; + fvals[static_cast(Feature3D::MEDIAN)][0] = val_MEDIAN; + fvals[static_cast(Feature3D::MIN)][0] = val_MIN; + fvals[static_cast(Feature3D::MAX)][0] = val_MAX; + fvals[static_cast(Feature3D::RANGE)][0] = val_RANGE; + fvals[static_cast(Feature3D::COVERED_IMAGE_INTENSITY_RANGE)][0] = val_COVERED_IMAGE_INTENSITY_RANGE; + fvals[static_cast(Feature3D::STANDARD_DEVIATION)][0] = val_STANDARD_DEVIATION; + fvals[static_cast(Feature3D::STANDARD_ERROR)][0] = val_STANDARD_ERROR; + fvals[static_cast(Feature3D::SKEWNESS)][0] = val_SKEWNESS; + fvals[static_cast(Feature3D::KURTOSIS)][0] = val_KURTOSIS; + fvals[static_cast(Feature3D::EXCESS_KURTOSIS)][0] = val_EXCESS_KURTOSIS; + fvals[static_cast(Feature3D::HYPERSKEWNESS)][0] = val_HYPERSKEWNESS; + fvals[static_cast(Feature3D::HYPERFLATNESS)][0] = val_HYPERFLATNESS; + fvals[static_cast(Feature3D::MEAN_ABSOLUTE_DEVIATION)][0] = val_MEAN_ABSOLUTE_DEVIATION; + fvals[static_cast(Feature3D::MEDIAN_ABSOLUTE_DEVIATION)][0] = val_MEDIAN_ABSOLUTE_DEVIATION; + fvals[static_cast(Feature3D::ENERGY)][0] = val_ENERGY; + fvals[static_cast(Feature3D::ROOT_MEAN_SQUARED)][0] = val_ROOT_MEAN_SQUARED; + fvals[static_cast(Feature3D::ENTROPY)][0] = val_ENTROPY; + fvals[static_cast(Feature3D::MODE)][0] = val_MODE; + fvals[static_cast(Feature3D::UNIFORMITY)][0] = val_UNIFORMITY; + fvals[static_cast(Feature3D::UNIFORMITY_PIU)][0] = val_UNIFORMITY_PIU; + fvals[static_cast(Feature3D::P01)][0] = val_P01; + fvals[static_cast(Feature3D::P10)][0] = val_P10; + fvals[static_cast(Feature3D::P25)][0] = val_P25; + fvals[static_cast(Feature3D::P75)][0] = val_P75; + fvals[static_cast(Feature3D::P90)][0] = val_P90; + fvals[static_cast(Feature3D::P99)][0] = val_P99; + fvals[static_cast(Feature3D::QCOD)][0] = val_QCOD; + fvals[static_cast(Feature3D::INTERQUARTILE_RANGE)][0] = val_INTERQUARTILE_RANGE; + fvals[static_cast(Feature3D::QCOD)][0] = val_QCOD; + fvals[static_cast(Feature3D::ROBUST_MEAN)][0] = val_ROBUST_MEAN; + fvals[static_cast(Feature3D::ROBUST_MEAN_ABSOLUTE_DEVIATION)][0] = val_ROBUST_MEAN_ABSOLUTE_DEVIATION; + fvals[static_cast(Feature3D::COV)][0] = val_COV; + fvals[static_cast(Feature3D::STANDARD_DEVIATION_BIASED)][0] = val_STANDARD_DEVIATION_BIASED; + fvals[static_cast(Feature3D::VARIANCE)][0] = val_VARIANCE; + fvals[static_cast(Feature3D::VARIANCE_BIASED)][0] = val_VARIANCE_BIASED; } void D3_VoxelIntensityFeatures::reduce (size_t start, size_t end, std::vector* ptrLabels, std::unordered_map * ptrLabelData, const Fsettings & s, const Dataset & ds) diff --git a/src/nyx/features/3d_intensity.h b/src/nyx/features/3d_intensity.h index 46d0deb67..9310e8b81 100644 --- a/src/nyx/features/3d_intensity.h +++ b/src/nyx/features/3d_intensity.h @@ -24,7 +24,7 @@ class D3_VoxelIntensityFeatures: public FeatureMethod // list dependencies of this class static bool required (const FeatureSet& fs); - const constexpr static std::initializer_list featureset = + static constexpr std::initializer_list featureset = { Nyxus::Feature3D::COV, Nyxus::Feature3D::COVERED_IMAGE_INTENSITY_RANGE, diff --git a/src/nyx/features/3d_ngldm.cpp b/src/nyx/features/3d_ngldm.cpp index cde678cf0..a4c699b4b 100644 --- a/src/nyx/features/3d_ngldm.cpp +++ b/src/nyx/features/3d_ngldm.cpp @@ -138,7 +138,7 @@ void D3_NGLDM_feature::calc_ngld_matrix (SimpleMatrix& NGLDM, int& // Get a dense index value for sparse binned intensity cpi_ auto iter = std::find(U.begin(), U.end(), cpi_); - int row = (int)(iter - U.begin()); + int row = static_cast((iter - U.begin())); // Having pixel (x,y) as the center, iterate pixels of the neighborhood and update its histogram int n_matches = 0; // (y,x)'s dependency -- the number of matches of center pixel (y,x)'s intensity in its neighborhood @@ -361,25 +361,25 @@ void D3_NGLDM_feature::calc_features(const std::vector& Sg, const std::v void D3_NGLDM_feature::save_value(std::vector>& fvals) { - fvals[(int)Feature3D::NGLDM_LDE][0] = f_LDE; - fvals[(int)Feature3D::NGLDM_HDE][0] = f_HDE; - fvals[(int)Feature3D::NGLDM_LGLCE][0] = f_LGLCE; - fvals[(int)Feature3D::NGLDM_HGLCE][0] = f_HGLCE; - fvals[(int)Feature3D::NGLDM_LDLGLE][0] = f_LDLGLE; - fvals[(int)Feature3D::NGLDM_LDHGLE][0] = f_LDHGLE; - fvals[(int)Feature3D::NGLDM_HDLGLE][0] = f_HDLGLE; - fvals[(int)Feature3D::NGLDM_HDHGLE][0] = f_HDHGLE; - fvals[(int)Feature3D::NGLDM_GLNU][0] = f_GLNU; - fvals[(int)Feature3D::NGLDM_GLNUN][0] = f_GLNUN; - fvals[(int)Feature3D::NGLDM_DCNU][0] = f_DCNU; - fvals[(int)Feature3D::NGLDM_DCNUN][0] = f_DCNUN; - fvals[(int)Feature3D::NGLDM_GLM][0] = f_GLCM; - fvals[(int)Feature3D::NGLDM_GLV][0] = f_GLV; - fvals[(int)Feature3D::NGLDM_DCM][0] = f_DCM; - fvals[(int)Feature3D::NGLDM_DCP][0] = f_DCP; - fvals[(int)Feature3D::NGLDM_DCV][0] = f_DCV; - fvals[(int)Feature3D::NGLDM_DCENT][0] = f_DCENT; - fvals[(int)Feature3D::NGLDM_DCENE][0] = f_DCENE; + fvals[static_cast(Feature3D::NGLDM_LDE)][0] = f_LDE; + fvals[static_cast(Feature3D::NGLDM_HDE)][0] = f_HDE; + fvals[static_cast(Feature3D::NGLDM_LGLCE)][0] = f_LGLCE; + fvals[static_cast(Feature3D::NGLDM_HGLCE)][0] = f_HGLCE; + fvals[static_cast(Feature3D::NGLDM_LDLGLE)][0] = f_LDLGLE; + fvals[static_cast(Feature3D::NGLDM_LDHGLE)][0] = f_LDHGLE; + fvals[static_cast(Feature3D::NGLDM_HDLGLE)][0] = f_HDLGLE; + fvals[static_cast(Feature3D::NGLDM_HDHGLE)][0] = f_HDHGLE; + fvals[static_cast(Feature3D::NGLDM_GLNU)][0] = f_GLNU; + fvals[static_cast(Feature3D::NGLDM_GLNUN)][0] = f_GLNUN; + fvals[static_cast(Feature3D::NGLDM_DCNU)][0] = f_DCNU; + fvals[static_cast(Feature3D::NGLDM_DCNUN)][0] = f_DCNUN; + fvals[static_cast(Feature3D::NGLDM_GLM)][0] = f_GLCM; + fvals[static_cast(Feature3D::NGLDM_GLV)][0] = f_GLV; + fvals[static_cast(Feature3D::NGLDM_DCM)][0] = f_DCM; + fvals[static_cast(Feature3D::NGLDM_DCP)][0] = f_DCP; + fvals[static_cast(Feature3D::NGLDM_DCV)][0] = f_DCV; + fvals[static_cast(Feature3D::NGLDM_DCENT)][0] = f_DCENT; + fvals[static_cast(Feature3D::NGLDM_DCENE)][0] = f_DCENE; } void D3_NGLDM_feature::reduce (size_t start, size_t end, std::vector* ptrLabels, std::unordered_map * ptrLabelData, const Fsettings & s, const Dataset & _) diff --git a/src/nyx/features/3d_ngldm.h b/src/nyx/features/3d_ngldm.h index 9d98a373a..2b03d8795 100644 --- a/src/nyx/features/3d_ngldm.h +++ b/src/nyx/features/3d_ngldm.h @@ -10,7 +10,7 @@ class D3_NGLDM_feature : public FeatureMethod // Codes of features implemented by this class. Used in feature manager's mechanisms, // in the feature group nickname expansion, and in the feature value output - const constexpr static std::initializer_list featureset = + static constexpr std::initializer_list featureset = { Nyxus::Feature3D::NGLDM_LDE, // Low Dependence Emphasis Nyxus::Feature3D::NGLDM_HDE, // High Dependence Emphasis diff --git a/src/nyx/features/3d_ngtdm.cpp b/src/nyx/features/3d_ngtdm.cpp index cf6dce21d..31d597640 100644 --- a/src/nyx/features/3d_ngtdm.cpp +++ b/src/nyx/features/3d_ngtdm.cpp @@ -155,7 +155,7 @@ int nsh = sizeof(shifts) / sizeof(ShiftToNeighbor); row = int(lower - I.begin()); // col - int col = (int)z.second; // 1-based + int col = static_cast(z.second); // 1-based // increment N[row]++; // --S @@ -170,7 +170,7 @@ int nsh = sizeof(shifts) / sizeof(ShiftToNeighbor); // --Calculate Nvc (sum of N) double Nvc = 0; for (int i = 0; i < N.size(); i++) - Nvc += (double) N[i]; + Nvc += static_cast(N[i]); // --Calculate P for (int i = 0; i < N.size(); i++) @@ -249,8 +249,8 @@ void D3_NGTDM_feature::calculate (LR& r, const Fsettings& s) // fill the NGTD-matrix // --dimensions - Ng = (int)I.size(); - Ngp = (int)U.size(); + Ng = static_cast(I.size()); + Ngp = static_cast(U.size()); Nvp = D3_NGTDM_feature::calc_NGTDM (N, P, S, Z, I); // Calculate features @@ -263,11 +263,11 @@ void D3_NGTDM_feature::calculate (LR& r, const Fsettings& s) void D3_NGTDM_feature::save_value(std::vector>& fvals) { - fvals[(int)Feature3D::NGTDM_COARSENESS][0] = _coarseness; - fvals[(int)Feature3D::NGTDM_CONTRAST][0] = _contrast; - fvals[(int)Feature3D::NGTDM_BUSYNESS][0] = _busyness; - fvals[(int)Feature3D::NGTDM_COMPLEXITY][0] = _complexity; - fvals[(int)Feature3D::NGTDM_STRENGTH][0] = _strength; + fvals[static_cast(Feature3D::NGTDM_COARSENESS)][0] = _coarseness; + fvals[static_cast(Feature3D::NGTDM_CONTRAST)][0] = _contrast; + fvals[static_cast(Feature3D::NGTDM_BUSYNESS)][0] = _busyness; + fvals[static_cast(Feature3D::NGTDM_COMPLEXITY)][0] = _complexity; + fvals[static_cast(Feature3D::NGTDM_STRENGTH)][0] = _strength; } void D3_NGTDM_feature::osized_add_online_pixel(size_t x, size_t y, uint32_t intensity) {} // Not supporting @@ -370,8 +370,8 @@ void D3_NGTDM_feature::osized_calculate (LR& r, const Fsettings& s, ImageLoader& // Fill the matrix - Ng = (int) U.size(); - Ngp = (int) U.size(); + Ng = static_cast(U.size()); + Ngp = static_cast(U.size()); // --allocate the matrix P.resize (Ng, 0); @@ -390,7 +390,7 @@ void D3_NGTDM_feature::osized_calculate (LR& r, const Fsettings& s, ImageLoader& int row = (STNGS_IBSI(s)) ? z.first : int(iter - I.begin()); // col - int col = (int)z.second; // 1-based + int col = static_cast(z.second); // 1-based // increment N[row]++; // --S @@ -409,7 +409,7 @@ void D3_NGTDM_feature::osized_calculate (LR& r, const Fsettings& s, ImageLoader& // --Calculate P for (int i = 0; i < N.size(); i++) - P[i] = (double)N[i] / Nvc; + P[i] = static_cast(N[i] )/ Nvc; // Calculate features _coarseness = calc_Coarseness(); @@ -434,10 +434,10 @@ double D3_NGTDM_feature::calc_Contrast() double sum = 0.0; for (int i = 1; i <= Ng; i++) { - double ival = (double)I[i - 1]; + double ival = static_cast(I[i - 1]); for (int j = 1; j <= Ng; j++) { - double jval = (double)I[j - 1]; + double jval = static_cast(I[j - 1]); double tmp = P[i - 1] * P[j - 1] * (ival - jval) * (ival - jval); sum += tmp; } @@ -472,10 +472,10 @@ double D3_NGTDM_feature::calc_Busyness() double sum2 = 0.0; for (int i = 1; i <= Ng; i++) { - double ival = (double)I[i - 1]; + double ival = static_cast(I[i - 1]); for (int j = 1; j <= Ng; j++) { - double jval = (double)I[j - 1]; + double jval = static_cast(I[j - 1]); if (P[i - 1] != 0 && P[j - 1] != 0) { double tmp = P[i - 1] * ival - P[j - 1] * jval; @@ -496,10 +496,10 @@ double D3_NGTDM_feature::calc_Complexity() double sum = 0.0; for (int i = 1; i <= Ng; i++) { - double ival = (double)I[i - 1]; + double ival = static_cast(I[i - 1]); for (int j = 1; j <= Ng; j++) { - double jval = (double)I[j - 1]; + double jval = static_cast(I[j - 1]); if (P[i - 1] != 0 && P[j - 1] != 0) { sum += std::abs(ival - jval) * (P[i - 1] * S[i - 1] + P[j - 1] * S[j - 1]) / (P[i - 1] + P[j - 1]); @@ -516,10 +516,10 @@ double D3_NGTDM_feature::calc_Strength() double sum1 = 0.0; for (int i = 1; i <= Ng; i++) { - double ival = (double)I[i - 1]; + double ival = static_cast(I[i - 1]); for (int j = 1; j <= Ng; j++) { - double jval = (double)I[j - 1]; + double jval = static_cast(I[j - 1]); if (P[i - 1] != 0 && P[j - 1] != 0) { sum1 += (P[i - 1] + P[j - 1]) * (ival - jval) * (ival - jval); diff --git a/src/nyx/features/3d_ngtdm.h b/src/nyx/features/3d_ngtdm.h index 50d62bbf4..8a4e4e39e 100644 --- a/src/nyx/features/3d_ngtdm.h +++ b/src/nyx/features/3d_ngtdm.h @@ -15,7 +15,7 @@ class D3_NGTDM_feature : public FeatureMethod, public TextureFeature // Codes of features implemented by this class. Used in feature manager's mechanisms, // in the feature group nickname expansion, and in the feature value output - const constexpr static std::initializer_list featureset = + static constexpr std::initializer_list featureset = { Nyxus::Feature3D::NGTDM_COARSENESS, Nyxus::Feature3D::NGTDM_CONTRAST, diff --git a/src/nyx/features/3d_surface.cpp b/src/nyx/features/3d_surface.cpp index ddc30bf12..b846728ca 100644 --- a/src/nyx/features/3d_surface.cpp +++ b/src/nyx/features/3d_surface.cpp @@ -286,7 +286,7 @@ void D3_SurfaceFeature::build_surface (LR & r) for (auto ip : plane) { auto v = r.raw_pixels_3D[ip]; - P.push_back (std::array({ (float)v.x, (float)v.y, (float)v.z })); + P.push_back (std::array({ static_cast(v.x), static_cast(v.y), static_cast(v.z )})); } } @@ -521,21 +521,21 @@ void D3_SurfaceFeature::osized_calculate (LR& r, const Fsettings& s, ImageLoader void D3_SurfaceFeature::save_value(std::vector>& fvals) { - fvals[(int)Nyxus::Feature3D::AREA][0] = fval_AREA; - fvals[(int)Nyxus::Feature3D::AREA_2_VOLUME][0] = fval_AREA_2_VOLUME; - fvals[(int)Nyxus::Feature3D::COMPACTNESS1][0] = fval_COMPACTNESS1; - fvals[(int)Nyxus::Feature3D::COMPACTNESS2][0] = fval_COMPACTNESS2; - fvals[(int)Nyxus::Feature3D::MESH_VOLUME][0] = fval_MESH_VOLUME; - fvals[(int)Nyxus::Feature3D::SPHERICAL_DISPROPORTION][0] = fval_SPHERICAL_DISPROPORTION; - fvals[(int)Nyxus::Feature3D::SPHERICITY][0] = fval_SPHERICITY; - fvals[(int)Nyxus::Feature3D::VOLUME_CONVEXHULL][0] = fval_VOLUME_CONVEXHULL; - fvals[(int)Nyxus::Feature3D::VOXEL_VOLUME][0] = fval_VOXEL_VOLUME; - - fvals[(int)Nyxus::Feature3D::MAJOR_AXIS_LEN][0] = fval_MAJOR_AXIS_LEN; - fvals[(int)Nyxus::Feature3D::MINOR_AXIS_LEN][0] = fval_MINOR_AXIS_LEN; - fvals[(int)Nyxus::Feature3D::LEAST_AXIS_LEN][0] = fval_LEAST_AXIS_LEN; - fvals[(int)Nyxus::Feature3D::ELONGATION][0] = fval_ELONGATION; - fvals[(int)Nyxus::Feature3D::FLATNESS][0] = fval_FLATNESS; + fvals[static_cast(Nyxus::Feature3D::AREA)][0] = fval_AREA; + fvals[static_cast(Nyxus::Feature3D::AREA_2_VOLUME)][0] = fval_AREA_2_VOLUME; + fvals[static_cast(Nyxus::Feature3D::COMPACTNESS1)][0] = fval_COMPACTNESS1; + fvals[static_cast(Nyxus::Feature3D::COMPACTNESS2)][0] = fval_COMPACTNESS2; + fvals[static_cast(Nyxus::Feature3D::MESH_VOLUME)][0] = fval_MESH_VOLUME; + fvals[static_cast(Nyxus::Feature3D::SPHERICAL_DISPROPORTION)][0] = fval_SPHERICAL_DISPROPORTION; + fvals[static_cast(Nyxus::Feature3D::SPHERICITY)][0] = fval_SPHERICITY; + fvals[static_cast(Nyxus::Feature3D::VOLUME_CONVEXHULL)][0] = fval_VOLUME_CONVEXHULL; + fvals[static_cast(Nyxus::Feature3D::VOXEL_VOLUME)][0] = fval_VOXEL_VOLUME; + + fvals[static_cast(Nyxus::Feature3D::MAJOR_AXIS_LEN)][0] = fval_MAJOR_AXIS_LEN; + fvals[static_cast(Nyxus::Feature3D::MINOR_AXIS_LEN)][0] = fval_MINOR_AXIS_LEN; + fvals[static_cast(Nyxus::Feature3D::LEAST_AXIS_LEN)][0] = fval_LEAST_AXIS_LEN; + fvals[static_cast(Nyxus::Feature3D::ELONGATION)][0] = fval_ELONGATION; + fvals[static_cast(Nyxus::Feature3D::FLATNESS)][0] = fval_FLATNESS; } void D3_SurfaceFeature::cleanup_instance() diff --git a/src/nyx/features/3d_surface.h b/src/nyx/features/3d_surface.h index be1042f4e..82c4e8b8c 100644 --- a/src/nyx/features/3d_surface.h +++ b/src/nyx/features/3d_surface.h @@ -21,7 +21,7 @@ class D3_SurfaceFeature : public FeatureMethod static void extract (LR& r, const Fsettings& s); static bool required(const FeatureSet& fs); - const constexpr static std::initializer_list featureset = + static constexpr std::initializer_list featureset = { Nyxus::Feature3D::AREA, Nyxus::Feature3D::AREA_2_VOLUME, @@ -41,13 +41,13 @@ class D3_SurfaceFeature : public FeatureMethod private: - struct Simplex3 - { - float a[3], b[3], c[3]; // layout: x, y, z - Simplex3 (const float* a_, const float* b_, const float* c_) - { - for (int i = 0; i < 3; i++) - { + struct Simplex3 + { + float a[3], b[3], c[3]; // layout: x, y, z + Simplex3 (const float* a_, const float* b_, const float* c_) + { + for (int i = 0; i < 3; i++) + { a[i] = a_[i]; b[i] = b_[i]; c[i] = c_[i]; diff --git a/src/nyx/features/basic_morphology.cpp b/src/nyx/features/basic_morphology.cpp index a7f3c3c6d..77355a682 100644 --- a/src/nyx/features/basic_morphology.cpp +++ b/src/nyx/features/basic_morphology.cpp @@ -21,19 +21,19 @@ void BasicMorphologyFeatures::calculate (LR& r, const Fsettings& sett) double n = r.aux_area; // --AREA - double xyres = sett[(int)NyxSetting::XYRES].rval, - pxsize = sett[(int)NyxSetting::PIXELSIZEUM].rval; + double xyres = sett[static_cast(NyxSetting::XYRES)].rval, + pxsize = sett[static_cast(NyxSetting::PIXELSIZEUM)].rval; val_AREA_PIXELS_COUNT = n; if (xyres > 0.0) // former theEnvironment.xyRes val_AREA_UM2 = n * std::pow(pxsize, 2); // former theEnvironment.pixelSizeUm - // --DIAMETER_EQUAL_AREA - val_DIAMETER_EQUAL_AREA = 2.0 * std::sqrt(static_cast(val_AREA_PIXELS_COUNT) / M_PI); + // --DIAMETER_EQUAL_AREA + val_DIAMETER_EQUAL_AREA = 2.0 * std::sqrt(static_cast(val_AREA_PIXELS_COUNT) / M_PI); - //==== Basic morphology :: Bounding box - val_BBOX_XMIN = r.aabb.get_xmin(); - val_BBOX_YMIN = r.aabb.get_ymin(); - val_BBOX_WIDTH = r.aabb.get_width(); + //==== Basic morphology :: Bounding box + val_BBOX_XMIN = r.aabb.get_xmin(); + val_BBOX_YMIN = r.aabb.get_ymin(); + val_BBOX_WIDTH = r.aabb.get_width(); val_BBOX_HEIGHT = r.aabb.get_height(); //==== Basic morphology :: Centroids @@ -42,30 +42,30 @@ void BasicMorphologyFeatures::calculate (LR& r, const Fsettings& sett) { val_CENTROID_X += px.x; val_CENTROID_Y += px.y; - } - val_CENTROID_X /= n; - val_CENTROID_Y /= n; - - // --COMPACTNESS - Moments2 mom2; - for (auto& px : r.raw_pixels) - { - double dx = static_cast(px.x) - val_CENTROID_X; - double dy = static_cast(px.y) - val_CENTROID_Y; - double dst = std::sqrt(dx * dx + dy * dy); - mom2.add(dst); - } - val_COMPACTNESS = mom2.std() / n; - - //==== Basic morphology :: Weighted centroids - double x_mass = 0, y_mass = 0, mass = 0; - - for (auto& px : r.raw_pixels) - { - x_mass += px.x * px.inten; - y_mass += px.y * px.inten; - mass += px.inten; - } + } + val_CENTROID_X /= n; + val_CENTROID_Y /= n; + + // --COMPACTNESS + Moments2 mom2; + for (auto& px : r.raw_pixels) + { + double dx = static_cast(px.x) - val_CENTROID_X; + double dy = static_cast(px.y) - val_CENTROID_Y; + double dst = std::sqrt(dx * dx + dy * dy); + mom2.add(dst); + } + val_COMPACTNESS = mom2.std() / n; + + //==== Basic morphology :: Weighted centroids + double x_mass = 0, y_mass = 0, mass = 0; + + for (auto& px : r.raw_pixels) + { + x_mass += px.x * px.inten; + y_mass += px.y * px.inten; + mass += px.inten; + } if (mass > 0) { @@ -87,8 +87,8 @@ void BasicMorphologyFeatures::calculate (LR& r, const Fsettings& sett) //==== Basic morphology :: Extent val_EXTENT = n / r.aabb.get_area(); - //==== Basic morphology :: Aspect ratio - val_ASPECT_RATIO = static_cast(r.aabb.get_width()) / static_cast(r.aabb.get_height()); + //==== Basic morphology :: Aspect ratio + val_ASPECT_RATIO = static_cast(r.aabb.get_width()) / static_cast(r.aabb.get_height()); } void BasicMorphologyFeatures::osized_add_online_pixel(size_t x, size_t y, uint32_t intensity) {} // Not providing online calculation for these group of features @@ -98,19 +98,19 @@ void BasicMorphologyFeatures::osized_calculate (LR& r, const Fsettings& s, Image double n = r.aux_area; // --AREA - double xyres = s[(int)NyxSetting::XYRES].rval, - pxsize = s[(int)NyxSetting::PIXELSIZEUM].rval; + double xyres = s[static_cast(NyxSetting::XYRES)].rval, + pxsize = s[static_cast(NyxSetting::PIXELSIZEUM)].rval; val_AREA_PIXELS_COUNT = n; if (xyres > 0.0) val_AREA_UM2 = n * std::pow(pxsize, 2); - // --DIAMETER_EQUAL_AREA - val_DIAMETER_EQUAL_AREA = 2.0 * std::sqrt(static_cast(val_AREA_PIXELS_COUNT) / M_PI); + // --DIAMETER_EQUAL_AREA + val_DIAMETER_EQUAL_AREA = 2.0 * std::sqrt(static_cast(val_AREA_PIXELS_COUNT) / M_PI); - //==== Basic morphology :: Bounding box - val_BBOX_XMIN = r.aabb.get_xmin(); - val_BBOX_YMIN = r.aabb.get_ymin(); - val_BBOX_WIDTH = r.aabb.get_width(); + //==== Basic morphology :: Bounding box + val_BBOX_XMIN = r.aabb.get_xmin(); + val_BBOX_YMIN = r.aabb.get_ymin(); + val_BBOX_WIDTH = r.aabb.get_width(); val_BBOX_HEIGHT = r.aabb.get_height(); //==== Basic morphology :: Centroids @@ -120,32 +120,32 @@ void BasicMorphologyFeatures::osized_calculate (LR& r, const Fsettings& s, Image auto px = r.raw_pixels_NT.get_at(i); val_CENTROID_X += px.x; val_CENTROID_Y += px.y; - } - val_CENTROID_X /= n; - val_CENTROID_Y /= n; - - // --COMPACTNESS - Moments2 mom2; - for (size_t i = 0; i < r.raw_pixels_NT.size(); i++) // for (auto& px : r.raw_pixels) - { - auto px = r.raw_pixels_NT.get_at(i); - double dx = static_cast(px.x) - val_CENTROID_X; - double dy = static_cast(px.y) - val_CENTROID_Y; - double dst = std::sqrt(dx * dx + dy * dy); - mom2.add(dst); - } - val_COMPACTNESS = mom2.std() / n; - - //==== Basic morphology :: Weighted centroids - double x_mass = 0, y_mass = 0, mass = 0; - - for (size_t i = 0; i < r.raw_pixels_NT.size(); i++) // for (auto& px : r.raw_pixels) - { - auto px = r.raw_pixels_NT.get_at(i); - x_mass += px.x * px.inten; - y_mass += px.y * px.inten; - mass += px.inten; - } + } + val_CENTROID_X /= n; + val_CENTROID_Y /= n; + + // --COMPACTNESS + Moments2 mom2; + for (size_t i = 0; i < r.raw_pixels_NT.size(); i++) // for (auto& px : r.raw_pixels) + { + auto px = r.raw_pixels_NT.get_at(i); + double dx = static_cast(px.x) - val_CENTROID_X; + double dy = static_cast(px.y) - val_CENTROID_Y; + double dst = std::sqrt(dx * dx + dy * dy); + mom2.add(dst); + } + val_COMPACTNESS = mom2.std() / n; + + //==== Basic morphology :: Weighted centroids + double x_mass = 0, y_mass = 0, mass = 0; + + for (size_t i = 0; i < r.raw_pixels_NT.size(); i++) // for (auto& px : r.raw_pixels) + { + auto px = r.raw_pixels_NT.get_at(i); + x_mass += px.x * px.inten; + y_mass += px.y * px.inten; + mass += px.inten; + } if (mass > 0) { @@ -167,27 +167,27 @@ void BasicMorphologyFeatures::osized_calculate (LR& r, const Fsettings& s, Image //==== Basic morphology :: Extent val_EXTENT = n / r.aabb.get_area(); - //==== Basic morphology :: Aspect ratio - val_ASPECT_RATIO = static_cast(r.aabb.get_width()) / static_cast(r.aabb.get_height()); -} + //==== Basic morphology :: Aspect ratio + val_ASPECT_RATIO = static_cast(r.aabb.get_width()) / static_cast(r.aabb.get_height()); +} void BasicMorphologyFeatures::save_value(std::vector>& fvals) { - fvals[(int)Feature2D::AREA_PIXELS_COUNT][0] = val_AREA_PIXELS_COUNT; - fvals[(int)Feature2D::AREA_UM2][0] = val_AREA_UM2; - fvals[(int)Feature2D::ASPECT_RATIO][0] = val_ASPECT_RATIO; - fvals[(int)Feature2D::BBOX_XMIN][0] = val_BBOX_XMIN; - fvals[(int)Feature2D::BBOX_YMIN][0] = val_BBOX_YMIN; - fvals[(int)Feature2D::BBOX_WIDTH][0] = val_BBOX_WIDTH; - fvals[(int)Feature2D::BBOX_HEIGHT][0] = val_BBOX_HEIGHT; - fvals[(int)Feature2D::CENTROID_X][0] = val_CENTROID_X; - fvals[(int)Feature2D::CENTROID_Y][0] = val_CENTROID_Y; - fvals[(int)Feature2D::COMPACTNESS][0] = val_COMPACTNESS; - fvals[(int)Feature2D::DIAMETER_EQUAL_AREA][0] = val_DIAMETER_EQUAL_AREA; - fvals[(int)Feature2D::EXTENT][0] = val_EXTENT; - fvals[(int)Feature2D::MASS_DISPLACEMENT][0] = val_MASS_DISPLACEMENT; - fvals[(int)Feature2D::WEIGHTED_CENTROID_X][0] = val_WEIGHTED_CENTROID_X; - fvals[(int)Feature2D::WEIGHTED_CENTROID_Y][0] = val_WEIGHTED_CENTROID_Y; + fvals[static_cast(Feature2D::AREA_PIXELS_COUNT)][0] = val_AREA_PIXELS_COUNT; + fvals[static_cast(Feature2D::AREA_UM2)][0] = val_AREA_UM2; + fvals[static_cast(Feature2D::ASPECT_RATIO)][0] = val_ASPECT_RATIO; + fvals[static_cast(Feature2D::BBOX_XMIN)][0] = val_BBOX_XMIN; + fvals[static_cast(Feature2D::BBOX_YMIN)][0] = val_BBOX_YMIN; + fvals[static_cast(Feature2D::BBOX_WIDTH)][0] = val_BBOX_WIDTH; + fvals[static_cast(Feature2D::BBOX_HEIGHT)][0] = val_BBOX_HEIGHT; + fvals[static_cast(Feature2D::CENTROID_X)][0] = val_CENTROID_X; + fvals[static_cast(Feature2D::CENTROID_Y)][0] = val_CENTROID_Y; + fvals[static_cast(Feature2D::COMPACTNESS)][0] = val_COMPACTNESS; + fvals[static_cast(Feature2D::DIAMETER_EQUAL_AREA)][0] = val_DIAMETER_EQUAL_AREA; + fvals[static_cast(Feature2D::EXTENT)][0] = val_EXTENT; + fvals[static_cast(Feature2D::MASS_DISPLACEMENT)][0] = val_MASS_DISPLACEMENT; + fvals[static_cast(Feature2D::WEIGHTED_CENTROID_X)][0] = val_WEIGHTED_CENTROID_X; + fvals[static_cast(Feature2D::WEIGHTED_CENTROID_Y)][0] = val_WEIGHTED_CENTROID_Y; } void BasicMorphologyFeatures::extract (LR & r, const Fsettings & s) diff --git a/src/nyx/features/basic_morphology.h b/src/nyx/features/basic_morphology.h index c895b6448..6f477b3fc 100644 --- a/src/nyx/features/basic_morphology.h +++ b/src/nyx/features/basic_morphology.h @@ -9,7 +9,7 @@ class BasicMorphologyFeatures : public FeatureMethod { public: - const constexpr static std::initializer_list featureset = + static constexpr std::initializer_list featureset = { Nyxus::Feature2D::AREA_PIXELS_COUNT, Nyxus::Feature2D::AREA_UM2, diff --git a/src/nyx/features/caliper.h b/src/nyx/features/caliper.h index a99198c16..e10017d8e 100644 --- a/src/nyx/features/caliper.h +++ b/src/nyx/features/caliper.h @@ -11,7 +11,7 @@ class CaliperNassensteinFeature : public FeatureMethod { public: - const constexpr static std::initializer_list featureset = + static constexpr std::initializer_list featureset = { Nyxus::Feature2D::STAT_NASSENSTEIN_DIAM_MIN, Nyxus::Feature2D::STAT_NASSENSTEIN_DIAM_MAX, @@ -48,7 +48,7 @@ class CaliperNassensteinFeature : public FeatureMethod class CaliperFeretFeature : public FeatureMethod { public: - const constexpr static std::initializer_list featureset = + static constexpr std::initializer_list featureset = { Nyxus::Feature2D::MIN_FERET_ANGLE, Nyxus::Feature2D::MAX_FERET_ANGLE, @@ -95,7 +95,7 @@ class CaliperFeretFeature : public FeatureMethod class CaliperMartinFeature : public FeatureMethod { public: - const constexpr static std::initializer_list featureset = + static constexpr std::initializer_list featureset = { Nyxus::Feature2D::STAT_MARTIN_DIAM_MIN, Nyxus::Feature2D::STAT_MARTIN_DIAM_MAX, diff --git a/src/nyx/features/caliper_feret.cpp b/src/nyx/features/caliper_feret.cpp index f4b7595ec..f26e1129b 100644 --- a/src/nyx/features/caliper_feret.cpp +++ b/src/nyx/features/caliper_feret.cpp @@ -25,7 +25,7 @@ void CaliperFeretFeature::calculate (LR& r, const Fsettings& s) _mean = _median = _stdev = - _mode = s[(int)NyxSetting::SOFTNAN].rval; // former theEnvironment.resultOptions.noval() + _mode = s[static_cast(NyxSetting::SOFTNAN)].rval; // former theEnvironment.resultOptions.noval() return; } @@ -61,20 +61,20 @@ void CaliperFeretFeature::calculate (LR& r, const Fsettings& s) _mean = _median = _stdev = - _mode = s[(int)NyxSetting::SOFTNAN].rval; // former theEnvironment.resultOptions.noval() + _mode = s[static_cast(NyxSetting::SOFTNAN)].rval; // former theEnvironment.resultOptions.noval() } } void CaliperFeretFeature::save_value(std::vector>& fvals) { - fvals[(int)Feature2D::MIN_FERET_ANGLE][0] = minFeretAngle; - fvals[(int)Feature2D::MAX_FERET_ANGLE][0] = maxFeretAngle; - fvals[(int)Feature2D::STAT_FERET_DIAM_MIN][0] = _min; - fvals[(int)Feature2D::STAT_FERET_DIAM_MAX][0] = _max; - fvals[(int)Feature2D::STAT_FERET_DIAM_MEAN][0] = _mean; - fvals[(int)Feature2D::STAT_FERET_DIAM_MEDIAN][0] = _median; - fvals[(int)Feature2D::STAT_FERET_DIAM_STDDEV][0] = _stdev; - fvals[(int)Feature2D::STAT_FERET_DIAM_MODE][0] = _mode; + fvals[static_cast(Feature2D::MIN_FERET_ANGLE)][0] = minFeretAngle; + fvals[static_cast(Feature2D::MAX_FERET_ANGLE)][0] = maxFeretAngle; + fvals[static_cast(Feature2D::STAT_FERET_DIAM_MIN)][0] = _min; + fvals[static_cast(Feature2D::STAT_FERET_DIAM_MAX)][0] = _max; + fvals[static_cast(Feature2D::STAT_FERET_DIAM_MEAN)][0] = _mean; + fvals[static_cast(Feature2D::STAT_FERET_DIAM_MEDIAN)][0] = _median; + fvals[static_cast(Feature2D::STAT_FERET_DIAM_STDDEV)][0] = _stdev; + fvals[static_cast(Feature2D::STAT_FERET_DIAM_MODE)][0] = _mode; } void CaliperFeretFeature::calculate_angled_caliper_measurements (const std::vector& convex_hull, std::vector& angles, std::vector& ferets) @@ -91,7 +91,7 @@ void CaliperFeretFeature::calculate_angled_caliper_measurements (const std::vect Rotation::rotate_around_center_fp (convex_hull, theta, CH_rot); // FIX (caliper float-precision): no integer truncation // FIX (caliper float-precision): min/max X directly over the float hull (AABB::from_pixelcloud takes Pixel2) double minX = CH_rot[0].x, maxX = CH_rot[0].x; - for (auto& p : CH_rot) { minX = std::min(minX, (double)p.x); maxX = std::max(maxX, (double)p.x); } + for (auto& p : CH_rot) { minX = std::min(minX, static_cast(p.x)); maxX = std::max(maxX, static_cast(p.x)); } // Save a caliper measurement orthogonal to X double feret = maxX - minX; diff --git a/src/nyx/features/caliper_martin.cpp b/src/nyx/features/caliper_martin.cpp index 16a067ed0..628d310f3 100644 --- a/src/nyx/features/caliper_martin.cpp +++ b/src/nyx/features/caliper_martin.cpp @@ -33,8 +33,8 @@ static double hull_width_at_y (const std::vector& poly, double y) } else // horizontal edge lying on the cut: it spans [min x, max x] { - e0 = std::min ((double)a.x, (double)b.x); - e1 = std::max ((double)a.x, (double)b.x); + e0 = std::min (static_cast(a.x), static_cast(b.x)); + e1 = std::max (static_cast(a.x), static_cast(b.x)); } if (!have) { xlo = e0; xhi = e1; have = true; } else { xlo = std::min (xlo, e0); xhi = std::max (xhi, e1); } @@ -58,7 +58,7 @@ void CaliperMartinFeature::calculate (LR& r, const Fsettings& settings) _mean = _median = _stdev = - _mode = settings[(int)NyxSetting::SOFTNAN].rval; // former theEnvironment.resultOptions.noval() + _mode = settings[static_cast(NyxSetting::SOFTNAN)].rval; // former theEnvironment.resultOptions.noval() return; } @@ -68,22 +68,22 @@ void CaliperMartinFeature::calculate (LR& r, const Fsettings& settings) auto s = ComputeCommonStatistics2(allD); - _min = (double)s.min; - _max = (double)s.max; + _min = static_cast(s.min); + _max = static_cast(s.max); _mean = s.mean; _median = s.median; _stdev = s.stdev; - _mode = (double)s.mode; + _mode = static_cast(s.mode); } void CaliperMartinFeature::save_value(std::vector>& fvals) { - fvals[(int)Feature2D::STAT_MARTIN_DIAM_MIN][0] = _min; - fvals[(int)Feature2D::STAT_MARTIN_DIAM_MAX][0] = _max; - fvals[(int)Feature2D::STAT_MARTIN_DIAM_MEAN][0] = _mean; - fvals[(int)Feature2D::STAT_MARTIN_DIAM_MEDIAN][0] = _median; - fvals[(int)Feature2D::STAT_MARTIN_DIAM_STDDEV][0] = _stdev; - fvals[(int)Feature2D::STAT_MARTIN_DIAM_MODE][0] = _mode; + fvals[static_cast(Feature2D::STAT_MARTIN_DIAM_MIN)][0] = _min; + fvals[static_cast(Feature2D::STAT_MARTIN_DIAM_MAX)][0] = _max; + fvals[static_cast(Feature2D::STAT_MARTIN_DIAM_MEAN)][0] = _mean; + fvals[static_cast(Feature2D::STAT_MARTIN_DIAM_MEDIAN)][0] = _median; + fvals[static_cast(Feature2D::STAT_MARTIN_DIAM_STDDEV)][0] = _stdev; + fvals[static_cast(Feature2D::STAT_MARTIN_DIAM_MODE)][0] = _mode; } void CaliperMartinFeature::calculate_imp(const std::vector& convex_hull, std::vector& all_D) @@ -104,7 +104,7 @@ void CaliperMartinFeature::calculate_imp(const std::vector& convex_hull, Rotation::rotate_around_center_fp(convex_hull, theta, CH_rot); // FIX (caliper float-precision): no integer truncation // FIX (caliper float-precision): min/max Y directly over the float hull (AABB::from_pixelcloud takes Pixel2) double minY = CH_rot[0].y, maxY = CH_rot[0].y; - for (auto& p : CH_rot) { minY = std::min(minY, (double)p.y); maxY = std::max(maxY, (double)p.y); } + for (auto& p : CH_rot) { minY = std::min(minY, static_cast(p.y)); maxY = std::max(maxY, static_cast(p.y)); } if (maxY <= minY) // FIX: degenerate (collinear) hull at this angle — skip continue; @@ -146,12 +146,12 @@ void CaliperMartinFeature::osized_calculate (LR& r, const Fsettings& settings, I // Process the stats auto s = ComputeCommonStatistics2(all_D); - _min = (double)s.min; - _max = (double)s.max; + _min = static_cast(s.min); + _max = static_cast(s.max); _mean = s.mean; _median = s.median; _stdev = s.stdev; - _mode = (double)s.mode; + _mode = static_cast(s.mode); } void CaliperMartinFeature::extract (LR& r, const Fsettings& s) diff --git a/src/nyx/features/caliper_nassenstein.cpp b/src/nyx/features/caliper_nassenstein.cpp index 9df7925f1..0e8426a3f 100644 --- a/src/nyx/features/caliper_nassenstein.cpp +++ b/src/nyx/features/caliper_nassenstein.cpp @@ -33,8 +33,8 @@ static double hull_height_at_x (const std::vector& poly, double x) } else // vertical edge lying on the cut: it spans [min y, max y] { - e0 = std::min ((double)a.y, (double)b.y); - e1 = std::max ((double)a.y, (double)b.y); + e0 = std::min (static_cast(a.y), static_cast(b.y)); + e1 = std::max (static_cast(a.y), static_cast(b.y)); } if (!have) { ylo = e0; yhi = e1; have = true; } else { ylo = std::min (ylo, e0); yhi = std::max (yhi, e1); } @@ -58,7 +58,7 @@ void CaliperNassensteinFeature::calculate (LR& r, const Fsettings& settings) _mean = _median = _stdev = - _mode = settings [(int)NyxSetting::SOFTNAN].rval; // former theEnvironment.resultOptions.noval() + _mode = settings [static_cast(NyxSetting::SOFTNAN)].rval; // former theEnvironment.resultOptions.noval() return; } @@ -68,22 +68,22 @@ void CaliperNassensteinFeature::calculate (LR& r, const Fsettings& settings) auto s = ComputeCommonStatistics2(allD); - _min = (double)s.min; - _max = (double)s.max; + _min = static_cast(s.min); + _max = static_cast(s.max); _mean = s.mean; _median = s.median; _stdev = s.stdev; - _mode = (double)s.mode; + _mode = static_cast(s.mode); } void CaliperNassensteinFeature::save_value (std::vector>& fvals) { - fvals[(int)Feature2D::STAT_NASSENSTEIN_DIAM_MIN][0] = _min; - fvals[(int)Feature2D::STAT_NASSENSTEIN_DIAM_MAX][0] = _max; - fvals[(int)Feature2D::STAT_NASSENSTEIN_DIAM_MEAN][0] = _mean; - fvals[(int)Feature2D::STAT_NASSENSTEIN_DIAM_MEDIAN][0] = _median; - fvals[(int)Feature2D::STAT_NASSENSTEIN_DIAM_STDDEV][0] = _stdev; - fvals[(int)Feature2D::STAT_NASSENSTEIN_DIAM_MODE][0] = _mode; + fvals[static_cast(Feature2D::STAT_NASSENSTEIN_DIAM_MIN)][0] = _min; + fvals[static_cast(Feature2D::STAT_NASSENSTEIN_DIAM_MAX)][0] = _max; + fvals[static_cast(Feature2D::STAT_NASSENSTEIN_DIAM_MEAN)][0] = _mean; + fvals[static_cast(Feature2D::STAT_NASSENSTEIN_DIAM_MEDIAN)][0] = _median; + fvals[static_cast(Feature2D::STAT_NASSENSTEIN_DIAM_STDDEV)][0] = _stdev; + fvals[static_cast(Feature2D::STAT_NASSENSTEIN_DIAM_MODE)][0] = _mode; } void CaliperNassensteinFeature::calculate_imp (const std::vector& convex_hull, std::vector& all_D) @@ -109,11 +109,11 @@ void CaliperNassensteinFeature::calculate_imp (const std::vector& convex // vertices (a single vertex generically, or the midpoint of a flat bottom edge) double ymax = CH_rot[0].y; for (auto& p : CH_rot) - ymax = std::max (ymax, (double)p.y); + ymax = std::max (ymax, static_cast(p.y)); double xsum = 0.0; int cnt = 0; for (auto& p : CH_rot) - if (std::abs((double)p.y - ymax) < 1e-3) + if (std::abs(static_cast(p.y )- ymax) < 1e-3) { xsum += p.x; cnt++; @@ -135,12 +135,12 @@ void CaliperNassensteinFeature::osized_calculate (LR& r, const Fsettings& settin // Process the stats auto s = ComputeCommonStatistics2 (all_D); - _min = (double)s.min; - _max = (double)s.max; + _min = static_cast(s.min); + _max = static_cast(s.max); _mean = s.mean; _median = s.median; _stdev = s.stdev; - _mode = (double)s.mode; + _mode = static_cast(s.mode); } void CaliperNassensteinFeature::extract (LR& r, const Fsettings& s) diff --git a/src/nyx/features/chords.h b/src/nyx/features/chords.h index 00ac7aa60..ed6aea914 100644 --- a/src/nyx/features/chords.h +++ b/src/nyx/features/chords.h @@ -18,7 +18,7 @@ class ChordsFeature : public FeatureMethod { public: - const constexpr static std::initializer_list featureset = + static constexpr std::initializer_list featureset = { Nyxus::Feature2D::MAXCHORDS_MAX, Nyxus::Feature2D::MAXCHORDS_MAX_ANG, diff --git a/src/nyx/features/chords_nontriv.cpp b/src/nyx/features/chords_nontriv.cpp index 72132703d..8dcdd1a47 100644 --- a/src/nyx/features/chords_nontriv.cpp +++ b/src/nyx/features/chords_nontriv.cpp @@ -131,20 +131,20 @@ void ChordsFeature::osized_calculate (LR& r, const Fsettings& stng, ImageLoader& void ChordsFeature::save_value (std::vector>& feature_vals) { - feature_vals[(int)Nyxus::Feature2D::MAXCHORDS_MAX][0] = maxchords_max; - feature_vals[(int)Nyxus::Feature2D::MAXCHORDS_MAX_ANG][0] = maxchords_max_angle; - feature_vals[(int)Nyxus::Feature2D::MAXCHORDS_MIN][0] = maxchords_min; - feature_vals[(int)Nyxus::Feature2D::MAXCHORDS_MIN_ANG][0] = maxchords_min_angle; - feature_vals[(int)Nyxus::Feature2D::MAXCHORDS_MEDIAN][0] = maxchords_median; - feature_vals[(int)Nyxus::Feature2D::MAXCHORDS_MEAN][0] = maxchords_mean; - feature_vals[(int)Nyxus::Feature2D::MAXCHORDS_MODE][0] = maxchords_mode; - feature_vals[(int)Nyxus::Feature2D::MAXCHORDS_STDDEV][0] = maxchords_stddev; - feature_vals[(int)Nyxus::Feature2D::ALLCHORDS_MAX][0] = allchords_max; - feature_vals[(int)Nyxus::Feature2D::ALLCHORDS_MAX_ANG][0] = allchords_max_angle; - feature_vals[(int)Nyxus::Feature2D::ALLCHORDS_MIN][0] = allchords_min; - feature_vals[(int)Nyxus::Feature2D::ALLCHORDS_MIN_ANG][0] = allchords_min_angle; - feature_vals[(int)Nyxus::Feature2D::ALLCHORDS_MEDIAN][0] = allchords_median; - feature_vals[(int)Nyxus::Feature2D::ALLCHORDS_MEAN][0] = allchords_mean; - feature_vals[(int)Nyxus::Feature2D::ALLCHORDS_MODE][0] = allchords_mode; - feature_vals[(int)Nyxus::Feature2D::ALLCHORDS_STDDEV][0] = allchords_stddev; + feature_vals[static_cast(Nyxus::Feature2D::MAXCHORDS_MAX)][0] = maxchords_max; + feature_vals[static_cast(Nyxus::Feature2D::MAXCHORDS_MAX_ANG)][0] = maxchords_max_angle; + feature_vals[static_cast(Nyxus::Feature2D::MAXCHORDS_MIN)][0] = maxchords_min; + feature_vals[static_cast(Nyxus::Feature2D::MAXCHORDS_MIN_ANG)][0] = maxchords_min_angle; + feature_vals[static_cast(Nyxus::Feature2D::MAXCHORDS_MEDIAN)][0] = maxchords_median; + feature_vals[static_cast(Nyxus::Feature2D::MAXCHORDS_MEAN)][0] = maxchords_mean; + feature_vals[static_cast(Nyxus::Feature2D::MAXCHORDS_MODE)][0] = maxchords_mode; + feature_vals[static_cast(Nyxus::Feature2D::MAXCHORDS_STDDEV)][0] = maxchords_stddev; + feature_vals[static_cast(Nyxus::Feature2D::ALLCHORDS_MAX)][0] = allchords_max; + feature_vals[static_cast(Nyxus::Feature2D::ALLCHORDS_MAX_ANG)][0] = allchords_max_angle; + feature_vals[static_cast(Nyxus::Feature2D::ALLCHORDS_MIN)][0] = allchords_min; + feature_vals[static_cast(Nyxus::Feature2D::ALLCHORDS_MIN_ANG)][0] = allchords_min_angle; + feature_vals[static_cast(Nyxus::Feature2D::ALLCHORDS_MEDIAN)][0] = allchords_median; + feature_vals[static_cast(Nyxus::Feature2D::ALLCHORDS_MEAN)][0] = allchords_mean; + feature_vals[static_cast(Nyxus::Feature2D::ALLCHORDS_MODE)][0] = allchords_mode; + feature_vals[static_cast(Nyxus::Feature2D::ALLCHORDS_STDDEV)][0] = allchords_stddev; } diff --git a/src/nyx/features/circle.cpp b/src/nyx/features/circle.cpp index 2ecb5a885..d0ef34ef1 100644 --- a/src/nyx/features/circle.cpp +++ b/src/nyx/features/circle.cpp @@ -15,14 +15,14 @@ void EnclosingInscribingCircumscribingCircleFeature::calculate (LR& r, const Fse r.merge_multicontour(K); d_minEnclo = calculate_min_enclosing_circle_diam (K); - std::tie(d_inscr, d_circum) = calculate_inscribing_circumscribing_circle (K, r.fvals[(int)Feature2D::CENTROID_X][0], r.fvals[(int)Feature2D::CENTROID_Y][0]); + std::tie(d_inscr, d_circum) = calculate_inscribing_circumscribing_circle (K, r.fvals[static_cast(Feature2D::CENTROID_X)][0], r.fvals[static_cast(Feature2D::CENTROID_Y)][0]); } void EnclosingInscribingCircumscribingCircleFeature::save_value(std::vector>& fvals) { - fvals[(int)Nyxus::Feature2D::DIAMETER_MIN_ENCLOSING_CIRCLE][0] = d_minEnclo; - fvals[(int)Nyxus::Feature2D::DIAMETER_INSCRIBING_CIRCLE][0] = d_inscr; - fvals[(int)Nyxus::Feature2D::DIAMETER_CIRCUMSCRIBING_CIRCLE][0] = d_circum; + fvals[static_cast(Nyxus::Feature2D::DIAMETER_MIN_ENCLOSING_CIRCLE)][0] = d_minEnclo; + fvals[static_cast(Nyxus::Feature2D::DIAMETER_INSCRIBING_CIRCLE)][0] = d_inscr; + fvals[static_cast(Nyxus::Feature2D::DIAMETER_CIRCUMSCRIBING_CIRCLE)][0] = d_circum; } double EnclosingInscribingCircumscribingCircleFeature::calculate_min_enclosing_circle_diam (std::vector& Contour) @@ -77,25 +77,25 @@ void EnclosingInscribingCircumscribingCircleFeature::findCircle3pts (const std:: } float cx = (c1 * v2.y - c2 * v1.y) / det; float cy = (v1.x * c2 - v2.x * c1) / det; - center.x = (float)cx; - center.y = (float)cy; + center.x = static_cast(cx); + center.y = static_cast(cy); cx -= pts[0].x; cy -= pts[0].y; - radius = (float)(std::sqrt(cx * cx + cy * cy)) + EPS; + radius = static_cast((std::sqrt(cx * cx + cy * cy)) )+ EPS; } void EnclosingInscribingCircumscribingCircleFeature::findThirdPoint (const std::vector& pts, int i, int j, Point2f& center, float& radius) { - center.x = (float)(pts[j].x + pts[i].x) / 2.0f; - center.y = (float)(pts[j].y + pts[i].y) / 2.0f; - float dx = (float)(pts[j].x - pts[i].x); - float dy = (float)(pts[j].y - pts[i].y); - radius = (float)normL2(Point2f(dx, dy)) / 2.0f + EPS; + center.x = static_cast((pts[j].x + pts[i].x) )/ 2.0f; + center.y = static_cast((pts[j].y + pts[i].y) )/ 2.0f; + float dx = static_cast((pts[j].x - pts[i].x)); + float dy = static_cast((pts[j].y - pts[i].y)); + radius = static_cast(normL2(Point2f(dx, dy)) )/ 2.0f + EPS; for (int k = 0; k < j; k++) { - dx = center.x - (float)pts[k].x; - dy = center.y - (float)pts[k].y; + dx = center.x - static_cast(pts[k].x); + dy = center.y - static_cast(pts[k].y); if (normL2(Point2f(dx, dy)) < radius) continue; else @@ -117,16 +117,16 @@ void EnclosingInscribingCircumscribingCircleFeature::findThirdPoint (const std:: void EnclosingInscribingCircumscribingCircleFeature::findSecondPoint (const std::vector& pts, int i, Point2f& center, float& radius) { - center.x = (float)(pts[0].x + pts[i].x) / 2.0f; - center.y = (float)(pts[0].y + pts[i].y) / 2.0f; - float dx = (float)(pts[0].x - pts[i].x); - float dy = (float)(pts[0].y - pts[i].y); - radius = (float)normL2(Point2f(dx, dy)) / 2.0f + EPS; + center.x = static_cast((pts[0].x + pts[i].x) )/ 2.0f; + center.y = static_cast((pts[0].y + pts[i].y) )/ 2.0f; + float dx = static_cast((pts[0].x - pts[i].x)); + float dy = static_cast((pts[0].y - pts[i].y)); + radius = static_cast(normL2(Point2f(dx, dy)) )/ 2.0f + EPS; for (int j = 1; j < i; j++) { - dx = center.x - (float)pts[j].x; - dy = center.y - (float)pts[j].y; + dx = center.x - static_cast(pts[j].x); + dy = center.y - static_cast(pts[j].y); if (normL2(Point2f(dx, dy)) < radius) continue; else @@ -144,18 +144,18 @@ void EnclosingInscribingCircumscribingCircleFeature::findSecondPoint (const std: void EnclosingInscribingCircumscribingCircleFeature::findMinEnclosingCircle (const std::vector& contour, Point2f& center, float& radius) { - center.x = (float)(contour[0].x + contour[1].x) / 2.0f; - center.y = (float)(contour[0].y + contour[1].y) / 2.0f; - float dx = (float)(contour[0].x - contour[1].x), - dy = (float)(contour[0].y - contour[1].y); - radius = (float)normL2(Point2f(dx, dy)) / 2.0f + EPS; + center.x = static_cast((contour[0].x + contour[1].x) )/ 2.0f; + center.y = static_cast((contour[0].y + contour[1].y) )/ 2.0f; + float dx = static_cast((contour[0].x - contour[1].x)), + dy = static_cast((contour[0].y - contour[1].y)); + radius = static_cast(normL2(Point2f(dx, dy)) )/ 2.0f + EPS; auto count = contour.size(); for (auto i = 2; i < count; i++) { - dx = (float)contour[i].x - center.x; - dy = (float)contour[i].y - center.y; - float d = (float)normL2(Point2f(dx, dy)); + dx = static_cast(contour[i].x )- center.x; + dy = static_cast(contour[i].y )- center.y; + float d = static_cast(normL2(Point2f(dx, dy))); if (d < radius) continue; else @@ -190,17 +190,17 @@ void EnclosingInscribingCircumscribingCircleFeature::minEnclosingCircle( { case 1: { - _center = Point2f ((float)Contour[0].x, (float)Contour[0].y); //(is_float) ? ptsf[0] : Point2f((float)ptsi[0].x, (float)ptsi[0].y); + _center = Point2f (static_cast(Contour[0].x), static_cast(Contour[0].y)); //(is_float) ? ptsf[0] : Point2f((float)ptsi[0].x, (float)ptsi[0].y); _radius = EPS; break; } case 2: { - Point2f p1 = Point2f ((float)Contour[0].x, (float)Contour[0].y); //(is_float) ? ptsf[0] : Point2f((float)ptsi[0].x, (float)ptsi[0].y); - Point2f p2 = Point2f ((float)Contour[1].x, (float)Contour[1].y); //(is_float) ? ptsf[1] : Point2f((float)ptsi[1].x, (float)ptsi[1].y); + Point2f p1 = Point2f (static_cast(Contour[0].x), static_cast(Contour[0].y)); //(is_float) ? ptsf[0] : Point2f((float)ptsi[0].x, (float)ptsi[0].y); + Point2f p2 = Point2f (static_cast(Contour[1].x), static_cast(Contour[1].y)); //(is_float) ? ptsf[1] : Point2f((float)ptsi[1].x, (float)ptsi[1].y); _center.x = (p1.x + p2.x) / 2.0f; _center.y = (p1.y + p2.y) / 2.0f; - _radius = (float)(normL2(p1 - p2) / 2.0) + EPS; + _radius = static_cast((normL2(p1 - p2) / 2.0) )+ EPS; break; } default: diff --git a/src/nyx/features/circle.h b/src/nyx/features/circle.h index be0d7f6d9..157a4f9fe 100644 --- a/src/nyx/features/circle.h +++ b/src/nyx/features/circle.h @@ -14,7 +14,7 @@ class EnclosingInscribingCircumscribingCircleFeature: public FeatureMethod { public: - const constexpr static std::initializer_list featureset = + static constexpr std::initializer_list featureset = { Nyxus::Feature2D::DIAMETER_MIN_ENCLOSING_CIRCLE, Nyxus::Feature2D::DIAMETER_INSCRIBING_CIRCLE, diff --git a/src/nyx/features/contour.cpp b/src/nyx/features/contour.cpp index f2b035a6c..503b24f59 100644 --- a/src/nyx/features/contour.cpp +++ b/src/nyx/features/contour.cpp @@ -196,8 +196,8 @@ ContourFeature::ContourFeature() : FeatureMethod("ContourFeature") std::vector cands10; for (const Pixel2& px : unordered) { - auto dx = std::fabs((int)px.x - (int)tip.x), - dy = std::fabs((int)px.y - (int)tip.y); + auto dx = std::fabs(static_cast(px.x )- static_cast(tip.x)), + dy = std::fabs(static_cast(px.y )- static_cast(tip.y)); if (dx+dy>1) continue; cands10.push_back (px); @@ -212,8 +212,8 @@ ContourFeature::ContourFeature() : FeatureMethod("ContourFeature") for (const Pixel2& px : unordered) { - auto dx = std::fabs((int)px.x - (int)tip.x), - dy = std::fabs((int)px.y - (int)tip.y); + auto dx = std::fabs(static_cast(px.x )- static_cast(tip.x)), + dy = std::fabs(static_cast(px.y )- static_cast(tip.y)); if (dx==1 && dy==1) cands11.push_back(px); } @@ -381,23 +381,23 @@ ContourFeature::ContourFeature() : FeatureMethod("ContourFeature") return looplen; } -/*static*/ void ContourFeature::gather_multicontour ( - // out - std::vector>& multicountour, +/*static*/ void ContourFeature::gather_multicontour ( + // out + std::vector>& multicountour, // in std::vector P, // padded image - int w, - int h, - int verbose) -{ - // This function fills the caller-owned contour container from scratch. - // Clearing it up front prevents stale contours from surviving the early - // return below when a ROI degenerates to isolated speckles. - multicountour.clear(); - - const int BLANK = 0; - bool inside = false; - int pos = 0; + int w, + int h, + int verbose) +{ + // This function fills the caller-owned contour container from scratch. + // Clearing it up front prevents stale contours from surviving the early + // return below when a ROI degenerates to isolated speckles. + multicountour.clear(); + + const int BLANK = 0; + bool inside = false; + int pos = 0; //==== Prepare a contour ("border") image std::vector borderImage((h + 2) * (w + 2), 0); @@ -643,22 +643,22 @@ ContourFeature::ContourFeature() : FeatureMethod("ContourFeature") } } -/*static*/ void ContourFeature::buildRegularContour(LR& r, const Fsettings& s) -{ - // cast ROI's pixel cloud to a padded image +/*static*/ void ContourFeature::buildRegularContour(LR& r, const Fsettings& s) +{ + // cast ROI's pixel cloud to a padded image int width = r.aabb.get_width(), height = r.aabb.get_height(), base_x = r.aabb.get_xmin(), base_y = r.aabb.get_ymin(); - int paddingColor = 0; - std::vector paddedImage((height + 2) * (width + 2), paddingColor); - - // Rebuild the contour cache from scratch for this ROI. - r.multicontour_.clear(); - - for (auto px : r.raw_pixels) - { + int paddingColor = 0; + std::vector paddedImage((height + 2) * (width + 2), paddingColor); + + // Rebuild the contour cache from scratch for this ROI. + r.multicontour_.clear(); + + for (auto px : r.raw_pixels) + { auto x = px.x - base_x + 1, y = px.y - base_y + 1; paddedImage.at(x + y * (width + 2)) = px.inten + 1; // we build a contour keeping corresponding intensities @@ -846,8 +846,8 @@ void ContourFeature::buildRegularContour_nontriv (LR& r, const Fsettings& s) for (Pixel2& px : unordered) { // --test for proximity and skio non-neighbors - auto dx = std::fabs((int)px.x - (int)pxTip.x), - dy = std::fabs((int)px.y - (int)pxTip.y); + auto dx = std::fabs(static_cast(px.x )- static_cast(pxTip.x)), + dy = std::fabs(static_cast(px.y )- static_cast(pxTip.y)); if (dx > 1 || dy > 1) continue; // not a neighbor of pxTip @@ -857,12 +857,12 @@ void ContourFeature::buildRegularContour_nontriv (LR& r, const Fsettings& s) if (!cands.empty()) { - int distMin = (int)pxTip.sqdist(cands[0]); + int distMin = static_cast(pxTip.sqdist(cands[0])); int idxMin = 0; for (int i = 1; i < cands.size(); i++) { Pixel2& px = cands[i]; - int dist = (int)pxTip.sqdist(cands[i]); + int dist = static_cast(pxTip.sqdist(cands[i])); if (dist < distMin) { idxMin = i; @@ -996,7 +996,7 @@ void ContourFeature::osized_calculate (LR& r, const Fsettings& s, ImageLoader& i r.merge_multicontour(K); //=== Calculate the features - fval_PERIMETER = (StatsInt) K.size(); + fval_PERIMETER = static_cast(K.size()); fval_DIAMETER_EQUAL_PERIMETER = fval_PERIMETER / M_PI; auto [cmin, cmax, cmean, cstddev] = calc_min_max_mean_stddev_intensity (K); fval_EDGE_MEAN_INTENSITY = cmean; @@ -1011,13 +1011,13 @@ void ContourFeature::osized_calculate (LR& r, const Fsettings& s, ImageLoader& i void ContourFeature::save_value(std::vector>& fvals) { - fvals[(int)Feature2D::PERIMETER][0] = fval_PERIMETER; - fvals[(int)Feature2D::DIAMETER_EQUAL_PERIMETER][0] = fval_DIAMETER_EQUAL_PERIMETER; - fvals[(int)Feature2D::EDGE_MEAN_INTENSITY][0] = fval_EDGE_MEAN_INTENSITY; - fvals[(int)Feature2D::EDGE_STDDEV_INTENSITY][0] = fval_EDGE_STDDEV_INTENSITY; - fvals[(int)Feature2D::EDGE_MAX_INTENSITY][0] = fval_EDGE_MAX_INTENSITY; - fvals[(int)Feature2D::EDGE_MIN_INTENSITY][0] = fval_EDGE_MIN_INTENSITY; - fvals[(int)Feature2D::EDGE_INTEGRATED_INTENSITY][0] = fval_EDGE_INTEGRATEDINTENSITY; + fvals[static_cast(Feature2D::PERIMETER)][0] = fval_PERIMETER; + fvals[static_cast(Feature2D::DIAMETER_EQUAL_PERIMETER)][0] = fval_DIAMETER_EQUAL_PERIMETER; + fvals[static_cast(Feature2D::EDGE_MEAN_INTENSITY)][0] = fval_EDGE_MEAN_INTENSITY; + fvals[static_cast(Feature2D::EDGE_STDDEV_INTENSITY)][0] = fval_EDGE_STDDEV_INTENSITY; + fvals[static_cast(Feature2D::EDGE_MAX_INTENSITY)][0] = fval_EDGE_MAX_INTENSITY; + fvals[static_cast(Feature2D::EDGE_MIN_INTENSITY)][0] = fval_EDGE_MIN_INTENSITY; + fvals[static_cast(Feature2D::EDGE_INTEGRATED_INTENSITY)][0] = fval_EDGE_INTEGRATEDINTENSITY; } void ContourFeature::cleanup_instance() diff --git a/src/nyx/features/contour.h b/src/nyx/features/contour.h index 99b669f3f..64cacd42f 100644 --- a/src/nyx/features/contour.h +++ b/src/nyx/features/contour.h @@ -14,7 +14,7 @@ class ContourFeature: public FeatureMethod { public: - const constexpr static std::initializer_list featureset = + static constexpr std::initializer_list featureset = { Nyxus::Feature2D::PERIMETER, Nyxus::Feature2D::DIAMETER_EQUAL_PERIMETER, diff --git a/src/nyx/features/convex_hull.h b/src/nyx/features/convex_hull.h index 7b5f989bc..9b9581571 100644 --- a/src/nyx/features/convex_hull.h +++ b/src/nyx/features/convex_hull.h @@ -9,7 +9,7 @@ class ConvexHullFeature : public FeatureMethod { public: - const constexpr static std::initializer_list featureset = + static constexpr std::initializer_list featureset = { Nyxus::Feature2D::CONVEX_HULL_AREA, Nyxus::Feature2D::SOLIDITY, diff --git a/src/nyx/features/convex_hull_nontriv.cpp b/src/nyx/features/convex_hull_nontriv.cpp index d780e84a7..4a626da14 100644 --- a/src/nyx/features/convex_hull_nontriv.cpp +++ b/src/nyx/features/convex_hull_nontriv.cpp @@ -25,8 +25,8 @@ static long hull_boundary_points (const std::vector& v) { const Pixel2& p1 = v[i]; const Pixel2& p2 = v[(i + 1) % n]; - long dx = (long)p2.x - (long)p1.x; if (dx < 0) dx = -dx; - long dy = (long)p2.y - (long)p1.y; if (dy < 0) dy = -dy; + long dx = static_cast(p2.x )- static_cast(p1.x); if (dx < 0) dx = -dx; + long dy = static_cast(p2.y )- static_cast(p1.y); if (dy < 0) dy = -dy; B += std::gcd(dx, dy); } return B; @@ -40,9 +40,9 @@ ConvexHullFeature::ConvexHullFeature() : FeatureMethod("ConvexHullFeature") void ConvexHullFeature::save_value(std::vector>& fvals) { - fvals [(int)Feature2D::CONVEX_HULL_AREA][0] = area; - fvals [(int)Feature2D::SOLIDITY][0] = solidity; - fvals [(int)Feature2D::CIRCULARITY][0] = circularity; + fvals [static_cast(Feature2D::CONVEX_HULL_AREA)][0] = area; + fvals [static_cast(Feature2D::SOLIDITY)][0] = solidity; + fvals [static_cast(Feature2D::CIRCULARITY)][0] = circularity; } void ConvexHullFeature::cleanup_instance() @@ -59,7 +59,7 @@ void ConvexHullFeature::calculate (LR& r, const Fsettings& s) // measured on the same basis as the ROI (pixel count) -> SOLIDITY <= 1. double s_hull = polygon_area(r.convHull_CH) + hull_boundary_points(r.convHull_CH) / 2.0 + 1.0, s_roi = r.raw_pixels.size(), - p = r.fvals[(int)Feature2D::PERIMETER][0]; + p = r.fvals[static_cast(Feature2D::PERIMETER)][0]; area = s_hull; solidity = (s_hull > 0.0) ? s_roi / s_hull : 0.0; circularity = sqrt(4.0 * M_PI * s_roi / (p*p)); @@ -220,7 +220,7 @@ void ConvexHullFeature::osized_calculate (LR& r, const Fsettings& s, ImageLoader // Calculate related features (Pick's-theorem pixel-count-equivalent hull area; see calculate()) double s_hull = polygon_area(r.convHull_CH) + hull_boundary_points(r.convHull_CH) / 2.0 + 1.0, s_roi = r.raw_pixels_NT.size(), - p = r.fvals[(int)Feature2D::PERIMETER][0]; + p = r.fvals[static_cast(Feature2D::PERIMETER)][0]; area = s_hull; solidity = (s_hull > 0.0) ? s_roi / s_hull : 0.0; circularity = sqrt(4.0 * M_PI * s_roi / (p * p)); diff --git a/src/nyx/features/ellipse_fitting.cpp b/src/nyx/features/ellipse_fitting.cpp index fc2f5a18d..458bcfd4d 100644 --- a/src/nyx/features/ellipse_fitting.cpp +++ b/src/nyx/features/ellipse_fitting.cpp @@ -27,9 +27,9 @@ void EllipseFittingFeature::calculate (LR& r, const Fsettings& s) { // Idea: calculate normalized second central moments for the region. 1/12 is the normalized second central moment of a pixel with unit length. - double centroid_x = r.fvals[(int)Feature2D::CENTROID_X][0], - centroid_y = r.fvals[(int)Feature2D::CENTROID_Y][0], - area = r.fvals[(int)Feature2D::AREA_PIXELS_COUNT][0]; + double centroid_x = r.fvals[static_cast(Feature2D::CENTROID_X)][0], + centroid_y = r.fvals[static_cast(Feature2D::CENTROID_Y)][0], + area = r.fvals[static_cast(Feature2D::AREA_PIXELS_COUNT)][0]; double xSquaredTmp = 0, ySquaredTmp = 0, @@ -44,7 +44,7 @@ void EllipseFittingFeature::calculate (LR& r, const Fsettings& s) xySquaredTmp += diffX * diffY; } - double n = (double) r.raw_pixels.size(); + double n = static_cast(r.raw_pixels.size()); double uxx = xSquaredTmp / n + 1. / 12.; double uyy = ySquaredTmp / n + 1. / 12.; double uxy = xySquaredTmp / n; @@ -136,9 +136,9 @@ void EllipseFittingFeature::osized_calculate (LR& r, const Fsettings& s, ImageLo { // Idea: calculate normalized second central moments for the region. 1/12 is the normalized second central moment of a pixel with unit length. - double centroid_x = r.fvals[(int)Feature2D::CENTROID_X][0], - centroid_y = r.fvals[(int)Feature2D::CENTROID_Y][0], - area = r.fvals[(int)Feature2D::AREA_PIXELS_COUNT][0]; + double centroid_x = r.fvals[static_cast(Feature2D::CENTROID_X)][0], + centroid_y = r.fvals[static_cast(Feature2D::CENTROID_Y)][0], + area = r.fvals[static_cast(Feature2D::AREA_PIXELS_COUNT)][0]; double xSquaredTmp = 0, ySquaredTmp = 0, @@ -153,7 +153,7 @@ void EllipseFittingFeature::osized_calculate (LR& r, const Fsettings& s, ImageLo xySquaredTmp += diffX * diffY; } - double n = (double) r.raw_pixels_NT.size(); + double n = static_cast(r.raw_pixels_NT.size()); double uxx = xSquaredTmp / n + 1. / 12.; double uyy = ySquaredTmp / n + 1. / 12.; double uxy = xySquaredTmp / n; @@ -192,10 +192,10 @@ void EllipseFittingFeature::osized_calculate (LR& r, const Fsettings& s, ImageLo void EllipseFittingFeature::save_value (std::vector>& fvals) { - fvals[(int)Feature2D::MAJOR_AXIS_LENGTH][0] = get_major_axis_length(); - fvals[(int)Feature2D::MINOR_AXIS_LENGTH][0] = get_minor_axis_length(); - fvals[(int)Feature2D::ECCENTRICITY][0] = get_eccentricity(); - fvals[(int)Feature2D::ELONGATION][0] = get_elongation(); - fvals[(int)Feature2D::ORIENTATION][0] = get_orientation(); - fvals[(int)Feature2D::ROUNDNESS][0] = get_roundness(); + fvals[static_cast(Feature2D::MAJOR_AXIS_LENGTH)][0] = get_major_axis_length(); + fvals[static_cast(Feature2D::MINOR_AXIS_LENGTH)][0] = get_minor_axis_length(); + fvals[static_cast(Feature2D::ECCENTRICITY)][0] = get_eccentricity(); + fvals[static_cast(Feature2D::ELONGATION)][0] = get_elongation(); + fvals[static_cast(Feature2D::ORIENTATION)][0] = get_orientation(); + fvals[static_cast(Feature2D::ROUNDNESS)][0] = get_roundness(); } \ No newline at end of file diff --git a/src/nyx/features/ellipse_fitting.h b/src/nyx/features/ellipse_fitting.h index bfa1c8b89..9ca970349 100644 --- a/src/nyx/features/ellipse_fitting.h +++ b/src/nyx/features/ellipse_fitting.h @@ -13,7 +13,7 @@ class EllipseFittingFeature: public FeatureMethod { public: - const constexpr static std::initializer_list featureset = + static constexpr std::initializer_list featureset = { Nyxus::Feature2D::MAJOR_AXIS_LENGTH, Nyxus::Feature2D::MINOR_AXIS_LENGTH, diff --git a/src/nyx/features/erosion.cpp b/src/nyx/features/erosion.cpp index 18611c9f9..d387357ee 100644 --- a/src/nyx/features/erosion.cpp +++ b/src/nyx/features/erosion.cpp @@ -25,7 +25,7 @@ void ErosionPixelsFeature::calculate (LR& r, const Fsettings& s) minx = r.aabb.get_xmin(), miny = r.aabb.get_ymin(); - SimpleMatrix I2((int)width, (int)height); + SimpleMatrix I2(static_cast(width), static_cast(height)); for (auto px : r.raw_pixels) { @@ -37,8 +37,8 @@ void ErosionPixelsFeature::calculate (LR& r, const Fsettings& s) } // structural element's half-width and height - auto halfHeight = (int)floor(SE_R / 2); - auto halfWidth = (int)floor(SE_C / 2); + auto halfHeight = static_cast(floor(SE_R / 2)); + auto halfWidth = static_cast(floor(SE_C / 2)); // Initialize output image std::vector Nv; @@ -121,8 +121,8 @@ void ErosionPixelsFeature::osized_calculate (LR& r, const Fsettings& s, ImageLoa WriteImageMatrix_nontriv I2("I2", r.label); I2.allocate_from_cloud (r.raw_pixels_NT, r.aabb, true); - auto halfHeight = (int)floor(SE_R / 2); - auto halfWidth = (int)floor(SE_C / 2); + auto halfHeight = static_cast(floor(SE_R / 2)); + auto halfWidth = static_cast(floor(SE_C / 2)); // Initialize output image std::vector Nv; @@ -195,7 +195,7 @@ void ErosionPixelsFeature::osized_calculate (LR& r, const Fsettings& s, ImageLoa void ErosionPixelsFeature::save_value(std::vector>& fvals) { - fvals[(int)Feature2D::EROSIONS_2_VANISH][0] = numErosions; + fvals[static_cast(Feature2D::EROSIONS_2_VANISH)][0] = numErosions; } void ErosionPixelsFeature::extract (LR& r, const Fsettings& s) diff --git a/src/nyx/features/erosion.h b/src/nyx/features/erosion.h index b1660692a..4bbc07427 100644 --- a/src/nyx/features/erosion.h +++ b/src/nyx/features/erosion.h @@ -12,7 +12,7 @@ class ErosionPixelsFeature: public FeatureMethod { public: - const constexpr static std::initializer_list featureset = + static constexpr std::initializer_list featureset = { Nyxus::Feature2D::EROSIONS_2_VANISH, Nyxus::Feature2D::EROSIONS_2_VANISH_COMPLEMENT diff --git a/src/nyx/features/euler_number.cpp b/src/nyx/features/euler_number.cpp index d971f18f1..0444c763d 100644 --- a/src/nyx/features/euler_number.cpp +++ b/src/nyx/features/euler_number.cpp @@ -26,17 +26,17 @@ void EulerNumberFeature::calculate (LR& r, const Fsettings& s) max_y = aabb.get_ymax(); // Create the image mask matrix - int ny = max_y - min_y + 3, - nx = max_x - min_x + 3, - n = nx * ny; - std::vector I(n, 0); - for (auto& p : cloud) - { - int col = p.x - min_x + 1, - row = p.y - min_y + 1, - idx = row * nx + col; - I[idx] = 1; - } + int ny = max_y - min_y + 3, + nx = max_x - min_x + 3, + n = nx * ny; + std::vector I(n, 0); + for (auto& p : cloud) + { + int col = p.x - min_x + 1, + row = p.y - min_y + 1, + idx = row * nx + col; + I[idx] = 1; + } euler_number = calculate_euler (I, ny, nx, mode); } @@ -85,9 +85,9 @@ long EulerNumberFeature::calculate_euler (std::vector & arr, int C3++; } else - if (i == 8 || i == 9) { - Cd++; - } + if (i == 8 || i == 9) { + Cd++; + } } } @@ -99,7 +99,7 @@ long EulerNumberFeature::calculate_euler (std::vector & arr, int void EulerNumberFeature::save_value(std::vector>& fvals) { - fvals[(int)Feature2D::EULER_NUMBER][0] = euler_number; + fvals[static_cast(Feature2D::EULER_NUMBER)][0] = euler_number; } void EulerNumberFeature::extract (LR& r, const Fsettings& s) @@ -142,9 +142,9 @@ void EulerNumberFeature::osized_calculate (LR& r, const Fsettings& s, ImageLoade max_y = aabb.get_ymax(); // Create the image mask matrix - int height = max_y - min_y + 3, - width = max_x - min_x + 3, - n = width * height; + int height = max_y - min_y + 3, + width = max_x - min_x + 3, + n = width * height; //std::vector I(n, 0); WriteImageMatrix_nontriv I ("I", r.label); @@ -160,11 +160,11 @@ void EulerNumberFeature::osized_calculate (LR& r, const Fsettings& s, ImageLoade for (auto i = 0; i < cloud.size(); i++) { const auto& p = cloud.get_at(i); - int col = p.x - min_x + 1, - row = p.y - min_y + 1, - idx = row * width + col; - I.set_at (idx, 1); - } + int col = p.x - min_x + 1, + row = p.y - min_y + 1, + idx = row * width + col; + I.set_at (idx, 1); + } //euler_number = calculate_euler(I, ny, nx, mode); @@ -203,9 +203,9 @@ void EulerNumberFeature::osized_calculate (LR& r, const Fsettings& s, ImageLoade C3++; } else - if (i == 8 || i == 9) { - Cd++; - } + if (i == 8 || i == 9) { + Cd++; + } } } diff --git a/src/nyx/features/euler_number.h b/src/nyx/features/euler_number.h index c7d709cb7..34a81a836 100644 --- a/src/nyx/features/euler_number.h +++ b/src/nyx/features/euler_number.h @@ -15,7 +15,7 @@ class EulerNumberFeature: public FeatureMethod { public: - const constexpr static std::initializer_list featureset = { Nyxus::Feature2D::EULER_NUMBER }; + static constexpr std::initializer_list featureset = { Nyxus::Feature2D::EULER_NUMBER }; EulerNumberFeature(); diff --git a/src/nyx/features/extrema.cpp b/src/nyx/features/extrema.cpp index 1dd01b012..b1a924c05 100644 --- a/src/nyx/features/extrema.cpp +++ b/src/nyx/features/extrema.cpp @@ -31,27 +31,27 @@ void ExtremaFeature::calculate (LR& r, const Fsettings& s) for (Pixel2 p : r.raw_pixels) { // Find leftmost and rightmost x-pixels of the top - if (p.y == TopMost && (TopMost_MostLeft == -1 || p.x < (StatsInt)TopMost_MostLeft)) + if (p.y == TopMost && (TopMost_MostLeft == -1 || p.x < static_cast(TopMost_MostLeft))) TopMost_MostLeft = p.x; - if (p.y == TopMost && (TopMost_MostRight == -1 || p.x > (StatsInt)TopMost_MostRight)) + if (p.y == TopMost && (TopMost_MostRight == -1 || p.x > static_cast(TopMost_MostRight))) TopMost_MostRight = p.x; // Find leftmost and rightmost x-pixels of the bottom - if (p.y == Lowest && (Lowest_MostLeft == -1 || p.x < (StatsInt)Lowest_MostLeft)) + if (p.y == Lowest && (Lowest_MostLeft == -1 || p.x < static_cast(Lowest_MostLeft))) Lowest_MostLeft = p.x; - if (p.y == Lowest && (Lowest_MostRight == -1 || p.x > (StatsInt)Lowest_MostRight)) + if (p.y == Lowest && (Lowest_MostRight == -1 || p.x > static_cast(Lowest_MostRight))) Lowest_MostRight = p.x; // Find top and bottom y-pixels of the leftmost - if (p.x == LeftMost && (LeftMost_Top == -1 || p.y < (StatsInt)LeftMost_Top)) + if (p.x == LeftMost && (LeftMost_Top == -1 || p.y < static_cast(LeftMost_Top))) LeftMost_Top = p.y; - if (p.x == LeftMost && (LeftMost_Bottom == -1 || p.y > (StatsInt)LeftMost_Bottom)) + if (p.x == LeftMost && (LeftMost_Bottom == -1 || p.y > static_cast(LeftMost_Bottom))) LeftMost_Bottom = p.y; // Find top and bottom y-pixels of the rightmost - if (p.x == RightMost && (RightMost_Top == -1 || p.y < (StatsInt)RightMost_Top)) + if (p.x == RightMost && (RightMost_Top == -1 || p.y < static_cast(RightMost_Top))) RightMost_Top = p.y; - if (p.x == RightMost && (RightMost_Bottom == -1 || p.y > (StatsInt)RightMost_Bottom)) + if (p.x == RightMost && (RightMost_Bottom == -1 || p.y > static_cast(RightMost_Bottom))) RightMost_Bottom = p.y; } @@ -94,27 +94,27 @@ void ExtremaFeature::osized_calculate (LR& r, const Fsettings& s, ImageLoader& i Pixel2 p = r.raw_pixels_NT.get_at(i); // Find leftmost and rightmost x-pixels of the top - if (p.y == TopMost && (TopMost_MostLeft == -1 || p.x < (StatsInt)TopMost_MostLeft)) + if (p.y == TopMost && (TopMost_MostLeft == -1 || p.x < static_cast(TopMost_MostLeft))) TopMost_MostLeft = p.x; - if (p.y == TopMost && (TopMost_MostRight == -1 || p.x > (StatsInt)TopMost_MostRight)) + if (p.y == TopMost && (TopMost_MostRight == -1 || p.x > static_cast(TopMost_MostRight))) TopMost_MostRight = p.x; // Find leftmost and rightmost x-pixels of the bottom - if (p.y == Lowest && (Lowest_MostLeft == -1 || p.x < (StatsInt)Lowest_MostLeft)) + if (p.y == Lowest && (Lowest_MostLeft == -1 || p.x < static_cast(Lowest_MostLeft))) Lowest_MostLeft = p.x; - if (p.y == Lowest && (Lowest_MostRight == -1 || p.x > (StatsInt)Lowest_MostRight)) + if (p.y == Lowest && (Lowest_MostRight == -1 || p.x > static_cast(Lowest_MostRight))) Lowest_MostRight = p.x; // Find top and bottom y-pixels of the leftmost - if (p.x == LeftMost && (LeftMost_Top == -1 || p.y < (StatsInt)LeftMost_Top)) + if (p.x == LeftMost && (LeftMost_Top == -1 || p.y < static_cast(LeftMost_Top))) LeftMost_Top = p.y; - if (p.x == LeftMost && (LeftMost_Bottom == -1 || p.y > (StatsInt)LeftMost_Bottom)) + if (p.x == LeftMost && (LeftMost_Bottom == -1 || p.y > static_cast(LeftMost_Bottom))) LeftMost_Bottom = p.y; // Find top and bottom y-pixels of the rightmost - if (p.x == RightMost && (RightMost_Top == -1 || p.y < (StatsInt)RightMost_Top)) + if (p.x == RightMost && (RightMost_Top == -1 || p.y < static_cast(RightMost_Top))) RightMost_Top = p.y; - if (p.x == RightMost && (RightMost_Bottom == -1 || p.y > (StatsInt)RightMost_Bottom)) + if (p.x == RightMost && (RightMost_Bottom == -1 || p.y > static_cast(RightMost_Bottom))) RightMost_Bottom = p.y; } @@ -153,22 +153,22 @@ std::tuple>& fvals) { - fvals [(int)Feature2D::EXTREMA_P1_Y][0] = y1; - fvals [(int)Feature2D::EXTREMA_P1_X][0] = x1; - fvals [(int)Feature2D::EXTREMA_P2_Y][0] = y2; - fvals [(int)Feature2D::EXTREMA_P2_X][0] = x2; - fvals [(int)Feature2D::EXTREMA_P3_Y][0] = y3; - fvals [(int)Feature2D::EXTREMA_P3_X][0] = x3; - fvals [(int)Feature2D::EXTREMA_P4_Y][0] = y4; - fvals [(int)Feature2D::EXTREMA_P4_X][0] = x4; - fvals [(int)Feature2D::EXTREMA_P5_Y][0] = y5; - fvals [(int)Feature2D::EXTREMA_P5_X][0] = x5; - fvals [(int)Feature2D::EXTREMA_P6_Y][0] = y6; - fvals [(int)Feature2D::EXTREMA_P6_X][0] = x6; - fvals [(int)Feature2D::EXTREMA_P7_Y][0] = y7; - fvals [(int)Feature2D::EXTREMA_P7_X][0] = x7; - fvals [(int)Feature2D::EXTREMA_P8_Y][0] = y8; - fvals [(int)Feature2D::EXTREMA_P8_X][0] = x8; + fvals [static_cast(Feature2D::EXTREMA_P1_Y)][0] = y1; + fvals [static_cast(Feature2D::EXTREMA_P1_X)][0] = x1; + fvals [static_cast(Feature2D::EXTREMA_P2_Y)][0] = y2; + fvals [static_cast(Feature2D::EXTREMA_P2_X)][0] = x2; + fvals [static_cast(Feature2D::EXTREMA_P3_Y)][0] = y3; + fvals [static_cast(Feature2D::EXTREMA_P3_X)][0] = x3; + fvals [static_cast(Feature2D::EXTREMA_P4_Y)][0] = y4; + fvals [static_cast(Feature2D::EXTREMA_P4_X)][0] = x4; + fvals [static_cast(Feature2D::EXTREMA_P5_Y)][0] = y5; + fvals [static_cast(Feature2D::EXTREMA_P5_X)][0] = x5; + fvals [static_cast(Feature2D::EXTREMA_P6_Y)][0] = y6; + fvals [static_cast(Feature2D::EXTREMA_P6_X)][0] = x6; + fvals [static_cast(Feature2D::EXTREMA_P7_Y)][0] = y7; + fvals [static_cast(Feature2D::EXTREMA_P7_X)][0] = x7; + fvals [static_cast(Feature2D::EXTREMA_P8_Y)][0] = y8; + fvals [static_cast(Feature2D::EXTREMA_P8_X)][0] = x8; } void ExtremaFeature::extract (LR& r, const Fsettings& s) diff --git a/src/nyx/features/extrema.h b/src/nyx/features/extrema.h index da153c168..2364153e8 100644 --- a/src/nyx/features/extrema.h +++ b/src/nyx/features/extrema.h @@ -13,7 +13,7 @@ class ExtremaFeature: public FeatureMethod { public: - const constexpr static std::initializer_list featureset = + static constexpr std::initializer_list featureset = { Nyxus::Feature2D::EXTREMA_P1_Y, Nyxus::Feature2D::EXTREMA_P1_X, diff --git a/src/nyx/features/focus_score.cpp b/src/nyx/features/focus_score.cpp index 5a06726a3..0c02a741c 100644 --- a/src/nyx/features/focus_score.cpp +++ b/src/nyx/features/focus_score.cpp @@ -84,8 +84,8 @@ void FocusScoreFeature::osized_calculate (LR& r, const Fsettings& s, ImageLoader void FocusScoreFeature::save_value(std::vector>& feature_vals) { - feature_vals[(int)FeatureIMQ::FOCUS_SCORE][0] = focus_score_; - feature_vals[(int)FeatureIMQ::LOCAL_FOCUS_SCORE][0] = local_focus_score_; + feature_vals[static_cast(FeatureIMQ::FOCUS_SCORE)][0] = focus_score_; + feature_vals[static_cast(FeatureIMQ::LOCAL_FOCUS_SCORE)][0] = local_focus_score_; } @@ -110,7 +110,7 @@ double FocusScoreFeature::get_focus_score_NT(WriteImageMatrix_nontriv& Im, int k auto width = Im.get_width(), height = Im.get_height(); - auto xy0 = (int)ceil(double(n) / 2.); + auto xy0 = static_cast(ceil(double(n) / 2.)); // Window (N-fold kernel size) int winX = n * 10, diff --git a/src/nyx/features/focus_score.h b/src/nyx/features/focus_score.h index efe4040a3..3717a1662 100644 --- a/src/nyx/features/focus_score.h +++ b/src/nyx/features/focus_score.h @@ -13,7 +13,7 @@ class FocusScoreFeature: public FeatureMethod { public: - const constexpr static std::initializer_list featureset = { Nyxus::FeatureIMQ::FOCUS_SCORE, Nyxus::FeatureIMQ::LOCAL_FOCUS_SCORE}; + static constexpr std::initializer_list featureset = { Nyxus::FeatureIMQ::FOCUS_SCORE, Nyxus::FeatureIMQ::LOCAL_FOCUS_SCORE}; FocusScoreFeature(); diff --git a/src/nyx/features/fractal_dim.cpp b/src/nyx/features/fractal_dim.cpp index cb4e394b6..9dee19804 100644 --- a/src/nyx/features/fractal_dim.cpp +++ b/src/nyx/features/fractal_dim.cpp @@ -34,7 +34,7 @@ void FractalDimensionFeature::calculate_boxcount_fdim (LR & r) // those are cheap to shift. So auto-switch: // - large ROI -> single origin grid via the padded mask matrix (fast early-exit tile scan) // - small ROI -> shift the grid over a few origins and take the minimum box count - int bigSide = (int)std::max(r.aabb.get_width(), r.aabb.get_height()); + int bigSide = static_cast(std::max(r.aabb.get_width(), r.aabb.get_height())); int paddedSide = Nyxus::ceil_pow2(bigSide); std::vector> coverage; @@ -71,7 +71,7 @@ void FractalDimensionFeature::calculate_boxcount_fdim (LR & r) for (int s = paddedSide; s > 1; s >>= 1, --shift) { int span = (paddedSide >> shift) + 2; // boxes per axis (+slack for the origin shift) - occ.assign((size_t)span * span, 0); + occ.assign(static_cast(span )* span, 0); int best = -1; for (int oyi = 0; oyi < n_off; oyi++) for (int oxi = 0; oxi < n_off; oxi++) @@ -80,15 +80,15 @@ void FractalDimensionFeature::calculate_boxcount_fdim (LR & r) int cnt = 0; for (const Pixel2& p : px) { - int col = (int)(p.x - xmin + ox) >> shift; - int row = (int)(p.y - ymin + oy) >> shift; - size_t idx = (size_t)row * span + col; + int col = static_cast((p.x - xmin + ox) )>> shift; + int row = static_cast((p.y - ymin + oy) )>> shift; + size_t idx = static_cast(row )* span + col; if (!occ[idx]) { occ[idx] = 1; cnt++; } } if (best < 0 || cnt < best) best = cnt; if (oyi + 1 < n_off || oxi + 1 < n_off) - std::fill(occ.begin(), occ.end(), (char)0); // reset for next origin + std::fill(occ.begin(), occ.end(), static_cast(0)); // reset for next origin } coverage.push_back({ double(s), double(best) }); } @@ -201,8 +201,8 @@ void FractalDimensionFeature::osized_calculate (LR& r, const Fsettings& s, Image void FractalDimensionFeature::save_value(std::vector>& fvals) { - fvals[(int)Feature2D::FRACT_DIM_BOXCOUNT][0] = box_count_fd; - fvals[(int)Feature2D::FRACT_DIM_PERIMETER][0] = perim_fd; + fvals[static_cast(Feature2D::FRACT_DIM_BOXCOUNT)][0] = box_count_fd; + fvals[static_cast(Feature2D::FRACT_DIM_PERIMETER)][0] = perim_fd; } void FractalDimensionFeature::extract (LR& r, const Fsettings& s) diff --git a/src/nyx/features/fractal_dim.h b/src/nyx/features/fractal_dim.h index fb036bacc..f0bee04ce 100644 --- a/src/nyx/features/fractal_dim.h +++ b/src/nyx/features/fractal_dim.h @@ -14,7 +14,7 @@ class FractalDimensionFeature: public FeatureMethod { public: - const constexpr static std::initializer_list featureset = + static constexpr std::initializer_list featureset = { Nyxus::Feature2D::FRACT_DIM_BOXCOUNT, Nyxus::Feature2D::FRACT_DIM_PERIMETER diff --git a/src/nyx/features/gabor.cpp b/src/nyx/features/gabor.cpp index 16bd04fe6..b87645151 100644 --- a/src/nyx/features/gabor.cpp +++ b/src/nyx/features/gabor.cpp @@ -1,710 +1,710 @@ -#define _USE_MATH_DEFINES // For M_PI, etc. -#include -#include "gabor.h" -#ifdef USE_GPU - #include "../cache.h" -#endif - -using namespace Nyxus; - -// -// Static members changeable by user via class 'Environment' -// - -double GaborFeature::gamma = 0.1; -double GaborFeature::sig2lam = 0.8; -int GaborFeature::n = 16; // convolution kernel size -double GaborFeature::f0LP = 0.1; -double GaborFeature::GRAYthr = 0.025; -std::vector> GaborFeature::f0_theta_pairs -{ - {0, 4.0}, - {M_PI_4, 16.0}, - {M_PI_2, 32.0}, - {M_PI_4*3.0, 64.0} -}; - -#ifdef USE_GPU - int GaborFeature::n_bank_filters = -1; - std::vector> GaborFeature::filterbank; - std::vector GaborFeature::ho_filterbank; - double* GaborFeature::dev_filterbank = nullptr; -#endif - -// -// -// - -bool GaborFeature::required(const FeatureSet& fs) -{ - return fs.isEnabled (Feature2D::GABOR); -} - -void GaborFeature::calculate (LR& r, const Fsettings& s) -{ - // Number of frequencies (feature values) calculated - int nFreqs = (int) GaborFeature::f0_theta_pairs.size(); - - // Prepare the feature value buffer - if (fvals.size() != nFreqs) - fvals.resize (nFreqs); - - // Skip calculation in case of noninformative data and return all zeros as feature values - if (r.aux_max == r.aux_min) - { - std::fill (fvals.begin(), fvals.end(), 0.0); // 'fvals' will then be picked up by save_values() - return; - } - - // Get ahold of the ROI image matrix - const ImageMatrix& Im0 = r.aux_image_matrix; - - // Temp buffers - - // --1 Real-valued filter-response image (was a PixIntens ImageMatrix, which truncated the - // response magnitudes to unsigned int and floored sub-integer responses to 0). - std::vector e2 (Im0.width * Im0.height); - - // --2 - std::vector auxC ((Im0.width + n - 1) * (Im0.height + n - 1) * 2); - - // --3 - std::vector auxG (n * n * 2); - - // --4 Memory for Gabor harmonics amplitudes - tx.resize (n + 1); - ty.resize (n + 1); - - // Compute the baseline score before applying high-pass Gabor filters - GaborEnergy (Im0, e2.data(), auxC.data(), auxG.data(), f0LP, sig2lam, gamma, M_PI_2, n); // compromise pi/2 theta - - // Values that we need for scoring filter responses - double maxval = e2[0], cmpval = e2[0]; - for (double a : e2) - { - maxval = std::max(maxval, a); - cmpval = std::min(cmpval, a); - } - - // intercept blank baseline filter response - if (maxval == cmpval) - { - for (int i = 0; i < nFreqs; i++) - fvals[i] = STNGS_NAN(s); - return; - } - - // Score the baseline signal - unsigned long baselineScore = 0; - for (double a : e2) - if (a > cmpval) - baselineScore++; - - // Iterate frequencies and score corresponding filter response over the baseline - for (int i=0; i < nFreqs; i++) - { - // -- unpack a frequency-angle pair - const auto& ft = f0_theta_pairs[i]; - auto f0 = ft.first; - auto theta = ft.second; - - // filter response for i-th frequency (overwrites e2) - GaborEnergy (Im0, e2.data(), auxC.data(), auxG.data(), f0, sig2lam, gamma, theta, n); - - // score it - unsigned long afterGaborScore = 0; - for (double a : e2) - if (a/maxval > GRAYthr) - afterGaborScore++; - - // save the score as feature value - fvals[i] = (double)afterGaborScore / (double)baselineScore; - } -} - -#ifdef USE_GPU - -namespace CuGabor -{ - bool drvImatFromCloud(size_t ri, size_t w, size_t h, GpusideCache& devsideCache); -} - -void GaborFeature::calculate_gpu (LR& r) -{ - // Number of frequencies (feature values) calculated - int nFreqs = (int)GaborFeature::f0_theta_pairs.size(); - - // Prepare the feature value buffer - if (fvals.size() != nFreqs) - fvals.resize(nFreqs); - - // Skip calculation in case of noninformative data and return all zeros as feature values - if (r.aux_max == r.aux_min) - { - std::fill(fvals.begin(), fvals.end(), 0.0); // 'fvals' will then be picked up by save_values() - return; - } - - // Get ahold of the ROI image matrix - const ImageMatrix& Im0 = r.aux_image_matrix; - readOnlyPixels im0_plane = Im0.ReadablePixels(); - - // Temp buffers - - // --1 Real-valued filter-response image (was a PixIntens ImageMatrix, which truncated the - // response magnitudes to unsigned int). - std::vector e2 (Im0.width * Im0.height); - - // --2 - std::vector auxC ((Im0.width + n - 1) * (Im0.height + n - 1) * 2); - - // --3 - std::vector auxG (n * n * 2); - - // --4 Memory for Gabor harmonics amplitudes - tx.resize (n + 1); - ty.resize (n + 1); - - // Compute the baseline score before applying high-pass Gabor filters - GaborEnergyGPU (Im0, e2.data(), auxC.data(), auxG.data(), f0LP, sig2lam, gamma, M_PI_2, n); // compromise pi/2 theta - - // Values that we need for scoring filter responses - double maxval = e2[0], cmpval = e2[0]; - for (double a : e2) - { - maxval = std::max(maxval, a); - cmpval = std::min(cmpval, a); - } - - // Score the baseline signal - unsigned long baselineScore = 0; - for (double a : e2) - if (a > cmpval) - baselineScore++; - - // Iterate frequencies and score corresponding filter response over the baseline - for (int i=0; i < nFreqs; i++) - { - // -- unpack a frequency-angle pair - const auto& ft = f0_theta_pairs[i]; - auto f0 = ft.first; - auto theta = ft.second; - - // filter response for i-th frequency (overwrites e2) - GaborEnergyGPU (Im0, e2.data(), auxC.data(), auxG.data(), f0, sig2lam, gamma, theta, n); - - // score it - unsigned long afterGaborScore = 0; - for (double a : e2) - if (a/maxval > GRAYthr) - afterGaborScore++; - - // save the score as feature value - fvals[i] = (double)afterGaborScore / (double)baselineScore; - } -} - -void GaborFeature::calculate_gpu_multi_filter (LR & r, size_t roiidx, GpusideCache & devsideCache) -{ - // Number of frequencies (feature values) calculated - int nFreqs = (int)GaborFeature::f0_theta_pairs.size(); - - // Prepare the feature value buffer - if (fvals.size() != nFreqs) - fvals.resize(nFreqs); - - // Skip calculation in case of noninformative data and return all zeros as feature values - if (r.aux_max == r.aux_min) - { - std::fill(fvals.begin(), fvals.end(), 0.0); // 'fvals' will then be picked up by save_values() - return; - } - - // create a GPU-side image matrix - if (!CuGabor::drvImatFromCloud (roiidx, r.aabb.get_width(), r.aabb.get_height(), devsideCache)) - { - std::cerr << "ERROR: image matrix from pixel cloud failed \n"; - return; - } - - // Get ahold of the ROI image matrix - const ImageMatrix& Im0 = r.aux_image_matrix; - readOnlyPixels im0_plane = Im0.ReadablePixels(); - - // cuFFT dimensions - long int cufft_size = 2 * ((Im0.width + n - 1) * (Im0.height + n - 1)); - int step_size = ceil(cufft_size / CUFFT_MAX_SIZE); - if(step_size == 0) - step_size = 1; - int num_filters = ceil(nFreqs/step_size) + 1; - - // Temp buffers - // - - // ROI image padded w.r.t. convolution kernel in complex layout - std::vector auxC (num_filters * (Im0.width + n - 1) * (Im0.height + n - 1) * 2); - - // convolution kernel in complex layout - std::vector auxG (n * n * 2); - - // Memory for Gabor harmonics amplitudes - tx.resize (n + 1); - ty.resize (n + 1); - - // Common frequency vector: merge the low-pass (baseline related) and high-pass frequencies - std::vector freqs = { f0LP }, - thetas = { M_PI_2 }; // the lowpass filter goes at compromise pi/2 theta - for (auto& ft : f0_theta_pairs) - { - freqs.push_back(ft.first); - thetas.push_back(ft.second); - } - - // Compute the baseline score before applying high-pass Gabor filters. - // Real-valued responses (was PixIntens, which truncated the magnitudes to unsigned int). - std::vector> responses (num_filters, std::vector(Im0.width * Im0.height)); - - // Calculate low-passed baseline and high-passed filter responses - // 'responses' is montage of Gabor energy of filter responses - GaborEnergyGPUMultiFilter (Im0, responses, auxC.data(), auxG.data(), freqs, sig2lam, gamma, thetas, n, freqs.size(), devsideCache); - - // Examine the baseline signal - - // we need to get these 3 values from response[0], the baseline signal - double maxval = 0.0, // magnitudes are non-negative - cmpval = std::numeric_limits::max(); // min - size_t baselineScore = 0; - - size_t wh = Im0.width * Im0.height; - for (size_t i = 0; i < wh; i++) - { - auto a = responses[0][i]; - maxval = std::max(a, maxval); - cmpval = std::min(a, cmpval); - } - - for (size_t i = 0; i < wh; i++) - { - auto a = responses[0][i]; - if (a > cmpval) - baselineScore++; - } - - // Iterate high-pass filter response signals and score them - for (auto k = 1; k < freqs.size(); k++) - { - size_t offs = k * wh; - size_t afterGaborScore = 0; - // score this filter response - for (size_t i = 0; i < wh; i++) - { - double a = responses[k][i]; - if (a / maxval > GRAYthr) - afterGaborScore++; - } - // save the score as feature value - fvals[k - 1] = (double)afterGaborScore / (double)baselineScore; - } - -} -#endif - -void GaborFeature::save_value(std::vector>& feature_vals) -{ - int nFreqs = (int) GaborFeature::f0_theta_pairs.size(); - - if (feature_vals[(int)Feature2D::GABOR].size() != nFreqs) - feature_vals[(int)Feature2D::GABOR].resize(fvals.size()); - for (int i=0; i < nFreqs; i++) - feature_vals[(int)Feature2D::GABOR][i] = fvals[i]; -} - -// conv_dud -- producing a double-valued image by convolving an unsigned int valued image with double-valued kernel -// ('conv_dud' is double <- uint * double) -// -// C -- Result matrix (ma+mb-1)-by-(na+nb-1). Must be zero-filled before call! -// A -- Larger matrix -// B -- Smaller matrix of convolution kernel -// ma -- Row size of A -// na -- Column size of A -// mb -- Row size of B -// nb -- Column size of B - -void GaborFeature::conv_dud( - double* C, - const unsigned int* A, - double* B, - int na, int ma, int nb, int mb) -{ - int ip, iq; // Pointer to elements in 'A' and 'C' matrices - - double wr, wi; // Imaginary and real weights from matrix B - int mc, nc; - - int ir = 0; // Pointer to elements in 'b' matrix - - mc = ma + mb - 1; - nc = (na + nb - 1) * 2; - - // initialize the output matrix - int mcnc = mc * nc; - for (int i = 0; i < mcnc; i++) - C[i] = 0.0; - - for (int j = 0; j < mb; ++j) - { - // For each element in b - for (int i = 0; i < nb; ++i) - { - // Get weight from B matrix - wr = B[ir]; - wi = B[ir+1]; - ir += 2; - - // Start at first row of A in C - ip = j * nc + i * 2; - iq = 0; - - for (int l = 0; l < ma; l++) - { - // For each row of A ... - for (int k = 0; k < na; k++) - { - // cache A[iq] - double a = A[iq]; - iq++; - - // multiply by the real weight and add - C[ip] += a * wr; - - // multiply by the imaginary weight and add - C[ip+1] += a * wi; - ip += 2; - } - - // Jump to next row position of A in C - ip += (nb - 1) * 2; - } - } - } -} - -// Creates a normalized Gabor filter -void GaborFeature::Gabor (double* Gex, double f0, double sig2lam, double gamma, double theta, double fi, int n, std::vector & tx, std::vector & ty) -{ - double lambda = 2 * M_PI / f0, - cos_theta = cos(theta), - sin_theta = sin(theta), - sig = sig2lam * lambda; - double sum; - int x, y; - int nx = n; - int ny = n; - - if (nx % 2 > 0) { - tx[0] = -((nx - 1) / 2); - for (x = 1; x < nx; x++) - tx[x] = tx[x - 1] + 1; - } - else { - tx[0] = -(nx / 2); - for (x = 1; x < nx; x++) - tx[x] = tx[x - 1] + 1; - } - - if (ny % 2 > 0) { - ty[0] = -((ny - 1) / 2); - for (y = 1; y < ny; y++) - ty[y] = ty[y - 1] + 1; - } - else { - ty[0] = -(ny / 2); - for (y = 1; y < ny; y++) - ty[y] = ty[y - 1] + 1; - } - - sum = 0; - for (y = 0; y < n; y++) - { - for (x = 0; x < n; x++) -{ - double argm, xte, yte, rte, ge; - xte = tx[x] * cos_theta + ty[y] * sin_theta; - yte = ty[y] * cos_theta - tx[x] * sin_theta; - rte = xte * xte + gamma * gamma * yte * yte; - ge = exp(-1 * rte / (2 * sig * sig)); - argm = xte * f0 + fi; - int idx = y * n * 2 + x * 2; - Gex[idx] = ge * cos(argm); // ge .* exp(j.*argm); - Gex[idx + 1] = ge * sin(argm); - sum += sqrt(pow(Gex[idx], 2) + pow(Gex[idx + 1], 2)); - } - } - - // normalize - for (y = 0; y < n; y++) - for (x = 0; x < n * 2; x++) - Gex[y * n * 2 + x] /= sum; - -} - -// Computes Gabor energy -void GaborFeature::GaborEnergy ( - const ImageMatrix& Im, - double* out, - double* auxC, - double* Gexp, - double f0, - double sig2lam, - double gamma, - double theta, - int n) -{ - int n_gab = n; - - double fi = 0; - Gabor (Gexp, f0, sig2lam, gamma, theta, fi, n_gab, tx, ty); - - readOnlyPixels pix_plane = Im.ReadablePixels(); - - #if 0 - //=== Version 1 (using the cached image) - for (int i = 0; i < (Im.width + n - 1) * (Im.height + n - 1) * 2; i++) - { - c[i] = 0; - } //MM - - double *image = new double[Im.width * Im.height]; - //std::vector image(Im.width * Im.height); - - for (auto y = 0; y < Im.height; y++) - for (auto x = 0; x < Im.width; x++) - image[y * Im.width + x] = pix_plane(y, x); - - conv (c, image, Gexp, Im.width, Im.height, n, n); - - delete[] image; - #endif - - //=== Version 2 - conv_dud (auxC, pix_plane.data(), Gexp, Im.width, Im.height, n_gab, n_gab); - - decltype(Im.height) b = 0; - for (auto y = (int)ceil((double)n / 2); b < Im.height; y++) - { - decltype(Im.width) a = 0; - for (auto x = (int)ceil((double)n / 2); a < Im.width; x++) - { - if (std::isnan(auxC[y * 2 * (Im.width + n - 1) + x * 2]) || std::isnan(auxC[y * 2 * (Im.width + n - 1) + x * 2 + 1])) - { - out[b * Im.width + a] = std::numeric_limits::quiet_NaN(); // keep response real-valued (was truncated to unsigned int) - a++; - continue; - } - - out[b * Im.width + a] = sqrt(pow(auxC[y * 2 * (Im.width + n - 1) + x * 2], 2) + pow(auxC[y * 2 * (Im.width + n - 1) + x * 2 + 1], 2)); // real magnitude, no unsigned-int truncation - a++; - } - b++; - } -} - -#ifdef USE_GPU -void GaborFeature::GaborEnergyGPU ( - const ImageMatrix& Im, - double* out, - double* auxC, - double* Gexp, - double f0, - double sig2lam, - double gamma, - double theta, - int n) -{ - int n_gab = n; - - double fi = 0; - Gabor (Gexp, f0, sig2lam, gamma, theta, fi, n_gab, tx, ty); - - readOnlyPixels pix_plane = Im.ReadablePixels(); - - //=== Version 2 - bool success = CuGabor::conv_dud_gpu_fft (auxC, pix_plane.data(), Gexp, Im.width, Im.height, n_gab, n_gab); - if(!success) { - std::cerr << "Unable to calculate Gabor features on GPU \n"; - } - - decltype(Im.height) b = 0; - for (auto y = (int)ceil((double)n / 2); b < Im.height; y++) - { - decltype(Im.width) a = 0; - for (auto x = (int)ceil((double)n / 2); a < Im.width; x++) - { - if (std::isnan(auxC[y * 2 * (Im.width + n - 1) + x * 2]) || std::isnan(auxC[y * 2 * (Im.width + n - 1) + x * 2 + 1])) - { - out[b * Im.width + a] = std::numeric_limits::quiet_NaN(); // keep response real-valued (was truncated to unsigned int) - a++; - continue; - } - - out[b * Im.width + a] = sqrt(pow(auxC[y * 2 * (Im.width + n - 1) + x * 2], 2) + pow(auxC[y * 2 * (Im.width + n - 1) + x * 2 + 1], 2)); // real magnitude, no unsigned-int truncation - a++; - } - b++; - } -} - -void GaborFeature::GaborEnergyGPUMultiFilter ( - const ImageMatrix& Im, - std::vector>& out, // energy image (real-valued; was PixIntens) - double* auxC, // batch of filter responses in complex layout - double* Gexp, - const std::vector& f0s, // f0-s matching 'thetas' - double sig2lam, - double gamma, - const std::vector& thetas, // thetas matching frequencies in 'f0s' - int kerside, - int num_filters, - GpusideCache & devside) -{ - readOnlyPixels pix_plane = Im.ReadablePixels(); - - // result in NyxusGpu::gabor_energy_image.hobuffer - // of length [ num_filters * Im.width * Im.height ] - bool success = CuGabor::conv_dud_gpu_fft_multi_filter ( - auxC, - pix_plane.data(), - GaborFeature::ho_filterbank.data(), - Im.width, - Im.height, - kerside, - kerside, - num_filters, - GaborFeature::dev_filterbank, - devside); - if (!success) - { - std::cerr << "\n\n\nUnable to calculate Gabor features on GPU \n\n\n"; - return; - } - - // GPU: 'NyxusGpu::gabor_energy_image.hobuffer' already has the above out[i][.] result - - // Convert it to a 'paged' layout - size_t wh = Im.width * Im.height; - for (int f = 0; f < num_filters; f++) - { - size_t skip = f * wh; - for (size_t i = 0; i < wh; i++) - out[f][i] = devside.gabor_energy_image.hobuffer [skip + i]; - } - -} -#endif - -void GaborFeature::extract (LR& r, const Fsettings& s) -{ - GaborFeature gf; - gf.calculate (r, s); - gf.save_value (r.fvals); -} - -void GaborFeature::reduce (size_t start, size_t end, std::vector* ptrLabels, std::unordered_map * ptrLabelData, const Fsettings & s, const Dataset & _) -{ - for (auto i = start; i < end; i++) - { - int lab = (*ptrLabels)[i]; - LR& r = (*ptrLabelData)[lab]; - extract (r, s); - } -} - -#ifdef USE_GPU -void GaborFeature::gpu_process_all_rois( - std::vector& L, - std::unordered_map & RoiData, - size_t batch_offset, - size_t batch_len, - GpusideCache & devsideCache) -{ - for (size_t i = 0; i < batch_len; i++) - { - size_t far_i = i + batch_offset; - auto lab = L [far_i]; - LR& r = RoiData [lab]; - - // Calculate features - GaborFeature f; - f.calculate_gpu_multi_filter (r, i, devsideCache); - f.save_value (r.fvals); - } -} -#endif - - -double GaborFeature::get_theta_in_degrees (int i) -{ - // theta needs to be unpacked from a pair - const auto& ft = GaborFeature::f0_theta_pairs[i]; - auto theta = ft.second; - return theta / M_PI * 180; -} - -#ifdef USE_GPU - -void GaborFeature::create_filterbank() -{ - // frequencies and angles - std::vector freqs = { f0LP }, - thetas = { M_PI_2 }; // the lowpass filter goes at compromise pi/2 theta - for (auto& ft : GaborFeature::f0_theta_pairs) - { - freqs.push_back(ft.first); - thetas.push_back(ft.second); - } - - // allocate the conv kernels buffer - GaborFeature::n_bank_filters = (int)freqs.size(); - GaborFeature::filterbank.resize(GaborFeature::n_bank_filters); - for (auto& f : GaborFeature::filterbank) - f.resize (2 * GaborFeature::n * GaborFeature::n * GaborFeature::n_bank_filters); - - ho_filterbank.resize(2 * GaborFeature::n * GaborFeature::n * GaborFeature::n_bank_filters); - - // temps - std::vector temp_tx, temp_ty; - temp_tx.resize (GaborFeature::n + 1); - temp_ty.resize (GaborFeature::n + 1); - double fi = 0; // offset - - // filter bank as a single chunk of memory - int idx = 0; - for (int i = 0; i < GaborFeature::n_bank_filters; i++) - { - auto filterData = GaborFeature::filterbank[i]; - Gabor (filterData.data(), freqs[i], GaborFeature::sig2lam, GaborFeature::gamma, thetas[i], fi, GaborFeature::n, temp_tx, temp_ty); - - for (int i = 0; i < 2 * GaborFeature::n * GaborFeature::n; ++i) - GaborFeature::ho_filterbank [idx + i] = filterData[i]; - - idx += 2 * GaborFeature::n * GaborFeature::n; - } -} - -bool GaborFeature::send_filterbank_2_gpuside() -{ - return CuGabor::send_filterbank_2_gpuside (&GaborFeature::dev_filterbank, GaborFeature::ho_filterbank.data(), GaborFeature::ho_filterbank.size()); -} - -#endif - -bool GaborFeature::init_class() -{ - #ifdef USE_GPU - GaborFeature::create_filterbank(); - if (! GaborFeature::send_filterbank_2_gpuside()) - return false; - #endif - - return true; +#define _USE_MATH_DEFINES // For M_PI, etc. +#include +#include "gabor.h" +#ifdef USE_GPU + #include "../cache.h" +#endif + +using namespace Nyxus; + +// +// Static members changeable by user via class 'Environment' +// + +double GaborFeature::gamma = 0.1; +double GaborFeature::sig2lam = 0.8; +int GaborFeature::n = 16; // convolution kernel size +double GaborFeature::f0LP = 0.1; +double GaborFeature::GRAYthr = 0.025; +std::vector> GaborFeature::f0_theta_pairs +{ + {0, 4.0}, + {M_PI_4, 16.0}, + {M_PI_2, 32.0}, + {M_PI_4*3.0, 64.0} +}; + +#ifdef USE_GPU + int GaborFeature::n_bank_filters = -1; + std::vector> GaborFeature::filterbank; + std::vector GaborFeature::ho_filterbank; + double* GaborFeature::dev_filterbank = nullptr; +#endif + +// +// +// + +bool GaborFeature::required(const FeatureSet& fs) +{ + return fs.isEnabled (Feature2D::GABOR); +} + +void GaborFeature::calculate (LR& r, const Fsettings& s) +{ + // Number of frequencies (feature values) calculated + int nFreqs = static_cast(GaborFeature::f0_theta_pairs.size()); + + // Prepare the feature value buffer + if (fvals.size() != nFreqs) + fvals.resize (nFreqs); + + // Skip calculation in case of noninformative data and return all zeros as feature values + if (r.aux_max == r.aux_min) + { + std::fill (fvals.begin(), fvals.end(), 0.0); // 'fvals' will then be picked up by save_values() + return; + } + + // Get ahold of the ROI image matrix + const ImageMatrix& Im0 = r.aux_image_matrix; + + // Temp buffers + + // --1 Real-valued filter-response image (was a PixIntens ImageMatrix, which truncated the + // response magnitudes to unsigned int and floored sub-integer responses to 0). + std::vector e2 (Im0.width * Im0.height); + + // --2 + std::vector auxC ((Im0.width + n - 1) * (Im0.height + n - 1) * 2); + + // --3 + std::vector auxG (n * n * 2); + + // --4 Memory for Gabor harmonics amplitudes + tx.resize (n + 1); + ty.resize (n + 1); + + // Compute the baseline score before applying high-pass Gabor filters + GaborEnergy (Im0, e2.data(), auxC.data(), auxG.data(), f0LP, sig2lam, gamma, M_PI_2, n); // compromise pi/2 theta + + // Values that we need for scoring filter responses + double maxval = e2[0], cmpval = e2[0]; + for (double a : e2) + { + maxval = std::max(maxval, a); + cmpval = std::min(cmpval, a); + } + + // intercept blank baseline filter response + if (maxval == cmpval) + { + for (int i = 0; i < nFreqs; i++) + fvals[i] = STNGS_NAN(s); + return; + } + + // Score the baseline signal + unsigned long baselineScore = 0; + for (double a : e2) + if (a > cmpval) + baselineScore++; + + // Iterate frequencies and score corresponding filter response over the baseline + for (int i=0; i < nFreqs; i++) + { + // -- unpack a frequency-angle pair + const auto& ft = f0_theta_pairs[i]; + auto f0 = ft.first; + auto theta = ft.second; + + // filter response for i-th frequency (overwrites e2) + GaborEnergy (Im0, e2.data(), auxC.data(), auxG.data(), f0, sig2lam, gamma, theta, n); + + // score it + unsigned long afterGaborScore = 0; + for (double a : e2) + if (a/maxval > GRAYthr) + afterGaborScore++; + + // save the score as feature value + fvals[i] = static_cast(afterGaborScore )/ static_cast(baselineScore); + } +} + +#ifdef USE_GPU + +namespace CuGabor +{ + bool drvImatFromCloud(size_t ri, size_t w, size_t h, GpusideCache& devsideCache); +} + +void GaborFeature::calculate_gpu (LR& r) +{ + // Number of frequencies (feature values) calculated + int nFreqs = static_cast(GaborFeature::f0_theta_pairs.size()); + + // Prepare the feature value buffer + if (fvals.size() != nFreqs) + fvals.resize(nFreqs); + + // Skip calculation in case of noninformative data and return all zeros as feature values + if (r.aux_max == r.aux_min) + { + std::fill(fvals.begin(), fvals.end(), 0.0); // 'fvals' will then be picked up by save_values() + return; + } + + // Get ahold of the ROI image matrix + const ImageMatrix& Im0 = r.aux_image_matrix; + readOnlyPixels im0_plane = Im0.ReadablePixels(); + + // Temp buffers + + // --1 Real-valued filter-response image (was a PixIntens ImageMatrix, which truncated the + // response magnitudes to unsigned int). + std::vector e2 (Im0.width * Im0.height); + + // --2 + std::vector auxC ((Im0.width + n - 1) * (Im0.height + n - 1) * 2); + + // --3 + std::vector auxG (n * n * 2); + + // --4 Memory for Gabor harmonics amplitudes + tx.resize (n + 1); + ty.resize (n + 1); + + // Compute the baseline score before applying high-pass Gabor filters + GaborEnergyGPU (Im0, e2.data(), auxC.data(), auxG.data(), f0LP, sig2lam, gamma, M_PI_2, n); // compromise pi/2 theta + + // Values that we need for scoring filter responses + double maxval = e2[0], cmpval = e2[0]; + for (double a : e2) + { + maxval = std::max(maxval, a); + cmpval = std::min(cmpval, a); + } + + // Score the baseline signal + unsigned long baselineScore = 0; + for (double a : e2) + if (a > cmpval) + baselineScore++; + + // Iterate frequencies and score corresponding filter response over the baseline + for (int i=0; i < nFreqs; i++) + { + // -- unpack a frequency-angle pair + const auto& ft = f0_theta_pairs[i]; + auto f0 = ft.first; + auto theta = ft.second; + + // filter response for i-th frequency (overwrites e2) + GaborEnergyGPU (Im0, e2.data(), auxC.data(), auxG.data(), f0, sig2lam, gamma, theta, n); + + // score it + unsigned long afterGaborScore = 0; + for (double a : e2) + if (a/maxval > GRAYthr) + afterGaborScore++; + + // save the score as feature value + fvals[i] = static_cast(afterGaborScore )/ static_cast(baselineScore); + } +} + +void GaborFeature::calculate_gpu_multi_filter (LR & r, size_t roiidx, GpusideCache & devsideCache) +{ + // Number of frequencies (feature values) calculated + int nFreqs = static_cast(GaborFeature::f0_theta_pairs.size()); + + // Prepare the feature value buffer + if (fvals.size() != nFreqs) + fvals.resize(nFreqs); + + // Skip calculation in case of noninformative data and return all zeros as feature values + if (r.aux_max == r.aux_min) + { + std::fill(fvals.begin(), fvals.end(), 0.0); // 'fvals' will then be picked up by save_values() + return; + } + + // create a GPU-side image matrix + if (!CuGabor::drvImatFromCloud (roiidx, r.aabb.get_width(), r.aabb.get_height(), devsideCache)) + { + std::cerr << "ERROR: image matrix from pixel cloud failed \n"; + return; + } + + // Get ahold of the ROI image matrix + const ImageMatrix& Im0 = r.aux_image_matrix; + readOnlyPixels im0_plane = Im0.ReadablePixels(); + + // cuFFT dimensions + long int cufft_size = 2 * ((Im0.width + n - 1) * (Im0.height + n - 1)); + int step_size = ceil(cufft_size / CUFFT_MAX_SIZE); + if(step_size == 0) + step_size = 1; + int num_filters = ceil(nFreqs/step_size) + 1; + + // Temp buffers + // + + // ROI image padded w.r.t. convolution kernel in complex layout + std::vector auxC (num_filters * (Im0.width + n - 1) * (Im0.height + n - 1) * 2); + + // convolution kernel in complex layout + std::vector auxG (n * n * 2); + + // Memory for Gabor harmonics amplitudes + tx.resize (n + 1); + ty.resize (n + 1); + + // Common frequency vector: merge the low-pass (baseline related) and high-pass frequencies + std::vector freqs = { f0LP }, + thetas = { M_PI_2 }; // the lowpass filter goes at compromise pi/2 theta + for (auto& ft : f0_theta_pairs) + { + freqs.push_back(ft.first); + thetas.push_back(ft.second); + } + + // Compute the baseline score before applying high-pass Gabor filters. + // Real-valued responses (was PixIntens, which truncated the magnitudes to unsigned int). + std::vector> responses (num_filters, std::vector(Im0.width * Im0.height)); + + // Calculate low-passed baseline and high-passed filter responses + // 'responses' is montage of Gabor energy of filter responses + GaborEnergyGPUMultiFilter (Im0, responses, auxC.data(), auxG.data(), freqs, sig2lam, gamma, thetas, n, freqs.size(), devsideCache); + + // Examine the baseline signal + + // we need to get these 3 values from response[0], the baseline signal + double maxval = 0.0, // magnitudes are non-negative + cmpval = std::numeric_limits::max(); // min + size_t baselineScore = 0; + + size_t wh = Im0.width * Im0.height; + for (size_t i = 0; i < wh; i++) + { + auto a = responses[0][i]; + maxval = std::max(a, maxval); + cmpval = std::min(a, cmpval); + } + + for (size_t i = 0; i < wh; i++) + { + auto a = responses[0][i]; + if (a > cmpval) + baselineScore++; + } + + // Iterate high-pass filter response signals and score them + for (auto k = 1; k < freqs.size(); k++) + { + size_t offs = k * wh; + size_t afterGaborScore = 0; + // score this filter response + for (size_t i = 0; i < wh; i++) + { + double a = responses[k][i]; + if (a / maxval > GRAYthr) + afterGaborScore++; + } + // save the score as feature value + fvals[k - 1] = static_cast(afterGaborScore )/ static_cast(baselineScore); + } + +} +#endif + +void GaborFeature::save_value(std::vector>& feature_vals) +{ + int nFreqs = static_cast(GaborFeature::f0_theta_pairs.size()); + + if (feature_vals[static_cast(Feature2D::GABOR)].size() != nFreqs) + feature_vals[static_cast(Feature2D::GABOR)].resize(fvals.size()); + for (int i=0; i < nFreqs; i++) + feature_vals[static_cast(Feature2D::GABOR)][i] = fvals[i]; +} + +// conv_dud -- producing a double-valued image by convolving an unsigned int valued image with double-valued kernel +// ('conv_dud' is double <- uint * double) +// +// C -- Result matrix (ma+mb-1)-by-(na+nb-1). Must be zero-filled before call! +// A -- Larger matrix +// B -- Smaller matrix of convolution kernel +// ma -- Row size of A +// na -- Column size of A +// mb -- Row size of B +// nb -- Column size of B + +void GaborFeature::conv_dud( + double* C, + const unsigned int* A, + double* B, + int na, int ma, int nb, int mb) +{ + int ip, iq; // Pointer to elements in 'A' and 'C' matrices + + double wr, wi; // Imaginary and real weights from matrix B + int mc, nc; + + int ir = 0; // Pointer to elements in 'b' matrix + + mc = ma + mb - 1; + nc = (na + nb - 1) * 2; + + // initialize the output matrix + int mcnc = mc * nc; + for (int i = 0; i < mcnc; i++) + C[i] = 0.0; + + for (int j = 0; j < mb; ++j) + { + // For each element in b + for (int i = 0; i < nb; ++i) + { + // Get weight from B matrix + wr = B[ir]; + wi = B[ir+1]; + ir += 2; + + // Start at first row of A in C + ip = j * nc + i * 2; + iq = 0; + + for (int l = 0; l < ma; l++) + { + // For each row of A ... + for (int k = 0; k < na; k++) + { + // cache A[iq] + double a = A[iq]; + iq++; + + // multiply by the real weight and add + C[ip] += a * wr; + + // multiply by the imaginary weight and add + C[ip+1] += a * wi; + ip += 2; + } + + // Jump to next row position of A in C + ip += (nb - 1) * 2; + } + } + } +} + +// Creates a normalized Gabor filter +void GaborFeature::Gabor (double* Gex, double f0, double sig2lam, double gamma, double theta, double fi, int n, std::vector & tx, std::vector & ty) +{ + double lambda = 2 * M_PI / f0, + cos_theta = cos(theta), + sin_theta = sin(theta), + sig = sig2lam * lambda; + double sum; + int x, y; + int nx = n; + int ny = n; + + if (nx % 2 > 0) { + tx[0] = -((nx - 1) / 2); + for (x = 1; x < nx; x++) + tx[x] = tx[x - 1] + 1; + } + else { + tx[0] = -(nx / 2); + for (x = 1; x < nx; x++) + tx[x] = tx[x - 1] + 1; + } + + if (ny % 2 > 0) { + ty[0] = -((ny - 1) / 2); + for (y = 1; y < ny; y++) + ty[y] = ty[y - 1] + 1; + } + else { + ty[0] = -(ny / 2); + for (y = 1; y < ny; y++) + ty[y] = ty[y - 1] + 1; + } + + sum = 0; + for (y = 0; y < n; y++) + { + for (x = 0; x < n; x++) +{ + double argm, xte, yte, rte, ge; + xte = tx[x] * cos_theta + ty[y] * sin_theta; + yte = ty[y] * cos_theta - tx[x] * sin_theta; + rte = xte * xte + gamma * gamma * yte * yte; + ge = exp(-1 * rte / (2 * sig * sig)); + argm = xte * f0 + fi; + int idx = y * n * 2 + x * 2; + Gex[idx] = ge * cos(argm); // ge .* exp(j.*argm); + Gex[idx + 1] = ge * sin(argm); + sum += sqrt(pow(Gex[idx], 2) + pow(Gex[idx + 1], 2)); + } + } + + // normalize + for (y = 0; y < n; y++) + for (x = 0; x < n * 2; x++) + Gex[y * n * 2 + x] /= sum; + +} + +// Computes Gabor energy +void GaborFeature::GaborEnergy ( + const ImageMatrix& Im, + double* out, + double* auxC, + double* Gexp, + double f0, + double sig2lam, + double gamma, + double theta, + int n) +{ + int n_gab = n; + + double fi = 0; + Gabor (Gexp, f0, sig2lam, gamma, theta, fi, n_gab, tx, ty); + + readOnlyPixels pix_plane = Im.ReadablePixels(); + + #if 0 + //=== Version 1 (using the cached image) + for (int i = 0; i < (Im.width + n - 1) * (Im.height + n - 1) * 2; i++) + { + c[i] = 0; + } //MM + + double *image = new double[Im.width * Im.height]; + //std::vector image(Im.width * Im.height); + + for (auto y = 0; y < Im.height; y++) + for (auto x = 0; x < Im.width; x++) + image[y * Im.width + x] = pix_plane(y, x); + + conv (c, image, Gexp, Im.width, Im.height, n, n); + + delete[] image; + #endif + + //=== Version 2 + conv_dud (auxC, pix_plane.data(), Gexp, Im.width, Im.height, n_gab, n_gab); + + decltype(Im.height) b = 0; + for (auto y = static_cast(ceil(static_cast(n) / 2)); b < Im.height; y++) + { + decltype(Im.width) a = 0; + for (auto x = static_cast(ceil(static_cast(n) / 2)); a < Im.width; x++) + { + if (std::isnan(auxC[y * 2 * (Im.width + n - 1) + x * 2]) || std::isnan(auxC[y * 2 * (Im.width + n - 1) + x * 2 + 1])) + { + out[b * Im.width + a] = std::numeric_limits::quiet_NaN(); // keep response real-valued (was truncated to unsigned int) + a++; + continue; + } + + out[b * Im.width + a] = sqrt(pow(auxC[y * 2 * (Im.width + n - 1) + x * 2], 2) + pow(auxC[y * 2 * (Im.width + n - 1) + x * 2 + 1], 2)); // real magnitude, no unsigned-int truncation + a++; + } + b++; + } +} + +#ifdef USE_GPU +void GaborFeature::GaborEnergyGPU ( + const ImageMatrix& Im, + double* out, + double* auxC, + double* Gexp, + double f0, + double sig2lam, + double gamma, + double theta, + int n) +{ + int n_gab = n; + + double fi = 0; + Gabor (Gexp, f0, sig2lam, gamma, theta, fi, n_gab, tx, ty); + + readOnlyPixels pix_plane = Im.ReadablePixels(); + + //=== Version 2 + bool success = CuGabor::conv_dud_gpu_fft (auxC, pix_plane.data(), Gexp, Im.width, Im.height, n_gab, n_gab); + if(!success) { + std::cerr << "Unable to calculate Gabor features on GPU \n"; + } + + decltype(Im.height) b = 0; + for (auto y = static_cast(ceil(static_cast(n) / 2)); b < Im.height; y++) + { + decltype(Im.width) a = 0; + for (auto x = static_cast(ceil(static_cast(n) / 2)); a < Im.width; x++) + { + if (std::isnan(auxC[y * 2 * (Im.width + n - 1) + x * 2]) || std::isnan(auxC[y * 2 * (Im.width + n - 1) + x * 2 + 1])) + { + out[b * Im.width + a] = std::numeric_limits::quiet_NaN(); // keep response real-valued (was truncated to unsigned int) + a++; + continue; + } + + out[b * Im.width + a] = sqrt(pow(auxC[y * 2 * (Im.width + n - 1) + x * 2], 2) + pow(auxC[y * 2 * (Im.width + n - 1) + x * 2 + 1], 2)); // real magnitude, no unsigned-int truncation + a++; + } + b++; + } +} + +void GaborFeature::GaborEnergyGPUMultiFilter ( + const ImageMatrix& Im, + std::vector>& out, // energy image (real-valued; was PixIntens) + double* auxC, // batch of filter responses in complex layout + double* Gexp, + const std::vector& f0s, // f0-s matching 'thetas' + double sig2lam, + double gamma, + const std::vector& thetas, // thetas matching frequencies in 'f0s' + int kerside, + int num_filters, + GpusideCache & devside) +{ + readOnlyPixels pix_plane = Im.ReadablePixels(); + + // result in NyxusGpu::gabor_energy_image.hobuffer + // of length [ num_filters * Im.width * Im.height ] + bool success = CuGabor::conv_dud_gpu_fft_multi_filter ( + auxC, + pix_plane.data(), + GaborFeature::ho_filterbank.data(), + Im.width, + Im.height, + kerside, + kerside, + num_filters, + GaborFeature::dev_filterbank, + devside); + if (!success) + { + std::cerr << "\n\n\nUnable to calculate Gabor features on GPU \n\n\n"; + return; + } + + // GPU: 'NyxusGpu::gabor_energy_image.hobuffer' already has the above out[i][.] result + + // Convert it to a 'paged' layout + size_t wh = Im.width * Im.height; + for (int f = 0; f < num_filters; f++) + { + size_t skip = f * wh; + for (size_t i = 0; i < wh; i++) + out[f][i] = devside.gabor_energy_image.hobuffer [skip + i]; + } + +} +#endif + +void GaborFeature::extract (LR& r, const Fsettings& s) +{ + GaborFeature gf; + gf.calculate (r, s); + gf.save_value (r.fvals); +} + +void GaborFeature::reduce (size_t start, size_t end, std::vector* ptrLabels, std::unordered_map * ptrLabelData, const Fsettings & s, const Dataset & _) +{ + for (auto i = start; i < end; i++) + { + int lab = (*ptrLabels)[i]; + LR& r = (*ptrLabelData)[lab]; + extract (r, s); + } +} + +#ifdef USE_GPU +void GaborFeature::gpu_process_all_rois( + std::vector& L, + std::unordered_map & RoiData, + size_t batch_offset, + size_t batch_len, + GpusideCache & devsideCache) +{ + for (size_t i = 0; i < batch_len; i++) + { + size_t far_i = i + batch_offset; + auto lab = L [far_i]; + LR& r = RoiData [lab]; + + // Calculate features + GaborFeature f; + f.calculate_gpu_multi_filter (r, i, devsideCache); + f.save_value (r.fvals); + } +} +#endif + + +double GaborFeature::get_theta_in_degrees (int i) +{ + // theta needs to be unpacked from a pair + const auto& ft = GaborFeature::f0_theta_pairs[i]; + auto theta = ft.second; + return theta / M_PI * 180; +} + +#ifdef USE_GPU + +void GaborFeature::create_filterbank() +{ + // frequencies and angles + std::vector freqs = { f0LP }, + thetas = { M_PI_2 }; // the lowpass filter goes at compromise pi/2 theta + for (auto& ft : GaborFeature::f0_theta_pairs) + { + freqs.push_back(ft.first); + thetas.push_back(ft.second); + } + + // allocate the conv kernels buffer + GaborFeature::n_bank_filters = static_cast(freqs.size()); + GaborFeature::filterbank.resize(GaborFeature::n_bank_filters); + for (auto& f : GaborFeature::filterbank) + f.resize (2 * GaborFeature::n * GaborFeature::n * GaborFeature::n_bank_filters); + + ho_filterbank.resize(2 * GaborFeature::n * GaborFeature::n * GaborFeature::n_bank_filters); + + // temps + std::vector temp_tx, temp_ty; + temp_tx.resize (GaborFeature::n + 1); + temp_ty.resize (GaborFeature::n + 1); + double fi = 0; // offset + + // filter bank as a single chunk of memory + int idx = 0; + for (int i = 0; i < GaborFeature::n_bank_filters; i++) + { + auto filterData = GaborFeature::filterbank[i]; + Gabor (filterData.data(), freqs[i], GaborFeature::sig2lam, GaborFeature::gamma, thetas[i], fi, GaborFeature::n, temp_tx, temp_ty); + + for (int i = 0; i < 2 * GaborFeature::n * GaborFeature::n; ++i) + GaborFeature::ho_filterbank [idx + i] = filterData[i]; + + idx += 2 * GaborFeature::n * GaborFeature::n; + } +} + +bool GaborFeature::send_filterbank_2_gpuside() +{ + return CuGabor::send_filterbank_2_gpuside (&GaborFeature::dev_filterbank, GaborFeature::ho_filterbank.data(), GaborFeature::ho_filterbank.size()); +} + +#endif + +bool GaborFeature::init_class() +{ + #ifdef USE_GPU + GaborFeature::create_filterbank(); + if (! GaborFeature::send_filterbank_2_gpuside()) + return false; + #endif + + return true; } \ No newline at end of file diff --git a/src/nyx/features/gabor.h b/src/nyx/features/gabor.h index ac9bea494..ddb43ee72 100644 --- a/src/nyx/features/gabor.h +++ b/src/nyx/features/gabor.h @@ -20,7 +20,7 @@ class GaborFeature: public FeatureMethod { public: - const constexpr static std::initializer_list featureset = { Nyxus::Feature2D::GABOR }; + static constexpr std::initializer_list featureset = { Nyxus::Feature2D::GABOR }; GaborFeature(); diff --git a/src/nyx/features/gabor_nontriv.cpp b/src/nyx/features/gabor_nontriv.cpp index dd578bb63..1f7f70c73 100644 --- a/src/nyx/features/gabor_nontriv.cpp +++ b/src/nyx/features/gabor_nontriv.cpp @@ -1,240 +1,240 @@ -#define _USE_MATH_DEFINES // For M_PI, etc. -#include -#include "gabor.h" -#include "image_matrix_nontriv.h" - -using namespace Nyxus; - -GaborFeature::GaborFeature() : FeatureMethod("GaborFeature") -{ - provide_features ({ Feature2D::GABOR }); -} - -void GaborFeature::osized_calculate (LR& r, const Fsettings& s, ImageLoader&) -{ - int nF = (int)GaborFeature::f0_theta_pairs.size(); - - if (fvals.size() != nF) - fvals.resize(nF); - std::fill (fvals.begin(), fvals.end(), 0.0); - - // Skip calculation in case of noninformative data - if (r.aux_max == r.aux_min) - return; - - // Prepare the image matrix - WriteImageMatrix_nontriv Im0 ("GaborFeature-osized_calculate-Im0", r.label); - Im0.allocate_from_cloud (r.raw_pixels_NT, r.aabb, false); - - // Buffer for Gabor filters - std::vector auxG (n * n * 2); - - // Prepare temp objects - tx.resize(n + 1); - ty.resize(n + 1); - - // Compute the original score before Gabor - double max0 = 0.0; - size_t cnt0 = 0; - GaborEnergy_NT2 (Im0, auxG.data(), f0LP, sig2lam, gamma, M_PI_2, n, true/*request max*/, 0/*threshold*/, max0/*out*/, cnt0/*out*/); // compromise pi/2 theta - - double cmp_a = max0 * GRAYthr; - - // NOTE (pre-existing, separate from the response-truncation fix): originalScore is the baseline - // score and must be the count of baseline pixels above the baseline minimum (as the trivial - // calculate() computes it), but it is left at 0 here, so every fvals[i] below divides by ~0. - // The out-of-core Gabor path needs the baseline min + count wired in to match the in-RAM path. - size_t originalScore = 0; - for (int i=0; i < nF; i++) - { - if (STNGS_VERBOSLVL(s) == 3) // former VERBOSLVL3 - std::cout << "\tcalculating Gabor frequency " << i+1 << "/" << nF << "\n"; - - // -- unpack a frequency-angle pair - const auto& ft = f0_theta_pairs[i]; - auto f0 = ft.first; - auto theta = ft.second; - - size_t afterGaborScore = 0; - GaborEnergy_NT2 (Im0, auxG.data(), f0, sig2lam, gamma, theta, n, false/*request count*/, cmp_a/*threshold*/, max0/*out*/, afterGaborScore/*out*/); - fvals[i] = (double)afterGaborScore / ((double)originalScore + STNGS_TINY(s)); // former theEnvironment.resultOptions.tiny() - - if (STNGS_VERBOSLVL(s) == 3) // former VERBOSLVL3 - std::cout << "\t\tfeature [" << i << "] = " << fvals[i] << "\n"; - } -} - -void GaborFeature::GetStats_NT (WriteImageMatrix_nontriv & I, Moments2& moments2) -{ - // Feed all the image pixels into the Moments2 object: - moments2.reset(); - for (size_t i = 0; i < I.size(); i++) - { - auto inten = I.get_at(i); - moments2.add (inten); - } -} - -// Computes Gabor energy -void GaborFeature::GaborEnergy_NT2 ( - WriteImageMatrix_nontriv& Im, - double* Gexp, - double f0, - double sig2lam, - double gamma, - double theta, - int n, - bool max_or_threshold, // 'true' to return max, 'false' to return count - double threshold, - double & max_val/*out*/, - size_t & over_threshold_count/*out*/) -{ - // Reset the output variables - over_threshold_count = 0; - max_val = -1; - - // Prepare a filter - double fi = 0; - Gabor (Gexp, f0, sig2lam, gamma, theta, fi, n, tx, ty); - - // Helpful temps - auto width = Im.get_width(), - height = Im.get_height(); - auto xy0 = (int)ceil(double(n) / 2.); - - // Window (N-fold kernel size) - int winX = n * 10, - winY = n * 10; - std::vector W (winY * winX); - - // Convolution result buffer - std::vector auxC ((winY + n - 1) * (winX + n - 1) * 2); - - // Iterate the image window by window - int n_winHor = width / winX, //ceil (float(width) / float(win)), - n_winVert = height / winY; //ceil (float(height) / float(win)); - - // ROI smaller than kernel? - if (n_winVert == 0 || n_winHor == 0) - { - // Fill the window with data - for (int row=0; row < height; row++) - for (int col = 0; col < width; col++) - { - size_t idx = row * width + col; - W[idx] = Im.get_at(idx); - } - - // Convolve - conv_dud (auxC.data(), W.data(), Gexp, winY, winX, n, n); - - // Collect the result - for (auto y = xy0, b = 0; b < winY; y++, b++) - for (auto x = xy0, a = 0; a < winX; x++, a++) - { - double inten = sqrt(pow(auxC[y * 2 * (winX + n - 1) + x * 2], 2) + pow(auxC[y * 2 * (winX + n - 1) + x * 2 + 1], 2)); // real magnitude, no unsigned-int truncation - // Calculate requested summary - if (max_or_threshold) - max_val = std::max(max_val, double(inten)); - else - if (double(inten) > threshold) - over_threshold_count++; - } - - return; - } - - // ROI larger than kernel - for (int winVert = 0; winVert < n_winVert; winVert++) - { - for (int winHor = 0; winHor < n_winHor; winHor++) - { - // Fill the window with data - for (int row=0; row threshold) - over_threshold_count++; - } - } - } -} - -void GaborFeature::conv_dud_NT ( - double* C, - WriteImageMatrix_nontriv& A, - double* B, - int na, int ma, int nb, int mb) -{ - int ip, iq; // Pointer to elements in 'A' and 'C' matrices - - double wr, wi; // Imaginary and real weights from matrix B - int mc, nc; - - int ir = 0; // Pointer to elements in 'b' matrix - - mc = ma + mb - 1; - nc = (na + nb - 1) * 2; - - // initialize the output matrix - int mcnc = mc * nc; - for (int i = 0; i < mcnc; i++) - C[i] = 0.0; - - for (int j = 0; j < mb; ++j) - { - // For each element in b - for (int i = 0; i < nb; ++i) - { - // Get weight from B matrix - wr = B[ir]; - wi = B[ir + 1]; - ir += 2; - - // Start at first row of A in C - ip = j * nc + i * 2; - iq = 0; - - for (int l = 0; l < ma; l++) - { - // For each row of A ... - for (int k = 0; k < na; k++) - { - // cache A[iq] - double a = A[iq]; - iq++; - - // multiply by the real weight and add - C[ip] += a * wr; - - // multiply by the imaginary weight and add - C[ip + 1] += a * wi; - ip += 2; - } - - // Jump to next row position of A in C - ip += (nb - 1) * 2; - } - } - } -} - +#define _USE_MATH_DEFINES // For M_PI, etc. +#include +#include "gabor.h" +#include "image_matrix_nontriv.h" + +using namespace Nyxus; + +GaborFeature::GaborFeature() : FeatureMethod("GaborFeature") +{ + provide_features ({ Feature2D::GABOR }); +} + +void GaborFeature::osized_calculate (LR& r, const Fsettings& s, ImageLoader&) +{ + int nF = static_cast(GaborFeature::f0_theta_pairs.size()); + + if (fvals.size() != nF) + fvals.resize(nF); + std::fill (fvals.begin(), fvals.end(), 0.0); + + // Skip calculation in case of noninformative data + if (r.aux_max == r.aux_min) + return; + + // Prepare the image matrix + WriteImageMatrix_nontriv Im0 ("GaborFeature-osized_calculate-Im0", r.label); + Im0.allocate_from_cloud (r.raw_pixels_NT, r.aabb, false); + + // Buffer for Gabor filters + std::vector auxG (n * n * 2); + + // Prepare temp objects + tx.resize(n + 1); + ty.resize(n + 1); + + // Compute the original score before Gabor + double max0 = 0.0; + size_t cnt0 = 0; + GaborEnergy_NT2 (Im0, auxG.data(), f0LP, sig2lam, gamma, M_PI_2, n, true/*request max*/, 0/*threshold*/, max0/*out*/, cnt0/*out*/); // compromise pi/2 theta + + double cmp_a = max0 * GRAYthr; + + // NOTE (pre-existing, separate from the response-truncation fix): originalScore is the baseline + // score and must be the count of baseline pixels above the baseline minimum (as the trivial + // calculate() computes it), but it is left at 0 here, so every fvals[i] below divides by ~0. + // The out-of-core Gabor path needs the baseline min + count wired in to match the in-RAM path. + size_t originalScore = 0; + for (int i=0; i < nF; i++) + { + if (STNGS_VERBOSLVL(s) == 3) // former VERBOSLVL3 + std::cout << "\tcalculating Gabor frequency " << i+1 << "/" << nF << "\n"; + + // -- unpack a frequency-angle pair + const auto& ft = f0_theta_pairs[i]; + auto f0 = ft.first; + auto theta = ft.second; + + size_t afterGaborScore = 0; + GaborEnergy_NT2 (Im0, auxG.data(), f0, sig2lam, gamma, theta, n, false/*request count*/, cmp_a/*threshold*/, max0/*out*/, afterGaborScore/*out*/); + fvals[i] = static_cast(afterGaborScore )/ (static_cast(originalScore )+ STNGS_TINY(s)); // former theEnvironment.resultOptions.tiny() + + if (STNGS_VERBOSLVL(s) == 3) // former VERBOSLVL3 + std::cout << "\t\tfeature [" << i << "] = " << fvals[i] << "\n"; + } +} + +void GaborFeature::GetStats_NT (WriteImageMatrix_nontriv & I, Moments2& moments2) +{ + // Feed all the image pixels into the Moments2 object: + moments2.reset(); + for (size_t i = 0; i < I.size(); i++) + { + auto inten = I.get_at(i); + moments2.add (inten); + } +} + +// Computes Gabor energy +void GaborFeature::GaborEnergy_NT2 ( + WriteImageMatrix_nontriv& Im, + double* Gexp, + double f0, + double sig2lam, + double gamma, + double theta, + int n, + bool max_or_threshold, // 'true' to return max, 'false' to return count + double threshold, + double & max_val/*out*/, + size_t & over_threshold_count/*out*/) +{ + // Reset the output variables + over_threshold_count = 0; + max_val = -1; + + // Prepare a filter + double fi = 0; + Gabor (Gexp, f0, sig2lam, gamma, theta, fi, n, tx, ty); + + // Helpful temps + auto width = Im.get_width(), + height = Im.get_height(); + auto xy0 = static_cast(ceil(double(n) / 2.)); + + // Window (N-fold kernel size) + int winX = n * 10, + winY = n * 10; + std::vector W (winY * winX); + + // Convolution result buffer + std::vector auxC ((winY + n - 1) * (winX + n - 1) * 2); + + // Iterate the image window by window + int n_winHor = width / winX, //ceil (float(width) / float(win)), + n_winVert = height / winY; //ceil (float(height) / float(win)); + + // ROI smaller than kernel? + if (n_winVert == 0 || n_winHor == 0) + { + // Fill the window with data + for (int row=0; row < height; row++) + for (int col = 0; col < width; col++) + { + size_t idx = row * width + col; + W[idx] = Im.get_at(idx); + } + + // Convolve + conv_dud (auxC.data(), W.data(), Gexp, winY, winX, n, n); + + // Collect the result + for (auto y = xy0, b = 0; b < winY; y++, b++) + for (auto x = xy0, a = 0; a < winX; x++, a++) + { + double inten = sqrt(pow(auxC[y * 2 * (winX + n - 1) + x * 2], 2) + pow(auxC[y * 2 * (winX + n - 1) + x * 2 + 1], 2)); // real magnitude, no unsigned-int truncation + // Calculate requested summary + if (max_or_threshold) + max_val = std::max(max_val, double(inten)); + else + if (double(inten) > threshold) + over_threshold_count++; + } + + return; + } + + // ROI larger than kernel + for (int winVert = 0; winVert < n_winVert; winVert++) + { + for (int winHor = 0; winHor < n_winHor; winHor++) + { + // Fill the window with data + for (int row=0; row threshold) + over_threshold_count++; + } + } + } +} + +void GaborFeature::conv_dud_NT ( + double* C, + WriteImageMatrix_nontriv& A, + double* B, + int na, int ma, int nb, int mb) +{ + int ip, iq; // Pointer to elements in 'A' and 'C' matrices + + double wr, wi; // Imaginary and real weights from matrix B + int mc, nc; + + int ir = 0; // Pointer to elements in 'b' matrix + + mc = ma + mb - 1; + nc = (na + nb - 1) * 2; + + // initialize the output matrix + int mcnc = mc * nc; + for (int i = 0; i < mcnc; i++) + C[i] = 0.0; + + for (int j = 0; j < mb; ++j) + { + // For each element in b + for (int i = 0; i < nb; ++i) + { + // Get weight from B matrix + wr = B[ir]; + wi = B[ir + 1]; + ir += 2; + + // Start at first row of A in C + ip = j * nc + i * 2; + iq = 0; + + for (int l = 0; l < ma; l++) + { + // For each row of A ... + for (int k = 0; k < na; k++) + { + // cache A[iq] + double a = A[iq]; + iq++; + + // multiply by the real weight and add + C[ip] += a * wr; + + // multiply by the imaginary weight and add + C[ip + 1] += a * wi; + ip += 2; + } + + // Jump to next row position of A in C + ip += (nb - 1) * 2; + } + } + } +} + diff --git a/src/nyx/features/geo_len_thickness.cpp b/src/nyx/features/geo_len_thickness.cpp index 21bf45fb3..3ce4169f9 100644 --- a/src/nyx/features/geo_len_thickness.cpp +++ b/src/nyx/features/geo_len_thickness.cpp @@ -1,71 +1,71 @@ -#include -#include "geodetic_len_thickness.h" - -using namespace Nyxus; - -bool GeodeticLengthThicknessFeature::required(const FeatureSet& fs) -{ - return fs.anyEnabled({ Feature2D::GEODETIC_LENGTH, Feature2D::THICKNESS }); -} - -GeodeticLengthThicknessFeature::GeodeticLengthThicknessFeature() : FeatureMethod("GeodeticLengthThicknessFeature") -{ - provide_features (GeodeticLengthThicknessFeature::featureset); - add_dependencies ({ Feature2D::AREA_PIXELS_COUNT, Feature2D::PERIMETER }); -} - -void GeodeticLengthThicknessFeature::calculate (LR& r, const Fsettings& s) -{ - // Keep perimeter as a real number: assigning it into size_t truncated the fractional part and - // forced integer division below, so geodetic_length/thickness deviated from the rectangle-model - // formula (e.g. ~11% on the 8x8 shape2d fixture: geodetic 10.0 instead of ~11.13). - double roiArea = r.aux_area, - roiPerimeter = r.fvals[(int)Feature2D::PERIMETER][0]; - - double SqRootTmp = roiPerimeter * roiPerimeter / 16.0 - roiArea; - - // Make sure value under SqRootTmp is always positive - if (SqRootTmp < 0) - SqRootTmp = 0; - - // Calculate geodetic_length with pq-formula (see above): - geodetic_length = roiPerimeter / 4.0 + sqrt(SqRootTmp); - - // Calculate thickness by rewriting Equation (2): - thickness = roiPerimeter / 2.0 - geodetic_length; -} - -void GeodeticLengthThicknessFeature::osized_calculate (LR& r, const Fsettings& s, ImageLoader&) -{ - calculate (r, s); // This feature is not critical to ROI size -} - -void GeodeticLengthThicknessFeature::osized_add_online_pixel (size_t x, size_t y, uint32_t intensity) {} - -void GeodeticLengthThicknessFeature::save_value (std::vector>& fvals) -{ - fvals[(int)Feature2D::GEODETIC_LENGTH][0] = geodetic_length; - fvals[(int)Feature2D::THICKNESS][0] = thickness; -} - -void GeodeticLengthThicknessFeature::extract (LR& r, const Fsettings& s) -{ - GeodeticLengthThicknessFeature glt; - glt.calculate (r, s); - glt.save_value (r.fvals); -} - -void GeodeticLengthThicknessFeature::parallel_process_1_batch (size_t start, size_t end, std::vector* ptrLabels, std::unordered_map * ptrLabelData, const Fsettings & s, const Dataset & _) -{ - for (auto i = start; i < end; i++) - { - int lab = (*ptrLabels)[i]; - LR& r = (*ptrLabelData)[lab]; - - if (r.has_bad_data()) - continue; - - extract (r, s); - } -} - +#include +#include "geodetic_len_thickness.h" + +using namespace Nyxus; + +bool GeodeticLengthThicknessFeature::required(const FeatureSet& fs) +{ + return fs.anyEnabled({ Feature2D::GEODETIC_LENGTH, Feature2D::THICKNESS }); +} + +GeodeticLengthThicknessFeature::GeodeticLengthThicknessFeature() : FeatureMethod("GeodeticLengthThicknessFeature") +{ + provide_features (GeodeticLengthThicknessFeature::featureset); + add_dependencies ({ Feature2D::AREA_PIXELS_COUNT, Feature2D::PERIMETER }); +} + +void GeodeticLengthThicknessFeature::calculate (LR& r, const Fsettings& s) +{ + // Keep perimeter as a real number: assigning it into size_t truncated the fractional part and + // forced integer division below, so geodetic_length/thickness deviated from the rectangle-model + // formula (e.g. ~11% on the 8x8 shape2d fixture: geodetic 10.0 instead of ~11.13). + double roiArea = r.aux_area, + roiPerimeter = r.fvals[static_cast(Feature2D::PERIMETER)][0]; + + double SqRootTmp = roiPerimeter * roiPerimeter / 16.0 - roiArea; + + // Make sure value under SqRootTmp is always positive + if (SqRootTmp < 0) + SqRootTmp = 0; + + // Calculate geodetic_length with pq-formula (see above): + geodetic_length = roiPerimeter / 4.0 + sqrt(SqRootTmp); + + // Calculate thickness by rewriting Equation (2): + thickness = roiPerimeter / 2.0 - geodetic_length; +} + +void GeodeticLengthThicknessFeature::osized_calculate (LR& r, const Fsettings& s, ImageLoader&) +{ + calculate (r, s); // This feature is not critical to ROI size +} + +void GeodeticLengthThicknessFeature::osized_add_online_pixel (size_t x, size_t y, uint32_t intensity) {} + +void GeodeticLengthThicknessFeature::save_value (std::vector>& fvals) +{ + fvals[static_cast(Feature2D::GEODETIC_LENGTH)][0] = geodetic_length; + fvals[static_cast(Feature2D::THICKNESS)][0] = thickness; +} + +void GeodeticLengthThicknessFeature::extract (LR& r, const Fsettings& s) +{ + GeodeticLengthThicknessFeature glt; + glt.calculate (r, s); + glt.save_value (r.fvals); +} + +void GeodeticLengthThicknessFeature::parallel_process_1_batch (size_t start, size_t end, std::vector* ptrLabels, std::unordered_map * ptrLabelData, const Fsettings & s, const Dataset & _) +{ + for (auto i = start; i < end; i++) + { + int lab = (*ptrLabels)[i]; + LR& r = (*ptrLabelData)[lab]; + + if (r.has_bad_data()) + continue; + + extract (r, s); + } +} + diff --git a/src/nyx/features/geodetic_len_thickness.h b/src/nyx/features/geodetic_len_thickness.h index 212661d53..79aedbfde 100644 --- a/src/nyx/features/geodetic_len_thickness.h +++ b/src/nyx/features/geodetic_len_thickness.h @@ -13,7 +13,7 @@ class GeodeticLengthThicknessFeature:public FeatureMethod { public: - const constexpr static std::initializer_list featureset = + static constexpr std::initializer_list featureset = { Nyxus::Feature2D::GEODETIC_LENGTH, Nyxus::Feature2D::THICKNESS diff --git a/src/nyx/features/glcm.cpp b/src/nyx/features/glcm.cpp index 2ee95d952..208d9a7f1 100644 --- a/src/nyx/features/glcm.cpp +++ b/src/nyx/features/glcm.cpp @@ -22,7 +22,7 @@ void GLCMFeature::calculate (LR& r, const Fsettings& s) // (We need to smart-select the greyInfo rather than just theEnvironment.get_coarse_gray_depth()) int nGreys = STNGS_GLCM_GREYDEPTH(s), offset = STNGS_GLCM_OFFSET(s); - double softNAN = s[(int)NyxSetting::SOFTNAN].rval; + double softNAN = s[static_cast(NyxSetting::SOFTNAN)].rval; auto binnedMin = bin_pixel(r.aux_min, r.aux_min, r.aux_max, nGreys); auto binnedMax = bin_pixel(r.aux_max, r.aux_min, r.aux_max, nGreys); @@ -32,65 +32,65 @@ void GLCMFeature::calculate (LR& r, const Fsettings& s) // assign it to each angled feature value auto n = angles.size(); - r.fvals[(int)Feature2D::GLCM_ASM].assign(n, w); - r.fvals[(int)Feature2D::GLCM_ACOR].assign(n, w); - r.fvals[(int)Feature2D::GLCM_CLUPROM].assign(n, w); - r.fvals[(int)Feature2D::GLCM_CLUSHADE].assign(n, w); - r.fvals[(int)Feature2D::GLCM_CLUTEND].assign(n, w); - r.fvals[(int)Feature2D::GLCM_CONTRAST].assign(n, w); - r.fvals[(int)Feature2D::GLCM_CORRELATION].assign(n, w); - r.fvals[(int)Feature2D::GLCM_DIFAVE].assign(n, w); - r.fvals[(int)Feature2D::GLCM_DIFENTRO].assign(n, w); - r.fvals[(int)Feature2D::GLCM_DIFVAR].assign(n, w); - r.fvals[(int)Feature2D::GLCM_DIS].assign(n, w); - r.fvals[(int)Feature2D::GLCM_ENERGY].assign(n, w); - r.fvals[(int)Feature2D::GLCM_ENTROPY].assign(n, w); - r.fvals[(int)Feature2D::GLCM_HOM1].assign(n, w); - r.fvals[(int)Feature2D::GLCM_HOM2].assign(n, w); - r.fvals[(int)Feature2D::GLCM_IDMN].assign(n, w); - r.fvals[(int)Feature2D::GLCM_ID].assign(n, w); - r.fvals[(int)Feature2D::GLCM_IDN].assign(n, w); - r.fvals[(int)Feature2D::GLCM_INFOMEAS1].assign(n, w); - r.fvals[(int)Feature2D::GLCM_INFOMEAS2].assign(n, w); - r.fvals[(int)Feature2D::GLCM_IDM].assign(n, w); - r.fvals[(int)Feature2D::GLCM_IV].assign(n, w); - r.fvals[(int)Feature2D::GLCM_JAVE].assign(n, w); - r.fvals[(int)Feature2D::GLCM_JE].assign(n, w); - r.fvals[(int)Feature2D::GLCM_JMAX].assign(n, w); - r.fvals[(int)Feature2D::GLCM_JVAR].assign(n, w); - r.fvals[(int)Feature2D::GLCM_SUMAVERAGE].assign(n, w); - r.fvals[(int)Feature2D::GLCM_SUMENTROPY].assign(n, w); - r.fvals[(int)Feature2D::GLCM_SUMVARIANCE].assign(n, w); - r.fvals[(int)Feature2D::GLCM_VARIANCE].assign(n, w); - r.fvals[(int)Feature2D::GLCM_ASM_AVE][0] = - r.fvals[(int)Feature2D::GLCM_ACOR_AVE][0] = - r.fvals[(int)Feature2D::GLCM_CLUPROM_AVE][0] = - r.fvals[(int)Feature2D::GLCM_CLUSHADE_AVE][0] = - r.fvals[(int)Feature2D::GLCM_CLUTEND_AVE][0] = - r.fvals[(int)Feature2D::GLCM_CONTRAST_AVE][0] = - r.fvals[(int)Feature2D::GLCM_CORRELATION_AVE][0] = - r.fvals[(int)Feature2D::GLCM_DIFAVE_AVE][0] = - r.fvals[(int)Feature2D::GLCM_DIFENTRO_AVE][0] = - r.fvals[(int)Feature2D::GLCM_DIFVAR_AVE][0] = - r.fvals[(int)Feature2D::GLCM_DIS_AVE][0] = - r.fvals[(int)Feature2D::GLCM_ENERGY_AVE][0] = - r.fvals[(int)Feature2D::GLCM_ENTROPY_AVE][0] = - r.fvals[(int)Feature2D::GLCM_HOM1_AVE][0] = - r.fvals[(int)Feature2D::GLCM_ID_AVE][0] = - r.fvals[(int)Feature2D::GLCM_IDN_AVE][0] = - r.fvals[(int)Feature2D::GLCM_IDM_AVE][0] = - r.fvals[(int)Feature2D::GLCM_IDMN_AVE][0] = - r.fvals[(int)Feature2D::GLCM_IV_AVE][0] = - r.fvals[(int)Feature2D::GLCM_JAVE_AVE][0] = - r.fvals[(int)Feature2D::GLCM_JE_AVE][0] = - r.fvals[(int)Feature2D::GLCM_INFOMEAS1_AVE][0] = - r.fvals[(int)Feature2D::GLCM_INFOMEAS2_AVE][0] = - r.fvals[(int)Feature2D::GLCM_JMAX_AVE][0] = - r.fvals[(int)Feature2D::GLCM_JVAR_AVE][0] = - r.fvals[(int)Feature2D::GLCM_SUMAVERAGE_AVE][0] = - r.fvals[(int)Feature2D::GLCM_SUMENTROPY_AVE][0] = - r.fvals[(int)Feature2D::GLCM_SUMVARIANCE_AVE][0] = - r.fvals[(int)Feature2D::GLCM_VARIANCE_AVE][0] = w; + r.fvals[static_cast(Feature2D::GLCM_ASM)].assign(n, w); + r.fvals[static_cast(Feature2D::GLCM_ACOR)].assign(n, w); + r.fvals[static_cast(Feature2D::GLCM_CLUPROM)].assign(n, w); + r.fvals[static_cast(Feature2D::GLCM_CLUSHADE)].assign(n, w); + r.fvals[static_cast(Feature2D::GLCM_CLUTEND)].assign(n, w); + r.fvals[static_cast(Feature2D::GLCM_CONTRAST)].assign(n, w); + r.fvals[static_cast(Feature2D::GLCM_CORRELATION)].assign(n, w); + r.fvals[static_cast(Feature2D::GLCM_DIFAVE)].assign(n, w); + r.fvals[static_cast(Feature2D::GLCM_DIFENTRO)].assign(n, w); + r.fvals[static_cast(Feature2D::GLCM_DIFVAR)].assign(n, w); + r.fvals[static_cast(Feature2D::GLCM_DIS)].assign(n, w); + r.fvals[static_cast(Feature2D::GLCM_ENERGY)].assign(n, w); + r.fvals[static_cast(Feature2D::GLCM_ENTROPY)].assign(n, w); + r.fvals[static_cast(Feature2D::GLCM_HOM1)].assign(n, w); + r.fvals[static_cast(Feature2D::GLCM_HOM2)].assign(n, w); + r.fvals[static_cast(Feature2D::GLCM_IDMN)].assign(n, w); + r.fvals[static_cast(Feature2D::GLCM_ID)].assign(n, w); + r.fvals[static_cast(Feature2D::GLCM_IDN)].assign(n, w); + r.fvals[static_cast(Feature2D::GLCM_INFOMEAS1)].assign(n, w); + r.fvals[static_cast(Feature2D::GLCM_INFOMEAS2)].assign(n, w); + r.fvals[static_cast(Feature2D::GLCM_IDM)].assign(n, w); + r.fvals[static_cast(Feature2D::GLCM_IV)].assign(n, w); + r.fvals[static_cast(Feature2D::GLCM_JAVE)].assign(n, w); + r.fvals[static_cast(Feature2D::GLCM_JE)].assign(n, w); + r.fvals[static_cast(Feature2D::GLCM_JMAX)].assign(n, w); + r.fvals[static_cast(Feature2D::GLCM_JVAR)].assign(n, w); + r.fvals[static_cast(Feature2D::GLCM_SUMAVERAGE)].assign(n, w); + r.fvals[static_cast(Feature2D::GLCM_SUMENTROPY)].assign(n, w); + r.fvals[static_cast(Feature2D::GLCM_SUMVARIANCE)].assign(n, w); + r.fvals[static_cast(Feature2D::GLCM_VARIANCE)].assign(n, w); + r.fvals[static_cast(Feature2D::GLCM_ASM_AVE)][0] = + r.fvals[static_cast(Feature2D::GLCM_ACOR_AVE)][0] = + r.fvals[static_cast(Feature2D::GLCM_CLUPROM_AVE)][0] = + r.fvals[static_cast(Feature2D::GLCM_CLUSHADE_AVE)][0] = + r.fvals[static_cast(Feature2D::GLCM_CLUTEND_AVE)][0] = + r.fvals[static_cast(Feature2D::GLCM_CONTRAST_AVE)][0] = + r.fvals[static_cast(Feature2D::GLCM_CORRELATION_AVE)][0] = + r.fvals[static_cast(Feature2D::GLCM_DIFAVE_AVE)][0] = + r.fvals[static_cast(Feature2D::GLCM_DIFENTRO_AVE)][0] = + r.fvals[static_cast(Feature2D::GLCM_DIFVAR_AVE)][0] = + r.fvals[static_cast(Feature2D::GLCM_DIS_AVE)][0] = + r.fvals[static_cast(Feature2D::GLCM_ENERGY_AVE)][0] = + r.fvals[static_cast(Feature2D::GLCM_ENTROPY_AVE)][0] = + r.fvals[static_cast(Feature2D::GLCM_HOM1_AVE)][0] = + r.fvals[static_cast(Feature2D::GLCM_ID_AVE)][0] = + r.fvals[static_cast(Feature2D::GLCM_IDN_AVE)][0] = + r.fvals[static_cast(Feature2D::GLCM_IDM_AVE)][0] = + r.fvals[static_cast(Feature2D::GLCM_IDMN_AVE)][0] = + r.fvals[static_cast(Feature2D::GLCM_IV_AVE)][0] = + r.fvals[static_cast(Feature2D::GLCM_JAVE_AVE)][0] = + r.fvals[static_cast(Feature2D::GLCM_JE_AVE)][0] = + r.fvals[static_cast(Feature2D::GLCM_INFOMEAS1_AVE)][0] = + r.fvals[static_cast(Feature2D::GLCM_INFOMEAS2_AVE)][0] = + r.fvals[static_cast(Feature2D::GLCM_JMAX_AVE)][0] = + r.fvals[static_cast(Feature2D::GLCM_JVAR_AVE)][0] = + r.fvals[static_cast(Feature2D::GLCM_SUMAVERAGE_AVE)][0] = + r.fvals[static_cast(Feature2D::GLCM_SUMENTROPY_AVE)][0] = + r.fvals[static_cast(Feature2D::GLCM_SUMVARIANCE_AVE)][0] = + r.fvals[static_cast(Feature2D::GLCM_VARIANCE_AVE)][0] = w; return; } @@ -142,69 +142,69 @@ void GLCMFeature::copyfvals(AngledFeatures& dst, const AngledFeatures& src) void GLCMFeature::save_value(std::vector>& fvals) { - copyfvals(fvals[(int)Feature2D::GLCM_ASM], fvals_ASM); - - copyfvals(fvals[(int)Feature2D::GLCM_ACOR], fvals_acor); - copyfvals(fvals[(int)Feature2D::GLCM_ACOR], fvals_acor); - - copyfvals(fvals[(int)Feature2D::GLCM_CLUPROM], fvals_cluprom); - copyfvals(fvals[(int)Feature2D::GLCM_CLUSHADE], fvals_clushade); - copyfvals(fvals[(int)Feature2D::GLCM_CLUTEND], fvals_clutend); - copyfvals(fvals[(int)Feature2D::GLCM_CONTRAST], fvals_contrast); - copyfvals(fvals[(int)Feature2D::GLCM_CORRELATION], fvals_correlation); - copyfvals(fvals[(int)Feature2D::GLCM_DIFAVE], fvals_diff_avg); - copyfvals(fvals[(int)Feature2D::GLCM_DIFVAR], fvals_diff_var); - copyfvals(fvals[(int)Feature2D::GLCM_DIFENTRO], fvals_diff_entropy); - copyfvals(fvals[(int)Feature2D::GLCM_DIS], fvals_dis); - copyfvals(fvals[(int)Feature2D::GLCM_ENERGY], fvals_energy); - copyfvals(fvals[(int)Feature2D::GLCM_ENTROPY], fvals_entropy); - copyfvals(fvals[(int)Feature2D::GLCM_HOM1], fvals_homo); - copyfvals(fvals[(int)Feature2D::GLCM_HOM2], fvals_hom2); - copyfvals(fvals[(int)Feature2D::GLCM_ID], fvals_id); - copyfvals(fvals[(int)Feature2D::GLCM_IDN], fvals_idn); - copyfvals(fvals[(int)Feature2D::GLCM_IDM], fvals_IDM); - copyfvals(fvals[(int)Feature2D::GLCM_IDMN], fvals_idmn); - copyfvals(fvals[(int)Feature2D::GLCM_INFOMEAS1], fvals_meas_corr1); - copyfvals(fvals[(int)Feature2D::GLCM_INFOMEAS2], fvals_meas_corr2); - copyfvals(fvals[(int)Feature2D::GLCM_IV], fvals_iv); - copyfvals(fvals[(int)Feature2D::GLCM_JAVE], fvals_jave); - copyfvals(fvals[(int)Feature2D::GLCM_JE], fvals_je); - copyfvals(fvals[(int)Feature2D::GLCM_JMAX], fvals_jmax); - copyfvals(fvals[(int)Feature2D::GLCM_JVAR], fvals_jvar); - copyfvals(fvals[(int)Feature2D::GLCM_SUMAVERAGE], fvals_sum_avg); - copyfvals(fvals[(int)Feature2D::GLCM_SUMVARIANCE], fvals_sum_var); - copyfvals(fvals[(int)Feature2D::GLCM_SUMENTROPY], fvals_sum_entropy); - copyfvals(fvals[(int)Feature2D::GLCM_VARIANCE], fvals_variance); - fvals[(int)Feature2D::GLCM_ASM_AVE][0] = calc_ave(fvals_ASM); - fvals[(int)Feature2D::GLCM_ACOR_AVE][0] = calc_ave(fvals_acor); - fvals[(int)Feature2D::GLCM_CLUPROM_AVE][0] = calc_ave(fvals_cluprom); - fvals[(int)Feature2D::GLCM_CLUSHADE_AVE][0] = calc_ave(fvals_clushade); - fvals[(int)Feature2D::GLCM_CLUTEND_AVE][0] = calc_ave(fvals_clutend); - fvals[(int)Feature2D::GLCM_CONTRAST_AVE][0] = calc_ave(fvals_contrast); - fvals[(int)Feature2D::GLCM_CORRELATION_AVE][0] = calc_ave(fvals_correlation); - fvals[(int)Feature2D::GLCM_DIFAVE_AVE][0] = calc_ave(fvals_diff_avg); - fvals[(int)Feature2D::GLCM_DIFVAR_AVE][0] = calc_ave(fvals_diff_var); - fvals[(int)Feature2D::GLCM_DIFENTRO_AVE][0] = calc_ave(fvals_diff_entropy); - fvals[(int)Feature2D::GLCM_DIS_AVE][0] = calc_ave(fvals_dis); - fvals[(int)Feature2D::GLCM_ENERGY_AVE][0] = calc_ave(fvals_energy); - fvals[(int)Feature2D::GLCM_ENTROPY_AVE][0] = calc_ave(fvals_entropy); - fvals[(int)Feature2D::GLCM_HOM1_AVE][0] = calc_ave(fvals_homo); - fvals[(int)Feature2D::GLCM_ID_AVE][0] = calc_ave(fvals_id); - fvals[(int)Feature2D::GLCM_IDN_AVE][0] = calc_ave(fvals_idn); - fvals[(int)Feature2D::GLCM_IDM_AVE][0] = calc_ave(fvals_IDM); - fvals[(int)Feature2D::GLCM_IDMN_AVE][0] = calc_ave(fvals_idmn); - fvals[(int)Feature2D::GLCM_IV_AVE][0] = calc_ave(fvals_iv); - fvals[(int)Feature2D::GLCM_JAVE_AVE][0] = calc_ave(fvals_jave); - fvals[(int)Feature2D::GLCM_JE_AVE][0] = calc_ave(fvals_je); - fvals[(int)Feature2D::GLCM_INFOMEAS1_AVE][0] = calc_ave(fvals_meas_corr1); - fvals[(int)Feature2D::GLCM_INFOMEAS2_AVE][0] = calc_ave(fvals_meas_corr2); - fvals[(int)Feature2D::GLCM_VARIANCE_AVE][0] = calc_ave(fvals_variance); - fvals[(int)Feature2D::GLCM_JMAX_AVE][0] = calc_ave(fvals_jmax); - fvals[(int)Feature2D::GLCM_JVAR_AVE][0] = calc_ave(fvals_jvar); - fvals[(int)Feature2D::GLCM_SUMAVERAGE_AVE][0] = calc_ave(fvals_sum_avg); - fvals[(int)Feature2D::GLCM_SUMVARIANCE_AVE][0] = calc_ave(fvals_sum_var); - fvals[(int)Feature2D::GLCM_SUMENTROPY_AVE][0] = calc_ave(fvals_sum_entropy); - fvals[(int)Feature2D::GLCM_VARIANCE_AVE][0] = calc_ave(fvals_variance); + copyfvals(fvals[static_cast(Feature2D::GLCM_ASM)], fvals_ASM); + + copyfvals(fvals[static_cast(Feature2D::GLCM_ACOR)], fvals_acor); + copyfvals(fvals[static_cast(Feature2D::GLCM_ACOR)], fvals_acor); + + copyfvals(fvals[static_cast(Feature2D::GLCM_CLUPROM)], fvals_cluprom); + copyfvals(fvals[static_cast(Feature2D::GLCM_CLUSHADE)], fvals_clushade); + copyfvals(fvals[static_cast(Feature2D::GLCM_CLUTEND)], fvals_clutend); + copyfvals(fvals[static_cast(Feature2D::GLCM_CONTRAST)], fvals_contrast); + copyfvals(fvals[static_cast(Feature2D::GLCM_CORRELATION)], fvals_correlation); + copyfvals(fvals[static_cast(Feature2D::GLCM_DIFAVE)], fvals_diff_avg); + copyfvals(fvals[static_cast(Feature2D::GLCM_DIFVAR)], fvals_diff_var); + copyfvals(fvals[static_cast(Feature2D::GLCM_DIFENTRO)], fvals_diff_entropy); + copyfvals(fvals[static_cast(Feature2D::GLCM_DIS)], fvals_dis); + copyfvals(fvals[static_cast(Feature2D::GLCM_ENERGY)], fvals_energy); + copyfvals(fvals[static_cast(Feature2D::GLCM_ENTROPY)], fvals_entropy); + copyfvals(fvals[static_cast(Feature2D::GLCM_HOM1)], fvals_homo); + copyfvals(fvals[static_cast(Feature2D::GLCM_HOM2)], fvals_hom2); + copyfvals(fvals[static_cast(Feature2D::GLCM_ID)], fvals_id); + copyfvals(fvals[static_cast(Feature2D::GLCM_IDN)], fvals_idn); + copyfvals(fvals[static_cast(Feature2D::GLCM_IDM)], fvals_IDM); + copyfvals(fvals[static_cast(Feature2D::GLCM_IDMN)], fvals_idmn); + copyfvals(fvals[static_cast(Feature2D::GLCM_INFOMEAS1)], fvals_meas_corr1); + copyfvals(fvals[static_cast(Feature2D::GLCM_INFOMEAS2)], fvals_meas_corr2); + copyfvals(fvals[static_cast(Feature2D::GLCM_IV)], fvals_iv); + copyfvals(fvals[static_cast(Feature2D::GLCM_JAVE)], fvals_jave); + copyfvals(fvals[static_cast(Feature2D::GLCM_JE)], fvals_je); + copyfvals(fvals[static_cast(Feature2D::GLCM_JMAX)], fvals_jmax); + copyfvals(fvals[static_cast(Feature2D::GLCM_JVAR)], fvals_jvar); + copyfvals(fvals[static_cast(Feature2D::GLCM_SUMAVERAGE)], fvals_sum_avg); + copyfvals(fvals[static_cast(Feature2D::GLCM_SUMVARIANCE)], fvals_sum_var); + copyfvals(fvals[static_cast(Feature2D::GLCM_SUMENTROPY)], fvals_sum_entropy); + copyfvals(fvals[static_cast(Feature2D::GLCM_VARIANCE)], fvals_variance); + fvals[static_cast(Feature2D::GLCM_ASM_AVE)][0] = calc_ave(fvals_ASM); + fvals[static_cast(Feature2D::GLCM_ACOR_AVE)][0] = calc_ave(fvals_acor); + fvals[static_cast(Feature2D::GLCM_CLUPROM_AVE)][0] = calc_ave(fvals_cluprom); + fvals[static_cast(Feature2D::GLCM_CLUSHADE_AVE)][0] = calc_ave(fvals_clushade); + fvals[static_cast(Feature2D::GLCM_CLUTEND_AVE)][0] = calc_ave(fvals_clutend); + fvals[static_cast(Feature2D::GLCM_CONTRAST_AVE)][0] = calc_ave(fvals_contrast); + fvals[static_cast(Feature2D::GLCM_CORRELATION_AVE)][0] = calc_ave(fvals_correlation); + fvals[static_cast(Feature2D::GLCM_DIFAVE_AVE)][0] = calc_ave(fvals_diff_avg); + fvals[static_cast(Feature2D::GLCM_DIFVAR_AVE)][0] = calc_ave(fvals_diff_var); + fvals[static_cast(Feature2D::GLCM_DIFENTRO_AVE)][0] = calc_ave(fvals_diff_entropy); + fvals[static_cast(Feature2D::GLCM_DIS_AVE)][0] = calc_ave(fvals_dis); + fvals[static_cast(Feature2D::GLCM_ENERGY_AVE)][0] = calc_ave(fvals_energy); + fvals[static_cast(Feature2D::GLCM_ENTROPY_AVE)][0] = calc_ave(fvals_entropy); + fvals[static_cast(Feature2D::GLCM_HOM1_AVE)][0] = calc_ave(fvals_homo); + fvals[static_cast(Feature2D::GLCM_ID_AVE)][0] = calc_ave(fvals_id); + fvals[static_cast(Feature2D::GLCM_IDN_AVE)][0] = calc_ave(fvals_idn); + fvals[static_cast(Feature2D::GLCM_IDM_AVE)][0] = calc_ave(fvals_IDM); + fvals[static_cast(Feature2D::GLCM_IDMN_AVE)][0] = calc_ave(fvals_idmn); + fvals[static_cast(Feature2D::GLCM_IV_AVE)][0] = calc_ave(fvals_iv); + fvals[static_cast(Feature2D::GLCM_JAVE_AVE)][0] = calc_ave(fvals_jave); + fvals[static_cast(Feature2D::GLCM_JE_AVE)][0] = calc_ave(fvals_je); + fvals[static_cast(Feature2D::GLCM_INFOMEAS1_AVE)][0] = calc_ave(fvals_meas_corr1); + fvals[static_cast(Feature2D::GLCM_INFOMEAS2_AVE)][0] = calc_ave(fvals_meas_corr2); + fvals[static_cast(Feature2D::GLCM_VARIANCE_AVE)][0] = calc_ave(fvals_variance); + fvals[static_cast(Feature2D::GLCM_JMAX_AVE)][0] = calc_ave(fvals_jmax); + fvals[static_cast(Feature2D::GLCM_JVAR_AVE)][0] = calc_ave(fvals_jvar); + fvals[static_cast(Feature2D::GLCM_SUMAVERAGE_AVE)][0] = calc_ave(fvals_sum_avg); + fvals[static_cast(Feature2D::GLCM_SUMVARIANCE_AVE)][0] = calc_ave(fvals_sum_var); + fvals[static_cast(Feature2D::GLCM_SUMENTROPY_AVE)][0] = calc_ave(fvals_sum_entropy); + fvals[static_cast(Feature2D::GLCM_VARIANCE_AVE)][0] = calc_ave(fvals_variance); } void GLCMFeature::extract (LR& r, const Fsettings& s) @@ -259,7 +259,7 @@ void GLCMFeature::Extract_Texture_Features2 (const Fsettings& s, int angle, cons // Blank cooc-matrix? -- no point to use it, assign each feature value '0' and return. if (sum_p == 0) { - double _ = s[(int)NyxSetting::SOFTNAN].rval; + double _ = s[static_cast(NyxSetting::SOFTNAN)].rval; fvals_ASM.push_back(_); fvals_acor.push_back(_); fvals_cluprom.push_back(_); @@ -303,7 +303,7 @@ void GLCMFeature::Extract_Texture_Features2 (const Fsettings& s, int angle, cons // Compute Haralick statistics fvals_ASM.push_back (f_asm(P_matrix)); fvals_contrast.push_back (f_contrast(P_matrix)); - fvals_correlation.push_back (f_corr(s[(int)NyxSetting::SOFTNAN].rval)); + fvals_correlation.push_back (f_corr(s[static_cast(NyxSetting::SOFTNAN)].rval)); fvals_energy.push_back (f_energy(P_matrix)); fvals_homo.push_back (f_homogeneity()); fvals_variance.push_back (f_var(P_matrix)); @@ -314,7 +314,7 @@ void GLCMFeature::Extract_Texture_Features2 (const Fsettings& s, int angle, cons fvals_diff_var.push_back (f_dvar(P_matrix)); fvals_diff_entropy.push_back (f_dentropy(P_matrix)); fvals_diff_avg.push_back (f_difference_avg()); - fvals_meas_corr1.push_back (f_info_meas_corr1(P_matrix, s[(int)NyxSetting::SOFTNAN].rval)); + fvals_meas_corr1.push_back (f_info_meas_corr1(P_matrix, s[static_cast(NyxSetting::SOFTNAN)].rval)); fvals_meas_corr2.push_back (f_info_meas_corr2(P_matrix)); fvals_acor.push_back (f_GLCM_ACOR(P_matrix)); fvals_cluprom.push_back (f_GLCM_CLUPROM()); @@ -351,8 +351,8 @@ void GLCMFeature::calculateCoocMatAtAngle( PixIntens grays_min_val, PixIntens grays_max_val) { - int nGreys = s[(int)NyxSetting::GREYDEPTH].ival; - bool ibsi = s[(int)NyxSetting::IBSI].bval; + int nGreys = s[static_cast(NyxSetting::GREYDEPTH)].ival; + bool ibsi = s[static_cast(NyxSetting::IBSI)].bval; //--- grey bining --- int rows = grays.height, @@ -394,7 +394,7 @@ void GLCMFeature::calculateCoocMatAtAngle( I.assign(U.begin(), U.end()); std::sort(I.begin(), I.end()); - GLCM.allocate((int)I.size(), (int)I.size()); + GLCM.allocate(static_cast(I.size()), static_cast(I.size())); } else if (matlab_grey_binning(greyInfo)) @@ -939,7 +939,7 @@ double GLCMFeature::f_homogeneity() for (int r = 0; r < Ng; r++) for (int c = 0; c < Ng; c++) - homogeneity += P_matrix.yx(r,c) / sum_p / (1.0 + (double)std::abs(r - c)); + homogeneity += P_matrix.yx(r,c) / sum_p / (1.0 + static_cast(std::abs(r - c))); return homogeneity; } @@ -954,10 +954,10 @@ double GLCMFeature::f_GLCM_ACOR(const SimpleMatrix& P) for (int x = 0; x < Ng; x++) { - double xval = (double) I[x]; + double xval = static_cast(I[x]); for (int y = 0; y < Ng; y++) { - double yval = (double) I[y]; + double yval = static_cast(I[y]); f += P.xy(x, y) * xval * yval; } } @@ -1066,7 +1066,7 @@ double GLCMFeature::f_GLCM_HOM2(const SimpleMatrix& P_matrix) for (int y = 0; y < n_levels; y++) // FIX: normalize by sum_p (joint probability), matching f_idm/f_GLCM_JE. Was summing the // UNNORMALIZED co-occurrence counts -> homogeneity > 1 (e.g. 14.79 on the IBSI phantom). - hom2 += (P_matrix.xy(x, y) / sum_p) / (1.0 + (double)std::abs(x - y) * (double)std::abs(x - y)); + hom2 += (P_matrix.xy(x, y) / sum_p) / (1.0 + static_cast(std::abs(x - y) )* static_cast(std::abs(x - y))); return hom2; } diff --git a/src/nyx/features/glcm.h b/src/nyx/features/glcm.h index e60280f90..58d4d69f0 100644 --- a/src/nyx/features/glcm.h +++ b/src/nyx/features/glcm.h @@ -26,7 +26,7 @@ class GLCMFeature : public FeatureMethod, public TextureFeature // Codes of features implemented by this class. Used in feature manager's mechanisms, // in the feature group nickname expansion, and in the feature value output - const constexpr static std::initializer_list featureset = + static constexpr std::initializer_list featureset = { Nyxus::Feature2D::GLCM_ACOR, // Autocorrelation, IBSI # QWB0 Nyxus::Feature2D::GLCM_ASM, // Angular second moment IBSI # 8ZQL @@ -90,7 +90,7 @@ class GLCMFeature : public FeatureMethod, public TextureFeature }; // Features implemented by this class that do not require vector-like angled output. Instead, they are output as a single values - const constexpr static std::initializer_list nonAngledFeatures = + static constexpr std::initializer_list nonAngledFeatures = { Nyxus::Feature2D::GLCM_ASM_AVE, Nyxus::Feature2D::GLCM_ACOR_AVE, @@ -172,7 +172,7 @@ class GLCMFeature : public FeatureMethod, public TextureFeature static inline int cast_to_range(PixIntens orig_I, PixIntens min_orig_I, PixIntens max_orig_I, int min_target_I, int max_target_I) { - int target_I = (int)(double(orig_I - min_orig_I) / double(max_orig_I - min_orig_I) * double(max_target_I - min_target_I) + min_target_I); + int target_I = static_cast((double(orig_I - min_orig_I) / double(max_orig_I - min_orig_I) * double(max_target_I - min_target_I) + min_target_I)); return target_I; } diff --git a/src/nyx/features/glcm_nontriv.cpp b/src/nyx/features/glcm_nontriv.cpp index fab51bcd3..923cf912c 100644 --- a/src/nyx/features/glcm_nontriv.cpp +++ b/src/nyx/features/glcm_nontriv.cpp @@ -132,7 +132,7 @@ void GLCMFeature::calculateCoocMatAtAngle_NT( bool normalize, bool ibsi) { - matrix.allocate ((int)I.size(), (int)I.size()); + matrix.allocate (static_cast(I.size()), static_cast(I.size())); matrix.fill (0.0); int count = 0; // normalizing factor @@ -161,8 +161,8 @@ void GLCMFeature::calculateCoocMatAtAngle_NT( // Cast intensities on the 1-n_levels scale if (ibsi == false) { - x = GLCMFeature::cast_to_range(raw_lvl_x, min_val, max_val, 1, (int)I.size()) - 1; - y = GLCMFeature::cast_to_range(raw_lvl_y, min_val, max_val, 1, (int)I.size()) - 1; + x = GLCMFeature::cast_to_range(raw_lvl_x, min_val, max_val, 1, static_cast(I.size())) - 1; + y = GLCMFeature::cast_to_range(raw_lvl_y, min_val, max_val, 1, static_cast(I.size())) - 1; } // Increment the symmetric count @@ -174,8 +174,8 @@ void GLCMFeature::calculateCoocMatAtAngle_NT( // calculate sum of P for feature calculations sum_p = 0; - for (int i = 0; i < (int)I.size(); ++i) - for (int j = 0; j < (int)I.size(); ++j) + for (int i = 0; i < static_cast(I.size()); ++i) + for (int j = 0; j < static_cast(I.size()); ++j) sum_p += matrix.xy(i, j); // Normalize the matrix @@ -183,8 +183,8 @@ void GLCMFeature::calculateCoocMatAtAngle_NT( return; double realCnt = count; - for (int i = 0; i < (int)I.size(); i++) - for (int j = 0; j < (int)I.size(); j++) + for (int i = 0; i < static_cast(I.size()); i++) + for (int j = 0; j < static_cast(I.size()); j++) matrix.xy(i, j) /= (realCnt + EPSILON); } diff --git a/src/nyx/features/gldm.cpp b/src/nyx/features/gldm.cpp index 8b1f65bd9..0a50d70b0 100644 --- a/src/nyx/features/gldm.cpp +++ b/src/nyx/features/gldm.cpp @@ -167,7 +167,7 @@ void GLDMFeature::calculate (LR& r, const Fsettings& s) //==== Fill the matrix - Ng = greyInfo==0 ? *std::max_element(I.begin(), I.end()) : (int) I.size(); + Ng = greyInfo==0 ? *std::max_element(I.begin(), I.end()) : static_cast(I.size()); Nd = 8 + 1; // N, NE, E, SE, S, SW, W, NW + zero // --allocate the matrix @@ -296,14 +296,14 @@ void GLDMFeature::osized_calculate (LR& r, const Fsettings& s, ImageLoader&) continue; // Find a non-blank pixel - PixIntens pi = Nyxus::to_grayscale((unsigned int) D.yx(row, col), r.aux_min, piRange, nGrays, STNGS_IBSI(s)); // former Environment::ibsi_compliance + PixIntens pi = Nyxus::to_grayscale(static_cast(D.yx(row, col)), r.aux_min, piRange, nGrays, STNGS_IBSI(s)); // former Environment::ibsi_compliance // Count dependencies. Only ROI pixels (raw != 0) are valid neighbours. int nd = 1; // Number of dependencies PixIntens piQ; // Pixel intensity of questionn if (D.safe(row - 1, col) && D.yx(row - 1, col) != 0) { - piQ = Nyxus::to_grayscale((unsigned int) D.yx(row - 1, col), r.aux_min, piRange, nGrays, STNGS_IBSI(s)); // North + piQ = Nyxus::to_grayscale(static_cast(D.yx(row - 1, col)), r.aux_min, piRange, nGrays, STNGS_IBSI(s)); // North if (piQ == pi) nd++; @@ -311,7 +311,7 @@ void GLDMFeature::osized_calculate (LR& r, const Fsettings& s, ImageLoader&) if (D.safe(row - 1, col + 1) && D.yx(row - 1, col + 1) != 0) { - piQ = Nyxus::to_grayscale((unsigned int) D.yx(row - 1, col + 1), r.aux_min, piRange, nGrays, STNGS_IBSI(s)); // North-East + piQ = Nyxus::to_grayscale(static_cast(D.yx(row - 1, col + 1)), r.aux_min, piRange, nGrays, STNGS_IBSI(s)); // North-East if (piQ == pi) nd++; @@ -319,7 +319,7 @@ void GLDMFeature::osized_calculate (LR& r, const Fsettings& s, ImageLoader&) if (D.safe(row, col + 1) && D.yx(row, col + 1) != 0) { - piQ = Nyxus::to_grayscale((unsigned int) D.yx(row, col + 1), r.aux_min, piRange, nGrays, STNGS_IBSI(s)); // East + piQ = Nyxus::to_grayscale(static_cast(D.yx(row, col + 1)), r.aux_min, piRange, nGrays, STNGS_IBSI(s)); // East if (piQ == pi) nd++; @@ -327,7 +327,7 @@ void GLDMFeature::osized_calculate (LR& r, const Fsettings& s, ImageLoader&) if (D.safe(row + 1, col + 1) && D.yx(row + 1, col + 1) != 0) { - piQ = Nyxus::to_grayscale((unsigned int) D.yx(row + 1, col + 1), r.aux_min, piRange, nGrays, STNGS_IBSI(s)); // South-East + piQ = Nyxus::to_grayscale(static_cast(D.yx(row + 1, col + 1)), r.aux_min, piRange, nGrays, STNGS_IBSI(s)); // South-East if (piQ == pi) nd++; @@ -335,7 +335,7 @@ void GLDMFeature::osized_calculate (LR& r, const Fsettings& s, ImageLoader&) if (D.safe(row + 1, col) && D.yx(row + 1, col) != 0) { - piQ = Nyxus::to_grayscale((unsigned int) D.yx(row + 1, col), r.aux_min, piRange, nGrays, STNGS_IBSI(s)); // South + piQ = Nyxus::to_grayscale(static_cast(D.yx(row + 1, col)), r.aux_min, piRange, nGrays, STNGS_IBSI(s)); // South if (piQ == pi) nd++; @@ -343,7 +343,7 @@ void GLDMFeature::osized_calculate (LR& r, const Fsettings& s, ImageLoader&) if (D.safe(row + 1, col - 1) && D.yx(row + 1, col - 1) != 0) { - piQ = Nyxus::to_grayscale((unsigned int) D.yx(row + 1, col - 1), r.aux_min, piRange, nGrays, STNGS_IBSI(s)); // South-West + piQ = Nyxus::to_grayscale(static_cast(D.yx(row + 1, col - 1)), r.aux_min, piRange, nGrays, STNGS_IBSI(s)); // South-West if (piQ == pi) nd++; @@ -351,7 +351,7 @@ void GLDMFeature::osized_calculate (LR& r, const Fsettings& s, ImageLoader&) if (D.safe(row, col - 1) && D.yx(row, col - 1) != 0) { - piQ = Nyxus::to_grayscale((unsigned int) D.yx(row, col - 1), r.aux_min, piRange, nGrays, STNGS_IBSI(s)); // West + piQ = Nyxus::to_grayscale(static_cast(D.yx(row, col - 1)), r.aux_min, piRange, nGrays, STNGS_IBSI(s)); // West if (piQ == pi) nd++; @@ -359,7 +359,7 @@ void GLDMFeature::osized_calculate (LR& r, const Fsettings& s, ImageLoader&) if (D.safe(row - 1, col - 1) && D.yx(row - 1, col - 1) != 0) { - piQ = Nyxus::to_grayscale((unsigned int) D.yx(row - 1, col - 1), r.aux_min, piRange, nGrays, STNGS_IBSI(s)); // North-West + piQ = Nyxus::to_grayscale(static_cast(D.yx(row - 1, col - 1)), r.aux_min, piRange, nGrays, STNGS_IBSI(s)); // North-West if (piQ == pi) nd++; @@ -374,7 +374,7 @@ void GLDMFeature::osized_calculate (LR& r, const Fsettings& s, ImageLoader&) } //==== Fill the matrix - Ng = (int) U.size(); + Ng = static_cast(U.size()); Nd = 8 + 1; // N, NE, E, SE, S, SW, W, NW + zero Nz = (decltype(Nz))Z.size(); @@ -410,20 +410,20 @@ void GLDMFeature::osized_calculate (LR& r, const Fsettings& s, ImageLoader&) void GLDMFeature::save_value(std::vector>& fvals) { - fvals[(int)Feature2D::GLDM_SDE][0] = fv_SDE; - fvals[(int)Feature2D::GLDM_LDE][0] = fv_LDE; - fvals[(int)Feature2D::GLDM_GLN][0] = fv_GLN; - fvals[(int)Feature2D::GLDM_DN][0] = fv_DN; - fvals[(int)Feature2D::GLDM_DNN][0] = fv_DNN; - fvals[(int)Feature2D::GLDM_GLV][0] = fv_GLV; - fvals[(int)Feature2D::GLDM_DV][0] = fv_DV; - fvals[(int)Feature2D::GLDM_DE][0] = fv_DE; - fvals[(int)Feature2D::GLDM_LGLE][0] = fv_LGLE; - fvals[(int)Feature2D::GLDM_HGLE][0] = fv_HGLE; - fvals[(int)Feature2D::GLDM_SDLGLE][0] = fv_SDLGLE; - fvals[(int)Feature2D::GLDM_SDHGLE][0] = fv_SDHGLE; - fvals[(int)Feature2D::GLDM_LDLGLE][0] = fv_LDLGLE; - fvals[(int)Feature2D::GLDM_LDHGLE][0] = fv_LDHGLE; + fvals[static_cast(Feature2D::GLDM_SDE)][0] = fv_SDE; + fvals[static_cast(Feature2D::GLDM_LDE)][0] = fv_LDE; + fvals[static_cast(Feature2D::GLDM_GLN)][0] = fv_GLN; + fvals[static_cast(Feature2D::GLDM_DN)][0] = fv_DN; + fvals[static_cast(Feature2D::GLDM_DNN)][0] = fv_DNN; + fvals[static_cast(Feature2D::GLDM_GLV)][0] = fv_GLV; + fvals[static_cast(Feature2D::GLDM_DV)][0] = fv_DV; + fvals[static_cast(Feature2D::GLDM_DE)][0] = fv_DE; + fvals[static_cast(Feature2D::GLDM_LGLE)][0] = fv_LGLE; + fvals[static_cast(Feature2D::GLDM_HGLE)][0] = fv_HGLE; + fvals[static_cast(Feature2D::GLDM_SDLGLE)][0] = fv_SDLGLE; + fvals[static_cast(Feature2D::GLDM_SDHGLE)][0] = fv_SDHGLE; + fvals[static_cast(Feature2D::GLDM_LDLGLE)][0] = fv_LDLGLE; + fvals[static_cast(Feature2D::GLDM_LDHGLE)][0] = fv_LDHGLE; } // 1. Small Dependence Emphasis(SDE) @@ -522,7 +522,7 @@ double GLDMFeature::calc_GLV() double mu = 0.0; for (int i = 1; i <= Ng; i++) { - double inten = (double) I[i-1]; + double inten = static_cast(I[i-1]); for (int j = 1; j <= Nd; j++) { mu += P.matlab(i, j) / double(Nz) * inten; @@ -532,7 +532,7 @@ double GLDMFeature::calc_GLV() double f = 0.0; for (int i = 1; i <= Ng; i++) { - double inten = (double) I[i-1]; + double inten = static_cast(I[i-1]); for (int j = 1; j <= Nd; j++) { double mu2 = (inten - mu) * (inten - mu); @@ -589,7 +589,7 @@ double GLDMFeature::calc_LGLE() double sum_i = 0; for (int i = 1; i <= Ng; i++) { - double inten2 = (double) I[i-1]; + double inten2 = static_cast(I[i-1]); inten2 *= inten2; double sum_j = 0; for (int j = 1; j <= Nd; j++) @@ -616,7 +616,7 @@ double GLDMFeature::calc_HGLE() double f = 0.0; for (int i = 1; i <= Ng; i++) { - double inten = (double) I[i-1]; + double inten = static_cast(I[i-1]); f += si[i-1] * inten * inten; } @@ -630,7 +630,7 @@ double GLDMFeature::calc_SDLGLE() double f = 0.0; for (int i = 1; i <= Ng; i++) { - double inten = (double) I[i-1]; + double inten = static_cast(I[i-1]); for (int j = 1; j <= Nd; j++) { f += P.matlab(i, j) / double(inten * inten * j * j); @@ -646,7 +646,7 @@ double GLDMFeature::calc_SDHGLE() double f = 0.0; for (int i = 1; i <= Ng; i++) { - double inten = (double) I[i-1]; + double inten = static_cast(I[i-1]); for (int j = 1; j <= Nd; j++) { f += P.matlab(i, j) * (inten * inten) / double(j*j); @@ -662,7 +662,7 @@ double GLDMFeature::calc_LDLGLE() double f = 0.0; for (int i = 1; i <= Ng; i++) { - double inten = (double) I[i-1]; + double inten = static_cast(I[i-1]); for (int j = 1; j <= Nd; j++) { f += P.matlab(i, j) * double(j * j) / (inten * inten); @@ -678,7 +678,7 @@ double GLDMFeature::calc_LDHGLE() double f = 0.0; for (int i = 1; i <= Ng; i++) { - double inten = (double)I[i - 1]; + double inten = static_cast(I[i - 1]); for (int j = 1; j <= Nd; j++) { f += P.matlab(i, j) * double(inten * inten * j * j); diff --git a/src/nyx/features/gldm.h b/src/nyx/features/gldm.h index 341635711..58c8ec726 100644 --- a/src/nyx/features/gldm.h +++ b/src/nyx/features/gldm.h @@ -29,7 +29,7 @@ class GLDMFeature: public FeatureMethod, public TextureFeature // Codes of features implemented by this class. Used in feature manager's mechanisms, // in the feature group nickname expansion, and in the feature value output - const constexpr static std::initializer_list featureset = + static constexpr std::initializer_list featureset = { Nyxus::Feature2D::GLDM_SDE, // Small Dependence Emphasis Nyxus::Feature2D::GLDM_LDE, // Large Dependence Emphasis diff --git a/src/nyx/features/gldzm.cpp b/src/nyx/features/gldzm.cpp index 49410823d..abf021c99 100644 --- a/src/nyx/features/gldzm.cpp +++ b/src/nyx/features/gldzm.cpp @@ -42,7 +42,7 @@ void GLDZMFeature::calc_gldzm_matrix (SimpleMatrix & GLDZM, const { // row. Gray tones are sparse so we need to find indices of tones in 'Z' and use them as rows of P-matrix auto iter = std::find (I.begin(), I.end(), std::get<0>(z)); - int row = (int)(iter - I.begin()); + int row = static_cast((iter - I.begin())); // column (a distance). Distances are dense \in [1,Nd] int col = std::get<1>(z) - 1; // 0-based => -1 auto& k = GLDZM.yx(row, col); @@ -239,7 +239,7 @@ void GLDZMFeature::prepare_GLDZM_matrix_kit (SimpleMatrix& GLDZM, //==== Fill the zonal metric matrix // -- number of discrete intensity values in the image - Ng = (int)I.size(); + Ng = static_cast(I.size()); // -- max zone distance to ROI or image border Nd = 0; @@ -397,7 +397,7 @@ template void GLDZMFeature::calc_features (const std::vector((d_+ 1)); double m = Md [d_]; f_SDE += m / d / d; // Small Distance Emphasis = \frac{1}{N_s} \sum_d \frac{m_d}{d^2} f_LDE += d * d * m; // Large Distance Emphasis = \frac{1}{N_s} \sum_d d^2 m_d @@ -416,7 +416,7 @@ template void GLDZMFeature::calc_features (const std::vector(greysLUT[g]); double x = Mx[g]; f_LGLZE += x / (g_ * g_); // Low Grey Level Emphasis = \frac{1}{N_s} \sum_x \frac{m_x}{x^2} f_HGLZE += (g_ * g_) * x; // High Grey Level Emphasis = \frac{1}{N_s} \sum_x x^2 m_x @@ -434,7 +434,7 @@ template void GLDZMFeature::calc_features (const std::vector(greysLUT[g]), d_ = double (d + 1); double p = P.yx (g,d); f_SDLGLE += p / g_ / g_ / d_ / d_; // Small Distance Low Grey Level Emphasis = \frac{1}{N_s} \sum_x \sum_d \frac{ m_{x,d}}{x^2 d^2} @@ -466,12 +466,12 @@ template void GLDZMFeature::calc_features (const std::vector(greysLUT[g]), dif = x - f_GLM; f_GLV += dif * dif * p; // Zone Distance Variance} = \sum_x \sum_d \left(d - \mu_d \right)^2 p_{x,d} - double d_ = (double) (d + 1); + double d_ = static_cast((d + 1)); dif = d_ - f_ZDM; f_ZDV += dif * dif * p; } @@ -479,24 +479,24 @@ template void GLDZMFeature::calc_features (const std::vector>& fvals) { - fvals[(int)Feature2D::GLDZM_SDE][0] = f_SDE; - fvals[(int)Feature2D::GLDZM_LDE][0] = f_LDE; - fvals[(int)Feature2D::GLDZM_LGLZE][0] = f_LGLZE; - fvals[(int)Feature2D::GLDZM_HGLZE][0] = f_HGLZE; - fvals[(int)Feature2D::GLDZM_SDLGLE][0] = f_SDLGLE; - fvals[(int)Feature2D::GLDZM_SDHGLE][0] = f_SDHGLE; - fvals[(int)Feature2D::GLDZM_LDLGLE][0] = f_LDLGLE; - fvals[(int)Feature2D::GLDZM_LDHGLE][0] = f_LDHGLE; - fvals[(int)Feature2D::GLDZM_GLNU][0] = f_GLNU; - fvals[(int)Feature2D::GLDZM_GLNUN][0] = f_GLNUN; - fvals[(int)Feature2D::GLDZM_ZDNU][0] = f_ZDNU; - fvals[(int)Feature2D::GLDZM_ZDNUN][0] = f_ZDNUN; - fvals[(int)Feature2D::GLDZM_ZP][0] = f_ZP; - fvals[(int)Feature2D::GLDZM_GLM][0] = f_GLM; - fvals[(int)Feature2D::GLDZM_GLV][0] = f_GLV; - fvals[(int)Feature2D::GLDZM_ZDM][0] = f_ZDM; - fvals[(int)Feature2D::GLDZM_ZDV][0] = f_ZDV; - fvals[(int)Feature2D::GLDZM_ZDE][0] = f_ZDE; + fvals[static_cast(Feature2D::GLDZM_SDE)][0] = f_SDE; + fvals[static_cast(Feature2D::GLDZM_LDE)][0] = f_LDE; + fvals[static_cast(Feature2D::GLDZM_LGLZE)][0] = f_LGLZE; + fvals[static_cast(Feature2D::GLDZM_HGLZE)][0] = f_HGLZE; + fvals[static_cast(Feature2D::GLDZM_SDLGLE)][0] = f_SDLGLE; + fvals[static_cast(Feature2D::GLDZM_SDHGLE)][0] = f_SDHGLE; + fvals[static_cast(Feature2D::GLDZM_LDLGLE)][0] = f_LDLGLE; + fvals[static_cast(Feature2D::GLDZM_LDHGLE)][0] = f_LDHGLE; + fvals[static_cast(Feature2D::GLDZM_GLNU)][0] = f_GLNU; + fvals[static_cast(Feature2D::GLDZM_GLNUN)][0] = f_GLNUN; + fvals[static_cast(Feature2D::GLDZM_ZDNU)][0] = f_ZDNU; + fvals[static_cast(Feature2D::GLDZM_ZDNUN)][0] = f_ZDNUN; + fvals[static_cast(Feature2D::GLDZM_ZP)][0] = f_ZP; + fvals[static_cast(Feature2D::GLDZM_GLM)][0] = f_GLM; + fvals[static_cast(Feature2D::GLDZM_GLV)][0] = f_GLV; + fvals[static_cast(Feature2D::GLDZM_ZDM)][0] = f_ZDM; + fvals[static_cast(Feature2D::GLDZM_ZDV)][0] = f_ZDV; + fvals[static_cast(Feature2D::GLDZM_ZDE)][0] = f_ZDE; } void GLDZMFeature::extract (LR& r, const Fsettings& s) @@ -640,19 +640,19 @@ void GLDZMFeature::osized_calculate (LR& r, const Fsettings& s, ImageLoader&) U.insert(inten); // --2 Create a zone - Z_int.add_pixel(Pixel2(-1, -1, (StatsInt)inten)); // using just intensity field of triplet Pixel2 - Z_dist.add_pixel(Pixel2(-1, -1, (StatsInt)zoneMetric)); + Z_int.add_pixel(Pixel2(-1, -1, static_cast(inten))); // using just intensity field of triplet Pixel2 + Z_dist.add_pixel(Pixel2(-1, -1, static_cast(zoneMetric))); } //==== Fill the zonal metric matrix // -- number of discrete intensity values in the image - int Ng = (int)U.size(); + int Ng = static_cast(U.size()); // -- max zone distance to ROI or image border int Nd = 0; for (auto p : Z_dist) - Nd = std::max (Nd, (int)p.inten); + Nd = std::max (Nd, static_cast(p.inten)); // --Set to vector to be able to know each intensity's index std::vector greysLUT (U.begin(), U.end()); @@ -669,7 +669,7 @@ void GLDZMFeature::osized_calculate (LR& r, const Fsettings& s, ImageLoader&) auto dist = Z_dist[i].inten; // row. Gray tones are sparse so we need to find indices of tones in 'Z' and use them as rows of P-matrix auto iter = std::find (greysLUT.begin(), greysLUT.end(), inten); - int row = (int) (iter - greysLUT.begin()); + int row = static_cast((iter - greysLUT.begin())); // col (a distance). Distances are dense \in [1,Nd] int col = dist - 1; // 0-based => -1 auto k = P.yx (row, col); diff --git a/src/nyx/features/gldzm.h b/src/nyx/features/gldzm.h index 67483fbd1..9c91b519e 100644 --- a/src/nyx/features/gldzm.h +++ b/src/nyx/features/gldzm.h @@ -15,7 +15,7 @@ class GLDZMFeature : public FeatureMethod, public TextureFeature // Codes of features implemented by this class. Used in feature manager's mechanisms, // in the feature group nickname expansion, and in the feature value output - const constexpr static std::initializer_list featureset = + static constexpr std::initializer_list featureset = { Nyxus::Feature2D::GLDZM_SDE, // Small Distance Emphasis Nyxus::Feature2D::GLDZM_LDE, // Large Distance Emphasis diff --git a/src/nyx/features/glrlm.cpp b/src/nyx/features/glrlm.cpp index 4d59f803b..40e127816 100644 --- a/src/nyx/features/glrlm.cpp +++ b/src/nyx/features/glrlm.cpp @@ -207,7 +207,7 @@ void GLRLMFeature::calculate (LR& r, const Fsettings& s) int Ng = STNGS_IBSI(s) ? *std::max_element(I.begin(), I.end()) : I.size(); int Nr = maxZoneArea; - int Nz = (int) Z.size(); + int Nz = static_cast(Z.size()); int Np = count; // --allocate the matrix @@ -549,40 +549,40 @@ void GLRLMFeature::osized_calculate (LR& r, const Fsettings& s, ImageLoader&) void GLRLMFeature::save_value(std::vector>& fvals) { - fvals[(int)Feature2D::GLRLM_SRE] = angled_SRE; - fvals[(int)Feature2D::GLRLM_LRE] = angled_LRE; - fvals[(int)Feature2D::GLRLM_GLN] = angled_GLN; - fvals[(int)Feature2D::GLRLM_GLNN] = angled_GLNN; - fvals[(int)Feature2D::GLRLM_RLN] = angled_RLN; - fvals[(int)Feature2D::GLRLM_RLNN] = angled_RLNN; - fvals[(int)Feature2D::GLRLM_RP] = angled_RP; - fvals[(int)Feature2D::GLRLM_GLV] = angled_GLV; - fvals[(int)Feature2D::GLRLM_RV] = angled_RV; - fvals[(int)Feature2D::GLRLM_RE] = angled_RE; - fvals[(int)Feature2D::GLRLM_LGLRE] = angled_LGLRE; - fvals[(int)Feature2D::GLRLM_HGLRE] = angled_HGLRE; - fvals[(int)Feature2D::GLRLM_SRLGLE] = angled_SRLGLE; - fvals[(int)Feature2D::GLRLM_SRHGLE] = angled_SRHGLE; - fvals[(int)Feature2D::GLRLM_LRLGLE] = angled_LRLGLE; - fvals[(int)Feature2D::GLRLM_LRHGLE] = angled_LRHGLE; + fvals[static_cast(Feature2D::GLRLM_SRE)] = angled_SRE; + fvals[static_cast(Feature2D::GLRLM_LRE)] = angled_LRE; + fvals[static_cast(Feature2D::GLRLM_GLN)] = angled_GLN; + fvals[static_cast(Feature2D::GLRLM_GLNN)] = angled_GLNN; + fvals[static_cast(Feature2D::GLRLM_RLN)] = angled_RLN; + fvals[static_cast(Feature2D::GLRLM_RLNN)] = angled_RLNN; + fvals[static_cast(Feature2D::GLRLM_RP)] = angled_RP; + fvals[static_cast(Feature2D::GLRLM_GLV)] = angled_GLV; + fvals[static_cast(Feature2D::GLRLM_RV)] = angled_RV; + fvals[static_cast(Feature2D::GLRLM_RE)] = angled_RE; + fvals[static_cast(Feature2D::GLRLM_LGLRE)] = angled_LGLRE; + fvals[static_cast(Feature2D::GLRLM_HGLRE)] = angled_HGLRE; + fvals[static_cast(Feature2D::GLRLM_SRLGLE)] = angled_SRLGLE; + fvals[static_cast(Feature2D::GLRLM_SRHGLE)] = angled_SRHGLE; + fvals[static_cast(Feature2D::GLRLM_LRLGLE)] = angled_LRLGLE; + fvals[static_cast(Feature2D::GLRLM_LRHGLE)] = angled_LRHGLE; // -- averages -- - fvals[(int)Feature2D::GLRLM_SRE_AVE][0] = calc_ave(angled_SRE); - fvals[(int)Feature2D::GLRLM_LRE_AVE][0] = calc_ave(angled_LRE); - fvals[(int)Feature2D::GLRLM_GLN_AVE][0] = calc_ave(angled_GLN); - fvals[(int)Feature2D::GLRLM_GLNN_AVE][0] = calc_ave(angled_GLNN); - fvals[(int)Feature2D::GLRLM_RLN_AVE][0] = calc_ave(angled_RLN); - fvals[(int)Feature2D::GLRLM_RLNN_AVE][0] = calc_ave(angled_RLNN); - fvals[(int)Feature2D::GLRLM_RP_AVE][0] = calc_ave(angled_RP); - fvals[(int)Feature2D::GLRLM_GLV_AVE][0] = calc_ave(angled_GLV); - fvals[(int)Feature2D::GLRLM_RV_AVE][0] = calc_ave(angled_RV); - fvals[(int)Feature2D::GLRLM_RE_AVE][0] = calc_ave(angled_RE); - fvals[(int)Feature2D::GLRLM_LGLRE_AVE][0] = calc_ave(angled_LGLRE); - fvals[(int)Feature2D::GLRLM_HGLRE_AVE][0] = calc_ave(angled_HGLRE); - fvals[(int)Feature2D::GLRLM_SRLGLE_AVE][0] = calc_ave(angled_SRLGLE); - fvals[(int)Feature2D::GLRLM_SRHGLE_AVE][0] = calc_ave(angled_SRHGLE); - fvals[(int)Feature2D::GLRLM_LRLGLE_AVE][0] = calc_ave(angled_LRLGLE); - fvals[(int)Feature2D::GLRLM_LRHGLE_AVE][0] = calc_ave(angled_LRHGLE); + fvals[static_cast(Feature2D::GLRLM_SRE_AVE)][0] = calc_ave(angled_SRE); + fvals[static_cast(Feature2D::GLRLM_LRE_AVE)][0] = calc_ave(angled_LRE); + fvals[static_cast(Feature2D::GLRLM_GLN_AVE)][0] = calc_ave(angled_GLN); + fvals[static_cast(Feature2D::GLRLM_GLNN_AVE)][0] = calc_ave(angled_GLNN); + fvals[static_cast(Feature2D::GLRLM_RLN_AVE)][0] = calc_ave(angled_RLN); + fvals[static_cast(Feature2D::GLRLM_RLNN_AVE)][0] = calc_ave(angled_RLNN); + fvals[static_cast(Feature2D::GLRLM_RP_AVE)][0] = calc_ave(angled_RP); + fvals[static_cast(Feature2D::GLRLM_GLV_AVE)][0] = calc_ave(angled_GLV); + fvals[static_cast(Feature2D::GLRLM_RV_AVE)][0] = calc_ave(angled_RV); + fvals[static_cast(Feature2D::GLRLM_RE_AVE)][0] = calc_ave(angled_RE); + fvals[static_cast(Feature2D::GLRLM_LGLRE_AVE)][0] = calc_ave(angled_LGLRE); + fvals[static_cast(Feature2D::GLRLM_HGLRE_AVE)][0] = calc_ave(angled_HGLRE); + fvals[static_cast(Feature2D::GLRLM_SRLGLE_AVE)][0] = calc_ave(angled_SRLGLE); + fvals[static_cast(Feature2D::GLRLM_SRHGLE_AVE)][0] = calc_ave(angled_SRHGLE); + fvals[static_cast(Feature2D::GLRLM_LRLGLE_AVE)][0] = calc_ave(angled_LRLGLE); + fvals[static_cast(Feature2D::GLRLM_LRHGLE_AVE)][0] = calc_ave(angled_LRHGLE); } diff --git a/src/nyx/features/glrlm.h b/src/nyx/features/glrlm.h index 6de9618cc..ec6713811 100644 --- a/src/nyx/features/glrlm.h +++ b/src/nyx/features/glrlm.h @@ -21,7 +21,7 @@ class GLRLMFeature : public FeatureMethod, public TextureFeature // Codes of features implemented by this class. Used in feature manager's mechanisms, // in the feature group nickname expansion, and in the feature value output - const constexpr static std::initializer_list featureset = + static constexpr std::initializer_list featureset = { Nyxus::Feature2D::GLRLM_SRE, // Short Run Emphasis Nyxus::Feature2D::GLRLM_LRE, // Long Run Emphasis @@ -59,7 +59,7 @@ class GLRLMFeature : public FeatureMethod, public TextureFeature }; // Features implemented by this class that do not require vector-like angled output. Instead, they are output as a single values - const constexpr static std::initializer_list nonAngledFeatures = + static constexpr std::initializer_list nonAngledFeatures = { Nyxus::Feature2D::GLRLM_SRE_AVE, Nyxus::Feature2D::GLRLM_LRE_AVE, diff --git a/src/nyx/features/glszm.cpp b/src/nyx/features/glszm.cpp index d37e5a878..915e1b4db 100644 --- a/src/nyx/features/glszm.cpp +++ b/src/nyx/features/glszm.cpp @@ -176,9 +176,9 @@ void GLSZMFeature::osized_calculate (LR& r, const Fsettings& s, ImageLoader&) //==== Fill the SZ-matrix - Ng = (int)U.size(); + Ng = static_cast(U.size()); Ns = maxZoneArea; - Nz = (int)Z.size(); + Nz = static_cast(Z.size()); Np = count; // --Set to vector to be able to know each intensity's index @@ -367,7 +367,7 @@ void GLSZMFeature::calculate (LR& r, const Fsettings& s) Ng = STNGS_IBSI(s) ? *std::max_element(I.begin(), I.end()) : I.size(); Ns = height * width; - Nz = (int)Z.size(); + Nz = static_cast(Z.size()); Np = count; // --allocate the matrix @@ -515,7 +515,7 @@ void GLSZMFeature::calc_sums_of_P() // Aggregate by grayscale level for (int i = 1; i <= Ng; ++i) { - double inten = (double) I[i-1]; + double inten = static_cast(I[i-1]); double sum = 0; for (int j = 1; j <= Ns; ++j) { @@ -555,22 +555,22 @@ void GLSZMFeature::calc_sums_of_P() void GLSZMFeature::save_value (std::vector>& fvals) { - fvals[(int)Feature2D::GLSZM_SAE][0] = fv_SAE; - fvals[(int)Feature2D::GLSZM_LAE][0] = fv_LAE; - fvals[(int)Feature2D::GLSZM_GLN][0] = fv_GLN; - fvals[(int)Feature2D::GLSZM_GLNN][0] = fv_GLNN; - fvals[(int)Feature2D::GLSZM_SZN][0] = fv_SZN; - fvals[(int)Feature2D::GLSZM_SZNN][0] = fv_SZNN; - fvals[(int)Feature2D::GLSZM_ZP][0] = fv_ZP; - fvals[(int)Feature2D::GLSZM_GLV][0] = fv_GLV; - fvals[(int)Feature2D::GLSZM_ZV][0] = fv_ZV; - fvals[(int)Feature2D::GLSZM_ZE][0] = fv_ZE; - fvals[(int)Feature2D::GLSZM_LGLZE][0] = fv_LGLZE; - fvals[(int)Feature2D::GLSZM_HGLZE][0] = fv_HGLZE; - fvals[(int)Feature2D::GLSZM_SALGLE][0] = fv_SALGLE; - fvals[(int)Feature2D::GLSZM_SAHGLE][0] = fv_SAHGLE; - fvals[(int)Feature2D::GLSZM_LALGLE][0] = fv_LALGLE; - fvals[(int)Feature2D::GLSZM_LAHGLE][0] = fv_LAHGLE; + fvals[static_cast(Feature2D::GLSZM_SAE)][0] = fv_SAE; + fvals[static_cast(Feature2D::GLSZM_LAE)][0] = fv_LAE; + fvals[static_cast(Feature2D::GLSZM_GLN)][0] = fv_GLN; + fvals[static_cast(Feature2D::GLSZM_GLNN)][0] = fv_GLNN; + fvals[static_cast(Feature2D::GLSZM_SZN)][0] = fv_SZN; + fvals[static_cast(Feature2D::GLSZM_SZNN)][0] = fv_SZNN; + fvals[static_cast(Feature2D::GLSZM_ZP)][0] = fv_ZP; + fvals[static_cast(Feature2D::GLSZM_GLV)][0] = fv_GLV; + fvals[static_cast(Feature2D::GLSZM_ZV)][0] = fv_ZV; + fvals[static_cast(Feature2D::GLSZM_ZE)][0] = fv_ZE; + fvals[static_cast(Feature2D::GLSZM_LGLZE)][0] = fv_LGLZE; + fvals[static_cast(Feature2D::GLSZM_HGLZE)][0] = fv_HGLZE; + fvals[static_cast(Feature2D::GLSZM_SALGLE)][0] = fv_SALGLE; + fvals[static_cast(Feature2D::GLSZM_SAHGLE)][0] = fv_SAHGLE; + fvals[static_cast(Feature2D::GLSZM_LALGLE)][0] = fv_LALGLE; + fvals[static_cast(Feature2D::GLSZM_LAHGLE)][0] = fv_LAHGLE; } // 1. Small Area Emphasis @@ -674,7 +674,7 @@ double GLSZMFeature::calc_GLV() double f = 0.0; for (int i = 1; i <= Ng; i++) { - double inten = (double) I[i-1]; + double inten = static_cast(I[i-1]); for (int j = 1; j <= Ns; j++) { double d2 = (inten - mu_GLV) * (inten - mu_GLV); @@ -715,7 +715,7 @@ double GLSZMFeature::calc_LGLZE() double f = 0.0; for (int i = 1; i <= Ng; i++) { - double inten = (double)I[i - 1]; + double inten = static_cast(I[i - 1]); f += si[i] / (inten * inten); } @@ -730,7 +730,7 @@ double GLSZMFeature::calc_HGLZE() double f = 0.0; for (int i = 1; i <= Ng; i++) { - double inten = (double) I[i-1]; + double inten = static_cast(I[i-1]); f += si[i] * (inten * inten); } diff --git a/src/nyx/features/glszm.h b/src/nyx/features/glszm.h index 67c151794..d8363c45a 100644 --- a/src/nyx/features/glszm.h +++ b/src/nyx/features/glszm.h @@ -22,7 +22,7 @@ class GLSZMFeature: public FeatureMethod, public TextureFeature // Codes of features implemented by this class. Used in feature manager's mechanisms, // in the feature group nickname expansion, and in the feature value output - const constexpr static std::initializer_list featureset = + static constexpr std::initializer_list featureset = { Nyxus::Feature2D::GLSZM_SAE, // Small Area Emphasis Nyxus::Feature2D::GLSZM_LAE, // Large Area Emphasis diff --git a/src/nyx/features/hexagonality_polygonality.cpp b/src/nyx/features/hexagonality_polygonality.cpp index daaa7b033..5ce54f330 100644 --- a/src/nyx/features/hexagonality_polygonality.cpp +++ b/src/nyx/features/hexagonality_polygonality.cpp @@ -31,13 +31,13 @@ void HexagonalityPolygonalityFeature::calculate (LR& r, const Fsettings& s) // Dispersion of hexagonality_score relative to its mean. // - size_t neighbors = r.fvals[(int)Feature2D::NUM_NEIGHBORS][0]; + size_t neighbors = r.fvals[static_cast(Feature2D::NUM_NEIGHBORS)][0]; double area = r.aux_area; - double perimeter = r.fvals[(int)Feature2D::PERIMETER][0]; - double area_hull = r.fvals[(int)Feature2D::CONVEX_HULL_AREA][0]; + double perimeter = r.fvals[static_cast(Feature2D::PERIMETER)][0]; + double area_hull = r.fvals[static_cast(Feature2D::CONVEX_HULL_AREA)][0]; double perim_hull = 6 * sqrt(area_hull / (1.5 * sqrt(3))); - double min_feret_diam = r.fvals[(int)Feature2D::STAT_FERET_DIAM_MIN][0]; - double max_feret_diam = r.fvals[(int)Feature2D::STAT_FERET_DIAM_MAX][0]; + double min_feret_diam = r.fvals[static_cast(Feature2D::STAT_FERET_DIAM_MIN)][0]; + double max_feret_diam = r.fvals[static_cast(Feature2D::STAT_FERET_DIAM_MAX)][0]; double perimeter_neighbors; if (neighbors == 0) @@ -174,9 +174,9 @@ void HexagonalityPolygonalityFeature::osized_calculate (LR& r, const Fsettings& void HexagonalityPolygonalityFeature::save_value(std::vector>& fvals) { - fvals[(int)Feature2D::POLYGONALITY_AVE][0] = polyAve; - fvals[(int)Feature2D::HEXAGONALITY_AVE][0] = hexAve; - fvals[(int)Feature2D::HEXAGONALITY_STDDEV][0] = hexSd; + fvals[static_cast(Feature2D::POLYGONALITY_AVE)][0] = polyAve; + fvals[static_cast(Feature2D::HEXAGONALITY_AVE)][0] = hexAve; + fvals[static_cast(Feature2D::HEXAGONALITY_STDDEV)][0] = hexSd; } void HexagonalityPolygonalityFeature::parallel_process_1_batch (size_t start, size_t end, std::vector* ptrLabels, std::unordered_map * ptrLabelData, const Fsettings & s, const Dataset & _) @@ -199,7 +199,7 @@ void HexagonalityPolygonalityFeature::parallel_process_1_batch (size_t start, si } // Feasibility check #2 - if (r.multicontour_.empty() || r.multicontour_[0].empty() || r.fvals[(int)Feature2D::CONVEX_HULL_AREA][0] == 0 || r.fvals[(int)Feature2D::NUM_NEIGHBORS][0] == 0) + if (r.multicontour_.empty() || r.multicontour_[0].empty() || r.fvals[static_cast(Feature2D::CONVEX_HULL_AREA)][0] == 0 || r.fvals[static_cast(Feature2D::NUM_NEIGHBORS)][0] == 0) { // Explicitly assign dummy yet valid values to indicate that features weren't calculated. Better than NAN - less data cleaning before training HexagonalityPolygonalityFeature hexpo; diff --git a/src/nyx/features/histogram.h b/src/nyx/features/histogram.h index e1547edd4..cdaaccc13 100644 --- a/src/nyx/features/histogram.h +++ b/src/nyx/features/histogram.h @@ -359,7 +359,7 @@ class TrivialHistogram if (n % 2 != 0) { HistoItem median = raw_I[n / 2]; - return (double)median; + return static_cast(median); } else { diff --git a/src/nyx/features/image_matrix.cpp b/src/nyx/features/image_matrix.cpp index c3f8e35cc..ae9b538a5 100644 --- a/src/nyx/features/image_matrix.cpp +++ b/src/nyx/features/image_matrix.cpp @@ -146,7 +146,7 @@ void ImageMatrix::histogram(double* bins, unsigned short nbins, bool imhist, con // similar to the Matlab imhist h_min = 0; int bits = sizeof(PixIntens) * 8; - h_max = pow((double)2, bits) - 1; + h_max = pow(static_cast(2), bits) - 1; } else if (in_stats.n() > 0) { @@ -161,7 +161,7 @@ void ImageMatrix::histogram(double* bins, unsigned short nbins, bool imhist, con h_min = local_stats.min__(); h_max = local_stats.max__(); } - if (h_max - h_min > 0) h_scale = (double)nbins / double(h_max - h_min); + if (h_max - h_min > 0) h_scale = static_cast(nbins )/ double(h_max - h_min); else h_scale = 0; // initialize the bins, invicem "memset(bins, 0, nbins * sizeof(double))" @@ -174,7 +174,7 @@ void ImageMatrix::histogram(double* bins, unsigned short nbins, bool imhist, con val = pix_plane[a]; if (std::isnan(val)) continue; - bin = (unsigned long)(((val - h_min) * h_scale)); + bin = static_cast((((val - h_min) * h_scale))); if (bin >= nbins) bin = nbins - 1; bins[bin] += 1.0; } @@ -196,7 +196,7 @@ void ImageMatrix::apply_distance_to_contour_weights (const std::vector& r = p.y - original_aabb.get_ymin(); // Weighted intensity - PixIntens wi = PixIntens((double)_pix_plane.yx(r, c) / (dist + epsilon)); + PixIntens wi = PixIntens(static_cast(_pix_plane.yx(r, c) )/ (dist + epsilon)); _pix_plane.yx(r,c) = wi; } @@ -264,7 +264,7 @@ void apply_dist2contour_weighting( double dist = std::sqrt(mind2); // adjusted intensity - PixIntens wi = PixIntens((double)p.inten / (dist + epsilon)); + PixIntens wi = PixIntens(static_cast(p.inten )/ (dist + epsilon)); // save p.inten = wi; diff --git a/src/nyx/features/image_matrix_nontriv.cpp b/src/nyx/features/image_matrix_nontriv.cpp index 2a98038c1..0aab16a72 100644 --- a/src/nyx/features/image_matrix_nontriv.cpp +++ b/src/nyx/features/image_matrix_nontriv.cpp @@ -327,7 +327,7 @@ double OOR_ReadMatrix::get_at (size_t pixel_row, size_t pixel_col) const auto& dataI = imloader.get_int_tile_buffer(); size_t idx = imloader.get_within_tile_idx(pixel_row, pixel_col); auto val = dataI[idx]; - return (double)val; + return static_cast(val); } double OOR_ReadMatrix::get_at(size_t idx) const @@ -382,7 +382,7 @@ double ReadImageMatrix_nontriv::get_at (ImageLoader& imloader, size_t pixel_row, auto& dataI = imloader.get_int_tile_buffer(); size_t idx = imloader.get_within_tile_idx (pixel_row, pixel_col); auto val = dataI[idx]; - return (double)val; + return static_cast(val); } double ReadImageMatrix_nontriv::get_at (ImageLoader& imloader, size_t idx) diff --git a/src/nyx/features/image_matrix_nontriv.h b/src/nyx/features/image_matrix_nontriv.h index 649fc71e4..8b0aa6005 100644 --- a/src/nyx/features/image_matrix_nontriv.h +++ b/src/nyx/features/image_matrix_nontriv.h @@ -164,7 +164,7 @@ class WriteImageMatrix_nontriv size_t get_height(); size_t get_chlen(size_t x); bool safe(size_t y, size_t x) const; - PixIntens operator[] (size_t idx) { return (PixIntens) get_at(idx); } + PixIntens operator[] (size_t idx) { return static_cast(get_at(idx)); } void check_non_empty(); std::string info(); diff --git a/src/nyx/features/intensity.cpp b/src/nyx/features/intensity.cpp index f4f268dd8..c462f4172 100644 --- a/src/nyx/features/intensity.cpp +++ b/src/nyx/features/intensity.cpp @@ -90,7 +90,7 @@ void PixelIntensityFeatures::calculate (LR& r, const Fsettings & fsett, const Da val_COV = val_STANDARD_DEVIATION_BIASED = val_VARIANCE = - val_VARIANCE_BIASED = fsett[(int)NyxSetting::SOFTNAN].rval; // former theEnvironment.resultOptions.noval(); + val_VARIANCE_BIASED = fsett[static_cast(NyxSetting::SOFTNAN)].rval; // former theEnvironment.resultOptions.noval(); return; } @@ -358,48 +358,48 @@ void PixelIntensityFeatures::osized_calculate (LR& r, const Fsettings& stng, con void PixelIntensityFeatures::save_value(std::vector>& fvals) { - fvals[(int)Feature2D::INTEGRATED_INTENSITY][0] = val_INTEGRATED_INTENSITY; - fvals[(int)Feature2D::MEAN][0] = val_MEAN; - fvals[(int)Feature2D::MEDIAN][0] = val_MEDIAN; - fvals[(int)Feature2D::MIN][0] = val_MIN; - fvals[(int)Feature2D::MAX][0] = val_MAX; - fvals[(int)Feature2D::RANGE][0] = val_RANGE; - fvals[(int)Feature2D::COVERED_IMAGE_INTENSITY_RANGE][0] = val_COVERED_IMAGE_INTENSITY_RANGE; - fvals[(int)Feature2D::STANDARD_DEVIATION][0] = val_STANDARD_DEVIATION; - fvals[(int)Feature2D::STANDARD_ERROR][0] = val_STANDARD_ERROR; - fvals[(int)Feature2D::SKEWNESS][0] = val_SKEWNESS; - fvals[(int)Feature2D::KURTOSIS][0] = val_KURTOSIS; - fvals[(int)Feature2D::EXCESS_KURTOSIS][0] = val_EXCESS_KURTOSIS; - fvals[(int)Feature2D::HYPERSKEWNESS][0] = val_HYPERSKEWNESS; - fvals[(int)Feature2D::HYPERFLATNESS][0] = val_HYPERFLATNESS; - fvals[(int)Feature2D::MEAN_ABSOLUTE_DEVIATION][0] = val_MEAN_ABSOLUTE_DEVIATION; - fvals[(int)Feature2D::MEDIAN_ABSOLUTE_DEVIATION][0] = val_MEDIAN_ABSOLUTE_DEVIATION; - fvals[(int)Feature2D::ENERGY][0] = val_ENERGY; - fvals[(int)Feature2D::ROOT_MEAN_SQUARED][0] = val_ROOT_MEAN_SQUARED; - fvals[(int)Feature2D::ENTROPY][0] = val_ENTROPY; - fvals[(int)Feature2D::MODE][0] = val_MODE; - fvals[(int)Feature2D::UNIFORMITY][0] = val_UNIFORMITY; - fvals[(int)Feature2D::UNIFORMITY_PIU][0] = val_UNIFORMITY_PIU; - fvals[(int)Feature2D::P01][0] = val_P01; - fvals[(int)Feature2D::P10][0] = val_P10; - fvals[(int)Feature2D::P25][0] = val_P25; - fvals[(int)Feature2D::P75][0] = val_P75; - fvals[(int)Feature2D::P90][0] = val_P90; - fvals[(int)Feature2D::P99][0] = val_P99; - fvals[(int)Feature2D::QCOD][0] = val_QCOD; - fvals[(int)Feature2D::INTERQUARTILE_RANGE][0] = val_INTERQUARTILE_RANGE; - fvals[(int)Feature2D::QCOD][0] = val_QCOD; - fvals[(int)Feature2D::ROBUST_MEAN][0] = val_ROBUST_MEAN; - fvals[(int)Feature2D::ROBUST_MEAN_ABSOLUTE_DEVIATION][0] = val_ROBUST_MEAN_ABSOLUTE_DEVIATION; - fvals[(int)Feature2D::COV][0] = val_COV; - fvals[(int)Feature2D::STANDARD_DEVIATION_BIASED][0] = val_STANDARD_DEVIATION_BIASED; - fvals[(int)Feature2D::VARIANCE][0] = val_VARIANCE; - fvals[(int)Feature2D::VARIANCE_BIASED][0] = val_VARIANCE_BIASED; + fvals[static_cast(Feature2D::INTEGRATED_INTENSITY)][0] = val_INTEGRATED_INTENSITY; + fvals[static_cast(Feature2D::MEAN)][0] = val_MEAN; + fvals[static_cast(Feature2D::MEDIAN)][0] = val_MEDIAN; + fvals[static_cast(Feature2D::MIN)][0] = val_MIN; + fvals[static_cast(Feature2D::MAX)][0] = val_MAX; + fvals[static_cast(Feature2D::RANGE)][0] = val_RANGE; + fvals[static_cast(Feature2D::COVERED_IMAGE_INTENSITY_RANGE)][0] = val_COVERED_IMAGE_INTENSITY_RANGE; + fvals[static_cast(Feature2D::STANDARD_DEVIATION)][0] = val_STANDARD_DEVIATION; + fvals[static_cast(Feature2D::STANDARD_ERROR)][0] = val_STANDARD_ERROR; + fvals[static_cast(Feature2D::SKEWNESS)][0] = val_SKEWNESS; + fvals[static_cast(Feature2D::KURTOSIS)][0] = val_KURTOSIS; + fvals[static_cast(Feature2D::EXCESS_KURTOSIS)][0] = val_EXCESS_KURTOSIS; + fvals[static_cast(Feature2D::HYPERSKEWNESS)][0] = val_HYPERSKEWNESS; + fvals[static_cast(Feature2D::HYPERFLATNESS)][0] = val_HYPERFLATNESS; + fvals[static_cast(Feature2D::MEAN_ABSOLUTE_DEVIATION)][0] = val_MEAN_ABSOLUTE_DEVIATION; + fvals[static_cast(Feature2D::MEDIAN_ABSOLUTE_DEVIATION)][0] = val_MEDIAN_ABSOLUTE_DEVIATION; + fvals[static_cast(Feature2D::ENERGY)][0] = val_ENERGY; + fvals[static_cast(Feature2D::ROOT_MEAN_SQUARED)][0] = val_ROOT_MEAN_SQUARED; + fvals[static_cast(Feature2D::ENTROPY)][0] = val_ENTROPY; + fvals[static_cast(Feature2D::MODE)][0] = val_MODE; + fvals[static_cast(Feature2D::UNIFORMITY)][0] = val_UNIFORMITY; + fvals[static_cast(Feature2D::UNIFORMITY_PIU)][0] = val_UNIFORMITY_PIU; + fvals[static_cast(Feature2D::P01)][0] = val_P01; + fvals[static_cast(Feature2D::P10)][0] = val_P10; + fvals[static_cast(Feature2D::P25)][0] = val_P25; + fvals[static_cast(Feature2D::P75)][0] = val_P75; + fvals[static_cast(Feature2D::P90)][0] = val_P90; + fvals[static_cast(Feature2D::P99)][0] = val_P99; + fvals[static_cast(Feature2D::QCOD)][0] = val_QCOD; + fvals[static_cast(Feature2D::INTERQUARTILE_RANGE)][0] = val_INTERQUARTILE_RANGE; + fvals[static_cast(Feature2D::QCOD)][0] = val_QCOD; + fvals[static_cast(Feature2D::ROBUST_MEAN)][0] = val_ROBUST_MEAN; + fvals[static_cast(Feature2D::ROBUST_MEAN_ABSOLUTE_DEVIATION)][0] = val_ROBUST_MEAN_ABSOLUTE_DEVIATION; + fvals[static_cast(Feature2D::COV)][0] = val_COV; + fvals[static_cast(Feature2D::STANDARD_DEVIATION_BIASED)][0] = val_STANDARD_DEVIATION_BIASED; + fvals[static_cast(Feature2D::VARIANCE)][0] = val_VARIANCE; + fvals[static_cast(Feature2D::VARIANCE_BIASED)][0] = val_VARIANCE_BIASED; // Multi-valued: one frequency per histogram bin. assign() grows the inner // vector from its default size of 1 to the bin count (empty for blank ROIs; // the CSV writer pads to the bin count with zeros). - fvals[(int)Feature2D::HISTOGRAM].assign (val_HISTOGRAM.begin(), val_HISTOGRAM.end()); + fvals[static_cast(Feature2D::HISTOGRAM)].assign (val_HISTOGRAM.begin(), val_HISTOGRAM.end()); } void PixelIntensityFeatures::extract (LR& r, const Fsettings & fs, const Dataset & ds) diff --git a/src/nyx/features/intensity.h b/src/nyx/features/intensity.h index 140c61bf9..f94e51bd9 100644 --- a/src/nyx/features/intensity.h +++ b/src/nyx/features/intensity.h @@ -5,7 +5,7 @@ class PixelIntensityFeatures : public FeatureMethod { public: - const constexpr static std::initializer_list featureset = + static constexpr std::initializer_list featureset = { Nyxus::Feature2D::COV, Nyxus::Feature2D::COVERED_IMAGE_INTENSITY_RANGE, diff --git a/src/nyx/features/intensity_histogram.cpp b/src/nyx/features/intensity_histogram.cpp index 7f962e0ac..53bf37d0e 100644 --- a/src/nyx/features/intensity_histogram.cpp +++ b/src/nyx/features/intensity_histogram.cpp @@ -23,7 +23,7 @@ void IntensityHistogramFeatures::fill_invalid (double nan_val) result_.clear(); result_.reserve (featureset.size()); for (auto fc : featureset) - result_.push_back ({ (int)fc, nan_val }); + result_.push_back ({ static_cast(fc), nan_val }); } // IBSI Intensity Histogram core: all 46 features are derived from a single N-bin @@ -37,18 +37,18 @@ void IntensityHistogramFeatures::compute (const Pixelcloud& pixels, double minVa // --- Build the N-bin frequency histogram (bin index = floor((v-min)/binW) // clamped to [0,N-1]; v==max folds into the last bin). - std::vector freq ((size_t)N, 0.0); + std::vector freq (static_cast(N), 0.0); const size_t M = pixels.size(); for (size_t j = 0; j < M; j++) { - double v = poffset + pscale * (double) pixels[j].inten; - int idx = (int) std::floor ((v - minVal) / binWidth); + double v = poffset + pscale * static_cast(pixels[j].inten); + int idx = static_cast(std::floor ((v - minVal) / binWidth)); if (idx < 0) idx = 0; if (idx >= N) idx = N - 1; - freq[(size_t)idx] += 1.0; + freq[static_cast(idx)] += 1.0; } - const double totalFrequency = (double) count; + const double totalFrequency = static_cast(count); // bin geometry auto binMin = [&](int i) { return minVal + double(i) * binWidth; }; @@ -58,7 +58,7 @@ void IntensityHistogramFeatures::compute (const Pixelcloud& pixels, double minVa // Bin index (0-based) of an arbitrary value auto getIndexOf = [&](double value) -> int { - int idx = (int) std::floor ((value - minVal) / binWidth); + int idx = static_cast(std::floor ((value - minVal) / binWidth)); if (idx < 0) idx = 0; if (idx >= N) idx = N - 1; return idx; @@ -73,7 +73,7 @@ void IntensityHistogramFeatures::compute (const Pixelcloud& pixels, double minVa int n = 0; p_n = 0.0; do { - f_n = freq[(size_t)n]; + f_n = freq[static_cast(n)]; cumulated += f_n; p_n_prev = p_n; p_n = cumulated / totalFrequency; @@ -88,7 +88,7 @@ void IntensityHistogramFeatures::compute (const Pixelcloud& pixels, double minVa int n = N - 1, m = 0; p_n = 1.0; do { - f_n = freq[(size_t)n]; + f_n = freq[static_cast(n)]; cumulated += f_n; p_n_prev = p_n; p_n = 1.0 - cumulated / totalFrequency; @@ -109,7 +109,7 @@ void IntensityHistogramFeatures::compute (const Pixelcloud& pixels, double minVa int bin = 0; while (total <= half && bin < N) { - total += freq[(size_t)bin]; + total += freq[static_cast(bin)]; ++bin; } --bin; @@ -132,7 +132,7 @@ void IntensityHistogramFeatures::compute (const Pixelcloud& pixels, double minVa double robustMeanValue = 0.0, robustMeanIndex = 0.0, robustCount = 0.0; for (int i = 0; i < N; i++) { - double f = freq[(size_t)i]; + double f = freq[static_cast(i)]; double probability = f / totalFrequency; double voxelValue = binCenter (i); @@ -169,7 +169,7 @@ void IntensityHistogramFeatures::compute (const Pixelcloud& pixels, double minVa for (int i = 0; i < N; i++) { - double f = freq[(size_t)i]; + double f = freq[static_cast(i)]; double probability = f / totalFrequency; double voxelValue = binCenter (i); @@ -209,9 +209,9 @@ void IntensityHistogramFeatures::compute (const Pixelcloud& pixels, double minVa if (i == 0) gradient = freq[1] - freq[0]; else if (i == N - 1) - gradient = freq[(size_t)i] - freq[(size_t)(i - 1)]; + gradient = freq[static_cast(i)] - freq[static_cast((i - 1))]; else - gradient = (freq[(size_t)(i + 1)] - freq[(size_t)(i - 1)]) / 2.0; + gradient = (freq[static_cast((i + 1))] - freq[static_cast((i - 1))]) / 2.0; if (gradient > maximumGradientValue) { @@ -294,7 +294,7 @@ void IntensityHistogramFeatures::compute (const Pixelcloud& pixels, double minVa result_.reserve (featureset.size()); int k = 0; for (auto fc : featureset) - result_.push_back ({ (int)fc, out[k++] }); + result_.push_back ({ static_cast(fc), out[k++] }); } void IntensityHistogramFeatures::calculate (LR& r, const Fsettings& s, const Dataset& ds) diff --git a/src/nyx/features/intensity_histogram.h b/src/nyx/features/intensity_histogram.h index 815fa0f66..375856fbb 100644 --- a/src/nyx/features/intensity_histogram.h +++ b/src/nyx/features/intensity_histogram.h @@ -24,7 +24,7 @@ class IntensityHistogramFeatures : public FeatureMethod { public: - const constexpr static std::initializer_list featureset = + static constexpr std::initializer_list featureset = { // "...Value" family (20) Nyxus::Feature2D::IH_MEAN_VAL, diff --git a/src/nyx/features/neighbors.cpp b/src/nyx/features/neighbors.cpp index 0b17dd34e..fc9b264a3 100644 --- a/src/nyx/features/neighbors.cpp +++ b/src/nyx/features/neighbors.cpp @@ -1,31 +1,31 @@ -#define _USE_MATH_DEFINES // For M_PI, etc. -#include -#include +#define _USE_MATH_DEFINES // For M_PI, etc. +#include +#include #include #include #include #include #include #include -#include -#include -#include +#include +#include +#include #include "../globals.h" #include "../environment.h" #include "neighbors.h" -using namespace Nyxus; - -namespace -{ - double direction_angle_deg(double x1, double y1, double x2, double y2) - { - double ang = std::atan2(y2 - y1, x2 - x1) * 180.0 / M_PI; - if (ang < 0.0) - ang += 360.0; - return ang; - } -} +using namespace Nyxus; + +namespace +{ + double direction_angle_deg(double x1, double y1, double x2, double y2) + { + double ang = std::atan2(y2 - y1, x2 - x1) * 180.0 / M_PI; + if (ang < 0.0) + ang += 360.0; + return ang; + } +} bool NeighborsFeature::required(const FeatureSet& fs) { @@ -113,10 +113,10 @@ void parallel_process_1_batch_of_collision_pairs ( continue; // Save partial statis of r1's touching pixel stats - r1.fvals[(int)Feature2D::PERCENT_TOUCHING][0] += n_touchingOuterPixels; + r1.fvals[static_cast(Feature2D::PERCENT_TOUCHING)][0] += n_touchingOuterPixels; // Definitely neighbors - r1.fvals[(int)Feature2D::NUM_NEIGHBORS][0]++; + r1.fvals[static_cast(Feature2D::NUM_NEIGHBORS)][0]++; r1.aux_neighboring_labels.push_back(l2); } } @@ -128,50 +128,50 @@ void NeighborsFeature::manual_reduce ( // in const Fsettings& s, const std::unordered_set & uniqueLabels) -{ - int radius = STNGS_PIXELDISTANCE(s); // former theEnvironment.get_pixel_distance() - int n_threads = 1; - const int percentTouchingIdx = static_cast(Feature2D::PERCENT_TOUCHING); - const int numNeighborsIdx = static_cast(Feature2D::NUM_NEIGHBORS); - const int centroidXIdx = static_cast(Feature2D::CENTROID_X); - const int centroidYIdx = static_cast(Feature2D::CENTROID_Y); - const int closestNeighbor1DistIdx = static_cast(Feature2D::CLOSEST_NEIGHBOR1_DIST); - const int closestNeighbor1AngIdx = static_cast(Feature2D::CLOSEST_NEIGHBOR1_ANG); - const int closestNeighbor2DistIdx = static_cast(Feature2D::CLOSEST_NEIGHBOR2_DIST); - const int closestNeighbor2AngIdx = static_cast(Feature2D::CLOSEST_NEIGHBOR2_ANG); - const int angBetweenNeighborsMeanIdx = static_cast(Feature2D::ANG_BW_NEIGHBORS_MEAN); - const int angBetweenNeighborsStddevIdx = static_cast(Feature2D::ANG_BW_NEIGHBORS_STDDEV); - const int angBetweenNeighborsModeIdx = static_cast(Feature2D::ANG_BW_NEIGHBORS_MODE); - - //==== Collision detection, method 1 (greedy) +{ + int radius = STNGS_PIXELDISTANCE(s); // former theEnvironment.get_pixel_distance() + int n_threads = 1; + const int percentTouchingIdx = static_cast(Feature2D::PERCENT_TOUCHING); + const int numNeighborsIdx = static_cast(Feature2D::NUM_NEIGHBORS); + const int centroidXIdx = static_cast(Feature2D::CENTROID_X); + const int centroidYIdx = static_cast(Feature2D::CENTROID_Y); + const int closestNeighbor1DistIdx = static_cast(Feature2D::CLOSEST_NEIGHBOR1_DIST); + const int closestNeighbor1AngIdx = static_cast(Feature2D::CLOSEST_NEIGHBOR1_ANG); + const int closestNeighbor2DistIdx = static_cast(Feature2D::CLOSEST_NEIGHBOR2_DIST); + const int closestNeighbor2AngIdx = static_cast(Feature2D::CLOSEST_NEIGHBOR2_ANG); + const int angBetweenNeighborsMeanIdx = static_cast(Feature2D::ANG_BW_NEIGHBORS_MEAN); + const int angBetweenNeighborsStddevIdx = static_cast(Feature2D::ANG_BW_NEIGHBORS_STDDEV); + const int angBetweenNeighborsModeIdx = static_cast(Feature2D::ANG_BW_NEIGHBORS_MODE); + + //==== Collision detection, method 1 (greedy) auto n_ul = uniqueLabels.size(); - std::vector LabsVec; - LabsVec.reserve (uniqueLabels.size()); - LabsVec.insert (LabsVec.end(), uniqueLabels.begin(), uniqueLabels.end()); - std::sort(LabsVec.begin(), LabsVec.end()); + std::vector LabsVec; + LabsVec.reserve (uniqueLabels.size()); + LabsVec.insert (LabsVec.end(), uniqueLabels.begin(), uniqueLabels.end()); + std::sort(LabsVec.begin(), LabsVec.end()); std::vector > CM2; CM2.reserve (n_ul * n_ul / 4); // estimate: 25% of the segment population - for (size_t i1 = 0; i1 < n_ul; i1++) - { - auto l1 = LabsVec[i1]; - LR& r1 = roiData.at (l1); + for (size_t i1 = 0; i1 < n_ul; i1++) + { + auto l1 = LabsVec[i1]; + LR& r1 = roiData.at (l1); for (size_t i2 = 0; i2 < n_ul; i2++) { auto l2 = LabsVec[i2]; if (i1 == i2) continue; // Trivial - diagonal element - if (n_threads==1 && i1 > i2) - continue; // No need to check the upper triangle for single-threaded runs. Multi-threaded runs require the upper triangle for thread-safe results. - - LR& r2 = roiData[l2]; - bool noOverlap = aabbNoOverlap(r1, r2, radius); - if (! noOverlap) - { - CM2.push_back( {l1, l2}); + if (n_threads==1 && i1 > i2) + continue; // No need to check the upper triangle for single-threaded runs. Multi-threaded runs require the upper triangle for thread-safe results. + + LR& r2 = roiData[l2]; + bool noOverlap = aabbNoOverlap(r1, r2, radius); + if (! noOverlap) + { + CM2.push_back( {l1, l2}); //DEBUG // n_aabb_collis++; @@ -292,9 +292,9 @@ void NeighborsFeature::manual_reduce ( r2.aux_neighboring_labels.push_back(l1); } for (auto l : uniqueLabels) - { + { LR& r1 = roiData[l]; - + std::vector K1; r1.merge_multicontour(K1); @@ -304,8 +304,8 @@ void NeighborsFeature::manual_reduce ( if (it != touchMask.end()) for (char c : it->second) nt += (c != 0); r1.fvals[percentTouchingIdx][0] = K1.empty() ? 0.0 : 100.0 * double(nt) / double(K1.size()); - } - } + } + } else { // multi-threading @@ -443,7 +443,7 @@ void NeighborsFeature::manual_reduce ( for (auto l : uniqueLabels) { LR& r = roiData[l]; - int n_neigs = static_cast(r.fvals[numNeighborsIdx][0]); + int n_neigs = static_cast(r.fvals[numNeighborsIdx][0]); // Any neighbors of this ROI ? if (n_neigs == 0) @@ -453,87 +453,87 @@ void NeighborsFeature::manual_reduce ( std::vector dists; dists.reserve(r.aux_neighboring_labels.size()); - for (auto l_neig : r.aux_neighboring_labels) - { - LR& r_neig = roiData[l_neig]; + for (auto l_neig : r.aux_neighboring_labels) + { + LR& r_neig = roiData[l_neig]; double cenx_n = cen[l_neig].first, ceny_n = cen[l_neig].second, - dx = cenx - cenx_n, - dy = ceny - ceny_n, - dist = std::sqrt(dx * dx + dy * dy); - dists.push_back(dist); - } - - // Find idx of minimum - auto ite1st = std::min_element(dists.begin(), dists.end()); + dx = cenx - cenx_n, + dy = ceny - ceny_n, + dist = std::sqrt(dx * dx + dy * dy); + dists.push_back(dist); + } + + // Find idx of minimum + auto ite1st = std::min_element(dists.begin(), dists.end()); auto closest_1_idx = std::distance(dists.begin(), ite1st); auto closest1label = r.aux_neighboring_labels[closest_1_idx]; // Save distance to neighbor #1 - r.fvals[closestNeighbor1DistIdx][0] = dists[closest_1_idx]; - - // Save angle with neighbor #1 + r.fvals[closestNeighbor1DistIdx][0] = dists[closest_1_idx]; + + // Save angle with neighbor #1 r.fvals[closestNeighbor1AngIdx][0] = direction_angle_deg(cenx, ceny, cen[closest1label].first, cen[closest1label].second); - - // Find idx of 2nd minimum - if (n_neigs > 1) - { - std::vector dists_copy = dists; - dists_copy[closest_1_idx] = std::numeric_limits::infinity(); - auto ite2nd = std::min_element(dists_copy.begin(), dists_copy.end()); - auto closest_2_idx = std::distance(dists_copy.begin(), ite2nd); - auto closest2label = r.aux_neighboring_labels[closest_2_idx]; - - // Save distance to neighbor #2 - r.fvals[closestNeighbor2DistIdx][0] = dists[closest_2_idx]; - - // Save angle with neighbor #2 + + // Find idx of 2nd minimum + if (n_neigs > 1) + { + std::vector dists_copy = dists; + dists_copy[closest_1_idx] = std::numeric_limits::infinity(); + auto ite2nd = std::min_element(dists_copy.begin(), dists_copy.end()); + auto closest_2_idx = std::distance(dists_copy.begin(), ite2nd); + auto closest2label = r.aux_neighboring_labels[closest_2_idx]; + + // Save distance to neighbor #2 + r.fvals[closestNeighbor2DistIdx][0] = dists[closest_2_idx]; + + // Save angle with neighbor #2 r.fvals[closestNeighbor2AngIdx][0] = direction_angle_deg(cenx, ceny, cen[closest2label].first, cen[closest2label].second); - } - } - - // Angle between neighbors - for (auto l : uniqueLabels) - { - LR& r = roiData[l]; - int n_neigs = static_cast(r.fvals[numNeighborsIdx][0]); + } + } + + // Angle between neighbors + for (auto l : uniqueLabels) + { + LR& r = roiData[l]; + int n_neigs = static_cast(r.fvals[numNeighborsIdx][0]); // Any neighbors of this ROI ? if (n_neigs == 0) continue; double cenx = cen[l].first, ceny = cen[l].second; - - Moments2 mom2; - std::array angleCounts{}; - - // Iterate all the neighbors - for (auto l_neig : r.aux_neighboring_labels) - { - LR& r_neig = roiData[l_neig]; + + Moments2 mom2; + std::array angleCounts{}; + + // Iterate all the neighbors + for (auto l_neig : r.aux_neighboring_labels) + { + LR& r_neig = roiData[l_neig]; double cenx_n = cen[l_neig].first, ceny_n = cen[l_neig].second; - - double ang = direction_angle_deg(cenx, ceny, cenx_n, ceny_n); - mom2.add(ang); - int roundedAngle = static_cast(std::round(ang)); - roundedAngle = std::max(0, std::min(360, roundedAngle)); - ++angleCounts[roundedAngle]; - } - - int angleMode = 0; - int angleModeCount = 0; - for (size_t i = 0; i < angleCounts.size(); ++i) - { - if (angleCounts[i] > angleModeCount) - { - angleModeCount = angleCounts[i]; - angleMode = static_cast(i); - } - } - r.fvals[angBetweenNeighborsMeanIdx][0] = mom2.mean(); - r.fvals[angBetweenNeighborsStddevIdx][0] = mom2.std(); - r.fvals[angBetweenNeighborsModeIdx][0] = angleMode; - } -} + + double ang = direction_angle_deg(cenx, ceny, cenx_n, ceny_n); + mom2.add(ang); + int roundedAngle = static_cast(std::round(ang)); + roundedAngle = std::max(0, std::min(360, roundedAngle)); + ++angleCounts[roundedAngle]; + } + + int angleMode = 0; + int angleModeCount = 0; + for (size_t i = 0; i < angleCounts.size(); ++i) + { + if (angleCounts[i] > angleModeCount) + { + angleModeCount = angleCounts[i]; + angleMode = static_cast(i); + } + } + r.fvals[angBetweenNeighborsMeanIdx][0] = mom2.mean(); + r.fvals[angBetweenNeighborsStddevIdx][0] = mom2.std(); + r.fvals[angBetweenNeighborsModeIdx][0] = angleMode; + } +} // Spatial hashing inline bool NeighborsFeature::aabbNoOverlap( diff --git a/src/nyx/features/neighbors.h b/src/nyx/features/neighbors.h index 49a35c2d5..54bc5b077 100644 --- a/src/nyx/features/neighbors.h +++ b/src/nyx/features/neighbors.h @@ -14,7 +14,7 @@ class NeighborsFeature : public FeatureMethod { public: - const constexpr static std::initializer_list featureset = { + static constexpr std::initializer_list featureset = { Nyxus::Feature2D::NUM_NEIGHBORS, Nyxus::Feature2D::PERCENT_TOUCHING, Nyxus::Feature2D::CLOSEST_NEIGHBOR1_DIST, diff --git a/src/nyx/features/ngldm.cpp b/src/nyx/features/ngldm.cpp index 89a0f1125..6ee4f2d0d 100644 --- a/src/nyx/features/ngldm.cpp +++ b/src/nyx/features/ngldm.cpp @@ -356,25 +356,25 @@ void NGLDMfeature::calc_features (const std::vector& Sg, const std::vect void NGLDMfeature::save_value (std::vector>& fvals) { - fvals[(int)Feature2D::NGLDM_LDE][0] = f_LDE; - fvals[(int)Feature2D::NGLDM_HDE][0] = f_HDE; - fvals[(int)Feature2D::NGLDM_LGLCE][0] = f_LGLCE; - fvals[(int)Feature2D::NGLDM_HGLCE][0] = f_HGLCE; - fvals[(int)Feature2D::NGLDM_LDLGLE][0] = f_LDLGLE; - fvals[(int)Feature2D::NGLDM_LDHGLE][0] = f_LDHGLE; - fvals[(int)Feature2D::NGLDM_HDLGLE][0] = f_HDLGLE; - fvals[(int)Feature2D::NGLDM_HDHGLE][0] = f_HDHGLE; - fvals[(int)Feature2D::NGLDM_GLNU][0] = f_GLNU; - fvals[(int)Feature2D::NGLDM_GLNUN][0] = f_GLNUN; - fvals[(int)Feature2D::NGLDM_DCNU][0] = f_DCNU; - fvals[(int)Feature2D::NGLDM_DCNUN][0] = f_DCNUN; - fvals[(int)Feature2D::NGLDM_GLM][0] = f_GLCM; - fvals[(int)Feature2D::NGLDM_GLV][0] = f_GLV; - fvals[(int)Feature2D::NGLDM_DCM][0] = f_DCM; - fvals[(int)Feature2D::NGLDM_DCP][0] = f_DCP; - fvals[(int)Feature2D::NGLDM_DCV][0] = f_DCV; - fvals[(int)Feature2D::NGLDM_DCENT][0] = f_DCENT; - fvals[(int)Feature2D::NGLDM_DCENE][0] = f_DCENE; + fvals[static_cast(Feature2D::NGLDM_LDE)][0] = f_LDE; + fvals[static_cast(Feature2D::NGLDM_HDE)][0] = f_HDE; + fvals[static_cast(Feature2D::NGLDM_LGLCE)][0] = f_LGLCE; + fvals[static_cast(Feature2D::NGLDM_HGLCE)][0] = f_HGLCE; + fvals[static_cast(Feature2D::NGLDM_LDLGLE)][0] = f_LDLGLE; + fvals[static_cast(Feature2D::NGLDM_LDHGLE)][0] = f_LDHGLE; + fvals[static_cast(Feature2D::NGLDM_HDLGLE)][0] = f_HDLGLE; + fvals[static_cast(Feature2D::NGLDM_HDHGLE)][0] = f_HDHGLE; + fvals[static_cast(Feature2D::NGLDM_GLNU)][0] = f_GLNU; + fvals[static_cast(Feature2D::NGLDM_GLNUN)][0] = f_GLNUN; + fvals[static_cast(Feature2D::NGLDM_DCNU)][0] = f_DCNU; + fvals[static_cast(Feature2D::NGLDM_DCNUN)][0] = f_DCNUN; + fvals[static_cast(Feature2D::NGLDM_GLM)][0] = f_GLCM; + fvals[static_cast(Feature2D::NGLDM_GLV)][0] = f_GLV; + fvals[static_cast(Feature2D::NGLDM_DCM)][0] = f_DCM; + fvals[static_cast(Feature2D::NGLDM_DCP)][0] = f_DCP; + fvals[static_cast(Feature2D::NGLDM_DCV)][0] = f_DCV; + fvals[static_cast(Feature2D::NGLDM_DCENT)][0] = f_DCENT; + fvals[static_cast(Feature2D::NGLDM_DCENE)][0] = f_DCENE; } void NGLDMfeature::extract (LR& r, const Fsettings& s) diff --git a/src/nyx/features/ngldm.h b/src/nyx/features/ngldm.h index b5d7c47c4..a8171216b 100644 --- a/src/nyx/features/ngldm.h +++ b/src/nyx/features/ngldm.h @@ -14,7 +14,7 @@ class NGLDMfeature : public FeatureMethod // Codes of features implemented by this class. Used in feature manager's mechanisms, // in the feature group nickname expansion, and in the feature value output - const constexpr static std::initializer_list featureset = + static constexpr std::initializer_list featureset = { Nyxus::Feature2D::NGLDM_LDE, // Low Dependence Emphasis Nyxus::Feature2D::NGLDM_HDE, // High Dependence Emphasis diff --git a/src/nyx/features/ngtdm.cpp b/src/nyx/features/ngtdm.cpp index 63de89715..3ae6fa88a 100644 --- a/src/nyx/features/ngtdm.cpp +++ b/src/nyx/features/ngtdm.cpp @@ -147,8 +147,8 @@ void NGTDMFeature::calculate (LR& r, const Fsettings& s) // Fill the matrix // --dimensions - Ng = (int) I.size(); //---pre 2024---> Ng = STNGS_IBSI(s) ? *std::max_element(std::begin(im.ReadablePixels()), std::end(im.ReadablePixels())) : (int) U.size(); - Ngp = (int) U.size(); + Ng = static_cast(I.size()); //---pre 2024---> Ng = STNGS_IBSI(s) ? *std::max_element(std::begin(im.ReadablePixels()), std::end(im.ReadablePixels())) : (int) U.size(); + Ngp = static_cast(U.size()); // --allocate the matrix P.resize(Ng + 1, 0); @@ -170,7 +170,7 @@ void NGTDMFeature::calculate (LR& r, const Fsettings& s) } // col - int col = (int) z.second; // 1-based + int col = static_cast(z.second); // 1-based // increment N[row]++; // --S @@ -189,7 +189,7 @@ void NGTDMFeature::calculate (LR& r, const Fsettings& s) // --Calculate P for (int i = 0; i < N.size(); i++) - P[i] = (double)N[i] / Nvc; + P[i] = static_cast(N[i] )/ Nvc; // Calculate features _coarseness = calc_Coarseness(); @@ -201,11 +201,11 @@ void NGTDMFeature::calculate (LR& r, const Fsettings& s) void NGTDMFeature::save_value(std::vector>& fvals) { - fvals[(int)Feature2D::NGTDM_COARSENESS][0] = _coarseness; - fvals[(int)Feature2D::NGTDM_CONTRAST][0] = _contrast; - fvals[(int)Feature2D::NGTDM_BUSYNESS][0] = _busyness; - fvals[(int)Feature2D::NGTDM_COMPLEXITY][0] = _complexity; - fvals[(int)Feature2D::NGTDM_STRENGTH][0] = _strength; + fvals[static_cast(Feature2D::NGTDM_COARSENESS)][0] = _coarseness; + fvals[static_cast(Feature2D::NGTDM_CONTRAST)][0] = _contrast; + fvals[static_cast(Feature2D::NGTDM_BUSYNESS)][0] = _busyness; + fvals[static_cast(Feature2D::NGTDM_COMPLEXITY)][0] = _complexity; + fvals[static_cast(Feature2D::NGTDM_STRENGTH)][0] = _strength; } void NGTDMFeature::osized_add_online_pixel(size_t x, size_t y, uint32_t intensity) {} // Not supporting @@ -308,8 +308,8 @@ void NGTDMFeature::osized_calculate (LR& r, const Fsettings& s, ImageLoader&) // Fill the matrix - Ng = (int)U.size(); - Ngp = (int)U.size(); + Ng = static_cast(U.size()); + Ngp = static_cast(U.size()); // --allocate the matrix P.resize(Ng + 1, 0); @@ -328,7 +328,7 @@ void NGTDMFeature::osized_calculate (LR& r, const Fsettings& s, ImageLoader&) int row = (STNGS_IBSI(s)) ? z.first : int(iter - I.begin()); // col - int col = (int)z.second; // 1-based + int col = static_cast(z.second); // 1-based // increment N[row]++; // --S @@ -347,7 +347,7 @@ void NGTDMFeature::osized_calculate (LR& r, const Fsettings& s, ImageLoader&) // --Calculate P for (int i = 0; i < N.size(); i++) - P[i] = (double)N[i] / Nvc; + P[i] = static_cast(N[i] )/ Nvc; // Calculate features _coarseness = calc_Coarseness(); @@ -376,10 +376,10 @@ double NGTDMFeature::calc_Contrast() double sum = 0.0; for (int i = 1; i <= Ng; i++) { - double ival = (double) I [i-1]; + double ival = static_cast(I [i-1]); for (int j = 1; j <= Ng; j++) { - double jval = (double) I [j-1]; + double jval = static_cast(I [j-1]); double tmp = P[i-1] * P[j-1] * (ival - jval) * (ival - jval); sum += tmp; } @@ -412,10 +412,10 @@ double NGTDMFeature::calc_Busyness() double sum2 = 0.0; for (int i = 1; i <= Ng; i++) { - double ival = (double) I [i-1]; + double ival = static_cast(I [i-1]); for (int j = 1; j <= Ng; j++) { - double jval = (double) I [j-1]; + double jval = static_cast(I [j-1]); if (P[i-1] != 0 && P[j-1] != 0) { double tmp = P[i-1] * ival - P[j-1] * jval; @@ -438,10 +438,10 @@ double NGTDMFeature::calc_Complexity() double sum = 0.0; for (int i = 1; i <= Ng; i++) { - double ival = (double) I [i-1]; + double ival = static_cast(I [i-1]); for (int j = 1; j <= Ng; j++) { - double jval = (double) I [j-1]; + double jval = static_cast(I [j-1]); if (P[i-1] != 0 && P[j-1] != 0) { sum += std::abs(ival-jval) * (P[i-1]*S[i-1] + P[j-1]*S[j-1]) / (P[i-1] + P[j-1]) ; @@ -460,10 +460,10 @@ double NGTDMFeature::calc_Strength() double sum1 = 0.0; for (int i = 1; i <= Ng; i++) { - double ival = (double) I[i-1]; + double ival = static_cast(I[i-1]); for (int j = 1; j <= Ng; j++) { - double jval = (double) I[j-1]; + double jval = static_cast(I[j-1]); if (P[i-1] != 0 && P[j-1] != 0) { sum1 += (P[i-1] + P[j-1]) * (ival - jval) * (ival - jval); diff --git a/src/nyx/features/ngtdm.h b/src/nyx/features/ngtdm.h index 930b0a177..bc1fda7f2 100644 --- a/src/nyx/features/ngtdm.h +++ b/src/nyx/features/ngtdm.h @@ -30,7 +30,7 @@ class NGTDMFeature: public FeatureMethod, public TextureFeature // Codes of features implemented by this class. Used in feature manager's mechanisms, // in the feature group nickname expansion, and in the feature value output - const constexpr static std::initializer_list featureset = + static constexpr std::initializer_list featureset = { Nyxus::Feature2D::NGTDM_COARSENESS, Nyxus::Feature2D::NGTDM_CONTRAST, diff --git a/src/nyx/features/pixel.cpp b/src/nyx/features/pixel.cpp index d41a70e84..17c087e75 100644 --- a/src/nyx/features/pixel.cpp +++ b/src/nyx/features/pixel.cpp @@ -201,7 +201,7 @@ double Pixel2::dist_to_segment (const Pixel2 & p1, const Pixel2 & p2) const double h = dx * dx + dy * dy; if (h <= 0) - return (double)INT_MAX; + return static_cast(INT_MAX); double retval = std::fabs(dy*this->x - dx*this->y + p2.x*p1.y - p2.y*p1.x) / sqrt(h); return retval; @@ -226,8 +226,8 @@ double Pixel2::sqdist(const Pixel2& px) const double Pixel2::sqdist(int x, int y) const { - double dx = (double)x - double(this->x), - dy = (double)y - double(this->y); + double dx = static_cast(x )- double(this->x), + dy = static_cast(y )- double(this->y); double retval = dx * dx + dy * dy; return retval; } @@ -251,7 +251,7 @@ double Pixel2::sqdist(int x, int y) const std::vector> table; for (auto vox : cloud) { - std::vector voxRow = { (double)vox.x - ccx, (double)vox.y - ccy, (double)vox.z - ccz }; + std::vector voxRow = { static_cast(vox.x )- ccx, static_cast(vox.y )- ccy, static_cast(vox.z )- ccz }; table.push_back({ voxRow }); } diff --git a/src/nyx/features/pixel.h b/src/nyx/features/pixel.h index 457b9f8da..895f0c4d1 100644 --- a/src/nyx/features/pixel.h +++ b/src/nyx/features/pixel.h @@ -56,9 +56,9 @@ struct Pixel2 : public Point2i Pixel2() : Point2(0, 0), inten(0) {} Pixel2 (StatsInt x_, StatsInt y_, PixIntens i_) : Point2(x_, y_), inten(i_) {} Pixel2 (int x_, int y_, PixIntens i_) : Point2(x_, y_), inten(i_) {} - Pixel2 (float x_, float y_, PixIntens i_) : Point2((StatsInt)x_, (StatsInt)y_), inten(i_) {} - Pixel2 (size_t x_, size_t y_, double i_) : Point2((StatsInt)x_, (StatsInt)y_), inten((PixIntens)i_) {} - Pixel2 (size_t x_, size_t y_, PixIntens i_) : Point2((StatsInt)x_, (StatsInt)y_), inten(i_) {} + Pixel2 (float x_, float y_, PixIntens i_) : Point2(static_cast(x_), static_cast(y_)), inten(i_) {} + Pixel2 (size_t x_, size_t y_, double i_) : Point2(static_cast(x_), static_cast(y_)), inten(static_cast(i_)) {} + Pixel2 (size_t x_, size_t y_, PixIntens i_) : Point2(static_cast(x_), static_cast(y_)), inten(i_) {} bool operator == (const Pixel2& p2) { @@ -91,7 +91,7 @@ struct Pixel2 : public Point2i } operator Point2f () const { - Point2f p((float)this->x, (float)this->y); + Point2f p(static_cast(this->x), static_cast(this->y)); return p; } @@ -198,9 +198,9 @@ struct Pixel3 : public Point3i Pixel3() : Point3(0, 0, 0), inten(0) {} Pixel3(StatsInt x_, StatsInt y_, StatsInt z_, PixIntens i_) : Point3(x_, y_, z_), inten(i_) {} Pixel3(int x_, int y_, int z_, PixIntens i_) : Point3(x_, y_,z_), inten(i_) {} - Pixel3(float x_, float y_, float z_, PixIntens i_) : Point3((StatsInt)x_, (StatsInt)y_, (StatsInt)z_), inten(i_) {} - Pixel3(size_t x_, size_t y_, size_t z_, double i_) : Point3((StatsInt)x_, (StatsInt)y_, (StatsInt)z_), inten((PixIntens)i_) {} - Pixel3(size_t x_, size_t y_, size_t z_, PixIntens i_) : Point3((StatsInt)x_, (StatsInt)y_, (StatsInt)z_), inten(i_) {} + Pixel3(float x_, float y_, float z_, PixIntens i_) : Point3(static_cast(x_), static_cast(y_), static_cast(z_)), inten(i_) {} + Pixel3(size_t x_, size_t y_, size_t z_, double i_) : Point3(static_cast(x_), static_cast(y_), static_cast(z_)), inten(static_cast(i_)) {} + Pixel3(size_t x_, size_t y_, size_t z_, PixIntens i_) : Point3(static_cast(x_), static_cast(y_), static_cast(z_)), inten(i_) {} bool operator == (const Pixel3& p) { diff --git a/src/nyx/features/power_spectrum.cpp b/src/nyx/features/power_spectrum.cpp index 2217d3086..359bf1338 100644 --- a/src/nyx/features/power_spectrum.cpp +++ b/src/nyx/features/power_spectrum.cpp @@ -56,7 +56,7 @@ void PowerSpectrumFeature::parallel_process_1_batch (size_t firstitem, size_t la void PowerSpectrumFeature::save_value(std::vector>& feature_vals) { - feature_vals[(int)FeatureIMQ::POWER_SPECTRUM_SLOPE][0] = slope_; + feature_vals[static_cast(FeatureIMQ::POWER_SPECTRUM_SLOPE)][0] = slope_; } @@ -122,7 +122,7 @@ void PowerSpectrumFeature::invariant(const std::vector& image, std double median = out[n]; for (int i = 0; i < image.size(); ++i) { - out[i] = (double)image[i] / median; + out[i] = static_cast(image[i] )/ median; } } diff --git a/src/nyx/features/power_spectrum.h b/src/nyx/features/power_spectrum.h index fbc3c522e..b001a6d34 100644 --- a/src/nyx/features/power_spectrum.h +++ b/src/nyx/features/power_spectrum.h @@ -14,7 +14,7 @@ class PowerSpectrumFeature: public FeatureMethod { public: - const constexpr static std::initializer_list featureset = { Nyxus::FeatureIMQ::FOCUS_SCORE }; + static constexpr std::initializer_list featureset = { Nyxus::FeatureIMQ::FOCUS_SCORE }; PowerSpectrumFeature(); diff --git a/src/nyx/features/radial_distribution.cpp b/src/nyx/features/radial_distribution.cpp index 85c1c4730..5477842fa 100644 --- a/src/nyx/features/radial_distribution.cpp +++ b/src/nyx/features/radial_distribution.cpp @@ -187,9 +187,9 @@ void RadialDistributionFeature::osized_calculate (LR& r, const Fsettings& s, Ima void RadialDistributionFeature::save_value(std::vector>& fvals) { - fvals[(int)Feature2D::FRAC_AT_D] = values_FracAtD; - fvals[(int)Feature2D::MEAN_FRAC] = values_MeanFrac; - fvals[(int)Feature2D::RADIAL_CV] = values_RadialCV; + fvals[static_cast(Feature2D::FRAC_AT_D)] = values_FracAtD; + fvals[static_cast(Feature2D::MEAN_FRAC)] = values_MeanFrac; + fvals[static_cast(Feature2D::RADIAL_CV)] = values_RadialCV; } void RadialDistributionFeature::extract (LR& r, const Fsettings& s) diff --git a/src/nyx/features/radial_distribution.h b/src/nyx/features/radial_distribution.h index db4d25fcf..5717be178 100644 --- a/src/nyx/features/radial_distribution.h +++ b/src/nyx/features/radial_distribution.h @@ -12,7 +12,7 @@ class RadialDistributionFeature: public FeatureMethod { public: - const constexpr static std::initializer_list featureset = + static constexpr std::initializer_list featureset = { Nyxus::Feature2D::FRAC_AT_D, Nyxus::Feature2D::MEAN_FRAC, diff --git a/src/nyx/features/roi_radius.cpp b/src/nyx/features/roi_radius.cpp index 460818c62..61fe7f25c 100644 --- a/src/nyx/features/roi_radius.cpp +++ b/src/nyx/features/roi_radius.cpp @@ -69,9 +69,9 @@ void RoiRadiusFeature::osized_calculate (LR& r, const Fsettings& s, ImageLoader& void RoiRadiusFeature::save_value (std::vector>& fvals) { - fvals[(int)Feature2D::ROI_RADIUS_MEAN][0] = mean_r; - fvals[(int)Feature2D::ROI_RADIUS_MAX][0] = max_r; - fvals[(int)Feature2D::ROI_RADIUS_MEDIAN][0] = median_r; + fvals[static_cast(Feature2D::ROI_RADIUS_MEAN)][0] = mean_r; + fvals[static_cast(Feature2D::ROI_RADIUS_MAX)][0] = max_r; + fvals[static_cast(Feature2D::ROI_RADIUS_MEDIAN)][0] = median_r; } void RoiRadiusFeature::extract (LR& r, const Fsettings& s) diff --git a/src/nyx/features/roi_radius.h b/src/nyx/features/roi_radius.h index 6df770d13..8566732cc 100644 --- a/src/nyx/features/roi_radius.h +++ b/src/nyx/features/roi_radius.h @@ -14,7 +14,7 @@ class RoiRadiusFeature: public FeatureMethod { public: - const constexpr static std::initializer_list featureset = + static constexpr std::initializer_list featureset = { Nyxus::Feature2D::ROI_RADIUS_MEAN, Nyxus::Feature2D::ROI_RADIUS_MAX, diff --git a/src/nyx/features/rotation.cpp b/src/nyx/features/rotation.cpp index 2b6c63f87..8a98385b5 100644 --- a/src/nyx/features/rotation.cpp +++ b/src/nyx/features/rotation.cpp @@ -29,7 +29,7 @@ void Rotation::rotate_around_center( { double x_rot = (p.x - cx) * c - (p.y - cy) * s + cx; double y_rot = (p.y - cy) * c + (p.x - cx) * s + cy; - Pixel2 p_rot ((float)x_rot, (float)y_rot, p.inten); + Pixel2 p_rot (static_cast(x_rot), static_cast(y_rot), p.inten); P_rot.push_back (p_rot); } } @@ -63,7 +63,7 @@ void Rotation::rotate_around_center_fp ( double y_rot = (p.y - cy) * c + (p.x - cx) * s + cy; // FIX (caliper float-precision): store the rotated vertex in floating point (Point2f) instead of the // integer Pixel2 that truncated it inward - the caliper chord math then integrates on exact coords. - P_rot.push_back (Point2f ((float)x_rot, (float)y_rot)); + P_rot.push_back (Point2f (static_cast(x_rot), static_cast(y_rot))); } } @@ -85,7 +85,7 @@ void Rotation::rotate_cloud ( { double x_rot = (p.x - cx) * c - (p.y - cy) * s + cx; double y_rot = (p.y - cy) * c + (p.x - cx) * s + cy; - Pixel2 p_rot((float)x_rot, (float)y_rot, p.inten); + Pixel2 p_rot(static_cast(x_rot), static_cast(y_rot), p.inten); P_rot.push_back(p_rot); } } @@ -106,7 +106,7 @@ void Rotation::rotate_cloud_NT ( { double x_rot = (p.x - cx) * c - (p.y - cy) * s + cx; double y_rot = (p.y - cy) * c + (p.x - cx) * s + cy; - Pixel2 p_rot((float)x_rot, (float)y_rot, p.inten); + Pixel2 p_rot(static_cast(x_rot), static_cast(y_rot), p.inten); rotated_cloud.add_pixel (p_rot); } } diff --git a/src/nyx/features/saturation.cpp b/src/nyx/features/saturation.cpp index 736119e65..6fd8add8d 100644 --- a/src/nyx/features/saturation.cpp +++ b/src/nyx/features/saturation.cpp @@ -67,8 +67,8 @@ void SaturationFeature::osized_calculate (LR& r, const Fsettings& s, ImageLoader void SaturationFeature::save_value(std::vector>& feature_vals) { - feature_vals[(int)FeatureIMQ::MAX_SATURATION][0] = max_saturation_; - feature_vals[(int)FeatureIMQ::MIN_SATURATION][0] = min_saturation_; + feature_vals[static_cast(FeatureIMQ::MAX_SATURATION)][0] = max_saturation_; + feature_vals[static_cast(FeatureIMQ::MIN_SATURATION)][0] = min_saturation_; } std::tuple SaturationFeature::get_percent_max_pixels(const ImageMatrix& Im) { diff --git a/src/nyx/features/saturation.h b/src/nyx/features/saturation.h index b809698d2..5485b506c 100644 --- a/src/nyx/features/saturation.h +++ b/src/nyx/features/saturation.h @@ -12,7 +12,7 @@ class SaturationFeature : public FeatureMethod public: - const constexpr static std::initializer_list featureset = { Nyxus::FeatureIMQ::MIN_SATURATION, Nyxus::FeatureIMQ::MAX_SATURATION}; + static constexpr std::initializer_list featureset = { Nyxus::FeatureIMQ::MIN_SATURATION, Nyxus::FeatureIMQ::MAX_SATURATION}; SaturationFeature(); diff --git a/src/nyx/features/sharpness.cpp b/src/nyx/features/sharpness.cpp index 228d7d051..48e27416d 100644 --- a/src/nyx/features/sharpness.cpp +++ b/src/nyx/features/sharpness.cpp @@ -48,7 +48,7 @@ bool SharpnessFeature::required(const FeatureSet& fs) } void SharpnessFeature::save_value(std::vector>& feature_vals) { - feature_vals[(int)FeatureIMQ::SHARPNESS][0] = sharpness_; + feature_vals[static_cast(FeatureIMQ::SHARPNESS)][0] = sharpness_; } void SharpnessFeature::remove_padding(std::vector& img, int img_row, int img_col, int row_padding, int col_padding) { @@ -131,7 +131,7 @@ void SharpnessFeature::median_blur(const std::vector& img, std::ve std::sort(window.begin(), window.end()); // Get the median value - int median_index = std::floor((double)window.size() / 2); + int median_index = std::floor(static_cast(window.size() )/ 2); blurred_img_out[i * padded_cols + j] = window[median_index]; } diff --git a/src/nyx/features/sharpness.h b/src/nyx/features/sharpness.h index cfebfc0ba..f6d5de1cb 100644 --- a/src/nyx/features/sharpness.h +++ b/src/nyx/features/sharpness.h @@ -15,7 +15,7 @@ class SharpnessFeature: public FeatureMethod { public: - const constexpr static std::initializer_list featureset = { Nyxus::FeatureIMQ::SHARPNESS }; + static constexpr std::initializer_list featureset = { Nyxus::FeatureIMQ::SHARPNESS }; SharpnessFeature(); diff --git a/src/nyx/features/specfunc.cpp b/src/nyx/features/specfunc.cpp index f1586e539..4773b6673 100644 --- a/src/nyx/features/specfunc.cpp +++ b/src/nyx/features/specfunc.cpp @@ -970,7 +970,7 @@ psi_n_xg0(const int n, const double x, gsl_sf_result* result) gsl_sf_result ln_nf; gsl_sf_result hzeta; int stat_hz = gsl_sf_hzeta_e(n + 1.0, x, &hzeta); - int stat_nf = gsl_sf_lnfact_e((unsigned int)n, &ln_nf); + int stat_nf = gsl_sf_lnfact_e(static_cast(n), &ln_nf); int stat_e = gsl_sf_exp_mult_err_e(ln_nf.val, ln_nf.err, hzeta.val, hzeta.err, result); @@ -994,7 +994,7 @@ int gsl_sf_psi_1_e(const double x, gsl_sf_result* result) else if (x > -5.0) { /* Abramowitz + Stegun 6.4.6 */ - int M = (int)-floor(x); + int M = static_cast(-floor(x)); double fx = x + M; double sum = 0.0; int m; @@ -1074,7 +1074,7 @@ int gsl_sf_psi_n_e(const int n, const double x, gsl_sf_result* result) gsl_sf_result ln_nf; gsl_sf_result hzeta; int stat_hz = gsl_sf_hzeta_e(n + 1.0, x, &hzeta); - int stat_nf = gsl_sf_lnfact_e((unsigned int)n, &ln_nf); + int stat_nf = gsl_sf_lnfact_e(static_cast(n), &ln_nf); int stat_e = gsl_sf_exp_mult_err_e(ln_nf.val, ln_nf.err, hzeta.val, hzeta.err, result); @@ -1378,7 +1378,7 @@ gamma_xgthalf(const double x, gsl_sf_result* result) return GSL_SUCCESS; } else if (x <= (GSL_SF_FACT_NMAX + 1.0) && x == floor(x)) { - int n = (int)floor(x); + int n = static_cast(floor(x)); result->val = fact_table[n - 1].f; result->err = GSL_DBL_EPSILON * result->val; return GSL_SUCCESS; @@ -1507,7 +1507,7 @@ int gsl_sf_lngamma_sgn_e(double x, gsl_sf_result* result_lg, double* sgn) GSL_ERROR("error", GSL_EROUND); } else { - int N = -(int)(x - 0.5); + int N = -static_cast((x - 0.5)); double eps = x + N; return lngamma_sgn_sing(N, eps, result_lg, sgn); } @@ -1580,7 +1580,7 @@ int gsl_sf_lngamma_e(double x, gsl_sf_result* result) GSL_ERROR("error", GSL_EROUND); } else { - int N = -(int)(x - 0.5); + int N = -static_cast((x - 0.5)); double eps = x + N; double sgn; return lngamma_sgn_sing(N, eps, result, &sgn); @@ -1673,7 +1673,7 @@ int gsl_sf_choose_e(unsigned int n, unsigned int m, gsl_sf_result* result) unsigned int k; for (k = n; k >= m + 1; k--) { - double tk = (double)k / (double)(k - m); + double tk = static_cast(k )/ static_cast((k - m)); if (tk > GSL_DBL_MAX / prod) { OVERFLOW_ERROR(result); } @@ -1701,7 +1701,7 @@ int gsl_sf_gamma_e(const double x, gsl_sf_result* result) { if (x < 0.5) { - int rint_x = (int)floor(x + 0.5); + int rint_x = static_cast(floor(x + 0.5)); double f_x = x - rint_x; double sgn_gamma = (GSL_IS_EVEN(rint_x) ? 1.0 : -1.0); double sin_term = sgn_gamma * sin(M_PI * f_x) / M_PI; diff --git a/src/nyx/features/texture_feature.h b/src/nyx/features/texture_feature.h index e2a435e12..1c3dbb5bf 100644 --- a/src/nyx/features/texture_feature.h +++ b/src/nyx/features/texture_feature.h @@ -16,7 +16,7 @@ class TextureFeature static inline int cast_to_range(PixIntens orig_I, PixIntens min_orig_I, PixIntens max_orig_I, int min_target_I, int max_target_I) { - int target_I = (int)(double(orig_I - min_orig_I) / double(max_orig_I - min_orig_I) * double(max_target_I - min_target_I) + min_target_I); + int target_I = static_cast((double(orig_I - min_orig_I) / double(max_orig_I - min_orig_I) * double(max_target_I - min_target_I) + min_target_I)); return target_I; } @@ -108,7 +108,7 @@ class TextureFeature if (x) { double binW = double(max__ - min__) / double(binCount); - PixIntens y = (PixIntens) (double(x - min__) / binW + 1); + PixIntens y = static_cast((double(x - min__) / binW + 1)); if (y > binCount) y = binCount; // the last bin is +1 unit wider return y; @@ -155,7 +155,7 @@ class TextureFeature // scale double scaled_real_i = std::floor(slope * double(i) + intercept); - PixIntens scaled_i = (PixIntens) scaled_real_i; + PixIntens scaled_i = static_cast(scaled_real_i); // clip values outside the range if (scaled_i > cached_n_levels) @@ -174,10 +174,10 @@ class TextureFeature // scale double scaled_real_i = std::floor(slope_ * double(x) + intercept_); - unsigned int scaled_i = (unsigned int)scaled_real_i; + unsigned int scaled_i = static_cast(scaled_real_i); // clip values outside the range - if (scaled_i > (PixIntens) n_levels) + if (scaled_i > static_cast(n_levels)) scaled_i = n_levels; if (scaled_i < 1) scaled_i = 1; diff --git a/src/nyx/features/zernike.cpp b/src/nyx/features/zernike.cpp index 203d813fc..3fc05fdc7 100644 --- a/src/nyx/features/zernike.cpp +++ b/src/nyx/features/zernike.cpp @@ -50,11 +50,11 @@ void ZernikeFeature::osized_add_online_pixel (size_t x, size_t y, uint32_t inten void ZernikeFeature::save_value (std::vector>& fvals) { - fvals[(int)Feature2D::ZERNIKE2D].clear(); + fvals[static_cast(Feature2D::ZERNIKE2D)].clear(); for (int i=0; i(Feature2D::ZERNIKE2D)].push_back(f); } } @@ -96,8 +96,8 @@ void ZernikeFeature::mb_Znl (double* X, double* Y, double* P, int size, double D { for (m = 0; m <= (n - l) / 2; m++) { - LUT[theLUT] = pow((double)-1.0, (double)m) * ((long double)gsl_sf_fact(n - m) / ((long double)gsl_sf_fact(m) * (long double)gsl_sf_fact((n - 2 * m + l) / 2) * - (long double)gsl_sf_fact((n - 2 * m - l) / 2))); + LUT[theLUT] = pow(static_cast(-1.0), static_cast(m)) * (static_cast(gsl_sf_fact(n - m) )/ (static_cast(gsl_sf_fact(m) )* static_cast(gsl_sf_fact((n - 2 * m + l) / 2) )* + static_cast(gsl_sf_fact((n - 2 * m - l) / 2)))); theLUT++; } n_s[theZ] = n; @@ -139,7 +139,7 @@ void ZernikeFeature::mb_Znl (double* X, double* Y, double* P, int size, double D Vnl = complex(0.0, 0.0); for (m = 0; m <= (n - l) / 2; m++) { - Vnl += (polar(1.0, l * atan2yx) * LUT[theLUT] * pow(sqr_x2y2, (double)(n - 2 * m))); + Vnl += (polar(1.0, l * atan2yx) * LUT[theLUT] * pow(sqr_x2y2, static_cast((n - 2 * m)))); theLUT++; } sum[theZ] += (conj(Vnl) * p); @@ -160,7 +160,7 @@ void ZernikeFeature::mb_Znl (double* X, double* Y, double* P, int size, double D /* Algorithms for fast computation of Zernike moments and their numerical stability - Chandan Singh and Ekta Walia, Image and Vision Computing 29 (2011) 251–259 + Chandan Singh and Ekta Walia, Image and Vision Computing 29 (2011) 251�259 Implemented from pseudo-code by Ilya Goldberg 2011-04-27 This code is 10x faster than the previous code, and 50x faster than previous unoptimized code. @@ -186,14 +186,14 @@ void ZernikeFeature::mb_zernike2D (const ImageMatrix& Im, double order, double r //--alternatively-- N = Im.width > Im.height ? Im.width : Im.height; //MM: This change is needed for bounding box implementations to ensure disk is covering the entire area of the Image if (order > 0) - L = (int)order; + L = static_cast(order); else L = 15; assert(L < MAX_L); if (!(rad > 0.0)) rad = N; - D = (int)(rad * 2); + D = static_cast((rad * 2)); static double H1[MAX_L][MAX_L]; static double H2[MAX_L][MAX_L]; @@ -216,7 +216,7 @@ void ZernikeFeature::mb_zernike2D (const ImageMatrix& Im, double order, double r for (i = 0; i < cols; i++) for (j = 0; j < rows; j++) { - if (std::isnan((double)I_pix_plane.yx(j, i))) + if (std::isnan(static_cast(I_pix_plane.yx(j, i)))) continue; //MM intensity = INTEN(I_pix_plane.yx(j,i)); sum += intensity; @@ -236,9 +236,9 @@ void ZernikeFeature::mb_zernike2D (const ImageMatrix& Im, double order, double r { if (n != m) { - H3[n][m] = -(double)(4.0 * (m + 2.0) * (m + 1.0)) / (double)((n + m + 2.0) * (n - m)); - H2[n][m] = ((double)(H3[n][m] * (n + m + 4.0) * (n - m - 2.0)) / (double)(4.0 * (m + 3.0))) + (m + 2.0); - H1[n][m] = ((double)((m + 4.0) * (m + 3.0)) / 2.0) - ((m + 4.0) * H2[n][m]) + ((double)(H3[n][m] * (n + m + 6.0) * (n - m - 4.0)) / 8.0); + H3[n][m] = -static_cast((4.0 * (m + 2.0) * (m + 1.0)) )/ static_cast(((n + m + 2.0) * (n - m))); + H2[n][m] = (static_cast((H3[n][m] * (n + m + 4.0) * (n - m - 2.0)) )/ static_cast((4.0 * (m + 3.0)))) + (m + 2.0); + H1[n][m] = (static_cast(((m + 4.0) * (m + 3.0)) )/ 2.0) - ((m + 4.0) * H2[n][m]) + (static_cast((H3[n][m] * (n + m + 6.0) * (n - m - 4.0)) )/ 8.0); } } } @@ -262,7 +262,7 @@ void ZernikeFeature::mb_zernike2D (const ImageMatrix& Im, double order, double r x = (i + 1 - m10_m00) / rad; for (j = 0; j < rows; j++) { - if (std::isnan((double)I_pix_plane.yx(j, i))) + if (std::isnan(static_cast(I_pix_plane.yx(j, i)))) continue; //MM // In the paper, the center of the unit circle was the center of the image diff --git a/src/nyx/features/zernike.h b/src/nyx/features/zernike.h index 3f7ab0bc8..598620e6d 100644 --- a/src/nyx/features/zernike.h +++ b/src/nyx/features/zernike.h @@ -13,7 +13,7 @@ class ZernikeFeature: public FeatureMethod { public: - const constexpr static std::initializer_list featureset = + static constexpr std::initializer_list featureset = { Nyxus::Feature2D::ZERNIKE2D }; @@ -40,12 +40,12 @@ class ZernikeFeature: public FeatureMethod void mb_Znl(double* X, double* Y, double* P, int size, double D, double m10_m00, double m01_m00, double R, double psum, double* zvalues, long* output_size); /// @brief Algorithms for fast computation of Zernike momentsand their numerical stability - /// Chandan Singhand Ekta Walia, Imageand Vision Computing 29 (2011) 251–259 implemented from + /// Chandan Singhand Ekta Walia, Imageand Vision Computing 29 (2011) 251�259 implemented from /// pseudo-code by Ilya Goldberg void mb_zernike2D (const ImageMatrix& Im, double order, double rad, double* zvalues); /// @brief Algorithms for fast computation of Zernike momentsand their numerical stability - /// Chandan Singhand Ekta Walia, Imageand Vision Computing 29 (2011) 251–259 implemented from + /// Chandan Singhand Ekta Walia, Imageand Vision Computing 29 (2011) 251�259 implemented from /// pseudo-code by Ilya Goldberg void mb_zernike2D_nontriv (WriteImageMatrix_nontriv& I, double order, double rad, double* zvalues); diff --git a/src/nyx/features/zernike_nontriv.cpp b/src/nyx/features/zernike_nontriv.cpp index e192cfa7c..595e76219 100644 --- a/src/nyx/features/zernike_nontriv.cpp +++ b/src/nyx/features/zernike_nontriv.cpp @@ -54,7 +54,7 @@ void ZernikeFeature::osized_calculate (LR& r, const Fsettings& s, ImageLoader& i /* Algorithms for fast computation of Zernike moments and their numerical stability - Chandan Singh and Ekta Walia, Image and Vision Computing 29 (2011) 251–259 + Chandan Singh and Ekta Walia, Image and Vision Computing 29 (2011) 251�259 Implemented from pseudo-code by Ilya Goldberg 2011-04-27 This code is 10x faster than the previous code, and 50x faster than previous unoptimized code. @@ -79,14 +79,14 @@ void ZernikeFeature::mb_zernike2D_nontriv (WriteImageMatrix_nontriv& I, double o //--alternatively-- N = Im.width > Im.height ? Im.width : Im.height; //MM: This change is needed for bounding box implementations to ensure disk is covering the entire area of the Image if (order > 0) - L = (int)order; + L = static_cast(order); else L = 15; assert(L < MAX_L); if (!(rad > 0.0)) rad = N; - D = (int)(rad * 2); + D = static_cast((rad * 2)); static double H1[MAX_L][MAX_L]; static double H2[MAX_L][MAX_L]; @@ -129,9 +129,9 @@ void ZernikeFeature::mb_zernike2D_nontriv (WriteImageMatrix_nontriv& I, double o { if (n != m) { - H3[n][m] = -(double)(4.0 * (m + 2.0) * (m + 1.0)) / (double)((n + m + 2.0) * (n - m)); - H2[n][m] = ((double)(H3[n][m] * (n + m + 4.0) * (n - m - 2.0)) / (double)(4.0 * (m + 3.0))) + (m + 2.0); - H1[n][m] = ((double)((m + 4.0) * (m + 3.0)) / 2.0) - ((m + 4.0) * H2[n][m]) + ((double)(H3[n][m] * (n + m + 6.0) * (n - m - 4.0)) / 8.0); + H3[n][m] = -static_cast((4.0 * (m + 2.0) * (m + 1.0)) )/ static_cast(((n + m + 2.0) * (n - m))); + H2[n][m] = (static_cast((H3[n][m] * (n + m + 4.0) * (n - m - 2.0)) )/ static_cast((4.0 * (m + 3.0)))) + (m + 2.0); + H1[n][m] = (static_cast(((m + 4.0) * (m + 3.0)) )/ 2.0) - ((m + 4.0) * H2[n][m]) + (static_cast((H3[n][m] * (n + m + 6.0) * (n - m - 4.0)) )/ 8.0); } } } diff --git a/src/nyx/featureset.cpp b/src/nyx/featureset.cpp index d70dbb290..4f7182719 100644 --- a/src/nyx/featureset.cpp +++ b/src/nyx/featureset.cpp @@ -988,7 +988,7 @@ bool FeatureSet::find_2D_FeatureByString ( if (it_f == Nyxus::UserFacingFeatureNames.end()) return false; - f = enable * (int) it_f->second; + f = enable * static_cast(it_f->second); return true; } @@ -1015,7 +1015,7 @@ bool FeatureSet::find_2D_GroupByString ( if (itr == Nyxus::UserFacing2dFeaturegroupNames.end()) return false; - grpCode = enable * (int) itr->second; + grpCode = enable * static_cast(itr->second); return true; } @@ -1043,7 +1043,7 @@ bool FeatureSet::find_3D_FeatureByString (const std::string & name, int & f) if (it_f == Nyxus::UserFacing_3D_featureNames.end()) return false; - f = enable * (int)it_f->second; + f = enable * static_cast(it_f->second); return true; } @@ -1068,7 +1068,7 @@ bool FeatureSet::find_3D_GroupByString (const std::string & name, int & grpCode) if (itr == Nyxus::UserFacing3dFeaturegroupNames.end()) return false; - grpCode = enable * (int)itr->second; + grpCode = enable * static_cast(itr->second); return true; } @@ -1087,7 +1087,7 @@ bool FeatureSet::find_IMQ_FeatureByString (const std::string & name, int & f) if (it_f == Nyxus::UserFacingIMQFeatureNames.end()) return false; - f = (int) it_f->second; + f = static_cast(it_f->second); return true; } @@ -1105,7 +1105,7 @@ bool FeatureSet::find_IMQ_GroupByString (const std::string & name, int & grpCode if (itr == Nyxus::UserFacingIMQFeaturegroupNames.end()) return false; - grpCode = (int) itr->second; + grpCode = static_cast(itr->second); return true; } @@ -1157,7 +1157,7 @@ std::string FeatureSet::findGroupNameByCode (Fgroup2D code) return result->first; // Not found - return "UNNAMED_FEATURE_GROUP_" + std::to_string((int)code); + return "UNNAMED_FEATURE_GROUP_" + std::to_string(static_cast(code)); } std::string FeatureSet::findGroupNameByCode (Fgroup3D code) @@ -1174,7 +1174,7 @@ std::string FeatureSet::findGroupNameByCode (Fgroup3D code) return result->first; // Not found - return "UNNAMED_FEATURE_GROUP_" + std::to_string((int)code); + return "UNNAMED_FEATURE_GROUP_" + std::to_string(static_cast(code)); } std::string FeatureSet::findGroupNameByCode (FgroupIMQ code) @@ -1191,7 +1191,7 @@ std::string FeatureSet::findGroupNameByCode (FgroupIMQ code) return result->first; // Not found - return "UNNAMED_FEATURE_GROUP_" + std::to_string((int)code); + return "UNNAMED_FEATURE_GROUP_" + std::to_string(static_cast(code)); } // Relying on RVO rather than std::move @@ -1200,7 +1200,7 @@ std::vector> FeatureSet::getEnabledFeatures() const std::vector> F; // 2D features - for (int i = 0; i < (int) Nyxus::Feature2D::_COUNT_; i++) + for (int i = 0; i < static_cast(Nyxus::Feature2D::_COUNT_); i++) { if (m_enabledFeatures[i]) { @@ -1208,7 +1208,7 @@ std::vector> FeatureSet::getEnabledFeatures() const std::string fname = "2D-feature" + std::to_string(i); // name feature will indicate a number of a missing user-facing feature name, if any for (const auto& f : Nyxus::UserFacingFeatureNames) { - if (f.second == (Nyxus::Feature2D) i) + if (f.second == static_cast(i)) { fname = f.first; break; @@ -1222,7 +1222,7 @@ std::vector> FeatureSet::getEnabledFeatures() const } // 3D features - for (int i = (int) Nyxus::Feature2D::_COUNT_; i < (int) Nyxus::Feature3D::_COUNT_; i++) + for (int i = static_cast(Nyxus::Feature2D::_COUNT_); i < static_cast(Nyxus::Feature3D::_COUNT_); i++) { if (m_enabledFeatures[i]) { @@ -1230,7 +1230,7 @@ std::vector> FeatureSet::getEnabledFeatures() const std::string fname = "3D-feature" + std::to_string(i); // name feature will indicate a number of a missing user-facing feature name, if any for (const auto& f : Nyxus::UserFacing_3D_featureNames) { - if (f.second == (Nyxus::Feature3D) i) + if (f.second == static_cast(i)) { fname = f.first; break; @@ -1244,7 +1244,7 @@ std::vector> FeatureSet::getEnabledFeatures() const } // Image Quality features - for (int i = (int) Nyxus::Feature3D::_COUNT_; i < (int) Nyxus::FeatureIMQ::_COUNT_; i++) + for (int i = static_cast(Nyxus::Feature3D::_COUNT_); i < static_cast(Nyxus::FeatureIMQ::_COUNT_); i++) { if (m_enabledFeatures[i]) { @@ -1252,7 +1252,7 @@ std::vector> FeatureSet::getEnabledFeatures() const std::string fname = "IMQ-feature" + std::to_string(i); // name feature will indicate a number of a missing user-facing feature name, if any for (const auto& f : Nyxus::UserFacingIMQFeatureNames) { - if (f.second == (Nyxus::FeatureIMQ) i) + if (f.second == static_cast(i)) { fname = f.first; break; diff --git a/src/nyx/featureset.h b/src/nyx/featureset.h index 7e6dc50d9..4a74f20fb 100644 --- a/src/nyx/featureset.h +++ b/src/nyx/featureset.h @@ -643,7 +643,7 @@ namespace Nyxus enum class Feature3D { // Intensity - COV = (int) Feature2D::_COUNT_, + COV = static_cast(Feature2D::_COUNT_), COVERED_IMAGE_INTENSITY_RANGE, ENERGY, ENTROPY, @@ -919,7 +919,7 @@ namespace Nyxus enum class FeatureIMQ { // Image Quality features - FOCUS_SCORE = (int) Feature3D::_COUNT_, + FOCUS_SCORE = static_cast(Feature3D::_COUNT_), LOCAL_FOCUS_SCORE, POWER_SPECTRUM_SLOPE, MAX_SATURATION, @@ -956,7 +956,7 @@ namespace Nyxus enum class Fgroup3D { - FG3_ALL = (int) Fgroup2D::_COUNT_, + FG3_ALL = static_cast(Fgroup2D::_COUNT_), FG3_INTENSITY, FG3_MORPHOLOGY, FG3_TEXTURE, // 3D_GLCM + 3D_GLRLM + 3D_GLSZM + etc @@ -976,7 +976,7 @@ namespace Nyxus enum class FgroupIMQ { - ALL_IMQ= (int) Fgroup3D::_COUNT_, + ALL_IMQ= static_cast(Fgroup3D::_COUNT_), __COUNT_ }; @@ -1005,21 +1005,21 @@ class FeatureSet void disableFeatures(const std::initializer_list& desiredFeatures) { for (auto f : desiredFeatures) - m_enabledFeatures[(int)f] = false; + m_enabledFeatures[static_cast(f)] = false; } void enableFeatures(const std::initializer_list& F, bool enable=true) { for (auto f : F) - m_enabledFeatures[(int)f] = enable; + m_enabledFeatures[static_cast(f)] = enable; } void enableFeatures(const std::initializer_list& F, bool enable = true) { for (auto f : F) - m_enabledFeatures[(int)f] = enable; + m_enabledFeatures[static_cast(f)] = enable; } void enableFeatures(const std::initializer_list& desiredFeatures) { for (auto f : desiredFeatures) - m_enabledFeatures[(int)f] = true; + m_enabledFeatures[static_cast(f)] = true; } void enableFeature (int fcode) { @@ -1032,88 +1032,88 @@ class FeatureSet } void enablePixelIntenStats() { enableAll(false); - m_enabledFeatures[(int)Nyxus::Feature2D::MEAN] = - m_enabledFeatures[(int)Nyxus::Feature2D::MEDIAN] = - m_enabledFeatures[(int)Nyxus::Feature2D::MIN] = - m_enabledFeatures[(int)Nyxus::Feature2D::MAX] = - m_enabledFeatures[(int)Nyxus::Feature2D::RANGE] = - m_enabledFeatures[(int)Nyxus::Feature2D::COVERED_IMAGE_INTENSITY_RANGE] = - m_enabledFeatures[(int)Nyxus::Feature2D::STANDARD_DEVIATION] = - m_enabledFeatures[(int)Nyxus::Feature2D::SKEWNESS] = - m_enabledFeatures[(int)Nyxus::Feature2D::KURTOSIS] = - m_enabledFeatures[(int)Nyxus::Feature2D::EXCESS_KURTOSIS] = - m_enabledFeatures[(int)Nyxus::Feature2D::MEAN_ABSOLUTE_DEVIATION] = - m_enabledFeatures[(int)Nyxus::Feature2D::MEDIAN_ABSOLUTE_DEVIATION] = - m_enabledFeatures[(int)Nyxus::Feature2D::ENERGY] = - m_enabledFeatures[(int)Nyxus::Feature2D::ROOT_MEAN_SQUARED] = - m_enabledFeatures[(int)Nyxus::Feature2D::ENTROPY] = - m_enabledFeatures[(int)Nyxus::Feature2D::MODE] = - m_enabledFeatures[(int)Nyxus::Feature2D::UNIFORMITY] = - m_enabledFeatures[(int)Nyxus::Feature2D::P10] = - m_enabledFeatures[(int)Nyxus::Feature2D::P25] = - m_enabledFeatures[(int)Nyxus::Feature2D::P75] = - m_enabledFeatures[(int)Nyxus::Feature2D::P90] = - m_enabledFeatures[(int)Nyxus::Feature2D::QCOD] = - m_enabledFeatures[(int)Nyxus::Feature2D::INTERQUARTILE_RANGE] = - m_enabledFeatures[(int)Nyxus::Feature2D::ROBUST_MEAN] = - m_enabledFeatures[(int)Nyxus::Feature2D::ROBUST_MEAN_ABSOLUTE_DEVIATION] = - m_enabledFeatures[(int)Nyxus::Feature2D::COV] = - m_enabledFeatures[(int)Nyxus::Feature2D::WEIGHTED_CENTROID_Y] = - m_enabledFeatures[(int)Nyxus::Feature2D::WEIGHTED_CENTROID_X] = - m_enabledFeatures[(int)Nyxus::Feature2D::MASS_DISPLACEMENT] = - m_enabledFeatures[(int)Nyxus::Feature2D::STANDARD_DEVIATION_BIASED] = - m_enabledFeatures[(int)Nyxus::Feature2D::VARIANCE] = - m_enabledFeatures[(int)Nyxus::Feature2D::VARIANCE_BIASED] = true; + m_enabledFeatures[static_cast(Nyxus::Feature2D::MEAN)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::MEDIAN)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::MIN)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::MAX)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::RANGE)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::COVERED_IMAGE_INTENSITY_RANGE)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::STANDARD_DEVIATION)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::SKEWNESS)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::KURTOSIS)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::EXCESS_KURTOSIS)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::MEAN_ABSOLUTE_DEVIATION)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::MEDIAN_ABSOLUTE_DEVIATION)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::ENERGY)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::ROOT_MEAN_SQUARED)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::ENTROPY)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::MODE)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::UNIFORMITY)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::P10)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::P25)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::P75)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::P90)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::QCOD)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::INTERQUARTILE_RANGE)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::ROBUST_MEAN)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::ROBUST_MEAN_ABSOLUTE_DEVIATION)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::COV)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::WEIGHTED_CENTROID_Y)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::WEIGHTED_CENTROID_X)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::MASS_DISPLACEMENT)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::STANDARD_DEVIATION_BIASED)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::VARIANCE)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::VARIANCE_BIASED)] = true; } void enableBoundingBox() { enableAll(false); - m_enabledFeatures[(int)Nyxus::Feature2D::BBOX_YMIN] = - m_enabledFeatures[(int)Nyxus::Feature2D::BBOX_XMIN] = - m_enabledFeatures[(int)Nyxus::Feature2D::BBOX_HEIGHT] = - m_enabledFeatures[(int)Nyxus::Feature2D::BBOX_WIDTH] = true; + m_enabledFeatures[static_cast(Nyxus::Feature2D::BBOX_YMIN)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::BBOX_XMIN)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::BBOX_HEIGHT)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::BBOX_WIDTH)] = true; } void enableFeret() { enableAll(false); - m_enabledFeatures[(int)Nyxus::Feature2D::MIN_FERET_ANGLE] = - m_enabledFeatures[(int)Nyxus::Feature2D::MAX_FERET_ANGLE] = - m_enabledFeatures[(int)Nyxus::Feature2D::STAT_FERET_DIAM_MIN] = - m_enabledFeatures[(int)Nyxus::Feature2D::STAT_FERET_DIAM_MAX] = - m_enabledFeatures[(int)Nyxus::Feature2D::STAT_FERET_DIAM_MEAN] = - m_enabledFeatures[(int)Nyxus::Feature2D::STAT_FERET_DIAM_MEDIAN] = - m_enabledFeatures[(int)Nyxus::Feature2D::STAT_FERET_DIAM_STDDEV] = - m_enabledFeatures[(int)Nyxus::Feature2D::STAT_FERET_DIAM_MODE] = true; + m_enabledFeatures[static_cast(Nyxus::Feature2D::MIN_FERET_ANGLE)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::MAX_FERET_ANGLE)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::STAT_FERET_DIAM_MIN)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::STAT_FERET_DIAM_MAX)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::STAT_FERET_DIAM_MEAN)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::STAT_FERET_DIAM_MEDIAN)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::STAT_FERET_DIAM_STDDEV)] = + m_enabledFeatures[static_cast(Nyxus::Feature2D::STAT_FERET_DIAM_MODE)] = true; } bool isEnabled (Nyxus::Feature2D fc) const { - return fc < Nyxus::Feature2D::_COUNT_ ? m_enabledFeatures[(int)fc] : false; + return fc < Nyxus::Feature2D::_COUNT_ ? m_enabledFeatures[static_cast(fc)] : false; } bool isEnabled (Nyxus::Feature3D fc) const { - return fc < Nyxus::Feature3D::_COUNT_ ? m_enabledFeatures[(int)fc] : false; + return fc < Nyxus::Feature3D::_COUNT_ ? m_enabledFeatures[static_cast(fc)] : false; } bool isEnabled (Nyxus::FeatureIMQ fc) const { - return fc < Nyxus::FeatureIMQ::_COUNT_ ? m_enabledFeatures[(int)fc] : false; + return fc < Nyxus::FeatureIMQ::_COUNT_ ? m_enabledFeatures[static_cast(fc)] : false; } bool anyEnabled (const std::initializer_list& F) const { for (auto f : F) - if (m_enabledFeatures[(int)f]) + if (m_enabledFeatures[static_cast(f)]) return true; return false; } bool anyEnabled (const std::initializer_list& F) const { for (auto f : F) - if (m_enabledFeatures[(int)f]) + if (m_enabledFeatures[static_cast(f)]) return true; return false; } bool anyEnabled (const std::initializer_list& F) const { for (auto f : F) - if (m_enabledFeatures[(int)f]) + if (m_enabledFeatures[static_cast(f)]) return true; return false; } @@ -1125,17 +1125,17 @@ class FeatureSet if (dim == 2) { // regular features - for (int i = (int) Nyxus::Feature2D::_FIRST_; i < (int) Nyxus::Feature2D::_COUNT_ ; i++) + for (int i = static_cast(Nyxus::Feature2D::_FIRST_); i < static_cast(Nyxus::Feature2D::_COUNT_ ); i++) if (m_enabledFeatures[i]) cnt++; // quality features - for (int i = (int) Nyxus::FeatureIMQ::_FIRST_; i < (int) Nyxus::FeatureIMQ::_COUNT_; i++) + for (int i = static_cast(Nyxus::FeatureIMQ::_FIRST_); i < static_cast(Nyxus::FeatureIMQ::_COUNT_); i++) if (m_enabledFeatures[i]) cnt++; } else // 3D { - for (int i = (int)Nyxus::Feature3D::_FIRST_; i < (int) Nyxus::Feature3D::_COUNT_; i++) + for (int i = static_cast(Nyxus::Feature3D::_FIRST_); i < static_cast(Nyxus::Feature3D::_COUNT_); i++) if (m_enabledFeatures[i]) cnt++; } @@ -1162,7 +1162,7 @@ class FeatureSet std::vector> getEnabledFeatures() const; private: - bool m_enabledFeatures [(int) Nyxus::FeatureIMQ::_COUNT_]; + bool m_enabledFeatures [static_cast(Nyxus::FeatureIMQ::_COUNT_)]; }; namespace Nyxus diff --git a/src/nyx/gpu/gabor.cu b/src/nyx/gpu/gabor.cu index 48ea2163f..b23ec54e7 100644 --- a/src/nyx/gpu/gabor.cu +++ b/src/nyx/gpu/gabor.cu @@ -144,13 +144,13 @@ namespace CuGabor { int n[2] = { row_size, col_size }; - auto ok = cudaMalloc((void**)&d_image, sizeof(CuComplex) * size * batch_size); + auto ok = cudaMalloc(reinterpret_cast(&d_image), sizeof(CuComplex) * size * batch_size); CHECKERR(ok); - ok = cudaMalloc((void**)&d_result, sizeof(CuComplex) * size * batch_size); + ok = cudaMalloc(reinterpret_cast(&d_result), sizeof(CuComplex) * size * batch_size); CHECKERR(ok); - ok = cudaMalloc((void**)&d_kernel, sizeof(CuComplex) * size * batch_size); + ok = cudaMalloc(reinterpret_cast(&d_kernel), sizeof(CuComplex) * size * batch_size); CHECKERR(ok); // copy data to GPU @@ -501,7 +501,7 @@ namespace CuGabor { { auto szb = sizeof(dev_filterbank[0]) * filterbank_len_all_batches; - auto ok = cudaMalloc((void**)dev_filterbank, szb); + auto ok = cudaMalloc(reinterpret_cast(dev_filterbank), szb); CHECKERR(ok); ok = cudaMemcpy(*dev_filterbank, ho_filterbank, szb, cudaMemcpyHostToDevice); diff --git a/src/nyx/gpu/gpu.h b/src/nyx/gpu/gpu.h index 93eef266d..47660b434 100644 --- a/src/nyx/gpu/gpu.h +++ b/src/nyx/gpu/gpu.h @@ -9,7 +9,7 @@ static const int blockSize = 256; -#define whole_chunks2(n,t) ((unsigned int)n+(t)-1)/(t) +#define whole_chunks2(n,t) (static_cast(n)+(t)-1)/(t) #ifndef WITH_PYTHON_H diff --git a/src/nyx/gpu/helper_cuda.h b/src/nyx/gpu/helper_cuda.h index 645fc2479..1c9e34218 100644 --- a/src/nyx/gpu/helper_cuda.h +++ b/src/nyx/gpu/helper_cuda.h @@ -838,7 +838,7 @@ inline int gpuGetMaxGflopsDeviceId() { exit(EXIT_FAILURE); } } - uint64_t compute_perf = (uint64_t)multiProcessorCount * sm_per_multiproc * clockRate; + uint64_t compute_perf = static_cast(multiProcessorCount )* sm_per_multiproc * clockRate; if (compute_perf > max_compute_perf) { max_compute_perf = compute_perf; diff --git a/src/nyx/gpu/reducers.cu b/src/nyx/gpu/reducers.cu index bf0f689fe..a5fb40838 100644 --- a/src/nyx/gpu/reducers.cu +++ b/src/nyx/gpu/reducers.cu @@ -190,7 +190,7 @@ namespace NyxusGpu double* d_idata = g_idata, * d_odata = nullptr; - cudaMalloc((void**)&d_odata, numBlocks * sizeof(d_odata[0])); + cudaMalloc(reinterpret_cast(&d_odata), numBlocks * sizeof(d_odata[0])); //std::vector odata(numBlocks, 0.0); //double* h_odata = odata.data(); diff --git a/src/nyx/gpucache.cpp b/src/nyx/gpucache.cpp index eabfa3bee..4699e78d9 100644 --- a/src/nyx/gpucache.cpp +++ b/src/nyx/gpucache.cpp @@ -102,11 +102,11 @@ bool GpuCache::alloc (size_t total_len__, size_t num_rois__) // allocate on device size_t szb = total_len * sizeof(devbuffer[0]); - if (! GpusideCache::allocate_on_device ((void**)&devbuffer, szb)) + if (! GpusideCache::allocate_on_device (reinterpret_cast(&devbuffer), szb)) return false; szb = num_rois * sizeof(dev_offsets[0]); - if (! GpusideCache::allocate_on_device ((void**)&dev_offsets, szb)) + if (! GpusideCache::allocate_on_device (reinterpret_cast(&dev_offsets), szb)) return false; // allocate on host @@ -114,10 +114,10 @@ bool GpuCache::alloc (size_t total_len__, size_t num_rois__) hobuffer = (Pixel2*) std::malloc(total_len * sizeof(hobuffer[0])); if (!hobuffer) return false; - ho_lengths = (size_t*) std::malloc(num_rois * sizeof(ho_lengths[0])); + ho_lengths = static_cast(std::malloc(num_rois * sizeof(ho_lengths[0]))); if (!ho_lengths) return false; - ho_offsets = (size_t*) std::malloc(num_rois * sizeof(ho_offsets[0])); + ho_offsets = static_cast(std::malloc(num_rois * sizeof(ho_offsets[0]))); return true; } @@ -145,7 +145,7 @@ bool GpuCache::alloc(size_t roi_buf_len, size_t num_rois__) // allocate on device size_t szb = total_len * sizeof(devbuffer[0]); - if (!GpusideCache::allocate_on_device((void**)&devbuffer, szb)) + if (!GpusideCache::allocate_on_device(reinterpret_cast(&devbuffer), szb)) return false; // not allocating dev_offsets @@ -164,11 +164,11 @@ template<> bool GpuCache::upload() { size_t szb = total_len * sizeof(devbuffer[0]); - if (!GpusideCache::upload_on_device((void*)devbuffer, (void*)hobuffer, szb)) + if (!GpusideCache::upload_on_device(static_cast(devbuffer), static_cast(hobuffer), szb)) return false; szb = num_rois * sizeof(dev_offsets[0]); - if (!GpusideCache::upload_on_device((void*)dev_offsets, (void*)ho_offsets, szb)) + if (!GpusideCache::upload_on_device(static_cast(dev_offsets), static_cast(ho_offsets), szb)) return false; return true; @@ -178,7 +178,7 @@ template<> bool GpuCache::download() { size_t szb = total_len * sizeof(devbuffer[0]); - if (!GpusideCache::download_on_host ((void*)hobuffer, (void*)devbuffer, szb)) + if (!GpusideCache::download_on_host (static_cast(hobuffer), static_cast(devbuffer), szb)) return false; return true; @@ -232,7 +232,7 @@ bool GpuCache::alloc(size_t roi_buf_len, size_t num_rois__) // allocate on device size_t szb = total_len * sizeof(devbuffer[0]); - if (!GpusideCache::allocate_on_device((void**)&devbuffer, szb)) + if (!GpusideCache::allocate_on_device(reinterpret_cast(&devbuffer), szb)) return false; // not allocating dev_offsets @@ -244,7 +244,7 @@ template<> bool GpuCache::download() { size_t szb = total_len * sizeof(devbuffer[0]); - if (!GpusideCache::download_on_host((void*)hobuffer, (void*)devbuffer, szb)) + if (!GpusideCache::download_on_host(static_cast(hobuffer), static_cast(devbuffer), szb)) return false; return true; @@ -291,14 +291,14 @@ bool GpuCache::alloc(size_t roi_buf_len, size_t num_rois__) total_len = roi_buf_len * num_rois; // allocate on host - hobuffer = (PixIntens*) std::malloc(total_len * sizeof(hobuffer[0])); + hobuffer = static_cast(std::malloc(total_len * sizeof(hobuffer[0]))); // not allocating ho_lengths // not allocating ho_offsets // allocate on device size_t szb = total_len * sizeof(devbuffer[0]); - if (!GpusideCache::allocate_on_device((void**)&devbuffer, szb)) + if (!GpusideCache::allocate_on_device(reinterpret_cast(&devbuffer), szb)) return false; return true; @@ -347,14 +347,14 @@ bool GpuCache::alloc(size_t roi_buf_len, size_t num_rois__) total_len = roi_buf_len * num_rois; // allocate on host - hobuffer = (float*)std::malloc(total_len * sizeof(hobuffer[0])); + hobuffer = static_cast(std::malloc(total_len * sizeof(hobuffer[0]))); // not allocating ho_lengths // not allocating ho_offsets // allocate on device size_t szb = total_len * sizeof(devbuffer[0]); - if (!GpusideCache::allocate_on_device((void**)&devbuffer, szb)) + if (!GpusideCache::allocate_on_device(reinterpret_cast(&devbuffer), szb)) return false; return true; @@ -364,7 +364,7 @@ template<> bool GpuCache::download() { size_t szb = total_len * sizeof(devbuffer[0]); - if (!GpusideCache::download_on_host((void*)hobuffer, (void*)devbuffer, szb)) + if (!GpusideCache::download_on_host(static_cast(hobuffer), static_cast(devbuffer), szb)) return false; return true; diff --git a/src/nyx/grayscale_tiff.h b/src/nyx/grayscale_tiff.h index 931c11597..933eb3bdd 100644 --- a/src/nyx/grayscale_tiff.h +++ b/src/nyx/grayscale_tiff.h @@ -241,9 +241,9 @@ class NyxusGrayscaleTiffTileLoader : public AbstractTileLoader auto row = i / tileWidth_, col = i % tileHeight_; if (col < fullWidth_ && row < fullHeight_) - dest->data()[i] = (DataType)((FileType*)(src))[i]; + dest->data()[i] = static_cast((static_cast(src))[i]); else - dest->data()[i] = (DataType)0; // Zero-fill gaps + dest->data()[i] = static_cast(0); // Zero-fill gaps } } #endif @@ -278,13 +278,13 @@ class NyxusGrayscaleTiffTileLoader : public AbstractTileLoader // (-1024 -> ~4.29e9), blowing up the max-intensity-driven grey-bin/histogram allocation // (macOS segfault; garbage MIN/MAX/MEAN elsewhere). Keep the clamp confined to the else // branch so preserve_hu still retains negatives via hu_offset. - FileType v = *(((FileType*)src) + physOffs); + FileType v = *((static_cast(src)) + physOffs); if (preserve_hu) - *(dest + logOffs) = hu_offset ((double)v); + *(dest + logOffs) = hu_offset (static_cast(v)); else { if constexpr (std::is_signed_v) if (v < 0) v = 0; - *(dest + logOffs) = (DataType) v; + *(dest + logOffs) = static_cast(v); } } } @@ -298,13 +298,13 @@ class NyxusGrayscaleTiffTileLoader : public AbstractTileLoader // FIX(#373): clamp negatives of a signed integer file type before the unsigned cast so int16 // CT (negative HU) doesn't wrap to ~4.29e9; confined to the else branch so preserve_hu keeps // negatives via hu_offset. - FileType v = *(((FileType*)src) + i); + FileType v = *((static_cast(src)) + i); if (preserve_hu) - *(dest + i) = hu_offset ((double)v); + *(dest + i) = hu_offset (static_cast(v)); else { if constexpr (std::is_signed_v) if (v < 0) v = 0; - *(dest + i) = (DataType) v; + *(dest + i) = static_cast(v); } } } @@ -336,7 +336,7 @@ class NyxusGrayscaleTiffTileLoader : public AbstractTileLoader physOffs = r * tileWidth_ + c; // Prevent real-valued intensities smaller than 1.0 from being cast to integer 0 - auto tmp1 = * (((FileType*)src) + physOffs); // real-valued raw (uncast) intensity e.g. 0.0724 + auto tmp1 = * ((static_cast(src)) + physOffs); // real-valued raw (uncast) intensity e.g. 0.0724 *(dest + logOffs) = map_real_intensity (tmp1); } } @@ -347,7 +347,7 @@ class NyxusGrayscaleTiffTileLoader : public AbstractTileLoader for (size_t i = 0; i < n; i++) { // Prevent real-valued intensities smaller than 1.0 from being cast to integer 0 - auto tmp1 = * (((FileType*)src) + i); // real-valued intensity e.g. 0.0724 + auto tmp1 = * ((static_cast(src)) + i); // real-valued intensity e.g. 0.0724 *(dest + i) = map_real_intensity (tmp1); } } @@ -381,9 +381,9 @@ class NyxusGrayscaleTiffTileLoader : public AbstractTileLoader // clamping sub-min outliers (incl. negative CT values) to 0 instead of wrapping. DataType hu_offset (double x) const { - double y = x - std::floor ((double)floatpt_image_min_intensity); + double y = x - std::floor (static_cast(floatpt_image_min_intensity)); if (y < 0.0) y = 0.0; - return (DataType) std::llround (y); + return static_cast(std::llround (y)); } // Map one real-valued pixel to the integer feature domain, honoring HU mode. @@ -393,9 +393,9 @@ class NyxusGrayscaleTiffTileLoader : public AbstractTileLoader { if (preserve_hu) return hu_offset (x); - double t = x < floatpt_image_min_intensity ? (double)floatpt_image_min_intensity : x; - t = t > floatpt_image_max_intensity ? (double)floatpt_image_max_intensity : t; - return (DataType)(floatpt_image_target_dyn_range * (t - floatpt_image_min_intensity) / (floatpt_image_max_intensity - floatpt_image_min_intensity)); + double t = x < floatpt_image_min_intensity ? static_cast(floatpt_image_min_intensity ): x; + t = t > floatpt_image_max_intensity ? static_cast(floatpt_image_max_intensity ): t; + return static_cast((floatpt_image_target_dyn_range * (t - floatpt_image_min_intensity) / (floatpt_image_max_intensity - floatpt_image_min_intensity))); } }; @@ -618,11 +618,11 @@ class NyxusGrayscaleTiffStripLoader : public AbstractTileLoader for (size_t col = startCol; col < endCol; col++) { // Logic to prevent "noise" in images whose dimensions are smaller than the default tile buffer size 1024x1024 - DataType dataItem = (DataType) 0; // Zero-fill gaps + DataType dataItem = static_cast(0); // Zero-fill gaps // - Informative zone of the strip if (layer < fullDepth_ && row < fullHeight_ && col < fullWidth_) - dataItem = (DataType)((FileType*)(src))[col]; + dataItem = static_cast((static_cast(src))[col]); // - Save the informative or zero-filled value dest->data()[ @@ -655,7 +655,7 @@ class NyxusGrayscaleTiffStripLoader : public AbstractTileLoader for (size_t col = start_col; col < end_col; col++) { // Logic to prevent "noise" in images whose dimensions are smaller than the default tile buffer size 1024x1024 - DataType dataItem = (DataType) 0; // Zero-fill gaps + DataType dataItem = static_cast(0); // Zero-fill gaps // - Informative zone of the strip if (layer < fullDepth_ && row < fullHeight_ && col < fullWidth_) @@ -664,9 +664,9 @@ class NyxusGrayscaleTiffStripLoader : public AbstractTileLoader // the cast to the unsigned pipeline type, so -1024 doesn't wrap to ~4.29e9 and blow up the // max-intensity-sized grey-bin/histogram allocation (macOS segfault). This is the // strip-loader twin of the tile-loader guard; proper HU handling is the preserve_hu path. - FileType v = ((FileType*)(src))[col]; + FileType v = (static_cast(src))[col]; if constexpr (std::is_signed_v) if (v < 0) v = 0; - dataItem = (DataType) v; + dataItem = static_cast(v); } // - Save the informative or zero-filled value diff --git a/src/nyx/helpers/fft.h b/src/nyx/helpers/fft.h index f972a5a3b..93a52ba2d 100644 --- a/src/nyx/helpers/fft.h +++ b/src/nyx/helpers/fft.h @@ -99,7 +99,7 @@ template void r2r_fft2d_inplace(std::vector &xi, const fft_dir &dir) { DJ_ASSERT((xi.size() & (xi.size() - 1)) == 0 && "invalid input size"); - int cnt2 = (int)xi.size(); // NxN + int cnt2 = static_cast(xi.size()); // NxN int msb = findMSB(cnt2) / 2; // lg2(N) = lg2(sqrt(NxN)) int cnt = 1 << msb; // N = 2^lg2(N) T nrm = T(1) / T(cnt); diff --git a/src/nyx/helpers/helpers.cpp b/src/nyx/helpers/helpers.cpp index 2b53d0782..32b7c0f16 100644 --- a/src/nyx/helpers/helpers.cpp +++ b/src/nyx/helpers/helpers.cpp @@ -51,12 +51,12 @@ namespace Nyxus double calc_mean (const std::vector& X) { double sum = std::accumulate(X.begin(), X.end(), 0.0); - return sum / (double) X.size(); + return sum / static_cast(X.size()); } double calc_covariance (const std::vector& data1, double mean1, const std::vector& data2, double mean2) { - double normfactor = (double)(data1.size() - 1), // sample covariance + double normfactor = static_cast((data1.size() - 1)), // sample covariance sum_of_products = 0.0; for (size_t i = 0; i < data1.size(); i++) diff --git a/src/nyx/helpers/helpers.h b/src/nyx/helpers/helpers.h index 243ce9852..f76a1535b 100644 --- a/src/nyx/helpers/helpers.h +++ b/src/nyx/helpers/helpers.h @@ -113,7 +113,7 @@ namespace Nyxus return false; // Successful conversion, return its result - result = (int)res; + result = static_cast(res); return true; } @@ -242,9 +242,9 @@ namespace Nyxus { if (a <= 1) return 1; - unsigned int x = (unsigned int)(a - 1); + unsigned int x = static_cast((a - 1)); x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; - return (int)(x + 1); + return static_cast((x + 1)); } inline void print_curve(const std::vector>& curve, const std::string& name) @@ -282,7 +282,7 @@ namespace Nyxus inline double fast_log10 (double _x) // compute log2(x) by reducing x to [0.75, 1.5) { - float x = (float)_x; + float x = static_cast(_x); // a*(x-1)^2 + b*(x-1) approximates log2(x) when 0.75 <= x < 1.5 const float a = -.6296735f; @@ -340,7 +340,7 @@ namespace Nyxus return i; double pi = ((double(i-min_i) / double(i_range) * double(n_levels))); - unsigned int new_pi = (unsigned int)pi; + unsigned int new_pi = static_cast(pi); return new_pi; } @@ -449,10 +449,10 @@ namespace Nyxus return ""; // integer part - size_t y = (size_t) std::abs(x); + size_t y = static_cast(std::abs(x)); // fractional part ("123.4567" -> "4567") - double f = x - (int) x; + double f = x - static_cast(x); std::string s = std::signbit(x) ? "-" : ""; std::string frac = f==0.0 ? "0.0" : std::to_string(f); if (frac.length()>=1) diff --git a/src/nyx/image_loader.cpp b/src/nyx/image_loader.cpp index 6e99b9e83..472189c36 100644 --- a/src/nyx/image_loader.cpp +++ b/src/nyx/image_loader.cpp @@ -46,7 +46,7 @@ bool ImageLoader::open (SlideProps & p, const FpImageOptions & fpopts) // would clamp every negative HU to 0. Only the non-HU float path uses the // fp override min. intFL = new NyxusGrayscaleDicomLoader(n_threads, int_fpath, - (fpopts.preserve_hu() || fpopts.empty()) ? p.min_preroi_inten : (double)fpopts.min_intensity(), + (fpopts.preserve_hu() || fpopts.empty()) ? p.min_preroi_inten : static_cast(fpopts.min_intensity()), fpopts.preserve_hu()); #else std::string erm = "This version of Nyxus was not build with DICOM support"; @@ -60,7 +60,7 @@ bool ImageLoader::open (SlideProps & p, const FpImageOptions & fpopts) if (ext == ".nii" || ext == ".nii.gz") { intFL = new NiftiLoader (int_fpath, - (fpopts.preserve_hu() || fpopts.empty()) ? p.min_preroi_inten : (double)fpopts.min_intensity(), // HU offset base = scanned HU-domain slide min; ignore fp min in preserve_hu mode (else negative HU clamps to 0) + (fpopts.preserve_hu() || fpopts.empty()) ? p.min_preroi_inten : static_cast(fpopts.min_intensity()), // HU offset base = scanned HU-domain slide min; ignore fp min in preserve_hu mode (else negative HU clamps to 0) fpopts.preserve_hu()); // CT/HU mode: offset-preserving map (matches DICOM/TIFF) } else diff --git a/src/nyx/io/nifti/laynii_lib.cpp b/src/nyx/io/nifti/laynii_lib.cpp index b1587556d..464ee8fce 100644 --- a/src/nyx/io/nifti/laynii_lib.cpp +++ b/src/nyx/io/nifti/laynii_lib.cpp @@ -51,7 +51,7 @@ double ren_stdev(double arr[], int size) { mean = ren_average(arr, size); for (i = 0; i < size; ++i) { - sum += (arr[i] - mean) * (arr[i] - mean) / ((double)size - 1); + sum += (arr[i] - mean) * (arr[i] - mean) / (static_cast(size )- 1); } if (sqrt( sum) != sqrt( sum) ) sum = 0; return sqrt( sum); @@ -87,7 +87,7 @@ double ren_skew(double arr[], int size) { sum1 += (arr[i] - mean) * (arr[i] - mean) * (arr[i] - mean); sum2 += (arr[i] - mean) * (arr[i] - mean); } - skew = (1 / ((double)size) * sum1) / (pow(1 / ((double)size - 1) * sum2, 1.5)); + skew = (1 / (static_cast(size)) * sum1) / (pow(1 / (static_cast(size )- 1) * sum2, 1.5)); if (skew != skew ) skew = 0; return (skew); } @@ -100,8 +100,8 @@ double ren_kurt(double arr[], int size) { double mean = ren_average(arr, size); for (i = 0; i < size; ++i) { - sum1 += (arr[i] - mean) * (arr[i] - mean) * (arr[i] - mean) * (arr[i] - mean) / ((double)size); - sum2 += (arr[i] - mean) * (arr[i] - mean) / ((double)size); + sum1 += (arr[i] - mean) * (arr[i] - mean) * (arr[i] - mean) * (arr[i] - mean) / (static_cast(size)); + sum2 += (arr[i] - mean) * (arr[i] - mean) / (static_cast(size)); } kurt = sum1 / (sum2 * sum2) - 3 ; if (kurt != kurt ) kurt = 0 ; @@ -617,52 +617,52 @@ nifti_image* copy_nifti_as_float16(nifti_image* nii) { if (nii->datatype == 2) { // NIFTI_TYPE_UINT8 uint8_t* nii_data = static_cast(nii->data); for (int i = 0; i < nr_voxels; ++i) { - *(nii_new_data + i) = (short)((double) (*(nii_data + i) * 1000)); + *(nii_new_data + i) = static_cast((static_cast((*(nii_data + i) * 1000)))); } } else if (nii->datatype == 512) { // NIFTI_TYPE_UINT16 uint16_t* nii_data = static_cast(nii->data); for (int i = 0; i < nr_voxels; ++i) { - *(nii_new_data + i) = (short)((double) (*(nii_data + i) * 1000)); + *(nii_new_data + i) = static_cast((static_cast((*(nii_data + i) * 1000)))); } } else if (nii->datatype == 768) { // NIFTI_TYPE_UINT32 uint32_t* nii_data = static_cast(nii->data); for (int i = 0; i < nr_voxels; ++i) { - *(nii_new_data + i) = (short)((double) (*(nii_data + i) * 1000)); + *(nii_new_data + i) = static_cast((static_cast((*(nii_data + i) * 1000)))); } } else if (nii->datatype == 1280) { // NIFTI_TYPE_UINT64 uint64_t* nii_data = static_cast(nii->data); for (int i = 0; i < nr_voxels; ++i) { - *(nii_new_data + i) = (short)((double) (*(nii_data + i) * 1000)); + *(nii_new_data + i) = static_cast((static_cast((*(nii_data + i) * 1000)))); } } else if (nii->datatype == 256) { // NIFTI_TYPE_INT8 int8_t* nii_data = static_cast(nii->data); for (int i = 0; i < nr_voxels; ++i) { - *(nii_new_data + i) = (short)((double) (*(nii_data + i) * 1000)); + *(nii_new_data + i) = static_cast((static_cast((*(nii_data + i) * 1000)))); } } else if (nii->datatype == 4) { // NIFTI_TYPE_INT16 int16_t* nii_data = static_cast(nii->data); for (int i = 0; i < nr_voxels; ++i) { - *(nii_new_data + i) = (short)((double) (*(nii_data + i) * 1000)); + *(nii_new_data + i) = static_cast((static_cast((*(nii_data + i) * 1000)))); } } else if (nii->datatype == 8) { // NIFTI_TYPE_INT32 int32_t* nii_data = static_cast(nii->data); for (int i = 0; i < nr_voxels; ++i) { - *(nii_new_data + i) = (short)((double) (*(nii_data + i) * 1000)); + *(nii_new_data + i) = static_cast((static_cast((*(nii_data + i) * 1000)))); } } else if (nii->datatype == 1024) { // NIFTI_TYPE_INT64 int64_t* nii_data = static_cast(nii->data); for (int i = 0; i < nr_voxels; ++i) { - *(nii_new_data + i) = (short)((double) (*(nii_data + i) * 1000)); + *(nii_new_data + i) = static_cast((static_cast((*(nii_data + i) * 1000)))); } } else if (nii->datatype == 16) { // NIFTI_TYPE_FLOAT32 float* nii_data = static_cast(nii->data); for (int i = 0; i < nr_voxels; ++i) { - *(nii_new_data + i) = (short)((double) (*(nii_data + i) * 1000)); + *(nii_new_data + i) = static_cast((static_cast((*(nii_data + i) * 1000)))); } } else if (nii->datatype == 64) { // NIFTI_TYPE_FLOAT64 double* nii_data = static_cast(nii->data); for (int i = 0; i < nr_voxels; ++i) { - *(nii_new_data + i) = (short)((double) (*(nii_data + i) * 1000)); + *(nii_new_data + i) = static_cast((static_cast((*(nii_data + i) * 1000)))); } } else { cout << "Warning! Unrecognized nifti data type!" << endl; @@ -1092,7 +1092,7 @@ void ln_smooth_gaussian_iterative_3D(float* data_in, int data_size = nx * ny * nz * nt; - float* data_temp = (float*)malloc(data_size * sizeof(float)); + float* data_temp = static_cast(malloc(data_size * sizeof(float))); // Compute Gaussian weights float w_0 = ln_gaussian(0, fwhm); @@ -1264,8 +1264,8 @@ void ln_compute_hessian_3D(const float* data_in, float* data_shorthessian, float FWHM = 1.0; // Allocate memory (NOTE: I have prioritized RAM optimization) - float* data_grad_1st = (float*)malloc(data_size * sizeof(float)); - float* data_grad_2nd = (float*)malloc(data_size * sizeof(float)); + float* data_grad_1st = static_cast(malloc(data_size * sizeof(float))); + float* data_grad_2nd = static_cast(malloc(data_size * sizeof(float))); // x ln_compute_gradients_3D_over_x(data_in, data_grad_1st, nx, ny, nz, nt); @@ -1654,9 +1654,9 @@ void ln_compute_divergence_3D(float* data_out, const float* data_gra1, const flo const int nx, const int ny, const int nz, const int nt) { int data_size = nx * ny * nz * nt; - float* data_out1 = (float*)malloc(data_size * sizeof(float)); - float* data_out2 = (float*)malloc(data_size * sizeof(float)); - float* data_out3 = (float*)malloc(data_size * sizeof(float)); + float* data_out1 = static_cast(malloc(data_size * sizeof(float))); + float* data_out2 = static_cast(malloc(data_size * sizeof(float))); + float* data_out3 = static_cast(malloc(data_size * sizeof(float))); ln_compute_gradients_3D_over_x(data_gra1, data_out1, nx, ny, nz, nt); ln_compute_gradients_3D_over_y(data_gra2, data_out2, nx, ny, nz, nt); diff --git a/src/nyx/io/nifti/nifti1.h b/src/nyx/io/nifti/nifti1.h index dd6c9ac5e..aff6f4d5c 100644 --- a/src/nyx/io/nifti/nifti1.h +++ b/src/nyx/io/nifti/nifti1.h @@ -1347,8 +1347,8 @@ typedef struct { unsigned char r,g,b; } rgb_byte ; #define XYZT_TO_TIME(xyzt) ( (xyzt) & 0x38 ) #undef SPACE_TIME_TO_XYZT -#define SPACE_TIME_TO_XYZT(ss,tt) ( (((char)(ss)) & 0x07) \ - | (((char)(tt)) & 0x38) ) +#define SPACE_TIME_TO_XYZT(ss,tt) ( ((static_cast((ss))) & 0x07) \ + | ((static_cast((tt))) & 0x38) ) /*---------------------------------------------------------------------------*/ /* MRI-SPECIFIC SPATIAL AND TEMPORAL INFORMATION: @@ -1445,9 +1445,9 @@ typedef struct { unsigned char r,g,b; } rgb_byte ; #define DIM_INFO_TO_SLICE_DIM(di) ( ((di) >> 4) & 0x03 ) #undef FPS_INTO_DIM_INFO -#define FPS_INTO_DIM_INFO(fd,pd,sd) ( ( ( ((char)(fd)) & 0x03) ) | \ - ( ( ((char)(pd)) & 0x03) << 2 ) | \ - ( ( ((char)(sd)) & 0x03) << 4 ) ) +#define FPS_INTO_DIM_INFO(fd,pd,sd) ( ( ( (static_cast((fd))) & 0x03) ) | \ + ( ( (static_cast((pd))) & 0x03) << 2 ) | \ + ( ( (static_cast((sd))) & 0x03) << 4 ) ) /*! \defgroup NIFTI1_SLICE_ORDER \brief nifti1 slice order codes, describing the acquisition order diff --git a/src/nyx/io/nifti/nifti2_io.cpp b/src/nyx/io/nifti/nifti2_io.cpp index ecb02c92a..dd372fc5e 100644 --- a/src/nyx/io/nifti/nifti2_io.cpp +++ b/src/nyx/io/nifti/nifti2_io.cpp @@ -638,7 +638,7 @@ nifti_image *nifti_image_read_bricks(const char * hname, int64_t nbricks, if( !hname || !NBL ){ fprintf(stderr,"** nifti_image_read_bricks: bad params (%p,%p)\n", - hname, (void *)NBL); + hname, static_cast(NBL)); return NULL; } @@ -828,7 +828,7 @@ int nifti_image_load_bricks( nifti_image * nim , int64_t nbricks, /* we can have blist == NULL */ if( !nim || !NBL ){ fprintf(stderr,"** nifti_image_load_bricks, bad params (%p,%p)\n", - (void *)nim, (void *)NBL); + static_cast(nim), static_cast(NBL)); return -1; } @@ -997,7 +997,7 @@ static int nifti_alloc_NBL_mem(nifti_image * nim, int64_t nbricks, } nbl->bsize = nim->nx * nim->ny * nim->nz * nim->nbyper; /* bytes */ - nbl->bricks = (void **)malloc(nbl->nbricks * sizeof(void *)); + nbl->bricks = reinterpret_cast(malloc(nbl->nbricks * sizeof(void *))); if( ! nbl->bricks ){ fprintf(stderr,"** NIFTI NANM: failed to alloc void ptrs\n"); @@ -1005,7 +1005,7 @@ static int nifti_alloc_NBL_mem(nifti_image * nim, int64_t nbricks, } for( c = 0; c < nbl->nbricks; c++ ){ - nbl->bricks[c] = (void *)malloc(nbl->bsize); + nbl->bricks[c] = static_cast(malloc(nbl->bsize)); if( ! nbl->bricks[c] ){ fprintf(stderr,"** NIFTI NANM: failed to alloc bytes for brick \n"); /* so free and clear everything before returning */ @@ -1045,8 +1045,8 @@ static int nifti_copynsort(int64_t nbricks, const int64_t *blist, int64_t * stmp, * itmp; /* for ease of typing/reading */ int64_t c1, c2, spos, tmp; - *slist = (int64_t *)malloc(nbricks * sizeof(int64_t)); - *sindex = (int64_t *)malloc(nbricks * sizeof(int64_t)); + *slist = static_cast(malloc(nbricks * sizeof(int64_t))); + *sindex = static_cast(malloc(nbricks * sizeof(int64_t))); if( !*slist || !*sindex ){ fprintf(stderr,"** NIFTI NCS: failed to alloc ints for sorting\n"); @@ -1186,7 +1186,7 @@ static int nifti_NBL_matches_nim(const nifti_image *nim, /* for nim, compute volbytes and nvols */ if( nim->ndim > 0 ) { /* first 3 indices are over a single volume */ - volbytes = (int64_t)nim->nbyper; + volbytes = static_cast(nim->nbyper); for( ind = 1; ind <= nim->ndim && ind < 4; ind++ ) volbytes *= nim->dim[ind]; @@ -1254,7 +1254,7 @@ char *nifti_strdup(const char *str) if( !str ) return NULL; /* allow calls passing NULL */ - dup = (char *)malloc(strlen(str) + 1); + dup = static_cast(malloc(strlen(str) + 1)); /* check for failure */ if( dup ) strcpy(dup, str); @@ -1546,7 +1546,7 @@ int nifti_mat44_to_dmat44(mat44 * fm, nifti_dmat44 * dm) if( !dm || !fm ) return 1; for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) - dm->m[i][j] = (double)fm->m[i][j]; + dm->m[i][j] = static_cast(fm->m[i][j]); return 0; } @@ -1556,7 +1556,7 @@ int nifti_dmat44_to_mat44(nifti_dmat44 * dm, mat44 * fm) if( !dm || !fm ) return 1; for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) - fm->m[i][j] = (float)dm->m[i][j]; + fm->m[i][j] = static_cast(dm->m[i][j]); return 0; } @@ -1679,15 +1679,15 @@ mat44 nifti_quatern_to_mat44( float qb, float qc, float qd, if( qfac < 0.0 ) zd = -zd ; /* left handedness? */ - R.m[0][0] = (float)( (a*a+b*b-c*c-d*d) * xd) ; + R.m[0][0] = static_cast(( (a*a+b*b-c*c-d*d) * xd) ); R.m[0][1] = 2.0l * (b*c-a*d ) * yd ; R.m[0][2] = 2.0l * (b*d+a*c ) * zd ; R.m[1][0] = 2.0l * (b*c+a*d ) * xd ; - R.m[1][1] = (float)( (a*a+c*c-b*b-d*d) * yd) ; + R.m[1][1] = static_cast(( (a*a+c*c-b*b-d*d) * yd) ); R.m[1][2] = 2.0l * (c*d-a*b ) * zd ; R.m[2][0] = 2.0l * (b*d-a*c ) * xd ; R.m[2][1] = 2.0l * (c*d+a*b ) * yd ; - R.m[2][2] = (float)( (a*a+d*d-c*c-b*b) * zd) ; + R.m[2][2] = static_cast(( (a*a+d*d-c*c-b*b) * zd) ); /* load offsets */ @@ -1893,7 +1893,7 @@ void nifti_mat44_to_quatern( mat44 R , /* assign the output lengths */ - ASSIF(dx,(float)xd) ; ASSIF(dy,(float)yd) ; ASSIF(dz,(float)zd) ; + ASSIF(dx,static_cast(xd)) ; ASSIF(dy,static_cast(yd)) ; ASSIF(dz,static_cast(zd)) ; /* normalize the columns */ @@ -1913,9 +1913,9 @@ void nifti_mat44_to_quatern( mat44 R , will result in the inverse orthogonal matrix at this point. If we just orthogonalized the columns, this wouldn't necessarily hold. */ - Q.m[0][0] = (float)r11 ; Q.m[0][1] = (float)r12 ; Q.m[0][2] = (float)r13 ; /* load Q */ - Q.m[1][0] = (float)r21 ; Q.m[1][1] = (float)r22 ; Q.m[1][2] = (float)r23 ; - Q.m[2][0] = (float)r31 ; Q.m[2][1] = (float)r32 ; Q.m[2][2] = (float)r33 ; + Q.m[0][0] = static_cast(r11 ); Q.m[0][1] = static_cast(r12 ); Q.m[0][2] = static_cast(r13 ); /* load Q */ + Q.m[1][0] = static_cast(r21 ); Q.m[1][1] = static_cast(r22 ); Q.m[1][2] = static_cast(r23 ); + Q.m[2][0] = static_cast(r31 ); Q.m[2][1] = static_cast(r32 ); Q.m[2][2] = static_cast(r33 ); P = nifti_mat33_polar(Q) ; /* P is orthog matrix closest to Q */ @@ -1972,7 +1972,7 @@ void nifti_mat44_to_quatern( mat44 R , if( a < 0.0l ){ b=-b ; c=-c ; d=-d; } } - ASSIF(qb,(float)b) ; ASSIF(qc,(float)c) ; ASSIF(qd,(float)d) ; + ASSIF(qb,static_cast(b)) ; ASSIF(qc,static_cast(c)) ; ASSIF(qd,static_cast(d)) ; return ; } @@ -2062,23 +2062,23 @@ mat44 nifti_mat44_inverse( mat44 R ) if( deti != 0.0l ) deti = 1.0l / deti ; - Q.m[0][0] = (float)( deti*( r22*r33-r32*r23) ) ; - Q.m[0][1] = (float)( deti*(-r12*r33+r32*r13) ) ; - Q.m[0][2] = (float)( deti*( r12*r23-r22*r13) ) ; - Q.m[0][3] = (float)( deti*(-r12*r23*v3+r12*v2*r33+r22*r13*v3 - -r22*v1*r33-r32*r13*v2+r32*v1*r23) ) ; + Q.m[0][0] = static_cast(( deti*( r22*r33-r32*r23) ) ); + Q.m[0][1] = static_cast(( deti*(-r12*r33+r32*r13) ) ); + Q.m[0][2] = static_cast(( deti*( r12*r23-r22*r13) ) ); + Q.m[0][3] = static_cast(( deti*(-r12*r23*v3+r12*v2*r33+r22*r13*v3 + -r22*v1*r33-r32*r13*v2+r32*v1*r23) ) ); - Q.m[1][0] = (float)( deti*(-r21*r33+r31*r23) ) ; - Q.m[1][1] = (float)( deti*( r11*r33-r31*r13) ) ; - Q.m[1][2] = (float)( deti*(-r11*r23+r21*r13) ) ; - Q.m[1][3] = (float)( deti*( r11*r23*v3-r11*v2*r33-r21*r13*v3 - +r21*v1*r33+r31*r13*v2-r31*v1*r23) ) ; + Q.m[1][0] = static_cast(( deti*(-r21*r33+r31*r23) ) ); + Q.m[1][1] = static_cast(( deti*( r11*r33-r31*r13) ) ); + Q.m[1][2] = static_cast(( deti*(-r11*r23+r21*r13) ) ); + Q.m[1][3] = static_cast(( deti*( r11*r23*v3-r11*v2*r33-r21*r13*v3 + +r21*v1*r33+r31*r13*v2-r31*v1*r23) ) ); - Q.m[2][0] = (float)( deti*( r21*r32-r31*r22) ) ; - Q.m[2][1] = (float)( deti*(-r11*r32+r31*r12) ) ; - Q.m[2][2] = (float)( deti*( r11*r22-r21*r12) ) ; - Q.m[2][3] = (float)( deti*(-r11*r22*v3+r11*r32*v2+r21*r12*v3 - -r21*r32*v1-r31*r12*v2+r31*r22*v1) ) ; + Q.m[2][0] = static_cast(( deti*( r21*r32-r31*r22) ) ); + Q.m[2][1] = static_cast(( deti*(-r11*r32+r31*r12) ) ); + Q.m[2][2] = static_cast(( deti*( r11*r22-r21*r12) ) ); + Q.m[2][3] = static_cast(( deti*(-r11*r22*v3+r11*r32*v2+r21*r12*v3 + -r21*r32*v1-r31*r12*v2+r31*r22*v1) ) ); Q.m[3][0] = Q.m[3][1] = Q.m[3][2] = 0.0l ; Q.m[3][3] = (deti == 0.0l) ? 0.0l : 1.0l ; /* failure flag if deti == 0 */ @@ -2220,7 +2220,7 @@ mat44 nifti_make_orthog_mat44( float r11, float r12, float r13 , val = Q.m[0][0]*Q.m[0][0] + Q.m[0][1]*Q.m[0][1] + Q.m[0][2]*Q.m[0][2] ; if( val > 0.0l ){ val = 1.0l / sqrt(val) ; - Q.m[0][0] *= (float)val ; Q.m[0][1] *= (float)val ; Q.m[0][2] *= (float)val ; + Q.m[0][0] *= static_cast(val ); Q.m[0][1] *= static_cast(val ); Q.m[0][2] *= static_cast(val ); } else { Q.m[0][0] = 1.0l ; Q.m[0][1] = 0.0l ; Q.m[0][2] = 0.0l ; } @@ -2230,7 +2230,7 @@ mat44 nifti_make_orthog_mat44( float r11, float r12, float r13 , val = Q.m[1][0]*Q.m[1][0] + Q.m[1][1]*Q.m[1][1] + Q.m[1][2]*Q.m[1][2] ; if( val > 0.0l ){ val = 1.0l / sqrt(val) ; - Q.m[1][0] *= (float)val ; Q.m[1][1] *= (float)val ; Q.m[1][2] *= (float)val ; + Q.m[1][0] *= static_cast(val ); Q.m[1][1] *= static_cast(val ); Q.m[1][2] *= static_cast(val ); } else { Q.m[1][0] = 0.0l ; Q.m[1][1] = 1.0l ; Q.m[1][2] = 0.0l ; } @@ -2240,7 +2240,7 @@ mat44 nifti_make_orthog_mat44( float r11, float r12, float r13 , val = Q.m[2][0]*Q.m[2][0] + Q.m[2][1]*Q.m[2][1] + Q.m[2][2]*Q.m[2][2] ; if( val > 0.0l ){ val = 1.0l / sqrt(val) ; - Q.m[2][0] *= (float)val ; Q.m[2][1] *= (float)val ; Q.m[2][2] *= (float)val ; + Q.m[2][0] *= static_cast(val ); Q.m[2][1] *= static_cast(val ); Q.m[2][2] *= static_cast(val ); } else { Q.m[2][0] = Q.m[0][1]*Q.m[1][2] - Q.m[0][2]*Q.m[1][1] ; /* cross */ Q.m[2][1] = Q.m[0][2]*Q.m[1][0] - Q.m[0][0]*Q.m[1][2] ; /* product */ @@ -2305,17 +2305,17 @@ mat33 nifti_mat33_inverse( mat33 R ) /* inverse of 3x3 matrix */ if( deti != 0.0l ) deti = 1.0l / deti ; - Q.m[0][0] = (float)( deti*( r22*r33-r32*r23) ) ; - Q.m[0][1] = (float)( deti*(-r12*r33+r32*r13) ) ; - Q.m[0][2] = (float)( deti*( r12*r23-r22*r13) ) ; + Q.m[0][0] = static_cast(( deti*( r22*r33-r32*r23) ) ); + Q.m[0][1] = static_cast(( deti*(-r12*r33+r32*r13) ) ); + Q.m[0][2] = static_cast(( deti*( r12*r23-r22*r13) ) ); - Q.m[1][0] = (float)( deti*(-r21*r33+r31*r23) ) ; - Q.m[1][1] = (float)( deti*( r11*r33-r31*r13) ) ; - Q.m[1][2] = (float)( deti*(-r11*r23+r21*r13) ) ; + Q.m[1][0] = static_cast(( deti*(-r21*r33+r31*r23) ) ); + Q.m[1][1] = static_cast(( deti*( r11*r33-r31*r13) ) ); + Q.m[1][2] = static_cast(( deti*(-r11*r23+r21*r13) ) ); - Q.m[2][0] = (float)( deti*( r21*r32-r31*r22) ) ; - Q.m[2][1] = (float)( deti*(-r11*r32+r31*r12) ) ; - Q.m[2][2] = (float)( deti*( r11*r22-r21*r12) ) ; + Q.m[2][0] = static_cast(( deti*( r21*r32-r31*r22) ) ); + Q.m[2][1] = static_cast(( deti*(-r11*r32+r31*r12) ) ); + Q.m[2][2] = static_cast(( deti*( r11*r22-r21*r12) ) ); return Q ; } @@ -2346,8 +2346,8 @@ float nifti_mat33_determ( mat33 R ) /* determinant of 3x3 matrix */ r21 = R.m[1][0]; r22 = R.m[1][1]; r23 = R.m[1][2]; /* [ r21 r22 r23 ] */ r31 = R.m[2][0]; r32 = R.m[2][1]; r33 = R.m[2][2]; /* [ r31 r32 r33 ] */ - return (float)(r11*r22*r33-r11*r32*r23-r21*r12*r33 - +r21*r32*r13+r31*r12*r23-r31*r22*r13) ; + return static_cast((r11*r22*r33-r11*r32*r23-r21*r12*r33 + +r21*r32*r13+r31*r12*r23-r31*r22*r13) ); } /*----------------------------------------------------------------------*/ @@ -2372,9 +2372,9 @@ float nifti_mat33_rownorm( mat33 A ) /* max row norm of 3x3 matrix */ { float r1,r2,r3 ; - r1 = (float)( fabs(A.m[0][0])+fabs(A.m[0][1])+fabs(A.m[0][2]) ) ; - r2 = (float)( fabs(A.m[1][0])+fabs(A.m[1][1])+fabs(A.m[1][2]) ) ; - r3 = (float)( fabs(A.m[2][0])+fabs(A.m[2][1])+fabs(A.m[2][2]) ) ; + r1 = static_cast(( fabs(A.m[0][0])+fabs(A.m[0][1])+fabs(A.m[0][2]) ) ); + r2 = static_cast(( fabs(A.m[1][0])+fabs(A.m[1][1])+fabs(A.m[1][2]) ) ); + r3 = static_cast(( fabs(A.m[2][0])+fabs(A.m[2][1])+fabs(A.m[2][2]) ) ); if( r1 < r2 ) r1 = r2 ; if( r1 < r3 ) r1 = r3 ; return r1 ; @@ -2402,9 +2402,9 @@ float nifti_mat33_colnorm( mat33 A ) /* max column norm of 3x3 matrix */ { float r1,r2,r3 ; - r1 = (float)( fabs(A.m[0][0])+fabs(A.m[1][0])+fabs(A.m[2][0]) ) ; - r2 = (float)( fabs(A.m[0][1])+fabs(A.m[1][1])+fabs(A.m[2][1]) ) ; - r3 = (float)( fabs(A.m[0][2])+fabs(A.m[1][2])+fabs(A.m[2][2]) ) ; + r1 = static_cast(( fabs(A.m[0][0])+fabs(A.m[1][0])+fabs(A.m[2][0]) ) ); + r2 = static_cast(( fabs(A.m[0][1])+fabs(A.m[1][1])+fabs(A.m[2][1]) ) ); + r3 = static_cast(( fabs(A.m[0][2])+fabs(A.m[1][2])+fabs(A.m[2][2]) ) ); if( r1 < r2 ) r1 = r2 ; if( r1 < r3 ) r1 = r3 ; return r1 ; @@ -2548,7 +2548,7 @@ mat33 nifti_mat33_polar( mat33 A ) gam = nifti_mat33_determ(X) ; while( gam == 0.0 ){ /* perturb matrix */ - gam = (float)( 0.00001 * ( 0.001 + nifti_mat33_rownorm(X) ) ) ; + gam = static_cast(( 0.00001 * ( 0.001 + nifti_mat33_rownorm(X) ) ) ); X.m[0][0] += gam ; X.m[1][1] += gam ; X.m[2][2] += gam ; gam = nifti_mat33_determ(X) ; } @@ -2556,28 +2556,28 @@ mat33 nifti_mat33_polar( mat33 A ) while(1){ Y = nifti_mat33_inverse(X) ; if( dif > 0.3 ){ /* far from convergence */ - alp = (float)( sqrt( nifti_mat33_rownorm(X) * nifti_mat33_colnorm(X) ) ) ; - bet = (float)( sqrt( nifti_mat33_rownorm(Y) * nifti_mat33_colnorm(Y) ) ) ; - gam = (float)( sqrt( bet / alp ) ) ; - gmi = (float)( 1.0 / gam ) ; + alp = static_cast(( sqrt( nifti_mat33_rownorm(X) * nifti_mat33_colnorm(X) ) ) ); + bet = static_cast(( sqrt( nifti_mat33_rownorm(Y) * nifti_mat33_colnorm(Y) ) ) ); + gam = static_cast(( sqrt( bet / alp ) ) ); + gmi = static_cast(( 1.0 / gam ) ); } else { gam = gmi = 1.0f ; /* close to convergence */ } - Z.m[0][0] = (float)( 0.5 * ( gam*X.m[0][0] + gmi*Y.m[0][0] ) ) ; - Z.m[0][1] = (float)( 0.5 * ( gam*X.m[0][1] + gmi*Y.m[1][0] ) ) ; - Z.m[0][2] = (float)( 0.5 * ( gam*X.m[0][2] + gmi*Y.m[2][0] ) ) ; - Z.m[1][0] = (float)( 0.5 * ( gam*X.m[1][0] + gmi*Y.m[0][1] ) ) ; - Z.m[1][1] = (float)( 0.5 * ( gam*X.m[1][1] + gmi*Y.m[1][1] ) ) ; - Z.m[1][2] = (float)( 0.5 * ( gam*X.m[1][2] + gmi*Y.m[2][1] ) ) ; - Z.m[2][0] = (float)( 0.5 * ( gam*X.m[2][0] + gmi*Y.m[0][2] ) ) ; - Z.m[2][1] = (float)( 0.5 * ( gam*X.m[2][1] + gmi*Y.m[1][2] ) ) ; - Z.m[2][2] = (float)( 0.5 * ( gam*X.m[2][2] + gmi*Y.m[2][2] ) ) ; - - dif = (float)( fabs(Z.m[0][0]-X.m[0][0])+fabs(Z.m[0][1]-X.m[0][1]) + Z.m[0][0] = static_cast(( 0.5 * ( gam*X.m[0][0] + gmi*Y.m[0][0] ) ) ); + Z.m[0][1] = static_cast(( 0.5 * ( gam*X.m[0][1] + gmi*Y.m[1][0] ) ) ); + Z.m[0][2] = static_cast(( 0.5 * ( gam*X.m[0][2] + gmi*Y.m[2][0] ) ) ); + Z.m[1][0] = static_cast(( 0.5 * ( gam*X.m[1][0] + gmi*Y.m[0][1] ) ) ); + Z.m[1][1] = static_cast(( 0.5 * ( gam*X.m[1][1] + gmi*Y.m[1][1] ) ) ); + Z.m[1][2] = static_cast(( 0.5 * ( gam*X.m[1][2] + gmi*Y.m[2][1] ) ) ); + Z.m[2][0] = static_cast(( 0.5 * ( gam*X.m[2][0] + gmi*Y.m[0][2] ) ) ); + Z.m[2][1] = static_cast(( 0.5 * ( gam*X.m[2][1] + gmi*Y.m[1][2] ) ) ); + Z.m[2][2] = static_cast(( 0.5 * ( gam*X.m[2][2] + gmi*Y.m[2][2] ) ) ); + + dif = static_cast(( fabs(Z.m[0][0]-X.m[0][0])+fabs(Z.m[0][1]-X.m[0][1]) +fabs(Z.m[0][2]-X.m[0][2])+fabs(Z.m[1][0]-X.m[1][0]) +fabs(Z.m[1][1]-X.m[1][1])+fabs(Z.m[1][2]-X.m[1][2]) +fabs(Z.m[2][0]-X.m[2][0])+fabs(Z.m[2][1]-X.m[2][1]) - +fabs(Z.m[2][2]-X.m[2][2]) ); + +fabs(Z.m[2][2]-X.m[2][2]) )); k = k+1 ; if( k > 100 || dif < 3.e-6 ) break ; /* convergence or exhaustion */ @@ -2816,13 +2816,13 @@ void nifti_mat44_to_orientation( mat44 R , int *icod, int *jcod, int *kcod ) /* normalize i axis */ - val = (float)sqrt( xi*xi + yi*yi + zi*zi ) ; + val = static_cast(sqrt( xi*xi + yi*yi + zi*zi ) ); if( val == 0.0 ) return ; /* stupid input */ xi /= val ; yi /= val ; zi /= val ; /* normalize j axis */ - val = (float)sqrt( xj*xj + yj*yj + zj*zj ) ; + val = static_cast(sqrt( xj*xj + yj*yj + zj*zj ) ); if( val == 0.0 ) return ; /* stupid input */ xj /= val ; yj /= val ; zj /= val ; @@ -2831,14 +2831,14 @@ void nifti_mat44_to_orientation( mat44 R , int *icod, int *jcod, int *kcod ) val = xi*xj + yi*yj + zi*zj ; /* dot product between i and j */ if( fabs(val) > 1.e-4 ){ xj -= val*xi ; yj -= val*yi ; zj -= val*zi ; - val = (float)sqrt( xj*xj + yj*yj + zj*zj ) ; /* must renormalize */ + val = static_cast(sqrt( xj*xj + yj*yj + zj*zj ) ); /* must renormalize */ if( val == 0.0 ) return ; /* j was parallel to i? */ xj /= val ; yj /= val ; zj /= val ; } /* normalize k axis; if it is zero, make it the cross product i x j */ - val = (float)sqrt( xk*xk + yk*yk + zk*zk ) ; + val = static_cast(sqrt( xk*xk + yk*yk + zk*zk ) ); if( val == 0.0 ){ xk = yi*zj-zi*yj; yk = zi*xj-zj*xi ; zk=xi*yj-yi*xj ; } else { xk /= val ; yk /= val ; zk /= val ; } @@ -2847,7 +2847,7 @@ void nifti_mat44_to_orientation( mat44 R , int *icod, int *jcod, int *kcod ) val = xi*xk + yi*yk + zi*zk ; /* dot product between i and k */ if( fabs(val) > 1.e-4 ){ xk -= val*xi ; yk -= val*yi ; zk -= val*zi ; - val = (float)sqrt( xk*xk + yk*yk + zk*zk ) ; + val = static_cast(sqrt( xk*xk + yk*yk + zk*zk ) ); if( val == 0.0 ) return ; /* bad */ xk /= val ; yk /= val ; zk /= val ; } @@ -2857,7 +2857,7 @@ void nifti_mat44_to_orientation( mat44 R , int *icod, int *jcod, int *kcod ) val = xj*xk + yj*yk + zj*zk ; /* dot product between j and k */ if( fabs(val) > 1.e-4 ){ xk -= val*xj ; yk -= val*yj ; zk -= val*zj ; - val = (float)sqrt( xk*xk + yk*yk + zk*zk ) ; + val = static_cast(sqrt( xk*xk + yk*yk + zk*zk ) ); if( val == 0.0 ) return ; /* bad */ xk /= val ; yk /= val ; zk /= val ; } @@ -2969,7 +2969,7 @@ void nifti_mat44_to_orientation( mat44 R , int *icod, int *jcod, int *kcod ) void nifti_swap_2bytes( int64_t n , void *ar ) /* 2 bytes at a time */ { int64_t ii ; - unsigned char * cp1 = (unsigned char *)ar, * cp2 ; + unsigned char * cp1 = static_cast(ar), * cp2 ; unsigned char tval; for( ii=0 ; ii < n ; ii++ ){ @@ -2986,7 +2986,7 @@ void nifti_swap_2bytes( int64_t n , void *ar ) /* 2 bytes at a time */ void nifti_swap_4bytes( int64_t n , void *ar ) /* 4 bytes at a time */ { int64_t ii ; - unsigned char * cp0 = (unsigned char *)ar, * cp1, * cp2 ; + unsigned char * cp0 = static_cast(ar), * cp1, * cp2 ; unsigned char tval ; for( ii=0 ; ii < n ; ii++ ){ @@ -3007,7 +3007,7 @@ void nifti_swap_4bytes( int64_t n , void *ar ) /* 4 bytes at a time */ void nifti_swap_8bytes( int64_t n , void *ar ) /* 8 bytes at a time */ { int64_t ii ; - unsigned char * cp0 = (unsigned char *)ar, * cp1, * cp2 ; + unsigned char * cp0 = static_cast(ar), * cp1, * cp2 ; unsigned char tval ; for( ii=0 ; ii < n ; ii++ ){ @@ -3028,7 +3028,7 @@ void nifti_swap_8bytes( int64_t n , void *ar ) /* 8 bytes at a time */ void nifti_swap_16bytes( int64_t n , void *ar ) /* 16 bytes at a time */ { int64_t ii ; - unsigned char * cp0 = (unsigned char *)ar, * cp1, * cp2 ; + unsigned char * cp0 = static_cast(ar), * cp1, * cp2 ; unsigned char tval ; for( ii=0 ; ii < n ; ii++ ){ @@ -3051,7 +3051,7 @@ void nifti_swap_16bytes( int64_t n , void *ar ) /* 16 bytes at a time */ void nifti_swap_bytes( int64_t n , int siz , void *ar ) { int64_t ii ; - unsigned char * cp0 = (unsigned char *)ar, * cp1, * cp2 ; + unsigned char * cp0 = static_cast(ar), * cp1, * cp2 ; unsigned char tval ; for( ii=0 ; ii < n ; ii++ ){ @@ -3096,8 +3096,8 @@ void swap_nifti_header( void * hdr , int ni_ver ) fprintf(stderr,"++ swapping NIFTI header via ni_ver %d\n", ni_ver); if ( ni_ver == 0 ) nifti_swap_as_analyze((nifti_analyze75 *)hdr); - else if( ni_ver == 1 ) nifti_swap_as_nifti1((nifti_1_header *)hdr); - else if( ni_ver == 2 ) nifti_swap_as_nifti2((nifti_2_header *)hdr); + else if( ni_ver == 1 ) nifti_swap_as_nifti1(static_cast(hdr)); + else if( ni_ver == 2 ) nifti_swap_as_nifti2(static_cast(hdr)); else if( ni_ver >= 0 && ni_ver <= 9 ) { fprintf(stderr,"** swap_nifti_header: not ready for version %d\n",ni_ver); } else { @@ -3354,7 +3354,7 @@ int64_t nifti_get_filesize( const char *pathname ) *//*--------------------------------------------------------------------*/ int64_t nifti_get_volsize(const nifti_image *nim) { - return (int64_t)nim->nbyper * nim->nvox ; /* total bytes */ + return static_cast(nim->nbyper )* nim->nvox ; /* total bytes */ } @@ -3494,7 +3494,7 @@ char * nifti_find_file_extension( const char * name ) if ( ! name ) return NULL; - len = (int)strlen(name); + len = static_cast(strlen(name)); if ( len < 4 ) return NULL; ext = name + len - 4; @@ -3510,7 +3510,7 @@ char * nifti_find_file_extension( const char * name ) ext); return NULL; } - else return (char *)ext; /* Cast away the constness of the input parameter */ + else return const_cast(ext); /* Cast away the constness of the input parameter */ } #ifdef HAVE_ZLIB @@ -3531,7 +3531,7 @@ char * nifti_find_file_extension( const char * name ) ext); return NULL; } - else return (char *)ext; /* Cast away the constness of the input parameter */ + else return const_cast(ext); /* Cast away the constness of the input parameter */ } #endif @@ -3552,7 +3552,7 @@ int nifti_is_gzfile(const char* fname) #ifdef HAVE_ZLIB { /* just so len doesn't generate compile warning */ int len; - len = (int)strlen(fname); + len = static_cast(strlen(fname)); if (len < 3) return 0; /* so we don't search before the name */ if (fileext_compare(fname + strlen(fname) - 3,".gz")==0) { return 1; } } @@ -3715,7 +3715,7 @@ char * nifti_findhdrname(const char* fname) make_uppercase(extzip); } - hdrname = (char *)calloc(sizeof(char),strlen(basename)+8); + hdrname = static_cast(calloc(sizeof(char),strlen(basename)+8)); if( !hdrname ){ fprintf(stderr,"** nifti_findhdrname: failed to alloc hdrname\n"); free(basename); @@ -3792,7 +3792,7 @@ char * nifti_findimgname(const char* fname , int nifti_type) if( !nifti_validfilename(fname) ) return NULL; basename = nifti_makebasename(fname); - imgname = (char *)calloc(sizeof(char),strlen(basename)+8); + imgname = static_cast(calloc(sizeof(char),strlen(basename)+8)); if( !imgname ){ fprintf(stderr,"** nifti_findimgname: failed to alloc imgname\n"); free(basename); @@ -3878,7 +3878,7 @@ char * nifti_makehdrname(const char * prefix, int nifti_type, int check, if( !nifti_validfilename(prefix) ) return NULL; /* add space for extension, optional ".gz", and null char */ - iname = (char *)calloc(sizeof(char),strlen(prefix)+8); + iname = static_cast(calloc(sizeof(char),strlen(prefix)+8)); if( !iname ){ fprintf(stderr,"** NIFTI small malloc failure!\n"); return NULL; @@ -3954,7 +3954,7 @@ char * nifti_makeimgname(const char * prefix, int nifti_type, int check, if( !nifti_validfilename(prefix) ) return NULL; /* add space for extension, optional ".gz", and null char */ - iname = (char *)calloc(sizeof(char),strlen(prefix)+8); + iname = static_cast(calloc(sizeof(char),strlen(prefix)+8)); if( !iname ){ fprintf(stderr,"** NIFTI: small malloc failure!\n"); return NULL; @@ -4023,7 +4023,7 @@ int nifti_set_filenames( nifti_image * nim, const char * prefix, int check, if( !nim || !prefix ){ fprintf(stderr,"** nifti_set_filenames, bad params %p, %p\n", - (void *)nim,prefix); + static_cast(nim),prefix); return -1; } @@ -4180,7 +4180,7 @@ static int fileext_compare(const char * test_ext, const char * known_ext) /* if here, strings are different but need to check upper-case */ - for(c = 0; c < len; c++ ) caps[c] = toupper((int) known_ext[c]); + for(c = 0; c < len; c++ ) caps[c] = toupper(static_cast(known_ext[c])); caps[c] = '\0'; return strcmp(test_ext, caps); @@ -4205,7 +4205,7 @@ static int fileext_n_compare(const char * test_ext, if( len > 7 ) return cmp; /* if here, strings are different but need to check upper-case */ - for(c = 0; c < len; c++ ) caps[c] = toupper((int) known_ext[c]); + for(c = 0; c < len; c++ ) caps[c] = toupper(static_cast(known_ext[c])); caps[c] = '\0'; return strncmp(test_ext, caps, maxlen); @@ -4220,8 +4220,8 @@ static int is_uppercase(const char * str) if( !str || !*str ) return 0; for(c = 0; c < strlen(str); c++ ) { - if( islower((int) str[c]) ) return 0; - if( !hasupper && isupper((int) str[c]) ) hasupper = 1; + if( islower(static_cast(str[c])) ) return 0; + if( !hasupper && isupper(static_cast(str[c])) ) hasupper = 1; } return hasupper; @@ -4236,8 +4236,8 @@ static int is_mixedcase(const char * str) if( !str || !*str ) return 0; for(c = 0; c < strlen(str); c++ ) { - if( !haslower && islower((int) str[c]) ) haslower = 1; - if( !hasupper && isupper((int) str[c]) ) hasupper = 1; + if( !haslower && islower(static_cast(str[c])) ) haslower = 1; + if( !hasupper && isupper(static_cast(str[c])) ) hasupper = 1; if( haslower && hasupper ) return 1; } @@ -4253,7 +4253,7 @@ static int make_uppercase(char * str) if( !str || !*str ) return 0; for(c = 0; c < strlen(str); c++ ) - if( islower((int) str[c]) ) str[c] = toupper((int) str[c]); + if( islower(static_cast(str[c])) ) str[c] = toupper(static_cast(str[c])); return 0; } @@ -4265,7 +4265,7 @@ static int make_lowercase(char * str) if( !str || !*str ) return 0; for(c = 0; c < strlen(str); c++ ) - if( isupper((int) str[c]) ) str[c] = tolower((int) str[c]); + if( isupper(static_cast(str[c])) ) str[c] = tolower(static_cast(str[c])); return 0; } @@ -4428,9 +4428,9 @@ int is_nifti_file( const char *hname ) /* read header, close file */ - ii = (int)znzread( &nhdr , 1 , sizeof(nhdr) , fp ) ; + ii = static_cast(znzread( &nhdr , 1 , sizeof(nhdr) , fp ) ); znzclose( fp ) ; - if( ii < (int) sizeof(nhdr) ) return -1 ; /* bad read? */ + if( ii < static_cast(sizeof(nhdr) )) return -1 ; /* bad read? */ /* check for NIFTI-ness */ @@ -4441,12 +4441,12 @@ int is_nifti_file( const char *hname ) /* check for ANALYZE-ness (sizeof_hdr field == 348) */ ii = nhdr.sizeof_hdr ; - if( ii == (int)sizeof(nhdr) ) return 0 ; /* matches */ + if( ii == static_cast(sizeof(nhdr) )) return 0 ; /* matches */ /* try byte-swapping header */ swap_4(ii) ; - if( ii == (int)sizeof(nhdr) ) return 0 ; /* matches */ + if( ii == static_cast(sizeof(nhdr) )) return 0 ; /* matches */ return -1 ; /* not good */ } @@ -4626,7 +4626,7 @@ int disp_nifti_2_header( const char * info, const nifti_2_header * hp ) fprintf(fp, " intent_code = %d\n", hp->intent_code); fprintf(fp, " intent_name = '%-.16s'\n", hp->intent_name); - fprintf(fp, " dim_info = 0x%02x\n",(unsigned char)hp->dim_info); + fprintf(fp, " dim_info = 0x%02x\n",static_cast(hp->dim_info)); fprintf(fp, " unused_str = 0x "); for ( c = 0; c < 15; c++ ) fprintf(fp," %02x", hp->unused_str[c]); fputc('\n', fp); @@ -4654,7 +4654,7 @@ nifti_image* nifti_convert_n1hdr2nim(nifti_1_header nhdr, const char * fname) int ni_ver , is_onefile ; nifti_image *nim; - nim = (nifti_image *)calloc( 1 , sizeof(nifti_image) ) ; + nim = static_cast(calloc( 1 , sizeof(nifti_image) ) ); if( !nim ) ERREX("failed to allocate nifti image"); /* be explicit with pointers */ @@ -4685,7 +4685,7 @@ nifti_image* nifti_convert_n1hdr2nim(nifti_1_header nhdr, const char * fname) * the qform_code will be zero, at which point you can check * analyze75_orient if you care to. */ - unsigned char c = *((char *)(&nhdr.qform_code)); + unsigned char c = *(reinterpret_cast(&nhdr.qform_code)); nim->analyze75_orient = (analyze_75_orient_code)c; } if( doswap ) { @@ -4907,10 +4907,10 @@ nifti_image* nifti_convert_n1hdr2nim(nifti_1_header nhdr, const char * fname) is_onefile = ni_ver && NIFTI_ONEFILE(nhdr) ; if( is_onefile ){ - ioff = (int)nhdr.vox_offset ; - if( ioff < (int) sizeof(nhdr) ) ioff = (int) sizeof(nhdr) ; + ioff = static_cast(nhdr.vox_offset ); + if( ioff < static_cast(sizeof(nhdr) )) ioff = static_cast(sizeof(nhdr) ); } else { - ioff = (int)nhdr.vox_offset ; + ioff = static_cast(nhdr.vox_offset ); } nim->iname_offset = ioff ; @@ -4946,7 +4946,7 @@ nifti_image* nifti_convert_n2hdr2nim(nifti_2_header nhdr, const char * fname) int ii, doswap, ni_ver, is_onefile; nifti_image *nim; - nim = (nifti_image *)calloc( 1 , sizeof(nifti_image) ) ; + nim = static_cast(calloc( 1 , sizeof(nifti_image) ) ); if( !nim ) ERREX("failed to allocate nifti image"); /* be explicit with pointers */ @@ -5173,8 +5173,8 @@ nifti_image* nifti_convert_n2hdr2nim(nifti_2_header nhdr, const char * fname) /**- set ioff from vox_offset (but at least sizeof(header)) */ nim->iname_offset = nhdr.vox_offset; - if( is_onefile && nhdr.vox_offset < (int64_t)sizeof(nhdr) ) - nim->iname_offset = (int64_t)sizeof(nhdr); + if( is_onefile && nhdr.vox_offset < static_cast(sizeof(nhdr) )) + nim->iname_offset = static_cast(sizeof(nhdr)); /**- deal with file names if set */ if (fname!=NULL) { @@ -5288,13 +5288,13 @@ nifti_1_header * nifti_read_n1_hdr(const char * hname, int *swapped, int check) } /* read the binary header */ - bytes = (int)znzread( &nhdr, 1, sizeof(nhdr), fp ); + bytes = static_cast(znzread( &nhdr, 1, sizeof(nhdr), fp )); znzclose( fp ); /* we are done with the file now */ - if( bytes < (int)sizeof(nhdr) ){ + if( bytes < static_cast(sizeof(nhdr) )){ if( g_opts.debug > 0 ){ LNI_FERR(fname,"bad binary header read for file", hname); - fprintf(stderr," - read %d of %d bytes\n",bytes, (int)sizeof(nhdr)); + fprintf(stderr," - read %d of %d bytes\n",bytes, static_cast(sizeof(nhdr))); } return NULL; } @@ -5322,7 +5322,7 @@ nifti_1_header * nifti_read_n1_hdr(const char * hname, int *swapped, int check) } /* all looks good, so allocate memory for and return the header */ - hptr = (nifti_1_header *)malloc(sizeof(nifti_1_header)); + hptr = static_cast(malloc(sizeof(nifti_1_header))); if( ! hptr ){ fprintf(stderr,"** nifti_read_hdr: failed to alloc nifti_1_header\n"); return NULL; @@ -5390,7 +5390,7 @@ nifti_2_header * nifti_read_n2_hdr(const char * hname, int * swapped, znzclose(fp) ; if( ! nim ) return NULL; - hptr = (nifti_2_header *)malloc(sizeof(nifti_2_header)); + hptr = static_cast(malloc(sizeof(nifti_2_header))); rv = nifti_convert_nim2n2hdr(nim, hptr); free(nim); @@ -5399,13 +5399,13 @@ nifti_2_header * nifti_read_n2_hdr(const char * hname, int * swapped, } /* read the binary header */ - bytes = (int)znzread( &nhdr, 1, sizeof(nhdr), fp ); + bytes = static_cast(znzread( &nhdr, 1, sizeof(nhdr), fp )); znzclose( fp ); /* we are done with the file now */ - if( bytes < (int)sizeof(nhdr) ){ + if( bytes < static_cast(sizeof(nhdr) )){ if( g_opts.debug > 0 ){ LNI_FERR(fname,"bad binary header read for N2 file", hname); - fprintf(stderr," - read %d of %d bytes\n",bytes, (int)sizeof(nhdr)); + fprintf(stderr," - read %d of %d bytes\n",bytes, static_cast(sizeof(nhdr))); } return NULL; } @@ -5425,7 +5425,7 @@ nifti_2_header * nifti_read_n2_hdr(const char * hname, int * swapped, } /* all looks good, so allocate memory for and return the header */ - hptr = (nifti_2_header *)malloc(sizeof(nifti_2_header)); + hptr = static_cast(malloc(sizeof(nifti_2_header))); if( ! hptr ){ fprintf(stderr,"** nifti2_read_hdr: failed to alloc nifti_2_header\n"); return NULL; @@ -5523,7 +5523,7 @@ int nifti_valid_header_size(int ni_ver, int whine) if( whine ) fprintf(stderr, "** warning: sizeof(nifti_1_header) = %d, expected %d\n", - (int)sizeof(nifti_1_header), size); + static_cast(sizeof(nifti_1_header)), size); errs++; } } @@ -5535,7 +5535,7 @@ int nifti_valid_header_size(int ni_ver, int whine) if( whine ) fprintf(stderr, "** warning: sizeof(nifti_2_header) = %d, expected %d\n", - (int)sizeof(nifti_2_header), size); + static_cast(sizeof(nifti_2_header)), size); errs++; } } @@ -5569,7 +5569,7 @@ int nifti_hdr2_looks_good(const nifti_2_header * hdr) if( !hdr ) { fprintf(stderr,"** NIFTI n2hdr: hdr is NULL\n"); return 0; } /* for now, just warn if the header sizes are not right */ - if( g_opts.debug > 0 ) (void)nifti_valid_header_size(0, 1); + if( g_opts.debug > 0 ) static_cast(nifti_valid_header_size(0, 1)); if( hdr->sizeof_hdr != sizeof(nifti_2_header) ) { if( g_opts.debug > 0 ) @@ -5733,12 +5733,12 @@ void * nifti_read_header( const char *hname, int *nver, int check ) } /**- next read into nifti_1_header and determine nifti type */ - ii = (int)znzread(&n1hdr, 1, h1size, fp); + ii = static_cast(znzread(&n1hdr, 1, h1size, fp)); - if( ii < (int)h1size ){ /* failure? */ + if( ii < static_cast(h1size )){ /* failure? */ if( g_opts.debug > 0 ){ LNI_FERR(fname,"bad binary header read for file", hfile); - fprintf(stderr," - read %d of %d bytes\n",ii, (int)h1size); + fprintf(stderr," - read %d of %d bytes\n",ii, static_cast(h1size)); } znzclose(fp) ; free(hfile); @@ -5760,8 +5760,8 @@ void * nifti_read_header( const char *hname, int *nver, int check ) memcpy(&n2hdr, &n1hdr, h1size); /* copy first part */ remain = h2size - h1size; posn = (char *)&n2hdr + h1size; - ii = (int)znzread(posn, 1, remain, fp); /* read remaining part */ - if( ii < (int)remain) { + ii = static_cast(znzread(posn, 1, remain, fp)); /* read remaining part */ + if( ii < static_cast(remain)) { LNI_FERR(fname,"short NIFTI-2 header read for file", hfile); znzclose(fp); free(hfile); return NULL; } @@ -5888,12 +5888,12 @@ nifti_image *nifti_image_read( const char *hname , int read_data ) h2size = sizeof(nifti_2_header); /**- next read into nifti_1_header and determine nifti type */ - ii = (int)znzread(&n1hdr, 1, h1size, fp); + ii = static_cast(znzread(&n1hdr, 1, h1size, fp)); - if( ii < (int)h1size ){ /* failure? */ + if( ii < static_cast(h1size )){ /* failure? */ if( g_opts.debug > 0 ){ LNI_FERR(fname,"bad binary header read for file", hfile); - fprintf(stderr," - read %d of %d bytes\n",ii, (int)h1size); + fprintf(stderr," - read %d of %d bytes\n",ii, static_cast(h1size)); } znzclose(fp) ; free(hfile); @@ -5915,8 +5915,8 @@ nifti_image *nifti_image_read( const char *hname , int read_data ) memcpy(&n2hdr, &n1hdr, h1size); /* copy first part */ remain = h2size - h1size; posn = (char *)&n2hdr + h1size; - ii = (int)znzread(posn, 1, remain, fp); /* read remaining part */ - if( ii < (int)remain) { + ii = static_cast(znzread(posn, 1, remain, fp)); /* read remaining part */ + if( ii < static_cast(remain)) { LNI_FERR(fname,"short NIFTI-2 header read for file", hfile); znzclose(fp); free(hfile); return NULL; } @@ -5955,7 +5955,7 @@ nifti_image *nifti_image_read( const char *hname , int read_data ) if ( ni_ver <= 1 ) remain -= h1size; else remain -= h2size; - (void)nifti_read_extensions(nim, fp, remain); + static_cast(nifti_read_extensions(nim, fp, remain)); znzclose( fp ) ; /* close the file */ free(hfile); @@ -6052,7 +6052,7 @@ static int has_ascii_header( znzFile fp ) if( znz_isnull(fp) ) return 0; - nread = (int)znzread( buf, 1, 12, fp ); + nread = static_cast(znzread( buf, 1, 12, fp )); buf[12] = '\0'; if( nread < 12 ) return -1; @@ -6091,7 +6091,7 @@ nifti_image * nifti_read_ascii_image(znzFile fp, const char *fname, int flen, fprintf(stderr,"-d %s: have ASCII NIFTI file of size %d\n",fname,slen); if( slen > 65530 ) slen = 65530 ; - sbuf = (char *)calloc(sizeof(char),slen+1) ; + sbuf = static_cast(calloc(sizeof(char),slen+1) ); if( !sbuf ){ fprintf(stderr,"** %s: failed to alloc %d bytes for sbuf",lfunc,65530); return NULL; @@ -6105,11 +6105,11 @@ nifti_image * nifti_read_ascii_image(znzFile fp, const char *fname, int flen, nim->nifti_type = NIFTI_FTYPE_ASCII ; /* compute remaining space for extensions */ - remain = flen - txt_size - (int)nifti_get_volsize(nim); + remain = flen - txt_size - static_cast(nifti_get_volsize(nim)); if( remain > 4 ){ /* read extensions (reposition file pointer, first) */ znzseek(fp, txt_size, SEEK_SET); - (void) nifti_read_extensions(nim, fp, (int64_t)remain); + static_cast(nifti_read_extensions(nim, fp, static_cast(remain))); } nim->iname_offset = -1 ; /* check from the end of the file */ @@ -6151,7 +6151,7 @@ static int nifti_read_extensions( nifti_image *nim, znzFile fp, int64_t remain ) if( !nim || znz_isnull(fp) ) { if( g_opts.debug > 0 ) fprintf(stderr,"** nifti_read_extensions: bad inputs (%p,%p)\n", - (void *)nim, (void *)fp); + static_cast(nim), static_cast(fp)); return -1; } @@ -6197,7 +6197,7 @@ static int nifti_read_extensions( nifti_image *nim, znzFile fp, int64_t remain ) Elist = NULL; while (nifti_read_next_extension(&extn, nim, remain, fp) > 0) { - if( nifti_add_exten_to_list(&extn, &Elist, (int)count+1) < 0 ){ + if( nifti_add_exten_to_list(&extn, &Elist, static_cast(count)+1) < 0 ){ free(Elist); if( g_opts.debug > 0 ) fprintf(stderr,"** NIFTI: failed adding ext to list\n"); @@ -6221,7 +6221,7 @@ static int nifti_read_extensions( nifti_image *nim, znzFile fp, int64_t remain ) if( g_opts.debug > 2 ) fprintf(stderr,"+d found extension(s)\n"); /* rcr n2 - allow int64_t num ext? */ - nim->num_ext = (int)count; + nim->num_ext = static_cast(count); nim->ext_list = Elist; return count; @@ -6279,7 +6279,7 @@ static int nifti_add_exten_to_list( nifti1_extension * new_ext, /* check for failure first */ if( ! *list ){ fprintf(stderr,"** NIFTI: failed to alloc %d ext structs (%d bytes)\n", - new_length, new_length*(int)sizeof(nifti1_extension)); + new_length, new_length*static_cast(sizeof(nifti1_extension))); if( !tmplist ) return -1; /* no old list to lose */ *list = tmplist; /* reset list to old one */ @@ -6319,7 +6319,7 @@ static int nifti_fill_extension( nifti1_extension *ext, const char * data, if( !ext || !data || len < 0 ){ fprintf(stderr,"** NIFTI fill_ext: bad params (%p,%p,%d)\n", - (void *)ext, (void *)data, len); + static_cast(ext), static_cast(data), len); return -1; } else if( ! nifti_is_valid_ecode(ecode) ){ fprintf(stderr,"** NIFTI fill_ext: invalid ecode %d\n", ecode); @@ -6332,7 +6332,7 @@ static int nifti_fill_extension( nifti1_extension *ext, const char * data, ext->esize = esize; /* allocate esize-8 (maybe more than len), using calloc for fill */ - ext->edata = (char *)calloc(esize-8, sizeof(char)); + ext->edata = static_cast(calloc(esize-8, sizeof(char))); if( !ext->edata ){ fprintf(stderr,"** NIFTI NFE: failed to alloc %d bytes for extension\n", len); @@ -6376,8 +6376,8 @@ static int nifti_read_next_extension( nifti1_extension * nex, nifti_image *nim, } /* must start with 4-byte size and code */ - count = (int)znzread( &size, 4, 1, fp ); - if( count == 1 ) count += (int)znzread( &code, 4, 1, fp ); + count = static_cast(znzread( &size, 4, 1, fp )); + if( count == 1 ) count += static_cast(znzread( &code, 4, 1, fp )); if( count != 2 || code == -1 ){ if( g_opts.debug > 2 ) @@ -6410,14 +6410,14 @@ static int nifti_read_next_extension( nifti1_extension * nex, nifti_image *nim, nex->ecode = code; size -= 8; /* subtract space for size and code in extension */ - nex->edata = (char *)malloc(size * sizeof(char)); + nex->edata = static_cast(malloc(size * sizeof(char))); if( !nex->edata ){ fprintf(stderr,"** NIFTI: failed to allocate %d bytes for extension\n", size); return -1; } - count = (int)znzread(nex->edata, 1, size, fp); + count = static_cast(znzread(nex->edata, 1, size, fp)); if( count < size ){ if( g_opts.debug > 0 ) fprintf(stderr,"-d read only %d (of %d) bytes for extension\n", @@ -6495,8 +6495,8 @@ int valid_nifti_extensions(const nifti_image * nim) \return -1 on error, else NIFTI version *//*--------------------------------------------------------------------*/ int nifti_header_version(const char * buf, size_t nbytes){ - nifti_1_header *n1p = (nifti_1_header *)buf; - nifti_2_header *n2p = (nifti_2_header *)buf; + nifti_1_header *n1p = reinterpret_cast(const_cast(buf)); + nifti_2_header *n2p = reinterpret_cast(const_cast(buf)); char fname[] = { "nifti_header_version" }; int sizeof_hdr, sver, nver; @@ -6515,12 +6515,12 @@ int nifti_header_version(const char * buf, size_t nbytes){ /* try to determine the version based on sizeof_hdr */ sver = -1; sizeof_hdr = n1p->sizeof_hdr; - if ( sizeof_hdr == (int)sizeof(nifti_1_header) ) sver = 1; - else if( sizeof_hdr == (int)sizeof(nifti_2_header) ) sver = 2; + if ( sizeof_hdr == static_cast(sizeof(nifti_1_header) )) sver = 1; + else if( sizeof_hdr == static_cast(sizeof(nifti_2_header) )) sver = 2; else { /* try swapping */ nifti_swap_4bytes(1, &sizeof_hdr); - if ( sizeof_hdr == (int)sizeof(nifti_1_header) ) sver = 1; - else if( sizeof_hdr == (int)sizeof(nifti_2_header) ) sver = 2; + if ( sizeof_hdr == static_cast(sizeof(nifti_1_header) )) sver = 1; + else if( sizeof_hdr == static_cast(sizeof(nifti_2_header) )) sver = 2; } /* and check magic field */ @@ -6681,7 +6681,7 @@ static znzFile nifti_image_load_prep( nifti_image *nim ) } /**- seek to the appropriate read position */ - if( znzseek(fp , (long)ioff , SEEK_SET) < 0 ){ + if( znzseek(fp , static_cast(ioff ), SEEK_SET) < 0 ){ fprintf(stderr,"** NIFTI: could not seek to offset in file \n"); znzclose(fp); return NULL; @@ -6731,11 +6731,11 @@ int nifti_image_load( nifti_image *nim ) if( nim->data == NULL ) { - nim->data = (void *)calloc(1,ntot) ; /* create image memory */ + nim->data = static_cast(calloc(1,ntot) ); /* create image memory */ if( nim->data == NULL ){ if( g_opts.debug > 0 ) fprintf(stderr,"** NIFTI: failed to alloc %d bytes for image data\n", - (int)ntot); + static_cast(ntot)); znzclose(fp); return -1; } @@ -6803,7 +6803,7 @@ int64_t nifti_read_buffer(znzFile fp, void* dataptr, int64_t ntot, if( nim->swapsize > 1 && nim->byteorder != nifti_short_order() ) { if( g_opts.debug > 1 ) fprintf(stderr,"+d nifti_read_buffer: swapping data bytes...\n"); - nifti_swap_Nbytes( (int)(ntot / nim->swapsize), nim->swapsize , dataptr ) ; + nifti_swap_Nbytes( static_cast((ntot / nim->swapsize)), nim->swapsize , dataptr ) ; } #ifdef isfiniteX /* Chris Rorden, 2020: disable isfinite to preserve NaN */ @@ -6815,7 +6815,7 @@ int64_t nifti_read_buffer(znzFile fp, void* dataptr, int64_t ntot, case NIFTI_TYPE_FLOAT32: case NIFTI_TYPE_COMPLEX64:{ - float *far = (float *)dataptr ; int64_t jj,nj ; + float *far = static_cast(dataptr ); int64_t jj,nj ; nj = ntot / sizeof(float) ; for( jj=0 ; jj < nj ; jj++ ) /* count fixes 30 Nov 2004 [rickr] */ if( !IS_GOOD_FLOAT(far[jj]) ){ @@ -6827,7 +6827,7 @@ int64_t nifti_read_buffer(znzFile fp, void* dataptr, int64_t ntot, case NIFTI_TYPE_FLOAT64: case NIFTI_TYPE_COMPLEX128:{ - double *far = (double *)dataptr ; int64_t jj,nj ; + double *far = static_cast(dataptr ); int64_t jj,nj ; nj = ntot / sizeof(double) ; for( jj=0 ; jj < nj ; jj++ ) /* count fixes 30 Nov 2004 [rickr] */ if( !IS_GOOD_FLOAT(far[jj]) ){ @@ -6874,7 +6874,7 @@ void nifti_image_free( nifti_image *nim ) if( nim->fname != NULL ) free(nim->fname) ; if( nim->iname != NULL ) free(nim->iname) ; if( nim->data != NULL ) free(nim->data ) ; - (void)nifti_free_extensions( nim ) ; + static_cast(nifti_free_extensions( nim ) ); free(nim) ; return ; } @@ -6902,7 +6902,7 @@ int nifti_free_extensions( nifti_image *nim ) /* or if it is inconsistent, warn the user (if we are not in quiet mode) */ else if ( (nim->num_ext > 0 || nim->ext_list != NULL) && (g_opts.debug > 0) ) fprintf(stderr,"** warning: nifti extension num/ptr mismatch (%d,%p)\n", - nim->num_ext, (void *)nim->ext_list); + nim->num_ext, static_cast(nim->ext_list)); if( g_opts.debug > 2 ) fprintf(stderr,"+d free'd %d extension(s)\n", nim->num_ext); @@ -6945,7 +6945,7 @@ int64_t nifti_write_buffer(znzFile fp, const void *buffer, int64_t numbytes) fprintf(stderr,"** ERROR: nifti_write_buffer: null file pointer\n"); return 0; } - ss = znzwrite( (const void*)buffer , 1 , numbytes , fp ) ; + ss = znzwrite( static_cast(buffer ), 1 , numbytes , fp ) ; return ss; } @@ -7046,14 +7046,14 @@ static int nifti_write_extensions(znzFile fp, nifti_image *nim) list = nim->ext_list; for ( c = 0; c < nim->num_ext; c++ ){ - size = (int)nifti_write_buffer(fp, &list->esize, sizeof(int)); - ok = (size == (int)sizeof(int)); + size = static_cast(nifti_write_buffer(fp, &list->esize, sizeof(int))); + ok = (size == static_cast(sizeof(int))); if( ok ){ - size = (int)nifti_write_buffer(fp, &list->ecode, sizeof(int)); - ok = (size == (int)sizeof(int)); + size = static_cast(nifti_write_buffer(fp, &list->ecode, sizeof(int))); + ok = (size == static_cast(sizeof(int))); } if( ok ){ - size = (int)nifti_write_buffer(fp, list->edata, list->esize - 8); + size = static_cast(nifti_write_buffer(fp, list->edata, list->esize - 8)); ok = (size == list->esize - 8); } @@ -7158,7 +7158,7 @@ nifti_2_header * nifti_make_new_n2_header(const int64_t arg_dims[], if( g_opts.debug > 1 ) fprintf(stderr,"+d make_new_n2_header, dim[0] = , datatype = %d\n", dtype); - nhdr = (nifti_2_header *)calloc(1,sizeof(nifti_2_header)); + nhdr = static_cast(calloc(1,sizeof(nifti_2_header))); if( !nhdr ){ fprintf(stderr,"** NIFTI make_new_n2_header: failed to alloc hdr\n"); return NULL; @@ -7235,7 +7235,7 @@ nifti_1_header * nifti_make_new_n1_header(const int64_t arg_dims[], if( g_opts.debug > 1 ) fprintf(stderr,"+d make_new_n1_header, dim[0] = , datatype = %d\n",dtype); - nhdr = (nifti_1_header *)calloc(1,sizeof(nifti_1_header)); + nhdr = static_cast(calloc(1,sizeof(nifti_1_header))); if( !nhdr ){ fprintf(stderr,"** NIFTI make_new_n1_header: failed to alloc hdr\n"); return NULL; @@ -7245,11 +7245,11 @@ nifti_1_header * nifti_make_new_n1_header(const int64_t arg_dims[], nhdr->regular = 'r' ; /* for some stupid reason */ /* init dim and pixdim */ - nhdr->dim[0] = (int)dim[0]; /* rcr n2 - check dim sizes for nifti-1 */ + nhdr->dim[0] = static_cast(dim[0]); /* rcr n2 - check dim sizes for nifti-1 */ /* (verify vals are < 2^15) */ nhdr->pixdim[0] = 0.0f; for( c = 1; c <= dim[0]; c++ ) { - nhdr->dim[c] = (int)dim[c]; + nhdr->dim[c] = static_cast(dim[c]); nhdr->pixdim[c] = 1.0f; } @@ -7389,13 +7389,13 @@ int nifti_convert_nim2n1hdr(const nifti_image * nim, nifti_1_header * hdr) if( nim->nifti_type == NIFTI_FTYPE_NIFTI1_1 ) strcpy(nhdr.magic,"n+1") ; else strcpy(nhdr.magic,"ni1") ; - nhdr.pixdim[1] = (float)fabs(nhdr.pixdim[1]) ; - nhdr.pixdim[2] = (float)fabs(nhdr.pixdim[2]) ; - nhdr.pixdim[3] = (float)fabs(nhdr.pixdim[3]) ; - nhdr.pixdim[4] = (float)fabs(nhdr.pixdim[4]) ; - nhdr.pixdim[5] = (float)fabs(nhdr.pixdim[5]) ; - nhdr.pixdim[6] = (float)fabs(nhdr.pixdim[6]) ; - nhdr.pixdim[7] = (float)fabs(nhdr.pixdim[7]) ; + nhdr.pixdim[1] = static_cast(fabs(nhdr.pixdim[1]) ); + nhdr.pixdim[2] = static_cast(fabs(nhdr.pixdim[2]) ); + nhdr.pixdim[3] = static_cast(fabs(nhdr.pixdim[3]) ); + nhdr.pixdim[4] = static_cast(fabs(nhdr.pixdim[4]) ); + nhdr.pixdim[5] = static_cast(fabs(nhdr.pixdim[5]) ); + nhdr.pixdim[6] = static_cast(fabs(nhdr.pixdim[6]) ); + nhdr.pixdim[7] = static_cast(fabs(nhdr.pixdim[7]) ); N_CHECK_2BYTE_VAL(intent_code); N_CHECK_2BYTE_VAL(qform_code); @@ -7410,7 +7410,7 @@ int nifti_convert_nim2n1hdr(const nifti_image * nim, nifti_1_header * hdr) nhdr.intent_name[15] = '\0' ; } - nhdr.vox_offset = (float) nim->iname_offset ; + nhdr.vox_offset = static_cast(nim->iname_offset ); nhdr.xyzt_units = SPACE_TIME_TO_XYZT( nim->xyz_units, nim->time_units ) ; nhdr.toffset = nim->toffset ; @@ -7618,7 +7618,7 @@ int nifti_copy_extensions(nifti_image * nim_dest, const nifti_image * nim_src) fprintf(stderr,"+d dup'ing ext #%d of size %d (from size %d)\n", c, size, old_size); /* data length is size-8, as esize includes space for esize and ecode */ - data = (char *)calloc(size-8,sizeof(char)); /* maybe size > old */ + data = static_cast(calloc(size-8,sizeof(char))); /* maybe size > old */ if( !data ){ fprintf(stderr,"** NIFTI: failed to alloc %d bytes for extension\n", size); @@ -7767,7 +7767,7 @@ int doPigz2(nifti_image *nim, struct nifti_2_header nhdr, const nifti_brick_list #endif znzFile fp; - fp = (znzFile) calloc(1,sizeof(struct znzptr)); + fp = static_cast(calloc(1,sizeof(struct znzptr))); fp->zfptr = NULL; fp->withz = 0; fp->nzfptr = pigzPipe; @@ -7812,7 +7812,7 @@ int doPigz(nifti_image *nim, struct nifti_1_header nhdr, const nifti_brick_list #endif znzFile fp; - fp = (znzFile) calloc(1,sizeof(struct znzptr)); + fp = static_cast(calloc(1,sizeof(struct znzptr))); fp->zfptr = NULL; fp->withz = 0; fp->nzfptr = pigzPipe; @@ -7870,7 +7870,7 @@ znzFile nifti_image_write_hdr_img2(nifti_image *nim, int write_opts, znzFile fp=NULL; int64_t ss ; int write_data, leave_open; - int nver=1, hsize=(int)sizeof(nifti_1_header); /* 5 Aug 2015 */ + int nver=1, hsize=static_cast(sizeof(nifti_1_header)); /* 5 Aug 2015 */ char func[] = { "nifti_image_write_hdr_img2" }; write_data = write_opts & 1; /* just separate the bits now */ @@ -7913,7 +7913,7 @@ znzFile nifti_image_write_hdr_img2(nifti_image *nim, int write_opts, if( nifti_convert_nim2n2hdr(nim, &n2hdr) ) return NULL; //fprintf(stderr,"+d writing %s as NIFTI-2, instead...\n", nim->fname); nver = 2; - hsize = (int)sizeof(nifti_2_header); + hsize = static_cast(sizeof(nifti_2_header)); } else /*end*/ if( nifti_convert_nim2n1hdr(nim, &n1hdr) ) { @@ -7921,7 +7921,7 @@ znzFile nifti_image_write_hdr_img2(nifti_image *nim, int write_opts, if( nifti_convert_nim2n2hdr(nim, &n2hdr) ) return NULL; fprintf(stderr,"+d writing %s as NIFTI-2, instead...\n", nim->fname); nver = 2; /* we will write NIFTI-2 */ - hsize = (int)sizeof(nifti_2_header); + hsize = static_cast(sizeof(nifti_2_header)); } /* if writing to 2 files, make sure iname is set and different from fname */ if( nim->nifti_type != NIFTI_FTYPE_NIFTI1_1 ){ @@ -7980,7 +7980,7 @@ znzFile nifti_image_write_hdr_img2(nifti_image *nim, int write_opts, /* partial file exists, and errors have been printed, so ignore return */ if( nim->nifti_type != NIFTI_FTYPE_ANALYZE ) - (void)nifti_write_extensions(fp,nim); + static_cast(nifti_write_extensions(fp,nim)); /* if the header is all we want, we are done */ if( ! write_data && ! leave_open ){ @@ -8101,7 +8101,7 @@ void nifti_image_write_bricks( nifti_image *nim, const nifti_brick_list * NBL ) nifti_image * nifti_copy_nim_info(const nifti_image * src) { nifti_image *dest; - dest = (nifti_image *)calloc(1,sizeof(nifti_image)); + dest = static_cast(calloc(1,sizeof(nifti_image))); if( !dest ){ fprintf(stderr,"** NCNI: failed to alloc nifti_image\n"); return NULL; @@ -8112,7 +8112,7 @@ nifti_image * nifti_copy_nim_info(const nifti_image * src) dest->num_ext = 0; dest->ext_list = NULL; /* errors will be printed in NCE(), continue in either case */ - (void)nifti_copy_extensions(dest, src); + static_cast(nifti_copy_extensions(dest, src)); dest->data = NULL; @@ -8144,7 +8144,7 @@ static int unescape_string( char *str ) int ii,jj , nn,ll ; if( str == NULL ) return 0 ; /* no string? */ - ll = (int)strlen(str) ; if( ll == 0 ) return 0 ; + ll = static_cast(strlen(str) ); if( ll == 0 ) return 0 ; /* scan for escapes: &something; */ @@ -8188,23 +8188,23 @@ static int unescape_string( char *str ) else if( ii+3 < ll && str[ii+1] == '#' && - isdigit((int) str[ii+2]) ){ /* &#dec; */ + isdigit(static_cast(str[ii+2])) ){ /* &#dec; */ unsigned int val='?' ; int kk=ii+3 ; while( kk < ll && kk != ';' ) kk++ ; sscanf( str+ii+2 , "%u" , &val ) ; - str[jj] = (char) val ; ii = kk ; nn++ ; + str[jj] = static_cast(val ); ii = kk ; nn++ ; } else if( ii+4 < ll && str[ii+1] == '#' && str[ii+2] == 'x' && - isxdigit((int) str[ii+3]) ){ /* &#hex; */ + isxdigit(static_cast(str[ii+3])) ){ /* &#hex; */ unsigned int val='?' ; int kk=ii+4 ; while( kk < ll && kk != ';' ) kk++ ; sscanf( str+ii+3 , "%x" , &val ) ; - str[jj] = (char) val ; ii = kk ; nn++ ; + str[jj] = static_cast(val ); ii = kk ; nn++ ; } /* didn't start a recognized escape, so just copy as normal */ @@ -8241,7 +8241,7 @@ static char *escapize_string( const char * str ) int ii,jj , lstr,lout ; char *out ; - if( str == NULL || (lstr=(int)strlen(str)) == 0 ){ /* 0 length */ + if( str == NULL || (lstr=static_cast(strlen(str))) == 0 ){ /* 0 length */ out = nifti_strdup("''") ; return out ; /* string?? */ } @@ -8263,7 +8263,7 @@ static char *escapize_string( const char * str ) default: lout++ ; break ; /* copy all other chars */ } } - out = (char *)calloc(1,lout) ; /* allocate output string */ + out = static_cast(calloc(1,lout) ); /* allocate output string */ if( !out ){ fprintf(stderr,"** NIFTI escapize_string: failed to alloc %d bytes\n", lout); @@ -8308,7 +8308,7 @@ char *nifti_image_to_ascii( const nifti_image *nim ) if( g_opts.debug > 2 ) fprintf(stderr,"+d converting %s to ASCII\n",nim->fname); - buf = (char *)calloc(1,65534); /* longer than needed, to be safe */ + buf = static_cast(calloc(1,65534)); /* longer than needed, to be safe */ if( !buf ){ fprintf(stderr,"** NIFTI NITA: failed to alloc %d bytes\n",65534); return NULL; @@ -8534,8 +8534,8 @@ char *nifti_image_to_ascii( const nifti_image *nim ) snprintf( buf+strlen(buf) , 16+strlen(buf), "/>\n" ) ; /* XML-ish closer */ - nbuf = (int)strlen(buf) ; - buf = (char *)realloc((void *)buf, nbuf+1); /* cut back to proper length */ + nbuf = static_cast(strlen(buf) ); + buf = static_cast(realloc(static_cast(buf), nbuf+1)); /* cut back to proper length */ if( !buf ) fprintf(stderr,"** NIFTI NITA: failed to realloc %d bytes\n", nbuf+1); return buf ; @@ -8605,7 +8605,7 @@ nifti_image *nifti_image_from_ascii( const char *str, int * bytes_read ) /* create empty image struct */ - nim = (nifti_image *)calloc( 1 , sizeof(nifti_image) ) ; + nim = static_cast(calloc( 1 , sizeof(nifti_image) ) ); if( !nim ){ fprintf(stderr,"** NIFA: failed to alloc nifti_image\n"); return NULL; @@ -8625,7 +8625,7 @@ nifti_image *nifti_image_from_ascii( const char *str, int * bytes_read ) while(1){ - while( isspace((int) str[spos]) ) spos++ ; /* skip whitespace */ + while( isspace(static_cast(str[spos])) ) spos++ ; /* skip whitespace */ if( str[spos] == '\0' ) break ; /* end of string? */ /* get lhs string */ @@ -8635,7 +8635,7 @@ nifti_image *nifti_image_from_ascii( const char *str, int * bytes_read ) /* skip whitespace and the '=' marker */ - while( isspace((int) str[spos]) || str[spos] == '=' ) spos++ ; + while( isspace(static_cast(str[spos])) || str[spos] == '=' ) spos++ ; if( str[spos] == '\0' ) break ; /* end of string? */ /* if next character is a quote ', copy everything up to next ' @@ -8756,7 +8756,7 @@ nifti_image *nifti_image_from_ascii( const char *str, int * bytes_read ) nim->dim[6] = nim->nv ; nim->pixdim[6] = nim->dv ; nim->dim[7] = nim->nw ; nim->pixdim[7] = nim->dw ; - nim->nvox = (int64_t)nim->nx * nim->ny * nim->nz + nim->nvox = static_cast(nim->nx )* nim->ny * nim->nz * nim->nt * nim->nu * nim->nv * nim->nw ; if( nim->qform_code > 0 ) @@ -8975,7 +8975,7 @@ int64_t nifti_read_collapsed_image( nifti_image * nim, const int64_t dims [8], /** - check pointers for sanity */ if( !nim || !dims || !data ){ fprintf(stderr,"** nifti_RCI: bad params %p, %p, %p\n", - (void *)nim, (const void *)dims, (void *)data); + static_cast(nim), static_cast(dims), static_cast(data)); return -1; } @@ -9013,7 +9013,7 @@ int64_t nifti_read_collapsed_image( nifti_image * nim, const int64_t dims [8], /** - call the recursive reading function, passing nim, the pivot info, location to store memory, and file pointer and position */ - c = rci_read_data(nim, pivots, prods, nprods, dims, (char *)*data, fp, + c = rci_read_data(nim, pivots, prods, nprods, dims, static_cast(*data), fp, znztell(fp)); znzclose(fp); /* in any case, close the file */ if( c < 0 ){ free(*data); *data = NULL; return -1; } /* failure */ @@ -9139,7 +9139,7 @@ int64_t nifti_read_subregion_image( nifti_image * nim, for(i = 0; i < nim->ndim; i++) total_alloc_size *= region_size[i]; /* allocate buffer, if necessary */ - if(! *data) *data = (void *)malloc(total_alloc_size); + if(! *data) *data = static_cast(malloc(total_alloc_size)); if(! *data) { if(g_opts.debug > 1) @@ -9258,8 +9258,8 @@ static int rci_read_data(nifti_image * nim, int * pivots, int64_t * prods, /* offset is (c * sub-block size (including pivot dim)) */ /* + (dims[] index into pivot sub-block) */ /* the unneeded multiplication is to make this more clear */ - offset = (int64_t)c * sublen * nim->dim[*pivots] + - (int64_t)sublen * dims[*pivots]; + offset = static_cast(c )* sublen * nim->dim[*pivots] + + static_cast(sublen )* dims[*pivots]; offset *= nim->nbyper; if( g_opts.debug > 3 ) @@ -9404,7 +9404,7 @@ int64_t * nifti_get_int64list( int64_t nvals , const char * str ) if( str == NULL || str[0] == '\0' ) return NULL ; /* skip initial '[' or '{' */ - subv = (int64_t *)malloc( sizeof(int64_t) * 2 ) ; + subv = static_cast(malloc( sizeof(int64_t) * 2 ) ); if( !subv ) { fprintf(stderr,"** nifti_get_intlist: failed alloc of 2 ints\n"); return NULL; @@ -9419,10 +9419,10 @@ int64_t * nifti_get_int64list( int64_t nvals , const char * str ) /**- for each sub-selector until end of input... */ - slen = (int)strlen(str) ; + slen = static_cast(strlen(str) ); while( ipos < slen && !ISEND(str[ipos]) ){ - while( isspace((int) str[ipos]) ) ipos++ ; /* skip blanks */ + while( isspace(static_cast(str[ipos])) ) ipos++ ; /* skip blanks */ if( ISEND(str[ipos]) ) break ; /* done */ /**- get starting value */ @@ -9447,13 +9447,13 @@ int64_t * nifti_get_int64list( int64_t nvals , const char * str ) ipos += nused ; } - while( isspace((int) str[ipos]) ) ipos++ ; /* skip blanks */ + while( isspace(static_cast(str[ipos])) ) ipos++ ; /* skip blanks */ /**- if that's it for this sub-selector, add one value to list */ if( str[ipos] == ',' || ISEND(str[ipos]) ){ nout++ ; - subv_realloc = (int64_t *)realloc( (char *)subv , sizeof(int64_t)*(nout+1) ) ; + subv_realloc = static_cast(realloc( reinterpret_cast(subv), sizeof(int64_t)*(nout+1) ) ); if( !subv_realloc ) { free(subv); fprintf(stderr,"** nifti_get_intlist: failed realloc of ints\n"); @@ -9504,7 +9504,7 @@ int64_t * nifti_get_int64list( int64_t nvals , const char * str ) istep = (ibot <= itop) ? 1 : -1 ; - while( isspace((int) str[ipos]) ) ipos++ ; /* skip blanks */ + while( isspace(static_cast(str[ipos])) ) ipos++ ; /* skip blanks */ /**- check if we have a non-default loop step */ @@ -9527,7 +9527,7 @@ int64_t * nifti_get_int64list( int64_t nvals , const char * str ) for( ii=ibot ; (ii-itop)*istep <= 0 ; ii += istep ){ nout++ ; - subv_realloc = (int64_t *)realloc( (char *)subv , sizeof(int64_t)*(nout+1) ) ; + subv_realloc = static_cast(realloc( reinterpret_cast(subv), sizeof(int64_t)*(nout+1) ) ); if( !subv_realloc ) { free(subv); fprintf(stderr,"** nifti_get_intlist: failed realloc of ints\n"); @@ -9540,7 +9540,7 @@ int64_t * nifti_get_int64list( int64_t nvals , const char * str ) /**- check if we have a comma to skip over */ - while( isspace((int) str[ipos]) ) ipos++ ; /* skip blanks */ + while( isspace(static_cast(str[ipos])) ) ipos++ ; /* skip blanks */ if( str[ipos] == ',' ) ipos++ ; /* skip commas */ } /* end of loop through selector string */ @@ -9562,7 +9562,7 @@ int * nifti_get_intlist( int nvals , const char * str ) int *ilist=NULL; int64_t *i64list=NULL, nints, index; - i64list = nifti_get_int64list((int64_t)nvals, str); + i64list = nifti_get_int64list(static_cast(nvals), str); if( !i64list ) return NULL; /* check that the length is between 1 and INT_MAX */ @@ -9576,7 +9576,7 @@ int * nifti_get_intlist( int nvals , const char * str ) } /* have a valid result, copy as ints */ - ilist = (int *)malloc((nints+1) * sizeof(int)); + ilist = static_cast(malloc((nints+1) * sizeof(int))); if( !ilist ) { fprintf(stderr,"** nifti_get_intlist: failed to alloc ints\n"); free(i64list); @@ -9591,7 +9591,7 @@ int * nifti_get_intlist( int nvals , const char * str ) free(i64list); return NULL; } - ilist[index] = (int)i64list[index]; + ilist[index] = static_cast(i64list[index]); } free(i64list); diff --git a/src/nyx/io/nifti/znzlib.cpp b/src/nyx/io/nifti/znzlib.cpp index 922ac6223..46b913168 100644 --- a/src/nyx/io/nifti/znzlib.cpp +++ b/src/nyx/io/nifti/znzlib.cpp @@ -49,7 +49,7 @@ znzlib.c (zipped or non-zipped library) znzFile znzopen(const char *path, const char *mode, int use_compression) { znzFile file; - file = (znzFile) calloc(1,sizeof(struct znzptr)); + file = static_cast(calloc(1,sizeof(struct znzptr))); if( file == NULL ){ fprintf(stderr,"** ERROR: znzopen failed to alloc znzptr\n"); return NULL; @@ -86,7 +86,7 @@ znzFile znzopen(const char *path, const char *mode, int use_compression) znzFile znzdopen(int fd, const char *mode, int use_compression) { znzFile file; - file = (znzFile) calloc(1,sizeof(struct znzptr)); + file = static_cast(calloc(1,sizeof(struct znzptr))); if( file == NULL ){ fprintf(stderr,"** ERROR: znzdopen failed to alloc znzptr\n"); return NULL; @@ -133,7 +133,7 @@ int Xznzclose(znzFile * file) size_t znzread(void* buf, size_t size, size_t nmemb, znzFile file) { size_t remain = size*nmemb; - char * cbuf = (char *)buf; + char * cbuf = static_cast(buf); unsigned n2read; int nread; @@ -144,19 +144,19 @@ size_t znzread(void* buf, size_t size, size_t nmemb, znzFile file) (noted by M Hanke, example given by M Adler) 6 July 2010 [rickr] */ while( remain > 0 ) { n2read = (remain < ZNZ_MAX_BLOCK_SIZE) ? remain : ZNZ_MAX_BLOCK_SIZE; - nread = gzread(file->zfptr, (void *)cbuf, n2read); + nread = gzread(file->zfptr, static_cast(cbuf), n2read); if( nread < 0 ) return nread; /* returns -1 on error */ remain -= nread; cbuf += nread; /* require reading n2read bytes, so we don't get stuck */ - if( nread < (int)n2read ) break; /* return will be short */ + if( nread < static_cast(n2read )) break; /* return will be short */ } /* warn of a short read that will seem complete */ if( remain > 0 && remain < size ) - fprintf(stderr,"** znzread: read short by %u bytes\n",(unsigned)remain); + fprintf(stderr,"** znzread: read short by %u bytes\n",static_cast(remain)); return nmemb - remain/size; /* return number of members processed */ } @@ -167,7 +167,7 @@ size_t znzread(void* buf, size_t size, size_t nmemb, znzFile file) size_t znzwrite(const void* buf, size_t size, size_t nmemb, znzFile file) { size_t remain = size*nmemb; - const char * cbuf = (const char *)buf; + const char * cbuf = static_cast(buf); unsigned n2write; int nwritten; @@ -176,7 +176,7 @@ size_t znzwrite(const void* buf, size_t size, size_t nmemb, znzFile file) if (file->zfptr!=NULL) { while( remain > 0 ) { n2write = (remain < ZNZ_MAX_BLOCK_SIZE) ? remain : ZNZ_MAX_BLOCK_SIZE; - nwritten = gzwrite(file->zfptr, (const void *)cbuf, n2write); + nwritten = gzwrite(file->zfptr, static_cast(cbuf), n2write); /* gzread returns 0 on error, but in case that ever changes... */ if( nwritten < 0 ) return nwritten; @@ -185,12 +185,12 @@ size_t znzwrite(const void* buf, size_t size, size_t nmemb, znzFile file) cbuf += nwritten; /* require writing n2write bytes, so we don't get stuck */ - if( nwritten < (int)n2write ) break; + if( nwritten < static_cast(n2write )) break; } /* warn of a short write that will seem complete */ if( remain > 0 && remain < size ) - fprintf(stderr,"** znzwrite: write short by %u bytes\n",(unsigned)remain); + fprintf(stderr,"** znzwrite: write short by %u bytes\n",static_cast(remain)); return nmemb - remain/size; /* return number of members processed */ } @@ -202,7 +202,7 @@ long znzseek(znzFile file, long offset, int whence) { if (file==NULL) { return 0; } #ifdef HAVE_ZLIB - if (file->zfptr!=NULL) return (long) gzseek(file->zfptr,offset,whence); + if (file->zfptr!=NULL) return static_cast(gzseek(file->zfptr,offset,whence)); #endif return fseek(file->nzfptr,offset,whence); } @@ -217,7 +217,7 @@ int znzrewind(znzFile stream) if (stream->zfptr!=NULL) return gzrewind(stream->zfptr); */ - if (stream->zfptr!=NULL) return (int)gzseek(stream->zfptr, 0L, SEEK_SET); + if (stream->zfptr!=NULL) return static_cast(gzseek(stream->zfptr, 0L, SEEK_SET)); #endif rewind(stream->nzfptr); return 0; @@ -227,7 +227,7 @@ long znztell(znzFile file) { if (file==NULL) { return 0; } #ifdef HAVE_ZLIB - if (file->zfptr!=NULL) return (long) gztell(file->zfptr); + if (file->zfptr!=NULL) return static_cast(gztell(file->zfptr)); #endif return ftell(file->nzfptr); } @@ -303,7 +303,7 @@ int znzprintf(znzFile stream, const char *format, ...) if (stream->zfptr!=NULL) { int size; /* local to HAVE_ZLIB block */ size = strlen(format) + 1000000; /* overkill I hope */ - tmpstr = (char *)calloc(1, size); + tmpstr = static_cast(calloc(1, size)); if( tmpstr == NULL ){ fprintf(stderr,"** ERROR: znzprintf failed to alloc %d bytes\n", size); return retval; diff --git a/src/nyx/nyxus_dicom_loader.h b/src/nyx/nyxus_dicom_loader.h index d4cb9d43f..abee6e1f0 100644 --- a/src/nyx/nyxus_dicom_loader.h +++ b/src/nyx/nyxus_dicom_loader.h @@ -268,10 +268,10 @@ class NyxusGrayscaleDicomLoader : public AbstractTileLoader { // rescale stored -> true HU, then slope-1 offset by floor(global HU min); // negatives (below the offset base) clamp to 0 instead of wrapping. - double hu = rescaleSlope_ * (double)buffer[i] + rescaleIntercept_; + double hu = rescaleSlope_ * static_cast(buffer[i] )+ rescaleIntercept_; double y = hu - std::floor(fpmin_); if (y < 0.0) y = 0.0; - *(dest+i) = (DataType) std::llround(y); + *(dest+i) = static_cast(std::llround(y)); } else *(dest+i) = static_cast(buffer[i]); diff --git a/src/nyx/output_2_buffer.cpp b/src/nyx/output_2_buffer.cpp index 619aa6bf3..5d7be074f 100644 --- a/src/nyx/output_2_buffer.cpp +++ b/src/nyx/output_2_buffer.cpp @@ -57,8 +57,8 @@ namespace Nyxus // Parameterized feature // --GLCM family - bool glcmFeature = std::find(GLCMFeature::featureset.begin(), GLCMFeature::featureset.end(), (Feature2D)fc) != GLCMFeature::featureset.end(); - bool nonAngledGlcmFeature = std::find(GLCMFeature::nonAngledFeatures.begin(), GLCMFeature::nonAngledFeatures.end(), (Feature2D)fc) != GLCMFeature::nonAngledFeatures.end(); // prevent output of a non-angled feature in an angled way + bool glcmFeature = std::find(GLCMFeature::featureset.begin(), GLCMFeature::featureset.end(), static_cast(fc)) != GLCMFeature::featureset.end(); + bool nonAngledGlcmFeature = std::find(GLCMFeature::nonAngledFeatures.begin(), GLCMFeature::nonAngledFeatures.end(), static_cast(fc)) != GLCMFeature::nonAngledFeatures.end(); // prevent output of a non-angled feature in an angled way if (glcmFeature && nonAngledGlcmFeature == false) { // Populate with angles @@ -73,8 +73,8 @@ namespace Nyxus } // --GLRLM family - bool glrlmFeature = std::find(GLRLMFeature::featureset.begin(), GLRLMFeature::featureset.end(), (Feature2D)fc) != GLRLMFeature::featureset.end(); - bool nonAngledGlrlmFeature = std::find(GLRLMFeature::nonAngledFeatures.begin(), GLRLMFeature::nonAngledFeatures.end(), (Feature2D)fc) != GLRLMFeature::nonAngledFeatures.end(); // prevent output of a non-angled feature in an angled way + bool glrlmFeature = std::find(GLRLMFeature::featureset.begin(), GLRLMFeature::featureset.end(), static_cast(fc)) != GLRLMFeature::featureset.end(); + bool nonAngledGlrlmFeature = std::find(GLRLMFeature::nonAngledFeatures.begin(), GLRLMFeature::nonAngledFeatures.end(), static_cast(fc)) != GLRLMFeature::nonAngledFeatures.end(); // prevent output of a non-angled feature in an angled way if (glrlmFeature && nonAngledGlrlmFeature == false) { // Populate with angles @@ -89,7 +89,7 @@ namespace Nyxus } // --Gabor - if (fc == (int)Feature2D::GABOR) + if (fc == static_cast(Feature2D::GABOR)) { // Generate the feature value list for (auto i = 0; i < GaborFeature::f0_theta_pairs.size(); i++) @@ -102,7 +102,7 @@ namespace Nyxus continue; } - if (fc == (int)Feature2D::FRAC_AT_D) + if (fc == static_cast(Feature2D::FRAC_AT_D)) { // Generate the feature value list for (auto i = 0; i < RadialDistributionFeature::num_features_FracAtD; i++) @@ -115,7 +115,7 @@ namespace Nyxus continue; } - if (fc == (int)Feature2D::MEAN_FRAC) + if (fc == static_cast(Feature2D::MEAN_FRAC)) { // Generate the feature value list for (auto i = 0; i < RadialDistributionFeature::num_features_MeanFrac; i++) @@ -128,7 +128,7 @@ namespace Nyxus continue; } - if (fc == (int)Feature2D::RADIAL_CV) + if (fc == static_cast(Feature2D::RADIAL_CV)) { // Generate the feature value list for (auto i = 0; i < RadialDistributionFeature::num_features_RadialCV; i++) @@ -142,7 +142,7 @@ namespace Nyxus } // --Zernike family - if (fc == (int)Feature2D::ZERNIKE2D) + if (fc == static_cast(Feature2D::ZERNIKE2D)) { // Populate with indices for (int i = 0; i < ZernikeFeature::NUM_FEATURE_VALS; i++) @@ -156,7 +156,7 @@ namespace Nyxus } // --Intensity histogram: one column per bin (HISTOGRAM_BIN_0 .. _N-1) - if (fc == (int)Feature2D::HISTOGRAM) + if (fc == static_cast(Feature2D::HISTOGRAM)) { int nbins = env.get_coarse_gray_depth(); for (int i = 0; i < nbins; i++) @@ -194,8 +194,8 @@ namespace Nyxus // Parameterized feature // --GLCM family - bool glcmFeature = std::find(GLCMFeature::featureset.begin(), GLCMFeature::featureset.end(), (Feature2D)fc) != GLCMFeature::featureset.end(); - bool nonAngledGlcmFeature = std::find(GLCMFeature::nonAngledFeatures.begin(), GLCMFeature::nonAngledFeatures.end(), (Feature2D)fc) != GLCMFeature::nonAngledFeatures.end(); // prevent output of a non-angled feature in an angled way + bool glcmFeature = std::find(GLCMFeature::featureset.begin(), GLCMFeature::featureset.end(), static_cast(fc)) != GLCMFeature::featureset.end(); + bool nonAngledGlcmFeature = std::find(GLCMFeature::nonAngledFeatures.begin(), GLCMFeature::nonAngledFeatures.end(), static_cast(fc)) != GLCMFeature::nonAngledFeatures.end(); // prevent output of a non-angled feature in an angled way if (glcmFeature && nonAngledGlcmFeature == false) { // Mock angled values if they haven't been calculated for some error reason @@ -214,8 +214,8 @@ namespace Nyxus } // --GLRLM family - bool glrlmFeature = std::find(GLRLMFeature::featureset.begin(), GLRLMFeature::featureset.end(), (Feature2D)fc) != GLRLMFeature::featureset.end(); - bool nonAngledGlrlmFeature = std::find(GLRLMFeature::nonAngledFeatures.begin(), GLRLMFeature::nonAngledFeatures.end(), (Feature2D)fc) != GLRLMFeature::nonAngledFeatures.end(); // prevent output of a non-angled feature in an angled way + bool glrlmFeature = std::find(GLRLMFeature::featureset.begin(), GLRLMFeature::featureset.end(), static_cast(fc)) != GLRLMFeature::featureset.end(); + bool nonAngledGlrlmFeature = std::find(GLRLMFeature::nonAngledFeatures.begin(), GLRLMFeature::nonAngledFeatures.end(), static_cast(fc)) != GLRLMFeature::nonAngledFeatures.end(); // prevent output of a non-angled feature in an angled way if (glrlmFeature && nonAngledGlrlmFeature == false) { // Populate with angles @@ -229,7 +229,7 @@ namespace Nyxus } // --Gabor - if (fc == (int)Feature2D::GABOR) + if (fc == static_cast(Feature2D::GABOR)) { for (auto i = 0; i < GaborFeature::f0_theta_pairs.size(); i++) { @@ -240,7 +240,7 @@ namespace Nyxus } // --Zernike family - if (fc == (int)Feature2D::ZERNIKE2D) + if (fc == static_cast(Feature2D::ZERNIKE2D)) { for (int i = 0; i < ZernikeFeature::NUM_FEATURE_VALS; i++) { @@ -251,7 +251,7 @@ namespace Nyxus } // --Radial distribution features - if (fc == (int)Feature2D::FRAC_AT_D) + if (fc == static_cast(Feature2D::FRAC_AT_D)) { for (auto i = 0; i < RadialDistributionFeature::num_features_FracAtD; i++) { @@ -260,7 +260,7 @@ namespace Nyxus // Proceed with other features continue; } - if (fc == (int)Feature2D::MEAN_FRAC) + if (fc == static_cast(Feature2D::MEAN_FRAC)) { for (auto i = 0; i < RadialDistributionFeature::num_features_MeanFrac; i++) { @@ -269,7 +269,7 @@ namespace Nyxus // Proceed with other features continue; } - if (fc == (int)Feature2D::RADIAL_CV) + if (fc == static_cast(Feature2D::RADIAL_CV)) { for (auto i = 0; i < RadialDistributionFeature::num_features_RadialCV; i++) { @@ -280,10 +280,10 @@ namespace Nyxus } // --Intensity histogram (one value per bin); pad blank ROIs to bin count - if (fc == (int)Feature2D::HISTOGRAM) + if (fc == static_cast(Feature2D::HISTOGRAM)) { int nbins = env.get_coarse_gray_depth(); - if ((int)vv.size() < nbins) + if (static_cast(vv.size() )< nbins) vv.resize(nbins, 0.0); for (int i = 0; i < nbins; i++) rescache.add_numeric(Nyxus::force_finite_number(vv[i], env.resultOptions.noval())); @@ -326,8 +326,8 @@ namespace Nyxus // Parameterized feature // --GLCM family - bool glcmFeature = std::find(GLCMFeature::featureset.begin(), GLCMFeature::featureset.end(), (Feature2D)fc) != GLCMFeature::featureset.end(); - bool nonAngledGlcmFeature = std::find(GLCMFeature::nonAngledFeatures.begin(), GLCMFeature::nonAngledFeatures.end(), (Feature2D)fc) != GLCMFeature::nonAngledFeatures.end(); // prevent output of a non-angled feature in an angled way + bool glcmFeature = std::find(GLCMFeature::featureset.begin(), GLCMFeature::featureset.end(), static_cast(fc)) != GLCMFeature::featureset.end(); + bool nonAngledGlcmFeature = std::find(GLCMFeature::nonAngledFeatures.begin(), GLCMFeature::nonAngledFeatures.end(), static_cast(fc)) != GLCMFeature::nonAngledFeatures.end(); // prevent output of a non-angled feature in an angled way if (glcmFeature && nonAngledGlcmFeature == false) { // Populate with angles @@ -342,8 +342,8 @@ namespace Nyxus } // --GLRLM family - bool glrlmFeature = std::find(GLRLMFeature::featureset.begin(), GLRLMFeature::featureset.end(), (Feature2D)fc) != GLRLMFeature::featureset.end(); - bool nonAngledGlrlmFeature = std::find(GLRLMFeature::nonAngledFeatures.begin(), GLRLMFeature::nonAngledFeatures.end(), (Feature2D)fc) != GLRLMFeature::nonAngledFeatures.end(); // prevent output of a non-angled feature in an angled way + bool glrlmFeature = std::find(GLRLMFeature::featureset.begin(), GLRLMFeature::featureset.end(), static_cast(fc)) != GLRLMFeature::featureset.end(); + bool nonAngledGlrlmFeature = std::find(GLRLMFeature::nonAngledFeatures.begin(), GLRLMFeature::nonAngledFeatures.end(), static_cast(fc)) != GLRLMFeature::nonAngledFeatures.end(); // prevent output of a non-angled feature in an angled way if (glrlmFeature && nonAngledGlrlmFeature == false) { // Populate with angles @@ -358,7 +358,7 @@ namespace Nyxus } // --Gabor - if (fc == (int) Feature2D::GABOR) + if (fc == static_cast(Feature2D::GABOR)) { // Generate the feature value list for (auto i = 0; i < GaborFeature::f0_theta_pairs.size(); i++) @@ -371,7 +371,7 @@ namespace Nyxus continue; } - if (fc == (int) Feature2D::FRAC_AT_D) + if (fc == static_cast(Feature2D::FRAC_AT_D)) { // Generate the feature value list for (auto i = 0; i < RadialDistributionFeature::num_features_FracAtD; i++) @@ -384,7 +384,7 @@ namespace Nyxus continue; } - if (fc == (int) Feature2D::MEAN_FRAC) + if (fc == static_cast(Feature2D::MEAN_FRAC)) { // Generate the feature value list for (auto i = 0; i < RadialDistributionFeature::num_features_MeanFrac; i++) @@ -397,7 +397,7 @@ namespace Nyxus continue; } - if (fc == (int) Feature2D::RADIAL_CV) + if (fc == static_cast(Feature2D::RADIAL_CV)) { // Generate the feature value list for (auto i = 0; i < RadialDistributionFeature::num_features_RadialCV; i++) @@ -411,7 +411,7 @@ namespace Nyxus } // --Zernike family - if (fc == (int) Feature2D::ZERNIKE2D) + if (fc == static_cast(Feature2D::ZERNIKE2D)) { // Populate with indices for (int i = 0; i < ZernikeFeature::NUM_FEATURE_VALS; i++) @@ -425,7 +425,7 @@ namespace Nyxus } // --Intensity histogram: one column per bin (HISTOGRAM_BIN_0 .. _N-1) - if (fc == (int) Feature2D::HISTOGRAM) + if (fc == static_cast(Feature2D::HISTOGRAM)) { int nbins = env.get_coarse_gray_depth(); for (int i = 0; i < nbins; i++) @@ -475,8 +475,8 @@ namespace Nyxus // Parameterized feature // --GLCM family - bool glcmFeature = std::find(GLCMFeature::featureset.begin(), GLCMFeature::featureset.end(), (Feature2D)fc) != GLCMFeature::featureset.end(); - bool nonAngledGlcmFeature = std::find(GLCMFeature::nonAngledFeatures.begin(), GLCMFeature::nonAngledFeatures.end(), (Feature2D)fc) != GLCMFeature::nonAngledFeatures.end(); // prevent output of a non-angled feature in an angled way + bool glcmFeature = std::find(GLCMFeature::featureset.begin(), GLCMFeature::featureset.end(), static_cast(fc)) != GLCMFeature::featureset.end(); + bool nonAngledGlcmFeature = std::find(GLCMFeature::nonAngledFeatures.begin(), GLCMFeature::nonAngledFeatures.end(), static_cast(fc)) != GLCMFeature::nonAngledFeatures.end(); // prevent output of a non-angled feature in an angled way if (glcmFeature && nonAngledGlcmFeature == false) { // Mock angled values if they haven't been calculated for some error reason @@ -495,8 +495,8 @@ namespace Nyxus } // --GLRLM family - bool glrlmFeature = std::find(GLRLMFeature::featureset.begin(), GLRLMFeature::featureset.end(), (Feature2D)fc) != GLRLMFeature::featureset.end(); - bool nonAngledGlrlmFeature = std::find(GLRLMFeature::nonAngledFeatures.begin(), GLRLMFeature::nonAngledFeatures.end(), (Feature2D)fc) != GLRLMFeature::nonAngledFeatures.end(); // prevent output of a non-angled feature in an angled way + bool glrlmFeature = std::find(GLRLMFeature::featureset.begin(), GLRLMFeature::featureset.end(), static_cast(fc)) != GLRLMFeature::featureset.end(); + bool nonAngledGlrlmFeature = std::find(GLRLMFeature::nonAngledFeatures.begin(), GLRLMFeature::nonAngledFeatures.end(), static_cast(fc)) != GLRLMFeature::nonAngledFeatures.end(); // prevent output of a non-angled feature in an angled way if (glrlmFeature && nonAngledGlrlmFeature == false) { // Populate with angles @@ -510,7 +510,7 @@ namespace Nyxus } // --Gabor - if (fc == (int) Feature2D::GABOR) + if (fc == static_cast(Feature2D::GABOR)) { for (auto i = 0; i < GaborFeature::f0_theta_pairs.size(); i++) { @@ -521,7 +521,7 @@ namespace Nyxus } // --Zernike family - if (fc == (int) Feature2D::ZERNIKE2D) + if (fc == static_cast(Feature2D::ZERNIKE2D)) { for (int i = 0; i < ZernikeFeature::NUM_FEATURE_VALS; i++) { @@ -532,7 +532,7 @@ namespace Nyxus } // --Radial distribution features - if (fc == (int) Feature2D::FRAC_AT_D) + if (fc == static_cast(Feature2D::FRAC_AT_D)) { for (auto i = 0; i < RadialDistributionFeature::num_features_FracAtD; i++) { @@ -541,7 +541,7 @@ namespace Nyxus // Proceed with other features continue; } - if (fc == (int) Feature2D::MEAN_FRAC) + if (fc == static_cast(Feature2D::MEAN_FRAC)) { for (auto i = 0; i < RadialDistributionFeature::num_features_MeanFrac; i++) { @@ -550,7 +550,7 @@ namespace Nyxus // Proceed with other features continue; } - if (fc == (int) Feature2D::RADIAL_CV) + if (fc == static_cast(Feature2D::RADIAL_CV)) { for (auto i = 0; i < RadialDistributionFeature::num_features_RadialCV; i++) { @@ -561,10 +561,10 @@ namespace Nyxus } // --Intensity histogram (one value per bin); pad blank ROIs to bin count - if (fc == (int) Feature2D::HISTOGRAM) + if (fc == static_cast(Feature2D::HISTOGRAM)) { int nbins = env.get_coarse_gray_depth(); - if ((int)vv.size() < nbins) + if (static_cast(vv.size() )< nbins) vv.resize(nbins, 0.0); for (int i = 0; i < nbins; i++) rescache.add_numeric (Nyxus::force_finite_number(vv[i], env.resultOptions.noval())); diff --git a/src/nyx/output_2_csv.cpp b/src/nyx/output_2_csv.cpp index e282c4325..b13a160ab 100644 --- a/src/nyx/output_2_csv.cpp +++ b/src/nyx/output_2_csv.cpp @@ -96,8 +96,8 @@ namespace Nyxus // Parameterized feature // --GLCM family - bool glcmFeature = std::find(GLCMFeature::featureset.begin(), GLCMFeature::featureset.end(), (Feature2D)fc) != GLCMFeature::featureset.end(); - bool nonAngledGlcmFeature = std::find(GLCMFeature::nonAngledFeatures.begin(), GLCMFeature::nonAngledFeatures.end(), (Feature2D)fc) != GLCMFeature::nonAngledFeatures.end(); // prevent output of a non-angled feature in an angled way + bool glcmFeature = std::find(GLCMFeature::featureset.begin(), GLCMFeature::featureset.end(), static_cast(fc)) != GLCMFeature::featureset.end(); + bool nonAngledGlcmFeature = std::find(GLCMFeature::nonAngledFeatures.begin(), GLCMFeature::nonAngledFeatures.end(), static_cast(fc)) != GLCMFeature::nonAngledFeatures.end(); // prevent output of a non-angled feature in an angled way if (glcmFeature && nonAngledGlcmFeature == false) { // Populate with angles @@ -113,8 +113,8 @@ namespace Nyxus } // --GLRLM family - bool glrlmFeature = std::find(GLRLMFeature::featureset.begin(), GLRLMFeature::featureset.end(), (Feature2D)fc) != GLRLMFeature::featureset.end(); - bool nonAngledGlrlmFeature = std::find(GLRLMFeature::nonAngledFeatures.begin(), GLRLMFeature::nonAngledFeatures.end(), (Feature2D)fc) != GLRLMFeature::nonAngledFeatures.end(); // prevent output of a non-angled feature in an angled way + bool glrlmFeature = std::find(GLRLMFeature::featureset.begin(), GLRLMFeature::featureset.end(), static_cast(fc)) != GLRLMFeature::featureset.end(); + bool nonAngledGlrlmFeature = std::find(GLRLMFeature::nonAngledFeatures.begin(), GLRLMFeature::nonAngledFeatures.end(), static_cast(fc)) != GLRLMFeature::nonAngledFeatures.end(); // prevent output of a non-angled feature in an angled way if (glrlmFeature && nonAngledGlrlmFeature == false) { // Populate with angles @@ -127,7 +127,7 @@ namespace Nyxus } // --Gabor - if (fc == (int) Feature2D::GABOR) + if (fc == static_cast(Feature2D::GABOR)) { // Generate the feature value list for (auto i = 0; i < GaborFeature::f0_theta_pairs.size(); i++) @@ -137,7 +137,7 @@ namespace Nyxus continue; } - if (fc == (int) Feature2D::FRAC_AT_D) + if (fc == static_cast(Feature2D::FRAC_AT_D)) { // Generate the feature value list for (auto i = 0; i < RadialDistributionFeature::num_features_FracAtD; i++) @@ -147,7 +147,7 @@ namespace Nyxus continue; } - if (fc == (int) Feature2D::MEAN_FRAC) + if (fc == static_cast(Feature2D::MEAN_FRAC)) { // Generate the feature value list for (auto i = 0; i < RadialDistributionFeature::num_features_MeanFrac; i++) @@ -157,7 +157,7 @@ namespace Nyxus continue; } - if (fc == (int) Feature2D::RADIAL_CV) + if (fc == static_cast(Feature2D::RADIAL_CV)) { // Generate the feature value list for (auto i = 0; i < RadialDistributionFeature::num_features_RadialCV; i++) @@ -168,7 +168,7 @@ namespace Nyxus } // --Zernike features header - if (fc == (int) Feature2D::ZERNIKE2D) + if (fc == static_cast(Feature2D::ZERNIKE2D)) { // Populate with indices for (int i = 0; i < ZernikeFeature::NUM_FEATURE_VALS; i++) // i < ZernikeFeature::num_feature_values_calculated @@ -180,7 +180,7 @@ namespace Nyxus // --Intensity histogram: one column per bin (HISTOGRAM_BIN_0 .. _N-1). // Bin edges are reconstructable from MIN/MAX and the bin count. - if (fc == (int) Feature2D::HISTOGRAM) + if (fc == static_cast(Feature2D::HISTOGRAM)) { int nbins = env.get_coarse_gray_depth(); for (int i = 0; i < nbins; i++) @@ -302,15 +302,15 @@ namespace Nyxus // Parameterized feature // --GLCM family - bool glcmFeature = std::find(GLCMFeature::featureset.begin(), GLCMFeature::featureset.end(), (Feature2D)fc) != GLCMFeature::featureset.end(); - bool nonAngledGlcmFeature = std::find(GLCMFeature::nonAngledFeatures.begin(), GLCMFeature::nonAngledFeatures.end(), (Feature2D)fc) != GLCMFeature::nonAngledFeatures.end(); // prevent output of a non-angled feature in an angled way + bool glcmFeature = std::find(GLCMFeature::featureset.begin(), GLCMFeature::featureset.end(), static_cast(fc)) != GLCMFeature::featureset.end(); + bool nonAngledGlcmFeature = std::find(GLCMFeature::nonAngledFeatures.begin(), GLCMFeature::nonAngledFeatures.end(), static_cast(fc)) != GLCMFeature::nonAngledFeatures.end(); // prevent output of a non-angled feature in an angled way if (glcmFeature && nonAngledGlcmFeature == false) { // Mock angled values if they haven't been calculated for some error reason if (vv.size() < GLCMFeature::angles.size()) vv.resize(GLCMFeature::angles.size(), 0.0); // Output the sub-values - int nAng = (int)GLCMFeature::angles.size(); + int nAng = static_cast(GLCMFeature::angles.size()); for (int i = 0; i < nAng; i++) { double fv = Nyxus::force_finite_number(vv[i], env.resultOptions.noval()); // safe feature value (no NAN, no inf) @@ -322,8 +322,8 @@ namespace Nyxus } // --GLRLM family - bool glrlmFeature = std::find(GLRLMFeature::featureset.begin(), GLRLMFeature::featureset.end(), (Feature2D)fc) != GLRLMFeature::featureset.end(); - bool nonAngledGlrlmFeature = std::find(GLRLMFeature::nonAngledFeatures.begin(), GLRLMFeature::nonAngledFeatures.end(), (Feature2D)fc) != GLRLMFeature::nonAngledFeatures.end(); // prevent output of a non-angled feature in an angled way + bool glrlmFeature = std::find(GLRLMFeature::featureset.begin(), GLRLMFeature::featureset.end(), static_cast(fc)) != GLRLMFeature::featureset.end(); + bool nonAngledGlrlmFeature = std::find(GLRLMFeature::nonAngledFeatures.begin(), GLRLMFeature::nonAngledFeatures.end(), static_cast(fc)) != GLRLMFeature::nonAngledFeatures.end(); // prevent output of a non-angled feature in an angled way if (glrlmFeature && nonAngledGlrlmFeature == false) { // Populate with angles @@ -339,7 +339,7 @@ namespace Nyxus } // --Gabor - if (fc == (int)Feature2D::GABOR) + if (fc == static_cast(Feature2D::GABOR)) { for (auto i = 0; i < GaborFeature::f0_theta_pairs.size(); i++) { @@ -353,7 +353,7 @@ namespace Nyxus } // --Zernike feature values - if (fc == (int)Feature2D::ZERNIKE2D) + if (fc == static_cast(Feature2D::ZERNIKE2D)) { for (int i = 0; i < ZernikeFeature::NUM_FEATURE_VALS; i++) { @@ -367,7 +367,7 @@ namespace Nyxus } // --Radial distribution features - if (fc == (int)Feature2D::FRAC_AT_D) + if (fc == static_cast(Feature2D::FRAC_AT_D)) { for (auto i = 0; i < RadialDistributionFeature::num_features_FracAtD; i++) { @@ -378,7 +378,7 @@ namespace Nyxus // Proceed with other features continue; } - if (fc == (int)Feature2D::MEAN_FRAC) + if (fc == static_cast(Feature2D::MEAN_FRAC)) { for (auto i = 0; i < RadialDistributionFeature::num_features_MeanFrac; i++) { @@ -389,7 +389,7 @@ namespace Nyxus // Proceed with other features continue; } - if (fc == (int)Feature2D::RADIAL_CV) + if (fc == static_cast(Feature2D::RADIAL_CV)) { for (auto i = 0; i < RadialDistributionFeature::num_features_RadialCV; i++) { @@ -501,7 +501,7 @@ namespace Nyxus std::vector a (n_feats); std::fill(a.begin(), a.end(), 0.0); - double n_rois = (double) allres.size(); + double n_rois = static_cast(allres.size()); for (const auto& tup : allres) { // we ned to add Skipping blacklisted ROI @@ -580,15 +580,15 @@ namespace Nyxus // Parameterized feature // --GLCM family - bool glcmFeature = std::find(GLCMFeature::featureset.begin(), GLCMFeature::featureset.end(), (Feature2D)fc) != GLCMFeature::featureset.end(); - bool nonAngledGlcmFeature = std::find(GLCMFeature::nonAngledFeatures.begin(), GLCMFeature::nonAngledFeatures.end(), (Feature2D)fc) != GLCMFeature::nonAngledFeatures.end(); // prevent output of a non-angled feature in an angled way + bool glcmFeature = std::find(GLCMFeature::featureset.begin(), GLCMFeature::featureset.end(), static_cast(fc)) != GLCMFeature::featureset.end(); + bool nonAngledGlcmFeature = std::find(GLCMFeature::nonAngledFeatures.begin(), GLCMFeature::nonAngledFeatures.end(), static_cast(fc)) != GLCMFeature::nonAngledFeatures.end(); // prevent output of a non-angled feature in an angled way if (glcmFeature && nonAngledGlcmFeature == false) { // Mock angled values if they haven't been calculated for some error reason if (vv.size() < GLCMFeature::angles.size()) vv.resize(GLCMFeature::angles.size(), 0.0); // Output the sub-values - int nAng = (int) GLCMFeature::angles.size(); + int nAng = static_cast(GLCMFeature::angles.size()); for (int i = 0; i < nAng; i++) { double fv = Nyxus::force_finite_number(vv[i], env.resultOptions.noval()); // safe feature value (no NAN, no inf) @@ -605,8 +605,8 @@ namespace Nyxus } // --GLRLM family - bool glrlmFeature = std::find(GLRLMFeature::featureset.begin(), GLRLMFeature::featureset.end(), (Feature2D)fc) != GLRLMFeature::featureset.end(); - bool nonAngledGlrlmFeature = std::find(GLRLMFeature::nonAngledFeatures.begin(), GLRLMFeature::nonAngledFeatures.end(), (Feature2D)fc) != GLRLMFeature::nonAngledFeatures.end(); // prevent output of a non-angled feature in an angled way + bool glrlmFeature = std::find(GLRLMFeature::featureset.begin(), GLRLMFeature::featureset.end(), static_cast(fc)) != GLRLMFeature::featureset.end(); + bool nonAngledGlrlmFeature = std::find(GLRLMFeature::nonAngledFeatures.begin(), GLRLMFeature::nonAngledFeatures.end(), static_cast(fc)) != GLRLMFeature::nonAngledFeatures.end(); // prevent output of a non-angled feature in an angled way if (glrlmFeature && nonAngledGlrlmFeature == false) { // Populate with angles @@ -627,7 +627,7 @@ namespace Nyxus } // --Gabor - if (fc == (int) Feature2D::GABOR) + if (fc == static_cast(Feature2D::GABOR)) { for (auto i = 0; i < GaborFeature::f0_theta_pairs.size(); i++) { @@ -646,7 +646,7 @@ namespace Nyxus } // --Zernike feature values - if (fc == (int) Feature2D::ZERNIKE2D) + if (fc == static_cast(Feature2D::ZERNIKE2D)) { for (int i = 0; i < ZernikeFeature::NUM_FEATURE_VALS; i++) { @@ -665,11 +665,11 @@ namespace Nyxus } // --Intensity histogram values (one per bin) - if (fc == (int) Feature2D::HISTOGRAM) + if (fc == static_cast(Feature2D::HISTOGRAM)) { int nbins = env.get_coarse_gray_depth(); // Pad with zeros if the ROI produced no histogram (e.g. blank ROI) - if ((int)vv.size() < nbins) + if (static_cast(vv.size() )< nbins) vv.resize(nbins, 0.0); for (int i = 0; i < nbins; i++) { @@ -687,7 +687,7 @@ namespace Nyxus } // --Radial distribution features - if (fc == (int) Feature2D::FRAC_AT_D) + if (fc == static_cast(Feature2D::FRAC_AT_D)) { for (auto i = 0; i < RadialDistributionFeature::num_features_FracAtD; i++) { @@ -703,7 +703,7 @@ namespace Nyxus // Proceed with other features continue; } - if (fc == (int) Feature2D::MEAN_FRAC) + if (fc == static_cast(Feature2D::MEAN_FRAC)) { for (auto i = 0; i < RadialDistributionFeature::num_features_MeanFrac; i++) { @@ -719,7 +719,7 @@ namespace Nyxus // Proceed with other features continue; } - if (fc == (int) Feature2D::RADIAL_CV) + if (fc == static_cast(Feature2D::RADIAL_CV)) { for (auto i = 0; i < RadialDistributionFeature::num_features_RadialCV; i++) { @@ -778,15 +778,15 @@ namespace Nyxus // Parameterized feature // --GLCM family - bool glcmFeature = std::find(GLCMFeature::featureset.begin(), GLCMFeature::featureset.end(), (Feature2D)fc) != GLCMFeature::featureset.end(); - bool nonAngledGlcmFeature = std::find(GLCMFeature::nonAngledFeatures.begin(), GLCMFeature::nonAngledFeatures.end(), (Feature2D)fc) != GLCMFeature::nonAngledFeatures.end(); // prevent output of a non-angled feature in an angled way + bool glcmFeature = std::find(GLCMFeature::featureset.begin(), GLCMFeature::featureset.end(), static_cast(fc)) != GLCMFeature::featureset.end(); + bool nonAngledGlcmFeature = std::find(GLCMFeature::nonAngledFeatures.begin(), GLCMFeature::nonAngledFeatures.end(), static_cast(fc)) != GLCMFeature::nonAngledFeatures.end(); // prevent output of a non-angled feature in an angled way if (glcmFeature && nonAngledGlcmFeature == false) { // Mock angled values if they haven't been calculated for some error reason if (vv.size() < GLCMFeature::angles.size()) vv.resize(GLCMFeature::angles.size(), 0.0); // Output the sub-values - int nAng = (int)GLCMFeature::angles.size(); + int nAng = static_cast(GLCMFeature::angles.size()); for (int i = 0; i < nAng; i++) { fvals.push_back(vv[i]); @@ -796,8 +796,8 @@ namespace Nyxus } // --GLRLM family - bool glrlmFeature = std::find(GLRLMFeature::featureset.begin(), GLRLMFeature::featureset.end(), (Feature2D)fc) != GLRLMFeature::featureset.end(); - bool nonAngledGlrlmFeature = std::find(GLRLMFeature::nonAngledFeatures.begin(), GLRLMFeature::nonAngledFeatures.end(), (Feature2D)fc) != GLRLMFeature::nonAngledFeatures.end(); // prevent output of a non-angled feature in an angled way + bool glrlmFeature = std::find(GLRLMFeature::featureset.begin(), GLRLMFeature::featureset.end(), static_cast(fc)) != GLRLMFeature::featureset.end(); + bool nonAngledGlrlmFeature = std::find(GLRLMFeature::nonAngledFeatures.begin(), GLRLMFeature::nonAngledFeatures.end(), static_cast(fc)) != GLRLMFeature::nonAngledFeatures.end(); // prevent output of a non-angled feature in an angled way if (glrlmFeature && nonAngledGlrlmFeature == false) { // Polulate with angles @@ -811,7 +811,7 @@ namespace Nyxus } // --Gabor - if (fc == (int)Feature2D::GABOR) + if (fc == static_cast(Feature2D::GABOR)) { for (auto i = 0; i < GaborFeature::f0_theta_pairs.size(); i++) { @@ -823,7 +823,7 @@ namespace Nyxus } // --Zernike feature values - if (fc == (int)Feature2D::ZERNIKE2D) + if (fc == static_cast(Feature2D::ZERNIKE2D)) { for (int i = 0; i < ZernikeFeature::NUM_FEATURE_VALS; i++) { @@ -835,7 +835,7 @@ namespace Nyxus } // --Radial distribution features - if (fc == (int)Feature2D::FRAC_AT_D) + if (fc == static_cast(Feature2D::FRAC_AT_D)) { for (auto i = 0; i < RadialDistributionFeature::num_features_FracAtD; i++) { @@ -844,7 +844,7 @@ namespace Nyxus // Proceed with other features continue; } - if (fc == (int)Feature2D::MEAN_FRAC) + if (fc == static_cast(Feature2D::MEAN_FRAC)) { for (auto i = 0; i < RadialDistributionFeature::num_features_MeanFrac; i++) { @@ -853,7 +853,7 @@ namespace Nyxus // Proceed with other features continue; } - if (fc == (int)Feature2D::RADIAL_CV) + if (fc == static_cast(Feature2D::RADIAL_CV)) { for (auto i = 0; i < RadialDistributionFeature::num_features_RadialCV; i++) { @@ -864,10 +864,10 @@ namespace Nyxus } // --Intensity histogram (one value per bin); pad blank ROIs to bin count - if (fc == (int)Feature2D::HISTOGRAM) + if (fc == static_cast(Feature2D::HISTOGRAM)) { int nbins = env.get_coarse_gray_depth(); - if ((int)vv.size() < nbins) + if (static_cast(vv.size() )< nbins) vv.resize(nbins, 0.0); for (int i = 0; i < nbins; i++) fvals.push_back(vv[i]); @@ -931,15 +931,15 @@ namespace Nyxus // Parameterized feature // --GLCM family - bool glcmFeature = std::find(GLCMFeature::featureset.begin(), GLCMFeature::featureset.end(), (Feature2D)fc) != GLCMFeature::featureset.end(); - bool nonAngledGlcmFeature = std::find(GLCMFeature::nonAngledFeatures.begin(), GLCMFeature::nonAngledFeatures.end(), (Feature2D)fc) != GLCMFeature::nonAngledFeatures.end(); // prevent output of a non-angled feature in an angled way + bool glcmFeature = std::find(GLCMFeature::featureset.begin(), GLCMFeature::featureset.end(), static_cast(fc)) != GLCMFeature::featureset.end(); + bool nonAngledGlcmFeature = std::find(GLCMFeature::nonAngledFeatures.begin(), GLCMFeature::nonAngledFeatures.end(), static_cast(fc)) != GLCMFeature::nonAngledFeatures.end(); // prevent output of a non-angled feature in an angled way if (glcmFeature && nonAngledGlcmFeature == false) { // Mock angled values if they haven't been calculated for some error reason if (vv.size() < GLCMFeature::angles.size()) vv.resize(GLCMFeature::angles.size(), 0.0); // Output the sub-values - int nAng = (int) GLCMFeature::angles.size(); + int nAng = static_cast(GLCMFeature::angles.size()); for (int i = 0; i < nAng; i++) { feature_values.push_back(vv[i]); @@ -949,8 +949,8 @@ namespace Nyxus } // --GLRLM family - bool glrlmFeature = std::find(GLRLMFeature::featureset.begin(), GLRLMFeature::featureset.end(), (Feature2D)fc) != GLRLMFeature::featureset.end(); - bool nonAngledGlrlmFeature = std::find(GLRLMFeature::nonAngledFeatures.begin(), GLRLMFeature::nonAngledFeatures.end(), (Feature2D)fc) != GLRLMFeature::nonAngledFeatures.end(); // prevent output of a non-angled feature in an angled way + bool glrlmFeature = std::find(GLRLMFeature::featureset.begin(), GLRLMFeature::featureset.end(), static_cast(fc)) != GLRLMFeature::featureset.end(); + bool nonAngledGlrlmFeature = std::find(GLRLMFeature::nonAngledFeatures.begin(), GLRLMFeature::nonAngledFeatures.end(), static_cast(fc)) != GLRLMFeature::nonAngledFeatures.end(); // prevent output of a non-angled feature in an angled way if (glrlmFeature && nonAngledGlrlmFeature == false) { // Polulate with angles @@ -964,7 +964,7 @@ namespace Nyxus } // --Gabor - if (fc == (int) Feature2D::GABOR) + if (fc == static_cast(Feature2D::GABOR)) { for (auto i = 0; i < GaborFeature::f0_theta_pairs.size(); i++) { @@ -976,7 +976,7 @@ namespace Nyxus } // --Zernike feature values - if (fc == (int) Feature2D::ZERNIKE2D) + if (fc == static_cast(Feature2D::ZERNIKE2D)) { for (int i = 0; i < ZernikeFeature::NUM_FEATURE_VALS; i++) { @@ -988,7 +988,7 @@ namespace Nyxus } // --Radial distribution features - if (fc == (int) Feature2D::FRAC_AT_D) + if (fc == static_cast(Feature2D::FRAC_AT_D)) { for (auto i = 0; i < RadialDistributionFeature::num_features_FracAtD; i++) { @@ -997,7 +997,7 @@ namespace Nyxus // Proceed with other features continue; } - if (fc == (int) Feature2D::MEAN_FRAC) + if (fc == static_cast(Feature2D::MEAN_FRAC)) { for (auto i = 0; i < RadialDistributionFeature::num_features_MeanFrac; i++) { @@ -1006,7 +1006,7 @@ namespace Nyxus // Proceed with other features continue; } - if (fc == (int) Feature2D::RADIAL_CV) + if (fc == static_cast(Feature2D::RADIAL_CV)) { for (auto i = 0; i < RadialDistributionFeature::num_features_RadialCV; i++) { @@ -1017,10 +1017,10 @@ namespace Nyxus } // --Intensity histogram (one value per bin); pad blank ROIs to bin count - if (fc == (int) Feature2D::HISTOGRAM) + if (fc == static_cast(Feature2D::HISTOGRAM)) { int nbins = env.get_coarse_gray_depth(); - if ((int)vv.size() < nbins) + if (static_cast(vv.size() )< nbins) vv.resize(nbins, 0.0); for (int i = 0; i < nbins; i++) feature_values.push_back(vv[i]); diff --git a/src/nyx/phase2_25d.cpp b/src/nyx/phase2_25d.cpp index fa06319ab..a7b7bc4ad 100644 --- a/src/nyx/phase2_25d.cpp +++ b/src/nyx/phase2_25d.cpp @@ -147,7 +147,7 @@ namespace Nyxus int lvl = 0, // pyramid level lyr = 0; // layer - size_t vD = (size_t)(double(z_indices.size()) * aniso_z); // virtual depth + size_t vD = static_cast((double(z_indices.size()) * aniso_z)); // virtual depth for (size_t vz = 0; vz < vD; vz++) { @@ -178,10 +178,10 @@ namespace Nyxus fullheight = env.theImLoader.get_full_height(); // virtual slide properties - size_t vh = (size_t)(double(fullheight) * aniso_y), - vw = (size_t)(double(fullwidth) * aniso_x), - vth = (size_t)(double(th) * aniso_y), - vtw = (size_t)(double(tw) * aniso_x); + size_t vh = static_cast((double(fullheight) * aniso_y)), + vw = static_cast((double(fullwidth) * aniso_x)), + vth = static_cast((double(th) * aniso_y)), + vtw = static_cast((double(tw) * aniso_x)); // current tile to skip tile reloads size_t curt_x = 999, curt_y = 999; diff --git a/src/nyx/phase2_2d.cpp b/src/nyx/phase2_2d.cpp index e49ff543f..c71c30fc5 100644 --- a/src/nyx/phase2_2d.cpp +++ b/src/nyx/phase2_2d.cpp @@ -207,10 +207,10 @@ namespace Nyxus fullheight = ldr.get_full_height(); // virtual slide properties - size_t vh = (size_t) (double(fullheight) * sf_y), - vw = (size_t) (double(fullwidth) * sf_x), - vth = (size_t)(double(th) * sf_y), - vtw = (size_t)(double(tw) * sf_x); + size_t vh = static_cast((double(fullheight) * sf_y)), + vw = static_cast((double(fullwidth) * sf_x)), + vth = static_cast((double(th) * sf_y)), + vtw = static_cast((double(tw) * sf_x)); // current tile to skip tile reloads size_t curt_x = 999, curt_y = 999; @@ -369,10 +369,10 @@ namespace Nyxus fullheight = ldr.get_full_height(); // virtual slide properties - size_t vh = (size_t)(double(fullheight) * aniso_y), - vw = (size_t)(double(fullwidth) * aniso_x), - vth = (size_t)(double(th) * aniso_y), - vtw = (size_t)(double(tw) * aniso_x); + size_t vh = static_cast((double(fullheight) * aniso_y)), + vw = static_cast((double(fullwidth) * aniso_x)), + vth = static_cast((double(th) * aniso_y)), + vtw = static_cast((double(tw) * aniso_x)); // current tile to skip tile reloads size_t curt_x = 999, curt_y = 999; diff --git a/src/nyx/phase2_3d.cpp b/src/nyx/phase2_3d.cpp index f081ebd0e..c2e52be95 100644 --- a/src/nyx/phase2_3d.cpp +++ b/src/nyx/phase2_3d.cpp @@ -192,17 +192,17 @@ namespace Nyxus fullH = env.theImLoader.get_full_height(), fullD = env.theImLoader.get_full_depth(); - size_t vD = (size_t)(double(fullD) * aniso_z); // virtual depth + size_t vD = static_cast((double(fullD) * aniso_z)); // virtual depth for (size_t vz = 0; vz < vD; vz++) { size_t z = size_t(double(vz) / aniso_z); // physical z // virtual slide properties - size_t vh = (size_t)(double(fullH) * aniso_y), - vw = (size_t)(double(fullW) * aniso_x), - vth = (size_t)(double(th) * aniso_y), - vtw = (size_t)(double(tw) * aniso_x); + size_t vh = static_cast((double(fullH) * aniso_y)), + vw = static_cast((double(fullW) * aniso_x)), + vth = static_cast((double(th) * aniso_y)), + vtw = static_cast((double(tw) * aniso_x)); // current tile to skip tile reloads size_t curt_x = 999, curt_y = 999; @@ -527,9 +527,9 @@ namespace Nyxus fullD = ilo.get_full_depth(), sliceSize = fullW * fullH; - size_t vh = (size_t) (double(fullH) * aniso_y), - vw = (size_t) (double(fullW) * aniso_x), - vd = (size_t) (double(fullD) * aniso_z); + size_t vh = static_cast((double(fullH) * aniso_y)), + vw = static_cast((double(fullW) * aniso_x)), + vd = static_cast((double(fullD) * aniso_z)); // in the 3D case tiling is a formality, so fetch the only tile in the file if (! ilo.load_tile(0, 0)) @@ -555,9 +555,9 @@ namespace Nyxus x = (i - z * vSliceSize) % vw; // physical voxel position - size_t ph_x = (size_t) (double(x) / aniso_x), - ph_y = (size_t) (double(y) / aniso_y), - ph_z = (size_t) (double(z) / aniso_z); + size_t ph_x = static_cast((double(x) / aniso_x)), + ph_y = static_cast((double(y) / aniso_y)), + ph_z = static_cast((double(z) / aniso_z)); i = ph_z * sliceSize + ph_y * fullH + ph_x; // Cache this pixel @@ -593,10 +593,10 @@ namespace Nyxus fullheight = ldr.get_full_height(); // virtual slide properties - size_t vh = (size_t)(double(fullheight) * aniso_y), - vw = (size_t)(double(fullwidth) * aniso_x), - vth = (size_t)(double(th) * aniso_y), - vtw = (size_t)(double(tw) * aniso_x); + size_t vh = static_cast((double(fullheight) * aniso_y)), + vw = static_cast((double(fullwidth) * aniso_x)), + vth = static_cast((double(th) * aniso_y)), + vtw = static_cast((double(tw) * aniso_x)); // current tile to skip tile reloads size_t curt_x = 999, curt_y = 999; diff --git a/src/nyx/python/new_bindings_py.cpp b/src/nyx/python/new_bindings_py.cpp index c23c29ce8..fb0fab6ab 100644 --- a/src/nyx/python/new_bindings_py.cpp +++ b/src/nyx/python/new_bindings_py.cpp @@ -999,7 +999,7 @@ std::map get_params_imp (uint64_t instid, const std params["dynamic_range"] = theEnvironment.fpimageOptions.target_dyn_range(); params["min_intensity"] = theEnvironment.fpimageOptions.min_intensity(); params["max_intensity"] = theEnvironment.fpimageOptions.max_intensity(); - params["ram_limit"] = (int)(theEnvironment.get_ram_limit()/1048576); // convert from bytes to megabytes + params["ram_limit"] = static_cast((theEnvironment.get_ram_limit()/1048576)); // convert from bytes to megabytes if (vars.size() == 0) return params; diff --git a/src/nyx/raw_dicom.h b/src/nyx/raw_dicom.h index ad4d602c7..b1f69345a 100644 --- a/src/nyx/raw_dicom.h +++ b/src/nyx/raw_dicom.h @@ -202,7 +202,7 @@ class RawDicomLoader : public RawFormatLoader // in the HU domain (matches the loader offset + float_domain_map reconstruction). if (preserve_hu_ && idx < hu_tile_.size()) return hu_tile_ [idx]; - double rv = (double) tile [idx]; + double rv = static_cast(tile [idx]); return rv; } @@ -290,7 +290,7 @@ class RawDicomLoader : public RawFormatLoader // In HU mode keep the TRUE Hounsfield value (rescaled from the signed/unsigned // stored pixel) so the slide scan computes an HU-domain min/max, not the wrapped uint. if (preserve_hu_) - hu_tile_[i] = rescaleSlope_ * (double)buffer[i] + rescaleIntercept_; + hu_tile_[i] = rescaleSlope_ * static_cast(buffer[i] )+ rescaleIntercept_; } } else { diff --git a/src/nyx/raw_format.h b/src/nyx/raw_format.h index 7dc9de273..c2deb2882 100644 --- a/src/nyx/raw_format.h +++ b/src/nyx/raw_format.h @@ -57,15 +57,15 @@ class RawFormatLoader [[nodiscard]] virtual size_t numberPyramidLevels() const = 0; [[nodiscard]] size_t numberTileHeight(size_t level = 0) const { - return (size_t)std::ceil((double)(fullHeight(level)) / tileHeight(level)); + return static_cast(std::ceil(static_cast((fullHeight(level)) )/ tileHeight(level))); } [[nodiscard]] size_t numberTileWidth(size_t level = 0) const { - return (size_t)std::ceil((double)(fullWidth(level)) / tileWidth(level)); + return static_cast(std::ceil(static_cast((fullWidth(level)) )/ tileWidth(level))); } [[nodiscard]] size_t numberTileDepth(size_t level = 0) const { - return (size_t)std::ceil((double)(fullDepth(level)) / tileDepth(level)); + return static_cast(std::ceil(static_cast((fullDepth(level)) )/ tileDepth(level))); } protected: diff --git a/src/nyx/raw_nifti.h b/src/nyx/raw_nifti.h index ad85db9e2..aa389d7b0 100644 --- a/src/nyx/raw_nifti.h +++ b/src/nyx/raw_nifti.h @@ -27,8 +27,8 @@ class RawNiftiLoader : public RawFormatLoader // FIX: HU rescale (used only in preserve_hu mode): true value = slope*stored + intercept. // Per NIfTI spec scl_slope==0 means "no scaling", so fall back to an identity transform. - scl_slope_ = (nii_->scl_slope != 0.0) ? (double)nii_->scl_slope : 1.0; - scl_inter_ = (nii_->scl_slope != 0.0) ? (double)nii_->scl_inter : 0.0; + scl_slope_ = (nii_->scl_slope != 0.0) ? static_cast(nii_->scl_slope ): 1.0; + scl_inter_ = (nii_->scl_slope != 0.0) ? static_cast(nii_->scl_inter ): 0.0; switch (nii_->datatype) { @@ -109,15 +109,15 @@ class RawNiftiLoader : public RawFormatLoader template static uint32_t get_uint32_pixel_imp (const void* src, size_t idx) { - FileType x = *(((FileType*)src) + idx); - return (uint32_t)x; + FileType x = *((static_cast(src)) + idx); + return static_cast(x); } template static double get_dp_pixel_imp (const void* src, size_t idx) { - FileType x = *(((FileType*)src) + idx); - return (double)x; + FileType x = *((static_cast(src)) + idx); + return static_cast(x); } uint32_t get_uint32_pixel (size_t idx) const @@ -241,8 +241,8 @@ class NiftiLoader : public AbstractTileLoader } // FIX: HU rescale for this read (used only in preserve_hu mode); scl_slope==0 => identity. - cur_scl_slope_ = (nii->scl_slope != 0.0) ? (double)nii->scl_slope : 1.0; - cur_scl_inter_ = (nii->scl_slope != 0.0) ? (double)nii->scl_inter : 0.0; + cur_scl_slope_ = (nii->scl_slope != 0.0) ? static_cast(nii->scl_slope ): 1.0; + cur_scl_inter_ = (nii->scl_slope != 0.0) ? static_cast(nii->scl_inter ): 0.0; // cache if (nii->datatype == 2) { // NIFTI_TYPE_UINT8 @@ -342,7 +342,7 @@ class NiftiLoader : public AbstractTileLoader double base = std::floor (hu_min_base_); for (size_t i = 0; i < n; ++i) { - double hu = cur_scl_slope_ * (double)houbuf[i] + cur_scl_inter_; + double hu = cur_scl_slope_ * static_cast(houbuf[i] )+ cur_scl_inter_; double y = hu - base; if (y < 0.0) y = 0.0; nyxbuf[i] = static_cast(std::llround(y)); diff --git a/src/nyx/raw_omezarr.h b/src/nyx/raw_omezarr.h index 687814f90..a6419e859 100644 --- a/src/nyx/raw_omezarr.h +++ b/src/nyx/raw_omezarr.h @@ -134,7 +134,7 @@ class RawOmezarrLoader: public RawFormatLoader double get_dpequiv_pixel (size_t idx) const { - double rv = (double) dest[idx]; + double rv = static_cast(dest[idx]); return rv; } diff --git a/src/nyx/raw_tiff.h b/src/nyx/raw_tiff.h index cbef867f3..b0a5669aa 100644 --- a/src/nyx/raw_tiff.h +++ b/src/nyx/raw_tiff.h @@ -6,12 +6,12 @@ #include #undef uint64 #undef int64 -#else - #include -#endif -#include -#include -#include +#else + #include +#endif +#include +#include +#include #pragma once #include @@ -237,7 +237,7 @@ class RawTiffTileLoader : public RawFormatLoader { size_t logOffs = r * tileWidth_ + c, physOffs = r * tileWidth_ + c; - FileType x = *(((FileType*)src) + physOffs); + FileType x = *((static_cast(src)) + physOffs); minval = (std::min) (double(x), minval); maxval = (std::max) (double(x), maxval); } @@ -248,7 +248,7 @@ class RawTiffTileLoader : public RawFormatLoader size_t n = tileHeight_ * tileWidth_; for (size_t i = 0; i < n; i++) { - FileType x = *(((FileType*)src) + i); + FileType x = *((static_cast(src)) + i); minval = (std::min)(double(x), minval); maxval = (std::max)(double(x), maxval); } @@ -258,15 +258,15 @@ class RawTiffTileLoader : public RawFormatLoader template static uint32_t get_uint32_pixel_imp (tdata_t src, size_t idx) { - FileType x = *(((FileType*)src) + idx); - return (uint32_t) x; + FileType x = *((static_cast(src)) + idx); + return static_cast(x); } template static double get_dp_pixel_imp (tdata_t src, size_t idx) { - FileType x = *(((FileType*)src) + idx); - return (double) x; + FileType x = *((static_cast(src)) + idx); + return static_cast(x); } double (*get_dpequiv_pixel_typeresolved) (tdata_t src, size_t idx) = nullptr; @@ -458,7 +458,7 @@ class RawTiffStripLoader : public RawFormatLoader throw (std::runtime_error(erm)); } - auto* fub = static_cast(buf); + auto* fub = static_cast(buf); for (size_t r = 0; r < tileHeight_; r++) { size_t offs = r * scanline_szb; @@ -518,7 +518,7 @@ class RawTiffStripLoader : public RawFormatLoader // - Informative zone of the strip if (layer < fullDepth_ && row < fullHeight_ && col < fullWidth_) - x = ((FileType*)(src))[col]; + x = (static_cast(src))[col]; minval = (std::min)(double(x), minval); maxval = (std::max)(double(x), maxval); @@ -528,15 +528,15 @@ class RawTiffStripLoader : public RawFormatLoader template static uint32_t get_uint32_pixel_imp(tdata_t src, size_t idx) { - FileType x = *(((FileType*)src) + idx); - return (uint32_t)x; + FileType x = *((static_cast(src)) + idx); + return static_cast(x); } template static double get_dp_pixel_imp(tdata_t src, size_t idx) { - FileType x = *(((FileType*)src) + idx); - return (double)x; + FileType x = *((static_cast(src)) + idx); + return static_cast(x); } double (*get_dpequiv_pixel_typeresolved) (tdata_t src, size_t idx) = nullptr; diff --git a/src/nyx/reduce_trivial_rois.cpp b/src/nyx/reduce_trivial_rois.cpp index 03245098e..37f5f7c75 100644 --- a/src/nyx/reduce_trivial_rois.cpp +++ b/src/nyx/reduce_trivial_rois.cpp @@ -267,7 +267,7 @@ namespace Nyxus size_t gbl = env.devCache.gpu_batch_len; // former NyxusGpu::gpu_batch_len // Cache ROI clouds and contours size_t nrois = L.size(); - int nb = std::ceil ((float)nrois / (float)gbl); + int nb = std::ceil (static_cast(nrois )/ static_cast(gbl)); for (int b = 0; b < nb; b++) { size_t off_this_batch = b * gbl; diff --git a/src/nyx/roi_cache.cpp b/src/nyx/roi_cache.cpp index ccf98132d..9ecb17903 100644 --- a/src/nyx/roi_cache.cpp +++ b/src/nyx/roi_cache.cpp @@ -85,7 +85,7 @@ std::vector LR::get_fvals (int fcode) const void LR::initialize_fvals() { - fvals.resize ((int)Nyxus::FeatureIMQ::_COUNT_); + fvals.resize (static_cast(Nyxus::FeatureIMQ::_COUNT_)); for (auto& valVec : fvals) valVec.push_back(0.0); } diff --git a/src/nyx/roi_cache.h b/src/nyx/roi_cache.h index e01b6ac43..45508bd50 100644 --- a/src/nyx/roi_cache.h +++ b/src/nyx/roi_cache.h @@ -30,7 +30,7 @@ enum RoiDataCacheItem class LR: public BasicLR { public: - static constexpr const RoiDataCacheItem CachedObjects[] = { RAW_PIXELS, CONTOUR, CONVEX_HULL, IMAGE_MATRIX, NEIGHBOR_ROI_LABELS }; + static constexpr RoiDataCacheItem CachedObjects[] = { RAW_PIXELS, CONTOUR, CONVEX_HULL, IMAGE_MATRIX, NEIGHBOR_ROI_LABELS }; LR (int roi_label); LR() : BasicLR(-1) {} diff --git a/src/nyx/slideprops.cpp b/src/nyx/slideprops.cpp index f96de6bbc..fcdaa2a78 100644 --- a/src/nyx/slideprops.cpp +++ b/src/nyx/slideprops.cpp @@ -396,14 +396,14 @@ namespace Nyxus for (const auto& pair : R) { const LR& r = pair.second; - maxArea = (std::max)(maxArea, (size_t)r.aux_area); + maxArea = (std::max)(maxArea, static_cast(r.aux_area)); const AABB& bb = r.aabb; auto w = bb.get_width(); auto h = bb.get_height(); auto d = bb.get_z_depth(); - max_w = (std::max)(max_w, (size_t)w); - max_h = (std::max)(max_h, (size_t)h); - max_d = (std::max)(max_d, (size_t)d); + max_w = (std::max)(max_w, static_cast(w)); + max_h = (std::max)(max_h, static_cast(h)); + max_d = (std::max)(max_d, static_cast(d)); } p.slide_w = fullW; diff --git a/src/nyx/slideprops.h b/src/nyx/slideprops.h index 5bbfcf0d3..3ff00ad46 100644 --- a/src/nyx/slideprops.h +++ b/src/nyx/slideprops.h @@ -52,17 +52,17 @@ class SlideProps // slope-1 offset map: u = round(x - floor(min)). e.g. min=-1024 => HU -1024->0, 0->1024, 3071->4095 double y = x - std::floor(min_preroi_inten); if (y < 0.0) y = 0.0; // clamp rare sub-min outliers to 0 (stay in unsigned range) - return (unsigned int) std::llround(y); + return static_cast(std::llround(y)); } if (fp_phys_pivoxels) { double y = x < min_preroi_inten ? min_preroi_inten : x; y = y > max_preroi_inten ? max_preroi_inten : y; y = uint_dynrange * (y - min_preroi_inten) / (max_preroi_inten - min_preroi_inten); - return (unsigned int)y; + return static_cast(y); } else - return (unsigned int) x; + return static_cast(x); } // geometric diff --git a/src/nyx/workflow_2d_whole.cpp b/src/nyx/workflow_2d_whole.cpp index 9911f404f..3288f452c 100644 --- a/src/nyx/workflow_2d_whole.cpp +++ b/src/nyx/workflow_2d_whole.cpp @@ -103,13 +103,13 @@ namespace Nyxus // same offset domain as the loaded pixels (as workflow_3d_whole already does), instead // of casting a negative HU straight to PixIntens and wrapping. double off = std::floor (p.min_preroi_inten); - vroi.aux_min = (PixIntens) std::llround (p.min_preroi_inten - off); - vroi.aux_max = (PixIntens) std::llround (p.max_preroi_inten - off); + vroi.aux_min = static_cast(std::llround (p.min_preroi_inten - off)); + vroi.aux_max = static_cast(std::llround (p.max_preroi_inten - off)); } else { - vroi.aux_min = (PixIntens) p.fp_phys_pivoxels ? 0 : (PixIntens) p.min_preroi_inten; - vroi.aux_max = (PixIntens) p.fp_phys_pivoxels ? (PixIntens) env.fpimageOptions.target_dyn_range() : (PixIntens) p.max_preroi_inten; + vroi.aux_min = static_cast(p.fp_phys_pivoxels )? 0 : static_cast(p.min_preroi_inten); + vroi.aux_max = static_cast(p.fp_phys_pivoxels )? static_cast(env.fpimageOptions.target_dyn_range() ): static_cast(p.max_preroi_inten); } // fix the AABB with respect to anisotropy diff --git a/src/nyx/workflow_3d_segmented.cpp b/src/nyx/workflow_3d_segmented.cpp index aa3630eb6..f506f8334 100644 --- a/src/nyx/workflow_3d_segmented.cpp +++ b/src/nyx/workflow_3d_segmented.cpp @@ -217,7 +217,7 @@ namespace Nyxus // -- empty indicating a 3D case (.nii, .dcm, etc) // Display (1) dataset progress info and (2) file pair info - int digits = 2, k = (int)std::pow(10.f, digits); + int digits = 2, k = static_cast(std::pow(10.f, digits)); float perCent = float(i * 100 * k / nf) / float(k); VERBOSLVL1(env.get_verbosity_level(), std::cout << "[ " << std::setw(digits + 2) << perCent << "% ]\t" << " INT: " << ifile.fname << " SEG: " << mfile.fname << " T:" << t << "\n") diff --git a/src/nyx/workflow_3d_whole.cpp b/src/nyx/workflow_3d_whole.cpp index a452600b2..b13715c50 100644 --- a/src/nyx/workflow_3d_whole.cpp +++ b/src/nyx/workflow_3d_whole.cpp @@ -100,8 +100,8 @@ namespace Nyxus // tell ROI the actual uint rynamic range or greybinned one depending on the slide's low-level properties // with the Hounsfield adjustment - vroi.aux_min = (PixIntens) (p.min_preroi_inten - p.min_preroi_inten); // in CT datasets p.min_preroi_inten can be -1024.0 - vroi.aux_max = (PixIntens) (p.max_preroi_inten - p.min_preroi_inten); + vroi.aux_min = static_cast((p.min_preroi_inten - p.min_preroi_inten)); // in CT datasets p.min_preroi_inten can be -1024.0 + vroi.aux_max = static_cast((p.max_preroi_inten - p.min_preroi_inten)); // fix the AABB with respect to anisotropy if (env.anisoOptions.customized() == false)