Esempio n. 1
0
        public void SetAllVoxelContents(byte[] buffer, out BoundingBoxD bounding)
        {
            // quantize the buffer and compute sum
            this._voxelContentSum = 0;
            for (var i = 0; i < buffer.Length; i++)
            {
                buffer[i]              = MyVoxelContentCellContent.QuantizedValue(buffer[i]);
                this._voxelContentSum += buffer[i];
            }

            bounding = new BoundingBoxD(Vector3I.MaxValue, Vector3I.MinValue);

            // mixed-->empty/full: deallocate
            // empty/full-->mixed: allocate
            // mixed: fill with values from buffer
            if (_voxelContentSum == 0)
            {
                if (this.CellType == MyVoxelCellType.MIXED)
                {
                    this.Deallocate();
                }
                this.CellType = MyVoxelCellType.EMPTY;
            }
            else if (_voxelContentSum == MyVoxelConstants.VOXEL_CELL_CONTENT_SUM_TOTAL)
            {
                if (this.CellType == MyVoxelCellType.MIXED)
                {
                    this.Deallocate();
                }
                this.CellType = MyVoxelCellType.FULL;
            }
            else
            {
                if (this.CellType == MyVoxelCellType.FULL || this.CellType == MyVoxelCellType.EMPTY)
                {
                    this._cellContent = new MyVoxelContentCellContent();
                }
                if (this._cellContent != null)
                {
                    this._cellContent.SetAddVoxelContents(buffer, ref bounding);
                }
                this.CellType = MyVoxelCellType.MIXED;
            }
        }
Esempio n. 2
0
        public void SetAllVoxelContents(byte[] buffer, out BoundingBoxD bounding)
        {
            // quantize the buffer and compute sum
            this._voxelContentSum = 0;
            for (var i = 0; i < buffer.Length; i++)
            {
                buffer[i] = MyVoxelContentCellContent.QuantizedValue(buffer[i]);
                this._voxelContentSum += buffer[i];
            }

            bounding = new BoundingBoxD(Vector3I.MaxValue, Vector3I.MinValue);

            // mixed-->empty/full: deallocate
            // empty/full-->mixed: allocate
            // mixed: fill with values from buffer
            if (_voxelContentSum == 0)
            {
                if (this.CellType == MyVoxelCellType.MIXED) this.Deallocate();
                this.CellType = MyVoxelCellType.EMPTY;
            }
            else if (_voxelContentSum == MyVoxelConstants.VOXEL_CELL_CONTENT_SUM_TOTAL)
            {
                if (this.CellType == MyVoxelCellType.MIXED) this.Deallocate();
                this.CellType = MyVoxelCellType.FULL;
            }
            else
            {
                if (this.CellType == MyVoxelCellType.FULL || this.CellType == MyVoxelCellType.EMPTY)
                {
                    this._cellContent = new MyVoxelContentCellContent();
                }
                if (this._cellContent != null)
                {
                    this._cellContent.SetAddVoxelContents(buffer, ref bounding);
                }
                this.CellType = MyVoxelCellType.MIXED;
            }
        }
Esempio n. 3
0
        //  Voxel at specified coordinate 'x, y, z' sets to value 'content'. Coordinates are relative to voxel cell
        //  IMPORTANT: Do not call this method directly! Always call it through MyVoxelMap.SetVoxelContent()
        public void SetVoxelContent(byte content, ref Vector3I voxelCoordInCell)
        {
            content = MyVoxelContentCellContent.QuantizedValue(content);

            if (this.CellType == MyVoxelCellType.FULL)
            {
                if (content == MyVoxelConstants.VOXEL_CONTENT_FULL)
                {
                    //  Nothing is changing
                    return;
                }
                else
                {
                    this._voxelContentSum -= (MyVoxelConstants.VOXEL_CONTENT_FULL - content);
                    this.CheckCellType();

                    //  If this cell is mixed, we change voxel's value in the cell content array, but first allocate the array
                    if (this.CellType == MyVoxelCellType.MIXED)
                    {
                        this._cellContent = new MyVoxelContentCellContent(); // MyVoxelContentCellContents.Allocate();
                        if (this._cellContent != null)
                        {
                            this._cellContent.Reset(MyVoxelConstants.VOXEL_CONTENT_FULL);
                            this._cellContent.SetVoxelContent(content, ref voxelCoordInCell);
                        }
                    }
                }
            }
            else if (this.CellType == MyVoxelCellType.EMPTY)
            {
                if (content == MyVoxelConstants.VOXEL_CONTENT_EMPTY)
                {
                    //  Nothing is changing
                    return;
                }
                else
                {
                    this._voxelContentSum += content;
                    this.CheckCellType();

                    //  If this cell is mixed, we change voxel's value in the cell content array, but first allocate the array
                    if (this.CellType == MyVoxelCellType.MIXED)
                    {
                        this._cellContent = new MyVoxelContentCellContent(); //MyVoxelContentCellContents.Allocate();
                        if (this._cellContent != null)
                        {
                            this._cellContent.Reset(MyVoxelConstants.VOXEL_CONTENT_EMPTY);
                            this._cellContent.SetVoxelContent(content, ref voxelCoordInCell);
                        }
                    }
                }
            }
            else if (this.CellType == MyVoxelCellType.MIXED)
            {
                if (this._cellContent == null)
                {
                    return;
                }
                //  Check for previous content value not only for optimisation, but because we need to know how much it changed
                //  for calculating whole cell content summary.
                var previousContent = this._cellContent.GetVoxelContent(ref voxelCoordInCell);

                if (previousContent == content)
                {
                    //  New value is same as current, so nothing needs to be changed
                    return;
                }

                this._voxelContentSum -= previousContent - content;
                this.CheckCellType();

                //  If this cell is still mixed, we change voxel's value in the cell content array
                if (this.CellType == MyVoxelCellType.MIXED)
                {
                    this._cellContent.SetVoxelContent(content, ref voxelCoordInCell);
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Esempio n. 4
0
 public void Deallocate()
 {
     this._cellContent = null;
 }
Esempio n. 5
0
        //  Voxel at specified coordinate 'x, y, z' sets to value 'content'. Coordinates are relative to voxel cell
        //  IMPORTANT: Do not call this method directly! Always call it through MyVoxelMap.SetVoxelContent()
        public void SetVoxelContent(byte content, ref Vector3I voxelCoordInCell)
        {
            content = MyVoxelContentCellContent.QuantizedValue(content);

            if (this.CellType == MyVoxelCellType.FULL)
            {
                if (content == MyVoxelConstants.VOXEL_CONTENT_FULL)
                {
                    //  Nothing is changing
                    return;
                }
                else
                {
                    this._voxelContentSum -= (MyVoxelConstants.VOXEL_CONTENT_FULL - content);
                    this.CheckCellType();

                    //  If this cell is mixed, we change voxel's value in the cell content array, but first allocate the array
                    if (this.CellType == MyVoxelCellType.MIXED)
                    {
                        this._cellContent = new MyVoxelContentCellContent(); // MyVoxelContentCellContents.Allocate();
                        if (this._cellContent != null)
                        {
                            this._cellContent.Reset(MyVoxelConstants.VOXEL_CONTENT_FULL);
                            this._cellContent.SetVoxelContent(content, ref voxelCoordInCell);
                        }
                    }
                }
            }
            else if (this.CellType == MyVoxelCellType.EMPTY)
            {
                if (content == MyVoxelConstants.VOXEL_CONTENT_EMPTY)
                {
                    //  Nothing is changing
                    return;
                }
                else
                {
                    this._voxelContentSum += content;
                    this.CheckCellType();

                    //  If this cell is mixed, we change voxel's value in the cell content array, but first allocate the array
                    if (this.CellType == MyVoxelCellType.MIXED)
                    {
                        this._cellContent = new MyVoxelContentCellContent(); //MyVoxelContentCellContents.Allocate();
                        if (this._cellContent != null)
                        {
                            this._cellContent.Reset(MyVoxelConstants.VOXEL_CONTENT_EMPTY);
                            this._cellContent.SetVoxelContent(content, ref voxelCoordInCell);
                        }
                    }
                }
            }
            else if (this.CellType == MyVoxelCellType.MIXED)
            {
                if (this._cellContent == null)
                {
                    return;
                }
                //  Check for previous content value not only for optimisation, but because we need to know how much it changed
                //  for calculating whole cell content summary.
                var previousContent = this._cellContent.GetVoxelContent(ref voxelCoordInCell);

                if (previousContent == content)
                {
                    //  New value is same as current, so nothing needs to be changed
                    return;
                }

                this._voxelContentSum -= previousContent - content;
                this.CheckCellType();

                //  If this cell is still mixed, we change voxel's value in the cell content array
                if (this.CellType == MyVoxelCellType.MIXED)
                {
                    this._cellContent.SetVoxelContent(content, ref voxelCoordInCell);
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Esempio n. 6
0
 public void Deallocate()
 {
     this._cellContent = null;
 }