Mesh Utilities

Utilities.meshutils.area_AABB(points, **kwargs)[source]

Marks points that are inside the specified AABB in the plan.

Parameters
  • points (torch.Tensor) – Point tensor of dimension (\(N\), 2), with \(N\) number of points, that will be marked.

  • aabb (Utilities.AABB) – The AABB that marks the area.

Returns

Bool tensor of dimension \(N\), with \(i\) True if point \(i\) is inside the shape.

Return type

torch.BoolTensor

Utilities.meshutils.area_convex_hull(points, **kwargs)[source]

Marks points inside a computed convex hull.

Returns a torch.BoolTensor marking points that are inside the convex hull of scatter.

Parameters
  • points (torch.Tensor) – Points tensor of dimension (\(N\), 2), with \(N\) number of points, that will be marked.

  • scatter (torch.Tensor) – Points tensor of dimension (\(M\), 2), with \(M\) number of points, from which the convex hull will be computed.

  • intersect (bool, default=False) – Set this to True if points on the line should be accounted inside the marking region.

Returns

Bool tensor of dimension \(N\), with \(i\) True if point \(i\) is inside the convex hull.

Return type

torch.BoolTensor

Utilities.meshutils.area_convex_shape(points, **kwargs)[source]

Marks points inside a convex shape.

Returns a torch.BoolTensor marking points that are inside the convex shape shape.

Parameters
  • points (torch.Tensor) – Point tensor of dimension (\(N\), 2), with \(N\) number of points, that will be marked.

  • shape (torch.Tensor) – Point tensor of dimension (\(M\), 2), with \(M\) number of points, that defines the convex shape.

  • side (either +1 or -1, default=1) – If set to +1/-1 shape is defined as CW/CCW.

  • intersect (bool, default=False) – Set this to True if points on the line should be accounted inside the marking region.

Returns

Bool tensor of dimension \(N\), with \(i\) True if point \(i\) is inside the convex hull.

Return type

torch.BoolTensor

Utilities.meshutils.area_disc(points, **kwargs)[source]

Marks points that are inside the specified disc in the plan.

Returns a boolean tensor.

Parameters
  • points (torch.Tensor) – Point tensor of dimension (\(N\), 2), with \(N\) number of points, that will be marked.

  • center (torch.Tensor) – Point tensor of dimension (2) that defines the center of the disc.

  • radius (float) – Radius of the disc.

Returns

Bool tensor of dimension \(N\), with \(i\) True if point \(i\) is inside the shape.

Return type

torch.BoolTensor

Utilities.meshutils.area_polyline_outline(points, **kwargs)[source]

Marks points that are in the neighborhood of a polyline.

Parameters
  • points (torch.Tensor) – Point tensor of dimension (\(N\), 2), with \(N\) number of points, that will be marked.

  • polyline (torch.Tensor) – Point tensor of dimension (\(M\), 2), with \(M\) number of vertices, that defines the polyline.

  • width (float, default=0.) – Width of the polyline.

  • close (bool, default=False) – Set to True in order to close the polyline.

Returns

Bool tensor of dimension \(N\), with \(i\) True if point \(i\) is inside the shape.

Return type

torch.BoolTensor

Utilities.meshutils.area_segment(points, **kwargs)[source]

Marks points that are inside the neighborhood of the specified segment in the plan.

Parameters
  • points (torch.Tensor) – Point tensor of dimension (\(N\), 2), with \(N\) number of points, that will be marked.

  • p0 (torch.Tensor) – First point defining the separation line.

  • p1 (torch.Tensor) – Second point defining the separation line and thus its direction.

  • origin (torch.Tensor) – Origin vector.

  • direction (torch.Tensor) – Direction vector.

  • width (torch.Tensor) – Width of the segment.

Returns

Bool tensor of dimension \(N\), with \(i\) True if point \(i\) is inside the shape.

Return type

torch.BoolTensor

Utilities.meshutils.area_shape(points, **kwargs)[source]

Marks points inside a shape.

Returns a torch.BoolTensor marking points that are inside the shape shape. Shape does not need to be convex and can overlap itself.

Parameters
  • points (torch.Tensor) – Point tensor of dimension (\(N\), 2), with \(N\) number of points, that will be marked.

  • shape (torch.Tensor) – Shape.

  • side (either +1 or -1, default=1) – If set to +1/-1 shape is defined as CW/CCW.

  • intersect (bool, default=False) – Set this to True if points on the line should be accounted inside the marking region.

Returns

Bool tensor of dimension \(N\), with \(i\) True if point \(i\) is inside the shape.

Return type

torch.BoolTensor

Utilities.meshutils.area_side(points, **kwargs)[source]

Marks points that are on one side of the specified separation line on the plan.

Returns a torch.BoolTensor marking points that are in side side. The seperation line can either be specified by two points p0 and p1, or by origin and direction.

Parameters
  • points (torch.Tensor) – Point tensor of dimension (\(N\), 2), with \(N\) number of points, that will be marked.

  • p0 (torch.Tensor) – First point tensor of dimension (2) defining the separation line.

  • p1 (torch.Tensor) – Second point tensor of dimension (2) defining the separation line and thus its direction.

  • origin (torch.Tensor) – Origin vector of dimension (2).

  • direction (torch.Tensor) – Direction vector of dimension (2).

  • side (int, either +1 or -1, default=1) – +1/-1 to select points to the left/right of the separation line.

  • intersect (bool, default=False) – Set this to True if points on the line should be accounted inside the marking region.

Returns

Bool tensor of dimension \(N\), with \(i\) True if point \(i\) is at side side of the defined separation line.

Return type

torch.BoolTensor

Utilities.meshutils.close_shape(shape)[source]

Returns the closed shape.

Parameters

shape (torch.Tensor) – Shape tensor of dimension (\(N\)), with \(N\) number of vertices, that will be closed.

Returns

The closed shape.

Return type

torch.Tensor

Utilities.meshutils.compute_centers_normals_lengths(vertices, faces)[source]
Utilities.meshutils.distance_segment(point, p0, p1)[source]

Returns the minimal distance between a point and a segment.

Parameters
  • point (torch.Tensor) – Point tensor of dimension (2) from which distance is computed.

  • p0 (torch.Tensor) – First point defining the segment.

  • p1 (torch.Tensor) – Second point defining the segment.

Returns

The minimal distance between the point and the segment.

Return type

float

Utilities.meshutils.extract_convex_hull(points)[source]

Extracts a convex hull from a set of points.

Notes

The output shape in 2D is CCW defined. In 3D outputs a tuple of points and triangle list forming the convex hull. Uses Scipy internaly.

Parameters

points (torch.Tensor) – Points tensor of dimension (\(N\), d), with \(N\) the number of points and \(d\) the dimension, from which the convex hull will be computed.

Returns

If in 2D, the resulting convex hull, of dimension (\(M\), 2), with \(M\) the number of points the convex hull contains. If in 3D, a 2-tuple with first element representing the points of the convex hull of dimension (\(M\), 3), with \(M\) the number of points the convex hull contains and a list of 3-tuple representing the faces of the hull.

Return type

torch.Tensor

Utilities.meshutils.fill_area_random(area, aabb, N, **kwargs)[source]

Randomly fill a 2D area enclosed by aabb given by the area function.

The random process follows a Poisson distribution. Sampling is done using a rejection sampling algorithm.

Parameters
  • area (callable) – Callable defining the area that will be filled.

  • enclosing_aabb (Utilities.AABB) – Bounding box enclosing the area callable function.

  • N (int) – Number of points to generate.

  • kwargs (dictpp) – Arguments passed to the area function.

Returns

Points tensor of dimension (\(N\), 2), with \(N\) the number of points.

Return type

torch.Tensor

Utilities.meshutils.fill_area_random_density(area, aabb, density, **kwargs)[source]

Randomly fill a 2D area enclosed by aabb given by the area function.

The random process follows a Poisson distribution. Sampling is done using a rejection sampling algorithm.

Parameters
  • area (callable) – Callable defining the area that will be filled.

  • enclosing_aabb (Utilities.AABB) – Bounding box enclosing the area callable function.

  • density (int) – Density of points to generate.

  • kwargs (dict) – Arguments passed to the area function.

Returns

Points tensor of dimension (\(N\), 2), with \(N\) the number of points.

Return type

torch.Tensor

Utilities.meshutils.fill_area_uniform(area, enclosing_aabb, spacing, **kwargs)[source]

Uniformly fills a 2D area enclosed given by a callable.

The area callable should have the following signature:

Parameters
  • area (callable) – Callable defining the area that will be filled.

  • enclosing_aabb (Utilities.AABB) – Bounding box enclosing the area callable function.

  • spacing (float) – Distance between points.

  • kwargs (dict) – Arguments passed to the area callable function.

Returns

Points tensor of dimension (\(N\), 2), with \(N\) the number of points.

Return type

torch.Tensor

Utilities.meshutils.fill_area_uniform_density(area, enclosing_aabb, density, **kwargs)[source]

Fill a 2D area enclosed by aabb given by the area function uniformly.

Parameters
  • area (callable) – Callable defining the area that will be filled.

  • enclosing_aabb (Utilities.AABB) – AABB.

  • density (float) – Density of points.

  • kwargs (dict) – Arguments passed to the area function.

Returns

Points tensor of dimension (\(N\), 2), with \(N\) the number of points.

Return type

torch.Tensor

Utilities.meshutils.gaussian_kernel_smooth(points, sigma)[source]
Utilities.meshutils.is_shape_closed(shape)[source]

Returns True if the input shape is closed.

Parameters

shape (torch.Tensor) – Shape tensor of dimension (\(N\), 2), with \(N\) number of vertices, that will be closed.

Returns

True if shape is closed, False otherwise.

Return type

bool

Utilities.meshutils.kernel_smooth(points, kernel)[source]
Utilities.meshutils.point_side(point, p0, p1)[source]

Returns the side of a point relative to a line.

Parameters
  • point (torch.Tensor) – Point tensor of dimension (2) from which side will be computed.

  • p0 (torch.Tensor) – First point defining the line.

  • p1 (torch.Tensor) – Second point defining the line, and thus it’s direction.

Returns

-1/+1 if the point is on the left/right. 0 if the point is exactly on the line.

Return type

int

Utilities.meshutils.resample_curve(curve, density)[source]
Utilities.meshutils.winding_order(point, shape, side)[source]

Returns the winding order of a point relative to a shape.

Notes

This function assumes the shape is closed.

Parameters
  • point (torch.Tensor) – Point tensor of dimension (2) around which the winding order will be computed.

  • shape (torch.Tensor) – Shape tensor of dimension (\(N\)), with \(N\) number of vertices, from which the winding order will be computed.

  • side (int, either +1 or -1) – Set to +1/-1 if shape is defined CCW/CW.

Returns

The computed winding order.

Return type

int