Skip to Content.
Sympa Menu

cgal-discuss - [cgal-discuss] Samples Spatial Searching, combining Custom distance with property maps

Subject: CGAL users discussion list

List archive

[cgal-discuss] Samples Spatial Searching, combining Custom distance with property maps


Chronological Thread 
  • From: "Daniel S." <>
  • To:
  • Subject: [cgal-discuss] Samples Spatial Searching, combining Custom distance with property maps
  • Date: Tue, 6 Nov 2012 08:22:29 -0800 (PST)

Dear CGAL Users,

atm I'm using cgal to do some nearest neighbour searching.

*Situation:*
Up to now I used the sample for property maps stated here:

http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Spatial_searching/Chapter_main.html

->61.3.6 Examples for Using an Arbitrary Point Type with Point Property
Maps
Using a Point and an Integer as Key Type

Meanwhile I need to define my own metric/point and use it in the kd-Tree. So
I try to combine the sample stated above with the example, also on this
page, for

61.3.5 Example for User Defined Point and Distance Class

*Problem:* If i use the kd Tree, it doesn't recognized, that the input are
boost tuples (or he actually doesn't use the map ?)it throws following
error:

error C2664: 'double Distance::transformed_distance(const Point &,const
Point &) const':
Converting Parameter 2 from 'const boost::tuples::tuple<T0,T1>' in 'const
Point &'
not possible C:\CGAL-4.0.2\include\CGAL\K_neighbor_search.h 120

a little "work around" is, to wirte a function in distance.h that accepts
tuples and knows, that the first parameter is the point. But this is
certainly not the way to go. As it doesn't help with the rest tuple entries.

*Following my simple code sample:*

#include <experimental/motionPlanning2/TestingClasses/distance.h>

typedef boost::tuple<Point,int> Point_and_int;

//definition of the property map
struct My_point_property_map{
typedef Point value_type;
typedef const value_type& reference;
typedef const Point_and_int& key_type;
typedef boost::readable_property_map_tag category;
};

//get function for the property map
My_point_property_map::reference
get(My_point_property_map,My_point_property_map::key_type p)
{return boost::get<0>(p);}

typedef CGAL::Search_traits<double, Point, const double*,
Construct_coord_iterator> Traits_base;
typedef
CGAL::Search_traits_adapter<Point_and_int,My_point_property_map,Traits_base>

Traits;
typedef CGAL::K_neighbor_search<Traits, Distance>

K_neighbor_search;
typedef K_neighbor_search::Tree Tree;
typedef K_neighbor_search::Distance DistanceD;

class kdTreeTest3 {
public:
static void testIt();
};

void kdTreeTest3::testIt(){
const int D = 7;//set dimension
const double bound = 1.0;//and bounds;
const unsigned int K = 1;
CGAL::Random random;
Tree tree;

Point q1(1.0,1.0,1.0,1.0,0.0,0.0,0.0);
Point q2(0.5,0.5,0.5,0.0,0.0,0.0,1.0);

tree.insert(boost::make_tuple(q1,1));
tree.insert(boost::make_tuple(q2,2));

Point query(0.5, 0.5, 0.5,1.0,0.0,0.0,0.0);
DistanceD tr_dist;

// search K nearest neighbours
K_neighbor_search search(tree, query, K);
for(K_neighbor_search::iterator it = search.begin(); it != search.end();
it++){
std::cout << " d(q, nearest neighbor)=
"<<std::endl&lt;&lt;boost::get&lt;0>(it->first)<<"with "
<< tr_dist.transformed_distance(it->second) << std::endl;

}
// search K furthest neighbour searching, with eps=0, search_nearest=false
K_neighbor_search search2(tree, query, K, 0.0, false);

for(K_neighbor_search::iterator it = search2.begin(); it != search2.end();
it++){
std::cout << " d(q, furthest neighbor)=
"<<std::endl&lt;&lt;boost::get&lt;0>(it->first)<<"with "
<< tr_dist.transformed_distance(it->second) << std::endl;
}
}
//end code

I would really appreciate some help, as im stuck on this problem. Thanks in
advance.

Greets from Germany
Daniel



--
View this message in context:
http://cgal-discuss.949826.n4.nabble.com/Samples-Spatial-Searching-combining-Custom-distance-with-property-maps-tp4656160.html
Sent from the cgal-discuss mailing list archive at Nabble.com.



Archive powered by MHonArc 2.6.18.

Top of Page