spherical-volume-rendering / svr-algorithm

A spherical volume rendering algorithm that performs ray casting through a spherical voxel grid.
Other
6 stars 7 forks source link

Tangential Hit Bug - No Progress #146

Closed cgyurgyik closed 4 years ago

cgyurgyik commented 4 years ago

I believe I may have some issues with the tangential hit.

        const BoundVec3 min_bound(-200000.0, -200000.0, -200000.0);
        const BoundVec3 max_bound(200000.0, 200000.0, 200000.0);
        const BoundVec3 sphere_center(0.0, 0.0, 0.0);
        const double sphere_max_radius = 10e3;
        const std::size_t num_radial_sections = 128;
        const std::size_t num_angular_sections = 1;
        const std::size_t num_azimuthal_sections = 1;
        const svr::SphericalVoxelGrid grid(min_bound, max_bound, num_radial_sections, num_angular_sections,
                                           num_azimuthal_sections, sphere_center, sphere_max_radius);
        const double t_begin = 0.0;
        const double t_end = sphere_max_radius * 3;
        const BoundVec3 ray_origin(-421.875, -562.5, -(sphere_max_radius + 1.0));
        const FreeVec3 ray_direction(0.0, 0.0, 1.0);
        const Ray ray(ray_origin, ray_direction);
        const auto actual_voxels = sphericalCoordinateVoxelTraversal(ray, grid, t_begin, t_end);

The expected behavior for radial_voxels is 1, 2, 3, ..., X, ..., 3, 2, 1. This works fine when num_radial_sections = 64, num_radial_sections = 127, and num_radial_sections = 129. When it is changed to 128, we get the following behavior:

...
Radial Hit Entrance: < Current Voxel: 113, Current t: 8967.503394 > - {it[0]: 9063.500000, it[1]: 10938.500000, it[2]: 25.749866, it[3]: 19976.250134} - intersection_time: 9063.500000, is_radial_transition: False, is_tangential_hit: False
Radial Hit Entrance: < Current Voxel: 114, Current t: 9063.500000 > - {it[0]: 9163.202711, it[1]: 10838.797289, it[2]: 25.749866, it[3]: 19976.250134} - intersection_time: 9163.202711, is_radial_transition: False, is_tangential_hit: False
Radial Hit Entrance: < Current Voxel: 115, Current t: 9163.202711 > - {it[0]: 9268.122538, it[1]: 10733.877462, it[2]: 25.749866, it[3]: 19976.250134} - intersection_time: 9268.122538, is_radial_transition: False, is_tangential_hit: False
Radial Hit Entrance: < Current Voxel: 116, Current t: 9268.122538 > - {it[0]: 9380.902036, it[1]: 10621.097964, it[2]: 25.749866, it[3]: 19976.250134} - intersection_time: 9380.902036, is_radial_transition: False, is_tangential_hit: False
Radial Hit Entrance: < Current Voxel: 117, Current t: 9380.902036 > - {it[0]: 9506.894116, it[1]: 10495.105884, it[2]: 25.749866, it[3]: 19976.250134} - intersection_time: 9506.894116, is_radial_transition: False, is_tangential_hit: False
Radial Hit Entrance: < Current Voxel: 118, Current t: 9506.894116 > - {it[0]: 9660.461020, it[1]: 10341.538980, it[2]: 25.749866, it[3]: 19976.250134} - intersection_time: 9660.461020, is_radial_transition: False, is_tangential_hit: False
Radial Hit Entrance: < Current Voxel: 119, Current t: 9660.461020 > - {it[0]: 10001.000000, it[1]: 10001.000000, it[2]: 25.749866, it[3]: 19976.250134} - intersection_time: 10001.000000, is_radial_transition: False, is_tangential_hit: True
Radial Hit Entrance: < Current Voxel: 119, Current t: 10001.000000 > - {it[0]: 10001.000000, it[1]: 10001.000000, it[2]: 25.749866, it[3]: 19976.250134} - intersection_time: 19976.250134, is_radial_transition: False, is_tangential_hit: True
// algorithm ends

Here, I've printed out the data for the last few radial hits. The issue arises with the second to last radial hit:

Radial Hit Entrance: < Current Voxel: 119, Current t: 9660.461020 > - {it[0]: 10001.000000, it[1]: 10001.000000, it[2]: 25.749866, it[3]: 19976.250134} - intersection_time: 10001.000000, is_radial_transition: False, is_tangential_hit: True
Radial Hit Entrance: < Current Voxel: 119, Current t: 10001.000000 > - {it[0]: 10001.000000, it[1]: 10001.000000, it[2]: 25.749866, it[3]: 19976.250134} - intersection_time: 19976.250134, is_radial_transition: False, is_tangential_hit: True

The algorithm just ends after this. It should continue here; since the ray passes entirely through the sphere, the first and last radial voxel should be 1.

At first I thought it was because the sphere maximum radius was small and the number of radial sections large, but I don't think this is the case. Let's set num_radial_sections to 129:

...
Radial Hit Entrance: < Current Voxel: 113, Current t: 8886.419490 > - {it[0]: 8979.244490, it[1]: 11022.755510, it[2]: 25.749866, it[3]: 19976.250134} - intersection_time: 8979.244490, is_radial_transition: False, is_tangential_hit: False
Radial Hit Entrance: < Current Voxel: 114, Current t: 8979.244490 > - {it[0]: 9074.880439, it[1]: 10927.119561, it[2]: 25.749866, it[3]: 19976.250134} - intersection_time: 9074.880439, is_radial_transition: False, is_tangential_hit: False
Radial Hit Entrance: < Current Voxel: 115, Current t: 9074.880439 > - {it[0]: 9174.302312, it[1]: 10827.697688, it[2]: 25.749866, it[3]: 19976.250134} - intersection_time: 9174.302312, is_radial_transition: False, is_tangential_hit: False
Radial Hit Entrance: < Current Voxel: 116, Current t: 9174.302312 > - {it[0]: 9279.072578, it[1]: 10722.927422, it[2]: 25.749866, it[3]: 19976.250134} - intersection_time: 9279.072578, is_radial_transition: False, is_tangential_hit: False
Radial Hit Entrance: < Current Voxel: 117, Current t: 9279.072578 > - {it[0]: 9391.945120, it[1]: 10610.054880, it[2]: 25.749866, it[3]: 19976.250134} - intersection_time: 9391.945120, is_radial_transition: False, is_tangential_hit: False
Radial Hit Entrance: < Current Voxel: 118, Current t: 9391.945120 > - {it[0]: 9518.573841, it[1]: 10483.426159, it[2]: 25.749866, it[3]: 19976.250134} - intersection_time: 9518.573841, is_radial_transition: False, is_tangential_hit: False
Radial Hit Entrance: < Current Voxel: 119, Current t: 9518.573841 > - {it[0]: 9674.594333, it[1]: 10327.405667, it[2]: 25.749866, it[3]: 19976.250134} - intersection_time: 9674.594333, is_radial_transition: False, is_tangential_hit: False
Radial Hit Entrance: < Current Voxel: 120, Current t: 9674.594333 > - {it[0]: 9674.594333, it[1]: 10327.405667, it[2]: 25.749866, it[3]: 19976.250134} - intersection_time: 10327.405667, is_radial_transition: True, is_tangential_hit: False
Radial Hit Entrance: < Current Voxel: 119, Current t: 10327.405667 > - {it[0]: 9674.594333, it[1]: 10327.405667, it[2]: 9518.573841, it[3]: 10483.426159} - intersection_time: 10483.426159, is_radial_transition: True, is_tangential_hit: False
Radial Hit Entrance: < Current Voxel: 118, Current t: 10483.426159 > - {it[0]: 9518.573841, it[1]: 10483.426159, it[2]: 9391.945120, it[3]: 10610.054880} - intersection_time: 10610.054880, is_radial_transition: True, is_tangential_hit: False
Radial Hit Entrance: < Current Voxel: 117, Current t: 10610.054880 > - {it[0]: 9391.945120, it[1]: 10610.054880, it[2]: 9279.072578, it[3]: 10722.927422} - intersection_time: 10722.927422, is_radial_transition: True, is_tangential_hit: False
Radial Hit Entrance: < Current Voxel: 116, Current t: 10722.927422 > - {it[0]: 9279.072578, it[1]: 10722.927422, it[2]: 9174.302312, it[3]: 10827.697688} - intersection_time: 10827.697688, is_radial_transition: True, is_tangential_hit: False
...
// algorithm continues to radial voxel 1.

No issues at all.

cgyurgyik commented 4 years ago

@ak-2485 When we talked earlier, I said I thought it was because of small floating point error due to a large number of radial sections and a small sphere max radius; I no longer think this is the case. It works fine when N = 32, 64, 127, 129. It breaks exactly when N = 128. This seems to be occurring because of a tangential hit at radial voxel 119. Since its a tangential hit, no step occurs and it gets stuck using the same times. Since the next biggest time will be the last radial voxel, it jumps to the end.

ak-2485 commented 4 years ago

We should be able to test a case when we have several radial sections and the ray is tangential to an interior section. @nukenukenukelol can you create a matlab test with that spec?

nukenukenukelol commented 4 years ago

We should be able to test a case when we have several radial sections and the ray is tangential to an interior section. @nukenukenukelol can you create a matlab test with that spec?

Yes, I will work on that! Just to be clear, we want a sphere with large radial sections with a ray that is tangential to one of the planes (xy, xz, yz) or tangential to one of the radial sections?

cgyurgyik commented 4 years ago

I think any number of radial sections is fine. We want a ray tangent to a radial section that is not the first or last radial section. So if there are N radial sections, it needs to be between the bounds 1 and N (exclusive). There should just be one azimuthal and angular section, since we're just trying to see this case.

The issue: The ray is tangent to a radial section, the step value is 0, and then it jumps to the end.

If this doesn't work, maybe try replicating my numbers above in MATLAB.