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 class
FileMincHDF.HDFNode
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ATTR_DIM_ALIGNMENT
static java.lang.String
ATTR_DIM_DIRECTION_COSINES
static java.lang.String
ATTR_DIM_LENGTH
static java.lang.String
ATTR_DIM_SPACETYPE
static java.lang.String
ATTR_DIM_START
static java.lang.String
ATTR_DIM_STEP
static java.lang.String
ATTR_DIM_UNITS
static java.lang.String
ATTR_IMAGE_DIM_ORDER
static java.lang.String
ATTR_IMAGE_VALID_RANGE
static java.lang.String
ATTR_INFO_SLICE_THICKNESS
static java.lang.String
ATTR_INFO_STUDY_MODALITY
static java.lang.String
DICOM_ELEMENT_PREFIX
static java.lang.String
DICOM_GROUP_PREFIX
private java.lang.String[]
dimOrder
The ordering of the dimensions.private int[]
dimReorderIndexes
private java.lang.String[]
dimStrings
private java.lang.String[]
dimStringsReordered
private double[][]
dirCosines
direction cosines matrixprivate java.lang.String
fileDir
The directory containing the minc file being written out or read in.private ncsa.hdf.object.FileFormat
fileFormat
will always use the HDF5 fileformatprivate FileInfoMincHDF
fileInfo
private java.lang.String
fileName
The name of the minc file to be read in or written out.private ncsa.hdf.object.h5.H5File
h5File
the file to be read/writtenprivate javax.swing.tree.DefaultMutableTreeNode
imageNode
the image node of the HDF file tree that contains the image data, and min max per slice informationprivate boolean
is4D
private boolean[]
isCentered
whether each axis is centeredstatic java.lang.String
LEAF_ACQUISITION
static java.lang.String
LEAF_IMAGE
static java.lang.String
LEAF_IMAGE_MAX
static java.lang.String
LEAF_IMAGE_MIN
static java.lang.String
LEAF_PATIENT
static java.lang.String
LEAF_PROCESSING
static java.lang.String
LEAF_STUDY
static java.lang.String
LEAF_T_SPACE
static java.lang.String
LEAF_X_SPACE
static java.lang.String
LEAF_Y_SPACE
static java.lang.String
LEAF_Z_SPACE
private double[]
mincStartLoc
static java.lang.String
NODE_DIMENSIONS
static java.lang.String
NODE_IMAGE
static java.lang.String
NODE_INFO
private double[]
step
MINC 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 void
buildDimensionNode(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 void
buildImageNode(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 void
buildInfoNode(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.DefaultMutableTreeNode
findNode(javax.swing.tree.DefaultMutableTreeNode nodeToSearch, java.lang.String nodeNameToFind)
Recursively finds the node within a tree with a given name.FileInfoMincHDF
getFileInfo()
Returns the FileInfoXML read from the file.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.static FileInfoBase.Unit
getUnitFromString(java.lang.String val)
Return the proper unit based on a given unit string (abbrevation or full word).private void
parseDims(javax.swing.tree.DefaultMutableTreeNode dimensionNode)
Determines the dimensions, dirCosines, isCentered, step, and alignmentprivate void
parseHDFHeader(javax.swing.tree.DefaultMutableTreeNode node)
recursively parses the HDF tree into the given file infoprivate ModelImage
parseImage(javax.swing.tree.DefaultMutableTreeNode iNode)
Parses the image node and reads in the image data (and image min and max per slice)private void
parseImageDimOrder(javax.swing.tree.DefaultMutableTreeNode rootNode)
parses the dim orderprivate void
parseInfo(javax.swing.tree.DefaultMutableTreeNode infoNode)
Parses the info node (right now only grabs the modality)boolean
readHeader(javax.swing.tree.DefaultMutableTreeNode rootNode)
ModelImage
readImage(boolean one)
Reads a MINC 2.0 HDF-5 filevoid
writeImage(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.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 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.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 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.
-
-