示例#1
0
        /// <summary>
        /// Read temperature and displays a Threshold point warning depending on the selected ThresholdPoint enum
        /// </summary>
        /// <param name="value"></param>
        /// <param name="thresholdPoint"></param>
        /// <returns></returns>
        public TemperatureModel ReadTemperature(double value, ThresholdPoint thresholdPoint)
        {
            Temperature.Value = value;

            if (thresholdPoint == ThresholdPoint.FreezingPoint && value <= FreezingPoint)
            {
                GetFreezingPoint();
                //Temperature.Message = "Freezing point reached";
            }
            else if (thresholdPoint == ThresholdPoint.BoilingPoint && value >= BoilingPoint)
            {
                GetBoilingPoint();
                //Temperature.Message = "Boiling point reached";
            }
            else if (thresholdPoint == ThresholdPoint.CustomPoint && value == CustomThresholdPoint)
            {
                GetCustomPoint();
                //Temperature.Message = "Freezing point reached";
            }
            else
            {
                Temperature.Status  = null;
                Temperature.Message = "";
            }

            return(Temperature);
        }
示例#2
0
        public byte GetThresholdLevel()
        {
            // blend together groups of pixels to average their data and get rid of local spikes
            int weightedArraySize = DATA_ARRAY_SIZE - 4;
            uint[] weightedData = new uint[weightedArraySize];
            for (int i = 0; i < weightedArraySize; ++i)
            {
                weightedData[i] =
                    4 * Data[i + 2] +
                    3 * (Data[i + 1] + Data[i + 3]) +
                    Data[i] + Data[i + 4];
            }

            // find highest local maximum (biggest concentration of pixels of a single color
            int queueSize = (int)Math.Ceiling(weightedArraySize / 2f);
            FastPriorityQueue<ThresholdPoint> queue = new FastPriorityQueue<ThresholdPoint>(queueSize);
            for (int i = 1; i < weightedArraySize - 1; ++i)
            {
                // check if current point is higher than both of its neighbors
                if (weightedData[i] > weightedData[i + 1] && weightedData[i] > weightedData[i - 1])
                {
                    queue.Enqueue(new ThresholdPoint(i, weightedData[i]), -weightedData[i]);        // reversing queue priority to store higher values in front
                }
            }

            // find two highest value groups separated by a certain minimal distance
            ThresholdPoint a = queue.Dequeue();
            ThresholdPoint b = queue.Dequeue();
            int minPixelDistance = 16;
            while (Math.Abs(a.Index - b.Index) < minPixelDistance)
            {
                b = queue.Dequeue();
            }

            // switch points around if necessary so that 'a' represents a lower index
            if (a.Index > b.Index)
            {
                ThresholdPoint t = a;
                a = b;
                b = t;
            }

            // find the lowest value between these two groups
            uint minVal = a.Value;
            int minPos = a.Index;

            for (int i = a.Index + 1; i < b.Index; ++i)
            {
                if (weightedData[i] < minVal)
                {
                    minVal = weightedData[i];
                    minPos = i;
                }
            }

            return (byte)(minPos + 2);
        }