Package gov.nih.mipav.model.file
Class FileDicomBase
- java.lang.Object
-
- gov.nih.mipav.model.file.FileDicomBase
-
- Direct Known Subclasses:
FileDicom
public class FileDicomBase extends java.lang.ObjectFileDICOMBase 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
Fields Modifier and Type Field Description private intb1Integer variable used to read/write in data so that they don't need to be allocated with each read/write.private intb2Integer variable used to read/write in data so that they don't need to be allocated with each read/write.private intb3Integer variable used to read/write in data so that they don't need to be allocated with each read/write.private intb4Integer variable used to read/write in data so that they don't need to be allocated with each read/write.private intb5Integer variable used to read/write in data so that they don't need to be allocated with each read/write.private intb6Integer variable used to read/write in data so that they don't need to be allocated with each read/write.private intb7Integer variable used to read/write in data so that they don't need to be allocated with each read/write.private intb8Integer variable used to read/write in data so that they don't need to be allocated with each read/write.static booleanBIG_ENDIANByte order.private intbPtrBuffer pointer (aka file pointer).static longBUFFER_SIZEThe size of the buffer that contains the tags of the DICOM image.protected byte[]byteBufferOne byte array used to read/write in data so that one doesn't't need to be allocated with each read/write.protected byte[]byteBuffer2Two byte array used to read/write in data so that one doesn't't need to be allocated with each read/write.protected byte[]byteBuffer4Four byte array used to read/write in data so that one doesn't need to be allocated with each read/write.protected byte[]byteBuffer8Eight byte array used to read/write in data so that they don't need to be allocated with each read/write.protected longfLengthTotal length of the image file.protected intimageElementLengthprotected intimageElementWordprotected intimageGroupWordprotected intimageTagLocationprotected booleanisDicomRecvstatic booleanLITTLE_ENDIANByte order.protected booleannotDirIf file is a DICOMDIR this is false *protected intnumEmbeddedImagesThe number of images inside of this file which are not the main displayable image (may be icon, RT planning, etc.protected booleanpBarVisibleFlag indicating if the progress bar should be shown.protected ProgressBarInterfaceprogressBarProgress bar to show when reading in image file.protected java.io.RandomAccessFileraFilePointer to file to read or write from.static intREADRead only access.static intREAD_WRITERead-write access.protected booleanSPECTROSCOPYprotected byte[]tagBufferThe buffer that holds the tags of the DICOM image.protected booleanTAMAR
-
Constructor Summary
Constructors Constructor Description FileDicomBase()Empty constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidfinalize()Prepares this class for cleanup.intgetByte()Reads unsigned bytes from file.doublegetDouble(boolean endianess)Reads eight unsigned bytes from file.protected longgetFileLength()protected intgetFilePointer()Gets the file/buffer pointer and returns it.floatgetFloat(boolean endianess)Reads four unsigned bytes from file.intgetInt(boolean endianess)Reads four signed bytes from file.longgetLong(boolean endianess)Reads eight unsigned bytes from file.intgetSignedByte()Reads signed bytes from file.intgetSignedShort(boolean endianess)Reads two byte signed short from file.java.lang.StringgetString(int length)Reads a string from a file of givenlength.java.lang.StringgetStringFromFile(int length)Reads a string from a file of givenlength.longgetUInt(boolean endianess)Reads four unsigned bytes from file.intgetUnsignedShort(boolean endianess)Reads two unsigned bytes from file.voidinitializeFullRead()Setups the allocation of memory for the byte buffer to load the entire image.booleanisHeaderOnlyRead()Returns whether this Dicom read is only interested in the header tags and not the image data (if it exists).booleanisProgressBarVisible()Returns 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 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 voidseek(int value)Seeks to a point in the buffer.voidsetBufferFloat(byte[] buffer, float data, int i, boolean endianess)Sets byte buffer with int.voidsetBufferInt(byte[] buffer, int data, int i, boolean endianess)Sets byte buffer with int.voidsetBufferLong(byte[] buffer, long data, int i, boolean endianess)Sets byte buffer with long.voidsetBufferShort(byte[] buffer, short data, int i, boolean endianess)Sets byte buffer with int.voidsetBufferString(byte[] buffer, java.lang.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.voidsetTagBuffer(byte[] buffer)DOCUMENT ME!protected voidskipBytes(int value)Skips to a new point in the buffer.voidwriteByte(byte data)Writes a byte to a file.voidwriteDouble(double data, boolean endianess)Writes a double as eight bytes to a file.voidwriteFloat(float data, boolean endianess)Writes a float as four bytes to a file.voidwriteInt(int data, boolean endianess)Writes an int as four bytes to a file.voidwriteLong(long data, boolean endianess)Writes a long as eight bytes to a file.voidwriteShort(short data, boolean endianess)Writes a short as two bytes to a file.voidwriteUnsignedShort(short data, boolean endianess)Writes an unsigned short as two bytes to a file.
-
-
-
Field Detail
-
LITTLE_ENDIAN
public static final boolean LITTLE_ENDIAN
Byte order. Rightmost byte is most significant.- See Also:
- Constant Field Values
-
BIG_ENDIAN
public static final boolean BIG_ENDIAN
Byte order. Leftmost byte is most significant.- See Also:
- Constant Field Values
-
READ
public static final int READ
Read only access.- See Also:
- Constant Field Values
-
READ_WRITE
public static final int READ_WRITE
Read-write access.- See Also:
- Constant Field Values
-
BUFFER_SIZE
public static final long BUFFER_SIZE
The size of the buffer that contains the tags of the DICOM image. Default = 400Thousand.- See Also:
- Constant Field Values
-
byteBuffer
protected final byte[] byteBuffer
One 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[] byteBuffer2
Two 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[] byteBuffer4
Four 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[] byteBuffer8
Eight byte array used to read/write in data so that they don't need to be allocated with each read/write.
-
fLength
protected long fLength
Total length of the image file.
-
pBarVisible
protected boolean pBarVisible
Flag indicating if the progress bar should be shown.
-
progressBar
protected ProgressBarInterface progressBar
Progress bar to show when reading in image file.
-
raFile
protected java.io.RandomAccessFile raFile
Pointer to file to read or write from.
-
tagBuffer
protected byte[] tagBuffer
The buffer that holds the tags of the DICOM image.
-
b1
private int b1
Integer variable used to read/write in data so that they don't need to be allocated with each read/write.
-
b2
private int b2
Integer variable used to read/write in data so that they don't need to be allocated with each read/write.
-
b3
private int b3
Integer variable used to read/write in data so that they don't need to be allocated with each read/write.
-
b4
private int b4
Integer variable used to read/write in data so that they don't need to be allocated with each read/write.
-
b5
private int b5
Integer variable used to read/write in data so that they don't need to be allocated with each read/write.
-
b6
private int b6
Integer variable used to read/write in data so that they don't need to be allocated with each read/write.
-
b7
private int b7
Integer variable used to read/write in data so that they don't need to be allocated with each read/write.
-
b8
private int b8
Integer variable used to read/write in data so that they don't need to be allocated with each read/write.
-
bPtr
private int bPtr
Buffer pointer (aka file pointer).
-
notDir
protected boolean notDir
If file is a DICOMDIR this is false *
-
numEmbeddedImages
protected int numEmbeddedImages
The 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
-
-
Method Detail
-
finalize
public void finalize()
Prepares this class for cleanup.- Overrides:
finalizein classjava.lang.Object
-
getByte
public final int getByte() throws java.io.IOExceptionReads unsigned bytes from file.- Returns:
- The value of unsigned byte read from the file returned as an int.
- Throws:
java.io.IOException- if there is an error reading the file
-
getSignedByte
public final int getSignedByte() throws java.io.IOExceptionReads signed bytes from file.- Returns:
- The value of signed byte read from the file returned as an int.
- Throws:
java.io.IOException- if there is an error reading the file
-
getDouble
public final double getDouble(boolean endianess) throws java.io.IOExceptionReads 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:
java.io.IOException- if there is an error reading the file
-
getFloat
public final float getFloat(boolean endianess) throws java.io.IOExceptionReads 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:
java.io.IOException- if there is an error reading the file
-
getInt
public final int getInt(boolean endianess) throws java.io.IOExceptionReads 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:
java.io.IOException- if there is an error reading the file
-
getLong
public final long getLong(boolean endianess) throws java.io.IOExceptionReads 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:
java.io.IOException- if there is an error reading the file
-
getSignedShort
public final int getSignedShort(boolean endianess) throws java.io.IOExceptionReads 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:
java.io.IOException- if there is an error reading the file
-
getString
public final java.lang.String getString(int length) throws java.io.IOExceptionReads a string from a file of givenlength.- Parameters:
length- Number of bytes that form the string.- Returns:
- The string read from the file.
- Throws:
java.io.IOException- if there is an error reading the file
-
getStringFromFile
public final java.lang.String getStringFromFile(int length) throws java.io.IOExceptionReads a string from a file of givenlength.- Parameters:
length- Number of bytes that form the string.- Returns:
- The string read from the file.
- Throws:
java.io.IOException- if there is an error reading the file
-
getUInt
public final long getUInt(boolean endianess) throws java.io.IOExceptionReads 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:
java.io.IOException- if there is an error reading the file
-
getUnsignedShort
public final int getUnsignedShort(boolean endianess) throws java.io.IOExceptionReads 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:
java.io.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
public void loadTagBuffer(int b3) throws java.io.IOExceptionSetups 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:
java.io.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
public final void setBufferString(byte[] buffer, java.lang.String str, int i)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
public final void writeDouble(double data, boolean endianess) throws java.io.IOExceptionWrites 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:
java.io.IOException- if there is an error writing the file
-
writeFloat
public final void writeFloat(float data, boolean endianess) throws java.io.IOExceptionWrites 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:
java.io.IOException- if there is an error writing the file
-
writeInt
public final void writeInt(int data, boolean endianess) throws java.io.IOExceptionWrites 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:
java.io.IOException- if there is an error writing the file
-
writeLong
public final void writeLong(long data, boolean endianess) throws java.io.IOExceptionWrites 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:
java.io.IOException- if there is an error writing the file
-
writeShort
public final void writeShort(short data, boolean endianess) throws java.io.IOExceptionWrites 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:
java.io.IOException- if there is an error writing the file
-
writeUnsignedShort
public final void writeUnsignedShort(short data, boolean endianess) throws java.io.IOExceptionWrites 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:
java.io.IOException- if there is an error writing the file
-
writeByte
public final void writeByte(byte data) throws java.io.IOExceptionWrites a byte to a file.- Parameters:
data- Data to be written to file.- Throws:
java.io.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.
-
-