TexturedTriMesh

class menpo.shape.mesh.TexturedTriMesh(points, tcoords, texture, trilist=None, copy=True)

Bases: TriMesh, Rasterizable

Combines a TriMesh with a texture. Also encapsulates the texture coordinates required to render the texture on the mesh.

Parameters:

points : (N, D) ndarray

The coordinates of the mesh.

tcoords : (N, 2) ndarray

The texture coordinates for the mesh.

texture : Image

The texture for the mesh.

trilist : (M, 3) ndarray, optional

The triangle list for the mesh. If None, a Delaunay triangulation will be performed.

Default: None

copy: bool, optional :

If False, the points, trilist and texture will not be copied on assignment. In general this should only be used if you know what you are doing.

Default: False

as_vector(**kwargs)

Returns a flattened representation of the object as a single vector.

Returns:

vector : (N,) ndarray

The core representation of the object, flattened into a single vector. Note that this is always a view back on to the original object, but is not writable.

bounds(boundary=0)

The minimum to maximum extent of the PointCloud. An optional boundary argument can be provided to expand the bounds by a constant margin.

Parameters:

boundary : float

A optional padding distance that is added to the bounds. Default is 0, meaning the max/min of tightest possible containing square/cube/hypercube is returned.

Returns:

min_b : (n_dims,) ndarray

The minimum extent of the PointCloud and boundary along each dimension

max_b : (n_dims,) ndarray

The maximum extent of the PointCloud and boundary along each dimension

copy()

An efficient copy of this TexturedTriMesh.

Only landmarks and points will be transferred. For a full copy consider using deepcopy().

Returns:

texturedtrimesh: :map:`TexturedTriMesh` :

A TexturedTriMesh with the same points, trilist, tcoords, texture and landmarks as this one.

distance_to(pointcloud, **kwargs)

Returns a distance matrix between this point cloud and another. By default the Euclidian distance is calculated - see scipy.spatial.distance.cdist for valid kwargs to change the metric and other properties.

Parameters:

pointcloud : PointCloud

The second pointcloud to compute distances between. This must be of the same dimension as this PointCloud.

Returns:

distance_matrix: ``(n_points, n_points)`` `ndarray` :

The symmetric pairwise distance matrix between the two PointClouds s.t. distance_matrix[i, j] is the distance between the i’th point of this PointCloud and the j’th point of the input PointCloud.

from_mask(mask)

A 1D boolean array with the same number of elements as the number of points in the pointcloud. This is then broadcast across the dimensions of the pointcloud and returns a new pointcloud containing only those points that were True in the mask.

Parameters:

mask : (n_points,) ndarray

1D array of booleans

Returns:

pointcloud : PointCloud

A new pointcloud that has been masked.

from_vector(flattened)

Builds a new TriMesh given then flattened vector. This allows rebuilding pointclouds with the correct number of dimensions from a vector. Note that the trilist will be drawn from self.

Parameters:

flattened : (N,) ndarray

Vector representing a set of points.

Returns:

trimesh : TriMesh

A new trimesh created from the vector with self’s trilist.

from_vector_inplace(vector)

Updates this PointCloud in-place with a new vector of parameters

norm(**kwargs)

Returns the norm of this point cloud. This is a translation and rotation invariant measure of the point cloud’s intrinsic size - in other words, it is always taken around the point cloud’s centre.

By default, the Frobenius norm is taken, but this can be changed by setting kwargs - see numpy.linalg.norm for valid options.

Returns:

norm : float

The norm of this PointCloud

range(boundary=0)

The range of the extent of the PointCloud.

Parameters:

boundary : float

A optional padding distance that is used to extend the bounds from which the range is computed. Default is 0, no extension is performed.

Returns:

range : (n_dims,) ndarray

The range of the PointCloud extent in each dimension.

tcoords_pixel_scaled()

Returns a PointCloud that is modified to be suitable for directly indexing into the pixels of the texture (e.g. for manual mapping operations). The resulting tcoords behave just like image landmarks do:

>>> texture = texturedtrimesh.texture
>>> tc_ps = texturedtrimesh.tcoords_pixel_scaled()
>>> pixel_values_at_tcs = texture[tc_ps[: ,0], tc_ps[:, 1]]

The operations that are performed are:

  • Flipping the origin from bottom-left to top-left
  • Scaling the tcoords by the image shape (denormalising them)
  • Permuting the axis so that
Returns:

tcoords_scaled : PointCloud

A copy of the tcoords that behave like Image landmarks

tojson()

Convert this TriMesh to a dictionary JSON representation.

Returns:

dictionary with ‘points’, ‘trilist’ and ‘tcoords’ keys. Both are lists :

suitable for use in the by the `json` standard library package. :

Note that textures are best transmitted in a native format like jpeg :

rather that in a JSON format. For this reason the texture itself is :

not encoded. Consumers of this method (e.g. a web server serving :

Menpo TexturedTriMeshes) could use the ioinfo property to locate the :

original texture on disk for clients and serve this directly. :

update_from_mask(mask)

A 1D boolean array with the same number of elements as the number of points in the pointcloud. This is then broadcast across the dimensions of the pointcloud. The same pointcloud is updated in place.

Parameters:

mask : (n_points,) ndarray

1D array of booleans

Returns:

pointcloud : PointCloud

A pointer to self.

view(**kwargs)

View the object using the default rendering engine figure handling. For example, the default behaviour for Matplotlib is that all draw commands are applied to the same figure object.

Parameters:

kwargs : dict

Passed through to specific rendering engine.

Returns:

viewer : Renderer

The renderer instantiated.

view_new(**kwargs)

View the object on a new figure.

Parameters:

kwargs : dict

Passed through to specific rendering engine.

Returns:

viewer : Renderer

The renderer instantiated.

view_on(figure_id, **kwargs)

View the object on a a specific figure specified by the given id.

Parameters:

figure_id : object

A unique identifier for a figure.

kwargs : dict

Passed through to specific rendering engine.

Returns:

viewer : Renderer

The renderer instantiated.

centre

The mean of all the points in this PointCloud (in the centre of mass sense)

Type:(n_dims) ndarray The mean of this PointCloud’s points.
centre_of_bounds

The centre of the absolute bounds of this PointCloud. Contrast with centre, which is the mean point position.

Type:n_dims ndarray The centre of the bounds of this PointCloud.
face_normals

Normal at each face.

Type:(n_tris, 3) ndarray

Compute the face normals from the current set of points and triangle list. Only valid for 3D dimensional meshes.

Raises:

DimensionalityError :

If mesh is not 3D

h_points

homogeneous points of shape (n_dims + 1, n_points)

n_dims

The number of dimensions in the pointcloud.

Type:int
n_landmark_groups

The number of landmark groups on this object.

Type:int
n_parameters

The length of the vector that this object produces.

Type:int
n_points

The number of points in the pointcloud.

Type:int
n_tris

The number of triangles in the triangle list.

Type:int
vertex_normals

Normal at each point.

Type:(n_points, 3) ndarray

Compute the per-vertex normals from the current set of points and triangle list. Only valid for 3D dimensional meshes.

Raises:

DimensionalityError :

If mesh is not 3D