Пример #1
0
        private static List <float> generateMinMaxArray(string[] axis, string fileName)
        {
            List <float> minMaxArray = new List <float>();

            foreach (string a in axis)
            {
                string filePath = FileStructure.cacheDirectory;
                string path     = Path.Combine(filePath, fileName, "fields", a, "mmAray.bin");

                float[] minMax = AllMeshes.minMaxOfFile(path);
                minMaxArray.Add(minMax[0]);
                minMaxArray.Add(minMax[1]);
            }
            return(minMaxArray);
        }
Пример #2
0
        /// <summary>
        /// Given a filename and a resolution, creates a point cloud array from
        /// the locations found in the file
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="resolution"></param>
        /// <returns></returns>
        public VoxelArray createPointCloud(string filename, int resolution, string xaxis, string yaxis, string zaxis, float[] minMaxArray)
        {
            //how to output the file based on input
            string filePath  = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(filename)));
            string attribute = Path.GetFileName(Path.GetDirectoryName(filename));
            string divider   = Path.GetFileNameWithoutExtension(filename);

            Directory.CreateDirectory(filePath + "\\meshes\\" + attribute + "\\" + resolution + "\\");
            outputPath = filePath + "\\meshes\\" + attribute + "\\" + resolution + "\\" + divider;

            List <FieldCell> cells = FieldCell.ReadCells(filename);

            //sort based on cell number
            cells.Sort(delegate(FieldCell c1, FieldCell c2) { return(c1.cellNum.CompareTo(c2.cellNum)); });
            //Now we need to create a list of ATTRPoint by pulling necessarry parts from
            //other files

            //TODO make this so that it checks if the axis exist in the cache
            string xFPath = Path.Combine(filePath, "fields", xaxis, "full.BNF");
            string yFPath = Path.Combine(filePath, "fields", yaxis, "full.BNF");
            string zFPath = Path.Combine(filePath, "fields", zaxis, "full.BNF");

            //Set up xcoord, ycoord, zcoord readers
            FileStream[] streams = new FileStream[3];
            streams[0] = File.OpenRead(xFPath);
            streams[1] = File.OpenRead(yFPath);
            streams[2] = File.OpenRead(zFPath);
            BinaryReader[] readers = new BinaryReader[3];
            readers[0] = new BinaryReader(streams[0]);
            readers[1] = new BinaryReader(streams[1]);
            readers[2] = new BinaryReader(streams[2]);

            int numToRead = 1;
            int bIndex    = 0;
            List <AttCoordCell> points = new List <AttCoordCell>();
            int count = 0;

            for (int i = 0; i < cells.Count; i++)
            {
                //The number of floats to read from each file is:
                //numToRead = cells[i].cellnumber - bIndex
                //The next bytes will be the values associated with the
                //desired cell
                //Then set bIndex = cells[i].cellnumber so that our bIndex
                //is updated
                numToRead = (cells[i].cellNum - bIndex) - 1;
                //incrementing our readers to the correct index

                if (numToRead > 0)
                {
                    int bytes = numToRead * 4;
                    readers[0].ReadBytes(bytes);
                    readers[1].ReadBytes(bytes);
                    readers[2].ReadBytes(bytes);
                }

                float xc = readers[0].ReadSingle();
                float yc = readers[1].ReadSingle();
                float zc = readers[2].ReadSingle();
                bIndex = cells[i].cellNum;
                AttCoordCell toAdd = new AttCoordCell(cells[i].cellNum, xc, yc, zc, cells[i].field);
                points.Add(toAdd);
                count++;
                //if (count % 50000 == 0)
                //{
                //    double perc = ((double)count / (double)cells.Count) * 100;
                //    PercentageClass.UpdatePercentage("Creating Point Cloud Array", perc);
                //    DebugLog.logConsole("Attribute Coordcell Reading: "+perc.ToString("#.##") + "%");
                //}
            }

            foreach (BinaryReader r in readers)
            {
                r.Close();
            }
            foreach (Stream s in streams)
            {
                s.Close();
            }
            if (points.Count < 3)
            {
                throw new InvalidOperationException();
            }
            if (minMaxArray == null)
            {
                List <float> newMinMax = new List <float>();
                string[]     axises    = new string[] { xaxis, yaxis, zaxis };
                foreach (string a in axises)
                {
                    string axisPath = Path.Combine(filePath, "fields", xaxis, "mmAray.bin");

                    float[] minMax = AllMeshes.minMaxOfFile(axisPath);
                    newMinMax.Add(minMax[0]);
                    newMinMax.Add(minMax[1]);
                }

                VoxelArray array = new VoxelArray(resolution, newMinMax.ToArray());
                //inserting all the points into the array
                array.insertPoints(points);

                return(array);
            }
            else
            {
                VoxelArray array = new VoxelArray(resolution, minMaxArray);
                //inserting all the points into the array
                array.insertPoints(points);

                return(array);
            }
        }