示例#1
0
            public override void SetStudyTree(StudyTree studyTree)
            {
                base.SetStudyTree(studyTree);

                _basicFactory.SetStudyTree(studyTree);

                if (_echoFactory != null)
                {
                    _echoFactory.SetStudyTree(studyTree);
                }

                if (_multiFrameStackFactory != null)
                {
                    _multiFrameStackFactory.SetStudyTree(studyTree);
                }

                if (_mixedMultiFrameFactory != null)
                {
                    _mixedMultiFrameFactory.SetStudyTree(studyTree);
                }

                _placeholderDisplaySetFactory.SetStudyTree(studyTree);

                foreach (var factory in _externalFactories)
                {
                    factory.SetStudyTree(studyTree);
                }
            }
        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();
            }
        }
示例#3
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();
			}
		}
示例#4
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();
			}
		}
        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();
            }
        }