in source/rig/RigSimulator.cpp [658:777]
int main(int argc, char** argv) {
system_util::initDep(argc, argv, kUsageMessage);
CHECK_NE(FLAGS_mode, "");
CHECK_NE(FLAGS_skybox_path, "");
// load skybox
cv::Mat_<cv::Vec3b> skybox = imreadExceptionOnFail(FLAGS_skybox_path, cv::IMREAD_COLOR);
// construct scene of triangles
std::vector<Triangle> triangles;
if (FLAGS_scene == "icosahedron") {
makeIcosahedronScene(triangles);
} else if (FLAGS_scene == "cube") {
makeCubesScene(triangles);
} else if (FLAGS_scene == "ground_plane") {
makeGroundPlaneScene(triangles);
} else {
CHECK(false) << "unexpected scene: " << FLAGS_scene;
}
// bind indices of triangles. we need these to know how to color them after
// finding the ray-bvh intersection.
for (int i = 0; i < int(triangles.size()); ++i) {
triangles[i].selfIdx = i;
}
// build bounding volume hierarchy
LOG(INFO) << "building BVH";
const static int kBVHStopNumTrianglesInLeaf = 20;
const static int kBVHSplitK = 5;
const static int kBVHMaxDepth = 50;
BoundingVolumeHierarchy bvh = BoundingVolumeHierarchy::makeBVH(
triangles,
kBVHStopNumTrianglesInLeaf,
kBVHSplitK,
0, // start at depth = 0
kBVHMaxDepth);
if (FLAGS_mode == "mono_eqr") {
CHECK_NE(FLAGS_dest_mono, "");
CHECK_NE(FLAGS_dest_mono_depth, "");
cv::Mat_<cv::Vec3f> monoEquirect;
cv::Mat_<float> monoEquirectInvDepth;
std::tie(monoEquirect, monoEquirectInvDepth) =
renderMonoEquirect(triangles, bvh, FLAGS_eqr_width, FLAGS_eqr_height, skybox);
imwriteExceptionOnFail(FLAGS_dest_mono, monoEquirect);
imwriteExceptionOnFail(FLAGS_dest_mono_depth, monoEquirectInvDepth * 255.0);
} else if (FLAGS_mode == "stereo_eqr") {
CHECK_NE(FLAGS_dest_left, "");
CHECK_NE(FLAGS_dest_right, "");
CHECK_NE(FLAGS_dest_stereo, "");
std::pair<cv::Mat_<cv::Vec3f>, cv::Mat_<cv::Vec3f>> eqrLeftRight =
renderStereoEquirect(triangles, bvh, FLAGS_eqr_width, FLAGS_eqr_height, skybox);
cv::Mat_<cv::Vec3f> stereoPair;
vconcat(eqrLeftRight.first, eqrLeftRight.second, stereoPair);
imwriteExceptionOnFail(FLAGS_dest_left, eqrLeftRight.first);
imwriteExceptionOnFail(FLAGS_dest_right, eqrLeftRight.second);
imwriteExceptionOnFail(FLAGS_dest_stereo, stereoPair);
} else {
std::vector<Camera> cameras;
if (FLAGS_mode == "pinhole_ring") {
cameras = makeHorizontalRingOfPinholeCameras(
FLAGS_num_cams_in_ring,
FLAGS_rig_radius,
FLAGS_pinhole_width,
FLAGS_pinhole_height,
FLAGS_pinhole_fov_horizontal,
FLAGS_pinhole_aspect_ratio);
} else if (FLAGS_mode == "ftheta_ring") {
cameras = makeHorizontalRingOfFThetaCameras(
FLAGS_num_cams_in_ring,
FLAGS_rig_radius,
FLAGS_ftheta_width,
FLAGS_ftheta_height,
FLAGS_ftheta_image_circle_radius,
FLAGS_ftheta_image_circle_fov);
// add top camera, too
addTopCamera(
cameras,
FLAGS_ftheta_width,
FLAGS_ftheta_height,
FLAGS_ftheta_image_circle_radius,
FLAGS_ftheta_image_circle_fov);
} else if (FLAGS_mode == "dodecahedron") {
cameras = makeDodecahedronOfFThetaCameras(
FLAGS_rig_radius,
FLAGS_ftheta_width,
FLAGS_ftheta_height,
FLAGS_ftheta_image_circle_radius,
FLAGS_ftheta_image_circle_fov);
} else if (FLAGS_mode == "icosahedron") {
cameras = makeIcosahedronOfFThetaCameras(
FLAGS_rig_radius,
FLAGS_ftheta_width,
FLAGS_ftheta_height,
FLAGS_ftheta_image_circle_radius,
FLAGS_ftheta_image_circle_fov);
} else if (FLAGS_mode == "rig_from_json") {
CHECK_NE(FLAGS_rig_in, "");
cameras = Camera::loadRig(FLAGS_rig_in);
} else {
CHECK(false) << "unexpected mode: " << FLAGS_mode;
}
if (!FLAGS_rig_out.empty()) {
const std::vector<std::string> comments = {};
const int doubleNumDigits = 10;
Camera::saveRig(FLAGS_rig_out, cameras, comments, doubleNumDigits);
}
if (!FLAGS_dest_cam_images.empty()) {
renderCamerasThreaded(skybox, triangles, bvh, cameras, FLAGS_dest_cam_images);
}
}
return EXIT_SUCCESS;
}