public CachedColorMap(ColorRamp ramp, StretchBase stretch, int desiredDestinationBins) { if (stretch == null) { throw new ArgumentNullException("stretch"); } m_ramp = ramp; m_map = new IntervalMap(stretch, desiredDestinationBins, false); // allow overflow m_bins = new int[m_map.Count + 1]; foreach (var interval in m_map.GetIntervals()) { m_bins[interval.Index] = m_ramp.GetColor(interval.StretchRatio).ToArgb(); } // overflow m_bins[m_bins.Length - 1] = m_bins[m_bins.Length - 2]; }
public IntervalMap(StretchBase stretch, int desiredDestinationBins, bool scaleDesiredBinsToStretchRange) { m_scaleDesiredBinsToStretchRange = scaleDesiredBinsToStretchRange; m_stretch = stretch; m_binCountDesired = desiredDestinationBins; m_binCountEstimated = m_binCountDesired; // determine how many total bins are required if the // desired bin count is used for the stretch range if (m_scaleDesiredBinsToStretchRange) { m_binCountEstimated = (int)(m_binCountEstimated / m_stretch.StretchRatio); } m_actualRangePow = (int)Math.Ceiling(Math.Log(m_stretch.ActualRange, 2)); //m_actualRange = (uint)Math.Pow(2, m_actualRangePow); //// handle max range overflow (unlikely) //if (m_actualRangePow == 32) // m_actualRange = uint.MaxValue; m_binCountPow = (int)Math.Ceiling(Math.Log(m_binCountEstimated, 2)); // make sure that there are not more bins than discrete values if (m_binCountPow > m_actualRangePow) { m_binCountPow = m_actualRangePow; } m_binCount = (int)Math.Pow(2, m_binCountPow); m_rightShift = (m_actualRangePow - m_binCountPow); m_actualMinShifted = m_stretch.ActualMin >> m_rightShift; m_actualMaxShifted = m_stretch.ActualMax >> m_rightShift; m_stretchMinShifted = m_stretch.StretchMin >> m_rightShift; m_stretchMaxShifted = m_stretch.StretchMax >> m_rightShift; }
public IntervalMap(StretchBase stretch, int desiredDestinationBins, bool scaleDesiredBinsToStretchRange) { m_scaleDesiredBinsToStretchRange = scaleDesiredBinsToStretchRange; m_stretch = stretch; m_binCountDesired = desiredDestinationBins; m_binCountEstimated = m_binCountDesired; // determine how many total bins are required if the // desired bin count is used for the stretch range if (m_scaleDesiredBinsToStretchRange) m_binCountEstimated = (int)(m_binCountEstimated / m_stretch.StretchRatio); m_actualRangePow = (int)Math.Ceiling(Math.Log(m_stretch.ActualRange, 2)); //m_actualRange = (uint)Math.Pow(2, m_actualRangePow); //// handle max range overflow (unlikely) //if (m_actualRangePow == 32) // m_actualRange = uint.MaxValue; m_binCountPow = (int)Math.Ceiling(Math.Log(m_binCountEstimated, 2)); // make sure that there are not more bins than discrete values if (m_binCountPow > m_actualRangePow) m_binCountPow = m_actualRangePow; m_binCount = (int)Math.Pow(2, m_binCountPow); m_rightShift = (m_actualRangePow - m_binCountPow); m_actualMinShifted = m_stretch.ActualMin >> m_rightShift; m_actualMaxShifted = m_stretch.ActualMax >> m_rightShift; m_stretchMinShifted = m_stretch.StretchMin >> m_rightShift; m_stretchMaxShifted = m_stretch.StretchMax >> m_rightShift; }
public CachedColorMap CreateCachedRamp(StretchBase stretch, int desiredDestinationBins) { var cachedRamp = new CachedColorMap(this, stretch, desiredDestinationBins); return(cachedRamp); }