ColouredTriMesh

class menpo.shape.mesh.ColouredTriMesh(points, trilist=None, colours=None, copy=True)

Bases: TriMesh, Rasterizable

Combines a TriMesh with a colour per vertex.

Parameters:

points : (N, D) ndarray

The coordinates of the mesh.

trilist : (M, 3) ndarray, optional

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

Default: None

colours : (N, 3) ndarray, optional

The floating point RGB colour per vertex. If not given, grey will be assigned to each vertex.

Default: None

copy: bool, optional :

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

Default: False

Raises:

ValueError :

If the number of colour values does not match the number of vertices.

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 ColouredTriMesh.

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

Returns:

colouredtrimesh: :map:`ColouredTriMesh` :

A ColouredTriMesh with the same points, trilist, colours 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.

tojson()

Convert this TriMesh to a dictionary JSON representation.

Returns:

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

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

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