Esempio n. 1
0
        public void CalculateMedialAx(ref Voxel[, ,] grid, ref float[, ,] disField, out bool[, ,] result)
        {
            int l = grid.GetLength(0);
            int m = grid.GetLength(1);
            int n = grid.GetLength(2);

            result = new bool[l, m, n];
            int r = (int)Math.Ceiling(FindMax(ref disField));

            int[,] lut = new int[MAXWEIGHTING, MAXLUTENTRY];

            CompLutMask(l, m, n, ref lut, 0, r * r);

            for (int i = 0; i < l; ++i)
            {
                for (int j = 0; j < m; ++j)
                {
                    for (int k = 0; k < n; ++k)
                    {
                        bool set = grid[i, j, k].set;
                        for (int vIdx = 0; vIdx < MAXWEIGHTING; ++vIdx)
                        {
                            LutVec org = mask.vg[vIdx];
                            for (int h = 0; h < 46; ++h)
                            {
                                LutVec v = CalculatePermutation(h, ref org);
                                if (v.x == 0 && v.y == 0 && v.z == 0 && v.r == 0)
                                {
                                    continue;
                                }
                                if (i + v.x >= 0 && i + v.x < l && j + v.y >= 0 && j + v.y < m && k + v.z >= 0 && k + v.z < n)
                                {
                                    set &= disField[i + v.x, j + v.y, k + v.z] <= lut[vIdx, (int)disField[i, j, k]];
                                }
                                if (!set)
                                {
                                    break;
                                }
                            }
                            if (!set)
                            {
                                break;
                            }
                        }
                        result[i, j, k] = set;
                    }
                }
            }
        }
Esempio n. 2
0
        private void CompLutCol(ref int[] CT, int lx, int ly, int lz, LutVec vec, int idx, int rMax, ref int[,] Lut)
        {
            int r1, r2, rb, l2 = ly * lz;

            for (int r = 0; r <= rMax; ++r)
            {
                Lut[idx, r] = 0;
            }
            for (int z = 0; z < lz - vec.z; ++z)
            {
                for (int y = 0; y <= z && y < ly; ++y)
                {
                    for (int x = 0; x <= y && x < lx; ++x)
                    {
                        r1 = CT[x * l2 + y * lz + z] + 1;
                        r2 = CT[(x + vec.x) * l2 + (y + vec.y) * lz + z + vec.z] + 1;
                        if (r1 <= rMax && r2 > Lut[idx, r1])
                        {
                            Lut[idx, r1] = r2;
                        }
                    }
                }
            }

            rb = 0;
            for (int ra = 0; ra < rMax; ++ra)
            {
                if (Lut[idx, ra] > rb)
                {
                    rb = Lut[idx, ra];
                }
                else
                {
                    Lut[idx, ra] = rb;
                }
            }
        }
Esempio n. 3
0
        private LutVec CalculatePermutation(int i, ref LutVec vec)
        {
            LutVec result = vec;

            if (i >= 8 && i < 16)
            {
                result.x = vec.z;
                result.y = vec.x;
                result.z = vec.y;
            }
            else if (i >= 16 && i < 24)
            {
                result.x = vec.y;
                result.y = vec.z;
                result.z = vec.x;
            }
            else if (i >= 24 && i < 32)
            {
                result.x = vec.x;
                result.y = vec.z;
                result.z = vec.y;
            }
            else if (i >= 32 && i < 40)
            {
                result.x = vec.y;
                result.y = vec.x;
                result.z = vec.z;
            }
            else if (i >= 40 && i < 46)
            {
                result.x = vec.z;
                result.y = vec.y;
                result.z = vec.x;
            }

            if (i % 8 == 1)
            {
                result.x = -result.x;
                result.y = result.y;
                result.z = result.z;
            }
            else if (i % 8 == 2)
            {
                result.x = result.x;
                result.y = -result.y;
                result.z = result.z;
            }
            else if (i % 8 == 3)
            {
                result.x = result.x;
                result.y = result.y;
                result.z = -result.z;
            }
            else if (i % 8 == 4)
            {
                result.x = -result.x;
                result.y = -result.y;
                result.z = result.z;
            }
            else if (i % 8 == 5)
            {
                result.x = -result.x;
                result.y = result.y;
                result.z = -result.z;
            }
            else if (i % 8 == 6)
            {
                result.x = result.x;
                result.y = -result.y;
                result.z = -result.z;
            }
            else if (i % 8 == 7)
            {
                result.x = -result.x;
                result.y = -result.y;
                result.z = -result.z;
            }

            return(result);
        }