Search in sources :

Example 16 with RegionImage

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

the class SurfaceViewer method createQuadSurface.

/**
 * Comment
 */
private cbit.vcell.geometry.surface.SurfaceCollection createQuadSurface(cbit.vcell.geometry.Geometry geometry) throws cbit.image.ImageException, cbit.vcell.parser.ExpressionException, cbit.vcell.geometry.GeometryException {
    cbit.vcell.geometry.GeometrySpec geometrySpec = geometry.getGeometrySpec();
    if (geometrySpec.getDimension() > 0) {
        org.vcell.util.ISize sampleSize = geometrySpec.getDefaultSampledImageSize();
        // force to be 3D if at all spatial
        if (geometrySpec.getDimension() < 3) {
            sampleSize = new org.vcell.util.ISize(Math.max(2, sampleSize.getX()), Math.max(2, sampleSize.getY()), Math.max(2, sampleSize.getZ()));
            System.out.println("SurfaceViewer.createSurface(): padding geometry from " + geometrySpec.getDimension() + "D to 3D for surface generation - region determination");
        }
        System.out.println("SurfaceViewer.createSurface(): size = " + sampleSize);
        cbit.image.VCImage image = geometrySpec.createSampledImage(sampleSize);
        cbit.vcell.geometry.RegionImage regionImage = new cbit.vcell.geometry.RegionImage(image, 3, geometrySpec.getExtent(), geometrySpec.getOrigin(), RegionImage.NO_SMOOTHING);
        // return surfaceCollection;
        return regionImage.getSurfacecollection();
    } else {
        return null;
    }
}
Also used : RegionImage(cbit.vcell.geometry.RegionImage) RegionImage(cbit.vcell.geometry.RegionImage)

Example 17 with RegionImage

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

the class ROIAssistPanel method calculateRegionInfos.

private RegionInfo[] calculateRegionInfos(short[] validatePixels) throws Exception {
    byte[] roiBytes = new byte[validatePixels.length];
    for (int i = 0; i < roiBytes.length; i++) {
        roiBytes[i] = (byte) (validatePixels[i] == 0 ? 0 : 1);
    }
    VCImageUncompressed roiVCImage = new VCImageUncompressed(null, roiBytes, new Extent(1, 1, 1), originalROI.getISize().getX(), originalROI.getISize().getY(), originalROI.getISize().getZ());
    RegionImage roiRegionImage = new RegionImage(roiVCImage, 0, null, null, RegionImage.NO_SMOOTHING);
    return roiRegionImage.getRegionInfos();
}
Also used : Extent(org.vcell.util.Extent) RegionImage(cbit.vcell.geometry.RegionImage) VCImageUncompressed(cbit.image.VCImageUncompressed)

Example 18 with RegionImage

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

the class ROIMultiPaintManager method fillVoids.

private boolean fillVoids(BufferedImage[] roiPixels, boolean bCheckOnly) throws Exception {
    if (true) {
        throw new IllegalArgumentException("Not yet implemented fully");
    }
    boolean bHadAnyInternalVoids = false;
    int xSize = roiPixels[0].getWidth();
    int ySize = roiPixels[0].getHeight();
    int zSize = roiPixels.length;
    int XYSIZE = xSize * ySize;
    boolean bUseZ = roiPixels.length > 1;
    VCImage checkImage = ROIMultiPaintManager.createVCImageFromBufferedImages(getImageDataSetChannel().getExtent(), roiComposite);
    RegionImage regionImage = new RegionImage(checkImage, 0, /*0 means generate no surfacecollection*/
    checkImage.getExtent(), getImageDataSetChannel().getAllImages()[0].getOrigin(), RegionImage.NO_SMOOTHING, progressWaitPopup);
    RegionInfo[] newRegionInfos = regionImage.getRegionInfos();
    for (int i = 0; i < newRegionInfos.length; i++) {
        if (newRegionInfos[i].getPixelValue() == 0) {
            boolean bInternalVoid = true;
            for (int z = 0; z < zSize; z++) {
                int zOffset = z * XYSIZE;
                for (int y = 0; y < ySize; y++) {
                    int yoffset = y * xSize;
                    int zyOffset = zOffset + yoffset;
                    for (int x = 0; x < xSize; x++) {
                        if (newRegionInfos[i].isIndexInRegion(zyOffset + x)) {
                            if (x == 0 || y == 0 | (bUseZ && z == 0) | x == (xSize - 1) || y == (ySize - 1) || (bUseZ && z == (zSize - 1))) {
                                bInternalVoid = false;
                                break;
                            }
                        }
                    }
                    if (!bInternalVoid) {
                        break;
                    }
                }
                if (!bInternalVoid) {
                    break;
                }
            }
            if (bInternalVoid) {
                bHadAnyInternalVoids = true;
                if (bCheckOnly) {
                    return bHadAnyInternalVoids;
                }
                for (int z = 0; z < zSize; z++) {
                    byte[] roiPixelsBytes = ((DataBufferByte) roiPixels[z].getRaster().getDataBuffer()).getData();
                    for (int xy = 0; xy < XYSIZE; xy++) {
                    // if(newRegionInfos[i].isIndexInRegion(j)){
                    // fillvoidPixels[j]|= 0xFFFF;
                    // }
                    }
                }
            }
        }
    }
    return bHadAnyInternalVoids;
}
Also used : RegionImage(cbit.vcell.geometry.RegionImage) VCImage(cbit.image.VCImage) RegionInfo(cbit.vcell.geometry.RegionImage.RegionInfo) DataBufferByte(java.awt.image.DataBufferByte) Point(java.awt.Point)

Example 19 with RegionImage

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

the class VFrap_ROIAssistPanel method calculateRegionInfos.

private RegionInfo[] calculateRegionInfos(short[] validatePixels) throws Exception {
    byte[] roiBytes = new byte[validatePixels.length];
    for (int i = 0; i < roiBytes.length; i++) {
        roiBytes[i] = (byte) (validatePixels[i] == 0 ? 0 : 1);
    }
    VCImageUncompressed roiVCImage = new VCImageUncompressed(null, roiBytes, new Extent(1, 1, 1), originalROI.getISize().getX(), originalROI.getISize().getY(), originalROI.getISize().getZ());
    RegionImage roiRegionImage = new RegionImage(roiVCImage, 0, null, null, RegionImage.NO_SMOOTHING);
    return roiRegionImage.getRegionInfos();
}
Also used : Extent(org.vcell.util.Extent) RegionImage(cbit.vcell.geometry.RegionImage) VCImageUncompressed(cbit.image.VCImageUncompressed)

Example 20 with RegionImage

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

the class RasterExporter method writeStanfordPolygonTex.

public static PolyTexHelper writeStanfordPolygonTex(RegionImage regionImage, Writer writer, /*BitSet bInDomain,*/
CartesianMesh mesh) throws IOException, MathException {
    int totalPolygons = regionImage.getSurfacecollection().getTotalPolygonCount();
    int totalVerts = totalPolygons * 4;
    final int ALL_NEIGHBOR_QUAD_BOX_SIDE = 3;
    // 2D image texture
    int imgSideSize = (int) Math.ceil(Math.sqrt((totalPolygons)));
    int texelXSize = (imgSideSize * ALL_NEIGHBOR_QUAD_BOX_SIDE);
    int[][] texIndexToFaceIndexPtrs = new int[texelXSize * texelXSize][0];
    // Arrays.fill(texImage0, Integer.MAX_VALUE);
    final int squareSize = 40;
    int fontXSize = texelXSize * squareSize;
    int fontYSize = texelXSize * squareSize;
    BufferedImage image0 = createTextureImage(fontXSize);
    // int[] texFontImage = new int[fontXSize*fontYSize];
    // Arrays.fill(texFontImage, 0xFF000000);
    // int[] bitMasks0 = new int[]{0xFF0000, 0xFF00, 0xFF, 0xFF000000};
    // SinglePixelPackedSampleModel sm0 = new SinglePixelPackedSampleModel(
    // DataBuffer.TYPE_INT, texelXSize*squareSize, texelXSize*squareSize, bitMasks0);
    // DataBufferInt db0 = new DataBufferInt(texFontImage, texFontImage.length);
    // WritableRaster wr0 = Raster.createWritableRaster(sm0, db0, new Point());
    // BufferedImage image0 = new BufferedImage(ColorModel.getRGBdefault(), wr0, false, null);
    Graphics2D g2d = image0.createGraphics();
    g2d.setColor(Color.white);
    Font bigF = Font.decode("Dialog-plain-10");
    g2d.setFont(bigF);
    float texelSize = 1.0f / texelXSize;
    writer.write("ply\n");
    writer.write("format ascii 1.0\n");
    // writer.write("comment "+geometrySurfaceDescription.getGeometry().getName()+"\n");
    writer.write("comment textureImage size is " + imgSideSize + "x" + imgSideSize + "\n");
    writer.write("element vertex " + totalVerts + "\n");
    writer.write("property float x\n");
    writer.write("property float y\n");
    writer.write("property float z\n");
    // must be 's' for blender (u texture coord)
    writer.write("property float s\n");
    // must be 't' for blender (v texture coord)
    writer.write("property float t\n");
    writer.write("element face " + totalPolygons + "\n");
    writer.write("property list uchar int vertex_index\n");
    writer.write("end_header\n");
    StringBuffer sbVert = new StringBuffer();
    StringBuffer sbFace = new StringBuffer();
    int faceIndex = 0;
    int vertIndex = 0;
    for (int currSurf = 0; currSurf < regionImage.getSurfacecollection().getSurfaceCount(); currSurf++) {
        for (int currFace = 0; currFace < regionImage.getSurfacecollection().getSurfaces(currSurf).getPolygonCount(); currFace++) {
            // if(bInDomain != null && !bInDomain.get(faceIndex)){
            // continue;
            // }
            g2d.setColor(Color.white);
            Quadrilateral quad = (Quadrilateral) regionImage.getSurfacecollection().getSurfaces(currSurf).getPolygons(currFace);
            NAHelper naHelper0 = calcNAHelper(quad);
            Point2D p2dm = Coordinate.get2DProjection(naHelper0.middle, naHelper0.normalAxis);
            int x = faceIndex % imgSideSize;
            int y = faceIndex / imgSideSize;
            int boxX = (x * ALL_NEIGHBOR_QUAD_BOX_SIDE) + 1;
            int boxY = (y * ALL_NEIGHBOR_QUAD_BOX_SIDE) + 1;
            int fontX = boxX * squareSize;
            int fontY = boxY * squareSize;
            // das.getColorFromValue(data[faceIndex]);//face color
            texIndexToFaceIndexPtrs[boxY * texelXSize + boxX] = new int[] { faceIndex };
            g2d.drawString(currSurf + "-" + currFace, fontX, fontY);
            float imgXTexelCenter = (boxX + .5f) * texelSize;
            float imgYTexelCenter = (boxY + .5f) * texelSize;
            ArrayList<RegionImage.MembraneEdgeNeighbor> neighbors = regionImage.getMembraneEdgeNeighbors()[currSurf][currFace];
            sbFace.append(quad.getNodeCount() + "");
            for (int vrt = 0; vrt < quad.getNodeCount(); vrt++) {
                g2d.setColor(Color.white);
                RegionImage.MembraneEdgeNeighbor membraneEdgeNeighbor = neighbors.get(vrt);
                MembraneElementIdentifier neighb = membraneEdgeNeighbor.getMembraneElementIdentifier();
                if (neighb != null) {
                    Quadrilateral quadNeighbor = (Quadrilateral) regionImage.getSurfacecollection().getSurfaces(neighb.surfaceIndex).getPolygons(neighb.nonMasterPolygonIndex);
                    NAHelper naHelper1 = calcNAHelper(quadNeighbor);
                    Point2D p2dmNeighb = Coordinate.get2DProjection(naHelper1.middle, naHelper0.normalAxis);
                    double xdiff = p2dmNeighb.getX() - p2dm.getX();
                    double ydiff = p2dmNeighb.getY() - p2dm.getY();
                    int dxn = (int) Math.signum((Math.abs(xdiff) < 1e-9 ? 0 : xdiff));
                    int dyn = (int) Math.signum((Math.abs(ydiff) < 1e-9 ? 0 : ydiff));
                    // das.getColorFromValue(data[membraneEdgeNeighbor.getMasterPolygonIndex()]);
                    texIndexToFaceIndexPtrs[(boxY + dyn) * texelXSize + (boxX + dxn)] = new int[] { membraneEdgeNeighbor.getMasterPolygonIndex() };
                    g2d.drawString(neighb.nonMasterPolygonIndex + "", fontX + (dxn * squareSize), fontY + (dyn * squareSize));
                    RegionImage.MembraneEdgeNeighbor membraneEdgeNeighbor2 = neighbors.get((vrt + 1 == quad.getNodeCount() ? 0 : vrt + 1));
                    MembraneElementIdentifier neighb2 = membraneEdgeNeighbor2.getMembraneElementIdentifier();
                    if (neighb2 != null) {
                        CommonNeighb commonNeighb = calculateCommonNeighbor(mesh, regionImage, mesh.getMembraneElements()[membraneEdgeNeighbor.getMasterPolygonIndex()], mesh.getMembraneElements()[membraneEdgeNeighbor2.getMasterPolygonIndex()], faceIndex);
                        if (commonNeighb != null) {
                            if (commonNeighb.neighborneighbos.size() == 0) {
                                commonNeighb.neighborneighbos.add(membraneEdgeNeighbor.getMasterPolygonIndex());
                                commonNeighb.neighborneighbos.add(membraneEdgeNeighbor2.getMasterPolygonIndex());
                            }
                            // mesh.getMembraneElements()[commonNeighb].getCentroid();
                            Coordinate commonCoord = new Coordinate(commonNeighb.node.getX(), commonNeighb.node.getY(), commonNeighb.node.getZ());
                            Point2D p2dmcommon = Coordinate.get2DProjection(commonCoord, naHelper0.normalAxis);
                            double xdiff1 = p2dmcommon.getX() - p2dm.getX();
                            double ydiff1 = p2dmcommon.getY() - p2dm.getY();
                            int dxc = (int) Math.signum((Math.abs(xdiff1) < 1e-9 ? 0 : xdiff1));
                            int dyc = (int) Math.signum((Math.abs(ydiff1) < 1e-9 ? 0 : ydiff1));
                            g2d.setColor(Color.green);
                            int xloc = fontX + (dxc * squareSize);
                            int yloc = fontY + (dyc * squareSize);
                            double avgVal = 0;
                            int texIndex = (boxY + dyc) * texelXSize + boxX + dxc;
                            texIndexToFaceIndexPtrs[texIndex] = new int[commonNeighb.neighborneighbos.size()];
                            for (int k = 0; k < commonNeighb.neighborneighbos.size(); k++) {
                                g2d.drawString(regionImage.getQuadIndexToSurfAndFace().get(commonNeighb.neighborneighbos.get(k)).getFace() + "", xloc, yloc + (k * 11));
                                // avgVal+= data[commonNeighb.neighborneighbos.get(k)];
                                // das.getColorFromValue(avgVal/commonNeighb.neighborneighbos.size());
                                texIndexToFaceIndexPtrs[texIndex][k] = commonNeighb.neighborneighbos.get(k);
                            }
                        // if(texImage0[texIndex] != Integer.MAX_VALUE){
                        // System.out.println("texture pixel used twice");
                        // }
                        }
                    }
                } else {
                    System.out.println("neighbor null");
                }
                Point2D p2dv = Coordinate.get2DProjection(new Coordinate(quad.getNodes(vrt).getX(), quad.getNodes(vrt).getY(), quad.getNodes(vrt).getZ()), naHelper0.normalAxis);
                double xdiff3 = p2dv.getX() - p2dm.getX();
                double ydiff3 = p2dv.getY() - p2dm.getY();
                int dx = (int) Math.signum((Math.abs(xdiff3) < 1e-9 ? 0 : xdiff3));
                int dy = (int) Math.signum((Math.abs(ydiff3) < 1e-9 ? 0 : ydiff3));
                float u = (float) imgXTexelCenter + ((float) dx * texelSize / 2.0f);
                float v = (float) imgYTexelCenter + ((float) dy * texelSize / 2.0f);
                Node vertex = quad.getNodes()[vrt];
                sbVert.append((float) vertex.getX() + " " + (float) vertex.getY() + " " + (float) vertex.getZ() + " " + u + " " + v + "\n");
                sbFace.append(" ");
                sbFace.append(vertIndex + "");
                vertIndex++;
            }
            sbFace.append("\n");
            faceIndex++;
        }
    }
    if (faceIndex != totalPolygons || vertIndex != totalVerts) {
        throw new IOException("Final faces and verts count don't match");
    }
    writer.write(sbVert.toString());
    writer.write(sbFace.toString());
    // ImageIO.write(op0.filter(image0, null), "png", baos);
    return new PolyTexHelper(texIndexToFaceIndexPtrs, flipPNG(image0), texelXSize);
}
Also used : Node(cbit.vcell.geometry.surface.Node) IOException(java.io.IOException) Point(java.awt.Point) BufferedImage(java.awt.image.BufferedImage) Font(java.awt.Font) MembraneElementIdentifier(cbit.vcell.geometry.RegionImage.MembraneElementIdentifier) Graphics2D(java.awt.Graphics2D) Quadrilateral(cbit.vcell.geometry.surface.Quadrilateral) Point2D(java.awt.geom.Point2D) Coordinate(org.vcell.util.Coordinate) RegionImage(cbit.vcell.geometry.RegionImage)

Aggregations

RegionImage (cbit.vcell.geometry.RegionImage)34 VCImageUncompressed (cbit.image.VCImageUncompressed)18 ISize (org.vcell.util.ISize)18 Extent (org.vcell.util.Extent)17 CartesianMesh (cbit.vcell.solvers.CartesianMesh)16 Origin (org.vcell.util.Origin)14 VCImage (cbit.image.VCImage)11 FieldDataFileOperationSpec (cbit.vcell.field.io.FieldDataFileOperationSpec)11 VariableType (cbit.vcell.math.VariableType)7 Point (java.awt.Point)6 UserCancelException (org.vcell.util.UserCancelException)6 ExternalDataIdentifier (org.vcell.util.document.ExternalDataIdentifier)6 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)5 RegionInfo (cbit.vcell.geometry.RegionImage.RegionInfo)4 BufferedImage (java.awt.image.BufferedImage)4 Hashtable (java.util.Hashtable)4 ImageException (cbit.image.ImageException)3 ImageDataset (cbit.vcell.VirtualMicroscopy.ImageDataset)3 DocumentManager (cbit.vcell.clientdb.DocumentManager)3 Surface (cbit.vcell.geometry.surface.Surface)3