Пример #1
0
        public void ExportLink(bool zIsUp)
        {
            CreateBaseRefOrigin(zIsUp);
            MathTransform coordSysTransform =
                ActiveSWModel.Extension.GetCoordinateSystemTransformByName("Origin_global");
            Matrix <double> GlobalTransform = MathOps.GetTransformation(coordSysTransform);

            LocalizeLink(URDFRobot.BaseLink, GlobalTransform);

            //Creating package directories
            URDFPackage package = new URDFPackage(PackageName, SavePath);

            package.CreateDirectories();
            string meshFileName            = package.MeshesDirectory + URDFRobot.BaseLink.Name + ".STL";
            string windowsMeshFileName     = package.WindowsMeshesDirectory + URDFRobot.BaseLink.Name + ".STL";
            string windowsURDFFileName     = package.WindowsRobotsDirectory + URDFRobot.Name + ".urdf";
            string windowsManifestFileName = package.WindowsPackageDirectory + "manifest.xml";

            //Creating manifest file
            PackageXMLWriter manifestWriter = new PackageXMLWriter(windowsManifestFileName);
            PackageXML       Manifest       = new PackageXML(URDFRobot.Name);

            Manifest.WriteElement(manifestWriter);

            //Customizing STL preferences to how I want them
            SaveUserPreferences();
            SetSTLExportPreferences();
            SetLinkSpecificSTLPreferences("", URDFRobot.BaseLink.STLQualityFine, ActiveSWModel);
            int errors   = 0;
            int warnings = 0;

            //Saving part as STL mesh

            ActiveSWModel.Extension.SaveAs(windowsMeshFileName, (int)swSaveAsVersion_e.swSaveAsCurrentVersion,
                                           (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref errors, ref warnings);
            URDFRobot.BaseLink.Visual.Geometry.Mesh.Filename    = meshFileName;
            URDFRobot.BaseLink.Collision.Geometry.Mesh.Filename = meshFileName;

            URDFRobot.BaseLink.Visual.Material.Texture.Filename =
                package.TexturesDirectory + Path.GetFileName(URDFRobot.BaseLink.Visual.Material.Texture.wFilename);
            string textureSavePath =
                package.WindowsTexturesDirectory + Path.GetFileName(URDFRobot.BaseLink.Visual.Material.Texture.wFilename);

            if (!String.IsNullOrWhiteSpace(URDFRobot.BaseLink.Visual.Material.Texture.wFilename))
            {
                File.Copy(URDFRobot.BaseLink.Visual.Material.Texture.wFilename, textureSavePath, true);
            }

            //Writing URDF to file
            URDFWriter uWriter = new URDFWriter(windowsURDFFileName);

            //mRobot.addLink(mLink);
            URDFRobot.WriteURDF(uWriter.writer);

            ResetUserPreferences();
        }
Пример #2
0
        public void Vector2NegateTest()
        {
            Vector2 a = new Vector2(1.0f, 2.0f);

            Vector2 expected = new Vector2(-1.0f, -2.0f);
            Vector2 actual;

            actual = MathOps.Negate(a);
            Assert.AreEqual(expected, actual);
        }
Пример #3
0
        public void Vector2TransformByQuaternionTest1()
        {
            Vector2    v        = new Vector2(1.0f, 2.0f);
            Quaternion q        = new Quaternion();
            Vector2    expected = v;

            Vector2 actual = MathOps.Transform(v, q);

            Assert.True(MathHelper.Equal(expected, actual), "Vector2f.Transform did not return the expected value.");
        }
Пример #4
0
        static void Main(string[] args)
        {
            MathOps multiply = ClassA.Multiply;
            MathOps add      = ClassB.Add;
            int     resultA  = multiply(30, 30);
            int     resultB  = add(1000, 500);

            Console.WriteLine("Results: " + resultA + " " + resultB);
            Console.ReadKey();
        }
Пример #5
0
        /// <summary>
        /// Solves the problem of stress-strain state
        /// </summary>
        /// <param name="type">Type of fixation</param>
        /// <param name="conditions">Boundary conditions</param>
        /// <returns>Result vector</returns>
        public void Solve(TypeOfFixation type, IBoundaryCondition conditions, ILoad load)
        {
            results = new double[solver.GlobalMatrix.Length];

            SetLoads(load);
            SetBoundaryConditions(type, conditions);

            results = MathOps.MethodOfGauss(DIRECTORY_PATH, globalMatrix, loads);
            //results = MathOps.CGMethod(DIRECTORY_PATH, globalMatrix, loads, EPSILON);
        }
Пример #6
0
        public void Vector2DotTest1()
        {
            Vector2 a = new Vector2(1.55f, 1.55f);
            Vector2 b = new Vector2(-1.55f, 1.55f);

            float expected = 0.0f;
            float actual   = MathOps.Dot(a, b);

            Assert.AreEqual(expected, actual);
        }
Пример #7
0
        public void Vector3SqrtTest()
        {
            Vector3 a = new Vector3(-2.5f, 2.0f, 0.5f);
            Vector3 b = new Vector3(5.5f, 4.5f, 16.5f);

            Assert.AreEqual(2, (int)MathOps.SquareRoot(b).X);
            Assert.AreEqual(2, (int)MathOps.SquareRoot(b).Y);
            Assert.AreEqual(4, (int)MathOps.SquareRoot(b).Z);
            Assert.AreEqual(float.NaN, MathOps.SquareRoot(a).X);
        }
        /// <summary>
        /// Solves the problem of stress-strain state
        /// </summary>
        /// <param name="type">Type of fixation</param>
        /// <param name="conditions">Boundary conditions</param>
        /// <returns>Result vector</returns>
        public void Solve(TypeOfFixation type, IBoundaryCondition conditions, ILoad load)
        {
            globalMatrix = solver.GlobalMatrix;
            results      = new double[globalMatrix.Count];

            SetLoads(load);
            SetBoundaryConditions(type, conditions);

            results = MathOps.MethodOfGauss(ref globalMatrix, loads);
        }
Пример #9
0
        public void Vector3NegateTest()
        {
            Vector3 a = new Vector3(1.0f, 2.0f, 3.0f);

            Vector3 expected = new Vector3(-1.0f, -2.0f, -3.0f);
            Vector3 actual;

            actual = MathOps.Negate(a);
            Assert.AreEqual(expected, actual);
        }
 public void TestClosestPointOnLineWithinBox(
     double xMin, double xMax, double yMin, double yMax, double zMin, double zMax,
     double[] line, double[] pointOnLine, double[] expected)
 {
     double[] result = MathOps.ClosestPointOnLineWithinBox(xMin, xMax, yMin, yMax, zMin, zMax, line, pointOnLine);
     for (int i = 0; i < expected.Length; i++)
     {
         Assert.Equal(expected[i], result[i], 10);
     }
 }
Пример #11
0
        public void Vector3TransformByQuaternionTest2()
        {
            Vector3    v        = new Vector3(1.0f, 2.0f, 3.0f);
            Quaternion q        = Quaternion.Identity;
            Vector3    expected = v;

            Vector3 actual = MathOps.Transform(v, q);

            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Transform did not return the expected value.");
        }
Пример #12
0
        public void Vector3CrossTest1()
        {
            Vector3 a = new Vector3(0.0f, 1.0f, 0.0f);
            Vector3 b = new Vector3(0.0f, 1.0f, 0.0f);

            Vector3 expected = new Vector3(0.0f, 0.0f, 0.0f);
            Vector3 actual   = MathOps.Cross(a, b);

            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Cross did not return the expected value.");
        }
        public void TestGetRPYDenseMatrix(double[] matrixData, double[] expected)
        {
            Matrix <double> m = new DenseMatrix(4, 4, matrixData);

            double[] result = MathOps.GetRPY(m);
            for (int i = 0; i < expected.Length; i++)
            {
                Assert.Equal(expected[i], result[i], 10);
            }
        }
Пример #14
0
        /// <summary>
        /// Solves the problem of stress-strain state
        /// </summary>
        /// <param name="type">Type of fixation</param>
        /// <param name="conditions">Boundary conditions</param>
        /// <returns>Result vector</returns>
        public void Solve(TypeOfFixation type, IBoundaryCondition conditions, ILoad load)
        {
            globalMatrix = solver.GlobalMatrix;
            results      = new double[globalMatrix.GetLength(1)];

            SetLoads(load);
            SetBoundaryConditions(type, conditions);

            results = MathOps.GausSlau(globalMatrix, loads);
        }
        public void MatriXMatrixTest()
        {
            var value = MathOps.MultiplyMatrixByMatrix(new double[, ] {
                { 2, 1 }
            }, new double[, ] {
                { 2 }, { 1 }
            });

            Assert.Equal(5, value);
        }
Пример #16
0
        public void Vector3ClampTest()
        {
            Vector3 a   = new Vector3(0.5f, 0.3f, 0.33f);
            Vector3 min = new Vector3(0.0f, 0.1f, 0.13f);
            Vector3 max = new Vector3(1.0f, 1.1f, 1.13f);

            // Normal case.
            // Case N1: specified value is in the range.
            Vector3 expected = new Vector3(0.5f, 0.3f, 0.33f);
            Vector3 actual   = MathOps.Clamp(a, min, max);

            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Clamp did not return the expected value.");

            // Normal case.
            // Case N2: specified value is bigger than max value.
            a        = new Vector3(2.0f, 3.0f, 4.0f);
            expected = max;
            actual   = MathOps.Clamp(a, min, max);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Clamp did not return the expected value.");

            // Case N3: specified value is smaller than max value.
            a        = new Vector3(-2.0f, -3.0f, -4.0f);
            expected = min;
            actual   = MathOps.Clamp(a, min, max);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Clamp did not return the expected value.");

            // Case N4: combination case.
            a        = new Vector3(-2.0f, 0.5f, 4.0f);
            expected = new Vector3(min.X, a.Y, max.Z);
            actual   = MathOps.Clamp(a, min, max);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Clamp did not return the expected value.");

            // User specified min value is bigger than max value.
            max = new Vector3(0.0f, 0.1f, 0.13f);
            min = new Vector3(1.0f, 1.1f, 1.13f);

            // Case W1: specified value is in the range.
            a        = new Vector3(0.5f, 0.3f, 0.33f);
            expected = min;
            actual   = MathOps.Clamp(a, min, max);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Clamp did not return the expected value.");

            // Normal case.
            // Case W2: specified value is bigger than max and min value.
            a        = new Vector3(2.0f, 3.0f, 4.0f);
            expected = min;
            actual   = MathOps.Clamp(a, min, max);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Clamp did not return the expected value.");

            // Case W3: specified value is smaller than min and max value.
            a        = new Vector3(-2.0f, -3.0f, -4.0f);
            expected = min;
            actual   = MathOps.Clamp(a, min, max);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Clamp did not return the expected value.");
        }
Пример #17
0
        public void Vector3DivideTest1()
        {
            Vector3 a = new Vector3(1.0f, 6.0f, 7.0f);
            Vector3 b = new Vector3(5.0f, 2.0f, 3.0f);

            Vector3 expected = new Vector3(1.0f / 5.0f, 6.0f / 2.0f, 7.0f / 3.0f);
            Vector3 actual;

            actual = MathOps.Divide(a, b);
            Assert.AreEqual(expected, actual);
        }
Пример #18
0
        public void Vector3AddTest()
        {
            Vector3 a = new Vector3(1.0f, 2.0f, 3.0f);
            Vector3 b = new Vector3(5.0f, 6.0f, 7.0f);

            Vector3 expected = new Vector3(6.0f, 8.0f, 10.0f);
            Vector3 actual;

            actual = MathOps.Add(a, b);
            Assert.AreEqual(expected, actual);
        }
Пример #19
0
        public void Vector3DistanceTest()
        {
            Vector3 a = new Vector3(1.0f, 2.0f, 3.0f);
            Vector3 b = new Vector3(4.0f, 5.0f, 6.0f);

            float expected = (float)System.Math.Sqrt(27);
            float actual;

            actual = MathOps.Distance(a, b);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Distance did not return the expected value.");
        }
        public void TransposeMatrixTest()
        {
            double[,] m = new double[, ] {
                { -12 }, { 6 }
            };

            var value = MathOps.TransposeMatrix(m);

            Assert.Equal(-12, value[0, 0]);
            Assert.Equal(6, value[0, 1]);
        }
Пример #21
0
        public void Vector3SubtractTest()
        {
            Vector3 a = new Vector3(1.0f, 6.0f, 3.0f);
            Vector3 b = new Vector3(5.0f, 2.0f, 3.0f);

            Vector3 expected = new Vector3(-4.0f, 4.0f, 0.0f);
            Vector3 actual;

            actual = MathOps.Subtract(a, b);
            Assert.AreEqual(expected, actual);
        }
Пример #22
0
        public void Vector3MaxTest()
        {
            Vector3 a = new Vector3(-1.0f, 4.0f, -3.0f);
            Vector3 b = new Vector3(2.0f, 1.0f, -1.0f);

            Vector3 expected = new Vector3(2.0f, 4.0f, -1.0f);
            Vector3 actual;

            actual = MathOps.Max(a, b);
            Assert.True(MathHelper.Equal(expected, actual), "MathOps.Max did not return the expected value.");
        }
Пример #23
0
        public void Vector3DotTest()
        {
            Vector3 a = new Vector3(1.0f, 2.0f, 3.0f);
            Vector3 b = new Vector3(4.0f, 5.0f, 6.0f);

            float expected = 32.0f;
            float actual;

            actual = MathOps.Dot(a, b);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Dot did not return the expected value.");
        }
        public void MatriXScalarTest()
        {
            double[,] m = new double[, ] {
                { -12 }, { 6 }
            };

            var value = MathOps.MultiplyMatrixByScalar(m, -1);

            Assert.Equal(12, value[0, 0]);
            Assert.Equal(-6, value[1, 0]);
        }
Пример #25
0
        public void Vector3MultiplyTest3()
        {
            Vector3 a = new Vector3(1.0f, 2.0f, 3.0f);
            Vector3 b = new Vector3(5.0f, 6.0f, 7.0f);

            Vector3 expected = new Vector3(5.0f, 12.0f, 21.0f);
            Vector3 actual;

            actual = MathOps.Multiply(a, b);
            Assert.AreEqual(expected, actual);
        }
        public void MatriXNegatOneTest()
        {
            double[,] m = new double[, ] {
                { -12 }, { 6 }
            };

            var value = MathOps.MatriXNegativeOne(m);

            Assert.Equal(12, value[0, 0]);
            Assert.Equal(-6, value[1, 0]);
        }
Пример #27
0
        public void Vector3LerpTest4()
        {
            Vector3 a = new Vector3(0.0f, 0.0f, 0.0f);
            Vector3 b = new Vector3(4.0f, 5.0f, 6.0f);

            float   t        = -2.0f;
            Vector3 expected = new Vector3(-8.0f, -10.0f, -12.0f);
            Vector3 actual   = MathOps.Lerp(a, b, t);

            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Lerp did not return the expected value.");
        }
        public void AddMatricesTest()
        {
            double[,] m = MathOps.AddMatrices(new double[, ] {
                { 0 }, { -0.6957 }
            }, new double[, ] {
                { 0.242 }, { 0 }
            });

            Assert.Equal(0.242, m[0, 0]);
            Assert.Equal(-0.6957, m[1, 0]);
        }
Пример #29
0
        public void Vector3LerpTest5()
        {
            Vector3 a = new Vector3(1.68f, 2.34f, 5.43f);
            Vector3 b = a;

            float   t        = 0.18f;
            Vector3 expected = new Vector3(1.68f, 2.34f, 5.43f);
            Vector3 actual   = MathOps.Lerp(a, b, t);

            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Lerp did not return the expected value.");
        }
Пример #30
0
        ///////////////////////////////////////////////////////////////////////

        public override int GetMaxByteCount(
            int charCount
            )
        {
            if (!MathOps.CanDouble(charCount))
            {
                throw new ArgumentOutOfRangeException("charCount");
            }

            return(charCount * 2); /* one-to-two mapping */
        }
        private static void calculate(MathOps mathOpIdx, IImage src1, IImage src2, IImage dest, Image<Gray, byte> mask = null)
        {
            Debug.Assert(src1.ColorInfo.Equals(src2.ColorInfo) && src1.Size.Equals(src2.Size));

            if (mask == null)
            {
                mask = new Image<Gray, byte>(dest.Width, dest.Height);
                mask.SetValue(new Gray(255));
            }

            var mathOperationOnTypes = mathOperatorFuncs[(int)mathOpIdx];

            MathOpFunc mathOpFunc = null;
            if (mathOperationOnTypes.TryGetValue(src1.ColorInfo.ChannelType, out mathOpFunc) == false)
                throw new Exception(string.Format("Math operation {0} can not be executed on an image of type {1}", mathOpIdx.ToString(), src1.ColorInfo.ChannelType));

            var proc = new ParallelProcessor<bool, bool>(dest.Size,
                                                            () =>
                                                            {
                                                                return true;
                                                            },
                                                            (bool _, bool __, Rectangle area) =>
                                                            {
                                                                var src1Patch = src1.GetSubRect(area);
                                                                var src2Patch = src2.GetSubRect(area);
                                                                var destPatch = dest.GetSubRect(area);
                                                                var maskPatch = mask.GetSubRect(area);

                                                                mathOpFunc(src1Patch, src2Patch, destPatch, maskPatch);
                                                            }
                                                            /*,new ParallelOptions { ForceSequential = true}*/);

            proc.Process(true);
        }