Skip to content

Class: NeuroSpace ​

Defined in: src/geometry/NeuroSpace.ts:16

Constructors ​

Constructor ​

ts
new NeuroSpace(
   dim, 
   spacing?, 
   origin?, 
   axes?, 
   transform?): NeuroSpace;

Defined in: src/geometry/NeuroSpace.ts:32

Constructs a new NeuroSpace instance.

Parameters ​

dim ​

readonly number[]

An array representing the dimensions of the space.

spacing? ​

readonly number[]

Optional array representing the spacing of each dimension. Defaults to 1 for each dimension up to 3.

origin? ​

readonly number[]

Optional array representing the origin of the space. Defaults to 0 for each dimension up to 3.

axes? ​

AxisSet

Optional AxisSet representing the orientation of the space.

transform? ​

Matrix | readonly readonly number[][]

Optional transformation matrix. If not provided, an identity matrix is used.

Returns ​

NeuroSpace

Accessors ​

dim ​

Get Signature ​

ts
get dim(): number[];

Defined in: src/geometry/NeuroSpace.ts:471

Returns ​

number[]


origin ​

Get Signature ​

ts
get origin(): number[];

Defined in: src/geometry/NeuroSpace.ts:475

Returns ​

number[]


spacing ​

Get Signature ​

ts
get spacing(): number[];

Defined in: src/geometry/NeuroSpace.ts:485

Gets the spacing values.

Returns ​

number[]

An array of spacing values.


axes ​

Get Signature ​

ts
get axes(): Readonly<AxisSet>;

Defined in: src/geometry/NeuroSpace.ts:490

Returns ​

Readonly<AxisSet>


size ​

Get Signature ​

ts
get size(): number;

Defined in: src/geometry/NeuroSpace.ts:498

Get the total number of elements (voxels) in this space.

Returns ​

number

The product of all dimensions


trans ​

Get Signature ​

ts
get trans(): Matrix;

Defined in: src/geometry/NeuroSpace.ts:502

Returns ​

Matrix


inverseTrans ​

Get Signature ​

ts
get inverseTrans(): Matrix;

Defined in: src/geometry/NeuroSpace.ts:506

Returns ​

Matrix

Methods ​

extractSliceNeuroSpace() ​

ts
extractSliceNeuroSpace(zlevel, axisToDrop?): NeuroSpace;

Defined in: src/geometry/NeuroSpace.ts:206

Parameters ​

zlevel ​

number

axisToDrop? ​

number

Returns ​

NeuroSpace


dropDim() ​

ts
dropDim(): NeuroSpace | null;

Defined in: src/geometry/NeuroSpace.ts:281

Returns ​

NeuroSpace | null


ndim() ​

ts
ndim(): number;

Defined in: src/geometry/NeuroSpace.ts:424

Gets the number of dimensions.

Returns ​

number

The number of dimensions.


centroid() ​

ts
centroid(): number[];

Defined in: src/geometry/NeuroSpace.ts:435

Calculates the centroid of the NeuroSpace. The centroid is the geometric center of the space, calculated by averaging the coordinates of two opposite corners of the bounding box.

Returns ​

number[]

An array representing the coordinates of the centroid.


dimOf() ​

ts
dimOf(axis): number;

Defined in: src/geometry/NeuroSpace.ts:449

Gets the size of a specific dimension based on the axis.

Parameters ​

axis ​

NamedAxis

The axis for which to get the dimension size.

Returns ​

number

The size of the dimension.


whichDim() ​

ts
whichDim(axis): number;

Defined in: src/geometry/NeuroSpace.ts:461

Determines which dimension corresponds to the given axis.

Parameters ​

axis ​

NamedAxis

The axis to match.

Returns ​

number

The index of the matching dimension.

Throws ​

NeuroimError (INVALID_ARGUMENT) if no matching axis is found.


withDimensions() ​

ts
withDimensions(dim): NeuroSpace;

Defined in: src/geometry/NeuroSpace.ts:515

Create a space with different logical dimensions but identical spatial geometry. This is intended for 3D volume <-> 4D vector conversions, where the complete affine (including obliquity/shear) must be retained.

Parameters ​

dim ​

readonly number[]

Returns ​

NeuroSpace


isSpatiallyCompatibleWith() ​

ts
isSpatiallyCompatibleWith(other, tolerance?): boolean;

Defined in: src/geometry/NeuroSpace.ts:533

Compare complete spatial geometry using a scale-aware affine tolerance.

Parameters ​

other ​

NeuroSpace

tolerance? ​

number = 1e-6

Returns ​

boolean


bounds() ​

ts
bounds(): [number[], number[]];

Defined in: src/geometry/NeuroSpace.ts:563

Calculates the bounds of the NeuroSpace.

Returns ​

[number[], number[]]

A tuple containing the minimum and maximum coordinates.


indexToGrid() ​

ts
indexToGrid(idx): number[];

Defined in: src/geometry/NeuroSpace.ts:579

Converts a linear index to grid coordinates.

Parameters ​

idx ​

number

The linear index.

Returns ​

number[]

An array representing grid coordinates.


indexToCoord() ​

ts
indexToCoord(idx): number[];

Defined in: src/geometry/NeuroSpace.ts:588

Converts a linear index to real-world coordinates.

Parameters ​

idx ​

number

The linear index.

Returns ​

number[]

An array representing real-world coordinates.


coordToIndex() ​

ts
coordToIndex(coords): number;

Defined in: src/geometry/NeuroSpace.ts:599

Converts real-world coordinates to a linear index.

Parameters ​

coords ​

number[]

An array of real-world coordinates.

Returns ​

number

The corresponding linear index.


coordToGrid() ​

ts
coordToGrid(coords): number[];

Defined in: src/geometry/NeuroSpace.ts:609

Converts real-world coordinates to grid coordinates.

Parameters ​

coords ​

number[]

An array of real-world coordinates.

Returns ​

number[]

An array representing grid coordinates.


containsCoord() ​

ts
containsCoord(coords): boolean;

Defined in: src/geometry/NeuroSpace.ts:613

Parameters ​

coords ​

number[]

Returns ​

boolean


voxelToWorld() ​

ts
voxelToWorld(voxel): number[];

Defined in: src/geometry/NeuroSpace.ts:624

Converts voxel coordinates to world coordinates. Alias for gridToCoord.

Parameters ​

voxel ​

number[]

An array of voxel coordinates.

Returns ​

number[]

An array representing world coordinates.


worldToVoxel() ​

ts
worldToVoxel(world): number[];

Defined in: src/geometry/NeuroSpace.ts:634

Converts world coordinates to voxel coordinates. Alias for coordToGrid.

Parameters ​

world ​

number[]

An array of world coordinates.

Returns ​

number[]

An array representing voxel coordinates.


gridToGrid() ​

ts
gridToGrid(vox): number[];

Defined in: src/geometry/NeuroSpace.ts:643

Converts voxel coordinates to real-world coordinates.

Parameters ​

vox ​

number[]

An array of voxel coordinates.

Returns ​

number[]

An array representing real-world coordinates.


gridToCoord() ​

ts
gridToCoord(coords): number[];

Defined in: src/geometry/NeuroSpace.ts:666

Converts grid coordinates to real-world coordinates.

Parameters ​

coords ​

number[]

An array of grid coordinates.

Returns ​

number[]

An array representing real-world coordinates.


gridToIndex() ​

ts
gridToIndex(coords): number;

Defined in: src/geometry/NeuroSpace.ts:700

Converts grid coordinates to a linear index.

Parameters ​

coords ​

number[]

An array of grid coordinates.

Returns ​

number

The corresponding linear index.


reorient() ​

ts
reorient(orient): NeuroSpace;

Defined in: src/geometry/NeuroSpace.ts:705

Parameters ​

orient ​

AxisSet

Returns ​

NeuroSpace


computeAxisPermutation() ​

ts
computeAxisPermutation(oldAxes, newAxes): object;

Defined in: src/geometry/NeuroSpace.ts:773

Parameters ​

oldAxes ​

NamedAxis[]

newAxes ​

NamedAxis[]

Returns ​

object

perm ​
ts
perm: number[];
flip ​
ts
flip: number[];

permuteGridCoordinates() ​

ts
permuteGridCoordinates(coords, axes): number[];

Defined in: src/geometry/NeuroSpace.ts:802

Parameters ​

coords ​

number[]

axes ​

AxisSet

Returns ​

number[]


boundsFromView() ​

ts
boundsFromView(axes): [number[], number[]];

Defined in: src/geometry/NeuroSpace.ts:819

Calculates the bounds of the NeuroSpace with respect to a given set of axes.

Parameters ​

axes ​

AxisSet

The AxisSet defining the desired orientation.

Returns ​

[number[], number[]]

A tuple containing the minimum and maximum coordinates in the local coordinate space.


generateCornerIndices() ​

ts
generateCornerIndices(dims): number[][];

Defined in: src/geometry/NeuroSpace.ts:854

Generates all corner indices for an n-dimensional grid.

Parameters ​

dims ​

number[]

The dimensions of the grid.

Returns ​

number[][]

An array of grid coordinates representing each corner.


transformCoordToAxes() ​

ts
transformCoordToAxes(coord, axes): number[];

Defined in: src/geometry/NeuroSpace.ts:878

Transforms a coordinate from world space to the local coordinate space defined by the given axes.

Parameters ​

coord ​

number[]

The coordinate in world space.

axes ​

AxisSet

The AxisSet defining the desired orientation.

Returns ​

number[]

The coordinate in the local coordinate space.


seqAlong() ​

ts
seqAlong(axis, step): number[];

Defined in: src/geometry/NeuroSpace.ts:929

Generates a sequence of values along a given axis within the space.

Parameters ​

axis ​

NamedAxis

The axis along which to generate the sequence.

step ​

number

The step size between values in the sequence.

Returns ​

number[]

An array of numbers representing the sequence along the axis.

Throws ​

NeuroimError (INVALID_ARGUMENT) if the provided axis doesn't match any axis in the space.


sliceIndices() ​

ts
sliceIndices(axis): number[];

Defined in: src/geometry/NeuroSpace.ts:956

Returns an array of slice indices along a given axis.

Parameters ​

axis ​

NamedAxis

The axis along which to generate slice indices.

Returns ​

number[]

An array of numbers representing the slice indices from 0 to ndom-1.

Throws ​

NeuroimError (INVALID_ARGUMENT) if the provided axis doesn't match any axis in the space.


getOrigin() ​

ts
getOrigin(): number[];

Defined in: src/geometry/NeuroSpace.ts:1012

Returns the origin values.

Returns ​

number[]

An array representing the origin.


getAxes() ​

ts
getAxes(): AxisSet;

Defined in: src/geometry/NeuroSpace.ts:1020

Returns the axes set.

Returns ​

AxisSet

The AxisSet instance.


getTrans() ​

ts
getTrans(): Matrix;

Defined in: src/geometry/NeuroSpace.ts:1028

Returns the transformation matrix.

Returns ​

Matrix

The transformation Matrix.


getInverseTrans() ​

ts
getInverseTrans(): Matrix;

Defined in: src/geometry/NeuroSpace.ts:1036

Returns the inverse transformation matrix.

Returns ​

Matrix

The inverse transformation Matrix.


toString() ​

ts
toString(): string;

Defined in: src/geometry/NeuroSpace.ts:1044

Returns a string representation of the NeuroSpace object.

Returns ​

string

A formatted string containing information about the NeuroSpace.


isEqualTo() ​

ts
isEqualTo(other): boolean;

Defined in: src/geometry/NeuroSpace.ts:1065

Checks if this NeuroSpace object is equal to another NeuroSpace object.

Parameters ​

other ​

NeuroSpace

The other NeuroSpace object to compare with.

Returns ​

boolean

True if the objects are equal, false otherwise.


print() ​

ts
print(): void;

Defined in: src/geometry/NeuroSpace.ts:1072

Logs a string representation of the NeuroSpace object to the console.

Returns ​

void


getTransformationMatrixTo() ​

ts
getTransformationMatrixTo(targetSpace): Matrix;

Defined in: src/geometry/NeuroSpace.ts:1081

Generates a transformation matrix to convert real-world coordinates from this space to another space.

Parameters ​

targetSpace ​

NeuroSpace

The target NeuroSpace to convert coordinates to.

Returns ​

Matrix

A transformation matrix that converts real-world coordinates from this space to the target space.


getPermutationMatrixTo() ​

ts
getPermutationMatrixTo(targetAxes): Matrix;

Defined in: src/geometry/NeuroSpace.ts:1096

Generates a transformation matrix to convert voxel coordinates from this space to another compatible space.

Parameters ​

targetAxes ​

AxisSet

The target NeuroSpace to convert coordinates to.

Returns ​

Matrix

A transformation matrix that converts voxel coordinates from this space to the target space.

Throws ​

NeuroimError (GEOMETRY_MISMATCH) if the spaces are not compatible.


isCompatibleWith() ​

ts
isCompatibleWith(otherSpace): boolean;

Defined in: src/geometry/NeuroSpace.ts:1144

Checks if this space is compatible with another space for transformation.

Parameters ​

otherSpace ​

NeuroSpace

The other NeuroSpace to check compatibility with.

Returns ​

boolean

True if the spaces are compatible, false otherwise.


isCompatibleWithAxes() ​

ts
isCompatibleWithAxes(targetAxes): boolean;

Defined in: src/geometry/NeuroSpace.ts:1160

Parameters ​

targetAxes ​

AxisSet

Returns ​

boolean


toStringDetailed() ​

ts
toStringDetailed(): string;

Defined in: src/geometry/NeuroSpace.ts:1180

Returns a string representation of the NeuroSpace object.

Returns ​

string

A formatted string containing information about the NeuroSpace.


prettyPrint() ​

ts
prettyPrint(): void;

Defined in: src/geometry/NeuroSpace.ts:1200

Prints a well-formatted, colorful representation of the NeuroSpace object to the console. This method enhances debugging by highlighting key properties with colors and proper structure.

Returns ​

void

Released under the MIT License.