<br><br><div class="gmail_quote">2008/7/11 Gonsolo <<a href="mailto:gonsolo@gmail.com">gonsolo@gmail.com</a>>:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi and thanks again for your help!<br>
<br>
Paul Harris schrieb:<div class="Ih2E3d"><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
node is whatever you store in the tree...<br>
<br>
so in this case its pretty easy<br>
<br>
struct not_me<br>
{<br>
shared_ptr<A> me;<br>
not_me(shared_ptr<A> m) : me(m) {}<br>
<br>
bool operator()( shared_ptr<A> const& n ) const { return n != me; }<br>
};<br>
</blockquote>
<br></div>
I managed to write a reduced testcase:<br>
<br>
#include "kdtree++/kdtree.hpp"<br>
#include "boost/shared_ptr.hpp"<br>
<br>
class Point<br>
{<br>
float v[3];<br>
public:<br>
float operator[]( int k ) {<br>
assert( k >= 0 && k < 3 );<br>
return v[k];<br>
}<br>
};<br>
<br>
class A<br>
{<br>
Point p;<br>
public:<br>
typedef boost::shared_ptr<A> ptr;<br>
Point getP() { return p; }<br>
};<br>
</blockquote><div><br><br>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; };<br>
<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
typedef KDTree::KDTree<3, A::ptr, std::pointer_to_binary_function< A::ptr,int,double> > kdtree;<br>
inline double tac( A::ptr s, int k ) { return s->getP()[k]; }<br>
</blockquote><div><br><br>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 ?<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
struct not_me<br>
{<br>
A::ptr me;<br>
not_me( A::ptr m ) : me( m ) {}<br>
bool operator()( A::ptr const & n ) const { return n != me; }<br>
};<br>
<br>
kdtree::iterator findNearest( kdtree & tree, kdtree::iterator it )<br>
{<br>
A::ptr tmp = *it;<br>
float mmax = std::numeric_limits<float>::max();<br>
kdtree::const_iterator found = tree.find_nearest_if( tmp, mmax, not_me( tmp ) ).first;<br>
assert( it != found );<br>
return found;<br>
}<br>
<br>
<br>
<br>
and compiling with<br>
<br>
g++ -I. -c tmp.cc<br>
<br>
<br>
the following error occurs (german, sorry):<br>
<br>
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> > >]«:<br>
tmp.cc:36: instantiated from here<br>
kdtree++/kdtree.hpp:494: Fehler: keine Übereinstimmung für Aufruf von »(not_me) (const KDTree::_Node<boost::shared_ptr<A> >*)«<br>
tmp.cc:29: Anmerkung: Kandidaten sind: bool not_me::operator()(const boost::shared_ptr<A>&) const<br>
<br>
</blockquote><div><br>well I can't read the uberestrumming bit, but it looks like you just need to adjust the method signature to match.<br><br>
struct not_me<br>
{<br>
shared_ptr<A> me;<br>
not_me(shared_ptr<A> m) : me(m) {}<br>
<br>
bool operator()( kdtree::Node< shared_ptr<A> > const& n ) const { return n != me; }<br>or<br>
bool operator()( shared_ptr<A> const* n ) const { return *n != me; }<br>};<br>
<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
<br>
It seems that the method _M_get_root in kdtree.hpp:494 returns a pointer whereas we expect a const &.<br>
Do you see some light here?<br><font color="#888888">
</font></blockquote><div><br><br>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.<br>
</div></div><br>cheers<br>Paul<br><br>