示例#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);
        }
示例#2
0
        public void Multiplicities_Returns_A_Dictionary_Of_Knot_Values_And_Multiplicity()
        {
            // Arrange
            double[]   knotsValue         = { 0, 1, 2, 3, 3.3, 4 };
            int[]      multiplicityResult = { 4, 2, 3, 1, 1, 3 };
            int        count = 0;
            KnotVector knots = new KnotVector {
                0, 0, 0, 0, 1, 1, 2, 2, 2, 3, 3.3, 4, 4, 4
            };

            // Act
            Dictionary <double, int> multiplicities = knots.Multiplicities();

            // Assert
            multiplicities.Keys.Count.Should().Be(knotsValue.Length);

            foreach ((double key, int value) in multiplicities)
            {
                key.Should().Be(knotsValue[count]);
                value.Should().Be(multiplicityResult[count]);
                count += 1;
            }
        }