Ejemplo n.º 1
0
        /// <summary>
        /// Sets the <see cref="IComposableLut"/> field and sets up the LutChanged event handler.
        /// </summary>
        private void SetLutField <T>(ref T field, T value)
            where T : class, IComposableLut
        {
            if (Equals(field, value))
            {
                return;
            }

            if (field != null)
            {
                field.LutChanged -= OnLutValuesChanged;
            }

            field = value;

            if (field != null)
            {
                field.LutChanged += OnLutValuesChanged;
            }

            // clear the LUT pipeline so that it will be reassembled
            if (_lutCollection != null)
            {
                _lutCollection.Clear();
                _lutCollection = null;
            }

            OnLutChanged();
        }
Ejemplo n.º 2
0
            public IComposedLut GetLut(LutCollection sourceLuts)
            {
                IComposedLut lut = _realComposedLut;

                if (lut != null)
                {
                    return(lut);
                }

                lock (_syncLock)
                {
                    if (_realComposedLut != null)
                    {
                        return(_realComposedLut);
                    }

                    //Trace.WriteLine(String.Format("Creating Composed Lut '{0}'", Key), "LUT");

                    _realComposedLut = new ComposedLut(sourceLuts.ToArray(), _bufferCache);
                    //just use the creation time as the "last access time", otherwise it can get expensive when called in a tight loop.
                    _largeObjectData.UpdateLastAccessTime();
                    _largeObjectData.BytesHeldCount   = _realComposedLut.Data.Length * sizeof(int);
                    _largeObjectData.LargeObjectCount = 1;
                    MemoryManager.Add(this);
                    Diagnostics.OnLargeObjectAllocated(_largeObjectData.BytesHeldCount);

                    return(_realComposedLut);
                }
            }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the output LUT of the pipeline,
        /// </summary>
        public IComposedLut GetOutputLut(int minOutputValue, int maxOutputValue)
        {
            MinOutputValue = PresentationLut.MinOutputValue = minOutputValue;
            MaxOutputValue = PresentationLut.MaxOutputValue = maxOutputValue;

            LutCollection.SyncMinMaxValues();
            LutCollection.Validate();

            return(_cachedLut ?? (_cachedLut = ComposedLutCache.GetLut(LutCollection)));
        }
Ejemplo n.º 4
0
        private void SyncMinMaxValues()
        {
            if (LutCollection.Count > 0)
            {
                IComposableLut firstLut = LutCollection[0];
                firstLut.MinInputValue = _minInputValue;
                firstLut.MaxInputValue = _maxInputValue;
            }

            LutCollection.SyncMinMaxValues();
        }
Ejemplo n.º 5
0
        private void OnLutChanged()
        {
            // clear the LUT pipeline so that it will be reassembled
            if (_lutCollection != null)
            {
                _lutCollection.Clear();
                _lutCollection = null;
            }

            SyncMinMaxValues();
            _recalculate = true;
        }
Ejemplo n.º 6
0
        private void SyncMinMaxValues()
        {
            if (LutCollection.Count == 0)
            {
                return;
            }

            IComposableLut firstLut = LutCollection[0];

            firstLut.MinInputValue = _minInputValue;
            firstLut.MaxInputValue = _maxInputValue;

            LutCollection.SyncMinMaxValues();

            PresentationLut.MinOutputValue = _minOutputValue;
            PresentationLut.MaxOutputValue = _maxOutputValue;
        }
Ejemplo n.º 7
0
        public ComposedLut(LutCollection luts, BufferCache <int> cache)
        {
            //luts.Validate();

            int            lutCount;
            IComposableLut firstLut, lastLut;

            GetFirstAndLastLut(luts, out firstLut, out lastLut, out lutCount);

            _minInputValue = (int)Math.Round(firstLut.MinInputValue);
            _maxInputValue = (int)Math.Round(firstLut.MaxInputValue);
            _length        = _maxInputValue - _minInputValue + 1;
            _data          = cache != null?cache.Allocate(_length) : MemoryManager.Allocate <int>(_length);

            //copy to array because accessing ObservableList's indexer in a tight loop is very expensive
            IComposableLut[] lutArray = new IComposableLut[lutCount];
            luts.CopyTo(lutArray, 0);

            unsafe
            {
                fixed(int *composedLutData = _data)
                {
                    int *pLutData = composedLutData;
                    int  min      = _minInputValue;
                    int  max      = _maxInputValue + 1;

                    for (int i = min; i < max; ++i)
                    {
                        double val = i;

                        for (int j = 0; j < lutCount; ++j)
                        {
                            val = lutArray[j][val];
                        }

                        *pLutData = (int)Math.Round(val);
                        ++pLutData;
                    }
                }
            }
        }
Ejemplo n.º 8
0
 internal CachedLutProxy(LutCollection sourceLuts)
 {
     _sourceLuts = sourceLuts;
 }
Ejemplo n.º 9
0
 public static ICachedLut GetLut(LutCollection sourceLuts)
 {
     Platform.CheckForNullReference(sourceLuts, "sourceLuts");
     return(new CachedLutProxy(sourceLuts));
 }
Ejemplo n.º 10
0
 public IComposedLut GetLut(LutCollection sourceLuts)
 {
     return(_cacheItem.GetLut(sourceLuts));
 }
Ejemplo n.º 11
0
 public ComposedLut(LutCollection luts) : this(luts, null)
 {
 }