コード例 #1
0
        void CreateFitCurves()
        {
            //---------------------------------------
            //convert point to vector
            int            j    = currentPointSet.Count;
            List <Vector2> data = new List <Vector2>(j);

            for (int i = 0; i < j; ++i)
            {
                Point pp = currentPointSet[i];
                data.Add(new Vector2(pp.x, pp.y));
            }

            //CurvePreprocess.Linearize(data, 8);
            //List<Vector2> reduced = CurvePreprocess.RdpReduce(data, 2);

            //string code = DumpPointsToString();
            //string code2 = DumpPointsToString2();
            //var data2 = data;
            var data2 = CurvePreprocess.RdpReduce(data, 2);

            j = data2.Count;
            List <Point> simplifiedPoints = new List <Point>();

            this.simplifiedPointSets.Add(simplifiedPoints);
            for (int i = 0; i < j; ++i)
            {
                var pp = data2[i];
                simplifiedPoints.Add(new Point((int)pp.x, (int)pp.y));
            }


            CubicBezier[] cubicBzs = CurveFit.Fit(data2, 8);
            cubicCurves.AddRange(cubicBzs);
        }
コード例 #2
0
    public void test()
    {
        if (UseBlend == false)
        {
            int frameNum = bp.frames;


            pos.Clear();
            rot.Clear();
            BVHParser.BVHBone.BVHChannel[] channels = bp.root.channels;

            for (int i = 0; i < frameNum; i++)
            {
                Vector3 p, r;
                p = new Vector3(-channels[0].values[i], channels[2].values[i], -channels[1].values[i]);
                r = new Vector3(channels[3].values[i], channels[4].values[i], channels[5].values[i]);
                pos.Add(p);
                rot.Add(r);
                //Gizmos.DrawSphere(p, 3);
            }
            List <Vector3> reduced = CurvePreprocess.RdpReduce(pos, error);   // use the Ramer-Douglas-Pueker algorithm to remove unnecessary points
            Debug.Log(reduced.Count);
            curves.Clear();
            curves.AddRange(CurveFit.Fit(reduced, error2));            // fit the curves to those points
            createControlObj();

            DrawMutiCurve();
        }
    }
コード例 #3
0
ファイル: Program.cs プロジェクト: oetyng/curves
        public static void Main(string[] args)
        {
            // do once so it's in cache
            List <VECTOR> data    = new List <VECTOR>(TestData.data);
            List <VECTOR> reduced = CurvePreprocess.RdpReduce(data, 2);

            CurveFit.Fit(reduced, 8);

            Console.WriteLine("{0,-40}{1}", "typeof(VECTOR)", typeof(VECTOR).FullName);
            Console.WriteLine("{0,-40}{1}", "RyuJIT enabled", RyuJitStatus.RyuJitEnabled);
            Console.WriteLine("{0,-40}{1}", "SIMD enabled", RyuJitStatus.SimdEnabled);
            Console.WriteLine("{0,-40}{1}", "Iterations Per Test", N_ITERS);
            Console.WriteLine("{0,-40}{1}", "Test Data Size", data.Count);
            Console.WriteLine();

            double    totalTime = 0;
            Stopwatch sw        = new Stopwatch();

            Console.WriteLine("{0,-10} {1,-10} {2,-10} {3,-10} {4,-10} {5}", "RDP Error", "Fit Error", "Points", "Curves", "Time (s)", "Time Per Iter (ms)");
            Console.WriteLine("{0,-10} {1,-10} {2,-10} {3,-10} {4,-10} {5}", "---------", "---------", "------", "------", "--------", "------------------");
            foreach (FLOAT rdpError in _paramRdpError)
            {
                foreach (FLOAT fitError in _paramFitError)
                {
                    int    nPts, nCurves;
                    double t = runTest(sw, data, rdpError, fitError, out nPts, out nCurves);
                    totalTime += t;
                    Console.WriteLine("{0,-10} {1,-10} {2,-10} {3,-10} {4,-10:N4} {5,-10:N4}", rdpError, fitError, nPts, nCurves, t, (t / N_ITERS) * 1000);
                }
            }

            Console.WriteLine();
            Console.WriteLine("TOTAL TIME: " + totalTime);
            Console.WriteLine();
        }
        /// <summary>
        /// Various preprocesses available to apply to point data.
        /// </summary>
        /// <param name="pts">List of points on the curve.</param>
        /// <param name="preprocessMode">Mode, if any, to apply as preprocessing.</param>
        /// <param name="linearDist">See CurvePreprocess.Linearize.</param>
        /// <param name="rdpError">See CurvePreprocess.RdpReduce</param>
        /// <returns></returns>
        public static List <Vector2> Preprocess(List <Vector2> pts, ePreprocessModes preprocessMode, float linearDist, float rdpError)
        {
            switch (preprocessMode)
            {
            case ePreprocessModes.NONE:             return(pts);

            case ePreprocessModes.LINEAR:   return(CurvePreprocess.Linearize(pts, linearDist));

            case ePreprocessModes.RDP:              return(CurvePreprocess.RdpReduce(pts, rdpError));

            default:                                                return(CurvePreprocess.RemoveDuplicates(pts));
            }
        }
コード例 #5
0
        public static int Main(string[] args)
        {
            // Before we do anything, we want to call these to force them to be JITed. Ohterwise the first time they are called will give wildly different
            // performance results than the user expects. This only takes a few ms, so it won't slow down app startup that much.
            List <VECTOR> data = new List <VECTOR>(TestData.data);

            CurvePreprocess.Linearize(data, 8);
            List <VECTOR> reduced = CurvePreprocess.RdpReduce(data, 2);

            CurveFit.Fit(reduced, 8);

            // Okay, now run the app
            return(WpfMain.run <App>());
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: oetyng/curves
        private static double runTest(Stopwatch sw, List <VECTOR> data, FLOAT rdpError, FLOAT fitError, out int nPtsReduced, out int nCurves)
        {
            List <VECTOR> reduced = null;

            CubicBezier[] curves = null;
            sw.Reset();
            sw.Start();
            for (int i = 0; i < N_ITERS; i++)
            {
                reduced = CurvePreprocess.RdpReduce(data, rdpError);
                curves  = CurveFit.Fit(reduced, fitError);
            }
            sw.Stop();
            nPtsReduced = reduced.Count;
            nCurves     = curves.Length;
            return(sw.Elapsed.TotalSeconds);
        }
コード例 #7
0
ファイル: DrawingSurface.cs プロジェクト: oetyng/curves
        private static List <VECTOR> preprocess(List <VECTOR> pts, PreprocessModes ppMode, FLOAT linDist, FLOAT rdpError)
        {
            switch (ppMode)
            {
            case PreprocessModes.NONE:
                return(pts);

            case PreprocessModes.LINEAR:
                return(CurvePreprocess.Linearize(pts, linDist));

            case PreprocessModes.RDP:
                return(CurvePreprocess.RdpReduce(pts, rdpError));

            default:
                _log.error("Invalid PreprocessMode");
                return(CurvePreprocess.RemoveDuplicates(pts));
            }
        }
コード例 #8
0
        public List <CubicBezier> FitBezier(List <Vector3> pts, List <float> times, bool useRdp = true)
        {
            AllInputPoints = new List <Vector3d>(pts.Count);

            foreach (var pt in pts)
            {
                AllInputPoints.Add(pt);
            }
            inputPointsTree = new PointAABBTree3(new PointSet(AllInputPoints.ToArray()));

            AllInputPointTimes = times;

            if (useRdp)
            {
                var reduced = CurvePreprocess.RdpReduce(pts, Globals.RDP_ERROR, out List <int> keepIdx);
                PointsKeepIdx = keepIdx;
                InputPoints   = reduced;
                Curves        = new List <CubicBezier>(CurveFit.Fit(reduced, Globals.BEZIER_FIT_MAX_ERROR));
            }
            else
            {
                InputPoints = pts;
                Curves      = new List <CubicBezier>(CurveFit.Fit(pts, Globals.BEZIER_FIT_MAX_ERROR));
            }

            Curves[0] = new CubicBezier(
                Curves[0].p0,
                Curves[0].p0 + (Curves[0].p1 - Curves[0].p0).magnitude * Vector3.forward,
                Curves[0].p2,
                Curves[0].p3);

            if (Curves.Count == 0)
            {
                ControlPoints = new Vector3[0];
            }
            else
            {
                ControlPoints    = new Vector3[1 + 3 * Curves.Count];
                ControlPoints[0] = Curves[0].p0;
            }
            for (int i = 0; i < Curves.Count; ++i)
            {
                ControlPoints[3 * i + 1] = Curves[i].p1;
                ControlPoints[3 * i + 2] = Curves[i].p2;
                ControlPoints[3 * i + 3] = Curves[i].p3;
            }


            float[] cpData = new float[ControlPoints.Length * 3];
            for (int i = 0; i < ControlPoints.Length; ++i)
            {
                cpData[3 * i + 0] = ControlPoints[i].x;
                cpData[3 * i + 1] = ControlPoints[i].y;
                cpData[3 * i + 2] = ControlPoints[i].z;
            }

            if (_path != IntPtr.Zero)
            {
                _DeleteUnmanagedPathObject(_path);
            }
            _path = _CreateUnmanagedPathObject(cpData, ControlPoints.Length);

            CacheArcLength();

            if (times.Count == 0)
            {
                paramToTimeCache = paramToArcLengthCache;
            }
            else
            {
                CacheTime();
            }

            InputPointArcLengths = new List <float>(InputPoints.Count);
            foreach (var pt in InputPoints)
            {
                var res = GetClosestPoint(pt, out Vector3 closest, out int bezierIdx, out float param);
                if (res)
                {
                    InputPointArcLengths.Add(GetArcLengthFromSplineParam(bezierIdx, param));
                }
                else
                {
                    throw new Exception("Something horrible happened!");
                }
            }

            return(Curves);
        }
コード例 #9
0
        public void FindBestAug(GameObject[] linepoints)
        {
            frame = GlobalData.FrameCountList[0];
            //hip = GameObject.Find("hip");
            // c_numSamples = GlobalData.FrameCount+1;
            List <Vector3> pts = new List <Vector3>();

            for (int i = 0; i < linepoints.Length; i++)
            {
                pts.Add(linepoints[i].transform.position);
            }
            CurvePreprocess.RemoveDuplicates(pts);
            List <Vector3> reduced = CurvePreprocess.RdpReduce(pts, 0.0001f);

            CubicBezier[] curves = CurveFit.Fit(reduced, 0.1f);

            Vector3 offset = new Vector3(1, 0, 0);

            for (int i = 0; i < curves.Length; i++)
            {
                GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Cube);
                obj.name = "conp0";
                obj.transform.localPosition = curves[i].p0 - offset;
                obj.transform.localScale    = new Vector3(0.1f, 0.1f, 0.1f);
                obj.transform.SetParent(this.transform);

                GameObject obj1 = GameObject.CreatePrimitive(PrimitiveType.Cube);
                obj1.name = "conp1";
                obj1.transform.localPosition = curves[i].p1 - offset;
                obj1.transform.localScale    = new Vector3(0.1f, 0.1f, 0.1f);
                obj1.transform.SetParent(this.transform);

                GameObject obj2 = GameObject.CreatePrimitive(PrimitiveType.Cube);
                obj2.name = "conp2";
                obj2.transform.localPosition = curves[i].p2 - offset;
                obj2.transform.localScale    = new Vector3(0.1f, 0.1f, 0.1f);
                obj2.transform.SetParent(this.transform);

                GameObject obj3 = GameObject.CreatePrimitive(PrimitiveType.Cube);
                obj3.name = "conp3";
                obj3.transform.localPosition = curves[i].p3 - offset;
                obj3.transform.localScale    = new Vector3(0.1f, 0.1f, 0.1f);
                obj3.transform.SetParent(this.transform);

                GameObject[] contset = { obj, obj1, obj2, obj3 };
                controlpts.Add(contset);
            }


            for (int i = 0; i < controlpts.Count; i++)
            {
                Vector3[] vcot = { controlpts[i][0].transform.position, controlpts[i][1].transform.position, controlpts[i][2].transform.position, controlpts[i][3].transform.position };
                prevcontrolpts.Add(vcot);
            }

            if (controlpts.Count > 1)
            {
                c_numSamples = (GlobalData.FrameCountList[0] / controlpts.Count) + 1;
            }
            else
            {
                c_numSamples = GlobalData.FrameCountList[0];
            }

            //DrawBezier();
            calparaBezier();
            InitializeArcLengths();
            tangentCalculation();
            for (int i = 0; i < tangpoint.Count; i++)
            {
                origtangpoint.Add(tangpoint[i]);
            }
        }