diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/__init__.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..9fecfe5d112229a6c455b03e8cee3f781c3b2a57 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/__init__.py @@ -0,0 +1,9 @@ +# 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. + +# pyre-unsafe + +__version__ = "0.7.7" diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/__init__.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..affe30d69f53faf7bf569d402cd4aedfdae4bf3b --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/__init__.py @@ -0,0 +1,89 @@ +# 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. + +# pyre-unsafe + +from .blending import ( + BlendParams, + hard_rgb_blend, + sigmoid_alpha_blend, + softmax_rgb_blend, +) +from .camera_utils import join_cameras_as_batch, rotate_on_spot +from .cameras import ( # deprecated # deprecated # deprecated # deprecated + camera_position_from_spherical_angles, + CamerasBase, + FoVOrthographicCameras, + FoVPerspectiveCameras, + get_world_to_view_transform, + look_at_rotation, + look_at_view_transform, + OpenGLOrthographicCameras, + OpenGLPerspectiveCameras, + OrthographicCameras, + PerspectiveCameras, + SfMOrthographicCameras, + SfMPerspectiveCameras, +) +from .implicit import ( + AbsorptionOnlyRaymarcher, + EmissionAbsorptionRaymarcher, + GridRaysampler, + HarmonicEmbedding, + HeterogeneousRayBundle, + ImplicitRenderer, + MonteCarloRaysampler, + MultinomialRaysampler, + NDCGridRaysampler, + NDCMultinomialRaysampler, + ray_bundle_to_ray_points, + ray_bundle_variables_to_ray_points, + RayBundle, + VolumeRenderer, + VolumeSampler, +) +from .lighting import AmbientLights, diffuse, DirectionalLights, PointLights, specular +from .materials import Materials +from .mesh import ( + gouraud_shading, + HardFlatShader, + HardGouraudShader, + HardPhongShader, + MeshRasterizer, + MeshRenderer, + MeshRendererWithFragments, + phong_shading, + RasterizationSettings, + rasterize_meshes, + SoftGouraudShader, + SoftPhongShader, + SoftSilhouetteShader, + SplatterPhongShader, + Textures, + TexturesAtlas, + TexturesUV, + TexturesVertex, +) + +from .points import ( + AlphaCompositor, + NormWeightedCompositor, + PointsRasterizationSettings, + PointsRasterizer, + PointsRenderer, + PulsarPointsRenderer, + rasterize_points, +) +from .splatter_blend import SplatterBlender +from .utils import ( + convert_to_tensors_and_broadcast, + ndc_grid_sample, + ndc_to_grid_sample_coords, + TensorProperties, +) + + +__all__ = [k for k in globals().keys() if not k.startswith("_")] diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/blending.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/blending.py new file mode 100644 index 0000000000000000000000000000000000000000..b84b91ab6b7673a46f99fc058badb57ceb080043 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/blending.py @@ -0,0 +1,241 @@ +# 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. + +# pyre-unsafe + +from typing import NamedTuple, Sequence, Union + +import torch +from pytorch3d import _C +from pytorch3d.common.datatypes import Device + +# Example functions for blending the top K colors per pixel using the outputs +# from rasterization. +# NOTE: All blending function should return an RGBA image per batch element + + +class BlendParams(NamedTuple): + """ + Data class to store blending params with defaults + + Members: + sigma (float): For SoftmaxPhong, controls the width of the sigmoid + function used to calculate the 2D distance based probability. Determines + the sharpness of the edges of the shape. Higher => faces have less defined + edges. For SplatterPhong, this is the standard deviation of the Gaussian + kernel. Higher => splats have a stronger effect and the rendered image is + more blurry. + gamma (float): Controls the scaling of the exponential function used + to set the opacity of the color. + Higher => faces are more transparent. + background_color: RGB values for the background color as a tuple or + as a tensor of three floats. + """ + + sigma: float = 1e-4 + gamma: float = 1e-4 + background_color: Union[torch.Tensor, Sequence[float]] = (1.0, 1.0, 1.0) + + +def _get_background_color( + blend_params: BlendParams, device: Device, dtype=torch.float32 +) -> torch.Tensor: + background_color_ = blend_params.background_color + if isinstance(background_color_, torch.Tensor): + background_color = background_color_.to(device) + else: + background_color = torch.tensor(background_color_, dtype=dtype, device=device) + return background_color + + +def hard_rgb_blend( + colors: torch.Tensor, fragments, blend_params: BlendParams +) -> torch.Tensor: + """ + Naive blending of top K faces to return an RGBA image + - **RGB** - choose color of the closest point i.e. K=0 + - **A** - 1.0 + + Args: + colors: (N, H, W, K, 3) RGB color for each of the top K faces per pixel. + fragments: the outputs of rasterization. From this we use + - pix_to_face: LongTensor of shape (N, H, W, K) specifying the indices + of the faces (in the packed representation) which + overlap each pixel in the image. This is used to + determine the output shape. + blend_params: BlendParams instance that contains a background_color + field specifying the color for the background + Returns: + RGBA pixel_colors: (N, H, W, 4) + """ + background_color = _get_background_color(blend_params, fragments.pix_to_face.device) + + # Mask for the background. + is_background = fragments.pix_to_face[..., 0] < 0 # (N, H, W) + + # Find out how much background_color needs to be expanded to be used for masked_scatter. + num_background_pixels = is_background.sum() + + # Set background color. + pixel_colors = colors[..., 0, :].masked_scatter( + is_background[..., None], + background_color[None, :].expand(num_background_pixels, -1), + ) # (N, H, W, 3) + + # Concat with the alpha channel. + alpha = (~is_background).type_as(pixel_colors)[..., None] + + return torch.cat([pixel_colors, alpha], dim=-1) # (N, H, W, 4) + + +# Wrapper for the C++/CUDA Implementation of sigmoid alpha blend. +class _SigmoidAlphaBlend(torch.autograd.Function): + @staticmethod + def forward(ctx, dists, pix_to_face, sigma): + alphas = _C.sigmoid_alpha_blend(dists, pix_to_face, sigma) + ctx.save_for_backward(dists, pix_to_face, alphas) + ctx.sigma = sigma + return alphas + + @staticmethod + def backward(ctx, grad_alphas): + dists, pix_to_face, alphas = ctx.saved_tensors + sigma = ctx.sigma + grad_dists = _C.sigmoid_alpha_blend_backward( + grad_alphas, alphas, dists, pix_to_face, sigma + ) + return grad_dists, None, None + + +_sigmoid_alpha = _SigmoidAlphaBlend.apply + + +def sigmoid_alpha_blend(colors, fragments, blend_params: BlendParams) -> torch.Tensor: + """ + Silhouette blending to return an RGBA image + - **RGB** - choose color of the closest point. + - **A** - blend based on the 2D distance based probability map [1]. + + Args: + colors: (N, H, W, K, 3) RGB color for each of the top K faces per pixel. + fragments: the outputs of rasterization. From this we use + - pix_to_face: LongTensor of shape (N, H, W, K) specifying the indices + of the faces (in the packed representation) which + overlap each pixel in the image. + - dists: FloatTensor of shape (N, H, W, K) specifying + the 2D euclidean distance from the center of each pixel + to each of the top K overlapping faces. + + Returns: + RGBA pixel_colors: (N, H, W, 4) + + [1] Liu et al, 'Soft Rasterizer: A Differentiable Renderer for Image-based + 3D Reasoning', ICCV 2019 + """ + N, H, W, K = fragments.pix_to_face.shape + pixel_colors = torch.ones((N, H, W, 4), dtype=colors.dtype, device=colors.device) + pixel_colors[..., :3] = colors[..., 0, :] + alpha = _sigmoid_alpha(fragments.dists, fragments.pix_to_face, blend_params.sigma) + pixel_colors[..., 3] = alpha + return pixel_colors + + +def softmax_rgb_blend( + colors: torch.Tensor, + fragments, + blend_params: BlendParams, + znear: Union[float, torch.Tensor] = 1.0, + zfar: Union[float, torch.Tensor] = 100, +) -> torch.Tensor: + """ + RGB and alpha channel blending to return an RGBA image based on the method + proposed in [1] + - **RGB** - blend the colors based on the 2D distance based probability map and + relative z distances. + - **A** - blend based on the 2D distance based probability map. + + Args: + colors: (N, H, W, K, 3) RGB color for each of the top K faces per pixel. + fragments: namedtuple with outputs of rasterization. We use properties + - pix_to_face: LongTensor of shape (N, H, W, K) specifying the indices + of the faces (in the packed representation) which + overlap each pixel in the image. + - dists: FloatTensor of shape (N, H, W, K) specifying + the 2D euclidean distance from the center of each pixel + to each of the top K overlapping faces. + - zbuf: FloatTensor of shape (N, H, W, K) specifying + the interpolated depth from each pixel to to each of the + top K overlapping faces. + blend_params: instance of BlendParams dataclass containing properties + - sigma: float, parameter which controls the width of the sigmoid + function used to calculate the 2D distance based probability. + Sigma controls the sharpness of the edges of the shape. + - gamma: float, parameter which controls the scaling of the + exponential function used to control the opacity of the color. + - background_color: (3) element list/tuple/torch.Tensor specifying + the RGB values for the background color. + znear: float, near clipping plane in the z direction + zfar: float, far clipping plane in the z direction + + Returns: + RGBA pixel_colors: (N, H, W, 4) + + [0] Shichen Liu et al, 'Soft Rasterizer: A Differentiable Renderer for + Image-based 3D Reasoning' + """ + + N, H, W, K = fragments.pix_to_face.shape + pixel_colors = torch.ones((N, H, W, 4), dtype=colors.dtype, device=colors.device) + background_color = _get_background_color(blend_params, fragments.pix_to_face.device) + + # Weight for background color + eps = 1e-10 + + # Mask for padded pixels. + mask = fragments.pix_to_face >= 0 + + # Sigmoid probability map based on the distance of the pixel to the face. + prob_map = torch.sigmoid(-fragments.dists / blend_params.sigma) * mask + + # The cumulative product ensures that alpha will be 0.0 if at least 1 + # face fully covers the pixel as for that face, prob will be 1.0. + # This results in a multiplication by 0.0 because of the (1.0 - prob) + # term. Therefore 1.0 - alpha will be 1.0. + alpha = torch.prod((1.0 - prob_map), dim=-1) + + # Weights for each face. Adjust the exponential by the max z to prevent + # overflow. zbuf shape (N, H, W, K), find max over K. + # TODO: there may still be some instability in the exponent calculation. + + # Reshape to be compatible with (N, H, W, K) values in fragments + if torch.is_tensor(zfar): + zfar = zfar[:, None, None, None] + if torch.is_tensor(znear): + znear = znear[:, None, None, None] + + # pyre-fixme[6]: Expected `float` but got `Union[float, Tensor]` + z_inv = (zfar - fragments.zbuf) / (zfar - znear) * mask + # pyre-fixme[6]: Expected `Tensor` but got `float` + z_inv_max = torch.max(z_inv, dim=-1).values[..., None].clamp(min=eps) + # pyre-fixme[6]: Expected `Tensor` but got `float` + weights_num = prob_map * torch.exp((z_inv - z_inv_max) / blend_params.gamma) + + # Also apply exp normalize trick for the background color weight. + # Clamp to ensure delta is never 0. + # pyre-fixme[6]: Expected `Tensor` for 1st param but got `float`. + delta = torch.exp((eps - z_inv_max) / blend_params.gamma).clamp(min=eps) + + # Normalize weights. + # weights_num shape: (N, H, W, K). Sum over K and divide through by the sum. + denom = weights_num.sum(dim=-1)[..., None] + delta + + # Sum: weights * textures + background color + weighted_colors = (weights_num[..., None] * colors).sum(dim=-2) + weighted_background = delta * background_color + pixel_colors[..., :3] = (weighted_colors + weighted_background) / denom + pixel_colors[..., 3] = 1.0 - alpha + + return pixel_colors diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/camera_conversions.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/camera_conversions.py new file mode 100644 index 0000000000000000000000000000000000000000..d18707a318dd9e66e4f5f7763ae0c00a03952310 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/camera_conversions.py @@ -0,0 +1,194 @@ +# 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. + +# pyre-unsafe + +import logging +from typing import Tuple + +import torch + +from ..transforms import matrix_to_rotation_6d +from .cameras import PerspectiveCameras + + +LOGGER = logging.getLogger(__name__) + + +def _cameras_from_opencv_projection( + R: torch.Tensor, + tvec: torch.Tensor, + camera_matrix: torch.Tensor, + image_size: torch.Tensor, +) -> PerspectiveCameras: + focal_length = torch.stack([camera_matrix[:, 0, 0], camera_matrix[:, 1, 1]], dim=-1) + principal_point = camera_matrix[:, :2, 2] + + # Retype the image_size correctly and flip to width, height. + image_size_wh = image_size.to(R).flip(dims=(1,)) + + # Screen to NDC conversion: + # For non square images, we scale the points such that smallest side + # has range [-1, 1] and the largest side has range [-u, u], with u > 1. + # This convention is consistent with the PyTorch3D renderer, as well as + # the transformation function `get_ndc_to_screen_transform`. + scale = image_size_wh.to(R).min(dim=1, keepdim=True)[0] / 2.0 + scale = scale.expand(-1, 2) + c0 = image_size_wh / 2.0 + + # Get the PyTorch3D focal length and principal point. + focal_pytorch3d = focal_length / scale + p0_pytorch3d = -(principal_point - c0) / scale + + # For R, T we flip x, y axes (opencv screen space has an opposite + # orientation of screen axes). + # We also transpose R (opencv multiplies points from the opposite=left side). + R_pytorch3d = R.clone().permute(0, 2, 1) + T_pytorch3d = tvec.clone() + R_pytorch3d[:, :, :2] *= -1 + T_pytorch3d[:, :2] *= -1 + + return PerspectiveCameras( + R=R_pytorch3d, + T=T_pytorch3d, + focal_length=focal_pytorch3d, + principal_point=p0_pytorch3d, + image_size=image_size, + device=R.device, + ) + + +def _opencv_from_cameras_projection( + cameras: PerspectiveCameras, + image_size: torch.Tensor, +) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]: + R_pytorch3d = cameras.R.clone() + T_pytorch3d = cameras.T.clone() + focal_pytorch3d = cameras.focal_length + p0_pytorch3d = cameras.principal_point + T_pytorch3d[:, :2] *= -1 + R_pytorch3d[:, :, :2] *= -1 + tvec = T_pytorch3d + R = R_pytorch3d.permute(0, 2, 1) + + # Retype the image_size correctly and flip to width, height. + image_size_wh = image_size.to(R).flip(dims=(1,)) + + # NDC to screen conversion. + scale = image_size_wh.to(R).min(dim=1, keepdim=True)[0] / 2.0 + scale = scale.expand(-1, 2) + c0 = image_size_wh / 2.0 + + principal_point = -p0_pytorch3d * scale + c0 + focal_length = focal_pytorch3d * scale + + camera_matrix = torch.zeros_like(R) + camera_matrix[:, :2, 2] = principal_point + camera_matrix[:, 2, 2] = 1.0 + camera_matrix[:, 0, 0] = focal_length[:, 0] + camera_matrix[:, 1, 1] = focal_length[:, 1] + return R, tvec, camera_matrix + + +def _pulsar_from_opencv_projection( + R: torch.Tensor, + tvec: torch.Tensor, + camera_matrix: torch.Tensor, + image_size: torch.Tensor, + znear: float = 0.1, +) -> torch.Tensor: + assert len(camera_matrix.size()) == 3, "This function requires batched inputs!" + assert len(R.size()) == 3, "This function requires batched inputs!" + assert len(tvec.size()) in (2, 3), "This function reuqires batched inputs!" + + # Validate parameters. + image_size_wh = image_size.to(R).flip(dims=(1,)) + assert torch.all( + image_size_wh > 0 + ), "height and width must be positive but min is: %s" % ( + str(image_size_wh.min().item()) + ) + assert ( + camera_matrix.size(1) == 3 and camera_matrix.size(2) == 3 + ), "Incorrect camera matrix shape: expected 3x3 but got %dx%d" % ( + camera_matrix.size(1), + camera_matrix.size(2), + ) + assert ( + R.size(1) == 3 and R.size(2) == 3 + ), "Incorrect R shape: expected 3x3 but got %dx%d" % ( + R.size(1), + R.size(2), + ) + if len(tvec.size()) == 2: + tvec = tvec.unsqueeze(2) + assert ( + tvec.size(1) == 3 and tvec.size(2) == 1 + ), "Incorrect tvec shape: expected 3x1 but got %dx%d" % ( + tvec.size(1), + tvec.size(2), + ) + # Check batch size. + batch_size = camera_matrix.size(0) + assert R.size(0) == batch_size, "Expected R to have batch size %d. Has size %d." % ( + batch_size, + R.size(0), + ) + assert ( + tvec.size(0) == batch_size + ), "Expected tvec to have batch size %d. Has size %d." % ( + batch_size, + tvec.size(0), + ) + # Check image sizes. + image_w = image_size_wh[0, 0] + image_h = image_size_wh[0, 1] + assert torch.all( + image_size_wh[:, 0] == image_w + ), "All images in a batch must have the same width!" + assert torch.all( + image_size_wh[:, 1] == image_h + ), "All images in a batch must have the same height!" + # Focal length. + fx = camera_matrix[:, 0, 0].unsqueeze(1) + fy = camera_matrix[:, 1, 1].unsqueeze(1) + # Check that we introduce less than 1% error by averaging the focal lengths. + fx_y = fx / fy + if torch.any(fx_y > 1.01) or torch.any(fx_y < 0.99): + LOGGER.warning( + "Pulsar only supports a single focal lengths. For converting OpenCV " + "focal lengths, we average them for x and y directions. " + "The focal lengths for x and y you provided differ by more than 1%, " + "which means this could introduce a noticeable error." + ) + f = (fx + fy) / 2 + # Normalize f into normalized device coordinates. + focal_length_px = f / image_w + # Transfer into focal_length and sensor_width. + focal_length = torch.tensor([znear - 1e-5], dtype=torch.float32, device=R.device) + focal_length = focal_length[None, :].repeat(batch_size, 1) + sensor_width = focal_length / focal_length_px + # Principal point. + cx = camera_matrix[:, 0, 2].unsqueeze(1) + cy = camera_matrix[:, 1, 2].unsqueeze(1) + # Transfer principal point offset into centered offset. + cx = -(cx - image_w / 2) + cy = cy - image_h / 2 + # Concatenate to final vector. + param = torch.cat([focal_length, sensor_width, cx, cy], dim=1) + R_trans = R.permute(0, 2, 1) + cam_pos = -torch.bmm(R_trans, tvec).squeeze(2) + cam_rot = matrix_to_rotation_6d(R_trans) + cam_params = torch.cat([cam_pos, cam_rot, param], dim=1) + return cam_params + + +def _pulsar_from_cameras_projection( + cameras: PerspectiveCameras, + image_size: torch.Tensor, +) -> torch.Tensor: + opencv_R, opencv_T, opencv_K = _opencv_from_cameras_projection(cameras, image_size) + return _pulsar_from_opencv_projection(opencv_R, opencv_T, opencv_K, image_size) diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/camera_utils.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/camera_utils.py new file mode 100644 index 0000000000000000000000000000000000000000..e56563156098ffeacd74ad692069a46838006f37 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/camera_utils.py @@ -0,0 +1,209 @@ +# 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. + +# pyre-unsafe + +from typing import Sequence, Tuple + +import torch +from pytorch3d.transforms import Transform3d + +from .cameras import CamerasBase + + +def camera_to_eye_at_up( + world_to_view_transform: Transform3d, +) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]: + """ + Given a world to view transform, return the eye, at and up vectors which + represent its position. + + For example, if cam is a camera object, then after running + + .. code-block:: + + from cameras import look_at_view_transform + eye, at, up = camera_to_eye_at_up(cam.get_world_to_view_transform()) + R, T = look_at_view_transform(eye=eye, at=at, up=up) + + any other camera created from R and T will have the same world to view + transform as cam. + + Also, given a camera position R and T, then after running: + + .. code-block:: + + from cameras import get_world_to_view_transform, look_at_view_transform + eye, at, up = camera_to_eye_at_up(get_world_to_view_transform(R=R, T=T)) + R2, T2 = look_at_view_transform(eye=eye, at=at, up=up) + + R2 will equal R and T2 will equal T. + + Args: + world_to_view_transform: Transform3d representing the extrinsic + transformation of N cameras. + + Returns: + eye: FloatTensor of shape [N, 3] representing the camera centers in world space. + at: FloatTensor of shape [N, 3] representing points in world space directly in + front of the cameras e.g. the positions of objects to be viewed by the + cameras. + up: FloatTensor of shape [N, 3] representing vectors in world space which + when projected on to the camera plane point upwards. + """ + cam_trans = world_to_view_transform.inverse() + # In the PyTorch3D right handed coordinate system, the camera in view space + # is always at the origin looking along the +z axis. + + # The up vector is not a position so cannot be transformed with + # transform_points. However the position eye+up above the camera + # (whose position vector in the camera coordinate frame is an up vector) + # can be transformed with transform_points. + eye_at_up_view = torch.tensor( + [[0, 0, 0], [0, 0, 1], [0, 1, 0]], dtype=torch.float32, device=cam_trans.device + ) + eye_at_up_world = cam_trans.transform_points(eye_at_up_view).reshape(-1, 3, 3) + + eye, at, up_plus_eye = eye_at_up_world.unbind(1) + up = up_plus_eye - eye + return eye, at, up + + +def rotate_on_spot( + R: torch.Tensor, T: torch.Tensor, rotation: torch.Tensor +) -> Tuple[torch.Tensor, torch.Tensor]: + """ + Given a camera position as R and T (batched or not), + and a rotation matrix (batched or not) + return a new R and T representing camera position(s) + in the same location but rotated on the spot by the + given rotation. In particular the new world to view + rotation will be the previous one followed by the inverse + of the given rotation. + + For example, adding the following lines before constructing a camera + will make the camera point a little to the right of where it + otherwise would have been. + + .. code-block:: + + from math import radians + from pytorch3d.transforms import axis_angle_to_matrix + angles = [0, radians(10), 0] + rotation = axis_angle_to_matrix(torch.FloatTensor(angles)) + R, T = rotate_on_spot(R, T, rotation) + + Note here that if you have a column vector, then when you + premultiply it by this `rotation` (see the rotation_conversions doc), + then it will be rotated anticlockwise if facing the -y axis. + In our context, where we postmultiply row vectors to transform them, + `rotation` will rotate the camera clockwise around the -y axis + (i.e. when looking down), which is a turn to the right. + + If angles was [radians(10), 0, 0], the camera would get pointed + up a bit instead. + + If angles was [0, 0, radians(10)], the camera would be rotated anticlockwise + a bit, so the image would appear rotated clockwise from how it + otherwise would have been. + + If you want to translate the camera from the origin in camera + coordinates, this is simple and does not need a separate function. + In particular, a translation by X = [a, b, c] would cause + the camera to move a units left, b units up, and c units + forward. This is achieved by using T-X in place of T. + + Args: + R: FloatTensor of shape [3, 3] or [N, 3, 3] + T: FloatTensor of shape [3] or [N, 3] + rotation: FloatTensor of shape [3, 3] or [n, 3, 3] + where if neither n nor N is 1, then n and N must be equal. + + Returns: + R: FloatTensor of shape [max(N, n), 3, 3] + T: FloatTensor of shape [max(N, n), 3] + """ + if R.ndim == 2: + R = R[None] + if T.ndim == 1: + T = T[None] + if rotation.ndim == 2: + rotation = rotation[None] + + if R.ndim != 3 or R.shape[1:] != (3, 3): + raise ValueError("Invalid R") + if T.ndim != 2 or T.shape[1] != 3: + raise ValueError("Invalid T") + if rotation.ndim != 3 or rotation.shape[1:] != (3, 3): + raise ValueError("Invalid rotation") + + new_R = R @ rotation.transpose(1, 2) + old_RT = torch.bmm(R, T[:, :, None]) + new_T = torch.matmul(new_R.transpose(1, 2), old_RT)[:, :, 0] + + return new_R, new_T + + +def join_cameras_as_batch(cameras_list: Sequence[CamerasBase]) -> CamerasBase: + """ + Create a batched cameras object by concatenating a list of input + cameras objects. All the tensor attributes will be joined along + the batch dimension. + + Args: + cameras_list: List of camera classes all of the same type and + on the same device. Each represents one or more cameras. + Returns: + cameras: single batched cameras object of the same + type as all the objects in the input list. + """ + # Get the type and fields to join from the first camera in the batch + c0 = cameras_list[0] + fields = c0._FIELDS + shared_fields = c0._SHARED_FIELDS + + if not all(isinstance(c, CamerasBase) for c in cameras_list): + raise ValueError("cameras in cameras_list must inherit from CamerasBase") + + if not all(type(c) is type(c0) for c in cameras_list[1:]): + raise ValueError("All cameras must be of the same type") + + if not all(c.device == c0.device for c in cameras_list[1:]): + raise ValueError("All cameras in the batch must be on the same device") + + # Concat the fields to make a batched tensor + kwargs = {} + kwargs["device"] = c0.device + + for field in fields: + field_not_none = [(getattr(c, field) is not None) for c in cameras_list] + if not any(field_not_none): + continue + if not all(field_not_none): + raise ValueError(f"Attribute {field} is inconsistently present") + + attrs_list = [getattr(c, field) for c in cameras_list] + + if field in shared_fields: + # Only needs to be set once + if not all(a == attrs_list[0] for a in attrs_list): + raise ValueError(f"Attribute {field} is not constant across inputs") + + # e.g. "in_ndc" is set as attribute "_in_ndc" on the class + # but provided as "in_ndc" in the input args + if field.startswith("_"): + field = field[1:] + + kwargs[field] = attrs_list[0] + elif isinstance(attrs_list[0], torch.Tensor): + # In the init, all inputs will be converted to + # batched tensors before set as attributes + # Join as a tensor along the batch dimension + kwargs[field] = torch.cat(attrs_list, dim=0) + else: + raise ValueError(f"Field {field} type is not supported for batching") + + return c0.__class__(**kwargs) diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/cameras.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/cameras.py new file mode 100644 index 0000000000000000000000000000000000000000..7ac72033bc61a5199792e228d25f75fd5fc50895 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/cameras.py @@ -0,0 +1,1874 @@ +# 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. + +# pyre-unsafe + +import math +import warnings +from typing import Any, Dict, List, Optional, Sequence, Tuple, Union + +import numpy as np +import torch +import torch.nn.functional as F +from pytorch3d.common.datatypes import Device +from pytorch3d.transforms import Rotate, Transform3d, Translate + +from .utils import convert_to_tensors_and_broadcast, TensorProperties + + +# Default values for rotation and translation matrices. +_R = torch.eye(3)[None] # (1, 3, 3) +_T = torch.zeros(1, 3) # (1, 3) + +# An input which is a float per batch element +_BatchFloatType = Union[float, Sequence[float], torch.Tensor] + +# one or two floats per batch element +_FocalLengthType = Union[ + float, Sequence[Tuple[float]], Sequence[Tuple[float, float]], torch.Tensor +] + + +class CamerasBase(TensorProperties): + """ + `CamerasBase` implements a base class for all cameras. + + For cameras, there are four different coordinate systems (or spaces) + - World coordinate system: This is the system the object lives - the world. + - Camera view coordinate system: This is the system that has its origin on + the camera and the Z-axis perpendicular to the image plane. + In PyTorch3D, we assume that +X points left, and +Y points up and + +Z points out from the image plane. + The transformation from world --> view happens after applying a rotation (R) + and translation (T) + - NDC coordinate system: This is the normalized coordinate system that confines + points in a volume the rendered part of the object or scene, also known as + view volume. For square images, given the PyTorch3D convention, (+1, +1, znear) + is the top left near corner, and (-1, -1, zfar) is the bottom right far + corner of the volume. + The transformation from view --> NDC happens after applying the camera + projection matrix (P) if defined in NDC space. + For non square images, we scale the points such that smallest side + has range [-1, 1] and the largest side has range [-u, u], with u > 1. + - Screen coordinate system: This is another representation of the view volume with + the XY coordinates defined in image space instead of a normalized space. + + An illustration of the coordinate systems can be found in pytorch3d/docs/notes/cameras.md. + + CameraBase defines methods that are common to all camera models: + - `get_camera_center` that returns the optical center of the camera in + world coordinates + - `get_world_to_view_transform` which returns a 3D transform from + world coordinates to the camera view coordinates (R, T) + - `get_full_projection_transform` which composes the projection + transform (P) with the world-to-view transform (R, T) + - `transform_points` which takes a set of input points in world coordinates and + projects to the space the camera is defined in (NDC or screen) + - `get_ndc_camera_transform` which defines the transform from screen/NDC to + PyTorch3D's NDC space + - `transform_points_ndc` which takes a set of points in world coordinates and + projects them to PyTorch3D's NDC space + - `transform_points_screen` which takes a set of points in world coordinates and + projects them to screen space + + For each new camera, one should implement the `get_projection_transform` + routine that returns the mapping from camera view coordinates to camera + coordinates (NDC or screen). + + Another useful function that is specific to each camera model is + `unproject_points` which sends points from camera coordinates (NDC or screen) + back to camera view or world coordinates depending on the `world_coordinates` + boolean argument of the function. + """ + + # Used in __getitem__ to index the relevant fields + # When creating a new camera, this should be set in the __init__ + _FIELDS: Tuple[str, ...] = () + + # Names of fields which are a constant property of the whole batch, rather + # than themselves a batch of data. + # When joining objects into a batch, they will have to agree. + _SHARED_FIELDS: Tuple[str, ...] = () + + def get_projection_transform(self, **kwargs): + """ + Calculate the projective transformation matrix. + + Args: + **kwargs: parameters for the projection can be passed in as keyword + arguments to override the default values set in `__init__`. + + Return: + a `Transform3d` object which represents a batch of projection + matrices of shape (N, 3, 3) + """ + raise NotImplementedError() + + def unproject_points(self, xy_depth: torch.Tensor, **kwargs): + """ + Transform input points from camera coordinates (NDC or screen) + to the world / camera coordinates. + + Each of the input points `xy_depth` of shape (..., 3) is + a concatenation of the x, y location and its depth. + + For instance, for an input 2D tensor of shape `(num_points, 3)` + `xy_depth` takes the following form: + `xy_depth[i] = [x[i], y[i], depth[i]]`, + for a each point at an index `i`. + + The following example demonstrates the relationship between + `transform_points` and `unproject_points`: + + .. code-block:: python + + cameras = # camera object derived from CamerasBase + xyz = # 3D points of shape (batch_size, num_points, 3) + # transform xyz to the camera view coordinates + xyz_cam = cameras.get_world_to_view_transform().transform_points(xyz) + # extract the depth of each point as the 3rd coord of xyz_cam + depth = xyz_cam[:, :, 2:] + # project the points xyz to the camera + xy = cameras.transform_points(xyz)[:, :, :2] + # append depth to xy + xy_depth = torch.cat((xy, depth), dim=2) + # unproject to the world coordinates + xyz_unproj_world = cameras.unproject_points(xy_depth, world_coordinates=True) + print(torch.allclose(xyz, xyz_unproj_world)) # True + # unproject to the camera coordinates + xyz_unproj = cameras.unproject_points(xy_depth, world_coordinates=False) + print(torch.allclose(xyz_cam, xyz_unproj)) # True + + Args: + xy_depth: torch tensor of shape (..., 3). + world_coordinates: If `True`, unprojects the points back to world + coordinates using the camera extrinsics `R` and `T`. + `False` ignores `R` and `T` and unprojects to + the camera view coordinates. + from_ndc: If `False` (default), assumes xy part of input is in + NDC space if self.in_ndc(), otherwise in screen space. If + `True`, assumes xy is in NDC space even if the camera + is defined in screen space. + + Returns + new_points: unprojected points with the same shape as `xy_depth`. + """ + raise NotImplementedError() + + def get_camera_center(self, **kwargs) -> torch.Tensor: + """ + Return the 3D location of the camera optical center + in the world coordinates. + + Args: + **kwargs: parameters for the camera extrinsics can be passed in + as keyword arguments to override the default values + set in __init__. + + Setting R or T here will update the values set in init as these + values may be needed later on in the rendering pipeline e.g. for + lighting calculations. + + Returns: + C: a batch of 3D locations of shape (N, 3) denoting + the locations of the center of each camera in the batch. + """ + w2v_trans = self.get_world_to_view_transform(**kwargs) + P = w2v_trans.inverse().get_matrix() + # the camera center is the translation component (the first 3 elements + # of the last row) of the inverted world-to-view + # transform (4x4 RT matrix) + C = P[:, 3, :3] + return C + + def get_world_to_view_transform(self, **kwargs) -> Transform3d: + """ + Return the world-to-view transform. + + Args: + **kwargs: parameters for the camera extrinsics can be passed in + as keyword arguments to override the default values + set in __init__. + + Setting R and T here will update the values set in init as these + values may be needed later on in the rendering pipeline e.g. for + lighting calculations. + + Returns: + A Transform3d object which represents a batch of transforms + of shape (N, 3, 3) + """ + R: torch.Tensor = kwargs.get("R", self.R) + T: torch.Tensor = kwargs.get("T", self.T) + self.R = R + self.T = T + world_to_view_transform = get_world_to_view_transform(R=R, T=T) + return world_to_view_transform + + def get_full_projection_transform(self, **kwargs) -> Transform3d: + """ + Return the full world-to-camera transform composing the + world-to-view and view-to-camera transforms. + If camera is defined in NDC space, the projected points are in NDC space. + If camera is defined in screen space, the projected points are in screen space. + + Args: + **kwargs: parameters for the projection transforms can be passed in + as keyword arguments to override the default values + set in __init__. + + Setting R and T here will update the values set in init as these + values may be needed later on in the rendering pipeline e.g. for + lighting calculations. + + Returns: + a Transform3d object which represents a batch of transforms + of shape (N, 3, 3) + """ + self.R: torch.Tensor = kwargs.get("R", self.R) + self.T: torch.Tensor = kwargs.get("T", self.T) + world_to_view_transform = self.get_world_to_view_transform(R=self.R, T=self.T) + view_to_proj_transform = self.get_projection_transform(**kwargs) + return world_to_view_transform.compose(view_to_proj_transform) + + def transform_points( + self, points, eps: Optional[float] = None, **kwargs + ) -> torch.Tensor: + """ + Transform input points from world to camera space. + If camera is defined in NDC space, the projected points are in NDC space. + If camera is defined in screen space, the projected points are in screen space. + + For `CamerasBase.transform_points`, setting `eps > 0` + stabilizes gradients since it leads to avoiding division + by excessively low numbers for points close to the camera plane. + + Args: + points: torch tensor of shape (..., 3). + eps: If eps!=None, the argument is used to clamp the + divisor in the homogeneous normalization of the points + transformed to the ndc space. Please see + `transforms.Transform3d.transform_points` for details. + + For `CamerasBase.transform_points`, setting `eps > 0` + stabilizes gradients since it leads to avoiding division + by excessively low numbers for points close to the + camera plane. + + Returns + new_points: transformed points with the same shape as the input. + """ + world_to_proj_transform = self.get_full_projection_transform(**kwargs) + return world_to_proj_transform.transform_points(points, eps=eps) + + def get_ndc_camera_transform(self, **kwargs) -> Transform3d: + """ + Returns the transform from camera projection space (screen or NDC) to NDC space. + For cameras that can be specified in screen space, this transform + allows points to be converted from screen to NDC space. + The default transform scales the points from [0, W]x[0, H] + to [-1, 1]x[-u, u] or [-u, u]x[-1, 1] where u > 1 is the aspect ratio of the image. + This function should be modified per camera definitions if need be, + e.g. for Perspective/Orthographic cameras we provide a custom implementation. + This transform assumes PyTorch3D coordinate system conventions for + both the NDC space and the input points. + + This transform interfaces with the PyTorch3D renderer which assumes + input points to the renderer to be in NDC space. + """ + if self.in_ndc(): + return Transform3d(device=self.device, dtype=torch.float32) + else: + # For custom cameras which can be defined in screen space, + # users might might have to implement the screen to NDC transform based + # on the definition of the camera parameters. + # See PerspectiveCameras/OrthographicCameras for an example. + # We don't flip xy because we assume that world points are in + # PyTorch3D coordinates, and thus conversion from screen to ndc + # is a mere scaling from image to [-1, 1] scale. + image_size = kwargs.get("image_size", self.get_image_size()) + return get_screen_to_ndc_transform( + self, with_xyflip=False, image_size=image_size + ) + + def transform_points_ndc( + self, points, eps: Optional[float] = None, **kwargs + ) -> torch.Tensor: + """ + Transforms points from PyTorch3D world/camera space to NDC space. + Input points follow the PyTorch3D coordinate system conventions: +X left, +Y up. + Output points are in NDC space: +X left, +Y up, origin at image center. + + Args: + points: torch tensor of shape (..., 3). + eps: If eps!=None, the argument is used to clamp the + divisor in the homogeneous normalization of the points + transformed to the ndc space. Please see + `transforms.Transform3d.transform_points` for details. + + For `CamerasBase.transform_points`, setting `eps > 0` + stabilizes gradients since it leads to avoiding division + by excessively low numbers for points close to the + camera plane. + + Returns + new_points: transformed points with the same shape as the input. + """ + world_to_ndc_transform = self.get_full_projection_transform(**kwargs) + if not self.in_ndc(): + to_ndc_transform = self.get_ndc_camera_transform(**kwargs) + world_to_ndc_transform = world_to_ndc_transform.compose(to_ndc_transform) + + return world_to_ndc_transform.transform_points(points, eps=eps) + + def transform_points_screen( + self, points, eps: Optional[float] = None, with_xyflip: bool = True, **kwargs + ) -> torch.Tensor: + """ + Transforms points from PyTorch3D world/camera space to screen space. + Input points follow the PyTorch3D coordinate system conventions: +X left, +Y up. + Output points are in screen space: +X right, +Y down, origin at top left corner. + + Args: + points: torch tensor of shape (..., 3). + eps: If eps!=None, the argument is used to clamp the + divisor in the homogeneous normalization of the points + transformed to the ndc space. Please see + `transforms.Transform3d.transform_points` for details. + + For `CamerasBase.transform_points`, setting `eps > 0` + stabilizes gradients since it leads to avoiding division + by excessively low numbers for points close to the + camera plane. + with_xyflip: If True, flip x and y directions. In world/camera/ndc coords, + +x points to the left and +y up. If with_xyflip is true, in screen + coords +x points right, and +y down, following the usual RGB image + convention. Warning: do not set to False unless you know what you're + doing! + + Returns + new_points: transformed points with the same shape as the input. + """ + points_ndc = self.transform_points_ndc(points, eps=eps, **kwargs) + image_size = kwargs.get("image_size", self.get_image_size()) + return get_ndc_to_screen_transform( + self, with_xyflip=with_xyflip, image_size=image_size + ).transform_points(points_ndc, eps=eps) + + def clone(self): + """ + Returns a copy of `self`. + """ + cam_type = type(self) + other = cam_type(device=self.device) + return super().clone(other) + + def is_perspective(self): + raise NotImplementedError() + + def in_ndc(self): + """ + Specifies whether the camera is defined in NDC space + or in screen (image) space + """ + raise NotImplementedError() + + def get_znear(self): + return getattr(self, "znear", None) + + def get_image_size(self): + """ + Returns the image size, if provided, expected in the form of (height, width) + The image size is used for conversion of projected points to screen coordinates. + """ + return getattr(self, "image_size", None) + + def __getitem__( + self, index: Union[int, List[int], torch.BoolTensor, torch.LongTensor] + ) -> "CamerasBase": + """ + Override for the __getitem__ method in TensorProperties which needs to be + refactored. + + Args: + index: an integer index, list/tensor of integer indices, or tensor of boolean + indicators used to filter all the fields in the cameras given by self._FIELDS. + Returns: + an instance of the current cameras class with only the values at the selected index. + """ + + kwargs = {} + + tensor_types = { + # pyre-fixme[16]: Module `cuda` has no attribute `BoolTensor`. + "bool": (torch.BoolTensor, torch.cuda.BoolTensor), + # pyre-fixme[16]: Module `cuda` has no attribute `LongTensor`. + "long": (torch.LongTensor, torch.cuda.LongTensor), + } + if not isinstance( + index, (int, list, *tensor_types["bool"], *tensor_types["long"]) + ) or ( + isinstance(index, list) + and not all(isinstance(i, int) and not isinstance(i, bool) for i in index) + ): + msg = ( + "Invalid index type, expected int, List[int] or Bool/LongTensor; got %r" + ) + raise ValueError(msg % type(index)) + + if isinstance(index, int): + index = [index] + + if isinstance(index, tensor_types["bool"]): + # pyre-fixme[16]: Item `List` of `Union[List[int], BoolTensor, + # LongTensor]` has no attribute `ndim`. + # pyre-fixme[16]: Item `List` of `Union[List[int], BoolTensor, + # LongTensor]` has no attribute `shape`. + if index.ndim != 1 or index.shape[0] != len(self): + raise ValueError( + # pyre-fixme[16]: Item `List` of `Union[List[int], BoolTensor, + # LongTensor]` has no attribute `shape`. + f"Boolean index of shape {index.shape} does not match cameras" + ) + elif max(index) >= len(self): + raise IndexError(f"Index {max(index)} is out of bounds for select cameras") + + for field in self._FIELDS: + val = getattr(self, field, None) + if val is None: + continue + + # e.g. "in_ndc" is set as attribute "_in_ndc" on the class + # but provided as "in_ndc" on initialization + if field.startswith("_"): + field = field[1:] + + if isinstance(val, (str, bool)): + kwargs[field] = val + elif isinstance(val, torch.Tensor): + # In the init, all inputs will be converted to + # tensors before setting as attributes + kwargs[field] = val[index] + else: + raise ValueError(f"Field {field} type is not supported for indexing") + + kwargs["device"] = self.device + return self.__class__(**kwargs) + + +############################################################ +# Field of View Camera Classes # +############################################################ + + +def OpenGLPerspectiveCameras( + znear: _BatchFloatType = 1.0, + zfar: _BatchFloatType = 100.0, + aspect_ratio: _BatchFloatType = 1.0, + fov: _BatchFloatType = 60.0, + degrees: bool = True, + R: torch.Tensor = _R, + T: torch.Tensor = _T, + device: Device = "cpu", +) -> "FoVPerspectiveCameras": + """ + OpenGLPerspectiveCameras has been DEPRECATED. Use FoVPerspectiveCameras instead. + Preserving OpenGLPerspectiveCameras for backward compatibility. + """ + + warnings.warn( + """OpenGLPerspectiveCameras is deprecated, + Use FoVPerspectiveCameras instead. + OpenGLPerspectiveCameras will be removed in future releases.""", + PendingDeprecationWarning, + ) + + return FoVPerspectiveCameras( + znear=znear, + zfar=zfar, + aspect_ratio=aspect_ratio, + fov=fov, + degrees=degrees, + R=R, + T=T, + device=device, + ) + + +class FoVPerspectiveCameras(CamerasBase): + """ + A class which stores a batch of parameters to generate a batch of + projection matrices by specifying the field of view. + The definitions of the parameters follow the OpenGL perspective camera. + + The extrinsics of the camera (R and T matrices) can also be set in the + initializer or passed in to `get_full_projection_transform` to get + the full transformation from world -> ndc. + + The `transform_points` method calculates the full world -> ndc transform + and then applies it to the input points. + + The transforms can also be returned separately as Transform3d objects. + + * Setting the Aspect Ratio for Non Square Images * + + If the desired output image size is non square (i.e. a tuple of (H, W) where H != W) + the aspect ratio needs special consideration: There are two aspect ratios + to be aware of: + - the aspect ratio of each pixel + - the aspect ratio of the output image + The `aspect_ratio` setting in the FoVPerspectiveCameras sets the + pixel aspect ratio. When using this camera with the differentiable rasterizer + be aware that in the rasterizer we assume square pixels, but allow + variable image aspect ratio (i.e rectangle images). + + In most cases you will want to set the camera `aspect_ratio=1.0` + (i.e. square pixels) and only vary the output image dimensions in pixels + for rasterization. + """ + + # For __getitem__ + _FIELDS = ( + "K", + "znear", + "zfar", + "aspect_ratio", + "fov", + "R", + "T", + "degrees", + ) + + _SHARED_FIELDS = ("degrees",) + + def __init__( + self, + znear: _BatchFloatType = 1.0, + zfar: _BatchFloatType = 100.0, + aspect_ratio: _BatchFloatType = 1.0, + fov: _BatchFloatType = 60.0, + degrees: bool = True, + R: torch.Tensor = _R, + T: torch.Tensor = _T, + K: Optional[torch.Tensor] = None, + device: Device = "cpu", + ) -> None: + """ + + Args: + znear: near clipping plane of the view frustrum. + zfar: far clipping plane of the view frustrum. + aspect_ratio: aspect ratio of the image pixels. + 1.0 indicates square pixels. + fov: field of view angle of the camera. + degrees: bool, set to True if fov is specified in degrees. + R: Rotation matrix of shape (N, 3, 3) + T: Translation matrix of shape (N, 3) + K: (optional) A calibration matrix of shape (N, 4, 4) + If provided, don't need znear, zfar, fov, aspect_ratio, degrees + device: Device (as str or torch.device) + """ + # The initializer formats all inputs to torch tensors and broadcasts + # all the inputs to have the same batch dimension where necessary. + super().__init__( + device=device, + znear=znear, + zfar=zfar, + aspect_ratio=aspect_ratio, + fov=fov, + R=R, + T=T, + K=K, + ) + + # No need to convert to tensor or broadcast. + self.degrees = degrees + + def compute_projection_matrix( + self, znear, zfar, fov, aspect_ratio, degrees: bool + ) -> torch.Tensor: + """ + Compute the calibration matrix K of shape (N, 4, 4) + + Args: + znear: near clipping plane of the view frustrum. + zfar: far clipping plane of the view frustrum. + fov: field of view angle of the camera. + aspect_ratio: aspect ratio of the image pixels. + 1.0 indicates square pixels. + degrees: bool, set to True if fov is specified in degrees. + + Returns: + torch.FloatTensor of the calibration matrix with shape (N, 4, 4) + """ + K = torch.zeros((self._N, 4, 4), device=self.device, dtype=torch.float32) + ones = torch.ones((self._N), dtype=torch.float32, device=self.device) + if degrees: + fov = (np.pi / 180) * fov + + if not torch.is_tensor(fov): + fov = torch.tensor(fov, device=self.device) + tanHalfFov = torch.tan((fov / 2)) + max_y = tanHalfFov * znear + min_y = -max_y + max_x = max_y * aspect_ratio + min_x = -max_x + + # NOTE: In OpenGL the projection matrix changes the handedness of the + # coordinate frame. i.e the NDC space positive z direction is the + # camera space negative z direction. This is because the sign of the z + # in the projection matrix is set to -1.0. + # In pytorch3d we maintain a right handed coordinate system throughout + # so the so the z sign is 1.0. + z_sign = 1.0 + + # pyre-fixme[58]: `/` is not supported for operand types `float` and `Tensor`. + K[:, 0, 0] = 2.0 * znear / (max_x - min_x) + # pyre-fixme[58]: `/` is not supported for operand types `float` and `Tensor`. + K[:, 1, 1] = 2.0 * znear / (max_y - min_y) + K[:, 0, 2] = (max_x + min_x) / (max_x - min_x) + K[:, 1, 2] = (max_y + min_y) / (max_y - min_y) + K[:, 3, 2] = z_sign * ones + + # NOTE: This maps the z coordinate from [0, 1] where z = 0 if the point + # is at the near clipping plane and z = 1 when the point is at the far + # clipping plane. + K[:, 2, 2] = z_sign * zfar / (zfar - znear) + K[:, 2, 3] = -(zfar * znear) / (zfar - znear) + + return K + + def get_projection_transform(self, **kwargs) -> Transform3d: + """ + Calculate the perspective projection matrix with a symmetric + viewing frustrum. Use column major order. + The viewing frustrum will be projected into ndc, s.t. + (max_x, max_y) -> (+1, +1) + (min_x, min_y) -> (-1, -1) + + Args: + **kwargs: parameters for the projection can be passed in as keyword + arguments to override the default values set in `__init__`. + + Return: + a Transform3d object which represents a batch of projection + matrices of shape (N, 4, 4) + + .. code-block:: python + + h1 = (max_y + min_y)/(max_y - min_y) + w1 = (max_x + min_x)/(max_x - min_x) + tanhalffov = tan((fov/2)) + s1 = 1/tanhalffov + s2 = 1/(tanhalffov * (aspect_ratio)) + + # To map z to the range [0, 1] use: + f1 = far / (far - near) + f2 = -(far * near) / (far - near) + + # Projection matrix + K = [ + [s1, 0, w1, 0], + [0, s2, h1, 0], + [0, 0, f1, f2], + [0, 0, 1, 0], + ] + """ + K = kwargs.get("K", self.K) + if K is not None: + if K.shape != (self._N, 4, 4): + msg = "Expected K to have shape of (%r, 4, 4)" + raise ValueError(msg % (self._N)) + else: + K = self.compute_projection_matrix( + kwargs.get("znear", self.znear), + kwargs.get("zfar", self.zfar), + kwargs.get("fov", self.fov), + kwargs.get("aspect_ratio", self.aspect_ratio), + kwargs.get("degrees", self.degrees), + ) + + # Transpose the projection matrix as PyTorch3D transforms use row vectors. + transform = Transform3d( + matrix=K.transpose(1, 2).contiguous(), device=self.device + ) + return transform + + def unproject_points( + self, + xy_depth: torch.Tensor, + world_coordinates: bool = True, + scaled_depth_input: bool = False, + **kwargs, + ) -> torch.Tensor: + """>! + FoV cameras further allow for passing depth in world units + (`scaled_depth_input=False`) or in the [0, 1]-normalized units + (`scaled_depth_input=True`) + + Args: + scaled_depth_input: If `True`, assumes the input depth is in + the [0, 1]-normalized units. If `False` the input depth is in + the world units. + """ + + # obtain the relevant transformation to ndc + if world_coordinates: + to_ndc_transform = self.get_full_projection_transform() + else: + to_ndc_transform = self.get_projection_transform() + + if scaled_depth_input: + # the input is scaled depth, so we don't have to do anything + xy_sdepth = xy_depth + else: + # parse out important values from the projection matrix + K_matrix = self.get_projection_transform(**kwargs.copy()).get_matrix() + # parse out f1, f2 from K_matrix + unsqueeze_shape = [1] * xy_depth.dim() + unsqueeze_shape[0] = K_matrix.shape[0] + f1 = K_matrix[:, 2, 2].reshape(unsqueeze_shape) + f2 = K_matrix[:, 3, 2].reshape(unsqueeze_shape) + # get the scaled depth + sdepth = (f1 * xy_depth[..., 2:3] + f2) / xy_depth[..., 2:3] + # concatenate xy + scaled depth + xy_sdepth = torch.cat((xy_depth[..., 0:2], sdepth), dim=-1) + + # unproject with inverse of the projection + unprojection_transform = to_ndc_transform.inverse() + return unprojection_transform.transform_points(xy_sdepth) + + def is_perspective(self): + return True + + def in_ndc(self): + return True + + +def OpenGLOrthographicCameras( + znear: _BatchFloatType = 1.0, + zfar: _BatchFloatType = 100.0, + top: _BatchFloatType = 1.0, + bottom: _BatchFloatType = -1.0, + left: _BatchFloatType = -1.0, + right: _BatchFloatType = 1.0, + scale_xyz=((1.0, 1.0, 1.0),), # (1, 3) + R: torch.Tensor = _R, + T: torch.Tensor = _T, + device: Device = "cpu", +) -> "FoVOrthographicCameras": + """ + OpenGLOrthographicCameras has been DEPRECATED. Use FoVOrthographicCameras instead. + Preserving OpenGLOrthographicCameras for backward compatibility. + """ + + warnings.warn( + """OpenGLOrthographicCameras is deprecated, + Use FoVOrthographicCameras instead. + OpenGLOrthographicCameras will be removed in future releases.""", + PendingDeprecationWarning, + ) + + return FoVOrthographicCameras( + znear=znear, + zfar=zfar, + max_y=top, + min_y=bottom, + max_x=right, + min_x=left, + scale_xyz=scale_xyz, + R=R, + T=T, + device=device, + ) + + +class FoVOrthographicCameras(CamerasBase): + """ + A class which stores a batch of parameters to generate a batch of + projection matrices by specifying the field of view. + The definitions of the parameters follow the OpenGL orthographic camera. + """ + + # For __getitem__ + _FIELDS = ( + "K", + "znear", + "zfar", + "R", + "T", + "max_y", + "min_y", + "max_x", + "min_x", + "scale_xyz", + ) + + def __init__( + self, + znear: _BatchFloatType = 1.0, + zfar: _BatchFloatType = 100.0, + max_y: _BatchFloatType = 1.0, + min_y: _BatchFloatType = -1.0, + max_x: _BatchFloatType = 1.0, + min_x: _BatchFloatType = -1.0, + scale_xyz=((1.0, 1.0, 1.0),), # (1, 3) + R: torch.Tensor = _R, + T: torch.Tensor = _T, + K: Optional[torch.Tensor] = None, + device: Device = "cpu", + ): + """ + + Args: + znear: near clipping plane of the view frustrum. + zfar: far clipping plane of the view frustrum. + max_y: maximum y coordinate of the frustrum. + min_y: minimum y coordinate of the frustrum. + max_x: maximum x coordinate of the frustrum. + min_x: minimum x coordinate of the frustrum + scale_xyz: scale factors for each axis of shape (N, 3). + R: Rotation matrix of shape (N, 3, 3). + T: Translation of shape (N, 3). + K: (optional) A calibration matrix of shape (N, 4, 4) + If provided, don't need znear, zfar, max_y, min_y, max_x, min_x, scale_xyz + device: torch.device or string. + + Only need to set min_x, max_x, min_y, max_y for viewing frustrums + which are non symmetric about the origin. + """ + # The initializer formats all inputs to torch tensors and broadcasts + # all the inputs to have the same batch dimension where necessary. + super().__init__( + device=device, + znear=znear, + zfar=zfar, + max_y=max_y, + min_y=min_y, + max_x=max_x, + min_x=min_x, + scale_xyz=scale_xyz, + R=R, + T=T, + K=K, + ) + + def compute_projection_matrix( + self, znear, zfar, max_x, min_x, max_y, min_y, scale_xyz + ) -> torch.Tensor: + """ + Compute the calibration matrix K of shape (N, 4, 4) + + Args: + znear: near clipping plane of the view frustrum. + zfar: far clipping plane of the view frustrum. + max_x: maximum x coordinate of the frustrum. + min_x: minimum x coordinate of the frustrum + max_y: maximum y coordinate of the frustrum. + min_y: minimum y coordinate of the frustrum. + scale_xyz: scale factors for each axis of shape (N, 3). + """ + K = torch.zeros((self._N, 4, 4), dtype=torch.float32, device=self.device) + ones = torch.ones((self._N), dtype=torch.float32, device=self.device) + # NOTE: OpenGL flips handedness of coordinate system between camera + # space and NDC space so z sign is -ve. In PyTorch3D we maintain a + # right handed coordinate system throughout. + z_sign = +1.0 + + K[:, 0, 0] = (2.0 / (max_x - min_x)) * scale_xyz[:, 0] + K[:, 1, 1] = (2.0 / (max_y - min_y)) * scale_xyz[:, 1] + K[:, 0, 3] = -(max_x + min_x) / (max_x - min_x) + K[:, 1, 3] = -(max_y + min_y) / (max_y - min_y) + K[:, 3, 3] = ones + + # NOTE: This maps the z coordinate to the range [0, 1] and replaces the + # the OpenGL z normalization to [-1, 1] + K[:, 2, 2] = z_sign * (1.0 / (zfar - znear)) * scale_xyz[:, 2] + K[:, 2, 3] = -znear / (zfar - znear) + + return K + + def get_projection_transform(self, **kwargs) -> Transform3d: + """ + Calculate the orthographic projection matrix. + Use column major order. + + Args: + **kwargs: parameters for the projection can be passed in to + override the default values set in __init__. + Return: + a Transform3d object which represents a batch of projection + matrices of shape (N, 4, 4) + + .. code-block:: python + + scale_x = 2 / (max_x - min_x) + scale_y = 2 / (max_y - min_y) + scale_z = 2 / (far-near) + mid_x = (max_x + min_x) / (max_x - min_x) + mix_y = (max_y + min_y) / (max_y - min_y) + mid_z = (far + near) / (far - near) + + K = [ + [scale_x, 0, 0, -mid_x], + [0, scale_y, 0, -mix_y], + [0, 0, -scale_z, -mid_z], + [0, 0, 0, 1], + ] + """ + K = kwargs.get("K", self.K) + if K is not None: + if K.shape != (self._N, 4, 4): + msg = "Expected K to have shape of (%r, 4, 4)" + raise ValueError(msg % (self._N)) + else: + K = self.compute_projection_matrix( + kwargs.get("znear", self.znear), + kwargs.get("zfar", self.zfar), + kwargs.get("max_x", self.max_x), + kwargs.get("min_x", self.min_x), + kwargs.get("max_y", self.max_y), + kwargs.get("min_y", self.min_y), + kwargs.get("scale_xyz", self.scale_xyz), + ) + + transform = Transform3d( + matrix=K.transpose(1, 2).contiguous(), device=self.device + ) + return transform + + def unproject_points( + self, + xy_depth: torch.Tensor, + world_coordinates: bool = True, + scaled_depth_input: bool = False, + **kwargs, + ) -> torch.Tensor: + """>! + FoV cameras further allow for passing depth in world units + (`scaled_depth_input=False`) or in the [0, 1]-normalized units + (`scaled_depth_input=True`) + + Args: + scaled_depth_input: If `True`, assumes the input depth is in + the [0, 1]-normalized units. If `False` the input depth is in + the world units. + """ + + if world_coordinates: + to_ndc_transform = self.get_full_projection_transform(**kwargs.copy()) + else: + to_ndc_transform = self.get_projection_transform(**kwargs.copy()) + + if scaled_depth_input: + # the input depth is already scaled + xy_sdepth = xy_depth + else: + # we have to obtain the scaled depth first + K = self.get_projection_transform(**kwargs).get_matrix() + unsqueeze_shape = [1] * K.dim() + unsqueeze_shape[0] = K.shape[0] + mid_z = K[:, 3, 2].reshape(unsqueeze_shape) + scale_z = K[:, 2, 2].reshape(unsqueeze_shape) + scaled_depth = scale_z * xy_depth[..., 2:3] + mid_z + # cat xy and scaled depth + xy_sdepth = torch.cat((xy_depth[..., :2], scaled_depth), dim=-1) + # finally invert the transform + unprojection_transform = to_ndc_transform.inverse() + return unprojection_transform.transform_points(xy_sdepth) + + def is_perspective(self): + return False + + def in_ndc(self): + return True + + +############################################################ +# MultiView Camera Classes # +############################################################ +""" +Note that the MultiView Cameras accept parameters in NDC space. +""" + + +def SfMPerspectiveCameras( + focal_length: _FocalLengthType = 1.0, + principal_point=((0.0, 0.0),), + R: torch.Tensor = _R, + T: torch.Tensor = _T, + device: Device = "cpu", +) -> "PerspectiveCameras": + """ + SfMPerspectiveCameras has been DEPRECATED. Use PerspectiveCameras instead. + Preserving SfMPerspectiveCameras for backward compatibility. + """ + + warnings.warn( + """SfMPerspectiveCameras is deprecated, + Use PerspectiveCameras instead. + SfMPerspectiveCameras will be removed in future releases.""", + PendingDeprecationWarning, + ) + + return PerspectiveCameras( + focal_length=focal_length, + principal_point=principal_point, + R=R, + T=T, + device=device, + ) + + +class PerspectiveCameras(CamerasBase): + """ + A class which stores a batch of parameters to generate a batch of + transformation matrices using the multi-view geometry convention for + perspective camera. + + Parameters for this camera are specified in NDC if `in_ndc` is set to True. + If parameters are specified in screen space, `in_ndc` must be set to False. + """ + + # For __getitem__ + _FIELDS = ( + "K", + "R", + "T", + "focal_length", + "principal_point", + "_in_ndc", # arg is in_ndc but attribute set as _in_ndc + "image_size", + ) + + _SHARED_FIELDS = ("_in_ndc",) + + def __init__( + self, + focal_length: _FocalLengthType = 1.0, + principal_point=((0.0, 0.0),), + R: torch.Tensor = _R, + T: torch.Tensor = _T, + K: Optional[torch.Tensor] = None, + device: Device = "cpu", + in_ndc: bool = True, + image_size: Optional[Union[List, Tuple, torch.Tensor]] = None, + ) -> None: + """ + + Args: + focal_length: Focal length of the camera in world units. + A tensor of shape (N, 1) or (N, 2) for + square and non-square pixels respectively. + principal_point: xy coordinates of the center of + the principal point of the camera in pixels. + A tensor of shape (N, 2). + in_ndc: True if camera parameters are specified in NDC. + If camera parameters are in screen space, it must + be set to False. + R: Rotation matrix of shape (N, 3, 3) + T: Translation matrix of shape (N, 3) + K: (optional) A calibration matrix of shape (N, 4, 4) + If provided, don't need focal_length, principal_point + image_size: (height, width) of image size. + A tensor of shape (N, 2) or a list/tuple. Required for screen cameras. + device: torch.device or string + """ + # The initializer formats all inputs to torch tensors and broadcasts + # all the inputs to have the same batch dimension where necessary. + kwargs = {"image_size": image_size} if image_size is not None else {} + super().__init__( + device=device, + focal_length=focal_length, + principal_point=principal_point, + R=R, + T=T, + K=K, + _in_ndc=in_ndc, + **kwargs, # pyre-ignore + ) + if image_size is not None: + if (self.image_size < 1).any(): # pyre-ignore + raise ValueError("Image_size provided has invalid values") + else: + self.image_size = None + + # When focal length is provided as one value, expand to + # create (N, 2) shape tensor + if self.focal_length.ndim == 1: # (N,) + self.focal_length = self.focal_length[:, None] # (N, 1) + self.focal_length = self.focal_length.expand(-1, 2) # (N, 2) + + def get_projection_transform(self, **kwargs) -> Transform3d: + """ + Calculate the projection matrix using the + multi-view geometry convention. + + Args: + **kwargs: parameters for the projection can be passed in as keyword + arguments to override the default values set in __init__. + + Returns: + A `Transform3d` object with a batch of `N` projection transforms. + + .. code-block:: python + + fx = focal_length[:, 0] + fy = focal_length[:, 1] + px = principal_point[:, 0] + py = principal_point[:, 1] + + K = [ + [fx, 0, px, 0], + [0, fy, py, 0], + [0, 0, 0, 1], + [0, 0, 1, 0], + ] + """ + K = kwargs.get("K", self.K) + if K is not None: + if K.shape != (self._N, 4, 4): + msg = "Expected K to have shape of (%r, 4, 4)" + raise ValueError(msg % (self._N)) + else: + K = _get_sfm_calibration_matrix( + self._N, + self.device, + kwargs.get("focal_length", self.focal_length), + kwargs.get("principal_point", self.principal_point), + orthographic=False, + ) + + transform = Transform3d( + matrix=K.transpose(1, 2).contiguous(), device=self.device + ) + return transform + + def unproject_points( + self, + xy_depth: torch.Tensor, + world_coordinates: bool = True, + from_ndc: bool = False, + **kwargs, + ) -> torch.Tensor: + """ + Args: + from_ndc: If `False` (default), assumes xy part of input is in + NDC space if self.in_ndc(), otherwise in screen space. If + `True`, assumes xy is in NDC space even if the camera + is defined in screen space. + """ + if world_coordinates: + to_camera_transform = self.get_full_projection_transform(**kwargs) + else: + to_camera_transform = self.get_projection_transform(**kwargs) + if from_ndc: + to_camera_transform = to_camera_transform.compose( + self.get_ndc_camera_transform() + ) + + unprojection_transform = to_camera_transform.inverse() + xy_inv_depth = torch.cat( + (xy_depth[..., :2], 1.0 / xy_depth[..., 2:3]), dim=-1 # type: ignore + ) + return unprojection_transform.transform_points(xy_inv_depth) + + def get_principal_point(self, **kwargs) -> torch.Tensor: + """ + Return the camera's principal point + + Args: + **kwargs: parameters for the camera extrinsics can be passed in + as keyword arguments to override the default values + set in __init__. + """ + proj_mat = self.get_projection_transform(**kwargs).get_matrix() + return proj_mat[:, 2, :2] + + def get_ndc_camera_transform(self, **kwargs) -> Transform3d: + """ + Returns the transform from camera projection space (screen or NDC) to NDC space. + If the camera is defined already in NDC space, the transform is identity. + For cameras defined in screen space, we adjust the principal point computation + which is defined in the image space (commonly) and scale the points to NDC space. + + This transform leaves the depth unchanged. + + Important: This transforms assumes PyTorch3D conventions for the input points, + i.e. +X left, +Y up. + """ + if self.in_ndc(): + ndc_transform = Transform3d(device=self.device, dtype=torch.float32) + else: + # when cameras are defined in screen/image space, the principal point is + # provided in the (+X right, +Y down), aka image, coordinate system. + # Since input points are defined in the PyTorch3D system (+X left, +Y up), + # we need to adjust for the principal point transform. + pr_point_fix = torch.zeros( + (self._N, 4, 4), device=self.device, dtype=torch.float32 + ) + pr_point_fix[:, 0, 0] = 1.0 + pr_point_fix[:, 1, 1] = 1.0 + pr_point_fix[:, 2, 2] = 1.0 + pr_point_fix[:, 3, 3] = 1.0 + pr_point_fix[:, :2, 3] = -2.0 * self.get_principal_point(**kwargs) + pr_point_fix_transform = Transform3d( + matrix=pr_point_fix.transpose(1, 2).contiguous(), device=self.device + ) + image_size = kwargs.get("image_size", self.get_image_size()) + screen_to_ndc_transform = get_screen_to_ndc_transform( + self, with_xyflip=False, image_size=image_size + ) + ndc_transform = pr_point_fix_transform.compose(screen_to_ndc_transform) + + return ndc_transform + + def is_perspective(self): + return True + + def in_ndc(self): + return self._in_ndc + + +def SfMOrthographicCameras( + focal_length: _FocalLengthType = 1.0, + principal_point=((0.0, 0.0),), + R: torch.Tensor = _R, + T: torch.Tensor = _T, + device: Device = "cpu", +) -> "OrthographicCameras": + """ + SfMOrthographicCameras has been DEPRECATED. Use OrthographicCameras instead. + Preserving SfMOrthographicCameras for backward compatibility. + """ + + warnings.warn( + """SfMOrthographicCameras is deprecated, + Use OrthographicCameras instead. + SfMOrthographicCameras will be removed in future releases.""", + PendingDeprecationWarning, + ) + + return OrthographicCameras( + focal_length=focal_length, + principal_point=principal_point, + R=R, + T=T, + device=device, + ) + + +class OrthographicCameras(CamerasBase): + """ + A class which stores a batch of parameters to generate a batch of + transformation matrices using the multi-view geometry convention for + orthographic camera. + + Parameters for this camera are specified in NDC if `in_ndc` is set to True. + If parameters are specified in screen space, `in_ndc` must be set to False. + """ + + # For __getitem__ + _FIELDS = ( + "K", + "R", + "T", + "focal_length", + "principal_point", + "_in_ndc", + "image_size", + ) + + _SHARED_FIELDS = ("_in_ndc",) + + def __init__( + self, + focal_length: _FocalLengthType = 1.0, + principal_point=((0.0, 0.0),), + R: torch.Tensor = _R, + T: torch.Tensor = _T, + K: Optional[torch.Tensor] = None, + device: Device = "cpu", + in_ndc: bool = True, + image_size: Optional[Union[List, Tuple, torch.Tensor]] = None, + ) -> None: + """ + + Args: + focal_length: Focal length of the camera in world units. + A tensor of shape (N, 1) or (N, 2) for + square and non-square pixels respectively. + principal_point: xy coordinates of the center of + the principal point of the camera in pixels. + A tensor of shape (N, 2). + in_ndc: True if camera parameters are specified in NDC. + If False, then camera parameters are in screen space. + R: Rotation matrix of shape (N, 3, 3) + T: Translation matrix of shape (N, 3) + K: (optional) A calibration matrix of shape (N, 4, 4) + If provided, don't need focal_length, principal_point, image_size + image_size: (height, width) of image size. + A tensor of shape (N, 2) or list/tuple. Required for screen cameras. + device: torch.device or string + """ + # The initializer formats all inputs to torch tensors and broadcasts + # all the inputs to have the same batch dimension where necessary. + kwargs = {"image_size": image_size} if image_size is not None else {} + super().__init__( + device=device, + focal_length=focal_length, + principal_point=principal_point, + R=R, + T=T, + K=K, + _in_ndc=in_ndc, + **kwargs, # pyre-ignore + ) + if image_size is not None: + if (self.image_size < 1).any(): # pyre-ignore + raise ValueError("Image_size provided has invalid values") + else: + self.image_size = None + + # When focal length is provided as one value, expand to + # create (N, 2) shape tensor + if self.focal_length.ndim == 1: # (N,) + self.focal_length = self.focal_length[:, None] # (N, 1) + self.focal_length = self.focal_length.expand(-1, 2) # (N, 2) + + def get_projection_transform(self, **kwargs) -> Transform3d: + """ + Calculate the projection matrix using + the multi-view geometry convention. + + Args: + **kwargs: parameters for the projection can be passed in as keyword + arguments to override the default values set in __init__. + + Returns: + A `Transform3d` object with a batch of `N` projection transforms. + + .. code-block:: python + + fx = focal_length[:,0] + fy = focal_length[:,1] + px = principal_point[:,0] + py = principal_point[:,1] + + K = [ + [fx, 0, 0, px], + [0, fy, 0, py], + [0, 0, 1, 0], + [0, 0, 0, 1], + ] + """ + K = kwargs.get("K", self.K) + if K is not None: + if K.shape != (self._N, 4, 4): + msg = "Expected K to have shape of (%r, 4, 4)" + raise ValueError(msg % (self._N)) + else: + K = _get_sfm_calibration_matrix( + self._N, + self.device, + kwargs.get("focal_length", self.focal_length), + kwargs.get("principal_point", self.principal_point), + orthographic=True, + ) + + transform = Transform3d( + matrix=K.transpose(1, 2).contiguous(), device=self.device + ) + return transform + + def unproject_points( + self, + xy_depth: torch.Tensor, + world_coordinates: bool = True, + from_ndc: bool = False, + **kwargs, + ) -> torch.Tensor: + """ + Args: + from_ndc: If `False` (default), assumes xy part of input is in + NDC space if self.in_ndc(), otherwise in screen space. If + `True`, assumes xy is in NDC space even if the camera + is defined in screen space. + """ + if world_coordinates: + to_camera_transform = self.get_full_projection_transform(**kwargs) + else: + to_camera_transform = self.get_projection_transform(**kwargs) + if from_ndc: + to_camera_transform = to_camera_transform.compose( + self.get_ndc_camera_transform() + ) + + unprojection_transform = to_camera_transform.inverse() + return unprojection_transform.transform_points(xy_depth) + + def get_principal_point(self, **kwargs) -> torch.Tensor: + """ + Return the camera's principal point + + Args: + **kwargs: parameters for the camera extrinsics can be passed in + as keyword arguments to override the default values + set in __init__. + """ + proj_mat = self.get_projection_transform(**kwargs).get_matrix() + return proj_mat[:, 3, :2] + + def get_ndc_camera_transform(self, **kwargs) -> Transform3d: + """ + Returns the transform from camera projection space (screen or NDC) to NDC space. + If the camera is defined already in NDC space, the transform is identity. + For cameras defined in screen space, we adjust the principal point computation + which is defined in the image space (commonly) and scale the points to NDC space. + + Important: This transforms assumes PyTorch3D conventions for the input points, + i.e. +X left, +Y up. + """ + if self.in_ndc(): + ndc_transform = Transform3d(device=self.device, dtype=torch.float32) + else: + # when cameras are defined in screen/image space, the principal point is + # provided in the (+X right, +Y down), aka image, coordinate system. + # Since input points are defined in the PyTorch3D system (+X left, +Y up), + # we need to adjust for the principal point transform. + pr_point_fix = torch.zeros( + (self._N, 4, 4), device=self.device, dtype=torch.float32 + ) + pr_point_fix[:, 0, 0] = 1.0 + pr_point_fix[:, 1, 1] = 1.0 + pr_point_fix[:, 2, 2] = 1.0 + pr_point_fix[:, 3, 3] = 1.0 + pr_point_fix[:, :2, 3] = -2.0 * self.get_principal_point(**kwargs) + pr_point_fix_transform = Transform3d( + matrix=pr_point_fix.transpose(1, 2).contiguous(), device=self.device + ) + image_size = kwargs.get("image_size", self.get_image_size()) + screen_to_ndc_transform = get_screen_to_ndc_transform( + self, with_xyflip=False, image_size=image_size + ) + ndc_transform = pr_point_fix_transform.compose(screen_to_ndc_transform) + + return ndc_transform + + def is_perspective(self): + return False + + def in_ndc(self): + return self._in_ndc + + +################################################ +# Helper functions for cameras # +################################################ + + +def _get_sfm_calibration_matrix( + N: int, + device: Device, + focal_length, + principal_point, + orthographic: bool = False, +) -> torch.Tensor: + """ + Returns a calibration matrix of a perspective/orthographic camera. + + Args: + N: Number of cameras. + focal_length: Focal length of the camera. + principal_point: xy coordinates of the center of + the principal point of the camera in pixels. + orthographic: Boolean specifying if the camera is orthographic or not + + The calibration matrix `K` is set up as follows: + + .. code-block:: python + + fx = focal_length[:,0] + fy = focal_length[:,1] + px = principal_point[:,0] + py = principal_point[:,1] + + for orthographic==True: + K = [ + [fx, 0, 0, px], + [0, fy, 0, py], + [0, 0, 1, 0], + [0, 0, 0, 1], + ] + else: + K = [ + [fx, 0, px, 0], + [0, fy, py, 0], + [0, 0, 0, 1], + [0, 0, 1, 0], + ] + + Returns: + A calibration matrix `K` of the SfM-conventioned camera + of shape (N, 4, 4). + """ + + if not torch.is_tensor(focal_length): + focal_length = torch.tensor(focal_length, device=device) + + if focal_length.ndim in (0, 1) or focal_length.shape[1] == 1: + fx = fy = focal_length + else: + fx, fy = focal_length.unbind(1) + + if not torch.is_tensor(principal_point): + principal_point = torch.tensor(principal_point, device=device) + + px, py = principal_point.unbind(1) + + K = fx.new_zeros(N, 4, 4) + K[:, 0, 0] = fx + K[:, 1, 1] = fy + if orthographic: + K[:, 0, 3] = px + K[:, 1, 3] = py + K[:, 2, 2] = 1.0 + K[:, 3, 3] = 1.0 + else: + K[:, 0, 2] = px + K[:, 1, 2] = py + K[:, 3, 2] = 1.0 + K[:, 2, 3] = 1.0 + + return K + + +################################################ +# Helper functions for world to view transforms +################################################ + + +def get_world_to_view_transform( + R: torch.Tensor = _R, T: torch.Tensor = _T +) -> Transform3d: + """ + This function returns a Transform3d representing the transformation + matrix to go from world space to view space by applying a rotation and + a translation. + + PyTorch3D uses the same convention as Hartley & Zisserman. + I.e., for camera extrinsic parameters R (rotation) and T (translation), + we map a 3D point `X_world` in world coordinates to + a point `X_cam` in camera coordinates with: + `X_cam = X_world R + T` + + Args: + R: (N, 3, 3) matrix representing the rotation. + T: (N, 3) matrix representing the translation. + + Returns: + a Transform3d object which represents the composed RT transformation. + + """ + # TODO: also support the case where RT is specified as one matrix + # of shape (N, 4, 4). + + if T.shape[0] != R.shape[0]: + msg = "Expected R, T to have the same batch dimension; got %r, %r" + raise ValueError(msg % (R.shape[0], T.shape[0])) + if T.dim() != 2 or T.shape[1:] != (3,): + msg = "Expected T to have shape (N, 3); got %r" + raise ValueError(msg % repr(T.shape)) + if R.dim() != 3 or R.shape[1:] != (3, 3): + msg = "Expected R to have shape (N, 3, 3); got %r" + raise ValueError(msg % repr(R.shape)) + + # Create a Transform3d object + T_ = Translate(T, device=T.device) + R_ = Rotate(R, device=R.device) + return R_.compose(T_) + + +def camera_position_from_spherical_angles( + distance: float, + elevation: float, + azimuth: float, + degrees: bool = True, + device: Device = "cpu", +) -> torch.Tensor: + """ + Calculate the location of the camera based on the distance away from + the target point, the elevation and azimuth angles. + + Args: + distance: distance of the camera from the object. + elevation, azimuth: angles. + The inputs distance, elevation and azimuth can be one of the following + - Python scalar + - Torch scalar + - Torch tensor of shape (N) or (1) + degrees: bool, whether the angles are specified in degrees or radians. + device: str or torch.device, device for new tensors to be placed on. + + The vectors are broadcast against each other so they all have shape (N, 1). + + Returns: + camera_position: (N, 3) xyz location of the camera. + """ + broadcasted_args = convert_to_tensors_and_broadcast( + distance, elevation, azimuth, device=device + ) + dist, elev, azim = broadcasted_args + if degrees: + elev = math.pi / 180.0 * elev + azim = math.pi / 180.0 * azim + x = dist * torch.cos(elev) * torch.sin(azim) + y = dist * torch.sin(elev) + z = dist * torch.cos(elev) * torch.cos(azim) + camera_position = torch.stack([x, y, z], dim=1) + if camera_position.dim() == 0: + camera_position = camera_position.view(1, -1) # add batch dim. + return camera_position.view(-1, 3) + + +def look_at_rotation( + camera_position, at=((0, 0, 0),), up=((0, 1, 0),), device: Device = "cpu" +) -> torch.Tensor: + """ + This function takes a vector 'camera_position' which specifies the location + of the camera in world coordinates and two vectors `at` and `up` which + indicate the position of the object and the up directions of the world + coordinate system respectively. The object is assumed to be centered at + the origin. + + The output is a rotation matrix representing the transformation + from world coordinates -> view coordinates. + + Args: + camera_position: position of the camera in world coordinates + at: position of the object in world coordinates + up: vector specifying the up direction in the world coordinate frame. + + The inputs camera_position, at and up can each be a + - 3 element tuple/list + - torch tensor of shape (1, 3) + - torch tensor of shape (N, 3) + + The vectors are broadcast against each other so they all have shape (N, 3). + + Returns: + R: (N, 3, 3) batched rotation matrices + """ + # Format input and broadcast + broadcasted_args = convert_to_tensors_and_broadcast( + camera_position, at, up, device=device + ) + camera_position, at, up = broadcasted_args + for t, n in zip([camera_position, at, up], ["camera_position", "at", "up"]): + if t.shape[-1] != 3: + msg = "Expected arg %s to have shape (N, 3); got %r" + raise ValueError(msg % (n, t.shape)) + z_axis = F.normalize(at - camera_position, eps=1e-5) + x_axis = F.normalize(torch.cross(up, z_axis, dim=1), eps=1e-5) + y_axis = F.normalize(torch.cross(z_axis, x_axis, dim=1), eps=1e-5) + is_close = torch.isclose(x_axis, torch.tensor(0.0), atol=5e-3).all( + dim=1, keepdim=True + ) + if is_close.any(): + replacement = F.normalize(torch.cross(y_axis, z_axis, dim=1), eps=1e-5) + x_axis = torch.where(is_close, replacement, x_axis) + R = torch.cat((x_axis[:, None, :], y_axis[:, None, :], z_axis[:, None, :]), dim=1) + return R.transpose(1, 2) + + +def look_at_view_transform( + dist: _BatchFloatType = 1.0, + elev: _BatchFloatType = 0.0, + azim: _BatchFloatType = 0.0, + degrees: bool = True, + eye: Optional[Union[Sequence, torch.Tensor]] = None, + at=((0, 0, 0),), # (1, 3) + up=((0, 1, 0),), # (1, 3) + device: Device = "cpu", +) -> Tuple[torch.Tensor, torch.Tensor]: + """ + This function returns a rotation and translation matrix + to apply the 'Look At' transformation from world -> view coordinates [0]. + + Args: + dist: distance of the camera from the object + elev: angle in degrees or radians. This is the angle between the + vector from the object to the camera, and the horizontal plane y = 0 (xz-plane). + azim: angle in degrees or radians. The vector from the object to + the camera is projected onto a horizontal plane y = 0. + azim is the angle between the projected vector and a + reference vector at (0, 0, 1) on the reference plane (the horizontal plane). + dist, elev and azim can be of shape (1), (N). + degrees: boolean flag to indicate if the elevation and azimuth + angles are specified in degrees or radians. + eye: the position of the camera(s) in world coordinates. If eye is not + None, it will override the camera position derived from dist, elev, azim. + up: the direction of the x axis in the world coordinate system. + at: the position of the object(s) in world coordinates. + eye, up and at can be of shape (1, 3) or (N, 3). + + Returns: + 2-element tuple containing + + - **R**: the rotation to apply to the points to align with the camera. + - **T**: the translation to apply to the points to align with the camera. + + References: + [0] https://www.scratchapixel.com + """ + + if eye is not None: + broadcasted_args = convert_to_tensors_and_broadcast(eye, at, up, device=device) + eye, at, up = broadcasted_args + C = eye + else: + broadcasted_args = convert_to_tensors_and_broadcast( + dist, elev, azim, at, up, device=device + ) + dist, elev, azim, at, up = broadcasted_args + C = ( + camera_position_from_spherical_angles( + dist, elev, azim, degrees=degrees, device=device + ) + + at + ) + + R = look_at_rotation(C, at, up, device=device) + T = -torch.bmm(R.transpose(1, 2), C[:, :, None])[:, :, 0] + return R, T + + +def get_ndc_to_screen_transform( + cameras, + with_xyflip: bool = False, + image_size: Optional[Union[List, Tuple, torch.Tensor]] = None, +) -> Transform3d: + """ + PyTorch3D NDC to screen conversion. + Conversion from PyTorch3D's NDC space (+X left, +Y up) to screen/image space + (+X right, +Y down, origin top left). + + Args: + cameras + with_xyflip: flips x- and y-axis if set to True. + Optional kwargs: + image_size: ((height, width),) specifying the height, width + of the image. If not provided, it reads it from cameras. + + We represent the NDC to screen conversion as a Transform3d + with projection matrix + + K = [ + [s, 0, 0, cx], + [0, s, 0, cy], + [0, 0, 1, 0], + [0, 0, 0, 1], + ] + + """ + # We require the image size, which is necessary for the transform + if image_size is None: + msg = "For NDC to screen conversion, image_size=(height, width) needs to be specified." + raise ValueError(msg) + + K = torch.zeros((cameras._N, 4, 4), device=cameras.device, dtype=torch.float32) + if not torch.is_tensor(image_size): + image_size = torch.tensor(image_size, device=cameras.device) + image_size = image_size.view(-1, 2) # of shape (1 or B)x2 + height, width = image_size.unbind(1) + + # For non square images, we scale the points such that smallest side + # has range [-1, 1] and the largest side has range [-u, u], with u > 1. + # This convention is consistent with the PyTorch3D renderer + scale = (image_size.min(dim=1).values - 0.0) / 2.0 + + K[:, 0, 0] = scale + K[:, 1, 1] = scale + K[:, 0, 3] = -1.0 * (width - 0.0) / 2.0 + K[:, 1, 3] = -1.0 * (height - 0.0) / 2.0 + K[:, 2, 2] = 1.0 + K[:, 3, 3] = 1.0 + + # Transpose the projection matrix as PyTorch3D transforms use row vectors. + transform = Transform3d( + matrix=K.transpose(1, 2).contiguous(), device=cameras.device + ) + + if with_xyflip: + # flip x, y axis + xyflip = torch.eye(4, device=cameras.device, dtype=torch.float32) + xyflip[0, 0] = -1.0 + xyflip[1, 1] = -1.0 + xyflip = xyflip.view(1, 4, 4).expand(cameras._N, -1, -1) + xyflip_transform = Transform3d( + matrix=xyflip.transpose(1, 2).contiguous(), device=cameras.device + ) + transform = transform.compose(xyflip_transform) + return transform + + +def get_screen_to_ndc_transform( + cameras, + with_xyflip: bool = False, + image_size: Optional[Union[List, Tuple, torch.Tensor]] = None, +) -> Transform3d: + """ + Screen to PyTorch3D NDC conversion. + Conversion from screen/image space (+X right, +Y down, origin top left) + to PyTorch3D's NDC space (+X left, +Y up). + + Args: + cameras + with_xyflip: flips x- and y-axis if set to True. + Optional kwargs: + image_size: ((height, width),) specifying the height, width + of the image. If not provided, it reads it from cameras. + + We represent the screen to NDC conversion as a Transform3d + with projection matrix + + K = [ + [1/s, 0, 0, cx/s], + [ 0, 1/s, 0, cy/s], + [ 0, 0, 1, 0], + [ 0, 0, 0, 1], + ] + + """ + transform = get_ndc_to_screen_transform( + cameras, + with_xyflip=with_xyflip, + image_size=image_size, + ).inverse() + return transform + + +def try_get_projection_transform( + cameras: CamerasBase, cameras_kwargs: Dict[str, Any] +) -> Optional[Transform3d]: + """ + Try block to get projection transform from cameras and cameras_kwargs. + + Args: + cameras: cameras instance, can be linear cameras or nonliear cameras + cameras_kwargs: camera parameters to be passed to cameras + + Returns: + If the camera implemented projection_transform, return the + projection transform; Otherwise, return None + """ + + transform = None + try: + transform = cameras.get_projection_transform(**cameras_kwargs) + except NotImplementedError: + pass + return transform diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/compositing.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/compositing.py new file mode 100644 index 0000000000000000000000000000000000000000..507f3f90755309c8f98eadee6231c7e16223f37f --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/compositing.py @@ -0,0 +1,244 @@ +# 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. + +# pyre-unsafe + +import torch +from pytorch3d import _C + + +# Example functions for blending the top K features per pixel using the outputs +# from rasterization. +# NOTE: All blending function should return a (N, H, W, C) tensor per batch element. +# This can be an image (C=3) or a set of features. + + +class _CompositeAlphaPoints(torch.autograd.Function): + """ + Composite features within a z-buffer using alpha compositing. Given a z-buffer + with corresponding features and weights, these values are accumulated according + to their weights such that features nearer in depth contribute more to the final + feature than ones further away. + + Concretely this means: + weighted_fs[b,c,i,j] = sum_k cum_alpha_k * features[c,pointsidx[b,k,i,j]] + cum_alpha_k = alphas[b,k,i,j] * prod_l=0..k-1 (1 - alphas[b,l,i,j]) + + Args: + features: Packed Tensor of shape (C, P) giving the features of each point. + alphas: float32 Tensor of shape (N, points_per_pixel, image_size, + image_size) giving the weight of each point in the z-buffer. + Values should be in the interval [0, 1]. + pointsidx: int32 Tensor of shape (N, points_per_pixel, image_size, image_size) + giving the indices of the nearest points at each pixel, sorted in z-order. + Concretely pointsidx[n, k, y, x] = p means that features[:, p] is the + feature of the kth closest point (along the z-direction) to pixel (y, x) in + batch element n. This is weighted by alphas[n, k, y, x]. + + Returns: + weighted_fs: Tensor of shape (N, C, image_size, image_size) + giving the accumulated features at each point. + """ + + @staticmethod + def forward(ctx, features, alphas, points_idx): + pt_cld = _C.accum_alphacomposite(features, alphas, points_idx) + + ctx.save_for_backward(features.clone(), alphas.clone(), points_idx.clone()) + return pt_cld + + @staticmethod + def backward(ctx, grad_output): + grad_features = None + grad_alphas = None + grad_points_idx = None + features, alphas, points_idx = ctx.saved_tensors + + grad_features, grad_alphas = _C.accum_alphacomposite_backward( + grad_output, features, alphas, points_idx + ) + + return grad_features, grad_alphas, grad_points_idx, None + + +def alpha_composite(pointsidx, alphas, pt_clds) -> torch.Tensor: + """ + Composite features within a z-buffer using alpha compositing. Given a z-buffer + with corresponding features and weights, these values are accumulated according + to their weights such that features nearer in depth contribute more to the final + feature than ones further away. + + Concretely this means: + weighted_fs[b,c,i,j] = sum_k cum_alpha_k * features[c,pointsidx[b,k,i,j]] + cum_alpha_k = alphas[b,k,i,j] * prod_l=0..k-1 (1 - alphas[b,l,i,j]) + + + Args: + pt_clds: Tensor of shape (N, C, P) giving the features of each point (can use + RGB for example). + alphas: float32 Tensor of shape (N, points_per_pixel, image_size, + image_size) giving the weight of each point in the z-buffer. + Values should be in the interval [0, 1]. + pointsidx: int32 Tensor of shape (N, points_per_pixel, image_size, image_size) + giving the indices of the nearest points at each pixel, sorted in z-order. + Concretely pointsidx[n, k, y, x] = p means that features[n, :, p] is the + feature of the kth closest point (along the z-direction) to pixel (y, x) in + batch element n. This is weighted by alphas[n, k, y, x]. + + Returns: + Combined features: Tensor of shape (N, C, image_size, image_size) + giving the accumulated features at each point. + """ + return _CompositeAlphaPoints.apply(pt_clds, alphas, pointsidx) + + +class _CompositeNormWeightedSumPoints(torch.autograd.Function): + """ + Composite features within a z-buffer using normalized weighted sum. Given a z-buffer + with corresponding features and weights, these values are accumulated + according to their weights such that depth is ignored; the weights are used to + perform a weighted sum. + + Concretely this means: + weighted_fs[b,c,i,j] = + sum_k alphas[b,k,i,j] * features[c,pointsidx[b,k,i,j]] / sum_k alphas[b,k,i,j] + + Args: + features: Packed Tensor of shape (C, P) giving the features of each point. + alphas: float32 Tensor of shape (N, points_per_pixel, image_size, + image_size) giving the weight of each point in the z-buffer. + Values should be in the interval [0, 1]. + pointsidx: int32 Tensor of shape (N, points_per_pixel, image_size, image_size) + giving the indices of the nearest points at each pixel, sorted in z-order. + Concretely pointsidx[n, k, y, x] = p means that features[:, p] is the + feature of the kth closest point (along the z-direction) to pixel (y, x) in + batch element n. This is weighted by alphas[n, k, y, x]. + + Returns: + weighted_fs: Tensor of shape (N, C, image_size, image_size) + giving the accumulated features at each point. + """ + + @staticmethod + def forward(ctx, features, alphas, points_idx): + pt_cld = _C.accum_weightedsumnorm(features, alphas, points_idx) + + ctx.save_for_backward(features.clone(), alphas.clone(), points_idx.clone()) + return pt_cld + + @staticmethod + def backward(ctx, grad_output): + grad_features = None + grad_alphas = None + grad_points_idx = None + features, alphas, points_idx = ctx.saved_tensors + + grad_features, grad_alphas = _C.accum_weightedsumnorm_backward( + grad_output, features, alphas, points_idx + ) + + return grad_features, grad_alphas, grad_points_idx, None + + +def norm_weighted_sum(pointsidx, alphas, pt_clds) -> torch.Tensor: + """ + Composite features within a z-buffer using normalized weighted sum. Given a z-buffer + with corresponding features and weights, these values are accumulated + according to their weights such that depth is ignored; the weights are used to + perform a weighted sum. + + Concretely this means: + weighted_fs[b,c,i,j] = + sum_k alphas[b,k,i,j] * features[c,pointsidx[b,k,i,j]] / sum_k alphas[b,k,i,j] + + Args: + pt_clds: Packed feature tensor of shape (C, P) giving the features of each point + (can use RGB for example). + alphas: float32 Tensor of shape (N, points_per_pixel, image_size, + image_size) giving the weight of each point in the z-buffer. + Values should be in the interval [0, 1]. + pointsidx: int32 Tensor of shape (N, points_per_pixel, image_size, image_size) + giving the indices of the nearest points at each pixel, sorted in z-order. + Concretely pointsidx[n, k, y, x] = p means that features[:, p] is the + feature of the kth closest point (along the z-direction) to pixel (y, x) in + batch element n. This is weighted by alphas[n, k, y, x]. + + Returns: + Combined features: Tensor of shape (N, C, image_size, image_size) + giving the accumulated features at each point. + """ + return _CompositeNormWeightedSumPoints.apply(pt_clds, alphas, pointsidx) + + +class _CompositeWeightedSumPoints(torch.autograd.Function): + """ + Composite features within a z-buffer using normalized weighted sum. Given a z-buffer + with corresponding features and weights, these values are accumulated + according to their weights such that depth is ignored; the weights are used to + perform a weighted sum. As opposed to norm weighted sum, the weights are not + normalized to sum to 1. + + Concretely this means: + weighted_fs[b,c,i,j] = sum_k alphas[b,k,i,j] * features[c,pointsidx[b,k,i,j]] + + Args: + features: Packed Tensor of shape (C, P) giving the features of each point. + alphas: float32 Tensor of shape (N, points_per_pixel, image_size, + image_size) giving the weight of each point in the z-buffer. + Values should be in the interval [0, 1]. + pointsidx: int32 Tensor of shape (N, points_per_pixel, image_size, image_size) + giving the indices of the nearest points at each pixel, sorted in z-order. + Concretely pointsidx[n, k, y, x] = p means that features[:, p] is the + feature of the kth closest point (along the z-direction) to pixel (y, x) in + batch element n. This is weighted by alphas[n, k, y, x]. + + Returns: + weighted_fs: Tensor of shape (N, C, image_size, image_size) + giving the accumulated features at each point. + """ + + @staticmethod + def forward(ctx, features, alphas, points_idx): + pt_cld = _C.accum_weightedsum(features, alphas, points_idx) + + ctx.save_for_backward(features.clone(), alphas.clone(), points_idx.clone()) + return pt_cld + + @staticmethod + def backward(ctx, grad_output): + grad_features = None + grad_alphas = None + grad_points_idx = None + features, alphas, points_idx = ctx.saved_tensors + + grad_features, grad_alphas = _C.accum_weightedsum_backward( + grad_output, features, alphas, points_idx + ) + + return grad_features, grad_alphas, grad_points_idx, None + + +def weighted_sum(pointsidx, alphas, pt_clds) -> torch.Tensor: + """ + Composite features within a z-buffer using normalized weighted sum. + + Args: + pt_clds: Packed Tensor of shape (C, P) giving the features of each point + (can use RGB for example). + alphas: float32 Tensor of shape (N, points_per_pixel, image_size, + image_size) giving the weight of each point in the z-buffer. + Values should be in the interval [0, 1]. + pointsidx: int32 Tensor of shape (N, points_per_pixel, image_size, image_size) + giving the indices of the nearest points at each pixel, sorted in z-order. + Concretely pointsidx[n, k, y, x] = p means that features[:, p] is the + feature of the kth closest point (along the z-direction) to pixel (y, x) in + batch element n. This is weighted by alphas[n, k, y, x]. + + Returns: + Combined features: Tensor of shape (N, C, image_size, image_size) + giving the accumulated features at each point. + """ + return _CompositeWeightedSumPoints.apply(pt_clds, alphas, pointsidx) diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/fisheyecameras.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/fisheyecameras.py new file mode 100644 index 0000000000000000000000000000000000000000..5b464a0be54317c259d658b695f4adacf4fdad21 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/fisheyecameras.py @@ -0,0 +1,585 @@ +# 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. + +# pyre-unsafe + +import math +from typing import List, Optional, Tuple, Union + +import torch +from pytorch3d.common.datatypes import Device +from pytorch3d.renderer.cameras import _R, _T, CamerasBase + +_focal_length = torch.tensor(((1.0,),)) +_principal_point = torch.tensor(((0.0, 0.0),)) +_radial_params = torch.tensor(((0.0, 0.0, 0.0, 0.0, 0.0, 0.0),)) +_tangential_params = torch.tensor(((0.0, 0.0),)) +_thin_prism_params = torch.tensor(((0.0, 0.0, 0.0, 0.0),)) + + +class FishEyeCameras(CamerasBase): + """ + A class which extends Pinhole camera by considering radial, tangential and + thin-prism distortion. For the fisheye camera model, k1, k2, ..., k_n_radial are + polynomial coefficents to model radial distortions. Two common types of radial + distortions are barrel and pincusion radial distortions. + + a = x / z, b = y / z, r = (a*a+b*b)^(1/2) + th = atan(r) + [x_r] = (th+ k0 * th^3 + k1* th^5 + ...) [a/r] + [y_r] [b/r] [1] + + + The tangential distortion parameters are p1 and p2. The primary cause is + due to the lens assembly not being centered over and parallel to the image plane. + tangentialDistortion = [(2 x_r^2 + rd^2)*p_0 + 2*x_r*y_r*p_1] + [(2 y_r^2 + rd^2)*p_1 + 2*x_r*y_r*p_0] [2] + where rd^2 = x_r^2 + y_r^2 + + The thin-prism distortion is modeled with s1, s2, s3, s4 coefficients + thinPrismDistortion = [s0 * rd^2 + s1 rd^4] + [s2 * rd^2 + s3 rd^4] [3] + + The projection + proj = diag(f, f) * uvDistorted + [cu; cv] + uvDistorted = [x_r] + tangentialDistortion + thinPrismDistortion [4] + [y_r] + f is the focal length and cu, cv are principal points in x, y axis. + + """ + + _FIELDS = ( + "focal_length", + "principal_point", + "R", + "T", + "radial_params", + "tangential_params", + "thin_prism_params", + "world_coordinates", + "use_radial", + "use_tangential", + "use_tin_prism", + "device", + "image_size", + ) + + def __init__( + self, + focal_length=_focal_length, + principal_point=_principal_point, + radial_params=_radial_params, + tangential_params=_tangential_params, + thin_prism_params=_thin_prism_params, + R: torch.Tensor = _R, + T: torch.Tensor = _T, + world_coordinates: bool = False, + use_radial: bool = True, + use_tangential: bool = True, + use_thin_prism: bool = True, + device: Device = "cpu", + image_size: Optional[Union[List, Tuple, torch.Tensor]] = None, + ) -> None: + """ + + Args: + focal_ength: Focal length of the camera in world units. + A tensor of shape (N, 1) for square pixels, + where N is number of transforms. + principal_point: xy coordinates of the center of + the principal point of the camera in pixels. + A tensor of shape (N, 2). + radial_params: parameters for radial distortions. + A tensor of shape (N, num_radial). + tangential_params:parameters for tangential distortions. + A tensor of shape (N, 2). + thin_prism_params: parameters for thin-prism distortions. + A tensor of shape (N, 4). + R: Rotation matrix of shape (N, 3, 3) + T: Translation matrix of shape (N, 3) + world_coordinates: if True, project from world coordinates; otherwise from camera + coordinates + use_radial: radial_distortion, default to True + use_tangential: tangential distortion, default to True + use_thin_prism: thin prism distortion, default to True + device: torch.device or string + image_size: (height, width) of image size. + A tensor of shape (N, 2) or a list/tuple. Required for screen cameras. + + """ + + kwargs = {"image_size": image_size} if image_size is not None else {} + super().__init__( + device=device, + R=R, + T=T, + **kwargs, # pyre-ignore + ) + if image_size is not None: + if (self.image_size < 1).any(): # pyre-ignore + raise ValueError("Image_size provided has invalid values") + else: + self.image_size = None + + self.device = device + self.focal = focal_length.to(self.device) + self.principal_point = principal_point.to(self.device) + self.radial_params = radial_params.to(self.device) + self.tangential_params = tangential_params.to(self.device) + self.thin_prism_params = thin_prism_params.to(self.device) + self.R = R + self.T = T + self.world_coordinates = world_coordinates + self.use_radial = use_radial + self.use_tangential = use_tangential + self.use_thin_prism = use_thin_prism + self.epsilon = 1e-10 + self.num_distortion_iters = 50 + + self.R = self.R.to(self.device) + self.T = self.T.to(self.device) + self.num_radial = radial_params.shape[-1] + + def _project_points_batch( + self, + focal, + principal_point, + radial_params, + tangential_params, + thin_prism_params, + points, + ) -> torch.Tensor: + """ + Takes in points in the local reference frame of the camera and projects it + onto the image plan. Since this is a symmetric model, points with negative z are + projected to the positive sphere. i.e project(1,1,-1) == project(-1,-1,1) + + Args: + focal: (1) + principal_point: (2) + radial_params: (num_radial) + tangential_params: (2) + thin_prism_params: (4) + points in the camera coordinate frame: (..., 3). E.g., (P, 3) (1, P, 3) + or (M, P, 3) where P is the number of points + + Returns: + projected_points in the image plane: (..., 3). E.g., (P, 3) or + (1, P, 3) or (M, P, 3) + + """ + assert points.shape[-1] == 3, "points shape incorrect" + ab = points[..., :2] / points[..., 2:] + uv_distorted = ab + + r = ab.norm(dim=-1) + th = r.atan() + theta_sq = th * th + + # compute radial distortions, eq 1 + t = theta_sq + theta_pow = torch.stack([t, t**2, t**3, t**4, t**5, t**6], dim=-1) + th_radial = 1 + torch.sum(theta_pow * radial_params, dim=-1) + + # compute th/r, using the limit for small values + th_divr = th / r + boolean_mask = abs(r) < self.epsilon + th_divr[boolean_mask] = 1.0 + + # the distorted coordinates -- except for focal length and principal point + # start with the radial term + coeff = th_radial * th_divr + xr_yr = coeff[..., None] * ab + xr_yr_squared_norm = torch.pow(xr_yr, 2).sum(dim=-1, keepdim=True) + + if self.use_radial: + uv_distorted = xr_yr + + # compute tangential distortions, eq 2 + if self.use_tangential: + temp = 2 * torch.sum( + xr_yr * tangential_params, + dim=-1, + ) + uv_distorted = uv_distorted + ( + temp[..., None] * xr_yr + xr_yr_squared_norm * tangential_params + ) + + # compute thin-prism distortions, eq 3 + sh = uv_distorted.shape[:-1] + if self.use_thin_prism: + radial_powers = torch.cat( + [xr_yr_squared_norm, xr_yr_squared_norm * xr_yr_squared_norm], dim=-1 + ) + uv_distorted[..., 0] = uv_distorted[..., 0] + torch.sum( + thin_prism_params[..., 0:2] * radial_powers, + dim=-1, + ) + uv_distorted[..., 1] = uv_distorted[..., 1] + torch.sum( + thin_prism_params[..., 2:4] * radial_powers, + dim=-1, + ) + # return value: distorted points on the uv plane, eq 4 + projected_points = focal * uv_distorted + principal_point + return torch.cat( + [projected_points, torch.ones(list(sh) + [1], device=self.device)], dim=-1 + ) + + def check_input(self, points: torch.Tensor, batch_size: int): + """ + Check if the shapes are broadcastable between points and transforms. + Accept points of shape (P, 3) or (1, P, 3) or (M, P, 3). The batch_size + for transforms should be 1 when points take (M, P, 3). The batch_size + can be 1 or N when points take shape (P, 3). + + Args: + points: tensor of shape (P, 3) or (1, P, 3) or (M, P, 3) + batch_size: number of transforms + + Returns: + Boolean value if the input shapes are compatible. + """ + if points.ndim > 3: + return False + if points.ndim == 3: + M, P, K = points.shape + if K != 3: + return False + if M > 1 and batch_size > 1: + return False + return True + + def transform_points( + self, points, eps: Optional[float] = None, **kwargs + ) -> torch.Tensor: + """ + Transform input points from camera space to image space. + Args: + points: tensor of (..., 3). E.g., (P, 3) or (1, P, 3), (M, P, 3) + eps: tiny number to avoid zero divsion + + Returns: + torch.Tensor + when points take shape (P, 3) or (1, P, 3), output is (N, P, 3) + when points take shape (M, P, 3), output is (M, P, 3) + where N is the number of transforms, P number of points + """ + # project from world space to camera space + if self.world_coordinates: + world_to_view_transform = self.get_world_to_view_transform( + R=self.R, T=self.T + ) + points = world_to_view_transform.transform_points( + points.to(self.device), eps=eps + ) + else: + points = points.to(self.device) + + # project from camera space to image space + N = len(self.radial_params) + if not self.check_input(points, N): + msg = "Expected points of (P, 3) with batch_size 1 or N, or shape (M, P, 3) \ + with batch_size 1; got points of shape %r and batch_size %r" + raise ValueError(msg % (points.shape, N)) + + if N == 1: + return self._project_points_batch( + self.focal[0], + self.principal_point[0], + self.radial_params[0], + self.tangential_params[0], + self.thin_prism_params[0], + points, + ) + else: + outputs = [] + for i in range(N): + outputs.append( + self._project_points_batch( + self.focal[i], + self.principal_point[i], + self.radial_params[i], + self.tangential_params[i], + self.thin_prism_params[i], + points, + ) + ) + outputs = torch.stack(outputs, dim=0) + return outputs.squeeze() + + def _unproject_points_batch( + self, + focal, + principal_point, + radial_params, + tangential_params, + thin_prism_params, + xy: torch.Tensor, + ) -> torch.Tensor: + """ + Args: + focal: (1) + principal_point: (2) + radial_params: (num_radial) + tangential_params: (2) + thin_prism_params: (4) + xy: (..., 2) + + Returns: + point3d_est: (..., 3) + """ + sh = list(xy.shape[:-1]) + assert xy.shape[-1] == 2, "xy_depth shape incorrect" + uv_distorted = (xy - principal_point) / focal + + # get xr_yr from uvDistorted + xr_yr = self._compute_xr_yr_from_uv_distorted( + tangential_params, thin_prism_params, uv_distorted + ) + xr_yrNorm = torch.norm(xr_yr, dim=-1) + + # find theta + theta = self._get_theta_from_norm_xr_yr(radial_params, xr_yrNorm) + # get the point coordinates: + point3d_est = theta.new_ones(*sh, 3) + point3d_est[..., :2] = theta.tan()[..., None] / xr_yrNorm[..., None] * xr_yr + return point3d_est + + def unproject_points( + self, + xy_depth: torch.Tensor, + world_coordinates: bool = True, + scaled_depth_input: bool = False, + **kwargs, + ) -> torch.Tensor: + """ + Takes in 3-point ``uv_depth`` in the image plane of the camera and unprojects it + into the reference frame of the camera. + This function is the inverse of ``transform_points``. In particular it holds that + + X = unproject(project(X)) + and + x = project(unproject(s*x)) + + Args: + xy_depth: points in the image plane of shape (..., 3). E.g., + (P, 3) or (1, P, 3) or (M, P, 3) + world_coordinates: if the output is in world_coordinate, if False, convert to + camera coordinate + scaled_depth_input: False + + Returns: + unprojected_points in the camera frame with z = 1 + when points take shape (P, 3) or (1, P, 3), output is (N, P, 3) + when points take shape (M, P, 3), output is (M, P, 3) + where N is the number of transforms, P number of point + """ + xy_depth = xy_depth.to(self.device) + N = len(self.radial_params) + if N == 1: + return self._unproject_points_batch( + self.focal[0], + self.principal_point[0], + self.radial_params[0], + self.tangential_params[0], + self.thin_prism_params[0], + xy_depth[..., 0:2], + ) + else: + outputs = [] + for i in range(N): + outputs.append( + self._unproject_points_batch( + self.focal[i], + self.principal_point[i], + self.radial_params[i], + self.tangential_params[i], + self.thin_prism_params[i], + xy_depth[..., 0:2], + ) + ) + outputs = torch.stack(outputs, dim=0) + return outputs.squeeze() + + def _compute_xr_yr_from_uv_distorted( + self, tangential_params, thin_prism_params, uv_distorted: torch.Tensor + ) -> torch.Tensor: + """ + Helper function to compute the vector [x_r; y_r] from uvDistorted + + Args: + tangential_params: (2) + thin_prism_params: (4) + uv_distorted: (..., 2), E.g., (P, 2), (1, P, 2), (M, P, 2) + + Returns: + xr_yr: (..., 2) + """ + # early exit if we're not using any tangential/ thin prism distortions + if not self.use_tangential and not self.use_thin_prism: + return uv_distorted + + xr_yr = uv_distorted + # do Newton iterations to find xr_yr + for _ in range(self.num_distortion_iters): + # compute the estimated uvDistorted + uv_distorted_est = xr_yr.clone() + xr_yr_squared_norm = torch.pow(xr_yr, 2).sum(dim=-1, keepdim=True) + + if self.use_tangential: + temp = 2.0 * torch.sum( + xr_yr * tangential_params[..., 0:2], + dim=-1, + keepdim=True, + ) + uv_distorted_est = uv_distorted_est + ( + temp * xr_yr + xr_yr_squared_norm * tangential_params[..., 0:2] + ) + + if self.use_thin_prism: + radial_powers = torch.cat( + [xr_yr_squared_norm, xr_yr_squared_norm * xr_yr_squared_norm], + dim=-1, + ) + uv_distorted_est[..., 0] = uv_distorted_est[..., 0] + torch.sum( + thin_prism_params[..., 0:2] * radial_powers, + dim=-1, + ) + uv_distorted_est[..., 1] = uv_distorted_est[..., 1] + torch.sum( + thin_prism_params[..., 2:4] * radial_powers, + dim=-1, + ) + + # compute the derivative of uvDistorted wrt xr_yr + duv_distorted_dxryr = self._compute_duv_distorted_dxryr( + tangential_params, thin_prism_params, xr_yr, xr_yr_squared_norm[..., 0] + ) + # compute correction: + # note: the matrix duvDistorted_dxryr will be close to identity (for reasonable + # values of tangential/thin prism distortions) + correction = torch.linalg.solve( + duv_distorted_dxryr, (uv_distorted - uv_distorted_est)[..., None] + ) + xr_yr = xr_yr + correction[..., 0] + return xr_yr + + def _get_theta_from_norm_xr_yr( + self, radial_params, th_radial_desired + ) -> torch.Tensor: + """ + Helper function to compute the angle theta from the norm of the vector [x_r; y_r] + + Args: + radial_params: k1, k2, ..., k_num_radial, (num_radial) + th_radial_desired: desired angle of shape (...), E.g., (P), (1, P), (M, P) + + Returns: + th: angle theta (in radians) of shape (...), E.g., (P), (1, P), (M, P) + """ + sh = list(th_radial_desired.shape) + th = th_radial_desired + c = torch.tensor( + [2.0 * i + 3 for i in range(self.num_radial)], device=self.device + ) + for _ in range(self.num_distortion_iters): + theta_sq = th * th + th_radial = 1.0 + dthD_dth = 1.0 + + # compute the theta polynomial and its derivative wrt theta + t = theta_sq + theta_pow = torch.stack([t, t**2, t**3, t**4, t**5, t**6], dim=-1) + th_radial = th_radial + torch.sum(theta_pow * radial_params, dim=-1) + + dthD_dth = dthD_dth + torch.sum(c * radial_params * theta_pow, dim=-1) + th_radial = th_radial * th + + # compute the correction + step = torch.zeros(*sh, device=self.device) + # make sure don't divide by zero + nonzero_mask = dthD_dth.abs() > self.epsilon + step = step + nonzero_mask * (th_radial_desired - th_radial) / dthD_dth + # if derivative is close to zero, apply small correction in the appropriate + # direction to avoid numerical explosions + close_to_zero_mask = dthD_dth.abs() <= self.epsilon + dir_mask = (th_radial_desired - th_radial) * dthD_dth > 0.0 + boolean_mask = close_to_zero_mask & dir_mask + step = step + 10.0 * self.epsilon * boolean_mask + step = step - 10 * self.epsilon * (~nonzero_mask & ~boolean_mask) + + # apply correction + th = th + step + # revert to within 180 degrees FOV to avoid numerical overflow + idw = th.abs() >= math.pi / 2.0 + th[idw] = 0.999 * math.pi / 2.0 + return th + + def _compute_duv_distorted_dxryr( + self, tangential_params, thin_prism_params, xr_yr, xr_yr_squareNorm + ) -> torch.Tensor: + """ + Helper function, computes the Jacobian of uvDistorted wrt the vector [x_r;y_r] + + Args: + tangential_params: (2) + thin_prism_params: (4) + xr_yr: (P, 2) + xr_yr_squareNorm: (...), E.g., (P), (1, P), (M, P) + + Returns: + duv_distorted_dxryr: (..., 2, 2) Jacobian + """ + sh = list(xr_yr.shape[:-1]) + duv_distorted_dxryr = torch.empty((*sh, 2, 2), device=self.device) + if self.use_tangential: + duv_distorted_dxryr[..., 0, 0] = ( + 1.0 + + 6.0 * xr_yr[..., 0] * tangential_params[..., 0] + + 2.0 * xr_yr[..., 1] * tangential_params[..., 1] + ) + offdiag = 2.0 * ( + xr_yr[..., 0] * tangential_params[..., 1] + + xr_yr[..., 1] * tangential_params[..., 0] + ) + duv_distorted_dxryr[..., 0, 1] = offdiag + duv_distorted_dxryr[..., 1, 0] = offdiag + duv_distorted_dxryr[..., 1, 1] = ( + 1.0 + + 6.0 * xr_yr[..., 1] * tangential_params[..., 1] + + 2.0 * xr_yr[..., 0] * tangential_params[..., 0] + ) + else: + duv_distorted_dxryr = torch.eye(2).repeat(*sh, 1, 1) + + if self.use_thin_prism: + temp1 = 2.0 * ( + thin_prism_params[..., 0] + + 2.0 * thin_prism_params[..., 1] * xr_yr_squareNorm[...] + ) + duv_distorted_dxryr[..., 0, 0] = ( + duv_distorted_dxryr[..., 0, 0] + xr_yr[..., 0] * temp1 + ) + duv_distorted_dxryr[..., 0, 1] = ( + duv_distorted_dxryr[..., 0, 1] + xr_yr[..., 1] * temp1 + ) + + temp2 = 2.0 * ( + thin_prism_params[..., 2] + + 2.0 * thin_prism_params[..., 3] * xr_yr_squareNorm[...] + ) + duv_distorted_dxryr[..., 1, 0] = ( + duv_distorted_dxryr[..., 1, 0] + xr_yr[..., 0] * temp2 + ) + duv_distorted_dxryr[..., 1, 1] = ( + duv_distorted_dxryr[..., 1, 1] + xr_yr[..., 1] * temp2 + ) + return duv_distorted_dxryr + + def in_ndc(self): + return True + + def is_perspective(self): + return False diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/implicit/raysampling.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/implicit/raysampling.py new file mode 100644 index 0000000000000000000000000000000000000000..09decba8f6681fedfc3d5e1f16cdf3830aecac63 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/implicit/raysampling.py @@ -0,0 +1,796 @@ +# 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. + +# pyre-unsafe + +import warnings +from typing import Optional, Tuple, Union + +import torch +from pytorch3d.common.compat import meshgrid_ij +from pytorch3d.ops import padded_to_packed +from pytorch3d.renderer.cameras import CamerasBase +from pytorch3d.renderer.implicit.utils import HeterogeneousRayBundle, RayBundle +from torch.nn import functional as F + + +""" +This file defines three raysampling techniques: + - MultinomialRaysampler which can be used to sample rays from pixels of an image grid + - NDCMultinomialRaysampler which can be used to sample rays from pixels of an image grid, + which follows the pytorch3d convention for image grid coordinates + - MonteCarloRaysampler which randomly selects real-valued locations in the image plane + and emits rays from them +""" + + +class MultinomialRaysampler(torch.nn.Module): + """ + Samples a fixed number of points along rays which are regularly distributed + in a batch of rectangular image grids. Points along each ray + have uniformly-spaced z-coordinates between a predefined + minimum and maximum depth. + + The raysampler first generates a 3D coordinate grid of the following form:: + + / min_x, min_y, max_depth -------------- / max_x, min_y, max_depth + / /| + / / | ^ + / min_depth min_depth / | | + min_x ----------------------------- max_x | | image + min_y min_y | | height + | | | | + | | | v + | | | + | | / max_x, max_y, ^ + | | / max_depth / + min_x max_y / / n_pts_per_ray + max_y ----------------------------- max_x/ min_depth v + < --- image_width --- > + + In order to generate ray points, `MultinomialRaysampler` takes each 3D point of + the grid (with coordinates `[x, y, depth]`) and unprojects it + with `cameras.unproject_points([x, y, depth])`, where `cameras` are an + additional input to the `forward` function. + + Note that this is a generic implementation that can support any image grid + coordinate convention. For a raysampler which follows the PyTorch3D + coordinate conventions please refer to `NDCMultinomialRaysampler`. + As such, `NDCMultinomialRaysampler` is a special case of `MultinomialRaysampler`. + + Attributes: + min_x: The leftmost x-coordinate of each ray's source pixel's center. + max_x: The rightmost x-coordinate of each ray's source pixel's center. + min_y: The topmost y-coordinate of each ray's source pixel's center. + max_y: The bottommost y-coordinate of each ray's source pixel's center. + """ + + def __init__( + self, + *, + min_x: float, + max_x: float, + min_y: float, + max_y: float, + image_width: int, + image_height: int, + n_pts_per_ray: int, + min_depth: float, + max_depth: float, + n_rays_per_image: Optional[int] = None, + n_rays_total: Optional[int] = None, + unit_directions: bool = False, + stratified_sampling: bool = False, + ) -> None: + """ + Args: + min_x: The leftmost x-coordinate of each ray's source pixel's center. + max_x: The rightmost x-coordinate of each ray's source pixel's center. + min_y: The topmost y-coordinate of each ray's source pixel's center. + max_y: The bottommost y-coordinate of each ray's source pixel's center. + image_width: The horizontal size of the image grid. + image_height: The vertical size of the image grid. + n_pts_per_ray: The number of points sampled along each ray. + min_depth: The minimum depth of a ray-point. + max_depth: The maximum depth of a ray-point. + n_rays_per_image: If given, this amount of rays are sampled from the grid. + `n_rays_per_image` and `n_rays_total` cannot both be defined. + n_rays_total: How many rays in total to sample from the cameras provided. The result + is as if `n_rays_total_training` cameras were sampled with replacement from the + cameras provided and for every camera one ray was sampled. If set returns the + HeterogeneousRayBundle with batch_size=n_rays_total. + `n_rays_per_image` and `n_rays_total` cannot both be defined. + unit_directions: whether to normalize direction vectors in ray bundle. + stratified_sampling: if True, performs stratified random sampling + along the ray; otherwise takes ray points at deterministic offsets. + """ + super().__init__() + self._n_pts_per_ray = n_pts_per_ray + self._min_depth = min_depth + self._max_depth = max_depth + self._n_rays_per_image = n_rays_per_image + self._n_rays_total = n_rays_total + self._unit_directions = unit_directions + self._stratified_sampling = stratified_sampling + self.min_x, self.max_x = min_x, max_x + self.min_y, self.max_y = min_y, max_y + # get the initial grid of image xy coords + y, x = meshgrid_ij( + torch.linspace(min_y, max_y, image_height, dtype=torch.float32), + torch.linspace(min_x, max_x, image_width, dtype=torch.float32), + ) + _xy_grid = torch.stack([x, y], dim=-1) + + self.register_buffer("_xy_grid", _xy_grid, persistent=False) + + def forward( + self, + cameras: CamerasBase, + *, + mask: Optional[torch.Tensor] = None, + min_depth: Optional[float] = None, + max_depth: Optional[float] = None, + n_rays_per_image: Optional[int] = None, + n_pts_per_ray: Optional[int] = None, + stratified_sampling: Optional[bool] = None, + n_rays_total: Optional[int] = None, + **kwargs, + ) -> Union[RayBundle, HeterogeneousRayBundle]: + """ + Args: + cameras: A batch of `batch_size` cameras from which the rays are emitted. + mask: if given, the rays are sampled from the mask. Should be of size + (batch_size, image_height, image_width). + min_depth: The minimum depth of a ray-point. + max_depth: The maximum depth of a ray-point. + n_rays_per_image: If given, this amount of rays are sampled from the grid. + `n_rays_per_image` and `n_rays_total` cannot both be defined. + n_pts_per_ray: The number of points sampled along each ray. + stratified_sampling: if set, overrides stratified_sampling provided + in __init__. + n_rays_total: How many rays in total to sample from the cameras provided. The result + is as if `n_rays_total_training` cameras were sampled with replacement from the + cameras provided and for every camera one ray was sampled. If set returns the + HeterogeneousRayBundle with batch_size=n_rays_total. + `n_rays_per_image` and `n_rays_total` cannot both be defined. + Returns: + A named tuple RayBundle or dataclass HeterogeneousRayBundle with the + following fields: + + origins: A tensor of shape + `(batch_size, s1, s2, 3)` + denoting the locations of ray origins in the world coordinates. + directions: A tensor of shape + `(batch_size, s1, s2, 3)` + denoting the directions of each ray in the world coordinates. + lengths: A tensor of shape + `(batch_size, s1, s2, n_pts_per_ray)` + containing the z-coordinate (=depth) of each ray in world units. + xys: A tensor of shape + `(batch_size, s1, s2, 2)` + containing the 2D image coordinates of each ray or, + if mask is given, `(batch_size, n, 1, 2)` + Here `s1, s2` refer to spatial dimensions. + `(s1, s2)` refer to (highest priority first): + - `(1, 1)` if `n_rays_total` is provided, (batch_size=n_rays_total) + - `(n_rays_per_image, 1) if `n_rays_per_image` if provided, + - `(n, 1)` where n is the minimum cardinality of the mask + in the batch if `mask` is provided + - `(image_height, image_width)` if nothing from above is satisfied + + `HeterogeneousRayBundle` has additional members: + - camera_ids: tensor of shape (M,), where `M` is the number of unique sampled + cameras. It represents unique ids of sampled cameras. + - camera_counts: tensor of shape (M,), where `M` is the number of unique sampled + cameras. Represents how many times each camera from `camera_ids` was sampled + + `HeterogeneousRayBundle` is returned if `n_rays_total` is provided else `RayBundle` + is returned. + """ + n_rays_total = n_rays_total or self._n_rays_total + n_rays_per_image = n_rays_per_image or self._n_rays_per_image + if (n_rays_total is not None) and (n_rays_per_image is not None): + raise ValueError( + "`n_rays_total` and `n_rays_per_image` cannot both be defined." + ) + if n_rays_total: + ( + cameras, + mask, + camera_ids, # unique ids of sampled cameras + camera_counts, # number of times unique camera id was sampled + # `n_rays_per_image` is equal to the max number of times a simgle camera + # was sampled. We sample all cameras at `camera_ids` `n_rays_per_image` times + # and then discard the unneeded rays. + # pyre-ignore[9] + n_rays_per_image, + ) = _sample_cameras_and_masks(n_rays_total, cameras, mask) + else: + # pyre-ignore[9] + camera_ids: torch.LongTensor = torch.arange(len(cameras), dtype=torch.long) + + batch_size = cameras.R.shape[0] + device = cameras.device + + # expand the (H, W, 2) grid batch_size-times to (B, H, W, 2) + xy_grid = self._xy_grid.to(device).expand(batch_size, -1, -1, -1) + + if mask is not None and n_rays_per_image is None: + # if num rays not given, sample according to the smallest mask + n_rays_per_image = ( + n_rays_per_image or mask.sum(dim=(1, 2)).min().int().item() + ) + + if n_rays_per_image is not None: + if mask is not None: + assert mask.shape == xy_grid.shape[:3] + weights = mask.reshape(batch_size, -1) + else: + # it is probably more efficient to use torch.randperm + # for uniform weights but it is unlikely given that randperm + # is not batched and does not support partial permutation + _, width, height, _ = xy_grid.shape + weights = xy_grid.new_ones(batch_size, width * height) + # pyre-fixme[6]: For 2nd param expected `int` but got `Union[bool, + # float, int]`. + rays_idx = _safe_multinomial(weights, n_rays_per_image)[..., None].expand( + -1, -1, 2 + ) + + xy_grid = torch.gather(xy_grid.reshape(batch_size, -1, 2), 1, rays_idx)[ + :, :, None + ] + + min_depth = min_depth if min_depth is not None else self._min_depth + max_depth = max_depth if max_depth is not None else self._max_depth + n_pts_per_ray = ( + n_pts_per_ray if n_pts_per_ray is not None else self._n_pts_per_ray + ) + stratified_sampling = ( + stratified_sampling + if stratified_sampling is not None + else self._stratified_sampling + ) + + ray_bundle = _xy_to_ray_bundle( + cameras, + xy_grid, + min_depth, + max_depth, + n_pts_per_ray, + self._unit_directions, + stratified_sampling, + ) + + return ( + # pyre-ignore[61] + _pack_ray_bundle(ray_bundle, camera_ids, camera_counts) + if n_rays_total + else ray_bundle + ) + + +class NDCMultinomialRaysampler(MultinomialRaysampler): + """ + Samples a fixed number of points along rays which are regularly distributed + in a batch of rectangular image grids. Points along each ray + have uniformly-spaced z-coordinates between a predefined minimum and maximum depth. + + `NDCMultinomialRaysampler` follows the screen conventions of the `Meshes` and `Pointclouds` + renderers. I.e. the pixel coordinates are in [-1, 1]x[-u, u] or [-u, u]x[-1, 1] + where u > 1 is the aspect ratio of the image. + + For the description of arguments, see the documentation to MultinomialRaysampler. + """ + + def __init__( + self, + *, + image_width: int, + image_height: int, + n_pts_per_ray: int, + min_depth: float, + max_depth: float, + n_rays_per_image: Optional[int] = None, + n_rays_total: Optional[int] = None, + unit_directions: bool = False, + stratified_sampling: bool = False, + ) -> None: + if image_width >= image_height: + range_x = image_width / image_height + range_y = 1.0 + else: + range_x = 1.0 + range_y = image_height / image_width + + half_pix_width = range_x / image_width + half_pix_height = range_y / image_height + super().__init__( + min_x=range_x - half_pix_width, + max_x=-range_x + half_pix_width, + min_y=range_y - half_pix_height, + max_y=-range_y + half_pix_height, + image_width=image_width, + image_height=image_height, + n_pts_per_ray=n_pts_per_ray, + min_depth=min_depth, + max_depth=max_depth, + n_rays_per_image=n_rays_per_image, + n_rays_total=n_rays_total, + unit_directions=unit_directions, + stratified_sampling=stratified_sampling, + ) + + +class MonteCarloRaysampler(torch.nn.Module): + """ + Samples a fixed number of pixels within denoted xy bounds uniformly at random. + For each pixel, a fixed number of points is sampled along its ray at uniformly-spaced + z-coordinates such that the z-coordinates range between a predefined minimum + and maximum depth. + + For practical purposes, this is similar to MultinomialRaysampler without a mask, + however sampling at real-valued locations bypassing replacement checks may be faster. + """ + + def __init__( + self, + min_x: float, + max_x: float, + min_y: float, + max_y: float, + n_rays_per_image: int, + n_pts_per_ray: int, + min_depth: float, + max_depth: float, + *, + n_rays_total: Optional[int] = None, + unit_directions: bool = False, + stratified_sampling: bool = False, + ) -> None: + """ + Args: + min_x: The smallest x-coordinate of each ray's source pixel. + max_x: The largest x-coordinate of each ray's source pixel. + min_y: The smallest y-coordinate of each ray's source pixel. + max_y: The largest y-coordinate of each ray's source pixel. + n_rays_per_image: The number of rays randomly sampled in each camera. + `n_rays_per_image` and `n_rays_total` cannot both be defined. + n_pts_per_ray: The number of points sampled along each ray. + min_depth: The minimum depth of each ray-point. + max_depth: The maximum depth of each ray-point. + n_rays_total: How many rays in total to sample from the cameras provided. The result + is as if `n_rays_total_training` cameras were sampled with replacement from the + cameras provided and for every camera one ray was sampled. If set returns the + HeterogeneousRayBundle with batch_size=n_rays_total. + `n_rays_per_image` and `n_rays_total` cannot both be defined. + unit_directions: whether to normalize direction vectors in ray bundle. + stratified_sampling: if True, performs stratified sampling in n_pts_per_ray + bins for each ray; otherwise takes n_pts_per_ray deterministic points + on each ray with uniform offsets. + """ + super().__init__() + self._min_x = min_x + self._max_x = max_x + self._min_y = min_y + self._max_y = max_y + self._n_rays_per_image = n_rays_per_image + self._n_pts_per_ray = n_pts_per_ray + self._min_depth = min_depth + self._max_depth = max_depth + self._n_rays_total = n_rays_total + self._unit_directions = unit_directions + self._stratified_sampling = stratified_sampling + + def forward( + self, + cameras: CamerasBase, + *, + stratified_sampling: Optional[bool] = None, + **kwargs, + ) -> Union[RayBundle, HeterogeneousRayBundle]: + """ + Args: + cameras: A batch of `batch_size` cameras from which the rays are emitted. + stratified_sampling: if set, overrides stratified_sampling provided + in __init__. + Returns: + A named tuple `RayBundle` or dataclass `HeterogeneousRayBundle` with the + following fields: + + origins: A tensor of shape + `(batch_size, n_rays_per_image, 3)` + denoting the locations of ray origins in the world coordinates. + directions: A tensor of shape + `(batch_size, n_rays_per_image, 3)` + denoting the directions of each ray in the world coordinates. + lengths: A tensor of shape + `(batch_size, n_rays_per_image, n_pts_per_ray)` + containing the z-coordinate (=depth) of each ray in world units. + xys: A tensor of shape + `(batch_size, n_rays_per_image, 2)` + containing the 2D image coordinates of each ray. + If `n_rays_total` is provided `batch_size=n_rays_total`and + `n_rays_per_image=1` and `HeterogeneousRayBundle` is returned else `RayBundle` + is returned. + + `HeterogeneousRayBundle` has additional members: + - camera_ids: tensor of shape (M,), where `M` is the number of unique sampled + cameras. It represents unique ids of sampled cameras. + - camera_counts: tensor of shape (M,), where `M` is the number of unique sampled + cameras. Represents how many times each camera from `camera_ids` was sampled + """ + if ( + sum(x is not None for x in [self._n_rays_total, self._n_rays_per_image]) + != 1 + ): + raise ValueError( + "Exactly one of `self.n_rays_total` and `self.n_rays_per_image` " + "must be given." + ) + + if self._n_rays_total: + ( + cameras, + _, + camera_ids, + camera_counts, + n_rays_per_image, + ) = _sample_cameras_and_masks(self._n_rays_total, cameras, None) + else: + # pyre-ignore[9] + camera_ids: torch.LongTensor = torch.arange(len(cameras), dtype=torch.long) + n_rays_per_image = self._n_rays_per_image + + batch_size = cameras.R.shape[0] + + device = cameras.device + + # get the initial grid of image xy coords + # of shape (batch_size, n_rays_per_image, 2) + rays_xy = torch.cat( + [ + torch.rand( + size=(batch_size, n_rays_per_image, 1), + dtype=torch.float32, + device=device, + ) + * (high - low) + + low + for low, high in ( + (self._min_x, self._max_x), + (self._min_y, self._max_y), + ) + ], + dim=2, + ) + + stratified_sampling = ( + stratified_sampling + if stratified_sampling is not None + else self._stratified_sampling + ) + + ray_bundle = _xy_to_ray_bundle( + cameras, + rays_xy, + self._min_depth, + self._max_depth, + self._n_pts_per_ray, + self._unit_directions, + stratified_sampling, + ) + + return ( + # pyre-ignore[61] + _pack_ray_bundle(ray_bundle, camera_ids, camera_counts) + if self._n_rays_total + else ray_bundle + ) + + +# Settings for backwards compatibility +def GridRaysampler( + min_x: float, + max_x: float, + min_y: float, + max_y: float, + image_width: int, + image_height: int, + n_pts_per_ray: int, + min_depth: float, + max_depth: float, +) -> "MultinomialRaysampler": + """ + GridRaysampler has been DEPRECATED. Use MultinomialRaysampler instead. + Preserving GridRaysampler for backward compatibility. + """ + + warnings.warn( + """GridRaysampler is deprecated, + Use MultinomialRaysampler instead. + GridRaysampler will be removed in future releases.""", + PendingDeprecationWarning, + ) + + return MultinomialRaysampler( + min_x=min_x, + max_x=max_x, + min_y=min_y, + max_y=max_y, + image_width=image_width, + image_height=image_height, + n_pts_per_ray=n_pts_per_ray, + min_depth=min_depth, + max_depth=max_depth, + ) + + +# Settings for backwards compatibility +def NDCGridRaysampler( + image_width: int, + image_height: int, + n_pts_per_ray: int, + min_depth: float, + max_depth: float, +) -> "NDCMultinomialRaysampler": + """ + NDCGridRaysampler has been DEPRECATED. Use NDCMultinomialRaysampler instead. + Preserving NDCGridRaysampler for backward compatibility. + """ + + warnings.warn( + """NDCGridRaysampler is deprecated, + Use NDCMultinomialRaysampler instead. + NDCGridRaysampler will be removed in future releases.""", + PendingDeprecationWarning, + ) + + return NDCMultinomialRaysampler( + image_width=image_width, + image_height=image_height, + n_pts_per_ray=n_pts_per_ray, + min_depth=min_depth, + max_depth=max_depth, + ) + + +def _safe_multinomial(input: torch.Tensor, num_samples: int) -> torch.Tensor: + """ + Wrapper around torch.multinomial that attempts sampling without replacement + when possible, otherwise resorts to sampling with replacement. + + Args: + input: tensor of shape [B, n] containing non-negative values; + rows are interpreted as unnormalized event probabilities + in categorical distributions. + num_samples: number of samples to take. + + Returns: + LongTensor of shape [B, num_samples] containing + values from {0, ..., n - 1} where the elements [i, :] of row i make + (1) if there are num_samples or more non-zero values in input[i], + a random subset of the indices of those values, with + probabilities proportional to the values in input[i, :]. + + (2) if not, a random sample with replacement of the indices of + those values, with probabilities proportional to them. + This sample might not contain all the indices of the + non-zero values. + Behavior undetermined if there are no non-zero values in a whole row + or if there are negative values. + """ + try: + res = torch.multinomial(input, num_samples, replacement=False) + except RuntimeError: + # this is probably rare, so we don't mind sampling twice + res = torch.multinomial(input, num_samples, replacement=True) + no_repl = (input > 0.0).sum(dim=-1) >= num_samples + res[no_repl] = torch.multinomial(input[no_repl], num_samples, replacement=False) + return res + + # in some versions of Pytorch, zero probabilty samples can be drawn without an error + # due to this bug: https://github.com/pytorch/pytorch/issues/50034. Handle this case: + repl = (input > 0.0).sum(dim=-1) < num_samples + if repl.any(): + res[repl] = torch.multinomial(input[repl], num_samples, replacement=True) + + return res + + +def _xy_to_ray_bundle( + cameras: CamerasBase, + xy_grid: torch.Tensor, + min_depth: float, + max_depth: float, + n_pts_per_ray: int, + unit_directions: bool, + stratified_sampling: bool = False, +) -> RayBundle: + """ + Extends the `xy_grid` input of shape `(batch_size, ..., 2)` to rays. + This adds to each xy location in the grid a vector of `n_pts_per_ray` depths + uniformly spaced between `min_depth` and `max_depth`. + + The extended grid is then unprojected with `cameras` to yield + ray origins, directions and depths. + + Args: + cameras: cameras object representing a batch of cameras. + xy_grid: torch.tensor grid of image xy coords. + min_depth: The minimum depth of each ray-point. + max_depth: The maximum depth of each ray-point. + n_pts_per_ray: The number of points sampled along each ray. + unit_directions: whether to normalize direction vectors in ray bundle. + stratified_sampling: if True, performs stratified sampling in n_pts_per_ray + bins for each ray; otherwise takes n_pts_per_ray deterministic points + on each ray with uniform offsets. + """ + batch_size = xy_grid.shape[0] + spatial_size = xy_grid.shape[1:-1] + n_rays_per_image = spatial_size.numel() + + # ray z-coords + rays_zs = xy_grid.new_empty((0,)) + if n_pts_per_ray > 0: + depths = torch.linspace( + min_depth, + max_depth, + n_pts_per_ray, + dtype=xy_grid.dtype, + device=xy_grid.device, + ) + rays_zs = depths[None, None].expand(batch_size, n_rays_per_image, n_pts_per_ray) + + if stratified_sampling: + rays_zs = _jiggle_within_stratas(rays_zs) + + # make two sets of points at a constant depth=1 and 2 + to_unproject = torch.cat( + ( + xy_grid.view(batch_size, 1, n_rays_per_image, 2) + .expand(batch_size, 2, n_rays_per_image, 2) + .reshape(batch_size, n_rays_per_image * 2, 2), + torch.cat( + ( + xy_grid.new_ones(batch_size, n_rays_per_image, 1), + 2.0 * xy_grid.new_ones(batch_size, n_rays_per_image, 1), + ), + dim=1, + ), + ), + dim=-1, + ) + + # unproject the points + unprojected = cameras.unproject_points(to_unproject, from_ndc=True) + + # split the two planes back + rays_plane_1_world = unprojected[:, :n_rays_per_image] + rays_plane_2_world = unprojected[:, n_rays_per_image:] + + # directions are the differences between the two planes of points + rays_directions_world = rays_plane_2_world - rays_plane_1_world + + # origins are given by subtracting the ray directions from the first plane + rays_origins_world = rays_plane_1_world - rays_directions_world + + if unit_directions: + rays_directions_world = F.normalize(rays_directions_world, dim=-1) + + return RayBundle( + rays_origins_world.view(batch_size, *spatial_size, 3), + rays_directions_world.view(batch_size, *spatial_size, 3), + rays_zs.view(batch_size, *spatial_size, n_pts_per_ray), + xy_grid, + ) + + +def _jiggle_within_stratas(bin_centers: torch.Tensor) -> torch.Tensor: + """ + Performs sampling of 1 point per bin given the bin centers. + + More specifically, it replaces each point's value `z` + with a sample from a uniform random distribution on + `[z - delta_-, z + delta_+]`, where `delta_-` is half of the difference + between `z` and the previous point, and `delta_+` is half of the difference + between the next point and `z`. For the first and last items, the + corresponding boundary deltas are assumed zero. + + Args: + `bin_centers`: The input points of size (..., N); the result is broadcast + along all but the last dimension (the rows). Each row should be + sorted in ascending order. + + Returns: + a tensor of size (..., N) with the locations jiggled within stratas/bins. + """ + # Get intervals between bin centers. + mids = 0.5 * (bin_centers[..., 1:] + bin_centers[..., :-1]) + upper = torch.cat((mids, bin_centers[..., -1:]), dim=-1) + lower = torch.cat((bin_centers[..., :1], mids), dim=-1) + # Samples in those intervals. + jiggled = lower + (upper - lower) * torch.rand_like(lower) + return jiggled + + +def _sample_cameras_and_masks( + n_samples: int, cameras: CamerasBase, mask: Optional[torch.Tensor] = None +) -> Tuple[ + CamerasBase, + Optional[torch.Tensor], + torch.LongTensor, + torch.LongTensor, + torch.LongTensor, +]: + """ + Samples n_rays_total cameras and masks and returns them in a form + (camera_idx, count), where count represents number of times the same camera + has been sampled. + + Args: + n_samples: how many camera and mask pairs to sample + cameras: A batch of `batch_size` cameras from which the rays are emitted. + mask: Optional. Should be of size (batch_size, image_height, image_width). + Returns: + tuple of a form (sampled_cameras, sampled_masks, unique_sampled_camera_ids, + number_of_times_each_sampled_camera_has_been_sampled, + max_number_of_times_camera_has_been_sampled, + ) + """ + sampled_ids = torch.randint( + 0, + len(cameras), + size=(n_samples,), + dtype=torch.long, + ) + unique_ids, counts = torch.unique(sampled_ids, return_counts=True) + # pyre-ignore[7] + return ( + cameras[unique_ids], + mask[unique_ids] if mask is not None else None, + unique_ids, + counts, + torch.max(counts), + ) + + +# TODO: this function can be unified with ImplicitronRayBundle.get_padded_xys +def _pack_ray_bundle( + ray_bundle: RayBundle, camera_ids: torch.LongTensor, camera_counts: torch.LongTensor +) -> HeterogeneousRayBundle: + """ + Pack the raybundle from [n_cameras, max(rays_per_camera), ...] to + [total_num_rays, 1, ...] + + Args: + ray_bundle: A ray_bundle to pack + camera_ids: Unique ids of cameras that were sampled + camera_counts: how many of which camera to pack, each count coresponds to + one 'row' of the ray_bundle and says how many rays wll be taken + from it and packed. + Returns: + HeterogeneousRayBundle where batch_size=sum(camera_counts) and n_rays_per_image=1 + """ + # pyre-ignore[9] + camera_counts = camera_counts.to(ray_bundle.origins.device) + cumsum = torch.cumsum(camera_counts, dim=0, dtype=torch.long) + # pyre-ignore[9] + first_idxs: torch.LongTensor = torch.cat( + (camera_counts.new_zeros((1,), dtype=torch.long), cumsum[:-1]) + ) + num_inputs = int(camera_counts.sum()) + + return HeterogeneousRayBundle( + origins=padded_to_packed(ray_bundle.origins, first_idxs, num_inputs)[:, None], + directions=padded_to_packed(ray_bundle.directions, first_idxs, num_inputs)[ + :, None + ], + lengths=padded_to_packed(ray_bundle.lengths, first_idxs, num_inputs)[:, None], + xys=padded_to_packed(ray_bundle.xys, first_idxs, num_inputs)[:, None], + camera_ids=camera_ids, + camera_counts=camera_counts, + ) diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/implicit/renderer.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/implicit/renderer.py new file mode 100644 index 0000000000000000000000000000000000000000..963f7d07ef1c8f7ba0ed274e79c631f3f349962d --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/implicit/renderer.py @@ -0,0 +1,415 @@ +# 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. + +# pyre-unsafe + +from typing import Callable, Tuple, Union + +import torch + +from ...ops.utils import eyes +from ...structures import Volumes +from ...transforms import Transform3d +from ..cameras import CamerasBase +from .raysampling import HeterogeneousRayBundle, RayBundle +from .utils import _validate_ray_bundle_variables, ray_bundle_variables_to_ray_points + + +# The implicit renderer class should be initialized with a +# function for raysampling and a function for raymarching. + +# During the forward pass: +# 1) The raysampler: +# - samples rays from input cameras +# - transforms the rays to world coordinates +# 2) The volumetric_function (which is a callable argument of the forward pass) +# evaluates ray_densities and ray_features at the sampled ray-points. +# 3) The raymarcher takes ray_densities and ray_features and uses a raymarching +# algorithm to render each ray. + + +class ImplicitRenderer(torch.nn.Module): + """ + A class for rendering a batch of implicit surfaces. The class should + be initialized with a raysampler and raymarcher class which both have + to be a `Callable`. + + VOLUMETRIC_FUNCTION + + The `forward` function of the renderer accepts as input the rendering cameras + as well as the `volumetric_function` `Callable`, which defines a field of opacity + and feature vectors over the 3D domain of the scene. + + A standard `volumetric_function` has the following signature:: + + def volumetric_function( + ray_bundle: Union[RayBundle, HeterogeneousRayBundle], + **kwargs, + ) -> Tuple[torch.Tensor, torch.Tensor] + + With the following arguments: + `ray_bundle`: A RayBundle or HeterogeneousRayBundle object + containing the following variables: + + `origins`: A tensor of shape `(minibatch, ..., 3)` denoting + the origins of the rendering rays. + `directions`: A tensor of shape `(minibatch, ..., 3)` + containing the direction vectors of rendering rays. + `lengths`: A tensor of shape + `(minibatch, ..., num_points_per_ray)`containing the + lengths at which the ray points are sampled. + `xys`: A tensor of shape + `(minibatch, ..., 2)` containing the + xy locations of each ray's pixel in the screen space. + Calling `volumetric_function` then returns the following: + `rays_densities`: A tensor of shape + `(minibatch, ..., num_points_per_ray, opacity_dim)` containing + the an opacity vector for each ray point. + `rays_features`: A tensor of shape + `(minibatch, ..., num_points_per_ray, feature_dim)` containing + the an feature vector for each ray point. + + Note that, in order to increase flexibility of the API, we allow multiple + other arguments to enter the volumetric function via additional + (optional) keyword arguments `**kwargs`. + A typical use-case is passing a `CamerasBase` object as an additional + keyword argument, which can allow the volumetric function to adjust its + outputs based on the directions of the projection rays. + + Example: + A simple volumetric function of a 0-centered + RGB sphere with a unit diameter is defined as follows:: + + def volumetric_function( + ray_bundle: Union[RayBundle, HeterogeneousRayBundle], + **kwargs, + ) -> Tuple[torch.Tensor, torch.Tensor]: + + # first convert the ray origins, directions and lengths + # to 3D ray point locations in world coords + rays_points_world = ray_bundle_to_ray_points(ray_bundle) + + # set the densities as an inverse sigmoid of the + # ray point distance from the sphere centroid + rays_densities = torch.sigmoid( + -100.0 * rays_points_world.norm(dim=-1, keepdim=True) + ) + + # set the ray features to RGB colors proportional + # to the 3D location of the projection of ray points + # on the sphere surface + rays_features = torch.nn.functional.normalize( + rays_points_world, dim=-1 + ) * 0.5 + 0.5 + + return rays_densities, rays_features + + """ + + def __init__(self, raysampler: Callable, raymarcher: Callable) -> None: + """ + Args: + raysampler: A `Callable` that takes as input scene cameras + (an instance of `CamerasBase`) and returns a + RayBundle or HeterogeneousRayBundle, that + describes the rays emitted from the cameras. + raymarcher: A `Callable` that receives the response of the + `volumetric_function` (an input to `self.forward`) evaluated + along the sampled rays, and renders the rays with a + ray-marching algorithm. + """ + super().__init__() + + if not callable(raysampler): + raise ValueError('"raysampler" has to be a "Callable" object.') + if not callable(raymarcher): + raise ValueError('"raymarcher" has to be a "Callable" object.') + + self.raysampler = raysampler + self.raymarcher = raymarcher + + def forward( + self, cameras: CamerasBase, volumetric_function: Callable, **kwargs + ) -> Tuple[torch.Tensor, Union[RayBundle, HeterogeneousRayBundle]]: + """ + Render a batch of images using a volumetric function + represented as a callable (e.g. a Pytorch module). + + Args: + cameras: A batch of cameras that render the scene. A `self.raysampler` + takes the cameras as input and samples rays that pass through the + domain of the volumetric function. + volumetric_function: A `Callable` that accepts the parametrizations + of the rendering rays and returns the densities and features + at the respective 3D of the rendering rays. Please refer to + the main class documentation for details. + + Returns: + images: A tensor of shape `(minibatch, ..., feature_dim + opacity_dim)` + containing the result of the rendering. + ray_bundle: A `Union[RayBundle, HeterogeneousRayBundle]` containing + the parametrizations of the sampled rendering rays. + """ + + if not callable(volumetric_function): + raise ValueError('"volumetric_function" has to be a "Callable" object.') + + # first call the ray sampler that returns the RayBundle or HeterogeneousRayBundle + # parametrizing the rendering rays. + ray_bundle = self.raysampler( + cameras=cameras, volumetric_function=volumetric_function, **kwargs + ) + # ray_bundle.origins - minibatch x ... x 3 + # ray_bundle.directions - minibatch x ... x 3 + # ray_bundle.lengths - minibatch x ... x n_pts_per_ray + # ray_bundle.xys - minibatch x ... x 2 + + # given sampled rays, call the volumetric function that + # evaluates the densities and features at the locations of the + # ray points + # pyre-fixme[23]: Unable to unpack `object` into 2 values. + rays_densities, rays_features = volumetric_function( + ray_bundle=ray_bundle, cameras=cameras, **kwargs + ) + # ray_densities - minibatch x ... x n_pts_per_ray x density_dim + # ray_features - minibatch x ... x n_pts_per_ray x feature_dim + + # finally, march along the sampled rays to obtain the renders + images = self.raymarcher( + rays_densities=rays_densities, + rays_features=rays_features, + ray_bundle=ray_bundle, + **kwargs, + ) + # images - minibatch x ... x (feature_dim + opacity_dim) + + return images, ray_bundle + + +# The volume renderer class should be initialized with a +# function for raysampling and a function for raymarching. + +# During the forward pass: +# 1) The raysampler: +# - samples rays from input cameras +# - transforms the rays to world coordinates +# 2) The scene volumes (which are an argument of the forward function) +# are then sampled at the locations of the ray-points to generate +# ray_densities and ray_features. +# 3) The raymarcher takes ray_densities and ray_features and uses a raymarching +# algorithm to render each ray. + + +class VolumeRenderer(torch.nn.Module): + """ + A class for rendering a batch of Volumes. The class should + be initialized with a raysampler and a raymarcher class which both have + to be a `Callable`. + """ + + def __init__( + self, raysampler: Callable, raymarcher: Callable, sample_mode: str = "bilinear" + ) -> None: + """ + Args: + raysampler: A `Callable` that takes as input scene cameras + (an instance of `CamerasBase`) and returns a + `Union[RayBundle, HeterogeneousRayBundle],` that + describes the rays emitted from the cameras. + raymarcher: A `Callable` that receives the `volumes` + (an instance of `Volumes` input to `self.forward`) + sampled at the ray-points, and renders the rays with a + ray-marching algorithm. + sample_mode: Defines the algorithm used to sample the volumetric + voxel grid. Can be either "bilinear" or "nearest". + """ + super().__init__() + + self.renderer = ImplicitRenderer(raysampler, raymarcher) + self._sample_mode = sample_mode + + def forward( + self, cameras: CamerasBase, volumes: Volumes, **kwargs + ) -> Tuple[torch.Tensor, Union[RayBundle, HeterogeneousRayBundle]]: + """ + Render a batch of images using raymarching over rays cast through + input `Volumes`. + + Args: + cameras: A batch of cameras that render the scene. A `self.raysampler` + takes the cameras as input and samples rays that pass through the + domain of the volumetric function. + volumes: An instance of the `Volumes` class representing a + batch of volumes that are being rendered. + + Returns: + images: A tensor of shape `(minibatch, ..., (feature_dim + opacity_dim)` + containing the result of the rendering. + ray_bundle: A `RayBundle` or `HeterogeneousRayBundle` containing the + parametrizations of the sampled rendering rays. + """ + volumetric_function = VolumeSampler(volumes, sample_mode=self._sample_mode) + return self.renderer( + cameras=cameras, volumetric_function=volumetric_function, **kwargs + ) + + +class VolumeSampler(torch.nn.Module): + """ + A module to sample a batch of volumes `Volumes` + at 3D points sampled along projection rays. + """ + + def __init__( + self, + volumes: Volumes, + sample_mode: str = "bilinear", + padding_mode: str = "zeros", + ) -> None: + """ + Args: + volumes: An instance of the `Volumes` class representing a + batch of volumes that are being rendered. + sample_mode: Defines the algorithm used to sample the volumetric + voxel grid. Can be either "bilinear" or "nearest". + padding_mode: How to handle values outside of the volume. + One of: zeros, border, reflection + See torch.nn.functional.grid_sample for more information. + """ + super().__init__() + if not isinstance(volumes, Volumes): + raise ValueError("'volumes' have to be an instance of the 'Volumes' class.") + self._volumes = volumes + self._sample_mode = sample_mode + self._padding_mode = padding_mode + + def _get_ray_directions_transform(self): + """ + Compose the ray-directions transform by removing the translation component + from the volume global-to-local coords transform. + """ + world2local = self._volumes.get_world_to_local_coords_transform().get_matrix() + directions_transform_matrix = eyes( + 4, + N=world2local.shape[0], + device=world2local.device, + dtype=world2local.dtype, + ) + directions_transform_matrix[:, :3, :3] = world2local[:, :3, :3] + directions_transform = Transform3d(matrix=directions_transform_matrix) + return directions_transform + + def forward( + self, ray_bundle: Union[RayBundle, HeterogeneousRayBundle], **kwargs + ) -> Tuple[torch.Tensor, torch.Tensor]: + """ + Given an input ray parametrization, the forward function samples + `self._volumes` at the respective 3D ray-points. + Can also accept ImplicitronRayBundle as argument for ray_bundle. + + Args: + ray_bundle: A RayBundle or HeterogeneousRayBundle object with the following fields: + rays_origins_world: A tensor of shape `(minibatch, ..., 3)` denoting the + origins of the sampling rays in world coords. + rays_directions_world: A tensor of shape `(minibatch, ..., 3)` + containing the direction vectors of sampling rays in world coords. + rays_lengths: A tensor of shape `(minibatch, ..., num_points_per_ray)` + containing the lengths at which the rays are sampled. + + Returns: + rays_densities: A tensor of shape + `(minibatch, ..., num_points_per_ray, opacity_dim)` containing the + density vectors sampled from the volume at the locations of + the ray points. + rays_features: A tensor of shape + `(minibatch, ..., num_points_per_ray, feature_dim)` containing the + feature vectors sampled from the volume at the locations of + the ray points. + """ + + # take out the interesting parts of ray_bundle + rays_origins_world = ray_bundle.origins + rays_directions_world = ray_bundle.directions + rays_lengths = ray_bundle.lengths + + # validate the inputs + _validate_ray_bundle_variables( + rays_origins_world, rays_directions_world, rays_lengths + ) + if self._volumes.densities().shape[0] != rays_origins_world.shape[0]: + raise ValueError("Input volumes have to have the same batch size as rays.") + + ######################################################### + # 1) convert the origins/directions to the local coords # + ######################################################### + + # origins are mapped with the world_to_local transform of the volumes + rays_origins_local = self._volumes.world_to_local_coords(rays_origins_world) + + # obtain the Transform3d object that transforms ray directions to local coords + directions_transform = self._get_ray_directions_transform() + + # transform the directions to the local coords + rays_directions_local = directions_transform.transform_points( + rays_directions_world.view(rays_lengths.shape[0], -1, 3) + ).view(rays_directions_world.shape) + + ############################ + # 2) obtain the ray points # + ############################ + + # this op produces a fairly big tensor (minibatch, ..., n_samples_per_ray, 3) + rays_points_local = ray_bundle_variables_to_ray_points( + rays_origins_local, rays_directions_local, rays_lengths + ) + + ######################## + # 3) sample the volume # + ######################## + + # generate the tensor for sampling + volumes_densities = self._volumes.densities() + dim_density = volumes_densities.shape[1] + volumes_features = self._volumes.features() + + # reshape to a size which grid_sample likes + rays_points_local_flat = rays_points_local.view( + rays_points_local.shape[0], -1, 1, 1, 3 + ) + + # run the grid sampler on the volumes densities + rays_densities = torch.nn.functional.grid_sample( + volumes_densities, + rays_points_local_flat, + mode=self._sample_mode, + padding_mode=self._padding_mode, + align_corners=self._volumes.get_align_corners(), + ) + + # permute the dimensions & reshape densities after sampling + rays_densities = rays_densities.permute(0, 2, 3, 4, 1).view( + *rays_points_local.shape[:-1], volumes_densities.shape[1] + ) + + # if features exist, run grid sampler again on the features densities + if volumes_features is None: + dim_feature = 0 + _, rays_features = rays_densities.split([dim_density, dim_feature], dim=-1) + else: + rays_features = torch.nn.functional.grid_sample( + volumes_features, + rays_points_local_flat, + mode=self._sample_mode, + padding_mode=self._padding_mode, + align_corners=self._volumes.get_align_corners(), + ) + + # permute the dimensions & reshape features after sampling + rays_features = rays_features.permute(0, 2, 3, 4, 1).view( + *rays_points_local.shape[:-1], volumes_features.shape[1] + ) + + return rays_densities, rays_features diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/implicit/sample_pdf.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/implicit/sample_pdf.py new file mode 100644 index 0000000000000000000000000000000000000000..7009867d7aa21311fd28986b98108346653fac49 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/implicit/sample_pdf.py @@ -0,0 +1,148 @@ +# 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. + +# pyre-unsafe + + +import torch +from pytorch3d import _C + + +def sample_pdf( + bins: torch.Tensor, + weights: torch.Tensor, + n_samples: int, + det: bool = False, + eps: float = 1e-5, +) -> torch.Tensor: + """ + Samples probability density functions defined by bin edges `bins` and + the non-negative per-bin probabilities `weights`. + + Args: + bins: Tensor of shape `(..., n_bins+1)` denoting the edges of the sampling bins. + weights: Tensor of shape `(..., n_bins)` containing non-negative numbers + representing the probability of sampling the corresponding bin. + n_samples: The number of samples to draw from each set of bins. + det: If `False`, the sampling is random. `True` yields deterministic + uniformly-spaced sampling from the inverse cumulative density function. + eps: A constant preventing division by zero in case empty bins are present. + + Returns: + samples: Tensor of shape `(..., n_samples)` containing `n_samples` samples + drawn from each probability distribution. + + Refs: + [1] https://github.com/bmild/nerf/blob/55d8b00244d7b5178f4d003526ab6667683c9da9/run_nerf_helpers.py#L183 # noqa E501 + """ + if torch.is_grad_enabled() and (bins.requires_grad or weights.requires_grad): + raise NotImplementedError("sample_pdf differentiability.") + if weights.min() <= -eps: + raise ValueError("Negative weights provided.") + batch_shape = bins.shape[:-1] + n_bins = weights.shape[-1] + if n_bins + 1 != bins.shape[-1] or weights.shape[:-1] != batch_shape: + shapes = f"{bins.shape}{weights.shape}" + raise ValueError("Inconsistent shapes of bins and weights: " + shapes) + output_shape = batch_shape + (n_samples,) + + if det: + u = torch.linspace(0.0, 1.0, n_samples, device=bins.device, dtype=torch.float32) + output = u.expand(output_shape).contiguous() + else: + output = torch.rand(output_shape, dtype=torch.float32, device=bins.device) + + # pyre-fixme[16]: Module `pytorch3d` has no attribute `_C`. + _C.sample_pdf( + bins.reshape(-1, n_bins + 1), + weights.reshape(-1, n_bins), + output.reshape(-1, n_samples), + eps, + ) + + return output + + +def sample_pdf_python( + bins: torch.Tensor, + weights: torch.Tensor, + N_samples: int, + det: bool = False, + eps: float = 1e-5, +) -> torch.Tensor: + """ + This is a pure python implementation of the `sample_pdf` function. + It may be faster than sample_pdf when the number of bins is very large, + because it behaves as O(batchsize * [n_bins + log(n_bins) * n_samples] ) + whereas sample_pdf behaves as O(batchsize * n_bins * n_samples). + For 64 bins sample_pdf is much faster. + + Samples probability density functions defined by bin edges `bins` and + the non-negative per-bin probabilities `weights`. + + Note: This is a direct conversion of the TensorFlow function from the original + release [1] to PyTorch. It requires PyTorch 1.6 or greater due to the use of + torch.searchsorted. + + Args: + bins: Tensor of shape `(..., n_bins+1)` denoting the edges of the sampling bins. + weights: Tensor of shape `(..., n_bins)` containing non-negative numbers + representing the probability of sampling the corresponding bin. + N_samples: The number of samples to draw from each set of bins. + det: If `False`, the sampling is random. `True` yields deterministic + uniformly-spaced sampling from the inverse cumulative density function. + eps: A constant preventing division by zero in case empty bins are present. + + Returns: + samples: Tensor of shape `(..., N_samples)` containing `N_samples` samples + drawn from each probability distribution. + + Refs: + [1] https://github.com/bmild/nerf/blob/55d8b00244d7b5178f4d003526ab6667683c9da9/run_nerf_helpers.py#L183 # noqa E501 + """ + + # Get pdf + weights = weights + eps # prevent nans + if weights.min() <= 0: + raise ValueError("Negative weights provided.") + pdf = weights / weights.sum(dim=-1, keepdim=True) + cdf = torch.cumsum(pdf, -1) + cdf = torch.cat([torch.zeros_like(cdf[..., :1]), cdf], -1) + + # Take uniform samples u of shape (..., N_samples) + if det: + u = torch.linspace(0.0, 1.0, N_samples, device=cdf.device, dtype=cdf.dtype) + u = u.expand(list(cdf.shape[:-1]) + [N_samples]).contiguous() + else: + u = torch.rand( + list(cdf.shape[:-1]) + [N_samples], device=cdf.device, dtype=cdf.dtype + ) + + # Invert CDF + inds = torch.searchsorted(cdf, u, right=True) + # inds has shape (..., N_samples) identifying the bin of each sample. + below = (inds - 1).clamp(0) + above = inds.clamp(max=cdf.shape[-1] - 1) + # Below and above are of shape (..., N_samples), identifying the bin + # edges surrounding each sample. + + inds_g = torch.stack([below, above], -1).view( + *below.shape[:-1], below.shape[-1] * 2 + ) + cdf_g = torch.gather(cdf, -1, inds_g).view(*below.shape, 2) + bins_g = torch.gather(bins, -1, inds_g).view(*below.shape, 2) + # cdf_g and bins_g are of shape (..., N_samples, 2) and identify + # the cdf and the index of the two bin edges surrounding each sample. + + denom = cdf_g[..., 1] - cdf_g[..., 0] + denom = torch.where(denom < eps, torch.ones_like(denom), denom) + t = (u - cdf_g[..., 0]) / denom + # t is of shape (..., N_samples) and identifies how far through + # each sample is in its bin. + + samples = bins_g[..., 0] + t * (bins_g[..., 1] - bins_g[..., 0]) + + return samples diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/implicit/utils.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/implicit/utils.py new file mode 100644 index 0000000000000000000000000000000000000000..bd6bcc31f325fa1521a2e8b5c4e4e0dcd866e2c2 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/implicit/utils.py @@ -0,0 +1,173 @@ +# 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. + +# pyre-unsafe + +import dataclasses +from typing import NamedTuple, Optional, Union + +import torch + + +class RayBundle(NamedTuple): + """ + Parametrizes points along projection rays by storing: + + origins: A tensor of shape `(..., 3)` denoting the + origins of the sampling rays in world coords. + directions: A tensor of shape `(..., 3)` containing the direction + vectors of sampling rays in world coords. They don't have to be normalized; + they define unit vectors in the respective 1D coordinate systems; see + documentation for :func:`ray_bundle_to_ray_points` for the conversion formula. + lengths: A tensor of shape `(..., num_points_per_ray)` + containing the lengths at which the rays are sampled. + xys: A tensor of shape `(..., 2)`, the xy-locations (`xys`) of the ray pixels + """ + + origins: torch.Tensor + directions: torch.Tensor + lengths: torch.Tensor + xys: torch.Tensor + + +@dataclasses.dataclass +class HeterogeneousRayBundle: + """ + Members: + origins: A tensor of shape `(..., 3)` denoting the + origins of the sampling rays in world coords. + directions: A tensor of shape `(..., 3)` containing the direction + vectors of sampling rays in world coords. They don't have to be normalized; + they define unit vectors in the respective 1D coordinate systems; see + documentation for :func:`ray_bundle_to_ray_points` for the conversion formula. + lengths: A tensor of shape `(..., num_points_per_ray)` + containing the lengths at which the rays are sampled. + xys: A tensor of shape `(..., 2)`, the xy-locations (`xys`) of the ray pixels + camera_ids: A tensor of shape (N, ) which indicates which camera + was used to sample the rays. `N` is the number of unique sampled cameras. + camera_counts: A tensor of shape (N, ) which how many times the + coresponding camera in `camera_ids` was sampled. + `sum(camera_counts)==total_number_of_rays` + + If we sample cameras of ids [0, 3, 5, 3, 1, 0, 0] that would be + stored as camera_ids=[1, 3, 5, 0] and camera_counts=[1, 2, 1, 3]. `camera_ids` is a + set like object with no particular ordering of elements. ith element of + `camera_ids` coresponds to the ith element of `camera_counts`. + """ + + origins: torch.Tensor + directions: torch.Tensor + lengths: torch.Tensor + xys: torch.Tensor + camera_ids: Optional[torch.LongTensor] = None + camera_counts: Optional[torch.LongTensor] = None + + +def ray_bundle_to_ray_points( + ray_bundle: Union[RayBundle, HeterogeneousRayBundle] +) -> torch.Tensor: + """ + Converts rays parametrized with a `ray_bundle` (an instance of the `RayBundle` + named tuple or HeterogeneousRayBundle dataclass) to 3D points by + extending each ray according to the corresponding length. + + E.g. for 2 dimensional tensors `ray_bundle.origins`, `ray_bundle.directions` + and `ray_bundle.lengths`, the ray point at position `[i, j]` is:: + + ray_bundle.points[i, j, :] = ( + ray_bundle.origins[i, :] + + ray_bundle.directions[i, :] * ray_bundle.lengths[i, j] + ) + + Note that both the directions and magnitudes of the vectors in + `ray_bundle.directions` matter. + + Args: + ray_bundle: A `RayBundle` or `HeterogeneousRayBundle` object with fields: + origins: A tensor of shape `(..., 3)` + directions: A tensor of shape `(..., 3)` + lengths: A tensor of shape `(..., num_points_per_ray)` + + Returns: + rays_points: A tensor of shape `(..., num_points_per_ray, 3)` + containing the points sampled along each ray. + """ + return ray_bundle_variables_to_ray_points( + ray_bundle.origins, ray_bundle.directions, ray_bundle.lengths + ) + + +def ray_bundle_variables_to_ray_points( + rays_origins: torch.Tensor, + rays_directions: torch.Tensor, + rays_lengths: torch.Tensor, +) -> torch.Tensor: + """ + Converts rays parametrized with origins and directions + to 3D points by extending each ray according to the corresponding + ray length: + + E.g. for 2 dimensional input tensors `rays_origins`, `rays_directions` + and `rays_lengths`, the ray point at position `[i, j]` is:: + + rays_points[i, j, :] = ( + rays_origins[i, :] + + rays_directions[i, :] * rays_lengths[i, j] + ) + + Note that both the directions and magnitudes of the vectors in + `rays_directions` matter. + + Args: + rays_origins: A tensor of shape `(..., 3)` + rays_directions: A tensor of shape `(..., 3)` + rays_lengths: A tensor of shape `(..., num_points_per_ray)` + + Returns: + rays_points: A tensor of shape `(..., num_points_per_ray, 3)` + containing the points sampled along each ray. + """ + rays_points = ( + rays_origins[..., None, :] + + rays_lengths[..., :, None] * rays_directions[..., None, :] + ) + return rays_points + + +def _validate_ray_bundle_variables( + rays_origins: torch.Tensor, + rays_directions: torch.Tensor, + rays_lengths: torch.Tensor, +) -> None: + """ + Validate the shapes of RayBundle variables + `rays_origins`, `rays_directions`, and `rays_lengths`. + """ + ndim = rays_origins.ndim + if any(r.ndim != ndim for r in (rays_directions, rays_lengths)): + raise ValueError( + "rays_origins, rays_directions and rays_lengths" + + " have to have the same number of dimensions." + ) + + if ndim <= 2: + raise ValueError( + "rays_origins, rays_directions and rays_lengths" + + " have to have at least 3 dimensions." + ) + + spatial_size = rays_origins.shape[:-1] + if any(spatial_size != r.shape[:-1] for r in (rays_directions, rays_lengths)): + raise ValueError( + "The shapes of rays_origins, rays_directions and rays_lengths" + + " may differ only in the last dimension." + ) + + if any(r.shape[-1] != 3 for r in (rays_origins, rays_directions)): + raise ValueError( + "The size of the last dimension of rays_origins/rays_directions" + + "has to be 3." + ) diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/lighting.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/lighting.py new file mode 100644 index 0000000000000000000000000000000000000000..4394c3e59020039692a617db49ac74de465414fa --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/lighting.py @@ -0,0 +1,341 @@ +# 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. + +# pyre-unsafe + + +import torch +import torch.nn.functional as F + +from ..common.datatypes import Device +from .utils import convert_to_tensors_and_broadcast, TensorProperties + + +def diffuse(normals, color, direction) -> torch.Tensor: + """ + Calculate the diffuse component of light reflection using Lambert's + cosine law. + + Args: + normals: (N, ..., 3) xyz normal vectors. Normals and points are + expected to have the same shape. + color: (1, 3) or (N, 3) RGB color of the diffuse component of the light. + direction: (x,y,z) direction of the light + + Returns: + colors: (N, ..., 3), same shape as the input points. + + The normals and light direction should be in the same coordinate frame + i.e. if the points have been transformed from world -> view space then + the normals and direction should also be in view space. + + NOTE: to use with the packed vertices (i.e. no batch dimension) reformat the + inputs in the following way. + + .. code-block:: python + + Args: + normals: (P, 3) + color: (N, 3)[batch_idx, :] -> (P, 3) + direction: (N, 3)[batch_idx, :] -> (P, 3) + + Returns: + colors: (P, 3) + + where batch_idx is of shape (P). For meshes, batch_idx can be: + meshes.verts_packed_to_mesh_idx() or meshes.faces_packed_to_mesh_idx() + depending on whether points refers to the vertex coordinates or + average/interpolated face coordinates. + """ + # TODO: handle multiple directional lights per batch element. + # TODO: handle attenuation. + + # Ensure color and location have same batch dimension as normals + normals, color, direction = convert_to_tensors_and_broadcast( + normals, color, direction, device=normals.device + ) + + # Reshape direction and color so they have all the arbitrary intermediate + # dimensions as normals. Assume first dim = batch dim and last dim = 3. + points_dims = normals.shape[1:-1] + expand_dims = (-1,) + (1,) * len(points_dims) + (3,) + if direction.shape != normals.shape: + direction = direction.view(expand_dims) + if color.shape != normals.shape: + color = color.view(expand_dims) + + # Renormalize the normals in case they have been interpolated. + # We tried to replace the following with F.cosine_similarity, but it wasn't faster. + normals = F.normalize(normals, p=2, dim=-1, eps=1e-6) + direction = F.normalize(direction, p=2, dim=-1, eps=1e-6) + angle = F.relu(torch.sum(normals * direction, dim=-1)) + return color * angle[..., None] + + +def specular( + points, normals, direction, color, camera_position, shininess +) -> torch.Tensor: + """ + Calculate the specular component of light reflection. + + Args: + points: (N, ..., 3) xyz coordinates of the points. + normals: (N, ..., 3) xyz normal vectors for each point. + color: (N, 3) RGB color of the specular component of the light. + direction: (N, 3) vector direction of the light. + camera_position: (N, 3) The xyz position of the camera. + shininess: (N) The specular exponent of the material. + + Returns: + colors: (N, ..., 3), same shape as the input points. + + The points, normals, camera_position, and direction should be in the same + coordinate frame i.e. if the points have been transformed from + world -> view space then the normals, camera_position, and light direction + should also be in view space. + + To use with a batch of packed points reindex in the following way. + .. code-block:: python:: + + Args: + points: (P, 3) + normals: (P, 3) + color: (N, 3)[batch_idx] -> (P, 3) + direction: (N, 3)[batch_idx] -> (P, 3) + camera_position: (N, 3)[batch_idx] -> (P, 3) + shininess: (N)[batch_idx] -> (P) + Returns: + colors: (P, 3) + + where batch_idx is of shape (P). For meshes batch_idx can be: + meshes.verts_packed_to_mesh_idx() or meshes.faces_packed_to_mesh_idx(). + """ + # TODO: handle multiple directional lights + # TODO: attenuate based on inverse squared distance to the light source + + if points.shape != normals.shape: + msg = "Expected points and normals to have the same shape: got %r, %r" + raise ValueError(msg % (points.shape, normals.shape)) + + # Ensure all inputs have same batch dimension as points + matched_tensors = convert_to_tensors_and_broadcast( + points, color, direction, camera_position, shininess, device=points.device + ) + _, color, direction, camera_position, shininess = matched_tensors + + # Reshape direction and color so they have all the arbitrary intermediate + # dimensions as points. Assume first dim = batch dim and last dim = 3. + points_dims = points.shape[1:-1] + expand_dims = (-1,) + (1,) * len(points_dims) + if direction.shape != normals.shape: + direction = direction.view(expand_dims + (3,)) + if color.shape != normals.shape: + color = color.view(expand_dims + (3,)) + if camera_position.shape != normals.shape: + camera_position = camera_position.view(expand_dims + (3,)) + if shininess.shape != normals.shape: + shininess = shininess.view(expand_dims) + + # Renormalize the normals in case they have been interpolated. + # We tried a version that uses F.cosine_similarity instead of renormalizing, + # but it was slower. + normals = F.normalize(normals, p=2, dim=-1, eps=1e-6) + direction = F.normalize(direction, p=2, dim=-1, eps=1e-6) + cos_angle = torch.sum(normals * direction, dim=-1) + # No specular highlights if angle is less than 0. + mask = (cos_angle > 0).to(torch.float32) + + # Calculate the specular reflection. + view_direction = camera_position - points + view_direction = F.normalize(view_direction, p=2, dim=-1, eps=1e-6) + reflect_direction = -direction + 2 * (cos_angle[..., None] * normals) + + # Cosine of the angle between the reflected light ray and the viewer + alpha = F.relu(torch.sum(view_direction * reflect_direction, dim=-1)) * mask + return color * torch.pow(alpha, shininess)[..., None] + + +class DirectionalLights(TensorProperties): + def __init__( + self, + ambient_color=((0.5, 0.5, 0.5),), + diffuse_color=((0.3, 0.3, 0.3),), + specular_color=((0.2, 0.2, 0.2),), + direction=((0, 1, 0),), + device: Device = "cpu", + ) -> None: + """ + Args: + ambient_color: RGB color of the ambient component. + diffuse_color: RGB color of the diffuse component. + specular_color: RGB color of the specular component. + direction: (x, y, z) direction vector of the light. + device: Device (as str or torch.device) on which the tensors should be located + + The inputs can each be + - 3 element tuple/list or list of lists + - torch tensor of shape (1, 3) + - torch tensor of shape (N, 3) + The inputs are broadcast against each other so they all have batch + dimension N. + """ + super().__init__( + device=device, + ambient_color=ambient_color, + diffuse_color=diffuse_color, + specular_color=specular_color, + direction=direction, + ) + _validate_light_properties(self) + if self.direction.shape[-1] != 3: + msg = "Expected direction to have shape (N, 3); got %r" + raise ValueError(msg % repr(self.direction.shape)) + + def clone(self): + other = self.__class__(device=self.device) + return super().clone(other) + + def diffuse(self, normals, points=None) -> torch.Tensor: + # NOTE: Points is not used but is kept in the args so that the API is + # the same for directional and point lights. The call sites should not + # need to know the light type. + return diffuse( + normals=normals, + color=self.diffuse_color, + direction=self.direction, + ) + + def specular(self, normals, points, camera_position, shininess) -> torch.Tensor: + return specular( + points=points, + normals=normals, + color=self.specular_color, + direction=self.direction, + camera_position=camera_position, + shininess=shininess, + ) + + +class PointLights(TensorProperties): + def __init__( + self, + ambient_color=((0.5, 0.5, 0.5),), + diffuse_color=((0.3, 0.3, 0.3),), + specular_color=((0.2, 0.2, 0.2),), + location=((0, 1, 0),), + device: Device = "cpu", + ) -> None: + """ + Args: + ambient_color: RGB color of the ambient component + diffuse_color: RGB color of the diffuse component + specular_color: RGB color of the specular component + location: xyz position of the light. + device: Device (as str or torch.device) on which the tensors should be located + + The inputs can each be + - 3 element tuple/list or list of lists + - torch tensor of shape (1, 3) + - torch tensor of shape (N, 3) + The inputs are broadcast against each other so they all have batch + dimension N. + """ + super().__init__( + device=device, + ambient_color=ambient_color, + diffuse_color=diffuse_color, + specular_color=specular_color, + location=location, + ) + _validate_light_properties(self) + if self.location.shape[-1] != 3: + msg = "Expected location to have shape (N, 3); got %r" + raise ValueError(msg % repr(self.location.shape)) + + def clone(self): + other = self.__class__(device=self.device) + return super().clone(other) + + def reshape_location(self, points) -> torch.Tensor: + """ + Reshape the location tensor to have dimensions + compatible with the points which can either be of + shape (P, 3) or (N, H, W, K, 3). + """ + if self.location.ndim == points.ndim: + return self.location + return self.location[:, None, None, None, :] + + def diffuse(self, normals, points) -> torch.Tensor: + location = self.reshape_location(points) + direction = location - points + return diffuse(normals=normals, color=self.diffuse_color, direction=direction) + + def specular(self, normals, points, camera_position, shininess) -> torch.Tensor: + location = self.reshape_location(points) + direction = location - points + return specular( + points=points, + normals=normals, + color=self.specular_color, + direction=direction, + camera_position=camera_position, + shininess=shininess, + ) + + +class AmbientLights(TensorProperties): + """ + A light object representing the same color of light everywhere. + By default, this is white, which effectively means lighting is + not used in rendering. + + Unlike other lights this supports an arbitrary number of channels, not just 3 for RGB. + The ambient_color input determines the number of channels. + """ + + def __init__(self, *, ambient_color=None, device: Device = "cpu") -> None: + """ + If ambient_color is provided, it should be a sequence of + triples of floats. + + Args: + ambient_color: RGB color + device: Device (as str or torch.device) on which the tensors should be located + + The ambient_color if provided, should be + - tuple/list of C-element tuples of floats + - torch tensor of shape (1, C) + - torch tensor of shape (N, C) + where C is the number of channels and N is batch size. + For RGB, C is 3. + """ + if ambient_color is None: + ambient_color = ((1.0, 1.0, 1.0),) + super().__init__(ambient_color=ambient_color, device=device) + + def clone(self): + other = self.__class__(device=self.device) + return super().clone(other) + + def diffuse(self, normals, points) -> torch.Tensor: + return self._zeros_channels(points) + + def specular(self, normals, points, camera_position, shininess) -> torch.Tensor: + return self._zeros_channels(points) + + def _zeros_channels(self, points: torch.Tensor) -> torch.Tensor: + ch = self.ambient_color.shape[-1] + return torch.zeros(*points.shape[:-1], ch, device=points.device) + + +def _validate_light_properties(obj) -> None: + props = ("ambient_color", "diffuse_color", "specular_color") + for n in props: + t = getattr(obj, n) + if t.shape[-1] != 3: + msg = "Expected %s to have shape (N, 3); got %r" + raise ValueError(msg % (n, t.shape)) diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/materials.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/materials.py new file mode 100644 index 0000000000000000000000000000000000000000..be85b8ab1442ba0766bd4c2b2c610b8c478fe3c2 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/materials.py @@ -0,0 +1,67 @@ +# 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. + +# pyre-unsafe + + +import torch + +from ..common.datatypes import Device +from .utils import TensorProperties + + +class Materials(TensorProperties): + """ + A class for storing a batch of material properties. Currently only one + material per batch element is supported. + """ + + def __init__( + self, + ambient_color=((1, 1, 1),), + diffuse_color=((1, 1, 1),), + specular_color=((1, 1, 1),), + shininess=64, + device: Device = "cpu", + ) -> None: + """ + Args: + ambient_color: ambient reflectivity of the material + diffuse_color: diffuse reflectivity of the material + specular_color: specular reflectivity of the material + shininess: The specular exponent for the material. This defines + the focus of the specular highlight with a high value + resulting in a concentrated highlight. Shininess values + can range from 0-1000. + device: Device (as str or torch.device) on which the tensors should be located + + ambient_color, diffuse_color and specular_color can be of shape + (1, C) or (N, C) where C is typically 3 (for RGB). shininess can be of shape (1,) + or (N,). + + The colors and shininess are broadcast against each other so need to + have either the same batch dimension or batch dimension = 1. + """ + super().__init__( + device=device, + diffuse_color=diffuse_color, + ambient_color=ambient_color, + specular_color=specular_color, + shininess=shininess, + ) + C = self.ambient_color.shape[-1] + for n in ["ambient_color", "diffuse_color", "specular_color"]: + t = getattr(self, n) + if t.shape[-1] != C: + msg = "Expected %s to have shape (N, %d); got %r" + raise ValueError(msg % (n, C, t.shape)) + if self.shininess.shape != torch.Size([self._N]): + msg = "shininess should have shape (N); got %r" + raise ValueError(msg % repr(self.shininess.shape)) + + def clone(self): + other = Materials(device=self.device) + return super().clone(other) diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/mesh/__init__.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/mesh/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..bf8ced062dafb53a046e673e7e1d1c4bd5a85061 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/mesh/__init__.py @@ -0,0 +1,40 @@ +# 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. + +# pyre-unsafe + +from .clip import ( + clip_faces, + ClipFrustum, + ClippedFaces, + convert_clipped_rasterization_to_original_faces, +) + +from .rasterize_meshes import rasterize_meshes +from .rasterizer import MeshRasterizer, RasterizationSettings +from .renderer import MeshRenderer, MeshRendererWithFragments +from .shader import ( # DEPRECATED + BlendParams, + HardFlatShader, + HardGouraudShader, + HardPhongShader, + SoftGouraudShader, + SoftPhongShader, + SoftSilhouetteShader, + SplatterPhongShader, + TexturedSoftPhongShader, +) +from .shading import gouraud_shading, phong_shading +from .textures import ( # DEPRECATED + Textures, + TexturesAtlas, + TexturesBase, + TexturesUV, + TexturesVertex, +) + + +__all__ = [k for k in globals().keys() if not k.startswith("_")] diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/mesh/clip.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/mesh/clip.py new file mode 100644 index 0000000000000000000000000000000000000000..b8e8ae9721f905b19e142ac9a035fa3321ce14ab --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/mesh/clip.py @@ -0,0 +1,726 @@ +# 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. + +# pyre-unsafe + +from typing import Any, List, Optional, Tuple + +import torch + + +""" +Mesh clipping is done before rasterization and is implemented using 4 cases +(these will be referred to throughout the functions below) + +Case 1: the triangle is completely in front of the clipping plane (it is left + unchanged) +Case 2: the triangle is completely behind the clipping plane (it is culled) +Case 3: the triangle has exactly two vertices behind the clipping plane (it is + clipped into a smaller triangle) +Case 4: the triangle has exactly one vertex behind the clipping plane (it is clipped + into a smaller quadrilateral and divided into two triangular faces) + +After rasterization, the Fragments from the clipped/modified triangles +are mapped back to the triangles in the original mesh. The indices, +barycentric coordinates and distances are all relative to original mesh triangles. + +NOTE: It is assumed that all z-coordinates are in world coordinates (not NDC +coordinates), while x and y coordinates may be in NDC/screen coordinates +(i.e after applying a projective transform e.g. cameras.transform_points(points)). +""" + + +class ClippedFaces: + """ + Helper class to store the data for the clipped version of a Meshes object + (face_verts, mesh_to_face_first_idx, num_faces_per_mesh) along with + conversion information (faces_clipped_to_unclipped_idx, barycentric_conversion, + faces_clipped_to_conversion_idx, clipped_faces_neighbor_idx) required to convert + barycentric coordinates from rasterization of the clipped Meshes to barycentric + coordinates in terms of the unclipped Meshes. + + Args: + face_verts: FloatTensor of shape (F_clipped, 3, 3) giving the verts of + each of the clipped faces + mesh_to_face_first_idx: an tensor of shape (N,), where N is the number of meshes + in the batch. The ith element stores the index into face_verts + of the first face of the ith mesh. + num_faces_per_mesh: a tensor of shape (N,) storing the number of faces in each mesh. + faces_clipped_to_unclipped_idx: (F_clipped,) shaped LongTensor mapping each clipped + face back to the face in faces_unclipped (i.e. the faces in the original meshes + obtained using meshes.faces_packed()) + barycentric_conversion: (T, 3, 3) FloatTensor, where barycentric_conversion[i, :, k] + stores the barycentric weights in terms of the world coordinates of the original + (big) unclipped triangle for the kth vertex in the clipped (small) triangle. + If the rasterizer then expresses some NDC coordinate in terms of barycentric + world coordinates for the clipped (small) triangle as alpha_clipped[i,:], + alpha_unclipped[i, :] = barycentric_conversion[i, :, :]*alpha_clipped[i, :] + faces_clipped_to_conversion_idx: (F_clipped,) shaped LongTensor mapping each clipped + face to the applicable row of barycentric_conversion (or set to -1 if conversion is + not needed). + clipped_faces_neighbor_idx: LongTensor of shape (F_clipped,) giving the index of the + neighboring face for each case 4 triangle. e.g. for a case 4 face with f split + into two triangles (t1, t2): clipped_faces_neighbor_idx[t1_idx] = t2_idx. + Faces which are not clipped and subdivided are set to -1 (i.e cases 1/2/3). + """ + + __slots__ = [ + "face_verts", + "mesh_to_face_first_idx", + "num_faces_per_mesh", + "faces_clipped_to_unclipped_idx", + "barycentric_conversion", + "faces_clipped_to_conversion_idx", + "clipped_faces_neighbor_idx", + ] + + def __init__( + self, + face_verts: torch.Tensor, + mesh_to_face_first_idx: torch.Tensor, + num_faces_per_mesh: torch.Tensor, + faces_clipped_to_unclipped_idx: Optional[torch.Tensor] = None, + barycentric_conversion: Optional[torch.Tensor] = None, + faces_clipped_to_conversion_idx: Optional[torch.Tensor] = None, + clipped_faces_neighbor_idx: Optional[torch.Tensor] = None, + ) -> None: + self.face_verts = face_verts + self.mesh_to_face_first_idx = mesh_to_face_first_idx + self.num_faces_per_mesh = num_faces_per_mesh + self.faces_clipped_to_unclipped_idx = faces_clipped_to_unclipped_idx + self.barycentric_conversion = barycentric_conversion + self.faces_clipped_to_conversion_idx = faces_clipped_to_conversion_idx + self.clipped_faces_neighbor_idx = clipped_faces_neighbor_idx + + +class ClipFrustum: + """ + Helper class to store the information needed to represent a view frustum + (left, right, top, bottom, znear, zfar), which is used to clip or cull triangles. + Values left as None mean that culling should not be performed for that axis. + The parameters perspective_correct, cull, and z_clip_value are used to define + behavior for clipping triangles to the frustum. + + Args: + left: NDC coordinate of the left clipping plane (along x axis) + right: NDC coordinate of the right clipping plane (along x axis) + top: NDC coordinate of the top clipping plane (along y axis) + bottom: NDC coordinate of the bottom clipping plane (along y axis) + znear: world space z coordinate of the near clipping plane + zfar: world space z coordinate of the far clipping plane + perspective_correct: should be set to True for a perspective camera + cull: if True, triangles outside the frustum should be culled + z_clip_value: if not None, then triangles should be clipped (possibly into + smaller triangles) such that z >= z_clip_value. This avoids projections + that go to infinity as z->0 + """ + + __slots__ = [ + "left", + "right", + "top", + "bottom", + "znear", + "zfar", + "perspective_correct", + "cull", + "z_clip_value", + ] + + def __init__( + self, + left: Optional[float] = None, + right: Optional[float] = None, + top: Optional[float] = None, + bottom: Optional[float] = None, + znear: Optional[float] = None, + zfar: Optional[float] = None, + perspective_correct: bool = False, + cull: bool = True, + z_clip_value: Optional[float] = None, + ) -> None: + self.left = left + self.right = right + self.top = top + self.bottom = bottom + self.znear = znear + self.zfar = zfar + self.perspective_correct = perspective_correct + self.cull = cull + self.z_clip_value = z_clip_value + + +def _get_culled_faces(face_verts: torch.Tensor, frustum: ClipFrustum) -> torch.Tensor: + """ + Helper function used to find all the faces in Meshes which are + fully outside the view frustum. A face is culled if all 3 vertices are outside + the same axis of the view frustum. + + Args: + face_verts: An (F,3,3) tensor, where F is the number of faces in + the packed representation of Meshes. The 2nd dimension represents the 3 vertices + of a triangle, and the 3rd dimension stores the xyz locations of each + vertex. + frustum: An instance of the ClipFrustum class with the information on the + position of the clipping planes. + + Returns: + faces_culled: An boolean tensor of size F specifying whether or not each face should be + culled. + """ + clipping_planes = ( + (frustum.left, 0, "<"), + (frustum.right, 0, ">"), + (frustum.top, 1, "<"), + (frustum.bottom, 1, ">"), + (frustum.znear, 2, "<"), + (frustum.zfar, 2, ">"), + ) + faces_culled = torch.zeros( + [face_verts.shape[0]], dtype=torch.bool, device=face_verts.device + ) + for plane in clipping_planes: + clip_value, axis, op = plane + # If clip_value is None then don't clip along that plane + if frustum.cull and clip_value is not None: + if op == "<": + verts_clipped = face_verts[:, axis] < clip_value + else: + verts_clipped = face_verts[:, axis] > clip_value + + # If all verts are clipped then face is outside the frustum + faces_culled |= verts_clipped.sum(1) == 3 + + return faces_culled + + +def _find_verts_intersecting_clipping_plane( + face_verts: torch.Tensor, + p1_face_ind: torch.Tensor, + clip_value: float, + perspective_correct: bool, +) -> Tuple[Tuple[Any, Any, Any, Any, Any], List[Any]]: + r""" + Helper function to find the vertices used to form a new triangle for case 3/case 4 faces. + + Given a list of triangles that are already known to intersect the clipping plane, + solve for the two vertices p4 and p5 where the edges of the triangle intersects the + clipping plane. + + p1 + /\ + / \ + / t \ + _____________p4/______\p5__________ clip_value + / \ + /____ \ + p2 ---____\p3 + + Args: + face_verts: An (F,3,3) tensor, where F is the number of faces in + the packed representation of the Meshes, the 2nd dimension represents + the 3 vertices of the face, and the 3rd dimension stores the xyz locations of each + vertex. The z-coordinates must be represented in world coordinates, while + the xy-coordinates may be in NDC/screen coordinates (i.e. after projection). + p1_face_ind: A tensor of shape (N,) with values in the range of 0 to 2. In each + case 3/case 4 triangle, two vertices are on the same side of the + clipping plane and the 3rd is on the other side. p1_face_ind stores the index of + the vertex that is not on the same side as any other vertex in the triangle. + clip_value: Float, the z-value defining where to clip the triangle. + perspective_correct: Bool, Should be set to true if a perspective camera was + used and xy-coordinates of face_verts_unclipped are in NDC/screen coordinates. + + Returns: + A 2-tuple + p: (p1, p2, p3, p4, p5)) + p_barycentric (p1_bary, p2_bary, p3_bary, p4_bary, p5_bary) + + Each of p1...p5 is an (F,3) tensor of the xyz locations of the 5 points in the + diagram above for case 3/case 4 faces. Each p1_bary...p5_bary is an (F, 3) tensor + storing the barycentric weights used to encode p1...p5 in terms of the the original + unclipped triangle. + """ + + # Let T be number of triangles in face_verts (note that these correspond to the subset + # of case 1 or case 2 triangles). p1_face_ind, p2_face_ind, and p3_face_ind are (T) + # tensors with values in the range of 0 to 2. p1_face_ind stores the index of the + # vertex that is not on the same side as any other vertex in the triangle, and + # p2_face_ind and p3_face_ind are the indices of the other two vertices preserving + # the same counterclockwise or clockwise ordering + T = face_verts.shape[0] + p2_face_ind = torch.remainder(p1_face_ind + 1, 3) + p3_face_ind = torch.remainder(p1_face_ind + 2, 3) + + # p1, p2, p3 are (T, 3) tensors storing the corresponding (x, y, z) coordinates + # of p1_face_ind, p2_face_ind, p3_face_ind + p1 = face_verts.gather(1, p1_face_ind[:, None, None].expand(-1, -1, 3)).squeeze(1) + p2 = face_verts.gather(1, p2_face_ind[:, None, None].expand(-1, -1, 3)).squeeze(1) + p3 = face_verts.gather(1, p3_face_ind[:, None, None].expand(-1, -1, 3)).squeeze(1) + + ################################## + # Solve for intersection point p4 + ################################## + + # p4 is a (T, 3) tensor is the point on the segment between p1 and p2 that + # intersects the clipping plane. + # Solve for the weight w2 such that p1.z*(1-w2) + p2.z*w2 = clip_value. + # Then interpolate p4 = p1*(1-w2) + p2*w2 where it is assumed that z-coordinates + # are expressed in world coordinates (since we want to clip z in world coordinates). + w2 = (p1[:, 2] - clip_value) / (p1[:, 2] - p2[:, 2]) + p4 = p1 * (1 - w2[:, None]) + p2 * w2[:, None] + if perspective_correct: + # It is assumed that all z-coordinates are in world coordinates (not NDC + # coordinates), while x and y coordinates may be in NDC/screen coordinates. + # If x and y are in NDC/screen coordinates and a projective transform was used + # in a perspective camera, then we effectively want to: + # 1. Convert back to world coordinates (by multiplying by z) + # 2. Interpolate using w2 + # 3. Convert back to NDC/screen coordinates (by dividing by the new z=clip_value) + p1_world = p1[:, :2] * p1[:, 2:3] + p2_world = p2[:, :2] * p2[:, 2:3] + p4[:, :2] = (p1_world * (1 - w2[:, None]) + p2_world * w2[:, None]) / clip_value + + ################################## + # Solve for intersection point p5 + ################################## + + # p5 is a (T, 3) tensor representing the point on the segment between p1 and p3 that + # intersects the clipping plane. + # Solve for the weight w3 such that p1.z * (1-w3) + p2.z * w3 = clip_value, + # and then interpolate p5 = p1 * (1-w3) + p3 * w3 + w3 = (p1[:, 2] - clip_value) / (p1[:, 2] - p3[:, 2]) + w3 = w3.detach() + p5 = p1 * (1 - w3[:, None]) + p3 * w3[:, None] + if perspective_correct: + # Again if using a perspective camera, convert back to world coordinates + # interpolate and convert back + p1_world = p1[:, :2] * p1[:, 2:3] + p3_world = p3[:, :2] * p3[:, 2:3] + p5[:, :2] = (p1_world * (1 - w3[:, None]) + p3_world * w3[:, None]) / clip_value + + # Set the barycentric coordinates of p1,p2,p3,p4,p5 in terms of the original + # unclipped triangle in face_verts. + T_idx = torch.arange(T, device=face_verts.device) + p_barycentric = [torch.zeros((T, 3), device=face_verts.device) for i in range(5)] + p_barycentric[0][(T_idx, p1_face_ind)] = 1 + p_barycentric[1][(T_idx, p2_face_ind)] = 1 + p_barycentric[2][(T_idx, p3_face_ind)] = 1 + p_barycentric[3][(T_idx, p1_face_ind)] = 1 - w2 + p_barycentric[3][(T_idx, p2_face_ind)] = w2 + p_barycentric[4][(T_idx, p1_face_ind)] = 1 - w3 + p_barycentric[4][(T_idx, p3_face_ind)] = w3 + + p = (p1, p2, p3, p4, p5) + + return p, p_barycentric + + +################### +# Main Entry point +################### +def clip_faces( + face_verts_unclipped: torch.Tensor, + mesh_to_face_first_idx: torch.Tensor, + num_faces_per_mesh: torch.Tensor, + frustum: ClipFrustum, +) -> ClippedFaces: + """ + Clip a mesh to the portion contained within a view frustum and with z > z_clip_value. + + There are two types of clipping: + 1) Cull triangles that are completely outside the view frustum. This is purely + to save computation by reducing the number of triangles that need to be + rasterized. + 2) Clip triangles into the portion of the triangle where z > z_clip_value. The + clipped region may be a quadrilateral, which results in splitting a triangle + into two triangles. This does not save computation, but is necessary to + correctly rasterize using perspective cameras for triangles that pass through + z <= 0, because NDC/screen coordinates go to infinity at z=0. + + Args: + face_verts_unclipped: An (F, 3, 3) tensor, where F is the number of faces in + the packed representation of Meshes, the 2nd dimension represents the 3 vertices + of the triangle, and the 3rd dimension stores the xyz locations of each + vertex. The z-coordinates must be represented in world coordinates, while + the xy-coordinates may be in NDC/screen coordinates + mesh_to_face_first_idx: an tensor of shape (N,), where N is the number of meshes + in the batch. The ith element stores the index into face_verts_unclipped + of the first face of the ith mesh. + num_faces_per_mesh: a tensor of shape (N,) storing the number of faces in each mesh. + frustum: a ClipFrustum object defining the frustum used to cull faces. + + Returns: + clipped_faces: ClippedFaces object storing a clipped version of the Meshes + along with tensors that can be used to convert barycentric coordinates + returned by rasterization of the clipped meshes into a barycentric + coordinates for the unclipped meshes. + """ + F = face_verts_unclipped.shape[0] + device = face_verts_unclipped.device + + # Triangles completely outside the view frustum will be culled + # faces_culled is of shape (F, ) + faces_culled = _get_culled_faces(face_verts_unclipped, frustum) + + # Triangles that are partially behind the z clipping plane will be clipped to + # smaller triangles + z_clip_value = frustum.z_clip_value + perspective_correct = frustum.perspective_correct + if z_clip_value is not None: + # (F, 3) tensor (where F is the number of triangles) marking whether each vertex + # in a triangle is behind the clipping plane + faces_clipped_verts = face_verts_unclipped[:, :, 2] < z_clip_value + + # (F) dim tensor containing the number of clipped vertices in each triangle + faces_num_clipped_verts = faces_clipped_verts.sum(1) + else: + faces_num_clipped_verts = torch.zeros([F], device=device) + + # If no triangles need to be clipped or culled, avoid unnecessary computation + # and return early + if faces_num_clipped_verts.sum().item() == 0 and faces_culled.sum().item() == 0: + return ClippedFaces( + face_verts=face_verts_unclipped, + mesh_to_face_first_idx=mesh_to_face_first_idx, + num_faces_per_mesh=num_faces_per_mesh, + ) + + ##################################################################################### + # Classify faces into the 4 relevant cases: + # 1) The triangle is completely in front of the clipping plane (it is left + # unchanged) + # 2) The triangle is completely behind the clipping plane (it is culled) + # 3) The triangle has exactly two vertices behind the clipping plane (it is + # clipped into a smaller triangle) + # 4) The triangle has exactly one vertex behind the clipping plane (it is clipped + # into a smaller quadrilateral and split into two triangles) + ##################################################################################### + + faces_unculled = ~faces_culled + # Case 1: no clipped verts or culled faces + cases1_unclipped = (faces_num_clipped_verts == 0) & faces_unculled + case1_unclipped_idx = cases1_unclipped.nonzero(as_tuple=True)[0] + # Case 2: all verts clipped + case2_unclipped = (faces_num_clipped_verts == 3) | faces_culled + # Case 3: two verts clipped + case3_unclipped = (faces_num_clipped_verts == 2) & faces_unculled + case3_unclipped_idx = case3_unclipped.nonzero(as_tuple=True)[0] + # Case 4: one vert clipped + case4_unclipped = (faces_num_clipped_verts == 1) & faces_unculled + case4_unclipped_idx = case4_unclipped.nonzero(as_tuple=True)[0] + + # faces_unclipped_to_clipped_idx is an (F) dim tensor storing the index of each + # face to the corresponding face in face_verts_clipped. + # Each case 2 triangle will be culled (deleted from face_verts_clipped), + # while each case 4 triangle will be split into two smaller triangles + # (replaced by two consecutive triangles in face_verts_clipped) + + # case2_unclipped is an (F,) dim 0/1 tensor of all the case2 faces + # case4_unclipped is an (F,) dim 0/1 tensor of all the case4 faces + faces_delta = case4_unclipped.int() - case2_unclipped.int() + # faces_delta_cum gives the per face change in index. Faces which are + # clipped in the original mesh are mapped to the closest non clipped face + # in face_verts_clipped (this doesn't matter as they are not used + # during rasterization anyway). + faces_delta_cum = faces_delta.cumsum(0) - faces_delta + delta = 1 + case4_unclipped.int() - case2_unclipped.int() + faces_unclipped_to_clipped_idx = delta.cumsum(0) - delta + + ########################################### + # Allocate tensors for the output Meshes. + # These will then be filled in for each case. + ########################################### + F_clipped = ( + F + # pyre-fixme[58]: `+` is not supported for operand types `int` and + # `Union[bool, float, int]`. + + faces_delta_cum[-1].item() + # pyre-fixme[58]: `+` is not supported for operand types `int` and + # `Union[bool, float, int]`. + + faces_delta[-1].item() + ) # Total number of faces in the new Meshes + face_verts_clipped = torch.zeros( + (F_clipped, 3, 3), dtype=face_verts_unclipped.dtype, device=device + ) + faces_clipped_to_unclipped_idx = torch.zeros( + [F_clipped], dtype=torch.int64, device=device + ) + + # Update version of mesh_to_face_first_idx and num_faces_per_mesh applicable to + # face_verts_clipped + mesh_to_face_first_idx_clipped = faces_unclipped_to_clipped_idx[ + mesh_to_face_first_idx + ] + F_clipped_t = torch.full([1], F_clipped, dtype=torch.int64, device=device) + num_faces_next = torch.cat((mesh_to_face_first_idx_clipped[1:], F_clipped_t)) + num_faces_per_mesh_clipped = num_faces_next - mesh_to_face_first_idx_clipped + + ################# Start Case 1 ######################################## + + # Case 1: Triangles are fully visible, copy unchanged triangles into the + # appropriate position in the new list of faces + case1_clipped_idx = faces_unclipped_to_clipped_idx[case1_unclipped_idx] + face_verts_clipped[case1_clipped_idx] = face_verts_unclipped[case1_unclipped_idx] + faces_clipped_to_unclipped_idx[case1_clipped_idx] = case1_unclipped_idx + + # If no triangles need to be clipped but some triangles were culled, avoid + # unnecessary clipping computation + if case3_unclipped_idx.shape[0] + case4_unclipped_idx.shape[0] == 0: + return ClippedFaces( + face_verts=face_verts_clipped, + mesh_to_face_first_idx=mesh_to_face_first_idx_clipped, + num_faces_per_mesh=num_faces_per_mesh_clipped, + faces_clipped_to_unclipped_idx=faces_clipped_to_unclipped_idx, + ) + + ################# End Case 1 ########################################## + + ################# Start Case 3 ######################################## + + # Case 3: exactly two vertices are behind the camera, clipping the triangle into a + # triangle. In the diagram below, we clip the bottom part of the triangle, and add + # new vertices p4 and p5 by intersecting with the clipping plane. The updated + # triangle is the triangle between p4, p1, p5 + # + # p1 (unclipped vertex) + # /\ + # / \ + # / t \ + # _____________p4/______\p5__________ clip_value + # xxxxxxxxxxxxxx/ \xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + # xxxxxxxxxxxxx/____ \xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + # xxxxxxxxxx p2 xxxx---____\p3 xxxxxxxxxxxxxxxxxxxxxxxxxxx + # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + faces_case3 = face_verts_unclipped[case3_unclipped_idx] + + # index (0, 1, or 2) of the vertex in front of the clipping plane + p1_face_ind = torch.where(~faces_clipped_verts[case3_unclipped_idx])[1] + + # Solve for the points p4, p5 that intersect the clipping plane + p, p_barycentric = _find_verts_intersecting_clipping_plane( + faces_case3, p1_face_ind, z_clip_value, perspective_correct + ) + + p1, _, _, p4, p5 = p + p1_barycentric, _, _, p4_barycentric, p5_barycentric = p_barycentric + + # Store clipped triangle + case3_clipped_idx = faces_unclipped_to_clipped_idx[case3_unclipped_idx] + t_barycentric = torch.stack((p4_barycentric, p5_barycentric, p1_barycentric), 2) + face_verts_clipped[case3_clipped_idx] = torch.stack((p4, p5, p1), 1) + faces_clipped_to_unclipped_idx[case3_clipped_idx] = case3_unclipped_idx + + ################# End Case 3 ########################################## + + ################# Start Case 4 ######################################## + + # Case 4: exactly one vertex is behind the camera, clip the triangle into a + # quadrilateral. In the diagram below, we clip the bottom part of the triangle, + # and add new vertices p4 and p5 by intersecting with the cliiping plane. The + # unclipped region is a quadrilateral, which is split into two triangles: + # t1: p4, p2, p5 + # t2: p5, p2, p3 + # + # p3_____________________p2 + # \ __--/ + # \ t2 __-- / + # \ __-- t1 / + # ______________p5\__--_________/p4_________clip_value + # xxxxxxxxxxxxxxxxx\ /xxxxxxxxxxxxxxxxxx + # xxxxxxxxxxxxxxxxxx\ /xxxxxxxxxxxxxxxxxxx + # xxxxxxxxxxxxxxxxxxx\ /xxxxxxxxxxxxxxxxxxxx + # xxxxxxxxxxxxxxxxxxxx\ /xxxxxxxxxxxxxxxxxxxxx + # xxxxxxxxxxxxxxxxxxxxx\ /xxxxxxxxxxxxxxxxxxxxx + # xxxxxxxxxxxxxxxxxxxxxx\ /xxxxxxxxxxxxxxxxxxxxx + # p1 (clipped vertex) + + faces_case4 = face_verts_unclipped[case4_unclipped_idx] + + # index (0, 1, or 2) of the vertex behind the clipping plane + p1_face_ind = torch.where(faces_clipped_verts[case4_unclipped_idx])[1] + + # Solve for the points p4, p5 that intersect the clipping plane + p, p_barycentric = _find_verts_intersecting_clipping_plane( + faces_case4, p1_face_ind, z_clip_value, perspective_correct + ) + _, p2, p3, p4, p5 = p + _, p2_barycentric, p3_barycentric, p4_barycentric, p5_barycentric = p_barycentric + + # Store clipped triangles + case4_clipped_idx = faces_unclipped_to_clipped_idx[case4_unclipped_idx] + face_verts_clipped[case4_clipped_idx] = torch.stack((p4, p2, p5), 1) + face_verts_clipped[case4_clipped_idx + 1] = torch.stack((p5, p2, p3), 1) + t1_barycentric = torch.stack((p4_barycentric, p2_barycentric, p5_barycentric), 2) + t2_barycentric = torch.stack((p5_barycentric, p2_barycentric, p3_barycentric), 2) + faces_clipped_to_unclipped_idx[case4_clipped_idx] = case4_unclipped_idx + faces_clipped_to_unclipped_idx[case4_clipped_idx + 1] = case4_unclipped_idx + + ##################### End Case 4 ######################### + + # Triangles that were clipped (case 3 & case 4) will require conversion of + # barycentric coordinates from being in terms of the smaller clipped triangle to in terms + # of the original big triangle. If there are T clipped triangles, + # barycentric_conversion is a (T, 3, 3) tensor, where barycentric_conversion[i, :, k] + # stores the barycentric weights in terms of the world coordinates of the original + # (big) triangle for the kth vertex in the clipped (small) triangle. If our + # rasterizer then expresses some NDC coordinate in terms of barycentric + # world coordinates for the clipped (small) triangle as alpha_clipped[i,:], + # alpha_unclipped[i, :] = barycentric_conversion[i, :, :]*alpha_clipped[i, :] + barycentric_conversion = torch.cat((t_barycentric, t1_barycentric, t2_barycentric)) + + # faces_clipped_to_conversion_idx is an (F_clipped,) shape tensor mapping each output + # face to the applicable row of barycentric_conversion (or set to -1 if conversion is + # not needed) + faces_to_convert_idx = torch.cat( + (case3_clipped_idx, case4_clipped_idx, case4_clipped_idx + 1), 0 + ) + barycentric_idx = torch.arange( + barycentric_conversion.shape[0], dtype=torch.int64, device=device + ) + faces_clipped_to_conversion_idx = torch.full( + [F_clipped], -1, dtype=torch.int64, device=device + ) + faces_clipped_to_conversion_idx[faces_to_convert_idx] = barycentric_idx + + # clipped_faces_quadrilateral_ind is an (F_clipped) dim tensor + # For case 4 clipped triangles (where a big triangle is split in two smaller triangles), + # store the index of the neighboring clipped triangle. + # This will be needed because if the soft rasterizer includes both + # triangles in the list of top K nearest triangles, we + # should only use the one with the smaller distance. + clipped_faces_neighbor_idx = torch.full( + [F_clipped], -1, dtype=torch.int64, device=device + ) + clipped_faces_neighbor_idx[case4_clipped_idx] = case4_clipped_idx + 1 + clipped_faces_neighbor_idx[case4_clipped_idx + 1] = case4_clipped_idx + + clipped_faces = ClippedFaces( + face_verts=face_verts_clipped, + mesh_to_face_first_idx=mesh_to_face_first_idx_clipped, + num_faces_per_mesh=num_faces_per_mesh_clipped, + faces_clipped_to_unclipped_idx=faces_clipped_to_unclipped_idx, + barycentric_conversion=barycentric_conversion, + faces_clipped_to_conversion_idx=faces_clipped_to_conversion_idx, + clipped_faces_neighbor_idx=clipped_faces_neighbor_idx, + ) + return clipped_faces + + +def convert_clipped_rasterization_to_original_faces( + pix_to_face_clipped, bary_coords_clipped, clipped_faces: ClippedFaces +) -> Tuple[torch.Tensor, torch.Tensor]: + """ + Convert rasterization Fragments (expressed as pix_to_face_clipped, + bary_coords_clipped, dists_clipped) of clipped Meshes computed using clip_faces() + to the corresponding rasterization Fragments where barycentric coordinates and + face indices are in terms of the original unclipped Meshes. The distances are + handled in the rasterizer C++/CUDA kernels (i.e. for Cases 1/3 the distance + can be used directly and for Case 4 triangles the distance of the pixel to + the closest of the two subdivided triangles is used). + + Args: + pix_to_face_clipped: LongTensor of shape (N, image_size, image_size, + faces_per_pixel) giving the indices of the nearest faces at each pixel, + sorted in ascending z-order. Concretely + ``pix_to_face_clipped[n, y, x, k] = f`` means that ``faces_verts_clipped[f]`` + is the kth closest face (in the z-direction) to pixel (y, x). Pixels that + are hit by fewer than faces_per_pixel are padded with -1. + bary_coords_clipped: FloatTensor of shape + (N, image_size, image_size, faces_per_pixel, 3) giving the barycentric + coordinates in world coordinates of the nearest faces at each pixel, sorted + in ascending z-order. Concretely, if ``pix_to_face_clipped[n, y, x, k] = f`` + then ``[w0, w1, w2] = bary_coords_clipped[n, y, x, k]`` gives the + barycentric coords for pixel (y, x) relative to the face defined by + ``unproject(face_verts_clipped[f])``. Pixels hit by fewer than + faces_per_pixel are padded with -1. + clipped_faces: an instance of ClippedFaces class giving the auxillary variables + for converting rasterization outputs from clipped to unclipped Meshes. + + Returns: + 3-tuple: (pix_to_face_unclipped, bary_coords_unclipped, dists_unclipped) that + have the same definition as (pix_to_face_clipped, bary_coords_clipped, + dists_clipped) except that they pertain to faces_verts_unclipped instead of + faces_verts_clipped (i.e the original meshes as opposed to the modified meshes) + """ + faces_clipped_to_unclipped_idx = clipped_faces.faces_clipped_to_unclipped_idx + + # If no clipping then return inputs + if ( + faces_clipped_to_unclipped_idx is None + or faces_clipped_to_unclipped_idx.numel() == 0 + ): + return pix_to_face_clipped, bary_coords_clipped + + device = pix_to_face_clipped.device + + # Convert pix_to_face indices to now refer to the faces in the unclipped Meshes. + # Init empty tensor to fill in all the background values which have pix_to_face=-1. + empty = torch.full(pix_to_face_clipped.shape, -1, device=device, dtype=torch.int64) + pix_to_face_unclipped = torch.where( + pix_to_face_clipped != -1, + faces_clipped_to_unclipped_idx[pix_to_face_clipped], + empty, + ) + + # For triangles that were clipped into smaller triangle(s), convert barycentric + # coordinates from being in terms of the clipped triangle to being in terms of the + # original unclipped triangle. + + # barycentric_conversion is a (T, 3, 3) tensor such that + # alpha_unclipped[i, :] = barycentric_conversion[i, :, :]*alpha_clipped[i, :] + barycentric_conversion = clipped_faces.barycentric_conversion + + # faces_clipped_to_conversion_idx is an (F_clipped,) shape tensor mapping each output + # face to the applicable row of barycentric_conversion (or set to -1 if conversion is + # not needed) + faces_clipped_to_conversion_idx = clipped_faces.faces_clipped_to_conversion_idx + + if barycentric_conversion is not None: + bary_coords_unclipped = bary_coords_clipped.clone() + + # Select the subset of faces that require conversion, where N is the sum + # number of case3/case4 triangles that are in the closest k triangles to some + # rasterized pixel. + pix_to_conversion_idx = torch.where( + pix_to_face_clipped != -1, + faces_clipped_to_conversion_idx[pix_to_face_clipped], + empty, + ) + faces_to_convert_mask = pix_to_conversion_idx != -1 + N = faces_to_convert_mask.sum().item() + + # Expand to (N, H, W, K, 3) to be the same shape as barycentric coordinates + faces_to_convert_mask_expanded = faces_to_convert_mask[:, :, :, :, None].expand( + -1, -1, -1, -1, 3 + ) + + # An (N,) dim tensor of indices into barycentric_conversion + conversion_idx_subset = pix_to_conversion_idx[faces_to_convert_mask] + + # An (N, 3, 1) tensor of barycentric coordinates in terms of the clipped triangles + bary_coords_clipped_subset = bary_coords_clipped[faces_to_convert_mask_expanded] + bary_coords_clipped_subset = bary_coords_clipped_subset.reshape((N, 3, 1)) + + # An (N, 3, 3) tensor storing matrices to convert from clipped to unclipped + # barycentric coordinates + bary_conversion_subset = barycentric_conversion[conversion_idx_subset] + + # An (N, 3, 1) tensor of barycentric coordinates in terms of the unclipped triangle + bary_coords_unclipped_subset = bary_conversion_subset.bmm( + bary_coords_clipped_subset + ) + + bary_coords_unclipped_subset = bary_coords_unclipped_subset.reshape([N * 3]) + bary_coords_unclipped[faces_to_convert_mask_expanded] = ( + bary_coords_unclipped_subset + ) + + # dists for case 4 faces will be handled in the rasterizer + # so no need to modify them here. + else: + bary_coords_unclipped = bary_coords_clipped + + return pix_to_face_unclipped, bary_coords_unclipped diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/mesh/rasterize_meshes.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/mesh/rasterize_meshes.py new file mode 100644 index 0000000000000000000000000000000000000000..88c28fd8b064078baad265a0b65ea3a29caee80b --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/mesh/rasterize_meshes.py @@ -0,0 +1,767 @@ +# 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. + +# pyre-unsafe + + +from typing import List, Optional, Tuple, Union + +import numpy as np +import torch +from pytorch3d import _C + +from ..utils import parse_image_size + +from .clip import ( + clip_faces, + ClipFrustum, + convert_clipped_rasterization_to_original_faces, +) + + +# TODO make the epsilon user configurable +kEpsilon = 1e-8 + +# Maximum number of faces per bins for +# coarse-to-fine rasterization +kMaxFacesPerBin = 22 + + +def rasterize_meshes( + meshes, + image_size: Union[int, List[int], Tuple[int, int]] = 256, + blur_radius: float = 0.0, + faces_per_pixel: int = 8, + bin_size: Optional[int] = None, + max_faces_per_bin: Optional[int] = None, + perspective_correct: bool = False, + clip_barycentric_coords: bool = False, + cull_backfaces: bool = False, + z_clip_value: Optional[float] = None, + cull_to_frustum: bool = False, +): + """ + Rasterize a batch of meshes given the shape of the desired output image. + Each mesh is rasterized onto a separate image of shape + (H, W) if `image_size` is a tuple or (image_size, image_size) if it + is an int. + + If the desired image size is non square (i.e. a tuple of (H, W) where H != W) + the aspect ratio needs special consideration. There are two aspect ratios + to be aware of: + - the aspect ratio of each pixel + - the aspect ratio of the output image + The camera can be used to set the pixel aspect ratio. In the rasterizer, + we assume square pixels, but variable image aspect ratio (i.e rectangle images). + + In most cases you will want to set the camera aspect ratio to + 1.0 (i.e. square pixels) and only vary the + `image_size` (i.e. the output image dimensions in pixels). + + Args: + meshes: A Meshes object representing a batch of meshes, batch size N. + image_size: Size in pixels of the output image to be rasterized. + Can optionally be a tuple of (H, W) in the case of non square images. + blur_radius: Float distance in the range [0, 2] used to expand the face + bounding boxes for rasterization. Setting blur radius + results in blurred edges around the shape instead of a + hard boundary. Set to 0 for no blur. + faces_per_pixel (Optional): Number of faces to save per pixel, returning + the nearest faces_per_pixel points along the z-axis. + bin_size: Size of bins to use for coarse-to-fine rasterization. Setting + bin_size=0 uses naive rasterization; setting bin_size=None attempts to + set it heuristically based on the shape of the input. This should not + affect the output, but can affect the speed of the forward pass. + max_faces_per_bin: Only applicable when using coarse-to-fine rasterization + (bin_size > 0); this is the maximum number of faces allowed within each + bin. This should not affect the output values, but can affect + the memory usage in the forward pass. + perspective_correct: Bool, Whether to apply perspective correction when computing + barycentric coordinates for pixels. This should be set to True if a perspective + camera is used. + clip_barycentric_coords: Whether, after any perspective correction is applied + but before the depth is calculated (e.g. for z clipping), + to "correct" a location outside the face (i.e. with a negative + barycentric coordinate) to a position on the edge of the face. + cull_backfaces: Bool, Whether to only rasterize mesh faces which are + visible to the camera. This assumes that vertices of + front-facing triangles are ordered in an anti-clockwise + fashion, and triangles that face away from the camera are + in a clockwise order relative to the current view + direction. NOTE: This will only work if the mesh faces are + consistently defined with counter-clockwise ordering when + viewed from the outside. + z_clip_value: if not None, then triangles will be clipped (and possibly + subdivided into smaller triangles) such that z >= z_clip_value. + This avoids camera projections that go to infinity as z->0. + Default is None as clipping affects rasterization speed and + should only be turned on if explicitly needed. + See clip.py for all the extra computation that is required. + cull_to_frustum: if True, triangles outside the view frustum will be culled. + Culling involves removing all faces which fall outside view frustum. + Default is False so that it is turned on only when needed. + + Returns: + 4-element tuple containing + + - **pix_to_face**: LongTensor of shape + (N, image_size, image_size, faces_per_pixel) + giving the indices of the nearest faces at each pixel, + sorted in ascending z-order. + Concretely ``pix_to_face[n, y, x, k] = f`` means that + ``faces_verts[f]`` is the kth closest face (in the z-direction) + to pixel (y, x). Pixels that are hit by fewer than + faces_per_pixel are padded with -1. + - **zbuf**: FloatTensor of shape (N, image_size, image_size, faces_per_pixel) + giving the NDC z-coordinates of the nearest faces at each pixel, + sorted in ascending z-order. + Concretely, if ``pix_to_face[n, y, x, k] = f`` then + ``zbuf[n, y, x, k] = face_verts[f, 2]``. Pixels hit by fewer than + faces_per_pixel are padded with -1. + - **barycentric**: FloatTensor of shape + (N, image_size, image_size, faces_per_pixel, 3) + giving the barycentric coordinates in NDC units of the + nearest faces at each pixel, sorted in ascending z-order. + Concretely, if ``pix_to_face[n, y, x, k] = f`` then + ``[w0, w1, w2] = barycentric[n, y, x, k]`` gives + the barycentric coords for pixel (y, x) relative to the face + defined by ``face_verts[f]``. Pixels hit by fewer than + faces_per_pixel are padded with -1. + - **pix_dists**: FloatTensor of shape + (N, image_size, image_size, faces_per_pixel) + giving the signed Euclidean distance (in NDC units) in the + x/y plane of each point closest to the pixel. Concretely if + ``pix_to_face[n, y, x, k] = f`` then ``pix_dists[n, y, x, k]`` is the + squared distance between the pixel (y, x) and the face given + by vertices ``face_verts[f]``. Pixels hit with fewer than + ``faces_per_pixel`` are padded with -1. + + In the case that image_size is a tuple of (H, W) then the outputs + will be of shape `(N, H, W, ...)`. + """ + verts_packed = meshes.verts_packed() + faces_packed = meshes.faces_packed() + face_verts = verts_packed[faces_packed] + mesh_to_face_first_idx = meshes.mesh_to_faces_packed_first_idx() + num_faces_per_mesh = meshes.num_faces_per_mesh() + + # In the case that H != W use the max image size to set the bin_size + # to accommodate the num bins constraint in the coarse rasterizer. + # If the ratio of H:W is large this might cause issues as the smaller + # dimension will have fewer bins. + # TODO: consider a better way of setting the bin size. + im_size = parse_image_size(image_size) + max_image_size = max(*im_size) + + clipped_faces_neighbor_idx = None + + if z_clip_value is not None or cull_to_frustum: + # Cull faces outside the view frustum, and clip faces that are partially + # behind the camera into the portion of the triangle in front of the + # camera. This may change the number of faces + frustum = ClipFrustum( + left=-1, + right=1, + top=-1, + bottom=1, + perspective_correct=perspective_correct, + z_clip_value=z_clip_value, + cull=cull_to_frustum, + ) + clipped_faces = clip_faces( + face_verts, mesh_to_face_first_idx, num_faces_per_mesh, frustum=frustum + ) + face_verts = clipped_faces.face_verts + mesh_to_face_first_idx = clipped_faces.mesh_to_face_first_idx + num_faces_per_mesh = clipped_faces.num_faces_per_mesh + + # For case 4 clipped triangles (where a big triangle is split in two smaller triangles), + # need the index of the neighboring clipped triangle as only one can be in + # in the top K closest faces in the rasterization step. + clipped_faces_neighbor_idx = clipped_faces.clipped_faces_neighbor_idx + + if clipped_faces_neighbor_idx is None: + # Set to the default which is all -1s. + clipped_faces_neighbor_idx = torch.full( + size=(face_verts.shape[0],), + fill_value=-1, + device=meshes.device, + dtype=torch.int64, + ) + + # TODO: Choose naive vs coarse-to-fine based on mesh size and image size. + if bin_size is None: + if not verts_packed.is_cuda: + # Binned CPU rasterization is not supported. + bin_size = 0 + else: + # TODO better heuristics for bin size. + if max_image_size <= 64: + bin_size = 8 + else: + # Heuristic based formula maps max_image_size -> bin_size as follows: + # max_image_size < 64 -> 8 + # 16 < max_image_size < 256 -> 16 + # 256 < max_image_size < 512 -> 32 + # 512 < max_image_size < 1024 -> 64 + # 1024 < max_image_size < 2048 -> 128 + bin_size = int(2 ** max(np.ceil(np.log2(max_image_size)) - 4, 4)) + + if bin_size != 0: + # There is a limit on the number of faces per bin in the cuda kernel. + faces_per_bin = 1 + (max_image_size - 1) // bin_size + if faces_per_bin >= kMaxFacesPerBin: + raise ValueError( + "bin_size too small, number of faces per bin must be less than %d; got %d" + % (kMaxFacesPerBin, faces_per_bin) + ) + + if max_faces_per_bin is None: + max_faces_per_bin = int(max(10000, meshes._F / 5)) + + pix_to_face, zbuf, barycentric_coords, dists = _RasterizeFaceVerts.apply( + face_verts, + mesh_to_face_first_idx, + num_faces_per_mesh, + clipped_faces_neighbor_idx, + im_size, + blur_radius, + faces_per_pixel, + bin_size, + max_faces_per_bin, + perspective_correct, + clip_barycentric_coords, + cull_backfaces, + ) + + if z_clip_value is not None or cull_to_frustum: + # If faces were clipped, map the rasterization result to be in terms of the + # original unclipped faces. This may involve converting barycentric + # coordinates + outputs = convert_clipped_rasterization_to_original_faces( + pix_to_face, + barycentric_coords, + # pyre-fixme[61]: `clipped_faces` may not be initialized here. + clipped_faces, + ) + pix_to_face, barycentric_coords = outputs + + return pix_to_face, zbuf, barycentric_coords, dists + + +class _RasterizeFaceVerts(torch.autograd.Function): + """ + Torch autograd wrapper for forward and backward pass of rasterize_meshes + implemented in C++/CUDA. + + Args: + face_verts: Tensor of shape (F, 3, 3) giving (packed) vertex positions + for faces in all the meshes in the batch. Concretely, + face_verts[f, i] = [x, y, z] gives the coordinates for the + ith vertex of the fth face. These vertices are expected to + be in NDC coordinates in the range [-1, 1]. + mesh_to_face_first_idx: LongTensor of shape (N) giving the index in + faces_verts of the first face in each mesh in + the batch. + num_faces_per_mesh: LongTensor of shape (N) giving the number of faces + for each mesh in the batch. + image_size, blur_radius, faces_per_pixel: same as rasterize_meshes. + perspective_correct: same as rasterize_meshes. + cull_backfaces: same as rasterize_meshes. + + Returns: + same as rasterize_meshes function. + """ + + @staticmethod + def forward( + ctx, + face_verts: torch.Tensor, + mesh_to_face_first_idx: torch.Tensor, + num_faces_per_mesh: torch.Tensor, + clipped_faces_neighbor_idx: torch.Tensor, + image_size: Union[List[int], Tuple[int, int]] = (256, 256), + blur_radius: float = 0.01, + faces_per_pixel: int = 0, + bin_size: int = 0, + max_faces_per_bin: int = 0, + perspective_correct: bool = False, + clip_barycentric_coords: bool = False, + cull_backfaces: bool = False, + z_clip_value: Optional[float] = None, + cull_to_frustum: bool = True, + ): + # pyre-fixme[16]: Module `pytorch3d` has no attribute `_C`. + pix_to_face, zbuf, barycentric_coords, dists = _C.rasterize_meshes( + face_verts, + mesh_to_face_first_idx, + num_faces_per_mesh, + clipped_faces_neighbor_idx, + image_size, + blur_radius, + faces_per_pixel, + bin_size, + max_faces_per_bin, + perspective_correct, + clip_barycentric_coords, + cull_backfaces, + ) + + ctx.save_for_backward(face_verts, pix_to_face) + ctx.mark_non_differentiable(pix_to_face) + ctx.perspective_correct = perspective_correct + ctx.clip_barycentric_coords = clip_barycentric_coords + return pix_to_face, zbuf, barycentric_coords, dists + + @staticmethod + def backward(ctx, grad_pix_to_face, grad_zbuf, grad_barycentric_coords, grad_dists): + grad_face_verts = None + grad_mesh_to_face_first_idx = None + grad_num_faces_per_mesh = None + grad_clipped_faces_neighbor_idx = None + grad_image_size = None + grad_radius = None + grad_faces_per_pixel = None + grad_bin_size = None + grad_max_faces_per_bin = None + grad_perspective_correct = None + grad_clip_barycentric_coords = None + grad_cull_backfaces = None + face_verts, pix_to_face = ctx.saved_tensors + grad_face_verts = _C.rasterize_meshes_backward( + face_verts, + pix_to_face, + grad_zbuf, + grad_barycentric_coords, + grad_dists, + ctx.perspective_correct, + ctx.clip_barycentric_coords, + ) + grads = ( + grad_face_verts, + grad_mesh_to_face_first_idx, + grad_num_faces_per_mesh, + grad_clipped_faces_neighbor_idx, + grad_image_size, + grad_radius, + grad_faces_per_pixel, + grad_bin_size, + grad_max_faces_per_bin, + grad_perspective_correct, + grad_clip_barycentric_coords, + grad_cull_backfaces, + ) + return grads + + +def non_square_ndc_range(S1, S2): + """ + In the case of non square images, we scale the NDC range + to maintain the aspect ratio. The smaller dimension has NDC + range of 2.0. + + Args: + S1: dimension along with the NDC range is needed + S2: the other image dimension + + Returns: + ndc_range: NDC range for dimension S1 + """ + ndc_range = 2.0 + if S1 > S2: + ndc_range = (S1 / S2) * ndc_range + return ndc_range + + +def pix_to_non_square_ndc(i, S1, S2): + """ + The default value of the NDC range is [-1, 1]. + However in the case of non square images, we scale the NDC range + to maintain the aspect ratio. The smaller dimension has NDC + range from [-1, 1] and the other dimension is scaled by + the ratio of H:W. + e.g. for image size (H, W) = (64, 128) + Height NDC range: [-1, 1] + Width NDC range: [-2, 2] + + Args: + i: pixel position on axes S1 + S1: dimension along with i is given + S2: the other image dimension + + Returns: + pixel: NDC coordinate of point i for dimension S1 + """ + # NDC: x-offset + (i * pixel_width + half_pixel_width) + ndc_range = non_square_ndc_range(S1, S2) + offset = ndc_range / 2.0 + return -offset + (ndc_range * i + offset) / S1 + + +def rasterize_meshes_python( # noqa: C901 + meshes, + image_size: Union[int, Tuple[int, int]] = 256, + blur_radius: float = 0.0, + faces_per_pixel: int = 8, + perspective_correct: bool = False, + clip_barycentric_coords: bool = False, + cull_backfaces: bool = False, + z_clip_value: Optional[float] = None, + cull_to_frustum: bool = True, + clipped_faces_neighbor_idx: Optional[torch.Tensor] = None, +): + """ + Naive PyTorch implementation of mesh rasterization with the same inputs and + outputs as the rasterize_meshes function. + + This function is not optimized and is implemented as a comparison for the + C++/CUDA implementations. + """ + N = len(meshes) + H, W = image_size if isinstance(image_size, tuple) else (image_size, image_size) + + K = faces_per_pixel + device = meshes.device + + verts_packed = meshes.verts_packed() + faces_packed = meshes.faces_packed() + faces_verts = verts_packed[faces_packed] + mesh_to_face_first_idx = meshes.mesh_to_faces_packed_first_idx() + num_faces_per_mesh = meshes.num_faces_per_mesh() + + if z_clip_value is not None or cull_to_frustum: + # Cull faces outside the view frustum, and clip faces that are partially + # behind the camera into the portion of the triangle in front of the + # camera. This may change the number of faces + frustum = ClipFrustum( + left=-1, + right=1, + top=-1, + bottom=1, + perspective_correct=perspective_correct, + z_clip_value=z_clip_value, + cull=cull_to_frustum, + ) + clipped_faces = clip_faces( + faces_verts, mesh_to_face_first_idx, num_faces_per_mesh, frustum=frustum + ) + faces_verts = clipped_faces.face_verts + mesh_to_face_first_idx = clipped_faces.mesh_to_face_first_idx + num_faces_per_mesh = clipped_faces.num_faces_per_mesh + + # Initialize output tensors. + face_idxs = torch.full( + (N, H, W, K), fill_value=-1, dtype=torch.int64, device=device + ) + zbuf = torch.full((N, H, W, K), fill_value=-1, dtype=torch.float32, device=device) + bary_coords = torch.full( + (N, H, W, K, 3), fill_value=-1, dtype=torch.float32, device=device + ) + pix_dists = torch.full( + (N, H, W, K), fill_value=-1, dtype=torch.float32, device=device + ) + + # Calculate all face bounding boxes. + x_mins = torch.min(faces_verts[:, :, 0], dim=1, keepdim=True).values + x_maxs = torch.max(faces_verts[:, :, 0], dim=1, keepdim=True).values + y_mins = torch.min(faces_verts[:, :, 1], dim=1, keepdim=True).values + y_maxs = torch.max(faces_verts[:, :, 1], dim=1, keepdim=True).values + z_mins = torch.min(faces_verts[:, :, 2], dim=1, keepdim=True).values + + # Expand by blur radius. + x_mins = x_mins - np.sqrt(blur_radius) - kEpsilon + x_maxs = x_maxs + np.sqrt(blur_radius) + kEpsilon + y_mins = y_mins - np.sqrt(blur_radius) - kEpsilon + y_maxs = y_maxs + np.sqrt(blur_radius) + kEpsilon + + # Loop through meshes in the batch. + for n in range(N): + face_start_idx = mesh_to_face_first_idx[n] + face_stop_idx = face_start_idx + num_faces_per_mesh[n] + + # Iterate through the horizontal lines of the image from top to bottom. + for yi in range(H): + # Y coordinate of one end of the image. Reverse the ordering + # of yi so that +Y is pointing up in the image. + yfix = H - 1 - yi + yf = pix_to_non_square_ndc(yfix, H, W) + + # Iterate through pixels on this horizontal line, left to right. + for xi in range(W): + # X coordinate of one end of the image. Reverse the ordering + # of xi so that +X is pointing to the left in the image. + xfix = W - 1 - xi + xf = pix_to_non_square_ndc(xfix, W, H) + top_k_points = [] + + # Check whether each face in the mesh affects this pixel. + for f in range(face_start_idx, face_stop_idx): + face = faces_verts[f].squeeze() + v0, v1, v2 = face.unbind(0) + + face_area = edge_function(v0, v1, v2) + + # Ignore triangles facing away from the camera. + back_face = face_area < 0 + if cull_backfaces and back_face: + continue + + # Ignore faces which have zero area. + if face_area == 0.0: + continue + + outside_bbox = ( + xf < x_mins[f] + or xf > x_maxs[f] + or yf < y_mins[f] + or yf > y_maxs[f] + ) + + # Faces with at least one vertex behind the camera won't + # render correctly and should be removed or clipped before + # calling the rasterizer + if z_mins[f] < kEpsilon: + continue + + # Check if pixel is outside of face bbox. + if outside_bbox: + continue + + # Compute barycentric coordinates and pixel z distance. + pxy = torch.tensor([xf, yf], dtype=torch.float32, device=device) + + bary = barycentric_coordinates(pxy, v0[:2], v1[:2], v2[:2]) + if perspective_correct: + z0, z1, z2 = v0[2], v1[2], v2[2] + l0, l1, l2 = bary[0], bary[1], bary[2] + top0 = l0 * z1 * z2 + top1 = z0 * l1 * z2 + top2 = z0 * z1 * l2 + bot = top0 + top1 + top2 + bary = torch.stack([top0 / bot, top1 / bot, top2 / bot]) + + # Check if inside before clipping + inside = all(x > 0.0 for x in bary) + + # Barycentric clipping + if clip_barycentric_coords: + bary = barycentric_coordinates_clip(bary) + # use clipped barycentric coords to calculate the z value + pz = bary[0] * v0[2] + bary[1] * v1[2] + bary[2] * v2[2] + + # Check if point is behind the image. + if pz < 0: + continue + + # Calculate signed 2D distance from point to face. + # Points inside the triangle have negative distance. + dist = point_triangle_distance(pxy, v0[:2], v1[:2], v2[:2]) + + # Add an epsilon to prevent errors when comparing distance + # to blur radius. + if not inside and dist >= blur_radius: + continue + + # Handle the case where a face (f) partially behind the image plane is + # clipped to a quadrilateral and then split into two faces (t1, t2). + top_k_idx = -1 + if ( + clipped_faces_neighbor_idx is not None + and clipped_faces_neighbor_idx[f] != -1 + ): + neighbor_idx = clipped_faces_neighbor_idx[f] + # See if neighbor_idx is in top_k and find index + top_k_idx = [ + i + for i, val in enumerate(top_k_points) + if val[1] == neighbor_idx + ] + top_k_idx = top_k_idx[0] if len(top_k_idx) > 0 else -1 + + if top_k_idx != -1 and dist < top_k_points[top_k_idx][3]: + # Overwrite the neighbor with current face info + top_k_points[top_k_idx] = (pz, f, bary, dist, inside) + else: + # Handle as a normal face + top_k_points.append((pz, f, bary, dist, inside)) + + top_k_points.sort() + if len(top_k_points) > K: + top_k_points = top_k_points[:K] + + # Save to output tensors. + for k, (pz, f, bary, dist, inside) in enumerate(top_k_points): + zbuf[n, yi, xi, k] = pz + face_idxs[n, yi, xi, k] = f + bary_coords[n, yi, xi, k, 0] = bary[0] + bary_coords[n, yi, xi, k, 1] = bary[1] + bary_coords[n, yi, xi, k, 2] = bary[2] + # Write the signed distance + pix_dists[n, yi, xi, k] = -dist if inside else dist + + if z_clip_value is not None or cull_to_frustum: + # If faces were clipped, map the rasterization result to be in terms of the + # original unclipped faces. This may involve converting barycentric + # coordinates + ( + face_idxs, + bary_coords, + ) = convert_clipped_rasterization_to_original_faces( + face_idxs, + bary_coords, + # pyre-fixme[61]: `clipped_faces` may not be initialized here. + clipped_faces, + ) + + return face_idxs, zbuf, bary_coords, pix_dists + + +def edge_function(p, v0, v1): + r""" + Determines whether a point p is on the right side of a 2D line segment + given by the end points v0, v1. + + Args: + p: (x, y) Coordinates of a point. + v0, v1: (x, y) Coordinates of the end points of the edge. + + Returns: + area: The signed area of the parallelogram given by the vectors + + .. code-block:: python + + B = p - v0 + A = v1 - v0 + + v1 ________ + /\ / + A / \ / + / \ / + v0 /______\/ + B p + + The area can also be interpreted as the cross product A x B. + If the sign of the area is positive, the point p is on the + right side of the edge. Negative area indicates the point is on + the left side of the edge. i.e. for an edge v1 - v0 + + .. code-block:: python + + v1 + / + / + - / + + / + / + v0 + """ + return (p[0] - v0[0]) * (v1[1] - v0[1]) - (p[1] - v0[1]) * (v1[0] - v0[0]) + + +def barycentric_coordinates_clip(bary): + """ + Clip negative barycentric coordinates to 0.0 and renormalize so + the barycentric coordinates for a point sum to 1. When the blur_radius + is greater than 0, a face will still be recorded as overlapping a pixel + if the pixel is outside the face. In this case at least one of the + barycentric coordinates for the pixel relative to the face will be negative. + Clipping will ensure that the texture and z buffer are interpolated correctly. + + Args: + bary: tuple of barycentric coordinates + + Returns + bary_clip: (w0, w1, w2) barycentric coordinates with no negative values. + """ + # Only negative values are clamped to 0.0. + w0_clip = torch.clamp(bary[0], min=0.0) + w1_clip = torch.clamp(bary[1], min=0.0) + w2_clip = torch.clamp(bary[2], min=0.0) + bary_sum = torch.clamp(w0_clip + w1_clip + w2_clip, min=1e-5) + w0_clip = w0_clip / bary_sum + w1_clip = w1_clip / bary_sum + w2_clip = w2_clip / bary_sum + + return (w0_clip, w1_clip, w2_clip) + + +def barycentric_coordinates(p, v0, v1, v2): + """ + Compute the barycentric coordinates of a point relative to a triangle. + + Args: + p: Coordinates of a point. + v0, v1, v2: Coordinates of the triangle vertices. + + Returns + bary: (w0, w1, w2) barycentric coordinates in the range [0, 1]. + """ + area = edge_function(v2, v0, v1) + kEpsilon # 2 x face area. + w0 = edge_function(p, v1, v2) / area + w1 = edge_function(p, v2, v0) / area + w2 = edge_function(p, v0, v1) / area + return (w0, w1, w2) + + +def point_line_distance(p, v0, v1): + """ + Return minimum distance between line segment (v1 - v0) and point p. + + Args: + p: Coordinates of a point. + v0, v1: Coordinates of the end points of the line segment. + + Returns: + non-square distance to the boundary of the triangle. + + Consider the line extending the segment - this can be parameterized as + ``v0 + t (v1 - v0)``. + + First find the projection of point p onto the line. It falls where + ``t = [(p - v0) . (v1 - v0)] / |v1 - v0|^2`` + where . is the dot product. + + The parameter t is clamped from [0, 1] to handle points outside the + segment (v1 - v0). + + Once the projection of the point on the segment is known, the distance from + p to the projection gives the minimum distance to the segment. + """ + if p.shape != v0.shape != v1.shape: + raise ValueError("All points must have the same number of coordinates") + + v1v0 = v1 - v0 + l2 = v1v0.dot(v1v0) # |v1 - v0|^2 + if l2 <= kEpsilon: + return (p - v1).dot(p - v1) # v0 == v1 + + t = v1v0.dot(p - v0) / l2 + t = torch.clamp(t, min=0.0, max=1.0) + p_proj = v0 + t * v1v0 + delta_p = p_proj - p + return delta_p.dot(delta_p) + + +def point_triangle_distance(p, v0, v1, v2): + """ + Return shortest distance between a point and a triangle. + + Args: + p: Coordinates of a point. + v0, v1, v2: Coordinates of the three triangle vertices. + + Returns: + shortest absolute distance from the point to the triangle. + """ + if p.shape != v0.shape != v1.shape != v2.shape: + raise ValueError("All points must have the same number of coordinates") + + e01_dist = point_line_distance(p, v0, v1) + e02_dist = point_line_distance(p, v0, v2) + e12_dist = point_line_distance(p, v1, v2) + edge_dists_min = torch.min(torch.min(e01_dist, e02_dist), e12_dist) + + return edge_dists_min diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/mesh/rasterizer.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/mesh/rasterizer.py new file mode 100644 index 0000000000000000000000000000000000000000..0e5c9f4dd00e96258286c56e28e48585a16a7ab7 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/mesh/rasterizer.py @@ -0,0 +1,273 @@ +# 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. + +# pyre-unsafe + +from dataclasses import dataclass +from typing import Optional, Tuple, Union + +import torch +import torch.nn as nn +from pytorch3d.renderer.cameras import try_get_projection_transform + +from .rasterize_meshes import rasterize_meshes + + +@dataclass(frozen=True) +class Fragments: + """ + A dataclass representing the outputs of a rasterizer. Can be detached from the + computational graph in order to stop the gradients from flowing through the + rasterizer. + + Members: + pix_to_face: + LongTensor of shape (N, image_size, image_size, faces_per_pixel) giving + the indices of the nearest faces at each pixel, sorted in ascending + z-order. Concretely ``pix_to_face[n, y, x, k] = f`` means that + ``faces_verts[f]`` is the kth closest face (in the z-direction) to pixel + (y, x). Pixels that are hit by fewer than faces_per_pixel are padded with + -1. + + zbuf: + FloatTensor of shape (N, image_size, image_size, faces_per_pixel) giving + the NDC z-coordinates of the nearest faces at each pixel, sorted in + ascending z-order. Concretely, if ``pix_to_face[n, y, x, k] = f`` then + ``zbuf[n, y, x, k] = face_verts[f, 2]``. Pixels hit by fewer than + faces_per_pixel are padded with -1. + + bary_coords: + FloatTensor of shape (N, image_size, image_size, faces_per_pixel, 3) + giving the barycentric coordinates in NDC units of the nearest faces at + each pixel, sorted in ascending z-order. Concretely, if ``pix_to_face[n, + y, x, k] = f`` then ``[w0, w1, w2] = barycentric[n, y, x, k]`` gives the + barycentric coords for pixel (y, x) relative to the face defined by + ``face_verts[f]``. Pixels hit by fewer than faces_per_pixel are padded + with -1. + + dists: + FloatTensor of shape (N, image_size, image_size, faces_per_pixel) giving + the signed Euclidean distance (in NDC units) in the x/y plane of each + point closest to the pixel. Concretely if ``pix_to_face[n, y, x, k] = f`` + then ``pix_dists[n, y, x, k]`` is the squared distance between the pixel + (y, x) and the face given by vertices ``face_verts[f]``. Pixels hit with + fewer than ``faces_per_pixel`` are padded with -1. + """ + + pix_to_face: torch.Tensor + zbuf: torch.Tensor + bary_coords: torch.Tensor + dists: Optional[torch.Tensor] + + def detach(self) -> "Fragments": + return Fragments( + pix_to_face=self.pix_to_face, + zbuf=self.zbuf.detach(), + bary_coords=self.bary_coords.detach(), + dists=self.dists.detach() if self.dists is not None else self.dists, + ) + + +@dataclass +class RasterizationSettings: + """ + Class to store the mesh rasterization params with defaults + + Members: + image_size: Either common height and width or (height, width), in pixels. + blur_radius: Float distance in the range [0, 2] used to expand the face + bounding boxes for rasterization. Setting blur radius + results in blurred edges around the shape instead of a + hard boundary. Set to 0 for no blur. + faces_per_pixel: (int) Number of faces to keep track of per pixel. + We return the nearest faces_per_pixel faces along the z-axis. + bin_size: Size of bins to use for coarse-to-fine rasterization. Setting + bin_size=0 uses naive rasterization; setting bin_size=None attempts + to set it heuristically based on the shape of the input. This should + not affect the output, but can affect the speed of the forward pass. + max_faces_opengl: Max number of faces in any mesh we will rasterize. Used only by + MeshRasterizerOpenGL to pre-allocate OpenGL memory. + max_faces_per_bin: Only applicable when using coarse-to-fine + rasterization (bin_size != 0); this is the maximum number of faces + allowed within each bin. This should not affect the output values, + but can affect the memory usage in the forward pass. + Setting max_faces_per_bin=None attempts to set with a heuristic. + perspective_correct: Whether to apply perspective correction when + computing barycentric coordinates for pixels. + None (default) means make correction if the camera uses perspective. + clip_barycentric_coords: Whether, after any perspective correction + is applied but before the depth is calculated (e.g. for + z clipping), to "correct" a location outside the face (i.e. with + a negative barycentric coordinate) to a position on the edge of the + face. None (default) means clip if blur_radius > 0, which is a condition + under which such outside-face-points are likely. + cull_backfaces: Whether to only rasterize mesh faces which are + visible to the camera. This assumes that vertices of + front-facing triangles are ordered in an anti-clockwise + fashion, and triangles that face away from the camera are + in a clockwise order relative to the current view + direction. NOTE: This will only work if the mesh faces are + consistently defined with counter-clockwise ordering when + viewed from the outside. + z_clip_value: if not None, then triangles will be clipped (and possibly + subdivided into smaller triangles) such that z >= z_clip_value. + This avoids camera projections that go to infinity as z->0. + Default is None as clipping affects rasterization speed and + should only be turned on if explicitly needed. + See clip.py for all the extra computation that is required. + cull_to_frustum: Whether to cull triangles outside the view frustum. + Culling involves removing all faces which fall outside view frustum. + Default is False for performance as often not needed. + """ + + image_size: Union[int, Tuple[int, int]] = 256 + blur_radius: float = 0.0 + faces_per_pixel: int = 1 + bin_size: Optional[int] = None + max_faces_opengl: int = 10_000_000 + max_faces_per_bin: Optional[int] = None + perspective_correct: Optional[bool] = None + clip_barycentric_coords: Optional[bool] = None + cull_backfaces: bool = False + z_clip_value: Optional[float] = None + cull_to_frustum: bool = False + + +class MeshRasterizer(nn.Module): + """ + This class implements methods for rasterizing a batch of heterogeneous + Meshes. + """ + + def __init__(self, cameras=None, raster_settings=None) -> None: + """ + Args: + cameras: A cameras object which has a `transform_points` method + which returns the transformed points after applying the + world-to-view and view-to-ndc transformations. + raster_settings: the parameters for rasterization. This should be a + named tuple. + + All these initial settings can be overridden by passing keyword + arguments to the forward function. + """ + super().__init__() + if raster_settings is None: + raster_settings = RasterizationSettings() + + self.cameras = cameras + self.raster_settings = raster_settings + + def to(self, device): + # Manually move to device cameras as it is not a subclass of nn.Module + if self.cameras is not None: + self.cameras = self.cameras.to(device) + return self + + def transform(self, meshes_world, **kwargs) -> torch.Tensor: + """ + Args: + meshes_world: a Meshes object representing a batch of meshes with + vertex coordinates in world space. + + Returns: + meshes_proj: a Meshes object with the vertex positions projected + in NDC space + + NOTE: keeping this as a separate function for readability but it could + be moved into forward. + """ + cameras = kwargs.get("cameras", self.cameras) + if cameras is None: + msg = "Cameras must be specified either at initialization \ + or in the forward pass of MeshRasterizer" + raise ValueError(msg) + + n_cameras = len(cameras) + if n_cameras != 1 and n_cameras != len(meshes_world): + msg = "Wrong number (%r) of cameras for %r meshes" + raise ValueError(msg % (n_cameras, len(meshes_world))) + + verts_world = meshes_world.verts_padded() + + # NOTE: Retaining view space z coordinate for now. + # TODO: Revisit whether or not to transform z coordinate to [-1, 1] or + # [0, 1] range. + eps = kwargs.get("eps", None) + verts_view = cameras.get_world_to_view_transform(**kwargs).transform_points( + verts_world, eps=eps + ) + to_ndc_transform = cameras.get_ndc_camera_transform(**kwargs) + projection_transform = try_get_projection_transform(cameras, kwargs) + if projection_transform is not None: + projection_transform = projection_transform.compose(to_ndc_transform) + verts_ndc = projection_transform.transform_points(verts_view, eps=eps) + else: + # Call transform_points instead of explicitly composing transforms to handle + # the case, where camera class does not have a projection matrix form. + verts_proj = cameras.transform_points(verts_world, eps=eps) + verts_ndc = to_ndc_transform.transform_points(verts_proj, eps=eps) + + verts_ndc[..., 2] = verts_view[..., 2] + meshes_ndc = meshes_world.update_padded(new_verts_padded=verts_ndc) + return meshes_ndc + + def forward(self, meshes_world, **kwargs) -> Fragments: + """ + Args: + meshes_world: a Meshes object representing a batch of meshes with + coordinates in world space. + Returns: + Fragments: Rasterization outputs as a named tuple. + """ + meshes_proj = self.transform(meshes_world, **kwargs) + raster_settings = kwargs.get("raster_settings", self.raster_settings) + + # By default, turn on clip_barycentric_coords if blur_radius > 0. + # When blur_radius > 0, a face can be matched to a pixel that is outside the + # face, resulting in negative barycentric coordinates. + clip_barycentric_coords = raster_settings.clip_barycentric_coords + if clip_barycentric_coords is None: + clip_barycentric_coords = raster_settings.blur_radius > 0.0 + + # If not specified, infer perspective_correct and z_clip_value from the camera + cameras = kwargs.get("cameras", self.cameras) + if raster_settings.perspective_correct is not None: + perspective_correct = raster_settings.perspective_correct + else: + perspective_correct = cameras.is_perspective() + if raster_settings.z_clip_value is not None: + z_clip = raster_settings.z_clip_value + else: + znear = cameras.get_znear() + if isinstance(znear, torch.Tensor): + znear = znear.min().item() + z_clip = None if not perspective_correct or znear is None else znear / 2 + + # By default, turn on clip_barycentric_coords if blur_radius > 0. + # When blur_radius > 0, a face can be matched to a pixel that is outside the + # face, resulting in negative barycentric coordinates. + + pix_to_face, zbuf, bary_coords, dists = rasterize_meshes( + meshes_proj, + image_size=raster_settings.image_size, + blur_radius=raster_settings.blur_radius, + faces_per_pixel=raster_settings.faces_per_pixel, + bin_size=raster_settings.bin_size, + max_faces_per_bin=raster_settings.max_faces_per_bin, + clip_barycentric_coords=clip_barycentric_coords, + perspective_correct=perspective_correct, + cull_backfaces=raster_settings.cull_backfaces, + z_clip_value=z_clip, + cull_to_frustum=raster_settings.cull_to_frustum, + ) + + return Fragments( + pix_to_face=pix_to_face, + zbuf=zbuf, + bary_coords=bary_coords, + dists=dists, + ) diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/mesh/renderer.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/mesh/renderer.py new file mode 100644 index 0000000000000000000000000000000000000000..5b623243a2a5660505fb6476bb31f5d15615d362 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/mesh/renderer.py @@ -0,0 +1,112 @@ +# 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. + +# pyre-unsafe + +from typing import Tuple + +import torch +import torch.nn as nn + +from ...structures.meshes import Meshes + +# A renderer class should be initialized with a +# function for rasterization and a function for shading. +# The rasterizer should: +# - transform inputs from world -> screen space +# - rasterize inputs +# - return fragments +# The shader can take fragments as input along with any other properties of +# the scene and generate images. + +# E.g. rasterize inputs and then shade +# +# fragments = self.rasterize(meshes) +# images = self.shader(fragments, meshes) +# return images + + +class MeshRenderer(nn.Module): + """ + A class for rendering a batch of heterogeneous meshes. The class should + be initialized with a rasterizer (a MeshRasterizer or a MeshRasterizerOpenGL) + and shader class which each have a forward function. + """ + + def __init__(self, rasterizer, shader) -> None: + super().__init__() + self.rasterizer = rasterizer + self.shader = shader + + def to(self, device): + # Rasterizer and shader have submodules which are not of type nn.Module + self.rasterizer.to(device) + self.shader.to(device) + return self + + def forward(self, meshes_world: Meshes, **kwargs) -> torch.Tensor: + """ + Render a batch of images from a batch of meshes by rasterizing and then + shading. + + NOTE: If the blur radius for rasterization is > 0.0, some pixels can + have one or more barycentric coordinates lying outside the range [0, 1]. + For a pixel with out of bounds barycentric coordinates with respect to a + face f, clipping is required before interpolating the texture uv + coordinates and z buffer so that the colors and depths are limited to + the range for the corresponding face. + For this set rasterizer.raster_settings.clip_barycentric_coords=True + """ + fragments = self.rasterizer(meshes_world, **kwargs) + images = self.shader(fragments, meshes_world, **kwargs) + + return images + + +class MeshRendererWithFragments(nn.Module): + """ + A class for rendering a batch of heterogeneous meshes. The class should + be initialized with a rasterizer (a MeshRasterizer or a MeshRasterizerOpenGL) + and shader class which each have a forward function. + + In the forward pass this class returns the `fragments` from which intermediate + values such as the depth map can be easily extracted e.g. + + .. code-block:: python + images, fragments = renderer(meshes) + depth = fragments.zbuf + """ + + def __init__(self, rasterizer, shader) -> None: + super().__init__() + self.rasterizer = rasterizer + self.shader = shader + + def to(self, device): + # Rasterizer and shader have submodules which are not of type nn.Module + self.rasterizer.to(device) + self.shader.to(device) + return self + + def forward( + self, meshes_world: Meshes, **kwargs + ) -> Tuple[torch.Tensor, torch.Tensor]: + """ + Render a batch of images from a batch of meshes by rasterizing and then + shading. + + NOTE: If the blur radius for rasterization is > 0.0, some pixels can + have one or more barycentric coordinates lying outside the range [0, 1]. + For a pixel with out of bounds barycentric coordinates with respect to a + face f, clipping is required before interpolating the texture uv + coordinates and z buffer so that the colors and depths are limited to + the range for the corresponding face. + For this set rasterizer.raster_settings.clip_barycentric_coords=True + """ + fragments = self.rasterizer(meshes_world, **kwargs) + images = self.shader(fragments, meshes_world, **kwargs) + + return images, fragments diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/mesh/shader.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/mesh/shader.py new file mode 100644 index 0000000000000000000000000000000000000000..77aeba91892b02ff91577eb69b4159854e56053e --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/mesh/shader.py @@ -0,0 +1,444 @@ +# 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. + +# pyre-unsafe + +import warnings +from typing import Optional + +import torch +import torch.nn as nn + +from ...common.datatypes import Device +from ...structures.meshes import Meshes +from ..blending import ( + BlendParams, + hard_rgb_blend, + sigmoid_alpha_blend, + softmax_rgb_blend, +) +from ..lighting import PointLights +from ..materials import Materials +from ..splatter_blend import SplatterBlender +from ..utils import TensorProperties +from .rasterizer import Fragments +from .shading import ( + _phong_shading_with_pixels, + flat_shading, + gouraud_shading, + phong_shading, +) + + +# A Shader should take as input fragments from the output of rasterization +# along with scene params and output images. A shader could perform operations +# such as: +# - interpolate vertex attributes for all the fragments +# - sample colors from a texture map +# - apply per pixel lighting +# - blend colors across top K faces per pixel. +class ShaderBase(nn.Module): + def __init__( + self, + device: Device = "cpu", + cameras: Optional[TensorProperties] = None, + lights: Optional[TensorProperties] = None, + materials: Optional[Materials] = None, + blend_params: Optional[BlendParams] = None, + ) -> None: + super().__init__() + self.lights = lights if lights is not None else PointLights(device=device) + self.materials = ( + materials if materials is not None else Materials(device=device) + ) + self.cameras = cameras + self.blend_params = blend_params if blend_params is not None else BlendParams() + + def _get_cameras(self, **kwargs): + cameras = kwargs.get("cameras", self.cameras) + if cameras is None: + msg = "Cameras must be specified either at initialization \ + or in the forward pass of the shader." + raise ValueError(msg) + + return cameras + + # pyre-fixme[14]: `to` overrides method defined in `Module` inconsistently. + def to(self, device: Device): + # Manually move to device modules which are not subclasses of nn.Module + cameras = self.cameras + if cameras is not None: + self.cameras = cameras.to(device) + self.materials = self.materials.to(device) + self.lights = self.lights.to(device) + return self + + +class HardPhongShader(ShaderBase): + """ + Per pixel lighting - the lighting model is applied using the interpolated + coordinates and normals for each pixel. The blending function hard assigns + the color of the closest face for each pixel. + + To use the default values, simply initialize the shader with the desired + device e.g. + + .. code-block:: + + shader = HardPhongShader(device=torch.device("cuda:0")) + """ + + def forward(self, fragments: Fragments, meshes: Meshes, **kwargs) -> torch.Tensor: + cameras = super()._get_cameras(**kwargs) + texels = meshes.sample_textures(fragments) + lights = kwargs.get("lights", self.lights) + materials = kwargs.get("materials", self.materials) + blend_params = kwargs.get("blend_params", self.blend_params) + colors = phong_shading( + meshes=meshes, + fragments=fragments, + texels=texels, + lights=lights, + cameras=cameras, + materials=materials, + ) + images = hard_rgb_blend(colors, fragments, blend_params) + return images + + +class SoftPhongShader(ShaderBase): + """ + Per pixel lighting - the lighting model is applied using the interpolated + coordinates and normals for each pixel. The blending function returns the + soft aggregated color using all the faces per pixel. + + To use the default values, simply initialize the shader with the desired + device e.g. + + .. code-block:: + + shader = SoftPhongShader(device=torch.device("cuda:0")) + """ + + def forward(self, fragments: Fragments, meshes: Meshes, **kwargs) -> torch.Tensor: + cameras = super()._get_cameras(**kwargs) + texels = meshes.sample_textures(fragments) + lights = kwargs.get("lights", self.lights) + materials = kwargs.get("materials", self.materials) + blend_params = kwargs.get("blend_params", self.blend_params) + colors = phong_shading( + meshes=meshes, + fragments=fragments, + texels=texels, + lights=lights, + cameras=cameras, + materials=materials, + ) + znear = kwargs.get("znear", getattr(cameras, "znear", 1.0)) + zfar = kwargs.get("zfar", getattr(cameras, "zfar", 100.0)) + images = softmax_rgb_blend( + colors, fragments, blend_params, znear=znear, zfar=zfar + ) + return images + + +class HardGouraudShader(ShaderBase): + """ + Per vertex lighting - the lighting model is applied to the vertex colors and + the colors are then interpolated using the barycentric coordinates to + obtain the colors for each pixel. The blending function hard assigns + the color of the closest face for each pixel. + + To use the default values, simply initialize the shader with the desired + device e.g. + + .. code-block:: + + shader = HardGouraudShader(device=torch.device("cuda:0")) + """ + + def forward(self, fragments: Fragments, meshes: Meshes, **kwargs) -> torch.Tensor: + cameras = super()._get_cameras(**kwargs) + lights = kwargs.get("lights", self.lights) + materials = kwargs.get("materials", self.materials) + blend_params = kwargs.get("blend_params", self.blend_params) + + # As Gouraud shading applies the illumination to the vertex + # colors, the interpolated pixel texture is calculated in the + # shading step. In comparison, for Phong shading, the pixel + # textures are computed first after which the illumination is + # applied. + pixel_colors = gouraud_shading( + meshes=meshes, + fragments=fragments, + lights=lights, + cameras=cameras, + materials=materials, + ) + images = hard_rgb_blend(pixel_colors, fragments, blend_params) + return images + + +class SoftGouraudShader(ShaderBase): + """ + Per vertex lighting - the lighting model is applied to the vertex colors and + the colors are then interpolated using the barycentric coordinates to + obtain the colors for each pixel. The blending function returns the + soft aggregated color using all the faces per pixel. + + To use the default values, simply initialize the shader with the desired + device e.g. + + .. code-block:: + + shader = SoftGouraudShader(device=torch.device("cuda:0")) + """ + + def forward(self, fragments: Fragments, meshes: Meshes, **kwargs) -> torch.Tensor: + cameras = super()._get_cameras(**kwargs) + lights = kwargs.get("lights", self.lights) + materials = kwargs.get("materials", self.materials) + pixel_colors = gouraud_shading( + meshes=meshes, + fragments=fragments, + lights=lights, + cameras=cameras, + materials=materials, + ) + znear = kwargs.get("znear", getattr(cameras, "znear", 1.0)) + zfar = kwargs.get("zfar", getattr(cameras, "zfar", 100.0)) + images = softmax_rgb_blend( + pixel_colors, fragments, self.blend_params, znear=znear, zfar=zfar + ) + return images + + +def TexturedSoftPhongShader( + device: Device = "cpu", + cameras: Optional[TensorProperties] = None, + lights: Optional[TensorProperties] = None, + materials: Optional[Materials] = None, + blend_params: Optional[BlendParams] = None, +) -> SoftPhongShader: + """ + TexturedSoftPhongShader class has been DEPRECATED. Use SoftPhongShader instead. + Preserving TexturedSoftPhongShader as a function for backwards compatibility. + """ + warnings.warn( + """TexturedSoftPhongShader is now deprecated; + use SoftPhongShader instead.""", + PendingDeprecationWarning, + ) + return SoftPhongShader( + device=device, + cameras=cameras, + lights=lights, + materials=materials, + blend_params=blend_params, + ) + + +class HardFlatShader(ShaderBase): + """ + Per face lighting - the lighting model is applied using the average face + position and the face normal. The blending function hard assigns + the color of the closest face for each pixel. + + To use the default values, simply initialize the shader with the desired + device e.g. + + .. code-block:: + + shader = HardFlatShader(device=torch.device("cuda:0")) + """ + + def forward(self, fragments: Fragments, meshes: Meshes, **kwargs) -> torch.Tensor: + cameras = super()._get_cameras(**kwargs) + texels = meshes.sample_textures(fragments) + lights = kwargs.get("lights", self.lights) + materials = kwargs.get("materials", self.materials) + blend_params = kwargs.get("blend_params", self.blend_params) + colors = flat_shading( + meshes=meshes, + fragments=fragments, + texels=texels, + lights=lights, + cameras=cameras, + materials=materials, + ) + images = hard_rgb_blend(colors, fragments, blend_params) + return images + + +class SoftSilhouetteShader(nn.Module): + """ + Calculate the silhouette by blending the top K faces for each pixel based + on the 2d euclidean distance of the center of the pixel to the mesh face. + + Use this shader for generating silhouettes similar to SoftRasterizer [0]. + + .. note:: + + To be consistent with SoftRasterizer, initialize the + RasterizationSettings for the rasterizer with + `blur_radius = np.log(1. / 1e-4 - 1.) * blend_params.sigma` + + [0] Liu et al, 'Soft Rasterizer: A Differentiable Renderer for Image-based + 3D Reasoning', ICCV 2019 + """ + + def __init__(self, blend_params: Optional[BlendParams] = None) -> None: + super().__init__() + self.blend_params = blend_params if blend_params is not None else BlendParams() + + def forward(self, fragments: Fragments, meshes: Meshes, **kwargs) -> torch.Tensor: + """ + Only want to render the silhouette so RGB values can be ones. + There is no need for lighting or texturing + """ + colors = torch.ones_like(fragments.bary_coords) + blend_params = kwargs.get("blend_params", self.blend_params) + images = sigmoid_alpha_blend(colors, fragments, blend_params) + return images + + +class SplatterPhongShader(ShaderBase): + """ + Per pixel lighting - the lighting model is applied using the interpolated + coordinates and normals for each pixel. The blending function returns the + color aggregated using splats from surrounding pixels (see [0]). + + To use the default values, simply initialize the shader with the desired + device e.g. + + .. code-block:: + + shader = SplatterPhongShader(device=torch.device("cuda:0")) + + [0] Cole, F. et al., "Differentiable Surface Rendering via Non-differentiable + Sampling". + """ + + def __init__(self, **kwargs): + self.splatter_blender = None + super().__init__(**kwargs) + + def to(self, device: Device): + if self.splatter_blender: + self.splatter_blender.to(device) + return super().to(device) + + def forward(self, fragments: Fragments, meshes: Meshes, **kwargs) -> torch.Tensor: + cameras = super()._get_cameras(**kwargs) + texels = meshes.sample_textures(fragments) + lights = kwargs.get("lights", self.lights) + materials = kwargs.get("materials", self.materials) + + colors, pixel_coords_cameras = _phong_shading_with_pixels( + meshes=meshes, + fragments=fragments.detach(), + texels=texels, + lights=lights, + cameras=cameras, + materials=materials, + ) + + if not self.splatter_blender: + # Init only once, to avoid re-computing constants. + N, H, W, K, _ = colors.shape + self.splatter_blender = SplatterBlender((N, H, W, K), colors.device) + + blend_params = kwargs.get("blend_params", self.blend_params) + self.check_blend_params(blend_params) + + images = self.splatter_blender( + colors, + pixel_coords_cameras, + cameras, + fragments.pix_to_face < 0, + kwargs.get("blend_params", self.blend_params), + ) + + return images + + def check_blend_params(self, blend_params): + if blend_params.sigma != 0.5: + warnings.warn( + f"SplatterPhongShader received sigma={blend_params.sigma}. sigma is " + "defined in pixel units, and any value other than 0.5 is highly " + "unexpected. Only use other values if you know what you are doing. " + ) + + +class HardDepthShader(ShaderBase): + """ + Renders the Z distances of the closest face for each pixel. If no face is + found it returns the zfar value of the camera. + + Output from this shader is [N, H, W, 1] since it's only depth. + + To use the default values, simply initialize the shader with the desired + device e.g. + + .. code-block:: + + shader = HardDepthShader(device=torch.device("cuda:0")) + """ + + def forward(self, fragments: Fragments, meshes: Meshes, **kwargs) -> torch.Tensor: + cameras = super()._get_cameras(**kwargs) + + zfar = kwargs.get("zfar", getattr(cameras, "zfar", 100.0)) + mask = fragments.pix_to_face[..., 0:1] < 0 + + zbuf = fragments.zbuf[..., 0:1].clone() + zbuf[mask] = zfar + return zbuf + + +class SoftDepthShader(ShaderBase): + """ + Renders the Z distances using an aggregate of the distances of each face + based off of the point distance. If no face is found it returns the zfar + value of the camera. + + Output from this shader is [N, H, W, 1] since it's only depth. + + To use the default values, simply initialize the shader with the desired + device e.g. + + .. code-block:: + + shader = SoftDepthShader(device=torch.device("cuda:0")) + """ + + def forward(self, fragments: Fragments, meshes: Meshes, **kwargs) -> torch.Tensor: + if fragments.dists is None: + raise ValueError("SoftDepthShader requires Fragments.dists to be present.") + + cameras = super()._get_cameras(**kwargs) + + N, H, W, K = fragments.pix_to_face.shape + device = fragments.zbuf.device + mask = fragments.pix_to_face >= 0 + + zfar = kwargs.get("zfar", getattr(cameras, "zfar", 100.0)) + + # Sigmoid probability map based on the distance of the pixel to the face. + prob_map = torch.sigmoid(-fragments.dists / self.blend_params.sigma) * mask + + # append extra face for zfar + dists = torch.cat( + (fragments.zbuf, torch.ones((N, H, W, 1), device=device) * zfar), dim=3 + ) + probs = torch.cat((prob_map, torch.ones((N, H, W, 1), device=device)), dim=3) + + # compute weighting based off of probabilities using cumsum + probs = probs.cumsum(dim=3) + probs = probs.clamp(max=1) + probs = probs.diff(dim=3, prepend=torch.zeros((N, H, W, 1), device=device)) + + return (probs * dists).sum(dim=3).unsqueeze(3) diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/mesh/shading.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/mesh/shading.py new file mode 100644 index 0000000000000000000000000000000000000000..bb113ee12b1682fd6b8e8e9982c2a05562047003 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/mesh/shading.py @@ -0,0 +1,225 @@ +# 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. + +# pyre-unsafe + + +from typing import Tuple + +import torch +from pytorch3d.ops import interpolate_face_attributes + +from .textures import TexturesVertex + + +def _apply_lighting( + points, normals, lights, cameras, materials +) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]: + """ + Args: + points: torch tensor of shape (N, ..., 3) or (P, 3). + normals: torch tensor of shape (N, ..., 3) or (P, 3) + lights: instance of the Lights class. + cameras: instance of the Cameras class. + materials: instance of the Materials class. + + Returns: + ambient_color: same shape as materials.ambient_color + diffuse_color: same shape as the input points + specular_color: same shape as the input points + """ + light_diffuse = lights.diffuse(normals=normals, points=points) + light_specular = lights.specular( + normals=normals, + points=points, + camera_position=cameras.get_camera_center(), + shininess=materials.shininess, + ) + ambient_color = materials.ambient_color * lights.ambient_color + diffuse_color = materials.diffuse_color * light_diffuse + specular_color = materials.specular_color * light_specular + + if normals.dim() == 2 and points.dim() == 2: + # If given packed inputs remove batch dim in output. + return ( + ambient_color.squeeze(), + diffuse_color.squeeze(), + specular_color.squeeze(), + ) + + if ambient_color.ndim != diffuse_color.ndim: + # Reshape from (N, 3) to have dimensions compatible with + # diffuse_color which is of shape (N, H, W, K, 3) + ambient_color = ambient_color[:, None, None, None, :] + return ambient_color, diffuse_color, specular_color + + +def _phong_shading_with_pixels( + meshes, fragments, lights, cameras, materials, texels +) -> Tuple[torch.Tensor, torch.Tensor]: + """ + Apply per pixel shading. First interpolate the vertex normals and + vertex coordinates using the barycentric coordinates to get the position + and normal at each pixel. Then compute the illumination for each pixel. + The pixel color is obtained by multiplying the pixel textures by the ambient + and diffuse illumination and adding the specular component. + + Args: + meshes: Batch of meshes + fragments: Fragments named tuple with the outputs of rasterization + lights: Lights class containing a batch of lights + cameras: Cameras class containing a batch of cameras + materials: Materials class containing a batch of material properties + texels: texture per pixel of shape (N, H, W, K, 3) + + Returns: + colors: (N, H, W, K, 3) + pixel_coords: (N, H, W, K, 3), camera coordinates of each intersection. + """ + verts = meshes.verts_packed() # (V, 3) + faces = meshes.faces_packed() # (F, 3) + vertex_normals = meshes.verts_normals_packed() # (V, 3) + faces_verts = verts[faces] + faces_normals = vertex_normals[faces] + pixel_coords_in_camera = interpolate_face_attributes( + fragments.pix_to_face, fragments.bary_coords, faces_verts + ) + pixel_normals = interpolate_face_attributes( + fragments.pix_to_face, fragments.bary_coords, faces_normals + ) + ambient, diffuse, specular = _apply_lighting( + pixel_coords_in_camera, pixel_normals, lights, cameras, materials + ) + colors = (ambient + diffuse) * texels + specular + return colors, pixel_coords_in_camera + + +def phong_shading( + meshes, fragments, lights, cameras, materials, texels +) -> torch.Tensor: + """ + Apply per pixel shading. First interpolate the vertex normals and + vertex coordinates using the barycentric coordinates to get the position + and normal at each pixel. Then compute the illumination for each pixel. + The pixel color is obtained by multiplying the pixel textures by the ambient + and diffuse illumination and adding the specular component. + + Args: + meshes: Batch of meshes + fragments: Fragments named tuple with the outputs of rasterization + lights: Lights class containing a batch of lights + cameras: Cameras class containing a batch of cameras + materials: Materials class containing a batch of material properties + texels: texture per pixel of shape (N, H, W, K, 3) + + Returns: + colors: (N, H, W, K, 3) + """ + colors, _ = _phong_shading_with_pixels( + meshes, fragments, lights, cameras, materials, texels + ) + return colors + + +def gouraud_shading(meshes, fragments, lights, cameras, materials) -> torch.Tensor: + """ + Apply per vertex shading. First compute the vertex illumination by applying + ambient, diffuse and specular lighting. If vertex color is available, + combine the ambient and diffuse vertex illumination with the vertex color + and add the specular component to determine the vertex shaded color. + Then interpolate the vertex shaded colors using the barycentric coordinates + to get a color per pixel. + + Gouraud shading is only supported for meshes with texture type `TexturesVertex`. + This is because the illumination is applied to the vertex colors. + + Args: + meshes: Batch of meshes + fragments: Fragments named tuple with the outputs of rasterization + lights: Lights class containing a batch of lights parameters + cameras: Cameras class containing a batch of cameras parameters + materials: Materials class containing a batch of material properties + + Returns: + colors: (N, H, W, K, 3) + """ + if not isinstance(meshes.textures, TexturesVertex): + raise ValueError("Mesh textures must be an instance of TexturesVertex") + + faces = meshes.faces_packed() # (F, 3) + verts = meshes.verts_packed() # (V, 3) + verts_normals = meshes.verts_normals_packed() # (V, 3) + verts_colors = meshes.textures.verts_features_packed() # (V, D) + vert_to_mesh_idx = meshes.verts_packed_to_mesh_idx() + + # Format properties of lights and materials so they are compatible + # with the packed representation of the vertices. This transforms + # all tensor properties in the class from shape (N, ...) -> (V, ...) where + # V is the number of packed vertices. If the number of meshes in the + # batch is one then this is not necessary. + if len(meshes) > 1: + lights = lights.clone().gather_props(vert_to_mesh_idx) + cameras = cameras.clone().gather_props(vert_to_mesh_idx) + materials = materials.clone().gather_props(vert_to_mesh_idx) + + # Calculate the illumination at each vertex + ambient, diffuse, specular = _apply_lighting( + verts, verts_normals, lights, cameras, materials + ) + + verts_colors_shaded = verts_colors * (ambient + diffuse) + specular + face_colors = verts_colors_shaded[faces] + colors = interpolate_face_attributes( + fragments.pix_to_face, fragments.bary_coords, face_colors + ) + return colors + + +def flat_shading(meshes, fragments, lights, cameras, materials, texels) -> torch.Tensor: + """ + Apply per face shading. Use the average face position and the face normals + to compute the ambient, diffuse and specular lighting. Apply the ambient + and diffuse color to the pixel color and add the specular component to + determine the final pixel color. + + Args: + meshes: Batch of meshes + fragments: Fragments named tuple with the outputs of rasterization + lights: Lights class containing a batch of lights parameters + cameras: Cameras class containing a batch of cameras parameters + materials: Materials class containing a batch of material properties + texels: texture per pixel of shape (N, H, W, K, 3) + + Returns: + colors: (N, H, W, K, 3) + """ + verts = meshes.verts_packed() # (V, 3) + faces = meshes.faces_packed() # (F, 3) + face_normals = meshes.faces_normals_packed() # (V, 3) + faces_verts = verts[faces] + face_coords = faces_verts.mean(dim=-2) # (F, 3, XYZ) mean xyz across verts + + # Replace empty pixels in pix_to_face with 0 in order to interpolate. + mask = fragments.pix_to_face == -1 + pix_to_face = fragments.pix_to_face.clone() + pix_to_face[mask] = 0 + + N, H, W, K = pix_to_face.shape + idx = pix_to_face.view(N * H * W * K, 1).expand(N * H * W * K, 3) + + # gather pixel coords + pixel_coords = face_coords.gather(0, idx).view(N, H, W, K, 3) + pixel_coords[mask] = 0.0 + # gather pixel normals + pixel_normals = face_normals.gather(0, idx).view(N, H, W, K, 3) + pixel_normals[mask] = 0.0 + + # Calculate the illumination at each face + ambient, diffuse, specular = _apply_lighting( + pixel_coords, pixel_normals, lights, cameras, materials + ) + colors = (ambient + diffuse) * texels + specular + return colors diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/mesh/textures.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/mesh/textures.py new file mode 100644 index 0000000000000000000000000000000000000000..736be41df27c008c5cc2e1b98b2715cbb5409b29 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/mesh/textures.py @@ -0,0 +1,1933 @@ +# 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. + +# pyre-unsafe + +import itertools +import warnings +from typing import Dict, List, Optional, Tuple, TYPE_CHECKING, Union + +import torch +import torch.nn.functional as F +from pytorch3d.ops import interpolate_face_attributes +from pytorch3d.structures.utils import list_to_packed, list_to_padded, padded_to_list +from torch.nn.functional import interpolate + +from .utils import pack_unique_rectangles, PackedRectangle, Rectangle + + +# This file contains classes and helper functions for texturing. +# There are three types of textures: TexturesVertex, TexturesAtlas +# and TexturesUV which inherit from a base textures class TexturesBase. +# +# Each texture class has a method 'sample_textures' to sample a +# value given barycentric coordinates. +# +# All the textures accept either list or padded inputs. The values +# are stored as either per face values (TexturesAtlas, TexturesUV), +# or per face vertex features (TexturesVertex). + + +def _list_to_padded_wrapper( + x: List[torch.Tensor], + pad_size: Union[list, tuple, None] = None, + pad_value: float = 0.0, +) -> torch.Tensor: + r""" + This is a wrapper function for + pytorch3d.structures.utils.list_to_padded function which only accepts + 3-dimensional inputs. + + For this use case, the input x is of shape (F, 3, ...) where only F + is different for each element in the list + + Transforms a list of N tensors each of shape (Mi, ...) into a single tensor + of shape (N, pad_size, ...), or (N, max(Mi), ...) + if pad_size is None. + + Args: + x: list of Tensors + pad_size: int specifying the size of the first dimension + of the padded tensor + pad_value: float value to be used to fill the padded tensor + + Returns: + x_padded: tensor consisting of padded input tensors + """ + N = len(x) + dims = x[0].ndim + reshape_dims = x[0].shape[1:] + D = torch.prod(torch.tensor(reshape_dims)).item() + x_reshaped = [] + for y in x: + if y.ndim != dims and y.shape[1:] != reshape_dims: + msg = ( + "list_to_padded requires tensors to have the same number of dimensions" + ) + raise ValueError(msg) + # pyre-fixme[6]: For 2nd param expected `int` but got `Union[bool, float, int]`. + x_reshaped.append(y.reshape(-1, D)) + x_padded = list_to_padded(x_reshaped, pad_size=pad_size, pad_value=pad_value) + # pyre-fixme[58]: `+` is not supported for operand types `Tuple[int, int]` and + # `Size`. + return x_padded.reshape((N, -1) + reshape_dims) + + +def _padded_to_list_wrapper( + x: torch.Tensor, split_size: Union[list, tuple, None] = None +) -> List[torch.Tensor]: + r""" + This is a wrapper function for pytorch3d.structures.utils.padded_to_list + which only accepts 3-dimensional inputs. + + For this use case, the input x is of shape (N, F, ...) where F + is the number of faces which is different for each tensor in the batch. + + This function transforms a padded tensor of shape (N, M, ...) into a + list of N tensors of shape (Mi, ...) where (Mi) is specified in + split_size(i), or of shape (M,) if split_size is None. + + Args: + x: padded Tensor + split_size: list of ints defining the number of items for each tensor + in the output list. + + Returns: + x_list: a list of tensors + """ + N, M = x.shape[:2] + reshape_dims = x.shape[2:] + D = torch.prod(torch.tensor(reshape_dims)).item() + # pyre-fixme[6]: For 3rd param expected `int` but got `Union[bool, float, int]`. + x_reshaped = x.reshape(N, M, D) + x_list = padded_to_list(x_reshaped, split_size=split_size) + # pyre-fixme[58]: `+` is not supported for operand types `Tuple[typing.Any]` and + # `Size`. + x_list = [xl.reshape((xl.shape[0],) + reshape_dims) for xl in x_list] + return x_list + + +def _pad_texture_maps( + images: Union[Tuple[torch.Tensor], List[torch.Tensor]], align_corners: bool +) -> torch.Tensor: + """ + Pad all texture images so they have the same height and width. + + Args: + images: list of N tensors of shape (H_i, W_i, C) + align_corners: used for interpolation + + Returns: + tex_maps: Tensor of shape (N, max_H, max_W, C) + """ + tex_maps = [] + max_H = 0 + max_W = 0 + for im in images: + h, w, _C = im.shape + if h > max_H: + max_H = h + if w > max_W: + max_W = w + tex_maps.append(im) + max_shape = (max_H, max_W) + + for i, image in enumerate(tex_maps): + if image.shape[:2] != max_shape: + image_BCHW = image.permute(2, 0, 1)[None] + new_image_BCHW = interpolate( + image_BCHW, + size=max_shape, + mode="bilinear", + align_corners=align_corners, + ) + tex_maps[i] = new_image_BCHW[0].permute(1, 2, 0) + tex_maps = torch.stack(tex_maps, dim=0) # (num_tex_maps, max_H, max_W, C) + return tex_maps + + +def _pad_texture_multiple_maps( + multiple_texture_maps: Union[Tuple[torch.Tensor], List[torch.Tensor]], + align_corners: bool, +) -> torch.Tensor: + """ + Pad all texture images so they have the same height and width. + + Args: + images: list of N tensors of shape (M_i, H_i, W_i, C) + M_i : Number of texture maps:w + + align_corners: used for interpolation + + Returns: + tex_maps: Tensor of shape (N, max_M, max_H, max_W, C) + """ + tex_maps = [] + max_M = 0 + max_H = 0 + max_W = 0 + C = 0 + for im in multiple_texture_maps: + m, h, w, C = im.shape + if m > max_M: + max_M = m + if h > max_H: + max_H = h + if w > max_W: + max_W = w + tex_maps.append(im) + max_shape = (max_M, max_H, max_W, C) + max_im_shape = (max_H, max_W) + for i, tms in enumerate(tex_maps): + new_tex_maps = torch.zeros(max_shape) + for j in range(tms.shape[0]): + im = tms[j] + if im.shape[:2] != max_im_shape: + image_BCHW = im.permute(2, 0, 1)[None] + new_image_BCHW = interpolate( + image_BCHW, + size=max_im_shape, + mode="bilinear", + align_corners=align_corners, + ) + new_tex_maps[j] = new_image_BCHW[0].permute(1, 2, 0) + else: + new_tex_maps[j] = im + tex_maps[i] = new_tex_maps + tex_maps = torch.stack(tex_maps, dim=0) # (num_tex_maps, max_H, max_W, C) + return tex_maps + + +# A base class for defining a batch of textures +# with helper methods. +# This is also useful to have so that inside `Meshes` +# we can allow the input textures to be any texture +# type which is an instance of the base class. +class TexturesBase: + def isempty(self): + if self._N is not None and self.valid is not None: + return self._N == 0 or self.valid.eq(False).all() + return False + + def to(self, device): + for k in dir(self): + v = getattr(self, k) + if isinstance(v, (list, tuple)) and all( + torch.is_tensor(elem) for elem in v + ): + v = [elem.to(device) for elem in v] + setattr(self, k, v) + if torch.is_tensor(v) and v.device != device: + setattr(self, k, v.to(device)) + self.device = device + return self + + def _extend(self, N: int, props: List[str]) -> Dict[str, Union[torch.Tensor, List]]: + """ + Create a dict with the specified properties + repeated N times per batch element. + + Args: + N: number of new copies of each texture + in the batch. + props: a List of strings which refer to either + class attributes or class methods which + return tensors or lists. + + Returns: + Dict with the same keys as props. The values are the + extended properties. + """ + if not isinstance(N, int): + raise ValueError("N must be an integer.") + if N <= 0: + raise ValueError("N must be > 0.") + + new_props = {} + for p in props: + t = getattr(self, p) + if callable(t): + t = t() # class method + if t is None: + new_props[p] = None + elif isinstance(t, list): + if not all(isinstance(elem, (int, float)) for elem in t): + raise ValueError("Extend only supports lists of scalars") + t = [[ti] * N for ti in t] + new_props[p] = list(itertools.chain(*t)) + elif torch.is_tensor(t): + new_props[p] = t.repeat_interleave(N, dim=0) + else: + raise ValueError( + f"Property {p} has unsupported type {type(t)}." + "Only tensors and lists are supported." + ) + return new_props + + def _getitem(self, index: Union[int, slice], props: List[str]): + """ + Helper function for __getitem__ + """ + new_props = {} + if isinstance(index, (int, slice)): + for p in props: + t = getattr(self, p) + if callable(t): + t = t() # class method + new_props[p] = t[index] if t is not None else None + elif isinstance(index, list): + index = torch.tensor(index) + if isinstance(index, torch.Tensor): + if index.dtype == torch.bool: + index = index.nonzero() + index = index.squeeze(1) if index.numel() > 0 else index + index = index.tolist() + for p in props: + t = getattr(self, p) + if callable(t): + t = t() # class method + new_props[p] = [t[i] for i in index] if t is not None else None + return new_props + + def sample_textures(self) -> torch.Tensor: + """ + Different texture classes sample textures in different ways + e.g. for vertex textures, the values at each vertex + are interpolated across the face using the barycentric + coordinates. + Each texture class should implement a sample_textures + method to take the `fragments` from rasterization. + Using `fragments.pix_to_face` and `fragments.bary_coords` + this function should return the sampled texture values for + each pixel in the output image. + """ + raise NotImplementedError() + + def submeshes( + self, + vertex_ids_list: List[List[torch.LongTensor]], + faces_ids_list: List[List[torch.LongTensor]], + ) -> "TexturesBase": + """ + Extract sub-textures used for submeshing. + """ + raise NotImplementedError(f"{self.__class__} does not support submeshes") + + def faces_verts_textures_packed(self) -> torch.Tensor: + """ + Returns the texture for each vertex for each face in the mesh. + For N meshes, this function returns sum(Fi)x3xC where Fi is the + number of faces in the i-th mesh and C is the dimensional of + the feature (C = 3 for RGB textures). + You can use the utils function in structures.utils to convert the + packed representation to a list or padded. + """ + raise NotImplementedError() + + def clone(self) -> "TexturesBase": + """ + Each texture class should implement a method + to clone all necessary internal tensors. + """ + raise NotImplementedError() + + def detach(self) -> "TexturesBase": + """ + Each texture class should implement a method + to detach all necessary internal tensors. + """ + raise NotImplementedError() + + def __getitem__(self, index) -> "TexturesBase": + """ + Each texture class should implement a method + to get the texture properties for the + specified elements in the batch. + The TexturesBase._getitem(i) method + can be used as a helper function to retrieve the + class attributes for item i. Then, a new + instance of the child class can be created with + the attributes. + """ + raise NotImplementedError() + + +def Textures( + maps: Optional[Union[List[torch.Tensor], torch.Tensor]] = None, + faces_uvs: Optional[torch.Tensor] = None, + verts_uvs: Optional[torch.Tensor] = None, + verts_rgb: Optional[torch.Tensor] = None, +) -> TexturesBase: + """ + Textures class has been DEPRECATED. + Preserving Textures as a function for backwards compatibility. + + Args: + maps: texture map per mesh. This can either be a list of maps + [(H, W, C)] or a padded tensor of shape (N, H, W, C). + faces_uvs: (N, F, 3) tensor giving the index into verts_uvs for each + vertex in the face. Padding value is assumed to be -1. + verts_uvs: (N, V, 2) tensor giving the uv coordinate per vertex. + verts_rgb: (N, V, C) tensor giving the color per vertex. Padding + value is assumed to be -1. (C=3 for RGB.) + + + Returns: + a Textures class which is an instance of TexturesBase e.g. TexturesUV, + TexturesAtlas, TexturesVertex + + """ + + warnings.warn( + """Textures class is deprecated, + use TexturesUV, TexturesAtlas, TexturesVertex instead. + Textures class will be removed in future releases.""", + PendingDeprecationWarning, + ) + + if faces_uvs is not None and verts_uvs is not None and maps is not None: + return TexturesUV(maps=maps, faces_uvs=faces_uvs, verts_uvs=verts_uvs) + + if verts_rgb is not None: + return TexturesVertex(verts_features=verts_rgb) + + raise ValueError( + "Textures either requires all three of (faces uvs, verts uvs, maps) or verts rgb" + ) + + +class TexturesAtlas(TexturesBase): + def __init__(self, atlas: Union[torch.Tensor, List[torch.Tensor]]) -> None: + """ + A texture representation where each face has a square texture map. + This is based on the implementation from SoftRasterizer [1]. + + Args: + atlas: (N, F, R, R, C) tensor giving the per face texture map. + The atlas can be created during obj loading with the + pytorch3d.io.load_obj function - in the input arguments + set `create_texture_atlas=True`. The atlas will be + returned in aux.texture_atlas. + + + The padded and list representations of the textures are stored + and the packed representations is computed on the fly and + not cached. + + [1] Liu et al, 'Soft Rasterizer: A Differentiable Renderer for Image-based + 3D Reasoning', ICCV 2019 + See also https://github.com/ShichenLiu/SoftRas/issues/21 + """ + if isinstance(atlas, (list, tuple)): + correct_format = all( + ( + torch.is_tensor(elem) + and elem.ndim == 4 + and elem.shape[1] == elem.shape[2] + and elem.shape[1] == atlas[0].shape[1] + ) + for elem in atlas + ) + if not correct_format: + msg = ( + "Expected atlas to be a list of tensors of shape (F, R, R, C) " + "with the same value of R." + ) + raise ValueError(msg) + self._atlas_list = atlas + self._atlas_padded = None + self.device = torch.device("cpu") + + # These values may be overridden when textures is + # passed into the Meshes constructor. For more details + # refer to the __init__ of Meshes. + self._N = len(atlas) + self._num_faces_per_mesh = [len(a) for a in atlas] + + if self._N > 0: + self.device = atlas[0].device + + elif torch.is_tensor(atlas): + if atlas.ndim != 5: + msg = "Expected atlas to be of shape (N, F, R, R, C); got %r" + raise ValueError(msg % repr(atlas.ndim)) + self._atlas_padded = atlas + self._atlas_list = None + self.device = atlas.device + + # These values may be overridden when textures is + # passed into the Meshes constructor. For more details + # refer to the __init__ of Meshes. + self._N = len(atlas) + max_F = atlas.shape[1] + self._num_faces_per_mesh = [max_F] * self._N + else: + raise ValueError("Expected atlas to be a tensor or list") + + # The num_faces_per_mesh, N and valid + # are reset inside the Meshes object when textures is + # passed into the Meshes constructor. For more details + # refer to the __init__ of Meshes. + self.valid = torch.ones((self._N,), dtype=torch.bool, device=self.device) + + def clone(self) -> "TexturesAtlas": + tex = self.__class__(atlas=self.atlas_padded().clone()) + if self._atlas_list is not None: + tex._atlas_list = [atlas.clone() for atlas in self._atlas_list] + num_faces = ( + self._num_faces_per_mesh.clone() + if torch.is_tensor(self._num_faces_per_mesh) + else self._num_faces_per_mesh + ) + tex.valid = self.valid.clone() + tex._num_faces_per_mesh = num_faces + return tex + + def detach(self) -> "TexturesAtlas": + tex = self.__class__(atlas=self.atlas_padded().detach()) + if self._atlas_list is not None: + tex._atlas_list = [atlas.detach() for atlas in self._atlas_list] + num_faces = ( + self._num_faces_per_mesh.detach() + if torch.is_tensor(self._num_faces_per_mesh) + else self._num_faces_per_mesh + ) + tex.valid = self.valid.detach() + tex._num_faces_per_mesh = num_faces + return tex + + def __getitem__(self, index) -> "TexturesAtlas": + props = ["atlas_list", "_num_faces_per_mesh"] + new_props = self._getitem(index, props=props) + atlas = new_props["atlas_list"] + if isinstance(atlas, list): + # multiple batch elements + new_tex = self.__class__(atlas=atlas) + elif torch.is_tensor(atlas): + # single element + new_tex = self.__class__(atlas=[atlas]) + else: + raise ValueError("Not all values are provided in the correct format") + new_tex._num_faces_per_mesh = new_props["_num_faces_per_mesh"] + return new_tex + + def atlas_padded(self) -> torch.Tensor: + if self._atlas_padded is None: + if self.isempty(): + self._atlas_padded = torch.zeros( + (self._N, 0, 0, 0, 3), dtype=torch.float32, device=self.device + ) + else: + self._atlas_padded = _list_to_padded_wrapper( + self._atlas_list, pad_value=0.0 + ) + return self._atlas_padded + + def atlas_list(self) -> List[torch.Tensor]: + if self._atlas_list is None: + if self.isempty(): + self._atlas_padded = [ + torch.empty((0, 0, 0, 3), dtype=torch.float32, device=self.device) + ] * self._N + self._atlas_list = _padded_to_list_wrapper( + self._atlas_padded, split_size=self._num_faces_per_mesh + ) + return self._atlas_list + + def atlas_packed(self) -> torch.Tensor: + if self.isempty(): + return torch.zeros( + (self._N, 0, 0, 3), dtype=torch.float32, device=self.device + ) + atlas_list = self.atlas_list() + return list_to_packed(atlas_list)[0] + + def extend(self, N: int) -> "TexturesAtlas": + new_props = self._extend(N, ["atlas_padded", "_num_faces_per_mesh"]) + new_tex = self.__class__(atlas=new_props["atlas_padded"]) + new_tex._num_faces_per_mesh = new_props["_num_faces_per_mesh"] + return new_tex + + # pyre-fixme[14]: `sample_textures` overrides method defined in `TexturesBase` + # inconsistently. + def sample_textures(self, fragments, **kwargs) -> torch.Tensor: + """ + This is similar to a nearest neighbor sampling and involves a + discretization step. The barycentric coordinates from + rasterization are used to find the nearest grid cell in the texture + atlas and the RGB is returned as the color. + This means that this step is differentiable with respect to the RGB + values of the texture atlas but not differentiable with respect to the + barycentric coordinates. + + TODO: Add a different sampling mode which interpolates the barycentric + coordinates to sample the texture and will be differentiable w.r.t + the barycentric coordinates. + + Args: + fragments: + The outputs of rasterization. From this we use + + - pix_to_face: LongTensor of shape (N, H, W, K) specifying the indices + of the faces (in the packed representation) which + overlap each pixel in the image. + - barycentric_coords: FloatTensor of shape (N, H, W, K, 3) specifying + the barycentric coordinates of each pixel + relative to the faces (in the packed + representation) which overlap the pixel. + + Returns: + texels: (N, H, W, K, C) + """ + N, H, W, K = fragments.pix_to_face.shape + atlas_packed = self.atlas_packed() + R = atlas_packed.shape[1] + bary = fragments.bary_coords + pix_to_face = fragments.pix_to_face + + bary_w01 = bary[..., :2] + # pyre-fixme[16]: `bool` has no attribute `__getitem__`. + mask = (pix_to_face < 0)[..., None] + bary_w01 = torch.where(mask, torch.zeros_like(bary_w01), bary_w01) + # If barycentric coordinates are > 1.0 (in the case of + # blur_radius > 0.0), wxy might be > R. We need to clamp this + # index to R-1 to index into the texture atlas. + w_xy = (bary_w01 * R).to(torch.int64).clamp(max=R - 1) # (N, H, W, K, 2) + + below_diag = ( + bary_w01.sum(dim=-1) * R - w_xy.float().sum(dim=-1) + ) <= 1.0 # (N, H, W, K) + w_x, w_y = w_xy.unbind(-1) + w_x = torch.where(below_diag, w_x, (R - 1 - w_x)) + w_y = torch.where(below_diag, w_y, (R - 1 - w_y)) + + texels = atlas_packed[pix_to_face, w_y, w_x] + texels = texels * (pix_to_face >= 0)[..., None].float() + + return texels + + def submeshes( + self, + vertex_ids_list: List[List[torch.LongTensor]], + faces_ids_list: List[List[torch.LongTensor]], + ) -> "TexturesAtlas": + """ + Extract a sub-texture for use in a submesh. + + If the meshes batch corresponding to this TextureAtlas contains + `n = len(faces_ids_list)` meshes, then self.atlas_list() + will be of length n. After submeshing, we obtain a batch of + `k = sum(len(v) for v in atlas_list` submeshes (see Meshes.submeshes). This + function creates a corresponding TexturesAtlas object with `atlas_list` + of length `k`. + """ + if len(faces_ids_list) != len(self.atlas_list()): + raise IndexError( + "faces_ids_list must be of " "the same length as atlas_list." + ) + + sub_features = [] + for atlas, faces_ids in zip(self.atlas_list(), faces_ids_list): + for faces_ids_submesh in faces_ids: + sub_features.append(atlas[faces_ids_submesh]) + + return self.__class__(sub_features) + + def faces_verts_textures_packed(self) -> torch.Tensor: + """ + Samples texture from each vertex for each face in the mesh. + For N meshes with {Fi} number of faces, it returns a + tensor of shape sum(Fi)x3xC (C = 3 for RGB). + You can use the utils function in structures.utils to convert the + packed representation to a list or padded. + """ + atlas_packed = self.atlas_packed() + # assume each face consists of (v0, v1, v2). + # to sample from the atlas we only need the first two barycentric coordinates. + # for details on how this texture sample works refer to the sample_textures function. + t0 = atlas_packed[:, 0, -1] # corresponding to v0 with bary = (1, 0) + t1 = atlas_packed[:, -1, 0] # corresponding to v1 with bary = (0, 1) + t2 = atlas_packed[:, 0, 0] # corresponding to v2 with bary = (0, 0) + return torch.stack((t0, t1, t2), dim=1) + + def join_batch(self, textures: List["TexturesAtlas"]) -> "TexturesAtlas": + """ + Join the list of textures given by `textures` to + self to create a batch of textures. Return a new + TexturesAtlas object with the combined textures. + + Args: + textures: List of TexturesAtlas objects + + Returns: + new_tex: TexturesAtlas object with the combined + textures from self and the list `textures`. + """ + tex_types_same = all(isinstance(tex, TexturesAtlas) for tex in textures) + if not tex_types_same: + raise ValueError("All textures must be of type TexturesAtlas.") + + atlas_list = [] + atlas_list += self.atlas_list() + num_faces_per_mesh = self._num_faces_per_mesh.copy() + for tex in textures: + atlas_list += tex.atlas_list() + num_faces_per_mesh += tex._num_faces_per_mesh + new_tex = self.__class__(atlas=atlas_list) + new_tex._num_faces_per_mesh = num_faces_per_mesh + return new_tex + + def join_scene(self) -> "TexturesAtlas": + """ + Return a new TexturesAtlas amalgamating the batch. + """ + return self.__class__(atlas=[torch.cat(self.atlas_list())]) + + def check_shapes( + self, batch_size: int, max_num_verts: int, max_num_faces: int + ) -> bool: + """ + Check if the dimensions of the atlas match that of the mesh faces + """ + # (N, F) should be the same + return self.atlas_padded().shape[0:2] == (batch_size, max_num_faces) + + +class TexturesUV(TexturesBase): + def __init__( + self, + maps: Union[torch.Tensor, List[torch.Tensor]], + faces_uvs: Union[torch.Tensor, List[torch.Tensor], Tuple[torch.Tensor]], + verts_uvs: Union[torch.Tensor, List[torch.Tensor], Tuple[torch.Tensor]], + *, + maps_ids: Optional[ + Union[torch.Tensor, List[torch.Tensor], Tuple[torch.Tensor]] + ] = None, + padding_mode: str = "border", + align_corners: bool = True, + sampling_mode: str = "bilinear", + ) -> None: + """ + Textures are represented as a per mesh texture map and uv coordinates for each + vertex in each face. NOTE: this class only supports one texture map per mesh. + + Args: + maps: Either (1) a texture map per mesh. This can either be a list of maps + [(H, W, C)] or a padded tensor of shape (N, H, W, C). + For RGB, C = 3. In this case maps_ids must be None. + Or (2) a set of M texture maps per mesh. This can either be a list of sets + [(M, H, W, C)] or a padded tensor of shape (N, M, H, W, C). + For RGB, C = 3. In this case maps_ids must be provided to + identify which is relevant to each face. + faces_uvs: (N, F, 3) LongTensor giving the index into verts_uvs + for each face + verts_uvs: (N, V, 2) tensor giving the uv coordinates per vertex + (a FloatTensor with values between 0 and 1). + maps_ids: Used if there are to be multiple maps per face. This can be either a list of map_ids [(F,)] + or a long tensor of shape (N, F) giving the id of the texture map + for each face. If maps_ids is present, the maps has an extra dimension M + (so maps_padded is (N, M, H, W, C) and maps_list has elements of + shape (M, H, W, C)). + Specifically, the color + of a vertex V is given by an average of maps_padded[i, maps_ids[i, f], u, v, :] + over u and v integers adjacent to + _verts_uvs_padded[i, _faces_uvs_padded[i, f, 0], :] . + align_corners: If true, the extreme values 0 and 1 for verts_uvs + indicate the centers of the edge pixels in the maps. + padding_mode: padding mode for outside grid values + ("zeros", "border" or "reflection"). + sampling_mode: type of interpolation used to sample the texture. + Corresponds to the mode parameter in PyTorch's + grid_sample ("nearest" or "bilinear"). + + The align_corners and padding_mode arguments correspond to the arguments + of the `grid_sample` torch function. There is an informative illustration of + the two align_corners options at + https://discuss.pytorch.org/t/22663/9 . + + An example of how the indexing into the maps, with align_corners=True, + works is as follows. + If maps[i] has shape [1001, 101] and the value of verts_uvs[i][j] + is [0.4, 0.3], then a value of j in faces_uvs[i] means a vertex + whose color is given by maps[i][700, 40]. padding_mode affects what + happens if a value in verts_uvs is less than 0 or greater than 1. + Note that increasing a value in verts_uvs[..., 0] increases an index + in maps, whereas increasing a value in verts_uvs[..., 1] _decreases_ + an _earlier_ index in maps. + + If align_corners=False, an example would be as follows. + If maps[i] has shape [1000, 100] and the value of verts_uvs[i][j] + is [0.405, 0.2995], then a value of j in faces_uvs[i] means a vertex + whose color is given by maps[i][700, 40]. + When align_corners=False, padding_mode even matters for values in + verts_uvs slightly above 0 or slightly below 1. In this case, the + padding_mode matters if the first value is outside the interval + [0.0005, 0.9995] or if the second is outside the interval + [0.005, 0.995]. + """ + self.padding_mode = padding_mode + self.align_corners = align_corners + self.sampling_mode = sampling_mode + if isinstance(faces_uvs, (list, tuple)): + for fv in faces_uvs: + if fv.ndim != 2 or fv.shape[-1] != 3: + msg = "Expected faces_uvs to be of shape (F, 3); got %r" + raise ValueError(msg % repr(fv.shape)) + self._faces_uvs_list = faces_uvs + self._faces_uvs_padded = None + self.device = torch.device("cpu") + + # These values may be overridden when textures is + # passed into the Meshes constructor. For more details + # refer to the __init__ of Meshes. + self._N = len(faces_uvs) + self._num_faces_per_mesh = [len(fv) for fv in faces_uvs] + + if self._N > 0: + self.device = faces_uvs[0].device + + elif torch.is_tensor(faces_uvs): + if faces_uvs.ndim != 3 or faces_uvs.shape[-1] != 3: + msg = "Expected faces_uvs to be of shape (N, F, 3); got %r" + raise ValueError(msg % repr(faces_uvs.shape)) + self._faces_uvs_padded = faces_uvs + self._faces_uvs_list = None + self.device = faces_uvs.device + + # These values may be overridden when textures is + # passed into the Meshes constructor. For more details + # refer to the __init__ of Meshes. + self._N = len(faces_uvs) + max_F = faces_uvs.shape[1] + self._num_faces_per_mesh = [max_F] * self._N + else: + raise ValueError("Expected faces_uvs to be a tensor or list") + + if isinstance(verts_uvs, (list, tuple)): + for fv in verts_uvs: + if fv.ndim != 2 or fv.shape[-1] != 2: + msg = "Expected verts_uvs to be of shape (V, 2); got %r" + raise ValueError(msg % repr(fv.shape)) + self._verts_uvs_list = verts_uvs + self._verts_uvs_padded = None + + if len(verts_uvs) != self._N: + raise ValueError( + "verts_uvs and faces_uvs must have the same batch dimension" + ) + if not all(v.device == self.device for v in verts_uvs): + raise ValueError("verts_uvs and faces_uvs must be on the same device") + + elif torch.is_tensor(verts_uvs): + if ( + verts_uvs.ndim != 3 + or verts_uvs.shape[-1] != 2 + or verts_uvs.shape[0] != self._N + ): + msg = "Expected verts_uvs to be of shape (N, V, 2); got %r" + raise ValueError(msg % repr(verts_uvs.shape)) + self._verts_uvs_padded = verts_uvs + self._verts_uvs_list = None + + if verts_uvs.device != self.device: + raise ValueError("verts_uvs and faces_uvs must be on the same device") + else: + raise ValueError("Expected verts_uvs to be a tensor or list") + + self._maps_ids_padded, self._maps_ids_list = self._format_maps_ids(maps_ids) + + if isinstance(maps, (list, tuple)): + self._maps_list = maps + else: + self._maps_list = None + self._maps_padded = self._format_maps_padded(maps) + + if self._maps_padded.device != self.device: + raise ValueError("maps must be on the same device as verts/faces uvs.") + self.valid = torch.ones((self._N,), dtype=torch.bool, device=self.device) + + def _format_maps_ids( + self, + maps_ids: Optional[ + Union[torch.Tensor, List[torch.Tensor], Tuple[torch.Tensor]] + ], + ) -> Tuple[ + Optional[torch.Tensor], Optional[Union[List[torch.Tensor], Tuple[torch.Tensor]]] + ]: + if maps_ids is None: + return None, None + elif isinstance(maps_ids, (list, tuple)): + for mid in maps_ids: + if mid.ndim != 1: + msg = "Expected maps_ids to be of shape (F,); got %r" + raise ValueError(msg % repr(mid.shape)) + if len(maps_ids) != self._N: + raise ValueError( + "map_ids, faces_uvs and verts_uvs must have the same batch dimension" + ) + if not all(mid.device == self.device for mid in maps_ids): + raise ValueError( + "maps_ids and verts/faces uvs must be on the same device" + ) + + if not all( + mid.shape[0] == nfm + for mid, nfm in zip(maps_ids, self._num_faces_per_mesh) + ): + raise ValueError( + "map_ids and faces_uvs must have the same number of faces per mesh" + ) + if not all(mid.device == self.device for mid in maps_ids): + raise ValueError( + "maps_ids and verts/faces uvs must be on the same device" + ) + if not self._num_faces_per_mesh: + return torch.Tensor(), maps_ids + return list_to_padded(maps_ids, pad_value=0), maps_ids + elif isinstance(maps_ids, torch.Tensor): + if maps_ids.ndim != 2 or maps_ids.shape[0] != self._N: + msg = "Expected maps_ids to be of shape (N, F); got %r" + raise ValueError(msg % repr(maps_ids.shape)) + maps_ids_padded = maps_ids + max_F = max(self._num_faces_per_mesh) + if not maps_ids.shape[1] == max_F: + raise ValueError( + "map_ids and faces_uvs must have the same number of faces per mesh" + ) + if maps_ids.device != self.device: + raise ValueError( + "maps_ids and verts/faces uvs must be on the same device" + ) + return maps_ids_padded, None + raise ValueError("Expected maps_ids to be a tensor or list") + + def _format_maps_padded( + self, maps: Union[torch.Tensor, List[torch.Tensor]] + ) -> torch.Tensor: + maps_ids_none = self._maps_ids_padded is None + if isinstance(maps, torch.Tensor): + if not maps_ids_none: + if maps.ndim != 5 or maps.shape[0] != self._N: + msg = "Expected maps to be of shape (N, M, H, W, C); got %r" + raise ValueError(msg % repr(maps.shape)) + elif maps.ndim != 4 or maps.shape[0] != self._N: + msg = "Expected maps to be of shape (N, H, W, C); got %r" + raise ValueError(msg % repr(maps.shape)) + return maps + + if isinstance(maps, (list, tuple)): + if len(maps) != self._N: + raise ValueError("Expected one texture map per mesh in the batch.") + if self._N > 0: + ndim = 3 if maps_ids_none else 4 + if not all(map.ndim == ndim for map in maps): + raise ValueError("Invalid number of dimensions in texture maps") + if not all(map.shape[-1] == maps[0].shape[-1] for map in maps): + raise ValueError("Inconsistent number of channels in maps") + maps_padded = ( + _pad_texture_maps(maps, align_corners=self.align_corners) + if maps_ids_none + else _pad_texture_multiple_maps( + maps, align_corners=self.align_corners + ) + ) + else: + if maps_ids_none: + maps_padded = torch.empty( + (self._N, 0, 0, 3), dtype=torch.float32, device=self.device + ) + else: + maps_padded = torch.empty( + (self._N, 0, 0, 0, 3), dtype=torch.float32, device=self.device + ) + return maps_padded + + raise ValueError("Expected maps to be a tensor or list of tensors.") + + def clone(self) -> "TexturesUV": + tex = self.__class__( + self.maps_padded().clone(), + self.faces_uvs_padded().clone(), + self.verts_uvs_padded().clone(), + maps_ids=( + self._maps_ids_padded.clone() + if self._maps_ids_padded is not None + else None + ), + align_corners=self.align_corners, + padding_mode=self.padding_mode, + sampling_mode=self.sampling_mode, + ) + if self._maps_list is not None: + tex._maps_list = [m.clone() for m in self._maps_list] + if self._verts_uvs_list is not None: + tex._verts_uvs_list = [v.clone() for v in self._verts_uvs_list] + if self._faces_uvs_list is not None: + tex._faces_uvs_list = [f.clone() for f in self._faces_uvs_list] + if self._maps_ids_list is not None: + tex._maps_ids_list = [f.clone() for f in self._maps_ids_list] + num_faces = ( + self._num_faces_per_mesh.clone() + if torch.is_tensor(self._num_faces_per_mesh) + else self._num_faces_per_mesh + ) + tex._num_faces_per_mesh = num_faces + tex.valid = self.valid.clone() + return tex + + def detach(self) -> "TexturesUV": + tex = self.__class__( + self.maps_padded().detach(), + self.faces_uvs_padded().detach(), + self.verts_uvs_padded().detach(), + maps_ids=( + self._maps_ids_padded.detach() + if self._maps_ids_padded is not None + else None + ), + align_corners=self.align_corners, + padding_mode=self.padding_mode, + sampling_mode=self.sampling_mode, + ) + if self._maps_list is not None: + tex._maps_list = [m.detach() for m in self._maps_list] + if self._verts_uvs_list is not None: + tex._verts_uvs_list = [v.detach() for v in self._verts_uvs_list] + if self._faces_uvs_list is not None: + tex._faces_uvs_list = [f.detach() for f in self._faces_uvs_list] + if self._maps_ids_list is not None: + tex._maps_ids_list = [mi.detach() for mi in self._maps_ids_list] + num_faces = ( + self._num_faces_per_mesh.detach() + if torch.is_tensor(self._num_faces_per_mesh) + else self._num_faces_per_mesh + ) + tex._num_faces_per_mesh = num_faces + tex.valid = self.valid.detach() + return tex + + def __getitem__(self, index) -> "TexturesUV": + props = [ + "faces_uvs_list", + "verts_uvs_list", + "maps_list", + "maps_ids_list", + "_num_faces_per_mesh", + ] + new_props = self._getitem(index, props) + faces_uvs = new_props["faces_uvs_list"] + verts_uvs = new_props["verts_uvs_list"] + maps = new_props["maps_list"] + maps_ids = new_props["maps_ids_list"] + + # if index has multiple values then faces/verts/maps may be a list of tensors + if all(isinstance(f, (list, tuple)) for f in [faces_uvs, verts_uvs, maps]): + if maps_ids is not None and not isinstance(maps_ids, (list, tuple)): + raise ValueError( + "Maps ids are not in the correct format expected list or tuple" + ) + new_tex = self.__class__( + faces_uvs=faces_uvs, + verts_uvs=verts_uvs, + maps=maps, + maps_ids=maps_ids, + padding_mode=self.padding_mode, + align_corners=self.align_corners, + sampling_mode=self.sampling_mode, + ) + elif all(torch.is_tensor(f) for f in [faces_uvs, verts_uvs, maps]): + if maps_ids is not None and not torch.is_tensor(maps_ids): + raise ValueError( + "Maps ids are not in the correct format expected tensor" + ) + new_tex = self.__class__( + faces_uvs=[faces_uvs], + verts_uvs=[verts_uvs], + maps=[maps], + maps_ids=[maps_ids] if maps_ids is not None else None, + padding_mode=self.padding_mode, + align_corners=self.align_corners, + sampling_mode=self.sampling_mode, + ) + else: + raise ValueError("Not all values are provided in the correct format") + new_tex._num_faces_per_mesh = new_props["_num_faces_per_mesh"] + return new_tex + + def faces_uvs_padded(self) -> torch.Tensor: + if self._faces_uvs_padded is None: + if self.isempty(): + self._faces_uvs_padded = torch.zeros( + (self._N, 0, 3), dtype=torch.float32, device=self.device + ) + else: + self._faces_uvs_padded = list_to_padded( + self._faces_uvs_list, pad_value=0.0 + ) + return self._faces_uvs_padded + + def faces_uvs_list(self) -> List[torch.Tensor]: + if self._faces_uvs_list is None: + if self.isempty(): + self._faces_uvs_list = [ + torch.empty((0, 3), dtype=torch.float32, device=self.device) + ] * self._N + else: + self._faces_uvs_list = padded_to_list( + self._faces_uvs_padded, split_size=self._num_faces_per_mesh + ) + return self._faces_uvs_list + + def verts_uvs_padded(self) -> torch.Tensor: + if self._verts_uvs_padded is None: + if self.isempty(): + self._verts_uvs_padded = torch.zeros( + (self._N, 0, 2), dtype=torch.float32, device=self.device + ) + else: + self._verts_uvs_padded = list_to_padded( + self._verts_uvs_list, pad_value=0.0 + ) + return self._verts_uvs_padded + + def verts_uvs_list(self) -> List[torch.Tensor]: + if self._verts_uvs_list is None: + if self.isempty(): + self._verts_uvs_list = [ + torch.empty((0, 2), dtype=torch.float32, device=self.device) + ] * self._N + else: + # The number of vertices in the mesh and in verts_uvs can differ + # e.g. if a vertex is shared between 3 faces, it can + # have up to 3 different uv coordinates. + self._verts_uvs_list = list(self._verts_uvs_padded.unbind(0)) + return self._verts_uvs_list + + def maps_ids_padded(self) -> Optional[torch.Tensor]: + return self._maps_ids_padded + + def maps_ids_list(self) -> Optional[List[torch.Tensor]]: + if self._maps_ids_list is not None: + return self._maps_ids_list + elif self._maps_ids_padded is not None: + return self._maps_ids_padded.unbind(0) + else: + return None + + # Currently only the padded maps are used. + def maps_padded(self) -> torch.Tensor: + return self._maps_padded + + def maps_list(self) -> List[torch.Tensor]: + if self._maps_list is not None: + return self._maps_list + return self._maps_padded.unbind(0) + + def extend(self, N: int) -> "TexturesUV": + new_props = self._extend( + N, + [ + "maps_padded", + "verts_uvs_padded", + "faces_uvs_padded", + "maps_ids_padded", + "_num_faces_per_mesh", + ], + ) + new_tex = self.__class__( + maps=new_props["maps_padded"], + faces_uvs=new_props["faces_uvs_padded"], + verts_uvs=new_props["verts_uvs_padded"], + maps_ids=new_props["maps_ids_padded"], + padding_mode=self.padding_mode, + align_corners=self.align_corners, + sampling_mode=self.sampling_mode, + ) + + new_tex._num_faces_per_mesh = new_props["_num_faces_per_mesh"] + return new_tex + + # pyre-fixme[14]: `sample_textures` overrides method defined in `TexturesBase` + # inconsistently. + def sample_textures(self, fragments, **kwargs) -> torch.Tensor: + """ + Interpolate a 2D texture map using uv vertex texture coordinates for each + face in the mesh. First interpolate the vertex uvs using barycentric coordinates + for each pixel in the rasterized output. Then interpolate the texture map + using the uv coordinate for each pixel. + + Args: + fragments: + The outputs of rasterization. From this we use + + - pix_to_face: LongTensor of shape (N, H, W, K) specifying the indices + of the faces (in the packed representation) which + overlap each pixel in the image. + - barycentric_coords: FloatTensor of shape (N, H, W, K, 3) specifying + the barycentric coordinates of each pixel + relative to the faces (in the packed + representation) which overlap the pixel. + + Returns: + texels: tensor of shape (N, H, W, K, C) giving the interpolated + texture for each pixel in the rasterized image. + """ + if self.isempty(): + faces_verts_uvs = torch.zeros( + (self._N, 3, 2), dtype=torch.float32, device=self.device + ) + else: + packing_list = [ + i[j] for i, j in zip(self.verts_uvs_list(), self.faces_uvs_list()) + ] + faces_verts_uvs = torch.cat(packing_list) + + # pixel_uvs: (N, H, W, K, 2) + pixel_uvs = interpolate_face_attributes( + fragments.pix_to_face, fragments.bary_coords, faces_verts_uvs + ) + + N, H_out, W_out, K = fragments.pix_to_face.shape + + texture_maps = self.maps_padded() + maps_ids_padded = self.maps_ids_padded() + if maps_ids_padded is None: + # pixel_uvs: (N, H, W, K, 2) -> (N, K, H, W, 2) -> (NK, H, W, 2) + pixel_uvs = pixel_uvs.permute(0, 3, 1, 2, 4).reshape(N * K, H_out, W_out, 2) + N, H_in, W_in, C = texture_maps.shape # 3 for RGB + + # textures.map: + # (N, H, W, C) -> (N, C, H, W) -> (1, N, C, H, W) + # -> expand (K, N, C, H, W) -> reshape (N*K, C, H, W) + texture_maps = ( + texture_maps.permute(0, 3, 1, 2)[None, ...] + .expand(K, -1, -1, -1, -1) + .transpose(0, 1) + .reshape(N * K, C, H_in, W_in) + ) + # Textures: (N*K, C, H, W), pixel_uvs: (N*K, H, W, 2) + # Now need to format the pixel uvs and the texture map correctly! + # From pytorch docs, grid_sample takes `grid` and `input`: + # grid specifies the sampling pixel locations normalized by + # the input spatial dimensions It should have most + # values in the range of [-1, 1]. Values x = -1, y = -1 + # is the left-top pixel of input, and values x = 1, y = 1 is the + # right-bottom pixel of input. + + # map to a range of [-1, 1] and flip the y axis + pixel_uvs = torch.lerp( + pixel_uvs.new_tensor([-1.0, 1.0]), + pixel_uvs.new_tensor([1.0, -1.0]), + pixel_uvs, + ) + + if texture_maps.device != pixel_uvs.device: + texture_maps = texture_maps.to(pixel_uvs.device) + texels = F.grid_sample( + texture_maps, + pixel_uvs, + mode=self.sampling_mode, + align_corners=self.align_corners, + padding_mode=self.padding_mode, + ) + # texels now has shape (NK, C, H_out, W_out) + texels = texels.reshape(N, K, C, H_out, W_out).permute(0, 3, 4, 1, 2) + return texels + else: + # We have maps_ids_padded: (N, F), textures_map: (N, M, Hi, Wi, C),fragmenmts.pix_to_face: (N, Ho, Wo, K) + # Get pixel_to_map_ids: (N, K, Ho, Wo) by indexing pix_to_face into maps_ids + N, M, H_in, W_in, C = texture_maps.shape # 3 for RGB + + mask = fragments.pix_to_face < 0 + pix_to_face = fragments.pix_to_face.clone() + pix_to_face[mask] = 0 + + pixel_to_map_ids = ( + maps_ids_padded.flatten() + .gather(0, pix_to_face.flatten()) + .view(N, K, H_out, W_out) + ) + + # Normalize between -1 and 1 with M (number of maps) + pixel_to_map_ids = (2.0 * pixel_to_map_ids.float() / float(M - 1)) - 1 + pixel_uvs = pixel_uvs.permute(0, 3, 1, 2, 4) + pixel_uvs = torch.lerp( + pixel_uvs.new_tensor([-1.0, 1.0]), + pixel_uvs.new_tensor([1.0, -1.0]), + pixel_uvs, + ) + + # N x H_out x W_out x K x 3 + pixel_uvms = torch.cat((pixel_uvs, pixel_to_map_ids.unsqueeze(4)), dim=4) + # (N, M, H, W, C) -> (N, C, M, H, W) + texture_maps = texture_maps.permute(0, 4, 1, 2, 3) + if texture_maps.device != pixel_uvs.device: + texture_maps = texture_maps.to(pixel_uvs.device) + texels = F.grid_sample( + texture_maps, + pixel_uvms, + mode=self.sampling_mode, + align_corners=self.align_corners, + padding_mode=self.padding_mode, + ) + # (N, C, K, H_out, W_out) -> (N, H_out, W_out, K, C) + texels = texels.permute(0, 3, 4, 2, 1).contiguous() + return texels + + def faces_verts_textures_packed(self) -> torch.Tensor: + """ + Samples texture from each vertex and for each face in the mesh. + For N meshes with {Fi} number of faces, it returns a + tensor of shape sum(Fi)x3xC (C = 3 for RGB). + You can use the utils function in structures.utils to convert the + packed representation to a list or padded. + """ + if self.isempty(): + return torch.zeros( + (0, 3, self.maps_padded().shape[-1]), + dtype=torch.float32, + device=self.device, + ) + else: + packing_list = [ + i[j] for i, j in zip(self.verts_uvs_list(), self.faces_uvs_list()) + ] + faces_verts_uvs = _list_to_padded_wrapper( + packing_list, pad_value=0.0 + ) # Nxmax(Fi)x3x2 + # map to a range of [-1, 1] and flip the y axis + faces_verts_uvs = torch.lerp( + faces_verts_uvs.new_tensor([-1.0, 1.0]), + faces_verts_uvs.new_tensor([1.0, -1.0]), + faces_verts_uvs, + ) + texture_maps = self.maps_padded() # NxHxWxC or NxMxHxWxC + maps_ids_padded = self.maps_ids_padded() + if maps_ids_padded is None: + texture_maps = texture_maps.permute(0, 3, 1, 2) # NxCxHxW + else: + M = texture_maps.shape[1] + # (N, M, H, W, C) -> (N, C, M, H, W) + texture_maps = texture_maps.permute(0, 4, 1, 2, 3) + # expand maps_ids to (N, F, 3, 1) + maps_ids_padded = maps_ids_padded[:, :, None, None].expand(-1, -1, 3, -1) + maps_ids_padded = (2.0 * maps_ids_padded.float() / float(M - 1)) - 1.0 + + # (N, F, 3, 2+1) -> (N, 1, F, 3, 3) + faces_verts_uvs = torch.cat( + (faces_verts_uvs, maps_ids_padded), dim=3 + ).unsqueeze(1) + # (N, M, H, W, C) -> (N, C, H, W, M) + # texture_maps = texture_maps.permute(0, 4, 2, 3, 1) + textures = F.grid_sample( + texture_maps, + faces_verts_uvs, + mode=self.sampling_mode, + align_corners=self.align_corners, + padding_mode=self.padding_mode, + ) # (N, C, max(Fi), 3) + if maps_ids_padded is not None: + textures = textures.squeeze(dim=2) + # (N, C, max(Fi), 3) -> (N, max(Fi), 3, C) + textures = textures.permute(0, 2, 3, 1) + textures = _padded_to_list_wrapper( + textures, split_size=self._num_faces_per_mesh + ) # list of N {Fix3xC} tensors + return list_to_packed(textures)[0] + + def join_batch(self, textures: List["TexturesUV"]) -> "TexturesUV": + """ + Join the list of textures given by `textures` to + self to create a batch of textures. Return a new + TexturesUV object with the combined textures. + + Args: + textures: List of TexturesUV objects + + Returns: + new_tex: TexturesUV object with the combined + textures from self and the list `textures`. + """ + if self.maps_ids_padded() is not None: + # TODO + raise NotImplementedError( + "join_batch does not support TexturesUV with multiple maps" + ) + tex_types_same = all(isinstance(tex, TexturesUV) for tex in textures) + if not tex_types_same: + raise ValueError("All textures must be of type TexturesUV.") + + padding_modes_same = all( + tex.padding_mode == self.padding_mode for tex in textures + ) + if not padding_modes_same: + raise ValueError("All textures must have the same padding_mode.") + align_corners_same = all( + tex.align_corners == self.align_corners for tex in textures + ) + if not align_corners_same: + raise ValueError("All textures must have the same align_corners value.") + sampling_mode_same = all( + tex.sampling_mode == self.sampling_mode for tex in textures + ) + if not sampling_mode_same: + raise ValueError("All textures must have the same sampling_mode.") + + verts_uvs_list = [] + faces_uvs_list = [] + maps_list = [] + faces_uvs_list += self.faces_uvs_list() + verts_uvs_list += self.verts_uvs_list() + maps_list += self.maps_list() + num_faces_per_mesh = self._num_faces_per_mesh.copy() + for tex in textures: + verts_uvs_list += tex.verts_uvs_list() + faces_uvs_list += tex.faces_uvs_list() + num_faces_per_mesh += tex._num_faces_per_mesh + maps_list += tex.maps_list() + + new_tex = self.__class__( + maps=maps_list, + faces_uvs=faces_uvs_list, + verts_uvs=verts_uvs_list, + padding_mode=self.padding_mode, + align_corners=self.align_corners, + sampling_mode=self.sampling_mode, + ) + new_tex._num_faces_per_mesh = num_faces_per_mesh + return new_tex + + def _place_map_into_single_map( + self, single_map: torch.Tensor, map_: torch.Tensor, location: PackedRectangle + ) -> None: + """ + Copy map into a larger tensor single_map at the destination specified by location. + If align_corners is False, we add the needed border around the destination. + + Used by join_scene. + + Args: + single_map: (total_H, total_W, C) + map_: (H, W, C) source data + location: where to place map + """ + do_flip = location.flipped + source = map_.transpose(0, 1) if do_flip else map_ + border_width = 0 if self.align_corners else 1 + lower_u = location.x + border_width + lower_v = location.y + border_width + upper_u = lower_u + source.shape[0] + upper_v = lower_v + source.shape[1] + single_map[lower_u:upper_u, lower_v:upper_v] = source + + if self.padding_mode != "zeros" and not self.align_corners: + single_map[lower_u - 1, lower_v:upper_v] = single_map[ + lower_u, lower_v:upper_v + ] + single_map[upper_u, lower_v:upper_v] = single_map[ + upper_u - 1, lower_v:upper_v + ] + single_map[lower_u:upper_u, lower_v - 1] = single_map[ + lower_u:upper_u, lower_v + ] + single_map[lower_u:upper_u, upper_v] = single_map[ + lower_u:upper_u, upper_v - 1 + ] + single_map[lower_u - 1, lower_v - 1] = single_map[lower_u, lower_v] + single_map[lower_u - 1, upper_v] = single_map[lower_u, upper_v - 1] + single_map[upper_u, lower_v - 1] = single_map[upper_u - 1, lower_v] + single_map[upper_u, upper_v] = single_map[upper_u - 1, upper_v - 1] + + def join_scene(self) -> "TexturesUV": + """ + Return a new TexturesUV amalgamating the batch. + + We calculate a large single map which contains the original maps, + and find verts_uvs to point into it. This will not replicate + behavior of padding for verts_uvs values outside [0,1]. + + If align_corners=False, we need to add an artificial border around + every map. + + We use the function `pack_unique_rectangles` to provide a layout for + the single map. This means that if self was created with a list of maps, + and to() has not been called, and there were two maps which were exactly + the same tensor object, then they will become the same data in the unified map. + _place_map_into_single_map is used to copy the maps into the single map. + The merging of verts_uvs and faces_uvs is handled locally in this function. + """ + if self.maps_ids_padded() is not None: + # TODO + raise NotImplementedError("join_scene does not support multiple maps.") + maps = self.maps_list() + heights_and_widths = [] + extra_border = 0 if self.align_corners else 2 + for map_ in maps: + heights_and_widths.append( + Rectangle( + map_.shape[0] + extra_border, map_.shape[1] + extra_border, id(map_) + ) + ) + merging_plan = pack_unique_rectangles(heights_and_widths) + C = maps[0].shape[-1] + single_map = maps[0].new_zeros((*merging_plan.total_size, C)) + verts_uvs = self.verts_uvs_list() + verts_uvs_merged = [] + + for map_, loc, uvs in zip(maps, merging_plan.locations, verts_uvs): + new_uvs = uvs.clone() + if loc.is_first: + self._place_map_into_single_map(single_map, map_, loc) + do_flip = loc.flipped + x_shape = map_.shape[1] if do_flip else map_.shape[0] + y_shape = map_.shape[0] if do_flip else map_.shape[1] + + if do_flip: + # Here we have flipped / transposed the map. + # In uvs, the y values are decreasing from 1 to 0 and the x + # values increase from 0 to 1. We subtract all values from 1 + # as the x's become y's and the y's become x's. + new_uvs = 1.0 - new_uvs[:, [1, 0]] + if TYPE_CHECKING: + new_uvs = torch.Tensor(new_uvs) + + # If align_corners is True, then an index of x (where x is in + # the range 0 .. map_.shape[1]-1) in one of the input maps + # was hit by a u of x/(map_.shape[1]-1). + # That x is located at the index loc[1] + x in the single_map, and + # to hit that we need u to equal (loc[1] + x) / (total_size[1]-1) + # so the old u should be mapped to + # { u*(map_.shape[1]-1) + loc[1] } / (total_size[1]-1) + + # Also, an index of y (where y is in + # the range 0 .. map_.shape[0]-1) in one of the input maps + # was hit by a v of 1 - y/(map_.shape[0]-1). + # That y is located at the index loc[0] + y in the single_map, and + # to hit that we need v to equal 1 - (loc[0] + y) / (total_size[0]-1) + # so the old v should be mapped to + # 1 - { (1-v)*(map_.shape[0]-1) + loc[0] } / (total_size[0]-1) + # = + # { v*(map_.shape[0]-1) + total_size[0] - map.shape[0] - loc[0] } + # / (total_size[0]-1) + + # If align_corners is False, then an index of x (where x is in + # the range 1 .. map_.shape[1]-2) in one of the input maps + # was hit by a u of (x+0.5)/(map_.shape[1]). + # That x is located at the index loc[1] + 1 + x in the single_map, + # (where the 1 is for the border) + # and to hit that we need u to equal (loc[1] + 1 + x + 0.5) / (total_size[1]) + # so the old u should be mapped to + # { loc[1] + 1 + u*map_.shape[1]-0.5 + 0.5 } / (total_size[1]) + # = { loc[1] + 1 + u*map_.shape[1] } / (total_size[1]) + + # Also, an index of y (where y is in + # the range 1 .. map_.shape[0]-2) in one of the input maps + # was hit by a v of 1 - (y+0.5)/(map_.shape[0]). + # That y is located at the index loc[0] + 1 + y in the single_map, + # (where the 1 is for the border) + # and to hit that we need v to equal 1 - (loc[0] + 1 + y + 0.5) / (total_size[0]) + # so the old v should be mapped to + # 1 - { loc[0] + 1 + (1-v)*map_.shape[0]-0.5 + 0.5 } / (total_size[0]) + # = { total_size[0] - loc[0] -1 - (1-v)*map_.shape[0] } + # / (total_size[0]) + # = { total_size[0] - loc[0] - map.shape[0] - 1 + v*map_.shape[0] } + # / (total_size[0]) + + # We change the y's in new_uvs for the scaling of height, + # and the x's for the scaling of width. + # That is why the 1's and 0's are mismatched in these lines. + one_if_align = 1 if self.align_corners else 0 + one_if_not_align = 1 - one_if_align + denom_x = merging_plan.total_size[0] - one_if_align + scale_x = x_shape - one_if_align + denom_y = merging_plan.total_size[1] - one_if_align + scale_y = y_shape - one_if_align + new_uvs[:, 1] *= scale_x / denom_x + new_uvs[:, 1] += ( + merging_plan.total_size[0] - x_shape - loc.x - one_if_not_align + ) / denom_x + new_uvs[:, 0] *= scale_y / denom_y + new_uvs[:, 0] += (loc.y + one_if_not_align) / denom_y + + verts_uvs_merged.append(new_uvs) + + faces_uvs_merged = [] + offset = 0 + for faces_uvs_, verts_uvs_ in zip(self.faces_uvs_list(), verts_uvs): + faces_uvs_merged.append(offset + faces_uvs_) + offset += verts_uvs_.shape[0] + + return self.__class__( + maps=[single_map], + faces_uvs=[torch.cat(faces_uvs_merged)], + verts_uvs=[torch.cat(verts_uvs_merged)], + align_corners=self.align_corners, + padding_mode=self.padding_mode, + sampling_mode=self.sampling_mode, + ) + + def centers_for_image(self, index: int) -> torch.Tensor: + """ + Return the locations in the texture map which correspond to the given + verts_uvs, for one of the meshes. This is potentially useful for + visualizing the data. See the texturesuv_image_matplotlib and + texturesuv_image_PIL functions. + + Args: + index: batch index of the mesh whose centers to return. + + Returns: + centers: coordinates of points in the texture image + - a FloatTensor of shape (V,2) + """ + if self.maps_ids_padded() is not None: + # TODO: invent a visualization for the multiple maps case + raise NotImplementedError("This function does not support multiple maps.") + if self._N != 1: + raise ValueError( + "This function only supports plotting textures for one mesh." + ) + texture_image = self.maps_padded() + verts_uvs = self.verts_uvs_list()[index][None] + _, H, W, _3 = texture_image.shape + coord1 = torch.arange(W).expand(H, W) + coord2 = torch.arange(H)[:, None].expand(H, W) + coords = torch.stack([coord1, coord2])[None] + with torch.no_grad(): + # Get xy cartesian coordinates based on the uv coordinates + centers = F.grid_sample( + torch.flip(coords.to(texture_image), [2]), + # Convert from [0, 1] -> [-1, 1] range expected by grid sample + verts_uvs[:, None] * 2.0 - 1, + mode=self.sampling_mode, + align_corners=self.align_corners, + padding_mode=self.padding_mode, + ).cpu() + centers = centers[0, :, 0].T + return centers + + def check_shapes( + self, batch_size: int, max_num_verts: int, max_num_faces: int + ) -> bool: + """ + Check if the dimensions of the verts/faces uvs match that of the mesh + """ + # (N, F) should be the same + # (N, V) is not guaranteed to be the same + return (self.faces_uvs_padded().shape[0:2] == (batch_size, max_num_faces)) and ( + self.verts_uvs_padded().shape[0] == batch_size + ) + + def submeshes( + self, + vertex_ids_list: List[List[torch.LongTensor]], + faces_ids_list: List[List[torch.LongTensor]], + ) -> "TexturesUV": + """ + Extract a sub-texture for use in a submesh. + + If the meshes batch corresponding to this TexturesUV contains + `n = len(faces_ids_list)` meshes, then self.faces_uvs_padded() + will be of length n. After submeshing, we obtain a batch of + `k = sum(len(f) for f in faces_ids_list` submeshes (see Meshes.submeshes). This + function creates a corresponding TexturesUV object with `faces_uvs_padded` + of length `k`. + + Args: + vertex_ids_list: Not used when submeshing TexturesUV. + + face_ids_list: A list of length equal to self.faces_uvs_padded. Each + element is a LongTensor listing the face ids that the submesh keeps in + each respective mesh. + + + Returns: + A "TexturesUV in which faces_uvs_padded, verts_uvs_padded, and maps_padded + have length sum(len(faces) for faces in faces_ids_list) + """ + if self.maps_ids_padded() is not None: + # TODO + raise NotImplementedError("This function does not support multiple maps.") + if len(faces_ids_list) != len(self.faces_uvs_padded()): + raise IndexError( + "faces_uvs_padded must be of " "the same length as face_ids_list." + ) + + sub_faces_uvs, sub_verts_uvs, sub_maps = [], [], [] + for faces_ids, faces_uvs, verts_uvs, map_ in zip( + faces_ids_list, + self.faces_uvs_padded(), + self.verts_uvs_padded(), + self.maps_padded(), + ): + for faces_ids_submesh in faces_ids: + sub_faces_uvs.append(faces_uvs[faces_ids_submesh]) + sub_verts_uvs.append(verts_uvs) + sub_maps.append(map_) + + return self.__class__( + maps=sub_maps, + faces_uvs=sub_faces_uvs, + verts_uvs=sub_verts_uvs, + padding_mode=self.padding_mode, + align_corners=self.align_corners, + sampling_mode=self.sampling_mode, + ) + + +class TexturesVertex(TexturesBase): + def __init__( + self, + verts_features: Union[torch.Tensor, List[torch.Tensor], Tuple[torch.Tensor]], + ) -> None: + """ + Batched texture representation where each vertex in a mesh + has a C dimensional feature vector. + + Args: + verts_features: list of (Vi, C) or (N, V, C) tensor giving a feature + vector with arbitrary dimensions for each vertex. + """ + if isinstance(verts_features, (tuple, list)): + correct_shape = all( + (torch.is_tensor(v) and v.ndim == 2) for v in verts_features + ) + if not correct_shape: + raise ValueError( + "Expected verts_features to be a list of tensors of shape (V, C)." + ) + + self._verts_features_list = verts_features + self._verts_features_padded = None + self.device = torch.device("cpu") + + # These values may be overridden when textures is + # passed into the Meshes constructor. For more details + # refer to the __init__ of Meshes. + self._N = len(verts_features) + self._num_verts_per_mesh = [len(fv) for fv in verts_features] + + if self._N > 0: + self.device = verts_features[0].device + + elif torch.is_tensor(verts_features): + if verts_features.ndim != 3: + msg = "Expected verts_features to be of shape (N, V, C); got %r" + raise ValueError(msg % repr(verts_features.shape)) + self._verts_features_padded = verts_features + self._verts_features_list = None + self.device = verts_features.device + + # These values may be overridden when textures is + # passed into the Meshes constructor. For more details + # refer to the __init__ of Meshes. + self._N = len(verts_features) + max_F = verts_features.shape[1] + self._num_verts_per_mesh = [max_F] * self._N + else: + raise ValueError("verts_features must be a tensor or list of tensors") + + # This is set inside the Meshes object when textures is + # passed into the Meshes constructor. For more details + # refer to the __init__ of Meshes. + self.valid = torch.ones((self._N,), dtype=torch.bool, device=self.device) + + def clone(self) -> "TexturesVertex": + tex = self.__class__(self.verts_features_padded().clone()) + if self._verts_features_list is not None: + tex._verts_features_list = [f.clone() for f in self._verts_features_list] + tex._num_verts_per_mesh = self._num_verts_per_mesh.copy() + tex.valid = self.valid.clone() + return tex + + def detach(self) -> "TexturesVertex": + tex = self.__class__(self.verts_features_padded().detach()) + if self._verts_features_list is not None: + tex._verts_features_list = [f.detach() for f in self._verts_features_list] + tex._num_verts_per_mesh = self._num_verts_per_mesh.copy() + tex.valid = self.valid.detach() + return tex + + def __getitem__(self, index) -> "TexturesVertex": + props = ["verts_features_list", "_num_verts_per_mesh"] + new_props = self._getitem(index, props) + verts_features = new_props["verts_features_list"] + if isinstance(verts_features, list): + # Handle the case of an empty list + if len(verts_features) == 0: + verts_features = torch.empty( + size=(0, 0, 3), + dtype=torch.float32, + device=self.verts_features_padded().device, + ) + new_tex = self.__class__(verts_features=verts_features) + elif torch.is_tensor(verts_features): + new_tex = self.__class__(verts_features=[verts_features]) + else: + raise ValueError("Not all values are provided in the correct format") + new_tex._num_verts_per_mesh = new_props["_num_verts_per_mesh"] + return new_tex + + def verts_features_padded(self) -> torch.Tensor: + if self._verts_features_padded is None: + if self.isempty(): + self._verts_features_padded = torch.zeros( + (self._N, 0, 3, 0), dtype=torch.float32, device=self.device + ) + else: + self._verts_features_padded = list_to_padded( + self._verts_features_list, pad_value=0.0 + ) + return self._verts_features_padded + + def verts_features_list(self) -> List[torch.Tensor]: + if self._verts_features_list is None: + if self.isempty(): + self._verts_features_list = [ + torch.empty((0, 3), dtype=torch.float32, device=self.device) + ] * self._N + else: + self._verts_features_list = padded_to_list( + self._verts_features_padded, split_size=self._num_verts_per_mesh + ) + return self._verts_features_list + + def verts_features_packed(self) -> torch.Tensor: + if self.isempty(): + return torch.zeros((self._N, 3, 0), dtype=torch.float32, device=self.device) + verts_features_list = self.verts_features_list() + return list_to_packed(verts_features_list)[0] + + def extend(self, N: int) -> "TexturesVertex": + new_props = self._extend(N, ["verts_features_padded", "_num_verts_per_mesh"]) + new_tex = self.__class__(verts_features=new_props["verts_features_padded"]) + new_tex._num_verts_per_mesh = new_props["_num_verts_per_mesh"] + return new_tex + + # pyre-fixme[14]: `sample_textures` overrides method defined in `TexturesBase` + # inconsistently. + def sample_textures(self, fragments, faces_packed=None) -> torch.Tensor: + """ + Determine the color for each rasterized face. Interpolate the colors for + vertices which form the face using the barycentric coordinates. + Args: + fragments: + The outputs of rasterization. From this we use + + - pix_to_face: LongTensor of shape (N, H, W, K) specifying the indices + of the faces (in the packed representation) which + overlap each pixel in the image. + - barycentric_coords: FloatTensor of shape (N, H, W, K, 3) specifying + the barycentric coordinates of each pixel + relative to the faces (in the packed + representation) which overlap the pixel. + + Returns: + texels: An texture per pixel of shape (N, H, W, K, C). + There will be one C dimensional value for each element in + fragments.pix_to_face. + """ + verts_features_packed = self.verts_features_packed() + faces_verts_features = verts_features_packed[faces_packed] + + texels = interpolate_face_attributes( + fragments.pix_to_face, fragments.bary_coords, faces_verts_features + ) + return texels + + def submeshes( + self, + vertex_ids_list: List[List[torch.LongTensor]], + faces_ids_list: List[List[torch.LongTensor]], + ) -> "TexturesVertex": + """ + Extract a sub-texture for use in a submesh. + + If the meshes batch corresponding to this TexturesVertex contains + `n = len(vertex_ids_list)` meshes, then self.verts_features_list() + will be of length n. After submeshing, we obtain a batch of + `k = sum(len(v) for v in vertex_ids_list` submeshes (see Meshes.submeshes). This + function creates a corresponding TexturesVertex object with `verts_features_list` + of length `k`. + + Args: + vertex_ids_list: A list of length equal to self.verts_features_list. Each + element is a LongTensor listing the vertices that the submesh keeps in + each respective mesh. + + face_ids_list: Not used when submeshing TexturesVertex. + + Returns: + A TexturesVertex in which verts_features_list has length + sum(len(vertices) for vertices in vertex_ids_list). Each element contains + vertex features corresponding to the subset of vertices in that submesh. + """ + if len(vertex_ids_list) != len(self.verts_features_list()): + raise IndexError( + "verts_features_list must be of " "the same length as vertex_ids_list." + ) + + sub_features = [] + for vertex_ids, features in zip(vertex_ids_list, self.verts_features_list()): + for vertex_ids_submesh in vertex_ids: + sub_features.append(features[vertex_ids_submesh]) + + return self.__class__(sub_features) + + def faces_verts_textures_packed(self, faces_packed=None) -> torch.Tensor: + """ + Samples texture from each vertex and for each face in the mesh. + For N meshes with {Fi} number of faces, it returns a + tensor of shape sum(Fi)x3xC (C = 3 for RGB). + You can use the utils function in structures.utils to convert the + packed representation to a list or padded. + """ + verts_features_packed = self.verts_features_packed() + faces_verts_features = verts_features_packed[faces_packed] + return faces_verts_features + + def join_batch(self, textures: List["TexturesVertex"]) -> "TexturesVertex": + """ + Join the list of textures given by `textures` to + self to create a batch of textures. Return a new + TexturesVertex object with the combined textures. + + Args: + textures: List of TexturesVertex objects + + Returns: + new_tex: TexturesVertex object with the combined + textures from self and the list `textures`. + """ + tex_types_same = all(isinstance(tex, TexturesVertex) for tex in textures) + if not tex_types_same: + raise ValueError("All textures must be of type TexturesVertex.") + + verts_features_list = [] + verts_features_list += self.verts_features_list() + num_verts_per_mesh = self._num_verts_per_mesh.copy() + for tex in textures: + verts_features_list += tex.verts_features_list() + num_verts_per_mesh += tex._num_verts_per_mesh + + new_tex = self.__class__(verts_features=verts_features_list) + new_tex._num_verts_per_mesh = num_verts_per_mesh + return new_tex + + def join_scene(self) -> "TexturesVertex": + """ + Return a new TexturesVertex amalgamating the batch. + """ + return self.__class__(verts_features=[torch.cat(self.verts_features_list())]) + + def check_shapes( + self, batch_size: int, max_num_verts: int, max_num_faces: int + ) -> bool: + """ + Check if the dimensions of the verts features match that of the mesh verts + """ + # (N, V) should be the same + return self.verts_features_padded().shape[:-1] == (batch_size, max_num_verts) diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/mesh/utils.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/mesh/utils.py new file mode 100644 index 0000000000000000000000000000000000000000..73b91c495b0b94a8d70184e526d67ca64ad6db64 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/mesh/utils.py @@ -0,0 +1,320 @@ +# 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. + +# pyre-unsafe + +from typing import List, NamedTuple, Tuple + +import torch +from pytorch3d.ops import interpolate_face_attributes + + +def _clip_barycentric_coordinates(bary) -> torch.Tensor: + """ + Args: + bary: barycentric coordinates of shape (...., 3) where `...` represents + an arbitrary number of dimensions + + Returns: + bary: Barycentric coordinates clipped (i.e any values < 0 are set to 0) + and renormalized. We only clip the negative values. Values > 1 will fall + into the [0, 1] range after renormalization. + The output is the same shape as the input. + """ + if bary.shape[-1] != 3: + msg = "Expected barycentric coords to have last dim = 3; got %r" + raise ValueError(msg % (bary.shape,)) + ndims = bary.ndim - 1 + mask = bary.eq(-1).all(dim=-1, keepdim=True).expand(*((-1,) * ndims + (3,))) + clipped = bary.clamp(min=0.0) + clipped[mask] = 0.0 + clipped_sum = torch.clamp(clipped.sum(dim=-1, keepdim=True), min=1e-5) + clipped = clipped / clipped_sum + clipped[mask] = -1.0 + return clipped + + +def _interpolate_zbuf( + pix_to_face: torch.Tensor, barycentric_coords: torch.Tensor, meshes +) -> torch.Tensor: + """ + A helper function to calculate the z buffer for each pixel in the + rasterized output. + + Args: + pix_to_face: LongTensor of shape (N, H, W, K) specifying the indices + of the faces (in the packed representation) which + overlap each pixel in the image. + barycentric_coords: FloatTensor of shape (N, H, W, K, 3) specifying + the barycentric coordinates of each pixel + relative to the faces (in the packed + representation) which overlap the pixel. + meshes: Meshes object representing a batch of meshes. + + Returns: + zbuffer: (N, H, W, K) FloatTensor + """ + verts = meshes.verts_packed() + faces = meshes.faces_packed() + faces_verts_z = verts[faces][..., 2][..., None] # (F, 3, 1) + zbuf = interpolate_face_attributes(pix_to_face, barycentric_coords, faces_verts_z)[ + ..., 0 + ] # (1, H, W, K) + zbuf[pix_to_face == -1] = -1 + return zbuf + + +# ----------- Rectangle Packing -------------------- # + + +class Rectangle(NamedTuple): + xsize: int + ysize: int + identifier: int + + +class PackedRectangle(NamedTuple): + x: int + y: int + flipped: bool + is_first: bool + + +class PackedRectangles(NamedTuple): + total_size: Tuple[int, int] + locations: List[PackedRectangle] + + +# Note the order of members matters here because it determines the queue order. +# We want to place longer rectangles first. +class _UnplacedRectangle(NamedTuple): + size: Tuple[int, int] + ind: int + flipped: bool + + +def _try_place_rectangle( + rect: _UnplacedRectangle, + placed_so_far: List[PackedRectangle], + occupied: List[Tuple[int, int]], +) -> bool: + """ + Try to place rect within the current bounding box. + Part of the implementation of pack_rectangles. + + Note that the arguments `placed_so_far` and `occupied` are modified. + + Args: + rect: rectangle to place + placed_so_far: the locations decided upon so far - a list of + (x, y, whether flipped). The nth element is the + location of the nth rectangle if it has been decided. + (modified in place) + occupied: the nodes of the graph of extents of rightmost placed + rectangles - (modified in place) + + Returns: + True on success. + + Example: + (We always have placed the first rectangle horizontally and other + rectangles above it.) + Let's say the placed boxes 1-4 are laid out like this. + The coordinates of the points marked X are stored in occupied. + It is to the right of the X's that we seek to place rect. + + +-----------------------X + |2 | + | +---X + | |4 | + | | | + | +---+X + | |3 | + | | | + +-----------------------+----+------X + y |1 | + ^ | --->x | + | +-----------------------------------+ + + We want to place this rectangle. + + +-+ + |5| + | | + | | = rect + | | + | | + | | + +-+ + + The call will succeed, returning True, leaving us with + + +-----------------------X + |2 | +-X + | +---+|5| + | |4 || | + | | || | + | +---++ | + | |3 | | + | | | | + +-----------------------+----+-+----X + |1 | + | | + +-----------------------------------+ . + + """ + total_width = occupied[0][0] + needed_height = rect.size[1] + current_start_idx = None + current_max_width = 0 + previous_height = 0 + currently_packed = 0 + for idx, interval in enumerate(occupied): + if interval[0] <= total_width - rect.size[0]: + currently_packed += interval[1] - previous_height + current_max_width = max(interval[0], current_max_width) + if current_start_idx is None: + current_start_idx = idx + if currently_packed >= needed_height: + current_max_width = max(interval[0], current_max_width) + placed_so_far[rect.ind] = PackedRectangle( + current_max_width, + occupied[current_start_idx - 1][1], + rect.flipped, + True, + ) + new_occupied = ( + current_max_width + rect.size[0], + occupied[current_start_idx - 1][1] + needed_height, + ) + if currently_packed == needed_height: + occupied[idx] = new_occupied + del occupied[current_start_idx:idx] + elif idx > current_start_idx: + occupied[idx - 1] = new_occupied + del occupied[current_start_idx : (idx - 1)] + else: + occupied.insert(idx, new_occupied) + return True + else: + current_start_idx = None + current_max_width = 0 + currently_packed = 0 + previous_height = interval[1] + return False + + +def pack_rectangles(sizes: List[Tuple[int, int]]) -> PackedRectangles: + """ + Naive rectangle packing in to a large rectangle. Flipping (i.e. rotating + a rectangle by 90 degrees) is allowed. + + This is used to join several uv maps into a single scene, see + TexturesUV.join_scene. + + Args: + sizes: List of sizes of rectangles to pack + + Returns: + total_size: size of total large rectangle + rectangles: location for each of the input rectangles. + This includes whether they are flipped. + The is_first field is always True. + """ + + if len(sizes) < 2: + raise ValueError("Cannot pack less than two boxes") + + queue = [] + for i, size in enumerate(sizes): + if size[0] < size[1]: + queue.append(_UnplacedRectangle((size[1], size[0]), i, True)) + else: + queue.append(_UnplacedRectangle((size[0], size[1]), i, False)) + queue.sort() + placed_so_far = [PackedRectangle(-1, -1, False, False)] * len(sizes) + + biggest = queue.pop() + total_width, current_height = biggest.size + placed_so_far[biggest.ind] = PackedRectangle(0, 0, biggest.flipped, True) + + second = queue.pop() + placed_so_far[second.ind] = PackedRectangle(0, current_height, second.flipped, True) + current_height += second.size[1] + occupied = [biggest.size, (second.size[0], current_height)] + + for rect in reversed(queue): + if _try_place_rectangle(rect, placed_so_far, occupied): + continue + + rotated = _UnplacedRectangle( + (rect.size[1], rect.size[0]), rect.ind, not rect.flipped + ) + if _try_place_rectangle(rotated, placed_so_far, occupied): + continue + + # rect wasn't placed in the current bounding box, + # so we add extra space to fit it in. + placed_so_far[rect.ind] = PackedRectangle(0, current_height, rect.flipped, True) + current_height += rect.size[1] + occupied.append((rect.size[0], current_height)) + + return PackedRectangles((total_width, current_height), placed_so_far) + + +def pack_unique_rectangles(rectangles: List[Rectangle]) -> PackedRectangles: + """ + Naive rectangle packing in to a large rectangle. Flipping (i.e. rotating + a rectangle by 90 degrees) is allowed. Inputs are deduplicated by their + identifier. + + This is a wrapper around pack_rectangles, where inputs come with an + identifier. In particular, it calls pack_rectangles for the deduplicated inputs, + then returns the values for all the inputs. The output for all rectangles with + the same identifier will be the same, except that only the first one will have + the is_first field True. + + This is used to join several uv maps into a single scene, see + TexturesUV.join_scene. + + Args: + rectangles: List of sizes of rectangles to pack + + Returns: + total_size: size of total large rectangle + rectangles: location for each of the input rectangles. + This includes whether they are flipped. + The is_first field is true for the first rectangle + with each identifier. + """ + + if len(rectangles) < 2: + raise ValueError("Cannot pack less than two boxes") + + input_map = {} + input_indices: List[Tuple[int, bool]] = [] + unique_input_sizes: List[Tuple[int, int]] = [] + for rectangle in rectangles: + if rectangle.identifier not in input_map: + unique_index = len(unique_input_sizes) + unique_input_sizes.append((rectangle.xsize, rectangle.ysize)) + input_map[rectangle.identifier] = unique_index + input_indices.append((unique_index, True)) + else: + unique_index = input_map[rectangle.identifier] + input_indices.append((unique_index, False)) + + if len(unique_input_sizes) == 1: + first = [PackedRectangle(0, 0, False, True)] + rest = (len(rectangles) - 1) * [PackedRectangle(0, 0, False, False)] + return PackedRectangles(unique_input_sizes[0], first + rest) + + total_size, unique_locations = pack_rectangles(unique_input_sizes) + full_locations = [] + for input_index, first in input_indices: + full_locations.append(unique_locations[input_index]._replace(is_first=first)) + + return PackedRectangles(total_size, full_locations) diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/opengl/__init__.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/opengl/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..388a300907c62c84ff92e7aeba162ded76dbe9f9 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/opengl/__init__.py @@ -0,0 +1,40 @@ +# 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. + +# pyre-unsafe + + +# If we can access EGL, import MeshRasterizerOpenGL. +def _can_import_egl_and_pycuda(): + import os + import warnings + + try: + os.environ["PYOPENGL_PLATFORM"] = "egl" + import OpenGL.EGL + except (AttributeError, ImportError, ModuleNotFoundError): + warnings.warn( + "Can't import EGL, not importing MeshRasterizerOpenGL. This might happen if" + " your Python application imported OpenGL with a non-EGL backend before" + " importing PyTorch3D, or if you don't have pyopengl installed as part" + " of your Python distribution." + ) + return False + + try: + import pycuda.gl + except (ImportError, ImportError, ModuleNotFoundError): + warnings.warn("Can't import pycuda.gl, not importing MeshRasterizerOpenGL.") + return False + + return True + + +if _can_import_egl_and_pycuda(): + from .opengl_utils import EGLContext, global_device_context_store + from .rasterizer_opengl import MeshRasterizerOpenGL + +__all__ = [k for k in globals().keys() if not k.startswith("_")] diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/opengl/opengl_utils.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/opengl/opengl_utils.py new file mode 100644 index 0000000000000000000000000000000000000000..8201b3076482def0c63eb0f48386614cf44f1a1e --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/opengl/opengl_utils.py @@ -0,0 +1,450 @@ +# 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. + +# pyre-unsafe + +# Utilities useful for OpenGL rendering. +# +# NOTE: This module MUST be imported before any other OpenGL modules in this Python +# session, unless you set PYOPENGL_PLATFORM to egl *before* importing other modules. +# Otherwise, the imports below will throw an error. +# +# This module (as well as rasterizer_opengl) will not be imported into pytorch3d if +# you do not have pycuda.gl and pyopengl installed. + +import contextlib +import ctypes +import os +import threading +from typing import Any, Dict + + +os.environ["PYOPENGL_PLATFORM"] = "egl" +import OpenGL.EGL as egl # noqa + +import pycuda.driver as cuda # noqa +from OpenGL._opaque import opaque_pointer_cls # noqa +from OpenGL.raw.EGL._errors import EGLError # noqa + +# A few constants necessary to use EGL extensions, see links for details. + +# https://www.khronos.org/registry/EGL/extensions/EXT/EGL_EXT_platform_device.txt +EGL_PLATFORM_DEVICE_EXT = 0x313F +# https://www.khronos.org/registry/EGL/extensions/NV/EGL_NV_device_cuda.txt +EGL_CUDA_DEVICE_NV = 0x323A + + +# To use EGL extensions, we need to tell OpenGL about them. For details, see +# https://developer.nvidia.com/blog/egl-eye-opengl-visualization-without-x-server/. +# To avoid garbage collection of the protos, we'll store them in a module-global list. +def _define_egl_extension(name: str, type): + if hasattr(egl, name): + return + addr = egl.eglGetProcAddress(name) + if addr is None: + raise RuntimeError(f"Cannot find EGL extension {name}.") + else: + proto = ctypes.CFUNCTYPE(type) + func = proto(addr) + setattr(egl, name, func) + return proto + + +_protos = [] +_protos.append(_define_egl_extension("eglGetPlatformDisplayEXT", egl.EGLDisplay)) +_protos.append(_define_egl_extension("eglQueryDevicesEXT", egl.EGLBoolean)) +_protos.append(_define_egl_extension("eglQueryDeviceAttribEXT", egl.EGLBoolean)) +_protos.append(_define_egl_extension("eglQueryDisplayAttribEXT", egl.EGLBoolean)) +_protos.append(_define_egl_extension("eglQueryDeviceStringEXT", ctypes.c_char_p)) + +if not hasattr(egl, "EGLDeviceEXT"): + egl.EGLDeviceEXT = opaque_pointer_cls("EGLDeviceEXT") + + +def _egl_convert_to_int_array(egl_attributes): + """ + Convert a Python dict of EGL attributes into an array of ints (some of which are + special EGL ints. + + Args: + egl_attributes: A dict where keys are EGL attributes, and values are their vals. + + Returns: + A c-list of length 2 * len(egl_attributes) + 1, of the form [key1, val1, ..., + keyN, valN, EGL_NONE] + """ + attributes_list = sum(([k, v] for k, v in egl_attributes.items()), []) + [ + egl.EGL_NONE + ] + return (egl.EGLint * len(attributes_list))(*attributes_list) + + +def _get_cuda_device(requested_device_id: int): + """ + Find an EGL device with a given CUDA device ID. + + Args: + requested_device_id: The desired CUDA device ID, e.g. "1" for "cuda:1". + + Returns: + EGL device with the desired CUDA ID. + """ + num_devices = egl.EGLint() + if ( + # pyre-ignore Undefined attribute [16] + not egl.eglQueryDevicesEXT(0, None, ctypes.pointer(num_devices)) + or num_devices.value < 1 + ): + raise RuntimeError("EGL requires a system that supports at least one device.") + devices = (egl.EGLDeviceEXT * num_devices.value)() # array of size num_devices + if ( + # pyre-ignore Undefined attribute [16] + not egl.eglQueryDevicesEXT( + num_devices.value, devices, ctypes.pointer(num_devices) + ) + or num_devices.value < 1 + ): + raise RuntimeError("EGL sees no available devices.") + if len(devices) < requested_device_id + 1: + raise ValueError( + f"Device {requested_device_id} not available. Found only {len(devices)} devices." + ) + + # Iterate over all the EGL devices, and check if their CUDA ID matches the request. + for device in devices: + available_device_id = egl.EGLAttrib(ctypes.c_int(-1)) + # pyre-ignore Undefined attribute [16] + egl.eglQueryDeviceAttribEXT(device, EGL_CUDA_DEVICE_NV, available_device_id) + if available_device_id.contents.value == requested_device_id: + return device + raise ValueError( + f"Found {len(devices)} CUDA devices, but none with CUDA id {requested_device_id}." + ) + + +def _get_egl_config(egl_dpy, surface_type): + """ + Get an EGL config with reasonable settings (for use with MeshRasterizerOpenGL). + + Args: + egl_dpy: An EGL display constant (int). + surface_type: An EGL surface_type int. + + Returns: + An EGL config object. + + Throws: + ValueError if the desired config is not available or invalid. + """ + egl_config_dict = { + egl.EGL_RED_SIZE: 8, + egl.EGL_GREEN_SIZE: 8, + egl.EGL_BLUE_SIZE: 8, + egl.EGL_ALPHA_SIZE: 8, + egl.EGL_DEPTH_SIZE: 24, + egl.EGL_STENCIL_SIZE: egl.EGL_DONT_CARE, + egl.EGL_RENDERABLE_TYPE: egl.EGL_OPENGL_BIT, + egl.EGL_SURFACE_TYPE: surface_type, + } + egl_config_array = _egl_convert_to_int_array(egl_config_dict) + egl_config = egl.EGLConfig() + num_configs = egl.EGLint() + if ( + not egl.eglChooseConfig( + egl_dpy, + egl_config_array, + ctypes.pointer(egl_config), + 1, + ctypes.pointer(num_configs), + ) + or num_configs.value == 0 + ): + raise ValueError("Invalid EGL config.") + return egl_config + + +class EGLContext: + """ + A class representing an EGL context. In short, EGL allows us to render OpenGL con- + tent in a headless mode, that is without an actual display to render to. This capa- + bility enables MeshRasterizerOpenGL to render on the GPU and then transfer the re- + sults to PyTorch3D. + """ + + def __init__(self, width: int, height: int, cuda_device_id: int = 0) -> None: + """ + Args: + width: Width of the "display" to render to. + height: Height of the "display" to render to. + cuda_device_id: Device ID to render to, in the CUDA convention (note that + this might be different than EGL's device numbering). + """ + # Lock used to prevent multiple threads from rendering on the same device + # at the same time, creating/destroying contexts at the same time, etc. + self.lock = threading.Lock() + self.cuda_device_id = cuda_device_id + self.device = _get_cuda_device(self.cuda_device_id) + self.width = width + self.height = height + self.dpy = egl.eglGetPlatformDisplayEXT( + EGL_PLATFORM_DEVICE_EXT, self.device, None + ) + major, minor = egl.EGLint(), egl.EGLint() + + # Initialize EGL components: the display, surface, and context + egl.eglInitialize(self.dpy, ctypes.pointer(major), ctypes.pointer(minor)) + + config = _get_egl_config(self.dpy, egl.EGL_PBUFFER_BIT) + pb_surf_attribs = _egl_convert_to_int_array( + { + egl.EGL_WIDTH: width, + egl.EGL_HEIGHT: height, + } + ) + self.surface = egl.eglCreatePbufferSurface(self.dpy, config, pb_surf_attribs) + if self.surface == egl.EGL_NO_SURFACE: + raise RuntimeError("Failed to create an EGL surface.") + + if not egl.eglBindAPI(egl.EGL_OPENGL_API): + raise RuntimeError("Failed to bind EGL to the OpenGL API.") + self.context = egl.eglCreateContext(self.dpy, config, egl.EGL_NO_CONTEXT, None) + if self.context == egl.EGL_NO_CONTEXT: + raise RuntimeError("Failed to create an EGL context.") + + @contextlib.contextmanager + def active_and_locked(self): + """ + A context manager used to make sure a given EGL context is only current in + a single thread at a single time. It is recommended to ALWAYS use EGL within + a `with context.active_and_locked():` context. + + Throws: + EGLError when the context cannot be made current or make non-current. + """ + self.lock.acquire() + egl.eglMakeCurrent(self.dpy, self.surface, self.surface, self.context) + try: + yield + finally: + egl.eglMakeCurrent( + self.dpy, egl.EGL_NO_SURFACE, egl.EGL_NO_SURFACE, egl.EGL_NO_CONTEXT + ) + self.lock.release() + + def get_context_info(self) -> Dict[str, Any]: + """ + Return context info. Useful for debugging. + + Returns: + A dict of keys and ints, representing the context's display, surface, + the context itself, and the current thread. + """ + return { + "dpy": self.dpy, + "surface": self.surface, + "context": self.context, + "thread": threading.get_ident(), + } + + def release(self): + """ + Release the context's resources. + """ + self.lock.acquire() + try: + if self.surface: + egl.eglDestroySurface(self.dpy, self.surface) + if self.context and self.dpy: + egl.eglDestroyContext(self.dpy, self.context) + egl.eglMakeCurrent( + self.dpy, egl.EGL_NO_SURFACE, egl.EGL_NO_SURFACE, egl.EGL_NO_CONTEXT + ) + if self.dpy: + egl.eglTerminate(self.dpy) + except EGLError as err: + print( + f"EGL could not release context on device cuda:{self.cuda_device_id}." + " This can happen if you created two contexts on the same device." + " Instead, you can use DeviceContextStore to use a single context" + " per device, and EGLContext.make_(in)active_in_current_thread to" + " (in)activate the context as needed." + ) + raise err + + egl.eglReleaseThread() + self.lock.release() + + +class _DeviceContextStore: + """ + DeviceContextStore provides thread-safe storage for EGL and pycuda contexts. It + should not be used directly. opengl_utils instantiates a module-global variable + called opengl_utils.global_device_context_store. MeshRasterizerOpenGL uses this + store to avoid unnecessary context creation and destruction. + + The EGL/CUDA contexts are not meant to be created and destroyed all the time, + and having multiple on a single device can be troublesome. Intended use is entirely + transparent to the user:: + + rasterizer1 = MeshRasterizerOpenGL(...some args...) + mesh1 = load_mesh_on_cuda_0() + + # Now rasterizer1 will request EGL/CUDA contexts from + # global_device_context_store on cuda:0, and since there aren't any, the + # store will create new ones. + rasterizer1.rasterize(mesh1) + + # rasterizer2 also needs EGL & CUDA contexts. But global_context_store + # already has them for cuda:0. Instead of creating new contexts, the store + # will tell rasterizer2 to use them. + rasterizer2 = MeshRasterizerOpenGL(dcs) + rasterize2.rasterize(mesh1) + + # When rasterizer1 needs to render on cuda:1, the store will create new contexts. + mesh2 = load_mesh_on_cuda_1() + rasterizer1.rasterize(mesh2) + + """ + + def __init__(self): + cuda.init() + # pycuda contexts, at most one per device. + self._cuda_contexts = {} + # EGL contexts, at most one per device. + self._egl_contexts = {} + # Any extra per-device data (e.g. precompiled GL objects). + self._context_data = {} + # Lock for DeviceContextStore used in multithreaded multidevice scenarios. + self._lock = threading.Lock() + # All EGL contexts created by this store will have this resolution. + self.max_egl_width = 2048 + self.max_egl_height = 2048 + + def get_cuda_context(self, device): + """ + Return a pycuda's CUDA context on a given CUDA device. If we have not created + such a context yet, create a new one and store it in a dict. The context is + popped (you need to call context.push() to start using it). This function + is thread-safe. + + Args: + device: A torch.device. + + Returns: A pycuda context corresponding to the given device. + """ + cuda_device_id = device.index + with self._lock: + if cuda_device_id not in self._cuda_contexts: + self._cuda_contexts[cuda_device_id] = _init_cuda_context(cuda_device_id) + self._cuda_contexts[cuda_device_id].pop() + return self._cuda_contexts[cuda_device_id] + + def get_egl_context(self, device): + """ + Return an EGL context on a given CUDA device. If we have not created such a + context yet, create a new one and store it in a dict. The context if not current + (you should use the `with egl_context.active_and_locked:` context manager when + you need it to be current). This function is thread-safe. + + Args: + device: A torch.device. + + Returns: An EGLContext on the requested device. The context will have size + self.max_egl_width and self.max_egl_height. + """ + cuda_device_id = device.index + with self._lock: + egl_context = self._egl_contexts.get(cuda_device_id, None) + if egl_context is None: + self._egl_contexts[cuda_device_id] = EGLContext( + self.max_egl_width, self.max_egl_height, cuda_device_id + ) + return self._egl_contexts[cuda_device_id] + + def set_context_data(self, device, value): + """ + Set arbitrary data in a per-device dict. + + This function is intended for storing precompiled OpenGL objects separately for + EGL contexts on different devices. Each such context needs a separate compiled + OpenGL program, but (in case e.g. of MeshRasterizerOpenGL) there's no need to + re-compile it each time we move the rasterizer to the same device repeatedly, + as it happens when using DataParallel. + + Args: + device: A torch.device + value: An arbitrary Python object. + """ + + cuda_device_id = device.index + self._context_data[cuda_device_id] = value + + def get_context_data(self, device): + """ + Get arbitrary data in a per-device dict. See set_context_data for more detail. + + Args: + device: A torch.device + + Returns: + The most recent object stored using set_context_data. + """ + cuda_device_id = device.index + return self._context_data.get(cuda_device_id, None) + + def release(self): + """ + Release all CUDA and EGL contexts. + """ + for context in self._cuda_contexts.values(): + context.detach() + + for context in self._egl_contexts.values(): + context.release() + + +def _init_cuda_context(device_id: int = 0): + """ + Initialize a pycuda context on a chosen device. + + Args: + device_id: int, specifies which GPU to use. + + Returns: + A pycuda Context. + """ + # pyre-ignore Undefined attribute [16] + device = cuda.Device(device_id) + cuda_context = device.make_context() + return cuda_context + + +def _torch_to_opengl(torch_tensor, cuda_context, cuda_buffer): + # CUDA access to the OpenGL buffer is only allowed within a map-unmap block. + cuda_context.push() + mapping_obj = cuda_buffer.map() + + # data_ptr points to the OpenGL shader storage buffer memory. + data_ptr, sz = mapping_obj.device_ptr_and_size() + + # Copy the torch tensor to the OpenGL buffer directly on device. + cuda_copy = cuda.Memcpy2D() + cuda_copy.set_src_device(torch_tensor.data_ptr()) + cuda_copy.set_dst_device(data_ptr) + cuda_copy.width_in_bytes = cuda_copy.src_pitch = cuda_copy.dst_ptch = ( + torch_tensor.shape[1] * 4 + ) + cuda_copy.height = torch_tensor.shape[0] + cuda_copy(False) + + # Unmap and pop the cuda context to make sure OpenGL won't interfere with + # PyTorch ops down the line. + mapping_obj.unmap() + cuda_context.pop() + + +# Initialize a global _DeviceContextStore. Almost always we will only need a single one. +global_device_context_store = _DeviceContextStore() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/opengl/rasterizer_opengl.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/opengl/rasterizer_opengl.py new file mode 100644 index 0000000000000000000000000000000000000000..cd1dce0defdb3c64454437ac726b10e910dc461c --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/opengl/rasterizer_opengl.py @@ -0,0 +1,723 @@ +# 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. + +# pyre-unsafe + +# NOTE: This module (as well as rasterizer_opengl) will not be imported into pytorch3d +# if you do not have pycuda.gl and pyopengl installed. In addition, please make sure +# your Python application *does not* import OpenGL before importing PyTorch3D, unless +# you are using the EGL backend. +import warnings +from typing import Optional, Tuple, Union + +import numpy as np +import OpenGL.GL as gl +import pycuda.gl +import torch + +import torch.nn as nn + +from pytorch3d.structures.meshes import Meshes + +from ..cameras import FoVOrthographicCameras, FoVPerspectiveCameras +from ..mesh.rasterizer import Fragments, RasterizationSettings +from ..utils import parse_image_size + +from .opengl_utils import _torch_to_opengl, global_device_context_store + +# Shader strings, used below to compile an OpenGL program. +vertex_shader = """ +// The vertex shader does nothing. +#version 430 + +void main() { } +""" + +geometry_shader = """ +#version 430 + +layout (points) in; +layout (triangle_strip, max_vertices = 3) out; + +out layout (location = 0) vec2 bary_coords; +out layout (location = 1) float depth; +out layout (location = 2) float p2f; + +layout(binding=0) buffer triangular_mesh { float mesh_buffer[]; }; + +uniform mat4 perspective_projection; + +vec3 get_vertex_position(int vertex_index) { + int offset = gl_PrimitiveIDIn * 9 + vertex_index * 3; + return vec3( + mesh_buffer[offset], + mesh_buffer[offset + 1], + mesh_buffer[offset + 2] + ); +} + +void main() { + vec3 positions[3] = { + get_vertex_position(0), + get_vertex_position(1), + get_vertex_position(2) + }; + vec4 projected_vertices[3] = { + perspective_projection * vec4(positions[0], 1.0), + perspective_projection * vec4(positions[1], 1.0), + perspective_projection * vec4(positions[2], 1.0) + }; + + for (int i = 0; i < 3; ++i) { + gl_Position = projected_vertices[i]; + bary_coords = vec2(i==0 ? 1.0 : 0.0, i==1 ? 1.0 : 0.0); + // At the moment, we output depth as the distance from the image plane in + // view coordinates -- NOT distance along the camera ray. + depth = positions[i][2]; + p2f = gl_PrimitiveIDIn; + EmitVertex(); + } + EndPrimitive(); +} +""" + +fragment_shader = """ +#version 430 + +in layout(location = 0) vec2 bary_coords; +in layout(location = 1) float depth; +in layout(location = 2) float p2f; + + +out vec4 bary_depth_p2f; + +void main() { + bary_depth_p2f = vec4(bary_coords, depth, round(p2f)); +} +""" + + +def _parse_and_verify_image_size( + image_size: Union[Tuple[int, int], int], +) -> Tuple[int, int]: + """ + Parse image_size as a tuple of ints. Throw ValueError if the size is incompatible + with the maximum renderable size as set in global_device_context_store. + """ + height, width = parse_image_size(image_size) + max_h = global_device_context_store.max_egl_height + max_w = global_device_context_store.max_egl_width + if height > max_h or width > max_w: + raise ValueError( + f"Max rasterization size is height={max_h}, width={max_w}. " + f"Cannot raster an image of size {height}, {width}. You can change max " + "allowed rasterization size by modifying the MAX_EGL_HEIGHT and " + "MAX_EGL_WIDTH environment variables." + ) + return height, width + + +class MeshRasterizerOpenGL(nn.Module): + """ + EXPERIMENTAL, USE WITH CAUTION + + This class implements methods for rasterizing a batch of heterogeneous + Meshes using OpenGL. This rasterizer, as opposed to MeshRasterizer, is + *not differentiable* and needs to be used with shading methods such as + SplatterPhongShader, which do not require differentiable rasterizerization. + It is, however, faster: on a 2M-faced mesh, about 20x so. + + Fragments output by MeshRasterizerOpenGL and MeshRasterizer should have near + identical pix_to_face, bary_coords and zbuf. However, MeshRasterizerOpenGL does not + return Fragments.dists which is only relevant to SoftPhongShader and + SoftSilhouetteShader. These do not work with MeshRasterizerOpenGL (because it is + not differentiable). + """ + + def __init__( + self, + cameras: Optional[Union[FoVOrthographicCameras, FoVPerspectiveCameras]] = None, + raster_settings=None, + ) -> None: + """ + Args: + cameras: A cameras object which has a `transform_points` method + which returns the transformed points after applying the + world-to-view and view-to-ndc transformations. Currently, only FoV + cameras are supported. + raster_settings: the parameters for rasterization. This should be a + named tuple. + """ + super().__init__() + if raster_settings is None: + raster_settings = RasterizationSettings() + self.raster_settings = raster_settings + _check_raster_settings(self.raster_settings) + self.cameras = cameras + self.image_size = _parse_and_verify_image_size(self.raster_settings.image_size) + + self.opengl_machinery = _OpenGLMachinery( + max_faces=self.raster_settings.max_faces_opengl, + ) + + def forward(self, meshes_world: Meshes, **kwargs) -> Fragments: + """ + Args: + meshes_world: a Meshes object representing a batch of meshes with + coordinates in world space. The batch must live on a GPU. + + Returns: + Fragments: Rasterization outputs as a named tuple. These are different than + Fragments returned by MeshRasterizer in two ways. First, we return no + `dist` which is only relevant to SoftPhongShader which doesn't work + with MeshRasterizerOpenGL (because it is not differentiable). Second, + the zbuf uses the opengl zbuf convention, where the z-vals are between 0 + (at projection plane) and 1 (at clipping distance), and are a non-linear + function of the depth values of the camera ray intersections. In + contrast, MeshRasterizer's zbuf values are simply the distance of each + ray intersection from the camera. + + Throws: + ValueError if meshes_world lives on the CPU. + """ + if meshes_world.device == torch.device("cpu"): + raise ValueError("MeshRasterizerOpenGL works only on CUDA devices.") + + raster_settings = kwargs.get("raster_settings", self.raster_settings) + _check_raster_settings(raster_settings) + + image_size = ( + _parse_and_verify_image_size(raster_settings.image_size) or self.image_size + ) + + # OpenGL needs vertices in NDC coordinates with un-flipped xy directions. + cameras_unpacked = kwargs.get("cameras", self.cameras) + _check_cameras(cameras_unpacked) + meshes_gl_ndc = _convert_meshes_to_gl_ndc( + meshes_world, image_size, cameras_unpacked, **kwargs + ) + + # Perspective projection will happen within the OpenGL rasterizer. + projection_matrix = cameras_unpacked.get_projection_transform(**kwargs)._matrix + + # Run OpenGL rasterization machinery. + pix_to_face, bary_coords, zbuf = self.opengl_machinery( + meshes_gl_ndc, projection_matrix, image_size + ) + + # Return the Fragments and detach, because gradients don't go through OpenGL. + return Fragments( + pix_to_face=pix_to_face, + zbuf=zbuf, + bary_coords=bary_coords, + dists=None, + ).detach() + + def to(self, device): + # Manually move to device cameras as it is not a subclass of nn.Module + if self.cameras is not None: + self.cameras = self.cameras.to(device) + + # Create a new OpenGLMachinery, as its member variables can be tied to a GPU. + self.opengl_machinery = _OpenGLMachinery( + max_faces=self.raster_settings.max_faces_opengl, + ) + + +class _OpenGLMachinery: + """ + A class holding OpenGL machinery used by MeshRasterizerOpenGL. + """ + + def __init__( + self, + max_faces: int = 10_000_000, + ) -> None: + self.max_faces = max_faces + self.program = None + + # These will be created on an appropriate GPU each time we render a new mesh on + # that GPU for the first time. + self.egl_context = None + self.cuda_context = None + self.perspective_projection_uniform = None + self.mesh_buffer_object = None + self.vao = None + self.fbo = None + self.cuda_buffer = None + + def __call__( + self, + meshes_gl_ndc: Meshes, + projection_matrix: torch.Tensor, + image_size: Tuple[int, int], + ) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]: + """ + Rasterize a batch of meshes, using a given batch of projection matrices and + image size. + + Args: + meshes_gl_ndc: A Meshes object, with vertices in the OpenGL NDC convention. + projection_matrix: A 3x3 camera projection matrix, or a tensor of projection + matrices equal in length to the number of meshes in meshes_gl_ndc. + image_size: Image size to rasterize. Must be smaller than the max height and + width stored in global_device_context_store. + + Returns: + pix_to_faces: A BHW1 tensor of ints, filled with -1 where no face projects + to a given pixel. + bary_coords: A BHW3 float tensor, filled with -1 where no face projects to + a given pixel. + zbuf: A BHW1 float tensor, filled with 1 where no face projects to a given + pixel. NOTE: this zbuf uses the opengl zbuf convention, where the z-vals + are between 0 (at projection plane) and 1 (at clipping distance), and + are a non-linear function of the depth values of the camera ray inter- + sections. + """ + + self.initialize_device_data(meshes_gl_ndc.device) + with self.egl_context.active_and_locked(): + # Perspective projection happens in OpenGL. Move the matrix over if there's only + # a single camera shared by all the meshes. + if projection_matrix.shape[0] == 1: + self._projection_matrix_to_opengl(projection_matrix) + + pix_to_faces = [] + bary_coords = [] + zbufs = [] + + # pyre-ignore Incompatible parameter type [6] + for mesh_id, mesh in enumerate(meshes_gl_ndc): + pix_to_face, bary_coord, zbuf = self._rasterize_mesh( + mesh, + image_size, + projection_matrix=( + projection_matrix[mesh_id] + if projection_matrix.shape[0] > 1 + else None + ), + ) + pix_to_faces.append(pix_to_face) + bary_coords.append(bary_coord) + zbufs.append(zbuf) + + return ( + torch.cat(pix_to_faces, dim=0), + torch.cat(bary_coords, dim=0), + torch.cat(zbufs, dim=0), + ) + + def initialize_device_data(self, device) -> None: + """ + Initialize data specific to a GPU device: the EGL and CUDA contexts, the OpenGL + program, as well as various buffer and array objects used to communicate with + OpenGL. + + Args: + device: A torch.device. + """ + self.egl_context = global_device_context_store.get_egl_context(device) + self.cuda_context = global_device_context_store.get_cuda_context(device) + + # self.program represents the OpenGL program we use for rasterization. + if global_device_context_store.get_context_data(device) is None: + with self.egl_context.active_and_locked(): + self.program = self._compile_and_link_gl_program() + self._set_up_gl_program_properties(self.program) + + # Create objects used to transfer data into and out of the program. + ( + self.perspective_projection_uniform, + self.mesh_buffer_object, + self.vao, + self.fbo, + ) = self._prepare_persistent_opengl_objects( + self.program, + self.max_faces, + ) + + # Register the input buffer with pycuda, to transfer data directly into it. + self.cuda_context.push() + self.cuda_buffer = pycuda.gl.RegisteredBuffer( + int(self.mesh_buffer_object), + pycuda.gl.graphics_map_flags.WRITE_DISCARD, + ) + self.cuda_context.pop() + + global_device_context_store.set_context_data( + device, + ( + self.program, + self.perspective_projection_uniform, + self.mesh_buffer_object, + self.vao, + self.fbo, + self.cuda_buffer, + ), + ) + ( + self.program, + self.perspective_projection_uniform, + self.mesh_buffer_object, + self.vao, + self.fbo, + self.cuda_buffer, + ) = global_device_context_store.get_context_data(device) + + def release(self) -> None: + """ + Release CUDA and OpenGL resources. + """ + # Finish all current operations. + torch.cuda.synchronize() + self.cuda_context.synchronize() + + # Free pycuda resources. + self.cuda_context.push() + self.cuda_buffer.unregister() + self.cuda_context.pop() + + # Free GL resources. + gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, self.fbo) + # pyre-fixme[16]: Module `GL_3_0` has no attribute `glDeleteFramebuffers`. + gl.glDeleteFramebuffers(1, [self.fbo]) + gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, 0) + del self.fbo + + gl.glBindBufferBase(gl.GL_SHADER_STORAGE_BUFFER, 0, self.mesh_buffer_object) + # pyre-fixme[16]: Module `GL_1_5` has no attribute `glDeleteBuffers`. + gl.glDeleteBuffers(1, [self.mesh_buffer_object]) + gl.glBindBufferBase(gl.GL_SHADER_STORAGE_BUFFER, 0, 0) + del self.mesh_buffer_object + + gl.glDeleteProgram(self.program) + self.egl_context.release() + + def _projection_matrix_to_opengl(self, projection_matrix: torch.Tensor) -> None: + """ + Transfer a torch projection matrix to OpenGL. + + Args: + projection matrix: A 3x3 float tensor. + """ + gl.glUseProgram(self.program) + # pyre-fixme[16]: Module `GL_2_0` has no attribute `glUniformMatrix4fv`. + gl.glUniformMatrix4fv( + self.perspective_projection_uniform, + 1, + gl.GL_FALSE, + projection_matrix.detach().flatten().cpu().numpy().astype(np.float32), + ) + gl.glUseProgram(0) + + def _rasterize_mesh( + self, + mesh: Meshes, + image_size: Tuple[int, int], + projection_matrix: Optional[torch.Tensor] = None, + ) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]: + """ + Rasterize a single mesh using OpenGL. + + Args: + mesh: A Meshes object, containing a single mesh only. + projection_matrix: A 3x3 camera projection matrix, or a tensor of projection + matrices equal in length to the number of meshes in meshes_gl_ndc. + image_size: Image size to rasterize. Must be smaller than the max height and + width stored in global_device_context_store. + + Returns: + pix_to_faces: A 1HW1 tensor of ints, filled with -1 where no face projects + to a given pixel. + bary_coords: A 1HW3 float tensor, filled with -1 where no face projects to + a given pixel. + zbuf: A 1HW1 float tensor, filled with 1 where no face projects to a given + pixel. NOTE: this zbuf uses the opengl zbuf convention, where the z-vals + are between 0 (at projection plane) and 1 (at clipping distance), and + are a non-linear function of the depth values of the camera ray inter- + sections. + """ + height, width = image_size + # Extract face_verts and move them to OpenGL as well. We use pycuda to + # directly move the vertices on the GPU, to avoid a costly torch/GPU -> CPU + # -> openGL/GPU trip. + verts_packed = mesh.verts_packed().detach() + faces_packed = mesh.faces_packed().detach() + face_verts = verts_packed[faces_packed].reshape(-1, 9) + _torch_to_opengl(face_verts, self.cuda_context, self.cuda_buffer) + + if projection_matrix is not None: + self._projection_matrix_to_opengl(projection_matrix) + + # Start OpenGL operations. + gl.glUseProgram(self.program) + + # Render an image of size (width, height). + gl.glViewport(0, 0, width, height) + + gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, self.fbo) + # Clear the output framebuffer. The "background" value for both pix_to_face + # as well as bary_coords is -1 (background = pixels which the rasterizer + # projected no triangle to). + gl.glClearColor(-1.0, -1.0, -1.0, -1.0) + gl.glClearDepth(1.0) + # pyre-ignore Unsupported operand [58] + gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) + + # Run the actual rendering. The face_verts were transported to the OpenGL + # program into a shader storage buffer which is used directly in the geometry + # shader. Here, we only pass the number of these vertices to the vertex shader + # (which doesn't do anything and passes directly to the geometry shader). + gl.glBindVertexArray(self.vao) + gl.glDrawArrays(gl.GL_POINTS, 0, len(face_verts)) + gl.glBindVertexArray(0) + + # Read out the result. We ignore the depth buffer. The RGBA color buffer stores + # barycentrics in the RGB component and pix_to_face in the A component. + bary_depth_p2f_gl = gl.glReadPixels( + 0, + 0, + width, + height, + gl.GL_RGBA, + gl.GL_FLOAT, + ) + + gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, 0) + gl.glUseProgram(0) + + # Create torch tensors containing the results. + bary_depth_p2f = ( + torch.frombuffer(bary_depth_p2f_gl, dtype=torch.float) + .reshape(1, height, width, 1, -1) + .to(verts_packed.device) + ) + + # Read out barycentrics. GL only outputs the first two, so we need to compute + # the third one and make sure we still leave no-intersection pixels with -1. + barycentric_coords = torch.cat( + [ + bary_depth_p2f[..., :2], + 1.0 - bary_depth_p2f[..., 0:1] - bary_depth_p2f[..., 1:2], + ], + dim=-1, + ) + barycentric_coords = torch.where( + barycentric_coords == 3, -1, barycentric_coords + ) + depth = bary_depth_p2f[..., 2:3].squeeze(-1) + pix_to_face = bary_depth_p2f[..., -1].long() + + return pix_to_face, barycentric_coords, depth + + @staticmethod + def _compile_and_link_gl_program(): + """ + Compile the vertex, geometry, and fragment shaders and link them into an OpenGL + program. The shader sources are strongly inspired by https://github.com/tensorflow/ + graphics/blob/master/tensorflow_graphics/rendering/opengl/rasterization_backend.py. + + Returns: + An OpenGL program for mesh rasterization. + """ + program = gl.glCreateProgram() + shader_objects = [] + + for shader_string, shader_type in zip( + [vertex_shader, geometry_shader, fragment_shader], + [gl.GL_VERTEX_SHADER, gl.GL_GEOMETRY_SHADER, gl.GL_FRAGMENT_SHADER], + ): + shader_objects.append(gl.glCreateShader(shader_type)) + gl.glShaderSource(shader_objects[-1], shader_string) + + gl.glCompileShader(shader_objects[-1]) + status = gl.glGetShaderiv(shader_objects[-1], gl.GL_COMPILE_STATUS) + if status == gl.GL_FALSE: + gl.glDeleteShader(shader_objects[-1]) + gl.glDeleteProgram(program) + error_msg = gl.glGetShaderInfoLog(shader_objects[-1]).decode("utf-8") + raise RuntimeError(f"Compilation failure:\n {error_msg}") + + gl.glAttachShader(program, shader_objects[-1]) + gl.glDeleteShader(shader_objects[-1]) + + gl.glLinkProgram(program) + status = gl.glGetProgramiv(program, gl.GL_LINK_STATUS) + + if status == gl.GL_FALSE: + gl.glDeleteProgram(program) + error_msg = gl.glGetProgramInfoLog(program) + raise RuntimeError(f"Link failure:\n {error_msg}") + + return program + + @staticmethod + def _set_up_gl_program_properties(program) -> None: + """ + Set basic OpenGL program properties: disable blending, enable depth testing, + and disable face culling. + """ + gl.glUseProgram(program) + gl.glDisable(gl.GL_BLEND) + gl.glEnable(gl.GL_DEPTH_TEST) + gl.glDisable(gl.GL_CULL_FACE) + gl.glUseProgram(0) + + @staticmethod + def _prepare_persistent_opengl_objects(program, max_faces: int): + """ + Prepare OpenGL objects that we want to persist between rasterizations. + + Args: + program: The OpenGL program the resources will be tied to. + max_faces: Max number of faces of any mesh we will rasterize. + + Returns: + perspective_projection_uniform: An OpenGL object pointing to a location of + the perspective projection matrix in OpenGL memory. + mesh_buffer_object: An OpenGL object pointing to the location of the mesh + buffer object in OpenGL memory. + vao: The OpenGL input array object. + fbo: The OpenGL output framebuffer. + + """ + gl.glUseProgram(program) + # Get location of the "uniform" (that is, an internal OpenGL variable available + # to the shaders) that we'll load the projection matrices to. + perspective_projection_uniform = gl.glGetUniformLocation( + program, "perspective_projection" + ) + + # Mesh buffer object -- our main input point. We'll copy the mesh here + # from pytorch/cuda. The buffer needs enough space to store the three vertices + # of each face, that is its size in bytes is + # max_faces * 3 (vertices) * 3 (coordinates) * 4 (bytes) + # pyre-fixme[16]: Module `GL_1_5` has no attribute `glGenBuffers`. + mesh_buffer_object = gl.glGenBuffers(1) + gl.glBindBufferBase(gl.GL_SHADER_STORAGE_BUFFER, 0, mesh_buffer_object) + + gl.glBufferData( + gl.GL_SHADER_STORAGE_BUFFER, + max_faces * 9 * 4, + np.zeros((max_faces, 9), dtype=np.float32), + gl.GL_DYNAMIC_COPY, + ) + + # Input vertex array object. We will only use it implicitly for indexing the + # vertices, but the actual input data is passed in the shader storage buffer. + # pyre-fixme[16]: Module `GL_3_0` has no attribute `glGenVertexArrays`. + vao = gl.glGenVertexArrays(1) + + # Create the framebuffer object (fbo) where we'll store output data. + MAX_EGL_WIDTH = global_device_context_store.max_egl_width + MAX_EGL_HEIGHT = global_device_context_store.max_egl_height + # pyre-fixme[16]: Module `GL_3_0` has no attribute `glGenRenderbuffers`. + color_buffer = gl.glGenRenderbuffers(1) + gl.glBindRenderbuffer(gl.GL_RENDERBUFFER, color_buffer) + gl.glRenderbufferStorage( + gl.GL_RENDERBUFFER, gl.GL_RGBA32F, MAX_EGL_WIDTH, MAX_EGL_HEIGHT + ) + gl.glBindRenderbuffer(gl.GL_RENDERBUFFER, 0) + + # pyre-fixme[16]: Module `GL_3_0` has no attribute `glGenRenderbuffers`. + depth_buffer = gl.glGenRenderbuffers(1) + gl.glBindRenderbuffer(gl.GL_RENDERBUFFER, depth_buffer) + gl.glRenderbufferStorage( + gl.GL_RENDERBUFFER, gl.GL_DEPTH_COMPONENT, MAX_EGL_WIDTH, MAX_EGL_HEIGHT + ) + gl.glBindRenderbuffer(gl.GL_RENDERBUFFER, 0) + + # pyre-fixme[16]: Module `GL_3_0` has no attribute `glGenFramebuffers`. + fbo = gl.glGenFramebuffers(1) + gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, fbo) + gl.glFramebufferRenderbuffer( + gl.GL_FRAMEBUFFER, gl.GL_COLOR_ATTACHMENT0, gl.GL_RENDERBUFFER, color_buffer + ) + gl.glFramebufferRenderbuffer( + gl.GL_FRAMEBUFFER, gl.GL_DEPTH_ATTACHMENT, gl.GL_RENDERBUFFER, depth_buffer + ) + gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, 0) + + gl.glUseProgram(0) + return perspective_projection_uniform, mesh_buffer_object, vao, fbo + + +def _check_cameras(cameras) -> None: + # Check that the cameras are non-None and compatible with MeshRasterizerOpenGL. + if cameras is None: + msg = "Cameras must be specified either at initialization \ + or in the forward pass of MeshRasterizer" + raise ValueError(msg) + if type(cameras).__name__ in {"PerspectiveCameras", "OrthographicCameras"}: + raise ValueError( + "MeshRasterizerOpenGL only works with FoVPerspectiveCameras and " + "FoVOrthographicCameras, which are OpenGL compatible." + ) + + +def _check_raster_settings(raster_settings) -> None: + # Check that the rasterizer's settings are compatible with MeshRasterizerOpenGL. + if raster_settings.faces_per_pixel > 1: + warnings.warn( + "MeshRasterizerOpenGL currently works only with one face per pixel." + ) + if raster_settings.cull_backfaces: + warnings.warn( + "MeshRasterizerOpenGL cannot cull backfaces yet, rasterizing without culling." + ) + if raster_settings.cull_to_frustum: + warnings.warn( + "MeshRasterizerOpenGL cannot cull to frustum yet, rasterizing without culling." + ) + if raster_settings.z_clip_value is not None: + raise NotImplementedError("MeshRasterizerOpenGL cannot do z-clipping yet.") + if raster_settings.perspective_correct is False: + raise ValueError( + "MeshRasterizerOpenGL always uses perspective-correct interpolation." + ) + + +def _convert_meshes_to_gl_ndc( + meshes_world: Meshes, image_size: Tuple[int, int], camera, **kwargs +) -> Meshes: + """ + Convert a batch of world-coordinate meshes to GL NDC coordinates. + + Args: + meshes_world: Meshes in the world coordinate system. + image_size: Image height and width, used to modify mesh coords for rendering in + non-rectangular images. OpenGL will expand anything within the [-1, 1] NDC + range to fit the width and height of the screen, so we will squeeze the NDCs + appropriately if rendering a rectangular image. + camera: FoV cameras. + kwargs['R'], kwargs['T']: If present, used to define the world-view transform. + """ + height, width = image_size + verts_ndc = ( + camera.get_world_to_view_transform(**kwargs) + .compose(camera.get_ndc_camera_transform(**kwargs)) + .transform_points(meshes_world.verts_padded(), eps=None) + ) + verts_ndc[..., 0] = -verts_ndc[..., 0] + verts_ndc[..., 1] = -verts_ndc[..., 1] + + # In case of a non-square viewport, transform the vertices. OpenGL will expand + # the anything within the [-1, 1] NDC range to fit the width and height of the + # screen. So to work with PyTorch3D cameras, we need to squeeze the NDCs + # appropriately. + dtype, device = verts_ndc.dtype, verts_ndc.device + if height > width: + verts_ndc = verts_ndc * torch.tensor( + [1, width / height, 1], dtype=dtype, device=device + ) + elif width > height: + verts_ndc = verts_ndc * torch.tensor( + [height / width, 1, 1], dtype=dtype, device=device + ) + + meshes_gl_ndc = meshes_world.update_padded(new_verts_padded=verts_ndc) + + return meshes_gl_ndc diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/points/__init__.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/points/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..2abb97cef38f4d04b73ce7eb60784e0a7c39a96f --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/points/__init__.py @@ -0,0 +1,17 @@ +# 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. + +# pyre-unsafe + +from .compositor import AlphaCompositor, NormWeightedCompositor +from .pulsar.unified import PulsarPointsRenderer + +from .rasterize_points import rasterize_points +from .rasterizer import PointsRasterizationSettings, PointsRasterizer +from .renderer import PointsRenderer + + +__all__ = [k for k in globals().keys() if not k.startswith("_")] diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/points/compositor.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/points/compositor.py new file mode 100644 index 0000000000000000000000000000000000000000..14187eee279c330ce5291cfd6ddcc7db8a598841 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/points/compositor.py @@ -0,0 +1,116 @@ +# 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. + +# pyre-unsafe + +from typing import List, Optional, Tuple, Union + +import torch +import torch.nn as nn + +from ..compositing import alpha_composite, norm_weighted_sum + + +# A compositor should take as input 3D points and some corresponding information. +# Given this information, the compositor can: +# - blend colors across the top K vertices at a pixel + + +class AlphaCompositor(nn.Module): + """ + Accumulate points using alpha compositing. + """ + + def __init__( + self, background_color: Optional[Union[Tuple, List, torch.Tensor]] = None + ) -> None: + super().__init__() + self.background_color = background_color + + def forward(self, fragments, alphas, ptclds, **kwargs) -> torch.Tensor: + background_color = kwargs.get("background_color", self.background_color) + images = alpha_composite(fragments, alphas, ptclds) + + # images are of shape (N, C, H, W) + # check for background color & feature size C (C=4 indicates rgba) + if background_color is not None: + return _add_background_color_to_images(fragments, images, background_color) + return images + + +class NormWeightedCompositor(nn.Module): + """ + Accumulate points using a normalized weighted sum. + """ + + def __init__( + self, background_color: Optional[Union[Tuple, List, torch.Tensor]] = None + ) -> None: + super().__init__() + self.background_color = background_color + + def forward(self, fragments, alphas, ptclds, **kwargs) -> torch.Tensor: + background_color = kwargs.get("background_color", self.background_color) + images = norm_weighted_sum(fragments, alphas, ptclds) + + # images are of shape (N, C, H, W) + # check for background color & feature size C (C=4 indicates rgba) + if background_color is not None: + return _add_background_color_to_images(fragments, images, background_color) + return images + + +def _add_background_color_to_images(pix_idxs, images, background_color): + """ + Mask pixels in images without corresponding points with a given background_color. + + Args: + pix_idxs: int32 Tensor of shape (N, points_per_pixel, image_size, image_size) + giving the indices of the nearest points at each pixel, sorted in z-order. + images: Tensor of shape (N, 4, image_size, image_size) giving the + accumulated features at each point, where 4 refers to a rgba feature. + background_color: Tensor, list, or tuple with 3 or 4 values indicating the rgb/rgba + value for the new background. Values should be in the interval [0,1]. + Returns: + images: Tensor of shape (N, 4, image_size, image_size), where pixels with + no nearest points have features set to the background color, and other + pixels with accumulated features have unchanged values. + """ + # Initialize background mask + background_mask = pix_idxs[:, 0] < 0 # (N, H, W) + + # Convert background_color to an appropriate tensor and check shape + if not torch.is_tensor(background_color): + background_color = images.new_tensor(background_color) + + if background_color.ndim == 0: + background_color = background_color.expand(images.shape[1]) + + if background_color.ndim > 1: + raise ValueError("Wrong shape of background_color") + + background_color = background_color.to(images) + + # add alpha channel if needed + if background_color.shape[0] + 1 == images.shape[1]: + alpha = images.new_ones(1) + background_color = torch.cat([background_color, alpha]) + + if images.shape[1] != background_color.shape[0]: + raise ValueError( + "Background color has %s channels not %s" + % (background_color.shape[0], images.shape[1]) + ) + + num_background_pixels = background_mask.sum() + + # permute so that features are the last dimension for masked_scatter to work + masked_images = images.permute(0, 2, 3, 1).masked_scatter( + background_mask[..., None], + background_color[None, :].expand(num_background_pixels, -1), + ) + + return masked_images.permute(0, 3, 1, 2) diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/points/pulsar/__init__.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/points/pulsar/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..c843025a7bc67325f18a818425926bf82398f6e3 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/points/pulsar/__init__.py @@ -0,0 +1,9 @@ +# 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. + +# pyre-unsafe + +from .renderer import Renderer # noqa: F401 diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/points/pulsar/renderer.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/points/pulsar/renderer.py new file mode 100644 index 0000000000000000000000000000000000000000..5aceda6fc700fb784d263ea123dbf0f89887c23b --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/points/pulsar/renderer.py @@ -0,0 +1,666 @@ +# 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. + +# pyre-unsafe + +"""pulsar renderer PyTorch integration. + +Proper Python support for pytorch requires creating a torch.autograd.function +(independent of whether this is being done within the C++ module). This is done +here and a torch.nn.Module is exposed for the use in more complex models. +""" +import logging +import warnings +from typing import Optional, Tuple, Union + +import torch +from pytorch3d import _C +from pytorch3d.transforms import axis_angle_to_matrix, rotation_6d_to_matrix + + +LOGGER = logging.getLogger(__name__) +GAMMA_WARNING_EMITTED = False +AXANGLE_WARNING_EMITTED = False + + +class _Render(torch.autograd.Function): + """ + Differentiable rendering function for the Pulsar renderer. + + Usually this will be used through the `Renderer` module, which takes care of + setting up the buffers and putting them on the correct device. If you use + the function directly, you will have to do this manually. + + The steps for this are two-fold: first, you need to create a native Renderer + object to provide the required buffers. This is the `native_renderer` parameter + for this function. You can create it by creating a `pytorch3d._C.PulsarRenderer` + object (with parameters for width, height and maximum number of balls it should + be able to render). This object by default resides on the CPU. If you want to + shift the buffers to a different device, just assign an empty tensor on the target + device to its property `device_tracker`. + + To convert camera parameters from a more convenient representation to the + required vectors as in this function, you can use the static + function `pytorch3d.renderer.points.pulsar.Renderer._transform_cam_params`. + + Args: + * ctx: Pytorch context. + * vert_pos: vertex positions. [Bx]Nx3 tensor of positions in 3D space. + * vert_col: vertex colors. [Bx]NxK tensor of channels. + * vert_rad: vertex radii. [Bx]N tensor of radiuses, >0. + * cam_pos: camera position(s). [Bx]3 tensor in 3D coordinates. + * pixel_0_0_center: [Bx]3 tensor center(s) of the upper left pixel(s) in + world coordinates. + * pixel_vec_x: [Bx]3 tensor from one pixel center to the next in image x + direction in world coordinates. + * pixel_vec_y: [Bx]3 tensor from one pixel center to the next in image y + direction in world coordinates. + * focal_length: [Bx]1 tensor of focal lengths in world coordinates. + * principal_point_offsets: [Bx]2 tensor of principal point offsets in pixels. + * gamma: sphere transparency in [1.,1E-5], with 1 being mostly transparent. + [Bx]1. + * max_depth: maximum depth for spheres to render. Set this as tighly + as possible to have good numerical accuracy for gradients. + * native_renderer: a `pytorch3d._C.PulsarRenderer` object. + * min_depth: a float with the minimum depth a sphere must have to be renderer. + Must be 0. or > max(focal_length). + * bg_col: K tensor with a background color to use or None (uses all ones). + * opacity: [Bx]N tensor of opacity values in [0., 1.] or None (uses all ones). + * percent_allowed_difference: a float in [0., 1.[ with the maximum allowed + difference in color space. This is used to speed up the + computation. Default: 0.01. + * max_n_hits: a hard limit on the number of hits per ray. Default: max int. + * mode: render mode in {0, 1}. 0: render an image; 1: render the hit map. + * return_forward_info: whether to return a second map. This second map contains + 13 channels: first channel contains sm_m (the maximum exponent factor + observed), the second sm_d (the normalization denominator, the sum of all + coefficients), the third the maximum closest possible intersection for a + hit. The following channels alternate with the float encoded integer index + of a sphere and its weight. They are the five spheres with the highest + color contribution to this pixel color, ordered descending. + + Returns: + * image: [Bx]HxWxK float tensor with the resulting image. + * forw_info: [Bx]HxWx13 float forward information as described above, + if enabled. + """ + + @staticmethod + # pyre-fixme[14]: `forward` overrides method defined in `Function` inconsistently. + def forward( + ctx, + vert_pos, + vert_col, + vert_rad, + cam_pos, + pixel_0_0_center, + pixel_vec_x, + pixel_vec_y, + focal_length, + principal_point_offsets, + gamma, + max_depth, + native_renderer, + min_depth=0.0, + bg_col=None, + opacity=None, + percent_allowed_difference=0.01, + # pyre-fixme[16]: Module `_C` has no attribute `MAX_UINT`. + max_n_hits=_C.MAX_UINT, + mode=0, + return_forward_info=False, + ) -> Union[torch.Tensor, Tuple[torch.Tensor, torch.Tensor]]: + if mode != 0: + assert not return_forward_info, ( + "You are using a non-standard rendering mode. This does " + "not provide gradients, and also no `forward_info`. Please " + "set `return_forward_info` to `False`." + ) + ctx.gamma = gamma + ctx.max_depth = max_depth + ctx.min_depth = min_depth + ctx.percent_allowed_difference = percent_allowed_difference + ctx.max_n_hits = max_n_hits + ctx.mode = mode + ctx.native_renderer = native_renderer + image, info = ctx.native_renderer.forward( + vert_pos, + vert_col, + vert_rad, + cam_pos, + pixel_0_0_center, + pixel_vec_x, + pixel_vec_y, + focal_length, + principal_point_offsets, + gamma, + max_depth, + min_depth, + bg_col, + opacity, + percent_allowed_difference, + max_n_hits, + mode, + ) + if mode != 0: + # Backprop not possible! + info = None + # Prepare for backprop. + ctx.save_for_backward( + vert_pos, + vert_col, + vert_rad, + cam_pos, + pixel_0_0_center, + pixel_vec_x, + pixel_vec_y, + focal_length, + principal_point_offsets, + bg_col, + opacity, + image, + info, + ) + if return_forward_info: + return image, info + else: + return image + + @staticmethod + def backward(ctx, grad_im, *args): + global GAMMA_WARNING_EMITTED + ( + vert_pos, + vert_col, + vert_rad, + cam_pos, + pixel_0_0_center, + pixel_vec_x, + pixel_vec_y, + focal_length, + principal_point_offsets, + bg_col, + opacity, + image, + info, + ) = ctx.saved_tensors + if ( + ( + ctx.needs_input_grad[0] + or ctx.needs_input_grad[2] + or ctx.needs_input_grad[3] + or ctx.needs_input_grad[4] + or ctx.needs_input_grad[5] + or ctx.needs_input_grad[6] + or ctx.needs_input_grad[7] + ) + and ctx.gamma < 1e-3 + and not GAMMA_WARNING_EMITTED + ): + warnings.warn( + "Optimizing for non-color parameters and having a gamma value < 1E-3! " + "This is probably not going to produce usable gradients." + ) + GAMMA_WARNING_EMITTED = True + if ctx.mode == 0: + ( + grad_pos, + grad_col, + grad_rad, + grad_cam_pos, + grad_pixel_0_0_center, + grad_pixel_vec_x, + grad_pixel_vec_y, + grad_opacity, + ) = ctx.native_renderer.backward( + grad_im, + image, + info, + vert_pos, + vert_col, + vert_rad, + cam_pos, + pixel_0_0_center, + pixel_vec_x, + pixel_vec_y, + focal_length, + principal_point_offsets, + ctx.gamma, + ctx.max_depth, + ctx.min_depth, + bg_col, + opacity, + ctx.percent_allowed_difference, + ctx.max_n_hits, + ctx.mode, + ctx.needs_input_grad[0], + ctx.needs_input_grad[1], + ctx.needs_input_grad[2], + ctx.needs_input_grad[3] + or ctx.needs_input_grad[4] + or ctx.needs_input_grad[5] + or ctx.needs_input_grad[6] + or ctx.needs_input_grad[7], + ctx.needs_input_grad[14], + None, # No debug information provided. + ) + else: + raise ValueError( + "Performing a backward pass for a " + "rendering with `mode != 0`! This is not possible." + ) + return ( + grad_pos, + grad_col, + grad_rad, + grad_cam_pos, + grad_pixel_0_0_center, + grad_pixel_vec_x, + grad_pixel_vec_y, + None, # focal_length + None, # principal_point_offsets + None, # gamma + None, # max_depth + None, # native_renderer + None, # min_depth + None, # bg_col + grad_opacity, + None, # percent_allowed_difference + None, # max_n_hits + None, # mode + None, # return_forward_info + ) + + +class Renderer(torch.nn.Module): + """ + Differentiable rendering module for the Pulsar renderer. + + Set the maximum number of balls to a reasonable value. It is used to determine + several buffer sizes. It is no problem to render less balls than this number, + but never more. + + When optimizing for sphere positions, sphere radiuses or camera parameters you + have to use higher gamma values (closer to one) and larger sphere sizes: spheres + can only 'move' to areas that they cover, and only with higher gamma values exists + a gradient w.r.t. their color depending on their position. + + Args: + * width: result image width in pixels. + * height: result image height in pixels. + * max_num_balls: the maximum number of balls this renderer will handle. + * orthogonal_projection: use an orthogonal instead of perspective projection. + Default: False. + * right_handed_system: use a right-handed instead of a left-handed coordinate + system. This is relevant for compatibility with other drawing or scanning + systems. Pulsar by default assumes a left-handed world and camera coordinate + system as known from mathematics with x-axis to the right, y axis up and z + axis for increasing depth along the optical axis. In the image coordinate + system, only the y axis is pointing down, leading still to a left-handed + system. If you set this to True, it is assuming a right-handed world and + camera coordinate system with x axis to the right, y axis to the top and + z axis decreasing along the optical axis. Again, the image coordinate + system has a flipped y axis, remaining a right-handed system. + Default: False. + * background_normalized_depth: the normalized depth the background is placed + at. + This is on a scale from 0. to 1. between the specified min and max depth + (see the forward function). The value 0. is the most furthest depth whereas + 1. is the closest. Be careful when setting the background too far front - it + may hide elements in your scene. Default: EPS. + * n_channels: the number of image content channels to use. This is usually three + for regular color representations, but can be a higher or lower number. + Default: 3. + * n_track: the number of spheres to track for gradient calculation per pixel. + Only the closest n_track spheres will receive gradients. Default: 5. + """ + + def __init__( + self, + width: int, + height: int, + max_num_balls: int, + orthogonal_projection: bool = False, + right_handed_system: bool = False, + # pyre-fixme[16]: Module `_C` has no attribute `EPS`. + background_normalized_depth: float = _C.EPS, + n_channels: int = 3, + n_track: int = 5, + ) -> None: + super(Renderer, self).__init__() + # pyre-fixme[16]: Module `pytorch3d` has no attribute `_C`. + self._renderer = _C.PulsarRenderer( + width, + height, + max_num_balls, + orthogonal_projection, + right_handed_system, + background_normalized_depth, + n_channels, + n_track, + ) + self.register_buffer("device_tracker", torch.zeros(1)) + + @staticmethod + def sphere_ids_from_result_info_nograd(result_info: torch.Tensor) -> torch.Tensor: + """ + Get the sphere IDs from a result info tensor. + """ + if result_info.ndim == 3: + return Renderer.sphere_ids_from_result_info_nograd(result_info[None, ...]) + # pyre-fixme[16]: Module `pytorch3d` has no attribute `_C`. + return _C.pulsar_sphere_ids_from_result_info_nograd(result_info) + + @staticmethod + def depth_map_from_result_info_nograd(result_info: torch.Tensor) -> torch.Tensor: + """ + Get the depth map from a result info tensor. + + This returns a map of the same size as the image with just one channel + containing the closest intersection value at that position. Gradients + are not available for this tensor, but do note that you can use + `sphere_ids_from_result_info_nograd` to get the IDs of the spheres at + each position and directly create a loss on their depth if required. + + The depth map contains -1. at positions where no intersection has + been detected. + """ + return result_info[..., 4] + + @staticmethod + def _transform_cam_params( + cam_params: torch.Tensor, + width: int, + height: int, + orthogonal: bool, + right_handed: bool, + first_R_then_T: bool = False, + ) -> Tuple[ + torch.Tensor, + torch.Tensor, + torch.Tensor, + torch.Tensor, + torch.Tensor, + torch.Tensor, + ]: + """ + Transform 8 component camera parameter vector(s) to the internal camera + representation. + + The input vectors consists of: + * 3 components for camera position, + * 3 components for camera rotation (three rotation angles) or + 6 components as described in "On the Continuity of Rotation + Representations in Neural Networks" (Zhou et al.), + * focal length, + * the sensor width in world coordinates, + * [optional] the principal point offset in x and y. + + The sensor height is inferred by pixel size and sensor width to obtain + quadratic pixels. + + Args: + * cam_params: [Bx]{8, 10, 11, 13}, input tensors as described above. + * width: number of pixels in x direction. + * height: number of pixels in y direction. + * orthogonal: bool, whether an orthogonal projection is used + (does not use focal length). + * right_handed: bool, whether to use a right handed system + (negative z in camera direction). + * first_R_then_T: bool, whether to first rotate, then translate + the camera (PyTorch3D convention). + + Returns: + * pos_vec: the position vector in 3D, + * pixel_0_0_center: the center of the upper left pixel in world coordinates, + * pixel_vec_x: the step to move one pixel on the image x axis + in world coordinates, + * pixel_vec_y: the step to move one pixel on the image y axis + in world coordinates, + * focal_length: the focal lengths, + * principal_point_offsets: the principal point offsets in x, y. + """ + global AXANGLE_WARNING_EMITTED + # Set up all direction vectors, i.e., the sensor direction of all axes. + assert width > 0 + assert height > 0 + batch_processing = True + if cam_params.ndimension() == 1: + batch_processing = False + cam_params = cam_params[None, :] + batch_size = cam_params.size(0) + continuous_rep = True + if cam_params.shape[1] in [8, 10]: + if cam_params.requires_grad and not AXANGLE_WARNING_EMITTED: + warnings.warn( + "Using an axis angle representation for camera rotations. " + "This has discontinuities and should not be used for optimization. " + "Alternatively, use a six-component representation as described in " + "'On the Continuity of Rotation Representations in Neural Networks'" + " (Zhou et al.). " + "The `pytorch3d.transforms` module provides " + "facilities for using this representation." + ) + AXANGLE_WARNING_EMITTED = True + continuous_rep = False + else: + assert cam_params.shape[1] in [11, 13] + pos_vec: torch.Tensor = cam_params[:, :3] + principal_point_offsets: torch.Tensor = torch.zeros( + (cam_params.shape[0], 2), dtype=torch.int32, device=cam_params.device + ) + if continuous_rep: + rot_vec = cam_params[:, 3:9] + focal_length: torch.Tensor = cam_params[:, 9:10] + sensor_size_x = cam_params[:, 10:11] + if cam_params.shape[1] == 13: + principal_point_offsets: torch.Tensor = cam_params[:, 11:13].to( + torch.int32 + ) + else: + rot_vec = cam_params[:, 3:6] + focal_length: torch.Tensor = cam_params[:, 6:7] + sensor_size_x = cam_params[:, 7:8] + if cam_params.shape[1] == 10: + principal_point_offsets: torch.Tensor = cam_params[:, 8:10].to( + torch.int32 + ) + # Always get quadratic pixels. + pixel_size_x = sensor_size_x / float(width) + sensor_size_y = height * pixel_size_x + if continuous_rep: + rot_mat = rotation_6d_to_matrix(rot_vec) + else: + rot_mat = axis_angle_to_matrix(rot_vec) + if first_R_then_T: + pos_vec = torch.matmul(rot_mat, pos_vec[..., None])[:, :, 0] + sensor_dir_x = torch.matmul( + rot_mat, + torch.tensor( + [1.0, 0.0, 0.0], dtype=torch.float32, device=rot_mat.device + ).repeat(batch_size, 1)[:, :, None], + )[:, :, 0] + sensor_dir_y = torch.matmul( + rot_mat, + torch.tensor( + [0.0, -1.0, 0.0], dtype=torch.float32, device=rot_mat.device + ).repeat(batch_size, 1)[:, :, None], + )[:, :, 0] + sensor_dir_z = torch.matmul( + rot_mat, + torch.tensor( + [0.0, 0.0, 1.0], dtype=torch.float32, device=rot_mat.device + ).repeat(batch_size, 1)[:, :, None], + )[:, :, 0] + if right_handed: + sensor_dir_z *= -1 + if orthogonal: + sensor_center = pos_vec + else: + sensor_center = pos_vec + focal_length * sensor_dir_z + sensor_luc = ( # Sensor left upper corner. + sensor_center + - sensor_dir_x * (sensor_size_x / 2.0) + - sensor_dir_y * (sensor_size_y / 2.0) + ) + pixel_size_x = sensor_size_x / float(width) + pixel_size_y = sensor_size_y / float(height) + pixel_vec_x: torch.Tensor = sensor_dir_x * pixel_size_x + pixel_vec_y: torch.Tensor = sensor_dir_y * pixel_size_y + pixel_0_0_center = sensor_luc + 0.5 * pixel_vec_x + 0.5 * pixel_vec_y + # Reduce dimension. + focal_length: torch.Tensor = focal_length[:, 0] + if batch_processing: + return ( + pos_vec, + pixel_0_0_center, + pixel_vec_x, + pixel_vec_y, + focal_length, + principal_point_offsets, + ) + else: + return ( + pos_vec[0], + pixel_0_0_center[0], + pixel_vec_x[0], + pixel_vec_y[0], + focal_length[0], + principal_point_offsets[0], + ) + + def forward( + self, + vert_pos: torch.Tensor, + vert_col: torch.Tensor, + vert_rad: torch.Tensor, + cam_params: torch.Tensor, + gamma: float, + max_depth: float, + min_depth: float = 0.0, + bg_col: Optional[torch.Tensor] = None, + opacity: Optional[torch.Tensor] = None, + percent_allowed_difference: float = 0.01, + # pyre-fixme[16]: Module `_C` has no attribute `MAX_UINT`. + max_n_hits: int = _C.MAX_UINT, + mode: int = 0, + return_forward_info: bool = False, + first_R_then_T: bool = False, + ) -> Union[torch.Tensor, Tuple[torch.Tensor, Optional[torch.Tensor]]]: + """ + Rendering pass to create an image from the provided spheres and camera + parameters. + + Args: + * vert_pos: vertex positions. [Bx]Nx3 tensor of positions in 3D space. + * vert_col: vertex colors. [Bx]NxK tensor of channels. + * vert_rad: vertex radii. [Bx]N tensor of radiuses, >0. + * cam_params: camera parameter(s). [Bx]8 tensor, consisting of: + - 3 components for camera position, + - 3 components for camera rotation (axis angle representation) or + 6 components as described in "On the Continuity of Rotation + Representations in Neural Networks" (Zhou et al.), + - focal length, + - the sensor width in world coordinates, + - [optional] an offset for the principal point in x, y (no gradients). + * gamma: sphere transparency in [1.,1E-5], with 1 being mostly transparent. + [Bx]1. + * max_depth: maximum depth for spheres to render. Set this as tightly + as possible to have good numerical accuracy for gradients. + float > min_depth + eps. + * min_depth: a float with the minimum depth a sphere must have to be + rendered. Must be 0. or > max(focal_length) + eps. + * bg_col: K tensor with a background color to use or None (uses all ones). + * opacity: [Bx]N tensor of opacity values in [0., 1.] or None (uses all + ones). + * percent_allowed_difference: a float in [0., 1.[ with the maximum allowed + difference in color space. This is used to speed up the + computation. Default: 0.01. + * max_n_hits: a hard limit on the number of hits per ray. Default: max int. + * mode: render mode in {0, 1}. 0: render an image; 1: render the hit map. + * return_forward_info: whether to return a second map. This second map + contains 13 channels: first channel contains sm_m (the maximum + exponent factor observed), the second sm_d (the normalization + denominator, the sum of all coefficients), the third the maximum closest + possible intersection for a hit. The following channels alternate with + the float encoded integer index of a sphere and its weight. They are the + five spheres with the highest color contribution to this pixel color, + ordered descending. Default: False. + * first_R_then_T: bool, whether to first apply rotation to the camera, + then translation (PyTorch3D convention). Default: False. + + Returns: + * image: [Bx]HxWx3 float tensor with the resulting image. + * forw_info: [Bx]HxWx13 float forward information as described above, if + enabled. + """ + # The device tracker is registered as buffer. + self._renderer.device_tracker = self.device_tracker + ( + pos_vec, + pixel_0_0_center, + pixel_vec_x, + pixel_vec_y, + focal_lengths, + principal_point_offsets, + ) = Renderer._transform_cam_params( + cam_params, + self._renderer.width, + self._renderer.height, + self._renderer.orthogonal, + self._renderer.right_handed, + first_R_then_T=first_R_then_T, + ) + if ( + focal_lengths.min().item() > 0.0 + and max_depth > 10_000.0 * focal_lengths.min().item() + ): + warnings.warn( + ( + "Extreme ratio of `max_depth` vs. focal length detected " + "(%f vs. %f, ratio: %f). This will likely lead to " + "artifacts due to numerical instabilities." + ) + % ( + max_depth, + focal_lengths.min().item(), + max_depth / focal_lengths.min().item(), + ) + ) + ret_res = _Render.apply( + vert_pos, + vert_col, + vert_rad, + pos_vec, + pixel_0_0_center, + pixel_vec_x, + pixel_vec_y, + # Focal length and sensor size don't need gradients other than through + # `pixel_vec_x` and `pixel_vec_y`. The focal length is only used in the + # renderer to determine the projection areas of the balls. + focal_lengths, + # principal_point_offsets does not receive gradients. + principal_point_offsets, + gamma, + max_depth, + self._renderer, + min_depth, + bg_col, + opacity, + percent_allowed_difference, + max_n_hits, + mode, + (mode == 0) and return_forward_info, + ) + if return_forward_info and mode != 0: + return ret_res, None + return ret_res + + def extra_repr(self) -> str: + """Extra information to print in pytorch graphs.""" + return "width={}, height={}, max_num_balls={}".format( + self._renderer.width, self._renderer.height, self._renderer.max_num_balls + ) diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/points/pulsar/unified.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/points/pulsar/unified.py new file mode 100644 index 0000000000000000000000000000000000000000..13664d4deb55212ee1d8e0974bed4ede5db02523 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/points/pulsar/unified.py @@ -0,0 +1,556 @@ +# 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. + +# pyre-unsafe + +import math +import warnings +from typing import Any, Dict, Optional, Tuple, Union + +import torch +import torch.nn as nn + +from ...camera_conversions import _pulsar_from_cameras_projection +from ...cameras import ( + FoVOrthographicCameras, + FoVPerspectiveCameras, + OrthographicCameras, + PerspectiveCameras, +) +from ..compositor import AlphaCompositor, NormWeightedCompositor +from ..rasterizer import PointsRasterizer +from .renderer import Renderer as PulsarRenderer + + +def _ensure_float_tensor(val_in, device): + """Make sure that the value provided is wrapped a PyTorch float tensor.""" + if not isinstance(val_in, torch.Tensor): + val_out = torch.tensor(val_in, dtype=torch.float32, device=device).reshape((1,)) + else: + val_out = val_in.to(torch.float32).to(device).reshape((1,)) + return val_out + + +class PulsarPointsRenderer(nn.Module): + """ + This renderer is a PyTorch3D interface wrapper around the pulsar renderer. + + It provides an interface consistent with PyTorch3D Pointcloud rendering. + It will extract all necessary information from the rasterizer and compositor + objects and convert them to the pulsar required format, then invoke rendering + in the pulsar renderer. All gradients are handled appropriately through the + wrapper and the wrapper should provide equivalent results to using the pulsar + renderer directly. + """ + + def __init__( + self, + rasterizer: PointsRasterizer, + compositor: Optional[Union[NormWeightedCompositor, AlphaCompositor]] = None, + n_channels: int = 3, + max_num_spheres: int = int(1e6), # noqa: B008 + **kwargs, + ) -> None: + """ + rasterizer (PointsRasterizer): An object encapsulating rasterization parameters. + compositor (ignored): Only keeping this for interface consistency. Default: None. + n_channels (int): The number of channels of the resulting image. Default: 3. + max_num_spheres (int): The maximum number of spheres intended to render with + this renderer. Default: 1e6. + kwargs (Any): kwargs to pass on to the pulsar renderer. + See `pytorch3d.renderer.points.pulsar.renderer.Renderer` for all options. + """ + super().__init__() + self.rasterizer = rasterizer + if compositor is not None: + warnings.warn( + "Creating a `PulsarPointsRenderer` with a compositor object! " + "This object is ignored and just allowed as an argument for interface " + "compatibility." + ) + # Initialize the pulsar renderers. + if not isinstance( + rasterizer.cameras, + ( + FoVOrthographicCameras, + FoVPerspectiveCameras, + PerspectiveCameras, + OrthographicCameras, + ), + ): + raise ValueError( + "Only FoVPerspectiveCameras, PerspectiveCameras, " + "FoVOrthographicCameras and OrthographicCameras are supported " + "by the pulsar backend." + ) + if isinstance(rasterizer.raster_settings.image_size, tuple): + height, width = rasterizer.raster_settings.image_size + else: + width = rasterizer.raster_settings.image_size + height = rasterizer.raster_settings.image_size + # Making sure about integer types. + width = int(width) + height = int(height) + max_num_spheres = int(max_num_spheres) + orthogonal_projection = isinstance( + rasterizer.cameras, (FoVOrthographicCameras, OrthographicCameras) + ) + n_channels = int(n_channels) + self.renderer = PulsarRenderer( + width=width, + height=height, + max_num_balls=max_num_spheres, + orthogonal_projection=orthogonal_projection, + right_handed_system=False, + n_channels=n_channels, + **kwargs, + ) + + def _conf_check(self, point_clouds, kwargs: Dict[str, Any]) -> bool: + """ + Verify internal configuration state with kwargs and pointclouds. + + This method will raise ValueError's for any inconsistencies found. It + returns whether an orthogonal projection will be used. + """ + if "gamma" not in kwargs.keys(): + raise ValueError( + "gamma is a required keyword argument for the PulsarPointsRenderer!" + ) + if ( + len(point_clouds) != len(self.rasterizer.cameras) + and len(self.rasterizer.cameras) != 1 + ): + raise ValueError( + ( + "The len(point_clouds) must either be equal to len(rasterizer.cameras) or " + "only one camera must be used. len(point_clouds): %d, " + "len(rasterizer.cameras): %d." + ) + % ( + len(point_clouds), + len(self.rasterizer.cameras), + ) + ) + # Make sure the rasterizer and cameras objects have no + # changes that can't be matched. + orthogonal_projection = isinstance( + self.rasterizer.cameras, (FoVOrthographicCameras, OrthographicCameras) + ) + if orthogonal_projection != self.renderer._renderer.orthogonal: + raise ValueError( + "The camera type can not be changed after renderer initialization! " + "Current camera orthogonal: %r. Original orthogonal: %r." + ) % (orthogonal_projection, self.renderer._renderer.orthogonal) + image_size = self.rasterizer.raster_settings.image_size + if isinstance(image_size, tuple): + expected_height, expected_width = image_size + else: + expected_height = expected_width = image_size + if expected_width != self.renderer._renderer.width: + raise ValueError( + ( + "The rasterizer width can not be changed after renderer " + "initialization! Current width: %s. Original width: %d." + ) + % ( + expected_width, + self.renderer._renderer.width, + ) + ) + if expected_height != self.renderer._renderer.height: + raise ValueError( + ( + "The rasterizer height can not be changed after renderer " + "initialization! Current height: %s. Original height: %d." + ) + % ( + expected_height, + self.renderer._renderer.height, + ) + ) + return orthogonal_projection + + def _extract_intrinsics( # noqa: C901 + self, orthogonal_projection, kwargs, cloud_idx, device + ) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, float, float]: + """ + Translate the camera intrinsics from PyTorch3D format to pulsar format. + """ + # Shorthand: + cameras = self.rasterizer.cameras + if orthogonal_projection: + focal_length = torch.zeros((1,), dtype=torch.float32) + if isinstance(cameras, FoVOrthographicCameras): + znear = kwargs.get("znear", cameras.znear)[cloud_idx] + zfar = kwargs.get("zfar", cameras.zfar)[cloud_idx] + max_y = kwargs.get("max_y", cameras.max_y)[cloud_idx] + min_y = kwargs.get("min_y", cameras.min_y)[cloud_idx] + max_x = kwargs.get("max_x", cameras.max_x)[cloud_idx] + min_x = kwargs.get("min_x", cameras.min_x)[cloud_idx] + if max_y != -min_y: + raise ValueError( + "The orthographic camera must be centered around 0. " + f"Max is {max_y} and min is {min_y}." + ) + if max_x != -min_x: + raise ValueError( + "The orthographic camera must be centered around 0. " + f"Max is {max_x} and min is {min_x}." + ) + if not torch.all( + kwargs.get("scale_xyz", cameras.scale_xyz)[cloud_idx] == 1.0 + ): + raise ValueError( + "The orthographic camera scale must be ((1.0, 1.0, 1.0),). " + f"{kwargs.get('scale_xyz', cameras.scale_xyz)[cloud_idx]}." + ) + sensor_width = max_x - min_x + if not sensor_width > 0.0: + raise ValueError( + f"The orthographic camera must have positive size! Is: {sensor_width}." # noqa: B950 + ) + principal_point_x, principal_point_y = ( + torch.zeros((1,), dtype=torch.float32), + torch.zeros((1,), dtype=torch.float32), + ) + else: + # Currently, this means it must be an 'OrthographicCameras' object. + focal_length_conf = kwargs.get("focal_length", cameras.focal_length)[ + cloud_idx + ] + if ( + focal_length_conf.numel() == 2 + and focal_length_conf[0] * self.renderer._renderer.width + - focal_length_conf[1] * self.renderer._renderer.height + > 1e-5 + ): + raise ValueError( + "Pulsar only supports a single focal length! " + "Provided: %s." % (str(focal_length_conf)) + ) + if focal_length_conf.numel() == 2: + sensor_width = 2.0 / focal_length_conf[0] + else: + if focal_length_conf.numel() != 1: + raise ValueError( + "Focal length not parsable: %s." % (str(focal_length_conf)) + ) + sensor_width = 2.0 / focal_length_conf + if "znear" not in kwargs.keys() or "zfar" not in kwargs.keys(): + raise ValueError( + "pulsar needs znear and zfar values for " + "the OrthographicCameras. Please provide them as keyword " + "argument to the forward method." + ) + znear = kwargs["znear"][cloud_idx] + zfar = kwargs["zfar"][cloud_idx] + principal_point_x = ( + kwargs.get("principal_point", cameras.principal_point)[cloud_idx][0] + * 0.5 + * self.renderer._renderer.width + ) + principal_point_y = ( + kwargs.get("principal_point", cameras.principal_point)[cloud_idx][1] + * 0.5 + * self.renderer._renderer.height + ) + else: + if not isinstance(cameras, PerspectiveCameras): + # Create a virtual focal length that is closer than znear. + znear = kwargs.get("znear", cameras.znear)[cloud_idx] + zfar = kwargs.get("zfar", cameras.zfar)[cloud_idx] + focal_length = znear - 1e-6 + # Create a sensor size that matches the expected fov assuming this f. + afov = kwargs.get("fov", cameras.fov)[cloud_idx] + if kwargs.get("degrees", cameras.degrees): + afov *= math.pi / 180.0 + sensor_width = math.tan(afov / 2.0) * 2.0 * focal_length + if not ( + kwargs.get("aspect_ratio", cameras.aspect_ratio)[cloud_idx] + - self.renderer._renderer.width / self.renderer._renderer.height + < 1e-6 + ): + raise ValueError( + "The aspect ratio (" + f"{kwargs.get('aspect_ratio', cameras.aspect_ratio)[cloud_idx]}) " + "must agree with the resolution width / height (" + f"{self.renderer._renderer.width / self.renderer._renderer.height})." # noqa: B950 + ) + principal_point_x, principal_point_y = ( + torch.zeros((1,), dtype=torch.float32), + torch.zeros((1,), dtype=torch.float32), + ) + else: + focal_length_conf = kwargs.get("focal_length", cameras.focal_length)[ + cloud_idx + ] + if ( + focal_length_conf.numel() == 2 + and focal_length_conf[0] * self.renderer._renderer.width + - focal_length_conf[1] * self.renderer._renderer.height + > 1e-5 + ): + raise ValueError( + "Pulsar only supports a single focal length! " + "Provided: %s." % (str(focal_length_conf)) + ) + if "znear" not in kwargs.keys() or "zfar" not in kwargs.keys(): + raise ValueError( + "pulsar needs znear and zfar values for " + "the PerspectiveCameras. Please provide them as keyword " + "argument to the forward method." + ) + znear = kwargs["znear"][cloud_idx] + zfar = kwargs["zfar"][cloud_idx] + if focal_length_conf.numel() == 2: + focal_length_px = focal_length_conf[0] + else: + if focal_length_conf.numel() != 1: + raise ValueError( + "Focal length not parsable: %s." % (str(focal_length_conf)) + ) + focal_length_px = focal_length_conf + focal_length = torch.tensor( + [ + znear - 1e-6, + ], + dtype=torch.float32, + device=focal_length_px.device, + ) + sensor_width = focal_length / focal_length_px * 2.0 + principal_point_x = ( + kwargs.get("principal_point", cameras.principal_point)[cloud_idx][0] + * 0.5 + * self.renderer._renderer.width + ) + principal_point_y = ( + kwargs.get("principal_point", cameras.principal_point)[cloud_idx][1] + * 0.5 + * self.renderer._renderer.height + ) + focal_length = _ensure_float_tensor(focal_length, device) + sensor_width = _ensure_float_tensor(sensor_width, device) + principal_point_x = _ensure_float_tensor(principal_point_x, device) + principal_point_y = _ensure_float_tensor(principal_point_y, device) + znear = _ensure_float_tensor(znear, device) + zfar = _ensure_float_tensor(zfar, device) + return ( + focal_length, + sensor_width, + principal_point_x, + principal_point_y, + znear, + zfar, + ) + + def _extract_extrinsics( + self, kwargs, cloud_idx + ) -> Tuple[torch.Tensor, torch.Tensor]: + """ + Extract the extrinsic information from the kwargs for a specific point cloud. + + Instead of implementing a direct translation from the PyTorch3D to the Pulsar + camera model, we chain the two conversions of PyTorch3D->OpenCV and + OpenCV->Pulsar for better maintainability (PyTorch3D->OpenCV is maintained and + tested by the core PyTorch3D team, whereas OpenCV->Pulsar is maintained and + tested by the Pulsar team). + """ + # Shorthand: + cameras = self.rasterizer.cameras + R = kwargs.get("R", cameras.R)[cloud_idx] + T = kwargs.get("T", cameras.T)[cloud_idx] + tmp_cams = PerspectiveCameras( + R=R.unsqueeze(0), T=T.unsqueeze(0), device=R.device + ) + size_tensor = torch.tensor( + [[self.renderer._renderer.height, self.renderer._renderer.width]] + ) + pulsar_cam = _pulsar_from_cameras_projection(tmp_cams, size_tensor) + cam_pos = pulsar_cam[0, :3] + cam_rot = pulsar_cam[0, 3:9] + return cam_pos, cam_rot + + def _get_vert_rad( + self, vert_pos, cam_pos, orthogonal_projection, focal_length, kwargs, cloud_idx + ) -> torch.Tensor: + """ + Get point radiuses. + + These can be depending on the camera position in case of a perspective + transform. + """ + # Normalize point radiuses. + # `self.rasterizer.raster_settings.radius` can either be a float + # or itself a tensor. + raster_rad = self.rasterizer.raster_settings.radius + if kwargs.get("radius_world", False): + return raster_rad + if ( + isinstance(raster_rad, torch.Tensor) + and raster_rad.numel() > 1 + and raster_rad.ndim > 1 + ): + # In this case it must be a batched torch tensor. + raster_rad = raster_rad[cloud_idx] + if orthogonal_projection: + vert_rad = ( + torch.ones( + (vert_pos.shape[0],), dtype=torch.float32, device=vert_pos.device + ) + * raster_rad + ) + else: + point_dists = torch.norm((vert_pos - cam_pos), p=2, dim=1, keepdim=False) + vert_rad = raster_rad / focal_length.to(vert_pos.device) * point_dists + if isinstance(self.rasterizer.cameras, PerspectiveCameras): + # NDC normalization happens through adjusted focal length. + pass + else: + vert_rad = vert_rad / 2.0 # NDC normalization. + return vert_rad + + # point_clouds is not typed to avoid a cyclic dependency. + def forward(self, point_clouds, **kwargs) -> torch.Tensor: + """ + Get the rendering of the provided `Pointclouds`. + + The number of point clouds in the `Pointclouds` object determines the + number of resulting images. The provided cameras can be either 1 or equal + to the number of pointclouds (in the first case, the same camera will be + used for all clouds, in the latter case each point cloud will be rendered + with the corresponding camera). + + The following kwargs are support from PyTorch3D (depending on the selected + camera model potentially overriding camera parameters): + radius_world (bool): use the provided radiuses from the raster_settings + plain as radiuses in world space. Default: False. + znear (Iterable[float]): near geometry cutoff. Is required for + OrthographicCameras and PerspectiveCameras. + zfar (Iterable[float]): far geometry cutoff. Is required for + OrthographicCameras and PerspectiveCameras. + R (torch.Tensor): [Bx3x3] camera rotation matrices. + T (torch.Tensor): [Bx3] camera translation vectors. + principal_point (torch.Tensor): [Bx2] camera intrinsic principal + point offset vectors. + focal_length (torch.Tensor): [Bx1] camera intrinsic focal lengths. + aspect_ratio (Iterable[float]): camera aspect ratios. + fov (Iterable[float]): camera FOVs. + degrees (bool): whether FOVs are specified in degrees or + radians. + min_x (Iterable[float]): minimum x for the FoVOrthographicCameras. + max_x (Iterable[float]): maximum x for the FoVOrthographicCameras. + min_y (Iterable[float]): minimum y for the FoVOrthographicCameras. + max_y (Iterable[float]): maximum y for the FoVOrthographicCameras. + + The following kwargs are supported from pulsar: + gamma (float): The gamma value to use. This defines the transparency for + differentiability (see pulsar paper for details). Must be in [1., 1e-5] + with 1.0 being mostly transparent. This keyword argument is *required*! + bg_col (torch.Tensor): The background color. Must be a tensor on the same + device as the point clouds, with as many channels as features (no batch + dimension - it is the same for all images in the batch). + Default: 0.0 for all channels. + percent_allowed_difference (float): a value in [0., 1.[ with the maximum + allowed difference in channel space. This is used to speed up the + computation. Default: 0.01. + max_n_hits (int): a hard limit on the number of sphere hits per ray. + Default: max int. + mode (int): render mode in {0, 1}. 0: render image; 1: render hit map. + """ + orthogonal_projection: bool = self._conf_check(point_clouds, kwargs) + # Get access to inputs. We're using the list accessor and process + # them sequentially. + position_list = point_clouds.points_list() + features_list = point_clouds.features_list() + # Result list. + images = [] + for cloud_idx, (vert_pos, vert_col) in enumerate( + zip(position_list, features_list) + ): + # Get extrinsics. + cam_pos, cam_rot = self._extract_extrinsics(kwargs, cloud_idx) + # Get intrinsics. + ( + focal_length, + sensor_width, + principal_point_x, + principal_point_y, + znear, + zfar, + ) = self._extract_intrinsics( + orthogonal_projection, kwargs, cloud_idx, cam_pos.device + ) + # Put everything together. + cam_params = torch.cat( + ( + cam_pos, + cam_rot.to(cam_pos.device), + torch.cat( + [ + focal_length, + sensor_width, + principal_point_x, + principal_point_y, + ], + ), + ) + ) + # Get point radiuses (can depend on camera position). + vert_rad = self._get_vert_rad( + vert_pos, + cam_pos, + orthogonal_projection, + focal_length, + kwargs, + cloud_idx, + ) + # Clean kwargs for passing on. + gamma = kwargs["gamma"][cloud_idx] + if "first_R_then_T" in kwargs.keys(): + raise ValueError("`first_R_then_T` is not supported in this interface.") + otherargs = { + argn: argv + for argn, argv in kwargs.items() + if argn + not in [ + "radius_world", + "gamma", + "znear", + "zfar", + "R", + "T", + "principal_point", + "focal_length", + "aspect_ratio", + "fov", + "degrees", + "min_x", + "max_x", + "min_y", + "max_y", + ] + } + # background color + if "bg_col" not in otherargs: + bg_col = torch.zeros( + vert_col.shape[1], device=cam_params.device, dtype=torch.float32 + ) + otherargs["bg_col"] = bg_col + # Go! + images.append( + self.renderer( + vert_pos=vert_pos, + vert_col=vert_col, + vert_rad=vert_rad, + cam_params=cam_params, + gamma=gamma, + max_depth=zfar, + min_depth=znear, + **otherargs, + ).flip(dims=[0]) + ) + return torch.stack(images, dim=0) diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/points/rasterize_points.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/points/rasterize_points.py new file mode 100644 index 0000000000000000000000000000000000000000..3d2c6b7ca59326e8f743ee164a8832bd6ede5c1d --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/points/rasterize_points.py @@ -0,0 +1,322 @@ +# 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. + +# pyre-unsafe + +from typing import List, Optional, Tuple, Union + +import numpy as np +import torch +from pytorch3d import _C + +from pytorch3d.renderer.mesh.rasterize_meshes import pix_to_non_square_ndc + +from ..utils import parse_image_size + + +# Maximum number of faces per bins for +# coarse-to-fine rasterization +kMaxPointsPerBin = 22 + + +def rasterize_points( + pointclouds, + image_size: Union[int, List[int], Tuple[int, int]] = 256, + radius: Union[float, List, Tuple, torch.Tensor] = 0.01, + points_per_pixel: int = 8, + bin_size: Optional[int] = None, + max_points_per_bin: Optional[int] = None, +): + """ + Each pointcloud is rasterized onto a separate image of shape + (H, W) if `image_size` is a tuple or (image_size, image_size) if it + is an int. + + If the desired image size is non square (i.e. a tuple of (H, W) where H != W) + the aspect ratio needs special consideration. There are two aspect ratios + to be aware of: + - the aspect ratio of each pixel + - the aspect ratio of the output image + The camera can be used to set the pixel aspect ratio. In the rasterizer, + we assume square pixels, but variable image aspect ratio (i.e rectangle images). + + In most cases you will want to set the camera aspect ratio to + 1.0 (i.e. square pixels) and only vary the + `image_size` (i.e. the output image dimensions in pix + + Args: + pointclouds: A Pointclouds object representing a batch of point clouds to be + rasterized. This is a batch of N pointclouds, where each point cloud + can have a different number of points; the coordinates of each point + are (x, y, z). The coordinates are expected to + be in normalized device coordinates (NDC): [-1, 1]^3 with the camera at + (0, 0, 0); In the camera coordinate frame the x-axis goes from right-to-left, + the y-axis goes from bottom-to-top, and the z-axis goes from back-to-front. + image_size: Size in pixels of the output image to be rasterized. + Can optionally be a tuple of (H, W) in the case of non square images. + radius (Optional): The radius (in NDC units) of the disk to + be rasterized. This can either be a float in which case the same radius is used + for each point, or a torch.Tensor of shape (N, P) giving a radius per point + in the batch. + points_per_pixel (Optional): We will keep track of this many points per + pixel, returning the nearest points_per_pixel points along the z-axis + bin_size: Size of bins to use for coarse-to-fine rasterization. Setting + bin_size=0 uses naive rasterization; setting bin_size=None attempts to + set it heuristically based on the shape of the input. This should not + affect the output, but can affect the speed of the forward pass. + max_points_per_bin: Only applicable when using coarse-to-fine rasterization + (bin_size > 0); this is the maximum number of points allowed within each + bin. This should not affect the output values, but can affect + the memory usage in the forward pass. + + Returns: + 3-element tuple containing + + - **idx**: int32 Tensor of shape (N, image_size, image_size, points_per_pixel) + giving the indices of the nearest points at each pixel, in ascending + z-order. Concretely `idx[n, y, x, k] = p` means that `points[p]` is the kth + closest point (along the z-direction) to pixel (y, x) - note that points + represents the packed points of shape (P, 3). + Pixels that are hit by fewer than points_per_pixel are padded with -1. + - **zbuf**: Tensor of shape (N, image_size, image_size, points_per_pixel) + giving the z-coordinates of the nearest points at each pixel, sorted in + z-order. Concretely, if `idx[n, y, x, k] = p` then + `zbuf[n, y, x, k] = points[n, p, 2]`. Pixels hit by fewer than + points_per_pixel are padded with -1 + - **dists2**: Tensor of shape (N, image_size, image_size, points_per_pixel) + giving the squared Euclidean distance (in NDC units) in the x/y plane + for each point closest to the pixel. Concretely if `idx[n, y, x, k] = p` + then `dists[n, y, x, k]` is the squared distance between the pixel (y, x) + and the point `(points[n, p, 0], points[n, p, 1])`. Pixels hit with fewer + than points_per_pixel are padded with -1. + + In the case that image_size is a tuple of (H, W) then the outputs + will be of shape `(N, H, W, ...)`. + """ + points_packed = pointclouds.points_packed() + cloud_to_packed_first_idx = pointclouds.cloud_to_packed_first_idx() + num_points_per_cloud = pointclouds.num_points_per_cloud() + + radius = _format_radius(radius, pointclouds) + + # In the case that H != W use the max image size to set the bin_size + # to accommodate the num bins constraint in the coarse rasterizer. + # If the ratio of H:W is large this might cause issues as the smaller + # dimension will have fewer bins. + # TODO: consider a better way of setting the bin size. + im_size = parse_image_size(image_size) + max_image_size = max(*im_size) + + if bin_size is None: + if not points_packed.is_cuda: + # Binned CPU rasterization not fully implemented + bin_size = 0 + else: + bin_size = int(2 ** max(np.ceil(np.log2(max_image_size)) - 4, 4)) + + if bin_size != 0: + # There is a limit on the number of points per bin in the cuda kernel. + points_per_bin = 1 + (max_image_size - 1) // bin_size + if points_per_bin >= kMaxPointsPerBin: + raise ValueError( + "bin_size too small, number of points per bin must be less than %d; got %d" + % (kMaxPointsPerBin, points_per_bin) + ) + + if max_points_per_bin is None: + max_points_per_bin = int(max(10000, pointclouds._P / 5)) + + # Function.apply cannot take keyword args, so we handle defaults in this + # wrapper and call apply with positional args only + return _RasterizePoints.apply( + points_packed, + cloud_to_packed_first_idx, + num_points_per_cloud, + im_size, + radius, + points_per_pixel, + bin_size, + max_points_per_bin, + ) + + +def _format_radius( + radius: Union[float, List, Tuple, torch.Tensor], pointclouds +) -> torch.Tensor: + """ + Format the radius as a torch tensor of shape (P_packed,) + where P_packed is the total number of points in the + batch (i.e. pointclouds.points_packed().shape[0]). + + This will enable support for a different size radius + for each point in the batch. + + Args: + radius: can be a float, List, Tuple or tensor of + shape (N, P_padded) where P_padded is the + maximum number of points for each pointcloud + in the batch. + + Returns: + radius: torch.Tensor of shape (P_packed) + """ + N, P_padded = pointclouds._N, pointclouds._P + points_packed = pointclouds.points_packed() + P_packed = points_packed.shape[0] + if isinstance(radius, (list, tuple)): + radius = torch.tensor(radius).type_as(points_packed) + if isinstance(radius, torch.Tensor): + if N == 1 and radius.ndim == 1: + radius = radius[None, ...] + if radius.shape != (N, P_padded): + msg = "radius must be of shape (N, P): got %s" + raise ValueError(msg % (repr(radius.shape))) + else: + padded_to_packed_idx = pointclouds.padded_to_packed_idx() + radius = radius.view(-1)[padded_to_packed_idx] + elif isinstance(radius, float): + radius = torch.full((P_packed,), fill_value=radius).type_as(points_packed) + else: + msg = "radius must be a float, list, tuple or tensor; got %s" + raise ValueError(msg % type(radius)) + return radius + + +class _RasterizePoints(torch.autograd.Function): + @staticmethod + def forward( + ctx, + points, # (P, 3) + cloud_to_packed_first_idx, + num_points_per_cloud, + image_size: Union[List[int], Tuple[int, int]] = (256, 256), + radius: Union[float, torch.Tensor] = 0.01, + points_per_pixel: int = 8, + bin_size: int = 0, + max_points_per_bin: int = 0, + ): + # TODO: Add better error handling for when there are more than + # max_points_per_bin in any bin. + args = ( + points, + cloud_to_packed_first_idx, + num_points_per_cloud, + image_size, + radius, + points_per_pixel, + bin_size, + max_points_per_bin, + ) + # pyre-fixme[16]: Module `pytorch3d` has no attribute `_C`. + idx, zbuf, dists = _C.rasterize_points(*args) + ctx.save_for_backward(points, idx) + ctx.mark_non_differentiable(idx) + return idx, zbuf, dists + + @staticmethod + def backward(ctx, grad_idx, grad_zbuf, grad_dists): + grad_points = None + grad_cloud_to_packed_first_idx = None + grad_num_points_per_cloud = None + grad_image_size = None + grad_radius = None + grad_points_per_pixel = None + grad_bin_size = None + grad_max_points_per_bin = None + points, idx = ctx.saved_tensors + args = (points, idx, grad_zbuf, grad_dists) + grad_points = _C.rasterize_points_backward(*args) + grads = ( + grad_points, + grad_cloud_to_packed_first_idx, + grad_num_points_per_cloud, + grad_image_size, + grad_radius, + grad_points_per_pixel, + grad_bin_size, + grad_max_points_per_bin, + ) + return grads + + +def rasterize_points_python( + pointclouds, + image_size: Union[int, Tuple[int, int]] = 256, + radius: Union[float, torch.Tensor] = 0.01, + points_per_pixel: int = 8, +): + """ + Naive pure PyTorch implementation of pointcloud rasterization. + + Inputs / Outputs: Same as above + """ + N = len(pointclouds) + H, W = ( + image_size + if isinstance(image_size, (tuple, list)) + else (image_size, image_size) + ) + K = points_per_pixel + device = pointclouds.device + + points_packed = pointclouds.points_packed() + cloud_to_packed_first_idx = pointclouds.cloud_to_packed_first_idx() + num_points_per_cloud = pointclouds.num_points_per_cloud() + + # Support variable size radius for each point in the batch + radius = _format_radius(radius, pointclouds) + + # Initialize output tensors. + point_idxs = torch.full( + (N, H, W, K), fill_value=-1, dtype=torch.int32, device=device + ) + zbuf = torch.full((N, H, W, K), fill_value=-1, dtype=torch.float32, device=device) + pix_dists = torch.full( + (N, H, W, K), fill_value=-1, dtype=torch.float32, device=device + ) + + # NDC is from [-1, 1]. Get pixel size using specified image size. + radius2 = radius * radius + + # Iterate through the batch of point clouds. + for n in range(N): + point_start_idx = cloud_to_packed_first_idx[n] + point_stop_idx = point_start_idx + num_points_per_cloud[n] + + # Iterate through the horizontal lines of the image from top to bottom. + for yi in range(H): + # Y coordinate of one end of the image. Reverse the ordering + # of yi so that +Y is pointing up in the image. + yfix = H - 1 - yi + yf = pix_to_non_square_ndc(yfix, H, W) + + # Iterate through pixels on this horizontal line, left to right. + for xi in range(W): + # X coordinate of one end of the image. Reverse the ordering + # of xi so that +X is pointing to the left in the image. + xfix = W - 1 - xi + xf = pix_to_non_square_ndc(xfix, W, H) + + top_k_points = [] + # Check whether each point in the batch affects this pixel. + for p in range(point_start_idx, point_stop_idx): + px, py, pz = points_packed[p, :] + r = radius2[p] + if pz < 0: + continue + dx = px - xf + dy = py - yf + dist2 = dx * dx + dy * dy + if dist2 < r: + top_k_points.append((pz, p, dist2)) + top_k_points.sort() + if len(top_k_points) > K: + top_k_points = top_k_points[:K] + for k, (pz, p, dist2) in enumerate(top_k_points): + zbuf[n, yi, xi, k] = pz + point_idxs[n, yi, xi, k] = p + pix_dists[n, yi, xi, k] = dist2 + return point_idxs, zbuf, pix_dists diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/points/rasterizer.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/points/rasterizer.py new file mode 100644 index 0000000000000000000000000000000000000000..8c141b9012be0b36301f33210596a980d49db0dc --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/points/rasterizer.py @@ -0,0 +1,169 @@ +#!/usr/bin/env python3 +# 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. + +# pyre-unsafe + +from dataclasses import dataclass +from typing import NamedTuple, Optional, Tuple, Union + +import torch +import torch.nn as nn +from pytorch3d.renderer.cameras import try_get_projection_transform +from pytorch3d.structures import Pointclouds + +from .rasterize_points import rasterize_points + + +class PointFragments(NamedTuple): + """ + Class to store the outputs of point rasterization + + Members: + idx: int32 Tensor of shape (N, image_size, image_size, points_per_pixel) + giving the indices of the nearest points at each pixel, in ascending + z-order. Concretely `idx[n, y, x, k] = p` means that `points[p]` is the kth + closest point (along the z-direction) to pixel (y, x) - note that points + represents the packed points of shape (P, 3). + Pixels that are hit by fewer than points_per_pixel are padded with -1. + zbuf: Tensor of shape (N, image_size, image_size, points_per_pixel) + giving the z-coordinates of the nearest points at each pixel, sorted in + z-order. Concretely, if `idx[n, y, x, k] = p` then + `zbuf[n, y, x, k] = points[n, p, 2]`. Pixels hit by fewer than + points_per_pixel are padded with -1. + dists: Tensor of shape (N, image_size, image_size, points_per_pixel) + giving the squared Euclidean distance (in NDC units) in the x/y plane + for each point closest to the pixel. Concretely if `idx[n, y, x, k] = p` + then `dists[n, y, x, k]` is the squared distance between the pixel (y, x) + and the point `(points[n, p, 0], points[n, p, 1])`. Pixels hit with fewer + than points_per_pixel are padded with -1. + """ + + idx: torch.Tensor + zbuf: torch.Tensor + dists: torch.Tensor + + +@dataclass +class PointsRasterizationSettings: + """ + Class to store the point rasterization params with defaults + + Members: + image_size: Either common height and width or (height, width), in pixels. + radius: The radius (in NDC units) of each disk to be rasterized. + This can either be a float in which case the same radius is used + for each point, or a torch.Tensor of shape (N, P) giving a radius + per point in the batch. + points_per_pixel: (int) Number of points to keep track of per pixel. + We return the nearest points_per_pixel points along the z-axis. + bin_size: Size of bins to use for coarse-to-fine rasterization. Setting + bin_size=0 uses naive rasterization; setting bin_size=None attempts + to set it heuristically based on the shape of the input. This should + not affect the output, but can affect the speed of the forward pass. + max_points_per_bin: Only applicable when using coarse-to-fine + rasterization (bin_size != 0); this is the maximum number of points + allowed within each bin. This should not affect the output values, + but can affect the memory usage in the forward pass. + Setting max_points_per_bin=None attempts to set with a heuristic. + """ + + image_size: Union[int, Tuple[int, int]] = 256 + radius: Union[float, torch.Tensor] = 0.01 + points_per_pixel: int = 8 + bin_size: Optional[int] = None + max_points_per_bin: Optional[int] = None + + +class PointsRasterizer(nn.Module): + """ + This class implements methods for rasterizing a batch of pointclouds. + """ + + def __init__(self, cameras=None, raster_settings=None) -> None: + """ + cameras: A cameras object which has a `transform_points` method + which returns the transformed points after applying the + world-to-view and view-to-ndc transformations. + raster_settings: the parameters for rasterization. This should be a + named tuple. + + All these initial settings can be overridden by passing keyword + arguments to the forward function. + """ + super().__init__() + if raster_settings is None: + raster_settings = PointsRasterizationSettings() + + self.cameras = cameras + self.raster_settings = raster_settings + + def transform(self, point_clouds, **kwargs) -> Pointclouds: + """ + Args: + point_clouds: a set of point clouds + + Returns: + points_proj: the points with positions projected + in NDC space + + NOTE: keeping this as a separate function for readability but it could + be moved into forward. + """ + cameras = kwargs.get("cameras", self.cameras) + if cameras is None: + msg = "Cameras must be specified either at initialization \ + or in the forward pass of PointsRasterizer" + raise ValueError(msg) + + pts_world = point_clouds.points_padded() + # NOTE: Retaining view space z coordinate for now. + # TODO: Remove this line when the convention for the z coordinate in + # the rasterizer is decided. i.e. retain z in view space or transform + # to a different range. + eps = kwargs.get("eps", None) + pts_view = cameras.get_world_to_view_transform(**kwargs).transform_points( + pts_world, eps=eps + ) + to_ndc_transform = cameras.get_ndc_camera_transform(**kwargs) + projection_transform = try_get_projection_transform(cameras, kwargs) + if projection_transform is not None: + projection_transform = projection_transform.compose(to_ndc_transform) + pts_ndc = projection_transform.transform_points(pts_view, eps=eps) + else: + # Call transform_points instead of explicitly composing transforms to handle + # the case, where camera class does not have a projection matrix form. + pts_proj = cameras.transform_points(pts_world, eps=eps) + pts_ndc = to_ndc_transform.transform_points(pts_proj, eps=eps) + + pts_ndc[..., 2] = pts_view[..., 2] + point_clouds = point_clouds.update_padded(pts_ndc) + return point_clouds + + def to(self, device): + # Manually move to device cameras as it is not a subclass of nn.Module + if self.cameras is not None: + self.cameras = self.cameras.to(device) + return self + + def forward(self, point_clouds, **kwargs) -> PointFragments: + """ + Args: + point_clouds: a set of point clouds with coordinates in world space. + Returns: + PointFragments: Rasterization outputs as a named tuple. + """ + points_proj = self.transform(point_clouds, **kwargs) + raster_settings = kwargs.get("raster_settings", self.raster_settings) + idx, zbuf, dists2 = rasterize_points( + points_proj, + image_size=raster_settings.image_size, + radius=raster_settings.radius, + points_per_pixel=raster_settings.points_per_pixel, + bin_size=raster_settings.bin_size, + max_points_per_bin=raster_settings.max_points_per_bin, + ) + return PointFragments(idx=idx, zbuf=zbuf, dists=dists2) diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/points/renderer.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/points/renderer.py new file mode 100644 index 0000000000000000000000000000000000000000..4ce5360514ea52155c6518d132e9dd236fe03443 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/points/renderer.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python3 +# 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. + +# pyre-unsafe + +import torch +import torch.nn as nn + + +# A renderer class should be initialized with a +# function for rasterization and a function for compositing. +# The rasterizer should: +# - transform inputs from world -> screen space +# - rasterize inputs +# - return fragments +# The compositor can take fragments as input along with any other properties of +# the scene and generate images. + +# E.g. rasterize inputs and then shade +# +# fragments = self.rasterize(point_clouds) +# images = self.compositor(fragments, point_clouds) +# return images + + +class PointsRenderer(nn.Module): + """ + A class for rendering a batch of points. The class should + be initialized with a rasterizer and compositor class which each have a forward + function. + + The points are rendered with with varying alpha (weights) values depending on + the distance of the pixel center to the true point in the xy plane. The purpose + of this is to soften the hard decision boundary, for differentiability. + See Section 3.2 of "SynSin: End-to-end View Synthesis from a Single Image" + (https://arxiv.org/pdf/1912.08804.pdf) for more details. + """ + + def __init__(self, rasterizer, compositor) -> None: + super().__init__() + self.rasterizer = rasterizer + self.compositor = compositor + + def to(self, device): + # Manually move to device rasterizer as the cameras + # within the class are not of type nn.Module + self.rasterizer = self.rasterizer.to(device) + self.compositor = self.compositor.to(device) + return self + + def forward(self, point_clouds, **kwargs) -> torch.Tensor: + fragments = self.rasterizer(point_clouds, **kwargs) + + # Construct weights based on the distance of a point to the true point. + # However, this could be done differently: e.g. predicted as opposed + # to a function of the weights. + r = self.rasterizer.raster_settings.radius + + dists2 = fragments.dists.permute(0, 3, 1, 2) + weights = 1 - dists2 / (r * r) + images = self.compositor( + fragments.idx.long().permute(0, 3, 1, 2), + weights, + point_clouds.features_packed().permute(1, 0), + **kwargs, + ) + + # permute so image comes at the end + images = images.permute(0, 2, 3, 1) + + return images diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/splatter_blend.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/splatter_blend.py new file mode 100644 index 0000000000000000000000000000000000000000..e753d29ac45861f5d9c29a30ec63d7f65151304d --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/splatter_blend.py @@ -0,0 +1,568 @@ +# 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. + +# pyre-unsafe + +# This file defines SplatterBlender, which is used for blending in SplatterPhongShader. + +import itertools +from typing import Tuple + +import torch +import torch.nn.functional as F +from pytorch3d.common.datatypes import Device +from pytorch3d.renderer import BlendParams +from pytorch3d.renderer.cameras import FoVPerspectiveCameras + +from .blending import _get_background_color + + +def _precompute( + input_shape: Tuple[int, int, int, int], device: Device +) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]: + """ + Precompute padding and offset constants that won't change for a given NHWK shape. + + Args: + input_shape: Tuple indicating N (batch size), H, W (image size) and K (number of + intersections) output by the rasterizer. + device: Device to store the tensors on. + + returns: + crop_ids_h: An (N, H, W+2, K, 9, 5) tensor, used during splatting to offset the + p-pixels (splatting pixels) in one of the 9 splatting directions within a + call to torch.gather. See comments and offset_splats for details. + crop_ids_w: An (N, H, W, K, 9, 5) tensor, used similarly to crop_ids_h. + offsets: A (1, 1, 1, 1, 9, 2) tensor (shaped so for broadcasting) containing va- + lues [-1, -1], [-1, 0], [-1, 1], [0, -1], ..., [1, 1] which correspond to + the nine splatting directions. + """ + N, H, W, K = input_shape + + # (N, H, W+2, K, 9, 5) tensor, used to reduce a tensor from (N, H+2, W+2...) to + # (N, H, W+2, ...) in torch.gather. If only torch.gather broadcasted, we wouldn't + # need the tiling. But it doesn't. + crop_ids_h = ( + torch.arange(0, H, device=device).view(1, H, 1, 1, 1, 1) + + torch.tensor([0, 1, 2, 0, 1, 2, 0, 1, 2], device=device).view( + 1, 1, 1, 1, 9, 1 + ) + ).expand(N, H, W + 2, K, 9, 5) + + # (N, H, W, K, 9, 5) tensor, used to reduce a tensor from (N, H, W+2, ...) to + # (N, H, W, ...) in torch.gather. + crop_ids_w = ( + torch.arange(0, W, device=device).view(1, 1, W, 1, 1, 1) + + torch.tensor([0, 0, 0, 1, 1, 1, 2, 2, 2], device=device).view( + 1, 1, 1, 1, 9, 1 + ) + ).expand(N, H, W, K, 9, 5) + + offsets = torch.tensor( + list(itertools.product((-1, 0, 1), repeat=2)), + dtype=torch.long, + device=device, + ) + + return crop_ids_h, crop_ids_w, offsets + + +def _prepare_pixels_and_colors( + pixel_coords_cameras: torch.Tensor, + colors: torch.Tensor, + cameras: FoVPerspectiveCameras, + background_mask: torch.Tensor, +) -> Tuple[torch.Tensor, torch.Tensor]: + """ + Project pixel coords into the un-inverted screen frame of reference, and set + background pixel z-values to 1.0 and alphas to 0.0. + + Args: + pixel_coords_cameras: (N, H, W, K, 3) float tensor. + colors: (N, H, W, K, 3) float tensor. + cameras: PyTorch3D cameras, for now we assume FoVPerspectiveCameras. + background_mask: (N, H, W, K) boolean tensor. + + Returns: + pixel_coords_screen: (N, H, W, K, 3) float tensor. Background pixels have + x=y=z=1.0. + colors: (N, H, W, K, 4). Alpha is set to 1 for foreground pixels and 0 for back- + ground pixels. + """ + + N, H, W, K, C = colors.shape + # pixel_coords_screen will contain invalid values at background + # intersections, and [H+0.5, W+0.5, z] at valid intersections. It is important + # to not flip the xy axes, otherwise the gradients will be inverted when the + # splatter works with a detached rasterizer. + pixel_coords_screen = cameras.transform_points_screen( + pixel_coords_cameras.view([N, -1, 3]), image_size=(H, W), with_xyflip=False + ).reshape(pixel_coords_cameras.shape) + + # Set colors' alpha to 1 and background to 0. + colors = torch.cat( + [colors, torch.ones_like(colors[..., :1])], dim=-1 + ) # (N, H, W, K, 4) + + # The hw values of background don't matter because their alpha is set + # to 0 in the next step (which means that no matter what their splatting kernel + # value is, they will not splat as the kernel is multiplied by alpha). However, + # their z-values need to be at max depth. Otherwise, we could incorrectly compute + # occlusion layer linkage. + pixel_coords_screen[background_mask] = 1.0 + + # Any background color value value with alpha=0 will do, as anything with + # alpha=0 will have a zero-weight splatting power. Note that neighbors can still + # splat on zero-alpha pixels: that's the way we get non-zero gradients at the + # boundary with the background. + colors[background_mask] = 0.0 + + return pixel_coords_screen, colors + + +def _get_splat_kernel_normalization( + offsets: torch.Tensor, + sigma: float = 0.5, +): + if sigma <= 0.0: + raise ValueError("Only positive standard deviations make sense.") + + epsilon = 0.05 + normalization_constant = torch.exp( + # pyre-fixme[58]: `**` is not supported for operand types `Tensor` and `int`. + -(offsets**2).sum(dim=1) + / (2 * sigma**2) + ).sum() + + # We add an epsilon to the normalization constant to ensure the gradient will travel + # through non-boundary pixels' normalization factor, see Sec. 3.3.1 in "Differentia- + # ble Surface Rendering via Non-Differentiable Sampling", Cole et al. + # pyre-fixme[58]: `/` is not supported for operand types `float` and `Tensor`. + return (1 + epsilon) / normalization_constant + + +def _compute_occlusion_layers( + q_depth: torch.Tensor, +) -> torch.Tensor: + """ + For each splatting pixel, decide whether it splats from a background, surface, or + foreground depth relative to the splatted pixel. See unit tests in + test_splatter_blend for some enlightening examples. + + Args: + q_depth: (N, H, W, K) tensor of z-values of the splatted pixels. + + Returns: + occlusion_layers: (N, H, W, 9) long tensor. Each of the 9 values corresponds to + one of the nine splatting directions ([-1, -1], [-1, 0], ..., [1, + 1]). The value at nhwd (where d is the splatting direction) is 0 if + the splat in direction d is on the same surface level as the pixel at + hw. The value is negative if the splat is in the background (occluded + by another splat above it that is at the same surface level as the + pixel splatted on), and the value is positive if the splat is in the + foreground. + """ + N, H, W, K = q_depth.shape + + # q are the "center pixels" and p the pixels splatting onto them. Use `unfold` to + # create `p_depth`, a tensor with 9 layers, each of which corresponds to the + # depth of a neighbor of q in one of the 9 directions. For example, p_depth[nk0hw] + # is the depth of the pixel splatting onto pixel nhwk from the [-1, -1] direction, + # and p_depth[nk4hw] the depth of q (self-splatting onto itself). + # More concretely, imagine the pixel depths in a 2x2 image's k-th layer are + # .1 .2 + # .3 .4 + # Then (remembering that we pad with zeros when a pixel has fewer than 9 neighbors): + # + # p_depth[n, k, :, 0, 0] = [ 0 0 0 0 .1 .2 0 .3 .4] - neighbors of .1 + # p_depth[n, k, :, 0, 1] = [ 0 0 0 .1 .2 0 .3 .4 0] - neighbors of .2 + # p_depth[n, k, :, 1, 0] = [ 0 .1 .2 0 .3 .4 0 0 0] - neighbors of .3 + # p_depth[n, k, :, 0, 1] = [.1 .2 0 .3 .4 0 0 0 0] - neighbors of .4 + q_depth = q_depth.permute(0, 3, 1, 2) # (N, K, H, W) + p_depth = F.unfold(q_depth, kernel_size=3, padding=1) # (N, 3^2 * K, H * W) + q_depth = q_depth.view(N, K, 1, H, W) + p_depth = p_depth.view(N, K, 9, H, W) + + # Take the center pixel q's top rasterization layer. This is the "surface layer" + # that we're splatting on. For each of the nine splatting directions p, find which + # of the K splatting rasterization layers is closest in depth to the surface + # splatted layer. + qtop_to_p_zdist = torch.abs(p_depth - q_depth[:, 0:1]) # (N, K, 9, H, W) + qtop_to_p_closest_zdist, qtop_to_p_closest_id = qtop_to_p_zdist.min(dim=1) + + # For each of the nine splatting directions p, take the top of the K rasterization + # layers. Check which of the K q-layers (that the given direction is splatting on) + # is closest in depth to the top splatting layer. + ptop_to_q_zdist = torch.abs(p_depth[:, 0:1] - q_depth) # (N, K, 9, H, W) + ptop_to_q_closest_zdist, ptop_to_q_closest_id = ptop_to_q_zdist.min(dim=1) + + # Decide whether each p is on the same level, below, or above the q it is splatting + # on. See Fig. 4 in [0] for an illustration. Briefly: say we're interested in pixel + # p_{h, w} = [10, 32] splatting onto its neighbor q_{h, w} = [11, 33]. The splat is + # coming from direction [-1, -1], which has index 0 in our enumeration of splatting + # directions. Hence, we are interested in + # + # P = p_depth[n, :, d=0, 11, 33] - a vector of K depth values, and + # Q = q_depth.squeeze()[n, :, 11, 33] - a vector of K depth values. + # + # If Q[0] is closest, say, to P[2], then we assume the 0th surface layer of Q is + # the same surface as P[2] that's splatting onto it, and P[:2] are foreground splats + # and P[3:] are background splats. + # + # If instead say Q[2] is closest to P[0], then all the splats are background splats, + # because the top splatting layer is the same surface as a non-top splatted layer. + # + # Finally, if Q[0] is closest to P[0], then the top-level P is splatting onto top- + # level Q, and P[1:] are all background splats. + occlusion_offsets = torch.where( # noqa + ptop_to_q_closest_zdist < qtop_to_p_closest_zdist, + -ptop_to_q_closest_id, + qtop_to_p_closest_id, + ) # (N, 9, H, W) + + occlusion_layers = occlusion_offsets.permute((0, 2, 3, 1)) # (N, H, W, 9) + return occlusion_layers + + +def _compute_splatting_colors_and_weights( + pixel_coords_screen: torch.Tensor, + colors: torch.Tensor, + sigma: float, + offsets: torch.Tensor, +) -> torch.Tensor: + """ + For each center pixel q, compute the splatting weights of its surrounding nine spla- + tting pixels p, as well as their splatting colors (which are just their colors re- + weighted by the splatting weights). + + Args: + pixel_coords_screen: (N, H, W, K, 2) tensor of pixel screen coords. + colors: (N, H, W, K, 4) RGBA tensor of pixel colors. + sigma: splatting kernel variance. + offsets: (9, 2) tensor computed by _precompute, indicating the nine + splatting directions ([-1, -1], ..., [1, 1]). + + Returns: + splat_colors_and_weights: (N, H, W, K, 9, 5) tensor. + splat_colors_and_weights[..., :4] corresponds to the splatting colors, and + splat_colors_and_weights[..., 4:5] to the splatting weights. The "9" di- + mension corresponds to the nine splatting directions. + """ + N, H, W, K, C = colors.shape + splat_kernel_normalization = _get_splat_kernel_normalization(offsets, sigma) + + # Distance from each barycentric-interpolated triangle vertices' triplet from its + # "ideal" pixel-center location. pixel_coords_screen are in screen coordinates, and + # should be at the "ideal" locations on the forward pass -- e.g. + # pixel_coords_screen[n, 24, 31, k] = [24.5, 31.5]. For this reason, q_to_px_center + # should equal torch.zeros during the forward pass. On the backwards pass, these + # coordinates will be adjusted and non-zero, allowing the gradients to flow back + # to the mesh vertex coordinates. + q_to_px_center = ( + torch.floor(pixel_coords_screen[..., :2]) - pixel_coords_screen[..., :2] + 0.5 + ).view((N, H, W, K, 1, 2)) + + # pyre-fixme[58]: `**` is not supported for operand types `Tensor` and `int`. + dist2_p_q = torch.sum((q_to_px_center + offsets) ** 2, dim=5) # (N, H, W, K, 9) + splat_weights = torch.exp(-dist2_p_q / (2 * sigma**2)) + alpha = colors[..., 3:4] + splat_weights = (alpha * splat_kernel_normalization * splat_weights).unsqueeze( + 5 + ) # (N, H, W, K, 9, 1) + + # splat_colors[n, h, w, direction, :] contains the splatting color (weighted by the + # splatting weight) that pixel h, w will splat in one of the nine possible + # directions (e.g. nhw0 corresponds to splatting in [-1, 1] direciton, nhw4 is + # self-splatting). + splat_colors = splat_weights * colors.unsqueeze(4) # (N, H, W, K, 9, 4) + + return torch.cat([splat_colors, splat_weights], dim=5) + + +def _offset_splats( + splat_colors_and_weights: torch.Tensor, + crop_ids_h: torch.Tensor, + crop_ids_w: torch.Tensor, +) -> torch.Tensor: + """ + Pad splatting colors and weights so that tensor locations/coordinates are aligned + with the splatting directions. For example, say we have an example input Red channel + splat_colors_and_weights[n, :, :, k, direction=0, channel=0] equal to + .1 .2 .3 + .4 .5 .6 + .7 .8 .9 + the (h, w) entry indicates that pixel n, h, w, k splats the given color in direction + equal to 0, which corresponds to offsets[0] = (-1, -1). Note that this is the x-y + direction, not h-w. This function pads and crops this array to + 0 0 0 + .2 .3 0 + .5 .6 0 + which indicates, for example, that: + * There is no pixel splatting in direction (-1, -1) whose splat lands on pixel + h=w=0. + * There is a pixel splatting in direction (-1, -1) whose splat lands on the pi- + xel h=1, w=0, and that pixel's splatting color is .2. + * There is a pixel splatting in direction (-1, -1) whose splat lands on the pi- + xel h=2, w=1, and that pixel's splatting color is .6. + + Args: + *splat_colors_and_weights*: (N, H, W, K, 9, 5) tensor of colors and weights, + where dim=-2 corresponds to the splatting directions/offsets. + *crop_ids_h*: (N, H, W+2, K, 9, 5) precomputed tensor used for padding within + torch.gather. See _precompute for more info. + *crop_ids_w*: (N, H, W, K, 9, 5) precomputed tensor used for padding within + torch.gather. See _precompute for more info. + + + Returns: + *splat_colors_and_weights*: (N, H, W, K, 9, 5) tensor. + """ + N, H, W, K, _, _ = splat_colors_and_weights.shape + # Transform splat_colors such that each of the 9 layers (corresponding to + # the 9 splat offsets) is padded with 1 and shifted in the appropriate + # direction. E.g. splat_colors[n, :, :, 0] corresponds to the (-1, -1) + # offset, so will be padded with one rows of 1 on the right and have a + # single row clipped at the bottom, and splat_colors[n, :, :, 4] corrsponds + # to offset (0, 0) and will remain unchanged. + splat_colors_and_weights = F.pad( + splat_colors_and_weights, [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0] + ) # N, H+2, W+2, 9, 5 + + # (N, H+2, W+2, K, 9, 5) -> (N, H, W+2, K, 9, 5) + splat_colors_and_weights = torch.gather( + splat_colors_and_weights, dim=1, index=crop_ids_h + ) + + # (N, H, W+2, K, 9, 5) -> (N, H, W, K, 9, 5) + splat_colors_and_weights = torch.gather( + splat_colors_and_weights, dim=2, index=crop_ids_w + ) + + return splat_colors_and_weights + + +def _compute_splatted_colors_and_weights( + occlusion_layers: torch.Tensor, # (N, H, W, 9) + splat_colors_and_weights: torch.Tensor, # (N, H, W, K, 9, 5) +) -> Tuple[torch.Tensor, torch.Tensor]: + """ + Accumulate splatted colors in background, surface and foreground occlusion buffers. + + Args: + occlusion_layers: (N, H, W, 9) tensor. See _compute_occlusion_layers. + splat_colors_and_weights: (N, H, W, K, 9, 5) tensor. See _offset_splats. + + Returns: + splatted_colors: (N, H, W, 4, 3) tensor. Last dimension corresponds to back- + ground, surface, and foreground splat colors. + splatted_weights: (N, H, W, 1, 3) tensor. Last dimension corresponds to back- + ground, surface, and foreground splat weights and is used for normalization. + + """ + N, H, W, K, _, _ = splat_colors_and_weights.shape + + # Create an occlusion mask, with the last dimension of length 3, corresponding to + # background/surface/foreground splatting. E.g. occlusion_layer_mask[n,h,w,k,d,0] is + # 1 if the pixel at hw is splatted from direction d such that the splatting pixel p + # is below the splatted pixel q (in the background); otherwise, the value is 0. + # occlusion_layer_mask[n,h,w,k,d,1] is 1 if the splatting pixel is at the same + # surface level as the splatted pixel q, and occlusion_layer_mask[n,h,w,k,d,2] is + # 1 only if the splatting pixel is in the foreground. + layer_ids = torch.arange(K, device=splat_colors_and_weights.device).view( + 1, 1, 1, K, 1 + ) + occlusion_layers = occlusion_layers.view(N, H, W, 1, 9) + occlusion_layer_mask = torch.stack( + [ + occlusion_layers > layer_ids, # (N, H, W, K, 9) + occlusion_layers == layer_ids, # (N, H, W, K, 9) + occlusion_layers < layer_ids, # (N, H, W, K, 9) + ], + dim=5, + ).float() # (N, H, W, K, 9, 3) + + # (N * H * W, 5, 9 * K) x (N * H * W, 9 * K, 3) -> (N * H * W, 5, 3) + splatted_colors_and_weights = torch.bmm( + splat_colors_and_weights.permute(0, 1, 2, 5, 3, 4).reshape( + (N * H * W, 5, K * 9) + ), + occlusion_layer_mask.reshape((N * H * W, K * 9, 3)), + ).reshape((N, H, W, 5, 3)) + + return ( + splatted_colors_and_weights[..., :4, :], + splatted_colors_and_weights[..., 4:5, :], + ) + + +def _normalize_and_compose_all_layers( + background_color: torch.Tensor, + splatted_colors_per_occlusion_layer: torch.Tensor, + splatted_weights_per_occlusion_layer: torch.Tensor, +) -> torch.Tensor: + """ + Normalize each bg/surface/fg buffer by its weight, and compose. + + Args: + background_color: (3) RGB tensor. + splatter_colors_per_occlusion_layer: (N, H, W, 4, 3) RGBA tensor, last dimension + corresponds to foreground, surface, and background splatting. + splatted_weights_per_occlusion_layer: (N, H, W, 1, 3) weight tensor. + + Returns: + output_colors: (N, H, W, 4) RGBA tensor. + """ + device = splatted_colors_per_occlusion_layer.device + + # Normalize each of bg/surface/fg splat layers separately. + normalization_scales = 1.0 / ( + # pyre-fixme[58]: `/` is not supported for operand types `float` and `Tensor`. + torch.maximum( + splatted_weights_per_occlusion_layer, + torch.tensor([1.0], device=device), + ) + ) # (N, H, W, 1, 3) + + normalized_splatted_colors = ( + splatted_colors_per_occlusion_layer * normalization_scales + ) # (N, H, W, 4, 3) + + # Use alpha-compositing to compose the splat layers. + output_colors = torch.cat( + [background_color, torch.tensor([0.0], device=device)] + ) # (4), will broadcast to (N, H, W, 4) below. + + for occlusion_layer_id in (-1, -2, -3): + # Over-compose the bg, surface, and fg occlusion layers. Note that we already + # multiplied each pixel's RGBA by its own alpha as part of self-splatting in + # _compute_splatting_colors_and_weights, so we don't re-multiply by alpha here. + alpha = normalized_splatted_colors[..., 3:4, occlusion_layer_id] # (N, H, W, 1) + output_colors = ( + normalized_splatted_colors[..., occlusion_layer_id] + + (1.0 - alpha) * output_colors + ) + return output_colors + + +class SplatterBlender(torch.nn.Module): + def __init__( + self, + input_shape: Tuple[int, int, int, int], + device, + ): + """ + A splatting blender. See `forward` docs for details of the splatting mechanism. + + Args: + input_shape: Tuple (N, H, W, K) indicating the batch size, image height, + image width, and number of rasterized layers. Used to precompute + constant tensors that do not change as long as this tuple is unchanged. + """ + super().__init__() + self.crop_ids_h, self.crop_ids_w, self.offsets = _precompute( + input_shape, device + ) + + def to(self, device): + self.offsets = self.offsets.to(device) + self.crop_ids_h = self.crop_ids_h.to(device) + self.crop_ids_w = self.crop_ids_w.to(device) + super().to(device) + + def forward( + self, + colors: torch.Tensor, + pixel_coords_cameras: torch.Tensor, + cameras: FoVPerspectiveCameras, + background_mask: torch.Tensor, + blend_params: BlendParams, + ) -> torch.Tensor: + """ + RGB blending using splatting, as proposed in [0]. + + Args: + colors: (N, H, W, K, 3) tensor of RGB colors at each h, w pixel location for + K intersection layers. + pixel_coords_cameras: (N, H, W, K, 3) tensor of pixel coordinates in the + camera frame of reference. It is *crucial* that these are computed by + interpolating triangle vertex positions using barycentric coordinates -- + this allows gradients to travel through pixel_coords_camera back to the + vertex positions. + cameras: Cameras object used to project pixel_coords_cameras screen coords. + background_mask: (N, H, W, K, 3) boolean tensor, True for bg pixels. A pixel + is considered "background" if no mesh triangle projects to it. This is + typically computed by the rasterizer. + blend_params: BlendParams, from which we use sigma (splatting kernel + variance) and background_color. + + Returns: + output_colors: (N, H, W, 4) tensor of RGBA values. The alpha layer is set to + fully transparent in the background. + + [0] Cole, F. et al., "Differentiable Surface Rendering via Non-differentiable + Sampling". + """ + + # Our implementation has 6 stages. In the description below, we will call each + # pixel q and the 9 surrounding splatting pixels (including itself) p. + # 1. Use barycentrics to compute the position of each pixel in screen + # coordinates. These should exactly correspond to pixel centers during the + # forward pass, but can be shifted on backwards. This step allows gradients to + # travel to vertex coordinates, even if the rasterizer is non-differentiable. + # 2a. For each center pixel q, take each splatting p and decide whether it + # is on the same surface level as q, or in the background or foreground. + # 2b. For each center pixel q, compute the splatting weight of surrounding + # pixels p, and their splatting colors (which are just the original colors + # weighted by the splatting weights). + # 3. As a vectorization technicality, offset the tensors corresponding to + # the splatting p values in the nine directions, by padding each of nine + # splatting layers on the bottom/top, left/right. + # 4. Do the actual splatting, by accumulating the splatting colors of the + # surrounding p's for each pixel q. The weights get accumulated separately for + # p's that got assigned to the background/surface/foreground in Step 2a. + # 5. Normalize each the splatted bg/surface/fg colors for each q, and + # compose the resulting color maps. + # + # Note that it is crucial that in Step 1 we compute the pixel coordinates by in- + # terpolating triangle vertices using barycentric coords from the rasterizer. In + # our case, these pixel_coords_camera are computed by the shader and passed to + # this function to avoid re-computation. + + pixel_coords_screen, colors = _prepare_pixels_and_colors( + pixel_coords_cameras, colors, cameras, background_mask + ) # (N, H, W, K, 3) and (N, H, W, K, 4) + + occlusion_layers = _compute_occlusion_layers( + pixel_coords_screen[..., 2:3].squeeze(dim=-1) + ) # (N, H, W, 9) + + splat_colors_and_weights = _compute_splatting_colors_and_weights( + pixel_coords_screen, + colors, + blend_params.sigma, + self.offsets, + ) # (N, H, W, K, 9, 5) + + splat_colors_and_weights = _offset_splats( + splat_colors_and_weights, + self.crop_ids_h, + self.crop_ids_w, + ) # (N, H, W, K, 9, 5) + + ( + splatted_colors_per_occlusion_layer, + splatted_weights_per_occlusion_layer, + ) = _compute_splatted_colors_and_weights( + occlusion_layers, splat_colors_and_weights + ) # (N, H, W, 4, 3) and (N, H, W, 1, 3) + + output_colors = _normalize_and_compose_all_layers( + _get_background_color(blend_params, colors.device), + splatted_colors_per_occlusion_layer, + splatted_weights_per_occlusion_layer, + ) # (N, H, W, 4) + + return output_colors diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/utils.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/utils.py new file mode 100644 index 0000000000000000000000000000000000000000..ac7e8c85d2e7c9b8f7d5e27cc1624fb632b90be2 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/renderer/utils.py @@ -0,0 +1,462 @@ +# 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. + +# pyre-unsafe + + +import copy +import inspect +import warnings +from typing import Any, List, Optional, Tuple, TypeVar, Union + +import numpy as np +import torch +import torch.nn as nn + +from ..common.datatypes import Device, make_device + + +class TensorAccessor(nn.Module): + """ + A helper class to be used with the __getitem__ method. This can be used for + getting/setting the values for an attribute of a class at one particular + index. This is useful when the attributes of a class are batched tensors + and one element in the batch needs to be modified. + """ + + def __init__(self, class_object, index: Union[int, slice]) -> None: + """ + Args: + class_object: this should be an instance of a class which has + attributes which are tensors representing a batch of + values. + index: int/slice, an index indicating the position in the batch. + In __setattr__ and __getattr__ only the value of class + attributes at this index will be accessed. + """ + self.__dict__["class_object"] = class_object + self.__dict__["index"] = index + + def __setattr__(self, name: str, value: Any): + """ + Update the attribute given by `name` to the value given by `value` + at the index specified by `self.index`. + + Args: + name: str, name of the attribute. + value: value to set the attribute to. + """ + v = getattr(self.class_object, name) + if not torch.is_tensor(v): + msg = "Can only set values on attributes which are tensors; got %r" + raise AttributeError(msg % type(v)) + + # Convert the attribute to a tensor if it is not a tensor. + if not torch.is_tensor(value): + value = torch.tensor( + value, device=v.device, dtype=v.dtype, requires_grad=v.requires_grad + ) + + # Check the shapes match the existing shape and the shape of the index. + if v.dim() > 1 and value.dim() > 1 and value.shape[1:] != v.shape[1:]: + msg = "Expected value to have shape %r; got %r" + raise ValueError(msg % (v.shape, value.shape)) + if ( + v.dim() == 0 + and isinstance(self.index, slice) + and len(value) != len(self.index) + ): + msg = "Expected value to have len %r; got %r" + raise ValueError(msg % (len(self.index), len(value))) + self.class_object.__dict__[name][self.index] = value + + def __getattr__(self, name: str): + """ + Return the value of the attribute given by "name" on self.class_object + at the index specified in self.index. + + Args: + name: string of the attribute name + """ + if hasattr(self.class_object, name): + return self.class_object.__dict__[name][self.index] + else: + msg = "Attribute %s not found on %r" + return AttributeError(msg % (name, self.class_object.__name__)) + + +BROADCAST_TYPES = (float, int, list, tuple, torch.Tensor, np.ndarray) + + +class TensorProperties(nn.Module): + """ + A mix-in class for storing tensors as properties with helper methods. + """ + + def __init__( + self, + dtype: torch.dtype = torch.float32, + device: Device = "cpu", + **kwargs, + ) -> None: + """ + Args: + dtype: data type to set for the inputs + device: Device (as str or torch.device) + kwargs: any number of keyword arguments. Any arguments which are + of type (float/int/list/tuple/tensor/array) are broadcasted and + other keyword arguments are set as attributes. + """ + super().__init__() + self.device = make_device(device) + self._N = 0 + if kwargs is not None: + + # broadcast all inputs which are float/int/list/tuple/tensor/array + # set as attributes anything else e.g. strings, bools + args_to_broadcast = {} + for k, v in kwargs.items(): + if v is None or isinstance(v, (str, bool)): + setattr(self, k, v) + elif isinstance(v, BROADCAST_TYPES): + args_to_broadcast[k] = v + else: + msg = "Arg %s with type %r is not broadcastable" + warnings.warn(msg % (k, type(v))) + + names = args_to_broadcast.keys() + # convert from type dict.values to tuple + values = tuple(v for v in args_to_broadcast.values()) + + if len(values) > 0: + broadcasted_values = convert_to_tensors_and_broadcast( + *values, device=device + ) + + # Set broadcasted values as attributes on self. + for i, n in enumerate(names): + setattr(self, n, broadcasted_values[i]) + if self._N == 0: + self._N = broadcasted_values[i].shape[0] + + def __len__(self) -> int: + return self._N + + def isempty(self) -> bool: + return self._N == 0 + + def __getitem__(self, index: Union[int, slice]) -> TensorAccessor: + """ + + Args: + index: an int or slice used to index all the fields. + + Returns: + if `index` is an index int/slice return a TensorAccessor class + with getattribute/setattribute methods which return/update the value + at the index in the original class. + """ + if isinstance(index, (int, slice)): + return TensorAccessor(class_object=self, index=index) + + msg = "Expected index of type int or slice; got %r" + raise ValueError(msg % type(index)) + + # pyre-fixme[14]: `to` overrides method defined in `Module` inconsistently. + def to(self, device: Device = "cpu") -> "TensorProperties": + """ + In place operation to move class properties which are tensors to a + specified device. If self has a property "device", update this as well. + """ + device_ = make_device(device) + for k in dir(self): + v = getattr(self, k) + if k == "device": + setattr(self, k, device_) + if torch.is_tensor(v) and v.device != device_: + setattr(self, k, v.to(device_)) + return self + + def cpu(self) -> "TensorProperties": + return self.to("cpu") + + # pyre-fixme[14]: `cuda` overrides method defined in `Module` inconsistently. + def cuda(self, device: Optional[int] = None) -> "TensorProperties": + return self.to(f"cuda:{device}" if device is not None else "cuda") + + def clone(self, other) -> "TensorProperties": + """ + Update the tensor properties of other with the cloned properties of self. + """ + for k in dir(self): + v = getattr(self, k) + if inspect.ismethod(v) or k.startswith("__") or type(v) is TypeVar: + continue + if torch.is_tensor(v): + v_clone = v.clone() + else: + v_clone = copy.deepcopy(v) + setattr(other, k, v_clone) + return other + + def gather_props(self, batch_idx) -> "TensorProperties": + """ + This is an in place operation to reformat all tensor class attributes + based on a set of given indices using torch.gather. This is useful when + attributes which are batched tensors e.g. shape (N, 3) need to be + multiplied with another tensor which has a different first dimension + e.g. packed vertices of shape (V, 3). + + Example + + .. code-block:: python + + self.specular_color = (N, 3) tensor of specular colors for each mesh + + A lighting calculation may use + + .. code-block:: python + + verts_packed = meshes.verts_packed() # (V, 3) + + To multiply these two tensors the batch dimension needs to be the same. + To achieve this we can do + + .. code-block:: python + + batch_idx = meshes.verts_packed_to_mesh_idx() # (V) + + This gives index of the mesh for each vertex in verts_packed. + + .. code-block:: python + + self.gather_props(batch_idx) + self.specular_color = (V, 3) tensor with the specular color for + each packed vertex. + + torch.gather requires the index tensor to have the same shape as the + input tensor so this method takes care of the reshaping of the index + tensor to use with class attributes with arbitrary dimensions. + + Args: + batch_idx: shape (B, ...) where `...` represents an arbitrary + number of dimensions + + Returns: + self with all properties reshaped. e.g. a property with shape (N, 3) + is transformed to shape (B, 3). + """ + # Iterate through the attributes of the class which are tensors. + for k in dir(self): + v = getattr(self, k) + if torch.is_tensor(v): + if v.shape[0] > 1: + # There are different values for each batch element + # so gather these using the batch_idx. + # First clone the input batch_idx tensor before + # modifying it. + _batch_idx = batch_idx.clone() + idx_dims = _batch_idx.shape + tensor_dims = v.shape + if len(idx_dims) > len(tensor_dims): + msg = "batch_idx cannot have more dimensions than %s. " + msg += "got shape %r and %s has shape %r" + raise ValueError(msg % (k, idx_dims, k, tensor_dims)) + if idx_dims != tensor_dims: + # To use torch.gather the index tensor (_batch_idx) has + # to have the same shape as the input tensor. + new_dims = len(tensor_dims) - len(idx_dims) + new_shape = idx_dims + (1,) * new_dims + # pyre-fixme[58]: `+` is not supported for operand types + # `Tuple[int]` and `torch._C.Size` + expand_dims = (-1,) + tensor_dims[1:] + _batch_idx = _batch_idx.view(*new_shape) + _batch_idx = _batch_idx.expand(*expand_dims) + + v = v.gather(0, _batch_idx) + setattr(self, k, v) + return self + + +def format_tensor( + input, + dtype: torch.dtype = torch.float32, + device: Device = "cpu", +) -> torch.Tensor: + """ + Helper function for converting a scalar value to a tensor. + + Args: + input: Python scalar, Python list/tuple, torch scalar, 1D torch tensor + dtype: data type for the input + device: Device (as str or torch.device) on which the tensor should be placed. + + Returns: + input_vec: torch tensor with optional added batch dimension. + """ + device_ = make_device(device) + if not torch.is_tensor(input): + input = torch.tensor(input, dtype=dtype, device=device_) + + if input.dim() == 0: + input = input.view(1) + + if input.device == device_: + return input + + input = input.to(device=device) + return input + + +def convert_to_tensors_and_broadcast( + *args, + dtype: torch.dtype = torch.float32, + device: Device = "cpu", +): + """ + Helper function to handle parsing an arbitrary number of inputs (*args) + which all need to have the same batch dimension. + The output is a list of tensors. + + Args: + *args: an arbitrary number of inputs + Each of the values in `args` can be one of the following + - Python scalar + - Torch scalar + - Torch tensor of shape (N, K_i) or (1, K_i) where K_i are + an arbitrary number of dimensions which can vary for each + value in args. In this case each input is broadcast to a + tensor of shape (N, K_i) + dtype: data type to use when creating new tensors. + device: torch device on which the tensors should be placed. + + Output: + args: A list of tensors of shape (N, K_i) + """ + # Convert all inputs to tensors with a batch dimension + args_1d = [format_tensor(c, dtype, device) for c in args] + + # Find broadcast size + sizes = [c.shape[0] for c in args_1d] + N = max(sizes) + + args_Nd = [] + for c in args_1d: + if c.shape[0] != 1 and c.shape[0] != N: + msg = "Got non-broadcastable sizes %r" % sizes + raise ValueError(msg) + + # Expand broadcast dim and keep non broadcast dims the same size + expand_sizes = (N,) + (-1,) * len(c.shape[1:]) + args_Nd.append(c.expand(*expand_sizes)) + + return args_Nd + + +def ndc_grid_sample( + input: torch.Tensor, + grid_ndc: torch.Tensor, + *, + align_corners: bool = False, + **grid_sample_kwargs, +) -> torch.Tensor: + """ + Samples a tensor `input` of shape `(B, dim, H, W)` at 2D locations + specified by a tensor `grid_ndc` of shape `(B, ..., 2)` using + the `torch.nn.functional.grid_sample` function. + `grid_ndc` is specified in PyTorch3D NDC coordinate frame. + + Args: + input: The tensor of shape `(B, dim, H, W)` to be sampled. + grid_ndc: A tensor of shape `(B, ..., 2)` denoting the set of + 2D locations at which `input` is sampled. + See [1] for a detailed description of the NDC coordinates. + align_corners: Forwarded to the `torch.nn.functional.grid_sample` + call. See its docstring. + grid_sample_kwargs: Additional arguments forwarded to the + `torch.nn.functional.grid_sample` call. See the corresponding + docstring for a listing of the corresponding arguments. + + Returns: + sampled_input: A tensor of shape `(B, dim, ...)` containing the samples + of `input` at 2D locations `grid_ndc`. + + References: + [1] https://pytorch3d.org/docs/cameras + """ + + batch, *spatial_size, pt_dim = grid_ndc.shape + if batch != input.shape[0]: + raise ValueError("'input' and 'grid_ndc' have to have the same batch size.") + if input.ndim != 4: + raise ValueError("'input' has to be a 4-dimensional Tensor.") + if pt_dim != 2: + raise ValueError("The last dimension of 'grid_ndc' has to be == 2.") + + grid_ndc_flat = grid_ndc.reshape(batch, -1, 1, 2) + + # pyre-fixme[6]: For 2nd param expected `Tuple[int, int]` but got `Size`. + grid_flat = ndc_to_grid_sample_coords(grid_ndc_flat, input.shape[2:]) + + sampled_input_flat = torch.nn.functional.grid_sample( + input, grid_flat, align_corners=align_corners, **grid_sample_kwargs + ) + + sampled_input = sampled_input_flat.reshape([batch, input.shape[1], *spatial_size]) + + return sampled_input + + +def ndc_to_grid_sample_coords( + xy_ndc: torch.Tensor, + image_size_hw: Tuple[int, int], +) -> torch.Tensor: + """ + Convert from the PyTorch3D's NDC coordinates to + `torch.nn.functional.grid_sampler`'s coordinates. + + Args: + xy_ndc: Tensor of shape `(..., 2)` containing 2D points in the + PyTorch3D's NDC coordinates. + image_size_hw: A tuple `(image_height, image_width)` denoting the + height and width of the image tensor to sample. + Returns: + xy_grid_sample: Tensor of shape `(..., 2)` containing 2D points in the + `torch.nn.functional.grid_sample` coordinates. + """ + if len(image_size_hw) != 2 or any(s <= 0 for s in image_size_hw): + raise ValueError("'image_size_hw' has to be a 2-tuple of positive integers") + aspect = min(image_size_hw) / max(image_size_hw) + xy_grid_sample = -xy_ndc # first negate the coords + if image_size_hw[0] >= image_size_hw[1]: + xy_grid_sample[..., 1] *= aspect + else: + xy_grid_sample[..., 0] *= aspect + return xy_grid_sample + + +def parse_image_size( + image_size: Union[List[int], Tuple[int, int], int] +) -> Tuple[int, int]: + """ + Args: + image_size: A single int (for square images) or a tuple/list of two ints. + + Returns: + A tuple of two ints. + + Throws: + ValueError if got more than two ints, any negative numbers or non-ints. + """ + if not isinstance(image_size, (tuple, list)): + return (image_size, image_size) + if len(image_size) != 2: + raise ValueError("Image size can only be a tuple/list of (H, W)") + if not all(i > 0 for i in image_size): + raise ValueError("Image sizes must be greater than 0; got %d, %d" % image_size) + if not all(isinstance(i, int) for i in image_size): + raise ValueError("Image sizes must be integers; got %f, %f" % image_size) + return tuple(image_size) diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/structures/__init__.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/structures/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..7ed0194a4fbfa2d68bb113c96e1c0d4e70c4debf --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/structures/__init__.py @@ -0,0 +1,19 @@ +# 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. + +# pyre-unsafe + +from .meshes import join_meshes_as_batch, join_meshes_as_scene, Meshes +from .pointclouds import ( + join_pointclouds_as_batch, + join_pointclouds_as_scene, + Pointclouds, +) +from .utils import list_to_packed, list_to_padded, packed_to_list, padded_to_list +from .volumes import Volumes + + +__all__ = [k for k in globals().keys() if not k.startswith("_")] diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/structures/meshes.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/structures/meshes.py new file mode 100644 index 0000000000000000000000000000000000000000..53f3f454aa663ace0246bcecc2a4ff268e2d646a --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/structures/meshes.py @@ -0,0 +1,1752 @@ +# 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. + +# pyre-unsafe + +from typing import List, Union + +import torch + +from ..common.datatypes import Device, make_device +from . import utils as struct_utils + + +class Meshes: + """ + This class provides functions for working with batches of triangulated + meshes with varying numbers of faces and vertices, and converting between + representations. + + Within Meshes, there are three different representations of the faces and + verts data: + + List + - only used for input as a starting point to convert to other representations. + Padded + - has specific batch dimension. + Packed + - no batch dimension. + - has auxiliary variables used to index into the padded representation. + + Example: + + Input list of verts V_n = [[V_1], [V_2], ... , [V_N]] + where V_1, ... , V_N are the number of verts in each mesh and N is the + number of meshes. + + Input list of faces F_n = [[F_1], [F_2], ... , [F_N]] + where F_1, ... , F_N are the number of faces in each mesh. + + # SPHINX IGNORE + List | Padded | Packed + ---------------------------|-------------------------|------------------------ + [[V_1], ... , [V_N]] | size = (N, max(V_n), 3) | size = (sum(V_n), 3) + | | + Example for verts: | | + | | + V_1 = 3, V_2 = 4, V_3 = 5 | size = (3, 5, 3) | size = (12, 3) + | | + List([ | tensor([ | tensor([ + [ | [ | [0.1, 0.3, 0.5], + [0.1, 0.3, 0.5], | [0.1, 0.3, 0.5], | [0.5, 0.2, 0.1], + [0.5, 0.2, 0.1], | [0.5, 0.2, 0.1], | [0.6, 0.8, 0.7], + [0.6, 0.8, 0.7], | [0.6, 0.8, 0.7], | [0.1, 0.3, 0.3], + ], | [0, 0, 0], | [0.6, 0.7, 0.8], + [ | [0, 0, 0], | [0.2, 0.3, 0.4], + [0.1, 0.3, 0.3], | ], | [0.1, 0.5, 0.3], + [0.6, 0.7, 0.8], | [ | [0.7, 0.3, 0.6], + [0.2, 0.3, 0.4], | [0.1, 0.3, 0.3], | [0.2, 0.4, 0.8], + [0.1, 0.5, 0.3], | [0.6, 0.7, 0.8], | [0.9, 0.5, 0.2], + ], | [0.2, 0.3, 0.4], | [0.2, 0.3, 0.4], + [ | [0.1, 0.5, 0.3], | [0.9, 0.3, 0.8], + [0.7, 0.3, 0.6], | [0, 0, 0], | ]) + [0.2, 0.4, 0.8], | ], | + [0.9, 0.5, 0.2], | [ | + [0.2, 0.3, 0.4], | [0.7, 0.3, 0.6], | + [0.9, 0.3, 0.8], | [0.2, 0.4, 0.8], | + ] | [0.9, 0.5, 0.2], | + ]) | [0.2, 0.3, 0.4], | + | [0.9, 0.3, 0.8], | + | ] | + | ]) | + Example for faces: | | + | | + F_1 = 1, F_2 = 2, F_3 = 7 | size = (3, 7, 3) | size = (10, 3) + | | + List([ | tensor([ | tensor([ + [ | [ | [ 0, 1, 2], + [0, 1, 2], | [0, 1, 2], | [ 3, 4, 5], + ], | [-1, -1, -1], | [ 4, 5, 6], + [ | [-1, -1, -1] | [ 8, 9, 7], + [0, 1, 2], | [-1, -1, -1] | [ 7, 8, 10], + [1, 2, 3], | [-1, -1, -1] | [ 9, 10, 8], + ], | [-1, -1, -1], | [11, 10, 9], + [ | [-1, -1, -1], | [11, 7, 8], + [1, 2, 0], | ], | [11, 10, 8], + [0, 1, 3], | [ | [11, 9, 8], + [2, 3, 1], | [0, 1, 2], | ]) + [4, 3, 2], | [1, 2, 3], | + [4, 0, 1], | [-1, -1, -1], | + [4, 3, 1], | [-1, -1, -1], | + [4, 2, 1], | [-1, -1, -1], | + ], | [-1, -1, -1], | + ]) | [-1, -1, -1], | + | ], | + | [ | + | [1, 2, 0], | + | [0, 1, 3], | + | [2, 3, 1], | + | [4, 3, 2], | + | [4, 0, 1], | + | [4, 3, 1], | + | [4, 2, 1], | + | ] | + | ]) | + ----------------------------------------------------------------------------- + + Auxiliary variables for packed representation + + Name | Size | Example from above + -------------------------------|---------------------|----------------------- + | | + verts_packed_to_mesh_idx | size = (sum(V_n)) | tensor([ + | | 0, 0, 0, 1, 1, 1, + | | 1, 2, 2, 2, 2, 2 + | | )] + | | size = (12) + | | + mesh_to_verts_packed_first_idx | size = (N) | tensor([0, 3, 7]) + | | size = (3) + | | + num_verts_per_mesh | size = (N) | tensor([3, 4, 5]) + | | size = (3) + | | + faces_packed_to_mesh_idx | size = (sum(F_n)) | tensor([ + | | 0, 1, 1, 2, 2, 2, + | | 2, 2, 2, 2 + | | )] + | | size = (10) + | | + mesh_to_faces_packed_first_idx | size = (N) | tensor([0, 1, 3]) + | | size = (3) + | | + num_faces_per_mesh | size = (N) | tensor([1, 2, 7]) + | | size = (3) + | | + verts_padded_to_packed_idx | size = (sum(V_n)) | tensor([ + | | 0, 1, 2, 5, 6, 7, + | | 8, 10, 11, 12, 13, + | | 14 + | | )] + | | size = (12) + ----------------------------------------------------------------------------- + # SPHINX IGNORE + + From the faces, edges are computed and have packed and padded + representations with auxiliary variables. + + E_n = [[E_1], ... , [E_N]] + where E_1, ... , E_N are the number of unique edges in each mesh. + Total number of unique edges = sum(E_n) + + # SPHINX IGNORE + Name | Size | Example from above + -------------------------------|-------------------------|---------------------- + | | + edges_packed | size = (sum(E_n), 2) | tensor([ + | | [0, 1], + | | [0, 2], + | | [1, 2], + | | ... + | | [10, 11], + | | )] + | | size = (18, 2) + | | + num_edges_per_mesh | size = (N) | tensor([3, 5, 10]) + | | size = (3) + | | + edges_packed_to_mesh_idx | size = (sum(E_n)) | tensor([ + | | 0, 0, 0, + | | . . . + | | 2, 2, 2 + | | ]) + | | size = (18) + | | + faces_packed_to_edges_packed | size = (sum(F_n), 3) | tensor([ + | | [2, 1, 0], + | | [5, 4, 3], + | | . . . + | | [12, 14, 16], + | | ]) + | | size = (10, 3) + | | + mesh_to_edges_packed_first_idx | size = (N) | tensor([0, 3, 8]) + | | size = (3) + ---------------------------------------------------------------------------- + # SPHINX IGNORE + """ + + _INTERNAL_TENSORS = [ + "_verts_packed", + "_verts_packed_to_mesh_idx", + "_mesh_to_verts_packed_first_idx", + "_verts_padded", + "_num_verts_per_mesh", + "_faces_packed", + "_faces_packed_to_mesh_idx", + "_mesh_to_faces_packed_first_idx", + "_faces_padded", + "_faces_areas_packed", + "_verts_normals_packed", + "_faces_normals_packed", + "_num_faces_per_mesh", + "_edges_packed", + "_edges_packed_to_mesh_idx", + "_mesh_to_edges_packed_first_idx", + "_faces_packed_to_edges_packed", + "_num_edges_per_mesh", + "_verts_padded_to_packed_idx", + "_laplacian_packed", + "valid", + "equisized", + ] + + def __init__( + self, + verts, + faces, + textures=None, + *, + verts_normals=None, + ) -> None: + """ + Args: + verts: + Can be either + + - List where each element is a tensor of shape (num_verts, 3) + containing the (x, y, z) coordinates of each vertex. + - Padded float tensor with shape (num_meshes, max_num_verts, 3). + Meshes should be padded with fill value of 0 so they all have + the same number of vertices. + faces: + Can be either + + - List where each element is a tensor of shape (num_faces, 3) + containing the indices of the 3 vertices in the corresponding + mesh in verts which form the triangular face. + - Padded long tensor of shape (num_meshes, max_num_faces, 3). + Meshes should be padded with fill value of -1 so they have + the same number of faces. + textures: Optional instance of the Textures class with mesh + texture properties. + verts_normals: + Optional. Can be either + + - List where each element is a tensor of shape (num_verts, 3) + containing the normals of each vertex. + - Padded float tensor with shape (num_meshes, max_num_verts, 3). + They should be padded with fill value of 0 so they all have + the same number of vertices. + Note that modifying the mesh later, e.g. with offset_verts_, + can cause these normals to be forgotten and normals to be recalculated + based on the new vertex positions. + + Refer to comments above for descriptions of List and Padded representations. + """ + self.device = torch.device("cpu") + if textures is not None and not hasattr(textures, "sample_textures"): + msg = "Expected textures to be an instance of type TexturesBase; got %r" + raise ValueError(msg % type(textures)) + + self.textures = textures + + # Indicates whether the meshes in the list/batch have the same number + # of faces and vertices. + self.equisized = False + + # Boolean indicator for each mesh in the batch + # True if mesh has non zero number of verts and face, False otherwise. + self.valid = None + + self._N = 0 # batch size (number of meshes) + self._V = 0 # (max) number of vertices per mesh + self._F = 0 # (max) number of faces per mesh + + # List of Tensors of verts and faces. + self._verts_list = None + self._faces_list = None + + # Packed representation for verts. + self._verts_packed = None # (sum(V_n), 3) + self._verts_packed_to_mesh_idx = None # sum(V_n) + + # Index to convert verts from flattened padded to packed + self._verts_padded_to_packed_idx = None # N * max_V + + # Index of each mesh's first vert in the packed verts. + # Assumes packing is sequential. + self._mesh_to_verts_packed_first_idx = None # N + + # Packed representation for faces. + self._faces_packed = None # (sum(F_n), 3) + self._faces_packed_to_mesh_idx = None # sum(F_n) + + # Index of each mesh's first face in packed faces. + # Assumes packing is sequential. + self._mesh_to_faces_packed_first_idx = None # N + + # Packed representation of edges sorted by index of the first vertex + # in the edge. Edges can be shared between faces in a mesh. + self._edges_packed = None # (sum(E_n), 2) + + # Map from packed edges to corresponding mesh index. + self._edges_packed_to_mesh_idx = None # sum(E_n) + self._num_edges_per_mesh = None # N + self._mesh_to_edges_packed_first_idx = None # N + + # Map from packed faces to packed edges. This represents the index of + # the edge opposite the vertex for each vertex in the face. E.g. + # + # v0 + # /\ + # / \ + # e1 / \ e2 + # / \ + # /________\ + # v2 e0 v1 + # + # Face (v0, v1, v2) => Edges (e0, e1, e2) + self._faces_packed_to_edges_packed = None # (sum(F_n), 3) + + # Padded representation of verts. + self._verts_padded = None # (N, max(V_n), 3) + self._num_verts_per_mesh = None # N + + # Padded representation of faces. + self._faces_padded = None # (N, max(F_n), 3) + self._num_faces_per_mesh = None # N + + # Face areas + self._faces_areas_packed = None + + # Normals + self._verts_normals_packed = None + self._faces_normals_packed = None + + # Packed representation of Laplacian Matrix + self._laplacian_packed = None + + # Identify type of verts and faces. + if isinstance(verts, list) and isinstance(faces, list): + self._verts_list = verts + self._faces_list = [ + f[f.gt(-1).all(1)].to(torch.int64) if len(f) > 0 else f for f in faces + ] + self._N = len(self._verts_list) + self.valid = torch.zeros((self._N,), dtype=torch.bool, device=self.device) + if self._N > 0: + self.device = self._verts_list[0].device + if not ( + all(v.device == self.device for v in verts) + and all(f.device == self.device for f in faces) + ): + raise ValueError( + "All Verts and Faces tensors should be on same device." + ) + self._num_verts_per_mesh = torch.tensor( + [len(v) for v in self._verts_list], device=self.device + ) + self._V = int(self._num_verts_per_mesh.max()) + self._num_faces_per_mesh = torch.tensor( + [len(f) for f in self._faces_list], device=self.device + ) + self._F = int(self._num_faces_per_mesh.max()) + self.valid = torch.tensor( + [ + len(v) > 0 and len(f) > 0 + for (v, f) in zip(self._verts_list, self._faces_list) + ], + dtype=torch.bool, + device=self.device, + ) + if (len(self._num_verts_per_mesh.unique()) == 1) and ( + len(self._num_faces_per_mesh.unique()) == 1 + ): + self.equisized = True + + elif torch.is_tensor(verts) and torch.is_tensor(faces): + if verts.size(2) != 3 or faces.size(2) != 3: + raise ValueError("Verts or Faces tensors have incorrect dimensions.") + self._verts_padded = verts + self._faces_padded = faces.to(torch.int64) + self._N = self._verts_padded.shape[0] + self._V = self._verts_padded.shape[1] + + if verts.device != faces.device: + msg = "Verts and Faces tensors should be on same device. \n Got {} and {}." + raise ValueError(msg.format(verts.device, faces.device)) + + self.device = self._verts_padded.device + self.valid = torch.zeros((self._N,), dtype=torch.bool, device=self.device) + if self._N > 0: + # Check that padded faces - which have value -1 - are at the + # end of the tensors + faces_not_padded = self._faces_padded.gt(-1).all(2) + self._num_faces_per_mesh = faces_not_padded.sum(1) + if (faces_not_padded[:, :-1] < faces_not_padded[:, 1:]).any(): + raise ValueError("Padding of faces must be at the end") + + # NOTE that we don't check for the ordering of padded verts + # as long as the faces index correspond to the right vertices. + + self.valid = self._num_faces_per_mesh > 0 + self._F = int(self._num_faces_per_mesh.max()) + if len(self._num_faces_per_mesh.unique()) == 1: + self.equisized = True + + self._num_verts_per_mesh = torch.full( + size=(self._N,), + fill_value=self._V, + dtype=torch.int64, + device=self.device, + ) + + else: + raise ValueError( + "Verts and Faces must be either a list or a tensor with \ + shape (batch_size, N, 3) where N is either the maximum \ + number of verts or faces respectively." + ) + + if self.isempty(): + self._num_verts_per_mesh = torch.zeros( + (0,), dtype=torch.int64, device=self.device + ) + self._num_faces_per_mesh = torch.zeros( + (0,), dtype=torch.int64, device=self.device + ) + + # Set the num verts/faces on the textures if present. + if textures is not None: + shape_ok = self.textures.check_shapes(self._N, self._V, self._F) + if not shape_ok: + msg = "Textures do not match the dimensions of Meshes." + raise ValueError(msg) + + self.textures._num_faces_per_mesh = self._num_faces_per_mesh.tolist() + self.textures._num_verts_per_mesh = self._num_verts_per_mesh.tolist() + self.textures.valid = self.valid + + if verts_normals is not None: + self._set_verts_normals(verts_normals) + + def _set_verts_normals(self, verts_normals) -> None: + if isinstance(verts_normals, list): + if len(verts_normals) != self._N: + raise ValueError("Invalid verts_normals input") + + for item, n_verts in zip(verts_normals, self._num_verts_per_mesh): + if ( + not isinstance(item, torch.Tensor) + or item.ndim != 2 + or item.shape[1] != 3 + or item.shape[0] != n_verts + ): + raise ValueError("Invalid verts_normals input") + self._verts_normals_packed = torch.cat(verts_normals, 0) + elif torch.is_tensor(verts_normals): + if ( + verts_normals.ndim != 3 + or verts_normals.size(2) != 3 + or verts_normals.size(0) != self._N + ): + raise ValueError("Vertex normals tensor has incorrect dimensions.") + self._verts_normals_packed = struct_utils.padded_to_packed( + verts_normals, split_size=self._num_verts_per_mesh.tolist() + ) + else: + raise ValueError("verts_normals must be a list or tensor") + + def __len__(self) -> int: + return self._N + + def __getitem__( + self, index: Union[int, List[int], slice, torch.BoolTensor, torch.LongTensor] + ) -> "Meshes": + """ + Args: + index: Specifying the index of the mesh to retrieve. + Can be an int, slice, list of ints or a boolean tensor. + + Returns: + Meshes object with selected meshes. The mesh tensors are not cloned. + """ + if isinstance(index, (int, slice)): + verts = self.verts_list()[index] + faces = self.faces_list()[index] + elif isinstance(index, list): + verts = [self.verts_list()[i] for i in index] + faces = [self.faces_list()[i] for i in index] + elif isinstance(index, torch.Tensor): + if index.dim() != 1 or index.dtype.is_floating_point: + raise IndexError(index) + # NOTE consider converting index to cpu for efficiency + if index.dtype == torch.bool: + # advanced indexing on a single dimension + index = index.nonzero() + index = index.squeeze(1) if index.numel() > 0 else index + index = index.tolist() + verts = [self.verts_list()[i] for i in index] + faces = [self.faces_list()[i] for i in index] + else: + raise IndexError(index) + + textures = None if self.textures is None else self.textures[index] + + if torch.is_tensor(verts) and torch.is_tensor(faces): + return self.__class__(verts=[verts], faces=[faces], textures=textures) + elif isinstance(verts, list) and isinstance(faces, list): + return self.__class__(verts=verts, faces=faces, textures=textures) + else: + raise ValueError("(verts, faces) not defined correctly") + + def isempty(self) -> bool: + """ + Checks whether any mesh is valid. + + Returns: + bool indicating whether there is any data. + """ + return self._N == 0 or self.valid.eq(False).all() + + def verts_list(self): + """ + Get the list representation of the vertices. + + Returns: + list of tensors of vertices of shape (V_n, 3). + """ + if self._verts_list is None: + assert ( + self._verts_padded is not None + ), "verts_padded is required to compute verts_list." + self._verts_list = struct_utils.padded_to_list( + self._verts_padded, self.num_verts_per_mesh().tolist() + ) + return self._verts_list + + def faces_list(self): + """ + Get the list representation of the faces. + + Returns: + list of tensors of faces of shape (F_n, 3). + """ + if self._faces_list is None: + assert ( + self._faces_padded is not None + ), "faces_padded is required to compute faces_list." + self._faces_list = struct_utils.padded_to_list( + self._faces_padded, self.num_faces_per_mesh().tolist() + ) + return self._faces_list + + def verts_packed(self): + """ + Get the packed representation of the vertices. + + Returns: + tensor of vertices of shape (sum(V_n), 3). + """ + self._compute_packed() + return self._verts_packed + + def verts_packed_to_mesh_idx(self): + """ + Return a 1D tensor with the same first dimension as verts_packed. + verts_packed_to_mesh_idx[i] gives the index of the mesh which contains + verts_packed[i]. + + Returns: + 1D tensor of indices. + """ + self._compute_packed() + return self._verts_packed_to_mesh_idx + + def mesh_to_verts_packed_first_idx(self): + """ + Return a 1D tensor x with length equal to the number of meshes such that + the first vertex of the ith mesh is verts_packed[x[i]]. + + Returns: + 1D tensor of indices of first items. + """ + self._compute_packed() + return self._mesh_to_verts_packed_first_idx + + def num_verts_per_mesh(self): + """ + Return a 1D tensor x with length equal to the number of meshes giving + the number of vertices in each mesh. + + Returns: + 1D tensor of sizes. + """ + return self._num_verts_per_mesh + + def faces_packed(self): + """ + Get the packed representation of the faces. + Faces are given by the indices of the three vertices in verts_packed. + + Returns: + tensor of faces of shape (sum(F_n), 3). + """ + self._compute_packed() + return self._faces_packed + + def faces_packed_to_mesh_idx(self): + """ + Return a 1D tensor with the same first dimension as faces_packed. + faces_packed_to_mesh_idx[i] gives the index of the mesh which contains + faces_packed[i]. + + Returns: + 1D tensor of indices. + """ + self._compute_packed() + return self._faces_packed_to_mesh_idx + + def mesh_to_faces_packed_first_idx(self): + """ + Return a 1D tensor x with length equal to the number of meshes such that + the first face of the ith mesh is faces_packed[x[i]]. + + Returns: + 1D tensor of indices of first items. + """ + self._compute_packed() + return self._mesh_to_faces_packed_first_idx + + def verts_padded(self): + """ + Get the padded representation of the vertices. + + Returns: + tensor of vertices of shape (N, max(V_n), 3). + """ + self._compute_padded() + return self._verts_padded + + def faces_padded(self): + """ + Get the padded representation of the faces. + + Returns: + tensor of faces of shape (N, max(F_n), 3). + """ + self._compute_padded() + return self._faces_padded + + def num_faces_per_mesh(self): + """ + Return a 1D tensor x with length equal to the number of meshes giving + the number of faces in each mesh. + + Returns: + 1D tensor of sizes. + """ + return self._num_faces_per_mesh + + def edges_packed(self): + """ + Get the packed representation of the edges. + + Returns: + tensor of edges of shape (sum(E_n), 2). + """ + self._compute_edges_packed() + return self._edges_packed + + def edges_packed_to_mesh_idx(self): + """ + Return a 1D tensor with the same first dimension as edges_packed. + edges_packed_to_mesh_idx[i] gives the index of the mesh which contains + edges_packed[i]. + + Returns: + 1D tensor of indices. + """ + self._compute_edges_packed() + return self._edges_packed_to_mesh_idx + + def mesh_to_edges_packed_first_idx(self): + """ + Return a 1D tensor x with length equal to the number of meshes such that + the first edge of the ith mesh is edges_packed[x[i]]. + + Returns: + 1D tensor of indices of first items. + """ + self._compute_edges_packed() + return self._mesh_to_edges_packed_first_idx + + def faces_packed_to_edges_packed(self): + """ + Get the packed representation of the faces in terms of edges. + Faces are given by the indices of the three edges in + the packed representation of the edges. + + Returns: + tensor of faces of shape (sum(F_n), 3). + """ + self._compute_edges_packed() + return self._faces_packed_to_edges_packed + + def num_edges_per_mesh(self): + """ + Return a 1D tensor x with length equal to the number of meshes giving + the number of edges in each mesh. + + Returns: + 1D tensor of sizes. + """ + self._compute_edges_packed() + return self._num_edges_per_mesh + + def verts_padded_to_packed_idx(self): + """ + Return a 1D tensor x with length equal to the total number of vertices + such that verts_packed()[i] is element x[i] of the flattened padded + representation. + The packed representation can be calculated as follows. + + .. code-block:: python + + p = verts_padded().reshape(-1, 3) + verts_packed = p[x] + + Returns: + 1D tensor of indices. + """ + if self._verts_padded_to_packed_idx is not None: + return self._verts_padded_to_packed_idx + + self._verts_padded_to_packed_idx = torch.cat( + [ + torch.arange(v, dtype=torch.int64, device=self.device) + i * self._V + for (i, v) in enumerate(self.num_verts_per_mesh()) + ], + dim=0, + ) + return self._verts_padded_to_packed_idx + + def has_verts_normals(self) -> bool: + """ + Check whether vertex normals are already present. + """ + return self._verts_normals_packed is not None + + def verts_normals_packed(self): + """ + Get the packed representation of the vertex normals. + + Returns: + tensor of normals of shape (sum(V_n), 3). + """ + self._compute_vertex_normals() + return self._verts_normals_packed + + def verts_normals_list(self): + """ + Get the list representation of the vertex normals. + + Returns: + list of tensors of normals of shape (V_n, 3). + """ + if self.isempty(): + return [ + torch.empty((0, 3), dtype=torch.float32, device=self.device) + ] * self._N + verts_normals_packed = self.verts_normals_packed() + split_size = self.num_verts_per_mesh().tolist() + return struct_utils.packed_to_list(verts_normals_packed, split_size) + + def verts_normals_padded(self): + """ + Get the padded representation of the vertex normals. + + Returns: + tensor of normals of shape (N, max(V_n), 3). + """ + if self.isempty(): + return torch.zeros((self._N, 0, 3), dtype=torch.float32, device=self.device) + verts_normals_list = self.verts_normals_list() + return struct_utils.list_to_padded( + verts_normals_list, (self._V, 3), pad_value=0.0, equisized=self.equisized + ) + + def faces_normals_packed(self): + """ + Get the packed representation of the face normals. + + Returns: + tensor of normals of shape (sum(F_n), 3). + """ + self._compute_face_areas_normals() + return self._faces_normals_packed + + def faces_normals_list(self): + """ + Get the list representation of the face normals. + + Returns: + list of tensors of normals of shape (F_n, 3). + """ + if self.isempty(): + return [ + torch.empty((0, 3), dtype=torch.float32, device=self.device) + ] * self._N + faces_normals_packed = self.faces_normals_packed() + split_size = self.num_faces_per_mesh().tolist() + return struct_utils.packed_to_list(faces_normals_packed, split_size) + + def faces_normals_padded(self): + """ + Get the padded representation of the face normals. + + Returns: + tensor of normals of shape (N, max(F_n), 3). + """ + if self.isempty(): + return torch.zeros((self._N, 0, 3), dtype=torch.float32, device=self.device) + faces_normals_list = self.faces_normals_list() + return struct_utils.list_to_padded( + faces_normals_list, (self._F, 3), pad_value=0.0, equisized=self.equisized + ) + + def faces_areas_packed(self): + """ + Get the packed representation of the face areas. + + Returns: + tensor of areas of shape (sum(F_n),). + """ + self._compute_face_areas_normals() + return self._faces_areas_packed + + def laplacian_packed(self): + self._compute_laplacian_packed() + return self._laplacian_packed + + def _compute_face_areas_normals(self, refresh: bool = False): + """ + Compute the area and normal of each face in faces_packed. + The convention of a normal for a face consisting of verts [v0, v1, v2] + is normal = (v1 - v0) x (v2 - v0) + + Args: + refresh: Set to True to force recomputation of face areas. + Default: False. + """ + from ..ops.mesh_face_areas_normals import mesh_face_areas_normals + + if not ( + refresh + or any( + v is None + for v in [self._faces_areas_packed, self._faces_normals_packed] + ) + ): + return + faces_packed = self.faces_packed() + verts_packed = self.verts_packed() + face_areas, face_normals = mesh_face_areas_normals(verts_packed, faces_packed) + self._faces_areas_packed = face_areas + self._faces_normals_packed = face_normals + + def _compute_vertex_normals(self, refresh: bool = False): + """Computes the packed version of vertex normals from the packed verts + and faces. This assumes verts are shared between faces. The normal for + a vertex is computed as the sum of the normals of all the faces it is + part of weighed by the face areas. + + Args: + refresh: Set to True to force recomputation of vertex normals. + Default: False. + """ + if not (refresh or any(v is None for v in [self._verts_normals_packed])): + return + + if self.isempty(): + self._verts_normals_packed = torch.zeros( + (self._N, 3), dtype=torch.int64, device=self.device + ) + else: + faces_packed = self.faces_packed() + verts_packed = self.verts_packed() + verts_normals = torch.zeros_like(verts_packed) + vertices_faces = verts_packed[faces_packed] + + faces_normals = torch.cross( + vertices_faces[:, 2] - vertices_faces[:, 1], + vertices_faces[:, 0] - vertices_faces[:, 1], + dim=1, + ) + + # NOTE: this is already applying the area weighting as the magnitude + # of the cross product is 2 x area of the triangle. + verts_normals = verts_normals.index_add( + 0, faces_packed[:, 0], faces_normals + ) + verts_normals = verts_normals.index_add( + 0, faces_packed[:, 1], faces_normals + ) + verts_normals = verts_normals.index_add( + 0, faces_packed[:, 2], faces_normals + ) + + self._verts_normals_packed = torch.nn.functional.normalize( + verts_normals, eps=1e-6, dim=1 + ) + + def _compute_padded(self, refresh: bool = False): + """ + Computes the padded version of meshes from verts_list and faces_list. + """ + if not ( + refresh or any(v is None for v in [self._verts_padded, self._faces_padded]) + ): + return + + verts_list = self.verts_list() + faces_list = self.faces_list() + assert ( + faces_list is not None and verts_list is not None + ), "faces_list and verts_list arguments are required" + + if self.isempty(): + self._faces_padded = torch.zeros( + (self._N, 0, 3), dtype=torch.int64, device=self.device + ) + self._verts_padded = torch.zeros( + (self._N, 0, 3), dtype=torch.float32, device=self.device + ) + else: + self._faces_padded = struct_utils.list_to_padded( + faces_list, (self._F, 3), pad_value=-1.0, equisized=self.equisized + ) + self._verts_padded = struct_utils.list_to_padded( + verts_list, (self._V, 3), pad_value=0.0, equisized=self.equisized + ) + + # TODO(nikhilar) Improve performance of _compute_packed. + def _compute_packed(self, refresh: bool = False): + """ + Computes the packed version of the meshes from verts_list and faces_list + and sets the values of auxiliary tensors. + + Args: + refresh: Set to True to force recomputation of packed representations. + Default: False. + """ + + if not ( + refresh + or any( + v is None + for v in [ + self._verts_packed, + self._verts_packed_to_mesh_idx, + self._mesh_to_verts_packed_first_idx, + self._faces_packed, + self._faces_packed_to_mesh_idx, + self._mesh_to_faces_packed_first_idx, + ] + ) + ): + return + + # Packed can be calculated from padded or list, so can call the + # accessor function for verts_list and faces_list. + verts_list = self.verts_list() + faces_list = self.faces_list() + if self.isempty(): + self._verts_packed = torch.zeros( + (0, 3), dtype=torch.float32, device=self.device + ) + self._verts_packed_to_mesh_idx = torch.zeros( + (0,), dtype=torch.int64, device=self.device + ) + self._mesh_to_verts_packed_first_idx = torch.zeros( + (0,), dtype=torch.int64, device=self.device + ) + self._num_verts_per_mesh = torch.zeros( + (0,), dtype=torch.int64, device=self.device + ) + self._faces_packed = -( + torch.ones((0, 3), dtype=torch.int64, device=self.device) + ) + self._faces_packed_to_mesh_idx = torch.zeros( + (0,), dtype=torch.int64, device=self.device + ) + self._mesh_to_faces_packed_first_idx = torch.zeros( + (0,), dtype=torch.int64, device=self.device + ) + self._num_faces_per_mesh = torch.zeros( + (0,), dtype=torch.int64, device=self.device + ) + return + + verts_list_to_packed = struct_utils.list_to_packed(verts_list) + self._verts_packed = verts_list_to_packed[0] + if not torch.allclose(self.num_verts_per_mesh(), verts_list_to_packed[1]): + raise ValueError("The number of verts per mesh should be consistent.") + self._mesh_to_verts_packed_first_idx = verts_list_to_packed[2] + self._verts_packed_to_mesh_idx = verts_list_to_packed[3] + + faces_list_to_packed = struct_utils.list_to_packed(faces_list) + faces_packed = faces_list_to_packed[0] + if not torch.allclose(self.num_faces_per_mesh(), faces_list_to_packed[1]): + raise ValueError("The number of faces per mesh should be consistent.") + self._mesh_to_faces_packed_first_idx = faces_list_to_packed[2] + self._faces_packed_to_mesh_idx = faces_list_to_packed[3] + + faces_packed_offset = self._mesh_to_verts_packed_first_idx[ + self._faces_packed_to_mesh_idx + ] + self._faces_packed = faces_packed + faces_packed_offset.view(-1, 1) + + def _compute_edges_packed(self, refresh: bool = False): + """ + Computes edges in packed form from the packed version of faces and verts. + """ + if not ( + refresh + or any( + v is None + for v in [ + self._edges_packed, + self._faces_packed_to_mesh_idx, + self._edges_packed_to_mesh_idx, + self._num_edges_per_mesh, + self._mesh_to_edges_packed_first_idx, + ] + ) + ): + return + + if self.isempty(): + self._edges_packed = torch.full( + (0, 2), fill_value=-1, dtype=torch.int64, device=self.device + ) + self._edges_packed_to_mesh_idx = torch.zeros( + (0,), dtype=torch.int64, device=self.device + ) + return + + faces = self.faces_packed() + F = faces.shape[0] + v0, v1, v2 = faces.chunk(3, dim=1) + e01 = torch.cat([v0, v1], dim=1) # (sum(F_n), 2) + e12 = torch.cat([v1, v2], dim=1) # (sum(F_n), 2) + e20 = torch.cat([v2, v0], dim=1) # (sum(F_n), 2) + + # All edges including duplicates. + edges = torch.cat([e12, e20, e01], dim=0) # (sum(F_n)*3, 2) + edge_to_mesh = torch.cat( + [ + self._faces_packed_to_mesh_idx, + self._faces_packed_to_mesh_idx, + self._faces_packed_to_mesh_idx, + ], + dim=0, + ) # sum(F_n)*3 + + # Sort the edges in increasing vertex order to remove duplicates as + # the same edge may appear in different orientations in different faces. + # i.e. rows in edges after sorting will be of the form (v0, v1) where v1 > v0. + # This sorting does not change the order in dim=0. + edges, _ = edges.sort(dim=1) + + # Remove duplicate edges: convert each edge (v0, v1) into an + # integer hash = V * v0 + v1; this allows us to use the scalar version of + # unique which is much faster than edges.unique(dim=1) which is very slow. + # After finding the unique elements reconstruct the vertex indices as: + # (v0, v1) = (hash / V, hash % V) + # The inverse maps from unique_edges back to edges: + # unique_edges[inverse_idxs] == edges + # i.e. inverse_idxs[i] == j means that edges[i] == unique_edges[j] + + V = self._verts_packed.shape[0] + edges_hash = V * edges[:, 0] + edges[:, 1] + u, inverse_idxs = torch.unique(edges_hash, return_inverse=True) + + # Find indices of unique elements. + # TODO (nikhilar) remove following 4 lines when torch.unique has support + # for returning unique indices + sorted_hash, sort_idx = torch.sort(edges_hash, dim=0) + unique_mask = torch.ones( + edges_hash.shape[0], dtype=torch.bool, device=self.device + ) + unique_mask[1:] = sorted_hash[1:] != sorted_hash[:-1] + unique_idx = sort_idx[unique_mask] + + self._edges_packed = torch.stack([u // V, u % V], dim=1) + self._edges_packed_to_mesh_idx = edge_to_mesh[unique_idx] + + self._faces_packed_to_edges_packed = inverse_idxs.reshape(3, F).t() + + # Compute number of edges per mesh + num_edges_per_mesh = torch.zeros(self._N, dtype=torch.int32, device=self.device) + ones = torch.ones(1, dtype=torch.int32, device=self.device).expand( + self._edges_packed_to_mesh_idx.shape + ) + num_edges_per_mesh = num_edges_per_mesh.scatter_add_( + 0, self._edges_packed_to_mesh_idx, ones + ) + self._num_edges_per_mesh = num_edges_per_mesh + + # Compute first idx for each mesh in edges_packed + mesh_to_edges_packed_first_idx = torch.zeros( + self._N, dtype=torch.int64, device=self.device + ) + num_edges_cumsum = num_edges_per_mesh.cumsum(dim=0) + mesh_to_edges_packed_first_idx[1:] = num_edges_cumsum[:-1].clone() + + self._mesh_to_edges_packed_first_idx = mesh_to_edges_packed_first_idx + + def _compute_laplacian_packed(self, refresh: bool = False): + """ + Computes the laplacian in packed form. + The definition of the laplacian is + L[i, j] = -1 , if i == j + L[i, j] = 1 / deg(i) , if (i, j) is an edge + L[i, j] = 0 , otherwise + where deg(i) is the degree of the i-th vertex in the graph + + Returns: + Sparse FloatTensor of shape (V, V) where V = sum(V_n) + + """ + from ..ops import laplacian + + if not (refresh or self._laplacian_packed is None): + return + + if self.isempty(): + self._laplacian_packed = torch.zeros( + (0, 0), dtype=torch.float32, device=self.device + ).to_sparse() + return + + verts_packed = self.verts_packed() # (sum(V_n), 3) + edges_packed = self.edges_packed() # (sum(E_n), 3) + + self._laplacian_packed = laplacian(verts_packed, edges_packed) + + def clone(self): + """ + Deep copy of Meshes object. All internal tensors are cloned individually. + + Returns: + new Meshes object. + """ + verts_list = self.verts_list() + faces_list = self.faces_list() + new_verts_list = [v.clone() for v in verts_list] + new_faces_list = [f.clone() for f in faces_list] + other = self.__class__(verts=new_verts_list, faces=new_faces_list) + for k in self._INTERNAL_TENSORS: + v = getattr(self, k) + if torch.is_tensor(v): + setattr(other, k, v.clone()) + + # Textures is not a tensor but has a clone method + if self.textures is not None: + other.textures = self.textures.clone() + return other + + def detach(self): + """ + Detach Meshes object. All internal tensors are detached individually. + + Returns: + new Meshes object. + """ + verts_list = self.verts_list() + faces_list = self.faces_list() + new_verts_list = [v.detach() for v in verts_list] + new_faces_list = [f.detach() for f in faces_list] + other = self.__class__(verts=new_verts_list, faces=new_faces_list) + for k in self._INTERNAL_TENSORS: + v = getattr(self, k) + if torch.is_tensor(v): + setattr(other, k, v.detach()) + + # Textures is not a tensor but has a detach method + if self.textures is not None: + other.textures = self.textures.detach() + return other + + def to(self, device: Device, copy: bool = False): + """ + Match functionality of torch.Tensor.to() + If copy = True or the self Tensor is on a different device, the + returned tensor is a copy of self with the desired torch.device. + If copy = False and the self Tensor already has the correct torch.device, + then self is returned. + + Args: + device: Device (as str or torch.device) for the new tensor. + copy: Boolean indicator whether or not to clone self. Default False. + + Returns: + Meshes object. + """ + device_ = make_device(device) + if not copy and self.device == device_: + return self + + other = self.clone() + if self.device == device_: + return other + + other.device = device_ + if other._N > 0: + other._verts_list = [v.to(device_) for v in other._verts_list] + other._faces_list = [f.to(device_) for f in other._faces_list] + for k in self._INTERNAL_TENSORS: + v = getattr(self, k) + if torch.is_tensor(v): + setattr(other, k, v.to(device_)) + if self.textures is not None: + other.textures = other.textures.to(device_) + return other + + def cpu(self): + return self.to("cpu") + + def cuda(self): + return self.to("cuda") + + def get_mesh_verts_faces(self, index: int): + """ + Get tensors for a single mesh from the list representation. + + Args: + index: Integer in the range [0, N). + + Returns: + verts: Tensor of shape (V, 3). + faces: LongTensor of shape (F, 3). + """ + if not isinstance(index, int): + raise ValueError("Mesh index must be an integer.") + if index < 0 or index > self._N: + raise ValueError( + "Mesh index must be in the range [0, N) where \ + N is the number of meshes in the batch." + ) + verts = self.verts_list() + faces = self.faces_list() + return verts[index], faces[index] + + # TODO(nikhilar) Move function to a utils file. + def split(self, split_sizes: list): + """ + Splits Meshes object of size N into a list of Meshes objects of + size len(split_sizes), where the i-th Meshes object is of size split_sizes[i]. + Similar to torch.split(). + + Args: + split_sizes: List of integer sizes of Meshes objects to be returned. + + Returns: + list[Meshes]. + """ + if not all(isinstance(x, int) for x in split_sizes): + raise ValueError("Value of split_sizes must be a list of integers.") + meshlist = [] + curi = 0 + for i in split_sizes: + meshlist.append(self[curi : curi + i]) + curi += i + return meshlist + + def offset_verts_(self, vert_offsets_packed): + """ + Add an offset to the vertices of this Meshes. In place operation. + If normals are present they may be recalculated. + + Args: + vert_offsets_packed: A Tensor of shape (3,) or the same shape as + self.verts_packed, giving offsets to be added + to all vertices. + Returns: + self. + """ + verts_packed = self.verts_packed() + if vert_offsets_packed.shape == (3,): + update_normals = False + vert_offsets_packed = vert_offsets_packed.expand_as(verts_packed) + else: + update_normals = True + if vert_offsets_packed.shape != verts_packed.shape: + raise ValueError("Verts offsets must have dimension (all_v, 3).") + # update verts packed + self._verts_packed = verts_packed + vert_offsets_packed + new_verts_list = list( + self._verts_packed.split(self.num_verts_per_mesh().tolist(), 0) + ) + # update verts list + # Note that since _compute_packed() has been executed, verts_list + # cannot be None even if not provided during construction. + self._verts_list = new_verts_list + + # update verts padded + if self._verts_padded is not None: + for i, verts in enumerate(new_verts_list): + if len(verts) > 0: + self._verts_padded[i, : verts.shape[0], :] = verts + + # update face areas and normals and vertex normals + # only if the original attributes are present + if update_normals and any( + v is not None + for v in [self._faces_areas_packed, self._faces_normals_packed] + ): + self._compute_face_areas_normals(refresh=True) + if update_normals and self._verts_normals_packed is not None: + self._compute_vertex_normals(refresh=True) + + return self + + # TODO(nikhilar) Move out of place operator to a utils file. + def offset_verts(self, vert_offsets_packed): + """ + Out of place offset_verts. + + Args: + vert_offsets_packed: A Tensor of the same shape as self.verts_packed + giving offsets to be added to all vertices. + Returns: + new Meshes object. + """ + new_mesh = self.clone() + return new_mesh.offset_verts_(vert_offsets_packed) + + def scale_verts_(self, scale): + """ + Multiply the vertices of this Meshes object by a scalar value. + In place operation. + + Args: + scale: A scalar, or a Tensor of shape (N,). + + Returns: + self. + """ + if not torch.is_tensor(scale): + scale = torch.full((len(self),), scale, device=self.device) + new_verts_list = [] + verts_list = self.verts_list() + for i, old_verts in enumerate(verts_list): + new_verts_list.append(scale[i] * old_verts) + # update list + self._verts_list = new_verts_list + # update packed + if self._verts_packed is not None: + self._verts_packed = torch.cat(new_verts_list, dim=0) + # update padded + if self._verts_padded is not None: + for i, verts in enumerate(self._verts_list): + if len(verts) > 0: + self._verts_padded[i, : verts.shape[0], :] = verts + + # update face areas and normals + # only if the original attributes are computed + if any( + v is not None + for v in [self._faces_areas_packed, self._faces_normals_packed] + ): + self._compute_face_areas_normals(refresh=True) + return self + + def scale_verts(self, scale): + """ + Out of place scale_verts. + + Args: + scale: A scalar, or a Tensor of shape (N,). + + Returns: + new Meshes object. + """ + new_mesh = self.clone() + return new_mesh.scale_verts_(scale) + + def update_padded(self, new_verts_padded): + """ + This function allows for an update of verts_padded without having to + explicitly convert it to the list representation for heterogeneous batches. + Returns a Meshes structure with updated padded tensors and copies of the + auxiliary tensors at construction time. + It updates self._verts_padded with new_verts_padded, and does a + shallow copy of (faces_padded, faces_list, num_verts_per_mesh, num_faces_per_mesh). + If packed representations are computed in self, they are updated as well. + + Args: + new_points_padded: FloatTensor of shape (N, V, 3) + + Returns: + Meshes with updated padded representations + """ + + def check_shapes(x, size): + if x.shape[0] != size[0]: + raise ValueError("new values must have the same batch dimension.") + if x.shape[1] != size[1]: + raise ValueError("new values must have the same number of points.") + if x.shape[2] != size[2]: + raise ValueError("new values must have the same dimension.") + + check_shapes(new_verts_padded, [self._N, self._V, 3]) + + new = self.__class__(verts=new_verts_padded, faces=self.faces_padded()) + + if new._N != self._N or new._V != self._V or new._F != self._F: + raise ValueError("Inconsistent sizes after construction.") + + # overwrite the equisized flag + new.equisized = self.equisized + + # overwrite textures if any + new.textures = self.textures + + # copy auxiliary tensors + copy_tensors = ["_num_verts_per_mesh", "_num_faces_per_mesh", "valid"] + + for k in copy_tensors: + v = getattr(self, k) + if torch.is_tensor(v): + setattr(new, k, v) # shallow copy + + # shallow copy of faces_list if any, st new.faces_list() + # does not re-compute from _faces_padded + new._faces_list = self._faces_list + + # update verts/faces packed if they are computed in self + if self._verts_packed is not None: + copy_tensors = [ + "_faces_packed", + "_verts_packed_to_mesh_idx", + "_faces_packed_to_mesh_idx", + "_mesh_to_verts_packed_first_idx", + "_mesh_to_faces_packed_first_idx", + ] + for k in copy_tensors: + v = getattr(self, k) + assert torch.is_tensor(v) + setattr(new, k, v) # shallow copy + # update verts_packed + pad_to_packed = self.verts_padded_to_packed_idx() + new_verts_packed = new_verts_padded.reshape(-1, 3)[pad_to_packed, :] + new._verts_packed = new_verts_packed + new._verts_padded_to_packed_idx = pad_to_packed + + # update edges packed if they are computed in self + if self._edges_packed is not None: + copy_tensors = [ + "_edges_packed", + "_edges_packed_to_mesh_idx", + "_mesh_to_edges_packed_first_idx", + "_faces_packed_to_edges_packed", + "_num_edges_per_mesh", + ] + for k in copy_tensors: + v = getattr(self, k) + assert torch.is_tensor(v) + setattr(new, k, v) # shallow copy + + # update laplacian if it is compute in self + if self._laplacian_packed is not None: + new._laplacian_packed = self._laplacian_packed + + assert new._verts_list is None + assert new._verts_normals_packed is None + assert new._faces_normals_packed is None + assert new._faces_areas_packed is None + + return new + + # TODO(nikhilar) Move function to utils file. + def get_bounding_boxes(self): + """ + Compute an axis-aligned bounding box for each mesh in this Meshes object. + + Returns: + bboxes: Tensor of shape (N, 3, 2) where bbox[i, j] gives the + min and max values of mesh i along the jth coordinate axis. + """ + all_mins, all_maxes = [], [] + for verts in self.verts_list(): + cur_mins = verts.min(dim=0)[0] # (3,) + cur_maxes = verts.max(dim=0)[0] # (3,) + all_mins.append(cur_mins) + all_maxes.append(cur_maxes) + all_mins = torch.stack(all_mins, dim=0) # (N, 3) + all_maxes = torch.stack(all_maxes, dim=0) # (N, 3) + bboxes = torch.stack([all_mins, all_maxes], dim=2) + return bboxes + + def extend(self, N: int): + """ + Create new Meshes class which contains each input mesh N times + + Args: + N: number of new copies of each mesh. + + Returns: + new Meshes object. + """ + if not isinstance(N, int): + raise ValueError("N must be an integer.") + if N <= 0: + raise ValueError("N must be > 0.") + new_verts_list, new_faces_list = [], [] + for verts, faces in zip(self.verts_list(), self.faces_list()): + new_verts_list.extend(verts.clone() for _ in range(N)) + new_faces_list.extend(faces.clone() for _ in range(N)) + + tex = None + if self.textures is not None: + tex = self.textures.extend(N) + + return self.__class__(verts=new_verts_list, faces=new_faces_list, textures=tex) + + def sample_textures(self, fragments): + if self.textures is not None: + + # Check dimensions of textures match that of meshes + shape_ok = self.textures.check_shapes(self._N, self._V, self._F) + if not shape_ok: + msg = "Textures do not match the dimensions of Meshes." + raise ValueError(msg) + + # Pass in faces packed. If the textures are defined per + # vertex, the face indices are needed in order to interpolate + # the vertex attributes across the face. + return self.textures.sample_textures( + fragments, faces_packed=self.faces_packed() + ) + else: + raise ValueError("Meshes does not have textures") + + def submeshes( + self, + face_indices: Union[ + List[List[torch.LongTensor]], List[torch.LongTensor], torch.LongTensor + ], + ) -> "Meshes": + """ + Split a batch of meshes into a batch of submeshes. + + The return value is a Meshes object representing + [mesh restricted to only faces indexed by selected_faces + for mesh, selected_faces_list in zip(self, face_indices) + for faces in selected_faces_list] + + Args: + face_indices: + Let the original mesh have verts_list() of length N. + Can be either + - List of lists of LongTensors. The n-th element is a list of length + num_submeshes_n (empty lists are allowed). The k-th element of the n-th + sublist is a LongTensor of length num_faces_submesh_n_k. + - List of LongTensors. The n-th element is a (possibly empty) LongTensor + of shape (num_submeshes_n, num_faces_n). + - A LongTensor of shape (N, num_submeshes_per_mesh, num_faces_per_submesh) + where all meshes in the batch will have the same number of submeshes. + This will result in an output Meshes object with batch size equal to + N * num_submeshes_per_mesh. + + Returns: + Meshes object of length `sum(len(ids) for ids in face_indices)`. + + Example 1: + + If `meshes` has batch size 1, and `face_indices` is a 1D LongTensor, + then `meshes.submeshes([[face_indices]]) and + `meshes.submeshes(face_indices[None, None])` both produce a Meshes of length 1, + containing a single submesh with a subset of `meshes`' faces, whose indices are + specified by `face_indices`. + + Example 2: + + Take a Meshes object `cubes` with 4 meshes, each a translated cube. Then: + * len(cubes) is 4, len(cubes.verts_list()) is 4, len(cubes.faces_list()) 4, + * [cube_verts.size for cube_verts in cubes.verts_list()] is [8, 8, 8, 8], + * [cube_faces.size for cube_faces in cubes.faces_list()] if [6, 6, 6, 6], + + Now let front_facet, top_and_bottom, all_facets be LongTensors of + sizes (2), (4), and (12), each picking up a number of facets of a cube by + specifying the appropriate triangular faces. + + Then let `subcubes = cubes.submeshes([[front_facet, top_and_bottom], [], + [all_facets], []])`. + * len(subcubes) is 3. + * subcubes[0] is the front facet of the cube contained in cubes[0]. + * subcubes[1] is a mesh containing the (disconnected) top and bottom facets + of cubes[0]. + * subcubes[2] is cubes[2]. + * There are no submeshes of cubes[1] and cubes[3] in subcubes. + * subcubes[0] and subcubes[1] are not watertight. subcubes[2] is. + """ + if len(face_indices) != len(self): + raise ValueError( + "You must specify exactly one set of submeshes" + " for each mesh in this Meshes object." + ) + + sub_verts = [] + sub_verts_ids = [] + sub_faces = [] + + for face_ids_per_mesh, faces, verts in zip( + face_indices, self.faces_list(), self.verts_list() + ): + sub_verts_ids.append([]) + for submesh_face_ids in face_ids_per_mesh: + faces_to_keep = faces[submesh_face_ids] + + # Say we are keeping two faces from a mesh with six vertices: + # faces_to_keep = [[0, 6, 4], + # [0, 2, 6]] + # Then we want verts_to_keep to contain only vertices [0, 2, 4, 6]: + vertex_ids_to_keep = torch.unique(faces_to_keep, sorted=True) + sub_verts.append(verts[vertex_ids_to_keep]) + sub_verts_ids[-1].append(vertex_ids_to_keep) + + # Now, convert faces_to_keep to use the new vertex ids. + # In our example, instead of + # [[0, 6, 4], + # [0, 2, 6]] + # we want faces_to_keep to be + # [[0, 3, 2], + # [0, 1, 3]], + # as each point id got reduced to its sort rank. + _, ids_of_unique_ids_in_sorted = torch.unique( + faces_to_keep, return_inverse=True + ) + sub_faces.append(ids_of_unique_ids_in_sorted) + + return self.__class__( + verts=sub_verts, + faces=sub_faces, + textures=( + self.textures.submeshes(sub_verts_ids, face_indices) + if self.textures + else None + ), + ) + + +def join_meshes_as_batch(meshes: List[Meshes], include_textures: bool = True) -> Meshes: + """ + Merge multiple Meshes objects, i.e. concatenate the meshes objects. They + must all be on the same device. If include_textures is true, they must all + be compatible, either all or none having textures, and all the Textures + objects being the same type. If include_textures is False, textures are + ignored. + + If the textures are TexturesAtlas then being the same type includes having + the same resolution. If they are TexturesUV then it includes having the same + align_corners and padding_mode. + + Args: + meshes: list of meshes. + include_textures: (bool) whether to try to join the textures. + + Returns: + new Meshes object containing all the meshes from all the inputs. + """ + if isinstance(meshes, Meshes): + # Meshes objects can be iterated and produce single Meshes. We avoid + # letting join_meshes_as_batch(mesh1, mesh2) silently do the wrong thing. + raise ValueError("Wrong first argument to join_meshes_as_batch.") + verts = [v for mesh in meshes for v in mesh.verts_list()] + faces = [f for mesh in meshes for f in mesh.faces_list()] + if len(meshes) == 0 or not include_textures: + return Meshes(verts=verts, faces=faces) + + if meshes[0].textures is None: + if any(mesh.textures is not None for mesh in meshes): + raise ValueError("Inconsistent textures in join_meshes_as_batch.") + return Meshes(verts=verts, faces=faces) + + if any(mesh.textures is None for mesh in meshes): + raise ValueError("Inconsistent textures in join_meshes_as_batch.") + + # Now we know there are multiple meshes and they have textures to merge. + all_textures = [mesh.textures for mesh in meshes] + first = all_textures[0] + tex_types_same = all(type(tex) == type(first) for tex in all_textures) # noqa: E721 + + if not tex_types_same: + raise ValueError("All meshes in the batch must have the same type of texture.") + + tex = first.join_batch(all_textures[1:]) + return Meshes(verts=verts, faces=faces, textures=tex) + + +def join_meshes_as_scene( + meshes: Union[Meshes, List[Meshes]], include_textures: bool = True +) -> Meshes: + """ + Joins a batch of meshes in the form of a Meshes object or a list of Meshes + objects as a single mesh. If the input is a list, the Meshes objects in the + list must all be on the same device. Unless include_textures is False, the + meshes must all have the same type of texture or must all not have textures. + + If textures are included, then the textures are joined as a single scene in + addition to the meshes. For this, texture types have an appropriate method + called join_scene which joins mesh textures into a single texture. + If the textures are TexturesAtlas then they must have the same resolution. + If they are TexturesUV then they must have the same align_corners and + padding_mode. Values in verts_uvs outside [0, 1] will not + be respected. + + Args: + meshes: Meshes object that contains a batch of meshes, or a list of + Meshes objects. + include_textures: (bool) whether to try to join the textures. + + Returns: + new Meshes object containing a single mesh + """ + if not isinstance(include_textures, (bool, int)): + # We want to avoid letting join_meshes_as_scene(mesh1, mesh2) silently + # do the wrong thing. + raise ValueError( + f"include_textures argument cannot be {type(include_textures)}" + ) + if isinstance(meshes, List): + meshes = join_meshes_as_batch(meshes, include_textures=include_textures) + + if len(meshes) == 1: + return meshes + verts = meshes.verts_packed() # (sum(V_n), 3) + # Offset automatically done by faces_packed + faces = meshes.faces_packed() # (sum(F_n), 3) + textures = None + + if include_textures and meshes.textures is not None: + textures = meshes.textures.join_scene() + + mesh = Meshes(verts=verts.unsqueeze(0), faces=faces.unsqueeze(0), textures=textures) + return mesh diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/structures/pointclouds.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/structures/pointclouds.py new file mode 100644 index 0000000000000000000000000000000000000000..f699881c5b41fed04442b59611857949331e93f9 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/structures/pointclouds.py @@ -0,0 +1,1305 @@ +# 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. + +# pyre-unsafe + +from itertools import zip_longest +from typing import List, Optional, Sequence, Tuple, Union + +import numpy as np +import torch + +from ..common.datatypes import Device, make_device +from . import utils as struct_utils + + +class Pointclouds: + """ + This class provides functions for working with batches of 3d point clouds, + and converting between representations. + + Within Pointclouds, there are three different representations of the data. + + List + - only used for input as a starting point to convert to other representations. + Padded + - has specific batch dimension. + Packed + - no batch dimension. + - has auxiliary variables used to index into the padded representation. + + Example + + Input list of points = [[P_1], [P_2], ... , [P_N]] + where P_1, ... , P_N are the number of points in each cloud and N is the + number of clouds. + + # SPHINX IGNORE + List | Padded | Packed + ---------------------------|-------------------------|------------------------ + [[P_1], ... , [P_N]] | size = (N, max(P_n), 3) | size = (sum(P_n), 3) + | | + Example for locations | | + or colors: | | + | | + P_1 = 3, P_2 = 4, P_3 = 5 | size = (3, 5, 3) | size = (12, 3) + | | + List([ | tensor([ | tensor([ + [ | [ | [0.1, 0.3, 0.5], + [0.1, 0.3, 0.5], | [0.1, 0.3, 0.5], | [0.5, 0.2, 0.1], + [0.5, 0.2, 0.1], | [0.5, 0.2, 0.1], | [0.6, 0.8, 0.7], + [0.6, 0.8, 0.7] | [0.6, 0.8, 0.7], | [0.1, 0.3, 0.3], + ], | [0, 0, 0], | [0.6, 0.7, 0.8], + [ | [0, 0, 0] | [0.2, 0.3, 0.4], + [0.1, 0.3, 0.3], | ], | [0.1, 0.5, 0.3], + [0.6, 0.7, 0.8], | [ | [0.7, 0.3, 0.6], + [0.2, 0.3, 0.4], | [0.1, 0.3, 0.3], | [0.2, 0.4, 0.8], + [0.1, 0.5, 0.3] | [0.6, 0.7, 0.8], | [0.9, 0.5, 0.2], + ], | [0.2, 0.3, 0.4], | [0.2, 0.3, 0.4], + [ | [0.1, 0.5, 0.3], | [0.9, 0.3, 0.8], + [0.7, 0.3, 0.6], | [0, 0, 0] | ]) + [0.2, 0.4, 0.8], | ], | + [0.9, 0.5, 0.2], | [ | + [0.2, 0.3, 0.4], | [0.7, 0.3, 0.6], | + [0.9, 0.3, 0.8], | [0.2, 0.4, 0.8], | + ] | [0.9, 0.5, 0.2], | + ]) | [0.2, 0.3, 0.4], | + | [0.9, 0.3, 0.8] | + | ] | + | ]) | + ----------------------------------------------------------------------------- + + Auxiliary variables for packed representation + + Name | Size | Example from above + -------------------------------|---------------------|----------------------- + | | + packed_to_cloud_idx | size = (sum(P_n)) | tensor([ + | | 0, 0, 0, 1, 1, 1, + | | 1, 2, 2, 2, 2, 2 + | | )] + | | size = (12) + | | + cloud_to_packed_first_idx | size = (N) | tensor([0, 3, 7]) + | | size = (3) + | | + num_points_per_cloud | size = (N) | tensor([3, 4, 5]) + | | size = (3) + | | + padded_to_packed_idx | size = (sum(P_n)) | tensor([ + | | 0, 1, 2, 5, 6, 7, + | | 8, 10, 11, 12, 13, + | | 14 + | | )] + | | size = (12) + ----------------------------------------------------------------------------- + # SPHINX IGNORE + """ + + _INTERNAL_TENSORS = [ + "_points_packed", + "_points_padded", + "_normals_packed", + "_normals_padded", + "_features_packed", + "_features_padded", + "_packed_to_cloud_idx", + "_cloud_to_packed_first_idx", + "_num_points_per_cloud", + "_padded_to_packed_idx", + "valid", + "equisized", + ] + + def __init__(self, points, normals=None, features=None) -> None: + """ + Args: + points: + Can be either + + - List where each element is a tensor of shape (num_points, 3) + containing the (x, y, z) coordinates of each point. + - Padded float tensor with shape (num_clouds, num_points, 3). + normals: + Can be either + + - None + - List where each element is a tensor of shape (num_points, 3) + containing the normal vector for each point. + - Padded float tensor of shape (num_clouds, num_points, 3). + features: + Can be either + + - None + - List where each element is a tensor of shape (num_points, C) + containing the features for the points in the cloud. + - Padded float tensor of shape (num_clouds, num_points, C). + where C is the number of channels in the features. + For example 3 for RGB color. + + Refer to comments above for descriptions of List and Padded + representations. + """ + self.device = torch.device("cpu") + + # Indicates whether the clouds in the list/batch have the same number + # of points. + self.equisized = False + + # Boolean indicator for each cloud in the batch. + # True if cloud has non zero number of points, False otherwise. + self.valid = None + + self._N = 0 # batch size (number of clouds) + self._P = 0 # (max) number of points per cloud + self._C = None # number of channels in the features + + # List of Tensors of points and features. + self._points_list = None + self._normals_list = None + self._features_list = None + + # Number of points per cloud. + self._num_points_per_cloud = None # N + + # Packed representation. + self._points_packed = None # (sum(P_n), 3) + self._normals_packed = None # (sum(P_n), 3) + self._features_packed = None # (sum(P_n), C) + + self._packed_to_cloud_idx = None # sum(P_n) + + # Index of each cloud's first point in the packed points. + # Assumes packing is sequential. + self._cloud_to_packed_first_idx = None # N + + # Padded representation. + self._points_padded = None # (N, max(P_n), 3) + self._normals_padded = None # (N, max(P_n), 3) + self._features_padded = None # (N, max(P_n), C) + + # Index to convert points from flattened padded to packed. + self._padded_to_packed_idx = None # N * max_P + + # Identify type of points. + if isinstance(points, list): + self._points_list = points + self._N = len(self._points_list) + self.valid = torch.zeros((self._N,), dtype=torch.bool, device=self.device) + + if self._N > 0: + self.device = self._points_list[0].device + for p in self._points_list: + if len(p) > 0 and (p.dim() != 2 or p.shape[1] != 3): + raise ValueError("Clouds in list must be of shape Px3 or empty") + if p.device != self.device: + raise ValueError("All points must be on the same device") + + num_points_per_cloud = torch.tensor( + [len(p) for p in self._points_list], device=self.device + ) + self._P = int(num_points_per_cloud.max()) + self.valid = torch.tensor( + [len(p) > 0 for p in self._points_list], + dtype=torch.bool, + device=self.device, + ) + + if len(num_points_per_cloud.unique()) == 1: + self.equisized = True + self._num_points_per_cloud = num_points_per_cloud + else: + self._num_points_per_cloud = torch.tensor([], dtype=torch.int64) + + elif torch.is_tensor(points): + if points.dim() != 3 or points.shape[2] != 3: + raise ValueError("Points tensor has incorrect dimensions.") + self._points_padded = points + self._N = self._points_padded.shape[0] + self._P = self._points_padded.shape[1] + self.device = self._points_padded.device + self.valid = torch.ones((self._N,), dtype=torch.bool, device=self.device) + self._num_points_per_cloud = torch.tensor( + [self._P] * self._N, device=self.device + ) + self.equisized = True + else: + raise ValueError( + "Points must be either a list or a tensor with \ + shape (batch_size, P, 3) where P is the maximum number of \ + points in a cloud." + ) + + # parse normals + normals_parsed = self._parse_auxiliary_input(normals) + self._normals_list, self._normals_padded, normals_C = normals_parsed + if normals_C is not None and normals_C != 3: + raise ValueError("Normals are expected to be 3-dimensional") + + # parse features + features_parsed = self._parse_auxiliary_input(features) + self._features_list, self._features_padded, features_C = features_parsed + if features_C is not None: + self._C = features_C + + def _parse_auxiliary_input( + self, aux_input + ) -> Tuple[Optional[List[torch.Tensor]], Optional[torch.Tensor], Optional[int]]: + """ + Interpret the auxiliary inputs (normals, features) given to __init__. + + Args: + aux_input: + Can be either + + - List where each element is a tensor of shape (num_points, C) + containing the features for the points in the cloud. + - Padded float tensor of shape (num_clouds, num_points, C). + For normals, C = 3 + + Returns: + 3-element tuple of list, padded, num_channels. + If aux_input is list, then padded is None. If aux_input is a tensor, + then list is None. + """ + if aux_input is None or self._N == 0: + return None, None, None + + aux_input_C = None + + if isinstance(aux_input, list): + return self._parse_auxiliary_input_list(aux_input) + if torch.is_tensor(aux_input): + if aux_input.dim() != 3: + raise ValueError("Auxiliary input tensor has incorrect dimensions.") + if self._N != aux_input.shape[0]: + raise ValueError("Points and inputs must be the same length.") + if self._P != aux_input.shape[1]: + raise ValueError( + "Inputs tensor must have the right maximum \ + number of points in each cloud." + ) + if aux_input.device != self.device: + raise ValueError( + "All auxiliary inputs must be on the same device as the points." + ) + aux_input_C = aux_input.shape[2] + return None, aux_input, aux_input_C + else: + raise ValueError( + "Auxiliary input must be either a list or a tensor with \ + shape (batch_size, P, C) where P is the maximum number of \ + points in a cloud." + ) + + def _parse_auxiliary_input_list( + self, aux_input: list + ) -> Tuple[Optional[List[torch.Tensor]], None, Optional[int]]: + """ + Interpret the auxiliary inputs (normals, features) given to __init__, + if a list. + + Args: + aux_input: + - List where each element is a tensor of shape (num_points, C) + containing the features for the points in the cloud. + For normals, C = 3 + + Returns: + 3-element tuple of list, padded=None, num_channels. + If aux_input is list, then padded is None. If aux_input is a tensor, + then list is None. + """ + aux_input_C = None + good_empty = None + needs_fixing = False + + if len(aux_input) != self._N: + raise ValueError("Points and auxiliary input must be the same length.") + for p, d in zip(self._num_points_per_cloud, aux_input): + valid_but_empty = p == 0 and d is not None and d.ndim == 2 + if p > 0 or valid_but_empty: + if p != d.shape[0]: + raise ValueError( + "A cloud has mismatched numbers of points and inputs" + ) + if d.dim() != 2: + raise ValueError( + "A cloud auxiliary input must be of shape PxC or empty" + ) + if aux_input_C is None: + aux_input_C = d.shape[1] + elif aux_input_C != d.shape[1]: + raise ValueError("The clouds must have the same number of channels") + if d.device != self.device: + raise ValueError( + "All auxiliary inputs must be on the same device as the points." + ) + else: + needs_fixing = True + + if aux_input_C is None: + # We found nothing useful + return None, None, None + + # If we have empty but "wrong" inputs we want to store "fixed" versions. + if needs_fixing: + if good_empty is None: + good_empty = torch.zeros((0, aux_input_C), device=self.device) + aux_input_out = [] + for p, d in zip(self._num_points_per_cloud, aux_input): + valid_but_empty = p == 0 and d is not None and d.ndim == 2 + if p > 0 or valid_but_empty: + aux_input_out.append(d) + else: + aux_input_out.append(good_empty) + else: + aux_input_out = aux_input + + return aux_input_out, None, aux_input_C + + def __len__(self) -> int: + return self._N + + def __getitem__( + self, + index: Union[int, List[int], slice, torch.BoolTensor, torch.LongTensor], + ) -> "Pointclouds": + """ + Args: + index: Specifying the index of the cloud to retrieve. + Can be an int, slice, list of ints or a boolean tensor. + + Returns: + Pointclouds object with selected clouds. The tensors are not cloned. + """ + normals, features = None, None + normals_list = self.normals_list() + features_list = self.features_list() + if isinstance(index, int): + points = [self.points_list()[index]] + if normals_list is not None: + normals = [normals_list[index]] + if features_list is not None: + features = [features_list[index]] + elif isinstance(index, slice): + points = self.points_list()[index] + if normals_list is not None: + normals = normals_list[index] + if features_list is not None: + features = features_list[index] + elif isinstance(index, list): + points = [self.points_list()[i] for i in index] + if normals_list is not None: + normals = [normals_list[i] for i in index] + if features_list is not None: + features = [features_list[i] for i in index] + elif isinstance(index, torch.Tensor): + if index.dim() != 1 or index.dtype.is_floating_point: + raise IndexError(index) + # NOTE consider converting index to cpu for efficiency + if index.dtype == torch.bool: + # advanced indexing on a single dimension + index = index.nonzero() + index = index.squeeze(1) if index.numel() > 0 else index + index = index.tolist() + points = [self.points_list()[i] for i in index] + if normals_list is not None: + normals = [normals_list[i] for i in index] + if features_list is not None: + features = [features_list[i] for i in index] + else: + raise IndexError(index) + + return self.__class__(points=points, normals=normals, features=features) + + def isempty(self) -> bool: + """ + Checks whether any cloud is valid. + + Returns: + bool indicating whether there is any data. + """ + return self._N == 0 or self.valid.eq(False).all() + + def points_list(self) -> List[torch.Tensor]: + """ + Get the list representation of the points. + + Returns: + list of tensors of points of shape (P_n, 3). + """ + if self._points_list is None: + assert ( + self._points_padded is not None + ), "points_padded is required to compute points_list." + points_list = [] + for i in range(self._N): + points_list.append( + self._points_padded[i, : self.num_points_per_cloud()[i]] + ) + self._points_list = points_list + return self._points_list + + def normals_list(self) -> Optional[List[torch.Tensor]]: + """ + Get the list representation of the normals, + or None if there are no normals. + + Returns: + list of tensors of normals of shape (P_n, 3). + """ + if self._normals_list is None: + if self._normals_padded is None: + # No normals provided so return None + return None + self._normals_list = struct_utils.padded_to_list( + self._normals_padded, self.num_points_per_cloud().tolist() + ) + return self._normals_list + + def features_list(self) -> Optional[List[torch.Tensor]]: + """ + Get the list representation of the features, + or None if there are no features. + + Returns: + list of tensors of features of shape (P_n, C). + """ + if self._features_list is None: + if self._features_padded is None: + # No features provided so return None + return None + self._features_list = struct_utils.padded_to_list( + self._features_padded, self.num_points_per_cloud().tolist() + ) + return self._features_list + + def points_packed(self) -> torch.Tensor: + """ + Get the packed representation of the points. + + Returns: + tensor of points of shape (sum(P_n), 3). + """ + self._compute_packed() + return self._points_packed + + def normals_packed(self) -> Optional[torch.Tensor]: + """ + Get the packed representation of the normals. + + Returns: + tensor of normals of shape (sum(P_n), 3), + or None if there are no normals. + """ + self._compute_packed() + return self._normals_packed + + def features_packed(self) -> Optional[torch.Tensor]: + """ + Get the packed representation of the features. + + Returns: + tensor of features of shape (sum(P_n), C), + or None if there are no features + """ + self._compute_packed() + return self._features_packed + + def packed_to_cloud_idx(self): + """ + Return a 1D tensor x with length equal to the total number of points. + packed_to_cloud_idx()[i] gives the index of the cloud which contains + points_packed()[i]. + + Returns: + 1D tensor of indices. + """ + self._compute_packed() + return self._packed_to_cloud_idx + + def cloud_to_packed_first_idx(self): + """ + Return a 1D tensor x with length equal to the number of clouds such that + the first point of the ith cloud is points_packed[x[i]]. + + Returns: + 1D tensor of indices of first items. + """ + self._compute_packed() + return self._cloud_to_packed_first_idx + + def num_points_per_cloud(self) -> torch.Tensor: + """ + Return a 1D tensor x with length equal to the number of clouds giving + the number of points in each cloud. + + Returns: + 1D tensor of sizes. + """ + return self._num_points_per_cloud + + def points_padded(self) -> torch.Tensor: + """ + Get the padded representation of the points. + + Returns: + tensor of points of shape (N, max(P_n), 3). + """ + self._compute_padded() + return self._points_padded + + def normals_padded(self) -> Optional[torch.Tensor]: + """ + Get the padded representation of the normals, + or None if there are no normals. + + Returns: + tensor of normals of shape (N, max(P_n), 3). + """ + self._compute_padded() + return self._normals_padded + + def features_padded(self) -> Optional[torch.Tensor]: + """ + Get the padded representation of the features, + or None if there are no features. + + Returns: + tensor of features of shape (N, max(P_n), 3). + """ + self._compute_padded() + return self._features_padded + + def padded_to_packed_idx(self): + """ + Return a 1D tensor x with length equal to the total number of points + such that points_packed()[i] is element x[i] of the flattened padded + representation. + The packed representation can be calculated as follows. + + .. code-block:: python + + p = points_padded().reshape(-1, 3) + points_packed = p[x] + + Returns: + 1D tensor of indices. + """ + if self._padded_to_packed_idx is not None: + return self._padded_to_packed_idx + if self._N == 0: + self._padded_to_packed_idx = [] + else: + self._padded_to_packed_idx = torch.cat( + [ + torch.arange(v, dtype=torch.int64, device=self.device) + i * self._P + for (i, v) in enumerate(self.num_points_per_cloud()) + ], + dim=0, + ) + return self._padded_to_packed_idx + + def _compute_padded(self, refresh: bool = False): + """ + Computes the padded version from points_list, normals_list and features_list. + + Args: + refresh: whether to force the recalculation. + """ + if not (refresh or self._points_padded is None): + return + + self._normals_padded, self._features_padded = None, None + if self.isempty(): + self._points_padded = torch.zeros((self._N, 0, 3), device=self.device) + else: + self._points_padded = struct_utils.list_to_padded( + self.points_list(), + (self._P, 3), + pad_value=0.0, + equisized=self.equisized, + ) + normals_list = self.normals_list() + if normals_list is not None: + self._normals_padded = struct_utils.list_to_padded( + normals_list, + (self._P, 3), + pad_value=0.0, + equisized=self.equisized, + ) + features_list = self.features_list() + if features_list is not None: + self._features_padded = struct_utils.list_to_padded( + features_list, + (self._P, self._C), + pad_value=0.0, + equisized=self.equisized, + ) + + # TODO(nikhilar) Improve performance of _compute_packed. + def _compute_packed(self, refresh: bool = False): + """ + Computes the packed version from points_list, normals_list and + features_list and sets the values of auxiliary tensors. + + Args: + refresh: Set to True to force recomputation of packed + representations. Default: False. + """ + + if not ( + refresh + or any( + v is None + for v in [ + self._points_packed, + self._packed_to_cloud_idx, + self._cloud_to_packed_first_idx, + ] + ) + ): + return + + # Packed can be calculated from padded or list, so can call the + # accessor function for the lists. + points_list = self.points_list() + normals_list = self.normals_list() + features_list = self.features_list() + if self.isempty(): + self._points_packed = torch.zeros( + (0, 3), dtype=torch.float32, device=self.device + ) + self._packed_to_cloud_idx = torch.zeros( + (0,), dtype=torch.int64, device=self.device + ) + self._cloud_to_packed_first_idx = torch.zeros( + (0,), dtype=torch.int64, device=self.device + ) + self._normals_packed = None + self._features_packed = None + return + + points_list_to_packed = struct_utils.list_to_packed(points_list) + self._points_packed = points_list_to_packed[0] + if not torch.allclose(self._num_points_per_cloud, points_list_to_packed[1]): + raise ValueError("Inconsistent list to packed conversion") + self._cloud_to_packed_first_idx = points_list_to_packed[2] + self._packed_to_cloud_idx = points_list_to_packed[3] + + self._normals_packed, self._features_packed = None, None + if normals_list is not None: + normals_list_to_packed = struct_utils.list_to_packed(normals_list) + self._normals_packed = normals_list_to_packed[0] + + if features_list is not None: + features_list_to_packed = struct_utils.list_to_packed(features_list) + self._features_packed = features_list_to_packed[0] + + def clone(self): + """ + Deep copy of Pointclouds object. All internal tensors are cloned + individually. + + Returns: + new Pointclouds object. + """ + # instantiate new pointcloud with the representation which is not None + # (either list or tensor) to save compute. + new_points, new_normals, new_features = None, None, None + if self._points_list is not None: + new_points = [v.clone() for v in self.points_list()] + normals_list = self.normals_list() + features_list = self.features_list() + if normals_list is not None: + new_normals = [n.clone() for n in normals_list] + if features_list is not None: + new_features = [f.clone() for f in features_list] + elif self._points_padded is not None: + new_points = self.points_padded().clone() + normals_padded = self.normals_padded() + features_padded = self.features_padded() + if normals_padded is not None: + new_normals = self.normals_padded().clone() + if features_padded is not None: + new_features = self.features_padded().clone() + other = self.__class__( + points=new_points, normals=new_normals, features=new_features + ) + for k in self._INTERNAL_TENSORS: + v = getattr(self, k) + if torch.is_tensor(v): + setattr(other, k, v.clone()) + return other + + def detach(self): + """ + Detach Pointclouds object. All internal tensors are detached + individually. + + Returns: + new Pointclouds object. + """ + # instantiate new pointcloud with the representation which is not None + # (either list or tensor) to save compute. + new_points, new_normals, new_features = None, None, None + if self._points_list is not None: + new_points = [v.detach() for v in self.points_list()] + normals_list = self.normals_list() + features_list = self.features_list() + if normals_list is not None: + new_normals = [n.detach() for n in normals_list] + if features_list is not None: + new_features = [f.detach() for f in features_list] + elif self._points_padded is not None: + new_points = self.points_padded().detach() + normals_padded = self.normals_padded() + features_padded = self.features_padded() + if normals_padded is not None: + new_normals = self.normals_padded().detach() + if features_padded is not None: + new_features = self.features_padded().detach() + other = self.__class__( + points=new_points, normals=new_normals, features=new_features + ) + for k in self._INTERNAL_TENSORS: + v = getattr(self, k) + if torch.is_tensor(v): + setattr(other, k, v.detach()) + return other + + def to(self, device: Device, copy: bool = False): + """ + Match functionality of torch.Tensor.to() + If copy = True or the self Tensor is on a different device, the + returned tensor is a copy of self with the desired torch.device. + If copy = False and the self Tensor already has the correct torch.device, + then self is returned. + + Args: + device: Device (as str or torch.device) for the new tensor. + copy: Boolean indicator whether or not to clone self. Default False. + + Returns: + Pointclouds object. + """ + device_ = make_device(device) + + if not copy and self.device == device_: + return self + + other = self.clone() + if self.device == device_: + return other + + other.device = device_ + if other._N > 0: + other._points_list = [v.to(device_) for v in other.points_list()] + if other._normals_list is not None: + other._normals_list = [n.to(device_) for n in other.normals_list()] + if other._features_list is not None: + other._features_list = [f.to(device_) for f in other.features_list()] + for k in self._INTERNAL_TENSORS: + v = getattr(self, k) + if torch.is_tensor(v): + setattr(other, k, v.to(device_)) + return other + + def cpu(self): + return self.to("cpu") + + def cuda(self): + return self.to("cuda") + + def get_cloud(self, index: int): + """ + Get tensors for a single cloud from the list representation. + + Args: + index: Integer in the range [0, N). + + Returns: + points: Tensor of shape (P, 3). + normals: Tensor of shape (P, 3) + features: LongTensor of shape (P, C). + """ + if not isinstance(index, int): + raise ValueError("Cloud index must be an integer.") + if index < 0 or index > self._N: + raise ValueError( + "Cloud index must be in the range [0, N) where \ + N is the number of clouds in the batch." + ) + points = self.points_list()[index] + normals, features = None, None + normals_list = self.normals_list() + if normals_list is not None: + normals = normals_list[index] + features_list = self.features_list() + if features_list is not None: + features = features_list[index] + return points, normals, features + + # TODO(nikhilar) Move function to a utils file. + def split(self, split_sizes: list): + """ + Splits Pointclouds object of size N into a list of Pointclouds objects + of size len(split_sizes), where the i-th Pointclouds object is of size + split_sizes[i]. Similar to torch.split(). + + Args: + split_sizes: List of integer sizes of Pointclouds objects to be + returned. + + Returns: + list[Pointclouds]. + """ + if not all(isinstance(x, int) for x in split_sizes): + raise ValueError("Value of split_sizes must be a list of integers.") + cloudlist = [] + curi = 0 + for i in split_sizes: + cloudlist.append(self[curi : curi + i]) + curi += i + return cloudlist + + def offset_(self, offsets_packed): + """ + Translate the point clouds by an offset. In place operation. + + Args: + offsets_packed: A Tensor of shape (3,) or the same shape + as self.points_packed giving offsets to be added to + all points. + + Returns: + self. + """ + points_packed = self.points_packed() + if offsets_packed.shape == (3,): + offsets_packed = offsets_packed.expand_as(points_packed) + if offsets_packed.shape != points_packed.shape: + raise ValueError("Offsets must have dimension (all_p, 3).") + self._points_packed = points_packed + offsets_packed + new_points_list = list( + self._points_packed.split(self.num_points_per_cloud().tolist(), 0) + ) + # Note that since _compute_packed() has been executed, points_list + # cannot be None even if not provided during construction. + self._points_list = new_points_list + if self._points_padded is not None: + for i, points in enumerate(new_points_list): + if len(points) > 0: + self._points_padded[i, : points.shape[0], :] = points + return self + + # TODO(nikhilar) Move out of place operator to a utils file. + def offset(self, offsets_packed): + """ + Out of place offset. + + Args: + offsets_packed: A Tensor of the same shape as self.points_packed + giving offsets to be added to all points. + Returns: + new Pointclouds object. + """ + new_clouds = self.clone() + return new_clouds.offset_(offsets_packed) + + def subsample(self, max_points: Union[int, Sequence[int]]) -> "Pointclouds": + """ + Subsample each cloud so that it has at most max_points points. + + Args: + max_points: maximum number of points in each cloud. + + Returns: + new Pointclouds object, or self if nothing to be done. + """ + if isinstance(max_points, int): + max_points = [max_points] * len(self) + elif len(max_points) != len(self): + raise ValueError("wrong number of max_points supplied") + if all( + int(n_points) <= int(max_) + for n_points, max_ in zip(self.num_points_per_cloud(), max_points) + ): + return self + + points_list = [] + features_list = [] + normals_list = [] + for max_, n_points, points, features, normals in zip_longest( + map(int, max_points), + map(int, self.num_points_per_cloud()), + self.points_list(), + self.features_list() or (), + self.normals_list() or (), + ): + if n_points > max_: + keep_np = np.random.choice(n_points, max_, replace=False) + keep = torch.tensor(keep_np, device=points.device, dtype=torch.int64) + points = points[keep] + if features is not None: + features = features[keep] + if normals is not None: + normals = normals[keep] + points_list.append(points) + features_list.append(features) + normals_list.append(normals) + + return Pointclouds( + points=points_list, + normals=self.normals_list() and normals_list, + features=self.features_list() and features_list, + ) + + def scale_(self, scale): + """ + Multiply the coordinates of this object by a scalar value. + - i.e. enlarge/dilate + In place operation. + + Args: + scale: A scalar, or a Tensor of shape (N,). + + Returns: + self. + """ + if not torch.is_tensor(scale): + scale = torch.full((len(self),), scale, device=self.device) + new_points_list = [] + points_list = self.points_list() + for i, old_points in enumerate(points_list): + new_points_list.append(scale[i] * old_points) + self._points_list = new_points_list + if self._points_packed is not None: + self._points_packed = torch.cat(new_points_list, dim=0) + if self._points_padded is not None: + for i, points in enumerate(new_points_list): + if len(points) > 0: + self._points_padded[i, : points.shape[0], :] = points + return self + + def scale(self, scale): + """ + Out of place scale_. + + Args: + scale: A scalar, or a Tensor of shape (N,). + + Returns: + new Pointclouds object. + """ + new_clouds = self.clone() + return new_clouds.scale_(scale) + + # TODO(nikhilar) Move function to utils file. + def get_bounding_boxes(self): + """ + Compute an axis-aligned bounding box for each cloud. + + Returns: + bboxes: Tensor of shape (N, 3, 2) where bbox[i, j] gives the + min and max values of cloud i along the jth coordinate axis. + """ + all_mins, all_maxes = [], [] + for points in self.points_list(): + cur_mins = points.min(dim=0)[0] # (3,) + cur_maxes = points.max(dim=0)[0] # (3,) + all_mins.append(cur_mins) + all_maxes.append(cur_maxes) + all_mins = torch.stack(all_mins, dim=0) # (N, 3) + all_maxes = torch.stack(all_maxes, dim=0) # (N, 3) + bboxes = torch.stack([all_mins, all_maxes], dim=2) + return bboxes + + def estimate_normals( + self, + neighborhood_size: int = 50, + disambiguate_directions: bool = True, + assign_to_self: bool = False, + ): + """ + Estimates the normals of each point in each cloud and assigns + them to the internal tensors `self._normals_list` and `self._normals_padded` + + The function uses `ops.estimate_pointcloud_local_coord_frames` + to estimate the normals. Please refer to that function for more + detailed information about the implemented algorithm. + + Args: + **neighborhood_size**: The size of the neighborhood used to estimate the + geometry around each point. + **disambiguate_directions**: If `True`, uses the algorithm from [1] to + ensure sign consistency of the normals of neighboring points. + **normals**: A tensor of normals for each input point + of shape `(minibatch, num_point, 3)`. + If `pointclouds` are of `Pointclouds` class, returns a padded tensor. + **assign_to_self**: If `True`, assigns the computed normals to the + internal buffers overwriting any previously stored normals. + + References: + [1] Tombari, Salti, Di Stefano: Unique Signatures of Histograms for + Local Surface Description, ECCV 2010. + """ + from .. import ops + + # estimate the normals + normals_est = ops.estimate_pointcloud_normals( + self, + neighborhood_size=neighborhood_size, + disambiguate_directions=disambiguate_directions, + ) + + # assign to self + if assign_to_self: + _, self._normals_padded, _ = self._parse_auxiliary_input(normals_est) + self._normals_list, self._normals_packed = None, None + if self._points_list is not None: + # update self._normals_list + self.normals_list() + if self._points_packed is not None: + # update self._normals_packed + self._normals_packed = torch.cat(self._normals_list, dim=0) + + return normals_est + + def extend(self, N: int): + """ + Create new Pointclouds which contains each cloud N times. + + Args: + N: number of new copies of each cloud. + + Returns: + new Pointclouds object. + """ + if not isinstance(N, int): + raise ValueError("N must be an integer.") + if N <= 0: + raise ValueError("N must be > 0.") + + new_points_list, new_normals_list, new_features_list = [], None, None + for points in self.points_list(): + new_points_list.extend(points.clone() for _ in range(N)) + normals_list = self.normals_list() + if normals_list is not None: + new_normals_list = [] + for normals in normals_list: + new_normals_list.extend(normals.clone() for _ in range(N)) + features_list = self.features_list() + if features_list is not None: + new_features_list = [] + for features in features_list: + new_features_list.extend(features.clone() for _ in range(N)) + return self.__class__( + points=new_points_list, normals=new_normals_list, features=new_features_list + ) + + def update_padded( + self, new_points_padded, new_normals_padded=None, new_features_padded=None + ): + """ + Returns a Pointcloud structure with updated padded tensors and copies of + the auxiliary tensors. This function allows for an update of + points_padded (and normals and features) without having to explicitly + convert it to the list representation for heterogeneous batches. + + Args: + new_points_padded: FloatTensor of shape (N, P, 3) + new_normals_padded: (optional) FloatTensor of shape (N, P, 3) + new_features_padded: (optional) FloatTensor of shape (N, P, C) + + Returns: + Pointcloud with updated padded representations + """ + + def check_shapes(x, size): + if x.shape[0] != size[0]: + raise ValueError("new values must have the same batch dimension.") + if x.shape[1] != size[1]: + raise ValueError("new values must have the same number of points.") + if size[2] is not None: + if x.shape[2] != size[2]: + raise ValueError( + "new values must have the same number of channels." + ) + + check_shapes(new_points_padded, [self._N, self._P, 3]) + if new_normals_padded is not None: + check_shapes(new_normals_padded, [self._N, self._P, 3]) + if new_features_padded is not None: + check_shapes(new_features_padded, [self._N, self._P, self._C]) + + new = self.__class__( + points=new_points_padded, + normals=new_normals_padded, + features=new_features_padded, + ) + + # overwrite the equisized flag + new.equisized = self.equisized + + # copy normals + if new_normals_padded is None: + # If no normals are provided, keep old ones (shallow copy) + new._normals_list = self._normals_list + new._normals_padded = self._normals_padded + new._normals_packed = self._normals_packed + + # copy features + if new_features_padded is None: + # If no features are provided, keep old ones (shallow copy) + new._features_list = self._features_list + new._features_padded = self._features_padded + new._features_packed = self._features_packed + + # copy auxiliary tensors + copy_tensors = [ + "_packed_to_cloud_idx", + "_cloud_to_packed_first_idx", + "_num_points_per_cloud", + "_padded_to_packed_idx", + "valid", + ] + for k in copy_tensors: + v = getattr(self, k) + if torch.is_tensor(v): + setattr(new, k, v) # shallow copy + + # update points + new._points_padded = new_points_padded + assert new._points_list is None + assert new._points_packed is None + + # update normals and features if provided + if new_normals_padded is not None: + new._normals_padded = new_normals_padded + new._normals_list = None + new._normals_packed = None + if new_features_padded is not None: + new._features_padded = new_features_padded + new._features_list = None + new._features_packed = None + return new + + def inside_box(self, box): + """ + Finds the points inside a 3D box. + + Args: + box: FloatTensor of shape (2, 3) or (N, 2, 3) where N is the number + of clouds. + box[..., 0, :] gives the min x, y & z. + box[..., 1, :] gives the max x, y & z. + Returns: + idx: BoolTensor of length sum(P_i) indicating whether the packed points are + within the input box. + """ + if box.dim() > 3 or box.dim() < 2: + raise ValueError("Input box must be of shape (2, 3) or (N, 2, 3).") + + if box.dim() == 3 and box.shape[0] != 1 and box.shape[0] != self._N: + raise ValueError( + "Input box dimension is incompatible with pointcloud size." + ) + + if box.dim() == 2: + box = box[None] + + if (box[..., 0, :] > box[..., 1, :]).any(): + raise ValueError("Input box is invalid: min values larger than max values.") + + points_packed = self.points_packed() + sumP = points_packed.shape[0] + + if box.shape[0] == 1: + box = box.expand(sumP, 2, 3) + elif box.shape[0] == self._N: + box = box.unbind(0) + box = [ + b.expand(p, 2, 3) for (b, p) in zip(box, self.num_points_per_cloud()) + ] + box = torch.cat(box, 0) + + coord_inside = (points_packed >= box[:, 0]) * (points_packed <= box[:, 1]) + return coord_inside.all(dim=-1) + + +def join_pointclouds_as_batch(pointclouds: Sequence[Pointclouds]) -> Pointclouds: + """ + Merge a list of Pointclouds objects into a single batched Pointclouds + object. All pointclouds must be on the same device. + + Args: + batch: List of Pointclouds objects each with batch dim [b1, b2, ..., bN] + Returns: + pointcloud: Poinclouds object with all input pointclouds collated into + a single object with batch dim = sum(b1, b2, ..., bN) + """ + if isinstance(pointclouds, Pointclouds) or not isinstance(pointclouds, Sequence): + raise ValueError("Wrong first argument to join_points_as_batch.") + + device = pointclouds[0].device + if not all(p.device == device for p in pointclouds): + raise ValueError("Pointclouds must all be on the same device") + + kwargs = {} + for field in ("points", "normals", "features"): + field_list = [getattr(p, field + "_list")() for p in pointclouds] + if None in field_list: + if field == "points": + raise ValueError("Pointclouds cannot have their points set to None!") + if not all(f is None for f in field_list): + raise ValueError( + f"Pointclouds in the batch have some fields '{field}'" + + " defined and some set to None." + ) + field_list = None + else: + field_list = [p for points in field_list for p in points] + if field == "features" and any( + p.shape[1] != field_list[0].shape[1] for p in field_list[1:] + ): + raise ValueError("Pointclouds must have the same number of features") + kwargs[field] = field_list + + return Pointclouds(**kwargs) + + +def join_pointclouds_as_scene( + pointclouds: Union[Pointclouds, List[Pointclouds]] +) -> Pointclouds: + """ + Joins a batch of point cloud in the form of a Pointclouds object or a list of Pointclouds + objects as a single point cloud. If the input is a list, the Pointclouds objects in the + list must all be on the same device, and they must either all or none have features and + all or none have normals. + + Args: + Pointclouds: Pointclouds object that contains a batch of point clouds, or a list of + Pointclouds objects. + + Returns: + new Pointclouds object containing a single point cloud + """ + if isinstance(pointclouds, list): + pointclouds = join_pointclouds_as_batch(pointclouds) + + if len(pointclouds) == 1: + return pointclouds + points = pointclouds.points_packed() + features = pointclouds.features_packed() + normals = pointclouds.normals_packed() + pointcloud = Pointclouds( + points=points[None], + features=None if features is None else features[None], + normals=None if normals is None else normals[None], + ) + return pointcloud diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/structures/utils.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/structures/utils.py new file mode 100644 index 0000000000000000000000000000000000000000..6c0c4f73012d4b3b9601f69623d8d105e50a0db0 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/structures/utils.py @@ -0,0 +1,242 @@ +# 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. + +# pyre-unsafe + +from typing import List, Sequence, Tuple, Union + +import torch + + +""" +Util functions for points/verts/faces/volumes. +""" + + +def list_to_padded( + x: Union[List[torch.Tensor], Tuple[torch.Tensor]], + pad_size: Union[Sequence[int], None] = None, + pad_value: float = 0.0, + equisized: bool = False, +) -> torch.Tensor: + r""" + Transforms a list of N tensors each of shape (Si_0, Si_1, ... Si_D) + into: + - a single tensor of shape (N, pad_size(0), pad_size(1), ..., pad_size(D)) + if pad_size is provided + - or a tensor of shape (N, max(Si_0), max(Si_1), ..., max(Si_D)) if pad_size is None. + + Args: + x: list of Tensors + pad_size: list(int) specifying the size of the padded tensor. + If `None` (default), the largest size of each dimension + is set as the `pad_size`. + pad_value: float value to be used to fill the padded tensor + equisized: bool indicating whether the items in x are of equal size + (sometimes this is known and if provided saves computation) + + Returns: + x_padded: tensor consisting of padded input tensors stored + over the newly allocated memory. + """ + if equisized: + return torch.stack(x, 0) + + if not all(torch.is_tensor(y) for y in x): + raise ValueError("All items have to be instances of a torch.Tensor.") + + # we set the common number of dimensions to the maximum + # of the dimensionalities of the tensors in the list + element_ndim = max(y.ndim for y in x) + + # replace empty 1D tensors with empty tensors with a correct number of dimensions + x = [ + (y.new_zeros([0] * element_ndim) if (y.ndim == 1 and y.nelement() == 0) else y) + for y in x + ] + + if any(y.ndim != x[0].ndim for y in x): + raise ValueError("All items have to have the same number of dimensions!") + + if pad_size is None: + pad_dims = [ + max(y.shape[dim] for y in x if len(y) > 0) for dim in range(x[0].ndim) + ] + else: + if any(len(pad_size) != y.ndim for y in x): + raise ValueError("Pad size must contain target size for all dimensions.") + pad_dims = pad_size + + N = len(x) + x_padded = x[0].new_full((N, *pad_dims), pad_value) + for i, y in enumerate(x): + if len(y) > 0: + slices = (i, *(slice(0, y.shape[dim]) for dim in range(y.ndim))) + x_padded[slices] = y + return x_padded + + +def padded_to_list( + x: torch.Tensor, + split_size: Union[Sequence[int], Sequence[Sequence[int]], None] = None, +): + r""" + Transforms a padded tensor of shape (N, S_1, S_2, ..., S_D) into a list + of N tensors of shape: + - (Si_1, Si_2, ..., Si_D) where (Si_1, Si_2, ..., Si_D) is specified in split_size(i) + - or (S_1, S_2, ..., S_D) if split_size is None + - or (Si_1, S_2, ..., S_D) if split_size(i) is an integer. + + Args: + x: tensor + split_size: optional 1D or 2D list/tuple of ints defining the number of + items for each tensor. + + Returns: + x_list: a list of tensors sharing the memory with the input. + """ + x_list = list(x.unbind(0)) + + if split_size is None: + return x_list + + N = len(split_size) + if x.shape[0] != N: + raise ValueError("Split size must be of same length as inputs first dimension") + + for i in range(N): + if isinstance(split_size[i], int): + x_list[i] = x_list[i][: split_size[i]] + else: + slices = tuple(slice(0, s) for s in split_size[i]) # pyre-ignore + x_list[i] = x_list[i][slices] + return x_list + + +def list_to_packed(x: List[torch.Tensor]): + r""" + Transforms a list of N tensors each of shape (Mi, K, ...) into a single + tensor of shape (sum(Mi), K, ...). + + Args: + x: list of tensors. + + Returns: + 4-element tuple containing + + - **x_packed**: tensor consisting of packed input tensors along the + 1st dimension. + - **num_items**: tensor of shape N containing Mi for each element in x. + - **item_packed_first_idx**: tensor of shape N indicating the index of + the first item belonging to the same element in the original list. + - **item_packed_to_list_idx**: tensor of shape sum(Mi) containing the + index of the element in the list the item belongs to. + """ + if not x: + raise ValueError("Input list is empty") + device = x[0].device + sizes = [xi.shape[0] for xi in x] + sizes_total = sum(sizes) + num_items = torch.tensor(sizes, dtype=torch.int64, device=device) + item_packed_first_idx = torch.zeros_like(num_items) + item_packed_first_idx[1:] = torch.cumsum(num_items[:-1], dim=0) + item_packed_to_list_idx = torch.arange( + sizes_total, dtype=torch.int64, device=device + ) + item_packed_to_list_idx = ( + torch.bucketize(item_packed_to_list_idx, item_packed_first_idx, right=True) - 1 + ) + x_packed = torch.cat(x, dim=0) + + return x_packed, num_items, item_packed_first_idx, item_packed_to_list_idx + + +def packed_to_list(x: torch.Tensor, split_size: Union[list, int]): + r""" + Transforms a tensor of shape (sum(Mi), K, L, ...) to N set of tensors of + shape (Mi, K, L, ...) where Mi's are defined in split_size + + Args: + x: tensor + split_size: list, tuple or int defining the number of items for each tensor + in the output list. + + Returns: + x_list: A list of Tensors + """ + return x.split(split_size, dim=0) + + +def padded_to_packed( + x: torch.Tensor, + split_size: Union[list, tuple, None] = None, + pad_value: Union[float, int, None] = None, +): + r""" + Transforms a padded tensor of shape (N, M, K) into a packed tensor + of shape: + - (sum(Mi), K) where (Mi, K) are the dimensions of + each of the tensors in the batch and Mi is specified by split_size(i) + - (N*M, K) if split_size is None + + Support only for 3-dimensional input tensor and 1-dimensional split size. + + Args: + x: tensor + split_size: list, tuple or int defining the number of items for each tensor + in the output list. + pad_value: optional value to use to filter the padded values in the input + tensor. + + Only one of split_size or pad_value should be provided, or both can be None. + + Returns: + x_packed: a packed tensor. + """ + if x.ndim != 3: + raise ValueError("Supports only 3-dimensional input tensors") + + N, M, D = x.shape + + if split_size is not None and pad_value is not None: + raise ValueError("Only one of split_size or pad_value should be provided.") + + x_packed = x.reshape(-1, D) # flatten padded + + if pad_value is None and split_size is None: + return x_packed + + # Convert to packed using pad value + if pad_value is not None: + mask = x_packed.ne(pad_value).any(-1) + x_packed = x_packed[mask] + return x_packed + + # Convert to packed using split sizes + # pyre-fixme[6]: Expected `Sized` for 1st param but got `Union[None, + # List[typing.Any], typing.Tuple[typing.Any, ...]]`. + N = len(split_size) + if x.shape[0] != N: + raise ValueError("Split size must be of same length as inputs first dimension") + + # pyre-fixme[16]: `None` has no attribute `__iter__`. + if not all(isinstance(i, int) for i in split_size): + raise ValueError( + "Support only 1-dimensional unbinded tensor. \ + Split size for more dimensions provided" + ) + + padded_to_packed_idx = torch.cat( + [ + torch.arange(v, dtype=torch.int64, device=x.device) + i * M + # pyre-fixme[6]: Expected `Iterable[Variable[_T]]` for 1st param but got + # `Union[None, List[typing.Any], typing.Tuple[typing.Any, ...]]`. + for (i, v) in enumerate(split_size) + ], + dim=0, + ) + + return x_packed[padded_to_packed_idx] diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/structures/volumes.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/structures/volumes.py new file mode 100644 index 0000000000000000000000000000000000000000..8bf069b5f9e2b46c8203cf23666bb2fc8e7dcc45 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/structures/volumes.py @@ -0,0 +1,1137 @@ +# 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. + +# pyre-unsafe + +import copy +from typing import List, Optional, Tuple, Union + +import torch +from pytorch3d.common.compat import meshgrid_ij +from pytorch3d.common.datatypes import Device, make_device +from pytorch3d.transforms import Scale, Transform3d + +from . import utils as struct_utils + + +_Scalar = Union[int, float] +_Vector = Union[torch.Tensor, Tuple[_Scalar, ...], List[_Scalar]] +_ScalarOrVector = Union[_Scalar, _Vector] + +_VoxelSize = _ScalarOrVector +_Translation = _Vector + +_TensorBatch = Union[torch.Tensor, List[torch.Tensor], Tuple[torch.Tensor]] +_ALL_CONTENT: slice = slice(0, None) + + +class Volumes: + """ + This class provides functions for working with batches of volumetric grids + of possibly varying spatial sizes. + + VOLUME DENSITIES + + The Volumes class can be either constructed from a 5D tensor of + `densities` of size `batch x density_dim x depth x height x width` or + from a list of differently-sized 4D tensors `[D_1, ..., D_batch]`, + where each `D_i` is of size `[density_dim x depth_i x height_i x width_i]`. + + In case the `Volumes` object is initialized from the list of `densities`, + the list of tensors is internally converted to a single 5D tensor by + zero-padding the relevant dimensions. Both list and padded representations can be + accessed with the `Volumes.densities()` or `Volumes.densities_list()` getters. + The sizes of the individual volumes in the structure can be retrieved + with the `Volumes.get_grid_sizes()` getter. + + The `Volumes` class is immutable. I.e. after generating a `Volumes` object, + one cannot change its properties, such as `self._densities` or `self._features` + anymore. + + + VOLUME FEATURES + + While the `densities` field is intended to represent various measures of the + "density" of the volume cells (opacity, signed/unsigned distances + from the nearest surface, ...), one can additionally initialize the + object with the `features` argument. `features` are either a 5D tensor + of shape `batch x feature_dim x depth x height x width` or a list of + of differently-sized 4D tensors `[F_1, ..., F_batch]`, + where each `F_i` is of size `[feature_dim x depth_i x height_i x width_i]`. + `features` are intended to describe other properties of volume cells, + such as per-voxel 3D vectors of RGB colors that can be later used + for rendering the volume. + + + VOLUME COORDINATES + + Additionally, using the `VolumeLocator` class the `Volumes` class keeps track + of the locations of the centers of the volume cells in the local volume + coordinates as well as in the world coordinates. + + Local coordinates: + - Represent the locations of the volume cells in the local coordinate + frame of the volume. + - The center of the voxel indexed with `[·, ·, 0, 0, 0]` in the volume + has its 3D local coordinate set to `[-1, -1, -1]`, while the voxel + at index `[·, ·, depth_i-1, height_i-1, width_i-1]` has its + 3D local coordinate set to `[1, 1, 1]`. + - The first/second/third coordinate of each of the 3D per-voxel + XYZ vector denotes the horizontal/vertical/depth-wise position + respectively. I.e the order of the coordinate dimensions in the + volume is reversed w.r.t. the order of the 3D coordinate vectors. + - The intermediate coordinates between `[-1, -1, -1]` and `[1, 1, 1]`. + are linearly interpolated over the spatial dimensions of the volume. + - Note that the convention is the same as for the 5D version of the + `torch.nn.functional.grid_sample` function called with + the same value of `align_corners` argument. + - Note that the local coordinate convention of `Volumes` + (+X = left to right, +Y = top to bottom, +Z = away from the user) + is *different* from the world coordinate convention of the + renderer for `Meshes` or `Pointclouds` + (+X = right to left, +Y = bottom to top, +Z = away from the user). + + World coordinates: + - These define the locations of the centers of the volume cells + in the world coordinates. + - They are specified with the following mapping that converts + points `x_local` in the local coordinates to points `x_world` + in the world coordinates:: + + x_world = ( + x_local * (volume_size - 1) * 0.5 * voxel_size + ) - volume_translation, + + here `voxel_size` specifies the size of each voxel of the volume, + and `volume_translation` is the 3D offset of the central voxel of + the volume w.r.t. the origin of the world coordinate frame. + Both `voxel_size` and `volume_translation` are specified in + the world coordinate units. `volume_size` is the spatial size of + the volume in form of a 3D vector `[width, height, depth]`. + - Given the above definition of `x_world`, one can derive the + inverse mapping from `x_world` to `x_local` as follows:: + + x_local = ( + (x_world + volume_translation) / (0.5 * voxel_size) + ) / (volume_size - 1) + + - For a trivial volume with `volume_translation==[0, 0, 0]` + with `voxel_size=-1`, `x_world` would range + from -(volume_size-1)/2` to `+(volume_size-1)/2`. + + Coordinate tensors that denote the locations of each of the volume cells in + local / world coordinates (with shape `(depth x height x width x 3)`) + can be retrieved by calling the `Volumes.get_coord_grid()` getter with the + appropriate `world_coordinates` argument. + + Internally, the mapping between `x_local` and `x_world` is represented + as a `Transform3d` object `Volumes.VolumeLocator._local_to_world_transform`. + Users can access the relevant transformations with the + `Volumes.get_world_to_local_coords_transform()` and + `Volumes.get_local_to_world_coords_transform()` + functions. + + Example coordinate conversion: + - For a "trivial" volume with `voxel_size = 1.`, + `volume_translation=[0., 0., 0.]`, and the spatial size of + `DxHxW = 5x5x5`, the point `x_world = (-2, 0, 2)` gets mapped + to `x_local=(-1, 0, 1)`. + - For a "trivial" volume `v` with `voxel_size = 1.`, + `volume_translation=[0., 0., 0.]`, the following holds: + + torch.nn.functional.grid_sample( + v.densities(), + v.get_coord_grid(world_coordinates=False), + align_corners=align_corners, + ) == v.densities(), + + i.e. sampling the volume at trivial local coordinates + (no scaling with `voxel_size`` or shift with `volume_translation`) + results in the same volume. + """ + + def __init__( + self, + densities: _TensorBatch, + features: Optional[_TensorBatch] = None, + voxel_size: _VoxelSize = 1.0, + volume_translation: _Translation = (0.0, 0.0, 0.0), + align_corners: bool = True, + ) -> None: + """ + Args: + **densities**: Batch of input feature volume occupancies of shape + `(minibatch, density_dim, depth, height, width)`, or a list + of 4D tensors `[D_1, ..., D_minibatch]` where each `D_i` has + shape `(density_dim, depth_i, height_i, width_i)`. + Typically, each voxel contains a non-negative number + corresponding to its opaqueness. + **features**: Batch of input feature volumes of shape: + `(minibatch, feature_dim, depth, height, width)` or a list + of 4D tensors `[F_1, ..., F_minibatch]` where each `F_i` has + shape `(feature_dim, depth_i, height_i, width_i)`. + The field is optional and can be set to `None` in case features are + not required. + **voxel_size**: Denotes the size of each volume voxel in world units. + Has to be one of: + a) A scalar (square voxels) + b) 3-tuple or a 3-list of scalars + c) a Tensor of shape (3,) + d) a Tensor of shape (minibatch, 3) + e) a Tensor of shape (minibatch, 1) + f) a Tensor of shape (1,) (square voxels) + **volume_translation**: Denotes the 3D translation of the center + of the volume in world units. Has to be one of: + a) 3-tuple or a 3-list of scalars + b) a Tensor of shape (3,) + c) a Tensor of shape (minibatch, 3) + d) a Tensor of shape (1,) (square voxels) + **align_corners**: If set (default), the coordinates of the corner voxels are + exactly −1 or +1 in the local coordinate system. Otherwise, the coordinates + correspond to the centers of the corner voxels. Cf. the namesake argument to + `torch.nn.functional.grid_sample`. + """ + + # handle densities + densities_, grid_sizes = self._convert_densities_features_to_tensor( + densities, "densities" + ) + + # take device from densities + self.device = densities_.device + + # assign to the internal buffers + self._densities = densities_ + + # assign a coordinate transformation member + self.locator = VolumeLocator( + batch_size=len(self), + grid_sizes=grid_sizes, + voxel_size=voxel_size, + volume_translation=volume_translation, + device=self.device, + align_corners=align_corners, + ) + + # handle features + self._features = None + if features is not None: + self._set_features(features) + + def _convert_densities_features_to_tensor( + self, x: _TensorBatch, var_name: str + ) -> Tuple[torch.Tensor, torch.LongTensor]: + """ + Handle the `densities` or `features` arguments to the constructor. + """ + if isinstance(x, (list, tuple)): + x_tensor = struct_utils.list_to_padded(x) + if any(x_.ndim != 4 for x_ in x): + raise ValueError( + f"`{var_name}` has to be a list of 4-dim tensors of shape: " + f"({var_name}_dim, height, width, depth)" + ) + if any(x_.shape[0] != x[0].shape[0] for x_ in x): + raise ValueError( + f"Each entry in the list of `{var_name}` has to have the " + "same number of channels (first dimension in the tensor)." + ) + x_shapes = torch.stack( + [ + torch.tensor( + list(x_.shape[1:]), dtype=torch.long, device=x_tensor.device + ) + for x_ in x + ], + dim=0, + ) + elif torch.is_tensor(x): + if x.ndim != 5: + raise ValueError( + f"`{var_name}` has to be a 5-dim tensor of shape: " + f"(minibatch, {var_name}_dim, height, width, depth)" + ) + x_tensor = x + x_shapes = torch.tensor( + list(x.shape[2:]), dtype=torch.long, device=x.device + )[None].repeat(x.shape[0], 1) + else: + raise ValueError( + f"{var_name} must be either a list or a tensor with " + f"shape (batch_size, {var_name}_dim, H, W, D)." + ) + # pyre-ignore[7] + return x_tensor, x_shapes + + def __len__(self) -> int: + return self._densities.shape[0] + + def __getitem__( + self, + index: Union[ + int, List[int], Tuple[int], slice, torch.BoolTensor, torch.LongTensor + ], + ) -> "Volumes": + """ + Args: + index: Specifying the index of the volume to retrieve. + Can be an int, slice, list of ints or a boolean or a long tensor. + + Returns: + Volumes object with selected volumes. The tensors are not cloned. + """ + if isinstance(index, int): + index = torch.LongTensor([index]) + elif isinstance(index, (slice, list, tuple)): + pass + elif torch.is_tensor(index): + if index.dim() != 1 or index.dtype.is_floating_point: + raise IndexError(index) + else: + raise IndexError(index) + + new = self.__class__( + # pyre-fixme[16]: `Optional` has no attribute `__getitem__`. + features=self.features()[index] if self._features is not None else None, + densities=self.densities()[index], + ) + # dont forget to update grid_sizes! + self.locator._copy_transform_and_sizes(new.locator, index=index) + return new + + def features(self) -> Optional[torch.Tensor]: + """ + Returns the features of the volume. + + Returns: + **features**: The tensor of volume features. + """ + return self._features + + def densities(self) -> torch.Tensor: + """ + Returns the densities of the volume. + + Returns: + **densities**: The tensor of volume densities. + """ + return self._densities + + def densities_list(self) -> List[torch.Tensor]: + """ + Get the list representation of the densities. + + Returns: + list of tensors of densities of shape (dim_i, D_i, H_i, W_i). + """ + return self._features_densities_list(self.densities()) + + def features_list(self) -> List[torch.Tensor]: + """ + Get the list representation of the features. + + Returns: + list of tensors of features of shape (dim_i, D_i, H_i, W_i) + or `None` for feature-less volumes. + """ + features_ = self.features() + if features_ is None: + # No features provided so return None + # pyre-fixme[7]: Expected `List[torch.Tensor]` but got `None`. + return None + return self._features_densities_list(features_) + + def get_align_corners(self) -> bool: + """ + Return whether the corners of the voxels should be aligned with the + image pixels. + """ + return self.locator._align_corners + + def _features_densities_list(self, x: torch.Tensor) -> List[torch.Tensor]: + """ + Retrieve the list representation of features/densities. + + Args: + x: self.features() or self.densities() + + Returns: + list of tensors of features/densities of shape (dim_i, D_i, H_i, W_i). + """ + x_dim = x.shape[1] + pad_sizes = torch.nn.functional.pad( + self.get_grid_sizes(), [1, 0], mode="constant", value=x_dim + ) + x_list = struct_utils.padded_to_list(x, pad_sizes.tolist()) + return x_list + + def update_padded( + self, new_densities: torch.Tensor, new_features: Optional[torch.Tensor] = None + ) -> "Volumes": + """ + Returns a Volumes structure with updated padded tensors and copies of + the auxiliary tensors `self._local_to_world_transform`, + `device` and `self._grid_sizes`. This function allows for an update of + densities (and features) without having to explicitly + convert it to the list representation for heterogeneous batches. + + Args: + new_densities: FloatTensor of shape (N, dim_density, D, H, W) + new_features: (optional) FloatTensor of shape (N, dim_feature, D, H, W) + + Returns: + Volumes with updated features and densities + """ + new = copy.copy(self) + new._set_densities(new_densities) + if new_features is None: + new._features = None + else: + new._set_features(new_features) + return new + + def _set_features(self, features: _TensorBatch) -> None: + self._set_densities_features("features", features) + + def _set_densities(self, densities: _TensorBatch) -> None: + self._set_densities_features("densities", densities) + + def _set_densities_features(self, var_name: str, x: _TensorBatch) -> None: + x_tensor, grid_sizes = self._convert_densities_features_to_tensor(x, var_name) + if x_tensor.device != self.device: + raise ValueError( + f"`{var_name}` have to be on the same device as `self.densities`." + ) + if len(x_tensor.shape) != 5: + raise ValueError( + f"{var_name} has to be a 5-dim tensor of shape: " + f"(minibatch, {var_name}_dim, height, width, depth)" + ) + + if not ( + (self.get_grid_sizes().shape == grid_sizes.shape) + and torch.allclose(self.get_grid_sizes(), grid_sizes) + ): + raise ValueError( + f"The size of every grid in `{var_name}` has to match the size of" + "the corresponding `densities` grid." + ) + setattr(self, "_" + var_name, x_tensor) + + def clone(self) -> "Volumes": + """ + Deep copy of Volumes object. All internal tensors are cloned + individually. + + Returns: + new Volumes object. + """ + return copy.deepcopy(self) + + def to(self, device: Device, copy: bool = False) -> "Volumes": + """ + Match the functionality of torch.Tensor.to() + If copy = True or the self Tensor is on a different device, the + returned tensor is a copy of self with the desired torch.device. + If copy = False and the self Tensor already has the correct torch.device, + then self is returned. + + Args: + device: Device (as str or torch.device) for the new tensor. + copy: Boolean indicator whether or not to clone self. Default False. + + Returns: + Volumes object. + """ + device_ = make_device(device) + if not copy and self.device == device_: + return self + + other = self.clone() + if self.device == device_: + return other + + other.device = device_ + other._densities = self._densities.to(device_) + if self._features is not None: + # pyre-fixme[16]: `Optional` has no attribute `to`. + other._features = self.features().to(device_) + self.locator._copy_transform_and_sizes(other.locator, device=device_) + other.locator = other.locator.to(device, copy) + return other + + def cpu(self) -> "Volumes": + return self.to("cpu") + + def cuda(self) -> "Volumes": + return self.to("cuda") + + def get_grid_sizes(self) -> torch.LongTensor: + """ + Returns the sizes of individual volumetric grids in the structure. + + Returns: + **grid_sizes**: Tensor of spatial sizes of each of the volumes + of size (batchsize, 3), where i-th row holds (D_i, H_i, W_i). + """ + return self.locator.get_grid_sizes() + + def get_local_to_world_coords_transform(self) -> Transform3d: + """ + Return a Transform3d object that converts points in the + the local coordinate frame of the volume to world coordinates. + Local volume coordinates are scaled s.t. the coordinates along one + side of the volume are in range [-1, 1]. + + Returns: + **local_to_world_transform**: A Transform3d object converting + points from local coordinates to the world coordinates. + """ + return self.locator.get_local_to_world_coords_transform() + + def get_world_to_local_coords_transform(self) -> Transform3d: + """ + Return a Transform3d object that converts points in the + world coordinates to the local coordinate frame of the volume. + Local volume coordinates are scaled s.t. the coordinates along one + side of the volume are in range [-1, 1]. + + Returns: + **world_to_local_transform**: A Transform3d object converting + points from world coordinates to local coordinates. + """ + return self.get_local_to_world_coords_transform().inverse() + + def world_to_local_coords(self, points_3d_world: torch.Tensor) -> torch.Tensor: + """ + Convert a batch of 3D point coordinates `points_3d_world` of shape + (minibatch, ..., dim) in the world coordinates to + the local coordinate frame of the volume. Local volume + coordinates are scaled s.t. the coordinates along one side of the volume + are in range [-1, 1]. + + Args: + **points_3d_world**: A tensor of shape `(minibatch, ..., 3)` + containing the 3D coordinates of a set of points that will + be converted from the local volume coordinates (ranging + within [-1, 1]) to the world coordinates + defined by the `self.center` and `self.voxel_size` parameters. + + Returns: + **points_3d_local**: `points_3d_world` converted to the local + volume coordinates of shape `(minibatch, ..., 3)`. + """ + return self.locator.world_to_local_coords(points_3d_world) + + def local_to_world_coords(self, points_3d_local: torch.Tensor) -> torch.Tensor: + """ + Convert a batch of 3D point coordinates `points_3d_local` of shape + (minibatch, ..., dim) in the local coordinate frame of the volume + to the world coordinates. + + Args: + **points_3d_local**: A tensor of shape `(minibatch, ..., 3)` + containing the 3D coordinates of a set of points that will + be converted from the local volume coordinates (ranging + within [-1, 1]) to the world coordinates + defined by the `self.center` and `self.voxel_size` parameters. + + Returns: + **points_3d_world**: `points_3d_local` converted to the world + coordinates of the volume of shape `(minibatch, ..., 3)`. + """ + return self.locator.local_to_world_coords(points_3d_local) + + def get_coord_grid(self, world_coordinates: bool = True) -> torch.Tensor: + """ + Return the 3D coordinate grid of the volumetric grid + in local (`world_coordinates=False`) or world coordinates + (`world_coordinates=True`). + + The grid records location of each center of the corresponding volume voxel. + + Local coordinates are scaled s.t. the values along one side of the + volume are in range [-1, 1]. + + Args: + **world_coordinates**: if `True`, the method + returns the grid in the world coordinates, + otherwise, in local coordinates. + + Returns: + **coordinate_grid**: The grid of coordinates of shape + `(minibatch, depth, height, width, 3)`, where `minibatch`, + `height`, `width` and `depth` are the batch size, height, width + and depth of the volume `features` or `densities`. + """ + return self.locator.get_coord_grid(world_coordinates) + + +class VolumeLocator: + """ + The `VolumeLocator` class keeps track of the locations of the + centers of the volume cells in the local volume coordinates as well as in + the world coordinates for a voxel grid structure in 3D. + + Local coordinates: + - Represent the locations of the volume cells in the local coordinate + frame of the volume. + - The center of the voxel indexed with `[·, ·, 0, 0, 0]` in the volume + has its 3D local coordinate set to `[-1, -1, -1]`, while the voxel + at index `[·, ·, depth_i-1, height_i-1, width_i-1]` has its + 3D local coordinate set to `[1, 1, 1]`. + - The first/second/third coordinate of each of the 3D per-voxel + XYZ vector denotes the horizontal/vertical/depth-wise position + respectively. I.e the order of the coordinate dimensions in the + volume is reversed w.r.t. the order of the 3D coordinate vectors. + - The intermediate coordinates between `[-1, -1, -1]` and `[1, 1, 1]`. + are linearly interpolated over the spatial dimensions of the volume. + - Note that the convention is the same as for the 5D version of the + `torch.nn.functional.grid_sample` function called with + the same value of `align_corners` argument. + - Note that the local coordinate convention of `VolumeLocator` + (+X = left to right, +Y = top to bottom, +Z = away from the user) + is *different* from the world coordinate convention of the + renderer for `Meshes` or `Pointclouds` + (+X = right to left, +Y = bottom to top, +Z = away from the user). + + World coordinates: + - These define the locations of the centers of the volume cells + in the world coordinates. + - They are specified with the following mapping that converts + points `x_local` in the local coordinates to points `x_world` + in the world coordinates:: + + x_world = ( + x_local * (volume_size - 1) * 0.5 * voxel_size + ) - volume_translation, + + here `voxel_size` specifies the size of each voxel of the volume, + and `volume_translation` is the 3D offset of the central voxel of + the volume w.r.t. the origin of the world coordinate frame. + Both `voxel_size` and `volume_translation` are specified in + the world coordinate units. `volume_size` is the spatial size of + the volume in form of a 3D vector `[width, height, depth]`. + - Given the above definition of `x_world`, one can derive the + inverse mapping from `x_world` to `x_local` as follows:: + + x_local = ( + (x_world + volume_translation) / (0.5 * voxel_size) + ) / (volume_size - 1) + + - For a trivial volume with `volume_translation==[0, 0, 0]` + with `voxel_size=-1`, `x_world` would range + from -(volume_size-1)/2` to `+(volume_size-1)/2`. + + Coordinate tensors that denote the locations of each of the volume cells in + local / world coordinates (with shape `(depth x height x width x 3)`) + can be retrieved by calling the `VolumeLocator.get_coord_grid()` getter with the + appropriate `world_coordinates` argument. + + Internally, the mapping between `x_local` and `x_world` is represented + as a `Transform3d` object `VolumeLocator._local_to_world_transform`. + Users can access the relevant transformations with the + `VolumeLocator.get_world_to_local_coords_transform()` and + `VolumeLocator.get_local_to_world_coords_transform()` + functions. + + Example coordinate conversion: + - For a "trivial" volume with `voxel_size = 1.`, + `volume_translation=[0., 0., 0.]`, and the spatial size of + `DxHxW = 5x5x5`, the point `x_world = (-2, 0, 2)` gets mapped + to `x_local=(-1, 0, 1)`. + - For a "trivial" volume `v` with `voxel_size = 1.`, + `volume_translation=[0., 0., 0.]`, the following holds:: + + torch.nn.functional.grid_sample( + v.densities(), + v.get_coord_grid(world_coordinates=False), + align_corners=align_corners, + ) == v.densities(), + + i.e. sampling the volume at trivial local coordinates + (no scaling with `voxel_size`` or shift with `volume_translation`) + results in the same volume. + """ + + def __init__( + self, + batch_size: int, + grid_sizes: Union[ + torch.LongTensor, Tuple[int, int, int], List[torch.LongTensor] + ], + device: torch.device, + voxel_size: _VoxelSize = 1.0, + volume_translation: _Translation = (0.0, 0.0, 0.0), + align_corners: bool = True, + ): + """ + **batch_size** : Batch size of the underlying grids + **grid_sizes** : Represents the resolutions of different grids in the batch. Can be + a) tuple of form (H, W, D) + b) list/tuple of length batch_size of lists/tuples of form (H, W, D) + c) torch.Tensor of shape (batch_size, H, W, D) + H, W, D are height, width, depth respectively. If `grid_sizes` is a tuple than + all the grids in the batch have the same resolution. + **voxel_size**: Denotes the size of each volume voxel in world units. + Has to be one of: + a) A scalar (square voxels) + b) 3-tuple or a 3-list of scalars + c) a Tensor of shape (3,) + d) a Tensor of shape (minibatch, 3) + e) a Tensor of shape (minibatch, 1) + f) a Tensor of shape (1,) (square voxels) + **volume_translation**: Denotes the 3D translation of the center + of the volume in world units. Has to be one of: + a) 3-tuple or a 3-list of scalars + b) a Tensor of shape (3,) + c) a Tensor of shape (minibatch, 3) + d) a Tensor of shape (1,) (square voxels) + **align_corners**: If set (default), the coordinates of the corner voxels are + exactly −1 or +1 in the local coordinate system. Otherwise, the coordinates + correspond to the centers of the corner voxels. Cf. the namesake argument to + `torch.nn.functional.grid_sample`. + """ + self.device = device + self._batch_size = batch_size + self._grid_sizes = self._convert_grid_sizes2tensor(grid_sizes) + self._resolution = tuple(torch.max(self._grid_sizes.cpu(), dim=0).values) + self._align_corners = align_corners + + # set the local_to_world transform + self._set_local_to_world_transform( + voxel_size=voxel_size, + volume_translation=volume_translation, + ) + + def _convert_grid_sizes2tensor( + self, x: Union[torch.LongTensor, List[torch.LongTensor], Tuple[int, int, int]] + ) -> torch.LongTensor: + """ + Handle the grid_sizes argument to the constructor. + """ + if isinstance(x, (list, tuple)): + if isinstance(x[0], (torch.LongTensor, list, tuple)): + if self._batch_size != len(x): + raise ValueError("x should have a batch size of 'batch_size'") + # pyre-ignore[6] + if any(len(x_) != 3 for x_ in x): + raise ValueError( + "`grid_sizes` has to be a list of 3-dim tensors of shape: " + "(height, width, depth)" + ) + x_shapes = torch.stack( + [ + torch.tensor( + # pyre-ignore[6] + list(x_), + dtype=torch.long, + device=self.device, + ) + for x_ in x + ], + dim=0, + ) + elif isinstance(x[0], int): + x_shapes = torch.stack( + [ + torch.tensor(list(x), dtype=torch.long, device=self.device) + for _ in range(self._batch_size) + ], + dim=0, + ) + else: + raise ValueError( + "`grid_sizes` can be a list/tuple of int or torch.Tensor not of " + + "{type(x[0])}." + ) + + elif torch.is_tensor(x): + if x.ndim != 2: + raise ValueError( + "`grid_sizes` has to be a 2-dim tensor of shape: (minibatch, 3)" + ) + x_shapes = x.to(self.device) + else: + raise ValueError( + "grid_sizes must be either a list of tensors with shape (H, W, D), tensor with" + "shape (batch_size, H, W, D) or a tuple of (H, W, D)." + ) + # pyre-ignore[7] + return x_shapes + + def _voxel_size_translation_to_transform( + self, + voxel_size: torch.Tensor, + volume_translation: torch.Tensor, + batch_size: int, + ) -> Transform3d: + """ + Converts the `voxel_size` and `volume_translation` constructor arguments + to the internal `Transform3d` object `local_to_world_transform`. + """ + volume_size_zyx = self.get_grid_sizes().float() + volume_size_xyz = volume_size_zyx[:, [2, 1, 0]] + + # x_local = ( + # (x_world + volume_translation) / (0.5 * voxel_size) + # ) / (volume_size - 1) + + # x_world = ( + # x_local * (volume_size - 1) * 0.5 * voxel_size + # ) - volume_translation + + local_to_world_transform = Scale( + (volume_size_xyz - 1) * voxel_size * 0.5, device=self.device + ).translate(-volume_translation) + + return local_to_world_transform + + def get_coord_grid(self, world_coordinates: bool = True) -> torch.Tensor: + """ + Return the 3D coordinate grid of the volumetric grid + in local (`world_coordinates=False`) or world coordinates + (`world_coordinates=True`). + + The grid records location of each center of the corresponding volume voxel. + + Local coordinates are scaled s.t. the values along one side of the + volume are in range [-1, 1]. + + Args: + **world_coordinates**: if `True`, the method + returns the grid in the world coordinates, + otherwise, in local coordinates. + + Returns: + **coordinate_grid**: The grid of coordinates of shape + `(minibatch, depth, height, width, 3)`, where `minibatch`, + `height`, `width` and `depth` are the batch size, height, width + and depth of the volume `features` or `densities`. + """ + # TODO(dnovotny): Implement caching of the coordinate grid. + return self._calculate_coordinate_grid(world_coordinates=world_coordinates) + + def _calculate_coordinate_grid( + self, world_coordinates: bool = True + ) -> torch.Tensor: + """ + Calculate the 3D coordinate grid of the volumetric grid either + in local (`world_coordinates=False`) or + world coordinates (`world_coordinates=True`) . + """ + + ba, (de, he, wi) = self._batch_size, self._resolution + grid_sizes = self.get_grid_sizes() + + # generate coordinate axes + def corner_coord_adjustment(r): + return 0.0 if self._align_corners else 1.0 / r + + vol_axes = [ + torch.linspace( + -1.0 + corner_coord_adjustment(r), + 1.0 - corner_coord_adjustment(r), + r, + dtype=torch.float32, + device=self.device, + ) + for r in (de, he, wi) + ] + + # generate per-coord meshgrids + Z, Y, X = meshgrid_ij(vol_axes) + + # stack the coord grids ... this order matches the coordinate convention + # of torch.nn.grid_sample + vol_coords_local = torch.stack((X, Y, Z), dim=3)[None].repeat(ba, 1, 1, 1, 1) + + # get grid sizes relative to the maximal volume size + grid_sizes_relative = ( + torch.tensor([[de, he, wi]], device=grid_sizes.device, dtype=torch.float32) + - 1 + ) / (grid_sizes - 1).float() + + if (grid_sizes_relative != 1.0).any(): + # if any of the relative sizes != 1.0, adjust the grid + grid_sizes_relative_reshape = grid_sizes_relative[:, [2, 1, 0]][ + :, None, None, None + ] + vol_coords_local *= grid_sizes_relative_reshape + vol_coords_local += grid_sizes_relative_reshape - 1 + + if world_coordinates: + vol_coords = self.local_to_world_coords(vol_coords_local) + else: + vol_coords = vol_coords_local + + return vol_coords + + def get_local_to_world_coords_transform(self) -> Transform3d: + """ + Return a Transform3d object that converts points in the + the local coordinate frame of the volume to world coordinates. + Local volume coordinates are scaled s.t. the coordinates along one + side of the volume are in range [-1, 1]. + + Returns: + **local_to_world_transform**: A Transform3d object converting + points from local coordinates to the world coordinates. + """ + return self._local_to_world_transform + + def get_world_to_local_coords_transform(self) -> Transform3d: + """ + Return a Transform3d object that converts points in the + world coordinates to the local coordinate frame of the volume. + Local volume coordinates are scaled s.t. the coordinates along one + side of the volume are in range [-1, 1]. + + Returns: + **world_to_local_transform**: A Transform3d object converting + points from world coordinates to local coordinates. + """ + return self.get_local_to_world_coords_transform().inverse() + + def world_to_local_coords(self, points_3d_world: torch.Tensor) -> torch.Tensor: + """ + Convert a batch of 3D point coordinates `points_3d_world` of shape + (minibatch, ..., dim) in the world coordinates to + the local coordinate frame of the volume. Local volume + coordinates are scaled s.t. the coordinates along one side of the volume + are in range [-1, 1]. + + Args: + **points_3d_world**: A tensor of shape `(minibatch, ..., 3)` + containing the 3D coordinates of a set of points that will + be converted from the local volume coordinates (ranging + within [-1, 1]) to the world coordinates + defined by the `self.center` and `self.voxel_size` parameters. + + Returns: + **points_3d_local**: `points_3d_world` converted to the local + volume coordinates of shape `(minibatch, ..., 3)`. + """ + pts_shape = points_3d_world.shape + return ( + self.get_world_to_local_coords_transform() + .transform_points(points_3d_world.view(pts_shape[0], -1, 3)) + .view(pts_shape) + ) + + def local_to_world_coords(self, points_3d_local: torch.Tensor) -> torch.Tensor: + """ + Convert a batch of 3D point coordinates `points_3d_local` of shape + (minibatch, ..., dim) in the local coordinate frame of the volume + to the world coordinates. + + Args: + **points_3d_local**: A tensor of shape `(minibatch, ..., 3)` + containing the 3D coordinates of a set of points that will + be converted from the local volume coordinates (ranging + within [-1, 1]) to the world coordinates + defined by the `self.center` and `self.voxel_size` parameters. + + Returns: + **points_3d_world**: `points_3d_local` converted to the world + coordinates of the volume of shape `(minibatch, ..., 3)`. + """ + pts_shape = points_3d_local.shape + return ( + self.get_local_to_world_coords_transform() + .transform_points(points_3d_local.view(pts_shape[0], -1, 3)) + .view(pts_shape) + ) + + def get_grid_sizes(self) -> torch.LongTensor: + """ + Returns the sizes of individual volumetric grids in the structure. + + Returns: + **grid_sizes**: Tensor of spatial sizes of each of the volumes + of size (batchsize, 3), where i-th row holds (D_i, H_i, W_i). + """ + return self._grid_sizes + + def _set_local_to_world_transform( + self, + voxel_size: _VoxelSize = 1.0, + volume_translation: _Translation = (0.0, 0.0, 0.0), + ): + """ + Sets the internal representation of the transformation between the + world and local volume coordinates by specifying + `voxel_size` and `volume_translation` + + Args: + **voxel_size**: Denotes the size of input voxels. Has to be one of: + a) A scalar (square voxels) + b) 3-tuple or a 3-list of scalars + c) a Tensor of shape (3,) + d) a Tensor of shape (minibatch, 3) + e) a Tensor of shape (1,) (square voxels) + **volume_translation**: Denotes the 3D translation of the center + of the volume in world units. Has to be one of: + a) 3-tuple or a 3-list of scalars + b) a Tensor of shape (3,) + c) a Tensor of shape (minibatch, 3) + d) a Tensor of shape (1,) (square voxels) + """ + # handle voxel size and center + # here we force the tensors to lie on self.device + voxel_size = self._handle_voxel_size(voxel_size, len(self)) + volume_translation = self._handle_volume_translation( + volume_translation, len(self) + ) + self._local_to_world_transform = self._voxel_size_translation_to_transform( + voxel_size, volume_translation, len(self) + ) + + def _copy_transform_and_sizes( + self, + other: "VolumeLocator", + device: Optional[torch.device] = None, + index: Optional[ + Union[int, List[int], Tuple[int], slice, torch.Tensor] + ] = _ALL_CONTENT, + ) -> None: + """ + Copies the local to world transform and grid sizes to other VolumeLocator object + and moves it to specified device. Operates in place on other. + + Args: + other: VolumeLocator object to which to copy + device: torch.device on which to put the result, defatults to self.device + index: Specifies which parts to copy. + Can be an int, slice, list of ints or a boolean or a long tensor. + Defaults to all items (`:`). + """ + device = device if device is not None else self.device + other._grid_sizes = self._grid_sizes[index].to(device) + other._local_to_world_transform = self.get_local_to_world_coords_transform()[ + # pyre-fixme[6]: For 1st param expected `Union[List[int], int, slice, + # BoolTensor, LongTensor]` but got `Union[None, List[int], Tuple[int], + # int, slice, Tensor]`. + index + ].to(device) + + def _handle_voxel_size( + self, voxel_size: _VoxelSize, batch_size: int + ) -> torch.Tensor: + """ + Handle the `voxel_size` argument to the `VolumeLocator` constructor. + """ + err_msg = ( + "voxel_size has to be either a 3-tuple of scalars, or a scalar, or" + " a torch.Tensor of shape (3,) or (1,) or (minibatch, 3) or (minibatch, 1)." + ) + if isinstance(voxel_size, (float, int)): + # convert a scalar to a 3-element tensor + voxel_size = torch.full( + (1, 3), voxel_size, device=self.device, dtype=torch.float32 + ) + elif isinstance(voxel_size, torch.Tensor): + if voxel_size.numel() == 1: + # convert a single-element tensor to a 3-element one + voxel_size = voxel_size.view(-1).repeat(3) + elif len(voxel_size.shape) == 2 and ( + voxel_size.shape[0] == batch_size and voxel_size.shape[1] == 1 + ): + voxel_size = voxel_size.repeat(1, 3) + return self._convert_volume_property_to_tensor(voxel_size, batch_size, err_msg) + + def _handle_volume_translation( + self, translation: _Translation, batch_size: int + ) -> torch.Tensor: + """ + Handle the `volume_translation` argument to the `VolumeLocator` constructor. + """ + err_msg = ( + "`volume_translation` has to be either a 3-tuple of scalars, or" + " a Tensor of shape (1,3) or (minibatch, 3) or (3,)`." + ) + return self._convert_volume_property_to_tensor(translation, batch_size, err_msg) + + def __len__(self) -> int: + return self._batch_size + + def _convert_volume_property_to_tensor( + self, x: _Vector, batch_size: int, err_msg: str + ) -> torch.Tensor: + """ + Handle the `volume_translation` or `voxel_size` argument to + the VolumeLocator constructor. + Return a tensor of shape (N, 3) where N is the batch_size. + """ + if isinstance(x, (list, tuple)): + if len(x) != 3: + raise ValueError(err_msg) + x = torch.tensor(x, device=self.device, dtype=torch.float32)[None] + x = x.repeat((batch_size, 1)) + elif isinstance(x, torch.Tensor): + ok = ( + (x.shape[0] == 1 and x.shape[1] == 3) + or (x.shape[0] == 3 and len(x.shape) == 1) + or (x.shape[0] == batch_size and x.shape[1] == 3) + ) + if not ok: + raise ValueError(err_msg) + if x.device != self.device: + x = x.to(self.device) + if x.shape[0] == 3 and len(x.shape) == 1: + x = x[None] + if x.shape[0] == 1: + x = x.repeat((batch_size, 1)) + else: + raise ValueError(err_msg) + + return x + + def to(self, device: Device, copy: bool = False) -> "VolumeLocator": + """ + Match the functionality of torch.Tensor.to() + If copy = True or the self Tensor is on a different device, the + returned tensor is a copy of self with the desired torch.device. + If copy = False and the self Tensor already has the correct torch.device, + then self is returned. + + Args: + device: Device (as str or torch.device) for the new tensor. + copy: Boolean indicator whether or not to clone self. Default False. + + Returns: + VolumeLocator object. + """ + device_ = make_device(device) + if not copy and self.device == device_: + return self + + other = self.clone() + if self.device == device_: + return other + + other.device = device_ + other._grid_sizes = self._grid_sizes.to(device_) + other._local_to_world_transform = self.get_local_to_world_coords_transform().to( + device + ) + return other + + def clone(self) -> "VolumeLocator": + """ + Deep copy of VoluVolumeLocatormes object. All internal tensors are cloned + individually. + + Returns: + new VolumeLocator object. + """ + return copy.deepcopy(self) + + def cpu(self) -> "VolumeLocator": + return self.to("cpu") + + def cuda(self) -> "VolumeLocator": + return self.to("cuda") diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/transforms/__init__.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/transforms/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..96b241562c7675153c2e4ce67e0a10e6e6b071c1 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/transforms/__init__.py @@ -0,0 +1,41 @@ +# 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. + +# pyre-unsafe + +from .math import acos_linear_extrapolation +from .rotation_conversions import ( + axis_angle_to_matrix, + axis_angle_to_quaternion, + euler_angles_to_matrix, + matrix_to_axis_angle, + matrix_to_euler_angles, + matrix_to_quaternion, + matrix_to_rotation_6d, + quaternion_apply, + quaternion_invert, + quaternion_multiply, + quaternion_raw_multiply, + quaternion_to_axis_angle, + quaternion_to_matrix, + random_quaternions, + random_rotation, + random_rotations, + rotation_6d_to_matrix, + standardize_quaternion, +) +from .se3 import se3_exp_map, se3_log_map +from .so3 import ( + so3_exp_map, + so3_exponential_map, + so3_log_map, + so3_relative_angle, + so3_rotation_angle, +) +from .transform3d import Rotate, RotateAxisAngle, Scale, Transform3d, Translate + + +__all__ = [k for k in globals().keys() if not k.startswith("_")] diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/transforms/math.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/transforms/math.py new file mode 100644 index 0000000000000000000000000000000000000000..5008bd589f3fbf744ad203228d38d8a106203226 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/transforms/math.py @@ -0,0 +1,87 @@ +# 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. + +# pyre-unsafe + +import math +from typing import Tuple + +import torch + + +DEFAULT_ACOS_BOUND: float = 1.0 - 1e-4 + + +def acos_linear_extrapolation( + x: torch.Tensor, + bounds: Tuple[float, float] = (-DEFAULT_ACOS_BOUND, DEFAULT_ACOS_BOUND), +) -> torch.Tensor: + """ + Implements `arccos(x)` which is linearly extrapolated outside `x`'s original + domain of `(-1, 1)`. This allows for stable backpropagation in case `x` + is not guaranteed to be strictly within `(-1, 1)`. + + More specifically:: + + bounds=(lower_bound, upper_bound) + if lower_bound <= x <= upper_bound: + acos_linear_extrapolation(x) = acos(x) + elif x <= lower_bound: # 1st order Taylor approximation + acos_linear_extrapolation(x) + = acos(lower_bound) + dacos/dx(lower_bound) * (x - lower_bound) + else: # x >= upper_bound + acos_linear_extrapolation(x) + = acos(upper_bound) + dacos/dx(upper_bound) * (x - upper_bound) + + Args: + x: Input `Tensor`. + bounds: A float 2-tuple defining the region for the + linear extrapolation of `acos`. + The first/second element of `bound` + describes the lower/upper bound that defines the lower/upper + extrapolation region, i.e. the region where + `x <= bound[0]`/`bound[1] <= x`. + Note that all elements of `bound` have to be within (-1, 1). + Returns: + acos_linear_extrapolation: `Tensor` containing the extrapolated `arccos(x)`. + """ + + lower_bound, upper_bound = bounds + + if lower_bound > upper_bound: + raise ValueError("lower bound has to be smaller or equal to upper bound.") + + if lower_bound <= -1.0 or upper_bound >= 1.0: + raise ValueError("Both lower bound and upper bound have to be within (-1, 1).") + + # init an empty tensor and define the domain sets + acos_extrap = torch.empty_like(x) + x_upper = x >= upper_bound + x_lower = x <= lower_bound + x_mid = (~x_upper) & (~x_lower) + + # acos calculation for upper_bound < x < lower_bound + acos_extrap[x_mid] = torch.acos(x[x_mid]) + # the linear extrapolation for x >= upper_bound + acos_extrap[x_upper] = _acos_linear_approximation(x[x_upper], upper_bound) + # the linear extrapolation for x <= lower_bound + acos_extrap[x_lower] = _acos_linear_approximation(x[x_lower], lower_bound) + + return acos_extrap + + +def _acos_linear_approximation(x: torch.Tensor, x0: float) -> torch.Tensor: + """ + Calculates the 1st order Taylor expansion of `arccos(x)` around `x0`. + """ + return (x - x0) * _dacos_dx(x0) + math.acos(x0) + + +def _dacos_dx(x: float) -> float: + """ + Calculates the derivative of `arccos(x)` w.r.t. `x`. + """ + return (-1.0) / math.sqrt(1.0 - x * x) diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/transforms/rotation_conversions.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/transforms/rotation_conversions.py new file mode 100644 index 0000000000000000000000000000000000000000..a9fcae226e951bbd4c299960d07a1e86e414c11a --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/transforms/rotation_conversions.py @@ -0,0 +1,601 @@ +# 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. + +# pyre-unsafe + +from typing import Optional + +import torch +import torch.nn.functional as F + +from ..common.datatypes import Device + + +""" +The transformation matrices returned from the functions in this file assume +the points on which the transformation will be applied are column vectors. +i.e. the R matrix is structured as + + R = [ + [Rxx, Rxy, Rxz], + [Ryx, Ryy, Ryz], + [Rzx, Rzy, Rzz], + ] # (3, 3) + +This matrix can be applied to column vectors by post multiplication +by the points e.g. + + points = [[0], [1], [2]] # (3 x 1) xyz coordinates of a point + transformed_points = R * points + +To apply the same matrix to points which are row vectors, the R matrix +can be transposed and pre multiplied by the points: + +e.g. + points = [[0, 1, 2]] # (1 x 3) xyz coordinates of a point + transformed_points = points * R.transpose(1, 0) +""" + + +def quaternion_to_matrix(quaternions: torch.Tensor) -> torch.Tensor: + """ + Convert rotations given as quaternions to rotation matrices. + + Args: + quaternions: quaternions with real part first, + as tensor of shape (..., 4). + + Returns: + Rotation matrices as tensor of shape (..., 3, 3). + """ + r, i, j, k = torch.unbind(quaternions, -1) + # pyre-fixme[58]: `/` is not supported for operand types `float` and `Tensor`. + two_s = 2.0 / (quaternions * quaternions).sum(-1) + + o = torch.stack( + ( + 1 - two_s * (j * j + k * k), + two_s * (i * j - k * r), + two_s * (i * k + j * r), + two_s * (i * j + k * r), + 1 - two_s * (i * i + k * k), + two_s * (j * k - i * r), + two_s * (i * k - j * r), + two_s * (j * k + i * r), + 1 - two_s * (i * i + j * j), + ), + -1, + ) + return o.reshape(quaternions.shape[:-1] + (3, 3)) + + +def _copysign(a: torch.Tensor, b: torch.Tensor) -> torch.Tensor: + """ + Return a tensor where each element has the absolute value taken from the, + corresponding element of a, with sign taken from the corresponding + element of b. This is like the standard copysign floating-point operation, + but is not careful about negative 0 and NaN. + + Args: + a: source tensor. + b: tensor whose signs will be used, of the same shape as a. + + Returns: + Tensor of the same shape as a with the signs of b. + """ + signs_differ = (a < 0) != (b < 0) + return torch.where(signs_differ, -a, a) + + +def _sqrt_positive_part(x: torch.Tensor) -> torch.Tensor: + """ + Returns torch.sqrt(torch.max(0, x)) + but with a zero subgradient where x is 0. + """ + ret = torch.zeros_like(x) + positive_mask = x > 0 + if torch.is_grad_enabled(): + ret[positive_mask] = torch.sqrt(x[positive_mask]) + else: + ret = torch.where(positive_mask, torch.sqrt(x), ret) + return ret + + +def matrix_to_quaternion(matrix: torch.Tensor) -> torch.Tensor: + """ + Convert rotations given as rotation matrices to quaternions. + + Args: + matrix: Rotation matrices as tensor of shape (..., 3, 3). + + Returns: + quaternions with real part first, as tensor of shape (..., 4). + """ + if matrix.size(-1) != 3 or matrix.size(-2) != 3: + raise ValueError(f"Invalid rotation matrix shape {matrix.shape}.") + + batch_dim = matrix.shape[:-2] + m00, m01, m02, m10, m11, m12, m20, m21, m22 = torch.unbind( + matrix.reshape(batch_dim + (9,)), dim=-1 + ) + + q_abs = _sqrt_positive_part( + torch.stack( + [ + 1.0 + m00 + m11 + m22, + 1.0 + m00 - m11 - m22, + 1.0 - m00 + m11 - m22, + 1.0 - m00 - m11 + m22, + ], + dim=-1, + ) + ) + + # we produce the desired quaternion multiplied by each of r, i, j, k + quat_by_rijk = torch.stack( + [ + # pyre-fixme[58]: `**` is not supported for operand types `Tensor` and + # `int`. + torch.stack([q_abs[..., 0] ** 2, m21 - m12, m02 - m20, m10 - m01], dim=-1), + # pyre-fixme[58]: `**` is not supported for operand types `Tensor` and + # `int`. + torch.stack([m21 - m12, q_abs[..., 1] ** 2, m10 + m01, m02 + m20], dim=-1), + # pyre-fixme[58]: `**` is not supported for operand types `Tensor` and + # `int`. + torch.stack([m02 - m20, m10 + m01, q_abs[..., 2] ** 2, m12 + m21], dim=-1), + # pyre-fixme[58]: `**` is not supported for operand types `Tensor` and + # `int`. + torch.stack([m10 - m01, m20 + m02, m21 + m12, q_abs[..., 3] ** 2], dim=-1), + ], + dim=-2, + ) + + # We floor here at 0.1 but the exact level is not important; if q_abs is small, + # the candidate won't be picked. + flr = torch.tensor(0.1).to(dtype=q_abs.dtype, device=q_abs.device) + quat_candidates = quat_by_rijk / (2.0 * q_abs[..., None].max(flr)) + + # if not for numerical problems, quat_candidates[i] should be same (up to a sign), + # forall i; we pick the best-conditioned one (with the largest denominator) + out = quat_candidates[ + F.one_hot(q_abs.argmax(dim=-1), num_classes=4) > 0.5, : + ].reshape(batch_dim + (4,)) + return standardize_quaternion(out) + + +def _axis_angle_rotation(axis: str, angle: torch.Tensor) -> torch.Tensor: + """ + Return the rotation matrices for one of the rotations about an axis + of which Euler angles describe, for each value of the angle given. + + Args: + axis: Axis label "X" or "Y or "Z". + angle: any shape tensor of Euler angles in radians + + Returns: + Rotation matrices as tensor of shape (..., 3, 3). + """ + + cos = torch.cos(angle) + sin = torch.sin(angle) + one = torch.ones_like(angle) + zero = torch.zeros_like(angle) + + if axis == "X": + R_flat = (one, zero, zero, zero, cos, -sin, zero, sin, cos) + elif axis == "Y": + R_flat = (cos, zero, sin, zero, one, zero, -sin, zero, cos) + elif axis == "Z": + R_flat = (cos, -sin, zero, sin, cos, zero, zero, zero, one) + else: + raise ValueError("letter must be either X, Y or Z.") + + return torch.stack(R_flat, -1).reshape(angle.shape + (3, 3)) + + +def euler_angles_to_matrix(euler_angles: torch.Tensor, convention: str) -> torch.Tensor: + """ + Convert rotations given as Euler angles in radians to rotation matrices. + + Args: + euler_angles: Euler angles in radians as tensor of shape (..., 3). + convention: Convention string of three uppercase letters from + {"X", "Y", and "Z"}. + + Returns: + Rotation matrices as tensor of shape (..., 3, 3). + """ + if euler_angles.dim() == 0 or euler_angles.shape[-1] != 3: + raise ValueError("Invalid input euler angles.") + if len(convention) != 3: + raise ValueError("Convention must have 3 letters.") + if convention[1] in (convention[0], convention[2]): + raise ValueError(f"Invalid convention {convention}.") + for letter in convention: + if letter not in ("X", "Y", "Z"): + raise ValueError(f"Invalid letter {letter} in convention string.") + matrices = [ + _axis_angle_rotation(c, e) + for c, e in zip(convention, torch.unbind(euler_angles, -1)) + ] + # return functools.reduce(torch.matmul, matrices) + return torch.matmul(torch.matmul(matrices[0], matrices[1]), matrices[2]) + + +def _angle_from_tan( + axis: str, other_axis: str, data, horizontal: bool, tait_bryan: bool +) -> torch.Tensor: + """ + Extract the first or third Euler angle from the two members of + the matrix which are positive constant times its sine and cosine. + + Args: + axis: Axis label "X" or "Y or "Z" for the angle we are finding. + other_axis: Axis label "X" or "Y or "Z" for the middle axis in the + convention. + data: Rotation matrices as tensor of shape (..., 3, 3). + horizontal: Whether we are looking for the angle for the third axis, + which means the relevant entries are in the same row of the + rotation matrix. If not, they are in the same column. + tait_bryan: Whether the first and third axes in the convention differ. + + Returns: + Euler Angles in radians for each matrix in data as a tensor + of shape (...). + """ + + i1, i2 = {"X": (2, 1), "Y": (0, 2), "Z": (1, 0)}[axis] + if horizontal: + i2, i1 = i1, i2 + even = (axis + other_axis) in ["XY", "YZ", "ZX"] + if horizontal == even: + return torch.atan2(data[..., i1], data[..., i2]) + if tait_bryan: + return torch.atan2(-data[..., i2], data[..., i1]) + return torch.atan2(data[..., i2], -data[..., i1]) + + +def _index_from_letter(letter: str) -> int: + if letter == "X": + return 0 + if letter == "Y": + return 1 + if letter == "Z": + return 2 + raise ValueError("letter must be either X, Y or Z.") + + +def matrix_to_euler_angles(matrix: torch.Tensor, convention: str) -> torch.Tensor: + """ + Convert rotations given as rotation matrices to Euler angles in radians. + + Args: + matrix: Rotation matrices as tensor of shape (..., 3, 3). + convention: Convention string of three uppercase letters. + + Returns: + Euler angles in radians as tensor of shape (..., 3). + """ + if len(convention) != 3: + raise ValueError("Convention must have 3 letters.") + if convention[1] in (convention[0], convention[2]): + raise ValueError(f"Invalid convention {convention}.") + for letter in convention: + if letter not in ("X", "Y", "Z"): + raise ValueError(f"Invalid letter {letter} in convention string.") + if matrix.size(-1) != 3 or matrix.size(-2) != 3: + raise ValueError(f"Invalid rotation matrix shape {matrix.shape}.") + i0 = _index_from_letter(convention[0]) + i2 = _index_from_letter(convention[2]) + tait_bryan = i0 != i2 + if tait_bryan: + central_angle = torch.asin( + matrix[..., i0, i2] * (-1.0 if i0 - i2 in [-1, 2] else 1.0) + ) + else: + central_angle = torch.acos(matrix[..., i0, i0]) + + o = ( + _angle_from_tan( + convention[0], convention[1], matrix[..., i2], False, tait_bryan + ), + central_angle, + _angle_from_tan( + convention[2], convention[1], matrix[..., i0, :], True, tait_bryan + ), + ) + return torch.stack(o, -1) + + +def random_quaternions( + n: int, dtype: Optional[torch.dtype] = None, device: Optional[Device] = None +) -> torch.Tensor: + """ + Generate random quaternions representing rotations, + i.e. versors with nonnegative real part. + + Args: + n: Number of quaternions in a batch to return. + dtype: Type to return. + device: Desired device of returned tensor. Default: + uses the current device for the default tensor type. + + Returns: + Quaternions as tensor of shape (N, 4). + """ + if isinstance(device, str): + device = torch.device(device) + o = torch.randn((n, 4), dtype=dtype, device=device) + s = (o * o).sum(1) + o = o / _copysign(torch.sqrt(s), o[:, 0])[:, None] + return o + + +def random_rotations( + n: int, dtype: Optional[torch.dtype] = None, device: Optional[Device] = None +) -> torch.Tensor: + """ + Generate random rotations as 3x3 rotation matrices. + + Args: + n: Number of rotation matrices in a batch to return. + dtype: Type to return. + device: Device of returned tensor. Default: if None, + uses the current device for the default tensor type. + + Returns: + Rotation matrices as tensor of shape (n, 3, 3). + """ + quaternions = random_quaternions(n, dtype=dtype, device=device) + return quaternion_to_matrix(quaternions) + + +def random_rotation( + dtype: Optional[torch.dtype] = None, device: Optional[Device] = None +) -> torch.Tensor: + """ + Generate a single random 3x3 rotation matrix. + + Args: + dtype: Type to return + device: Device of returned tensor. Default: if None, + uses the current device for the default tensor type + + Returns: + Rotation matrix as tensor of shape (3, 3). + """ + return random_rotations(1, dtype, device)[0] + + +def standardize_quaternion(quaternions: torch.Tensor) -> torch.Tensor: + """ + Convert a unit quaternion to a standard form: one in which the real + part is non negative. + + Args: + quaternions: Quaternions with real part first, + as tensor of shape (..., 4). + + Returns: + Standardized quaternions as tensor of shape (..., 4). + """ + return torch.where(quaternions[..., 0:1] < 0, -quaternions, quaternions) + + +def quaternion_raw_multiply(a: torch.Tensor, b: torch.Tensor) -> torch.Tensor: + """ + Multiply two quaternions. + Usual torch rules for broadcasting apply. + + Args: + a: Quaternions as tensor of shape (..., 4), real part first. + b: Quaternions as tensor of shape (..., 4), real part first. + + Returns: + The product of a and b, a tensor of quaternions shape (..., 4). + """ + aw, ax, ay, az = torch.unbind(a, -1) + bw, bx, by, bz = torch.unbind(b, -1) + ow = aw * bw - ax * bx - ay * by - az * bz + ox = aw * bx + ax * bw + ay * bz - az * by + oy = aw * by - ax * bz + ay * bw + az * bx + oz = aw * bz + ax * by - ay * bx + az * bw + return torch.stack((ow, ox, oy, oz), -1) + + +def quaternion_multiply(a: torch.Tensor, b: torch.Tensor) -> torch.Tensor: + """ + Multiply two quaternions representing rotations, returning the quaternion + representing their composition, i.e. the versor with nonnegative real part. + Usual torch rules for broadcasting apply. + + Args: + a: Quaternions as tensor of shape (..., 4), real part first. + b: Quaternions as tensor of shape (..., 4), real part first. + + Returns: + The product of a and b, a tensor of quaternions of shape (..., 4). + """ + ab = quaternion_raw_multiply(a, b) + return standardize_quaternion(ab) + + +def quaternion_invert(quaternion: torch.Tensor) -> torch.Tensor: + """ + Given a quaternion representing rotation, get the quaternion representing + its inverse. + + Args: + quaternion: Quaternions as tensor of shape (..., 4), with real part + first, which must be versors (unit quaternions). + + Returns: + The inverse, a tensor of quaternions of shape (..., 4). + """ + + scaling = torch.tensor([1, -1, -1, -1], device=quaternion.device) + return quaternion * scaling + + +def quaternion_apply(quaternion: torch.Tensor, point: torch.Tensor) -> torch.Tensor: + """ + Apply the rotation given by a quaternion to a 3D point. + Usual torch rules for broadcasting apply. + + Args: + quaternion: Tensor of quaternions, real part first, of shape (..., 4). + point: Tensor of 3D points of shape (..., 3). + + Returns: + Tensor of rotated points of shape (..., 3). + """ + if point.size(-1) != 3: + raise ValueError(f"Points are not in 3D, {point.shape}.") + real_parts = point.new_zeros(point.shape[:-1] + (1,)) + point_as_quaternion = torch.cat((real_parts, point), -1) + out = quaternion_raw_multiply( + quaternion_raw_multiply(quaternion, point_as_quaternion), + quaternion_invert(quaternion), + ) + return out[..., 1:] + + +def axis_angle_to_matrix(axis_angle: torch.Tensor) -> torch.Tensor: + """ + Convert rotations given as axis/angle to rotation matrices. + + Args: + axis_angle: Rotations given as a vector in axis angle form, + as a tensor of shape (..., 3), where the magnitude is + the angle turned anticlockwise in radians around the + vector's direction. + + Returns: + Rotation matrices as tensor of shape (..., 3, 3). + """ + return quaternion_to_matrix(axis_angle_to_quaternion(axis_angle)) + + +def matrix_to_axis_angle(matrix: torch.Tensor) -> torch.Tensor: + """ + Convert rotations given as rotation matrices to axis/angle. + + Args: + matrix: Rotation matrices as tensor of shape (..., 3, 3). + + Returns: + Rotations given as a vector in axis angle form, as a tensor + of shape (..., 3), where the magnitude is the angle + turned anticlockwise in radians around the vector's + direction. + """ + return quaternion_to_axis_angle(matrix_to_quaternion(matrix)) + + +def axis_angle_to_quaternion(axis_angle: torch.Tensor) -> torch.Tensor: + """ + Convert rotations given as axis/angle to quaternions. + + Args: + axis_angle: Rotations given as a vector in axis angle form, + as a tensor of shape (..., 3), where the magnitude is + the angle turned anticlockwise in radians around the + vector's direction. + + Returns: + quaternions with real part first, as tensor of shape (..., 4). + """ + angles = torch.norm(axis_angle, p=2, dim=-1, keepdim=True) + half_angles = angles * 0.5 + eps = 1e-6 + small_angles = angles.abs() < eps + sin_half_angles_over_angles = torch.empty_like(angles) + sin_half_angles_over_angles[~small_angles] = ( + torch.sin(half_angles[~small_angles]) / angles[~small_angles] + ) + # for x small, sin(x/2) is about x/2 - (x/2)^3/6 + # so sin(x/2)/x is about 1/2 - (x*x)/48 + sin_half_angles_over_angles[small_angles] = ( + 0.5 - (angles[small_angles] * angles[small_angles]) / 48 + ) + quaternions = torch.cat( + [torch.cos(half_angles), axis_angle * sin_half_angles_over_angles], dim=-1 + ) + return quaternions + + +def quaternion_to_axis_angle(quaternions: torch.Tensor) -> torch.Tensor: + """ + Convert rotations given as quaternions to axis/angle. + + Args: + quaternions: quaternions with real part first, + as tensor of shape (..., 4). + + Returns: + Rotations given as a vector in axis angle form, as a tensor + of shape (..., 3), where the magnitude is the angle + turned anticlockwise in radians around the vector's + direction. + """ + norms = torch.norm(quaternions[..., 1:], p=2, dim=-1, keepdim=True) + half_angles = torch.atan2(norms, quaternions[..., :1]) + angles = 2 * half_angles + eps = 1e-6 + small_angles = angles.abs() < eps + sin_half_angles_over_angles = torch.empty_like(angles) + sin_half_angles_over_angles[~small_angles] = ( + torch.sin(half_angles[~small_angles]) / angles[~small_angles] + ) + # for x small, sin(x/2) is about x/2 - (x/2)^3/6 + # so sin(x/2)/x is about 1/2 - (x*x)/48 + sin_half_angles_over_angles[small_angles] = ( + 0.5 - (angles[small_angles] * angles[small_angles]) / 48 + ) + return quaternions[..., 1:] / sin_half_angles_over_angles + + +def rotation_6d_to_matrix(d6: torch.Tensor) -> torch.Tensor: + """ + Converts 6D rotation representation by Zhou et al. [1] to rotation matrix + using Gram--Schmidt orthogonalization per Section B of [1]. + Args: + d6: 6D rotation representation, of size (*, 6) + + Returns: + batch of rotation matrices of size (*, 3, 3) + + [1] Zhou, Y., Barnes, C., Lu, J., Yang, J., & Li, H. + On the Continuity of Rotation Representations in Neural Networks. + IEEE Conference on Computer Vision and Pattern Recognition, 2019. + Retrieved from http://arxiv.org/abs/1812.07035 + """ + + a1, a2 = d6[..., :3], d6[..., 3:] + b1 = F.normalize(a1, dim=-1) + b2 = a2 - (b1 * a2).sum(-1, keepdim=True) * b1 + b2 = F.normalize(b2, dim=-1) + b3 = torch.cross(b1, b2, dim=-1) + return torch.stack((b1, b2, b3), dim=-2) + + +def matrix_to_rotation_6d(matrix: torch.Tensor) -> torch.Tensor: + """ + Converts rotation matrices to 6D rotation representation by Zhou et al. [1] + by dropping the last row. Note that 6D representation is not unique. + Args: + matrix: batch of rotation matrices of size (*, 3, 3) + + Returns: + 6D rotation representation, of size (*, 6) + + [1] Zhou, Y., Barnes, C., Lu, J., Yang, J., & Li, H. + On the Continuity of Rotation Representations in Neural Networks. + IEEE Conference on Computer Vision and Pattern Recognition, 2019. + Retrieved from http://arxiv.org/abs/1812.07035 + """ + batch_dim = matrix.size()[:-2] + return matrix[..., :2, :].clone().reshape(batch_dim + (6,)) diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/transforms/se3.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/transforms/se3.py new file mode 100644 index 0000000000000000000000000000000000000000..693b84c22ac56208b3b8b37374d7f078dc54241a --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/transforms/se3.py @@ -0,0 +1,223 @@ +# 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. + +# pyre-unsafe + +import torch + +from .so3 import _so3_exp_map, hat, so3_log_map + + +def se3_exp_map(log_transform: torch.Tensor, eps: float = 1e-4) -> torch.Tensor: + """ + Convert a batch of logarithmic representations of SE(3) matrices `log_transform` + to a batch of 4x4 SE(3) matrices using the exponential map. + See e.g. [1], Sec 9.4.2. for more detailed description. + + A SE(3) matrix has the following form: + ``` + [ R 0 ] + [ T 1 ] , + ``` + where `R` is a 3x3 rotation matrix and `T` is a 3-D translation vector. + SE(3) matrices are commonly used to represent rigid motions or camera extrinsics. + + In the SE(3) logarithmic representation SE(3) matrices are + represented as 6-dimensional vectors `[log_translation | log_rotation]`, + i.e. a concatenation of two 3D vectors `log_translation` and `log_rotation`. + + The conversion from the 6D representation to a 4x4 SE(3) matrix `transform` + is done as follows: + ``` + transform = exp( [ hat(log_rotation) 0 ] + [ log_translation 1 ] ) , + ``` + where `exp` is the matrix exponential and `hat` is the Hat operator [2]. + + Note that for any `log_transform` with `0 <= ||log_rotation|| < 2pi` + (i.e. the rotation angle is between 0 and 2pi), the following identity holds: + ``` + se3_log_map(se3_exponential_map(log_transform)) == log_transform + ``` + + The conversion has a singularity around `||log(transform)|| = 0` + which is handled by clamping controlled with the `eps` argument. + + Args: + log_transform: Batch of vectors of shape `(minibatch, 6)`. + eps: A threshold for clipping the squared norm of the rotation logarithm + to avoid unstable gradients in the singular case. + + Returns: + Batch of transformation matrices of shape `(minibatch, 4, 4)`. + + Raises: + ValueError if `log_transform` is of incorrect shape. + + [1] https://jinyongjeong.github.io/Download/SE3/jlblanco2010geometry3d_techrep.pdf + [2] https://en.wikipedia.org/wiki/Hat_operator + """ + + if log_transform.ndim != 2 or log_transform.shape[1] != 6: + raise ValueError("Expected input to be of shape (N, 6).") + + N, _ = log_transform.shape + + log_translation = log_transform[..., :3] + log_rotation = log_transform[..., 3:] + + # rotation is an exponential map of log_rotation + ( + R, + rotation_angles, + log_rotation_hat, + log_rotation_hat_square, + ) = _so3_exp_map(log_rotation, eps=eps) + + # translation is V @ T + V = _se3_V_matrix( + log_rotation, + log_rotation_hat, + log_rotation_hat_square, + rotation_angles, + eps=eps, + ) + T = torch.bmm(V, log_translation[:, :, None])[:, :, 0] + + transform = torch.zeros( + N, 4, 4, dtype=log_transform.dtype, device=log_transform.device + ) + + transform[:, :3, :3] = R + transform[:, :3, 3] = T + transform[:, 3, 3] = 1.0 + + return transform.permute(0, 2, 1) + + +def se3_log_map( + transform: torch.Tensor, eps: float = 1e-4, cos_bound: float = 1e-4 +) -> torch.Tensor: + """ + Convert a batch of 4x4 transformation matrices `transform` + to a batch of 6-dimensional SE(3) logarithms of the SE(3) matrices. + See e.g. [1], Sec 9.4.2. for more detailed description. + + A SE(3) matrix has the following form: + ``` + [ R 0 ] + [ T 1 ] , + ``` + where `R` is an orthonormal 3x3 rotation matrix and `T` is a 3-D translation vector. + SE(3) matrices are commonly used to represent rigid motions or camera extrinsics. + + In the SE(3) logarithmic representation SE(3) matrices are + represented as 6-dimensional vectors `[log_translation | log_rotation]`, + i.e. a concatenation of two 3D vectors `log_translation` and `log_rotation`. + + The conversion from the 4x4 SE(3) matrix `transform` to the + 6D representation `log_transform = [log_translation | log_rotation]` + is done as follows: + ``` + log_transform = log(transform) + log_translation = log_transform[3, :3] + log_rotation = inv_hat(log_transform[:3, :3]) + ``` + where `log` is the matrix logarithm + and `inv_hat` is the inverse of the Hat operator [2]. + + Note that for any valid 4x4 `transform` matrix, the following identity holds: + ``` + se3_exp_map(se3_log_map(transform)) == transform + ``` + + The conversion has a singularity around `(transform=I)` which is handled + by clamping controlled with the `eps` and `cos_bound` arguments. + + Args: + transform: batch of SE(3) matrices of shape `(minibatch, 4, 4)`. + eps: A threshold for clipping the squared norm of the rotation logarithm + to avoid division by zero in the singular case. + cos_bound: Clamps the cosine of the rotation angle to + [-1 + cos_bound, 3 - cos_bound] to avoid non-finite outputs. + The non-finite outputs can be caused by passing small rotation angles + to the `acos` function in `so3_rotation_angle` of `so3_log_map`. + + Returns: + Batch of logarithms of input SE(3) matrices + of shape `(minibatch, 6)`. + + Raises: + ValueError if `transform` is of incorrect shape. + ValueError if `R` has an unexpected trace. + + [1] https://jinyongjeong.github.io/Download/SE3/jlblanco2010geometry3d_techrep.pdf + [2] https://en.wikipedia.org/wiki/Hat_operator + """ + + if transform.ndim != 3: + raise ValueError("Input tensor shape has to be (N, 4, 4).") + + N, dim1, dim2 = transform.shape + if dim1 != 4 or dim2 != 4: + raise ValueError("Input tensor shape has to be (N, 4, 4).") + + if not torch.allclose(transform[:, :3, 3], torch.zeros_like(transform[:, :3, 3])): + raise ValueError("All elements of `transform[:, :3, 3]` should be 0.") + + # log_rot is just so3_log_map of the upper left 3x3 block + R = transform[:, :3, :3].permute(0, 2, 1) + log_rotation = so3_log_map(R, eps=eps, cos_bound=cos_bound) + + # log_translation is V^-1 @ T + T = transform[:, 3, :3] + V = _se3_V_matrix(*_get_se3_V_input(log_rotation), eps=eps) + log_translation = torch.linalg.solve(V, T[:, :, None])[:, :, 0] + + return torch.cat((log_translation, log_rotation), dim=1) + + +def _se3_V_matrix( + log_rotation: torch.Tensor, + log_rotation_hat: torch.Tensor, + log_rotation_hat_square: torch.Tensor, + rotation_angles: torch.Tensor, + eps: float = 1e-4, +) -> torch.Tensor: + """ + A helper function that computes the "V" matrix from [1], Sec 9.4.2. + [1] https://jinyongjeong.github.io/Download/SE3/jlblanco2010geometry3d_techrep.pdf + """ + + V = ( + torch.eye(3, dtype=log_rotation.dtype, device=log_rotation.device)[None] + + log_rotation_hat + # pyre-fixme[58]: `**` is not supported for operand types `Tensor` and `int`. + * ((1 - torch.cos(rotation_angles)) / (rotation_angles**2))[:, None, None] + + ( + log_rotation_hat_square + # pyre-fixme[58]: `**` is not supported for operand types `Tensor` and + # `int`. + * ((rotation_angles - torch.sin(rotation_angles)) / (rotation_angles**3))[ + :, None, None + ] + ) + ) + + return V + + +def _get_se3_V_input(log_rotation: torch.Tensor, eps: float = 1e-4): + """ + A helper function that computes the input variables to the `_se3_V_matrix` + function. + """ + # pyre-fixme[58]: `**` is not supported for operand types `Tensor` and `int`. + nrms = (log_rotation**2).sum(-1) + rotation_angles = torch.clamp(nrms, eps).sqrt() + log_rotation_hat = hat(log_rotation) + log_rotation_hat_square = torch.bmm(log_rotation_hat, log_rotation_hat) + return log_rotation, log_rotation_hat, log_rotation_hat_square, rotation_angles diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/transforms/so3.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/transforms/so3.py new file mode 100644 index 0000000000000000000000000000000000000000..169e1df0b8783e754d46a5a85043811a6ae081f0 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/transforms/so3.py @@ -0,0 +1,270 @@ +# 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. + +# pyre-unsafe + +import warnings +from typing import Tuple + +import torch +from pytorch3d.transforms import rotation_conversions + +from ..transforms import acos_linear_extrapolation + + +def so3_relative_angle( + R1: torch.Tensor, + R2: torch.Tensor, + cos_angle: bool = False, + cos_bound: float = 1e-4, + eps: float = 1e-4, +) -> torch.Tensor: + """ + Calculates the relative angle (in radians) between pairs of + rotation matrices `R1` and `R2` with `angle = acos(0.5 * (Trace(R1 R2^T)-1))` + + .. note:: + This corresponds to a geodesic distance on the 3D manifold of rotation + matrices. + + Args: + R1: Batch of rotation matrices of shape `(minibatch, 3, 3)`. + R2: Batch of rotation matrices of shape `(minibatch, 3, 3)`. + cos_angle: If==True return cosine of the relative angle rather than + the angle itself. This can avoid the unstable calculation of `acos`. + cos_bound: Clamps the cosine of the relative rotation angle to + [-1 + cos_bound, 1 - cos_bound] to avoid non-finite outputs/gradients + of the `acos` call. Note that the non-finite outputs/gradients + are returned when the angle is requested (i.e. `cos_angle==False`) + and the rotation angle is close to 0 or π. + eps: Tolerance for the valid trace check of the relative rotation matrix + in `so3_rotation_angle`. + Returns: + Corresponding rotation angles of shape `(minibatch,)`. + If `cos_angle==True`, returns the cosine of the angles. + + Raises: + ValueError if `R1` or `R2` is of incorrect shape. + ValueError if `R1` or `R2` has an unexpected trace. + """ + R12 = torch.bmm(R1, R2.permute(0, 2, 1)) + return so3_rotation_angle(R12, cos_angle=cos_angle, cos_bound=cos_bound, eps=eps) + + +def so3_rotation_angle( + R: torch.Tensor, + eps: float = 1e-4, + cos_angle: bool = False, + cos_bound: float = 1e-4, +) -> torch.Tensor: + """ + Calculates angles (in radians) of a batch of rotation matrices `R` with + `angle = acos(0.5 * (Trace(R)-1))`. The trace of the + input matrices is checked to be in the valid range `[-1-eps,3+eps]`. + The `eps` argument is a small constant that allows for small errors + caused by limited machine precision. + + Args: + R: Batch of rotation matrices of shape `(minibatch, 3, 3)`. + eps: Tolerance for the valid trace check. + cos_angle: If==True return cosine of the rotation angles rather than + the angle itself. This can avoid the unstable + calculation of `acos`. + cos_bound: Clamps the cosine of the rotation angle to + [-1 + cos_bound, 1 - cos_bound] to avoid non-finite outputs/gradients + of the `acos` call. Note that the non-finite outputs/gradients + are returned when the angle is requested (i.e. `cos_angle==False`) + and the rotation angle is close to 0 or π. + + Returns: + Corresponding rotation angles of shape `(minibatch,)`. + If `cos_angle==True`, returns the cosine of the angles. + + Raises: + ValueError if `R` is of incorrect shape. + ValueError if `R` has an unexpected trace. + """ + + N, dim1, dim2 = R.shape + if dim1 != 3 or dim2 != 3: + raise ValueError("Input has to be a batch of 3x3 Tensors.") + + rot_trace = R[:, 0, 0] + R[:, 1, 1] + R[:, 2, 2] + + if ((rot_trace < -1.0 - eps) + (rot_trace > 3.0 + eps)).any(): + raise ValueError("A matrix has trace outside valid range [-1-eps,3+eps].") + + # phi ... rotation angle + phi_cos = (rot_trace - 1.0) * 0.5 + + if cos_angle: + return phi_cos + else: + if cos_bound > 0.0: + bound = 1.0 - cos_bound + return acos_linear_extrapolation(phi_cos, (-bound, bound)) + else: + return torch.acos(phi_cos) + + +def so3_exp_map(log_rot: torch.Tensor, eps: float = 0.0001) -> torch.Tensor: + """ + Convert a batch of logarithmic representations of rotation matrices `log_rot` + to a batch of 3x3 rotation matrices using Rodrigues formula [1]. + + In the logarithmic representation, each rotation matrix is represented as + a 3-dimensional vector (`log_rot`) who's l2-norm and direction correspond + to the magnitude of the rotation angle and the axis of rotation respectively. + + The conversion has a singularity around `log(R) = 0` + which is handled by clamping controlled with the `eps` argument. + + Args: + log_rot: Batch of vectors of shape `(minibatch, 3)`. + eps: A float constant handling the conversion singularity. + + Returns: + Batch of rotation matrices of shape `(minibatch, 3, 3)`. + + Raises: + ValueError if `log_rot` is of incorrect shape. + + [1] https://en.wikipedia.org/wiki/Rodrigues%27_rotation_formula + """ + return _so3_exp_map(log_rot, eps=eps)[0] + + +def so3_exponential_map(log_rot: torch.Tensor, eps: float = 0.0001) -> torch.Tensor: + warnings.warn( + """so3_exponential_map is deprecated, + Use so3_exp_map instead. + so3_exponential_map will be removed in future releases.""", + PendingDeprecationWarning, + ) + + return so3_exp_map(log_rot, eps) + + +def _so3_exp_map( + log_rot: torch.Tensor, eps: float = 0.0001 +) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]: + """ + A helper function that computes the so3 exponential map and, + apart from the rotation matrix, also returns intermediate variables + that can be re-used in other functions. + """ + _, dim = log_rot.shape + if dim != 3: + raise ValueError("Input tensor shape has to be Nx3.") + + nrms = (log_rot * log_rot).sum(1) + # phis ... rotation angles + rot_angles = torch.clamp(nrms, eps).sqrt() + skews = hat(log_rot) + skews_square = torch.bmm(skews, skews) + + R = rotation_conversions.axis_angle_to_matrix(log_rot) + + return R, rot_angles, skews, skews_square + + +def so3_log_map( + R: torch.Tensor, eps: float = 0.0001, cos_bound: float = 1e-4 +) -> torch.Tensor: + """ + Convert a batch of 3x3 rotation matrices `R` + to a batch of 3-dimensional matrix logarithms of rotation matrices + The conversion has a singularity around `(R=I)`. + + Args: + R: batch of rotation matrices of shape `(minibatch, 3, 3)`. + eps: (unused, for backward compatibility) + cos_bound: (unused, for backward compatibility) + + Returns: + Batch of logarithms of input rotation matrices + of shape `(minibatch, 3)`. + """ + + N, dim1, dim2 = R.shape + if dim1 != 3 or dim2 != 3: + raise ValueError("Input has to be a batch of 3x3 Tensors.") + + return rotation_conversions.matrix_to_axis_angle(R) + + +def hat_inv(h: torch.Tensor) -> torch.Tensor: + """ + Compute the inverse Hat operator [1] of a batch of 3x3 matrices. + + Args: + h: Batch of skew-symmetric matrices of shape `(minibatch, 3, 3)`. + + Returns: + Batch of 3d vectors of shape `(minibatch, 3, 3)`. + + Raises: + ValueError if `h` is of incorrect shape. + ValueError if `h` not skew-symmetric. + + [1] https://en.wikipedia.org/wiki/Hat_operator + """ + + N, dim1, dim2 = h.shape + if dim1 != 3 or dim2 != 3: + raise ValueError("Input has to be a batch of 3x3 Tensors.") + + ss_diff = torch.abs(h + h.permute(0, 2, 1)).max() + + HAT_INV_SKEW_SYMMETRIC_TOL = 1e-5 + if float(ss_diff) > HAT_INV_SKEW_SYMMETRIC_TOL: + raise ValueError("One of input matrices is not skew-symmetric.") + + x = h[:, 2, 1] + y = h[:, 0, 2] + z = h[:, 1, 0] + + v = torch.stack((x, y, z), dim=1) + + return v + + +def hat(v: torch.Tensor) -> torch.Tensor: + """ + Compute the Hat operator [1] of a batch of 3D vectors. + + Args: + v: Batch of vectors of shape `(minibatch , 3)`. + + Returns: + Batch of skew-symmetric matrices of shape + `(minibatch, 3 , 3)` where each matrix is of the form: + `[ 0 -v_z v_y ] + [ v_z 0 -v_x ] + [ -v_y v_x 0 ]` + + Raises: + ValueError if `v` is of incorrect shape. + + [1] https://en.wikipedia.org/wiki/Hat_operator + """ + + N, dim = v.shape + if dim != 3: + raise ValueError("Input vectors have to be 3-dimensional.") + + h = torch.zeros((N, 3, 3), dtype=v.dtype, device=v.device) + + x, y, z = v.unbind(1) + + h[:, 0, 1] = -z + h[:, 0, 2] = y + h[:, 1, 0] = z + h[:, 1, 2] = -x + h[:, 2, 0] = -y + h[:, 2, 1] = x + + return h diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/transforms/transform3d.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/transforms/transform3d.py new file mode 100644 index 0000000000000000000000000000000000000000..fef2984552f197419cff533eb9d4d3f02cff81ca --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/transforms/transform3d.py @@ -0,0 +1,909 @@ +# 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. + +# pyre-unsafe + +import math +import os +import warnings +from typing import List, Optional, Union + +import torch + +from ..common.datatypes import Device, get_device, make_device +from ..common.workaround import _safe_det_3x3 +from .rotation_conversions import _axis_angle_rotation +from .se3 import se3_log_map + + +class Transform3d: + """ + A Transform3d object encapsulates a batch of N 3D transformations, and knows + how to transform points and normal vectors. Suppose that t is a Transform3d; + then we can do the following: + + .. code-block:: python + + N = len(t) + points = torch.randn(N, P, 3) + normals = torch.randn(N, P, 3) + points_transformed = t.transform_points(points) # => (N, P, 3) + normals_transformed = t.transform_normals(normals) # => (N, P, 3) + + + BROADCASTING + Transform3d objects supports broadcasting. Suppose that t1 and tN are + Transform3d objects with len(t1) == 1 and len(tN) == N respectively. Then we + can broadcast transforms like this: + + .. code-block:: python + + t1.transform_points(torch.randn(P, 3)) # => (P, 3) + t1.transform_points(torch.randn(1, P, 3)) # => (1, P, 3) + t1.transform_points(torch.randn(M, P, 3)) # => (M, P, 3) + tN.transform_points(torch.randn(P, 3)) # => (N, P, 3) + tN.transform_points(torch.randn(1, P, 3)) # => (N, P, 3) + + + COMBINING TRANSFORMS + Transform3d objects can be combined in two ways: composing and stacking. + Composing is function composition. Given Transform3d objects t1, t2, t3, + the following all compute the same thing: + + .. code-block:: python + + y1 = t3.transform_points(t2.transform_points(t1.transform_points(x))) + y2 = t1.compose(t2).compose(t3).transform_points(x) + y3 = t1.compose(t2, t3).transform_points(x) + + + Composing transforms should broadcast. + + .. code-block:: python + + if len(t1) == 1 and len(t2) == N, then len(t1.compose(t2)) == N. + + We can also stack a sequence of Transform3d objects, which represents + composition along the batch dimension; then the following should compute the + same thing. + + .. code-block:: python + + N, M = len(tN), len(tM) + xN = torch.randn(N, P, 3) + xM = torch.randn(M, P, 3) + y1 = torch.cat([tN.transform_points(xN), tM.transform_points(xM)], dim=0) + y2 = tN.stack(tM).transform_points(torch.cat([xN, xM], dim=0)) + + BUILDING TRANSFORMS + We provide convenience methods for easily building Transform3d objects + as compositions of basic transforms. + + .. code-block:: python + + # Scale by 0.5, then translate by (1, 2, 3) + t1 = Transform3d().scale(0.5).translate(1, 2, 3) + + # Scale each axis by a different amount, then translate, then scale + t2 = Transform3d().scale(1, 3, 3).translate(2, 3, 1).scale(2.0) + + t3 = t1.compose(t2) + tN = t1.stack(t3, t3) + + + BACKPROP THROUGH TRANSFORMS + When building transforms, we can also parameterize them by Torch tensors; + in this case we can backprop through the construction and application of + Transform objects, so they could be learned via gradient descent or + predicted by a neural network. + + .. code-block:: python + + s1_params = torch.randn(N, requires_grad=True) + t_params = torch.randn(N, 3, requires_grad=True) + s2_params = torch.randn(N, 3, requires_grad=True) + + t = Transform3d().scale(s1_params).translate(t_params).scale(s2_params) + x = torch.randn(N, 3) + y = t.transform_points(x) + loss = compute_loss(y) + loss.backward() + + with torch.no_grad(): + s1_params -= lr * s1_params.grad + t_params -= lr * t_params.grad + s2_params -= lr * s2_params.grad + + CONVENTIONS + We adopt a right-hand coordinate system, meaning that rotation about an axis + with a positive angle results in a counter clockwise rotation. + + This class assumes that transformations are applied on inputs which + are row vectors. The internal representation of the Nx4x4 transformation + matrix is of the form: + + .. code-block:: python + + M = [ + [Rxx, Ryx, Rzx, 0], + [Rxy, Ryy, Rzy, 0], + [Rxz, Ryz, Rzz, 0], + [Tx, Ty, Tz, 1], + ] + + To apply the transformation to points, which are row vectors, the latter are + converted to homogeneous (4D) coordinates and right-multiplied by the M matrix: + + .. code-block:: python + + points = [[0, 1, 2]] # (1 x 3) xyz coordinates of a point + [transformed_points, 1] ∝ [points, 1] @ M + + """ + + def __init__( + self, + dtype: torch.dtype = torch.float32, + device: Device = "cpu", + matrix: Optional[torch.Tensor] = None, + ) -> None: + """ + Args: + dtype: The data type of the transformation matrix. + to be used if `matrix = None`. + device: The device for storing the implemented transformation. + If `matrix != None`, uses the device of input `matrix`. + matrix: A tensor of shape (4, 4) or of shape (minibatch, 4, 4) + representing the 4x4 3D transformation matrix. + If `None`, initializes with identity using + the specified `device` and `dtype`. + """ + + if matrix is None: + self._matrix = torch.eye(4, dtype=dtype, device=device).view(1, 4, 4) + else: + if matrix.ndim not in (2, 3): + raise ValueError('"matrix" has to be a 2- or a 3-dimensional tensor.') + if matrix.shape[-2] != 4 or matrix.shape[-1] != 4: + raise ValueError( + '"matrix" has to be a tensor of shape (minibatch, 4, 4) or (4, 4).' + ) + # set dtype and device from matrix + dtype = matrix.dtype + device = matrix.device + self._matrix = matrix.view(-1, 4, 4) + + self._transforms = [] # store transforms to compose + self._lu = None + self.device = make_device(device) + self.dtype = dtype + + def __len__(self) -> int: + return self.get_matrix().shape[0] + + def __getitem__( + self, index: Union[int, List[int], slice, torch.BoolTensor, torch.LongTensor] + ) -> "Transform3d": + """ + Args: + index: Specifying the index of the transform to retrieve. + Can be an int, slice, list of ints, boolean, long tensor. + Supports negative indices. + + Returns: + Transform3d object with selected transforms. The tensors are not cloned. + """ + if isinstance(index, int): + index = [index] + return self.__class__(matrix=self.get_matrix()[index]) + + def compose(self, *others: "Transform3d") -> "Transform3d": + """ + Return a new Transform3d representing the composition of self with the + given other transforms, which will be stored as an internal list. + + Args: + *others: Any number of Transform3d objects + + Returns: + A new Transform3d with the stored transforms + """ + out = Transform3d(dtype=self.dtype, device=self.device) + out._matrix = self._matrix.clone() + for other in others: + if not isinstance(other, Transform3d): + msg = "Only possible to compose Transform3d objects; got %s" + raise ValueError(msg % type(other)) + out._transforms = self._transforms + list(others) + return out + + def get_matrix(self) -> torch.Tensor: + """ + Returns a 4×4 matrix corresponding to each transform in the batch. + + If the transform was composed from others, the matrix for the composite + transform will be returned. + For example, if self.transforms contains transforms t1, t2, and t3, and + given a set of points x, the following should be true: + + .. code-block:: python + + y1 = t1.compose(t2, t3).transform(x) + y2 = t3.transform(t2.transform(t1.transform(x))) + y1.get_matrix() == y2.get_matrix() + + Where necessary, those transforms are broadcast against each other. + + Returns: + A (N, 4, 4) batch of transformation matrices representing + the stored transforms. See the class documentation for the conventions. + """ + composed_matrix = self._matrix.clone() + if len(self._transforms) > 0: + for other in self._transforms: + other_matrix = other.get_matrix() + composed_matrix = _broadcast_bmm(composed_matrix, other_matrix) + return composed_matrix + + def get_se3_log(self, eps: float = 1e-4, cos_bound: float = 1e-4) -> torch.Tensor: + """ + Returns a 6D SE(3) log vector corresponding to each transform in the batch. + + In the SE(3) logarithmic representation SE(3) matrices are + represented as 6-dimensional vectors `[log_translation | log_rotation]`, + i.e. a concatenation of two 3D vectors `log_translation` and `log_rotation`. + + The conversion from the 4x4 SE(3) matrix `transform` to the + 6D representation `log_transform = [log_translation | log_rotation]` + is done as follows:: + + log_transform = log(transform.get_matrix()) + log_translation = log_transform[3, :3] + log_rotation = inv_hat(log_transform[:3, :3]) + + where `log` is the matrix logarithm + and `inv_hat` is the inverse of the Hat operator [2]. + + See the docstring for `se3.se3_log_map` and [1], Sec 9.4.2. for more + detailed description. + + Args: + eps: A threshold for clipping the squared norm of the rotation logarithm + to avoid division by zero in the singular case. + cos_bound: Clamps the cosine of the rotation angle to + [-1 + cos_bound, 3 - cos_bound] to avoid non-finite outputs. + The non-finite outputs can be caused by passing small rotation angles + to the `acos` function in `so3_rotation_angle` of `so3_log_map`. + + Returns: + A (N, 6) tensor, rows of which represent the individual transforms + stored in the object as SE(3) logarithms. + + Raises: + ValueError if the stored transform is not Euclidean (e.g. R is not a rotation + matrix or the last column has non-zeros in the first three places). + + [1] https://jinyongjeong.github.io/Download/SE3/jlblanco2010geometry3d_techrep.pdf + [2] https://en.wikipedia.org/wiki/Hat_operator + """ + return se3_log_map(self.get_matrix(), eps, cos_bound) + + def _get_matrix_inverse(self) -> torch.Tensor: + """ + Return the inverse of self._matrix. + """ + return torch.inverse(self._matrix) + + def inverse(self, invert_composed: bool = False) -> "Transform3d": + """ + Returns a new Transform3d object that represents an inverse of the + current transformation. + + Args: + invert_composed: + - True: First compose the list of stored transformations + and then apply inverse to the result. This is + potentially slower for classes of transformations + with inverses that can be computed efficiently + (e.g. rotations and translations). + - False: Invert the individual stored transformations + independently without composing them. + + Returns: + A new Transform3d object containing the inverse of the original + transformation. + """ + + tinv = Transform3d(dtype=self.dtype, device=self.device) + + if invert_composed: + # first compose then invert + tinv._matrix = torch.inverse(self.get_matrix()) + else: + # self._get_matrix_inverse() implements efficient inverse + # of self._matrix + i_matrix = self._get_matrix_inverse() + + # 2 cases: + if len(self._transforms) > 0: + # a) Either we have a non-empty list of transforms: + # Here we take self._matrix and append its inverse at the + # end of the reverted _transforms list. After composing + # the transformations with get_matrix(), this correctly + # right-multiplies by the inverse of self._matrix + # at the end of the composition. + tinv._transforms = [t.inverse() for t in reversed(self._transforms)] + last = Transform3d(dtype=self.dtype, device=self.device) + last._matrix = i_matrix + tinv._transforms.append(last) + else: + # b) Or there are no stored transformations + # we just set inverted matrix + tinv._matrix = i_matrix + + return tinv + + def stack(self, *others: "Transform3d") -> "Transform3d": + """ + Return a new batched Transform3d representing the batch elements from + self and all the given other transforms all batched together. + + Args: + *others: Any number of Transform3d objects + + Returns: + A new Transform3d. + """ + transforms = [self] + list(others) + matrix = torch.cat([t.get_matrix() for t in transforms], dim=0) + out = Transform3d(dtype=self.dtype, device=self.device) + out._matrix = matrix + return out + + def transform_points(self, points, eps: Optional[float] = None) -> torch.Tensor: + """ + Use this transform to transform a set of 3D points. Assumes row major + ordering of the input points. + + Args: + points: Tensor of shape (P, 3) or (N, P, 3) + eps: If eps!=None, the argument is used to clamp the + last coordinate before performing the final division. + The clamping corresponds to: + last_coord := (last_coord.sign() + (last_coord==0)) * + torch.clamp(last_coord.abs(), eps), + i.e. the last coordinates that are exactly 0 will + be clamped to +eps. + + Returns: + points_out: points of shape (N, P, 3) or (P, 3) depending + on the dimensions of the transform + """ + points_batch = points.clone() + if points_batch.dim() == 2: + points_batch = points_batch[None] # (P, 3) -> (1, P, 3) + if points_batch.dim() != 3: + msg = "Expected points to have dim = 2 or dim = 3: got shape %r" + raise ValueError(msg % repr(points.shape)) + + N, P, _3 = points_batch.shape + ones = torch.ones(N, P, 1, dtype=points.dtype, device=points.device) + points_batch = torch.cat([points_batch, ones], dim=2) + + composed_matrix = self.get_matrix() + points_out = _broadcast_bmm(points_batch, composed_matrix) + denom = points_out[..., 3:] # denominator + if eps is not None: + denom_sign = denom.sign() + (denom == 0.0).type_as(denom) + denom = denom_sign * torch.clamp(denom.abs(), eps) + points_out = points_out[..., :3] / denom + + # When transform is (1, 4, 4) and points is (P, 3) return + # points_out of shape (P, 3) + if points_out.shape[0] == 1 and points.dim() == 2: + points_out = points_out.reshape(points.shape) + + return points_out + + def transform_normals(self, normals) -> torch.Tensor: + """ + Use this transform to transform a set of normal vectors. + + Args: + normals: Tensor of shape (P, 3) or (N, P, 3) + + Returns: + normals_out: Tensor of shape (P, 3) or (N, P, 3) depending + on the dimensions of the transform + """ + if normals.dim() not in [2, 3]: + msg = "Expected normals to have dim = 2 or dim = 3: got shape %r" + raise ValueError(msg % (normals.shape,)) + composed_matrix = self.get_matrix() + + # TODO: inverse is bad! Solve a linear system instead + mat = composed_matrix[:, :3, :3] + normals_out = _broadcast_bmm(normals, mat.transpose(1, 2).inverse()) + + # This doesn't pass unit tests. TODO investigate further + # if self._lu is None: + # self._lu = self._matrix[:, :3, :3].transpose(1, 2).lu() + # normals_out = normals.lu_solve(*self._lu) + + # When transform is (1, 4, 4) and normals is (P, 3) return + # normals_out of shape (P, 3) + if normals_out.shape[0] == 1 and normals.dim() == 2: + normals_out = normals_out.reshape(normals.shape) + + return normals_out + + def translate(self, *args, **kwargs) -> "Transform3d": + return self.compose( + Translate(*args, device=self.device, dtype=self.dtype, **kwargs) + ) + + def scale(self, *args, **kwargs) -> "Transform3d": + return self.compose( + Scale(*args, device=self.device, dtype=self.dtype, **kwargs) + ) + + def rotate(self, *args, **kwargs) -> "Transform3d": + return self.compose( + Rotate(*args, device=self.device, dtype=self.dtype, **kwargs) + ) + + def rotate_axis_angle(self, *args, **kwargs) -> "Transform3d": + return self.compose( + RotateAxisAngle(*args, device=self.device, dtype=self.dtype, **kwargs) + ) + + def clone(self) -> "Transform3d": + """ + Deep copy of Transforms object. All internal tensors are cloned + individually. + + Returns: + new Transforms object. + """ + other = Transform3d(dtype=self.dtype, device=self.device) + if self._lu is not None: + other._lu = [elem.clone() for elem in self._lu] + other._matrix = self._matrix.clone() + other._transforms = [t.clone() for t in self._transforms] + return other + + def to( + self, + device: Device, + copy: bool = False, + dtype: Optional[torch.dtype] = None, + ) -> "Transform3d": + """ + Match functionality of torch.Tensor.to() + If copy = True or the self Tensor is on a different device, the + returned tensor is a copy of self with the desired torch.device. + If copy = False and the self Tensor already has the correct torch.device, + then self is returned. + + Args: + device: Device (as str or torch.device) for the new tensor. + copy: Boolean indicator whether or not to clone self. Default False. + dtype: If not None, casts the internal tensor variables + to a given torch.dtype. + + Returns: + Transform3d object. + """ + device_ = make_device(device) + dtype_ = self.dtype if dtype is None else dtype + skip_to = self.device == device_ and self.dtype == dtype_ + + if not copy and skip_to: + return self + + other = self.clone() + + if skip_to: + return other + + other.device = device_ + other.dtype = dtype_ + other._matrix = other._matrix.to(device=device_, dtype=dtype_) + other._transforms = [ + t.to(device_, copy=copy, dtype=dtype_) for t in other._transforms + ] + return other + + def cpu(self) -> "Transform3d": + return self.to("cpu") + + def cuda(self) -> "Transform3d": + return self.to("cuda") + + +class Translate(Transform3d): + def __init__( + self, + x, + y=None, + z=None, + dtype: torch.dtype = torch.float32, + device: Optional[Device] = None, + ) -> None: + """ + Create a new Transform3d representing 3D translations. + + Option I: Translate(xyz, dtype=torch.float32, device='cpu') + xyz should be a tensor of shape (N, 3) + + Option II: Translate(x, y, z, dtype=torch.float32, device='cpu') + Here x, y, and z will be broadcast against each other and + concatenated to form the translation. Each can be: + - A python scalar + - A torch scalar + - A 1D torch tensor + """ + xyz = _handle_input(x, y, z, dtype, device, "Translate") + super().__init__(device=xyz.device, dtype=dtype) + N = xyz.shape[0] + + mat = torch.eye(4, dtype=dtype, device=self.device) + mat = mat.view(1, 4, 4).repeat(N, 1, 1) + mat[:, 3, :3] = xyz + self._matrix = mat + + def _get_matrix_inverse(self) -> torch.Tensor: + """ + Return the inverse of self._matrix. + """ + inv_mask = self._matrix.new_ones([1, 4, 4]) + inv_mask[0, 3, :3] = -1.0 + i_matrix = self._matrix * inv_mask + return i_matrix + + def __getitem__( + self, index: Union[int, List[int], slice, torch.BoolTensor, torch.LongTensor] + ) -> "Transform3d": + """ + Args: + index: Specifying the index of the transform to retrieve. + Can be an int, slice, list of ints, boolean, long tensor. + Supports negative indices. + + Returns: + Transform3d object with selected transforms. The tensors are not cloned. + """ + if isinstance(index, int): + index = [index] + return self.__class__(self.get_matrix()[index, 3, :3]) + + +class Scale(Transform3d): + def __init__( + self, + x, + y=None, + z=None, + dtype: torch.dtype = torch.float32, + device: Optional[Device] = None, + ) -> None: + """ + A Transform3d representing a scaling operation, with different scale + factors along each coordinate axis. + + Option I: Scale(s, dtype=torch.float32, device='cpu') + s can be one of + - Python scalar or torch scalar: Single uniform scale + - 1D torch tensor of shape (N,): A batch of uniform scale + - 2D torch tensor of shape (N, 3): Scale differently along each axis + + Option II: Scale(x, y, z, dtype=torch.float32, device='cpu') + Each of x, y, and z can be one of + - python scalar + - torch scalar + - 1D torch tensor + """ + xyz = _handle_input(x, y, z, dtype, device, "scale", allow_singleton=True) + super().__init__(device=xyz.device, dtype=dtype) + N = xyz.shape[0] + + # TODO: Can we do this all in one go somehow? + mat = torch.eye(4, dtype=dtype, device=self.device) + mat = mat.view(1, 4, 4).repeat(N, 1, 1) + mat[:, 0, 0] = xyz[:, 0] + mat[:, 1, 1] = xyz[:, 1] + mat[:, 2, 2] = xyz[:, 2] + self._matrix = mat + + def _get_matrix_inverse(self) -> torch.Tensor: + """ + Return the inverse of self._matrix. + """ + xyz = torch.stack([self._matrix[:, i, i] for i in range(4)], dim=1) + # pyre-fixme[58]: `/` is not supported for operand types `float` and `Tensor`. + ixyz = 1.0 / xyz + # pyre-fixme[6]: For 1st param expected `Tensor` but got `float`. + imat = torch.diag_embed(ixyz, dim1=1, dim2=2) + return imat + + def __getitem__( + self, index: Union[int, List[int], slice, torch.BoolTensor, torch.LongTensor] + ) -> "Transform3d": + """ + Args: + index: Specifying the index of the transform to retrieve. + Can be an int, slice, list of ints, boolean, long tensor. + Supports negative indices. + + Returns: + Transform3d object with selected transforms. The tensors are not cloned. + """ + if isinstance(index, int): + index = [index] + mat = self.get_matrix()[index] + x = mat[:, 0, 0] + y = mat[:, 1, 1] + z = mat[:, 2, 2] + return self.__class__(x, y, z) + + +class Rotate(Transform3d): + def __init__( + self, + R: torch.Tensor, + dtype: torch.dtype = torch.float32, + device: Optional[Device] = None, + orthogonal_tol: float = 1e-5, + ) -> None: + """ + Create a new Transform3d representing 3D rotation using a rotation + matrix as the input. + + Args: + R: a tensor of shape (3, 3) or (N, 3, 3) + orthogonal_tol: tolerance for the test of the orthogonality of R + + """ + device_ = get_device(R, device) + super().__init__(device=device_, dtype=dtype) + if R.dim() == 2: + R = R[None] + if R.shape[-2:] != (3, 3): + msg = "R must have shape (3, 3) or (N, 3, 3); got %s" + raise ValueError(msg % repr(R.shape)) + R = R.to(device=device_, dtype=dtype) + if os.environ.get("PYTORCH3D_CHECK_ROTATION_MATRICES", "0") == "1": + # Note: aten::all_close in the check is computationally slow, so we + # only run the check when PYTORCH3D_CHECK_ROTATION_MATRICES is on. + _check_valid_rotation_matrix(R, tol=orthogonal_tol) + N = R.shape[0] + mat = torch.eye(4, dtype=dtype, device=device_) + mat = mat.view(1, 4, 4).repeat(N, 1, 1) + mat[:, :3, :3] = R + self._matrix = mat + + def _get_matrix_inverse(self) -> torch.Tensor: + """ + Return the inverse of self._matrix. + """ + return self._matrix.permute(0, 2, 1).contiguous() + + def __getitem__( + self, index: Union[int, List[int], slice, torch.BoolTensor, torch.LongTensor] + ) -> "Transform3d": + """ + Args: + index: Specifying the index of the transform to retrieve. + Can be an int, slice, list of ints, boolean, long tensor. + Supports negative indices. + + Returns: + Transform3d object with selected transforms. The tensors are not cloned. + """ + if isinstance(index, int): + index = [index] + return self.__class__(self.get_matrix()[index, :3, :3]) + + +class RotateAxisAngle(Rotate): + def __init__( + self, + angle, + axis: str = "X", + degrees: bool = True, + dtype: torch.dtype = torch.float32, + device: Optional[Device] = None, + ) -> None: + """ + Create a new Transform3d representing 3D rotation about an axis + by an angle. + + Assuming a right-hand coordinate system, positive rotation angles result + in a counter clockwise rotation. + + Args: + angle: + - A torch tensor of shape (N,) + - A python scalar + - A torch scalar + axis: + string: one of ["X", "Y", "Z"] indicating the axis about which + to rotate. + NOTE: All batch elements are rotated about the same axis. + """ + axis = axis.upper() + if axis not in ["X", "Y", "Z"]: + msg = "Expected axis to be one of ['X', 'Y', 'Z']; got %s" + raise ValueError(msg % axis) + angle = _handle_angle_input(angle, dtype, device, "RotateAxisAngle") + angle = (angle / 180.0 * math.pi) if degrees else angle + # We assume the points on which this transformation will be applied + # are row vectors. The rotation matrix returned from _axis_angle_rotation + # is for transforming column vectors. Therefore we transpose this matrix. + # R will always be of shape (N, 3, 3) + R = _axis_angle_rotation(axis, angle).transpose(1, 2) + super().__init__(device=angle.device, R=R, dtype=dtype) + + +def _handle_coord(c, dtype: torch.dtype, device: torch.device) -> torch.Tensor: + """ + Helper function for _handle_input. + + Args: + c: Python scalar, torch scalar, or 1D torch tensor + + Returns: + c_vec: 1D torch tensor + """ + if not torch.is_tensor(c): + c = torch.tensor(c, dtype=dtype, device=device) + if c.dim() == 0: + c = c.view(1) + if c.device != device or c.dtype != dtype: + c = c.to(device=device, dtype=dtype) + return c + + +def _handle_input( + x, + y, + z, + dtype: torch.dtype, + device: Optional[Device], + name: str, + allow_singleton: bool = False, +) -> torch.Tensor: + """ + Helper function to handle parsing logic for building transforms. The output + is always a tensor of shape (N, 3), but there are several types of allowed + input. + + Case I: Single Matrix + In this case x is a tensor of shape (N, 3), and y and z are None. Here just + return x. + + Case II: Vectors and Scalars + In this case each of x, y, and z can be one of the following + - Python scalar + - Torch scalar + - Torch tensor of shape (N, 1) or (1, 1) + In this case x, y and z are broadcast to tensors of shape (N, 1) + and concatenated to a tensor of shape (N, 3) + + Case III: Singleton (only if allow_singleton=True) + In this case y and z are None, and x can be one of the following: + - Python scalar + - Torch scalar + - Torch tensor of shape (N, 1) or (1, 1) + Here x will be duplicated 3 times, and we return a tensor of shape (N, 3) + + Returns: + xyz: Tensor of shape (N, 3) + """ + device_ = get_device(x, device) + # If x is actually a tensor of shape (N, 3) then just return it + if torch.is_tensor(x) and x.dim() == 2: + if x.shape[1] != 3: + msg = "Expected tensor of shape (N, 3); got %r (in %s)" + raise ValueError(msg % (x.shape, name)) + if y is not None or z is not None: + msg = "Expected y and z to be None (in %s)" % name + raise ValueError(msg) + return x.to(device=device_, dtype=dtype) + + if allow_singleton and y is None and z is None: + y = x + z = x + + # Convert all to 1D tensors + xyz = [_handle_coord(c, dtype, device_) for c in [x, y, z]] + + # Broadcast and concatenate + sizes = [c.shape[0] for c in xyz] + N = max(sizes) + for c in xyz: + if c.shape[0] != 1 and c.shape[0] != N: + msg = "Got non-broadcastable sizes %r (in %s)" % (sizes, name) + raise ValueError(msg) + xyz = [c.expand(N) for c in xyz] + xyz = torch.stack(xyz, dim=1) + return xyz + + +def _handle_angle_input( + x, dtype: torch.dtype, device: Optional[Device], name: str +) -> torch.Tensor: + """ + Helper function for building a rotation function using angles. + The output is always of shape (N,). + + The input can be one of: + - Torch tensor of shape (N,) + - Python scalar + - Torch scalar + """ + device_ = get_device(x, device) + if torch.is_tensor(x) and x.dim() > 1: + msg = "Expected tensor of shape (N,); got %r (in %s)" + raise ValueError(msg % (x.shape, name)) + else: + return _handle_coord(x, dtype, device_) + + +def _broadcast_bmm(a, b) -> torch.Tensor: + """ + Batch multiply two matrices and broadcast if necessary. + + Args: + a: torch tensor of shape (P, K) or (M, P, K) + b: torch tensor of shape (N, K, K) + + Returns: + a and b broadcast multiplied. The output batch dimension is max(N, M). + + To broadcast transforms across a batch dimension if M != N then + expect that either M = 1 or N = 1. The tensor with batch dimension 1 is + expanded to have shape N or M. + """ + if a.dim() == 2: + a = a[None] + if len(a) != len(b): + if not ((len(a) == 1) or (len(b) == 1)): + msg = "Expected batch dim for bmm to be equal or 1; got %r, %r" + raise ValueError(msg % (a.shape, b.shape)) + if len(a) == 1: + a = a.expand(len(b), -1, -1) + if len(b) == 1: + b = b.expand(len(a), -1, -1) + return a.bmm(b) + + +@torch.no_grad() +def _check_valid_rotation_matrix(R, tol: float = 1e-7) -> None: + """ + Determine if R is a valid rotation matrix by checking it satisfies the + following conditions: + + ``RR^T = I and det(R) = 1`` + + Args: + R: an (N, 3, 3) matrix + + Returns: + None + + Emits a warning if R is an invalid rotation matrix. + """ + N = R.shape[0] + eye = torch.eye(3, dtype=R.dtype, device=R.device) + eye = eye.view(1, 3, 3).expand(N, -1, -1) + orthogonal = torch.allclose(R.bmm(R.transpose(1, 2)), eye, atol=tol) + det_R = _safe_det_3x3(R) + no_distortion = torch.allclose(det_R, torch.ones_like(det_R)) + if not (orthogonal and no_distortion): + msg = "R is not a valid rotation matrix" + warnings.warn(msg) + return diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/utils/__init__.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/utils/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..504dace63d92a8e4a964fc68e5e7f3e42c027b13 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/utils/__init__.py @@ -0,0 +1,23 @@ +# 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. + +# pyre-unsafe + +from .camera_conversions import ( + cameras_from_opencv_projection, + opencv_from_cameras_projection, + pulsar_from_cameras_projection, + pulsar_from_opencv_projection, +) + +from .checkerboard import checkerboard + +from .ico_sphere import ico_sphere + +from .torus import torus + + +__all__ = [k for k in globals().keys() if not k.startswith("_")] diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/utils/camera_conversions.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/utils/camera_conversions.py new file mode 100644 index 0000000000000000000000000000000000000000..b9fa43be089c64f8924cd8335b5a1c2d4b793b4b --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/utils/camera_conversions.py @@ -0,0 +1,159 @@ +# 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. + +# pyre-unsafe + +from typing import Tuple + +import torch + +from ..renderer import PerspectiveCameras +from ..renderer.camera_conversions import ( + _cameras_from_opencv_projection, + _opencv_from_cameras_projection, + _pulsar_from_cameras_projection, + _pulsar_from_opencv_projection, +) + + +def cameras_from_opencv_projection( + R: torch.Tensor, + tvec: torch.Tensor, + camera_matrix: torch.Tensor, + image_size: torch.Tensor, +) -> PerspectiveCameras: + """ + Converts a batch of OpenCV-conventioned cameras parametrized with the + rotation matrices `R`, translation vectors `tvec`, and the camera + calibration matrices `camera_matrix` to `PerspectiveCameras` in PyTorch3D + convention. + + More specifically, the conversion is carried out such that a projection + of a 3D shape to the OpenCV-conventioned screen of size `image_size` results + in the same image as a projection with the corresponding PyTorch3D camera + to the NDC screen convention of PyTorch3D. + + More specifically, the OpenCV convention projects points to the OpenCV screen + space as follows:: + + x_screen_opencv = camera_matrix @ (R @ x_world + tvec) + + followed by the homogenization of `x_screen_opencv`. + + Note: + The parameters `R, tvec, camera_matrix` correspond to the inputs of + `cv2.projectPoints(x_world, rvec, tvec, camera_matrix, [])`, + where `rvec` is an axis-angle vector that can be obtained from + the rotation matrix `R` expected here by calling the `so3_log_map` function. + Correspondingly, `R` can be obtained from `rvec` by calling `so3_exp_map`. + + Args: + R: A batch of rotation matrices of shape `(N, 3, 3)`. + tvec: A batch of translation vectors of shape `(N, 3)`. + camera_matrix: A batch of camera calibration matrices of shape `(N, 3, 3)`. + image_size: A tensor of shape `(N, 2)` containing the sizes of the images + (height, width) attached to each camera. + + Returns: + cameras_pytorch3d: A batch of `N` cameras in the PyTorch3D convention. + """ + return _cameras_from_opencv_projection(R, tvec, camera_matrix, image_size) + + +def opencv_from_cameras_projection( + cameras: PerspectiveCameras, + image_size: torch.Tensor, +) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]: + """ + Converts a batch of `PerspectiveCameras` into OpenCV-convention + rotation matrices `R`, translation vectors `tvec`, and the camera + calibration matrices `camera_matrix`. This operation is exactly the inverse + of `cameras_from_opencv_projection`. + + Note: + The outputs `R, tvec, camera_matrix` correspond to the inputs of + `cv2.projectPoints(x_world, rvec, tvec, camera_matrix, [])`, + where `rvec` is an axis-angle vector that can be obtained from + the rotation matrix `R` output here by calling the `so3_log_map` function. + Correspondingly, `R` can be obtained from `rvec` by calling `so3_exp_map`. + + Args: + cameras: A batch of `N` cameras in the PyTorch3D convention. + image_size: A tensor of shape `(N, 2)` containing the sizes of the images + (height, width) attached to each camera. + return_as_rotmat (bool): If set to True, return the full 3x3 rotation + matrices. Otherwise, return an axis-angle vector (default). + + Returns: + R: A batch of rotation matrices of shape `(N, 3, 3)`. + tvec: A batch of translation vectors of shape `(N, 3)`. + camera_matrix: A batch of camera calibration matrices of shape `(N, 3, 3)`. + """ + return _opencv_from_cameras_projection(cameras, image_size) + + +def pulsar_from_opencv_projection( + R: torch.Tensor, + tvec: torch.Tensor, + camera_matrix: torch.Tensor, + image_size: torch.Tensor, + znear: float = 0.1, +) -> torch.Tensor: + """ + Convert OpenCV style camera parameters to Pulsar style camera parameters. + + Note: + * Pulsar does NOT support different focal lengths for x and y. + For conversion, we use the average of fx and fy. + * The Pulsar renderer MUST use a left-handed coordinate system for this + mapping to work. + * The resulting image will be vertically flipped - which has to be + addressed AFTER rendering by the user. + * The parameters `R, tvec, camera_matrix` correspond to the outputs + of `cv2.decomposeProjectionMatrix`. + + Args: + R: A batch of rotation matrices of shape `(N, 3, 3)`. + tvec: A batch of translation vectors of shape `(N, 3)`. + camera_matrix: A batch of camera calibration matrices of shape `(N, 3, 3)`. + image_size: A tensor of shape `(N, 2)` containing the sizes of the images + (height, width) attached to each camera. + znear (float): The near clipping value to use for Pulsar. + + Returns: + cameras_pulsar: A batch of `N` Pulsar camera vectors in the Pulsar + convention `(N, 13)` (3 translation, 6 rotation, focal_length, sensor_width, + c_x, c_y). + """ + return _pulsar_from_opencv_projection(R, tvec, camera_matrix, image_size, znear) + + +def pulsar_from_cameras_projection( + cameras: PerspectiveCameras, + image_size: torch.Tensor, +) -> torch.Tensor: + """ + Convert PyTorch3D `PerspectiveCameras` to Pulsar style camera parameters. + + Note: + * Pulsar does NOT support different focal lengths for x and y. + For conversion, we use the average of fx and fy. + * The Pulsar renderer MUST use a left-handed coordinate system for this + mapping to work. + * The resulting image will be vertically flipped - which has to be + addressed AFTER rendering by the user. + + Args: + cameras: A batch of `N` cameras in the PyTorch3D convention. + image_size: A tensor of shape `(N, 2)` containing the sizes of the images + (height, width) attached to each camera. + + Returns: + cameras_pulsar: A batch of `N` Pulsar camera vectors in the Pulsar + convention `(N, 13)` (3 translation, 6 rotation, focal_length, sensor_width, + c_x, c_y). + """ + return _pulsar_from_cameras_projection(cameras, image_size) diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/utils/checkerboard.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/utils/checkerboard.py new file mode 100644 index 0000000000000000000000000000000000000000..a0d53fd9b3c56bc0f9bccb0424c23b76e16410e0 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/utils/checkerboard.py @@ -0,0 +1,91 @@ +# 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. + +# pyre-unsafe + + +from typing import Optional, Tuple + +import torch +from pytorch3d.common.compat import meshgrid_ij +from pytorch3d.renderer.mesh.textures import TexturesAtlas +from pytorch3d.structures.meshes import Meshes + + +def checkerboard( + radius: int = 4, + color1: Tuple[float, ...] = (0.0, 0.0, 0.0), + color2: Tuple[float, ...] = (1.0, 1.0, 1.0), + device: Optional[torch.types._device] = None, +) -> Meshes: + """ + Returns a mesh of squares in the xy-plane where each unit is one of the two given + colors and adjacent squares have opposite colors. + Args: + radius: how many squares in each direction from the origin + color1: background color + color2: foreground color (must have the same number of channels as color1) + Returns: + new Meshes object containing one mesh. + """ + + if device is None: + device = torch.device("cpu") + if radius < 1: + raise ValueError("radius must be > 0") + + num_verts_per_row = 2 * radius + 1 + + # construct 2D grid of 3D vertices + x = torch.arange(-radius, radius + 1, device=device) + grid_y, grid_x = meshgrid_ij(x, x) + verts = torch.stack( + [grid_x, grid_y, torch.zeros((2 * radius + 1, 2 * radius + 1))], dim=-1 + ) + verts = verts.view(1, -1, 3) + + top_triangle_idx = torch.arange(0, num_verts_per_row * (num_verts_per_row - 1)) + top_triangle_idx = torch.stack( + [ + top_triangle_idx, + top_triangle_idx + 1, + top_triangle_idx + num_verts_per_row + 1, + ], + dim=-1, + ) + + bottom_triangle_idx = top_triangle_idx[:, [0, 2, 1]] + torch.tensor( + [0, 0, num_verts_per_row - 1] + ) + + faces = torch.zeros( + (1, len(top_triangle_idx) + len(bottom_triangle_idx), 3), + dtype=torch.long, + device=device, + ) + faces[0, ::2] = top_triangle_idx + faces[0, 1::2] = bottom_triangle_idx + + # construct range of indices that excludes the boundary to avoid wrong triangles + indexing_range = torch.arange(0, 2 * num_verts_per_row * num_verts_per_row).view( + num_verts_per_row, num_verts_per_row, 2 + ) + indexing_range = indexing_range[:-1, :-1] # removes boundaries from list of indices + indexing_range = indexing_range.reshape( + 2 * (num_verts_per_row - 1) * (num_verts_per_row - 1) + ) + + faces = faces[:, indexing_range] + + # adding color + colors = torch.tensor(color1).repeat(2 * num_verts_per_row * num_verts_per_row, 1) + colors[2::4] = torch.tensor(color2) + colors[3::4] = torch.tensor(color2) + colors = colors[None, indexing_range, None, None] + + texture_atlas = TexturesAtlas(colors) + + return Meshes(verts=verts, faces=faces, textures=texture_atlas) diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/utils/ico_sphere.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/utils/ico_sphere.py new file mode 100644 index 0000000000000000000000000000000000000000..bc7ca24fd4aac046ebc5aa949b7268ce418a1b28 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/utils/ico_sphere.py @@ -0,0 +1,86 @@ +# 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. + +# pyre-unsafe + + +import torch +from pytorch3d.ops.subdivide_meshes import SubdivideMeshes +from pytorch3d.structures.meshes import Meshes + + +# Vertex coordinates for a level 0 ico-sphere. +_ico_verts0 = [ + [-0.5257, 0.8507, 0.0000], + [0.5257, 0.8507, 0.0000], + [-0.5257, -0.8507, 0.0000], + [0.5257, -0.8507, 0.0000], + [0.0000, -0.5257, 0.8507], + [0.0000, 0.5257, 0.8507], + [0.0000, -0.5257, -0.8507], + [0.0000, 0.5257, -0.8507], + [0.8507, 0.0000, -0.5257], + [0.8507, 0.0000, 0.5257], + [-0.8507, 0.0000, -0.5257], + [-0.8507, 0.0000, 0.5257], +] + + +# Faces for level 0 ico-sphere +_ico_faces0 = [ + [0, 11, 5], + [0, 5, 1], + [0, 1, 7], + [0, 7, 10], + [0, 10, 11], + [1, 5, 9], + [5, 11, 4], + [11, 10, 2], + [10, 7, 6], + [7, 1, 8], + [3, 9, 4], + [3, 4, 2], + [3, 2, 6], + [3, 6, 8], + [3, 8, 9], + [4, 9, 5], + [2, 4, 11], + [6, 2, 10], + [8, 6, 7], + [9, 8, 1], +] + + +def ico_sphere(level: int = 0, device=None): + """ + Create verts and faces for a unit ico-sphere, with all faces oriented + consistently. + + Args: + level: integer specifying the number of iterations for subdivision + of the mesh faces. Each additional level will result in four new + faces per face. + device: A torch.device object on which the outputs will be allocated. + + Returns: + Meshes object with verts and faces. + """ + if device is None: + device = torch.device("cpu") + if level < 0: + raise ValueError("level must be >= 0.") + if level == 0: + verts = torch.tensor(_ico_verts0, dtype=torch.float32, device=device) + faces = torch.tensor(_ico_faces0, dtype=torch.int64, device=device) + + else: + mesh = ico_sphere(level - 1, device) + subdivide = SubdivideMeshes() + mesh = subdivide(mesh) + verts = mesh.verts_list()[0] + verts /= verts.norm(p=2, dim=1, keepdim=True) + faces = mesh.faces_list()[0] + return Meshes(verts=[verts], faces=[faces]) diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/utils/torus.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/utils/torus.py new file mode 100644 index 0000000000000000000000000000000000000000..853cd895c998e6b762ce2ae25414ede27e54c7e1 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/utils/torus.py @@ -0,0 +1,73 @@ +# 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. + +# pyre-unsafe + +from itertools import tee +from math import cos, pi, sin +from typing import Iterator, Optional, Tuple + +import torch +from pytorch3d.structures.meshes import Meshes + + +# Make an iterator over the adjacent pairs: (-1, 0), (0, 1), ..., (N - 2, N - 1) +def _make_pair_range(N: int) -> Iterator[Tuple[int, int]]: + i, j = tee(range(-1, N)) + next(j, None) + return zip(i, j) + + +def torus( + r: float, R: float, sides: int, rings: int, device: Optional[torch.device] = None +) -> Meshes: + """ + Create vertices and faces for a torus. + + Args: + r: Inner radius of the torus. + R: Outer radius of the torus. + sides: Number of inner divisions. + rings: Number of outer divisions. + device: Device on which the outputs will be allocated. + + Returns: + Meshes object with the generated vertices and faces. + """ + if not (sides > 0): + raise ValueError("sides must be > 0.") + if not (rings > 0): + raise ValueError("rings must be > 0.") + device = device if device else torch.device("cpu") + + verts = [] + for i in range(rings): + # phi ranges from 0 to 2 pi (rings - 1) / rings + phi = 2 * pi * i / rings + for j in range(sides): + # theta ranges from 0 to 2 pi (sides - 1) / sides + theta = 2 * pi * j / sides + x = (R + r * cos(theta)) * cos(phi) + y = (R + r * cos(theta)) * sin(phi) + z = r * sin(theta) + # This vertex has index i * sides + j + verts.append([x, y, z]) + + faces = [] + for i0, i1 in _make_pair_range(rings): + index0 = (i0 % rings) * sides + index1 = (i1 % rings) * sides + for j0, j1 in _make_pair_range(sides): + index00 = index0 + (j0 % sides) + index01 = index0 + (j1 % sides) + index10 = index1 + (j0 % sides) + index11 = index1 + (j1 % sides) + faces.append([index00, index10, index11]) + faces.append([index11, index01, index00]) + + verts_list = [torch.tensor(verts, dtype=torch.float32, device=device)] + faces_list = [torch.tensor(faces, dtype=torch.int64, device=device)] + return Meshes(verts_list, faces_list) diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/vis/__init__.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/vis/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..eb0266b9e9ac1877a9084f31aa3207d2f0685753 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/vis/__init__.py @@ -0,0 +1,23 @@ +# 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. + +# pyre-unsafe + +import warnings + + +try: + from .plotly_vis import get_camera_wireframe, plot_batch_individually, plot_scene +except ModuleNotFoundError as err: + if "plotly" in str(err): + warnings.warn( + "Cannot import plotly-based visualization code." + " Please install plotly to enable (pip install plotly)." + ) + else: + raise + +from .texture_vis import texturesuv_image_matplotlib, texturesuv_image_PIL diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/vis/plotly_vis.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/vis/plotly_vis.py new file mode 100644 index 0000000000000000000000000000000000000000..8b5a8f4875bbf6e09482287e8b91a91bffb2b83a --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/vis/plotly_vis.py @@ -0,0 +1,1050 @@ +# 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. + +# pyre-unsafe + +import warnings +from typing import Dict, List, NamedTuple, Optional, Tuple, Union + +import plotly.graph_objects as go +import torch +from plotly.subplots import make_subplots +from pytorch3d.renderer import ( + HeterogeneousRayBundle, + ray_bundle_to_ray_points, + RayBundle, + TexturesAtlas, + TexturesVertex, +) +from pytorch3d.renderer.camera_utils import camera_to_eye_at_up +from pytorch3d.renderer.cameras import CamerasBase +from pytorch3d.structures import join_meshes_as_scene, Meshes, Pointclouds + + +Struct = Union[CamerasBase, Meshes, Pointclouds, RayBundle, HeterogeneousRayBundle] + + +def _get_len(struct: Union[Struct, List[Struct]]) -> int: # pragma: no cover + """ + Returns the length (usually corresponds to the batch size) of the input structure. + """ + # pyre-ignore[6] + if not _is_ray_bundle(struct): + # pyre-ignore[6] + return len(struct) + if _is_heterogeneous_ray_bundle(struct): + # pyre-ignore[16] + return len(struct.camera_counts) + # pyre-ignore[16] + return len(struct.directions) + + +def _is_ray_bundle(struct: Struct) -> bool: + """ + Args: + struct: Struct object to test + Returns: + True if something is a RayBundle, HeterogeneousRayBundle or + ImplicitronRayBundle, else False + """ + return hasattr(struct, "directions") + + +def _is_heterogeneous_ray_bundle(struct: Union[List[Struct], Struct]) -> bool: + """ + Args: + struct :object to test + Returns: + True if something is a HeterogeneousRayBundle or ImplicitronRayBundle + and cant be reduced to RayBundle else False + """ + # pyre-ignore[16] + return hasattr(struct, "camera_counts") and struct.camera_counts is not None + + +def get_camera_wireframe(scale: float = 0.3): # pragma: no cover + """ + Returns a wireframe of a 3D line-plot of a camera symbol. + """ + a = 0.5 * torch.tensor([-2, 1.5, 4]) + up1 = 0.5 * torch.tensor([0, 1.5, 4]) + up2 = 0.5 * torch.tensor([0, 2, 4]) + b = 0.5 * torch.tensor([2, 1.5, 4]) + c = 0.5 * torch.tensor([-2, -1.5, 4]) + d = 0.5 * torch.tensor([2, -1.5, 4]) + C = torch.zeros(3) + F = torch.tensor([0, 0, 3]) + camera_points = [a, up1, up2, up1, b, d, c, a, C, b, d, C, c, C, F] + lines = torch.stack([x.float() for x in camera_points]) * scale + return lines + + +class AxisArgs(NamedTuple): # pragma: no cover + showgrid: bool = False + zeroline: bool = False + showline: bool = False + ticks: str = "" + showticklabels: bool = False + backgroundcolor: str = "#fff" + showaxeslabels: bool = False + + +class Lighting(NamedTuple): # pragma: no cover + ambient: float = 0.8 + diffuse: float = 1.0 + fresnel: float = 0.0 + specular: float = 0.0 + roughness: float = 0.5 + facenormalsepsilon: float = 1e-6 + vertexnormalsepsilon: float = 1e-12 + + +@torch.no_grad() +def plot_scene( + plots: Dict[str, Dict[str, Struct]], + *, + viewpoint_cameras: Optional[CamerasBase] = None, + ncols: int = 1, + camera_scale: float = 0.3, + pointcloud_max_points: int = 20000, + pointcloud_marker_size: int = 1, + raybundle_max_rays: int = 20000, + raybundle_max_points_per_ray: int = 1000, + raybundle_ray_point_marker_size: int = 1, + raybundle_ray_line_width: int = 1, + **kwargs, +): # pragma: no cover + """ + Main function to visualize Cameras, Meshes, Pointclouds, and RayBundle. + Plots input Cameras, Meshes, Pointclouds, and RayBundle data into named subplots, + with named traces based on the dictionary keys. Cameras are + rendered at the camera center location using a wireframe. + + Args: + plots: A dict containing subplot and trace names, + as well as the Meshes, Cameras and Pointclouds objects to be rendered. + See below for examples of the format. + viewpoint_cameras: an instance of a Cameras object providing a location + to view the plotly plot from. If the batch size is equal + to the number of subplots, it is a one to one mapping. + If the batch size is 1, then that viewpoint will be used + for all the subplots will be viewed from that point. + Otherwise, the viewpoint_cameras will not be used. + ncols: the number of subplots per row + camera_scale: determines the size of the wireframe used to render cameras. + pointcloud_max_points: the maximum number of points to plot from + a pointcloud. If more are present, a random sample of size + pointcloud_max_points is used. + pointcloud_marker_size: the size of the points rendered by plotly + when plotting a pointcloud. + raybundle_max_rays: maximum number of rays of a RayBundle to visualize. Randomly + subsamples without replacement in case the number of rays is bigger than max_rays. + raybundle_max_points_per_ray: the maximum number of points per ray in RayBundle + to visualize. If more are present, a random sample of size + max_points_per_ray is used. + raybundle_ray_point_marker_size: the size of the ray points of a plotted RayBundle + raybundle_ray_line_width: the width of the plotted rays of a RayBundle + **kwargs: Accepts lighting (a Lighting object) and any of the args xaxis, + yaxis and zaxis which Plotly's scene accepts. Accepts axis_args, + which is an AxisArgs object that is applied to all 3 axes. + Example settings for axis_args and lighting are given at the + top of this file. + + Example: + + ..code-block::python + + mesh = ... + point_cloud = ... + fig = plot_scene({ + "subplot_title": { + "mesh_trace_title": mesh, + "pointcloud_trace_title": point_cloud + } + }) + fig.show() + + The above example will render one subplot which has both a mesh and pointcloud. + + If the Meshes, Pointclouds, or Cameras objects are batched, then every object in that batch + will be plotted in a single trace. + + ..code-block::python + mesh = ... # batch size 2 + point_cloud = ... # batch size 2 + fig = plot_scene({ + "subplot_title": { + "mesh_trace_title": mesh, + "pointcloud_trace_title": point_cloud + } + }) + fig.show() + + The above example renders one subplot with 2 traces, each of which renders + both objects from their respective batched data. + + Multiple subplots follow the same pattern: + ..code-block::python + mesh = ... # batch size 2 + point_cloud = ... # batch size 2 + fig = plot_scene({ + "subplot1_title": { + "mesh_trace_title": mesh[0], + "pointcloud_trace_title": point_cloud[0] + }, + "subplot2_title": { + "mesh_trace_title": mesh[1], + "pointcloud_trace_title": point_cloud[1] + } + }, + ncols=2) # specify the number of subplots per row + fig.show() + + The above example will render two subplots, each containing a mesh + and a pointcloud. The ncols argument will render two subplots in one row + instead of having them vertically stacked because the default is one subplot + per row. + + To view plotly plots from a PyTorch3D camera's point of view, we can use + viewpoint_cameras: + ..code-block::python + mesh = ... # batch size 2 + R, T = look_at_view_transform(2.7, 0, [0, 180]) # 2 camera angles, front and back + # Any instance of CamerasBase works, here we use FoVPerspectiveCameras + cameras = FoVPerspectiveCameras(device=device, R=R, T=T) + fig = plot_scene({ + "subplot1_title": { + "mesh_trace_title": mesh[0] + }, + "subplot2_title": { + "mesh_trace_title": mesh[1] + } + }, + viewpoint_cameras=cameras) + fig.show() + + The above example will render the first subplot seen from the camera on the +z axis, + and the second subplot from the viewpoint of the camera on the -z axis. + + We can visualize these cameras as well: + ..code-block::python + mesh = ... + R, T = look_at_view_transform(2.7, 0, [0, 180]) # 2 camera angles, front and back + # Any instance of CamerasBase works, here we use FoVPerspectiveCameras + cameras = FoVPerspectiveCameras(device=device, R=R, T=T) + fig = plot_scene({ + "subplot1_title": { + "mesh_trace_title": mesh, + "cameras_trace_title": cameras, + }, + }) + fig.show() + + The above example will render one subplot with the mesh object + and two cameras. + + RayBundle visualization is also supproted: + ..code-block::python + cameras = PerspectiveCameras(...) + ray_bundle = RayBundle(origins=..., lengths=..., directions=..., xys=...) + fig = plot_scene({ + "subplot1_title": { + "ray_bundle_trace_title": ray_bundle, + "cameras_trace_title": cameras, + }, + }) + fig.show() + + For an example of using kwargs, see below: + ..code-block::python + mesh = ... + point_cloud = ... + fig = plot_scene({ + "subplot_title": { + "mesh_trace_title": mesh, + "pointcloud_trace_title": point_cloud + } + }, + axis_args=AxisArgs(backgroundcolor="rgb(200,230,200)")) # kwarg axis_args + fig.show() + + The above example will render each axis with the input background color. + + See the tutorials in pytorch3d/docs/tutorials for more examples + (namely rendered_color_points.ipynb and rendered_textured_meshes.ipynb). + """ + + subplots = list(plots.keys()) + fig = _gen_fig_with_subplots(len(subplots), ncols, subplots) + lighting = kwargs.get("lighting", Lighting())._asdict() + axis_args_dict = kwargs.get("axis_args", AxisArgs())._asdict() + + # Set axis arguments to defaults defined at the top of this file + x_settings = {**axis_args_dict} + y_settings = {**axis_args_dict} + z_settings = {**axis_args_dict} + + # Update the axes with any axis settings passed in as kwargs. + x_settings.update(**kwargs.get("xaxis", {})) + y_settings.update(**kwargs.get("yaxis", {})) + z_settings.update(**kwargs.get("zaxis", {})) + + camera = { + "up": { + "x": 0.0, + "y": 1.0, + "z": 0.0, + } # set the up vector to match PyTorch3D world coordinates conventions + } + viewpoints_eye_at_up_world = None + if viewpoint_cameras: + n_viewpoint_cameras = len(viewpoint_cameras) + if n_viewpoint_cameras == len(subplots) or n_viewpoint_cameras == 1: + # Calculate the vectors eye, at, up in world space + # to initialize the position of the camera in + # the plotly figure + viewpoints_eye_at_up_world = camera_to_eye_at_up( + viewpoint_cameras.get_world_to_view_transform().cpu() + ) + else: + msg = "Invalid number {} of viewpoint cameras were provided. Either 1 \ + or {} cameras are required".format( + len(viewpoint_cameras), len(subplots) + ) + warnings.warn(msg) + + for subplot_idx in range(len(subplots)): + subplot_name = subplots[subplot_idx] + traces = plots[subplot_name] + for trace_name, struct in traces.items(): + if isinstance(struct, Meshes): + _add_mesh_trace(fig, struct, trace_name, subplot_idx, ncols, lighting) + elif isinstance(struct, Pointclouds): + _add_pointcloud_trace( + fig, + struct, + trace_name, + subplot_idx, + ncols, + pointcloud_max_points, + pointcloud_marker_size, + ) + elif isinstance(struct, CamerasBase): + _add_camera_trace( + fig, struct, trace_name, subplot_idx, ncols, camera_scale + ) + elif _is_ray_bundle(struct): + _add_ray_bundle_trace( + fig, + struct, + trace_name, + subplot_idx, + ncols, + raybundle_max_rays, + raybundle_max_points_per_ray, + raybundle_ray_point_marker_size, + raybundle_ray_line_width, + ) + else: + raise ValueError( + "struct {} is not a Cameras, Meshes, Pointclouds,".format(struct) + + " , RayBundle or HeterogeneousRayBundle object." + ) + + # Ensure update for every subplot. + plot_scene = "scene" + str(subplot_idx + 1) + current_layout = fig["layout"][plot_scene] + xaxis = current_layout["xaxis"] + yaxis = current_layout["yaxis"] + zaxis = current_layout["zaxis"] + + # Update the axes with our above default and provided settings. + xaxis.update(**x_settings) + yaxis.update(**y_settings) + zaxis.update(**z_settings) + + # update camera viewpoint if provided + if viewpoints_eye_at_up_world is not None: + # Use camera params for batch index or the first camera if only one provided. + viewpoint_idx = min(n_viewpoint_cameras - 1, subplot_idx) + + eye, at, up = (i[viewpoint_idx] for i in viewpoints_eye_at_up_world) + eye_x, eye_y, eye_z = eye.tolist() + at_x, at_y, at_z = at.tolist() + up_x, up_y, up_z = up.tolist() + + # scale camera eye to plotly [-1, 1] ranges + x_range = xaxis["range"] + y_range = yaxis["range"] + z_range = zaxis["range"] + + eye_x = _scale_camera_to_bounds(eye_x, x_range, True) + eye_y = _scale_camera_to_bounds(eye_y, y_range, True) + eye_z = _scale_camera_to_bounds(eye_z, z_range, True) + + at_x = _scale_camera_to_bounds(at_x, x_range, True) + at_y = _scale_camera_to_bounds(at_y, y_range, True) + at_z = _scale_camera_to_bounds(at_z, z_range, True) + + up_x = _scale_camera_to_bounds(up_x, x_range, False) + up_y = _scale_camera_to_bounds(up_y, y_range, False) + up_z = _scale_camera_to_bounds(up_z, z_range, False) + + camera["eye"] = {"x": eye_x, "y": eye_y, "z": eye_z} + camera["center"] = {"x": at_x, "y": at_y, "z": at_z} + camera["up"] = {"x": up_x, "y": up_y, "z": up_z} + + current_layout.update( + { + "xaxis": xaxis, + "yaxis": yaxis, + "zaxis": zaxis, + "aspectmode": "cube", + "camera": camera, + } + ) + + return fig + + +@torch.no_grad() +def plot_batch_individually( + batched_structs: Union[ + List[Struct], + Struct, + ], + *, + viewpoint_cameras: Optional[CamerasBase] = None, + ncols: int = 1, + extend_struct: bool = True, + subplot_titles: Optional[List[str]] = None, + **kwargs, +): # pragma: no cover + """ + This is a higher level plotting function than plot_scene, for plotting + Cameras, Meshes, Pointclouds, and RayBundle in simple cases. The simplest use + is to plot a single Cameras, Meshes, Pointclouds, or a RayBundle object, + where you just pass it in as a one element list. This will plot each batch + element in a separate subplot. + + More generally, you can supply multiple Cameras, Meshes, Pointclouds, or RayBundle + having the same batch size `n`. In this case, there will be `n` subplots, + each depicting the corresponding batch element of all the inputs. + + In addition, you can include Cameras, Meshes, Pointclouds, or RayBundle of size 1 in + the input. These will either be rendered in the first subplot + (if extend_struct is False), or in every subplot. + RayBundle includes ImplicitronRayBundle and HeterogeneousRaybundle. + + Args: + batched_structs: a list of Cameras, Meshes, Pointclouds and RayBundle to be + rendered. Each structure's corresponding batch element will be plotted in a + single subplot, resulting in n subplots for a batch of size n. Every struct + should either have the same batch size or be of batch size 1. See extend_struct + and the description above for how batch size 1 structs are handled. Also accepts + a single Cameras, Meshes, Pointclouds, and RayBundle object, which will have + each individual element plotted in its own subplot. + viewpoint_cameras: an instance of a Cameras object providing a location + to view the plotly plot from. If the batch size is equal + to the number of subplots, it is a one to one mapping. + If the batch size is 1, then that viewpoint will be used + for all the subplots will be viewed from that point. + Otherwise, the viewpoint_cameras will not be used. + ncols: the number of subplots per row + extend_struct: if True, indicates that structs of batch size 1 + should be plotted in every subplot. + subplot_titles: strings to name each subplot + **kwargs: keyword arguments which are passed to plot_scene. + See plot_scene documentation for details. + + Example: + + ..code-block::python + + mesh = ... # mesh of batch size 2 + point_cloud = ... # point_cloud of batch size 2 + fig = plot_batch_individually([mesh, point_cloud], subplot_titles=["plot1", "plot2"]) + fig.show() + + # this is equivalent to the below figure + fig = plot_scene({ + "plot1": { + "trace1-1": mesh[0], + "trace1-2": point_cloud[0] + }, + "plot2":{ + "trace2-1": mesh[1], + "trace2-2": point_cloud[1] + } + }) + fig.show() + + The above example will render two subplots which each have both a mesh and pointcloud. + For more examples look at the pytorch3d tutorials at `pytorch3d/docs/tutorials`, + in particular the files rendered_color_points.ipynb and rendered_textured_meshes.ipynb. + """ + + # check that every batch is the same size or is size 1 + if _get_len(batched_structs) == 0: + msg = "No structs to plot" + warnings.warn(msg) + return + max_size = 0 + if isinstance(batched_structs, list): + max_size = max(_get_len(s) for s in batched_structs) + for struct in batched_structs: + struct_len = _get_len(struct) + if struct_len not in (1, max_size): + msg = "invalid batch size {} provided: {}".format(struct_len, struct) + raise ValueError(msg) + else: + max_size = _get_len(batched_structs) + + if max_size == 0: + msg = "No data is provided with at least one element" + raise ValueError(msg) + + if subplot_titles: + if len(subplot_titles) != max_size: + msg = "invalid number of subplot titles" + raise ValueError(msg) + + # if we are dealing with HeterogeneousRayBundle of ImplicitronRayBundle create + # first indexes for faster + first_idxs = None + if _is_heterogeneous_ray_bundle(batched_structs): + # pyre-ignore[16] + cumsum = batched_structs.camera_counts.cumsum(dim=0) + first_idxs = torch.cat((cumsum.new_zeros((1,)), cumsum)) + + scene_dictionary = {} + # construct the scene dictionary + for scene_num in range(max_size): + subplot_title = ( + subplot_titles[scene_num] + if subplot_titles + else "subplot " + str(scene_num + 1) + ) + scene_dictionary[subplot_title] = {} + + if isinstance(batched_structs, list): + for i, batched_struct in enumerate(batched_structs): + first_idxs = None + if _is_heterogeneous_ray_bundle(batched_structs[i]): + # pyre-ignore[16] + cumsum = batched_struct.camera_counts.cumsum(dim=0) + first_idxs = torch.cat((cumsum.new_zeros((1,)), cumsum)) + # check for whether this struct needs to be extended + batched_struct_len = _get_len(batched_struct) + if i >= batched_struct_len and not extend_struct: + continue + _add_struct_from_batch( + batched_struct, + scene_num, + subplot_title, + scene_dictionary, + i + 1, + first_idxs=first_idxs, + ) + else: # batched_structs is a single struct + _add_struct_from_batch( + batched_structs, + scene_num, + subplot_title, + scene_dictionary, + first_idxs=first_idxs, + ) + + return plot_scene( + scene_dictionary, viewpoint_cameras=viewpoint_cameras, ncols=ncols, **kwargs + ) + + +def _add_struct_from_batch( + batched_struct: Struct, + scene_num: int, + subplot_title: str, + scene_dictionary: Dict[str, Dict[str, Struct]], + trace_idx: int = 1, + first_idxs: Optional[torch.Tensor] = None, +) -> None: # pragma: no cover + """ + Adds the struct corresponding to the given scene_num index to + a provided scene_dictionary to be passed in to plot_scene + + Args: + batched_struct: the batched data structure to add to the dict + scene_num: the subplot from plot_batch_individually which this struct + should be added to + subplot_title: the title of the subplot + scene_dictionary: the dictionary to add the indexed struct to + trace_idx: the trace number, starting at 1 for this struct's trace + """ + struct = None + if isinstance(batched_struct, CamerasBase): + # we can't index directly into camera batches + R, T = batched_struct.R, batched_struct.T + r_idx = min(scene_num, len(R) - 1) + t_idx = min(scene_num, len(T) - 1) + R = R[r_idx].unsqueeze(0) + T = T[t_idx].unsqueeze(0) + struct = CamerasBase(device=batched_struct.device, R=R, T=T) + elif _is_ray_bundle(batched_struct) and not _is_heterogeneous_ray_bundle( + batched_struct + ): + # for RayBundle we treat the camera count as the batch index + struct_idx = min(scene_num, _get_len(batched_struct) - 1) + + struct = RayBundle( + **{ + attr: getattr(batched_struct, attr)[struct_idx] + for attr in ["origins", "directions", "lengths", "xys"] + } + ) + elif _is_heterogeneous_ray_bundle(batched_struct): + # for RayBundle we treat the camera count as the batch index + struct_idx = min(scene_num, _get_len(batched_struct) - 1) + + struct = RayBundle( + **{ + attr: getattr(batched_struct, attr)[ + # pyre-ignore[16] + first_idxs[struct_idx] : first_idxs[struct_idx + 1] + ] + for attr in ["origins", "directions", "lengths", "xys"] + } + ) + + else: # batched meshes and pointclouds are indexable + struct_idx = min(scene_num, _get_len(batched_struct) - 1) + # pyre-ignore[16] + struct = batched_struct[struct_idx] + trace_name = "trace{}-{}".format(scene_num + 1, trace_idx) + scene_dictionary[subplot_title][trace_name] = struct + + +def _add_mesh_trace( + fig: go.Figure, # pyre-ignore[11] + meshes: Meshes, + trace_name: str, + subplot_idx: int, + ncols: int, + lighting: Lighting, +) -> None: # pragma: no cover + """ + Adds a trace rendering a Meshes object to the passed in figure, with + a given name and in a specific subplot. + + Args: + fig: plotly figure to add the trace within. + meshes: Meshes object to render. It can be batched. + trace_name: name to label the trace with. + subplot_idx: identifies the subplot, with 0 being the top left. + ncols: the number of subplots per row. + lighting: a Lighting object that specifies the Mesh3D lighting. + """ + + mesh = join_meshes_as_scene(meshes) + mesh = mesh.detach().cpu() + verts = mesh.verts_packed() + faces = mesh.faces_packed() + # If mesh has vertex colors or face colors, use them + # for figure, otherwise use plotly's default colors. + verts_rgb = None + faces_rgb = None + if isinstance(mesh.textures, TexturesVertex): + verts_rgb = mesh.textures.verts_features_packed() + verts_rgb.clamp_(min=0.0, max=1.0) + verts_rgb = torch.tensor(255.0) * verts_rgb + if isinstance(mesh.textures, TexturesAtlas): + atlas = mesh.textures.atlas_packed() + # If K==1 + if atlas.shape[1] == 1 and atlas.shape[3] == 3: + faces_rgb = atlas[:, 0, 0] + + # Reposition the unused vertices to be "inside" the object + # (i.e. they won't be visible in the plot). + verts_used = torch.zeros((verts.shape[0],), dtype=torch.bool) + verts_used[torch.unique(faces)] = True + verts_center = verts[verts_used].mean(0) + verts[~verts_used] = verts_center + + row, col = subplot_idx // ncols + 1, subplot_idx % ncols + 1 + fig.add_trace( + go.Mesh3d( + x=verts[:, 0], + y=verts[:, 1], + z=verts[:, 2], + vertexcolor=verts_rgb, + facecolor=faces_rgb, + i=faces[:, 0], + j=faces[:, 1], + k=faces[:, 2], + lighting=lighting, + name=trace_name, + ), + row=row, + col=col, + ) + + # Access the current subplot's scene configuration + plot_scene = "scene" + str(subplot_idx + 1) + current_layout = fig["layout"][plot_scene] + + # update the bounds of the axes for the current trace + max_expand = (verts.max(0)[0] - verts.min(0)[0]).max() + _update_axes_bounds(verts_center, max_expand, current_layout) + + +def _add_pointcloud_trace( + fig: go.Figure, + pointclouds: Pointclouds, + trace_name: str, + subplot_idx: int, + ncols: int, + max_points_per_pointcloud: int, + marker_size: int, +) -> None: # pragma: no cover + """ + Adds a trace rendering a Pointclouds object to the passed in figure, with + a given name and in a specific subplot. + + Args: + fig: plotly figure to add the trace within. + pointclouds: Pointclouds object to render. It can be batched. + trace_name: name to label the trace with. + subplot_idx: identifies the subplot, with 0 being the top left. + ncols: the number of subplots per row. + max_points_per_pointcloud: the number of points to render, which are randomly sampled. + marker_size: the size of the rendered points + """ + pointclouds = pointclouds.detach().cpu().subsample(max_points_per_pointcloud) + verts = pointclouds.points_packed() + features = pointclouds.features_packed() + + color = None + if features is not None: + if features.shape[1] == 4: # rgba + template = "rgb(%d, %d, %d, %f)" + rgb = (features[:, :3].clamp(0.0, 1.0) * 255).int() + color = [template % (*rgb_, a_) for rgb_, a_ in zip(rgb, features[:, 3])] + + if features.shape[1] == 3: + template = "rgb(%d, %d, %d)" + rgb = (features.clamp(0.0, 1.0) * 255).int() + color = [template % (r, g, b) for r, g, b in rgb] + + row = subplot_idx // ncols + 1 + col = subplot_idx % ncols + 1 + fig.add_trace( + go.Scatter3d( + x=verts[:, 0], + y=verts[:, 1], + z=verts[:, 2], + marker={"color": color, "size": marker_size}, + mode="markers", + name=trace_name, + ), + row=row, + col=col, + ) + + # Access the current subplot's scene configuration + plot_scene = "scene" + str(subplot_idx + 1) + current_layout = fig["layout"][plot_scene] + + # update the bounds of the axes for the current trace + verts_center = verts.mean(0) + max_expand = (verts.max(0)[0] - verts.min(0)[0]).max() + _update_axes_bounds(verts_center, max_expand, current_layout) + + +def _add_camera_trace( + fig: go.Figure, + cameras: CamerasBase, + trace_name: str, + subplot_idx: int, + ncols: int, + camera_scale: float, +) -> None: # pragma: no cover + """ + Adds a trace rendering a Cameras object to the passed in figure, with + a given name and in a specific subplot. + + Args: + fig: plotly figure to add the trace within. + cameras: the Cameras object to render. It can be batched. + trace_name: name to label the trace with. + subplot_idx: identifies the subplot, with 0 being the top left. + ncols: the number of subplots per row. + camera_scale: the size of the wireframe used to render the Cameras object. + """ + cam_wires = get_camera_wireframe(camera_scale).to(cameras.device) + cam_trans = cameras.get_world_to_view_transform().inverse() + cam_wires_trans = cam_trans.transform_points(cam_wires).detach().cpu() + # if batch size is 1, unsqueeze to add dimension + if len(cam_wires_trans.shape) < 3: + cam_wires_trans = cam_wires_trans.unsqueeze(0) + + nan_tensor = torch.Tensor([[float("NaN")] * 3]) + all_cam_wires = cam_wires_trans[0] + for wire in cam_wires_trans[1:]: + # We combine camera points into a single tensor to plot them in a + # single trace. The NaNs are inserted between sets of camera + # points so that the lines drawn by Plotly are not drawn between + # points that belong to different cameras. + all_cam_wires = torch.cat((all_cam_wires, nan_tensor, wire)) + x, y, z = all_cam_wires.detach().cpu().numpy().T.astype(float) + + row, col = subplot_idx // ncols + 1, subplot_idx % ncols + 1 + fig.add_trace( + go.Scatter3d(x=x, y=y, z=z, marker={"size": 1}, name=trace_name), + row=row, + col=col, + ) + + # Access the current subplot's scene configuration + plot_scene = "scene" + str(subplot_idx + 1) + current_layout = fig["layout"][plot_scene] + + # flatten for bounds calculations + flattened_wires = cam_wires_trans.flatten(0, 1) + verts_center = flattened_wires.mean(0) + max_expand = (flattened_wires.max(0)[0] - flattened_wires.min(0)[0]).max() + _update_axes_bounds(verts_center, max_expand, current_layout) + + +def _add_ray_bundle_trace( + fig: go.Figure, + ray_bundle: Union[RayBundle, HeterogeneousRayBundle], + trace_name: str, + subplot_idx: int, + ncols: int, + max_rays: int, + max_points_per_ray: int, + marker_size: int, + line_width: int, +) -> None: # pragma: no cover + """ + Adds a trace rendering a ray bundle object + to the passed in figure, with a given name and in a specific subplot. + + Args: + fig: plotly figure to add the trace within. + ray_bundle: the RayBundle, ImplicitronRayBundle or HeterogeneousRaybundle to render. + It can be batched. + trace_name: name to label the trace with. + subplot_idx: identifies the subplot, with 0 being the top left. + ncols: the number of subplots per row. + max_rays: maximum number of plotted rays in total. Randomly subsamples + without replacement in case the number of rays is bigger than max_rays. + max_points_per_ray: maximum number of points plotted per ray. + marker_size: the size of the ray point markers. + line_width: the width of the ray lines. + """ + + n_pts_per_ray = ray_bundle.lengths.shape[-1] + n_rays = ray_bundle.lengths.shape[:-1].numel() + + # flatten all batches of rays into a single big bundle + ray_bundle_flat = RayBundle( + **{ + attr: torch.flatten(getattr(ray_bundle, attr), start_dim=0, end_dim=-2) + for attr in ["origins", "directions", "lengths", "xys"] + } + ) + + # subsample the rays (if needed) + if n_rays > max_rays: + indices_rays = torch.randperm(n_rays)[:max_rays] + ray_bundle_flat = RayBundle( + **{ + attr: getattr(ray_bundle_flat, attr)[indices_rays] + for attr in ["origins", "directions", "lengths", "xys"] + } + ) + + # make ray line endpoints + min_max_ray_depth = torch.stack( + [ + ray_bundle_flat.lengths.min(dim=1).values, + ray_bundle_flat.lengths.max(dim=1).values, + ], + dim=-1, + ) + ray_lines_endpoints = ray_bundle_to_ray_points( + ray_bundle_flat._replace(lengths=min_max_ray_depth) + ) + + # make the ray lines for plotly plotting + nan_tensor = torch.tensor( + [[float("NaN")] * 3], + device=ray_lines_endpoints.device, + dtype=ray_lines_endpoints.dtype, + ) + ray_lines = torch.empty(size=(1, 3), device=ray_lines_endpoints.device) + for ray_line in ray_lines_endpoints: + # We combine the ray lines into a single tensor to plot them in a + # single trace. The NaNs are inserted between sets of ray lines + # so that the lines drawn by Plotly are not drawn between + # lines that belong to different rays. + ray_lines = torch.cat((ray_lines, nan_tensor, ray_line)) + x, y, z = ray_lines.detach().cpu().numpy().T.astype(float) + row, col = subplot_idx // ncols + 1, subplot_idx % ncols + 1 + fig.add_trace( + go.Scatter3d( + x=x, + y=y, + z=z, + marker={"size": 0.1}, + line={"width": line_width}, + name=trace_name, + ), + row=row, + col=col, + ) + + # subsample the ray points (if needed) + if n_pts_per_ray > max_points_per_ray: + indices_ray_pts = torch.cat( + [ + torch.randperm(n_pts_per_ray)[:max_points_per_ray] + ri * n_pts_per_ray + for ri in range(ray_bundle_flat.lengths.shape[0]) + ] + ) + ray_bundle_flat = ray_bundle_flat._replace( + lengths=ray_bundle_flat.lengths.reshape(-1)[indices_ray_pts].reshape( + ray_bundle_flat.lengths.shape[0], -1 + ) + ) + + # plot the ray points + ray_points = ( + ray_bundle_to_ray_points(ray_bundle_flat) + .view(-1, 3) + .detach() + .cpu() + .numpy() + .astype(float) + ) + fig.add_trace( + go.Scatter3d( + x=ray_points[:, 0], + y=ray_points[:, 1], + z=ray_points[:, 2], + mode="markers", + name=trace_name + "_points", + marker={"size": marker_size}, + ), + row=row, + col=col, + ) + + # Access the current subplot's scene configuration + plot_scene = "scene" + str(subplot_idx + 1) + current_layout = fig["layout"][plot_scene] + + # update the bounds of the axes for the current trace + all_ray_points = ray_bundle_to_ray_points(ray_bundle).reshape(-1, 3) + ray_points_center = all_ray_points.mean(dim=0) + max_expand = (all_ray_points.max(0)[0] - all_ray_points.min(0)[0]).max().item() + _update_axes_bounds(ray_points_center, float(max_expand), current_layout) + + +def _gen_fig_with_subplots( + batch_size: int, ncols: int, subplot_titles: List[str] +): # pragma: no cover + """ + Takes in the number of objects to be plotted and generate a plotly figure + with the appropriate number and orientation of titled subplots. + Args: + batch_size: the number of elements in the batch of objects to be visualized. + ncols: number of subplots in the same row. + subplot_titles: titles for the subplot(s). list of strings of length batch_size. + + Returns: + Plotly figure with ncols subplots per row, and batch_size subplots. + """ + fig_rows = batch_size // ncols + if batch_size % ncols != 0: + fig_rows += 1 # allow for non-uniform rows + fig_cols = ncols + fig_type = [{"type": "scene"}] + specs = [fig_type * fig_cols] * fig_rows + # subplot_titles must have one title per subplot + fig = make_subplots( + rows=fig_rows, + cols=fig_cols, + specs=specs, + subplot_titles=subplot_titles, + column_widths=[1.0] * fig_cols, + ) + return fig + + +def _update_axes_bounds( + verts_center: torch.Tensor, + max_expand: float, + current_layout: go.Scene, # pyre-ignore[11] +) -> None: # pragma: no cover + """ + Takes in the vertices' center point and max spread, and the current plotly figure + layout and updates the layout to have bounds that include all traces for that subplot. + Args: + verts_center: tensor of size (3) corresponding to a trace's vertices' center point. + max_expand: the maximum spread in any dimension of the trace's vertices. + current_layout: the plotly figure layout scene corresponding to the referenced trace. + """ + verts_center = verts_center.detach().cpu() + verts_min = verts_center - max_expand + verts_max = verts_center + max_expand + bounds = torch.t(torch.stack((verts_min, verts_max))) + + # Ensure that within a subplot, the bounds capture all traces + old_xrange, old_yrange, old_zrange = ( + current_layout["xaxis"]["range"], + current_layout["yaxis"]["range"], + current_layout["zaxis"]["range"], + ) + x_range, y_range, z_range = bounds + if old_xrange is not None: + x_range[0] = min(x_range[0], old_xrange[0]) + x_range[1] = max(x_range[1], old_xrange[1]) + if old_yrange is not None: + y_range[0] = min(y_range[0], old_yrange[0]) + y_range[1] = max(y_range[1], old_yrange[1]) + if old_zrange is not None: + z_range[0] = min(z_range[0], old_zrange[0]) + z_range[1] = max(z_range[1], old_zrange[1]) + + xaxis = {"range": x_range} + yaxis = {"range": y_range} + zaxis = {"range": z_range} + current_layout.update({"xaxis": xaxis, "yaxis": yaxis, "zaxis": zaxis}) + + +def _scale_camera_to_bounds( + coordinate: float, axis_bounds: Tuple[float, float], is_position: bool +) -> float: # pragma: no cover + """ + We set our plotly plot's axes' bounding box to [-1,1]x[-1,1]x[-1,1]. As such, + the plotly camera location has to be scaled accordingly to have its world coordinates + correspond to its relative plotted coordinates for viewing the plotly plot. + This function does the scaling and offset to transform the coordinates. + + Args: + coordinate: the float value to be transformed + axis_bounds: the bounds of the plotly plot for the axis which + the coordinate argument refers to + is_position: If true, the float value is the coordinate of a position, and so must + be moved in to [-1,1]. Otherwise it is a component of a direction, and so needs only + to be scaled. + """ + scale = (axis_bounds[1] - axis_bounds[0]) / 2 + if not is_position: + return coordinate / scale + offset = (axis_bounds[1] / scale) - 1 + return coordinate / scale - offset diff --git a/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/vis/texture_vis.py b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/vis/texture_vis.py new file mode 100644 index 0000000000000000000000000000000000000000..60b0d1b4db17a0fec731c2e1bdbfee14cbea4a2e --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/pytorch3d/vis/texture_vis.py @@ -0,0 +1,112 @@ +# 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. + +# pyre-unsafe + +from typing import Any, Optional + +import numpy as np +from PIL import Image, ImageDraw +from pytorch3d.renderer.mesh import TexturesUV + + +def texturesuv_image_matplotlib( + texture: TexturesUV, + *, + texture_index: int = 0, + radius: float = 1, + color=(1.0, 0.0, 0.0), + subsample: Optional[int] = 10000, + origin: str = "upper", +) -> None: # pragma: no cover + """ + Plot the texture image for one element of a TexturesUV with + matplotlib together with verts_uvs positions circled. + In particular a value in verts_uvs which is never referenced + in faces_uvs will still be plotted. + This is for debugging purposes, e.g. to align the map with + the uv coordinates. In particular, matplotlib + is used which is not an official dependency of PyTorch3D. + + Args: + texture: a TexturesUV object with one mesh + texture_index: index in the batch to plot + radius: plotted circle radius in pixels + color: any matplotlib-understood color for the circles. + subsample: if not None, number of points to plot. + Otherwise all points are plotted. + origin: "upper" or "lower" like matplotlib.imshow . + upper (the default) matches texturesuv_image_PIL. + """ + + import matplotlib.pyplot as plt + from matplotlib.patches import Circle + + texture_image = texture.maps_padded() + centers = texture.centers_for_image(index=texture_index).numpy() + + ax = plt.gca() + ax.imshow(texture_image[texture_index].detach().cpu().numpy(), origin=origin) + + n_points = centers.shape[0] + if subsample is None or n_points <= subsample: + indices = range(n_points) + else: + indices = np.random.choice(n_points, subsample, replace=False) + for i in indices: + # setting clip_on=False makes it obvious when + # we have UV coordinates outside the correct range + ax.add_patch(Circle(centers[i], radius, color=color, clip_on=False)) + + +def texturesuv_image_PIL( + texture: TexturesUV, + *, + texture_index: int = 0, + radius: float = 1, + color: Any = "red", + subsample: Optional[int] = 10000, +): # pragma: no cover + """ + Return a PIL image of the texture image of one element of the batch + from a TexturesUV, together with the verts_uvs positions circled. + In particular a value in verts_uvs which is never referenced + in faces_uvs will still be plotted. + This is for debugging purposes, e.g. to align the map with + the uv coordinates. In particular, matplotlib + is used which is not an official dependency of PyTorch3D. + + Args: + texture: a TexturesUV object with one mesh + texture_index: index in the batch to plot + radius: plotted circle radius in pixels + color: any PIL-understood color for the circles. + subsample: if not None, number of points to plot. + Otherwise all points are plotted. + + Returns: + PIL Image object. + """ + + centers = texture.centers_for_image(index=texture_index).numpy() + texture_image = texture.maps_padded() + texture_array = (texture_image[texture_index] * 255).cpu().numpy().astype(np.uint8) + + image = Image.fromarray(texture_array) + draw = ImageDraw.Draw(image) + + n_points = centers.shape[0] + if subsample is None or n_points <= subsample: + indices = range(n_points) + else: + indices = np.random.choice(n_points, subsample, replace=False) + + for i in indices: + x = centers[i][0] + y = centers[i][1] + draw.ellipse([(x - radius, y - radius), (x + radius, y + radius)], fill=color) + + return image diff --git a/third_party/AnyBimanual/third_party/pytorch3d/scripts/build_website.sh b/third_party/AnyBimanual/third_party/pytorch3d/scripts/build_website.sh new file mode 100644 index 0000000000000000000000000000000000000000..2fc2db9ad112ebc0f68d6db7528042e1e0978d52 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/scripts/build_website.sh @@ -0,0 +1,66 @@ +#!/bin/bash +# 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. + +# run this script from the project root using `./scripts/build_docs.sh` + +set -e + +usage() { + echo "Usage: $0 [-b]" + echo "" + echo "Build PyTorch3D documentation." + echo "" + echo " -b Build static version of documentation (otherwise start server)" + echo "" + exit 1 +} + +BUILD_STATIC=false + +while getopts 'hb' flag; do + case "${flag}" in + h) + usage + ;; + b) + BUILD_STATIC=true + ;; + *) + usage + ;; + esac +done + + +echo "-----------------------------------" +echo "Building PyTorch3D Docusaurus site" +echo "-----------------------------------" +cd website +yarn +cd .. + +echo "-----------------------------------" +echo "Generating tutorials" +echo "-----------------------------------" +cwd=$(pwd) +mkdir -p "website/_tutorials" +mkdir -p "website/static/files" +python scripts/parse_tutorials.py --repo_dir "${cwd}" + +cd website + +if [[ $BUILD_STATIC == true ]]; then + echo "-----------------------------------" + echo "Building static site" + echo "-----------------------------------" + yarn build +else + echo "-----------------------------------" + echo "Starting local server" + echo "-----------------------------------" + yarn start +fi diff --git a/third_party/AnyBimanual/third_party/pytorch3d/scripts/parse_tutorials.py b/third_party/AnyBimanual/third_party/pytorch3d/scripts/parse_tutorials.py new file mode 100644 index 0000000000000000000000000000000000000000..a7c7cd267b00c4267db9d719eda1c07b8c3f6694 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/scripts/parse_tutorials.py @@ -0,0 +1,117 @@ +#!/usr/bin/env python3 +# 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. + +import argparse +import json +import os + +import nbformat +from bs4 import BeautifulSoup +from nbconvert import HTMLExporter, ScriptExporter + + +TEMPLATE = """const CWD = process.cwd(); + +const React = require('react'); +const Tutorial = require(`${{CWD}}/core/Tutorial.js`); + +class TutorialPage extends React.Component {{ + render() {{ + const {{config: siteConfig}} = this.props; + const {{baseUrl}} = siteConfig; + return ; + }} +}} + +module.exports = TutorialPage; + +""" + +JS_SCRIPTS = """ + + +""" # noqa: E501 + + +def gen_tutorials(repo_dir: str) -> None: + """Generate HTML tutorials for PyTorch3D Docusaurus site from Jupyter notebooks. + + Also create ipynb and py versions of tutorial in Docusaurus site for + download. + """ + with open(os.path.join(repo_dir, "website", "tutorials.json"), "r") as infile: + tutorial_config = json.loads(infile.read()) + + tutorial_ids = {x["id"] for v in tutorial_config.values() for x in v} + + for tid in tutorial_ids: + print("Generating {} tutorial".format(tid)) + + # convert notebook to HTML + ipynb_in_path = os.path.join( + repo_dir, "docs", "tutorials", "{}.ipynb".format(tid) + ) + with open(ipynb_in_path, "r") as infile: + nb_str = infile.read() + nb = nbformat.reads(nb_str, nbformat.NO_CONVERT) + + # displayname is absent from notebook metadata + nb["metadata"]["kernelspec"]["display_name"] = "python3" + + exporter = HTMLExporter() + html, meta = exporter.from_notebook_node(nb) + + # pull out html div for notebook + soup = BeautifulSoup(html, "html.parser") + nb_meat = soup.find("div", {"id": "notebook-container"}) + del nb_meat.attrs["id"] + nb_meat.attrs["class"] = ["notebook"] + html_out = JS_SCRIPTS + str(nb_meat) + + # generate html file + html_out_path = os.path.join( + repo_dir, "website", "_tutorials", "{}.html".format(tid) + ) + with open(html_out_path, "w") as html_outfile: + html_outfile.write(html_out) + + # generate JS file + script = TEMPLATE.format(tid) + js_out_path = os.path.join( + repo_dir, "website", "pages", "tutorials", "{}.js".format(tid) + ) + with open(js_out_path, "w") as js_outfile: + js_outfile.write(script) + + # output tutorial in both ipynb & py form + ipynb_out_path = os.path.join( + repo_dir, "website", "static", "files", "{}.ipynb".format(tid) + ) + with open(ipynb_out_path, "w") as ipynb_outfile: + ipynb_outfile.write(nb_str) + exporter = ScriptExporter() + script, meta = exporter.from_notebook_node(nb) + py_out_path = os.path.join( + repo_dir, "website", "static", "files", "{}.py".format(tid) + ) + with open(py_out_path, "w") as py_outfile: + py_outfile.write(script) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser( + description="Generate JS, HTML, ipynb, and py files for tutorials." + ) + parser.add_argument( + "--repo_dir", metavar="path", required=True, help="PyTorch3D repo directory." + ) + args = parser.parse_args() + gen_tutorials(args.repo_dir) diff --git a/third_party/AnyBimanual/third_party/pytorch3d/scripts/publish_website.sh b/third_party/AnyBimanual/third_party/pytorch3d/scripts/publish_website.sh new file mode 100644 index 0000000000000000000000000000000000000000..604875245965948db603e27dae4bbe95d629e0a1 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/scripts/publish_website.sh @@ -0,0 +1,43 @@ +#!/bin/bash +# 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. + + +# Instructions, assuming you are on a fresh pytorch3d checkout on a local +# drive. + +# (1) Have a separate checkout of pytorch3d at the head of the gh-pages branch +# on a local drive. Set the variable GHP to its full path. +# Any uncommitted changes there will be obliterated. +# For example +# GHP=/path/to/pytorch3d-gh-pages +# git clone -b gh-pages https://github.com/facebookresearch/pytorch3d $GHP + +# (2) Run this script in this directory with +# sudo docker run -it --rm -v $PWD/..:/loc -v $GHP:/ghp continuumio/miniconda3 bash --login /loc/scripts/publish_website.sh + +# (3) Choose a commit message, commit and push: +# cd $GHP && git add . +# git commit -m 'Update latest version of site' +# git push + +set -e + +conda create -y -n myenv python=3.7 nodejs + +# Note: Using bash --login together with the continuumio/miniconda3 image +# is what lets conda activate work so smoothly. + +conda activate myenv +pip install nbformat==4.4.0 nbconvert==5.3.1 ipywidgets==7.5.1 tornado==4.2 bs4 notebook==5.7.12 'mistune<2' +npm install --global yarn + +cd /loc +bash scripts/build_website.sh -b + +rm -rf /ghp/* +echo "pytorch3d.org" > /ghp/CNAME +mv /loc/website/build/pytorch3d/* /ghp/ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/__init__.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..2e41cd717f6a439a9c08d76a9d0e4a54e190fc5a --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/__init__.py @@ -0,0 +1,5 @@ +# 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. diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_acos_linear_extrapolation.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_acos_linear_extrapolation.py new file mode 100644 index 0000000000000000000000000000000000000000..4cfd3fa1262dcbfce77b3f138c089520fdf23d42 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_acos_linear_extrapolation.py @@ -0,0 +1,27 @@ +# 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. + +from fvcore.common.benchmark import benchmark +from tests.test_acos_linear_extrapolation import TestAcosLinearExtrapolation + + +def bm_acos_linear_extrapolation() -> None: + kwargs_list = [ + {"batch_size": 1}, + {"batch_size": 100}, + {"batch_size": 10000}, + {"batch_size": 1000000}, + ] + benchmark( + TestAcosLinearExtrapolation.acos_linear_extrapolation, + "ACOS_LINEAR_EXTRAPOLATION", + kwargs_list, + warmup_iters=1, + ) + + +if __name__ == "__main__": + bm_acos_linear_extrapolation() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_ball_query.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_ball_query.py new file mode 100644 index 0000000000000000000000000000000000000000..73aefd0a4a562722957999828635c4b8d7a4fca0 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_ball_query.py @@ -0,0 +1,40 @@ +# 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. + +from itertools import product + +from fvcore.common.benchmark import benchmark +from tests.test_ball_query import TestBallQuery + + +def bm_ball_query() -> None: + + backends = ["cpu", "cuda:0"] + + kwargs_list = [] + Ns = [32] + P1s = [256] + P2s = [128, 512] + Ds = [3, 10] + Ks = [3, 24, 100] + Rs = [0.1, 0.2, 5] + test_cases = product(Ns, P1s, P2s, Ds, Ks, Rs, backends) + for case in test_cases: + N, P1, P2, D, K, R, b = case + kwargs_list.append( + {"N": N, "P1": P1, "P2": P2, "D": D, "K": K, "radius": R, "device": b} + ) + + benchmark( + TestBallQuery.ball_query_square, "BALLQUERY_SQUARE", kwargs_list, warmup_iters=1 + ) + benchmark( + TestBallQuery.ball_query_ragged, "BALLQUERY_RAGGED", kwargs_list, warmup_iters=1 + ) + + +if __name__ == "__main__": + bm_ball_query() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_barycentric_clipping.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_barycentric_clipping.py new file mode 100644 index 0000000000000000000000000000000000000000..289233ac08cc748aeafc1cfd721077ce81bfb1f2 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_barycentric_clipping.py @@ -0,0 +1,120 @@ +# 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. + +from itertools import product + +import torch +from fvcore.common.benchmark import benchmark +from pytorch3d.renderer.cameras import FoVPerspectiveCameras, look_at_view_transform +from pytorch3d.renderer.mesh.rasterizer import ( + Fragments, + MeshRasterizer, + RasterizationSettings, +) +from pytorch3d.renderer.mesh.utils import ( + _clip_barycentric_coordinates, + _interpolate_zbuf, +) +from pytorch3d.utils.ico_sphere import ico_sphere + + +def baryclip_cuda( + num_meshes: int = 8, + ico_level: int = 5, + image_size: int = 64, + faces_per_pixel: int = 50, + device="cuda", +): + # Init meshes + sphere_meshes = ico_sphere(ico_level, device).extend(num_meshes) + # Init transform + R, T = look_at_view_transform(1.0, 0.0, 0.0) + cameras = FoVPerspectiveCameras(device=device, R=R, T=T) + # Init rasterizer + raster_settings = RasterizationSettings( + image_size=image_size, + blur_radius=1e-4, + faces_per_pixel=faces_per_pixel, + clip_barycentric_coords=True, + ) + rasterizer = MeshRasterizer(cameras=cameras, raster_settings=raster_settings) + + torch.cuda.synchronize() + + def raster_fn(): + rasterizer(sphere_meshes) + torch.cuda.synchronize() + + return raster_fn + + +def baryclip_pytorch( + num_meshes: int = 8, + ico_level: int = 5, + image_size: int = 64, + faces_per_pixel: int = 50, + device="cuda", +): + # Init meshes + sphere_meshes = ico_sphere(ico_level, device).extend(num_meshes) + # Init transform + R, T = look_at_view_transform(1.0, 0.0, 0.0) + cameras = FoVPerspectiveCameras(device=device, R=R, T=T) + # Init rasterizer + raster_settings = RasterizationSettings( + image_size=image_size, + blur_radius=1e-4, + faces_per_pixel=faces_per_pixel, + clip_barycentric_coords=False, + ) + rasterizer = MeshRasterizer(cameras=cameras, raster_settings=raster_settings) + + torch.cuda.synchronize() + + def raster_fn(): + fragments = rasterizer(sphere_meshes) + + # Clip bary and reinterpolate + clipped_bary_coords = _clip_barycentric_coordinates(fragments.bary_coords) + clipped_zbuf = _interpolate_zbuf( + fragments.pix_to_face, clipped_bary_coords, sphere_meshes + ) + fragments = Fragments( + bary_coords=clipped_bary_coords, + zbuf=clipped_zbuf, + dists=fragments.dists, + pix_to_face=fragments.pix_to_face, + ) + torch.cuda.synchronize() + + return raster_fn + + +def bm_barycentric_clip() -> None: + if torch.cuda.is_available(): + kwargs_list = [] + num_meshes = [1, 8] + ico_level = [0, 4] + image_size = [64, 128, 256] + faces_per_pixel = [10, 75, 100] + test_cases = product(num_meshes, ico_level, image_size, faces_per_pixel) + for case in test_cases: + n, ic, im, nf = case + kwargs_list.append( + { + "num_meshes": n, + "ico_level": ic, + "image_size": im, + "faces_per_pixel": nf, + } + ) + + benchmark(baryclip_cuda, "BARY_CLIP_CUDA", kwargs_list, warmup_iters=1) + benchmark(baryclip_pytorch, "BARY_CLIP_PYTORCH", kwargs_list, warmup_iters=1) + + +if __name__ == "__main__": + bm_barycentric_clip() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_blending.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_blending.py new file mode 100644 index 0000000000000000000000000000000000000000..6a404233c46182a580d26f8c195118be8ae5458d --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_blending.py @@ -0,0 +1,74 @@ +# 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. + + +from itertools import product + +from fvcore.common.benchmark import benchmark +from tests.test_blending import TestBlending + + +def bm_blending() -> None: + devices = ["cuda"] + kwargs_list = [] + num_meshes = [8] + image_size = [64, 128, 256] + faces_per_pixel = [2, 50, 100] + backend = ["pytorch", "custom"] + test_cases = product(num_meshes, image_size, faces_per_pixel, devices, backend) + + for case in test_cases: + n, s, k, d, b = case + kwargs_list.append( + { + "num_meshes": n, + "image_size": s, + "faces_per_pixel": k, + "device": d, + "backend": b, + } + ) + + benchmark( + TestBlending.bm_sigmoid_alpha_blending, + "SIGMOID_ALPHA_BLENDING_PYTORCH", + kwargs_list, + warmup_iters=1, + ) + + kwargs_list = [case for case in kwargs_list if case["backend"] == "pytorch"] + benchmark( + TestBlending.bm_softmax_blending, + "SOFTMAX_BLENDING_PYTORCH", + kwargs_list, + warmup_iters=1, + ) + + kwargs_list = [] + faces_per_pixel = [2, 10] + backend = ["pytorch"] + test_cases = product(num_meshes, image_size, faces_per_pixel, devices, backend) + for case in test_cases: + n, s, k, d, b = case + kwargs_list.append( + { + "num_meshes": n, + "image_size": s, + "faces_per_pixel": k, + "device": d, + "backend": b, + } + ) + benchmark( + TestBlending.bm_splatter_blending, + "SPLATTER_BLENDING_PYTORCH", + kwargs_list, + warmup_iters=1, + ) + + +if __name__ == "__main__": + bm_blending() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_cameras.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_cameras.py new file mode 100644 index 0000000000000000000000000000000000000000..8cf6bf221c99a8f9c7e42b36aaf76ab1ec7bee9d --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_cameras.py @@ -0,0 +1,59 @@ +# 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. + +import itertools + +from fvcore.common.benchmark import benchmark +from tests.test_cameras import TestCamerasCommon + + +def _setUp(): + case_grid = { + "cam_type": [ + "OpenGLOrthographicCameras", + "OpenGLPerspectiveCameras", + "SfMOrthographicCameras", + "SfMPerspectiveCameras", + "FoVOrthographicCameras", + "FoVPerspectiveCameras", + "OrthographicCameras", + "PerspectiveCameras", + "FishEyeCameras", + ], + "batch_size": [1, 10], + "num_points": [10, 100], + "device": ["cpu", "cuda:0"], + } + test_cases = itertools.product(*case_grid.values()) + kwargs_list = [dict(zip(case_grid.keys(), case)) for case in test_cases] + return kwargs_list + + +def _bm_cameras_project() -> None: + kwargs_list = _setUp() + benchmark( + TestCamerasCommon.transform_points, + "TEST_TRANSFORM_POINTS", + kwargs_list, + ) + + +def _bm_cameras_unproject() -> None: + kwargs_list = _setUp() + benchmark( + TestCamerasCommon.unproject_points, + "TEST_UNPROJECT_POINTS", + kwargs_list, + ) + + +def bm_cameras() -> None: + _bm_cameras_project() + _bm_cameras_unproject() + + +if __name__ == "__main__": + bm_cameras() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_cameras_alignment.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_cameras_alignment.py new file mode 100644 index 0000000000000000000000000000000000000000..22dd1570f88fdeca1da9fad027532bed98bbc407 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_cameras_alignment.py @@ -0,0 +1,32 @@ +# 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. + +import itertools + +from fvcore.common.benchmark import benchmark +from tests.test_cameras_alignment import TestCamerasAlignment + + +def bm_cameras_alignment() -> None: + + case_grid = { + "batch_size": [10, 100, 1000], + "mode": ["centers", "extrinsics"], + "estimate_scale": [False, True], + } + test_cases = itertools.product(*case_grid.values()) + kwargs_list = [dict(zip(case_grid.keys(), case)) for case in test_cases] + + benchmark( + TestCamerasAlignment.corresponding_cameras_alignment, + "CORRESPONDING_CAMERAS_ALIGNMENT", + kwargs_list, + warmup_iters=1, + ) + + +if __name__ == "__main__": + bm_cameras_alignment() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_chamfer.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_chamfer.py new file mode 100644 index 0000000000000000000000000000000000000000..81944c477cc7b87abcf60b93a3cc5cadde5a1355 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_chamfer.py @@ -0,0 +1,65 @@ +# 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. + +from itertools import product + +import torch +from fvcore.common.benchmark import benchmark +from tests.test_chamfer import TestChamfer + + +def bm_chamfer() -> None: + # Currently disabled. + return + devices = ["cpu"] + if torch.cuda.is_available(): + devices.append("cuda:0") + + kwargs_list_naive = [] + batch_size = [1, 32] + return_normals = [True, False] + test_cases = product(batch_size, return_normals, devices) + + for case in test_cases: + b, n, d = case + kwargs_list_naive.append( + {"batch_size": b, "P1": 32, "P2": 64, "return_normals": n, "device": d} + ) + + benchmark( + TestChamfer.chamfer_naive_with_init, + "CHAMFER_NAIVE", + kwargs_list_naive, + warmup_iters=1, + ) + + if torch.cuda.is_available(): + device = "cuda:0" + kwargs_list = [] + batch_size = [1, 32] + P1 = [32, 1000, 10000] + P2 = [64, 3000, 30000] + return_normals = [True, False] + homogeneous = [True, False] + test_cases = product(batch_size, P1, P2, return_normals, homogeneous) + + for case in test_cases: + b, p1, p2, n, h = case + kwargs_list.append( + { + "batch_size": b, + "P1": p1, + "P2": p2, + "return_normals": n, + "homogeneous": h, + "device": device, + } + ) + benchmark(TestChamfer.chamfer_with_init, "CHAMFER", kwargs_list, warmup_iters=1) + + +if __name__ == "__main__": + bm_chamfer() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_cubify.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_cubify.py new file mode 100644 index 0000000000000000000000000000000000000000..37b18a5f54db09c37da037b878af14b1339d106b --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_cubify.py @@ -0,0 +1,21 @@ +# 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. + +from fvcore.common.benchmark import benchmark +from tests.test_cubify import TestCubify + + +def bm_cubify() -> None: + kwargs_list = [ + {"batch_size": 32, "V": 16}, + {"batch_size": 64, "V": 16}, + {"batch_size": 16, "V": 32}, + ] + benchmark(TestCubify.cubify_with_init, "CUBIFY", kwargs_list, warmup_iters=1) + + +if __name__ == "__main__": + bm_cubify() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_face_areas_normals.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_face_areas_normals.py new file mode 100644 index 0000000000000000000000000000000000000000..970a4de30d761704648482d6cd48e6eb47287087 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_face_areas_normals.py @@ -0,0 +1,47 @@ +# 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. + + +from itertools import product + +import torch +from fvcore.common.benchmark import benchmark +from tests.test_face_areas_normals import TestFaceAreasNormals + + +def bm_face_areas_normals() -> None: + kwargs_list = [] + backend = ["cpu"] + if torch.cuda.is_available(): + backend.append("cuda:0") + + num_meshes = [2, 10, 32] + num_verts = [100, 1000] + num_faces = [300, 3000] + + test_cases = product(num_meshes, num_verts, num_faces, backend) + for case in test_cases: + n, v, f, d = case + kwargs_list.append( + {"num_meshes": n, "num_verts": v, "num_faces": f, "device": d} + ) + benchmark( + TestFaceAreasNormals.face_areas_normals_with_init, + "FACE_AREAS_NORMALS", + kwargs_list, + warmup_iters=1, + ) + + benchmark( + TestFaceAreasNormals.face_areas_normals_with_init_torch, + "FACE_AREAS_NORMALS_TORCH", + kwargs_list, + warmup_iters=1, + ) + + +if __name__ == "__main__": + bm_face_areas_normals() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_graph_conv.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_graph_conv.py new file mode 100644 index 0000000000000000000000000000000000000000..4276f23d2392523b8851cef0ea09668b84712dbe --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_graph_conv.py @@ -0,0 +1,50 @@ +# 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. + + +from itertools import product + +import torch +from fvcore.common.benchmark import benchmark +from tests.test_graph_conv import TestGraphConv + + +def bm_graph_conv() -> None: + backends = ["cpu"] + if torch.cuda.is_available(): + backends.append("cuda") + + kwargs_list = [] + gconv_dim = [128, 256] + num_meshes = [32, 64] + num_verts = [100] + num_faces = [1000] + directed = [False, True] + test_cases = product( + gconv_dim, num_meshes, num_verts, num_faces, directed, backends + ) + for case in test_cases: + g, n, v, f, d, b = case + kwargs_list.append( + { + "gconv_dim": g, + "num_meshes": n, + "num_verts": v, + "num_faces": f, + "directed": d, + "backend": b, + } + ) + benchmark( + TestGraphConv.graph_conv_forward_backward, + "GRAPH CONV", + kwargs_list, + warmup_iters=1, + ) + + +if __name__ == "__main__": + bm_graph_conv() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_interpolate_face_attributes.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_interpolate_face_attributes.py new file mode 100644 index 0000000000000000000000000000000000000000..bc56f4293d416abbd8c76c361a2cd99d9c906b27 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_interpolate_face_attributes.py @@ -0,0 +1,84 @@ +# 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. + +from itertools import product + +import torch +from fvcore.common.benchmark import benchmark +from pytorch3d.ops.interp_face_attrs import ( + interpolate_face_attributes, + interpolate_face_attributes_python, +) + + +def _generate_data(N, S, K, F, D, device, requires_grad=False): + pix_to_face = torch.randint(-10, F, (N, S, S, K), device=device) + barycentric_coords = torch.randn( + N, S, S, K, 3, device=device, requires_grad=requires_grad + ) + face_attrs = torch.randn(F, 3, D, device=device, requires_grad=requires_grad) + grad_pix_attrs = torch.randn(N, S, S, K, D, device=device) + return pix_to_face, barycentric_coords, face_attrs, grad_pix_attrs + + +def _bm_forward(N, S, F, K, D, impl): + # The runtime depends on the values of pix_to_face. So for proper + # benchmarking we should probably take the average of multiple + # values of pix to face. But this doesn't easily fit into fvcore + # benchmarking, so instead we'll just set a manual seed to make sure + # that different impls will use the same data. + torch.manual_seed(0) + device = torch.device("cuda") + data = _generate_data(N, S, K, F, D, device, requires_grad=False) + args = data[:3] + torch.cuda.synchronize() + if impl == "cuda": + fun = interpolate_face_attributes + elif impl == "python": + fun = interpolate_face_attributes_python + return lambda: fun(*args) + + +def _bm_forward_backward(N, S, F, K, D, impl): + torch.manual_seed(0) + device = torch.device("cuda") + data = _generate_data(N, S, K, F, D, device, requires_grad=True) + args, grad = data[:3], data[3] + torch.cuda.synchronize() + if impl == "cuda": + fun = interpolate_face_attributes + elif impl == "python": + fun = interpolate_face_attributes_python + + def run(): + out = fun(*args) + out.backward(gradient=grad) + + return run + + +def bm_interpolate_face_attribues() -> None: + # For now only benchmark on GPU + if not torch.cuda.is_available(): + return + + Ns = [1, 4] + Ss = [128] + Ks = [1, 10, 40] + Fs = [5000] + Ds = [1, 3, 16] + impls = ["python", "cuda"] + test_cases = product(Ns, Ss, Ks, Fs, Ds, impls) + kwargs_list = [] + for case in test_cases: + N, S, K, F, D, impl = case + kwargs_list.append({"N": N, "S": S, "K": K, "F": F, "D": D, "impl": impl}) + benchmark(_bm_forward, "FORWARD", kwargs_list, warmup_iters=3) + benchmark(_bm_forward_backward, "FORWARD+BACKWARD", kwargs_list, warmup_iters=3) + + +if __name__ == "__main__": + bm_interpolate_face_attribues() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_iou_box3d.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_iou_box3d.py new file mode 100644 index 0000000000000000000000000000000000000000..152e36ea78862faab7acd73968613e1e5cb0a033 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_iou_box3d.py @@ -0,0 +1,54 @@ +# 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. + +from itertools import product + +from fvcore.common.benchmark import benchmark +from tests.test_iou_box3d import TestIoU3D + + +def bm_iou_box3d() -> None: + # Realistic use cases + N = [30, 100] + M = [5, 10, 100] + kwargs_list = [] + test_cases = product(N, M) + for case in test_cases: + n, m = case + kwargs_list.append({"N": n, "M": m, "device": "cuda:0"}) + benchmark(TestIoU3D.iou, "3D_IOU", kwargs_list, warmup_iters=1) + + # Comparison of C++/CUDA + kwargs_list = [] + N = [1, 4, 8, 16] + devices = ["cpu", "cuda:0"] + test_cases = product(N, N, devices) + for case in test_cases: + n, m, d = case + kwargs_list.append({"N": n, "M": m, "device": d}) + benchmark(TestIoU3D.iou, "3D_IOU", kwargs_list, warmup_iters=1) + + # Naive PyTorch + N = [1, 4] + kwargs_list = [] + test_cases = product(N, N) + for case in test_cases: + n, m = case + kwargs_list.append({"N": n, "M": m, "device": "cuda:0"}) + benchmark(TestIoU3D.iou_naive, "3D_IOU_NAIVE", kwargs_list, warmup_iters=1) + + # Sampling based method + num_samples = [2000, 5000] + kwargs_list = [] + test_cases = product(N, N, num_samples) + for case in test_cases: + n, m, s = case + kwargs_list.append({"N": n, "M": m, "num_samples": s, "device": "cuda:0"}) + benchmark(TestIoU3D.iou_sampling, "3D_IOU_SAMPLING", kwargs_list, warmup_iters=1) + + +if __name__ == "__main__": + bm_iou_box3d() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_knn.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_knn.py new file mode 100644 index 0000000000000000000000000000000000000000..f6ffa5e857f0dd9eb5c28cc71c655e1d1fe5c9d6 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_knn.py @@ -0,0 +1,34 @@ +# 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. + +from itertools import product + +from fvcore.common.benchmark import benchmark +from tests.test_knn import TestKNN + + +def bm_knn() -> None: + + backends = ["cpu", "cuda:0"] + + kwargs_list = [] + Ns = [32] + P1s = [256] + P2s = [128, 512] + Ds = [3] + Ks = [24] + test_cases = product(Ns, P1s, P2s, Ds, Ks, backends) + for case in test_cases: + N, P1, P2, D, K, b = case + kwargs_list.append({"N": N, "P1": P1, "P2": P2, "D": D, "K": K, "device": b}) + + benchmark(TestKNN.knn_square, "KNN_SQUARE", kwargs_list, warmup_iters=1) + + benchmark(TestKNN.knn_ragged, "KNN_RAGGED", kwargs_list, warmup_iters=1) + + +if __name__ == "__main__": + bm_knn() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_lighting.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_lighting.py new file mode 100644 index 0000000000000000000000000000000000000000..b5c70b63f9e98bec0fdec265169f2b0e12afbccf --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_lighting.py @@ -0,0 +1,55 @@ +# 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. + +from itertools import product + +import torch +from fvcore.common.benchmark import benchmark +from pytorch3d.renderer.lighting import diffuse, specular + + +def _bm_diffuse_cuda_with_init(N, S, K): + device = torch.device("cuda") + normals = torch.randn(N, S, S, K, 3, device=device) + color = torch.randn(1, 3, device=device) + direction = torch.randn(N, S, S, K, 3, device=device) + args = (normals, color, direction) + torch.cuda.synchronize() + return lambda: diffuse(*args) + + +def _bm_specular_cuda_with_init(N, S, K): + device = torch.device("cuda") + points = torch.randn(N, S, S, K, 3, device=device) + normals = torch.randn(N, S, S, K, 3, device=device) + direction = torch.randn(N, S, S, K, 3, device=device) + color = torch.randn(1, 3, device=device) + camera_position = torch.randn(N, 3, device=device) + shininess = torch.randn(N, device=device) + args = (points, normals, direction, color, camera_position, shininess) + torch.cuda.synchronize() + return lambda: specular(*args) + + +def bm_lighting() -> None: + # For now only benchmark lighting on GPU + if not torch.cuda.is_available(): + return + + kwargs_list = [] + Ns = [1, 8] + Ss = [128, 256] + Ks = [1, 10, 80] + test_cases = product(Ns, Ss, Ks) + for case in test_cases: + N, S, K = case + kwargs_list.append({"N": N, "S": S, "K": K}) + benchmark(_bm_diffuse_cuda_with_init, "DIFFUSE", kwargs_list, warmup_iters=3) + benchmark(_bm_specular_cuda_with_init, "SPECULAR", kwargs_list, warmup_iters=3) + + +if __name__ == "__main__": + bm_lighting() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_main.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_main.py new file mode 100644 index 0000000000000000000000000000000000000000..ce10012e2f559eaadf053b29f06df8b3e1e00c2f --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_main.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +# 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. + +import glob +import os +import subprocess +import sys +from os.path import dirname, isfile, join + + +def main() -> None: + # pyre-ignore[16] + if len(sys.argv) > 1: + # Parse from flags. + # pyre-ignore[16] + file_names = [ + join(dirname(__file__), n) for n in sys.argv if n.startswith("bm_") + ] + else: + # Get all the benchmark files (starting with "bm_"). + bm_files = glob.glob(join(dirname(__file__), "bm_*.py")) + file_names = sorted( + f for f in bm_files if isfile(f) and not f.endswith("bm_main.py") + ) + + # Forward all important path information to the subprocesses through the + # environment. + os.environ["PATH"] = sys.path[0] + ":" + os.environ.get("PATH", "") + os.environ["LD_LIBRARY_PATH"] = ( + sys.path[0] + ":" + os.environ.get("LD_LIBRARY_PATH", "") + ) + os.environ["PYTHONPATH"] = ":".join(sys.path) + for file_name in file_names: + subprocess.check_call([sys.executable, file_name]) + + +if __name__ == "__main__": + main() # pragma: no cover diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_marching_cubes.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_marching_cubes.py new file mode 100644 index 0000000000000000000000000000000000000000..625728310174eb5c2f4ad488d3e1705b8565ac98 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_marching_cubes.py @@ -0,0 +1,35 @@ +# 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. + +import itertools + +from fvcore.common.benchmark import benchmark +from tests.test_marching_cubes import TestMarchingCubes + + +def bm_marching_cubes() -> None: + case_grid = { + "algo_type": [ + "naive", + "extension", + ], + "batch_size": [1, 2], + "V": [5, 10, 20, 100, 512], + "device": ["cpu", "cuda:0"], + } + test_cases = itertools.product(*case_grid.values()) + kwargs_list = [dict(zip(case_grid.keys(), case)) for case in test_cases] + + benchmark( + TestMarchingCubes.marching_cubes_with_init, + "MARCHING_CUBES", + kwargs_list, + warmup_iters=1, + ) + + +if __name__ == "__main__": + bm_marching_cubes() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_mesh_edge_loss.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_mesh_edge_loss.py new file mode 100644 index 0000000000000000000000000000000000000000..3cf14b174ea7fd3b8ef9a7cb45932a744b485e3e --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_mesh_edge_loss.py @@ -0,0 +1,29 @@ +# 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. + + +from itertools import product + +from fvcore.common.benchmark import benchmark +from tests.test_mesh_edge_loss import TestMeshEdgeLoss + + +def bm_mesh_edge_loss() -> None: + kwargs_list = [] + num_meshes = [1, 16, 32] + max_v = [100, 10000] + max_f = [300, 30000] + test_cases = product(num_meshes, max_v, max_f) + for case in test_cases: + n, v, f = case + kwargs_list.append({"num_meshes": n, "max_v": v, "max_f": f}) + benchmark( + TestMeshEdgeLoss.mesh_edge_loss, "MESH_EDGE_LOSS", kwargs_list, warmup_iters=1 + ) + + +if __name__ == "__main__": + bm_mesh_edge_loss() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_mesh_io.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_mesh_io.py new file mode 100644 index 0000000000000000000000000000000000000000..37155fae34691442d4f1acb0e47a1563f0746ba6 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_mesh_io.py @@ -0,0 +1,105 @@ +# 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. + +from itertools import product + +from fvcore.common.benchmark import benchmark +from tests.test_io_obj import TestMeshObjIO +from tests.test_io_ply import TestMeshPlyIO + + +def bm_save_load() -> None: + simple_kwargs_list = [ + {"V": 100, "F": 200}, + {"V": 1000, "F": 2000}, + {"V": 10000, "F": 20000}, + ] + benchmark( + TestMeshObjIO.bm_load_simple_obj_with_init, + "LOAD_SIMPLE_OBJ", + simple_kwargs_list, + warmup_iters=1, + ) + benchmark( + TestMeshObjIO.bm_save_simple_obj_with_init, + "SAVE_SIMPLE_OBJ", + simple_kwargs_list, + warmup_iters=1, + ) + benchmark( + TestMeshPlyIO.bm_load_simple_ply_with_init, + "LOAD_SIMPLE_PLY", + simple_kwargs_list, + warmup_iters=1, + ) + benchmark( + TestMeshPlyIO.bm_save_simple_ply_with_init, + "SAVE_SIMPLE_PLY", + simple_kwargs_list, + warmup_iters=1, + ) + + complex_kwargs_list = [{"N": 8}, {"N": 32}, {"N": 128}] + benchmark( + TestMeshObjIO.bm_load_complex_obj, + "LOAD_COMPLEX_OBJ", + complex_kwargs_list, + warmup_iters=1, + ) + benchmark( + TestMeshObjIO.bm_save_complex_obj, + "SAVE_COMPLEX_OBJ", + complex_kwargs_list, + warmup_iters=1, + ) + benchmark( + TestMeshPlyIO.bm_load_complex_ply, + "LOAD_COMPLEX_PLY", + complex_kwargs_list, + warmup_iters=1, + ) + benchmark( + TestMeshPlyIO.bm_save_complex_ply, + "SAVE_COMPLEX_PLY", + complex_kwargs_list, + warmup_iters=1, + ) + + # Texture loading benchmarks + kwargs_list = [{"R": 2}, {"R": 4}, {"R": 10}, {"R": 15}, {"R": 20}] + benchmark( + TestMeshObjIO.bm_load_texture_atlas, + "PYTORCH3D_TEXTURE_ATLAS", + kwargs_list, + warmup_iters=1, + ) + + kwargs_list = [] + S = [64, 256, 1024] + F = [100, 1000, 10000] + R = [5, 10, 20] + test_cases = product(S, F, R) + + for case in test_cases: + s, f, r = case + kwargs_list.append({"S": s, "F": f, "R": r}) + + benchmark( + TestMeshObjIO.bm_bilinear_sampling_vectorized, + "BILINEAR_VECTORIZED", + kwargs_list, + warmup_iters=1, + ) + benchmark( + TestMeshObjIO.bm_bilinear_sampling_grid_sample, + "BILINEAR_GRID_SAMPLE", + kwargs_list, + warmup_iters=1, + ) + + +if __name__ == "__main__": + bm_save_load() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_mesh_laplacian_smoothing.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_mesh_laplacian_smoothing.py new file mode 100644 index 0000000000000000000000000000000000000000..440aafbae75bc917aaea13f7e096d3a5fb73a92c --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_mesh_laplacian_smoothing.py @@ -0,0 +1,40 @@ +# 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. + + +from itertools import product + +import torch +from fvcore.common.benchmark import benchmark +from tests.test_mesh_laplacian_smoothing import TestLaplacianSmoothing + + +def bm_mesh_laplacian_smoothing() -> None: + devices = ["cpu"] + if torch.cuda.is_available(): + devices.append("cuda") + + kwargs_list = [] + num_meshes = [2, 10, 32] + num_verts = [100, 1000] + num_faces = [300, 3000] + test_cases = product(num_meshes, num_verts, num_faces, devices) + for case in test_cases: + n, v, f, d = case + kwargs_list.append( + {"num_meshes": n, "num_verts": v, "num_faces": f, "device": d} + ) + + benchmark( + TestLaplacianSmoothing.laplacian_smoothing_with_init, + "MESH_LAPLACIAN_SMOOTHING", + kwargs_list, + warmup_iters=1, + ) + + +if __name__ == "__main__": + bm_mesh_laplacian_smoothing() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_mesh_normal_consistency.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_mesh_normal_consistency.py new file mode 100644 index 0000000000000000000000000000000000000000..11d1be46c19c0e923c60f7165ac8d032680f834c --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_mesh_normal_consistency.py @@ -0,0 +1,37 @@ +# 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. + + +from itertools import product + +import torch +from fvcore.common.benchmark import benchmark +from tests.test_mesh_normal_consistency import TestMeshNormalConsistency + + +def bm_mesh_normal_consistency() -> None: + devices = ["cpu"] + if torch.cuda.is_available(): + devices.append("cuda") + + kwargs_list = [] + num_meshes = [16, 32, 64] + levels = [2, 3] + test_cases = product(num_meshes, levels, devices) + for case in test_cases: + n, l, d = case + kwargs_list.append({"num_meshes": n, "level": l, "device": d}) + + benchmark( + TestMeshNormalConsistency.mesh_normal_consistency_with_ico, + "MESH_NORMAL_CONSISTENCY_ICO", + kwargs_list, + warmup_iters=1, + ) + + +if __name__ == "__main__": + bm_mesh_normal_consistency() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_mesh_rasterizer_transform.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_mesh_rasterizer_transform.py new file mode 100644 index 0000000000000000000000000000000000000000..e65c265ef6e902b51acca9a8df9a258eeb85e7e4 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_mesh_rasterizer_transform.py @@ -0,0 +1,53 @@ +# 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. + + +from itertools import product + +import torch +from fvcore.common.benchmark import benchmark +from pytorch3d.renderer.cameras import FoVPerspectiveCameras, look_at_view_transform +from pytorch3d.renderer.mesh.rasterizer import MeshRasterizer +from pytorch3d.utils.ico_sphere import ico_sphere + + +def rasterize_transform_with_init(num_meshes: int, ico_level: int = 5, device="cuda"): + # Init meshes + sphere_meshes = ico_sphere(ico_level, device).extend(num_meshes) + # Init transform + R, T = look_at_view_transform(1.0, 0.0, 0.0) + cameras = FoVPerspectiveCameras(device=device, R=R, T=T) + # Init rasterizer + rasterizer = MeshRasterizer(cameras=cameras) + + torch.cuda.synchronize() + + def raster_fn(): + rasterizer.transform(sphere_meshes) + torch.cuda.synchronize() + + return raster_fn + + +def bm_mesh_rasterizer_transform() -> None: + if torch.cuda.is_available(): + kwargs_list = [] + num_meshes = [1, 8] + ico_level = [0, 1, 3, 4] + test_cases = product(num_meshes, ico_level) + for case in test_cases: + n, ic = case + kwargs_list.append({"num_meshes": n, "ico_level": ic}) + benchmark( + rasterize_transform_with_init, + "MESH_RASTERIZER", + kwargs_list, + warmup_iters=1, + ) + + +if __name__ == "__main__": + bm_mesh_rasterizer_transform() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_meshes.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_meshes.py new file mode 100644 index 0000000000000000000000000000000000000000..1d0b63f2ba1f0b339780238e029b306fcaea6847 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_meshes.py @@ -0,0 +1,43 @@ +# 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. + + +from itertools import product + +import torch +from fvcore.common.benchmark import benchmark +from tests.test_meshes import TestMeshes + + +def bm_compute_packed_padded_meshes() -> None: + devices = ["cpu"] + if torch.cuda.is_available(): + devices.append("cuda") + + kwargs_list = [] + num_meshes = [32, 128] + max_v = [100, 1000, 10000] + max_f = [300, 3000, 30000] + test_cases = product(num_meshes, max_v, max_f, devices) + for case in test_cases: + n, v, f, d = case + kwargs_list.append({"num_meshes": n, "max_v": v, "max_f": f, "device": d}) + benchmark( + TestMeshes.compute_packed_with_init, + "COMPUTE_PACKED", + kwargs_list, + warmup_iters=1, + ) + benchmark( + TestMeshes.compute_padded_with_init, + "COMPUTE_PADDED", + kwargs_list, + warmup_iters=1, + ) + + +if __name__ == "__main__": + bm_compute_packed_padded_meshes() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_packed_to_padded.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_packed_to_padded.py new file mode 100644 index 0000000000000000000000000000000000000000..e61f36daa2cf8a912bfa8d09915ad16f36b4f23b --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_packed_to_padded.py @@ -0,0 +1,48 @@ +# 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. + + +from itertools import product + +import torch +from fvcore.common.benchmark import benchmark +from tests.test_packed_to_padded import TestPackedToPadded + + +def bm_packed_to_padded() -> None: + kwargs_list = [] + backend = ["cpu"] + if torch.cuda.is_available(): + backend.append("cuda:0") + + num_meshes = [2, 10, 32] + num_verts = [100, 1000] + num_faces = [300, 3000] + num_ds = [0, 1, 16] + + test_cases = product(num_meshes, num_verts, num_faces, num_ds, backend) + for case in test_cases: + n, v, f, d, b = case + kwargs_list.append( + {"num_meshes": n, "num_verts": v, "num_faces": f, "num_d": d, "device": b} + ) + benchmark( + TestPackedToPadded.packed_to_padded_with_init, + "PACKED_TO_PADDED", + kwargs_list, + warmup_iters=1, + ) + + benchmark( + TestPackedToPadded.packed_to_padded_with_init_torch, + "PACKED_TO_PADDED_TORCH", + kwargs_list, + warmup_iters=1, + ) + + +if __name__ == "__main__": + bm_packed_to_padded() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_perspective_n_points.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_perspective_n_points.py new file mode 100644 index 0000000000000000000000000000000000000000..672e530af9b61f5f032581856fbacae788872fe5 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_perspective_n_points.py @@ -0,0 +1,33 @@ +# 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. + +import itertools + +from fvcore.common.benchmark import benchmark +from tests.test_perspective_n_points import TestPerspectiveNPoints + + +def bm_perspective_n_points() -> None: + case_grid = { + "batch_size": [1, 10, 100], + "num_pts": [100, 100000], + "skip_q": [False, True], + } + + test_cases = itertools.product(*case_grid.values()) + kwargs_list = [dict(zip(case_grid.keys(), case)) for case in test_cases] + + test = TestPerspectiveNPoints() + benchmark( + test.case_with_gaussian_points, + "PerspectiveNPoints", + kwargs_list, + warmup_iters=1, + ) + + +if __name__ == "__main__": + bm_perspective_n_points() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_point_mesh_distance.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_point_mesh_distance.py new file mode 100644 index 0000000000000000000000000000000000000000..bc1da12883da43fa792ce14d561ae6af072b7a70 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_point_mesh_distance.py @@ -0,0 +1,44 @@ +# 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. + + +from itertools import product + +from fvcore.common.benchmark import benchmark +from tests.test_point_mesh_distance import TestPointMeshDistance + + +def bm_point_mesh_distance() -> None: + + backend = ["cuda:0"] + + kwargs_list = [] + batch_size = [4, 8, 16] + num_verts = [100, 1000] + num_faces = [300, 3000] + num_points = [5000, 10000] + test_cases = product(batch_size, num_verts, num_faces, num_points, backend) + for case in test_cases: + n, v, f, p, b = case + kwargs_list.append({"N": n, "V": v, "F": f, "P": p, "device": b}) + + benchmark( + TestPointMeshDistance.point_mesh_edge, + "POINT_MESH_EDGE", + kwargs_list, + warmup_iters=1, + ) + + benchmark( + TestPointMeshDistance.point_mesh_face, + "POINT_MESH_FACE", + kwargs_list, + warmup_iters=1, + ) + + +if __name__ == "__main__": + bm_point_mesh_distance() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_pointclouds.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_pointclouds.py new file mode 100644 index 0000000000000000000000000000000000000000..4868e6bf2aa202fb5fd77ccb21f7e4699ea49db8 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_pointclouds.py @@ -0,0 +1,38 @@ +# 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. + + +from itertools import product + +from fvcore.common.benchmark import benchmark +from tests.test_pointclouds import TestPointclouds + + +def bm_compute_packed_padded_pointclouds() -> None: + kwargs_list = [] + num_clouds = [32, 128] + max_p = [100, 10000] + feats = [1, 10, 300] + test_cases = product(num_clouds, max_p, feats) + for case in test_cases: + n, p, f = case + kwargs_list.append({"num_clouds": n, "max_p": p, "features": f}) + benchmark( + TestPointclouds.compute_packed_with_init, + "COMPUTE_PACKED", + kwargs_list, + warmup_iters=1, + ) + benchmark( + TestPointclouds.compute_padded_with_init, + "COMPUTE_PADDED", + kwargs_list, + warmup_iters=1, + ) + + +if __name__ == "__main__": + bm_compute_packed_padded_pointclouds() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_points_alignment.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_points_alignment.py new file mode 100644 index 0000000000000000000000000000000000000000..842773fb6390548b5cfcf28f6fdc0e90a4b67f05 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_points_alignment.py @@ -0,0 +1,80 @@ +# 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. + +from copy import deepcopy +from itertools import product + +from fvcore.common.benchmark import benchmark +from tests.test_points_alignment import TestCorrespondingPointsAlignment, TestICP + + +def bm_iterative_closest_point() -> None: + + case_grid = { + "batch_size": [1, 10], + "dim": [3, 20], + "n_points_X": [100, 1000], + "n_points_Y": [100, 1000], + "use_pointclouds": [False], + } + + test_args = sorted(case_grid.keys()) + test_cases = product(*case_grid.values()) + kwargs_list = [dict(zip(test_args, case)) for case in test_cases] + + # add the use_pointclouds=True test cases whenever we have dim==3 + kwargs_to_add = [] + for entry in kwargs_list: + if entry["dim"] == 3: + entry_add = deepcopy(entry) + entry_add["use_pointclouds"] = True + kwargs_to_add.append(entry_add) + kwargs_list.extend(kwargs_to_add) + + benchmark( + TestICP.iterative_closest_point, + "IterativeClosestPoint", + kwargs_list, + warmup_iters=1, + ) + + +def bm_corresponding_points_alignment() -> None: + + case_grid = { + "allow_reflection": [True, False], + "batch_size": [1, 10, 100], + "dim": [3, 20], + "estimate_scale": [True, False], + "n_points": [100, 10000], + "random_weights": [False, True], + "use_pointclouds": [False], + } + + test_args = sorted(case_grid.keys()) + test_cases = product(*case_grid.values()) + kwargs_list = [dict(zip(test_args, case)) for case in test_cases] + + # add the use_pointclouds=True test cases whenever we have dim==3 + kwargs_to_add = [] + for entry in kwargs_list: + if entry["dim"] == 3: + entry_add = deepcopy(entry) + entry_add["use_pointclouds"] = True + kwargs_to_add.append(entry_add) + kwargs_list.extend(kwargs_to_add) + + benchmark( + TestCorrespondingPointsAlignment.corresponding_points_alignment, + "CorrespodingPointsAlignment", + kwargs_list, + warmup_iters=1, + ) + + +if __name__ == "__main__": + bm_corresponding_points_alignment() + bm_iterative_closest_point() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_points_normals.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_points_normals.py new file mode 100644 index 0000000000000000000000000000000000000000..efdf9950bb134f77f2a21c8b61d8c9686cc90b22 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_points_normals.py @@ -0,0 +1,47 @@ +# 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. + +import itertools + +import torch +from fvcore.common.benchmark import benchmark +from pytorch3d.ops import estimate_pointcloud_normals +from tests.test_points_normals import TestPCLNormals + + +def to_bm(num_points, use_symeig_workaround): + device = torch.device("cuda:0") + points_padded, _normals = TestPCLNormals.init_spherical_pcl( + num_points=num_points, device=device, use_pointclouds=False + ) + torch.cuda.synchronize() + + def run(): + estimate_pointcloud_normals( + points_padded, use_symeig_workaround=use_symeig_workaround + ) + torch.cuda.synchronize() + + return run + + +def bm_points_normals() -> None: + case_grid = { + "use_symeig_workaround": [True, False], + "num_points": [3000, 6000], + } + test_cases = itertools.product(*case_grid.values()) + kwargs_list = [dict(zip(case_grid.keys(), case)) for case in test_cases] + benchmark( + to_bm, + "normals", + kwargs_list, + warmup_iters=1, + ) + + +if __name__ == "__main__": + bm_points_normals() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_points_to_volumes.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_points_to_volumes.py new file mode 100644 index 0000000000000000000000000000000000000000..7a79b1954e9a992cfb26bc045740dafcc549694f --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_points_to_volumes.py @@ -0,0 +1,33 @@ +# 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. + +import itertools + +from fvcore.common.benchmark import benchmark +from tests.test_points_to_volumes import TestPointsToVolumes + + +def bm_points_to_volumes() -> None: + case_grid = { + "device": ["cpu", "cuda:0"], + "batch_size": [10, 100], + "interp_mode": ["trilinear", "nearest"], + "volume_size": [[25, 25, 25], [101, 111, 121]], + "n_points": [1000, 10000, 100000], + } + test_cases = itertools.product(*case_grid.values()) + kwargs_list = [dict(zip(case_grid.keys(), case)) for case in test_cases] + + benchmark( + TestPointsToVolumes.add_points_to_volumes, + "ADD_POINTS_TO_VOLUMES", + kwargs_list, + warmup_iters=1, + ) + + +if __name__ == "__main__": + bm_points_to_volumes() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_pulsar.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_pulsar.py new file mode 100644 index 0000000000000000000000000000000000000000..74110ef124bf6d0ee2c1bd8f9e1979e17f47d1ce --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_pulsar.py @@ -0,0 +1,126 @@ +# 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. + +"""Test render speed.""" +import logging +import sys +from os import path + +import torch +from fvcore.common.benchmark import benchmark +from pytorch3d.renderer.points.pulsar import Renderer +from torch.autograd import Variable + + +# Making sure you can run this, even if pulsar hasn't been installed yet. +sys.path.insert(0, path.join(path.dirname(__file__), "..")) +LOGGER = logging.getLogger(__name__) + + +"""Measure the execution speed of the rendering. + +This measures a very pessimistic upper bound on speed, because synchronization +points have to be introduced in Python. On a pure PyTorch execution pipeline, +results should be significantly faster. You can get pure CUDA timings through +C++ by activating `PULSAR_TIMINGS_BATCHED_ENABLED` in the file +`pytorch3d/csrc/pulsar/logging.h` or defining it for your compiler. +""" + + +def _bm_pulsar(): + n_points = 1_000_000 + width = 1_000 + height = 1_000 + renderer = Renderer(width, height, n_points) + # 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_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, 5.0, 2.0], dtype=torch.float32 + ) + device = torch.device("cuda") + vert_pos = vert_pos.to(device) + vert_col = vert_col.to(device) + vert_rad = vert_rad.to(device) + cam_params = cam_params.to(device) + renderer = renderer.to(device) + vert_pos_var = Variable(vert_pos, requires_grad=False) + vert_col_var = Variable(vert_col, requires_grad=False) + vert_rad_var = Variable(vert_rad, requires_grad=False) + cam_params_var = Variable(cam_params, requires_grad=False) + + def bm_closure(): + renderer.forward( + vert_pos_var, + vert_col_var, + vert_rad_var, + cam_params_var, + 1.0e-1, + 45.0, + percent_allowed_difference=0.01, + ) + torch.cuda.synchronize() + + return bm_closure + + +def _bm_pulsar_backward(): + n_points = 1_000_000 + width = 1_000 + height = 1_000 + renderer = Renderer(width, height, n_points) + # 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_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, 5.0, 2.0], dtype=torch.float32 + ) + device = torch.device("cuda") + vert_pos = vert_pos.to(device) + vert_col = vert_col.to(device) + vert_rad = vert_rad.to(device) + cam_params = cam_params.to(device) + renderer = renderer.to(device) + vert_pos_var = Variable(vert_pos, requires_grad=True) + vert_col_var = Variable(vert_col, requires_grad=True) + vert_rad_var = Variable(vert_rad, requires_grad=True) + cam_params_var = Variable(cam_params, requires_grad=True) + res = renderer.forward( + vert_pos_var, + vert_col_var, + vert_rad_var, + cam_params_var, + 1.0e-1, + 45.0, + percent_allowed_difference=0.01, + ) + loss = res.sum() + + def bm_closure(): + loss.backward(retain_graph=True) + torch.cuda.synchronize() + + return bm_closure + + +def bm_pulsar() -> None: + if not torch.cuda.is_available(): + return + + benchmark(_bm_pulsar, "PULSAR_FORWARD", [{}], warmup_iters=3) + benchmark(_bm_pulsar_backward, "PULSAR_BACKWARD", [{}], warmup_iters=3) + + +if __name__ == "__main__": + bm_pulsar() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_rasterize_meshes.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_rasterize_meshes.py new file mode 100644 index 0000000000000000000000000000000000000000..0a6531a389189ad13c63d1712ef08d499ba1584c --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_rasterize_meshes.py @@ -0,0 +1,127 @@ +# 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. + +import os +from itertools import product + +import torch +from fvcore.common.benchmark import benchmark +from tests.test_rasterize_meshes import TestRasterizeMeshes + +BM_RASTERIZE_MESHES_N_THREADS = os.getenv("BM_RASTERIZE_MESHES_N_THREADS", 1) +torch.set_num_threads(int(BM_RASTERIZE_MESHES_N_THREADS)) + +# ico levels: +# 0: (12 verts, 20 faces) +# 1: (42 verts, 80 faces) +# 3: (642 verts, 1280 faces) +# 4: (2562 verts, 5120 faces) +# 5: (10242 verts, 20480 faces) +# 6: (40962 verts, 81920 faces) + + +def bm_rasterize_meshes() -> None: + kwargs_list = [ + { + "num_meshes": 1, + "ico_level": 0, + "image_size": 10, # very slow with large image size + "blur_radius": 0.0, + "faces_per_pixel": 3, + } + ] + benchmark( + TestRasterizeMeshes.rasterize_meshes_python_with_init, + "RASTERIZE_MESHES", + kwargs_list, + warmup_iters=1, + ) + + kwargs_list = [] + num_meshes = [1] + ico_level = [1] + image_size = [64, 128, 512] + blur = [1e-6] + faces_per_pixel = [3, 50] + test_cases = product(num_meshes, ico_level, image_size, blur, faces_per_pixel) + for case in test_cases: + n, ic, im, b, f = case + kwargs_list.append( + { + "num_meshes": n, + "ico_level": ic, + "image_size": im, + "blur_radius": b, + "faces_per_pixel": f, + } + ) + benchmark( + TestRasterizeMeshes.rasterize_meshes_cpu_with_init, + "RASTERIZE_MESHES", + kwargs_list, + warmup_iters=1, + ) + + if torch.cuda.is_available(): + kwargs_list = [] + num_meshes = [8, 16] + ico_level = [4, 5, 6] + # Square and non square cases + image_size = [64, 128, 512, (512, 256), (256, 512)] + blur = [1e-6] + faces_per_pixel = [40] + test_cases = product(num_meshes, ico_level, image_size, blur, faces_per_pixel) + + for case in test_cases: + n, ic, im, b, f = case + kwargs_list.append( + { + "num_meshes": n, + "ico_level": ic, + "image_size": im, + "blur_radius": b, + "faces_per_pixel": f, + } + ) + benchmark( + TestRasterizeMeshes.rasterize_meshes_cuda_with_init, + "RASTERIZE_MESHES_CUDA", + kwargs_list, + warmup_iters=1, + ) + + # Test a subset of the cases with the + # image plane intersecting the mesh. + kwargs_list = [] + num_meshes = [8, 16] + # Square and non square cases + image_size = [64, 128, 512, (512, 256), (256, 512)] + dist = [3, 0.8, 0.5] + test_cases = product(num_meshes, dist, image_size) + + for case in test_cases: + n, d, im = case + kwargs_list.append( + { + "num_meshes": n, + "ico_level": 4, + "image_size": im, + "blur_radius": 1e-6, + "faces_per_pixel": 40, + "dist": d, + } + ) + + benchmark( + TestRasterizeMeshes.bm_rasterize_meshes_with_clipping, + "RASTERIZE_MESHES_CUDA_CLIPPING", + kwargs_list, + warmup_iters=1, + ) + + +if __name__ == "__main__": + bm_rasterize_meshes() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_rasterize_points.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_rasterize_points.py new file mode 100644 index 0000000000000000000000000000000000000000..bcdd8fb08393aed7862488601725e1f5b686aaea --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_rasterize_points.py @@ -0,0 +1,105 @@ +# 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. + +from itertools import product + +import torch +from fvcore.common.benchmark import benchmark +from pytorch3d.renderer.points.rasterize_points import ( + rasterize_points, + rasterize_points_python, +) +from pytorch3d.structures.pointclouds import Pointclouds + + +def _bm_python_with_init(N, P, img_size=32, radius=0.1, pts_per_pxl=3): + torch.manual_seed(231) + points = torch.randn(N, P, 3) + pointclouds = Pointclouds(points=points) + args = (pointclouds, img_size, radius, pts_per_pxl) + return lambda: rasterize_points_python(*args) + + +def _bm_rasterize_points_with_init( + N, P, img_size=32, radius=0.1, pts_per_pxl=3, device="cpu", expand_radius=False +): + torch.manual_seed(231) + device = torch.device(device) + points = torch.randn(N, P, 3, device=device) + pointclouds = Pointclouds(points=points) + + if expand_radius: + points_padded = pointclouds.points_padded() + radius = torch.full((N, P), fill_value=radius).type_as(points_padded) + + args = (pointclouds, img_size, radius, pts_per_pxl) + if device == "cuda": + torch.cuda.synchronize(device) + + def fn(): + rasterize_points(*args) + if device == "cuda": + torch.cuda.synchronize(device) + + return fn + + +def bm_python_vs_cpu_vs_cuda() -> None: + kwargs_list = [] + num_meshes = [1] + num_points = [10000, 2000] + image_size = [128, 256] + radius = [1e-3, 0.01] + pts_per_pxl = [50, 100] + expand = [True, False] + test_cases = product( + num_meshes, num_points, image_size, radius, pts_per_pxl, expand + ) + for case in test_cases: + n, p, im, r, pts, e = case + kwargs_list.append( + { + "N": n, + "P": p, + "img_size": im, + "radius": r, + "pts_per_pxl": pts, + "device": "cpu", + "expand_radius": e, + } + ) + + benchmark( + _bm_rasterize_points_with_init, "RASTERIZE_CPU", kwargs_list, warmup_iters=1 + ) + kwargs_list += [ + {"N": 32, "P": 100000, "img_size": 128, "radius": 0.01, "pts_per_pxl": 50}, + {"N": 8, "P": 200000, "img_size": 512, "radius": 0.01, "pts_per_pxl": 50}, + {"N": 8, "P": 200000, "img_size": 256, "radius": 0.01, "pts_per_pxl": 50}, + { + "N": 8, + "P": 200000, + "img_size": (512, 256), + "radius": 0.01, + "pts_per_pxl": 50, + }, + { + "N": 8, + "P": 200000, + "img_size": (256, 512), + "radius": 0.01, + "pts_per_pxl": 50, + }, + ] + for k in kwargs_list: + k["device"] = "cuda" + benchmark( + _bm_rasterize_points_with_init, "RASTERIZE_CUDA", kwargs_list, warmup_iters=1 + ) + + +if __name__ == "__main__": + bm_python_vs_cpu_vs_cuda() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_raymarching.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_raymarching.py new file mode 100644 index 0000000000000000000000000000000000000000..b37f612734b184edd8cae93dd077ec468d05d223 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_raymarching.py @@ -0,0 +1,23 @@ +# 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. + +import itertools + +from fvcore.common.benchmark import benchmark +from pytorch3d.renderer import AbsorptionOnlyRaymarcher, EmissionAbsorptionRaymarcher +from tests.test_raymarching import TestRaymarching + + +def bm_raymarching() -> None: + case_grid = { + "raymarcher_type": [EmissionAbsorptionRaymarcher, AbsorptionOnlyRaymarcher], + "n_rays": [10, 1000, 10000], + "n_pts_per_ray": [10, 1000, 10000], + } + test_cases = itertools.product(*case_grid.values()) + kwargs_list = [dict(zip(case_grid.keys(), case)) for case in test_cases] + + benchmark(TestRaymarching.raymarcher, "RAYMARCHER", kwargs_list, warmup_iters=1) diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_raysampling.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_raysampling.py new file mode 100644 index 0000000000000000000000000000000000000000..09b0f1283e65a2788c43d8002822283d7b02e393 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_raysampling.py @@ -0,0 +1,47 @@ +# 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. + +import itertools + +from fvcore.common.benchmark import benchmark +from pytorch3d.renderer import ( + FoVOrthographicCameras, + FoVPerspectiveCameras, + MonteCarloRaysampler, + MultinomialRaysampler, + NDCMultinomialRaysampler, + OrthographicCameras, + PerspectiveCameras, +) +from tests.test_raysampling import TestRaysampling + + +def bm_raysampling() -> None: + case_grid = { + "raysampler_type": [ + MultinomialRaysampler, + NDCMultinomialRaysampler, + MonteCarloRaysampler, + ], + "camera_type": [ + PerspectiveCameras, + OrthographicCameras, + FoVPerspectiveCameras, + FoVOrthographicCameras, + ], + "batch_size": [1, 10], + "n_pts_per_ray": [10, 1000, 10000], + "image_width": [10, 300], + "image_height": [10, 300], + } + test_cases = itertools.product(*case_grid.values()) + kwargs_list = [dict(zip(case_grid.keys(), case)) for case in test_cases] + + benchmark(TestRaysampling.raysampler, "RAYSAMPLER", kwargs_list, warmup_iters=1) + + +if __name__ == "__main__": + bm_raysampling() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_render_implicit.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_render_implicit.py new file mode 100644 index 0000000000000000000000000000000000000000..af38047a2e2f9b3a88348e5e18e15286ecfa0d84 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_render_implicit.py @@ -0,0 +1,26 @@ +# 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. + +import itertools + +from fvcore.common.benchmark import benchmark +from pytorch3d.renderer import AbsorptionOnlyRaymarcher, EmissionAbsorptionRaymarcher +from tests.test_render_implicit import TestRenderImplicit + + +def bm_render_volumes() -> None: + case_grid = { + "batch_size": [1, 5], + "raymarcher_type": [EmissionAbsorptionRaymarcher, AbsorptionOnlyRaymarcher], + "n_rays_per_image": [64**2, 256**2], + "n_pts_per_ray": [16, 128], + } + test_cases = itertools.product(*case_grid.values()) + kwargs_list = [dict(zip(case_grid.keys(), case)) for case in test_cases] + + benchmark( + TestRenderImplicit.renderer, "IMPLICIT_RENDERER", kwargs_list, warmup_iters=1 + ) diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_render_volumes.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_render_volumes.py new file mode 100644 index 0000000000000000000000000000000000000000..abe76d93205d72f64d3eff1b057e5f1acbd8e281 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_render_volumes.py @@ -0,0 +1,28 @@ +# 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. + +import itertools + +from fvcore.common.benchmark import benchmark +from pytorch3d.renderer import AbsorptionOnlyRaymarcher, EmissionAbsorptionRaymarcher +from tests.test_render_volumes import TestRenderVolumes + + +def bm_render_volumes() -> None: + case_grid = { + "volume_size": [tuple([17] * 3), tuple([129] * 3)], + "batch_size": [1, 5], + "shape": ["sphere", "cube"], + "raymarcher_type": [EmissionAbsorptionRaymarcher, AbsorptionOnlyRaymarcher], + "n_rays_per_image": [64**2, 256**2], + "n_pts_per_ray": [16, 128], + } + test_cases = itertools.product(*case_grid.values()) + kwargs_list = [dict(zip(case_grid.keys(), case)) for case in test_cases] + + benchmark( + TestRenderVolumes.renderer, "VOLUME_RENDERER", kwargs_list, warmup_iters=1 + ) diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_sample_farthest_points.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_sample_farthest_points.py new file mode 100644 index 0000000000000000000000000000000000000000..1bf355ce05e3362c74b8502fe93ba0db76844a53 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_sample_farthest_points.py @@ -0,0 +1,46 @@ +# 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. + +from itertools import product + +from fvcore.common.benchmark import benchmark +from tests.test_sample_farthest_points import TestFPS + + +def bm_fps() -> None: + kwargs_list = [] + backends = ["cpu", "cuda:0"] + Ns = [8, 32] + Ps = [64, 256] + Ds = [3] + Ks = [24] + test_cases = product(Ns, Ps, Ds, Ks, backends) + for case in test_cases: + N, P, D, K, d = case + kwargs_list.append({"N": N, "P": P, "D": D, "K": K, "device": d}) + + benchmark( + TestFPS.sample_farthest_points_naive, + "FPS_NAIVE_PYTHON", + kwargs_list, + warmup_iters=1, + ) + + # Add some larger batch sizes and pointcloud sizes + Ns = [32] + Ps = [2048, 8192, 18384] + Ds = [3, 9] + Ks = [24, 48] + test_cases = product(Ns, Ps, Ds, Ks, backends) + for case in test_cases: + N, P, D, K, d = case + kwargs_list.append({"N": N, "P": P, "D": D, "K": K, "device": d}) + + benchmark(TestFPS.sample_farthest_points, "FPS", kwargs_list, warmup_iters=1) + + +if __name__ == "__main__": + bm_fps() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_sample_pdf.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_sample_pdf.py new file mode 100644 index 0000000000000000000000000000000000000000..0f94df8f9a1915001d929177a4c47006ccbaeefe --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_sample_pdf.py @@ -0,0 +1,37 @@ +# 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. + +from itertools import product + +from fvcore.common.benchmark import benchmark +from tests.test_sample_pdf import TestSamplePDF + + +def bm_sample_pdf() -> None: + + backends = ["python_cuda", "cuda", "python_cpu", "cpu"] + + kwargs_list = [] + sample_counts = [64] + batch_sizes = [1024, 10240] + bin_counts = [62, 600] + test_cases = product(backends, sample_counts, batch_sizes, bin_counts) + for case in test_cases: + backend, n_samples, batch_size, n_bins = case + kwargs_list.append( + { + "backend": backend, + "n_samples": n_samples, + "batch_size": batch_size, + "n_bins": n_bins, + } + ) + + benchmark(TestSamplePDF.bm_fn, "SAMPLE_PDF", kwargs_list, warmup_iters=1) + + +if __name__ == "__main__": + bm_sample_pdf() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_sample_points_from_meshes.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_sample_points_from_meshes.py new file mode 100644 index 0000000000000000000000000000000000000000..480e7eb97bdc1e78921fef776bcf19c809007074 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_sample_points_from_meshes.py @@ -0,0 +1,46 @@ +# 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. + + +from itertools import product + +import torch +from fvcore.common.benchmark import benchmark +from tests.test_sample_points_from_meshes import TestSamplePoints + + +def bm_sample_points() -> None: + + backend = ["cpu"] + if torch.cuda.is_available(): + backend.append("cuda:0") + kwargs_list = [] + num_meshes = [2, 10, 32] + num_verts = [100, 1000] + num_faces = [300, 3000] + num_samples = [5000, 10000] + test_cases = product(num_meshes, num_verts, num_faces, num_samples, backend) + for case in test_cases: + n, v, f, s, b = case + kwargs_list.append( + { + "num_meshes": n, + "num_verts": v, + "num_faces": f, + "num_samples": s, + "device": b, + } + ) + benchmark( + TestSamplePoints.sample_points_with_init, + "SAMPLE_MESH", + kwargs_list, + warmup_iters=1, + ) + + +if __name__ == "__main__": + bm_sample_points() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_se3.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_se3.py new file mode 100644 index 0000000000000000000000000000000000000000..62ac896730cb10ecf0e616b43986a4b9e5c4faec --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_se3.py @@ -0,0 +1,23 @@ +# 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. + +from fvcore.common.benchmark import benchmark +from tests.test_se3 import TestSE3 + + +def bm_se3() -> None: + kwargs_list = [ + {"batch_size": 1}, + {"batch_size": 10}, + {"batch_size": 100}, + {"batch_size": 1000}, + ] + benchmark(TestSE3.se3_expmap, "SE3_EXP", kwargs_list, warmup_iters=1) + benchmark(TestSE3.se3_logmap, "SE3_LOG", kwargs_list, warmup_iters=1) + + +if __name__ == "__main__": + bm_se3() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_so3.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_so3.py new file mode 100644 index 0000000000000000000000000000000000000000..851e9fc4b9cc33d96adadd5ab229c06d434cbd71 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_so3.py @@ -0,0 +1,23 @@ +# 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. + +from fvcore.common.benchmark import benchmark +from tests.test_so3 import TestSO3 + + +def bm_so3() -> None: + kwargs_list = [ + {"batch_size": 1}, + {"batch_size": 10}, + {"batch_size": 100}, + {"batch_size": 1000}, + ] + benchmark(TestSO3.so3_expmap, "SO3_EXP", kwargs_list, warmup_iters=1) + benchmark(TestSO3.so3_logmap, "SO3_LOG", kwargs_list, warmup_iters=1) + + +if __name__ == "__main__": + bm_so3() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_subdivide_meshes.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_subdivide_meshes.py new file mode 100644 index 0000000000000000000000000000000000000000..79a4a30a96828bf3de3b566eafb39eaa63583a4e --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_subdivide_meshes.py @@ -0,0 +1,31 @@ +# 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. + + +from itertools import product + +from fvcore.common.benchmark import benchmark +from tests.test_subdivide_meshes import TestSubdivideMeshes + + +def bm_subdivide() -> None: + kwargs_list = [] + num_meshes = [1, 16, 32] + same_topo = [True, False] + test_cases = product(num_meshes, same_topo) + for case in test_cases: + n, s = case + kwargs_list.append({"num_meshes": n, "same_topo": s}) + benchmark( + TestSubdivideMeshes.subdivide_meshes_with_init, + "SUBDIVIDE", + kwargs_list, + warmup_iters=1, + ) + + +if __name__ == "__main__": + bm_subdivide() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_symeig3x3.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_symeig3x3.py new file mode 100644 index 0000000000000000000000000000000000000000..c0e4dc6346350c0790d9769fda07dc92a108c6a0 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_symeig3x3.py @@ -0,0 +1,94 @@ +# 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. + + +from itertools import product +from typing import Any, Callable + +import torch +from common_testing import get_random_cuda_device +from fvcore.common.benchmark import benchmark +from pytorch3d.common.workaround import symeig3x3 +from tests.test_symeig3x3 import TestSymEig3x3 + + +torch.set_num_threads(1) + +CUDA_DEVICE = get_random_cuda_device() + + +def create_traced_func(func, device, batch_size): + traced_func = torch.jit.trace( + func, (TestSymEig3x3.create_random_sym3x3(device, batch_size),) + ) + + return traced_func + + +FUNC_NAME_TO_FUNC = { + "sym3x3eig": (lambda inputs: symeig3x3(inputs, eigenvectors=True)), + "sym3x3eig_traced_cuda": create_traced_func( + (lambda inputs: symeig3x3(inputs, eigenvectors=True)), CUDA_DEVICE, 1024 + ), + "torch_symeig": (lambda inputs: torch.symeig(inputs, eigenvectors=True)), + "torch_linalg_eigh": (lambda inputs: torch.linalg.eigh(inputs)), + "torch_pca_lowrank": ( + lambda inputs: torch.pca_lowrank(inputs, center=False, niter=1) + ), + "sym3x3eig_no_vecs": (lambda inputs: symeig3x3(inputs, eigenvectors=False)), + "torch_symeig_no_vecs": (lambda inputs: torch.symeig(inputs, eigenvectors=False)), + "torch_linalg_eigvalsh_no_vecs": (lambda inputs: torch.linalg.eigvalsh(inputs)), +} + + +def test_symeig3x3(func_name, batch_size, device) -> Callable[[], Any]: + func = FUNC_NAME_TO_FUNC[func_name] + inputs = TestSymEig3x3.create_random_sym3x3(device, batch_size) + torch.cuda.synchronize() + + def symeig3x3(): + func(inputs) + torch.cuda.synchronize() + + return symeig3x3 + + +def bm_symeig3x3() -> None: + devices = ["cpu"] + if torch.cuda.is_available(): + devices.append(CUDA_DEVICE) + + kwargs_list = [] + func_names = FUNC_NAME_TO_FUNC.keys() + batch_sizes = [16, 128, 1024, 8192, 65536, 1048576] + + for func_name, batch_size, device in product(func_names, batch_sizes, devices): + # Run CUDA-only implementations only on GPU + if "cuda" in func_name and not device.startswith("cuda"): + continue + + # Torch built-ins are quite slow on larger batches + if "torch" in func_name and batch_size > 8192: + continue + + # Avoid running CPU implementations on larger batches as well + if device == "cpu" and batch_size > 8192: + continue + + kwargs_list.append( + {"func_name": func_name, "batch_size": batch_size, "device": device} + ) + + benchmark( + test_symeig3x3, + "SYMEIG3X3", + kwargs_list, + warmup_iters=3, + ) + + +if __name__ == "__main__": + bm_symeig3x3() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_vert_align.py b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_vert_align.py new file mode 100644 index 0000000000000000000000000000000000000000..6670029e89203fbd5e516d1cb57f15b946c94cec --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/benchmarks/bm_vert_align.py @@ -0,0 +1,37 @@ +# 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. + + +from itertools import product + +import torch +from fvcore.common.benchmark import benchmark +from tests.test_vert_align import TestVertAlign + + +def bm_vert_align() -> None: + devices = ["cpu"] + if torch.cuda.is_available(): + devices.append("cuda") + + kwargs_list = [] + num_meshes = [2, 10, 32] + num_verts = [100, 1000] + num_faces = [300, 3000] + test_cases = product(num_meshes, num_verts, num_faces, devices) + for case in test_cases: + n, v, f, d = case + kwargs_list.append( + {"num_meshes": n, "num_verts": v, "num_faces": f, "device": d} + ) + + benchmark( + TestVertAlign.vert_align_with_init, "VERT_ALIGN", kwargs_list, warmup_iters=1 + ) + + +if __name__ == "__main__": + bm_vert_align() diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/cv_project_points_precomputed.json b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/cv_project_points_precomputed.json new file mode 100644 index 0000000000000000000000000000000000000000..ba430912056c13c749f20f7313c9c50322ad9aa9 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/cv_project_points_precomputed.json @@ -0,0 +1,1230 @@ +[ + { + "rvec": [ + -1.6336234226511284, + -1.009804818052615, + 0.4160736184401035 + ], + "tvec": [ + 1.626905, + -1.5187958, + -4.6009063 + ], + "camera_matrix": [ + [ + -1.0406556, + 0.0, + 0.6160261 + ], + [ + -0.0, + -4.6370989, + -2.2859802 + ], + [ + -0.0, + -0.0, + 1.0 + ] + ], + "image_size": [ + 19, + 16 + ], + "pts": [ + [ + 0.7610377, + 0.121675, + 0.4438632 + ], + [ + 0.3336743, + 1.4940791, + -0.2051583 + ], + [ + 0.3130677, + -0.8540957, + -2.5529898 + ], + [ + 0.6536186, + 0.8644362, + -0.742165 + ], + [ + 2.2697546, + -1.4543657, + 0.0457585 + ], + [ + -0.1871839, + 1.5327792, + 1.4693588 + ], + [ + 0.1549474, + 0.3781625, + -0.8877857 + ], + [ + -1.9807965, + -0.3479121, + 0.156349 + ], + [ + 1.2302907, + 1.2023798, + -0.3873268 + ], + [ + -0.3023028, + -1.048553, + -1.4200179 + ], + [ + -1.7062702, + 1.9507754, + -0.5096522 + ], + [ + -0.4380743, + -1.2527954, + 0.7774904 + ], + [ + -1.6138978, + -0.2127403, + -0.8954666 + ], + [ + 0.3869025, + -0.5108051, + -1.1806322 + ], + [ + -0.0281822, + 0.4283319, + 0.0665172 + ], + [ + 0.3024719, + -0.6343221, + -0.3627412 + ], + [ + -0.6724604, + -0.3595532, + -0.8131463 + ], + [ + -1.7262826, + 0.1774261, + -0.4017809 + ], + [ + -1.6301983, + 0.4627823, + -0.9072984 + ], + [ + 0.0519454, + 0.7290906, + 0.1289829 + ], + [ + 1.1394007, + -1.2348258, + 0.4023416 + ], + [ + -0.6848101, + -0.8707971, + -0.5788497 + ], + [ + -0.3115525, + 0.0561653, + -1.1651498 + ], + [ + 0.9008265, + 0.4656624, + -1.5362437 + ], + [ + 1.4882522, + 1.8958892, + 1.1787796 + ], + [ + -0.1799248, + -1.0707526, + 1.0544517 + ], + [ + -0.4031769, + 1.2224451, + 0.208275 + ], + [ + 0.976639, + 0.3563664, + 0.7065732 + ], + [ + 0.0105, + 1.7858705, + 0.1269121 + ], + [ + 0.4019894, + 1.8831507, + -1.3477591 + ] + ], + "pts_proj": [ + [ + 1.0145014, + -2.9284953 + ], + [ + 1.0724146, + -3.4080993 + ], + [ + 1.7917063, + -6.7793572 + ], + [ + 1.2140849, + -3.6559075 + ], + [ + 1.4910298, + -1.7436687 + ], + [ + 0.7868983, + -2.8461123 + ], + [ + 1.1790002, + -4.2421372 + ], + [ + 0.6688383, + -5.165954 + ], + [ + 1.2222519, + -2.9970978 + ], + [ + 1.2750471, + -6.013773 + ], + [ + 0.8970727, + -4.5353657 + ], + [ + 0.7041445, + -3.9451632 + ], + [ + 0.9085118, + -5.7326503 + ], + [ + 1.3246946, + -4.7337656 + ], + [ + 0.9750362, + -3.678297 + ], + [ + 1.1074375, + -4.0924549 + ], + [ + 1.0367661, + -5.1176712 + ], + [ + 0.8222725, + -5.1682077 + ], + [ + 0.9272976, + -5.3440215 + ], + [ + 0.9797946, + -3.5213536 + ], + [ + 1.0847165, + -2.7743226 + ], + [ + 0.9762082, + -5.2337584 + ], + [ + 1.1681587, + -4.9342569 + ], + [ + 1.4412056, + -4.1796204 + ], + [ + 1.0048257, + -2.0358393 + ], + [ + 0.7052604, + -3.4338048 + ], + [ + 0.9221008, + -3.6497452 + ], + [ + 1.0001084, + -2.588002 + ], + [ + 0.9887072, + -3.3682799 + ], + [ + 1.2562716, + -3.9393683 + ] + ] + }, + { + "rvec": [ + -1.624698671197051, + 1.2717319528620892, + 0.026455585547038436 + ], + "tvec": [ + -0.7416676, + -0.9513922, + 1.2411273 + ], + "camera_matrix": [ + [ + -0.6674566, + 0.0, + 0.0366092 + ], + [ + -0.0, + -0.4250565, + -0.1661673 + ], + [ + -0.0, + -0.0, + 1.0 + ] + ], + "image_size": [ + 11, + 19 + ], + "pts": [ + [ + 0.9182028, + -0.1588005, + -0.9640634 + ], + [ + -1.9907788, + 0.0897307, + 0.1148539 + ], + [ + -0.5858152, + 0.298772, + 0.2222599 + ], + [ + 0.435183, + -0.0457481, + 0.0498984 + ], + [ + -0.9355305, + 0.2873877, + 0.3604273 + ], + [ + 0.4081481, + -1.9407157, + 1.4448357 + ], + [ + 0.1928609, + -0.4208648, + 1.7402535 + ], + [ + -0.3640868, + 1.3439544, + -0.818221 + ], + [ + 0.0827099, + -1.2910585, + -0.6611042 + ], + [ + -1.180191, + 0.1976426, + 0.4139 + ], + [ + 1.197322, + 1.8833539, + 0.7142238 + ], + [ + 2.2843334, + 1.5641026, + 0.6111037 + ], + [ + -0.8773633, + -1.6210875, + -0.581673 + ], + [ + -0.537834, + -1.5560237, + -0.0544648 + ], + [ + -1.8112788, + -0.6311752, + -0.9281592 + ], + [ + 1.4907219, + 0.1954993, + -0.4716043 + ], + [ + 1.8123547, + -2.2941375, + 0.6512093 + ], + [ + -1.1304964, + -0.7773467, + 1.1159385 + ], + [ + 1.339453, + -1.7674337, + 0.4244125 + ], + [ + 1.089309, + -0.3841857, + 0.6322014 + ], + [ + -0.5496559, + 0.5211257, + 0.1083495 + ], + [ + 0.2616685, + -0.9147553, + 0.8582378 + ], + [ + 0.0943343, + -1.4859039, + -1.9005843 + ], + [ + -1.1375792, + -1.7620389, + -0.2886232 + ], + [ + 1.0479822, + 0.2499575, + 0.0469045 + ], + [ + -1.032243, + 0.4031857, + -0.6840593 + ], + [ + 1.2623222, + -2.0055566, + -0.3320304 + ], + [ + -0.2961004, + -2.2183608, + -0.1835029 + ], + [ + 0.3923081, + 0.2416348, + 0.1039359 + ], + [ + -0.8295712, + 0.4927594, + 0.0901128 + ] + ], + "pts_proj": [ + [ + 0.4141589, + 0.5870938 + ], + [ + 0.5208963, + -0.2684058 + ], + [ + 0.6192571, + -0.0457759 + ], + [ + 0.3620623, + 0.3519971 + ], + [ + 0.5966208, + -0.1618695 + ], + [ + -0.6130961, + -0.0666413 + ], + [ + -0.5973283, + -0.240145 + ], + [ + 1.7229771, + 0.3713118 + ], + [ + 0.069312, + 0.1164213 + ], + [ + 0.5411626, + -0.21708 + ], + [ + -0.7298492, + -0.6226879 + ], + [ + -0.2271261, + -0.7756765 + ], + [ + 0.0919778, + -0.0452863 + ], + [ + 0.005477, + -0.0454978 + ], + [ + 0.3725968, + -0.1135225 + ], + [ + 0.6738571, + 1.806536 + ], + [ + -0.8906672, + 0.3956792 + ], + [ + 0.0670651, + -0.294005 + ], + [ + -0.5670261, + 0.3293613 + ], + [ + -0.3558128, + 0.7635874 + ], + [ + 0.7998255, + -0.0010898 + ], + [ + -0.2129184, + 0.031003 + ], + [ + 0.1711748, + 0.1747995 + ], + [ + 0.0606019, + -0.0990852 + ], + [ + 0.6655512, + 1.3313645 + ], + [ + 0.6986332, + -0.0128461 + ], + [ + -0.3178348, + 0.297116 + ], + [ + -0.1058796, + -0.0156453 + ], + [ + 0.6059715, + 0.4297142 + ], + [ + 0.750323, + -0.082273 + ] + ] + }, + { + "rvec": [ + 0.9529480300972241, + -0.8534383895555052, + -2.0235766239679127 + ], + "tvec": [ + -0.3351616, + -1.6076185, + 0.0039651 + ], + "camera_matrix": [ + [ + 0.6332697, + 0.0, + -0.0084798 + ], + [ + 0.0, + 0.5719922, + 0.5328057 + ], + [ + 0.0, + 0.0, + 1.0 + ] + ], + "image_size": [ + 10, + 19 + ], + "pts": [ + [ + -0.3824862, + 0.6916619, + 0.353885 + ], + [ + 1.0475853, + -0.4238962, + -3.5147681 + ], + [ + -1.3431567, + 1.4255061, + 0.228582 + ], + [ + -0.2576638, + 0.0503707, + -1.3802109 + ], + [ + -0.2616721, + -0.1793797, + -0.6927706 + ], + [ + 1.1378269, + -0.1691573, + -0.7639137 + ], + [ + -0.4980731, + -0.3628911, + 0.2639603 + ], + [ + -0.6296419, + -0.4722584, + -1.513361 + ], + [ + 1.1076247, + 0.1762388, + -0.9403535 + ], + [ + 0.9295943, + -1.0627949, + -0.8864063 + ], + [ + 1.921347, + -0.4597805, + -1.0890344 + ], + [ + 0.9841173, + -1.1592063, + -0.4365371 + ], + [ + 1.0092445, + 0.7133896, + -0.7280577 + ], + [ + 0.8395165, + 1.239021, + -1.7848039 + ], + [ + -0.7961858, + -1.4005413, + -0.1843506 + ], + [ + -1.3911931, + 0.0362597, + -0.8144056 + ], + [ + 0.6973728, + -1.7374292, + 0.1158557 + ], + [ + 0.3656514, + -0.0739235, + -0.4935176 + ], + [ + 3.1015306, + 0.8587542, + -1.1547755 + ], + [ + 0.9418343, + -0.2821351, + -0.9756547 + ], + [ + 0.0981867, + 0.90549, + 1.0187414 + ], + [ + -0.1148989, + 1.7430387, + -0.3218792 + ], + [ + 0.8295711, + -0.207318, + 1.1179986 + ], + [ + 1.0642497, + 1.1513298, + -0.7724577 + ], + [ + -1.2936343, + 0.6770268, + 0.4240552 + ], + [ + -0.4856762, + -0.0516972, + 0.5670564 + ], + [ + 1.0678336, + 0.2715957, + 0.6193018 + ], + [ + -0.058626, + 1.2565714, + 0.2967472 + ], + [ + 0.3985857, + -1.0531744, + -0.6394763 + ], + [ + -0.1485269, + -1.5745821, + -0.4956882 + ] + ], + "pts_proj": [ + [ + -0.1735197, + -0.5026447 + ], + [ + -0.5086927, + 1.2602939 + ], + [ + 0.1995019, + 0.1377832 + ], + [ + -1.0602558, + 2.3228582 + ], + [ + -0.4811967, + 2.6476893 + ], + [ + 0.1891248, + 2.2078843 + ], + [ + -14.5705317, + -27.5060102 + ], + [ + -0.7295134, + 1.2970094 + ], + [ + -0.0004579, + 2.8277094 + ], + [ + 0.1412656, + 1.2635503 + ], + [ + 0.1810516, + 1.7102113 + ], + [ + 0.3390042, + 1.2833538 + ], + [ + -0.1753715, + 12.5495766 + ], + [ + -3.6611631, + 10.1461827 + ], + [ + 0.1812461, + 0.7066171 + ], + [ + 6.5346752, + -3.5950883 + ], + [ + 0.5305561, + 0.9966792 + ], + [ + 0.1684846, + 3.1942163 + ], + [ + 0.3376347, + 3.4565985 + ], + [ + 0.024885, + 1.9060357 + ], + [ + -0.4946605, + -0.3688437 + ], + [ + 0.2704817, + -0.5945693 + ], + [ + -8.9040477, + -8.4144665 + ], + [ + 0.7361192, + -10.8591518 + ], + [ + 0.0607204, + 0.1565487 + ], + [ + -0.9204385, + -0.9006548 + ], + [ + -4.7045052, + -7.8600902 + ], + [ + -0.0843625, + -0.5081105 + ], + [ + 0.1565888, + 1.2224583 + ], + [ + 0.1561078, + 0.8506761 + ] + ] + }, + { + "rvec": [ + -0.9637575928124262, + 1.6344477621933204, + 1.1377406680922277 + ], + "tvec": [ + -5.0736742, + -15.0264648, + 3.7663565 + ], + "camera_matrix": [ + [ + 0.0592345, + 0.0, + 1.0948929 + ], + [ + 0.0, + 2.0469542, + -1.6769676 + ], + [ + 0.0, + 0.0, + 1.0 + ] + ], + "image_size": [ + 19, + 12 + ], + "pts": [ + [ + 0.0815831, + 1.2381695, + 2.1837783 + ], + [ + 0.1905641, + -0.4981669, + 0.0475124 + ], + [ + 1.4483291, + 0.4282211, + -0.1707534 + ], + [ + -2.3547773, + -0.4678065, + -0.1294017 + ], + [ + 0.9000515, + -0.5156528, + 0.5203996 + ], + [ + 1.1410499, + -1.4447244, + -1.0176718 + ], + [ + -0.9902687, + 1.5241503, + 0.636245 + ], + [ + 0.1996184, + -0.0077118, + 1.1754896 + ], + [ + 1.2556589, + -0.2809262, + -0.3669177 + ], + [ + 1.6537248, + -0.0856097, + 0.2933573 + ], + [ + 1.4872575, + -0.6384799, + 0.7087688 + ], + [ + -0.0825277, + -0.6873837, + -1.4113116 + ], + [ + 0.6213837, + 0.3085112, + -0.3309394 + ], + [ + -0.4852161, + -0.0602118, + -1.5596469 + ], + [ + -0.2914053, + 0.8040719, + 0.7358267 + ], + [ + -0.2026395, + 0.2902467, + -0.8548176 + ], + [ + -0.3261322, + -0.952252, + 1.1869633 + ], + [ + -1.1571738, + 0.0193, + 1.4500207 + ], + [ + 0.6521225, + -0.3442692, + 1.2908895 + ], + [ + -0.8021245, + -1.3890878, + 0.2576423 + ], + [ + 1.1274729, + 2.7849331, + -0.0913946 + ], + [ + -0.0290724, + 1.030574, + 1.0248824 + ], + [ + 1.5831991, + 1.0291609, + 1.8343708 + ], + [ + -0.4910075, + -0.8094693, + -0.2462478 + ], + [ + -0.4517529, + -0.6581127, + 0.3922879 + ], + [ + -1.3964618, + 0.3368952, + 0.6266755 + ], + [ + 0.5469885, + -0.3078414, + 0.0734122 + ], + [ + -0.2766632, + 0.1395219, + -0.050913 + ], + [ + 0.740091, + -0.3233616, + 2.4009981 + ], + [ + 2.8127453, + 0.6191253, + -2.3287021 + ] + ], + "pts_proj": [ + [ + 1.0011881, + -8.7962669 + ], + [ + 1.0148904, + -10.6624766 + ], + [ + 0.9559355, + -13.9861497 + ], + [ + 1.0550145, + -6.889409 + ], + [ + 0.9903897, + -12.9240756 + ], + [ + 0.9922857, + -15.2615745 + ], + [ + 1.0231235, + -7.3797553 + ], + [ + 1.0095861, + -10.1396779 + ], + [ + 0.9732178, + -14.1103632 + ], + [ + 0.9437488, + -16.0891922 + ], + [ + 0.9584208, + -16.2312512 + ], + [ + 1.0231435, + -10.332697 + ], + [ + 0.9944343, + -11.1411459 + ], + [ + 1.0257093, + -9.1991957 + ], + [ + 1.0149771, + -8.6661286 + ], + [ + 1.0172749, + -9.379192 + ], + [ + 1.0324498, + -9.6570503 + ], + [ + 1.0382854, + -7.6709289 + ], + [ + 0.9976967, + -11.7654687 + ], + [ + 1.0447702, + -9.1607223 + ], + [ + 0.9566311, + -10.3084282 + ], + [ + 1.0066492, + -8.9367541 + ], + [ + 0.9320123, + -13.8820569 + ], + [ + 1.0331906, + -9.4447618 + ], + [ + 1.0314307, + -9.3262563 + ], + [ + 1.0384939, + -7.4069907 + ], + [ + 1.0022615, + -11.4736859 + ], + [ + 1.0202613, + -9.217644 + ], + [ + 0.9922728, + -11.9963374 + ], + [ + 0.8448706, + -23.0521993 + ] + ] + } +] diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/glb_cow.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/glb_cow.png new file mode 100644 index 0000000000000000000000000000000000000000..aef052361ff31719be96cb5ffbb86e6d92169451 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/glb_cow.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/glb_cow_gray.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/glb_cow_gray.png new file mode 100644 index 0000000000000000000000000000000000000000..084b59e8dd6ea555d66f07d663f3767ad095c9f6 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/glb_cow_gray.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/missing_files_obj/model.mtl b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/missing_files_obj/model.mtl new file mode 100644 index 0000000000000000000000000000000000000000..d6a0f4fb3c119916f2c324f846a040879e4b6e2a --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/missing_files_obj/model.mtl @@ -0,0 +1,9 @@ +newmtl material_1 +map_Kd material_1.png + +# Test colors + +Ka 1.000 1.000 1.000 # white +Kd 1.000 1.000 1.000 # white +Ks 0.000 0.000 0.000 # black +Ns 10.0 diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/missing_files_obj/model.obj b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/missing_files_obj/model.obj new file mode 100644 index 0000000000000000000000000000000000000000..cf411442fd4d6e5364e0e49aea0e3bbd570d6b06 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/missing_files_obj/model.obj @@ -0,0 +1,10 @@ + +mtllib model.mtl + +v 0.1 0.2 0.3 +v 0.2 0.3 0.4 +v 0.3 0.4 0.5 +v 0.4 0.5 0.6 +usemtl material_1 +f 1 2 3 +f 1 2 4 diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/missing_files_obj/model2.obj b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/missing_files_obj/model2.obj new file mode 100644 index 0000000000000000000000000000000000000000..df393f9f1b360ded4b6d232039702a2c745f5529 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/missing_files_obj/model2.obj @@ -0,0 +1,10 @@ + +mtllib model2.mtl + +v 0.1 0.2 0.3 +v 0.2 0.3 0.4 +v 0.3 0.4 0.5 +v 0.4 0.5 0.6 +usemtl material_1 +f 1 2 3 +f 1 2 4 diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/missing_usemtl/README.md b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/missing_usemtl/README.md new file mode 100644 index 0000000000000000000000000000000000000000..1c9b08bea9e0a4efac7770c872a7aa2b6023e307 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/missing_usemtl/README.md @@ -0,0 +1,7 @@ +# Acknowledgements + +This is copied version of docs/tutorials/data/cow_mesh with removed line 6159 (usemtl material_1) to test behavior without usemtl material_1 declaration. + +Thank you to Keenan Crane for allowing the cow mesh model to be used freely in the public domain. + +###### Source: http://www.cs.cmu.edu/~kmcrane/Projects/ModelRepository/ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/missing_usemtl/cow.mtl b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/missing_usemtl/cow.mtl new file mode 100644 index 0000000000000000000000000000000000000000..c3bc054358c3db2526520c29f4c30ac812f7c370 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/missing_usemtl/cow.mtl @@ -0,0 +1,9 @@ +newmtl material_1 +map_Kd cow_texture.png + +# Test colors + +Ka 1.000 1.000 1.000 # white +Kd 1.000 1.000 1.000 # white +Ks 0.000 0.000 0.000 # black +Ns 10.0 diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/missing_usemtl/cow.obj b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/missing_usemtl/cow.obj new file mode 100644 index 0000000000000000000000000000000000000000..2f349d0dac3994869486bdac7f15892f5acb2508 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/missing_usemtl/cow.obj @@ -0,0 +1,12014 @@ + +mtllib cow.mtl + +v 0.348799 -0.334989 -0.0832331 +v 0.313132 -0.399051 0.881192 +v 0.266758 0.181628 0.122726 +v 0.229555 0.0663178 0.828702 +v 0.353623 -0.0486456 0.443969 +v 0.335878 -0.384495 0.425693 +v 0.305362 0.0307983 -0.00655663 +v 0.279611 -0.0552387 0.858547 +v 0.266719 0.10578 0.46681 +v 0.149341 -0.451522 0.166423 +v 0.12606 -0.162036 -0.185668 +v 0.114009 -0.358339 -0.0759521 +v 0.101546 -0.475382 0.663157 +v 0.240757 -0.435635 0.421981 +v 0.385825 -0.174501 0.180766 +v 0.358602 -0.37797 0.17897 +v 0.345953 -0.229705 0.664126 +v 0.316102 -0.419396 0.649153 +v 0.131961 -0.201382 0.951731 +v 0.0876766 -0.391182 0.901606 +v 0.161859 0.285356 0.303098 +v 0.177264 0.282839 0.0875537 +v 0.158786 0.0751889 -0.141343 +v 0.310974 -0.0974099 -0.0697762 +v 0.138236 0.191142 0.700393 +v 0.13061 0.109881 0.873657 +v 0.287544 -0.214549 0.864938 +v 0.25445 0.101336 0.680112 +v 0.34304 -0.0541165 0.672286 +v 0.369388 -0.0242775 0.205838 +v 0.273782 0.160332 0.273861 +v 0.36907 -0.228332 0.435279 +v 0.146074 0.206063 0.488052 +v 0.15689 0.317253 -0.0179554 +v 0.184529 0.181235 -0.238574 +v 0.229877 0.446038 -0.0428095 +v 0.326584 0.303676 -0.375494 +v 0.257915 0.488969 -0.517721 +v 0.187711 0.730295 -0.437134 +v 0.190442 0.122856 -0.437696 +v 0.271501 0.201979 -0.579853 +v 0.227961 0.337016 -0.641468 +v 0.323288 -0.645898 -0.0650069 +v 0.277559 -0.660659 0.872426 +v 0.15321 -0.671553 0.116597 +v 0.153343 -0.652512 -0.0628489 +v 0.129752 -0.680413 0.714233 +v 0.310744 -0.658159 0.12474 +v 0.270197 -0.670204 0.705429 +v 0.125665 -0.664371 0.877017 +v 0.264169 0.646946 -0.369897 +v 0.180359 0.68646 -0.148279 +v 0.263204 0.560375 -0.137191 +v 0.371765 0.683869 -0.321196 +v 0.432195 0.751246 -0.233457 +v 0.424574 0.680439 -0.150855 +v 0.379346 0.604049 -0.213075 +v 0 -0.192084 -0.196407 +v 0 0.505678 -0.563016 +v 0 0.340641 -0.665066 +v 0 0.0414775 -0.241591 +v 0 0.117615 -0.305384 +v 0 0.100384 -0.450564 +v 0 0.182587 -0.616155 +v -4.33681e-19 0.765067 -0.449072 +v -4.33681e-19 0.834757 -0.307668 +v 0 -0.434774 0.0615192 +v 0 -0.354126 -0.0677048 +v 0 0.326124 0.139538 +v 0 0.352207 0.0388631 +v 0 0.499175 0.0586613 +v -4.33681e-19 0.723906 -0.0597107 +v 0 0.816061 -0.189369 +v 0 -0.435249 0.726548 +v 0 -0.533724 0.415511 +v 0 0.301194 0.312719 +v 0 0.233342 0.49566 +v 0 -0.340037 0.891691 +v 0 -0.194995 0.971379 +v 0 0.220553 0.711025 +v 0 0.130478 0.891171 +v 0.164015 0.929339 -0.232094 +v 0.205905 0.915741 -0.313374 +v 0.15338 0.935554 -0.282029 +v 0.221786 0.905461 -0.256021 +v 0.115236 0.837896 -0.222054 +v 0.086327 0.812209 -0.211465 +v 0.172231 0.819312 -0.334104 +v 0.162464 0.791078 -0.351846 +v 0.0787362 0.822102 -0.294366 +v 0.102999 0.844736 -0.288229 +v 0.219399 0.754552 -0.28348 +v 0.199751 0.790382 -0.244881 +v 0.184684 0.762009 -0.196152 +v 0.279703 0.762439 -0.233186 +v 0.120311 -0.456517 0.243094 +v 0.111282 -0.477316 0.58188 +v 0.186164 -0.487701 0.417533 +v 0 -0.462404 0.208739 +v 0 -0.483948 0.606421 +v 0.17185 -0.0410977 0.94527 +v 0.106249 -0.0142167 0.968533 +v 0.107395 -0.0653463 0.975253 +v 0 0.00228925 0.987177 +v 0 -0.0756163 0.995507 +v 0.0517509 -0.0608359 1.02473 +v 0.0517951 -0.0798093 1.0112 +v 0 -0.0688251 1.04807 +v 0 -0.0952192 1.02642 +v -0.348799 -0.334989 -0.0832331 +v -0.313132 -0.399051 0.881192 +v -0.266758 0.181628 0.122726 +v -0.229555 0.0663178 0.828702 +v -0.353623 -0.0486456 0.443969 +v -0.335878 -0.384495 0.425693 +v -0.305362 0.0307983 -0.00655663 +v -0.279611 -0.0552387 0.858547 +v -0.266719 0.10578 0.46681 +v -0.149341 -0.451522 0.166423 +v -0.12606 -0.162036 -0.185668 +v -0.114009 -0.358339 -0.0759521 +v -0.101546 -0.475382 0.663157 +v -0.240757 -0.435635 0.421981 +v -0.385825 -0.174501 0.180766 +v -0.358602 -0.37797 0.17897 +v -0.345953 -0.229705 0.664126 +v -0.316102 -0.419396 0.649153 +v -0.131961 -0.201382 0.951731 +v -0.0876766 -0.391182 0.901606 +v -0.161859 0.285356 0.303098 +v -0.177264 0.282839 0.0875537 +v -0.158786 0.0751889 -0.141343 +v -0.310974 -0.0974099 -0.0697762 +v -0.138236 0.191142 0.700393 +v -0.13061 0.109881 0.873657 +v -0.287544 -0.214549 0.864938 +v -0.25445 0.101336 0.680112 +v -0.34304 -0.0541165 0.672286 +v -0.369388 -0.0242775 0.205838 +v -0.273782 0.160332 0.273861 +v -0.36907 -0.228332 0.435279 +v -0.146074 0.206063 0.488052 +v -0.15689 0.317253 -0.0179554 +v -0.184529 0.181235 -0.238574 +v -0.229877 0.446038 -0.0428095 +v -0.326584 0.303676 -0.375494 +v -0.257915 0.488969 -0.517721 +v -0.187711 0.730295 -0.437134 +v -0.190442 0.122856 -0.437696 +v -0.271501 0.201979 -0.579853 +v -0.227961 0.337016 -0.641468 +v -0.323288 -0.645898 -0.0650069 +v -0.277559 -0.660659 0.872426 +v -0.15321 -0.671553 0.116597 +v -0.153343 -0.652512 -0.0628489 +v -0.129752 -0.680413 0.714233 +v -0.310744 -0.658159 0.12474 +v -0.270197 -0.670204 0.705429 +v -0.125665 -0.664371 0.877017 +v -0.264169 0.646946 -0.369897 +v -0.180359 0.68646 -0.148279 +v -0.263204 0.560375 -0.137191 +v -0.371765 0.683869 -0.321196 +v -0.432195 0.751246 -0.233457 +v -0.424574 0.680439 -0.150855 +v -0.379346 0.604049 -0.213075 +v -0.164015 0.929339 -0.232094 +v -0.205905 0.915741 -0.313374 +v -0.15338 0.935554 -0.282029 +v -0.221786 0.905461 -0.256021 +v -0.115236 0.837896 -0.222054 +v -0.086327 0.812209 -0.211465 +v -0.172231 0.819312 -0.334104 +v -0.162464 0.791078 -0.351846 +v -0.0787362 0.822102 -0.294366 +v -0.102999 0.844736 -0.288229 +v -0.219399 0.754552 -0.28348 +v -0.199751 0.790382 -0.244881 +v -0.184684 0.762009 -0.196152 +v -0.279703 0.762439 -0.233186 +v -0.120311 -0.456517 0.243094 +v -0.111282 -0.477316 0.58188 +v -0.186164 -0.487701 0.417533 +v -0.17185 -0.0410977 0.94527 +v -0.106249 -0.0142167 0.968533 +v -0.107395 -0.0653463 0.975253 +v -0.0517509 -0.0608359 1.02473 +v -0.0517951 -0.0798093 1.0112 +v 0.287063 -0.417912 0.42339 +v 0.223323 -0.431749 0.300839 +v 0.262599 -0.446574 0.214165 +v 0.345683 -0.367458 0.305622 +v 0.284862 -0.410239 0.304857 +v 0.320467 -0.390454 0.538527 +v 0.218649 -0.474853 0.619945 +v 0.19621 -0.447285 0.538732 +v 0.257025 -0.429064 0.536591 +v 0.240602 -0.341214 -0.117452 +v 0.12147 -0.249274 -0.145022 +v 0.221157 -0.120393 -0.146058 +v 0.328715 -0.192761 -0.0778193 +v 0.229478 -0.212011 -0.133147 +v 0.307987 -0.0331195 -0.049691 +v 0.139893 -0.0548182 -0.181103 +v 0.237075 0.0521949 -0.0759725 +v 0.227173 -0.0372356 -0.128413 +v 0.301492 -0.292885 0.870674 +v 0.213279 -0.204742 0.922518 +v 0.117499 -0.281642 0.935739 +v 0.211816 -0.394732 0.922409 +v 0.215547 -0.286415 0.919674 +v 0.364968 -0.12541 0.046235 +v 0.382458 -0.25968 0.176197 +v 0.385194 -0.351205 0.0306159 +v 0.375418 -0.216313 0.0359591 +v 0.382575 -0.209764 0.311653 +v 0.361147 -0.316624 0.430338 +v 0.374384 -0.294532 0.308248 +v 0.368668 -0.137134 0.438729 +v 0.385132 -0.101185 0.188168 +v 0.365146 -0.0406368 0.324829 +v 0.381949 -0.125584 0.315412 +v 0.350232 0.00253885 0.0908221 +v 0.361458 -0.0619596 0.0609153 +v 0.343331 -0.409171 0.778577 +v 0.341862 -0.313907 0.657949 +v 0.328019 -0.223318 0.773747 +v 0.336544 -0.303107 0.775339 +v 0.283052 -0.132631 0.863571 +v 0.351001 -0.142438 0.668828 +v 0.322487 -0.0565049 0.774019 +v 0.329 -0.140489 0.774308 +v 0.349301 -0.0521301 0.560904 +v 0.357572 -0.233122 0.551664 +v 0.360647 -0.141814 0.556564 +v 0.349272 -0.319879 0.544579 +v 0.23281 0.229543 0.110217 +v 0.170184 0.299829 0.20555 +v 0.221341 0.236481 0.293418 +v 0.272682 0.181352 0.189589 +v 0.227226 0.252859 0.204008 +v 0.271155 0.129527 0.366223 +v 0.153276 0.244216 0.39384 +v 0.20969 0.164574 0.478658 +v 0.215375 0.198113 0.382954 +v 0.24282 0.0875955 0.770725 +v 0.198521 0.154682 0.689709 +v 0.134533 0.161682 0.796578 +v 0.187262 0.086887 0.854887 +v 0.191558 0.132026 0.78245 +v 0.141545 0.196582 0.593509 +v 0.26179 0.101674 0.574769 +v 0.204392 0.157257 0.584394 +v 0.327755 0.0676272 0.239516 +v 0.317321 0.0335117 0.454173 +v 0.324726 0.0469262 0.344192 +v 0.307072 0.0296092 0.675079 +v 0.253941 0.0157408 0.848168 +v 0.289863 0.0225221 0.77107 +v 0.190901 0.188016 -0.0300482 +v 0.288174 0.116771 0.0639197 +v 0.239299 0.151564 0.0118342 +v 0.313467 0.030566 0.566851 +v 0.317033 0.0909783 0.142973 +v 0.150018 0.148066 -0.170355 +v 0.192003 0.257627 -0.114007 +v 0.150923 0.290686 0.0162651 +v 0.172619 0.221245 -0.0722104 +v 0.274031 0.23831 -0.301318 +v 0.294876 0.383503 -0.203773 +v 0.194068 0.37243 -0.0269037 +v 0.248629 0.311098 -0.153862 +v 0.196806 0.141274 -0.362924 +v 0.23911 0.14497 -0.502892 +v 0.324701 0.24108 -0.502727 +v 0.278147 0.181024 -0.423508 +v 0.263786 0.27805 -0.630217 +v 0.250979 0.388662 -0.601302 +v 0.318198 0.390558 -0.446528 +v 0.314593 0.32071 -0.563292 +v 0.338046 -0.680095 0.0309463 +v 0.228165 -0.692422 0.147407 +v 0.12828 -0.689708 0.0245746 +v 0.238161 -0.677382 -0.0918856 +v 0.229681 -0.733842 0.0266899 +v 0.20056 -0.687393 0.898863 +v 0.107919 -0.696884 0.796995 +v 0.199176 -0.699686 0.68654 +v 0.291818 -0.690195 0.788408 +v 0.198244 -0.736784 0.793448 +v 0.307855 -0.55258 0.89062 +v 0.294592 -0.571581 0.678753 +v 0.335563 -0.561971 0.78431 +v 0.0593616 -0.458076 0.795932 +v 0.110927 -0.595142 0.691599 +v 0.102733 -0.558625 0.896274 +v 0.0716769 -0.583028 0.796447 +v 0.203007 -0.591569 0.647127 +v 0.206666 -0.553636 0.930804 +v 0.339121 -0.546516 0.150832 +v 0.352933 -0.520557 -0.0885122 +v 0.383244 -0.532332 0.0297109 +v 0.132569 -0.534652 -0.0767316 +v 0.24402 -0.524662 -0.124285 +v 0.143499 -0.577512 0.141914 +v 0.241073 -0.571789 0.188527 +v 0.0964942 -0.434904 0.0342915 +v 0.0999951 -0.56397 0.0317575 +v 0.271576 0.561647 -0.416318 +v 0.282894 0.56989 -0.257283 +v 0.23851 0.520387 -0.0907886 +v 0.293195 0.482084 -0.276654 +v 0.213045 0.609177 -0.109989 +v 0.321376 0.576724 -0.185683 +v 0.422878 0.632073 -0.168661 +v 0.32688 0.680784 -0.145207 +v 0.326345 0.612341 -0.141546 +v 0.312594 0.674309 -0.341185 +v 0.379053 0.63587 -0.283895 +v 0.3154 0.606871 -0.278418 +v 0.417773 0.731266 -0.288914 +v 0.460287 0.727236 -0.177367 +v 0.454185 0.684351 -0.230461 +v 0 0.320051 0.223298 +v 0.0857686 0.301184 0.309872 +v 0.0922474 0.320203 0.127906 +v 0.0910385 0.318251 0.216664 +v 0 0.227033 0.602086 +v 0.0710686 0.213115 0.708099 +v 0.0750596 0.22755 0.493766 +v 0.0724773 0.219588 0.599773 +v 0 0.186603 0.810651 +v 0.0670456 0.125156 0.886255 +v 0.0695062 0.18012 0.806775 +v 0 -0.40432 -0.00187701 +v 0.0502685 -0.34467 -0.0665397 +v 0.0661753 -0.432919 0.0879789 +v 0.056363 -0.399912 0.0126968 +v 0 -0.395546 0.810009 +v 0.0398588 -0.442711 0.714357 +v 0.0361117 -0.34665 0.891624 +v 0.0321101 -0.404726 0.804765 +v 0 0.264692 0.401284 +v 0.0798727 0.262384 0.399618 +v 0 0.330325 0.0716557 +v 0.0874752 0.345901 0.0284499 +v 0.0858416 0.32349 0.0605597 +v 0 0.409384 0.0515977 +v 0.124296 0.487548 0.0340513 +v 0.105997 0.402715 0.0360884 +v 0 0.641579 -0.507325 +v 0.104733 0.755088 -0.444831 +v 0.214286 0.629383 -0.484754 +v 0.136392 0.50382 -0.556974 +v 0.121817 0.636846 -0.502061 +v 0 0.412943 -0.623842 +v 0.139278 0.340909 -0.661549 +v 0.138945 0.411476 -0.620153 +v 0 -0.271137 0.943676 +v 0.0622199 -0.197393 0.966789 +v 0.0501277 -0.274014 0.941915 +v 0 -0.286073 -0.138523 +v 0.0553298 -0.185801 -0.197022 +v 0.050202 -0.275405 -0.142323 +v 0 -0.0695404 -0.225378 +v 0.0766662 0.0457919 -0.217551 +v 0.0655056 -0.0670069 -0.214493 +v 0 0.101519 -0.264918 +v 0.0933959 0.130309 -0.285229 +v 0.0838463 0.11062 -0.238883 +v 0 0.106874 -0.369301 +v 0.114603 0.104637 -0.445501 +v 0.102596 0.115199 -0.359834 +v 0 0.126441 -0.539369 +v 0.153665 0.185489 -0.611191 +v 0.137484 0.129002 -0.534091 +v 0 0.259825 -0.661348 +v 0.150371 0.262453 -0.657355 +v 0.0819636 0.707011 -0.0978848 +v 0 0.613137 0.0118372 +v 0.128934 0.593549 -0.0276065 +v 0.230899 0.696193 -0.415496 +v 0.2462 0.632058 -0.451998 +v 0.2255 0.918412 -0.287909 +v 0.182289 0.937359 -0.304334 +v 0.155831 0.94592 -0.253016 +v 0.199042 0.926972 -0.236591 +v 0.198381 0.950853 -0.26973 +v 0.195536 0.768708 -0.323732 +v 0.162591 0.796641 -0.337706 +v 0.198135 0.804412 -0.300184 +v 0.204856 0.767832 -0.258627 +v 0.190344 0.780419 -0.305321 +v 0.158595 0.817014 -0.220186 +v 0.102838 0.815304 -0.21903 +v 0.12548 0.786281 -0.190531 +v 0.18859 0.771476 -0.215131 +v 0.14521 0.793415 -0.208712 +v 0.113814 0.810725 -0.339255 +v 0.0911506 0.822276 -0.28966 +v 0.134346 0.834135 -0.324328 +v 0.12321 0.811864 -0.327105 +v 0.0699464 0.823757 -0.248502 +v 0.0956349 0.846841 -0.248877 +v 0.0836698 0.824545 -0.249204 +v 0.24364 0.757848 -0.207433 +v 0.246443 0.756953 -0.257453 +v 0.21289 0.762245 -0.22883 +v 0.355751 0.762428 -0.238497 +v 0.249966 0.723503 -0.332259 +v 0.32003 0.739642 -0.304714 +v 0.181848 0.741315 -0.180043 +v 0.328516 0.741977 -0.181175 +v 0.0499681 0.812176 -0.199395 +v 0 0.785709 -0.129116 +v 0.0788354 0.774284 -0.158189 +v 0.0505691 0.828853 -0.304368 +v 0.168022 0.778755 -0.386065 +v 0 0.821114 -0.378707 +v 0.0897195 0.811796 -0.373587 +v 0 0.831803 -0.246303 +v 0.0404745 0.828353 -0.247459 +v 0.211302 0.744371 -0.365196 +v 0.193702 0.87269 -0.329392 +v 0.216553 0.856661 -0.251136 +v 0.218551 0.860755 -0.297102 +v 0.126841 0.897388 -0.285836 +v 0.157513 0.887986 -0.320358 +v 0.138938 0.890583 -0.222912 +v 0.120161 0.900194 -0.247801 +v 0.181137 0.872948 -0.224154 +v 0.106299 -0.467348 0.612794 +v 0.156751 -0.485651 0.517662 +v 0.218865 -0.458568 0.419816 +v 0.177713 -0.464461 0.527871 +v 0 -0.459742 0.666605 +v 0.0640756 -0.481225 0.60015 +v 0.0486808 -0.462533 0.655449 +v 0.129769 -0.445891 0.210992 +v 0.0674919 -0.459184 0.218582 +v 0 -0.445956 0.12884 +v 0.0638357 -0.444618 0.15006 +v 0.160168 -0.471758 0.313909 +v 0.192938 -0.45045 0.307624 +v 0 -0.518477 0.519852 +v 0.106971 -0.518553 0.416032 +v 0.0913755 -0.507594 0.518132 +v 0 -0.503509 0.307563 +v 0.0906862 -0.492986 0.310407 +v 0.148938 -0.0188178 0.950827 +v 0.109744 -0.0412763 0.976341 +v 0.152295 -0.0598695 0.957881 +v 0.133131 -0.0374762 0.965091 +v 0.129144 -0.123186 0.961976 +v 0.214922 -0.0472768 0.917853 +v 0.202946 -0.113321 0.930645 +v 0.124777 0.0448234 0.926767 +v 0.189431 0.0176502 0.907717 +v 0.0541294 -0.000582154 0.980957 +v 0 0.0636729 0.946137 +v 0.0627521 0.0592134 0.940397 +v 0.0544734 -0.0758718 0.989219 +v 0 -0.121134 0.98554 +v 0.0631528 -0.123094 0.979468 +v 0.0716307 -0.0432 1.00541 +v 0.052795 -0.0725924 1.01945 +v 0.0717681 -0.0690106 0.994894 +v 0.0809297 -0.0558501 0.997263 +v 0 -0.0400118 1.02513 +v 0.0297219 -0.0653048 1.04059 +v 0.0406958 -0.0395224 1.01839 +v 0.0297587 -0.0908237 1.02001 +v 0 -0.0782912 1.00911 +v 0.0407812 -0.0765567 1.00299 +v 0 -0.0903561 1.04431 +v 0.0264068 -0.0851806 1.03686 +v -0.345683 -0.367458 0.305622 +v -0.262599 -0.446574 0.214165 +v -0.223323 -0.431749 0.300839 +v -0.287063 -0.417912 0.42339 +v -0.284862 -0.410239 0.304857 +v -0.19621 -0.447285 0.538732 +v -0.218649 -0.474853 0.619945 +v -0.320467 -0.390454 0.538527 +v -0.257025 -0.429064 0.536591 +v -0.328715 -0.192761 -0.0778193 +v -0.221157 -0.120393 -0.146058 +v -0.12147 -0.249274 -0.145022 +v -0.240602 -0.341214 -0.117452 +v -0.229478 -0.212011 -0.133147 +v -0.237075 0.0521949 -0.0759725 +v -0.139893 -0.0548182 -0.181103 +v -0.307987 -0.0331195 -0.049691 +v -0.227173 -0.0372356 -0.128413 +v -0.211816 -0.394732 0.922409 +v -0.117499 -0.281642 0.935739 +v -0.213279 -0.204742 0.922518 +v -0.301492 -0.292885 0.870674 +v -0.215547 -0.286415 0.919674 +v -0.385194 -0.351205 0.0306159 +v -0.382458 -0.25968 0.176197 +v -0.364968 -0.12541 0.046235 +v -0.375418 -0.216313 0.0359591 +v -0.361147 -0.316624 0.430338 +v -0.382575 -0.209764 0.311653 +v -0.374384 -0.294532 0.308248 +v -0.365146 -0.0406368 0.324829 +v -0.385132 -0.101185 0.188168 +v -0.368668 -0.137134 0.438729 +v -0.381949 -0.125584 0.315412 +v -0.350232 0.00253885 0.0908221 +v -0.361458 -0.0619596 0.0609153 +v -0.328019 -0.223318 0.773747 +v -0.341862 -0.313907 0.657949 +v -0.343331 -0.409171 0.778577 +v -0.336544 -0.303107 0.775339 +v -0.322487 -0.0565049 0.774019 +v -0.351001 -0.142438 0.668828 +v -0.283052 -0.132631 0.863571 +v -0.329 -0.140489 0.774308 +v -0.357572 -0.233122 0.551664 +v -0.349301 -0.0521301 0.560904 +v -0.360647 -0.141814 0.556564 +v -0.349272 -0.319879 0.544579 +v -0.272682 0.181352 0.189589 +v -0.221341 0.236481 0.293418 +v -0.170184 0.299829 0.20555 +v -0.23281 0.229543 0.110217 +v -0.227226 0.252859 0.204008 +v -0.20969 0.164574 0.478658 +v -0.153276 0.244216 0.39384 +v -0.271155 0.129527 0.366223 +v -0.215375 0.198113 0.382954 +v -0.187262 0.086887 0.854887 +v -0.134533 0.161682 0.796578 +v -0.198521 0.154682 0.689709 +v -0.24282 0.0875955 0.770725 +v -0.191558 0.132026 0.78245 +v -0.26179 0.101674 0.574769 +v -0.141545 0.196582 0.593509 +v -0.204392 0.157257 0.584394 +v -0.317321 0.0335117 0.454173 +v -0.327755 0.0676272 0.239516 +v -0.324726 0.0469262 0.344192 +v -0.253941 0.0157408 0.848168 +v -0.307072 0.0296092 0.675079 +v -0.289863 0.0225221 0.77107 +v -0.288174 0.116771 0.0639197 +v -0.190901 0.188016 -0.0300482 +v -0.239299 0.151564 0.0118342 +v -0.313467 0.030566 0.566851 +v -0.317033 0.0909783 0.142973 +v -0.150923 0.290686 0.0162651 +v -0.192003 0.257627 -0.114007 +v -0.150018 0.148066 -0.170355 +v -0.172619 0.221245 -0.0722104 +v -0.194068 0.37243 -0.0269037 +v -0.294876 0.383503 -0.203773 +v -0.274031 0.23831 -0.301318 +v -0.248629 0.311098 -0.153862 +v -0.324701 0.24108 -0.502727 +v -0.23911 0.14497 -0.502892 +v -0.196806 0.141274 -0.362924 +v -0.278147 0.181024 -0.423508 +v -0.318198 0.390558 -0.446528 +v -0.250979 0.388662 -0.601302 +v -0.263786 0.27805 -0.630217 +v -0.314593 0.32071 -0.563292 +v -0.238161 -0.677382 -0.0918856 +v -0.12828 -0.689708 0.0245746 +v -0.228165 -0.692422 0.147407 +v -0.338046 -0.680095 0.0309463 +v -0.229681 -0.733842 0.0266899 +v -0.291818 -0.690195 0.788408 +v -0.199176 -0.699686 0.68654 +v -0.107919 -0.696884 0.796995 +v -0.20056 -0.687393 0.898863 +v -0.198244 -0.736784 0.793448 +v -0.294592 -0.571581 0.678753 +v -0.307855 -0.55258 0.89062 +v -0.335563 -0.561971 0.78431 +v -0.102733 -0.558625 0.896274 +v -0.110927 -0.595142 0.691599 +v -0.0593616 -0.458076 0.795932 +v -0.0716769 -0.583028 0.796447 +v -0.203007 -0.591569 0.647127 +v -0.206666 -0.553636 0.930804 +v -0.352933 -0.520557 -0.0885122 +v -0.339121 -0.546516 0.150832 +v -0.383244 -0.532332 0.0297109 +v -0.132569 -0.534652 -0.0767316 +v -0.24402 -0.524662 -0.124285 +v -0.143499 -0.577512 0.141914 +v -0.241073 -0.571789 0.188527 +v -0.0964942 -0.434904 0.0342915 +v -0.0999951 -0.56397 0.0317575 +v -0.23851 0.520387 -0.0907886 +v -0.282894 0.56989 -0.257283 +v -0.271576 0.561647 -0.416318 +v -0.293195 0.482084 -0.276654 +v -0.32688 0.680784 -0.145207 +v -0.422878 0.632073 -0.168661 +v -0.321376 0.576724 -0.185683 +v -0.213045 0.609177 -0.109989 +v -0.326345 0.612341 -0.141546 +v -0.379053 0.63587 -0.283895 +v -0.312594 0.674309 -0.341185 +v -0.3154 0.606871 -0.278418 +v -0.460287 0.727236 -0.177367 +v -0.417773 0.731266 -0.288914 +v -0.454185 0.684351 -0.230461 +v -0.0922474 0.320203 0.127906 +v -0.0857686 0.301184 0.309872 +v -0.0910385 0.318251 0.216664 +v -0.0750596 0.22755 0.493766 +v -0.0710686 0.213115 0.708099 +v -0.0724773 0.219588 0.599773 +v -0.0670456 0.125156 0.886255 +v -0.0695062 0.18012 0.806775 +v -0.0661753 -0.432919 0.0879789 +v -0.0502685 -0.34467 -0.0665397 +v -0.056363 -0.399912 0.0126968 +v -0.0361117 -0.34665 0.891624 +v -0.0398588 -0.442711 0.714357 +v -0.0321101 -0.404726 0.804765 +v -0.0798727 0.262384 0.399618 +v -0.0874752 0.345901 0.0284499 +v -0.0858416 0.32349 0.0605597 +v -0.124296 0.487548 0.0340513 +v -0.105997 0.402715 0.0360884 +v -0.136392 0.50382 -0.556974 +v -0.214286 0.629383 -0.484754 +v -0.104733 0.755088 -0.444831 +v -0.121817 0.636846 -0.502061 +v -0.139278 0.340909 -0.661549 +v -0.138945 0.411476 -0.620153 +v -0.0622199 -0.197393 0.966789 +v -0.0501277 -0.274014 0.941915 +v -0.0553298 -0.185801 -0.197022 +v -0.050202 -0.275405 -0.142323 +v -0.0766662 0.0457919 -0.217551 +v -0.0655056 -0.0670069 -0.214493 +v -0.0933959 0.130309 -0.285229 +v -0.0838463 0.11062 -0.238883 +v -0.114603 0.104637 -0.445501 +v -0.102596 0.115199 -0.359834 +v -0.153665 0.185489 -0.611191 +v -0.137484 0.129002 -0.534091 +v -0.150371 0.262453 -0.657355 +v -0.0819636 0.707011 -0.0978848 +v -0.128934 0.593549 -0.0276065 +v -0.230899 0.696193 -0.415496 +v -0.2462 0.632058 -0.451998 +v -0.199042 0.926972 -0.236591 +v -0.155831 0.94592 -0.253016 +v -0.182289 0.937359 -0.304334 +v -0.2255 0.918412 -0.287909 +v -0.198381 0.950853 -0.26973 +v -0.204856 0.767832 -0.258627 +v -0.198135 0.804412 -0.300184 +v -0.162591 0.796641 -0.337706 +v -0.195536 0.768708 -0.323732 +v -0.190344 0.780419 -0.305321 +v -0.18859 0.771476 -0.215131 +v -0.12548 0.786281 -0.190531 +v -0.102838 0.815304 -0.21903 +v -0.158595 0.817014 -0.220186 +v -0.14521 0.793415 -0.208712 +v -0.134346 0.834135 -0.324328 +v -0.0911506 0.822276 -0.28966 +v -0.113814 0.810725 -0.339255 +v -0.12321 0.811864 -0.327105 +v -0.0956349 0.846841 -0.248877 +v -0.0699464 0.823757 -0.248502 +v -0.0836698 0.824545 -0.249204 +v -0.246443 0.756953 -0.257453 +v -0.24364 0.757848 -0.207433 +v -0.21289 0.762245 -0.22883 +v -0.249966 0.723503 -0.332259 +v -0.355751 0.762428 -0.238497 +v -0.32003 0.739642 -0.304714 +v -0.181848 0.741315 -0.180043 +v -0.328516 0.741977 -0.181175 +v -0.0499681 0.812176 -0.199395 +v -0.0788354 0.774284 -0.158189 +v -0.168022 0.778755 -0.386065 +v -0.0505691 0.828853 -0.304368 +v -0.0897195 0.811796 -0.373587 +v -0.0404745 0.828353 -0.247459 +v -0.211302 0.744371 -0.365196 +v -0.216553 0.856661 -0.251136 +v -0.193702 0.87269 -0.329392 +v -0.218551 0.860755 -0.297102 +v -0.126841 0.897388 -0.285836 +v -0.157513 0.887986 -0.320358 +v -0.138938 0.890583 -0.222912 +v -0.120161 0.900194 -0.247801 +v -0.181137 0.872948 -0.224154 +v -0.218865 -0.458568 0.419816 +v -0.156751 -0.485651 0.517662 +v -0.106299 -0.467348 0.612794 +v -0.177713 -0.464461 0.527871 +v -0.0640756 -0.481225 0.60015 +v -0.0486808 -0.462533 0.655449 +v -0.0674919 -0.459184 0.218582 +v -0.129769 -0.445891 0.210992 +v -0.0638357 -0.444618 0.15006 +v -0.160168 -0.471758 0.313909 +v -0.192938 -0.45045 0.307624 +v -0.106971 -0.518553 0.416032 +v -0.0913755 -0.507594 0.518132 +v -0.0906862 -0.492986 0.310407 +v -0.152295 -0.0598695 0.957881 +v -0.109744 -0.0412763 0.976341 +v -0.148938 -0.0188178 0.950827 +v -0.133131 -0.0374762 0.965091 +v -0.214922 -0.0472768 0.917853 +v -0.129144 -0.123186 0.961976 +v -0.202946 -0.113321 0.930645 +v -0.124777 0.0448234 0.926767 +v -0.189431 0.0176502 0.907717 +v -0.0541294 -0.000582154 0.980957 +v -0.0627521 0.0592134 0.940397 +v -0.0544734 -0.0758718 0.989219 +v -0.0631528 -0.123094 0.979468 +v -0.0717681 -0.0690106 0.994894 +v -0.052795 -0.0725924 1.01945 +v -0.0716307 -0.0432 1.00541 +v -0.0809297 -0.0558501 0.997263 +v -0.0297219 -0.0653048 1.04059 +v -0.0406958 -0.0395224 1.01839 +v -0.0297587 -0.0908237 1.02001 +v -0.0407812 -0.0765567 1.00299 +v -0.0264068 -0.0851806 1.03686 +v 0.313121 -0.40468 0.424303 +v 0.289638 -0.411984 0.363044 +v 0.317818 -0.392423 0.305485 +v 0.341299 -0.375944 0.366232 +v 0.317288 -0.397295 0.364448 +v 0.23935 -0.43199 0.361842 +v 0.251544 -0.422435 0.302332 +v 0.261632 -0.427221 0.422701 +v 0.262332 -0.422664 0.362137 +v 0.2099 -0.457622 0.202318 +v 0.274846 -0.418754 0.252658 +v 0.194817 -0.437402 0.239358 +v 0.231211 -0.430966 0.245486 +v 0.350284 -0.364453 0.244783 +v 0.312495 -0.42258 0.208415 +v 0.316601 -0.396416 0.250199 +v 0.328162 -0.387696 0.483083 +v 0.291362 -0.413379 0.536815 +v 0.275025 -0.421949 0.482067 +v 0.303426 -0.408222 0.482265 +v 0.26979 -0.455493 0.624003 +v 0.236564 -0.444228 0.584476 +v 0.315111 -0.397679 0.592146 +v 0.280089 -0.425608 0.586435 +v 0.156119 -0.458526 0.595789 +v 0.222989 -0.439421 0.53835 +v 0.164011 -0.483033 0.631406 +v 0.191143 -0.453861 0.591118 +v 0.225399 -0.440193 0.480871 +v 0.247502 -0.431674 0.481825 +v 0.300873 -0.335808 -0.11045 +v 0.23546 -0.269794 -0.12322 +v 0.283535 -0.198083 -0.11242 +v 0.339519 -0.257182 -0.0802831 +v 0.292915 -0.260195 -0.110308 +v 0.119478 -0.295776 -0.113872 +v 0.173106 -0.230478 -0.142628 +v 0.176383 -0.34915 -0.10631 +v 0.174532 -0.282877 -0.121531 +v 0.172014 -0.141551 -0.170002 +v 0.224047 -0.163495 -0.142015 +v 0.123113 -0.206388 -0.170045 +v 0.171621 -0.184999 -0.160037 +v 0.318497 -0.140059 -0.0746981 +v 0.26898 -0.103901 -0.112945 +v 0.274851 -0.146856 -0.114171 +v 0.307808 -0.00318692 -0.0317095 +v 0.269878 -0.0318881 -0.0928838 +v 0.232462 0.00608204 -0.106821 +v 0.273281 0.0420733 -0.0438498 +v 0.272342 0.00331308 -0.0724007 +v 0.222802 -0.0788504 -0.141507 +v 0.308256 -0.0631453 -0.0619102 +v 0.26804 -0.0666021 -0.106124 +v 0.131964 -0.111136 -0.188613 +v 0.182883 -0.0457092 -0.157469 +v 0.176218 -0.0952439 -0.168768 +v 0.199052 0.0623656 -0.105989 +v 0.148915 0.00578811 -0.165362 +v 0.190658 0.0074224 -0.137241 +v 0.30851 -0.340088 0.875405 +v 0.263105 -0.289222 0.900577 +v 0.214141 -0.334681 0.919903 +v 0.26887 -0.396352 0.909752 +v 0.266995 -0.336923 0.904292 +v 0.253262 -0.209214 0.897882 +v 0.215216 -0.244729 0.920604 +v 0.293898 -0.252639 0.867139 +v 0.258195 -0.248301 0.898482 +v 0.126656 -0.240414 0.945024 +v 0.164801 -0.284207 0.93026 +v 0.172003 -0.202637 0.93974 +v 0.169955 -0.242358 0.935335 +v 0.149733 -0.3934 0.920339 +v 0.104904 -0.328487 0.922781 +v 0.15673 -0.332639 0.924128 +v 0.358457 -0.200112 -0.0267162 +v 0.380901 -0.277243 0.032671 +v 0.375987 -0.340814 -0.0337268 +v 0.367895 -0.263853 -0.0306343 +v 0.342627 -0.106257 -0.015664 +v 0.369603 -0.166291 0.0406057 +v 0.349444 -0.148083 -0.0217878 +v 0.385185 -0.214712 0.178025 +v 0.382253 -0.237542 0.105277 +v 0.379025 -0.149836 0.112764 +v 0.38088 -0.190046 0.108528 +v 0.379176 -0.364086 0.102343 +v 0.375596 -0.311145 0.175939 +v 0.381399 -0.294389 0.103665 +v 0.363729 -0.333817 0.306674 +v 0.367965 -0.307651 0.370431 +v 0.351404 -0.354331 0.427814 +v 0.35769 -0.345276 0.36828 +v 0.379525 -0.278609 0.243679 +v 0.369702 -0.323364 0.243084 +v 0.386398 -0.194374 0.247084 +v 0.380079 -0.252636 0.309953 +v 0.384425 -0.235652 0.245143 +v 0.366553 -0.273812 0.432936 +v 0.376188 -0.22098 0.374406 +v 0.373629 -0.265433 0.372527 +v 0.363531 -0.0923241 0.440867 +v 0.375379 -0.132559 0.377674 +v 0.376221 -0.0834201 0.319025 +v 0.359143 -0.0454376 0.384517 +v 0.369754 -0.0887861 0.380331 +v 0.383633 -0.167556 0.313214 +v 0.370145 -0.182621 0.437038 +v 0.377148 -0.176656 0.375911 +v 0.386429 -0.137312 0.183762 +v 0.385994 -0.115397 0.252169 +v 0.387444 -0.154662 0.24911 +v 0.369328 -0.0337485 0.265179 +v 0.380073 -0.0641595 0.195141 +v 0.380479 -0.0754649 0.257209 +v 0.331012 0.0171674 0.0389716 +v 0.357964 -0.0317511 0.0731655 +v 0.338487 -0.0443826 0.00235778 +v 0.336366 -0.0157204 0.0175237 +v 0.37698 -0.0821329 0.123634 +v 0.363023 -0.0117289 0.147082 +v 0.372551 -0.0487428 0.133083 +v 0.363023 -0.0919062 0.0524717 +v 0.378431 -0.114848 0.117331 +v 0.339774 -0.073126 -0.00816016 +v 0.336842 -0.40362 0.835552 +v 0.340911 -0.350598 0.77666 +v 0.324728 -0.29766 0.82767 +v 0.331904 -0.344898 0.831349 +v 0.334716 -0.360298 0.654176 +v 0.340676 -0.308781 0.717453 +v 0.335933 -0.414813 0.716014 +v 0.339263 -0.356428 0.715872 +v 0.338685 -0.226798 0.720092 +v 0.331546 -0.262105 0.774295 +v 0.344609 -0.271269 0.661246 +v 0.339619 -0.266826 0.718796 +v 0.311718 -0.219243 0.822794 +v 0.317327 -0.257308 0.824743 +v 0.282982 -0.0932074 0.86163 +v 0.309753 -0.137557 0.821642 +v 0.32815 -0.0982774 0.774453 +v 0.304296 -0.0566442 0.818942 +v 0.309064 -0.0966912 0.82069 +v 0.328063 -0.182474 0.773912 +v 0.284251 -0.173813 0.864211 +v 0.309915 -0.178867 0.822052 +v 0.348891 -0.186539 0.666645 +v 0.342261 -0.141944 0.72292 +v 0.340465 -0.184932 0.72153 +v 0.335097 -0.0554519 0.724795 +v 0.349859 -0.0980743 0.670701 +v 0.341372 -0.0985454 0.724072 +v 0.350887 -0.0507559 0.502911 +v 0.3576 -0.096426 0.55865 +v 0.364199 -0.140124 0.498352 +v 0.360004 -0.0947951 0.500374 +v 0.356689 -0.14249 0.613383 +v 0.34723 -0.0531297 0.617509 +v 0.354744 -0.0974434 0.615492 +v 0.35206 -0.232064 0.608144 +v 0.360088 -0.187609 0.554338 +v 0.355112 -0.187591 0.610995 +v 0.363053 -0.232129 0.494204 +v 0.364779 -0.186112 0.496433 +v 0.354812 -0.320109 0.488079 +v 0.338808 -0.358381 0.541229 +v 0.344689 -0.357576 0.485189 +v 0.354746 -0.277669 0.548235 +v 0.360332 -0.277544 0.491251 +v 0.344841 -0.317709 0.600763 +v 0.349578 -0.27523 0.604646 +v 0.335024 -0.360119 0.596759 +v 0.253104 0.203435 0.118078 +v 0.22988 0.247545 0.157829 +v 0.250535 0.219935 0.200112 +v 0.270021 0.183796 0.151405 +v 0.251096 0.217673 0.158942 +v 0.173937 0.295795 0.151795 +v 0.201028 0.279793 0.204606 +v 0.208445 0.255016 0.0997486 +v 0.204742 0.274117 0.153286 +v 0.19325 0.264928 0.298974 +v 0.224342 0.248556 0.249012 +v 0.166122 0.2964 0.255682 +v 0.197174 0.276415 0.252836 +v 0.273837 0.172969 0.230557 +v 0.247672 0.201215 0.285394 +v 0.249328 0.213762 0.242242 +v 0.269047 0.115689 0.415447 +v 0.243641 0.166107 0.375362 +v 0.21248 0.178956 0.429644 +v 0.238934 0.137098 0.472953 +v 0.241351 0.149381 0.423 +v 0.218341 0.218477 0.337805 +v 0.272811 0.14513 0.319056 +v 0.245762 0.184358 0.32963 +v 0.157504 0.266542 0.348704 +v 0.185529 0.224498 0.389084 +v 0.189327 0.246276 0.344018 +v 0.178799 0.187723 0.48375 +v 0.149393 0.222637 0.439843 +v 0.181979 0.203634 0.435289 +v 0.235856 0.0765799 0.805621 +v 0.217701 0.11212 0.775527 +v 0.188626 0.112308 0.821548 +v 0.212012 0.0755801 0.841201 +v 0.213324 0.0965225 0.811853 +v 0.226814 0.130295 0.684497 +v 0.195015 0.146226 0.738197 +v 0.249108 0.0961373 0.728207 +v 0.222367 0.12354 0.732548 +v 0.136442 0.179619 0.750387 +v 0.163968 0.1484 0.789706 +v 0.169138 0.174847 0.695193 +v 0.166543 0.164739 0.744396 +v 0.159999 0.0987976 0.865373 +v 0.13257 0.138159 0.837992 +v 0.161693 0.126272 0.830304 +v 0.207042 0.158534 0.530777 +v 0.233686 0.131486 0.579487 +v 0.264402 0.101968 0.520397 +v 0.236433 0.132176 0.525634 +v 0.143538 0.198754 0.539805 +v 0.173735 0.178964 0.589175 +v 0.176115 0.180806 0.535582 +v 0.201599 0.157166 0.637907 +v 0.139858 0.195421 0.647569 +v 0.171473 0.178284 0.642915 +v 0.258575 0.102323 0.628487 +v 0.230534 0.131902 0.632959 +v 0.34742 0.00319315 0.333602 +v 0.320929 0.0389878 0.398635 +v 0.337836 -0.00655256 0.448549 +v 0.342419 -0.00261151 0.390867 +v 0.351215 0.0204208 0.221415 +v 0.327429 0.0566863 0.291075 +v 0.350974 0.0108683 0.277027 +v 0.298744 0.0894187 0.355449 +v 0.30121 0.115034 0.257783 +v 0.300703 0.102007 0.305644 +v 0.293232 0.0711038 0.460405 +v 0.296022 0.0786559 0.407077 +v 0.328122 -0.0112347 0.673608 +v 0.30029 0.0266191 0.725054 +v 0.308985 -0.0158364 0.772679 +v 0.320738 -0.0133772 0.724898 +v 0.267341 0.0573644 0.769829 +v 0.281859 0.0674534 0.67711 +v 0.275748 0.0634772 0.725933 +v 0.24017 0.0457536 0.838346 +v 0.274888 0.0183198 0.812257 +v 0.256292 0.0501447 0.807253 +v 0.268509 -0.018423 0.854481 +v 0.291897 -0.0177918 0.816142 +v 0.181753 0.135303 -0.0848536 +v 0.213035 0.170022 -0.00953204 +v 0.239418 0.102195 -0.0351077 +v 0.20757 0.117335 -0.0616182 +v 0.236523 0.195781 0.0609139 +v 0.190293 0.237055 0.0258931 +v 0.212268 0.218116 0.0448664 +v 0.276588 0.155574 0.0981021 +v 0.265278 0.133372 0.0353559 +v 0.258648 0.173682 0.0768666 +v 0.298292 0.0729821 0.0271766 +v 0.270541 0.0874645 -0.00640695 +v 0.311113 0.0304905 0.622016 +v 0.288873 0.0678482 0.57056 +v 0.286019 0.0682635 0.624906 +v 0.334099 -0.00961306 0.563635 +v 0.332102 -0.0102295 0.619617 +v 0.315185 0.0311388 0.510574 +v 0.335537 -0.00863692 0.506376 +v 0.291063 0.0681481 0.515313 +v 0.33595 0.0447295 0.115485 +v 0.324423 0.0791082 0.189745 +v 0.346277 0.0318576 0.16704 +v 0.305188 0.103086 0.100412 +v 0.320025 0.0585873 0.0683354 +v 0.295396 0.137443 0.169109 +v 0.288286 0.145212 0.129998 +v 0.299573 0.127115 0.211987 +v 0.149034 0.119255 -0.152767 +v 0.167034 0.18223 -0.122798 +v 0.177314 0.204818 -0.0510199 +v 0.168725 0.158519 -0.103729 +v 0.194921 0.221357 -0.173014 +v 0.177164 0.238112 -0.093383 +v 0.160058 0.168229 -0.195838 +v 0.175228 0.201681 -0.146613 +v 0.149721 0.3008 -0.00470029 +v 0.167426 0.259011 -0.0241111 +v 0.17918 0.290497 -0.0609743 +v 0.168557 0.27236 -0.0447148 +v 0.159665 0.285267 0.0452783 +v 0.175009 0.248965 0.00116269 +v 0.233098 0.21084 -0.267301 +v 0.26422 0.274293 -0.228207 +v 0.21819 0.281995 -0.133552 +v 0.227725 0.245742 -0.199837 +v 0.314639 0.343639 -0.292523 +v 0.27622 0.344814 -0.176785 +v 0.306638 0.268641 -0.338166 +v 0.294985 0.306469 -0.259249 +v 0.21453 0.407775 -0.0317089 +v 0.225521 0.344757 -0.0845003 +v 0.267222 0.417414 -0.116444 +v 0.249809 0.379204 -0.0978893 +v 0.173263 0.341693 -0.0238379 +v 0.200073 0.314908 -0.0732157 +v 0.192666 0.159829 -0.308601 +v 0.240251 0.15911 -0.387649 +v 0.279797 0.207117 -0.366981 +v 0.238726 0.181983 -0.331175 +v 0.213461 0.12942 -0.465108 +v 0.265715 0.160342 -0.469212 +v 0.195451 0.128497 -0.407372 +v 0.233311 0.142158 -0.432916 +v 0.305787 0.218563 -0.547441 +v 0.307399 0.208213 -0.46356 +v 0.259412 0.1698 -0.542722 +v 0.290901 0.186126 -0.509143 +v 0.330786 0.26947 -0.445487 +v 0.31171 0.235804 -0.406418 +v 0.32675 0.280027 -0.535933 +v 0.321008 0.352655 -0.511417 +v 0.329541 0.345256 -0.410956 +v 0.333345 0.309542 -0.480189 +v 0.272516 0.239582 -0.609537 +v 0.296456 0.295786 -0.60247 +v 0.307295 0.256707 -0.578835 +v 0.240548 0.35766 -0.62796 +v 0.289278 0.358786 -0.584918 +v 0.246645 0.312827 -0.640337 +v 0.274305 0.331026 -0.617491 +v 0.295245 0.436762 -0.484187 +v 0.255976 0.429549 -0.563622 +v 0.295399 0.395443 -0.540067 +v 0.335047 -0.66747 -0.026194 +v 0.288313 -0.71953 0.0292002 +v 0.233667 -0.718383 -0.0394682 +v 0.288912 -0.666279 -0.0831981 +v 0.288523 -0.704927 -0.0329901 +v 0.276152 -0.679477 0.14116 +v 0.227442 -0.724741 0.0933852 +v 0.327044 -0.674066 0.0872825 +v 0.281161 -0.710704 0.0910758 +v 0.136631 -0.686121 0.0787634 +v 0.172796 -0.723594 0.0247169 +v 0.182766 -0.687312 0.135767 +v 0.176191 -0.716151 0.0857864 +v 0.187443 -0.669698 -0.0818819 +v 0.136552 -0.67511 -0.0280042 +v 0.179633 -0.708233 -0.0350267 +v 0.2461 -0.678205 0.889508 +v 0.198896 -0.723335 0.85193 +v 0.248642 -0.724519 0.790895 +v 0.288217 -0.679435 0.838379 +v 0.246831 -0.711912 0.845432 +v 0.113033 -0.684171 0.844965 +v 0.148661 -0.727347 0.795626 +v 0.15574 -0.680004 0.892121 +v 0.151829 -0.713932 0.849146 +v 0.157976 -0.694713 0.696986 +v 0.198408 -0.728532 0.734591 +v 0.115859 -0.693483 0.748115 +v 0.153047 -0.720555 0.741401 +v 0.283587 -0.684515 0.738785 +v 0.24088 -0.688682 0.691628 +v 0.244434 -0.716483 0.736358 +v 0.342489 -0.483419 0.78141 +v 0.32282 -0.565952 0.726198 +v 0.30391 -0.498066 0.668956 +v 0.331237 -0.488983 0.719836 +v 0.31354 -0.474577 0.887895 +v 0.331331 -0.556659 0.842236 +v 0.337524 -0.478425 0.840051 +v 0.319732 -0.633454 0.786428 +v 0.294197 -0.618974 0.884469 +v 0.315639 -0.625673 0.839496 +v 0.28283 -0.632563 0.691009 +v 0.308326 -0.632734 0.733956 +v 0.0634711 -0.431765 0.851899 +v 0.0654567 -0.515878 0.79543 +v 0.0774719 -0.570173 0.85133 +v 0.0969194 -0.478778 0.897495 +v 0.0707234 -0.496321 0.852392 +v 0.106684 -0.534636 0.682874 +v 0.0832655 -0.591144 0.740087 +v 0.069956 -0.47422 0.735292 +v 0.0773661 -0.528459 0.735056 +v 0.0840444 -0.64607 0.797118 +v 0.119063 -0.647679 0.702012 +v 0.0943475 -0.648249 0.746058 +v 0.112805 -0.624088 0.888986 +v 0.0899111 -0.634521 0.847274 +v 0.252371 -0.581833 0.652832 +v 0.208287 -0.52835 0.637223 +v 0.260651 -0.513618 0.642398 +v 0.20034 -0.651356 0.660475 +v 0.244653 -0.641994 0.666514 +v 0.15335 -0.595644 0.66033 +v 0.156436 -0.650983 0.672896 +v 0.153645 -0.534978 0.650489 +v 0.149543 -0.554429 0.922812 +v 0.209392 -0.47177 0.928314 +v 0.147798 -0.472236 0.922294 +v 0.203436 -0.628169 0.923071 +v 0.153584 -0.625261 0.914716 +v 0.262868 -0.552296 0.920108 +v 0.253551 -0.622939 0.912658 +v 0.267734 -0.472455 0.917082 +v 0.348561 -0.464054 0.158716 +v 0.369537 -0.538419 0.0961211 +v 0.387436 -0.440321 0.0296682 +v 0.376444 -0.45013 0.0999599 +v 0.368236 -0.614976 0.0306267 +v 0.325558 -0.615423 0.139592 +v 0.354786 -0.614851 0.0904298 +v 0.340742 -0.597899 -0.0798229 +v 0.378455 -0.525308 -0.0356201 +v 0.364087 -0.605614 -0.0296813 +v 0.354445 -0.427851 -0.0878125 +v 0.380964 -0.432504 -0.0361787 +v 0.243518 -0.430642 -0.121062 +v 0.182701 -0.527846 -0.109937 +v 0.12704 -0.448099 -0.0735785 +v 0.179139 -0.436248 -0.106528 +v 0.304443 -0.521287 -0.117606 +v 0.305291 -0.427537 -0.115465 +v 0.241923 -0.609859 -0.117359 +v 0.296601 -0.602967 -0.109127 +v 0.141316 -0.607217 -0.0730372 +v 0.186967 -0.607615 -0.104287 +v 0.148115 -0.512563 0.149929 +v 0.188536 -0.577394 0.174934 +v 0.25113 -0.502745 0.197094 +v 0.196177 -0.511769 0.183546 +v 0.233064 -0.638226 0.175543 +v 0.145237 -0.635178 0.13052 +v 0.185474 -0.638484 0.162245 +v 0.293784 -0.559568 0.181063 +v 0.282371 -0.626877 0.167977 +v 0.304357 -0.484216 0.189956 +v 0.105712 -0.548895 -0.0268432 +v 0.0997946 -0.492468 0.0352712 +v 0.0953701 -0.405611 -0.0214782 +v 0.102107 -0.469936 -0.0239275 +v 0.106751 -0.633108 0.0275567 +v 0.114552 -0.619641 -0.0267392 +v 0.113288 -0.573273 0.0910993 +v 0.117988 -0.635837 0.0828 +v 0.112515 -0.451919 0.0935688 +v 0.115559 -0.506404 0.0968639 +v 0.271184 0.525759 -0.460079 +v 0.285353 0.520853 -0.361551 +v 0.308658 0.43336 -0.368305 +v 0.291391 0.478507 -0.418527 +v 0.278055 0.600765 -0.320108 +v 0.282577 0.535883 -0.259681 +v 0.267 0.601931 -0.388185 +v 0.278645 0.563976 -0.33172 +v 0.247008 0.54474 -0.114114 +v 0.271214 0.498067 -0.167977 +v 0.277875 0.55689 -0.190965 +v 0.271665 0.531425 -0.180446 +v 0.298509 0.427522 -0.236282 +v 0.235335 0.485531 -0.0647615 +v 0.272045 0.45855 -0.143225 +v 0.317802 0.38717 -0.32759 +v 0.192626 0.647576 -0.125774 +v 0.267679 0.610284 -0.129549 +v 0.326452 0.645309 -0.138504 +v 0.252363 0.682167 -0.15033 +v 0.258116 0.645451 -0.13607 +v 0.289471 0.569074 -0.162469 +v 0.324346 0.587714 -0.15672 +v 0.239082 0.578957 -0.111996 +v 0.279361 0.583208 -0.137022 +v 0.401583 0.612716 -0.19176 +v 0.380321 0.61857 -0.152413 +v 0.35448 0.589213 -0.202564 +v 0.367842 0.597467 -0.17194 +v 0.388682 0.680406 -0.144893 +v 0.430349 0.658277 -0.154382 +v 0.384792 0.647908 -0.143704 +v 0.294439 0.591849 -0.266039 +v 0.318359 0.584666 -0.230094 +v 0.294318 0.572729 -0.209871 +v 0.28588 0.662049 -0.349089 +v 0.312606 0.638668 -0.319124 +v 0.290372 0.624108 -0.317788 +v 0.375881 0.662505 -0.310821 +v 0.343967 0.620068 -0.286887 +v 0.345079 0.681327 -0.333156 +v 0.34177 0.649107 -0.318477 +v 0.380591 0.614582 -0.245535 +v 0.347363 0.598425 -0.244565 +v 0.393743 0.706765 -0.3123 +v 0.444197 0.711394 -0.263256 +v 0.419572 0.658706 -0.261892 +v 0.412958 0.685943 -0.291128 +v 0.452589 0.744444 -0.206816 +v 0.471552 0.708579 -0.199184 +v 0.43241 0.746455 -0.258303 +v 0.460792 0.730831 -0.231063 +v 0.447289 0.655956 -0.196803 +v 0.447397 0.702392 -0.15815 +v 0.460337 0.681448 -0.17325 +v 0.417303 0.633713 -0.225256 +v 0 0.324094 0.180165 +v 0.0462436 0.320164 0.221337 +v 0.0925539 0.320139 0.170699 +v 0.0467382 0.325284 0.136739 +v 0.0468991 0.323707 0.17766 +v 0.0434892 0.30185 0.311934 +v 0.0886491 0.312396 0.263435 +v 0 0.312812 0.267846 +v 0.0450231 0.313323 0.266515 +v 0.132936 0.312061 0.210485 +v 0.125628 0.296564 0.306829 +v 0.129481 0.307575 0.259519 +v 0.135299 0.30832 0.112598 +v 0.13572 0.310986 0.159838 +v 0 0.228164 0.547798 +v 0.0364517 0.2252 0.601479 +v 0.0735327 0.221293 0.545706 +v 0.0377827 0.232065 0.495188 +v 0.0369868 0.226526 0.54726 +v 0.0357781 0.218679 0.710249 +v 0.0717153 0.218255 0.65442 +v 0 0.22586 0.657001 +v 0.0360809 0.22396 0.656319 +v 0.107651 0.210086 0.597079 +v 0.105384 0.203917 0.704755 +v 0.106456 0.208743 0.651454 +v 0.111325 0.219111 0.491389 +v 0.109197 0.212143 0.543201 +v 0 0.20702 0.762635 +v 0.035033 0.18494 0.809623 +v 0.0703592 0.199987 0.759265 +v 0.0354469 0.205232 0.761742 +v 0.0337403 0.129119 0.889852 +v 0.0684286 0.154761 0.849486 +v 0 0.160642 0.853891 +v 0.0344822 0.159128 0.852718 +v 0.10286 0.172311 0.802347 +v 0.0994805 0.118705 0.880737 +v 0.101303 0.147713 0.844481 +v 0.104202 0.191409 0.755412 +v 0 -0.422236 0.0297518 +v 0.0290027 -0.401336 0.00260959 +v 0.0619855 -0.419454 0.0516405 +v 0.032544 -0.433336 0.0684456 +v 0.0312142 -0.420036 0.03584 +v 0.024587 -0.350255 -0.0669927 +v 0.0524989 -0.374486 -0.0268658 +v 0 -0.38147 -0.0341137 +v 0.0265726 -0.377866 -0.0315624 +v 0.0804386 -0.407577 0.025012 +v 0.0781392 -0.343402 -0.0680291 +v 0.0771327 -0.378765 -0.022981 +v 0.101981 -0.43742 0.118873 +v 0.0918712 -0.426509 0.0746889 +v 0 -0.369655 0.853165 +v 0.0162142 -0.396858 0.808469 +v 0.032518 -0.377955 0.851217 +v 0.0173499 -0.340897 0.891348 +v 0.0161103 -0.370733 0.852319 +v 0.0190571 -0.436735 0.723869 +v 0.0352263 -0.426311 0.757202 +v 0 -0.417485 0.766409 +v 0.0173127 -0.418962 0.764189 +v 0.0473693 -0.423079 0.799815 +v 0.0641499 -0.454693 0.696538 +v 0.0543417 -0.44245 0.745122 +v 0.0576974 -0.360469 0.893822 +v 0.0495204 -0.395304 0.851292 +v 0 0.284012 0.356829 +v 0.0403407 0.264584 0.4009 +v 0.08278 0.283223 0.354838 +v 0.0418935 0.284411 0.356338 +v 0.0772361 0.242537 0.445498 +v 0 0.24666 0.447191 +v 0.0389355 0.245943 0.446792 +v 0.117787 0.25622 0.397308 +v 0.114267 0.235186 0.443214 +v 0.121652 0.278062 0.352302 +v 0 0.337744 0.0495788 +v 0.0441574 0.329119 0.0693112 +v 0.084777 0.331134 0.0392602 +v 0.0448664 0.351036 0.0368917 +v 0.0436281 0.336529 0.047541 +v 0.0891709 0.320583 0.0906503 +v 0 0.327327 0.102505 +v 0.0455092 0.326229 0.0998335 +v 0.122579 0.311429 0.0436831 +v 0.129137 0.308034 0.0737864 +v 0.125569 0.33518 0.0110101 +v 0.120968 0.319807 0.0225689 +v 0 0.450581 0.0596803 +v 0.0541098 0.40816 0.0483714 +v 0.116503 0.442256 0.0399308 +v 0.0632284 0.496693 0.0522852 +v 0.0593708 0.448955 0.0551193 +v 0.0954346 0.370179 0.029827 +v 0 0.37634 0.0420973 +v 0.0488177 0.375217 0.039732 +v 0.153438 0.391277 0.0121446 +v 0.13765 0.35956 0.0095734 +v 0.18104 0.470039 0.00485434 +v 0.169159 0.42866 0.0126096 +v 0 0.570891 -0.534672 +v 0.0626485 0.640189 -0.506046 +v 0.130136 0.568004 -0.528764 +v 0.0692761 0.505582 -0.562042 +v 0.0664738 0.570216 -0.533525 +v 0.0536794 0.762368 -0.447664 +v 0.113201 0.701726 -0.474505 +v 0 0.709164 -0.479338 +v 0.0582379 0.707055 -0.477971 +v 0.199905 0.685497 -0.462496 +v 0.174025 0.632377 -0.495223 +v 0.150533 0.744043 -0.44196 +v 0.161614 0.694175 -0.469576 +v 0.199187 0.49892 -0.545668 +v 0.232047 0.565216 -0.501918 +v 0.188173 0.564066 -0.51907 +v 0 0.376475 -0.648788 +v 0.0711811 0.413275 -0.623292 +v 0.138282 0.375681 -0.645424 +v 0.0726958 0.340957 -0.664799 +v 0.0716465 0.376815 -0.648416 +v 0.138821 0.452917 -0.589054 +v 0 0.45452 -0.593995 +v 0.0706181 0.454733 -0.593233 +v 0.199873 0.404748 -0.612935 +v 0.202195 0.446614 -0.579567 +v 0.193634 0.339499 -0.652866 +v 0.194895 0.370921 -0.637938 +v 0 -0.233549 0.959877 +v 0.0240468 -0.271835 0.943264 +v 0.057123 -0.235922 0.956621 +v 0.0306399 -0.195728 0.970285 +v 0.0277858 -0.234252 0.959139 +v 0.0425527 -0.311463 0.921053 +v 0 -0.306916 0.921405 +v 0.0202817 -0.307657 0.921165 +v 0.0802769 -0.277764 0.939515 +v 0.0688023 -0.319918 0.921674 +v 0.0956803 -0.199455 0.960676 +v 0.0895627 -0.238122 0.952018 +v 0 -0.322733 -0.103397 +v 0.0238367 -0.283103 -0.139843 +v 0.049547 -0.311956 -0.105817 +v 0.023709 -0.319134 -0.103998 +v 0.0267024 -0.190718 -0.197111 +v 0.0521008 -0.23408 -0.173683 +v 0 -0.242929 -0.170415 +v 0.0248684 -0.240765 -0.171792 +v 0.0816243 -0.264189 -0.144485 +v 0.0878074 -0.176513 -0.193941 +v 0.0840611 -0.222685 -0.173847 +v 0.0796433 -0.304819 -0.108871 +v 0 -0.132321 -0.213832 +v 0.0321871 -0.0691596 -0.222731 +v 0.0599751 -0.128388 -0.209467 +v 0.0292367 -0.131565 -0.213064 +v 0.0381981 0.0419961 -0.235526 +v 0.0713902 -0.00682142 -0.215572 +v 0 -0.00964083 -0.233734 +v 0.035269 -0.00935459 -0.229192 +v 0.101087 -0.0620719 -0.200364 +v 0.115674 0.055105 -0.187883 +v 0.109216 -0.00036684 -0.192884 +v 0.0937169 -0.121882 -0.201748 +v 0 0.0779149 -0.251636 +v 0.0428926 0.103386 -0.257977 +v 0.0803711 0.0844567 -0.225271 +v 0.0406901 0.0790388 -0.244814 +v 0.0470212 0.120443 -0.299626 +v 0.0884331 0.12573 -0.258533 +v 0 0.114136 -0.282485 +v 0.0449537 0.11665 -0.27594 +v 0.120922 0.124855 -0.209363 +v 0.138478 0.148595 -0.265069 +v 0.128964 0.142918 -0.232488 +v 0.118034 0.096215 -0.193935 +v 0 0.113801 -0.334664 +v 0.0518947 0.108853 -0.365753 +v 0.097999 0.124878 -0.319976 +v 0.0492429 0.116377 -0.329956 +v 0.0595919 0.101024 -0.449026 +v 0.107541 0.107031 -0.401861 +v 0 0.101009 -0.408276 +v 0.0552525 0.102268 -0.405836 +v 0.150911 0.126322 -0.356271 +v 0.16045 0.112915 -0.441079 +v 0.153901 0.116281 -0.399697 +v 0.145782 0.140078 -0.308863 +v 0 0.109177 -0.495145 +v 0.0709982 0.126709 -0.538642 +v 0.125551 0.112279 -0.490196 +v 0.065189 0.10952 -0.494143 +v 0.0790718 0.182988 -0.615599 +v 0.1475 0.153854 -0.575332 +v 0 0.151226 -0.580589 +v 0.0759743 0.151547 -0.579976 +v 0.194944 0.134806 -0.523346 +v 0.219301 0.191387 -0.600189 +v 0.210129 0.15949 -0.56385 +v 0.176258 0.119186 -0.482359 +v 0 0.219576 -0.64342 +v 0.0775425 0.260206 -0.661002 +v 0.154044 0.222564 -0.638941 +v 0.0792455 0.219987 -0.642965 +v 0.144378 0.302534 -0.665208 +v 0 0.300969 -0.668909 +v 0.0750102 0.301309 -0.668637 +v 0.213772 0.26767 -0.647803 +v 0.202463 0.304851 -0.656009 +v 0.21995 0.228648 -0.628685 +v 0.126715 0.537337 0.0111468 +v 0.0606884 0.60785 0.00104436 +v 0 0.554408 0.0408567 +v 0.0643107 0.550463 0.0321785 +v 0.191637 0.550233 -0.0477524 +v 0.185308 0.513743 -0.0172354 +v 0.171165 0.605799 -0.0764289 +v 0.209701 0.569968 -0.0807895 +v 0.126096 0.69557 -0.127071 +v 0.0987466 0.656786 -0.062447 +v 0.142824 0.650926 -0.0969906 +v 0 0.672219 -0.0228265 +v 0.0403517 0.7183 -0.0719016 +v 0.0504326 0.666442 -0.034872 +v 0.237614 0.630468 -0.469873 +v 0.258514 0.602197 -0.445199 +v 0.253217 0.578269 -0.474783 +v 0.212896 0.714905 -0.428435 +v 0.240943 0.662224 -0.43894 +v 0.224501 0.676789 -0.452578 +v 0.246529 0.67248 -0.397952 +v 0.254771 0.635976 -0.4207 +v 0.226436 0.912723 -0.26973 +v 0.21544 0.938681 -0.279423 +v 0.201014 0.943338 -0.25145 +v 0.214224 0.916672 -0.246046 +v 0.216965 0.931825 -0.261167 +v 0.196917 0.927676 -0.311546 +v 0.191876 0.948989 -0.288378 +v 0.216862 0.918936 -0.303965 +v 0.207634 0.937732 -0.29671 +v 0.1537 0.943252 -0.269054 +v 0.17745 0.953646 -0.260405 +v 0.165912 0.939303 -0.292739 +v 0.173109 0.951035 -0.277835 +v 0.179801 0.930945 -0.23207 +v 0.159856 0.939686 -0.239651 +v 0.180783 0.946411 -0.244635 +v 0.207814 0.759869 -0.30299 +v 0.191438 0.774734 -0.312022 +v 0.199084 0.77337 -0.281405 +v 0.209996 0.761876 -0.268358 +v 0.201734 0.767127 -0.28955 +v 0.161743 0.793141 -0.342758 +v 0.178221 0.788374 -0.325575 +v 0.180956 0.7796 -0.34144 +v 0.178357 0.783728 -0.331262 +v 0.18742 0.811743 -0.321532 +v 0.192387 0.789092 -0.301842 +v 0.165819 0.804418 -0.335288 +v 0.181068 0.796668 -0.322844 +v 0.202175 0.775482 -0.251997 +v 0.203233 0.797472 -0.273932 +v 0.199221 0.78193 -0.2764 +v 0.181336 0.804317 -0.228606 +v 0.151415 0.801648 -0.215482 +v 0.168503 0.781447 -0.210541 +v 0.192516 0.777938 -0.227759 +v 0.174268 0.789156 -0.220565 +v 0.108345 0.822919 -0.221075 +v 0.12229 0.805309 -0.211386 +v 0.135327 0.828572 -0.217894 +v 0.128262 0.813355 -0.215464 +v 0.103071 0.800257 -0.198013 +v 0.137434 0.789176 -0.20042 +v 0.0963023 0.812563 -0.21585 +v 0.114773 0.801816 -0.205592 +v 0.186175 0.766882 -0.204739 +v 0.153638 0.772539 -0.191376 +v 0.162292 0.776737 -0.200861 +v 0.13845 0.801677 -0.350685 +v 0.119159 0.809804 -0.331351 +v 0.143329 0.804627 -0.337252 +v 0.140844 0.802002 -0.341998 +v 0.086003 0.820458 -0.291304 +v 0.10501 0.817882 -0.310157 +v 0.0934554 0.817549 -0.318853 +v 0.100185 0.816042 -0.313185 +v 0.116614 0.840248 -0.308051 +v 0.127696 0.819206 -0.325202 +v 0.0961567 0.829666 -0.288835 +v 0.109848 0.825231 -0.308777 +v 0.153713 0.826966 -0.334024 +v 0.147191 0.8121 -0.335056 +v 0.0710179 0.824335 -0.270682 +v 0.0780919 0.822576 -0.248928 +v 0.084054 0.824638 -0.268864 +v 0.0786961 0.822795 -0.269513 +v 0.0899479 0.821575 -0.232115 +v 0.0751675 0.819879 -0.228529 +v 0.084018 0.819324 -0.230668 +v 0.102029 0.843892 -0.232989 +v 0.0888081 0.831892 -0.249223 +v 0.095203 0.828981 -0.232883 +v 0.0959818 0.847028 -0.267898 +v 0.0891348 0.832003 -0.268429 +v 0.208076 0.764415 -0.241789 +v 0.226075 0.759994 -0.240858 +v 0.231902 0.754223 -0.26947 +v 0.216972 0.759952 -0.252956 +v 0.20189 0.765574 -0.22074 +v 0.201854 0.770051 -0.234112 +v 0.215759 0.757673 -0.200462 +v 0.223444 0.760451 -0.217689 +v 0.205912 0.761992 -0.209879 +v 0.264144 0.760816 -0.243923 +v 0.265103 0.760852 -0.220189 +v 0.240714 0.760641 -0.229576 +v 0.278995 0.751255 -0.279238 +v 0.277858 0.727498 -0.319523 +v 0.234872 0.742799 -0.306286 +v 0.256224 0.744786 -0.293184 +v 0.311167 0.763685 -0.236173 +v 0.343965 0.756617 -0.269721 +v 0.300161 0.759231 -0.259113 +v 0.37536 0.738148 -0.30116 +v 0.402685 0.758643 -0.236201 +v 0.390758 0.753705 -0.27032 +v 0.317986 0.708047 -0.333577 +v 0.358205 0.712515 -0.324745 +v 0.258236 0.693552 -0.356883 +v 0.284726 0.698216 -0.343913 +v 0.183529 0.754714 -0.188935 +v 0.248651 0.737773 -0.18066 +v 0.277376 0.753251 -0.197126 +v 0.23327 0.750984 -0.191422 +v 0.329845 0.712932 -0.159268 +v 0.178779 0.718135 -0.16643 +v 0.252112 0.713887 -0.166078 +v 0.409003 0.736167 -0.174314 +v 0.39942 0.710994 -0.155057 +v 0.352617 0.756796 -0.208565 +v 0.409429 0.752424 -0.202781 +v 0.303456 0.759588 -0.213776 +v 0.0705006 0.811753 -0.205807 +v 0.0602661 0.797425 -0.177797 +v 0.106741 0.782082 -0.178969 +v 0.0845451 0.798015 -0.188581 +v 0 0.80352 -0.16013 +v 0.0359638 0.781745 -0.13792 +v 0.0258744 0.814456 -0.19275 +v 0.0313039 0.800824 -0.16616 +v 0.0771688 0.744134 -0.128582 +v 0 0.760454 -0.0953915 +v 0.0372542 0.755486 -0.106376 +v 0.128352 0.75368 -0.16956 +v 0.122404 0.729951 -0.151266 +v 0.140544 0.766364 -0.181936 +v 0.0269807 0.832763 -0.306956 +v 0.0647564 0.824008 -0.337021 +v 0.0438017 0.818098 -0.377412 +v 0 0.831312 -0.342444 +v 0.0352238 0.828719 -0.341387 +v 0.105446 0.812324 -0.352131 +v 0.0673729 0.8251 -0.299446 +v 0.0829065 0.820245 -0.328154 +v 0.163948 0.787613 -0.366372 +v 0.134148 0.794627 -0.38492 +v 0.134862 0.801108 -0.364702 +v 0.0968568 0.789376 -0.411772 +v 0.176513 0.760515 -0.410655 +v 0.140375 0.776566 -0.412207 +v 0 0.800708 -0.414889 +v 0.0494105 0.797681 -0.413491 +v 0.0431316 0.822381 -0.222498 +v 0.0209585 0.83068 -0.246717 +v 0 0.825505 -0.217769 +v 0.0222752 0.824379 -0.219341 +v 0.0571055 0.825864 -0.248034 +v 0.0611506 0.820889 -0.225684 +v 0.0427143 0.830406 -0.274631 +v 0.0589761 0.827121 -0.27268 +v 0 0.834904 -0.275945 +v 0.0223763 0.833445 -0.275661 +v 0.192333 0.761236 -0.378584 +v 0.220893 0.723503 -0.390265 +v 0.20182 0.742487 -0.402976 +v 0.202503 0.759013 -0.342238 +v 0.185497 0.772855 -0.357643 +v 0.229147 0.73046 -0.348619 +v 0.217964 0.748268 -0.323878 +v 0.238328 0.704586 -0.373617 +v 0.182638 0.844163 -0.332751 +v 0.20855 0.866089 -0.317157 +v 0.208154 0.830042 -0.298948 +v 0.197796 0.836731 -0.320106 +v 0.225435 0.891324 -0.293612 +v 0.202088 0.898609 -0.32219 +v 0.216036 0.894273 -0.311279 +v 0.221713 0.885753 -0.253374 +v 0.22169 0.856724 -0.273536 +v 0.227222 0.886884 -0.273083 +v 0.207473 0.823979 -0.249259 +v 0.212209 0.824662 -0.273398 +v 0.113654 0.869597 -0.287244 +v 0.140188 0.893495 -0.304854 +v 0.144889 0.85895 -0.323167 +v 0.127225 0.865094 -0.306986 +v 0.170407 0.915574 -0.314537 +v 0.141278 0.921251 -0.283964 +v 0.154011 0.919177 -0.300925 +v 0.17602 0.88052 -0.329499 +v 0.186655 0.907214 -0.322451 +v 0.164181 0.851772 -0.332764 +v 0.125921 0.862724 -0.222037 +v 0.126235 0.896792 -0.232757 +v 0.106278 0.87162 -0.248059 +v 0.112672 0.868658 -0.232446 +v 0.136706 0.926532 -0.249134 +v 0.152825 0.914652 -0.226568 +v 0.141818 0.921807 -0.235425 +v 0.120264 0.900007 -0.266157 +v 0.136018 0.925025 -0.266007 +v 0.106638 0.871852 -0.266963 +v 0.201725 0.863227 -0.234578 +v 0.169297 0.842653 -0.222278 +v 0.191458 0.831381 -0.232334 +v 0.191735 0.902282 -0.228209 +v 0.209229 0.892731 -0.238166 +v 0.158724 0.882351 -0.220155 +v 0.171199 0.908866 -0.224253 +v 0.146124 0.853579 -0.218747 +v 0.183641 -0.455489 0.534379 +v 0.20511 -0.461837 0.475502 +v 0.228365 -0.446181 0.420977 +v 0.21326 -0.450303 0.478539 +v 0.102981 -0.465723 0.632974 +v 0.142559 -0.466669 0.57469 +v 0.143787 -0.462243 0.587914 +v 0.132033 -0.481167 0.556781 +v 0.17086 -0.474631 0.521789 +v 0.109552 -0.472057 0.595485 +v 0.140849 -0.473458 0.563316 +v 0.206663 -0.472505 0.418626 +v 0.176881 -0.48852 0.469991 +v 0.194975 -0.474631 0.472428 +v 0.0439995 -0.453929 0.682063 +v 0.0755892 -0.465387 0.639018 +v 0.0705061 -0.461083 0.663389 +v 0 -0.448613 0.69461 +v 0.0238268 -0.46053 0.664171 +v 0.0210984 -0.44987 0.691901 +v 0.0329053 -0.483094 0.604968 +v 0.0549351 -0.471091 0.629642 +v 0 -0.470799 0.638539 +v 0.0276324 -0.470883 0.636565 +v 0.0917758 -0.479034 0.591505 +v 0.0815781 -0.471375 0.616771 +v 0.065741 -0.440111 0.119726 +v 0.0317646 -0.445352 0.134276 +v 0 -0.441491 0.0941719 +v 0.0323291 -0.440606 0.100743 +v 0.138015 -0.443895 0.192281 +v 0.0965198 -0.444834 0.175662 +v 0.101319 -0.442167 0.150389 +v 0.0981278 -0.457279 0.230677 +v 0.0636123 -0.450028 0.182161 +v 0.124102 -0.450719 0.228684 +v 0.0942201 -0.449501 0.201118 +v 0 -0.451738 0.166652 +v 0.034368 -0.461296 0.211229 +v 0.0320458 -0.45108 0.17059 +v 0.205661 -0.440923 0.30331 +v 0.163536 -0.447685 0.255959 +v 0.174785 -0.442414 0.24495 +v 0.213095 -0.454425 0.36305 +v 0.224677 -0.442616 0.362277 +v 0.178344 -0.481123 0.364052 +v 0.179537 -0.460826 0.31166 +v 0.199389 -0.4673 0.363772 +v 0.138385 -0.462583 0.271465 +v 0.153491 -0.454897 0.266081 +v 0 -0.501354 0.566258 +v 0.0472884 -0.515301 0.519274 +v 0.0774159 -0.49456 0.56248 +v 0.0400356 -0.499329 0.565268 +v 0.0552219 -0.529321 0.415644 +v 0.102374 -0.516827 0.468605 +v 0 -0.53078 0.469003 +v 0.0529288 -0.526727 0.468796 +v 0.12906 -0.497175 0.517019 +v 0.151776 -0.503865 0.416665 +v 0.144853 -0.503338 0.468859 +v 0.109485 -0.488354 0.558077 +v 0 -0.522771 0.361177 +v 0.046641 -0.500432 0.308431 +v 0.101727 -0.509066 0.362546 +v 0.0524328 -0.518796 0.361628 +v 0.0778956 -0.474931 0.261875 +v 0 -0.481524 0.256229 +v 0.0399262 -0.479506 0.257737 +v 0.12954 -0.482953 0.312862 +v 0.111951 -0.469275 0.268257 +v 0.144743 -0.495777 0.363499 +v 0.16267 -0.0297463 0.947597 +v 0.137897 -0.0298265 0.961061 +v 0.139042 -0.0451633 0.963659 +v 0.164631 -0.0504489 0.951176 +v 0.150007 -0.038161 0.957034 +v 0.109331 -0.0304408 0.974293 +v 0.122462 -0.037914 0.969963 +v 0.130968 -0.0135459 0.956851 +v 0.124172 -0.0273895 0.966259 +v 0.133714 -0.0642499 0.965416 +v 0.109851 -0.0516794 0.976283 +v 0.125245 -0.0487781 0.969619 +v 0.172782 -0.0812671 0.947651 +v 0.213918 -0.078022 0.922841 +v 0.18873 -0.0434748 0.935764 +v 0.185903 -0.064746 0.940486 +v 0.119758 -0.0911109 0.968067 +v 0.163882 -0.120989 0.949271 +v 0.149065 -0.0885975 0.957545 +v 0.209867 -0.161573 0.925244 +v 0.133001 -0.161124 0.956956 +v 0.170754 -0.160591 0.943861 +v 0.24743 -0.125194 0.898745 +v 0.2493 -0.167014 0.898651 +v 0.247517 -0.0516572 0.891815 +v 0.248772 -0.0872467 0.896118 +v 0.206641 -0.0168625 0.913183 +v 0.165953 -0.00373407 0.934179 +v 0.181563 -0.0218941 0.9332 +v 0.225597 0.0165132 0.878354 +v 0.237857 -0.0169093 0.886885 +v 0.188508 0.055577 0.881861 +v 0.216542 0.0481267 0.863247 +v 0.128713 0.0776757 0.9026 +v 0.155037 0.0342159 0.918365 +v 0.159167 0.0664178 0.894094 +v 0.116698 0.0146029 0.948102 +v 0.143447 0.00727528 0.940085 +v 0.0272441 0.00174637 0.985368 +v 0.0591053 0.0273947 0.96148 +v 0.0314129 0.062618 0.944549 +v 0 0.031249 0.967483 +v 0.0296124 0.0304081 0.965777 +v 0.0939443 0.0532189 0.93429 +v 0.0802969 -0.0053962 0.974961 +v 0.0883591 0.0217178 0.955411 +v 0.0652762 0.0925539 0.91594 +v 0.0973395 0.0863776 0.910036 +v 0 0.0974522 0.921309 +v 0.032753 0.0962353 0.919852 +v 0.0640997 -0.158632 0.974036 +v 0.0313918 -0.121887 0.983992 +v 0 -0.156323 0.979553 +v 0.0317497 -0.157085 0.978196 +v 0.0956523 -0.123707 0.972085 +v 0.0976501 -0.160225 0.966985 +v 0.0810019 -0.0733797 0.982855 +v 0.05977 -0.0942344 0.98419 +v 0.0898671 -0.0931811 0.977114 +v 0 -0.0930316 0.990478 +v 0.0273784 -0.0760818 0.993721 +v 0.0298425 -0.0936976 0.988793 +v 0.0955999 -0.0476973 0.985969 +v 0.0789269 -0.06284 0.994959 +v 0.0864529 -0.0640166 0.98579 +v 0.0940951 -0.0565412 0.98502 +v 0.0861068 -0.0306433 0.989153 +v 0.0788425 -0.0488271 1.00064 +v 0.0938769 -0.0385712 0.986828 +v 0.0525009 -0.0662129 1.0231 +v 0.0666347 -0.0644079 1.00864 +v 0.0598411 -0.0536198 1.01768 +v 0.0652608 -0.0582549 1.01251 +v 0.0598989 -0.0753391 1.00401 +v 0.0525276 -0.0775374 1.01483 +v 0.0652946 -0.0700523 1.00523 +v 0.0476184 -0.0223971 1.0006 +v 0.0582598 -0.0403976 1.0119 +v 0.0694706 -0.025394 0.994502 +v 0 -0.0210975 1.00705 +v 0.0209047 -0.039677 1.02317 +v 0.0242006 -0.0212264 1.00515 +v 0.0152462 -0.0676801 1.04602 +v 0.0344846 -0.0534302 1.03232 +v 0 -0.0555541 1.03946 +v 0.0177789 -0.0547726 1.03745 +v 0.0426567 -0.0627588 1.03251 +v 0.0490439 -0.0525287 1.02501 +v 0.0477856 -0.0718253 0.995571 +v 0.0209476 -0.0779737 1.00716 +v 0 -0.0724905 1.00177 +v 0.0242757 -0.0726037 0.999895 +v 0.0583871 -0.073576 0.998233 +v 0.0697639 -0.0690371 0.990088 +v 0.0427012 -0.0854758 1.01505 +v 0.0345351 -0.0845283 1.01121 +v 0.0491057 -0.0804193 1.00671 +v 0 -0.0876552 1.01738 +v 0.0152667 -0.0940994 1.02438 +v 0.0178069 -0.0869021 1.01538 +v 0.0271444 -0.0763309 1.04139 +v 0.0394909 -0.0796254 1.02906 +v 0.0399318 -0.0720589 1.03309 +v 0 -0.0809251 1.049 +v 0.0132272 -0.0889316 1.04223 +v 0.0137291 -0.0795664 1.04692 +v 0.0271637 -0.0905263 1.02914 +v 0 -0.0956202 1.03609 +v 0.01374 -0.0942759 1.03402 +v 0.0399551 -0.0846544 1.02277 +v -0.341299 -0.375944 0.366232 +v -0.317818 -0.392423 0.305485 +v -0.289638 -0.411984 0.363044 +v -0.313121 -0.40468 0.424303 +v -0.317288 -0.397295 0.364448 +v -0.312495 -0.42258 0.208415 +v -0.274846 -0.418754 0.252658 +v -0.350284 -0.364453 0.244783 +v -0.316601 -0.396416 0.250199 +v -0.194817 -0.437402 0.239358 +v -0.251544 -0.422435 0.302332 +v -0.2099 -0.457622 0.202318 +v -0.231211 -0.430966 0.245486 +v -0.261632 -0.427221 0.422701 +v -0.23935 -0.43199 0.361842 +v -0.262332 -0.422664 0.362137 +v -0.275025 -0.421949 0.482067 +v -0.291362 -0.413379 0.536815 +v -0.328162 -0.387696 0.483083 +v -0.303426 -0.408222 0.482265 +v -0.225399 -0.440193 0.480871 +v -0.222989 -0.439421 0.53835 +v -0.247502 -0.431674 0.481825 +v -0.164011 -0.483033 0.631406 +v -0.236564 -0.444228 0.584476 +v -0.156119 -0.458526 0.595789 +v -0.191143 -0.453861 0.591118 +v -0.315111 -0.397679 0.592146 +v -0.26979 -0.455493 0.624003 +v -0.280089 -0.425608 0.586435 +v -0.339519 -0.257182 -0.0802831 +v -0.283535 -0.198083 -0.11242 +v -0.23546 -0.269794 -0.12322 +v -0.300873 -0.335808 -0.11045 +v -0.292915 -0.260195 -0.110308 +v -0.26898 -0.103901 -0.112945 +v -0.224047 -0.163495 -0.142015 +v -0.318497 -0.140059 -0.0746981 +v -0.274851 -0.146856 -0.114171 +v -0.123113 -0.206388 -0.170045 +v -0.173106 -0.230478 -0.142628 +v -0.172014 -0.141551 -0.170002 +v -0.171621 -0.184999 -0.160037 +v -0.176383 -0.34915 -0.10631 +v -0.119478 -0.295776 -0.113872 +v -0.174532 -0.282877 -0.121531 +v -0.273281 0.0420733 -0.0438498 +v -0.232462 0.00608204 -0.106821 +v -0.269878 -0.0318881 -0.0928838 +v -0.307808 -0.00318692 -0.0317095 +v -0.272342 0.00331308 -0.0724007 +v -0.148915 0.00578811 -0.165362 +v -0.182883 -0.0457092 -0.157469 +v -0.199052 0.0623656 -0.105989 +v -0.190658 0.0074224 -0.137241 +v -0.222802 -0.0788504 -0.141507 +v -0.131964 -0.111136 -0.188613 +v -0.176218 -0.0952439 -0.168768 +v -0.308256 -0.0631453 -0.0619102 +v -0.26804 -0.0666021 -0.106124 +v -0.26887 -0.396352 0.909752 +v -0.214141 -0.334681 0.919903 +v -0.263105 -0.289222 0.900577 +v -0.30851 -0.340088 0.875405 +v -0.266995 -0.336923 0.904292 +v -0.104904 -0.328487 0.922781 +v -0.164801 -0.284207 0.93026 +v -0.149733 -0.3934 0.920339 +v -0.15673 -0.332639 0.924128 +v -0.172003 -0.202637 0.93974 +v -0.215216 -0.244729 0.920604 +v -0.126656 -0.240414 0.945024 +v -0.169955 -0.242358 0.935335 +v -0.293898 -0.252639 0.867139 +v -0.253262 -0.209214 0.897882 +v -0.258195 -0.248301 0.898482 +v -0.375987 -0.340814 -0.0337268 +v -0.380901 -0.277243 0.032671 +v -0.358457 -0.200112 -0.0267162 +v -0.367895 -0.263853 -0.0306343 +v -0.375596 -0.311145 0.175939 +v -0.382253 -0.237542 0.105277 +v -0.379176 -0.364086 0.102343 +v -0.381399 -0.294389 0.103665 +v -0.379025 -0.149836 0.112764 +v -0.369603 -0.166291 0.0406057 +v -0.385185 -0.214712 0.178025 +v -0.38088 -0.190046 0.108528 +v -0.342627 -0.106257 -0.015664 +v -0.349444 -0.148083 -0.0217878 +v -0.351404 -0.354331 0.427814 +v -0.367965 -0.307651 0.370431 +v -0.363729 -0.333817 0.306674 +v -0.35769 -0.345276 0.36828 +v -0.376188 -0.22098 0.374406 +v -0.380079 -0.252636 0.309953 +v -0.366553 -0.273812 0.432936 +v -0.373629 -0.265433 0.372527 +v -0.379525 -0.278609 0.243679 +v -0.386398 -0.194374 0.247084 +v -0.384425 -0.235652 0.245143 +v -0.369702 -0.323364 0.243084 +v -0.359143 -0.0454376 0.384517 +v -0.376221 -0.0834201 0.319025 +v -0.375379 -0.132559 0.377674 +v -0.363531 -0.0923241 0.440867 +v -0.369754 -0.0887861 0.380331 +v -0.380073 -0.0641595 0.195141 +v -0.385994 -0.115397 0.252169 +v -0.369328 -0.0337485 0.265179 +v -0.380479 -0.0754649 0.257209 +v -0.383633 -0.167556 0.313214 +v -0.386429 -0.137312 0.183762 +v -0.387444 -0.154662 0.24911 +v -0.370145 -0.182621 0.437038 +v -0.377148 -0.176656 0.375911 +v -0.338487 -0.0443826 0.00235778 +v -0.357964 -0.0317511 0.0731655 +v -0.331012 0.0171674 0.0389716 +v -0.336366 -0.0157204 0.0175237 +v -0.363023 -0.0919062 0.0524717 +v -0.339774 -0.073126 -0.00816016 +v -0.37698 -0.0821329 0.123634 +v -0.378431 -0.114848 0.117331 +v -0.363023 -0.0117289 0.147082 +v -0.372551 -0.0487428 0.133083 +v -0.324728 -0.29766 0.82767 +v -0.340911 -0.350598 0.77666 +v -0.336842 -0.40362 0.835552 +v -0.331904 -0.344898 0.831349 +v -0.311718 -0.219243 0.822794 +v -0.331546 -0.262105 0.774295 +v -0.317327 -0.257308 0.824743 +v -0.344609 -0.271269 0.661246 +v -0.340676 -0.308781 0.717453 +v -0.338685 -0.226798 0.720092 +v -0.339619 -0.266826 0.718796 +v -0.335933 -0.414813 0.716014 +v -0.334716 -0.360298 0.654176 +v -0.339263 -0.356428 0.715872 +v -0.304296 -0.0566442 0.818942 +v -0.32815 -0.0982774 0.774453 +v -0.309753 -0.137557 0.821642 +v -0.282982 -0.0932074 0.86163 +v -0.309064 -0.0966912 0.82069 +v -0.349859 -0.0980743 0.670701 +v -0.342261 -0.141944 0.72292 +v -0.335097 -0.0554519 0.724795 +v -0.341372 -0.0985454 0.724072 +v -0.328063 -0.182474 0.773912 +v -0.348891 -0.186539 0.666645 +v -0.340465 -0.184932 0.72153 +v -0.284251 -0.173813 0.864211 +v -0.309915 -0.178867 0.822052 +v -0.364199 -0.140124 0.498352 +v -0.3576 -0.096426 0.55865 +v -0.350887 -0.0507559 0.502911 +v -0.360004 -0.0947951 0.500374 +v -0.363053 -0.232129 0.494204 +v -0.360088 -0.187609 0.554338 +v -0.364779 -0.186112 0.496433 +v -0.356689 -0.14249 0.613383 +v -0.35206 -0.232064 0.608144 +v -0.355112 -0.187591 0.610995 +v -0.34723 -0.0531297 0.617509 +v -0.354744 -0.0974434 0.615492 +v -0.338808 -0.358381 0.541229 +v -0.354812 -0.320109 0.488079 +v -0.344689 -0.357576 0.485189 +v -0.344841 -0.317709 0.600763 +v -0.335024 -0.360119 0.596759 +v -0.354746 -0.277669 0.548235 +v -0.349578 -0.27523 0.604646 +v -0.360332 -0.277544 0.491251 +v -0.270021 0.183796 0.151405 +v -0.250535 0.219935 0.200112 +v -0.22988 0.247545 0.157829 +v -0.253104 0.203435 0.118078 +v -0.251096 0.217673 0.158942 +v -0.247672 0.201215 0.285394 +v -0.224342 0.248556 0.249012 +v -0.273837 0.172969 0.230557 +v -0.249328 0.213762 0.242242 +v -0.166122 0.2964 0.255682 +v -0.201028 0.279793 0.204606 +v -0.19325 0.264928 0.298974 +v -0.197174 0.276415 0.252836 +v -0.208445 0.255016 0.0997486 +v -0.173937 0.295795 0.151795 +v -0.204742 0.274117 0.153286 +v -0.238934 0.137098 0.472953 +v -0.21248 0.178956 0.429644 +v -0.243641 0.166107 0.375362 +v -0.269047 0.115689 0.415447 +v -0.241351 0.149381 0.423 +v -0.149393 0.222637 0.439843 +v -0.185529 0.224498 0.389084 +v -0.178799 0.187723 0.48375 +v -0.181979 0.203634 0.435289 +v -0.218341 0.218477 0.337805 +v -0.157504 0.266542 0.348704 +v -0.189327 0.246276 0.344018 +v -0.272811 0.14513 0.319056 +v -0.245762 0.184358 0.32963 +v -0.212012 0.0755801 0.841201 +v -0.188626 0.112308 0.821548 +v -0.217701 0.11212 0.775527 +v -0.235856 0.0765799 0.805621 +v -0.213324 0.0965225 0.811853 +v -0.13257 0.138159 0.837992 +v -0.163968 0.1484 0.789706 +v -0.159999 0.0987976 0.865373 +v -0.161693 0.126272 0.830304 +v -0.169138 0.174847 0.695193 +v -0.195015 0.146226 0.738197 +v -0.136442 0.179619 0.750387 +v -0.166543 0.164739 0.744396 +v -0.249108 0.0961373 0.728207 +v -0.226814 0.130295 0.684497 +v -0.222367 0.12354 0.732548 +v -0.264402 0.101968 0.520397 +v -0.233686 0.131486 0.579487 +v -0.207042 0.158534 0.530777 +v -0.236433 0.132176 0.525634 +v -0.201599 0.157166 0.637907 +v -0.258575 0.102323 0.628487 +v -0.230534 0.131902 0.632959 +v -0.139858 0.195421 0.647569 +v -0.173735 0.178964 0.589175 +v -0.171473 0.178284 0.642915 +v -0.143538 0.198754 0.539805 +v -0.176115 0.180806 0.535582 +v -0.337836 -0.00655256 0.448549 +v -0.320929 0.0389878 0.398635 +v -0.34742 0.00319315 0.333602 +v -0.342419 -0.00261151 0.390867 +v -0.298744 0.0894187 0.355449 +v -0.293232 0.0711038 0.460405 +v -0.296022 0.0786559 0.407077 +v -0.30121 0.115034 0.257783 +v -0.327429 0.0566863 0.291075 +v -0.300703 0.102007 0.305644 +v -0.351215 0.0204208 0.221415 +v -0.350974 0.0108683 0.277027 +v -0.308985 -0.0158364 0.772679 +v -0.30029 0.0266191 0.725054 +v -0.328122 -0.0112347 0.673608 +v -0.320738 -0.0133772 0.724898 +v -0.268509 -0.018423 0.854481 +v -0.274888 0.0183198 0.812257 +v -0.291897 -0.0177918 0.816142 +v -0.267341 0.0573644 0.769829 +v -0.24017 0.0457536 0.838346 +v -0.256292 0.0501447 0.807253 +v -0.281859 0.0674534 0.67711 +v -0.275748 0.0634772 0.725933 +v -0.239418 0.102195 -0.0351077 +v -0.213035 0.170022 -0.00953204 +v -0.181753 0.135303 -0.0848536 +v -0.20757 0.117335 -0.0616182 +v -0.298292 0.0729821 0.0271766 +v -0.265278 0.133372 0.0353559 +v -0.270541 0.0874645 -0.00640695 +v -0.236523 0.195781 0.0609139 +v -0.276588 0.155574 0.0981021 +v -0.258648 0.173682 0.0768666 +v -0.190293 0.237055 0.0258931 +v -0.212268 0.218116 0.0448664 +v -0.288873 0.0678482 0.57056 +v -0.311113 0.0304905 0.622016 +v -0.286019 0.0682635 0.624906 +v -0.315185 0.0311388 0.510574 +v -0.291063 0.0681481 0.515313 +v -0.334099 -0.00961306 0.563635 +v -0.335537 -0.00863692 0.506376 +v -0.332102 -0.0102295 0.619617 +v -0.324423 0.0791082 0.189745 +v -0.33595 0.0447295 0.115485 +v -0.346277 0.0318576 0.16704 +v -0.295396 0.137443 0.169109 +v -0.299573 0.127115 0.211987 +v -0.305188 0.103086 0.100412 +v -0.288286 0.145212 0.129998 +v -0.320025 0.0585873 0.0683354 +v -0.177314 0.204818 -0.0510199 +v -0.167034 0.18223 -0.122798 +v -0.149034 0.119255 -0.152767 +v -0.168725 0.158519 -0.103729 +v -0.159665 0.285267 0.0452783 +v -0.167426 0.259011 -0.0241111 +v -0.175009 0.248965 0.00116269 +v -0.17918 0.290497 -0.0609743 +v -0.177164 0.238112 -0.093383 +v -0.149721 0.3008 -0.00470029 +v -0.168557 0.27236 -0.0447148 +v -0.160058 0.168229 -0.195838 +v -0.194921 0.221357 -0.173014 +v -0.175228 0.201681 -0.146613 +v -0.21819 0.281995 -0.133552 +v -0.26422 0.274293 -0.228207 +v -0.233098 0.21084 -0.267301 +v -0.227725 0.245742 -0.199837 +v -0.173263 0.341693 -0.0238379 +v -0.225521 0.344757 -0.0845003 +v -0.200073 0.314908 -0.0732157 +v -0.267222 0.417414 -0.116444 +v -0.27622 0.344814 -0.176785 +v -0.21453 0.407775 -0.0317089 +v -0.249809 0.379204 -0.0978893 +v -0.306638 0.268641 -0.338166 +v -0.314639 0.343639 -0.292523 +v -0.294985 0.306469 -0.259249 +v -0.279797 0.207117 -0.366981 +v -0.240251 0.15911 -0.387649 +v -0.192666 0.159829 -0.308601 +v -0.238726 0.181983 -0.331175 +v -0.330786 0.26947 -0.445487 +v -0.307399 0.208213 -0.46356 +v -0.31171 0.235804 -0.406418 +v -0.259412 0.1698 -0.542722 +v -0.265715 0.160342 -0.469212 +v -0.305787 0.218563 -0.547441 +v -0.290901 0.186126 -0.509143 +v -0.195451 0.128497 -0.407372 +v -0.213461 0.12942 -0.465108 +v -0.233311 0.142158 -0.432916 +v -0.329541 0.345256 -0.410956 +v -0.321008 0.352655 -0.511417 +v -0.32675 0.280027 -0.535933 +v -0.333345 0.309542 -0.480189 +v -0.255976 0.429549 -0.563622 +v -0.289278 0.358786 -0.584918 +v -0.295245 0.436762 -0.484187 +v -0.295399 0.395443 -0.540067 +v -0.246645 0.312827 -0.640337 +v -0.296456 0.295786 -0.60247 +v -0.240548 0.35766 -0.62796 +v -0.274305 0.331026 -0.617491 +v -0.272516 0.239582 -0.609537 +v -0.307295 0.256707 -0.578835 +v -0.288912 -0.666279 -0.0831981 +v -0.233667 -0.718383 -0.0394682 +v -0.288313 -0.71953 0.0292002 +v -0.335047 -0.66747 -0.026194 +v -0.288523 -0.704927 -0.0329901 +v -0.136552 -0.67511 -0.0280042 +v -0.172796 -0.723594 0.0247169 +v -0.187443 -0.669698 -0.0818819 +v -0.179633 -0.708233 -0.0350267 +v -0.182766 -0.687312 0.135767 +v -0.227442 -0.724741 0.0933852 +v -0.136631 -0.686121 0.0787634 +v -0.176191 -0.716151 0.0857864 +v -0.327044 -0.674066 0.0872825 +v -0.276152 -0.679477 0.14116 +v -0.281161 -0.710704 0.0910758 +v -0.288217 -0.679435 0.838379 +v -0.248642 -0.724519 0.790895 +v -0.198896 -0.723335 0.85193 +v -0.2461 -0.678205 0.889508 +v -0.246831 -0.711912 0.845432 +v -0.24088 -0.688682 0.691628 +v -0.198408 -0.728532 0.734591 +v -0.283587 -0.684515 0.738785 +v -0.244434 -0.716483 0.736358 +v -0.115859 -0.693483 0.748115 +v -0.148661 -0.727347 0.795626 +v -0.157976 -0.694713 0.696986 +v -0.153047 -0.720555 0.741401 +v -0.15574 -0.680004 0.892121 +v -0.113033 -0.684171 0.844965 +v -0.151829 -0.713932 0.849146 +v -0.30391 -0.498066 0.668956 +v -0.32282 -0.565952 0.726198 +v -0.342489 -0.483419 0.78141 +v -0.331237 -0.488983 0.719836 +v -0.319732 -0.633454 0.786428 +v -0.28283 -0.632563 0.691009 +v -0.308326 -0.632734 0.733956 +v -0.294197 -0.618974 0.884469 +v -0.331331 -0.556659 0.842236 +v -0.315639 -0.625673 0.839496 +v -0.31354 -0.474577 0.887895 +v -0.337524 -0.478425 0.840051 +v -0.0969194 -0.478778 0.897495 +v -0.0774719 -0.570173 0.85133 +v -0.0654567 -0.515878 0.79543 +v -0.0634711 -0.431765 0.851899 +v -0.0707234 -0.496321 0.852392 +v -0.0840444 -0.64607 0.797118 +v -0.112805 -0.624088 0.888986 +v -0.0899111 -0.634521 0.847274 +v -0.119063 -0.647679 0.702012 +v -0.0832655 -0.591144 0.740087 +v -0.0943475 -0.648249 0.746058 +v -0.069956 -0.47422 0.735292 +v -0.106684 -0.534636 0.682874 +v -0.0773661 -0.528459 0.735056 +v -0.208287 -0.52835 0.637223 +v -0.252371 -0.581833 0.652832 +v -0.260651 -0.513618 0.642398 +v -0.15335 -0.595644 0.66033 +v -0.153645 -0.534978 0.650489 +v -0.20034 -0.651356 0.660475 +v -0.156436 -0.650983 0.672896 +v -0.244653 -0.641994 0.666514 +v -0.209392 -0.47177 0.928314 +v -0.149543 -0.554429 0.922812 +v -0.147798 -0.472236 0.922294 +v -0.262868 -0.552296 0.920108 +v -0.267734 -0.472455 0.917082 +v -0.203436 -0.628169 0.923071 +v -0.253551 -0.622939 0.912658 +v -0.153584 -0.625261 0.914716 +v -0.387436 -0.440321 0.0296682 +v -0.369537 -0.538419 0.0961211 +v -0.348561 -0.464054 0.158716 +v -0.376444 -0.45013 0.0999599 +v -0.354445 -0.427851 -0.0878125 +v -0.378455 -0.525308 -0.0356201 +v -0.380964 -0.432504 -0.0361787 +v -0.368236 -0.614976 0.0306267 +v -0.340742 -0.597899 -0.0798229 +v -0.364087 -0.605614 -0.0296813 +v -0.325558 -0.615423 0.139592 +v -0.354786 -0.614851 0.0904298 +v -0.12704 -0.448099 -0.0735785 +v -0.182701 -0.527846 -0.109937 +v -0.243518 -0.430642 -0.121062 +v -0.179139 -0.436248 -0.106528 +v -0.241923 -0.609859 -0.117359 +v -0.141316 -0.607217 -0.0730372 +v -0.186967 -0.607615 -0.104287 +v -0.304443 -0.521287 -0.117606 +v -0.296601 -0.602967 -0.109127 +v -0.305291 -0.427537 -0.115465 +v -0.25113 -0.502745 0.197094 +v -0.188536 -0.577394 0.174934 +v -0.148115 -0.512563 0.149929 +v -0.196177 -0.511769 0.183546 +v -0.293784 -0.559568 0.181063 +v -0.304357 -0.484216 0.189956 +v -0.233064 -0.638226 0.175543 +v -0.282371 -0.626877 0.167977 +v -0.145237 -0.635178 0.13052 +v -0.185474 -0.638484 0.162245 +v -0.0953701 -0.405611 -0.0214782 +v -0.0997946 -0.492468 0.0352712 +v -0.105712 -0.548895 -0.0268432 +v -0.102107 -0.469936 -0.0239275 +v -0.113288 -0.573273 0.0910993 +v -0.112515 -0.451919 0.0935688 +v -0.115559 -0.506404 0.0968639 +v -0.106751 -0.633108 0.0275567 +v -0.117988 -0.635837 0.0828 +v -0.114552 -0.619641 -0.0267392 +v -0.308658 0.43336 -0.368305 +v -0.285353 0.520853 -0.361551 +v -0.271184 0.525759 -0.460079 +v -0.291391 0.478507 -0.418527 +v -0.298509 0.427522 -0.236282 +v -0.317802 0.38717 -0.32759 +v -0.235335 0.485531 -0.0647615 +v -0.271214 0.498067 -0.167977 +v -0.272045 0.45855 -0.143225 +v -0.277875 0.55689 -0.190965 +v -0.282577 0.535883 -0.259681 +v -0.247008 0.54474 -0.114114 +v -0.271665 0.531425 -0.180446 +v -0.267 0.601931 -0.388185 +v -0.278055 0.600765 -0.320108 +v -0.278645 0.563976 -0.33172 +v -0.252363 0.682167 -0.15033 +v -0.326452 0.645309 -0.138504 +v -0.267679 0.610284 -0.129549 +v -0.192626 0.647576 -0.125774 +v -0.258116 0.645451 -0.13607 +v -0.430349 0.658277 -0.154382 +v -0.380321 0.61857 -0.152413 +v -0.388682 0.680406 -0.144893 +v -0.384792 0.647908 -0.143704 +v -0.35448 0.589213 -0.202564 +v -0.324346 0.587714 -0.15672 +v -0.401583 0.612716 -0.19176 +v -0.367842 0.597467 -0.17194 +v -0.239082 0.578957 -0.111996 +v -0.289471 0.569074 -0.162469 +v -0.279361 0.583208 -0.137022 +v -0.318359 0.584666 -0.230094 +v -0.294439 0.591849 -0.266039 +v -0.294318 0.572729 -0.209871 +v -0.380591 0.614582 -0.245535 +v -0.343967 0.620068 -0.286887 +v -0.347363 0.598425 -0.244565 +v -0.345079 0.681327 -0.333156 +v -0.312606 0.638668 -0.319124 +v -0.375881 0.662505 -0.310821 +v -0.34177 0.649107 -0.318477 +v -0.28588 0.662049 -0.349089 +v -0.290372 0.624108 -0.317788 +v -0.419572 0.658706 -0.261892 +v -0.444197 0.711394 -0.263256 +v -0.393743 0.706765 -0.3123 +v -0.412958 0.685943 -0.291128 +v -0.447289 0.655956 -0.196803 +v -0.417303 0.633713 -0.225256 +v -0.447397 0.702392 -0.15815 +v -0.471552 0.708579 -0.199184 +v -0.460337 0.681448 -0.17325 +v -0.43241 0.746455 -0.258303 +v -0.452589 0.744444 -0.206816 +v -0.460792 0.730831 -0.231063 +v -0.0467382 0.325284 0.136739 +v -0.0925539 0.320139 0.170699 +v -0.0462436 0.320164 0.221337 +v -0.0468991 0.323707 0.17766 +v -0.132936 0.312061 0.210485 +v -0.135299 0.30832 0.112598 +v -0.13572 0.310986 0.159838 +v -0.125628 0.296564 0.306829 +v -0.0886491 0.312396 0.263435 +v -0.129481 0.307575 0.259519 +v -0.0434892 0.30185 0.311934 +v -0.0450231 0.313323 0.266515 +v -0.0377827 0.232065 0.495188 +v -0.0735327 0.221293 0.545706 +v -0.0364517 0.2252 0.601479 +v -0.0369868 0.226526 0.54726 +v -0.107651 0.210086 0.597079 +v -0.111325 0.219111 0.491389 +v -0.109197 0.212143 0.543201 +v -0.105384 0.203917 0.704755 +v -0.0717153 0.218255 0.65442 +v -0.106456 0.208743 0.651454 +v -0.0357781 0.218679 0.710249 +v -0.0360809 0.22396 0.656319 +v -0.0703592 0.199987 0.759265 +v -0.035033 0.18494 0.809623 +v -0.0354469 0.205232 0.761742 +v -0.10286 0.172311 0.802347 +v -0.104202 0.191409 0.755412 +v -0.0994805 0.118705 0.880737 +v -0.0684286 0.154761 0.849486 +v -0.101303 0.147713 0.844481 +v -0.0337403 0.129119 0.889852 +v -0.0344822 0.159128 0.852718 +v -0.032544 -0.433336 0.0684456 +v -0.0619855 -0.419454 0.0516405 +v -0.0290027 -0.401336 0.00260959 +v -0.0312142 -0.420036 0.03584 +v -0.0804386 -0.407577 0.025012 +v -0.101981 -0.43742 0.118873 +v -0.0918712 -0.426509 0.0746889 +v -0.0781392 -0.343402 -0.0680291 +v -0.0524989 -0.374486 -0.0268658 +v -0.0771327 -0.378765 -0.022981 +v -0.024587 -0.350255 -0.0669927 +v -0.0265726 -0.377866 -0.0315624 +v -0.0173499 -0.340897 0.891348 +v -0.032518 -0.377955 0.851217 +v -0.0162142 -0.396858 0.808469 +v -0.0161103 -0.370733 0.852319 +v -0.0473693 -0.423079 0.799815 +v -0.0576974 -0.360469 0.893822 +v -0.0495204 -0.395304 0.851292 +v -0.0641499 -0.454693 0.696538 +v -0.0352263 -0.426311 0.757202 +v -0.0543417 -0.44245 0.745122 +v -0.0190571 -0.436735 0.723869 +v -0.0173127 -0.418962 0.764189 +v -0.08278 0.283223 0.354838 +v -0.0403407 0.264584 0.4009 +v -0.0418935 0.284411 0.356338 +v -0.117787 0.25622 0.397308 +v -0.121652 0.278062 0.352302 +v -0.0772361 0.242537 0.445498 +v -0.114267 0.235186 0.443214 +v -0.0389355 0.245943 0.446792 +v -0.0448664 0.351036 0.0368917 +v -0.084777 0.331134 0.0392602 +v -0.0441574 0.329119 0.0693112 +v -0.0436281 0.336529 0.047541 +v -0.122579 0.311429 0.0436831 +v -0.125569 0.33518 0.0110101 +v -0.120968 0.319807 0.0225689 +v -0.0891709 0.320583 0.0906503 +v -0.129137 0.308034 0.0737864 +v -0.0455092 0.326229 0.0998335 +v -0.0632284 0.496693 0.0522852 +v -0.116503 0.442256 0.0399308 +v -0.0541098 0.40816 0.0483714 +v -0.0593708 0.448955 0.0551193 +v -0.153438 0.391277 0.0121446 +v -0.18104 0.470039 0.00485434 +v -0.169159 0.42866 0.0126096 +v -0.0954346 0.370179 0.029827 +v -0.13765 0.35956 0.0095734 +v -0.0488177 0.375217 0.039732 +v -0.0692761 0.505582 -0.562042 +v -0.130136 0.568004 -0.528764 +v -0.0626485 0.640189 -0.506046 +v -0.0664738 0.570216 -0.533525 +v -0.232047 0.565216 -0.501918 +v -0.174025 0.632377 -0.495223 +v -0.199187 0.49892 -0.545668 +v -0.188173 0.564066 -0.51907 +v -0.150533 0.744043 -0.44196 +v -0.113201 0.701726 -0.474505 +v -0.199905 0.685497 -0.462496 +v -0.161614 0.694175 -0.469576 +v -0.0536794 0.762368 -0.447664 +v -0.0582379 0.707055 -0.477971 +v -0.0726958 0.340957 -0.664799 +v -0.138282 0.375681 -0.645424 +v -0.0711811 0.413275 -0.623292 +v -0.0716465 0.376815 -0.648416 +v -0.199873 0.404748 -0.612935 +v -0.193634 0.339499 -0.652866 +v -0.194895 0.370921 -0.637938 +v -0.138821 0.452917 -0.589054 +v -0.202195 0.446614 -0.579567 +v -0.0706181 0.454733 -0.593233 +v -0.0306399 -0.195728 0.970285 +v -0.057123 -0.235922 0.956621 +v -0.0240468 -0.271835 0.943264 +v -0.0277858 -0.234252 0.959139 +v -0.0802769 -0.277764 0.939515 +v -0.0956803 -0.199455 0.960676 +v -0.0895627 -0.238122 0.952018 +v -0.0425527 -0.311463 0.921053 +v -0.0688023 -0.319918 0.921674 +v -0.0202817 -0.307657 0.921165 +v -0.049547 -0.311956 -0.105817 +v -0.0238367 -0.283103 -0.139843 +v -0.023709 -0.319134 -0.103998 +v -0.0816243 -0.264189 -0.144485 +v -0.0796433 -0.304819 -0.108871 +v -0.0878074 -0.176513 -0.193941 +v -0.0521008 -0.23408 -0.173683 +v -0.0840611 -0.222685 -0.173847 +v -0.0267024 -0.190718 -0.197111 +v -0.0248684 -0.240765 -0.171792 +v -0.0599751 -0.128388 -0.209467 +v -0.0321871 -0.0691596 -0.222731 +v -0.0292367 -0.131565 -0.213064 +v -0.101087 -0.0620719 -0.200364 +v -0.0937169 -0.121882 -0.201748 +v -0.115674 0.055105 -0.187883 +v -0.0713902 -0.00682142 -0.215572 +v -0.109216 -0.00036684 -0.192884 +v -0.0381981 0.0419961 -0.235526 +v -0.035269 -0.00935459 -0.229192 +v -0.0803711 0.0844567 -0.225271 +v -0.0428926 0.103386 -0.257977 +v -0.0406901 0.0790388 -0.244814 +v -0.120922 0.124855 -0.209363 +v -0.118034 0.096215 -0.193935 +v -0.138478 0.148595 -0.265069 +v -0.0884331 0.12573 -0.258533 +v -0.128964 0.142918 -0.232488 +v -0.0470212 0.120443 -0.299626 +v -0.0449537 0.11665 -0.27594 +v -0.097999 0.124878 -0.319976 +v -0.0518947 0.108853 -0.365753 +v -0.0492429 0.116377 -0.329956 +v -0.150911 0.126322 -0.356271 +v -0.145782 0.140078 -0.308863 +v -0.16045 0.112915 -0.441079 +v -0.107541 0.107031 -0.401861 +v -0.153901 0.116281 -0.399697 +v -0.0595919 0.101024 -0.449026 +v -0.0552525 0.102268 -0.405836 +v -0.125551 0.112279 -0.490196 +v -0.0709982 0.126709 -0.538642 +v -0.065189 0.10952 -0.494143 +v -0.194944 0.134806 -0.523346 +v -0.176258 0.119186 -0.482359 +v -0.219301 0.191387 -0.600189 +v -0.1475 0.153854 -0.575332 +v -0.210129 0.15949 -0.56385 +v -0.0790718 0.182988 -0.615599 +v -0.0759743 0.151547 -0.579976 +v -0.154044 0.222564 -0.638941 +v -0.0775425 0.260206 -0.661002 +v -0.0792455 0.219987 -0.642965 +v -0.213772 0.26767 -0.647803 +v -0.21995 0.228648 -0.628685 +v -0.144378 0.302534 -0.665208 +v -0.202463 0.304851 -0.656009 +v -0.0750102 0.301309 -0.668637 +v -0.0606884 0.60785 0.00104436 +v -0.126715 0.537337 0.0111468 +v -0.0643107 0.550463 0.0321785 +v -0.0403517 0.7183 -0.0719016 +v -0.0987466 0.656786 -0.062447 +v -0.0504326 0.666442 -0.034872 +v -0.171165 0.605799 -0.0764289 +v -0.126096 0.69557 -0.127071 +v -0.142824 0.650926 -0.0969906 +v -0.191637 0.550233 -0.0477524 +v -0.209701 0.569968 -0.0807895 +v -0.185308 0.513743 -0.0172354 +v -0.258514 0.602197 -0.445199 +v -0.237614 0.630468 -0.469873 +v -0.253217 0.578269 -0.474783 +v -0.246529 0.67248 -0.397952 +v -0.240943 0.662224 -0.43894 +v -0.254771 0.635976 -0.4207 +v -0.212896 0.714905 -0.428435 +v -0.224501 0.676789 -0.452578 +v -0.214224 0.916672 -0.246046 +v -0.201014 0.943338 -0.25145 +v -0.21544 0.938681 -0.279423 +v -0.226436 0.912723 -0.26973 +v -0.216965 0.931825 -0.261167 +v -0.159856 0.939686 -0.239651 +v -0.17745 0.953646 -0.260405 +v -0.179801 0.930945 -0.23207 +v -0.180783 0.946411 -0.244635 +v -0.165912 0.939303 -0.292739 +v -0.191876 0.948989 -0.288378 +v -0.1537 0.943252 -0.269054 +v -0.173109 0.951035 -0.277835 +v -0.216862 0.918936 -0.303965 +v -0.196917 0.927676 -0.311546 +v -0.207634 0.937732 -0.29671 +v -0.209996 0.761876 -0.268358 +v -0.199084 0.77337 -0.281405 +v -0.191438 0.774734 -0.312022 +v -0.207814 0.759869 -0.30299 +v -0.201734 0.767127 -0.28955 +v -0.203233 0.797472 -0.273932 +v -0.192387 0.789092 -0.301842 +v -0.202175 0.775482 -0.251997 +v -0.199221 0.78193 -0.2764 +v -0.165819 0.804418 -0.335288 +v -0.178221 0.788374 -0.325575 +v -0.18742 0.811743 -0.321532 +v -0.181068 0.796668 -0.322844 +v -0.180956 0.7796 -0.34144 +v -0.161743 0.793141 -0.342758 +v -0.178357 0.783728 -0.331262 +v -0.192516 0.777938 -0.227759 +v -0.168503 0.781447 -0.210541 +v -0.151415 0.801648 -0.215482 +v -0.181336 0.804317 -0.228606 +v -0.174268 0.789156 -0.220565 +v -0.153638 0.772539 -0.191376 +v -0.137434 0.789176 -0.20042 +v -0.186175 0.766882 -0.204739 +v -0.162292 0.776737 -0.200861 +v -0.0963023 0.812563 -0.21585 +v -0.12229 0.805309 -0.211386 +v -0.103071 0.800257 -0.198013 +v -0.114773 0.801816 -0.205592 +v -0.135327 0.828572 -0.217894 +v -0.108345 0.822919 -0.221075 +v -0.128262 0.813355 -0.215464 +v -0.143329 0.804627 -0.337252 +v -0.119159 0.809804 -0.331351 +v -0.13845 0.801677 -0.350685 +v -0.140844 0.802002 -0.341998 +v -0.153713 0.826966 -0.334024 +v -0.127696 0.819206 -0.325202 +v -0.147191 0.8121 -0.335056 +v -0.0961567 0.829666 -0.288835 +v -0.10501 0.817882 -0.310157 +v -0.116614 0.840248 -0.308051 +v -0.109848 0.825231 -0.308777 +v -0.0934554 0.817549 -0.318853 +v -0.086003 0.820458 -0.291304 +v -0.100185 0.816042 -0.313185 +v -0.084054 0.824638 -0.268864 +v -0.0780919 0.822576 -0.248928 +v -0.0710179 0.824335 -0.270682 +v -0.0786961 0.822795 -0.269513 +v -0.0959818 0.847028 -0.267898 +v -0.0888081 0.831892 -0.249223 +v -0.0891348 0.832003 -0.268429 +v -0.0899479 0.821575 -0.232115 +v -0.102029 0.843892 -0.232989 +v -0.095203 0.828981 -0.232883 +v -0.0751675 0.819879 -0.228529 +v -0.084018 0.819324 -0.230668 +v -0.231902 0.754223 -0.26947 +v -0.226075 0.759994 -0.240858 +v -0.208076 0.764415 -0.241789 +v -0.216972 0.759952 -0.252956 +v -0.265103 0.760852 -0.220189 +v -0.223444 0.760451 -0.217689 +v -0.264144 0.760816 -0.243923 +v -0.240714 0.760641 -0.229576 +v -0.20189 0.765574 -0.22074 +v -0.215759 0.757673 -0.200462 +v -0.205912 0.761992 -0.209879 +v -0.201854 0.770051 -0.234112 +v -0.234872 0.742799 -0.306286 +v -0.277858 0.727498 -0.319523 +v -0.278995 0.751255 -0.279238 +v -0.256224 0.744786 -0.293184 +v -0.317986 0.708047 -0.333577 +v -0.258236 0.693552 -0.356883 +v -0.284726 0.698216 -0.343913 +v -0.37536 0.738148 -0.30116 +v -0.358205 0.712515 -0.324745 +v -0.402685 0.758643 -0.236201 +v -0.343965 0.756617 -0.269721 +v -0.390758 0.753705 -0.27032 +v -0.311167 0.763685 -0.236173 +v -0.300161 0.759231 -0.259113 +v -0.277376 0.753251 -0.197126 +v -0.248651 0.737773 -0.18066 +v -0.183529 0.754714 -0.188935 +v -0.23327 0.750984 -0.191422 +v -0.352617 0.756796 -0.208565 +v -0.303456 0.759588 -0.213776 +v -0.409003 0.736167 -0.174314 +v -0.409429 0.752424 -0.202781 +v -0.329845 0.712932 -0.159268 +v -0.39942 0.710994 -0.155057 +v -0.178779 0.718135 -0.16643 +v -0.252112 0.713887 -0.166078 +v -0.106741 0.782082 -0.178969 +v -0.0602661 0.797425 -0.177797 +v -0.0705006 0.811753 -0.205807 +v -0.0845451 0.798015 -0.188581 +v -0.128352 0.75368 -0.16956 +v -0.140544 0.766364 -0.181936 +v -0.0771688 0.744134 -0.128582 +v -0.122404 0.729951 -0.151266 +v -0.0359638 0.781745 -0.13792 +v -0.0372542 0.755486 -0.106376 +v -0.0258744 0.814456 -0.19275 +v -0.0313039 0.800824 -0.16616 +v -0.0438017 0.818098 -0.377412 +v -0.0647564 0.824008 -0.337021 +v -0.0269807 0.832763 -0.306956 +v -0.0352238 0.828719 -0.341387 +v -0.0968568 0.789376 -0.411772 +v -0.0494105 0.797681 -0.413491 +v -0.176513 0.760515 -0.410655 +v -0.134148 0.794627 -0.38492 +v -0.140375 0.776566 -0.412207 +v -0.105446 0.812324 -0.352131 +v -0.163948 0.787613 -0.366372 +v -0.134862 0.801108 -0.364702 +v -0.0673729 0.8251 -0.299446 +v -0.0829065 0.820245 -0.328154 +v -0.0209585 0.83068 -0.246717 +v -0.0431316 0.822381 -0.222498 +v -0.0222752 0.824379 -0.219341 +v -0.0427143 0.830406 -0.274631 +v -0.0223763 0.833445 -0.275661 +v -0.0571055 0.825864 -0.248034 +v -0.0589761 0.827121 -0.27268 +v -0.0611506 0.820889 -0.225684 +v -0.220893 0.723503 -0.390265 +v -0.192333 0.761236 -0.378584 +v -0.20182 0.742487 -0.402976 +v -0.229147 0.73046 -0.348619 +v -0.238328 0.704586 -0.373617 +v -0.202503 0.759013 -0.342238 +v -0.217964 0.748268 -0.323878 +v -0.185497 0.772855 -0.357643 +v -0.208154 0.830042 -0.298948 +v -0.20855 0.866089 -0.317157 +v -0.182638 0.844163 -0.332751 +v -0.197796 0.836731 -0.320106 +v -0.207473 0.823979 -0.249259 +v -0.22169 0.856724 -0.273536 +v -0.212209 0.824662 -0.273398 +v -0.225435 0.891324 -0.293612 +v -0.221713 0.885753 -0.253374 +v -0.227222 0.886884 -0.273083 +v -0.202088 0.898609 -0.32219 +v -0.216036 0.894273 -0.311279 +v -0.144889 0.85895 -0.323167 +v -0.140188 0.893495 -0.304854 +v -0.113654 0.869597 -0.287244 +v -0.127225 0.865094 -0.306986 +v -0.17602 0.88052 -0.329499 +v -0.164181 0.851772 -0.332764 +v -0.170407 0.915574 -0.314537 +v -0.186655 0.907214 -0.322451 +v -0.141278 0.921251 -0.283964 +v -0.154011 0.919177 -0.300925 +v -0.106278 0.87162 -0.248059 +v -0.126235 0.896792 -0.232757 +v -0.125921 0.862724 -0.222037 +v -0.112672 0.868658 -0.232446 +v -0.120264 0.900007 -0.266157 +v -0.106638 0.871852 -0.266963 +v -0.136706 0.926532 -0.249134 +v -0.136018 0.925025 -0.266007 +v -0.152825 0.914652 -0.226568 +v -0.141818 0.921807 -0.235425 +v -0.169297 0.842653 -0.222278 +v -0.201725 0.863227 -0.234578 +v -0.191458 0.831381 -0.232334 +v -0.158724 0.882351 -0.220155 +v -0.146124 0.853579 -0.218747 +v -0.191735 0.902282 -0.228209 +v -0.171199 0.908866 -0.224253 +v -0.209229 0.892731 -0.238166 +v -0.228365 -0.446181 0.420977 +v -0.20511 -0.461837 0.475502 +v -0.183641 -0.455489 0.534379 +v -0.21326 -0.450303 0.478539 +v -0.176881 -0.48852 0.469991 +v -0.17086 -0.474631 0.521789 +v -0.206663 -0.472505 0.418626 +v -0.194975 -0.474631 0.472428 +v -0.109552 -0.472057 0.595485 +v -0.142559 -0.466669 0.57469 +v -0.132033 -0.481167 0.556781 +v -0.140849 -0.473458 0.563316 +v -0.102981 -0.465723 0.632974 +v -0.143787 -0.462243 0.587914 +v -0.0755892 -0.465387 0.639018 +v -0.0439995 -0.453929 0.682063 +v -0.0705061 -0.461083 0.663389 +v -0.0917758 -0.479034 0.591505 +v -0.0549351 -0.471091 0.629642 +v -0.0815781 -0.471375 0.616771 +v -0.0238268 -0.46053 0.664171 +v -0.0329053 -0.483094 0.604968 +v -0.0276324 -0.470883 0.636565 +v -0.0210984 -0.44987 0.691901 +v -0.0317646 -0.445352 0.134276 +v -0.065741 -0.440111 0.119726 +v -0.0323291 -0.440606 0.100743 +v -0.034368 -0.461296 0.211229 +v -0.0636123 -0.450028 0.182161 +v -0.0320458 -0.45108 0.17059 +v -0.124102 -0.450719 0.228684 +v -0.0965198 -0.444834 0.175662 +v -0.0981278 -0.457279 0.230677 +v -0.0942201 -0.449501 0.201118 +v -0.138015 -0.443895 0.192281 +v -0.101319 -0.442167 0.150389 +v -0.163536 -0.447685 0.255959 +v -0.205661 -0.440923 0.30331 +v -0.174785 -0.442414 0.24495 +v -0.138385 -0.462583 0.271465 +v -0.179537 -0.460826 0.31166 +v -0.153491 -0.454897 0.266081 +v -0.213095 -0.454425 0.36305 +v -0.178344 -0.481123 0.364052 +v -0.199389 -0.4673 0.363772 +v -0.224677 -0.442616 0.362277 +v -0.0774159 -0.49456 0.56248 +v -0.0472884 -0.515301 0.519274 +v -0.0400356 -0.499329 0.565268 +v -0.12906 -0.497175 0.517019 +v -0.109485 -0.488354 0.558077 +v -0.151776 -0.503865 0.416665 +v -0.102374 -0.516827 0.468605 +v -0.144853 -0.503338 0.468859 +v -0.0552219 -0.529321 0.415644 +v -0.0529288 -0.526727 0.468796 +v -0.101727 -0.509066 0.362546 +v -0.046641 -0.500432 0.308431 +v -0.0524328 -0.518796 0.361628 +v -0.12954 -0.482953 0.312862 +v -0.144743 -0.495777 0.363499 +v -0.0778956 -0.474931 0.261875 +v -0.111951 -0.469275 0.268257 +v -0.0399262 -0.479506 0.257737 +v -0.164631 -0.0504489 0.951176 +v -0.139042 -0.0451633 0.963659 +v -0.137897 -0.0298265 0.961061 +v -0.16267 -0.0297463 0.947597 +v -0.150007 -0.038161 0.957034 +v -0.109851 -0.0516794 0.976283 +v -0.122462 -0.037914 0.969963 +v -0.133714 -0.0642499 0.965416 +v -0.125245 -0.0487781 0.969619 +v -0.130968 -0.0135459 0.956851 +v -0.109331 -0.0304408 0.974293 +v -0.124172 -0.0273895 0.966259 +v -0.18873 -0.0434748 0.935764 +v -0.213918 -0.078022 0.922841 +v -0.172782 -0.0812671 0.947651 +v -0.185903 -0.064746 0.940486 +v -0.24743 -0.125194 0.898745 +v -0.247517 -0.0516572 0.891815 +v -0.248772 -0.0872467 0.896118 +v -0.209867 -0.161573 0.925244 +v -0.2493 -0.167014 0.898651 +v -0.133001 -0.161124 0.956956 +v -0.163882 -0.120989 0.949271 +v -0.170754 -0.160591 0.943861 +v -0.119758 -0.0911109 0.968067 +v -0.149065 -0.0885975 0.957545 +v -0.165953 -0.00373407 0.934179 +v -0.206641 -0.0168625 0.913183 +v -0.181563 -0.0218941 0.9332 +v -0.116698 0.0146029 0.948102 +v -0.155037 0.0342159 0.918365 +v -0.143447 0.00727528 0.940085 +v -0.188508 0.055577 0.881861 +v -0.128713 0.0776757 0.9026 +v -0.159167 0.0664178 0.894094 +v -0.225597 0.0165132 0.878354 +v -0.216542 0.0481267 0.863247 +v -0.237857 -0.0169093 0.886885 +v -0.0314129 0.062618 0.944549 +v -0.0591053 0.0273947 0.96148 +v -0.0272441 0.00174637 0.985368 +v -0.0296124 0.0304081 0.965777 +v -0.0652762 0.0925539 0.91594 +v -0.032753 0.0962353 0.919852 +v -0.0939443 0.0532189 0.93429 +v -0.0973395 0.0863776 0.910036 +v -0.0802969 -0.0053962 0.974961 +v -0.0883591 0.0217178 0.955411 +v -0.0313918 -0.121887 0.983992 +v -0.0640997 -0.158632 0.974036 +v -0.0317497 -0.157085 0.978196 +v -0.0273784 -0.0760818 0.993721 +v -0.05977 -0.0942344 0.98419 +v -0.0298425 -0.0936976 0.988793 +v -0.0956523 -0.123707 0.972085 +v -0.0810019 -0.0733797 0.982855 +v -0.0898671 -0.0931811 0.977114 +v -0.0976501 -0.160225 0.966985 +v -0.0864529 -0.0640166 0.98579 +v -0.0789269 -0.06284 0.994959 +v -0.0955999 -0.0476973 0.985969 +v -0.0940951 -0.0565412 0.98502 +v -0.0525276 -0.0775374 1.01483 +v -0.0666347 -0.0644079 1.00864 +v -0.0598989 -0.0753391 1.00401 +v -0.0652946 -0.0700523 1.00523 +v -0.0598411 -0.0536198 1.01768 +v -0.0788425 -0.0488271 1.00064 +v -0.0525009 -0.0662129 1.0231 +v -0.0652608 -0.0582549 1.01251 +v -0.0861068 -0.0306433 0.989153 +v -0.0938769 -0.0385712 0.986828 +v -0.0582598 -0.0403976 1.0119 +v -0.0476184 -0.0223971 1.0006 +v -0.0694706 -0.025394 0.994502 +v -0.0426567 -0.0627588 1.03251 +v -0.0344846 -0.0534302 1.03232 +v -0.0490439 -0.0525287 1.02501 +v -0.0209047 -0.039677 1.02317 +v -0.0152462 -0.0676801 1.04602 +v -0.0177789 -0.0547726 1.03745 +v -0.0242006 -0.0212264 1.00515 +v -0.0209476 -0.0779737 1.00716 +v -0.0477856 -0.0718253 0.995571 +v -0.0242757 -0.0726037 0.999895 +v -0.0152667 -0.0940994 1.02438 +v -0.0345351 -0.0845283 1.01121 +v -0.0178069 -0.0869021 1.01538 +v -0.0583871 -0.073576 0.998233 +v -0.0427012 -0.0854758 1.01505 +v -0.0491057 -0.0804193 1.00671 +v -0.0697639 -0.0690371 0.990088 +v -0.0394909 -0.0796254 1.02906 +v -0.0271444 -0.0763309 1.04139 +v -0.0399318 -0.0720589 1.03309 +v -0.0271637 -0.0905263 1.02914 +v -0.0399551 -0.0846544 1.02277 +v -0.0132272 -0.0889316 1.04223 +v -0.01374 -0.0942759 1.03402 +v -0.0137291 -0.0795664 1.04692 +vt 0.800375 0.667457 +vt 0.789584 0.668215 +vt 0.799923 0.663933 +vt 0.789057 0.664897 +vt 0.811842 0.670848 +vt 0.80103 0.671718 +vt 0.811217 0.666381 +vt 0.810346 0.655189 +vt 0.810548 0.658683 +vt 0.799442 0.658809 +vt 0.799641 0.661178 +vt 0.788653 0.662549 +vt 0.821717 0.660492 +vt 0.821466 0.655998 +vt 0.832622 0.658487 +vt 0.832389 0.653218 +vt 0.821251 0.651569 +vt 0.822539 0.669852 +vt 0.822041 0.665116 +vt 0.832855 0.663756 +vt 0.768389 0.668485 +vt 0.778915 0.668524 +vt 0.769427 0.673433 +vt 0.779732 0.673035 +vt 0.778165 0.664791 +vt 0.74577 0.661865 +vt 0.756532 0.663039 +vt 0.747747 0.667793 +vt 0.758027 0.6682 +vt 0.759367 0.673605 +vt 0.753496 0.653114 +vt 0.765177 0.656219 +vt 0.755019 0.658037 +vt 0.76625 0.660042 +vt 0.743793 0.655937 +vt 0.777492 0.661858 +vt 0.776857 0.659324 +vt 0.860743 0.66105 +vt 0.85437 0.658994 +vt 0.861885 0.655612 +vt 0.85471 0.654338 +vt 0.858253 0.665619 +vt 0.86356 0.668573 +vt 0.867109 0.663417 +vt 0.870052 0.650753 +vt 0.862482 0.650015 +vt 0.870421 0.644717 +vt 0.862589 0.644612 +vt 0.85505 0.649682 +vt 0.883125 0.662497 +vt 0.876218 0.659429 +vt 0.885992 0.655087 +vt 0.877897 0.652301 +vt 0.878895 0.645534 +vt 0.869196 0.672347 +vt 0.87346 0.666407 +vt 0.879453 0.669777 +vt 0.889305 0.677736 +vt 0.893116 0.683944 +vt 0.881403 0.682863 +vt 0.884277 0.688027 +vt 0.896144 0.692562 +vt 0.90593 0.689794 +vt 0.901798 0.679591 +vt 0.889995 0.666526 +vt 0.884742 0.673283 +vt 0.878268 0.679148 +vt 0.902596 0.665971 +vt 0.89431 0.659538 +vt 0.908133 0.659549 +vt 0.89794 0.652608 +vt 0.916609 0.686107 +vt 0.910596 0.674701 +vt 0.918591 0.668435 +vt 0.713434 0.678889 +vt 0.718232 0.673865 +vt 0.719971 0.68226 +vt 0.723135 0.677582 +vt 0.720227 0.663887 +vt 0.722594 0.669482 +vt 0.714094 0.668877 +vt 0.690854 0.689174 +vt 0.699881 0.681004 +vt 0.701094 0.693026 +vt 0.707762 0.685198 +vt 0.716169 0.688193 +vt 0.697269 0.662673 +vt 0.702107 0.668949 +vt 0.686646 0.668347 +vt 0.692886 0.67536 +vt 0.6822 0.683174 +vt 0.710252 0.663404 +vt 0.717861 0.658291 +vt 0.706788 0.657767 +vt 0.858365 0.672357 +vt 0.853611 0.668611 +vt 0.843559 0.666338 +vt 0.848795 0.664994 +vt 0.847566 0.670615 +vt 0.855227 0.679121 +vt 0.862995 0.676364 +vt 0.858343 0.683022 +vt 0.867102 0.680206 +vt 0.834415 0.678265 +vt 0.843484 0.67676 +vt 0.836434 0.683129 +vt 0.846261 0.68128 +vt 0.848914 0.685681 +vt 0.840865 0.672225 +vt 0.838324 0.667682 +vt 0.832962 0.673545 +vt 0.812703 0.675707 +vt 0.801925 0.676679 +vt 0.791163 0.677558 +vt 0.792268 0.683394 +vt 0.803066 0.682261 +vt 0.82446 0.679693 +vt 0.823312 0.674685 +vt 0.815369 0.686723 +vt 0.826081 0.684957 +vt 0.817113 0.692704 +vt 0.827981 0.690382 +vt 0.79352 0.689825 +vt 0.804461 0.688386 +vt 0.806115 0.694921 +vt 0.798864 0.71184 +vt 0.810186 0.708981 +vt 0.801046 0.72017 +vt 0.812549 0.716812 +vt 0.823667 0.712859 +vt 0.826337 0.721153 +vt 0.81509 0.725328 +vt 0.819076 0.698906 +vt 0.808032 0.701735 +vt 0.796857 0.704106 +vt 0.829963 0.69587 +vt 0.840668 0.692798 +vt 0.832092 0.701818 +vt 0.842717 0.698135 +vt 0.834432 0.708622 +vt 0.837107 0.716573 +vt 0.844937 0.704332 +vt 0.867471 0.703655 +vt 0.86533 0.696176 +vt 0.877095 0.699305 +vt 0.875007 0.692109 +vt 0.872828 0.687102 +vt 0.853212 0.694487 +vt 0.855272 0.700217 +vt 0.857607 0.707609 +vt 0.851162 0.689863 +vt 0.861137 0.686828 +vt 0.870286 0.68346 +vt 0.737342 0.674399 +vt 0.736161 0.679693 +vt 0.731151 0.674738 +vt 0.729268 0.679242 +vt 0.727195 0.684244 +vt 0.743049 0.685744 +vt 0.743345 0.679784 +vt 0.751789 0.685777 +vt 0.751276 0.679628 +vt 0.743533 0.67406 +vt 0.73204 0.698591 +vt 0.733516 0.691513 +vt 0.741945 0.699272 +vt 0.742539 0.692176 +vt 0.751932 0.692359 +vt 0.72474 0.690242 +vt 0.722029 0.697328 +vt 0.716708 0.714828 +vt 0.715092 0.72481 +vt 0.702617 0.714132 +vt 0.700538 0.724407 +vt 0.728191 0.725265 +vt 0.727285 0.735883 +vt 0.713954 0.735509 +vt 0.730575 0.706575 +vt 0.719186 0.705595 +vt 0.70688 0.704276 +vt 0.740902 0.715992 +vt 0.741399 0.707225 +vt 0.75229 0.716217 +vt 0.752093 0.707508 +vt 0.740453 0.725533 +vt 0.740092 0.735897 +vt 0.752425 0.725529 +vt 0.789126 0.722623 +vt 0.790991 0.731868 +vt 0.776943 0.72426 +vt 0.778298 0.733889 +vt 0.787299 0.713921 +vt 0.76386 0.71596 +vt 0.764649 0.725167 +vt 0.765442 0.735096 +vt 0.773153 0.698992 +vt 0.774288 0.706826 +vt 0.762394 0.699466 +vt 0.763091 0.707391 +vt 0.785576 0.705767 +vt 0.784024 0.698116 +vt 0.781583 0.684283 +vt 0.780606 0.678305 +vt 0.77033 0.678903 +vt 0.772112 0.691699 +vt 0.782707 0.69092 +vt 0.761214 0.685501 +vt 0.761821 0.692189 +vt 0.760412 0.679339 +vt 0.899727 0.753469 +vt 0.893091 0.747999 +vt 0.905106 0.743418 +vt 0.897762 0.739947 +vt 0.887783 0.741206 +vt 0.880731 0.745814 +vt 0.886161 0.754214 +vt 0.904716 0.775474 +vt 0.898651 0.768079 +vt 0.914323 0.765617 +vt 0.907202 0.758849 +vt 0.913707 0.74723 +vt 0.877978 0.781668 +vt 0.872582 0.772759 +vt 0.888929 0.775502 +vt 0.883177 0.767576 +vt 0.894526 0.783756 +vt 0.872228 0.750111 +vt 0.877492 0.759308 +vt 0.867387 0.763696 +vt 0.843778 0.771729 +vt 0.83028 0.775596 +vt 0.839713 0.76143 +vt 0.826842 0.765165 +vt 0.83386 0.786091 +vt 0.815809 0.779609 +vt 0.818643 0.790465 +vt 0.860927 0.77752 +vt 0.856148 0.767799 +vt 0.851602 0.757722 +vt 0.852231 0.792074 +vt 0.865736 0.787127 +vt 0.856409 0.802551 +vt 0.870501 0.796949 +vt 0.837491 0.796705 +vt 0.821654 0.801351 +vt 0.841215 0.807639 +vt 0.724356 0.780932 +vt 0.721897 0.791331 +vt 0.712133 0.77893 +vt 0.708432 0.787628 +vt 0.688991 0.788336 +vt 0.696924 0.781352 +vt 0.7032 0.796344 +vt 0.734947 0.804179 +vt 0.736823 0.793158 +vt 0.751835 0.804371 +vt 0.752608 0.793134 +vt 0.738282 0.782037 +vt 0.732844 0.815397 +vt 0.730608 0.827229 +vt 0.715066 0.812163 +vt 0.711339 0.823597 +vt 0.751007 0.816099 +vt 0.681689 0.797702 +vt 0.697958 0.806263 +vt 0.692594 0.817566 +vt 0.802671 0.795049 +vt 0.800517 0.783977 +vt 0.798447 0.773092 +vt 0.783398 0.776846 +vt 0.784699 0.788076 +vt 0.788691 0.822864 +vt 0.787323 0.810943 +vt 0.807157 0.818048 +vt 0.804858 0.806345 +vt 0.768947 0.80275 +vt 0.769269 0.814405 +vt 0.769629 0.82649 +vt 0.768262 0.779889 +vt 0.768648 0.791284 +vt 0.829319 0.730383 +vt 0.817782 0.734631 +vt 0.807922 0.748352 +vt 0.80562 0.738467 +vt 0.820629 0.744508 +vt 0.843731 0.736281 +vt 0.840238 0.725959 +vt 0.854152 0.732184 +vt 0.850604 0.721518 +vt 0.847491 0.747042 +vt 0.836031 0.750919 +vt 0.858049 0.743181 +vt 0.823637 0.754744 +vt 0.810425 0.758547 +vt 0.739591 0.758816 +vt 0.739858 0.747133 +vt 0.753132 0.758368 +vt 0.752889 0.746823 +vt 0.726681 0.747058 +vt 0.739135 0.77052 +vt 0.725558 0.770057 +vt 0.753262 0.7701 +vt 0.69786 0.758579 +vt 0.712375 0.758296 +vt 0.700367 0.76912 +vt 0.712782 0.769064 +vt 0.712907 0.746891 +vt 0.698005 0.747078 +vt 0.929639 0.699595 +vt 0.928443 0.716654 +vt 0.918934 0.700571 +vt 0.918764 0.716584 +vt 0.908376 0.702434 +vt 0.917291 0.732639 +vt 0.908091 0.730817 +vt 0.926839 0.733706 +vt 0.899583 0.717133 +vt 0.899655 0.729345 +vt 0.890467 0.718513 +vt 0.891789 0.729325 +vt 0.898356 0.704249 +vt 0.888732 0.70646 +vt 0.766981 0.757058 +vt 0.767683 0.768445 +vt 0.782175 0.765786 +vt 0.779622 0.744124 +vt 0.766227 0.745834 +vt 0.794659 0.751851 +vt 0.792827 0.741649 +vt 0.796513 0.762357 +vt 0.870023 0.713177 +vt 0.860485 0.717218 +vt 0.863872 0.728122 +vt 0.881776 0.720957 +vt 0.879363 0.709514 +vt 0.876505 0.735646 +vt 0.884297 0.731857 +vt 0.867737 0.739401 +vt 0.942885 0.685053 +vt 0.953367 0.687709 +vt 0.940102 0.70044 +vt 0.950147 0.702062 +vt 0.938165 0.716742 +vt 0.968754 0.704629 +vt 0.964644 0.717556 +vt 0.959599 0.703413 +vt 0.956139 0.717201 +vt 0.963128 0.689798 +vt 0.953145 0.730828 +vt 0.951463 0.743182 +vt 0.945243 0.731521 +vt 0.944286 0.744982 +vt 0.960533 0.730482 +vt 0.936315 0.732906 +vt 0.935707 0.747908 +vt 0.168776 0.186925 +vt 0.153188 0.186399 +vt 0.169355 0.173108 +vt 0.15372 0.172537 +vt 0.137511 0.174005 +vt 0.154886 0.15836 +vt 0.139434 0.160894 +vt 0.135878 0.200202 +vt 0.153921 0.199631 +vt 0.13741 0.213278 +vt 0.156324 0.212569 +vt 0.169774 0.199674 +vt 0.115769 0.200908 +vt 0.0946273 0.201684 +vt 0.11798 0.188318 +vt 0.0992616 0.189776 +vt 0.115489 0.212947 +vt 0.120823 0.175844 +vt 0.123982 0.163427 +vt 0.103896 0.177868 +vt 0.197705 0.18287 +vt 0.184318 0.177386 +vt 0.204286 0.174321 +vt 0.191177 0.166862 +vt 0.182759 0.189357 +vt 0.218051 0.196712 +vt 0.206672 0.195261 +vt 0.218754 0.189245 +vt 0.208611 0.187062 +vt 0.213838 0.179979 +vt 0.195322 0.2024 +vt 0.206572 0.20383 +vt 0.197221 0.212029 +vt 0.207879 0.212331 +vt 0.217851 0.204542 +vt 0.183316 0.200806 +vt 0.185616 0.211745 +vt 0.200177 0.221191 +vt 0.189289 0.222187 +vt 0.176497 0.223558 +vt 0.183072 0.235218 +vt 0.194814 0.232099 +vt 0.222696 0.225794 +vt 0.213531 0.227462 +vt 0.220244 0.219432 +vt 0.210159 0.220329 +vt 0.219048 0.242324 +vt 0.210793 0.236729 +vt 0.224444 0.237674 +vt 0.218111 0.23337 +vt 0.225701 0.231231 +vt 0.192704 0.246651 +vt 0.20267 0.241446 +vt 0.21291 0.248905 +vt 0.147552 0.942756 +vt 0.13896 0.937482 +vt 0.15442 0.936036 +vt 0.145004 0.930904 +vt 0.131991 0.943023 +vt 0.122815 0.936756 +vt 0.130641 0.931218 +vt 0.148962 0.952945 +vt 0.155644 0.947301 +vt 0.157149 0.955791 +vt 0.164222 0.950166 +vt 0.162965 0.941085 +vt 0.125551 0.956525 +vt 0.133402 0.953212 +vt 0.134656 0.9604 +vt 0.141677 0.957166 +vt 0.14902 0.960085 +vt 0.115375 0.942445 +vt 0.124894 0.947972 +vt 0.116632 0.951525 +vt 0.871579 0.942636 +vt 0.878596 0.946725 +vt 0.86416 0.948207 +vt 0.872055 0.95214 +vt 0.886187 0.942108 +vt 0.885478 0.951547 +vt 0.893652 0.946846 +vt 0.872605 0.934139 +vt 0.865133 0.939046 +vt 0.865671 0.931509 +vt 0.858017 0.93669 +vt 0.857275 0.944342 +vt 0.895145 0.930139 +vt 0.887213 0.93361 +vt 0.887365 0.926738 +vt 0.880339 0.930202 +vt 0.873942 0.927331 +vt 0.901581 0.942011 +vt 0.893918 0.937827 +vt 0.902324 0.934359 +vt 0.937778 0.969427 +vt 0.924742 0.963135 +vt 0.963417 0.953814 +vt 0.94277 0.951002 +vt 0.929636 0.938971 +vt 0.950985 0.939207 +vt 0.924587 0.948175 +vt 0.897606 0.964725 +vt 0.904637 0.974329 +vt 0.880983 0.968761 +vt 0.883219 0.980673 +vt 0.91214 0.985041 +vt 0.902437 0.951808 +vt 0.891517 0.95734 +vt 0.87954 0.960235 +vt 0.911331 0.94532 +vt 0.915423 0.938551 +vt 0.837802 0.927994 +vt 0.819804 0.940196 +vt 0.826204 0.927352 +vt 0.800609 0.943494 +vt 0.811605 0.952025 +vt 0.831685 0.94681 +vt 0.836697 0.937574 +vt 0.857877 0.916732 +vt 0.87928 0.910354 +vt 0.863614 0.921492 +vt 0.880267 0.917735 +vt 0.851798 0.911211 +vt 0.857703 0.929735 +vt 0.868668 0.924726 +vt 0.880724 0.922242 +vt 0.845039 0.94326 +vt 0.848987 0.936302 +vt 0.924475 0.930625 +vt 0.941648 0.929031 +vt 0.96114 0.927417 +vt 0.933224 0.916635 +vt 0.922496 0.92029 +vt 0.903495 0.926861 +vt 0.911938 0.93218 +vt 0.897103 0.91889 +vt 0.892712 0.923251 +vt 0.905308 0.905852 +vt 0.901263 0.912802 +vt 0.820926 0.962167 +vt 0.836809 0.955124 +vt 0.840048 0.970839 +vt 0.802886 0.96989 +vt 0.830758 0.980145 +vt 0.856645 0.954682 +vt 0.848379 0.949442 +vt 0.864116 0.967327 +vt 0.867473 0.958814 +vt 0.86125 0.978259 +vt 0.85863 0.990399 +vt 0.191842 0.938528 +vt 0.18483 0.928669 +vt 0.214023 0.932819 +vt 0.202519 0.920832 +vt 0.190621 0.899112 +vt 0.222723 0.912315 +vt 0.180131 0.909732 +vt 0.161958 0.928403 +vt 0.17217 0.935147 +vt 0.177196 0.942628 +vt 0.133862 0.910183 +vt 0.152639 0.912726 +vt 0.135915 0.920575 +vt 0.149326 0.922843 +vt 0.155653 0.899975 +vt 0.158518 0.885909 +vt 0.131 0.896051 +vt 0.0727151 0.905945 +vt 0.0872616 0.914579 +vt 0.045865 0.922565 +vt 0.0688679 0.927864 +vt 0.0891699 0.932953 +vt 0.0611106 0.940896 +vt 0.0850445 0.943365 +vt 0.116168 0.914322 +vt 0.108088 0.902447 +vt 0.0995652 0.889326 +vt 0.112481 0.9301 +vt 0.123364 0.923705 +vt 0.10407 0.937626 +vt 0.101008 0.945485 +vt 0.141749 0.967835 +vt 0.159735 0.964585 +vt 0.141615 0.973986 +vt 0.164947 0.968203 +vt 0.198452 0.956803 +vt 0.170264 0.972446 +vt 0.186612 0.957297 +vt 0.165935 0.957311 +vt 0.154732 0.962219 +vt 0.141924 0.964387 +vt 0.187555 0.948567 +vt 0.17427 0.950399 +vt 0.205846 0.945238 +vt 0.226639 0.94116 +vt 0.0918948 0.952851 +vt 0.072194 0.95227 +vt 0.0497805 0.951411 +vt 0.080546 0.963637 +vt 0.0937428 0.962144 +vt 0.116457 0.959008 +vt 0.10617 0.952878 +vt 0.123264 0.966181 +vt 0.12877 0.963081 +vt 0.111312 0.975863 +vt 0.117382 0.970674 +vt 0.168188 0.257701 +vt 0.179853 0.251475 +vt 0.181861 0.270696 +vt 0.19145 0.264485 +vt 0.168322 0.238524 +vt 0.157989 0.278114 +vt 0.139623 0.26474 +vt 0.161775 0.267111 +vt 0.143271 0.254169 +vt 0.176773 0.279775 +vt 0.122129 0.24267 +vt 0.0996677 0.231893 +vt 0.121641 0.233595 +vt 0.0964428 0.225792 +vt 0.121258 0.251367 +vt 0.141637 0.226246 +vt 0.118437 0.223765 +vt 0.0932179 0.219692 +vt 0.160802 0.225544 +vt 0.0419152 0.53618 +vt 0.0472563 0.523503 +vt 0.0332681 0.539408 +vt 0.038828 0.522754 +vt 0.0547796 0.5128 +vt 0.0629257 0.517019 +vt 0.0550589 0.52441 +vt 0.0478604 0.554178 +vt 0.0476885 0.543737 +vt 0.0376346 0.561691 +vt 0.0380519 0.549348 +vt 0.0277081 0.556063 +vt 0.0662616 0.533766 +vt 0.0581 0.532485 +vt 0.0632249 0.540131 +vt 0.0559107 0.540335 +vt 0.055828 0.548702 +vt 0.0616102 0.525629 +vt 0.0679204 0.520553 +vt 0.0687181 0.527585 +vt 0.0509533 0.580146 +vt 0.0426311 0.57189 +vt 0.0442882 0.588789 +vt 0.0332182 0.580753 +vt 0.0513392 0.563763 +vt 0.0757862 0.577556 +vt 0.0655669 0.57722 +vt 0.0718228 0.588438 +vt 0.060513 0.586655 +vt 0.0553583 0.596825 +vt 0.0637107 0.564356 +vt 0.0704192 0.569255 +vt 0.070071 0.55722 +vt 0.0760258 0.562179 +vt 0.0789464 0.569999 +vt 0.0586375 0.557107 +vt 0.0648092 0.550898 +vt 0.0904211 0.548013 +vt 0.0833422 0.555408 +vt 0.0957205 0.55254 +vt 0.0881221 0.560358 +vt 0.0767944 0.549978 +vt 0.090315 0.526886 +vt 0.0877993 0.53464 +vt 0.0982366 0.53011 +vt 0.0953147 0.539062 +vt 0.100791 0.542278 +vt 0.0746039 0.537227 +vt 0.0781908 0.530701 +vt 0.0798442 0.524364 +vt 0.0701373 0.544116 +vt 0.925171 0.815649 +vt 0.920243 0.805051 +vt 0.934775 0.80669 +vt 0.929739 0.796503 +vt 0.93322 0.778201 +vt 0.938087 0.788562 +vt 0.924761 0.786096 +vt 0.904862 0.803051 +vt 0.910168 0.813683 +vt 0.893079 0.810992 +vt 0.898686 0.821929 +vt 0.915568 0.824608 +vt 0.910263 0.784583 +vt 0.899742 0.793007 +vt 0.888113 0.80057 +vt 0.919899 0.77525 +vt 0.928896 0.766724 +vt 0.815787 0.855921 +vt 0.819336 0.868912 +vt 0.793818 0.862058 +vt 0.795798 0.875795 +vt 0.831679 0.83698 +vt 0.836161 0.849417 +vt 0.812478 0.843031 +vt 0.770591 0.852857 +vt 0.771369 0.867508 +vt 0.748599 0.854921 +vt 0.748212 0.870509 +vt 0.772261 0.882678 +vt 0.790259 0.835472 +vt 0.77004 0.839246 +vt 0.749297 0.841006 +vt 0.80965 0.830342 +vt 0.827993 0.824626 +vt 0.724119 0.869298 +vt 0.722193 0.885121 +vt 0.69961 0.865356 +vt 0.695663 0.88068 +vt 0.726136 0.854086 +vt 0.681189 0.844692 +vt 0.675206 0.860163 +vt 0.659402 0.836491 +vt 0.651382 0.852648 +vt 0.669133 0.87624 +vt 0.686995 0.830434 +vt 0.707465 0.836555 +vt 0.667117 0.821916 +vt 0.728335 0.840094 +vt 0.844791 0.630193 +vt 0.844724 0.634228 +vt 0.843982 0.630547 +vt 0.842478 0.634715 +vt 0.837664 0.639425 +vt 0.840419 0.635163 +vt 0.840973 0.638882 +vt 0.848717 0.637567 +vt 0.847346 0.633664 +vt 0.854083 0.636646 +vt 0.851791 0.632782 +vt 0.845599 0.629839 +vt 0.849337 0.641623 +vt 0.849581 0.645756 +vt 0.844215 0.642375 +vt 0.843773 0.646487 +vt 0.855223 0.640762 +vt 0.839469 0.64305 +vt 0.83491 0.643687 +vt 0.837964 0.647218 +vt 0.725656 0.643083 +vt 0.719643 0.64232 +vt 0.724939 0.640251 +vt 0.71996 0.638782 +vt 0.711679 0.641543 +vt 0.711659 0.645946 +vt 0.719749 0.645744 +vt 0.738356 0.646598 +vt 0.732577 0.6462 +vt 0.736627 0.644893 +vt 0.731247 0.643959 +vt 0.729918 0.641719 +vt 0.727515 0.648634 +vt 0.733906 0.64844 +vt 0.728655 0.651352 +vt 0.735235 0.65068 +vt 0.740086 0.648303 +vt 0.712958 0.649959 +vt 0.7207 0.648941 +vt 0.722074 0.652024 +vt 0.884966 0.82932 +vt 0.890192 0.840682 +vt 0.86976 0.836188 +vt 0.87442 0.847798 +vt 0.879899 0.818138 +vt 0.849222 0.830896 +vt 0.853822 0.842863 +vt 0.858647 0.854913 +vt 0.860816 0.813432 +vt 0.845073 0.819095 +vt 0.87515 0.807317 +vt 0.953522 0.784398 +vt 0.950371 0.775653 +vt 0.958094 0.777732 +vt 0.955796 0.769832 +vt 0.959544 0.757237 +vt 0.961105 0.764151 +vt 0.953683 0.761713 +vt 0.940794 0.771842 +vt 0.944716 0.781755 +vt 0.94895 0.791065 +vt 0.945308 0.756461 +vt 0.937496 0.760723 +vt 0.957984 0.750323 +vt 0.951941 0.753153 +vt 0.237985 0.738297 +vt 0.268705 0.737229 +vt 0.241633 0.762787 +vt 0.268705 0.761697 +vt 0.200475 0.715676 +vt 0.234693 0.711537 +vt 0.207029 0.741466 +vt 0.222333 0.788147 +vt 0.245519 0.78554 +vt 0.230341 0.810102 +vt 0.249523 0.807426 +vt 0.268705 0.784364 +vt 0.159946 0.773803 +vt 0.187254 0.769363 +vt 0.175961 0.794629 +vt 0.199147 0.791261 +vt 0.211159 0.812779 +vt 0.165843 0.72393 +vt 0.175598 0.746705 +vt 0.14393 0.752977 +vt 0.253345 0.280308 +vt 0.268706 0.280765 +vt 0.253464 0.295744 +vt 0.268576 0.296249 +vt 0.238317 0.265747 +vt 0.253558 0.266767 +vt 0.238168 0.279086 +vt 0.239577 0.31028 +vt 0.253859 0.311911 +vt 0.240382 0.325349 +vt 0.254334 0.327593 +vt 0.268615 0.312525 +vt 0.21323 0.291052 +vt 0.225134 0.292637 +vt 0.214544 0.305067 +vt 0.22632 0.307825 +vt 0.227134 0.322083 +vt 0.223441 0.277203 +vt 0.223004 0.263413 +vt 0.210121 0.276206 +vt 0.268934 0.241592 +vt 0.268768 0.248379 +vt 0.255927 0.241503 +vt 0.254998 0.248112 +vt 0.243677 0.241038 +vt 0.256594 0.23557 +vt 0.244966 0.235422 +vt 0.239676 0.25526 +vt 0.254158 0.256284 +vt 0.268799 0.256538 +vt 0.225586 0.253155 +vt 0.229504 0.24562 +vt 0.233074 0.239996 +vt 0.235164 0.235206 +vt 0.672084 0.639787 +vt 0.66845 0.628475 +vt 0.686608 0.639919 +vt 0.68396 0.631421 +vt 0.660815 0.654442 +vt 0.655577 0.64149 +vt 0.676137 0.650509 +vt 0.700237 0.640623 +vt 0.701506 0.646666 +vt 0.69947 0.634368 +vt 0.693146 0.655714 +vt 0.703781 0.652284 +vt 0.681027 0.660046 +vt 0.66725 0.665722 +vt 0.869213 0.629853 +vt 0.859507 0.631337 +vt 0.868187 0.625508 +vt 0.857298 0.627496 +vt 0.861301 0.635363 +vt 0.891113 0.635857 +vt 0.879896 0.634217 +vt 0.89156 0.629458 +vt 0.879626 0.628853 +vt 0.879077 0.62352 +vt 0.870406 0.639191 +vt 0.879607 0.639641 +vt 0.889853 0.641715 +vt 0.862262 0.639758 +vt 0.92121 0.637592 +vt 0.905828 0.63279 +vt 0.925118 0.630408 +vt 0.907542 0.62597 +vt 0.903798 0.639508 +vt 0.942567 0.656273 +vt 0.930472 0.650822 +vt 0.949711 0.646823 +vt 0.936482 0.642606 +vt 0.942694 0.634846 +vt 0.912967 0.652217 +vt 0.924862 0.659954 +vt 0.936428 0.667127 +vt 0.901136 0.646022 +vt 0.966001 0.650564 +vt 0.958961 0.649232 +vt 0.970644 0.639264 +vt 0.965457 0.639274 +vt 0.952791 0.65981 +vt 0.969418 0.663982 +vt 0.972601 0.651548 +vt 0.976942 0.665473 +vt 0.97898 0.652359 +vt 0.975831 0.639254 +vt 0.957281 0.67448 +vt 0.966331 0.676693 +vt 0.974903 0.678588 +vt 0.947274 0.67163 +vt 0.269766 0.158525 +vt 0.250658 0.159766 +vt 0.270029 0.149052 +vt 0.248065 0.150831 +vt 0.220307 0.146351 +vt 0.245291 0.141613 +vt 0.226699 0.154829 +vt 0.24059 0.178843 +vt 0.237237 0.170956 +vt 0.254532 0.176342 +vt 0.25289 0.168134 +vt 0.269586 0.166899 +vt 0.216438 0.167843 +vt 0.223799 0.174757 +vt 0.228354 0.181409 +vt 0.20652 0.159758 +vt 0.195322 0.151089 +vt 0.255674 0.193252 +vt 0.255353 0.184799 +vt 0.26904 0.192481 +vt 0.269203 0.183716 +vt 0.242017 0.186776 +vt 0.242969 0.210229 +vt 0.242663 0.202753 +vt 0.255922 0.209205 +vt 0.255817 0.201447 +vt 0.269103 0.200716 +vt 0.229862 0.196333 +vt 0.229944 0.203984 +vt 0.230377 0.211402 +vt 0.229853 0.188704 +vt 0.256133 0.216346 +vt 0.269011 0.215922 +vt 0.256393 0.223033 +vt 0.26887 0.222737 +vt 0.243486 0.217235 +vt 0.244951 0.229727 +vt 0.256648 0.229427 +vt 0.268973 0.2293 +vt 0.232926 0.224635 +vt 0.234642 0.230172 +vt 0.231438 0.218332 +vt 0.231875 0.681974 +vt 0.195405 0.687835 +vt 0.268705 0.681041 +vt 0.268707 0.649795 +vt 0.231298 0.650222 +vt 0.159651 0.701684 +vt 0.124255 0.719528 +vt 0.152896 0.681504 +vt 0.120595 0.706905 +vt 0.162996 0.634435 +vt 0.141452 0.664926 +vt 0.142052 0.61864 +vt 0.127664 0.650149 +vt 0.116935 0.694282 +vt 0.211524 0.580428 +vt 0.203702 0.612749 +vt 0.187831 0.570739 +vt 0.178593 0.601672 +vt 0.15644 0.58713 +vt 0.268705 0.617234 +vt 0.234725 0.616894 +vt 0.239135 0.585332 +vt 0.199167 0.27764 +vt 0.203439 0.290476 +vt 0.191338 0.282164 +vt 0.195938 0.298294 +vt 0.204702 0.30253 +vt 0.194745 0.309006 +vt 0.204397 0.314025 +vt 0.187394 0.290439 +vt 0.185378 0.30188 +vt 0.158413 0.418134 +vt 0.159054 0.422514 +vt 0.151701 0.418126 +vt 0.153357 0.422511 +vt 0.148767 0.427196 +vt 0.147324 0.422254 +vt 0.154331 0.42702 +vt 0.164378 0.426932 +vt 0.164461 0.422716 +vt 0.169254 0.42687 +vt 0.169733 0.422548 +vt 0.164807 0.418553 +vt 0.159617 0.435925 +vt 0.159655 0.431437 +vt 0.163693 0.43525 +vt 0.1639 0.431123 +vt 0.16807 0.431122 +vt 0.15511 0.43158 +vt 0.150273 0.432153 +vt 0.155198 0.436148 +vt 0.137897 0.391939 +vt 0.139469 0.389504 +vt 0.17063 0.392906 +vt 0.177579 0.390684 +vt 0.108525 0.396264 +vt 0.10962 0.392167 +vt 0.136029 0.394644 +vt 0.189135 0.398093 +vt 0.201386 0.395105 +vt 0.205359 0.404085 +vt 0.221392 0.400547 +vt 0.215689 0.391863 +vt 0.159402 0.397834 +vt 0.180988 0.400577 +vt 0.156251 0.401361 +vt 0.175531 0.40322 +vt 0.1956 0.40625 +vt 0.133566 0.39789 +vt 0.106177 0.400376 +vt 0.13333 0.401583 +vt 0.105778 0.419582 +vt 0.112909 0.431692 +vt 0.0857539 0.42372 +vt 0.0978159 0.435407 +vt 0.0792543 0.412786 +vt 0.0493589 0.420043 +vt 0.0604704 0.429958 +vt 0.113824 0.445537 +vt 0.130697 0.452864 +vt 0.104492 0.449389 +vt 0.127195 0.455721 +vt 0.123421 0.442151 +vt 0.0620736 0.445754 +vt 0.0967788 0.453971 +vt 0.042503 0.451596 +vt 0.0898755 0.458919 +vt 0.12693 0.459685 +vt 0.0109524 0.427572 +vt 0.0292777 0.436932 +vt -0.00486957 0.444274 +vt 0.218498 0.42425 +vt 0.211205 0.424626 +vt 0.236149 0.408646 +vt 0.221871 0.411246 +vt 0.209393 0.413479 +vt 0.194343 0.436667 +vt 0.197771 0.438115 +vt 0.182271 0.446693 +vt 0.18375 0.449328 +vt 0.200848 0.439853 +vt 0.190212 0.435797 +vt 0.185733 0.435099 +vt 0.197971 0.425316 +vt 0.191608 0.425692 +vt 0.179819 0.445093 +vt 0.200514 0.414982 +vt 0.193566 0.416303 +vt 0.160223 0.460849 +vt 0.159192 0.459271 +vt 0.17171 0.458153 +vt 0.171322 0.455881 +vt 0.17064 0.453743 +vt 0.14455 0.458507 +vt 0.146064 0.460995 +vt 0.148735 0.463545 +vt 0.158128 0.455703 +vt 0.14535 0.456142 +vt 0.158194 0.452773 +vt 0.147456 0.453335 +vt 0.169371 0.451874 +vt 0.167924 0.449711 +vt 0.0851413 0.39891 +vt 0.0922294 0.393554 +vt 0.0991561 0.388722 +vt 0.100257 0.388524 +vt 0.0806903 0.395723 +vt 0.0520286 0.41091 +vt 0.0799332 0.404918 +vt 0.0223556 0.413036 +vt 0.0433475 0.407848 +vt -0.0149432 0.424994 +vt 0.019659 0.417742 +vt 0.0699681 0.398298 +vt 0.0980548 0.388921 +vt 0.0596545 0.401078 +vt 0.112325 0.545469 +vt 0.112227 0.562147 +vt 0.121292 0.533311 +vt 0.124355 0.551553 +vt 0.0994555 0.572536 +vt 0.0969232 0.587328 +vt 0.112171 0.578561 +vt 0.106779 0.524557 +vt 0.107589 0.538443 +vt 0.110423 0.513527 +vt 0.112506 0.528264 +vt 0.118228 0.515069 +vt 0.0989423 0.555133 +vt 0.104283 0.542593 +vt 0.104701 0.530629 +vt 0.0882754 0.571292 +vt 0.0894754 0.56478 +vt 0.0853955 0.582515 +vt 0.0816758 0.596094 +vt 0.0753139 0.485928 +vt 0.0650052 0.492652 +vt 0.0850253 0.491819 +vt 0.076075 0.499356 +vt 0.0930081 0.48361 +vt 0.100394 0.488016 +vt 0.0945577 0.497873 +vt 0.0651895 0.505551 +vt 0.073766 0.51176 +vt 0.0546966 0.499376 +vt 0.0900973 0.518593 +vt 0.0785101 0.518041 +vt 0.0994002 0.522709 +vt 0.100625 0.514782 +vt 0.107779 0.492421 +vt 0.103732 0.504253 +vt 0.23946 0.508287 +vt 0.230571 0.517622 +vt 0.228964 0.503271 +vt 0.217261 0.507781 +vt 0.188396 0.491269 +vt 0.206255 0.496224 +vt 0.200655 0.50824 +vt 0.268702 0.540749 +vt 0.243925 0.538213 +vt 0.268704 0.526377 +vt 0.248486 0.524031 +vt 0.253257 0.51249 +vt 0.215104 0.553361 +vt 0.241505 0.558876 +vt 0.268704 0.561105 +vt 0.190298 0.545736 +vt 0.166291 0.537055 +vt 0.187254 0.524533 +vt 0.161754 0.51849 +vt 0.170538 0.486314 +vt 0.179959 0.505005 +vt 0.157216 0.499924 +vt 0.24946 0.367438 +vt 0.258636 0.367175 +vt 0.255765 0.379731 +vt 0.262283 0.37965 +vt 0.255826 0.354536 +vt 0.268674 0.354878 +vt 0.268728 0.367451 +vt 0.234227 0.359499 +vt 0.242109 0.369275 +vt 0.228611 0.363909 +vt 0.23567 0.3719 +vt 0.249247 0.379811 +vt 0.215158 0.338968 +vt 0.227222 0.344776 +vt 0.214279 0.345817 +vt 0.224857 0.351242 +vt 0.221552 0.355917 +vt 0.240937 0.339238 +vt 0.227708 0.334728 +vt 0.215289 0.329543 +vt 0.268674 0.342201 +vt 0.254691 0.341571 +vt 0.244771 0.497304 +vt 0.256308 0.499747 +vt 0.268704 0.500841 +vt 0.268703 0.486337 +vt 0.258069 0.48605 +vt 0.225998 0.491141 +vt 0.227882 0.481103 +vt 0.234955 0.49435 +vt 0.237658 0.483058 +vt 0.249236 0.471672 +vt 0.239501 0.471434 +vt 0.250178 0.458265 +vt 0.240915 0.459645 +vt 0.229767 0.471064 +vt 0.25897 0.471644 +vt 0.268704 0.471564 +vt 0.259441 0.456884 +vt 0.203423 0.33552 +vt 0.203968 0.325186 +vt 0.193422 0.320894 +vt 0.18965 0.357864 +vt 0.190908 0.345555 +vt 0.202072 0.352895 +vt 0.202774 0.344537 +vt 0.18128 0.331343 +vt 0.179249 0.347026 +vt 0.17058 0.329645 +vt 0.167693 0.348723 +vt 0.177228 0.362833 +vt 0.183331 0.315904 +vt 0.173467 0.310566 +vt 0.17135 0.406685 +vt 0.182441 0.411169 +vt 0.16826 0.410583 +vt 0.176559 0.414437 +vt 0.155839 0.404764 +vt 0.157521 0.413533 +vt 0.166076 0.414524 +vt 0.172571 0.417098 +vt 0.135724 0.413665 +vt 0.144491 0.409813 +vt 0.142544 0.416326 +vt 0.148879 0.413937 +vt 0.13814 0.405626 +vt 0.124506 0.410074 +vt 0.174252 0.441387 +vt 0.171559 0.438762 +vt 0.181259 0.434168 +vt 0.176807 0.433082 +vt 0.186036 0.426037 +vt 0.174588 0.426678 +vt 0.172391 0.431921 +vt 0.168862 0.436383 +vt 0.180644 0.419795 +vt 0.175028 0.421443 +vt 0.186883 0.417995 +vt 0.149859 0.449516 +vt 0.140851 0.446115 +vt 0.152195 0.445145 +vt 0.145413 0.441926 +vt 0.158597 0.449574 +vt 0.159394 0.440679 +vt 0.154101 0.440679 +vt 0.14915 0.438598 +vt 0.165593 0.443116 +vt 0.164422 0.439274 +vt 0.166713 0.446693 +vt 0.121193 0.418911 +vt 0.132677 0.420037 +vt 0.1248 0.429441 +vt 0.142327 0.427533 +vt 0.140909 0.42129 +vt 0.13921 0.436123 +vt 0.145149 0.43376 +vt 0.131925 0.438966 +vt 0.718331 0.590305 +vt 0.746935 0.609408 +vt 0.714187 0.592962 +vt 0.74538 0.618837 +vt 0.776045 0.619539 +vt 0.775836 0.606046 +vt 0.748316 0.600181 +vt 0.698297 0.570265 +vt 0.691016 0.56935 +vt 0.678793 0.553513 +vt 0.668258 0.550016 +vt 0.682993 0.567088 +vt 0.724973 0.581367 +vt 0.704095 0.568485 +vt 0.726629 0.571953 +vt 0.707052 0.562689 +vt 0.687534 0.554647 +vt 0.775571 0.595734 +vt 0.74935 0.591359 +vt 0.749786 0.580241 +vt 0.631527 0.521919 +vt 0.643349 0.524282 +vt 0.641663 0.531566 +vt 0.653323 0.535777 +vt 0.66485 0.539385 +vt 0.649849 0.514184 +vt 0.635476 0.513181 +vt 0.647883 0.501604 +vt 0.631937 0.501954 +vt 0.62139 0.512271 +vt 0.684619 0.531929 +vt 0.668859 0.529 +vt 0.681508 0.516892 +vt 0.664797 0.515372 +vt 0.663468 0.501153 +vt 0.676113 0.541788 +vt 0.689104 0.545131 +vt 0.919101 0.529512 +vt 0.932277 0.513107 +vt 0.933894 0.53169 +vt 0.952549 0.514234 +vt 0.938271 0.4968 +vt 0.915407 0.496828 +vt 0.912378 0.512315 +vt 0.874997 0.559455 +vt 0.89162 0.543518 +vt 0.884334 0.563198 +vt 0.903546 0.546094 +vt 0.915238 0.549145 +vt 0.888008 0.52727 +vt 0.879227 0.541892 +vt 0.86975 0.528566 +vt 0.864702 0.54298 +vt 0.866281 0.556104 +vt 0.894945 0.496872 +vt 0.893224 0.512192 +vt 0.87312 0.513029 +vt 0.860186 0.581167 +vt 0.86658 0.586129 +vt 0.833052 0.598471 +vt 0.836578 0.605656 +vt 0.854086 0.575883 +vt 0.804878 0.613577 +vt 0.803304 0.602321 +vt 0.806576 0.625184 +vt 0.801979 0.591764 +vt 0.80095 0.579355 +vt 0.826879 0.582241 +vt 0.824828 0.570521 +vt 0.848572 0.569954 +vt 0.845415 0.561476 +vt 0.723056 0.499144 +vt 0.723365 0.520768 +vt 0.700461 0.499917 +vt 0.701169 0.518891 +vt 0.702985 0.536491 +vt 0.773996 0.544472 +vt 0.748527 0.544271 +vt 0.773366 0.521907 +vt 0.747679 0.521923 +vt 0.747248 0.498271 +vt 0.725988 0.558685 +vt 0.74937 0.564127 +vt 0.774586 0.566031 +vt 0.705814 0.551558 +vt 0.799676 0.520274 +vt 0.799659 0.497042 +vt 0.825661 0.517765 +vt 0.825711 0.49681 +vt 0.799857 0.542467 +vt 0.848896 0.532613 +vt 0.850371 0.515118 +vt 0.850862 0.496842 +vt 0.824745 0.55595 +vt 0.846383 0.548548 +vt 0.800262 0.562542 +vt 0.622835 0.741898 +vt 0.629822 0.737341 +vt 0.630937 0.748106 +vt 0.637348 0.741916 +vt 0.638168 0.732456 +vt 0.632743 0.72671 +vt 0.623594 0.732979 +vt 0.601364 0.736825 +vt 0.612351 0.737387 +vt 0.601727 0.746549 +vt 0.614012 0.74515 +vt 0.621199 0.753622 +vt 0.623692 0.721651 +vt 0.615298 0.729693 +vt 0.603694 0.727299 +vt 0.64705 0.720202 +vt 0.651064 0.728223 +vt 0.666861 0.725286 +vt 0.666356 0.736499 +vt 0.651523 0.736804 +vt 0.655097 0.70327 +vt 0.638367 0.712843 +vt 0.644545 0.693632 +vt 0.627328 0.703786 +vt 0.680292 0.699272 +vt 0.669656 0.692929 +vt 0.66043 0.68407 +vt 0.686784 0.713263 +vt 0.693307 0.702612 +vt 0.683906 0.72429 +vt 0.682763 0.73584 +vt 0.664776 0.7482 +vt 0.649538 0.745843 +vt 0.644256 0.754878 +vt 0.68235 0.760278 +vt 0.681446 0.748063 +vt 0.67624 0.777475 +vt 0.68787 0.771805 +vt 0.657375 0.798004 +vt 0.64028 0.785894 +vt 0.666427 0.786487 +vt 0.651148 0.774455 +vt 0.634824 0.763445 +vt 0.622928 0.773335 +vt 0.597165 0.801047 +vt 0.584037 0.816073 +vt 0.575655 0.789046 +vt 0.561282 0.802854 +vt 0.606349 0.829025 +vt 0.594793 0.84477 +vt 0.570888 0.831255 +vt 0.629233 0.799056 +vt 0.610251 0.786335 +vt 0.590115 0.774943 +vt 0.648026 0.811186 +vt 0.638424 0.825833 +vt 0.628613 0.841743 +vt 0.618698 0.858285 +vt 0.643447 0.660513 +vt 0.635997 0.646287 +vt 0.6049 0.637043 +vt 0.628919 0.631286 +vt 0.614692 0.652678 +vt 0.634531 0.681735 +vt 0.651642 0.673186 +vt 0.584936 0.681759 +vt 0.604883 0.675219 +vt 0.597105 0.697898 +vt 0.616244 0.690669 +vt 0.593009 0.659162 +vt 0.58088 0.642801 +vt 0.571868 0.665802 +vt 0.586302 0.735665 +vt 0.587541 0.725613 +vt 0.566532 0.713946 +vt 0.585456 0.714475 +vt 0.569532 0.724249 +vt 0.584349 0.745549 +vt 0.579071 0.755761 +vt 0.565094 0.743135 +vt 0.557994 0.751956 +vt 0.550572 0.731836 +vt 0.547179 0.740294 +vt 0.532926 0.729581 +vt 0.530226 0.737883 +vt 0.540511 0.747664 +vt 0.550413 0.713789 +vt 0.552359 0.722818 +vt 0.536163 0.720718 +vt 0.553225 0.778158 +vt 0.567858 0.766798 +vt 0.546459 0.760192 +vt 0.496408 0.78312 +vt 0.5145 0.775693 +vt 0.521696 0.80043 +vt 0.537687 0.789339 +vt 0.512875 0.758052 +vt 0.492969 0.762083 +vt 0.500324 0.747435 +vt 0.478432 0.748437 +vt 0.471121 0.76581 +vt 0.5289 0.753414 +vt 0.51732 0.74582 +vt 0.55219 0.672662 +vt 0.56563 0.687095 +vt 0.519008 0.667707 +vt 0.537934 0.658133 +vt 0.533662 0.679776 +vt 0.558759 0.703094 +vt 0.577435 0.701334 +vt 0.516448 0.703502 +vt 0.530573 0.696655 +vt 0.529774 0.709521 +vt 0.542602 0.705297 +vt 0.515971 0.687177 +vt 0.500082 0.677282 +vt 0.500703 0.696106 +vt 0.496419 0.736002 +vt 0.513862 0.73676 +vt 0.515969 0.727011 +vt 0.476228 0.734685 +vt 0.454664 0.733089 +vt 0.481514 0.721061 +vt 0.463494 0.717678 +vt 0.505915 0.712954 +vt 0.489445 0.707801 +vt 0.472325 0.702267 +vt 0.521085 0.717345 +vt 0.817772 0.32972 +vt 0.817268 0.334177 +vt 0.807098 0.329266 +vt 0.806518 0.333516 +vt 0.806012 0.337004 +vt 0.795796 0.333142 +vt 0.795184 0.336418 +vt 0.838686 0.341177 +vt 0.827785 0.339607 +vt 0.838685 0.335915 +vt 0.827985 0.335004 +vt 0.82832 0.330282 +vt 0.827498 0.348469 +vt 0.816308 0.345239 +vt 0.82763 0.344073 +vt 0.816582 0.341797 +vt 0.838688 0.346438 +vt 0.805553 0.339703 +vt 0.794562 0.338721 +vt 0.805117 0.342008 +vt 0.784417 0.336886 +vt 0.785167 0.333173 +vt 0.774651 0.33352 +vt 0.775476 0.328538 +vt 0.785864 0.328653 +vt 0.771718 0.345756 +vt 0.772735 0.341953 +vt 0.782822 0.342267 +vt 0.783629 0.339781 +vt 0.763085 0.339283 +vt 0.761859 0.344306 +vt 0.752475 0.340764 +vt 0.750993 0.34675 +vt 0.760614 0.349246 +vt 0.765302 0.328633 +vt 0.764271 0.334092 +vt 0.753958 0.334778 +vt 0.872696 0.335583 +vt 0.866407 0.338084 +vt 0.86882 0.330441 +vt 0.863658 0.333516 +vt 0.867867 0.343569 +vt 0.860064 0.340257 +vt 0.860616 0.34494 +vt 0.882136 0.339457 +vt 0.878875 0.332422 +vt 0.888775 0.336165 +vt 0.88462 0.328842 +vt 0.874176 0.326498 +vt 0.876903 0.354499 +vt 0.876407 0.348394 +vt 0.885368 0.353577 +vt 0.88421 0.346688 +vt 0.892061 0.343631 +vt 0.868751 0.349227 +vt 0.861168 0.349623 +vt 0.869036 0.354668 +vt 0.905832 0.318045 +vt 0.897126 0.314006 +vt 0.909273 0.307792 +vt 0.899606 0.305356 +vt 0.888216 0.310241 +vt 0.885668 0.315488 +vt 0.89379 0.320385 +vt 0.912856 0.338167 +vt 0.907418 0.331814 +vt 0.922353 0.328655 +vt 0.914539 0.322618 +vt 0.91968 0.310994 +vt 0.895263 0.331765 +vt 0.899861 0.338745 +vt 0.903538 0.34573 +vt 0.882771 0.319356 +vt 0.889606 0.32508 +vt 0.726761 0.338632 +vt 0.720269 0.333665 +vt 0.728661 0.332789 +vt 0.724048 0.328479 +vt 0.728685 0.324646 +vt 0.725283 0.320091 +vt 0.718943 0.323554 +vt 0.708141 0.33392 +vt 0.716815 0.339387 +vt 0.703619 0.340611 +vt 0.713734 0.345346 +vt 0.724861 0.344474 +vt 0.705092 0.321759 +vt 0.698212 0.327693 +vt 0.695328 0.313899 +vt 0.68654 0.320218 +vt 0.692159 0.335172 +vt 0.721158 0.3143 +vt 0.712853 0.317398 +vt 0.705649 0.309794 +vt 0.849098 0.333114 +vt 0.852849 0.328742 +vt 0.854305 0.334344 +vt 0.858906 0.330607 +vt 0.863427 0.326736 +vt 0.848559 0.322731 +vt 0.846187 0.327308 +vt 0.839608 0.321509 +vt 0.838379 0.326237 +vt 0.84389 0.331884 +vt 0.862887 0.316059 +vt 0.859996 0.320044 +vt 0.853481 0.313684 +vt 0.851078 0.31815 +vt 0.841341 0.316617 +vt 0.867789 0.322599 +vt 0.871643 0.31863 +vt 0.808609 0.31864 +vt 0.807782 0.324278 +vt 0.797841 0.317858 +vt 0.797082 0.323766 +vt 0.818436 0.324849 +vt 0.821851 0.307693 +vt 0.820468 0.313742 +vt 0.810856 0.305827 +vt 0.809616 0.312441 +vt 0.79869 0.311344 +vt 0.829771 0.320444 +vt 0.831091 0.315141 +vt 0.832672 0.309663 +vt 0.828882 0.32546 +vt 0.827295 0.287378 +vt 0.81609 0.283741 +vt 0.829537 0.279056 +vt 0.81819 0.275174 +vt 0.802762 0.289081 +vt 0.80451 0.280694 +vt 0.814142 0.291631 +vt 0.836158 0.298133 +vt 0.838143 0.291297 +vt 0.84681 0.301473 +vt 0.848714 0.295264 +vt 0.84041 0.283327 +vt 0.823454 0.301435 +vt 0.834348 0.304125 +vt 0.84504 0.30685 +vt 0.801169 0.296892 +vt 0.812381 0.298942 +vt 0.876986 0.311536 +vt 0.878898 0.306488 +vt 0.870963 0.295312 +vt 0.88062 0.29932 +vt 0.869186 0.302754 +vt 0.865464 0.312169 +vt 0.874638 0.315263 +vt 0.855505 0.309448 +vt 0.857319 0.304788 +vt 0.859093 0.299048 +vt 0.861066 0.291675 +vt 0.732418 0.318062 +vt 0.734712 0.322982 +vt 0.743001 0.327869 +vt 0.736781 0.327408 +vt 0.741594 0.322579 +vt 0.738426 0.310793 +vt 0.729673 0.312154 +vt 0.736628 0.303749 +vt 0.726615 0.305165 +vt 0.757036 0.316401 +vt 0.748245 0.31651 +vt 0.75687 0.309754 +vt 0.747447 0.310045 +vt 0.746533 0.302937 +vt 0.748795 0.322531 +vt 0.749221 0.328331 +vt 0.756792 0.322664 +vt 0.731654 0.277237 +vt 0.718591 0.277987 +vt 0.730298 0.26671 +vt 0.717089 0.267402 +vt 0.704046 0.278768 +vt 0.706282 0.288897 +vt 0.720525 0.287868 +vt 0.756105 0.285792 +vt 0.744751 0.286232 +vt 0.755817 0.276484 +vt 0.743878 0.276719 +vt 0.743048 0.266393 +vt 0.734816 0.295809 +vt 0.745635 0.294985 +vt 0.756313 0.294527 +vt 0.710968 0.298566 +vt 0.723383 0.296998 +vt 0.792536 0.278545 +vt 0.791154 0.28731 +vt 0.780323 0.277204 +vt 0.793935 0.269245 +vt 0.781204 0.267531 +vt 0.78873 0.303265 +vt 0.777827 0.302657 +vt 0.789858 0.295534 +vt 0.778545 0.294752 +vt 0.767676 0.285819 +vt 0.767323 0.294432 +vt 0.767022 0.302415 +vt 0.768024 0.276581 +vt 0.768346 0.266629 +vt 0.776124 0.323009 +vt 0.786496 0.323337 +vt 0.787134 0.317284 +vt 0.766566 0.316536 +vt 0.766062 0.322804 +vt 0.777196 0.310038 +vt 0.766828 0.309761 +vt 0.78785 0.310554 +vt 0.887192 0.245173 +vt 0.894254 0.251226 +vt 0.882204 0.253513 +vt 0.889316 0.257984 +vt 0.899158 0.259059 +vt 0.906216 0.25556 +vt 0.900579 0.245749 +vt 0.873068 0.226854 +vt 0.883747 0.231913 +vt 0.868263 0.235954 +vt 0.878436 0.240212 +vt 0.873612 0.249405 +vt 0.899039 0.231269 +vt 0.889175 0.22393 +vt 0.904851 0.223823 +vt 0.894483 0.215603 +vt 0.878092 0.21784 +vt 0.907771 0.240362 +vt 0.914548 0.251706 +vt 0.914646 0.233613 +vt 0.83088 0.224634 +vt 0.816277 0.220886 +vt 0.83396 0.214024 +vt 0.818586 0.209908 +vt 0.827947 0.235154 +vt 0.840898 0.238644 +vt 0.844486 0.228275 +vt 0.855747 0.197071 +vt 0.852027 0.207701 +vt 0.840323 0.192176 +vt 0.837098 0.203273 +vt 0.821041 0.19888 +vt 0.861296 0.22221 +vt 0.8657 0.212494 +vt 0.870075 0.20254 +vt 0.852868 0.242144 +vt 0.856947 0.232012 +vt 0.689623 0.215775 +vt 0.70332 0.207275 +vt 0.697939 0.222493 +vt 0.709017 0.215819 +vt 0.725203 0.22199 +vt 0.713143 0.224363 +vt 0.722188 0.211648 +vt 0.691318 0.186238 +vt 0.709695 0.179461 +vt 0.697458 0.197483 +vt 0.714155 0.190926 +vt 0.68169 0.206684 +vt 0.751207 0.197567 +vt 0.734425 0.198302 +vt 0.74968 0.185753 +vt 0.731649 0.18705 +vt 0.728678 0.175143 +vt 0.738996 0.220423 +vt 0.736932 0.209325 +vt 0.752641 0.20886 +vt 0.784858 0.21308 +vt 0.800826 0.216826 +vt 0.784162 0.2244 +vt 0.799325 0.227809 +vt 0.802394 0.205632 +vt 0.768345 0.19871 +vt 0.768707 0.210268 +vt 0.768953 0.22173 +vt 0.786206 0.189958 +vt 0.767985 0.186934 +vt 0.786915 0.177877 +vt 0.767639 0.174701 +vt 0.803984 0.194191 +vt 0.805673 0.182317 +vt 0.809955 0.252364 +vt 0.822756 0.255918 +vt 0.80815 0.262293 +vt 0.820407 0.265831 +vt 0.832047 0.269793 +vt 0.837735 0.249207 +vt 0.825254 0.245637 +vt 0.811949 0.242115 +vt 0.856542 0.267463 +vt 0.846044 0.263615 +vt 0.859897 0.256492 +vt 0.849272 0.252848 +vt 0.843066 0.273938 +vt 0.853522 0.278101 +vt 0.742291 0.255201 +vt 0.729185 0.255607 +vt 0.755289 0.255203 +vt 0.754976 0.243665 +vt 0.741468 0.243564 +vt 0.715531 0.256156 +vt 0.700801 0.256437 +vt 0.714427 0.244869 +vt 0.700028 0.24508 +vt 0.72694 0.232765 +vt 0.714289 0.234159 +vt 0.701971 0.234531 +vt 0.754532 0.231935 +vt 0.740439 0.231904 +vt 0.911041 0.2953 +vt 0.921301 0.296781 +vt 0.93161 0.297423 +vt 0.929903 0.281016 +vt 0.920542 0.281282 +vt 0.901221 0.293843 +vt 0.891715 0.291968 +vt 0.901867 0.281252 +vt 0.892897 0.280142 +vt 0.909625 0.267746 +vt 0.901437 0.269362 +vt 0.893739 0.269552 +vt 0.927824 0.264632 +vt 0.918548 0.265802 +vt 0.783513 0.23552 +vt 0.768967 0.233217 +vt 0.768829 0.24463 +vt 0.796609 0.249173 +vt 0.797938 0.238614 +vt 0.782032 0.257262 +vt 0.795284 0.259419 +vt 0.768618 0.255873 +vt 0.866329 0.271283 +vt 0.863474 0.282119 +vt 0.873054 0.28587 +vt 0.878455 0.263629 +vt 0.869642 0.26007 +vt 0.884271 0.277953 +vt 0.886283 0.267215 +vt 0.882397 0.289232 +vt 0.941581 0.296368 +vt 0.939264 0.280761 +vt 0.944658 0.31122 +vt 0.954503 0.308374 +vt 0.951091 0.294591 +vt 0.945764 0.266671 +vt 0.937066 0.26534 +vt 0.944666 0.253926 +vt 0.936188 0.251002 +vt 0.964594 0.279716 +vt 0.956479 0.280128 +vt 0.960523 0.267756 +vt 0.953407 0.267371 +vt 0.951694 0.255808 +vt 0.963661 0.306017 +vt 0.960023 0.293069 +vt 0.968665 0.291676 +vt 0.386764 0.173365 +vt 0.386251 0.159166 +vt 0.403134 0.175347 +vt 0.40173 0.162164 +vt 0.370756 0.187276 +vt 0.370795 0.173446 +vt 0.38669 0.187253 +vt 0.422389 0.190328 +vt 0.419955 0.177717 +vt 0.441316 0.192402 +vt 0.437002 0.180281 +vt 0.417209 0.165162 +vt 0.401826 0.214817 +vt 0.403793 0.201683 +vt 0.424104 0.215186 +vt 0.424198 0.203052 +vt 0.44563 0.204522 +vt 0.385442 0.200518 +vt 0.36925 0.200049 +vt 0.382596 0.213492 +vt 0.356262 0.189263 +vt 0.355175 0.177265 +vt 0.348714 0.166736 +vt 0.334762 0.173858 +vt 0.341079 0.182428 +vt 0.340863 0.211835 +vt 0.342946 0.202073 +vt 0.352708 0.211778 +vt 0.355322 0.200767 +vt 0.331414 0.194664 +vt 0.331412 0.203371 +vt 0.319782 0.196009 +vt 0.319946 0.204047 +vt 0.330031 0.212063 +vt 0.324674 0.179566 +vt 0.32968 0.18654 +vt 0.319256 0.188731 +vt 0.34302 0.232291 +vt 0.34877 0.222299 +vt 0.354926 0.235741 +vt 0.361782 0.224028 +vt 0.337711 0.221083 +vt 0.32682 0.236795 +vt 0.334971 0.241716 +vt 0.31849 0.242434 +vt 0.324587 0.249202 +vt 0.345001 0.247217 +vt 0.32414 0.227342 +vt 0.319507 0.233375 +vt 0.314915 0.225618 +vt 0.311922 0.231227 +vt 0.313143 0.237776 +vt 0.327627 0.220146 +vt 0.317481 0.219239 +vt 0.63785 0.953205 +vt 0.630881 0.947663 +vt 0.647016 0.946972 +vt 0.6392 0.9414 +vt 0.622289 0.952938 +vt 0.615431 0.946184 +vt 0.624837 0.941085 +vt 0.636439 0.963394 +vt 0.644947 0.958154 +vt 0.644288 0.966733 +vt 0.653209 0.961707 +vt 0.654465 0.952626 +vt 0.612697 0.965958 +vt 0.620878 0.963127 +vt 0.620821 0.970267 +vt 0.628164 0.967348 +vt 0.635184 0.970582 +vt 0.606875 0.951267 +vt 0.614197 0.957483 +vt 0.605619 0.960347 +vt 0.367121 0.917394 +vt 0.374142 0.923099 +vt 0.360165 0.922438 +vt 0.367724 0.92812 +vt 0.381201 0.91911 +vt 0.388569 0.925813 +vt 0.380653 0.929651 +vt 0.367048 0.90811 +vt 0.360477 0.912329 +vt 0.360243 0.904335 +vt 0.353385 0.908573 +vt 0.353375 0.916883 +vt 0.388646 0.907697 +vt 0.381128 0.909826 +vt 0.380927 0.902848 +vt 0.374115 0.905116 +vt 0.367999 0.901318 +vt 0.396044 0.921905 +vt 0.388216 0.915684 +vt 0.396055 0.913595 +vt 0.328818 0.915038 +vt 0.333156 0.924854 +vt 0.309844 0.916921 +vt 0.317341 0.929308 +vt 0.32345 0.950038 +vt 0.299401 0.934005 +vt 0.334074 0.942122 +vt 0.352513 0.92816 +vt 0.344718 0.920885 +vt 0.341477 0.913527 +vt 0.373801 0.947808 +vt 0.357974 0.943112 +vt 0.374058 0.938334 +vt 0.362633 0.93464 +vt 0.352852 0.95399 +vt 0.347499 0.966072 +vt 0.373169 0.960769 +vt 0.418321 0.915362 +vt 0.435775 0.918439 +vt 0.422947 0.925132 +vt 0.443681 0.930756 +vt 0.455589 0.922184 +vt 0.430406 0.905691 +vt 0.418226 0.905767 +vt 0.397194 0.906411 +vt 0.405585 0.913617 +vt 0.409188 0.921144 +vt 0.376316 0.893935 +vt 0.392361 0.898152 +vt 0.375205 0.897753 +vt 0.386735 0.900808 +vt 0.405223 0.889198 +vt 0.398631 0.894039 +vt 0.377906 0.887331 +vt 0.336894 0.897334 +vt 0.318775 0.906333 +vt 0.327696 0.895339 +vt 0.301524 0.906655 +vt 0.333962 0.906288 +vt 0.360174 0.89468 +vt 0.356966 0.889714 +vt 0.353868 0.884022 +vt 0.353137 0.901438 +vt 0.363602 0.898194 +vt 0.345023 0.906797 +vt 0.434342 0.941415 +vt 0.453466 0.949534 +vt 0.415406 0.950555 +vt 0.42616 0.960391 +vt 0.417515 0.933928 +vt 0.390161 0.946583 +vt 0.394517 0.958315 +vt 0.398853 0.971248 +vt 0.39657 0.933133 +vt 0.385766 0.937253 +vt 0.40528 0.927706 +vt 0.57922 0.909293 +vt 0.58971 0.919914 +vt 0.547117 0.922496 +vt 0.567321 0.931013 +vt 0.577999 0.948709 +vt 0.555818 0.943001 +vt 0.585011 0.938851 +vt 0.617202 0.922908 +vt 0.614188 0.910157 +vt 0.635979 0.920365 +vt 0.638841 0.906233 +vt 0.611323 0.89609 +vt 0.607883 0.938585 +vt 0.620514 0.933025 +vt 0.633926 0.930757 +vt 0.597671 0.945329 +vt 0.592645 0.95281 +vt 0.700973 0.938045 +vt 0.70873 0.951078 +vt 0.680671 0.943135 +vt 0.684796 0.953548 +vt 0.697126 0.916127 +vt 0.723976 0.932747 +vt 0.682579 0.924761 +vt 0.65736 0.940282 +vt 0.665771 0.947808 +vt 0.668833 0.955667 +vt 0.653673 0.924504 +vt 0.646476 0.933887 +vt 0.670275 0.899507 +vt 0.661753 0.912628 +vt 0.571389 0.966985 +vt 0.583228 0.967478 +vt 0.599576 0.982628 +vt 0.604894 0.978385 +vt 0.628092 0.978017 +vt 0.628226 0.984167 +vt 0.610106 0.974767 +vt 0.582286 0.958749 +vt 0.563995 0.95542 +vt 0.543202 0.951342 +vt 0.603906 0.967493 +vt 0.595571 0.96058 +vt 0.615108 0.972401 +vt 0.627917 0.974569 +vt 0.676098 0.972325 +vt 0.697647 0.962452 +vt 0.689295 0.973819 +vt 0.72006 0.961593 +vt 0.677946 0.963033 +vt 0.646577 0.976363 +vt 0.652459 0.980856 +vt 0.658529 0.986044 +vt 0.653384 0.96919 +vt 0.64107 0.973262 +vt 0.663671 0.963059 +vt 0.36984 0.23949 +vt 0.357948 0.252377 +vt 0.346028 0.26526 +vt 0.355607 0.271672 +vt 0.369662 0.258935 +vt 0.397205 0.227812 +vt 0.377725 0.226506 +vt 0.417354 0.23588 +vt 0.420828 0.226027 +vt 0.4431 0.22875 +vt 0.446522 0.222697 +vt 0.398497 0.266882 +vt 0.394993 0.256063 +vt 0.417376 0.253869 +vt 0.416668 0.245046 +vt 0.439677 0.234803 +vt 0.375987 0.26863 +vt 0.360587 0.280948 +vt 0.379618 0.279895 +vt 0.470993 0.595329 +vt 0.466212 0.581429 +vt 0.482679 0.589544 +vt 0.476881 0.579741 +vt 0.489311 0.600458 +vt 0.499356 0.579702 +vt 0.49224 0.574945 +vt 0.479771 0.564752 +vt 0.472749 0.572159 +vt 0.474256 0.558067 +vt 0.468458 0.56471 +vt 0.46434 0.573191 +vt 0.492648 0.557082 +vt 0.486003 0.554296 +vt 0.497062 0.544746 +vt 0.490231 0.543792 +vt 0.480758 0.549772 +vt 0.509401 0.558946 +vt 0.500678 0.558385 +vt 0.505852 0.543851 +vt 0.497996 0.536049 +vt 0.505621 0.535332 +vt 0.501948 0.53012 +vt 0.507915 0.530515 +vt 0.51368 0.534353 +vt 0.482316 0.532549 +vt 0.489579 0.530568 +vt 0.484501 0.537962 +vt 0.491239 0.536243 +vt 0.491373 0.524968 +vt 0.485801 0.52569 +vt 0.484285 0.519868 +vt 0.479547 0.521219 +vt 0.479193 0.527051 +vt 0.496798 0.525508 +vt 0.50215 0.526678 +vt 0.490005 0.520085 +vt 0.473801 0.535793 +vt 0.470659 0.528429 +vt 0.469034 0.521857 +vt 0.460157 0.521751 +vt 0.461514 0.530505 +vt 0.469248 0.549809 +vt 0.476929 0.543255 +vt 0.456268 0.544777 +vt 0.462181 0.555305 +vt 0.449568 0.548141 +vt 0.456741 0.560093 +vt 0.451562 0.524114 +vt 0.453071 0.533958 +vt 0.446261 0.536501 +vt 0.933404 0.221309 +vt 0.924739 0.213284 +vt 0.938258 0.211078 +vt 0.929637 0.202912 +vt 0.924585 0.183534 +vt 0.934625 0.192739 +vt 0.919804 0.19418 +vt 0.910176 0.214711 +vt 0.920022 0.224053 +vt 0.929173 0.232598 +vt 0.892208 0.188152 +vt 0.904301 0.196133 +vt 0.88756 0.198715 +vt 0.899431 0.206272 +vt 0.909372 0.185384 +vt 0.914544 0.174329 +vt 0.89751 0.177035 +vt 0.829357 0.162643 +vt 0.809729 0.156901 +vt 0.833272 0.14992 +vt 0.812406 0.143745 +vt 0.789947 0.13803 +vt 0.815325 0.130471 +vt 0.791208 0.124039 +vt 0.787797 0.165074 +vt 0.807536 0.169823 +vt 0.826253 0.175235 +vt 0.767318 0.161769 +vt 0.746459 0.160576 +vt 0.767097 0.147949 +vt 0.744921 0.146466 +vt 0.767051 0.133048 +vt 0.767091 0.117607 +vt 0.743596 0.130619 +vt 0.722473 0.147996 +vt 0.719464 0.132562 +vt 0.695065 0.137329 +vt 0.716504 0.116494 +vt 0.690034 0.121812 +vt 0.725582 0.162157 +vt 0.70494 0.166437 +vt 0.656395 0.167991 +vt 0.677929 0.158979 +vt 0.665245 0.182639 +vt 0.684786 0.173336 +vt 0.670811 0.143368 +vt 0.663563 0.127131 +vt 0.647183 0.151721 +vt 0.844502 0.359871 +vt 0.847714 0.360296 +vt 0.847408 0.363957 +vt 0.849348 0.364269 +vt 0.851648 0.36844 +vt 0.850981 0.368241 +vt 0.851475 0.364632 +vt 0.850753 0.356913 +vt 0.846081 0.356324 +vt 0.850205 0.353003 +vt 0.844447 0.352351 +vt 0.841595 0.355786 +vt 0.855799 0.357604 +vt 0.861641 0.358449 +vt 0.855262 0.361451 +vt 0.860512 0.36239 +vt 0.855963 0.353655 +vt 0.853976 0.365096 +vt 0.852315 0.368639 +vt 0.858224 0.366005 +vt 0.720036 0.362311 +vt 0.71959 0.357661 +vt 0.728015 0.361123 +vt 0.727779 0.35756 +vt 0.73391 0.360061 +vt 0.73344 0.362971 +vt 0.728708 0.364784 +vt 0.736235 0.351526 +vt 0.735307 0.354339 +vt 0.729598 0.350921 +vt 0.728459 0.354192 +vt 0.720575 0.353357 +vt 0.740522 0.356645 +vt 0.741697 0.354388 +vt 0.746207 0.356041 +vt 0.747858 0.354388 +vt 0.742872 0.352131 +vt 0.739347 0.358902 +vt 0.738172 0.361159 +vt 0.744555 0.357694 +vt 0.878699 0.181029 +vt 0.883387 0.169647 +vt 0.867761 0.162851 +vt 0.888238 0.158069 +vt 0.871973 0.151014 +vt 0.874335 0.192023 +vt 0.859716 0.186019 +vt 0.843668 0.180528 +vt 0.847301 0.168505 +vt 0.85139 0.156282 +vt 0.855707 0.143958 +vt 0.959959 0.243101 +vt 0.954077 0.238396 +vt 0.961713 0.236753 +vt 0.956323 0.230743 +vt 0.954067 0.216174 +vt 0.958767 0.22329 +vt 0.950811 0.224595 +vt 0.952226 0.24645 +vt 0.945638 0.243001 +vt 0.958206 0.249448 +vt 0.941091 0.227849 +vt 0.937833 0.238648 +vt 0.949366 0.209059 +vt 0.945053 0.218173 +vt 0.336934 0.71568 +vt 0.33038 0.741466 +vt 0.302716 0.711537 +vt 0.299424 0.738297 +vt 0.295776 0.762787 +vt 0.393479 0.752977 +vt 0.377463 0.773803 +vt 0.361811 0.746705 +vt 0.350155 0.769363 +vt 0.371566 0.72393 +vt 0.338262 0.791261 +vt 0.32625 0.812779 +vt 0.315076 0.788147 +vt 0.307068 0.810102 +vt 0.361448 0.794629 +vt 0.29189 0.78554 +vt 0.287886 0.807426 +vt 0.299023 0.2659 +vt 0.299047 0.279209 +vt 0.283956 0.266822 +vt 0.283986 0.280354 +vt 0.283688 0.295775 +vt 0.327087 0.27663 +vt 0.323816 0.291325 +vt 0.313749 0.277461 +vt 0.311916 0.292761 +vt 0.31433 0.263721 +vt 0.296663 0.325331 +vt 0.297456 0.310292 +vt 0.309865 0.321929 +vt 0.31066 0.307783 +vt 0.322425 0.305028 +vt 0.283294 0.311929 +vt 0.282898 0.327607 +vt 0.281812 0.241506 +vt 0.281311 0.235544 +vt 0.29388 0.241063 +vt 0.292617 0.235389 +vt 0.282538 0.248141 +vt 0.307969 0.245729 +vt 0.304463 0.240079 +vt 0.302421 0.235265 +vt 0.297743 0.255375 +vt 0.311831 0.253377 +vt 0.283363 0.256332 +vt 0.665914 0.351378 +vt 0.682493 0.354562 +vt 0.661557 0.365446 +vt 0.679123 0.366239 +vt 0.694271 0.365301 +vt 0.676262 0.378559 +vt 0.692167 0.374571 +vt 0.699871 0.348099 +vt 0.686879 0.344167 +vt 0.6718 0.339046 +vt 0.709168 0.357329 +vt 0.711074 0.351244 +vt 0.708348 0.363848 +vt 0.708071 0.370584 +vt 0.867597 0.363815 +vt 0.865591 0.367703 +vt 0.874845 0.369526 +vt 0.873284 0.373919 +vt 0.863133 0.371378 +vt 0.876827 0.360099 +vt 0.868698 0.3595 +vt 0.885694 0.365176 +vt 0.885881 0.359586 +vt 0.896427 0.363349 +vt 0.895778 0.357262 +vt 0.884753 0.370807 +vt 0.883435 0.376459 +vt 0.896131 0.370165 +vt 0.908527 0.359153 +vt 0.909799 0.366215 +vt 0.924545 0.360491 +vt 0.927731 0.367892 +vt 0.910658 0.373446 +vt 0.917439 0.345549 +vt 0.906434 0.352429 +vt 0.933647 0.34626 +vt 0.928384 0.337086 +vt 0.944982 0.340124 +vt 0.93903 0.329282 +vt 0.939163 0.354526 +vt 0.944804 0.362339 +vt 0.951802 0.349505 +vt 0.954599 0.336095 +vt 0.960613 0.346611 +vt 0.967306 0.344981 +vt 0.971931 0.35627 +vt 0.966904 0.356527 +vt 0.949139 0.32438 +vt 0.958528 0.321259 +vt 0.967014 0.318797 +vt 0.975048 0.316665 +vt 0.970264 0.331384 +vt 0.97736 0.329695 +vt 0.976958 0.356012 +vt 0.973591 0.343753 +vt 0.979672 0.342725 +vt 0.320524 0.146521 +vt 0.313373 0.154734 +vt 0.2954 0.141698 +vt 0.292003 0.150779 +vt 0.28884 0.159589 +vt 0.322801 0.167455 +vt 0.333528 0.159639 +vt 0.345648 0.151344 +vt 0.301572 0.170503 +vt 0.31486 0.174313 +vt 0.297761 0.178302 +vt 0.309891 0.180957 +vt 0.286147 0.16786 +vt 0.284108 0.176013 +vt 0.296019 0.186221 +vt 0.282908 0.18447 +vt 0.282346 0.192959 +vt 0.307895 0.195694 +vt 0.308085 0.188134 +vt 0.295125 0.202337 +vt 0.307775 0.203492 +vt 0.294766 0.209933 +vt 0.307347 0.211107 +vt 0.28222 0.201212 +vt 0.28215 0.209032 +vt 0.294211 0.217025 +vt 0.281754 0.216221 +vt 0.281328 0.222946 +vt 0.304681 0.22447 +vt 0.306231 0.218115 +vt 0.292675 0.229646 +vt 0.302952 0.230124 +vt 0.281165 0.229372 +vt 0.305534 0.681974 +vt 0.306111 0.650222 +vt 0.342004 0.687835 +vt 0.333707 0.612749 +vt 0.302684 0.616894 +vt 0.325885 0.580428 +vt 0.298274 0.585332 +vt 0.395357 0.618639 +vt 0.374414 0.634434 +vt 0.380969 0.58713 +vt 0.358816 0.601672 +vt 0.349578 0.570739 +vt 0.384513 0.681504 +vt 0.395957 0.664926 +vt 0.416814 0.706905 +vt 0.420474 0.694282 +vt 0.409745 0.650149 +vt 0.377758 0.701684 +vt 0.413154 0.719528 +vt 0.338053 0.278233 +vt 0.345863 0.28289 +vt 0.333606 0.290848 +vt 0.34226 0.309133 +vt 0.341074 0.298701 +vt 0.351677 0.302345 +vt 0.349731 0.291219 +vt 0.332267 0.302652 +vt 0.332584 0.313884 +vt 0.387723 0.422423 +vt 0.382162 0.422373 +vt 0.388869 0.417427 +vt 0.382859 0.417822 +vt 0.377549 0.413541 +vt 0.384244 0.41338 +vt 0.377169 0.417955 +vt 0.377116 0.426931 +vt 0.381664 0.426972 +vt 0.377432 0.431442 +vt 0.381856 0.431562 +vt 0.386531 0.427438 +vt 0.367249 0.422554 +vt 0.372123 0.422513 +vt 0.368692 0.426806 +vt 0.372857 0.426712 +vt 0.373317 0.430853 +vt 0.371782 0.41828 +vt 0.37118 0.414106 +vt 0.366505 0.41823 +vt 0.426004 0.390403 +vt 0.398456 0.389437 +vt 0.424679 0.386349 +vt 0.396424 0.386762 +vt 0.363793 0.388475 +vt 0.394705 0.384351 +vt 0.356716 0.386401 +vt 0.378598 0.396645 +vt 0.375308 0.393171 +vt 0.401577 0.396345 +vt 0.401115 0.392641 +vt 0.428621 0.394516 +vt 0.353918 0.396416 +vt 0.339672 0.402446 +vt 0.345629 0.394106 +vt 0.329812 0.40053 +vt 0.35953 0.398947 +vt 0.33321 0.391382 +vt 0.318726 0.38845 +vt 0.313563 0.397303 +vt 0.476084 0.423195 +vt 0.45045 0.417502 +vt 0.486588 0.412986 +vt 0.456271 0.406372 +vt 0.430198 0.413801 +vt 0.423791 0.426121 +vt 0.43912 0.429517 +vt 0.507665 0.429493 +vt 0.542219 0.436093 +vt 0.475452 0.439099 +vt 0.495356 0.444524 +vt 0.525393 0.419675 +vt 0.43331 0.443713 +vt 0.441295 0.448141 +vt 0.411039 0.45059 +vt 0.411532 0.454564 +vt 0.448493 0.452954 +vt 0.423753 0.440055 +vt 0.413961 0.436871 +vt 0.407352 0.447798 +vt 0.31374 0.40806 +vt 0.32634 0.410021 +vt 0.317907 0.421046 +vt 0.299322 0.405773 +vt 0.325214 0.421259 +vt 0.338474 0.421652 +vt 0.3353 0.411329 +vt 0.344846 0.421904 +vt 0.34232 0.412499 +vt 0.355509 0.44277 +vt 0.342793 0.432971 +vt 0.357815 0.441106 +vt 0.346865 0.432004 +vt 0.351296 0.431202 +vt 0.336492 0.43632 +vt 0.339458 0.434504 +vt 0.354149 0.44545 +vt 0.366963 0.45175 +vt 0.367513 0.449587 +vt 0.378353 0.456489 +vt 0.366715 0.454041 +vt 0.379286 0.45488 +vt 0.368666 0.447681 +vt 0.369978 0.445476 +vt 0.38013 0.451272 +vt 0.379885 0.448331 +vt 0.392918 0.451424 +vt 0.393862 0.45378 +vt 0.390643 0.448651 +vt 0.392502 0.456314 +vt 0.389991 0.458936 +vt 0.434919 0.382651 +vt 0.453791 0.389264 +vt 0.433807 0.382477 +vt 0.442133 0.387347 +vt 0.449541 0.392567 +vt 0.49183 0.400597 +vt 0.464657 0.391608 +vt 0.513113 0.405332 +vt 0.475128 0.394166 +vt 0.436031 0.382826 +vt 0.516095 0.409998 +vt 0.483347 0.40387 +vt 0.551098 0.416497 +vt 0.455111 0.398484 +vt 0.472738 0.503366 +vt 0.465757 0.493643 +vt 0.482409 0.502085 +vt 0.475421 0.491708 +vt 0.456009 0.49597 +vt 0.450804 0.485866 +vt 0.459618 0.483598 +vt 0.474669 0.513513 +vt 0.481402 0.512442 +vt 0.489397 0.512463 +vt 0.46027 0.514483 +vt 0.470459 0.516768 +vt 0.449301 0.508912 +vt 0.450715 0.51651 +vt 0.441643 0.516565 +vt 0.44392 0.523436 +vt 0.44199 0.488134 +vt 0.446094 0.499081 +vt 0.437618 0.505763 +vt 0.409641 0.53125 +vt 0.417486 0.517634 +vt 0.424725 0.549489 +vt 0.428372 0.534587 +vt 0.421164 0.563953 +vt 0.440531 0.58304 +vt 0.440131 0.567599 +vt 0.438076 0.530458 +vt 0.43219 0.518805 +vt 0.42533 0.504018 +vt 0.445266 0.55059 +vt 0.442015 0.535846 +vt 0.453943 0.564519 +vt 0.453765 0.571874 +vt 0.456182 0.585446 +vt 0.459898 0.602127 +vt 0.349013 0.491269 +vt 0.336754 0.508239 +vt 0.331154 0.496224 +vt 0.320148 0.507781 +vt 0.297949 0.508264 +vt 0.308444 0.503271 +vt 0.306838 0.517622 +vt 0.350155 0.524533 +vt 0.35745 0.505005 +vt 0.375656 0.518489 +vt 0.380193 0.499924 +vt 0.366871 0.486313 +vt 0.322305 0.553361 +vt 0.347111 0.545735 +vt 0.371118 0.537055 +vt 0.293484 0.538213 +vt 0.295904 0.558876 +vt 0.288923 0.524031 +vt 0.284152 0.512489 +vt 0.281519 0.354585 +vt 0.27883 0.367232 +vt 0.275331 0.37971 +vt 0.281861 0.37985 +vt 0.288051 0.367559 +vt 0.296239 0.339242 +vt 0.282591 0.341601 +vt 0.310112 0.344766 +vt 0.309416 0.334597 +vt 0.322149 0.338741 +vt 0.321809 0.329248 +vt 0.30337 0.359703 +vt 0.312751 0.351414 +vt 0.309216 0.364244 +vt 0.316363 0.356301 +vt 0.323307 0.345678 +vt 0.295502 0.369475 +vt 0.288392 0.37999 +vt 0.302069 0.372187 +vt 0.281101 0.499747 +vt 0.27934 0.48605 +vt 0.292638 0.497304 +vt 0.28723 0.458265 +vt 0.288173 0.471672 +vt 0.277967 0.456884 +vt 0.278439 0.471644 +vt 0.299751 0.483057 +vt 0.297907 0.471434 +vt 0.309526 0.481102 +vt 0.307642 0.471064 +vt 0.296494 0.459645 +vt 0.302454 0.49435 +vt 0.311411 0.491141 +vt 0.343632 0.320416 +vt 0.333105 0.324778 +vt 0.333814 0.334838 +vt 0.363585 0.310039 +vt 0.366431 0.327171 +vt 0.353718 0.315393 +vt 0.355806 0.329495 +vt 0.346397 0.343469 +vt 0.357889 0.343783 +vt 0.347817 0.354895 +vt 0.35997 0.358164 +vt 0.369277 0.344302 +vt 0.334695 0.343565 +vt 0.335664 0.351626 +vt 0.379291 0.400052 +vt 0.363918 0.402333 +vt 0.367243 0.406178 +vt 0.353116 0.407088 +vt 0.35919 0.410239 +vt 0.41091 0.404675 +vt 0.399926 0.408536 +vt 0.397021 0.400516 +vt 0.390935 0.404866 +vt 0.37815 0.408898 +vt 0.386805 0.409108 +vt 0.393279 0.411364 +vt 0.363338 0.412821 +vt 0.369666 0.410088 +vt 0.350438 0.422105 +vt 0.355707 0.430165 +vt 0.363148 0.437257 +vt 0.365676 0.434559 +vt 0.360087 0.428972 +vt 0.349098 0.414046 +vt 0.35544 0.415713 +vt 0.361911 0.422489 +vt 0.36115 0.417241 +vt 0.368224 0.432108 +vt 0.364426 0.427706 +vt 0.379285 0.445126 +vt 0.388009 0.44487 +vt 0.385408 0.440532 +vt 0.396797 0.441249 +vt 0.391983 0.437144 +vt 0.371003 0.442416 +vt 0.371902 0.438797 +vt 0.377944 0.436209 +vt 0.372836 0.434912 +vt 0.388047 0.433887 +vt 0.38323 0.436089 +vt 0.411804 0.424136 +vt 0.414761 0.413476 +vt 0.40336 0.414868 +vt 0.405273 0.433865 +vt 0.397822 0.431174 +vt 0.394183 0.422617 +vt 0.391746 0.428935 +vt 0.395216 0.416313 +vt 0.775924 0.375151 +vt 0.775728 0.388743 +vt 0.746453 0.386032 +vt 0.747928 0.395308 +vt 0.717395 0.406114 +vt 0.713072 0.403611 +vt 0.744823 0.376573 +vt 0.749092 0.40422 +vt 0.749645 0.415483 +vt 0.72449 0.414957 +vt 0.72621 0.424666 +vt 0.7756 0.399248 +vt 0.70368 0.428763 +vt 0.687208 0.443737 +vt 0.697322 0.42707 +vt 0.677635 0.445158 +vt 0.707038 0.434775 +vt 0.68965 0.428163 +vt 0.681322 0.43065 +vt 0.666675 0.448773 +vt 0.663815 0.460707 +vt 0.651924 0.464538 +vt 0.630412 0.480156 +vt 0.639991 0.468922 +vt 0.642366 0.477595 +vt 0.66825 0.472074 +vt 0.675624 0.457981 +vt 0.68415 0.468328 +vt 0.689031 0.45406 +vt 0.649396 0.488552 +vt 0.664408 0.486592 +vt 0.681197 0.484039 +vt 0.634969 0.490079 +vt 0.620833 0.49139 +vt 0.912385 0.481335 +vt 0.932278 0.480511 +vt 0.952544 0.479369 +vt 0.933883 0.461959 +vt 0.919103 0.464149 +vt 0.869741 0.465154 +vt 0.887953 0.466437 +vt 0.873151 0.480724 +vt 0.893241 0.481526 +vt 0.865824 0.437779 +vt 0.874945 0.43437 +vt 0.878921 0.451884 +vt 0.891561 0.450226 +vt 0.864248 0.450831 +vt 0.915223 0.44455 +vt 0.903554 0.447624 +vt 0.884353 0.430602 +vt 0.854087 0.418075 +vt 0.860227 0.412749 +vt 0.833101 0.395604 +vt 0.866565 0.407739 +vt 0.836568 0.388337 +vt 0.826949 0.411924 +vt 0.848341 0.424031 +vt 0.824944 0.4236 +vt 0.84502 0.432484 +vt 0.803376 0.3921 +vt 0.802127 0.402739 +vt 0.801153 0.415145 +vt 0.804904 0.380706 +vt 0.806571 0.368936 +vt 0.702688 0.462561 +vt 0.700952 0.48073 +vt 0.723247 0.47733 +vt 0.725766 0.438352 +vt 0.705712 0.446642 +vt 0.74847 0.451919 +vt 0.749286 0.431814 +vt 0.774044 0.450536 +vt 0.774704 0.42899 +vt 0.747651 0.474504 +vt 0.773403 0.473071 +vt 0.799984 0.45176 +vt 0.799741 0.47385 +vt 0.825727 0.475971 +vt 0.824826 0.438046 +vt 0.800446 0.431839 +vt 0.848903 0.461112 +vt 0.846154 0.445298 +vt 0.850422 0.478567 +vt 0.62364 0.273336 +vt 0.631303 0.268742 +vt 0.633284 0.279074 +vt 0.640023 0.273125 +vt 0.639784 0.263935 +vt 0.632769 0.258173 +vt 0.623739 0.264647 +vt 0.600029 0.280268 +vt 0.598688 0.270903 +vt 0.613376 0.277111 +vt 0.610984 0.269667 +vt 0.621969 0.284647 +vt 0.621719 0.253201 +vt 0.613611 0.261924 +vt 0.599928 0.261159 +vt 0.670072 0.278979 +vt 0.653616 0.276716 +vt 0.669832 0.267969 +vt 0.654614 0.268283 +vt 0.648422 0.284838 +vt 0.690213 0.290189 +vt 0.687377 0.279381 +vt 0.68627 0.268024 +vt 0.683842 0.304224 +vt 0.697203 0.300525 +vt 0.645124 0.311795 +vt 0.656458 0.301386 +vt 0.663002 0.320505 +vt 0.672639 0.311009 +vt 0.637949 0.292669 +vt 0.625515 0.302527 +vt 0.64648 0.25088 +vt 0.652498 0.259521 +vt 0.667905 0.256541 +vt 0.65209 0.231125 +vt 0.635774 0.242815 +vt 0.639961 0.22002 +vt 0.62248 0.233347 +vt 0.677556 0.227123 +vt 0.666981 0.218489 +vt 0.656893 0.207226 +vt 0.684642 0.243963 +vt 0.689474 0.232327 +vt 0.684466 0.25604 +vt 0.602642 0.176918 +vt 0.580529 0.190632 +vt 0.589953 0.161017 +vt 0.566382 0.1753 +vt 0.557833 0.204588 +vt 0.573039 0.21849 +vt 0.594645 0.205765 +vt 0.635672 0.179448 +vt 0.62466 0.163426 +vt 0.613523 0.146733 +vt 0.646437 0.19413 +vt 0.627782 0.207015 +vt 0.588272 0.232651 +vt 0.608699 0.2205 +vt 0.608211 0.373618 +vt 0.616832 0.356454 +vt 0.634284 0.378082 +vt 0.640225 0.361705 +vt 0.646724 0.346174 +vt 0.603899 0.333518 +vt 0.593087 0.35113 +vt 0.582299 0.32801 +vt 0.570201 0.34546 +vt 0.582138 0.369154 +vt 0.635039 0.324678 +vt 0.614437 0.31673 +vt 0.593411 0.310569 +vt 0.65434 0.332333 +vt 0.561644 0.296106 +vt 0.564966 0.285457 +vt 0.580542 0.294418 +vt 0.583116 0.283009 +vt 0.582766 0.272899 +vt 0.546607 0.278466 +vt 0.547908 0.287734 +vt 0.528899 0.281331 +vt 0.53186 0.290461 +vt 0.545646 0.297066 +vt 0.561955 0.266155 +vt 0.543727 0.269714 +vt 0.555322 0.257166 +vt 0.537387 0.262094 +vt 0.526554 0.27266 +vt 0.581699 0.262937 +vt 0.576957 0.252641 +vt 0.565582 0.241532 +vt 0.543702 0.248829 +vt 0.550357 0.230094 +vt 0.496387 0.262785 +vt 0.509284 0.25153 +vt 0.513745 0.264403 +vt 0.525705 0.256225 +vt 0.51058 0.233141 +vt 0.488727 0.247432 +vt 0.491672 0.225616 +vt 0.466102 0.243633 +vt 0.473932 0.261753 +vt 0.534066 0.218808 +vt 0.517242 0.2076 +vt 0.516335 0.345283 +vt 0.530115 0.332372 +vt 0.5362 0.354987 +vt 0.549386 0.339171 +vt 0.561842 0.32354 +vt 0.526052 0.315178 +vt 0.511862 0.325172 +vt 0.511906 0.308506 +vt 0.496234 0.31623 +vt 0.49647 0.33558 +vt 0.537837 0.306011 +vt 0.553916 0.307529 +vt 0.525234 0.302122 +vt 0.572839 0.308275 +vt 0.511827 0.28428 +vt 0.509974 0.274041 +vt 0.492244 0.274874 +vt 0.501435 0.298913 +vt 0.516739 0.294259 +vt 0.458569 0.293763 +vt 0.476889 0.290416 +vt 0.467587 0.30982 +vt 0.484835 0.304206 +vt 0.471621 0.276173 +vt 0.449551 0.277706 +vt 0.79029 0.672484 +vt 0.810842 0.6624 +vt 0.788538 0.66243 +vt 0.832155 0.647948 +vt 0.833088 0.669026 +vt 0.767347 0.664111 +vt 0.749725 0.673721 +vt 0.741816 0.650008 +vt 0.85403 0.66365 +vt 0.868881 0.657298 +vt 0.85539 0.645025 +vt 0.888074 0.648027 +vt 0.874212 0.676013 +vt 0.886607 0.695639 +vt 0.89598 0.672443 +vt 0.929571 0.681021 +vt 0.72496 0.675077 +vt 0.707382 0.674426 +vt 0.711754 0.695525 +vt 0.674442 0.675309 +vt 0.715494 0.652696 +vt 0.851241 0.674754 +vt 0.83861 0.688008 +vt 0.813905 0.681083 +vt 0.795054 0.69679 +vt 0.803314 0.729031 +vt 0.821237 0.705648 +vt 0.847489 0.712022 +vt 0.863108 0.691149 +vt 0.734908 0.685353 +vt 0.751974 0.699565 +vt 0.699285 0.735409 +vt 0.729177 0.71566 +vt 0.752628 0.735708 +vt 0.775609 0.715256 +vt 0.771295 0.685081 +vt 0.892477 0.736968 +vt 0.891992 0.760942 +vt 0.924257 0.752441 +vt 0.883161 0.790753 +vt 0.862406 0.753942 +vt 0.813012 0.768991 +vt 0.847704 0.781855 +vt 0.824711 0.812689 +vt 0.703179 0.776568 +vt 0.71878 0.801121 +vt 0.75314 0.781706 +vt 0.750148 0.828139 +vt 0.674567 0.808938 +vt 0.785894 0.799205 +vt 0.832437 0.740517 +vt 0.726143 0.758511 +vt 0.908808 0.716733 +vt 0.780855 0.754707 +vt 0.872961 0.724451 +vt 0.947275 0.716911 +vt 0.972864 0.691703 +vt 0.956423 0.743409 +vt 0.170337 0.155827 +vt 0.136076 0.187112 +vt 0.172299 0.21177 +vt 0.0899929 0.213591 +vt 0.10853 0.16596 +vt 0.195445 0.192426 +vt 0.220169 0.183556 +vt 0.218642 0.212212 +vt 0.204829 0.229447 +vt 0.228379 0.234767 +vt 0.205687 0.259413 +vt 0.137176 0.927417 +vt 0.140528 0.948093 +vt 0.168383 0.944741 +vt 0.141913 0.961891 +vt 0.11077 0.946594 +vt 0.878967 0.954757 +vt 0.879367 0.938048 +vt 0.853203 0.941375 +vt 0.880712 0.92523 +vt 0.906681 0.938262 +vt 0.989055 0.9382 +vt 0.912651 0.957127 +vt 0.886501 1.00065 +vt 0.775015 0.959635 +vt 0.84864 0.929044 +vt 0.877392 0.895069 +vt 0.91222 0.923978 +vt 0.849069 0.962192 +vt 0.254826 0.925518 +vt 0.170213 0.919654 +vt 0.126415 0.872706 +vt 0.0190149 0.939185 +vt 0.100899 0.922774 +vt 0.142077 0.988088 +vt 0.17534 0.957124 +vt 0.106027 0.960245 +vt 0.148988 0.242126 +vt 0.176354 0.291487 +vt 0.102893 0.237993 +vt 0.044388 0.5061 +vt 0.0504472 0.534124 +vt 0.0221481 0.572717 +vt 0.0611958 0.546374 +vt 0.0719578 0.52396 +vt 0.0576334 0.571748 +vt 0.0664284 0.60486 +vt 0.0810156 0.564522 +vt 0.0825732 0.542567 +vt 0.101769 0.534189 +vt 0.944378 0.797731 +vt 0.915109 0.794589 +vt 0.905965 0.833567 +vt 0.842874 0.862029 +vt 0.791851 0.848437 +vt 0.748723 0.889561 +vt 0.703598 0.850293 +vt 0.642603 0.8718 +vt 0.843173 0.630902 +vt 0.84458 0.638283 +vt 0.846408 0.629484 +vt 0.71498 0.637314 +vt 0.726461 0.64589 +vt 0.734897 0.643187 +vt 0.865004 0.824698 +vt 0.962666 0.771065 +vt 0.94749 0.766441 +vt 0.268705 0.710477 +vt 0.214528 0.765549 +vt 0.268705 0.80475 +vt 0.191977 0.815455 +vt 0.127915 0.732152 +vt 0.268814 0.267129 +vt 0.238957 0.294344 +vt 0.268669 0.328244 +vt 0.215045 0.317962 +vt 0.269051 0.235581 +vt 0.241893 0.247542 +vt 0.652939 0.625528 +vt 0.689461 0.648127 +vt 0.870091 0.634597 +vt 0.889967 0.621532 +vt 0.917129 0.645104 +vt 0.960269 0.639284 +vt 0.9614 0.662237 +vt 0.981019 0.639244 +vt 0.270276 0.136874 +vt 0.232631 0.163206 +vt 0.269409 0.175133 +vt 0.242681 0.194855 +vt 0.269141 0.208639 +vt 0.244466 0.223601 +vt 0.189521 0.653078 +vt 0.113276 0.681659 +vt 0.170828 0.555621 +vt 0.268705 0.586687 +vt 0.197069 0.290309 +vt 0.147015 0.418787 +vt 0.159401 0.426978 +vt 0.169209 0.419346 +vt 0.166865 0.4343 +vt 0.151569 0.435731 +vt 0.101359 0.388325 +vt 0.164076 0.395797 +vt 0.253799 0.393043 +vt 0.188648 0.408382 +vt 0.10719 0.406598 +vt 0.0810976 0.440196 +vt 0.135792 0.449792 +vt 0.137248 0.466241 +vt -0.0522421 0.436952 +vt 0.203585 0.425014 +vt 0.183198 0.455456 +vt 0.176955 0.4435 +vt 0.158284 0.457002 +vt 0.0646922 0.403325 +vt 0.0969534 0.389119 +vt 0.127418 0.569795 +vt 0.101838 0.557019 +vt 0.115165 0.496827 +vt 0.0856225 0.479205 +vt 0.0876161 0.508163 +vt 0.224113 0.501179 +vt 0.216094 0.528531 +vt 0.268704 0.514179 +vt 0.152679 0.481359 +vt 0.268801 0.37957 +vt 0.241478 0.353126 +vt 0.242729 0.379892 +vt 0.214493 0.347926 +vt 0.247642 0.484503 +vt 0.231652 0.461026 +vt 0.268704 0.455503 +vt 0.192219 0.333104 +vt 0.164806 0.367802 +vt 0.156354 0.409665 +vt 0.179537 0.42641 +vt 0.158914 0.444672 +vt 0.1348 0.428233 +vt 0.776574 0.644712 +vt 0.722394 0.585817 +vt 0.651799 0.541213 +vt 0.694305 0.554226 +vt 0.775203 0.583316 +vt 0.656336 0.526524 +vt 0.611254 0.502624 +vt 0.680604 0.50058 +vt 0.971205 0.496778 +vt 0.903217 0.52798 +vt 0.896582 0.566601 +vt 0.859045 0.553539 +vt 0.874064 0.496896 +vt 0.829393 0.590056 +vt 0.725299 0.540094 +vt 0.773136 0.497495 +vt 0.8247 0.537119 +vt 0.64197 0.737033 +vt 0.61964 0.737363 +vt 0.604328 0.759732 +vt 0.608299 0.714718 +vt 0.667128 0.712276 +vt 0.663413 0.762979 +vt 0.546984 0.81774 +vt 0.617742 0.813781 +vt 0.624356 0.66752 +vt 0.55686 0.648558 +vt 0.568421 0.733816 +vt 0.529143 0.743889 +vt 0.538817 0.714517 +vt 0.531598 0.768055 +vt 0.445833 0.7485 +vt 0.547123 0.691597 +vt 0.481156 0.686856 +vt 0.499408 0.724217 +vt 0.796428 0.328877 +vt 0.8169 0.338119 +vt 0.838683 0.330654 +vt 0.838689 0.3517 +vt 0.793926 0.338777 +vt 0.773732 0.337889 +vt 0.74951 0.352736 +vt 0.755441 0.328792 +vt 0.859512 0.335574 +vt 0.874845 0.341757 +vt 0.878929 0.322664 +vt 0.894264 0.350808 +vt 0.86172 0.354306 +vt 0.890121 0.302638 +vt 0.900633 0.325513 +vt 0.932192 0.315548 +vt 0.730562 0.326947 +vt 0.713106 0.328223 +vt 0.72296 0.350316 +vt 0.678736 0.328632 +vt 0.716325 0.307131 +vt 0.856285 0.324517 +vt 0.84324 0.311687 +vt 0.81933 0.31943 +vt 0.799782 0.304286 +vt 0.806322 0.271776 +vt 0.825244 0.294637 +vt 0.850879 0.287575 +vt 0.86722 0.30781 +vt 0.740091 0.316932 +vt 0.756566 0.302501 +vt 0.702583 0.267919 +vt 0.73303 0.286789 +vt 0.75555 0.26631 +vt 0.779434 0.286256 +vt 0.776741 0.316735 +vt 0.894098 0.262064 +vt 0.892695 0.238422 +vt 0.863735 0.245736 +vt 0.882937 0.208649 +vt 0.924796 0.246563 +vt 0.814013 0.231601 +vt 0.847948 0.218052 +vt 0.823544 0.187373 +vt 0.704382 0.227027 +vt 0.718515 0.201921 +vt 0.673705 0.195595 +vt 0.748091 0.173595 +vt 0.753811 0.220319 +vt 0.785435 0.201844 +vt 0.834654 0.259639 +vt 0.728096 0.244245 +vt 0.910872 0.281409 +vt 0.782742 0.246644 +vt 0.87545 0.274707 +vt 0.948004 0.28051 +vt 0.956452 0.255796 +vt 0.972736 0.303635 +vt 0.370772 0.156168 +vt 0.404072 0.188535 +vt 0.432688 0.16816 +vt 0.449944 0.216643 +vt 0.366322 0.212187 +vt 0.343097 0.19204 +vt 0.319164 0.211948 +vt 0.318073 0.183115 +vt 0.332918 0.229442 +vt 0.33175 0.259955 +vt 0.309225 0.234833 +vt 0.632664 0.937599 +vt 0.629313 0.958275 +vt 0.659071 0.956775 +vt 0.627927 0.972073 +vt 0.601457 0.954923 +vt 0.374133 0.932158 +vt 0.374091 0.913509 +vt 0.349193 0.91288 +vt 0.374675 0.900396 +vt 0.400674 0.918841 +vt 0.275352 0.917971 +vt 0.344112 0.934726 +vt 0.371547 0.982105 +vt 0.480772 0.938676 +vt 0.406833 0.906276 +vt 0.38004 0.872706 +vt 0.345731 0.899719 +vt 0.405214 0.941284 +vt 0.515015 0.935699 +vt 0.599629 0.929832 +vt 0.643425 0.882887 +vt 0.750826 0.949367 +vt 0.668941 0.932959 +vt 0.627764 0.99827 +vt 0.594501 0.967304 +vt 0.663814 0.97043 +vt 0.389421 0.243699 +vt 0.436255 0.240856 +vt 0.360739 0.292908 +vt 0.479266 0.621214 +vt 0.485524 0.569542 +vt 0.463254 0.566666 +vt 0.48531 0.54359 +vt 0.519446 0.53819 +vt 0.495549 0.530351 +vt 0.47602 0.523291 +vt 0.496385 0.522841 +vt 0.465093 0.54022 +vt 0.446797 0.527765 +vt 0.944666 0.201943 +vt 0.914837 0.204675 +vt 0.904503 0.165124 +vt 0.839442 0.136903 +vt 0.788702 0.151899 +vt 0.742974 0.111175 +vt 0.700099 0.152559 +vt 0.637093 0.13245 +vt 0.850315 0.368043 +vt 0.851223 0.360798 +vt 0.852982 0.368837 +vt 0.723976 0.366596 +vt 0.734474 0.357174 +vt 0.742904 0.359347 +vt 0.863449 0.174562 +vt 0.963467 0.230405 +vt 0.947856 0.233441 +vt 0.322881 0.76555 +vt 0.409494 0.732152 +vt 0.345432 0.815455 +vt 0.298143 0.294421 +vt 0.321942 0.31772 +vt 0.295585 0.24761 +vt 0.660357 0.382546 +vt 0.69659 0.356392 +vt 0.876132 0.364721 +vt 0.893585 0.379 +vt 0.921054 0.3528 +vt 0.961877 0.356785 +vt 0.962698 0.33339 +vt 0.981984 0.355755 +vt 0.306768 0.162912 +vt 0.295194 0.194359 +vt 0.29317 0.223456 +vt 0.347888 0.653078 +vt 0.366581 0.55562 +vt 0.424133 0.681659 +vt 0.340033 0.290817 +vt 0.388965 0.413938 +vt 0.377097 0.422446 +vt 0.385455 0.431061 +vt 0.370091 0.429971 +vt 0.366833 0.415002 +vt 0.432694 0.382302 +vt 0.370508 0.391231 +vt 0.427991 0.40079 +vt 0.346746 0.40443 +vt 0.280737 0.3905 +vt 0.456111 0.433947 +vt 0.589083 0.427663 +vt 0.401629 0.461384 +vt 0.402075 0.444828 +vt 0.332854 0.421481 +vt 0.360577 0.439441 +vt 0.355077 0.451593 +vt 0.380059 0.45258 +vt 0.470234 0.396534 +vt 0.437143 0.383 +vt 0.468433 0.48133 +vt 0.462264 0.506664 +vt 0.433175 0.490402 +vt 0.401796 0.544866 +vt 0.440576 0.55139 +vt 0.313296 0.501179 +vt 0.321314 0.528529 +vt 0.38473 0.481358 +vt 0.295899 0.353213 +vt 0.32351 0.348357 +vt 0.294922 0.38013 +vt 0.289767 0.484501 +vt 0.305757 0.461026 +vt 0.344952 0.331857 +vt 0.372123 0.361433 +vt 0.379071 0.404986 +vt 0.356951 0.422334 +vt 0.378668 0.44021 +vt 0.40174 0.423148 +vt 0.776574 0.349534 +vt 0.721657 0.410555 +vt 0.77532 0.411729 +vt 0.694232 0.4441 +vt 0.649571 0.457689 +vt 0.655529 0.474973 +vt 0.903209 0.465704 +vt 0.85855 0.440351 +vt 0.896562 0.42714 +vt 0.829462 0.404087 +vt 0.725094 0.457517 +vt 0.824792 0.456782 +vt 0.644474 0.268488 +vt 0.619495 0.269287 +vt 0.604207 0.292645 +vt 0.603235 0.247789 +vt 0.669742 0.291872 +vt 0.665491 0.242026 +vt 0.542812 0.189584 +vt 0.615129 0.192251 +vt 0.625589 0.340224 +vt 0.556065 0.36469 +vt 0.56464 0.275636 +vt 0.534275 0.296732 +vt 0.525704 0.266294 +vt 0.528338 0.24086 +vt 0.440532 0.261649 +vt 0.542934 0.319725 +vt 0.476605 0.325877 +vt 0.495044 0.287182 +f 739/1 735/2 736/3 +f 189/4 736/3 735/2 +f 192/5 738/6 737/7 +f 739/1 737/7 738/6 +f 190/8 741/9 740/10 +f 743/11 740/10 741/9 +f 736/3 189/4 743/11 +f 742/12 743/11 189/4 +f 745/13 747/14 191/15 +f 744/16 191/15 747/14 +f 746/17 747/14 190/8 +f 741/9 190/8 747/14 +f 748/18 192/5 750/19 +f 737/7 750/19 192/5 +f 191/15 749/20 745/13 +f 750/19 745/13 749/20 +f 752/21 754/22 194/23 +f 751/24 194/23 754/22 +f 753/25 189/4 754/22 +f 735/2 754/22 189/4 +f 195/26 756/27 755/28 +f 758/29 755/28 756/27 +f 194/23 757/30 752/21 +f 758/29 752/21 757/30 +f 759/31 196/32 762/33 +f 760/34 762/33 196/32 +f 761/35 762/33 195/26 +f 756/27 195/26 762/33 +f 764/36 742/12 753/25 +f 189/4 753/25 742/12 +f 196/32 763/37 760/34 +f 764/36 760/34 763/37 +f 769/38 765/39 766/40 +f 198/41 766/40 765/39 +f 768/42 769/38 201/43 +f 767/44 201/43 769/38 +f 771/45 773/46 199/47 +f 770/48 199/47 773/46 +f 772/49 773/46 198/41 +f 766/40 198/41 773/46 +f 200/50 775/51 774/52 +f 777/53 774/52 775/51 +f 199/47 776/54 771/45 +f 777/53 771/45 776/54 +f 201/43 767/44 778/55 +f 780/56 778/55 767/44 +f 779/57 780/56 200/50 +f 775/51 200/50 780/56 +f 782/58 785/59 203/60 +f 781/61 203/60 785/59 +f 784/62 785/59 205/63 +f 783/64 205/63 785/59 +f 200/50 786/65 779/57 +f 788/66 779/57 786/65 +f 203/60 787/67 782/58 +f 788/66 782/58 787/67 +f 790/68 791/69 204/70 +f 789/71 204/70 791/69 +f 774/52 791/69 200/50 +f 786/65 200/50 791/69 +f 205/63 783/64 792/72 +f 794/73 792/72 783/64 +f 204/70 793/74 790/68 +f 794/73 790/68 793/74 +f 796/75 799/76 207/77 +f 795/78 207/77 799/76 +f 210/79 798/80 797/81 +f 799/76 797/81 798/80 +f 208/82 801/83 800/84 +f 803/85 800/84 801/83 +f 207/77 802/86 796/75 +f 803/85 796/75 802/86 +f 209/87 805/88 804/89 +f 807/90 804/89 805/88 +f 806/91 807/90 208/82 +f 801/83 208/82 807/90 +f 797/81 810/92 210/79 +f 808/93 210/79 810/92 +f 809/94 810/92 209/87 +f 805/88 209/87 810/92 +f 201/43 811/95 768/42 +f 814/96 768/42 811/95 +f 214/97 813/98 812/99 +f 814/96 812/99 813/98 +f 816/100 817/101 212/102 +f 815/103 212/102 817/101 +f 778/55 817/101 201/43 +f 811/95 201/43 817/101 +f 213/104 819/105 818/106 +f 821/107 818/106 819/105 +f 212/102 820/108 816/100 +f 821/107 816/100 820/108 +f 812/99 824/109 214/97 +f 822/110 214/97 824/109 +f 823/111 824/109 213/104 +f 819/105 213/104 824/109 +f 825/112 828/113 192/5 +f 738/6 192/5 828/113 +f 827/114 828/113 217/115 +f 826/116 217/115 828/113 +f 213/104 829/117 823/111 +f 830/118 823/111 829/117 +f 830/118 825/112 748/18 +f 192/5 748/18 825/112 +f 832/119 833/120 216/121 +f 831/122 216/121 833/120 +f 818/106 833/120 213/104 +f 829/117 213/104 833/120 +f 217/115 826/116 834/123 +f 836/124 834/123 826/116 +f 216/121 835/125 832/119 +f 836/124 832/119 835/125 +f 219/126 838/127 837/128 +f 841/129 837/128 838/127 +f 839/130 221/131 841/129 +f 840/132 841/129 221/131 +f 842/133 844/134 216/121 +f 835/125 216/121 844/134 +f 843/135 844/134 219/126 +f 838/127 219/126 844/134 +f 847/136 845/137 846/138 +f 220/139 846/138 845/137 +f 216/121 831/122 842/133 +f 847/136 842/133 831/122 +f 850/140 848/141 839/130 +f 221/131 839/130 848/141 +f 846/138 220/139 850/140 +f 849/142 850/140 220/139 +f 223/143 852/144 851/145 +f 854/146 851/145 852/144 +f 203/60 781/61 853/147 +f 854/146 853/147 781/61 +f 220/139 855/148 849/142 +f 857/149 849/142 855/148 +f 852/144 223/143 857/149 +f 856/150 857/149 223/143 +f 820/108 212/102 859/151 +f 858/152 859/151 212/102 +f 845/137 859/151 220/139 +f 855/148 220/139 859/151 +f 787/67 203/60 860/153 +f 853/147 860/153 203/60 +f 212/102 815/103 858/152 +f 860/153 858/152 815/103 +f 225/154 862/155 861/156 +f 864/157 861/156 862/155 +f 207/77 795/78 863/158 +f 864/157 863/158 795/78 +f 866/159 868/160 226/161 +f 865/162 226/161 868/160 +f 867/163 868/160 225/154 +f 862/155 225/154 868/160 +f 227/164 870/165 869/166 +f 872/167 869/166 870/165 +f 226/161 871/168 866/159 +f 872/167 866/159 871/168 +f 863/158 874/169 207/77 +f 802/86 207/77 874/169 +f 873/170 874/169 227/164 +f 870/165 227/164 874/169 +f 876/171 879/172 229/173 +f 875/174 229/173 879/172 +f 877/175 231/176 879/172 +f 878/177 879/172 231/176 +f 227/164 880/178 873/170 +f 882/179 873/170 880/178 +f 229/173 881/180 876/171 +f 882/179 876/171 881/180 +f 884/181 885/182 230/183 +f 883/184 230/183 885/182 +f 869/166 885/182 227/164 +f 880/178 227/164 885/182 +f 888/185 886/186 877/175 +f 231/176 877/175 886/186 +f 230/183 887/187 884/181 +f 888/185 884/181 887/187 +f 892/188 889/189 890/190 +f 233/191 890/190 889/189 +f 892/188 891/192 837/128 +f 219/126 837/128 891/192 +f 893/193 895/194 230/183 +f 887/187 230/183 895/194 +f 894/195 895/194 233/191 +f 890/190 233/191 895/194 +f 234/196 897/197 896/198 +f 898/199 896/198 897/197 +f 230/183 883/184 893/193 +f 898/199 893/193 883/184 +f 900/200 843/135 891/192 +f 219/126 891/192 843/135 +f 899/201 900/200 234/196 +f 897/197 234/196 900/200 +f 217/115 901/202 827/114 +f 903/203 827/114 901/202 +f 194/23 751/24 902/204 +f 903/203 902/204 751/24 +f 234/196 904/205 899/201 +f 905/206 899/201 904/205 +f 834/123 905/206 217/115 +f 901/202 217/115 905/206 +f 906/207 907/208 226/161 +f 871/168 226/161 907/208 +f 896/198 907/208 234/196 +f 904/205 234/196 907/208 +f 908/209 757/30 902/204 +f 194/23 902/204 757/30 +f 226/161 865/162 906/207 +f 908/209 906/207 865/162 +f 910/210 913/211 237/212 +f 909/213 237/212 913/211 +f 912/214 913/211 240/215 +f 911/216 240/215 913/211 +f 238/217 915/218 914/219 +f 917/220 914/219 915/218 +f 917/220 910/210 916/221 +f 237/212 916/221 910/210 +f 918/222 239/223 921/224 +f 919/225 921/224 239/223 +f 920/226 921/224 238/217 +f 915/218 238/217 921/224 +f 240/215 911/216 922/227 +f 924/228 922/227 911/216 +f 239/223 923/229 919/225 +f 924/228 919/225 923/229 +f 926/230 929/231 242/232 +f 925/233 242/232 929/231 +f 929/231 927/234 928/235 +f 244/236 928/235 927/234 +f 239/223 930/237 923/229 +f 932/238 923/229 930/237 +f 242/232 931/239 926/230 +f 932/238 926/230 931/239 +f 934/240 935/241 243/242 +f 933/243 243/242 935/241 +f 918/222 935/241 239/223 +f 930/237 239/223 935/241 +f 938/244 936/245 927/234 +f 244/236 927/234 936/245 +f 243/242 937/246 934/240 +f 938/244 934/240 937/246 +f 246/247 940/248 939/249 +f 943/250 939/249 940/248 +f 249/251 942/252 941/253 +f 943/250 941/253 942/252 +f 945/254 947/255 247/256 +f 944/257 247/256 947/255 +f 946/258 947/255 246/247 +f 940/248 246/247 947/255 +f 951/259 948/260 949/261 +f 248/262 949/261 948/260 +f 247/256 950/263 945/254 +f 951/259 945/254 950/263 +f 952/264 249/251 954/265 +f 941/253 954/265 249/251 +f 953/266 954/265 248/262 +f 949/261 248/262 954/265 +f 955/267 958/268 244/236 +f 928/235 244/236 958/268 +f 957/269 958/268 252/270 +f 956/271 252/270 958/268 +f 251/272 960/273 959/274 +f 961/275 959/274 960/273 +f 244/236 936/245 955/267 +f 961/275 955/267 936/245 +f 962/276 964/277 247/256 +f 950/263 247/256 964/277 +f 963/278 964/277 251/272 +f 960/273 251/272 964/277 +f 252/270 956/271 965/279 +f 966/280 965/279 956/271 +f 247/256 944/257 962/276 +f 966/280 962/276 944/257 +f 221/131 967/281 840/132 +f 970/282 840/132 967/281 +f 255/283 969/284 968/285 +f 970/282 968/285 969/284 +f 972/286 973/287 254/288 +f 971/289 254/288 973/287 +f 848/141 973/287 221/131 +f 967/281 221/131 973/287 +f 976/290 931/239 974/291 +f 242/232 974/291 931/239 +f 254/288 975/292 972/286 +f 976/290 972/286 975/292 +f 968/285 978/293 255/283 +f 977/294 255/283 978/293 +f 974/291 242/232 978/293 +f 925/233 978/293 242/232 +f 980/295 982/296 257/297 +f 979/298 257/297 982/296 +f 886/186 982/296 231/176 +f 981/299 231/176 982/296 +f 985/300 946/258 983/301 +f 246/247 983/301 946/258 +f 257/297 984/302 980/295 +f 985/300 980/295 984/302 +f 258/303 987/304 986/305 +f 988/306 986/305 987/304 +f 246/247 939/249 983/301 +f 988/306 983/301 939/249 +f 231/176 981/299 878/177 +f 990/307 878/177 981/299 +f 990/307 987/304 989/308 +f 258/303 989/308 987/304 +f 991/309 260/310 994/311 +f 992/312 994/311 260/310 +f 792/72 994/311 205/63 +f 993/313 205/63 994/311 +f 916/221 237/212 997/314 +f 995/315 997/314 237/212 +f 260/310 996/316 992/312 +f 997/314 992/312 996/316 +f 999/317 1000/318 261/319 +f 998/320 261/319 1000/318 +f 237/212 909/213 995/315 +f 1000/318 995/315 909/213 +f 205/63 993/313 784/62 +f 1002/321 784/62 993/313 +f 1002/321 999/317 1001/322 +f 261/319 1001/322 999/317 +f 1003/323 1005/324 257/297 +f 984/302 257/297 1005/324 +f 965/279 1005/324 252/270 +f 1004/325 252/270 1005/324 +f 233/191 1006/326 894/195 +f 1007/327 894/195 1006/326 +f 257/297 979/298 1003/323 +f 1007/327 1003/323 979/298 +f 1008/328 1009/329 255/283 +f 969/284 255/283 1009/329 +f 889/189 1009/329 233/191 +f 1006/326 233/191 1009/329 +f 252/270 1004/325 957/269 +f 1010/330 957/269 1004/325 +f 255/283 977/294 1008/328 +f 1010/330 1008/328 977/294 +f 223/143 1011/331 856/150 +f 1013/332 856/150 1011/331 +f 254/288 971/289 1012/333 +f 1013/332 1012/333 971/289 +f 1014/334 1015/335 261/319 +f 1001/322 261/319 1015/335 +f 851/145 1015/335 223/143 +f 1011/331 223/143 1015/335 +f 240/215 1016/336 912/214 +f 1017/337 912/214 1016/336 +f 261/319 998/320 1014/334 +f 1017/337 1014/334 998/320 +f 1012/333 1018/338 254/288 +f 975/292 254/288 1018/338 +f 922/227 1018/338 240/215 +f 1016/336 240/215 1018/338 +f 1019/339 265/340 1022/341 +f 1020/342 1022/341 265/340 +f 1022/341 1021/343 991/309 +f 260/310 991/309 1021/343 +f 1023/344 266/345 1026/346 +f 1024/347 1026/346 266/345 +f 1025/348 1026/346 265/340 +f 1020/342 265/340 1026/346 +f 1030/349 1027/350 1028/351 +f 267/352 1028/351 1027/350 +f 266/345 1029/353 1024/347 +f 1030/349 1024/347 1029/353 +f 1021/343 1032/354 260/310 +f 996/316 260/310 1032/354 +f 1028/351 267/352 1032/354 +f 1031/355 1032/354 267/352 +f 269/356 1034/357 1033/358 +f 1036/359 1033/358 1034/357 +f 1036/359 1035/360 1023/361 +f 266/362 1023/361 1035/360 +f 1038/363 1040/364 270/365 +f 1037/366 270/365 1040/364 +f 1039/367 1040/364 269/356 +f 1034/357 269/356 1040/364 +f 1044/368 1041/369 1042/370 +f 271/371 1042/370 1041/369 +f 270/365 1043/372 1038/363 +f 1044/368 1038/363 1043/372 +f 1035/360 1046/373 266/362 +f 1029/374 266/362 1046/373 +f 1042/370 271/371 1046/373 +f 1045/375 1046/373 271/371 +f 1048/376 1050/377 273/378 +f 1047/379 273/378 1050/377 +f 1033/358 1050/377 269/356 +f 1049/380 269/356 1050/377 +f 274/381 1052/382 1051/383 +f 1054/384 1051/383 1052/382 +f 273/378 1053/385 1048/376 +f 1054/384 1048/376 1053/385 +f 1056/386 1058/387 275/388 +f 1055/389 275/388 1058/387 +f 1057/390 1058/387 274/381 +f 1052/382 274/381 1058/387 +f 269/356 1049/380 1039/367 +f 1060/391 1039/367 1049/380 +f 275/388 1059/392 1056/386 +f 1060/391 1056/386 1059/392 +f 1061/393 1064/394 275/388 +f 1059/392 275/388 1064/394 +f 1063/395 1064/394 279/396 +f 1062/397 279/396 1064/394 +f 277/398 1066/399 1065/400 +f 1067/401 1065/400 1066/399 +f 275/388 1055/389 1061/393 +f 1067/401 1061/393 1055/389 +f 278/402 1069/403 1068/404 +f 1071/405 1068/404 1069/403 +f 1070/406 1071/405 277/398 +f 1066/399 277/398 1071/405 +f 279/396 1062/397 1072/407 +f 1074/408 1072/407 1062/397 +f 1073/409 1074/408 278/402 +f 1069/403 278/402 1074/408 +f 1076/410 1079/411 281/412 +f 1075/413 281/412 1079/411 +f 1077/414 284/415 1079/411 +f 1078/416 1079/411 284/415 +f 1081/417 1083/418 282/419 +f 1080/420 282/419 1083/418 +f 281/412 1082/421 1076/410 +f 1083/418 1076/410 1082/421 +f 283/422 1085/423 1084/424 +f 1087/425 1084/424 1085/423 +f 282/419 1086/426 1081/417 +f 1087/425 1081/417 1086/426 +f 284/415 1077/414 1088/427 +f 1090/428 1088/427 1077/414 +f 1090/428 1085/423 1089/429 +f 283/422 1089/429 1085/423 +f 1092/430 1095/431 286/432 +f 1091/433 286/432 1095/431 +f 1095/431 1093/434 1094/435 +f 289/436 1094/435 1093/434 +f 1097/437 1099/438 287/439 +f 1096/440 287/439 1099/438 +f 286/432 1098/441 1092/430 +f 1099/438 1092/430 1098/441 +f 288/442 1101/443 1100/444 +f 1103/445 1100/444 1101/443 +f 287/439 1102/446 1097/437 +f 1103/445 1097/437 1102/446 +f 289/436 1093/434 1104/447 +f 1106/448 1104/447 1093/434 +f 1101/443 288/442 1106/448 +f 1105/449 1106/448 288/442 +f 225/450 1107/451 867/452 +f 1110/453 867/452 1107/451 +f 292/454 1109/455 1108/456 +f 1110/453 1108/456 1109/455 +f 1112/457 1113/458 291/459 +f 1111/460 291/459 1113/458 +f 861/461 1113/458 225/450 +f 1107/451 225/450 1113/458 +f 289/436 1114/462 1094/435 +f 1116/463 1094/435 1114/462 +f 291/459 1115/464 1112/457 +f 1116/463 1112/457 1115/464 +f 1108/456 1118/465 292/454 +f 1117/466 292/454 1118/465 +f 289/436 1104/447 1114/462 +f 1118/465 1114/462 1104/447 +f 1120/467 1123/468 294/469 +f 1119/470 294/469 1123/468 +f 1122/471 1123/468 296/472 +f 1121/473 296/472 1123/468 +f 1127/474 1124/475 1125/476 +f 295/477 1125/476 1124/475 +f 294/469 1126/478 1120/467 +f 1127/474 1120/467 1126/478 +f 1128/479 1130/480 287/439 +f 1102/446 287/439 1130/480 +f 295/477 1129/481 1125/476 +f 1130/480 1125/476 1129/481 +f 296/472 1121/473 1131/482 +f 1132/483 1131/482 1121/473 +f 287/439 1096/440 1128/479 +f 1132/483 1128/479 1096/440 +f 1133/484 1135/485 292/454 +f 1109/455 292/454 1135/485 +f 755/486 1135/485 195/487 +f 1134/488 195/487 1135/485 +f 288/442 1136/489 1105/449 +f 1137/490 1105/449 1136/489 +f 292/454 1117/466 1133/484 +f 1137/490 1133/484 1117/466 +f 295/477 1138/491 1129/481 +f 1139/492 1129/481 1138/491 +f 1136/489 288/442 1139/492 +f 1100/444 1139/492 288/442 +f 195/487 1134/488 761/493 +f 1140/494 761/493 1134/488 +f 295/477 1124/475 1138/491 +f 1140/494 1138/491 1124/475 +f 1143/495 1122/471 1141/496 +f 296/472 1141/496 1122/471 +f 1143/495 1142/497 808/498 +f 210/499 808/498 1142/497 +f 1144/500 1145/501 286/432 +f 1098/441 286/432 1145/501 +f 1141/496 296/472 1145/501 +f 1131/482 1145/501 296/472 +f 291/459 1146/502 1115/464 +f 1147/503 1115/464 1146/502 +f 286/432 1091/433 1144/500 +f 1147/503 1144/500 1091/433 +f 1142/497 1148/504 210/499 +f 798/505 210/499 1148/504 +f 1146/502 291/459 1148/504 +f 1111/460 1148/504 291/459 +f 300/506 1150/507 1149/508 +f 1152/509 1149/508 1150/507 +f 214/510 822/511 1151/512 +f 1152/509 1151/512 822/511 +f 1153/513 1155/514 281/412 +f 1082/421 281/412 1155/514 +f 1150/507 300/506 1155/514 +f 1154/515 1155/514 300/506 +f 301/516 1157/517 1156/518 +f 1158/519 1156/518 1157/517 +f 281/412 1075/413 1153/513 +f 1158/519 1153/513 1075/413 +f 1151/512 1160/520 214/510 +f 813/521 214/510 1160/520 +f 1157/517 301/516 1160/520 +f 1159/522 1160/520 301/516 +f 198/523 1161/524 772/525 +f 1164/526 772/525 1161/524 +f 1164/526 1162/527 1163/528 +f 303/529 1163/528 1162/527 +f 1165/530 1166/531 301/516 +f 1159/522 301/516 1166/531 +f 765/532 1166/531 198/523 +f 1161/524 198/523 1166/531 +f 284/415 1167/533 1078/416 +f 1168/534 1078/416 1167/533 +f 301/516 1156/518 1165/530 +f 1168/534 1165/530 1156/518 +f 1162/527 1170/535 303/529 +f 1169/536 303/529 1170/535 +f 1167/533 284/415 1170/535 +f 1088/427 1170/535 284/415 +f 305/537 1172/538 1171/539 +f 1174/540 1171/539 1172/538 +f 191/541 744/542 1173/543 +f 1174/540 1173/543 744/542 +f 1175/544 1177/545 282/419 +f 1086/426 282/419 1177/545 +f 1176/546 1177/545 305/537 +f 1172/538 305/537 1177/545 +f 300/506 1178/547 1154/515 +f 1179/548 1154/515 1178/547 +f 282/419 1080/420 1175/544 +f 1179/548 1175/544 1080/420 +f 1173/543 1180/549 191/541 +f 749/550 191/541 1180/549 +f 1149/508 1180/549 300/506 +f 1178/547 300/506 1180/549 +f 1181/551 1184/552 303/529 +f 1163/528 303/529 1184/552 +f 1183/553 1184/552 307/554 +f 1182/555 307/554 1184/552 +f 283/422 1185/556 1089/429 +f 1186/557 1089/429 1185/556 +f 303/529 1169/536 1181/551 +f 1186/557 1181/551 1169/536 +f 305/537 1187/558 1176/546 +f 1188/559 1176/546 1187/558 +f 283/422 1084/424 1185/556 +f 1188/559 1185/556 1084/424 +f 307/554 1182/555 1189/560 +f 1190/561 1189/560 1182/555 +f 1171/539 1190/561 305/537 +f 1187/558 305/537 1190/561 +f 1192/562 1194/563 309/564 +f 1191/565 309/564 1194/563 +f 1072/407 1194/563 279/396 +f 1193/566 279/396 1194/563 +f 1195/567 310/568 1198/569 +f 1196/570 1198/569 310/568 +f 1192/562 309/564 1198/569 +f 1197/571 1198/569 309/564 +f 1202/572 1199/573 1200/574 +f 311/575 1200/574 1199/573 +f 310/568 1201/576 1196/570 +f 1202/572 1196/570 1201/576 +f 1203/577 1205/578 270/365 +f 1043/372 270/365 1205/578 +f 1200/574 311/575 1205/578 +f 1204/579 1205/578 311/575 +f 279/396 1193/566 1063/395 +f 1206/580 1063/395 1193/566 +f 270/365 1037/366 1203/577 +f 1206/580 1203/577 1037/366 +f 1208/581 1211/582 313/583 +f 1207/584 313/583 1211/582 +f 1210/585 1211/582 316/586 +f 1209/587 316/586 1211/582 +f 314/588 1213/589 1212/590 +f 1215/591 1212/590 1213/589 +f 313/583 1214/592 1208/581 +f 1215/591 1208/581 1214/592 +f 315/593 1217/594 1216/595 +f 1219/596 1216/595 1217/594 +f 1219/596 1213/589 1218/597 +f 314/588 1218/597 1213/589 +f 1209/587 1222/598 316/586 +f 1220/599 316/586 1222/598 +f 1221/600 1222/598 315/593 +f 1217/594 315/593 1222/598 +f 1223/601 1225/602 310/603 +f 1201/604 310/603 1225/602 +f 1212/590 1225/602 314/588 +f 1224/605 314/588 1225/602 +f 318/606 1227/607 1226/608 +f 1228/609 1226/608 1227/607 +f 1228/609 1223/601 1195/610 +f 310/603 1195/610 1223/601 +f 1230/611 1232/612 319/613 +f 1229/614 319/613 1232/612 +f 1231/615 1232/612 318/606 +f 1227/607 318/606 1232/612 +f 314/588 1224/605 1218/597 +f 1234/616 1218/597 1224/605 +f 319/613 1233/617 1230/611 +f 1234/616 1230/611 1233/617 +f 1236/618 1238/619 321/620 +f 1235/621 321/620 1238/619 +f 1237/622 319/613 1238/619 +f 1229/614 1238/619 319/613 +f 322/623 1240/624 1239/625 +f 1242/626 1239/625 1240/624 +f 321/620 1241/627 1236/618 +f 1242/626 1236/618 1241/627 +f 315/593 1243/628 1221/600 +f 1245/629 1221/600 1243/628 +f 1240/624 322/623 1245/629 +f 1244/630 1245/629 322/623 +f 319/613 1237/622 1233/617 +f 1246/631 1233/617 1237/622 +f 1246/631 1243/628 1216/595 +f 315/593 1216/595 1243/628 +f 324/632 1248/633 1247/634 +f 1251/635 1247/634 1248/633 +f 326/636 1250/637 1249/638 +f 1251/635 1249/638 1250/637 +f 1253/639 1255/640 325/641 +f 1252/642 325/641 1255/640 +f 1254/643 1255/640 324/632 +f 1248/633 324/632 1255/640 +f 238/217 1256/644 920/226 +f 1258/645 920/226 1256/644 +f 325/641 1257/646 1253/639 +f 1258/645 1253/639 1257/646 +f 1249/638 1260/647 326/636 +f 1259/648 326/636 1260/647 +f 914/219 1260/647 238/217 +f 1256/644 238/217 1260/647 +f 1265/649 1261/650 1262/651 +f 328/652 1262/651 1261/650 +f 330/653 1264/654 1263/655 +f 1265/649 1263/655 1264/654 +f 1267/656 1269/657 329/658 +f 1266/659 329/658 1269/657 +f 1262/651 328/652 1269/657 +f 1268/660 1269/657 328/652 +f 251/272 1270/661 963/278 +f 1272/662 963/278 1270/661 +f 1272/662 1267/656 1271/663 +f 329/658 1271/663 1267/656 +f 1263/655 1274/664 330/653 +f 1273/665 330/653 1274/664 +f 959/274 1274/664 251/272 +f 1270/661 251/272 1274/664 +f 1278/666 1275/667 1276/668 +f 332/669 1276/668 1275/667 +f 329/658 1266/659 1277/670 +f 1278/666 1277/670 1266/659 +f 1280/671 1282/672 333/673 +f 1279/674 333/673 1282/672 +f 1276/668 332/669 1282/672 +f 1281/675 1282/672 332/669 +f 1285/676 953/266 1283/677 +f 248/262 1283/677 953/266 +f 333/673 1284/678 1280/671 +f 1285/676 1280/671 1284/678 +f 1271/663 329/658 1286/679 +f 1277/670 1286/679 329/658 +f 948/260 1286/679 248/262 +f 1283/677 248/262 1286/679 +f 335/680 1288/681 1287/682 +f 1291/683 1287/682 1288/681 +f 337/684 1290/685 1289/686 +f 1291/683 1289/686 1290/685 +f 1293/687 1295/688 336/689 +f 1292/690 336/689 1295/688 +f 1288/681 335/680 1295/688 +f 1294/691 1295/688 335/680 +f 1298/692 1183/693 1296/694 +f 307/695 1296/694 1183/693 +f 1298/692 1293/687 1297/696 +f 336/689 1297/696 1293/687 +f 1289/686 1300/697 337/684 +f 1299/698 337/684 1300/697 +f 1296/694 307/695 1300/697 +f 1189/699 1300/697 307/695 +f 1302/700 1305/701 339/702 +f 1301/703 339/702 1305/701 +f 1304/704 1305/701 341/705 +f 1303/706 341/705 1305/701 +f 340/707 1307/708 1306/709 +f 1309/710 1306/709 1307/708 +f 1309/710 1302/700 1308/711 +f 339/702 1308/711 1302/700 +f 1310/712 1312/713 294/714 +f 1126/715 294/714 1312/713 +f 1307/708 340/707 1312/713 +f 1311/716 1312/713 340/707 +f 341/705 1303/706 1313/717 +f 1314/718 1313/717 1303/706 +f 294/714 1119/719 1310/712 +f 1314/718 1310/712 1119/719 +f 1318/720 1315/721 1316/722 +f 343/723 1316/722 1315/721 +f 325/641 1252/642 1317/724 +f 1318/720 1317/724 1252/642 +f 1319/725 1321/726 330/653 +f 1264/654 330/653 1321/726 +f 1316/722 343/723 1321/726 +f 1320/727 1321/726 343/723 +f 243/242 1322/728 937/246 +f 1323/729 937/246 1322/728 +f 1323/729 1319/725 1273/665 +f 330/653 1273/665 1319/725 +f 1317/724 1324/730 325/641 +f 1257/646 325/641 1324/730 +f 933/243 1324/730 243/242 +f 1322/728 243/242 1324/730 +f 345/731 1326/732 1325/733 +f 1329/734 1325/733 1326/732 +f 346/735 1328/736 1327/737 +f 1329/734 1327/737 1328/736 +f 1330/738 1332/739 326/636 +f 1250/637 326/636 1332/739 +f 1331/740 1332/739 345/731 +f 1326/732 345/731 1332/739 +f 267/352 1333/741 1031/355 +f 1334/742 1031/355 1333/741 +f 326/636 1259/648 1330/738 +f 1334/742 1330/738 1259/648 +f 1335/743 346/735 1336/744 +f 1327/737 1336/744 346/735 +f 1027/350 1336/744 267/352 +f 1333/741 267/352 1336/744 +f 1341/745 1337/746 1338/747 +f 348/748 1338/747 1337/746 +f 349/749 1340/750 1339/751 +f 1341/745 1339/751 1340/750 +f 1342/752 1344/753 346/754 +f 1328/755 346/754 1344/753 +f 1338/747 348/748 1344/753 +f 1343/756 1344/753 348/748 +f 271/757 1345/758 1045/759 +f 1346/760 1045/759 1345/758 +f 1346/760 1342/752 1335/761 +f 346/754 1335/761 1342/752 +f 349/749 1339/751 1347/762 +f 1348/763 1347/762 1339/751 +f 1041/764 1348/763 271/757 +f 1345/758 271/757 1348/763 +f 1353/765 1349/766 1350/767 +f 351/768 1350/767 1349/766 +f 354/769 1352/770 1351/771 +f 1353/765 1351/771 1352/770 +f 1355/772 1357/773 352/774 +f 1354/775 352/774 1357/773 +f 1350/767 351/768 1357/773 +f 1356/776 1357/773 351/768 +f 353/777 1359/778 1358/779 +f 1361/780 1358/779 1359/778 +f 352/774 1360/781 1355/772 +f 1361/780 1355/772 1360/781 +f 1351/771 1364/782 354/769 +f 1362/783 354/769 1364/782 +f 1363/784 1364/782 353/777 +f 1359/778 353/777 1364/782 +f 1365/785 356/786 1369/787 +f 1366/788 1369/787 356/786 +f 1369/787 1367/789 1368/790 +f 357/791 1368/790 1367/789 +f 1370/792 1372/793 354/769 +f 1352/770 354/769 1372/793 +f 356/786 1371/794 1366/788 +f 1372/793 1366/788 1371/794 +f 1374/795 1073/409 1373/796 +f 278/402 1373/796 1073/409 +f 354/769 1362/783 1370/792 +f 1374/795 1370/792 1362/783 +f 1367/789 1376/797 357/791 +f 1375/798 357/791 1376/797 +f 278/402 1068/404 1373/796 +f 1376/797 1373/796 1068/404 +f 1381/799 1377/800 1378/801 +f 359/802 1378/801 1377/800 +f 360/803 1380/804 1379/805 +f 1381/799 1379/805 1380/804 +f 1384/806 1304/704 1382/807 +f 341/705 1382/807 1304/704 +f 1378/801 359/802 1384/806 +f 1383/808 1384/806 359/802 +f 209/87 1385/809 809/94 +f 1386/810 809/94 1385/809 +f 1382/807 341/705 1386/810 +f 1313/717 1386/810 341/705 +f 1379/805 1388/811 360/803 +f 1387/812 360/803 1388/811 +f 804/89 1388/811 209/87 +f 1385/809 209/87 1388/811 +f 1390/813 1392/814 362/815 +f 1389/816 362/815 1392/814 +f 1391/817 336/689 1392/814 +f 1292/690 1392/814 336/689 +f 363/818 1394/819 1393/820 +f 1396/821 1393/820 1394/819 +f 1396/821 1390/813 1395/822 +f 362/815 1395/822 1390/813 +f 1397/823 1399/824 199/47 +f 776/54 199/47 1399/824 +f 1398/825 1399/824 363/818 +f 1394/819 363/818 1399/824 +f 1400/826 1297/696 1391/817 +f 336/689 1391/817 1297/696 +f 199/47 770/48 1397/823 +f 1400/826 1397/823 770/48 +f 1402/827 1404/828 365/829 +f 1401/830 365/829 1404/828 +f 1403/831 363/818 1404/828 +f 1393/820 1404/828 363/818 +f 366/832 1406/833 1405/834 +f 1408/835 1405/834 1406/833 +f 1408/835 1402/827 1407/836 +f 365/829 1407/836 1402/827 +f 1409/837 1411/838 204/70 +f 793/74 204/70 1411/838 +f 1410/839 1411/838 366/832 +f 1406/833 366/832 1411/838 +f 363/818 1403/831 1398/825 +f 1412/840 1398/825 1403/831 +f 204/70 789/71 1409/837 +f 1412/840 1409/837 789/71 +f 1414/841 1416/842 368/843 +f 1413/844 368/843 1416/842 +f 1405/834 1416/842 366/832 +f 1415/845 366/832 1416/842 +f 1418/846 1420/847 369/848 +f 1417/849 369/848 1420/847 +f 1419/850 1420/847 368/843 +f 1414/841 368/843 1420/847 +f 265/340 1421/851 1025/348 +f 1423/852 1025/348 1421/851 +f 1423/852 1418/846 1422/853 +f 369/848 1422/853 1418/846 +f 366/832 1415/845 1410/839 +f 1424/854 1410/839 1415/845 +f 1424/854 1421/851 1019/339 +f 265/340 1019/339 1421/851 +f 371/855 1426/856 1425/857 +f 1428/858 1425/857 1426/856 +f 369/859 1417/860 1427/861 +f 1428/858 1427/861 1417/860 +f 372/862 1430/863 1429/864 +f 1432/865 1429/864 1430/863 +f 1431/866 1432/865 371/855 +f 1426/856 371/855 1432/865 +f 1433/867 1435/868 273/378 +f 1053/385 273/378 1435/868 +f 1434/869 1435/868 372/862 +f 1430/863 372/862 1435/868 +f 1427/861 1436/870 369/859 +f 1422/871 369/859 1436/870 +f 273/378 1047/379 1433/867 +f 1436/870 1433/867 1047/379 +f 1438/872 1440/873 374/874 +f 1437/875 374/874 1440/873 +f 1429/864 1440/873 372/862 +f 1439/876 372/862 1440/873 +f 375/877 1442/878 1441/879 +f 1444/880 1441/879 1442/878 +f 1444/880 1438/872 1443/881 +f 374/874 1443/881 1438/872 +f 1445/882 1447/883 274/381 +f 1057/390 274/381 1447/883 +f 1446/884 1447/883 375/877 +f 1442/878 375/877 1447/883 +f 372/862 1439/876 1434/869 +f 1448/885 1434/869 1439/876 +f 274/381 1051/383 1445/882 +f 1448/885 1445/882 1051/383 +f 1452/886 1449/887 1450/888 +f 377/889 1450/888 1449/887 +f 1451/890 375/877 1452/886 +f 1441/879 1452/886 375/877 +f 1453/891 1455/892 357/791 +f 1368/790 357/791 1455/892 +f 1450/888 377/889 1455/892 +f 1454/893 1455/892 377/889 +f 277/398 1456/894 1070/406 +f 1457/895 1070/406 1456/894 +f 357/791 1375/798 1453/891 +f 1457/895 1453/891 1375/798 +f 1446/884 375/877 1458/896 +f 1451/890 1458/896 375/877 +f 1065/400 1458/896 277/398 +f 1456/894 277/398 1458/896 +f 1462/897 1340/750 1459/898 +f 349/749 1459/898 1340/750 +f 1461/899 1462/897 380/900 +f 1460/901 380/900 1462/897 +f 1464/902 1204/903 1463/904 +f 311/905 1463/904 1204/903 +f 1459/898 349/749 1464/902 +f 1347/762 1464/902 349/749 +f 1465/906 1466/907 313/908 +f 1214/909 313/908 1466/907 +f 1199/910 1466/907 311/905 +f 1463/904 311/905 1466/907 +f 379/911 1468/912 1467/913 +f 1469/914 1467/913 1468/912 +f 313/908 1207/915 1465/906 +f 1469/914 1465/906 1207/915 +f 380/900 1460/901 1470/916 +f 1472/917 1470/916 1460/901 +f 1472/917 1468/912 1471/918 +f 379/911 1471/918 1468/912 +f 1363/784 353/777 1475/919 +f 1473/920 1475/919 353/777 +f 1191/565 1475/919 309/564 +f 1474/921 309/564 1475/919 +f 1477/922 1478/923 382/924 +f 1476/925 382/924 1478/923 +f 1358/779 1478/923 353/777 +f 1473/920 353/777 1478/923 +f 309/564 1474/921 1197/571 +f 1480/926 1197/571 1474/921 +f 382/924 1479/927 1477/922 +f 1480/926 1477/922 1479/927 +f 384/928 1482/929 1481/930 +f 1485/931 1481/930 1482/929 +f 387/932 1484/933 1483/934 +f 1485/931 1483/934 1484/933 +f 1487/935 1489/936 385/937 +f 1486/938 385/937 1489/936 +f 1488/939 1489/936 384/928 +f 1482/929 384/928 1489/936 +f 386/940 1491/941 1490/942 +f 1493/943 1490/942 1491/941 +f 385/937 1492/944 1487/935 +f 1493/943 1487/935 1492/944 +f 1483/934 1496/945 387/932 +f 1494/946 387/932 1496/945 +f 1491/941 386/940 1496/945 +f 1495/947 1496/945 386/940 +f 1501/948 1497/949 1498/950 +f 389/951 1498/950 1497/949 +f 392/952 1500/953 1499/954 +f 1501/948 1499/954 1500/953 +f 1503/955 1505/956 390/957 +f 1502/958 390/957 1505/956 +f 1498/950 389/951 1505/956 +f 1504/959 1505/956 389/951 +f 1507/960 1509/961 391/962 +f 1506/963 391/962 1509/961 +f 1509/961 1503/955 1508/964 +f 390/957 1508/964 1503/955 +f 1499/954 1512/965 392/952 +f 1510/966 392/952 1512/965 +f 391/962 1511/967 1507/960 +f 1512/965 1507/960 1511/967 +f 1513/968 394/969 1517/970 +f 1514/971 1517/970 394/969 +f 1516/972 1517/970 397/973 +f 1515/974 397/973 1517/970 +f 1521/975 1518/976 1519/977 +f 395/978 1519/977 1518/976 +f 1514/971 394/969 1521/975 +f 1520/979 1521/975 394/969 +f 1523/980 1525/981 396/982 +f 1522/983 396/982 1525/981 +f 1519/977 395/978 1525/981 +f 1524/984 1525/981 395/978 +f 397/973 1515/974 1526/985 +f 1528/986 1526/985 1515/974 +f 1528/986 1523/980 1527/987 +f 396/982 1527/987 1523/980 +f 399/988 1530/989 1529/990 +f 1532/991 1529/990 1530/989 +f 1502/958 1532/991 390/957 +f 1531/992 390/957 1532/991 +f 1534/993 1536/994 400/995 +f 1533/996 400/995 1536/994 +f 399/988 1535/997 1530/989 +f 1536/994 1530/989 1535/997 +f 1540/998 1537/999 1538/1000 +f 401/1001 1538/1000 1537/999 +f 400/995 1539/1002 1534/993 +f 1540/998 1534/993 1539/1002 +f 1531/992 1542/1003 390/957 +f 1508/964 390/957 1542/1003 +f 1538/1000 401/1001 1542/1003 +f 1541/1004 1542/1003 401/1001 +f 403/1005 1544/1006 1543/1007 +f 1546/1008 1543/1007 1544/1006 +f 1546/1008 1545/1009 1533/996 +f 400/995 1533/996 1545/1009 +f 395/978 1547/1010 1524/984 +f 1549/1011 1524/984 1547/1010 +f 1549/1011 1544/1006 1548/1012 +f 403/1005 1548/1012 1544/1006 +f 1551/1013 1552/1014 404/1015 +f 1550/1016 404/1015 1552/1014 +f 1518/976 1552/1014 395/978 +f 1547/1010 395/978 1552/1014 +f 1545/1009 1554/1017 400/995 +f 1539/1002 400/995 1554/1017 +f 1554/1017 1551/1013 1553/1018 +f 404/1015 1553/1018 1551/1013 +f 1555/1019 1558/1020 392/952 +f 1500/953 392/952 1558/1020 +f 407/1021 1557/1022 1556/1023 +f 1558/1020 1556/1023 1557/1022 +f 397/973 1559/1024 1516/972 +f 1560/1025 1516/972 1559/1024 +f 392/952 1510/966 1555/1019 +f 1560/1025 1555/1019 1510/966 +f 406/1026 1562/1027 1561/1028 +f 1563/1029 1561/1028 1562/1027 +f 1526/985 1563/1029 397/973 +f 1559/1024 397/973 1563/1029 +f 1556/1023 1566/1030 407/1021 +f 1564/1031 407/1021 1566/1030 +f 1565/1032 1566/1030 406/1026 +f 1562/1027 406/1026 1566/1030 +f 1567/1033 1570/1034 407/1035 +f 1557/1036 407/1035 1570/1034 +f 1568/1037 410/1038 1570/1034 +f 1569/1039 1570/1034 410/1038 +f 409/1040 1572/1041 1571/1042 +f 1573/1043 1571/1042 1572/1041 +f 407/1035 1564/1044 1567/1033 +f 1573/1043 1567/1033 1564/1044 +f 1574/1045 1576/1046 321/620 +f 1241/627 321/620 1576/1046 +f 1575/1047 1576/1046 409/1040 +f 1572/1041 409/1040 1576/1046 +f 318/606 1577/1048 1231/615 +f 1578/1049 1231/615 1577/1048 +f 321/620 1235/621 1574/1045 +f 1578/1049 1574/1045 1235/621 +f 1568/1037 1580/1050 410/1038 +f 1579/1051 410/1038 1580/1050 +f 1226/608 1580/1050 318/606 +f 1577/1048 318/606 1580/1050 +f 1581/1052 412/1053 1584/1054 +f 1582/1055 1584/1054 412/1053 +f 1561/1056 1584/1054 406/1057 +f 1583/1058 406/1057 1584/1054 +f 1587/1059 1210/585 1585/1060 +f 316/586 1585/1060 1210/585 +f 1587/1059 1582/1055 1586/1061 +f 412/1053 1586/1061 1582/1055 +f 322/623 1588/1062 1244/630 +f 1589/1063 1244/630 1588/1062 +f 1589/1063 1585/1060 1220/599 +f 316/586 1220/599 1585/1060 +f 1591/1064 1575/1047 1590/1065 +f 409/1040 1590/1065 1575/1047 +f 322/623 1239/625 1588/1062 +f 1591/1064 1588/1062 1239/625 +f 406/1057 1583/1058 1565/1066 +f 1592/1067 1565/1066 1583/1058 +f 409/1040 1571/1042 1590/1065 +f 1592/1067 1590/1065 1571/1042 +f 414/1068 1594/1069 1593/1070 +f 1596/1071 1593/1070 1594/1069 +f 396/1072 1522/1073 1595/1074 +f 1596/1071 1595/1074 1522/1073 +f 415/1075 1598/1076 1597/1077 +f 1600/1078 1597/1077 1598/1076 +f 1600/1078 1594/1069 1599/1079 +f 414/1068 1599/1079 1594/1069 +f 1601/1080 1603/1081 379/911 +f 1471/918 379/911 1603/1081 +f 1602/1082 1603/1081 415/1075 +f 1598/1076 415/1075 1603/1081 +f 1605/1083 1586/1084 1604/1085 +f 412/1086 1604/1085 1586/1084 +f 379/911 1467/913 1601/1080 +f 1605/1083 1601/1080 1467/913 +f 1527/1087 396/1072 1606/1088 +f 1595/1074 1606/1088 396/1072 +f 1604/1085 412/1086 1606/1088 +f 1581/1089 1606/1088 412/1086 +f 1608/1090 1611/1091 417/1092 +f 1607/1093 417/1092 1611/1091 +f 1609/1094 419/1095 1611/1091 +f 1610/1096 1611/1091 419/1095 +f 1612/1097 1614/1098 399/1099 +f 1535/1100 399/1099 1614/1098 +f 1614/1098 1608/1090 1613/1101 +f 417/1092 1613/1101 1608/1090 +f 418/1102 1616/1103 1615/1104 +f 1617/1105 1615/1104 1616/1103 +f 1612/1097 399/1099 1617/1105 +f 1529/1106 1617/1105 399/1099 +f 1618/1107 1620/1108 352/774 +f 1360/781 352/774 1620/1108 +f 1619/1109 1620/1108 418/1102 +f 1616/1103 418/1102 1620/1108 +f 419/1095 1609/1094 1621/1110 +f 1622/1111 1621/1110 1609/1094 +f 352/774 1354/775 1618/1107 +f 1622/1111 1618/1107 1354/775 +f 414/1068 1623/1112 1599/1079 +f 1626/1113 1599/1079 1623/1112 +f 1625/1114 1626/1113 421/1115 +f 1624/1116 421/1115 1626/1113 +f 1548/1117 403/1118 1628/1119 +f 1627/1120 1628/1119 403/1118 +f 1593/1070 1628/1119 414/1068 +f 1623/1112 414/1068 1628/1119 +f 1629/1121 1630/1122 417/1123 +f 1613/1124 417/1123 1630/1122 +f 1627/1120 403/1118 1630/1122 +f 1543/1125 1630/1122 403/1118 +f 1632/1126 1631/1127 1624/1116 +f 421/1115 1624/1116 1631/1127 +f 417/1123 1607/1128 1629/1121 +f 1632/1126 1629/1121 1607/1128 +f 418/1102 1633/1129 1619/1109 +f 1635/1130 1619/1109 1633/1129 +f 382/924 1476/925 1634/1131 +f 1635/1130 1634/1131 1476/925 +f 389/1132 1636/1133 1504/1134 +f 1637/1135 1504/1134 1636/1133 +f 1615/1104 1637/1135 418/1102 +f 1633/1129 418/1102 1637/1135 +f 1638/1136 1639/1137 410/1138 +f 1569/1139 410/1138 1639/1137 +f 1497/1140 1639/1137 389/1132 +f 1636/1133 389/1132 1639/1137 +f 1634/1131 1640/1141 382/924 +f 1479/927 382/924 1640/1141 +f 1579/1142 1640/1141 410/1138 +f 1638/1136 410/1138 1640/1141 +f 1644/1143 1641/1144 1642/1145 +f 424/1146 1642/1145 1641/1144 +f 391/962 1506/963 1643/1147 +f 1644/1143 1643/1147 1506/963 +f 384/928 1645/1148 1488/939 +f 1647/1149 1488/939 1645/1148 +f 424/1146 1646/1150 1642/1145 +f 1647/1149 1642/1145 1646/1150 +f 425/1151 1649/1152 1648/1153 +f 1650/1154 1648/1153 1649/1152 +f 384/928 1481/930 1645/1148 +f 1650/1154 1645/1148 1481/930 +f 1643/1147 1652/1155 391/962 +f 1511/967 391/962 1652/1155 +f 1651/1156 1652/1155 425/1151 +f 1649/1152 425/1151 1652/1155 +f 1653/1157 427/1158 1656/1159 +f 1654/1160 1656/1159 427/1158 +f 1537/999 1656/1159 401/1001 +f 1655/1161 401/1001 1656/1159 +f 385/937 1657/1162 1492/944 +f 1659/1163 1492/944 1657/1162 +f 427/1158 1658/1164 1654/1160 +f 1659/1163 1654/1160 1658/1164 +f 424/1146 1660/1165 1646/1150 +f 1661/1166 1646/1150 1660/1165 +f 385/937 1486/938 1657/1162 +f 1661/1166 1657/1162 1486/938 +f 401/1001 1655/1161 1541/1004 +f 1662/1167 1541/1004 1655/1161 +f 1641/1144 1662/1167 424/1146 +f 1660/1165 424/1146 1662/1167 +f 1666/1168 1663/1169 1664/1170 +f 429/1171 1664/1170 1663/1169 +f 404/1015 1550/1016 1665/1172 +f 1666/1168 1665/1172 1550/1016 +f 386/940 1667/1173 1495/947 +f 1669/1174 1495/947 1667/1173 +f 429/1171 1668/1175 1664/1170 +f 1669/1174 1664/1170 1668/1175 +f 1670/1176 1671/1177 427/1158 +f 1658/1164 427/1158 1671/1177 +f 1667/1173 386/940 1671/1177 +f 1490/942 1671/1177 386/940 +f 1553/1018 404/1015 1672/1178 +f 1665/1172 1672/1178 404/1015 +f 1672/1178 1670/1176 1653/1157 +f 427/1158 1653/1157 1670/1176 +f 1651/1156 425/1151 1675/1179 +f 1673/1180 1675/1179 425/1151 +f 1513/968 1675/1179 394/969 +f 1674/1181 394/969 1675/1179 +f 387/932 1676/1182 1484/933 +f 1677/1183 1484/933 1676/1182 +f 425/1151 1648/1153 1673/1180 +f 1677/1183 1673/1180 1648/1153 +f 429/1171 1678/1184 1668/1175 +f 1679/1185 1668/1175 1678/1184 +f 387/932 1494/946 1676/1182 +f 1679/1185 1676/1182 1494/946 +f 394/969 1674/1181 1520/979 +f 1680/1186 1520/979 1674/1181 +f 1680/1186 1678/1184 1663/1169 +f 429/1171 1663/1169 1678/1184 +f 1681/1187 1684/1188 196/1189 +f 763/1190 196/1189 1684/1188 +f 1683/1191 1684/1188 434/1192 +f 1682/1193 434/1192 1684/1188 +f 1686/1194 1687/1195 432/1196 +f 1685/1197 432/1196 1687/1195 +f 1687/1195 1681/1187 759/1198 +f 196/1189 759/1198 1681/1187 +f 1689/1199 1691/1200 433/1201 +f 1688/1202 433/1201 1691/1200 +f 1691/1200 1686/1194 1690/1203 +f 432/1196 1690/1203 1686/1194 +f 434/1192 1682/1193 1692/1204 +f 1694/1205 1692/1204 1682/1193 +f 1694/1205 1689/1199 1693/1206 +f 433/1201 1693/1206 1689/1199 +f 340/1207 1695/1208 1311/1209 +f 1697/1210 1311/1209 1695/1208 +f 432/1196 1685/1197 1696/1211 +f 1697/1210 1696/1211 1685/1197 +f 1699/1212 1700/1213 436/1214 +f 1698/1215 436/1214 1700/1213 +f 1306/1216 1700/1213 340/1207 +f 1695/1208 340/1207 1700/1213 +f 437/1217 1702/1218 1701/1219 +f 1704/1220 1701/1219 1702/1218 +f 436/1214 1703/1221 1699/1212 +f 1704/1220 1699/1212 1703/1221 +f 1690/1203 432/1196 1706/1222 +f 1696/1211 1706/1222 432/1196 +f 1705/1223 1706/1222 437/1217 +f 1702/1218 437/1217 1706/1222 +f 1707/1224 1710/1225 337/1226 +f 1290/1227 337/1226 1710/1225 +f 1709/1228 1710/1225 441/1229 +f 1708/1230 441/1229 1710/1225 +f 439/1231 1712/1232 1711/1233 +f 1713/1234 1711/1233 1712/1232 +f 337/1226 1299/1235 1707/1224 +f 1713/1234 1707/1224 1299/1235 +f 1715/1236 1717/1237 440/1238 +f 1714/1239 440/1238 1717/1237 +f 1716/1240 1717/1237 439/1231 +f 1712/1232 439/1231 1717/1237 +f 441/1229 1708/1230 1718/1241 +f 1720/1242 1718/1241 1708/1230 +f 440/1238 1719/1243 1715/1236 +f 1720/1242 1715/1236 1719/1243 +f 1723/1244 746/1245 1721/1246 +f 190/1247 1721/1246 746/1245 +f 1722/1248 439/1231 1723/1244 +f 1711/1233 1723/1244 439/1231 +f 1725/1249 1683/1191 1724/1250 +f 434/1192 1724/1250 1683/1191 +f 1721/1246 190/1247 1725/1249 +f 740/1251 1725/1249 190/1247 +f 1728/1252 1726/1253 1727/1254 +f 443/1255 1727/1254 1726/1253 +f 434/1192 1692/1204 1724/1250 +f 1728/1252 1724/1250 1692/1204 +f 1730/1256 1716/1240 1722/1248 +f 439/1231 1722/1248 1716/1240 +f 1727/1254 443/1255 1730/1256 +f 1729/1257 1730/1256 443/1255 +f 445/1258 1732/1259 1731/1260 +f 1734/1261 1731/1260 1732/1259 +f 1701/1219 1734/1261 437/1217 +f 1733/1262 437/1217 1734/1261 +f 446/1263 1736/1264 1735/1265 +f 1738/1266 1735/1265 1736/1264 +f 1737/1267 1738/1266 445/1258 +f 1732/1259 445/1258 1738/1266 +f 1739/1268 1741/1269 433/1201 +f 1693/1206 433/1201 1741/1269 +f 1740/1270 1741/1269 446/1263 +f 1736/1264 446/1263 1741/1269 +f 437/1217 1733/1262 1705/1223 +f 1742/1271 1705/1223 1733/1262 +f 433/1201 1688/1202 1739/1268 +f 1742/1271 1739/1268 1688/1202 +f 1746/1272 1743/1273 1744/1274 +f 448/1275 1744/1274 1743/1273 +f 446/1263 1735/1265 1745/1276 +f 1746/1272 1745/1276 1735/1265 +f 1747/1277 1749/1278 440/1238 +f 1719/1243 440/1238 1749/1278 +f 1744/1274 448/1275 1749/1278 +f 1748/1279 1749/1278 448/1275 +f 443/1255 1750/1280 1729/1257 +f 1751/1281 1729/1257 1750/1280 +f 440/1238 1714/1239 1747/1277 +f 1751/1281 1747/1277 1714/1239 +f 1745/1276 1752/1282 446/1263 +f 1740/1270 446/1263 1752/1282 +f 1726/1253 1752/1282 443/1255 +f 1750/1280 443/1255 1752/1282 +f 1754/1283 1757/1284 450/1285 +f 1753/1286 450/1285 1757/1284 +f 1756/1287 1757/1284 452/1288 +f 1755/1289 452/1288 1757/1284 +f 451/1290 1759/1291 1758/1292 +f 1761/1293 1758/1292 1759/1291 +f 450/1285 1760/1294 1754/1283 +f 1761/1293 1754/1283 1760/1294 +f 452/1288 1755/1289 1762/1295 +f 1764/1296 1762/1295 1755/1289 +f 1763/1297 1764/1296 451/1290 +f 1759/1291 451/1290 1764/1296 +f 452/1288 1765/1298 1756/1287 +f 1768/1299 1756/1287 1765/1298 +f 1766/1300 455/1301 1768/1299 +f 1767/1302 1768/1299 455/1301 +f 1770/1303 1771/1304 454/1305 +f 1769/1306 454/1305 1771/1304 +f 1762/1295 1771/1304 452/1288 +f 1765/1298 452/1288 1771/1304 +f 208/82 1772/1307 806/91 +f 1774/1308 806/91 1772/1307 +f 454/1305 1773/1309 1770/1303 +f 1774/1308 1770/1303 1773/1309 +f 1775/1310 1776/1311 229/173 +f 881/180 229/173 1776/1311 +f 800/84 1776/1311 208/82 +f 1772/1307 208/82 1776/1311 +f 1778/1312 1777/1313 1766/1300 +f 455/1301 1766/1300 1777/1313 +f 229/173 875/174 1775/1310 +f 1778/1312 1775/1310 875/174 +f 455/1301 1779/1314 1767/1302 +f 1781/1315 1767/1302 1779/1314 +f 450/1285 1753/1286 1780/1316 +f 1781/1315 1780/1316 1753/1286 +f 1782/1317 1783/1318 258/303 +f 989/308 258/303 1783/1318 +f 1777/1313 1783/1318 455/1301 +f 1779/1314 455/1301 1783/1318 +f 1784/1319 1785/1320 249/251 +f 942/252 249/251 1785/1320 +f 258/303 986/305 1782/1317 +f 1785/1320 1782/1317 986/305 +f 1786/1321 457/1322 1788/1323 +f 1787/1324 1788/1323 457/1322 +f 1784/1319 249/251 1788/1323 +f 952/264 1788/1323 249/251 +f 1780/1316 1790/1325 450/1285 +f 1760/1294 450/1285 1790/1325 +f 1789/1326 1790/1325 457/1322 +f 1787/1324 457/1322 1790/1325 +f 1792/1327 1795/1328 459/1329 +f 1791/1330 459/1329 1795/1328 +f 1793/1331 460/1332 1795/1328 +f 1794/1333 1795/1328 460/1332 +f 457/1322 1796/1334 1789/1326 +f 1798/1335 1789/1326 1796/1334 +f 459/1329 1797/1336 1792/1327 +f 1798/1335 1792/1327 1797/1336 +f 1284/678 333/673 1800/1337 +f 1799/1338 1800/1337 333/673 +f 1786/1321 1800/1337 457/1322 +f 1796/1334 457/1322 1800/1337 +f 1802/1339 1801/1340 1793/1331 +f 460/1332 1793/1331 1801/1340 +f 333/673 1279/674 1799/1338 +f 1802/1339 1799/1338 1279/674 +f 360/803 1803/1341 1380/804 +f 1806/1342 1380/804 1803/1341 +f 463/1343 1805/1344 1804/1345 +f 1806/1342 1804/1345 1805/1344 +f 1807/1346 1808/1347 454/1305 +f 1773/1309 454/1305 1808/1347 +f 1387/812 1808/1347 360/803 +f 1803/1341 360/803 1808/1347 +f 462/1348 1810/1349 1809/1350 +f 1811/1351 1809/1350 1810/1349 +f 454/1305 1769/1306 1807/1346 +f 1811/1351 1807/1346 1769/1306 +f 1804/1345 1814/1352 463/1343 +f 1812/1353 463/1343 1814/1352 +f 1813/1354 1814/1352 462/1348 +f 1810/1349 462/1348 1814/1352 +f 451/1290 1815/1355 1763/1297 +f 1818/1356 1763/1297 1815/1355 +f 467/1357 1817/1358 1816/1359 +f 1818/1356 1816/1359 1817/1358 +f 1821/1360 1819/1361 1820/1362 +f 465/1363 1820/1362 1819/1361 +f 1758/1292 1821/1360 451/1290 +f 1815/1355 451/1290 1821/1360 +f 1823/1364 1825/1365 466/1366 +f 1822/1367 466/1366 1825/1365 +f 1820/1362 465/1363 1825/1365 +f 1824/1368 1825/1365 465/1363 +f 1826/1369 467/1357 1828/1370 +f 1816/1359 1828/1370 467/1357 +f 1823/1364 466/1366 1828/1370 +f 1827/1371 1828/1370 466/1366 +f 1829/1372 1831/1373 459/1329 +f 1797/1336 459/1329 1831/1373 +f 1819/1361 1831/1373 465/1363 +f 1830/1374 465/1363 1831/1373 +f 469/1375 1833/1376 1832/1377 +f 1834/1378 1832/1377 1833/1376 +f 459/1329 1791/1330 1829/1372 +f 1834/1378 1829/1372 1791/1330 +f 1836/1379 1838/1380 470/1381 +f 1835/1382 470/1381 1838/1380 +f 1837/1383 1838/1380 469/1375 +f 1833/1376 469/1375 1838/1380 +f 465/1363 1830/1374 1824/1368 +f 1840/1384 1824/1368 1830/1374 +f 470/1381 1839/1385 1836/1379 +f 1840/1384 1836/1379 1839/1385 +f 1844/1386 1813/1354 1841/1387 +f 462/1348 1841/1387 1813/1354 +f 473/1388 1843/1389 1842/1390 +f 1844/1386 1842/1390 1843/1389 +f 1845/1391 1846/1392 467/1357 +f 1817/1358 467/1357 1846/1392 +f 1841/1387 462/1348 1846/1392 +f 1809/1350 1846/1392 462/1348 +f 472/1393 1848/1394 1847/1395 +f 1849/1396 1847/1395 1848/1394 +f 1849/1396 1845/1391 1826/1369 +f 467/1357 1826/1369 1845/1391 +f 1842/1390 1852/1397 473/1388 +f 1850/1398 473/1388 1852/1397 +f 1851/1399 1852/1397 472/1393 +f 1848/1394 472/1393 1852/1397 +f 1853/1400 1855/1401 470/1381 +f 1839/1385 470/1381 1855/1401 +f 1854/1402 466/1366 1855/1401 +f 1822/1367 1855/1401 466/1366 +f 1858/1403 1856/1404 1857/1405 +f 475/1406 1857/1405 1856/1404 +f 470/1381 1835/1382 1853/1400 +f 1858/1403 1853/1400 1835/1382 +f 472/1393 1859/1407 1851/1399 +f 1861/1408 1851/1399 1859/1407 +f 475/1406 1860/1409 1857/1405 +f 1861/1408 1857/1405 1860/1409 +f 1854/1402 1862/1410 466/1366 +f 1827/1371 466/1366 1862/1410 +f 1859/1407 472/1393 1862/1410 +f 1847/1395 1862/1410 472/1393 +f 477/1411 1864/1412 1863/1413 +f 1867/1414 1863/1413 1864/1412 +f 1867/1414 1865/1415 1866/1416 +f 480/1417 1866/1416 1865/1415 +f 478/1418 1869/1419 1868/1420 +f 1871/1421 1868/1420 1869/1419 +f 1870/1422 1871/1421 477/1411 +f 1864/1412 477/1411 1871/1421 +f 1872/1423 479/1424 1875/1425 +f 1873/1426 1875/1425 479/1424 +f 1874/1427 1875/1425 478/1418 +f 1869/1419 478/1418 1875/1425 +f 1865/1415 1878/1428 480/1417 +f 1876/1429 480/1417 1878/1428 +f 479/1424 1877/1430 1873/1426 +f 1878/1428 1873/1426 1877/1430 +f 1879/1431 1882/1432 480/1417 +f 1866/1416 480/1417 1882/1432 +f 1880/1433 484/1434 1882/1432 +f 1881/1435 1882/1432 484/1434 +f 482/1436 1884/1437 1883/1438 +f 1885/1439 1883/1438 1884/1437 +f 1885/1439 1879/1431 1876/1429 +f 480/1417 1876/1429 1879/1431 +f 1887/1440 1889/1441 483/1442 +f 1886/1443 483/1442 1889/1441 +f 1888/1444 1889/1441 482/1436 +f 1884/1437 482/1436 1889/1441 +f 484/1434 1880/1433 1890/1445 +f 1892/1446 1890/1445 1880/1433 +f 483/1442 1891/1447 1887/1440 +f 1892/1446 1887/1440 1891/1447 +f 1894/1448 1897/1449 486/1450 +f 1893/1451 486/1450 1897/1449 +f 1897/1449 1895/1452 1896/1453 +f 489/1454 1896/1453 1895/1452 +f 1899/1455 1901/1456 487/1457 +f 1898/1458 487/1457 1901/1456 +f 486/1450 1900/1459 1894/1448 +f 1901/1456 1894/1448 1900/1459 +f 488/1460 1903/1461 1902/1462 +f 1905/1463 1902/1462 1903/1461 +f 487/1457 1904/1464 1899/1455 +f 1905/1463 1899/1455 1904/1464 +f 1895/1452 1908/1465 489/1454 +f 1906/1466 489/1454 1908/1465 +f 1907/1467 1908/1465 488/1460 +f 1903/1461 488/1460 1908/1465 +f 1910/1468 1913/1469 491/1470 +f 1909/1471 491/1470 1913/1469 +f 1912/1472 1913/1469 493/1473 +f 1911/1474 493/1473 1913/1469 +f 492/1475 1915/1476 1914/1477 +f 1917/1478 1914/1477 1915/1476 +f 491/1470 1916/1479 1910/1468 +f 1917/1478 1910/1468 1916/1479 +f 1918/1480 1920/1481 487/1457 +f 1904/1464 487/1457 1920/1481 +f 1919/1482 1920/1481 492/1475 +f 1915/1476 492/1475 1920/1481 +f 493/1473 1911/1474 1921/1483 +f 1922/1484 1921/1483 1911/1474 +f 487/1457 1898/1458 1918/1480 +f 1922/1484 1918/1480 1898/1458 +f 495/1485 1924/1486 1923/1487 +f 1927/1488 1923/1487 1924/1486 +f 1926/1489 1927/1488 498/1490 +f 1925/1491 498/1490 1927/1488 +f 1929/1492 1931/1493 496/1494 +f 1928/1495 496/1494 1931/1493 +f 1930/1496 1931/1493 495/1485 +f 1924/1486 495/1485 1931/1493 +f 1933/1497 1935/1498 497/1499 +f 1932/1500 497/1499 1935/1498 +f 496/1494 1934/1501 1929/1492 +f 1935/1498 1929/1492 1934/1501 +f 498/1490 1925/1491 1936/1502 +f 1938/1503 1936/1502 1925/1491 +f 497/1499 1937/1504 1933/1497 +f 1938/1503 1933/1497 1937/1504 +f 500/1505 1940/1506 1939/1507 +f 1942/1508 1939/1507 1940/1506 +f 486/1450 1893/1451 1941/1509 +f 1942/1508 1941/1509 1893/1451 +f 1944/1510 1946/1511 501/1512 +f 1943/1513 501/1512 1946/1511 +f 1945/1514 1946/1511 500/1505 +f 1940/1506 500/1505 1946/1511 +f 502/1515 1948/1516 1947/1517 +f 1950/1518 1947/1517 1948/1516 +f 501/1512 1949/1519 1944/1510 +f 1950/1518 1944/1510 1949/1519 +f 1941/1509 1952/1520 486/1450 +f 1900/1459 486/1450 1952/1520 +f 1951/1521 1952/1520 502/1515 +f 1948/1516 502/1515 1952/1520 +f 1954/1522 1956/1523 504/1524 +f 1953/1525 504/1524 1956/1523 +f 1955/1526 477/1411 1956/1523 +f 1863/1413 1956/1523 477/1411 +f 505/1527 1958/1528 1957/1529 +f 1960/1530 1957/1529 1958/1528 +f 504/1524 1959/1531 1954/1522 +f 1960/1530 1954/1522 1959/1531 +f 1961/1532 1963/1533 501/1512 +f 1949/1519 501/1512 1963/1533 +f 1962/1534 1963/1533 505/1527 +f 1958/1528 505/1527 1963/1533 +f 1964/1535 1870/1422 1955/1526 +f 477/1411 1955/1526 1870/1422 +f 501/1512 1943/1513 1961/1532 +f 1964/1535 1961/1532 1943/1513 +f 1966/1536 1969/1537 507/1538 +f 1965/1539 507/1538 1969/1537 +f 509/1540 1968/1541 1967/1542 +f 1969/1537 1967/1542 1968/1541 +f 1971/1543 1973/1544 508/1545 +f 1970/1546 508/1545 1973/1544 +f 1973/1544 1966/1536 1972/1547 +f 507/1538 1972/1547 1966/1536 +f 505/1527 1974/1548 1962/1534 +f 1976/1549 1962/1534 1974/1548 +f 1976/1549 1971/1543 1975/1550 +f 508/1545 1975/1550 1971/1543 +f 1977/1551 509/1540 1978/1552 +f 1967/1542 1978/1552 509/1540 +f 1957/1529 1978/1552 505/1527 +f 1974/1548 505/1527 1978/1552 +f 493/1473 1979/1553 1912/1472 +f 1982/1554 1912/1472 1979/1553 +f 511/1555 1981/1556 1980/1557 +f 1982/1554 1980/1557 1981/1556 +f 502/1515 1983/1558 1951/1521 +f 1984/1559 1951/1521 1983/1558 +f 1921/1483 1984/1559 493/1473 +f 1979/1553 493/1473 1984/1559 +f 1975/1550 508/1545 1986/1560 +f 1985/1561 1986/1560 508/1545 +f 1947/1517 1986/1560 502/1515 +f 1983/1558 502/1515 1986/1560 +f 1980/1557 1988/1562 511/1555 +f 1987/1563 511/1555 1988/1562 +f 508/1545 1970/1546 1985/1561 +f 1988/1562 1985/1561 1970/1546 +f 498/1490 1989/1564 1926/1489 +f 1992/1565 1926/1489 1989/1564 +f 515/1566 1991/1567 1990/1568 +f 1992/1565 1990/1568 1991/1567 +f 1994/1569 1995/1570 513/1571 +f 1993/1572 513/1571 1995/1570 +f 1936/1502 1995/1570 498/1490 +f 1989/1564 498/1490 1995/1570 +f 514/1573 1997/1574 1996/1575 +f 1999/1576 1996/1575 1997/1574 +f 513/1571 1998/1577 1994/1569 +f 1999/1576 1994/1569 1998/1577 +f 1990/1568 2002/1578 515/1566 +f 2000/1579 515/1566 2002/1578 +f 2001/1580 2002/1578 514/1573 +f 1997/1574 514/1573 2002/1578 +f 2004/1581 2007/1582 517/1583 +f 2003/1584 517/1583 2007/1582 +f 2006/1585 2007/1582 519/1586 +f 2005/1587 519/1586 2007/1582 +f 518/1588 2009/1589 2008/1590 +f 2011/1591 2008/1590 2009/1589 +f 2011/1591 2004/1581 2010/1592 +f 517/1583 2010/1592 2004/1581 +f 2012/1593 2014/1594 513/1571 +f 1998/1577 513/1571 2014/1594 +f 2013/1595 2014/1594 518/1588 +f 2009/1589 518/1588 2014/1594 +f 519/1586 2005/1587 2015/1596 +f 2016/1597 2015/1596 2005/1587 +f 513/1571 1993/1572 2012/1593 +f 2016/1597 2012/1593 1993/1572 +f 2020/1598 1968/1541 2017/1599 +f 509/1540 2017/1599 1968/1541 +f 2020/1598 2018/1600 2019/1601 +f 522/1602 2019/1601 2018/1600 +f 2021/1603 521/1604 2023/1605 +f 2022/1606 2023/1605 521/1604 +f 2023/1605 2017/1599 1977/1551 +f 509/1540 1977/1551 2017/1599 +f 518/1588 2024/1607 2013/1595 +f 2026/1608 2013/1595 2024/1607 +f 521/1604 2025/1609 2022/1606 +f 2026/1608 2022/1606 2025/1609 +f 2018/1600 2028/1610 522/1602 +f 2027/1611 522/1602 2028/1610 +f 2008/1590 2028/1610 518/1588 +f 2024/1607 518/1588 2028/1610 +f 484/1434 2029/1612 1881/1435 +f 2031/1613 1881/1435 2029/1612 +f 504/1524 1953/1525 2030/1614 +f 2031/1613 2030/1614 1953/1525 +f 514/1573 2032/1615 2001/1580 +f 2033/1616 2001/1580 2032/1615 +f 1890/1445 2033/1616 484/1434 +f 2029/1612 484/1434 2033/1616 +f 2034/1617 2035/1618 521/1604 +f 2025/1609 521/1604 2035/1618 +f 1996/1575 2035/1618 514/1573 +f 2032/1615 514/1573 2035/1618 +f 1959/1531 504/1524 2036/1619 +f 2030/1614 2036/1619 504/1524 +f 521/1604 2021/1603 2034/1617 +f 2036/1619 2034/1617 2021/1603 +f 2038/1620 2041/1621 525/1622 +f 2037/1623 525/1622 2041/1621 +f 2040/1624 2041/1621 528/1625 +f 2039/1626 528/1625 2041/1621 +f 526/1627 2043/1628 2042/1629 +f 2045/1630 2042/1629 2043/1628 +f 525/1622 2044/1631 2038/1620 +f 2045/1630 2038/1620 2044/1631 +f 2047/1632 2049/1633 527/1634 +f 2046/1635 527/1634 2049/1633 +f 2048/1636 2049/1633 526/1627 +f 2043/1628 526/1627 2049/1633 +f 2052/1637 2050/1638 2039/1626 +f 528/1625 2039/1626 2050/1638 +f 527/1634 2051/1639 2047/1632 +f 2052/1637 2047/1632 2051/1639 +f 2057/1640 2053/1641 2054/1642 +f 530/1643 2054/1642 2053/1641 +f 2056/1644 2057/1640 532/1645 +f 2055/1646 532/1645 2057/1640 +f 531/1647 2059/1648 2058/1649 +f 2061/1650 2058/1649 2059/1648 +f 2061/1650 2054/1642 2060/1651 +f 530/1643 2060/1651 2054/1642 +f 2062/1652 2064/1653 526/1627 +f 2048/1636 526/1627 2064/1653 +f 2063/1654 2064/1653 531/1647 +f 2059/1648 531/1647 2064/1653 +f 532/1645 2055/1646 2065/1655 +f 2066/1656 2065/1655 2055/1646 +f 526/1627 2042/1629 2062/1652 +f 2066/1656 2062/1652 2042/1629 +f 534/1657 2068/1658 2067/1659 +f 2071/1660 2067/1659 2068/1658 +f 537/1661 2070/1662 2069/1663 +f 2071/1660 2069/1663 2070/1662 +f 2072/1664 535/1665 2075/1666 +f 2073/1667 2075/1666 535/1665 +f 2074/1668 2075/1666 534/1657 +f 2068/1658 534/1657 2075/1666 +f 536/1669 2077/1670 2076/1671 +f 2079/1672 2076/1671 2077/1670 +f 2079/1672 2073/1667 2078/1673 +f 535/1665 2078/1673 2073/1667 +f 2080/1674 537/1661 2082/1675 +f 2069/1663 2082/1675 537/1661 +f 2081/1676 2082/1675 536/1669 +f 2077/1670 536/1669 2082/1675 +f 2084/1677 2086/1678 539/1679 +f 2083/1680 539/1679 2086/1678 +f 2053/1641 2086/1678 530/1643 +f 2085/1681 530/1643 2086/1678 +f 536/1669 2087/1682 2081/1676 +f 2089/1683 2081/1676 2087/1682 +f 539/1679 2088/1684 2084/1677 +f 2089/1683 2084/1677 2088/1684 +f 2091/1685 2092/1686 540/1687 +f 2090/1688 540/1687 2092/1686 +f 2076/1671 2092/1686 536/1669 +f 2087/1682 536/1669 2092/1686 +f 530/1643 2085/1681 2060/1651 +f 2094/1689 2060/1651 2085/1681 +f 540/1687 2093/1690 2091/1685 +f 2094/1689 2091/1685 2093/1690 +f 542/1691 2096/1692 2095/1693 +f 2098/1694 2095/1693 2096/1692 +f 507/1538 1965/1539 2097/1695 +f 2098/1694 2097/1695 1965/1539 +f 2099/1696 2101/1697 532/1645 +f 2056/1644 532/1645 2101/1697 +f 2100/1698 2101/1697 542/1691 +f 2096/1692 542/1691 2101/1697 +f 543/1699 2103/1700 2102/1701 +f 2104/1702 2102/1701 2103/1700 +f 2104/1702 2099/1696 2065/1655 +f 532/1645 2065/1655 2099/1696 +f 2097/1695 2106/1703 507/1538 +f 1972/1547 507/1538 2106/1703 +f 2105/1704 2106/1703 543/1699 +f 2103/1700 543/1699 2106/1703 +f 2010/1592 517/1583 2110/1705 +f 2107/1706 2110/1705 517/1583 +f 2109/1707 2110/1705 546/1708 +f 2108/1709 546/1708 2110/1705 +f 2113/1710 2111/1711 2112/1712 +f 545/1713 2112/1712 2111/1711 +f 517/1583 2003/1584 2107/1706 +f 2113/1710 2107/1706 2003/1584 +f 537/1661 2114/1714 2070/1662 +f 2116/1715 2070/1662 2114/1714 +f 545/1713 2115/1716 2112/1712 +f 2116/1715 2112/1712 2115/1716 +f 546/1708 2108/1709 2117/1717 +f 2118/1718 2117/1717 2108/1709 +f 2080/1674 2118/1718 537/1661 +f 2114/1714 537/1661 2118/1718 +f 2119/1719 2122/1720 491/1470 +f 1916/1479 491/1470 2122/1720 +f 2121/1721 2122/1720 549/1722 +f 2120/1723 549/1722 2122/1720 +f 2125/1724 2123/1725 2124/1726 +f 548/1727 2124/1726 2123/1725 +f 491/1470 1909/1471 2119/1719 +f 2125/1724 2119/1719 1909/1471 +f 528/1625 2126/1728 2040/1624 +f 2128/1729 2040/1624 2126/1728 +f 2124/1726 548/1727 2128/1729 +f 2127/1730 2128/1729 548/1727 +f 549/1722 2120/1723 2129/1731 +f 2130/1732 2129/1731 2120/1723 +f 2050/1638 2130/1732 528/1625 +f 2126/1728 528/1625 2130/1732 +f 2131/1733 2133/1734 539/1679 +f 2088/1684 539/1679 2133/1734 +f 2117/1717 2133/1734 546/1708 +f 2132/1735 546/1708 2133/1734 +f 542/1691 2134/1736 2100/1698 +f 2135/1737 2100/1698 2134/1736 +f 539/1679 2083/1680 2131/1733 +f 2135/1737 2131/1733 2083/1680 +f 2136/1738 2137/1739 522/1602 +f 2019/1601 522/1602 2137/1739 +f 2095/1693 2137/1739 542/1691 +f 2134/1736 542/1691 2137/1739 +f 546/1708 2132/1735 2109/1707 +f 2138/1740 2109/1707 2132/1735 +f 522/1602 2027/1611 2136/1738 +f 2138/1740 2136/1738 2027/1611 +f 543/1699 2139/1741 2105/1704 +f 2141/1742 2105/1704 2139/1741 +f 511/1555 1987/1563 2140/1743 +f 2141/1742 2140/1743 1987/1563 +f 2142/1744 2143/1745 525/1622 +f 2044/1631 525/1622 2143/1745 +f 2102/1701 2143/1745 543/1699 +f 2139/1741 543/1699 2143/1745 +f 548/1727 2144/1746 2127/1730 +f 2145/1747 2127/1730 2144/1746 +f 525/1622 2037/1623 2142/1744 +f 2145/1747 2142/1744 2037/1623 +f 2140/1743 2146/1748 511/1555 +f 1981/1556 511/1555 2146/1748 +f 2123/1725 2146/1748 548/1727 +f 2144/1746 548/1727 2146/1748 +f 2150/1749 2121/1721 2147/1750 +f 549/1722 2147/1750 2121/1721 +f 2149/1751 2150/1749 555/1752 +f 2148/1753 555/1752 2150/1749 +f 2152/1754 2153/1755 553/1756 +f 2151/1757 553/1756 2153/1755 +f 2147/1750 549/1722 2153/1755 +f 2129/1731 2153/1755 549/1722 +f 554/1758 2155/1759 2154/1760 +f 2157/1761 2154/1760 2155/1759 +f 2157/1761 2152/1754 2156/1762 +f 553/1756 2156/1762 2152/1754 +f 2158/1763 555/1752 2160/1764 +f 2148/1753 2160/1764 555/1752 +f 2159/1765 2160/1764 554/1758 +f 2155/1759 554/1758 2160/1764 +f 2164/1766 2159/1767 2161/1768 +f 554/1769 2161/1768 2159/1767 +f 559/1770 2163/1771 2162/1772 +f 2164/1766 2162/1772 2163/1771 +f 2166/1773 2167/1774 557/1775 +f 2165/1776 557/1775 2167/1774 +f 2161/1768 554/1769 2167/1774 +f 2154/1777 2167/1774 554/1769 +f 558/1778 2169/1779 2168/1780 +f 2171/1781 2168/1780 2169/1779 +f 2171/1781 2166/1773 2170/1782 +f 557/1775 2170/1782 2166/1773 +f 2162/1772 2174/1783 559/1770 +f 2172/1784 559/1770 2174/1783 +f 2173/1785 2174/1783 558/1778 +f 2169/1779 558/1778 2174/1783 +f 2175/1786 2178/1787 559/1770 +f 2163/1771 559/1770 2178/1787 +f 2177/1788 2178/1787 563/1789 +f 2176/1790 563/1789 2178/1787 +f 561/1791 2180/1792 2179/1793 +f 2181/1794 2179/1793 2180/1792 +f 559/1770 2172/1784 2175/1786 +f 2181/1794 2175/1786 2172/1784 +f 2183/1795 2185/1796 562/1797 +f 2182/1798 562/1797 2185/1796 +f 2184/1799 2185/1796 561/1791 +f 2180/1792 561/1791 2185/1796 +f 563/1789 2176/1790 2186/1800 +f 2188/1801 2186/1800 2176/1790 +f 562/1797 2187/1802 2183/1795 +f 2188/1801 2183/1795 2187/1802 +f 2190/1803 2192/1804 565/1805 +f 2189/1806 565/1805 2192/1804 +f 2179/1793 2192/1804 561/1791 +f 2191/1807 561/1791 2192/1804 +f 2194/1808 2196/1809 566/1810 +f 2193/1811 566/1810 2196/1809 +f 565/1805 2195/1812 2190/1803 +f 2196/1809 2190/1803 2195/1812 +f 2198/1813 2200/1814 567/1815 +f 2197/1816 567/1815 2200/1814 +f 566/1810 2199/1817 2194/1808 +f 2200/1814 2194/1808 2199/1817 +f 561/1791 2191/1807 2184/1799 +f 2202/1818 2184/1799 2191/1807 +f 567/1815 2201/1819 2198/1813 +f 2202/1818 2198/1813 2201/1819 +f 2204/1820 2207/1821 569/1822 +f 2203/1823 569/1822 2207/1821 +f 2205/1824 572/1825 2207/1821 +f 2206/1826 2207/1821 572/1825 +f 2209/1827 2211/1828 570/1829 +f 2208/1830 570/1829 2211/1828 +f 569/1822 2210/1831 2204/1820 +f 2211/1828 2204/1820 2210/1831 +f 571/1832 2213/1833 2212/1834 +f 2215/1835 2212/1834 2213/1833 +f 570/1829 2214/1836 2209/1827 +f 2215/1835 2209/1827 2214/1836 +f 572/1825 2205/1824 2216/1837 +f 2218/1838 2216/1837 2205/1824 +f 2213/1833 571/1832 2218/1838 +f 2217/1839 2218/1838 571/1832 +f 2220/1840 2223/1841 574/1842 +f 2219/1843 574/1842 2223/1841 +f 2221/1844 577/1845 2223/1841 +f 2222/1846 2223/1841 577/1845 +f 2225/1847 2227/1848 575/1849 +f 2224/1850 575/1849 2227/1848 +f 574/1842 2226/1851 2220/1840 +f 2227/1848 2220/1840 2226/1851 +f 576/1852 2229/1853 2228/1854 +f 2231/1855 2228/1854 2229/1853 +f 575/1849 2230/1856 2225/1847 +f 2231/1855 2225/1847 2230/1856 +f 577/1845 2221/1844 2232/1857 +f 2234/1858 2232/1857 2221/1844 +f 2229/1853 576/1852 2234/1858 +f 2233/1859 2234/1858 576/1852 +f 579/1860 2236/1861 2235/1862 +f 2238/1863 2235/1862 2236/1861 +f 515/1864 2000/1865 2237/1866 +f 2238/1863 2237/1866 2000/1865 +f 574/1842 2239/1867 2226/1851 +f 2241/1868 2226/1851 2239/1867 +f 2236/1861 579/1860 2241/1868 +f 2240/1869 2241/1868 579/1860 +f 580/1870 2243/1871 2242/1872 +f 2244/1873 2242/1872 2243/1871 +f 574/1842 2219/1843 2239/1867 +f 2244/1873 2239/1867 2219/1843 +f 2237/1866 2246/1874 515/1864 +f 1991/1875 515/1864 2246/1874 +f 2243/1871 580/1870 2246/1874 +f 2245/1876 2246/1874 580/1870 +f 2248/1877 2251/1878 582/1879 +f 2247/1880 582/1879 2251/1878 +f 2250/1881 2251/1878 584/1882 +f 2249/1883 584/1882 2251/1878 +f 576/1852 2252/1884 2233/1859 +f 2254/1885 2233/1859 2252/1884 +f 582/1879 2253/1886 2248/1877 +f 2254/1885 2248/1877 2253/1886 +f 583/1887 2256/1888 2255/1889 +f 2257/1890 2255/1889 2256/1888 +f 2252/1884 576/1852 2257/1890 +f 2228/1854 2257/1890 576/1852 +f 584/1882 2249/1883 2258/1891 +f 2260/1892 2258/1891 2249/1883 +f 2260/1892 2256/1888 2259/1893 +f 583/1887 2259/1893 2256/1888 +f 2261/1894 2263/1895 483/1896 +f 1891/1897 483/1896 2263/1895 +f 2235/1862 2263/1895 579/1860 +f 2262/1898 579/1860 2263/1895 +f 583/1887 2264/1899 2259/1893 +f 2265/1900 2259/1893 2264/1899 +f 483/1896 1886/1901 2261/1894 +f 2265/1900 2261/1894 1886/1901 +f 2266/1902 2267/1903 575/1849 +f 2230/1856 575/1849 2267/1903 +f 583/1887 2255/1889 2264/1899 +f 2267/1903 2264/1899 2255/1889 +f 579/1860 2262/1898 2240/1869 +f 2268/1904 2240/1869 2262/1898 +f 575/1849 2224/1850 2266/1902 +f 2268/1904 2266/1902 2224/1850 +f 2271/1905 1930/1906 2269/1907 +f 495/1908 2269/1907 1930/1906 +f 2271/1905 2270/1909 2247/1880 +f 582/1879 2247/1880 2270/1909 +f 2272/1910 2273/1911 580/1870 +f 2245/1876 580/1870 2273/1911 +f 2269/1907 495/1908 2273/1911 +f 1923/1912 2273/1911 495/1908 +f 577/1845 2274/1913 2222/1846 +f 2275/1914 2222/1846 2274/1913 +f 580/1870 2242/1872 2272/1910 +f 2275/1914 2272/1910 2242/1872 +f 2270/1909 2276/1915 582/1879 +f 2253/1886 582/1879 2276/1915 +f 2276/1915 2274/1913 2232/1857 +f 577/1845 2232/1857 2274/1913 +f 500/1916 2277/1917 1945/1918 +f 2280/1919 1945/1918 2277/1917 +f 589/1920 2279/1921 2278/1922 +f 2280/1919 2278/1922 2279/1921 +f 2282/1923 2283/1924 588/1925 +f 2281/1926 588/1925 2283/1924 +f 1939/1927 2283/1924 500/1916 +f 2277/1917 500/1916 2283/1924 +f 572/1825 2284/1928 2206/1826 +f 2286/1929 2206/1826 2284/1928 +f 588/1925 2285/1930 2282/1923 +f 2286/1929 2282/1923 2285/1930 +f 2278/1922 2288/1931 589/1920 +f 2287/1932 589/1920 2288/1931 +f 2284/1928 572/1825 2288/1931 +f 2216/1837 2288/1931 572/1825 +f 2292/1933 2289/1934 2290/1935 +f 591/1936 2290/1935 2289/1934 +f 489/1937 1906/1938 2291/1939 +f 2292/1933 2291/1939 1906/1938 +f 2293/1940 2295/1941 569/1822 +f 2210/1831 569/1822 2295/1941 +f 2290/1935 591/1936 2295/1941 +f 2294/1942 2295/1941 591/1936 +f 588/1925 2296/1943 2285/1930 +f 2297/1944 2285/1930 2296/1943 +f 569/1822 2203/1823 2293/1940 +f 2297/1944 2293/1940 2203/1823 +f 1896/1945 489/1937 2298/1946 +f 2291/1939 2298/1946 489/1937 +f 2296/1943 588/1925 2298/1946 +f 2281/1926 2298/1946 588/1925 +f 478/1947 2299/1948 1874/1949 +f 2302/1950 1874/1949 2299/1948 +f 593/1951 2301/1952 2300/1953 +f 2302/1950 2300/1953 2301/1952 +f 2303/1954 2304/1955 589/1920 +f 2279/1921 589/1920 2304/1955 +f 1868/1956 2304/1955 478/1947 +f 2299/1948 478/1947 2304/1955 +f 571/1832 2305/1957 2217/1839 +f 2306/1958 2217/1839 2305/1957 +f 589/1920 2287/1932 2303/1954 +f 2306/1958 2303/1954 2287/1932 +f 2300/1953 2308/1959 593/1951 +f 2307/1960 593/1951 2308/1959 +f 2212/1834 2308/1959 571/1832 +f 2305/1957 571/1832 2308/1959 +f 2310/1961 2312/1962 595/1963 +f 2309/1964 595/1963 2312/1962 +f 2289/1934 2312/1962 591/1936 +f 2311/1965 591/1936 2312/1962 +f 2313/1966 2315/1967 593/1951 +f 2301/1952 593/1951 2315/1967 +f 595/1963 2314/1968 2310/1961 +f 2315/1967 2310/1961 2314/1968 +f 570/1829 2316/1969 2214/1836 +f 2317/1970 2214/1836 2316/1969 +f 593/1951 2307/1960 2313/1966 +f 2317/1970 2313/1966 2307/1960 +f 591/1936 2311/1965 2294/1942 +f 2318/1971 2294/1942 2311/1965 +f 570/1829 2208/1830 2316/1969 +f 2318/1971 2316/1969 2208/1830 +f 2319/1972 2322/1973 565/1805 +f 2195/1812 565/1805 2322/1973 +f 2321/1974 2322/1973 599/1975 +f 2320/1976 599/1975 2322/1973 +f 558/1778 2323/1977 2173/1785 +f 2324/1978 2173/1785 2323/1977 +f 565/1805 2189/1806 2319/1972 +f 2324/1978 2319/1972 2189/1806 +f 2326/1979 2327/1980 597/1981 +f 2325/1982 597/1981 2327/1980 +f 2323/1977 558/1778 2327/1980 +f 2168/1780 2327/1980 558/1778 +f 598/1983 2329/1984 2328/1985 +f 2331/1986 2328/1985 2329/1984 +f 2331/1986 2326/1979 2330/1987 +f 597/1981 2330/1987 2326/1979 +f 2320/1976 2334/1988 599/1975 +f 2332/1989 599/1975 2334/1988 +f 2333/1990 2334/1988 598/1983 +f 2329/1984 598/1983 2334/1988 +f 2335/1991 601/1992 2339/1993 +f 2336/1994 2339/1993 601/1992 +f 2338/1995 2339/1993 604/1996 +f 2337/1997 604/1996 2339/1993 +f 2341/1998 2343/1999 602/2000 +f 2340/2001 602/2000 2343/1999 +f 2336/1994 601/1992 2343/1999 +f 2342/2002 2343/1999 601/1992 +f 2345/2003 2347/2004 603/2005 +f 2344/2006 603/2005 2347/2004 +f 602/2000 2346/2007 2341/1998 +f 2347/2004 2341/1998 2346/2007 +f 604/1996 2337/1997 2348/2008 +f 2350/2009 2348/2008 2337/1997 +f 603/2005 2349/2010 2345/2003 +f 2350/2009 2345/2003 2349/2010 +f 2351/2011 2353/2012 603/2005 +f 2349/2010 603/2005 2353/2012 +f 2352/2013 598/2014 2353/2012 +f 2328/2015 2353/2012 598/2014 +f 606/2016 2355/2017 2354/2018 +f 2356/2019 2354/2018 2355/2017 +f 603/2005 2344/2006 2351/2011 +f 2356/2019 2351/2011 2344/2006 +f 2358/2020 2360/2021 607/2022 +f 2357/2023 607/2022 2360/2021 +f 2359/2024 2360/2021 606/2016 +f 2355/2017 606/2016 2360/2021 +f 2362/2025 2333/2026 2352/2013 +f 598/2014 2352/2013 2333/2026 +f 607/2022 2361/2027 2358/2020 +f 2362/2025 2358/2020 2361/2027 +f 2363/2028 2366/2029 606/2016 +f 2359/2024 606/2016 2366/2029 +f 2365/2030 2366/2029 610/2031 +f 2364/2032 610/2031 2366/2029 +f 2367/2033 2368/2034 602/2000 +f 2346/2007 602/2000 2368/2034 +f 606/2016 2354/2018 2363/2028 +f 2368/2034 2363/2028 2354/2018 +f 2370/2035 2371/2036 609/2037 +f 2369/2038 609/2037 2371/2036 +f 602/2000 2340/2001 2367/2033 +f 2371/2036 2367/2033 2340/2001 +f 610/2031 2364/2032 2372/2039 +f 2374/2040 2372/2039 2364/2032 +f 609/2037 2373/2041 2370/2035 +f 2374/2040 2370/2035 2373/2041 +f 612/2042 2376/2043 2375/2044 +f 2378/2045 2375/2044 2376/2043 +f 324/2046 1247/2047 2377/2048 +f 2378/2045 2377/2048 1247/2047 +f 2379/2049 2381/2050 527/1634 +f 2051/1639 527/1634 2381/2050 +f 2380/2051 2381/2050 612/2042 +f 2376/2043 612/2042 2381/2050 +f 613/2052 2383/2053 2382/2054 +f 2384/2055 2382/2054 2383/2053 +f 527/1634 2046/1635 2379/2049 +f 2384/2055 2379/2049 2046/1635 +f 2377/2048 2386/2056 324/2046 +f 1254/2057 324/2046 2386/2056 +f 2385/2058 2386/2056 613/2052 +f 2383/2053 613/2052 2386/2056 +f 615/2059 2388/2060 2387/2061 +f 2390/2062 2387/2061 2388/2060 +f 2390/2062 2389/2063 1261/2064 +f 328/2065 1261/2064 2389/2063 +f 2391/2066 2393/2067 540/1687 +f 2093/1690 540/1687 2393/2067 +f 2392/2068 2393/2067 615/2059 +f 2388/2060 615/2059 2393/2067 +f 2396/2069 2394/2070 2395/2071 +f 616/2072 2395/2071 2394/2070 +f 540/1687 2090/1688 2391/2066 +f 2396/2069 2391/2066 2090/1688 +f 2389/2063 2398/2073 328/2065 +f 1268/2074 328/2065 2398/2073 +f 2395/2071 616/2072 2398/2073 +f 2397/2075 2398/2073 616/2072 +f 616/2072 2399/2076 2397/2075 +f 2401/2077 2397/2075 2399/2076 +f 2401/2077 2400/2078 1275/2079 +f 332/2080 1275/2079 2400/2078 +f 2078/1673 535/1665 2403/2081 +f 2402/2082 2403/2081 535/1665 +f 2394/2070 2403/2081 616/2072 +f 2399/2076 616/2072 2403/2081 +f 618/2083 2405/2084 2404/2085 +f 2406/2086 2404/2085 2405/2084 +f 2406/2086 2402/2082 2072/1664 +f 535/1665 2072/1664 2402/2082 +f 2400/2078 2408/2087 332/2080 +f 1281/2088 332/2080 2408/2087 +f 2405/2084 618/2083 2408/2087 +f 2407/2089 2408/2087 618/2083 +f 620/2090 2410/2091 2409/2092 +f 2412/2093 2409/2092 2410/2091 +f 335/2094 1287/2095 2411/2096 +f 2412/2093 2411/2096 1287/2095 +f 2413/2097 2415/2098 595/2099 +f 2314/2100 595/2099 2415/2098 +f 2414/2101 2415/2098 620/2090 +f 2410/2091 620/2090 2415/2098 +f 2418/2102 2416/2103 2417/2104 +f 621/2105 2417/2104 2416/2103 +f 2418/2102 2413/2097 2309/2106 +f 595/2099 2309/2106 2413/2097 +f 2411/2096 2420/2107 335/2094 +f 1294/2108 335/2094 2420/2107 +f 2417/2104 621/2105 2420/2107 +f 2419/2109 2420/2107 621/2105 +f 2421/2110 623/2111 2424/2112 +f 2422/2113 2424/2112 623/2111 +f 2423/2114 339/2115 2424/2112 +f 1301/2116 2424/2112 339/2115 +f 584/2117 2425/2118 2250/2119 +f 2427/2120 2250/2119 2425/2118 +f 623/2111 2426/2121 2422/2113 +f 2427/2120 2422/2113 2426/2121 +f 2429/2122 2430/2123 624/2124 +f 2428/2125 624/2124 2430/2123 +f 2425/2118 584/2117 2430/2123 +f 2258/2126 2430/2123 584/2117 +f 2432/2127 1308/2128 2423/2114 +f 339/2115 2423/2114 1308/2128 +f 624/2124 2431/2129 2429/2122 +f 2432/2127 2429/2122 2431/2129 +f 613/2052 2433/2130 2385/2058 +f 2435/2131 2385/2058 2433/2130 +f 2435/2131 2434/2132 1315/2133 +f 343/2134 1315/2133 2434/2132 +f 2063/1654 531/1647 2437/2135 +f 2436/2136 2437/2135 531/1647 +f 2382/2054 2437/2135 613/2052 +f 2433/2130 613/2052 2437/2135 +f 2439/2137 2392/2068 2438/2138 +f 615/2059 2438/2138 2392/2068 +f 531/1647 2058/1649 2436/2136 +f 2439/2137 2436/2136 2058/1649 +f 2434/2132 2440/2139 343/2134 +f 1320/2140 343/2134 2440/2139 +f 2438/2138 615/2059 2440/2139 +f 2387/2061 2440/2139 615/2059 +f 627/2141 2442/2142 2441/2143 +f 2444/2144 2441/2143 2442/2142 +f 345/2145 1325/2146 2443/2147 +f 2444/2144 2443/2147 1325/2146 +f 2156/1762 553/1756 2447/2148 +f 2445/2149 2447/2148 553/1756 +f 2446/2150 2447/2148 627/2141 +f 2442/2142 627/2141 2447/2148 +f 612/2042 2448/2151 2380/2051 +f 2449/2152 2380/2051 2448/2151 +f 553/1756 2151/1757 2445/2149 +f 2449/2152 2445/2149 2151/1757 +f 1331/2153 345/2145 2450/2154 +f 2443/2147 2450/2154 345/2145 +f 2375/2044 2450/2154 612/2042 +f 2448/2151 612/2042 2450/2154 +f 629/2155 2452/2156 2451/2157 +f 2454/2158 2451/2157 2452/2156 +f 2454/2158 2453/2159 1337/746 +f 348/748 1337/746 2453/2159 +f 2170/2160 557/2161 2457/2162 +f 2455/2163 2457/2162 557/2161 +f 629/2155 2456/2164 2452/2156 +f 2457/2162 2452/2156 2456/2164 +f 2459/2165 2446/2166 2458/2167 +f 627/2168 2458/2167 2446/2166 +f 557/2161 2165/2169 2455/2163 +f 2459/2165 2455/2163 2165/2169 +f 2453/2159 2460/2170 348/748 +f 1343/756 348/748 2460/2170 +f 2458/2167 627/2168 2460/2170 +f 2441/2171 2460/2170 627/2168 +f 631/2172 2462/2173 2461/2174 +f 2464/2175 2461/2174 2462/2173 +f 2464/2175 2463/2176 1349/766 +f 351/768 1349/766 2463/2176 +f 2465/2177 632/2178 2468/2179 +f 2466/2180 2468/2179 632/2178 +f 2467/2181 2468/2179 631/2172 +f 2462/2173 631/2172 2468/2179 +f 633/2182 2470/2183 2469/2184 +f 2472/2185 2469/2184 2470/2183 +f 632/2178 2471/2186 2466/2180 +f 2472/2185 2466/2180 2471/2186 +f 2463/2176 2474/2187 351/768 +f 1356/776 351/768 2474/2187 +f 2473/2188 2474/2187 633/2182 +f 2470/2183 633/2182 2474/2187 +f 2478/2189 2475/2190 2476/2191 +f 635/2192 2476/2191 2475/2190 +f 1365/785 2478/2189 356/786 +f 2477/2193 356/786 2478/2189 +f 566/1810 2479/2194 2199/1817 +f 2481/2195 2199/1817 2479/2194 +f 2476/2191 635/2192 2481/2195 +f 2480/2196 2481/2195 635/2192 +f 631/2172 2482/2197 2467/2181 +f 2483/2198 2467/2181 2482/2197 +f 2193/1811 2483/2198 566/1810 +f 2479/2194 566/1810 2483/2198 +f 356/786 2477/2193 1371/794 +f 2484/2199 1371/794 2477/2193 +f 2482/2197 631/2172 2484/2199 +f 2461/2174 2484/2199 631/2172 +f 637/2200 2486/2201 2485/2202 +f 2488/2203 2485/2202 2486/2201 +f 2488/2203 2487/2204 1377/2205 +f 359/2206 1377/2205 2487/2204 +f 2489/2207 2491/2208 496/1494 +f 1934/1501 496/1494 2491/2208 +f 2490/2209 2491/2208 637/2200 +f 2486/2201 637/2200 2491/2208 +f 2492/2210 2493/2211 623/2111 +f 2426/2121 623/2111 2493/2211 +f 496/1494 1928/1495 2489/2207 +f 2493/2211 2489/2207 1928/1495 +f 2487/2204 2494/2212 359/2206 +f 1383/2213 359/2206 2494/2212 +f 2494/2212 2492/2210 2421/2110 +f 623/2111 2421/2110 2492/2210 +f 2495/2214 2497/2215 621/2105 +f 2419/2109 621/2105 2497/2215 +f 2496/2216 362/2217 2497/2215 +f 1389/2218 2497/2215 362/2217 +f 488/1460 2498/2219 1907/1467 +f 2499/2220 1907/1467 2498/2219 +f 2499/2220 2495/2214 2416/2103 +f 621/2105 2416/2103 2495/2214 +f 2501/2221 2502/2222 639/2223 +f 2500/2224 639/2223 2502/2222 +f 1902/1462 2502/2222 488/1460 +f 2498/2219 488/1460 2502/2222 +f 2504/2225 1395/2226 2496/2216 +f 362/2217 2496/2216 1395/2226 +f 639/2223 2503/2227 2501/2221 +f 2504/2225 2501/2221 2503/2227 +f 2505/2228 2507/2229 639/2223 +f 2503/2227 639/2223 2507/2229 +f 2506/2230 365/2231 2507/2229 +f 1401/2232 2507/2229 365/2231 +f 492/1475 2508/2233 1919/1482 +f 2509/2234 1919/1482 2508/2233 +f 639/2223 2500/2224 2505/2228 +f 2509/2234 2505/2228 2500/2224 +f 2511/2235 2512/2236 641/2237 +f 2510/2238 641/2237 2512/2236 +f 1914/1477 2512/2236 492/1475 +f 2508/2233 492/1475 2512/2236 +f 2514/2239 1407/2240 2506/2230 +f 365/2231 2506/2230 1407/2240 +f 641/2237 2513/2241 2511/2235 +f 2514/2239 2511/2235 2513/2241 +f 2515/2242 2517/2243 641/2237 +f 2513/2241 641/2237 2517/2243 +f 2516/2244 368/2245 2517/2243 +f 1413/2246 2517/2243 368/2245 +f 2519/2247 2149/1751 2518/2248 +f 555/1752 2518/2248 2149/1751 +f 641/2237 2510/2238 2515/2242 +f 2519/2247 2515/2242 2510/2238 +f 2522/2249 2520/2250 2521/2251 +f 643/2252 2521/2251 2520/2250 +f 555/1752 2158/1763 2518/2248 +f 2522/2249 2518/2248 2158/1763 +f 1419/2253 368/2245 2524/2254 +f 2516/2244 2524/2254 368/2245 +f 2521/2251 643/2252 2524/2254 +f 2523/2255 2524/2254 643/2252 +f 643/2256 2525/2257 2523/2258 +f 2527/2259 2523/2258 2525/2257 +f 371/855 1425/857 2526/2260 +f 2527/2259 2526/2260 1425/857 +f 563/1789 2528/2261 2177/1788 +f 2529/2262 2177/1788 2528/2261 +f 2520/2263 2529/2262 643/2256 +f 2525/2257 643/2256 2529/2262 +f 2531/2264 2532/2265 645/2266 +f 2530/2267 645/2266 2532/2265 +f 2186/1800 2532/2265 563/1789 +f 2528/2261 563/1789 2532/2265 +f 1431/866 371/855 2534/2268 +f 2526/2260 2534/2268 371/855 +f 645/2266 2533/2269 2531/2264 +f 2534/2268 2531/2264 2533/2269 +f 2535/2270 2537/2271 645/2266 +f 2533/2269 645/2266 2537/2271 +f 2536/2272 374/874 2537/2271 +f 1437/875 2537/2271 374/874 +f 562/1797 2538/2273 2187/1802 +f 2539/2274 2187/1802 2538/2273 +f 645/2266 2530/2267 2535/2270 +f 2539/2274 2535/2270 2530/2267 +f 2541/2275 2542/2276 647/2277 +f 2540/2278 647/2277 2542/2276 +f 2182/1798 2542/2276 562/1797 +f 2538/2273 562/1797 2542/2276 +f 2544/2279 1443/881 2536/2272 +f 374/874 2536/2272 1443/881 +f 647/2277 2543/2280 2541/2275 +f 2544/2279 2541/2275 2543/2280 +f 2545/2281 2547/2282 647/2277 +f 2543/2280 647/2277 2547/2282 +f 2547/2282 2546/2283 1449/887 +f 377/889 1449/887 2546/2283 +f 2548/2284 2549/2285 567/1815 +f 2201/1819 567/1815 2549/2285 +f 2540/2278 2549/2285 647/2277 +f 2545/2281 647/2277 2549/2285 +f 635/2192 2550/2286 2480/2196 +f 2551/2287 2480/2196 2550/2286 +f 567/1815 2197/1816 2548/2284 +f 2551/2287 2548/2284 2197/1816 +f 2546/2283 2552/2288 377/889 +f 1454/893 377/889 2552/2288 +f 2550/2286 635/2192 2552/2288 +f 2475/2190 2552/2288 635/2192 +f 2555/2289 1461/899 2553/2290 +f 380/900 2553/2290 1461/899 +f 2555/2289 2554/2291 2451/2157 +f 629/2155 2451/2157 2554/2291 +f 2557/2292 2558/2293 650/2294 +f 2556/2295 650/2294 2558/2293 +f 380/900 1470/916 2553/2290 +f 2558/2293 2553/2290 1470/916 +f 604/2296 2559/2297 2338/2298 +f 2561/2299 2338/2298 2559/2297 +f 650/2294 2560/2300 2557/2292 +f 2561/2299 2557/2292 2560/2300 +f 2562/2301 2563/2302 597/2303 +f 2330/2304 597/2303 2563/2302 +f 2348/2305 2563/2302 604/2296 +f 2559/2297 604/2296 2563/2302 +f 2554/2291 2564/2306 629/2155 +f 2456/2164 629/2155 2564/2306 +f 2564/2306 2562/2301 2325/2307 +f 597/2303 2325/2307 2562/2301 +f 2321/1974 599/1975 2567/2308 +f 2565/2309 2567/2308 599/1975 +f 2465/2177 2567/2308 632/2178 +f 2566/2310 632/2178 2567/2308 +f 652/2311 2569/2312 2568/2313 +f 2570/2314 2568/2313 2569/2312 +f 599/1975 2332/1989 2565/2309 +f 2570/2314 2565/2309 2332/1989 +f 2471/2186 632/2178 2572/2315 +f 2566/2310 2572/2315 632/2178 +f 2571/2316 2572/2315 652/2311 +f 2569/2312 652/2311 2572/2315 +f 654/2317 2574/2318 2573/2319 +f 2577/2320 2573/2319 2574/2318 +f 657/2321 2576/2322 2575/2323 +f 2577/2320 2575/2323 2576/2322 +f 2579/2324 2581/2325 655/2326 +f 2578/2327 655/2326 2581/2325 +f 2580/2328 2581/2325 654/2317 +f 2574/2318 654/2317 2581/2325 +f 656/2329 2583/2330 2582/2331 +f 2585/2332 2582/2331 2583/2330 +f 655/2326 2584/2333 2579/2324 +f 2585/2332 2579/2324 2584/2333 +f 2575/2323 2588/2334 657/2321 +f 2586/2335 657/2321 2588/2334 +f 2587/2336 2588/2334 656/2329 +f 2583/2330 656/2329 2588/2334 +f 659/2337 2590/2338 2589/2339 +f 2593/2340 2589/2339 2590/2338 +f 2593/2340 2591/2341 2592/2342 +f 662/2343 2592/2342 2591/2341 +f 660/2344 2595/2345 2594/2346 +f 2597/2347 2594/2346 2595/2345 +f 2590/2338 659/2337 2597/2347 +f 2596/2348 2597/2347 659/2337 +f 2601/2349 2598/2350 2599/2351 +f 661/2352 2599/2351 2598/2350 +f 2595/2345 660/2344 2601/2349 +f 2600/2353 2601/2349 660/2344 +f 2591/2341 2604/2354 662/2343 +f 2602/2355 662/2343 2604/2354 +f 2599/2351 661/2352 2604/2354 +f 2603/2356 2604/2354 661/2352 +f 2606/2357 2609/2358 664/2359 +f 2605/2360 664/2359 2609/2358 +f 2608/2361 2609/2358 667/2362 +f 2607/2363 667/2362 2609/2358 +f 2613/2364 2610/2365 2611/2366 +f 665/2367 2611/2366 2610/2365 +f 664/2359 2612/2368 2606/2357 +f 2613/2364 2606/2357 2612/2368 +f 2615/2369 2617/2370 666/2371 +f 2614/2372 666/2371 2617/2370 +f 2611/2366 665/2367 2617/2370 +f 2616/2373 2617/2370 665/2367 +f 2607/2363 2620/2374 667/2362 +f 2618/2375 667/2362 2620/2374 +f 2620/2374 2615/2369 2619/2376 +f 666/2371 2619/2376 2615/2369 +f 2603/2356 661/2352 2624/2377 +f 2621/2378 2624/2377 661/2352 +f 671/2379 2623/2380 2622/2381 +f 2624/2377 2622/2381 2623/2380 +f 2626/2382 2627/2383 669/2384 +f 2625/2385 669/2384 2627/2383 +f 2621/2378 661/2352 2627/2383 +f 2598/2350 2627/2383 661/2352 +f 670/2386 2629/2387 2628/2388 +f 2631/2389 2628/2388 2629/2387 +f 2631/2389 2626/2382 2630/2390 +f 669/2384 2630/2390 2626/2382 +f 671/2379 2622/2381 2632/2391 +f 2634/2392 2632/2391 2622/2381 +f 2629/2387 670/2386 2634/2392 +f 2633/2393 2634/2392 670/2386 +f 2638/2394 2633/2393 2635/2395 +f 670/2386 2635/2395 2633/2393 +f 674/2396 2637/2397 2636/2398 +f 2638/2394 2636/2398 2637/2397 +f 2641/2399 2639/2400 2640/2401 +f 673/2402 2640/2401 2639/2400 +f 2635/2395 670/2386 2641/2399 +f 2628/2388 2641/2399 670/2386 +f 2619/2376 666/2371 2644/2403 +f 2642/2404 2644/2403 666/2371 +f 2644/2403 2640/2401 2643/2405 +f 673/2402 2643/2405 2640/2401 +f 2646/2406 2645/2407 2636/2398 +f 674/2396 2636/2398 2645/2407 +f 666/2371 2614/2372 2642/2404 +f 2646/2406 2642/2404 2614/2372 +f 676/2408 2648/2409 2647/2410 +f 2650/2411 2647/2410 2648/2409 +f 2589/2339 2650/2411 659/2337 +f 2649/2412 659/2337 2650/2411 +f 2652/2413 2654/2414 677/2415 +f 2651/2416 677/2415 2654/2414 +f 2653/2417 2654/2414 676/2408 +f 2648/2409 676/2408 2654/2414 +f 2612/2368 664/2359 2657/2418 +f 2655/2419 2657/2418 664/2359 +f 677/2415 2656/2420 2652/2413 +f 2657/2418 2652/2413 2656/2420 +f 659/2337 2649/2412 2596/2348 +f 2658/2421 2596/2348 2649/2412 +f 664/2359 2605/2360 2655/2419 +f 2658/2421 2655/2419 2605/2360 +f 2660/2422 2662/2423 679/2424 +f 2659/2425 679/2424 2662/2423 +f 2661/2426 676/2427 2662/2423 +f 2647/2428 2662/2423 676/2427 +f 2663/2429 2665/2430 607/2022 +f 2361/2027 607/2022 2665/2430 +f 2664/2431 2665/2430 679/2424 +f 2660/2422 679/2424 2665/2430 +f 610/2031 2666/2432 2365/2030 +f 2667/2433 2365/2030 2666/2432 +f 607/2022 2357/2023 2663/2429 +f 2667/2433 2663/2429 2357/2023 +f 2669/2434 2670/2435 680/2436 +f 2668/2437 680/2436 2670/2435 +f 2372/2039 2670/2435 610/2031 +f 2666/2432 610/2031 2670/2435 +f 676/2427 2661/2426 2653/2438 +f 2672/2439 2653/2438 2661/2426 +f 680/2436 2671/2440 2669/2434 +f 2672/2439 2669/2434 2671/2440 +f 2656/2441 677/2442 2676/2443 +f 2673/2444 2676/2443 677/2442 +f 2675/2445 2676/2443 682/2446 +f 2674/2447 682/2446 2676/2443 +f 680/2436 2677/2448 2671/2440 +f 2678/2449 2671/2440 2677/2448 +f 677/2442 2651/2450 2673/2444 +f 2678/2449 2673/2444 2651/2450 +f 609/2037 2679/2451 2373/2041 +f 2680/2452 2373/2041 2679/2451 +f 2680/2452 2677/2448 2668/2437 +f 680/2436 2668/2437 2677/2448 +f 2682/2453 2342/2002 2681/2454 +f 601/1992 2681/2454 2342/2002 +f 609/2037 2369/2038 2679/2451 +f 2682/2453 2679/2451 2369/2038 +f 2684/2455 2683/2456 2674/2447 +f 682/2446 2674/2447 2683/2456 +f 2684/2455 2681/2454 2335/1991 +f 601/1992 2335/1991 2681/2454 +f 665/2457 2685/2458 2616/2459 +f 2688/2460 2616/2459 2685/2458 +f 684/2461 2687/2462 2686/2463 +f 2688/2460 2686/2463 2687/2462 +f 2689/2464 2690/2465 682/2466 +f 2675/2467 682/2466 2690/2465 +f 2610/2468 2690/2465 665/2457 +f 2685/2458 665/2457 2690/2465 +f 650/2294 2691/2469 2560/2300 +f 2692/2470 2560/2300 2691/2469 +f 2692/2470 2689/2464 2683/2471 +f 682/2466 2683/2471 2689/2464 +f 2693/2472 2694/2473 415/1075 +f 1602/1082 415/1075 2694/2473 +f 2556/2295 2694/2473 650/2294 +f 2691/2469 650/2294 2694/2473 +f 2686/2463 2696/2474 684/2461 +f 2695/2475 684/2461 2696/2474 +f 415/1075 1597/1077 2693/2472 +f 2696/2474 2693/2472 1597/1077 +f 2697/2476 2700/2477 419/1095 +f 1610/1096 419/1095 2700/2477 +f 2699/2478 2700/2477 687/2479 +f 2698/2480 687/2479 2700/2477 +f 633/2182 2701/2481 2473/2188 +f 2702/2482 2473/2188 2701/2481 +f 419/1095 1621/1110 2697/2476 +f 2702/2482 2697/2476 1621/1110 +f 2704/2483 2705/2484 686/2485 +f 2703/2486 686/2485 2705/2484 +f 2469/2184 2705/2484 633/2182 +f 2701/2481 633/2182 2705/2484 +f 2706/2487 2708/2488 671/2489 +f 2623/2490 671/2489 2708/2488 +f 686/2485 2707/2491 2704/2483 +f 2708/2488 2704/2483 2707/2491 +f 2710/2492 2709/2493 2698/2480 +f 687/2479 2698/2480 2709/2493 +f 2706/2487 671/2489 2710/2492 +f 2632/2494 2710/2492 671/2489 +f 1625/1114 421/1115 2713/2495 +f 2711/2496 2713/2495 421/1115 +f 684/2461 2695/2475 2712/2497 +f 2713/2495 2712/2497 2695/2475 +f 687/2498 2714/2499 2699/2500 +f 2715/2501 2699/2500 2714/2499 +f 2715/2501 2711/2496 1631/1127 +f 421/1115 1631/1127 2711/2496 +f 2716/2502 2717/2503 674/2504 +f 2637/2505 674/2504 2717/2503 +f 2714/2499 687/2498 2717/2503 +f 2709/2506 2717/2503 687/2498 +f 2712/2497 2718/2507 684/2461 +f 2687/2462 684/2461 2718/2507 +f 2645/2508 2718/2507 674/2504 +f 2716/2502 674/2504 2718/2507 +f 652/2311 2719/2509 2571/2316 +f 2721/2510 2571/2316 2719/2509 +f 686/2485 2703/2486 2720/2511 +f 2721/2510 2720/2511 2703/2486 +f 2664/2512 679/2513 2723/2514 +f 2722/2515 2723/2514 679/2513 +f 2568/2313 2723/2514 652/2311 +f 2719/2509 652/2311 2723/2514 +f 2724/2516 2725/2517 662/2518 +f 2592/2519 662/2518 2725/2517 +f 2659/2520 2725/2517 679/2513 +f 2722/2515 679/2513 2725/2517 +f 2720/2511 2726/2521 686/2485 +f 2707/2491 686/2485 2726/2521 +f 662/2518 2602/2522 2724/2516 +f 2726/2521 2724/2516 2602/2522 +f 660/2344 2727/2523 2600/2353 +f 2730/2524 2600/2353 2727/2523 +f 2730/2524 2728/2525 2729/2526 +f 692/2527 2729/2526 2728/2525 +f 2731/2528 691/2529 2733/2530 +f 2732/2531 2733/2530 691/2529 +f 2594/2346 2733/2530 660/2344 +f 2727/2523 660/2344 2733/2530 +f 657/2321 2734/2532 2576/2322 +f 2736/2533 2576/2322 2734/2532 +f 691/2529 2735/2534 2732/2531 +f 2736/2533 2732/2531 2735/2534 +f 692/2527 2728/2525 2737/2535 +f 2738/2536 2737/2535 2728/2525 +f 657/2321 2586/2335 2734/2532 +f 2738/2536 2734/2532 2586/2335 +f 2739/2537 2742/2538 669/2384 +f 2630/2390 669/2384 2742/2538 +f 2741/2539 2742/2538 694/2540 +f 2740/2541 694/2540 2742/2538 +f 2729/2526 692/2527 2744/2542 +f 2743/2543 2744/2542 692/2527 +f 669/2384 2625/2385 2739/2537 +f 2744/2542 2739/2537 2625/2385 +f 656/2329 2745/2544 2587/2336 +f 2746/2545 2587/2336 2745/2544 +f 692/2527 2737/2535 2743/2543 +f 2746/2545 2743/2543 2737/2535 +f 694/2540 2740/2541 2747/2546 +f 2748/2547 2747/2546 2740/2541 +f 656/2329 2582/2331 2745/2544 +f 2748/2547 2745/2544 2582/2331 +f 673/2402 2749/2548 2643/2405 +f 2752/2549 2643/2405 2749/2548 +f 2752/2549 2750/2550 2751/2551 +f 696/2552 2751/2551 2750/2550 +f 2754/2553 2741/2539 2753/2554 +f 694/2540 2753/2554 2741/2539 +f 2639/2400 2754/2553 673/2402 +f 2749/2548 673/2402 2754/2553 +f 2755/2555 2756/2556 655/2326 +f 2584/2333 655/2326 2756/2556 +f 2753/2554 694/2540 2756/2556 +f 2747/2546 2756/2556 694/2540 +f 696/2552 2750/2550 2757/2557 +f 2758/2558 2757/2557 2750/2550 +f 655/2326 2578/2327 2755/2555 +f 2758/2558 2755/2555 2578/2327 +f 2759/2559 2761/2560 667/2362 +f 2608/2361 667/2362 2761/2560 +f 2731/2528 2761/2560 691/2529 +f 2760/2561 691/2529 2761/2560 +f 2763/2562 2751/2551 2762/2563 +f 696/2552 2762/2563 2751/2551 +f 667/2362 2618/2375 2759/2559 +f 2763/2562 2759/2559 2618/2375 +f 654/2317 2764/2564 2580/2328 +f 2765/2565 2580/2328 2764/2564 +f 696/2552 2757/2557 2762/2563 +f 2765/2565 2762/2563 2757/2557 +f 691/2529 2760/2561 2735/2534 +f 2766/2566 2735/2534 2760/2561 +f 654/2317 2573/2319 2764/2564 +f 2766/2566 2764/2564 2573/2319 +f 2767/2567 699/2568 2770/2569 +f 2768/2570 2770/2569 699/2568 +f 2769/2571 482/2572 2770/2569 +f 1883/2573 2770/2569 482/2572 +f 2774/2574 2771/2575 2772/2576 +f 700/2577 2772/2576 2771/2575 +f 699/2568 2773/2578 2768/2570 +f 2774/2574 2768/2570 2773/2578 +f 2778/2579 2775/2580 2776/2581 +f 701/2582 2776/2581 2775/2580 +f 2772/2576 700/2577 2778/2579 +f 2777/2583 2778/2579 700/2577 +f 2780/2584 1888/2585 2769/2571 +f 482/2572 2769/2571 1888/2585 +f 2776/2581 701/2582 2780/2584 +f 2779/2586 2780/2584 701/2582 +f 701/2582 2781/2587 2779/2586 +f 2783/2588 2779/2586 2781/2587 +f 624/2589 2428/2590 2782/2591 +f 2783/2588 2782/2591 2428/2590 +f 2785/2592 2786/2593 703/2594 +f 2784/2595 703/2594 2786/2593 +f 2775/2580 2786/2593 701/2582 +f 2781/2587 701/2582 2786/2593 +f 436/1214 2787/2596 1703/1221 +f 2789/2597 1703/1221 2787/2596 +f 703/2594 2788/2598 2785/2592 +f 2789/2597 2785/2592 2788/2598 +f 2782/2591 2790/2599 624/2589 +f 2431/2600 624/2589 2790/2599 +f 1698/1215 2790/2599 436/1214 +f 2787/2596 436/1214 2790/2599 +f 2791/2601 2793/2602 441/1229 +f 1709/1228 441/1229 2793/2602 +f 2409/2603 2793/2602 620/2604 +f 2792/2605 620/2604 2793/2602 +f 705/2606 2795/2607 2794/2608 +f 2796/2609 2794/2608 2795/2607 +f 441/1229 1718/1241 2791/2601 +f 2796/2609 2791/2601 1718/1241 +f 2797/2610 706/2611 2800/2612 +f 2798/2613 2800/2612 706/2611 +f 2799/2614 2800/2612 705/2606 +f 2795/2607 705/2606 2800/2612 +f 620/2604 2792/2605 2414/2615 +f 2802/2616 2414/2615 2792/2605 +f 706/2611 2801/2617 2798/2613 +f 2802/2616 2798/2613 2801/2617 +f 2803/2618 2805/2619 706/2611 +f 2801/2617 706/2611 2805/2619 +f 2805/2619 2804/2620 1872/2621 +f 479/2622 1872/2621 2804/2620 +f 2807/2623 2808/2624 708/2625 +f 2806/2626 708/2625 2808/2624 +f 2808/2624 2803/2618 2797/2610 +f 706/2611 2797/2610 2803/2618 +f 699/2568 2809/2627 2773/2578 +f 2811/2628 2773/2578 2809/2627 +f 2811/2628 2807/2623 2810/2629 +f 708/2625 2810/2629 2807/2623 +f 2804/2620 2812/2630 479/2622 +f 1877/2631 479/2622 2812/2630 +f 2812/2630 2809/2627 2767/2567 +f 699/2568 2767/2567 2809/2627 +f 2813/2632 2815/2633 703/2594 +f 2788/2598 703/2594 2815/2633 +f 445/1258 1731/1260 2814/2634 +f 2815/2633 2814/2634 1731/1260 +f 700/2577 2816/2635 2777/2583 +f 2817/2636 2777/2583 2816/2635 +f 703/2594 2784/2595 2813/2632 +f 2817/2636 2813/2632 2784/2595 +f 2819/2637 2820/2638 710/2639 +f 2818/2640 710/2639 2820/2638 +f 2771/2575 2820/2638 700/2577 +f 2816/2635 700/2577 2820/2638 +f 2822/2641 1737/1267 2814/2634 +f 445/1258 2814/2634 1737/1267 +f 710/2639 2821/2642 2819/2637 +f 2822/2641 2819/2637 2821/2642 +f 710/2639 2823/2643 2821/2642 +f 2825/2644 2821/2642 2823/2643 +f 1743/1273 2825/2644 448/1275 +f 2824/2645 448/1275 2825/2644 +f 2826/2646 2827/2647 708/2625 +f 2810/2629 708/2625 2827/2647 +f 2818/2640 2827/2647 710/2639 +f 2823/2643 710/2639 2827/2647 +f 705/2606 2828/2648 2799/2614 +f 2829/2649 2799/2614 2828/2648 +f 708/2625 2806/2626 2826/2646 +f 2829/2649 2826/2646 2806/2626 +f 2824/2645 2830/2650 448/1275 +f 1748/1279 448/1275 2830/2650 +f 2794/2608 2830/2650 705/2606 +f 2828/2648 705/2606 2830/2650 +f 2832/2651 2835/2652 713/2653 +f 2831/2654 713/2653 2835/2652 +f 2834/2655 2835/2652 715/2656 +f 2833/2657 715/2656 2835/2652 +f 2836/2658 714/2659 2839/2660 +f 2837/2661 2839/2660 714/2659 +f 713/2653 2838/2662 2832/2651 +f 2839/2660 2832/2651 2838/2662 +f 715/2656 2833/2657 2840/2663 +f 2842/2664 2840/2663 2833/2657 +f 714/2659 2841/2665 2837/2661 +f 2842/2664 2837/2661 2841/2665 +f 2844/2666 2846/2667 717/2668 +f 2843/2669 717/2668 2846/2667 +f 713/2653 2831/2654 2845/2670 +f 2846/2667 2845/2670 2831/2654 +f 519/1586 2847/2671 2006/1585 +f 2849/2672 2006/1585 2847/2671 +f 2849/2672 2844/2666 2848/2673 +f 717/2668 2848/2673 2844/2666 +f 2850/2674 2851/2675 497/1499 +f 1937/1504 497/1499 2851/2675 +f 2015/1596 2851/2675 519/1586 +f 2847/2671 519/1586 2851/2675 +f 718/2676 2853/2677 2852/2678 +f 2854/2679 2852/2678 2853/2677 +f 497/1499 1932/1500 2850/2674 +f 2854/2679 2850/2674 1932/1500 +f 2845/2670 2856/2680 713/2653 +f 2838/2662 713/2653 2856/2680 +f 2855/2681 2856/2680 718/2676 +f 2853/2677 718/2676 2856/2680 +f 715/2656 2857/2682 2834/2655 +f 2859/2683 2834/2655 2857/2682 +f 717/2668 2843/2669 2858/2684 +f 2859/2683 2858/2684 2843/2669 +f 2861/2685 2862/2686 720/2687 +f 2860/2688 720/2687 2862/2686 +f 2840/2663 2862/2686 715/2656 +f 2857/2682 715/2656 2862/2686 +f 2863/2689 2865/2690 534/1657 +f 2074/1668 534/1657 2865/2690 +f 2864/2691 2865/2690 720/2687 +f 2861/2685 720/2687 2865/2690 +f 545/1713 2866/2692 2115/1716 +f 2867/2693 2115/1716 2866/2692 +f 2863/2689 534/1657 2867/2693 +f 2067/1659 2867/2693 534/1657 +f 2858/2684 2868/2694 717/2668 +f 2848/2673 717/2668 2868/2694 +f 2111/1711 2868/2694 545/1713 +f 2866/2692 545/1713 2868/2694 +f 2869/2695 2872/2696 460/2697 +f 1794/2698 460/2697 2872/2696 +f 2871/2699 2872/2696 722/2700 +f 2870/2701 722/2700 2872/2696 +f 618/2083 2873/2702 2407/2089 +f 2874/2703 2407/2089 2873/2702 +f 2874/2703 2869/2695 1801/2704 +f 460/2697 1801/2704 2869/2695 +f 2864/2691 720/2687 2876/2705 +f 2875/2706 2876/2705 720/2687 +f 2404/2085 2876/2705 618/2083 +f 2873/2702 618/2083 2876/2705 +f 722/2700 2870/2701 2877/2707 +f 2878/2708 2877/2707 2870/2701 +f 720/2687 2860/2688 2875/2706 +f 2878/2708 2875/2706 2860/2688 +f 463/2709 2879/2710 1805/2711 +f 2881/2712 1805/2711 2879/2710 +f 637/2200 2485/2202 2880/2713 +f 2881/2712 2880/2713 2485/2202 +f 2883/2714 2884/2715 724/2716 +f 2882/2717 724/2716 2884/2715 +f 1812/2718 2884/2715 463/2709 +f 2879/2710 463/2709 2884/2715 +f 718/2676 2885/2719 2855/2681 +f 2887/2720 2855/2681 2885/2719 +f 724/2716 2886/2721 2883/2714 +f 2887/2720 2883/2714 2886/2721 +f 2880/2713 2888/2722 637/2200 +f 2490/2209 637/2200 2888/2722 +f 2852/2678 2888/2722 718/2676 +f 2885/2719 718/2676 2888/2722 +f 726/2723 2890/2724 2889/2725 +f 2892/2726 2889/2725 2890/2724 +f 714/2659 2836/2658 2891/2727 +f 2892/2726 2891/2727 2836/2658 +f 2894/2728 2896/2729 727/2730 +f 2893/2731 727/2730 2896/2729 +f 2895/2732 2896/2729 726/2723 +f 2890/2724 726/2723 2896/2729 +f 2898/2733 2900/2734 728/2735 +f 2897/2736 728/2735 2900/2734 +f 2894/2728 727/2730 2900/2734 +f 2899/2737 2900/2734 727/2730 +f 2841/2665 714/2659 2902/2738 +f 2891/2727 2902/2738 714/2659 +f 2902/2738 2898/2733 2901/2739 +f 728/2735 2901/2739 2898/2733 +f 2901/2739 728/2735 2905/2740 +f 2903/2741 2905/2740 728/2735 +f 2877/2707 2905/2740 722/2700 +f 2904/2742 722/2700 2905/2740 +f 730/2743 2907/2744 2906/2745 +f 2908/2746 2906/2745 2907/2744 +f 728/2735 2897/2736 2903/2741 +f 2908/2746 2903/2741 2897/2736 +f 2909/2747 2911/2748 469/2749 +f 1837/2750 469/2749 2911/2748 +f 2910/2751 2911/2748 730/2743 +f 2907/2744 730/2743 2911/2748 +f 722/2700 2904/2742 2871/2699 +f 2912/2752 2871/2699 2904/2742 +f 469/2749 1832/2753 2909/2747 +f 2912/2752 2909/2747 1832/2753 +f 473/2754 2913/2755 1843/2756 +f 2915/2757 1843/2756 2913/2755 +f 2915/2757 2914/2758 2882/2717 +f 724/2716 2882/2717 2914/2758 +f 2917/2759 2918/2760 732/2761 +f 2916/2762 732/2761 2918/2760 +f 1850/2763 2918/2760 473/2754 +f 2913/2755 473/2754 2918/2760 +f 2921/2764 2895/2732 2919/2765 +f 726/2723 2919/2765 2895/2732 +f 732/2761 2920/2766 2917/2759 +f 2921/2764 2917/2759 2920/2766 +f 2914/2758 2922/2767 724/2716 +f 2886/2721 724/2716 2922/2767 +f 2919/2765 726/2723 2922/2767 +f 2889/2725 2922/2767 726/2723 +f 2923/2768 2925/2769 727/2730 +f 2899/2737 727/2730 2925/2769 +f 2906/2745 2925/2769 730/2743 +f 2924/2770 730/2743 2925/2769 +f 2926/2771 2927/2772 732/2761 +f 2920/2766 732/2761 2927/2772 +f 2923/2768 727/2730 2927/2772 +f 2893/2731 2927/2772 727/2730 +f 475/2773 2928/2774 1860/2775 +f 2929/2776 1860/2775 2928/2774 +f 732/2761 2916/2762 2926/2771 +f 2929/2776 2926/2771 2916/2762 +f 730/2743 2924/2770 2910/2751 +f 2930/2777 2910/2751 2924/2770 +f 2930/2777 2928/2774 1856/2778 +f 475/2773 1856/2778 2928/2774 +f 738/6 6/2779 739/1 +f 735/2 739/1 6/2779 +f 193/2780 737/7 736/3 +f 739/1 736/3 737/7 +f 743/11 742/12 740/10 +f 14/2781 740/10 742/12 +f 741/9 193/2780 743/11 +f 736/3 743/11 193/2780 +f 747/14 746/17 744/16 +f 10/2782 744/16 746/17 +f 193/2780 741/9 745/13 +f 747/14 745/13 741/9 +f 16/2783 748/18 749/20 +f 750/19 749/20 748/18 +f 745/13 750/19 193/2780 +f 737/7 193/2780 750/19 +f 754/22 735/2 751/24 +f 6/2779 751/24 735/2 +f 197/2784 753/25 752/21 +f 754/22 752/21 753/25 +f 18/2785 755/28 757/30 +f 758/29 757/30 755/28 +f 752/21 758/29 197/2784 +f 756/27 197/2784 758/29 +f 762/33 761/35 759/31 +f 13/2786 759/31 761/35 +f 197/2784 756/27 760/34 +f 762/33 760/34 756/27 +f 763/37 14/2781 764/36 +f 742/12 764/36 14/2781 +f 760/34 764/36 197/2784 +f 753/25 197/2784 764/36 +f 1/2787 765/39 768/42 +f 769/38 768/42 765/39 +f 767/44 769/38 202/2788 +f 766/40 202/2788 769/38 +f 12/2789 770/48 772/49 +f 773/46 772/49 770/48 +f 202/2788 766/40 771/45 +f 773/46 771/45 766/40 +f 774/52 777/53 11/2790 +f 776/54 11/2790 777/53 +f 771/45 777/53 202/2788 +f 775/51 202/2788 777/53 +f 24/2791 778/55 779/57 +f 780/56 779/57 778/55 +f 202/2788 775/51 767/44 +f 780/56 767/44 775/51 +f 7/2792 781/61 784/62 +f 785/59 784/62 781/61 +f 206/2793 783/64 782/58 +f 785/59 782/58 783/64 +f 779/57 788/66 24/2791 +f 787/67 24/2791 788/66 +f 782/58 788/66 206/2793 +f 786/65 206/2793 788/66 +f 11/2790 789/71 774/52 +f 791/69 774/52 789/71 +f 206/2793 786/65 790/68 +f 791/69 790/68 786/65 +f 792/72 794/73 23/2794 +f 793/74 23/2794 794/73 +f 790/68 794/73 206/2793 +f 783/64 206/2793 794/73 +f 2/2795 795/78 798/80 +f 799/76 798/80 795/78 +f 211/2796 797/81 796/75 +f 799/76 796/75 797/81 +f 800/84 803/85 27/2797 +f 802/86 27/2797 803/85 +f 796/75 803/85 211/2796 +f 801/83 211/2796 803/85 +f 804/89 807/90 19/2798 +f 806/91 19/2798 807/90 +f 211/2796 801/83 805/88 +f 807/90 805/88 801/83 +f 20/2799 808/93 809/94 +f 810/92 809/94 808/93 +f 810/92 797/81 805/88 +f 211/2796 805/88 797/81 +f 768/42 814/96 1/2787 +f 813/98 1/2787 814/96 +f 812/99 814/96 215/2800 +f 811/95 215/2800 814/96 +f 24/2791 815/103 778/55 +f 817/101 778/55 815/103 +f 215/2800 811/95 816/100 +f 817/101 816/100 811/95 +f 818/106 821/107 15/2801 +f 820/108 15/2801 821/107 +f 816/100 821/107 215/2800 +f 819/105 215/2800 821/107 +f 16/2783 822/110 823/111 +f 824/109 823/111 822/110 +f 215/2800 819/105 812/99 +f 824/109 812/99 819/105 +f 828/113 827/114 738/6 +f 6/2779 738/6 827/114 +f 218/2802 826/116 825/112 +f 828/113 825/112 826/116 +f 16/2783 823/111 748/18 +f 830/118 748/18 823/111 +f 825/112 830/118 218/2802 +f 829/117 218/2802 830/118 +f 15/2801 831/122 818/106 +f 833/120 818/106 831/122 +f 218/2802 829/117 832/119 +f 833/120 832/119 829/117 +f 834/123 836/124 32/2803 +f 835/125 32/2803 836/124 +f 832/119 836/124 218/2802 +f 826/116 218/2802 836/124 +f 841/129 840/132 837/128 +f 5/2804 837/128 840/132 +f 838/127 222/2805 841/129 +f 839/130 841/129 222/2805 +f 32/2803 835/125 843/135 +f 844/134 843/135 835/125 +f 844/134 842/133 838/127 +f 222/2805 838/127 842/133 +f 831/122 15/2801 847/136 +f 845/137 847/136 15/2801 +f 842/133 847/136 222/2805 +f 846/138 222/2805 847/136 +f 849/142 30/2806 850/140 +f 848/141 850/140 30/2806 +f 222/2805 846/138 839/130 +f 850/140 839/130 846/138 +f 851/145 854/146 7/2792 +f 781/61 7/2792 854/146 +f 853/147 854/146 224/2807 +f 852/144 224/2807 854/146 +f 857/149 856/150 849/142 +f 30/2806 849/142 856/150 +f 855/148 224/2807 857/149 +f 852/144 857/149 224/2807 +f 15/2801 820/108 845/137 +f 859/151 845/137 820/108 +f 859/151 858/152 855/148 +f 224/2807 855/148 858/152 +f 24/2791 787/67 815/103 +f 860/153 815/103 787/67 +f 858/152 860/153 224/2807 +f 853/147 224/2807 860/153 +f 861/156 864/157 2/2795 +f 795/78 2/2795 864/157 +f 863/158 864/157 228/2808 +f 862/155 228/2808 864/157 +f 18/2785 865/162 867/163 +f 868/160 867/163 865/162 +f 228/2808 862/155 866/159 +f 868/160 866/159 862/155 +f 869/166 872/167 17/2809 +f 871/168 17/2809 872/167 +f 866/159 872/167 228/2808 +f 870/165 228/2808 872/167 +f 27/2797 802/86 873/170 +f 874/169 873/170 802/86 +f 228/2808 870/165 863/158 +f 874/169 863/158 870/165 +f 879/172 878/177 875/174 +f 8/2810 875/174 878/177 +f 232/2811 877/175 876/171 +f 879/172 876/171 877/175 +f 873/170 882/179 27/2797 +f 881/180 27/2797 882/179 +f 876/171 882/179 232/2811 +f 880/178 232/2811 882/179 +f 17/2809 883/184 869/166 +f 885/182 869/166 883/184 +f 232/2811 880/178 884/181 +f 885/182 884/181 880/178 +f 887/187 29/2812 888/185 +f 886/186 888/185 29/2812 +f 884/181 888/185 232/2811 +f 877/175 232/2811 888/185 +f 837/128 5/2804 892/188 +f 889/189 892/188 5/2804 +f 891/192 892/188 235/2813 +f 890/190 235/2813 892/188 +f 29/2812 887/187 894/195 +f 895/194 894/195 887/187 +f 235/2813 890/190 893/193 +f 895/194 893/193 890/190 +f 896/198 898/199 17/2809 +f 883/184 17/2809 898/199 +f 893/193 898/199 235/2813 +f 897/197 235/2813 898/199 +f 899/201 32/2803 900/200 +f 843/135 900/200 32/2803 +f 235/2813 897/197 891/192 +f 900/200 891/192 897/197 +f 751/24 6/2779 903/203 +f 827/114 903/203 6/2779 +f 236/2814 902/204 901/202 +f 903/203 901/202 902/204 +f 32/2803 899/201 834/123 +f 905/206 834/123 899/201 +f 901/202 905/206 236/2814 +f 904/205 236/2814 905/206 +f 17/2809 871/168 896/198 +f 907/208 896/198 871/168 +f 236/2814 904/205 906/207 +f 907/208 906/207 904/205 +f 18/2785 757/30 865/162 +f 908/209 865/162 757/30 +f 906/207 908/209 236/2814 +f 902/204 236/2814 908/209 +f 913/211 912/214 909/213 +f 3/2815 909/213 912/214 +f 241/2816 911/216 910/210 +f 913/211 910/210 911/216 +f 22/2817 914/219 916/221 +f 917/220 916/221 914/219 +f 915/218 241/2816 917/220 +f 910/210 917/220 241/2816 +f 21/2818 918/222 920/226 +f 921/224 920/226 918/222 +f 921/224 919/225 915/218 +f 241/2816 915/218 919/225 +f 31/2819 922/227 923/229 +f 924/228 923/229 922/227 +f 919/225 924/228 241/2816 +f 911/216 241/2816 924/228 +f 925/233 929/231 9/2820 +f 928/235 9/2820 929/231 +f 245/2821 927/234 926/230 +f 929/231 926/230 927/234 +f 923/229 932/238 31/2819 +f 931/239 31/2819 932/238 +f 926/230 932/238 245/2821 +f 930/237 245/2821 932/238 +f 21/2818 933/243 918/222 +f 935/241 918/222 933/243 +f 245/2821 930/237 934/240 +f 935/241 934/240 930/237 +f 938/244 937/246 936/245 +f 33/2822 936/245 937/246 +f 934/240 938/244 245/2821 +f 927/234 245/2821 938/244 +f 939/249 943/250 4/2823 +f 942/252 4/2823 943/250 +f 941/253 943/250 250/2824 +f 940/248 250/2824 943/250 +f 28/2825 944/257 946/258 +f 947/255 946/258 944/257 +f 250/2824 940/248 945/254 +f 947/255 945/254 940/248 +f 948/260 951/259 25/2826 +f 950/263 25/2826 951/259 +f 945/254 951/259 250/2824 +f 949/261 250/2824 951/259 +f 26/2827 952/264 953/266 +f 954/265 953/266 952/264 +f 954/265 941/253 949/261 +f 250/2824 949/261 941/253 +f 9/2820 928/235 957/269 +f 958/268 957/269 928/235 +f 253/2828 956/271 955/267 +f 958/268 955/267 956/271 +f 959/274 961/275 33/2822 +f 936/245 33/2822 961/275 +f 955/267 961/275 253/2828 +f 960/273 253/2828 961/275 +f 25/2826 950/263 963/278 +f 964/277 963/278 950/263 +f 253/2828 960/273 962/276 +f 964/277 962/276 960/273 +f 965/279 966/280 28/2825 +f 944/257 28/2825 966/280 +f 962/276 966/280 253/2828 +f 956/271 253/2828 966/280 +f 840/132 970/282 5/2804 +f 969/284 5/2804 970/282 +f 968/285 970/282 256/2829 +f 967/281 256/2829 970/282 +f 30/2806 971/289 848/141 +f 973/287 848/141 971/289 +f 256/2829 967/281 972/286 +f 973/287 972/286 967/281 +f 975/292 31/2819 976/290 +f 931/239 976/290 31/2819 +f 972/286 976/290 256/2829 +f 974/291 256/2829 976/290 +f 9/2820 977/294 925/233 +f 978/293 925/233 977/294 +f 256/2829 974/291 968/285 +f 978/293 968/285 974/291 +f 29/2812 979/298 886/186 +f 982/296 886/186 979/298 +f 982/296 980/295 981/299 +f 259/2830 981/299 980/295 +f 946/258 985/300 28/2825 +f 984/302 28/2825 985/300 +f 980/295 985/300 259/2830 +f 983/301 259/2830 985/300 +f 986/305 988/306 4/2823 +f 939/249 4/2823 988/306 +f 259/2830 983/301 987/304 +f 988/306 987/304 983/301 +f 878/177 990/307 8/2810 +f 989/308 8/2810 990/307 +f 981/299 259/2830 990/307 +f 987/304 990/307 259/2830 +f 23/2794 991/309 792/72 +f 994/311 792/72 991/309 +f 994/311 992/312 993/313 +f 262/2831 993/313 992/312 +f 22/2817 916/221 996/316 +f 997/314 996/316 916/221 +f 992/312 997/314 262/2831 +f 995/315 262/2831 997/314 +f 998/320 1000/318 3/2815 +f 909/213 3/2815 1000/318 +f 262/2831 995/315 999/317 +f 1000/318 999/317 995/315 +f 784/62 1002/321 7/2792 +f 1001/322 7/2792 1002/321 +f 993/313 262/2831 1002/321 +f 999/317 1002/321 262/2831 +f 28/2825 984/302 965/279 +f 1005/324 965/279 984/302 +f 263/2832 1004/325 1003/323 +f 1005/324 1003/323 1004/325 +f 894/195 1007/327 29/2812 +f 979/298 29/2812 1007/327 +f 1003/323 1007/327 263/2832 +f 1006/326 263/2832 1007/327 +f 5/2804 969/284 889/189 +f 1009/329 889/189 969/284 +f 263/2832 1006/326 1008/328 +f 1009/329 1008/328 1006/326 +f 957/269 1010/330 9/2820 +f 977/294 9/2820 1010/330 +f 1008/328 1010/330 263/2832 +f 1004/325 263/2832 1010/330 +f 856/150 1013/332 30/2806 +f 971/289 30/2806 1013/332 +f 1012/333 1013/332 264/2833 +f 1011/331 264/2833 1013/332 +f 7/2792 1001/322 851/145 +f 1015/335 851/145 1001/322 +f 264/2833 1011/331 1014/334 +f 1015/335 1014/334 1011/331 +f 912/214 1017/337 3/2815 +f 998/320 3/2815 1017/337 +f 1014/334 1017/337 264/2833 +f 1016/336 264/2833 1017/337 +f 31/2819 975/292 922/227 +f 1018/338 922/227 975/292 +f 264/2833 1016/336 1012/333 +f 1018/338 1012/333 1016/336 +f 23/2794 1019/339 991/309 +f 1022/341 991/309 1019/339 +f 1020/342 268/2834 1022/341 +f 1021/343 1022/341 268/2834 +f 35/2835 1023/344 1025/348 +f 1026/346 1025/348 1023/344 +f 1026/346 1024/347 1020/342 +f 268/2834 1020/342 1024/347 +f 1029/353 34/2836 1030/349 +f 1027/350 1030/349 34/2836 +f 1024/347 1030/349 268/2834 +f 1028/351 268/2834 1030/349 +f 1032/354 1031/355 996/316 +f 22/2817 996/316 1031/355 +f 268/2834 1028/351 1021/343 +f 1032/354 1021/343 1028/351 +f 1033/358 1036/359 35/2837 +f 1023/361 35/2837 1036/359 +f 1035/360 1036/359 272/2838 +f 1034/357 272/2838 1036/359 +f 37/2839 1037/366 1039/367 +f 1040/364 1039/367 1037/366 +f 272/2838 1034/357 1038/363 +f 1040/364 1038/363 1034/357 +f 1043/372 36/2840 1044/368 +f 1041/369 1044/368 36/2840 +f 1038/363 1044/368 272/2838 +f 1042/370 272/2838 1044/368 +f 1046/373 1045/375 1029/374 +f 34/2841 1029/374 1045/375 +f 272/2838 1042/370 1035/360 +f 1046/373 1035/360 1042/370 +f 35/2837 1047/379 1033/358 +f 1050/377 1033/358 1047/379 +f 276/2842 1049/380 1048/376 +f 1050/377 1048/376 1049/380 +f 1051/383 1054/384 40/2843 +f 1053/385 40/2843 1054/384 +f 1048/376 1054/384 276/2842 +f 1052/382 276/2842 1054/384 +f 41/2844 1055/389 1057/390 +f 1058/387 1057/390 1055/389 +f 276/2842 1052/382 1056/386 +f 1058/387 1056/386 1052/382 +f 1039/367 1060/391 37/2839 +f 1059/392 37/2839 1060/391 +f 1056/386 1060/391 276/2842 +f 1049/380 276/2842 1060/391 +f 37/2839 1059/392 1063/395 +f 1064/394 1063/395 1059/392 +f 280/2845 1062/397 1061/393 +f 1064/394 1061/393 1062/397 +f 1065/400 1067/401 41/2844 +f 1055/389 41/2844 1067/401 +f 1061/393 1067/401 280/2845 +f 1066/399 280/2845 1067/401 +f 1071/405 1070/406 1068/404 +f 42/2846 1068/404 1070/406 +f 280/2845 1066/399 1069/403 +f 1071/405 1069/403 1066/399 +f 38/2847 1072/407 1073/409 +f 1074/408 1073/409 1072/407 +f 1074/408 1062/397 1069/403 +f 280/2845 1069/403 1062/397 +f 1079/411 1078/416 1075/413 +f 43/2848 1075/413 1078/416 +f 285/2849 1077/414 1076/410 +f 1079/411 1076/410 1077/414 +f 1080/420 1083/418 48/2850 +f 1082/421 48/2850 1083/418 +f 285/2849 1076/410 1081/417 +f 1083/418 1081/417 1076/410 +f 1084/424 1087/425 45/2851 +f 1086/426 45/2851 1087/425 +f 285/2849 1081/417 1085/423 +f 1087/425 1085/423 1081/417 +f 1088/427 1090/428 46/2852 +f 1089/429 46/2852 1090/428 +f 285/2849 1085/423 1077/414 +f 1090/428 1077/414 1085/423 +f 1091/433 1095/431 44/2853 +f 1094/435 44/2853 1095/431 +f 290/2854 1093/434 1092/430 +f 1095/431 1092/430 1093/434 +f 1099/438 1098/441 1096/440 +f 50/2855 1096/440 1098/441 +f 290/2854 1092/430 1097/437 +f 1099/438 1097/437 1092/430 +f 1100/444 1103/445 47/2856 +f 1102/446 47/2856 1103/445 +f 1097/437 1103/445 290/2854 +f 1101/443 290/2854 1103/445 +f 1104/447 1106/448 49/2857 +f 1105/449 49/2857 1106/448 +f 290/2854 1101/443 1093/434 +f 1106/448 1093/434 1101/443 +f 18/2858 867/452 1109/455 +f 1110/453 1109/455 867/452 +f 1107/451 293/2859 1110/453 +f 1108/456 1110/453 293/2859 +f 1113/458 861/461 1111/460 +f 2/2860 1111/460 861/461 +f 293/2859 1107/451 1112/457 +f 1113/458 1112/457 1107/451 +f 1094/435 1116/463 44/2853 +f 1115/464 44/2853 1116/463 +f 1112/457 1116/463 293/2859 +f 1114/462 293/2859 1116/463 +f 1117/466 1118/465 49/2857 +f 1104/447 49/2857 1118/465 +f 293/2859 1114/462 1108/456 +f 1118/465 1108/456 1114/462 +f 20/2861 1119/470 1122/471 +f 1123/468 1122/471 1119/470 +f 297/2862 1121/473 1120/467 +f 1123/468 1120/467 1121/473 +f 13/2863 1124/475 1126/478 +f 1127/474 1126/478 1124/475 +f 1120/467 1127/474 297/2862 +f 1125/476 297/2862 1127/474 +f 1102/446 1130/480 47/2856 +f 1129/481 47/2856 1130/480 +f 297/2862 1125/476 1128/479 +f 1130/480 1128/479 1125/476 +f 1131/482 1132/483 50/2855 +f 1096/440 50/2855 1132/483 +f 1128/479 1132/483 297/2862 +f 1121/473 297/2862 1132/483 +f 18/2858 1109/455 755/486 +f 1135/485 755/486 1109/455 +f 298/2864 1134/488 1133/484 +f 1135/485 1133/484 1134/488 +f 1105/449 1137/490 49/2857 +f 1117/466 49/2857 1137/490 +f 1133/484 1137/490 298/2864 +f 1136/489 298/2864 1137/490 +f 1129/481 1139/492 47/2856 +f 1100/444 47/2856 1139/492 +f 298/2864 1136/489 1138/491 +f 1139/492 1138/491 1136/489 +f 13/2863 761/493 1124/475 +f 1140/494 1124/475 761/493 +f 1138/491 1140/494 298/2864 +f 1134/488 298/2864 1140/494 +f 20/2861 1122/471 808/498 +f 1143/495 808/498 1122/471 +f 1142/497 1143/495 299/2865 +f 1141/496 299/2865 1143/495 +f 1098/441 1145/501 50/2855 +f 1131/482 50/2855 1145/501 +f 299/2865 1141/496 1144/500 +f 1145/501 1144/500 1141/496 +f 1115/464 1147/503 44/2853 +f 1091/433 44/2853 1147/503 +f 1144/500 1147/503 299/2865 +f 1146/502 299/2865 1147/503 +f 1148/504 1111/460 798/505 +f 2/2860 798/505 1111/460 +f 1148/504 1142/497 1146/502 +f 299/2865 1146/502 1142/497 +f 16/2866 1149/508 822/511 +f 1152/509 822/511 1149/508 +f 1151/512 1152/509 302/2867 +f 1150/507 302/2867 1152/509 +f 1082/421 1155/514 48/2850 +f 1154/515 48/2850 1155/514 +f 302/2867 1150/507 1153/513 +f 1155/514 1153/513 1150/507 +f 1156/518 1158/519 43/2848 +f 1075/413 43/2848 1158/519 +f 1153/513 1158/519 302/2867 +f 1157/517 302/2867 1158/519 +f 1160/520 1159/522 813/521 +f 1/2868 813/521 1159/522 +f 302/2867 1157/517 1151/512 +f 1160/520 1151/512 1157/517 +f 772/525 1164/526 12/2869 +f 1163/528 12/2869 1164/526 +f 1161/524 304/2870 1164/526 +f 1162/527 1164/526 304/2870 +f 1159/522 1166/531 1/2868 +f 765/532 1/2868 1166/531 +f 1166/531 1165/530 1161/524 +f 304/2870 1161/524 1165/530 +f 1078/416 1168/534 43/2848 +f 1156/518 43/2848 1168/534 +f 1165/530 1168/534 304/2870 +f 1167/533 304/2870 1168/534 +f 1169/536 1170/535 46/2852 +f 1088/427 46/2852 1170/535 +f 304/2870 1167/533 1162/527 +f 1170/535 1162/527 1167/533 +f 1171/539 1174/540 10/2871 +f 744/542 10/2871 1174/540 +f 1173/543 1174/540 306/2872 +f 1172/538 306/2872 1174/540 +f 1086/426 1177/545 45/2851 +f 1176/546 45/2851 1177/545 +f 306/2872 1172/538 1175/544 +f 1177/545 1175/544 1172/538 +f 1154/515 1179/548 48/2850 +f 1080/420 48/2850 1179/548 +f 1175/544 1179/548 306/2872 +f 1178/547 306/2872 1179/548 +f 16/2866 749/550 1149/508 +f 1180/549 1149/508 749/550 +f 306/2872 1178/547 1173/543 +f 1180/549 1173/543 1178/547 +f 12/2869 1163/528 1183/553 +f 1184/552 1183/553 1163/528 +f 308/2873 1182/555 1181/551 +f 1184/552 1181/551 1182/555 +f 1089/429 1186/557 46/2852 +f 1169/536 46/2852 1186/557 +f 1181/551 1186/557 308/2873 +f 1185/556 308/2873 1186/557 +f 1176/546 1188/559 45/2851 +f 1084/424 45/2851 1188/559 +f 308/2873 1185/556 1187/558 +f 1188/559 1187/558 1185/556 +f 10/2871 1189/560 1171/539 +f 1190/561 1171/539 1189/560 +f 1187/558 1190/561 308/2873 +f 1182/555 308/2873 1190/561 +f 38/2847 1191/565 1072/407 +f 1194/563 1072/407 1191/565 +f 312/2874 1193/566 1192/562 +f 1194/563 1192/562 1193/566 +f 51/2875 1195/567 1197/571 +f 1198/569 1197/571 1195/567 +f 312/2874 1192/562 1196/570 +f 1198/569 1196/570 1192/562 +f 1201/576 53/2876 1202/572 +f 1199/573 1202/572 53/2876 +f 312/2874 1196/570 1200/574 +f 1202/572 1200/574 1196/570 +f 1205/578 1204/579 1043/372 +f 36/2840 1043/372 1204/579 +f 312/2874 1200/574 1203/577 +f 1205/578 1203/577 1200/574 +f 1063/395 1206/580 37/2839 +f 1037/366 37/2839 1206/580 +f 1203/577 1206/580 312/2874 +f 1193/566 312/2874 1206/580 +f 52/2877 1207/584 1210/585 +f 1211/582 1210/585 1207/584 +f 1211/582 1208/581 1209/587 +f 317/2878 1209/587 1208/581 +f 1212/590 1215/591 53/2879 +f 1214/592 53/2879 1215/591 +f 1208/581 1215/591 317/2878 +f 1213/589 317/2878 1215/591 +f 1216/595 1219/596 57/2880 +f 1218/597 57/2880 1219/596 +f 1217/594 317/2878 1219/596 +f 1213/589 1219/596 317/2878 +f 1222/598 1221/600 1220/599 +f 56/2881 1220/599 1221/600 +f 317/2878 1217/594 1209/587 +f 1222/598 1209/587 1217/594 +f 1225/602 1212/590 1201/604 +f 53/2879 1201/604 1212/590 +f 320/2882 1224/605 1223/601 +f 1225/602 1223/601 1224/605 +f 51/2883 1226/608 1195/610 +f 1228/609 1195/610 1226/608 +f 1227/607 320/2882 1228/609 +f 1223/601 1228/609 320/2882 +f 1232/612 1231/615 1229/614 +f 54/2884 1229/614 1231/615 +f 320/2882 1227/607 1230/611 +f 1232/612 1230/611 1227/607 +f 1218/597 1234/616 57/2880 +f 1233/617 57/2880 1234/616 +f 1230/611 1234/616 320/2882 +f 1224/605 320/2882 1234/616 +f 1238/619 1229/614 1235/621 +f 54/2884 1235/621 1229/614 +f 323/2885 1237/622 1236/618 +f 1238/619 1236/618 1237/622 +f 1239/625 1242/626 55/2886 +f 1241/627 55/2886 1242/626 +f 1236/618 1242/626 323/2885 +f 1240/624 323/2885 1242/626 +f 1221/600 1245/629 56/2881 +f 1244/630 56/2881 1245/629 +f 323/2885 1240/624 1243/628 +f 1245/629 1243/628 1240/624 +f 1233/617 1246/631 57/2880 +f 1216/595 57/2880 1246/631 +f 1243/628 1246/631 323/2885 +f 1237/622 323/2885 1246/631 +f 1247/634 1251/635 69/2887 +f 1250/637 69/2887 1251/635 +f 1249/638 1251/635 327/2888 +f 1248/633 327/2888 1251/635 +f 76/2889 1252/642 1254/643 +f 1255/640 1254/643 1252/642 +f 327/2888 1248/633 1253/639 +f 1255/640 1253/639 1248/633 +f 920/226 1258/645 21/2818 +f 1257/646 21/2818 1258/645 +f 1253/639 1258/645 327/2888 +f 1256/644 327/2888 1258/645 +f 22/2817 1259/648 914/219 +f 1260/647 914/219 1259/648 +f 327/2888 1256/644 1249/638 +f 1260/647 1249/638 1256/644 +f 1264/654 77/2890 1265/649 +f 1261/650 1265/649 77/2890 +f 1263/655 1265/649 331/2891 +f 1262/651 331/2891 1265/649 +f 1269/657 1268/660 1266/659 +f 80/2892 1266/659 1268/660 +f 331/2891 1262/651 1267/656 +f 1269/657 1267/656 1262/651 +f 963/278 1272/662 25/2826 +f 1271/663 25/2826 1272/662 +f 1270/661 331/2891 1272/662 +f 1267/656 1272/662 331/2891 +f 33/2822 1273/665 959/274 +f 1274/664 959/274 1273/665 +f 331/2891 1270/661 1263/655 +f 1274/664 1263/655 1270/661 +f 1266/659 80/2892 1278/666 +f 1275/667 1278/666 80/2892 +f 1277/670 1278/666 334/2893 +f 1276/668 334/2893 1278/666 +f 1282/672 1281/675 1279/674 +f 81/2894 1279/674 1281/675 +f 334/2893 1276/668 1280/671 +f 1282/672 1280/671 1276/668 +f 1284/678 26/2827 1285/676 +f 953/266 1285/676 26/2827 +f 1280/671 1285/676 334/2893 +f 1283/677 334/2893 1285/676 +f 25/2826 1271/663 948/260 +f 1286/679 948/260 1271/663 +f 1286/679 1277/670 1283/677 +f 334/2893 1283/677 1277/670 +f 1287/682 1291/683 67/2895 +f 1290/685 67/2895 1291/683 +f 1289/686 1291/683 338/2896 +f 1288/681 338/2896 1291/683 +f 1295/688 1294/691 1292/690 +f 68/2897 1292/690 1294/691 +f 338/2896 1288/681 1293/687 +f 1295/688 1293/687 1288/681 +f 1297/696 12/2789 1298/692 +f 1183/693 1298/692 12/2789 +f 1293/687 1298/692 338/2896 +f 1296/694 338/2896 1298/692 +f 1300/697 1189/699 1299/698 +f 10/2782 1299/698 1189/699 +f 338/2896 1296/694 1289/686 +f 1300/697 1289/686 1296/694 +f 78/2898 1301/703 1304/704 +f 1305/701 1304/704 1301/703 +f 1305/701 1302/700 1303/706 +f 342/2899 1303/706 1302/700 +f 1306/709 1309/710 74/2900 +f 1308/711 74/2900 1309/710 +f 1307/708 342/2899 1309/710 +f 1302/700 1309/710 342/2899 +f 1312/713 1311/716 1126/715 +f 13/2786 1126/715 1311/716 +f 342/2899 1307/708 1310/712 +f 1312/713 1310/712 1307/708 +f 1313/717 1314/718 20/2799 +f 1119/719 20/2799 1314/718 +f 1303/706 342/2899 1314/718 +f 1310/712 1314/718 342/2899 +f 1315/721 1318/720 76/2889 +f 1252/642 76/2889 1318/720 +f 1317/724 1318/720 344/2901 +f 1316/722 344/2901 1318/720 +f 1321/726 1320/727 1264/654 +f 77/2890 1264/654 1320/727 +f 344/2901 1316/722 1319/725 +f 1321/726 1319/725 1316/722 +f 937/246 1323/729 33/2822 +f 1273/665 33/2822 1323/729 +f 1322/728 344/2901 1323/729 +f 1319/725 1323/729 344/2901 +f 21/2818 1257/646 933/243 +f 1324/730 933/243 1257/646 +f 344/2901 1322/728 1317/724 +f 1324/730 1317/724 1322/728 +f 1328/736 70/2902 1329/734 +f 1325/733 1329/734 70/2902 +f 1326/732 347/2903 1329/734 +f 1327/737 1329/734 347/2903 +f 69/2887 1250/637 1331/740 +f 1332/739 1331/740 1250/637 +f 347/2903 1326/732 1330/738 +f 1332/739 1330/738 1326/732 +f 1031/355 1334/742 22/2817 +f 1259/648 22/2817 1334/742 +f 1330/738 1334/742 347/2903 +f 1333/741 347/2903 1334/742 +f 34/2836 1335/743 1027/350 +f 1336/744 1027/350 1335/743 +f 347/2903 1333/741 1327/737 +f 1336/744 1327/737 1333/741 +f 1340/750 71/2904 1341/745 +f 1337/746 1341/745 71/2904 +f 1339/751 1341/745 350/2905 +f 1338/747 350/2905 1341/745 +f 1344/753 1343/756 1328/755 +f 70/2906 1328/755 1343/756 +f 350/2905 1338/747 1342/752 +f 1344/753 1342/752 1338/747 +f 1045/759 1346/760 34/2907 +f 1335/761 34/2907 1346/760 +f 1345/758 350/2905 1346/760 +f 1342/752 1346/760 350/2905 +f 36/2908 1347/762 1041/764 +f 1348/763 1041/764 1347/762 +f 1348/763 1339/751 1345/758 +f 350/2905 1345/758 1339/751 +f 59/2909 1349/766 1352/770 +f 1353/765 1352/770 1349/766 +f 1351/771 1353/765 355/2910 +f 1350/767 355/2910 1353/765 +f 65/2911 1354/775 1356/776 +f 1357/773 1356/776 1354/775 +f 355/2910 1350/767 1355/772 +f 1357/773 1355/772 1350/767 +f 1358/779 1361/780 39/2912 +f 1360/781 39/2912 1361/780 +f 1355/772 1361/780 355/2910 +f 1359/778 355/2910 1361/780 +f 38/2847 1362/783 1363/784 +f 1364/782 1363/784 1362/783 +f 355/2910 1359/778 1351/771 +f 1364/782 1351/771 1359/778 +f 1368/790 60/2913 1369/787 +f 1365/785 1369/787 60/2913 +f 358/2914 1367/789 1366/788 +f 1369/787 1366/788 1367/789 +f 1372/793 1371/794 1352/770 +f 59/2909 1352/770 1371/794 +f 1370/792 358/2914 1372/793 +f 1366/788 1372/793 358/2914 +f 38/2847 1073/409 1362/783 +f 1374/795 1362/783 1073/409 +f 1374/795 1373/796 1370/792 +f 358/2914 1370/792 1373/796 +f 1375/798 1376/797 42/2846 +f 1068/404 42/2846 1376/797 +f 1373/796 1376/797 358/2914 +f 1367/789 358/2914 1376/797 +f 1380/804 79/2915 1381/799 +f 1377/800 1381/799 79/2915 +f 1379/805 1381/799 361/2916 +f 1378/801 361/2916 1381/799 +f 1383/808 78/2898 1384/806 +f 1304/704 1384/806 78/2898 +f 361/2916 1378/801 1382/807 +f 1384/806 1382/807 1378/801 +f 20/2799 809/94 1313/717 +f 1386/810 1313/717 809/94 +f 1385/809 361/2916 1386/810 +f 1382/807 1386/810 361/2916 +f 19/2798 1387/812 804/89 +f 1388/811 804/89 1387/812 +f 1388/811 1379/805 1385/809 +f 361/2916 1385/809 1379/805 +f 68/2897 1389/816 1292/690 +f 1392/814 1292/690 1389/816 +f 364/2917 1391/817 1390/813 +f 1392/814 1390/813 1391/817 +f 1393/820 1396/821 58/2918 +f 1395/822 58/2918 1396/821 +f 1394/819 364/2917 1396/821 +f 1390/813 1396/821 364/2917 +f 11/2790 776/54 1398/825 +f 1399/824 1398/825 776/54 +f 364/2917 1394/819 1397/823 +f 1399/824 1397/823 1394/819 +f 770/48 12/2789 1400/826 +f 1297/696 1400/826 12/2789 +f 1397/823 1400/826 364/2917 +f 1391/817 364/2917 1400/826 +f 1404/828 1393/820 1401/830 +f 58/2918 1401/830 1393/820 +f 367/2919 1403/831 1402/827 +f 1404/828 1402/827 1403/831 +f 1405/834 1408/835 61/2920 +f 1407/836 61/2920 1408/835 +f 1406/833 367/2919 1408/835 +f 1402/827 1408/835 367/2919 +f 23/2794 793/74 1410/839 +f 1411/838 1410/839 793/74 +f 367/2919 1406/833 1409/837 +f 1411/838 1409/837 1406/833 +f 1398/825 1412/840 11/2790 +f 789/71 11/2790 1412/840 +f 1409/837 1412/840 367/2919 +f 1403/831 367/2919 1412/840 +f 1413/844 1416/842 61/2920 +f 1405/834 61/2920 1416/842 +f 370/2921 1415/845 1414/841 +f 1416/842 1414/841 1415/845 +f 1420/847 1419/850 1417/849 +f 62/2922 1417/849 1419/850 +f 370/2921 1414/841 1418/846 +f 1420/847 1418/846 1414/841 +f 35/2835 1025/348 1422/853 +f 1423/852 1422/853 1025/348 +f 1421/851 370/2921 1423/852 +f 1418/846 1423/852 370/2921 +f 1410/839 1424/854 23/2794 +f 1019/339 23/2794 1424/854 +f 1421/851 1424/854 370/2921 +f 1415/845 370/2921 1424/854 +f 1425/857 1428/858 62/2923 +f 1417/860 62/2923 1428/858 +f 1427/861 1428/858 373/2924 +f 1426/856 373/2924 1428/858 +f 1429/864 1432/865 63/2925 +f 1431/866 63/2925 1432/865 +f 373/2924 1426/856 1430/863 +f 1432/865 1430/863 1426/856 +f 1435/868 1434/869 1053/385 +f 40/2843 1053/385 1434/869 +f 1433/867 373/2924 1435/868 +f 1430/863 1435/868 373/2924 +f 35/2837 1422/871 1047/379 +f 1436/870 1047/379 1422/871 +f 1436/870 1427/861 1433/867 +f 373/2924 1433/867 1427/861 +f 1440/873 1429/864 1437/875 +f 63/2925 1437/875 1429/864 +f 376/2926 1439/876 1438/872 +f 1440/873 1438/872 1439/876 +f 1441/879 1444/880 64/2927 +f 1443/881 64/2927 1444/880 +f 1438/872 1444/880 376/2926 +f 1442/878 376/2926 1444/880 +f 41/2844 1057/390 1446/884 +f 1447/883 1446/884 1057/390 +f 376/2926 1442/878 1445/882 +f 1447/883 1445/882 1442/878 +f 1434/869 1448/885 40/2843 +f 1051/383 40/2843 1448/885 +f 1445/882 1448/885 376/2926 +f 1439/876 376/2926 1448/885 +f 1452/886 1441/879 1449/887 +f 64/2927 1449/887 1441/879 +f 1451/890 1452/886 378/2928 +f 1450/888 378/2928 1452/886 +f 1455/892 1454/893 1368/790 +f 60/2913 1368/790 1454/893 +f 378/2928 1450/888 1453/891 +f 1455/892 1453/891 1450/888 +f 1070/406 1457/895 42/2846 +f 1375/798 42/2846 1457/895 +f 1453/891 1457/895 378/2928 +f 1456/894 378/2928 1457/895 +f 41/2844 1446/884 1065/400 +f 1458/896 1065/400 1446/884 +f 1458/896 1451/890 1456/894 +f 378/2928 1456/894 1451/890 +f 1462/897 1461/899 1340/750 +f 71/2904 1340/750 1461/899 +f 381/2929 1460/901 1459/898 +f 1462/897 1459/898 1460/901 +f 1347/762 36/2908 1464/902 +f 1204/903 1464/902 36/2908 +f 381/2929 1459/898 1463/904 +f 1464/902 1463/904 1459/898 +f 53/2930 1214/909 1199/910 +f 1466/907 1199/910 1214/909 +f 381/2929 1463/904 1465/906 +f 1466/907 1465/906 1463/904 +f 1467/913 1469/914 52/2931 +f 1207/915 52/2931 1469/914 +f 381/2929 1465/906 1468/912 +f 1469/914 1468/912 1465/906 +f 1470/916 1472/917 72/2932 +f 1471/918 72/2932 1472/917 +f 381/2929 1468/912 1460/901 +f 1472/917 1460/901 1468/912 +f 38/2847 1363/784 1191/565 +f 1475/919 1191/565 1363/784 +f 1475/919 1473/920 1474/921 +f 383/2933 1474/921 1473/920 +f 39/2912 1476/925 1358/779 +f 1478/923 1358/779 1476/925 +f 1478/923 1477/922 1473/920 +f 383/2933 1473/920 1477/922 +f 1197/571 1480/926 51/2875 +f 1479/927 51/2875 1480/926 +f 1477/922 1480/926 383/2933 +f 1474/921 383/2933 1480/926 +f 1485/931 1484/933 1481/930 +f 85/2934 1481/930 1484/933 +f 1483/934 1485/931 388/2935 +f 1482/929 388/2935 1485/931 +f 1489/936 1488/939 1486/938 +f 83/2936 1486/938 1488/939 +f 388/2935 1482/929 1487/935 +f 1489/936 1487/935 1482/929 +f 1490/942 1493/943 84/2937 +f 1492/944 84/2937 1493/943 +f 1487/935 1493/943 388/2935 +f 1491/941 388/2935 1493/943 +f 1496/945 1495/947 1494/946 +f 82/2938 1494/946 1495/947 +f 388/2935 1491/941 1483/934 +f 1496/945 1483/934 1491/941 +f 1497/949 1501/948 92/2939 +f 1500/953 92/2939 1501/948 +f 1499/954 1501/948 393/2940 +f 1498/950 393/2940 1501/948 +f 1505/956 1504/959 1502/958 +f 89/2941 1502/958 1504/959 +f 393/2940 1498/950 1503/955 +f 1505/956 1503/955 1498/950 +f 1509/961 1508/964 1506/963 +f 88/2942 1506/963 1508/964 +f 1507/960 393/2940 1509/961 +f 1503/955 1509/961 393/2940 +f 93/2943 1510/966 1511/967 +f 1512/965 1511/967 1510/966 +f 1512/965 1499/954 1507/960 +f 393/2940 1507/960 1499/954 +f 93/2943 1513/968 1516/972 +f 1517/970 1516/972 1513/968 +f 1517/970 1514/971 1515/974 +f 398/2944 1515/974 1514/971 +f 1521/975 1520/979 1518/976 +f 86/2945 1518/976 1520/979 +f 1514/971 1521/975 398/2944 +f 1519/977 398/2944 1521/975 +f 1525/981 1524/984 1522/983 +f 87/2946 1522/983 1524/984 +f 398/2944 1519/977 1523/980 +f 1525/981 1523/980 1519/977 +f 1526/985 1528/986 94/2947 +f 1527/987 94/2947 1528/986 +f 1515/974 398/2944 1528/986 +f 1523/980 1528/986 398/2944 +f 89/2941 1529/990 1502/958 +f 1532/991 1502/958 1529/990 +f 1530/989 402/2948 1532/991 +f 1531/992 1532/991 402/2948 +f 1535/997 90/2949 1536/994 +f 1533/996 1536/994 90/2949 +f 1530/989 1536/994 402/2948 +f 1534/993 402/2948 1536/994 +f 1539/1002 91/2950 1540/998 +f 1537/999 1540/998 91/2950 +f 1534/993 1540/998 402/2948 +f 1538/1000 402/2948 1540/998 +f 1542/1003 1541/1004 1508/964 +f 88/2942 1508/964 1541/1004 +f 402/2948 1538/1000 1531/992 +f 1542/1003 1531/992 1538/1000 +f 1543/1007 1546/1008 90/2949 +f 1533/996 90/2949 1546/1008 +f 1544/1006 405/2951 1546/1008 +f 1545/1009 1546/1008 405/2951 +f 1524/984 1549/1011 87/2946 +f 1548/1012 87/2946 1549/1011 +f 1547/1010 405/2951 1549/1011 +f 1544/1006 1549/1011 405/2951 +f 1518/976 86/2945 1552/1014 +f 1550/1016 1552/1014 86/2945 +f 405/2951 1547/1010 1551/1013 +f 1552/1014 1551/1013 1547/1010 +f 1554/1017 1553/1018 1539/1002 +f 91/2950 1539/1002 1553/1018 +f 1545/1009 405/2951 1554/1017 +f 1551/1013 1554/1017 405/2951 +f 92/2939 1500/953 1557/1022 +f 1558/1020 1557/1022 1500/953 +f 408/2952 1556/1023 1555/1019 +f 1558/1020 1555/1019 1556/1023 +f 93/2943 1516/972 1510/966 +f 1560/1025 1510/966 1516/972 +f 1555/1019 1560/1025 408/2952 +f 1559/1024 408/2952 1560/1025 +f 1561/1028 1563/1029 94/2947 +f 1526/985 94/2947 1563/1029 +f 1562/1027 408/2952 1563/1029 +f 1559/1024 1563/1029 408/2952 +f 95/2953 1564/1031 1565/1032 +f 1566/1030 1565/1032 1564/1031 +f 408/2952 1562/1027 1556/1023 +f 1566/1030 1556/1023 1562/1027 +f 1570/1034 1569/1039 1557/1036 +f 92/2954 1557/1036 1569/1039 +f 411/2955 1568/1037 1567/1033 +f 1570/1034 1567/1033 1568/1037 +f 1571/1042 1573/1043 95/2956 +f 1564/1044 95/2956 1573/1043 +f 411/2955 1567/1033 1572/1041 +f 1573/1043 1572/1041 1567/1033 +f 55/2886 1241/627 1575/1047 +f 1576/1046 1575/1047 1241/627 +f 411/2955 1572/1041 1574/1045 +f 1576/1046 1574/1045 1572/1041 +f 1231/615 1578/1049 54/2884 +f 1235/621 54/2884 1578/1049 +f 1574/1045 1578/1049 411/2955 +f 1577/1048 411/2955 1578/1049 +f 51/2883 1579/1051 1226/608 +f 1580/1050 1226/608 1579/1051 +f 411/2955 1577/1048 1568/1037 +f 1580/1050 1568/1037 1577/1048 +f 94/2957 1581/1052 1561/1056 +f 1584/1054 1561/1056 1581/1052 +f 1584/1054 1582/1055 1583/1058 +f 413/2958 1583/1058 1582/1055 +f 1586/1061 52/2877 1587/1059 +f 1210/585 1587/1059 52/2877 +f 1585/1060 413/2958 1587/1059 +f 1582/1055 1587/1059 413/2958 +f 1244/630 1589/1063 56/2881 +f 1220/599 56/2881 1589/1063 +f 413/2958 1585/1060 1588/1062 +f 1589/1063 1588/1062 1585/1060 +f 1575/1047 1591/1064 55/2886 +f 1239/625 55/2886 1591/1064 +f 413/2958 1588/1062 1590/1065 +f 1591/1064 1590/1065 1588/1062 +f 1571/1042 95/2956 1592/1067 +f 1565/1066 1592/1067 95/2956 +f 1590/1065 1592/1067 413/2958 +f 1583/1058 413/2958 1592/1067 +f 1593/1070 1596/1071 87/2959 +f 1522/1073 87/2959 1596/1071 +f 416/2960 1595/1074 1594/1069 +f 1596/1071 1594/1069 1595/1074 +f 1597/1077 1600/1078 73/2961 +f 1599/1079 73/2961 1600/1078 +f 416/2960 1594/1069 1598/1076 +f 1600/1078 1598/1076 1594/1069 +f 72/2932 1471/918 1602/1082 +f 1603/1081 1602/1082 1471/918 +f 416/2960 1598/1076 1601/1080 +f 1603/1081 1601/1080 1598/1076 +f 1605/1083 1467/913 1586/1084 +f 52/2931 1586/1084 1467/913 +f 416/2960 1601/1080 1604/1085 +f 1605/1083 1604/1085 1601/1080 +f 94/2962 1527/1087 1581/1089 +f 1606/1088 1581/1089 1527/1087 +f 1606/1088 1595/1074 1604/1085 +f 416/2960 1604/1085 1595/1074 +f 1611/1091 1610/1096 1607/1093 +f 66/2963 1607/1093 1610/1096 +f 420/2964 1609/1094 1608/1090 +f 1611/1091 1608/1090 1609/1094 +f 1614/1098 1613/1101 1535/1100 +f 90/2965 1535/1100 1613/1101 +f 420/2964 1608/1090 1612/1097 +f 1614/1098 1612/1097 1608/1090 +f 1615/1104 1617/1105 89/2966 +f 1529/1106 89/2966 1617/1105 +f 420/2964 1612/1097 1616/1103 +f 1617/1105 1616/1103 1612/1097 +f 39/2912 1360/781 1619/1109 +f 1620/1108 1619/1109 1360/781 +f 420/2964 1616/1103 1618/1107 +f 1620/1108 1618/1107 1616/1103 +f 1621/1110 1622/1111 65/2911 +f 1354/775 65/2911 1622/1111 +f 1618/1107 1622/1111 420/2964 +f 1609/1094 420/2964 1622/1111 +f 73/2961 1599/1079 1625/1114 +f 1626/1113 1625/1114 1599/1079 +f 1626/1113 1623/1112 1624/1116 +f 422/2967 1624/1116 1623/1112 +f 87/2959 1548/1117 1593/1070 +f 1628/1119 1593/1070 1548/1117 +f 422/2967 1623/1112 1627/1120 +f 1628/1119 1627/1120 1623/1112 +f 1630/1122 1543/1125 1613/1124 +f 90/2968 1613/1124 1543/1125 +f 422/2967 1627/1120 1629/1121 +f 1630/1122 1629/1121 1627/1120 +f 66/2969 1631/1127 1607/1128 +f 1632/1126 1607/1128 1631/1127 +f 1624/1116 422/2967 1632/1126 +f 1629/1121 1632/1126 422/2967 +f 1619/1109 1635/1130 39/2912 +f 1476/925 39/2912 1635/1130 +f 1634/1131 1635/1130 423/2970 +f 1633/1129 423/2970 1635/1130 +f 1637/1135 1615/1104 1504/1134 +f 89/2966 1504/1134 1615/1104 +f 423/2970 1633/1129 1636/1133 +f 1637/1135 1636/1133 1633/1129 +f 92/2971 1569/1139 1497/1140 +f 1639/1137 1497/1140 1569/1139 +f 423/2970 1636/1133 1638/1136 +f 1639/1137 1638/1136 1636/1133 +f 51/2875 1479/927 1579/1142 +f 1640/1141 1579/1142 1479/927 +f 423/2970 1638/1136 1634/1131 +f 1640/1141 1634/1131 1638/1136 +f 1506/963 88/2942 1644/1143 +f 1641/1144 1644/1143 88/2942 +f 1643/1147 1644/1143 426/2972 +f 1642/1145 426/2972 1644/1143 +f 1488/939 1647/1149 83/2936 +f 1646/1150 83/2936 1647/1149 +f 1642/1145 1647/1149 426/2972 +f 1645/1148 426/2972 1647/1149 +f 1648/1153 1650/1154 85/2934 +f 1481/930 85/2934 1650/1154 +f 1649/1152 426/2972 1650/1154 +f 1645/1148 1650/1154 426/2972 +f 93/2943 1511/967 1651/1156 +f 1652/1155 1651/1156 1511/967 +f 426/2972 1649/1152 1643/1147 +f 1652/1155 1643/1147 1649/1152 +f 91/2950 1653/1157 1537/999 +f 1656/1159 1537/999 1653/1157 +f 1656/1159 1654/1160 1655/1161 +f 428/2973 1655/1161 1654/1160 +f 1492/944 1659/1163 84/2937 +f 1658/1164 84/2937 1659/1163 +f 1654/1160 1659/1163 428/2973 +f 1657/1162 428/2973 1659/1163 +f 1646/1150 1661/1166 83/2936 +f 1486/938 83/2936 1661/1166 +f 1657/1162 1661/1166 428/2973 +f 1660/1165 428/2973 1661/1166 +f 1541/1004 1662/1167 88/2942 +f 1641/1144 88/2942 1662/1167 +f 1662/1167 1655/1161 1660/1165 +f 428/2973 1660/1165 1655/1161 +f 86/2945 1663/1169 1550/1016 +f 1666/1168 1550/1016 1663/1169 +f 1665/1172 1666/1168 430/2974 +f 1664/1170 430/2974 1666/1168 +f 1668/1175 82/2938 1669/1174 +f 1495/947 1669/1174 82/2938 +f 1664/1170 1669/1174 430/2974 +f 1667/1173 430/2974 1669/1174 +f 1658/1164 1671/1177 84/2937 +f 1490/942 84/2937 1671/1177 +f 1670/1176 430/2974 1671/1177 +f 1667/1173 1671/1177 430/2974 +f 91/2950 1553/1018 1653/1157 +f 1672/1178 1653/1157 1553/1018 +f 1672/1178 1665/1172 1670/1176 +f 430/2974 1670/1176 1665/1172 +f 93/2943 1651/1156 1513/968 +f 1675/1179 1513/968 1651/1156 +f 431/2975 1674/1181 1673/1180 +f 1675/1179 1673/1180 1674/1181 +f 1484/933 1677/1183 85/2934 +f 1648/1153 85/2934 1677/1183 +f 1673/1180 1677/1183 431/2975 +f 1676/1182 431/2975 1677/1183 +f 1668/1175 1679/1185 82/2938 +f 1494/946 82/2938 1679/1185 +f 1678/1184 431/2975 1679/1185 +f 1676/1182 1679/1185 431/2975 +f 1520/979 1680/1186 86/2945 +f 1663/1169 86/2945 1680/1186 +f 1674/1181 431/2975 1680/1186 +f 1678/1184 1680/1186 431/2975 +f 14/2976 763/1190 1683/1191 +f 1684/1188 1683/1191 763/1190 +f 1684/1188 1681/1187 1682/1193 +f 435/2977 1682/1193 1681/1187 +f 1687/1195 759/1198 1685/1197 +f 13/2978 1685/1197 759/1198 +f 435/2977 1681/1187 1686/1194 +f 1687/1195 1686/1194 1681/1187 +f 1688/1202 1691/1200 97/2979 +f 1690/1203 97/2979 1691/1200 +f 1689/1199 435/2977 1691/1200 +f 1686/1194 1691/1200 435/2977 +f 1692/1204 1694/1205 98/2980 +f 1693/1206 98/2980 1694/1205 +f 1682/1193 435/2977 1694/1205 +f 1689/1199 1694/1205 435/2977 +f 1685/1197 13/2978 1697/1210 +f 1311/1209 1697/1210 13/2978 +f 1696/1211 1697/1210 438/2981 +f 1695/1208 438/2981 1697/1210 +f 1700/1213 1306/1216 1698/1215 +f 74/2982 1698/1215 1306/1216 +f 438/2981 1695/1208 1699/1212 +f 1700/1213 1699/1212 1695/1208 +f 1701/1219 1704/1220 100/2983 +f 1703/1221 100/2983 1704/1220 +f 1699/1212 1704/1220 438/2981 +f 1702/1218 438/2981 1704/1220 +f 97/2979 1690/1203 1705/1223 +f 1706/1222 1705/1223 1690/1203 +f 438/2981 1702/1218 1696/1211 +f 1706/1222 1696/1211 1702/1218 +f 67/2984 1290/1227 1709/1228 +f 1710/1225 1709/1228 1290/1227 +f 442/2985 1708/1230 1707/1224 +f 1710/1225 1707/1224 1708/1230 +f 1711/1233 1713/1234 10/2986 +f 1299/1235 10/2986 1713/1234 +f 1707/1224 1713/1234 442/2985 +f 1712/1232 442/2985 1713/1234 +f 96/2987 1714/1239 1716/1240 +f 1717/1237 1716/1240 1714/1239 +f 442/2985 1712/1232 1715/1236 +f 1717/1237 1715/1236 1712/1232 +f 1718/1241 1720/1242 99/2988 +f 1719/1243 99/2988 1720/1242 +f 1715/1236 1720/1242 442/2985 +f 1708/1230 442/2985 1720/1242 +f 10/2986 746/1245 1711/1233 +f 1723/1244 1711/1233 746/1245 +f 1721/1246 444/2989 1723/1244 +f 1722/1248 1723/1244 444/2989 +f 740/1251 14/2976 1725/1249 +f 1683/1191 1725/1249 14/2976 +f 1725/1249 1724/1250 1721/1246 +f 444/2989 1721/1246 1724/1250 +f 1692/1204 98/2980 1728/1252 +f 1726/1253 1728/1252 98/2980 +f 1724/1250 1728/1252 444/2989 +f 1727/1254 444/2989 1728/1252 +f 1729/1257 96/2987 1730/1256 +f 1716/1240 1730/1256 96/2987 +f 444/2989 1727/1254 1722/1248 +f 1730/1256 1722/1248 1727/1254 +f 1734/1261 1701/1219 1731/1260 +f 100/2983 1731/1260 1701/1219 +f 447/2990 1733/1262 1732/1259 +f 1734/1261 1732/1259 1733/1262 +f 75/2991 1735/1265 1737/1267 +f 1738/1266 1737/1267 1735/1265 +f 1732/1259 1738/1266 447/2990 +f 1736/1264 447/2990 1738/1266 +f 98/2980 1693/1206 1740/1270 +f 1741/1269 1740/1270 1693/1206 +f 447/2990 1736/1264 1739/1268 +f 1741/1269 1739/1268 1736/1264 +f 1688/1202 97/2979 1742/1271 +f 1705/1223 1742/1271 97/2979 +f 1739/1268 1742/1271 447/2990 +f 1733/1262 447/2990 1742/1271 +f 75/2991 1743/1273 1735/1265 +f 1746/1272 1735/1265 1743/1273 +f 1745/1276 1746/1272 449/2992 +f 1744/1274 449/2992 1746/1272 +f 1749/1278 1748/1279 1719/1243 +f 99/2988 1719/1243 1748/1279 +f 449/2992 1744/1274 1747/1277 +f 1749/1278 1747/1277 1744/1274 +f 1729/1257 1751/1281 96/2987 +f 1714/1239 96/2987 1751/1281 +f 1747/1277 1751/1281 449/2992 +f 1750/1280 449/2992 1751/1281 +f 98/2980 1740/1270 1726/1253 +f 1752/1282 1726/1253 1740/1270 +f 449/2992 1750/1280 1745/1276 +f 1752/1282 1745/1276 1750/1280 +f 1757/1284 1756/1287 1753/1286 +f 101/2993 1753/1286 1756/1287 +f 1757/1284 1754/1283 1755/1289 +f 453/2994 1755/1289 1754/1283 +f 1758/1292 1761/1293 102/2995 +f 1760/1294 102/2995 1761/1293 +f 1754/1283 1761/1293 453/2994 +f 1759/1291 453/2994 1761/1293 +f 1762/1295 1764/1296 103/2996 +f 1763/1297 103/2996 1764/1296 +f 1759/1291 1764/1296 453/2994 +f 1755/1289 453/2994 1764/1296 +f 1768/1299 1767/1302 1756/1287 +f 101/2993 1756/1287 1767/1302 +f 456/2997 1766/1300 1765/1298 +f 1768/1299 1765/1298 1766/1300 +f 103/2996 1769/1306 1762/1295 +f 1771/1304 1762/1295 1769/1306 +f 456/2997 1765/1298 1770/1303 +f 1771/1304 1770/1303 1765/1298 +f 806/91 1774/1308 19/2798 +f 1773/1309 19/2798 1774/1308 +f 1770/1303 1774/1308 456/2997 +f 1772/1307 456/2997 1774/1308 +f 27/2797 881/180 800/84 +f 1776/1311 800/84 881/180 +f 456/2997 1772/1307 1775/1310 +f 1776/1311 1775/1310 1772/1307 +f 875/174 8/2810 1778/1312 +f 1777/1313 1778/1312 8/2810 +f 456/2997 1775/1310 1766/1300 +f 1778/1312 1766/1300 1775/1310 +f 1767/1302 1781/1315 101/2993 +f 1753/1286 101/2993 1781/1315 +f 458/2998 1780/1316 1779/1314 +f 1781/1315 1779/1314 1780/1316 +f 8/2810 989/308 1777/1313 +f 1783/1318 1777/1313 989/308 +f 458/2998 1779/1314 1782/1317 +f 1783/1318 1782/1317 1779/1314 +f 1785/1320 986/305 942/252 +f 4/2823 942/252 986/305 +f 458/2998 1782/1317 1784/1319 +f 1785/1320 1784/1319 1782/1317 +f 26/2827 1786/1321 952/264 +f 1788/1323 952/264 1786/1321 +f 458/2998 1784/1319 1787/1324 +f 1788/1323 1787/1324 1784/1319 +f 102/2995 1760/1294 1789/1326 +f 1790/1325 1789/1326 1760/1294 +f 458/2998 1787/1324 1780/1316 +f 1790/1325 1780/1316 1787/1324 +f 1795/1328 1794/1333 1791/1330 +f 104/2999 1791/1330 1794/1333 +f 461/3000 1793/1331 1792/1327 +f 1795/1328 1792/1327 1793/1331 +f 1789/1326 1798/1335 102/2995 +f 1797/1336 102/2995 1798/1335 +f 1792/1327 1798/1335 461/3000 +f 1796/1334 461/3000 1798/1335 +f 1786/1321 26/2827 1800/1337 +f 1284/678 1800/1337 26/2827 +f 1800/1337 1799/1338 1796/1334 +f 461/3000 1796/1334 1799/1338 +f 1279/674 81/2894 1802/1339 +f 1801/1340 1802/1339 81/2894 +f 1799/1338 1802/1339 461/3000 +f 1793/1331 461/3000 1802/1339 +f 1805/1344 79/2915 1806/1342 +f 1380/804 1806/1342 79/2915 +f 1804/1345 1806/1342 464/3001 +f 1803/1341 464/3001 1806/1342 +f 19/2798 1773/1309 1387/812 +f 1808/1347 1387/812 1773/1309 +f 464/3001 1803/1341 1807/1346 +f 1808/1347 1807/1346 1803/1341 +f 1809/1350 1811/1351 103/2996 +f 1769/1306 103/2996 1811/1351 +f 1807/1346 1811/1351 464/3001 +f 1810/1349 464/3001 1811/1351 +f 1814/1352 1813/1354 1812/1353 +f 105/3002 1812/1353 1813/1354 +f 464/3001 1810/1349 1804/1345 +f 1814/1352 1804/1345 1810/1349 +f 1763/1297 1818/1356 103/2996 +f 1817/1358 103/2996 1818/1356 +f 1815/1355 468/3003 1818/1356 +f 1816/1359 1818/1356 468/3003 +f 102/2995 1819/1361 1758/1292 +f 1821/1360 1758/1292 1819/1361 +f 1821/1360 1820/1362 1815/1355 +f 468/3003 1815/1355 1820/1362 +f 1825/1365 1824/1368 1822/1367 +f 106/3004 1822/1367 1824/1368 +f 468/3003 1820/1362 1823/1364 +f 1825/1365 1823/1364 1820/1362 +f 1828/1370 1827/1371 1826/1369 +f 107/3005 1826/1369 1827/1371 +f 1828/1370 1816/1359 1823/1364 +f 468/3003 1823/1364 1816/1359 +f 102/2995 1797/1336 1819/1361 +f 1831/1373 1819/1361 1797/1336 +f 471/3006 1830/1374 1829/1372 +f 1831/1373 1829/1372 1830/1374 +f 1832/1377 1834/1378 104/2999 +f 1791/1330 104/2999 1834/1378 +f 1829/1372 1834/1378 471/3006 +f 1833/1376 471/3006 1834/1378 +f 108/3007 1835/1382 1837/1383 +f 1838/1380 1837/1383 1835/1382 +f 471/3006 1833/1376 1836/1379 +f 1838/1380 1836/1379 1833/1376 +f 1824/1368 1840/1384 106/3004 +f 1839/1385 106/3004 1840/1384 +f 1836/1379 1840/1384 471/3006 +f 1830/1374 471/3006 1840/1384 +f 1843/1389 105/3002 1844/1386 +f 1813/1354 1844/1386 105/3002 +f 1842/1390 1844/1386 474/3008 +f 1841/1387 474/3008 1844/1386 +f 1846/1392 1809/1350 1817/1358 +f 103/2996 1817/1358 1809/1350 +f 474/3008 1841/1387 1845/1391 +f 1846/1392 1845/1391 1841/1387 +f 1847/1395 1849/1396 107/3005 +f 1826/1369 107/3005 1849/1396 +f 1848/1394 474/3008 1849/1396 +f 1845/1391 1849/1396 474/3008 +f 109/3009 1850/1398 1851/1399 +f 1852/1397 1851/1399 1850/1398 +f 1852/1397 1842/1390 1848/1394 +f 474/3008 1848/1394 1842/1390 +f 1855/1401 1822/1367 1839/1385 +f 106/3004 1839/1385 1822/1367 +f 476/3010 1854/1402 1853/1400 +f 1855/1401 1853/1400 1854/1402 +f 1856/1404 1858/1403 108/3007 +f 1835/1382 108/3007 1858/1403 +f 1853/1400 1858/1403 476/3010 +f 1857/1405 476/3010 1858/1403 +f 1851/1399 1861/1408 109/3009 +f 1860/1409 109/3009 1861/1408 +f 1857/1405 1861/1408 476/3010 +f 1859/1407 476/3010 1861/1408 +f 1862/1410 1847/1395 1827/1371 +f 107/3005 1827/1371 1847/1395 +f 476/3010 1859/1407 1854/1402 +f 1862/1410 1854/1402 1859/1407 +f 1863/1413 1867/1414 115/3011 +f 1866/1416 115/3011 1867/1414 +f 481/3012 1865/1415 1864/1412 +f 1867/1414 1864/1412 1865/1415 +f 125/3013 1868/1420 1870/1422 +f 1871/1421 1870/1422 1868/1420 +f 1869/1419 481/3012 1871/1421 +f 1864/1412 1871/1421 481/3012 +f 1875/1425 1874/1427 1872/1423 +f 119/3014 1872/1423 1874/1427 +f 481/3012 1869/1419 1873/1426 +f 1875/1425 1873/1426 1869/1419 +f 1878/1428 1877/1430 1876/1429 +f 123/3015 1876/1429 1877/1430 +f 1873/1426 1878/1428 481/3012 +f 1865/1415 481/3012 1878/1428 +f 1882/1432 1881/1435 1866/1416 +f 115/3011 1866/1416 1881/1435 +f 485/3016 1880/1433 1879/1431 +f 1882/1432 1879/1431 1880/1433 +f 1883/1438 1885/1439 123/3015 +f 1876/1429 123/3015 1885/1439 +f 1884/1437 485/3016 1885/1439 +f 1879/1431 1885/1439 485/3016 +f 1889/1441 1888/1444 1886/1443 +f 122/3017 1886/1443 1888/1444 +f 485/3016 1884/1437 1887/1440 +f 1889/1441 1887/1440 1884/1437 +f 127/3018 1890/1445 1891/1447 +f 1892/1446 1891/1447 1890/1445 +f 1887/1440 1892/1446 485/3016 +f 1880/1433 485/3016 1892/1446 +f 110/3019 1893/1451 1896/1453 +f 1897/1449 1896/1453 1893/1451 +f 1895/1452 1897/1449 490/3020 +f 1894/1448 490/3020 1897/1449 +f 133/3021 1898/1458 1900/1459 +f 1901/1456 1900/1459 1898/1458 +f 490/3020 1894/1448 1899/1455 +f 1901/1456 1899/1455 1894/1448 +f 1902/1462 1905/1463 120/3022 +f 1904/1464 120/3022 1905/1463 +f 1899/1455 1905/1463 490/3020 +f 1903/1461 490/3020 1905/1463 +f 121/3023 1906/1466 1907/1467 +f 1908/1465 1907/1467 1906/1466 +f 490/3020 1903/1461 1895/1452 +f 1908/1465 1895/1452 1903/1461 +f 116/3024 1909/1471 1912/1472 +f 1913/1469 1912/1472 1909/1471 +f 494/3025 1911/1474 1910/1468 +f 1913/1469 1910/1468 1911/1474 +f 1914/1477 1917/1478 132/3026 +f 1916/1479 132/3026 1917/1478 +f 1910/1468 1917/1478 494/3025 +f 1915/1476 494/3025 1917/1478 +f 120/3022 1904/1464 1919/1482 +f 1920/1481 1919/1482 1904/1464 +f 494/3025 1915/1476 1918/1480 +f 1920/1481 1918/1480 1915/1476 +f 1921/1483 1922/1484 133/3021 +f 1898/1458 133/3021 1922/1484 +f 1918/1480 1922/1484 494/3025 +f 1911/1474 494/3025 1922/1484 +f 111/3027 1923/1487 1926/1489 +f 1927/1488 1926/1489 1923/1487 +f 499/3028 1925/1491 1924/1486 +f 1927/1488 1924/1486 1925/1491 +f 129/3029 1928/1495 1930/1496 +f 1931/1493 1930/1496 1928/1495 +f 1931/1493 1929/1492 1924/1486 +f 499/3028 1924/1486 1929/1492 +f 1935/1498 1934/1501 1932/1500 +f 128/3030 1932/1500 1934/1501 +f 499/3028 1929/1492 1933/1497 +f 1935/1498 1933/1497 1929/1492 +f 1936/1502 1938/1503 136/3031 +f 1937/1504 136/3031 1938/1503 +f 1933/1497 1938/1503 499/3028 +f 1925/1491 499/3028 1938/1503 +f 1939/1507 1942/1508 110/3019 +f 1893/1451 110/3019 1942/1508 +f 1941/1509 1942/1508 503/3032 +f 1940/1506 503/3032 1942/1508 +f 125/3013 1943/1513 1945/1514 +f 1946/1511 1945/1514 1943/1513 +f 503/3032 1940/1506 1944/1510 +f 1946/1511 1944/1510 1940/1506 +f 1947/1517 1950/1518 124/3033 +f 1949/1519 124/3033 1950/1518 +f 1944/1510 1950/1518 503/3032 +f 1948/1516 503/3032 1950/1518 +f 133/3021 1900/1459 1951/1521 +f 1952/1520 1951/1521 1900/1459 +f 503/3032 1948/1516 1941/1509 +f 1952/1520 1941/1509 1948/1516 +f 1956/1523 1863/1413 1953/1525 +f 115/3011 1953/1525 1863/1413 +f 506/3034 1955/1526 1954/1522 +f 1956/1523 1954/1522 1955/1526 +f 1957/1529 1960/1530 141/3035 +f 1959/1531 141/3035 1960/1530 +f 1954/1522 1960/1530 506/3034 +f 1958/1528 506/3034 1960/1530 +f 124/3033 1949/1519 1962/1534 +f 1963/1533 1962/1534 1949/1519 +f 506/3034 1958/1528 1961/1532 +f 1963/1533 1961/1532 1958/1528 +f 125/3013 1870/1422 1943/1513 +f 1964/1535 1943/1513 1870/1422 +f 1961/1532 1964/1535 506/3034 +f 1955/1526 506/3034 1964/1535 +f 1969/1537 1968/1541 1965/1539 +f 114/3036 1965/1539 1968/1541 +f 1967/1542 1969/1537 510/3037 +f 1966/1536 510/3037 1969/1537 +f 1970/1546 1973/1544 139/3038 +f 1972/1547 139/3038 1973/1544 +f 510/3037 1966/1536 1971/1543 +f 1973/1544 1971/1543 1966/1536 +f 1962/1534 1976/1549 124/3033 +f 1975/1550 124/3033 1976/1549 +f 1974/1548 510/3037 1976/1549 +f 1971/1543 1976/1549 510/3037 +f 141/3035 1977/1551 1957/1529 +f 1978/1552 1957/1529 1977/1551 +f 1978/1552 1967/1542 1974/1548 +f 510/3037 1974/1548 1967/1542 +f 1912/1472 1982/1554 116/3024 +f 1981/1556 116/3024 1982/1554 +f 1979/1553 512/3039 1982/1554 +f 1980/1557 1982/1554 512/3039 +f 133/3021 1951/1521 1921/1483 +f 1984/1559 1921/1483 1951/1521 +f 1983/1558 512/3039 1984/1559 +f 1979/1553 1984/1559 512/3039 +f 124/3033 1975/1550 1947/1517 +f 1986/1560 1947/1517 1975/1550 +f 1986/1560 1985/1561 1983/1558 +f 512/3039 1983/1558 1985/1561 +f 1988/1562 1970/1546 1987/1563 +f 139/3038 1987/1563 1970/1546 +f 1985/1561 1988/1562 512/3039 +f 1980/1557 512/3039 1988/1562 +f 1926/1489 1992/1565 111/3027 +f 1991/1567 111/3027 1992/1565 +f 1990/1568 1992/1565 516/3040 +f 1989/1564 516/3040 1992/1565 +f 136/3031 1993/1572 1936/1502 +f 1995/1570 1936/1502 1993/1572 +f 516/3040 1989/1564 1994/1569 +f 1995/1570 1994/1569 1989/1564 +f 1996/1575 1999/1576 126/3041 +f 1998/1577 126/3041 1999/1576 +f 1994/1569 1999/1576 516/3040 +f 1997/1574 516/3040 1999/1576 +f 127/3018 2000/1579 2001/1580 +f 2002/1578 2001/1580 2000/1579 +f 516/3040 1997/1574 1990/1568 +f 2002/1578 1990/1568 1997/1574 +f 2007/1582 2006/1585 2003/1584 +f 117/3042 2003/1584 2006/1585 +f 520/3043 2005/1587 2004/1581 +f 2007/1582 2004/1581 2005/1587 +f 2008/1590 2011/1591 138/3044 +f 2010/1592 138/3044 2011/1591 +f 2009/1589 520/3043 2011/1591 +f 2004/1581 2011/1591 520/3043 +f 126/3041 1998/1577 2013/1595 +f 2014/1594 2013/1595 1998/1577 +f 520/3043 2009/1589 2012/1593 +f 2014/1594 2012/1593 2009/1589 +f 2015/1596 2016/1597 136/3031 +f 1993/1572 136/3031 2016/1597 +f 2012/1593 2016/1597 520/3043 +f 2005/1587 520/3043 2016/1597 +f 1968/1541 2020/1598 114/3036 +f 2019/1601 114/3036 2020/1598 +f 2017/1599 523/3045 2020/1598 +f 2018/1600 2020/1598 523/3045 +f 2021/1603 2023/1605 141/3035 +f 1977/1551 141/3035 2023/1605 +f 523/3045 2017/1599 2022/1606 +f 2023/1605 2022/1606 2017/1599 +f 2013/1595 2026/1608 126/3041 +f 2025/1609 126/3041 2026/1608 +f 2022/1606 2026/1608 523/3045 +f 2024/1607 523/3045 2026/1608 +f 138/3044 2027/1611 2008/1590 +f 2028/1610 2008/1590 2027/1611 +f 523/3045 2024/1607 2018/1600 +f 2028/1610 2018/1600 2024/1607 +f 1881/1435 2031/1613 115/3011 +f 1953/1525 115/3011 2031/1613 +f 524/3046 2030/1614 2029/1612 +f 2031/1613 2029/1612 2030/1614 +f 127/3018 2001/1580 1890/1445 +f 2033/1616 1890/1445 2001/1580 +f 2032/1615 524/3046 2033/1616 +f 2029/1612 2033/1616 524/3046 +f 126/3041 2025/1609 1996/1575 +f 2035/1618 1996/1575 2025/1609 +f 524/3046 2032/1615 2034/1617 +f 2035/1618 2034/1617 2032/1615 +f 141/3035 1959/1531 2021/1603 +f 2036/1619 2021/1603 1959/1531 +f 2034/1617 2036/1619 524/3046 +f 2030/1614 524/3046 2036/1619 +f 2041/1621 2040/1624 2037/1623 +f 112/3047 2037/1623 2040/1624 +f 529/3048 2039/1626 2038/1620 +f 2041/1621 2038/1620 2039/1626 +f 140/3049 2042/1629 2044/1631 +f 2045/1630 2044/1631 2042/1629 +f 2043/1628 529/3048 2045/1630 +f 2038/1620 2045/1630 529/3048 +f 130/3050 2046/1635 2048/1636 +f 2049/1633 2048/1636 2046/1635 +f 2049/1633 2047/1632 2043/1628 +f 529/3048 2043/1628 2047/1632 +f 131/3051 2050/1638 2051/1639 +f 2052/1637 2051/1639 2050/1638 +f 2047/1632 2052/1637 529/3048 +f 2039/1626 529/3048 2052/1637 +f 2056/1644 118/3052 2057/1640 +f 2053/1641 2057/1640 118/3052 +f 533/3053 2055/1646 2054/1642 +f 2057/1640 2054/1642 2055/1646 +f 2061/1650 2060/1651 2058/1649 +f 142/3054 2058/1649 2060/1651 +f 2054/1642 2061/1650 533/3053 +f 2059/1648 533/3053 2061/1650 +f 130/3050 2048/1636 2063/1654 +f 2064/1653 2063/1654 2048/1636 +f 533/3053 2059/1648 2062/1652 +f 2064/1653 2062/1652 2059/1648 +f 2065/1655 2066/1656 140/3049 +f 2042/1629 140/3049 2066/1656 +f 2062/1652 2066/1656 533/3053 +f 2055/1646 533/3053 2066/1656 +f 2067/1659 2071/1660 113/3055 +f 2070/1662 113/3055 2071/1660 +f 2069/1663 2071/1660 538/3056 +f 2068/1658 538/3056 2071/1660 +f 135/3057 2072/1664 2074/1668 +f 2075/1666 2074/1668 2072/1664 +f 2075/1666 2073/1667 2068/1658 +f 538/3056 2068/1658 2073/1667 +f 2076/1671 2079/1672 134/3058 +f 2078/1673 134/3058 2079/1672 +f 2073/1667 2079/1672 538/3056 +f 2077/1670 538/3056 2079/1672 +f 137/3059 2080/1674 2081/1676 +f 2082/1675 2081/1676 2080/1674 +f 538/3056 2077/1670 2069/1663 +f 2082/1675 2069/1663 2077/1670 +f 118/3052 2083/1680 2053/1641 +f 2086/1678 2053/1641 2083/1680 +f 541/3060 2085/1681 2084/1677 +f 2086/1678 2084/1677 2085/1681 +f 2081/1676 2089/1683 137/3059 +f 2088/1684 137/3059 2089/1683 +f 2084/1677 2089/1683 541/3060 +f 2087/1682 541/3060 2089/1683 +f 134/3058 2090/1688 2076/1671 +f 2092/1686 2076/1671 2090/1688 +f 541/3060 2087/1682 2091/1685 +f 2092/1686 2091/1685 2087/1682 +f 2060/1651 2094/1689 142/3054 +f 2093/1690 142/3054 2094/1689 +f 2091/1685 2094/1689 541/3060 +f 2085/1681 541/3060 2094/1689 +f 2095/1693 2098/1694 114/3036 +f 1965/1539 114/3036 2098/1694 +f 2097/1695 2098/1694 544/3061 +f 2096/1692 544/3061 2098/1694 +f 118/3052 2056/1644 2100/1698 +f 2101/1697 2100/1698 2056/1644 +f 544/3061 2096/1692 2099/1696 +f 2101/1697 2099/1696 2096/1692 +f 2102/1701 2104/1702 140/3049 +f 2065/1655 140/3049 2104/1702 +f 2099/1696 2104/1702 544/3061 +f 2103/1700 544/3061 2104/1702 +f 139/3038 1972/1547 2105/1704 +f 2106/1703 2105/1704 1972/1547 +f 544/3061 2103/1700 2097/1695 +f 2106/1703 2097/1695 2103/1700 +f 138/3044 2010/1592 2109/1707 +f 2110/1705 2109/1707 2010/1592 +f 2110/1705 2107/1706 2108/1709 +f 547/3062 2108/1709 2107/1706 +f 2111/1711 2113/1710 117/3042 +f 2003/1584 117/3042 2113/1710 +f 2107/1706 2113/1710 547/3062 +f 2112/1712 547/3062 2113/1710 +f 2070/1662 2116/1715 113/3055 +f 2115/1716 113/3055 2116/1715 +f 547/3062 2112/1712 2114/1714 +f 2116/1715 2114/1714 2112/1712 +f 2117/1717 2118/1718 137/3059 +f 2080/1674 137/3059 2118/1718 +f 2108/1709 547/3062 2118/1718 +f 2114/1714 2118/1718 547/3062 +f 132/3026 1916/1479 2121/1721 +f 2122/1720 2121/1721 1916/1479 +f 2122/1720 2119/1719 2120/1723 +f 550/3063 2120/1723 2119/1719 +f 2123/1725 2125/1724 116/3024 +f 1909/1471 116/3024 2125/1724 +f 2119/1719 2125/1724 550/3063 +f 2124/1726 550/3063 2125/1724 +f 2128/1729 2127/1730 2040/1624 +f 112/3047 2040/1624 2127/1730 +f 550/3063 2124/1726 2126/1728 +f 2128/1729 2126/1728 2124/1726 +f 131/3051 2129/1731 2050/1638 +f 2130/1732 2050/1638 2129/1731 +f 2120/1723 550/3063 2130/1732 +f 2126/1728 2130/1732 550/3063 +f 137/3059 2088/1684 2117/1717 +f 2133/1734 2117/1717 2088/1684 +f 551/3064 2132/1735 2131/1733 +f 2133/1734 2131/1733 2132/1735 +f 2100/1698 2135/1737 118/3052 +f 2083/1680 118/3052 2135/1737 +f 2131/1733 2135/1737 551/3064 +f 2134/1736 551/3064 2135/1737 +f 114/3036 2019/1601 2095/1693 +f 2137/1739 2095/1693 2019/1601 +f 551/3064 2134/1736 2136/1738 +f 2137/1739 2136/1738 2134/1736 +f 2109/1707 2138/1740 138/3044 +f 2027/1611 138/3044 2138/1740 +f 2136/1738 2138/1740 551/3064 +f 2132/1735 551/3064 2138/1740 +f 2105/1704 2141/1742 139/3038 +f 1987/1563 139/3038 2141/1742 +f 2140/1743 2141/1742 552/3065 +f 2139/1741 552/3065 2141/1742 +f 140/3049 2044/1631 2102/1701 +f 2143/1745 2102/1701 2044/1631 +f 552/3065 2139/1741 2142/1744 +f 2143/1745 2142/1744 2139/1741 +f 2127/1730 2145/1747 112/3047 +f 2037/1623 112/3047 2145/1747 +f 2142/1744 2145/1747 552/3065 +f 2144/1746 552/3065 2145/1747 +f 116/3024 1981/1556 2123/1725 +f 2146/1748 2123/1725 1981/1556 +f 552/3065 2144/1746 2140/1743 +f 2146/1748 2140/1743 2144/1746 +f 132/3026 2121/1721 2149/1751 +f 2150/1749 2149/1751 2121/1721 +f 2148/1753 2150/1749 556/3066 +f 2147/1750 556/3066 2150/1749 +f 2153/1755 2129/1731 2151/1757 +f 131/3051 2151/1757 2129/1731 +f 556/3066 2147/1750 2152/1754 +f 2153/1755 2152/1754 2147/1750 +f 2154/1760 2157/1761 143/3067 +f 2156/1762 143/3067 2157/1761 +f 2155/1759 556/3066 2157/1761 +f 2152/1754 2157/1761 556/3066 +f 144/3068 2158/1763 2159/1765 +f 2160/1764 2159/1765 2158/1763 +f 2160/1764 2148/1753 2155/1759 +f 556/3066 2155/1759 2148/1753 +f 2159/1767 2164/1766 144/3069 +f 2163/1771 144/3069 2164/1766 +f 2162/1772 2164/1766 560/3070 +f 2161/1768 560/3070 2164/1766 +f 2167/1774 2154/1777 2165/1776 +f 143/3071 2165/1776 2154/1777 +f 560/3070 2161/1768 2166/1773 +f 2167/1774 2166/1773 2161/1768 +f 2168/1780 2171/1781 145/3072 +f 2170/1782 145/3072 2171/1781 +f 2169/1779 560/3070 2171/1781 +f 2166/1773 2171/1781 560/3070 +f 146/3073 2172/1784 2173/1785 +f 2174/1783 2173/1785 2172/1784 +f 560/3070 2169/1779 2162/1772 +f 2174/1783 2162/1772 2169/1779 +f 144/3069 2163/1771 2177/1788 +f 2178/1787 2177/1788 2163/1771 +f 564/3074 2176/1790 2175/1786 +f 2178/1787 2175/1786 2176/1790 +f 2179/1793 2181/1794 146/3073 +f 2172/1784 146/3073 2181/1794 +f 2175/1786 2181/1794 564/3074 +f 2180/1792 564/3074 2181/1794 +f 150/3075 2182/1798 2184/1799 +f 2185/1796 2184/1799 2182/1798 +f 564/3074 2180/1792 2183/1795 +f 2185/1796 2183/1795 2180/1792 +f 2186/1800 2188/1801 149/3076 +f 2187/1802 149/3076 2188/1801 +f 2183/1795 2188/1801 564/3074 +f 2176/1790 564/3074 2188/1801 +f 146/3073 2189/1806 2179/1793 +f 2192/1804 2179/1793 2189/1806 +f 568/3077 2191/1807 2190/1803 +f 2192/1804 2190/1803 2191/1807 +f 147/3078 2193/1811 2195/1812 +f 2196/1809 2195/1812 2193/1811 +f 2190/1803 2196/1809 568/3077 +f 2194/1808 568/3077 2196/1809 +f 2200/1814 2199/1817 2197/1816 +f 151/3079 2197/1816 2199/1817 +f 568/3077 2194/1808 2198/1813 +f 2200/1814 2198/1813 2194/1808 +f 2184/1799 2202/1818 150/3075 +f 2201/1819 150/3075 2202/1818 +f 2198/1813 2202/1818 568/3077 +f 2191/1807 568/3077 2202/1818 +f 2207/1821 2206/1826 2203/1823 +f 152/3080 2203/1823 2206/1826 +f 573/3081 2205/1824 2204/1820 +f 2207/1821 2204/1820 2205/1824 +f 2208/1830 2211/1828 155/3082 +f 2210/1831 155/3082 2211/1828 +f 573/3081 2204/1820 2209/1827 +f 2211/1828 2209/1827 2204/1820 +f 2212/1834 2215/1835 154/3083 +f 2214/1836 154/3083 2215/1835 +f 573/3081 2209/1827 2213/1833 +f 2215/1835 2213/1833 2209/1827 +f 2216/1837 2218/1838 157/3084 +f 2217/1839 157/3084 2218/1838 +f 573/3081 2213/1833 2205/1824 +f 2218/1838 2205/1824 2213/1833 +f 2223/1841 2222/1846 2219/1843 +f 153/3085 2219/1843 2222/1846 +f 578/3086 2221/1844 2220/1840 +f 2223/1841 2220/1840 2221/1844 +f 2224/1850 2227/1848 158/3087 +f 2226/1851 158/3087 2227/1848 +f 578/3086 2220/1840 2225/1847 +f 2227/1848 2225/1847 2220/1840 +f 2228/1854 2231/1855 156/3088 +f 2230/1856 156/3088 2231/1855 +f 2225/1847 2231/1855 578/3086 +f 2229/1853 578/3086 2231/1855 +f 2232/1857 2234/1858 159/3089 +f 2233/1859 159/3089 2234/1858 +f 578/3086 2229/1853 2221/1844 +f 2234/1858 2221/1844 2229/1853 +f 127/3090 2235/1862 2000/1865 +f 2238/1863 2000/1865 2235/1862 +f 2237/1866 2238/1863 581/3091 +f 2236/1861 581/3091 2238/1863 +f 2226/1851 2241/1868 158/3087 +f 2240/1869 158/3087 2241/1868 +f 581/3091 2236/1861 2239/1867 +f 2241/1868 2239/1867 2236/1861 +f 2242/1872 2244/1873 153/3085 +f 2219/1843 153/3085 2244/1873 +f 2239/1867 2244/1873 581/3091 +f 2243/1871 581/3091 2244/1873 +f 2246/1874 2245/1876 1991/1875 +f 111/3092 1991/1875 2245/1876 +f 581/3091 2243/1871 2237/1866 +f 2246/1874 2237/1866 2243/1871 +f 129/3093 2247/1880 2250/1881 +f 2251/1878 2250/1881 2247/1880 +f 585/3094 2249/1883 2248/1877 +f 2251/1878 2248/1877 2249/1883 +f 2233/1859 2254/1885 159/3089 +f 2253/1886 159/3089 2254/1885 +f 2248/1877 2254/1885 585/3094 +f 2252/1884 585/3094 2254/1885 +f 2255/1889 2257/1890 156/3088 +f 2228/1854 156/3088 2257/1890 +f 585/3094 2252/1884 2256/1888 +f 2257/1890 2256/1888 2252/1884 +f 122/3095 2258/1891 2259/1893 +f 2260/1892 2259/1893 2258/1891 +f 2256/1888 2260/1892 585/3094 +f 2249/1883 585/3094 2260/1892 +f 127/3090 1891/1897 2235/1862 +f 2263/1895 2235/1862 1891/1897 +f 586/3096 2262/1898 2261/1894 +f 2263/1895 2261/1894 2262/1898 +f 122/3095 2259/1893 1886/1901 +f 2265/1900 1886/1901 2259/1893 +f 2261/1894 2265/1900 586/3096 +f 2264/1899 586/3096 2265/1900 +f 2230/1856 2267/1903 156/3088 +f 2255/1889 156/3088 2267/1903 +f 586/3096 2264/1899 2266/1902 +f 2267/1903 2266/1902 2264/1899 +f 2240/1869 2268/1904 158/3087 +f 2224/1850 158/3087 2268/1904 +f 2266/1902 2268/1904 586/3096 +f 2262/1898 586/3096 2268/1904 +f 129/3093 1930/1906 2247/1880 +f 2271/1905 2247/1880 1930/1906 +f 2269/1907 587/3097 2271/1905 +f 2270/1909 2271/1905 587/3097 +f 2273/1911 1923/1912 2245/1876 +f 111/3092 2245/1876 1923/1912 +f 2273/1911 2272/1910 2269/1907 +f 587/3097 2269/1907 2272/1910 +f 2222/1846 2275/1914 153/3085 +f 2242/1872 153/3085 2275/1914 +f 2272/1910 2275/1914 587/3097 +f 2274/1913 587/3097 2275/1914 +f 2253/1886 2276/1915 159/3089 +f 2232/1857 159/3089 2276/1915 +f 587/3097 2274/1913 2270/1909 +f 2276/1915 2270/1909 2274/1913 +f 125/3098 1945/1918 2279/1921 +f 2280/1919 2279/1921 1945/1918 +f 2278/1922 2280/1919 590/3099 +f 2277/1917 590/3099 2280/1919 +f 2283/1924 1939/1927 2281/1926 +f 110/3100 2281/1926 1939/1927 +f 590/3099 2277/1917 2282/1923 +f 2283/1924 2282/1923 2277/1917 +f 2206/1826 2286/1929 152/3080 +f 2285/1930 152/3080 2286/1929 +f 2282/1923 2286/1929 590/3099 +f 2284/1928 590/3099 2286/1929 +f 2287/1932 2288/1931 157/3084 +f 2216/1837 157/3084 2288/1931 +f 590/3099 2284/1928 2278/1922 +f 2288/1931 2278/1922 2284/1928 +f 2289/1934 2292/1933 121/3101 +f 1906/1938 121/3101 2292/1933 +f 2291/1939 2292/1933 592/3102 +f 2290/1935 592/3102 2292/1933 +f 2210/1831 2295/1941 155/3082 +f 2294/1942 155/3082 2295/1941 +f 592/3102 2290/1935 2293/1940 +f 2295/1941 2293/1940 2290/1935 +f 2285/1930 2297/1944 152/3080 +f 2203/1823 152/3080 2297/1944 +f 2293/1940 2297/1944 592/3102 +f 2296/1943 592/3102 2297/1944 +f 2281/1926 110/3100 2298/1946 +f 1896/1945 2298/1946 110/3100 +f 2298/1946 2291/1939 2296/1943 +f 592/3102 2296/1943 2291/1939 +f 1874/1949 2302/1950 119/3103 +f 2301/1952 119/3103 2302/1950 +f 2300/1953 2302/1950 594/3104 +f 2299/1948 594/3104 2302/1950 +f 125/3098 2279/1921 1868/1956 +f 2304/1955 1868/1956 2279/1921 +f 594/3104 2299/1948 2303/1954 +f 2304/1955 2303/1954 2299/1948 +f 2217/1839 2306/1958 157/3084 +f 2287/1932 157/3084 2306/1958 +f 2303/1954 2306/1958 594/3104 +f 2305/1957 594/3104 2306/1958 +f 2308/1959 2212/1834 2307/1960 +f 154/3083 2307/1960 2212/1834 +f 594/3104 2305/1957 2300/1953 +f 2308/1959 2300/1953 2305/1957 +f 121/3101 2309/1964 2289/1934 +f 2312/1962 2289/1934 2309/1964 +f 596/3105 2311/1965 2310/1961 +f 2312/1962 2310/1961 2311/1965 +f 119/3103 2301/1952 2314/1968 +f 2315/1967 2314/1968 2301/1952 +f 2310/1961 2315/1967 596/3105 +f 2313/1966 596/3105 2315/1967 +f 2214/1836 2317/1970 154/3083 +f 2307/1960 154/3083 2317/1970 +f 596/3105 2313/1966 2316/1969 +f 2317/1970 2316/1969 2313/1966 +f 2294/1942 2318/1971 155/3082 +f 2208/1830 155/3082 2318/1971 +f 2316/1969 2318/1971 596/3105 +f 2311/1965 596/3105 2318/1971 +f 147/3078 2195/1812 2321/1974 +f 2322/1973 2321/1974 2195/1812 +f 600/3106 2320/1976 2319/1972 +f 2322/1973 2319/1972 2320/1976 +f 2173/1785 2324/1978 146/3073 +f 2189/1806 146/3073 2324/1978 +f 2319/1972 2324/1978 600/3106 +f 2323/1977 600/3106 2324/1978 +f 2327/1980 2168/1780 2325/1982 +f 145/3072 2325/1982 2168/1780 +f 600/3106 2323/1977 2326/1979 +f 2327/1980 2326/1979 2323/1977 +f 2328/1985 2331/1986 162/3107 +f 2330/1987 162/3107 2331/1986 +f 600/3106 2326/1979 2329/1984 +f 2331/1986 2329/1984 2326/1979 +f 160/3108 2332/1989 2333/1990 +f 2334/1988 2333/1990 2332/1989 +f 600/3106 2329/1984 2320/1976 +f 2334/1988 2320/1976 2329/1984 +f 161/3109 2335/1991 2338/1995 +f 2339/1993 2338/1995 2335/1991 +f 2339/1993 2336/1994 2337/1997 +f 605/3110 2337/1997 2336/1994 +f 2343/1999 2342/2002 2340/2001 +f 165/3111 2340/2001 2342/2002 +f 605/3110 2336/1994 2341/1998 +f 2343/1999 2341/1998 2336/1994 +f 2344/2006 2347/2004 166/3112 +f 2346/2007 166/3112 2347/2004 +f 2341/1998 2347/2004 605/3110 +f 2345/2003 605/3110 2347/2004 +f 2349/2010 162/3113 2350/2009 +f 2348/2008 2350/2009 162/3113 +f 2337/1997 605/3110 2350/2009 +f 2345/2003 2350/2009 605/3110 +f 2353/2012 2328/2015 2349/2010 +f 162/3113 2349/2010 2328/2015 +f 608/3114 2352/2013 2351/2011 +f 2353/2012 2351/2011 2352/2013 +f 2354/2018 2356/2019 166/3112 +f 2344/2006 166/3112 2356/2019 +f 2351/2011 2356/2019 608/3114 +f 2355/2017 608/3114 2356/2019 +f 2360/2021 2359/2024 2357/2023 +f 163/3115 2357/2023 2359/2024 +f 608/3114 2355/2017 2358/2020 +f 2360/2021 2358/2020 2355/2017 +f 160/3116 2333/2026 2361/2027 +f 2362/2025 2361/2027 2333/2026 +f 2358/2020 2362/2025 608/3114 +f 2352/2013 608/3114 2362/2025 +f 2366/2029 2365/2030 2359/2024 +f 163/3115 2359/2024 2365/2030 +f 611/3117 2364/2032 2363/2028 +f 2366/2029 2363/2028 2364/2032 +f 2346/2007 2368/2034 166/3112 +f 2354/2018 166/3112 2368/2034 +f 2363/2028 2368/2034 611/3117 +f 2367/2033 611/3117 2368/2034 +f 2369/2038 2371/2036 165/3111 +f 2340/2001 165/3111 2371/2036 +f 611/3117 2367/2033 2370/2035 +f 2371/2036 2370/2035 2367/2033 +f 2373/2041 164/3118 2374/2040 +f 2372/2039 2374/2040 164/3118 +f 2370/2035 2374/2040 611/3117 +f 2364/2032 611/3117 2374/2040 +f 2375/2044 2378/2045 69/3119 +f 1247/2047 69/3119 2378/2045 +f 2377/2048 2378/2045 614/3120 +f 2376/2043 614/3120 2378/2045 +f 131/3051 2051/1639 2380/2051 +f 2381/2050 2380/2051 2051/1639 +f 614/3120 2376/2043 2379/2049 +f 2381/2050 2379/2049 2376/2043 +f 2382/2054 2384/2055 130/3050 +f 2046/1635 130/3050 2384/2055 +f 2379/2049 2384/2055 614/3120 +f 2383/2053 614/3120 2384/2055 +f 76/3121 1254/2057 2385/2058 +f 2386/2056 2385/2058 1254/2057 +f 614/3120 2383/2053 2377/2048 +f 2386/2056 2377/2048 2383/2053 +f 2387/2061 2390/2062 77/3122 +f 1261/2064 77/3122 2390/2062 +f 2388/2060 617/3123 2390/2062 +f 2389/2063 2390/2062 617/3123 +f 142/3054 2093/1690 2392/2068 +f 2393/2067 2392/2068 2093/1690 +f 617/3123 2388/2060 2391/2066 +f 2393/2067 2391/2066 2388/2060 +f 2394/2070 2396/2069 134/3058 +f 2090/1688 134/3058 2396/2069 +f 2391/2066 2396/2069 617/3123 +f 2395/2071 617/3123 2396/2069 +f 2398/2073 2397/2075 1268/2074 +f 80/3124 1268/2074 2397/2075 +f 617/3123 2395/2071 2389/2063 +f 2398/2073 2389/2063 2395/2071 +f 2397/2075 2401/2077 80/3124 +f 1275/2079 80/3124 2401/2077 +f 2399/2076 619/3125 2401/2077 +f 2400/2078 2401/2077 619/3125 +f 134/3058 2078/1673 2394/2070 +f 2403/2081 2394/2070 2078/1673 +f 2403/2081 2402/2082 2399/2076 +f 619/3125 2399/2076 2402/2082 +f 2404/2085 2406/2086 135/3057 +f 2072/1664 135/3057 2406/2086 +f 2405/2084 619/3125 2406/2086 +f 2402/2082 2406/2086 619/3125 +f 2408/2087 2407/2089 1281/2088 +f 81/3126 1281/2088 2407/2089 +f 619/3125 2405/2084 2400/2078 +f 2408/2087 2400/2078 2405/2084 +f 2409/2092 2412/2093 67/3127 +f 1287/2095 67/3127 2412/2093 +f 2411/2096 2412/2093 622/3128 +f 2410/2091 622/3128 2412/2093 +f 2415/2098 2414/2101 2314/2100 +f 119/3014 2314/2100 2414/2101 +f 622/3128 2410/2091 2413/2097 +f 2415/2098 2413/2097 2410/2091 +f 2416/2103 2418/2102 121/3023 +f 2309/2106 121/3023 2418/2102 +f 2417/2104 622/3128 2418/2102 +f 2413/2097 2418/2102 622/3128 +f 2420/2107 2419/2109 1294/2108 +f 68/3129 1294/2108 2419/2109 +f 622/3128 2417/2104 2411/2096 +f 2420/2107 2411/2096 2417/2104 +f 78/3130 2421/2110 1301/2116 +f 2424/2112 1301/2116 2421/2110 +f 2424/2112 2422/2113 2423/2114 +f 625/3131 2423/2114 2422/2113 +f 2250/2119 2427/2120 129/3029 +f 2426/2121 129/3029 2427/2120 +f 2422/2113 2427/2120 625/3131 +f 2425/2118 625/3131 2427/2120 +f 2430/2123 2258/2126 2428/2125 +f 122/3017 2428/2125 2258/2126 +f 625/3131 2425/2118 2429/2122 +f 2430/2123 2429/2122 2425/2118 +f 2431/2129 74/3132 2432/2127 +f 1308/2128 2432/2127 74/3132 +f 2429/2122 2432/2127 625/3131 +f 2423/2114 625/3131 2432/2127 +f 2385/2058 2435/2131 76/3121 +f 1315/2133 76/3121 2435/2131 +f 2434/2132 2435/2131 626/3133 +f 2433/2130 626/3133 2435/2131 +f 130/3050 2063/1654 2382/2054 +f 2437/2135 2382/2054 2063/1654 +f 626/3133 2433/2130 2436/2136 +f 2437/2135 2436/2136 2433/2130 +f 2058/1649 142/3054 2439/2137 +f 2392/2068 2439/2137 142/3054 +f 2436/2136 2439/2137 626/3133 +f 2438/2138 626/3133 2439/2137 +f 2440/2139 2387/2061 1320/2140 +f 77/3122 1320/2140 2387/2061 +f 626/3133 2438/2138 2434/2132 +f 2440/2139 2434/2132 2438/2138 +f 2441/2143 2444/2144 70/3134 +f 1325/2146 70/3134 2444/2144 +f 2443/2147 2444/2144 628/3135 +f 2442/2142 628/3135 2444/2144 +f 143/3067 2156/1762 2446/2150 +f 2447/2148 2446/2150 2156/1762 +f 628/3135 2442/2142 2445/2149 +f 2447/2148 2445/2149 2442/2142 +f 2380/2051 2449/2152 131/3051 +f 2151/1757 131/3051 2449/2152 +f 2445/2149 2449/2152 628/3135 +f 2448/2151 628/3135 2449/2152 +f 69/3119 1331/2153 2375/2044 +f 2450/2154 2375/2044 1331/2153 +f 628/3135 2448/2151 2443/2147 +f 2450/2154 2443/2147 2448/2151 +f 2451/2157 2454/2158 71/2904 +f 1337/746 71/2904 2454/2158 +f 2452/2156 630/3136 2454/2158 +f 2453/2159 2454/2158 630/3136 +f 145/3137 2170/2160 2456/2164 +f 2457/2162 2456/2164 2170/2160 +f 2457/2162 2455/2163 2452/2156 +f 630/3136 2452/2156 2455/2163 +f 2165/2169 143/3138 2459/2165 +f 2446/2166 2459/2165 143/3138 +f 2455/2163 2459/2165 630/3136 +f 2458/2167 630/3136 2459/2165 +f 2460/2170 2441/2171 1343/756 +f 70/2906 1343/756 2441/2171 +f 630/3136 2458/2167 2453/2159 +f 2460/2170 2453/2159 2458/2167 +f 59/2909 2461/2174 1349/766 +f 2464/2175 1349/766 2461/2174 +f 2463/2176 2464/2175 634/3139 +f 2462/2173 634/3139 2464/2175 +f 147/3078 2465/2177 2467/2181 +f 2468/2179 2467/2181 2465/2177 +f 634/3139 2462/2173 2466/2180 +f 2468/2179 2466/2180 2462/2173 +f 2469/2184 2472/2185 148/3140 +f 2471/2186 148/3140 2472/2185 +f 2466/2180 2472/2185 634/3139 +f 2470/2183 634/3139 2472/2185 +f 65/2911 1356/776 2473/2188 +f 2474/2187 2473/2188 1356/776 +f 634/3139 2470/2183 2463/2176 +f 2474/2187 2463/2176 2470/2183 +f 2475/2190 2478/2189 60/2913 +f 1365/785 60/2913 2478/2189 +f 636/3141 2477/2193 2476/2191 +f 2478/2189 2476/2191 2477/2193 +f 2199/1817 2481/2195 151/3079 +f 2480/2196 151/3079 2481/2195 +f 2479/2194 636/3141 2481/2195 +f 2476/2191 2481/2195 636/3141 +f 147/3078 2467/2181 2193/1811 +f 2483/2198 2193/1811 2467/2181 +f 2483/2198 2482/2197 2479/2194 +f 636/3141 2479/2194 2482/2197 +f 2484/2199 2461/2174 1371/794 +f 59/2909 1371/794 2461/2174 +f 2482/2197 2484/2199 636/3141 +f 2477/2193 636/3141 2484/2199 +f 2485/2202 2488/2203 79/3142 +f 1377/2205 79/3142 2488/2203 +f 2486/2201 638/3143 2488/2203 +f 2487/2204 2488/2203 638/3143 +f 128/3030 1934/1501 2490/2209 +f 2491/2208 2490/2209 1934/1501 +f 2491/2208 2489/2207 2486/2201 +f 638/3143 2486/2201 2489/2207 +f 129/3029 2426/2121 1928/1495 +f 2493/2211 1928/1495 2426/2121 +f 2489/2207 2493/2211 638/3143 +f 2492/2210 638/3143 2493/2211 +f 1383/2213 2494/2212 78/3130 +f 2421/2110 78/3130 2494/2212 +f 638/3143 2492/2210 2487/2204 +f 2494/2212 2487/2204 2492/2210 +f 68/3129 2419/2109 1389/2218 +f 2497/2215 1389/2218 2419/2109 +f 640/3144 2496/2216 2495/2214 +f 2497/2215 2495/2214 2496/2216 +f 1907/1467 2499/2220 121/3023 +f 2416/2103 121/3023 2499/2220 +f 2495/2214 2499/2220 640/3144 +f 2498/2219 640/3144 2499/2220 +f 120/3022 2500/2224 1902/1462 +f 2502/2222 1902/1462 2500/2224 +f 640/3144 2498/2219 2501/2221 +f 2502/2222 2501/2221 2498/2219 +f 2503/2227 58/3145 2504/2225 +f 1395/2226 2504/2225 58/3145 +f 2501/2221 2504/2225 640/3144 +f 2496/2216 640/3144 2504/2225 +f 2507/2229 1401/2232 2503/2227 +f 58/3145 2503/2227 1401/2232 +f 642/3146 2506/2230 2505/2228 +f 2507/2229 2505/2228 2506/2230 +f 1919/1482 2509/2234 120/3022 +f 2500/2224 120/3022 2509/2234 +f 2505/2228 2509/2234 642/3146 +f 2508/2233 642/3146 2509/2234 +f 132/3026 2510/2238 1914/1477 +f 2512/2236 1914/1477 2510/2238 +f 642/3146 2508/2233 2511/2235 +f 2512/2236 2511/2235 2508/2233 +f 2513/2241 61/3147 2514/2239 +f 1407/2240 2514/2239 61/3147 +f 2511/2235 2514/2239 642/3146 +f 2506/2230 642/3146 2514/2239 +f 2517/2243 1413/2246 2513/2241 +f 61/3147 2513/2241 1413/2246 +f 644/3148 2516/2244 2515/2242 +f 2517/2243 2515/2242 2516/2244 +f 2149/1751 2519/2247 132/3026 +f 2510/2238 132/3026 2519/2247 +f 2518/2248 644/3148 2519/2247 +f 2515/2242 2519/2247 644/3148 +f 144/3068 2520/2250 2158/1763 +f 2522/2249 2158/1763 2520/2250 +f 2518/2248 2522/2249 644/3148 +f 2521/2251 644/3148 2522/2249 +f 2524/2254 2523/2255 1419/2253 +f 62/3149 1419/2253 2523/2255 +f 644/3148 2521/2251 2516/2244 +f 2524/2254 2516/2244 2521/2251 +f 1425/857 62/2923 2527/2259 +f 2523/2258 2527/2259 62/2923 +f 2526/2260 2527/2259 646/3150 +f 2525/2257 646/3150 2527/2259 +f 144/3069 2177/1788 2520/2263 +f 2529/2262 2520/2263 2177/1788 +f 2529/2262 2528/2261 2525/2257 +f 646/3150 2525/2257 2528/2261 +f 2532/2265 2186/1800 2530/2267 +f 149/3076 2530/2267 2186/1800 +f 2528/2261 2532/2265 646/3150 +f 2531/2264 646/3150 2532/2265 +f 2533/2269 63/2925 2534/2268 +f 1431/866 2534/2268 63/2925 +f 646/3150 2531/2264 2526/2260 +f 2534/2268 2526/2260 2531/2264 +f 2537/2271 1437/875 2533/2269 +f 63/2925 2533/2269 1437/875 +f 648/3151 2536/2272 2535/2270 +f 2537/2271 2535/2270 2536/2272 +f 2187/1802 2539/2274 149/3076 +f 2530/2267 149/3076 2539/2274 +f 2535/2270 2539/2274 648/3151 +f 2538/2273 648/3151 2539/2274 +f 150/3075 2540/2278 2182/1798 +f 2542/2276 2182/1798 2540/2278 +f 648/3151 2538/2273 2541/2275 +f 2542/2276 2541/2275 2538/2273 +f 2543/2280 64/2927 2544/2279 +f 1443/881 2544/2279 64/2927 +f 2541/2275 2544/2279 648/3151 +f 2536/2272 648/3151 2544/2279 +f 2547/2282 1449/887 2543/2280 +f 64/2927 2543/2280 1449/887 +f 2545/2281 649/3152 2547/2282 +f 2546/2283 2547/2282 649/3152 +f 150/3075 2201/1819 2540/2278 +f 2549/2285 2540/2278 2201/1819 +f 2549/2285 2548/2284 2545/2281 +f 649/3152 2545/2281 2548/2284 +f 2480/2196 2551/2287 151/3079 +f 2197/1816 151/3079 2551/2287 +f 2548/2284 2551/2287 649/3152 +f 2550/2286 649/3152 2551/2287 +f 2552/2288 2475/2190 1454/893 +f 60/2913 1454/893 2475/2190 +f 649/3152 2550/2286 2546/2283 +f 2552/2288 2546/2283 2550/2286 +f 1461/899 2555/2289 71/2904 +f 2451/2157 71/2904 2555/2289 +f 651/3153 2554/2291 2553/2290 +f 2555/2289 2553/2290 2554/2291 +f 2558/2293 1470/916 2556/2295 +f 72/2932 2556/2295 1470/916 +f 651/3153 2553/2290 2557/2292 +f 2558/2293 2557/2292 2553/2290 +f 2338/2298 2561/2299 161/3154 +f 2560/2300 161/3154 2561/2299 +f 651/3153 2557/2292 2559/2297 +f 2561/2299 2559/2297 2557/2292 +f 162/3155 2330/2304 2348/2305 +f 2563/2302 2348/2305 2330/2304 +f 651/3153 2559/2297 2562/2301 +f 2563/2302 2562/2301 2559/2297 +f 2456/2164 2564/2306 145/3137 +f 2325/2307 145/3137 2564/2306 +f 651/3153 2562/2301 2554/2291 +f 2564/2306 2554/2291 2562/2301 +f 147/3078 2321/1974 2465/2177 +f 2567/2308 2465/2177 2321/1974 +f 2567/2308 2565/2309 2566/2310 +f 653/3156 2566/2310 2565/2309 +f 2568/2313 2570/2314 160/3108 +f 2332/1989 160/3108 2570/2314 +f 2565/2309 2570/2314 653/3156 +f 2569/2312 653/3156 2570/2314 +f 148/3140 2471/2186 2571/2316 +f 2572/2315 2571/2316 2471/2186 +f 2572/2315 2566/2310 2569/2312 +f 653/3156 2569/2312 2566/2310 +f 2577/2320 2576/2322 2573/2319 +f 170/3157 2573/2319 2576/2322 +f 2575/2323 2577/2320 658/3158 +f 2574/2318 658/3158 2577/2320 +f 2581/2325 2580/2328 2578/2327 +f 167/3159 2578/2327 2580/2328 +f 658/3158 2574/2318 2579/2324 +f 2581/2325 2579/2324 2574/2318 +f 2582/2331 2585/2332 169/3160 +f 2584/2333 169/3160 2585/2332 +f 2579/2324 2585/2332 658/3158 +f 2583/2330 658/3158 2585/2332 +f 2588/2334 2587/2336 2586/2335 +f 168/3161 2586/2335 2587/2336 +f 658/3158 2583/2330 2575/2323 +f 2588/2334 2575/2323 2583/2330 +f 2589/2339 2593/2340 177/3162 +f 2592/2342 177/3162 2593/2340 +f 2590/2338 663/3163 2593/2340 +f 2591/2341 2593/2340 663/3163 +f 178/3164 2594/2346 2596/2348 +f 2597/2347 2596/2348 2594/2346 +f 2597/2347 2595/2345 2590/2338 +f 663/3163 2590/2338 2595/2345 +f 2601/2349 2600/2353 2598/2350 +f 173/3165 2598/2350 2600/2353 +f 2595/2345 2601/2349 663/3163 +f 2599/2351 663/3163 2601/2349 +f 2604/2354 2603/2356 2602/2355 +f 174/3166 2602/2355 2603/2356 +f 663/3163 2599/2351 2591/2341 +f 2604/2354 2591/2341 2599/2351 +f 178/3164 2605/2360 2608/2361 +f 2609/2358 2608/2361 2605/2360 +f 2609/2358 2606/2357 2607/2363 +f 668/3167 2607/2363 2606/2357 +f 2612/2368 179/3168 2613/2364 +f 2610/2365 2613/2364 179/3168 +f 2606/2357 2613/2364 668/3167 +f 2611/2366 668/3167 2613/2364 +f 2617/2370 2616/2373 2614/2372 +f 172/3169 2614/2372 2616/2373 +f 668/3167 2611/2366 2615/2369 +f 2617/2370 2615/2369 2611/2366 +f 2620/2374 2619/2376 2618/2375 +f 171/3170 2618/2375 2619/2376 +f 2607/2363 668/3167 2620/2374 +f 2615/2369 2620/2374 668/3167 +f 174/3166 2603/2356 2623/2380 +f 2624/2377 2623/2380 2603/2356 +f 2622/2381 2624/2377 672/3171 +f 2621/2378 672/3171 2624/2377 +f 2627/2383 2598/2350 2625/2385 +f 173/3165 2625/2385 2598/2350 +f 672/3171 2621/2378 2626/2382 +f 2627/2383 2626/2382 2621/2378 +f 2628/2388 2631/2389 176/3172 +f 2630/2390 176/3172 2631/2389 +f 2629/2387 672/3171 2631/2389 +f 2626/2382 2631/2389 672/3171 +f 2632/2391 2634/2392 175/3173 +f 2633/2393 175/3173 2634/2392 +f 2622/2381 672/3171 2634/2392 +f 2629/2387 2634/2392 672/3171 +f 2637/2397 175/3173 2638/2394 +f 2633/2393 2638/2394 175/3173 +f 2636/2398 2638/2394 675/3174 +f 2635/2395 675/3174 2638/2394 +f 2641/2399 2628/2388 2639/2400 +f 176/3172 2639/2400 2628/2388 +f 2635/2395 2641/2399 675/3174 +f 2640/2401 675/3174 2641/2399 +f 2619/2376 2644/2403 171/3170 +f 2643/2405 171/3170 2644/2403 +f 675/3174 2640/2401 2642/2404 +f 2644/2403 2642/2404 2640/2401 +f 2614/2372 172/3169 2646/2406 +f 2645/2407 2646/2406 172/3169 +f 2642/2404 2646/2406 675/3174 +f 2636/2398 675/3174 2646/2406 +f 177/3162 2647/2410 2589/2339 +f 2650/2411 2589/2339 2647/2410 +f 678/3175 2649/2412 2648/2409 +f 2650/2411 2648/2409 2649/2412 +f 180/3176 2651/2416 2653/2417 +f 2654/2414 2653/2417 2651/2416 +f 678/3175 2648/2409 2652/2413 +f 2654/2414 2652/2413 2648/2409 +f 2656/2420 179/3168 2657/2418 +f 2612/2368 2657/2418 179/3168 +f 2652/2413 2657/2418 678/3175 +f 2655/2419 678/3175 2657/2418 +f 178/3164 2596/2348 2605/2360 +f 2658/2421 2605/2360 2596/2348 +f 2655/2419 2658/2421 678/3175 +f 2649/2412 678/3175 2658/2421 +f 2662/2423 2647/2428 2659/2425 +f 177/3177 2659/2425 2647/2428 +f 681/3178 2661/2426 2660/2422 +f 2662/2423 2660/2422 2661/2426 +f 160/3116 2361/2027 2664/2431 +f 2665/2430 2664/2431 2361/2027 +f 681/3178 2660/2422 2663/2429 +f 2665/2430 2663/2429 2660/2422 +f 2365/2030 2667/2433 163/3115 +f 2357/2023 163/3115 2667/2433 +f 2663/2429 2667/2433 681/3178 +f 2666/2432 681/3178 2667/2433 +f 164/3118 2668/2437 2372/2039 +f 2670/2435 2372/2039 2668/2437 +f 681/3178 2666/2432 2669/2434 +f 2670/2435 2669/2434 2666/2432 +f 2671/2440 180/3179 2672/2439 +f 2653/2438 2672/2439 180/3179 +f 681/3178 2669/2434 2661/2426 +f 2672/2439 2661/2426 2669/2434 +f 179/3180 2656/2441 2675/2445 +f 2676/2443 2675/2445 2656/2441 +f 2676/2443 2673/2444 2674/2447 +f 683/3181 2674/2447 2673/2444 +f 2671/2440 2678/2449 180/3179 +f 2651/2450 180/3179 2678/2449 +f 2677/2448 683/3181 2678/2449 +f 2673/2444 2678/2449 683/3181 +f 2373/2041 2680/2452 164/3118 +f 2668/2437 164/3118 2680/2452 +f 683/3181 2677/2448 2679/2451 +f 2680/2452 2679/2451 2677/2448 +f 2342/2002 2682/2453 165/3111 +f 2369/2038 165/3111 2682/2453 +f 683/3181 2679/2451 2681/2454 +f 2682/2453 2681/2454 2679/2451 +f 2683/2456 2684/2455 161/3109 +f 2335/1991 161/3109 2684/2455 +f 2681/2454 2684/2455 683/3181 +f 2674/2447 683/3181 2684/2455 +f 2616/2459 2688/2460 172/3182 +f 2687/2462 172/3182 2688/2460 +f 685/3183 2686/2463 2685/2458 +f 2688/2460 2685/2458 2686/2463 +f 179/3184 2675/2467 2610/2468 +f 2690/2465 2610/2468 2675/2467 +f 2690/2465 2689/2464 2685/2458 +f 685/3183 2685/2458 2689/2464 +f 2692/2470 2683/2471 2560/2300 +f 161/3154 2560/2300 2683/2471 +f 685/3183 2689/2464 2691/2469 +f 2692/2470 2691/2469 2689/2464 +f 72/2932 1602/1082 2556/2295 +f 2694/2473 2556/2295 1602/1082 +f 685/3183 2691/2469 2693/2472 +f 2694/2473 2693/2472 2691/2469 +f 2696/2474 1597/1077 2695/2475 +f 73/2961 2695/2475 1597/1077 +f 685/3183 2693/2472 2686/2463 +f 2696/2474 2686/2463 2693/2472 +f 1610/1096 2700/2477 66/2963 +f 2699/2478 66/2963 2700/2477 +f 688/3185 2698/2480 2697/2476 +f 2700/2477 2697/2476 2698/2480 +f 2473/2188 2702/2482 65/2911 +f 1621/1110 65/2911 2702/2482 +f 2697/2476 2702/2482 688/3185 +f 2701/2481 688/3185 2702/2482 +f 148/3140 2703/2486 2469/2184 +f 2705/2484 2469/2184 2703/2486 +f 688/3185 2701/2481 2704/2483 +f 2705/2484 2704/2483 2701/2481 +f 2707/2491 174/3186 2708/2488 +f 2623/2490 2708/2488 174/3186 +f 688/3185 2704/2483 2706/2487 +f 2708/2488 2706/2487 2704/2483 +f 2710/2492 2632/2494 2709/2493 +f 175/3187 2709/2493 2632/2494 +f 688/3185 2706/2487 2698/2480 +f 2710/2492 2698/2480 2706/2487 +f 73/2961 1625/1114 2695/2475 +f 2713/2495 2695/2475 1625/1114 +f 2713/2495 2711/2496 2712/2497 +f 689/3188 2712/2497 2711/2496 +f 66/2969 2699/2500 1631/1127 +f 2715/2501 1631/1127 2699/2500 +f 2711/2496 2715/2501 689/3188 +f 2714/2499 689/3188 2715/2501 +f 2717/2503 2709/2506 2637/2505 +f 175/3189 2637/2505 2709/2506 +f 689/3188 2714/2499 2716/2502 +f 2717/2503 2716/2502 2714/2499 +f 172/3182 2687/2462 2645/2508 +f 2718/2507 2645/2508 2687/2462 +f 689/3188 2716/2502 2712/2497 +f 2718/2507 2712/2497 2716/2502 +f 2571/2316 2721/2510 148/3140 +f 2703/2486 148/3140 2721/2510 +f 2720/2511 2721/2510 690/3190 +f 2719/2509 690/3190 2721/2510 +f 160/3108 2664/2512 2568/2313 +f 2723/2514 2568/2313 2664/2512 +f 690/3190 2719/2509 2722/2515 +f 2723/2514 2722/2515 2719/2509 +f 177/3191 2592/2519 2659/2520 +f 2725/2517 2659/2520 2592/2519 +f 690/3190 2722/2515 2724/2516 +f 2725/2517 2724/2516 2722/2515 +f 2726/2521 2602/2522 2707/2491 +f 174/3186 2707/2491 2602/2522 +f 690/3190 2724/2516 2720/2511 +f 2726/2521 2720/2511 2724/2516 +f 2600/2353 2730/2524 173/3165 +f 2729/2526 173/3165 2730/2524 +f 2727/2523 693/3192 2730/2524 +f 2728/2525 2730/2524 693/3192 +f 178/3164 2731/2528 2594/2346 +f 2733/2530 2594/2346 2731/2528 +f 693/3192 2727/2523 2732/2531 +f 2733/2530 2732/2531 2727/2523 +f 2576/2322 2736/2533 170/3157 +f 2735/2534 170/3157 2736/2533 +f 2732/2531 2736/2533 693/3192 +f 2734/2532 693/3192 2736/2533 +f 2737/2535 2738/2536 168/3161 +f 2586/2335 168/3161 2738/2536 +f 2728/2525 693/3192 2738/2536 +f 2734/2532 2738/2536 693/3192 +f 176/3172 2630/2390 2741/2539 +f 2742/2538 2741/2539 2630/2390 +f 2742/2538 2739/2537 2740/2541 +f 695/3193 2740/2541 2739/2537 +f 2625/2385 173/3165 2744/2542 +f 2729/2526 2744/2542 173/3165 +f 2744/2542 2743/2543 2739/2537 +f 695/3193 2739/2537 2743/2543 +f 2587/2336 2746/2545 168/3161 +f 2737/2535 168/3161 2746/2545 +f 2743/2543 2746/2545 695/3193 +f 2745/2544 695/3193 2746/2545 +f 2747/2546 2748/2547 169/3160 +f 2582/2331 169/3160 2748/2547 +f 2740/2541 695/3193 2748/2547 +f 2745/2544 2748/2547 695/3193 +f 171/3170 2643/2405 2751/2551 +f 2752/2549 2751/2551 2643/2405 +f 2749/2548 697/3194 2752/2549 +f 2750/2550 2752/2549 697/3194 +f 176/3172 2741/2539 2639/2400 +f 2754/2553 2639/2400 2741/2539 +f 2754/2553 2753/2554 2749/2548 +f 697/3194 2749/2548 2753/2554 +f 2584/2333 2756/2556 169/3160 +f 2747/2546 169/3160 2756/2556 +f 2753/2554 2756/2556 697/3194 +f 2755/2555 697/3194 2756/2556 +f 2757/2557 2758/2558 167/3159 +f 2578/2327 167/3159 2758/2558 +f 2750/2550 697/3194 2758/2558 +f 2755/2555 2758/2558 697/3194 +f 178/3164 2608/2361 2731/2528 +f 2761/2560 2731/2528 2608/2361 +f 698/3195 2760/2561 2759/2559 +f 2761/2560 2759/2559 2760/2561 +f 2751/2551 2763/2562 171/3170 +f 2618/2375 171/3170 2763/2562 +f 2759/2559 2763/2562 698/3195 +f 2762/2563 698/3195 2763/2562 +f 2580/2328 2765/2565 167/3159 +f 2757/2557 167/3159 2765/2565 +f 2762/2563 2765/2565 698/3195 +f 2764/2564 698/3195 2765/2565 +f 2735/2534 2766/2566 170/3157 +f 2573/2319 170/3157 2766/2566 +f 2764/2564 2766/2566 698/3195 +f 2760/2561 698/3195 2766/2566 +f 123/3196 2767/2567 1883/2573 +f 2770/2569 1883/2573 2767/2567 +f 2770/2569 2768/2570 2769/2571 +f 702/3197 2769/2571 2768/2570 +f 2773/2578 183/3198 2774/2574 +f 2771/2575 2774/2574 183/3198 +f 2768/2570 2774/2574 702/3197 +f 2772/2576 702/3197 2774/2574 +f 2777/2583 182/3199 2778/2579 +f 2775/2580 2778/2579 182/3199 +f 2772/2576 2778/2579 702/3197 +f 2776/2581 702/3197 2778/2579 +f 2780/2584 2779/2586 1888/2585 +f 122/3200 1888/2585 2779/2586 +f 702/3197 2776/2581 2769/2571 +f 2780/2584 2769/2571 2776/2581 +f 2779/2586 2783/2588 122/3200 +f 2428/2590 122/3200 2783/2588 +f 2782/2591 2783/2588 704/3201 +f 2781/2587 704/3201 2783/2588 +f 182/3199 2784/2595 2775/2580 +f 2786/2593 2775/2580 2784/2595 +f 704/3201 2781/2587 2785/2592 +f 2786/2593 2785/2592 2781/2587 +f 1703/1221 2789/2597 100/2983 +f 2788/2598 100/2983 2789/2597 +f 2785/2592 2789/2597 704/3201 +f 2787/2596 704/3201 2789/2597 +f 2790/2599 1698/1215 2431/2600 +f 74/2982 2431/2600 1698/1215 +f 704/3201 2787/2596 2782/2591 +f 2790/2599 2782/2591 2787/2596 +f 67/2984 1709/1228 2409/2603 +f 2793/2602 2409/2603 1709/1228 +f 707/3202 2792/2605 2791/2601 +f 2793/2602 2791/2601 2792/2605 +f 2794/2608 2796/2609 99/2988 +f 1718/1241 99/2988 2796/2609 +f 2791/2601 2796/2609 707/3202 +f 2795/2607 707/3202 2796/2609 +f 181/3203 2797/2610 2799/2614 +f 2800/2612 2799/2614 2797/2610 +f 707/3202 2795/2607 2798/2613 +f 2800/2612 2798/2613 2795/2607 +f 2801/2617 119/3204 2802/2616 +f 2414/2615 2802/2616 119/3204 +f 2798/2613 2802/2616 707/3202 +f 2792/2605 707/3202 2802/2616 +f 119/3204 2801/2617 1872/2621 +f 2805/2619 1872/2621 2801/2617 +f 2804/2620 2805/2619 709/3205 +f 2803/2618 709/3205 2805/2619 +f 2806/2626 2808/2624 181/3203 +f 2797/2610 181/3203 2808/2624 +f 709/3205 2803/2618 2807/2623 +f 2808/2624 2807/2623 2803/2618 +f 2773/2578 2811/2628 183/3198 +f 2810/2629 183/3198 2811/2628 +f 2809/2627 709/3205 2811/2628 +f 2807/2623 2811/2628 709/3205 +f 1877/2631 2812/2630 123/3196 +f 2767/2567 123/3196 2812/2630 +f 2812/2630 2804/2620 2809/2627 +f 709/3205 2809/2627 2804/2620 +f 2815/2633 1731/1260 2788/2598 +f 100/2983 2788/2598 1731/1260 +f 711/3206 2814/2634 2813/2632 +f 2815/2633 2813/2632 2814/2634 +f 2777/2583 2817/2636 182/3199 +f 2784/2595 182/3199 2817/2636 +f 2813/2632 2817/2636 711/3206 +f 2816/2635 711/3206 2817/2636 +f 183/3198 2818/2640 2771/2575 +f 2820/2638 2771/2575 2818/2640 +f 711/3206 2816/2635 2819/2637 +f 2820/2638 2819/2637 2816/2635 +f 75/2991 1737/1267 2821/2642 +f 2822/2641 2821/2642 1737/1267 +f 2819/2637 2822/2641 711/3206 +f 2814/2634 711/3206 2822/2641 +f 75/2991 2821/2642 1743/1273 +f 2825/2644 1743/1273 2821/2642 +f 2824/2645 2825/2644 712/3207 +f 2823/2643 712/3207 2825/2644 +f 183/3198 2810/2629 2818/2640 +f 2827/2647 2818/2640 2810/2629 +f 712/3207 2823/2643 2826/2646 +f 2827/2647 2826/2646 2823/2643 +f 2806/2626 181/3203 2829/2649 +f 2799/2614 2829/2649 181/3203 +f 2826/2646 2829/2649 712/3207 +f 2828/2648 712/3207 2829/2649 +f 2830/2650 2794/2608 1748/1279 +f 99/2988 1748/1279 2794/2608 +f 712/3207 2828/2648 2824/2645 +f 2830/2650 2824/2645 2828/2648 +f 2835/2652 2834/2655 2831/2654 +f 184/3208 2831/2654 2834/2655 +f 2835/2652 2832/2651 2833/2657 +f 716/3209 2833/2657 2832/2651 +f 2838/2662 186/3210 2839/2660 +f 2836/2658 2839/2660 186/3210 +f 2832/2651 2839/2660 716/3209 +f 2837/2661 716/3209 2839/2660 +f 2840/2663 2842/2664 185/3211 +f 2841/2665 185/3211 2842/2664 +f 2837/2661 2842/2664 716/3209 +f 2833/2657 716/3209 2842/2664 +f 2843/2669 2846/2667 184/3208 +f 2831/2654 184/3208 2846/2667 +f 719/3212 2845/2670 2844/2666 +f 2846/2667 2844/2666 2845/2670 +f 2006/1585 2849/2672 117/3042 +f 2848/2673 117/3042 2849/2672 +f 719/3212 2844/2666 2847/2671 +f 2849/2672 2847/2671 2844/2666 +f 136/3031 1937/1504 2015/1596 +f 2851/2675 2015/1596 1937/1504 +f 719/3212 2847/2671 2850/2674 +f 2851/2675 2850/2674 2847/2671 +f 2852/2678 2854/2679 128/3030 +f 1932/1500 128/3030 2854/2679 +f 2850/2674 2854/2679 719/3212 +f 2853/2677 719/3212 2854/2679 +f 186/3210 2838/2662 2855/2681 +f 2856/2680 2855/2681 2838/2662 +f 719/3212 2853/2677 2845/2670 +f 2856/2680 2845/2670 2853/2677 +f 2834/2655 2859/2683 184/3208 +f 2843/2669 184/3208 2859/2683 +f 721/3213 2858/2684 2857/2682 +f 2859/2683 2857/2682 2858/2684 +f 185/3211 2860/2688 2840/2663 +f 2862/2686 2840/2663 2860/2688 +f 721/3213 2857/2682 2861/2685 +f 2862/2686 2861/2685 2857/2682 +f 135/3057 2074/1668 2864/2691 +f 2865/2690 2864/2691 2074/1668 +f 721/3213 2861/2685 2863/2689 +f 2865/2690 2863/2689 2861/2685 +f 2115/1716 2867/2693 113/3055 +f 2067/1659 113/3055 2867/2693 +f 721/3213 2863/2689 2866/2692 +f 2867/2693 2866/2692 2863/2689 +f 117/3042 2848/2673 2111/1711 +f 2868/2694 2111/1711 2848/2673 +f 721/3213 2866/2692 2858/2684 +f 2868/2694 2858/2684 2866/2692 +f 2872/2696 2871/2699 1794/2698 +f 104/3214 1794/2698 2871/2699 +f 723/3215 2870/2701 2869/2695 +f 2872/2696 2869/2695 2870/2701 +f 2407/2089 2874/2703 81/3126 +f 1801/2704 81/3126 2874/2703 +f 2873/2702 723/3215 2874/2703 +f 2869/2695 2874/2703 723/3215 +f 2864/2691 2876/2705 135/3057 +f 2404/2085 135/3057 2876/2705 +f 2876/2705 2875/2706 2873/2702 +f 723/3215 2873/2702 2875/2706 +f 2877/2707 2878/2708 185/3211 +f 2860/2688 185/3211 2878/2708 +f 2875/2706 2878/2708 723/3215 +f 2870/2701 723/3215 2878/2708 +f 1805/2711 2881/2712 79/3142 +f 2485/2202 79/3142 2881/2712 +f 2880/2713 2881/2712 725/3216 +f 2879/2710 725/3216 2881/2712 +f 2884/2715 1812/2718 2882/2717 +f 105/3217 2882/2717 1812/2718 +f 725/3216 2879/2710 2883/2714 +f 2884/2715 2883/2714 2879/2710 +f 2855/2681 2887/2720 186/3210 +f 2886/2721 186/3210 2887/2720 +f 2883/2714 2887/2720 725/3216 +f 2885/2719 725/3216 2887/2720 +f 128/3030 2490/2209 2852/2678 +f 2888/2722 2852/2678 2490/2209 +f 725/3216 2885/2719 2880/2713 +f 2888/2722 2880/2713 2885/2719 +f 2836/2658 186/3210 2892/2726 +f 2889/2725 2892/2726 186/3210 +f 2891/2727 2892/2726 729/3218 +f 2890/2724 729/3218 2892/2726 +f 2896/2729 2895/2732 2893/2731 +f 188/3219 2893/2731 2895/2732 +f 2896/2729 2894/2728 2890/2724 +f 729/3218 2890/2724 2894/2728 +f 2900/2734 2899/2737 2897/2736 +f 187/3220 2897/2736 2899/2737 +f 729/3218 2894/2728 2898/2733 +f 2900/2734 2898/2733 2894/2728 +f 185/3211 2841/2665 2901/2739 +f 2902/2738 2901/2739 2841/2665 +f 2902/2738 2891/2727 2898/2733 +f 729/3218 2898/2733 2891/2727 +f 185/3211 2901/2739 2877/2707 +f 2905/2740 2877/2707 2901/2739 +f 731/3221 2904/2742 2903/2741 +f 2905/2740 2903/2741 2904/2742 +f 2906/2745 2908/2746 187/3220 +f 2897/2736 187/3220 2908/2746 +f 2903/2741 2908/2746 731/3221 +f 2907/2744 731/3221 2908/2746 +f 108/3222 1837/2750 2910/2751 +f 2911/2748 2910/2751 1837/2750 +f 731/3221 2907/2744 2909/2747 +f 2911/2748 2909/2747 2907/2744 +f 2871/2699 2912/2752 104/3214 +f 1832/2753 104/3214 2912/2752 +f 2909/2747 2912/2752 731/3221 +f 2904/2742 731/3221 2912/2752 +f 1843/2756 2915/2757 105/3217 +f 2882/2717 105/3217 2915/2757 +f 2913/2755 733/3223 2915/2757 +f 2914/2758 2915/2757 733/3223 +f 109/3224 2916/2762 1850/2763 +f 2918/2760 1850/2763 2916/2762 +f 2918/2760 2917/2759 2913/2755 +f 733/3223 2913/2755 2917/2759 +f 2920/2766 188/3219 2921/2764 +f 2895/2732 2921/2764 188/3219 +f 2917/2759 2921/2764 733/3223 +f 2919/2765 733/3223 2921/2764 +f 2922/2767 2889/2725 2886/2721 +f 186/3210 2886/2721 2889/2725 +f 733/3223 2919/2765 2914/2758 +f 2922/2767 2914/2758 2919/2765 +f 2925/2769 2906/2745 2899/2737 +f 187/3220 2899/2737 2906/2745 +f 734/3225 2924/2770 2923/2768 +f 2925/2769 2923/2768 2924/2770 +f 2927/2772 2893/2731 2920/2766 +f 188/3219 2920/2766 2893/2731 +f 734/3225 2923/2768 2926/2771 +f 2927/2772 2926/2771 2923/2768 +f 1860/2775 2929/2776 109/3224 +f 2916/2762 109/3224 2929/2776 +f 2926/2771 2929/2776 734/3225 +f 2928/2774 734/3225 2929/2776 +f 2910/2751 2930/2777 108/3222 +f 1856/2778 108/3222 2930/2777 +f 2928/2774 2930/2777 734/3225 +f 2924/2770 734/3225 2930/2777 diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/missing_usemtl/cow_texture.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/missing_usemtl/cow_texture.png new file mode 100644 index 0000000000000000000000000000000000000000..630944877af378f0816781a41f0a8f1020c123aa Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/missing_usemtl/cow_texture.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/obj_mtl_no_image/model.mtl b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/obj_mtl_no_image/model.mtl new file mode 100644 index 0000000000000000000000000000000000000000..ddb3197ce4c4b4f685381f296cc6cc44fd19a3ad --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/obj_mtl_no_image/model.mtl @@ -0,0 +1,7 @@ +# Material Count: 1 + +newmtl material_1 +Ns 96.078431 +Ka 0.000000 0.000000 0.000000 +Kd 0.500000 0.000000 0.000000 +Ks 0.500000 0.500000 0.500000 diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/obj_mtl_no_image/model.obj b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/obj_mtl_no_image/model.obj new file mode 100644 index 0000000000000000000000000000000000000000..cf411442fd4d6e5364e0e49aea0e3bbd570d6b06 --- /dev/null +++ b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/obj_mtl_no_image/model.obj @@ -0,0 +1,10 @@ + +mtllib model.mtl + +v 0.1 0.2 0.3 +v 0.2 0.3 0.4 +v 0.3 0.4 0.5 +v 0.4 0.5 0.6 +usemtl material_1 +f 1 2 3 +f 1 2 4 diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/room.jpg b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/room.jpg new file mode 100644 index 0000000000000000000000000000000000000000..29b9441fff2631a0ec7a4e74cbeab9e27e3c0631 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/room.jpg differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_FishEyeCameras_silhouette.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_FishEyeCameras_silhouette.png new file mode 100644 index 0000000000000000000000000000000000000000..a6fd9978e7ef126de49b3a249e187dedb5374846 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_FishEyeCameras_silhouette.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_FoVOrthographicCameras_silhouette.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_FoVOrthographicCameras_silhouette.png new file mode 100644 index 0000000000000000000000000000000000000000..df0c3d0a218fdf1ec47d9e8125640090106e55db Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_FoVOrthographicCameras_silhouette.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_FoVPerspectiveCameras_silhouette.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_FoVPerspectiveCameras_silhouette.png new file mode 100644 index 0000000000000000000000000000000000000000..86d9217b751e4a5fc46c86d4b5683bb28296f143 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_FoVPerspectiveCameras_silhouette.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_OrthographicCameras_silhouette.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_OrthographicCameras_silhouette.png new file mode 100644 index 0000000000000000000000000000000000000000..df0c3d0a218fdf1ec47d9e8125640090106e55db Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_OrthographicCameras_silhouette.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_PerspectiveCameras_silhouette.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_PerspectiveCameras_silhouette.png new file mode 100644 index 0000000000000000000000000000000000000000..a6fd9978e7ef126de49b3a249e187dedb5374846 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_PerspectiveCameras_silhouette.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_blurry_textured_rendering.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_blurry_textured_rendering.png new file mode 100644 index 0000000000000000000000000000000000000000..a71726b083324fe527ced8a4ebfd24c616696d9d Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_blurry_textured_rendering.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_bridge_pointcloud.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_bridge_pointcloud.png new file mode 100644 index 0000000000000000000000000000000000000000..be76dea6c8162a188b1d77981e07dee24f5a303b Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_bridge_pointcloud.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_cow_image_rectangle_MeshRasterizer.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_cow_image_rectangle_MeshRasterizer.png new file mode 100644 index 0000000000000000000000000000000000000000..14f11d70ff5f34357951f99080de608fe966e170 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_cow_image_rectangle_MeshRasterizer.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_cow_mesh_FishEyeCameras_radial_False_tangential_False_prism_False.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_cow_mesh_FishEyeCameras_radial_False_tangential_False_prism_False.png new file mode 100644 index 0000000000000000000000000000000000000000..8eb243739213c64c85e1d437c40268de42a6ce59 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_cow_mesh_FishEyeCameras_radial_False_tangential_False_prism_False.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_cow_mesh_FishEyeCameras_radial_False_tangential_False_prism_True.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_cow_mesh_FishEyeCameras_radial_False_tangential_False_prism_True.png new file mode 100644 index 0000000000000000000000000000000000000000..15f095ef630ee9ad659ef8a405678f46015e1039 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_cow_mesh_FishEyeCameras_radial_False_tangential_False_prism_True.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_cow_mesh_FishEyeCameras_radial_False_tangential_True_prism_False.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_cow_mesh_FishEyeCameras_radial_False_tangential_True_prism_False.png new file mode 100644 index 0000000000000000000000000000000000000000..120bc42b2d9a6192443db11690a93238f06ddbfb Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_cow_mesh_FishEyeCameras_radial_False_tangential_True_prism_False.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_cow_mesh_FishEyeCameras_radial_False_tangential_True_prism_True.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_cow_mesh_FishEyeCameras_radial_False_tangential_True_prism_True.png new file mode 100644 index 0000000000000000000000000000000000000000..7447642dae63407348b37010ea6b16b886a27cc6 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_cow_mesh_FishEyeCameras_radial_False_tangential_True_prism_True.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_cow_mesh_FishEyeCameras_radial_True_tangential_False_prism_False.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_cow_mesh_FishEyeCameras_radial_True_tangential_False_prism_False.png new file mode 100644 index 0000000000000000000000000000000000000000..e794f1ab52b6dc7cce46fd0295eeb8f302a4c704 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_cow_mesh_FishEyeCameras_radial_True_tangential_False_prism_False.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_cow_mesh_FishEyeCameras_radial_True_tangential_False_prism_True.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_cow_mesh_FishEyeCameras_radial_True_tangential_False_prism_True.png new file mode 100644 index 0000000000000000000000000000000000000000..7ffcd969f2119cb90f665a2d6f01ae024d6d917c Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_cow_mesh_FishEyeCameras_radial_True_tangential_False_prism_True.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_cow_mesh_FishEyeCameras_radial_True_tangential_True_prism_False.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_cow_mesh_FishEyeCameras_radial_True_tangential_True_prism_False.png new file mode 100644 index 0000000000000000000000000000000000000000..7d74060811346893373ff939fd81cccbef6f5d7b Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_cow_mesh_FishEyeCameras_radial_True_tangential_True_prism_False.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_cow_mesh_FishEyeCameras_radial_True_tangential_True_prism_True.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_cow_mesh_FishEyeCameras_radial_True_tangential_True_prism_True.png new file mode 100644 index 0000000000000000000000000000000000000000..785e44250bd89552d1061836b628e71fef50ef70 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_cow_mesh_FishEyeCameras_radial_True_tangential_True_prism_True.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_fisheye_rasterized_sphere_MeshRasterizer.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_fisheye_rasterized_sphere_MeshRasterizer.png new file mode 100644 index 0000000000000000000000000000000000000000..9387f060f2df1344e8f3965da42e88fcfbcfe969 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_fisheye_rasterized_sphere_MeshRasterizer.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinatlas_1_MeshRasterizer.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinatlas_1_MeshRasterizer.png new file mode 100644 index 0000000000000000000000000000000000000000..fd959d9b778d6a2da0c9db07817a73e2c16d68be Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinatlas_1_MeshRasterizer.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinatlas_1_MeshRasterizerOpenGL.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinatlas_1_MeshRasterizerOpenGL.png new file mode 100644 index 0000000000000000000000000000000000000000..681ce5da216c09fe5e08180ca2266d1a3865a204 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinatlas_1_MeshRasterizerOpenGL.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinatlas_2_MeshRasterizer.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinatlas_2_MeshRasterizer.png new file mode 100644 index 0000000000000000000000000000000000000000..a0aae8dc4208efaba735f867de89af60c39d44ec Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinatlas_2_MeshRasterizer.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinatlas_2_MeshRasterizerOpenGL.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinatlas_2_MeshRasterizerOpenGL.png new file mode 100644 index 0000000000000000000000000000000000000000..a81473c47efc619df8e19e9bf56e1339fbc57aa3 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinatlas_2_MeshRasterizerOpenGL.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinatlas_final_MeshRasterizer.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinatlas_final_MeshRasterizer.png new file mode 100644 index 0000000000000000000000000000000000000000..3f7605553377b66155077531a28daa108e6c6d0c Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinatlas_final_MeshRasterizer.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinatlas_final_MeshRasterizerOpenGL.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinatlas_final_MeshRasterizerOpenGL.png new file mode 100644 index 0000000000000000000000000000000000000000..2d9836cf5e0fea6db6562fd867102aa7c8ac5f78 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinatlas_final_MeshRasterizerOpenGL.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joined_spheres_flat.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joined_spheres_flat.png new file mode 100644 index 0000000000000000000000000000000000000000..71810990c64a43523e781d0bbe1509d2596c6482 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joined_spheres_flat.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joined_spheres_gouraud.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joined_spheres_gouraud.png new file mode 100644 index 0000000000000000000000000000000000000000..b34052c25f4bf5bfaf15a022fae06066700cb0b4 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joined_spheres_gouraud.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joined_spheres_phong.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joined_spheres_phong.png new file mode 100644 index 0000000000000000000000000000000000000000..13d254a014ee9ebe548fa54f1d7f823654cd6190 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joined_spheres_phong.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joined_spheres_splatter.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joined_spheres_splatter.png new file mode 100644 index 0000000000000000000000000000000000000000..c6dedc03119d9198e44b5f9796b8bf09f5a053e7 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joined_spheres_splatter.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinuvs0_MeshRasterizerOpenGL_final.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinuvs0_MeshRasterizerOpenGL_final.png new file mode 100644 index 0000000000000000000000000000000000000000..f861b52242a2b31fb8b0fb661a531217eda04352 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinuvs0_MeshRasterizerOpenGL_final.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinuvs0_MeshRasterizer_final.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinuvs0_MeshRasterizer_final.png new file mode 100644 index 0000000000000000000000000000000000000000..4fc3b6612ab08ecfe064a13478bccc24795f6600 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinuvs0_MeshRasterizer_final.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinuvs0_map.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinuvs0_map.png new file mode 100644 index 0000000000000000000000000000000000000000..163afcf61f6606f413de1f4e20cd42a11947de31 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinuvs0_map.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinuvs1_MeshRasterizerOpenGL_final.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinuvs1_MeshRasterizerOpenGL_final.png new file mode 100644 index 0000000000000000000000000000000000000000..f8725db95b836e31762e9a23ee9881759d8fe630 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinuvs1_MeshRasterizerOpenGL_final.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinuvs1_MeshRasterizer_final.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinuvs1_MeshRasterizer_final.png new file mode 100644 index 0000000000000000000000000000000000000000..09ba1d7878df1067ec98db1b8a874a1c095fae9d Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinuvs1_MeshRasterizer_final.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinuvs1_map.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinuvs1_map.png new file mode 100644 index 0000000000000000000000000000000000000000..616d08e83e9579a73b30281235018d43948fb1dd Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinuvs1_map.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinuvs2_MeshRasterizerOpenGL_final.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinuvs2_MeshRasterizerOpenGL_final.png new file mode 100644 index 0000000000000000000000000000000000000000..c2ddec8811f5b5f15390e5b59b5764feab363a7d Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinuvs2_MeshRasterizerOpenGL_final.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinuvs2_MeshRasterizer_final.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinuvs2_MeshRasterizer_final.png new file mode 100644 index 0000000000000000000000000000000000000000..2c93a46101bc90b859d22f482d1e3c45ac1e3880 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinuvs2_MeshRasterizer_final.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinuvs2_map.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinuvs2_map.png new file mode 100644 index 0000000000000000000000000000000000000000..ac9c43b02a50c6b37e13eb1ea1b810b04dabdec4 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinuvs2_map.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinverts_final_MeshRasterizer.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinverts_final_MeshRasterizer.png new file mode 100644 index 0000000000000000000000000000000000000000..9f85e06ffcb1a6790f8038b3f2b49215600ff03c Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinverts_final_MeshRasterizer.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinverts_final_MeshRasterizerOpenGL.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinverts_final_MeshRasterizerOpenGL.png new file mode 100644 index 0000000000000000000000000000000000000000..59f04d550a416d8aadd194308c34244ee4f0fa4d Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_joinverts_final_MeshRasterizerOpenGL.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_nd_sphere.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_nd_sphere.png new file mode 100644 index 0000000000000000000000000000000000000000..cf2f9a9eaef249f834dd2031de1593add12574cc Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_nd_sphere.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_perspective_rasterized_sphere_MeshRasterizer.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_perspective_rasterized_sphere_MeshRasterizer.png new file mode 100644 index 0000000000000000000000000000000000000000..9387f060f2df1344e8f3965da42e88fcfbcfe969 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_perspective_rasterized_sphere_MeshRasterizer.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_pointcloud_rectangle_image.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_pointcloud_rectangle_image.png new file mode 100644 index 0000000000000000000000000000000000000000..8bf30329477ed9d2a3945c63451fb05c32e33a93 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_pointcloud_rectangle_image.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_pulsar_simple_pointcloud_sphere_azimuth0.0_fovorthographic.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_pulsar_simple_pointcloud_sphere_azimuth0.0_fovorthographic.png new file mode 100644 index 0000000000000000000000000000000000000000..34c15cfdc9e26040b97136f753efadcf641438d2 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_pulsar_simple_pointcloud_sphere_azimuth0.0_fovorthographic.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_pulsar_simple_pointcloud_sphere_azimuth0.0_fovperspective.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_pulsar_simple_pointcloud_sphere_azimuth0.0_fovperspective.png new file mode 100644 index 0000000000000000000000000000000000000000..bbeb88078e19ad95401d3d29e838fa6bc2ea94e5 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_pulsar_simple_pointcloud_sphere_azimuth0.0_fovperspective.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_pulsar_simple_pointcloud_sphere_azimuth0.0_orthographic.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_pulsar_simple_pointcloud_sphere_azimuth0.0_orthographic.png new file mode 100644 index 0000000000000000000000000000000000000000..34c15cfdc9e26040b97136f753efadcf641438d2 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_pulsar_simple_pointcloud_sphere_azimuth0.0_orthographic.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_pulsar_simple_pointcloud_sphere_azimuth0.0_perspective.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_pulsar_simple_pointcloud_sphere_azimuth0.0_perspective.png new file mode 100644 index 0000000000000000000000000000000000000000..3bfa4d147cd91fa6f0a2324e29ecaeac87871539 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_pulsar_simple_pointcloud_sphere_azimuth0.0_perspective.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_pulsar_simple_pointcloud_sphere_azimuth90.0_fovorthographic.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_pulsar_simple_pointcloud_sphere_azimuth90.0_fovorthographic.png new file mode 100644 index 0000000000000000000000000000000000000000..53ec18de39bccfc0c62392675bf6af7729b4a1b0 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_pulsar_simple_pointcloud_sphere_azimuth90.0_fovorthographic.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_pulsar_simple_pointcloud_sphere_azimuth90.0_fovperspective.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_pulsar_simple_pointcloud_sphere_azimuth90.0_fovperspective.png new file mode 100644 index 0000000000000000000000000000000000000000..f378283bd2aeecafd4b3540325af66bab4b634f7 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_pulsar_simple_pointcloud_sphere_azimuth90.0_fovperspective.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_pulsar_simple_pointcloud_sphere_azimuth90.0_orthographic.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_pulsar_simple_pointcloud_sphere_azimuth90.0_orthographic.png new file mode 100644 index 0000000000000000000000000000000000000000..53ec18de39bccfc0c62392675bf6af7729b4a1b0 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_pulsar_simple_pointcloud_sphere_azimuth90.0_orthographic.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_pulsar_simple_pointcloud_sphere_azimuth90.0_perspective.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_pulsar_simple_pointcloud_sphere_azimuth90.0_perspective.png new file mode 100644 index 0000000000000000000000000000000000000000..ab01389a8e0277587fca685bf5f178dbecb76f54 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_pulsar_simple_pointcloud_sphere_azimuth90.0_perspective.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_r2n2_render_by_categories_0.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_r2n2_render_by_categories_0.png new file mode 100644 index 0000000000000000000000000000000000000000..03fb791ed35cb5be0b793a317e35919bc261c052 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_r2n2_render_by_categories_0.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_r2n2_render_by_categories_1.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_r2n2_render_by_categories_1.png new file mode 100644 index 0000000000000000000000000000000000000000..871e5594ced0202f220e944609adf90b26402b4b Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_r2n2_render_by_categories_1.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_r2n2_render_by_categories_2.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_r2n2_render_by_categories_2.png new file mode 100644 index 0000000000000000000000000000000000000000..461dba8e96d8293c8d4403526ca595e13619df98 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_r2n2_render_by_categories_2.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_r2n2_render_by_idxs_and_ids_0.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_r2n2_render_by_idxs_and_ids_0.png new file mode 100644 index 0000000000000000000000000000000000000000..d16c2ad99abaef132d947e32eb0817f99a2079b2 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_r2n2_render_by_idxs_and_ids_0.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_r2n2_render_by_idxs_and_ids_1.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_r2n2_render_by_idxs_and_ids_1.png new file mode 100644 index 0000000000000000000000000000000000000000..ae285391ef7a7341fabeddc4b6bbb49b911c2a76 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_r2n2_render_by_idxs_and_ids_1.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_r2n2_render_by_idxs_and_ids_2.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_r2n2_render_by_idxs_and_ids_2.png new file mode 100644 index 0000000000000000000000000000000000000000..b953b232de8e8cf9e123d3196cb6ad866edab32d Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_r2n2_render_by_idxs_and_ids_2.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_r2n2_render_with_blender_calibrations_0.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_r2n2_render_with_blender_calibrations_0.png new file mode 100644 index 0000000000000000000000000000000000000000..c9c169c99b1313f3dcc29cccffdf565b2e0cc3b8 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_r2n2_render_with_blender_calibrations_0.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_r2n2_render_with_blender_calibrations_1.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_r2n2_render_with_blender_calibrations_1.png new file mode 100644 index 0000000000000000000000000000000000000000..7c86933805f4485224516a27353792ccf807e9cf Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_r2n2_render_with_blender_calibrations_1.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_r2n2_render_with_blender_calibrations_2.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_r2n2_render_with_blender_calibrations_2.png new file mode 100644 index 0000000000000000000000000000000000000000..1cbda3d4c45a3559df87eae90e83b0552952392c Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_r2n2_render_with_blender_calibrations_2.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_r2n2_render_with_blender_calibrations_3.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_r2n2_render_with_blender_calibrations_3.png new file mode 100644 index 0000000000000000000000000000000000000000..4d907198605638cbd84f58951afb4856d29858fa Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_r2n2_render_with_blender_calibrations_3.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_r2n2_voxel_to_mesh_render.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_r2n2_voxel_to_mesh_render.png new file mode 100644 index 0000000000000000000000000000000000000000..d458298ac6681aedb00559eee7da55290305bae6 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_r2n2_voxel_to_mesh_render.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_rasterized_fisheye_sphere_points.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_rasterized_fisheye_sphere_points.png new file mode 100644 index 0000000000000000000000000000000000000000..f80690c557d444e05f13b113ac62809756b23f25 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_rasterized_fisheye_sphere_points.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_rasterized_perspective_sphere_points.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_rasterized_perspective_sphere_points.png new file mode 100644 index 0000000000000000000000000000000000000000..f80690c557d444e05f13b113ac62809756b23f25 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_rasterized_perspective_sphere_points.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_rasterized_sphere_MeshRasterizer.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_rasterized_sphere_MeshRasterizer.png new file mode 100644 index 0000000000000000000000000000000000000000..574800946c2251fc360828049707b5aae408b2c5 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_rasterized_sphere_MeshRasterizer.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_rasterized_sphere_MeshRasterizerOpenGL.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_rasterized_sphere_MeshRasterizerOpenGL.png new file mode 100644 index 0000000000000000000000000000000000000000..1175949d46aa77b63a9377bb7f0156d6f99168a8 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_rasterized_sphere_MeshRasterizerOpenGL.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_rasterized_sphere_zoom_MeshRasterizer.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_rasterized_sphere_zoom_MeshRasterizer.png new file mode 100644 index 0000000000000000000000000000000000000000..7c44b0963730775b0d583718bf54413e526c84bc Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_rasterized_sphere_zoom_MeshRasterizer.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_rasterized_sphere_zoom_MeshRasterizerOpenGL.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_rasterized_sphere_zoom_MeshRasterizerOpenGL.png new file mode 100644 index 0000000000000000000000000000000000000000..7c44b0963730775b0d583718bf54413e526c84bc Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_rasterized_sphere_zoom_MeshRasterizerOpenGL.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_render_fisheye_sphere_points.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_render_fisheye_sphere_points.png new file mode 100644 index 0000000000000000000000000000000000000000..711293293231bfb92d9069f6eba9347297c7106d Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_render_fisheye_sphere_points.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_shapenet_core_render_mixed_by_categories_0.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_shapenet_core_render_mixed_by_categories_0.png new file mode 100644 index 0000000000000000000000000000000000000000..5104bd71415beeccb70589a4cf1e52cdef6b27e8 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_shapenet_core_render_mixed_by_categories_0.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_shapenet_core_render_mixed_by_categories_1.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_shapenet_core_render_mixed_by_categories_1.png new file mode 100644 index 0000000000000000000000000000000000000000..4df6712209ca0b7d5ddd8fad27e81429dcdf82c8 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_shapenet_core_render_mixed_by_categories_1.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_shapenet_core_render_mixed_by_categories_2.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_shapenet_core_render_mixed_by_categories_2.png new file mode 100644 index 0000000000000000000000000000000000000000..e1c5ebb033953c3cba9f65356ed050e4c550556a Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_shapenet_core_render_mixed_by_categories_2.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_shapenet_core_render_piano.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_shapenet_core_render_piano.png new file mode 100644 index 0000000000000000000000000000000000000000..fc7524c89e5ea51bd36560a19efb938f75681c80 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_shapenet_core_render_piano.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_shapenet_core_render_piano_0.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_shapenet_core_render_piano_0.png new file mode 100644 index 0000000000000000000000000000000000000000..fc7524c89e5ea51bd36560a19efb938f75681c80 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_shapenet_core_render_piano_0.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_shapenet_core_render_piano_1.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_shapenet_core_render_piano_1.png new file mode 100644 index 0000000000000000000000000000000000000000..b53a022a4efc7963030618027ad4d16ea63703d8 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_shapenet_core_render_piano_1.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_shapenet_core_render_piano_2.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_shapenet_core_render_piano_2.png new file mode 100644 index 0000000000000000000000000000000000000000..fdcd4933407a74a14e84d0d75176441fd726e3a7 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_shapenet_core_render_piano_2.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_shapenet_core_render_without_sample_nums_0.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_shapenet_core_render_without_sample_nums_0.png new file mode 100644 index 0000000000000000000000000000000000000000..3fe33135bc2d21a474d631038b5dd808f23ea8b4 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_shapenet_core_render_without_sample_nums_0.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_shapenet_core_render_without_sample_nums_1.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_shapenet_core_render_without_sample_nums_1.png new file mode 100644 index 0000000000000000000000000000000000000000..cbf4d6924494ff7036f3415afcc84721af8fbc20 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_shapenet_core_render_without_sample_nums_1.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_simple_pointcloud_sphere.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_simple_pointcloud_sphere.png new file mode 100644 index 0000000000000000000000000000000000000000..aae845c7424871a120608aa5de1e1b2eb5e5f557 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_simple_pointcloud_sphere.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_simple_sphere_batched_flat_FoVPerspectiveCameras.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_simple_sphere_batched_flat_FoVPerspectiveCameras.png new file mode 100644 index 0000000000000000000000000000000000000000..891d6be37ae47de25d5f0a276041d6be797f0b8d Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_simple_sphere_batched_flat_FoVPerspectiveCameras.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_simple_sphere_batched_flat_FoVPerspectiveCameras_0.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_simple_sphere_batched_flat_FoVPerspectiveCameras_0.png new file mode 100644 index 0000000000000000000000000000000000000000..e34ce8fc9b31898f07590e05c3bda30b8233020d Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_simple_sphere_batched_flat_FoVPerspectiveCameras_0.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_simple_sphere_batched_flat_FoVPerspectiveCameras_1.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_simple_sphere_batched_flat_FoVPerspectiveCameras_1.png new file mode 100644 index 0000000000000000000000000000000000000000..0486c2ccb4f8b70b63a57d77873c162af487fc35 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_simple_sphere_batched_flat_FoVPerspectiveCameras_1.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_simple_sphere_batched_flat_FoVPerspectiveCameras_2.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_simple_sphere_batched_flat_FoVPerspectiveCameras_2.png new file mode 100644 index 0000000000000000000000000000000000000000..d89a18b72ed3f21c1ab1015e1ec0c61c85f91ebb Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_simple_sphere_batched_flat_FoVPerspectiveCameras_2.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_simple_sphere_batched_gouraud_FoVPerspectiveCameras.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_simple_sphere_batched_gouraud_FoVPerspectiveCameras.png new file mode 100644 index 0000000000000000000000000000000000000000..4f2d4cba34202965c2659d8a6fd373affad0e81d Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_simple_sphere_batched_gouraud_FoVPerspectiveCameras.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_simple_sphere_batched_gouraud_FoVPerspectiveCameras_0.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_simple_sphere_batched_gouraud_FoVPerspectiveCameras_0.png new file mode 100644 index 0000000000000000000000000000000000000000..f29552afee70190c59f60cc49724ae436f799cc4 Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_simple_sphere_batched_gouraud_FoVPerspectiveCameras_0.png differ diff --git a/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_simple_sphere_batched_gouraud_FoVPerspectiveCameras_2.png b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_simple_sphere_batched_gouraud_FoVPerspectiveCameras_2.png new file mode 100644 index 0000000000000000000000000000000000000000..65286bc0ce29692810b6a6705aee99856514b7da Binary files /dev/null and b/third_party/AnyBimanual/third_party/pytorch3d/tests/data/test_simple_sphere_batched_gouraud_FoVPerspectiveCameras_2.png differ