Skip to content

Class: NeuroSpace

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

Constructors

Constructor

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

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

Constructs a new NeuroSpace instance.

Parameters

dim

number[]

An array representing the dimensions of the space.

spacing?

number[]

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

origin?

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?

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:428

Returns

number[]


origin

Get Signature

ts
get origin(): number[];

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

Returns

number[]


spacing

Get Signature

ts
get spacing(): number[];

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

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:447

Returns

Readonly<AxisSet>


size

Get Signature

ts
get size(): number;

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

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:459

Returns

Matrix


inverseTrans

Get Signature

ts
get inverseTrans(): Matrix;

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

Returns

Matrix

Methods

extractSliceNeuroSpace()

ts
extractSliceNeuroSpace(zlevel, axisToDrop?): NeuroSpace;

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

Parameters

zlevel

number

axisToDrop?

number

Returns

NeuroSpace


dropDim()

ts
dropDim(): NeuroSpace | null;

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

Returns

NeuroSpace | null


ndim()

ts
ndim(): number;

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

Gets the number of dimensions.

Returns

number

The number of dimensions.


centroid()

ts
centroid(): number[];

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

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:406

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:418

Determines which dimension corresponds to the given axis.

Parameters

axis

NamedAxis

The axis to match.

Returns

number

The index of the matching dimension.

Throws

Error if no matching axis is found.


bounds()

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

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

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:487

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:496

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:509

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:519

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:524

Parameters

coords

number[]

Returns

boolean


voxelToWorld()

ts
voxelToWorld(voxel): number[];

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

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:545

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:554

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:577

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:594

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:599

Parameters

orient

AxisSet

Returns

NeuroSpace


computeAxisPermutation()

ts
computeAxisPermutation(oldAxes, newAxes): object;

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

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:691

Parameters

coords

number[]

axes

AxisSet

Returns

number[]


boundsFromView()

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

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

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:743

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:767

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:818

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

Error if the provided axis doesn't match any axis in the space.


sliceIndices()

ts
sliceIndices(axis): number[];

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

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

Error if the provided axis doesn't match any axis in the space.


getOrigin()

ts
getOrigin(): number[];

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

Returns the origin values.

Returns

number[]

An array representing the origin.


getAxes()

ts
getAxes(): AxisSet;

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

Returns the axes set.

Returns

AxisSet

The AxisSet instance.


getTrans()

ts
getTrans(): Matrix;

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

Returns the transformation matrix.

Returns

Matrix

The transformation Matrix.


getInverseTrans()

ts
getInverseTrans(): Matrix;

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

Returns the inverse transformation matrix.

Returns

Matrix

The inverse transformation Matrix.


toString()

ts
toString(): string;

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

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:954

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:961

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

Returns

void


getTransformationMatrixTo()

ts
getTransformationMatrixTo(targetSpace): Matrix;

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

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:985

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

Error if the spaces are not compatible.


isCompatibleWith()

ts
isCompatibleWith(otherSpace): boolean;

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

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:1049

Parameters

targetAxes

AxisSet

Returns

boolean


toStringDetailed()

ts
toStringDetailed(): string;

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

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:1089

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.