Class FileNRRD

java.lang.Object
gov.nih.mipav.model.file.FileBase
gov.nih.mipav.model.file.FileNRRD

public class FileNRRD extends FileBase
See Also:
  • Field Details

    • UNKNOWN

      private static final int UNKNOWN
      DOCUMENT ME!
      See Also:
    • 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:
    • LPST

      private static final int LPST
      Like LPS, but with time along the fourth axis.
      See Also:
    • 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:
    • SCANNER_XYZ_TIME

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

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

      private static final int THREED_LEFT_HANDED
      Any left-handed three-dimensional space.
      See Also:
    • 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:
    • 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:
    • 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:
    • CELL

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

      private static final int NODE
      The location of the sample is at the boundary between grid elements.
      See Also:
    • 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 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 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 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 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 String ext
      DOCUMENT ME!
    • file

      private File file
      DOCUMENT ME!
    • fileDir

      private String fileDir
      DOCUMENT ME!
    • fileInfo

      private FileInfoNRRD fileInfo
      DOCUMENT ME!
    • fileInfoSub

      private FileInfoNRRD fileInfoSub
      DOCUMENT ME!
    • fileLength

      private long fileLength
      DOCUMENT ME!
    • fileName

      private String fileName
      DOCUMENT ME!
    • fileNameSequence

      private boolean fileNameSequence
      DOCUMENT ME!
    • fileNameSet

      private 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.
    • image

      private ModelImage image
      DOCUMENT ME!
    • imgExtents

      private int[] imgExtents
      DOCUMENT ME!
    • kindsString

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

      private TransMatrix matrix
      DOCUMENT ME!
    • 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 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 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 String[] nrrdSpaceUnits
      DOCUMENT ME!
    • nrrdUnits

      private 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 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:
  • Constructor Details

    • FileNRRD

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

    • 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(String imageFileName, String fileDir) throws 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:
      IOException - if there is an error reading the header
      See Also:
    • readImage

      public ModelImage readImage(boolean one, boolean doHeader) throws IOException, 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:
      IOException - if there is an error reading the file
      OutOfMemoryError
      See Also:
    • 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 String readLine() throws 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:
      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, String fhName, String fDir, int beginSlice, int endSlice, int beginTime, int endTime) throws IOException
      write NRRD header
      Returns:
      Throws:
      IOException
    • writeImage

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

      private void writeHeader3DTo2D(ModelImage img, String headerName, String headerDir, FileWriteOptions options) throws 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:
      IOException - DOCUMENT ME!
    • writeHeader4DTo3D

      private void writeHeader4DTo3D(ModelImage image, String fileName, String fileDir, FileWriteOptions options) throws 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:
      IOException - DOCUMENT ME!