Signed Distance Fields

Sdf3D

class meshpy.Sdf3D(sdf_data, origin, resolution, use_abs=True, T_sdf_world=RigidTransform(rotation=[[ 1. 0. 0.] [ 0. 1. 0.] [ 0. 0. 1.]], translation=[ 0. 0. 0.], from_frame=sdf, to_frame=world))

Bases: meshpy.sdf.Sdf

transform(delta_T)

Creates a new SDF with a given pose with respect to world coordinates.

Parameters:delta_T (autolab_core.RigidTransform) – transform from cur sdf to transformed sdf coords
__getitem__(coords)

Returns the signed distance at the given coordinates.

Parameters:coords (numpy.ndarray of int) – A or 3-dimensional ndarray that indicates the desired coordinates in the grid.
Returns:The signed distance at the given coords (interpolated).
Return type:float
Raises:IndexError – If the coords vector does not have three entries.
gradient(coords)

Returns the SDF gradient at the given coordinates, interpolating if necessary

Parameters:coords (numpy.ndarray of int) – A 3-dimensional ndarray that indicates the desired coordinates in the grid.
Returns:The gradient at the given coords (interpolated).
Return type:float
Raises:IndexError – If the coords vector does not have three entries.
curvature(coords, delta=0.001)

Returns an approximation to the local SDF curvature (Hessian) at the given coordinate in grid basis.

Parameters:coords (numpy 3-vector) – the grid coordinates at which to get the curvature
Returns:curvature
Return type:3x3 ndarray of the curvature at the surface points
surface_normal(coords, delta=1.5)

Returns the sdf surface normal at the given coordinates by computing the tangent plane using SDF interpolation.

Parameters:
  • coords (numpy.ndarray of int) – A 3-dimensional ndarray that indicates the desired coordinates in the grid.
  • delta (float) – A radius for collecting surface points near the target coords for calculating the surface normal.
Returns:

The 3-dimensional ndarray that represents the surface normal.

Return type:

numpy.ndarray of float

Raises:

IndexError – If the coords vector does not have three entries.

surface_points(grid_basis=True)

Returns the points on the surface.

Parameters:grid_basis (bool) – If False, the surface points are transformed to the world frame. If True (default), the surface points are left in grid coordinates.
Returns:The points on the surface and the signed distances at those points.
Return type:tuple of numpy.ndarray of int, numpy.ndarray of float
rescale(scale)

Rescale an SDF by a given scale factor.

Parameters:scale (float) – the amount to scale the SDF
Returns:new sdf with given scale
Return type:Sdf3D
transform_dense(delta_T, detailed=False)

Transform the grid by pose T and scale with canonical reference frame at the SDF center with axis alignment.

Parameters:
  • delta_T (SimilarityTransform) – the transformation from the current frame of reference to the new frame of reference
  • detailed (bool) – whether or not to use interpolation
Returns:

new sdf with grid warped by T

Return type:

Sdf3D

transform_pt_obj_to_grid(x_sdf, direction=False)

Converts a point in sdf coords to the grid basis. If direction then don’t translate.

Parameters:x_sdf (numpy 3xN ndarray or numeric scalar) – points to transform from sdf basis in meters to grid basis
Returns:x_grid – points in grid basis
Return type:numpy 3xN ndarray or scalar
transform_pt_grid_to_obj(x_grid, direction=False)

Converts a point in grid coords to the world basis. If direction then don’t translate.

Parameters:x_grid (numpy 3xN ndarray or numeric scalar) – points to transform from grid basis to sdf basis in meters
Returns:x_sdf – points in sdf basis (meters)
Return type:numpy 3xN ndarray
static find_zero_crossing_linear(x1, y1, x2, y2)

Find zero crossing using linear approximation

static find_zero_crossing_quadratic(x1, y1, x2, y2, x3, y3, eps=1.0)

Find zero crossing using quadratic approximation along 1d line

Sdf

class meshpy.Sdf

Bases: object

Abstract class for signed distance fields.

dimensions

SDF dimension information.

Returns:The ndarray that contains the dimensions of the sdf.
Return type:numpy.ndarray of int
origin

The location of the origin in the SDF grid.

Returns:The 2- or 3-ndarray that contains the location of the origin of the mesh grid in real space.
Return type:numpy.ndarray of float
resolution

The grid resolution (how wide each grid cell is).

Returns:The width of each grid cell.
Return type:float
center

Center of grid.

This basically transforms the world frame to grid center.

Returns:
Return type:numpy.ndarray
gradients

Gradients of the SDF.

Returns:A list of ndarrays of the same dimension as the SDF. The arrays are in axis order and specify the gradients for that axis at each point.
Return type:list of numpy.ndarray of float
data

The SDF data.

Returns:The 2- or 3-dimensional ndarray that holds the grid of signed distances.
Return type:numpy.ndarray of float
transform(tf)

Returns a new SDF transformed by similarity tf.

transform_pt_obj_to_grid(x_world, direction=False)

Transforms points from world frame to grid frame

transform_pt_grid_to_obj(x_grid, direction=False)

Transforms points from grid frame to world frame

surface_points()

Returns the points on the surface.

Returns:The points on the surface and the signed distances at those points.
Return type:tuple of numpy.ndarray of int, numpy.ndarray of float
__getitem__(coords)

Returns the signed distance at the given coordinates.

Parameters:coords (numpy.ndarray of int) – A 2- or 3-dimensional ndarray that indicates the desired coordinates in the grid.
Returns:The signed distance at the given coords (interpolated).
Return type:float
transform_to_world()

Returns an sdf object with center in the world frame of reference.

center_world()

Center of grid (basically transforms world frame to grid center)

on_surface(coords)

Determines whether or not a point is on the object surface.

Parameters:coords (numpy.ndarray of int) – A 2- or 3-dimensional ndarray that indicates the desired coordinates in the grid.
Returns:Is the point on the object’s surface, and what is the signed distance at that point?
Return type:tuple of bool, float
is_out_of_bounds(coords)

Returns True if coords is an out of bounds access.

Parameters:coords (numpy.ndarray of int) – A 2- or 3-dimensional ndarray that indicates the desired coordinates in the grid.
Returns:Are the coordinates in coords out of bounds?
Return type:bool