예제 #1
0
 public void SetDedicatedData()
 {
     for (int i = 0; i < BoolModel.IntModelElements; i++)
     {
         MatrixTransposed.Add(MatrixTransformation.Transpose <int, int>(Matrix[i]));
     }
 }
예제 #2
0
 public void SetDedicatedData()
 {
     for (int i = 0; i < model.le; i++)
     {
         TransposedMatrix.Add(MatrixTransformation.Transpose <int, int>(Matrix[i]));
     }
 }
예제 #3
0
 /// <summary>
 /// Calculate and return reaction matrix.
 /// </summary>
 /// <returns></returns>
 private double[,] CalculateMatrixReactions()
 {
     double[,] doubleMatrix;
     doubleMatrix = MatrixTransformation.Multiply(DoubleMatrixStiffnessGlobal, DoubleMatrixDisplacements);
     doubleMatrix = MatrixTransformation.Substract(doubleMatrix, SolverModel.Load.Matrix);
     return(doubleMatrix);
 }
예제 #4
0
        public void SetDedicatedData()
        {
            Id = new int[IdentityModel.IntDOFPerNode * IdentityModel.IntModelNodes, IdentityModel.IntDOFPerNode *IdentityModel.IntModelNodes];
            MatrixTransformation.SetOnMatrixDiagonal(Id, IdentityModel.Support.IntMatrixSupportDOFs);

            Ip = new int[IdentityModel.IntDOFPerNode * IdentityModel.IntModelNodes, IdentityModel.IntDOFPerNode *IdentityModel.IntModelNodes];
            Ip = MatrixTransformation.SubstractOnMatrixDiagonal(Matrix, Id);
        }
예제 #5
0
        public void SetDedicatedData()
        {
            Id = new int[model.LQ * model.ln, model.LQ *model.ln];
            MatrixTransformation.SetOnMatrixDiagonal(Id, model.Support.Matrix);

            Ip = new int[model.LQ * model.ln, model.LQ *model.ln];
            Ip = MatrixTransformation.SubstractOnMatrixDiagonal(Matrix, Id);
        }
예제 #6
0
        private double[,] CalculateReactions()
        {
            double[,] currentMatrix = new double[model.LQ * model.ln, 1];

            currentMatrix = MatrixTransformation.Multiply <double, double>(K, U);
            currentMatrix = MatrixTransformation.Substract(currentMatrix, model.Load.Matrix);

            return(currentMatrix);
        }
예제 #7
0
        private void SetSubstitutiveMatrix()
        {
            equation = new double[model.LQ * model.ln, model.LQ *model.ln + 1];
            equation = MatrixTransformation.Sum(equation, KK);

            for (int i = 0; i < equation.GetLength(0); i++)
            {
                equation[i, equation.GetLength(0)] = F[i, 0];
            }
        }
예제 #8
0
        private void SetSubstitutiveMatrix()
        {
            equation = new double[SolverModel.IntDOFPerNode * SolverModel.IntModelNodes, SolverModel.IntDOFPerNode *SolverModel.IntModelNodes + 1];
            equation = MatrixTransformation.Sum(equation, DoubleMatrixBoundaryGlobal);

            for (int i = 0; i < equation.GetLength(0); i++)
            {
                equation[i, equation.GetLength(0)] = DoubleMatrixLoads[i, 0];
            }
        }
예제 #9
0
        /*** Private methods ***************************************************************************************************/

        private static double GetAlongTheMemberResult(IScheme scheme, IModel model, Dictionary <int, double[, ]> elementBoundaryDisplacements, double x, int startNodeNumber, int elementNumber)
        {
            IBeamProperty beamProperty = model.Beam.Properties.Where(beam => beam.Number == elementNumber).FirstOrDefault();
            double        L            = beamProperty.Lb;
            double        s            = ResultHelper.GetScalingParameter(scheme, x, startNodeNumber, L);

            double[,] currentShapeFunctionsVector = GetShapeFunctionsVector(s, L);
            double[,] result = MatrixTransformation.Multiply(currentShapeFunctionsVector, elementBoundaryDisplacements[elementNumber]);
            return(result[0, 0]);
        }
        /// <summary>
        /// Выполнение.
        /// </summary>
        private void Implementation()
        {
            //Прямой ход метода Гаусса для приведения к треугольному виду.
            MatrixTransformation.Gauss(elements, CornerDot, variable_visualization);

            //Выражение базисных переменных.
            MatrixTransformation.HoistingMatrix(elements, number_of_basix);

            //создаём сиплекс-таблицу
            simplextable = new SimplexTable(number_of_basix, number_of_free_variables, variable_visualization, elements, target_function_elements, true);
            MainGrid.Children.Add(simplextable);

            int responce;
            int step = 1;

            while (true)
            {
                if ((responce = simplextable.ResponseCheck()) == 0)
                {
                    //выбор любого опорного
                    simplextable.SelectionRandomSupportElement();
                    //смена визуализации переменных в симплек-таблице
                    simplextable.ChangeOfVisualWithoutBuffer();
                    //вычисление согласно выбранному опорному элементу
                    simplextable.CalculateSimplexTable();
                    //обновление данных сиплекс-таблицы
                    simplextable.UpdateSimplexTableValues();
                    //номер угловой точки
                    simplextable.CornerPoint(step);
                    step++;
                }
                else if (responce == 1)
                {
                    if (MinMax == 0)
                    {
                        labelanswer.Content = "Ответ :" + simplextable.Response() * (-1);
                    }
                    else
                    {
                        labelanswer.Content = "Ответ :" + simplextable.Response();
                    }
                    //добавляем точку
                    corner_dot = simplextable.ResponseCornerDot(step - 1);
                    MainGrid.Children.Add(corner_dot);
                    buttonToMainWindow.Visibility = Visibility.Visible;
                    break;
                }
                else if (responce == -1)
                {
                    labelanswer.Content           = "Задача не разрешима!";
                    buttonToMainWindow.Visibility = Visibility.Visible;
                    break;
                }
            }
        }
예제 #11
0
        private void ApplyBCs()
        {
            DoubleMatrixBoundaryGlobal = new double[SolverModel.IntDOFPerNode * SolverModel.IntModelNodes, SolverModel.IntDOFPerNode *SolverModel.IntModelNodes];

            DoubleMatrixBoundaryGlobal = MatrixTransformation.Multiply(SolverModel.Identity.Ip, DoubleMatrixStiffnessGlobal);
            DoubleMatrixBoundaryGlobal = MatrixTransformation.Multiply(DoubleMatrixBoundaryGlobal, SolverModel.Identity.Ip);
            DoubleMatrixBoundaryGlobal = MatrixTransformation.Sum(DoubleMatrixBoundaryGlobal, MatrixTransformation.ToDouble(SolverModel.Identity.Id));

            DoubleMatrixLoads = new double[SolverModel.IntDOFPerNode * SolverModel.IntModelNodes, 1];
            DoubleMatrixLoads = MatrixTransformation.Multiply(SolverModel.Identity.Ip, SolverModel.Load.Matrix);
        }
예제 #12
0
        private void ApplyBCs()
        {
            KK = new double[model.LQ * model.ln, model.LQ *model.ln];

            KK = MatrixTransformation.Multiply <int, double>(model.Identity.Ip, K);
            KK = MatrixTransformation.Multiply <double, int>(KK, model.Identity.Ip);
            KK = MatrixTransformation.Sum(KK, MatrixTransformation.ToDouble <int>(model.Identity.Id));

            F = new double[model.LQ * model.ln, 1];
            F = MatrixTransformation.Multiply <int, double>(model.Identity.Ip, model.Load.Matrix);
        }
예제 #13
0
        private void AggregateGlobalStiffnessMatrix()
        {
            K = new double[model.LQ * model.ln, model.LQ *model.ln];

            for (int i = 0; i < model.le; i++)
            {
                double[,] k = new double[4, 4];
                k           = MatrixTransformation.Multiply <int, double>(model.Boolean.TransposedMatrix[i], model.Beam.Matrix[i]);
                k           = MatrixTransformation.Multiply <double, int>(k, model.Boolean.Matrix[i]);

                K = MatrixTransformation.Sum(K, k);
            }
        }
예제 #14
0
        private static double GetAlongTheMemberResult(IModel model, Dictionary <int, double[, ]> elementBoundaryDisplacements, int elementNumber)
        {
            IBeamProperty beamProperty = model.Beam.Properties.Where(beam => beam.Number == elementNumber).FirstOrDefault();
            double        L            = beamProperty.Lb;

            double[,] currentShapeFunctionsVector = GetShapeFunctionsVector(L);
            double[,] result;
            result = MatrixTransformation.Multiply(currentShapeFunctionsVector, elementBoundaryDisplacements[elementNumber]);
            double resultFactor = beamProperty.Ey * beamProperty.Iy / Math.Pow(beamProperty.Lb, 3);

            result = MatrixTransformation.Multiply(result, resultFactor);
            return(result[0, 0]);
        }
예제 #15
0
        private void AggregateGlobalStiffnessMatrix()
        {
            DoubleMatrixStiffnessGlobal = new double[SolverModel.IntDOFPerNode * SolverModel.IntModelNodes, SolverModel.IntDOFPerNode *SolverModel.IntModelNodes];
            double[,] k;

            // Debug.WriteLine($"Solver.cs AggregateGlobalStiffnessMatrix(): Total number of elements in model = SolverModel.IntModelElements={SolverModel.IntModelElements}");
            for (int i = 0; i < SolverModel.IntModelElements; i++)
            {
                k = MatrixTransformation.Multiply(SolverModel.Boolean.MatrixTransposed[i], SolverModel.Beam.Matrix[i]);
                k = MatrixTransformation.Multiply(k, SolverModel.Boolean.Matrix[i]);
                DoubleMatrixStiffnessGlobal = MatrixTransformation.Sum(DoubleMatrixStiffnessGlobal, k);
            }
        }
예제 #16
0
        private Dictionary <int, double[, ]> CalculateElementBoundaryForces()
        {
            Dictionary <int, double[, ]> elementForces = new Dictionary <int, double[, ]>();

            for (int i = 0; i < model.le; i++)
            {
                double[,] nodalForces = new double[4, 1];
                nodalForces           = MatrixTransformation.Multiply(model.Beam.Matrix[i], model.Boolean.Matrix[i]);
                nodalForces           = MatrixTransformation.Multiply(nodalForces, solver.U);

                elementForces.Add(i + 1, nodalForces);
            }

            return(elementForces);
        }
예제 #17
0
        /// <summary>
        /// 七参数转换
        /// </summary>
        /// <param name="inputX"></param>
        /// <param name="inputY"></param>
        /// <param name="inputZ"></param>
        /// <param name="outputX"></param>
        /// <param name="outputY"></param>
        /// <param name="outputZ"></param>
        private void sevenParamTransform(double inputX, double inputY, double inputZ,
                                         out double outputX, out double outputY, out double outputZ)
        {
            double[,] rotationMatrix = MatrixTransformation.RotationMatrix(rx, ry, rz);
            double[,] originalCoord  = new double[3, 1];
            originalCoord[0, 0]      = inputX;
            originalCoord[1, 0]      = inputY;
            originalCoord[2, 0]      = inputZ;

            double[,] resCoord = MatrixTransformation.MatrixProduct(rotationMatrix, originalCoord);

            outputX = resCoord[0, 0] * (m + 1) + dx;
            outputY = resCoord[1, 0] * (m + 1) + dy;
            outputZ = resCoord[2, 0] * (m + 1) + dz;
        }
예제 #18
0
        private Dictionary <int, double[, ]> CalculateElementBoundaryDisplacements()
        {
            Dictionary <int, double[, ]> elementDisplacements = new Dictionary <int, double[, ]>();

            for (int i = 0; i < model.le; i++)
            {
                double[,] currentElementDisplacements = new double[4, 1];

                currentElementDisplacements = MatrixTransformation.Multiply(model.Boolean.Matrix[i], solver.U);

                elementDisplacements.Add(i + 1, currentElementDisplacements);
            }

            return(elementDisplacements);
        }
예제 #19
0
        protected bool VerifyDimentionalityForMatrixAddition(Matrix a, MatrixTransformation transA, Matrix b, MatrixTransformation transB, Matrix c)
        {
            int m1 = transA == MatrixTransformation.None ? a.Row : a.Column;
            int n1 = transA == MatrixTransformation.None ? a.Column : a.Row;
            int m2 = transB == MatrixTransformation.None ? b.Row : b.Column;
            int n2 = transB == MatrixTransformation.None ? b.Column : b.Row;

            if (m1 != m2 || m2 != c.Row)
            {
                throw new ArgumentException("row of transA(a) != row of transB(b) != row of c");
            }
            if (n1 != n2 || n2 != c.Column)
            {
                throw new ArgumentException("column of transA(a) != column of transB(b) != column of c");
            }
            return(true);
        }
예제 #20
0
        public override void MatrixMultiplication(Matrix a, MatrixTransformation transA, float alpha, Matrix b, MatrixTransformation transB, Matrix c, float beta, bool copyInputsFromCpuToGpu = false, bool copyOutputsFromGpuToCpu = false)
        {
            VerifyDimentionalityForMatrixMultiplication(a, transA, b, transB, c);
            if (copyInputsFromCpuToGpu)
            {
                a.CopyToCuda();
                b.CopyToCuda();
            }

            cuBlas.Gemm(GetOperation(transA), GetOperation(transB), c.Row, c.Column, transA == MatrixTransformation.None ? a.Column : a.Row,
                        alpha, a.DeviceData, a.Row, b.DeviceData, b.Row, beta, c.DeviceData, c.Row);

            if (copyOutputsFromGpuToCpu)
            {
                c.CopyFromCuda();
            }
        }
예제 #21
0
        protected Operation GetOperation(MatrixTransformation trans)
        {
            Operation retVal = Operation.NonTranspose;

            switch (trans)
            {
            case MatrixTransformation.None:
                retVal = Operation.NonTranspose;
                break;

            case MatrixTransformation.Transpose:
                retVal = Operation.Transpose;
                break;
                //case MatrixTransformation.ConjugateTranspose:
                //    retVal = Operation.ConjugateTranspose;
                //    break;
            }
            return(retVal);
        }
예제 #22
0
        protected bool VerifyDimentionalityForMatrixMultiplication(Matrix a, MatrixTransformation transA, Matrix b, MatrixTransformation transB, Matrix c)
        {
            int m  = transA == MatrixTransformation.None ? a.Row : a.Column;
            int k1 = transA == MatrixTransformation.None ? a.Column : a.Row;
            int k2 = transB == MatrixTransformation.None ? b.Row : b.Column;
            int n  = transB == MatrixTransformation.None ? b.Column : b.Row;

            if (k1 != k2)
            {
                throw new ArgumentException("column of trnasA(a) != row of transB(b)");
            }
            if (m != c.Row)
            {
                throw new ArgumentException("row of trnasA(a) != row of c)");
            }
            if (n != c.Column)
            {
                throw new ArgumentException("column of trnasB(b) != column of c)");
            }
            return(true);
        }
 /// <summary>
 /// Performs c = alpha*transA(a) + beta*transB(b)
 /// </summary>
 /// <param name="a"></param>
 /// <param name="transA"></param>
 /// <param name="alpha"></param>
 /// <param name="b"></param>
 /// <param name="transB"></param>
 /// <param name="beta"></param>
 /// <param name="c"></param>
 /// <param name="skipCopyFromCuda"></param>
 public abstract void MatrixAddition(Matrix a, MatrixTransformation transA, float alpha, Matrix b, MatrixTransformation transB, float beta, Matrix c, bool copyInputsFromCpuToGpu = false, bool copyOutputsFromGpuToCpu = false);
        public override void MatrixMultiplication(Matrix a, MatrixTransformation transA, float alpha, Matrix b, MatrixTransformation transB, Matrix c, float beta, bool copyInputsFromCpuToGpu = false, bool copyOutputsFromGpuToCpu = false)
        {
            VerifyDimentionalityForMatrixMultiplication(a, transA, b, transB, c);
            if (copyInputsFromCpuToGpu)
            {
                a.CopyToCuda();
                b.CopyToCuda();
            }

            cuBlas.Gemm(GetOperation(transA), GetOperation(transB), c.Row, c.Column, transA == MatrixTransformation.None ? a.Column : a.Row,
                alpha, a.DeviceData, a.Row, b.DeviceData, b.Row, beta, c.DeviceData, c.Row);

            if (copyOutputsFromGpuToCpu)
            {
                c.CopyFromCuda();
            }
        }
 public override void MatrixMultiplication(Matrix a, MatrixTransformation transA, float alpha, Matrix b, MatrixTransformation transB, Matrix c, float beta, bool copyInputsFromCpuToGpu = false, bool copyOutputsFromGpuToCpu = false)
 {
     throw new NotImplementedException();
 }
        protected bool VerifyDimentionalityForMatrixMultiplication(Matrix a, MatrixTransformation transA, Matrix b, MatrixTransformation transB, Matrix c)
        {
            int m = transA == MatrixTransformation.None ? a.Row : a.Column;
            int k1 = transA == MatrixTransformation.None ? a.Column : a.Row;
            int k2 = transB == MatrixTransformation.None ? b.Row : b.Column;
            int n = transB == MatrixTransformation.None ? b.Column : b.Row;

            if (k1 != k2)
            {
                throw new ArgumentException("column of trnasA(a) != row of transB(b)");
            }
            if (m != c.Row)
            {
                throw new ArgumentException("row of trnasA(a) != row of c)");
            }
            if (n != c.Column)
            {
                throw new ArgumentException("column of trnasB(b) != column of c)");
            }
            return true;
        }
        protected bool VerifyDimentionalityForMatrixAddition(Matrix a, MatrixTransformation transA, Matrix b, MatrixTransformation transB, Matrix c)
        {
            int m1 = transA == MatrixTransformation.None ? a.Row : a.Column;
            int n1 = transA == MatrixTransformation.None ? a.Column : a.Row;
            int m2 = transB == MatrixTransformation.None ? b.Row : b.Column;
            int n2 = transB == MatrixTransformation.None ? b.Column : b.Row;

            if (m1 != m2 || m2 != c.Row)
            {
                throw new ArgumentException("row of transA(a) != row of transB(b) != row of c");
            }
            if (n1 != n2 || n2 != c.Column)
            {
                throw new ArgumentException("column of transA(a) != column of transB(b) != column of c");
            }
            return true;
        }
예제 #28
0
 public override void MatrixMultiplication(Matrix a, MatrixTransformation transA, float alpha, Matrix b, MatrixTransformation transB, Matrix c, float beta, bool copyInputsFromCpuToGpu = false, bool copyOutputsFromGpuToCpu = false)
 {
     throw new NotImplementedException();
 }
예제 #29
0
        /// <summary>
        /// Кнопка "вперёд".
        /// </summary>
        private void buttonNext_Click(object sender, RoutedEventArgs e)
        {
            switch (step)
            {
            case 0:
                //буферизация данных
                BufferingTableValues();
                try
                {
                    buffer_variable_visualization = new int[variable_visualization.Length];
                    for (int i = 0; i < variable_visualization.Length; i++)
                    {
                        buffer_variable_visualization[i] = variable_visualization[i];
                    }
                    //прямой ход Гаусса
                    MatrixTransformation.Gauss(elements, CornerDot, variable_visualization);
                }
                catch (Exception d)
                {
                    MessageBox.Show(d.Message);
                    buttonToMainWindow.Visibility = Visibility.Visible;
                }
                //Обновление визуализации переменных.
                UpdateVisualVariables();
                //обновление таблицы
                UpdateTableValues();
                step++;
                labelsteps.Content = "Шаг 1: Прямой ход метода Гаусса.";
                break;

            case 1:
                //буферизация данных
                BufferingTableValues();
                //Выражение базисных переменных.
                MatrixTransformation.HoistingMatrix(elements, number_of_permutations);
                //обновление таблицы
                UpdateTableValues();
                step++;
                labelsteps.Content = "Шаг 2: Выражение базисных переменных.";
                break;

            case 2:
                //скрываем матрицу
                scrollgaussgrid.Visibility = Visibility.Hidden;
                if (simplex_table_was_draw == false)
                {
                    simplextable = new SimplexTable(number_of_permutations, number_of_free_variables, variable_visualization, elements, target_function_elements, true);
                    MainGrid.Children.Add(simplextable);
                    //Симплекс-таблица была создана
                    simplex_table_was_draw = true;
                }
                //показываем симплекс-таблицу
                simplextable.Visibility = Visibility.Visible;
                switch (simplextable.ResponseCheck())
                {
                case 0:
                    step++;
                    labelsteps.Content = "Шаг 3: Симплекс-таблица.";
                    break;

                case 1:
                    step++;
                    if (MinMax == 0)
                    {
                        labelsteps.Content = "Ответ :" + simplextable.Response() * (-1);
                    }
                    else
                    {
                        labelsteps.Content = "Ответ :" + simplextable.Response();
                    }
                    if (corner_dot_was_added == false)
                    {
                        //добавляем точку
                        corner_dot = simplextable.ResponseCornerDot(step);
                        MainGrid.Children.Add(corner_dot);
                        corner_dot_was_added = true;
                    }
                    //показываем угловую точку решения
                    corner_dot.Visibility         = Visibility.Hidden;
                    buttonToMainWindow.Visibility = Visibility.Visible;
                    break;

                case -1:
                    step++;
                    labelsteps.Content            = "Задача не разрешима!";
                    buttonToMainWindow.Visibility = Visibility.Visible;
                    break;
                }
                break;

            case 3:
                //выбор опорного
                simplextable.SelectionOfTheSupportElement();
                //обновление данных сиплекс-таблицы
                simplextable.UpdateSimplexTableValues();
                step++;
                labelsteps.Content = "Шаг " + step + ": Симплекс-таблица. Выбор опорного элемента.";
                break;

            default:
                try
                {
                    //выбран ли опорный элемент
                    simplextable.ButtonPressedOrNot();
                    //Смена местами визуализаций переменных(после выбора опорного элемента) + буферизация.
                    simplextable.ChangeOfVisualizationVariables();
                    //буферизация данных
                    simplextable.BufferingSimplexTableValues(step);
                    //удаляем кнопки
                    simplextable.DeleteButtons();
                    //вычисление согласно выбранному опорному элементу
                    simplextable.CalculateSimplexTable();
                    //обновление данных сиплекс-таблицы
                    simplextable.UpdateSimplexTableValues();
                    switch (simplextable.ResponseCheck())
                    {
                    case 0:
                        step++;
                        labelsteps.Content = "Шаг " + step + ": Симплекс-таблица. Выбор опорного элемента.";
                        //выбор опорного
                        simplextable.SelectionOfTheSupportElement();
                        break;

                    case 1:
                        step++;
                        if (MinMax == 0)
                        {
                            labelsteps.Content = "Ответ :" + simplextable.Response() * (-1);
                        }
                        else
                        {
                            labelsteps.Content = "Ответ :" + simplextable.Response();
                        }
                        //если не была добавлена, то добавляем
                        if (corner_dot_was_added == false)
                        {
                            //добавляем точку
                            corner_dot = simplextable.ResponseCornerDot(step - 4);
                            MainGrid.Children.Add(corner_dot);
                            corner_dot_was_added = true;
                        }
                        //показываем угловую точку решения
                        corner_dot.Visibility         = Visibility.Visible;
                        buttonToMainWindow.Visibility = Visibility.Visible;
                        break;

                    case -1:
                        step++;
                        labelsteps.Content            = "Задача не разрешима!";
                        buttonToMainWindow.Visibility = Visibility.Visible;
                        break;
                    }
                    simplextable.CornerPoint(step - 4);
                }
                catch (Exception d)
                {
                    MessageBox.Show(d.Message);
                }
                break;
            }
        }
예제 #30
0
 /// <summary>
 /// Transforms 3D-Points from the Camera Coordinate System into the Marker Coordinate System
 /// The transformation matrix "_final" is calculated in "UpdateTransformation"
 /// </summary>
 /// <param name="points"> List of Vectors, containing the 3d points which should be transformed</param>
 public void TransformPoints(ref List <Vector> points)
 {
     points = MatrixTransformation.TransformVectorToVector(_final, 1.0, points).ToList <Vector>();
 }
예제 #31
0
 public void SetComponent()
 {
     Matrix = new int[IdentityModel.IntDOFPerNode * IdentityModel.IntModelNodes, IdentityModel.IntDOFPerNode *IdentityModel.IntModelNodes];
     MatrixTransformation.SetIdentityMatrix(Matrix);
 }
예제 #32
0
 /// <summary>
 /// Performs c = alpha*transA(a)*transB(b) + beta*c
 /// </summary>
 /// <param name="a"></param>
 /// <param name="transA"></param>
 /// <param name="alpha"></param>
 /// <param name="b"></param>
 /// <param name="transB"></param>
 /// <param name="c"></param>
 /// <param name="beta"></param>
 /// <param name="skipCopyFromCuda"></param>
 public abstract void MatrixMultiplication(Matrix a, MatrixTransformation transA, float alpha, Matrix b, MatrixTransformation transB, Matrix c, float beta, bool copyInputsFromCpuToGpu = false, bool copyOutputsFromGpuToCpu = false);
 protected Operation GetOperation(MatrixTransformation trans)
 {
     Operation retVal = Operation.NonTranspose;
     switch (trans)
     {
         case MatrixTransformation.None:
             retVal = Operation.NonTranspose;
             break;
         case MatrixTransformation.Transpose:
             retVal = Operation.Transpose;
             break;
         //case MatrixTransformation.ConjugateTranspose:
         //    retVal = Operation.ConjugateTranspose;
         //    break;
     }
     return retVal;
 }
예제 #34
0
 public void SetComponent()
 {
     Matrix = new int[model.LQ * model.ln, model.LQ *model.ln];
     MatrixTransformation.SetIdentityMatrix(Matrix);
 }
예제 #35
0
        /// <summary>
        /// Tries to find the composite pattern and returns the output parameter image_points.
        /// In case of success the boolean value 'true' is returned.
        /// Note, that CompositePatterns can only be found, if the cameras' intrinsics are set.
        ///
        /// The algorithm is working as follows:
        /// If the main pattern 'patternA' could be found, the algorithm is finished already and the resulting
        /// image_points are known and returned.
        /// If only 'patternB' could be found, the given object_points of 'patternA' are transformed in the
        /// 'patternB' coordinate system, using the predefined transformation matrix.
        /// Furthermore, an extrinsic calibration is performed in order to find the extrinsic matrix, which describes
        /// the relation between camera coordinate system and the coordinate system of 'patternB'.
        /// Finally, the library function 'ProjectPoints' is called in order to project the transformed object_points
        /// (currently expressed in 'patternB'-coordinates) into the camera image plane.
        /// The projected points correspond to the image_points of 'patternA'.
        /// ==> To sum up: the predefined transformation is used to calculate the image_points of 'patternA', even
        /// if 'patternA' is invisible.
        /// </summary>
        /// <param name="img"> Input grayscale image. </param>
        /// <param name="image_points"> 2D output image points. </param>
        /// <returns> true... if pattern has been found; false... otherwise. </returns>
        public override bool FindPattern(Emgu.CV.Image <Emgu.CV.Structure.Gray, byte> img, out System.Drawing.PointF[] image_points)
        {
            if (this.IntrinsicParameters != null && _patternA != null && _patternB != null)
            {
                bool foundA = false;
                System.Drawing.PointF[] currentImagePointsA;
                System.Drawing.PointF[] currentImagePointsB;

                //set the object_points of the composite pattern to the object_points of 'patternA'
                this.ObjectPoints = _patternA.ObjectPoints;

                //try to find 'patternA'
                foundA = _patternA.FindPattern(img, out currentImagePointsA);

                //if 'patternA' could be found: the image_points have been found.
                if (foundA)
                {
                    image_points = currentImagePointsA;
                    //_logger.Info("Pattern found.");
                    return(true);
                }
                else
                //else: try to find 'patternB'
                if (_patternB.FindPattern(img, out currentImagePointsB))
                {
                    ExtrinsicCalibration ec_B = null;
                    Emgu.CV.ExtrinsicCameraParameters ecp_B = null;
                    Matrix extrinsic_matrix = Matrix.Identity(4, 4);
                    Matrix temp_matrix      = null;
                    Emgu.CV.Structure.MCvPoint3D32f[] transformedCornerPoints = new Emgu.CV.Structure.MCvPoint3D32f[_patternA.ObjectPoints.Length];

                    try
                    {
                        //if 'patternB' has been found: find the extrinsic matrix (relation between coordinate systems of 'patternB' and camera
                        ec_B  = new ExtrinsicCalibration(_patternB.ObjectPoints, this.IntrinsicParameters);
                        ecp_B = ec_B.Calibrate(currentImagePointsB);

                        if (ecp_B != null)
                        {
                            //form the resulting extrinsic matrix to a homogeneous (4x4) matrix.
                            temp_matrix = Parsley.Core.Extensions.ConvertToParsley.ToParsley(ecp_B.ExtrinsicMatrix);
                            extrinsic_matrix.SetMatrix(0, temp_matrix.RowCount - 1, 0, temp_matrix.ColumnCount - 1, temp_matrix);

                            //transform object points of A into B coordinate system.
                            transformedCornerPoints = MatrixTransformation.TransformVectorToEmgu(_transformationBToA.Inverse(), 1.0, _patternA.ObjectPoints).ToArray <Emgu.CV.Structure.MCvPoint3D32f>();

                            //project the points into the 2D camera plane (image_points)
                            image_points = Emgu.CV.CameraCalibration.ProjectPoints(transformedCornerPoints, ecp_B, this.IntrinsicParameters);
                            return(true);
                        }
                        else
                        {
                            _logger.Warn("Error calculating extrinsic parameters.");
                            image_points = null;
                            return(false);
                        }
                    }
                    catch (Exception e)
                    {
                        _logger.Warn("Caught Exception: {0}.", e);
                        image_points = null;
                        return(false);
                    }
                }
                else
                {
                    //reset the image_points if the pattern could not be found.
                    image_points = null;
                    return(false);
                }
            }
            else
            {
                _logger.Warn("Error: Intrinsics are needed to find a Composite Pattern but not available.");
                image_points = null;
                return(false);
            }
        }