Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] dD Spatial Searching using arbitrary keys

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] dD Spatial Searching using arbitrary keys


Chronological Thread 
  • From: "developer" <>
  • To:
  • Subject: Re: [cgal-discuss] dD Spatial Searching using arbitrary keys
  • Date: Tue, 10 May 2016 10:33:11 -0500
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None ; spf=None ; spf=None
  • Ironport-phdr: 9a23:JPJUGRTyQzUNcsjmuuv+pifE4Npsv+yvbD5Q0YIujvd0So/mwa65ZBaN2/xhgRfzUJnB7Loc0qyN4/GmADBLscbJmUtBWaIPfidNsd8RkQ0kDZzNImzAB9muURYHGt9fXkRu5XCxPBsdMs//Y1rPvi/6tmZKSV3BPAZ4bt74BpTVx5zukbviqtuKP04Y1HKUWvBbElaflU3prM4YgI9veO4a6yDihT92QdlQ3n5iPlmJnhzxtY+a9Z9n9DlM6bp6r5YTGZPTJfVlCOQIRHR7ayFmrPHs4BLMRA/K6noHWXgNiTJJBRLE5Vf0RMTLvzP+p9Z6jWOWMNP7SbcsVC7op/NnRQHljCAfOiQR7Gzcis12kKlc5hmmokos7ZTTZdTfOPdgc6faZd4ADyIVUstPWihGGo6mR5cCBOoAO/pTqM/2oF5Y/kj2PhWlGO66kmwAvXTxx6Bvjrws

I had modified example 3.6.3 to use std::map::insert instead of std::map::operator[] but the net effect is the same.
 
The sample below with key values of 10 through 15 produces erroneous results. If you change the key values to 0, 1, 2, 13, 14, 15 it also generates the wrong results. Only key values of 0 through 5 produce the correct results.
 
My expectation was that any key value should work not just continuous integers starting at zero.
 
Thank you,
Michael

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Search_traits_3.h>
#include <CGAL/Search_traits_adapter.h>
#include <CGAL/point_generators_3.h>
#include <CGAL/Orthogonal_k_neighbor_search.h>
#include <boost/iterator/counting_iterator.hpp>
#include <utility>
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::Point_3 Point_3;
typedef std::size_t Point;
typedef boost::const_associative_property_map<std::map<Point,Point_3> > My_point_property_map;
 
typedef CGAL::Search_traits_3<Kernel> Traits_base;
typedef CGAL::Search_traits_adapter<Point,My_point_property_map,Traits_base> Traits;
typedef CGAL::Orthogonal_k_neighbor_search<Traits> K_neighbor_search;
typedef K_neighbor_search::Tree Tree;
typedef Tree::Splitter Splitter;
typedef K_neighbor_search::Distance Distance;
int main() {
  const unsigned int K = 5;

  std::map<Point,Point_3> points;
 
  points.insert(std::pair<Point,Point_3>(10,Point_3(82.446, 1.432, -98.438)));
  points.insert(std::pair<Point,Point_3>(11,Point_3(82.059, 1.602, -98.052)));
  points.insert(std::pair<Point,Point_3>(12,Point_3(82.059, 1.547, -98.469)));
  points.insert(std::pair<Point,Point_3>(13,Point_3(82.059, 1.384, -98.858)));
  points.insert(std::pair<Point,Point_3>(14,Point_3(82.446, 1.433, -97.665)));
  points.insert(std::pair<Point,Point_3>(15,Point_3(82.059, 1.385, -97.246)));

  My_point_property_map ppmap(points);
  // Insert number_of_data_points in the tree
  Tree tree(
    boost::counting_iterator<std::size_t>(0),
    boost::counting_iterator<std::size_t>(points.size()),
    Splitter(),
    Traits(ppmap)
  );
  Point_3 query(83.059, 1.384, -98.858);
  Distance tr_dist(ppmap);
  // search K nearest neighbours
  K_neighbor_search search(tree, query, K,0,true,tr_dist);
  for(K_neighbor_search::iterator it = search.begin(); it != search.end(); it++){
    std::cout << " d(q, nearest neighbor)=  "
          << tr_dist.inverse_of_transformed_distance(it->second) << " "
              << points[it->first] << " " << it->first << std::endl;
  }
  return 0;
}


> -------Original Message-------
> From: Sebastien Loriot (GeometryFactory) <>
> To:
> Subject: Re: [cgal-discuss] dD Spatial Searching using arbitrary keys
> Sent: 10 May '16 02:42
>
> Do you have a minimal compilable example showing what you tried and did
> not work?
>
> Sebastien.
>
> On 05/10/2016 01:03 AM, developer wrote:
> > I am attempting to use the dD spatial searching module using the example code in section 3.6.3 (v4.8) as a starting point:
> > http://doc.cgal.org/latest/Spatial_searching/Spatial_searching_2searching_with_point_with_info_pmap_8cpp-example.html
> >
> > The data set I'm working with has point ID's (the map key) that do not start at zero and are not continuous. However the K_neighbor_search function outputs incorrect results for a std::map with integer keys that non continuous and/or do not start at zero.
> >
> > How can I use arbitrary integer keys with the K_neighbor_search function? Is the only way to create two maps, one with continuous keys for use in the K_neighbor_search and a second to act as a lookup table for the actual point ID's?
> >
> > Thanks,
> > Michael
> >
>
>
> --
> 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.18.

Top of Page