Skip to content

Commit

Permalink
Interactive Wisp checkpoint visualization in Jupyter notebooks. (#140)
Browse files Browse the repository at this point in the history
Added:
- Example notebook with live camera control of a pretrained checkpoint
- Utilities for working with ipycanvas and jupyter

Changed:
- Small adjustment to camera controller API to make `zoom` behavior more
predictable
- Fix in renderers factory

Remaining:
- Left API TODOs to make this work smoother in the future

Signed-off-by: Maria Masha Shugrina <mshugrina@nvidia.com>
Co-authored-by: Maria Masha Shugrina <mshugrina@nvidia.com>
  • Loading branch information
shumash and Maria Masha Shugrina committed Apr 14, 2023
1 parent 6e2e72c commit cb47e10
Show file tree
Hide file tree
Showing 6 changed files with 721 additions and 5 deletions.
268 changes: 268 additions & 0 deletions examples/notebook/view_pretrained.ipynb

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion wisp/renderer/core/api/renderers_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def _neural_field_to_renderer_cls(pipeline: Pipeline) -> Type[RayTracedRenderer]
else: # Try querying all parent(nef) + tracer combos for compatibility
bases = field_type.__bases__
if len(bases) > 0:
type_queue.append(*bases)
for b in bases:
type_queue.append(b)

if renderer_cls is not None:
break # Found a renderer class
Expand Down
13 changes: 12 additions & 1 deletion wisp/renderer/core/control/camera_controller_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ def start_pan(self, pan_direction, velocity=None, deaccelaration=None):
self._current_pan_velocity *= -1

def zoom(self, amount):
""" Performs end-to-end zoom while taking care of interaction bookkeeping internally. Useful for e.g.
hooking up a zoom-in button.
"""
self.start_pan("backward" if amount < 0 else "forward", 1, 1)
self._do_zoom(amount)
self.end_pan()

def _do_zoom(self, amount):
""" Performs a zoom step during interaction e.g. with mouse. This function does not do necessary
book-keeping.
"""
if self.camera.lens_type == 'ortho':
# Under orthographic projection, objects are not affected by distance to the camera
amount = self._zoom_ortho_distance_weight * self.camera.fov_distance * abs(amount) * np.sign(amount)
Expand All @@ -115,7 +126,7 @@ def progress_pan(self, dt):
('yz' in self.planes_forbidden_zooming_through and new_pos[0].sign() * cam_pos[0].sign() == -1):
self._remaining_pan_time = 0
else:
self.zoom(pos_delta)
self._do_zoom(pos_delta)
elif self._current_pan_direction in ('right', 'left'):
dist = self.camera.cam_pos().norm()
pos_delta *= self._key_pan_distance_weight * dist
Expand Down
6 changes: 3 additions & 3 deletions wisp/renderer/core/render_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ def set_full_resolution(self):
self.res_y = self.camera.height
self.interactive_mode = False

def set_low_resolution(self):
self.res_x = self.camera.width // 4
self.res_y = self.camera.height // 4
def set_low_resolution(self, downscale_factor: int = 4):
self.res_x = self.camera.width // downscale_factor
self.res_y = self.camera.height // downscale_factor
self.interactive_mode = True

def resize_canvas(self, width, height):
Expand Down
Empty file added wisp/renderer/web/__init__.py
Empty file.

0 comments on commit cb47e10

Please sign in to comment.