示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="VoxelizedSolid"/> class.
        /// </summary>
        /// <param name="voxelDiscretization">The voxel discretization.</param>
        /// <param name="bounds">The bounds.</param>
        /// <param name="units">The units.</param>
        /// <param name="name">The name.</param>
        /// <param name="filename">The filename.</param>
        /// <param name="comments">The comments.</param>
        /// <param name="language">The language.</param>
        public VoxelizedSolid(int bitsPerVoxelCoordinate, double[][] bounds, UnitType units = UnitType.unspecified, string name = "",
                              string filename = "", List <string> comments = null, string language = "") : base(units, name, filename,
                                                                                                                comments, language)
        {
            Discretization       = bitsPerVoxelCoordinate;
            bitLevelDistribution = Constants.DefaultBitLevelDistribution[Discretization];
            voxelsPerSide        = bitLevelDistribution.Select(b => (int)Math.Pow(2, b)).ToArray();
            voxelsInParent       = voxelsPerSide.Select(s => s * s * s).ToArray();
            defineMaskAndShifts(bitLevelDistribution);
            numberOfLevels = bitLevelDistribution.Length;

            double longestSide;

            Bounds     = new double[2][];
            Bounds[0]  = (double[])bounds[0].Clone();
            Bounds[1]  = (double[])bounds[1].Clone();
            dimensions = new double[3];
            for (int i = 0; i < 3; i++)
            {
                dimensions[i] = Bounds[1][i] - Bounds[0][i];
            }
            longestSide           = dimensions.Max();
            longestDimensionIndex = dimensions.FindIndex(d => d == longestSide);
            longestSide           = dimensions[longestDimensionIndex];
            VoxelSideLengths      = new double[numberOfLevels];
            VoxelSideLengths[0]   = longestSide / voxelsPerSide[0];
            for (int i = 1; i < numberOfLevels; i++)
            {
                VoxelSideLengths[i] = VoxelSideLengths[i - 1] / voxelsPerSide[i];
            }
            voxelDictionaryLevel0 = new VoxelBinSet(dimensions.Select(d => (int)Math.Ceiling(d / VoxelSideLengths[0])).ToArray(), bitLevelDistribution[0]);
            voxelsPerDimension    = new int[NumberOfLevels][];
            for (var i = 0; i < numberOfLevels; i++)
            {
                var voxelNum = dimensions.Select(d => (int)Math.Ceiling(d / VoxelSideLengths[i])).ToArray();
                voxelsPerDimension[i] = voxelNum;
            }
        }
示例#2
0
        internal VoxelizedSolid(TVGLFileData fileData, string fileName) : base(fileData, fileName)
        {
            bitLevelDistribution = fileData.BitLevelDistribution;
            Discretization       = bitLevelDistribution.Sum();
            voxelsPerSide        = bitLevelDistribution.Select(b => (int)Math.Pow(2, b)).ToArray();
            voxelsInParent       = voxelsPerSide.Select(s => s * s * s).ToArray();
            defineMaskAndShifts(bitLevelDistribution);
            numberOfLevels = bitLevelDistribution.Length;
            // the next 10 lines are common to the constructor above. They cannot be combines since these
            // flow down to different sub-constructors
            dimensions = new double[3];
            for (int i = 0; i < 3; i++)
            {
                dimensions[i] = Bounds[1][i] - Bounds[0][i];
            }
            var longestSide = dimensions.Max();

            longestDimensionIndex = dimensions.FindIndex(d => d == longestSide);
            longestSide           = Bounds[1][longestDimensionIndex] - Bounds[0][longestDimensionIndex];
            VoxelSideLengths      = new double[numberOfLevels];
            VoxelSideLengths[0]   = longestSide / voxelsPerSide[0];
            for (int i = 1; i < numberOfLevels; i++)
            {
                VoxelSideLengths[i] = VoxelSideLengths[i - 1] / voxelsPerSide[i];
            }
            voxelDictionaryLevel0 = new VoxelBinSet(dimensions.Select(d => (int)Math.Ceiling(d / VoxelSideLengths[0])).ToArray(), bitLevelDistribution[0]);
            voxelsPerDimension    = new int[NumberOfLevels][];
            for (var i = 0; i < numberOfLevels; i++)
            {
                voxelsPerDimension[i] = dimensions.Select(d => (int)Math.Ceiling(d / VoxelSideLengths[i])).ToArray();
            }
            var numChars0 = fileData.Voxels[0].Length;

            byte[] bytes = new byte[numChars0 / 2];
            for (var i = 0; i < numChars0; i += 2)
            {
                bytes[i / 2] = Convert.ToByte(fileData.Voxels[0].Substring(i, 2), 16);
            }
            for (int i = 0; i < bytes.Length; i += 8)
            {
                var ID = BitConverter.ToInt64(bytes, i);
                Constants.GetAllFlags(ID, out var level, out VoxelRoleTypes role, out bool btmInside);
                voxelDictionaryLevel0.AddOrReplace(new VoxelBinClass(ID, role, this, btmInside));
            }

            for (int i = 1; i < bitLevelDistribution.Length; i++)
            {
                var numChars = fileData.Voxels[i].Length;
                bytes = new byte[numChars / 2];
                for (var k = 0; k < numChars; k += 2)
                {
                    bytes[k / 2] = Convert.ToByte(fileData.Voxels[i].Substring(k, 2), 16);
                }
                for (int j = 0; j < bytes.Length; j += 8)
                {
                    var ID = BitConverter.ToInt64(bytes, j);
                    ((VoxelBinClass)voxelDictionaryLevel0.GetVoxel(ID)).InnerVoxels[i - 1]
                    .AddOrReplace(ID);
                }
            }

            UpdateProperties();

            if (fileData.Primitives != null && fileData.Primitives.Any())
            {
                Primitives = fileData.Primitives;
            }
        }