Subject: CGAL users discussion list
List archive
Re: [cgal-discuss] Samples Spatial Searching, combining Custom distance with property maps
Chronological Thread
- From: "Sebastien Loriot (GeometryFactory)" <>
- To:
- Subject: Re: [cgal-discuss] Samples Spatial Searching, combining Custom distance with property maps
- Date: Thu, 08 Nov 2012 09:01:21 +0100
- Organization: GeometryFactory
As written here [1], when using search_traits_adapter Point_d is Key.
Thus the distance must operate on the tuple as the error message state.
From here [2], you have a guess of what you must use:
"Expects for the second template argument a model of the concept GeneralDistance. If Traits is CGAL::Search_traits_adapter<Key,PointPropertyMap,BaseTraits> the default type is CGAL::Distance_for_point_adapter<Key,PointPropertyMap,CGAL::Euclidean_distance<Traits> >, and CGAL::Euclidean_distance<Traits> otherwise."
So CGAL::Distance_for_point_adapter is what you were looking for.
Sebastien.
[1] http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Spatial_searching_ref/Class_Search_traits_adapter.html
[2] http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Spatial_searching_ref/Class_K_neighbor_search.html
[3] http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Spatial_searching_ref/Class_Distance_for_point_adapter.html
On 11/06/2012 05:22 PM, Daniel S. wrote:
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<<boost::get<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<<boost::get<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.
- [cgal-discuss] Samples Spatial Searching, combining Custom distance with property maps, Daniel S., 11/06/2012
- Re: [cgal-discuss] Samples Spatial Searching, combining Custom distance with property maps, Sebastien Loriot (GeometryFactory), 11/08/2012
- [cgal-discuss] Re: Samples Spatial Searching, combining Custom distance with property maps, Daniel S., 11/08/2012
- Re: [cgal-discuss] Re: Samples Spatial Searching, combining Custom distance with property maps, Sebastien Loriot (GeometryFactory), 11/08/2012
- [cgal-discuss] Re: Samples Spatial Searching, combining Custom distance with property maps, Daniel S., 11/12/2012
- Re: [cgal-discuss] Re: Samples Spatial Searching, combining Custom distance with property maps, Sebastien Loriot (GeometryFactory), 11/12/2012
- [cgal-discuss] Re: Samples Spatial Searching, combining Custom distance with property maps, Daniel S., 11/12/2012
- Re: [cgal-discuss] Re: Samples Spatial Searching, combining Custom distance with property maps, Sebastien Loriot (GeometryFactory), 11/08/2012
- [cgal-discuss] Re: Samples Spatial Searching, combining Custom distance with property maps, Daniel S., 11/08/2012
- Re: [cgal-discuss] Samples Spatial Searching, combining Custom distance with property maps, Sebastien Loriot (GeometryFactory), 11/08/2012
Archive powered by MHonArc 2.6.18.