Skip to content

Commit a2c6af9

Browse files
bottlerfacebook-github-bot
authored andcommitted
more code blocks for readthedocs
Summary: More rst syntax fixes Reviewed By: davidsonic Differential Revision: D40977328 fbshipit-source-id: a3a3accbf2ba7cd9c84a0a82d0265010764a9d61
1 parent 94f321f commit a2c6af9

File tree

14 files changed

+172
-179
lines changed

14 files changed

+172
-179
lines changed

pytorch3d/io/pluggable.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,16 @@
2525
The main usage is via the IO object, and its methods
2626
`load_mesh`, `save_mesh`, `load_pointcloud` and `save_pointcloud`.
2727
28-
For example, to load a mesh you might do
29-
```
30-
from pytorch3d.io import IO
28+
For example, to load a mesh you might do::
3129
32-
mesh = IO().load_mesh("mymesh.obj")
33-
```
30+
from pytorch3d.io import IO
3431
35-
and to save a point cloud you might do
32+
mesh = IO().load_mesh("mymesh.obj")
3633
37-
```
38-
pcl = Pointclouds(...)
39-
IO().save_pointcloud(pcl, "output_pointcloud.obj")
40-
```
34+
and to save a point cloud you might do::
35+
36+
pcl = Pointclouds(...)
37+
IO().save_pointcloud(pcl, "output_pointcloud.obj")
4138
4239
"""
4340

pytorch3d/io/ply_io.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,33 +1067,33 @@ def load_ply(
10671067
is to use the IO.load_mesh and IO.load_pointcloud functions,
10681068
which can read more of the data.
10691069
1070-
Example .ply file format:
1071-
1072-
ply
1073-
format ascii 1.0 { ascii/binary, format version number }
1074-
comment made by Greg Turk { comments keyword specified, like all lines }
1075-
comment this file is a cube
1076-
element vertex 8 { define "vertex" element, 8 of them in file }
1077-
property float x { vertex contains float "x" coordinate }
1078-
property float y { y coordinate is also a vertex property }
1079-
property float z { z coordinate, too }
1080-
element face 6 { there are 6 "face" elements in the file }
1081-
property list uchar int vertex_index { "vertex_indices" is a list of ints }
1082-
end_header { delimits the end of the header }
1083-
0 0 0 { start of vertex list }
1084-
0 0 1
1085-
0 1 1
1086-
0 1 0
1087-
1 0 0
1088-
1 0 1
1089-
1 1 1
1090-
1 1 0
1091-
4 0 1 2 3 { start of face list }
1092-
4 7 6 5 4
1093-
4 0 4 5 1
1094-
4 1 5 6 2
1095-
4 2 6 7 3
1096-
4 3 7 4 0
1070+
Example .ply file format::
1071+
1072+
ply
1073+
format ascii 1.0 { ascii/binary, format version number }
1074+
comment made by Greg Turk { comments keyword specified, like all lines }
1075+
comment this file is a cube
1076+
element vertex 8 { define "vertex" element, 8 of them in file }
1077+
property float x { vertex contains float "x" coordinate }
1078+
property float y { y coordinate is also a vertex property }
1079+
property float z { z coordinate, too }
1080+
element face 6 { there are 6 "face" elements in the file }
1081+
property list uchar int vertex_index { "vertex_indices" is a list of ints }
1082+
end_header { delimits the end of the header }
1083+
0 0 0 { start of vertex list }
1084+
0 0 1
1085+
0 1 1
1086+
0 1 0
1087+
1 0 0
1088+
1 0 1
1089+
1 1 1
1090+
1 1 0
1091+
4 0 1 2 3 { start of face list }
1092+
4 7 6 5 4
1093+
4 0 4 5 1
1094+
4 1 5 6 2
1095+
4 2 6 7 3
1096+
4 3 7 4 0
10971097
10981098
Args:
10991099
f: A binary or text file-like object (with methods read, readline,

pytorch3d/ops/points_to_volumes.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ def add_pointclouds_to_volumes(
208208
of `initial_volumes` with its `features` and `densities` updated with the
209209
result of the pointcloud addition.
210210
211-
Example:
212-
```
211+
Example::
212+
213213
# init a random point cloud
214214
pointclouds = Pointclouds(
215215
points=torch.randn(4, 100, 3), features=torch.rand(4, 100, 5)
@@ -229,7 +229,6 @@ def add_pointclouds_to_volumes(
229229
initial_volumes=initial_volumes,
230230
mode="trilinear",
231231
)
232-
```
233232
234233
Args:
235234
pointclouds: Batch of 3D pointclouds represented with a `Pointclouds`

pytorch3d/renderer/implicit/harmonic_embedding.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ def __init__(
2121
(i.e. vector along the last dimension) in `x`
2222
into a series of harmonic features `embedding`,
2323
where for each i in range(dim) the following are present
24-
in embedding[...]:
25-
```
24+
in embedding[...]::
25+
2626
[
2727
sin(f_1*x[..., i]),
2828
sin(f_2*x[..., i]),
@@ -34,7 +34,7 @@ def __init__(
3434
cos(f_N * x[..., i]),
3535
x[..., i], # only present if append_input is True.
3636
]
37-
```
37+
3838
where N corresponds to `n_harmonic_functions-1`, and f_i is a scalar
3939
denoting the i-th frequency of the harmonic embedding.
4040

pytorch3d/renderer/implicit/raymarching.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,20 @@ class EmissionAbsorptionRaymarcher(torch.nn.Module):
2525
(i.e. its density -> 1.0).
2626
2727
EA first utilizes `rays_densities` to compute the absorption function
28-
along each ray as follows:
29-
```
28+
along each ray as follows::
29+
3030
absorption = cumprod(1 - rays_densities, dim=-1)
31-
```
31+
3232
The value of absorption at position `absorption[..., k]` specifies
3333
how much light has reached `k`-th point along a ray since starting
3434
its trajectory at `k=0`-th point.
3535
3636
Each ray is then rendered into a tensor `features` of shape `(..., feature_dim)`
37-
by taking a weighed combination of per-ray features `rays_features` as follows:
38-
```
37+
by taking a weighed combination of per-ray features `rays_features` as follows::
38+
3939
weights = absorption * rays_densities
4040
features = (rays_features * weights).sum(dim=-2)
41-
```
41+
4242
Where `weights` denote a function that has a strong peak around the location
4343
of the first surface point that a given ray passes through.
4444

pytorch3d/renderer/implicit/raysampling.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,22 @@ class MultinomialRaysampler(torch.nn.Module):
3232
have uniformly-spaced z-coordinates between a predefined
3333
minimum and maximum depth.
3434
35-
The raysampler first generates a 3D coordinate grid of the following form:
36-
```
37-
/ min_x, min_y, max_depth -------------- / max_x, min_y, max_depth
38-
/ /|
39-
/ / | ^
40-
/ min_depth min_depth / | |
41-
min_x ----------------------------- max_x | | image
42-
min_y min_y | | height
43-
| | | |
44-
| | | v
45-
| | |
46-
| | / max_x, max_y, ^
47-
| | / max_depth /
48-
min_x max_y / / n_pts_per_ray
49-
max_y ----------------------------- max_x/ min_depth v
50-
< --- image_width --- >
51-
```
35+
The raysampler first generates a 3D coordinate grid of the following form::
36+
37+
/ min_x, min_y, max_depth -------------- / max_x, min_y, max_depth
38+
/ /|
39+
/ / | ^
40+
/ min_depth min_depth / | |
41+
min_x ----------------------------- max_x | | image
42+
min_y min_y | | height
43+
| | | |
44+
| | | v
45+
| | |
46+
| | / max_x, max_y, ^
47+
| | / max_depth /
48+
min_x max_y / / n_pts_per_ray
49+
max_y ----------------------------- max_x/ min_depth v
50+
< --- image_width --- >
5251
5352
In order to generate ray points, `MultinomialRaysampler` takes each 3D point of
5453
the grid (with coordinates `[x, y, depth]`) and unprojects it

pytorch3d/renderer/implicit/renderer.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ class ImplicitRenderer(torch.nn.Module):
4141
as well as the `volumetric_function` `Callable`, which defines a field of opacity
4242
and feature vectors over the 3D domain of the scene.
4343
44-
A standard `volumetric_function` has the following signature:
45-
```
46-
def volumetric_function(
47-
ray_bundle: Union[RayBundle, HeterogeneousRayBundle],
48-
**kwargs,
49-
) -> Tuple[torch.Tensor, torch.Tensor]
50-
```
44+
A standard `volumetric_function` has the following signature::
45+
46+
def volumetric_function(
47+
ray_bundle: Union[RayBundle, HeterogeneousRayBundle],
48+
**kwargs,
49+
) -> Tuple[torch.Tensor, torch.Tensor]
50+
5151
With the following arguments:
5252
`ray_bundle`: A RayBundle or HeterogeneousRayBundle object
5353
containing the following variables:
@@ -79,32 +79,32 @@ def volumetric_function(
7979
8080
Example:
8181
A simple volumetric function of a 0-centered
82-
RGB sphere with a unit diameter is defined as follows:
83-
```
84-
def volumetric_function(
85-
ray_bundle: Union[RayBundle, HeterogeneousRayBundle],
86-
**kwargs,
87-
) -> Tuple[torch.Tensor, torch.Tensor]:
82+
RGB sphere with a unit diameter is defined as follows::
8883
89-
# first convert the ray origins, directions and lengths
90-
# to 3D ray point locations in world coords
91-
rays_points_world = ray_bundle_to_ray_points(ray_bundle)
84+
def volumetric_function(
85+
ray_bundle: Union[RayBundle, HeterogeneousRayBundle],
86+
**kwargs,
87+
) -> Tuple[torch.Tensor, torch.Tensor]:
9288
93-
# set the densities as an inverse sigmoid of the
94-
# ray point distance from the sphere centroid
95-
rays_densities = torch.sigmoid(
96-
-100.0 * rays_points_world.norm(dim=-1, keepdim=True)
97-
)
89+
# first convert the ray origins, directions and lengths
90+
# to 3D ray point locations in world coords
91+
rays_points_world = ray_bundle_to_ray_points(ray_bundle)
92+
93+
# set the densities as an inverse sigmoid of the
94+
# ray point distance from the sphere centroid
95+
rays_densities = torch.sigmoid(
96+
-100.0 * rays_points_world.norm(dim=-1, keepdim=True)
97+
)
98+
99+
# set the ray features to RGB colors proportional
100+
# to the 3D location of the projection of ray points
101+
# on the sphere surface
102+
rays_features = torch.nn.functional.normalize(
103+
rays_points_world, dim=-1
104+
) * 0.5 + 0.5
98105
99-
# set the ray features to RGB colors proportional
100-
# to the 3D location of the projection of ray points
101-
# on the sphere surface
102-
rays_features = torch.nn.functional.normalize(
103-
rays_points_world, dim=-1
104-
) * 0.5 + 0.5
106+
return rays_densities, rays_features
105107
106-
return rays_densities, rays_features
107-
```
108108
"""
109109

110110
def __init__(self, raysampler: Callable, raymarcher: Callable) -> None:

pytorch3d/renderer/implicit/utils.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ def ray_bundle_to_ray_points(
7373
extending each ray according to the corresponding length.
7474
7575
E.g. for 2 dimensional tensors `ray_bundle.origins`, `ray_bundle.directions`
76-
and `ray_bundle.lengths`, the ray point at position `[i, j]` is:
77-
```
76+
and `ray_bundle.lengths`, the ray point at position `[i, j]` is::
77+
7878
ray_bundle.points[i, j, :] = (
7979
ray_bundle.origins[i, :]
8080
+ ray_bundle.directions[i, :] * ray_bundle.lengths[i, j]
8181
)
82-
```
82+
8383
Note that both the directions and magnitudes of the vectors in
8484
`ray_bundle.directions` matter.
8585
@@ -109,13 +109,13 @@ def ray_bundle_variables_to_ray_points(
109109
ray length:
110110
111111
E.g. for 2 dimensional input tensors `rays_origins`, `rays_directions`
112-
and `rays_lengths`, the ray point at position `[i, j]` is:
113-
```
112+
and `rays_lengths`, the ray point at position `[i, j]` is::
113+
114114
rays_points[i, j, :] = (
115115
rays_origins[i, :]
116116
+ rays_directions[i, :] * rays_lengths[i, j]
117117
)
118-
```
118+
119119
Note that both the directions and magnitudes of the vectors in
120120
`rays_directions` matter.
121121

pytorch3d/renderer/opengl/opengl_utils.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -285,26 +285,26 @@ class _DeviceContextStore:
285285
286286
The EGL/CUDA contexts are not meant to be created and destroyed all the time,
287287
and having multiple on a single device can be troublesome. Intended use is entirely
288-
transparent to the user:
289-
290-
```
291-
rasterizer1 = MeshRasterizerOpenGL(...some args...)
292-
mesh1 = load_mesh_on_cuda_0()
293-
294-
# Now rasterizer1 will request EGL/CUDA contexts from global_device_context_store
295-
# on cuda:0, and since there aren't any, the store will create new ones.
296-
rasterizer1.rasterize(mesh1)
297-
298-
# rasterizer2 also needs EGL & CUDA contexts. But global_context_store already has
299-
# them for cuda:0. Instead of creating new contexts, the store will tell rasterizer2
300-
# to use them.
301-
rasterizer2 = MeshRasterizerOpenGL(dcs)
302-
rasterize2.rasterize(mesh1)
303-
304-
# When rasterizer1 needs to render on cuda:1, the store will create new contexts.
305-
mesh2 = load_mesh_on_cuda_1()
306-
rasterizer1.rasterize(mesh2)
307-
```
288+
transparent to the user::
289+
290+
rasterizer1 = MeshRasterizerOpenGL(...some args...)
291+
mesh1 = load_mesh_on_cuda_0()
292+
293+
# Now rasterizer1 will request EGL/CUDA contexts from
294+
# global_device_context_store on cuda:0, and since there aren't any, the
295+
# store will create new ones.
296+
rasterizer1.rasterize(mesh1)
297+
298+
# rasterizer2 also needs EGL & CUDA contexts. But global_context_store
299+
# already has them for cuda:0. Instead of creating new contexts, the store
300+
# will tell rasterizer2 to use them.
301+
rasterizer2 = MeshRasterizerOpenGL(dcs)
302+
rasterize2.rasterize(mesh1)
303+
304+
# When rasterizer1 needs to render on cuda:1, the store will create new contexts.
305+
mesh2 = load_mesh_on_cuda_1()
306+
rasterizer1.rasterize(mesh2)
307+
308308
"""
309309

310310
def __init__(self):

pytorch3d/renderer/points/pulsar/renderer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
here and a torch.nn.Module is exposed for the use in more complex models.
1212
"""
1313
import logging
14-
import math
1514
import warnings
1615
from typing import Optional, Tuple, Union
1716

0 commit comments

Comments
 (0)