Skip to content

Commit 8afb41f

Browse files
committed
Refactor level_set raytracing to use exact ray calculation instead of linear interpolation
1 parent 89038b0 commit 8afb41f

File tree

2 files changed

+28
-46
lines changed

2 files changed

+28
-46
lines changed

src/geometries/level_set_geometry.jl

Lines changed: 26 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,67 +3,49 @@
33
"""
44
abstract type AbstractLevelSetGeometry{T} <: AbstractGeometry end
55

6-
function _raytrace(
6+
@inline function _raytrace(
77
observation::A,
88
pixel::AbstractPixel{T},
99
mesh::Mesh{<:AbstractLevelSetGeometry,<:AbstractMaterial};
1010
res = 100,
1111
) where {A,T}
1212
geometry = mesh.geometry
1313
material = mesh.material
14-
ray = Vector{Intersection{T}}(undef, res)
15-
generate_ray!(ray, pixel, res)
16-
(; rs, θs, ϕs, νr, νθ) = ray[1]
17-
origin =
18-
boyer_lindquist_to_quasi_cartesian_kerr_schild_fast_light(pixel.metric, rs, θs, ϕs)
19-
z = zero(A)
20-
for i = 1:res
21-
(; ts, rs, θs, ϕs, νr, νθ) = ray[i]
22-
if rs <= Krang.horizon(pixel.metric) || iszero(rs)
23-
continue
24-
end
25-
line_point_2 = boyer_lindquist_to_quasi_cartesian_kerr_schild_fast_light(
26-
pixel.metric,
27-
rs,
28-
θs,
29-
ϕs,
30-
)
31-
if isinf(line_point_2[1]) || isinf(line_point_2[2]) || isinf(line_point_2[3])
32-
continue
33-
end
34-
didintersect, point = line_intersection(origin, line_point_2, geometry)
35-
rs = sqrt(sum(point .^ 2))
36-
θs = acos(point[3] / rs)
37-
ϕs = ϕ_BL(pixel.metric, rs, atan(point[2], point[1]))
14+
τf = Krang.total_mino_time(pixel)
15+
Δτ = τf / res - eps()
16+
origin_bl = 1e100,pixel.θo, 0.0, true, true
17+
for i in 1:res
18+
τref = Δτ*i
19+
τ = Krang.line_intersection(pixel, origin_bl, Δτ*(i-1), τref, geometry)
20+
rs, θs, ϕs, νr, νθ = Krang.emission_coordinates_fast_light(pixel, τ)
3821

3922
if rs < Krang.horizon(pixel.metric)
4023
continue
4124
end
4225

43-
intersection = Intersection(ts, rs, θs, ϕs, νr, νθ)
44-
observation += !didintersect ? z : material(pixel, intersection)#didintersect ? 1 : 0
45-
origin = line_point_2
26+
intersection = Krang.Intersection(0.0, rs, θs, ϕs, νr, νθ)
27+
observation += τ == 0 ? T(0) : material(pixel, intersection)#didintersect ? 1 : 0
28+
origin_bl = Krang.emission_coordinates_fast_light(pixel, τref)
29+
4630
end
4731
return observation
4832
end
4933

5034
@inline function line_intersection(
51-
origin::NTuple{3,T},
52-
line_point_2,
53-
geometry::AbstractLevelSetGeometry{T},
35+
pixel::Krang.AbstractPixel,
36+
origin_bl,
37+
τi::T,
38+
τf::T,
39+
geometry::Krang.AbstractLevelSetGeometry{T},
5440
) where {T}
55-
didintersect = geometry(origin...) * geometry(line_point_2...) <= zero(T)
41+
origin = Krang.boyer_lindquist_to_quasi_cartesian_kerr_schild_fast_light(pixel.metric, origin_bl[1:3]...)
42+
line_point_2_bl = Krang.emission_coordinates_fast_light(pixel, τf)
43+
line_point_2 = Krang.boyer_lindquist_to_quasi_cartesian_kerr_schild_fast_light(pixel.metric, line_point_2_bl[1:3]...)
44+
geo_origin = geometry(origin...)
45+
didintersect = geo_origin * geometry(line_point_2...) <= zero(T)
5646
if didintersect
57-
direction = (
58-
line_point_2[1] - origin[1],
59-
line_point_2[2] - origin[2],
60-
line_point_2[3] - origin[3],
61-
)
62-
63-
t = find_zero((x) -> geometry((origin .+ (direction .* x))...), (zero(T), one(T)))
64-
65-
return true, origin .+ (direction .* t)
47+
t = Krang.Roots.find_zero((x) -> x == zero(T) ? geo_origin : geometry(Krang.boyer_lindquist_to_quasi_cartesian_kerr_schild_fast_light(pixel.metric, Krang.emission_coordinates_fast_light(pixel, x)[1:3]...)...), (τi, τf))
48+
return t
6649
end
67-
return false, (zero(T), zero(T), zero(T))
68-
69-
end
50+
return zero(T)
51+
end

src/materials/physicsUtils.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ export p_bl_d,
1717
function p_bl_d(metric::Kerr{T}, r, θ, η, λ, νr::Bool, νθ::Bool) where {T}
1818
return @SVector[
1919
-one(T),
20-
(νr ? one(T) : -one(T)) * abs(r_potential(metric, η, λ, r)) /
20+
(νr ? one(T) : -one(T)) * max(zero(T), r_potential(metric, η, λ, r)) /
2121
Δ(metric, r),
22-
(νθ ? one(T) : -one(T)) * abs(θ_potential(metric, η, λ, θ)),
22+
(νθ ? one(T) : -one(T)) * max(zero(T), θ_potential(metric, η, λ, θ)),
2323
λ,
2424
]
2525
end

0 commit comments

Comments
 (0)