Skip to content

Commit

Permalink
Fix shadowed variable in mapillary/opensfm/opensfm/src/geometry/src/c…
Browse files Browse the repository at this point in the history
…amera.cc

Summary:
Our upcoming compiler upgrade will require us not to have shadowed variables. Such variables have a _high_ bug rate and reduce readability, so we would like to avoid them even if the compiler was not forcing us to do so.

This codemod attempts to fix an instance of a shadowed variable. Please review with care: if it's failed the result will be a silent bug.

**What's a shadowed variable?**

Shadowed variables are variables in an inner scope with the same name as another variable in an outer scope. Having the same name for both variables might be semantically correct, but it can make the code confusing to read! It can also hide subtle bugs.

This diff fixes such an issue by renaming the variable.

 - If you approve of this diff, please use the "Accept & Ship" button :-)

Reviewed By: dmm-fb

Differential Revision: D59008872

fbshipit-source-id: bd67d6396265aefb077ab37ae343e67c31a16408
  • Loading branch information
r-barnes authored and facebook-github-bot committed Jun 26, 2024
1 parent c9d7d98 commit 7b531ae
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
8 changes: 4 additions & 4 deletions opensfm/src/geometry/src/camera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,15 @@ Mat3d Camera::GetProjectionMatrix() const {
return unnormalized;
}

Mat3d Camera::GetProjectionMatrixScaled(int width, int height) const {
const auto unnormalizer = std::max(width, height);
Mat3d Camera::GetProjectionMatrixScaled(int width_2, int height_2) const {
const auto unnormalizer = std::max(width_2, height_2);
Mat3d unnormalized = Mat3d::Zero();

const auto projection_matrix = GetProjectionMatrix();
unnormalized.block<2, 2>(0, 0)
<< unnormalizer * projection_matrix.block<2, 2>(0, 0);
unnormalized.col(2) << projection_matrix(0, 2) * unnormalizer + 0.5 * width,
projection_matrix(1, 2) * unnormalizer + 0.5 * height, 1.0;
unnormalized.col(2) << projection_matrix(0, 2) * unnormalizer + 0.5 * width_2,
projection_matrix(1, 2) * unnormalizer + 0.5 * height_2, 1.0;
return unnormalized;
}

Expand Down
22 changes: 11 additions & 11 deletions opensfm/src/third_party/akaze/lib/AKAZE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,17 +374,17 @@ void AKAZE::Find_Scale_Space_Extrema(std::vector<cv::KeyPoint>& kpts) {
for (size_t i = 0; i < kpts_aux.size(); i++) {

is_repeated = false;
const cv::KeyPoint& point = kpts_aux[i];
const cv::KeyPoint& point_2 = kpts_aux[i];
for (size_t j = i+1; j < kpts_aux.size(); j++) {

// Compare response with the upper scale
if ((point.class_id+1) == kpts_aux[j].class_id) {
if ((point_2.class_id+1) == kpts_aux[j].class_id) {

dist = (point.pt.x-kpts_aux[j].pt.x)*(point.pt.x-kpts_aux[j].pt.x) +
(point.pt.y-kpts_aux[j].pt.y)*(point.pt.y-kpts_aux[j].pt.y);
dist = (point_2.pt.x-kpts_aux[j].pt.x)*(point_2.pt.x-kpts_aux[j].pt.x) +
(point_2.pt.y-kpts_aux[j].pt.y)*(point_2.pt.y-kpts_aux[j].pt.y);

if (dist <= point.size*point.size) {
if (point.response < kpts_aux[j].response) {
if (dist <= point_2.size*point_2.size) {
if (point_2.response < kpts_aux[j].response) {
is_repeated = true;
break;
}
Expand All @@ -393,7 +393,7 @@ void AKAZE::Find_Scale_Space_Extrema(std::vector<cv::KeyPoint>& kpts) {
}

if (is_repeated == false) {
kpts.push_back(point);
kpts.push_back(point_2);
}
}

Expand Down Expand Up @@ -959,8 +959,8 @@ void AKAZE::Get_MSURF_Upright_Descriptor_64(const cv::KeyPoint& kpt, float *desc
// convert to unit vector
len = sqrt(len);

for (int i = 0; i < dsize; i++) {
desc[i] /= len;
for (int i_2 = 0; i_2 < dsize; i_2++) {
desc[i_2] /= len;
}
}

Expand Down Expand Up @@ -1075,8 +1075,8 @@ void AKAZE::Get_MSURF_Descriptor_64(const cv::KeyPoint& kpt, float *desc) const
// convert to unit vector
len = sqrt(len);

for (int i = 0; i < dsize; i++) {
desc[i] /= len;
for (int i_2 = 0; i_2 < dsize; i_2++) {
desc[i_2] /= len;
}
}

Expand Down
32 changes: 16 additions & 16 deletions opensfm/src/third_party/akaze/lib/nldiffusion_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,11 @@ void nld_step_scalar(cv::Mat& Ld, const cv::Mat& c, cv::Mat& Lstep, const float
Ld_row_p = Ld.ptr<float>(Lstep.rows-2);
Lstep_row = Lstep.ptr<float>(Lstep.rows-1);

for (int x = 1; x < Lstep.cols-1; x++) {
float xpos = (c_row[x]+c_row[x+1])*(Ld_row[x+1]-Ld_row[x]);
float xneg = (c_row[x-1]+c_row[x])*(Ld_row[x]-Ld_row[x-1]);
float ypos = (c_row[x]+c_row_p[x])*(Ld_row_p[x]-Ld_row[x]);
Lstep_row[x] = 0.5*stepsize*(xpos-xneg + ypos);
for (int x_2 = 1; x_2 < Lstep.cols-1; x_2++) {
float xpos_2 = (c_row[x_2]+c_row[x_2+1])*(Ld_row[x_2+1]-Ld_row[x_2]);
float xneg_2 = (c_row[x_2-1]+c_row[x_2])*(Ld_row[x_2]-Ld_row[x_2-1]);
float ypos_2 = (c_row[x_2]+c_row_p[x_2])*(Ld_row_p[x_2]-Ld_row[x_2]);
Lstep_row[x_2] = 0.5*stepsize*(xpos_2-xneg_2 + ypos_2);
}

xpos = (c_row[0]+c_row[1])*(Ld_row[1]-Ld_row[0]);
Expand All @@ -290,22 +290,22 @@ void nld_step_scalar(cv::Mat& Ld, const cv::Mat& c, cv::Mat& Lstep, const float
// First and last columns
for (int i = 1; i < Lstep.rows-1; i++) {

const float* c_row = c.ptr<float>(i);
const float* c_row_2 = c.ptr<float>(i);
const float* c_row_m = c.ptr<float>(i-1);
const float* c_row_p = c.ptr<float>(i+1);
float* Ld_row = Ld.ptr<float>(i);
float* Ld_row_p = Ld.ptr<float>(i+1);
const float* c_row_p_2 = c.ptr<float>(i+1);
float* Ld_row_2 = Ld.ptr<float>(i);
float* Ld_row_p_2 = Ld.ptr<float>(i+1);
float* Ld_row_m = Ld.ptr<float>(i-1);
Lstep_row = Lstep.ptr<float>(i);

float xpos = (c_row[0]+c_row[1])*(Ld_row[1]-Ld_row[0]);
float ypos = (c_row[0]+c_row_p[0])*(Ld_row_p[0]-Ld_row[0]);
float yneg = (c_row_m[0]+c_row[0])*(Ld_row[0]-Ld_row_m[0]);
Lstep_row[0] = 0.5*stepsize*(xpos+ypos-yneg);
float xpos_2 = (c_row_2[0]+c_row_2[1])*(Ld_row_2[1]-Ld_row_2[0]);
float ypos = (c_row_2[0]+c_row_p_2[0])*(Ld_row_p_2[0]-Ld_row_2[0]);
float yneg = (c_row_m[0]+c_row_2[0])*(Ld_row_2[0]-Ld_row_m[0]);
Lstep_row[0] = 0.5*stepsize*(xpos_2+ypos-yneg);

float xneg = (c_row[Lstep.cols-2]+c_row[Lstep.cols-1])*(Ld_row[Lstep.cols-1]-Ld_row[Lstep.cols-2]);
ypos = (c_row[Lstep.cols-1]+c_row_p[Lstep.cols-1])*(Ld_row_p[Lstep.cols-1]-Ld_row[Lstep.cols-1]);
yneg = (c_row_m[Lstep.cols-1]+c_row[Lstep.cols-1])*(Ld_row[Lstep.cols-1]-Ld_row_m[Lstep.cols-1]);
float xneg = (c_row_2[Lstep.cols-2]+c_row_2[Lstep.cols-1])*(Ld_row_2[Lstep.cols-1]-Ld_row_2[Lstep.cols-2]);
ypos = (c_row_2[Lstep.cols-1]+c_row_p_2[Lstep.cols-1])*(Ld_row_p_2[Lstep.cols-1]-Ld_row_2[Lstep.cols-1]);
yneg = (c_row_m[Lstep.cols-1]+c_row_2[Lstep.cols-1])*(Ld_row_2[Lstep.cols-1]-Ld_row_m[Lstep.cols-1]);
Lstep_row[Lstep.cols-1] = 0.5*stepsize*(-xneg+ypos-yneg);
}

Expand Down

0 comments on commit 7b531ae

Please sign in to comment.