Package gov.nih.mipav.model.file
Class FileDicomBase
java.lang.Object
gov.nih.mipav.model.file.FileDicomBase
- Direct Known Subclasses:
FileDicom
FileDICOMBase is an class that supports the reading/writing of DICOM files. It reads in a buffer of tags that can be
parsed more quickly than continued random accesses to the harddrive.
- Version:
- 1.0 June 30, 2005
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intInteger variable used to read/write in data so that they don't need to be allocated with each read/write.private intInteger variable used to read/write in data so that they don't need to be allocated with each read/write.private intInteger variable used to read/write in data so that they don't need to be allocated with each read/write.private intInteger variable used to read/write in data so that they don't need to be allocated with each read/write.private intInteger variable used to read/write in data so that they don't need to be allocated with each read/write.private intInteger variable used to read/write in data so that they don't need to be allocated with each read/write.private intInteger variable used to read/write in data so that they don't need to be allocated with each read/write.private intInteger variable used to read/write in data so that they don't need to be allocated with each read/write.static final booleanByte order.private intBuffer pointer (aka file pointer).static final longThe size of the buffer that contains the tags of the DICOM image.protected final byte[]One byte array used to read/write in data so that one doesn't't need to be allocated with each read/write.protected final byte[]Two byte array used to read/write in data so that one doesn't't need to be allocated with each read/write.protected final byte[]Four byte array used to read/write in data so that one doesn't need to be allocated with each read/write.protected final byte[]Eight byte array used to read/write in data so that they don't need to be allocated with each read/write.protected longTotal length of the image file.protected intprotected intprotected intprotected intprotected booleanstatic final booleanByte order.protected booleanIf file is a DICOMDIR this is false *protected intThe number of images inside of this file which are not the main displayable image (may be icon, RT planning, etc.protected booleanFlag indicating if the progress bar should be shown.protected ProgressBarInterfaceProgress bar to show when reading in image file.protected RandomAccessFilePointer to file to read or write from.static final intRead only access.static final intRead-write access.protected booleanprotected byte[]The buffer that holds the tags of the DICOM image.protected boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidfinalize()Prepares this class for cleanup.final intgetByte()Reads unsigned bytes from file.final doublegetDouble(boolean endianess) Reads eight unsigned bytes from file.protected final longprotected final intGets the file/buffer pointer and returns it.final floatgetFloat(boolean endianess) Reads four unsigned bytes from file.final intgetInt(boolean endianess) Reads four signed bytes from file.final longgetLong(boolean endianess) Reads eight unsigned bytes from file.final intReads signed bytes from file.final intgetSignedShort(boolean endianess) Reads two byte signed short from file.final StringgetString(int length) Reads a string from a file of givenlength.final StringgetStringFromFile(int length) Reads a string from a file of givenlength.final longgetUInt(boolean endianess) Reads four unsigned bytes from file.final intgetUnsignedShort(boolean endianess) Reads two unsigned bytes from file.voidSetups the allocation of memory for the byte buffer to load the entire image.booleanReturns whether this Dicom read is only interested in the header tags and not the image data (if it exists).booleanReturns flag that indicates that the progressBar is visible.voidloadTagBuffer(int b3) Setups the allocation of memory for the byte buffer to load tags.intlocateImageTag(int offset, int imageNumber, int b3) Locates a DICOM image beginning at the given offset.protected final voidread(byte[] byteBuffer) Reads into the supplied buffer data from the DICOM tag buffer.private booleansearchForImageTag(byte[] tempTagBuffer, byte[] endianBuffer, int bufferIndex) Performs internal search for the image tag in a dicom file, given an appropriate endianess.protected final voidseek(int value) Seeks to a point in the buffer.final voidsetBufferFloat(byte[] buffer, float data, int i, boolean endianess) Sets byte buffer with int.final voidsetBufferInt(byte[] buffer, int data, int i, boolean endianess) Sets byte buffer with int.final voidsetBufferLong(byte[] buffer, long data, int i, boolean endianess) Sets byte buffer with long.final voidsetBufferShort(byte[] buffer, short data, int i, boolean endianess) Sets byte buffer with int.final voidsetBufferString(byte[] buffer, String str, int i) Sets byte buffer with int.voidsetHeaderOnlyRead(boolean isHeaderOnly) Sets whether this Dicom read is only interested in the header tags and not the image data (if it exists).voidsetProgressBarVisible(boolean flag) Sets whether or not the progress bar should be visible.final voidsetTagBuffer(byte[] buffer) DOCUMENT ME!protected final voidskipBytes(int value) Skips to a new point in the buffer.final voidwriteByte(byte data) Writes a byte to a file.final voidwriteDouble(double data, boolean endianess) Writes a double as eight bytes to a file.final voidwriteFloat(float data, boolean endianess) Writes a float as four bytes to a file.final voidwriteInt(int data, boolean endianess) Writes an int as four bytes to a file.final voidwriteLong(long data, boolean endianess) Writes a long as eight bytes to a file.final voidwriteShort(short data, boolean endianess) Writes a short as two bytes to a file.final voidwriteUnsignedShort(short data, boolean endianess) Writes an unsigned short as two bytes to a file.
-
Field Details
-
LITTLE_ENDIAN
public static final boolean LITTLE_ENDIANByte order. Rightmost byte is most significant.- See Also:
-
BIG_ENDIAN
public static final boolean BIG_ENDIANByte order. Leftmost byte is most significant.- See Also:
-
READ
public static final int READRead only access.- See Also:
-
READ_WRITE
public static final int READ_WRITERead-write access.- See Also:
-
BUFFER_SIZE
public static final long BUFFER_SIZEThe size of the buffer that contains the tags of the DICOM image. Default = 400Thousand.- See Also:
-
byteBuffer
protected final byte[] byteBufferOne byte array used to read/write in data so that one doesn't't need to be allocated with each read/write. -
byteBuffer2
protected final byte[] byteBuffer2Two byte array used to read/write in data so that one doesn't't need to be allocated with each read/write. -
byteBuffer4
protected final byte[] byteBuffer4Four byte array used to read/write in data so that one doesn't need to be allocated with each read/write. -
byteBuffer8
protected final byte[] byteBuffer8Eight byte array used to read/write in data so that they don't need to be allocated with each read/write. -
fLength
protected long fLengthTotal length of the image file. -
pBarVisible
protected boolean pBarVisibleFlag indicating if the progress bar should be shown. -
progressBar
Progress bar to show when reading in image file. -
raFile
Pointer to file to read or write from. -
tagBuffer
protected byte[] tagBufferThe buffer that holds the tags of the DICOM image. -
b1
private int b1Integer variable used to read/write in data so that they don't need to be allocated with each read/write. -
b2
private int b2Integer variable used to read/write in data so that they don't need to be allocated with each read/write. -
b3
private int b3Integer variable used to read/write in data so that they don't need to be allocated with each read/write. -
b4
private int b4Integer variable used to read/write in data so that they don't need to be allocated with each read/write. -
b5
private int b5Integer variable used to read/write in data so that they don't need to be allocated with each read/write. -
b6
private int b6Integer variable used to read/write in data so that they don't need to be allocated with each read/write. -
b7
private int b7Integer variable used to read/write in data so that they don't need to be allocated with each read/write. -
b8
private int b8Integer variable used to read/write in data so that they don't need to be allocated with each read/write. -
bPtr
private int bPtrBuffer pointer (aka file pointer). -
notDir
protected boolean notDirIf file is a DICOMDIR this is false * -
numEmbeddedImages
protected int numEmbeddedImagesThe number of images inside of this file which are not the main displayable image (may be icon, RT planning, etc. -
isDicomRecv
protected boolean isDicomRecv -
imageGroupWord
protected int imageGroupWord -
imageElementWord
protected int imageElementWord -
imageElementLength
protected int imageElementLength -
imageTagLocation
protected int imageTagLocation -
TAMAR
protected boolean TAMAR -
SPECTROSCOPY
protected boolean SPECTROSCOPY
-
-
Constructor Details
-
FileDicomBase
public FileDicomBase()Empty constructor.
-
-
Method Details
-
finalize
public void finalize()Prepares this class for cleanup. -
getByte
Reads unsigned bytes from file.- Returns:
- The value of unsigned byte read from the file returned as an int.
- Throws:
IOException- if there is an error reading the file
-
getSignedByte
Reads signed bytes from file.- Returns:
- The value of signed byte read from the file returned as an int.
- Throws:
IOException- if there is an error reading the file
-
getDouble
Reads eight unsigned bytes from file.- Parameters:
endianess-trueindicates big endian byte order,falseindicates little endian.- Returns:
- The value of the double read from the file.
- Throws:
IOException- if there is an error reading the file
-
getFloat
Reads four unsigned bytes from file.- Parameters:
endianess-trueindicates big endian byte order,falseindicates little endian.- Returns:
- The value of the float read from the file.
- Throws:
IOException- if there is an error reading the file
-
getInt
Reads four signed bytes from file.- Parameters:
endianess-trueindicates big endian byte order,falseindicates little endian.- Returns:
- The value of the integer read from the file.
- Throws:
IOException- if there is an error reading the file
-
getLong
Reads eight unsigned bytes from file.- Parameters:
endianess-trueindicates big endian byte order,falseindicates little endian.- Returns:
- The value of the long read from the file.
- Throws:
IOException- if there is an error reading the file
-
getSignedShort
Reads two byte signed short from file.- Parameters:
endianess-trueindicates big endian byte order,falseindicates little endian.- Returns:
- The value of signed short read from the file returned as an int.
- Throws:
IOException- if there is an error reading the file
-
getString
Reads a string from a file of givenlength.- Parameters:
length- Number of bytes that form the string.- Returns:
- The string read from the file.
- Throws:
IOException- if there is an error reading the file
-
getStringFromFile
Reads a string from a file of givenlength.- Parameters:
length- Number of bytes that form the string.- Returns:
- The string read from the file.
- Throws:
IOException- if there is an error reading the file
-
getUInt
Reads four unsigned bytes from file.- Parameters:
endianess-trueindicates big endian byte order,falseindicates little endian.- Returns:
- The value of the integer read from the file.
- Throws:
IOException- if there is an error reading the file
-
getUnsignedShort
Reads two unsigned bytes from file.- Parameters:
endianess-trueindicates big endian byte order,falseindicates little endian.- Returns:
- The value of unsigned short read from the file returned as an int.
- Throws:
IOException- if there is an error reading the file
-
initializeFullRead
public void initializeFullRead()Setups the allocation of memory for the byte buffer to load the entire image. -
isProgressBarVisible
public boolean isProgressBarVisible()Returns flag that indicates that the progressBar is visible.- Returns:
trueif progress bar is visible,falseif not visible.
-
searchForImageTag
private boolean searchForImageTag(byte[] tempTagBuffer, byte[] endianBuffer, int bufferIndex) Performs internal search for the image tag in a dicom file, given an appropriate endianess. -
loadTagBuffer
Setups the allocation of memory for the byte buffer to load tags. This tag buffer is a cache to speed the loading of the images.- Throws:
IOException
-
locateImageTag
public int locateImageTag(int offset, int imageNumber, int b3) Locates a DICOM image beginning at the given offset. When multiple images after the offset exist, imageNumber can be used to specify the exact image to retrieve. -
setBufferFloat
public final void setBufferFloat(byte[] buffer, float data, int i, boolean endianess) Sets byte buffer with int.- Parameters:
buffer- Byte buffers where data is to be stored.data- Float data is broken down in bytes and stored in the byte buffer.i- Index into byte buffer.endianess-trueindicates big endian byte order,falseindicates little endian.
-
setBufferInt
public final void setBufferInt(byte[] buffer, int data, int i, boolean endianess) Sets byte buffer with int.- Parameters:
buffer- Byte buffers where data is to be stored.data- Integer data is broken down in bytes and stored in the byte buffer.i- Index into byte buffer.endianess-trueindicates big endian byte order,falseindicates little endian.
-
setBufferLong
public final void setBufferLong(byte[] buffer, long data, int i, boolean endianess) Sets byte buffer with long.- Parameters:
buffer- Byte buffers where data is to be stored.data- Long data is broken down in bytes and stored in the byte buffer.i- Index into byte buffer.endianess-trueindicates big endian byte order,falseindicates little endian.
-
setBufferShort
public final void setBufferShort(byte[] buffer, short data, int i, boolean endianess) Sets byte buffer with int.- Parameters:
buffer- Byte buffers where data is to be stored.data- Short data is broken down in bytes and stored in the byte buffer.i- Index into byte buffer.endianess-trueindicates big endian byte order,falseindicates little endian.
-
setBufferString
Sets byte buffer with int.- Parameters:
buffer- Byte buffers where data is to be stored.str- String containing integer data which is broken down in bytes and stored in the byte buffer.i- Index into byte buffer.
-
setProgressBarVisible
public void setProgressBarVisible(boolean flag) Sets whether or not the progress bar should be visible.- Parameters:
flag-trueif should be visible,falseif not visible.
-
setTagBuffer
public final void setTagBuffer(byte[] buffer) DOCUMENT ME!- Parameters:
buffer- byte[]
-
writeDouble
Writes a double as eight bytes to a file.- Parameters:
data- Data to be written to file.endianess-trueindicates big endian byte order,falseindicates little endian.- Throws:
IOException- if there is an error writing the file
-
writeFloat
Writes a float as four bytes to a file.- Parameters:
data- Data to be written to file.endianess-trueindicates big endian byte order,falseindicates little endian.- Throws:
IOException- if there is an error writing the file
-
writeInt
Writes an int as four bytes to a file.- Parameters:
data- Data to be written to file.endianess-trueindicates big endian byte order,falseindicates little endian.- Throws:
IOException- if there is an error writing the file
-
writeLong
Writes a long as eight bytes to a file.- Parameters:
data- Data to be written to file.endianess-trueindicates big endian byte order,falseindicates little endian.- Throws:
IOException- if there is an error writing the file
-
writeShort
Writes a short as two bytes to a file.- Parameters:
data- Data to be written to file.endianess-trueindicates big endian byte order,falseindicates little endian.- Throws:
IOException- if there is an error writing the file
-
writeUnsignedShort
Writes an unsigned short as two bytes to a file.- Parameters:
data- Data to be written to file.endianess-trueindicates big endian byte order,falseindicates little endian.- Throws:
IOException- if there is an error writing the file
-
writeByte
Writes a byte to a file.- Parameters:
data- Data to be written to file.- Throws:
IOException- if there is an error writing the file
-
getFilePointer
protected final int getFilePointer()Gets the file/buffer pointer and returns it.- Returns:
- the file/buffer pointer
-
getFileLength
protected final long getFileLength() -
read
protected final void read(byte[] byteBuffer) Reads into the supplied buffer data from the DICOM tag buffer.- Parameters:
byteBuffer- byte[]
-
seek
protected final void seek(int value) Seeks to a point in the buffer.- Parameters:
value- indicates the new buffer pointer value
-
skipBytes
protected final void skipBytes(int value) Skips to a new point in the buffer.- Parameters:
value- number of bytes to skip
-
isHeaderOnlyRead
public boolean isHeaderOnlyRead()Returns whether this Dicom read is only interested in the header tags and not the image data (if it exists). Used by dcm recv and in cases like spectroscopy where there isn't a true image, but some tags may contain data that triggers the image search parameters ("7F" hex value, etc.).- Returns:
- Whether the image data should be searched for or otherwise read.
-
setHeaderOnlyRead
public void setHeaderOnlyRead(boolean isHeaderOnly) Sets whether this Dicom read is only interested in the header tags and not the image data (if it exists). Used by dcm recv and in cases like spectroscopy where there isn't a true image, but some tags may contain data that triggers the image search parameters ("7F" hex value, etc.).- Parameters:
isHeaderOnly- Whether we are only interested in reading the tags from the header, not the image data.
-