Table of Contents

Class ShellMetrics

Namespace
CADability.GeoObject
Assembly
CADability.dll

Measures a shell: the enclosed volume and the surface area integrated over the parameter domains of the faces (exact up to the quadrature, independent of the triangulation), the size of the shell and some topological counts. Ported from the ShapeIt application, where it measures the results of the modeling operations.

public static class ShellMetrics
Inheritance
ShellMetrics
Inherited Members

Properties

AreaFallbackCount

The number of faces whose area fell back to the flat triangle sum since the process started. Diagnostics only, like VolumeFallbackCount.

public static int AreaFallbackCount { get; }

Property Value

int

VolumeFallbackCount

The number of faces that fell back to the tetrahedron sum since the process started. Diagnostics only: a test reads it before and after a measurement to see whether the boundary route held.

public static int VolumeFallbackCount { get; }

Property Value

int

Methods

EulerCharacteristic(Shell)

V - E + F - R with E counting only real edges (no poles) and R the number of inner loops. Subtracting R is what makes the number meaningful for faces with holes, which the plain V - E + F does not handle: the Euler-Poincare formula for a b-rep requires every face to be a disk.

For a single closed shell the result is 2 - 2*genus: 2 for anything sphere-like, 0 with one through hole, -2 with two, and so on. It is a topology fingerprint, not an assertion - a wrong value in the baseline diff means faces, edges or loops got lost or duplicated.

public static int EulerCharacteristic(Shell shell)

Parameters

shell Shell

Returns

int

HoleLoopCount(Shell)

The number of inner loops (holes) over all faces of the shell.

public static int HoleLoopCount(Shell shell)

Parameters

shell Shell

Returns

int

IntegratedVolume(Shell)

The enclosed volume, integrated over the parameter domain of every face rather than summed over its triangles.

By the divergence theorem the volume of a closed body is 1/3 * closed integral of (r - c).n dA for any fixed point c, and for a parametrized face n dA = (Su x Sv) du dv, so one face contributes

integral over D of f(u,v) du dv, f = (S(u,v) - c).(Su x Sv) / 3

That integral over the uv domain D is turned into an integral over the BOUNDARY of D by Green's theorem, see CADability.GeoObject.ShellMetrics.GreenFaceIntegral(CADability.Shapes.SimpleShape,CADability.BoundingRect,System.Func{CADability.GeoPoint2D,System.Double},System.Double,System.Double[],System.Double[]). The boundary is the 2d outline the face carries anyway, so the triangulation does not enter the value: it is used only to read the orientation of the face, see CADability.GeoObject.ShellMetrics.OrientationOf(CADability.GeoObject.ISurface,CADability.GeoPoint[],CADability.GeoPoint2D[],System.Int32[]), and for the fallback of a face the boundary route cannot handle. Planar faces keep their closed form, a constant integrand times the area of the domain.

Until 2026-09-24 the domain was partitioned by the uv triangles of the mesh, with the shortfall along a curved outline corrected by the factor domain/covered, and a switch to the tetrahedron sum beyond 2 percent. That was good for most faces and bad at a pole: the triangulation drops the degenerate triangles next to the apex of a cone, so 2 to 23 percent of the domain of a trimmed pointed cone went uncovered depending on the mesh, and since the integrand vanishes towards the apex the global factor overcorrected. Measured on a pointed cone with a box cut out of it, five meshes gave errors between -0.07 and -1.8 percent, jumping whenever the mesh flipped the route. The boundary integral has no such switch, and a pole needs no special case: it is a line of constant v in the uv plane and contributes nothing to an integral over dv.

c is the center of the exact extent of the shell, not the origin. For a closed shell that changes nothing, the shift adds 1/3 * c . closed integral of n dA, which vanishes. But the contribution of every single face shrinks to the size of the shell, and with it whatever error a face carries - a shell far away from the origin used to be a sum of large face terms that nearly cancel.

What no quadrature can remove is the domain D itself, whose boundary is only as good as the 2d curves of the face. A ProjectedCurve is replaced by a spline through its points, within 1e-7 of the size of the domain. The curve of an intersection edge (InterpolatedDualSurfaceCurve.ProjectedCurve) is integrated with its exact points, see CADability.GeoObject.ShellMetrics.DifferencedDerivative(System.Func{System.Double,CADability.GeoPoint2D},System.Double,System.Double[]); until October 2026 it was replaced by a spline too, and faces bounded by intersection curves of crossing cylinders were up to 1e-4 relative off, where they are now within about 1e-9 (#459).

public static double IntegratedVolume(Shell shell)

Parameters

shell Shell

Returns

double

IntegratedVolume(Shell, double)

IntegratedVolume(Shell) with the mesh precision given explicitly. The mesh only decides the orientation of each face and the fallback here, so the answer is not supposed to depend on it - which is what VolumeTests.IntegratedVolumeMatchesAnalyticOnEveryMesh uses this overload to check.

public static double IntegratedVolume(Shell shell, double precision)

Parameters

shell Shell
precision double

Returns

double

IsPoleEdge(Edge)

A pole edge has no 3d curve and starts and ends at the same vertex - the degenerate boundary at the apex of a cone or at the pole of a sphere. It is a boundary in parameter space only and must not be counted as an edge of the solid.

public static bool IsPoleEdge(Edge edge)

Parameters

edge Edge

Returns

bool

PrecisionFor(Shell)

The precision volume, area and extent are computed with. It must not be 0.0, which is what the rest of the code passes: CADability.GeoObject.Face.AssureTriangles(System.Double) then reuses whatever triangulation happens to exist

  • however coarse it was made - and invents "extent size / 10" when there is none.

Asking for an explicit precision is only half the story: a face keeps a triangulation that is fine enough already, so a measurement which must not depend on earlier calls should run on a copy of the shell.

public static double PrecisionFor(Shell shell)

Parameters

shell Shell

Returns

double

RealEdgeCount(Shell)

Edges that really are edges of the solid, i.e. everything except the poles.

public static int RealEdgeCount(Shell shell)

Parameters

shell Shell

Returns

int

SizeOf(Shell)

The size of the shell, from the exact geometry only - vertex positions and edge curves, never from a triangulation - so it is the same number in every run. This is the absolute floor for comparing coordinates near zero, and the base PrecisionFor(Shell) derives the mesh precision from.

public static double SizeOf(Shell shell)

Parameters

shell Shell

Returns

double

SurfaceArea(Shell)

The 3d surface area: the integral of |Su x Sv| over the parameter domain of every face, by the same boundary integral the volume uses, see CADability.GeoObject.ShellMetrics.IntegrateOverDomain(CADability.GeoObject.ISurface,CADability.Shapes.SimpleShape,CADability.BoundingRect,System.Func{CADability.GeoPoint,CADability.GeoVector,CADability.GeoVector,System.Double},System.Double). A planar face is closed form, |Su x Sv| is constant there and the area is that times the exact area of the domain - which makes a trimmed disc pi*r^2 instead of the inscribed polygon.

The history, because both earlier versions were steps in the right direction and both left the mesh in the value. Until 2026-08-25 the flat triangles were summed, which underestimates a curved face by an amount that only falls with the square of the mesh size. Until 2026-09-24 the uv triangles partitioned the domain, with the shortfall along a curved outline corrected by the factor domain/covered and a switch back to the flat sum beyond 2 percent. That was the same weakness the volume had at the apex of a trimmed cone, where the triangulation drops the degenerate triangles: the small part coneCylConeMinusCyl#1 of ConeCylinderCommonInsphere, whose exact area is 410.4147, was recorded as 410.80, 412.75, 413.27 and 412.78 by successive versions of unrelated code.

The mesh is triangulated only for a face that has to fall back to the flat sum.

public static double SurfaceArea(Shell shell)

Parameters

shell Shell

Returns

double

TotalEdgeLength(Shell)

public static double TotalEdgeLength(Shell shell)

Parameters

shell Shell

Returns

double