예제 #1
0
        /// <summary>
        /// A MeshThread object to calculate a piece of a rbf mesh
        /// </summary>
        /// <param name="surf">the surface rbf to get mesh from</param>
        /// <param name="rows">total # of rows</param>
        /// <param name="rowstart">rows value for this thread to start from</param>
        /// <param name="rowsend">rows value for this thread to go to</param>
        /// <param name="columns">total # of columns</param>
        /// <param name="deltax">usually something like maxX-minX (max[0] - min[0])</param>
        /// <param name="deltay">usually something like maxY-minY (max[1] - min[1])</param>
        /// <param name="min">the minimum used to calculate the deltas</param>
        /// <param name="doneEvent">your ManualResetEvent that will tell you when this is done</param>
        public MeshThread(SurfaceRBF surf, int rows, int rowstart, int rowsend, int columns, double deltax, double deltay, double[] min, List<double[]> edgepnts, ManualResetEvent doneEvent, shaper shpr1, shaper shpr2)
        {
            if(shpr1 != null)
                    shaper1 = shpr1;
               else
                    shaper1 = ((double input) => { return input; }); // shapers undefined so return inputted value

               if(shpr2 != null)
                    shaper2 = shpr2;
               else
                    shaper2 = ((double input) => { return input; }); // shapers undefined so return inputted value

               _rowStart = rowstart;
               _rowsEnd = rowsend;
               _surf = surf;
               _deltax = deltax;
               _deltay = deltay;
               _columns = columns;
               _doneEvent = doneEvent;
               _min = min;
               _rowsTotal = rows;
               if (edgepnts != null)
               {
                    edgepnts.RemoveRange(0, edgepnts.Count - 9);// only use the slanted edge
                    _edge = new LeastSquares(edgepnts, 0, 0);
               }
        }
예제 #2
0
 private Plane(NsNode surf, double[] cofs)
 {
     if (!(surf is SurfaceRBF))
         throw new Exception("RBFPoly1's Parent must be a SurfaceRBF");
     else
         m_surf = surf as SurfaceRBF;
     cofs.CopyTo(polycofs, 0);
 }
예제 #3
0
        /// <summary>
        /// A MeshThread object to calculate a piece of a rbf mesh
        /// </summary>
        /// <param name="surf">the surface rbf to get mesh from</param>
        /// <param name="rows">total # of rows</param>
        /// <param name="rowstart">rows value for this thread to start from</param>
        /// <param name="rowsend">rows value for this thread to go to</param>
        /// <param name="columns">total # of columns</param>
        /// <param name="deltax">usually something like maxX-minX (max[0] - min[0])</param>
        /// <param name="deltay">usually something like maxY-minY (max[1] - min[1])</param>
        /// <param name="min">the minimum used to calculate the deltas</param>
        /// <param name="doneEvent">your ManualResetEvent that will tell you when this is done</param>
        /// <param name="getCVT">bool to indicate if you want to calculate the surface rbf curvature value as well</param>
        public MeshThread(SurfaceRBF surf, int rows, int rowstart, int rowsend, int columns, double deltax, double deltay, double[] min, ManualResetEvent doneEvent, List<double[]> edgepnts, bool getCVT)
        {
            shaper1 = ((double input) => { return input; }); // shapers undefined so return inputted value
               shaper2 = ((double input) => { return input; }); // shapers undefined so return inputted value

               _rowStart = rowstart;
               _rowsEnd = rowsend;
               _surf = surf;
               _deltax = deltax;
               _deltay = deltay;
               _columns = columns;
               _doneEvent = doneEvent;
               _min = min;
               _rowsTotal = rows;
               _getCVT = getCVT;
               if (edgepnts != null)
               {
                    edgepnts.RemoveRange(0, edgepnts.Count - 9);
                    _edge = new LeastSquares(edgepnts, 0, 0);
               }
        }
예제 #4
0
 public Plane(NsNode parent, System.Xml.XmlNode xml)
 {
     if (parent != null && !(parent is SurfaceRBF))
         throw new Exception("RBFPoly1's Parent must be a SurfaceRBF");
     else
         m_surf = parent as SurfaceRBF;
     if (!FromXml(xml))
         throw new NsNodes.AttributeXmlFormatException(this, xml, "Invalid Format in RBFPoly1");
 }
예제 #5
0
 public Plane(SurfaceRBF surf)
 {
     m_surf = surf;
 }
예제 #6
0
 public ParaboloidConst(SurfaceRBF surf)
 {
     m_surf = surf;
 }
예제 #7
0
 public Conic(SurfaceRBF surf)
 {
     m_surf = surf;
 }
예제 #8
0
        public _3dForm()
        {
            InitializeComponent();
            SetupWorker();

            stat = ((string message) => { m_status.Text = message; });

            CustomBasis GeneticBasis = null;

            Eval = new Evaluator((ref List<int> binaryCoded, ref List<int> bestChromo) =>
            {
                //if(!m_running)

                double error = 0;

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

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

                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]);

                double[] pnt1, pnt2, dx1, dx2;

                //List<double[]> fitpoints = new List<double[]>(oldRBF.OriginalFitPoints);

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

                found = new SurfaceRBF(null, "target", fitpoints, GeneticBasis, targetPoly, 0.0);

                //List<double[]> errorSurfPnts = new List<double[]>();
                double gridCount = GridSize;
                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);

                        error += 10.0 * Math.Pow(Math.Abs(pnt2[2] - pnt1[2]), 1);
                        //errorSurfPnts.Add(new double[] { i * 20.0, j * 20.0, pnt1[2] - pnt2[2] });
                    }
                }

                gridCount = 10.0;
                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);

                        error += Math.Pow(Math.Abs(pnt2[2] - pnt1[2]), 1);
                    }
                }

                //int count = 0;

                //double pntError = 1000;

                //gaPnts.ForEach((pnt) =>
                //{
                //     dx1 = new double[2];
                //     dx2 = new double[2];
                //     pnt2 = new double[] { pnt[0], pnt[1] };
                //     GaRBF.First(ref pnt, ref dx1);
                //     oldRBF.First(ref pnt, ref dx2);
                //     error += 2 * Math.Pow(pnt2[1] - pnt[1], 2);
                //     error += 2 * Math.Pow(Math.Pow(dx2[0] - dx1[0], 2) + Math.Pow(dx2[1] - dx1[1], 2), 2);
                //});

                //gaPnts.ForEach((pnt) =>
                //     {
                //          if (oldRBF.OriginalFitPoints.Find((Oldpnt) => { return Oldpnt[0] == pnt[0] && Oldpnt[1] == pnt[1]; }) != null)
                //               count++;
                //          else
                //               error *= 4;
                //     });

                //if (count != 0)
                //    pntError /= ((double)count / 5.0) * 1000.0;

                // error += pntError;

                //GC.Collect();
                return Math.Pow(error, -1);
            });
        }
예제 #9
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();
            }
        }
예제 #10
0
        private void CreateNewTargetSurface()
        {
            targetPoly = new RBFPolynomials.Paraboloid(null);

            switch (TargetBasis)
            {
                case BasisType.Cubic:
                    targetBasis = new RBFBasis.PolyHarmonic3(null);
                    break;
                case BasisType.Gaussian:
                    targetBasis = new RBFBasis.Gaussian(null);
                    break;
                case BasisType.Line:
                    targetBasis = new RBFBasis.CustomBasis(null, 0, 0, 1, 0);
                    break;
                case BasisType.Parabolic:
                    targetBasis = new RBFBasis.ThinPlateSpline2(null);
                    break;
                case BasisType.CubicParabolic:
                    targetBasis = new RBFBasis.CustomBasis(null, 1, 1, -1, 0);
                    break;
            }

            List<double[]> pnts = RandomizePoints(GridSize);
            target = new SurfaceRBF(null, "target", pnts, targetBasis, targetPoly, 0.0);

            Max[0] = Max[1] = Max[2] = -1e9; //start max low
            Min[0] = Min[1] = Min[2] = +1e9; //start min high

            pnts.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]);
                }
            });

            List<KeyValuePair<double[], double>> pts = target.GetMeshPointsCvt(60, 60, Max, Min, null);

            CreateMesh(pts, 60, ref m_targetMesh);
            TargetMesh.RegenMode = devDept.Eyeshot.Standard.Entity.regenType.RegenAndCompile;
            TargetMesh.EntityData = "targetSurface";
            AddEntity(TargetMesh, false);
            PointCloud fits = new PointCloud(doubleToPoint3d(pnts), 5.0f, Color.Red);
            fits.EntityData = "fitpoints";

            AddEntity(fits, true);

            GC.Collect();
        }