Search in sources :

Example 16 with Extent

use of org.vcell.util.Extent in project vcell by virtualcell.

the class DistanceMapGenerator method computeDistanceMaps.

public static SubvolumeSignedDistanceMap[] computeDistanceMaps(Geometry geometry, VCImage subvolumeHandleImage, boolean bCellCentered, boolean insideOnly) throws ImageException {
    double[] samplesX = new double[subvolumeHandleImage.getNumX()];
    double[] samplesY = new double[subvolumeHandleImage.getNumY()];
    double[] samplesZ = new double[subvolumeHandleImage.getNumZ()];
    ISize sampleSize = new ISize(subvolumeHandleImage.getNumX(), subvolumeHandleImage.getNumY(), subvolumeHandleImage.getNumZ());
    byte[] pixels = subvolumeHandleImage.getPixels();
    boolean[] ignoreMask = new boolean[sampleSize.getXYZ()];
    Origin origin = geometry.getOrigin();
    Extent extent = geometry.getExtent();
    RayCaster.sampleXYZCoordinates(sampleSize, origin, extent, samplesX, samplesY, samplesZ, bCellCentered);
    ArrayList<SubvolumeSignedDistanceMap> distanceMaps = new ArrayList<SubvolumeSignedDistanceMap>();
    int count = 0;
    for (SubVolume subVolume : geometry.getGeometrySpec().getSubVolumes()) {
        // 
        // find surfaces that bound the current SubVolume
        // 
        ArrayList<Surface> surfaces = new ArrayList<Surface>();
        for (GeometricRegion geometricRegion : geometry.getGeometrySurfaceDescription().getGeometricRegions()) {
            if (geometricRegion instanceof SurfaceGeometricRegion) {
                SurfaceGeometricRegion surfaceGeometricRegion = (SurfaceGeometricRegion) geometricRegion;
                for (GeometricRegion adjacentRegion : ((SurfaceGeometricRegion) geometricRegion).getAdjacentGeometricRegions()) {
                    if (adjacentRegion instanceof VolumeGeometricRegion && ((VolumeGeometricRegion) adjacentRegion).getSubVolume() == subVolume) {
                        surfaces.add(geometry.getGeometrySurfaceDescription().getSurfaceCollection().getSurface(surfaceGeometricRegion));
                    }
                }
            }
        }
        // find unsigned distances in a narrow band for surfaces that bound this SubVolume (expensive)
        // values outside the band are assumed to be initialized to MAX_NUMBER
        long t1 = System.currentTimeMillis();
        double[] distanceMap = localUnsignedDistanceMap(surfaces, samplesX, samplesY, samplesZ, 3);
        long t2 = System.currentTimeMillis();
        System.out.println("          Distance to triangle:   " + (int) ((t2 - t1) / 1000) + " sec.");
        // extend signed distance map using fast marching method from narrow band to all points.
        // will do it in 2 steps, positive growth first towards inside, then change the sign of the whole
        // distance map, then positive growth towards the exterior
        // this way, the interior distances will end negative and the exterior distances positive
        // 2 step growth saves memory and reduces the number of elements present at any given time in the binary
        // heap (binary heap manipulation is the most time consuming factor and it depends on the # of elements)
        Arrays.fill(ignoreMask, true);
        int subvolumeHandle = subVolume.getHandle();
        for (int i = 0; i < ignoreMask.length; i++) {
            if (pixels[i] == subvolumeHandle) {
                // inside
                ignoreMask[i] = false;
            } else {
                // outside
                if (distanceMap[i] < MAX_NUMBER) {
                    // make negative the part of narrow band which is outside
                    distanceMap[i] = -distanceMap[i];
                }
            }
        }
        // // step 1, we compute distances for the points "inside"
        // // the points outside are cold (we don't compute their distances this step)
        double deltaX = samplesX[1] - samplesX[0];
        double deltaY = samplesY[1] - samplesY[0];
        double deltaZ = samplesZ[1] - samplesZ[0];
        FastMarchingMethodHA fmm = new FastMarchingMethodHA(samplesX.length, samplesY.length, samplesZ.length, deltaX, deltaY, deltaZ, distanceMap, ignoreMask);
        fmm.march();
        if (!insideOnly) {
            // sign change of the half-completed distance map, the "interior" will become negative as it should be
            for (int i = 0; i < distanceMap.length; i++) {
                if (distanceMap[i] < MAX_NUMBER) {
                    distanceMap[i] = -distanceMap[i];
                }
            }
            // step 2, we compute distances for the points "outside"
            // no cold points (points we don't care about) this time, they are already frozen
            fmm = new FastMarchingMethodHA(samplesX.length, samplesY.length, samplesZ.length, deltaX, deltaY, deltaZ, distanceMap, null);
            fmm.march();
        } else {
            // sign change of the half-completed distance map, the "interior" will become negative as it should be
            for (int i = 0; i < distanceMap.length; i++) {
                if (distanceMap[i] < MAX_NUMBER) {
                    if (pixels[i] != subvolumeHandle) {
                        // need to filter out the part of the narrow band which is not inside
                        distanceMap[i] = MAX_NUMBER;
                    } else {
                        distanceMap[i] = -distanceMap[i];
                    }
                }
            }
        }
        // try {		// save some points in a VisIt compatible format
        // int xm = samplesX.length;
        // int ym = samplesY.length;
        // BufferedWriter out = new BufferedWriter(new FileWriter("c:\\TEMP\\2D_circle" + count + ".3D"));
        // out.write("x y z value\n");
        // 
        // for(int j=0; j<distanceMap.length; j++) {
        // int x = getX(j,xm,ym);
        // int y = getY(j,xm,ym);
        // int z = getZ(j,xm,ym);
        // if(distanceMap[j] < MAX_NUMBER) {
        // if((j%2 == 0 || j%3 == 0)  && (distanceMap[j] <= -2)) {
        // out.write(x + " " + y + " " + z + " " + (int)(distanceMap[j]*10) + "\n");
        // } else if((j%17 == 0 || j%23 == 0) && (distanceMap[j] <= 0.5) && (distanceMap[j] > -2)) {
        // out.write(x + " " + y + " " + z + " " + (int)(distanceMap[j]*10) + "\n");
        // } else if((j%31 == 0 || j%41 == 0) && (distanceMap[j] > 0.5)) {
        // out.write(x + " " + y + " " + z + " " + (int)(distanceMap[j]*10) + "\n");
        // }
        // }
        // if(distanceMap[j] < MAX_NUMBER) {
        // if(j%2 == 0) {
        // out.write(x + " " + y + " " + z + " " + (int)(distanceMap[j]*100) + "\n");
        // }
        // }
        // if(x==50 && y==50 && z==25) {		// on the surface
        // out.write(x + " " + y + " " + z + " " + (int)(distanceMap[j]*100) + "\n");
        // }
        // if(x==0 && y==0 && z==0) {
        // out.write(x + " " + y + " " + z + " " + 0 + "\n");
        // }
        // if(x==100 && y==100 && z==100) {
        // out.write(x + " " + y + " " + z + " " + 0 + "\n");
        // }
        // 
        // }
        // out.close();
        // } catch (IOException e) {
        // }
        SubvolumeSignedDistanceMap subvolumeSignedDistanceMap = new SubvolumeSignedDistanceMap(subVolume, samplesX, samplesY, samplesZ, distanceMap);
        distanceMaps.add(subvolumeSignedDistanceMap);
        count++;
    }
    return distanceMaps.toArray(new SubvolumeSignedDistanceMap[distanceMaps.size()]);
}
Also used : Origin(org.vcell.util.Origin) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) ArrayList(java.util.ArrayList) SubVolume(cbit.vcell.geometry.SubVolume) FastMarchingMethodHA(cbit.vcell.render.FastMarchingMethodHA)

Example 17 with Extent

use of org.vcell.util.Extent in project vcell by virtualcell.

the class RayCaster method sampleGeometry.

public static VCImage sampleGeometry(Geometry geometry, ISize sampleSize, boolean bCellCentered) throws ImageException, PropertyVetoException, GeometryException, ExpressionException {
    int numX = sampleSize.getX();
    int numY = sampleSize.getY();
    int numZ = sampleSize.getZ();
    Origin origin = geometry.getOrigin();
    Extent extent = geometry.getExtent();
    SurfaceCollection surfaceCollection = geometry.getGeometrySurfaceDescription().getSurfaceCollection();
    int surfaceCount = surfaceCollection.getSurfaceCount();
    // 
    if (surfaceCount == 0 && geometry.getGeometrySpec().getNumSubVolumes() == 1) {
        byte[] pixels = new byte[numX * numY * numZ];
        SubVolume subVolume = geometry.getGeometrySpec().getSubVolumes()[0];
        Arrays.fill(pixels, (byte) subVolume.getHandle());
        VCImageUncompressed vcImage = new VCImageUncompressed(null, pixels, extent, numX, numY, numZ);
        return vcImage;
    }
    VolumeSamples volumeSamples = volumeSampleSurface(surfaceCollection, sampleSize, origin, extent, bCellCentered);
    // for each mask bit, find union of masks which contain that bit ... iterate until no change.
    HashSet<Long> uniqueMasks = volumeSamples.getUniqueMasks();
    ArrayList<Long> consensusMaskArray = new ArrayList<Long>(uniqueMasks);
    // boolean bChanged = true;
    // while (bChanged){
    // bChanged = false;
    // for (int i=0;i<consensusMaskArray.size();i++){
    // for (int j=i+1;j<consensusMaskArray.size();j++){
    // if ((((long)consensusMaskArray.get(i)) & ((long)consensusMaskArray.get(j))) != 0L && (((long)consensusMaskArray.get(i))!=((long)consensusMaskArray.get(j)))){
    // long merged = consensusMaskArray.get(i) | consensusMaskArray.get(j);
    // if ((((merged<<1) & merged)==0L) &&  (((merged>>1) & merged)==0L)){
    // System.out.println("++++++++++++++++++++++++++++++++ merged "+Long.toBinaryString(consensusMaskArray.get(i))+" with "+Long.toBinaryString(consensusMaskArray.get(j))+" to get "+Long.toBinaryString(merged));
    // consensusMaskArray.set(i, merged);
    // consensusMaskArray.set(j, merged);
    // bChanged = true;
    // }
    // }
    // }
    // }
    // }
    /*
		for (Long l : consensusMaskArray) {
			System.out.println("++++++++++++++++++++++++++++++++ final mask "+Long.toBinaryString(l));
		}
		*/
    HashSet<Long> consensusSet = new HashSet<Long>(consensusMaskArray);
    byte[] pixels = new byte[numX * numY * numZ];
    setSurfaceMasks(geometry.getGeometrySurfaceDescription().getSurfaceCollection());
    for (long mask : consensusSet) {
        // for this consensus mask, find the subvolume that is associated
        SubVolume subvolume = getSubvolume(geometry, mask);
        if (subvolume == null) {
            throw new RuntimeException("could not reconcile volume samples with original geometry");
        }
        byte pixelValue = (byte) subvolume.getHandle();
        for (int i = 0; i < volumeSamples.getNumXYZ(); i++) {
            if ((volumeSamples.getMask(i) & mask) != 0) {
                pixels[i] = (byte) pixelValue;
            }
        }
    }
    VCImageUncompressed vcImage = new VCImageUncompressed(null, pixels, extent, numX, numY, numZ);
    return vcImage;
}
Also used : Origin(org.vcell.util.Origin) Extent(org.vcell.util.Extent) ArrayList(java.util.ArrayList) VCImageUncompressed(cbit.image.VCImageUncompressed) SubVolume(cbit.vcell.geometry.SubVolume) ImageSubVolume(cbit.vcell.geometry.ImageSubVolume) HashSet(java.util.HashSet)

Example 18 with Extent

use of org.vcell.util.Extent in project vcell by virtualcell.

the class RayCasterBitSet method createGeometryFromSTL.

public static Geometry createGeometryFromSTL(GeometryThumbnailImageFactory geometryThumbnailImageFactory, File stlFile, int numSamples) throws ImageException, PropertyVetoException, GeometryException, ExpressionException, IOException {
    SurfaceCollection surfaceCollection = StlReader.readStl(stlFile);
    Node[] nodes = surfaceCollection.getNodes();
    double minX = Double.MAX_VALUE;
    double maxX = -Double.MAX_VALUE;
    double minY = Double.MAX_VALUE;
    double maxY = -Double.MAX_VALUE;
    double minZ = Double.MAX_VALUE;
    double maxZ = -Double.MAX_VALUE;
    for (Node node : nodes) {
        double nx = node.getX();
        double ny = node.getY();
        double nz = node.getZ();
        minX = Math.min(minX, nx);
        maxX = Math.max(maxX, nx);
        minY = Math.min(minY, ny);
        maxY = Math.max(maxY, ny);
        minZ = Math.min(minZ, nz);
        maxZ = Math.max(maxZ, nz);
    }
    Extent extent = new Extent((maxX - minX) * 1.4, (maxY - minY) * 1.4, (maxZ - minZ) * 1.4);
    Origin origin = new Origin(minX - 0.2 * extent.getX(), minY - 0.2 * extent.getY(), minZ - 0.2 * extent.getZ());
    ISize sampleSize = GeometrySpec.calulateResetSamplingSize(3, extent, numSamples);
    Geometry geometry = createGeometry(geometryThumbnailImageFactory, surfaceCollection, origin, extent, sampleSize);
    return geometry;
}
Also used : Origin(org.vcell.util.Origin) Geometry(cbit.vcell.geometry.Geometry) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize)

Example 19 with Extent

use of org.vcell.util.Extent in project vcell by virtualcell.

the class RasterExporter method createSliceNrrdHelper.

private NRRDHelper createSliceNrrdHelper(CartesianMesh mesh, DataProcessingOutputInfo dataProcessingOutputInfo, VCDataIdentifier vcdID, VariableSpecs variableSpecs, TimeSpecs timeSpecs2, GeometrySpecs geometrySpecs, RasterSpecs rasterSpecs, FileDataContainerManager fileDataContainerManager) throws IOException, DataAccessException {
    ISize planeISize = Coordinate.convertAxisFromStandardXYZToNormal(mesh.getISize(), geometrySpecs.getAxis());
    planeISize = new ISize(planeISize.getX(), planeISize.getY(), 1);
    Extent planeExtent = Coordinate.convertAxisFromStandardXYZToNormal(mesh.getExtent(), geometrySpecs.getAxis());
    planeExtent = new Extent(planeExtent.getX(), planeExtent.getY(), 1);
    return NRRDHelper.getSizeCheckedNrrdHelper(variableSpecs, planeISize, planeExtent, dataProcessingOutputInfo);
}
Also used : Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize)

Example 20 with Extent

use of org.vcell.util.Extent in project vcell by virtualcell.

the class CartesianMesh method read.

/**
 * This method was created by a SmartGuide.
 * @param tokens java.util.StringTokenizer
 * @exception java.lang.Exception The exception description.
 */
private void read(CommentStringTokenizer tokens, MembraneMeshMetrics membraneMeshMetrics) throws MathException {
    // 
    // clear previous contents
    // 
    membraneElements = null;
    // 
    // read new stuff
    // 
    String token = null;
    token = tokens.nextToken();
    if (token.equalsIgnoreCase(VCML.Version)) {
        // 
        // read version number
        // 
        token = tokens.nextToken();
        this.version = token;
        token = tokens.nextToken();
    }
    if (token.equalsIgnoreCase(VCML.CartesianMesh)) {
        token = tokens.nextToken();
    } else {
        throw new MathFormatException("unexpected token " + token + " expecting " + VCML.CartesianMesh);
    }
    // 
    // only Version 1.1 and later supports membrane connectivity  (as of 8/30/2000)
    // 
    boolean bConnectivity = false;
    if (version.equals(VERSION_1_1) || version.equals(VERSION_1_2)) {
        bConnectivity = true;
    }
    // 
    // only Version 1.2 and later supports Regions
    // 
    boolean bRegions = false;
    if (version.equals(VERSION_1_2)) {
        bRegions = true;
        meshRegionInfo = new MeshRegionInfo();
    }
    if (!token.equalsIgnoreCase(VCML.BeginBlock)) {
        throw new MathFormatException("unexpected token " + token + " expecting " + VCML.BeginBlock);
    }
    while (tokens.hasMoreTokens()) {
        token = tokens.nextToken();
        if (token.equalsIgnoreCase(VCML.EndBlock)) {
            break;
        }
        if (token.equalsIgnoreCase(VCML.Size)) {
            int sx, sy, sz;
            try {
                token = tokens.nextToken();
                sx = Integer.valueOf(token).intValue();
                token = tokens.nextToken();
                sy = Integer.valueOf(token).intValue();
                token = tokens.nextToken();
                sz = Integer.valueOf(token).intValue();
            } catch (NumberFormatException e) {
                throw new MathFormatException("expected:  " + VCML.Size + " # # #");
            }
            setSize(sx, sy, sz);
            continue;
        }
        if (token.equalsIgnoreCase(VCML.Extent)) {
            double ex, ey, ez;
            try {
                token = tokens.nextToken();
                ex = Double.valueOf(token).doubleValue();
                token = tokens.nextToken();
                ey = Double.valueOf(token).doubleValue();
                token = tokens.nextToken();
                ez = Double.valueOf(token).doubleValue();
            } catch (NumberFormatException e) {
                throw new MathFormatException("expected:  " + VCML.Extent + " # # #");
            }
            setExtent(new Extent(ex, ey, ez));
            continue;
        }
        if (token.equalsIgnoreCase(VCML.Origin)) {
            double ox, oy, oz;
            try {
                token = tokens.nextToken();
                ox = Double.valueOf(token).doubleValue();
                token = tokens.nextToken();
                oy = Double.valueOf(token).doubleValue();
                token = tokens.nextToken();
                oz = Double.valueOf(token).doubleValue();
            } catch (NumberFormatException e) {
                throw new MathFormatException("expected:  " + VCML.Origin + " # # #");
            }
            setOrigin(new Origin(ox, oy, oz));
            continue;
        }
        // 
        if (token.equalsIgnoreCase(VCML.VolumeRegionsMapSubvolume)) {
            token = tokens.nextToken();
            if (!token.equalsIgnoreCase(VCML.BeginBlock)) {
                throw new MathFormatException("unexpected token " + token + " expecting " + VCML.BeginBlock);
            }
            token = tokens.nextToken();
            int numVolumeRegions = 0;
            try {
                numVolumeRegions = Integer.valueOf(token).intValue();
            } catch (NumberFormatException e) {
                throw new MathFormatException("unexpected token " + token + " expecting the VolumeRegionsMapSubvolume list length");
            }
            int checkCount = 0;
            while (tokens.hasMoreTokens()) {
                token = tokens.nextToken();
                if (token.equalsIgnoreCase(VCML.EndBlock)) {
                    break;
                }
                try {
                    int volRegionID = Integer.valueOf(token).intValue();
                    token = tokens.nextToken();
                    int subvolumeID = Integer.valueOf(token).intValue();
                    token = tokens.nextToken();
                    double volume = Double.valueOf(token).doubleValue();
                    String subdomainName = null;
                    if (subdomainInfo != null) {
                        subdomainName = subdomainInfo.getCompartmentSubdomainName(subvolumeID);
                    }
                    meshRegionInfo.mapVolumeRegionToSubvolume(volRegionID, subvolumeID, volume, subdomainName);
                } catch (NumberFormatException e) {
                    throw new MathFormatException("expected:  # # #");
                }
                checkCount += 1;
            }
            if (checkCount != numVolumeRegions) {
                throw new MathFormatException("CartesianMesh.read->VolumeRegionsMapSubvolume: read " + checkCount + " VolRegions but was expecting " + numVolumeRegions);
            }
            continue;
        }
        if (token.equalsIgnoreCase(VCML.MembraneRegionsMapVolumeRegion)) {
            token = tokens.nextToken();
            if (!token.equalsIgnoreCase(VCML.BeginBlock)) {
                throw new MathFormatException("unexpected token " + token + " expecting " + VCML.BeginBlock);
            }
            token = tokens.nextToken();
            int numMembraneRegions = 0;
            try {
                numMembraneRegions = Integer.valueOf(token).intValue();
            } catch (NumberFormatException e) {
                throw new MathFormatException("unexpected token " + token + " expecting the MembraneRegionsMapVolumeRegion list length");
            }
            int checkCount = 0;
            while (tokens.hasMoreTokens()) {
                token = tokens.nextToken();
                if (token.equalsIgnoreCase(VCML.EndBlock)) {
                    break;
                }
                try {
                    int memRegionID = Integer.valueOf(token).intValue();
                    token = tokens.nextToken();
                    int volRegionIn = Integer.valueOf(token).intValue();
                    token = tokens.nextToken();
                    int volRegionOut = Integer.valueOf(token).intValue();
                    token = tokens.nextToken();
                    double surface = Double.valueOf(token).doubleValue();
                    meshRegionInfo.mapMembraneRegionToVolumeRegion(memRegionID, volRegionIn, volRegionOut, surface);
                } catch (NumberFormatException e) {
                    throw new MathFormatException("expected:  # # #");
                }
                checkCount += 1;
            }
            if (checkCount != numMembraneRegions) {
                throw new MathFormatException("CartesianMesh.read->MembraneRegionsMapVolumeRegion: read " + checkCount + " MembraneRegions but was expecting " + numMembraneRegions);
            }
            continue;
        }
        if (token.equalsIgnoreCase(VCML.VolumeElementsMapVolumeRegion)) {
            token = tokens.nextToken();
            if (!token.equalsIgnoreCase(VCML.BeginBlock)) {
                throw new MathFormatException("unexpected token " + token + " expecting " + VCML.BeginBlock);
            }
            token = tokens.nextToken();
            int numVolumeElements = 0;
            try {
                numVolumeElements = Integer.valueOf(token).intValue();
            } catch (NumberFormatException e) {
                throw new MathFormatException("unexpected token " + token + " expecting the VolumeElementsMapVolumeRegion list length");
            }
            token = tokens.nextToken();
            boolean bCompressed = token.equalsIgnoreCase("Compressed");
            if (!bCompressed) {
                if (!token.equalsIgnoreCase("UnCompressed")) {
                    throw new MathFormatException("unexpected token " + token + " expecting Compress or UnCompress");
                }
            }
            byte[] volumeElementMap = new byte[numVolumeElements];
            int checkCount = 0;
            if (bCompressed) {
                // Get HEX encoded bytes of the compressed VolumeElements-RegionID Map
                StringBuffer hexOfCompressed = new StringBuffer();
                while (tokens.hasMoreTokens()) {
                    token = tokens.nextToken();
                    if (token.equalsIgnoreCase(VCML.EndBlock)) {
                        break;
                    }
                    hexOfCompressed.append(token);
                }
                // Un-HEX the compressed data
                byte[] compressedData = Hex.toBytes(hexOfCompressed.toString());
                try {
                    meshRegionInfo.setCompressedVolumeElementMapVolumeRegion(compressedData, numVolumeElements);
                } catch (IOException e) {
                    throw new MathFormatException("CartesianMesh.read->VolumeElementsMapVolumeRegion " + e.toString());
                }
                checkCount = meshRegionInfo.getUncompressedVolumeElementMapVolumeRegionLength();
            } else {
                while (tokens.hasMoreTokens()) {
                    token = tokens.nextToken();
                    if (token.equalsIgnoreCase(VCML.EndBlock)) {
                        break;
                    }
                    try {
                        int volumeRegionID = Integer.valueOf(token).intValue();
                        volumeElementMap[checkCount] = (byte) volumeRegionID;
                    } catch (NumberFormatException e) {
                        throw new MathFormatException("expected:  # # #");
                    }
                    checkCount += 1;
                }
            }
            if (checkCount != numVolumeElements && checkCount != 2 * numVolumeElements) {
                throw new MathFormatException("CartesianMesh.read->VolumeElementsMapVolumeRegion: read " + checkCount + " VolumeElements but was expecting " + numVolumeElements);
            }
            continue;
        }
        // 
        // 
        // 
        HashMap<Integer, Integer> volumeRegionMapSubvolume = getVolumeRegionMapSubvolume();
        if (token.equalsIgnoreCase(VCML.MembraneElements)) {
            // 
            // read '{'
            // 
            token = tokens.nextToken();
            if (!token.equalsIgnoreCase(VCML.BeginBlock)) {
                throw new MathFormatException("unexpected token " + token + " expecting " + VCML.BeginBlock);
            }
            token = tokens.nextToken();
            int numMemElements = 0;
            try {
                numMemElements = Integer.valueOf(token).intValue();
            } catch (NumberFormatException e) {
                throw new MathFormatException("unexpected token " + token + " expecting the membraneElement list length");
            }
            // 
            // read list of the following format:
            // 
            // memIndex insideVolIndex outsideVolIndex
            // 
            membraneElements = new MembraneElement[numMemElements];
            int index = 0;
            int[] membraneElementMapMembraneRegion = null;
            if (bRegions) {
                membraneElementMapMembraneRegion = new int[numMemElements];
                meshRegionInfo.mapMembraneElementsToMembraneRegions(membraneElementMapMembraneRegion);
            }
            // 
            while (tokens.hasMoreTokens()) {
                token = tokens.nextToken();
                if (token.equalsIgnoreCase(VCML.EndBlock)) {
                    break;
                }
                int memIndex = -1;
                int insideIndex = -1;
                int outsideIndex = -1;
                try {
                    // 
                    // read first three tokens of a membrane element
                    // 
                    // membraneIndex   insideIndex    outsideIndex
                    // 
                    memIndex = Integer.valueOf(token).intValue();
                    token = tokens.nextToken();
                    insideIndex = Integer.valueOf(token).intValue();
                    token = tokens.nextToken();
                    outsideIndex = Integer.valueOf(token).intValue();
                    if (subdomainInfo != null) {
                        int insideRegionIndex = getVolumeRegionIndex(insideIndex);
                        int outsideRegionIndex = getVolumeRegionIndex(outsideIndex);
                        int insideSubVolumeHandle = volumeRegionMapSubvolume.get(insideRegionIndex);
                        int outsideSubVolumeHandle = volumeRegionMapSubvolume.get(outsideRegionIndex);
                        int realInsideSubVolumeHandle = subdomainInfo.getInside(insideSubVolumeHandle, outsideSubVolumeHandle);
                        if (realInsideSubVolumeHandle != insideSubVolumeHandle) {
                            int temp = insideIndex;
                            insideIndex = outsideIndex;
                            outsideIndex = temp;
                        }
                    }
                } catch (NumberFormatException e) {
                    throw new MathFormatException("expected:  # # #");
                }
                MembraneElement me = null;
                // 
                if (bConnectivity) {
                    try {
                        token = tokens.nextToken();
                        int neighbor1 = Integer.valueOf(token).intValue();
                        token = tokens.nextToken();
                        int neighbor2 = Integer.valueOf(token).intValue();
                        token = tokens.nextToken();
                        int neighbor3 = Integer.valueOf(token).intValue();
                        token = tokens.nextToken();
                        int neighbor4 = Integer.valueOf(token).intValue();
                        // 
                        if (bRegions) {
                            token = tokens.nextToken();
                            int regionID = Integer.valueOf(token).intValue();
                            membraneElementMapMembraneRegion[memIndex] = regionID;
                        }
                        if (membraneMeshMetrics == null) {
                            me = new MembraneElement(memIndex, insideIndex, outsideIndex, neighbor1, neighbor2, neighbor3, neighbor4, MembraneElement.AREA_UNDEFINED, 0, 0, 0, 0, 0, 0);
                        } else {
                            me = new MembraneElement(memIndex, insideIndex, outsideIndex, neighbor1, neighbor2, neighbor3, neighbor4, membraneMeshMetrics.areas[memIndex], membraneMeshMetrics.normals[memIndex][0], membraneMeshMetrics.normals[memIndex][1], membraneMeshMetrics.normals[memIndex][2], membraneMeshMetrics.centroids[memIndex][0], membraneMeshMetrics.centroids[memIndex][1], membraneMeshMetrics.centroids[memIndex][2]);
                        }
                    } catch (NumberFormatException e) {
                        throw new MathFormatException("expected:  # # # # # # #");
                    }
                } else {
                    me = new MembraneElement(memIndex, insideIndex, outsideIndex);
                }
                membraneElements[index] = me;
                index++;
            }
            continue;
        }
        if (token.equalsIgnoreCase(VCML.ContourElements)) {
            // 
            // read '{'
            // 
            token = tokens.nextToken();
            if (!token.equalsIgnoreCase(VCML.BeginBlock)) {
                throw new MathFormatException("unexpected token " + token + " expecting " + VCML.BeginBlock);
            }
            token = tokens.nextToken();
            int numContourElements = 0;
            try {
                numContourElements = Integer.valueOf(token).intValue();
            } catch (NumberFormatException e) {
                throw new MathFormatException("unexpected token " + token + " expecting the contourElement list length");
            }
            // 
            // read list of the following format:
            // 
            // contourIndex volumeIndex beginCoord endCoord prevIndex nextIndex
            // 
            contourElements = new ContourElement[numContourElements];
            int index = 0;
            // 
            while (tokens.hasMoreTokens()) {
                token = tokens.nextToken();
                if (token.equalsIgnoreCase(VCML.EndBlock)) {
                    break;
                }
                ContourElement ce = null;
                try {
                    // 
                    // read first two tokens of a contour element
                    // 
                    // contourIndex volumeIndex
                    // 
                    int contourIndex = Integer.valueOf(token).intValue();
                    token = tokens.nextToken();
                    int volumeIndex = Integer.valueOf(token).intValue();
                    token = tokens.nextToken();
                    // 
                    // read beginCoord endCoord
                    // 
                    double beginX = Double.valueOf(token).doubleValue();
                    token = tokens.nextToken();
                    double beginY = Double.valueOf(token).doubleValue();
                    token = tokens.nextToken();
                    double beginZ = Double.valueOf(token).doubleValue();
                    token = tokens.nextToken();
                    double endX = Double.valueOf(token).doubleValue();
                    token = tokens.nextToken();
                    double endY = Double.valueOf(token).doubleValue();
                    token = tokens.nextToken();
                    double endZ = Double.valueOf(token).doubleValue();
                    token = tokens.nextToken();
                    Coordinate begin = new Coordinate(beginX, beginY, beginZ);
                    Coordinate end = new Coordinate(endX, endY, endZ);
                    // 
                    // read last two tokens of a contour element
                    // 
                    // prevContourIndex nextContourIndex
                    // 
                    int prevContourIndex = Integer.valueOf(token).intValue();
                    token = tokens.nextToken();
                    int nextContourIndex = Integer.valueOf(token).intValue();
                    ce = new ContourElement(contourIndex, volumeIndex, begin, end, prevContourIndex, nextContourIndex);
                } catch (NumberFormatException e) {
                    throw new MathFormatException("expected:  %d %d   %f %f %f    %f %f %f   %d %d");
                }
                contourElements[index] = ce;
                index++;
            }
            continue;
        }
        throw new MathFormatException("unexpected identifier " + token);
    }
    switch(getGeometryDimension()) {
        case 1:
            {
                if (extent.getY() != 1 || extent.getZ() != 1) {
                    System.out.println("Extent " + extent.toString() + " for a 1-D mesh truncated to 1 for y and z");
                    setExtent(new Extent(extent.getX(), 1.0, 1.0));
                }
                break;
            }
        case 2:
            {
                if (extent.getZ() != 1) {
                    System.out.println("Extent " + extent.toString() + " for a 2-D mesh truncated to 1 for z");
                    setExtent(new Extent(extent.getX(), extent.getY(), 1.0));
                }
                break;
            }
    }
}
Also used : Origin(org.vcell.util.Origin) Extent(org.vcell.util.Extent) MathFormatException(cbit.vcell.math.MathFormatException) IOException(java.io.IOException) Coordinate(org.vcell.util.Coordinate)

Aggregations

Extent (org.vcell.util.Extent)96 Origin (org.vcell.util.Origin)58 ISize (org.vcell.util.ISize)52 VCImageUncompressed (cbit.image.VCImageUncompressed)23 ImageException (cbit.image.ImageException)19 VCImage (cbit.image.VCImage)19 CartesianMesh (cbit.vcell.solvers.CartesianMesh)19 RegionImage (cbit.vcell.geometry.RegionImage)17 Geometry (cbit.vcell.geometry.Geometry)16 Expression (cbit.vcell.parser.Expression)16 FieldDataFileOperationSpec (cbit.vcell.field.io.FieldDataFileOperationSpec)15 IOException (java.io.IOException)15 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)13 BioModel (cbit.vcell.biomodel.BioModel)13 SubVolume (cbit.vcell.geometry.SubVolume)13 File (java.io.File)12 ArrayList (java.util.ArrayList)12 UserCancelException (org.vcell.util.UserCancelException)12 ExpressionException (cbit.vcell.parser.ExpressionException)10 ImageDataset (cbit.vcell.VirtualMicroscopy.ImageDataset)9