Skip to content

Commit

Permalink
Fix clang build for macOS users (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
nachovizzo authored Feb 21, 2023
1 parent c8ce571 commit 0879030
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
11 changes: 10 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ clang-format:
- clang-format -Werror --dry-run $(find . -regextype posix-extended -regex ".*\.(cpp|hpp|h)")

#----- build stage ---------------------------------------------------------------------------------
cpp_api:
cpp_api:gcc:
image: ubuntu:22.04
stage: build
before_script:
Expand All @@ -55,6 +55,15 @@ cpp_api:
- cmake -Bbuild src/cpp/kiss_icp/
- cmake --build build -j$(nproc --all)

cpp_api:clang:
image: ubuntu:22.04
stage: build
before_script:
- apt-get update && apt-get install --no-install-recommends -y clang cmake make
script:
- cmake cmake -DCMAKE_CXX_COMPILER=clang++ -Bbuild src/cpp/kiss_icp/
- cmake --build build -j$(nproc --all)

pip_package:
image: python:3.8
stage: build
Expand Down
10 changes: 7 additions & 3 deletions src/cpp/kiss_icp/core/Deskew.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ Vector3dVector MotionCompensator::DeSkewScan(const std::vector<Eigen::Vector3d>
const Eigen::Isometry3d &start_pose,
const Eigen::Isometry3d &finish_pose) {
// Estimate linear and angular velocities
const auto [lvel, avel] = VelocityEstimation(start_pose, finish_pose, scan_duration_);
const auto [lv, av] = VelocityEstimation(start_pose, finish_pose, scan_duration_);

// Compile in clang for macOS: https://stackoverflow.com/questions/46114214
const auto &linear_velocity = lv;
const auto &angular_velocity = av;

// TODO(Nacho) Add explanation of this
std::vector<double> timestamps_ = timestamps;
Expand All @@ -63,8 +67,8 @@ Vector3dVector MotionCompensator::DeSkewScan(const std::vector<Eigen::Vector3d>

std::vector<Eigen::Vector3d> corrected_frame(frame.size());
tbb::parallel_for(size_t(0), frame.size(), [&](size_t i) {
const auto &dt = timestamps_[i];
const auto motion = MakeTransform(dt * lvel, dt * avel);
const auto dt = timestamps_[i];
const auto motion = MakeTransform(dt * linear_velocity, dt * angular_velocity);
corrected_frame[i] = motion * frame[i];
});
return corrected_frame;
Expand Down
16 changes: 9 additions & 7 deletions src/cpp/kiss_icp/core/VoxelHashMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ VoxelHashMap::Vector3dVectorTuple VoxelHashMap::GetCorrespondences(
// 1st lambda: Paralell computation
[&](const tbb::blocked_range<points_iterator> &r, ResultTuple res) -> ResultTuple {
auto &[src, tgt] = res;
auto &source_private = src; // compile on clang
auto &target_private = tgt; // compile on clang
// Compile in clang for macOS: https://stackoverflow.com/questions/46114214
auto &source_private = src;
auto &target_private = tgt;
source_private.reserve(r.size());
target_private.reserve(r.size());
std::for_each(r.begin(), r.end(), [&](const auto &point) {
Expand All @@ -150,12 +151,13 @@ VoxelHashMap::Vector3dVectorTuple VoxelHashMap::GetCorrespondences(
// 2st lambda: Parallell reduction
[&](ResultTuple a, const ResultTuple &b) -> ResultTuple {
auto &[src, tgt] = a;
auto &source = src; // compile on clang
auto &target = tgt; // compile on clang
const auto &[srcp, tgtp] = b;
auto &source_private = srcp; // compile on clang
auto &target_private = tgtp; // compile on clang
source.insert(source.end(), //
// Compile in clang for macOS: https://stackoverflow.com/questions/46114214
auto &source = src;
auto &target = tgt;
auto &source_private = srcp;
auto &target_private = tgtp;
source.insert(source.end(), //
std::make_move_iterator(source_private.begin()),
std::make_move_iterator(source_private.end()));
target.insert(target.end(), //
Expand Down

0 comments on commit 0879030

Please sign in to comment.