示例#1
0
            private void LoadSop(string file)
            {
                try
                {
                    Sop sop = Sop.Create(file);
                    try
                    {
                        _viewer.StudyTree.AddSop(sop);
                    }
                    catch (SopValidationException)
                    {
                        sop.Dispose();
                        throw;
                    }
                }
                catch (Exception e)
                {
                    // Things that could go wrong in which an exception will be thrown:
                    // 1) file is not a valid DICOM image
                    // 2) file is a valid DICOM image, but its image parameters are invalid
                    // 3) file is a valid DICOM image, but we can't handle this type of DICOM image

                    _failed++;
                    Platform.Log(LogLevel.Error, e);
                }

                _total++;
            }
示例#2
0
        public void TestDisposal()
        {
            IList <DicomAttributeCollection> collections = base.SetupMRSeries(1, 1, "test");
            DicomFile      file       = new DicomFile(null, new DicomAttributeCollection(), collections[0]);
            TestDataSource dataSource = new TestDataSource(file);
            Sop            sop        = Sop.Create(dataSource);

            Assert.IsFalse(dataSource.IsDisposed);
            Assert.IsFalse(SopDataCache.ItemCount == 0, "The Sop data cache is empty.");

            sop.Dispose();

            Assert.IsTrue(dataSource.IsDisposed);
            Assert.IsTrue(SopDataCache.ItemCount == 0, "The Sop data cache is NOT empty.");
        }
示例#3
0
        public void TestCaching()
        {
            IList <DicomAttributeCollection> collections = base.SetupMRSeries(1, 1, "test");
            DicomFile file1 = new DicomFile(null, new DicomAttributeCollection(), collections[0].Copy());
            DicomFile file2 = new DicomFile(null, new DicomAttributeCollection(), collections[0].Copy());

            TestDataSource dataSource1 = new TestDataSource(file1);
            TestDataSource dataSource2 = new TestDataSource(file2);

            Sop sop1 = Sop.Create(dataSource1);

            Assert.IsTrue(SopDataCache.ItemCount == 1, "The Sop data cache should have 1 entry.");

            Sop sop2 = Sop.Create(dataSource2);

            Assert.IsTrue(SopDataCache.ItemCount == 1, "The Sop data cache should have 1 entry.");
            Assert.IsTrue(dataSource2.IsDisposed, "The data source has not been disposed.");
            Assert.IsFalse(dataSource1.IsDisposed, "The data source should not be disposed.");

            sop1.Dispose();
            Assert.IsTrue(SopDataCache.ItemCount == 1, "The Sop data cache should have 1 entry.");

            ISopReference reference21 = sop2.CreateTransientReference();
            ISopReference reference22 = sop2.CreateTransientReference();

            reference21.Dispose();
            Assert.IsFalse(dataSource1.IsDisposed, "The data source has been disposed.");
            Assert.IsTrue(SopDataCache.ItemCount == 1, "The Sop data cache should have 1 entry.");

            sop2.Dispose();
            Assert.IsFalse(dataSource1.IsDisposed, "The data source has been disposed.");
            Assert.IsTrue(SopDataCache.ItemCount == 1, "The Sop data cache should have 1 entry.");

            reference22.Dispose();
            Assert.IsTrue(dataSource1.IsDisposed, "The data source has not been disposed.");
            Assert.IsTrue(SopDataCache.ItemCount == 0, "The Sop data cache is NOT empty.");
        }
        private void LoadNewSeries(List <string> changedStudyInstanceUids)
        {
            const string segmentationModality = "SEG";

            foreach (string studyInstanceUid in changedStudyInstanceUids)
            {
                Study loadedStudy = ImageViewer.StudyTree.GetStudy(studyInstanceUid);
                if (loadedStudy == null)
                {
                    continue; // the given study is not loaded in this ImageViewer
                }
                // Query for new segmentation SOP Instances for the given study
                var seriesIdentifier = new SeriesIdentifier
                {
                    StudyInstanceUid = studyInstanceUid,
                    Modality         = segmentationModality
                };
                var seriesEntryRequest = new GetSeriesEntriesRequest
                {
                    Criteria = new SeriesEntry {
                        Series = seriesIdentifier
                    }
                };

                List <SeriesEntry> entries = null;
                Platform.GetService <IStudyStoreQuery>(
                    s =>
                    entries =
                        s.GetSeriesEntries(seriesEntryRequest)
                        .SeriesEntries.Where(
                            entry =>
                            loadedStudy.Series.All(series => series.SeriesInstanceUid != entry.Series.SeriesInstanceUid))
                        .ToList());

                // Get all unique AE Titles for the study. Can study have more than one?
                // We only need to query each AETitle once, or there will be duplicates/errors.
                List <IDicomServiceNode> studyAes =
                    (from seriesEntry in entries where seriesEntry != null select seriesEntry.Series.RetrieveAE).GroupBy
                    (
                        ae => ae.AETitle).Select(ae1 => ae1.First()).OfType <IDicomServiceNode>().ToList();

                if (!studyAes.Any())
                {
                    continue;
                }

                var reallyUpdatedStudies = new HashSet <string>();
                foreach (IDicomServiceNode studyAe in studyAes)
                {
                    IStudyLoader studyLoader;
                    try
                    {
                        studyLoader = studyAe.GetService <IStudyLoader>();
                    }
                    catch (Exception ex)
                    {
                        //Platform.Log(LogLevel.Error, ex, "Cannot get study loader", studyAe);
                        throw new Exception("Cannot get study loader", ex);
                    }

                    int numberOfSops =
                        studyLoader.Start(new StudyLoaderArgs(studyInstanceUid, null, new StudyLoaderOptions(true)));

                    // Load new segmentation SOP Instances
                    if (numberOfSops > 0)
                    {
                        for (int i = 0; i < numberOfSops; i++)
                        {
                            Sop sop = studyLoader.LoadNextSop();
                            if (sop != null && sop.Modality == segmentationModality)
                            {
                                try
                                {
                                    if (ImageViewer.StudyTree.AddSop(sop))
                                    {
                                        SegmentationDocument segmentationDocument =
                                            new SegmentationDeserializer(sop).DeserializeSegmenationDocument();
                                        if (segmentationDocument != null)
                                        {
                                            foreach (Seg seg in segmentationDocument.Segs)
                                            {
                                                IPresentationImage segPresentationImage = null;
                                                if (seg.ImageSeriesUid == null)
                                                {
                                                    if (seg.SegmentImageData != null &&
                                                        seg.SegmentImageData.SegmentFrameData != null &&
                                                        seg.SegmentImageData.SegmentFrameData.Count > 0)
                                                    {
                                                        foreach (
                                                            IImageBox imageBox in
                                                            ImageViewer.PhysicalWorkspace.ImageBoxes.Where(
                                                                imageBox => imageBox != null))
                                                        {
                                                            if (imageBox.DisplaySet != null)
                                                            {
                                                                segPresentationImage = SegmentationGraphicsHelpers.
                                                                                       PresentationImageFromPositionOrientation(
                                                                    seg.SegmentImageData.SegmentFrameData[0].
                                                                    ImagePositionPatient,
                                                                    seg.SegmentImageData.SegmentFrameData[0].
                                                                    ImageOrientationPatient,
                                                                    imageBox.DisplaySet,
                                                                    seg.SegmentImageData.FrameOfReferenceUid);
                                                            }
                                                            if (segPresentationImage != null)
                                                            {
                                                                break;
                                                            }
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    segPresentationImage =
                                                        GetFirstPresentationImageForSeries(sop.StudyInstanceUid,
                                                                                           seg.ImageSeriesUid);
                                                }
                                                if (segPresentationImage == null)
                                                {
                                                    Platform.Log(LogLevel.Info,
                                                                 "Failed to find a series and image to display a segmentation frame on (SOP Instance UID={0}, Label = {1}) (New)",
                                                                 segmentationDocument.SopInstanceUid, seg.Label);
                                                }
                                                else
                                                {
                                                    SegmentationGraphicsHelpers.CreateSeriesGraphicsForSeg(
                                                        segPresentationImage, seg, segmentationDocument,
                                                        sop.DataSource as IDicomMessageSopDataSource);
                                                    reallyUpdatedStudies.Add(studyInstanceUid);
                                                }

                                                var sopProvider = segPresentationImage as ISopProvider;
                                                if (sopProvider != null)
                                                {
                                                    AddSegmentationMenuInfo(segmentationDocument, seg, sopProvider.Sop);
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        sop.Dispose();
                                    }
                                }
                                catch (SopValidationException ex)
                                {
                                    Platform.Log(LogLevel.Error, ex,
                                                 "Failed to add newly loaded Segmentation SOP  to the StudyTree (studyInstanceUid={0}; SOPInstaceUID={1})",
                                                 sop.StudyInstanceUid, sop.SopInstanceUid);
                                    sop.Dispose();
                                }
                            }
                            else
                            {
                                sop.Dispose();
                            }
                        }
                    }
                }

                // Update component, if present
                if (reallyUpdatedStudies.Count > 0)
                {
                    UpdateSegmentationTreeInComponent();
                }
            }
        }