示例#1
0
        public devDept.Eyeshot.Standard.MulticolorOnVerticesMesh CreateMesh(List <WindowsFormsApplication2.ColoredPoint> coloredPs, int cols)
        {
            List <Point3D> vertices = new List <Point3D>(coloredPs.Count);

            for (int i = 0; i < coloredPs.Count; i++)
            {
                vertices.Add(new Point3D(coloredPs[i].X, coloredPs[i].Y, coloredPs[i].val));
            }

            int rows = vertices.Count / cols;

            devDept.Eyeshot.Standard.MulticolorOnVerticesMesh mesh = new MulticolorOnVerticesMesh(vertices.Count);

            // create the mesh
            System.Drawing.Color c = System.Drawing.Color.SlateBlue;
            if (mesh.Vertices.Length != vertices.Count)
            {
                mesh.ResizeVertices(vertices.Count);
            }

            mesh.NormalAveragingMode = devDept.Eyeshot.Standard.Mesh.normalAveragingType.Averaged;
            //mesh.EntityData = this; //point back to this object

            // set the vertices
            mesh.Vertices = vertices.ToArray();
            mesh.UpdateBoundingBox();

            //color the vertices
            //int i = ReColorMesh(colorvals);

            for (int i = 0; i < coloredPs.Count; i++)
            {
                mesh.SetVertex(i, coloredPs[i].color.R, coloredPs[i].color.G, coloredPs[i].color.B);
            }

            //if (i != vertices.Length)
            //return -3;

            // set vertex indices
            mesh.Triangles.Clear();
            mesh.Triangles.Capacity = (rows - 1) * (cols - 1) * 2;
            for (int j = 0; j < (rows - 1); j++)
            {
                for (int i = 0; i < (cols - 1); i++)
                {
                    mesh.Triangles.Add(new Mesh.Triangle(i + j * cols,
                                                         i + j * cols + 1,
                                                         i + (j + 1) * cols + 1));
                    mesh.Triangles.Add(new Mesh.Triangle(i + j * cols,
                                                         i + (j + 1) * cols + 1,
                                                         i + (j + 1) * cols));
                }
            }



            mesh.ComputeEdges();
            mesh.ComputeNormals();
            mesh.NormalAveragingMode = Mesh.normalAveragingType.None;
            //m_mesh.Rotate(Math.PI, new Vector3D(0, 0, 1));
            return(mesh);
        }
示例#2
0
        public int CreateMesh(Point3D[] vertices, double[] colorvals, int cols, ref MulticolorOnVerticesMesh surf)
        {
            int rows = vertices.Length / cols;

            // create the mesh
            System.Drawing.Color c = System.Drawing.Color.SlateBlue;

            if (surf.Vertices.Length != vertices.Length)
                surf.ResizeVertices(vertices.Length);

            surf.NormalAveragingMode = devDept.Eyeshot.Standard.Mesh.normalAveragingType.Averaged;
            surf.EntityData = this; //point back to this object

            // set the vertices
            surf.Vertices = vertices;
            surf.UpdateBoundingBox();

            //color the vertices
            int i = ReColorMesh(colorvals, ref surf);
            //if (i != vertices.Length)
            //return -3;

            // set vertex indices
            surf.Triangles.Clear();
            surf.Triangles.Capacity = (rows - 1) * (cols - 1) * 2;
            for (int j = 0; j < (rows - 1); j++)
            {
                for (i = 0; i < (cols - 1); i++)
                {

                    surf.Triangles.Add(new Mesh.Triangle(i + j * cols,
                                                                              i + j * cols + 1,
                                                                              i + (j + 1) * cols + 1));
                    surf.Triangles.Add(new Mesh.Triangle(i + j * cols,
                                                                              i + (j + 1) * cols + 1,
                                                                              i + (j + 1) * cols));
                }
            }

            //Area = 0;

            //TargetMesh.Triangles.ForEach((t) =>
            //{
            //     //A = 1/2 | (x₃ - x₁) x (x₃ - x₂) | ....... "x" means cross product
            //     Vector3D vec1, vec2;
            //     vec1 = new Vector3D(m_mesh.Vertices[t.V3].X - m_mesh.Vertices[t.V1].X, m_mesh.Vertices[t.V3].Y - m_mesh.Vertices[t.V1].Y, m_mesh.Vertices[t.V3].Z - m_mesh.Vertices[t.V1].Z);
            //     vec2 = new Vector3D(m_mesh.Vertices[t.V3].X - m_mesh.Vertices[t.V2].X, m_mesh.Vertices[t.V3].Y - m_mesh.Vertices[t.V2].Y, m_mesh.Vertices[t.V3].Z - m_mesh.Vertices[t.V2].Z);
            //     Vector3D cross = Vector3D.Cross(vec1, vec2);
            //     Area += cross.Length / 2.0;
            //});

            surf.ComputeEdges();
            surf.ComputeNormals();
            surf.NormalAveragingMode = Mesh.normalAveragingType.None;
            //m_mesh.Rotate(Math.PI, new Vector3D(0, 0, 1));
            return surf.Triangles.Count;
        }
示例#3
0
        public int CreateMesh(List<KeyValuePair<double[], double>> vertices, int cols, ref MulticolorOnVerticesMesh surf)
        {
            List<Point3D> verts = new List<Point3D>(vertices.Count);
            List<double> colors = new List<double>(vertices.Count);
            vertices.ForEach(delegate(KeyValuePair<double[], double> d)
            {
                if (d.Key.Length == 3)
                {
                    verts.Add(new Point3D(d.Key));
                    colors.Add(d.Value);
                }
            });

            return CreateMesh(verts.ToArray(), colors.ToArray(), cols, ref surf);
        }
示例#4
0
        private int ReColorMesh(ref MulticolorOnVerticesMesh surf)
        {
            System.Drawing.Color c = Color.Green;
            int i = 0;
            //double f;
            for (i = 0; i < TargetMesh.Vertices.Length; i++)
                surf.SetVertex(i, c.R, c.G, c.B);

            return i;
        }
示例#5
0
        void GAWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            if (GAWorker.CancellationPending == true)
                Algo.Stop();

            m_progBar.Value = e.ProgressPercentage;

            if (e.UserState == null)
                return;

            List<int> bestChromo = (List<int>)e.UserState;

            if (bestChromo.Count > 0)
            {
                List<double[]> gaPnts = new List<double[]>();

                double[] result = EvalChromosome(ref bestChromo, ref gaPnts);

                CustomBasis GeneticBasis = new CustomBasis(16.383 / 2.0 - result[0], 16.383 / 2.0 - result[1], 16.383 / 2.0 - result[2], 16.383 / 2.0 - result[3]);

                List<double[]> fitpoints = new List<double[]>(gaPnts);

                //for (int i = 0; i < fitpoints.Count; i++)
                //fitpoints[i][2] += 15; //offset

                SurfaceRBF tmpSurf = new SurfaceRBF(null, "best", fitpoints, GeneticBasis, targetPoly, 0.0);

                double[] max = new double[3]; double[] min = new double[3];
                max[0] = max[1] = max[2] = -1e9; //start max low
                min[0] = min[1] = min[2] = +1e9; //start min high

                fitpoints.ForEach((double[] v) =>
                {
                    for (int i = 0; i < v.Length; i++) //get fit points' bounding box
                    {
                        max[i] = Math.Max(v[i], Max[i]);
                        min[i] = Math.Min(v[i], Min[i]);
                    }
                });

                double[] pnt1 = new double[3]; double[] pnt2 = new double[3];

                List<double[]> errorSurfPnts = new List<double[]>();
                double gridCount = 10.0;
                List<devDept.Eyeshot.Labels.TextOnly> labels = new List<devDept.Eyeshot.Labels.TextOnly>();
                for (double i = 0; i < gridCount; i += 1.0)
                {
                    for (double j = 0; j < gridCount; j += 1.0)
                    {
                        pnt1 = new double[] { (i / (gridCount - 1)) * (Max[0] - Min[0]) + Min[0], (j / (gridCount - 1)) * (Max[1] - Min[1]) + Min[1], 0 };
                        pnt2 = new double[] { (i / (gridCount - 1)) * (Max[0] - Min[0]) + Min[0], (j / (gridCount - 1)) * (Max[1] - Min[1]) + Min[1], 0 };
                        target.Value(ref pnt1);
                        found.Value(ref pnt2);

                        errorSurfPnts.Add(new double[] { (i / (gridCount - 1)) * (Max[0] - Min[0]) + Min[0], (j / (gridCount - 1)) * (Max[1] - Min[1]) + Min[1], Math.Pow(pnt2[2] - pnt1[2], 2) });
                        labels.Add(new devDept.Eyeshot.Labels.TextOnly(new Point3D((i / (gridCount - 1)) * (Max[0] - Min[0]) + Min[0] + GridSize * 20, (j / (gridCount - 1)) * (Max[1] - Min[1]) + Min[1], Math.Pow(pnt1[2] - pnt2[2], 2)), Math.Pow(((pnt1[2] - pnt2[2]) / pnt1[2]), 1).ToString("#0.00"), new Font(FontFamily.GenericSansSerif, 12.0f), Color.White, ContentAlignment.BottomCenter));

                    }
                }

                SurfaceRBF tmpSurf2 = new SurfaceRBF(null, "error", errorSurfPnts, targetBasis, targetPoly, 0.0);
                List<KeyValuePair<double[], double>> errorpts = tmpSurf2.GetMeshPointsCvt(50, 50, max, min, null);
                MulticolorOnVerticesMesh errorMesh = new MulticolorOnVerticesMesh(0);
                CreateMesh(errorpts, 50, ref errorMesh);
                errorMesh.RegenMode = devDept.Eyeshot.Standard.Entity.regenType.RegenAndCompile;
                errorMesh.EntityData = "errorSurface";
                errorMesh.Translate(GridSize * 20, 0, 0);
                AddEntity(errorMesh, false);

                List<KeyValuePair<double[], double>> pts = tmpSurf.GetMeshPointsCvt(60, 60, max, min, null);
                MulticolorOnVerticesMesh bestMesh = new MulticolorOnVerticesMesh(0);

                CreateMesh(pts, 60, ref bestMesh);
                bestMesh.RegenMode = devDept.Eyeshot.Standard.Entity.regenType.RegenAndCompile;
                bestMesh.EntityData = "bestSurface";
                bestMesh.Translate(-2 * GridSize * 10, 0, 0);
                devDept.Eyeshot.Labels.TextOnly bestBasis = new devDept.Eyeshot.Labels.TextOnly(new Point3D(((gridCount / 2.0) / (gridCount - 1)) * (Max[0] - Min[0]) + Min[0] - (2 * GridSize * 10), ((gridCount / 2.0) / (gridCount - 1)) * (Max[1] - Min[1]) + Min[1], 20), GeneticBasis.ToString(), new Font(FontFamily.GenericSansSerif, 12.0f), Color.White, ContentAlignment.BottomCenter);

                viewportProfessional1.Labels.Clear();
                labels.ForEach((label) => { viewportProfessional1.Labels.Add(label); });
                viewportProfessional1.Labels.Add(bestBasis);

                AddEntity(bestMesh, false);
                //for (int i = 0; i < fitpoints.Count; i++)
                //fitpoints[i][2] -= 15; //offset
                PointCloud fits = new PointCloud(doubleToPoint3d(fitpoints), 7.5f, Color.Blue);
                fits.EntityData = "bestpoints";

                AddEntity(fits, true);
                pts.Clear();
                bestChromo.Clear();
                //GC.Collect();
            }
        }
示例#6
0
        public int ReColorMesh(double[] colorvals, ref MulticolorOnVerticesMesh surf)
        {
            if (colorvals == null)
                return ReColorMesh(ref surf);

            m_colorvals = colorvals;
            double max = -1e9;
            double min = 1e9;
            double avg;
            double stddev = BLAS.StandardDeviation(colorvals, out avg, out max, out min);

            ColorMaxMin = new double[] { min, max };
            //foreach (double d in colorvals)
            //{
            //     max = Math.Max(max, d);
            //     min = Math.Min(min, d);
            //}
            double q1 = avg + 2 * stddev;
            double q2 = avg - 2 * stddev;
            System.Drawing.Color c;
            int i = 0;
            foreach (double d in colorvals)
            {
                c = Utilities.GetColor(q1, q2, d);
                //c = Utilities.GetColor(max, min, d);
                surf.SetVertex(i++, c.R, c.G, c.B);
            }
            return 0;
        }