Tin¶
Class to encapsulate a tin made simply of arrays of points, triangles and adjacency information. Also methods to manipulate it.
-
class
xms.grid.triangulate.
Tin
(points=None, triangles=None, **kwargs)¶ -
__init__
(points=None, triangles=None, **kwargs)¶ Initialize self. See help(type(self)) for accurate signature.
-
adjacent_triangle
(triangle_index, edge_idx)¶ Find the adjacent triangle from a triangle index and an edge
- Parameters
triangle_index – index of the triangle
edge_idx – index of the edge
- Returns
The triangle adjance to the triangle at the index or None if there isn’t one
-
property
boundary_points
¶ Indices of all points on any boundary, in no particular order
-
property
boundary_polys
¶ Exterior boundary and all interior voids as polygons of 0-based point indices. First point is not repeated as the last point.
-
build_triangles_adjacent_to_points
()¶ Build array of triangles adjacent to points.
-
clear
()¶ Clear the tin of all points, triangles, and triangles adjacent to points.
-
common_edge_index
(triangle, adjacent_triangle)¶ Find common edge between triangle and neighbor
- Parameters
triangle – triangle index
adjacent_triangle – adjacent triangle index
- Returns
local index of the edge between the triange and adjacent_triangle if it exists, None otherwise.
-
delete_points
(points)¶ Delete a list of points, update and renumber.
- Parameters
points – Points to be deleted
-
delete_triangles
(triangles)¶ Delete a list of triangles, update and renumber.
- Parameters
triangles – Triangle to be deleted
-
export_tin_file
(file_name)¶ Export in the .tin file format.
- Parameters
file_name (str) – a file to write the tin to
-
property
extents
¶ The extents of the tin
-
global_index
(triangle_idx, local_point)¶ Returns the global index of a point given the local index and a triangle
- Parameters
triangle_idx – triangle to search
local_point – local index
- Returns
global index of local_point in triangle_idx
-
local_index
(triangle, point)¶ Returns index (0-2) of point within triangle given global index.
- Parameters
triangle – triangle index
point – global point index
- Returns
local index of the point in the triangle, or None if it is not part of the triangle
-
next_boundary_point
(point)¶ Get the next point CW from point on the boundary. CCW if in an inside hole.
- Parameters
point (int) – The starting point
- Returns
The point index or None if not found
-
property
number_of_points
¶ Number of points in the tin
-
property
number_of_triangles
¶ Number of triangles in the tin
-
optimize_triangulation
()¶ Swaps triangle edges until they are a Delauney triangulation.
- Returns
True if modified, False otherwise
-
property
points
¶ Points in the tin
-
previous_boundary_point
(point)¶ Get the previous point CCW from point on the boundary. CW if in an inside hole.
- Parameters
point (int) – The starting point
- Returns
The point index or None if not found
-
remove_long_thin_triangles_on_perimeter
(ratio)¶ Removes long thin triangles on the boundary of the tin.
- Parameters
ratio – The ratio of one edge length compared to the sum of the other two edge lengths. If the length ratio of a triangle is greater then or equal to this given ratio, the triangle is deleted.
- Returns
True if successful, False otherwise
-
set_geometry
(points, triangles, triangles_adjacent_to_points)¶ Set the geomoetry of the tin
- Parameters
points – Points in tin
triangles – Triangles defining tin
triangles_adjacent_to_points – Triangles adjacent to points
-
swap_edge
(triangle_a, triangle_b, check_angle=True)¶ Swap edges if triangles combine to form convex quad.
- Parameters
triangle_a – First triangle
triangle_b – Second triangle
check_angle – Dont swap very thin triangles
- Returns
True if successful False otherwise
-
triangle_adjacent_to_edge
(point1, point2)¶ Gives triangle on the right side of the edge.
- Parameters
point1 – first point of the edge
point2 – second point of the edge
- Returns
The triangle adjacent to the edge.
-
triangle_area
(triangle)¶ Calculate and return the area of a triangle.
- Parameters
triangle (int) – Triangle index (0-based).
- Returns
The area
-
triangle_centroid
(triangle)¶ Calculate and return the centroid of a triangle.
- Parameters
triangle (int) – Triangle index (0-based).
- Returns
The centroid
-
triangle_from_edge
(point1, point2)¶ Finds the triangle with the edge defined by an edge
- Parameters
point1 – first point of edge
point2 – second point of edge
- Returns
Triangle from an edge
-
property
triangles
¶ Triangles defining the tin
-
property
triangles_adjacent_to_points
¶ Triangles adjacent to points
-
triangulate
()¶ Triangulate the tin
-
vertices_are_adjacent
(point1, point2)¶ Check if vertices form an edge of a triangle
- Parameters
point1 – first point index
point2 – second point index
- Returns
True if points form a triangle edge, False otherwise.
-