Best practices to pass pcl::PointCloud to a function
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
1
down vote
favorite
I am trying to pass a point cloud to a function. Since the point cloud data is huge, I don't want the compiler to make a copy of it while passing. Hence I passed the reference of it as shown below-
void box_filter(pcl::PointCloud<pcl::PointXYZRGB>& in_cloud, pcl::PointCloud<pcl::PointXYZRGB>& out_cloud)
pcl::CropBox<pcl::PointXYZRGB> filter;
filter.setMin(Eigen::Vector4f(x_min, y_min, z_min, 1.0));
filter.setMax(Eigen::Vector4f(x_max, y_max, z_max, 1.0));
filter.setInputCloud(in_cloud);
filter.filter(out_cloud);
I defined the point clouds as following-
pcl::PointCloud<pcl::PointXYZRGB> raw_cloud, filterd_cloud;
Later, I am visualizing the filtered cloud using PCLVisualizer. Please see the code snippet-
pcl::PointCloud<pcl::PointXYZRGB> raw_cloud, filterd_cloud;
pcl::io::loadPCDFile(pcd_filename, raw_cloud);
box_filter(raw_cloud, filterd_cloud);
pcl::visualization::PCLVisualizer viewer("Cloud Viewer");
viewer.addPointCloud(filterd_cloud, "filterd_cloud");
viewer.spin();
Unfortunately, the code throws following compilation errors-
In function âÂÂvoid box_filter(pcl::PointCloud<pcl::PointXYZRGB>&, pcl::PointCloud<pcl::PointXYZRGB>&)âÂÂ:
error: no matching function for call to âÂÂpcl::CropBox<pcl::PointXYZRGB>::setInputCloud(pcl::PointCloud<pcl::PointXYZRGB>&)âÂÂ
filter.setInputCloud(in_cloud);
^
candidate is: void pcl::PCLBase<PointT>::setInputCloud(const PointCloudConstPtr&) [with PointT = pcl::PointXYZRGB; pcl::PCLBase<PointT>::PointCloudConstPtr = boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZRGB> >]
setInputCloud (const PointCloudConstPtr &cloud);
^
error: no matching function for call to âÂÂpcl::visualization::PCLVisualizer::addPointCloud(pcl::PointCloud<pcl::PointXYZRGB>&, const char [14])âÂÂ
viewer.addPointCloud(filterd_cloud, "filterd_cloud");
^
candidates are: template<class PointT> bool pcl::visualization::PCLVisualizer::addPointCloud(const typename pcl::PointCloud<PointT>::ConstPtr&, const string&, int)
addPointCloud (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
^
It is clear that there is a mismatch between datatype as it is expecting for pcl::PointCloud<PointT>::ConstPtr
instead of pcl::PointCloud<PointT>
.
I modified the code as shown below-
void box_filter(pcl::PointCloud<pcl::PointXYZRGB>::Ptr in_cloud, pcl::PointCloud<pcl::PointXYZRGB>::Ptr out_cloud)
pcl::CropBox<pcl::PointXYZRGB> filter;
filter.setMin(Eigen::Vector4f(x_min, y_min, z_min, 1.0));
filter.setMax(Eigen::Vector4f(x_max, y_max, z_max, 1.0));
filter.setInputCloud(in_cloud);
filter.filter(*out_cloud);
and this too-
pcl::PointCloud<pcl::PointXYZRGB>::Ptr raw_cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
pcl::PointCloud<pcl::PointXYZRGB>::Ptr filterd_cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
pcl::io::loadPCDFile(pcd_filename, *raw_cloud);
box_filter(raw_cloud, filterd_cloud);
pcl::visualization::PCLVisualizer viewer("Cloud Viewer");
viewer.addPointCloud(filterd_cloud, "filterd_cloud");
viewer.spin();
It works but Is it fine?
I am looking for best practices while dealing with pcl::PointCloud<PointT>
as it is making use of Boost Pointers.
c++ boost
add a comment |Â
up vote
1
down vote
favorite
I am trying to pass a point cloud to a function. Since the point cloud data is huge, I don't want the compiler to make a copy of it while passing. Hence I passed the reference of it as shown below-
void box_filter(pcl::PointCloud<pcl::PointXYZRGB>& in_cloud, pcl::PointCloud<pcl::PointXYZRGB>& out_cloud)
pcl::CropBox<pcl::PointXYZRGB> filter;
filter.setMin(Eigen::Vector4f(x_min, y_min, z_min, 1.0));
filter.setMax(Eigen::Vector4f(x_max, y_max, z_max, 1.0));
filter.setInputCloud(in_cloud);
filter.filter(out_cloud);
I defined the point clouds as following-
pcl::PointCloud<pcl::PointXYZRGB> raw_cloud, filterd_cloud;
Later, I am visualizing the filtered cloud using PCLVisualizer. Please see the code snippet-
pcl::PointCloud<pcl::PointXYZRGB> raw_cloud, filterd_cloud;
pcl::io::loadPCDFile(pcd_filename, raw_cloud);
box_filter(raw_cloud, filterd_cloud);
pcl::visualization::PCLVisualizer viewer("Cloud Viewer");
viewer.addPointCloud(filterd_cloud, "filterd_cloud");
viewer.spin();
Unfortunately, the code throws following compilation errors-
In function âÂÂvoid box_filter(pcl::PointCloud<pcl::PointXYZRGB>&, pcl::PointCloud<pcl::PointXYZRGB>&)âÂÂ:
error: no matching function for call to âÂÂpcl::CropBox<pcl::PointXYZRGB>::setInputCloud(pcl::PointCloud<pcl::PointXYZRGB>&)âÂÂ
filter.setInputCloud(in_cloud);
^
candidate is: void pcl::PCLBase<PointT>::setInputCloud(const PointCloudConstPtr&) [with PointT = pcl::PointXYZRGB; pcl::PCLBase<PointT>::PointCloudConstPtr = boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZRGB> >]
setInputCloud (const PointCloudConstPtr &cloud);
^
error: no matching function for call to âÂÂpcl::visualization::PCLVisualizer::addPointCloud(pcl::PointCloud<pcl::PointXYZRGB>&, const char [14])âÂÂ
viewer.addPointCloud(filterd_cloud, "filterd_cloud");
^
candidates are: template<class PointT> bool pcl::visualization::PCLVisualizer::addPointCloud(const typename pcl::PointCloud<PointT>::ConstPtr&, const string&, int)
addPointCloud (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
^
It is clear that there is a mismatch between datatype as it is expecting for pcl::PointCloud<PointT>::ConstPtr
instead of pcl::PointCloud<PointT>
.
I modified the code as shown below-
void box_filter(pcl::PointCloud<pcl::PointXYZRGB>::Ptr in_cloud, pcl::PointCloud<pcl::PointXYZRGB>::Ptr out_cloud)
pcl::CropBox<pcl::PointXYZRGB> filter;
filter.setMin(Eigen::Vector4f(x_min, y_min, z_min, 1.0));
filter.setMax(Eigen::Vector4f(x_max, y_max, z_max, 1.0));
filter.setInputCloud(in_cloud);
filter.filter(*out_cloud);
and this too-
pcl::PointCloud<pcl::PointXYZRGB>::Ptr raw_cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
pcl::PointCloud<pcl::PointXYZRGB>::Ptr filterd_cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
pcl::io::loadPCDFile(pcd_filename, *raw_cloud);
box_filter(raw_cloud, filterd_cloud);
pcl::visualization::PCLVisualizer viewer("Cloud Viewer");
viewer.addPointCloud(filterd_cloud, "filterd_cloud");
viewer.spin();
It works but Is it fine?
I am looking for best practices while dealing with pcl::PointCloud<PointT>
as it is making use of Boost Pointers.
c++ boost
1
That isn't a problem of best practices. You have to respect the library function signature, which asks for a pointer. Pointers and references have their pros and cons, but the choice was made for you by the library's author. Neither copies the data, luckily for you :-)
â papagaga
Feb 9 at 8:50
@papagaga: respect library function signature ... that's what I want to know. I usedPtr
shown above in the code but it that fine? Thanks!
â Ravi Joshi
Feb 9 at 9:05
Yes, that's as fine as can be.Boost::shared_ptr
isn't an optimal choice anymore since it has been superseded bystd::shared_ptr
but you're stuck with it. You're also correct to create theshared_ptr
before calling the function on them, since that could lead to memory leaks. See: boost.org/doc/libs/1_62_0/libs/smart_ptr/shared_ptr.htm, even though usingboost::make_shared
would still be better, for the same reasons asstd::make_shared
â papagaga
Feb 9 at 10:42
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am trying to pass a point cloud to a function. Since the point cloud data is huge, I don't want the compiler to make a copy of it while passing. Hence I passed the reference of it as shown below-
void box_filter(pcl::PointCloud<pcl::PointXYZRGB>& in_cloud, pcl::PointCloud<pcl::PointXYZRGB>& out_cloud)
pcl::CropBox<pcl::PointXYZRGB> filter;
filter.setMin(Eigen::Vector4f(x_min, y_min, z_min, 1.0));
filter.setMax(Eigen::Vector4f(x_max, y_max, z_max, 1.0));
filter.setInputCloud(in_cloud);
filter.filter(out_cloud);
I defined the point clouds as following-
pcl::PointCloud<pcl::PointXYZRGB> raw_cloud, filterd_cloud;
Later, I am visualizing the filtered cloud using PCLVisualizer. Please see the code snippet-
pcl::PointCloud<pcl::PointXYZRGB> raw_cloud, filterd_cloud;
pcl::io::loadPCDFile(pcd_filename, raw_cloud);
box_filter(raw_cloud, filterd_cloud);
pcl::visualization::PCLVisualizer viewer("Cloud Viewer");
viewer.addPointCloud(filterd_cloud, "filterd_cloud");
viewer.spin();
Unfortunately, the code throws following compilation errors-
In function âÂÂvoid box_filter(pcl::PointCloud<pcl::PointXYZRGB>&, pcl::PointCloud<pcl::PointXYZRGB>&)âÂÂ:
error: no matching function for call to âÂÂpcl::CropBox<pcl::PointXYZRGB>::setInputCloud(pcl::PointCloud<pcl::PointXYZRGB>&)âÂÂ
filter.setInputCloud(in_cloud);
^
candidate is: void pcl::PCLBase<PointT>::setInputCloud(const PointCloudConstPtr&) [with PointT = pcl::PointXYZRGB; pcl::PCLBase<PointT>::PointCloudConstPtr = boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZRGB> >]
setInputCloud (const PointCloudConstPtr &cloud);
^
error: no matching function for call to âÂÂpcl::visualization::PCLVisualizer::addPointCloud(pcl::PointCloud<pcl::PointXYZRGB>&, const char [14])âÂÂ
viewer.addPointCloud(filterd_cloud, "filterd_cloud");
^
candidates are: template<class PointT> bool pcl::visualization::PCLVisualizer::addPointCloud(const typename pcl::PointCloud<PointT>::ConstPtr&, const string&, int)
addPointCloud (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
^
It is clear that there is a mismatch between datatype as it is expecting for pcl::PointCloud<PointT>::ConstPtr
instead of pcl::PointCloud<PointT>
.
I modified the code as shown below-
void box_filter(pcl::PointCloud<pcl::PointXYZRGB>::Ptr in_cloud, pcl::PointCloud<pcl::PointXYZRGB>::Ptr out_cloud)
pcl::CropBox<pcl::PointXYZRGB> filter;
filter.setMin(Eigen::Vector4f(x_min, y_min, z_min, 1.0));
filter.setMax(Eigen::Vector4f(x_max, y_max, z_max, 1.0));
filter.setInputCloud(in_cloud);
filter.filter(*out_cloud);
and this too-
pcl::PointCloud<pcl::PointXYZRGB>::Ptr raw_cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
pcl::PointCloud<pcl::PointXYZRGB>::Ptr filterd_cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
pcl::io::loadPCDFile(pcd_filename, *raw_cloud);
box_filter(raw_cloud, filterd_cloud);
pcl::visualization::PCLVisualizer viewer("Cloud Viewer");
viewer.addPointCloud(filterd_cloud, "filterd_cloud");
viewer.spin();
It works but Is it fine?
I am looking for best practices while dealing with pcl::PointCloud<PointT>
as it is making use of Boost Pointers.
c++ boost
I am trying to pass a point cloud to a function. Since the point cloud data is huge, I don't want the compiler to make a copy of it while passing. Hence I passed the reference of it as shown below-
void box_filter(pcl::PointCloud<pcl::PointXYZRGB>& in_cloud, pcl::PointCloud<pcl::PointXYZRGB>& out_cloud)
pcl::CropBox<pcl::PointXYZRGB> filter;
filter.setMin(Eigen::Vector4f(x_min, y_min, z_min, 1.0));
filter.setMax(Eigen::Vector4f(x_max, y_max, z_max, 1.0));
filter.setInputCloud(in_cloud);
filter.filter(out_cloud);
I defined the point clouds as following-
pcl::PointCloud<pcl::PointXYZRGB> raw_cloud, filterd_cloud;
Later, I am visualizing the filtered cloud using PCLVisualizer. Please see the code snippet-
pcl::PointCloud<pcl::PointXYZRGB> raw_cloud, filterd_cloud;
pcl::io::loadPCDFile(pcd_filename, raw_cloud);
box_filter(raw_cloud, filterd_cloud);
pcl::visualization::PCLVisualizer viewer("Cloud Viewer");
viewer.addPointCloud(filterd_cloud, "filterd_cloud");
viewer.spin();
Unfortunately, the code throws following compilation errors-
In function âÂÂvoid box_filter(pcl::PointCloud<pcl::PointXYZRGB>&, pcl::PointCloud<pcl::PointXYZRGB>&)âÂÂ:
error: no matching function for call to âÂÂpcl::CropBox<pcl::PointXYZRGB>::setInputCloud(pcl::PointCloud<pcl::PointXYZRGB>&)âÂÂ
filter.setInputCloud(in_cloud);
^
candidate is: void pcl::PCLBase<PointT>::setInputCloud(const PointCloudConstPtr&) [with PointT = pcl::PointXYZRGB; pcl::PCLBase<PointT>::PointCloudConstPtr = boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZRGB> >]
setInputCloud (const PointCloudConstPtr &cloud);
^
error: no matching function for call to âÂÂpcl::visualization::PCLVisualizer::addPointCloud(pcl::PointCloud<pcl::PointXYZRGB>&, const char [14])âÂÂ
viewer.addPointCloud(filterd_cloud, "filterd_cloud");
^
candidates are: template<class PointT> bool pcl::visualization::PCLVisualizer::addPointCloud(const typename pcl::PointCloud<PointT>::ConstPtr&, const string&, int)
addPointCloud (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
^
It is clear that there is a mismatch between datatype as it is expecting for pcl::PointCloud<PointT>::ConstPtr
instead of pcl::PointCloud<PointT>
.
I modified the code as shown below-
void box_filter(pcl::PointCloud<pcl::PointXYZRGB>::Ptr in_cloud, pcl::PointCloud<pcl::PointXYZRGB>::Ptr out_cloud)
pcl::CropBox<pcl::PointXYZRGB> filter;
filter.setMin(Eigen::Vector4f(x_min, y_min, z_min, 1.0));
filter.setMax(Eigen::Vector4f(x_max, y_max, z_max, 1.0));
filter.setInputCloud(in_cloud);
filter.filter(*out_cloud);
and this too-
pcl::PointCloud<pcl::PointXYZRGB>::Ptr raw_cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
pcl::PointCloud<pcl::PointXYZRGB>::Ptr filterd_cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
pcl::io::loadPCDFile(pcd_filename, *raw_cloud);
box_filter(raw_cloud, filterd_cloud);
pcl::visualization::PCLVisualizer viewer("Cloud Viewer");
viewer.addPointCloud(filterd_cloud, "filterd_cloud");
viewer.spin();
It works but Is it fine?
I am looking for best practices while dealing with pcl::PointCloud<PointT>
as it is making use of Boost Pointers.
c++ boost
asked Feb 9 at 6:57
Ravi Joshi
18516
18516
1
That isn't a problem of best practices. You have to respect the library function signature, which asks for a pointer. Pointers and references have their pros and cons, but the choice was made for you by the library's author. Neither copies the data, luckily for you :-)
â papagaga
Feb 9 at 8:50
@papagaga: respect library function signature ... that's what I want to know. I usedPtr
shown above in the code but it that fine? Thanks!
â Ravi Joshi
Feb 9 at 9:05
Yes, that's as fine as can be.Boost::shared_ptr
isn't an optimal choice anymore since it has been superseded bystd::shared_ptr
but you're stuck with it. You're also correct to create theshared_ptr
before calling the function on them, since that could lead to memory leaks. See: boost.org/doc/libs/1_62_0/libs/smart_ptr/shared_ptr.htm, even though usingboost::make_shared
would still be better, for the same reasons asstd::make_shared
â papagaga
Feb 9 at 10:42
add a comment |Â
1
That isn't a problem of best practices. You have to respect the library function signature, which asks for a pointer. Pointers and references have their pros and cons, but the choice was made for you by the library's author. Neither copies the data, luckily for you :-)
â papagaga
Feb 9 at 8:50
@papagaga: respect library function signature ... that's what I want to know. I usedPtr
shown above in the code but it that fine? Thanks!
â Ravi Joshi
Feb 9 at 9:05
Yes, that's as fine as can be.Boost::shared_ptr
isn't an optimal choice anymore since it has been superseded bystd::shared_ptr
but you're stuck with it. You're also correct to create theshared_ptr
before calling the function on them, since that could lead to memory leaks. See: boost.org/doc/libs/1_62_0/libs/smart_ptr/shared_ptr.htm, even though usingboost::make_shared
would still be better, for the same reasons asstd::make_shared
â papagaga
Feb 9 at 10:42
1
1
That isn't a problem of best practices. You have to respect the library function signature, which asks for a pointer. Pointers and references have their pros and cons, but the choice was made for you by the library's author. Neither copies the data, luckily for you :-)
â papagaga
Feb 9 at 8:50
That isn't a problem of best practices. You have to respect the library function signature, which asks for a pointer. Pointers and references have their pros and cons, but the choice was made for you by the library's author. Neither copies the data, luckily for you :-)
â papagaga
Feb 9 at 8:50
@papagaga: respect library function signature ... that's what I want to know. I used
Ptr
shown above in the code but it that fine? Thanks!â Ravi Joshi
Feb 9 at 9:05
@papagaga: respect library function signature ... that's what I want to know. I used
Ptr
shown above in the code but it that fine? Thanks!â Ravi Joshi
Feb 9 at 9:05
Yes, that's as fine as can be.
Boost::shared_ptr
isn't an optimal choice anymore since it has been superseded by std::shared_ptr
but you're stuck with it. You're also correct to create the shared_ptr
before calling the function on them, since that could lead to memory leaks. See: boost.org/doc/libs/1_62_0/libs/smart_ptr/shared_ptr.htm, even though using boost::make_shared
would still be better, for the same reasons as std::make_shared
â papagaga
Feb 9 at 10:42
Yes, that's as fine as can be.
Boost::shared_ptr
isn't an optimal choice anymore since it has been superseded by std::shared_ptr
but you're stuck with it. You're also correct to create the shared_ptr
before calling the function on them, since that could lead to memory leaks. See: boost.org/doc/libs/1_62_0/libs/smart_ptr/shared_ptr.htm, even though using boost::make_shared
would still be better, for the same reasons as std::make_shared
â papagaga
Feb 9 at 10:42
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f187160%2fbest-practices-to-pass-pclpointcloudpointt-to-a-function%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
That isn't a problem of best practices. You have to respect the library function signature, which asks for a pointer. Pointers and references have their pros and cons, but the choice was made for you by the library's author. Neither copies the data, luckily for you :-)
â papagaga
Feb 9 at 8:50
@papagaga: respect library function signature ... that's what I want to know. I used
Ptr
shown above in the code but it that fine? Thanks!â Ravi Joshi
Feb 9 at 9:05
Yes, that's as fine as can be.
Boost::shared_ptr
isn't an optimal choice anymore since it has been superseded bystd::shared_ptr
but you're stuck with it. You're also correct to create theshared_ptr
before calling the function on them, since that could lead to memory leaks. See: boost.org/doc/libs/1_62_0/libs/smart_ptr/shared_ptr.htm, even though usingboost::make_shared
would still be better, for the same reasons asstd::make_shared
â papagaga
Feb 9 at 10:42