Class SoVRDicomFileReader

  • All Implemented Interfaces:

    public class SoVRDicomFileReader
    extends SoVolumeReader
    DICOM file reader. Volume reader for the DICOM file format. VolumeViz automatically selects this reader if a filename is given and the file extension is ".dc3", ".dic", ".dcm", or ".dicom".

    DICOM is a widely used format for storing medical image data (CT, MRI, etc), defined by the National Electrical Manufacturers Association (NEMA) (

    SoVRDicomFileReader can load a volume from a single DICOM file or from a list of DICOM files (stack of images). Loading a volume from a single DICOM file is the same as loading any other format supported by VolumeViz (see setFilename(const String& filename)). Loading a volume from a list of DICOM files can be done by:

    Unlike a raster stack, the position of each slice in a DICOM volume is determined by the location value in its file header and not by the order of the file name in the list. Also unlike a raster stack consisting of (for example) JPEG or PNG images, a DICOM file in the list may contain more than one slice of the volume. The reader handles this automatically. The first file in the list is considered the "reference" for the volume and all slices must be compatible with this one. Specifically this means that subsequent files must have the same width, height, data type and so on.

    Note when using a list file: If the file extension is not ".dc3", ".dic" or ".dicom" VolumeViz will not automatically select the DICOM volume reader. You can either give the list file one of the DICOM file extensions or force VolumeViz to use the DICOM reader by explicitly creating an instance of SoVRDicomFileReader and calling the SoVolumeData method setReader().

    The volume reader will automatically get the volume dimensions, data type, extent (voxel size/spacing) and number of significant bits from the DICOM file header. The reader will also apply the data adjustment (if any) specified by the RescaleSlope and RescaleIntercept tags in the DICOM file header, i.e.: actualValue = slope * storedValue + intercept. As part of this process the reader will automatically convert unsigned data to the corresponding signed data type if necessary (in other words if the rescale calculation produces negative values). The application can also explicitly specify the volume data type. This allows, for example, converting float data values to more compact integer values.
    Note: The DICOM reader only uses the rescale slope and intercept values from the first file in the list. It does not currently handle the (less common) case where each file contains different rescale values.

    Photometric Interpretation:

    • MONOCHROME1 : Mapping of data values to color and opacity is defined by the SoDataRange and SoTransferFunction nodes. The application will normally use the DICOM Window Center and Window Width values to set the SoDataRange. For SoTransferFunction the application can use the predefined light to dark color map INTENSITY_REVERSED for displaying single images.
    • MONOCHROME2 : Mapping of data values to color and opacity is defined by the SoDataRange and SoTransferFunction nodes. The application will normally use the DICOM Window Center and Window Width values to set the SoDataRange. For SoTransferFunction the application can use the predefined dark to light color map INTENSITY for displaying single images.
    • PALETTE COLOR : The reader converts the data values to RGBA values using the palette lookup tables in the DICOM file and alpha = 1 (opaque). SoDataRange and SoTransferFunction have no effect on an RGBA volume.
    • RGB : The reader converts the RGB values to RGBA values with alpha = 1 (opaque). SoDataRange and SoTransferFunction have no effect on an RGBA volume.

    Volume extent:

    The volume reader will compute the volume's width in X and height in Y from the volume dimensions and the voxel size. For example, if the volume dimension in X is 512 (voxels) and the voxel size in X is 0.408 mm, then the volume width is (approximately) 209 mm. The reader will compute the volume's depth in Z from the min and max slice locations specified in the file header(s). Note that for a DICOM data set, the volume 'position' is considered to be the center of the first voxel, however VolumeViz considers the volume extent (SoVolumeData.extent) to include all of the first and last voxels. Therefore the extent 'min' is alwaya the outside corner of the first voxel.

    NOTE: By default, the reader does not consider the DICOM volume origin (Image Position Patient attribute) when setting the volume extent. The volume extent set by the reader is always centered at 0,0,0 in 3D world coordinates. There are two options to get the volume correctly positioned in 3D space:

    • Call the MedicalHelper method dicomAdjustVolume() after setting the files to be loaded. (Recommended)
    • Set the preference variable VOLUMEVIZ_CENTERED_DICOM to false (default is true).

    Data Range:

    Use an SoDataRange node to specify the actual (or desired) range of data values to be mapped. For example, a typical initial data range for DICOM data calibrated in Hounsfield units might be -1000 to 3000.

    NOTE: By default, VolumeViz does not use the Window Center and Window Width values (if any) in the DICOM image file. Instead it maps the entire range of the voxel's data type (e.g. 0..65535 for unsigned short) into the colormap. There are two options to use the data range specified in the image file:

    • Call the MedicalHelper method dicomAdjustDataRange(). (Recommended)
    • Query the Window Center and Window Width values using the MedicalHelper method getWindowCenterWidth().
    • Query the Window Center (0028,1050) and Window Width (0028,1051) values using using an SoVRDicomData object (see getDicomData()) or an SiDicomDataSet object (see getDicomDataSet()).

    Coordinate Systems:

    In a medical imaging application there are at least three related coordinate systems.

    • 3D world coordinates:
      Also called XYZ coordinates. This is the Cartesian coordinate system in which rendering objects (volumes, geometry), cameras, lights, etc. are positioned. In Open Inventor this is a right-handed coordinate system (same as OpenGL). The default camera creates a view look down the Z axis, i.e. +Z is toward the user, +X is to the right and +Y is up.
    • Voxel coordinates:
      Also called "IJK" coordinates. Each voxel's position in the volume can be described by an IJK coordinate. In VolumeViz this is also a right-handed coordinate system, corresponding to the positive XYZ axes, i.e. in the default camera's view K is toward the user, I is to the right and J is up. You can convert between IJK and XYZ coordinates based on the volume dimensions and extent or use the conversion methods provided in the SoVolumeData class, e.g. voxelToXYZ().
    • Anatomical coordinates: The three standard viewing planes are Axial, Coronal and Sagittal. The Axial plane divides the body into Superior (head) and Inferior (foot) sections. The Coronal plane is a vertical plane dividing the body into Anterior (front) and Posterior (back) sections. The Sagittal plane divides the body longitudinally into Right and Left sections. The orientation of the patient in a medical data set is often specified using three letters to identify the primary axes, where each letter is one of the section names. DICOM volumes typically have LPS (Left, Posterior, Superior) orientation. In this case VolumeViz considers that the direction:
      • Toward the left side of the body (Left) is the I / +X / Sagittal axis,
      • Toward the back of the body (Posterior) is the J / +Y / Coronal axis, and
      • Toward the head (Superior) is the K / +Z / Axial axis.

      In other words, the default camera view is looking at the top of the head with the body "face down".

    NOTE: By default Open Inventor does not display DICOM images with the usual orientation. A convenient way to get the standard DICOM view orientations is to use the MedicalHelper method orientView(). This method is useful for orienting the camera to view along one of the standard medical axes (Axial, Coronal or Sagittal).

    When viewing a slice, also remember that the volume is always a 3D object to Open Inventor and you must also set the 'axis' field on the SoOrthoSlice node. See the dicomImageViewer example in the examples/source/Medical/Input directory.

    DICOM Attributes

    All DICOM attributes, including hierarchical data like Structured Reports, can be traversed and queried using SiDicomDataSet (see getDicomDataSet()). See the DicomSimpleViewer example in the examples/source/VolumeViz/examples directory.

    See Also:
    SoVRDicomData, SiDicomDataSet
    • Constructor Detail

      • SoVRDicomFileReader

        public SoVRDicomFileReader()
    • Method Detail

      • setFilenameList

        public boolean setFilenameList​(java.lang.String format,
                                       int startIndex,
                                       int endIndex)
        Calls setFilenameList(format, startIndex, endIndex, (int)1).
      • setFilenameList

        public boolean setFilenameList​(java.lang.String format)
        Calls setFilenameList(format, (int)0, Integer.MAX_VALUE, (int)1).
      • setFilenameList

        public boolean setFilenameList​(java.lang.String format,
                                       int startIndex)
        Calls setFilenameList(format, startIndex, Integer.MAX_VALUE, (int)1).
      • setFilenamePattern

        public int setFilenamePattern​(java.lang.String pattern)
        Specify a pattern of DICOM files to load.

        pattern - e.g. "data_directory/image_file*.dcm"

        0 if successful.

        Open Inventor 9.8

      • setDirectory

        public boolean setDirectory​(java.lang.String folder)
        Specify a directory containing DICOM files to load. Each file in this folder that has a supported extension (currently ".dc3", ".dic", ".dcm", or ".dicom") will be loaded. If the DICOM files have an unsupported extension, use the setFilenameList function instead.

        All the DICOM files in the specified directory should be part of the same volume data set. If not, the results are undefined.

        folder - The folder from which to load files.

        true if successful.

        Open Inventor 9.4.1

      • getDicomData

        public SoVRDicomData getDicomData()
        Returns an instance of SoVRDicomData for the first image of this volume. Note that the first image of the volume does not necessarily correspond to first file of file list. Images are automatically sorted using the Image Postion Patient attribute.

        This object can be queried for DICOM specific info, using for example the SoVRDicomData.getDicomInfo() method.

        To conveniently access the DICOM attributes, see getDicomDataSet() method.

      • getDicomDataSet

        public SiDicomDataSet getDicomDataSet​(long sliceIdx)
        Returns a DICOM data object for the specified slice containing all the DICOM attributes.

        sliceIdx - The index of the slice to extract the dataset from.

        A pointer to a new dataset object, that must be deleted by the application. Returns NULL if an error occured.

      • setFilenameList

        public boolean setFilenameList​(java.lang.String format,
                                       int startIndex,
                                       int endIndex,
                                       int indexStep)
        Specify a list of DICOM files to load, using a sprintf-like format. This will iterate from startIndex to endIndex (included) with increment of indexStep. For each step, this will add a file of name f, where f is format sprintf-ed with the current iteration index. All the specified files should be part of the same volume data set.

        format - The format of the file name, which must be an absolute file path.
        e.g. "c:/testData/Brain.%04d.dcm", where "%04d" will be replaced by the current index, producing "c:/testData/Brain.0000.dcm" and so on.

        startIndex - The index of the first file to add

        endIndex - The index of the last file to add

        indexStep - the stride to use (e.g. 2 will skip one out of two files, by generating indices 0, 2, 4, ...)

        true if successful.

        Open Inventor 9.4.1

      • setFilenameListFromSeries

        public boolean setFilenameListFromSeries​(java.lang.String base)
        Specify a DICOM file and load all image files in the same directory that are part of the same "series" based on the series UID (0x0020,0x000E).

        base - The path to a DICOM image file.

        true if successful.

      • loadInMemory

        public void loadInMemory()
        Load the DICOM data into contiguous memory if possible. Once the data is loaded, no additional file I/O is necessary and data access calls to the reader, e.g. getSubSlice(), will be fast.


        • This is a blocking call (does not return until all data is loaded).
        • It is not currently possible to directly access the data in memory.
        • It is not currently possible to monitor the progress of the data loading.
        • It is not currently possible to test if the data loading succeeded.
        • Do NOT call this method before setting the data source (filename or directory).
        • Do NOT call this method with an invalid data filename or directory.

        Open Inventor 10.3