Skip to content
This repository was archived by the owner on Oct 24, 2023. It is now read-only.

Commit 399dcd9

Browse files
authored
Merge pull request #6 from r4v10l1/patch-1
Add sytax highlighting to code blocks in FastVoxelTraversalOverview.md
2 parents 566dab8 + 9664199 commit 399dcd9

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

overview/FastVoxelTraversalOverview.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,23 @@ A “safer” implementation of this algorithm can be found in the paper [here](
2929

3030
#### Example:
3131
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
3333
grid.corners = [(0,0),(0,2),
3434
(2,2),(2,0)];
3535
```
3636

3737
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.
3838

3939
From here, based on grid we know that
40-
```
40+
```c
4141
grid.voxel_list = [(0,0),(1,0),
4242
(1,1),(0,1)]
4343
```
4444
and we can determine that the voxel we are located in is ```grid.voxel_list[0]```, or ```Voxel(0,0)```.
4545

4646
### Incremental Traversal
4747
This brings us to our first algorithm, which we’ll uncover one pseudovariable at a time.
48-
```
48+
```c
4949
loop {
5050
if (tMaxX < tMaxY) {
5151
tMaxX= tMaxX + tDeltaX;
@@ -77,15 +77,15 @@ In fact, some users also call this variable ```Dir```, short for direction. Let
7777
![ray direction 1](images/ray_dir.png)
7878

7979
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
8181
StepX = 1 * grid.x_step = 1;
8282
StepY = 1 * grid.y_step = 1;
8383
```
8484

8585
![ray direction 2](images/ray_dir2.png)
8686

8787
If the ray’s slope was 0, we’d have instead the following:
88-
```
88+
```c
8989
StepX = 1 * grid.x_step = 1;
9090
StepY = 0 * grid.y_step = 0;
9191
```
@@ -97,7 +97,7 @@ Note that, in addition to the slope of the ray, initializing ```Step``` relies o
9797
```StepX = (voxel_size);```
9898
This gives us the following generalized function for initializing StepX with unit sized voxel:
9999

100-
```
100+
```c
101101
// StepX will be 0, 1, -1 depending on the ray's x direction.
102102
InitializeStepX(Ray r) {
103103
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
114114
115115
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:
116116
117-
```
117+
```c
118118
if (tMaxX < tMaxY) {
119119
traverse in the x-direction.
120120
} else {
@@ -125,15 +125,15 @@ if (tMaxX < tMaxY) {
125125
Example code to calculate ```tMaxX``` might be the following:
126126
First, let’s calculate the current X index that the ray enters at initialization:
127127

128-
```
128+
```c
129129
// Here, we see this is determined by taking the maximum of the 1 and
130130
// the ray's origin and the minimum bound.
131131
// If the ray started outside of the grid, then this would default to 1.
132132
current_X_index = max(1, ceiling(ray_origin.x - grid.minBound.x));
133133
```
134134
We can then calculate ```tMaxX```:
135135

136-
```
136+
```c
137137
// grid.minBound.x is the lower left corner of the grid.
138138
// current_X_index is the current X index where the ray begins. If it starts outside, this is 1.
139139
// ray_origin.x is the x-coordinate of where the ray originates.
@@ -159,7 +159,7 @@ If one were to use a voxel size other than 1, we’d simply multiply by the ```v
159159

160160
### 2-dimensional incremental phase algorithm
161161
Now that we’ve established all of our variables, we can now refer to the algorithm. Here is the entire thing:
162-
```
162+
```c
163163
loop {
164164
if (tMaxX < tMaxY) {
165165
tMaxX= tMaxX + tDeltaX;
@@ -187,7 +187,7 @@ We are now moving along the ray. tDeltaX tells us how much we’ll move along un
187187
We’ve now updated either our X or Y component. This means we’ll move on to the next cell, located at (X,Y).
188188

189189
With checks for out of bounds and whether we’ve hit an object list, this gives us our final algorithm:
190-
```
190+
```c
191191
loop {
192192
if (tMaxX < tMaxY) {
193193
tMaxX= tMaxX + tDeltaX;
@@ -211,7 +211,7 @@ The paper also uses a ```do...while``` loop, which ends in the two cases we ment
211211
an ```ObjectList``` has been acquired, i.e. there is an object in the voxel, or we’ve gone out of bounds.
212212
Lastly, they name their variable ```justOutX``` instead of ```x_out_of_bounds```. The semantics for both remains the same.
213213

214-
```
214+
```c
215215
list= NIL;
216216
do {
217217
if(tMaxX < tMaxY) {

0 commit comments

Comments
 (0)