ntop.core. All coordinates and distances are in meters.
Loading a body
ntop.core.load
.implicit file. Triggers process-wide one-shot initialization of the engine’s dependencies on the first call.
- Raises
FileNotFoundErrorif the file does not exist,PermissionErrorif it cannot be opened,ValueErrorif the file is corrupt or an unsupported version.
ImplicitBody releases its native handle automatically when garbage collected, or immediately via a context manager:
ImplicitBody
Properties
field
points: shape(N, 3)or(3,). A single(3,)point returns a scalar rather than a length-1 array.- Raises
ValueErrorfor the wrong shape,ReferenceErrorif the handle was already released.
gradient
points: shape(N, 3)or(3,).- Returns a
GradientResult(values, gradient).gradienthas shape(N, 3)(or(3,)for a single point); its magnitude is 1 everywhere except the medial axis for a signed-distance field. - Raises
ValueErrorfor the wrong shape,ReferenceErrorif the handle was already released.
mesh
feature_size: sampling granularity in meters; smaller is finer. Must be positive.adaptivity: decimation tolerance.0disables decimation; negative values are clamped to0.- Returns a
TriangleMesh(always non-empty). - Raises
ValueErroriffeature_sizeis not positive,RuntimeErrorif meshing produced zero geometry (empty body, orfeature_sizetoo coarse),ReferenceErrorif the handle was already released.
Respects
KeyboardInterrupt when called from the main thread: meshing runs on a worker thread while the caller polls for signals.slice
z in the body’s XY plane.
feature_size: sampling granularity in meters. Must be positive.method:"dc"(Dual Contouring, default) or"ms"(Marching Squares).- Returns a list of
(K, 2)arrays, one per contour. An empty list is a valid result (e.g.zoutside the body) and does not raise. - Raises
ValueErroriffeature_sizeis not positive ormethodis unrecognized,ReferenceErrorif the handle was already released.
voxelize
field (no additional engine call).
spacing: distance between sample points in meters along all three axes. Must be positive.dimensions: physical(width, height, depth)of the sampling volume. Defaults to the body’s bounding box projected onto the frame axes.frame: orientation and origin of the sampling volume. Defaults to world-aligned axes with origin atbounding_box.min.- Returns a
(nx, ny, nz)boolean array,True= inside. Streams one Z-slice at a time, so peak memory isO(nx * ny)rather thanO(nx * ny * nz). - Raises
ValueErrorifspacingor adimensionsentry is not positive,ReferenceErrorif the handle was already released.
rasterize
ntop_core_fast_inout_query).
spacing: distance between sample points in meters. Must be positive.dimensions: physical(width, height)of the sampling window. Defaults to the bounding box projected onto the frame axes.frame: orientation and origin of the grid. Defaults to the world XY plane at the body’s center z-height.isovalue: offsets the body before sampling; positive expands, negative contracts.- Returns a
(height, width)boolean array, row-major, origin bottom-left. - Raises
ValueErrorifspacingor adimensionsentry is not positive,ReferenceErrorif the handle was already released.
closest_point
points: shape(N, 3).tolerance: convergence threshold in meters. Must be positive.- Returns
(projected, out_of_tolerance): best-effort projected positions for every input point, and the indices that did not converge withintolerance(empty if all converged). - Raises
ValueErrorfor the wrong shape or non-positivetolerance,ReferenceErrorif the handle was already released.
interval
(lower, upper) over a bounding box region. Same-sign bounds mean the region is strictly inside or outside the body; mixed-sign bounds do not guarantee a zero crossing exists.
- Raises
ReferenceErrorif the handle was already released.
transform
ImplicitBody. This body is unchanged.
Uses a passive-transform (pull-back) convention: frame.origin is the point in the old body’s space that maps to [0, 0, 0] in the new space. To translate by +d, set frame.origin = -d.
- Raises
ReferenceErrorif the handle was already released.
scale
pivot point, returning a new ImplicitBody. This body is unchanged.
factors,pivot: shape(3,).- Raises
ValueErrorif either argument is not shape(3,),ReferenceErrorif the handle was already released.
The field is only exactly preserved as a signed-distance field for uniform scale. Non-uniform scale approximates it by rescaling with
cbrt(sx * sy * sz).save
.implicit file.
- Raises
OSErrorif the file could not be written,ReferenceErrorif the handle was already released.
Data types
BoundingBox
Axis-aligned bounding box, in meters.
Frame
A local coordinate frame, used by transform, voxelize, and rasterize.
x_axis and y_axis are validated as unit vectors and as a mutually orthogonal pair at construction (ValueError if not).
GradientResult
Named tuple returned by gradient.
TriangleMesh
Returned by mesh.
Also unpacks positionally:
vertices, faces = body.mesh(feature_size=0.001).
Exceptions
All exceptions raised byntop.core are standard Python builtins (ValueError, FileNotFoundError, PermissionError, MemoryError, RuntimeError, ReferenceError, OSError). See each method’s Raises entry above for which one applies and when.
