public void TestNoSeriesSplitting()
        {
            const int             numberOfSeries     = 5;
            const int             instancesPerSeries = 10;
            List <TestDataSource> dataSources        = CreateMRStudyDataSources(numberOfSeries, instancesPerSeries, "1.2.3");
            StudyTree             studyTree          = CreateStudyTree(ConvertToSops(dataSources));

            BasicDisplaySetFactory factory = new BasicDisplaySetFactory();

            factory.SetStudyTree(studyTree);

            List <IDisplaySet> allDisplaySets = new List <IDisplaySet>();

            try
            {
                Patient patient = studyTree.Patients[0];
                Study   study   = patient.Studies[0];

                Assert.AreEqual(numberOfSeries, study.Series.Count, "There should be exactly {0} series", numberOfSeries);

                foreach (Series series in study.Series)
                {
                    Assert.AreEqual(instancesPerSeries, series.Sops.Count, "There should be exactly {0} sops", instancesPerSeries);

                    List <IDisplaySet> displaySets = factory.CreateDisplaySets(series);
                    allDisplaySets.AddRange(displaySets);

                    Assert.AreEqual(1, displaySets.Count, "There should be exactly {0} display sets", 1);

                    IDisplaySet displaySet = displaySets[0];

                    Assert.AreEqual(series.Sops.Count, displaySet.PresentationImages.Count, "#Sops should match #presentation images");
                    Assert.AreEqual(series.SeriesInstanceUid, displaySet.Descriptor.Uid, "Series UID and Display Set UID don't match");
                    Assert.AreEqual(typeof(SeriesDisplaySetDescriptor), displaySet.Descriptor.GetType(), "Wrong display set descriptor type");
                }
            }
            finally
            {
                foreach (IDisplaySet displaySet in allDisplaySets)
                {
                    displaySet.Dispose();
                }

                studyTree.Dispose();
            }
        }
Beispiel #2
0
		public void TestNoSeriesSplitting()
		{
			const int numberOfSeries = 5;
			const int instancesPerSeries = 10;
			List<TestDataSource> dataSources = CreateMRStudyDataSources(numberOfSeries, instancesPerSeries, "1.2.3");
			StudyTree studyTree = CreateStudyTree(ConvertToSops(dataSources));

			BasicDisplaySetFactory factory = new BasicDisplaySetFactory();
			factory.SetStudyTree(studyTree);

			List<IDisplaySet> allDisplaySets = new List<IDisplaySet>();

			try
			{
				Patient patient = studyTree.Patients[0];
				Study study = patient.Studies[0];

				Assert.AreEqual(numberOfSeries, study.Series.Count, "There should be exactly {0} series", numberOfSeries);

				foreach (Series series in study.Series)
				{
					Assert.AreEqual(instancesPerSeries, series.Sops.Count, "There should be exactly {0} sops", instancesPerSeries);

					List<IDisplaySet> displaySets = factory.CreateDisplaySets(series);
					allDisplaySets.AddRange(displaySets);

					Assert.AreEqual(1, displaySets.Count, "There should be exactly {0} display sets", 1);

					IDisplaySet displaySet = displaySets[0];

					Assert.AreEqual(series.Sops.Count, displaySet.PresentationImages.Count, "#Sops should match #presentation images");
					Assert.AreEqual(series.SeriesInstanceUid, displaySet.Descriptor.Uid, "Series UID and Display Set UID don't match");
					Assert.AreEqual(typeof(SeriesDisplaySetDescriptor), displaySet.Descriptor.GetType(), "Wrong display set descriptor type");
				}
			}
			finally
			{
				foreach (IDisplaySet displaySet in allDisplaySets)
					displaySet.Dispose();

				studyTree.Dispose();
			}
		}
Beispiel #3
0
		public void TestKeyImages(int numberOfFrames, int numberOfMultiframeKeyImages, int numberOfSingleFrameKeyImages, bool doSplitting)
		{
			Assert.IsTrue(numberOfFrames == 0 || numberOfFrames > 1);
			Assert.IsTrue(numberOfMultiframeKeyImages <= numberOfFrames);

			const int numberOfSeries = 1;
			int instancesPerSeries = numberOfSingleFrameKeyImages + ((numberOfFrames > 0) ? 1:0);

			Assert.IsTrue(instancesPerSeries > 0);

			List<TestDataSource> dataSources = CreateMRStudyDataSources(numberOfSeries, instancesPerSeries, "1.2.3");
			if (numberOfFrames > 0)
			{
				TestDataSource multiFrameDataSource = dataSources[0];
				DicomAttributeCollection oldDataSet = multiFrameDataSource._file.DataSet;
				DicomAttributeCollection newDataSet = new DicomAttributeCollection();
				DicomFile newFile = new DicomFile("", new DicomAttributeCollection(), newDataSet);
				//Yes this is the world's crappiest hack.
				base.SetupMultiframeXA(newDataSet, 512,512, (uint)numberOfFrames);
				//because of an exception that gets thrown from the DateTimeParser
				newDataSet[DicomTags.StudyDate].SetNullValue();
				newDataSet[DicomTags.StudyTime].SetNullValue();
				newDataSet[DicomTags.SeriesDate].SetNullValue();
				newDataSet[DicomTags.SeriesTime].SetNullValue();
				newDataSet[DicomTags.ReferencedStudySequence].SetEmptyValue();
				newDataSet[DicomTags.Modality].SetStringValue("MR");
				newDataSet[DicomTags.StudyInstanceUid].SetStringValue(oldDataSet[DicomTags.StudyInstanceUid].ToString());
				newDataSet[DicomTags.SeriesInstanceUid].SetStringValue(oldDataSet[DicomTags.SeriesInstanceUid].ToString());
				dataSources[0] = new TestDataSource(newFile);
			}

			StudyTree studyTree = CreateStudyTree(ConvertToSops(dataSources));
			KeyImageSerializer serializer = new KeyImageSerializer();

			Patient patient = studyTree.Patients[0];
			Study study = patient.Studies[0];
			Series sourceSeries = study.Series[0];

			List<IDisplaySet> allDisplaySets = new List<IDisplaySet>();

			BasicDisplaySetFactory factory = new BasicDisplaySetFactory();
			factory.SetStudyTree(studyTree);

			List<IDisplaySet> displaySets = factory.CreateDisplaySets(sourceSeries);
			allDisplaySets.AddRange(displaySets);

			List<DicomFile> presentationStates = new List<DicomFile>();
			int numberOfMultiframeKeyImagesCreated = 0;
			foreach (IDisplaySet displaySet in displaySets)
			{
				foreach (IPresentationImage image in displaySet.PresentationImages)
				{
					Frame frame = ((IImageSopProvider)image).Frame;
					if (frame.ParentImageSop.NumberOfFrames > 1)
					{
						if(numberOfMultiframeKeyImagesCreated >= numberOfMultiframeKeyImages)
							continue;

						++numberOfMultiframeKeyImagesCreated;
					}

					DicomSoftcopyPresentationState presentationState = DicomSoftcopyPresentationState.Create(image);
					//because of an exception that gets thrown from the DateTimeParser
					presentationState.DicomFile.DataSet[DicomTags.StudyDate].SetNullValue();
					presentationState.DicomFile.DataSet[DicomTags.StudyTime].SetNullValue();
					presentationState.DicomFile.DataSet[DicomTags.SeriesDate].SetNullValue();
					presentationState.DicomFile.DataSet[DicomTags.SeriesTime].SetNullValue();

					presentationStates.Add(presentationState.DicomFile);
					serializer.AddImage(frame, presentationState);
				}
			}

			List<DicomFile> files = serializer.Serialize();
			List<TestDataSource> keyImageDataSources = ConvertToDataSources(files);
			List<Sop> keyImageSops = ConvertToSops(keyImageDataSources);
			keyImageSops.AddRange(ConvertToSops(ConvertToDataSources(presentationStates)));

			foreach (Sop sop in keyImageSops)
				studyTree.AddSop(sop);

			try
			{
				foreach (Series series in study.Series)
				{
					if (series.Modality != "KO")
						continue;

				    List<IDisplaySet> keyImageDisplaySets;
                    if (doSplitting)
                    {
                        factory.CreateSingleImageDisplaySets = true;
                        keyImageDisplaySets = factory.CreateDisplaySets(series);
                        if (keyImageDisplaySets.Count == 0)
                        {
                            factory.CreateSingleImageDisplaySets = false;
                            keyImageDisplaySets = factory.CreateDisplaySets(series);
                        }
                    }
                    else
                    {
                        keyImageDisplaySets = factory.CreateDisplaySets(series);
                    }

					allDisplaySets.AddRange(keyImageDisplaySets);

					int numberOfKeyImages = numberOfMultiframeKeyImages + numberOfSingleFrameKeyImages;
					if (!doSplitting)
					{
						Assert.AreEqual(1, keyImageDisplaySets.Count, "There should be only one display set");
						IDisplaySet keyImageDisplaySet = keyImageDisplaySets[0];
						Assert.AreEqual(numberOfKeyImages, keyImageDisplaySet.PresentationImages.Count, "Expected {0} images", numberOfKeyImages);
						Assert.AreEqual(typeof(SeriesDisplaySetDescriptor), keyImageDisplaySet.Descriptor.GetType(), "Wrong display set descriptor type");
					}
					else
					{
						Assert.AreEqual(numberOfKeyImages, keyImageDisplaySets.Count, "Expected {0} display sets", numberOfKeyImages);

						foreach (IDisplaySet keyImageDisplaySet in keyImageDisplaySets)
						{
							Assert.AreEqual(1, keyImageDisplaySet.PresentationImages.Count, "There should be only one presentation image");
							IPresentationImage keyImage = keyImageDisplaySet.PresentationImages[0];
							ImageSop sop = ((IImageSopProvider)keyImage).ImageSop;

							Assert.AreEqual(sourceSeries.SeriesInstanceUid, sop.SeriesInstanceUid, "Series Instance Uid is not that of the source series");
							if (numberOfKeyImages == 1)
								Assert.AreEqual(typeof(SeriesDisplaySetDescriptor), keyImageDisplaySet.Descriptor.GetType(), "Wrong display set descriptor type");
							else if (sop.NumberOfFrames > 1)
								Assert.AreEqual(typeof(SingleFrameDisplaySetDescriptor), keyImageDisplaySet.Descriptor.GetType(), "Wrong display set descriptor type");
							else
								Assert.AreEqual(typeof(SingleImageDisplaySetDescriptor), keyImageDisplaySet.Descriptor.GetType(), "Wrong display set descriptor type");
						}
					}
				}
			}
			finally
			{
				foreach (IDisplaySet displaySet in allDisplaySets)
					displaySet.Dispose();

				studyTree.Dispose();
			}
		}
Beispiel #4
0
		private void TestSeriesSplittingSingleImage_MixedMultiframeSeries(int numberOfMultiframes, int numberOfSingleframes)
		{
			const int numberOfSeries = 1;
			int instancesPerSeries = numberOfMultiframes + numberOfSingleframes;
			const int multiFrameNumberOfFrames = 5;
			List<TestDataSource> dataSources = CreateMRStudyDataSources(numberOfSeries, instancesPerSeries, "1.2.3");
			for (int i = 0; i < numberOfMultiframes; ++i)
			{
				TestDataSource multiFrameDataSource = dataSources[i];
				multiFrameDataSource._file.DataSet[DicomTags.NumberOfFrames].SetInt32(0, multiFrameNumberOfFrames);
			}

			StudyTree studyTree = CreateStudyTree(ConvertToSops(dataSources));
			BasicDisplaySetFactory factory = new BasicDisplaySetFactory { CreateSingleImageDisplaySets = instancesPerSeries > 1 };

		    List<IDisplaySet> allDisplaySets = new List<IDisplaySet>();

			int numberOfMultiframesFound = 0;
			int numberOfSingleframesFound = 0;

			try
			{
				Patient patient = studyTree.Patients[0];
				Study study = patient.Studies[0];

				Assert.AreEqual(numberOfSeries, study.Series.Count, "There should be exactly {0} series", numberOfSeries);

				foreach (Series series in study.Series)
				{
					Assert.AreEqual(instancesPerSeries, series.Sops.Count, "There should be exactly {0} sops", instancesPerSeries);

					List<IDisplaySet> displaySets = factory.CreateDisplaySets(series);
					allDisplaySets.AddRange(displaySets);

					foreach (IDisplaySet displaySet in displaySets)
					{
						ImageSop imageSop = ((IImageSopProvider)displaySet.PresentationImages[0]).ImageSop;
						if (imageSop.NumberOfFrames > 1)
						{
							++numberOfMultiframesFound;
							Assert.AreEqual(multiFrameNumberOfFrames, displaySet.PresentationImages.Count, "There should be {0} presentation image per display set", multiFrameNumberOfFrames);
							if (instancesPerSeries > 1)
							{
								Assert.AreEqual(typeof(MultiframeDisplaySetDescriptor), displaySet.Descriptor.GetType(), "Wrong display set descriptor type");
								Assert.IsTrue(displaySet.Name.Contains("Multiframe #"), "display set name doesn't contain \"Multiframe #\"");
							}
						}
						else
						{
							++numberOfSingleframesFound;
							Assert.AreEqual(1, displaySet.PresentationImages.Count, "There should be only one presentation image per display set");
							if (instancesPerSeries > 1)
							{
								Assert.AreEqual(typeof(SingleImageDisplaySetDescriptor), displaySet.Descriptor.GetType(), "Wrong display set descriptor type");
								Assert.IsTrue(displaySet.Name.Contains("Image #"), "display set name doesn't contain \"Image #\"");
							}
						}

						if (instancesPerSeries == 1)
						{
							if (numberOfMultiframes == 1)
								Assert.AreEqual(multiFrameNumberOfFrames, displaySet.PresentationImages.Count, "There should be one presentation image per frame");
							else
								Assert.AreEqual(1, displaySet.PresentationImages.Count, "There should be only one presentation image per display set");

							Assert.AreEqual(typeof(SeriesDisplaySetDescriptor), displaySet.Descriptor.GetType(), "Wrong display set descriptor type");
						}
					}
				}
			}
			finally
			{
				foreach (IDisplaySet displaySet in allDisplaySets)
					displaySet.Dispose();

				studyTree.Dispose();
			}

			Assert.AreEqual(numberOfMultiframes, numberOfMultiframesFound, "Incorrect number of multiframes");
			Assert.AreEqual(numberOfSingleframes, numberOfSingleframesFound, "Incorrect number of singleframes");
		}
Beispiel #5
0
            public override List <IDisplaySet> CreateDisplaySets(Series series)
            {
                var displaySets = new List <IDisplaySet>();

                bool showOriginal = true;

                if (SplitMultiEchoSeries)
                {
                    List <IDisplaySet> echoDisplaySets = _echoFactory.CreateDisplaySets(series);
                    if (echoDisplaySets.Count > 0 && !ShowOriginalMREchoSeries)
                    {
                        showOriginal = false;
                    }

                    displaySets.AddRange(echoDisplaySets);
                }

                if (SplitMixedMultiframeSeries)
                {
                    List <IDisplaySet> multiFrameDisplaySets = _mixedMultiFrameFactory.CreateDisplaySets(series);
                    if (multiFrameDisplaySets.Count > 0 && !ShowOriginalMixedMultiframeSeries)
                    {
                        showOriginal = false;
                    }

                    displaySets.AddRange(multiFrameDisplaySets);
                }

                bool modalityDegenerateCase    = CreateAllImagesDisplaySet && !ModalityDisplaySetExists;
                bool singleImageDegenerateCase = false;

                if (CreateSingleImageDisplaySets)
                {
                    //The factory will only create single image display sets and will not create a series
                    //display set for the degenerate case of one image in a series. In the case where
                    //the user wants to see "single image" display sets, we actually create a series
                    //display set (below) for the degenerate case, because that's technically more correct.
                    _basicFactory.CreateSingleImageDisplaySets = true;
                    var singleImageDisplaySets = new List <IDisplaySet>();
                    foreach (IDisplaySet displaySet in _basicFactory.CreateDisplaySets(series))
                    {
                        singleImageDisplaySets.Add(displaySet);
                    }

                    displaySets.AddRange(singleImageDisplaySets);

                    singleImageDegenerateCase = singleImageDisplaySets.Count == 0;
                }

                //Show the original if:
                // 1. A previous part of this method hasn't already disabled it.
                // 2. The user wants to see it, or
                // 3. It's a degenerate case
                showOriginal = showOriginal && (ShowOriginalSeries || modalityDegenerateCase || singleImageDegenerateCase);
                if (showOriginal)
                {
                    //The factory will create series display sets only.
                    _basicFactory.CreateSingleImageDisplaySets = false;
                    foreach (IDisplaySet displaySet in _basicFactory.CreateDisplaySets(series))
                    {
                        displaySets.Add(displaySet);
                    }
                }

                bool anyDisplaySetsCreated = displaySets.Count > 0 || ModalityDisplaySetExists;

                if (!anyDisplaySetsCreated)
                {
                    displaySets.AddRange(_placeholderDisplaySetFactory.CreateDisplaySets(series));
                }

                foreach (var factory in _externalFactories)
                {
                    displaySets.AddRange(factory.CreateDisplaySets(series));
                }

                foreach (var displaySet in displaySets)
                {
                }
                return(displaySets);
            }
        public void TestKeyImages(int numberOfFrames, int numberOfMultiframeKeyImages, int numberOfSingleFrameKeyImages, bool doSplitting)
        {
            Assert.IsTrue(numberOfFrames == 0 || numberOfFrames > 1);
            Assert.IsTrue(numberOfMultiframeKeyImages <= numberOfFrames);

            const int numberOfSeries     = 1;
            int       instancesPerSeries = numberOfSingleFrameKeyImages + ((numberOfFrames > 0) ? 1 : 0);

            Assert.IsTrue(instancesPerSeries > 0);

            List <TestDataSource> dataSources = CreateMRStudyDataSources(numberOfSeries, instancesPerSeries, "1.2.3");

            if (numberOfFrames > 0)
            {
                TestDataSource           multiFrameDataSource = dataSources[0];
                DicomAttributeCollection oldDataSet           = multiFrameDataSource.File.DataSet;
                DicomAttributeCollection newDataSet           = new DicomAttributeCollection();
                DicomFile newFile = new DicomFile("", new DicomAttributeCollection(), newDataSet);
                //Yes this is the world's crappiest hack.
                base.SetupMultiframeXA(newDataSet, 512, 512, (uint)numberOfFrames);
                //because of an exception that gets thrown from the DateTimeParser
                newDataSet[DicomTags.StudyDate].SetNullValue();
                newDataSet[DicomTags.StudyTime].SetNullValue();
                newDataSet[DicomTags.SeriesDate].SetNullValue();
                newDataSet[DicomTags.SeriesTime].SetNullValue();
                newDataSet[DicomTags.ReferencedStudySequence].SetEmptyValue();
                newDataSet[DicomTags.Modality].SetStringValue("MR");
                newDataSet[DicomTags.StudyInstanceUid].SetStringValue(oldDataSet[DicomTags.StudyInstanceUid].ToString());
                newDataSet[DicomTags.SeriesInstanceUid].SetStringValue(oldDataSet[DicomTags.SeriesInstanceUid].ToString());
                dataSources[0] = new TestDataSource(newFile);
            }

            StudyTree          studyTree  = CreateStudyTree(ConvertToSops(dataSources));
            KeyImageSerializer serializer = new KeyImageSerializer();

            Patient patient      = studyTree.Patients[0];
            Study   study        = patient.Studies[0];
            Series  sourceSeries = study.Series[0];

            List <IDisplaySet> allDisplaySets = new List <IDisplaySet>();

            BasicDisplaySetFactory factory = new BasicDisplaySetFactory();

            factory.SetStudyTree(studyTree);

            List <IDisplaySet> displaySets = factory.CreateDisplaySets(sourceSeries);

            allDisplaySets.AddRange(displaySets);

            List <DicomFile> presentationStates    = new List <DicomFile>();
            int numberOfMultiframeKeyImagesCreated = 0;

            foreach (IDisplaySet displaySet in displaySets)
            {
                foreach (IPresentationImage image in displaySet.PresentationImages)
                {
                    Frame frame = ((IImageSopProvider)image).Frame;
                    if (frame.ParentImageSop.NumberOfFrames > 1)
                    {
                        if (numberOfMultiframeKeyImagesCreated >= numberOfMultiframeKeyImages)
                        {
                            continue;
                        }

                        ++numberOfMultiframeKeyImagesCreated;
                    }

                    DicomSoftcopyPresentationState presentationState = DicomSoftcopyPresentationState.Create(image);
                    //because of an exception that gets thrown from the DateTimeParser
                    presentationState.DicomFile.DataSet[DicomTags.StudyDate].SetNullValue();
                    presentationState.DicomFile.DataSet[DicomTags.StudyTime].SetNullValue();
                    presentationState.DicomFile.DataSet[DicomTags.SeriesDate].SetNullValue();
                    presentationState.DicomFile.DataSet[DicomTags.SeriesTime].SetNullValue();

                    presentationStates.Add(presentationState.DicomFile);
                    serializer.AddImage(frame, presentationState);
                }
            }

            List <DicomFile>      files = serializer.Serialize();
            List <TestDataSource> keyImageDataSources = ConvertToDataSources(files);
            List <Sop>            keyImageSops        = ConvertToSops(keyImageDataSources);

            keyImageSops.AddRange(ConvertToSops(ConvertToDataSources(presentationStates)));

            foreach (Sop sop in keyImageSops)
            {
                studyTree.AddSop(sop);
            }

            try
            {
                foreach (Series series in study.Series)
                {
                    if (series.Modality != "KO")
                    {
                        continue;
                    }

                    List <IDisplaySet> keyImageDisplaySets;
                    if (doSplitting)
                    {
                        factory.CreateSingleImageDisplaySets = true;
                        keyImageDisplaySets = factory.CreateDisplaySets(series);
                        if (keyImageDisplaySets.Count == 0)
                        {
                            factory.CreateSingleImageDisplaySets = false;
                            keyImageDisplaySets = factory.CreateDisplaySets(series);
                        }
                    }
                    else
                    {
                        keyImageDisplaySets = factory.CreateDisplaySets(series);
                    }

                    allDisplaySets.AddRange(keyImageDisplaySets);

                    int numberOfKeyImages = numberOfMultiframeKeyImages + numberOfSingleFrameKeyImages;
                    if (!doSplitting)
                    {
                        Assert.AreEqual(1, keyImageDisplaySets.Count, "There should be only one display set");
                        IDisplaySet keyImageDisplaySet = keyImageDisplaySets[0];
                        Assert.AreEqual(numberOfKeyImages, keyImageDisplaySet.PresentationImages.Count, "Expected {0} images", numberOfKeyImages);
                        Assert.AreEqual(typeof(KOSelectionDocumentDisplaySetDescriptor), keyImageDisplaySet.Descriptor.GetType(), "Wrong display set descriptor type");
                    }
                    else
                    {
                        Assert.AreEqual(numberOfKeyImages, keyImageDisplaySets.Count, "Expected {0} display sets", numberOfKeyImages);

                        foreach (IDisplaySet keyImageDisplaySet in keyImageDisplaySets)
                        {
                            Assert.AreEqual(1, keyImageDisplaySet.PresentationImages.Count, "There should be only one presentation image");
                            IPresentationImage keyImage = keyImageDisplaySet.PresentationImages[0];
                            ImageSop           sop      = ((IImageSopProvider)keyImage).ImageSop;

                            Assert.AreEqual(sourceSeries.SeriesInstanceUid, sop.SeriesInstanceUid, "Series Instance Uid is not that of the source series");
                            if (numberOfKeyImages == 1)
                            {
                                Assert.AreEqual(typeof(KOSelectionDocumentDisplaySetDescriptor), keyImageDisplaySet.Descriptor.GetType(), "Wrong display set descriptor type");
                            }
                            else if (sop.NumberOfFrames > 1)
                            {
                                Assert.AreEqual(typeof(KOSelectionSingleFrameDisplaySetDescriptor), keyImageDisplaySet.Descriptor.GetType(), "Wrong display set descriptor type");
                            }
                            else
                            {
                                Assert.AreEqual(typeof(KOSelectionSingleImageDisplaySetDescriptor), keyImageDisplaySet.Descriptor.GetType(), "Wrong display set descriptor type");
                            }
                        }
                    }
                }
            }
            finally
            {
                foreach (IDisplaySet displaySet in allDisplaySets)
                {
                    displaySet.Dispose();
                }

                studyTree.Dispose();
            }
        }
        private void TestSeriesSplittingSingleImage_MixedMultiframeSeries(int numberOfMultiframes, int numberOfSingleframes)
        {
            const int             numberOfSeries           = 1;
            int                   instancesPerSeries       = numberOfMultiframes + numberOfSingleframes;
            const int             multiFrameNumberOfFrames = 5;
            List <TestDataSource> dataSources = CreateMRStudyDataSources(numberOfSeries, instancesPerSeries, "1.2.3");

            for (int i = 0; i < numberOfMultiframes; ++i)
            {
                TestDataSource multiFrameDataSource = dataSources[i];
                multiFrameDataSource.File.DataSet[DicomTags.NumberOfFrames].SetInt32(0, multiFrameNumberOfFrames);
            }

            StudyTree studyTree            = CreateStudyTree(ConvertToSops(dataSources));
            BasicDisplaySetFactory factory = new BasicDisplaySetFactory {
                CreateSingleImageDisplaySets = instancesPerSeries > 1
            };

            List <IDisplaySet> allDisplaySets = new List <IDisplaySet>();

            int numberOfMultiframesFound  = 0;
            int numberOfSingleframesFound = 0;

            try
            {
                Patient patient = studyTree.Patients[0];
                Study   study   = patient.Studies[0];

                Assert.AreEqual(numberOfSeries, study.Series.Count, "There should be exactly {0} series", numberOfSeries);

                foreach (Series series in study.Series)
                {
                    Assert.AreEqual(instancesPerSeries, series.Sops.Count, "There should be exactly {0} sops", instancesPerSeries);

                    List <IDisplaySet> displaySets = factory.CreateDisplaySets(series);
                    allDisplaySets.AddRange(displaySets);

                    foreach (IDisplaySet displaySet in displaySets)
                    {
                        ImageSop imageSop = ((IImageSopProvider)displaySet.PresentationImages[0]).ImageSop;
                        if (imageSop.NumberOfFrames > 1)
                        {
                            ++numberOfMultiframesFound;
                            Assert.AreEqual(multiFrameNumberOfFrames, displaySet.PresentationImages.Count, "There should be {0} presentation image per display set", multiFrameNumberOfFrames);
                            if (instancesPerSeries > 1)
                            {
                                Assert.AreEqual(typeof(MultiframeDisplaySetDescriptor), displaySet.Descriptor.GetType(), "Wrong display set descriptor type");
                                Assert.IsTrue(displaySet.Name.Contains("Multiframe #"), "display set name doesn't contain \"Multiframe #\"");
                            }
                        }
                        else
                        {
                            ++numberOfSingleframesFound;
                            Assert.AreEqual(1, displaySet.PresentationImages.Count, "There should be only one presentation image per display set");
                            if (instancesPerSeries > 1)
                            {
                                Assert.AreEqual(typeof(SingleImageDisplaySetDescriptor), displaySet.Descriptor.GetType(), "Wrong display set descriptor type");
                                Assert.IsTrue(displaySet.Name.Contains("Image #"), "display set name doesn't contain \"Image #\"");
                            }
                        }

                        if (instancesPerSeries == 1)
                        {
                            if (numberOfMultiframes == 1)
                            {
                                Assert.AreEqual(multiFrameNumberOfFrames, displaySet.PresentationImages.Count, "There should be one presentation image per frame");
                            }
                            else
                            {
                                Assert.AreEqual(1, displaySet.PresentationImages.Count, "There should be only one presentation image per display set");
                            }

                            Assert.AreEqual(typeof(SeriesDisplaySetDescriptor), displaySet.Descriptor.GetType(), "Wrong display set descriptor type");
                        }
                    }
                }
            }
            finally
            {
                foreach (IDisplaySet displaySet in allDisplaySets)
                {
                    displaySet.Dispose();
                }

                studyTree.Dispose();
            }

            Assert.AreEqual(numberOfMultiframes, numberOfMultiframesFound, "Incorrect number of multiframes");
            Assert.AreEqual(numberOfSingleframes, numberOfSingleframesFound, "Incorrect number of singleframes");
        }