Class FileMincHDF


  • public class FileMincHDF
    extends FileBase
    HDF5 based reader/writer for MINC 2.0 Currently, for the image max and image min nodes: in the case of 3d images in which 1 image min and 1 image max is to be written out per slice, the dimorder is hardcoded to zspace. Sometimes minc2 3D images come in with just 1 image min and 1 image max per volume...in that case, we write out the same way and do not write out a dimorder ToDo: We need to make this type of functionality work for 4D images. Currently the code writes out 1 image min nd 1 image max per slice and hardcode the dimorder to time,zspace. We need to write out the same way we read in....yet to do.
    Author:
    linkb
    • Field Detail

      • LEAF_ACQUISITION

        public static final java.lang.String LEAF_ACQUISITION
        See Also:
        Constant Field Values
      • ATTR_DIM_DIRECTION_COSINES

        public static final java.lang.String ATTR_DIM_DIRECTION_COSINES
        See Also:
        Constant Field Values
      • ATTR_DIM_SPACETYPE

        public static final java.lang.String ATTR_DIM_SPACETYPE
        See Also:
        Constant Field Values
      • ATTR_DIM_ALIGNMENT

        public static final java.lang.String ATTR_DIM_ALIGNMENT
        See Also:
        Constant Field Values
      • ATTR_IMAGE_DIM_ORDER

        public static final java.lang.String ATTR_IMAGE_DIM_ORDER
        See Also:
        Constant Field Values
      • ATTR_IMAGE_VALID_RANGE

        public static final java.lang.String ATTR_IMAGE_VALID_RANGE
        See Also:
        Constant Field Values
      • ATTR_INFO_STUDY_MODALITY

        public static final java.lang.String ATTR_INFO_STUDY_MODALITY
        See Also:
        Constant Field Values
      • ATTR_INFO_SLICE_THICKNESS

        public static final java.lang.String ATTR_INFO_SLICE_THICKNESS
        See Also:
        Constant Field Values
      • DICOM_GROUP_PREFIX

        public static java.lang.String DICOM_GROUP_PREFIX
      • DICOM_ELEMENT_PREFIX

        public static java.lang.String DICOM_ELEMENT_PREFIX
      • imageNode

        private javax.swing.tree.DefaultMutableTreeNode imageNode
        the image node of the HDF file tree that contains the image data, and min max per slice information
      • dimStringsReordered

        private java.lang.String[] dimStringsReordered
      • dimStrings

        private java.lang.String[] dimStrings
      • step

        private double[] step
        MINC resolution (can be negative)
      • stepReordered

        private double[] stepReordered
      • dirCosines

        private double[][] dirCosines
        direction cosines matrix
      • isCentered

        private boolean[] isCentered
        whether each axis is centered
      • mincStartLoc

        private double[] mincStartLoc
      • fileDir

        private final java.lang.String fileDir
        The directory containing the minc file being written out or read in.
      • fileName

        private final java.lang.String fileName
        The name of the minc file to be read in or written out.
      • dimOrder

        private java.lang.String[] dimOrder
        The ordering of the dimensions. Should be found in the image node attributes.
      • fileFormat

        private final ncsa.hdf.object.FileFormat fileFormat
        will always use the HDF5 fileformat
      • h5File

        private ncsa.hdf.object.h5.H5File h5File
        the file to be read/written
      • dimReorderIndexes

        private int[] dimReorderIndexes
      • is4D

        private boolean is4D
    • Constructor Detail

      • FileMincHDF

        public FileMincHDF​(java.lang.String fName,
                           java.lang.String fDir)
                    throws java.io.IOException
        MINC reader/writer constructor.
        Parameters:
        fName - File name.
        fDir - File directory.
        Throws:
        java.io.IOException - if there is an error constructing the files
    • Method Detail

      • readHeader

        public boolean readHeader​(javax.swing.tree.DefaultMutableTreeNode rootNode)
                           throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getFileInfo

        public FileInfoMincHDF getFileInfo()
        Returns the FileInfoXML read from the file.
        Returns:
        File info read from file, or null if it has not been read.
      • parseHDFHeader

        private void parseHDFHeader​(javax.swing.tree.DefaultMutableTreeNode node)
                             throws java.lang.Exception
        recursively parses the HDF tree into the given file info
        Parameters:
        node -
        fileInfo -
        Throws:
        java.lang.Exception
      • findNode

        private static final javax.swing.tree.DefaultMutableTreeNode findNode​(javax.swing.tree.DefaultMutableTreeNode nodeToSearch,
                                                                              java.lang.String nodeNameToFind)
        Recursively finds the node within a tree with a given name.
        Parameters:
        nodeToSearch - the root node of the tree to search
        nodeNameToFind - the name of the node to find
        Returns:
        a node with the name given, or null if no node was found within the given tree
      • parseImageDimOrder

        private void parseImageDimOrder​(javax.swing.tree.DefaultMutableTreeNode rootNode)
                                 throws java.lang.Exception
        parses the dim order
        Parameters:
        rootNode -
        Throws:
        java.lang.Exception
      • parseDims

        private void parseDims​(javax.swing.tree.DefaultMutableTreeNode dimensionNode)
                        throws java.lang.Exception
        Determines the dimensions, dirCosines, isCentered, step, and alignment
        Parameters:
        dimensionNode -
        fileInfo -
        Throws:
        java.lang.Exception
      • parseInfo

        private void parseInfo​(javax.swing.tree.DefaultMutableTreeNode infoNode)
                        throws java.lang.Exception
        Parses the info node (right now only grabs the modality)
        Parameters:
        infoNode -
        fileInfo -
        Throws:
        java.lang.Exception
      • parseImage

        private ModelImage parseImage​(javax.swing.tree.DefaultMutableTreeNode iNode)
                               throws java.lang.Exception
        Parses the image node and reads in the image data (and image min and max per slice)
        Parameters:
        iNode -
        fileInfo -
        Returns:
        Throws:
        java.lang.Exception
      • readImage

        public ModelImage readImage​(boolean one)
                             throws java.lang.Exception
        Reads a MINC 2.0 HDF-5 file
        Parameters:
        one -
        Returns:
        the image
        Throws:
        java.lang.Exception
      • buildDimensionNode

        private void buildDimensionNode​(ModelImage image,
                                        FileWriteOptions options,
                                        ncsa.hdf.object.FileFormat format,
                                        FileMincHDF.HDFNode mincNode,
                                        javax.swing.tree.DefaultTreeModel model)
                                 throws java.lang.Exception
        Creates the dimension node for files that are not Minc2.0
        Parameters:
        image -
        format -
        mincNode -
        model -
        Throws:
        java.lang.Exception
      • buildInfoNode

        private void buildInfoNode​(ModelImage image,
                                   ncsa.hdf.object.FileFormat format,
                                   FileMincHDF.HDFNode mincNode,
                                   javax.swing.tree.DefaultTreeModel model)
                            throws java.lang.Exception
        builds the Info node for files that were not originally MINC 2.0 HDF5
        Parameters:
        image -
        format -
        mincNode -
        model -
        Throws:
        java.lang.Exception
      • buildImageNode

        private void buildImageNode​(ModelImage image,
                                    FileWriteOptions options,
                                    ncsa.hdf.object.FileFormat format,
                                    FileMincHDF.HDFNode mincNode,
                                    javax.swing.tree.DefaultTreeModel model)
                             throws java.lang.Exception
        Builds the image node (done for all filetypes when writing to MINC2.0 HDF5
        Parameters:
        image - the image node
        format - the HDF5 FileFormat
        mincNode - the minc root node
        model - the tree model linked to the root node
        Throws:
        java.lang.Exception
      • writeImage

        public void writeImage​(ModelImage image,
                               FileWriteOptions options)
                        throws java.lang.Exception
        Writes a MINC format type image. Calls the appropriate header method.
        Parameters:
        image - Image model where the data is stored.
        options - Information about how to write this file.
        Throws:
        java.io.IOException - if there is an error writing the file
        java.lang.Exception
        See Also:
        FileInfoMinc, FileMinc
      • getMipavOrderFromDimNode

        private int getMipavOrderFromDimNode​(java.lang.String dimNodeStr)
        Gets the proper MIPAV dimension ordering index for a given Minc dim node string using the image info.
        Parameters:
        dimNodeStr - A minc dimension node string (i.e., xspace, yspace, zspace, time).
        Returns:
        The proper MIPAV dimension ordering index.
      • getUnitFromString

        public static final FileInfoBase.Unit getUnitFromString​(java.lang.String val)
        Return the proper unit based on a given unit string (abbrevation or full word).
        Parameters:
        val - The unit name or abbreviation.
        Returns:
        The proper unit for the given string, or Unit.UNKNOWN_MEASURE if not recognized.