diff --git a/modules/core/include/visp3/core/vpArray2D.h b/modules/core/include/visp3/core/vpArray2D.h index 55877334cc..d466f451b6 100644 --- a/modules/core/include/visp3/core/vpArray2D.h +++ b/modules/core/include/visp3/core/vpArray2D.h @@ -215,7 +215,7 @@ template class vpArray2D rowNum(0), colNum(0), rowPtrs(nullptr), dsize(0), data(nullptr) #endif { - if (r > 0 && c > 0) { + if ((r > 0) && (c > 0)) { if ((r * c) != vec.size()) { throw(vpException(vpException::dimensionError, "Cannot initialize vpArray(%d, %d) from std::vector(%d). Wrong dimension", r, c, vec.size())); @@ -273,7 +273,7 @@ template class vpArray2D explicit vpArray2D(unsigned int nrows, unsigned int ncols, const std::initializer_list &list) : rowNum(0), colNum(0), rowPtrs(nullptr), dsize(0), data(nullptr) { - if (nrows * ncols != static_cast(list.size())) { + if ((nrows * ncols) != static_cast(list.size())) { std::ostringstream oss; oss << "Cannot create a vpArray2D of size (" << nrows << ", " << ncols << ") with a list of size " << list.size(); throw vpException(vpException::dimensionError, oss.str()); @@ -294,7 +294,7 @@ template class vpArray2D resize(nrows, ncols, false, false); auto it = lists.begin(); - for (unsigned int i = 0; i < rowNum; i++, ++it) { + for (unsigned int i = 0; i < rowNum; ++i, ++it) { std::copy(it->begin(), it->end(), rowPtrs[i]); } } @@ -314,7 +314,9 @@ template class vpArray2D free(rowPtrs); rowPtrs = nullptr; } - rowNum = colNum = dsize = 0; + rowNum = 0; + colNum = 0; + dsize = 0; } /** @name Inherited functionalities from vpArray2D */ @@ -352,19 +354,20 @@ template class vpArray2D void resize(unsigned int nrows, unsigned int ncols, bool flagNullify = true, bool recopy_ = true) { if ((nrows == rowNum) && (ncols == colNum)) { - if (flagNullify && this->data != nullptr) { + if (flagNullify && (this->data != nullptr)) { memset(this->data, 0, this->dsize * sizeof(Type)); } } else { - bool recopy = !flagNullify && recopy_; // priority to flagNullify - const bool recopyNeeded = (ncols != this->colNum && this->colNum > 0 && ncols > 0 && (!flagNullify || recopy)); + bool recopy = (!flagNullify) && recopy_; // priority to flagNullify + bool colcond = (ncols != this->colNum) && (this->colNum > 0) && (ncols > 0); + const bool recopyNeeded = colcond && ((!flagNullify) || recopy); Type *copyTmp = nullptr; unsigned int rowTmp = 0, colTmp = 0; // Recopy case per case is required if number of cols has changed; // structure of Type array is not the same in this case. - if (recopyNeeded && this->data != nullptr) { + if (recopyNeeded && (this->data != nullptr)) { copyTmp = new Type[this->dsize]; memcpy(copyTmp, this->data, sizeof(Type) * this->dsize); rowTmp = this->rowNum; @@ -404,11 +407,10 @@ template class vpArray2D } // Update rowPtrs - { - Type **t_ = rowPtrs; - for (unsigned int i = 0; i < dsize; i += ncols) { - *t_++ = this->data + i; - } + + Type **t_ = rowPtrs; + for (unsigned int i = 0; i < dsize; i += ncols) { + *t_++ = this->data + i; } this->rowNum = nrows; @@ -416,16 +418,16 @@ template class vpArray2D // Recopy of this->data array values or nullify if (flagNullify) { - memset(this->data, 0, (size_t)(this->dsize) * sizeof(Type)); + memset(this->data, 0, static_cast(this->dsize) * sizeof(Type)); } - else if (recopyNeeded && this->rowPtrs != nullptr) { + else if (recopyNeeded && (this->rowPtrs != nullptr)) { // Recopy... unsigned int minRow = (this->rowNum < rowTmp) ? this->rowNum : rowTmp; unsigned int minCol = (this->colNum < colTmp) ? this->colNum : colTmp; for (unsigned int i = 0; i < this->rowNum; ++i) { for (unsigned int j = 0; j < this->colNum; ++j) { if ((minRow > i) && (minCol > j)) { - (*this)[i][j] = copyTmp[i * colTmp + j]; + (*this)[i][j] = copyTmp[(i * colTmp) + j]; } else { (*this)[i][j] = 0; @@ -447,7 +449,7 @@ template class vpArray2D return; } - if (nrows * ncols != dsize) { + if ((nrows * ncols) != dsize) { std::ostringstream oss; oss << "Cannot reshape array of total size " << dsize << " into shape (" << nrows << ", " << ncols << ")"; throw vpException(vpException::dimensionError, oss.str()); @@ -483,13 +485,14 @@ template class vpArray2D */ void insert(const vpArray2D &A, unsigned int r, unsigned int c) { - if ((r + A.getRows()) <= rowNum && (c + A.getCols()) <= colNum) { - if (A.colNum == colNum && data != nullptr && A.data != nullptr && A.data != data) { - memcpy(data + r * colNum, A.data, sizeof(Type) * A.size()); + if (((r + A.getRows()) <= rowNum) && ((c + A.getCols()) <= colNum)) { + if ((A.colNum == colNum) && (data != nullptr) && (A.data != nullptr) && (A.data != data)) { + memcpy(data + (r * colNum), A.data, sizeof(Type) * A.size()); } - else if (data != nullptr && A.data != nullptr && A.data != data) { - for (unsigned int i = r; i < (r + A.getRows()); ++i) { - memcpy(data + i * colNum + c, A.data + (i - r) * A.colNum, sizeof(Type) * A.colNum); + else if ((data != nullptr) && (A.data != nullptr) && (A.data != data)) { + unsigned int a_rows = A.getRows(); + for (unsigned int i = r; i < (r + a_rows); ++i) { + memcpy(data + (i * colNum) + c, A.data + ((i - r) * A.colNum), sizeof(Type) * A.colNum); } } } @@ -521,8 +524,8 @@ template class vpArray2D vpArray2D &operator=(const vpArray2D &A) { resize(A.rowNum, A.colNum, false, false); - if (data != nullptr && A.data != nullptr && data != A.data) { - memcpy(data, A.data, (size_t)rowNum * (size_t)colNum * sizeof(Type)); + if ((data != nullptr) && (A.data != nullptr) && (data != A.data)) { + memcpy(data, A.data, static_cast(rowNum) * static_cast(colNum) * sizeof(Type)); } return *this; } @@ -575,7 +578,7 @@ template class vpArray2D resize(nrows, ncols, false, false); auto it = lists.begin(); - for (unsigned int i = 0; i < rowNum; i++, ++it) { + for (unsigned int i = 0; i < rowNum; ++i, ++it) { std::copy(it->begin(), it->end(), rowPtrs[i]); } @@ -599,20 +602,22 @@ template class vpArray2D */ friend std::ostream &operator<<(std::ostream &s, const vpArray2D &A) { - if (A.data == nullptr || A.size() == 0) { + if ((A.data == nullptr) || (A.size() == 0)) { return s; } std::ios_base::fmtflags original_flags = s.flags(); s.precision(10); - for (unsigned int i = 0; i < A.getRows(); ++i) { - for (unsigned int j = 0; j < A.getCols() - 1; ++j) { + unsigned int a_rows = A.getRows(); + unsigned int a_cols = A.getCols(); + for (unsigned int i = 0; i < a_rows; ++i) { + for (unsigned int j = 0; j < (a_cols - 1); ++j) { s << A[i][j] << " "; } // We don't add " " after the last row element - s << A[i][A.getCols() - 1]; + s << A[i][a_cols - 1]; // We don't add a \n char on the end of the last array line - if (i < A.getRows() - 1) { + if (i < (a_rows - 1)) { s << std::endl; } } @@ -704,7 +709,7 @@ template class vpArray2D file >> rows; file >> cols; - if (rows >= (std::numeric_limits::max)() || cols >= (std::numeric_limits::max)()) { + if ((rows >= std::numeric_limits::max()) || (cols >= std::numeric_limits::max())) { throw vpException(vpException::badValue, "Array exceed the max size."); } @@ -736,14 +741,14 @@ template class vpArray2D } unsigned int rows, cols; - file.read((char *)&rows, sizeof(unsigned int)); - file.read((char *)&cols, sizeof(unsigned int)); + file.read(reinterpret_cast(&rows), sizeof(unsigned int)); + file.read(reinterpret_cast(&cols), sizeof(unsigned int)); A.resize(rows, cols); Type value; for (unsigned int i = 0; i < rows; ++i) { for (unsigned int j = 0; j < cols; ++j) { - file.read((char *)&value, sizeof(Type)); + file.read(reinterpret_cast(&value), sizeof(Type)); A[i][j] = value; } } @@ -784,12 +789,12 @@ template class vpArray2D while (getline(file, line)) { if (inheader) { - if (rows == 0 && line.compare(0, 5, "rows:") == 0) { + if ((rows == 0) && (line.compare(0, 5, "rows:") == 0)) { std::stringstream ss(line); ss >> subs; ss >> rows; } - else if (cols == 0 && line.compare(0, 5, "cols:") == 0) { + else if ((cols == 0) && (line.compare(0, 5, "cols:") == 0)) { std::stringstream ss(line); ss >> subs; ss >> cols; @@ -805,20 +810,20 @@ template class vpArray2D // if i == 0, we just got out of the header: initialize matrix // dimensions if (i == 0) { - if (rows == 0 || cols == 0) { + if ((rows == 0) || (cols == 0)) { file.close(); return false; } A.resize(rows, cols); // get indentation level which is common to all lines - lineStart = (unsigned int)line.find("[") + 1; + lineStart = static_cast(line.find("[")) + 1; } std::stringstream ss(line.substr(lineStart, line.find("]") - lineStart)); j = 0; while (getline(ss, subs, ',')) { A[i][j++] = atof(subs.c_str()); } - i++; + ++i; } } @@ -876,7 +881,7 @@ template class vpArray2D if (header[i] == '\n') { file << "# "; } - i++; + ++i; } file << std::endl; file << A.getRows() << "\t" << A.getCols() << std::endl; @@ -885,19 +890,21 @@ template class vpArray2D else { int headerSize = 0; while (header[headerSize] != '\0') { - headerSize++; + ++headerSize; } - file.write(header, (size_t)headerSize + (size_t)1); + file.write(header, static_cast(headerSize)+static_cast(1)); unsigned int matrixSize; matrixSize = A.getRows(); - file.write((char *)&matrixSize, sizeof(unsigned int)); + file.write(reinterpret_cast(&matrixSize), sizeof(unsigned int)); matrixSize = A.getCols(); - file.write((char *)&matrixSize, sizeof(unsigned int)); + file.write(reinterpret_cast(&matrixSize), sizeof(unsigned int)); Type value; - for (unsigned int i = 0; i < A.getRows(); ++i) { - for (unsigned int j = 0; j < A.getCols(); ++j) { + unsigned int a_rows = A.getRows(); + unsigned int a_cols = A.getCols(); + for (unsigned int i = 0; i < a_rows; ++i) { + for (unsigned int j = 0; j < a_cols; ++j) { value = A[i][j]; - file.write((char *)&value, sizeof(Type)); + file.write(reinterpret_cast(&value), sizeof(Type)); } } } @@ -973,14 +980,14 @@ template class vpArray2D checkIndent = false; } } - if (header[i] == '\n' || (inIndent && header[i] == ' ')) { + if ((header[i] == '\n') || (inIndent && (header[i] == ' '))) { inIndent = true; } else { inIndent = false; } } - i++; + ++i; } if (i != 0) { @@ -995,9 +1002,11 @@ template class vpArray2D file << "data: " << std::endl; unsigned int j; - for (i = 0; i < A.getRows(); ++i) { + unsigned int a_rows = A.getRows(); + unsigned int a_cols = A.getCols(); + for (i = 0; i < a_rows; ++i) { file << indent << "- ["; - for (j = 0; j < A.getCols() - 1; ++j) { + for (j = 0; j < (a_cols - 1); ++j) { file << A[i][j] << ", "; } file << A[i][j] << "]" << std::endl; @@ -1080,12 +1089,12 @@ template Type vpArray2D::getMinValue() const { Type *dataptr = data; Type min = *dataptr; - dataptr++; - for (unsigned int i = 0; i < dsize - 1; ++i) { + ++dataptr; + for (unsigned int i = 0; i < (dsize - 1); ++i) { if (*dataptr < min) { min = *dataptr; } - dataptr++; + ++dataptr; } return min; } @@ -1097,12 +1106,12 @@ template Type vpArray2D::getMaxValue() const { Type *dataptr = data; Type max = *dataptr; - dataptr++; - for (unsigned int i = 0; i < dsize - 1; ++i) { + ++dataptr; + for (unsigned int i = 0; i < (dsize - 1); ++i) { if (*dataptr > max) { max = *dataptr; } - dataptr++; + ++dataptr; } return max; } @@ -1115,7 +1124,7 @@ template Type vpArray2D::getMaxValue() const */ template vpArray2D vpArray2D::hadamard(const vpArray2D &m) const { - if (m.getRows() != rowNum || m.getCols() != colNum) { + if ((m.getRows() != rowNum) || (m.getCols() != colNum)) { throw(vpException(vpException::dimensionError, "Hadamard product: bad dimensions!")); } @@ -1149,20 +1158,22 @@ template vpArray2D vpArray2D::conv2(const vpArray2D void vpArray2D::conv2(const vpArray2D &M, const vpArray2D &kernel, vpArray2D &res, const std::string &mode) { - if (M.getRows() * M.getCols() == 0 || kernel.getRows() * kernel.getCols() == 0) + if (((M.getRows() * M.getCols()) == 0) || ((kernel.getRows() * kernel.getCols()) == 0)) { return; + } if (mode == "valid") { - if (kernel.getRows() > M.getRows() || kernel.getCols() > M.getCols()) + if ((kernel.getRows() > M.getRows()) || (kernel.getCols() > M.getCols())) { return; + } } vpArray2D M_padded, res_same; - if (mode == "full" || mode == "same") { + if ((mode == "full") || (mode == "same")) { const unsigned int pad_x = kernel.getCols() - 1; const unsigned int pad_y = kernel.getRows() - 1; - M_padded.resize(M.getRows() + 2 * pad_y, M.getCols() + 2 * pad_x, true, false); + M_padded.resize(M.getRows() + (2 * pad_y), M.getCols() + (2 * pad_x), true, false); M_padded.insert(M, pad_y, pad_x); if (mode == "same") { @@ -1175,17 +1186,21 @@ template void vpArray2D::conv2(const vpArray2D &M, cons } else if (mode == "valid") { M_padded = M; - res.resize(M.getRows() - kernel.getRows() + 1, M.getCols() - kernel.getCols() + 1); + res.resize((M.getRows() - kernel.getRows()) + 1, (M.getCols() - kernel.getCols()) + 1); } else { return; } if (mode == "same") { - for (unsigned int i = 0; i < res_same.getRows(); ++i) { - for (unsigned int j = 0; j < res_same.getCols(); ++j) { - for (unsigned int k = 0; k < kernel.getRows(); ++k) { - for (unsigned int l = 0; l < kernel.getCols(); ++l) { + unsigned int res_same_rows = res_same.getRows(); + unsigned int res_same_cols = res_same.getCols(); + unsigned int kernel_rows = kernel.getRows(); + unsigned int kernel_cols = kernel.getCols(); + for (unsigned int i = 0; i < res_same_rows; ++i) { + for (unsigned int j = 0; j < res_same_cols; ++j) { + for (unsigned int k = 0; k < kernel_rows; ++k) { + for (unsigned int l = 0; l < kernel_cols; ++l) { res_same[i][j] += M_padded[i + k][j + l] * kernel[kernel.getRows() - k - 1][kernel.getCols() - l - 1]; } } @@ -1194,16 +1209,21 @@ template void vpArray2D::conv2(const vpArray2D &M, cons const unsigned int start_i = kernel.getRows() / 2; const unsigned int start_j = kernel.getCols() / 2; - for (unsigned int i = 0; i < M.getRows(); ++i) { - memcpy(res.data + i * M.getCols(), res_same.data + (i + start_i) * res_same.getCols() + start_j, + unsigned int m_rows = M.getRows(); + for (unsigned int i = 0; i < m_rows; ++i) { + memcpy(res.data + (i * M.getCols()), res_same.data + ((i + start_i) * res_same.getCols()) + start_j, sizeof(Type) * M.getCols()); } } else { - for (unsigned int i = 0; i < res.getRows(); ++i) { - for (unsigned int j = 0; j < res.getCols(); ++j) { - for (unsigned int k = 0; k < kernel.getRows(); ++k) { - for (unsigned int l = 0; l < kernel.getCols(); ++l) { + unsigned int res_rows = res.getRows(); + unsigned int res_cols = res.getCols(); + unsigned int kernel_rows = kernel.getRows(); + unsigned int kernel_cols = kernel.getCols(); + for (unsigned int i = 0; i < res_rows; ++i) { + for (unsigned int j = 0; j < res_cols; ++j) { + for (unsigned int k = 0; k < kernel_rows; ++k) { + for (unsigned int l = 0; l < kernel_cols; ++l) { res[i][j] += M_padded[i + k][j + l] * kernel[kernel.getRows() - k - 1][kernel.getCols() - l - 1]; } } @@ -1226,9 +1246,11 @@ template void vpArray2D::insert(const vpArray2D &A, cons if (((r + B.getRows()) <= A.getRows()) && ((c + B.getCols()) <= A.getCols())) { C.resize(A.getRows(), A.getCols(), false, false); - for (unsigned int i = 0; i < A.getRows(); ++i) { - for (unsigned int j = 0; j < A.getCols(); ++j) { - if (i >= r && i < (r + B.getRows()) && j >= c && j < (c + B.getCols())) { + unsigned int a_rows = A.getRows(); + unsigned int a_cols = A.getCols(); + for (unsigned int i = 0; i < a_rows; ++i) { + for (unsigned int j = 0; j < a_cols; ++j) { + if ((i >= r) && (i < (r + B.getRows())) && (j >= c) && (j < (c + B.getCols()))) { C[i][j] = B[i - r][j - c]; } else { @@ -1245,11 +1267,12 @@ template void vpArray2D::insert(const vpArray2D &A, cons template bool vpArray2D::operator==(const vpArray2D &A) const { - if (A.rowNum != rowNum || A.colNum != colNum) { + if ((A.rowNum != rowNum) || (A.colNum != colNum)) { return false; } - for (unsigned int i = 0; i < A.size(); ++i) { + unsigned int a_size = A.size(); + for (unsigned int i = 0; i < a_size; ++i) { if (data[i] != A.data[i]) { return false; } @@ -1263,11 +1286,12 @@ template bool vpArray2D::operator==(const vpArray2D &A) */ template <> inline bool vpArray2D::operator==(const vpArray2D &A) const { - if (A.rowNum != rowNum || A.colNum != colNum) { + if ((A.rowNum != rowNum) || (A.colNum != colNum)) { return false; } - for (unsigned int i = 0; i < A.size(); ++i) { + unsigned int a_size = A.size(); + for (unsigned int i = 0; i < a_size; ++i) { if (fabs(data[i] - A.data[i]) > std::numeric_limits::epsilon()) { return false; } @@ -1281,11 +1305,12 @@ template <> inline bool vpArray2D::operator==(const vpArray2D &A */ template <> inline bool vpArray2D::operator==(const vpArray2D &A) const { - if (A.rowNum != rowNum || A.colNum != colNum) { + if ((A.rowNum != rowNum) || (A.colNum != colNum)) { return false; } - for (unsigned int i = 0; i < A.size(); ++i) { + unsigned int a_size = A.size(); + for (unsigned int i = 0; i < a_size; ++i) { if (fabsf(data[i] - A.data[i]) > std::numeric_limits::epsilon()) { return false; } diff --git a/modules/core/include/visp3/core/vpColVector.h b/modules/core/include/visp3/core/vpColVector.h index e1e2ac4420..18906e6522 100644 --- a/modules/core/include/visp3/core/vpColVector.h +++ b/modules/core/include/visp3/core/vpColVector.h @@ -206,17 +206,17 @@ class VISP_EXPORT vpColVector : public vpArray2D * Constructor that initialize a column vector from a 3-dim (Euler or * \f$\theta {\bf u}\f$) or 4-dim (quaternion) rotation vector. */ - vpColVector(const vpRotationVector &v); + explicit vpColVector(const vpRotationVector &v); /*! * Constructor that initialize a column vector from a 6-dim pose vector. */ - vpColVector(const vpPoseVector &p); + explicit vpColVector(const vpPoseVector &p); /*! * Constructor that initialize a column vector from a 3-dim translation vector. */ - vpColVector(const vpTranslationVector &t); + explicit vpColVector(const vpTranslationVector &t); /*! * Constructor that creates a column vector from a m-by-1 matrix `M`. @@ -224,7 +224,7 @@ class VISP_EXPORT vpColVector : public vpArray2D * \exception vpException::dimensionError If the matrix is not a m-by-1 * matrix. */ - vpColVector(const vpMatrix &M); + explicit vpColVector(const vpMatrix &M); /*! * Constructor that takes column `j` of matrix `M`. @@ -234,12 +234,12 @@ class VISP_EXPORT vpColVector : public vpArray2D /*! * Constructor that creates a column vector from a std vector of double. */ - vpColVector(const std::vector &v); + explicit vpColVector(const std::vector &v); /*! * Constructor that creates a column vector from a std vector of float. */ - vpColVector(const std::vector &v); + explicit vpColVector(const std::vector &v); #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) /*! @@ -366,7 +366,7 @@ class VISP_EXPORT vpColVector : public vpArray2D */ vpColVector extract(unsigned int r, unsigned int colsize) const { - if (r >= rowNum || r + colsize > rowNum) { + if ((r >= rowNum) || ((r + colsize) > rowNum)) { throw(vpException(vpException::fatalError, "Cannot extract a (%dx1) column vector from a (%dx1) " "column vector starting at index %d", diff --git a/modules/core/include/visp3/core/vpDebug.h b/modules/core/include/visp3/core/vpDebug.h index 5b3eee6b8b..a9329f5be6 100644 --- a/modules/core/include/visp3/core/vpDebug.h +++ b/modules/core/include/visp3/core/vpDebug.h @@ -169,10 +169,12 @@ class vpTraceOutput va_list args; va_start(args, format); - if (err) + if (err) { std::cerr << "(L" << level << ") "; - else + } + else { std::cout << "(L" << level << ") "; + } // calls display with it display(format, args); diff --git a/modules/core/include/visp3/core/vpForceTwistMatrix.h b/modules/core/include/visp3/core/vpForceTwistMatrix.h index 2f9270af95..c4630d39b1 100644 --- a/modules/core/include/visp3/core/vpForceTwistMatrix.h +++ b/modules/core/include/visp3/core/vpForceTwistMatrix.h @@ -174,8 +174,8 @@ class VISP_EXPORT vpForceTwistMatrix : public vpArray2D vpForceTwistMatrix(const vpTranslationVector &t, const vpThetaUVector &thetau); vpForceTwistMatrix(double tx, double ty, double tz, double tux, double tuy, double tuz); - vpForceTwistMatrix(const vpRotationMatrix &R); - vpForceTwistMatrix(const vpThetaUVector &thetau); + explicit vpForceTwistMatrix(const vpRotationMatrix &R); + explicit vpForceTwistMatrix(const vpThetaUVector &thetau); vpForceTwistMatrix buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R); vpForceTwistMatrix buildFrom(const vpTranslationVector &t, const vpThetaUVector &thetau); diff --git a/modules/core/include/visp3/core/vpGEMM.h b/modules/core/include/visp3/core/vpGEMM.h index ad0b44c0ea..23837d406b 100644 --- a/modules/core/include/visp3/core/vpGEMM.h +++ b/modules/core/include/visp3/core/vpGEMM.h @@ -149,52 +149,60 @@ template <> inline void GEMM1<0>(const unsigned int &Arows, const unsigned int &Brows, const unsigned int &Bcols, const vpArray2D &A, const vpArray2D &B, const double &alpha, vpArray2D &D) { - for (unsigned int r = 0; r < Arows; ++r) + for (unsigned int r = 0; r < Arows; ++r) { for (unsigned int c = 0; c < Bcols; ++c) { double sum = 0; - for (unsigned int n = 0; n < Brows; ++n) + for (unsigned int n = 0; n < Brows; ++n) { sum += A[r][n] * B[n][c] * alpha; + } D[r][c] = sum; } + } } template <> inline void GEMM1<1>(const unsigned int &Arows, const unsigned int &Brows, const unsigned int &Bcols, const vpArray2D &A, const vpArray2D &B, const double &alpha, vpArray2D &D) { - for (unsigned int r = 0; r < Arows; ++r) + for (unsigned int r = 0; r < Arows; ++r) { for (unsigned int c = 0; c < Bcols; ++c) { double sum = 0; - for (unsigned int n = 0; n < Brows; ++n) + for (unsigned int n = 0; n < Brows; ++n) { sum += A[n][r] * B[n][c] * alpha; + } D[r][c] = sum; } + } } template <> inline void GEMM1<2>(const unsigned int &Arows, const unsigned int &Brows, const unsigned int &Bcols, const vpArray2D &A, const vpArray2D &B, const double &alpha, vpArray2D &D) { - for (unsigned int r = 0; r < Arows; ++r) + for (unsigned int r = 0; r < Arows; ++r) { for (unsigned int c = 0; c < Bcols; ++c) { double sum = 0; - for (unsigned int n = 0; n < Brows; ++n) + for (unsigned int n = 0; n < Brows; ++n) { sum += A[r][n] * B[c][n] * alpha; + } D[r][c] = sum; } + } } template <> inline void GEMM1<3>(const unsigned int &Arows, const unsigned int &Brows, const unsigned int &Bcols, const vpArray2D &A, const vpArray2D &B, const double &alpha, vpArray2D &D) { - for (unsigned int r = 0; r < Arows; ++r) + for (unsigned int r = 0; r < Arows; ++r) { for (unsigned int c = 0; c < Bcols; ++c) { double sum = 0; - for (unsigned int n = 0; n < Brows; ++n) + for (unsigned int n = 0; n < Brows; ++n) { sum += A[n][r] * B[c][n] * alpha; + } D[r][c] = sum; } + } } template @@ -208,13 +216,15 @@ inline void GEMM2<0>(const unsigned int &Arows, const unsigned int &Brows, const const vpArray2D &A, const vpArray2D &B, const double &alpha, const vpArray2D &C, const double &beta, vpArray2D &D) { - for (unsigned int r = 0; r < Arows; ++r) + for (unsigned int r = 0; r < Arows; ++r) { for (unsigned int c = 0; c < Bcols; ++c) { double sum = 0; - for (unsigned int n = 0; n < Brows; ++n) + for (unsigned int n = 0; n < Brows; ++n) { sum += A[r][n] * B[n][c] * alpha; - D[r][c] = sum + C[r][c] * beta; + } + D[r][c] = sum + (C[r][c] * beta); } + } } template <> @@ -222,13 +232,15 @@ inline void GEMM2<1>(const unsigned int &Arows, const unsigned int &Brows, const const vpArray2D &A, const vpArray2D &B, const double &alpha, const vpArray2D &C, const double &beta, vpArray2D &D) { - for (unsigned int r = 0; r < Arows; ++r) + for (unsigned int r = 0; r < Arows; ++r) { for (unsigned int c = 0; c < Bcols; ++c) { double sum = 0; - for (unsigned int n = 0; n < Brows; ++n) + for (unsigned int n = 0; n < Brows; ++n) { sum += A[n][r] * B[n][c] * alpha; - D[r][c] = sum + C[r][c] * beta; + } + D[r][c] = sum + (C[r][c] * beta); } + } } template <> @@ -236,13 +248,15 @@ inline void GEMM2<2>(const unsigned int &Arows, const unsigned int &Brows, const const vpArray2D &A, const vpArray2D &B, const double &alpha, const vpArray2D &C, const double &beta, vpArray2D &D) { - for (unsigned int r = 0; r < Arows; ++r) + for (unsigned int r = 0; r < Arows; ++r) { for (unsigned int c = 0; c < Bcols; ++c) { double sum = 0; - for (unsigned int n = 0; n < Brows; ++n) + for (unsigned int n = 0; n < Brows; ++n) { sum += A[r][n] * B[c][n] * alpha; - D[r][c] = sum + C[r][c] * beta; + } + D[r][c] = sum + (C[r][c] * beta); } + } } template <> @@ -250,13 +264,15 @@ inline void GEMM2<3>(const unsigned int &Arows, const unsigned int &Brows, const const vpArray2D &A, const vpArray2D &B, const double &alpha, const vpArray2D &C, const double &beta, vpArray2D &D) { - for (unsigned int r = 0; r < Arows; ++r) + for (unsigned int r = 0; r < Arows; ++r) { for (unsigned int c = 0; c < Bcols; ++c) { double sum = 0; - for (unsigned int n = 0; n < Brows; ++n) + for (unsigned int n = 0; n < Brows; ++n) { sum += A[n][r] * B[c][n] * alpha; - D[r][c] = sum + C[r][c] * beta; + } + D[r][c] = sum + (C[r][c] * beta); } + } } template <> @@ -264,13 +280,15 @@ inline void GEMM2<4>(const unsigned int &Arows, const unsigned int &Brows, const const vpArray2D &A, const vpArray2D &B, const double &alpha, const vpArray2D &C, const double &beta, vpArray2D &D) { - for (unsigned int r = 0; r < Arows; ++r) + for (unsigned int r = 0; r < Arows; ++r) { for (unsigned int c = 0; c < Bcols; ++c) { double sum = 0; - for (unsigned int n = 0; n < Brows; ++n) + for (unsigned int n = 0; n < Brows; ++n) { sum += A[r][n] * B[n][c] * alpha; - D[r][c] = sum + C[c][r] * beta; + } + D[r][c] = sum + (C[c][r] * beta); } + } } template <> @@ -278,13 +296,15 @@ inline void GEMM2<5>(const unsigned int &Arows, const unsigned int &Brows, const const vpArray2D &A, const vpArray2D &B, const double &alpha, const vpArray2D &C, const double &beta, vpArray2D &D) { - for (unsigned int r = 0; r < Arows; ++r) + for (unsigned int r = 0; r < Arows; ++r) { for (unsigned int c = 0; c < Bcols; ++c) { double sum = 0; - for (unsigned int n = 0; n < Brows; ++n) + for (unsigned int n = 0; n < Brows; ++n) { sum += A[n][r] * B[n][c] * alpha; - D[r][c] = sum + C[c][r] * beta; + } + D[r][c] = sum + (C[c][r] * beta); } + } } template <> @@ -292,13 +312,15 @@ inline void GEMM2<6>(const unsigned int &Arows, const unsigned int &Brows, const const vpArray2D &A, const vpArray2D &B, const double &alpha, const vpArray2D &C, const double &beta, vpArray2D &D) { - for (unsigned int r = 0; r < Arows; ++r) + for (unsigned int r = 0; r < Arows; ++r) { for (unsigned int c = 0; c < Bcols; ++c) { double sum = 0; - for (unsigned int n = 0; n < Brows; ++n) + for (unsigned int n = 0; n < Brows; ++n) { sum += A[r][n] * B[c][n] * alpha; - D[r][c] = sum + C[c][r] * beta; + } + D[r][c] = sum + (C[c][r] * beta); } + } } template <> @@ -306,13 +328,15 @@ inline void GEMM2<7>(const unsigned int &Arows, const unsigned int &Brows, const const vpArray2D &A, const vpArray2D &B, const double &alpha, const vpArray2D &C, const double &beta, vpArray2D &D) { - for (unsigned int r = 0; r < Arows; ++r) + for (unsigned int r = 0; r < Arows; ++r) { for (unsigned int c = 0; c < Bcols; ++c) { double sum = 0; - for (unsigned int n = 0; n < Brows; ++n) + for (unsigned int n = 0; n < Brows; ++n) { sum += A[n][r] * B[c][n] * alpha; - D[r][c] = sum + C[c][r] * beta; + } + D[r][c] = sum + (C[c][r] * beta); } + } } template @@ -327,8 +351,9 @@ inline void vpTGEMM(const vpArray2D &A, const vpArray2D &B, cons GEMMsize(A, B, Arows, Acols, Brows, Bcols); try { - if ((Arows != D.getRows()) || (Bcols != D.getCols())) + if ((Arows != D.getRows()) || (Bcols != D.getCols())) { D.resize(Arows, Bcols); + } } catch (...) { throw; diff --git a/modules/core/include/visp3/core/vpGaussianFilter.h b/modules/core/include/visp3/core/vpGaussianFilter.h index a35f8e8f9b..53135dff50 100644 --- a/modules/core/include/visp3/core/vpGaussianFilter.h +++ b/modules/core/include/visp3/core/vpGaussianFilter.h @@ -62,7 +62,7 @@ class VISP_EXPORT vpGaussianFilter virtual ~vpGaussianFilter(); private: - vpGaussianFilter(const vpGaussianFilter &); + vpGaussianFilter(const vpGaussianFilter &gf); vpGaussianFilter &operator=(const vpGaussianFilter &); // PIMPL idiom diff --git a/modules/core/include/visp3/core/vpHomogeneousMatrix.h b/modules/core/include/visp3/core/vpHomogeneousMatrix.h index 93048abda0..cbc386d158 100644 --- a/modules/core/include/visp3/core/vpHomogeneousMatrix.h +++ b/modules/core/include/visp3/core/vpHomogeneousMatrix.h @@ -54,7 +54,6 @@ class vpPoint; #include #include #include -//#include #include #ifdef VISP_HAVE_NLOHMANN_JSON @@ -208,7 +207,7 @@ class VISP_EXPORT vpHomogeneousMatrix : public vpArray2D explicit vpHomogeneousMatrix(const std::vector &v); vpHomogeneousMatrix(double tx, double ty, double tz, double tux, double tuy, double tuz); #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) - vpHomogeneousMatrix(const std::initializer_list &list); + explicit vpHomogeneousMatrix(const std::initializer_list &list); #endif void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R); diff --git a/modules/core/include/visp3/core/vpImage.h b/modules/core/include/visp3/core/vpImage.h index 606992c43c..a3158ec9d9 100644 --- a/modules/core/include/visp3/core/vpImage.h +++ b/modules/core/include/visp3/core/vpImage.h @@ -142,10 +142,10 @@ template class vpImage //! constructor vpImage(); //! copy constructor - vpImage(const vpImage &); + vpImage(const vpImage &img); #if ((__cplusplus >= 201103L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201103L))) // Check if cxx11 or higher //! move constructor - vpImage(vpImage &&); + vpImage(vpImage &&img); #endif //! constructor set the size of the image vpImage(unsigned int height, unsigned int width); @@ -292,10 +292,10 @@ template class vpImage */ inline Type operator()(const vpImagePoint &ip) const { - unsigned int i = (unsigned int)ip.get_i(); - unsigned int j = (unsigned int)ip.get_j(); + unsigned int i = static_cast(ip.get_i()); + unsigned int j = static_cast(ip.get_j()); - return bitmap[i * width + j]; + return bitmap[(i * width) + j]; } /*! @@ -308,10 +308,10 @@ template class vpImage */ inline void operator()(const vpImagePoint &ip, const Type &v) { - unsigned int i = (unsigned int)ip.get_i(); - unsigned int j = (unsigned int)ip.get_j(); + unsigned int i = static_cast(ip.get_i()); + unsigned int j = static_cast(ip.get_j()); - bitmap[i * width + j] = v; + bitmap[(i * width) + j] = v; } vpImage operator-(const vpImage &B) const; @@ -361,16 +361,18 @@ template std::ostream &operator<<(std::ostream &s, const vpImage &I std::ios_base::fmtflags original_flags = s.flags(); - for (unsigned int i = 0; i < I.getHeight(); ++i) { - for (unsigned int j = 0; j < I.getWidth() - 1; ++j) { + unsigned int i_height = I.getHeight(); + unsigned int i_width = I.getWidth(); + for (unsigned int i = 0; i < i_height; ++i) { + for (unsigned int j = 0; j < (i_width - 1); ++j) { s << std::setw(3) << static_cast(I[i][j]) << " "; } @@ -395,7 +399,7 @@ inline std::ostream &operator<<(std::ostream &s, const vpImage &I s << std::setw(3) << static_cast(I[i][I.getWidth() - 1]); // We don't add a \n character at the end of the last row line - if (i < I.getHeight() - 1) { + if (i < (i_height - 1)) { s << std::endl; } } @@ -412,16 +416,18 @@ inline std::ostream &operator<<(std::ostream &s, const vpImage &I) std::ios_base::fmtflags original_flags = s.flags(); - for (unsigned int i = 0; i < I.getHeight(); ++i) { - for (unsigned int j = 0; j < I.getWidth() - 1; ++j) { + unsigned int i_height = I.getHeight(); + unsigned int i_width = I.getWidth(); + for (unsigned int i = 0; i < i_height; ++i) { + for (unsigned int j = 0; j < (i_width - 1); ++j) { s << std::setw(4) << static_cast(I[i][j]) << " "; } // We don't add " " after the last column element - s << std::setw(4) << static_cast(I[i][I.getWidth() - 1]); + s << std::setw(4) << static_cast(I[i][i_width - 1]); // We don't add a \n character at the end of the last row line - if (i < I.getHeight() - 1) { + if (i < (i_height - 1)) { s << std::endl; } } @@ -439,16 +445,18 @@ inline std::ostream &operator<<(std::ostream &s, const vpImage &I) std::ios_base::fmtflags original_flags = s.flags(); s.precision(9); // http://en.cppreference.com/w/cpp/types/numeric_limits/max_digits10 - for (unsigned int i = 0; i < I.getHeight(); ++i) { - for (unsigned int j = 0; j < I.getWidth() - 1; ++j) { + unsigned int i_height = I.getHeight(); + unsigned int i_width = I.getWidth(); + for (unsigned int i = 0; i < i_height; ++i) { + for (unsigned int j = 0; j < (i_width - 1); ++j) { s << I[i][j] << " "; } // We don't add " " after the last column element - s << I[i][I.getWidth() - 1]; + s << I[i][i_width - 1]; // We don't add a \n character at the end of the last row line - if (i < I.getHeight() - 1) { + if (i < (i_height - 1)) { s << std::endl; } } @@ -466,16 +474,18 @@ inline std::ostream &operator<<(std::ostream &s, const vpImage &I) std::ios_base::fmtflags original_flags = s.flags(); s.precision(17); // http://en.cppreference.com/w/cpp/types/numeric_limits/max_digits10 - for (unsigned int i = 0; i < I.getHeight(); ++i) { - for (unsigned int j = 0; j < I.getWidth() - 1; ++j) { + unsigned int i_height = I.getHeight(); + unsigned int i_width = I.getWidth(); + for (unsigned int i = 0; i < i_height; ++i) { + for (unsigned int j = 0; j < (i_width - 1); ++j) { s << I[i][j] << " "; } // We don't add " " after the last column element - s << I[i][I.getWidth() - 1]; + s << I[i][i_width - 1]; // We don't add a \n character at the end of the last row line - if (i < I.getHeight() - 1) { + if (i < (i_height - 1)) { s << std::endl; } } @@ -619,9 +629,10 @@ void performLutRGBaThread(vpImageLutRGBa_Param_t *imageLut_param) template void vpImage::init(unsigned int h, unsigned int w, Type value) { init(h, w); - + /* // for (unsigned int i = 0; i < npixels; ++i) // bitmap[i] = value; + */ std::fill(bitmap, bitmap + npixels, value); } @@ -658,14 +669,16 @@ template void vpImage::init(unsigned int h, unsigned int w) if (bitmap == nullptr) { throw(vpException(vpException::memoryAllocationError, "cannot allocate bitmap ")); } - if (row == nullptr) + if (row == nullptr) { row = new Type *[height]; + } if (row == nullptr) { throw(vpException(vpException::memoryAllocationError, "cannot allocate row ")); } - for (unsigned int i = 0; i < height; ++i) - row[i] = bitmap + i * width; + for (unsigned int i = 0; i < height; ++i) { + row[i] = bitmap + (i * width); + } } /*! @@ -681,7 +694,7 @@ template void vpImage::init(Type *const array, unsigned int h } // Delete bitmap if copyData==false, otherwise only if the dimension differs - if ((copyData && ((h != this->height) || (w != this->width))) || !copyData) { + if ((copyData && ((h != this->height) || (w != this->width))) || (!copyData)) { if (bitmap != nullptr) { if (hasOwnership) { delete[] bitmap; @@ -697,29 +710,31 @@ template void vpImage::init(Type *const array, unsigned int h npixels = width * height; if (copyData) { - if (bitmap == nullptr) + if (bitmap == nullptr) { bitmap = new Type[npixels]; + } if (bitmap == nullptr) { throw(vpException(vpException::memoryAllocationError, "cannot allocate bitmap ")); } // Copy the image data - memcpy(static_cast(bitmap), static_cast(array), (size_t)(npixels * sizeof(Type))); + memcpy(static_cast(bitmap), static_cast(array), static_cast(npixels * sizeof(Type))); } else { // Copy the address of the array in the bitmap bitmap = array; } - if (row == nullptr) + if (row == nullptr) { row = new Type *[height]; + } if (row == nullptr) { throw(vpException(vpException::memoryAllocationError, "cannot allocate row ")); } for (unsigned int i = 0; i < height; ++i) { - row[i] = bitmap + i * width; + row[i] = bitmap + (i * width); } } @@ -873,8 +888,9 @@ vpImage::vpImage(vpImage &&I) */ template Type vpImage::getMaxValue(bool onlyFiniteVal) const { - if (npixels == 0) + if (npixels == 0) { throw(vpException(vpException::fatalError, "Cannot compute maximum value of an empty image")); + } Type m = bitmap[0]; for (unsigned int i = 0; i < npixels; ++i) { if (bitmap[i] > m) { @@ -895,19 +911,22 @@ template Type vpImage::getMaxValue(bool onlyFiniteVal) const */ template <> inline double vpImage::getMaxValue(bool onlyFiniteVal) const { - if (npixels == 0) + if (npixels == 0) { throw(vpException(vpException::fatalError, "Cannot compute maximum value of an empty image")); + } double m = bitmap[0]; if (onlyFiniteVal) { for (unsigned int i = 0; i < npixels; ++i) { - if (bitmap[i] > m && vpMath::isFinite(bitmap[i])) + if ((bitmap[i] > m) && (vpMath::isFinite(bitmap[i]))) { m = bitmap[i]; + } } } else { for (unsigned int i = 0; i < npixels; ++i) { - if (bitmap[i] > m) + if (bitmap[i] > m) { m = bitmap[i]; + } } } return m; @@ -923,19 +942,22 @@ template <> inline double vpImage::getMaxValue(bool onlyFiniteVal) const */ template <> inline float vpImage::getMaxValue(bool onlyFiniteVal) const { - if (npixels == 0) + if (npixels == 0) { throw(vpException(vpException::fatalError, "Cannot compute maximum value of an empty image")); + } float m = bitmap[0]; if (onlyFiniteVal) { for (unsigned int i = 0; i < npixels; ++i) { - if (bitmap[i] > m && vpMath::isFinite(bitmap[i])) + if ((bitmap[i] > m) && (vpMath::isFinite(bitmap[i]))) { m = bitmap[i]; + } } } else { for (unsigned int i = 0; i < npixels; ++i) { - if (bitmap[i] > m) + if (bitmap[i] > m) { m = bitmap[i]; + } } } return m; @@ -1015,7 +1037,7 @@ template double vpImage::getStdev(const double &mean, const v double sum = 0.; unsigned int nbPointsInMask = 0; if (p_mask) { - if (p_mask->getWidth() != width || p_mask->getHeight() != height) { + if ((p_mask->getWidth() != width) || (p_mask->getHeight() != height)) { throw(vpException(vpException::fatalError, "Cannot compute standard deviation: image and mask size differ")); } for (unsigned int i = 0; i < size; ++i) { @@ -1066,7 +1088,7 @@ template <> inline double vpImage::getStdev(const double &mean, const vp double sum = 0.; unsigned int nbPointsInMask = 0; if (p_mask) { - if (p_mask->getWidth() != width || p_mask->getHeight() != height) { + if ((p_mask->getWidth() != width) || (p_mask->getHeight() != height)) { throw(vpException(vpException::fatalError, "Cannot compute standard deviation: image and mask size differ")); } for (unsigned int i = 0; i < size; ++i) { @@ -1118,7 +1140,7 @@ template <> inline double vpImage::getStdev(const double &mean, const vp double sum = 0.; unsigned int nbPointsInMask = 0; if (p_mask) { - if (p_mask->getWidth() != width || p_mask->getHeight() != height) { + if ((p_mask->getWidth() != width) || (p_mask->getHeight() != height)) { throw(vpException(vpException::fatalError, "Cannot compute standard deviation: image and mask size differ")); } for (unsigned int i = 0; i < size; ++i) { @@ -1153,8 +1175,9 @@ template <> inline double vpImage::getStdev(const double &mean, const vp */ template Type vpImage::getMinValue(bool onlyFiniteVal) const { - if (npixels == 0) + if (npixels == 0) { throw(vpException(vpException::fatalError, "Cannot compute minimum value of an empty image")); + } Type m = bitmap[0]; for (unsigned int i = 0; i < npixels; ++i) { if (bitmap[i] < m) { @@ -1175,18 +1198,23 @@ template Type vpImage::getMinValue(bool onlyFiniteVal) const */ template <> inline double vpImage::getMinValue(bool onlyFiniteVal) const { - if (npixels == 0) + if (npixels == 0) { throw(vpException(vpException::fatalError, "Cannot compute minimum value of an empty image")); + } double m = bitmap[0]; if (onlyFiniteVal) { - for (unsigned int i = 0; i < npixels; ++i) - if (bitmap[i] < m && vpMath::isFinite(bitmap[i])) + for (unsigned int i = 0; i < npixels; ++i) { + if ((bitmap[i] < m) && (vpMath::isFinite(bitmap[i]))) { m = bitmap[i]; + } + } } else { - for (unsigned int i = 0; i < npixels; ++i) - if (bitmap[i] < m) + for (unsigned int i = 0; i < npixels; ++i) { + if (bitmap[i] < m) { m = bitmap[i]; + } + } } return m; } @@ -1201,18 +1229,23 @@ template <> inline double vpImage::getMinValue(bool onlyFiniteVal) const */ template <> inline float vpImage::getMinValue(bool onlyFiniteVal) const { - if (npixels == 0) + if (npixels == 0) { throw(vpException(vpException::fatalError, "Cannot compute minimum value of an empty image")); + } float m = bitmap[0]; if (onlyFiniteVal) { - for (unsigned int i = 0; i < npixels; ++i) - if (bitmap[i] < m && vpMath::isFinite(bitmap[i])) + for (unsigned int i = 0; i < npixels; ++i) { + if ((bitmap[i] < m) && (vpMath::isFinite(bitmap[i]))) { m = bitmap[i]; + } + } } else { - for (unsigned int i = 0; i < npixels; ++i) - if (bitmap[i] < m) + for (unsigned int i = 0; i < npixels; ++i) { + if (bitmap[i] < m) { m = bitmap[i]; + } + } } return m; } @@ -1229,15 +1262,19 @@ template <> inline float vpImage::getMinValue(bool onlyFiniteVal) const */ template void vpImage::getMinMaxValue(Type &min, Type &max, bool onlyFiniteVal) const { - if (npixels == 0) + if (npixels == 0) { throw(vpException(vpException::fatalError, "Cannot get minimum/maximum values of an empty image")); + } - min = max = bitmap[0]; + min = bitmap[0]; + max = bitmap[0]; for (unsigned int i = 0; i < npixels; ++i) { - if (bitmap[i] < min) + if (bitmap[i] < min) { min = bitmap[i]; - if (bitmap[i] > max) + } + if (bitmap[i] > max) { max = bitmap[i]; + } } (void)onlyFiniteVal; } @@ -1255,26 +1292,32 @@ template void vpImage::getMinMaxValue(Type &min, Type &max, b */ template <> inline void vpImage::getMinMaxValue(double &min, double &max, bool onlyFiniteVal) const { - if (npixels == 0) + if (npixels == 0) { throw(vpException(vpException::fatalError, "Cannot get minimum/maximum values of an empty image")); + } - min = max = bitmap[0]; + min = bitmap[0]; + max = bitmap[0]; if (onlyFiniteVal) { for (unsigned int i = 0; i < npixels; ++i) { if (vpMath::isFinite(bitmap[i])) { - if (bitmap[i] < min) + if (bitmap[i] < min) { min = bitmap[i]; - if (bitmap[i] > max) + } + if (bitmap[i] > max) { max = bitmap[i]; + } } } } else { for (unsigned int i = 0; i < npixels; ++i) { - if (bitmap[i] < min) + if (bitmap[i] < min) { min = bitmap[i]; - if (bitmap[i] > max) + } + if (bitmap[i] > max) { max = bitmap[i]; + } } } } @@ -1292,26 +1335,32 @@ template <> inline void vpImage::getMinMaxValue(double &min, double &max */ template <> inline void vpImage::getMinMaxValue(float &min, float &max, bool onlyFiniteVal) const { - if (npixels == 0) + if (npixels == 0) { throw(vpException(vpException::fatalError, "Cannot get minimum/maximum values of an empty image")); + } - min = max = bitmap[0]; + min = bitmap[0]; + max = bitmap[0]; if (onlyFiniteVal) { for (unsigned int i = 0; i < npixels; ++i) { if (vpMath::isFinite(bitmap[i])) { - if (bitmap[i] < min) + if (bitmap[i] < min) { min = bitmap[i]; - if (bitmap[i] > max) + } + if (bitmap[i] > max) { max = bitmap[i]; + } } } } else { for (unsigned int i = 0; i < npixels; ++i) { - if (bitmap[i] < min) + if (bitmap[i] < min) { min = bitmap[i]; - if (bitmap[i] > max) + } + if (bitmap[i] > max) { max = bitmap[i]; + } } } } @@ -1328,48 +1377,62 @@ template <> inline void vpImage::getMinMaxValue(float &min, float &max, b */ template <> inline void vpImage::getMinMaxValue(vpRGBf &min, vpRGBf &max, bool onlyFiniteVal) const { - if (npixels == 0) + if (npixels == 0) { throw(vpException(vpException::fatalError, "Cannot get minimum/maximum values of an empty image")); + } - min = max = bitmap[0]; + min = bitmap[0]; + max = bitmap[0]; if (onlyFiniteVal) { for (unsigned int i = 0; i < npixels; ++i) { if (vpMath::isFinite(bitmap[i].R)) { - if (bitmap[i].R < min.R) + if (bitmap[i].R < min.R) { min.R = bitmap[i].R; - if (bitmap[i].R > max.R) + } + if (bitmap[i].R > max.R) { max.R = bitmap[i].R; + } } if (vpMath::isFinite(bitmap[i].G)) { - if (bitmap[i].G < min.G) + if (bitmap[i].G < min.G) { min.G = bitmap[i].G; - if (bitmap[i].G > max.G) + } + if (bitmap[i].G > max.G) { max.G = bitmap[i].G; + } } if (vpMath::isFinite(bitmap[i].B)) { - if (bitmap[i].B < min.B) + if (bitmap[i].B < min.B) { min.B = bitmap[i].B; - if (bitmap[i].B > max.B) + } + if (bitmap[i].B > max.B) { max.B = bitmap[i].B; + } } } } else { for (unsigned int i = 0; i < npixels; ++i) { - if (bitmap[i].R < min.R) + if (bitmap[i].R < min.R) { min.R = bitmap[i].R; - if (bitmap[i].R > max.R) + } + if (bitmap[i].R > max.R) { max.R = bitmap[i].R; + } - if (bitmap[i].G < min.G) + if (bitmap[i].G < min.G) { min.G = bitmap[i].G; - if (bitmap[i].G > max.G) + } + if (bitmap[i].G > max.G) { max.G = bitmap[i].G; + } - if (bitmap[i].B < min.B) + if (bitmap[i].B < min.B) { min.B = bitmap[i].B; - if (bitmap[i].B > max.B) + } + if (bitmap[i].B > max.B) { max.B = bitmap[i].B; + } } } } @@ -1398,9 +1461,10 @@ template <> inline void vpImage::getMinMaxValue(vpRGBf &min, vpRGBf &max template void vpImage::getMinMaxLoc(vpImagePoint *minLoc, vpImagePoint *maxLoc, Type *minVal, Type *maxVal) const { - if (npixels == 0) + if (npixels == 0) { throw(vpException(vpException::fatalError, "Cannot get location of minimum/maximum " "values of an empty image")); + } Type min = bitmap[0], max = bitmap[0]; vpImagePoint minLoc_, maxLoc_; @@ -1418,17 +1482,21 @@ void vpImage::getMinMaxLoc(vpImagePoint *minLoc, vpImagePoint *maxLoc, Typ } } - if (minLoc != nullptr) + if (minLoc != nullptr) { *minLoc = minLoc_; + } - if (maxLoc != nullptr) + if (maxLoc != nullptr) { *maxLoc = maxLoc_; + } - if (minVal != nullptr) + if (minVal != nullptr) { *minVal = min; + } - if (maxVal != nullptr) + if (maxVal != nullptr) { *maxVal = max; + } } /*! @@ -1437,8 +1505,9 @@ void vpImage::getMinMaxLoc(vpImagePoint *minLoc, vpImagePoint *maxLoc, Typ template vpImage &vpImage::operator=(vpImage other) { swap(*this, other); - if (other.display != nullptr) + if (other.display != nullptr) { display = other.display; + } return *this; } @@ -1451,8 +1520,9 @@ template vpImage &vpImage::operator=(vpImage othe */ template vpImage &vpImage::operator=(const Type &v) { - for (unsigned int i = 0; i < npixels; ++i) + for (unsigned int i = 0; i < npixels; ++i) { bitmap[i] = v; + } return *this; } @@ -1464,17 +1534,23 @@ template vpImage &vpImage::operator=(const Type &v) */ template bool vpImage::operator==(const vpImage &I) const { - if (this->width != I.getWidth()) + if (this->width != I.getWidth()) { return false; - if (this->height != I.getHeight()) + } + if (this->height != I.getHeight()) { return false; + } + /* // printf("wxh: %dx%d bitmap: %p I.bitmap %p\n", width, height, bitmap, // I.bitmap); + */ for (unsigned int i = 0; i < npixels; ++i) { if (bitmap[i] != I.bitmap[i]) { + /* // std::cout << "differ for pixel " << i << " (" << i%this->height // << ", " << i - i%this->height << ")" << std::endl; + */ return false; } } @@ -1532,48 +1608,57 @@ template vpImage vpImage::operator-(const vpImage */ template void vpImage::insert(const vpImage &src, const vpImagePoint &topLeft) { - int itl = (int)topLeft.get_i(); - int jtl = (int)topLeft.get_j(); + int itl = static_cast(topLeft.get_i()); + int jtl = static_cast(topLeft.get_j()); int dest_ibegin = 0; int dest_jbegin = 0; int src_ibegin = 0; int src_jbegin = 0; - int dest_w = (int)this->getWidth(); - int dest_h = (int)this->getHeight(); - int src_w = (int)src.getWidth(); - int src_h = (int)src.getHeight(); - int wsize = (int)src.getWidth(); - int hsize = (int)src.getHeight(); - - if (itl >= dest_h || jtl >= dest_w) + int dest_w = static_cast(this->getWidth()); + int dest_h = static_cast(this->getHeight()); + int src_w = static_cast(src.getWidth()); + int src_h = static_cast(src.getHeight()); + int wsize = static_cast(src.getWidth()); + int hsize = static_cast(src.getHeight()); + + if ((itl >= dest_h) || (jtl >= dest_w)) { return; + } - if (itl < 0) + if (itl < 0) { src_ibegin = -itl; - else + } + else { dest_ibegin = itl; + } - if (jtl < 0) + if (jtl < 0) { src_jbegin = -jtl; - else + } + else { dest_jbegin = jtl; + } - if (src_w - src_jbegin > dest_w - dest_jbegin) + if ((src_w - src_jbegin) >(dest_w - dest_jbegin)) { wsize = dest_w - dest_jbegin; - else + } + else { wsize = src_w - src_jbegin; + } - if (src_h - src_ibegin > dest_h - dest_ibegin) + if ((src_h - src_ibegin) > (dest_h - dest_ibegin)) { hsize = dest_h - dest_ibegin; - else + } + else { hsize = src_h - src_ibegin; + } for (int i = 0; i < hsize; ++i) { - Type *srcBitmap = src.bitmap + ((src_ibegin + i) * src_w + src_jbegin); - Type *destBitmap = this->bitmap + ((dest_ibegin + i) * dest_w + dest_jbegin); + Type *srcBitmap = src.bitmap + (((src_ibegin + i) * src_w) + src_jbegin); + Type *destBitmap = this->bitmap + (((dest_ibegin + i) * dest_w) + dest_jbegin); - memcpy(static_cast(destBitmap), static_cast(srcBitmap), (size_t)wsize * sizeof(Type)); + memcpy(static_cast(destBitmap), static_cast(srcBitmap), static_cast(wsize) * sizeof(Type)); } } @@ -1612,9 +1697,11 @@ template void vpImage::halfSizeImage(vpImage &res) cons unsigned int h = height / 2; unsigned int w = width / 2; res.resize(h, w); - for (unsigned int i = 0; i < h; ++i) - for (unsigned int j = 0; j < w; ++j) + for (unsigned int i = 0; i < h; ++i) { + for (unsigned int j = 0; j < w; ++j) { res[i][j] = (*this)[i << 1][j << 1]; + } + } } /*! @@ -1637,16 +1724,18 @@ template void vpImage::halfSizeImage(vpImage &res) cons template void vpImage::subsample(unsigned int v_scale, unsigned int h_scale, vpImage &sampled) const { - if (v_scale == 1 && h_scale == 1) { + if ((v_scale == 1) && (h_scale == 1)) { sampled = (*this); return; } unsigned int h = height / v_scale; unsigned int w = width / h_scale; sampled.resize(h, w); - for (unsigned int i = 0; i < h; ++i) - for (unsigned int j = 0; j < w; ++j) + for (unsigned int i = 0; i < h; ++i) { + for (unsigned int j = 0; j < w; ++j) { sampled[i][j] = (*this)[i * v_scale][j * h_scale]; + } + } } /*! @@ -1676,9 +1765,11 @@ template void vpImage::quarterSizeImage(vpImage &res) c unsigned int h = height / 4; unsigned int w = width / 4; res.resize(h, w); - for (unsigned int i = 0; i < h; ++i) - for (unsigned int j = 0; j < w; ++j) + for (unsigned int i = 0; i < h; ++i) { + for (unsigned int j = 0; j < w; ++j) { res[i][j] = (*this)[i << 2][j << 2]; + } + } } /*! @@ -1720,9 +1811,11 @@ template void vpImage::doubleSizeImage(vpImage &res) res.resize(h, w); - for (int i = 0; i < h; ++i) - for (int j = 0; j < w; ++j) + for (int i = 0; i < h; ++i) { + for (int j = 0; j < w; ++j) { res[i][j] = (*this)[i >> 1][j >> 1]; + } + } /* A B C @@ -1733,20 +1826,26 @@ template void vpImage::doubleSizeImage(vpImage &res) */ // interpolate pixels B and I - for (int i = 0; i < h; i += 2) - for (int j = 1; j < w - 1; j += 2) + for (int i = 0; i < h; i += 2) { + for (int j = 1; j < (w - 1); j += 2) { res[i][j] = (Type)(0.5 * ((*this)[i >> 1][j >> 1] + (*this)[i >> 1][(j >> 1) + 1])); + } + } // interpolate pixels E and G - for (int i = 1; i < h - 1; i += 2) - for (int j = 0; j < w; j += 2) + for (int i = 1; i < (h - 1); i += 2) { + for (int j = 0; j < w; j += 2) { res[i][j] = (Type)(0.5 * ((*this)[i >> 1][j >> 1] + (*this)[(i >> 1) + 1][j >> 1])); + } + } // interpolate pixel F - for (int i = 1; i < h - 1; i += 2) - for (int j = 1; j < w - 1; j += 2) + for (int i = 1; i < (h - 1); i += 2) { + for (int j = 1; j < (w - 1); j += 2) { res[i][j] = (Type)(0.25 * ((*this)[i >> 1][j >> 1] + (*this)[i >> 1][(j >> 1) + 1] + (*this)[(i >> 1) + 1][j >> 1] + (*this)[(i >> 1) + 1][(j >> 1) + 1])); + } + } } /*! @@ -1763,7 +1862,7 @@ template void vpImage::doubleSizeImage(vpImage &res) */ template inline Type vpImage::getValue(unsigned int i, unsigned int j) const { - if (i >= height || j >= width) { + if ((i >= height) || (j >= width)) { throw(vpException(vpImageException::notInTheImage, "Pixel outside the image")); } @@ -1788,10 +1887,10 @@ template inline Type vpImage::getValue(unsigned int i, unsign */ template Type vpImage::getValue(double i, double j) const { - if (i < 0 || j < 0 || i + 1 > height || j + 1 > width) { + if ((i < 0) || (j < 0) || ((i + 1) > height) || ((j + 1) > width)) { throw(vpException(vpImageException::notInTheImage, "Pixel outside of the image")); } - if (height * width == 0) { + if ((height * width) == 0) { throw vpException(vpImageException::notInitializedError, "Empty image!"); } @@ -1808,9 +1907,9 @@ template Type vpImage::getValue(double i, double j) const unsigned int jround_1 = std::min(width - 1, jround + 1); double value = - (static_cast(row[iround][jround]) * rfrac + static_cast(row[iround_1][jround]) * rratio) * cfrac + - (static_cast(row[iround][jround_1]) * rfrac + static_cast(row[iround_1][jround_1]) * rratio) * - cratio; + (((static_cast(row[iround][jround]) * rfrac) + (static_cast(row[iround_1][jround]) * rratio)) * cfrac) + + (((static_cast(row[iround][jround_1]) * rfrac) + (static_cast(row[iround_1][jround_1]) * rratio)) * + cratio); return static_cast(vpMath::round(value)); } @@ -1820,10 +1919,10 @@ template Type vpImage::getValue(double i, double j) const */ template <> inline double vpImage::getValue(double i, double j) const { - if (i < 0 || j < 0 || i + 1 > height || j + 1 > width) { + if ((i < 0) || (j < 0) || ((i + 1) > height) || ((j + 1) > width)) { throw(vpException(vpImageException::notInTheImage, "Pixel outside of the image")); } - if (height * width == 0) { + if ((height * width) == 0) { throw vpException(vpImageException::notInitializedError, "Empty image!"); } @@ -1839,8 +1938,8 @@ template <> inline double vpImage::getValue(double i, double j) const unsigned int iround_1 = std::min(height - 1, iround + 1); unsigned int jround_1 = std::min(width - 1, jround + 1); - return (row[iround][jround] * rfrac + row[iround_1][jround] * rratio) * cfrac + - (row[iround][jround_1] * rfrac + row[iround_1][jround_1] * rratio) * cratio; + return (((row[iround][jround] * rfrac) + (row[iround_1][jround] * rratio)) * cfrac) + + (((row[iround][jround_1] * rfrac) + (row[iround_1][jround_1] * rratio)) * cratio); } /*! @@ -1848,10 +1947,10 @@ template <> inline double vpImage::getValue(double i, double j) const */ template <> inline unsigned char vpImage::getValue(double i, double j) const { - if (i < 0 || j < 0 || i + 1 > height || j + 1 > width) { + if ((i < 0) || (j < 0) || ((i + 1) > height) || ((j + 1) > width)) { throw(vpException(vpImageException::notInTheImage, "Pixel outside of the image")); } - if (height * width == 0) { + if ((height * width) == 0) { throw vpException(vpImageException::notInitializedError, "Empty image!"); } @@ -1874,7 +1973,7 @@ template <> inline unsigned char vpImage::getValue(double i, doub int64_t x_ = x >> 16; int64_t y_ = y >> 16; - if (y_ + 1 < height && x_ + 1 < width) { + if (((y_ + 1) < height) && ((x_ + 1) < width)) { uint16_t up = vpEndian::reinterpret_cast_uchar_to_uint16_LE(bitmap + y_ * width + x_); uint16_t down = vpEndian::reinterpret_cast_uchar_to_uint16_LE(bitmap + (y_ + 1) * width + x_); @@ -1882,10 +1981,10 @@ template <> inline unsigned char vpImage::getValue(double i, doub ((up >> 8) * rfrac + (down >> 8) * rratio) * cratio) >> 32); } - else if (y_ + 1 < height) { + else if ((y_ + 1) < height) { return static_cast(((row[y_][x_] * rfrac + row[y_ + 1][x_] * rratio)) >> 16); } - else if (x_ + 1 < width) { + else if ((x_ + 1) < width) { uint16_t up = vpEndian::reinterpret_cast_uchar_to_uint16_LE(bitmap + y_ * width + x_); return static_cast(((up & 0x00FF) * cfrac + (up >> 8) * cratio) >> 16); } @@ -1923,10 +2022,10 @@ template <> inline unsigned char vpImage::getValue(double i, doub */ template <> inline vpRGBa vpImage::getValue(double i, double j) const { - if (i < 0 || j < 0 || i + 1 > height || j + 1 > width) { + if ((i < 0) || (j < 0) || ((i + 1) > height) || ((j + 1) > width)) { throw(vpException(vpImageException::notInTheImage, "Pixel outside of the image")); } - if (height * width == 0) { + if ((height * width) == 0) { throw vpException(vpImageException::notInitializedError, "Empty image!"); } @@ -1943,20 +2042,20 @@ template <> inline vpRGBa vpImage::getValue(double i, double j) const unsigned int jround_1 = std::min(width - 1, jround + 1); double valueR = - (static_cast(row[iround][jround].R) * rfrac + static_cast(row[iround_1][jround].R) * rratio) * - cfrac + - (static_cast(row[iround][jround_1].R) * rfrac + static_cast(row[iround_1][jround_1].R) * rratio) * - cratio; + (((static_cast(row[iround][jround].R) * rfrac) + (static_cast(row[iround_1][jround].R) * rratio)) * + cfrac) + + (((static_cast(row[iround][jround_1].R) * rfrac) + (static_cast(row[iround_1][jround_1].R) * rratio)) * + cratio); double valueG = - (static_cast(row[iround][jround].G) * rfrac + static_cast(row[iround_1][jround].G) * rratio) * - cfrac + - (static_cast(row[iround][jround_1].G) * rfrac + static_cast(row[iround_1][jround_1].G) * rratio) * - cratio; + (((static_cast(row[iround][jround].G) * rfrac) + (static_cast(row[iround_1][jround].G) * rratio)) * + cfrac) + + (((static_cast(row[iround][jround_1].G) * rfrac) + (static_cast(row[iround_1][jround_1].G) * rratio)) * + cratio); double valueB = - (static_cast(row[iround][jround].B) * rfrac + static_cast(row[iround_1][jround].B) * rratio) * - cfrac + - (static_cast(row[iround][jround_1].B) * rfrac + static_cast(row[iround_1][jround_1].B) * rratio) * - cratio; + (((static_cast(row[iround][jround].B) * rfrac) + (static_cast(row[iround_1][jround].B) * rratio)) * + cfrac) + + (((static_cast(row[iround][jround_1].B) * rfrac) + (static_cast(row[iround_1][jround_1].B) * rratio)) * + cratio); return vpRGBa(static_cast(vpMath::round(valueR)), static_cast(vpMath::round(valueG)), static_cast(vpMath::round(valueB))); @@ -1967,10 +2066,10 @@ template <> inline vpRGBa vpImage::getValue(double i, double j) const */ template <> inline vpRGBf vpImage::getValue(double i, double j) const { - if (i < 0 || j < 0 || i + 1 > height || j + 1 > width) { + if ((i < 0) || (j < 0) || ((i + 1) > height) || ((j + 1) > width)) { throw(vpException(vpImageException::notInTheImage, "Pixel outside of the image")); } - if (height * width == 0) { + if ((height * width) == 0) { throw vpException(vpImageException::notInitializedError, "Empty image!"); } @@ -1987,20 +2086,20 @@ template <> inline vpRGBf vpImage::getValue(double i, double j) const unsigned int jround_1 = std::min(width - 1, jround + 1); double valueR = - (static_cast(row[iround][jround].R) * rfrac + static_cast(row[iround_1][jround].R) * rratio) * - cfrac + - (static_cast(row[iround][jround_1].R) * rfrac + static_cast(row[iround_1][jround_1].R) * rratio) * - cratio; + (((static_cast(row[iround][jround].R) * rfrac) + (static_cast(row[iround_1][jround].R) * rratio)) * + cfrac) + + (((static_cast(row[iround][jround_1].R) * rfrac) + (static_cast(row[iround_1][jround_1].R) * rratio)) * + cratio); double valueG = - (static_cast(row[iround][jround].G) * rfrac + static_cast(row[iround_1][jround].G) * rratio) * - cfrac + - (static_cast(row[iround][jround_1].G) * rfrac + static_cast(row[iround_1][jround_1].G) * rratio) * - cratio; + (((static_cast(row[iround][jround].G) * rfrac) + (static_cast(row[iround_1][jround].G) * rratio)) * + cfrac) + + (((static_cast(row[iround][jround_1].G) * rfrac) + (static_cast(row[iround_1][jround_1].G) * rratio)) * + cratio); double valueB = - (static_cast(row[iround][jround].B) * rfrac + static_cast(row[iround_1][jround].B) * rratio) * - cfrac + - (static_cast(row[iround][jround_1].B) * rfrac + static_cast(row[iround_1][jround_1].B) * rratio) * - cratio; + (((static_cast(row[iround][jround].B) * rfrac) + (static_cast(row[iround_1][jround].B) * rratio)) * + cfrac) + + (((static_cast(row[iround][jround_1].B) * rfrac) + (static_cast(row[iround_1][jround_1].B) * rratio)) * + cratio); return vpRGBf(static_cast(valueR), static_cast(valueG), static_cast(valueB)); } @@ -2070,7 +2169,7 @@ template inline double vpImage::getSum(const vpImage *p return 0.0; } if (p_mask) { - if (p_mask->getWidth() != width || p_mask->getHeight() != height) { + if ((p_mask->getWidth() != width) || (p_mask->getHeight() != height)) { throw(vpException(vpException::fatalError, "Cannot compute sum: image and mask size differ")); } } @@ -2119,7 +2218,7 @@ template <> inline double vpImage::getSum(const vpImage *p_mask, u unsigned int nbPointsInMask = 0; unsigned int size = height * width; if (p_mask) { - if (p_mask->getWidth() != width || p_mask->getHeight() != height) { + if ((p_mask->getWidth() != width) || (p_mask->getHeight() != height)) { throw(vpException(vpException::fatalError, "Cannot compute sum: image and mask size differ")); } for (unsigned int i = 0; i < size; ++i) { @@ -2130,7 +2229,7 @@ template <> inline double vpImage::getSum(const vpImage *p_mask, u } } else { - for (unsigned int i = 0; i < height * width; ++i) { + for (unsigned int i = 0; i < (height * width); ++i) { res += static_cast(bitmap[i].R) + static_cast(bitmap[i].G) + static_cast(bitmap[i].B); } nbPointsInMask = size; @@ -2161,7 +2260,7 @@ template <> inline double vpImage::getSum(const vpImage *p_mask, u unsigned int nbPointsInMask = 0; unsigned int size = height * width; if (p_mask) { - if (p_mask->getWidth() != width || p_mask->getHeight() != height) { + if ((p_mask->getWidth() != width) || (p_mask->getHeight() != height)) { throw(vpException(vpException::fatalError, "Cannot compute sum: image and mask size differ")); } for (unsigned int i = 0; i < size; ++i) { @@ -2172,7 +2271,7 @@ template <> inline double vpImage::getSum(const vpImage *p_mask, u } } else { - for (unsigned int i = 0; i < height * width; ++i) { + for (unsigned int i = 0; i < (height * width); ++i) { res += static_cast(bitmap[i].R) + static_cast(bitmap[i].G) + static_cast(bitmap[i].B); } nbPointsInMask = size; @@ -2217,8 +2316,9 @@ template void vpImage::sub(const vpImage &B, vpImagegetHeight() != C.getHeight()) || (this->getWidth() != C.getWidth())) + if ((this->getHeight() != C.getHeight()) || (this->getWidth() != C.getWidth())) { C.resize(this->getHeight(), this->getWidth()); + } } catch (const vpException &me) { std::cout << me << std::endl; @@ -2229,7 +2329,9 @@ template void vpImage::sub(const vpImage &B, vpImagegetWidth() * this->getHeight(); ++i) { + unsigned int this_width = this->getWidth(); + unsigned int this_height = this->getHeight(); + for (unsigned int i = 0; i < (this_width * this_height); ++i) { *(C.bitmap + i) = *(bitmap + i) - *(B.bitmap + i); } } @@ -2249,8 +2351,9 @@ template void vpImage::sub(const vpImage &A, const vpIm { try { - if ((A.getHeight() != C.getHeight()) || (A.getWidth() != C.getWidth())) + if ((A.getHeight() != C.getHeight()) || (A.getWidth() != C.getWidth())) { C.resize(A.getHeight(), A.getWidth()); + } } catch (const vpException &me) { std::cout << me << std::endl; @@ -2261,7 +2364,9 @@ template void vpImage::sub(const vpImage &A, const vpIm throw(vpException(vpException::memoryAllocationError, "vpImage mismatch in vpImage/vpImage subtraction ")); } - for (unsigned int i = 0; i < A.getWidth() * A.getHeight(); ++i) { + unsigned int a_width = A.getWidth(); + unsigned int a_height = A.getHeight(); + for (unsigned int i = 0; i < (a_width * a_height); ++i) { *(C.bitmap + i) = *(A.bitmap + i) - *(B.bitmap + i); } } @@ -2292,16 +2397,16 @@ template void vpImage::performLut(const Type(&)[256], unsigne template <> inline void vpImage::performLut(const unsigned char(&lut)[256], unsigned int nbThreads) { unsigned int size = getWidth() * getHeight(); - unsigned char *ptrStart = (unsigned char *)bitmap; + unsigned char *ptrStart = static_cast(bitmap); unsigned char *ptrEnd = ptrStart + size; unsigned char *ptrCurrent = ptrStart; - bool use_single_thread = (nbThreads == 0 || nbThreads == 1); + bool use_single_thread = ((nbThreads == 0) || (nbThreads == 1)); #if !defined(VISP_HAVE_THREADS) use_single_thread = true; #endif - if (!use_single_thread && getSize() <= nbThreads) { + if ((!use_single_thread) && (getSize() <= nbThreads)) { use_single_thread = true; } @@ -2371,16 +2476,16 @@ template <> inline void vpImage::performLut(const unsigned char(& template <> inline void vpImage::performLut(const vpRGBa(&lut)[256], unsigned int nbThreads) { unsigned int size = getWidth() * getHeight(); - unsigned char *ptrStart = (unsigned char *)bitmap; - unsigned char *ptrEnd = ptrStart + size * 4; + unsigned char *ptrStart = reinterpret_cast(bitmap); + unsigned char *ptrEnd = ptrStart + (size * 4); unsigned char *ptrCurrent = ptrStart; - bool use_single_thread = (nbThreads == 0 || nbThreads == 1); + bool use_single_thread = ((nbThreads == 0) || (nbThreads == 1)); #if !defined(VISP_HAVE_THREADS) use_single_thread = true; #endif - if (!use_single_thread && getSize() <= nbThreads) { + if ((!use_single_thread) && (getSize() <= nbThreads)) { use_single_thread = true; } diff --git a/modules/core/include/visp3/core/vpImageConvert.h b/modules/core/include/visp3/core/vpImageConvert.h index baa0ad5ff1..e5b3b02d36 100644 --- a/modules/core/include/visp3/core/vpImageConvert.h +++ b/modules/core/include/visp3/core/vpImageConvert.h @@ -192,9 +192,9 @@ class VISP_EXPORT vpImageConvert dg = dg > 255. ? 255. : dg; db = db > 255. ? 255. : db; - r = (unsigned char)dr; - g = (unsigned char)dg; - b = (unsigned char)db; + r = static_cast(dr); + g = static_cast(dg); + b = static_cast(db); } static void YUYVToRGBa(unsigned char *yuyv, unsigned char *rgba, unsigned int width, unsigned int height); static void YUYVToRGB(unsigned char *yuyv, unsigned char *rgb, unsigned int width, unsigned int height); diff --git a/modules/core/include/visp3/core/vpImageFilter.h b/modules/core/include/visp3/core/vpImageFilter.h index 2c658e9ed6..4ed8c57ef7 100644 --- a/modules/core/include/visp3/core/vpImageFilter.h +++ b/modules/core/include/visp3/core/vpImageFilter.h @@ -441,7 +441,7 @@ class VISP_EXPORT vpImageFilter float tf = static_cast(hist[i]); accu = accu + tf; if (accu > t) { - bon = (float)i; + bon = static_cast(i); break; } } @@ -459,8 +459,8 @@ class VISP_EXPORT vpImageFilter */ template static double derivativeFilterX(const vpImage &I, unsigned int r, unsigned int c) { - return (2047.0 * static_cast(I[r][c + 1] - I[r][c - 1]) + 913.0 * static_cast(I[r][c + 2] - I[r][c - 2]) + - 112.0 * static_cast(I[r][c + 3] - I[r][c - 3])) / 8418.0; + return ((2047.0 * static_cast(I[r][c + 1] - I[r][c - 1])) + (913.0 * static_cast(I[r][c + 2] - I[r][c - 2])) + + (112.0 * static_cast(I[r][c + 3] - I[r][c - 3]))) / 8418.0; } /*! @@ -472,8 +472,8 @@ class VISP_EXPORT vpImageFilter */ template static double derivativeFilterY(const vpImage &I, unsigned int r, unsigned int c) { - return (2047.0 * static_cast(I[r + 1][c] - I[r - 1][c]) + 913.0 * static_cast(I[r + 2][c] - I[r - 2][c]) + - 112.0 * static_cast(I[r + 3][c] - I[r - 3][c])) / 8418.0; + return ((2047.0 * static_cast(I[r + 1][c] - I[r - 1][c])) + (913.0 * static_cast(I[r + 2][c] - I[r - 2][c])) + + (112.0 * static_cast(I[r + 3][c] - I[r - 3][c]))) / 8418.0; } /*! @@ -584,7 +584,7 @@ class VISP_EXPORT vpImageFilter for (unsigned int a = 0; a < size_y; ++a) { for (unsigned int b = 0; b < size_x; ++b) { - FilterType val = static_cast(I[i + half_size_y - a][j + half_size_x - b]); // Convolution + FilterType val = static_cast(I[(i + half_size_y) - a][(j + half_size_x) - b]); // Convolution conv += M[a][b] * val; } } @@ -606,7 +606,7 @@ class VISP_EXPORT vpImageFilter for (unsigned int a = 0; a < size_y; ++a) { for (unsigned int b = 0; b < size_x; ++b) { - FilterType val = static_cast(I[i - half_size_y + a][j - half_size_x + b]); // Correlation + FilterType val = static_cast(I[(i - half_size_y) + a][(j - half_size_x) + b]); // Correlation corr += M[a][b] * val; } } @@ -663,7 +663,7 @@ class VISP_EXPORT vpImageFilter for (unsigned int a = 0; a < size; ++a) { for (unsigned int b = 0; b < size; ++b) { - FilterType val = static_cast(I[v + half_size - a][u + half_size - b]); // Convolution + FilterType val = static_cast(I[(v + half_size) - a][(u + half_size) - b]); // Convolution conv_u += M[a][b] * val; conv_v += M[b][a] * val; } @@ -687,7 +687,7 @@ class VISP_EXPORT vpImageFilter for (unsigned int a = 0; a < size; ++a) { for (unsigned int b = 0; b < size; ++b) { - FilterType val = static_cast(I[v - half_size + a][u - half_size + b]); // Correlation + FilterType val = static_cast(I[(v - half_size) + a][(u - half_size) + b]); // Correlation conv_u += M[a][b] * val; conv_v += M[b][a] * val; } @@ -736,11 +736,11 @@ class VISP_EXPORT vpImageFilter static inline unsigned char filterGaussXPyramidal(const vpImage &I, unsigned int i, unsigned int j) { - return static_cast((1. * I[i][j - 2] + 4. * I[i][j - 1] + 6. * I[i][j] + 4. * I[i][j + 1] + 1. * I[i][j + 2]) / 16.); + return static_cast(((1. * I[i][j - 2]) + (4. * I[i][j - 1]) + (6. * I[i][j]) + (4. * I[i][j + 1]) + (1. * I[i][j + 2])) / 16.); } static inline unsigned char filterGaussYPyramidal(const vpImage &I, unsigned int i, unsigned int j) { - return static_cast((1. * I[i - 2][j] + 4. * I[i - 1][j] + 6. * I[i][j] + 4. * I[i + 1][j] + 1. * I[i + 2][j]) / 16.); + return static_cast(((1. * I[i - 2][j]) + (4. * I[i - 1][j]) + (6. * I[i][j]) + (4. * I[i + 1][j]) + (1. * I[i + 2][j])) / 16.); } template @@ -750,7 +750,7 @@ class VISP_EXPORT vpImageFilter const unsigned int height = I.getHeight(); const unsigned int width = I.getWidth(); const unsigned int stop1J = (size - 1) / 2; - const unsigned int stop2J = width - (size - 1) / 2; + const unsigned int stop2J = width - ((size - 1) / 2); resizeAndInitializeIfNeeded(p_mask, height, width, dIx); for (unsigned int i = 0; i < height; ++i) { @@ -798,7 +798,7 @@ class VISP_EXPORT vpImageFilter for (unsigned int i = 1; i <= stop; ++i) { result += filter[i] * static_cast(I[r][c + i] + I[r][c - i]); } - return result + filter[0] * static_cast(I[r][c]); + return result + (filter[0] * static_cast(I[r][c])); } #ifndef DOXYGEN_SHOULD_SKIP_THIS @@ -809,7 +809,7 @@ class VISP_EXPORT vpImageFilter for (unsigned int i = 1; i <= stop; ++i) { result += filter[i] * static_cast(I[r][c + i].R + I[r][c - i].R); } - return result + filter[0] * static_cast(I[r][c].R); + return result + (filter[0] * static_cast(I[r][c].R)); } static inline double filterXG(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) @@ -820,7 +820,7 @@ class VISP_EXPORT vpImageFilter for (unsigned int i = 1; i <= stop; ++i) { result += filter[i] * static_cast(I[r][c + i].G + I[r][c - i].G); } - return result + filter[0] * static_cast(I[r][c].G); + return result + (filter[0] * static_cast(I[r][c].G)); } static inline double filterXB(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) @@ -831,7 +831,7 @@ class VISP_EXPORT vpImageFilter for (unsigned int i = 1; i <= stop; ++i) { result += filter[i] * static_cast(I[r][c + i].B + I[r][c - i].B); } - return result + filter[0] * static_cast(I[r][c].B); + return result + (filter[0] * static_cast(I[r][c].B)); } template @@ -849,7 +849,7 @@ class VISP_EXPORT vpImageFilter result += filter[i] * static_cast(I[r][c + i] + I[r][i - c]); } } - return result + filter[0] * static_cast(I[r][c]); + return result + (filter[0] * static_cast(I[r][c])); } static inline double filterXLeftBorderR(const vpImage &I, unsigned int r, unsigned int c, @@ -866,7 +866,7 @@ class VISP_EXPORT vpImageFilter result += filter[i] * static_cast(I[r][c + i].R + I[r][i - c].R); } } - return result + filter[0] * static_cast(I[r][c].R); + return result + (filter[0] * static_cast(I[r][c].R)); } static inline double filterXLeftBorderG(const vpImage &I, unsigned int r, unsigned int c, @@ -883,7 +883,7 @@ class VISP_EXPORT vpImageFilter result += filter[i] * static_cast(I[r][c + i].G + I[r][i - c].G); } } - return result + filter[0] * static_cast(I[r][c].G); + return result + (filter[0] * static_cast(I[r][c].G)); } static inline double filterXLeftBorderB(const vpImage &I, unsigned int r, unsigned int c, @@ -900,7 +900,7 @@ class VISP_EXPORT vpImageFilter result += filter[i] * static_cast(I[r][c + i].B + I[r][i - c].B); } } - return result + filter[0] * static_cast(I[r][c].B); + return result + (filter[0] * static_cast(I[r][c].B)); } template @@ -916,10 +916,10 @@ class VISP_EXPORT vpImageFilter result += filter[i] * static_cast(I[r][c + i] + I[r][c - i]); } else { - result += filter[i] * static_cast(I[r][2 * width - c - i - 1] + I[r][c - i]); + result += filter[i] * static_cast(I[r][((2 * width) - c) - i - 1] + I[r][c - i]); } } - return result + filter[0] * static_cast(I[r][c]); + return result + (filter[0] * static_cast(I[r][c])); } static inline double filterXRightBorderR(const vpImage &I, unsigned int r, unsigned int c, @@ -934,10 +934,10 @@ class VISP_EXPORT vpImageFilter result += filter[i] * static_cast(I[r][c + i].R + I[r][c - i].R); } else { - result += filter[i] * static_cast(I[r][2 * width - c - i - 1].R + I[r][c - i].R); + result += filter[i] * static_cast(I[r][((2 * width) - c) - i - 1].R + I[r][c - i].R); } } - return result + filter[0] * static_cast(I[r][c].R); + return result + (filter[0] * static_cast(I[r][c].R)); } static inline double filterXRightBorderG(const vpImage &I, unsigned int r, unsigned int c, @@ -952,10 +952,10 @@ class VISP_EXPORT vpImageFilter result += filter[i] * static_cast(I[r][c + i].G + I[r][c - i].G); } else { - result += filter[i] * static_cast(I[r][2 * width - c - i - 1].G + I[r][c - i].G); + result += filter[i] * static_cast(I[r][((2 * width) - c) - i - 1].G + I[r][c - i].G); } } - return result + filter[0] * static_cast(I[r][c].G); + return result + (filter[0] * static_cast(I[r][c].G)); } static inline double filterXRightBorderB(const vpImage &I, unsigned int r, unsigned int c, @@ -970,10 +970,10 @@ class VISP_EXPORT vpImageFilter result += filter[i] * static_cast(I[r][c + i].B + I[r][c - i].B); } else { - result += filter[i] * static_cast(I[r][2 * width - c - i - 1].B + I[r][c - i].B); + result += filter[i] * static_cast(I[r][(2 * width) - c - i - 1].B + I[r][c - i].B); } } - return result + filter[0] * static_cast(I[r][c].B); + return result + (filter[0] * static_cast(I[r][c].B)); } #endif @@ -992,7 +992,7 @@ class VISP_EXPORT vpImageFilter { const unsigned int height = I.getHeight(), width = I.getWidth(); const unsigned int stop1I = (size - 1) / 2; - const unsigned int stop2I = height - (size - 1) / 2; + const unsigned int stop2I = height - ((size - 1) / 2); resizeAndInitializeIfNeeded(p_mask, height, width, dIy); for (unsigned int i = 0; i < stop1I; ++i) { @@ -1036,7 +1036,7 @@ class VISP_EXPORT vpImageFilter for (unsigned int i = 1; i <= stop; ++i) { result += filter[i] * static_cast(I[r + i][c] + I[r - i][c]); } - return result + filter[0] * static_cast(I[r][c]); + return result + (filter[0] * static_cast(I[r][c])); } #ifndef DOXYGEN_SHOULD_SKIP_THIS static inline double filterYR(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) @@ -1047,7 +1047,7 @@ class VISP_EXPORT vpImageFilter for (unsigned int i = 1; i <= stop; ++i) { result += filter[i] * static_cast(I[r + i][c].R + I[r - i][c].R); } - return result + filter[0] * static_cast(I[r][c].R); + return result + (filter[0] * static_cast(I[r][c].R)); } static inline double filterYG(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) { @@ -1057,7 +1057,7 @@ class VISP_EXPORT vpImageFilter for (unsigned int i = 1; i <= stop; ++i) { result += filter[i] * static_cast(I[r + i][c].G + I[r - i][c].G); } - return result + filter[0] * static_cast(I[r][c].G); + return result + (filter[0] * static_cast(I[r][c].G)); } static inline double filterYB(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) @@ -1068,7 +1068,7 @@ class VISP_EXPORT vpImageFilter for (unsigned int i = 1; i <= stop; ++i) { result += filter[i] * static_cast(I[r + i][c].B + I[r - i][c].B); } - return result + filter[0] * static_cast(I[r][c].B); + return result + (filter[0] * static_cast(I[r][c].B)); } template @@ -1086,7 +1086,7 @@ class VISP_EXPORT vpImageFilter result += filter[i] * static_cast(I[r + i][c] + I[i - r][c]); } } - return result + filter[0] * static_cast(I[r][c]); + return result + (filter[0] * static_cast(I[r][c])); } double static inline filterYTopBorderR(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) @@ -1102,7 +1102,7 @@ class VISP_EXPORT vpImageFilter result += filter[i] * static_cast(I[r + i][c].R + I[i - r][c].R); } } - return result + filter[0] * static_cast(I[r][c].R); + return result + (filter[0] * static_cast(I[r][c].R)); } double static inline filterYTopBorderG(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) @@ -1118,7 +1118,7 @@ class VISP_EXPORT vpImageFilter result += filter[i] * static_cast(I[r + i][c].G + I[i - r][c].G); } } - return result + filter[0] * static_cast(I[r][c].G); + return result + (filter[0] * static_cast(I[r][c].G)); } double static inline filterYTopBorderB(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) @@ -1134,7 +1134,7 @@ class VISP_EXPORT vpImageFilter result += filter[i] * static_cast(I[r + i][c].B + I[i - r][c].B); } } - return result + filter[0] * static_cast(I[r][c].B); + return result + (filter[0] * static_cast(I[r][c].B)); } template @@ -1150,10 +1150,10 @@ class VISP_EXPORT vpImageFilter result += filter[i] * static_cast(I[r + i][c] + I[r - i][c]); } else { - result += filter[i] * static_cast(I[2 * height - r - i - 1][c] + I[r - i][c]); + result += filter[i] * static_cast(I[((2 * height) - r) - i - 1][c] + I[r - i][c]); } } - return result + filter[0] * static_cast(I[r][c]); + return result + (filter[0] * static_cast(I[r][c])); } double static inline filterYBottomBorderR(const vpImage &I, unsigned int r, unsigned int c, @@ -1168,10 +1168,10 @@ class VISP_EXPORT vpImageFilter result += filter[i] * static_cast(I[r + i][c].R + I[r - i][c].R); } else { - result += filter[i] * static_cast(I[2 * height - r - i - 1][c].R + I[r - i][c].R); + result += filter[i] * static_cast(I[((2 * height) - r) - i - 1][c].R + I[r - i][c].R); } } - return result + filter[0] * static_cast(I[r][c].R); + return result + (filter[0] * static_cast(I[r][c].R)); } double static inline filterYBottomBorderG(const vpImage &I, unsigned int r, unsigned int c, @@ -1186,10 +1186,10 @@ class VISP_EXPORT vpImageFilter result += filter[i] * static_cast(I[r + i][c].G + I[r - i][c].G); } else { - result += filter[i] * static_cast(I[2 * height - r - i - 1][c].G + I[r - i][c].G); + result += filter[i] * static_cast(I[((2 * height) - r) - i - 1][c].G + I[r - i][c].G); } } - return result + filter[0] * static_cast(I[r][c].G); + return result + (filter[0] * static_cast(I[r][c].G)); } double static inline filterYBottomBorderB(const vpImage &I, unsigned int r, unsigned int c, @@ -1204,10 +1204,10 @@ class VISP_EXPORT vpImageFilter result += filter[i] * static_cast(I[r + i][c].B + I[r - i][c].B); } else { - result += filter[i] * static_cast(I[2 * height - r - i - 1][c].B + I[r - i][c].B); + result += filter[i] * static_cast(I[((2 * height) - r) - i - 1][c].B + I[r - i][c].B); } } - return result + filter[0] * static_cast(I[r][c].B); + return result + (filter[0] * static_cast(I[r][c].B)); } #endif @@ -1250,12 +1250,13 @@ class VISP_EXPORT vpImageFilter */ template static double gaussianFilter(const vpImage &fr, unsigned int r, unsigned int c) { - return (15.0 * fr[r][c] + 12.0 * (fr[r - 1][c] + fr[r][c - 1] + fr[r + 1][c] + fr[r][c + 1]) + - 9.0 * (fr[r - 1][c - 1] + fr[r + 1][c - 1] + fr[r - 1][c + 1] + fr[r + 1][c + 1]) + - 5.0 * (fr[r - 2][c] + fr[r][c - 2] + fr[r + 2][c] + fr[r][c + 2]) + - 4.0 * (fr[r - 2][c + 1] + fr[r - 2][c - 1] + fr[r - 1][c - 2] + fr[r + 1][c - 2] + fr[r + 2][c - 1] + - fr[r + 2][c + 1] + fr[r - 1][c + 2] + fr[r + 1][c + 2]) + - 2.0 * (fr[r - 2][c - 2] + fr[r + 2][c - 2] + fr[r - 2][c + 2] + fr[r + 2][c + 2])) / 159.0; + return ((15.0 * fr[r][c]) + + (12.0 * (fr[r - 1][c] + fr[r][c - 1] + fr[r + 1][c] + fr[r][c + 1])) + + (9.0 * (fr[r - 1][c - 1] + fr[r + 1][c - 1] + fr[r - 1][c + 1] + fr[r + 1][c + 1])) + + (5.0 * (fr[r - 2][c] + fr[r][c - 2] + fr[r + 2][c] + fr[r][c + 2])) + + (4.0 * (fr[r - 2][c + 1] + fr[r - 2][c - 1] + fr[r - 1][c - 2] + fr[r + 1][c - 2] + fr[r + 2][c - 1] + + fr[r + 2][c + 1] + fr[r - 1][c + 2] + fr[r + 1][c + 2])) + + (2.0 * (fr[r - 2][c - 2] + fr[r + 2][c - 2] + fr[r - 2][c + 2] + fr[r + 2][c + 2]))) / 159.0; } // Gaussian pyramid operation static void getGaussPyramidal(const vpImage &I, vpImage &GI); @@ -1292,9 +1293,9 @@ class VISP_EXPORT vpImageFilter int middle = (static_cast(size) - 1) / 2; FilterType sigma2 = static_cast(vpMath::sqr(sigma)); FilterType coef1 = static_cast(1. / (sigma * sqrt(2. * M_PI))); - FilterType _2_sigma2 = static_cast(2. * sigma2); + FilterType v_2_sigma2 = static_cast(2. * sigma2); for (int i = 0; i <= middle; ++i) { - filter[i] = coef1 * static_cast(exp(-(i * i) / _2_sigma2)); + filter[i] = coef1 * static_cast(exp(-(i * i) / v_2_sigma2)); } if (normalize) { // renormalization @@ -1339,17 +1340,17 @@ class VISP_EXPORT vpImageFilter FilterType sigma2 = static_cast(vpMath::sqr(sigma)); FilterType coef_1 = static_cast(1. / (sigma * sqrt(2. * M_PI))); FilterType coef_1_over_2 = coef_1 / static_cast(2.); - FilterType _2_coef_1 = static_cast(2.) * coef_1; - FilterType _2_sigma2 = static_cast(2. * sigma2); + FilterType v_2_coef_1 = static_cast(2.) * coef_1; + FilterType v_2_sigma2 = static_cast(2. * sigma2); filter[0] = 0.; for (int i = 1; i <= middle; ++i) { - filter[i] = -coef_1_over_2 * (static_cast(exp(-((i + 1) * (i + 1)) / _2_sigma2)) - static_cast(exp(-((i - 1) * (i - 1)) / _2_sigma2))); + filter[i] = -coef_1_over_2 * (static_cast(exp(-((i + 1) * (i + 1)) / v_2_sigma2)) - static_cast(exp(-((i - 1) * (i - 1)) / v_2_sigma2))); } if (normalize) { FilterType sum = 0; for (int i = 1; i <= middle; ++i) { - sum += _2_coef_1 * static_cast(exp(-(i * i) / _2_sigma2)); + sum += v_2_coef_1 * static_cast(exp(-(i * i) / v_2_sigma2)); } sum += coef_1; @@ -1398,7 +1399,7 @@ class VISP_EXPORT vpImageFilter { const unsigned int height = I.getHeight(), width = I.getWidth(); const unsigned int stop1J = (size - 1) / 2; - const unsigned int stop2J = width - (size - 1) / 2; + const unsigned int stop2J = width - ((size - 1) / 2); resizeAndInitializeIfNeeded(p_mask, height, width, dIx); for (unsigned int i = 0; i < height; ++i) { @@ -1492,7 +1493,7 @@ class VISP_EXPORT vpImageFilter { const unsigned int height = I.getHeight(), width = I.getWidth(); const unsigned int stop1I = (size - 1) / 2; - const unsigned int stop2I = height - (size - 1) / 2; + const unsigned int stop2I = height - ((size - 1) / 2); resizeAndInitializeIfNeeded(p_mask, height, width, dIy); for (unsigned int i = 0; i < stop1I; ++i) { @@ -1560,11 +1561,11 @@ class VISP_EXPORT vpImageFilter if (size != 1) { // Size = 1 => kernel_size = 2*1 + 1 = 3 std::stringstream errMsg; - errMsg << "Cannot get Scharr kernel of size " << size * 2 + 1 << " != 3"; + errMsg << "Cannot get Scharr kernel of size " << ((size * 2) + 1) << " != 3"; throw vpException(vpException::dimensionError, errMsg.str()); } - vpArray2D ScharrY(size * 2 + 1, size * 2 + 1); + vpArray2D ScharrY((size * 2) + 1, (size * 2) + 1); FilterType norm = getScharrKernelY(ScharrY.data, size); memcpy(filter, ScharrY.t().data, ScharrY.getRows() * ScharrY.getCols() * sizeof(FilterType)); return norm; @@ -1586,11 +1587,11 @@ class VISP_EXPORT vpImageFilter if (size != 1) { // Size = 1 => kernel_size = 2*1 + 1 = 3 std::stringstream errMsg; - errMsg << "Cannot get Scharr kernel of size " << size * 2 + 1 << " != 3"; + errMsg << "Cannot get Scharr kernel of size " << ((size * 2) + 1) << " != 3"; throw vpException(vpException::dimensionError, errMsg.str()); } - const unsigned int kernel_size = size * 2 + 1; + const unsigned int kernel_size = (size * 2) + 1; if (kernel_size == 3) { memcpy(filter, ScharrY3x3, kernel_size * kernel_size * sizeof(FilterType)); return static_cast(1.0 / 32.0); @@ -1616,7 +1617,7 @@ class VISP_EXPORT vpImageFilter throw vpException(vpException::dimensionError, "Cannot get Sobel kernel of size > 20!"); } - vpArray2D SobelY(size * 2 + 1, size * 2 + 1); + vpArray2D SobelY((size * 2) + 1, (size * 2) + 1); FilterType norm = getSobelKernelY(SobelY.data, size); memcpy(filter, SobelY.t().data, SobelY.getRows() * SobelY.getCols() * sizeof(FilterType)); return norm; @@ -1657,7 +1658,7 @@ class VISP_EXPORT vpImageFilter throw vpException(vpException::dimensionError, "Cannot get Sobel kernel of size > 20!"); } - const unsigned int kernel_size = size * 2 + 1; + const unsigned int kernel_size = (size * 2) + 1; FilterType scale = static_cast(1. / 8.); // Scale to normalize Sobel3x3 if (kernel_size == 3) { memcpy(filter, SobelY3x3, kernel_size * kernel_size * sizeof(FilterType)); diff --git a/modules/core/include/visp3/core/vpImageMorphology.h b/modules/core/include/visp3/core/vpImageMorphology.h index c748209bd9..e467f4cd2b 100644 --- a/modules/core/include/visp3/core/vpImageMorphology.h +++ b/modules/core/include/visp3/core/vpImageMorphology.h @@ -188,9 +188,11 @@ void vpImageMorphology::erosion(vpImage &I, Type value, Type value_out, vp vpImage J(I.getHeight() + 2, I.getWidth() + 2); // Copy I to J and add border - for (unsigned int i = 0; i < J.getHeight(); ++i) { - if (i == 0 || i == J.getHeight() - 1) { - for (unsigned int j = 0; j < J.getWidth(); ++j) { + unsigned int j_height = J.getHeight(); + unsigned int j_width = J.getWidth(); + for (unsigned int i = 0; i < j_height; ++i) { + if ((i == 0) || (i == (j_height - 1))) { + for (unsigned int j = 0; j < j_width; ++j) { J[i][j] = value; } } @@ -202,8 +204,10 @@ void vpImageMorphology::erosion(vpImage &I, Type value, Type value_out, vp } if (connexity == CONNEXITY_4) { - for (unsigned int i = 0; i < I.getHeight(); ++i) { - for (unsigned int j = 0; j < I.getWidth(); ++j) { + unsigned int i_height = I.getHeight(); + unsigned int i_width = I.getWidth(); + for (unsigned int i = 0; i < i_height; ++i) { + for (unsigned int j = 0; j < i_width; ++j) { if (J[i + 1][j + 1] == value) { // Consider 4 neighbors if ((J[i][j + 1] == value_out) || // Top @@ -217,14 +221,19 @@ void vpImageMorphology::erosion(vpImage &I, Type value, Type value_out, vp } } else { - for (unsigned int i = 0; i < I.getHeight(); ++i) { - for (unsigned int j = 0; j < I.getWidth(); ++j) { + unsigned int i_height = I.getHeight(); + unsigned int i_width = I.getWidth(); + for (unsigned int i = 0; i < i_height; ++i) { + for (unsigned int j = 0; j < i_width; ++j) { if (J[i + 1][j + 1] == value) { // Consider 8 neighbors - if ((J[i][j] == value_out) || (J[i][j + 1] == value_out) || (J[i][j + 2] == value_out) || - (J[i + 1][j] == value_out) || (J[i + 1][j + 2] == value_out) || (J[i + 2][j] == value_out) || - (J[i + 2][j + 1] == value_out) || (J[i + 2][j + 2] == value_out)) + bool cond4firstneighbors = (J[i][j] == value_out) || (J[i][j + 1] == value_out) || + (J[i][j + 2] == value_out) || (J[i + 1][j] == value_out); + bool cond4secondneighbors = (J[i + 1][j + 2] == value_out) || (J[i + 2][j] == value_out) || + (J[i + 2][j + 1] == value_out) || (J[i + 2][j + 2] == value_out); + if (cond4firstneighbors || cond4secondneighbors) { I[i][j] = value_out; + } } } } @@ -258,9 +267,11 @@ void vpImageMorphology::dilatation(vpImage &I, Type value, Type value_out, vpImage J(I.getHeight() + 2, I.getWidth() + 2); // Copy I to J and add border - for (unsigned int i = 0; i < J.getHeight(); ++i) { - if (i == 0 || i == J.getHeight() - 1) { - for (unsigned int j = 0; j < J.getWidth(); ++j) { + unsigned int j_height = J.getHeight(); + unsigned int j_width = J.getWidth(); + for (unsigned int i = 0; i < j_height; ++i) { + if ((i == 0) || (i == (j_height - 1))) { + for (unsigned int j = 0; j < j_width; ++j) { J[i][j] = value_out; } } @@ -272,8 +283,10 @@ void vpImageMorphology::dilatation(vpImage &I, Type value, Type value_out, } if (connexity == CONNEXITY_4) { - for (unsigned int i = 0; i < I.getHeight(); ++i) { - for (unsigned int j = 0; j < I.getWidth(); ++j) { + unsigned int i_height = I.getHeight(); + unsigned int i_width = I.getWidth(); + for (unsigned int i = 0; i < i_height; ++i) { + for (unsigned int j = 0; j < i_width; ++j) { if (J[i + 1][j + 1] == value_out) { // Consider 4 neighbors if ((J[i][j + 1] == value) || // Top @@ -287,13 +300,16 @@ void vpImageMorphology::dilatation(vpImage &I, Type value, Type value_out, } } else { - for (unsigned int i = 0; i < I.getHeight(); ++i) { - for (unsigned int j = 0; j < I.getWidth(); ++j) { + unsigned int i_height = I.getHeight(); + unsigned int i_width = I.getWidth(); + for (unsigned int i = 0; i < i_height; ++i) { + for (unsigned int j = 0; j < i_width; ++j) { if (J[i + 1][j + 1] == value_out) { // Consider 8 neighbors - if ((J[i][j] == value) || (J[i][j + 1] == value) || (J[i][j + 2] == value) || (J[i + 1][j] == value) || - (J[i + 1][j + 2] == value) || (J[i + 2][j] == value) || (J[i + 2][j + 1] == value) || - (J[i + 2][j + 2] == value)) { + bool cond4firstneighbors = (J[i][j] == value) || (J[i][j + 1] == value) || (J[i][j + 2] == value) || (J[i + 1][j] == value); + bool cond4secondneighbors = (J[i + 1][j + 2] == value) || (J[i + 2][j] == value) || (J[i + 2][j + 1] == value) || + (J[i + 2][j + 2] == value); + if (cond4firstneighbors || cond4secondneighbors) { I[i][j] = value; } } @@ -423,20 +439,20 @@ void vpImageMorphology::imageOperation(vpImage &I, const T &(*operation)(cons for (int r = 0; r < height_in; ++r) { // Computing the rows we can explore without going outside the limits of the image int r_iterator_start = -halfKernelSize, r_iterator_stop = halfKernelSize + 1; - if (r - halfKernelSize < 0) { + if ((r - halfKernelSize) < 0) { r_iterator_start = -r; } - else if (r + halfKernelSize >= height_in) { + else if ((r + halfKernelSize) >= height_in) { r_iterator_stop = height_in - r; } for (int c = 0; c < width_in; ++c) { T value = I[r][c]; // Computing the columns we can explore without going outside the limits of the image int c_iterator_start = -halfKernelSize, c_iterator_stop = halfKernelSize + 1; - if (c - halfKernelSize < 0) { + if ((c - halfKernelSize) < 0) { c_iterator_start = -c; } - else if (c + halfKernelSize >= width_in) { + else if ((c + halfKernelSize) >= width_in) { c_iterator_stop = width_in - c; } for (int r_iterator = r_iterator_start; r_iterator < r_iterator_stop; ++r_iterator) { diff --git a/modules/core/include/visp3/core/vpImagePoint.h b/modules/core/include/visp3/core/vpImagePoint.h index f0a69ed114..120385f7b1 100644 --- a/modules/core/include/visp3/core/vpImagePoint.h +++ b/modules/core/include/visp3/core/vpImagePoint.h @@ -161,10 +161,11 @@ class VISP_EXPORT vpImagePoint */ inline bool inSegment(const vpImagePoint &start, const vpImagePoint &end) const { - return ((end.get_j() >= start.get_j() && end.get_j() >= this->j && this->j >= start.get_j()) || - (end.get_j() <= start.get_j() && end.get_j() <= this->j && this->j <= start.get_j())) && - ((end.get_i() >= start.get_i() && end.get_i() >= this->i && this->i >= start.get_i()) || - (end.get_i() <= start.get_i() && end.get_i() <= this->i && this->i <= start.get_i())); + bool cond11 = ((end.get_j() >= start.get_j()) && (end.get_j() >= this->j) && (this->j >= start.get_j())); + bool cond12 = ((end.get_j() <= start.get_j()) && (end.get_j() <= this->j) && (this->j <= start.get_j())); + bool cond21 = ((end.get_i() >= start.get_i()) && (end.get_i() >= this->i) && (this->i >= start.get_i())); + bool cond22 = ((end.get_i() <= start.get_i()) && (end.get_i() <= this->i) && (this->i <= start.get_i())); + return (cond11 || cond12) && (cond21 || cond22); } /*! @@ -216,15 +217,15 @@ class VISP_EXPORT vpImagePoint { const double line_slope = (end.get_i() - start.get_i()) / (end.get_j() - start.get_j()); if (fabs(end.get_j() - this->j) > fabs(end.get_i() - this->i)) { - double j_ = (end.get_j() > this->j ? this->j + 1 : this->j - 1); + double j_ = (end.get_j() > this->j ? (this->j + 1) : (this->j - 1)); #if ((__cplusplus >= 201103L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201103L))) // Check if cxx11 or higher - return { end.get_i() - line_slope * (end.get_j() - j_), j_ }; + return { end.get_i() - (line_slope * (end.get_j() - j_)), j_ }; #else return vpImagePoint(end.get_i() - line_slope * (end.get_j() - j_), j_); #endif } else { - double i_ = (end.get_i() > this->i ? this->i + 1 : this->i - 1); + double i_ = (end.get_i() > this->i ? (this->i + 1) : (this->i - 1)); #if ((__cplusplus >= 201103L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201103L))) // Check if cxx11 or higher return { i_, end.get_j() - ((end.get_i() - i_) / line_slope) }; #else diff --git a/modules/core/include/visp3/core/vpImageTools.h b/modules/core/include/visp3/core/vpImageTools.h index b5a1c4fd52..a9b0acbd33 100644 --- a/modules/core/include/visp3/core/vpImageTools.h +++ b/modules/core/include/visp3/core/vpImageTools.h @@ -312,30 +312,30 @@ template void vpImageTools::crop(const vpImage &I, double roi_top, double roi_left, unsigned int roi_height, unsigned int roi_width, vpImage &crop, unsigned int v_scale, unsigned int h_scale) { - int i_min = std::max((int)(ceil(roi_top / v_scale)), 0); - int j_min = std::max((int)(ceil(roi_left / h_scale)), 0); - int i_max = std::min((int)(ceil((roi_top + roi_height)) / v_scale), (int)(I.getHeight() / v_scale)); - int j_max = std::min((int)(ceil((roi_left + roi_width) / h_scale)), (int)(I.getWidth() / h_scale)); + int i_min = std::max(static_cast(ceil(roi_top / v_scale)), 0); + int j_min = std::max(static_cast(ceil(roi_left / h_scale)), 0); + int i_max = std::min(static_cast(ceil(roi_top + roi_height) / v_scale), static_cast(I.getHeight() / v_scale)); + int j_max = std::min(static_cast(ceil((roi_left + roi_width) / h_scale)), static_cast(I.getWidth() / h_scale)); - unsigned int i_min_u = (unsigned int)i_min; - unsigned int j_min_u = (unsigned int)j_min; + unsigned int i_min_u = static_cast(i_min); + unsigned int j_min_u = static_cast(j_min); - unsigned int r_width = (unsigned int)(j_max - j_min); - unsigned int r_height = (unsigned int)(i_max - i_min); + unsigned int r_width = static_cast(j_max - j_min); + unsigned int r_height = static_cast(i_max - i_min); crop.resize(r_height, r_width); - if (v_scale == 1 && h_scale == 1) { + if ((v_scale == 1) && (h_scale == 1)) { for (unsigned int i = 0; i < r_height; ++i) { void *src = (void *)(I[i + i_min_u] + j_min_u); - void *dst = (void *)crop[i]; + void *dst = (void *)(crop[i]); memcpy(dst, src, r_width * sizeof(Type)); } } else if (h_scale == 1) { for (unsigned int i = 0; i < r_height; ++i) { void *src = (void *)(I[(i + i_min_u) * v_scale] + j_min_u); - void *dst = (void *)crop[i]; + void *dst = (void *)(crop[i]); memcpy(dst, src, r_width * sizeof(Type)); } } @@ -392,7 +392,7 @@ template void vpImageTools::crop(const vpImage &I, const vpRect &roi, vpImage &crop, unsigned int v_scale, unsigned int h_scale) { - vpImageTools::crop(I, roi.getTop(), roi.getLeft(), (unsigned int)roi.getHeight(), (unsigned int)roi.getWidth(), crop, + vpImageTools::crop(I, roi.getTop(), roi.getLeft(), static_cast(roi.getHeight()), static_cast(roi.getWidth()), crop, v_scale, h_scale); } @@ -417,30 +417,30 @@ template void vpImageTools::crop(const unsigned char *bitmap, unsigned int width, unsigned int height, const vpRect &roi, vpImage &crop, unsigned int v_scale, unsigned int h_scale) { - int i_min = std::max((int)(ceil(roi.getTop() / v_scale)), 0); - int j_min = std::max((int)(ceil(roi.getLeft() / h_scale)), 0); - int i_max = std::min((int)(ceil((roi.getTop() + roi.getHeight()) / v_scale)), (int)(height / v_scale)); - int j_max = std::min((int)(ceil((roi.getLeft() + roi.getWidth()) / h_scale)), (int)(width / h_scale)); + int i_min = std::max(static_cast(ceil(roi.getTop() / v_scale)), 0); + int j_min = std::max(static_cast(ceil(roi.getLeft() / h_scale)), 0); + int i_max = std::min(static_cast(ceil((roi.getTop() + roi.getHeight()) / v_scale)), static_cast(height / v_scale)); + int j_max = std::min(static_cast(ceil((roi.getLeft() + roi.getWidth()) / h_scale)), static_cast(width / h_scale)); - unsigned int i_min_u = (unsigned int)i_min; - unsigned int j_min_u = (unsigned int)j_min; + unsigned int i_min_u = static_cast(i_min); + unsigned int j_min_u = static_cast(j_min); - unsigned int r_width = (unsigned int)(j_max - j_min); - unsigned int r_height = (unsigned int)(i_max - i_min); + unsigned int r_width = static_cast(j_max - j_min); + unsigned int r_height = static_cast(i_max - i_min); crop.resize(r_height, r_width); if (v_scale == 1 && h_scale == 1) { for (unsigned int i = 0; i < r_height; ++i) { void *src = (void *)(bitmap + ((i + i_min_u) * width + j_min_u) * sizeof(Type)); - void *dst = (void *)crop[i]; + void *dst = (void *)(crop[i]); memcpy(dst, src, r_width * sizeof(Type)); } } else if (h_scale == 1) { for (unsigned int i = 0; i < r_height; ++i) { void *src = (void *)(bitmap + ((i + i_min_u) * width * v_scale + j_min_u) * sizeof(Type)); - void *dst = (void *)crop[i]; + void *dst = (void *)(crop[i]); memcpy(dst, src, r_width * sizeof(Type)); } } @@ -449,7 +449,7 @@ void vpImageTools::crop(const unsigned char *bitmap, unsigned int width, unsigne unsigned int i_src = (i + i_min_u) * width * v_scale + j_min_u * h_scale; for (unsigned int j = 0; j < r_width; ++j) { void *src = (void *)(bitmap + (i_src + j * h_scale) * sizeof(Type)); - void *dst = (void *)&crop[i][j]; + void *dst = (void *)(&crop[i][j]); memcpy(dst, src, sizeof(Type)); } } @@ -476,15 +476,18 @@ inline void vpImageTools::binarise(vpImage &I, Type threshold1, Type thres Type v; Type *p = I.bitmap; - Type *pend = I.bitmap + I.getWidth() * I.getHeight(); + Type *pend = I.bitmap + (I.getWidth() * I.getHeight()); for (; p < pend; ++p) { v = *p; - if (v < threshold1) + if (v < threshold1) { *p = value1; - else if (v > threshold2) + } + else if (v > threshold2) { *p = value3; - else + } + else { *p = value2; + } } } @@ -513,15 +516,18 @@ inline void vpImageTools::binarise(vpImage &I, unsigned char thre } else { unsigned char *p = I.bitmap; - unsigned char *pend = I.bitmap + I.getWidth() * I.getHeight(); + unsigned char *pend = I.bitmap + (I.getWidth() * I.getHeight()); for (; p < pend; ++p) { unsigned char v = *p; - if (v < threshold1) + if (v < threshold1) { *p = value1; - else if (v > threshold2) + } + else if (v > threshold2) { *p = value3; - else + } + else { *p = value2; + } } } } @@ -718,7 +724,9 @@ void vpImageTools::undistort(const vpImage &I, const vpCameraParameters &c double py = cam.get_py(); double kud = cam.get_kud(); + /* // if (kud == 0) { + */ if (std::fabs(kud) <= std::numeric_limits::epsilon()) { // There is no need to undistort the image undistI = I; @@ -734,46 +742,56 @@ void vpImageTools::undistort(const vpImage &I, const vpCameraParameters &c Type *dst = undistI.bitmap; for (double v = 0; v < height; ++v) { double deltav = v - v0; + /* // double fr1 = 1.0 + kd * (vpMath::sqr(deltav * invpy)); - double fr1 = 1.0 + kud_py2 * deltav * deltav; + */ + double fr1 = 1.0 + (kud_py2 * deltav * deltav); for (double u = 0; u < width; ++u) { + /* // computation of u,v : corresponding pixel coordinates in I. + */ double deltau = u - u0; + /* // double fr2 = fr1 + kd * (vpMath::sqr(deltau * invpx)); - double fr2 = fr1 + kud_px2 * deltau * deltau; + */ + double fr2 = fr1 + (kud_px2 * deltau * deltau); - double u_double = deltau * fr2 + u0; - double v_double = deltav * fr2 + v0; + double u_double = (deltau * fr2) + u0; + double v_double = (deltav * fr2) + v0; // printf("[%g][%g] %g %g : ", u, v, u_double, v_double ); // computation of the bilinear interpolation // declarations - int u_round = (int)(u_double); - int v_round = (int)(v_double); - if (u_round < 0.f) + int u_round = static_cast(u_double); + int v_round = static_cast(v_double); + if (u_round < 0.f) { u_round = -1; - if (v_round < 0.f) + } + if (v_round < 0.f) { v_round = -1; - double du_double = (u_double)-(double)u_round; - double dv_double = (v_double)-(double)v_round; + } + double du_double = u_double-static_cast(u_round); + double dv_double = v_double-static_cast(v_round); Type v01; Type v23; - if ((0 <= u_round) && (0 <= v_round) && (u_round < (((int)width) - 1)) && (v_round < (((int)height) - 1))) { + if ((0 <= u_round) && (0 <= v_round) && (u_round < ((static_cast(width)) - 1)) && (v_round < ((static_cast(height)) - 1))) { // process interpolation - const Type *_mp = &I[(unsigned int)v_round][(unsigned int)u_round]; - v01 = (Type)(_mp[0] + ((_mp[1] - _mp[0]) * du_double)); - _mp += width; - v23 = (Type)(_mp[0] + ((_mp[1] - _mp[0]) * du_double)); - *dst = (Type)(v01 + ((v23 - v01) * dv_double)); + const Type *v_mp = &I[static_cast(v_round)][static_cast(u_round)]; + v01 = static_cast(v_mp[0] + ((v_mp[1] - v_mp[0]) * du_double)); + v_mp += width; + v23 = static_cast(v_mp[0] + ((v_mp[1] - v_mp[0]) * du_double)); + *dst = static_cast(v01 + ((v23 - v01) * dv_double)); + /* // printf("R %d G %d B %d\n", dst->R, dst->G, dst->B); + */ } else { *dst = 0; } - dst++; + ++dst; } } #endif // VISP_HAVE_THREADS @@ -842,7 +860,7 @@ template void vpImageTools::flip(const vpImage &I, vpImage void vpImageTools::flip(vpImage &I) vpImage Ibuf; Ibuf.resize(1, width); - for (unsigned int i = 0; i < height / 2; ++i) { - memcpy(Ibuf.bitmap, I.bitmap + i * width, width * sizeof(Type)); + for (unsigned int i = 0; i < (height / 2); ++i) { + memcpy(Ibuf.bitmap, I.bitmap + (i * width), width * sizeof(Type)); - memcpy(I.bitmap + i * width, I.bitmap + (height - 1 - i) * width, width * sizeof(Type)); - memcpy(I.bitmap + (height - 1 - i) * width, Ibuf.bitmap, width * sizeof(Type)); + memcpy(I.bitmap + (i * width), I.bitmap + ((height - 1 - i) * width), width * sizeof(Type)); + memcpy(I.bitmap + ((height - 1 - i) * width), Ibuf.bitmap, width * sizeof(Type)); } } @@ -1099,7 +1117,7 @@ void vpImageTools::resize(const vpImage &I, vpImage &Ires, const vpI #endif ) { - if (I.getWidth() < 2 || I.getHeight() < 2 || Ires.getWidth() < 2 || Ires.getHeight() < 2) { + if ((I.getWidth() < 2) || (I.getHeight() < 2) || (Ires.getWidth() < 2) || (Ires.getHeight() < 2)) { std::cerr << "Input or output image is too small!" << std::endl; return; } @@ -1119,13 +1137,17 @@ void vpImageTools::resize(const vpImage &I, vpImage &Ires, const vpI } #pragma omp parallel for schedule(dynamic) #endif + /* + // int ires_height = static_cast(Ires.getHeight()); + */ for (int i = 0; i < static_cast(Ires.getHeight()); ++i) { - const float v = (i + half) * scaleY - half; + const float v = ((i + half) * scaleY) - half; const float v0 = std::floor(v); const float yFrac = v - v0; - for (unsigned int j = 0; j < Ires.getWidth(); ++j) { - const float u = (j + half) * scaleX - half; + unsigned int ires_width = static_cast(Ires.getWidth()); + for (unsigned int j = 0; j < ires_width; ++j) { + const float u = ((j + half) * scaleX) - half; const float u0 = std::floor(u); const float xFrac = u - u0; @@ -1152,7 +1174,7 @@ inline void vpImageTools::resize(const vpImage &I, vpImage &I, vpImage(Ires.getHeight()); + */ for (int i = 0; i < static_cast(Ires.getHeight()); ++i) { - float v = (i + half) * scaleY - half; + float v = ((i + half) * scaleY) - half; float yFrac = v - static_cast(v); - for (unsigned int j = 0; j < Ires.getWidth(); ++j) { - float u = (j + half) * scaleX - half; + unsigned int ires_width = static_cast(Ires.getWidth()); + for (unsigned int j = 0; j < ires_width; ++j) { + float u = ((j + half) * scaleX) - half; float xFrac = u - static_cast(u); if (method == INTERPOLATION_NEAREST) { @@ -1202,7 +1228,7 @@ inline void vpImageTools::resize(const vpImage &I, vpImage &Ires #endif ) { - if (I.getWidth() < 2 || I.getHeight() < 2 || Ires.getWidth() < 2 || Ires.getHeight() < 2) { + if ((I.getWidth() < 2) || (I.getHeight() < 2) || (Ires.getWidth() < 2) || (Ires.getHeight() < 2)) { std::cerr << "Input or output image is too small!" << std::endl; return; } @@ -1224,12 +1250,16 @@ inline void vpImageTools::resize(const vpImage &I, vpImage &Ires } #pragma omp parallel for schedule(dynamic) #endif + /* + // int ires_height = static_cast(Ires.getHeight()); + */ for (int i = 0; i < static_cast(Ires.getHeight()); ++i) { float v = (i + half) * scaleY - half; float yFrac = v - static_cast(v); - for (unsigned int j = 0; j < Ires.getWidth(); ++j) { - float u = (j + half) * scaleX - half; + unsigned int ires_width = static_cast(Ires.getWidth()); + for (unsigned int j = 0; j < ires_width; ++j) { + float u = ((j + half) * scaleX) - half; float xFrac = u - static_cast(u); if (method == INTERPOLATION_NEAREST) { @@ -1262,7 +1292,7 @@ template void vpImageTools::warpImage(const vpImage &src, const vpMatrix &T, vpImage &dst, const vpImageInterpolationType &interpolation, bool fixedPointArithmetic, bool pixelCenter) { - if ((T.getRows() != 2 && T.getRows() != 3) || T.getCols() != 3) { + if (((T.getRows() != 2) && (T.getRows() != 3)) || (T.getCols() != 3)) { std::cerr << "Input transformation must be a (2x3) or (3x3) matrix." << std::endl; return; } @@ -1280,15 +1310,15 @@ void vpImageTools::warpImage(const vpImage &src, const vpMatrix &T, vpImag vpMatrix M = T; if (affine) { - double D = M[0][0] * M[1][1] - M[0][1] * M[1][0]; - D = !vpMath::nul(D, std::numeric_limits::epsilon()) ? 1.0 / D : 0; + double D = (M[0][0] * M[1][1]) - (M[0][1] * M[1][0]); + D = !vpMath::nul(D, std::numeric_limits::epsilon()) ? (1.0 / D) : 0; double A11 = M[1][1] * D, A22 = M[0][0] * D; M[0][0] = A11; M[0][1] *= -D; M[1][0] *= -D; M[1][1] = A22; - double b1 = -M[0][0] * M[0][2] - M[0][1] * M[1][2]; - double b2 = -M[1][0] * M[0][2] - M[1][1] * M[1][2]; + double b1 = (-M[0][0] * M[0][2]) - (M[0][1] * M[1][2]); + double b2 = (-M[1][0] * M[0][2]) - (M[1][1] * M[1][2]); M[0][2] = b1; M[1][2] = b2; } @@ -1296,7 +1326,7 @@ void vpImageTools::warpImage(const vpImage &src, const vpMatrix &T, vpImag M = T.inverseByLU(); } - if (fixedPointArithmetic && !pixelCenter) { + if (fixedPointArithmetic && (!pixelCenter)) { fixedPointArithmetic = checkFixedPoint(0, 0, M, affine) && checkFixedPoint(dst.getWidth() - 1, 0, M, affine) && checkFixedPoint(0, dst.getHeight() - 1, M, affine) && checkFixedPoint(dst.getWidth() - 1, dst.getHeight() - 1, M, affine); @@ -1316,7 +1346,7 @@ template void vpImageTools::warpNN(const vpImage &src, const vpMatrix &T, vpImage &dst, bool affine, bool centerCorner, bool fixedPoint) { - if (fixedPoint && !centerCorner) { + if (fixedPoint && (!centerCorner)) { const int nbits = 16; const int32_t precision = 1 << nbits; const float precision_1 = 1 / static_cast(precision); @@ -1335,14 +1365,16 @@ void vpImageTools::warpNN(const vpImage &src, const vpMatrix &T, vpImage((src.getWidth() - 1) * precision) + 0x8000; if (affine) { - for (unsigned int i = 0; i < dst.getHeight(); ++i) { + unsigned int dst_height = dst.getHeight(); + unsigned int dst_width = dst.getWidth(); + for (unsigned int i = 0; i < dst_height; ++i) { int32_t xi = a2_i32; int32_t yi = a5_i32; - for (unsigned int j = 0; j < dst.getWidth(); ++j) { - if (yi >= 0 && yi < height_1_i32 && xi >= 0 && xi < width_1_i32) { - float x_ = (xi >> nbits) + (xi & 0xFFFF) * precision_1; - float y_ = (yi >> nbits) + (yi & 0xFFFF) * precision_1; + for (unsigned int j = 0; j < dst_width; ++j) { + if ((yi >= 0) && (yi < height_1_i32) && (xi >= 0) && (xi < width_1_i32)) { + float x_ = (xi >> nbits) + ((xi & 0xFFFF) * precision_1); + float y_ = (yi >> nbits) + ((yi & 0xFFFF) * precision_1); int x = vpMath::round(x_); int y = vpMath::round(y_); @@ -1358,17 +1390,22 @@ void vpImageTools::warpNN(const vpImage &src, const vpMatrix &T, vpImage(src.getHeight()); + int src_width = static_cast(src.getWidth()); + for (unsigned int i = 0; i < dst_height; ++i) { int64_t xi = a2_i32; int64_t yi = a5_i32; int64_t wi = a8_i32; - for (unsigned int j = 0; j < dst.getWidth(); ++j) { - if (wi != 0 && yi >= 0 && yi <= (static_cast(src.getHeight()) - 1) * wi && xi >= 0 && - xi <= (static_cast(src.getWidth()) - 1) * wi) { - float w_ = (wi >> nbits) + (wi & 0xFFFF) * precision_1; - float x_ = ((xi >> nbits) + (xi & 0xFFFF) * precision_1) / w_; - float y_ = ((yi >> nbits) + (yi & 0xFFFF) * precision_1) / w_; + for (unsigned int j = 0; j < dst_width; ++j) { + bool cond_on_y = (yi >= 0) && (yi <= ((src_height - 1) * wi)); + bool cond_on_x = (xi >= 0) && (xi <= ((src_width - 1) * wi)); + if ((wi != 0) && cond_on_y && cond_on_x) { + float w_ = (wi >> nbits) + ((wi & 0xFFFF) * precision_1); + float x_ = ((xi >> nbits) + ((xi & 0xFFFF) * precision_1)) / w_; + float y_ = ((yi >> nbits) + ((yi & 0xFFFF) * precision_1)) / w_; int x = vpMath::round(x_); int y = vpMath::round(y_); @@ -1398,11 +1435,13 @@ void vpImageTools::warpNN(const vpImage &src, const vpMatrix &T, vpImage::epsilon())) { w = 1.0; @@ -1411,7 +1450,7 @@ void vpImageTools::warpNN(const vpImage &src, const vpMatrix &T, vpImage= 0 && x_ < static_cast(src.getWidth()) && y_ >= 0 && y_ < static_cast(src.getHeight())) { + if ((x_ >= 0) && (x_ < static_cast(src.getWidth())) && (y_ >= 0) && (y_ < static_cast(src.getHeight()))) { dst[i][j] = src[y_][x_]; } } @@ -1423,7 +1462,7 @@ template void vpImageTools::warpLinear(const vpImage &src, const vpMatrix &T, vpImage &dst, bool affine, bool centerCorner, bool fixedPoint) { - if (fixedPoint && !centerCorner) { + if (fixedPoint && (!centerCorner)) { const int nbits = 16; const int64_t precision = 1 << nbits; const float precision_1 = 1 / static_cast(precision); @@ -1444,12 +1483,14 @@ void vpImageTools::warpLinear(const vpImage &src, const vpMatrix &T, vpIma int64_t width_i64 = static_cast(src.getWidth() * precision); if (affine) { - for (unsigned int i = 0; i < dst.getHeight(); ++i) { + unsigned int dst_height = dst.getHeight(); + unsigned int dst_width = dst.getWidth(); + for (unsigned int i = 0; i < dst_height; ++i) { int64_t xi_ = a2_i64; int64_t yi_ = a5_i64; - for (unsigned int j = 0; j < dst.getWidth(); ++j) { - if (yi_ >= 0 && yi_ < height_i64 && xi_ >= 0 && xi_ < width_i64) { + for (unsigned int j = 0; j < dst_width; ++j) { + if ((yi_ >= 0) && (yi_ < height_i64) && (xi_ >= 0) && (xi_ < width_i64)) { const int64_t xi_lower = xi_ & (~0xFFFF); const int64_t yi_lower = yi_ & (~0xFFFF); @@ -1461,7 +1502,7 @@ void vpImageTools::warpLinear(const vpImage &src, const vpMatrix &T, vpIma const int x_ = static_cast(xi_ >> nbits); const int y_ = static_cast(yi_ >> nbits); - if (y_ < static_cast(src.getHeight()) - 1 && x_ < static_cast(src.getWidth()) - 1) { + if ((y_ < (static_cast(src.getHeight()) - 1)) && (x_ < (static_cast(src.getWidth()) - 1))) { const Type val00 = src[y_][x_]; const Type val01 = src[y_][x_ + 1]; const Type val10 = src[y_ + 1][x_]; @@ -1471,14 +1512,14 @@ void vpImageTools::warpLinear(const vpImage &src, const vpMatrix &T, vpIma const float interp = (interp_i64 >> (nbits * 2)) + (interp_i64 & 0xFFFFFFFF) * precision_2; dst[i][j] = vpMath::saturate(interp); } - else if (y_ < static_cast(src.getHeight()) - 1) { + else if (y_ < (static_cast(src.getHeight()) - 1)) { const Type val00 = src[y_][x_]; const Type val10 = src[y_ + 1][x_]; const int64_t interp_i64 = static_cast(t_1 * val00 + t * val10); const float interp = (interp_i64 >> nbits) + (interp_i64 & 0xFFFF) * precision_1; dst[i][j] = vpMath::saturate(interp); } - else if (x_ < static_cast(src.getWidth()) - 1) { + else if (x_ < (static_cast(src.getWidth()) - 1)) { const Type val00 = src[y_][x_]; const Type val01 = src[y_][x_ + 1]; const int64_t interp_i64 = static_cast(s_1 * val00 + s * val01); @@ -1499,17 +1540,22 @@ void vpImageTools::warpLinear(const vpImage &src, const vpMatrix &T, vpIma } } else { - for (unsigned int i = 0; i < dst.getHeight(); ++i) { + unsigned int dst_height = dst.getHeight(); + unsigned int dst_width = dst.getWidth(); + int src_height = static_cast(src.getHeight()); + int src_width = static_cast(src.getWidth()); + for (unsigned int i = 0; i < dst_height; ++i) { int64_t xi = a2_i64; int64_t yi = a5_i64; int64_t wi = a8_i64; - for (unsigned int j = 0; j < dst.getWidth(); ++j) { - if (wi != 0 && yi >= 0 && yi <= (static_cast(src.getHeight()) - 1) * wi && xi >= 0 && - xi <= (static_cast(src.getWidth()) - 1) * wi) { - const float wi_ = (wi >> nbits) + (wi & 0xFFFF) * precision_1; - const float xi_ = ((xi >> nbits) + (xi & 0xFFFF) * precision_1) / wi_; - const float yi_ = ((yi >> nbits) + (yi & 0xFFFF) * precision_1) / wi_; + for (unsigned int j = 0; j < dst_width; ++j) { + bool cond_on_y = (yi >= 0) && (yi <= ((src_height - 1) * wi)); + bool cond_on_x = (xi >= 0) && (xi <= ((src_width - 1) * wi)); + if ((wi != 0) && cond_on_y && cond_on_x) { + const float wi_ = (wi >> nbits) + ((wi & 0xFFFF) * precision_1); + const float xi_ = ((xi >> nbits) + ((xi & 0xFFFF) * precision_1)) / wi_; + const float yi_ = ((yi >> nbits) + ((yi & 0xFFFF) * precision_1)) / wi_; const int x_ = static_cast(xi_); const int y_ = static_cast(yi_); @@ -1517,7 +1563,7 @@ void vpImageTools::warpLinear(const vpImage &src, const vpMatrix &T, vpIma const float t = yi_ - y_; const float s = xi_ - x_; - if (y_ < static_cast(src.getHeight()) - 1 && x_ < static_cast(src.getWidth()) - 1) { + if ((y_ < (src_height - 1)) && (x_ < (src_width - 1))) { const float val00 = static_cast(src[y_][x_]); const float val01 = static_cast(src[y_][x_ + 1]); const float val10 = static_cast(src[y_ + 1][x_]); @@ -1527,13 +1573,13 @@ void vpImageTools::warpLinear(const vpImage &src, const vpMatrix &T, vpIma const float interp = lerp(col0, col1, t); dst[i][j] = vpMath::saturate(interp); } - else if (y_ < static_cast(src.getHeight()) - 1) { + else if (y_ < (src_height - 1)) { const float val00 = static_cast(src[y_][x_]); const float val10 = static_cast(src[y_ + 1][x_]); const float interp = lerp(val00, val10, t); dst[i][j] = vpMath::saturate(interp); } - else if (x_ < static_cast(src.getWidth()) - 1) { + else if (x_ < (src_width - 1)) { const float val00 = static_cast(src[y_][x_]); const float val01 = static_cast(src[y_][x_ + 1]); const float interp = lerp(val00, val01, s); @@ -1566,30 +1612,33 @@ void vpImageTools::warpLinear(const vpImage &src, const vpMatrix &T, vpIma double a7 = affine ? 0.0 : T[2][1]; double a8 = affine ? 1.0 : T[2][2]; - for (unsigned int i = 0; i < dst.getHeight(); ++i) { - for (unsigned int j = 0; j < dst.getWidth(); ++j) { - double x = a0 * (centerCorner ? j + 0.5 : j) + a1 * (centerCorner ? i + 0.5 : i) + a2; - double y = a3 * (centerCorner ? j + 0.5 : j) + a4 * (centerCorner ? i + 0.5 : i) + a5; - double w = a6 * (centerCorner ? j + 0.5 : j) + a7 * (centerCorner ? i + 0.5 : i) + a8; + unsigned int dst_height = dst.getHeight(); + unsigned int dst_width = dst.getWidth(); + int src_height = static_cast(src.getHeight()); + int src_width = static_cast(src.getWidth()); + for (unsigned int i = 0; i < dst_height; ++i) { + for (unsigned int j = 0; j < dst_width; ++j) { + double x = (a0 * (centerCorner ? (j + 0.5) : j)) + (a1 * (centerCorner ? (i + 0.5) : i)) + a2; + double y = (a3 * (centerCorner ? (j + 0.5) : j)) + (a4 * (centerCorner ? (i + 0.5) : i)) + a5; + double w = (a6 * (centerCorner ? (j + 0.5) : j)) + (a7 * (centerCorner ? (i + 0.5) : i)) + a8; if (vpMath::nul(w, std::numeric_limits::epsilon())) { w = 1; } - x = x / w - (centerCorner ? 0.5 : 0); - y = y / w - (centerCorner ? 0.5 : 0); + x = (x / w) - (centerCorner ? 0.5 : 0); + y = (y / w) - (centerCorner ? 0.5 : 0); int x_lower = static_cast(x); int y_lower = static_cast(y); - if (y_lower >= static_cast(src.getHeight()) || x_lower >= static_cast(src.getWidth()) || y < 0 || - x < 0) { + if ((y_lower >= src_height) || (x_lower >= src_width) || (y < 0) || (x < 0)) { continue; } double s = x - x_lower; double t = y - y_lower; - if (y_lower < static_cast(src.getHeight()) - 1 && x_lower < static_cast(src.getWidth()) - 1) { + if ((y_lower < (src_height - 1)) && (x_lower < (src_width - 1))) { const double val00 = static_cast(src[y_lower][x_lower]); const double val01 = static_cast(src[y_lower][x_lower + 1]); const double val10 = static_cast(src[y_lower + 1][x_lower]); @@ -1599,13 +1648,13 @@ void vpImageTools::warpLinear(const vpImage &src, const vpMatrix &T, vpIma const double interp = lerp(col0, col1, t); dst[i][j] = vpMath::saturate(interp); } - else if (y_lower < static_cast(src.getHeight()) - 1) { + else if (y_lower < (src_height - 1)) { const double val00 = static_cast(src[y_lower][x_lower]); const double val10 = static_cast(src[y_lower + 1][x_lower]); const double interp = lerp(val00, val10, t); dst[i][j] = vpMath::saturate(interp); } - else if (x_lower < static_cast(src.getWidth()) - 1) { + else if (x_lower < (src_width - 1)) { const double val00 = static_cast(src[y_lower][x_lower]); const double val01 = static_cast(src[y_lower][x_lower + 1]); const double interp = lerp(val00, val01, s); @@ -1623,7 +1672,7 @@ template <> inline void vpImageTools::warpLinear(const vpImage &src, const vpMatrix &T, vpImage &dst, bool affine, bool centerCorner, bool fixedPoint) { - if (fixedPoint && !centerCorner) { + if (fixedPoint && (!centerCorner)) { const int nbits = 16; const int64_t precision = 1 << nbits; const float precision_1 = 1 / static_cast(precision); @@ -1644,12 +1693,16 @@ inline void vpImageTools::warpLinear(const vpImage &src, const vpMatrix int64_t width_i64 = static_cast(src.getWidth() * precision); if (affine) { - for (unsigned int i = 0; i < dst.getHeight(); ++i) { + unsigned int dst_height = dst.getHeight(); + unsigned int dst_width = dst.getWidth(); + int src_height = static_cast(src.getHeight()); + int src_width = static_cast(src.getWidth()); + for (unsigned int i = 0; i < dst_height; ++i) { int64_t xi = a2_i64; int64_t yi = a5_i64; - for (unsigned int j = 0; j < dst.getWidth(); ++j) { - if (yi >= 0 && yi < height_i64 && xi >= 0 && xi < width_i64) { + for (unsigned int j = 0; j < dst_width; ++j) { + if ((yi >= 0) && (yi < height_i64) && (xi >= 0) && (xi < width_i64)) { const int64_t xi_lower = xi & (~0xFFFF); const int64_t yi_lower = yi & (~0xFFFF); @@ -1661,52 +1714,52 @@ inline void vpImageTools::warpLinear(const vpImage &src, const vpMatrix const int x_ = static_cast(xi >> nbits); const int y_ = static_cast(yi >> nbits); - if (y_ < static_cast(src.getHeight()) - 1 && x_ < static_cast(src.getWidth()) - 1) { + if ((y_ < (src_height - 1)) && (x_ < (src_width - 1))) { const vpRGBa val00 = src[y_][x_]; const vpRGBa val01 = src[y_][x_ + 1]; const vpRGBa val10 = src[y_ + 1][x_]; const vpRGBa val11 = src[y_ + 1][x_ + 1]; const int64_t interpR_i64 = - static_cast(s_1 * t_1 * val00.R + s * t_1 * val01.R + s_1 * t * val10.R + s * t * val11.R); - const float interpR = (interpR_i64 >> (nbits * 2)) + (interpR_i64 & 0xFFFFFFFF) * precision_2; + static_cast((s_1 * t_1 * val00.R) + (s * t_1 * val01.R) + (s_1 * t * val10.R) + (s * t * val11.R)); + const float interpR = (interpR_i64 >> (nbits * 2)) + ((interpR_i64 & 0xFFFFFFFF) * precision_2); const int64_t interpG_i64 = - static_cast(s_1 * t_1 * val00.G + s * t_1 * val01.G + s_1 * t * val10.G + s * t * val11.G); - const float interpG = (interpG_i64 >> (nbits * 2)) + (interpG_i64 & 0xFFFFFFFF) * precision_2; + static_cast((s_1 * t_1 * val00.G) + (s * t_1 * val01.G) + (s_1 * t * val10.G) + (s * t * val11.G)); + const float interpG = (interpG_i64 >> (nbits * 2)) + ((interpG_i64 & 0xFFFFFFFF) * precision_2); const int64_t interpB_i64 = - static_cast(s_1 * t_1 * val00.B + s * t_1 * val01.B + s_1 * t * val10.B + s * t * val11.B); - const float interpB = (interpB_i64 >> (nbits * 2)) + (interpB_i64 & 0xFFFFFFFF) * precision_2; + static_cast((s_1 * t_1 * val00.B) + (s * t_1 * val01.B) + (s_1 * t * val10.B) + (s * t * val11.B)); + const float interpB = (interpB_i64 >> (nbits * 2)) + ((interpB_i64 & 0xFFFFFFFF) * precision_2); dst[i][j] = vpRGBa(vpMath::saturate(interpR), vpMath::saturate(interpG), vpMath::saturate(interpB), 255); } - else if (y_ < static_cast(src.getHeight()) - 1) { + else if (y_ < (src_height - 1)) { const vpRGBa val00 = src[y_][x_]; const vpRGBa val10 = src[y_ + 1][x_]; const int64_t interpR_i64 = static_cast(t_1 * val00.R + t * val10.R); - const float interpR = (interpR_i64 >> nbits) + (interpR_i64 & 0xFFFF) * precision_1; + const float interpR = (interpR_i64 >> nbits) + ((interpR_i64 & 0xFFFF) * precision_1); - const int64_t interpG_i64 = static_cast(t_1 * val00.G + t * val10.G); - const float interpG = (interpG_i64 >> nbits) + (interpG_i64 & 0xFFFF) * precision_1; + const int64_t interpG_i64 = static_cast((t_1 * val00.G) + (t * val10.G)); + const float interpG = (interpG_i64 >> nbits) + ((interpG_i64 & 0xFFFF) * precision_1); - const int64_t interpB_i64 = static_cast(t_1 * val00.B + t * val10.B); - const float interpB = (interpB_i64 >> nbits) + (interpB_i64 & 0xFFFF) * precision_1; + const int64_t interpB_i64 = static_cast((t_1 * val00.B) + (t * val10.B)); + const float interpB = (interpB_i64 >> nbits) + ((interpB_i64 & 0xFFFF) * precision_1); dst[i][j] = vpRGBa(vpMath::saturate(interpR), vpMath::saturate(interpG), vpMath::saturate(interpB), 255); } - else if (x_ < static_cast(src.getWidth()) - 1) { + else if (x_ < (src_width - 1)) { const vpRGBa val00 = src[y_][x_]; const vpRGBa val01 = src[y_][x_ + 1]; - const int64_t interpR_i64 = static_cast(s_1 * val00.R + s * val01.R); - const float interpR = (interpR_i64 >> nbits) + (interpR_i64 & 0xFFFF) * precision_1; + const int64_t interpR_i64 = static_cast((s_1 * val00.R) + (s * val01.R)); + const float interpR = (interpR_i64 >> nbits) + ((interpR_i64 & 0xFFFF) * precision_1); - const int64_t interpG_i64 = static_cast(s_1 * val00.G + s * val01.G); - const float interpG = (interpG_i64 >> nbits) + (interpG_i64 & 0xFFFF) * precision_1; + const int64_t interpG_i64 = static_cast((s_1 * val00.G) + (s * val01.G)); + const float interpG = (interpG_i64 >> nbits) + ((interpG_i64 & 0xFFFF) * precision_1); - const int64_t interpB_i64 = static_cast(s_1 * val00.B + s * val01.B); - const float interpB = (interpB_i64 >> nbits) + (interpB_i64 & 0xFFFF) * precision_1; + const int64_t interpB_i64 = static_cast((s_1 * val00.B) + (s * val01.B)); + const float interpB = (interpB_i64 >> nbits) + ((interpB_i64 & 0xFFFF) * precision_1); dst[i][j] = vpRGBa(vpMath::saturate(interpR), vpMath::saturate(interpG), vpMath::saturate(interpB), 255); @@ -1725,17 +1778,21 @@ inline void vpImageTools::warpLinear(const vpImage &src, const vpMatrix } } else { - for (unsigned int i = 0; i < dst.getHeight(); ++i) { + unsigned int dst_height = dst.getHeight(); + unsigned int dst_width = dst.getWidth(); + int src_height = static_cast(src.getHeight()); + int src_width = static_cast(src.getWidth()); + for (unsigned int i = 0; i < dst_height; ++i) { int64_t xi = a2_i64; int64_t yi = a5_i64; int64_t wi = a8_i64; - for (unsigned int j = 0; j < dst.getWidth(); ++j) { - if (yi >= 0 && yi <= (static_cast(src.getHeight()) - 1) * wi && xi >= 0 && - xi <= (static_cast(src.getWidth()) - 1) * wi) { - const float wi_ = (wi >> nbits) + (wi & 0xFFFF) * precision_1; - const float xi_ = ((xi >> nbits) + (xi & 0xFFFF) * precision_1) / wi_; - const float yi_ = ((yi >> nbits) + (yi & 0xFFFF) * precision_1) / wi_; + for (unsigned int j = 0; j < dst_width; ++j) { + if ((yi >= 0) && (yi <= ((src_height - 1) * wi)) && (xi >= 0) && + (xi <= ((src_width - 1) * wi))) { + const float wi_ = (wi >> nbits) + ((wi & 0xFFFF) * precision_1); + const float xi_ = ((xi >> nbits) + ((xi & 0xFFFF) * precision_1)) / wi_; + const float yi_ = ((yi >> nbits) + ((yi & 0xFFFF) * precision_1)) / wi_; const int x_ = static_cast(xi_); const int y_ = static_cast(yi_); @@ -1743,7 +1800,7 @@ inline void vpImageTools::warpLinear(const vpImage &src, const vpMatrix const float t = yi_ - y_; const float s = xi_ - x_; - if (y_ < static_cast(src.getHeight()) - 1 && x_ < static_cast(src.getWidth()) - 1) { + if ((y_ < (src_height - 1)) && (x_ < (src_width - 1))) { const vpRGBa val00 = src[y_][x_]; const vpRGBa val01 = src[y_][x_ + 1]; const vpRGBa val10 = src[y_ + 1][x_]; @@ -1763,7 +1820,7 @@ inline void vpImageTools::warpLinear(const vpImage &src, const vpMatrix dst[i][j] = vpRGBa(vpMath::saturate(interpR), vpMath::saturate(interpG), vpMath::saturate(interpB), 255); } - else if (y_ < static_cast(src.getHeight()) - 1) { + else if (y_ < (src_height - 1)) { const vpRGBa val00 = src[y_][x_]; const vpRGBa val10 = src[y_ + 1][x_]; const float interpR = lerp(val00.R, val10.R, t); @@ -1773,7 +1830,7 @@ inline void vpImageTools::warpLinear(const vpImage &src, const vpMatrix dst[i][j] = vpRGBa(vpMath::saturate(interpR), vpMath::saturate(interpG), vpMath::saturate(interpB), 255); } - else if (x_ < static_cast(src.getWidth()) - 1) { + else if (x_ < (src_width - 1)) { const vpRGBa val00 = src[y_][x_]; const vpRGBa val01 = src[y_][x_ + 1]; const float interpR = lerp(val00.R, val01.R, s); @@ -1810,27 +1867,30 @@ inline void vpImageTools::warpLinear(const vpImage &src, const vpMatrix double a7 = affine ? 0.0 : T[2][1]; double a8 = affine ? 1.0 : T[2][2]; - for (unsigned int i = 0; i < dst.getHeight(); ++i) { - for (unsigned int j = 0; j < dst.getWidth(); ++j) { - double x = a0 * (centerCorner ? j + 0.5 : j) + a1 * (centerCorner ? i + 0.5 : i) + a2; - double y = a3 * (centerCorner ? j + 0.5 : j) + a4 * (centerCorner ? i + 0.5 : i) + a5; - double w = a6 * (centerCorner ? j + 0.5 : j) + a7 * (centerCorner ? i + 0.5 : i) + a8; + unsigned int dst_height = dst.getHeight(); + unsigned int dst_width = dst.getWidth(); + int src_height = static_cast(src.getHeight()); + int src_width = static_cast(src.getWidth()); + for (unsigned int i = 0; i < dst_height; ++i) { + for (unsigned int j = 0; j < dst_width; ++j) { + double x = (a0 * (centerCorner ? (j + 0.5) : j)) + (a1 * (centerCorner ? (i + 0.5) : i)) + a2; + double y = (a3 * (centerCorner ? (j + 0.5) : j)) + (a4 * (centerCorner ? (i + 0.5) : i)) + a5; + double w = (a6 * (centerCorner ? (j + 0.5) : j)) + (a7 * (centerCorner ? (i + 0.5) : i)) + a8; - x = x / w - (centerCorner ? 0.5 : 0); - y = y / w - (centerCorner ? 0.5 : 0); + x = (x / w) - (centerCorner ? 0.5 : 0); + y = (y / w) - (centerCorner ? 0.5 : 0); int x_lower = static_cast(x); int y_lower = static_cast(y); - if (y_lower >= static_cast(src.getHeight()) || x_lower >= static_cast(src.getWidth()) || y < 0 || - x < 0) { + if ((y_lower >= src_height) || (x_lower >= src_width) || (y < 0) || (x < 0)) { continue; } double s = x - x_lower; double t = y - y_lower; - if (y_lower < static_cast(src.getHeight()) - 1 && x_lower < static_cast(src.getWidth()) - 1) { + if ((y_lower < (src_height - 1)) && (x_lower < (src_width - 1))) { const vpRGBa val00 = src[y_lower][x_lower]; const vpRGBa val01 = src[y_lower][x_lower + 1]; const vpRGBa val10 = src[y_lower + 1][x_lower]; @@ -1850,7 +1910,7 @@ inline void vpImageTools::warpLinear(const vpImage &src, const vpMatrix dst[i][j] = vpRGBa(vpMath::saturate(interpR), vpMath::saturate(interpG), vpMath::saturate(interpB), 255); } - else if (y_lower < static_cast(src.getHeight()) - 1) { + else if (y_lower < (src_height - 1)) { const vpRGBa val00 = src[y_lower][x_lower]; const vpRGBa val10 = src[y_lower + 1][x_lower]; const double interpR = lerp(val00.R, val10.R, t); @@ -1860,7 +1920,7 @@ inline void vpImageTools::warpLinear(const vpImage &src, const vpMatrix dst[i][j] = vpRGBa(vpMath::saturate(interpR), vpMath::saturate(interpG), vpMath::saturate(interpB), 255); } - else if (x_lower < static_cast(src.getWidth()) - 1) { + else if (x_lower < (src_width - 1)) { const vpRGBa val00 = src[y_lower][x_lower]; const vpRGBa val01 = src[y_lower][x_lower + 1]; const double interpR = lerp(val00.R, val01.R, s); diff --git a/modules/core/include/visp3/core/vpList.h b/modules/core/include/visp3/core/vpList.h index 16528f03e9..ac5ce23642 100644 --- a/modules/core/include/visp3/core/vpList.h +++ b/modules/core/include/visp3/core/vpList.h @@ -53,6 +53,7 @@ */ template class vpListElement { + /* // private: // vpListElement(const vpListElement &) // : prev(nullptr), next(nullptr), val() @@ -64,7 +65,7 @@ template class vpListElement // throw vpException(vpException::functionNotImplementedError,"Not // implemented!"); return *this; // } - + */ public: vpListElement() : prev(nullptr), next(nullptr), val() { }; vpListElement *prev; ///! pointer to the previous element in the list @@ -226,12 +227,12 @@ template vpList::~vpList() /*! \brief return the number of element in the list */ -template unsigned int vpList::nbElement(void) { return (nb); } +template unsigned int vpList::nbElement(void) { return nb; } /*! \brief return the number of element in the list */ -template unsigned int vpList::nbElements(void) { return (nb); } +template unsigned int vpList::nbElements(void) { return nb; } /*! \brief position the current element on the next one @@ -395,8 +396,9 @@ template void vpList::addRight(const type &v) cur = first; } else { - if (outside()) + if (outside()) { std::cout << "vpList: outside with addRight " << std::endl; + } } cur->next->prev = x; x->next = cur->next; @@ -426,15 +428,16 @@ template void vpList::addLeft(const type &v) cur = last; } else { - if (outside()) + if (outside()) { std::cout << "vpList: outside with addLeft " << std::endl; + } } x->next = cur; x->prev = cur->prev; cur->prev->next = x; cur->prev = x; cur = x; - nb++; + ++nb; } /*! @@ -456,15 +459,16 @@ template void vpList::addRight(type &v) cur = first; } else { - if (outside()) + if (outside()) { std::cout << "vpList: outside with addRight " << std::endl; + } } cur->next->prev = x; x->next = cur->next; x->prev = cur; cur->next = x; cur = x; - nb++; + ++nb; } /*! @@ -487,15 +491,16 @@ template void vpList::addLeft(type &v) cur = last; } else { - if (outside()) + if (outside()) { std::cout << "vpList: outside with addLeft " << std::endl; + } } x->next = cur; x->prev = cur->prev; cur->prev->next = x; cur->prev = x; cur = x; - nb++; + ++nb; } /*! @@ -610,7 +615,7 @@ template void vpList::suppress(void) delete x; } - nb--; + --nb; } /*! @@ -695,7 +700,7 @@ template void vpList::display() while (!outside()) { std::cout << k << " ---> " << value() << std::endl; next(); - k++; + ++k; } std::cout << std::endl << std::endl; } diff --git a/modules/core/include/visp3/core/vpMath.h b/modules/core/include/visp3/core/vpMath.h index 2c2c11b898..51144d17d0 100644 --- a/modules/core/include/visp3/core/vpMath.h +++ b/modules/core/include/visp3/core/vpMath.h @@ -175,7 +175,7 @@ class VISP_EXPORT vpMath static float modulo(const float &value, const float &modulo) { float quotient = std::floor(value / modulo); - float rest = value - quotient * modulo; + float rest = value - (quotient * modulo); return rest; } @@ -190,7 +190,7 @@ class VISP_EXPORT vpMath static double modulo(const double &value, const double &modulo) { double quotient = std::floor(value / modulo); - double rest = value - quotient * modulo; + double rest = value - (quotient * modulo); return rest; } @@ -373,8 +373,9 @@ class VISP_EXPORT vpMath */ double vpMath::fact(unsigned int x) { - if ((x == 1) || (x == 0)) + if ((x == 1) || (x == 0)) { return 1; + } return x * fact(x - 1); } @@ -388,8 +389,9 @@ double vpMath::fact(unsigned int x) */ long double vpMath::comb(unsigned int n, unsigned int p) { - if (n == p) + if (n == p) { return 1; + } return fact(n) / (fact(n - p) * fact(p)); } @@ -421,13 +423,16 @@ int vpMath::round(double x) */ int vpMath::sign(double x) { - if (fabs(x) < std::numeric_limits::epsilon()) + if (fabs(x) < std::numeric_limits::epsilon()) { return 0; + } else { - if (x < 0) + if (x < 0) { return -1; - else + } + else { return 1; + } } } @@ -470,13 +475,15 @@ bool vpMath::greater(double x, double y, double threshold) { return (x > (y - th */ double vpMath::sigmoid(double x, double x0, double x1, double n) { - if (x < x0) + if (x < x0) { return 0.; - else if (x > x1) + } + else if (x > x1) { return 1.; + } double l0 = 1. / (1. + exp(0.5 * n)); double l1 = 1. / (1. + exp(-0.5 * n)); - return (1. / (1. + exp(-n * ((x - x0) / (x1 - x0) - 0.5))) - l0) / (l1 - l0); + return ((1. / (1. + exp(-n * (((x - x0) / (x1 - x0)) - 0.5)))) - l0) / (l1 - l0); } // unsigned char @@ -487,10 +494,12 @@ template <> inline unsigned char vpMath::saturate(char v) // leading to (int)(char -127) = 129. // On little endian arch, CHAR_MIN=-127 and CHAR_MAX=128 leading to // (int)(char -127) = -127. - if (std::numeric_limits::is_signed) + if (std::numeric_limits::is_signed) { return static_cast(std::max(static_cast(v), 0)); - else + } + else { return static_cast(static_cast(v) > SCHAR_MAX ? 0 : v); + } } template <> inline unsigned char vpMath::saturate(unsigned short v) @@ -571,10 +580,12 @@ template <> inline unsigned short vpMath::saturate(char v) // leading to (int)(char -127) = 129. // On little endian arch, CHAR_MIN=-127 and CHAR_MAX=128 leading to // (int)(char -127) = -127. - if (std::numeric_limits::is_signed) + if (std::numeric_limits::is_signed) { return static_cast(std::max(static_cast(v), 0)); - else + } + else { return static_cast(static_cast(v) > SCHAR_MAX ? 0 : v); + } } template <> inline unsigned short vpMath::saturate(short v) diff --git a/modules/core/include/visp3/core/vpMatrix.h b/modules/core/include/visp3/core/vpMatrix.h index a2151f7498..c3cbf90f62 100644 --- a/modules/core/include/visp3/core/vpMatrix.h +++ b/modules/core/include/visp3/core/vpMatrix.h @@ -217,7 +217,9 @@ class VISP_EXPORT vpMatrix : public vpArray2D free(rowPtrs); rowPtrs = nullptr; } - rowNum = colNum = dsize = 0; + rowNum = 0; + colNum = 0; + dsize = 0; } //------------------------------------------------- @@ -269,7 +271,7 @@ class VISP_EXPORT vpMatrix : public vpArray2D //--------------------------------- /** @name Assignment operators */ //@{ - vpMatrix &operator<<(double *); + vpMatrix &operator<<(double *p); vpMatrix &operator<<(double val); vpMatrix &operator,(double val); vpMatrix &operator=(const vpArray2D &A); diff --git a/modules/core/include/visp3/core/vpMeterPixelConversion.h b/modules/core/include/visp3/core/vpMeterPixelConversion.h index 0334b69d39..23f14744d2 100644 --- a/modules/core/include/visp3/core/vpMeterPixelConversion.h +++ b/modules/core/include/visp3/core/vpMeterPixelConversion.h @@ -114,35 +114,37 @@ class VISP_EXPORT vpMeterPixelConversion case vpCameraParameters::ProjWithKannalaBrandtDistortion: convertPointWithKannalaBrandtDistortion(cam, x, y, u, v); break; + default: + std::cerr << "projection model not identified" << std::endl; } } - /*! + /*! - Point coordinates conversion from normalized coordinates - \f$(x,y)\f$ in meter in the image plane to pixel coordinates in the image using ViSP camera parameters. + Point coordinates conversion from normalized coordinates + \f$(x,y)\f$ in meter in the image plane to pixel coordinates in the image using ViSP camera parameters. - The used formula depends on the projection model of the camera. To - know the currently used projection model use - vpCameraParameter::get_projModel() + The used formula depends on the projection model of the camera. To + know the currently used projection model use + vpCameraParameter::get_projModel() - \param[in] cam : camera parameters. - \param[in] x : input coordinate in meter along image plane x-axis. - \param[in] y : input coordinate in meter along image plane y-axis. - \param[out] iP : output coordinates in pixels. + \param[in] cam : camera parameters. + \param[in] x : input coordinate in meter along image plane x-axis. + \param[in] y : input coordinate in meter along image plane y-axis. + \param[out] iP : output coordinates in pixels. - In the frame (u,v) the result is given by: + In the frame (u,v) the result is given by: - \f$ u = x*p_x + u_0 \f$ and \f$ v = y*p_y + v_0 \f$ in the case of - perspective projection without distortion. + \f$ u = x*p_x + u_0 \f$ and \f$ v = y*p_y + v_0 \f$ in the case of + perspective projection without distortion. - \f$ u = x*p_x*(1+k_{ud}*r^2)+u_0 \f$ and \f$ v = y*p_y*(1+k_{ud}*r^2)+v_0 - \f$ with \f$ r^2 = x^2+y^2 \f$ in the case of perspective projection with - distortion. + \f$ u = x*p_x*(1+k_{ud}*r^2)+u_0 \f$ and \f$ v = y*p_y*(1+k_{ud}*r^2)+v_0 + \f$ with \f$ r^2 = x^2+y^2 \f$ in the case of perspective projection with + distortion. - In the case of a projection with Kannala-Brandt distortion, refer to - \cite KannalaBrandt. - */ + In the case of a projection with Kannala-Brandt distortion, refer to + \cite KannalaBrandt. + */ inline static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, vpImagePoint &iP) { @@ -156,6 +158,8 @@ class VISP_EXPORT vpMeterPixelConversion case vpCameraParameters::ProjWithKannalaBrandtDistortion: convertPointWithKannalaBrandtDistortion(cam, x, y, iP); break; + default: + std::cerr << "projection model not identified" << std::endl; } } @@ -172,8 +176,8 @@ class VISP_EXPORT vpMeterPixelConversion inline static void convertPointWithoutDistortion(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v) { - u = x * cam.m_px + cam.m_u0; - v = y * cam.m_py + cam.m_v0; + u = (x * cam.m_px) + cam.m_u0; + v = (y * cam.m_py) + cam.m_v0; } /*! @@ -189,8 +193,8 @@ class VISP_EXPORT vpMeterPixelConversion inline static void convertPointWithoutDistortion(const vpCameraParameters &cam, const double &x, const double &y, vpImagePoint &iP) { - iP.set_u(x * cam.m_px + cam.m_u0); - iP.set_v(y * cam.m_py + cam.m_v0); + iP.set_u((x * cam.m_px) + cam.m_u0); + iP.set_v((y * cam.m_py) + cam.m_v0); } /*! @@ -212,9 +216,9 @@ class VISP_EXPORT vpMeterPixelConversion inline static void convertPointWithDistortion(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v) { - double r2 = 1. + cam.m_kud * (x * x + y * y); - u = cam.m_u0 + cam.m_px * x * r2; - v = cam.m_v0 + cam.m_py * y * r2; + double r2 = 1. + (cam.m_kud * ((x * x) + (y * y))); + u = cam.m_u0 + (cam.m_px * x * r2); + v = cam.m_v0 + (cam.m_py * y * r2); } /*! @@ -236,9 +240,9 @@ class VISP_EXPORT vpMeterPixelConversion inline static void convertPointWithDistortion(const vpCameraParameters &cam, const double &x, const double &y, vpImagePoint &iP) { - double r2 = 1. + cam.m_kud * (x * x + y * y); - iP.set_u(cam.m_u0 + cam.m_px * x * r2); - iP.set_v(cam.m_v0 + cam.m_py * y * r2); + double r2 = 1. + (cam.m_kud * ((x * x) + (y * y))); + iP.set_u(cam.m_u0 + (cam.m_px * x * r2)); + iP.set_v(cam.m_v0 + (cam.m_py * y * r2)); } /*! @@ -274,15 +278,15 @@ class VISP_EXPORT vpMeterPixelConversion double theta2 = theta * theta, theta3 = theta2 * theta, theta4 = theta2 * theta2, theta5 = theta4 * theta, theta6 = theta3 * theta3, theta7 = theta6 * theta, theta8 = theta4 * theta4, theta9 = theta8 * theta; - double r_d = theta + k[0] * theta3 + k[1] * theta5 + k[2] * theta7 + k[3] * theta9; + double r_d = theta + (k[0] * theta3) + (k[1] * theta5) + (k[2] * theta7) + (k[3] * theta9); - double scale = (std::fabs(r) < std::numeric_limits::epsilon()) ? 1.0 : r_d / r; + double scale = (std::fabs(r) < std::numeric_limits::epsilon()) ? 1.0 : (r_d / r); double x_d = x * scale; double y_d = y * scale; - u = cam.m_px * x_d + cam.m_u0; - v = cam.m_py * y_d + cam.m_v0; + u = (cam.m_px * x_d) + cam.m_u0; + v = (cam.m_py * y_d) + cam.m_v0; } /*! @@ -324,8 +328,8 @@ class VISP_EXPORT vpMeterPixelConversion double x_d = x * scale; double y_d = y * scale; - iP.set_u(cam.m_px * x_d + cam.m_u0); - iP.set_v(cam.m_py * y_d + cam.m_v0); + iP.set_u((cam.m_px * x_d) + cam.m_u0); + iP.set_v((cam.m_py * y_d) + cam.m_v0); } #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS diff --git a/modules/core/include/visp3/core/vpPixelMeterConversion.h b/modules/core/include/visp3/core/vpPixelMeterConversion.h index 13257c139e..5531eb231e 100644 --- a/modules/core/include/visp3/core/vpPixelMeterConversion.h +++ b/modules/core/include/visp3/core/vpPixelMeterConversion.h @@ -111,6 +111,8 @@ class VISP_EXPORT vpPixelMeterConversion case vpCameraParameters::ProjWithKannalaBrandtDistortion: convertPointWithKannalaBrandtDistortion(cam, u, v, x, y); break; + default: + std::cerr << "projection model not identified" << std::endl; } } @@ -153,6 +155,8 @@ class VISP_EXPORT vpPixelMeterConversion case vpCameraParameters::ProjWithKannalaBrandtDistortion: convertPointWithKannalaBrandtDistortion(cam, iP, x, y); break; + default: + std::cerr << "projection model not identified" << std::endl; } } @@ -215,7 +219,7 @@ class VISP_EXPORT vpPixelMeterConversion inline static void convertPointWithDistortion(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y) { - double r2 = 1. + cam.m_kdu * (vpMath::sqr((u - cam.m_u0) * cam.m_inv_px) + vpMath::sqr((v - cam.m_v0) * cam.m_inv_py)); + double r2 = 1. + (cam.m_kdu * (vpMath::sqr((u - cam.m_u0) * cam.m_inv_px) + vpMath::sqr((v - cam.m_v0) * cam.m_inv_py))); x = (u - cam.m_u0) * r2 * cam.m_inv_px; y = (v - cam.m_v0) * r2 * cam.m_inv_py; } @@ -239,8 +243,8 @@ class VISP_EXPORT vpPixelMeterConversion inline static void convertPointWithDistortion(const vpCameraParameters &cam, const vpImagePoint &iP, double &x, double &y) { - double r2 = 1. + cam.m_kdu * (vpMath::sqr((iP.get_u() - cam.m_u0) * cam.m_inv_px) + - vpMath::sqr((iP.get_v() - cam.m_v0) * cam.m_inv_py)); + double r2 = 1. + (cam.m_kdu * (vpMath::sqr((iP.get_u() - cam.m_u0) * cam.m_inv_px) + + vpMath::sqr((iP.get_v() - cam.m_v0) * cam.m_inv_py))); x = (iP.get_u() - cam.m_u0) * r2 * cam.m_inv_px; y = (iP.get_v() - cam.m_v0) * r2 * cam.m_inv_py; } @@ -286,12 +290,15 @@ class VISP_EXPORT vpPixelMeterConversion double theta2 = theta * theta, theta4 = theta2 * theta2, theta6 = theta4 * theta2, theta8 = theta6 * theta2; double k0_theta2 = k[0] * theta2, k1_theta4 = k[1] * theta4, k2_theta6 = k[2] * theta6, k3_theta8 = k[3] * theta8; - /* new_theta = theta - theta_fix, theta_fix = f0(theta) / f0'(theta) */ + /* + // new_theta = theta - theta_fix, theta_fix = f0(theta) / f0'(theta) + */ double theta_fix = (theta * (1 + k0_theta2 + k1_theta4 + k2_theta6 + k3_theta8) - r_d) / (1 + 3 * k0_theta2 + 5 * k1_theta4 + 7 * k2_theta6 + 9 * k3_theta8); theta = theta - theta_fix; - if (fabs(theta_fix) < EPS) + if (fabs(theta_fix) < EPS) { break; + } } scale = std::tan(theta) / r_d; // Scale of norm of (x,y) and (x_d, y_d) @@ -341,9 +348,11 @@ class VISP_EXPORT vpPixelMeterConversion double theta2 = theta * theta, theta4 = theta2 * theta2, theta6 = theta4 * theta2, theta8 = theta6 * theta2; double k0_theta2 = k[0] * theta2, k1_theta4 = k[1] * theta4, k2_theta6 = k[2] * theta6, k3_theta8 = k[3] * theta8; - /* new_theta = theta - theta_fix, theta_fix = f0(theta) / f0'(theta) */ - double theta_fix = (theta * (1 + k0_theta2 + k1_theta4 + k2_theta6 + k3_theta8) - r_d) / - (1 + 3 * k0_theta2 + 5 * k1_theta4 + 7 * k2_theta6 + 9 * k3_theta8); + /* + // new_theta = theta - theta_fix, theta_fix = f0(theta) / f0'(theta) + */ + double theta_fix = ((theta * (1 + k0_theta2 + k1_theta4 + k2_theta6 + k3_theta8)) - r_d) / + (1 + (3 * k0_theta2) + (5 * k1_theta4) + (7 * k2_theta6) + (9 * k3_theta8)); theta = theta - theta_fix; if (fabs(theta_fix) < EPS) break; diff --git a/modules/core/include/visp3/core/vpRansac.h b/modules/core/include/visp3/core/vpRansac.h index cd9af76540..2be17d461c 100644 --- a/modules/core/include/visp3/core/vpRansac.h +++ b/modules/core/include/visp3/core/vpRansac.h @@ -107,9 +107,11 @@ bool vpRansac::ransac(unsigned int npts, const vpColVector &x, vpColVector &M, vpColVector &inliers, int consensus, double not_used, int maxNbumbersOfTrials, double *residual) { - /* bool isplanar; */ - /* if (s == 4) isplanar = true; */ - /* else isplanar = false; */ + /* + // bool isplanar; + // if (s == 4) isplanar = true; + // else isplanar = false; + */ (void)not_used; double eps = 1e-6; double p = 0.99; // Desired probability of choosing at least one sample @@ -119,8 +121,9 @@ bool vpRansac::ransac(unsigned int npts, const vpColVector &x, int maxDataTrials = 1000; // Max number of attempts to select a non-degenerate // data set. - if (s < 4) + if (s < 4) { s = 4; + } // Sentinel value allowing detection of solution failure. bool solutionFind = false; @@ -129,7 +132,7 @@ bool vpRansac::ransac(unsigned int npts, const vpColVector &x, int bestscore = -1; double N = 1; // Dummy initialisation for number of trials. - vpUniRand random((const long)time(nullptr)); + vpUniRand random(static_cast(time(nullptr))); vpColVector bestinliers; unsigned int *ind = new unsigned int[s]; int ninliers = 0; @@ -150,8 +153,9 @@ bool vpRansac::ransac(unsigned int npts, const vpColVector &x, // Test that these points are not a degenerate configuration. degenerate = vpTransformation::degenerateConfiguration(x, ind); + /* // degenerate = feval(degenfn, x(:,ind)); - + */ // Safeguard against being stuck in this loop forever count = count + 1; @@ -159,7 +163,9 @@ bool vpRansac::ransac(unsigned int npts, const vpColVector &x, delete[] ind; vpERROR_TRACE("Unable to select a nondegenerate data set"); throw(vpException(vpException::fatalError, "Unable to select a non degenerate data set")); + /* // return false; //Useless after a throw() function + */ } } // Fit model to this random selection of data points. @@ -178,13 +184,14 @@ bool vpRansac::ransac(unsigned int npts, const vpColVector &x, double resid = fabs(d[i]); if (resid < t) { inliers[i] = 1; - ninliers++; + ++ninliers; if (residual != nullptr) { *residual += fabs(d[i]); } } - else + else { inliers[i] = 0; + } } if (ninliers > bestscore) // Largest set of inliers so far... @@ -197,7 +204,7 @@ bool vpRansac::ransac(unsigned int npts, const vpColVector &x, // Update estimate of N, the number of trials to ensure we pick, // with probability p, a data set with no outliers. - double fracinliers = (double)ninliers / (double)npts; + double fracinliers = static_cast(ninliers) / static_cast(npts); double pNoOutliers = 1 - pow(fracinliers, static_cast(s)); diff --git a/modules/core/include/visp3/core/vpRect.h b/modules/core/include/visp3/core/vpRect.h index 5531af3a9d..207720d00e 100644 --- a/modules/core/include/visp3/core/vpRect.h +++ b/modules/core/include/visp3/core/vpRect.h @@ -91,7 +91,7 @@ class VISP_EXPORT vpRect Returns the bottom coordinate of the rectangle. \sa getRight() */ - inline double getBottom() const { return (this->top + this->height - 1.0); } + inline double getBottom() const { return ((this->top + this->height) - 1.0); } /*! Returns the bottom-left position of the rectangle. @@ -132,8 +132,8 @@ class VISP_EXPORT vpRect */ inline void getCenter(double &x, double &y) const { - x = this->left + this->width / 2.0 - 0.5; - y = this->top + this->height / 2.0 - 0.5; + x = (this->left + (this->width / 2.0)) - 0.5; + y = (this->top + (this->height / 2.0)) - 0.5; } /*! @@ -149,8 +149,8 @@ class VISP_EXPORT vpRect inline vpImagePoint getCenter() const { vpImagePoint center; - center.set_u(this->left + this->width / 2.0 - 0.5); - center.set_v(this->top + this->height / 2.0 - 0.5); + center.set_u((this->left + (this->width / 2.0)) - 0.5); + center.set_v((this->top + (this->height / 2.0)) - 0.5); return center; } @@ -173,7 +173,7 @@ class VISP_EXPORT vpRect Returns the right coordinate of the rectangle. \sa getLeft() */ - inline double getRight() const { return (this->left + this->width - 1.0); } + inline double getRight() const { return ((this->left + this->width) - 1.0); } /*! Returns the size of the rectangle. @@ -246,7 +246,7 @@ class VISP_EXPORT vpRect left = x1; top = y1; - if (width <= 0 || height <= 0) { + if ((width <= 0) || (height <= 0)) { *this = vpRect(); } @@ -282,7 +282,7 @@ class VISP_EXPORT vpRect \sa setTop() */ - inline void setBottom(double pos) { this->height = pos - this->top + 1.0; } + inline void setBottom(double pos) { this->height = (pos - this->top) + 1.0; } /*! Sets the bottom-right position of the rectangle. Will never change @@ -292,8 +292,8 @@ class VISP_EXPORT vpRect */ inline void setBottomRight(const vpImagePoint &bottomRight) { - this->height = bottomRight.get_v() - this->top + 1.0; - this->width = bottomRight.get_u() - this->left + 1.0; + this->height = (bottomRight.get_v() - this->top) + 1.0; + this->width = (bottomRight.get_u() - this->left) + 1.0; } /*! @@ -386,8 +386,8 @@ class VISP_EXPORT vpRect */ inline void moveCenter(double x, double y) { - this->left = x - this->width / 2 + 0.5; - this->top = y - this->height / 2 + 0.5; + this->left = (x - (this->width / 2)) + 0.5; + this->top = (y - (this->height / 2)) + 0.5; } /*! @@ -398,8 +398,8 @@ class VISP_EXPORT vpRect */ inline void moveCenter(const vpImagePoint ¢er) { - this->left = center.get_u() - this->width / 2 + 0.5; - this->top = center.get_v() - this->height / 2 + 0.5; + this->left = (center.get_u() - (this->width / 2)) + 0.5; + this->top = (center.get_v() - (this->height / 2)) + 0.5; } private: diff --git a/modules/core/include/visp3/core/vpRectOriented.h b/modules/core/include/visp3/core/vpRectOriented.h index dbaf468f3f..afe8667a66 100644 --- a/modules/core/include/visp3/core/vpRectOriented.h +++ b/modules/core/include/visp3/core/vpRectOriented.h @@ -55,7 +55,7 @@ class VISP_EXPORT vpRectOriented vpRectOriented(const vpImagePoint ¢er, double width, double height, double theta = 0); - vpRectOriented(const vpRect &rect); + explicit vpRectOriented(const vpRect &rect); #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) vpRectOriented &operator=(const vpRectOriented &) = default; diff --git a/modules/core/include/visp3/core/vpRotationVector.h b/modules/core/include/visp3/core/vpRotationVector.h index 49c3daae09..ac49de5431 100644 --- a/modules/core/include/visp3/core/vpRotationVector.h +++ b/modules/core/include/visp3/core/vpRotationVector.h @@ -127,7 +127,8 @@ class VISP_EXPORT vpRotationVector : public vpArray2D vpRotationVector &operator=(const vpRotationVector &v) { resize(v.size(), 1); - for (unsigned int i = 0; i < v.size(); ++i) { + unsigned int v_size = v.size(); + for (unsigned int i = 0; i < v_size; ++i) { data[i] = v.data[i]; } return *this; diff --git a/modules/core/include/visp3/core/vpRowVector.h b/modules/core/include/visp3/core/vpRowVector.h index 873eac222a..3119f303da 100644 --- a/modules/core/include/visp3/core/vpRowVector.h +++ b/modules/core/include/visp3/core/vpRowVector.h @@ -117,13 +117,13 @@ class VISP_EXPORT vpRowVector : public vpArray2D //! one. vpRowVector(const vpRowVector &v) : vpArray2D(v) { } vpRowVector(const vpRowVector &v, unsigned int c, unsigned int ncols); - vpRowVector(const vpMatrix &M); + explicit vpRowVector(const vpMatrix &M); vpRowVector(const vpMatrix &M, unsigned int i); - vpRowVector(const std::vector &v); - vpRowVector(const std::vector &v); + explicit vpRowVector(const std::vector &v); + explicit vpRowVector(const std::vector &v); #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) vpRowVector(vpRowVector &&v); - vpRowVector(const std::initializer_list &list) : vpArray2D(list) { } + explicit vpRowVector(const std::initializer_list &list) : vpArray2D(list) { } #endif /*! @@ -141,7 +141,9 @@ class VISP_EXPORT vpRowVector : public vpArray2D free(rowPtrs); rowPtrs = nullptr; } - rowNum = colNum = dsize = 0; + rowNum = 0; + colNum = 0; + dsize = 0; } std::ostream &cppPrint(std::ostream &os, const std::string &matrixName = "A", bool octet = false) const; @@ -178,7 +180,7 @@ class VISP_EXPORT vpRowVector : public vpArray2D */ vpRowVector extract(unsigned int c, unsigned int rowsize) const { - if (c >= colNum || c + rowsize > colNum) { + if ((c >= colNum) || ((c + rowsize) > colNum)) { throw(vpException(vpException::fatalError, "Cannot extract a (1x%d) row vector from a (1x%d) " "row vector starting at index %d", @@ -270,11 +272,12 @@ class VISP_EXPORT vpRowVector : public vpArray2D */ void resize(unsigned int nrows, unsigned int ncols, bool flagNullify) { - if (nrows != 1) + if (nrows != 1) { throw(vpException(vpException::fatalError, "Cannot resize a row vector to a (%dx%d) dimension " "vector that has more than one row", nrows, ncols)); + } vpArray2D::resize(nrows, ncols, flagNullify); } diff --git a/modules/core/include/visp3/core/vpSubColVector.h b/modules/core/include/visp3/core/vpSubColVector.h index ad97b7d2df..ebfe81edc0 100644 --- a/modules/core/include/visp3/core/vpSubColVector.h +++ b/modules/core/include/visp3/core/vpSubColVector.h @@ -56,7 +56,7 @@ class VISP_EXPORT vpSubColVector : public vpColVector { private: //! Copy constructor unavailable - vpSubColVector(const vpSubColVector & /* m */); + vpSubColVector(const vpSubColVector &v /* m */); protected: //! Number of row of parent vpColVector at initialization diff --git a/modules/core/include/visp3/core/vpSubMatrix.h b/modules/core/include/visp3/core/vpSubMatrix.h index d4fbfe6b01..8959603ba1 100644 --- a/modules/core/include/visp3/core/vpSubMatrix.h +++ b/modules/core/include/visp3/core/vpSubMatrix.h @@ -59,7 +59,7 @@ class VISP_EXPORT vpSubMatrix : public vpMatrix //! Eye method unavailable void eye(unsigned int m, unsigned int n); //! Copy constructor unavailable - vpSubMatrix(const vpSubMatrix & /* m */); + vpSubMatrix(const vpSubMatrix &m /* m */); protected: unsigned int pRowNum; diff --git a/modules/core/include/visp3/core/vpSubRowVector.h b/modules/core/include/visp3/core/vpSubRowVector.h index c5fa99611a..ffd5e1b0c1 100644 --- a/modules/core/include/visp3/core/vpSubRowVector.h +++ b/modules/core/include/visp3/core/vpSubRowVector.h @@ -56,7 +56,7 @@ class VISP_EXPORT vpSubRowVector : public vpRowVector { private: //! Copy constructor unavailable - vpSubRowVector(const vpSubRowVector & /* m */); + vpSubRowVector(const vpSubRowVector &m /* m */); protected: //! Number of row of parent vpColVector at initialization diff --git a/modules/core/include/visp3/core/vpVelocityTwistMatrix.h b/modules/core/include/visp3/core/vpVelocityTwistMatrix.h index d8a3ccf0ab..e87504ae2d 100644 --- a/modules/core/include/visp3/core/vpVelocityTwistMatrix.h +++ b/modules/core/include/visp3/core/vpVelocityTwistMatrix.h @@ -175,8 +175,8 @@ class VISP_EXPORT vpVelocityTwistMatrix : public vpArray2D vpVelocityTwistMatrix(const vpTranslationVector &t, const vpThetaUVector &thetau); vpVelocityTwistMatrix(double tx, double ty, double tz, double tux, double tuy, double tuz); - vpVelocityTwistMatrix(const vpRotationMatrix &R); - vpVelocityTwistMatrix(const vpThetaUVector &thetau); + explicit vpVelocityTwistMatrix(const vpRotationMatrix &R); + explicit vpVelocityTwistMatrix(const vpThetaUVector &thetau); vpVelocityTwistMatrix buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R); vpVelocityTwistMatrix buildFrom(const vpTranslationVector &t, const vpThetaUVector &thetau); diff --git a/modules/core/include/visp3/core/vpXmlParserCamera.h b/modules/core/include/visp3/core/vpXmlParserCamera.h index 565f739b9e..ebfb896dca 100644 --- a/modules/core/include/visp3/core/vpXmlParserCamera.h +++ b/modules/core/include/visp3/core/vpXmlParserCamera.h @@ -191,7 +191,7 @@ class VISP_EXPORT vpXmlParserCamera void setWidth(unsigned int width); private: - vpXmlParserCamera(const vpXmlParserCamera &); // noncopyable + vpXmlParserCamera(const vpXmlParserCamera &c); // noncopyable vpXmlParserCamera &operator=(const vpXmlParserCamera &); // // PIMPL idiom diff --git a/modules/core/include/visp3/core/vpXmlParserHomogeneousMatrix.h b/modules/core/include/visp3/core/vpXmlParserHomogeneousMatrix.h index d8243259ee..b99d65609b 100644 --- a/modules/core/include/visp3/core/vpXmlParserHomogeneousMatrix.h +++ b/modules/core/include/visp3/core/vpXmlParserHomogeneousMatrix.h @@ -39,8 +39,8 @@ */ -#ifndef vpXMLPARSERHOMOGENEOUSMATRIX_H -#define vpXMLPARSERHOMOGENEOUSMATRIX_H +#ifndef VP_XMLPARSERHOMOGENEOUSMATRIX_H +#define VP_XMLPARSERHOMOGENEOUSMATRIX_H #include @@ -164,7 +164,7 @@ class VISP_EXPORT vpXmlParserHomogeneousMatrix void setHomogeneousMatrixName(const std::string &name); private: - vpXmlParserHomogeneousMatrix(const vpXmlParserHomogeneousMatrix &); // noncopyable + vpXmlParserHomogeneousMatrix(const vpXmlParserHomogeneousMatrix &hm); // noncopyable vpXmlParserHomogeneousMatrix &operator=(const vpXmlParserHomogeneousMatrix &); // // PIMPL idiom diff --git a/modules/core/include/visp3/core/vpXmlParserRectOriented.h b/modules/core/include/visp3/core/vpXmlParserRectOriented.h index 52dcff8e69..861546c013 100644 --- a/modules/core/include/visp3/core/vpXmlParserRectOriented.h +++ b/modules/core/include/visp3/core/vpXmlParserRectOriented.h @@ -101,7 +101,7 @@ class VISP_EXPORT vpXmlParserRectOriented void setRectangle(const vpRectOriented &rectangle); private: - vpXmlParserRectOriented(const vpXmlParserRectOriented &); // noncopyable + vpXmlParserRectOriented(const vpXmlParserRectOriented &ro); // noncopyable vpXmlParserRectOriented &operator=(const vpXmlParserRectOriented &); // // PIMPL idiom diff --git a/modules/imgproc/include/visp3/imgproc/vpCircleHoughTransform.h b/modules/imgproc/include/visp3/imgproc/vpCircleHoughTransform.h index d51df0d51c..d006d836c4 100644 --- a/modules/imgproc/include/visp3/imgproc/vpCircleHoughTransform.h +++ b/modules/imgproc/include/visp3/imgproc/vpCircleHoughTransform.h @@ -67,56 +67,6 @@ class VISP_EXPORT vpCircleHoughTransform */ class vpCircleHoughTransformParameters { - private: - // // Filtering + gradient operators to use - vpImageFilter::vpCannyFilteringAndGradientType m_filteringAndGradientType; /*!< Permits to choose the filtering + - gradient operators to use.*/ - - // // Gaussian smoothing attributes - int m_gaussianKernelSize; /*!< Size of the Gaussian filter kernel used to smooth the input image. - Must be an odd number.*/ - float m_gaussianStdev; /*!< Standard deviation of the Gaussian filter.*/ - - // // Gradient computation attributes - int m_gradientFilterKernelSize; /*!< Size of the Sobel or Scharr kernels used to compute the gradients. Must be an odd number.*/ - - // // Edge detection attributes - float m_lowerCannyThresh; /*!< The lower threshold for the Canny operator. Values lower than this value are rejected. - A negative value makes the algorithm compute the lower threshold automatically.*/ - float m_upperCannyThresh; /*!< The upper threshold for the Canny operator. Only values greater than this value are marked as an edge. - A negative value makes the algorithm compute the upper and lower thresholds automatically.*/ - int m_edgeMapFilteringNbIter; /*!< Number of iterations of 8-neighbor connectivity filtering to apply to the edge map*/ - vpImageFilter::vpCannyBackendType m_cannyBackendType; /*!< Permits to choose the backend used to compute the edge map.*/ - float m_lowerCannyThreshRatio; /*!< The ratio of the upper threshold the lower threshold must be equal to. - It is used only if the user asks to compute the Canny thresholds.*/ - float m_upperCannyThreshRatio; /*!< The ratio of pixels whose absolute gradient Gabs is lower or equal to define - the upper threshold. It is used only if the user asks to compute the Canny thresholds.*/ - - // // Center candidates computation attributes - std::pair m_centerXlimits; /*!< Minimum and maximum position on the horizontal axis of the center of the circle we want to detect.*/ - std::pair m_centerYlimits; /*!< Minimum and maximum position on the vertical axis of the center of the circle we want to detect.*/ - float m_minRadius; /*!< Minimum radius of the circles we want to detect.*/ - float m_maxRadius; /*!< Maximum radius of the circles we want to detect.*/ - int m_dilatationKernelSize; /*!< Kernel size of the dilatation that is performed to detect the maximum number of votes for the center candidates.*/ - int m_averagingWindowSize; /*!< Size of the averaging window around the maximum number of votes to compute the - center candidate such as it is the barycenter of the window. Must be odd.*/ - float m_centerMinThresh; /*!< Minimum number of votes a point must exceed to be considered as center candidate.*/ - int m_expectedNbCenters; /*!< Expected number of different centers in the image. If negative, all candidates centers - are kept, otherwise only up to this number are kept.*/ - - // // Circle candidates computation attributes - float m_circleProbaThresh; /*!< Probability threshold in order to keep a circle candidate.*/ - float m_circlePerfectness; /*!< The threshold for the colinearity between the gradient of a point - and the radius it would form with a center candidate to be able to vote. - The formula to get the equivalent angle is: `angle = acos(circle_perfectness)`. */ - float m_circleVisibilityRatioThresh; /*!< Visibility ratio threshold: minimum ratio of the circle must be visible in order to keep a circle candidate.*/ - bool m_recordVotingPoints; /*!< If true, the edge-map points having voted for each circle will be stored.*/ - - // // Circle candidates merging attributes - float m_centerMinDist; /*!< Maximum distance between two circle candidates centers to consider merging them.*/ - float m_mergingRadiusDiffThresh; /*!< Maximum radius difference between two circle candidates to consider merging them.*/ - - friend class vpCircleHoughTransform; public: /** * \brief Construct a new vpCircleHoughTransformParameters object with default parameters. @@ -479,7 +429,8 @@ class VISP_EXPORT vpCircleHoughTransform txt << "\tCircle probability threshold = " << m_circleProbaThresh << "\n"; txt << "\tCircle visibility ratio threshold = " << m_circleVisibilityRatioThresh << "\n"; txt << "\tCircle perfectness threshold = " << m_circlePerfectness << "\n"; - txt << "\tRecord voting points = " + (m_recordVotingPoints ? std::string("true") : std::string("false")) << "\n"; + txt << "\tRecord voting points = "; + txt << (m_recordVotingPoints ? std::string("true") : std::string("false")) << "\n"; txt << "\tCenters minimum distance = " << m_centerMinDist << "\n"; txt << "\tRadius difference merging threshold = " << m_mergingRadiusDiffThresh << "\n"; return txt.str(); @@ -651,6 +602,57 @@ class VISP_EXPORT vpCircleHoughTransform {"mergingRadiusDiffThresh", params.m_mergingRadiusDiffThresh} }; } #endif + + private: + // // Filtering + gradient operators to use + vpImageFilter::vpCannyFilteringAndGradientType m_filteringAndGradientType; /*!< Permits to choose the filtering + + gradient operators to use.*/ + + // // Gaussian smoothing attributes + int m_gaussianKernelSize; /*!< Size of the Gaussian filter kernel used to smooth the input image. + Must be an odd number.*/ + float m_gaussianStdev; /*!< Standard deviation of the Gaussian filter.*/ + + // // Gradient computation attributes + int m_gradientFilterKernelSize; /*!< Size of the Sobel or Scharr kernels used to compute the gradients. Must be an odd number.*/ + + // // Edge detection attributes + float m_lowerCannyThresh; /*!< The lower threshold for the Canny operator. Values lower than this value are rejected. + A negative value makes the algorithm compute the lower threshold automatically.*/ + float m_upperCannyThresh; /*!< The upper threshold for the Canny operator. Only values greater than this value are marked as an edge. + A negative value makes the algorithm compute the upper and lower thresholds automatically.*/ + int m_edgeMapFilteringNbIter; /*!< Number of iterations of 8-neighbor connectivity filtering to apply to the edge map*/ + vpImageFilter::vpCannyBackendType m_cannyBackendType; /*!< Permits to choose the backend used to compute the edge map.*/ + float m_lowerCannyThreshRatio; /*!< The ratio of the upper threshold the lower threshold must be equal to. + It is used only if the user asks to compute the Canny thresholds.*/ + float m_upperCannyThreshRatio; /*!< The ratio of pixels whose absolute gradient Gabs is lower or equal to define + the upper threshold. It is used only if the user asks to compute the Canny thresholds.*/ + + // // Center candidates computation attributes + std::pair m_centerXlimits; /*!< Minimum and maximum position on the horizontal axis of the center of the circle we want to detect.*/ + std::pair m_centerYlimits; /*!< Minimum and maximum position on the vertical axis of the center of the circle we want to detect.*/ + float m_minRadius; /*!< Minimum radius of the circles we want to detect.*/ + float m_maxRadius; /*!< Maximum radius of the circles we want to detect.*/ + int m_dilatationKernelSize; /*!< Kernel size of the dilatation that is performed to detect the maximum number of votes for the center candidates.*/ + int m_averagingWindowSize; /*!< Size of the averaging window around the maximum number of votes to compute the + center candidate such as it is the barycenter of the window. Must be odd.*/ + float m_centerMinThresh; /*!< Minimum number of votes a point must exceed to be considered as center candidate.*/ + int m_expectedNbCenters; /*!< Expected number of different centers in the image. If negative, all candidates centers + are kept, otherwise only up to this number are kept.*/ + + // // Circle candidates computation attributes + float m_circleProbaThresh; /*!< Probability threshold in order to keep a circle candidate.*/ + float m_circlePerfectness; /*!< The threshold for the colinearity between the gradient of a point + and the radius it would form with a center candidate to be able to vote. + The formula to get the equivalent angle is: `angle = acos(circle_perfectness)`. */ + float m_circleVisibilityRatioThresh; /*!< Visibility ratio threshold: minimum ratio of the circle must be visible in order to keep a circle candidate.*/ + bool m_recordVotingPoints; /*!< If true, the edge-map points having voted for each circle will be stored.*/ + + // // Circle candidates merging attributes + float m_centerMinDist; /*!< Maximum distance between two circle candidates centers to consider merging them.*/ + float m_mergingRadiusDiffThresh; /*!< Maximum radius difference between two circle candidates to consider merging them.*/ + + friend class vpCircleHoughTransform; }; /** @@ -663,7 +665,7 @@ class VISP_EXPORT vpCircleHoughTransform * from a \b vpCircleHoughTransformParameters object. * \param[in] algoParams The parameters of the Circle Hough Transform. */ - vpCircleHoughTransform(const vpCircleHoughTransformParameters &algoParams); + explicit vpCircleHoughTransform(const vpCircleHoughTransformParameters &algoParams); /** * \brief Destroy the vp Circle Hough Transform object @@ -945,7 +947,7 @@ class VISP_EXPORT vpCircleHoughTransform void setCirclePerfectness(const float &circle_perfectness) { m_algoParams.m_circlePerfectness = circle_perfectness; - if (m_algoParams.m_circlePerfectness <= 0 || m_algoParams.m_circlePerfectness > 1) { + if ((m_algoParams.m_circlePerfectness <= 0) || (m_algoParams.m_circlePerfectness > 1)) { throw vpException(vpException::badValue, "Circle perfectness must be in the interval ] 0; 1]."); } }