C++ in PointCloud library: No matching function to call to

so I have this code in which I am trying to use the pointcloud library to match some descriptors I previously computed with other ones:

pcl::KdTreeFLANN<pcl::Narf36> matching = new pcl::KdTreeFLANN<pcl::Narf36>(false);
pcl::KdTree<pcl::Narf36>::PointCloudConstPtr ptr_narf_descriptors(&narf_descriptors);
matching.setInputCloud(ptr_narf_descriptors,NULL);

std::vector<int> correspondence;

// Check every descriptor computed for the scene.
for (size_t i = 0; i < narf_descriptors2.size(); ++i)
{
    std::vector<int> neighbors(1);
    std::vector<float> squaredDistances(1);
    // Ignore NaNs.
    if (pcl_isfinite(narf_descriptors2.at(i).descriptor[0]))
    {
        // Find the nearest neighbor (in descriptor space)...
        int neighborCount = matching.nearestKSearch(narf_descriptors2.at(i), 1, neighbors, squaredDistances);
        // ...and add a new correspondence if the distance is less than a threshold
        // (SHOT distances are between 0 and 1, other descriptors use different metrics).
        if (neighborCount == 1 && squaredDistances[0] < 0.25f)
        {
            //correspondence.push_back(neighbors[0], static_cast<int>(i), squaredDistances[0]);
            correspondence.push_back(neighbors[0]);
        }
    }
}

But compilator (make) says:

/home/adrian/PointCloudComparator/src/comparator.cpp: In function ‘void processNARF(std::string, std::string)’:
/home/adrian/PointCloudComparator/src/comparator.cpp:270:50: error: no 
matching function for call to ‘pcl::KdTreeFLANN<pcl::Narf36>::setInputCloud(pcl::KdTree<pcl::Narf36>::PointCloudConstPtr&, NULL)’
matching.setInputCloud(ptr_narf_descriptors,NULL);
                                              ^
/home/adrian/PointCloudComparator/src/comparator.cpp:270:50: note: candidate is:
 In file included from /usr/include/pcl-1.7/pcl/search/kdtree.h:44:0,
             from /usr/include/pcl-1.7/pcl/search/pcl_search.h:44,
             from /usr/include/pcl-1.7/pcl/features/impl/feature.hpp:44,
            from /usr/include/pcl-1.7/pcl/features/feature.h:498,
            from /usr/include/pcl-1.7/pcl/features/range_image_border_extractor.h:42,
             from /home/adrian/PointCloudComparator/src/comparator.cpp:9:
/usr/include/pcl-1.7/pcl/kdtree/kdtree_flann.h:146:7: note: 
void pcl::KdTreeFLANN<PointT, Dist>::setInputCloud(const PointCloudConstPtr&, const IndicesConstPtr&) [with PointT = pcl::Narf36; Dist = flann::L2_Simple<float>; pcl::KdTreeFLANN<PointT,
 Dist>::PointCloudConstPtr = boost::shared_ptr<const 
pcl::PointCloud<pcl::Narf36> >; pcl::KdTreeFLANN<PointT, 
Dist>::IndicesConstPtr = boost::shared_ptr<const std::vector<int> >]
   setInputCloud (const PointCloudConstPtr &cloud, const 
IndicesConstPtr &indices = IndicesConstPtr ());
   ^
                                      ^
make[2]: *** [CMakeFiles/comparator.dir/src/comparator.cpp.o] Error 1
make[1]: *** [CMakeFiles/comparator.dir/all] Error 2
make: *** [all] Error 2

Which is a bit weird since in the class kdtree_Flann the definition of the function is:

 /** \brief Provide a pointer to the input dataset.
    * \param[in] cloud the const boost shared pointer to a PointCloud message
    * \param[in] indices the point indices subset that is to be used from \a cloud - if NULL the whole cloud is used
    */
  void 
  setInputCloud (const PointCloudConstPtr &cloud, const IndicesConstPtr &indices = IndicesConstPtr ());

Is it me that I am writing the code wrong? Or is it the compilator which does not know where the actual function definition should come from?

Thanks and regards!


Working code - for version 1.7 of PCL library:

pcl::KdTreeFLANN<pcl::Narf36> matching = new pcl::KdTreeFLANN<pcl::Narf36>(false);
pcl::KdTree<pcl::Narf36>::PointCloudConstPtr ptr_narf_descriptors(&narf_descriptors);
matching.setInputCloud(ptr_narf_descriptors);

std::vector<int> correspondence;

Upvotes: 2

Views: 4431

Answers (1)

k.v.
k.v.

Reputation: 1223

You declared std::vector<int> correspondence(); - compiler treats it as function forward declaration.

If you want to define variable - define it without () in the end:

std::vector<int> correspondence;

Second problem is that you pass NULL as an argument which appear to be of type boost::shared_ptr. NULL is a C-style macros (see http://www.cplusplus.com/reference/cstddef/NULL/?kw=NULL) and it's not possible to construct boost::shared_ptr (and std:: smart pointers also) from it.

Replace NULL with nullptr (or with boost::shared_ptr<const std::vector<int> >()) and compiler will be able to construct boost::shared_ptr from that value.

Upvotes: 1

Related Questions