mirror of
https://github.com/facebookresearch/pytorch3d.git
synced 2025-07-31 10:52:50 +08:00
Summary: Converts the directory specified to use the Ruff formatter in pyfmt ruff_dog If this diff causes merge conflicts when rebasing, please run `hg status -n -0 --change . -I '**/*.{py,pyi}' | xargs -0 arc pyfmt` on your diff, and amend any changes before rebasing onto latest. That should help reduce or eliminate any merge conflicts. allow-large-files Reviewed By: bottler Differential Revision: D66472063 fbshipit-source-id: 35841cb397e4f8e066e2159550d2f56b403b1bef
133 lines
4.0 KiB
Python
133 lines
4.0 KiB
Python
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
# All rights reserved.
|
|
#
|
|
# This source code is licensed under the BSD-style license found in the
|
|
# LICENSE file in the root directory of this source tree.
|
|
|
|
"""Tests for the orthogonal projection."""
|
|
|
|
import logging
|
|
import sys
|
|
import unittest
|
|
from os import path
|
|
|
|
import numpy as np
|
|
import torch
|
|
|
|
|
|
# Making sure you can run this, even if pulsar hasn't been installed yet.
|
|
sys.path.insert(0, path.join(path.dirname(__file__), ".."))
|
|
devices = [torch.device("cuda"), torch.device("cpu")]
|
|
|
|
|
|
class TestOrtho(unittest.TestCase):
|
|
"""Test the orthogonal projection."""
|
|
|
|
def test_basic(self):
|
|
"""Basic forward test of the orthogonal projection."""
|
|
from pytorch3d.renderer.points.pulsar import Renderer
|
|
|
|
n_points = 10
|
|
width = 1000
|
|
height = 1000
|
|
renderer_left = Renderer(
|
|
width,
|
|
height,
|
|
n_points,
|
|
right_handed_system=False,
|
|
orthogonal_projection=True,
|
|
)
|
|
renderer_right = Renderer(
|
|
width,
|
|
height,
|
|
n_points,
|
|
right_handed_system=True,
|
|
orthogonal_projection=True,
|
|
)
|
|
# Generate sample data.
|
|
torch.manual_seed(1)
|
|
vert_pos = torch.rand(n_points, 3, dtype=torch.float32) * 10.0
|
|
vert_pos[:, 2] += 25.0
|
|
vert_pos[:, :2] -= 5.0
|
|
vert_pos_neg = vert_pos.clone()
|
|
vert_pos_neg[:, 2] *= -1.0
|
|
vert_col = torch.rand(n_points, 3, dtype=torch.float32)
|
|
vert_rad = torch.rand(n_points, dtype=torch.float32)
|
|
cam_params = torch.tensor(
|
|
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 20.0], dtype=torch.float32
|
|
)
|
|
for device in devices:
|
|
vert_pos = vert_pos.to(device)
|
|
vert_pos_neg = vert_pos_neg.to(device)
|
|
vert_col = vert_col.to(device)
|
|
vert_rad = vert_rad.to(device)
|
|
cam_params = cam_params.to(device)
|
|
renderer_left = renderer_left.to(device)
|
|
renderer_right = renderer_right.to(device)
|
|
result_left = (
|
|
renderer_left.forward(
|
|
vert_pos,
|
|
vert_col,
|
|
vert_rad,
|
|
cam_params,
|
|
1.0e-1,
|
|
45.0,
|
|
percent_allowed_difference=0.01,
|
|
)
|
|
.cpu()
|
|
.detach()
|
|
.numpy()
|
|
)
|
|
hits_left = (
|
|
renderer_left.forward(
|
|
vert_pos,
|
|
vert_col,
|
|
vert_rad,
|
|
cam_params,
|
|
1.0e-1,
|
|
45.0,
|
|
percent_allowed_difference=0.01,
|
|
mode=1,
|
|
)
|
|
.cpu()
|
|
.detach()
|
|
.numpy()
|
|
)
|
|
result_right = (
|
|
renderer_right.forward(
|
|
vert_pos_neg,
|
|
vert_col,
|
|
vert_rad,
|
|
cam_params,
|
|
1.0e-1,
|
|
45.0,
|
|
percent_allowed_difference=0.01,
|
|
)
|
|
.cpu()
|
|
.detach()
|
|
.numpy()
|
|
)
|
|
hits_right = (
|
|
renderer_right.forward(
|
|
vert_pos_neg,
|
|
vert_col,
|
|
vert_rad,
|
|
cam_params,
|
|
1.0e-1,
|
|
45.0,
|
|
percent_allowed_difference=0.01,
|
|
mode=1,
|
|
)
|
|
.cpu()
|
|
.detach()
|
|
.numpy()
|
|
)
|
|
self.assertTrue(np.allclose(result_left, result_right))
|
|
self.assertTrue(np.allclose(hits_left, hits_right))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
logging.basicConfig(level=logging.INFO)
|
|
logging.getLogger("pulsar.renderer").setLevel(logging.WARN)
|
|
unittest.main()
|