Skip to content

Commit 29f16b3

Browse files
authored
Viewer Pythonification (#163)
This PR refactors the Viewer class to have a minimal API and adds a viewer python class which does most of the heavy lifting for logic and error checks. It also adds docstrings. --------- Signed-off-by: Francis Williams <[email protected]>
1 parent 8019dc9 commit 29f16b3

File tree

8 files changed

+435
-216
lines changed

8 files changed

+435
-216
lines changed

fvdb/_Cpp.pyi

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class GaussianSplat3d:
101101
image_height: int,
102102
near: float,
103103
far: float,
104-
projection_type=...,
104+
projection_type: str = ...,
105105
min_radius_2d: float = ...,
106106
eps_2d: float = ...,
107107
antialias: bool = ...,
@@ -114,7 +114,7 @@ class GaussianSplat3d:
114114
image_height: int,
115115
near: float,
116116
far: float,
117-
projection_type=...,
117+
projection_type: str = ...,
118118
sh_degree_to_use: int = ...,
119119
min_radius_2d: float = ...,
120120
eps_2d: float = ...,
@@ -128,7 +128,7 @@ class GaussianSplat3d:
128128
image_height: int,
129129
near: float,
130130
far: float,
131-
projection_type=...,
131+
projection_type: str = ...,
132132
sh_degree_to_use: int = ...,
133133
min_radius_2d: float = ...,
134134
eps_2d: float = ...,
@@ -142,7 +142,7 @@ class GaussianSplat3d:
142142
image_height: int,
143143
near: float,
144144
far: float,
145-
projection_type=...,
145+
projection_type: str = ...,
146146
tile_size: int = ...,
147147
min_radius_2d: float = ...,
148148
eps_2d: float = ...,
@@ -165,7 +165,7 @@ class GaussianSplat3d:
165165
image_height: int,
166166
near: float,
167167
far: float,
168-
projection_type=...,
168+
projection_type: str = ...,
169169
sh_degree_to_use: int = ...,
170170
tile_size: int = ...,
171171
min_radius_2d: float = ...,
@@ -180,7 +180,7 @@ class GaussianSplat3d:
180180
image_height: int,
181181
near: float,
182182
far: float,
183-
projection_type=...,
183+
projection_type: str = ...,
184184
sh_degree_to_use: int = ...,
185185
tile_size: int = ...,
186186
min_radius_2d: float = ...,
@@ -195,7 +195,7 @@ class GaussianSplat3d:
195195
image_height: int,
196196
near: float,
197197
far: float,
198-
projection_type=...,
198+
projection_type: str = ...,
199199
tile_size: int = ...,
200200
min_radius_2d: float = ...,
201201
eps_2d: float = ...,
@@ -210,7 +210,7 @@ class GaussianSplat3d:
210210
image_height: int,
211211
near: float,
212212
far: float,
213-
projection_type=...,
213+
projection_type: str = ...,
214214
tile_size: int = ...,
215215
min_radius_2d: float = ...,
216216
eps_2d: float = ...,
@@ -225,7 +225,7 @@ class GaussianSplat3d:
225225
image_height: int,
226226
near: float,
227227
far: float,
228-
projection_type=...,
228+
projection_type: str = ...,
229229
tile_size: int = ...,
230230
min_radius_2d: float = ...,
231231
eps_2d: float = ...,
@@ -241,7 +241,7 @@ class GaussianSplat3d:
241241
image_height: int,
242242
near: float,
243243
far: float,
244-
projection_type=...,
244+
projection_type: str = ...,
245245
tile_size: int = ...,
246246
min_radius_2d: float = ...,
247247
eps_2d: float = ...,
@@ -813,7 +813,7 @@ class ProjectedGaussianSplats:
813813
@property
814814
def opacities(self) -> torch.Tensor: ...
815815
@property
816-
def projection_type(self): ...
816+
def projection_type(self) -> str: ...
817817
@property
818818
def radii(self) -> torch.Tensor: ...
819819
@property
@@ -899,6 +899,54 @@ class SparseConvPackInfo:
899899
@property
900900
def use_tf32(self) -> bool: ...
901901

902+
class GaussianSplat3dView:
903+
@property
904+
def tile_size(self) -> int: ...
905+
@tile_size.setter
906+
def tile_size(self, value: int) -> None: ...
907+
@property
908+
def min_radius_2d(self) -> float: ...
909+
@min_radius_2d.setter
910+
def min_radius_2d(self, value: float) -> None: ...
911+
@property
912+
def eps_2d(self) -> float: ...
913+
@eps_2d.setter
914+
def eps_2d(self, value: float) -> None: ...
915+
@property
916+
def antialias(self) -> bool: ...
917+
@antialias.setter
918+
def antialias(self, value: bool) -> None: ...
919+
@property
920+
def sh_degree_to_use(self) -> int: ...
921+
@sh_degree_to_use.setter
922+
def sh_degree_to_use(self, value: int) -> None: ...
923+
@property
924+
def near(self) -> float: ...
925+
@near.setter
926+
def near(self, value: float) -> None: ...
927+
@property
928+
def far(self) -> float: ...
929+
@far.setter
930+
def far(self, value: float) -> None: ...
931+
932+
class Viewer:
933+
def __init__(self, ip_address: str, port: int, verbose: bool) -> None: ...
934+
def start_server(self) -> None: ...
935+
def stop_server(self) -> None: ...
936+
def add_gaussian_splat_3d(self, name: str, gaussian_splat_3d: GaussianSplat3d) -> GaussianSplat3dView: ...
937+
def camera_origin(self) -> tuple[float, float, float]: ...
938+
def set_camera_origin(self, ox: float, oy: float, oz: float) -> None: ...
939+
def camera_view_direction(self) -> tuple[float, float, float]: ...
940+
def set_camera_view_direction(self, dx: float, dy: float, dz: float) -> None: ...
941+
def camera_up_direction(self) -> tuple[float, float, float]: ...
942+
def set_camera_up_direction(self, ux: float, uy: float, uz: float) -> None: ...
943+
def camera_near(self) -> float: ...
944+
def set_camera_near(self, near: float) -> None: ...
945+
def camera_far(self) -> float: ...
946+
def set_camera_far(self, near: float) -> None: ...
947+
def camera_projection_type(self) -> str: ...
948+
def set_camera_projection_type(self, projection_type: str) -> None: ...
949+
902950
class config:
903951
enable_ultra_sparse_acceleration: ClassVar[bool] = ...
904952
pedantic_error_checking: ClassVar[bool] = ...

fvdb/types.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,3 +1002,52 @@ def to_Vec3fBatch(
10021002
return to_FloatingTensorBroadcastableRank2(
10031003
x, (1, 3), dtype, value_constraint=value_constraint, do_broadcast_to=True
10041004
)
1005+
1006+
1007+
def to_Mat44f(
1008+
x: NumericMaxRank2,
1009+
dtype: torch.dtype = torch.float32,
1010+
value_constraint: ValueConstraint = ValueConstraint.NONE,
1011+
) -> torch.Tensor:
1012+
"""
1013+
Converts a NumericMaxRank2 to a Mat44f tensor, reshaped to (4, 4).
1014+
1015+
Args:
1016+
x (NumericMaxRank2): The input tensor.
1017+
dtype (torch.dtype): The floating dtype of the output tensor. Defaults to torch.float32.
1018+
value_constraint: Constraint on the value of the scalar.
1019+
default: ValueConstraint.NONE
1020+
if ValueConstraint.NON_NEGATIVE, the scalar must be non-negative
1021+
if ValueConstraint.POSITIVE, the scalar must be positive
1022+
1023+
Returns:
1024+
A torch.Tensor of dtype dtype and shape (4, 4).
1025+
"""
1026+
return to_FloatingTensorBroadcastableRank2(
1027+
x, (4, 4), dtype, value_constraint=value_constraint, do_broadcast_to=True
1028+
)
1029+
1030+
1031+
def to_Mat44fBroadcastable(
1032+
x: NumericMaxRank2,
1033+
dtype: torch.dtype = torch.float32,
1034+
value_constraint: ValueConstraint = ValueConstraint.NONE,
1035+
) -> torch.Tensor:
1036+
"""
1037+
Converts a NumericMaxRank2 to a Mat44f tensor that respects the shape of the input without reshaping,
1038+
but verifies that it can be broadcasted to the shape (4, 4).
1039+
1040+
Args:
1041+
x (NumericMaxRank2): The input tensor.
1042+
dtype (torch.dtype): The floating dtype of the output tensor. Defaults to torch.float32.
1043+
value_constraint: Constraint on the value of the scalar.
1044+
default: ValueConstraint.NONE
1045+
if ValueConstraint.NON_NEGATIVE, the scalar must be non-negative
1046+
if ValueConstraint.POSITIVE, the scalar must be positive
1047+
1048+
Returns:
1049+
A torch.Tensor of dtype dtype and shape (4, 4).
1050+
"""
1051+
return to_FloatingTensorBroadcastableRank2(
1052+
x, (4, 4), dtype, value_constraint=value_constraint, do_broadcast_to=False
1053+
)

fvdb/viz/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright Contributors to the OpenVDB Project
22
# SPDX-License-Identifier: Apache-2.0
33
#
4-
from .._Cpp.viz import Viewer, GaussianSplat3dView
4+
from .viewer import GaussianSplat3dView, Viewer
55

66
__all__ = [
77
"Viewer",

0 commit comments

Comments
 (0)