8000 Avoid const params in declarations by ahojnnes · Pull Request #2011 · colmap/colmap · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Avoid const params in declarations #2011

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 8 commits into from
Jul 8, 2023
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
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Checks: >
cppcoreguidelines-virtual-class-destructor,
google-explicit-constructor,
google-build-using-namespace,
readability-avoid-const-params-in-decls,
WarningsAsErrors: '*'
FormatStyle: 'file'
User: 'user'
50 changes: 25 additions & 25 deletions src/colmap/base/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,39 +47,39 @@ class Camera {

// Access the unique identifier of the camera.
inline camera_t CameraId() const;
inline void SetCameraId(const camera_t camera_id);
inline void SetCameraId(camera_t camera_id);

// Access the camera model.
inline int ModelId() const;
std::string ModelName() const;
void SetModelId(const int model_id);
void SetModelId(int model_id);
void SetModelIdFromName(const std::string& model_name);

// Access dimensions of the camera sensor.
inline size_t Width() const;
inline size_t Height() const;
inline void SetWidth(const size_t width);
inline void SetHeight(const size_t height);
inline void SetWidth(size_t width);
inline void SetHeight(size_t height);

// Access focal length parameters.
double MeanFocalLength() const;
double FocalLength() const;
double FocalLengthX() const;
double FocalLengthY() const;
void SetFocalLength(const double focal_length);
void SetFocalLengthX(const double focal_length_x);
void SetFocalLengthY(const double focal_length_y);
void SetFocalLength(double focal_length);
void SetFocalLengthX(double focal_length_x);
void SetFocalLengthY(double focal_length_y);

// Check if camera has prior focal length.
inline bool HasPriorFocalLength() const;
inline void SetPriorFocalLength(const bool prior);
inline void SetPriorFocalLength(bool prior);

// Access principal point parameters. Only works if there are two
// principal point parameters.
double PrincipalPointX() const;
double PrincipalPointY() const;
void SetPrincipalPointX(const double ppx);
void SetPrincipalPointY(const double ppy);
void SetPrincipalPointX(double ppx);
void SetPrincipalPointY(double ppy);

// Get the indices of the parameter groups in the parameter vector.
const std::vector<size_t>& FocalLengthIdxs() const;
Expand All @@ -97,8 +97,8 @@ class Camera {
inline size_t NumParams() const;
inline const std::vector<double>& Params() const;
inline std::vector<double>& Params();
inline double Params(const size_t idx) const;
inline double& Params(const size_t idx);
inline double Params(size_t idx) const;
inline double& Params(size_t idx);
inline const double* ParamsData() const;
inline double* ParamsData();
inline void SetParams(const std::vector<double>& params);
Expand All @@ -117,34 +117,34 @@ class Camera {
bool IsUndistorted() const;

// Check whether camera has bogus parameters.
bool HasBogusParams(const double min_focal_length_ratio,
const double max_focal_length_ratio,
const double max_extra_param) const;
bool HasBogusParams(double min_focal_length_ratio,
double max_focal_length_ratio,
double max_extra_param) const;

// Initialize parameters for given camera model and focal length, and set
// the principal point to be the image center.
void InitializeWithId(const int model_id,
const double focal_length,
const size_t width,
const size_t height);
void InitializeWithId(int model_id,
double focal_length,
size_t width,
size_t height);
void InitializeWithName(const std::string& model_name,
const double focal_length,
const size_t width,
const size_t height);
double focal_length,
size_t width,
size_t height);

// Project point in image plane to world / infinity.
Eigen::Vector2d ImageToWorld(const Eigen::Vector2d& image_point) const;

// Convert pixel threshold in image plane to world space.
double ImageToWorldThreshold(const double threshold) const;
double ImageToWorldThreshold(double threshold) const;

// Project point from world / infinity to image plane.
Eigen::Vector2d WorldToImage(const Eigen::Vector2d& world_point) const;

// Rescale camera dimensions and accordingly the focal length and
// and the principal point.
void Rescale(const double scale);
void Rescale(const size_t width, const size_t height);
void Rescale(double scale);
void Rescale(size_t width, size_t height);

private:
// The unique identifier of the camera. If the identifier is not specified
Expand Down
16 changes: 8 additions & 8 deletions src/colmap/base/camera_rig.h
10000
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ class CameraRig {
size_t NumSnapshots() const;

// Check whether the given camera is part of the rig.
bool HasCamera(const camera_t camera_id) const;
bool HasCamera(camera_t camera_id) const;

// Access the reference camera.
camera_t RefCameraId() const;
void SetRefCameraId(const camera_t camera_id);
void SetRefCameraId(camera_t camera_id);

// Get the identifiers of the cameras in the rig.
std::vector<camera_t> GetCameraIds() const;
Expand All @@ -71,7 +71,7 @@ class CameraRig {
// Add a new camera to the rig. The relative pose may contain dummy values and
// can then be computed automatically from a given reconstruction using the
// method `ComputeRelativePoses`.
void AddCamera(const camera_t camera_id,
void AddCamera(camera_t camera_id,
const Eigen::Vector4d& rel_qvec,
const Eigen::Vector3d& rel_tvec);

Expand All @@ -85,10 +85,10 @@ class CameraRig {
void Check(const Reconstruction& reconstruction) const;

// Get the relative poses of the cameras in the rig.
Eigen::Vector4d& RelativeQvec(const camera_t camera_id);
const Eigen::Vector4d& RelativeQvec(const camera_t camera_id) const;
Eigen::Vector3d& RelativeTvec(const camera_t camera_id);
const Eigen::Vector3d& RelativeTvec(const camera_t camera_id) const;
Eigen::Vector4d& RelativeQvec(camera_t camera_id);
const Eigen::Vector4d& RelativeQvec(camera_t camera_id) const;
Eigen::Vector3d& RelativeTvec(camera_t camera_id);
const Eigen::Vector3d& RelativeTvec(camera_t camera_id) const;

// Compute the scaling factor from the reconstruction to the camera rig
// dimensions by averaging over the distances between the projection centers.
Expand All @@ -105,7 +105,7 @@ class CameraRig {
// Compute the absolute camera pose of the rig. The absolute camera pose of
// the rig is computed as the average of all relative camera poses in the rig
// and their corresponding image poses in the reconstruction.
void ComputeAbsolutePose(const size_t snapshot_idx,
void ComputeAbsolutePose(size_t snapshot_idx,
const Reconstruction& reconstruction,
Eigen::Vector4d* abs_qvec,
Eigen::Vector3d* abs_tvec) const;
Expand Down
34 changes: 16 additions & 18 deletions src/colmap/base/correspondence_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,18 @@ class CorrespondenceGraph {
inline size_t NumImagePairs() const;

// Check whether image exists.
inline bool ExistsImage(const image_t image_id) const;
inline bool ExistsImage(image_t image_id) const;

// Get the number of observations in an image. An observation is an image
// point that has at least one correspondence.
inline point2D_t NumObservationsForImage(const image_t image_id) const;
inline point2D_t NumObservationsForImage(image_t image_id) const;

// Get the number of correspondences per image.
inline point2D_t NumCorrespondencesForImage(const image_t image_id) const;
inline point2D_t NumCorrespondencesForImage(image_t image_id) const;

// Get the number of correspondences between a pair of images.
inline point2D_t NumCorrespondencesBetweenImages(
const image_t image_id1, const image_t image_id2) const;
inline point2D_t NumCorrespondencesBetweenImages(image_t image_id1,
image_t image_id2) const;

// Get the number of correspondences between all images.
std::unordered_map<image_pair_t, point2D_t> NumCorrespondencesBetweenImages()
Expand All @@ -91,19 +91,19 @@ class CorrespondenceGraph {
void Finalize();

// Add new image to the correspondence graph.
void AddImage(const image_t image_id, const size_t num_points2D);
void AddImage(image_t image_id, size_t num_points2D);

// Add correspondences between images. This function ignores invalid
// correspondences where the point indices are out of bounds or duplicate
// correspondences between the same image points. Whenever either of the two
// cases occur this function prints a warning to the standard output.
void AddCorrespondences(const image_t image_id1,
const image_t image_id2,
void AddCorrespondences(image_t image_id1,
image_t image_id2,
const FeatureMatches& matches);

// Find the correspondence of an image observation to all other images.
inline const std::vector<Correspondence>& FindCorrespondences(
const image_t image_id, const point2D_t point2D_idx) const;
image_t image_id, point2D_t point2D_idx) const;

// Find correspondences to the given observation.
//
Expand All @@ -114,24 +114,22 @@ class CorrespondenceGraph {
// found. The returned list does not contain duplicates and contains
// the given observation.
void FindTransitiveCorrespondences(
const image_t image_id,
const point2D_t point2D_idx,
const size_t transitivity,
image_t image_id,
point2D_t point2D_idx,
size_t transitivity,
std::vector<Correspondence>* found_corrs) const;

// Find all correspondences between two images.
FeatureMatches FindCorrespondencesBetweenImages(
const image_t image_id1, const image_t image_id2) const;
FeatureMatches FindCorrespondencesBetweenImages(image_t image_id1,
image_t image_id2) const;

// Check whether the image point has correspondences.
inline bool HasCorrespondences(const image_t image_id,
const point2D_t point2D_idx) const;
inline bool HasCorrespondences(image_t image_id, point2D_t point2D_idx) const;

// Check whether the given observation is part of a two-view track, i.e.
// it only has one correspondence and that correspondence has the given
// observation as its only correspondence.
bool IsTwoViewObservation(const image_t image_id,
const point2D_t point2D_idx) const;
bool IsTwoViewObservation(image_t image_id, point2D_t point2D_idx) const;

private:
struct Image {
Expand Down
68 changes: 31 additions & 37 deletions src/colmap/base/database.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,13 @@ class Database {

// Check if entry already exists in database. For image pairs, the order of
// `image_id1` and `image_id2` does not matter.
bool ExistsCamera(const camera_t camera_id) const;
bool ExistsImage(const image_t image_id) const;
bool ExistsCamera(camera_t camera_id) const;
bool ExistsImage(image_t image_id) const;
bool ExistsImageWithName(const std::string& name) const;
bool ExistsKeypoints(const image_t image_id) const;
bool ExistsDescriptors(const image_t image_id) const;
bool ExistsMatches(const image_t image_id1, const image_t image_id2) const;
bool ExistsInlierMatches(const image_t image_id1,
const image_t image_id2) const;
bool ExistsKeypoints(image_t image_id) const;
bool ExistsDescriptors(image_t image_id) const;
bool ExistsMatches(image_t image_id1, image_t image_id2) const;
F438 bool ExistsInlierMatches(image_t image_id1, image_t image_id2) const;

// Number of rows in `cameras` table.
size_t NumCameras() const;
Expand All @@ -94,7 +93,7 @@ class Database {
size_t MaxNumKeypoints() const;

// Number of descriptors for specific image.
size_t NumKeypointsForImage(const image_t image_id) const;
size_t NumKeypointsForImage(image_t image_id) const;

// Sum of `rows` column in `descriptors` table,
// i.e. number of total descriptors.
Expand All @@ -104,7 +103,7 @@ class Database {
size_t MaxNumDescriptors() const;

// Number of descriptors for specific image.
size_t NumDescriptorsForImage(const image_t image_id) const;
size_t NumDescriptorsForImage(image_t image_id) const;

// Sum of `rows` column in `matches` table, i.e. number of total matches.
size_t NumMatches() const;
Expand All @@ -123,38 +122,36 @@ class Database {
// `two_view_geometries` table. We intentionally avoid to store the pairs in a
// separate table by using e.g. AUTOINCREMENT, since the overhead of querying
// the unique pair ID is significant.
inline static image_pair_t ImagePairToPairId(const image_t image_id1,
const image_t image_id2);
inline static image_pair_t ImagePairToPairId(image_t image_id1,
image_t image_id2);

inline static void PairIdToImagePair(const image_pair_t pair_id,
inline static void PairIdToImagePair(image_pair_t pair_id,
image_t* image_id1,
image_t* image_id2);

// Return true if image pairs should be swapped. Used to enforce a specific
// image order to generate unique image pair identifiers independent of the
// order in which the image identifiers are used.
inline static bool SwapImagePair(const image_t image_id1,
const image_t image_id2);
inline static bool SwapImagePair(image_t image_id1, image_t image_id2);

// Read an existing entry in the database. The user is responsible for making
// sure that the entry actually exists. For image pairs, the order of
// `image_id1` and `image_id2` does not matter.
Camera ReadCamera(const camera_t camera_id) const;
Camera ReadCamera(camera_t camera_id) const;
std::vector<Camera> ReadAllCameras() const;

Image ReadImage(const image_t image_id) const;
Image ReadImage(image_t image_id) const;
Image ReadImageWithName(const std::string& name) const;
std::vector<Image> ReadAllImages() const;

FeatureKeypoints ReadKeypoints(const image_t image_id) const;
FeatureDescriptors ReadDescriptors(const image_t image_id) const;
FeatureKeypoints ReadKeypoints(image_t image_id) const;
FeatureDescriptors ReadDescriptors(image_t image_id) const;

FeatureMatches ReadMatches(const image_t image_id1,
const image_t image_id2) const;
FeatureMatches ReadMatches(image_t image_id1, image_t image_id2) const;
std::vector<std::pair<image_pair_t, FeatureMatches>> ReadAllMatches() const;

TwoViewGeometry ReadTwoViewGeometry(const image_t image_id1,
const image_t image_id2) const;
TwoViewGeometry ReadTwoViewGeometry(image_t image_id1,
image_t image_id2) const;
void ReadTwoViewGeometries(
std::vector<image_pair_t>* image_pair_ids,
std::vector<TwoViewGeometry>* two_view_geometries) const;
Expand All @@ -167,25 +164,24 @@ class Database {

// Add new camera and return its database identifier. If `use_camera_id`
// is false a new identifier is automatically generated.
camera_t WriteCamera(const Camera& camera,
const bool use_camera_id = false) const;
camera_t WriteCamera(const Camera& camera, bool use_camera_id = false) const;

// Add new image and return its database identifier. If `use_image_id`
// is false a new identifier is automatically generated.
image_t WriteImage(const Image& image, const bool use_image_id = false) const;
image_t WriteImage(const Image& image, bool use_image_id = false) const;

// Write a new entry in the database. The user is responsible for making sure
// that the entry does not yet exist. For image pairs, the order of
// `image_id1` and `image_id2` does not matter.
void WriteKeypoints(const image_t image_id,
void WriteKeypoints(image_t image_id,
const FeatureKeypoints& keypoints) const;
void WriteDescriptors(const image_t image_id,
void WriteDescriptors(image_t image_id,
const FeatureDescriptors& descriptors) const;
void WriteMatches(const image_t image_id1,
const image_t image_id2,
void WriteMatches(image_t image_id1,
image_t image_id2,
const FeatureMatches& matches) const;
void WriteTwoViewGeometry(const image_t image_id1,
const image_t image_id2,
void WriteTwoViewGeometry(image_t image_id1,
image_t image_id2,
const TwoViewGeometry& two_view_geometry) const;

// Update an existing camera in the database. The user is responsible for
Expand All @@ -197,11 +193,10 @@ class Database {
void UpdateImage(const Image& image) const;

// Delete matches of an image pair.
void DeleteMatches(const image_t image_id1, const image_t image_id2) const;
void DeleteMatches(image_t image_id1, image_t image_id2) const;

// Delete inlier matches of an image pair.
void DeleteInlierMatches(const image_t image_id1,
const image_t image_id2) const;
void DeleteInlierMatches(image_t image_id1, image_t image_id2) const;

// Clear all database tables
void ClearAllTables() const;
Expand Down Expand Up @@ -260,13 +255,12 @@ class Database {
bool ExistsColumn(const std::string& table_name,
const std::string& column_name) const;

bool ExistsRowId(sqlite3_stmt* sql_stmt, const sqlite3_int64 row_id) const;
bool ExistsRowId(sqlite3_stmt* sql_stmt, sqlite3_int64 row_id) const;
bool ExistsRowString(sqlite3_stmt* sql_stmt,
const std::string& row_entry) const;

size_t CountRows(const std::string& table) const;
size_t CountRowsForEntry(sqlite3_stmt* sql_stmt,
const sqlite3_int64 row_id) const;
size_t CountRowsForEntry(sqlite3_stmt* sql_stmt, sqlite3_int64 row_id) const;
size_t SumColumn(const std::string& column, const std::string& table) const;
size_t MaxColumn(const std::string& column, const std::string& table) const;

Expand Down
Loading
0