Search in sources :

Example 6 with Origin

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

the class FRAPStudy method getROIDataGenerator.

public ROIDataGenerator getROIDataGenerator(LocalWorkspace localWorkspace) {
    // create ROI image
    short[] roiFieldData = null;
    ROI[] rois = getFrapData().getRois();
    if (rois.length > 0) {
        Extent extent = rois[0].getRoiImages()[0].getExtent();
        ISize isize = rois[0].getISize();
        int numROIX = rois[0].getISize().getX();
        int numROIY = rois[0].getISize().getY();
        roiFieldData = new short[numROIX * numROIY];
        short regionCounter = 1;
        for (int roiIdx = FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING1.ordinal(); roiIdx < rois.length; roiIdx++) {
            short[] roiImg = rois[roiIdx].getPixelsXYZ();
            for (int pixelIdx = 0; pixelIdx < (numROIX * numROIY); pixelIdx++) {
                if (roiImg[pixelIdx] > 0) {
                    roiFieldData[pixelIdx] = regionCounter;
                }
            }
            regionCounter++;
        }
        // create field data
        int NumTimePoints = 1;
        // 8 rois integrated into 1 image
        int NumChannels = 1;
        short[][][] pixData = new short[NumTimePoints][NumChannels][];
        pixData[0][0] = roiFieldData;
        // get extental data id
        ExternalDataIdentifier newROIExtDataID = FRAPStudy.createNewExternalDataInfo(localWorkspace, FRAPStudy.ROI_SUMDATA_NAME).getExternalDataIdentifier();
        CartesianMesh cartesianMesh;
        try {
            cartesianMesh = getCartesianMesh();
            Origin origin = new Origin(0, 0, 0);
            FieldDataFileOperationSpec fdos = new FieldDataFileOperationSpec();
            fdos.opType = FieldDataFileOperationSpec.FDOS_ADD;
            fdos.cartesianMesh = cartesianMesh;
            fdos.shortSpecData = pixData;
            fdos.specEDI = newROIExtDataID;
            fdos.varNames = new String[] { "roiSumDataVar" };
            fdos.owner = LocalWorkspace.getDefaultOwner();
            fdos.times = new double[] { 0.0 };
            fdos.variableTypes = new VariableType[] { VariableType.VOLUME };
            fdos.origin = origin;
            fdos.extent = extent;
            fdos.isize = isize;
            localWorkspace.getDataSetControllerImpl().fieldDataFileOperation(fdos);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return new ROIDataGenerator(ROI_EXTDATA_NAME, /*name*/
        new int[] { 0 }, /* volumePoints*/
        new int[0], /* membranePoints*/
        regionCounter, /*numRegions*/
        0, /*zSlice*/
        newROIExtDataID.getKey(), /* fieldDataKey, sample image*/
        new FieldFunctionArguments(FRAPStudy.ROI_SUMDATA_NAME, "roiSumDataVar", new Expression(0), VariableType.VOLUME), /*FieldFunctionArguments, sample image*/
        false);
    }
    return null;
}
Also used : Origin(org.vcell.util.Origin) Extent(org.vcell.util.Extent) FieldFunctionArguments(cbit.vcell.field.FieldFunctionArguments) ISize(org.vcell.util.ISize) FieldDataFileOperationSpec(cbit.vcell.field.io.FieldDataFileOperationSpec) ROI(cbit.vcell.VirtualMicroscopy.ROI) ImageException(cbit.image.ImageException) UserCancelException(org.vcell.util.UserCancelException) CartesianMesh(cbit.vcell.solvers.CartesianMesh) Expression(cbit.vcell.parser.Expression) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier)

Example 7 with Origin

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

the class Image method crop.

static Image crop(Image origImage, Rectangle rect) throws ImageException {
    Object inArray = origImage.getPixelArray();
    Object outArray = Array.newInstance(inArray.getClass().getComponentType(), rect.width * rect.height * origImage.getNumZ());
    for (int k = 0; k < origImage.getNumZ(); k++) {
        for (int j = 0; j < rect.height; j++) {
            for (int i = 0; i < rect.width; i++) {
                int inIndex = rect.x + i + (j + rect.y) * origImage.getNumX() + k * origImage.getNumX() * origImage.getNumY();
                int outIndex = i + j * rect.width + (k * rect.width * rect.height);
                Array.set(outArray, outIndex, Array.get(inArray, inIndex));
            }
        }
    }
    Extent croppedExtent = null;
    if (origImage.getExtent() != null) {
        croppedExtent = new Extent(origImage.getExtent().getX() * rect.width / origImage.getNumX(), origImage.getExtent().getY() * rect.height / origImage.getNumY(), origImage.getExtent().getZ());
    }
    Origin croppedOrigin = null;
    if (origImage.getOrigin() != null) {
        croppedOrigin = new Origin(calcOriginPosition(origImage.getOrigin().getX(), rect.x, origImage.getExtent().getX(), origImage.getNumX()), calcOriginPosition(origImage.getOrigin().getY(), rect.y, origImage.getExtent().getY(), origImage.getNumY()), // origImage.getOrigin().getY()+(rect.y*(origImage.getExtent().getY()/origImage.getNumY())),
        origImage.getExtent().getZ());
    }
    if (origImage instanceof UShortImage) {
        return new UShortImage((short[]) outArray, croppedOrigin, croppedExtent, rect.width, rect.height, origImage.getNumZ());
    } else if (origImage instanceof ByteImage) {
        return new ByteImage((byte[]) outArray, croppedOrigin, croppedExtent, rect.width, rect.height, origImage.getNumZ());
    } else if (origImage instanceof FloatImage) {
        return new FloatImage((float[]) outArray, croppedOrigin, croppedExtent, rect.width, rect.height, origImage.getNumZ());
    }
    throw new ImageException("Crop if Image type " + origImage.getClass().getName() + " not implemented.");
}
Also used : Origin(org.vcell.util.Origin) ImageException(cbit.image.ImageException) Extent(org.vcell.util.Extent)

Example 8 with Origin

use of org.vcell.util.Origin 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 9 with Origin

use of org.vcell.util.Origin 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 10 with Origin

use of org.vcell.util.Origin 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)

Aggregations

Origin (org.vcell.util.Origin)64 Extent (org.vcell.util.Extent)58 ISize (org.vcell.util.ISize)45 CartesianMesh (cbit.vcell.solvers.CartesianMesh)18 VCImageUncompressed (cbit.image.VCImageUncompressed)17 FieldDataFileOperationSpec (cbit.vcell.field.io.FieldDataFileOperationSpec)17 ImageException (cbit.image.ImageException)14 RegionImage (cbit.vcell.geometry.RegionImage)14 VCImage (cbit.image.VCImage)13 ArrayList (java.util.ArrayList)13 Expression (cbit.vcell.parser.Expression)12 IOException (java.io.IOException)12 SubVolume (cbit.vcell.geometry.SubVolume)11 File (java.io.File)11 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)10 Geometry (cbit.vcell.geometry.Geometry)9 ExternalDataIdentifier (org.vcell.util.document.ExternalDataIdentifier)8 ImageDataset (cbit.vcell.VirtualMicroscopy.ImageDataset)7 BioModel (cbit.vcell.biomodel.BioModel)7 AnalyticSubVolume (cbit.vcell.geometry.AnalyticSubVolume)7