Пример #1
0
        public static void Write(DICOMBinaryWriter dw, DICOMIOSettings settings, DICOMObject d,
                                 bool isSequenceItem = false)
        {
            if (!isSequenceItem)
            {
                TransferSyntaxHelper.SetSyntax(d, settings.TransferSyntax);
            }

            for (var i = 0; i < d.Elements.Count; i++)
            {
                var el = d.Elements[i];
                var currentSettings = IsFileMetaGroup(el) ? settings.GetFileMetaSettings() : settings;
                if (GroupWriter.IsGroupHeader(el))
                {
                    var skip = GroupWriter.WriteGroup(dw, currentSettings, d, el);
                    i += skip;
                }
                else
                {
                    _logger.LogInformation($"Writing element ${el.Tag.CompleteID}");
                    try
                    {
                        DICOMElementWriter.Write(dw, currentSettings, el);
                    }
                    catch (Exception e)
                    {
                        _logger.LogError($"Error writing :  ${el.Tag.CompleteID}\n{e}");
                        throw e;
                    }
                }
            }
        }
Пример #2
0
        public static int WriteGroup(DICOMBinaryWriter dw, DICOMIOSettings settings, DICOMObject d, IDICOMElement el)
        {
            var groupBytes = WriteGroupBytes(d, settings, el.Tag.Group);
            var length     = groupBytes.Length;
            var ul         = el as UnsignedLong;

            ul.SetData((uint)length);
            DICOMElementWriter.Write(dw, settings, ul);
            dw.Write(groupBytes);
            return(d.Elements.Where(elm => elm.Tag.Group == ul.Tag.Group).ToList().Count - 1);
        }
Пример #3
0
        public static int WriteGroupLittleEndian(DICOMBinaryWriter dw, DICOMWriteSettings settings, DICOMObject d, IDICOMElement el)
        {
            byte[]       groupBytes = WriteGroupBytesLittleEndian(d, settings, el.Tag.Group);
            int          length     = groupBytes.Length;
            UnsignedLong ul         = el as UnsignedLong;

            ul.SetData((uint)length);
            DICOMElementWriter.WriteLittleEndian(dw, settings, ul);
            dw.Write(groupBytes);
            return(d.Elements.Where(elm => elm.Tag.Group == ul.Tag.Group).ToList().Count - 1);
        }
Пример #4
0
 /// <summary>
 /// Ignores the rule of writing metadata in explicit VR little endian and instead writes all elements with the same passed in syntax
 /// Used in PData writing
 /// </summary>
 /// <param name="dw"></param>
 /// <param name="settings"></param>
 /// <param name="d"></param>
 /// <param name="isSequenceItem"></param>
 public static void WriteSameSyntax(DICOMBinaryWriter dw, DICOMIOSettings settings, DICOMObject d,
                                    bool isSequenceItem = false)
 {
     for (var i = 0; i < d.Elements.Count; i++)
     {
         var el = d.Elements[i];
         if (GroupWriter.IsGroupHeader(el))
         {
             var skip = GroupWriter.WriteGroup(dw, settings, d, el);
             i += skip;
         }
         else
         {
             DICOMElementWriter.Write(dw, settings, el);
         }
     }
 }
Пример #5
0
 public static void WriteObjectLittleEndian(DICOMBinaryWriter dw, DICOMWriteSettings settings, DICOMObject d)
 {
     for (int i = 0; i < d.Elements.Count; i++)
     {
         IDICOMElement      el = d.Elements[i];
         DICOMWriteSettings currentSettings = IsFileMetaGroup(el) ? settings.GetFileMetaSettings() : settings;
         if (GroupWriter.IsGroupHeader(el))
         {
             int skip = GroupWriter.WriteGroupLittleEndian(dw, currentSettings, d, el);
             i += skip;
         }
         else
         {
             DICOMElementWriter.WriteLittleEndian(dw, currentSettings, el);
         }
     }
 }
Пример #6
0
 /// <summary>
 /// Ignores the rule of writing metadata in explicit VR little endian and instead writes all elements with the passed in syntax
 /// </summary>
 /// <param name="dw"></param>
 /// <param name="settings"></param>
 /// <param name="d"></param>
 /// <param name="isSequenceItem"></param>
 public static void WriteSameSyntax(DICOMBinaryWriter dw, DICOMWriteSettings settings, DICOMObject d, bool isSequenceItem = false)
 {
     for (int i = 0; i < d.Elements.Count; i++)
     {
         IDICOMElement el = d.Elements[i];
         if (!isSequenceItem)
         {
             TransferSyntaxHelper.SetSyntax(d, settings.TransferSyntax);
         }
         if (GroupWriter.IsGroupHeader(el))
         {
             int skip = GroupWriter.WriteGroup(dw, settings, d, el);
             i += skip;
         }
         else
         {
             DICOMElementWriter.Write(dw, settings, el);
         }
     }
 }
Пример #7
0
        public static byte[] WriteGroupBytes(DICOMObject d, DICOMIOSettings settings, string groupId)
        {
            var groupElements = d.Elements.Where(el => el.Tag.Group == groupId).ToList();

            byte[] groupBytes;
            using (var stream = new MemoryStream())
            {
                using (var groupDW = new DICOMBinaryWriter(stream))
                {
                    foreach (var el in groupElements)
                    {
                        if (!IsGroupHeader(el))
                        {
                            DICOMElementWriter.Write(groupDW, settings, el);
                        }
                    }
                }
                groupBytes = stream.ToArray();
            }
            return(groupBytes);
        }
Пример #8
0
        private static byte[] WriteGroupBytesLittleEndian(DICOMObject d, DICOMWriteSettings settings, string groupID)
        {
            List <IDICOMElement> groupElements = d.Elements.Where(el => el.Tag.Group == groupID).ToList();

            byte[] groupBytes;
            using (MemoryStream stream = new MemoryStream())
            {
                using (DICOMBinaryWriter groupDW = new DICOMBinaryWriter(stream))
                {
                    foreach (IDICOMElement el in groupElements)
                    {
                        if (!IsGroupHeader(el))
                        {
                            DICOMElementWriter.WriteLittleEndian(groupDW, settings, el);
                        }
                    }
                }
                groupBytes = stream.ToArray();
            }
            return(groupBytes);
        }
Пример #9
0
 public static void Write(DICOMBinaryWriter dw, DICOMWriteSettings settings, DICOMObject d,
                          bool isSequenceItem = false)
 {
     for (var i = 0; i < d.Elements.Count; i++)
     {
         var el = d.Elements[i];
         if (!isSequenceItem)
         {
             TransferSyntaxHelper.SetSyntax(d, settings.TransferSyntax);
         }
         var currentSettings = IsFileMetaGroup(el) ? settings.GetFileMetaSettings() : settings;
         if (GroupWriter.IsGroupHeader(el))
         {
             var skip = GroupWriter.WriteGroup(dw, currentSettings, d, el);
             i += skip;
         }
         else
         {
             DICOMElementWriter.Write(dw, currentSettings, el);
         }
     }
 }