Пример #1
0
        private float3 ComputeVectorFor(int x, int y, int z, float[,,] Ix, float[,,] Iy, float[,,] Iz, float[,,] dI)
        {
            int i = 0;

            //float3 prevFlow = new float3(0, 0, 0);
            //float3 result = new float3(0, 0, 0);

            float[,] A = new float[125, 3];
            float[,] b = new float[125, 1];

            for (int zd = -2; zd <= 2; zd++)
            {
                for (int yd = -2; yd <= 2; yd++)
                {
                    for (int xd = -2; xd <= 2; xd++)
                    {
                        var xC = Math.Max(0, Math.Min(vCols - 1, x + xd));
                        var yC = Math.Max(0, Math.Min(vRows - 1, y + yd));
                        var zC = Math.Max(0, Math.Min(vSlis - 1, z + zd));

                        A[i, 0] = Coef3D[i] * Ix[zC, yC, xC];
                        A[i, 1] = Coef3D[i] * Iy[zC, yC, xC];
                        A[i, 2] = Coef3D[i] * Iz[zC, yC, xC];

                        b[i, 0] = -Coef3D[i] * dI[zC, yC, xC];

                        i++;
                    }
                }
            }

            var At = A.Transpose();

            var M = (At.Mul(A));

            var v = M.Inverse3().Mul(At).Mul(b);

            float3 e1, e2, e3;
            float  L1, L2, L3;

            AnalyticalEigenSolver.EigenSol(M, out L1, out L2, out L3, out e1, out e2, out e3);
            //GetEigenVectors3(M, out L1, out L2, out L3, out e1, out e2, out e3);

            if (L2 > L1 || L3 > L1)
            {
                throw new InvalidOperationException();
            }


            if (L3 >= 1)
            {
                return(new float3(v[0, 0], v[1, 0], v[2, 0]));
            }
            else
            {
                var dot = v[0, 0] * e1.x + v[1, 0] * e1.y + v[2, 0] * e1.z;
                return(new float3(dot * e1.x, dot * e1.y, dot * e1.z));
            }
        }
Пример #2
0
        private float3 ComputeVectorFor(int x, int y, int z, float[,,] Ix, float[,,] Iy, float[,,] Iz, float[,,] Ik, byte[,,] map1, byte[,,] map2)
        {
            float[,] M = new float[3, 3];
            float[] b = new float[3];

            for (int zd = -2; zd <= 2; zd++)
            {
                for (int yd = -2; yd <= 2; yd++)
                {
                    for (int xd = -2; xd <= 2; xd++)
                    {
                        var xC = Math.Max(0, Math.Min(vCols - 1, x + xd));
                        var yC = Math.Max(0, Math.Min(vRows - 1, y + yd));
                        var zC = Math.Max(0, Math.Min(vSlis - 1, z + zd));

                        M[0, 0] += Ix[zC, yC, xC] * Ix[zC, yC, xC];
                        M[0, 1] += Iy[zC, yC, xC] * Ix[zC, yC, xC];
                        M[0, 2] += Ix[zC, yC, xC] * Iz[zC, yC, xC];
                        M[1, 0] += Ix[zC, yC, xC] * Iy[zC, yC, xC];
                        M[1, 1] += Iy[zC, yC, xC] * Iy[zC, yC, xC];
                        M[1, 2] += Iy[zC, yC, xC] * Iz[zC, yC, xC];
                        M[2, 0] += Ix[zC, yC, xC] * Iz[zC, yC, xC];
                        M[2, 1] += Iy[zC, yC, xC] * Iz[zC, yC, xC];
                        M[2, 2] += Iz[zC, yC, xC] * Iz[zC, yC, xC];

                        b[0] += -Ik[zC, yC, xC] * Ix[zC, yC, xC];
                        b[1] += -Ik[zC, yC, xC] * Iy[zC, yC, xC];
                        b[2] += -Ik[zC, yC, xC] * Iz[zC, yC, xC];
                    }
                }
            }

            var v      = M.Inverse3().Mul(b);
            var result = new float3(v[0], v[1], v[2]);

            float3 e1, e2, e3;
            float  L1, L2, L3;

            AnalyticalEigenSolver.EigenSol(M, out L1, out L2, out L3, out e1, out e2, out e3);

            if (L2 > L1 || L3 > L1)
            {
                throw new InvalidOperationException();
            }


            if (L3 >= 1)
            {
                return(result);
            }

            else
            {
                var dot = result.x * e1.x + result.y * e1.y + result.z * e1.z;
                return(new float3(dot * e1.x, dot * e1.y, dot * e1.z));
            }
        }