Skip to Content.
Sympa Menu

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

Subject: CGAL users discussion list

List archive

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


Chronological Thread 
  • From: Yaoyu Hu <>
  • To:
  • Subject: Re: [cgal-discuss] Fwd: How to do the nearest neighbor search on a Point_set_3 with properties
  • Date: Sun, 6 Mar 2022 12:46:58 -0500
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None ; spf=Pass ; spf=None
  • Ironport-data: A9a23:ahgyI68AMhFoCRE186E3DrUDvXiTJUtcMsCJ2f8bNWPcYEJGY0x3z 2pLCmiFO6mKMWTyeo9xPN7n8RsF7ZaBmNRqHlFk+ClEQiMRo6IpJ/zJdxaqZ3v6wu7rFR88s Z1GMrEsCOhuExcwcz/0auCJQUFUjP3OHvylYAL9EngZqTVMEU/Nsjo+3b9h6mJUqYLhWVnV4 ous+5e31GKNglaYDEpEs8pvlzs05JweiBtA1rDpTa0jUPf2zhH5PbpHTU2DByOQrrp8QoZWc 93+IISRpQs1yfuC5uSNyd4XemVSKlLb0JPnZnB+A8BOiTAazsA+PzpS2Pc0MS9qZzu1c99Z+ e8TtJO+cTUTAZbImfwaYgRXAThiFPgTkFPHCSDXXc27ykTHdz70wawrAh1qe4If/elzDCdF8 vlwxDIlNEjSwbLrhujiFK8w2qzPL+GzVG8bknF93DjeHOt/EMCda6rP7N5cmjw3g6iiGN6EO 5RFMWo3NXwsZTVfCFs4NrkUxdu6g1evKC9c+E6T/5E4tj27IAtZieCxarI5YOeiTspcmgOUp 3nN4n/iKgoLMcSWjzuD6HOlwOHV9R4XQ6oXHby8s+Zo2RidmjBVBxoRWl+25/K+jyZSRu6zN WQlwHQvoqYKxnaUdd38RxqJvXGWpwI1Do84//IB1CmBza/d4gC8D2cCTyJcZNFOiCPQbWx1v rNut4O5bQGDoIF5WlrGqejJ9WLa1Tw9aD5dNXVdHGPp9vG6+Nlr5i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RuQe3v GPRE1LyNzOSimC4B06HPuRFjSXdNxtb8tLYEF4lGS34QdTqZwfuesdwliEzyKYoi2niMGcdN X1kcRoIoOHMqyxfhfp7FipK6X8vfozm026JquLfLJgRq/5iBC95wvlb7HoNwLxQ9ChYRfZxl UM6S/Zhplinlq+EzT81CHKmRR5EgYuKuQNpPqCLr/GouF7B9RMJqH2SUlEE+4cjBdrotKRdj NPIkfCrQAo=
  • Ironport-sdr: 7EtEH6FRUTYcVsQN6iQ479SB/d6JPGRKaJFblEuL2ZfDmvqht4IGy+PLwvD2q2AU0wyQCDQtBW SCYi6ouZl8cPLsuxpczcEP70kHaqfr3f4HvUoYKAYwZjPM3cOq5F0zl9eirYgq+vPKLEJd2gIR p/lGHfI55vZPqARKgB+FANsvihUmjvoJPbNyezK1LJzP5BEzFu+Ng4/yIR5xbtyg6JyNJfruxI FBGa3S9EXBE2XROUNcMTdedYP/5cvEFT4OtZ1+YFPtKdLBY3B9nbUf0W2cWOu2VAmiw3BGewsB tRc9XdySzbZW3ifTH4YOc7LB

Hi Sebastien,

In my sample code, I set up a point cloud with 10 points. Their coordinates have a range from [ 0, 0, 0 ] to [0.9, 0.9, 0.9]. Then I try to find the nearest point by using [0, 0, 0] as the query. But I got the result that point index 6 with coordinate [ 0.6, 0.6, 0.6 ] is the nearest one. In fact, no matter what query I use, I always get index 6 as the result. I must have done something wrong or misunderstood some details.

Thank you,

Yaoyu

On Fri, Mar 4, 2022 at 4:57 AM Sebastien Loriot <> wrote:
Could you please explain why you think there is a bug, with as assertion
for example?

Thanks,

Sebastien.

On 3/3/22 04:06, Yaoyu Hu ( via cgal-discuss
Mailing List) wrote:
> I was so dumb that the compiling error in my previous email is due to a
> typo.
>
> I have updated the sample code, now it compiles. Get the updated code here
> https://gist.github.com/huyaoyu/6bd9e6b54bc895b7fadebe3863456e92
> <https://gist.github.com/huyaoyu/6bd9e6b54bc895b7fadebe3863456e92>
>
> Now I have a new problem. If I run the code, I got the following
> outputs. It seems that the search does not work for me. I must have done
> something wrong.
>
> ========== Outputs. ==========
>
> Hello, test_point_set_nearest_neighbor!
> index = 0, point: [ 0 0 0 ], color: [ 100, 100, 100 ]
> index = 1, point: [ 0.1 0.1 0.1 ], color: [ 101, 101, 101 ]
> index = 2, point: [ 0.2 0.2 0.2 ], color: [ 102, 102, 102 ]
> index = 3, point: [ 0.3 0.3 0.3 ], color: [ 103, 103, 103 ]
> index = 4, point: [ 0.4 0.4 0.4 ], color: [ 104, 104, 104 ]
> index = 5, point: [ 0.5 0.5 0.5 ], color: [ 105, 105, 105 ]
> index = 6, point: [ 0.6 0.6 0.6 ], color: [ 106, 106, 106 ]
> index = 7, point: [ 0.7 0.7 0.7 ], color: [ 107, 107, 107 ]
> index = 8, point: [ 0.8 0.8 0.8 ], color: [ 108, 108, 108 ]
> index = 9, point: [ 0.9 0.9 0.9 ], color: [ 109, 109, 109 ]
> Found nearest point of 0 0 0:
> index = 6, distance = 0, point: [0.6 0.6 0.6 ]
> color = [ 106, 106, 106 ]
>
> ========== Outputs end. ==========
>
> Any help is appreciated.
>
> Thank you!
>
> Yaoyu
>
> ---------- Forwarded message ---------
> From: *Yaoyu Hu* < <mailto:>>
> Date: Wed, Mar 2, 2022 at 6:07 PM
> Subject: How to do the nearest neighbor search on a Point_set_3 with
> properties
> To: < <mailto:>>
>
>
> 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
> <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
> <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
>
> --
> You are currently subscribed to cgal-discuss.
> To unsubscribe or access the archives, go to
> https://sympa.inria.fr/sympa/info/cgal-discuss
>

--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://sympa.inria.fr/sympa/info/cgal-discuss





Archive powered by MHonArc 2.6.19+.

Top of Page