Class FileImageXML


public class FileImageXML extends FileXML
File class for reading/writing Image.XML file headers and their associated images. The XML reader uses the image.xsd schema for parsing. Inherits from FileXML, which parses the image.xml file based on the image.xsd
  • Field Details

    • imageStr

      private static final String[] imageStr
      array of strings representing the tags under in the xml schema.
    • datasetAttributesStr

      private static final String[] datasetAttributesStr
      array of strings representing the tags under invalid input: '<'Dataset-attributes> in the xml schema.
    • subjectInformationStr

      private static final String[] subjectInformationStr
      array of strings representing the tags under invalid input: '<'Subject-information> in the xml schema.
    • scanAttributesStr

      private static final String[] scanAttributesStr
      array of strings representing the tags under invalid input: '<'Scan-attributes> in the xml schema.
    • investigatorsStr

      private static final String[] investigatorsStr
      array of strings representing the tags under in the xml schema.
    • setStr

      private static final String[] setStr
      array of strings representing the tags under in the xml schema.
    • parameterStr

      private static final String[] parameterStr
      array of strings representing the tags under in the xml schema.
    • voiStr

      private static final String[] voiStr
      array of strings representing the tags under in the xml schema.
    • surfaceStr

      private static final String[] surfaceStr
      array of strings representing the tags under in the xml schema.
    • additionalSets

      private Enumeration<XMLPSet> additionalSets
      A listing of all the additional PSets to be written into the saved file.
    • annotationVector

      private Vector<VOI> annotationVector
      DOCUMENT ME!
    • functionIndex

      private int functionIndex
      Index of LUT function when reading xml header.
    • functionVector

      private Vector<WildMagic.LibFoundation.Mathematics.Vector2f> functionVector
      Vector to store the LUT functions when reading xml header.
    • matrixVector

      private Vector<TransMatrix> matrixVector
      Vector to hold matrices while they are being read in for the header (until they are added to the image
    • image

      private ModelImage image
      Model Image associated with the file.
    • imageFileName

      private String imageFileName
      Name of the RAW (or IMG) file associated with the XML header.
    • linkedFilename

      private String linkedFilename
      Name of the file linked to this file (separate from fileName).
    • LUT

      private ModelLUT LUT
      Lookup Table associated with the file (grayscale).
    • lutVector

      private Vector<FileImageXML.LUValue> lutVector
      Vector to store LUT values when reading xml header.
    • modelRGB

      private ModelRGB modelRGB
      RGB lookup table associated with the file.
    • rawExtension

      private String rawExtension
      The extension to give to the RAW file associated with the XML header. May be changed to .img if the XML header links to an Analyze image (and will need to be flipped when the image is read back in).
    • thumbnail

      private FileImageXML.Thumbnail thumbnail
      Thumbnail data and AWT Image.
    • dataFileName

      private String[] dataFileName
    • dtiparams

      private DTIParameters dtiparams
    • numVolumes

      private int numVolumes
    • gradients

      private double[][] gradients
    • bValues

      private double[] bValues
  • Constructor Details

    • FileImageXML

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

    • flipTopBottom

      public static final void flipTopBottom(ModelImage img) throws IOException
      Flips image. Analyze stores its data "upside down". Used if reading in an XML header attached to an .img raw data file.
      Parameters:
      img - Image to flip.
      Throws:
      IOException - if there is a problem importing or exporting the image
    • flipTopBottom

      public static final void flipTopBottom(float[] buffer, FileInfoImageXML xmlInfo)
      Flips image. Analyze stores its data "upside down". Used if reading in an XML header attached to an .img raw data file.
      Parameters:
      buffer - Buffer holding image to flip.
      xmlInfo - File info structure for image to flip.
    • clearAdditionalSets

      public void clearAdditionalSets()
      Convenience method to clear any additional sets of the enumerated list that might be written into the header file.
    • finalize

      public void finalize()
      Prepares class for cleanup.
      Overrides:
      finalize in class FileXML
    • getAdditionalSets

      public Enumeration<XMLPSet> getAdditionalSets()
      Returns the enumerated list of additional sets to be written into the header file.
      Returns:
      the additional parameter sets that will be written out to the header
    • getFileInfo

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

      public ModelLUT getModelLUT()
      Gets the LUT.
      Returns:
      ModelLUT the LUT
    • getModelRGB

      public ModelRGB getModelRGB()
      Gets the modelRGB.
      Returns:
      ModelRGB the modelRGB
    • getThumbnail

      public FileImageXML.Thumbnail getThumbnail()
      Returns the thumbnail associated with the xml file (saved in header).
      Returns:
      Thumbnail
    • getDataFileName

      public String[] getDataFileName()
      Accessor that returns the array of data file names
      Returns:
    • readHeader

      public float[][] readHeader(String headerFileName, String headerDir, TalairachTransformInfo talairach) throws IOException
      Reads and parses an XML header.
      Parameters:
      headerFileName - file name of xml header
      headerDir - directory
      talairach - the talairach transform info to fill out if contained within the header
      Returns:
      double array containing resolutions (for setting resolutions per FileInfoImageXML)
      Throws:
      IOException - DOCUMENT ME!
    • readImage

      public ModelImage readImage(boolean one) throws IOException, OutOfMemoryError
      Reads an XML image file by reading the XML 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.
      Returns:
      The image.
      Throws:
      IOException - if there is an error reading the file
      OutOfMemoryError - if there is a problem allocating memory for the image
      See Also:
    • getFullBuffer

      private byte[] getFullBuffer(InputStream in, byte[] buff, int off, int fullBufferSize)
    • readImage

      public void readImage(float[] buffer) throws IOException, OutOfMemoryError
      Reads an XML image file by reading the header then making a FileRaw to read the file. Image data is left in buffer. If the fileInfo cannot be found, the header will be located and read first.
      Parameters:
      buffer - Image buffer to store image data into. It is equal to the header length.
      Throws:
      IOException - if there is an error reading the file
      OutOfMemoryError - if there was a problem allocating enough memory
      See Also:
    • setAdditionalSets

      public void setAdditionalSets(Enumeration<XMLPSet> moreSets)
      Method to replace the enumerated list of additional sets to be written into the header file. Any existing value is lost.
      Parameters:
      moreSets - additional parameter sets to be written
    • setFileName

      public void setFileName(String fName)
      Accessor to set the file name (used when reading XML multiFile).
      Parameters:
      fName - file name of image to read.
    • setModelLUT

      public void setModelLUT(ModelLUT lut)
      Sets the model LUT.
      Parameters:
      lut - ModelLUT the LUT
    • setModelRGB

      public void setModelRGB(ModelRGB modelRGB)
      Sets the model RGB.
      Parameters:
      modelRGB - ModelRGB the modelRGB
    • setRawExtension

      public void setRawExtension(String ext)
      Changes the extension of the image data file associated with this XML header.
      Parameters:
      ext - the new file extension (such as .img)
    • setThumbnailData

      public void setThumbnailData(int xDim, int yDim, int[] data)
      Sets the thumbnail data (array of shorts).
      Parameters:
      xDim - the buffer length in the x dimension
      yDim - the buffer length in the y dimension
      data - the thumbnail data
    • writeHeader

      public boolean writeHeader(ModelImage img, FileWriteOptions options, String headerName, String headerDir, boolean changeDims) throws IOException
      Writes the XML header information out to the given filename and path.
      Parameters:
      img - image associated with header
      options - the options to use when writing out the file
      headerName - file name to write to
      headerDir - name of directory to write to
      changeDims - if true indicates that the image is changing dimensionality (e.g., 3D to 2D)
      Returns:
      if header write was successful
      Throws:
      IOException - if a file I/O problem is encoutered while writing the header
    • writeImage

      public void writeImage(ModelImage img, FileWriteOptions options) throws IOException
      Writes an XML image with the given options.
      Parameters:
      img - Model image to be written to disk
      options - tells how and where to save file
      Throws:
      IOException - if there is a problem writing to the file
    • getOffset

      private static int getOffset(FileInfoImageXML xmlInfo)
      Helper method to calculate the offset for getting only the middle analyze image slice from the 3D file.
      Parameters:
      xmlInfo - File info.
      Returns:
      offset
    • addFunctionToLUT

      private void addFunctionToLUT()
      Adds the LUT functions collected within the functionVector.
    • addFunctionToRGB

      private void addFunctionToRGB()
      Adds the ModelRGB functions contained within the functionVector.
    • addLUValue

      private void addLUValue(String s)
      Adds LUValue for either LUT or modelRGB.
      Parameters:
      s - String
    • addPointToFunction

      private void addPointToFunction(String s)
      Adds a point to the function associated with the LUT or modelRGB.
      Parameters:
      s - String
    • getFormattedThumbnailLine

      private String getFormattedThumbnailLine(int[] data, int index)
      Returns a String for writing the thumbnail data (r,g,b) to the XML header.
      Parameters:
      data - int[] array of int thumbnail data
      index - int index of thumbnail data (which line)
      Returns:
      String a formatted string containing comma separated thumbnail information
    • setLUT

      private void setLUT()
      Sets up the LUT based on the values read into the lutVector.
    • setRGB

      private void setRGB()
      sets up the model RGB while parsing XML header after all LUValues have been saved in the LUT vector.
    • updateOriginInfo

      private void updateOriginInfo(FileInfoImageXML[] xmlInfo)
      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:
      xmlInfo - the file info to update
    • writeHeader3DTo2D

      private void writeHeader3DTo2D(ModelImage img, String headerName, String headerDir, FileWriteOptions options) throws IOException
      Method to save off the header from a 4D image into 3D 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 img, String headerName, String headerDir, FileWriteOptions options) throws IOException
      Method to save off the header from a 4D image into 3D 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
      Throws:
      IOException - DOCUMENT ME!
    • writeSet

      private void writeSet(BufferedWriter bw, Enumeration<XMLPSet> setEnum)
      writeSet is a helper method, to allow writing set data out to the BufferedWriter with any enumeration.
      Parameters:
      bw - The writer to which we will write the data.
      setEnum - An enumerated list of set data.