pytorch3d.renderer.points.rasterizer
rasterizer
- class pytorch3d.renderer.points.rasterizer.PointFragments(idx: Tensor, zbuf: Tensor, dists: Tensor)[source]
Bases:
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: Tensor
Alias for field number 0
- zbuf: Tensor
Alias for field number 1
- dists: Tensor
Alias for field number 2
- class pytorch3d.renderer.points.rasterizer.PointsRasterizationSettings(image_size: int | Tuple[int, int] = 256, radius: float | Tensor = 0.01, points_per_pixel: int = 8, bin_size: int | None = None, max_points_per_bin: int | None = None)[source]
Bases:
object
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: int | Tuple[int, int] = 256
- radius: float | Tensor = 0.01
- points_per_pixel: int = 8
- bin_size: int | None = None
- max_points_per_bin: int | None = None
- class pytorch3d.renderer.points.rasterizer.PointsRasterizer(cameras=None, raster_settings=None)[source]
Bases:
Module
This class implements methods for rasterizing a batch of pointclouds.
- __init__(cameras=None, raster_settings=None) None [source]
- 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.
- transform(point_clouds, **kwargs) Pointclouds [source]
- Parameters:
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.
- forward(point_clouds, **kwargs) PointFragments [source]
- Parameters:
point_clouds – a set of point clouds with coordinates in world space.
- Returns:
PointFragments – Rasterization outputs as a named tuple.