public void ApplyThreshold() { lock (this.SnapshotLock) { if (this.Snapshot == null) { return; } } dynamic lowerValue = this.Histogram.Keys[this.LowerIndex]; dynamic upperValue = this.Histogram.Keys[this.UpperIndex]; lock (this.SnapshotLock) { if (!this.Inverted) { //// this.Snapshot.SetAllValidBits(false); foreach (SnapshotRegion region in this.Snapshot.SnapshotRegions) { for (IEnumerator <SnapshotElementComparer> enumerator = region.IterateComparer(SnapshotElementComparer.PointerIncrementMode.ValuesOnly, null); enumerator.MoveNext();) { SnapshotElementComparer element = enumerator.Current; dynamic label = element.GetElementLabel(); if (label >= lowerValue && label <= upperValue) { //// element.SetValid(true); } } } } else { //// this.Snapshot.SetAllValidBits(true); foreach (SnapshotRegion region in this.Snapshot.SnapshotRegions) { for (IEnumerator <SnapshotElementComparer> enumerator = region.IterateComparer(SnapshotElementComparer.PointerIncrementMode.LabelsOnly, null); enumerator.MoveNext();) { SnapshotElementComparer element = enumerator.Current; dynamic label = element.GetElementLabel(); if (label >= lowerValue && label <= upperValue) { //// element.SetValid(false); } } } } //// this.Snapshot.DiscardInvalidRegions(); } SnapshotManagerViewModel.GetInstance().SaveSnapshot(this.Snapshot); this.UpdateHistogram(forceUpdate: true); }
/// <summary> /// Called when the repeated task completes. /// </summary> protected override void OnEnd() { // Prefilter items with negative penalties (ie constantly changing variables) //// this.Snapshot.SetAllValidBits(false); foreach (SnapshotRegion region in this.Snapshot.SnapshotRegions) { for (IEnumerator <SnapshotElementComparer> enumerator = region.IterateComparer(SnapshotElementComparer.PointerIncrementMode.ValuesOnly, null); enumerator.MoveNext();) { SnapshotElementComparer element = enumerator.Current; if ((Int16)element.ElementLabel > 0) { //// element.SetValid(true); } } } //// this.Snapshot.DiscardInvalidRegions(); SnapshotManagerViewModel.GetInstance().SaveSnapshot(this.Snapshot); this.CleanUp(); LabelThresholderViewModel.GetInstance().OpenLabelThresholder(); }
/// <summary> /// Called when the scan updates. /// </summary> /// <param name="cancellationToken">The cancellation token for handling canceled tasks.</param> protected override void OnUpdate(CancellationToken cancellationToken) { ConcurrentDictionary <Object, Int64> histogram = new ConcurrentDictionary <Object, Int64>(); Int32 processedPages = 0; lock (this.SnapshotLock) { if (this.Snapshot == null) { this.Cancel(); return; } Parallel.ForEach( this.Snapshot.SnapshotRegions, SettingsViewModel.GetInstance().ParallelSettingsFast, (region) => { if (region.ReadGroup.ElementLabels == null || region.ElementCount <= 0) { return; } for (IEnumerator <SnapshotElementComparer> enumerator = region.IterateComparer(SnapshotElementComparer.PointerIncrementMode.LabelsOnly, null); enumerator.MoveNext();) { SnapshotElementComparer element = enumerator.Current; lock (this.ItemLock) { Object label = element.GetElementLabel(); if (histogram.ContainsKey(label)) { histogram[label]++; } else { histogram.TryAdd(label, 1); } } } lock (this.ProgressLock) { processedPages++; this.UpdateProgress(processedPages, this.Snapshot.RegionCount, canFinalize: false); } //// End foreach element }); //// End foreach region } this.Histogram = new SortedList <Object, Int64>(histogram); this.UpdateHistogram(); }
/// <summary> /// Called when the scan updates. /// </summary> /// <param name="cancellationToken">The cancellation token for handling canceled tasks.</param> protected override void OnUpdate(CancellationToken cancellationToken) { Int32 processedPages = 0; ValueCollectorModel valueCollectorModel = new ValueCollectorModel(defaultSnapshot: this.Snapshot, callback: (snapshot) => { Parallel.ForEach( this.Snapshot.OptimizedSnapshotRegions, SettingsViewModel.GetInstance().ParallelSettingsFastest, (region) => { if (!region.ReadGroup.CanCompare(hasRelativeConstraint: true)) { return; } for (IEnumerator <SnapshotElementComparer> enumerator = region.IterateComparer(SnapshotElementComparer.PointerIncrementMode.ValuesOnly, null); enumerator.MoveNext();) { SnapshotElementComparer element = enumerator.Current; // Perform the comparison based on the current scan constraint if (element.Compare()) { element.ElementLabel = (UInt16)((UInt16)element.ElementLabel + 1); } } // Update progress lock (this.ProgressLock) { processedPages++; this.UpdateProgress(processedPages, this.Snapshot.RegionCount, canFinalize: false); } }); this.ScanCount++; this.UpdateScanCount?.Invoke(); }); // TODO: Figure out a better way while (!valueCollectorModel.IsTaskComplete) { Thread.Sleep(100); } }
/// <summary> /// Called when the scan updates. /// </summary> /// <param name="cancellationToken">The cancellation token for handling canceled tasks.</param> protected void OnUpdate(CancellationToken cancellationToken) { Int32 processedPages = 0; Snapshot snapshot = ValueCollector.CollectValues(this.Snapshot).Result; Parallel.ForEach( snapshot.OptimizedSnapshotRegions, ParallelSettings.ParallelSettingsFastest, (region) => { if (!region.ReadGroup.CanCompare(hasRelativeConstraint: true)) { return; } for (IEnumerator <SnapshotElementComparer> enumerator = region.IterateComparer(SnapshotElementComparer.PointerIncrementMode.ValuesOnly, null); enumerator.MoveNext();) { SnapshotElementComparer element = enumerator.Current; // Perform the comparison based on the current scan constraint if (element.ElementCompare()) { element.ElementLabel = (UInt16)((UInt16)element.ElementLabel + 1); } } // Update progress lock (this.ProgressLock) { processedPages++; //// this.UpdateProgress(processedPages, snapshot.RegionCount, canFinalize: false); } }); this.ScanCount++; this.UpdateScanCount?.Invoke(); }