Skip to content

Commit

Permalink
Merge pull request #1601 from alicevision/clang/formatSoftware
Browse files Browse the repository at this point in the history
[software] Apply clang-formatting on all the executables
  • Loading branch information
fabiencastan authored Jan 15, 2024
2 parents 3e4dff1 + 341aa19 commit 064ff12
Show file tree
Hide file tree
Showing 127 changed files with 9,668 additions and 9,919 deletions.
4 changes: 4 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# [aliceVision] Reformat src/aliceVision with latest clang-format rules
0fb0a02b75142bcf3b23009428028e2198917275
# [software] Reformat src/software with latest clang-format rules
ea46ddca23332c115790c02105372bda37d943e3
# Apply `clang-format` on modified files
807034b1eb101b19b3bc9b9078a1635460591959
# Estimator states in SfMData: Apply clang-format across all files
Expand Down
53 changes: 25 additions & 28 deletions src/aliceVision/camera/DistortionBrown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
namespace aliceVision {
namespace camera {

Vec2 DistortionBrown::addDistortion(const Vec2& p) const
{
Vec2 DistortionBrown::addDistortion(const Vec2& p) const
{
const double k1 = _distortionParams[0];
const double k2 = _distortionParams[1];
const double k3 = _distortionParams[2];
const double t1 = _distortionParams[3];
const double t1 = _distortionParams[3];
const double t2 = _distortionParams[4];

double px = p(0);
Expand All @@ -29,21 +29,21 @@ Vec2 DistortionBrown::addDistortion(const Vec2& p) const
const double k_diff = (k1 * r2 + k2 * r4 + k3 * r6);
const double t_x = t2 * (r2 + 2 * px * px) + 2 * t1 * px * py;
const double t_y = t1 * (r2 + 2 * py * py) + 2 * t2 * px * py;

Vec2 result;

result(0) = px + px * k_diff + t_x;
result(1) = py + py * k_diff + t_y;

return result;
return result;
}

Eigen::Matrix2d DistortionBrown::getDerivativeAddDistoWrtPt(const Vec2& p) const
Eigen::Matrix2d DistortionBrown::getDerivativeAddDistoWrtPt(const Vec2& p) const
{
const double k1 = _distortionParams[0];
const double k2 = _distortionParams[1];
const double k3 = _distortionParams[2];
const double t1 = _distortionParams[3];
const double t1 = _distortionParams[3];
const double t2 = _distortionParams[4];

double px = p(0);
Expand All @@ -54,11 +54,10 @@ Eigen::Matrix2d DistortionBrown::getDerivativeAddDistoWrtPt(const Vec2& p) const
const double r6 = r4 * r2;

Eigen::Matrix2d ret;
ret(0, 0) = k1*r2 + k2*r4 + k3*r6 + 2*px*px*(k1 + 2*k2*r2 + 3*k3*r4) + 6*px*t2 + 2*py*t1 + 1;
ret(0, 1) = 2*px*py*(k1 + 2*k2*r2 + 3*k3*r4) + 2*px*t1 + 2*py*t2;
ret(1, 0) = 2*px*py*(k1 + 2*k2*r2 + 3*k3*r4) + 2*px*t1 + 2*py*t2;
ret(1, 1) = k1*r2 + k2*r4 + k3*r6 + 2*px*t2 + 2*py*py*(k1 + 2*k2*r2 + 3*k3*r4) + 6*py*t1 + 1;

ret(0, 0) = k1 * r2 + k2 * r4 + k3 * r6 + 2 * px * px * (k1 + 2 * k2 * r2 + 3 * k3 * r4) + 6 * px * t2 + 2 * py * t1 + 1;
ret(0, 1) = 2 * px * py * (k1 + 2 * k2 * r2 + 3 * k3 * r4) + 2 * px * t1 + 2 * py * t2;
ret(1, 0) = 2 * px * py * (k1 + 2 * k2 * r2 + 3 * k3 * r4) + 2 * px * t1 + 2 * py * t2;
ret(1, 1) = k1 * r2 + k2 * r4 + k3 * r6 + 2 * px * t2 + 2 * py * py * (k1 + 2 * k2 * r2 + 3 * k3 * r4) + 6 * py * t1 + 1;

return ret;
}
Expand All @@ -68,7 +67,7 @@ Eigen::MatrixXd DistortionBrown::getDerivativeAddDistoWrtDisto(const Vec2& p) co
const double k1 = _distortionParams[0];
const double k2 = _distortionParams[1];
const double k3 = _distortionParams[2];
const double t1 = _distortionParams[3];
const double t1 = _distortionParams[3];
const double t2 = _distortionParams[4];

double px = p(0);
Expand All @@ -80,18 +79,17 @@ Eigen::MatrixXd DistortionBrown::getDerivativeAddDistoWrtDisto(const Vec2& p) co

Eigen::Matrix<double, 2, 5> ret = Eigen::Matrix<double, 2, 5>::Zero();

ret(0, 0) = px*r2;
ret(0, 1) = px*r4;
ret(0, 2) = px*r6;
ret(0, 3) = 2*px*py;
ret(0, 4) = 3*px*px + py*py;

ret(0, 0) = px * r2;
ret(0, 1) = px * r4;
ret(0, 2) = px * r6;
ret(0, 3) = 2 * px * py;
ret(0, 4) = 3 * px * px + py * py;

ret(1, 0) = py*r2;
ret(1, 1) = py*r4;
ret(1, 2) = py*r6;
ret(1, 3) = px*px + 3*py*py;
ret(1, 4) = 2*px*py;
ret(1, 0) = py * r2;
ret(1, 1) = py * r4;
ret(1, 2) = py * r6;
ret(1, 3) = px * px + 3 * py * py;
ret(1, 4) = 2 * px * py;

return ret;
}
Expand All @@ -101,20 +99,19 @@ Vec2 DistortionBrown::removeDistortion(const Vec2& p) const
double epsilon = 1e-8;
Vec2 undistorted_value = p;


Vec2 diff = addDistortion(undistorted_value) - p;

int iter = 0;
while (diff.norm() > epsilon)
{
undistorted_value = undistorted_value - getDerivativeAddDistoWrtPt(undistorted_value).inverse() * diff;

diff = addDistortion(undistorted_value) - p;
iter++;
if (iter > 10)
{
break;
}
}
}

return undistorted_value;
Expand Down
18 changes: 8 additions & 10 deletions src/aliceVision/camera/DistortionFisheye1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Vec2 DistortionFisheye1::addDistortion(const Vec2& p) const
{
return p;
}

const double coef = (std::atan(2.0 * r * std::tan(0.5 * k1)) / k1) / r;

return p * coef;
Expand Down Expand Up @@ -48,7 +48,7 @@ Eigen::Matrix2d DistortionFisheye1::getDerivativeAddDistoWrtPt(const Vec2& p) co
double d_part1_d_r = 2.0 * std::tan(0.5 * k1);

double d_coef_d_part2 = 1.0 / part3;
double d_coef_d_part3 = - part2 / (part3 * part3);
double d_coef_d_part3 = -part2 / (part3 * part3);
double d_coef_d_r = d_coef_d_part2 * d_part2_d_part1 * d_part1_d_r + d_coef_d_part3 * d_part3_d_r;
Eigen::Matrix<double, 1, 2> d_coef_d_p = d_coef_d_r * d_r_d_p;

Expand All @@ -72,7 +72,7 @@ Eigen::MatrixXd DistortionFisheye1::getDerivativeAddDistoWrtDisto(const Vec2& p)
{
return p;
}
const double coef = (std::atan(2.0 * r * std::tan(0.5 * k1)) / k1) / r;
return p * coef;
Expand All @@ -88,7 +88,7 @@ Eigen::MatrixXd DistortionFisheye1::getDerivativeAddDistoWrtDisto(const Vec2& p)
double d_part3_d_params = r;
double d_part2_d_part1 = 1.0 / (part1 * part1 + 1.0);
double d_coef_d_part2 = 1.0 / part3;
double d_coef_d_part3 = - part2 / (part3 * part3);
double d_coef_d_part3 = -part2 / (part3 * part3);

double d_coef_d_params = d_coef_d_part3 * d_part3_d_params + d_coef_d_part2 * d_part2_d_part1 * d_part1_d_params;

Expand Down Expand Up @@ -126,7 +126,6 @@ Eigen::Matrix2d DistortionFisheye1::getDerivativeRemoveDistoWrtPt(const Vec2& p)
return Jinv.inverse();
}


Eigen::MatrixXd DistortionFisheye1::getDerivativeRemoveDistoWrtDisto(const Vec2& p) const
{
const double& k1 = _distortionParams.at(0);
Expand All @@ -140,7 +139,6 @@ Eigen::MatrixXd DistortionFisheye1::getDerivativeRemoveDistoWrtDisto(const Vec2&
const Vec2 p_undist = removeDistortion(p);
const double r = sqrt(p_undist(0) * p_undist(0) + p_undist(1) * p_undist(1));


const double part1 = 2.0 * r * std::tan(0.5 * k1);
const double part2 = std::atan(part1);
const double part3 = k1 * r;
Expand All @@ -151,13 +149,13 @@ Eigen::MatrixXd DistortionFisheye1::getDerivativeRemoveDistoWrtDisto(const Vec2&
double d_part3_d_params = r;
double d_part2_d_part1 = 1.0 / (part1 * part1 + 1.0);
double d_coef_d_part2 = (part2 * part2) / part3;
double d_coef_d_part3 = - part2 / (part3 * part3);
double d_coef_d_part3 = -part2 / (part3 * part3);
double d_coef_d_params = d_coef_d_part3 * d_part3_d_params + d_coef_d_part2 * d_part2_d_part1 * d_part1_d_params;

//p'/coef
// p'/coef
Eigen::Matrix<double, 2, 1> ret;
ret(0, 0) = - p(0) * d_coef_d_params / (coef * coef);
ret(1, 0) = - p(1) * d_coef_d_params / (coef * coef);
ret(0, 0) = -p(0) * d_coef_d_params / (coef * coef);
ret(1, 0) = -p(1) * d_coef_d_params / (coef * coef);

return ret;
}
Expand Down
7 changes: 1 addition & 6 deletions src/aliceVision/camera/Equidistant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ Eigen::Matrix<double, 2, 3> Equidistant::getDerivativeProjectWrtDisto(const Eige
Eigen::Matrix4d T = pose;
const Vec4 X = T * pt; // apply pose


/* Compute angle with optical center */
const double len2d = sqrt(X(0) * X(0) + X(1) * X(1));
const double angle_Z = std::atan2(len2d, X(2));
Expand Down Expand Up @@ -481,7 +480,6 @@ EINTRINSIC Equidistant::getType() const
return EINTRINSIC::EQUIDISTANT_CAMERA;
}


double Equidistant::getHorizontalFov() const
{
const double rsensor = std::min(sensorWidth(), sensorHeight());
Expand All @@ -492,10 +490,7 @@ double Equidistant::getHorizontalFov() const
return fov;
}

double Equidistant::getVerticalFov() const
{
return getHorizontalFov();
}
double Equidistant::getVerticalFov() const { return getHorizontalFov(); }

} // namespace camera
} // namespace aliceVision
4 changes: 2 additions & 2 deletions src/aliceVision/camera/Equidistant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ class Equidistant : public IntrinsicScaleOffsetDisto
/**
* @Brief get horizontal fov in radians
* @return horizontal fov in radians
*/
*/
double getHorizontalFov() const override;

/**
* @Brief get vertical fov in radians
* @return vertical fov in radians
*/
*/
double getVerticalFov() const override;

protected:
Expand Down
4 changes: 2 additions & 2 deletions src/aliceVision/camera/Pinhole.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ class Pinhole : public IntrinsicScaleOffsetDisto
/**
* @Brief get horizontal fov in radians
* @return horizontal fov in radians
*/
*/
double getHorizontalFov() const override;

/**
* @Brief get vertical fov in radians
* @return vertical fov in radians
*/
*/
double getVerticalFov() const override;
};

Expand Down
16 changes: 8 additions & 8 deletions src/aliceVision/depthMap/volumeIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ void exportSimilarityVolume(const CudaHostMemoryHeap<TSim, 3>& in_volumeSim_hmh,
if (simValue > maxValue)
continue;
const rgb c = getRGBFromJetColorMap(simValue / maxValue);
pointCloud.getLandmarks()[landmarkId] = sfmData::Landmark(
Vec3(p.x, p.y, p.z), feature::EImageDescriberType::UNKNOWN, image::RGBColor(c.r, c.g, c.b));
pointCloud.getLandmarks()[landmarkId] =
sfmData::Landmark(Vec3(p.x, p.y, p.z), feature::EImageDescriberType::UNKNOWN, image::RGBColor(c.r, c.g, c.b));

++landmarkId;
}
Expand Down Expand Up @@ -234,8 +234,8 @@ void exportSimilarityVolumeCross(const CudaHostMemoryHeap<TSim, 3>& in_volumeSim
continue;

const rgb c = getRGBFromJetColorMap(simValue / maxValue);
pointCloud.getLandmarks()[landmarkId] = sfmData::Landmark(
Vec3(p.x, p.y, p.z), feature::EImageDescriberType::UNKNOWN, image::RGBColor(c.r, c.g, c.b));
pointCloud.getLandmarks()[landmarkId] =
sfmData::Landmark(Vec3(p.x, p.y, p.z), feature::EImageDescriberType::UNKNOWN, image::RGBColor(c.r, c.g, c.b));

++landmarkId;
}
Expand Down Expand Up @@ -292,8 +292,8 @@ void exportSimilarityVolumeCross(const CudaHostMemoryHeap<TSimRefine, 3>& in_vol
const Point3d p = mp.CArr[camIndex] + (mp.iCamArr[camIndex] * pix).normalize() * depth;

const rgb c = getRGBFromJetColorMap(simValue / maxValue);
pointCloud.getLandmarks()[landmarkId] = sfmData::Landmark(
Vec3(p.x, p.y, p.z), feature::EImageDescriberType::UNKNOWN, image::RGBColor(c.r, c.g, c.b));
pointCloud.getLandmarks()[landmarkId] =
sfmData::Landmark(Vec3(p.x, p.y, p.z), feature::EImageDescriberType::UNKNOWN, image::RGBColor(c.r, c.g, c.b));

++landmarkId;
}
Expand Down Expand Up @@ -490,8 +490,8 @@ void exportColorVolume(const CudaHostMemoryHeap<float4, 3>& in_volumeSim_hmh,

float4 colorValue = *get3DBufferAt_h<float4>(in_volumeSim_hmh.getBuffer(), spitch, pitch, vx, vy, vz);
const rgb c = float4_to_rgb(colorValue); // TODO: convert Lab color into sRGB color
pointCloud.getLandmarks()[landmarkId] = sfmData::Landmark(
Vec3(p.x, p.y, p.z), feature::EImageDescriberType::UNKNOWN, image::RGBColor(c.r, c.g, c.b));
pointCloud.getLandmarks()[landmarkId] =
sfmData::Landmark(Vec3(p.x, p.y, p.z), feature::EImageDescriberType::UNKNOWN, image::RGBColor(c.r, c.g, c.b));

++landmarkId;
}
Expand Down
4 changes: 2 additions & 2 deletions src/aliceVision/fuseCut/Fuser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,8 @@ bool checkLandmarkMinObservationAngle(const sfmData::SfMData& sfmData, const sfm
const geometry::Pose3 poseJ = sfmData.getPose(viewJ).getTransform();
const camera::IntrinsicBase* intrinsicPtrJ = sfmData.getIntrinsicPtr(viewJ.getIntrinsicId());

const double angle =
camera::angleBetweenRays(poseI, intrinsicPtrI, poseJ, intrinsicPtrJ, observationPairI.second.getCoordinates(), observationPairJ.second.getCoordinates());
const double angle = camera::angleBetweenRays(
poseI, intrinsicPtrI, poseJ, intrinsicPtrJ, observationPairI.second.getCoordinates(), observationPairJ.second.getCoordinates());

// check angle between two observation
if (angle < minObservationAngle)
Expand Down
11 changes: 5 additions & 6 deletions src/aliceVision/geometry/Intersection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace aliceVision {
namespace geometry {

bool rayIntersectUnitSphere(Vec3 & coordinates, const Vec3 & start, const Vec3 & direction)
bool rayIntersectUnitSphere(Vec3& coordinates, const Vec3& start, const Vec3& direction)
{
/*
"Which point on the sphere relates to this point ?"
Expand All @@ -22,16 +22,16 @@ bool rayIntersectUnitSphere(Vec3 & coordinates, const Vec3 & start, const Vec3 &
+ (lambda * directionz)^2 + startz^2 + 2.0 * lambda * directionoriginz * directionz
= 1
(lambda^2) * (directionx^2 + directiony^2 + directionz^2)
+ lambda * (2.0 * directionoriginx * directionx + 2.0 * directionoriginy * directiony + 2.0 * directionoriginz * directionz)
(lambda^2) * (directionx^2 + directiony^2 + directionz^2)
+ lambda * (2.0 * directionoriginx * directionx + 2.0 * directionoriginy * directiony + 2.0 * directionoriginz * directionz)
+ (startx^2 + startx^2 + startx^2) - 1 = 0
*/

double a = direction.dot(direction);
double b = direction.dot(start) * 2.0;
double c = start.dot(start) - 1.0;
double det = b*b - 4.0*a*c;
double det = b * b - 4.0 * a * c;

if (det < 0)
{
return false;
Expand All @@ -48,4 +48,3 @@ bool rayIntersectUnitSphere(Vec3 & coordinates, const Vec3 & start, const Vec3 &

} // namespace geometry
} // namespace aliceVision

5 changes: 2 additions & 3 deletions src/aliceVision/geometry/Intersection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ namespace geometry {
* @param start the starting point of the ray
* @param direction the direction of the ray
* @return true if an intersection is found
*/
bool rayIntersectUnitSphere(Vec3 & coordinates, const Vec3 & start, const Vec3 & direction);
*/
bool rayIntersectUnitSphere(Vec3& coordinates, const Vec3& start, const Vec3& direction);

} // namespace geometry
} // namespace aliceVision

1 change: 0 additions & 1 deletion src/aliceVision/image/dcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <aliceVision/system/Logger.hpp>
#include <aliceVision/stl/mapUtils.hpp>


#include <boost/algorithm/string.hpp>
#include <boost/foreach.hpp>

Expand Down
6 changes: 3 additions & 3 deletions src/aliceVision/image/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ void writeImage(const std::string& path,
{
const fs::path bPath = fs::path(path);
const std::string extension = boost::to_lower_copy(bPath.extension().string());
const std::string tmpPath = (bPath.parent_path() / bPath.stem()).string() + "." + utils::generateUniqueFilename() + extension;
const std::string tmpPath = (bPath.parent_path() / bPath.stem()).string() + "." + utils::generateUniqueFilename() + extension;
const bool isEXR = (extension == ".exr");
// const bool isTIF = (extension == ".tif");
const bool isJPG = (extension == ".jpg");
Expand Down Expand Up @@ -1185,9 +1185,9 @@ void writeImageNoFloat(const std::string& path,
{
const fs::path bPath = fs::path(path);
const std::string extension = boost::to_lower_copy(bPath.extension().string());
const std::string tmpPath = (bPath.parent_path() / bPath.stem()).string() + "." + utils::generateUniqueFilename() + extension;
const std::string tmpPath = (bPath.parent_path() / bPath.stem()).string() + "." + utils::generateUniqueFilename() + extension;
const bool isEXR = (extension == ".exr");
//const bool isTIF = (extension == ".tif");
// const bool isTIF = (extension == ".tif");
const bool isJPG = (extension == ".jpg");
const bool isPNG = (extension == ".png");

Expand Down
Loading

0 comments on commit 064ff12

Please sign in to comment.