Skip to content

Merge NormalEstimationOMP into NormalEstimation #4279

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
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions apps/src/openni_feature_persistence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include <pcl/console/parse.h>
#include <pcl/features/fpfh_omp.h>
#include <pcl/features/multiscale_feature_persistence.h>
#include <pcl/features/normal_3d_omp.h>
#include <pcl/features/normal_3d.h>
#include <pcl/filters/extract_indices.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/io/openni_camera/openni_driver.h>
Expand Down Expand Up @@ -208,7 +208,7 @@ class OpenNIFeaturePersistence {
}

pcl::VoxelGrid<PointType> subsampling_filter_;
pcl::NormalEstimationOMP<PointType, pcl::Normal> normal_estimation_filter_;
pcl::NormalEstimation<PointType, pcl::Normal> normal_estimation_filter_;
typename pcl::FPFHEstimationOMP<PointType, pcl::Normal, pcl::FPFHSignature33>::Ptr
fpfh_estimation_;
pcl::MultiscaleFeaturePersistence<PointType, pcl::FPFHSignature33>
Expand Down
3 changes: 1 addition & 2 deletions apps/src/openni_tracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#include <pcl/console/parse.h>
#include <pcl/features/integral_image_normal.h>
#include <pcl/features/normal_3d.h>
#include <pcl/features/normal_3d_omp.h>
#include <pcl/filters/approximate_voxel_grid.h>
#include <pcl/filters/extract_indices.h>
#include <pcl/filters/passthrough.h>
Expand Down Expand Up @@ -635,7 +634,7 @@ class OpenNISegmentTracking {
std::string device_id_;
std::mutex mtx_;
bool new_cloud_;
pcl::NormalEstimationOMP<PointType, pcl::Normal> ne_; // to store threadpool
pcl::NormalEstimation<PointType, pcl::Normal> ne_; // to store threadpool
ParticleFilter::Ptr tracker_;
int counter_;
bool use_convex_hull_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <pcl/point_cloud.h>
#include <pcl/common/time.h>
#include <pcl/console/print.h>
#include <pcl/features/normal_3d_omp.h>
#include <pcl/features/normal_3d.h>
#include <pcl/features/fpfh_omp.h>
#include <pcl/filters/filter.h>
#include <pcl/filters/voxel_grid.h>
Expand Down Expand Up @@ -60,7 +60,7 @@ main (int argc, char **argv)

// Estimate normals for scene
pcl::console::print_highlight ("Estimating scene normals...\n");
pcl::NormalEstimationOMP<PointNT,PointNT> nest;
pcl::NormalEstimation<PointNT,PointNT> nest;
nest.setRadiusSearch (0.01);
nest.setInputCloud (scene);
nest.compute (*scene);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <pcl/io/pcd_io.h>
#include <pcl/point_cloud.h>
#include <pcl/correspondence.h>
#include <pcl/features/normal_3d_omp.h>
#include <pcl/features/normal_3d.h>
#include <pcl/features/shot_omp.h>
#include <pcl/features/board.h>
#include <pcl/filters/uniform_sampling.h>
Expand Down Expand Up @@ -210,7 +210,7 @@ main (int argc, char *argv[])
//
// Compute Normals
//
pcl::NormalEstimationOMP<PointType, NormalType> norm_est;
pcl::NormalEstimation<PointType, NormalType> norm_est;
norm_est.setKSearch (10);
norm_est.setInputCloud (model);
norm_est.compute (*model_normals);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <pcl/io/pcd_io.h>
#include <pcl/search/organized.h>
#include <pcl/search/kdtree.h>
#include <pcl/features/normal_3d_omp.h>
#include <pcl/features/normal_3d.h>
#include <pcl/filters/conditional_removal.h>
#include <pcl/segmentation/extract_clusters.h>

Expand Down Expand Up @@ -76,7 +76,7 @@ main (int argc, char *argv[])
}

// Compute normals using both small and large scales at each point
pcl::NormalEstimationOMP<PointXYZRGB, PointNormal> ne;
pcl::NormalEstimation<PointXYZRGB, PointNormal> ne;
ne.setInputCloud (cloud);
ne.setSearchMethod (tree);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include <pcl/io/pcd_io.h>
#include <pcl/point_cloud.h>
#include <pcl/correspondence.h>
#include <pcl/features/normal_3d_omp.h>
#include <pcl/features/normal_3d.h>
#include <pcl/features/shot_omp.h>
#include <pcl/features/board.h>
#include <pcl/filters/uniform_sampling.h>
Expand Down Expand Up @@ -247,7 +247,7 @@ main (int argc,
/**
* Compute Normals
*/
pcl::NormalEstimationOMP<PointType, NormalType> norm_est;
pcl::NormalEstimation<PointType, NormalType> norm_est;
norm_est.setKSearch (10);
norm_est.setInputCloud (model);
norm_est.compute (*model_normals);
Expand Down
6 changes: 3 additions & 3 deletions examples/features/example_difference_of_normals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
#include <string>

#include <pcl/io/pcd_io.h>
#include <pcl/features/normal_3d_omp.h>
#include <pcl/features/normal_3d.h>
#include <pcl/filters/conditional_removal.h>
#include <pcl/segmentation/extract_clusters.h>
#include <pcl/filters/voxel_grid.h>

#include <pcl/features/don.h>

#ifdef PCL_ONLY_CORE_POINT_TYPES
#include <pcl/features/impl/normal_3d_omp.hpp>
#include <pcl/features/impl/normal_3d.hpp>
#include <pcl/segmentation/impl/extract_clusters.hpp>
#endif

Expand Down Expand Up @@ -106,7 +106,7 @@ int main (int argc, char *argv[])
}

// Compute normals using both small and large scales at each point
pcl::NormalEstimationOMP<PointT, PointNT> ne;
pcl::NormalEstimation<PointT, PointNT> ne;
ne.setInputCloud (cloud);
ne.setSearchMethod (tree);

Expand Down
1 change: 0 additions & 1 deletion features/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ set(impl_incs
"include/pcl/${SUBSYS_NAME}/impl/multiscale_feature_persistence.hpp"
"include/pcl/${SUBSYS_NAME}/impl/narf.hpp"
"include/pcl/${SUBSYS_NAME}/impl/normal_3d.hpp"
"include/pcl/${SUBSYS_NAME}/impl/normal_3d_omp.hpp"
"include/pcl/${SUBSYS_NAME}/impl/normal_based_signature.hpp"
"include/pcl/${SUBSYS_NAME}/impl/organized_edge_detection.hpp"
"include/pcl/${SUBSYS_NAME}/impl/pfh.hpp"
Expand Down
95 changes: 25 additions & 70 deletions features/include/pcl/features/impl/normal_3d.hpp
Original file line number Diff line number Diff line change
@@ -1,49 +1,16 @@
/*
* 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$
*
*/

#ifndef PCL_FEATURES_IMPL_NORMAL_3D_H_
#define PCL_FEATURES_IMPL_NORMAL_3D_H_
#pragma once

#include <pcl/features/normal_3d.h>

///////////////////////////////////////////////////////////////////////////////////////////
template <typename PointInT, typename PointOutT> void
pcl::NormalEstimation<PointInT, PointOutT>::computeFeature (PointCloudOut &output)
{
Expand All @@ -53,48 +20,36 @@ pcl::NormalEstimation<PointInT, PointOutT>::computeFeature (PointCloudOut &outpu
std::vector<float> nn_dists (k_);

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)
{
// Iterating 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 ||
!computePointNormal (*surface_, nn_indices, output[idx].normal[0], output[idx].normal[1], output[idx].normal[2], output[idx].curvature))
{
output[idx].normal[0] = output[idx].normal[1] = output[idx].normal[2] = output[idx].curvature = std::numeric_limits<float>::quiet_NaN ();

output.is_dense = false;
continue;
}

flipNormalTowardsViewpoint ((*input_)[(*indices_)[idx]], vpx_, vpy_, vpz_,
output[idx].normal[0], output[idx].normal[1], output[idx].normal[2]);

}
}
else
{
#pragma omp parallel for \
default(none) \
shared(output) \
firstprivate(nn_indices, nn_dists) \
num_threads(threads_) \
if (threads_ != -1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If setNumberOfThreads() isn't called and no value is supplied to the constructor, the algorithm won't be run? Shouldn't it just default to one thread?

Can we maybe add { } for better readability?

Copy link
Member

@kunaltyagi kunaltyagi Jul 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving the if to be closer to the top might be better

// Iterating over the entire index vector
for (std::size_t idx = 0; idx < indices_->size (); ++idx)
for (std::ptrdiff_t idx = 0; idx < static_cast<std::ptrdiff_t> (indices_->size ()); ++idx)
{
if (!isFinite ((*input_)[(*indices_)[idx]]) ||
this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists) == 0 ||
!computePointNormal (*surface_, nn_indices, output[idx].normal[0], output[idx].normal[1], output[idx].normal[2], output[idx].curvature))
{
output[idx].normal[0] = output[idx].normal[1] = output[idx].normal[2] = output[idx].curvature = std::numeric_limits<float>::quiet_NaN ();

output.is_dense = false;
continue;
Eigen::Vector4f n;

if (input_->is_dense || isFinite ((*input_)[(*indices_)[idx]])) {
if (this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists) &&
pcl::computePointNormal (*surface_, nn_indices, n, output[idx].curvature)) {
output[idx].normal_x = n[0];
output[idx].normal_y = n[1];
output[idx].normal_z = n[2];

flipNormalTowardsViewpoint ((*input_)[(*indices_)[idx]], vpx_, vpy_, vpz_,
output[idx].normal[0], output[idx].normal[1], output[idx].normal[2]);
continue;
}
}

flipNormalTowardsViewpoint ((*input_)[(*indices_)[idx]], vpx_, vpy_, vpz_,
output[idx].normal[0], output[idx].normal[1], output[idx].normal[2]);
output[idx].normal[0] = output[idx].normal[1] = output[idx].normal[2] = output[idx].curvature = output[idx].curvature = std::numeric_limits<float>::quiet_NaN ();

if (output.is_dense)
output.is_dense = false;
}
}
}

#define PCL_INSTANTIATE_NormalEstimation(T,NT) template class PCL_EXPORTS pcl::NormalEstimation<T,NT>;

#endif // PCL_FEATURES_IMPL_NORMAL_3D_H_
Loading