Beispiel #1
0
        public void ReadWriteFileSpecialCaseTest()
        {
            // Write to a file then read it to see if we get the same thing
            Histogram rTest1 = new Histogram(1, decimal.MaxValue);

            //Add some fake values into the mix
            rTest1.AddBinVal(-5);
            rTest1.AddBinVal(7.123);

            // First try it with a real file
            using (ITempDir tmp = TempDir.Create())
            {
                UnitGroup ug       = new UnitGroup(VolumeUnit.CubicMeter, AreaUnit.SquareMeter, LengthUnit.Meter, LengthUnit.Meter);
                Area      cellArea = Area.From(0.2 * 0.3, ug.ArUnit);
                FileInfo  fPath    = new FileInfo(Path.Combine(tmp.Name, "myHistogram.csv"));
                rTest1.WriteFile(fPath, cellArea, ug);
                Histogram rTestRead = new Histogram(fPath);

                // Make sure the two histograms have the same edges and width
                Assert.AreEqual(rTest1.Count, rTest1.Count);
                Assert.AreEqual(rTest1.HistogramLower(ug).Meters, rTest1.HistogramLower(ug).Meters);
                Assert.AreEqual(rTest1.HistogramUpper(ug).Meters, rTest1.HistogramUpper(ug).Meters);
                Assert.AreEqual(rTest1._binWidth, rTest1._binWidth);

                // Now go bin-by-bin to make sure we end up with the same numbers everywhere
                for (int bid = 0; bid < rTestRead.Count; bid++)
                {
                    Assert.AreEqual(rTest1.BinCounts[bid], rTestRead.BinCounts[bid]);
                    Assert.AreEqual(rTest1.BinArea(bid, cellArea).SquareMeters, rTestRead.BinArea(bid, cellArea).SquareMeters);
                    Assert.AreEqual(rTest1.BinLower(bid, ug).Meters, rTestRead.BinLower(bid, ug).Meters);
                }
            }
        }
Beispiel #2
0
        private void GetDisplayValues(bool bArea)
        {
            // Note that the key to this dictionary is the histogram elevation values in their ORIGINAL units
            // while the elevation properties of the HistogramDisplayDataPoint should be in the display units
            histoData = new Dictionary <decimal, HistogramDisplayData>();

            for (int bid = 0; bid < _thrHist.Count; bid++)
            {
                // Make a dictionary entry if we don't already have one
                decimal bincentre = (decimal)_thrHist.BinCentre(bid, DataUnits).As(DisplayUnits.VertUnit);
                if (!histoData.ContainsKey(bincentre))
                {
                    histoData[bincentre] = new HistogramDisplayData(bincentre);
                }

                if (bArea)
                {
                    histoData[bincentre].Threshold = (decimal)(_thrHist.BinArea(bid, Project.ProjectManager.Project.CellArea).As(DisplayUnits.ArUnit));
                }
                else
                {
                    histoData[bincentre].Threshold = Math.Abs((decimal)_thrHist.BinVolume(bid, Project.ProjectManager.Project.CellArea, DataUnits).As(DisplayUnits.VolUnit));
                }
            }

            if ((_rawHist != null))
            {
                for (int bid = 0; bid < _rawHist.Count; bid++)
                {
                    // Make a dictionary entry if we don't already have one
                    decimal bincentre = (decimal)_rawHist.BinCentre(bid, DataUnits).As(DisplayUnits.VertUnit);
                    if (!histoData.ContainsKey(bincentre))
                    {
                        histoData[bincentre] = new HistogramDisplayData(bincentre);
                    }

                    if (bArea)
                    {
                        histoData[bincentre].Raw = (decimal)(_rawHist.BinArea(bid, Project.ProjectManager.Project.CellArea).As(DisplayUnits.ArUnit)) - histoData[bincentre].Threshold;
                    }
                    else
                    {
                        histoData[bincentre].Raw = Math.Abs((decimal)_rawHist.BinVolume(bid, Project.ProjectManager.Project.CellArea, DataUnits).As(DisplayUnits.VolUnit)) - histoData[bincentre].Threshold;
                    }
                }
            }
        }