Package gov.nih.mipav.model.file
Class FileSPM
java.lang.Object
gov.nih.mipav.model.file.FileBase
gov.nih.mipav.model.file.FileSPM
The class reads and writes SPM files.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate byte[]DOCUMENT ME!private Fileprivate Stringprivate static final intDOCUMENT ME!private static final intDOCUMENT ME!private static final intDOCUMENT ME!private static final intDOCUMENT ME!private static final intDOCUMENT ME!private static final intDOCUMENT ME!private static final intDOCUMENT ME!private static final intDOCUMENT ME!private static final intDOCUMENT ME!private static final intDOCUMENT ME!private static final intDOCUMENT ME!private static final intDOCUMENT ME!private StringDOCUMENT ME!private FileInfoSPMDOCUMENT ME!private StringDOCUMENT ME!private FileDOCUMENT ME!private Stringprivate intDOCUMENT ME!private ModelImageDOCUMENT ME!Fields inherited from class gov.nih.mipav.model.file.FileBase
BIG_ENDIAN, bitsPerPixel, fileNames, LITTLE_ENDIAN, pBarVisible, raFile, READ, READ_WRITE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidfinalize()Prepares this class for cleanup.voidflipTopBottom(float[] buffer, FileInfoSPM fileInfo) Flips image.voidflipTopBottom(ModelImage image) Flips image.Returns the FileInfoSPM read from the file.private intgetOffset(FileInfoSPM fileInfo) Helper method to calculate the offset for getting only the middle SPM image slice from the 3D file.static booleanDetermines whether this file is SPM file or not based on three fields of the header file: sizeof_hdr, extent and regular.booleanDOCUMENT ME!readImage(boolean one) Reads an SPM image file by reading the header then making a FileRaw to read the image for all filenames in the file list.voidreadImage(float[] buffer) Reads an SPM image file by reading the header then making a FileRaw to read the file.voidreOrgInfo(ModelImage image, FileInfoSPM fileInfo) Takes the image and sets it to SPM defaults, using the specified info.protected voidupdateUnitsOfMeasure(FileInfoSPM fileInfo) updates the units of Measure in the file info based on the voxUnits from an SPM Header.protected voidupdateUnitsOfMeasure(FileInfoSPM fileInfo, ModelImage image) updates the units of Measure in the file info based on the voxUnits from an SPM Header.private booleanwriteHeader(ModelImage image, int nImagesSaved, int nTimeSaved, String fileName, String fileDir) Writes an SPM header to a separate file.voidwriteHeader3DTo2D(ModelImage image, String fileName, String fileDir, FileWriteOptions options) DOCUMENT ME!voidwriteHeader4DTo3D(ModelImage image, String fileName, String fileDir, FileWriteOptions options) DOCUMENT ME!voidwriteImage(ModelImage image, FileWriteOptions options) Writes an SPM format type image.Methods inherited from class gov.nih.mipav.model.file.FileBase
addProgressChangeListener, bytesToDouble, bytesToFloat, bytesToInt, bytesToShort, doubleToBytes, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, floatToBytes, getBufferDouble, getBufferFloat, getBufferInt, getBufferLong, getBufferShort, getBufferUShort, getDataType, getDouble, getFloat, getInt, getLong, getProgressChangeListeners, getRaFile, getSignedShort, getString, getUInt, getUnsignedByte, getUnsignedShort, intToBytes, isBigEndian, isProgressBarVisible, linkProgress, longToBytes, readDouble, readFloat, readInt, readLong, readShort, readString, readUnsignedShort, removeProgressChangeListener, setBigEndian, setBufferFloat, setBufferInt, setBufferLong, setBufferShort, setBufferString, setDataType, setEndianess, shortToBytes, writeBytes, writeDouble, writeFloat, writeInt, writeLong, writeShort
-
Field Details
-
DT_NONE
private static final int DT_NONEDOCUMENT ME!- See Also:
-
DT_BINARY
private static final int DT_BINARYDOCUMENT ME!- See Also:
-
DT_BYTE
private static final int DT_BYTEDOCUMENT ME!- See Also:
-
DT_UNSIGNED_CHAR
private static final int DT_UNSIGNED_CHARDOCUMENT ME!- See Also:
-
DT_SIGNED_SHORT
private static final int DT_SIGNED_SHORTDOCUMENT ME!- See Also:
-
DT_UNSIGNED_SHORT
private static final int DT_UNSIGNED_SHORTDOCUMENT ME!- See Also:
-
DT_SIGNED_INT
private static final int DT_SIGNED_INTDOCUMENT ME!- See Also:
-
DT_UNSIGNED_INT
private static final int DT_UNSIGNED_INTDOCUMENT ME!- See Also:
-
DT_FLOAT
private static final int DT_FLOATDOCUMENT ME!- See Also:
-
DT_COMPLEX
private static final int DT_COMPLEXDOCUMENT ME!- See Also:
-
DT_DOUBLE
private static final int DT_DOUBLEDOCUMENT ME!- See Also:
-
DT_RGB
private static final int DT_RGBDOCUMENT ME!- See Also:
-
bufferByte
private byte[] bufferByteDOCUMENT ME! -
fileDir
DOCUMENT ME! -
fileInfo
DOCUMENT ME! -
fileName
DOCUMENT ME! -
headerSize
private int headerSizeDOCUMENT ME! -
image
DOCUMENT ME! -
headerFileName
-
headerFile
DOCUMENT ME! -
dataFileName
-
dataFile
-
-
Constructor Details
-
FileSPM
Constructs new file object.- Parameters:
fName- File name.fDir- File directory.
-
-
Method Details
-
finalize
public void finalize()Prepares this class for cleanup. Calls thefinalizemethod for existing elements, closes any open files and sets other elements tonull. -
isSPM
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
Flips image. SPM stores its data "upside down".- Parameters:
image- Image to flip.- Throws:
IOException- DOCUMENT ME!
-
flipTopBottom
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
Returns the FileInfoSPM read from the file.- Returns:
- File info read from file, or null if it has not been read.
-
readHeader
DOCUMENT ME!- Returns:
- true if read successfully
- Throws:
IOException- DOCUMENT ME!
-
readImage
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 fileOutOfMemoryError- See Also:
-
readImage
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 fileOutOfMemoryError- See Also:
-
reOrgInfo
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
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
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
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 readimage- -- a ModelImage that the fileInfo needs to be attached to
-
getOffset
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:
-