Skip to content

Commit

Permalink
remove superfluous locking in RandomSampler
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminum committed Nov 13, 2024
1 parent d2aad5c commit e046b18
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions cpp/open3d/geometry/PointCloudSegmentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class RandomSampler {
explicit RandomSampler(const size_t total_size) : total_size_(total_size) {}

std::vector<T> operator()(size_t sample_size) {
std::lock_guard<std::mutex> lock(mutex_);
std::vector<T> samples;
samples.reserve(sample_size);

Expand All @@ -48,7 +47,6 @@ class RandomSampler {

private:
size_t total_size_;
std::mutex mutex_;
};

/// \class RANSACResult
Expand Down Expand Up @@ -172,6 +170,7 @@ std::tuple<Eigen::Vector4d, std::vector<size_t>> PointCloud::SegmentPlane(
Eigen::Vector4d best_plane_model = Eigen::Vector4d(0, 0, 0, 0);

RandomSampler<size_t> sampler(num_points);
// Pre-generate all random samples before entering the parallel region
std::vector<std::vector<size_t>> all_sampled_indices;
all_sampled_indices.reserve(num_iterations);
for (int i = 0; i < num_iterations; i++) {
Expand Down

0 comments on commit e046b18

Please sign in to comment.