public DcmDataset Clone() { DcmDataset dataset = new DcmDataset(StreamPosition, StreamLength, InternalTransferSyntax); foreach (DcmItem item in Elements) { dataset.AddItem(item.Clone()); } dataset.UserState = UserState; return dataset; }
private static void Save(XElement parent, DcmDataset dataset) { foreach (XElement attr in parent.Elements("attr")) { DicomTag tag = DicomTag.Parse(attr.Attribute("tag").Value); DicomVR vr = DicomVR.Lookup(attr.Attribute("vr").Value); int len = int.Parse(attr.Attribute("len").Value, CultureInfo.InvariantCulture); if (vr == DicomVR.SQ) { DcmItemSequence seq = new DcmItemSequence(tag); foreach (XElement itm in attr.Elements("item")) { DcmItemSequenceItem item = new DcmItemSequenceItem(); Save(itm, item.Dataset); seq.AddSequenceItem(item); } dataset.AddItem(seq); } else if (len == -1) { DcmFragmentSequence seq = new DcmFragmentSequence(tag, vr); bool first = true; foreach (XElement itm in attr.Elements("item")) { if (first) { SaveFragmentOffsetTable(itm, seq); first = false; } else { SaveFragmentItem(itm, seq); } } dataset.AddItem(seq); } else { DcmElement element = DcmElement.Create(tag, vr); element.SetValueString(attr.FirstText()); dataset.AddItem(element); } } }
protected override void OnReceiveNGetRequest(byte presentationID, ushort messageID, DicomUID requestedClass, DicomUID requestedInstance, DicomTag[] attributes) { if (requestedClass == DicomUID.PrinterSOPClass && requestedInstance == DicomUID.PrinterSOPInstance) { DcmDataset ds = new DcmDataset(DicomTransferSyntax.ImplicitVRLittleEndian); ds.AddElementWithValue(DicomTags.PrinterStatus, "NORMAL"); ds.AddElementWithValue(DicomTags.PrinterStatus, "NORMAL"); ds.AddElementWithValue(DicomTags.PrinterName, _config.PrinterName); ds.AddElementWithValue(DicomTags.Manufacturer, "N/A"); ds.AddElementWithValue(DicomTags.ManufacturersModelName, "N/A"); ds.AddElementWithValue(DicomTags.DeviceSerialNumber, "N/A"); ds.AddElementWithValue(DicomTags.SoftwareVersions, "N/A"); ds.SetDateTime(DicomTags.DateOfLastCalibration, DicomTags.TimeOfLastCalibration, DateTime.Now); SendNGetResponse(presentationID, messageID, requestedClass, requestedInstance, ds, DcmStatus.Success); return; } if (requestedClass == DicomUID.PrintJobSOPClass) { DcmPrintJob job = null; foreach (DcmPrintJob pj in _jobs) { if (pj.SOPInstanceUID == requestedInstance) { job = pj; break; } } if (job == null) { job = new DcmPrintJob(requestedInstance); job.ExecutionStatus = "DONE"; job.CreationDateTime = DateTime.Today; job.PrintPriority = _session.PrintPriority; job.PrinterName = _config.PrinterName; job.Originator = Associate.CallingAE; } SendNGetResponse(presentationID, messageID, requestedClass, requestedInstance, job.Dataset, DcmStatus.Success); return; } if (requestedClass == DicomUID.PrinterConfigurationRetrievalSOPClass && requestedInstance == DicomUID.PrinterConfigurationRetrievalSOPInstance) { DcmDataset ds = new DcmDataset(DicomTransferSyntax.ImplicitVRLittleEndian); DcmDataset config = new DcmDataset(DicomTransferSyntax.ImplicitVRLittleEndian); DcmItemSequence sq = new DcmItemSequence(DicomTags.PrinterConfigurationSequence); sq.AddSequenceItem(config); ds.AddItem(sq); SendNGetResponse(presentationID, messageID, requestedClass, requestedInstance, ds, DcmStatus.Success); return; } SendAbort(DcmAbortSource.ServiceProvider, DcmAbortReason.NotSpecified); }
public void UpdateDataset(DcmDataset dataset) { if (_lossy) { DcmCodeString cs = dataset.GetCS(DicomTags.ImageType); if (cs != null) { string[] values = cs.GetValues(); values[0] = "DERIVED"; cs.SetValues(values); } dataset.AddElementWithValue(DicomTags.SOPInstanceUID, DicomUID.Generate()); // FIXME: append existing values dataset.AddElementWithValue(DicomTags.LossyImageCompression, "01"); dataset.AddElementWithValue(DicomTags.LossyImageCompressionMethod, _lossyMethod); dataset.AddElementWithValue(DicomTags.LossyImageCompressionRatio, _lossyRatio); } dataset.AddElementWithValue(DicomTags.NumberOfFrames, _frames); dataset.AddElementWithValue(DicomTags.Columns, _width); dataset.AddElementWithValue(DicomTags.Rows, _height); dataset.AddElementWithValue(DicomTags.HighBit, _highBit); dataset.AddElementWithValue(DicomTags.BitsStored, _bitsStored); dataset.AddElementWithValue(DicomTags.BitsAllocated, _bitsAllocated); dataset.AddElementWithValue(DicomTags.SamplesPerPixel, _samplesPerPixel); dataset.AddElementWithValue(DicomTags.PixelRepresentation, _pixelRepresentation); dataset.AddElementWithValue(DicomTags.PhotometricInterpretation, _photometricInterpretation); if (SamplesPerPixel == 1) { dataset.AddElementWithValue(DicomTags.RescaleSlope, _rescaleSlope); dataset.AddElementWithValue(DicomTags.RescaleIntercept, _rescaleIntercept); //if (_pixelPaddingValue != 0) // dataset.AddElementWithValue(DicomTags.PixelPaddingValue, _pixelPaddingValue); } else { dataset.AddElementWithValue(DicomTags.PlanarConfiguration, _planarConfiguration); } dataset.AddItem(_pixelDataItem); }