Dicom.Data.DcmDataset.CalculateWriteLength C# (CSharp) Method

CalculateWriteLength() public method

public CalculateWriteLength ( DicomTransferSyntax syntax, DicomWriteOptions options ) : uint
syntax DicomTransferSyntax
options DicomWriteOptions
return uint
        public uint CalculateWriteLength(DicomTransferSyntax syntax, DicomWriteOptions options)
        {
            uint length = 0;
            ushort group = 0xffff;
            foreach (DcmItem item in _items.Values) {
                if (item.Tag.Element == 0x0000)
                    continue;
                if (item.Tag.Group != group) {
                    group = item.Tag.Group;
                    if (Flags.IsSet(options, DicomWriteOptions.CalculateGroupLengths)) {
                        if (syntax.IsExplicitVR)
                            length += 4 + 2 + 2 + 4;
                        else
                            length += 4 + 4 + 4;
                    }
                }
                length += item.CalculateWriteLength(syntax, options);
            }
            return length;
        }

Usage Example

示例#1
0
        private bool SendDimse(byte pcid, DcmCommand command, DcmDataset dataset)
        {
            try {
                _disableTimeout = true;

                DicomTransferSyntax ts = _assoc.GetAcceptedTransferSyntax(pcid);

                if (dataset != null && ts != dataset.InternalTransferSyntax) {
                    if (ts.IsEncapsulated || dataset.InternalTransferSyntax.IsEncapsulated)
                        throw new DicomNetworkException("Unable to transcode encapsulated transfer syntax!");
                    dataset.ChangeTransferSyntax(ts, null);
                }

                DcmDimseProgress progress = new DcmDimseProgress();

                progress.EstimatedCommandLength = (int)command.CalculateWriteLength(DicomTransferSyntax.ImplicitVRLittleEndian, DicomWriteOptions.Default | DicomWriteOptions.CalculateGroupLengths);

                if (dataset != null)
                    progress.EstimatedDatasetLength = (int)dataset.CalculateWriteLength(ts, DicomWriteOptions.Default);

                PDataTFStream pdustream = new PDataTFStream(_network, pcid, (int)_assoc.MaximumPduLength);
                pdustream.OnPduSent += delegate() {
                    progress.BytesTransfered = pdustream.BytesSent;
                    OnSendDimseProgress(pcid, command, dataset, progress);
                };

                lock (_socket) {
                    OnSendDimseBegin(pcid, command, dataset, progress);

                    DicomStreamWriter dsw = new DicomStreamWriter(pdustream);
                    dsw.Write(command, DicomWriteOptions.Default | DicomWriteOptions.CalculateGroupLengths);

                    if (dataset != null) {
                        pdustream.IsCommand = false;
                        dsw.Write(dataset, DicomWriteOptions.Default);
                    }

                    // flush last pdu
                    pdustream.Flush(true);

                    OnSendDimse(pcid, command, dataset, progress);
                }

                return true;
            }
            catch (Exception e) {
            #if DEBUG
                Log.Error("{0} -> Error sending DIMSE: {1}", LogID, e.ToString());
            #else
                Log.Error("{0} -> Error sending DIMSE: {1}", LogID, e.Message);
            #endif
                OnNetworkError(e);
                return false;
            }
            finally {
                _disableTimeout = false;
            }
        }