Esempio n. 1
0
        /// <summary>
        /// Creates a regular grid of 3dpoints from the Surface on the specified uv-interval and colors them by gaussian
        /// </summary>
        /// <param name="s">the surface to mesh</param>
        /// <param name="ROWS">the number of constant-u sections</param>
        /// <param name="COLS">the number of constant-v sections</param>
        /// <param name="uvLim">(optional)the uv limits to mesh, uvLim[0,x] = uLim, uvLim[1,x] = vLim</param>
        /// <returns>the grid of points for meshing</returns>
        public static PointRGB[] GetMeshGaussianPoints(ISurface s, int ROWS, int COLS, double[,] uvLim)
        {
            Vect2 uv = new Vect2();
            Vect3 xyz = new Vect3();
            List<Vect3> xyzs = new List<Vect3>(ROWS * COLS);
            PointRGB[] meshpts = new PointRGB[ROWS * COLS];
            double[] gauss = new double[ROWS * COLS];
            double kMax = -1e9, kMin = 1e9;
            int i = 0;
            for (int iU = 0; iU < ROWS; iU++)
            {
                uv[0] = BLAS.interpolate((double)iU / (double)(ROWS - 1), uvLim[0, 1], uvLim[0, 0]);
                //uv[0] = (double)iU / (double)(ROWS - 1);
                for (int iV = 0; iV < COLS; iV++, i++)
                {
                    uv[1] = BLAS.interpolate((double)iV / (double)(COLS - 1), uvLim[1, 1], uvLim[1, 0]);
                    //uv[1] = (double)iV / (double)(COLS - 1);
                    s.xRad(uv, ref xyz, ref gauss[i]);
                    //copy to temp array
                    xyzs.Add(new Vect3(xyz));
                    //meshpts[i].X = xyz[0];
                    //meshpts[i].Y = xyz[1];
                    //meshpts[i].Z = xyz[2];
                    //track max/min for color scale
                    kMax = Math.Max(kMax, gauss[i]);
                    kMin = Math.Min(kMin, gauss[i]);
                }
            }
            double ave, q1, q3, stddev = BLAS.StandardDeviation(gauss, out ave, out q3, out q1);
            Color c;
            for (i = 0; i < meshpts.Length; i++)
            {
                c = ColorMath.GetScaleColor(ave + 2 * stddev, ave - 2 * stddev, gauss[i]);
                meshpts[i] = new PointRGB(xyzs[i][0], xyzs[i][1], xyzs[i][2], c);
            }

            return meshpts;
        }
Esempio n. 2
0
        double CheckError(ISurface cof)
        {
            int ROWS = 30, COLS = 30;

            Vect2 uv = new Vect2();
            Vect3 xyz = new Vect3();
            int i, j;
            double kThis=0, kCof=0, err=0;
            for (i = 0; i < ROWS; i++)
            {
                uv[0] = BLAS.interpolant(i, ROWS);
                for (j = 0; j < COLS; j++)
                {
                    uv[1] = BLAS.interpolant(j, COLS);
                    cof.xRad(uv, ref xyz, ref kCof);
                    xRad(uv, ref xyz, ref kThis);
                    err = Math.Pow(kCof - kThis, 2);
                }
            }
            err /= (ROWS*COLS);
            return err;
        }