Class FileSPM

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

public class FileSPM extends FileBase
The class reads and writes SPM files.
See Also:
  • Field Details

    • DT_NONE

      private static final int DT_NONE
      DOCUMENT ME!
      See Also:
    • DT_BINARY

      private static final int DT_BINARY
      DOCUMENT ME!
      See Also:
    • DT_BYTE

      private static final int DT_BYTE
      DOCUMENT ME!
      See Also:
    • DT_UNSIGNED_CHAR

      private static final int DT_UNSIGNED_CHAR
      DOCUMENT ME!
      See Also:
    • DT_SIGNED_SHORT

      private static final int DT_SIGNED_SHORT
      DOCUMENT ME!
      See Also:
    • DT_UNSIGNED_SHORT

      private static final int DT_UNSIGNED_SHORT
      DOCUMENT ME!
      See Also:
    • DT_SIGNED_INT

      private static final int DT_SIGNED_INT
      DOCUMENT ME!
      See Also:
    • DT_UNSIGNED_INT

      private static final int DT_UNSIGNED_INT
      DOCUMENT ME!
      See Also:
    • DT_FLOAT

      private static final int DT_FLOAT
      DOCUMENT ME!
      See Also:
    • DT_COMPLEX

      private static final int DT_COMPLEX
      DOCUMENT ME!
      See Also:
    • DT_DOUBLE

      private static final int DT_DOUBLE
      DOCUMENT ME!
      See Also:
    • DT_RGB

      private static final int DT_RGB
      DOCUMENT ME!
      See Also:
    • bufferByte

      private byte[] bufferByte
      DOCUMENT ME!
    • fileDir

      private String fileDir
      DOCUMENT ME!
    • fileInfo

      private FileInfoSPM fileInfo
      DOCUMENT ME!
    • fileName

      private String fileName
      DOCUMENT ME!
    • headerSize

      private int headerSize
      DOCUMENT ME!
    • image

      private ModelImage image
      DOCUMENT ME!
    • headerFileName

      private String headerFileName
    • headerFile

      private File headerFile
      DOCUMENT ME!
    • dataFileName

      private String dataFileName
    • dataFile

      private File dataFile
  • Constructor Details

    • FileSPM

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

      public static boolean isSPM(String absolutePath) throws FileNotFoundException, 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:
      FileNotFoundException - thrown when the file can't be found.
      IOException - thrown when the I/O error happens.
    • flipTopBottom

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

      public void flipTopBottom(float[] buffer, FileInfoSPM fileInfo) throws 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:
      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 IOException
      DOCUMENT ME!
      Returns:
      true if read successfully
      Throws:
      IOException - DOCUMENT ME!
    • readImage

      public ModelImage readImage(boolean one) throws IOException, 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:
      IOException - if there is an error reading the file
      OutOfMemoryError
      See Also:
    • readImage

      public void readImage(float[] buffer) throws IOException, 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:
      IOException - if there is an error reading the file
      OutOfMemoryError
      See Also:
    • 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, String fileName, String fileDir, FileWriteOptions options) throws IOException
      DOCUMENT ME!
      Parameters:
      image - DOCUMENT ME!
      fileName - DOCUMENT ME!
      fileDir - DOCUMENT ME!
      options - DOCUMENT ME!
      Throws:
      IOException - DOCUMENT ME!
    • writeHeader4DTo3D

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

      public void writeImage(ModelImage image, FileWriteOptions options) throws IOException
      Writes an SPM format type image.
      Parameters:
      image - Image model of data to write.
      Throws:
      IOException - if there is an error writing the file
      See Also:
    • 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, String fileName, String fileDir) throws 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:
      IOException - if there is an error
      See Also: