Esempio n. 1
0
        public static List <IsoTri> CalcIsoSurfaces(Mesh m, uint dataIndex, double isoCount, Testing_openTK_again.Del valueToColor, ColorMapControl.ColorMap.Mode mode)
        {
            List <IsoTri> isoTri = new List <IsoTri>();
            double        min, max;

            m.GetMinMaxValues(dataIndex, out min, out max);
            double isoStep = (max - min) / isoCount;
            double iso     = min + isoStep * 0.5;

            for (int ic = 0; ic < isoCount; ++ic)
            {
                foreach (Zone z in m.Zones)
                {
                    foreach (Element e in z.Elements)
                    {
                        List <double> data = new List <double>();
                        for (int i = 0; i < e.vertInOrder.Length; ++i)
                        {
                            data.Add(z.Vertices[e.vertInOrder[i]].Data[dataIndex]);
                        }

                        var elementCase = ISOSurface.GetElementCase(data.ToArray(), iso);
                        var edges       = ISOSurface.GetCaseEdges(elementCase);
                        for (int i = 0; i < edges.Length; i += 3)
                        {
                            if (edges[i] < 0 || edges[i] > 16)
                            {
                                break;
                            }
                            isoTri.Add(new IsoTri());
                            //triangles.Add(new List<Point3>());
                            for (int j = 0; j < 3; ++j)
                            {
                                var edge      = ISOSurface.GetEdgePoints(edges[i + j]);
                                var startVert = z.Vertices[e.vertInOrder[edge.Start]];
                                var endVert   = z.Vertices[e.vertInOrder[edge.End]];
                                var alpha     = (iso - startVert.Data[dataIndex]) / (endVert.Data[dataIndex] - startVert.Data[dataIndex]);
                                var p         = Lerp(startVert.Position, endVert.Position, alpha);
                                //var p = process(iso, startVert.Position, endVert.Position, startVert.Data[dataIndex], startVert.Data[dataIndex]);
                                isoTri[isoTri.Count - 1].triangle.Add(p);
                                Color c = valueToColor(mode, (float)(iso - endVert.Data[dataIndex] + startVert.Data[dataIndex]));

                                //Color c = valueToColor(mode, (float)(iso));// (float)(iso - endVert.Data[dataIndex] + startVert.Data[dataIndex]));
                                isoTri[isoTri.Count - 1].color = new double[] { c.R / 255.0, c.G / 255.0, c.B / 255.0 };
                            }
                        }
                    }
                }
                iso += isoStep;
            }
            return(isoTri);
        }
        public void MarchingCubeCount()
        {
            isoTri = new List <IsoTri>();
            int isoCount = (int)numericUpDown1.Value;

            m.GetMinMaxValues(dataIndex, out min, out max);
            double isoStep = (max - min) / isoCount;
            double iso     = min + isoStep * 0.5;

            for (int ic = 0; ic < isoCount; ++ic)
            {
                foreach (Zone z in m.Zones)
                {
                    foreach (Element e in z.Elements)
                    {
                        List <double> data = new List <double>();
                        for (int i = 0; i < e.vertInOrder.Length; ++i)
                        {
                            data.Add(z.Vertices[e.vertInOrder[i]].Data[dataIndex]);
                        }

                        var elementCase = ISOSurface.GetElementCase(data.ToArray(), iso);
                        var edges       = ISOSurface.GetCaseEdges(elementCase);
                        for (int i = 0; i < edges.Length; i += 3)
                        {
                            if (edges[i] < 0 || edges[i] > 16)
                            {
                                break;
                            }
                            isoTri.Add(new IsoTri());
                            //triangles.Add(new List<Point3>());
                            for (int j = 0; j < 3; ++j)
                            {
                                var edge      = ISOSurface.GetEdgePoints(edges[i + j]);
                                var startVert = z.Vertices[e.vertInOrder[edge.Start]];
                                var endVert   = z.Vertices[e.vertInOrder[edge.End]];
                                var alpha     = (iso - startVert.Data[dataIndex]) / (endVert.Data[dataIndex] - startVert.Data[dataIndex]);
                                var p         = Lerp(startVert.Position, endVert.Position, alpha);
                                //var p = process(iso, startVert.Position, endVert.Position, startVert.Data[dataIndex], startVert.Data[dataIndex]);
                                isoTri[isoTri.Count - 1].triangle.Add(p);
                                Color c = colorMap1.ValueToColor(colorMap1.GetMode(), (float)(iso));// (float)(iso - endVert.Data[dataIndex] + startVert.Data[dataIndex]));
                                isoTri[isoTri.Count - 1].color = new double[] { c.R / 255.0, c.G / 255.0, c.B / 255.0 };
                            }
                        }
                    }
                }
                iso += isoStep;
            }
            //MessageBox.Show(isoTri.Count.ToString());
        }