Skip to content

Commit

Permalink
🎨 format tabulations
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasParistech committed Jul 6, 2022
1 parent 2c58925 commit 2518f90
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 63 deletions.
6 changes: 3 additions & 3 deletions include/neural-graphics-primitives/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ enum class ERenderMode : int {
static constexpr const char* RenderModeStr = "AO\0Shade\0Normals\0Positions\0Depth\0Distortion\0Cost\0Slice\0\0";

enum class ECameraMode : int {
Perspective,
Orthographic,
Environment
Perspective,
Orthographic,
Environment
};

static constexpr const char* CameraModeStr = "Perspective\0Orthographic\0Environment\0\0";
Expand Down
98 changes: 49 additions & 49 deletions include/neural-graphics-primitives/common_device.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -270,69 +270,69 @@ inline __host__ __device__ Ray pixel_to_ray(
bool snap_to_pixel_centers = false,
float focus_z = 1.0f,
float dof = 0.0f,
const ECameraMode camera_mode = ECameraMode::Perspective,
const ECameraMode camera_mode = ECameraMode::Perspective,
const CameraDistortion& camera_distortion = {},
const float* __restrict__ distortion_data = nullptr,
const Eigen::Vector2i distortion_resolution = Eigen::Vector2i::Zero()
) {
Eigen::Vector2f offset = ld_random_pixel_offset(snap_to_pixel_centers ? 0 : spp);
Eigen::Vector2f uv = (pixel.cast<float>() + offset).cwiseQuotient(resolution.cast<float>());

const Eigen::Vector3f shift = {parallax_shift.x(), parallax_shift.y(), 0.f};
const Eigen::Vector3f shift = {parallax_shift.x(), parallax_shift.y(), 0.f};
Eigen::Vector3f dir;

Eigen::Vector3f head_pos;
if(camera_mode == ECameraMode::Orthographic){
dir = {0.f, 0.f, 1.f}; // Camera forward
head_pos = {
(uv.x() - screen_center.x()) * (float)resolution.x() / focal_length.x(),
(uv.y() - screen_center.y()) * (float)resolution.y() / focal_length.y(),
0.0f
};
Eigen::Vector3f head_pos;
if(camera_mode == ECameraMode::Orthographic){
dir = {0.f, 0.f, 1.f}; // Camera forward
head_pos = {
(uv.x() - screen_center.x()) * (float)resolution.x() / focal_length.x(),
(uv.y() - screen_center.y()) * (float)resolution.y() / focal_length.y(),
0.0f
};
head_pos += shift;
dir -= shift / parallax_shift.z(); // we could use focus_z here in the denominator. for now, we pack m_scale in here.
}
else if(camera_mode == ECameraMode::Environment){
// Camera convention: XYZ <-> Right Down Front
head_pos = {0.f, 0.f, 0.f};
const float phi = (uv.y()-0.5) * M_PI;
const float theta = (uv.x()-0.5) * 2.0 * M_PI;
const float cos_phi = std::cos(phi);
dir = {
cos_phi*std::sin(theta),
std::sin(phi),
cos_phi*std::cos(theta)
};
dir -= shift / parallax_shift.z(); // we could use focus_z here in the denominator. for now, we pack m_scale in here.
}
else if(camera_mode == ECameraMode::Environment){
// Camera convention: XYZ <-> Right Down Front
head_pos = {0.f, 0.f, 0.f};
const float phi = (uv.y()-0.5) * M_PI;
const float theta = (uv.x()-0.5) * 2.0 * M_PI;
const float cos_phi = std::cos(phi);
dir = {
cos_phi*std::sin(theta),
std::sin(phi),
cos_phi*std::cos(theta)
};
// Parallax isn't handled
}
else { // Perspective
head_pos = {0.f, 0.f, 0.f};
if (camera_distortion.mode == ECameraDistortionMode::FTheta) {
dir = f_theta_undistortion(uv - screen_center, camera_distortion.params, {1000.f, 0.f, 0.f});
if (dir.x() == 1000.f) {
return {{1000.f, 0.f, 0.f}, {0.f, 0.f, 1.f}}; // return a point outside the aabb so the pixel is not rendered
}
} else if (camera_distortion.mode == ECameraDistortionMode::LatLong) {
}
else { // Perspective
head_pos = {0.f, 0.f, 0.f};
if (camera_distortion.mode == ECameraDistortionMode::FTheta) {
dir = f_theta_undistortion(uv - screen_center, camera_distortion.params, {1000.f, 0.f, 0.f});
if (dir.x() == 1000.f) {
return {{1000.f, 0.f, 0.f}, {0.f, 0.f, 1.f}}; // return a point outside the aabb so the pixel is not rendered
}
} else if (camera_distortion.mode == ECameraDistortionMode::LatLong) {
dir = latlong_to_dir(uv);
} else {
dir = {
(uv.x() - screen_center.x()) * (float)resolution.x() / focal_length.x(),
(uv.y() - screen_center.y()) * (float)resolution.y() / focal_length.y(),
1.0f
};
if (camera_distortion.mode == ECameraDistortionMode::Iterative) {
iterative_camera_undistortion(camera_distortion.params, &dir.x(), &dir.y());
}
}
if (distortion_data) {
dir.head<2>() += read_image<2>(distortion_data, distortion_resolution, uv);
}
dir = {
(uv.x() - screen_center.x()) * (float)resolution.x() / focal_length.x(),
(uv.y() - screen_center.y()) * (float)resolution.y() / focal_length.y(),
1.0f
};
if (camera_distortion.mode == ECameraDistortionMode::Iterative) {
iterative_camera_undistortion(camera_distortion.params, &dir.x(), &dir.y());
}
}
if (distortion_data) {
dir.head<2>() += read_image<2>(distortion_data, distortion_resolution, uv);
}
head_pos += shift;
dir -= shift / parallax_shift.z(); // we could use focus_z here in the denominator. for now, we pack m_scale in here.
}
dir -= shift / parallax_shift.z(); // we could use focus_z here in the denominator. for now, we pack m_scale in here.
}

dir = camera_matrix.block<3, 3>(0, 0) * dir;
Eigen::Vector3f origin = camera_matrix.block<3, 3>(0, 0) * head_pos + camera_matrix.col(3);
dir = camera_matrix.block<3, 3>(0, 0) * dir;
Eigen::Vector3f origin = camera_matrix.block<3, 3>(0, 0) * head_pos + camera_matrix.col(3);

if (dof == 0.0f) {
return {origin, dir};
Expand Down Expand Up @@ -439,7 +439,7 @@ inline __host__ __device__ Eigen::Vector2f motion_vector_3d(
snap_to_pixel_centers,
1.0f,
0.0f,
camera_mode,
camera_mode,
camera_distortion,
nullptr,
Eigen::Vector2i::Zero()
Expand Down
4 changes: 2 additions & 2 deletions include/neural-graphics-primitives/testbed.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class Testbed {
int show_accel,
float cone_angle_constant,
ERenderMode render_mode,
ECameraMode camera_mode,
ECameraMode camera_mode,
cudaStream_t stream
);

Expand Down Expand Up @@ -466,7 +466,7 @@ class Testbed {
float m_bounding_radius = 1;
float m_exposure = 0.f;

ECameraMode m_camera_mode = ECameraMode::Perspective;
ECameraMode m_camera_mode = ECameraMode::Perspective;
ERenderMode m_render_mode = ERenderMode::Shade;
EMeshRenderMode m_mesh_render_mode = EMeshRenderMode::VertexNormals;

Expand Down
6 changes: 3 additions & 3 deletions src/python_api.cu
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,9 @@ PYBIND11_MODULE(pyngp, m) {
.value("Slice", ERenderMode::Slice)
.export_values();

py::enum_<ECameraMode>(m, "CameraMode")
py::enum_<ECameraMode>(m, "CameraMode")
.value("Perspective", ECameraMode::Perspective)
.value("Orthographic", ECameraMode::Orthographic)
.value("Orthographic", ECameraMode::Orthographic)
.value("Environment", ECameraMode::Environment)
.export_values();

Expand Down Expand Up @@ -430,7 +430,7 @@ PYBIND11_MODULE(pyngp, m) {
.def_readwrite("shall_train_network", &Testbed::m_train_network)
.def_readwrite("render_groundtruth", &Testbed::m_render_ground_truth)
.def_readwrite("render_mode", &Testbed::m_render_mode)
.def_readwrite("camera_mode", &Testbed::m_camera_mode)
.def_readwrite("camera_mode", &Testbed::m_camera_mode)
.def_readwrite("slice_plane_z", &Testbed::m_slice_plane_z)
.def_readwrite("dof", &Testbed::m_dof)
.def_readwrite("autofocus", &Testbed::m_autofocus)
Expand Down
12 changes: 6 additions & 6 deletions src/testbed_nerf.cu
Original file line number Diff line number Diff line change
Expand Up @@ -1791,7 +1791,7 @@ __global__ void init_rays_with_payload_kernel_nerf(
const float* __restrict__ distortion_data,
const Vector2i distortion_resolution,
ERenderMode render_mode,
ECameraMode camera_mode
ECameraMode camera_mode
) {
uint32_t x = threadIdx.x + blockDim.x * blockIdx.x;
uint32_t y = threadIdx.y + blockDim.y * blockIdx.y;
Expand Down Expand Up @@ -1822,7 +1822,7 @@ __global__ void init_rays_with_payload_kernel_nerf(
snap_to_pixel_centers,
plane_z,
dof,
camera_mode,
camera_mode,
camera_distortion,
distortion_data,
distortion_resolution
Expand Down Expand Up @@ -1972,7 +1972,7 @@ void Testbed::NerfTracer::init_rays_from_camera(
int show_accel,
float cone_angle_constant,
ERenderMode render_mode,
ECameraMode camera_mode,
ECameraMode camera_mode,
cudaStream_t stream
) {
// Make sure we have enough memory reserved to render at the requested resolution
Expand Down Expand Up @@ -2004,7 +2004,7 @@ void Testbed::NerfTracer::init_rays_from_camera(
distortion_data,
distortion_resolution,
render_mode,
camera_mode
camera_mode
);

m_n_rays_initialized = resolution.x() * resolution.y();
Expand Down Expand Up @@ -2267,7 +2267,7 @@ void Testbed::render_nerf(CudaRenderBuffer& render_buffer, const Vector2i& max_r
m_nerf.show_accel,
m_nerf.cone_angle_constant,
render_mode,
m_camera_mode,
m_camera_mode,
stream
);

Expand Down Expand Up @@ -2445,7 +2445,7 @@ void Testbed::Nerf::Training::export_camera_extrinsics(const std::string& filena
trajectory.emplace_back(frame);
}
std::ofstream file(filename);
file << std::setw(2) << trajectory << std::endl;
file << std::setw(2) << trajectory << std::endl;
}

Eigen::Matrix<float, 3, 4> Testbed::Nerf::Training::get_camera_extrinsics(int frame_idx) {
Expand Down

0 comments on commit 2518f90

Please sign in to comment.