Search in sources :

Example 1 with Segment2D

use of cbit.vcell.solvers.CartesianMeshChombo.Segment2D in project vcell by virtualcell.

the class MeshDisplayAdapter method constructChomboCurves.

private Hashtable<SampledCurve, int[]> constructChomboCurves(int normalAxis, int slice) {
    Hashtable<SampledCurve, int[]> curvesAndValues = null;
    if (mesh.isChomboMesh() && mesh.getMembraneElements() != null) {
        CartesianMeshChombo chomboMesh = (CartesianMeshChombo) mesh;
        curvesAndValues = new Hashtable<SampledCurve, int[]>();
        if (chomboMesh.getDimension() == 2) {
            MembraneElement[] membraneElements = mesh.getMembraneElements();
            List<MembraneElement> melist = new ArrayList<MembraneElement>();
            Segment2D[] segments = chomboMesh.get2DSegments();
            List<MembraneElement> openCurveStartingPointList = new ArrayList<MembraneElement>();
            for (MembraneElement me : membraneElements) {
                melist.add(me);
                Segment2D segment = segments[me.getMembraneIndex()];
                if (segment.prevNeigbhor < 0) {
                    openCurveStartingPointList.add(me);
                }
            }
            MembraneElement me = null;
            Coordinate[] vertices = chomboMesh.getVertices();
            SampledCurve curve = null;
            List<Integer> indexList = new ArrayList<Integer>();
            int startingIndex = -1;
            boolean bOpen = false;
            while (melist.size() > 0) {
                if (me == null) {
                    if (openCurveStartingPointList.size() > 0) {
                        me = openCurveStartingPointList.remove(0);
                        bOpen = true;
                    } else {
                        me = melist.get(0);
                        bOpen = false;
                    }
                    startingIndex = me.getMembraneIndex();
                    curve = new SampledCurve();
                    indexList.clear();
                }
                melist.remove(me);
                Segment2D segment = segments[me.getMembraneIndex()];
                indexList.add(me.getMembraneIndex());
                int pcnt = curve.getControlPointCount();
                if (pcnt == 0 && segment.prevVertex >= 0) {
                    Coordinate p1 = vertices[segment.prevVertex];
                    curve.appendControlPoint(p1);
                }
                if (segment.nextVertex >= 0 && segment.nextNeigbhor != startingIndex) {
                    Coordinate p2 = vertices[segment.nextVertex];
                    curve.appendControlPoint(p2);
                }
                int nextIndex = segment.nextNeigbhor;
                if (nextIndex == startingIndex || nextIndex < 0) {
                    // curve complete
                    int[] rmi = new int[indexList.size()];
                    for (int i = 0; i < indexList.size(); ++i) {
                        rmi[i] = indexList.get(i);
                    }
                    curve.setClosed(!bOpen);
                    curvesAndValues.put(curve, rmi);
                    // start a new curve
                    me = null;
                } else {
                    me = membraneElements[nextIndex];
                }
            }
        } else {
        // 3D
        }
    }
    return curvesAndValues;
}
Also used : SampledCurve(cbit.vcell.geometry.SampledCurve) ArrayList(java.util.ArrayList) Segment2D(cbit.vcell.solvers.CartesianMeshChombo.Segment2D) Coordinate(org.vcell.util.Coordinate)

Aggregations

SampledCurve (cbit.vcell.geometry.SampledCurve)1 Segment2D (cbit.vcell.solvers.CartesianMeshChombo.Segment2D)1 ArrayList (java.util.ArrayList)1 Coordinate (org.vcell.util.Coordinate)1