Esempio n. 1
0
        public List<DicomFile> Build(StudyBuilder study)
        {
            if (SeriesInstanceUid == null)
                SeriesInstanceUid = DicomUid.GenerateUid().UID;

            var files = new List<DicomFile>();
            foreach (var image in Images)
                files.Add(image.Build(study, this));

            return files;
        }
Esempio n. 2
0
        public DicomFile Build(StudyBuilder study, SeriesBuilder series)
        {
            var file = new DicomFile();
            var dataset = file.DataSet;

            if (study != null)
                dataset.SaveDicomFields(study);
            if (series != null)
                dataset.SaveDicomFields(series);

            dataset.SaveDicomFields(this);

            dataset[DicomTags.SopInstanceUid].SetStringValue(DicomUid.GenerateUid().UID);

            dataset[DicomTags.PixelSpacing].SetStringValue(string.Format(@"{0}\{1}", 0.5, 0.5));
            dataset[DicomTags.PhotometricInterpretation].SetStringValue("MONOCHROME2");
            dataset[DicomTags.SamplesPerPixel].SetInt32(0, 1);
            dataset[DicomTags.BitsStored].SetInt32(0, 16);
            dataset[DicomTags.BitsAllocated].SetInt32(0, 16);
            dataset[DicomTags.HighBit].SetInt32(0, 15);
            dataset[DicomTags.PixelRepresentation].SetInt32(0, 1);
            dataset[DicomTags.Rows].SetInt32(0, 10);
            dataset[DicomTags.Columns].SetInt32(0, 10);

            CreatePixelData(dataset);

            SetupMetaInfo(file);
            file.TransferSyntax = TransferSyntax.ExplicitVrLittleEndian;

            return file;
        }
// ReSharper disable InconsistentNaming
        public static StudyBuilder CreateCRXRayBuilder
// ReSharper restore InconsistentNaming
        (
            string patientId,
            string patientsName,
            string studyDescription,
            string studyInstanceUid,
            string seriesDescription,
            int startSeriesNumber,
            bool oneSeries,
            bool oneImagePerSeries,
            bool createSingleImageDisplaySets
        )
        {
            if (!oneSeries && !oneImagePerSeries)
            {
                throw new ArgumentException("Multiple Series currently restricted to one image each");
            }

            var studyBuilder = new StudyBuilder
            {
                DisplaySetFactory = new BasicDisplaySetFactory {
                    CreateSingleImageDisplaySets = createSingleImageDisplaySets
                },
                PatientId        = patientId,
                PatientsName     = patientsName,
                StudyDescription = studyDescription,
                StudyInstanceUid = studyInstanceUid
            };

            var image1 = new ImageBuilder
            {
                ImageLaterality = "U",
                ViewPosition    = "AP",
                InstanceNumber  = 1,
                SopClassUid     = SopClass.ComputedRadiographyImageStorageUid
            };

            var image2 = new ImageBuilder
            {
                ImageLaterality = "U",
                ViewPosition    = "LL",
                InstanceNumber  = 1,
                SopClassUid     = SopClass.ComputedRadiographyImageStorageUid
            };

            if (oneSeries)
            {
                var seriesBuilder = new SeriesBuilder
                {
                    Modality          = "CR",
                    SeriesDescription = seriesDescription,
                    SeriesNumber      = startSeriesNumber,
                    Images            = new List <ImageBuilder> {
                        image1
                    }
                };

                if (!oneImagePerSeries)
                {
                    seriesBuilder.Images.Add(image2);
                }

                studyBuilder.Series.Add(seriesBuilder);
            }
            else
            {
                var seriesBuilder = new SeriesBuilder
                {
                    Modality          = "CR",
                    SeriesDescription = seriesDescription,
                    SeriesNumber      = startSeriesNumber,
                    Images            = new List <ImageBuilder> {
                        image1
                    }
                };

                studyBuilder.Series.Add(seriesBuilder);

                seriesBuilder = new SeriesBuilder
                {
                    Modality          = "CR",
                    SeriesDescription = seriesDescription,
                    SeriesNumber      = startSeriesNumber,
                    Images            = new List <ImageBuilder> {
                        image2
                    }
                };

                studyBuilder.Series.Add(seriesBuilder);
            }

            return(studyBuilder);
        }
        public static StudyBuilder CreateMixedMultiframeUltrasound
        (
            string patientId,
            string patientsName,
            string studyDescription,
            string studyInstanceUid,
            int seriesNumber,
            string seriesDescription,
            int numberSingleImages,
            int numberMultiframes,
            bool createSeriesDisplaySet,
            bool createSingleImageDisplaySets
        )
        {
            var studyBuilder = new StudyBuilder
            {
                PatientId        = patientId,
                PatientsName     = patientsName,
                StudyDescription = studyDescription,
                StudyInstanceUid = studyInstanceUid
            };

            if (numberMultiframes <= 0 && numberSingleImages <= 0)
            {
                throw new ArgumentException();
            }

            SeriesBuilder seriesBuilder;

            studyBuilder.Series.Add(seriesBuilder = new SeriesBuilder
            {
                SeriesDescription = seriesDescription,
                Modality          = "US",
                SeriesNumber      = seriesNumber
            });

            int instanceNumber = 1;

            for (int i = 0; i < numberSingleImages; i++, instanceNumber++)
            {
                seriesBuilder.Images.Add(new ImageBuilder
                {
                    InstanceNumber = instanceNumber,
                    SopClassUid    = SopClass.UltrasoundImageStorageUid
                });
            }

            for (int i = 0; i < numberMultiframes; i++, instanceNumber++)
            {
                seriesBuilder.Images.Add(new ImageBuilder
                {
                    InstanceNumber = instanceNumber,
                    NumberOfFrames = 3,
                    SopClassUid    = SopClass.UltrasoundMultiFrameImageStorageUid
                });
            }

            if (createSingleImageDisplaySets)
            {
                studyBuilder.DisplaySetFactory = new BasicDisplaySetFactory {
                    CreateSingleImageDisplaySets = true
                }
            }
            ;
            //Only use the mixed multi-frame factory if it's going to work.
            else if (!createSeriesDisplaySet && (numberMultiframes > 1 || (numberMultiframes > 0 && numberSingleImages > 0)))
            {
                studyBuilder.DisplaySetFactory = new MixedMultiFrameDisplaySetFactory();
            }

            return(studyBuilder);
        }
        public static StudyBuilder CreateDigitalXRayBuilder
        (
            string patientId,
            string patientsName,
            string studyDescription,
            string studyInstanceUid,
            string seriesDescription,
            int startSeriesNumber,
            bool oneSeries,
            bool oneImagePerSeries,
            bool createSingleImageDisplaySets
        )
        {
            if (!oneSeries && !oneImagePerSeries)
            {
                throw new ArgumentException("Multiple Series currently restricted to one image each");
            }

            var studyBuilder = new StudyBuilder
            {
                DisplaySetFactory = new BasicDisplaySetFactory {
                    CreateSingleImageDisplaySets = createSingleImageDisplaySets
                },
                PatientId        = patientId,
                PatientsName     = patientsName,
                StudyDescription = studyDescription,
                StudyInstanceUid = studyInstanceUid
            };

            var image1 = new ImageBuilder
            {
                ImageLaterality        = "U",
                ViewPosition           = "AP",
                InstanceNumber         = 1,
                SopClassUid            = SopClass.DigitalXRayImageStorageForPresentationUid,
                PresentationIntentType = "FOR PRESENTATION"
            };

            var image2 = new ImageBuilder
            {
                ImageLaterality        = "U",
                ViewPosition           = "LL",
                InstanceNumber         = 1,
                SopClassUid            = SopClass.DigitalXRayImageStorageForPresentationUid,
                PresentationIntentType = "FOR PRESENTATION"
            };


            if (oneSeries)
            {
                var seriesBuilder = new SeriesBuilder
                {
                    Modality          = "DX",
                    SeriesDescription = seriesDescription,
                    SeriesNumber      = startSeriesNumber,
                    Images            = new List <ImageBuilder> {
                        image1
                    }
                };

                if (!oneImagePerSeries)
                {
                    seriesBuilder.Images.Add(image2);
                }

                studyBuilder.Series.Add(seriesBuilder);
            }
            else
            {
                var seriesBuilder = new SeriesBuilder
                {
                    Modality          = "DX",
                    SeriesDescription = seriesDescription,
                    SeriesNumber      = startSeriesNumber,
                    Images            = new List <ImageBuilder> {
                        image1
                    }
                };

                studyBuilder.Series.Add(seriesBuilder);

                seriesBuilder = new SeriesBuilder
                {
                    Modality          = "DX",
                    SeriesDescription = seriesDescription,
                    SeriesNumber      = startSeriesNumber,
                    Images            = new List <ImageBuilder> {
                        image2
                    }
                };

                studyBuilder.Series.Add(seriesBuilder);
            }

            return(studyBuilder);
        }
Esempio n. 6
0
        private void Test(StudyTree studyTree, StudyBuilder builder, DisplaySetCreationOptions options, bool expectModalityDisplaySet, int expectedDisplaySetCount)
        {
            var filler = new LayoutManager.ImageSetFiller(studyTree, options);
            var imageSet = new ImageSet { Uid = builder.StudyInstanceUid };

            var study = studyTree.Studies.First();

            try
            {
                //NOTE: follow the same pattern as the layout manager where we add the "all images" display sets
                //first, then we add ones for the individual series after.
                filler.AddMultiSeriesDisplaySets(imageSet, study);
                Assert.AreEqual(expectModalityDisplaySet ? 1 : 0, imageSet.DisplaySets.Count, "Empty Image Set");

                foreach (var series in study.Series)
                    filler.AddSeriesDisplaySets(imageSet, series);

                Assert.AreEqual(expectedDisplaySetCount, imageSet.DisplaySets.Count, "Display Set Counts");
            }
            finally
            {
                studyTree.Dispose();
                imageSet.Dispose();
            }
        }
        public static StudyBuilder CreateMixedMultiframeUltrasound
        (
            string patientId,
            string patientsName,
            string studyDescription,
            string studyInstanceUid,
            int seriesNumber,
            string seriesDescription,
            int numberSingleImages,
            int numberMultiframes,
            bool createSeriesDisplaySet,
            bool createSingleImageDisplaySets
        )
        {
            var studyBuilder = new StudyBuilder
                       {
                           PatientId = patientId,
                           PatientsName = patientsName,
                           StudyDescription = studyDescription,
                           StudyInstanceUid = studyInstanceUid
                       };

            if (numberMultiframes <= 0 && numberSingleImages <= 0)
                throw new ArgumentException();

            SeriesBuilder seriesBuilder;
            studyBuilder.Series.Add(seriesBuilder = new SeriesBuilder
            {
                SeriesDescription = seriesDescription,
                Modality = "US",
                SeriesNumber = seriesNumber
            });

            int instanceNumber = 1;
            for (int i = 0; i < numberSingleImages; i++, instanceNumber++)
            {
                seriesBuilder.Images.Add(new ImageBuilder
                                             {
                                                 InstanceNumber = instanceNumber,
                                                 SopClassUid = SopClass.UltrasoundImageStorageUid
                                             });
            }

            for (int i = 0; i < numberMultiframes; i++, instanceNumber++)
            {
                seriesBuilder.Images.Add(new ImageBuilder
                {
                    InstanceNumber = instanceNumber,
                    NumberOfFrames = 3,
                    SopClassUid = SopClass.UltrasoundMultiFrameImageStorageUid
                });
            }

            if (createSingleImageDisplaySets)
                studyBuilder.DisplaySetFactory = new BasicDisplaySetFactory{CreateSingleImageDisplaySets = true};
            //Only use the mixed multi-frame factory if it's going to work.
            else if (!createSeriesDisplaySet && (numberMultiframes > 1 || (numberMultiframes > 0 && numberSingleImages > 0)))
                studyBuilder.DisplaySetFactory = new MixedMultiFrameDisplaySetFactory();

            return studyBuilder;
        }
// ReSharper disable InconsistentNaming
        public static StudyBuilder CreateCRXRayBuilder
// ReSharper restore InconsistentNaming
        (
            string patientId,
            string patientsName,
            string studyDescription,
            string studyInstanceUid,
            string seriesDescription,
            int startSeriesNumber,
            bool oneSeries,
            bool oneImagePerSeries,
            bool createSingleImageDisplaySets
        )
        {
            if (!oneSeries && !oneImagePerSeries)
                throw new ArgumentException("Multiple Series currently restricted to one image each");

            var studyBuilder = new StudyBuilder
            {
                DisplaySetFactory = new BasicDisplaySetFactory { CreateSingleImageDisplaySets = createSingleImageDisplaySets },
                PatientId = patientId,
                PatientsName = patientsName,
                StudyDescription = studyDescription,
                StudyInstanceUid = studyInstanceUid
            };

            var image1 = new ImageBuilder
            {
                ImageLaterality = "U",
                ViewPosition = "AP",
                InstanceNumber = 1,
                SopClassUid = SopClass.ComputedRadiographyImageStorageUid
            };

            var image2 = new ImageBuilder
            {
                ImageLaterality = "U",
                ViewPosition = "LL",
                InstanceNumber = 1,
                SopClassUid = SopClass.ComputedRadiographyImageStorageUid
            };

            if (oneSeries)
            {
                var seriesBuilder = new SeriesBuilder
                                        {
                                            Modality = "CR",
                                            SeriesDescription = seriesDescription,
                                            SeriesNumber = startSeriesNumber,
                                            Images = new List<ImageBuilder> {image1}
                                        };

                if (!oneImagePerSeries)
                    seriesBuilder.Images.Add(image2);

                studyBuilder.Series.Add(seriesBuilder);
            }
            else
            {
                var seriesBuilder = new SeriesBuilder
                {
                    Modality = "CR",
                    SeriesDescription = seriesDescription,
                    SeriesNumber = startSeriesNumber,
                    Images = new List<ImageBuilder> { image1 }
                };

                studyBuilder.Series.Add(seriesBuilder);

                seriesBuilder = new SeriesBuilder
                {
                    Modality = "CR",
                    SeriesDescription = seriesDescription,
                    SeriesNumber = startSeriesNumber,
                    Images = new List<ImageBuilder> { image2 }
                };

                studyBuilder.Series.Add(seriesBuilder);
            }

            return studyBuilder;
        }
        public static StudyBuilder CreateDigitalXRayBuilder
        (
            string patientId,
            string patientsName,
            string studyDescription,
            string studyInstanceUid,
            string seriesDescription,
            int startSeriesNumber,
            bool oneSeries,
            bool oneImagePerSeries,
            bool createSingleImageDisplaySets
        )
        {
            if (!oneSeries && !oneImagePerSeries)
                throw new ArgumentException("Multiple Series currently restricted to one image each");

            var studyBuilder = new StudyBuilder
            {
                DisplaySetFactory = new BasicDisplaySetFactory { CreateSingleImageDisplaySets = createSingleImageDisplaySets },
                PatientId = patientId,
                PatientsName = patientsName,
                StudyDescription = studyDescription,
                StudyInstanceUid = studyInstanceUid
            };

            var image1 = new ImageBuilder
                             {
                                 ImageLaterality = "U",
                                 ViewPosition = "AP",
                                 InstanceNumber = 1,
                                 SopClassUid = SopClass.DigitalXRayImageStorageForPresentationUid,
                                 PresentationIntentType = "FOR PRESENTATION"
                             };

            var image2 = new ImageBuilder
                             {
                                 ImageLaterality = "U",
                                 ViewPosition = "LL",
                                 InstanceNumber = 1,
                                 SopClassUid = SopClass.DigitalXRayImageStorageForPresentationUid,
                                 PresentationIntentType = "FOR PRESENTATION"
                             };


            if (oneSeries)
            {
                var seriesBuilder = new SeriesBuilder
                                        {
                                            Modality = "DX",
                                            SeriesDescription = seriesDescription,
                                            SeriesNumber = startSeriesNumber,
                                            Images = new List<ImageBuilder> {image1 }
                                        };

                if (!oneImagePerSeries)
                    seriesBuilder.Images.Add(image2);

                studyBuilder.Series.Add(seriesBuilder);
            }
            else
            {
                var seriesBuilder = new SeriesBuilder
                                        {
                                            Modality = "DX",
                                            SeriesDescription = seriesDescription,
                                            SeriesNumber = startSeriesNumber,
                                            Images = new List<ImageBuilder> {image1}
                                        };

                studyBuilder.Series.Add(seriesBuilder);
                
                seriesBuilder = new SeriesBuilder
                                    {
                                        Modality = "DX",
                                        SeriesDescription = seriesDescription,
                                        SeriesNumber = startSeriesNumber,
                                        Images = new List<ImageBuilder> {image2}
                                    };

                studyBuilder.Series.Add(seriesBuilder);
            }

            return studyBuilder;
        }