Class: NeuroSpace
Defined in: src/geometry/NeuroSpace.ts:16
Constructors
Constructor
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?
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
get dim(): number[];Defined in: src/geometry/NeuroSpace.ts:471
Returns
number[]
origin
Get Signature
get origin(): number[];Defined in: src/geometry/NeuroSpace.ts:475
Returns
number[]
spacing
Get Signature
get spacing(): number[];Defined in: src/geometry/NeuroSpace.ts:485
Gets the spacing values.
Returns
number[]
An array of spacing values.
axes
Get Signature
get axes(): Readonly<AxisSet>;Defined in: src/geometry/NeuroSpace.ts:490
Returns
Readonly<AxisSet>
size
Get Signature
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
get trans(): Matrix;Defined in: src/geometry/NeuroSpace.ts:502
Returns
Matrix
inverseTrans
Get Signature
get inverseTrans(): Matrix;Defined in: src/geometry/NeuroSpace.ts:506
Returns
Matrix
Methods
extractSliceNeuroSpace()
extractSliceNeuroSpace(zlevel, axisToDrop?): NeuroSpace;Defined in: src/geometry/NeuroSpace.ts:206
Parameters
zlevel
number
axisToDrop?
number
Returns
NeuroSpace
dropDim()
dropDim(): NeuroSpace | null;Defined in: src/geometry/NeuroSpace.ts:281
Returns
NeuroSpace | null
ndim()
ndim(): number;Defined in: src/geometry/NeuroSpace.ts:424
Gets the number of dimensions.
Returns
number
The number of dimensions.
centroid()
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()
dimOf(axis): number;Defined in: src/geometry/NeuroSpace.ts:449
Gets the size of a specific dimension based on the axis.
Parameters
axis
The axis for which to get the dimension size.
Returns
number
The size of the dimension.
whichDim()
whichDim(axis): number;Defined in: src/geometry/NeuroSpace.ts:461
Determines which dimension corresponds to the given axis.
Parameters
axis
The axis to match.
Returns
number
The index of the matching dimension.
Throws
NeuroimError (INVALID_ARGUMENT) if no matching axis is found.
withDimensions()
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()
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()
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()
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()
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()
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()
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()
containsCoord(coords): boolean;Defined in: src/geometry/NeuroSpace.ts:613
Parameters
coords
number[]
Returns
boolean
voxelToWorld()
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()
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()
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()
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()
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()
reorient(orient): NeuroSpace;Defined in: src/geometry/NeuroSpace.ts:705
Parameters
orient
Returns
NeuroSpace
computeAxisPermutation()
computeAxisPermutation(oldAxes, newAxes): object;Defined in: src/geometry/NeuroSpace.ts:773
Parameters
oldAxes
newAxes
Returns
object
perm
perm: number[];flip
flip: number[];permuteGridCoordinates()
permuteGridCoordinates(coords, axes): number[];Defined in: src/geometry/NeuroSpace.ts:802
Parameters
coords
number[]
axes
Returns
number[]
boundsFromView()
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
The AxisSet defining the desired orientation.
Returns
[number[], number[]]
A tuple containing the minimum and maximum coordinates in the local coordinate space.
generateCornerIndices()
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()
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
The AxisSet defining the desired orientation.
Returns
number[]
The coordinate in the local coordinate space.
seqAlong()
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
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()
sliceIndices(axis): number[];Defined in: src/geometry/NeuroSpace.ts:956
Returns an array of slice indices along a given axis.
Parameters
axis
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()
getOrigin(): number[];Defined in: src/geometry/NeuroSpace.ts:1012
Returns the origin values.
Returns
number[]
An array representing the origin.
getAxes()
getAxes(): AxisSet;Defined in: src/geometry/NeuroSpace.ts:1020
Returns the axes set.
Returns
The AxisSet instance.
getTrans()
getTrans(): Matrix;Defined in: src/geometry/NeuroSpace.ts:1028
Returns the transformation matrix.
Returns
Matrix
The transformation Matrix.
getInverseTrans()
getInverseTrans(): Matrix;Defined in: src/geometry/NeuroSpace.ts:1036
Returns the inverse transformation matrix.
Returns
Matrix
The inverse transformation Matrix.
toString()
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()
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()
print(): void;Defined in: src/geometry/NeuroSpace.ts:1072
Logs a string representation of the NeuroSpace object to the console.
Returns
void
getTransformationMatrixTo()
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()
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
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()
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()
isCompatibleWithAxes(targetAxes): boolean;Defined in: src/geometry/NeuroSpace.ts:1160
Parameters
targetAxes
Returns
boolean
toStringDetailed()
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()
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