Skip to content

Commit 10fbde9

Browse files
Add function to compute intersection map
1 parent 74acfce commit 10fbde9

2 files changed

Lines changed: 73 additions & 48 deletions

File tree

src/FOVSimulator.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ export SpiceAsteroid
2727
export update!
2828

2929
include("image_generation.jl")
30-
export generate_pixel_rays, generate_thermal_image
30+
export generate_intersection_map, generate_image_radiance
3131

3232
end # module FOVSimulator

src/image_generation.jl

Lines changed: 72 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""
22
image_generation.jl
33
4-
カメラの視野情報からピクセルごとのレイを生成し、熱画像を生成する機能を提供する。
5-
バウンディングボックスを用いた高速化機能も提供する。
4+
Functions for generating images based on camera FOV information.
5+
Provides functionality for thermal image generation with bounding box optimization.
66
"""
77

88
"""
@@ -19,13 +19,13 @@ focal_length(fov_angle::Real, n_pixel::Int) = n_pixel / (2 * tan(deg2rad(fov_ang
1919
"""
2020
generate_pixel_rays(cam::SpiceCamera) -> Matrix{Ray}
2121
22-
SpiceCameraオブジェクトからカメラの視野情報を取得して、カメラ座標系において各ピクセルに対応するレイを生成する。
22+
Generate rays for each pixel based on camera FOV information in the camera frame.
2323
24-
# 引数
25-
- `cam` : SpiceCameraオブジェクト
24+
# Arguments
25+
- `cam` : SpiceCamera object
2626
27-
# 戻り値
28-
- `rays` : 各ピクセルに対応するレイの2次元配列(画像サイズと同じ形状)
27+
# Returns
28+
- `rays` : 2D array of rays corresponding to each pixel (same shape as the image)
2929
"""
3030
function generate_pixel_rays(cam::SpiceCamera)
3131
# Get camera parameters
@@ -69,28 +69,27 @@ end
6969
"""
7070
generate_pixel_rays(cam::SpiceCamera, asteroid::SpiceAsteroid) -> Matrix{Ray}
7171
72-
SpiceCameraオブジェクトからカメラの視野情報を取得して、各ピクセルに対応するレイを生成し、
73-
小惑星固定座標系に変換する。
72+
Generate rays for each pixel based on camera FOV information and transform them to the asteroid-fixed frame.
7473
75-
# 引数
76-
- `cam` : SpiceCameraオブジェクト
77-
- `asteroid`: SpiceAsteroidオブジェクト
78-
- `et` : エフェメリス時刻
79-
- `abcorr` : 光行差補正フラグ(例:"LT+S")
74+
# Arguments
75+
- `cam` : SpiceCamera object
76+
- `asteroid`: SpiceAsteroid object
8077
81-
# 戻り値
82-
- `rays` : 小惑星固定座標系における各ピクセルに対応するレイの2次元配列(画像サイズと同じ形状)
78+
# Returns
79+
- `rays` : 2D array of rays in the asteroid-fixed frame corresponding to each pixel
8380
"""
8481
function generate_pixel_rays(cam::SpiceCamera, asteroid::SpiceAsteroid)
85-
82+
# Check if camera and asteroid states are updated with the same ephemeris time
8683
if cam.state.et != asteroid.state.et
8784
error("The ephemeris time of the camera and asteroid must match. Update the camera and asteroid state before calling this function.")
8885
end
8986

87+
# Check if camera and asteroid states use the same aberration correction flag
9088
if cam.state.abcorr != asteroid.state.abcorr
9189
error("The `abcorr` flag of the camera and asteroid must match. Update the camera and asteroid state before calling this function.")
9290
end
9391

92+
# Get ephemeris time and aberration correction flag
9493
et = cam.state.et
9594
abcorr = cam.state.abcorr
9695

@@ -125,56 +124,82 @@ function generate_pixel_rays(cam::SpiceCamera, asteroid::SpiceAsteroid)
125124
end
126125

127126
"""
128-
generate_thermal_image(rays::Matrix{Ray}, asteroid::SpiceAsteroid, emissivities::Vector{Float64}, temperatures::Vector{Float64}) -> Matrix{Float64}
127+
generate_intersection_map(cam::SpiceCamera, asteroid::SpiceAsteroid) -> intersection_map::Matrix{RayShapeIntersectionResult}
129128
130-
`generate_pixel_rays`関数で生成したレイ、小惑星オブジェクト、各面に与えた温度と放射率をもとに、赤外線カメラの模擬画像を作成する。
131-
小惑星オブジェクトに格納されているバウンディングボックスを使用して高速化する。
129+
Generate an intersection map by casting rays from the camera to the asteroid shape model.
130+
Uses bounding box optimization for faster computation.
132131
133-
# 引数
134-
- `rays` : 各ピクセルに対応するレイの2次元配列(`generate_pixel_rays`関数で生成)
135-
- `asteroid` : 小惑星オブジェクト
136-
- `emissivities` : 各面の放射率(0-1)、face数と同じ長さ
137-
- `temperatures` : 各面の温度 [K]、face数と同じ長さ
132+
# Arguments
133+
- `cam` : SpiceCamera object
134+
- `asteroid`: SpiceAsteroid object
138135
139-
# 戻り値
140-
- `image` : 画素ごとの放射輝度 [W/m²/sr] を格納した2次元配列
136+
# Returns
137+
- `intersections` : 2D array of intersection results for each pixel
141138
"""
142-
function generate_thermal_image(rays::Matrix{Ray}, asteroid::SpiceAsteroid, emissivities::Vector{Float64}, temperatures::Vector{Float64})
143-
shape = asteroid.static.shape # Get shape model from asteroid object
139+
function generate_intersection_map(cam::SpiceCamera, asteroid::SpiceAsteroid)
140+
# Generate rays for each pixel in the asteroid-fixed frame
141+
rays = generate_pixel_rays(cam, asteroid)
142+
143+
# Get image dimensions
144+
height, width = size(rays)
144145

145-
# Check if the number of emissivities and temperatures matches the number of faces
146-
n_face = length(shape.faces)
147-
if length(emissivities) != n_face || length(temperatures) != n_face
148-
error("The number of emissivities and temperatures must match the number of faces in the shape model.")
146+
# Initialize array to store intersection results
147+
intersection_map = Matrix{RayShapeIntersectionResult}(undef, height, width)
148+
149+
# Perform intersection test for each pixel
150+
for v in 1:height
151+
for u in 1:width
152+
intersection_map[v, u] = intersect_ray_shape(rays[v, u], asteroid)
153+
end
149154
end
150155

151-
# Initialize image with the dimensions of the ray matrix
152-
height, width = size(rays)
156+
return intersection_map
157+
end
158+
159+
"""
160+
generate_image_radiance(intersection_map::Matrix{RayShapeIntersectionResult}, emissivities::Vector{Float64}, temperatures::Vector{Float64}) -> image::Matrix{Float64}
161+
162+
Generate a thermal image based on intersection results and surface properties.
163+
164+
# Arguments
165+
- `intersection_map` : 2D array of intersection results (from `generate_intersection_map`)
166+
- `emissivities` : Emissivity values (0-1) for each face, length should match the number of faces
167+
- `temperatures` : Temperature values [K] for each face, length should match the number of faces
168+
169+
# Returns
170+
- `image` : 2D array of radiance values [W/m²/sr] for each pixel
171+
"""
172+
function generate_image_radiance(intersection_map::Matrix{RayShapeIntersectionResult}, emissivities::Vector{Float64}, temperatures::Vector{Float64})
173+
# Get image dimensions
174+
height, width = size(intersection_map)
175+
176+
# Initialize array to store radiance values
153177
image = zeros(Float64, height, width)
154178

155-
# Process each pixel
179+
# Calculate radiance for each pixel
156180
for v in 1:height
157181
for u in 1:width
158-
# Get ray for this pixel
159-
ray = rays[v, u]
182+
# Get intersection result
183+
intersection = intersection_map[v, u]
160184

161-
# Perform ray-shape intersection using the asteroid's bounding box
162-
intersection = intersect_ray_shape(ray, asteroid)
163-
164-
# If intersection occurred
185+
# If intersection exists
165186
if intersection.hit
166-
# Get emissivity and temperature for this face
167-
ε = emissivities[intersection.face_index]
168-
T = temperatures[intersection.face_index]
187+
# Get face index
188+
face_index = intersection.face_index
189+
190+
# Get emissivity and temperature
191+
ε = emissivities[face_index]
192+
T = temperatures[face_index]
169193

170-
# Calculate total radiance using Stefan-Boltzmann law with emissivity
194+
# Calculate radiance using Stefan-Boltzmann law
171195
# E = ε·σT⁴ [W/m²] (total emitted power per unit area)
172196
# L = E/π [W/m²/sr] (radiance assuming Lambertian surface)
173197
radiance = ε * σ_SB * T^4 / π # [W/m²/sr]
174198

199+
# Store radiance
175200
image[v, u] = radiance
176201
else
177-
# If no intersection, set pixel to zero (or some other value)
202+
# No intersection (space)
178203
image[v, u] = 0.0
179204
end
180205
end

0 commit comments

Comments
 (0)