private static void FillSopCommonModule(IDicomAttributeProvider target, string sopClassUid)
        {
            var targetModule = new SopCommonModuleIod(target);

            targetModule.SopClassUid    = sopClassUid;
            targetModule.SopInstanceUid = DicomUid.GenerateUid().UID;
        }
Exemplo n.º 2
0
        internal static void FillDataSet(IDicomAttributeProvider dataSet, VolumeSlice slice)
        {
            // generate values for SC Equipment Module
            var scEquipment = new ScEquipmentModuleIod(dataSet);

            scEquipment.ConversionType = @"WSD";
            scEquipment.SecondaryCaptureDeviceManufacturer           = @"ClearCanvas Inc.";
            scEquipment.SecondaryCaptureDeviceManufacturersModelName = ProductInformation.GetName(false, false);
            scEquipment.SecondaryCaptureDeviceSoftwareVersions       = new[] { ProductInformation.GetVersion(true, true, true, true) };

            // generate values for the General Image Module
            dataSet[DicomTags.ImageType].SetStringValue(@"DERIVED\SECONDARY");
            dataSet[DicomTags.DerivationDescription].SetStringValue(@"Multiplanar Reformatting");
            dataSet[DicomTags.DerivationCodeSequence].Values = new[] { ImageDerivationContextGroup.MultiplanarReformatting.AsDicomSequenceItem() };

            // update the Image Plane Module
            dataSet[DicomTags.PixelSpacing].SetStringValue(slice.PixelSpacing);
            dataSet[DicomTags.ImageOrientationPatient].SetStringValue(slice.ImageOrientationPatient);
            dataSet[DicomTags.ImagePositionPatient].SetStringValue(slice.ImagePositionPatient);
            dataSet[DicomTags.SliceThickness].SetStringValue(slice.SliceThickness);

            // update the spacing between slices, even though it's only part of modality-specific modules
            dataSet[DicomTags.SpacingBetweenSlices].SetStringValue(slice.SpacingBetweenSlices);

            // update the Image Pixel Module
            dataSet[DicomTags.Rows].SetInt32(0, slice.Rows);
            dataSet[DicomTags.Columns].SetInt32(0, slice.Columns);

            // generate values for Multi-Frame Module
            dataSet[DicomTags.NumberOfFrames].SetInt32(0, 1);

            // generate values for SOP Common Module
            dataSet[DicomTags.SopClassUid].SetStringValue(SopClass.SecondaryCaptureImageStorageUid);
            dataSet[DicomTags.SopInstanceUid].SetStringValue(DicomUid.GenerateUid().UID);
        }
 public SeriesInfo(int seriesNumber)
 {
     SeriesNumber      = seriesNumber;
     SeriesDateTime    = Platform.Time;
     SeriesInstanceUid = DicomUid.GenerateUid().UID;
     SeriesDescription = "FOR KEY IMAGES";
 }
Exemplo n.º 4
0
        private static void FillDicomDataSet(DicomAttributeCollection metainfo, DicomAttributeCollection dataset)
        {
            dataset[DicomTags.PatientId].SetStringValue("PATIENT");
            dataset[DicomTags.PatientsName].SetStringValue("TEST^VTK IMAGE");
            dataset[DicomTags.StudyId].SetStringValue("STUDY");
            dataset[DicomTags.SeriesDescription].SetStringValue("SERIES");
            dataset[DicomTags.StudyInstanceUid].SetStringValue(DicomUid.GenerateUid().UID);
            dataset[DicomTags.SeriesInstanceUid].SetStringValue(DicomUid.GenerateUid().UID);
            dataset[DicomTags.SopInstanceUid].SetStringValue(DicomUid.GenerateUid().UID);
            dataset[DicomTags.SopClassUid].SetStringValue(SopClass.SecondaryCaptureImageStorageUid);
            dataset[DicomTags.FrameOfReferenceUid].SetStringValue(DicomUid.GenerateUid().UID);
            dataset[DicomTags.PixelSpacing].SetStringValue(@"1\1");
            dataset[DicomTags.PhotometricInterpretation].SetStringValue("MONOCHROME2");
            dataset[DicomTags.BitsStored].SetInt32(0, 16);
            dataset[DicomTags.BitsAllocated].SetInt32(0, 16);
            dataset[DicomTags.HighBit].SetInt32(0, 15);
            dataset[DicomTags.PixelRepresentation].SetInt32(0, 0);
            dataset[DicomTags.Rows].SetInt32(0, 100);
            dataset[DicomTags.Columns].SetInt32(0, 100);
            dataset[DicomTags.WindowCenter].SetInt32(0, 32768);
            dataset[DicomTags.WindowWidth].SetInt32(0, 65536);
            dataset[DicomTags.WindowCenterWidthExplanation].SetString(0, "Full Window");

            metainfo[DicomTags.SopInstanceUid].SetStringValue(dataset[DicomTags.SopInstanceUid].ToString());
            metainfo[DicomTags.SopClassUid].SetStringValue(dataset[DicomTags.SopClassUid].ToString());
        }
Exemplo n.º 5
0
        public void AddDuplicateImage()
        {
            IImageViewer viewer    = new ImageViewerComponent();
            StudyTree    studyTree = viewer.StudyTree;

            string studyUid1  = DicomUid.GenerateUid().UID;
            string seriesUid1 = DicomUid.GenerateUid().UID;
            string imageUid1  = DicomUid.GenerateUid().UID;

            ImageSop image1 = CreateImageSop("patient1", studyUid1, seriesUid1, imageUid1);
            ImageSop image2 = CreateImageSop("patient1", studyUid1, seriesUid1, imageUid1);

            //The sop has already silently disposed the 2nd data source.
            Assert.IsTrue(ReferenceEquals(image1.DataSource, image2.DataSource));
            studyTree.AddSop(image1);
            studyTree.AddSop(image2);

            Assert.IsTrue(studyTree.Patients["patient1"].Studies[studyUid1].Series[seriesUid1].Sops.Count == 1);

            TestDataSource dataSource = (TestDataSource)image1.DataSource;

            viewer.Dispose();

            Assert.IsTrue(dataSource.IsDisposed);
        }
Exemplo n.º 6
0
        private static DicomAttributeCollection CreateMockDataset(string patientName, string studyInstanceUid, string frameOfReferenceUid, Modality modality, int columns, int rows, bool signed, SizeF pixelSpacing)
        {
            DicomAttributeCollection dataset = new DicomAttributeCollection();

            dataset[DicomTags.PatientId].SetStringValue("PATIENT");
            dataset[DicomTags.PatientsName].SetStringValue(patientName);
            dataset[DicomTags.StudyId].SetStringValue("STUDY");
            dataset[DicomTags.SeriesDescription].SetStringValue(string.Format("SERIES-{0}", modality));
            dataset[DicomTags.StudyInstanceUid].SetStringValue(studyInstanceUid);
            dataset[DicomTags.SeriesInstanceUid].SetStringValue(DicomUid.GenerateUid().UID);
            dataset[DicomTags.SopInstanceUid].SetStringValue(DicomUid.GenerateUid().UID);
            dataset[DicomTags.SopClassUid].SetStringValue(GetSopClassUidByModality(modality));
            dataset[DicomTags.Modality].SetStringValue(modality.ToString());
            dataset[DicomTags.FrameOfReferenceUid].SetStringValue(frameOfReferenceUid);
            dataset[DicomTags.PixelSpacing].SetStringValue(string.Format(@"{0}\{1}", pixelSpacing.Height, pixelSpacing.Width));
            dataset[DicomTags.PhotometricInterpretation].SetStringValue("MONOCHROME2");
            dataset[DicomTags.BitsStored].SetInt32(0, 16);
            dataset[DicomTags.BitsAllocated].SetInt32(0, 16);
            dataset[DicomTags.HighBit].SetInt32(0, 15);
            dataset[DicomTags.PixelRepresentation].SetInt32(0, signed ? 1 : 0);
            dataset[DicomTags.Rows].SetInt32(0, rows);
            dataset[DicomTags.Columns].SetInt32(0, columns);
            dataset[DicomTags.WindowCenter].SetInt32(0, signed ? 0 : 32768);
            dataset[DicomTags.WindowWidth].SetInt32(0, 65536);
            dataset[DicomTags.WindowCenterWidthExplanation].SetString(0, "Full Window");
            return(dataset);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //CopyTest();

            openFileDialog.Filter = "DICOM|*.dcm";
            openFileDialog.ShowDialog();

            if (!File.Exists(openFileDialog.FileName))
            {
                return;
            }

            DicomFile dicomFile = new DicomFile(openFileDialog.FileName);

            dicomFile.Load();

            //dicomFile.DataSet[DicomTags.PatientsName].SetEmptyValue();
            //dicomFile.DataSet[DicomTags.PatientId].SetEmptyValue();
            dicomFile.DataSet[DicomTags.SopInstanceUid].SetStringValue(DicomUid.GenerateUid().UID);

            try
            {
                dicomFile.DataSet[DicomTags.PatientsBirthDate].SetStringValue("12/12/2009");
            }
            catch (Exception)
            {
            }

            saveFileDialog.Filter = "DICOM|*.dcm";
            if (DialogResult.OK == saveFileDialog.ShowDialog())
            {
                dicomFile.Save(saveFileDialog.FileName);
            }
        }
Exemplo n.º 8
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);
        }
 /// <summary>
 /// Initializes the attributes in this module to their default values.
 /// </summary>
 public void InitializeAttributes()
 {
     Modality          = @"DOC";
     SeriesInstanceUid = DicomUid.GenerateUid().UID;
     SeriesNumber      = 0;
     PerformedProcedureStepSummaryMacro.InitializeAttributes();
 }
Exemplo n.º 10
0
        private static DicomAttributeCollection CreateMockDataset(string patientName, int columns, int rows, bool signed)
        {
            DicomAttributeCollection dataset = new DicomAttributeCollection();

            dataset[DicomTags.PatientId].SetStringValue("PATIENT");
            dataset[DicomTags.PatientsName].SetStringValue(patientName);
            dataset[DicomTags.StudyId].SetStringValue("STUDY");
            dataset[DicomTags.SeriesDescription].SetStringValue("SERIES");
            dataset[DicomTags.StudyInstanceUid].SetStringValue(DicomUid.GenerateUid().UID);
            dataset[DicomTags.SeriesInstanceUid].SetStringValue(DicomUid.GenerateUid().UID);
            dataset[DicomTags.SopInstanceUid].SetStringValue(DicomUid.GenerateUid().UID);
            dataset[DicomTags.SopClassUid].SetStringValue(SopClass.SecondaryCaptureImageStorageUid);
            dataset[DicomTags.FrameOfReferenceUid].SetStringValue(DicomUid.GenerateUid().UID);
            dataset[DicomTags.PixelSpacing].SetStringValue(@"1\1");
            dataset[DicomTags.PhotometricInterpretation].SetStringValue("MONOCHROME2");
            dataset[DicomTags.BitsStored].SetInt32(0, 16);
            dataset[DicomTags.BitsAllocated].SetInt32(0, 16);
            dataset[DicomTags.HighBit].SetInt32(0, 15);
            dataset[DicomTags.PixelRepresentation].SetInt32(0, signed ? 1 : 0);
            dataset[DicomTags.Rows].SetInt32(0, rows);
            dataset[DicomTags.Columns].SetInt32(0, columns);
            dataset[DicomTags.WindowCenter].SetInt32(0, signed ? 0 : 32768);
            dataset[DicomTags.WindowWidth].SetInt32(0, 65536);
            dataset[DicomTags.WindowCenterWidthExplanation].SetString(0, "Full Window");
            return(dataset);
        }
Exemplo n.º 11
0
        public void StudyXmlTest()
        {
            string directory;

            using (var processor = new TestCommandProcessor())
            {
                var studyXml = new StudyXml(DicomUid.GenerateUid().UID);
                var images   = SetupMRSeries(2, 5, studyXml.StudyInstanceUid);
                directory = Path.Combine(processor.ProcessorContext.TempDirectory, "StudyXmlTest");

                DirectoryUtility.DeleteIfExists(directory);

                processor.AddCommand(new CreateDirectoryCommand(directory));

                foreach (var i in images)
                {
                    string file = Path.Combine(directory, i[DicomTags.SopInstanceUid] + ".dcm");
                    processor.AddCommand(new SaveDicomFileCommand(file, new DicomFile(file, new DicomAttributeCollection(), i), false));
                    processor.AddCommand(new InsertInstanceXmlCommand(studyXml, file));
                }

                Assert.IsTrue(processor.Execute(), processor.FailureReason);
                Assert.IsTrue((images.Count * 2 + 1) == processor.TestContext.CommandsExecuted);

                foreach (var i in images)
                {
                    Assert.IsTrue(studyXml.Contains(i[DicomTags.SeriesInstanceUid], i[DicomTags.SopInstanceUid]));
                }
                DirectoryUtility.DeleteIfExists(directory);
            }
        }
Exemplo n.º 12
0
        private void SetStudyTags()
        {
            StudyInstanceUid = DicomUid.GenerateUid().UID;

            _theFile.DataSet[DicomTags.StudyInstanceUid].SetStringValue(StudyInstanceUid);
            _theFile.DataSet[DicomTags.StudyDate].SetStringValue(DateParser.ToDicomString(StudyDate));
            _theFile.DataSet[DicomTags.StudyTime].SetStringValue(TimeParser.ToDicomString(DateTime.Now));
            _theFile.DataSet[DicomTags.PerformedProcedureStepStartDate].SetStringValue(DateParser.ToDicomString(StudyDate));
            _theFile.DataSet[DicomTags.PerformedProcedureStepStartTime].SetStringValue(TimeParser.ToDicomString(DateTime.Now));
            _theFile.DataSet[DicomTags.AccessionNumber].SetStringValue(ModalityHospital.GetNextAccession());

            _studyNumber++;
            _theFile.DataSet[DicomTags.StudyId].SetStringValue(string.Format("S{0:0000}", _studyNumber));
            _theFile.DataSet[DicomTags.ReferringPhysiciansName].SetStringValue(GetPatient());

            string name = GetPatient();

            _theFile.DataSet[DicomTags.PatientsName].SetStringValue(name);
            _theFile.DataSet[DicomTags.PatientId].SetStringValue(string.Format("{0} {1}", Math.Abs(name.GetHashCode()), ModalityHospital.Name));
            _theFile.DataSet[DicomTags.IssuerOfPatientId].SetStringValue(ModalityHospital.Name);

            DateTime birthdate = GetBirthdate(name);
            TimeSpan age       = StudyDate.Subtract(birthdate);

            _theFile.DataSet[DicomTags.PatientsBirthDate].SetStringValue(DateParser.ToDicomString(birthdate));
            _theFile.DataSet[DicomTags.PatientsAge].SetStringValue(String.Format("{0:000}Y", age.Days / 365));
            _theFile.DataSet[DicomTags.PatientsSex].SetStringValue("M");

            _theFile.DataSet[DicomTags.StudyDescription].SetStringValue(_studyDescription[Rand.Next(_studyDescription.Count)]);
        }
Exemplo n.º 13
0
            internal void OnFilmBoxCreated(DicomUid filmBoxUid, List <DicomUid> imageBoxUids)
            {
                _currentFilmBox.SopInstanceUid = filmBoxUid;

                // The SCP returns a list of imageBoxUids.  Create an imageBox for each UID.
                var imageBoxes = new List <ImageBox>();

                for (var i = 0; i < imageBoxUids.Count; i++)
                {
                    var imageBox = new ImageBox(_currentFilmBox, _printItemQueue.Dequeue())
                    {
                        ImageBoxPosition = (ushort)(i + 1),                                 // position is 1-based
                        SopInstanceUid   = imageBoxUids[i]
                    };
                    imageBoxes.Add(imageBox);

                    // No more print items.  Stop creating imageBoxes
                    if (_printItemQueue.Count == 0)
                    {
                        break;
                    }
                }

                // start setting the first imageBox
                _currentFilmBox.SetImageBoxes(imageBoxes);
                var imageBoxToSet = _currentFilmBox.GetNextImageBox();

                imageBoxToSet.BeforeSet(this.PrintScu.ColorMode);
                this.PrintScu.SetImageBox(imageBoxToSet);
                imageBoxToSet.AfterSet();
            }
Exemplo n.º 14
0
        private void RemapUidAttribute(DicomAttribute attribute)
        {
            int i = 0;

            foreach (string oldUid in (string[])attribute.Values)
            {
                if (!String.IsNullOrEmpty(oldUid))
                {
                    string newUid;
                    if (_uidMap.ContainsKey(oldUid))
                    {
                        newUid = _uidMap[oldUid];
                    }
                    else
                    {
                        newUid = DicomUid.GenerateUid().UID;
                        if (String.IsNullOrEmpty(newUid) || newUid == oldUid)
                        {
                            throw new DicomAnonymizerException("An error occurred while generating a new Uid.");
                        }

                        _uidMap[oldUid] = newUid;
                    }

                    attribute.SetString(i++, newUid);
                }
            }
        }
Exemplo n.º 15
0
        protected AssociationParameters(AssociationParameters parameters)
        {
            _appCtxNm           = parameters._appCtxNm;
            _calledAe           = parameters._calledAe;
            _callingAe          = parameters._callingAe;
            _implClass          = parameters._implClass;
            _implVersion        = parameters._implVersion;
            _localEndPoint      = parameters._localEndPoint;
            _localMaxPduLength  = parameters._localMaxPduLength;
            _remoteMaxPduLength = parameters._remoteMaxPduLength;
            _readTimeout        = parameters._readTimeout;
            _receiveBufferSize  = parameters._receiveBufferSize;
            _remoteEndPoint     = parameters._remoteEndPoint;
            _sendBufferSize     = parameters._sendBufferSize;
            _writeTimeout       = parameters._writeTimeout;
            _connectTimeout     = parameters._connectTimeout;

            foreach (byte id in parameters._presContexts.Keys)
            {
                AddPresentationContext(id, parameters._presContexts[id].AbstractSyntax);

                foreach (TransferSyntax ts in parameters._presContexts[id].GetTransfers())
                {
                    AddTransferSyntax(id, ts);
                }

                SetRoleSelect(id, parameters._presContexts[id].GetRoleSelect());
            }
        }
 private static string CreateUid(string uidHint)
 {
     if (string.IsNullOrEmpty(uidHint))
     {
         return(DicomUid.GenerateUid().UID);
     }
     return(uidHint);
 }
Exemplo n.º 17
0
        private void InitNewStudy(DateTime studyDate)
        {
            Random ran = new Random();

            AccessionNumber.Text  = String.Format("{0}{1}", (char)((int)'A' + ran.Next(26)), ran.Next(10000, 99999));
            StudyInstanceUid.Text = DicomUid.GenerateUid().UID;
            StudyDate.Text        = DateParser.ToDicomString(studyDate);
        }
Exemplo n.º 18
0
            internal void OnCreated(DicomUid filmSessionUid)
            {
                this.SopInstanceUid = filmSessionUid;

                // Move to the first element.
                _filmBoxes.Add(_currentFilmBox = _createFilmBoxCallback.Invoke(new List <IPrintItem>(_printItemQueue).AsReadOnly()));
                this.PrintScu.CreateFilmBox(this, _currentFilmBox);
            }
Exemplo n.º 19
0
        public IList <DicomAttributeCollection> SetupMRSeries(int seriesCount, int instancesPerSeries, string studyInstanceUid)
        {
            List <DicomAttributeCollection> instanceList = new List <DicomAttributeCollection>();

            DicomAttributeCollection baseCollection = new DicomAttributeCollection();

            SetupMR(baseCollection);

            baseCollection[DicomTags.StudyInstanceUid].SetStringValue(studyInstanceUid);

            int acquisitionNumber = 1;
            int instanceNumber    = 100;

            float positionX = -61.7564f;
            float positionY = -212.04848f;
            float positionZ = -99.6208f;

            float orientation1 = 0.861f;
            float orientation2 = 0.492f;
            float orientation3 = 0.126f;
            float orientation4 = -0.2965f;


            for (int i = 0; i < seriesCount; i++)
            {
                string seriesInstanceUid = DicomUid.GenerateUid().UID;

                for (int j = 0; j < instancesPerSeries; j++)
                {
                    string sopInstanceUid = DicomUid.GenerateUid().UID;
                    DicomAttributeCollection instanceCollection = baseCollection.Copy();
                    instanceCollection[DicomTags.SopInstanceUid].SetStringValue(sopInstanceUid);
                    instanceCollection[DicomTags.SeriesInstanceUid].SetStringValue(seriesInstanceUid);

                    instanceCollection[DicomTags.SeriesNumber].SetStringValue((i + 1).ToString());
                    instanceCollection[DicomTags.SeriesDescription].SetStringValue("Series" + (i + 1).ToString());

                    instanceCollection[DicomTags.AcquisitionNumber].SetStringValue(acquisitionNumber++.ToString());
                    instanceCollection[DicomTags.InstanceNumber].SetStringValue(instanceNumber++.ToString());

                    instanceCollection[DicomTags.ImagePositionPatient].SetFloat32(0, positionX);
                    instanceCollection[DicomTags.ImagePositionPatient].SetFloat32(1, positionY);
                    instanceCollection[DicomTags.ImagePositionPatient].SetFloat32(2, positionZ);
                    positionY += 0.1f;

                    instanceCollection[DicomTags.ImageOrientationPatient].SetFloat32(0, orientation1);
                    instanceCollection[DicomTags.ImageOrientationPatient].SetFloat32(1, orientation2);
                    instanceCollection[DicomTags.ImageOrientationPatient].SetFloat32(2, orientation3);
                    instanceCollection[DicomTags.ImageOrientationPatient].SetFloat32(2, orientation4);
                    orientation2 += 0.01f;

                    instanceList.Add(instanceCollection);
                }
            }

            return(instanceList);
        }
Exemplo n.º 20
0
        public PETFusionDisplaySetDescriptor(ISeriesIdentifier baseSeries, ISeriesIdentifier ptSeries, bool attenuationCorrection)
            : base(baseSeries, null)
        {
            _petSeries               = ptSeries;
            _attenuationCorrection   = attenuationCorrection;
            _fusionSeriesInstanceUid = DicomUid.GenerateUid().UID;

            IsComposite = true;
        }
        private static void TestVolume(bool signed, VolumeFunction f, IEnumerable <IVolumeSlicerParams> slicerParams, string testName, ImageKernelFunction imageKernel, VolumeKernelFunction volumeKernel)
        {
            const int      FULL_SCALE         = 65535;
            VolumeFunction normalizedFunction = f.Normalize(100);

            using (Volume volume = normalizedFunction.CreateVolume(100, signed))
            {
                float offset = signed ? -32768 : 0;
                foreach (IVolumeSlicerParams slicing in slicerParams)
                {
                    List <double> list = new List <double>();
                    using (VolumeSlicer slicer = new VolumeSlicer(volume, slicing, DicomUid.GenerateUid().UID))
                    {
                        foreach (ISopDataSource slice in slicer.CreateSlices())
                        {
                            using (ImageSop imageSop = new ImageSop(slice))
                            {
                                foreach (IPresentationImage image in PresentationImageFactory.Create(imageSop))
                                {
                                    IImageSopProvider     imageSopProvider     = (IImageSopProvider)image;
                                    IImageGraphicProvider imageGraphicProvider = (IImageGraphicProvider)image;
                                    DicomImagePlane       dip = DicomImagePlane.FromImage(image);

                                    for (int y = 1; y < imageSopProvider.Frame.Rows - 1; y++)
                                    {
                                        for (int x = 1; x < imageSopProvider.Frame.Columns - 1; x++)
                                        {
                                            // pixels on the extreme sides of the volume tend to have more interpolation error due to MPR padding values
                                            Vector3D vector = dip.ConvertToPatient(new PointF(x, y));                                             // +new Vector3D(-0.5f, -0.5f, 0);
                                            if (Between(vector.X, 1, 98) && Between(vector.Y, 1, 98) && Between(vector.Z, 1, 98))
                                            {
                                                float expected = volumeKernel.Invoke(normalizedFunction, vector.X, vector.Y, vector.Z) + offset;
                                                float actual   = imageKernel.Invoke(imageGraphicProvider.ImageGraphic.PixelData, x, y);
                                                list.Add(Math.Abs(expected - actual));
                                            }
                                        }
                                    }

                                    image.Dispose();
                                }
                            }
                            slice.Dispose();
                        }
                    }

                    Statistics stats = new Statistics(list);
                    Trace.WriteLine(string.Format("Testing {0}", testName));
                    Trace.WriteLine(string.Format("\tFunction/Slicing: {0} / {1}", normalizedFunction.Name, slicing.Description));
                    Trace.WriteLine(string.Format("\t       Pixel Rep: {0}", signed ? "signed" : "unsigned"));
                    Trace.WriteLine(string.Format("\t Voxels Compared: {0}", list.Count));
                    Trace.WriteLine(string.Format("\t      Mean Delta: {0:f2} ({1:p2} of full scale)", stats.Mean, stats.Mean / FULL_SCALE));
                    Trace.WriteLine(string.Format("\t    StdDev Delta: {0:f2} ({1:p2} of full scale)", stats.StandardDeviation, stats.StandardDeviation / FULL_SCALE));
                    Assert.Less(stats.Mean, FULL_SCALE * 0.05, "Mean delta exceeds 5% of full scale ({0})", FULL_SCALE);
                    Assert.Less(stats.StandardDeviation, FULL_SCALE * 0.05, "StdDev delta exceeds 5% of full scale ({0})", FULL_SCALE);
                }
            }
        }
Exemplo n.º 22
0
        private void SendCreateFilmSessionRequest(DicomClient client, ClientAssociationParameters association)
        {
            DicomMessage newRequestMessage = new DicomMessage(null, (DicomAttributeCollection)_basicFilmSessionModuleIod.DicomAttributeProvider);

            byte pcid = association.FindAbstractSyntaxOrThrowException(SopClass.BasicGrayscalePrintManagementMetaSopClass);

            _nextRequestType = RequestType.FilmBox;
            client.SendNCreateRequest(DicomUid.GenerateUid(), pcid, client.NextMessageID(), newRequestMessage, DicomUids.BasicFilmSession);
        }
Exemplo n.º 23
0
 public SeriesInfo(IImageSopProvider provider)
 {
     KeyObjectSeriesUid              = DicomUid.GenerateUid().UID;
     KeyObjectSeriesNumber           = CalculateSeriesNumber(provider.Frame);
     KeyObjectSeriesDateTime         = Platform.Time;
     PresentationSeriesUid           = DicomUid.GenerateUid().UID;
     PresentationSeriesNumber        = KeyObjectSeriesNumber + 1;
     PresentationSeriesDateTime      = Platform.Time;
     _presentationNextInstanceNumber = 1;
 }
        private void InitNewStudy()
        {
            Random ran = new Random();

            AccessionNumber.Text  = String.Format("{0}{1}", (char)((int)'A' + ran.Next(26)), ran.Next(10000, 99999));
            StudyInstanceUid.Text = DicomUid.GenerateUid().UID;
            StudyDate.Text        = ran.Next() % 10 == 0
                               ? ""
                               : DateParser.ToDicomString(new DateTime(1990, 1, 1).AddDays(ran.Next(0, 5000)));
        }
Exemplo n.º 25
0
        private static ISopDataSource CreateMockDataset(string modality, SopClass sopClass, SizeF?imagerPixelSpacing, SizeF?pixelSpacing, string pixelSpacingCalibrationType, string pixelSpacingCalibrationDescription, double?estimatedRadiographicMagnification)
        {
            var dicomFile = new DicomFile();
            var dataset   = dicomFile.DataSet;

            dataset[DicomTags.PatientId].SetStringValue("PATIENT");
            dataset[DicomTags.PatientsName].SetStringValue("YOSHI");
            dataset[DicomTags.StudyId].SetStringValue("STUDY");
            dataset[DicomTags.SeriesDescription].SetStringValue("SERIES");
            dataset[DicomTags.StudyInstanceUid].SetStringValue(DicomUid.GenerateUid().UID);
            dataset[DicomTags.SeriesInstanceUid].SetStringValue(DicomUid.GenerateUid().UID);
            dataset[DicomTags.Modality].SetStringValue(modality);
            dataset[DicomTags.SopInstanceUid].SetStringValue(DicomUid.GenerateUid().UID);
            dataset[DicomTags.SopClassUid].SetStringValue(sopClass.Uid);
            dataset[DicomTags.FrameOfReferenceUid].SetStringValue(DicomUid.GenerateUid().UID);
            dataset[DicomTags.PhotometricInterpretation].SetStringValue("MONOCHROME2");
            dataset[DicomTags.BitsStored].SetInt32(0, 16);
            dataset[DicomTags.BitsAllocated].SetInt32(0, 16);
            dataset[DicomTags.HighBit].SetInt32(0, 15);
            dataset[DicomTags.PixelRepresentation].SetInt32(0, 0);
            dataset[DicomTags.Rows].SetInt32(0, 100);
            dataset[DicomTags.Columns].SetInt32(0, 100);
            dataset[DicomTags.WindowCenter].SetInt32(0, 32768);
            dataset[DicomTags.WindowWidth].SetInt32(0, 65536);
            dataset[DicomTags.WindowCenterWidthExplanation].SetString(0, "Full Window");

            if (imagerPixelSpacing.HasValue)
            {
                dataset[DicomTags.ImagerPixelSpacing].SetFloat32(0, imagerPixelSpacing.Value.Height);
                dataset[DicomTags.ImagerPixelSpacing].SetFloat32(1, imagerPixelSpacing.Value.Width);
            }

            if (pixelSpacing.HasValue)
            {
                dataset[DicomTags.PixelSpacing].SetFloat32(0, pixelSpacing.Value.Height);
                dataset[DicomTags.PixelSpacing].SetFloat32(1, pixelSpacing.Value.Width);
            }

            if (!string.IsNullOrEmpty(pixelSpacingCalibrationType))
            {
                dataset[DicomTags.PixelSpacingCalibrationType].SetStringValue(pixelSpacingCalibrationType);
            }

            if (!string.IsNullOrEmpty(pixelSpacingCalibrationDescription))
            {
                dataset[DicomTags.PixelSpacingCalibrationDescription].SetStringValue(pixelSpacingCalibrationDescription);
            }

            if (estimatedRadiographicMagnification.HasValue)
            {
                dataset[DicomTags.EstimatedRadiographicMagnificationFactor].SetFloat64(0, estimatedRadiographicMagnification.Value);
            }

            return(new TestDataSource(dicomFile));
        }
        internal VolumeSliceSopDataSource(IVolumeReference volumeReference, IVolumeSlicerParams slicerParams, IList <Vector3D> throughPoints)
        {
            Platform.CheckForNullReference(throughPoints, "throughPoints");
            Platform.CheckTrue(throughPoints.Count > 0, "At least one through point must be specified.");
            var volume = volumeReference.Volume;

            _volumeReference     = volumeReference;
            _slicerParams        = slicerParams;
            _resliceMatrix       = new Matrix(slicerParams.SlicingPlaneRotation);
            _resliceMatrix[3, 0] = throughPoints[0].X;
            _resliceMatrix[3, 1] = throughPoints[0].Y;
            _resliceMatrix[3, 2] = throughPoints[0].Z;
            _throughPoints       = new List <Vector3D>(throughPoints).AsReadOnly();

            // keep a direct reference to the prototype, so that attribute values are available even if the referenced volume is unloaded via memory management
            _prototypeDataSet = volume.DataSet;

            _instanceDataSet = new DicomAttributeCollection();

            // JY: ideally, each slicing plane is represented by a single multiframe SOP where the individual slices are the frames.
            // We need to support multi-valued Slice Location in the base viewer first.
            // When that is implemented, the SOPs should be created on the first frame of the slicing (i.e. one of the end slices)
            // and the Slice Location Vector will simply store the slice locations relative to that defined in these attributes.
            // Also, the rows and columns will have to be computed to be the MAX possible size (all frames must have same size)

            // assign Rows and Columns to reflect actual output size
            Size frameSize = GetSliceExtent(volume, slicerParams);

            _instanceDataSet[DicomTags.Columns].SetInt32(0, frameSize.Width);
            _instanceDataSet[DicomTags.Rows].SetInt32(0, frameSize.Height);

            // assign Image Orientation (Patient)
            Matrix resliceAxesPatientOrientation = _volumeReference.Volume.RotateToPatientOrientation(_resliceMatrix);

            _instanceDataSet[DicomTags.ImageOrientationPatient].SetFloat32(0, resliceAxesPatientOrientation[0, 0]);
            _instanceDataSet[DicomTags.ImageOrientationPatient].SetFloat32(1, resliceAxesPatientOrientation[0, 1]);
            _instanceDataSet[DicomTags.ImageOrientationPatient].SetFloat32(2, resliceAxesPatientOrientation[0, 2]);
            _instanceDataSet[DicomTags.ImageOrientationPatient].SetFloat32(3, resliceAxesPatientOrientation[1, 0]);
            _instanceDataSet[DicomTags.ImageOrientationPatient].SetFloat32(4, resliceAxesPatientOrientation[1, 1]);
            _instanceDataSet[DicomTags.ImageOrientationPatient].SetFloat32(5, resliceAxesPatientOrientation[1, 2]);

            // assign Image Position (Patient)
            Vector3D topLeftOfSlicePatient = GetTopLeftOfSlicePatient(frameSize, throughPoints[0], volume, slicerParams);

            _instanceDataSet[DicomTags.ImagePositionPatient].SetFloat32(0, topLeftOfSlicePatient.X);
            _instanceDataSet[DicomTags.ImagePositionPatient].SetFloat32(1, topLeftOfSlicePatient.Y);
            _instanceDataSet[DicomTags.ImagePositionPatient].SetFloat32(2, topLeftOfSlicePatient.Z);

            // assign Number of Frames
            _instanceDataSet[DicomTags.NumberOfFrames].SetInt32(0, throughPoints.Count);

            // assign a new SOP instance UID
            _instanceDataSet[DicomTags.SopInstanceUid].SetString(0, DicomUid.GenerateUid().UID);
        }
Exemplo n.º 27
0
        private void SetSopTags( )
        {
            EnsureTagsSet();

            _theFile.MetaInfo[DicomTags.SourceApplicationEntityTitle].SetStringValue(String.Format("{0}_{1}", ModalityHospital.Name, Modality));
            _theFile.DataSet[DicomTags.SpecificCharacterSet].SetStringValue("ISO_IR 100");
            _theFile.DataSet[DicomTags.SopClassUid].SetStringValue(SopClassUid);

            _theFile.DataSet[DicomTags.SopInstanceUid].SetStringValue(DicomUid.GenerateUid().UID);
            _theFile.DataSet[DicomTags.SopClassUid].SetStringValue(SopClassUid);
        }
Exemplo n.º 28
0
        public ISopDataSource[] CreateSops(bool signed, Modality modality, Vector3D voxelSpacing, Vector3D sliceAxisX, Vector3D sliceAxisY, Vector3D sliceAxisZ)
        {
            var seriesInstanceUid = DicomUid.GenerateUid().UID;
            var slicerParams      = new VolumeSlicerParams(sliceAxisX, sliceAxisY, sliceAxisZ);
            var volume            = CreateVolume(signed, modality, voxelSpacing);

            using (VolumeSlicer slicer = new VolumeSlicer(volume, slicerParams, seriesInstanceUid))
            {
                return(new List <ISopDataSource>(slicer.CreateSlices()).ToArray());
            }
        }
Exemplo n.º 29
0
        public void StorageScuMoveOriginatorTest()
        {
            int port = 2112;

            _serverHandlerList.Clear();

            /* Setup the Server */
            var  serverParameters = new ServerAssociationParameters("AssocTestServer", new IPEndPoint(IPAddress.Any, port));
            byte pcid             = serverParameters.AddPresentationContext(SopClass.MrImageStorage);

            serverParameters.AddTransferSyntax(pcid, TransferSyntax.ExplicitVrLittleEndian);
            serverParameters.AddTransferSyntax(pcid, TransferSyntax.ExplicitVrBigEndian);
            serverParameters.AddTransferSyntax(pcid, TransferSyntax.ImplicitVrLittleEndian);

            _serverType = TestTypes.Receive;
            DicomServer.StartListening(serverParameters, ServerHandlerCreator);

            string     moveOriginatorAe = "ORIGINATOR";
            ushort     moveOriginatorId = 999;
            StorageScu scu = SetupScu(moveOriginatorAe, moveOriginatorId);

            IList <DicomAttributeCollection> list = SetupMRSeries(4, 2, DicomUid.GenerateUid().UID);

            foreach (DicomAttributeCollection collection in list)
            {
                var file = new DicomFile("test", new DicomAttributeCollection(), collection)
                {
                    TransferSyntax             = TransferSyntax.ExplicitVrLittleEndian,
                    MediaStorageSopClassUid    = SopClass.MrImageStorage.Uid,
                    MediaStorageSopInstanceUid = collection[DicomTags.SopInstanceUid].ToString()
                };

                scu.AddStorageInstance(new StorageInstance(file));
            }

            scu.Send();
            scu.Join();

            Assert.AreEqual(scu.Status, ScuOperationStatus.NotRunning);

            var handler       = CollectionUtils.FirstElement(_serverHandlerList);
            var serverHandler = handler as ServerHandler;

            Assert.NotNull(serverHandler);

            foreach (var message in serverHandler.MessagesReceived)
            {
                Assert.AreEqual(message.MoveOriginatorApplicationEntityTitle, moveOriginatorAe);
                Assert.AreEqual(message.MoveOriginatorMessageId, moveOriginatorId);
            }

            // StopListening
            DicomServer.StopListening(serverParameters);
        }
Exemplo n.º 30
0
        private static ISopDataSource CreateSopDataSource()
        {
            var uid = DicomUid.GenerateUid().UID;
            var dcf = new DicomFile();

            dcf.MediaStorageSopInstanceUid = uid;
            dcf.MediaStorageSopClassUid    = DicomUids.SecondaryCaptureImageStorage.UID;
            dcf.DataSet[DicomTags.SopInstanceUid].SetStringValue(uid);
            dcf.DataSet[DicomTags.SopClassUid].SetStringValue(DicomUids.SecondaryCaptureImageStorage.UID);
            return(new TestDataSource(dcf));
        }
Exemplo n.º 31
0
		/// <summary>
		/// Sends an N-Create Request.
		/// </summary>
		/// <param name="affectedSopInstanceUid">The affected sop instance uid.</param>
		/// <param name="presentationID">The presentation ID.</param>
		/// <param name="messageID">The message ID.</param>
		/// <param name="message">The message.</param>
		/// <param name="affectedClass">The affected class.</param>
		public void SendNCreateRequest(DicomUid affectedSopInstanceUid, byte presentationID, ushort messageID, DicomMessage message, DicomUid affectedClass)
		{
			if (message.DataSet.IsEmpty())
				throw new DicomException("Unexpected empty DataSet when sending N-CREATE-RQ.");

			if (affectedClass == null)
				affectedClass = _assoc.GetAbstractSyntax(presentationID);

			message.CommandSet[DicomTags.AffectedSopClassUid].SetStringValue(affectedClass.UID);
			message.CommandSet[DicomTags.MessageId].SetUInt16(0, messageID);
			message.CommandSet[DicomTags.CommandField].SetUInt16(0, (ushort) DicomCommandField.NCreateRequest);
			message.CommandSet[DicomTags.DataSetType].SetUInt16(0, 0x0102);

			if (affectedSopInstanceUid != null)
				message.CommandSet[DicomTags.AffectedSopInstanceUid].SetStringValue(affectedSopInstanceUid.UID);

			SendDimse(presentationID, message.CommandSet, message.DataSet);
		}
Exemplo n.º 32
0
		/// <summary>
		/// Sends an N-Create request, affected class is the one associated with the <paramref name="presentationID"/>.
		/// </summary>
		/// <param name="affectedSopInstanceUid">The affected sop instance uid.</param>
		/// <param name="presentationID">The presentation ID.</param>
		/// <param name="messageID">The message ID.</param>
		/// <param name="message">The message.</param>
		public void SendNCreateRequest(DicomUid affectedSopInstanceUid, byte presentationID, ushort messageID, DicomMessage message)
		{
			SendNCreateRequest(affectedSopInstanceUid, presentationID, messageID, message, null);
		}
Exemplo n.º 33
0
		/// <summary>
		/// Sends an N-Get request.
		/// </summary>
		/// <param name="requestedSopInstanceUid">The requested sop instance uid.</param>
		/// <param name="presentationID">The presentation ID.</param>
		/// <param name="messageID">The message ID.</param>
		/// <param name="message">The message.</param>
		public void SendNGetRequest(DicomUid requestedSopInstanceUid, byte presentationID, ushort messageID, DicomMessage message)
		{
			if (message.DataSet.IsEmpty())
				throw new DicomException("Unexpected empty DataSet when sending N-GET-RQ.");

			DicomUid affectedClass = _assoc.GetAbstractSyntax(presentationID);

			message.AffectedSopClassUid = affectedClass.UID;
			message.MessageId = messageID;
			message.CommandField = DicomCommandField.NGetRequest;
			message.DataSetType = 0x0102;

			message.CommandSet[DicomTags.RequestedSopClassUid].SetStringValue(affectedClass.UID);
			message.CommandSet[DicomTags.RequestedSopInstanceUid].SetStringValue(requestedSopInstanceUid.UID);


			SendDimse(presentationID, message.CommandSet, message.DataSet);
		}
Exemplo n.º 34
0
			internal void OnFilmBoxCreated(DicomUid filmBoxUid, List<DicomUid> imageBoxUids)
			{
				_currentFilmBox.SopInstanceUid = filmBoxUid;

				// The SCP returns a list of imageBoxUids.  Create an imageBox for each UID.
				var imageBoxes = new List<ImageBox>();
				for (var i = 0; i < imageBoxUids.Count; i++)
				{
					var imageBox = new ImageBox(_currentFilmBox, _printItemQueue.Dequeue())
						{
							ImageBoxPosition = (ushort) (i+1),  // position is 1-based
							SopInstanceUid = imageBoxUids[i]
						};
					imageBoxes.Add(imageBox);

					// No more print items.  Stop creating imageBoxes
					if (_printItemQueue.Count == 0)
						break;
				}

				// start setting the first imageBox
				_currentFilmBox.SetImageBoxes(imageBoxes);
				var imageBoxToSet = _currentFilmBox.GetNextImageBox();
				imageBoxToSet.BeforeSet(this.PrintScu.ColorMode);
				this.PrintScu.SetImageBox(imageBoxToSet);
				imageBoxToSet.AfterSet();
			}
Exemplo n.º 35
0
			internal void OnCreated(DicomUid filmSessionUid)
			{
				this.SopInstanceUid = filmSessionUid;

				// Move to the first element.
				_filmBoxes.Add(_currentFilmBox = _createFilmBoxCallback.Invoke(new List<IPrintItem>(_printItemQueue).AsReadOnly()));
				this.PrintScu.CreateFilmBox(this, _currentFilmBox);
			}
Exemplo n.º 36
0
        protected AssociationParameters(AssociationParameters parameters)
        {
            _appCtxNm = parameters._appCtxNm;
            _calledAe = parameters._calledAe;
            _callingAe = parameters._callingAe;
            _implClass = parameters._implClass;
            _implVersion = parameters._implVersion;
            _localEndPoint = parameters._localEndPoint;
            _localMaxPduLength = parameters._localMaxPduLength;
            _remoteMaxPduLength = parameters._remoteMaxPduLength;
            _readTimeout = parameters._readTimeout;
            _receiveBufferSize = parameters._receiveBufferSize;
            _remoteEndPoint = parameters._remoteEndPoint;
            _sendBufferSize = parameters._sendBufferSize;
            _writeTimeout = parameters._writeTimeout;
            _connectTimeout = parameters._connectTimeout;

            foreach (byte id in parameters._presContexts.Keys)
            {
                AddPresentationContext(id,parameters._presContexts[id].AbstractSyntax);

                foreach (TransferSyntax ts in parameters._presContexts[id].GetTransfers())
                {
                    AddTransferSyntax(id,ts);
                }

                SetRoleSelect(id, parameters._presContexts[id].GetRoleSelect());

            }
        }
Exemplo n.º 37
0
		internal void AddPresentationContext(byte pcid, DicomUid abstractSyntax, TransferSyntax transferSyntax, DicomPresContextResult result) {
			_presContexts.Add(pcid, new DicomPresContext(pcid, SopClass.GetSopClass(abstractSyntax.UID), transferSyntax, result));
		}
Exemplo n.º 38
0
            public void TestSet()
            {
                DicomAttributeUI attrib;

                #region set string
                attrib = CreateAttribute();
                attrib.SetStringValue("1.2.455.33.54");
                Assert.AreEqual(1, attrib.Count);
                Assert.AreEqual("1.2.455.33.54".Length+1, attrib.StreamLength);

                attrib.SetStringValue("1.2.455.33.54\\1.2.455.33.54.309393");
                Assert.AreEqual(2, attrib.Count);
                Assert.AreEqual("1.2.455.33.54\\1.2.455.33.54.309393".Length, attrib.StreamLength);

                attrib = CreateAttribute();
                attrib.SetString(0, "1.2.455.33.54");
                Assert.AreEqual(1, attrib.Count);
                Assert.AreEqual("1.2.455.33.54".Length+1, attrib.StreamLength);

                attrib.SetString(1, "1.2.455.33.54.309393");
                Assert.AreEqual(2, attrib.Count);
                Assert.AreEqual("1.2.455.33.54\\1.2.455.33.54.309393".Length, attrib.StreamLength);

                // special case: invalid index
                attrib = CreateAttribute();
                try
                {
                    attrib.SetString(10, "1.1.1.1");
                    Assert.Fail("Above statement should throw exception");
                }
                catch (IndexOutOfRangeException e)
                {

                }
                
                // special case: set null
                attrib = CreateAttribute();
                attrib.SetString(0, "1.2.455.33.54.309393");
                Assert.AreEqual(1, attrib.Count); 
                attrib.SetStringValue(null);
                Assert.AreEqual(1, attrib.Count);
                Assert.AreEqual(0, attrib.StreamLength);


                attrib = CreateAttribute(); 
                attrib.SetString(0, "1.2.455.33.54.309393");
                Assert.AreEqual(1, attrib.Count);
                attrib.SetString(1, null);
                Assert.AreEqual(2, attrib.Count);
                Assert.AreEqual("1.2.455.33.54.309393\\".Length + 1, attrib.StreamLength);
 
                
                #endregion

                #region Set dicomui
                attrib = CreateAttribute();
                DicomUid ui = new DicomUid("1.2.455.33.54.309393", "Some Description", UidType.SOPInstance);
                attrib.SetUid(0, ui);
                Assert.AreEqual(1, attrib.Count);
                Assert.AreEqual("1.2.455.33.54.309393".Length , attrib.StreamLength);


                ui = new DicomUid("1.2.455.33.54.123091823", "Some Description", UidType.SOPClass);
                attrib.SetUid(1, ui);
                Assert.AreEqual(2, attrib.Count);
                Assert.AreEqual("1.2.455.33.54.309393\\1.2.455.33.54.123091823".Length, attrib.StreamLength);

                // special case: invalid index
                try
                {
                    attrib.SetUid(10, ui);
                    Assert.Fail("Above statement should throw exception");
                }
                catch (IndexOutOfRangeException e)
                {
                }
                #endregion



            }
Exemplo n.º 39
0
            public void TestAppend()
            {
                DicomAttributeUI attrib ;

                #region append string
                attrib = CreateAttribute();
                attrib.AppendString("1.2.455.33.54.123091823");
                Assert.AreEqual(1, attrib.Count);
                Assert.AreEqual("1.2.455.33.54.123091823".Length+1, attrib.StreamLength);
                
                attrib.AppendString("1.2.455.33.54.309393");
                Assert.AreEqual(2, attrib.Count);
                Assert.AreEqual("1.2.455.33.54.123091823\\1.2.455.33.54.309393".Length, attrib.StreamLength);
                
                // special case: append null
                attrib.AppendString(null);
                Assert.AreEqual(3, attrib.Count);
                Assert.AreEqual("1.2.455.33.54.123091823\\1.2.455.33.54.309393\\".Length+1, attrib.StreamLength);
                

                #endregion

                #region append dicom uid
                attrib = CreateAttribute();
                DicomUid ui = new DicomUid("1.2.455.33.54.123091823", "Some Description", UidType.SOPInstance);
                attrib.AppendUid(ui);
                Assert.AreEqual(1, attrib.Count );
                Assert.AreEqual("1.2.455.33.54.123091823".Length+1, attrib.StreamLength);
                
                ui = new DicomUid("1.2.455.33.54.123123213", "Some Description", UidType.SOPInstance);
                attrib.AppendUid(ui);
                Assert.AreEqual(2, attrib.Count);
                Assert.AreEqual("1.2.455.33.54.123091823\\1.2.455.33.54.123123213".Length+1, attrib.StreamLength);
                
                #endregion

            }
Exemplo n.º 40
0
		protected AssociationParameters(String callingAE, String calledAE, IPEndPoint localEndPoint, IPEndPoint remoteEndPoint) {
			_appCtxNm = DicomUids.DICOMApplicationContextName;
			_implClass = DicomImplementation.ClassUID;
			_implVersion = DicomImplementation.Version;
			_presContexts = new SortedList<byte, DicomPresContext>();

            _calledAe = calledAE;
            _callingAe = callingAE;

            _localEndPoint = localEndPoint;
            _remoteEndPoint = remoteEndPoint;

            _totalBytesRead = 0;
            _totalDimseReceived = 0;
		}
Exemplo n.º 41
0
			internal void OnImageBoxSet(DicomUid imageBoxUid)
			{
				var imageBoxToSet = _currentFilmBox.GetNextImageBox();
				if (imageBoxToSet == null)
				{
					// No more imageBox to set.  Print the filmBox.
					this.PrintScu.PrintFilmBox(_currentFilmBox);
				}
				else
				{
					imageBoxToSet.BeforeSet(this.PrintScu.ColorMode);
					this.PrintScu.SetImageBox(imageBoxToSet);
					imageBoxToSet.AfterSet();
				}
			}
Exemplo n.º 42
0
		/// <summary>
		/// Called when received response message.
		/// </summary>
		/// <param name="client">The client.</param>
		/// <param name="association">The association.</param>
		/// <param name="presentationID">The presentation ID.</param>
		/// <param name="message">The message.</param>
		public override void OnReceiveResponseMessage(DicomClient client, ClientAssociationParameters association, byte presentationID, DicomMessage message)
		{
			try
			{
				this.ResultStatus = message.Status.Status;
				switch (this.ResultStatus)
				{
					case DicomState.Cancel:
					case DicomState.Pending:
					case DicomState.Failure:
						Platform.Log(LogLevel.Error, string.Format("{0} status received in Print Scu response message", message.Status.Status));

						this.FailureDescription = SR.MessagePrinterError;
						this.ReleaseConnection(client);
						return;

					case DicomState.Warning:
						Platform.Log(LogLevel.Warn, string.Format("{0} status received in Print Scu response message", message.Status.Status));
						break;

					case DicomState.Success:
						break;
				}

				EventsHelper.Fire(this.ProgressUpdated, this, new ProgressUpdateEventArgs(_numberOfImageBoxesSent));

				if (Canceled)
				{
					Platform.Log(LogLevel.Info, "Cancel requested by user.  Closing association.");
					client.SendAssociateAbort(DicomAbortSource.ServiceUser, DicomAbortReason.NotSpecified);
					return;
				}

				Platform.Log(LogLevel.Info, "Success status received in Print Scu");

				var affectedUid = new DicomUid(message.AffectedSopInstanceUid, "Instance UID", UidType.SOPInstance);

				switch (message.CommandField)
				{
					case DicomCommandField.NCreateResponse:
						switch (_eventObject)
						{
							case EventObject.FilmSession:
								_filmSession.OnCreated(affectedUid);
								break;
							case EventObject.FilmBox:
								{
									var responseFilmBoxModule = new BasicFilmBoxModuleIod(message.DataSet);
									_filmSession.OnFilmBoxCreated(affectedUid,
										CollectionUtils.Map<ReferencedInstanceSequenceIod, DicomUid>(
											responseFilmBoxModule.ReferencedImageBoxSequenceList,
											imageBoxModule => new DicomUid(imageBoxModule.ReferencedSopInstanceUid, "Instance UID", UidType.SOPInstance)
										));
								}
								break;
						}

						break;

					case DicomCommandField.NDeleteResponse:
						switch (_eventObject)
						{
							case EventObject.FilmSession:
								_filmSession.OnDeleted();
								this.ReleaseConnection(client);
								break;
							case EventObject.FilmBox:
								_filmSession.OnFilmBoxDeleted();
								break;
						}

						break;

					case DicomCommandField.NSetResponse:
						_numberOfImageBoxesSent++;
						_filmSession.OnImageBoxSet(affectedUid);
						break;

					case DicomCommandField.NActionResponse:
						_filmSession.OnFilmBoxPrinted(affectedUid);

						break;
					default:
						break;
				}
			}
			catch (Exception ex)
			{
				this.FailureDescription = ex.Message;
				Platform.Log(LogLevel.Error, ex.ToString());
				ReleaseConnection(client);
				throw;
			}
		}
Exemplo n.º 43
0
			internal void OnFilmBoxPrinted(DicomUid filmBoxUid)
			{
				this.PrintScu.DeleteFilmBox(_currentFilmBox);
			}
Exemplo n.º 44
0
		/// <summary>
		/// Sends an N-Create Request.
		/// </summary>
		/// <param name="affectedSopInstanceUid">The affected sop instance uid.</param>
		/// <param name="presentationID">The presentation ID.</param>
		/// <param name="messageID">The message ID.</param>
		/// <param name="message">The message.</param>
		/// <param name="affectedClass">The affected class.</param>
		public void SendNCreateRequest(DicomUid affectedSopInstanceUid, byte presentationID, ushort messageID, DicomMessage message, DicomUid affectedClass)
		{
			if (message.DataSet.IsEmpty())
				throw new DicomException("Unexpected empty DataSet when sending N-CREATE-RQ.");

			if (affectedClass == null)
				affectedClass = _assoc.GetAbstractSyntax(presentationID);

			message.AffectedSopClassUid = affectedClass.UID;
			message.MessageId = messageID;
			message.CommandField = DicomCommandField.NCreateRequest;
			if (!message.CommandSet.Contains(DicomTags.Priority))
				message.Priority = DicomPriority.Medium;
			message.DataSetType = 0x0202;

			if (affectedSopInstanceUid != null)
				message.AffectedSopInstanceUid = affectedSopInstanceUid.UID;

			SendDimse(presentationID, message.CommandSet, message.DataSet);
		}
Exemplo n.º 45
0
            public void TestGet()
            {
                DicomAttributeUI attrib;
                #region Get string
                string stringVal;

                attrib = CreateAttribute();
                attrib.SetStringValue("1.2.4.5.6.87.8.121\\1.3.54.3.54.5");
                Assert.AreEqual(2, attrib.Count);
                
                Assert.IsTrue(attrib.TryGetString(0, out stringVal));
                Assert.AreEqual("1.2.4.5.6.87.8.121", stringVal);
                Assert.AreEqual( "1.2.4.5.6.87.8.121", attrib.GetString(0, ""));

                Assert.IsTrue(attrib.TryGetString(1, out stringVal));
                Assert.AreEqual("1.3.54.3.54.5", stringVal);
                Assert.AreEqual("1.3.54.3.54.5", attrib.GetString(1, ""));

                // set using dicomui
                attrib = CreateAttribute();
                DicomUid ui = new DicomUid("1.2.455.33.54.123091823", "Some Description", UidType.SOPInstance);
                attrib.AppendUid(ui);
                Assert.AreEqual(1, attrib.Count);

                Assert.IsTrue(attrib.TryGetString(0, out stringVal));
                Assert.AreEqual("1.2.455.33.54.123091823", stringVal);
                Assert.AreEqual("1.2.455.33.54.123091823", attrib.GetString(0, ""));



                // special case: invalid index
                Assert.IsTrue(attrib.TryGetString(10, out stringVal)==false);
                Assert.AreEqual("", attrib.GetString(10, ""));



                #endregion

                #region Get to dicom uid
                DicomUid uiVal;

                attrib = CreateAttribute();
                attrib.SetString(0, "1.2.840.10008.5.1.4.1.1.6.1");
                Assert.AreEqual(1, attrib.Count);
                Assert.IsTrue(attrib.TryGetUid(0, out uiVal));
                Assert.AreEqual(SopClass.UltrasoundImageStorage.DicomUid, attrib.GetUid(0, null));

                // special case: invalid index
                Assert.IsTrue(attrib.TryGetUid(10, out uiVal) == false);
                Assert.AreEqual(null, attrib.GetUid(10, null));

                // special case: set null
                attrib = CreateAttribute();
                attrib.SetString(0, null);
                Assert.AreEqual(1, attrib.Count);
                Assert.IsTrue(attrib.TryGetUid(0, out uiVal)==true); // empty UI, should return true
                Assert.AreEqual(null, uiVal);
                Assert.AreEqual(null, attrib.GetUid(0, null));

                

                #endregion

            }