MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / raytracing

Function raytracing

examples/pde/bhrt.cpp:1068–1118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1066}
1067
1068void raytracing(uint32_t width, uint32_t height) {
1069 // Set the parameters of the raytraced image
1070 double vfov = radians(90.0);
1071 double focal_length = 0.01;
1072
1073 // Set the parameters of the camera
1074 af::array global_vertical = af::array(3, {0.0, 0.0, 1.0});
1075 af::array camera_position = af::array(3, {-7.0, 6.0, 2.0});
1076 af::array camera_lookat = af::array(3, {0.0, 0.0, 0.0});
1077 double accretion_inner_radius = M * 3.0;
1078 double accretion_outter_radius = M * 8.0;
1079 double simulation_tolerance = 1e-6;
1080 double max_simulation_time = 12.;
1081 uint32_t num_steps_per_collide_check = 1;
1082
1083 // Set the background of the scene
1084 auto bg_image =
1085 af::loadimage(ASSETS_DIR "/examples/images/westerlund.jpg", true);
1086 auto background = Background(bg_image);
1087
1088 // Set the objects living in the scene
1089 std::vector<std::unique_ptr<Object> > objects;
1090 if (scene != Scene::WORMHOLE)
1091 objects.push_back(std::make_unique<AccretionDisk>(
1092 af::array(3, {0.0, 0.0, 0.0}), af::array(3, {0.0, 0.0, 1.0}),
1093 accretion_inner_radius, accretion_outter_radius));
1094
1095 // Generate rays from the camera
1096 auto camera = Camera(camera_position, camera_lookat, vfov, focal_length,
1097 width, height);
1098 auto pair = camera.generate_viewport_4rays();
1099
1100 auto ray4_pos = pair.first;
1101 auto ray4_vel = pair.second;
1102
1103 auto begin = std::chrono::high_resolution_clock::now();
1104 // Generate raytraced image
1105 auto image = generate_image(
1106 ray4_pos, ray4_vel, objects, background, width, height,
1107 max_simulation_time, simulation_tolerance, num_steps_per_collide_check);
1108
1109 auto end = std::chrono::high_resolution_clock::now();
1110
1111 std::cout
1112 << "\nSimulation took: "
1113 << std::chrono::duration_cast<std::chrono::seconds>(end - begin).count()
1114 << " s" << std::endl;
1115
1116 // Save image
1117 af::saveImage("result.png", image);
1118}
1119
1120int main(int argc, char** argv) {
1121 int device = argc > 1 ? std::atoi(argv[1]) : 0;

Callers 1

mainFunction · 0.85

Calls 8

radiansFunction · 0.85
loadimageFunction · 0.85
BackgroundClass · 0.85
CameraClass · 0.85
saveImageFunction · 0.85
generate_imageFunction · 0.70
arrayClass · 0.50

Tested by

no test coverage detected