Class FileRaw


  • public class FileRaw
    extends FileBase
    The class reads and writes raw files of all data types: boolean, byte, short, int, long, float, and double. For the read process an offset can be pass as a parameter to identify the location in the file where the data starts. A number of file formats while not "raw" have data at a specific location after a fixed length but unknown header and therefore can be treated as raw.
    Version:
    0.1 Sept 2, 1997
    See Also:
    FileIO, FileInfoXML, FileRawChunk
    • Field Detail

      • compressionType

        private int compressionType
        DOCUMENT ME!
      • file

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

        private java.lang.String fileName
      • nImages

        private int nImages
        DOCUMENT ME!
      • nTimePeriods

        private int nTimePeriods
        DOCUMENT ME!
      • planarConfig

        private int planarConfig
        DOCUMENT ME!
      • YBR_FULL_422

        private boolean YBR_FULL_422
      • startPosition

        private long startPosition
        DOCUMENT ME!
      • numChannels

        private int numChannels
      • RGBAOrder

        private boolean RGBAOrder
        Allow reading from 4 color files with RGBA order
      • zeroLengthFlag

        private boolean zeroLengthFlag
        flag that indicates if raFile should first be set to length of 0
      • dataFileName

        private java.lang.String[] dataFileName
      • minimumBitsMinus1

        private int minimumBitsMinus1
        Used in reading and writing boolean
      • shiftToDivide

        private int shiftToDivide
        Used in reading and writing boolean
      • threeByteInteger

        private boolean threeByteInteger
      • bitsAllocated

        private int bitsAllocated
      • bitsStored

        private int bitsStored
      • highBit

        private int highBit
    • Constructor Detail

      • FileRaw

        public FileRaw​(FileInfoBase fInfo)
        Constructor for Raw Files that will be used to write from 4D to 3D or from 3D to 2D.
        Parameters:
        fInfo - fileinfo
      • FileRaw

        public FileRaw​(java.lang.String fileName,
                       FileInfoBase fInfo,
                       int rwFlag)
                throws java.io.IOException
        Raw reader/writer constructor.
        Parameters:
        fileName - Complete file name
        fInfo - Information that describes the image.
        rwFlag - Read/write flag.
        Throws:
        java.io.IOException - if there is an error making the files
      • FileRaw

        public FileRaw​(java.lang.String fileName,
                       java.lang.String fileDir,
                       FileInfoBase fInfo,
                       int rwFlag)
                throws java.io.IOException
        Raw reader/writer constructor..
        Parameters:
        fileName - File name (no path)
        fileDir - File directory (with trailing file separator).
        fInfo - Information that describes the image.
        showProgressBar - Boolean indicating if progess bar should be displayed.
        rwFlag - Read/write flag.
        Throws:
        java.io.IOException - if there is an error making the files
    • Method Detail

      • close

        public void close()
                   throws java.io.IOException
        Closes random access file associated with this object.
        Throws:
        java.io.IOException - DOCUMENT ME!
      • finalize

        public void finalize()
        Prepares this class for cleanup.
        Overrides:
        finalize in class FileBase
      • setThreeByteInteger

        public void setThreeByteInteger​(boolean threeByteInteger)
      • setBitsAllocated

        public void setBitsAllocated​(int bitsAllocated)
      • setBitsStored

        public void setBitsStored​(int bitsStored)
      • setHighBit

        public void setHighBit​(int highBit)
      • setMinimumBitsMinus1

        public void setMinimumBitsMinus1​(int minimumBitsMinus1)
        Used in reading and writing boolean
        Parameters:
        minimumBitsMinus1 -
      • setShiftToDivide

        public void setShiftToDivide​(int shiftToDivide)
        Used in reading and writing boolean
        Parameters:
        shiftToDivide -
      • setYBR_FULL_422

        public void setYBR_FULL_422​(boolean YBR_FULL_422)
      • getNImages

        public int getNImages()
        Accessor that returns the number of image slices saved.
        Returns:
        The number of images.
      • getNTimePeriods

        public int getNTimePeriods()
        Accessor that returns the number of time periods saved.
        Returns:
        The number of time periods.
      • getDataFileName

        public java.lang.String[] getDataFileName()
        Accessor that returns the array of data file names
        Returns:
      • readImage

        public void readImage​(ModelImage image,
                              long offset)
                       throws java.io.IOException
        This method reads a raw image file (1D - 5D).
        Parameters:
        image - Image model where the data will be stored.
        offset - Points to where the data of the image is located. It is equal to the header length.
        Throws:
        java.io.IOException - if there is an error reading the file
        See Also:
        FileInfoXML, FileRawChunk
      • readFloatImage

        public void readFloatImage​(ModelImage image,
                                   int originalDataType,
                                   float[] scaleFactor,
                                   float[] offsetAdjustment,
                                   long offset)
                            throws java.io.IOException
        This method reads a raw image file (1D - 5D). Then multiplies raw data by a scaleFactor[k] and adds an offsetAdjustment[k], where k is the slice index
        Parameters:
        image - Image model where the data will be stored. Either a ModelStorageBase.FLOAT or a ModelStorageBase.ARGB_FLOAT.
        originalDataType -
        scaleFactor - array with a multiplicative factor for each slice
        offsetAdjustment - array with an additive offset adjustment for each slice
        offset - Points to where the data of the image is located. It is equal to the header length.
        Throws:
        java.io.IOException - if there is an error reading the file
        See Also:
        FileInfoXML, FileRawChunk
      • readImage

        public void readImage​(float[] buffer,
                              long offset,
                              int imageType)
                       throws java.io.IOException
        This method reads a file and puts the data in the buffer.
        Parameters:
        buffer - float buffer where the data will be stored.
        offset - points to where the data of the image is located. It is equal to the header length.
        imageType - ModelImage type (i.e. boolean, byte ...);
        Throws:
        java.io.IOException - if there is an error reading the file
        See Also:
        FileInfoXML, FileRawChunk
      • readImage

        public void readImage​(double[] buffer,
                              long offset)
                       throws java.io.IOException
        This method reads a file and puts the data in the buffer.
        Parameters:
        buffer - double buffer where the data will be stored.
        offset - points to where the data of the image is located. It is equal to the header length.
        Throws:
        java.io.IOException - if there is an error reading the file
        See Also:
        FileInfoXML, FileRawChunk
      • readImage

        public void readImage​(short[] buffer,
                              long offset,
                              int imageType)
                       throws java.io.IOException
        This method reads a file and puts the data in the buffer. Added here to help speed the reading of DICOM images
        Parameters:
        buffer - float buffer where the data will be stored.
        offset - points to where the data of the image is located. It is equal to the header length.
        imageType - ModelImage type (i.e. boolean, byte ...);
        Throws:
        java.io.IOException - if there is an error reading the file
        See Also:
        FileInfoXML, FileRawChunk
      • readImage

        public void readImage​(int[] buffer,
                              long offset,
                              int imageType)
                       throws java.io.IOException
        This method reads a file and puts the data in the buffer. Added here to help speed the reading of DICOM images
        Parameters:
        buffer - float buffer where the data will be stored.
        offset - points to where the data of the image is located. It is equal to the header length.
        imageType - ModelImage type (i.e. boolean, byte ...);
        Throws:
        java.io.IOException - if there is an error reading the file
        See Also:
        FileInfoXML, FileRawChunk
      • setImageFile

        public void setImageFile​(java.lang.String fileName,
                                 java.lang.String fileDir,
                                 FileInfoBase fInfo,
                                 int rwFlag)
                          throws java.io.IOException
        Sets the name and directory to new values opens the file.
        Parameters:
        fileName - DOCUMENT ME!
        fileDir - File directory.
        fInfo - Information that describes the image.
        rwFlag - Read/write flag.
        Throws:
        java.io.IOException - if there is an error making the files
      • setPlanarConfig

        public void setPlanarConfig​(int _planarConfig)
        Sets the planar configuration for RGB images.
        Parameters:
        _planarConfig - 0 indicates pixels are RGB, RGB chunky
        1 indicates pixels are RRR, GGG, BBB planar
      • setNumChannels

        public void setNumChannels​(int numChannels)
        Sets the number of channels used in RGB files
        Parameters:
        numChannels -
      • setRGBAOrder

        public void setRGBAOrder​(boolean RGBAOrder)
      • setStartPosition

        public void setStartPosition​(long startPosition)
        DOCUMENT ME!
        Parameters:
        startPosition - starting byte position for writing data
      • writeImage

        public void writeImage​(ModelImage image,
                               FileWriteOptions options)
                        throws java.io.IOException
        This method writes a raw image file.
        Parameters:
        image - image model where the data is stored.
        options - DOCUMENT ME!
        Throws:
        java.io.IOException - if there is an error writing the file
      • writeImage

        public void writeImage​(ModelImage image,
                               int beginSlice,
                               int endSlice,
                               int beginTimePeriod,
                               int endTimePeriod)
                        throws java.io.IOException
        This method writes a raw image file.
        Parameters:
        image - image model where the data is stored.
        beginSlice -
        endSlice -
        beginTimePeriod -
        endTimePeriod -
        Throws:
        java.io.IOException - if there is an error writing the file
      • writeImage3DTo2D

        public void writeImage3DTo2D​(ModelImage image,
                                     FileWriteOptions options,
                                     java.lang.String suffix)
                              throws java.io.IOException
        Method to save 3D images to an array of 2D images. Images will be name sequentially with the given start # and # of digits
        Parameters:
        image - Image to be saved (broken down into 2D images)
        options - File Write options
        suffix - Suffix for file names. Example: ".xml", ".img"
        Throws:
        java.io.IOException - DOCUMENT ME!
      • writeImage3DTo2D

        public void writeImage3DTo2D​(ModelImage image,
                                     FileWriteOptions options,
                                     java.lang.String suffix,
                                     long[] finalHeaderPosition)
                              throws java.io.IOException
        Method to save 3D images to an array of 2D images. Images will be name sequentially with the given start # and # of digits
        Parameters:
        image - Image to be saved (broken down into 2D images)
        options - File Write options
        suffix - Suffix for file names. Example: ".xml", ".img"
        finalHeaderPosition - starting locations
        Throws:
        java.io.IOException - DOCUMENT ME!
      • writeImage4DTo3D

        public void writeImage4DTo3D​(ModelImage image,
                                     FileWriteOptions options,
                                     java.lang.String suffix)
                              throws java.io.IOException
        Method to write 4D images to an array of 3D image files. the files will be named sequentially with the given # of digits and given starting #. This method will save ALL slices and the files will be split up by time-period
        Parameters:
        image - Image that is to be saved
        options - File write options
        suffix - file suffix for saving name-convention example ".raw", ".img"
        Throws:
        java.io.IOException - DOCUMENT ME!
      • writeImage4DTo3D

        public void writeImage4DTo3D​(ModelImage image,
                                     FileWriteOptions options,
                                     java.lang.String suffix,
                                     long[] finalHeaderPosition)
                              throws java.io.IOException
        Method to write 4D images to an array of 3D image files. the files will be named sequentially with the given # of digits and given starting #. This method will save ALL slices and the files will be split up by time-period
        Parameters:
        image - Image that is to be saved
        options - File write options
        suffix - file suffix for saving name-convention example ".raw", ".img"
        finalHeaderPosition - starting positions
        Throws:
        java.io.IOException - DOCUMENT ME!
      • setZeroLengthFlag

        public void setZeroLengthFlag​(boolean zeroLengthFlag)
        setZeroLengthFlag
        Parameters:
        zeroLengthFlag -