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 Detail

      • imageStr

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

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

        private static final java.lang.String[] subjectInformationStr
        array of strings representing the tags under in the xml schema.
      • scanAttributesStr

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

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

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

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

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

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

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

        private java.util.Vector<VOI> annotationVector
        DOCUMENT ME!
      • functionIndex

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

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

        private java.util.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 java.lang.String imageFileName
        Name of the RAW (or IMG) file associated with the XML header.
      • linkedFilename

        private java.lang.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 java.util.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 java.lang.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).
      • dataFileName

        private java.lang.String[] dataFileName
      • numVolumes

        private int numVolumes
      • gradients

        private double[][] gradients
      • bValues

        private double[] bValues
    • Constructor Detail

      • FileImageXML

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

      • flipTopBottom

        public static final void flipTopBottom​(ModelImage img)
                                        throws java.io.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:
        java.io.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 java.util.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 java.lang.String[] getDataFileName()
        Accessor that returns the array of data file names
        Returns:
      • readHeader

        public float[][] readHeader​(java.lang.String headerFileName,
                                    java.lang.String headerDir,
                                    TalairachTransformInfo talairach)
                             throws java.io.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:
        java.io.IOException - DOCUMENT ME!
      • readImage

        public ModelImage readImage​(boolean one)
                             throws java.io.IOException,
                                    java.lang.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:
        java.io.IOException - if there is an error reading the file
        java.lang.OutOfMemoryError - if there is a problem allocating memory for the image
        See Also:
        FileRaw
      • getFullBuffer

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

        public void readImage​(float[] buffer)
                       throws java.io.IOException,
                              java.lang.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:
        java.io.IOException - if there is an error reading the file
        java.lang.OutOfMemoryError - if there was a problem allocating enough memory
        See Also:
        FileRaw
      • setAdditionalSets

        public void setAdditionalSets​(java.util.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​(java.lang.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​(java.lang.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,
                                   java.lang.String headerName,
                                   java.lang.String headerDir,
                                   boolean changeDims)
                            throws java.io.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:
        java.io.IOException - if a file I/O problem is encoutered while writing the header
      • writeImage

        public void writeImage​(ModelImage img,
                               FileWriteOptions options)
                        throws java.io.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:
        java.io.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​(java.lang.String s)
        Adds LUValue for either LUT or modelRGB.
        Parameters:
        s - String
      • addPointToFunction

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

        private java.lang.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,
                                       java.lang.String headerName,
                                       java.lang.String headerDir,
                                       FileWriteOptions options)
                                throws java.io.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:
        java.io.IOException - DOCUMENT ME!
      • writeHeader4DTo3D

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

        private void writeSet​(java.io.BufferedWriter bw,
                              java.util.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.