graspnetAPI.utils.dexnet.grasping.meshpy package

Submodules

graspnetAPI.utils.dexnet.grasping.meshpy.mesh module

Encapsulates mesh for grasping operations Authors: Jeff Mahler and Matt Matl

class graspnetAPI.utils.dexnet.grasping.meshpy.mesh.Mesh3D(vertices, triangles, normals=None, density=1.0, center_of_mass=None, trimesh=None, T_obj_world=RigidTransform(rotation=np.array([[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]), translation=np.array([0.0, 0.0, 0.0]), from_frame='obj', to_frame='world'))[source]

Bases: object

A triangular mesh for a three-dimensional shape representation.

vertices

A #verts by 3 array, where each row contains an ordered [x,y,z] set that describes one vertex.

Type

numpy.ndarray of float

triangles

A #tris by 3 array, where each row contains indices of vertices in the vertices array that are part of the triangle.

Type

numpy.ndarray of int

normals

A #normals by 3 array, where each row contains a normalized vector. This list should contain one norm per vertex.

Type

numpy.ndarray of float

density

The density of the mesh.

Type

float

center_of_mass

The 3D location of the mesh’s center of mass.

Type

numpy.ndarray of float

mass

The mass of the mesh (read-only).

Type

float

inertia

The 3x3 inertial matrix of the mesh (read-only).

Type

numpy.ndarray of float

bb_center

The 3D location of the center of the mesh’s minimal bounding box (read-only).

Type

numpy.ndarray of float

centroid

The 3D location of the mesh’s vertex mean (read-only).

Type

numpy.ndarray of float

C_canonical = array([[0.01666667, 0.00833333, 0.00833333], [0.00833333, 0.01666667, 0.00833333], [0.00833333, 0.00833333, 0.01666667]])
OBJ_EXT = '.obj'
PROC_TAG = '_proc'
ScalingTypeDiag = 4
ScalingTypeMax = 2
ScalingTypeMed = 1
ScalingTypeMin = 0
ScalingTypeRelative = 3
property T_obj_world

Return pose.

property bb_center

numpy.ndarray of float: The 3D location of the center of the mesh’s minimal bounding box (read-only).

bounding_box()[source]

Returns the mesh’s bounding box corners.

Returns

A 2-tuple of 3-ndarrays of floats. The first 3-array contains the vertex of the smallest corner of the bounding box, and the second 3-array contains the largest corner of the bounding box.

Return type

tuple of numpy.ndarray of float

bounding_box_mesh()[source]

Returns the mesh bounding box as a mesh.

Returns

A Mesh3D representation of the mesh’s bounding box.

Return type

Mesh3D

property center_of_mass

numpy.ndarray of float: The 3D location of the mesh’s center of mass.

center_vertices()[source]

Center the mesh’s vertices on the mesh center of mass.

This shifts the mesh without rotating it so that the center of its bounding box is at the origin.

center_vertices_avg()[source]

Center the mesh’s vertices at the centroid.

This shifts the mesh without rotating it so that the centroid (mean) of all vertices is at the origin.

center_vertices_bb()[source]

Center the mesh’s vertices at the center of its bounding box.

This shifts the mesh without rotating it so that the center of its bounding box is at the origin.

property centroid

numpy.ndarray of float: The 3D location of the mesh’s vertex mean (read-only).

compute_vertex_normals()[source]

Get normals from triangles

convex_hull()[source]

Return a 3D mesh that represents the convex hull of the mesh.

copy()[source]

Return a copy of the mesh.

Note

This method only copies the vertices and triangles of the mesh.

covariance()[source]

Return the total covariance of the mesh’s triangles.

Returns

The total covariance of the mesh’s triangles.

Return type

float

property density

The density of the mesh.

Type

float

find_contact(origin, direction)[source]

Finds the contact location with the mesh, if it exists.

flip_normals()[source]

Flips the mesh normals.

flip_tri_orientation()[source]

Flips the orientation of all triangles.

get_T_surface_obj(T_obj_surface, delta=0.0)[source]

Gets the transformation that puts the object resting exactly on the z=delta plane

Parameters
  • T_obj_surface (RigidTransform) – The RigidTransform by which the mesh is transformed.

  • delta (float) – Z-coordinate to rest the mesh on

Note

This method copies the vertices and triangles of the mesh.

property inertia

numpy.ndarray of float: The 3x3 inertial matrix of the mesh (read-only).

property is_watertight
static load(filename, cache_dir, preproc_script=None)[source]

Load a mesh from a file.

Note

If the mesh is not already in .obj format, this requires the installation of meshlab. Meshlab has a command called meshlabserver that is used to convert the file into a .obj format.

Parameters
  • filename (str) – Path to mesh file.

  • cache_dir (str) – A directory to store a converted .obj file in, if the file isn’t already in .obj format.

  • preproc_script (str) – The path to an optional script to run before converting the mesh file to .obj if necessary.

Returns

A 3D mesh object read from the file.

Return type

Mesh3D

property mass

The mass of the mesh (read-only).

Type

float

max_coords()[source]

Returns the maximum coordinates of the mesh.

Returns

A 3-ndarray of floats that represents the minimal x, y, and z coordinates represented in the mesh.

Return type

numpy.ndarray of float

merge(other_mesh)[source]

Combines this mesh with another mesh.

Parameters

other_mesh (Mesh3D) – the mesh to combine with

Returns

merged mesh

Return type

Mesh3D

min_coords()[source]

Returns the minimum coordinates of the mesh.

Returns

A 3-ndarray of floats that represents the minimal x, y, and z coordinates represented in the mesh.

Return type

numpy.ndarray of float

normalize_vertices()[source]

Normalize the mesh’s orientation along its principal axes.

Transforms the vertices and normals of the mesh such that the origin of the resulting mesh’s coordinate frame is at the center of the bounding box and the principal axes (as determined from PCA) are aligned with the vertical Z, Y, and X axes in that order.

property normals

numpy.ndarray of float: A #normals by 3 array, where each row contains a normalized vector. This list should contain one norm per vertex.

property num_triangles

int: The number of total triangles

property num_vertices

int: The number of total vertices

principal_dims()[source]

Returns the maximal span of the mesh’s coordinates.

The maximal span is the maximum coordinate value minus the minimal coordinate value in each principal axis.

Returns

A 3-ndarray of floats that represents the maximal x, y, and z spans of the mesh.

Return type

numpy.ndarray of float

random_points(n_points)[source]

Generate uniformly random points on the surface of the mesh.

Parameters

n_points (int) – The number of random points to generate.

Returns

A n_points by 3 ndarray that contains the sampled 3D points.

Return type

numpy.ndarray of float

ray_intersections(ray, point, distance)[source]

Returns a list containing the indices of the triangles that are intersected by the given ray emanating from the given point within some distance.

remove_bad_tris()[source]

Remove triangles with out-of-bounds vertices from the mesh.

remove_unreferenced_vertices()[source]

Remove any vertices that are not part of a triangular face.

Note

This method will fail if any bad triangles are present, so run remove_bad_tris() first if you’re unsure if bad triangles are present.

Returns

Returns True if vertices were removed, False otherwise.

Return type

bool

rescale(scale_factor)[source]

Rescales the vertex coordinates by scale_factor.

Parameters

scale_factor (float) – The desired scale factor for the mesh’s vertices.

rescale_dimension(scale, scaling_type=0)[source]

Rescales the vertex coordinates to scale using the given scaling_type.

Parameters
  • scale (float) – The desired scaling factor of the selected dimension, if scaling_type is ScalingTypeMin, ScalingTypeMed, ScalingTypeMax, or ScalingTypeDiag. Otherwise, the overall scaling factor.

  • scaling_type (int) – One of ScalingTypeMin, ScalingTypeMed, ScalingTypeMax, ScalingTypeRelative, or ScalingTypeDiag. ScalingTypeMin scales the smallest vertex extent (X, Y, or Z) by scale, ScalingTypeMed scales the median vertex extent, and ScalingTypeMax scales the maximum vertex extent. ScalingTypeDiag scales the bounding box diagonal (divided by three), and ScalingTypeRelative provides absolute scaling.

resting_pose(T_obj_world, eps=1e-10)[source]

Returns the stable pose that the mesh will rest on if it lands on an infinite planar worksurface quasi-statically in the given transformation (only the rotation is used).

Parameters
  • T_obj_world (autolab_core.RigidTransform) – transformation from object to table basis (z-axis upward) specifying the orientation of the mesh

  • eps (float) – numeric tolerance in cone projection solver

Returns

stable pose specifying the face that the mesh will land on

Return type

StablePose

scale_principal_eigenvalues(new_evals)[source]
stable_poses(min_prob=0.0)[source]

Computes all valid StablePose objects for the mesh.

Parameters

min_prob (float) – stable poses that are less likely than this threshold will be discarded

Returns

A list of StablePose objects for the mesh.

Return type

list of StablePose

subdivide(min_tri_length=inf)[source]

Return a copy of the mesh that has been subdivided by one iteration.

Note

This method only copies the vertices and triangles of the mesh.

support(direction)[source]

Returns the support function in the given direction

Parameters

direction (numpy.ndarray of float) – A 3-ndarray of floats that is a unit vector in the direction of the desired support.

Returns

A 3-ndarray of floats that represents the support.

Return type

numpy.ndarray of float

surface_area()[source]

Return the surface area of the mesh.

Returns

The surface area of the mesh.

Return type

float

total_volume()[source]

Return the total volume of the mesh.

Returns

The total volume of the mesh.

Return type

float

transform(T)[source]

Return a copy of the mesh that has been transformed by T.

Parameters

T (RigidTransform) – The RigidTransform by which the mesh is transformed.

Note

This method only copies the vertices and triangles of the mesh.

tri_centers()[source]

Returns an array of the triangle centers as 3D points.

Returns

An ndarray of 3-ndarrays of floats, where each 3-ndarray represents the 3D point at the center of the corresponding mesh triangle.

Return type

numpy.ndarray of numpy.ndarray of float

tri_normals(align_to_hull=False)[source]

Returns a list of the triangle normals.

Parameters

align_to_hull (bool) – If true, we re-orient the normals to point outward from the mesh by using the convex hull.

Returns

A #triangles by 3 array of floats, where each 3-ndarray represents the 3D normal vector of the corresponding triangle.

Return type

numpy.ndarray of float

property triangles

A #tris by 3 array, where each row contains indices of vertices in the vertices array that are part of the triangle.

Type

numpy.ndarray of int

property trimesh

Convert to trimesh.

update_tf(delta_T)[source]

Updates the mesh transformation.

property vertices

A #verts by 3 array, where each row contains an ordered [x,y,z] set that describes one vertex.

Type

numpy.ndarray of float

visualize(color=0.5, 0.5, 0.5, style='surface', opacity=1.0)[source]

Plots visualization of mesh using MayaVI.

Parameters
  • color (tuple of float) – 3-tuple of floats in [0,1] to give the mesh’s color

  • style (str) – Either ‘surface’, which produces an opaque surface, or ‘wireframe’, which produces a wireframe.

  • opacity (float) – A value in [0,1] indicating the opacity of the mesh. Zero is transparent, one is opaque.

Returns

The displayed surface.

Return type

mayavi.modules.surface.Surface

graspnetAPI.utils.dexnet.grasping.meshpy.obj_file module

File for loading and saving meshes from .OBJ files Author: Jeff Mahler

class graspnetAPI.utils.dexnet.grasping.meshpy.obj_file.ObjFile(filepath)[source]

Bases: object

A Wavefront .obj file reader and writer.

filepath

The full path to the .obj file associated with this reader/writer.

Type

str

property filepath

Returns the full path to the .obj file associated with this reader/writer.

Returns

The full path to the .obj file associated with this reader/writer.

Return type

str

read()[source]

Reads in the .obj file and returns a Mesh3D representation of that mesh.

Returns

A Mesh3D created from the data in the .obj file.

Return type

Mesh3D

write(mesh)[source]

Writes a Mesh3D object out to a .obj file format

Parameters

mesh (Mesh3D) – The Mesh3D object to write to the .obj file.

Note

Does not support material files or texture coordinates.

graspnetAPI.utils.dexnet.grasping.meshpy.sdf module

Definition of SDF Class Author: Sahaana Suri, Jeff Mahler, and Matt Matl

Currently assumes clean input

class graspnetAPI.utils.dexnet.grasping.meshpy.sdf.Sdf[source]

Bases: object

Abstract class for signed distance fields.

abstract __getitem__(coords)[source]

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

property center

Center of grid.

This basically transforms the world frame to grid center.

Returns

Return type

numpy.ndarray

center_world()[source]

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

property data

The SDF data.

Returns

The 2- or 3-dimensional ndarray that holds the grid of signed distances.

Return type

numpy.ndarray of float

property dimensions

SDF dimension information.

Returns

The ndarray that contains the dimensions of the sdf.

Return type

numpy.ndarray of int

property 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

is_out_of_bounds(coords)[source]

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

on_surface(coords)[source]

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

property 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

property resolution

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

Returns

The width of each grid cell.

Return type

float

abstract surface_points()[source]

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

abstract transform(tf)[source]

Returns a new SDF transformed by similarity tf.

abstract transform_pt_grid_to_obj(x_grid, direction=False)[source]

Transforms points from grid frame to world frame

abstract transform_pt_obj_to_grid(x_world, direction=False)[source]

Transforms points from world frame to grid frame

transform_to_world()[source]

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

class graspnetAPI.utils.dexnet.grasping.meshpy.sdf.Sdf3D(sdf_data, origin, resolution, use_abs=False, T_sdf_world=RigidTransform(rotation=np.array([[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]), translation=np.array([0.0, 0.0, 0.0]), from_frame='sdf', to_frame='world'))[source]

Bases: graspnetAPI.utils.dexnet.grasping.meshpy.sdf.Sdf

__getitem__(coords)[source]

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.

curvature(coords, delta=0.001)[source]

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

  • delta

Returns

curvature

Return type

3x3 ndarray of the curvature at the surface points

static find_zero_crossing_linear(x1, y1, x2, y2)[source]

Find zero crossing using linear approximation

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

Find zero crossing using quadratic approximation along 1d line

gradient(coords)[source]

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.

max_coords_x = [1, 4, 6, 7]
max_coords_y = [2, 4, 5, 7]
max_coords_z = [3, 5, 6, 7]
min_coords_x = [0, 2, 3, 5]
min_coords_y = [0, 1, 3, 6]
min_coords_z = [0, 1, 2, 4]
num_interpolants = 8
rescale(scale)[source]

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

surface_normal(coords, delta=1.5)[source]

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)[source]

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

transform(delta_T)[source]

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

transform_dense(delta_T, detailed=False)[source]

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_grid_to_obj(x_grid, direction=False)[source]

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

  • direction (bool) –

Returns

x_sdf – points in sdf basis (meters)

Return type

numpy 3xN ndarray

transform_pt_obj_to_grid(x_sdf, direction=False)[source]

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

  • direction (bool) –

Returns

x_grid – points in grid basis

Return type

numpy 3xN ndarray or scalar

graspnetAPI.utils.dexnet.grasping.meshpy.sdf_file module

Reads and writes sdfs to file Author: Jeff Mahler

class graspnetAPI.utils.dexnet.grasping.meshpy.sdf_file.SdfFile(filepath)[source]

Bases: object

A Signed Distance Field .sdf file reader and writer.

filepath

The full path to the .sdf or .csv file associated with this reader/writer.

Type

str

property filepath

Returns the full path to the file associated with this reader/writer.

Returns

The full path to the file associated with this reader/writer.

Return type

str

read()[source]

Reads in the SDF file and returns a Sdf object.

Returns

A Sdf created from the data in the file.

Return type

Sdf

write(sdf)[source]

Writes an SDF to a file.

Parameters

sdf (Sdf) – An Sdf object to write out.

Note

This is not currently implemented or supported.

graspnetAPI.utils.dexnet.grasping.meshpy.stable_pose module

A basic struct-like Stable Pose class to make accessing pose probability and rotation matrix easier

Author: Matt Matl and Nikhil Sharma

class graspnetAPI.utils.dexnet.grasping.meshpy.stable_pose.StablePose(p, r, x0, face=None, stp_id=- 1)[source]

Bases: object

A representation of a mesh’s stable pose.

p

Probability associated with this stable pose.

Type

float

r

3x3 rotation matrix that rotates the mesh into the stable pose from standardized coordinates.

Type

numpy.ndarray of :obj`numpy.ndarray` of float

x0

3D point in the mesh that is resting on the table.

Type

numpy.ndarray of float

face

3D vector of indices corresponding to vertices forming the resting face

Type

numpy.ndarray

stp_id

A string identifier for the stable pose

Type

str

T_obj_table

A RigidTransform representation of the pose’s rotation matrix.

Type

RigidTransform

property T_obj_table
property T_obj_world
__eq__(other)[source]

Check equivalence by rotation about the z axis

Module contents

class graspnetAPI.utils.dexnet.grasping.meshpy.Mesh3D(vertices, triangles, normals=None, density=1.0, center_of_mass=None, trimesh=None, T_obj_world=RigidTransform(rotation=np.array([[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]), translation=np.array([0.0, 0.0, 0.0]), from_frame='obj', to_frame='world'))[source]

Bases: object

A triangular mesh for a three-dimensional shape representation.

vertices

A #verts by 3 array, where each row contains an ordered [x,y,z] set that describes one vertex.

Type

numpy.ndarray of float

triangles

A #tris by 3 array, where each row contains indices of vertices in the vertices array that are part of the triangle.

Type

numpy.ndarray of int

normals

A #normals by 3 array, where each row contains a normalized vector. This list should contain one norm per vertex.

Type

numpy.ndarray of float

density

The density of the mesh.

Type

float

center_of_mass

The 3D location of the mesh’s center of mass.

Type

numpy.ndarray of float

mass

The mass of the mesh (read-only).

Type

float

inertia

The 3x3 inertial matrix of the mesh (read-only).

Type

numpy.ndarray of float

bb_center

The 3D location of the center of the mesh’s minimal bounding box (read-only).

Type

numpy.ndarray of float

centroid

The 3D location of the mesh’s vertex mean (read-only).

Type

numpy.ndarray of float

C_canonical = array([[0.01666667, 0.00833333, 0.00833333], [0.00833333, 0.01666667, 0.00833333], [0.00833333, 0.00833333, 0.01666667]])
OBJ_EXT = '.obj'
PROC_TAG = '_proc'
ScalingTypeDiag = 4
ScalingTypeMax = 2
ScalingTypeMed = 1
ScalingTypeMin = 0
ScalingTypeRelative = 3
property T_obj_world

Return pose.

property bb_center

numpy.ndarray of float: The 3D location of the center of the mesh’s minimal bounding box (read-only).

bounding_box()[source]

Returns the mesh’s bounding box corners.

Returns

A 2-tuple of 3-ndarrays of floats. The first 3-array contains the vertex of the smallest corner of the bounding box, and the second 3-array contains the largest corner of the bounding box.

Return type

tuple of numpy.ndarray of float

bounding_box_mesh()[source]

Returns the mesh bounding box as a mesh.

Returns

A Mesh3D representation of the mesh’s bounding box.

Return type

Mesh3D

property center_of_mass

numpy.ndarray of float: The 3D location of the mesh’s center of mass.

center_vertices()[source]

Center the mesh’s vertices on the mesh center of mass.

This shifts the mesh without rotating it so that the center of its bounding box is at the origin.

center_vertices_avg()[source]

Center the mesh’s vertices at the centroid.

This shifts the mesh without rotating it so that the centroid (mean) of all vertices is at the origin.

center_vertices_bb()[source]

Center the mesh’s vertices at the center of its bounding box.

This shifts the mesh without rotating it so that the center of its bounding box is at the origin.

property centroid

numpy.ndarray of float: The 3D location of the mesh’s vertex mean (read-only).

compute_vertex_normals()[source]

Get normals from triangles

convex_hull()[source]

Return a 3D mesh that represents the convex hull of the mesh.

copy()[source]

Return a copy of the mesh.

Note

This method only copies the vertices and triangles of the mesh.

covariance()[source]

Return the total covariance of the mesh’s triangles.

Returns

The total covariance of the mesh’s triangles.

Return type

float

property density

The density of the mesh.

Type

float

find_contact(origin, direction)[source]

Finds the contact location with the mesh, if it exists.

flip_normals()[source]

Flips the mesh normals.

flip_tri_orientation()[source]

Flips the orientation of all triangles.

get_T_surface_obj(T_obj_surface, delta=0.0)[source]

Gets the transformation that puts the object resting exactly on the z=delta plane

Parameters
  • T_obj_surface (RigidTransform) – The RigidTransform by which the mesh is transformed.

  • delta (float) – Z-coordinate to rest the mesh on

Note

This method copies the vertices and triangles of the mesh.

property inertia

numpy.ndarray of float: The 3x3 inertial matrix of the mesh (read-only).

property is_watertight
static load(filename, cache_dir, preproc_script=None)[source]

Load a mesh from a file.

Note

If the mesh is not already in .obj format, this requires the installation of meshlab. Meshlab has a command called meshlabserver that is used to convert the file into a .obj format.

Parameters
  • filename (str) – Path to mesh file.

  • cache_dir (str) – A directory to store a converted .obj file in, if the file isn’t already in .obj format.

  • preproc_script (str) – The path to an optional script to run before converting the mesh file to .obj if necessary.

Returns

A 3D mesh object read from the file.

Return type

Mesh3D

property mass

The mass of the mesh (read-only).

Type

float

max_coords()[source]

Returns the maximum coordinates of the mesh.

Returns

A 3-ndarray of floats that represents the minimal x, y, and z coordinates represented in the mesh.

Return type

numpy.ndarray of float

merge(other_mesh)[source]

Combines this mesh with another mesh.

Parameters

other_mesh (Mesh3D) – the mesh to combine with

Returns

merged mesh

Return type

Mesh3D

min_coords()[source]

Returns the minimum coordinates of the mesh.

Returns

A 3-ndarray of floats that represents the minimal x, y, and z coordinates represented in the mesh.

Return type

numpy.ndarray of float

normalize_vertices()[source]

Normalize the mesh’s orientation along its principal axes.

Transforms the vertices and normals of the mesh such that the origin of the resulting mesh’s coordinate frame is at the center of the bounding box and the principal axes (as determined from PCA) are aligned with the vertical Z, Y, and X axes in that order.

property normals

numpy.ndarray of float: A #normals by 3 array, where each row contains a normalized vector. This list should contain one norm per vertex.

property num_triangles

int: The number of total triangles

property num_vertices

int: The number of total vertices

principal_dims()[source]

Returns the maximal span of the mesh’s coordinates.

The maximal span is the maximum coordinate value minus the minimal coordinate value in each principal axis.

Returns

A 3-ndarray of floats that represents the maximal x, y, and z spans of the mesh.

Return type

numpy.ndarray of float

random_points(n_points)[source]

Generate uniformly random points on the surface of the mesh.

Parameters

n_points (int) – The number of random points to generate.

Returns

A n_points by 3 ndarray that contains the sampled 3D points.

Return type

numpy.ndarray of float

ray_intersections(ray, point, distance)[source]

Returns a list containing the indices of the triangles that are intersected by the given ray emanating from the given point within some distance.

remove_bad_tris()[source]

Remove triangles with out-of-bounds vertices from the mesh.

remove_unreferenced_vertices()[source]

Remove any vertices that are not part of a triangular face.

Note

This method will fail if any bad triangles are present, so run remove_bad_tris() first if you’re unsure if bad triangles are present.

Returns

Returns True if vertices were removed, False otherwise.

Return type

bool

rescale(scale_factor)[source]

Rescales the vertex coordinates by scale_factor.

Parameters

scale_factor (float) – The desired scale factor for the mesh’s vertices.

rescale_dimension(scale, scaling_type=0)[source]

Rescales the vertex coordinates to scale using the given scaling_type.

Parameters
  • scale (float) – The desired scaling factor of the selected dimension, if scaling_type is ScalingTypeMin, ScalingTypeMed, ScalingTypeMax, or ScalingTypeDiag. Otherwise, the overall scaling factor.

  • scaling_type (int) – One of ScalingTypeMin, ScalingTypeMed, ScalingTypeMax, ScalingTypeRelative, or ScalingTypeDiag. ScalingTypeMin scales the smallest vertex extent (X, Y, or Z) by scale, ScalingTypeMed scales the median vertex extent, and ScalingTypeMax scales the maximum vertex extent. ScalingTypeDiag scales the bounding box diagonal (divided by three), and ScalingTypeRelative provides absolute scaling.

resting_pose(T_obj_world, eps=1e-10)[source]

Returns the stable pose that the mesh will rest on if it lands on an infinite planar worksurface quasi-statically in the given transformation (only the rotation is used).

Parameters
  • T_obj_world (autolab_core.RigidTransform) – transformation from object to table basis (z-axis upward) specifying the orientation of the mesh

  • eps (float) – numeric tolerance in cone projection solver

Returns

stable pose specifying the face that the mesh will land on

Return type

StablePose

scale_principal_eigenvalues(new_evals)[source]
stable_poses(min_prob=0.0)[source]

Computes all valid StablePose objects for the mesh.

Parameters

min_prob (float) – stable poses that are less likely than this threshold will be discarded

Returns

A list of StablePose objects for the mesh.

Return type

list of StablePose

subdivide(min_tri_length=inf)[source]

Return a copy of the mesh that has been subdivided by one iteration.

Note

This method only copies the vertices and triangles of the mesh.

support(direction)[source]

Returns the support function in the given direction

Parameters

direction (numpy.ndarray of float) – A 3-ndarray of floats that is a unit vector in the direction of the desired support.

Returns

A 3-ndarray of floats that represents the support.

Return type

numpy.ndarray of float

surface_area()[source]

Return the surface area of the mesh.

Returns

The surface area of the mesh.

Return type

float

total_volume()[source]

Return the total volume of the mesh.

Returns

The total volume of the mesh.

Return type

float

transform(T)[source]

Return a copy of the mesh that has been transformed by T.

Parameters

T (RigidTransform) – The RigidTransform by which the mesh is transformed.

Note

This method only copies the vertices and triangles of the mesh.

tri_centers()[source]

Returns an array of the triangle centers as 3D points.

Returns

An ndarray of 3-ndarrays of floats, where each 3-ndarray represents the 3D point at the center of the corresponding mesh triangle.

Return type

numpy.ndarray of numpy.ndarray of float

tri_normals(align_to_hull=False)[source]

Returns a list of the triangle normals.

Parameters

align_to_hull (bool) – If true, we re-orient the normals to point outward from the mesh by using the convex hull.

Returns

A #triangles by 3 array of floats, where each 3-ndarray represents the 3D normal vector of the corresponding triangle.

Return type

numpy.ndarray of float

property triangles

A #tris by 3 array, where each row contains indices of vertices in the vertices array that are part of the triangle.

Type

numpy.ndarray of int

property trimesh

Convert to trimesh.

update_tf(delta_T)[source]

Updates the mesh transformation.

property vertices

A #verts by 3 array, where each row contains an ordered [x,y,z] set that describes one vertex.

Type

numpy.ndarray of float

visualize(color=0.5, 0.5, 0.5, style='surface', opacity=1.0)[source]

Plots visualization of mesh using MayaVI.

Parameters
  • color (tuple of float) – 3-tuple of floats in [0,1] to give the mesh’s color

  • style (str) – Either ‘surface’, which produces an opaque surface, or ‘wireframe’, which produces a wireframe.

  • opacity (float) – A value in [0,1] indicating the opacity of the mesh. Zero is transparent, one is opaque.

Returns

The displayed surface.

Return type

mayavi.modules.surface.Surface

class graspnetAPI.utils.dexnet.grasping.meshpy.ObjFile(filepath)[source]

Bases: object

A Wavefront .obj file reader and writer.

filepath

The full path to the .obj file associated with this reader/writer.

Type

str

property filepath

Returns the full path to the .obj file associated with this reader/writer.

Returns

The full path to the .obj file associated with this reader/writer.

Return type

str

read()[source]

Reads in the .obj file and returns a Mesh3D representation of that mesh.

Returns

A Mesh3D created from the data in the .obj file.

Return type

Mesh3D

write(mesh)[source]

Writes a Mesh3D object out to a .obj file format

Parameters

mesh (Mesh3D) – The Mesh3D object to write to the .obj file.

Note

Does not support material files or texture coordinates.

class graspnetAPI.utils.dexnet.grasping.meshpy.Sdf[source]

Bases: object

Abstract class for signed distance fields.

abstract __getitem__(coords)[source]

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

property center

Center of grid.

This basically transforms the world frame to grid center.

Returns

Return type

numpy.ndarray

center_world()[source]

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

property data

The SDF data.

Returns

The 2- or 3-dimensional ndarray that holds the grid of signed distances.

Return type

numpy.ndarray of float

property dimensions

SDF dimension information.

Returns

The ndarray that contains the dimensions of the sdf.

Return type

numpy.ndarray of int

property 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

is_out_of_bounds(coords)[source]

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

on_surface(coords)[source]

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

property 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

property resolution

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

Returns

The width of each grid cell.

Return type

float

abstract surface_points()[source]

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

abstract transform(tf)[source]

Returns a new SDF transformed by similarity tf.

abstract transform_pt_grid_to_obj(x_grid, direction=False)[source]

Transforms points from grid frame to world frame

abstract transform_pt_obj_to_grid(x_world, direction=False)[source]

Transforms points from world frame to grid frame

transform_to_world()[source]

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

class graspnetAPI.utils.dexnet.grasping.meshpy.Sdf3D(sdf_data, origin, resolution, use_abs=False, T_sdf_world=RigidTransform(rotation=np.array([[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]), translation=np.array([0.0, 0.0, 0.0]), from_frame='sdf', to_frame='world'))[source]

Bases: graspnetAPI.utils.dexnet.grasping.meshpy.sdf.Sdf

__getitem__(coords)[source]

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.

curvature(coords, delta=0.001)[source]

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

  • delta

Returns

curvature

Return type

3x3 ndarray of the curvature at the surface points

static find_zero_crossing_linear(x1, y1, x2, y2)[source]

Find zero crossing using linear approximation

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

Find zero crossing using quadratic approximation along 1d line

gradient(coords)[source]

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.

max_coords_x = [1, 4, 6, 7]
max_coords_y = [2, 4, 5, 7]
max_coords_z = [3, 5, 6, 7]
min_coords_x = [0, 2, 3, 5]
min_coords_y = [0, 1, 3, 6]
min_coords_z = [0, 1, 2, 4]
num_interpolants = 8
rescale(scale)[source]

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

surface_normal(coords, delta=1.5)[source]

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)[source]

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

transform(delta_T)[source]

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

transform_dense(delta_T, detailed=False)[source]

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_grid_to_obj(x_grid, direction=False)[source]

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

  • direction (bool) –

Returns

x_sdf – points in sdf basis (meters)

Return type

numpy 3xN ndarray

transform_pt_obj_to_grid(x_sdf, direction=False)[source]

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

  • direction (bool) –

Returns

x_grid – points in grid basis

Return type

numpy 3xN ndarray or scalar

class graspnetAPI.utils.dexnet.grasping.meshpy.SdfFile(filepath)[source]

Bases: object

A Signed Distance Field .sdf file reader and writer.

filepath

The full path to the .sdf or .csv file associated with this reader/writer.

Type

str

property filepath

Returns the full path to the file associated with this reader/writer.

Returns

The full path to the file associated with this reader/writer.

Return type

str

read()[source]

Reads in the SDF file and returns a Sdf object.

Returns

A Sdf created from the data in the file.

Return type

Sdf

write(sdf)[source]

Writes an SDF to a file.

Parameters

sdf (Sdf) – An Sdf object to write out.

Note

This is not currently implemented or supported.

class graspnetAPI.utils.dexnet.grasping.meshpy.StablePose(p, r, x0, face=None, stp_id=- 1)[source]

Bases: object

A representation of a mesh’s stable pose.

p

Probability associated with this stable pose.

Type

float

r

3x3 rotation matrix that rotates the mesh into the stable pose from standardized coordinates.

Type

numpy.ndarray of :obj`numpy.ndarray` of float

x0

3D point in the mesh that is resting on the table.

Type

numpy.ndarray of float

face

3D vector of indices corresponding to vertices forming the resting face

Type

numpy.ndarray

stp_id

A string identifier for the stable pose

Type

str

T_obj_table

A RigidTransform representation of the pose’s rotation matrix.

Type

RigidTransform

property T_obj_table
property T_obj_world
__eq__(other)[source]

Check equivalence by rotation about the z axis