Skip to content

Commit

Permalink
Fix clang-tidy errors (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
sarlinpe authored Jan 12, 2024
1 parent 177b66b commit 6b658f9
Show file tree
Hide file tree
Showing 24 changed files with 136 additions and 131 deletions.
8 changes: 4 additions & 4 deletions pycolmap/estimators/absolute_pose.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ using namespace pybind11::literals;
namespace py = pybind11;

py::object PyEstimateAndRefineAbsolutePose(
const std::vector<Eigen::Vector2d> points2D,
const std::vector<Eigen::Vector3d> points3D,
const std::vector<Eigen::Vector2d>& points2D,
const std::vector<Eigen::Vector3d>& points3D,
Camera& camera,
const AbsolutePoseEstimationOptions estimation_options,
const AbsolutePoseRefinementOptions refinement_options,
const AbsolutePoseEstimationOptions& estimation_options,
const AbsolutePoseRefinementOptions& refinement_options,
const bool return_covariance) {
SetPRNGSeed(0);
THROW_CHECK_EQ(points2D.size(), points3D.size());
Expand Down
6 changes: 3 additions & 3 deletions pycolmap/estimators/essential_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ using namespace pybind11::literals;
namespace py = pybind11;

py::object PyEstimateAndDecomposeEssentialMatrix(
const std::vector<Eigen::Vector2d> points2D1,
const std::vector<Eigen::Vector2d> points2D2,
const std::vector<Eigen::Vector2d>& points2D1,
const std::vector<Eigen::Vector2d>& points2D2,
Camera& camera1,
Camera& camera2,
const RANSACOptions options) {
const RANSACOptions& options) {
SetPRNGSeed(0);
THROW_CHECK_EQ(points2D1.size(), points2D2.size());
py::object failure = py::none();
Expand Down
6 changes: 3 additions & 3 deletions pycolmap/estimators/fundamental_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ using namespace pybind11::literals;
namespace py = pybind11;

py::object PyEstimateFundamentalMatrix(
const std::vector<Eigen::Vector2d> points2D1,
const std::vector<Eigen::Vector2d> points2D2,
const RANSACOptions options) {
const std::vector<Eigen::Vector2d>& points2D1,
const std::vector<Eigen::Vector2d>& points2D2,
const RANSACOptions& options) {
SetPRNGSeed(0);
THROW_CHECK_EQ(points2D1.size(), points2D2.size());
py::object failure = py::none();
Expand Down
4 changes: 2 additions & 2 deletions pycolmap/estimators/generalized_absolute_pose.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ py::object PyEstimateAndRefineGeneralizedAbsolutePose(
const std::vector<size_t>& camera_idxs,
const std::vector<Rigid3d>& cams_from_rig,
std::vector<Camera>& cameras,
RANSACOptions ransac_options,
AbsolutePoseRefinementOptions refinement_options,
const RANSACOptions& ransac_options,
const AbsolutePoseRefinementOptions& refinement_options,
const bool return_covariance) {
SetPRNGSeed(0);
THROW_CHECK_EQ(points2D.size(), points3D.size());
Expand Down
6 changes: 3 additions & 3 deletions pycolmap/estimators/homography_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ using namespace pybind11::literals;
namespace py = pybind11;

py::object PyEstimateHomographyMatrix(
const std::vector<Eigen::Vector2d> points2D1,
const std::vector<Eigen::Vector2d> points2D2,
const RANSACOptions options) {
const std::vector<Eigen::Vector2d>& points2D1,
const std::vector<Eigen::Vector2d>& points2D2,
const RANSACOptions& options) {
SetPRNGSeed(0);
THROW_CHECK_EQ(points2D1.size(), points2D2.size());
py::object failure = py::none();
Expand Down
16 changes: 8 additions & 8 deletions pycolmap/feature/sift.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ static std::map<int, std::unique_ptr<std::mutex>> sift_gpu_mutexes;
class Sift {
public:
Sift(SiftExtractionOptions options, Device device)
: options_(options), use_gpu_(IsGPU(device)) {
: options_(std::move(options)), use_gpu_(IsGPU(device)) {
VerifyGPUParams(use_gpu_);
options_.use_gpu = use_gpu_;
extractor_ = CreateSiftFeatureExtractor(options_);
THROW_CHECK(extractor_ != nullptr);
}

sift_output_t Extract(Eigen::Ref<const pyimage_t<uint8_t>> image) {
sift_output_t Extract(const Eigen::Ref<const pyimage_t<uint8_t>>& image) {
THROW_CHECK_LE(image.rows(), options_.max_image_size);
THROW_CHECK_LE(image.cols(), options_.max_image_size);

Expand Down Expand Up @@ -79,7 +79,7 @@ class Sift {
return std::make_tuple(keypoints, descriptors);
}

sift_output_t Extract(Eigen::Ref<const pyimage_t<float>> image) {
sift_output_t Extract(const Eigen::Ref<const pyimage_t<float>>& image) {
const pyimage_t<uint8_t> image_f = (image * 255.0f).cast<uint8_t>();
return Extract(image_f);
}
Expand All @@ -106,13 +106,13 @@ void BindSift(py::module& m) {
"options"_a = sift_options,
"device"_a = Device::AUTO)
.def("extract",
py::overload_cast<Eigen::Ref<const pyimage_t<uint8_t>>>(
py::overload_cast<const Eigen::Ref<const pyimage_t<uint8_t>>&>(
&Sift::Extract),
"image"_a.noconvert())
.def("extract",
py::overload_cast<const Eigen::Ref<const pyimage_t<float>>&>(
&Sift::Extract),
"image"_a.noconvert())
.def(
"extract",
py::overload_cast<Eigen::Ref<const pyimage_t<float>>>(&Sift::Extract),
"image"_a.noconvert())
.def_property_readonly("options", &Sift::Options)
.def_property_readonly("device", &Sift::GetDevice);
}
10 changes: 5 additions & 5 deletions pycolmap/geometry/homography_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ using namespace pybind11::literals;
namespace py = pybind11;

py::dict PyPoseFromHomographyMatrix(
const Eigen::Matrix3d H,
const Eigen::Matrix3d K1,
const Eigen::Matrix3d K2,
const std::vector<Eigen::Vector2d> points1,
const std::vector<Eigen::Vector2d> points2) {
const Eigen::Matrix3d& H,
const Eigen::Matrix3d& K1,
const Eigen::Matrix3d& K2,
const std::vector<Eigen::Vector2d>& points1,
const std::vector<Eigen::Vector2d>& points2) {
THROW_CHECK_EQ(points1.size(), points1.size());
py::gil_scoped_release release;

Expand Down
7 changes: 4 additions & 3 deletions pycolmap/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ inline std::string CreateSummary(const T& self, bool write_type) {
std::string summ = attribute.attr("summary")
.attr("__call__")(write_type)
.template cast<std::string>();
// NOLINTNEXTLINE(performance-inefficient-string-concatenation)
summ = std::regex_replace(summ, std::regex("\n"), "\n" + prefix);
ss << ": " << summ;
} else {
Expand Down Expand Up @@ -238,12 +239,12 @@ inline void MakeDataclass(py::class_<T, options...> cls) {
cls.def("summary", &CreateSummary<T>, "write_type"_a = false);
}
cls.def("todict", &ConvertToDict<T>);
cls.def(py::init([cls](py::dict dict) {
cls.def(py::init([cls](const py::dict& dict) {
auto self = py::object(cls());
self.attr("mergedict").attr("__call__")(dict);
return self.cast<T>();
}));
cls.def(py::init([cls](py::kwargs kwargs) {
cls.def(py::init([cls](const py::kwargs& kwargs) {
py::dict dict = kwargs.cast<py::dict>();
auto self = py::object(cls(dict));
return self.cast<T>();
Expand Down Expand Up @@ -276,7 +277,7 @@ for (...) {
struct PyInterrupt {
using clock = std::chrono::steady_clock;
using sec = std::chrono::duration<double>;
PyInterrupt(double gap = -1.0);
explicit PyInterrupt(double gap = -1.0);

inline bool Raised();

Expand Down
20 changes: 11 additions & 9 deletions pycolmap/log_exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ inline const char* __ColmapGetConstFileBaseName(const char* file) {
}

template <typename T>
inline T TemplateException(const char* file, const int line, std::string txt) {
inline T TemplateException(const char* file,
const int line,
const std::string& txt) {
std::stringstream ss;
ss << "[" << __ColmapGetConstFileBaseName(file) << ":" << line << "] " << txt;
return T(ss.str());
Expand Down Expand Up @@ -65,7 +67,7 @@ inline void __ThrowCheckImplMsg(const char* file,
const int line,
const bool result,
const char* expr_str,
std::string msg) {
const std::string& msg) {
if (!result) {
std::stringstream ss;
ss << expr_str << " : " << msg;
Expand Down Expand Up @@ -100,14 +102,14 @@ void __ThrowCheckOpImpl(const char* file,
throw TemplateException<exception>(__FILE__, __LINE__, ToString(msg));

#define THROW_CUSTOM_CHECK_MSG(condition, exception, msg) \
if (!condition) \
if (!(condition)) \
throw TemplateException<exception>( \
__FILE__, \
__LINE__, \
__GetCheckString(#condition) + std::string(" ") + ToString(msg));

#define THROW_CUSTOM_CHECK(condition, exception) \
if (!condition) \
if (!(condition)) \
throw TemplateException<exception>( \
__FILE__, __LINE__, __GetCheckString(#condition));

Expand All @@ -129,19 +131,19 @@ void __ThrowCheckOpImpl(const char* file,

#define THROW_CHECK_FILE_EXISTS(path) \
THROW_CHECK_MSG(ExistsFile(path), \
std::string("File ") + path + " does not exist.");
std::string("File ") + (path) + " does not exist.");

#define THROW_CHECK_DIR_EXISTS(path) \
THROW_CHECK_MSG(ExistsDir(path), \
std::string("Directory ") + path + " does not exist.");
std::string("Directory ") + (path) + " does not exist.");

#define THROW_CHECK_FILE_OPEN(path) \
THROW_CHECK_MSG( \
std::ofstream(path, std::ios::trunc).is_open(), \
std::string(": Could not open ") + path + \
std::string(": Could not open ") + (path) + \
". Is the path a directory or does the parent dir not exist?");

#define THROW_CHECK_HAS_FILE_EXTENSION(path, ext) \
THROW_CHECK_MSG(HasFileExtension(path, ext), \
std::string("Path ") + path + \
" does not match file extension " + ext + ".");
std::string("Path ") + (path) + \
" does not match file extension " + (ext) + ".");
8 changes: 4 additions & 4 deletions pycolmap/pipeline/extract_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ using namespace colmap;
using namespace pybind11::literals;
namespace py = pybind11;

void ExtractFeatures(const py::object database_path_,
const py::object image_path_,
const std::vector<std::string> image_list,
void ExtractFeatures(const py::object& database_path_,
const py::object& image_path_,
const std::vector<std::string>& image_list,
const CameraMode camera_mode,
const std::string camera_model,
const std::string& camera_model,
ImageReaderOptions reader_options,
SiftExtractionOptions sift_options,
const Device device) {
Expand Down
52 changes: 26 additions & 26 deletions pycolmap/pipeline/images.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ using namespace colmap;
using namespace pybind11::literals;
namespace py = pybind11;

void ImportImages(const py::object database_path_,
const py::object image_path_,
void ImportImages(const py::object& database_path_,
const py::object& image_path_,
const CameraMode camera_mode,
const std::vector<std::string> image_list,
const ImageReaderOptions options_) {
const std::vector<std::string>& image_list,
const ImageReaderOptions& options_) {
std::string database_path = py::str(database_path_).cast<std::string>();
THROW_CHECK_FILE_EXISTS(database_path);
std::string image_path = py::str(image_path_).cast<std::string>();
Expand Down Expand Up @@ -70,11 +70,11 @@ void ImportImages(const py::object database_path_,
}
}

void ImportImages(const py::object database_path_,
const py::object image_path_,
void ImportImages(const py::object& database_path_,
const py::object& image_path_,
const CameraMode camera_mode,
const std::string camera_model,
const std::vector<std::string> image_list) {
const std::string& camera_model,
const std::vector<std::string>& image_list) {
ImageReaderOptions options;
if (!camera_model.empty()) {
options.camera_model = camera_model;
Expand All @@ -83,8 +83,8 @@ void ImportImages(const py::object database_path_,
database_path_, image_path_, camera_mode, image_list, options);
}

Camera infer_camera_from_image(const py::object image_path_,
const ImageReaderOptions options) {
Camera infer_camera_from_image(const py::object& image_path_,
const ImageReaderOptions& options) {
std::string image_path = py::str(image_path_).cast<std::string>();
THROW_CHECK_FILE_EXISTS(image_path);

Expand Down Expand Up @@ -115,14 +115,14 @@ Camera infer_camera_from_image(const py::object image_path_,
return camera;
}

void UndistortImages(py::object output_path_,
py::object input_path_,
py::object image_path_,
std::vector<std::string> image_list,
std::string output_type,
CopyType copy_type,
int num_patch_match_src_images,
UndistortCameraOptions undistort_camera_options) {
void UndistortImages(const py::object& output_path_,
const py::object& input_path_,
const py::object& image_path_,
const std::vector<std::string>& image_list,
const std::string& output_type,
const CopyType copy_type,
const int num_patch_match_src_images,
const UndistortCameraOptions& undistort_camera_options) {
std::string output_path = py::str(output_path_).cast<std::string>();
std::string input_path = py::str(input_path_).cast<std::string>();
THROW_CHECK_DIR_EXISTS(input_path);
Expand Down Expand Up @@ -259,11 +259,11 @@ void BindImages(py::module& m) {
auto undistort_options = PyUndistortCameraOptions().cast<UDOpts>();

m.def("import_images",
static_cast<void (*)(const py::object,
const py::object,
static_cast<void (*)(const py::object&,
const py::object&,
const CameraMode,
const std::vector<std::string>,
const ImageReaderOptions)>(&ImportImages),
const std::vector<std::string>&,
const ImageReaderOptions&)>(&ImportImages),
"database_path"_a,
"image_path"_a,
"camera_mode"_a = CameraMode::AUTO,
Expand All @@ -272,11 +272,11 @@ void BindImages(py::module& m) {
"Import images into a database");

m.def("import_images",
static_cast<void (*)(const py::object,
const py::object,
static_cast<void (*)(const py::object&,
const py::object&,
const CameraMode,
const std::string,
const std::vector<std::string>)>(&ImportImages),
const std::string&,
const std::vector<std::string>&)>(&ImportImages),
"database_path"_a,
"image_path"_a,
"camera_mode"_a = CameraMode::AUTO,
Expand Down
6 changes: 3 additions & 3 deletions pycolmap/pipeline/match_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ template <typename Opts,
const SiftMatchingOptions&,
const TwoViewGeometryOptions&,
const std::string&)>
void MatchFeatures(py::object database_path_,
void MatchFeatures(const py::object& database_path_,
SiftMatchingOptions sift_options,
const Opts& matching_options,
const TwoViewGeometryOptions& verification_options,
Expand All @@ -55,8 +55,8 @@ void MatchFeatures(py::object database_path_,
PyWait(matcher.get());
}

void verify_matches(const py::object database_path_,
const py::object pairs_path_,
void verify_matches(const py::object& database_path_,
const py::object& pairs_path_,
const TwoViewGeometryOptions& verification_options) {
const std::string database_path = py::str(database_path_).cast<std::string>();
THROW_CHECK_FILE_EXISTS(database_path);
Expand Down
18 changes: 9 additions & 9 deletions pycolmap/pipeline/meshing.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ void BindMeshing(py::module& m) {

m.def(
"poisson_meshing",
[](py::object input_path_,
py::object output_path_,
PoissonMOpts options) -> void {
[](const py::object& input_path_,
const py::object& output_path_,
const PoissonMOpts& options) -> void {
std::string input_path = py::str(input_path_).cast<std::string>();
THROW_CHECK_HAS_FILE_EXTENSION(input_path, ".ply")
THROW_CHECK_FILE_EXISTS(input_path);
Expand All @@ -139,9 +139,9 @@ void BindMeshing(py::module& m) {
#ifdef COLMAP_CGAL_ENABLED
m.def(
"sparse_delaunay_meshing",
[](py::object input_path_,
py::object output_path_,
DMOpts options) -> void {
[](const py::object& input_path_,
const py::object& output_path_,
const DMOpts& options) -> void {
std::string input_path = py::str(input_path_).cast<std::string>();
THROW_CHECK_DIR_EXISTS(input_path);

Expand All @@ -157,9 +157,9 @@ void BindMeshing(py::module& m) {

m.def(
"dense_delaunay_meshing",
[](py::object input_path_,
py::object output_path_,
DMOpts options) -> void {
[](const py::object& input_path_,
const py::object& output_path_,
const DMOpts& options) -> void {
std::string input_path = py::str(input_path_).cast<std::string>();
THROW_CHECK_DIR_EXISTS(input_path);

Expand Down
Loading

0 comments on commit 6b658f9

Please sign in to comment.