odak.learn.raytracing
odak.learn.raytracing
Provides necessary definitions for geometric optics. See "General Ray tracing procedure" from G.H. Spencerand M.V.R.K Murty for more theoratical explanation.
detector
¶
A class to represent a detector.
Source code in odak/learn/raytracing/detector.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
__init__(colors=3, center=torch.tensor([0.0, 0.0, 0.0]), tilt=torch.tensor([0.0, 0.0, 0.0]), size=torch.tensor([10.0, 10.0]), resolution=torch.tensor([100, 100]), device=torch.device('cpu'))
¶
Parameters:
-
colors
–Number of color channels to register (e.g., RGB).
-
center
–Center point of the detector [3].
-
tilt
–Tilt angles of the surface in degrees [3].
-
size
–Size of the detector [2].
-
resolution
–Resolution of the detector.
-
device
–Device for computation (e.g., cuda, cpu).
Source code in odak/learn/raytracing/detector.py
clear()
¶
get_image()
¶
Function to return the detector image.
Returns:
-
image
(tensor
) –Detector image.
Source code in odak/learn/raytracing/detector.py
intersect(rays, color=0)
¶
Function to intersect rays with the detector
Parameters:
-
rays
–Rays to be intersected with a detector. Expected size is [1 x 2 x 3] or [m x 2 x 3].
-
color
–Color channel to register.
Returns:
-
points
(tensor
) –Intersection points with the image detector [k x 3].
Source code in odak/learn/raytracing/detector.py
planar_mesh
¶
Source code in odak/learn/raytracing/mesh.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
__init__(size=[1.0, 1.0], number_of_meshes=[10, 10], angles=torch.tensor([0.0, 0.0, 0.0]), offset=torch.tensor([0.0, 0.0, 0.0]), device=torch.device('cpu'), heights=None)
¶
Definition to generate a plane with meshes.
Parameters:
-
number_of_meshes
–Number of squares over plane. There are two triangles at each square.
-
size
–Size of the plane.
-
angles
–Rotation angles in degrees.
-
offset
–Offset along XYZ axes. Expected dimension is [1 x 3] or offset for each triangle [m x 3]. m here refers to `2 * number_of_meshes[0]` times `number_of_meshes[1]`.
-
device
–Computational resource to be used (e.g., cpu, cuda).
-
heights
–Load surface heights from a tensor.
Source code in odak/learn/raytracing/mesh.py
get_squares()
¶
Internal function to initiate squares over a plane.
Returns:
-
squares
(tensor
) –Squares over a plane. Expected size is [m x n x 3].
Source code in odak/learn/raytracing/mesh.py
get_triangles()
¶
Internal function to get triangles.
Source code in odak/learn/raytracing/mesh.py
init_heights(heights=None)
¶
Internal function to initialize a height map.
Note that self.heights is a differentiable variable, and can be optimized or learned.
See unit test test/test_learn_ray_detector.py
or test/test_learn_ray_mesh.py
as examples.
Source code in odak/learn/raytracing/mesh.py
mirror(rays)
¶
Function to bounce light rays off the meshes.
Parameters:
-
rays
–Rays to be bounced. Expected size is [2 x 3], [1 x 2 x 3] or [m x 2 x 3].
Returns:
-
reflected_rays
(tensor
) –Reflected rays. Expected size is [2 x 3], [1 x 2 x 3] or [m x 2 x 3].
-
reflected_normals
(tensor
) –Reflected normals. Expected size is [2 x 3], [1 x 2 x 3] or [m x 2 x 3].
Source code in odak/learn/raytracing/mesh.py
save_heights(filename='heights.pt')
¶
Function to save heights to a file.
Parameters:
-
filename
–Filename.
save_heights_as_PLY(filename='mesh.ply')
¶
Function to save mesh to a PLY file.
Parameters:
-
filename
–Filename.
center_of_triangle(triangle)
¶
Definition to calculate center of a triangle.
Parameters:
-
triangle
–An array that contains three points defining a triangle (Mx3). It can also parallel process many triangles (NxMx3).
Returns:
-
centers
(tensor
) –Triangle centers.
Source code in odak/learn/raytracing/primitives.py
create_ray(xyz, abg, direction=False)
¶
Definition to create a ray.
Parameters:
-
xyz
–List that contains X,Y and Z start locations of a ray. Size could be [1 x 3], [3], [m x 3].
-
abg
–List that contains angles in degrees with respect to the X,Y and Z axes. Size could be [1 x 3], [3], [m x 3].
-
direction
–If set to True, cosines of `abg` is not calculated.
Returns:
-
ray
(tensor
) –Array that contains starting points and cosines of a created ray. Size will be either [1 x 3] or [m x 3].
Source code in odak/learn/raytracing/ray.py
create_ray_from_all_pairs(x0y0z0, x1y1z1)
¶
Creates rays from all possible pairs of points in x0y0z0 and x1y1z1.
Parameters:
-
x0y0z0
–Tensor that contains X, Y, and Z start locations of rays. Size should be [m x 3].
-
x1y1z1
–Tensor that contains X, Y, and Z end locations of rays. Size should be [n x 3].
Returns:
-
rays
(tensor
) –Array that contains starting points and cosines of a created ray(s). Size of [n*m x 2 x 3]
Source code in odak/learn/raytracing/ray.py
create_ray_from_grid_w_luminous_angle(center, size, no, tilt, num_ray_per_light, angle_limit)
¶
Generate a 2D array of lights, each emitting rays within a specified solid angle and tilt.
Parameters:
center : torch.tensor The center point of the light array, shape [3]. size : list[int] The size of the light array [height, width] no : list[int] The number of the light arary [number of lights in height , number of lights inwidth] tilt : torch.tensor The tilt angles in degrees along x, y, z axes for the rays, shape [3]. angle_limit : float The maximum angle in degrees from the initial direction vector within which to emit rays. num_rays_per_light : int The number of rays each light should emit.
Returns:
rays : torch.tensor Array that contains starting points and cosines of a created ray(s). Size of [n x 2 x 3]
Source code in odak/learn/raytracing/ray.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|
create_ray_from_point_w_luminous_angle(origin, num_ray, tilt, angle_limit)
¶
Generate rays from a point, tilted by specific angles along x, y, z axes, within a specified solid angle.
Parameters:
origin : torch.tensor The origin point of the rays, shape [3]. num_rays : int The total number of rays to generate. tilt : torch.tensor The tilt angles in degrees along x, y, z axes, shape [3]. angle_limit : float The maximum angle in degrees from the initial direction vector within which to emit rays.
Returns:
rays : torch.tensor Array that contains starting points and cosines of a created ray(s). Size of [n x 2 x 3]
Source code in odak/learn/raytracing/ray.py
create_ray_from_two_points(x0y0z0, x1y1z1)
¶
Definition to create a ray from two given points. Note that both inputs must match in shape.
Parameters:
-
x0y0z0
–List that contains X,Y and Z start locations of a ray. Size could be [1 x 3], [3], [m x 3].
-
x1y1z1
–List that contains X,Y and Z ending locations of a ray or batch of rays. Size could be [1 x 3], [3], [m x 3].
Returns:
-
ray
(tensor
) –Array that contains starting points and cosines of a created ray(s).
Source code in odak/learn/raytracing/ray.py
define_circle(center, radius, angles)
¶
Definition to describe a circle in a single variable packed form.
Parameters:
-
center
–Center of a circle to be defined in 3D space.
-
radius
–Radius of a circle to be defined.
-
angles
–Angular tilt of a circle represented by rotations about x, y, and z axes.
Returns:
-
circle
(list
) –Single variable packed form.
Source code in odak/learn/raytracing/primitives.py
define_plane(point, angles=torch.tensor([0.0, 0.0, 0.0]))
¶
Definition to generate a rotation matrix along X axis.
Parameters:
-
point
–A point that is at the center of a plane.
-
angles
–Rotation angles in degrees.
Returns:
-
plane
(tensor
) –Points defining plane.
Source code in odak/learn/raytracing/primitives.py
define_plane_mesh(number_of_meshes=[10, 10], size=[1.0, 1.0], angles=torch.tensor([0.0, 0.0, 0.0]), offset=torch.tensor([[0.0, 0.0, 0.0]]))
¶
Definition to generate a plane with meshes.
Parameters:
-
number_of_meshes
–Number of squares over plane. There are two triangles at each square.
-
size
–Size of the plane.
-
angles
–Rotation angles in degrees.
-
offset
–Offset along XYZ axes. Expected dimension is [1 x 3] or offset for each triangle [m x 3]. m here refers to `2 * number_of_meshes[0]` times `number_of_meshes[1]`.
Returns:
-
triangles
(tensor
) –Triangles [m x 3 x 3], where m is
2 * number_of_meshes[0]
timesnumber_of_meshes[1]
.
Source code in odak/learn/raytracing/primitives.py
define_sphere(center=torch.tensor([[0.0, 0.0, 0.0]]), radius=torch.tensor([1.0]))
¶
Definition to define a sphere.
Parameters:
-
center
–Center of the sphere(s) along XYZ axes. Expected size is [3], [1, 3] or [m, 3].
-
radius
–Radius of that sphere(s). Expected size is [1], [1, 1], [m] or [m, 1].
Returns:
-
parameters
(tensor
) –Parameters of defined sphere(s). Expected size is [1, 3] or [m x 3].
Source code in odak/learn/raytracing/primitives.py
distance_between_two_points(point1, point2)
¶
Definition to calculate distance between two given points.
Parameters:
-
point1
–First point in X,Y,Z.
-
point2
–Second point in X,Y,Z.
Returns:
-
distance
(Tensor
) –Distance in between given two points.
Source code in odak/learn/tools/vector.py
get_sphere_normal_torch(point, sphere)
¶
Definition to get a normal of a point on a given sphere.
Parameters:
-
point
–Point on sphere in X,Y,Z.
-
sphere
–Center defined in X,Y,Z and radius.
Returns:
-
normal_vector
(tensor
) –Normal vector.
Source code in odak/learn/raytracing/boundary.py
get_triangle_normal(triangle, triangle_center=None)
¶
Definition to calculate surface normal of a triangle.
Parameters:
-
triangle
–Set of points in X,Y and Z to define a planar surface (3,3). It can also be list of triangles (mx3x3).
-
triangle_center
(tensor
, default:None
) –Center point of the given triangle. See odak.learn.raytracing.center_of_triangle for more. In many scenarios you can accelerate things by precomputing triangle centers.
Returns:
-
normal
(tensor
) –Surface normal at the point of intersection.
Source code in odak/learn/raytracing/boundary.py
grid_sample(no=[10, 10], size=[100.0, 100.0], center=[0.0, 0.0, 0.0], angles=[0.0, 0.0, 0.0])
¶
Definition to generate samples over a surface.
Parameters:
-
no
–Number of samples.
-
size
–Physical size of the surface.
-
center
–Center location of the surface.
-
angles
–Tilt of the surface.
Returns:
-
samples
(tensor
) –Samples generated.
-
rotx
(tensor
) –Rotation matrix at X axis.
-
roty
(tensor
) –Rotation matrix at Y axis.
-
rotz
(tensor
) –Rotation matrix at Z axis.
Source code in odak/learn/tools/sample.py
intersect_w_circle(ray, circle)
¶
Definition to find intersection point of a ray with a circle. Returns distance as zero if there isn't an intersection.
Parameters:
-
ray
–A vector/ray.
-
circle
–A list that contains (0) Set of points in X,Y and Z to define plane of a circle, (1) circle center, and (2) circle radius.
Returns:
-
normal
(Tensor
) –Surface normal at the point of intersection.
-
distance
(Tensor
) –Distance in between a starting point of a ray and the intersection point with a given triangle.
Source code in odak/learn/raytracing/boundary.py
intersect_w_sphere(ray, sphere, learning_rate=0.2, number_of_steps=5000, error_threshold=0.01)
¶
Definition to find the intersection between ray(s) and sphere(s).
Parameters:
-
ray
–Input ray(s). Expected size is [1 x 2 x 3] or [m x 2 x 3].
-
sphere
–Input sphere. Expected size is [1 x 4].
-
learning_rate
–Learning rate used in the optimizer for finding the propagation distances of the rays.
-
number_of_steps
–Number of steps used in the optimizer.
-
error_threshold
–The error threshold that will help deciding intersection or no intersection.
Returns:
-
intersecting_ray
(tensor
) –Ray(s) that intersecting with the given sphere. Expected size is [n x 2 x 3], where n could be any real number.
-
intersecting_normal
(tensor
) –Normal(s) for the ray(s) intersecting with the given sphere Expected size is [n x 2 x 3], where n could be any real number.
Source code in odak/learn/raytracing/boundary.py
intersect_w_surface(ray, points)
¶
Definition to find intersection point inbetween a surface and a ray. For more see: http://geomalgorithms.com/a06-_intersect-2.html
Parameters:
-
ray
–A vector/ray.
-
points
–Set of points in X,Y and Z to define a planar surface.
Returns:
-
normal
(tensor
) –Surface normal at the point of intersection.
-
distance
(float
) –Distance in between starting point of a ray with it's intersection with a planar surface.
Source code in odak/learn/raytracing/boundary.py
intersect_w_surface_batch(ray, triangle)
¶
Parameters:
-
ray
–A vector/ray (2 x 3). It can also be a list of rays (n x 2 x 3).
-
triangle
–Set of points in X,Y and Z to define a planar surface. It can also be a list of triangles (m x 3 x 3).
Returns:
-
normal
(tensor
) –Surface normal at the point of intersection (m x n x 2 x 3).
-
distance
(tensor
) –Distance in between starting point of a ray with it's intersection with a planar surface (m x n).
Source code in odak/learn/raytracing/boundary.py
intersect_w_triangle(ray, triangle)
¶
Definition to find intersection point of a ray with a triangle.
Parameters:
-
ray
–A ray [1 x 2 x 3] or a batch of ray [m x 2 x 3].
-
triangle
–Set of points in X,Y and Z to define a single triangle [1 x 3 x 3].
Returns:
-
normal
(tensor
) –Surface normal at the point of intersection with the surface of triangle. This could also involve surface normals that are not on the triangle. Expected size is [1 x 2 x 3] or [m x 2 x 3] depending on the input.
-
distance
(float
) –Distance in between a starting point of a ray and the intersection point with a given triangle. Expected size is [1 x 1] or [m x 1] depending on the input.
-
intersecting_ray
(tensor
) –Rays that intersect with the triangle plane and on the triangle. Expected size is [1 x 2 x 3] or [m x 2 x 3] depending on the input.
-
intersecting_normal
(tensor
) –Normals that intersect with the triangle plane and on the triangle. Expected size is [1 x 2 x 3] or [m x 2 x 3] depending on the input.
-
check
(tensor
) –A list that provides a bool as True or False for each ray used as input. A test to see is a ray could be on the given triangle. Expected size is [1] or [m].
Source code in odak/learn/raytracing/boundary.py
intersect_w_triangle_batch(ray, triangle)
¶
Definition to find intersection points of rays with triangles. Returns False for each variable if the rays doesn't intersect with given triangles.
Parameters:
-
ray
–vectors/rays (n x 2 x 3).
-
triangle
–Set of points in X,Y and Z to define triangles (m x 3 x 3).
Returns:
-
normal
(tensor
) –Surface normal at the point of intersection (m x n x 2 x 3).
-
distance
(List
) –Distance in between starting point of a ray with it's intersection with a planar surface (m x n).
-
intersect_ray
(List
) –List of intersecting rays (k x 2 x 3) where k <= n.
-
intersect_normal
(List
) –List of intersecting normals (k x 2 x 3) where k <= n*m.
-
check
(tensor
) –Boolean tensor (m x n) indicating whether each ray intersects with a triangle or not.
Source code in odak/learn/raytracing/boundary.py
is_it_on_triangle(point_to_check, triangle)
¶
Definition to check if a given point is inside a triangle. If the given point is inside a defined triangle, this definition returns True. For more details, visit: https://blackpawn.com/texts/pointinpoly/.
Parameters:
-
point_to_check
–Point(s) to check. Expected size is [3], [1 x 3] or [m x 3].
-
triangle
–Triangle described with three points. Expected size is [3 x 3], [1 x 3 x 3] or [m x 3 x3].
Returns:
-
result
(tensor
) –Is it on a triangle? Returns NaN if condition not satisfied. Expected size is [1] or [m] depending on the input.
Source code in odak/learn/raytracing/primitives.py
is_it_on_triangle_batch(point_to_check, triangle)
¶
Definition to check if given points are inside triangles. If the given points are inside defined triangles, this definition returns True.
Parameters:
-
point_to_check
–Points to check (m x n x 3).
-
triangle
–Triangles (m x 3 x 3).
Returns:
-
result
(torch.tensor (m x n)
) –
Source code in odak/learn/raytracing/primitives.py
propagate_ray(ray, distance)
¶
Definition to propagate a ray at a certain given distance.
Parameters:
-
ray
–A ray with a size of [2 x 3], [1 x 2 x 3] or a batch of rays with [m x 2 x 3].
-
distance
–Distance with a size of [1], [1, m] or distances with a size of [m], [1, m].
Returns:
-
new_ray
(tensor
) –Propagated ray with a size of [1 x 2 x 3] or batch of rays with [m x 2 x 3].
Source code in odak/learn/raytracing/ray.py
reflect(input_ray, normal)
¶
Definition to reflect an incoming ray from a surface defined by a surface normal. Used method described in G.H. Spencer and M.V.R.K. Murty, "General Ray-Tracing Procedure", 1961.
Parameters:
-
input_ray
–A ray or rays. Expected size is [2 x 3], [1 x 2 x 3] or [m x 2 x 3].
-
normal
–A surface normal(s). Expected size is [2 x 3], [1 x 2 x 3] or [m x 2 x 3].
Returns:
-
output_ray
(tensor
) –Array that contains starting points and cosines of a reflected ray. Expected size is [1 x 2 x 3] or [m x 2 x 3].
Source code in odak/learn/raytracing/boundary.py
refract(vector, normvector, n1, n2, error=0.01)
¶
Definition to refract an incoming ray. Used method described in G.H. Spencer and M.V.R.K. Murty, "General Ray-Tracing Procedure", 1961.
Parameters:
-
vector
–Incoming ray. Expected size is [2, 3], [1, 2, 3] or [m, 2, 3].
-
normvector
–Normal vector. Expected size is [2, 3], [1, 2, 3] or [m, 2, 3]].
-
n1
–Refractive index of the incoming medium.
-
n2
–Refractive index of the outgoing medium.
-
error
–Desired error.
Returns:
-
output
(tensor
) –Refracted ray. Expected size is [1, 2, 3]
Source code in odak/learn/raytracing/boundary.py
rotate_points(point, angles=torch.tensor([[0, 0, 0]]), mode='XYZ', origin=torch.tensor([[0, 0, 0]]), offset=torch.tensor([[0, 0, 0]]))
¶
Definition to rotate a given point. Note that rotation is always with respect to 0,0,0.
Parameters:
-
point
–A point with size of [3] or [1, 3] or [m, 3].
-
angles
–Rotation angles in degrees.
-
mode
–Rotation mode determines ordering of the rotations at each axis. There are XYZ,YXZ,ZXY and ZYX modes.
-
origin
–Reference point for a rotation. Expected size is [3] or [1, 3].
-
offset
–Shift with the given offset. Expected size is [3] or [1, 3] or [m, 3].
Returns:
-
result
(tensor
) –Result of the rotation [1 x 3] or [m x 3].
-
rotx
(tensor
) –Rotation matrix along X axis [3 x 3].
-
roty
(tensor
) –Rotation matrix along Y axis [3 x 3].
-
rotz
(tensor
) –Rotation matrix along Z axis [3 x 3].
Source code in odak/learn/tools/transformation.py
same_side(p1, p2, a, b)
¶
Definition to figure which side a point is on with respect to a line and a point. See http://www.blackpawn.com/texts/pointinpoly/ for more. If p1 and p2 are on the sameside, this definition returns True.
Parameters:
-
p1
–Point(s) to check.
-
p2
–This is the point check against.
-
a
–First point that forms the line.
-
b
–Second point that forms the line.
Source code in odak/learn/tools/vector.py
save_torch_tensor(fn, tensor)
¶
Definition to save a torch tensor.
Parameters:
-
fn
–Filename.
-
tensor
–Torch tensor to be saved.
write_PLY(triangles, savefn='output.ply')
¶
Definition to generate a PLY file from given points.
Parameters:
-
triangles
–List of triangles with the size of Mx3x3.
-
savefn
–Filename for a PLY file.
Source code in odak/tools/asset.py
get_sphere_normal_torch(point, sphere)
¶
Definition to get a normal of a point on a given sphere.
Parameters:
-
point
–Point on sphere in X,Y,Z.
-
sphere
–Center defined in X,Y,Z and radius.
Returns:
-
normal_vector
(tensor
) –Normal vector.
Source code in odak/learn/raytracing/boundary.py
get_triangle_normal(triangle, triangle_center=None)
¶
Definition to calculate surface normal of a triangle.
Parameters:
-
triangle
–Set of points in X,Y and Z to define a planar surface (3,3). It can also be list of triangles (mx3x3).
-
triangle_center
(tensor
, default:None
) –Center point of the given triangle. See odak.learn.raytracing.center_of_triangle for more. In many scenarios you can accelerate things by precomputing triangle centers.
Returns:
-
normal
(tensor
) –Surface normal at the point of intersection.
Source code in odak/learn/raytracing/boundary.py
intersect_w_circle(ray, circle)
¶
Definition to find intersection point of a ray with a circle. Returns distance as zero if there isn't an intersection.
Parameters:
-
ray
–A vector/ray.
-
circle
–A list that contains (0) Set of points in X,Y and Z to define plane of a circle, (1) circle center, and (2) circle radius.
Returns:
-
normal
(Tensor
) –Surface normal at the point of intersection.
-
distance
(Tensor
) –Distance in between a starting point of a ray and the intersection point with a given triangle.
Source code in odak/learn/raytracing/boundary.py
intersect_w_sphere(ray, sphere, learning_rate=0.2, number_of_steps=5000, error_threshold=0.01)
¶
Definition to find the intersection between ray(s) and sphere(s).
Parameters:
-
ray
–Input ray(s). Expected size is [1 x 2 x 3] or [m x 2 x 3].
-
sphere
–Input sphere. Expected size is [1 x 4].
-
learning_rate
–Learning rate used in the optimizer for finding the propagation distances of the rays.
-
number_of_steps
–Number of steps used in the optimizer.
-
error_threshold
–The error threshold that will help deciding intersection or no intersection.
Returns:
-
intersecting_ray
(tensor
) –Ray(s) that intersecting with the given sphere. Expected size is [n x 2 x 3], where n could be any real number.
-
intersecting_normal
(tensor
) –Normal(s) for the ray(s) intersecting with the given sphere Expected size is [n x 2 x 3], where n could be any real number.
Source code in odak/learn/raytracing/boundary.py
intersect_w_surface(ray, points)
¶
Definition to find intersection point inbetween a surface and a ray. For more see: http://geomalgorithms.com/a06-_intersect-2.html
Parameters:
-
ray
–A vector/ray.
-
points
–Set of points in X,Y and Z to define a planar surface.
Returns:
-
normal
(tensor
) –Surface normal at the point of intersection.
-
distance
(float
) –Distance in between starting point of a ray with it's intersection with a planar surface.
Source code in odak/learn/raytracing/boundary.py
intersect_w_surface_batch(ray, triangle)
¶
Parameters:
-
ray
–A vector/ray (2 x 3). It can also be a list of rays (n x 2 x 3).
-
triangle
–Set of points in X,Y and Z to define a planar surface. It can also be a list of triangles (m x 3 x 3).
Returns:
-
normal
(tensor
) –Surface normal at the point of intersection (m x n x 2 x 3).
-
distance
(tensor
) –Distance in between starting point of a ray with it's intersection with a planar surface (m x n).
Source code in odak/learn/raytracing/boundary.py
intersect_w_triangle(ray, triangle)
¶
Definition to find intersection point of a ray with a triangle.
Parameters:
-
ray
–A ray [1 x 2 x 3] or a batch of ray [m x 2 x 3].
-
triangle
–Set of points in X,Y and Z to define a single triangle [1 x 3 x 3].
Returns:
-
normal
(tensor
) –Surface normal at the point of intersection with the surface of triangle. This could also involve surface normals that are not on the triangle. Expected size is [1 x 2 x 3] or [m x 2 x 3] depending on the input.
-
distance
(float
) –Distance in between a starting point of a ray and the intersection point with a given triangle. Expected size is [1 x 1] or [m x 1] depending on the input.
-
intersecting_ray
(tensor
) –Rays that intersect with the triangle plane and on the triangle. Expected size is [1 x 2 x 3] or [m x 2 x 3] depending on the input.
-
intersecting_normal
(tensor
) –Normals that intersect with the triangle plane and on the triangle. Expected size is [1 x 2 x 3] or [m x 2 x 3] depending on the input.
-
check
(tensor
) –A list that provides a bool as True or False for each ray used as input. A test to see is a ray could be on the given triangle. Expected size is [1] or [m].
Source code in odak/learn/raytracing/boundary.py
intersect_w_triangle_batch(ray, triangle)
¶
Definition to find intersection points of rays with triangles. Returns False for each variable if the rays doesn't intersect with given triangles.
Parameters:
-
ray
–vectors/rays (n x 2 x 3).
-
triangle
–Set of points in X,Y and Z to define triangles (m x 3 x 3).
Returns:
-
normal
(tensor
) –Surface normal at the point of intersection (m x n x 2 x 3).
-
distance
(List
) –Distance in between starting point of a ray with it's intersection with a planar surface (m x n).
-
intersect_ray
(List
) –List of intersecting rays (k x 2 x 3) where k <= n.
-
intersect_normal
(List
) –List of intersecting normals (k x 2 x 3) where k <= n*m.
-
check
(tensor
) –Boolean tensor (m x n) indicating whether each ray intersects with a triangle or not.
Source code in odak/learn/raytracing/boundary.py
reflect(input_ray, normal)
¶
Definition to reflect an incoming ray from a surface defined by a surface normal. Used method described in G.H. Spencer and M.V.R.K. Murty, "General Ray-Tracing Procedure", 1961.
Parameters:
-
input_ray
–A ray or rays. Expected size is [2 x 3], [1 x 2 x 3] or [m x 2 x 3].
-
normal
–A surface normal(s). Expected size is [2 x 3], [1 x 2 x 3] or [m x 2 x 3].
Returns:
-
output_ray
(tensor
) –Array that contains starting points and cosines of a reflected ray. Expected size is [1 x 2 x 3] or [m x 2 x 3].
Source code in odak/learn/raytracing/boundary.py
refract(vector, normvector, n1, n2, error=0.01)
¶
Definition to refract an incoming ray. Used method described in G.H. Spencer and M.V.R.K. Murty, "General Ray-Tracing Procedure", 1961.
Parameters:
-
vector
–Incoming ray. Expected size is [2, 3], [1, 2, 3] or [m, 2, 3].
-
normvector
–Normal vector. Expected size is [2, 3], [1, 2, 3] or [m, 2, 3]].
-
n1
–Refractive index of the incoming medium.
-
n2
–Refractive index of the outgoing medium.
-
error
–Desired error.
Returns:
-
output
(tensor
) –Refracted ray. Expected size is [1, 2, 3]
Source code in odak/learn/raytracing/boundary.py
A class to represent a detector.
Source code in odak/learn/raytracing/detector.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
__init__(colors=3, center=torch.tensor([0.0, 0.0, 0.0]), tilt=torch.tensor([0.0, 0.0, 0.0]), size=torch.tensor([10.0, 10.0]), resolution=torch.tensor([100, 100]), device=torch.device('cpu'))
¶
Parameters:
-
colors
–Number of color channels to register (e.g., RGB).
-
center
–Center point of the detector [3].
-
tilt
–Tilt angles of the surface in degrees [3].
-
size
–Size of the detector [2].
-
resolution
–Resolution of the detector.
-
device
–Device for computation (e.g., cuda, cpu).
Source code in odak/learn/raytracing/detector.py
clear()
¶
get_image()
¶
Function to return the detector image.
Returns:
-
image
(tensor
) –Detector image.
Source code in odak/learn/raytracing/detector.py
intersect(rays, color=0)
¶
Function to intersect rays with the detector
Parameters:
-
rays
–Rays to be intersected with a detector. Expected size is [1 x 2 x 3] or [m x 2 x 3].
-
color
–Color channel to register.
Returns:
-
points
(tensor
) –Intersection points with the image detector [k x 3].
Source code in odak/learn/raytracing/detector.py
planar_mesh
¶
Source code in odak/learn/raytracing/mesh.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
__init__(size=[1.0, 1.0], number_of_meshes=[10, 10], angles=torch.tensor([0.0, 0.0, 0.0]), offset=torch.tensor([0.0, 0.0, 0.0]), device=torch.device('cpu'), heights=None)
¶
Definition to generate a plane with meshes.
Parameters:
-
number_of_meshes
–Number of squares over plane. There are two triangles at each square.
-
size
–Size of the plane.
-
angles
–Rotation angles in degrees.
-
offset
–Offset along XYZ axes. Expected dimension is [1 x 3] or offset for each triangle [m x 3]. m here refers to `2 * number_of_meshes[0]` times `number_of_meshes[1]`.
-
device
–Computational resource to be used (e.g., cpu, cuda).
-
heights
–Load surface heights from a tensor.
Source code in odak/learn/raytracing/mesh.py
get_squares()
¶
Internal function to initiate squares over a plane.
Returns:
-
squares
(tensor
) –Squares over a plane. Expected size is [m x n x 3].
Source code in odak/learn/raytracing/mesh.py
get_triangles()
¶
Internal function to get triangles.
Source code in odak/learn/raytracing/mesh.py
init_heights(heights=None)
¶
Internal function to initialize a height map.
Note that self.heights is a differentiable variable, and can be optimized or learned.
See unit test test/test_learn_ray_detector.py
or test/test_learn_ray_mesh.py
as examples.
Source code in odak/learn/raytracing/mesh.py
mirror(rays)
¶
Function to bounce light rays off the meshes.
Parameters:
-
rays
–Rays to be bounced. Expected size is [2 x 3], [1 x 2 x 3] or [m x 2 x 3].
Returns:
-
reflected_rays
(tensor
) –Reflected rays. Expected size is [2 x 3], [1 x 2 x 3] or [m x 2 x 3].
-
reflected_normals
(tensor
) –Reflected normals. Expected size is [2 x 3], [1 x 2 x 3] or [m x 2 x 3].