@@ -88,10 +88,10 @@ function phantom(
88
88
x:: AbstractVector ,
89
89
y:: AbstractVector ,
90
90
z:: AbstractVector ,
91
- oa:: Array{<:Object3d} ,
91
+ oa:: Array{<:Object3d{S,V} } ,
92
92
oversample:: Int ;
93
- T:: DataType = promote_type (eltype .(oa) ... , Float32),
94
- )
93
+ T:: DataType = promote_type (V , Float32),
94
+ ) where {S, V <: Number }
95
95
96
96
oversample < 1 && throw (ArgumentError (" oversample $oversample " ))
97
97
dx = x[2 ] - x[1 ]
@@ -104,7 +104,8 @@ function phantom(
104
104
o3 = oversample^ 3
105
105
ophantom = ob -> (x,y,z) ->
106
106
T (sum (phantom (ob).(ndgrid (x .+ dx* tmp, y .+ dy* tmp, z .+ dz* tmp)... )) / o3)
107
- return sum (ob -> ophantom (ob).(ndgrid (x,y,z)... ), oa)
107
+ out = sum (ob -> ophantom (ob).(ndgrid (x,y,z)... ), oa)
108
+ return out:: Array{T, 3}
108
109
end
109
110
110
111
@@ -173,6 +174,13 @@ function _xray(
173
174
end
174
175
175
176
177
+ # this gateway seems to help type inference
178
+ function _radon (ob:: Object3d{S} , u:: RealU , v:: RealU , ϕ:: RealU , θ:: RealU ) where S
179
+ T = radon_type (ob)
180
+ return T (ob. value * _xray (S (), ob. center, ob. width, ob. angle, u, v, ϕ, θ)):: T
181
+ end
182
+
183
+
176
184
"""
177
185
radon(ob::Object3d)::Function
178
186
Return function of `(u,v,ϕ,θ)` that user can sample
@@ -185,8 +193,7 @@ for an object ``f(x,y,z)``.
185
193
Then as `ϕ` increases, the line integrals rotate counter-clockwise.
186
194
"""
187
195
function radon (ob:: Object3d{S} ) where S
188
- return (u,v,ϕ,θ) -> ob. value *
189
- _xray (S (), ob. center, ob. width, ob. angle, u, v, ϕ, θ)
196
+ return (u:: RealU , v:: RealU , ϕ:: RealU , θ:: RealU ) -> _radon (ob, u, v, ϕ, θ)
190
197
end
191
198
192
199
@@ -198,7 +205,7 @@ to make projection views
198
205
for an array of 3D objects.
199
206
"""
200
207
function radon (oa:: Array{<:Object3d} )
201
- return (u,v,ϕ,θ ) -> sum (ob -> radon (ob)(u,v,ϕ,θ), oa)
208
+ return (u:: RealU , v :: RealU , ϕ :: RealU , θ :: RealU ) -> sum (ob -> radon (ob)(u,v,ϕ,θ), oa)
202
209
end
203
210
204
211
0 commit comments