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
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 ClassesModifier and TypeClassDescriptionprivate classStores LUT information (red, green, blue, alpha).private classUsed by the XML Parser to parse the xml header.classHolds 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 taggingNested classes/interfaces inherited from class gov.nih.mipav.model.file.FileXML
FileXML.XMLAttributes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Enumeration<XMLPSet> A listing of all the additionalPSetsto be written into the saved file.DOCUMENT ME!private double[]private String[]private static final String[]array of strings representing the tags under invalid input: '<'Dataset-attributes> in the xml schema.private DTIParametersprivate intIndex of LUT function when reading xml header.private Vector<WildMagic.LibFoundation.Mathematics.Vector2f> Vector to store the LUT functions when reading xml header.private double[][]private ModelImageModel Image associated with the file.private StringName of the RAW (or IMG) file associated with the XML header.private static final String[]array of strings representing the tags underin the xml schema. private static final String[]array of strings representing the tags underin the xml schema. private StringName of the file linked to this file (separate from fileName).private ModelLUTLookup Table associated with the file (grayscale).private Vector<FileImageXML.LUValue> Vector to store LUT values when reading xml header.private Vector<TransMatrix> Vector to hold matrices while they are being read in for the header (until they are added to the imageprivate ModelRGBRGB lookup table associated with the file.private intprivate static final String[]array of strings representing the tags underin the xml schema. private StringThe extension to give to the RAW file associated with the XML header.private static final String[]array of strings representing the tags under invalid input: '<'Scan-attributes> in the xml schema.private static final String[]array of strings representing the tags underin the xml schema. private static final String[]array of strings representing the tags under invalid input: '<'Subject-information> in the xml schema.private static final String[]array of strings representing the tags underin the xml schema. private FileImageXML.ThumbnailThumbnail data and AWT Image.private static final String[]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_HEADERFields inherited from class gov.nih.mipav.model.file.FileBase
BIG_ENDIAN, bitsPerPixel, fileNames, LITTLE_ENDIAN, pBarVisible, raFile, READ, READ_WRITE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidAdds the LUT functions collected within the functionVector.private voidAdds the ModelRGB functions contained within the functionVector.private voidaddLUValue(String s) Adds LUValue for either LUT or modelRGB.private voidAdds a point to the function associated with the LUT or modelRGB.voidConvenience method to clear any additional sets of the enumerated list that might be written into the header file.voidfinalize()Prepares class for cleanup.static final voidflipTopBottom(float[] buffer, FileInfoImageXML xmlInfo) Flips image.static final voidflipTopBottom(ModelImage img) Flips image.Returns the enumerated list of additional sets to be written into the header file.String[]Accessor that returns the array of data file namesReturns the FileInfoXML read from the file.private StringgetFormattedThumbnailLine(int[] data, int index) Returns a String for writing the thumbnail data (r,g,b) to the XML header.private byte[]getFullBuffer(InputStream in, byte[] buff, int off, int fullBufferSize) Gets the LUT.Gets the modelRGB.private static intgetOffset(FileInfoImageXML xmlInfo) Helper method to calculate the offset for getting only the middle analyze image slice from the 3D file.Returns the thumbnail associated with the xml file (saved in header).float[][]readHeader(String headerFileName, String headerDir, TalairachTransformInfo talairach) Reads and parses an XML header.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.voidreadImage(float[] buffer) Reads an XML image file by reading the header then making a FileRaw to read the file.voidsetAdditionalSets(Enumeration<XMLPSet> moreSets) Method to replace the enumerated list of additional sets to be written into the header file.voidsetFileName(String fName) Accessor to set the file name (used when reading XML multiFile).private voidsetLUT()Sets up the LUT based on the values read into the lutVector.voidsetModelLUT(ModelLUT lut) Sets the model LUT.voidsetModelRGB(ModelRGB modelRGB) Sets the model RGB.voidsetRawExtension(String ext) Changes the extension of the image data file associated with this XML header.private voidsetRGB()sets up the model RGB while parsing XML header after all LUValues have been saved in the LUT vector.voidsetThumbnailData(int xDim, int yDim, int[] data) Sets the thumbnail data (array of shorts).private voidupdateOriginInfo(FileInfoImageXML[] xmlInfo) Updates the start locations.booleanwriteHeader(ModelImage img, FileWriteOptions options, String headerName, String headerDir, boolean changeDims) Writes the XML header information out to the given filename and path.private voidwriteHeader3DTo2D(ModelImage img, String headerName, 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 voidwriteHeader4DTo3D(ModelImage img, String headerName, 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).voidwriteImage(ModelImage img, FileWriteOptions options) Writes an XML image with the given options.private voidwriteSet(BufferedWriter bw, Enumeration<XMLPSet> setEnum) writeSetis a helper method, to allow writing set data out to theBufferedWriterwith any enumeration.Methods inherited from class gov.nih.mipav.model.file.FileXML
closedTag, closedTag, closedTag, openTag, readHeader, setPBarMethods 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 Details
-
imageStr
array of strings representing the tags underin the xml schema. -
datasetAttributesStr
array of strings representing the tags under invalid input: '<'Dataset-attributes> in the xml schema. -
subjectInformationStr
array of strings representing the tags under invalid input: '<'Subject-information> in the xml schema. -
scanAttributesStr
array of strings representing the tags under invalid input: '<'Scan-attributes> in the xml schema. -
investigatorsStr
array of strings representing the tags underin the xml schema. -
setStr
array of strings representing the tags underin the xml schema. -
parameterStr
array of strings representing the tags underin the xml schema. -
voiStr
array of strings representing the tags underin the xml schema. -
surfaceStr
array of strings representing the tags underin the xml schema. -
additionalSets
A listing of all the additionalPSetsto be written into the saved file. -
annotationVector
DOCUMENT ME! -
functionIndex
private int functionIndexIndex of LUT function when reading xml header. -
functionVector
Vector to store the LUT functions when reading xml header. -
matrixVector
Vector to hold matrices while they are being read in for the header (until they are added to the image -
image
Model Image associated with the file. -
imageFileName
Name of the RAW (or IMG) file associated with the XML header. -
linkedFilename
Name of the file linked to this file (separate from fileName). -
LUT
Lookup Table associated with the file (grayscale). -
lutVector
Vector to store LUT values when reading xml header. -
modelRGB
RGB lookup table associated with the file. -
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
Thumbnail data and AWT Image. -
dataFileName
-
dtiparams
-
numVolumes
private int numVolumes -
gradients
private double[][] gradients -
bValues
private double[] bValues
-
-
Constructor Details
-
FileImageXML
Constructs new file object.- Parameters:
fName- File name.fDir- File directory.
-
-
Method Details
-
flipTopBottom
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:
IOException- if there is a problem importing or exporting the image
-
flipTopBottom
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. -
finalize
public void finalize()Prepares class for cleanup. -
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
Returns the FileInfoXML read from the file.- Returns:
- File info read from file, or null if it has not been read.
-
getModelLUT
Gets the LUT.- Returns:
- ModelLUT the LUT
-
getModelRGB
Gets the modelRGB.- Returns:
- ModelRGB the modelRGB
-
getThumbnail
Returns the thumbnail associated with the xml file (saved in header).- Returns:
- Thumbnail
-
getDataFileName
Accessor that returns the array of data file names- Returns:
-
readHeader
public float[][] readHeader(String headerFileName, String headerDir, TalairachTransformInfo talairach) throws 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:
IOException- DOCUMENT ME!
-
readImage
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:
IOException- if there is an error reading the fileOutOfMemoryError- if there is a problem allocating memory for the image- See Also:
-
getFullBuffer
-
readImage
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:
IOException- if there is an error reading the fileOutOfMemoryError- if there was a problem allocating enough memory- See Also:
-
setAdditionalSets
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
Accessor to set the file name (used when reading XML multiFile).- Parameters:
fName- file name of image to read.
-
setModelLUT
Sets the model LUT.- Parameters:
lut- ModelLUT the LUT
-
setModelRGB
Sets the model RGB.- Parameters:
modelRGB- ModelRGB the modelRGB
-
setRawExtension
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, String headerName, String headerDir, boolean changeDims) throws 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:
IOException- if a file I/O problem is encoutered while writing the header
-
writeImage
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:
IOException- if there is a problem writing to the file
-
getOffset
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
Adds LUValue for either LUT or modelRGB.- Parameters:
s- String
-
addPointToFunction
Adds a point to the function associated with the LUT or modelRGB.- Parameters:
s- String
-
getFormattedThumbnailLine
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
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, String headerName, String headerDir, FileWriteOptions options) throws 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:
IOException- DOCUMENT ME!
-
writeHeader4DTo3D
private void writeHeader4DTo3D(ModelImage img, String headerName, String headerDir, FileWriteOptions options) throws 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:
IOException- DOCUMENT ME!
-
writeSet
writeSetis a helper method, to allow writing set data out to theBufferedWriterwith any enumeration.- Parameters:
bw- The writer to which we will write the data.setEnum- An enumerated list of set data.
-