コード例 #1
0
        public void BinarySearch_PointOnKnotSpanBoundary_ReturnsCorrectSpanIndex()
        {
            double[]    knots         = { 0.0, 0.0, 0.0, 0.5, 1.0, 1.0, 1.0 };
            double[]    controlPoints = { 1.0, 1.0, 1.0, 1.0 };
            NurbsValues nurbsValues   = new NurbsValues(knots, 2, 1.0, controlPoints);
            int         result        = nurbsGenerator.BinarySearch(nurbsValues, 0.5);

            Assert.AreEqual(3, result, "The point lies in the fourth span, the returned index should be 3.");
        }
コード例 #2
0
        public void BinarySearch_PointInsideKnotSpan_ReturnsCorrectSpanIndex()
        {
            double[]    knots         = { 0.0, 0.0, 0.0, 0.5, 1.0, 1.0, 1.0 };
            double[]    controlPoints = { 1.0, 1.0, 1.0, 1.0 };
            NurbsValues nurbsValues   = new NurbsValues(knots, 1, 1.0, controlPoints);
            int         result        = nurbsGenerator.BinarySearch(nurbsValues, 0.1);

            Assert.AreEqual(2, result, "The point lies in the third span, the returned index should be 2.");
        }
コード例 #3
0
        public void BSplinesCoefficientsConstructor_ZeroLengthKnotSpan_ReturnsExpectedValues()
        {
            double[]    knots       = { 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 4.0, 4.0, 5.0, 5.0, 5.0 };
            int         degree      = 2;
            NurbsValues nurbsValues = new NurbsValues(knots, degree, 1.0, knots);

            bSplinesCoefficients = new BSplinesCoefficients(nurbsValues, 6);
            Assert.AreEqual(0.0, bSplinesCoefficients.Coefficients.ToEnumerable <double>().Sum(),
                            "Coefficients should be the same as the example on the Nurbs Book");
        }
コード例 #4
0
        public void EvaluateCurvePoint_KnownValues_ReturnsExpectedValues()
        {
            double[]    knots         = { 0.0, 0.0, 0.0, 1.45 / 3.0, 2.382 / 3.0, 1.0, 1.0, 1.0 };
            double[]    controlPoints = { 0.0, 6.0, 3.0, 6.0, 6.0 };
            double[]    basisFunction = { 0.430, 0.4980, 0.0720 };
            NurbsValues nurbsValues   = new NurbsValues(knots, 2, 3.0, controlPoints);

            double result = 3.204 - nurbsGenerator.EvaluateCurvePoint(2, basisFunction, nurbsValues);

            Assert.Less(result, 0.00001, "The returned value should be the same as the example at page 69 of the book 'An introduction to NURBS', within the rounding error.");
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: formozov/VTS
        /// <summary>
        /// Reads binary files generated in Matlab from the respective folder and writes JSON.
        /// </summary>
        /// <param name="readPath"></param>
        /// <param name="writePath"></param>
        /// <param name="domain"></param>
        /// <param name="folder"></param>
        private static void ReadBinaryAndWriteJson(string readPath, string writePath, string domain, string folder)
        {
            ushort[]    dims        = (ushort[])FileIO.ReadArrayFromBinaryInResources <ushort>(readPath + domain + folder + "dims", "Vts", 2);
            ushort[]    degrees     = (ushort[])FileIO.ReadArrayFromBinaryInResources <ushort>(readPath + domain + folder + "degrees", "Vts", 2);
            double[]    maxValues   = (double[])FileIO.ReadArrayFromBinaryInResources <double>(readPath + domain + folder + "maxValues", "Vts", 2);
            var         timeKnots   = (double[])FileIO.ReadArrayFromBinaryInResources <double>(readPath + domain + folder + "timeKnots", "Vts", dims[0]);
            var         spaceKnots  = (double[])FileIO.ReadArrayFromBinaryInResources <double>(readPath + domain + folder + "spaceKnots", "Vts", dims[1]);
            NurbsValues timeValues  = new NurbsValues(NurbsValuesDimensions.time, timeKnots, maxValues[0], degrees[0]);
            NurbsValues spaceValues = new NurbsValues(NurbsValuesDimensions.space, spaceKnots, maxValues[1], degrees[1]);

            timeValues.WriteToJson <NurbsValues>(writePath + readPath + domain + folder + "timeNurbsValues.txt");
            spaceValues.WriteToJson <NurbsValues>(writePath + readPath + domain + folder + "spaceNurbsValues.txt");
        }
コード例 #6
0
        public void EvaluateBasisFunctions_KnownValues_ReturnsExpectedValues()
        {
            double[]    knots       = { 0.0, 0.0, 0.0, 1.0 / 5.0, 2.0 / 5.0, 3.0 / 5.0, 4.0 / 5.0, 4.0 / 5.0, 1.0, 1.0, 1.0 };
            NurbsValues nurbsValues = new NurbsValues(knots, 2, 1.0, knots);

            double[] basisFunctions = nurbsGenerator.EvaluateBasisFunctions(4, 0.5, nurbsValues);
            double   result         = 0.0;

            for (int i = 0; i < basisFunctions.Length; i++)
            {
                result += basisFunctions[i];
            }

            Assert.Less(1.0 - result, 0.00001, "The sum of the basis functions should be equal to one, within the rounding error.");
        }
コード例 #7
0
        public void BSplinesCoefficientsConstructor_KnownValues_ReturnsExpectedValues()
        {
            double[] knots  = { 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 4.0, 4.0, 5.0, 5.0, 5.0 };
            int      degree = 2;

            double[,] knownValues =
            {
                {  1.0,  0.0, 0.0, 0.0 },
                { -2.0,  2.0, 0.0, 0.0 },
                {  1.0, -1.5, 0.5, 0.0 }
            };
            NurbsValues nurbsValues = new NurbsValues(knots, degree, 1.0, knots);

            bSplinesCoefficients = new BSplinesCoefficients(nurbsValues, 2);
            Assert.AreEqual(knownValues, bSplinesCoefficients.Coefficients,
                            "Coefficients should be the same as the example on the Nurbs Book");
        }
コード例 #8
0
 //[ExpectedException(typeof(ArgumentException), ExpectedMessage = "Negative parametric point not acceptable as input.")]
 public void FindSpan_ParametricPointSmallerThenZero_ThowsException()
 {
     //Assert.Throws<ArgumentException>(delegate { nurbsGenerator.FindSpan(nurbsValues, -1.0); }, "Negative parametric point not acceptable as input.");
     try
     {
         NurbsValues nurbsValues = new NurbsValues(1.0);
         nurbsGenerator.FindSpan(nurbsValues, -1.0);
     }
     catch (ArgumentException e)
     {
         Assert.AreEqual(e.Message, "Negative parametric point not acceptable as input.");
     }
     catch (Exception)
     {
         Assert.Fail();
     }
 }
コード例 #9
0
        public void EvaluateSurfacePoint_KnownValues_ReturnsExpectedValues()
        {
            NurbsValues nurbsValues = new NurbsValues(3);

            nurbsGenerator.TimeValues  = nurbsValues;
            nurbsGenerator.SpaceValues = nurbsValues;
            double[,] controlPoints    = { { 0.0,  0.0,   0.0,  0.0, 0.0 },
                                           { 0.0, 25.0,  50.0, 25.0, 0.0 },
                                           { 0.0, 25.0,  50.0, 25.0, 0.0 },
                                           { 0.0, 25.0, 150.0, 25.0, 0.0 },
                                           { 0.0,  0.0,   0.0,  0.0, 0.0 } };
            nurbsGenerator.ControlPoints = controlPoints;
            int timeSpanIndex  = 4;
            int spaceSpanIndex = 4;

            double[] timeBasisFunctions  = { 1.0 / 4.0, 0.5, 1.0 / 4.0, 0.0 };
            double[] spaceBasisFunctions = { 1.0 / 32.0, 0.25, 19.0 / 32.0, 1.0 / 8.0 };

            double result = 62.5 - nurbsGenerator.EvaluateSurfacePoint(timeSpanIndex, timeBasisFunctions, spaceSpanIndex, spaceBasisFunctions);

            Assert.Less(result, 0.00001, "The returned value should be the same as the example at page 216 of the book 'An introduction to NURBS', within the rounding error.");
        }