Class: NeuroSpace
Defined in: src/geometry/NeuroSpace.ts:15
Constructors
Constructor
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?
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
get dim(): number[];Defined in: src/geometry/NeuroSpace.ts:428
Returns
number[]
origin
Get Signature
get origin(): number[];Defined in: src/geometry/NeuroSpace.ts:432
Returns
number[]
spacing
Get Signature
get spacing(): number[];Defined in: src/geometry/NeuroSpace.ts:442
Gets the spacing values.
Returns
number[]
An array of spacing values.
axes
Get Signature
get axes(): Readonly<AxisSet>;Defined in: src/geometry/NeuroSpace.ts:447
Returns
Readonly<AxisSet>
size
Get Signature
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
get trans(): Matrix;Defined in: src/geometry/NeuroSpace.ts:459
Returns
Matrix
inverseTrans
Get Signature
get inverseTrans(): Matrix;Defined in: src/geometry/NeuroSpace.ts:463
Returns
Matrix
Methods
extractSliceNeuroSpace()
extractSliceNeuroSpace(zlevel, axisToDrop?): NeuroSpace;Defined in: src/geometry/NeuroSpace.ts:163
Parameters
zlevel
number
axisToDrop?
number
Returns
NeuroSpace
dropDim()
dropDim(): NeuroSpace | null;Defined in: src/geometry/NeuroSpace.ts:238
Returns
NeuroSpace | null
ndim()
ndim(): number;Defined in: src/geometry/NeuroSpace.ts:381
Gets the number of dimensions.
Returns
number
The number of dimensions.
centroid()
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()
dimOf(axis): number;Defined in: src/geometry/NeuroSpace.ts:406
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:418
Determines which dimension corresponds to the given axis.
Parameters
axis
The axis to match.
Returns
number
The index of the matching dimension.
Throws
Error if no matching axis is found.
bounds()
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()
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()
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()
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()
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()
containsCoord(coords): boolean;Defined in: src/geometry/NeuroSpace.ts:524
Parameters
coords
number[]
Returns
boolean
voxelToWorld()
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()
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()
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()
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()
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()
reorient(orient): NeuroSpace;Defined in: src/geometry/NeuroSpace.ts:599
Parameters
orient
Returns
NeuroSpace
computeAxisPermutation()
computeAxisPermutation(oldAxes, newAxes): object;Defined in: src/geometry/NeuroSpace.ts:662
Parameters
oldAxes
newAxes
Returns
object
perm
perm: number[];flip
flip: number[];permuteGridCoordinates()
permuteGridCoordinates(coords, axes): number[];Defined in: src/geometry/NeuroSpace.ts:691
Parameters
coords
number[]
axes
Returns
number[]
boundsFromView()
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
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: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()
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
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:818
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
Error if the provided axis doesn't match any axis in the space.
sliceIndices()
sliceIndices(axis): number[];Defined in: src/geometry/NeuroSpace.ts:845
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
Error if the provided axis doesn't match any axis in the space.
getOrigin()
getOrigin(): number[];Defined in: src/geometry/NeuroSpace.ts:901
Returns the origin values.
Returns
number[]
An array representing the origin.
getAxes()
getAxes(): AxisSet;Defined in: src/geometry/NeuroSpace.ts:909
Returns the axes set.
Returns
The AxisSet instance.
getTrans()
getTrans(): Matrix;Defined in: src/geometry/NeuroSpace.ts:917
Returns the transformation matrix.
Returns
Matrix
The transformation Matrix.
getInverseTrans()
getInverseTrans(): Matrix;Defined in: src/geometry/NeuroSpace.ts:925
Returns the inverse transformation matrix.
Returns
Matrix
The inverse transformation Matrix.
toString()
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()
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()
print(): void;Defined in: src/geometry/NeuroSpace.ts:961
Logs a string representation of the NeuroSpace object to the console.
Returns
void
getTransformationMatrixTo()
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()
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
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()
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()
isCompatibleWithAxes(targetAxes): boolean;Defined in: src/geometry/NeuroSpace.ts:1049
Parameters
targetAxes
Returns
boolean
toStringDetailed()
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()
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