Skip to content

Commit

Permalink
Code indentation with vscode settings and changes in cxx standard det…
Browse files Browse the repository at this point in the history
…ection
  • Loading branch information
fspindle committed Jan 24, 2024
1 parent 3da777d commit ed5d19a
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 134 deletions.
6 changes: 0 additions & 6 deletions modules/core/include/visp3/core/vpHistogram.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,3 @@ class VISP_EXPORT vpHistogram
};

#endif

/*
* Local variables:
* c-basic-offset: 2
* End:
*/
43 changes: 20 additions & 23 deletions modules/core/include/visp3/core/vpImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,6 @@
#include <opencv2/imgproc/imgproc_c.h>
#endif

#if (VISP_CXX_STANDARD == VISP_CXX_STANDARD_98)
namespace
{
// Helper to apply the scale to the raw values of the filters
template <typename FilterType>
void scaleFilter(vpArray2D<FilterType> &filter, const float &scale)
{
const unsigned int nbRows = filter.getRows();
const unsigned int nbCols = filter.getCols();
for (unsigned int r = 0; r < nbRows; ++r) {
for (unsigned int c = 0; c < nbCols; ++c) {
filter[r][c] = filter[r][c] * scale;
}
}
}
};
#endif

/*!
* \class vpImageFilter
*
Expand Down Expand Up @@ -122,7 +104,7 @@ class VISP_EXPORT vpImageFilter
static bool checkBooleanMask(const vpImage<bool> *p_mask, const unsigned int &r, const unsigned int &c)
{
bool computeVal = true;
#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
#if ((__cplusplus >= 201103L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201103L))) // Check if cxx11 or higher
if (p_mask != nullptr)
#else
if (p_mask != NULL)
Expand All @@ -133,6 +115,21 @@ class VISP_EXPORT vpImageFilter
return computeVal;
}

#if ((__cplusplus == 199711L) || (defined(_MSVC_LANG) && (_MSVC_LANG == 199711L))) // Check if cxx98
// Helper to apply the scale to the raw values of the filters
template <typename FilterType>
static void scaleFilter(vpArray2D<FilterType> &filter, const float &scale)
{
const unsigned int nbRows = filter.getRows();
const unsigned int nbCols = filter.getCols();
for (unsigned int r = 0; r < nbRows; ++r) {
for (unsigned int c = 0; c < nbCols; ++c) {
filter[r][c] = filter[r][c] * scale;
}
}
}
#endif

public:
//! Canny filter backends for the edge detection operations
typedef enum vpCannyBackendType
Expand Down Expand Up @@ -251,7 +248,7 @@ class VISP_EXPORT vpImageFilter
vpArray2D<FilterType> gradientFilterX(apertureGradient, apertureGradient); // Gradient filter along the X-axis
vpArray2D<FilterType> gradientFilterY(apertureGradient, apertureGradient); // Gradient filter along the Y-axis

#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
#if ((__cplusplus >= 201103L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201103L))) // Check if cxx11 or higher
// Helper to apply the scale to the raw values of the filters
auto scaleFilter = [](vpArray2D<FilterType> &filter, const float &scale) {
const unsigned int nbRows = filter.getRows();
Expand Down Expand Up @@ -313,7 +310,7 @@ class VISP_EXPORT vpImageFilter
}
}

#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
#if ((__cplusplus >= 201103L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201103L))) // Check if cxx11 or higher
template <typename FilterType>
inline static void computePartialDerivatives(const vpImage<vpRGBa> &I,
vpImage<FilterType> &dIx, vpImage<FilterType> &dIy,
Expand Down Expand Up @@ -618,7 +615,7 @@ class VISP_EXPORT vpImageFilter
}
}

#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
#if ((__cplusplus >= 201103L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201103L))) // Check if cxx11 or higher
template <typename FilterType>
static void filter(const vpImage<vpRGBa> &I, vpImage<FilterType> &If, const vpArray2D<FilterType> &M, bool convolve = false) = delete;
#else
Expand Down Expand Up @@ -701,7 +698,7 @@ class VISP_EXPORT vpImageFilter
}
}

#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
#if ((__cplusplus >= 201103L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201103L))) // Check if cxx11 or higher
template<typename FilterType>
static void filter(const vpImage<vpRGBa> &I, vpImage<FilterType> &Iu, vpImage<FilterType> &Iv, const vpArray2D<FilterType> &M, bool convolve) = delete;

Expand Down
60 changes: 40 additions & 20 deletions modules/core/src/image/vpCannyEdgeDetection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@

#include <visp3/core/vpImageConvert.h>

#if (VISP_CXX_STANDARD == VISP_CXX_STANDARD_98) // Check if cxx98
namespace
{
// Helper to apply the scale to the raw values of the filters
template <typename FilterType>
static void scaleFilter(vpArray2D<FilterType> &filter, const float &scale)
{
const unsigned int nbRows = filter.getRows();
const unsigned int nbCols = filter.getCols();
for (unsigned int r = 0; r < nbRows; ++r) {
for (unsigned int c = 0; c < nbCols; ++c) {
filter[r][c] = filter[r][c] * scale;
}
}
}
};
#endif

// // Initialization methods

vpCannyEdgeDetection::vpCannyEdgeDetection()
Expand All @@ -53,9 +71,9 @@ vpCannyEdgeDetection::vpCannyEdgeDetection()
}

vpCannyEdgeDetection::vpCannyEdgeDetection(const int &gaussianKernelSize, const float &gaussianStdev
, const unsigned int &sobelAperture, const float &lowerThreshold, const float &upperThreshold
, const float &lowerThresholdRatio, const float &upperThresholdRatio
, const vpImageFilter::vpCannyFilteringAndGradientType &filteringType
, const unsigned int &sobelAperture, const float &lowerThreshold, const float &upperThreshold
, const float &lowerThresholdRatio, const float &upperThresholdRatio
, const vpImageFilter::vpCannyFilteringAndGradientType &filteringType
)
: m_filteringAndGradientType(filteringType)
, m_gaussianKernelSize(gaussianKernelSize)
Expand Down Expand Up @@ -111,7 +129,7 @@ vpCannyEdgeDetection::initGaussianFilters()
if ((m_gaussianKernelSize % 2) == 0) {
throw(vpException(vpException::badValue, "The Gaussian kernel size should be odd"));
}
m_fg.resize(1, (m_gaussianKernelSize + 1)/2);
m_fg.resize(1, (m_gaussianKernelSize + 1) / 2);
vpImageFilter::getGaussianKernel(m_fg.data, m_gaussianKernelSize, m_gaussianStdev, true);
}

Expand All @@ -124,24 +142,26 @@ vpCannyEdgeDetection::initGradientFilters()
m_gradientFilterX.resize(m_gradientFilterKernelSize, m_gradientFilterKernelSize);
m_gradientFilterY.resize(m_gradientFilterKernelSize, m_gradientFilterKernelSize);

#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
auto scaleFilter = [](vpArray2D<float> &filter, const float &scale) {
for (unsigned int r = 0; r < filter.getRows(); r++) {
for (unsigned int c = 0; c < filter.getCols(); c++) {
filter[r][c] = filter[r][c] * scale;
}
}};
#endif

float scaleX = 1.f;
float scaleY = 1.f;

if (m_filteringAndGradientType == vpImageFilter::CANNY_GBLUR_SOBEL_FILTERING) {
scaleX = vpImageFilter::getSobelKernelX(m_gradientFilterX.data, (m_gradientFilterKernelSize - 1)/2);
scaleY = vpImageFilter::getSobelKernelY(m_gradientFilterY.data, (m_gradientFilterKernelSize - 1)/2);
scaleX = vpImageFilter::getSobelKernelX(m_gradientFilterX.data, (m_gradientFilterKernelSize - 1) / 2);
scaleY = vpImageFilter::getSobelKernelY(m_gradientFilterY.data, (m_gradientFilterKernelSize - 1) / 2);
}
else if (m_filteringAndGradientType == vpImageFilter::CANNY_GBLUR_SCHARR_FILTERING) {
// Compute the Scharr filters
scaleX = vpImageFilter::getScharrKernelX(m_gradientFilterX.data, (m_gradientFilterKernelSize - 1)/2);
scaleY = vpImageFilter::getScharrKernelY(m_gradientFilterY.data, (m_gradientFilterKernelSize - 1)/2);
scaleX = vpImageFilter::getScharrKernelX(m_gradientFilterX.data, (m_gradientFilterKernelSize - 1) / 2);
scaleY = vpImageFilter::getScharrKernelY(m_gradientFilterY.data, (m_gradientFilterKernelSize - 1) / 2);
}
else {
std::string errMsg = "[vpCannyEdgeDetection::initGradientFilters] Error: gradient filtering method \"";
Expand Down Expand Up @@ -215,7 +235,7 @@ void
vpCannyEdgeDetection::performFilteringAndGradientComputation(const vpImage<unsigned char> &I)
{
if (m_filteringAndGradientType == vpImageFilter::CANNY_GBLUR_SOBEL_FILTERING
|| m_filteringAndGradientType == vpImageFilter::CANNY_GBLUR_SCHARR_FILTERING) {
|| m_filteringAndGradientType == vpImageFilter::CANNY_GBLUR_SCHARR_FILTERING) {
// Computing the Gaussian blur
vpImage<float> Iblur;
vpImage<float> GIx;
Expand Down Expand Up @@ -248,9 +268,9 @@ vpCannyEdgeDetection::performFilteringAndGradientComputation(const vpImage<unsig
*/
void
getInterpolationWeightsAndOffsets(const float &gradientOrientation,
float &alpha, float &beta,
int &dRowGradAlpha, int &dRowGradBeta,
int &dColGradAlpha, int &dColGradBeta
float &alpha, float &beta,
int &dRowGradAlpha, int &dRowGradBeta,
int &dColGradAlpha, int &dColGradBeta
)
{
float thetaMin = 0.f;
Expand Down Expand Up @@ -304,11 +324,11 @@ getManhattanGradient(const vpImage<float> &dIx, const vpImage<float> &dIy, const
float grad = 0.;
int nbRows = dIx.getRows();
int nbCols = dIx.getCols();
if (row >= 0
&& row < nbRows
&& col >= 0
&& col < nbCols
) {
if (row >= 0
&& row < nbRows
&& col >= 0
&& col < nbCols
) {
float dx = dIx[row][col];
float dy = dIy[row][col];
grad = std::abs(dx) + std::abs(dy);
Expand Down Expand Up @@ -442,9 +462,9 @@ vpCannyEdgeDetection::recursiveSearchForStrongEdge(const std::pair<unsigned int,

// Checking if we are still looking for an edge in the limit of the image
if ((idRow < 0 || idRow >= nbRows)
|| (idCol < 0 || idCol >= nbCols)
|| (dr == 0 && dc == 0)
) {
|| (idCol < 0 || idCol >= nbCols)
|| (dr == 0 && dc == 0)
) {
continue;
}

Expand Down
Loading

0 comments on commit ed5d19a

Please sign in to comment.