From b40ec1e8637a2da1e3c237e8be864fb72e4f1274 Mon Sep 17 00:00:00 2001 From: Matt Tancik Date: Thu, 7 Jul 2022 12:05:15 -0700 Subject: [PATCH] Add missing inits --- pyrad/cameras/__init__.py | 13 ++++++ pyrad/cameras/camera_paths.py | 76 ++++++++++++++++---------------- pyrad/cameras/cameras.py | 10 ++++- pyrad/cameras/transformations.py | 1 + pyrad/cuda/__init__.py | 13 ++++++ pyrad/renderers/__init__.py | 13 ++++++ pyrad/viewer/server/socket.py | 14 ++++++ 7 files changed, 101 insertions(+), 39 deletions(-) create mode 100644 pyrad/cameras/__init__.py create mode 100644 pyrad/cuda/__init__.py create mode 100644 pyrad/renderers/__init__.py diff --git a/pyrad/cameras/__init__.py b/pyrad/cameras/__init__.py new file mode 100644 index 000000000..02655775e --- /dev/null +++ b/pyrad/cameras/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2022 The Plenoptix Team. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/pyrad/cameras/camera_paths.py b/pyrad/cameras/camera_paths.py index 97c58dca1..35237f712 100644 --- a/pyrad/cameras/camera_paths.py +++ b/pyrad/cameras/camera_paths.py @@ -16,50 +16,52 @@ Code for camera paths. """ +from dataclasses import dataclass from typing import List import torch from pyrad.cameras.cameras import Camera, get_camera, get_intrinsics_from_intrinsics_matrix -from pyrad.cameras.transformations import get_interpolated_poses, get_interpolated_poses_many -import numpy as np +from pyrad.cameras.transformations import get_interpolated_poses_many +@dataclass class CameraPath: + """A camera path.""" + + cameras: List[Camera] + + +def get_interpolated_camera_path(camera_a: Camera, camera_b: Camera, steps: int) -> CameraPath: + """Generate a camera path between two cameras. + + Args: + camera_a: The first camera. + camera_b: The second camera. + steps: The number of steps to interpolate between the two cameras. + + Returns: + CameraPath: A camera path. """ - Base class for camera path. + Ka = camera_a.get_intrinsics_matrix() + pose_a = camera_a.get_camera_to_world_h() + Kb = camera_b.get_intrinsics_matrix() + pose_b = camera_b.get_camera_to_world_h() + poses = [pose_a, pose_b] + Ks = [Ka, Kb] + poses, Ks = get_interpolated_poses_many(poses, Ks, steps_per_transition=steps) + # create a list of cameras + + cameras = [] + for pose, K in zip(poses, Ks): + intrinsics = get_intrinsics_from_intrinsics_matrix(K) + camera_to_world = torch.from_numpy(pose[:3]) + camera = get_camera(intrinsics, camera_to_world, None) + cameras.append(camera) + return CameraPath(cameras=cameras) + + +def get_spiral_path(camera_a: Camera, camera_b: Camera, steps: int) -> CameraPath: """ - - def __init__(self) -> None: - pass - - -class InterpolatedCameraPath(CameraPath): + Returns a list of camera in a sprial. """ - Class to interpolate between two cameras. - """ - - def __init__(self, camera_a: Camera, camera_b: Camera) -> None: - super().__init__() - self.camera_a = camera_a - self.camera_b = camera_b - - def get_path(self, steps: int) -> List[Camera]: - """ - Returns a list of cameras. - """ - K_a = self.camera_a.get_intrinsics_matrix() - pose_a = self.camera_a.get_camera_to_world_h() - K_b = self.camera_b.get_intrinsics_matrix() - pose_b = self.camera_b.get_camera_to_world_h() - poses = [pose_a, pose_b] - Ks = [K_a, K_b] - poses, Ks = get_interpolated_poses_many(poses, Ks, steps_per_transition=steps) - # create a list of cameras - - cameras = [] - for pose, K in zip(poses, Ks): - intrinsics = get_intrinsics_from_intrinsics_matrix(K) - camera_to_world = torch.from_numpy(pose[:3]) - camera = get_camera(intrinsics, camera_to_world, None) - cameras.append(camera) - return cameras + raise NotImplementedError diff --git a/pyrad/cameras/cameras.py b/pyrad/cameras/cameras.py index 09bc000e5..aeea2098d 100644 --- a/pyrad/cameras/cameras.py +++ b/pyrad/cameras/cameras.py @@ -16,7 +16,6 @@ Camera Models """ from abc import abstractmethod -from dataclasses import dataclass from typing import Optional, Type import torch @@ -366,7 +365,14 @@ def get_camera_model(num_intrinsics_params: int) -> Type[Camera]: raise NotImplementedError -def get_camera(intrinsics, camera_to_world, camera_index=None): +def get_camera(intrinsics: TensorType["num_intrinsics"], camera_to_world: TensorType[3, 4], camera_index=None): + """Returns a transformed camera. + + Args: + intrinsics (TensorType["num_intrinsics"]): Intrinsics tensor. + camera_to_world (TensorType[3, 4]): Camera to world transformation. + camera_index (int): Camera index. + """ assert len(intrinsics.shape) == 1, "The intrinsics object should be a flat tensor." num_intrinsics_params = len(intrinsics) camera_class = get_camera_model(num_intrinsics_params) diff --git a/pyrad/cameras/transformations.py b/pyrad/cameras/transformations.py index c38710c87..3a57976ea 100644 --- a/pyrad/cameras/transformations.py +++ b/pyrad/cameras/transformations.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +# pylint: skip-file """ Camera transformation helper code. """ diff --git a/pyrad/cuda/__init__.py b/pyrad/cuda/__init__.py new file mode 100644 index 000000000..02655775e --- /dev/null +++ b/pyrad/cuda/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2022 The Plenoptix Team. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/pyrad/renderers/__init__.py b/pyrad/renderers/__init__.py new file mode 100644 index 000000000..02655775e --- /dev/null +++ b/pyrad/renderers/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2022 The Plenoptix Team. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/pyrad/viewer/server/socket.py b/pyrad/viewer/server/socket.py index 90ed9653b..d37c95a58 100644 --- a/pyrad/viewer/server/socket.py +++ b/pyrad/viewer/server/socket.py @@ -1,3 +1,17 @@ +# Copyright 2022 The Plenoptix Team. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + # https://gist.github.com/jeffbass/ebf877e964c9a0b84272 # zmqimage.py -- classes to send, receive and display cv2 images via zmq