4
4
# This source code is licensed under the BSD-style license found in the
5
5
# LICENSE file in the root directory of this source tree.
6
6
7
+ from dataclasses import dataclass
7
8
from typing import NamedTuple , Optional , Tuple , Union
8
9
9
10
import torch
@@ -20,46 +21,66 @@ class Fragments(NamedTuple):
20
21
dists : torch .Tensor
21
22
22
23
23
- # Class to store the mesh rasterization params with defaults
24
+ @ dataclass
24
25
class RasterizationSettings :
25
- __slots__ = [
26
- "image_size" ,
27
- "blur_radius" ,
28
- "faces_per_pixel" ,
29
- "bin_size" ,
30
- "max_faces_per_bin" ,
31
- "perspective_correct" ,
32
- "clip_barycentric_coords" ,
33
- "cull_backfaces" ,
34
- "z_clip_value" ,
35
- "cull_to_frustum" ,
36
- ]
37
-
38
- def __init__ (
39
- self ,
40
- image_size : Union [int , Tuple [int , int ]] = 256 ,
41
- blur_radius : float = 0.0 ,
42
- faces_per_pixel : int = 1 ,
43
- bin_size : Optional [int ] = None ,
44
- max_faces_per_bin : Optional [int ] = None ,
45
- # set perspective_correct = None so that the
46
- # value can be inferred correctly from the Camera type
47
- perspective_correct : Optional [bool ] = None ,
48
- clip_barycentric_coords : Optional [bool ] = None ,
49
- cull_backfaces : bool = False ,
50
- z_clip_value : Optional [float ] = None ,
51
- cull_to_frustum : bool = False ,
52
- ) -> None :
53
- self .image_size = image_size
54
- self .blur_radius = blur_radius
55
- self .faces_per_pixel = faces_per_pixel
56
- self .bin_size = bin_size
57
- self .max_faces_per_bin = max_faces_per_bin
58
- self .perspective_correct = perspective_correct
59
- self .clip_barycentric_coords = clip_barycentric_coords
60
- self .cull_backfaces = cull_backfaces
61
- self .z_clip_value = z_clip_value
62
- self .cull_to_frustum = cull_to_frustum
26
+ """
27
+ Class to store the mesh rasterization params with defaults
28
+
29
+ Members:
30
+ image_size: Either common height and width or (height, width), in pixels.
31
+ blur_radius: Float distance in the range [0, 2] used to expand the face
32
+ bounding boxes for rasterization. Setting blur radius
33
+ results in blurred edges around the shape instead of a
34
+ hard boundary. Set to 0 for no blur.
35
+ faces_per_pixel: (int) Number of faces to keep track of per pixel.
36
+ We return the nearest faces_per_pixel faces along the z-axis.
37
+ bin_size: Size of bins to use for coarse-to-fine rasterization. Setting
38
+ bin_size=0 uses naive rasterization; setting bin_size=None attempts
39
+ to set it heuristically based on the shape of the input. This should
40
+ not affect the output, but can affect the speed of the forward pass.
41
+ max_faces_per_bin: Only applicable when using coarse-to-fine
42
+ rasterization (bin_size != 0); this is the maximum number of faces
43
+ allowed within each bin. This should not affect the output values,
44
+ but can affect the memory usage in the forward pass.
45
+ Setting max_faces_per_bin=None attempts to set with a heuristic.
46
+ perspective_correct: Whether to apply perspective correction when
47
+ computing barycentric coordinates for pixels.
48
+ None (default) means make correction if the camera uses perspective.
49
+ clip_barycentric_coords: Whether, after any perspective correction
50
+ is applied but before the depth is calculated (e.g. for
51
+ z clipping), to "correct" a location outside the face (i.e. with
52
+ a negative barycentric coordinate) to a position on the edge of the
53
+ face. None (default) means clip if blur_radius > 0, which is a condition
54
+ under which such outside-face-points are likely.
55
+ cull_backfaces: Whether to only rasterize mesh faces which are
56
+ visible to the camera. This assumes that vertices of
57
+ front-facing triangles are ordered in an anti-clockwise
58
+ fashion, and triangles that face away from the camera are
59
+ in a clockwise order relative to the current view
60
+ direction. NOTE: This will only work if the mesh faces are
61
+ consistently defined with counter-clockwise ordering when
62
+ viewed from the outside.
63
+ z_clip_value: if not None, then triangles will be clipped (and possibly
64
+ subdivided into smaller triangles) such that z >= z_clip_value.
65
+ This avoids camera projections that go to infinity as z->0.
66
+ Default is None as clipping affects rasterization speed and
67
+ should only be turned on if explicitly needed.
68
+ See clip.py for all the extra computation that is required.
69
+ cull_to_frustum: Whether to cull triangles outside the view frustum.
70
+ Culling involves removing all faces which fall outside view frustum.
71
+ Default is False for performance as often not needed.
72
+ """
73
+
74
+ image_size : Union [int , Tuple [int , int ]] = 256
75
+ blur_radius : float = 0.0
76
+ faces_per_pixel : int = 1
77
+ bin_size : Optional [int ] = None
78
+ max_faces_per_bin : Optional [int ] = None
79
+ perspective_correct : Optional [bool ] = None
80
+ clip_barycentric_coords : Optional [bool ] = None
81
+ cull_backfaces : bool = False
82
+ z_clip_value : Optional [float ] = None
83
+ cull_to_frustum : bool = False
63
84
64
85
65
86
class MeshRasterizer (nn .Module ):
0 commit comments