Class FileNRRD

    • Field Detail

      • LPS

        private static final int LPS
        A patient-based right-handed coordinate frame, with ordered basis vectors pointing towards left, posterior, and superior, respectively. Used in DICOM.
        See Also:
        Constant Field Values
      • LPST

        private static final int LPST
        Like LPS, but with time along the fourth axis.
        See Also:
        Constant Field Values
      • SCANNER_XYZ

        private static final int SCANNER_XYZ
        A scanner-based right-handed coordinate frame, used in ACR/NEMA 2.0. If a patient lies parallel to the ground, face-up on the table, with their feet-to-head direction same as the front-to-back direction of the imaging equipment, the axes of this scanner-based coordinate frame and the (patient-based) left-posterior-superior frame coincide.
        See Also:
        Constant Field Values
      • SCANNER_XYZ_TIME

        private static final int SCANNER_XYZ_TIME
        Like SCANNER_XYZ, but with time along the fourth axis.
        See Also:
        Constant Field Values
      • THREED_RIGHT_HANDED

        private static final int THREED_RIGHT_HANDED
        Any right-handed three-dimensional space.
        See Also:
        Constant Field Values
      • THREED_LEFT_HANDED

        private static final int THREED_LEFT_HANDED
        Any left-handed three-dimensional space.
        See Also:
        Constant Field Values
      • THREED_RIGHT_HANDED_TIME

        private static final int THREED_RIGHT_HANDED_TIME
        Like THREED_RIGHT_HANDED, but with time along the fourth axis.
        See Also:
        Constant Field Values
      • THREED_LEFT_HANDED_TIME

        private static final int THREED_LEFT_HANDED_TIME
        Like THREEE_LEFT_HANDED, but with time along the fourth axis.
        See Also:
        Constant Field Values
      • NONE

        private static final int NONE
        Centering information for this axis is either meaningless or unknown. This applies to any non-spatial axis.
        See Also:
        Constant Field Values
      • CELL

        private static final int CELL
        The location of the sample is located in the interior of the grid element.
        See Also:
        Constant Field Values
      • NODE

        private static final int NODE
        The location of the sample is at the boundary between grid elements.
        See Also:
        Constant Field Values
      • apInvert

        private boolean apInvert
        True for RAS and LAS, false for LPS. If true, change sign on origin[1] and row[1] of matrix.
      • autoSequence

        private boolean autoSequence
        True if data file: [] encountered If true, autosequence using integer format specification varied according to , , and .
      • axisMaxs

        private double[] axisMaxs
        Maximum axis value. centers[i], axisMins[i], axisMaxs[i], and nrrdSizes[i] are used to calculate resols[i] and origin[i] if spacings[i] not available.
      • axisMins

        private double[] axisMins
        Minimum axis value. centers[i], axisMins[i], axisMaxs[i], and nrrdSizes[i] are used to calculate resols[i] and origin[i] if spacings[i] not available.
      • axisOrientation

        private int[] axisOrientation
        For each axis R2L, L2R, A2P, P2A, I2S, or S2I
      • baseAfterNumber

        private java.lang.String baseAfterNumber
        In autosequencing number between a capital D and the last period used in generating filenames. The capital D must come after the percentage sign.
      • baseBeforeNumber

        private java.lang.String baseBeforeNumber
        In autosequencing number before percentage sign and period used in generating start of autosequenced filename.
      • baseNumber

        private boolean baseNumber
        Used if autosequencing. If true, increment file base. If false, increment file extension. True if period follows a capital D. The capital D must follow a percentage sign.
      • centers

        private int[] centers
        May remain null or may be created as NONE, CELL, or NODE.
      • dwmriGradient

        private java.lang.String[][] dwmriGradient
        "modality:=DWMRI" : This key/value pair explicitly indicates that the image is a diffusion-weighted MRI scan, and it implies that all of the following key/value pairs are also set in the header: "DWMRI_b-value:=b " : This key/value pair gives the (scalar) diffusion-weighting value, in units of s/mm^2. Example: "DWMRI_b-value:=1000". The effective magnitude of diffusion-weighting for each DWI is determined with some simple calculations based on the individual per-DWI gradient directions or B-matrices. For every index position NNNN along the DWI axis (whichever is the non-spatial axis identified by the "list" or "vector" kind field), either "DWMRI_gradient_NNNN:=x y z " or "DWMRI_B-matrix_NNNN:=xx xy xz yy yz zz " must be given (except if "DWMRI_NEX_NNNN:= M " is used).
      • dwmriNex

        private java.lang.String[][] dwmriNex
        "DWMRI_NEX_NNNN:=M " means that the information provided for image NNNN (either gradient or B-matrix) is the same as for image NNNN+1, NNNN+2, up to and including NNNN+M-1.
      • endianess

        private boolean endianess
        DOCUMENT ME!
      • ext

        private java.lang.String ext
        DOCUMENT ME!
      • file

        private java.io.File file
        DOCUMENT ME!
      • fileDir

        private java.lang.String fileDir
        DOCUMENT ME!
      • fileInfoSub

        private FileInfoNRRD fileInfoSub
        DOCUMENT ME!
      • fileLength

        private long fileLength
        DOCUMENT ME!
      • fileName

        private java.lang.String fileName
        DOCUMENT ME!
      • fileNameSequence

        private boolean fileNameSequence
        DOCUMENT ME!
      • fileNameSet

        private java.lang.String[] fileNameSet
        DOCUMENT ME!
      • fileNumber

        private int fileNumber
        DOCUMENT ME!
      • finishBlank

        private int[] finishBlank
        DOCUMENT ME!
      • finishQuote

        private int[] finishQuote
        DOCUMENT ME!
      • foundEOF

        private boolean foundEOF
        DOCUMENT ME!
      • foundEOHeader

        private boolean foundEOHeader
        DOCUMENT ME!
      • gunzip

        private boolean gunzip
        If true, data has gzip compression.
      • imgExtents

        private int[] imgExtents
        DOCUMENT ME!
      • kindsString

        private java.lang.String[] kindsString
        Kind of information represented by the samples along each axis.
      • measurementFrame

        private double[][] measurementFrame
        The measurement frame is a basic (per-array) field specification (not per-axis), which identifies a spaceDim-by-spaceDim matrix, where spaceDim is the dimension of the word space (implied by space or given by space dimension). The matrix transforms (a column vector of) coordinates in the measurement frame to corrdinates in world space. vector[i] gives column i of the measurement frame matrix. Just as the space directions field gives, one column at a time, the mapping from image space to world space coordinates, the measurement frame gives the mapping measurement frame to world space coordinates, also one column at a time.
      • mipavDataType

        private int mipavDataType
        DOCUMENT ME!
      • mipavDimensions

        private int mipavDimensions
        DOCUMENT ME!
      • mipavLabels

        private java.lang.String[] mipavLabels
        MIPAV axis names such as X, Y, or Z
      • mipavUnits

        private int[] mipavUnits
        DOCUMENT ME!
      • nrrdDataType

        private int nrrdDataType
        Does not tell if color or black and white.
      • nrrdDimensions

        private int nrrdDimensions
        May not be the same as MIPAV dimensions because in nrrd color is a dimension.
      • nrrdLabels

        private java.lang.String[] nrrdLabels
        nrrd axis names such as X, Y, or Z
      • nrrdSizes

        private int[] nrrdSizes
        The number of samples along each nrrd axis
      • nrrdSpaceUnits

        private java.lang.String[] nrrdSpaceUnits
        DOCUMENT ME!
      • nrrdUnits

        private java.lang.String[] nrrdUnits
        Units of measurement of nrrd axis
      • numColors

        private int numColors
        DOCUMENT ME!
      • numSpaceKinds

        private int numSpaceKinds
        Number of nrrd dimensions for which the kinds string equals "SPACE".
      • numThicknesses

        private int numThicknesses
        Number of axes for which thicknesses values found
      • offset1

        private long offset1
        DOCUMENT ME!
      • oneFileStorage

        private boolean oneFileStorage
        True for .nrrd file with header and data in the same file. False for .nhdr header files with the data in one or more other files.
      • origin

        private float[] origin
        DOCUMENT ME!
      • paddingNumber

        private int paddingNumber
        In autosequencing if the sequence number length is less than the padding number, zeroes are added to the front of the sequence number until the sequence number length equals the padding number.
      • planarConfig

        private int planarConfig
        0 indicates pixels are RGB, RGB chunky 1 indicates pixels are RRR, GGG, BBB planar.
      • reorder

        private boolean reorder
        The orientation information in some NRRD files cannot be applied to MIPAV without dimension reordering. This applies to 2 of my 15 example NRRD files. In Dwi-D.nhdr 4 dimensions are specified with the dimensions from 0 to 3 having sizes of 13, 29, 30, and 31. Right-anterior-superior space is specified, but the first axis contains diffusion values and the last 3 axes are the x, y, and z coordinates, so the right-anterior-space applies to the last 3 dimensions, whereas MIPAV would expect the first 3 dimensions to be involved. In gk2-rcc-mask2.nhdr 4 dimensions are specified with the dimensions from 0 to 3 having sizes of 7, 148, 190, and 160. Left-posterior-space is specified, but the first axis contains diffusion values and the last 3 axes are x, y, and z coordinates, so again the space applies to the last 3 dimensions rather than MIPAV's first 3 dimensions. In these cases reorder the data so that the first axis becomes the last axis.
      • resols

        private float[] resols
        DOCUMENT ME!
      • RGBAOrder

        private boolean RGBAOrder
        If true, data is a specialized form of 4-color with red, green, blue, and alpha, in that order.
      • rlInvert

        private boolean rlInvert
        True for RAS. False for LAS and LPS. If true, change sign on origin[0] and first row of matrix.
      • sequenceFinish

        private int sequenceFinish
        DOCUMENT ME!
      • sequenceStart

        private int sequenceStart
        DOCUMENT ME!
      • sequenceStep

        private int sequenceStep
        DOCUMENT ME!
      • skippedBytes

        private int skippedBytes
        Number of bytes to skip
      • skippedLines

        private int skippedLines
        Number of lines to skip
      • sliceThickness

        private float sliceThickness
        DOCUMENT ME!
      • space

        private int space
        RAS, LAS, LPS, RAST, LAST, LPST, SCANNER_XYZ, SCANNER_XYZ_TIME, THREED_RIGHT_HANDED, THREED_LEFT_HANDED, THREED_RIGHT_HANDED_TIME, or THREED_LEFT_HANDED_TIME
      • spaceDirections

        private double[][] spaceDirections
        Second index of spaceDirections specifies row of matrix to set.
      • spaceOrigin

        private double[] spaceOrigin
        Used to set origin values.
      • spaceUnitsString

        private java.lang.String spaceUnitsString
        DOCUMENT ME!
      • spacings

        private double[] spacings
        Resolutions values for nrrd axes
      • startBlank

        private int[] startBlank
        DOCUMENT ME!
      • startQuote

        private int[] startQuote
        DOCUMENT ME!
      • subdim

        private int subdim
        DOCUMENT ME!
      • thicknesses

        private double[] thicknesses
        Used to obtain MIPAV sliceThickness value
      • versionNumber

        private float versionNumber
        Version of the NRRD file format being used.
      • oneFile

        private boolean oneFile
        If true, header and data both stored in .nrrd file. If false, header stored in filename.nhdr and data stored in filename.raw.
      • writeVersionNumber

        private static final int writeVersionNumber
        version number of NRRD for writing
        See Also:
        Constant Field Values
    • Constructor Detail

      • FileNRRD

        public FileNRRD​(java.lang.String fName,
                        java.lang.String fDir)
        Constructs new file object.
        Parameters:
        fName - File name.
        fDir - File directory.
    • Method Detail

      • finalize

        public void finalize()
        Prepares this class for cleanup. Calls the finalize method for existing elements, closes any open files and sets other elements to null.
        Overrides:
        finalize in class FileBase
      • getFileInfo

        public FileInfoNRRD getFileInfo()
        Returns the FileInfoNRRD read from the file.
        Returns:
        File info read from file, or null if it has not been read.
      • readHeader

        public boolean readHeader​(java.lang.String imageFileName,
                                  java.lang.String fileDir)
                           throws java.io.IOException
        Reads the NRRD header and stores the information in fileInfo.
        Parameters:
        imageFileName - File name of image.
        fileDir - Directory.
        Returns:
        Flag to confirm a successful read.
        Throws:
        java.io.IOException - if there is an error reading the header
        See Also:
        FileInfoNRRD
      • readImage

        public ModelImage readImage​(boolean one,
                                    boolean doHeader)
                             throws java.io.IOException,
                                    java.lang.OutOfMemoryError
        Reads a NRRD image file by reading the header then making a FileRaw to read the image for all filenames in the file list. Only the one file directory (currently) supported.
        Parameters:
        one - flag indicating one image of a 3D dataset should be read in.
        doHeader -
        Returns:
        The image.
        Throws:
        java.io.IOException - if there is an error reading the file
        java.lang.OutOfMemoryError
        See Also:
        FileRaw
      • getAxisOrientation

        private int[] getAxisOrientation​(TransMatrix mat)
        Return the 3 axis orientation codes that correspond to the closest standard anatomical orientation of the (i,j,k) axes.
        Parameters:
        mat - 4x4 matrix that transforms (i,j,k) indexes to x,y,z coordinates where +x =Left, +y = Posterior, +z = Superior Only the upper-left 3x3 corner of the matrix is used This routine finds the permutation of (x,y,z) which has the smallest angle to the (i,j,k) axes directions, which are columns of the input matrix Errors: The codes returned will be zero.
        Returns:
        codes
      • getOffset

        private int getOffset​(FileInfoNRRD fileInfo)
        Helper method to calculate the offset for getting only the middle NRRD image slice from the 3D file.
        Parameters:
        fileInfo - File info.
        Returns:
        offset
      • readLine

        private java.lang.String readLine()
                                   throws java.io.IOException
        Reads lines of the file and strips comments indicated by the # symbol until a nonnull String results or the end of the file is reached or a blank line containing end of header with zero characters is reached.
        Returns:
        the line read in
        Throws:
        java.io.IOException - if there is an error reading the file
      • setFileInfo

        public void setFileInfo​(FileInfoNRRD fileInfo)
        Parameters:
        fileInfo -
      • setFileInfo

        private void setFileInfo​(FileInfoNRRD fileInfo,
                                 ModelImage image)
        DOCUMENT ME!
        Parameters:
        fileInfo - -- a NRRD file Info that has already been read
        image - -- a ModelImage that the fileInfo needs to be attached to
      • updateorigins

        private void updateorigins​(FileInfoBase[] fileInfo)
        Updates the start locations. Each image has a fileinfo where the start locations are stored. Note that the start location for the Z (3rd) dimension change with the change is the slice. The origin is in the upper left corner and we are using the right hand rule. + x -> left to right; + y -> top to bottom and + z -> into screen.
        Parameters:
        fileInfo - DOCUMENT ME!
      • writeHeader

        private boolean writeHeader​(ModelImage image,
                                    java.lang.String fhName,
                                    java.lang.String fDir,
                                    int beginSlice,
                                    int endSlice,
                                    int beginTime,
                                    int endTime)
                             throws java.io.IOException
        write NRRD header
        Returns:
        Throws:
        java.io.IOException
      • writeImage

        public void writeImage​(ModelImage image,
                               FileWriteOptions options)
                        throws java.io.IOException
        Writes a NRRD format type image.
        Parameters:
        image - Image model of data to write.
        options - FileWriteOptions
        Throws:
        java.io.IOException - if there is an error writing the file
      • writeHeader3DTo2D

        private void writeHeader3DTo2D​(ModelImage img,
                                       java.lang.String headerName,
                                       java.lang.String headerDir,
                                       FileWriteOptions options)
                                throws java.io.IOException
        Method to save off the header from a 3D image into 2D header files sequentially named (similar to the method in FileRaw).
        Parameters:
        img - Image to be saved
        headerName - Name of file
        headerDir - Directory for file
        options - File write options (contains # of digits and start #)
        Throws:
        java.io.IOException - DOCUMENT ME!
      • writeHeader4DTo3D

        private void writeHeader4DTo3D​(ModelImage image,
                                       java.lang.String fileName,
                                       java.lang.String fileDir,
                                       FileWriteOptions options)
                                throws java.io.IOException
        This method is used when saving a 4D image in an array of 3D files. The file name has numbers appended to correctly order the images.
        Parameters:
        image - the image dataset to be saved
        fileName - the file name
        fileDir - the file directory
        options - file options indicate how to save the image
        Throws:
        java.io.IOException - DOCUMENT ME!