Skip to main content

Module contour

Module contour 

Source
Expand description

Iso-dose contours of a gridded scalar field, with the area and centroid of each closed contour.

The contours are found by marching squares (W. E. Lorensen and H. E. Cline, “Marching cubes: a high resolution 3D surface construction algorithm”, Comput. Graph. 21, 163 (1987), the 2D case), with linear interpolation along the cell edges. A grid point is inside when its value is >= threshold.

  • Every contour is directed with the inside on its left. An outer boundary of an exposed feature is therefore counter-clockwise (positive Contour::signed_area_m2) and the boundary of a hole in a feature is clockwise (negative). The area of a feature with holes is the sum of the signed areas of its outer contour and its holes.
  • The saddle cells (two diagonal inside corners) are resolved by the mean of the four corner values: inside connects the inside corners when the mean is >= threshold, and separates them otherwise.
  • Open contours. A feature that touches the grid edge has a contour that leaves the grid. It is returned with closed = false, in the order walked, and has no area and no centroid (they are None): the grid does not say where the feature ends. Enlarge the grid to close it.
  • The area of a closed contour is the shoelace area of its polygon, and the centroid is the area centroid of that polygon (Bourke’s polygon formulas; textbook). The polygon is the piecewise-linear contour, so the area differs from the smooth contour’s by O(h²) in the grid spacing.

Contours are produced in a fixed order (by the cell and edge where each starts), so the output is deterministic.

Structs§

Contour
One contour.

Functions§

contours
The contours of dose at threshold.
contours_of
The contours of values (row-major on grid) at threshold.