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: "Sebastien Loriot (GeometryFactory)" <>
  • To:
  • Subject: Re: [cgal-discuss] dD Spatial Searching using arbitrary keys
  • Date: Tue, 10 May 2016 17:39:20 +0200
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None ; spf=Pass ; spf=None
  • Ironport-phdr: 9a23:fAyU1B17WNG2mtadsmDT+DRfVm0co7zxezQtwd8ZsegRIvad9pjvdHbS+e9qxAeQG96LurQd16GG4+jJYi8p39WoiDg6aptCVhsI2409vjcLJ4q7M3D9N+PgdCcgHc5PBxdP9nC/NlVJSo6lPwWB6kO74TNaIBjjLw09fr2zQd6DyZ3rnLDis7ToICx2xxOFKYtoKxu3qQiD/uI3uqBFbpgL9x3Sv3FTcP5Xz247bXianhL7+9vitMU7q3cYjdt7ppMFCfWyP/lgDO8QMDNzOG884IjntALIUBCUznoaSGQf1BRSUCbf6xSvFKz8uCLhqutw3mG+Otf3Sqx8GRuv6KJmVAX5pi4MKzkj4SCdwphriKVBoRW94Rl764HRaYCRcvF5e/WOLpshWWNdU5MJBGR6CYSmYt5SV+c=
  • Organization: GeometryFactory

you must insert in the tree only the keys you have used.

In your examples you are inserting keys 0, 1, 2, 3, 4 and 5.

Try:
> Tree tree(
> boost::counting_iterator<std::size_t>(10),
> boost::counting_iterator<std::size_t>(10+points.size()),
> Splitter(),
> Traits(ppmap)
> );

Sebastien.

On 05/10/2016 05:33 PM, developer wrote:
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