You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 24, 2023. It is now read-only.
Copy file name to clipboardExpand all lines: overview/FastVoxelTraversalOverview.md
+12-12
Original file line number
Diff line number
Diff line change
@@ -29,23 +29,23 @@ A “safer” implementation of this algorithm can be found in the paper [here](
29
29
30
30
#### Example:
31
31
The ray in the image above might be represented as ```r = u + tv``` where ```u = <0,-3/4>``` and ```v = <1, 8/9>```, i.e. ```r``` follows the line ```y = (-3/4)+ (9/8)x```. Thus, ```ray.origin.x = 0``` and ```ray.origin.y = -3/4```. Based on grid (given at initialization) we know that
32
-
```
32
+
```c
33
33
grid.corners = [(0,0),(0,2),
34
34
(2,2),(2,0)];
35
35
```
36
36
37
37
Thus, we can determine the boundary at which ```r``` intersects the grid. In particular, we see the ```y = 0``` boundary of the grid is represented by the vector ```r2 = <0,0> + <1,0>t```; solving for ```r2 = r``` yields ```t = 27/32```. Thus, at the annoying value of ```t = 27/32```, the ray ```r``` will intersect the boundary of the grid. Note that this value of ```t``` is the least such value of ```t``` for all boundary crossings.
38
38
39
39
From here, based on grid we know that
40
-
```
40
+
```c
41
41
grid.voxel_list = [(0,0),(1,0),
42
42
(1,1),(0,1)]
43
43
```
44
44
and we can determine that the voxel we are located in is ```grid.voxel_list[0]```, or ```Voxel(0,0)```.
45
45
46
46
### Incremental Traversal
47
47
This brings us to our first algorithm, which we’ll uncover one pseudovariable at a time.
48
-
```
48
+
```c
49
49
loop {
50
50
if (tMaxX < tMaxY) {
51
51
tMaxX= tMaxX + tDeltaX;
@@ -77,15 +77,15 @@ In fact, some users also call this variable ```Dir```, short for direction. Let
77
77

78
78
79
79
Here, (```ray.direction.y > 0``` and ```ray.direction.x > 0``` and ```grid.x_step = grid.y_step = 1```). So in this case,
80
-
```
80
+
```c
81
81
StepX = 1 * grid.x_step = 1;
82
82
StepY = 1 * grid.y_step = 1;
83
83
```
84
84
85
85

86
86
87
87
If the ray’s slope was 0, we’d have instead the following:
88
-
```
88
+
```c
89
89
StepX = 1 * grid.x_step = 1;
90
90
StepY = 0 * grid.y_step = 0;
91
91
```
@@ -97,7 +97,7 @@ Note that, in addition to the slope of the ray, initializing ```Step``` relies o
97
97
```StepX = (voxel_size);```
98
98
This gives us the following generalized function for initializing StepX with unit sized voxel:
99
99
100
-
```
100
+
```c
101
101
// StepX will be 0, 1, -1 depending on the ray's x direction.
102
102
InitializeStepX(Ray r) {
103
103
if (r.direction.x > 0) StepX = 1;
@@ -114,7 +114,7 @@ The value of ```tMax``` is determined with each iteration. It is the maximum dir
114
114
115
115
Here, ```tMaxX``` represents how far the ray can travel before hitting the first ```X``` boundary; ```tMaxY``` represents how far the ray can travel before hitting the first ```Y``` boundary. Clearly, for the example above, ```tMaxY``` is smaller than ```tMaxX```; this means we will enter the voxel associated with ```tMaxY``` first. This is exactly the first step of our loop:
116
116
117
-
```
117
+
```c
118
118
if (tMaxX < tMaxY) {
119
119
traverse in the x-direction.
120
120
} else {
@@ -125,15 +125,15 @@ if (tMaxX < tMaxY) {
125
125
Example code to calculate ```tMaxX``` might be the following:
126
126
First, let’s calculate the current X index that the ray enters at initialization:
127
127
128
-
```
128
+
```c
129
129
// Here, we see this is determined by taking the maximum of the 1 and
130
130
// the ray's origin and the minimum bound.
131
131
// If the ray started outside of the grid, then this would default to 1.
0 commit comments