public FaceRecord(IsoFaceRec r, PQPairs _pq)
 {
     face = r;
     pq = _pq;
 }
            public object Clone()
            {
                PQPairs pair = new PQPairs();
                pair.p = this.p;
                pair.q = this.q;
                pair.n = this.n;
                pair.pId = this.pId;
                pair.e1 = this.e1;
                pair.e2 = this.e2;
                pair.findex = this.findex;
                pair.lindex = this.lindex;
                pair.ratio1 = this.ratio1;
                pair.ratio2 = this.ratio2;
                pair.isovalue = this.isovalue;

                return pair;
            }
        private void LocateFacesIsoPosition(double[] f, double[] isovals)
        {
            if (f == null) throw new ArgumentException();

            // initialize isofaces
            this.isofaces = new IsoFaceRec[mesh.FaceCount];
            for (int i = 0; i < mesh.FaceCount; ++i)
                this.isofaces[i] = new IsoFaceRec();
            for (int i = 0; i < isovalues.Length; ++i)
            {
                double v = isovals[i];
                for (int k = 0, m = 0; k < this.mesh.FaceCount; ++k, m += 3)
                {
                    int c1 = this.mesh.FaceIndex[m];
                    int c2 = this.mesh.FaceIndex[m + 1];
                    int c3 = this.mesh.FaceIndex[m + 2];
                    PQPairs r = null;
                    if ((f[c1] <= v && f[c2] >= v) || (f[c2] <= v && f[c1] >= v))
                    {
                        if (r == null) { r = new PQPairs(); r.findex = k; }
                        if (r.e1 == -1)
                        {
                            r.e1 = 0; r.ratio1 = (v - f[c1]) / (f[c2] - f[c1]);
                        }
                        else
                        {
                            r.e2 = 0; r.ratio2 = (v - f[c1]) / (f[c2] - f[c1]);
                        }
                    }
                    if ((f[c2] <= v && f[c3] >= v) || (f[c3] <= v && f[c2] >= v))
                    {
                        if (r == null) { r = new PQPairs(); r.findex = k; }
                        if (r.e1 == -1)
                        {
                            r.e1 = 1; r.ratio1 = (v - f[c2]) / (f[c3] - f[c2]);
                        }
                        else
                        {
                            r.e2 = 1; r.ratio2 = (v - f[c2]) / (f[c3] - f[c2]);
                        }
                    }
                    if ((f[c3] <= v && f[c1] >= v) || (f[c1] <= v && f[c3] >= v))
                    {
                        if (r == null) { r = new PQPairs(); r.findex = k; }
                        if (r.e1 == -1)
                        {
                            r.e1 = 2; r.ratio1 = (v - f[c3]) / (f[c1] - f[c3]);
                        }
                        else
                        {
                            r.e2 = 2; r.ratio2 = (v - f[c3]) / (f[c1] - f[c3]);
                        }
                    }
                    if (r == null) continue;
                    if (r.e1 == -1 || r.e2 == -1) continue;

                    r.isovalue = v;
                    r.lindex = i;

                    Vector3d v1 = new Vector3d(mesh.VertexPos, c1 * 3);
                    Vector3d v2 = new Vector3d(mesh.VertexPos, c2 * 3);
                    Vector3d v3 = new Vector3d(mesh.VertexPos, c3 * 3);
                    Vector3d n1 = new Vector3d(mesh.FaceNormal, k * 3);
                    Vector3d p = new Vector3d(), q = new Vector3d();
                    switch (r.e1)
                    {
                        case 0: p = v2 * r.ratio1 + v1 * (1.0 - r.ratio1); break;
                        case 1: p = v3 * r.ratio1 + v2 * (1.0 - r.ratio1); break;
                        case 2: p = v1 * r.ratio1 + v3 * (1.0 - r.ratio1); break;
                    }
                    switch (r.e2)
                    {
                        case 0: q = v2 * r.ratio2 + v1 * (1.0 - r.ratio2); break;
                        case 1: q = v3 * r.ratio2 + v2 * (1.0 - r.ratio2); break;
                        case 2: q = v1 * r.ratio2 + v3 * (1.0 - r.ratio2); break;
                    }
                    r.n = n1; r.p = p; r.q = q;
                    isofaces[k].pqPairs.Add(r);
                    isofaces[k].index = k;
                    isofaces[k].valid = true;
                }
            }
        }