use of loci.formats.tools.AmiraParameters in project bioformats by openmicroscopy.
the class AmiraReader method initFile.
/* (non-Javadoc)
* @see loci.formats.FormatReader#initFile(java.lang.String)
*/
@Override
protected void initFile(String id) throws FormatException, IOException {
super.initFile(id);
in = new RandomAccessInputStream(id);
AmiraParameters parameters = new AmiraParameters(in);
offsetOfFirstStream = in.getFilePointer();
LOGGER.info("Populating metadata hashtable");
addGlobalMeta("Image width", parameters.width);
addGlobalMeta("Image height", parameters.height);
addGlobalMeta("Number of planes", parameters.depth);
addGlobalMeta("Bits per pixel", 8);
LOGGER.info("Populating core metadata");
int channelIndex = 1;
while (parameters.getStreams().get("@" + channelIndex) != null) {
channelIndex++;
}
CoreMetadata m = core.get(0);
m.sizeX = parameters.width;
m.sizeY = parameters.height;
m.sizeZ = parameters.depth;
m.sizeT = 1;
m.sizeC = channelIndex - 1;
m.imageCount = getSizeZ() * getSizeC();
m.littleEndian = parameters.littleEndian;
m.dimensionOrder = "XYZCT";
String streamType = parameters.streamTypes[0].toLowerCase();
if (streamType.equals("byte")) {
m.pixelType = FormatTools.UINT8;
} else if (streamType.equals("short")) {
m.pixelType = FormatTools.INT16;
addGlobalMeta("Bits per pixel", 16);
} else if (streamType.equals("ushort")) {
m.pixelType = FormatTools.UINT16;
addGlobalMeta("Bits per pixel", 16);
} else if (streamType.equals("int")) {
m.pixelType = FormatTools.INT32;
addGlobalMeta("Bits per pixel", 32);
} else if (streamType.equals("float")) {
m.pixelType = FormatTools.FLOAT;
addGlobalMeta("Bits per pixel", 32);
} else {
LOGGER.warn("Assuming data type is byte");
m.pixelType = FormatTools.UINT8;
}
LOGGER.info("Populating metadata store");
MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this);
// The bounding box is the range of the centre of the voxels
if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
double pixelWidth = (double) (parameters.x1 - parameters.x0) / (parameters.width - 1);
double pixelHeight = (double) (parameters.y1 - parameters.y0) / (parameters.height - 1);
// TODO - what is correct setting if single slice?
double pixelDepth = (double) (parameters.z1 - parameters.z0) / (parameters.depth - 1);
// Amira does not have a standard form for encoding units, so we just
// have to assume microns for microscopy data
addGlobalMeta("Pixels per meter (X)", 1e6 / pixelWidth);
addGlobalMeta("Pixels per meter (Y)", 1e6 / pixelHeight);
addGlobalMeta("Pixels per meter (Z)", 1e6 / pixelDepth);
Length sizeX = FormatTools.getPhysicalSizeX(pixelWidth);
Length sizeY = FormatTools.getPhysicalSizeY(pixelHeight);
Length sizeZ = FormatTools.getPhysicalSizeZ(pixelDepth);
if (sizeX != null) {
store.setPixelsPhysicalSizeX(sizeX, 0);
}
if (sizeY != null) {
store.setPixelsPhysicalSizeY(sizeY, 0);
}
if (sizeZ != null) {
store.setPixelsPhysicalSizeZ(sizeZ, 0);
}
}
ascii = parameters.ascii;
ArrayList streamData = (ArrayList) parameters.getStreams().get("@1");
if (streamData.size() > 2) {
compression = (String) streamData.get(2);
}
initPlaneReader();
hasPlaneReader = planeReader != null;
addGlobalMeta("Compression", compression);
Map params = (Map) parameters.getMap().get("Parameters");
if (params != null) {
Map materials = (Map) params.get("Materials");
if (materials != null) {
lut = getLookupTable(materials);
m.indexed = true;
}
}
}
Aggregations