Package gov.nih.mipav.model.file
Class FileMincHDF
- java.lang.Object
-
- gov.nih.mipav.model.file.FileBase
-
- gov.nih.mipav.model.file.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classFileMincHDF.HDFNode
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringATTR_DIM_ALIGNMENTstatic java.lang.StringATTR_DIM_DIRECTION_COSINESstatic java.lang.StringATTR_DIM_LENGTHstatic java.lang.StringATTR_DIM_SPACETYPEstatic java.lang.StringATTR_DIM_STARTstatic java.lang.StringATTR_DIM_STEPstatic java.lang.StringATTR_DIM_UNITSstatic java.lang.StringATTR_IMAGE_DIM_ORDERstatic java.lang.StringATTR_IMAGE_VALID_RANGEstatic java.lang.StringATTR_INFO_SLICE_THICKNESSstatic java.lang.StringATTR_INFO_STUDY_MODALITYstatic java.lang.StringDICOM_ELEMENT_PREFIXstatic java.lang.StringDICOM_GROUP_PREFIXprivate java.lang.String[]dimOrderThe ordering of the dimensions.private int[]dimReorderIndexesprivate java.lang.String[]dimStringsprivate java.lang.String[]dimStringsReorderedprivate double[][]dirCosinesdirection cosines matrixprivate java.lang.StringfileDirThe directory containing the minc file being written out or read in.private ncsa.hdf.object.FileFormatfileFormatwill always use the HDF5 fileformatprivate FileInfoMincHDFfileInfoprivate java.lang.StringfileNameThe name of the minc file to be read in or written out.private ncsa.hdf.object.h5.H5Fileh5Filethe file to be read/writtenprivate javax.swing.tree.DefaultMutableTreeNodeimageNodethe image node of the HDF file tree that contains the image data, and min max per slice informationprivate booleanis4Dprivate boolean[]isCenteredwhether each axis is centeredstatic java.lang.StringLEAF_ACQUISITIONstatic java.lang.StringLEAF_IMAGEstatic java.lang.StringLEAF_IMAGE_MAXstatic java.lang.StringLEAF_IMAGE_MINstatic java.lang.StringLEAF_PATIENTstatic java.lang.StringLEAF_PROCESSINGstatic java.lang.StringLEAF_STUDYstatic java.lang.StringLEAF_T_SPACEstatic java.lang.StringLEAF_X_SPACEstatic java.lang.StringLEAF_Y_SPACEstatic java.lang.StringLEAF_Z_SPACEprivate double[]mincStartLocstatic java.lang.StringNODE_DIMENSIONSstatic java.lang.StringNODE_IMAGEstatic java.lang.StringNODE_INFOprivate double[]stepMINC resolution (can be negative)private double[]stepReordered-
Fields inherited from class gov.nih.mipav.model.file.FileBase
BIG_ENDIAN, bitsPerPixel, fileNames, LITTLE_ENDIAN, pBarVisible, raFile, READ, READ_WRITE
-
-
Constructor Summary
Constructors Constructor Description FileMincHDF(java.lang.String fName, java.lang.String fDir)MINC reader/writer constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidbuildDimensionNode(ModelImage image, FileWriteOptions options, ncsa.hdf.object.FileFormat format, FileMincHDF.HDFNode mincNode, javax.swing.tree.DefaultTreeModel model)Creates the dimension node for files that are not Minc2.0private voidbuildImageNode(ModelImage image, FileWriteOptions options, ncsa.hdf.object.FileFormat format, FileMincHDF.HDFNode mincNode, javax.swing.tree.DefaultTreeModel model)Builds the image node (done for all filetypes when writing to MINC2.0 HDF5private voidbuildInfoNode(ModelImage image, ncsa.hdf.object.FileFormat format, FileMincHDF.HDFNode mincNode, javax.swing.tree.DefaultTreeModel model)builds the Info node for files that were not originally MINC 2.0 HDF5private static javax.swing.tree.DefaultMutableTreeNodefindNode(javax.swing.tree.DefaultMutableTreeNode nodeToSearch, java.lang.String nodeNameToFind)Recursively finds the node within a tree with a given name.FileInfoMincHDFgetFileInfo()Returns the FileInfoXML read from the file.private intgetMipavOrderFromDimNode(java.lang.String dimNodeStr)Gets the proper MIPAV dimension ordering index for a given Minc dim node string using the image info.static FileInfoBase.UnitgetUnitFromString(java.lang.String val)Return the proper unit based on a given unit string (abbrevation or full word).private voidparseDims(javax.swing.tree.DefaultMutableTreeNode dimensionNode)Determines the dimensions, dirCosines, isCentered, step, and alignmentprivate voidparseHDFHeader(javax.swing.tree.DefaultMutableTreeNode node)recursively parses the HDF tree into the given file infoprivate ModelImageparseImage(javax.swing.tree.DefaultMutableTreeNode iNode)Parses the image node and reads in the image data (and image min and max per slice)private voidparseImageDimOrder(javax.swing.tree.DefaultMutableTreeNode rootNode)parses the dim orderprivate voidparseInfo(javax.swing.tree.DefaultMutableTreeNode infoNode)Parses the info node (right now only grabs the modality)booleanreadHeader(javax.swing.tree.DefaultMutableTreeNode rootNode)ModelImagereadImage(boolean one)Reads a MINC 2.0 HDF-5 filevoidwriteImage(ModelImage image, FileWriteOptions options)Writes a MINC format type image.-
Methods inherited from class gov.nih.mipav.model.file.FileBase
addProgressChangeListener, bytesToDouble, bytesToFloat, bytesToInt, bytesToShort, doubleToBytes, finalize, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, floatToBytes, getBufferDouble, getBufferFloat, getBufferInt, getBufferLong, getBufferShort, getBufferUShort, getDataType, getDouble, getFloat, getInt, getLong, getProgressChangeListeners, getRaFile, getSignedShort, getString, getUInt, getUnsignedByte, getUnsignedShort, intToBytes, isBigEndian, isProgressBarVisible, linkProgress, longToBytes, readDouble, readFloat, readInt, readLong, readShort, readString, readUnsignedShort, removeProgressChangeListener, setBigEndian, setBufferFloat, setBufferInt, setBufferLong, setBufferShort, setBufferString, setDataType, setEndianess, shortToBytes, writeBytes, writeDouble, writeFloat, writeInt, writeLong, writeShort
-
-
-
-
Field Detail
-
NODE_DIMENSIONS
public static final java.lang.String NODE_DIMENSIONS
- See Also:
- Constant Field Values
-
NODE_IMAGE
public static final java.lang.String NODE_IMAGE
- See Also:
- Constant Field Values
-
NODE_INFO
public static final java.lang.String NODE_INFO
- See Also:
- Constant Field Values
-
LEAF_IMAGE
public static final java.lang.String LEAF_IMAGE
- See Also:
- Constant Field Values
-
LEAF_IMAGE_MAX
public static final java.lang.String LEAF_IMAGE_MAX
- See Also:
- Constant Field Values
-
LEAF_IMAGE_MIN
public static final java.lang.String LEAF_IMAGE_MIN
- See Also:
- Constant Field Values
-
LEAF_X_SPACE
public static final java.lang.String LEAF_X_SPACE
- See Also:
- Constant Field Values
-
LEAF_Y_SPACE
public static final java.lang.String LEAF_Y_SPACE
- See Also:
- Constant Field Values
-
LEAF_Z_SPACE
public static final java.lang.String LEAF_Z_SPACE
- See Also:
- Constant Field Values
-
LEAF_T_SPACE
public static final java.lang.String LEAF_T_SPACE
- See Also:
- Constant Field Values
-
LEAF_ACQUISITION
public static final java.lang.String LEAF_ACQUISITION
- See Also:
- Constant Field Values
-
LEAF_PATIENT
public static final java.lang.String LEAF_PATIENT
- See Also:
- Constant Field Values
-
LEAF_PROCESSING
public static final java.lang.String LEAF_PROCESSING
- See Also:
- Constant Field Values
-
LEAF_STUDY
public static final java.lang.String LEAF_STUDY
- See Also:
- Constant Field Values
-
ATTR_DIM_UNITS
public static final java.lang.String ATTR_DIM_UNITS
- See Also:
- Constant Field Values
-
ATTR_DIM_START
public static final java.lang.String ATTR_DIM_START
- See Also:
- Constant Field Values
-
ATTR_DIM_LENGTH
public static final java.lang.String ATTR_DIM_LENGTH
- 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_STEP
public static final java.lang.String ATTR_DIM_STEP
- 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
-
fileInfo
private final FileInfoMincHDF fileInfo
-
dimReorderIndexes
private int[] dimReorderIndexes
-
is4D
private boolean is4D
-
-
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.Exceptionrecursively 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 searchnodeNameToFind- 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.Exceptionparses the dim order- Parameters:
rootNode-- Throws:
java.lang.Exception
-
parseDims
private void parseDims(javax.swing.tree.DefaultMutableTreeNode dimensionNode) throws java.lang.ExceptionDetermines 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.ExceptionParses 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 nodeformat- the HDF5 FileFormatmincNode- the minc root nodemodel- 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 filejava.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.
-
-