import { PixelFormat, PixelFormatInfo } from './PixelFormat'; import { Vector2D, Vector3D, Section, Box } from './geometry'; import PartialVolumeDescriptor from '@utrad-ical/circus-lib/lib/PartialVolumeDescriptor'; /** * Raw voxel container with MPR support. */ export default class RawData { /** * Number of voxels. */ protected size: Vector3D; /** * Pixel format. */ protected pixelFormat: PixelFormat; /** * Bytes per voxel [byte/voxel] */ protected bpp: number; /** * Actual image data. */ data: ArrayBuffer; /** * The array view used with the array buffer (eg, Uint8Array) */ protected view: { [offset: number]: number; }; /** * Voxel reader function. */ protected read: (pos: number) => number; /** * Voxel writer function. */ protected write: (value: number, pos: number) => void; /** * Set the size of the volume and allocate an byte array. * @param size The number of voxels. * @param pixelFormat The pixel format. */ constructor(size: Vector3D, pixelFormat: PixelFormat); protected partialVolumeDescriptor?: PartialVolumeDescriptor; setPartialVolumeDescriptor(partialVolumeDescriptor: PartialVolumeDescriptor | undefined): void; /** * Gets pixel value at the specified location. Each parameter must be an integer. * @param x x-coordinate * @param y y-coordinate * @param z z-coordinate * @return Corresponding voxel value. */ getPixelAt(x: number, y: number, z: number): number; /** * Write pixel value at the specified location. * @param value Pixel value to write. * @param x x-coordinate * @param y y-coordinate * @param z z-coordinate */ writePixelAt(value: number, x: number, y: number, z: number): void; /** * Get pixel value from nearest neighbor. * @param x x-coordinate (floating point) * @param y y-coordinate (floating point) * @param z z-coordinate (floating point) * @return n Nearest neighbor corresponding voxel value. Returns undefined if out of bounds. */ getPixelNearestNeighbor(x: number, y: number, z: number): number | undefined; /** * Replace the internal data buffer. * @param buffer The data to replace. Must be exactly the same size of the existing buffer. */ assign(buffer: ArrayBuffer): void; /** * Get pixel value from floating-point coordinate * using trilinear interpolation. * @param x x-coordinate (floating point) * @param y y-coordinate (floating point) * @param z z-coordinate (floating point) * @return n Interpolated corresponding voxel value. Returns undefined if out of bounds. */ getPixelWithInterpolation(x: number, y: number, z: number): number | undefined; /** * Do 4-neighbor pixel interpolation within a given single axial slice. * @param xPixelLocation * @param yPixelLocation * @param iz * @return n Interpolated corresponding voxel value. Returns undefined if out of bounds. */ protected getPixelWithBilinearInterpolation(xPixelLocation: [number, number, number, number], yPixelLocation: [number, number, number, number], iz: number): number; private getPixelLocation; /** * Appends and overwrites one slice. * Note that the input data must be in the machine's native byte order * (i.e., little endian in x64 CPUs). * @param z Z coordinate of the image inserted. * @param imageData The inserted image data using the machine's native byte order. */ insertSingleImage(z: number, imageData: ArrayBuffer): void; /** * Gets single image at the given z-coordinate. * @param z z-coordinate * @return The image data */ getSingleImage(z: number): ArrayBuffer; /** * Assigns a correct `read` and `write` methods according to the * current pixel format. */ protected setAccessor(): void; /** * Returns the voxel number of this volume along the three axes. * @return The size of this volume. */ getDimension(): Vector3D; /** * Returns the current pixel format. * @return The current pixel format. */ getPixelFormat(): PixelFormat; /** * Returns the PixelFormatInfo object if no parameter is given. * Returns the corresponding PixelFormatInfo if type is set. * @param type The PixelFormat value. * @return The PixelFormatInfo object, which holds some * helpful information about the pixel format. */ getPixelFormatInfo(type?: PixelFormat): PixelFormatInfo; /** * Calculates the volume data size in bytes. * @return The byte size of the volume. */ readonly dataSize: number; /** * Converts this raw data to new pixel format, optionally using a filter. * @param targetFormat * @param mapper Optional function which is applied to * map the voxel values. */ convert(targetFormat: PixelFormat, mapper: (input: number) => number): void; /** * Fills the entire volume with the specified value. * @param value The value to fill. Can be a function. */ fillAll(value: number | ((x: number, y: number, z: number) => number)): void; /** * Fills the specified cuboid region with the specified value. * @param value The value to fill. Can be a function. * @param box The bounding box in which the volume is filled. */ fillCuboid(value: number | ((x: number, y: number, z: number) => number), box: Box): void; /** * Copies the voxel data from another RawData instance. * @param src The source RawData. * @param srcBox The source bounding box. * If unspecified, copies whole volume. * @param destOffset The point of this instance where * the source is started to be copied. * If unspecified, origin (0, 0, 0) is used. */ copy(src: RawData, srcBox?: Box, offset?: Vector3D): void; /** * Changes the size of this volume by transforming the bounding box. * Used to shrink or expand the existing volume. * Added region will be filled with zero, and * value data not in the newBox will be lost. * @param newBox New bounding box * @param orig The origin of the current bounding box. Defaults to [0, 0, 0]. */ transformBoundingBox(newBox: Box, origin?: Vector3D): void; /** * Applies window level/width. * @param width The window width. * @param level The window level. * @param pixel The input pixel value, typically a Uint16 value. * @return The windowed pixel value between 0 and 255. */ protected applyWindow(width: number, level: number, pixel: number): number; /** * Builds a new MPR image using the given section in index-coordinate. */ scanObliqueSection(section: Section, outSize: Vector2D, outImage: { [index: number]: number; }, interpolation?: boolean, windowWidth?: number, windowLevel?: number): void; /** * Scans over the volume and make an oblique image, * starting from origin and along with the plane defined by eu/ev. * The result is written to `image`. * If windowWidth/Level is given, output image will be an Uint8Array. * Otherwise, the output image must have the same pixel format as the * source volume data. * @param origin The origin point that corresponds to the top-left corner of the output image. * @param eu The scan vector which represents the horizontal one-pixel length of the output image. * @param ev The scan vector which represents the vertical one-pixel length of the output image. * @param outSize Output image size. * @param outImage The output typed array. * @param interpolation Whether to perform trilinear interpolation. * @param windowWidth The window width. * @param windowLevel The window height. */ scanOblique(origin: Vector3D, eu: Vector3D, ev: Vector3D, outSize: Vector2D, outImage: { [index: number]: number; }, interpolation?: boolean, windowWidth?: number, windowLevel?: number): void; }