Search in sources :

Example 1 with WlzDVertex3

use of uk.ac.mrc.hgu.Wlz.WlzDVertex3 in project bioformats by openmicroscopy.

the class WlzServiceImpl method openRead.

/*
  * Helper methods.
  */
private void openRead(String file) throws FormatException, IOException {
    state = WLZ_SERVICE_READ;
    try {
        wlzFP = new WlzFileInputStream(file);
        wlzObj = WlzObject.WlzReadObj(wlzFP);
        bBox = WlzObject.WlzBoundingBox3I(wlzObj);
        objType = WlzObject.WlzGetObjectType(wlzObj);
        if (objType == WlzObjectType.WLZ_3D_DOMAINOBJ) {
            voxSz = WlzObject.WlzGetVoxelSize(wlzObj);
        } else {
            voxSz = new WlzDVertex3(1.0, 1.0, 1.0);
        }
    } catch (WlzException e) {
        throw new IOException("Failed to read Woolz object (" + e + ")", e);
    }
    try {
        if (objType == WlzObjectType.WLZ_COMPOUND_ARR_1 || objType == WlzObjectType.WLZ_COMPOUND_ARR_2) {
            int count = objType == WlzObjectType.WLZ_COMPOUND_ARR_1 ? 1 : 2;
            WlzObject[][] dest = new WlzObject[1][count];
            WlzObject.WlzExplode(new int[] { count }, dest, wlzObj);
            wlzObj = dest[0][0];
            bBox = WlzObject.WlzBoundingBox3I(wlzObj);
            objType = WlzObject.WlzGetObjectType(wlzObj);
            if (objType == WlzObjectType.WLZ_3D_DOMAINOBJ) {
                voxSz = WlzObject.WlzGetVoxelSize(wlzObj);
            }
        }
        if (WlzObject.WlzObjectValuesIsNull(wlzObj) != 0) {
            /* Here we use WLZ_GREY_ERROR to indicate that the object has no
         * values not an error. */
            objGType = WlzGreyType.WLZ_GREY_ERROR;
        } else {
            // throw an exception here instead of segfaulting during readBytes*
            if (WlzObject.WlzGetObjectValuesType(wlzObj) > WlzObjectType.WLZ_GREY_TAB_TILED) {
                throw new FormatException("Value table data not supported");
            }
            objGType = WlzObject.WlzGreyTypeFromObj(wlzObj);
        }
    } catch (WlzException e) {
        throw new FormatException("Unable to determine Woolz object value type (" + e + ")", e);
    }
    switch(objGType) {
        case WlzGreyType.WLZ_GREY_UBYTE:
            break;
        case WlzGreyType.WLZ_GREY_SHORT:
            break;
        case WlzGreyType.WLZ_GREY_INT:
            break;
        case WlzGreyType.WLZ_GREY_FLOAT:
            break;
        case WlzGreyType.WLZ_GREY_DOUBLE:
            break;
        case WlzGreyType.WLZ_GREY_RGBA:
            break;
        case WlzGreyType.WLZ_GREY_ERROR:
            break;
        default:
            throw new FormatException("Inappropriate Woolz object value type (type = " + objGType + ")");
    }
}
Also used : WlzException(uk.ac.mrc.hgu.Wlz.WlzException) WlzFileInputStream(uk.ac.mrc.hgu.Wlz.WlzFileInputStream) WlzObject(uk.ac.mrc.hgu.Wlz.WlzObject) IOException(java.io.IOException) FormatException(loci.formats.FormatException) WlzDVertex3(uk.ac.mrc.hgu.Wlz.WlzDVertex3)

Example 2 with WlzDVertex3

use of uk.ac.mrc.hgu.Wlz.WlzDVertex3 in project bioformats by openmicroscopy.

the class WlzServiceImpl method setupWrite.

@Override
public void setupWrite(int orgX, int orgY, int orgZ, int pixSzX, int pixSzY, int pixSzZ, int pixSzC, int pixSzT, double voxSzX, double voxSzY, double voxSzZ, int gType) throws FormatException {
    bBox = new WlzIBox3();
    bBox.xMin = orgX;
    bBox.yMin = orgY;
    bBox.zMin = orgZ;
    bBox.xMax = orgX + pixSzX - 1;
    bBox.yMax = orgY + pixSzY - 1;
    bBox.zMax = orgZ + pixSzZ - 1;
    voxSz = new WlzDVertex3(voxSzX, voxSzY, voxSzZ);
    if ((bBox.xMax < bBox.xMin) || (bBox.yMax < bBox.yMin) || (bBox.zMax < bBox.zMin) || (pixSzC <= 0) || (pixSzT <= 0)) {
        throw new FormatException("Invalid image size (" + (bBox.xMax - bBox.xMin + 1) + ", " + (bBox.yMax - bBox.yMin + 1) + ", " + (bBox.zMax - bBox.zMin + 1) + ", " + pixSzC + ", " + pixSzT + ")");
    }
    switch(gType) {
        case FormatTools.UINT8:
            objGType = WlzGreyType.WLZ_GREY_UBYTE;
            break;
        case FormatTools.INT16:
            objGType = WlzGreyType.WLZ_GREY_SHORT;
            break;
        case FormatTools.INT32:
            objGType = WlzGreyType.WLZ_GREY_INT;
            break;
        case FormatTools.FLOAT:
            objGType = WlzGreyType.WLZ_GREY_FLOAT;
            break;
        case FormatTools.DOUBLE:
            objGType = WlzGreyType.WLZ_GREY_DOUBLE;
            break;
        default:
            throw new FormatException("Invalid image value type");
    }
    if (bBox.zMax == bBox.zMin) {
        objType = WlzObjectType.WLZ_2D_DOMAINOBJ;
    } else {
        objType = WlzObjectType.WLZ_3D_DOMAINOBJ;
    }
    try {
        wlzObj = WlzObject.WlzMakeEmpty();
    } catch (WlzException e) {
        throw new FormatException("Failed to create Woolz object", e);
    }
}
Also used : WlzIBox3(uk.ac.mrc.hgu.Wlz.WlzIBox3) WlzException(uk.ac.mrc.hgu.Wlz.WlzException) FormatException(loci.formats.FormatException) WlzDVertex3(uk.ac.mrc.hgu.Wlz.WlzDVertex3)

Aggregations

FormatException (loci.formats.FormatException)2 WlzDVertex3 (uk.ac.mrc.hgu.Wlz.WlzDVertex3)2 WlzException (uk.ac.mrc.hgu.Wlz.WlzException)2 IOException (java.io.IOException)1 WlzFileInputStream (uk.ac.mrc.hgu.Wlz.WlzFileInputStream)1 WlzIBox3 (uk.ac.mrc.hgu.Wlz.WlzIBox3)1 WlzObject (uk.ac.mrc.hgu.Wlz.WlzObject)1