find_nearest_nth

Paul Harris paulharris at computer.org
Fri Jul 11 02:43:49 UTC 2008


2008/7/11 Gonsolo <gonsolo at gmail.com>:

> Hi and thanks again for your help!
>
> Paul Harris schrieb:
>
>> node is whatever you store in the tree...
>>
>> so in this case its pretty easy
>>
>> struct not_me
>> {
>> shared_ptr<A> me;
>>  not_me(shared_ptr<A> m) : me(m) {}
>>
>>  bool operator()( shared_ptr<A> const& n ) const { return n != me; }
>> };
>>
>
> I managed to write a reduced testcase:
>
> #include "kdtree++/kdtree.hpp"
> #include "boost/shared_ptr.hpp"
>
> class Point
> {
>        float v[3];
> public:
>        float operator[]( int k ) {
>                assert( k >= 0 && k < 3 );
>                return v[k];
>        }
> };
>
> class A
> {
>        Point p;
> public:
>        typedef boost::shared_ptr<A> ptr;
>        Point getP() { return p; }
> };
>


note, i'd be careful putting such a small bit of data behind a pointer.  you
might get greater performance by just copying around a POD   struct
simplepoint { boost::array<float,3> v; };



>
> typedef KDTree::KDTree<3, A::ptr, std::pointer_to_binary_function<
> A::ptr,int,double> > kdtree;
> inline double tac( A::ptr s, int k ) { return s->getP()[k]; }
>


note 2, using 'kdtree' as a typedef is a recipe for confusion!  maybe try
PointTree or point_tree or point_kdtree or anything other than kdtree ?


>
> struct not_me
> {
>        A::ptr me;
>        not_me( A::ptr m ) : me( m ) {}
>        bool operator()( A::ptr const & n ) const { return n != me; }
> };
>
> kdtree::iterator findNearest( kdtree & tree, kdtree::iterator it )
> {
>        A::ptr tmp = *it;
>        float mmax = std::numeric_limits<float>::max();
>        kdtree::const_iterator found = tree.find_nearest_if( tmp, mmax,
> not_me( tmp ) ).first;
>        assert( it != found );
>        return found;
> }
>
>
>
> and compiling with
>
> g++ -I. -c tmp.cc
>
>
> the following error occurs (german, sorry):
>
> kdtree++/kdtree.hpp: In member function »std::pair<KDTree::_Iterator<_Val,
> const _Val&, const _Val*>, typename _Dist::distance_type>
> KDTree::KDTree<__K, _Val, _Acc, _Dist, _Cmp, _Alloc>::find_nearest_if(const
> _Val&, const typename _Dist::distance_type&, _Predicate) const [with
> _Predicate = not_me, unsigned int __K = 3u, _Val = boost::shared_ptr<A>,
> _Acc = std::pointer_to_binary_function<boost::shared_ptr<A>, int, double>,
> _Dist = KDTree::squared_difference<double, double>, _Cmp =
> std::less<double>, _Alloc =
> std::allocator<KDTree::_Node<boost::shared_ptr<A> > >]«:
> tmp.cc:36:   instantiated from here
> kdtree++/kdtree.hpp:494: Fehler: keine Übereinstimmung für Aufruf von
> »(not_me) (const KDTree::_Node<boost::shared_ptr<A> >*)«
> tmp.cc:29: Anmerkung: Kandidaten sind: bool not_me::operator()(const
> boost::shared_ptr<A>&) const
>
>
well I can't read the uberestrumming bit, but it looks like you just need to
adjust the method signature to match.

struct not_me
{
shared_ptr<A> me;
 not_me(shared_ptr<A> m) : me(m) {}

 bool operator()( kdtree::Node< shared_ptr<A> > const& n ) const { return n
!= me; }
or
  bool operator()( shared_ptr<A> const* n ) const { return *n != me; }
};



>
>
> It seems that the method _M_get_root in kdtree.hpp:494 returns a pointer
> whereas we expect a const &.
> Do you see some light here?
>


like I said, i've given the basics, please adjust to suit and then let me
know the correct way.  My kdtree might be slightly different than yours so I
can't be certain, and its been a while since I've directly used it.

cheers
Paul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.alioth.debian.org/pipermail/libkdtree-devel/attachments/20080711/f053d2d1/attachment.htm 


More information about the libkdtree-devel mailing list