private void SortImagesAndValidate( PresentationImageCollection orderedCollection, PresentationImageCollection nonOrderedCollection, bool reverse, IComparer <IPresentationImage> comparer, TraceDelegate trace) { if (reverse) { PresentationImageCollection reversedCollection = new PresentationImageCollection(); for (int i = orderedCollection.Count - 1; i >= 0; --i) { reversedCollection.Add(orderedCollection[i]); } orderedCollection = reversedCollection; } Randomize(orderedCollection, nonOrderedCollection); Debug.WriteLine("NON-ORDERED COLLECTION (PRE-SORT)\n"); trace(nonOrderedCollection); //Be certain it is currently *not* in order. Assert.IsFalse(VerifyOrdered(orderedCollection, nonOrderedCollection)); //Sort it. nonOrderedCollection.Sort(comparer); Debug.WriteLine("NON-ORDERED COLLECTION (POST-SORT)"); trace(nonOrderedCollection); //It should now be in the proper order. Assert.IsTrue(VerifyOrdered(orderedCollection, nonOrderedCollection)); }
private void AppendCollection(PresentationImageCollection collection, IEnumerable <PresentationImage> listImages) { foreach (PresentationImage image in listImages) { collection.Add(image); } }
private IPresentationImage FindRequiredImage(PresentationImageCollection images, string studyInstanceUid, string seriesInstanceUid, string sopInstanceUid) { return(CollectionUtils.SelectFirst( images, image => { var imageSopProvider = image as IImageSopProvider; return imageSopProvider != null && imageSopProvider.ImageSop.StudyInstanceUid == studyInstanceUid && imageSopProvider.ImageSop.SeriesInstanceUid == seriesInstanceUid && imageSopProvider.ImageSop.SopInstanceUid == sopInstanceUid; })); }
private bool VerifyOrdered( PresentationImageCollection orderedCollection, PresentationImageCollection nonOrderedCollection) { Assert.AreEqual(orderedCollection.Count, nonOrderedCollection.Count); int index = 0; foreach (PresentationImage orderedImage in orderedCollection) { IPresentationImage nonOrderedImage = nonOrderedCollection[index]; if (!(orderedImage is DicomGrayscalePresentationImage) && !(nonOrderedImage is DicomGrayscalePresentationImage)) { ++index; continue; } if (!(orderedImage is DicomGrayscalePresentationImage) && (nonOrderedImage is DicomGrayscalePresentationImage)) { return(false); } if ((orderedImage is DicomGrayscalePresentationImage) && !(nonOrderedImage is DicomGrayscalePresentationImage)) { return(false); } DicomGrayscalePresentationImage dicomOrdered = orderedImage as DicomGrayscalePresentationImage; DicomGrayscalePresentationImage dicomNonOrdered = nonOrderedImage as DicomGrayscalePresentationImage; if (dicomOrdered.ImageSop.StudyInstanceUid != dicomNonOrdered.ImageSop.StudyInstanceUid || dicomOrdered.ImageSop.SeriesInstanceUid != dicomNonOrdered.ImageSop.SeriesInstanceUid || dicomOrdered.ImageSop.InstanceNumber != dicomNonOrdered.ImageSop.InstanceNumber) { return(false); } ++index; } return(true); }
private void TestSortingDicomImagesByInstanceAndFrameNumber(bool reverse) { PresentationImageCollection orderedCollection = new PresentationImageCollection(); PresentationImageCollection nonOrderedCollection = new PresentationImageCollection(); AppendCollection(orderedCollection, NewDicomSeries("123", "1", 1, 25)); AppendCollection(orderedCollection, NewDicomSeries("123", "10", 1, 25)); AppendCollection(orderedCollection, NewDicomSeries("123", "111", 1, 25)); AppendCollection(orderedCollection, NewDicomSeries("123", "456", 1, 25)); AppendCollection(orderedCollection, NewDicomSeries("123", "789", 1, 25)); //Note that the seriesUID are *not* in numerical order. This is because //it is a string comparison that is being done. AppendCollection(orderedCollection, NewDicomSeries("a", "1", 1, 25)); AppendCollection(orderedCollection, NewDicomSeries("a", "11", 1, 25)); AppendCollection(orderedCollection, NewDicomSeries("a", "12", 1, 25)); AppendCollection(orderedCollection, NewDicomSeries("a", "6", 1, 25)); AppendCollection(orderedCollection, NewDicomSeries("a", "7", 1, 25)); AppendCollection(orderedCollection, NewDicomSeries("b", "20", 1, 25)); AppendCollection(orderedCollection, NewDicomSeries("b", "21", 1, 25)); AppendCollection(orderedCollection, NewDicomSeries("b", "33", 1, 25)); AppendCollection(orderedCollection, NewDicomSeries("b", "34", 1, 25)); AppendCollection(orderedCollection, NewDicomSeries("b", "40", 1, 25)); //just put one of these at the end, it's enough. We just want to see // that non-Dicom images get pushed to one end (depending on forward/reverse). orderedCollection.Add(new MockPresentationImage()); SortImagesAndValidate(orderedCollection, nonOrderedCollection, reverse, new InstanceAndFrameNumberComparer(reverse), TraceInstanceAndFrameNumbers); foreach (PresentationImage image in nonOrderedCollection) { image.Dispose(); } foreach (PresentationImage image in orderedCollection) { image.Dispose(); } }
private void TestSortingDicomImagesByAcquisitionTime(bool reverse) { PresentationImageCollection orderedCollection = new PresentationImageCollection(); PresentationImageCollection nonOrderedCollection = new PresentationImageCollection(); foreach (IPresentationImage image in GetAcquisitionTimeTestImages()) { orderedCollection.Add(image); } SortImagesAndValidate(orderedCollection, nonOrderedCollection, reverse, new SliceLocationComparer(reverse), TraceAcquisitionTime); foreach (PresentationImage image in nonOrderedCollection) { image.Dispose(); } foreach (PresentationImage image in orderedCollection) { image.Dispose(); } }
private void DisposePresentationImages() { if (_presentationImages == null) return; foreach (PresentationImage image in _presentationImages) image.Dispose(); _presentationImages.ItemAdded -= OnPresentationImageAdded; _presentationImages.ItemRemoved -= OnPresentationImageRemoved; _presentationImages.ItemChanging -= OnPresentationImageChanging; _presentationImages.ItemChanged -= OnPresentationImageChanged; _presentationImages = null; }