<br><br><div class="gmail_quote">2008/7/11 Gonsolo &lt;<a href="mailto:gonsolo@gmail.com">gonsolo@gmail.com</a>&gt;:<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&lt;A&gt; me;<br>
&nbsp;not_me(shared_ptr&lt;A&gt; m) : me(m) {}<br>
<br>
&nbsp;bool operator()( shared_ptr&lt;A&gt; const&amp; n ) const { return n != me; }<br>
};<br>
</blockquote>
<br></div>
I managed to write a reduced testcase:<br>
<br>
#include &quot;kdtree++/kdtree.hpp&quot;<br>
#include &quot;boost/shared_ptr.hpp&quot;<br>
<br>
class Point<br>
{<br>
 &nbsp; &nbsp; &nbsp; &nbsp;float v[3];<br>
public:<br>
 &nbsp; &nbsp; &nbsp; &nbsp;float operator[]( int k ) {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;assert( k &gt;= 0 &amp;&amp; k &lt; 3 );<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return v[k];<br>
 &nbsp; &nbsp; &nbsp; &nbsp;}<br>
};<br>
<br>
class A<br>
{<br>
 &nbsp; &nbsp; &nbsp; &nbsp;Point p;<br>
public:<br>
 &nbsp; &nbsp; &nbsp; &nbsp;typedef boost::shared_ptr&lt;A&gt; ptr;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;Point getP() { return p; }<br>
};<br>
</blockquote><div><br><br>note, i&#39;d be careful putting such a small bit of data behind a pointer.&nbsp; you might get greater performance by just copying around a POD&nbsp;&nbsp; struct simplepoint { boost::array&lt;float,3&gt; v; };<br>
<br>&nbsp;</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&lt;3, A::ptr, std::pointer_to_binary_function&lt; A::ptr,int,double&gt; &gt; kdtree;<br>
inline double tac( A::ptr s, int k ) { return s-&gt;getP()[k]; }<br>
</blockquote><div><br><br>note 2, using &#39;kdtree&#39; as a typedef is a recipe for confusion!&nbsp; maybe try PointTree or point_tree or point_kdtree or anything other than kdtree ?<br>&nbsp;</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>
 &nbsp; &nbsp; &nbsp; &nbsp;A::ptr me;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;not_me( A::ptr m ) : me( m ) {}<br>
 &nbsp; &nbsp; &nbsp; &nbsp;bool operator()( A::ptr const &amp; n ) const { return n != me; }<br>
};<br>
<br>
kdtree::iterator findNearest( kdtree &amp; tree, kdtree::iterator it )<br>
{<br>
 &nbsp; &nbsp; &nbsp; &nbsp;A::ptr tmp = *it;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;float mmax = std::numeric_limits&lt;float&gt;::max();<br>
 &nbsp; &nbsp; &nbsp; &nbsp;kdtree::const_iterator found = tree.find_nearest_if( tmp, mmax, not_me( tmp ) ).first;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;assert( it != found );<br>
 &nbsp; &nbsp; &nbsp; &nbsp;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&lt;KDTree::_Iterator&lt;_Val, const _Val&amp;, const _Val*&gt;, typename _Dist::distance_type&gt; KDTree::KDTree&lt;__K, _Val, _Acc, _Dist, _Cmp, _Alloc&gt;::find_nearest_if(const _Val&amp;, const typename _Dist::distance_type&amp;, _Predicate) const [with _Predicate = not_me, unsigned int __K = 3u, _Val = boost::shared_ptr&lt;A&gt;, _Acc = std::pointer_to_binary_function&lt;boost::shared_ptr&lt;A&gt;, int, double&gt;, _Dist = KDTree::squared_difference&lt;double, double&gt;, _Cmp = std::less&lt;double&gt;, _Alloc = std::allocator&lt;KDTree::_Node&lt;boost::shared_ptr&lt;A&gt; &gt; &gt;]«:<br>

tmp.cc:36: &nbsp; instantiated from here<br>
kdtree++/kdtree.hpp:494: Fehler: keine Übereinstimmung für Aufruf von »(not_me) (const KDTree::_Node&lt;boost::shared_ptr&lt;A&gt; &gt;*)«<br>
tmp.cc:29: Anmerkung: Kandidaten sind: bool not_me::operator()(const boost::shared_ptr&lt;A&gt;&amp;) const<br>
<br>
</blockquote><div><br>well I can&#39;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&lt;A&gt; me;<br>
&nbsp;not_me(shared_ptr&lt;A&gt; m) : me(m) {}<br>
<br>
&nbsp;bool operator()( kdtree::Node&lt; shared_ptr&lt;A&gt; &gt; const&amp; n ) const { return n != me; }<br>or<br>&nbsp;

bool operator()( shared_ptr&lt;A&gt; const* n ) const { return *n != me; }<br>};<br>

<br>&nbsp;</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 &amp;.<br>
Do you see some light here?<br><font color="#888888">
</font></blockquote><div><br><br>like I said, i&#39;ve given the basics, please adjust to suit and then let me know the correct way.&nbsp; My kdtree might be slightly different than yours so I can&#39;t be certain, and its been a while since I&#39;ve directly used it.<br>
</div></div><br>cheers<br>Paul<br><br>