Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ScImageIod"/> class.
        /// </summary>
        /// <param name="dicomAttributeProvider">The DICOM attribute provider.</param>
        public ScImageIod(IDicomAttributeProvider dicomAttributeProvider)
        {
            _dicomAttributeProvider = dicomAttributeProvider;

            _patientModule = new PatientModuleIod(_dicomAttributeProvider);
            _clinicalTrialSubjectModule = new ClinicalTrialSubjectModuleIod(_dicomAttributeProvider);
            _generalStudyModule         = new GeneralStudyModuleIod(_dicomAttributeProvider);
            _patientStudyModule         = new PatientStudyModuleIod(_dicomAttributeProvider);
            _clinicalTrialStudyModule   = new ClinicalTrialStudyModuleIod(_dicomAttributeProvider);
            _generalSeriesModule        = new GeneralSeriesModuleIod(_dicomAttributeProvider);
            _clinicalTrialSeriesModule  = new ClinicalTrialSeriesModuleIod(_dicomAttributeProvider);
            _generalEquipmentModule     = new GeneralEquipmentModuleIod(_dicomAttributeProvider);
            _scEquipmentModule          = new ScEquipmentModuleIod(_dicomAttributeProvider);
            _generalImageModule         = new GeneralImageModuleIod(_dicomAttributeProvider);
            _imagePixelModule           = new ImagePixelMacroIod(_dicomAttributeProvider);
            _deviceModule       = new DeviceModuleIod(_dicomAttributeProvider);
            _scImageModule      = new ScImageModuleIod(_dicomAttributeProvider);
            _overlayPlaneModule = new OverlayPlaneModuleIod(_dicomAttributeProvider);
            _modalityLutModule  = new ModalityLutModuleIod(_dicomAttributeProvider);
            _voiLutModule       = new VoiLutModuleIod(_dicomAttributeProvider);
            _iccProfileModule   = new IccProfileModuleIod(_dicomAttributeProvider);
            _sopCommonModule    = new SopCommonModuleIod(_dicomAttributeProvider);
        }
Exemple #2
0
 public SegmentationDocumentIod(IDicomAttributeProvider dicomAttributeProvider)
 {
     _dicomAttributeProvider     = dicomAttributeProvider;
     _patientModule              = new PatientModuleIod(_dicomAttributeProvider);
     _clinicalTrialSubjectModule = new ClinicalTrialSubjectModuleIod(_dicomAttributeProvider);
     _generalStudyModule         = new GeneralStudyModuleIod(_dicomAttributeProvider);
     _patientStudyModule         = new PatientStudyModuleIod(_dicomAttributeProvider);
     _clinicalTrialStudyModule   = new ClinicalTrialStudyModuleIod(_dicomAttributeProvider);
     _generalSeriesModule        = new GeneralSeriesModuleIod(_dicomAttributeProvider);
     _segmentationSeriesModule   = new SegmentationSeriesModuleIod(_dicomAttributeProvider);
     _clinicalTrialSeriesModule  = new ClinicalTrialSeriesModuleIod(_dicomAttributeProvider);
     _frameOfReferenceModule     = new FrameOfReferenceModuleIod(_dicomAttributeProvider);
     _generalEquipmentModule     = new GeneralEquipmentModuleIod(_dicomAttributeProvider);
     //_enhanceGeneralEquipmentModule = new EnhanceGeneralEquipmentModuleIod(_dicomAttributeProvider);
     _generalImageModule               = new GeneralImageModuleIod(_dicomAttributeProvider);
     _imagePixelModule                 = new ImagePixelMacroIod(_dicomAttributeProvider);
     _segmentationImageModule          = new SegmentationImageModuleIod(_dicomAttributeProvider);
     _multiFrameFunctionalGroupsModule = new MultiFrameFunctionalGroupsModuleIod(_dicomAttributeProvider);
     _multiFrameDimensionModule        = new MultiFrameDimensionModuleIod(_dicomAttributeProvider);
     _specimenModule = new SpecimenModuleIod(_dicomAttributeProvider);
     _commonInstanceReferenceModule = new CommonInstanceReferenceModuleIod(_dicomAttributeProvider);
     _sopCommonModule       = new SopCommonModuleIod(_dicomAttributeProvider);
     _frameExtractionModule = new FrameExtractionModuleIod(_dicomAttributeProvider);
 }
        private byte SelectPresentationContext(ClientAssociationParameters association, DicomFile file, out DicomMessage message)
        {
            byte pcid = 0;

            message = new DicomMessage(file);

            // If Lossy compressed & we have a matching context, send
            // If we don't have a codec, just return
            if (message.TransferSyntax.Encapsulated && message.TransferSyntax.LossyCompressed)
            {
                pcid = association.FindAbstractSyntaxWithTransferSyntax(message.SopClass, message.TransferSyntax);
                if (pcid != 0)
                {
                    return(pcid);
                }

                if (DicomCodecRegistry.GetCodec(message.TransferSyntax) == null)
                {
                    return(0);
                }
            }

            // If the image is lossless compressed & we don't have a codec, send if we
            // can as is.
            if (message.TransferSyntax.Encapsulated && message.TransferSyntax.LosslessCompressed)
            {
                if (DicomCodecRegistry.GetCodec(message.TransferSyntax) == null)
                {
                    pcid = association.FindAbstractSyntaxWithTransferSyntax(message.SopClass, message.TransferSyntax);
                    return(pcid);
                }
            }

            // If lossless compressed & requesting lossless syntax, just send as is
            if (message.TransferSyntax.Encapsulated &&
                message.TransferSyntax.LosslessCompressed &&
                ((_sendRequest.CompressionType == CompressionType.Rle ||
                  _sendRequest.CompressionType == CompressionType.JpegLossless ||
                  _sendRequest.CompressionType == CompressionType.J2KLossless)))
            {
                pcid = association.FindAbstractSyntaxWithTransferSyntax(message.SopClass, message.TransferSyntax);
                if (pcid != 0)
                {
                    return(pcid);
                }
            }


            if (_sendRequest.CompressionType == CompressionType.Rle)
            {
                pcid = association.FindAbstractSyntaxWithTransferSyntax(message.SopClass, TransferSyntax.RleLossless);
                if (pcid != 0)
                {
                    return(pcid);
                }
            }
            else if (_sendRequest.CompressionType == CompressionType.JpegLossless)
            {
                pcid = association.FindAbstractSyntaxWithTransferSyntax(message.SopClass, TransferSyntax.JpegLosslessNonHierarchicalFirstOrderPredictionProcess14SelectionValue1);
                if (pcid != 0)
                {
                    return(pcid);
                }
            }
            else if (_sendRequest.CompressionType == CompressionType.J2KLossless)
            {
                pcid = association.FindAbstractSyntaxWithTransferSyntax(message.SopClass, TransferSyntax.Jpeg2000ImageCompressionLosslessOnly);
                if (pcid != 0)
                {
                    return(pcid);
                }
            }
            else if (_sendRequest.CompressionType == CompressionType.J2KLossy)
            {
                pcid = association.FindAbstractSyntaxWithTransferSyntax(message.SopClass, TransferSyntax.Jpeg2000ImageCompression);
                if (pcid != 0)
                {
                    var doc = new XmlDocument();

                    XmlElement element = doc.CreateElement("compress");
                    doc.AppendChild(element);
                    XmlAttribute syntaxAttribute = doc.CreateAttribute("syntax");
                    syntaxAttribute.Value = TransferSyntax.Jpeg2000ImageCompressionUid;
                    element.Attributes.Append(syntaxAttribute);

                    decimal      ratio          = 100.0m / _sendRequest.CompressionLevel;
                    XmlAttribute ratioAttribute = doc.CreateAttribute("ratio");
                    ratioAttribute.Value = ratio.ToString(CultureInfo.InvariantCulture);
                    element.Attributes.Append(ratioAttribute);

                    syntaxAttribute       = doc.CreateAttribute("convertFromPalette");
                    syntaxAttribute.Value = true.ToString(CultureInfo.InvariantCulture);
                    element.Attributes.Append(syntaxAttribute);

                    IDicomCodecFactory[] codecs = DicomCodecRegistry.GetCodecFactories();
                    foreach (IDicomCodecFactory codec in codecs)
                    {
                        if (codec.CodecTransferSyntax.Equals(TransferSyntax.Jpeg2000ImageCompression))
                        {
                            try
                            {
                                if (message.TransferSyntax.Encapsulated)
                                {
                                    message.ChangeTransferSyntax(TransferSyntax.ExplicitVrLittleEndian);
                                    message.TransferSyntax = TransferSyntax.ExplicitVrLittleEndian;
                                }
                                message.ChangeTransferSyntax(TransferSyntax.Jpeg2000ImageCompression,
                                                             codec.GetDicomCodec(),
                                                             codec.GetCodecParameters(doc));
                                message.TransferSyntax = TransferSyntax.Jpeg2000ImageCompression;
                                return(pcid);
                            }
                            catch (Exception e)
                            {
                                Platform.Log(LogLevel.Warn, e, "Unexpected exception changing transfer syntax to {0}.",
                                             TransferSyntax.Jpeg2000ImageCompression.Name);
                            }
                        }
                    }
                }
            }
            else if (_sendRequest.CompressionType == CompressionType.JpegLossy)
            {
                var iod = new ImagePixelMacroIod(message.DataSet);

                if (iod.BitsStored == 8)
                {
                    pcid = association.FindAbstractSyntaxWithTransferSyntax(message.SopClass,
                                                                            TransferSyntax.JpegBaselineProcess1);
                    if (pcid != 0)
                    {
                        var doc = new XmlDocument();

                        XmlElement element = doc.CreateElement("compress");
                        doc.AppendChild(element);
                        XmlAttribute syntaxAttribute = doc.CreateAttribute("syntax");
                        syntaxAttribute.Value = TransferSyntax.JpegBaselineProcess1Uid;
                        element.Attributes.Append(syntaxAttribute);

                        syntaxAttribute       = doc.CreateAttribute("quality");
                        syntaxAttribute.Value = _sendRequest.CompressionLevel.ToString(CultureInfo.InvariantCulture);
                        element.Attributes.Append(syntaxAttribute);

                        syntaxAttribute       = doc.CreateAttribute("convertFromPalette");
                        syntaxAttribute.Value = true.ToString(CultureInfo.InvariantCulture);
                        element.Attributes.Append(syntaxAttribute);

                        IDicomCodecFactory[] codecs = DicomCodecRegistry.GetCodecFactories();
                        foreach (IDicomCodecFactory codec in codecs)
                        {
                            if (codec.CodecTransferSyntax.Equals(TransferSyntax.JpegBaselineProcess1))
                            {
                                try
                                {
                                    if (message.TransferSyntax.Encapsulated)
                                    {
                                        message.ChangeTransferSyntax(TransferSyntax.ExplicitVrLittleEndian);
                                        message.TransferSyntax = TransferSyntax.ExplicitVrLittleEndian;
                                    }

                                    message.ChangeTransferSyntax(TransferSyntax.JpegBaselineProcess1,
                                                                 codec.GetDicomCodec(),
                                                                 codec.GetCodecParameters(doc));
                                    message.TransferSyntax = TransferSyntax.JpegBaselineProcess1;
                                    return(pcid);
                                }
                                catch (Exception e)
                                {
                                    Platform.Log(LogLevel.Warn, e,
                                                 "Unexpected exception changing transfer syntax to {0}.",
                                                 TransferSyntax.JpegBaselineProcess1.Name);
                                }
                            }
                        }
                    }
                }
                else if (iod.BitsStored == 12)
                {
                    pcid = association.FindAbstractSyntaxWithTransferSyntax(message.SopClass,
                                                                            TransferSyntax.JpegExtendedProcess24);
                    if (pcid != 0)
                    {
                        var doc = new XmlDocument();

                        XmlElement element = doc.CreateElement("compress");
                        doc.AppendChild(element);
                        XmlAttribute syntaxAttribute = doc.CreateAttribute("syntax");
                        syntaxAttribute.Value = TransferSyntax.JpegExtendedProcess24Uid;
                        element.Attributes.Append(syntaxAttribute);

                        syntaxAttribute       = doc.CreateAttribute("quality");
                        syntaxAttribute.Value = _sendRequest.CompressionLevel.ToString(CultureInfo.InvariantCulture);
                        element.Attributes.Append(syntaxAttribute);

                        syntaxAttribute       = doc.CreateAttribute("convertFromPalette");
                        syntaxAttribute.Value = true.ToString(CultureInfo.InvariantCulture);
                        element.Attributes.Append(syntaxAttribute);

                        IDicomCodecFactory[] codecs = DicomCodecRegistry.GetCodecFactories();
                        foreach (IDicomCodecFactory codec in codecs)
                        {
                            if (codec.CodecTransferSyntax.Equals(TransferSyntax.JpegExtendedProcess24))
                            {
                                try
                                {
                                    if (message.TransferSyntax.Encapsulated)
                                    {
                                        message.ChangeTransferSyntax(TransferSyntax.ExplicitVrLittleEndian);
                                        message.TransferSyntax = TransferSyntax.ExplicitVrLittleEndian;
                                    }

                                    message.ChangeTransferSyntax(TransferSyntax.JpegExtendedProcess24,
                                                                 codec.GetDicomCodec(),
                                                                 codec.GetCodecParameters(doc));
                                    message.TransferSyntax = TransferSyntax.JpegExtendedProcess24;
                                    return(pcid);
                                }
                                catch (Exception e)
                                {
                                    Platform.Log(LogLevel.Warn, e,
                                                 "Unexpected exception changing transfer syntax to {0}.",
                                                 TransferSyntax.JpegExtendedProcess24.Name);
                                }
                            }
                        }
                    }
                }
            }

            if (pcid == 0)
            {
                pcid = association.FindAbstractSyntaxWithTransferSyntax(message.SopClass,
                                                                        TransferSyntax.ExplicitVrLittleEndian);
            }
            if (pcid == 0)
            {
                pcid = association.FindAbstractSyntaxWithTransferSyntax(message.SopClass,
                                                                        TransferSyntax.ImplicitVrLittleEndian);
            }

            return(pcid);
        }