Skip to Content.
Sympa Menu

cgal-discuss - [cgal-discuss] How to do the nearest neighbor search on a Point_set_3 with properties

Subject: CGAL users discussion list

List archive

[cgal-discuss] How to do the nearest neighbor search on a Point_set_3 with properties


Chronological Thread 
  • From: Yaoyu Hu <>
  • To:
  • Subject: [cgal-discuss] How to do the nearest neighbor search on a Point_set_3 with properties
  • Date: Wed, 2 Mar 2022 18:07:49 -0500
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None ; spf=Pass ; spf=None
  • Ironport-data: A9a23:sfkhw6IbMHXuxEs1FE+R45MlxSXFcZb7ZxGr2PjKsXjdYENS0D0Am 2QaX27TP/3YNDHzKt9za9y0pE8CscWEyNJiHgMd+CA2RRqmi+KVXIXDdh+Y0wC6d5CYEho/t 63yTvGacajYm1eF/k/F3oDJ9CU6jefRLlbFILas1hpZHGeIcw98z0M78wIFqtQw24LhWFvX4 Y+aT/D3YTdJ5RYkagr41IrY8HuDjNyq0N/PlgFWiVhj5TcyplFNZH4tDfnZw0jQHuG4KtWHq 9Prl9lVyI92EyAFUbtJmp6jGqEDryW70QKm0hK6UID66vROS7BbPqsTbJIhhUlrZzqhw994y +RxpJWKTQ4ULJf0mck+DSUfDHQrVUFG0OevzXmXtMWSywjecSKpzakzSk4xOoIc96B8BmQmG f4wcmhcKEDewbjvnvTnF4GAhex7RCXvFIMCq3hn3CyAXKZ4aZ/GSqTOo9Rf2V/cg+gRQaqBP JNIAdZpRBvwW15yOEpGM9EFu/uZi3rVKyFCgXvA8MLb5ECKlFAruFT3C/LeddWOAMlUhU2Fv Xnu5HX8GhhcNdqFyDPD/GjEuwPUtSbyWYZXDL/hs/A23RucwWscDBBQXly+yRWktqKgc45QI k8lxjsnl6w7yV6RdtjQfEOE52HR63bwROFsO+E97QiMzI/d7ACYGnUIQ1Z9hDoO5J9eqdsCh g/hoj/5OdB8mObKFi/Fp994uRv3aHdFdzZTDcMRZVJdu4GLnW0lsv7Yoj9e/EOdi9T0HXTow WnPonRjwboUisEP2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i9ZN3jYxy/dtRwiHdlpN98zmOPLmMaP TVmJglVqaaM6CpDnvhlM2lI734gNevd3ijFsq/XLZEZtfYtCSNx3bE/gjxy2/5e6ydKQ+Zwk S3Zo4t1ol2opeKIzyJuTBtErjsjbGOjuExjPeDB9MAFVyqZuh0K6mqUBlIBoN43UrUHVIhfz 9HOkOT4LzIQqro8GOMTAsHVLISMN39zaXLU
  • Ironport-sdr: ZURsEvrRd3WZ0Tczd6o+0DzAscEB8wrH+JwhD/RPypZKyOhCKnarbFgwqLAvzFlujbVB6zDz4w 7ko7vA+Bmi+2qrbBHzSyl8mIJPZBtgBFs25+3ImxNSOHA/BOD0n+O310WAgp/bUiJPnLXXVq7T ykIku4UwbzpgBmS+W7rSCfB9tRp6NBLozptvZubx3p8M8wDdA28ghsm8UHXxkuT7N/pmfJKPhl hgFxNupwDjOTjZd/3ZyYOFR8XwzRBtV8sUMi9sqfQUPcksMm8huZAp6iUnJ+Wk6V6zAjrdYmed 42iSKJCm/c97mC5jJUzx3jYQ

Hi,

On CGAL v5.4, Ubuntu 20.04, g++ 9.3.0.

I'm trying to do the nearest neighbor search on a Point_set_3 object by "dD Spatial Searching". The Point_set_3 has a property for point color. I am trying to follow the example "Using a Point Property Map of a Polygonal Mesh " https://doc.cgal.org/latest/Spatial_searching/index.html#Spatial_searchingUsingSurfaceMesh

The reason for referring to the above example is that I suppose points and colors are saved as property maps in Point_set_3 objects and I need to get the Index of a point from the Point_set_3 object, such that I can use the Index object to retrieve a color object saved in the property map. It looks like the relationship between mesh vertex descriptor and mesh point property.

I have two major questions based on my understanding of how Point_set_3 and "dD Spatial Searching " work:

(1) Do I need an explicit Point_set_3::Index value to be able to retrieve a property from a property_map of a Point_set_3 object? My current understanding is yes, I need to have a Point_set_3::Index value because the property_map is indexed by Point_set_3::Index objects.

(2) When doing a search by "dD Spatial Searching", if I want to have a Point_set_3::Index as the search result, I need to use things like CGAL::Search_traits_adapter such that the search tree will store Point_set_3::Index for me.

Based on the above thoughts, I have composed a sample code, which currently has some compile errors. I also created a GitHub gist if that is more convenient. 
https://gist.github.com/huyaoyu/6bd9e6b54bc895b7fadebe3863456e92

The compile error is shown after the code. The error says that CGAL::Search_traits_adapter needs three template arguments but I only give it one. I cannot understand why it gives this error since there are three template arguments already. I failed to proceed any further and I think it's better to ask for help from experts. I am also uncertain if my usage of "tree" and "search" is correct in the reset of the code.

Can someone help me to resolve the compile error and identify any other errors regarding "tree" and "search"? Thank you so much!

========== Code begins. ==========

#include <array>
#include <iostream>

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Point_set_3.h>

#include <CGAL/Orthogonal_k_neighbor_search.h>
#include <CGAL/Search_traits_3.h>
#include <CGAL/Search_traits_adapter.h>

template < typename CloudT, typename ColorMapT >
typename boost::property_traits<ColorMapT>::value_type nearest_color(
    const CloudT& cloud,
    const ColorMapT& color_map,
    const typename CloudT::Point_3& query) {
   
    typedef typename boost::property_traits<ColorMapT>::value_type Color_t;
   
    typedef typename CGAL::Kernel_traits<typename CloudT::Point_3>::Kernel CloudKernel_t;
    typedef CGAL::Search_traits_3<CloudKernel_t> SearchTraits_base_t;
    typedef CGAL::Search_traits_adapter<
        typename CloutT::Index,
        typename CloudT::Point_map,
        SearchTraits_base_t
    > SearchTraits_t;

    typedef CGAL::Orthogonal_k_neighbor_search<SearchTraits_t> CloudSearch_t;
    typedef CloudSearch_t::Tree                                CloudSearchTree_t;
    typedef CloudSearchTree_t::Splitter                        CloudSearchSplitter_t;
    typedef CloudSearch_t::Distance                            CloudSearchDistance_t;

    // Set up a search tree.
    CloudSearchTree_t tree(
        cloud.begin(), cloud.end(),
        CloudSearchSplitter_t(),
        SearchTraits_t( cloud.point_map() ) );

    // Search.
    CloudSearchDistance_t distance( cloud.point_map() );
    CloudSearch_t search( tree, query, 1, 0, true, distance );

    const auto& neighbor_point_index = search.begin()->first;
    auto& cloud_neighbor_color = color_map[neighbor_point_index];

    return cloud_neighbor_color;
}


int main(int argc, char** argv) {
    std::cout << "Hello, test_point_set_nearest_neighbor! \n";

    typedef std::array< unsigned char, 3 > Color_t;
    typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel_t;
    typedef Kernel_t::Point_3 Point_t;
    typedef CGAL::Point_set_3<Point_t> PointSet_t;

    PointSet_t cloud;

    auto [ color_map, flag_added ] = cloud.add_property_map<Color_t>("color");

    // Populate the point cloud with color.
    // Omitted.

    nearest_color( cloud, color_map, Point_t(0, 0, 0) );
   
    return 0;
}

========== Code ends. ==========

========== Compile error begins. ==========

src/test_point_set_nearest_neighbor.cpp: In function ‘typename boost::property_traits<IndexMap>::value_type nearest_color(const CloudT&, const ColorMapT&, const typename CloudT::Point_3&)’:
/ws/src/shimizu_test_reconstruct_surface/src/test_point_set_nearest_neighbor.cpp:26:5: error: wrong number of template arguments (1, should be 3)

(Later error messages are omitted.)

========== Compile error ends. ==========

Thank you!

Yaoyu



Archive powered by MHonArc 2.6.19+.

Top of Page