Note that there are some explanatory texts on larger screens.

plurals
  1. POGeneralized (non-slicing) pointer to templated tree nodes? (C++)
    text
    copied!<p>I'm working on an octree implementation where the tree nodes are templated with their dimensional length (as a power of 2):</p> <pre><code>template&lt;long N&gt; struct node_t { enum { DIM = 1 &lt;&lt; N }; node_t&lt;N+1&gt; * parent; node_t&lt;N-1&gt; * children[8]; long count; } </code></pre> <p>And specialized for N = 0 (leaves) to point to data.</p> <pre><code>struct node_t&lt;0&gt; { enum { DIM = 1 }; node_t&lt;1&gt; * parent; data_t data; long count; } </code></pre> <p>(<strong>Aside:</strong> I suppose I probably also need a specialization for N_MAX that excludes a parent pointer, or else C++ will generate types of increasing N ad finitum? But that's not really relevant to my question.)</p> <p>I'd like to create a function that steps along a ray in the 3D space that my octree occupies, so ostensibly I could just keep a pointer to the root node (which has a known type) and traverse the octree from the root at every step. However, I would prefer a more 'local' option, in which I can keep track of the current node so that I can start lower in the tree when possible and thus avoid unnecessarily traversing the upper nodes of the octree.</p> <p>But I don't know what that type pointer could be (or any other way of implementing this) so that I don't experience slicing.</p> <p>I'm not tied down to templates, as the dimension can simply be implemented as a <code>long const</code>. But then I don't know how to make it so that the leaves have a different child type than inodes.</p> <p>Thanks for your help!</p> <h2>Update</h2> <p>The reason I'd like to do it this way rather than something similar to <a href="https://stackoverflow.com/questions/6281415/octree-raycasting-raytracing-best-ray-leaf-intersection-without-recursion?rq=1">this</a> is because of the <code>count</code> variable in each node: if the count is 0, I'd like to jump through the whole cube, rather wasting time going through leaves that I know to be empty. (This is for a raytracing voxel engine.)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload