Search in sources :

Example 6 with CoordinateIndex

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

the class MathTestingUtilities method resample1DSpatialSimple.

/**
 * Insert the method's description here.
 * Creation date: (10/27/2003 5:07:42 PM)
 * @return double[]
 * @param data double[]
 * @param sourceMesh cbit.vcell.solvers.CartesianMesh
 * @param targetMesh cbit.vcell.solvers.CartesianMesh
 */
public static double[] resample1DSpatialSimple(double[] sourceData, CartesianMesh sourceMesh, CartesianMesh refMesh) {
    if (sourceData.length != sourceMesh.getNumVolumeElements()) {
        throw new RuntimeException("must be volume data, data length doesn't match number of volume elements");
    }
    // for volume samples:
    // 
    // loop through volumeIndexes from refMesh
    // Coordinate refCoordinate = refMesh.getCoordinate(volumeIndex);
    // Coordinate fractionalIndex = sourceMesh.getFractionCoordinateIndex(Coordinate refCoordinate);
    // ....interpolate in z
    // start with integer portion of fractionIndex
    double[] resampledData = new double[refMesh.getSizeX()];
    for (int i = 0; i < resampledData.length; i++) {
        Coordinate refCoordinate = refMesh.getCoordinateFromVolumeIndex(i);
        Coordinate fractionalIndex = sourceMesh.getFractionalCoordinateIndex(refCoordinate);
        int ceil_x;
        int floor_x;
        if (fractionalIndex.getX() < 0) {
            floor_x = 0;
            ceil_x = 1;
        } else if (fractionalIndex.getX() > sourceMesh.getSizeX() - 1) {
            floor_x = sourceMesh.getSizeX() - 2;
            ceil_x = sourceMesh.getSizeX() - 1;
        } else {
            ceil_x = (int) Math.ceil(fractionalIndex.getX());
            floor_x = (int) Math.floor(fractionalIndex.getX());
        }
        double fract_x = fractionalIndex.getX() - floor_x;
        // ***** SHOULD Y,Z BE 0 OR 1 ???? *****
        CoordinateIndex coord_1 = new CoordinateIndex(floor_x, 0, 0);
        CoordinateIndex coord_2 = new CoordinateIndex(ceil_x, 0, 0);
        int volIndx1 = sourceMesh.getVolumeIndex(coord_1);
        int volIndx2 = sourceMesh.getVolumeIndex(coord_2);
        // Interpolate in X - final resampledSourceData value
        resampledData[i] = sourceData[volIndx1] + fract_x * (sourceData[volIndx2] - sourceData[volIndx1]);
    }
    return resampledData;
}
Also used : Coordinate(org.vcell.util.Coordinate) CoordinateIndex(org.vcell.util.CoordinateIndex)

Example 7 with CoordinateIndex

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

the class MeshDisplayAdapter method determineOrder.

/**
 * Insert the method's description here.
 * Creation date: (9/2/00 4:44:31 PM)
 * @return boolean
 */
private int determineOrder(MembraneElement from, MembraneElement to, int normalAxis) {
    CoordinateIndex ciFrom = null;
    CoordinateIndex ciTo = null;
    if (from.getOutsideVolumeIndex() == to.getOutsideVolumeIndex()) {
        // Inside Corner
        ciFrom = mesh.getCoordinateIndexFromVolumeIndex(from.getInsideVolumeIndex());
        ciTo = mesh.getCoordinateIndexFromVolumeIndex(to.getInsideVolumeIndex());
    } else if (from.getInsideVolumeIndex() == to.getInsideVolumeIndex()) {
        // Outside Corner
        ciFrom = mesh.getCoordinateIndexFromVolumeIndex(from.getOutsideVolumeIndex());
        ciTo = mesh.getCoordinateIndexFromVolumeIndex(to.getOutsideVolumeIndex());
    } else {
        // Edge, can be either inside or outside, doesn't matter
        ciFrom = mesh.getCoordinateIndexFromVolumeIndex(from.getInsideVolumeIndex());
        ciTo = mesh.getCoordinateIndexFromVolumeIndex(to.getInsideVolumeIndex());
    }
    int[] deltaXYZ = new int[3];
    deltaXYZ[Coordinate.X_AXIS] = ciTo.x - ciFrom.x;
    deltaXYZ[Coordinate.Y_AXIS] = ciTo.y - ciFrom.y;
    deltaXYZ[Coordinate.Z_AXIS] = ciTo.z - ciFrom.z;
    int toMembranePlane = getParalellAxis(to, normalAxis);
    boolean bP0 = (deltaXYZ[toMembranePlane] < 0);
    int fromMembranePlane = getParalellAxis(from, normalAxis);
    boolean bPrepend = (deltaXYZ[fromMembranePlane] < 0);
    return (0x00 | (bPrepend ? ORDER_PREPEND : 0) | (bP0 ? ORDER_P0 : 0));
}
Also used : CoordinateIndex(org.vcell.util.CoordinateIndex)

Example 8 with CoordinateIndex

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

the class SpatialSelectionVolume method getMeshIndexFromU.

private int getMeshIndexFromU(double u) {
    Coordinate wc = getSamplingWorldCoordinate(u);
    CoordinateIndex ci = getCoordinateIndexFromWC(wc);
    return getMesh().getVolumeIndex(ci);
}
Also used : Coordinate(org.vcell.util.Coordinate) CoordinateIndex(org.vcell.util.CoordinateIndex)

Example 9 with CoordinateIndex

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

the class ROIMultiPaintManager method generateHighlightROIInfo.

private static HighlightROIInfo generateHighlightROIInfo(byte debugValue, BufferedImage[] roiArr, RegionImage regionImage, RegionAction regionAction, ClientTaskStatusSupport clientTaskStatusSupport) throws Exception {
    HighlightROIInfo highlightROIInfo = new HighlightROIInfo();
    // Create lookup map to speedup highlighting operation for large dataset
    RegionImage.RegionInfo[] selectedRegionMap = new RegionImage.RegionInfo[regionAction.getAllRegionInfos().length];
    Iterator<RegionImage.RegionInfo> selectedIter = regionAction.getSelectedRegionInfos().iterator();
    while (selectedIter.hasNext()) {
        RegionImage.RegionInfo nextRegion = selectedIter.next();
        selectedRegionMap[nextRegion.getRegionIndex()] = nextRegion;
    }
    byte[] shortEncodedRegionIndexes = regionImage.getShortEncodedRegionIndexImage();
    final int XSIZE = roiArr[0].getWidth();
    if (regionAction.getAction() == RegionAction.REGION_ACTION_HIGHLIGHT) {
        highlightROIInfo.highlightROI = createEmptyROI(new ISize(roiArr[0].getWidth(), roiArr[0].getHeight(), roiArr.length));
    }
    int allIndex = 0;
    final int ZMAX = roiArr.length - 1;
    final int XMAX = roiArr[0].getWidth() - 1;
    final int YMAX = roiArr[0].getHeight() - 1;
    for (int z = 0; z < roiArr.length; z++) {
        if (clientTaskStatusSupport != null && clientTaskStatusSupport.isInterrupted()) {
            return null;
        }
        int index = 0;
        byte[] zSlice = ((DataBufferByte) roiArr[z].getRaster().getDataBuffer()).getData();
        for (int y = 0; y < roiArr[0].getHeight(); y++) {
            for (int x = 0; x < XSIZE; x++) {
                int regionIndex = (shortEncodedRegionIndexes[allIndex] & 0x000000FF) | (shortEncodedRegionIndexes[allIndex + 1] & 0x000000FF) << 8;
                if (selectedRegionMap[regionIndex] != null) {
                    RegionInfo currentRegionInfo = selectedRegionMap[regionIndex];
                    if (regionAction.getAction() == RegionAction.REGION_ACTION_CHECKNEIGHBORSONLY) {
                        // Find neighbors
                        int[] neighbors = new int[6];
                        Arrays.fill(neighbors, -1);
                        if (z > 0) {
                            // top neighbor
                            neighbors[0] = 0x000000FF & ((DataBufferByte) roiArr[z - 1].getRaster().getDataBuffer()).getData()[index];
                        }
                        if (z < ZMAX) {
                            // bottom neighbor
                            neighbors[1] = 0x000000FF & ((DataBufferByte) roiArr[z + 1].getRaster().getDataBuffer()).getData()[index];
                        }
                        if (x > 0) {
                            // left neighbor
                            neighbors[2] = 0x000000FF & ((DataBufferByte) roiArr[z].getRaster().getDataBuffer()).getData()[index - 1];
                        }
                        if (x < XMAX) {
                            // right neighbor
                            neighbors[3] = 0x000000FF & ((DataBufferByte) roiArr[z].getRaster().getDataBuffer()).getData()[index + 1];
                        }
                        if (y > 0) {
                            // front neighbor
                            neighbors[4] = 0x000000FF & ((DataBufferByte) roiArr[z].getRaster().getDataBuffer()).getData()[index - XSIZE];
                        }
                        if (y < YMAX) {
                            // back neighbor
                            neighbors[5] = 0x000000FF & ((DataBufferByte) roiArr[z].getRaster().getDataBuffer()).getData()[index + XSIZE];
                        }
                        if (!highlightROIInfo.neighborsForRegionsMap.containsKey(currentRegionInfo)) {
                            highlightROIInfo.neighborsForRegionsMap.put(currentRegionInfo, new TreeSet<Integer>());
                        }
                        TreeSet<Integer> neighborTreeSet = highlightROIInfo.neighborsForRegionsMap.get(currentRegionInfo);
                        for (int i = 0; i < neighbors.length; i++) {
                            if (neighbors[i] != -1 && neighbors[i] != currentRegionInfo.getPixelValue()) {
                                neighborTreeSet.add(neighbors[i]);
                            }
                        }
                        if (!highlightROIInfo.coordIndexForRegionsMap.containsKey(currentRegionInfo)) {
                            highlightROIInfo.coordIndexForRegionsMap.put(currentRegionInfo, new CoordinateIndex(x, y, z));
                        }
                    } else if (regionAction.getAction() == RegionAction.REGION_ACTION_HIGHLIGHT) {
                        highlightROIInfo.highlightROI.getRoiImages()[z].getPixels()[index] = 1;
                    } else if (regionAction.getAction() == RegionAction.REGION_ACTION_MERGESELECTEDWITHNEIGHBORS) {
                        int numNeighbors = regionAction.getNeighborsForRegionMap().get(currentRegionInfo).size();
                        if (/*!regionAction.bLeaveMultiNeighborUnchanged || */
                        numNeighbors == 1) {
                            zSlice[index] = (byte) regionAction.getNeighborsForRegionMap().get(currentRegionInfo).first().intValue();
                        } else {
                            boolean hasBG = false;
                            Integer randomNeighbor = null;
                            Iterator<Integer> pixelValIter = regionAction.getNeighborsForRegionMap().get(currentRegionInfo).iterator();
                            while (pixelValIter.hasNext()) {
                                Integer pixelValue = pixelValIter.next();
                                if (pixelValue == 0) {
                                    hasBG = true;
                                    break;
                                } else {
                                    randomNeighbor = pixelValue;
                                }
                            }
                            if (hasBG) {
                                // merge with background
                                zSlice[index] = 0;
                            } else {
                                // merge with random
                                zSlice[index] = randomNeighbor.byteValue();
                            }
                        }
                    }
                }
                index++;
                allIndex += 2;
            }
        }
    }
    return highlightROIInfo;
}
Also used : RegionInfo(cbit.vcell.geometry.RegionImage.RegionInfo) ISize(org.vcell.util.ISize) RegionInfo(cbit.vcell.geometry.RegionImage.RegionInfo) DataBufferByte(java.awt.image.DataBufferByte) CoordinateIndex(org.vcell.util.CoordinateIndex) Point(java.awt.Point) RegionImage(cbit.vcell.geometry.RegionImage)

Example 10 with CoordinateIndex

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

the class ROIMultiPaintManager method padCropDataset.

private void padCropDataset() {
    int xm = 0;
    int ym = 0;
    int zm = 0;
    int xp = 0;
    int yp = 0;
    int zp = 0;
    String result = null;
    do {
        try {
            result = DialogUtils.showInputDialog0(overlayEditorPanelJAI, "Enter the number of pixels to add or crop (negative number) at each border: (xlow,ylow,zlow,xhigh,yhigh,zhigh)", xm + "," + ym + "," + zm + "," + xp + "," + yp + "," + zp);
            if (result != null) {
                final String SEP = ",";
                result = result.trim();
                StringTokenizer st = new StringTokenizer(result, SEP);
                xm = Integer.parseInt(st.nextToken());
                ym = Integer.parseInt(st.nextToken());
                zm = Integer.parseInt(st.nextToken());
                xp = Integer.parseInt(st.nextToken());
                yp = Integer.parseInt(st.nextToken());
                zp = Integer.parseInt(st.nextToken());
                if (st.hasMoreElements() || result.endsWith(SEP)) {
                    throw new Exception("Some input was not parsed, check input.");
                }
                break;
            }
        } catch (UtilCancelException e) {
            throw UserCancelException.CANCEL_GENERIC;
        } catch (Exception e) {
            DialogUtils.showErrorDialog(overlayEditorPanelJAI, "Error parsing '" + result + "' Resetting to valid values.  Enter 6 comma separated integers.");
        }
    } while (true);
    final CoordinateIndex low = new CoordinateIndex(xm, ym, zm);
    final CoordinateIndex high = new CoordinateIndex(xp, yp, zp);
    final AsynchClientTask padTask = new AsynchClientTask("Changeing borders...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            resizeImpl(ResizeInfo.createPadCropResizeInfo(getImageDataSetChannel().getISize(), low, high), getClientTaskStatusSupport());
        }
    };
    final AsynchClientTask updatePanelTask = getUpdateDisplayAfterCropTask();
    ClientTaskDispatcher.dispatch(overlayEditorPanelJAI, new Hashtable<String, Object>(), new AsynchClientTask[] { padTask, updatePanelTask }, false, false, null, true);
}
Also used : StringTokenizer(java.util.StringTokenizer) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) UtilCancelException(org.vcell.util.UtilCancelException) Hashtable(java.util.Hashtable) CoordinateIndex(org.vcell.util.CoordinateIndex) Point(java.awt.Point) UtilCancelException(org.vcell.util.UtilCancelException) UserCancelException(org.vcell.util.UserCancelException)

Aggregations

CoordinateIndex (org.vcell.util.CoordinateIndex)30 Coordinate (org.vcell.util.Coordinate)15 Point (java.awt.Point)7 SinglePoint (cbit.vcell.geometry.SinglePoint)4 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)3 Hashtable (java.util.Hashtable)3 Vector (java.util.Vector)3 ISize (org.vcell.util.ISize)3 CurveSelectionInfo (cbit.vcell.geometry.CurveSelectionInfo)2 RegionImage (cbit.vcell.geometry.RegionImage)2 SampledCurve (cbit.vcell.geometry.SampledCurve)2 DataBufferByte (java.awt.image.DataBufferByte)2 StringTokenizer (java.util.StringTokenizer)2 DisplayAdapterService (cbit.image.DisplayAdapterService)1 SourceDataInfo (cbit.image.SourceDataInfo)1 VCImage (cbit.image.VCImage)1 VCImageUncompressed (cbit.image.VCImageUncompressed)1 ImagePlaneManagerPanel (cbit.image.gui.ImagePlaneManagerPanel)1 Plot2D (cbit.plot.Plot2D)1 PlotData (cbit.plot.PlotData)1