コード例 #1
0
        /// <summary>
        /// Decompose a curve into a collection of bezier curves.<br/>
        /// </summary>
        /// <param name="curve">The curve object.</param>
        /// <param name="normalize">Set as per default false, true normalize the knots between 0 to 1.</param>
        /// <returns>Collection of curve objects, defined by degree, knots, and control points.</returns>
        internal static List <NurbsBase> DecomposeIntoBeziers(NurbsBase curve, bool normalize = false)
        {
            int           degree        = curve.Degree;
            List <Point4> controlPoints = curve.ControlPoints;
            KnotVector    knots         = curve.Knots;

            // Find all of the unique knot values and their multiplicity.
            // For each, increase their multiplicity to degree + 1.
            Dictionary <double, int> knotMultiplicities = knots.Multiplicities();
            int reqMultiplicity = degree + 1;

            // Insert the knots.
            foreach (KeyValuePair <double, int> kvp in knotMultiplicities)
            {
                if (kvp.Value >= reqMultiplicity)
                {
                    continue;
                }
                List <double> knotsToInsert = CollectionHelpers.RepeatData(kvp.Key, reqMultiplicity - kvp.Value);
                NurbsBase     curveTemp     = new NurbsCurve(degree, knots, controlPoints);
                NurbsBase     curveResult   = KnotRefine(curveTemp, knotsToInsert);
                knots         = curveResult.Knots;
                controlPoints = curveResult.ControlPoints;
            }

            int crvKnotLength       = reqMultiplicity * 2;
            List <NurbsBase> curves = new List <NurbsBase>();
            int i = 0;

            while (i < controlPoints.Count)
            {
                KnotVector knotsRange = (normalize)
                    ? knots.GetRange(i, crvKnotLength).ToKnot().Normalize()
                    : knots.GetRange(i, crvKnotLength).ToKnot();
                List <Point4> ptsRange = controlPoints.GetRange(i, reqMultiplicity);

                NurbsBase tempCrv = new NurbsCurve(degree, knotsRange, ptsRange);
                curves.Add(tempCrv);
                i += reqMultiplicity;
            }

            return(curves);
        }