Example #1
0
        public BitCube GrowOnesZ()
        {
            Int3 rsSize = Size;

            rsSize.Z += 2;
            int     lenZ = grid.GetLength(2);
            BitCube rs   = new BitCube(rsSize);

            for (int x = 0; x < grid.GetLength(0); x++)
            {
                for (int y = 0; y < grid.GetLength(1); y++)
                {
                    for (int z = 0; z < lenZ; z++)
                    {
                        var input = grid[x, y, z];
                        rs.grid[x, y, z] = input | (input << 1) | (input << 2);
                    }
                    for (int z = 1; z < lenZ; z++)
                    {
                        var edge = grid[x, y, z - 1];
                        rs.grid[x, y, z] |= (edge >> (BitsPerEntry - 1)) & 1;
                        rs.grid[x, y, z] |= (edge >> (BitsPerEntry - 2)) & 1;
                    }
                    //for (int z = 0; z + 1 < lenZ; z++)
                    //{
                    //	rs.grid[x, y, z] |= (grid[x, y, z + 1] & (1u)) != 0 ? HighestBit : 0;
                    //}
                }
            }
            rs.oneCount = -1;
            return(rs);
        }
Example #2
0
        public BitCube GrowOnesX()
        {
            Int3 rsSize = Size;

            rsSize.X += 2;
            BitCube rs = new BitCube(rsSize);

            for (int y = 0; y < grid.GetLength(1); y++)
            {
                for (int z = 0; z < grid.GetLength(2); z++)
                {
                    for (int x = 0; x < grid.GetLength(0); x++)
                    {
                        rs.grid[x + 1, y, z] = grid[x, y, z];
                    }
                    for (int x = 0; x + 1 < grid.GetLength(0); x++)
                    {
                        rs.grid[x + 1, y, z] |= grid[x + 1, y, z];
                    }
                    rs.grid[0, y, z] = grid[0, y, z];
                    for (int x = 1; x <= grid.GetLength(0); x++)
                    {
                        rs.grid[x + 1, y, z] |= grid[x - 1, y, z];
                    }
                    rs.grid[rs.grid.GetLength(0) - 1, y, z] = grid[grid.GetLength(0) - 1, y, z];
                }
            }
            rs.oneCount = -1;
            return(rs);
        }
Example #3
0
        public BitCube GrowOnesY()
        {
            Int3 rsSize = Size;

            rsSize.Y += 2;
            int     lenY = grid.GetLength(1);
            BitCube rs   = new BitCube(rsSize);

            for (int x = 0; x < grid.GetLength(0); x++)
            {
                for (int z = 0; z < grid.GetLength(2); z++)
                {
                    for (int y = 0; y < lenY; y++)
                    {
                        rs.grid[x, y + 1, z] = grid[x, y, z];
                    }
                    for (int y = 0; y + 1 < lenY; y++)
                    {
                        rs.grid[x, y + 1, z] |= grid[x, y + 1, z];
                    }
                    rs.grid[x, 0, z] = grid[x, 0, z];
                    for (int y = 1; y <= lenY; y++)
                    {
                        rs.grid[x, y + 1, z] |= grid[x, y - 1, z];
                    }
                    rs.grid[x, lenY + 1, z] = grid[x, lenY - 1, z];
                }
            }
            rs.oneCount = -1;
            return(rs);
        }
Example #4
0
        public BitCube SubCube(Int3 offset, Int3 size)
        {
            if ((offset >= Size).Any)
            {
                return(new BitCube());
            }
            for (int i = 0; i < 3; i++)
            {
                if (offset[i] < 0)
                {
                    size[i]  += offset[i];
                    offset[i] = 0;
                }
                if (offset[i] + size[i] > Size[i])
                {
                    size[i] = Size[i] - offset[i];
                }
            }
            BitCube rs = new BitCube(size);

            for (int x = 0; x < size.X; x++)
            {
                for (int y = 0; y < size.Y; y++)
                {
                    for (int z = 0; z < size.Z; z++)
                    {
                        rs[x, y, z] = this[offset.X + x, offset.Y + y, offset.Z + z];
                    }
                }
            }
            return(rs);
        }
Example #5
0
        public void Include(BitCube other, Int3 offset)
        {
            if ((offset >= size).Any)
            {
                return;
            }

            Int3 sourceStart = Int3.Max(-offset, 0);
            Int3 sourceCount = other.Size - sourceStart;

            Int3 destStart = Int3.Max(offset, 0);

            sourceCount = Int3.Min(destStart + sourceCount, size) - destStart;

            Int3 at = new Int3();

            for (at.X = 0; at.X < sourceCount.X; at.X++)
            {
                for (at.Y = 0; at.Y < sourceCount.Y; at.Y++)
                {
                    for (at.Z = 0; at.Z < sourceCount.Z; at.Z++)
                    {
                        this[at + destStart] |= other[at + sourceStart];
                    }
                }
            }
        }
Example #6
0
        public InconsistencyCoverage Grow(bool trimToLocalSize)
        {
            BitCube cube = base.GrowOnes();

            if (trimToLocalSize)
            {
                cube = cube.SubCube(new Int3(1), base.Size);
                if (cube.Size != base.Size)
                {
                    throw new IntegrityViolation("Unexpted grown size: " + cube.Size + ". Expected " + base.Size);
                }
            }
            return(new InconsistencyCoverage(cube));
        }
Example #7
0
 protected void LoadMaximum(BitCube a, BitCube b)
 {
     if (a.Size != b.Size)
     {
         throw new ArgumentException("Parameter size mismatch: " + a.Size + " != " + b.Size);
     }
     oneCount = -1;
     UpdateSize(a.Size);
     for (int x = 0; x < grid.GetLength(0); x++)
     {
         for (int y = 0; y < grid.GetLength(1); y++)
         {
             for (int z = 0; z < grid.GetLength(2); z++)
             {
                 grid[x, y, z] = a.grid[x, y, z] | b.grid[x, y, z];
             }
         }
     }
 }
Example #8
0
 private InconsistencyCoverage(BitCube raw) : base(raw)
 {
 }
Example #9
0
 public void LoadCopy(BitCube source)
 {
     UpdateSize(source.size);
     Buffer.BlockCopy(source.grid, 0, grid, 0, GridSize.Product * BytesPerEntry);
     oneCount = source.oneCount;
 }
Example #10
0
 protected BitCube(BitCube source)
 {
     size     = source.size;
     grid     = source.grid;
     oneCount = source.oneCount;
 }