当前位置: 首页>>代码示例>>C#>>正文


C# DicomAttribute.GetEncodedString方法代码示例

本文整理汇总了C#中ClearCanvas.Dicom.DicomAttribute.GetEncodedString方法的典型用法代码示例。如果您正苦于以下问题:C# DicomAttribute.GetEncodedString方法的具体用法?C# DicomAttribute.GetEncodedString怎么用?C# DicomAttribute.GetEncodedString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ClearCanvas.Dicom.DicomAttribute的用法示例。


在下文中一共展示了DicomAttribute.GetEncodedString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: EnsureCharacterSetIsGood

        /// <summary>
        /// Makes sure the new value can be encoded with the specific character set in the dicom file header. If necessary and if it's allowed,
        /// convert the dicom file to use unicode (ISO_IR 192).
        /// </summary>
        /// <param name="file"></param>
        /// <param name="attr"></param>
        /// <param name="desiredValue"></param>
        /// <exception cref="DicomCharacterSetException">Thrown if unicode is not allowed or (for some reason) the value cannot be encoded using unicode</exception>
        private void EnsureCharacterSetIsGood(DicomFile file, DicomAttribute attr, string desiredValue)
        {
            var encodedValue = attr.GetEncodedString(file.TransferSyntax, file.DataSet.SpecificCharacterSet);

            var diff = Diff(attr.Tag, encodedValue, desiredValue);
            if (diff < 0)
            {
                // it's all good
                return;
            }

            // The current specific character set does not support the new value. Try to encode it using unicode (if it's configured)
            if (!CanSaveInUnicode)
            {
                Platform.Log(LogLevel.Debug, "'{0}' cannot be encoded using current Character Set and Unicode is not allowed. Aborting..", desiredValue);
                
                //Throw DicomCharacterSetException
                var characterSetDescriptions = SpecificCharacterSetParser.GetCharacterSetInfoDescriptions(file.DataSet.SpecificCharacterSet);
                string instanceNumber = file.DataSet[DicomTags.InstanceNumber].ToString();
                string instanceUid = file.DataSet[DicomTags.SopInstanceUid].ToString();
                char badChar = diff >= desiredValue.Length ? desiredValue[desiredValue.Length - 1] : desiredValue[diff];
                var error = string.Format("SOP {5}\n\nCannot set {0} to {1}. Character {2} is not covered by character set {3} [{4}].",
                                          UpdateEntry.TagPath.Tag.Name, desiredValue, badChar, file.DataSet.SpecificCharacterSet,
                                          StringUtilities.Combine(characterSetDescriptions, ","),
                                          string.Format("#{0} [{1}]", instanceNumber, instanceUid)
                    );

                Platform.Log(LogLevel.Error, error);
                throw new DicomCharacterSetException(UpdateEntry.TagPath.Tag.TagValue, file.DataSet.SpecificCharacterSet, desiredValue, error);
            }


            // The attribute value has been set, only need to set specific character set to unicode
            const string newSpecificCharacterSet = "ISO_IR 192";

            // Before we commit the change, let's verify again if that's good.
            Platform.Log(LogLevel.Debug, "'{0}'cannot be encoded using current Character Set and Unicode is allowed. Checking for value consistency if switching to Unicode encoding", desiredValue);
            encodedValue = attr.GetEncodedString(file.TransferSyntax, newSpecificCharacterSet);
            diff = Diff(attr.Tag, encodedValue, desiredValue);
            if (diff >= 0)
            {
                // not ok?
                var characterSetDescriptions = SpecificCharacterSetParser.GetCharacterSetInfoDescriptions(file.DataSet.SpecificCharacterSet);
                string instanceNumber = file.DataSet[DicomTags.InstanceNumber].ToString();
                string instanceUid = file.DataSet[DicomTags.SopInstanceUid].ToString();
                char badChar = diff >= desiredValue.Length ? desiredValue[desiredValue.Length - 1] : desiredValue[diff];
                var error = string.Format("SOP {5}\n\nCannot set {0} to {1}. Character {2} is not covered by character set {3} [{4}]. Attempt to use {6} did not solve the problem.",
                                          UpdateEntry.TagPath.Tag.Name, desiredValue, badChar, file.DataSet.SpecificCharacterSet,
                                          StringUtilities.Combine(characterSetDescriptions, ","),
                                          string.Format("#{0} [{1}]", instanceNumber, instanceUid),
                                          newSpecificCharacterSet
                    );

                Platform.Log(LogLevel.Error, error);
                throw new DicomCharacterSetException(UpdateEntry.TagPath.Tag.TagValue, file.DataSet.SpecificCharacterSet, desiredValue, error);
            }

            Platform.Log(LogLevel.Debug, "Specific Character Set for SOP {0} is now changed to unicode", file.MediaStorageSopInstanceUid);

            file.DataSet.SpecificCharacterSet = newSpecificCharacterSet;
            file.DataSet[DicomTags.SpecificCharacterSet].SetStringValue(newSpecificCharacterSet);
        }
开发者ID:nhannd,项目名称:Xian,代码行数:70,代码来源:SetTagCommand.cs


注:本文中的ClearCanvas.Dicom.DicomAttribute.GetEncodedString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。