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.
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_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
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
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
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
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
create_ray(xyz, abg)
¶
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].
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_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
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].