Package gov.nih.mipav.model.file
Class FileImageXML
- java.lang.Object
-
- gov.nih.mipav.model.file.FileBase
-
- gov.nih.mipav.model.file.FileXML
-
- gov.nih.mipav.model.file.FileImageXML
-
public class FileImageXML extends FileXML
File class for reading/writing Image.XML file headers and their associated images. The XML reader uses the image.xsd schema for parsing. Inherits from FileXML, which parses the image.xml file based on the image.xsd
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
FileImageXML.LUValue
Stores LUT information (red, green, blue, alpha).private class
FileImageXML.MyXMLHandler
Used by the XML Parser to parse the xml header.class
FileImageXML.Thumbnail
Holds an AWT Image and an int[] array of data for an XML Thumbnail image the thumbnail is stored in the XML's header so that it may be read in independently from the actual image data. when an XML file is saved, the user has the option to also saved a reduced resolution (max 64x64) image into the XML's header using standard XML tagging-
Nested classes/interfaces inherited from class gov.nih.mipav.model.file.FileXML
FileXML.XMLAttributes
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Enumeration<XMLPSet>
additionalSets
A listing of all the additionalPSets
to be written into the saved file.private java.util.Vector<VOI>
annotationVector
DOCUMENT ME!private double[]
bValues
private java.lang.String[]
dataFileName
private static java.lang.String[]
datasetAttributesStr
array of strings representing the tags underin the xml schema. private DTIParameters
dtiparams
private int
functionIndex
Index of LUT function when reading xml header.private java.util.Vector<WildMagic.LibFoundation.Mathematics.Vector2f>
functionVector
Vector to store the LUT functions when reading xml header.private double[][]
gradients
private ModelImage
image
Model Image associated with the file.private java.lang.String
imageFileName
Name of the RAW (or IMG) file associated with the XML header.private static java.lang.String[]
imageStr
array of strings representing the tags underin the xml schema. private static java.lang.String[]
investigatorsStr
array of strings representing the tags underin the xml schema. private java.lang.String
linkedFilename
Name of the file linked to this file (separate from fileName).private ModelLUT
LUT
Lookup Table associated with the file (grayscale).private java.util.Vector<FileImageXML.LUValue>
lutVector
Vector to store LUT values when reading xml header.private java.util.Vector<TransMatrix>
matrixVector
Vector to hold matrices while they are being read in for the header (until they are added to the imageprivate ModelRGB
modelRGB
RGB lookup table associated with the file.private int
numVolumes
private static java.lang.String[]
parameterStr
array of strings representing the tags underin the xml schema. private java.lang.String
rawExtension
The extension to give to the RAW file associated with the XML header.private static java.lang.String[]
scanAttributesStr
array of strings representing the tags underin the xml schema. private static java.lang.String[]
setStr
array of strings representing the tags underin the xml schema. private static java.lang.String[]
subjectInformationStr
array of strings representing the tags underin the xml schema. private static java.lang.String[]
surfaceStr
array of strings representing the tags underin the xml schema. private FileImageXML.Thumbnail
thumbnail
Thumbnail data and AWT Image.private static java.lang.String[]
voiStr
array of strings representing the tags underin the xml schema. -
Fields inherited from class gov.nih.mipav.model.file.FileXML
bw, fileDir, fileInfo, fileName, m_kHandler, MIPAV_HEADER, pInterface, TAB, tabLevel, W3C_XML_SCHEMA, XML_ENCODING, XML_HEADER
-
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 FileImageXML(java.lang.String fName, java.lang.String fDir)
Constructs new file object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addFunctionToLUT()
Adds the LUT functions collected within the functionVector.private void
addFunctionToRGB()
Adds the ModelRGB functions contained within the functionVector.private void
addLUValue(java.lang.String s)
Adds LUValue for either LUT or modelRGB.private void
addPointToFunction(java.lang.String s)
Adds a point to the function associated with the LUT or modelRGB.void
clearAdditionalSets()
Convenience method to clear any additional sets of the enumerated list that might be written into the header file.void
finalize()
Prepares class for cleanup.static void
flipTopBottom(float[] buffer, FileInfoImageXML xmlInfo)
Flips image.static void
flipTopBottom(ModelImage img)
Flips image.java.util.Enumeration<XMLPSet>
getAdditionalSets()
Returns the enumerated list of additional sets to be written into the header file.java.lang.String[]
getDataFileName()
Accessor that returns the array of data file namesFileInfoImageXML
getFileInfo()
Returns the FileInfoXML read from the file.private java.lang.String
getFormattedThumbnailLine(int[] data, int index)
Returns a String for writing the thumbnail data (r,g,b) to the XML header.private byte[]
getFullBuffer(java.io.InputStream in, byte[] buff, int off, int fullBufferSize)
ModelLUT
getModelLUT()
Gets the LUT.ModelRGB
getModelRGB()
Gets the modelRGB.private static int
getOffset(FileInfoImageXML xmlInfo)
Helper method to calculate the offset for getting only the middle analyze image slice from the 3D file.FileImageXML.Thumbnail
getThumbnail()
Returns the thumbnail associated with the xml file (saved in header).float[][]
readHeader(java.lang.String headerFileName, java.lang.String headerDir, TalairachTransformInfo talairach)
Reads and parses an XML header.ModelImage
readImage(boolean one)
Reads an XML image file by reading the XML header then making a FileRaw to read the image for all filenames in the file list.void
readImage(float[] buffer)
Reads an XML image file by reading the header then making a FileRaw to read the file.void
setAdditionalSets(java.util.Enumeration<XMLPSet> moreSets)
Method to replace the enumerated list of additional sets to be written into the header file.void
setFileName(java.lang.String fName)
Accessor to set the file name (used when reading XML multiFile).private void
setLUT()
Sets up the LUT based on the values read into the lutVector.void
setModelLUT(ModelLUT lut)
Sets the model LUT.void
setModelRGB(ModelRGB modelRGB)
Sets the model RGB.void
setRawExtension(java.lang.String ext)
Changes the extension of the image data file associated with this XML header.private void
setRGB()
sets up the model RGB while parsing XML header after all LUValues have been saved in the LUT vector.void
setThumbnailData(int xDim, int yDim, int[] data)
Sets the thumbnail data (array of shorts).private void
updateOriginInfo(FileInfoImageXML[] xmlInfo)
Updates the start locations.boolean
writeHeader(ModelImage img, FileWriteOptions options, java.lang.String headerName, java.lang.String headerDir, boolean changeDims)
Writes the XML header information out to the given filename and path.private void
writeHeader3DTo2D(ModelImage img, java.lang.String headerName, java.lang.String headerDir, FileWriteOptions options)
Method to save off the header from a 4D image into 3D header files sequentially named (similar to the method in FileRaw).private void
writeHeader4DTo3D(ModelImage img, java.lang.String headerName, java.lang.String headerDir, FileWriteOptions options)
Method to save off the header from a 4D image into 3D header files sequentially named (similar to the method in FileRaw).void
writeImage(ModelImage img, FileWriteOptions options)
Writes an XML image with the given options.private void
writeSet(java.io.BufferedWriter bw, java.util.Enumeration<XMLPSet> setEnum)
writeSet
is a helper method, to allow writing set data out to theBufferedWriter
with any enumeration.-
Methods inherited from class gov.nih.mipav.model.file.FileXML
closedTag, closedTag, closedTag, openTag, readHeader, setPBar
-
Methods inherited from class gov.nih.mipav.model.file.FileBase
addProgressChangeListener, bytesToDouble, bytesToFloat, bytesToInt, bytesToShort, doubleToBytes, 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
-
imageStr
private static final java.lang.String[] imageStr
array of strings representing the tags underin the xml schema.
-
datasetAttributesStr
private static final java.lang.String[] datasetAttributesStr
array of strings representing the tags underin the xml schema.
-
subjectInformationStr
private static final java.lang.String[] subjectInformationStr
array of strings representing the tags underin the xml schema.
-
scanAttributesStr
private static final java.lang.String[] scanAttributesStr
array of strings representing the tags underin the xml schema.
-
investigatorsStr
private static final java.lang.String[] investigatorsStr
array of strings representing the tags underin the xml schema.
-
setStr
private static final java.lang.String[] setStr
array of strings representing the tags underin the xml schema.
-
parameterStr
private static final java.lang.String[] parameterStr
array of strings representing the tags underin the xml schema.
-
voiStr
private static final java.lang.String[] voiStr
array of strings representing the tags underin the xml schema.
-
surfaceStr
private static final java.lang.String[] surfaceStr
array of strings representing the tags underin the xml schema.
-
additionalSets
private java.util.Enumeration<XMLPSet> additionalSets
A listing of all the additionalPSets
to be written into the saved file.
-
annotationVector
private java.util.Vector<VOI> annotationVector
DOCUMENT ME!
-
functionIndex
private int functionIndex
Index of LUT function when reading xml header.
-
functionVector
private java.util.Vector<WildMagic.LibFoundation.Mathematics.Vector2f> functionVector
Vector to store the LUT functions when reading xml header.
-
matrixVector
private java.util.Vector<TransMatrix> matrixVector
Vector to hold matrices while they are being read in for the header (until they are added to the image
-
image
private ModelImage image
Model Image associated with the file.
-
imageFileName
private java.lang.String imageFileName
Name of the RAW (or IMG) file associated with the XML header.
-
linkedFilename
private java.lang.String linkedFilename
Name of the file linked to this file (separate from fileName).
-
LUT
private ModelLUT LUT
Lookup Table associated with the file (grayscale).
-
lutVector
private java.util.Vector<FileImageXML.LUValue> lutVector
Vector to store LUT values when reading xml header.
-
modelRGB
private ModelRGB modelRGB
RGB lookup table associated with the file.
-
rawExtension
private java.lang.String rawExtension
The extension to give to the RAW file associated with the XML header. May be changed to .img if the XML header links to an Analyze image (and will need to be flipped when the image is read back in).
-
thumbnail
private FileImageXML.Thumbnail thumbnail
Thumbnail data and AWT Image.
-
dataFileName
private java.lang.String[] dataFileName
-
dtiparams
private DTIParameters dtiparams
-
numVolumes
private int numVolumes
-
gradients
private double[][] gradients
-
bValues
private double[] bValues
-
-
Method Detail
-
flipTopBottom
public static final void flipTopBottom(ModelImage img) throws java.io.IOException
Flips image. Analyze stores its data "upside down". Used if reading in an XML header attached to an .img raw data file.- Parameters:
img
- Image to flip.- Throws:
java.io.IOException
- if there is a problem importing or exporting the image
-
flipTopBottom
public static final void flipTopBottom(float[] buffer, FileInfoImageXML xmlInfo)
Flips image. Analyze stores its data "upside down". Used if reading in an XML header attached to an .img raw data file.- Parameters:
buffer
- Buffer holding image to flip.xmlInfo
- File info structure for image to flip.
-
clearAdditionalSets
public void clearAdditionalSets()
Convenience method to clear any additional sets of the enumerated list that might be written into the header file.
-
getAdditionalSets
public java.util.Enumeration<XMLPSet> getAdditionalSets()
Returns the enumerated list of additional sets to be written into the header file.- Returns:
- the additional parameter sets that will be written out to the header
-
getFileInfo
public FileInfoImageXML getFileInfo()
Returns the FileInfoXML read from the file.- Returns:
- File info read from file, or null if it has not been read.
-
getModelLUT
public ModelLUT getModelLUT()
Gets the LUT.- Returns:
- ModelLUT the LUT
-
getModelRGB
public ModelRGB getModelRGB()
Gets the modelRGB.- Returns:
- ModelRGB the modelRGB
-
getThumbnail
public FileImageXML.Thumbnail getThumbnail()
Returns the thumbnail associated with the xml file (saved in header).- Returns:
- Thumbnail
-
getDataFileName
public java.lang.String[] getDataFileName()
Accessor that returns the array of data file names- Returns:
-
readHeader
public float[][] readHeader(java.lang.String headerFileName, java.lang.String headerDir, TalairachTransformInfo talairach) throws java.io.IOException
Reads and parses an XML header.- Parameters:
headerFileName
- file name of xml headerheaderDir
- directorytalairach
- the talairach transform info to fill out if contained within the header- Returns:
- double array containing resolutions (for setting resolutions per FileInfoImageXML)
- Throws:
java.io.IOException
- DOCUMENT ME!
-
readImage
public ModelImage readImage(boolean one) throws java.io.IOException, java.lang.OutOfMemoryError
Reads an XML image file by reading the XML header then making a FileRaw to read the image for all filenames in the file list. Only the one file directory (currently) supported.- Parameters:
one
- flag indicating one image of a 3D dataset should be read in.- Returns:
- The image.
- Throws:
java.io.IOException
- if there is an error reading the filejava.lang.OutOfMemoryError
- if there is a problem allocating memory for the image- See Also:
FileRaw
-
getFullBuffer
private byte[] getFullBuffer(java.io.InputStream in, byte[] buff, int off, int fullBufferSize)
-
readImage
public void readImage(float[] buffer) throws java.io.IOException, java.lang.OutOfMemoryError
Reads an XML image file by reading the header then making a FileRaw to read the file. Image data is left in buffer. If the fileInfo cannot be found, the header will be located and read first.- Parameters:
buffer
- Image buffer to store image data into. It is equal to the header length.- Throws:
java.io.IOException
- if there is an error reading the filejava.lang.OutOfMemoryError
- if there was a problem allocating enough memory- See Also:
FileRaw
-
setAdditionalSets
public void setAdditionalSets(java.util.Enumeration<XMLPSet> moreSets)
Method to replace the enumerated list of additional sets to be written into the header file. Any existing value is lost.- Parameters:
moreSets
- additional parameter sets to be written
-
setFileName
public void setFileName(java.lang.String fName)
Accessor to set the file name (used when reading XML multiFile).- Parameters:
fName
- file name of image to read.
-
setModelLUT
public void setModelLUT(ModelLUT lut)
Sets the model LUT.- Parameters:
lut
- ModelLUT the LUT
-
setModelRGB
public void setModelRGB(ModelRGB modelRGB)
Sets the model RGB.- Parameters:
modelRGB
- ModelRGB the modelRGB
-
setRawExtension
public void setRawExtension(java.lang.String ext)
Changes the extension of the image data file associated with this XML header.- Parameters:
ext
- the new file extension (such as .img)
-
setThumbnailData
public void setThumbnailData(int xDim, int yDim, int[] data)
Sets the thumbnail data (array of shorts).- Parameters:
xDim
- the buffer length in the x dimensionyDim
- the buffer length in the y dimensiondata
- the thumbnail data
-
writeHeader
public boolean writeHeader(ModelImage img, FileWriteOptions options, java.lang.String headerName, java.lang.String headerDir, boolean changeDims) throws java.io.IOException
Writes the XML header information out to the given filename and path.- Parameters:
img
- image associated with headeroptions
- the options to use when writing out the fileheaderName
- file name to write toheaderDir
- name of directory to write tochangeDims
- if true indicates that the image is changing dimensionality (e.g., 3D to 2D)- Returns:
- if header write was successful
- Throws:
java.io.IOException
- if a file I/O problem is encoutered while writing the header
-
writeImage
public void writeImage(ModelImage img, FileWriteOptions options) throws java.io.IOException
Writes an XML image with the given options.- Parameters:
img
- Model image to be written to diskoptions
- tells how and where to save file- Throws:
java.io.IOException
- if there is a problem writing to the file
-
getOffset
private static int getOffset(FileInfoImageXML xmlInfo)
Helper method to calculate the offset for getting only the middle analyze image slice from the 3D file.- Parameters:
xmlInfo
- File info.- Returns:
- offset
-
addFunctionToLUT
private void addFunctionToLUT()
Adds the LUT functions collected within the functionVector.
-
addFunctionToRGB
private void addFunctionToRGB()
Adds the ModelRGB functions contained within the functionVector.
-
addLUValue
private void addLUValue(java.lang.String s)
Adds LUValue for either LUT or modelRGB.- Parameters:
s
- String
-
addPointToFunction
private void addPointToFunction(java.lang.String s)
Adds a point to the function associated with the LUT or modelRGB.- Parameters:
s
- String
-
getFormattedThumbnailLine
private java.lang.String getFormattedThumbnailLine(int[] data, int index)
Returns a String for writing the thumbnail data (r,g,b) to the XML header.- Parameters:
data
- int[] array of int thumbnail dataindex
- int index of thumbnail data (which line)- Returns:
- String a formatted string containing comma separated thumbnail information
-
setLUT
private void setLUT()
Sets up the LUT based on the values read into the lutVector.
-
setRGB
private void setRGB()
sets up the model RGB while parsing XML header after all LUValues have been saved in the LUT vector.
-
updateOriginInfo
private void updateOriginInfo(FileInfoImageXML[] xmlInfo)
Updates the start locations. Each image has a fileinfo where the start locations are stored. Note that the start location for the Z (3rd) dimension change with the change is the slice. The origin is in the upper left corner and we are using the right hand rule. + x -> left to right; + y -> top to bottom and + z -> into screen.- Parameters:
xmlInfo
- the file info to update
-
writeHeader3DTo2D
private void writeHeader3DTo2D(ModelImage img, java.lang.String headerName, java.lang.String headerDir, FileWriteOptions options) throws java.io.IOException
Method to save off the header from a 4D image into 3D header files sequentially named (similar to the method in FileRaw).- Parameters:
img
- Image to be savedheaderName
- Name of fileheaderDir
- Directory for fileoptions
- File write options (contains # of digits and start #)- Throws:
java.io.IOException
- DOCUMENT ME!
-
writeHeader4DTo3D
private void writeHeader4DTo3D(ModelImage img, java.lang.String headerName, java.lang.String headerDir, FileWriteOptions options) throws java.io.IOException
Method to save off the header from a 4D image into 3D header files sequentially named (similar to the method in FileRaw).- Parameters:
img
- Image to be savedheaderName
- name of fileheaderDir
- directory for fileoptions
- file write options- Throws:
java.io.IOException
- DOCUMENT ME!
-
writeSet
private void writeSet(java.io.BufferedWriter bw, java.util.Enumeration<XMLPSet> setEnum)
writeSet
is a helper method, to allow writing set data out to theBufferedWriter
with any enumeration.- Parameters:
bw
- The writer to which we will write the data.setEnum
- An enumerated list of set data.
-
-