8000 Fix unnecessary copies in for range loops by ahojnnes · Pull Request #1162 · colmap/colmap · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix unnecessary copies in for range loops #1162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/base/correspondence_graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ CorrespondenceGraph::FindTransitiveCorrespondences(
const std::vector<Correspondence>& ref_corrs =
image.corrs[ref_corr.point2D_idx];

for (const Correspondence corr : ref_corrs) {
for (const Correspondence& corr : ref_corrs) {
// Check if correspondence already collected, otherwise collect.
auto& corr_image_corrs = image_corrs[corr.image_id];
if (corr_image_corrs.count(corr.point2D_idx) == 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/base/reconstruction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,7 @@ bool Reconstruction::ExtractColorsForImage(const image_t image_id,
}

const Eigen::Vector3ub kBlackColor(0, 0, 0);
for (const Point2D point2D : image.Points2D()) {
for (const Point2D& point2D : image.Points2D()) {
if (point2D.HasPoint3D()) {
class Point3D& point3D = Point3D(point2D.Point3DId());
if (point3D.Color() == kBlackColor) {
Expand Down Expand Up @@ -1391,7 +1391,7 @@ void Reconstruction::ExtractColorsForAllImages(const std::string& path) {
continue;
}

for (const Point2D point2D : image.Points2D()) {
for (const Point2D& point2D : image.Points2D()) {
if (point2D.HasPoint3D()) {
BitmapColor<float> color;
// COLMAP assumes that the upper left pixel center is (0.5, 0.5).
Expand Down
2 changes: 1 addition & 1 deletion src/base/undistortion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ void PMVSUndistorter::WriteVisibilityData() const {
const Point2D& point2D = image.Point2D(point2D_idx);
if (point2D.HasPoint3D()) {
const Point3D& point3D = reconstruction_.Point3D(point2D.Point3DId());
for (const TrackElement track_el : point3D.Track().Elements()) {
for (const TrackElement& track_el : point3D.Track().Elements()) {
if (track_el.image_id != image_id) {
visible_image_ids.insert(track_el.image_id);
}
Expand Down
4 changes: 2 additions & 2 deletions src/estimators/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ void CenterAndNormalizeImagePoints(const std::vector<Eigen::Vector2d>& points,
Eigen::Matrix3d* matrix) {
// Calculate centroid
Eigen::Vector2d centroid(0, 0);
for (const auto point : points) {
for (const Eigen::Vector2d& point : points) {
centroid += point;
}
centroid /= points.size();

// Root mean square error to centroid of all points
double rms_mean_dist = 0;
for (const auto point : points) {
for (const Eigen::Vector2d& point : points) {
rms_mean_dist += (point - centroid).squaredNorm();
}
rms_mean_dist = std::sqrt(rms_mean_dist / points.size());
Expand Down
4 changes: 2 additions & 2 deletions src/exe/image.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ int RunImageDeleter(int argc, char** argv) {
if (!image_ids_path.empty()) {
const auto image_ids = ReadTextFileLines(image_ids_path);

for (const auto image_id_str : image_ids) {
for (const auto& image_id_str : image_ids) {
if (image_id_str.empty()) {
continue;
}
Expand All @@ -124,7 +124,7 @@ int RunImageDeleter(int argc, char** argv) {
if (!image_names_path.empty()) {
const auto image_names = ReadTextFileLines(image_names_path);

for (const auto image_name : image_names) {
for (const auto& image_name : image_names) {
if (image_name.empty()) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/exe/model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ int RunModelAligner(int argc, char** argv) {
std::vector<std::string> ref_image_names;
std::vector<Eigen::Vector3d> ref_locations;
std::vector<std::string> lines = ReadTextFileLines(ref_images_path);
for (const auto line : lines) {
for (const auto& line : lines) {
std::stringstream line_parser(line);
std::string image_name = "";
Eigen::Vector3d camera_position;
Expand Down
0