Пример #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Voxel"/> struct.
 /// </summary>
 /// <param name="ID">The identifier.</param>
 /// <param name="solid">The solid.</param>
 internal Voxel(long ID, VoxelizedSolid solid = null)
 {
     this.ID = ID;
     Constants.GetAllFlags(ID, out var level, out var role, out var btmIsInside);
     Role              = role;
     Level             = level;
     BtmCoordIsInside  = btmIsInside;
     SideLength        = solid.VoxelSideLengths[Level];
     CoordinateIndices = Constants.GetCoordinateIndices(ID, solid.singleCoordinateShifts[level]);
     BottomCoordinate  =
         solid.GetRealCoordinates(Level, CoordinateIndices[0], CoordinateIndices[1], CoordinateIndices[2]);
 }
Пример #2
0
        internal VoxelHashSet Copy(VoxelizedSolid solid)
        {
            var copy = new VoxelHashSet(this.level, solid.bitLevelDistribution)
            {
                buckets   = (int[])this.buckets.Clone(),
                slots     = (Slot[])slots.Clone(),
                count     = this.count,
                lastIndex = this.lastIndex,
                freeList  = this.freeList,
            };

            return(copy);
        }
Пример #3
0
 public VoxelizedSolid(VoxelizedSolid vs)
 {
     Voxels          = (byte[, , ])vs.Voxels.Clone();
     Discretization  = vs.Discretization;
     VoxelsPerSide   = vs.VoxelsPerSide.ToArray();
     VoxelSideLength = vs.VoxelSideLength;
     Dimensions      = vs.Dimensions.ToArray();
     Bounds          = vs.Bounds.ToArray();
     TessToVoxSpace  = VoxelsPerSide.multiply(VoxelSideLength, 3).EltDivide(Dimensions, 3);
     SolidColor      = new Color(Constants.DefaultColor);
     Volume          = vs.Volume;
     SurfaceArea     = vs.SurfaceArea;
     Count           = vs.Count;
 }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VoxelizedSolid"/> class.
 /// </summary>
 /// <param name="vs">The vs.</param>
 internal VoxelizedSolid(VoxelizedSolid vs) : this()
 {
     Bounds          = new[] { vs.Bounds[0], vs.Bounds[1] };
     Dimensions      = Bounds[1].Subtract(Bounds[0]);
     SolidColor      = new Color(vs.SolidColor.A, vs.SolidColor.R, vs.SolidColor.G, vs.SolidColor.B);
     VoxelSideLength = vs.VoxelSideLength;
     numVoxelsX      = vs.numVoxelsX;
     numVoxelsY      = vs.numVoxelsY;
     numVoxelsZ      = vs.numVoxelsZ;
     voxels          = new IVoxelRow[numVoxelsY * numVoxelsZ];
     for (int i = 0; i < numVoxelsY * numVoxelsZ; i++)
     {
         voxels[i] = new VoxelRowSparse(vs.voxels[i], numVoxelsX);
     }
     FractionDense = 0;
     UpdateProperties();
 }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VoxelBinClass"/> class.
 /// </summary>
 /// <param name="ID">The identifier.</param>
 /// <param name="voxelRole">The voxel role.</param>
 /// <param name="solid">The solid.</param>
 public VoxelBinClass(long ID, VoxelRoleTypes voxelRole, VoxelizedSolid solid,
                      bool btmCoordIsInside = false)
 {
     InnerVoxels = new VoxelHashSet[solid.lastLevel];
     for (int i = 1; i < solid.numberOfLevels; i++)
     {
         InnerVoxels[i - 1] = new VoxelHashSet(i, solid.bitLevelDistribution);
     }
     Role    = voxelRole;
     this.ID = Constants.ClearFlagsFromID(ID) +
               Constants.MakeFlags(Level, Role, Role == VoxelRoleTypes.Full || btmCoordIsInside);
     BtmCoordIsInside  = btmCoordIsInside;
     SideLength        = solid.VoxelSideLengths[Level];
     CoordinateIndices = Constants.GetCoordinateIndices(ID, solid.singleCoordinateShifts[0]);
     BottomCoordinate  =
         solid.GetRealCoordinates(Level, CoordinateIndices[0], CoordinateIndices[1], CoordinateIndices[2]);
 }
Пример #6
0
 public VoxelizedSolid(VoxelizedSolid vs) : this()
 {
     Bounds          = new double[2][];
     Bounds[0]       = (double[])vs.Bounds[0].Clone();
     Bounds[1]       = (double[])vs.Bounds[1].Clone();
     Dimensions      = Bounds[1].subtract(Bounds[0]);
     SolidColor      = new Color(vs.SolidColor.A, vs.SolidColor.R, vs.SolidColor.G, vs.SolidColor.B);
     VoxelSideLength = vs.VoxelSideLength;
     numVoxelsX      = vs.numVoxelsX;
     numVoxelsY      = vs.numVoxelsY;
     numVoxelsZ      = vs.numVoxelsZ;
     voxels          = new IVoxelRow[numVoxelsY * numVoxelsZ];
     for (int i = 0; i < numVoxelsY * numVoxelsZ; i++)
     {
         voxels[i] = new VoxelRowSparse(vs.voxels[i], numVoxelsX);
     }
     FractionDense = 0;
     UpdateProperties();
 }
Пример #7
0
        /// <summary>
        /// Creates the full block given the dimensions and the size.
        /// </summary>
        /// <param name="voxelSideLength">Length of the voxel side.</param>
        /// <param name="bounds">The bounds.</param>
        /// <returns>VoxelizedSolid.</returns>
        public static VoxelizedSolid CreateFullBlock(double voxelSideLength, IReadOnlyList <Vector3> bounds)
        {
            var fullBlock = new VoxelizedSolid();

            fullBlock.Bounds          = new[] { bounds[0], bounds[1] };
            fullBlock.Dimensions      = fullBlock.Bounds[1].Subtract(fullBlock.Bounds[0]);
            fullBlock.SolidColor      = new Color(Constants.DefaultColor);
            fullBlock.VoxelSideLength = voxelSideLength;
            fullBlock.numVoxelsX      = (int)Math.Ceiling(fullBlock.Dimensions.X / fullBlock.VoxelSideLength);
            fullBlock.numVoxelsY      = (int)Math.Ceiling(fullBlock.Dimensions.Y / fullBlock.VoxelSideLength);
            fullBlock.numVoxelsZ      = (int)Math.Ceiling(fullBlock.Dimensions.Z / fullBlock.VoxelSideLength);
            fullBlock.voxels          = new IVoxelRow[fullBlock.numVoxelsY * fullBlock.numVoxelsZ];
            for (int i = 0; i < fullBlock.numVoxelsY * fullBlock.numVoxelsZ; i++)
            {
                var fullRow = new VoxelRowSparse(fullBlock.numVoxelsX);
                fullRow.indices.Add(0);
                fullRow.indices.Add((ushort)fullBlock.numVoxelsX);
                fullBlock.voxels[i] = fullRow;
            }
            fullBlock.UpdateProperties();
            return(fullBlock);
        }
Пример #8
0
 /// <summary>
 /// Creates the full block of voxels using the bounds and dimensions of an existing voxelized solid.
 /// </summary>
 /// <param name="vs">The vs.</param>
 /// <returns>VoxelizedSolid.</returns>
 public static VoxelizedSolid CreateFullBlock(VoxelizedSolid vs)
 {
     return(CreateFullBlock(vs.VoxelSideLength, vs.Bounds));
 }