-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Merge FPFHEstimationOMP into FPFHEstimation #4281
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
Open
shrijitsingh99
wants to merge
3
commits into
PointCloudLibrary:master
Choose a base branch
from
shrijitsingh99:fpfh
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,10 @@ | ||
/* | ||
* Software License Agreement (BSD License) | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
* | ||
* Point Cloud Library (PCL) - www.pointclouds.org | ||
* Copyright (c) 2010-2011, Willow Garage, Inc. | ||
* Copyright (c) 2012-, Open Perception, Inc. | ||
* | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above | ||
* copyright notice, this list of conditions and the following | ||
* disclaimer in the documentation and/or other materials provided | ||
* with the distribution. | ||
* * Neither the name of the copyright holder(s) nor the names of its | ||
* contributors may be used to endorse or promote products derived | ||
* from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* $Id$ | ||
* | ||
*/ | ||
|
||
#pragma once | ||
|
@@ -186,7 +155,8 @@ pcl::FPFHEstimation<PointInT, PointNT, PointOutT>::computeSPFHSignatures (std::v | |
std::vector<int> nn_indices (k_); | ||
std::vector<float> nn_dists (k_); | ||
|
||
std::set<int> spfh_indices; | ||
std::set<int> spfh_indices_set; | ||
std::vector<int> spfh_indices_vec; | ||
spfh_hist_lookup.resize (surface_->size ()); | ||
|
||
// Build a list of (unique) indices for which we will need to compute SPFH signatures | ||
|
@@ -199,26 +169,37 @@ pcl::FPFHEstimation<PointInT, PointNT, PointOutT>::computeSPFHSignatures (std::v | |
if (this->searchForNeighbors (p_idx, search_parameter_, nn_indices, nn_dists) == 0) | ||
continue; | ||
|
||
spfh_indices.insert (nn_indices.begin (), nn_indices.end ()); | ||
spfh_indices_set.insert (nn_indices.begin (), nn_indices.end ()); | ||
} | ||
spfh_indices_vec.resize (spfh_indices_set.size ()); | ||
std::copy (spfh_indices_set.cbegin (), spfh_indices_set.cend (), spfh_indices_vec.begin ()); | ||
} | ||
else | ||
{ | ||
// Special case: When a feature must be computed at every point, there is no need for a neighborhood search | ||
for (std::size_t idx = 0; idx < indices_->size (); ++idx) | ||
spfh_indices.insert (static_cast<int> (idx)); | ||
spfh_indices_vec.resize (indices_->size ()); | ||
std::iota(spfh_indices_vec.begin (), spfh_indices_vec.end (), | ||
static_cast<decltype(spfh_indices_vec)::value_type>(0)); | ||
} | ||
|
||
// Initialize the arrays that will store the SPFH signatures | ||
std::size_t data_size = spfh_indices.size (); | ||
const auto data_size = spfh_indices_vec.size (); | ||
hist_f1.setZero (data_size, nr_bins_f1_); | ||
hist_f2.setZero (data_size, nr_bins_f2_); | ||
hist_f3.setZero (data_size, nr_bins_f3_); | ||
|
||
// Compute SPFH signatures for every point that needs them | ||
std::size_t i = 0; | ||
for (const auto& p_idx: spfh_indices) | ||
#pragma omp parallel for \ | ||
default(none) \ | ||
shared(spfh_hist_lookup, spfh_indices_vec, hist_f1, hist_f2, hist_f3) \ | ||
firstprivate(nn_indices, nn_dists) \ | ||
num_threads(threads_) \ | ||
if (threads_ != -1) | ||
for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t> (spfh_indices_vec.size ()); ++i) | ||
{ | ||
// Get the next point index | ||
int p_idx = spfh_indices_vec[i]; | ||
|
||
// Find the neighborhood around p_idx | ||
if (this->searchForNeighbors (*surface_, p_idx, search_parameter_, nn_indices, nn_dists) == 0) | ||
continue; | ||
|
@@ -228,7 +209,6 @@ pcl::FPFHEstimation<PointInT, PointNT, PointOutT>::computeSPFHSignatures (std::v | |
|
||
// Populate a lookup table for converting a point index to its corresponding row in the spfh_hist_* matrices | ||
spfh_hist_lookup[p_idx] = i; | ||
i++; | ||
} | ||
} | ||
|
||
|
@@ -245,59 +225,32 @@ pcl::FPFHEstimation<PointInT, PointNT, PointOutT>::computeFeature (PointCloudOut | |
computeSPFHSignatures (spfh_hist_lookup, hist_f1_, hist_f2_, hist_f3_); | ||
|
||
output.is_dense = true; | ||
// Save a few cycles by not checking every point for NaN/Inf values if the cloud is set to dense | ||
if (input_->is_dense) | ||
{ | ||
// Iterate over the entire index vector | ||
for (std::size_t idx = 0; idx < indices_->size (); ++idx) | ||
{ | ||
if (this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists) == 0) | ||
{ | ||
for (Eigen::Index d = 0; d < fpfh_histogram_.size (); ++d) | ||
output[idx].histogram[d] = std::numeric_limits<float>::quiet_NaN (); | ||
|
||
output.is_dense = false; | ||
continue; | ||
} | ||
|
||
// ... and remap the nn_indices values so that they represent row indices in the spfh_hist_* matrices | ||
// instead of indices into surface_->points | ||
for (auto &nn_index : nn_indices) | ||
nn_index = spfh_hist_lookup[nn_index]; | ||
|
||
// Compute the FPFH signature (i.e. compute a weighted combination of local SPFH signatures) ... | ||
weightPointSPFHSignature (hist_f1_, hist_f2_, hist_f3_, nn_indices, nn_dists, fpfh_histogram_); | ||
|
||
// ...and copy it into the output cloud | ||
std::copy_n(fpfh_histogram_.data (), fpfh_histogram_.size (), output[idx].histogram); | ||
} | ||
} | ||
else | ||
// Iterate over the entire index vector | ||
for (std::size_t idx = 0; idx < indices_->size (); ++idx) | ||
{ | ||
// Iterate over the entire index vector | ||
for (std::size_t idx = 0; idx < indices_->size (); ++idx) | ||
{ | ||
if (!isFinite ((*input_)[(*indices_)[idx]]) || | ||
this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists) == 0) | ||
{ | ||
for (Eigen::Index d = 0; d < fpfh_histogram_.size (); ++d) | ||
output[idx].histogram[d] = std::numeric_limits<float>::quiet_NaN (); | ||
|
||
output.is_dense = false; | ||
if (input_->is_dense || isFinite ((*input_)[(*indices_)[idx]])) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please benchmark this. Should not have adverse effects, but just to be sure |
||
if (this->searchForNeighbors( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Outdent the block please |
||
(*indices_)[idx], search_parameter_, nn_indices, nn_dists)) { | ||
// ... and remap the nn_indices values so that they represent row indices in the spfh_hist_* matrices | ||
// instead of indices into surface_->points | ||
for (auto &nn_index : nn_indices) | ||
nn_index = spfh_hist_lookup[nn_index]; | ||
|
||
// Compute the FPFH signature (i.e. compute a weighted combination of local SPFH signatures) ... | ||
weightPointSPFHSignature (hist_f1_, hist_f2_, hist_f3_, nn_indices, nn_dists, fpfh_histogram_); | ||
|
||
// ...and copy it into the output cloud | ||
std::copy_n(fpfh_histogram_.data (), fpfh_histogram_.size (), output[idx].histogram); | ||
continue; | ||
} | ||
} | ||
|
||
// ... and remap the nn_indices values so that they represent row indices in the spfh_hist_* matrices | ||
// instead of indices into surface_->points | ||
for (auto &nn_index : nn_indices) | ||
nn_index = spfh_hist_lookup[nn_index]; | ||
|
||
// Compute the FPFH signature (i.e. compute a weighted combination of local SPFH signatures) ... | ||
weightPointSPFHSignature (hist_f1_, hist_f2_, hist_f3_, nn_indices, nn_dists, fpfh_histogram_); | ||
for (Eigen::Index d = 0; d < fpfh_histogram_.size(); ++d) | ||
output[idx].histogram[d] = std::numeric_limits<float>::quiet_NaN(); | ||
|
||
// ...and copy it into the output cloud | ||
std::copy_n(fpfh_histogram_.data (), fpfh_histogram_.size (), output[idx].histogram); | ||
} | ||
if (output.is_dense) | ||
output.is_dense = false; | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The number here is for removal. Release in 1.12 and removal in 1.13 doesn't sound great. Make it the 1.14 at least