Programming generic functions for point clouds

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Programming generic functions for point clouds

apalomer
Hello,

I want to build a function that does a computation on a cloud (let's say it just adds 1 to all x coordinates of points). Right now the only option that I know to have it available for more than one cloud is to implement the same function again for each point cloud type. I am doing someting like:

void addOne(pcl::PointCloud<pcl::PointXYZ>::Ptr pc)
{
    for (int i = 0;i<pc->size();i++)
        pc->points[i].x++;
}
void addOne(pcl::PointCloud<pcl::PointXYZRGB>::Ptr pc)
{
    for (int i = 0;i<pc->size();i++)
        pc->points[i].x++;
}

However, I would like to have something like:

void addOne(pcl::PointCloud<T>::Ptr pc)
{
    for (int i = 0;i<pc->size();i++)
        pc->points[i].x++;
}

so then I can instatiate this for each type of point that I would be using it.
Any idea on how to do so?

Thanks!!
Reply | Threaded
Open this post in threaded view
|

Re: Programming generic functions for point clouds

noname
hi,

what about templated functions/classes/methods?
i.e.
template<typename PointT>
void addOne(pcl::PointCloud<typename PointT>::Ptr pc)
{
     for(...) pc->points[i].x++;
}

kind regards

On 28.06.2017 13:52, apalomer wrote:

> Hello,
>
> I want to build a function that does a computation on a cloud (let's say it
> just adds 1 to all x coordinates of points). Right now the only option that
> I know to have it available for more than one cloud is to implement the same
> function again for each point cloud type. I am doing someting like:
>
> void addOne(pcl::PointCloud<pcl::PointXYZ>::Ptr pc)
> {
>      for (int i = 0;i<pc->size();i++)
>          pc->points[i].x++;
> }
> void addOne(pcl::PointCloud<pcl::PointXYZRGB>::Ptr pc)
> {
>      for (int i = 0;i<pc->size();i++)
>          pc->points[i].x++;
> }
>
> However, I would like to have something like:
>
> void addOne(pcl::PointCloud<T>::Ptr pc)
> {
>      for (int i = 0;i<pc->size();i++)
>          pc->points[i].x++;
> }
>
> so then I can instatiate this for each type of point that I would be using
> it.
> Any idea on how to do so?
>
> Thanks!!
>
>
>
> --
> View this message in context: http://www.pcl-users.org/Programming-generic-functions-for-point-clouds-tp4044676.html
> Sent from the Point Cloud Library (PCL) Users mailing list mailing list archive at Nabble.com.
> _______________________________________________
> [hidden email] / http://pointclouds.org
> http://pointclouds.org/mailman/listinfo/pcl-users

_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users
Reply | Threaded
Open this post in threaded view
|

Re: Programming generic functions for point clouds

apalomer
Sorry I sould have already said that I did try this options:

template<typename PointT>
void addOne(pcl::PointCloud<typename PointT>::Ptr pc)
{
    for (int i = 0;i<pc->size();i++)
        pc->points[i].x++;
}

with the following compiler error:
template argument 1 is invalid void addOne(pcl::PointCloud<typename PointT>::Ptr pc)

template<typename PointT>
void addOne(pcl::PointCloud<PointT>::Ptr pc)
{
    for (int i = 0;i<pc->size();i++)
        pc->points[i].x++;
}

with the following compiler error:
error: expected ')' before 'pc'  void addOne(pcl::PointCloud<PointT>::Ptr pc)

template<typename T>
void addOne(pcl::PointCloud<T>::Ptr pc)
{
    for (int i = 0;i<pc->size();i++)
        pc->points[i].x++;
}
with the following compiler error:
error: expected ')' before 'pc' void addOne(pcl::PointCloud<T>::Ptr pc)
Reply | Threaded
Open this post in threaded view
|

Re: Programming generic functions for point clouds

noname
you might need to prefix both templates with "typename". just tested the
following example, compiles fine here (no pcl available, thus my own
"MyPointCloud" type).

#include <vector>
template<typename PointT>
class MyPointCloud
{
public:
     typedef std::shared_ptr<MyPointCloud> Ptr;
     inline std::size_t size() const { return m_points.size(); }
     std::vector<PointT> m_points;
};

template<typename PointT>
void addOne(typename MyPointCloud<typename PointT>::Ptr pc)
{
     for (int i = 0; i < pc->size(); ++i)
     {
         pc->m_points[i].x++;
     }
}

kind regards


On 28.06.2017 14:43, apalomer wrote:

> Sorry I sould have already said that I did try this options:
>
> template<typename PointT>
> void addOne(pcl::PointCloud<typename PointT>::Ptr pc)
> {
>      for (int i = 0;i<pc->size();i++)
>          pc->points[i].x++;
> }
>
> with the following compiler error:
> template argument 1 is invalid void addOne(pcl::PointCloud<typename
> PointT>::Ptr pc)
>
> template<typename PointT>
> void addOne(pcl::PointCloud<PointT>::Ptr pc)
> {
>      for (int i = 0;i<pc->size();i++)
>          pc->points[i].x++;
> }
>
> with the following compiler error:
> error: expected ')' before 'pc'  void addOne(pcl::PointCloud<PointT>::Ptr
> pc)
>
> template<typename T>
> void addOne(pcl::PointCloud<T>::Ptr pc)
> {
>      for (int i = 0;i<pc->size();i++)
>          pc->points[i].x++;
> }
> with the following compiler error:
> error: expected ')' before 'pc' void addOne(pcl::PointCloud<T>::Ptr pc)
>
>
>
> --
> View this message in context: http://www.pcl-users.org/Programming-generic-functions-for-point-clouds-tp4044676p4044678.html
> Sent from the Point Cloud Library (PCL) Users mailing list mailing list archive at Nabble.com.
> _______________________________________________
> [hidden email] / http://pointclouds.org
> http://pointclouds.org/mailman/listinfo/pcl-users

_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users