Skip to content

Commit dc42ad1

Browse files
authored
CameraView - add viz params to constructor (openvdb#289)
We had concurrency issues in nanovdb_editor and changing CameraView viz parameters needs more work to update during runtime. For now the fallback is to initialize everything in the constructor. The setters were not yet used outside of the constructor anyway. Signed-off-by: Petra Hapalova <phapalova@nvidia.com>
1 parent d0ffd50 commit dc42ad1

File tree

5 files changed

+57
-11
lines changed

5 files changed

+57
-11
lines changed

fvdb/_Cpp.pyi

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,8 +1004,14 @@ class Viewer:
10041004
camera_to_world_matrices: torch.Tensor,
10051005
projection_matrices: torch.Tensor,
10061006
image_sizes: torch.Tensor,
1007-
frustum_near_plane: float = 0.1,
1008-
frustum_far_plane: float = 1000.0,
1007+
frustum_near_plane: float,
1008+
frustum_far_plane: float,
1009+
axis_length: float,
1010+
axis_thickness: float,
1011+
frustum_line_width: float,
1012+
frustum_scale: float,
1013+
frustum_color: tuple[float, float, float],
1014+
visible: bool,
10091015
) -> CameraView: ...
10101016
def has_camera_view(self, name: str) -> bool: ...
10111017
def get_camera_view(self, name: str) -> CameraView: ...

fvdb/viz/_camera_view.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,21 @@ def __init__(
9191
image_sizes=image_sizes,
9292
frustum_near_plane=frustum_near_plane,
9393
frustum_far_plane=frustum_far_plane,
94+
axis_length=axis_length,
95+
axis_thickness=axis_thickness,
96+
frustum_line_width=frustum_line_width,
97+
frustum_scale=frustum_scale,
98+
frustum_color=frustum_color,
99+
visible=enabled,
94100
)
95101

96-
view.axis_length = axis_length
97-
view.axis_thickness = axis_thickness
98-
view.frustum_line_width = frustum_line_width
99-
view.frustum_scale = frustum_scale
100-
view.frustum_color = frustum_color
101-
view.visible = enabled
102+
# TODO: needs adjustments on editor's side
103+
# view.axis_length = axis_length
104+
# view.axis_thickness = axis_thickness
105+
# view.frustum_line_width = frustum_line_width
106+
# view.frustum_scale = frustum_scale
107+
# view.frustum_color = frustum_color
108+
# view.visible = enabled
102109

103110
@property
104111
def enabled(self) -> bool:

src/fvdb/detail/viewer/Viewer.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,13 @@ Viewer::addCameraView(const std::string &scene_name,
374374
const torch::Tensor &projectionMatrices,
375375
const torch::Tensor &imageSizes,
376376
float frustumNear,
377-
float frustumFar) {
377+
float frustumFar,
378+
float axisLength,
379+
float axisThickness,
380+
float frustumLineWidth,
381+
float frustumScale,
382+
const std::tuple<float, float, float> &frustumColor,
383+
bool visible) {
378384
TORCH_CHECK(cameraToWorldMatrices.dim() == 3 && cameraToWorldMatrices.size(1) == 4 &&
379385
cameraToWorldMatrices.size(2) == 4,
380386
"camera_to_world_matrices must have shape [N, 4, 4]");
@@ -465,6 +471,15 @@ Viewer::addCameraView(const std::string &scene_name,
465471
}
466472
}
467473

474+
// Set visualization parameters
475+
it->second.setAxisLength(axisLength);
476+
it->second.setAxisThickness(axisThickness);
477+
it->second.setFrustumLineWidth(frustumLineWidth);
478+
it->second.setFrustumScale(frustumScale);
479+
it->second.setFrustumColor(
480+
std::get<0>(frustumColor), std::get<1>(frustumColor), std::get<2>(frustumColor));
481+
it->second.setVisible(visible);
482+
468483
mEditor.editor.add_camera_view_2(&mEditor.editor, sceneToken, &it->second.mView);
469484

470485
return it->second;

src/fvdb/detail/viewer/Viewer.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,13 @@ class Viewer {
7777
const torch::Tensor &projectionMatrices,
7878
const torch::Tensor &imageSizes,
7979
float frustumNear,
80-
float frustumFar);
80+
float frustumFar,
81+
float axisLength,
82+
float axisThickness,
83+
float frustumLineWidth,
84+
float frustumScale,
85+
const std::tuple<float, float, float> &frustumColor,
86+
bool visible);
8187

8288
bool
8389
hasGaussianSplat3dView(const std::string &name) const {

src/python/ViewerBinding.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,26 @@ bind_viewer(py::module &m) {
209209
const torch::Tensor &,
210210
const torch::Tensor &,
211211
float,
212-
float>(&fvdb::detail::viewer::Viewer::addCameraView),
212+
float,
213+
float,
214+
float,
215+
float,
216+
float,
217+
const std::tuple<float, float, float> &,
218+
bool>(&fvdb::detail::viewer::Viewer::addCameraView),
213219
py::arg("scene_name"),
214220
py::arg("name"),
215221
py::arg("camera_to_world_matrices"),
216222
py::arg("projection_matrices"),
217223
py::arg("image_sizes"),
218224
py::arg("frustum_near_plane"),
219225
py::arg("frustum_far_plane"),
226+
py::arg("axis_length"),
227+
py::arg("axis_thickness"),
228+
py::arg("frustum_line_width"),
229+
py::arg("frustum_scale"),
230+
py::arg("frustum_color"),
231+
py::arg("visible"),
220232
py::return_value_policy::reference_internal,
221233
"Add a named camera view from camera/world and projection matrices")
222234
.def("has_camera_view",

0 commit comments

Comments
 (0)