Skip to content
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

Provide dynamic and static pointer casts in pcl namespace to allow easy migration from boost to std smart pointers #3770

Merged
merged 8 commits into from
Apr 16, 2020
5 changes: 3 additions & 2 deletions apps/src/feature_matching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/keypoints/sift_keypoint.h>
#include <pcl/keypoints/harris_3d.h>
#include <pcl/memory.h> // for pcl::dynamic_pointer_cast
#include <pcl/ModelCoefficients.h>
#include <pcl/sample_consensus/method_types.h>
#include <pcl/sample_consensus/model_types.h>
Expand Down Expand Up @@ -245,13 +246,13 @@ void ICCVTutorial<FeatureType>::extractDescriptors (typename pcl::PointCloud<pcl

pcl::copyPointCloud(*keypoints, *kpts);

typename pcl::FeatureFromNormals<pcl::PointXYZRGB, pcl::Normal, FeatureType>::Ptr feature_from_normals = boost::dynamic_pointer_cast<pcl::FeatureFromNormals<pcl::PointXYZRGB, pcl::Normal, FeatureType> > (feature_extractor_);
typename pcl::FeatureFromNormals<pcl::PointXYZRGB, pcl::Normal, FeatureType>::Ptr feature_from_normals = pcl::dynamic_pointer_cast<pcl::FeatureFromNormals<pcl::PointXYZRGB, pcl::Normal, FeatureType> > (feature_extractor_);

feature_extractor_->setSearchSurface(input);
feature_extractor_->setInputCloud(kpts);

if (feature_from_normals)
//if (boost::dynamic_pointer_cast<typename pcl::FeatureFromNormals<pcl::PointXYZRGB, pcl::Normal, FeatureType> > (feature_extractor_))
//if (pcl::dynamic_pointer_cast<typename pcl::FeatureFromNormals<pcl::PointXYZRGB, pcl::Normal, FeatureType> > (feature_extractor_))
{
std::cout << "normal estimation..." << std::flush;
typename pcl::PointCloud<pcl::Normal>::Ptr normals (new pcl::PointCloud<pcl::Normal>);
Expand Down
7 changes: 6 additions & 1 deletion apps/src/organized_segmentation_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@
#include <QEvent>
#include <QObject>

#include <pcl/memory.h> // for pcl::dynamic_pointer_cast
#include <pcl/segmentation/extract_polygonal_prism_data.h>
#include <pcl/surface/convex_hull.h>

#include <vtkRenderWindow.h>

// #include <boost/filesystem.hpp> // for boost::filesystem::directory_iterator
aPonza marked this conversation as resolved.
Show resolved Hide resolved
#include <boost/signals2/connection.hpp> // for boost::signals2::connection


void
displayPlanarRegions (std::vector<pcl::PlanarRegion<PointT>, Eigen::aligned_allocator<pcl::PlanarRegion<PointT> > > &regions,
const pcl::visualization::PCLVisualizer::Ptr& viewer)
Expand Down Expand Up @@ -276,7 +281,7 @@ OrganizedSegmentationDemo::cloud_cb (const CloudConstPtr& cloud)
ne.setInputCloud (cloud);
ne.compute (*normal_cloud);
float* distance_map = ne.getDistanceMap ();
pcl::EdgeAwarePlaneComparator<PointT, pcl::Normal>::Ptr eapc = boost::dynamic_pointer_cast<pcl::EdgeAwarePlaneComparator<PointT, pcl::Normal> >(edge_aware_comparator_);
pcl::EdgeAwarePlaneComparator<PointT, pcl::Normal>::Ptr eapc = pcl::dynamic_pointer_cast<pcl::EdgeAwarePlaneComparator<PointT, pcl::Normal> >(edge_aware_comparator_);
eapc->setDistanceMap (distance_map);
eapc->setDistanceThreshold (0.01f, false);

Expand Down
13 changes: 9 additions & 4 deletions common/include/pcl/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@


#include <boost/make_shared.hpp> // for boost::allocate_shared, boost::make_shared
#include <boost/pointer_cast.hpp> // for boost::dynamic_pointer_cast, boost::static_pointer_cast
#include <boost/smart_ptr/shared_ptr.hpp> // for boost::shared_ptr

#include <Eigen/Core> // for EIGEN_MAKE_ALIGNED_OPERATOR_NEW
Expand All @@ -70,15 +71,19 @@
namespace pcl
{
/**
* \brief Alias for boost::shared_ptr
* \brief Force ADL for `shared_ptr`
*
* For ease of switching from boost::shared_ptr to std::shared_ptr
*
* \see pcl::make_shared
* \tparam T Type of the object stored inside the shared_ptr
*/
template <typename T>
using shared_ptr = boost::shared_ptr<T>;
using boost::shared_ptr;

/** ADL doesn't work until C++20 for dynamic_pointer_cast since it requires an explicit Tparam */
using boost::dynamic_pointer_cast;
aPonza marked this conversation as resolved.
Show resolved Hide resolved

/** ADL doesn't work until C++20 for static_pointer_cast since it requires an explicit Tparam */
using boost::static_pointer_cast;


template <typename ...> using void_t = void; // part of std in c++17
Expand Down
Loading