Class FileDicomBase

  • Direct Known Subclasses:
    FileDicom

    public class FileDicomBase
    extends java.lang.Object
    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

      Fields 
      Modifier and Type Field Description
      private int b1
      Integer variable used to read/write in data so that they don't need to be allocated with each read/write.
      private int b2
      Integer variable used to read/write in data so that they don't need to be allocated with each read/write.
      private int b3
      Integer variable used to read/write in data so that they don't need to be allocated with each read/write.
      private int b4
      Integer variable used to read/write in data so that they don't need to be allocated with each read/write.
      private int b5
      Integer variable used to read/write in data so that they don't need to be allocated with each read/write.
      private int b6
      Integer variable used to read/write in data so that they don't need to be allocated with each read/write.
      private int b7
      Integer variable used to read/write in data so that they don't need to be allocated with each read/write.
      private int b8
      Integer variable used to read/write in data so that they don't need to be allocated with each read/write.
      static boolean BIG_ENDIAN
      Byte order.
      private int bPtr
      Buffer pointer (aka file pointer).
      static long BUFFER_SIZE
      The size of the buffer that contains the tags of the DICOM image.
      protected 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.
      protected 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.
      protected byte[] byteBuffer4
      Four byte array used to read/write in data so that one doesn't need to be allocated with each read/write.
      protected byte[] byteBuffer8
      Eight byte array used to read/write in data so that they don't need to be allocated with each read/write.
      protected long fLength
      Total length of the image file.
      protected int imageElementLength  
      protected int imageElementWord  
      protected int imageGroupWord  
      protected int imageTagLocation  
      protected boolean isDicomRecv  
      static boolean LITTLE_ENDIAN
      Byte order.
      protected boolean notDir
      If file is a DICOMDIR this is false *
      protected int numEmbeddedImages
      The number of images inside of this file which are not the main displayable image (may be icon, RT planning, etc.
      protected boolean pBarVisible
      Flag indicating if the progress bar should be shown.
      protected ProgressBarInterface progressBar
      Progress bar to show when reading in image file.
      protected java.io.RandomAccessFile raFile
      Pointer to file to read or write from.
      static int READ
      Read only access.
      static int READ_WRITE
      Read-write access.
      protected boolean SPECTROSCOPY  
      protected byte[] tagBuffer
      The buffer that holds the tags of the DICOM image.
      protected boolean TAMAR  
    • Constructor Summary

      Constructors 
      Constructor Description
      FileDicomBase()
      Empty constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void finalize()
      Prepares this class for cleanup.
      int getByte()
      Reads unsigned bytes from file.
      double getDouble​(boolean endianess)
      Reads eight unsigned bytes from file.
      protected long getFileLength()  
      protected int getFilePointer()
      Gets the file/buffer pointer and returns it.
      float getFloat​(boolean endianess)
      Reads four unsigned bytes from file.
      int getInt​(boolean endianess)
      Reads four signed bytes from file.
      long getLong​(boolean endianess)
      Reads eight unsigned bytes from file.
      int getSignedByte()
      Reads signed bytes from file.
      int getSignedShort​(boolean endianess)
      Reads two byte signed short from file.
      java.lang.String getString​(int length)
      Reads a string from a file of given length.
      java.lang.String getStringFromFile​(int length)
      Reads a string from a file of given length.
      long getUInt​(boolean endianess)
      Reads four unsigned bytes from file.
      int getUnsignedShort​(boolean endianess)
      Reads two unsigned bytes from file.
      void initializeFullRead()
      Setups the allocation of memory for the byte buffer to load the entire image.
      boolean isHeaderOnlyRead()
      Returns whether this Dicom read is only interested in the header tags and not the image data (if it exists).
      boolean isProgressBarVisible()
      Returns flag that indicates that the progressBar is visible.
      void loadTagBuffer​(int b3)
      Setups the allocation of memory for the byte buffer to load tags.
      int locateImageTag​(int offset, int imageNumber, int b3)
      Locates a DICOM image beginning at the given offset.
      protected void read​(byte[] byteBuffer)
      Reads into the supplied buffer data from the DICOM tag buffer.
      private boolean searchForImageTag​(byte[] tempTagBuffer, byte[] endianBuffer, int bufferIndex)
      Performs internal search for the image tag in a dicom file, given an appropriate endianess.
      protected void seek​(int value)
      Seeks to a point in the buffer.
      void setBufferFloat​(byte[] buffer, float data, int i, boolean endianess)
      Sets byte buffer with int.
      void setBufferInt​(byte[] buffer, int data, int i, boolean endianess)
      Sets byte buffer with int.
      void setBufferLong​(byte[] buffer, long data, int i, boolean endianess)
      Sets byte buffer with long.
      void setBufferShort​(byte[] buffer, short data, int i, boolean endianess)
      Sets byte buffer with int.
      void setBufferString​(byte[] buffer, java.lang.String str, int i)
      Sets byte buffer with int.
      void setHeaderOnlyRead​(boolean isHeaderOnly)
      Sets whether this Dicom read is only interested in the header tags and not the image data (if it exists).
      void setProgressBarVisible​(boolean flag)
      Sets whether or not the progress bar should be visible.
      void setTagBuffer​(byte[] buffer)
      DOCUMENT ME!
      protected void skipBytes​(int value)
      Skips to a new point in the buffer.
      void writeByte​(byte data)
      Writes a byte to a file.
      void writeDouble​(double data, boolean endianess)
      Writes a double as eight bytes to a file.
      void writeFloat​(float data, boolean endianess)
      Writes a float as four bytes to a file.
      void writeInt​(int data, boolean endianess)
      Writes an int as four bytes to a file.
      void writeLong​(long data, boolean endianess)
      Writes a long as eight bytes to a file.
      void writeShort​(short data, boolean endianess)
      Writes a short as two bytes to a file.
      void writeUnsignedShort​(short data, boolean endianess)
      Writes an unsigned short as two bytes to a file.
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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
      • 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
    • Constructor Detail

      • FileDicomBase

        public FileDicomBase()
        Empty constructor.
    • Method Detail

      • finalize

        public void finalize()
        Prepares this class for cleanup.
        Overrides:
        finalize in class java.lang.Object
      • getByte

        public final int getByte()
                          throws java.io.IOException
        Reads 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.IOException
        Reads 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.IOException
        Reads eight unsigned bytes from file.
        Parameters:
        endianess - true indicates big endian byte order, false indicates 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.IOException
        Reads four unsigned bytes from file.
        Parameters:
        endianess - true indicates big endian byte order, false indicates 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.IOException
        Reads four signed bytes from file.
        Parameters:
        endianess - true indicates big endian byte order, false indicates 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.IOException
        Reads eight unsigned bytes from file.
        Parameters:
        endianess - true indicates big endian byte order, false indicates 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.IOException
        Reads two byte signed short from file.
        Parameters:
        endianess - true indicates big endian byte order, false indicates 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.IOException
        Reads a string from a file of given length.
        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.IOException
        Reads a string from a file of given length.
        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.IOException
        Reads four unsigned bytes from file.
        Parameters:
        endianess - true indicates big endian byte order, false indicates 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.IOException
        Reads two unsigned bytes from file.
        Parameters:
        endianess - true indicates big endian byte order, false indicates 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:
        true if progress bar is visible, false if 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.IOException
        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:
        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 - true indicates big endian byte order, false indicates 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 - true indicates big endian byte order, false indicates 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 - true indicates big endian byte order, false indicates 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 - true indicates big endian byte order, false indicates 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 - true if should be visible, false if 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.IOException
        Writes a double as eight bytes to a file.
        Parameters:
        data - Data to be written to file.
        endianess - true indicates big endian byte order, false indicates 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.IOException
        Writes a float as four bytes to a file.
        Parameters:
        data - Data to be written to file.
        endianess - true indicates big endian byte order, false indicates 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.IOException
        Writes an int as four bytes to a file.
        Parameters:
        data - Data to be written to file.
        endianess - true indicates big endian byte order, false indicates 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.IOException
        Writes a long as eight bytes to a file.
        Parameters:
        data - Data to be written to file.
        endianess - true indicates big endian byte order, false indicates 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.IOException
        Writes a short as two bytes to a file.
        Parameters:
        data - Data to be written to file.
        endianess - true indicates big endian byte order, false indicates 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.IOException
        Writes an unsigned short as two bytes to a file.
        Parameters:
        data - Data to be written to file.
        endianess - true indicates big endian byte order, false indicates little endian.
        Throws:
        java.io.IOException - if there is an error writing the file
      • writeByte

        public final void writeByte​(byte data)
                             throws java.io.IOException
        Writes 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.