Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>For the record, this is my implementation of the Revelles paper I ended up using:</p> <pre><code>#include "octree_traversal.h" using namespace std; unsigned char a; // because an unsigned char is 8 bits int first_node(double tx0, double ty0, double tz0, double txm, double tym, double tzm){ unsigned char answer = 0; // initialize to 00000000 // select the entry plane and set bits if(tx0 &gt; ty0){ if(tx0 &gt; tz0){ // PLANE YZ if(tym &lt; tx0) answer|=2; // set bit at position 1 if(tzm &lt; tx0) answer|=1; // set bit at position 0 return (int) answer; } } else { if(ty0 &gt; tz0){ // PLANE XZ if(txm &lt; ty0) answer|=4; // set bit at position 2 if(tzm &lt; ty0) answer|=1; // set bit at position 0 return (int) answer; } } // PLANE XY if(txm &lt; tz0) answer|=4; // set bit at position 2 if(tym &lt; tz0) answer|=2; // set bit at position 1 return (int) answer; } int new_node(double txm, int x, double tym, int y, double tzm, int z){ if(txm &lt; tym){ if(txm &lt; tzm){return x;} // YZ plane } else{ if(tym &lt; tzm){return y;} // XZ plane } return z; // XY plane; } void proc_subtree (double tx0, double ty0, double tz0, double tx1, double ty1, double tz1, Node* node){ float txm, tym, tzm; int currNode; if(tx1 &lt; 0 || ty1 &lt; 0 || tz1 &lt; 0) return; if(node-&gt;terminal){ cout &lt;&lt; "Reached leaf node " &lt;&lt; node-&gt;debug_ID &lt;&lt; endl; return; } else{ cout &lt;&lt; "Reached node " &lt;&lt; node-&gt;debug_ID &lt;&lt; endl;} txm = 0.5*(tx0 + tx1); tym = 0.5*(ty0 + ty1); tzm = 0.5*(tz0 + tz1); currNode = first_node(tx0,ty0,tz0,txm,tym,tzm); do{ switch (currNode) { case 0: { proc_subtree(tx0,ty0,tz0,txm,tym,tzm,node-&gt;children[a]); currNode = new_node(txm,4,tym,2,tzm,1); break;} case 1: { proc_subtree(tx0,ty0,tzm,txm,tym,tz1,node-&gt;children[1^a]); currNode = new_node(txm,5,tym,3,tz1,8); break;} case 2: { proc_subtree(tx0,tym,tz0,txm,ty1,tzm,node-&gt;children[2^a]); currNode = new_node(txm,6,ty1,8,tzm,3); break;} case 3: { proc_subtree(tx0,tym,tzm,txm,ty1,tz1,node-&gt;children[3^a]); currNode = new_node(txm,7,ty1,8,tz1,8); break;} case 4: { proc_subtree(txm,ty0,tz0,tx1,tym,tzm,node-&gt;children[4^a]); currNode = new_node(tx1,8,tym,6,tzm,5); break;} case 5: { proc_subtree(txm,ty0,tzm,tx1,tym,tz1,node-&gt;children[5^a]); currNode = new_node(tx1,8,tym,7,tz1,8); break;} case 6: { proc_subtree(txm,tym,tz0,tx1,ty1,tzm,node-&gt;children[6^a]); currNode = new_node(tx1,8,ty1,8,tzm,7); break;} case 7: { proc_subtree(txm,tym,tzm,tx1,ty1,tz1,node-&gt;children[7^a]); currNode = 8; break;} } } while (currNode&lt;8); } void ray_octree_traversal(Octree* octree, Ray ray){ a = 0; // fixes for rays with negative direction if(ray.direction[0] &lt; 0){ ray.origin[0] = octree-&gt;size[0] - ray.origin[0]; ray.direction[0] = - ray.direction[0]; a |= 4 ; //bitwise OR (latest bits are XYZ) } if(ray.direction[1] &lt; 0){ ray.origin[1] = octree-&gt;size[1] - ray.origin[1]; ray.direction[1] = - ray.direction[1]; a |= 2 ; } if(ray.direction[2] &lt; 0){ ray.origin[2] = octree-&gt;size[2] - ray.origin[2]; ray.direction[2] = - ray.direction[2]; a |= 1 ; } double divx = 1 / ray.direction[0]; // IEEE stability fix double divy = 1 / ray.direction[1]; double divz = 1 / ray.direction[2]; double tx0 = (octree-&gt;min[0] - ray.origin[0]) * divx; double tx1 = (octree-&gt;max[0] - ray.origin[0]) * divx; double ty0 = (octree-&gt;min[1] - ray.origin[1]) * divy; double ty1 = (octree-&gt;max[1] - ray.origin[1]) * divy; double tz0 = (octree-&gt;min[2] - ray.origin[2]) * divz; double tz1 = (octree-&gt;max[2] - ray.origin[2]) * divz; if( max(max(tx0,ty0),tz0) &lt; min(min(tx1,ty1),tz1) ){ proc_subtree(tx0,ty0,tz0,tx1,ty1,tz1,octree-&gt;root); } } </code></pre>
 

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