Search in sources :

Example 6 with Polygon

use of cbit.vcell.geometry.surface.Polygon in project vcell by virtualcell.

the class SurfaceRenderer method createProjectedScreenPolygons.

/**
 * Insert the method's description here.
 * Creation date: (7/7/2004 11:25:42 AM)
 * @param g java.awt.Graphics
 */
public PolygonInfo[] createProjectedScreenPolygons(SurfaceCollection surfaceCollection, int[] quickRenderSkip, BoundingBoxInfo bbi) {
    int[] xPoints = new int[4];
    int[] yPoints = new int[4];
    ArrayList<PolygonInfo> polygonInfoList = new ArrayList<PolygonInfo>(1000);
    Vect3d centroid = new Vect3d();
    Vect3d centroidProj = new Vect3d();
    Vect3d unitNormal = new Vect3d();
    Vect3d cameraVector = new Vect3d(0, 0, 1);
    Vect3d cameraVectorScene = new Vect3d();
    getTrackball().getCamera().unProjectPoint(cameraVector, cameraVectorScene);
    cameraVectorScene.unit();
    for (int i = 0; i < surfaceCollection.getSurfaceCount(); i++) {
        cbit.vcell.geometry.surface.Surface surface = surfaceCollection.getSurfaces(i);
        for (int j = 0; j < surface.getPolygonCount(); j++) {
            if (quickRenderSkip != null && (quickRenderSkip[i] == 0 || j % quickRenderSkip[i] != 0)) {
                continue;
            }
            cbit.vcell.geometry.surface.Polygon polygon = surface.getPolygons(j);
            // find centroid depth along user line of sight
            calculateProjectedCentroid(polygon, centroid, centroidProj);
            double depth = centroidProj.getZ();
            // depthCue color scale
            float notFlatShadeColorScale = (float) (1.0 - bbi.depthCue * (depth - bbi.minZ));
            // calculate flat shading scale, adjust due to normal
            polygon.getUnitNormal(unitNormal);
            double dot = unitNormal.dot(cameraVectorScene);
            float flatShadeColorScale = (float) (0.5 * notFlatShadeColorScale + 0.5 * Math.pow(Math.abs(dot), 2));
            // make sure color scale between 0 and 1
            notFlatShadeColorScale = (float) Math.min(1.0, Math.max(0.0, notFlatShadeColorScale));
            flatShadeColorScale = (float) Math.min(1.0, Math.max(0.0, flatShadeColorScale));
            polygonInfoList.add(new PolygonInfo(createScreenPolygon(polygon, xPoints, yPoints, bbi.xOffset, bbi.xScale, bbi.yOffset, bbi.yScale), depth, flatShadeColorScale, notFlatShadeColorScale, i, j));
        }
    }
    Collections.sort(polygonInfoList);
    PolygonInfo[] polygonInfoArr = new PolygonInfo[polygonInfoList.size()];
    polygonInfoList.toArray(polygonInfoArr);
    return polygonInfoArr;
}
Also used : ArrayList(java.util.ArrayList) Polygon(cbit.vcell.geometry.surface.Polygon) Vect3d(cbit.vcell.render.Vect3d)

Example 7 with Polygon

use of cbit.vcell.geometry.surface.Polygon in project vcell by virtualcell.

the class ROIMultiPaintManager method calcMinMax.

private static StatsHelper calcMinMax(File[] selectedFiles) throws Exception {
    ArrayList<SurfaceCollection> allSurfCollections = new ArrayList<>();
    TreeMap<String, TreeMap<Integer, ArrayList<TreeMap<Integer, TreeSet<Integer>>>>> fileMapSurfMapSubsurf = new TreeMap<>();
    for (int j = 0; j < selectedFiles.length; j++) {
        File selectedfiFile = selectedFiles[j];
        SurfaceCollection surfaceCollection = ClientRequestManager.createSurfaceCollectionFromSurfaceFile(selectedfiFile);
        if (surfaceCollection == null) {
            throw new Exception("Expecting .stl or .mesh(salk) from file '" + selectedfiFile + "'");
        }
        TreeMap<Integer, ArrayList<TreeMap<Integer, TreeSet<Integer>>>> fileSurf = new TreeMap<>();
        fileMapSurfMapSubsurf.put(selectedfiFile.getAbsolutePath(), fileSurf);
        // nodeMapFace.add(treeMap);
        TreeSet<Integer> allNodes = new TreeSet<>();
        for (int k = 0; k < surfaceCollection.getNodeCount(); k++) {
            allNodes.add(k);
        }
        TreeMap<Integer, ArrayList<TreeSet<Integer>>> allSubSurf = new TreeMap<>();
        int surfOutCount = 0;
        for (int i = 0; i < surfaceCollection.getSurfaceCount(); i++) {
            ArrayList<TreeMap<Integer, TreeSet<Integer>>> surfMap = new ArrayList<>();
            fileSurf.put(i, surfMap);
            TreeMap<Integer, TreeSet<Integer>> treeMap = new TreeMap<>();
            surfMap.add(treeMap);
            Surface surface = surfaceCollection.getSurfaces(i);
            for (int k = 0; k < surface.getPolygonCount(); k++) {
                Polygon polygon = surface.getPolygons(k);
                for (Node node : polygon.getNodes()) {
                    TreeSet<Integer> PolygonIndexes = treeMap.get(node.getGlobalIndex());
                    if (PolygonIndexes == null) {
                        PolygonIndexes = new TreeSet<Integer>();
                        treeMap.put(node.getGlobalIndex(), PolygonIndexes);
                    }
                    PolygonIndexes.add(k);
                }
            }
            allSubSurf.put(i, new ArrayList<>());
            while (allNodes.size() > 0) {
                surfOutCount += 1;
                TreeSet<Integer> searchNodes = new TreeSet<>(Arrays.asList(new Integer[] { allNodes.iterator().next() }));
                TreeSet<Integer> alreadySearched = new TreeSet<>();
                TreeSet<Integer> subSurf = new TreeSet<>();
                allSubSurf.get(i).add(subSurf);
                while (searchNodes.size() > 0) {
                    Integer currentNode = searchNodes.iterator().next();
                    searchNodes.remove(currentNode);
                    alreadySearched.add(currentNode);
                    allNodes.remove(currentNode);
                    TreeSet<Integer> facesForNode = treeMap.get(surfaceCollection.getNodes(currentNode).getGlobalIndex());
                    Iterator<Integer> facesIter = facesForNode.iterator();
                    while (facesIter.hasNext()) {
                        Integer faceIndex = facesIter.next();
                        subSurf.add(faceIndex);
                        Polygon poly = surfaceCollection.getSurfaces(i).getPolygons(faceIndex);
                        for (int k = 0; k < poly.getNodes().length; k++) {
                            if (poly.getNodes()[k].getGlobalIndex() != currentNode && !alreadySearched.contains(poly.getNodes()[k].getGlobalIndex())) {
                                searchNodes.add(poly.getNodes()[k].getGlobalIndex());
                            }
                        }
                    }
                }
            }
        }
        if (surfOutCount > surfaceCollection.getSurfaceCount()) {
            SurfaceCollection newSurfCollection = new SurfaceCollection();
            newSurfCollection.setNodes(surfaceCollection.getNodes());
            for (Integer origSurfIndex : allSubSurf.keySet()) {
                ArrayList<TreeSet<Integer>> newSubSurfaces = allSubSurf.get(origSurfIndex);
                for (TreeSet<Integer> subSurf : newSubSurfaces) {
                    OrigSurface os = new OrigSurface(0, 1);
                    Iterator<Integer> polyIter = subSurf.iterator();
                    while (polyIter.hasNext()) {
                        Polygon poly = surfaceCollection.getSurfaces(origSurfIndex).getPolygons(polyIter.next());
                        os.addPolygon(poly);
                    }
                    newSurfCollection.addSurface(os);
                }
            }
            allSurfCollections.add(newSurfCollection);
        } else {
            allSurfCollections.add(surfaceCollection);
        }
    // fileMapSurfMapSubsurf.get(selectedfiFile.getAbsolutePath()).get(i).add(treeMap);
    }
    StatsHelper statsHelper = new StatsHelper();
    statsHelper.recalSurfs = allSurfCollections;
    for (int j = 0; j < statsHelper.recalSurfs.size(); j++) {
        // File selectedfiFile = selectedFiles[j];
        // SurfaceCollection surfaceCollection = ClientRequestManager.createSurfaceCollectionFromSurfaceFile(selectedfiFile);
        SurfaceCollection surfaceCollection = statsHelper.recalSurfs.get(j);
        for (int i = 0; i < surfaceCollection.getNodes().length; i++) {
            if (j == 0 && i == 0) {
                statsHelper.xmin = surfaceCollection.getNodes()[i].getX();
                statsHelper.xmax = statsHelper.xmin;
                statsHelper.ymin = surfaceCollection.getNodes()[i].getY();
                statsHelper.ymax = statsHelper.ymin;
                statsHelper.zmin = surfaceCollection.getNodes()[i].getZ();
                statsHelper.zmax = statsHelper.zmin;
            }
            statsHelper.xmin = Math.min(statsHelper.xmin, surfaceCollection.getNodes()[i].getX());
            statsHelper.ymin = Math.min(statsHelper.ymin, surfaceCollection.getNodes()[i].getY());
            statsHelper.zmin = Math.min(statsHelper.zmin, surfaceCollection.getNodes()[i].getZ());
            statsHelper.xmax = Math.max(statsHelper.xmax, surfaceCollection.getNodes()[i].getX());
            statsHelper.ymax = Math.max(statsHelper.ymax, surfaceCollection.getNodes()[i].getY());
            statsHelper.zmax = Math.max(statsHelper.zmax, surfaceCollection.getNodes()[i].getZ());
        }
    }
    return statsHelper;
}
Also used : SurfaceCollection(cbit.vcell.geometry.surface.SurfaceCollection) Node(cbit.vcell.geometry.surface.Node) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) Point(java.awt.Point) UtilCancelException(org.vcell.util.UtilCancelException) UserCancelException(org.vcell.util.UserCancelException) Surface(cbit.vcell.geometry.surface.Surface) OrigSurface(cbit.vcell.geometry.surface.OrigSurface) TreeSet(java.util.TreeSet) OrigSurface(cbit.vcell.geometry.surface.OrigSurface) Polygon(cbit.vcell.geometry.surface.Polygon) File(java.io.File)

Example 8 with Polygon

use of cbit.vcell.geometry.surface.Polygon in project vcell by virtualcell.

the class AVS_UCD_Exporter method writeUCDGeometryOnly.

/**
 * Insert the method's description here.
 * Creation date: (7/19/2004 10:54:30 AM)
 * @param geometrySurfaceDescription cbit.vcell.geometry.surface.GeometrySurfaceDescription
 */
public static void writeUCDGeometryOnly(GeometrySurfaceDescription geometrySurfaceDescription, java.io.Writer writer) throws Exception {
    final String QUAD_TYPE = "quad";
    // GeometricRegion regions[] = geometrySurfaceDescription.getGeometricRegions();
    SurfaceCollection surfaceCollection = geometrySurfaceDescription.getSurfaceCollection();
    if (surfaceCollection == null) {
        geometrySurfaceDescription.updateAll();
        surfaceCollection = geometrySurfaceDescription.getSurfaceCollection();
    }
    Node[] nodes = surfaceCollection.getNodes();
    int numNodes = nodes.length;
    int numCells = 0;
    for (int i = 0; i < surfaceCollection.getSurfaceCount(); i++) {
        numCells += surfaceCollection.getSurfaces(i).getPolygonCount();
    }
    int numNodeData = 0;
    int numCellData = 0;
    int numModelData = 0;
    writer.write(numNodes + " " + numCells + " " + numNodeData + " " + numCellData + " " + numModelData + "\n");
    for (int i = 0; i < nodes.length; i++) {
        writer.write(nodes[i].getGlobalIndex() + " " + nodes[i].getX() + " " + nodes[i].getY() + " " + nodes[i].getZ() + "\n");
    }
    // 
    // print the "Cells" (polygons) for each surface (each surface has it's own material id).
    // 
    int cellID = 0;
    for (int i = 0; i < surfaceCollection.getSurfaceCount(); i++) {
        Surface surface = surfaceCollection.getSurfaces(i);
        // for material now just give it the index (later need to collect these in terms of closed objects).
        String materialType = Integer.toString(i);
        for (int j = 0; j < surface.getPolygonCount(); j++) {
            Polygon polygon = surface.getPolygons(j);
            int node0Index = polygon.getNodes(0).getGlobalIndex();
            int node1Index = polygon.getNodes(1).getGlobalIndex();
            int node2Index = polygon.getNodes(2).getGlobalIndex();
            int node3Index = polygon.getNodes(3).getGlobalIndex();
            writer.write(cellID + " " + materialType + " " + QUAD_TYPE + " " + node0Index + " " + node1Index + " " + node2Index + " " + node3Index + "\n");
            cellID++;
        }
    }
}
Also used : SurfaceCollection(cbit.vcell.geometry.surface.SurfaceCollection) Node(cbit.vcell.geometry.surface.Node) Polygon(cbit.vcell.geometry.surface.Polygon) Surface(cbit.vcell.geometry.surface.Surface)

Example 9 with Polygon

use of cbit.vcell.geometry.surface.Polygon in project vcell by virtualcell.

the class SmoldynFileWriter method writeMeshFile.

private void writeMeshFile() throws SolverException {
    FileOutputStream fos = null;
    try {
        polygonMembaneElementMap = new HashMap<Polygon, MembraneElement>();
        cartesianMesh = CartesianMesh.createSimpleCartesianMesh(resampledGeometry, polygonMembaneElementMap);
        // Write Mesh file
        File meshFile = new File(baseFileName + SimDataConstants.MESHFILE_EXTENSION);
        fos = new FileOutputStream(meshFile);
        cartesianMesh.write(new PrintStream(fos));
    } catch (Exception e) {
        e.printStackTrace(System.out);
        throw new SolverException(e.getMessage());
    } finally {
        try {
            if (fos != null) {
                fos.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Also used : PrintStream(java.io.PrintStream) FileOutputStream(java.io.FileOutputStream) MembraneElement(cbit.vcell.solvers.MembraneElement) SolverException(cbit.vcell.solver.SolverException) IOException(java.io.IOException) Polygon(cbit.vcell.geometry.surface.Polygon) File(java.io.File) ProgrammingException(org.vcell.util.ProgrammingException) GeometryException(cbit.vcell.geometry.GeometryException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) PropertyVetoException(java.beans.PropertyVetoException) DivideByZeroException(cbit.vcell.parser.DivideByZeroException) ImageException(cbit.image.ImageException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) SolverException(cbit.vcell.solver.SolverException) ExpressionException(cbit.vcell.parser.ExpressionException) MathException(cbit.vcell.math.MathException)

Aggregations

Polygon (cbit.vcell.geometry.surface.Polygon)9 Surface (cbit.vcell.geometry.surface.Surface)6 SurfaceCollection (cbit.vcell.geometry.surface.SurfaceCollection)5 Vect3d (cbit.vcell.render.Vect3d)5 ArrayList (java.util.ArrayList)5 Node (cbit.vcell.geometry.surface.Node)4 TreeSet (java.util.TreeSet)4 OrigSurface (cbit.vcell.geometry.surface.OrigSurface)3 SolverException (cbit.vcell.solver.SolverException)3 HashSet (java.util.HashSet)3 GeometrySpec (cbit.vcell.geometry.GeometrySpec)2 SubVolume (cbit.vcell.geometry.SubVolume)2 SurfaceClass (cbit.vcell.geometry.SurfaceClass)2 GeometricRegion (cbit.vcell.geometry.surface.GeometricRegion)2 GeometrySurfaceDescription (cbit.vcell.geometry.surface.GeometrySurfaceDescription)2 SurfaceGeometricRegion (cbit.vcell.geometry.surface.SurfaceGeometricRegion)2 Triangle (cbit.vcell.geometry.surface.Triangle)2 VolumeGeometricRegion (cbit.vcell.geometry.surface.VolumeGeometricRegion)2 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)2 MembraneSubDomain (cbit.vcell.math.MembraneSubDomain)2