Class FileSPM

    • Field Detail

      • DT_UNSIGNED_CHAR

        private static final int DT_UNSIGNED_CHAR
        DOCUMENT ME!
        See Also:
        Constant Field Values
      • DT_UNSIGNED_SHORT

        private static final int DT_UNSIGNED_SHORT
        DOCUMENT ME!
        See Also:
        Constant Field Values
      • bufferByte

        private byte[] bufferByte
        DOCUMENT ME!
      • fileDir

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

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

        private int headerSize
        DOCUMENT ME!
      • headerFileName

        private java.lang.String headerFileName
      • headerFile

        private java.io.File headerFile
        DOCUMENT ME!
      • dataFileName

        private java.lang.String dataFileName
      • dataFile

        private java.io.File dataFile
    • Constructor Detail

      • FileSPM

        public FileSPM​(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
      • isSPM

        public static boolean isSPM​(java.lang.String absolutePath)
                             throws java.io.FileNotFoundException,
                                    java.io.IOException
        Determines whether this file is SPM file or not based on three fields of the header file: sizeof_hdr, extent and regular.
        Parameters:
        absolutePath - the file name.
        Returns:
        true if the file is ANALYZE file.
        Throws:
        java.io.FileNotFoundException - thrown when the file can't be found.
        java.io.IOException - thrown when the I/O error happens.
      • flipTopBottom

        public void flipTopBottom​(ModelImage image)
                           throws java.io.IOException
        Flips image. SPM stores its data "upside down".
        Parameters:
        image - Image to flip.
        Throws:
        java.io.IOException - DOCUMENT ME!
      • flipTopBottom

        public void flipTopBottom​(float[] buffer,
                                  FileInfoSPM fileInfo)
                           throws java.io.IOException
        Flips image. SPM stores its data "upside down".
        Parameters:
        buffer - Buffer holding image to flip.
        fileInfo - File info structure for image to flip.
        Throws:
        java.io.IOException - DOCUMENT ME!
      • getFileInfo

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

        public boolean readHeader()
                           throws java.io.IOException
        DOCUMENT ME!
        Returns:
        true if read successfully
        Throws:
        java.io.IOException - DOCUMENT ME!
      • readImage

        public ModelImage readImage​(boolean one)
                             throws java.io.IOException,
                                    java.lang.OutOfMemoryError
        Reads an SPM 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.
        Returns:
        The image.
        Throws:
        java.io.IOException - if there is an error reading the file
        java.lang.OutOfMemoryError
        See Also:
        FileRaw
      • readImage

        public void readImage​(float[] buffer)
                       throws java.io.IOException,
                              java.lang.OutOfMemoryError
        Reads an SPM 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. Image is not 'flipped', and neither units of measure nor orientation are set.
        Parameters:
        buffer - Image buffer to store image data into.
        Throws:
        java.io.IOException - if there is an error reading the file
        java.lang.OutOfMemoryError
        See Also:
        FileRaw
      • reOrgInfo

        public void reOrgInfo​(ModelImage image,
                              FileInfoSPM fileInfo)
        Takes the image and sets it to SPM defaults, using the specified info.
        Parameters:
        image - Image to set to SPM defaults.
        fileInfo - File info structure to change.
      • writeHeader3DTo2D

        public void writeHeader3DTo2D​(ModelImage image,
                                      java.lang.String fileName,
                                      java.lang.String fileDir,
                                      FileWriteOptions options)
                               throws java.io.IOException
        DOCUMENT ME!
        Parameters:
        image - DOCUMENT ME!
        fileName - DOCUMENT ME!
        fileDir - DOCUMENT ME!
        options - DOCUMENT ME!
        Throws:
        java.io.IOException - DOCUMENT ME!
      • writeHeader4DTo3D

        public void writeHeader4DTo3D​(ModelImage image,
                                      java.lang.String fileName,
                                      java.lang.String fileDir,
                                      FileWriteOptions options)
                               throws java.io.IOException
        DOCUMENT ME!
        Parameters:
        image - DOCUMENT ME!
        fileName - DOCUMENT ME!
        fileDir - DOCUMENT ME!
        options - DOCUMENT ME!
        Throws:
        java.io.IOException - DOCUMENT ME!
      • writeImage

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

        protected void updateUnitsOfMeasure​(FileInfoSPM fileInfo)
        updates the units of Measure in the file info based on the voxUnits from an SPM Header. This version simply updates a single FileInfo. It does not have an image to attach to.
        Parameters:
        fileInfo - -- an SPM file Info that has already been read
      • updateUnitsOfMeasure

        protected void updateUnitsOfMeasure​(FileInfoSPM fileInfo,
                                            ModelImage image)
        updates the units of Measure in the file info based on the voxUnits from an SPM Header.
        Parameters:
        fileInfo - -- an SPM file Info that has already been read
        image - -- a ModelImage that the fileInfo needs to be attached to
      • getOffset

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

        private boolean writeHeader​(ModelImage image,
                                    int nImagesSaved,
                                    int nTimeSaved,
                                    java.lang.String fileName,
                                    java.lang.String fileDir)
                             throws java.io.IOException
        Writes an SPM header to a separate file.
        Parameters:
        image - Image model of data to write.
        fileName - File name.
        fileDir - File directory.
        Returns:
        Flag to confirm a successful read.
        Throws:
        java.io.IOException - if there is an error
        See Also:
        FileInfoSPM