Cleanup: use braces in headers

This commit is contained in:
Campbell Barton
2023-09-24 14:52:38 +10:00
parent d1d570d318
commit 2721b937fb
63 changed files with 605 additions and 308 deletions

View File

@@ -174,8 +174,9 @@ class ArrayND : public BaseArray {
/// Return the number of elements of the array.
int Size() const {
int size = 1;
for (int i = 0; i < N; ++i)
for (int i = 0; i < N; ++i) {
size *= Shape(i);
}
return size;
}
@@ -191,8 +192,9 @@ class ArrayND : public BaseArray {
/// Distance between the first element and the element at position index.
int Offset(const Index& index) const {
int offset = 0;
for (int i = 0; i < N; ++i)
for (int i = 0; i < N; ++i) {
offset += index(i) * Stride(i);
}
return offset;
}
@@ -260,9 +262,11 @@ class ArrayND : public BaseArray {
/// True if index is inside array.
bool Contains(const Index& index) const {
for (int i = 0; i < N; ++i)
if (index(i) < 0 || index(i) >= Shape(i))
for (int i = 0; i < N; ++i) {
if (index(i) < 0 || index(i) >= Shape(i)) {
return false;
}
}
return true;
}
@@ -281,13 +285,16 @@ class ArrayND : public BaseArray {
}
bool operator==(const ArrayND<T, N>& other) const {
if (shape_ != other.shape_)
if (shape_ != other.shape_) {
return false;
if (strides_ != other.strides_)
}
if (strides_ != other.strides_) {
return false;
}
for (int i = 0; i < Size(); ++i) {
if (this->Data()[i] != other.Data()[i])
if (this->Data()[i] != other.Data()[i]) {
return false;
}
}
return true;
}
@@ -401,8 +408,9 @@ void MultiplyElements(const AArrayType& a, const BArrayType& b, CArrayType* c) {
// The index starts at the maximum value for each dimension
const typename CArrayType::Index& cShape = c->Shape();
for (int i = 0; i < CArrayType::Index::SIZE; ++i)
for (int i = 0; i < CArrayType::Index::SIZE; ++i) {
index(i) = cShape(i) - 1;
}
// After each multiplication, the highest-dimensional index is reduced.
// if this reduces it less than zero, it resets to its maximum value

View File

@@ -35,8 +35,9 @@ namespace libmv {
/// is inside the image.
template <class Image, class Color>
inline void safePutPixel(int yc, int xc, const Color& col, Image* pim) {
if (!pim)
if (!pim) {
return;
}
if (pim->Contains(yc, xc)) {
(*pim)(yc, xc) = col;
}
@@ -46,11 +47,13 @@ inline void safePutPixel(int yc, int xc, const Color& col, Image* pim) {
/// \note The color pointer col must have size as the image depth
template <class Image, class Color>
inline void safePutPixel(int yc, int xc, const Color* col, Image* pim) {
if (!pim)
if (!pim) {
return;
}
if (pim->Contains(yc, xc)) {
for (int i = 0; i < pim->Depth(); ++i)
for (int i = 0; i < pim->Depth(); ++i) {
(*pim)(yc, xc, i) = *(col + i);
}
}
}
@@ -195,8 +198,9 @@ void DrawLine(int xa, int ya, int xb, int yb, const Color& col, Image* pim) {
&yup = ydir ? ny0 : ny1, &xdown = ydir ? nx1 : nx0,
&ydown = ydir ? ny1 : ny0;
if (xright < 0 || xleft >= width)
if (xright < 0 || xleft >= width) {
return;
}
if (xleft < 0) {
yleft -= xleft * (yright - yleft) / (xright - xleft);
xleft = 0;
@@ -205,8 +209,9 @@ void DrawLine(int xa, int ya, int xb, int yb, const Color& col, Image* pim) {
yright -= (xright - width) * (yright - yleft) / (xright - xleft);
xright = width - 1;
}
if (ydown < 0 || yup >= height)
if (ydown < 0 || yup >= height) {
return;
}
if (yup < 0) {
xup -= yup * (xdown - xup) / (ydown - yup);
yup = 0;

View File

@@ -50,16 +50,18 @@ struct AsymmetricError {
static void Residuals(const Mat& H, const Mat& x1, const Mat& x2, Mat2X* dx) {
dx->resize(2, x1.cols());
Mat3X x2h_est;
if (x1.rows() == 2)
if (x1.rows() == 2) {
x2h_est = H * EuclideanToHomogeneous(static_cast<Mat2X>(x1));
else
} else {
x2h_est = H * x1;
}
dx->row(0) = x2h_est.row(0).array() / x2h_est.row(2).array();
dx->row(1) = x2h_est.row(1).array() / x2h_est.row(2).array();
if (x2.rows() == 2)
if (x2.rows() == 2) {
*dx = x2 - *dx;
else
} else {
*dx = HomogeneousToEuclidean(static_cast<Mat3X>(x2)) - *dx;
}
}
/**
* Computes the asymmetric residuals between a 2D point x2 and the transformed
@@ -75,15 +77,17 @@ struct AsymmetricError {
*/
static void Residuals(const Mat& H, const Vec& x1, const Vec& x2, Vec2* dx) {
Vec3 x2h_est;
if (x1.rows() == 2)
if (x1.rows() == 2) {
x2h_est = H * EuclideanToHomogeneous(static_cast<Vec2>(x1));
else
} else {
x2h_est = H * x1;
if (x2.rows() == 2)
}
if (x2.rows() == 2) {
*dx = x2 - x2h_est.head<2>() / x2h_est[2];
else
} else {
*dx = HomogeneousToEuclidean(static_cast<Vec3>(x2)) -
x2h_est.head<2>() / x2h_est[2];
}
}
/**
* Computes the squared norm of the residuals between a set of 2D points x2
@@ -190,14 +194,16 @@ struct AlgebraicError {
*/
static void Residuals(const Mat& H, const Vec& x1, const Vec& x2, Vec3* dx) {
Vec3 x2h_est;
if (x1.rows() == 2)
if (x1.rows() == 2) {
x2h_est = H * EuclideanToHomogeneous(static_cast<Vec2>(x1));
else
} else {
x2h_est = H * x1;
if (x2.rows() == 2)
}
if (x2.rows() == 2) {
*dx = SkewMat(EuclideanToHomogeneous(static_cast<Vec2>(x2))) * x2h_est;
else
} else {
*dx = SkewMat(x2) * x2h_est;
}
// TODO(julien) This is inefficient since it creates an
// identical 3x3 skew matrix for each evaluation.
}

View File

@@ -183,10 +183,11 @@ double Depth(const Mat3& R, const Vec3& t, const Vec4& X);
inline bool isInFrontOfCamera(const Mat34& P, const Vec4& X) {
double condition_1 = P.row(2).dot(X) * X[3];
double condition_2 = X[2] * X[3];
if (condition_1 > 0 && condition_2 > 0)
if (condition_1 > 0 && condition_2 > 0) {
return true;
else
} else {
return false;
}
}
inline bool isInFrontOfCamera(const Mat34& P, const Vec3& X) {

View File

@@ -229,12 +229,15 @@ class Dogleg {
}
Scalar rho = actual / predicted;
if (step == GAUSS_NEWTON)
if (step == GAUSS_NEWTON) {
printf(" GAUSS");
if (step == STEEPEST_DESCENT)
}
if (step == STEEPEST_DESCENT) {
printf(" STEE");
if (step == DOGLEG)
}
if (step == DOGLEG) {
printf(" DOGL");
}
printf(" %12g %12g %12g\n", rho, actual, predicted);

View File

@@ -158,10 +158,11 @@ template <typename TMat, typename TVec>
double Nullspace(TMat* A, TVec* nullspace) {
Eigen::JacobiSVD<TMat> svd(*A, Eigen::ComputeFullV);
(*nullspace) = svd.matrixV().col(A->cols() - 1);
if (A->rows() >= A->cols())
if (A->rows() >= A->cols()) {
return svd.singularValues()(A->cols() - 1);
else
} else {
return 0.0;
}
}
// Solve the linear system Ax = 0 via SVD. Finds two solutions, x1 and x2, such
@@ -174,10 +175,11 @@ double Nullspace2(TMat* A, TVec1* x1, TVec2* x2) {
Eigen::JacobiSVD<TMat> svd(*A, Eigen::ComputeFullV);
*x1 = svd.matrixV().col(A->cols() - 1);
*x2 = svd.matrixV().col(A->cols() - 2);
if (A->rows() >= A->cols())
if (A->rows() >= A->cols()) {
return svd.singularValues()(A->cols() - 1);
else
} else {
return 0.0;
}
}
// In place transpose for square matrices.