Package gov.nih.mipav.model.file
Class FileRaw
- java.lang.Object
-
- gov.nih.mipav.model.file.FileBase
-
- gov.nih.mipav.model.file.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 Summary
Fields Modifier and Type Field Description private int
bitsAllocated
private int
bitsStored
private int
compressionType
DOCUMENT ME!private java.lang.String[]
dataFileName
private java.io.File
file
DOCUMENT ME!private FileInfoBase
fileInfo
DOCUMENT ME!private java.lang.String
fileName
private FileRawChunk
fileRW
DOCUMENT ME!private int
highBit
private int
minimumBitsMinus1
Used in reading and writing booleanprivate int
nImages
DOCUMENT ME!private int
nTimePeriods
DOCUMENT ME!private int
numChannels
private int
planarConfig
DOCUMENT ME!private boolean
RGBAOrder
Allow reading from 4 color files with RGBA orderprivate int
shiftToDivide
Used in reading and writing booleanprivate long
startPosition
DOCUMENT ME!private boolean
threeByteInteger
private boolean
YBR_FULL_422
private boolean
zeroLengthFlag
flag that indicates if raFile should first be set to length of 0-
Fields inherited from class gov.nih.mipav.model.file.FileBase
BIG_ENDIAN, bitsPerPixel, fileNames, LITTLE_ENDIAN, pBarVisible, raFile, READ, READ_WRITE
-
-
Constructor Summary
Constructors Constructor Description FileRaw(FileInfoBase fInfo)
Constructor for Raw Files that will be used to write from 4D to 3D or from 3D to 2D.FileRaw(java.lang.String fileName, FileInfoBase fInfo, int rwFlag)
Raw reader/writer constructor.FileRaw(java.lang.String fileName, java.lang.String fileDir, FileInfoBase fInfo, int rwFlag)
Raw reader/writer constructor..
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes random access file associated with this object.void
finalize()
Prepares this class for cleanup.java.lang.String[]
getDataFileName()
Accessor that returns the array of data file namesint
getNImages()
Accessor that returns the number of image slices saved.int
getNTimePeriods()
Accessor that returns the number of time periods saved.void
readFloatImage(ModelImage image, int originalDataType, float[] scaleFactor, float[] offsetAdjustment, long offset)
This method reads a raw image file (1D - 5D).void
readImage(double[] buffer, long offset)
This method reads a file and puts the data in the buffer.void
readImage(float[] buffer, long offset, int imageType)
This method reads a file and puts the data in the buffer.void
readImage(int[] buffer, long offset, int imageType)
This method reads a file and puts the data in the buffer.void
readImage(short[] buffer, long offset, int imageType)
This method reads a file and puts the data in the buffer.void
readImage(ModelImage image, long offset)
This method reads a raw image file (1D - 5D).void
setBitsAllocated(int bitsAllocated)
void
setBitsStored(int bitsStored)
void
setHighBit(int highBit)
void
setImageFile(java.lang.String fileName, java.lang.String fileDir, FileInfoBase fInfo, int rwFlag)
Sets the name and directory to new values opens the file.void
setMinimumBitsMinus1(int minimumBitsMinus1)
Used in reading and writing booleanvoid
setNumChannels(int numChannels)
Sets the number of channels used in RGB filesvoid
setPlanarConfig(int _planarConfig)
Sets the planar configuration for RGB images.void
setRGBAOrder(boolean RGBAOrder)
void
setShiftToDivide(int shiftToDivide)
Used in reading and writing booleanvoid
setStartPosition(long startPosition)
DOCUMENT ME!void
setThreeByteInteger(boolean threeByteInteger)
void
setYBR_FULL_422(boolean YBR_FULL_422)
void
setZeroLengthFlag(boolean zeroLengthFlag)
setZeroLengthFlagvoid
writeImage(ModelImage image, int beginSlice, int endSlice, int beginTimePeriod, int endTimePeriod)
This method writes a raw image file.void
writeImage(ModelImage image, FileWriteOptions options)
This method writes a raw image file.void
writeImage3DTo2D(ModelImage image, FileWriteOptions options, java.lang.String suffix)
Method to save 3D images to an array of 2D images.void
writeImage3DTo2D(ModelImage image, FileWriteOptions options, java.lang.String suffix, long[] finalHeaderPosition)
Method to save 3D images to an array of 2D images.void
writeImage4DTo3D(ModelImage image, FileWriteOptions options, java.lang.String suffix)
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 #.void
writeImage4DTo3D(ModelImage image, FileWriteOptions options, java.lang.String suffix, long[] finalHeaderPosition)
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 #.-
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 Detail
-
compressionType
private int compressionType
DOCUMENT ME!
-
file
private java.io.File file
DOCUMENT ME!
-
fileInfo
private FileInfoBase fileInfo
DOCUMENT ME!
-
fileName
private java.lang.String fileName
-
fileRW
private FileRawChunk fileRW
DOCUMENT ME!
-
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 namefInfo
- 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.
-
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 sliceoffsetAdjustment
- array with an additive offset adjustment for each sliceoffset
- 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 optionssuffix
- 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 optionssuffix
- 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 savedoptions
- File write optionssuffix
- 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 savedoptions
- File write optionssuffix
- 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
-
-
-