Search in sources :

Example 71 with Geometry

use of cbit.vcell.geometry.Geometry in project vcell by virtualcell.

the class MathDescription method setGeometry.

/**
 * This method was created in VisualAge.
 * @param geometry cbit.vcell.geometry.Geometry
 */
public void setGeometry(Geometry argGeometry) throws java.beans.PropertyVetoException {
    Geometry oldValue = this.geometry;
    fireVetoableChange(GeometryOwner.PROPERTY_NAME_GEOMETRY, oldValue, argGeometry);
    // this.geometry = argGeometry;
    setGeometry0(argGeometry);
    firePropertyChange(GeometryOwner.PROPERTY_NAME_GEOMETRY, oldValue, argGeometry);
    fireStateChanged();
    // 
    // compute warning string (if necessary)
    // 
    isValid();
}
Also used : Geometry(cbit.vcell.geometry.Geometry)

Example 72 with Geometry

use of cbit.vcell.geometry.Geometry in project vcell by virtualcell.

the class GeometryContext method setGeometry.

/**
 * Sets the geometry property (cbit.vcell.geometry.Geometry) value.
 * @param geometry The new value for the property.
 * @see #getGeometry
 */
void setGeometry(Geometry geometry) throws MappingException {
    Geometry oldValue = fieldGeometry;
    fieldGeometry = geometry;
    try {
        refreshStructureMappings();
        refreshDependencies();
        getSimulationContext().refreshSpatialObjects();
    } catch (PropertyVetoException e) {
        e.printStackTrace(System.out);
        throw new MappingException(e.getMessage());
    }
    firePropertyChange(GeometryOwner.PROPERTY_NAME_GEOMETRY, oldValue, geometry);
}
Also used : Geometry(cbit.vcell.geometry.Geometry) PropertyVetoException(java.beans.PropertyVetoException)

Example 73 with Geometry

use of cbit.vcell.geometry.Geometry in project vcell by virtualcell.

the class RayCaster method resampleGeometry.

public static Geometry resampleGeometry(GeometryThumbnailImageFactory geometryThumbnailImageFactory, Geometry origGeometry, ISize sampleSize) throws ImageException, PropertyVetoException, GeometryException, ExpressionException {
    if (origGeometry.getDimension() < 3) {
        throw new GeometryException("Presently, the Raycaster resampling works only for 3d geometries.");
    }
    GeometrySpec origGeometrySpec = origGeometry.getGeometrySpec();
    VCImage origSubvolumeImage = origGeometrySpec.getSampledImage().getCurrentValue();
    if (origSubvolumeImage == null) {
        throw new GeometryException("original geometry does not have a sampled image");
    }
    VCImage resampledSubvolumeImage = RayCaster.sampleGeometry(origGeometry, sampleSize, false);
    // 
    // Check if resampling failed:
    // if not the same number of pixelClasses (between original geometry and resampled)
    // if the subvolume handles are the same
    // 
    boolean bSameSubvolumes = true;
    if (origSubvolumeImage.getNumPixelClasses() != resampledSubvolumeImage.getNumPixelClasses()) {
        bSameSubvolumes = false;
    }
    // 
    for (VCPixelClass origPixelClass : origSubvolumeImage.getPixelClasses()) {
        VCPixelClass resampledPixelClass = resampledSubvolumeImage.getPixelClassFromPixelValue(origPixelClass.getPixel());
        if (resampledPixelClass == null) {
            bSameSubvolumes = false;
            break;
        }
    }
    // 
    if (!bSameSubvolumes) {
        StringBuffer message = new StringBuffer();
        message.append("\n\nexisting geometry:\n");
        for (SubVolume oldSubvolume : origGeometrySpec.getSubVolumes()) {
            long count = origSubvolumeImage.countPixelsByValue((byte) oldSubvolume.getHandle());
            message.append("subvolume('" + oldSubvolume.getName() + "',handle=" + oldSubvolume.getHandle() + ",numPixels=" + count + " of " + origSubvolumeImage.getNumXYZ() + "\n");
        }
        message.append("\n\nnew resampled handle VCImage:\n");
        for (VCPixelClass newPixelClass : resampledSubvolumeImage.getPixelClasses()) {
            long count = resampledSubvolumeImage.countPixelsByValue((byte) newPixelClass.getPixel());
            message.append("pixelClass('" + newPixelClass.getPixelClassName() + "',pixelValue=" + newPixelClass.getPixel() + ",numPixels=" + count + " of " + resampledSubvolumeImage.getNumXYZ() + ")\n");
        }
        throw new GeometryException("original Geometry had " + origSubvolumeImage.getNumPixelClasses() + " subvolumes, resampled Geometry found " + resampledSubvolumeImage.getNumPixelClasses() + " subvolumes " + message.toString());
    }
    // 
    // Create new VCImage that will form the basis for a new image-based geometry.
    // 
    VCImage newVCImage = null;
    if (origGeometrySpec.getImage() != null) {
        // 
        // was an image-based geometry - try to make new VCImage similar to the original (same pixelClass names and pixel values).
        // the goal is to make identical geometries if the sample size is same as the original image size.
        // 
        // create a new VCImage with same image pixel values (not subvolume handles) and pixel class names as original image.
        // 
        byte[] newVCImagePixels = new byte[sampleSize.getXYZ()];
        byte[] resampledSubvolumePixels = resampledSubvolumeImage.getPixels();
        for (int i = 0; i < sampleSize.getXYZ(); i++) {
            int subvolumeHandle = resampledSubvolumePixels[i];
            ImageSubVolume imageSubvolume = (ImageSubVolume) origGeometrySpec.getSubVolume(subvolumeHandle);
            newVCImagePixels[i] = (byte) imageSubvolume.getPixelValue();
        }
        newVCImage = new VCImageUncompressed(null, newVCImagePixels, origGeometry.getExtent(), sampleSize.getX(), sampleSize.getY(), sampleSize.getZ());
        newVCImage.setName(origGeometrySpec.getImage().getName());
        ArrayList<VCPixelClass> newPixelClasses = new ArrayList<VCPixelClass>();
        for (VCPixelClass origPixelClass : origGeometrySpec.getImage().getPixelClasses()) {
            SubVolume origSubvolume = origGeometrySpec.getImageSubVolumeFromPixelValue(origPixelClass.getPixel());
            newPixelClasses.add(new VCPixelClass(null, origSubvolume.getName(), origPixelClass.getPixel()));
        }
        newVCImage.setPixelClasses(newPixelClasses.toArray(new VCPixelClass[newPixelClasses.size()]));
    } else {
        // 
        // was an analytic geometry - create a new image-based geometry
        // 
        // create a new VCImage with image pixel values and pixelClass names equal to corresponding subvolumes from original geometry
        // make new subvolume names equal to old subvolume names.
        // 
        byte[] newVCImageSubvolumePixels = resampledSubvolumeImage.getPixels().clone();
        newVCImage = new VCImageUncompressed(null, newVCImageSubvolumePixels, origGeometry.getExtent(), sampleSize.getX(), sampleSize.getY(), sampleSize.getZ());
        ArrayList<VCPixelClass> newPixelClasses = new ArrayList<VCPixelClass>();
        for (SubVolume origSubvolume : origGeometrySpec.getSubVolumes()) {
            // note: newVCImage already has subvolume handle pixels.
            newPixelClasses.add(new VCPixelClass(null, origSubvolume.getName(), origSubvolume.getHandle()));
        }
        newVCImage.setPixelClasses(newPixelClasses.toArray(new VCPixelClass[newPixelClasses.size()]));
    }
    // 
    // construct the new geometry with the sampled VCImage.
    // 
    Geometry newGeometry = new Geometry(origGeometry.getName(), newVCImage);
    newGeometry.getGeometrySpec().setExtent(origGeometry.getExtent());
    newGeometry.getGeometrySpec().setOrigin(origGeometry.getOrigin());
    newGeometry.setDescription(origGeometry.getDescription());
    newGeometry.getGeometrySurfaceDescription().setFilterCutoffFrequency(origGeometry.getGeometrySurfaceDescription().getFilterCutoffFrequency());
    newGeometry.precomputeAll(geometryThumbnailImageFactory, true, true);
    return newGeometry;
}
Also used : VCPixelClass(cbit.image.VCPixelClass) GeometryException(cbit.vcell.geometry.GeometryException) ArrayList(java.util.ArrayList) VCImage(cbit.image.VCImage) VCImageUncompressed(cbit.image.VCImageUncompressed) GeometrySpec(cbit.vcell.geometry.GeometrySpec) Geometry(cbit.vcell.geometry.Geometry) SubVolume(cbit.vcell.geometry.SubVolume) ImageSubVolume(cbit.vcell.geometry.ImageSubVolume) ImageSubVolume(cbit.vcell.geometry.ImageSubVolume)

Example 74 with Geometry

use of cbit.vcell.geometry.Geometry in project vcell by virtualcell.

the class RayCaster method createGeometryFromSTL.

public static Geometry createGeometryFromSTL(GeometryThumbnailImageFactory geometryThumbnailImageFactory, SurfaceCollection surfaceCollection, int numSamples) throws ImageException, PropertyVetoException, GeometryException, ExpressionException, IOException {
    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 75 with Geometry

use of cbit.vcell.geometry.Geometry in project vcell by virtualcell.

the class RayCaster method createGeometry.

public static Geometry createGeometry(GeometryThumbnailImageFactory geometryThumbnailImageFactory, SurfaceCollection surfaceCollection, Origin origin, Extent extent, ISize sampleSize) throws ImageException, PropertyVetoException, GeometryException, ExpressionException {
    int numX = sampleSize.getX();
    int numY = sampleSize.getY();
    int numZ = sampleSize.getZ();
    VolumeSamples volumeSamples = volumeSampleSurface(surfaceCollection, sampleSize, origin, extent, false);
    // 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;
                    }
                }
            }
        }
    }
    HashSet<Long> consensusSet = new HashSet<Long>(consensusMaskArray);
    int[] pixels = new int[numX * numY * numZ];
    int pixelValue = 1;
    for (long mask : consensusSet) {
        System.out.println("++++++++++++++++++ +++++++++++++++ ++++++++++++++++++ consensus mask: " + Long.toBinaryString(mask));
        // use connectsAcrossSurface() to avoid short-circuiting a membrane.
        for (int i = 0; i < volumeSamples.getNumXYZ(); i++) {
            if ((volumeSamples.getMask(i) & mask) != 0) {
                // if (incidentSurfaceMasks[i] == mask){
                pixels[i] = pixelValue;
            }
        }
        pixelValue++;
    }
    VCImageUncompressed vcImage = new VCImageUncompressed(null, pixels, extent, numX, numY, numZ);
    Geometry geometry = new Geometry("newGeometry", vcImage);
    geometry.getGeometrySpec().setExtent(extent);
    geometry.getGeometrySpec().setOrigin(origin);
    geometry.precomputeAll(geometryThumbnailImageFactory, true, true);
    return geometry;
}
Also used : Geometry(cbit.vcell.geometry.Geometry) ArrayList(java.util.ArrayList) VCImageUncompressed(cbit.image.VCImageUncompressed) HashSet(java.util.HashSet)

Aggregations

Geometry (cbit.vcell.geometry.Geometry)121 MathDescription (cbit.vcell.math.MathDescription)32 SimulationContext (cbit.vcell.mapping.SimulationContext)31 Simulation (cbit.vcell.solver.Simulation)29 PropertyVetoException (java.beans.PropertyVetoException)24 BioModel (cbit.vcell.biomodel.BioModel)23 DataAccessException (org.vcell.util.DataAccessException)23 VCImage (cbit.image.VCImage)22 SubVolume (cbit.vcell.geometry.SubVolume)21 MathModel (cbit.vcell.mathmodel.MathModel)21 Expression (cbit.vcell.parser.Expression)19 ISize (org.vcell.util.ISize)19 Hashtable (java.util.Hashtable)18 GeometryThumbnailImageFactoryAWT (cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT)17 UserCancelException (org.vcell.util.UserCancelException)17 KeyValue (org.vcell.util.document.KeyValue)17 ImageException (cbit.image.ImageException)16 Extent (org.vcell.util.Extent)16 SurfaceClass (cbit.vcell.geometry.SurfaceClass)15 ExpressionException (cbit.vcell.parser.ExpressionException)15