DWVv0.37.0

Geometry

Source: geometry.js:114

2D/3D Geometry class.


Constructor

new Geometry( origins: Array.<Point3D>, size: Size, spacing: Spacing, orientation?: Matrix33, time?: VolumeId, ): Geometry

Parameters

  • origins (Array.<Point3D>) — The object origins.
  • size (Size) — The object size.
  • spacing (Spacing) — The object spacing.
  • orientation (Matrix33, optional) — The object orientation (33 matrix, default to 33 identity).
  • time (VolumeId, optional) — Optional time: a volume id or, without source, a frame index (for example {id: {value: 2}}).

Instance Methods

clone(): Geometry

Clone the geometry.

Returns

  • Geometry — A clone of this geometry.

getInitialTime(): VolumeId | undefined

Get the time that was passed at construction.

Returns

setInitialTime(time: VolumeId)

Set the initial time.

Parameters

  • time (VolumeId) — The new time: a volume id or, without source, a frame index.

setVolumeValues(values: Array.<SourcedNumberValue>)

Set the associated values of the volume ids, for example once guessed after load (see dicomVolume getVolumeValues).

Parameters

  • values (Array.<SourcedNumberValue>) — The associated values, one per volume id, in volume id order.

Throws

  • Error — If the number of values is not the number of volume ids.

getVolumeIds(): Array.<VolumeId> | undefined

Get the volume ids: the time of each volume, sorted by ascending id, the array index being the volume index. Times are volume ids if their id has a source.

Returns

  • Array.<VolumeId> | undefined — The volume ids, undefined if the times are not volume ids.

setVolumeIds(volumeIds: Array.<VolumeId>)

Set the volume ids of a geometry without times (for example a resampled one): the volumes all have the current origins.

Parameters

  • volumeIds (Array.<VolumeId>) — The volume ids, sorted by ascending id, one per volume (fourth dimension).

getVolumeIndex(id: number): number

Get the index of a volume id.

Parameters

  • id (number) — The volume id.

Returns

  • number — The volume index, -1 if not found.

canSyncVolume(geometry: Geometry, value: number): boolean

Check if the volume of this geometry can follow the one of another geometry: both volume ids have the same origin and the input volume id value is one of this geometry.

Parameters

  • geometry (Geometry) — The geometry to follow.
  • value (number) — The volume id value to follow.

Returns

  • boolean — True if the volume can follow.

getCurrentTotalNumberOfSlices(): number

Get the total number of slices. Can be different from what is stored in the size object during a volume with time points creation process.

Returns

  • number — The total count.

hasSlicesAtTime(time: number): boolean

Check if a time point has associated slices.

Parameters

  • time (number) — The time id to check.

Returns

  • boolean — True if slices are present.

getCurrentNumberOfSlicesBeforeTime( time: number, ): number | undefined

Get the number of slices stored for time points preceding the input one.

Parameters

  • time (number) — The time id to check.

Returns

  • number | undefined — The count.

checkTimeOrigins(): BooleanResult

Check that all time points have the same origins as the initial time point (same number and same values in the same order).

Returns

  • BooleanResult — Result with success set to true if the time origins are consistent.

getOrigin(): Point3D

Get the object origin. This should be the lowest origin to ease calculations (?).

Returns

getOrigins(): Array.<Point3D>

Get the object origins.

Returns

  • Array.<Point3D> — The object origins.

sortOrigins()

Sort origins by Z position ascending.

includesOrigin(point3D: Point3D, tol?: number): boolean

Check if a point is in the origin list.

Parameters

  • point3D (Point3D) — The point to check.
  • tol (number, optional) — Optional number comparison tolerance defaults to Number.EPSILON.

Returns

  • boolean — True if in list.

getSize(viewOrientation?: Matrix33): Size

Get the object size. Warning: the size comes as stored in DICOM, meaning that it could be oriented.

Parameters

  • viewOrientation (Matrix33, optional) — The view orientation (optional).

Returns

  • Size — The object size.

updateSliceSpacing()

Calculate slice spacing from origins and replace current if needed.

getSpacing(viewOrientation?: Matrix33): Spacing

Get the object spacing. Warning: the spacing comes as stored in DICOM, meaning that it could be oriented.

Parameters

  • viewOrientation (Matrix33, optional) — The view orientation (optional).

Returns

getRealSpacing(): Spacing

Get the image spacing in real world.

Returns

getOrientation(): Matrix33

Get the object orientation.

Returns

getSliceIndex(origin: Point3D, time?: number): number

Get the slice position of an origin in the current slice layout. Slice indices increase with decreasing origins (high index -> low origin), this simplified the handling of reconstruction since it means the displayed data is in the same 'direction' as the extracted data. As seen in the getOrigin method, the main origin is the lowest one. This implies that the index to world and reverse method do some flipping magic...

Limitation: the codirectional (before/after) refinement below is a strict sign check on the normal-projected residual, with no tolerance - unlike worldToIndex's magnitude-based half-spacing gate. That is safe for this method's one real caller (Image#appendSlice, which only ever compares exact, already-known slice origins - a clean, large residual, never close to zero), but this method should not be used for an arbitrary point with a large in-plane offset from its closest origin (eg a click position): float noise in that offset, amplified by a lower-precision orientation (eg gantry-tilt direction cosines with few decimal digits), can flip the sign of a residual that should be exactly zero. Use worldToIndex (or a plain Point3D#getClosest) instead for that case.

Parameters

  • origin (Point3D) — The origin to locate.
  • time (number, optional) — Optional time id.

Returns

  • number — The slice index.

canAppendSlice(rhs: Geometry): BooleanResult

Check if another geometry is compatible with this one, ie that slices with these geometries can be merged into one volume.

Parameters

  • rhs (Geometry) — The geometry to check.

Returns

  • BooleanResult — Result with success set to true if the geometry is compatible.

canAppendOrigin(origin: Point3D, time?: number): BooleanResult

Check if an origin can be appended to this geometry.

Parameters

  • origin (Point3D) — The origin to append.
  • time (number, optional) — Optional time id.

Returns

  • BooleanResult — Result with success set to true if the origin is compatible.

appendOrigin(origin: Point3D, index: number, time?: number)

Append an origin to the geometry.

Parameters

  • origin (Point3D) — The origin to append.
  • index (number) — The index at which to append.
  • time (number, optional) — Optional time id.

appendFrame(origin: Point3D, time: VolumeId)

Append a frame to the geometry.

Parameters

  • origin (Point3D) — The origin to append.
  • time (VolumeId) — The frame time: a volume id or, without source, a frame index.

toString(): string

Get a string representation of the geometry.

Returns

  • string — The geometry as a string.

equals(rhs: Geometry): boolean

Check for equality.

Parameters

  • rhs (Geometry) — The object to compare to.

Returns

  • boolean — True if both objects are equal.

isSimilar(rhs: Geometry, tol?: number): boolean

Check for similarity for origin and orientation, equality for size and spacing.

Parameters

  • rhs (Geometry) — The object to compare to.
  • tol (number, optional) — Optional number comparison tolerance, defaults to Number.EPSILON.

Returns

  • boolean — True if both objects are equal.

isInBounds(point: Point): boolean

Check that a point is within bounds.

Parameters

  • point (Point) — The point to check.

Returns

  • boolean — True if the given coordinates are within bounds.

isIndexInBounds(index: Index, dirs?: Array.<number>): boolean

Check that a index is within bounds.

Parameters

  • index (Index) — The index to check.
  • dirs (Array.<number>, optional) — Optional list of directions to check.

Returns

  • boolean — True if the given coordinates are within bounds.

getRange(): Array.<Point>

Get the geometrical range, ie the minimum and maximum positions.

Returns

  • Array.<Point> — The min and max positions.

indexToWorld(index: Index): Point

Convert an index into world coordinates.

Parameters

  • index (Index) — The index to convert.

Returns

  • Point — The corresponding point.

pointToWorld(point: Point3D): Point3D

Convert a 3D point into world coordinates.

Parameters

  • point (Point3D) — The 3D point to convert.

Returns

  • Point3D — The corresponding world 3D point.

worldToIndex(point: Point): Index

Convert world coordinates into an index.

Always returns an index, even for a point outside the geometry: this does not itself mean the point is in bounds, use isIndexInBounds/isInBounds for that. In-plane (row/column), an out-of-bounds point extrapolates freely (eg -5 or size+12). On the scroll axis, a point close to a real per-slice origin snaps to it; further away, it is pinned to just past the first/last known origin (ie the origins array length, or -1) rather than left to drift arbitrarily far via linear extrapolation - except when there are few or no real origins to compare against (eg a root geometry with only its first slice known), where it still falls back to that unclamped extrapolation.

Parameters

  • point (Point) — The point to convert.

Returns

  • Index — The corresponding index.

worldToPoint(point: Point): Point3D

Convert world coordinates into an point.

Parameters

  • point (Point) — The world point to convert.

Returns

  • Point3D — The corresponding point.