mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-07 00:09:14 +08:00
CropBox GUI implementation (#1205)
* fixed an exception bug in case of num_samples is 0 fixed an exception bug when num samples is 0 , "IndexError tensors used as indices must be long, byte or bool tensors" change type to long ( was float32) * implemented crop box in gui. For now works on instant-ngp-bounded * fixed import bugs * update aabb every time and not only on training * prevent crash when chosing accomulation and crop box * Checkbox * max_box is bounded by scevne box in the gui * implemented altenative intesection to nerfacc * convert str to bool correctly * fixed isort bug * fixed isort bug2 * update viewer version * remove json bug * Update UI * Force black background * Fix formatting Co-authored-by: dror <you@example.com> Co-authored-by: Matt Tancik <tancik@berkeley.edu> Co-authored-by: Matthew Tancik <mattt4001@gmail.com>
This commit is contained in:
12 files changed
+518
-25
No files matched your search
@@ -16,19 +16,25 @@
|
||||
Camera Models
|
||||
"""
|
||||
import base64
|
||||
import importlib
|
||||
import math
|
||||
import os
|
||||
from dataclasses import dataclass
|
||||
from distutils.util import strtobool
|
||||
from enum import Enum, auto
|
||||
from typing import Dict, List, Optional, Tuple, Union
|
||||
|
||||
import cv2
|
||||
import torch
|
||||
import torchvision
|
||||
from torch.nn import Parameter
|
||||
from torchtyping import TensorType
|
||||
|
||||
import nerfstudio.utils.math
|
||||
import nerfstudio.utils.poses as pose_utils
|
||||
from nerfstudio.cameras import camera_utils
|
||||
from nerfstudio.cameras.rays import RayBundle
|
||||
from nerfstudio.data.scene_box import SceneBox
|
||||
from nerfstudio.utils.tensor_dataclass import TensorDataclass
|
||||
|
||||
|
||||
@@ -308,6 +314,7 @@ class Cameras(TensorDataclass):
|
||||
distortion_params_delta: Optional[TensorType["num_rays":..., 6]] = None,
|
||||
keep_shape: Optional[bool] = None,
|
||||
disable_distortion: bool = False,
|
||||
aabb_box: SceneBox = None,
|
||||
) -> RayBundle:
|
||||
"""Generates rays for the given camera indices.
|
||||
|
||||
@@ -350,6 +357,7 @@ class Cameras(TensorDataclass):
|
||||
keeping dimensions. If False, we flatten at the end. If True, then we keep the shape of the
|
||||
camera_indices and coords tensors (if we can).
|
||||
disable_distortion: If True, disables distortion.
|
||||
aabb_box: if not None will calculate nears and fars of the ray according to aabb box intesection
|
||||
|
||||
Returns:
|
||||
Rays for the given camera indices and coords.
|
||||
@@ -449,6 +457,31 @@ class Cameras(TensorDataclass):
|
||||
if keep_shape is False:
|
||||
raybundle = raybundle.flatten()
|
||||
|
||||
if aabb_box:
|
||||
with torch.no_grad():
|
||||
tensor_aabb = Parameter(aabb_box.aabb.flatten(), requires_grad=False)
|
||||
|
||||
rays_o = raybundle.origins.contiguous()
|
||||
rays_d = raybundle.directions.contiguous()
|
||||
|
||||
tensor_aabb = tensor_aabb.to(rays_o.device)
|
||||
shape = rays_o.shape
|
||||
|
||||
rays_o = rays_o.reshape((-1, 3))
|
||||
rays_d = rays_d.reshape((-1, 3))
|
||||
|
||||
if strtobool(os.environ.get("INTERSECT_WITH_NERFACC", "TRUE")):
|
||||
nerfacc = importlib.import_module("nerfacc")
|
||||
t_min, t_max = nerfacc.ray_aabb_intersect(rays_o, rays_d, tensor_aabb)
|
||||
else:
|
||||
t_min, t_max = nerfstudio.utils.math.intersect_aabb(rays_o, rays_d, tensor_aabb)
|
||||
|
||||
t_min = t_min.reshape([shape[0], shape[1], 1])
|
||||
t_max = t_max.reshape([shape[0], shape[1], 1])
|
||||
|
||||
raybundle.nears = t_min
|
||||
raybundle.fars = t_max
|
||||
|
||||
# TODO: We should have to squeeze the last dimension here if we started with zero batch dims, but never have to,
|
||||
# so there might be a rogue squeeze happening somewhere, and this may cause some unintended behaviour
|
||||
# that we haven't caught yet with tests
|
||||
|
||||
Reference in new issue
Block a user