Search in sources :

Example 51 with Coordinate

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

Example 52 with Coordinate

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

the class SampledCurve method getDistanceToSampledCurve.

/**
 * This method was created in VisualAge.
 * @return double
 * @param coord cbit.vcell.geometry.Coordinate
 */
protected double getDistanceToSampledCurve(Coordinate coord) {
    int segmentCount = getSegmentCount();
    int controlPointCount = getControlPointCount();
    double shortestDistance = Double.MAX_VALUE;
    Coordinate p0 = null;
    Coordinate p1 = null;
    for (int i = 0; i < segmentCount; i += 1) {
        p0 = getControlPoint(i);
        p1 = getControlPoint((i + 1) % controlPointCount);
        double distance = getDistanceToLine(p0, p1, coord);
        if (distance < shortestDistance) {
            shortestDistance = distance;
        }
    }
    return shortestDistance;
}
Also used : Coordinate(org.vcell.util.Coordinate)

Example 53 with Coordinate

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

the class SampledCurve method getControlPointsForSegment.

/**
 * Insert the method's description here.
 * Creation date: (10/9/2004 6:55:12 PM)
 * @return cbit.vcell.geometry.Coordinate[]
 * @param sgementIndex int
 */
public Coordinate[] getControlPointsForSegment(int segmentIndex) {
    int controlPointCount = getControlPointCount();
    Coordinate p0 = null;
    Coordinate p1 = null;
    p0 = getControlPoint(segmentIndex);
    p1 = getControlPoint((segmentIndex + 1) % controlPointCount);
    return new Coordinate[] { p0, p1 };
}
Also used : Coordinate(org.vcell.util.Coordinate)

Example 54 with Coordinate

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

the class SampledCurve method coordinateFromNormalizedU.

/**
 * Insert the method's description here.
 * Creation date: (2/15/2001 1:42:43 PM)
 * @return cbit.vcell.geometry.Coordinate
 * @param normalizedU double
 */
public Coordinate coordinateFromNormalizedU(double normalizedU) {
    // 
    if (normalizedU < 0 || normalizedU > 1.0) {
        throw new RuntimeException("coordinateFromNormalizedU: normalizedU must be between 0 and 1");
    }
    // 
    Coordinate result = null;
    int segmentCount = getSegmentCount();
    int controlPointCount = getControlPointCount();
    Coordinate p0 = null;
    Coordinate p1 = null;
    // 
    double[] segmentLength = new double[segmentCount];
    double[] accumLength = new double[segmentCount];
    double totalLength = 0;
    for (int i = 0; i < segmentCount; i += 1) {
        p0 = getControlPoint(i);
        p1 = getControlPoint((i + 1) % controlPointCount);
        segmentLength[i] = p0.distanceTo(p1);
        accumLength[i] = totalLength;
        totalLength += segmentLength[i];
    }
    double targetLength = normalizedU * totalLength;
    // 
    for (int i = 0; i < segmentCount; i += 1) {
        if (targetLength >= accumLength[i] && targetLength <= (accumLength[i] + segmentLength[i])) {
            double segmentU = -1.0;
            if (segmentLength[i] == 0 && (i + 1) == segmentCount) {
                // Fix problem with duplicate points at end have 0 segment length and create NaN
                segmentU = 1.0;
            } else {
                segmentU = (targetLength - accumLength[i]) / segmentLength[i];
            }
            p0 = getControlPoint(i);
            p1 = getControlPoint((i + 1) % controlPointCount);
            double uX = p0.getX() + ((p1.getX() - p0.getX()) * segmentU);
            double uY = p0.getY() + ((p1.getY() - p0.getY()) * segmentU);
            double uZ = p0.getZ() + ((p1.getZ() - p0.getZ()) * segmentU);
            result = new Coordinate(uX, uY, uZ);
        }
    }
    return result;
}
Also used : Coordinate(org.vcell.util.Coordinate)

Example 55 with Coordinate

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

the class ControlPointCurve method compareEqual.

/**
 * compareEqual method comment.
 */
public boolean compareEqual(org.vcell.util.Matchable obj) {
    if (!super.compareEqual(obj)) {
        return false;
    }
    if (!(obj instanceof ControlPointCurve)) {
        return false;
    }
    ControlPointCurve cpc = (ControlPointCurve) obj;
    if (controlPoints.size() != cpc.controlPoints.size()) {
        return false;
    }
    for (int c = 0; c < controlPoints.size(); c += 1) {
        Coordinate thisCoord = controlPoints.elementAt(c);
        Coordinate cpcCoord = (Coordinate) cpc.controlPoints.elementAt(c);
        if (!org.vcell.util.Compare.isEqual(thisCoord, cpcCoord)) {
            return false;
        }
    }
    return true;
}
Also used : Coordinate(org.vcell.util.Coordinate)

Aggregations

Coordinate (org.vcell.util.Coordinate)81 CoordinateIndex (org.vcell.util.CoordinateIndex)16 SampledCurve (cbit.vcell.geometry.SampledCurve)11 SinglePoint (cbit.vcell.geometry.SinglePoint)11 ControlPointCurve (cbit.vcell.geometry.ControlPointCurve)10 CurveSelectionInfo (cbit.vcell.geometry.CurveSelectionInfo)6 Expression (cbit.vcell.parser.Expression)6 CartesianMesh (cbit.vcell.solvers.CartesianMesh)6 Vector (java.util.Vector)6 Extent (org.vcell.util.Extent)6 VariableType (cbit.vcell.math.VariableType)5 ISize (org.vcell.util.ISize)5 AnalyticSubVolume (cbit.vcell.geometry.AnalyticSubVolume)4 Curve (cbit.vcell.geometry.Curve)4 SubVolume (cbit.vcell.geometry.SubVolume)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Origin (org.vcell.util.Origin)4 VCImageUncompressed (cbit.image.VCImageUncompressed)3 Line (cbit.vcell.geometry.Line)3