Пример #1
0
 public YarnCurve(double p, MouldCurve warp1, MouldCurve warp2)
 {
     m_h = 0;
     m_p = p;
     m_Warps[0] = warp1;
     m_Warps[1] = warp2;
 }
Пример #2
0
        /// <summary>
        /// Will fit the spline using either InterpoFit or SimpleFit depending on the number of fitpoints
        /// </summary>
        /// <param name="c">the curve to fit</param>
        /// <param name="points">points to fit to, minimum 2</param>
        internal static void Fit(MouldCurve c, IFitPoint[] points)
        {
            if (points.Length <= 1)//need at least 2 points to fit a curve
                return;

            if (points.Length >= 5)
                SimpleFit(c, points);
            else //linear uv interpolation to match minimum 5 points required
                InterpoFit(c, points);
        }
Пример #3
0
        public bool ReadScript(Sail sail, IList<string> txt)
        {
            if (txt.Count != 3)
                return false;
            //[1] = "\t\tCurve: Luff"
            m_curve = sail.FindCurve(txt[1].Split(new char[]{':'})[1].Trim());
            txt[2] = txt[2].Trim('\t');

            string[] split = txt[2].Split(new char[] { ':' });

            S_Equ = new Equation(split[0], split[1]);

            return Update(sail);

            #region Old
            //string line;
            //double d;
            //foreach (string s in txt)
            //{
            //	line = s.TrimStart('\t');
            //	if (line.StartsWith("S-Cur: "))
            //	{
            //		if (double.TryParse(line.Substring(7), out d))
            //			m_sCurve = d;
            //	}
            //	else if (line.StartsWith("Curve: "))
            //	{
            //		string curlbl = line.Substring(7).Trim();
            //		m_curve = sail.FindCurve(curlbl);
            //	}

            //}

            //return true;
            #endregion
        }
Пример #4
0
 //    : this(s.m_sPos, s.m_curve, s.m_sCurve) { }
 public SlidePoint(MouldCurve curve, double sCurve)
     : this(0, curve, sCurve)
 {
 }
Пример #5
0
        IGroup[] CreateInnerGirths()
        {
            CurveGroup outer = FindGroup("Outer") as CurveGroup;
            if (outer == null)
                outer = CreateOuterCurves() as CurveGroup;

            IGroup[] girvir = new IGroup[2];
            //SurfaceCurve gir = null;
            for (int i = 0; i < 2; i++)
            {
                CurveGroup girths = new CurveGroup(i == 0 ? "Girths" : "Virths", this);
                for (double dg = 0.0; dg < 1; dg += 0.1)
                {
                    IFitPoint[] gir = new IFitPoint[2];
                    gir[1] = new CurvePoint(1, outer[2 * i + 1], dg);

                    //gir[1] = new FixedPoint(.3, .3);
                    if (i == 0)
                        gir[0] = new SlidePoint(0, outer[2 * i], dg);
                    else
                        gir[0] = new CurvePoint(0, outer[2 * i], dg);

                    MouldCurve girth = new MouldCurve(String.Format("{0}ir-{1:##0}%", i == 0 ? "G" : "V", dg * 100), this, null);
                    girth.Fit(gir);
                    girths.Add(girth);
                }
                Add(girths);
                girvir[i] = girths;
            }
            return girvir;
        }
Пример #6
0
 public CurveTracker(MouldCurve curve)
 {
     m_curve = curve;
 }
Пример #7
0
        public static Point3D[] GetCloudPoints(MouldCurve c)
        {
            Point3D[] pnts;
            Vect2 uv = new Vect2();
            Vect3 xyz = new Vect3();

            pnts = new Point3D[c.FitPoints.Length];
            double s;
            for (int i = 0; i < c.FitPoints.Length; i++)
            {
                s = c[i].S;
                c.xVal(s, ref uv, ref xyz);
                Utilities.Vect3ToPoint3D(ref pnts[i], xyz);
            }
            return pnts;
        }
Пример #8
0
        private void CreateGirth(string script)
        {
            IFitPoint[] fits = new IFitPoint[2];
            int nS = script.IndexOf("tarting");
            nS = script.IndexOf(' ', nS);
            fits[0] = ReadFitPoint(script, ++nS);
            nS = script.IndexOf("topping");
            nS = script.IndexOf(' ', nS);
            fits[1] = ReadFitPoint(script, ++nS);

            if (Curve == null)
                Curve = new MouldCurve(script.Substring(7, 5), m_sail, fits);
            else
            {
                Curve.Label = script.Substring(7, 5);
                Curve.Fit(fits.ToArray());
            }
        }
Пример #9
0
        /// <summary>
        /// inserts additional points into the geo-point arrays to ensure a smooth, linear geo
        /// </summary>
        /// <param name="g">the curve object to spline</param>
        /// <param name="sFits">in: the initial set of geo-points s-positions, out: an interpolated set of geo-point s-pos</param>
        /// <param name="uFits">in: the initial set of geo-points u-positions, out: an interpolated set of geo-point u-pos</param>
        static void RefineGeo(MouldCurve g, ref double[] sFits, ref Vect2[] uFits)
        {
            int NumFits = sFits.Length;
            List<double> sPos = new List<double>(NumFits * 10);
            int uAdd, xAdd, sAdd;
            double s, dau;
            Vect2 uv = new Vect2();//, um = new Vect2(), up = new Vect2();
            Vect2 dmu = new Vect2(), dpu = new Vect2();
            Vect3 xyz = new Vect3(), dmx = new Vect3(), dpx = new Vect3();

            sPos.Add(sFits[0]);
            for (int i = 1; i < NumFits; i++)
            {
                s = (sFits[i - 1] + sFits[i]) / 2.0;
                g.xVal(s, ref uv, ref xyz);

                dmu = uFits[i - 1] - uv;
                dpu = uFits[i] - uv;

                dau = Math.Acos(-(dmu.Dot(dpu)) / dmu.Magnitude / dpu.Magnitude);
                uAdd = (int)(dau / (Math.PI / 180.0) + 1);

                g.xVal(uFits[i - 1], ref dmx);
                g.xVal(uFits[i], ref dpx);
                dmx = dmx - xyz;
                dpx = dpx - xyz;

                dau = Math.Acos(-(dmx.Dot(dpx)) / dmx.Magnitude / dpx.Magnitude);
                xAdd = (int)(dau / (Math.PI / 180.0) + 1);

                sAdd = Math.Max(xAdd, uAdd);

                for (int iS = 1; iS <= sAdd; iS++)
                {
                    s = BLAS.interpolate((double)iS / (double)sAdd, sFits[i], sFits[i - 1]);
                    sPos.Add(s);//add evenly spaced s points
                }
            }

            uFits = new Vect2[sPos.Count];
            sFits = new double[sPos.Count];
            int iA = 0;
            foreach (double sA in sPos)
            {
                uFits[iA] = new Vect2();
                g.uVal(sA, ref uFits[iA]);
                sFits[iA] = sA;
                iA++;
            }
        }
Пример #10
0
        /// <summary>
        /// Fits a multi-segement geodesic between the specified fitpoints optionally specifying which segments to girth
        /// </summary>
        /// <param name="points">the array of fitpoints, must be more than 2</param>
        /// <param name="bGirths">an array specifying which segments to girth and which to spline 
        /// count is 1 less than the fitpoints count
        /// can be null which defaults to first and last segment girths</param>
        /// <returns>true if successful, false otherwise</returns>
        internal static bool Geo(MouldCurve g, IFitPoint[] points)
        {
            if (points == null || points.Length < 2)
                return false;
            else if (points.Length == 2 && g.IsGirth(0))
                return Geo(g, points[0], points[1]);

            //compiled piecewise values
            List<double> S = new List<double>();
            List<Vect2> U = new List<Vect2>();

            //segment values
            double[] spos = null;
            Vect2[] upos = null;

            Vect3 xyz = new Vect3(), xyp = new Vect3();

            //initialize S and U
            points[0].S = 0;
            S.Add(0);
            U.Add(points[0].UV);
            for (int i = 1; i < points.Length; i++)
            {
                //span a geo between the fitpoints
                //if (i % 2 == 1)
                if( g.IsGirth(i-1) )
                {
                    if (!GeoSegment(g, points[i - 1], points[i], ref spos, ref upos))
                        return false;

                    for (int nS = 1; nS < spos.Length; nS++)
                    {
                        //scale the spos by length to get distance
                        S.Add(spos[nS] * g.Length + points[i - 1].S);
                        //copy the upos
                        U.Add(upos[nS]);
                    }
                }
                else// if (i % 2 == 0)
                {
                    g.xVal(points[i - 1].UV, ref xyp);
                    g.xVal(points[i].UV, ref xyz);
                    S.Add(xyz.Distance(xyp) + points[i-1].S);
                    U.Add(points[i].UV);
                }
                points[i].S = S.Last();//store the curent length for paramterization
            }

            //reparamaterize
            g.Length = S.Last();
            for (int i = 0; i < S.Count; i++)
                S[i] /= g.Length;

            for (int i = 0; i < points.Length; i++)
                points[i].S /= g.Length;

            //spline the combined points
            g.ReSpline(S.ToArray(), U.ToArray());
            g.FitPoints = points;
            return true;
        }
Пример #11
0
        /// <summary>
        /// using the start, end and passed geo fit points will slide the points along their normals to achieve a geodesic
        /// </summary>
        /// <param name="g">the curve object to spline</param>
        /// <param name="start">the starting point of this segment</param>
        /// <param name="end">the ending point of this segment</param>
        /// <param name="sFits">the s-positons of each geo-point</param>
        /// <param name="uFits">the u-positons of each geo-point</param>
        /// <returns>true if successful, false otherwise</returns>
        static bool FitGeo(MouldCurve g, IFitPoint start, IFitPoint end, double[] sFits, Vect2[] uFits)
        {
            int NumFits = sFits.Length;
            int INC = NumFits - 1;
            int i;

            Vect2[] uNor = new Vect2[NumFits];
            Vect3 xyz = new Vect3(), dxu = new Vect3(), dxv = new Vect3();
            Vect2 ut = new Vect2(), un = new Vect2();
            double a11, a12, a22, det;
            //calculate insurface normals at each fitpoint
            uNor[0] = new Vect2();//fixed endpoint doesnt need normal
            for (i = 1; i < INC; i++)
            {
                g.Surface.xVec(uFits[i], ref xyz, ref dxu, ref dxv);
                //covariant metric tensor components
                a11 = dxu.Norm;
                a12 = dxu.Dot(dxv);
                a22 = dxv.Norm;

                det = Math.Sqrt(a11 * a22 - a12 * a12);

                //tangent(secant) vector u components
                ut = uFits[i + 1] - uFits[i - 1];

                //contravariant normal vector components in the surface plane
                un[0] = (a12 * ut[0] + a22 * ut[1]) / det;
                un[1] = -(a11 * ut[0] + a12 * ut[1]) / det;

                //store unit normal u components
                un.Magnitude = 1;
                uNor[i] = new Vect2(un);
            }
            uNor[INC] = new Vect2();//fixed endpoint doesnt need normal

            Vect3 xPrev = new Vect3();
            Vect3 ddxu = new Vect3(), ddxv = new Vect3(), dduv = new Vect3();
            Vect3[] xNor = new Vect3[NumFits];
            Vect3[] dxNor = new Vect3[NumFits];
            Vect3[] xTan = new Vect3[NumFits];
            double[] xLen = new double[NumFits];
            bool Conver = false;
            int nNwt; Vector x; DenseVector sNor;
            for (nNwt = 0; nNwt < 50; nNwt++)
            {
                xNor[0] = new Vect3();
                //update startpoint slide position
                if (start is SlidePoint)
                {
                    dxNor[0] = new Vect3();
                    (start as SlidePoint).Curve.xCvt((start as SlidePoint).SCurve, ref uFits[0], ref xPrev, ref xNor[0], ref dxNor[0]);
                    //uFits[0][0] = FitPoints[0][1];
                    //uFits[0][1] = FitPoints[0][2];
                }
                else
                    g.xVal(uFits[0], ref xPrev);

                //update endpoint slide position
                if (end is SlidePoint)
                {
                    uFits[INC][0] = end[1];
                    uFits[INC][1] = end[2];
                }

                xLen[0] = 0;
                //calc internal point vectors
                for (i = 1; i < NumFits; i++)
                {
                    g.Surface.xCvt(uFits[i], ref xyz, ref dxu, ref dxv, ref ddxu, ref ddxv, ref dduv);

                    a11 = uNor[i][0] * uNor[i][0];
                    a12 = uNor[i][0] * uNor[i][1] * 2;
                    a22 = uNor[i][1] * uNor[i][1];

                    // insurface normal x components
                    dxu.Scale(uNor[i][0]);
                    dxv.Scale(uNor[i][1]);
                    xNor[i] = dxu + dxv;

                    //insurface normal x derivatives
                    ddxu.Scale(a11);
                    dduv.Scale(a12);
                    ddxv.Scale(a22);
                    dxNor[i] = ddxu + dduv + ddxv;

                    //forward facing tangent vector
                    xTan[i] = xyz - xPrev;
                    xPrev.Set(xyz);

                    xLen[i] = xTan[i].Magnitude;//segment length
                    xLen[0] += xLen[i];//accumulate total length

                    xTan[i].Magnitude = 1;//unit tangent vector
                }
                //update endpoint slide position
                if (end is SlidePoint)
                {
                    (end as SlidePoint).Curve.xCvt((end as SlidePoint).SCurve, ref uFits[INC], ref xyz, ref xNor[INC], ref dxNor[INC]);
                }

                DenseMatrix A = new DenseMatrix(NumFits);
                sNor = new DenseVector(NumFits);
                double p0, pp, d, d0, dp, gm, g0, gp; int ix;

                //slide startpoint
                if (start is SlidePoint)
                {
                    //mid point normal vector dotted with end point tangent vectors
                    pp = xNor[0].Dot(xTan[1]);

                    for (g0 = gp = 0, ix = 0; ix < 3; ix++)
                    {
                        //midpoint tangent and curavture variantion
                        dp = (xNor[0][ix] - pp * xTan[1][ix]) / xLen[1];

                        //mid and top point gradients
                        g0 += -dp * xNor[0][ix] + xTan[1][ix] * dxNor[0][ix];
                        gp += dp * xNor[1][ix];
                    }
                    //geodesic residual and gradients
                    A[0, 0] = g0;
                    A[0, 1] = gp;
                    sNor[0] = pp;
                }
                else//fixed start point
                {
                    A[0, 0] = 1;
                    sNor[0] = 0;
                }

                for (i = 1; i < INC; i++)//internal points
                {
                    //midpoint normal dotted with tangents
                    p0 = xNor[i].Dot(xTan[i]);// BLAS.dot(xNor[i], xTan[i]);
                    pp = xNor[i].Dot(xTan[i + 1]);//BLAS.dot(xNor[i], xTan[i + 1]);

                    for (gm = g0 = gp = 0, ix = 0; ix < 3; ix++)
                    {
                        //midpoint curvature vector
                        d = xTan[i + 1][ix] - xTan[i][ix];

                        //midpoint tangent and curavture variantion
                        d0 = (xNor[i][ix] - p0 * xTan[i][ix]) / xLen[i];
                        dp = (xNor[i][ix] - pp * xTan[i + 1][ix]) / xLen[i + 1];

                        //bottom, mid and top point gradients
                        gm += d0 * xNor[i - 1][ix];
                        g0 += (-d0 - dp) * xNor[i][ix] + d * dxNor[i][ix];
                        gp += dp * xNor[i + 1][ix];
                    }
                    A[i, i - 1] = gm;
                    A[i, i] = g0;
                    A[i, i + 1] = gp;
                    sNor[i] = -p0 + pp;
                }

                if (end is SlidePoint)//slide endpoint
                {
                    p0 = xNor[i].Dot(xTan[i]);

                    for (gm = g0 = 0, ix = 0; ix < 3; ix++)
                    {
                        //midpoint tangent and curavture variantion
                        d0 = (xNor[i][ix] - p0 * xTan[i][ix]) / xLen[i];

                        //bottom, mid and top point gradients
                        gm += d0 * xNor[i - 1][ix];
                        g0 += -d0 * xNor[i][ix] - xTan[i][ix] * dxNor[i][ix];
                    }
                    A[i, i - 1] = gm;
                    A[i, i] = g0;
                    sNor[i] = -p0;
                }
                else//fixed endpoint
                {
                    A[i, i] = 1;
                    sNor[i] = 0;
                }

                LU decomp = A.LU();
                x = (Vector)decomp.Solve(sNor);

                double Reduce = Math.Min(1, .05 / x.AbsoluteMaximum());

                if( start is SlidePoint)
                        (start as SlidePoint).SCurve -= x[0] * Reduce;

                if( end is SlidePoint)
                        (end as SlidePoint).SCurve -= x[INC] * Reduce;

                for (i = 1; i < NumFits; i++)//increment uv points
                {
                    uFits[i][0] -= x[i] * uNor[i][0] * Reduce;
                    uFits[i][1] -= x[i] * uNor[i][1] * Reduce;
                }

                if (nNwt < 5)
                {
                    //keep initial (s)-increments within bounds
                    if (start is SlidePoint)
                        (start as SlidePoint).SCurve = Utilities.LimitRange(0, (start as SlidePoint).SCurve, 1);

                    if (end is SlidePoint)
                        (end as SlidePoint).SCurve = Utilities.LimitRange(0, (end as SlidePoint).SCurve, 1);

                    //	keep initial (u)-increments within bounds
                    for (i = 1; i < NumFits - 1; i++)
                    {
                        uFits[i][0] = Utilities.LimitRange(0, uFits[i][0], 1);
                        uFits[i][1] = Utilities.LimitRange(-.125, uFits[i][1], 1.125);
                    }
                }
                double xmax = x.AbsoluteMaximum();
                double smax = sNor.AbsoluteMaximum();
                if (Conver = (x.AbsoluteMaximum() < 1e-8 && sNor.AbsoluteMaximum() < 1e-7))
                    break;
            }

            if (!Conver)
                return false;

            g.Length = xLen[0];//store length

            //calculate unit length (s)-parameter values
            sFits[0] = 0;
            for (i = 1; i < NumFits; i++)
                sFits[i] = sFits[i - 1] + xLen[i] / xLen[0];
            //g.m_uvs = uFits;
            g.ReSpline(sFits, uFits);
            return true;
        }
Пример #12
0
        /// <summary>
        /// Fits a geodesic between the start and end points and returns the geo fit arrays for post-processing
        /// </summary>
        /// <param name="g">the curve object to fit with</param>
        /// <param name="start">the starting point of the segment</param>
        /// <param name="end">the end point of the segment</param>
        /// <param name="sFits">in: null, out: the segment s-positions of each geo fitting point</param>
        /// <param name="uFits">in: null, out: the segment u-positions of each geo fitting point</param>
        /// <returns>true if successful, false otherwise</returns>
        internal static bool GeoSegment(MouldCurve g, IFitPoint start, IFitPoint end, ref double[] sFits, ref Vect2[] uFits)
        {
            if (start == end || start.UV == end.UV || (start is SlidePoint && end is SlidePoint))
                return false;

            //start.S = 0;
            //end.S = 1;
            int REZ = 9;
            int END = REZ - 1;
            int i;

            double d = 0, sguess;
            Vect3 xI = new Vect3(), xs = new Vect3(), xe = new Vect3();

            Vect2 utemp = new Vect2();
            uFits = new Vect2[REZ];
            sFits = new double[REZ];
            //attempt a better starting slide position
            if (start is SlidePoint)
            {
                g.xVal(end.UV, ref xI);
                sguess = (start as SlidePoint).SCurve;
                if ((start as SlidePoint).Curve.xClosest(ref sguess, ref utemp, ref xI, ref d, 1e-9, false))
                    (start as SlidePoint).SCurve = sguess;
            }

            sFits[0] = 0;
            uFits[0] = new Vect2(start.UV);

            //attempt a better starting slide position
            if (end is SlidePoint)
            {
                g.xVal(uFits[0], ref xI);
                sguess = (end as SlidePoint).SCurve;
                if ((end as SlidePoint).Curve.xClosest(ref sguess, ref utemp, ref xI, ref d, 1e-9, false))
                    (end as SlidePoint).SCurve = sguess;
            }
            sFits[END] = 1;
            uFits[END] = new Vect2(end.UV);

            //interpolate 8 internal points in xyz
            g.xVal(uFits[0], ref xs);
            g.xVal(uFits[END], ref xe);
            for (i = 1; i < END; i++)
            {
                uFits[i] = new Vect2();
                sFits[i] = (double)i / (double)END;
                for (int j = 0; j < 3; j++)
                    xI[j] = BLAS.interpolate(sFits[i], xe[j], xs[j]);
                for (int j = 0; j < 2; j++)//interpolate starting uv guess
                    uFits[i][j] = BLAS.interpolate(sFits[i], uFits[END][j], uFits[0][j]);
                if (!g.Surface.xClosest(ref uFits[i], ref xI, ref d, 1e-5))
                    for (int j = 0; j < 2; j++)//default to uv interp if xyz fails
                        uFits[i][j] = BLAS.interpolate(sFits[i], uFits[END][j], uFits[0][j]);
            }

            if (!FitGeo(g, start, end, sFits, uFits))
                return false;

            RefineGeo(g, ref sFits, ref uFits);

            return FitGeo(g, start, end, sFits, uFits);
        }
Пример #13
0
 public CurvePoint(double s, MouldCurve curve, Equation Sequ)
 {
     m_sPos = s;
     S_Equ = Sequ;
     m_curve = curve;
 }
Пример #14
0
 public CurvePoint(double s, MouldCurve curve, double sCurve)
 {
     m_sPos = s;
     S_Equ = new Equation("s", sCurve.ToString());
     m_curve = curve;
 }
Пример #15
0
        private void helpToolStripButton_Click(object sender, EventArgs e)
        {
            if (ActiveSail == null)
                return;

            if (Tree.SelectedTag != null)
            {
                IRebuild tag = Tree.SelectedTag as IRebuild;
                List<IRebuild> rebuilds = new List<IRebuild>();
                if (tag != null)
                    tag.GetParents(ActiveSail, rebuilds);

                StringBuilder sb = new StringBuilder();
                foreach (IRebuild rb in rebuilds)
                    sb.AppendLine(rb.Label);
                MessageBox.Show(sb.ToString());
                return;
            }

            VariableGroup varGroup = new VariableGroup("Vars", ActiveSail);
            varGroup.Add(new Equation("yarScale", 1.0));
            varGroup.Add(new Equation("yarnDPI", "yarScale * 12780"));
            varGroup.Add(new Equation("targetScale", 1.0));
            varGroup.Add(new Equation("targetDPI", "targetScale * 14416"));
            ActiveSail.Add(varGroup);

            UpdateViews(ActiveSail.CreateOuterCurves());

            //Geodesic geo = new Geodesic("Geo", ActiveSail, new IFitPoint[] { new FixedPoint(.1, .1), new FixedPoint(.1, .9) });
            MouldCurve v1 = new MouldCurve("v1", ActiveSail, new IFitPoint[] { new FixedPoint(1, 0), new FixedPoint(.3, .4), new FixedPoint(.1, .8), new FixedPoint(0, 1) });

            MouldCurve v2 = new MouldCurve("v2", ActiveSail, new IFitPoint[] { new FixedPoint(1, 0), new FixedPoint(0, 1) });

            MouldCurve v3 = new MouldCurve("v3", ActiveSail, new IFitPoint[] { new FixedPoint(1, 0), new FixedPoint(.95, .25), new FixedPoint(.9, .55), new FixedPoint(.65, .85), new FixedPoint(0, 1) });
            //MouldCurve v4 = new MouldCurve("v4", ActiveSail, new IFitPoint[] { new FixedPoint(1, 0), new FixedPoint(.8, .5), new FixedPoint(1, 1) });
            //MouldCurve v5 = new MouldCurve("v5", ActiveSail, new IFitPoint[] { new FixedPoint(1, 0), new FixedPoint(1, 1) });
            CurveGroup grp = new CurveGroup("Warps", ActiveSail);
            grp.Add(v1);
            grp.Add(v2);
            grp.Add(v3);
            grp.Add(new MouldCurve("g3", ActiveSail,
                new IFitPoint[] {
                    new FixedPoint(0,0),
                    new SlidePoint(v1, 0),
                    new FixedPoint(1,.5) }));
            grp.Add(new MouldCurve("g4", ActiveSail,
                new IFitPoint[] {
                    new FixedPoint(1, 0),
                    new FixedPoint(.4, .4),
                    new FixedPoint(.3, .7),
                    new FixedPoint(0,1)}));
            //grp.Add(v4);
            //grp.Add(v5);
            //grp.Add(guide);

            CurveGroup guides = new CurveGroup("Guides", ActiveSail);
            GuideComb guide = new GuideComb("Guide", ActiveSail,
                new IFitPoint[] {
                    new FixedPoint(0, .5),
                    new SlidePoint(v2, .5),
                    new FixedPoint(1, .5) },
                new Vect2[] {
                    new Vect2(0, 1),
                    new Vect2(.3, .55),
                    new Vect2(.5, .5),
                    new Vect2(.7, .55),
                    new Vect2(1, 1) });
            guides.Add(guide);

            YarnGroup yar = new YarnGroup("yar1", ActiveSail, varGroup["yarnDPI"], varGroup["targetDPI"]);
            yar.Warps.Add((ActiveSail.FindGroup("Outer") as CurveGroup)[0]);
            yar.Warps.Add((ActiveSail.FindGroup("Outer") as CurveGroup)[1]);
            yar.Guide = guide;
            yar.DensityPos = new List<double>() { 0.2, 0.8 };
            ActiveSail.Add(grp);
            ActiveSail.Add(guides);
            ActiveSail.Add(yar);
            UpdateViews(grp);
            UpdateViews(guides);

            //YarnGroup LuYar = new YarnGroup("LuYar", ActiveSail, 12780);
            //LuYar.DensityPos.AddRange(new double[] { 0.25, 0.5, 0.75 });
            //LuYar.YarnsUpdated += LuYar_YarnsUpdated;
            ////if (LuYar.LayoutYarns(new List<MouldCurve>() { lu, mi, le }, guide, 14416) > 0)
            ////DateTime now = DateTime.Now;
            ////LuYar.LayoutYarns(grp, guide, 14416, LuYar.SpreadYarnsAlongGuide);
            ////TimeSpan gde = DateTime.Now - now;
            ////now = DateTime.Now;

            ////LuYar.LayoutYarns(grp, guide, 14416, LuYar.SpreadYarnsAcrossWarps);
            ////TimeSpan wrps = DateTime.Now - now;
            ////now = DateTime.Now;
            ////MessageBox.Show(string.Format("AcrossWarps: {0}\nAlongGuide: {1}", wrps.TotalMilliseconds, gde.TotalMilliseconds));

            UpdateViews(guides);
            UpdateViews(grp);
            yar.Update(ActiveSail);
            UpdateViews(yar);
            //if (LuYar.LayoutYarns(grp, guide, 14416) > 0
            //	|| MessageBox.Show(String.Format("Failed to match Target Dpi\nTarget: {0}\nAchieved: {1}\nContinue Anyway?", LuYar.TargetDpi, LuYar.AchievedDpi), "Yarn Generation Failed", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes )
            //	ActiveSail.Add(LuYar);

            ////Yarns.YarnGroup LeYar = new Yarns.YarnGroup("LeYar", ActiveSail, 12780);
            ////if (LeYar.LayoutYarns(new List<MouldCurve>() { mi, le }, guide, 14416) > 0)
            ////	ActiveSail.Add(LeYar);

            ////Rebuild(null);

            //UpdateViews(LuYar);
            //Rebuild(grp);
            //Rebuild(grp);
            //Rebuild(guides);
            //Rebuild(LuYar);
            View.Refresh();
            ActiveSail.Rebuild(null);
        }
Пример #16
0
        private void CreateCurve(string script)
        {
            List<IFitPoint> fits = new List<IFitPoint>();
            int nS = script.IndexOf("tarting");
            nS = script.IndexOf(' ', nS);
            fits.Add(ReadFitPoint(script, ++nS));
            while ((nS = script.IndexOf("hrough", nS)) > 0)
            {
                nS += 6;
                while (script[++nS] == ' ') ;//skip spaces
                fits.Add(ReadFitPoint(script, nS));
            }
            nS = script.IndexOf("topping");
            nS = script.IndexOf(' ', nS);
            fits.Add(ReadFitPoint(script, ++nS));

            if (Curve == null)
                Curve = new MouldCurve(script.Substring(7, 5), m_sail, fits.ToArray());
            else
            {
                Curve.Label = script.Substring(7, 5);
                Curve.Fit(fits.ToArray());
            }
        }
Пример #17
0
 /// <summary>
 /// Spans a girth between the start and end point
 /// faster than using Geo(IFitPoint[] fits) for 2 points
 /// </summary>
 /// <param name="g">the curve used for splining</param>
 /// <param name="start">the starting fitpoint</param>
 /// <param name="end">the ending fitpoint</param>
 /// <returns>true if successful, false otherwise</returns>
 internal static bool Geo(MouldCurve g, IFitPoint start, IFitPoint end)
 {
     double[] s = null;
     Vect2[] u = null;
     start.S = 0;
     end.S = 1;
     return GeoSegment(g, start, end, ref s, ref u);
 }
Пример #18
0
        //public void Add(IGroup g)
        //{
        //    Entity[] groupEntities = g.CreateEntities();
        //    devDept.Eyeshot.Labels.Label[] groupLabels = g.EntityLabel;
        //    if (groupEntities == null)
        //        return;
        //    int layerIndex = AddLayer(g.Label, true);
        //    for (int i = 0; i < groupEntities.Length; i++)
        //    {
        //        if( groupEntities[i].LayerIndex == 0 )
        //            groupEntities[i].LayerIndex = layerIndex;
        //        Add(groupEntities[i], groupLabels);
        //    }
        //}
        public Entity[][] Add(MouldCurve curve)
        {
            IRebuild g = curve.Group;
            int layerIndex = AddLayer(g.Label, Color.Black, true);
            List<Entity> es = curve.CreateEntities().ToList();
            devDept.Eyeshot.Labels.Label[] labels = curve.EntityLabel;

            foreach (Entity e in es)
                e.LayerIndex = layerIndex;
            if (labels == null)
                return AddRange(es);
            return AddRange(es, labels);
        }
Пример #19
0
        /// <summary>
        /// fit a curve to the specified points
        /// requires S parameter specified for each point
        /// requires at least 5 points
        /// </summary>
        /// <param name="points">points to fit to, minimum 5</param>
        internal static void SimpleFit(MouldCurve c, IFitPoint[] points)
        {
            Vect2 uv = new Vect2();
            Vect3 x0 = new Vect3();
            Vect3 x1 = new Vect3();

            double[][] uFits = new double[2][];
            double[] sFits = new double[points.Length];
            uFits[0] = new double[points.Length];
            uFits[1] = new double[points.Length];
            //complile fitpoints to fitting arrays
            sFits[0] = 0;
            points[0][0] = 0;
            c.xVal(points[0].UV, ref x0);//initialize starting x point
            for (int nFit = 0; nFit < points.Length; nFit++)
            {
                //sFits[nFit] = fits[nFit][0];
                uFits[0][nFit] = points[nFit][1];
                uFits[1][nFit] = points[nFit][2];

                if (nFit > 0)
                {
                    c.xVal(points[nFit].UV, ref x1);
                    points[nFit][0] = points[nFit - 1][0] + x1.Distance(x0);
                    x0.Set(x1);//store previous x point
                }
            }

            for (int nFit = 0; nFit < points.Length; nFit++)
                sFits[nFit] = points[nFit][0] /= points.Last()[0];//convert length to position
            //sFits[sFits.Length-1] = fits.Last()[0] = 1;//enforce unit length

            c.FitPoints = points;
            c.ReSpline(sFits, uFits);
        }
Пример #20
0
        private void SelectCurve(MouldCurve cur)
        {
            if (cur == null)
                return;
            if (m_temp != null)
                View.Remove(m_temp);

            Curve = cur;

            IFitPoint[] pts = new IFitPoint[Curve.FitPoints.Length];
            for (int i = 0; i < pts.Length; i++)
                pts[i] = Curve[i].Clone();

            m_temp = new MouldCurve(cur);
            m_temp.Label += "[preview]";
            m_tents = View.AddRange(m_temp.CreateEntities(true));

            foreach (Entity[] ents in m_tents)
                foreach (Entity ee in ents)
                {
                    ee.Color = Color.LightSkyBlue;
                    ee.ColorMethod = colorMethodType.byEntity;
                    if ( ee.LineWeight == 1 ) ee.LineWeight = 2.0f;
                    ee.LineWeightMethod = colorMethodType.byEntity;
                }

            m_edit.AutoFill = Sail.Watermark(Curve, Tree.SelectedTag as IGroup).ToList<object>();
            m_edit.ReadCurve(m_temp);
            m_edit.Label = Curve.Label;
            m_edit.Refresh();

            if (Tree.SelectedTag != Curve)
                Tree.SelectedTag = Curve;

            View.Select(Curve);
            View.Refresh();
        }
Пример #21
0
        /// <summary>
        /// Interpolates intermediate points in uv and fits a curve
        /// </summary>
        /// <param name="c">the curve to fit</param>
        /// <param name="points">points to fit to, minimum 2</param>
        internal static void InterpoFit(MouldCurve c, IFitPoint[] points)
        {
            if (points.Length <= 1 || points.Length >= 5)//need at least 2 points to fit a curve, can't interpolate more than 4
                return;
            //recalculate s-positions based on xyz-values
            //if (RePos)
            //{
            //	Vect2 uv = new Vect2();
            //	Vect3 x0 = new Vect3();
            //	Vect3 x1 = new Vect3();
            //	fits[0][0] = 0;//initialize s paramter
            //	Surface.xVal(fits[0].UV, ref x0);//initialize starting x point
            //	for (int nFit = 1; nFit < fits.Length; nFit++)
            //	{
            //		Surface.xVal(fits[nFit].UV, ref x1);
            //		fits[nFit][0] = fits[nFit - 1][0] + x1.Distance(x0);
            //		x1.Set(x0);//store previous x point
            //	}
            //	for (int nFit = 0; nFit < fits.Length; nFit++)
            //		fits[nFit][0] /= fits.Last()[0];//convert length to position
            //	fits.Last()[0] = 1;//enforce unit length
            //}

            //linear uv interpolation to match minimum 5 points required

                double[][] uFits = new double[2][];
                double[] sFits = new double[5];
                uFits[0] = new double[5];
                uFits[1] = new double[5];
                double p;
                int i, nint = 0;
                Vect3 x2 = new Vect3(), x1 = new Vect3();
                Vect2 umid = new Vect2();
                Dictionary<int, int> FitstoSFits = new Dictionary<int, int>();
                if (points.Length == 4)
                {
                    //store fitpoints
                    sFits[nint] = points[nint][0] = 0;
                    uFits[0][nint] = points[nint][1];
                    uFits[1][nint] = points[nint][2];
                    c.xVal(points[nint].UV, ref x1);
                    FitstoSFits[nint] = nint;
                    nint++;
                    //store fitpoints
                    //sFits[nint] = fits[nint][0];
                    uFits[0][nint] = points[nint][1];
                    uFits[1][nint] = points[nint][2];
                    c.xVal(points[nint].UV, ref x2);
                    sFits[nint] = x2.Distance(x1) + sFits[nint - 1];
                    FitstoSFits[nint] = nint;
                    nint++;
                    //insert midpoint
                    //sFits[nint] = (fits[nint][0] + fits[nint - 1][0]) / 2.0;
                    umid = points[nint].UV + points[nint - 1].UV;
                    umid /= 2;
                    uFits[0][nint] = umid[0];
                    uFits[1][nint] = umid[1];
                    c.xVal(umid, ref x1);
                    sFits[nint] = x2.Distance(x1) + sFits[nint - 1];
                    nint++;
                    //store fitpoints
                    //sFits[nint] = fits[nint-1][0];
                    uFits[0][nint] = points[nint - 1][1];
                    uFits[1][nint] = points[nint - 1][2];
                    c.xVal(points[nint - 1].UV, ref x2);
                    sFits[nint] = x2.Distance(x1) + sFits[nint - 1];
                    FitstoSFits[nint - 1] = nint;
                    nint++;
                    //store fitpoints
                    //sFits[nint] = fits[nint-1][0];
                    uFits[0][nint] = points[nint - 1][1];
                    uFits[1][nint] = points[nint - 1][2];
                    c.xVal(points[nint - 1].UV, ref x1);
                    sFits[nint] = x2.Distance(x1) + sFits[nint - 1];
                    FitstoSFits[nint - 1] = nint;
                    nint++;
                }
                else
                {
                    int num = (5 - points.Length) / (points.Length - 1);//insertion points
                    num = num < 1 ? 1 : num;
                    for (i = 0; i < points.Length - 1; i++)
                    {
                        //store fitpoints
                        //sFits[nint] = fits[i][0];
                        uFits[0][nint] = points[i][1];
                        uFits[1][nint] = points[i][2];
                        FitstoSFits[i] = nint;
                        c.xVal(points[i].UV, ref x1);
                        if (i == 0)
                        {
                            sFits[nint] = 0;
                        }
                        else
                        {
                            sFits[nint] = x2.Distance(x1) + sFits[nint - 1];
                        }
                        x2.Set(x1);//store xprev
                        nint++;
                        for (int j = 1; j <= num; j++)
                        {
                            //interpolate insertion points and store
                            p = BLAS.interpolant(j, num + 2);
                            //sFits[nint] = BLAS.interpolate(p, fits[i + 1][0], fits[i][0]);
                            umid[0] = uFits[0][nint] = BLAS.interpolate(p, points[i + 1][1], points[i][1]);
                            umid[1] = uFits[1][nint] = BLAS.interpolate(p, points[i + 1][2], points[i][2]);
                            c.xVal(umid, ref x1);
                            sFits[nint] = x2.Distance(x1) + sFits[nint - 1];
                            x2.Set(x1);//store xprev
                            nint++;
                        }
                    }
                    //endpoint
                    //sFits[nint] = 1;
                    uFits[0][nint] = points[i][1];
                    uFits[1][nint] = points[i][2];
                    c.xVal(points[i].UV, ref x1);
                    sFits[nint] = x2.Distance(x1) + sFits[nint - 1];
                    System.Diagnostics.Debug.Assert(nint == 4);
                    FitstoSFits[i] = nint;

                }

                for (i = 0; i < sFits.Length; i++)
                    sFits[i] /= sFits.Last();
                //sFits[sFits.Length - 1] = 1;

                foreach (int key in FitstoSFits.Keys)
                    points[key][0] = sFits[FitstoSFits[key]];

                c.FitPoints = points;
                c.ReSpline(sFits, uFits);
        }
Пример #22
0
        IGroup[] CreateInnerCurves()
        {
            CurveGroup outer = FindGroup("Outer") as CurveGroup;
            if (outer == null)
                outer = CreateOuterCurves() as CurveGroup;

            IGroup[] rets = new IGroup[2];
            //SurfaceCurve gir = null;
            for (int i = 0; i < 2; i++)
            {
                CurveGroup curves = new CurveGroup(i == 0 ? "Horiz" : "Verts", this);
                for (double dg = 0.0; dg < 1; dg += 0.1)
                {
                    IFitPoint[] gir = new IFitPoint[2];
                    gir[1] = new CurvePoint(1, outer[2 * i + 1], dg);

                    //gir[1] = new FixedPoint(.3, .3);

                    gir[0] = new CurvePoint(0, outer[2 * i], dg);

                    MouldCurve curve = new MouldCurve(String.Format("{0}ec-{1:##0}%", i == 0 ? "S" : "V", dg * 100), this, null);
                    curve.Fit(gir);
                    curves.Add(curve);
                }
                Add(curves);
                rets[i] = curves;
            }
            return rets;
        }
Пример #23
0
 internal void Fit(MouldCurve clone)
 {
     Fit(clone.FitPoints.ToArray(), clone.m_bGirths.ToArray());
 }
Пример #24
0
        void CreateSpokes()
        {
            const int NGIR = 5;
            const int NANG = 5;
            Vect2[] uv = new Vect2[2];
            CurveGroup group;
            //for (int nLu = 0; nLu < 1; nLu++)
            for (int nGir = 0; nGir < NGIR; nGir++)
            {
                group = new CurveGroup(string.Format("Spokes[{0}]", nGir), this);
                //group = new CurveGroup(string.Format("Spokes[{0}][{1}]", nLu, nGir), S);

                uv[0] = new Vect2(-0.3, BLAS.interpolant(nGir, NGIR));
                //uv[1-nLu] = new Vect2(1,0);

                for (int nAng = 0; nAng < NANG; nAng++)
                {
                    uv[1] = new Vect2(1.3, BLAS.interpolant(nAng, NANG));

                    MouldCurve g = new MouldCurve(string.Format(group.Label + "[{0}]", nAng), this, null);
                    g.Fit(uv[0], uv[1]);
                    group.Add(g);
                }
                Add(group);
            }
        }
Пример #25
0
 public MouldCurve(MouldCurve curve)
 {
     m_sail = curve.Sail;
     m_label = curve.Label;
     Fit(curve);
 }
Пример #26
0
 public SlidePoint(double s, MouldCurve curve, double sCurve)
     : base(s, curve, sCurve)
 {
 }
Пример #27
0
 public void ReadEditor(IFitEditor edit)
 {
     if (edit == null )
     throw new ArgumentNullException();
     if( !(edit is CurvePointEditor) )
         throw new ArgumentException("Type must be CurvePointEditor");
     CurvePointEditor cdit = edit as CurvePointEditor;
     m_curve = cdit.Curve;
     S_Equ = cdit.CS;
 }