| 855 | Background(const af::array& image_) { image = image_; } |
| 856 | |
| 857 | af::array get_color(const af::array& ray_dir) const { |
| 858 | auto spherical_dir = cart_to_sph_position(ray_dir); |
| 859 | |
| 860 | auto img_height = image.dims()[0]; |
| 861 | auto img_width = image.dims()[1]; |
| 862 | auto count = ray_dir.dims()[1]; |
| 863 | |
| 864 | // Spherical mapping of the direction to a pixel of the image |
| 865 | af::array o = spherical_dir(1, af::span); |
| 866 | af::array p = spherical_dir(2, af::span); |
| 867 | |
| 868 | auto x = (p / af::Pi + 1.0) * img_width / 2.0; |
| 869 | auto y = (o / af::Pi) * img_height; |
| 870 | |
| 871 | // Interpolate the colors of the image from the calculated pixel |
| 872 | // positions |
| 873 | af::array colors = af::approx2(image, af::moddims(y.as(f32), count), |
| 874 | af::moddims(x.as(f32), count), |
| 875 | af::interpType::AF_INTERP_CUBIC_SPLINE); |
| 876 | |
| 877 | // Zero out the color of any null rays |
| 878 | colors = af::moddims(colors, af::dim4(count, 3)); |
| 879 | af::replace(colors, !af::isNaN(colors), 0.f); |
| 880 | |
| 881 | return colors; |
| 882 | } |
| 883 | }; |
| 884 | |
| 885 | /** |
no test coverage detected