annotate OrthancFramework/Sources/DicomFormat/DicomStreamReader.h @ 4773:4757b36cc538

rewording
author Alain Mazy <am@osimis.io>
date Mon, 30 Aug 2021 09:48:46 +0200
parents 39192eb9b43d
children 7053502fbf97
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4220
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
4437
d9473bd5ed43 upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4277
diff changeset
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium
4220
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public License
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Lesser General Public License for more details.
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * License along with this program. If not, see
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * <http://www.gnu.org/licenses/>.
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #pragma once
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "DicomTag.h"
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "StreamBlockReader.h"
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 namespace Orthanc
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 {
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 /**
4221
e4c0218b6b23 better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4220
diff changeset
31 * This class parses a stream containing a DICOM instance, using a
e4c0218b6b23 better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4220
diff changeset
32 * state machine.
e4c0218b6b23 better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4220
diff changeset
33 *
e4c0218b6b23 better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4220
diff changeset
34 * It does *not* support the visit of sequences (it only works at
e4c0218b6b23 better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4220
diff changeset
35 * the first level of the hierarchy), and as a consequence, it
e4c0218b6b23 better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4220
diff changeset
36 * doesn't give access to the pixel data of compressed transfer
e4c0218b6b23 better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4220
diff changeset
37 * syntaxes.
4220
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 **/
4224
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4223
diff changeset
39 class ORTHANC_PUBLIC DicomStreamReader : public boost::noncopyable
4220
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 public:
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 class IVisitor : public boost::noncopyable
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 {
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 public:
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 virtual ~IVisitor()
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 {
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 }
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 // The data from this function will always be Little Endian (as
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 // specified by the DICOM standard)
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 virtual void VisitMetaHeaderTag(const DicomTag& tag,
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 const ValueRepresentation& vr,
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 const std::string& value) = 0;
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 virtual void VisitTransferSyntax(DicomTransferSyntax transferSyntax) = 0;
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 // Return "false" to stop processing
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 virtual bool VisitDatasetTag(const DicomTag& tag,
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 const ValueRepresentation& vr,
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 const std::string& value,
4493
b57ca702a430 DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
61 bool isLittleEndian,
b57ca702a430 DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
62 uint64_t fileOffset) = 0;
4220
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 };
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 private:
4493
b57ca702a430 DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
66 class PixelDataVisitor;
b57ca702a430 DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
67
4220
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 enum State
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 {
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 State_Preamble,
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 State_MetaHeader,
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 State_DatasetTag,
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 State_SequenceExplicitLength,
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 State_SequenceExplicitValue,
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 State_DatasetExplicitLength,
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 State_DatasetValue,
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 State_Done
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 };
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 StreamBlockReader reader_;
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 State state_;
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 DicomTransferSyntax transferSyntax_;
4222
7461f98c23a0 remove debug printf from DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4221
diff changeset
83 DicomTag danglingTag_; // Current root-level tag
4220
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 ValueRepresentation danglingVR_;
4493
b57ca702a430 DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
85 uint64_t danglingOffset_;
4220
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 unsigned int sequenceDepth_;
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 bool IsLittleEndian() const;
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 void HandlePreamble(IVisitor& visitor,
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 const std::string& block);
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 void HandleMetaHeader(IVisitor& visitor,
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 const std::string& block);
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 void HandleDatasetTag(const std::string& block,
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 const DicomTag& untilTag);
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 void HandleDatasetExplicitLength(uint32_t length);
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100
4493
b57ca702a430 DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
101 void HandleDatasetExplicitLength(IVisitor& visitor,
b57ca702a430 DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
102 const std::string& block);
4220
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 void HandleSequenceExplicitLength(const std::string& block);
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 void HandleSequenceExplicitValue();
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 void HandleDatasetValue(IVisitor& visitor,
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 const std::string& block);
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 public:
4223
3d6f14a05db1 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4222
diff changeset
112 explicit DicomStreamReader(std::istream& stream);
4220
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 /**
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 * Consume all the available bytes from the input stream, until
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 * end-of-stream is reached or the current tag is ">= untilTag".
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 * This method can be invoked several times, as more bytes are
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 * available from the input stream. To check if the DICOM stream
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 * is fully parsed until the goal tag, call "IsDone()".
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 **/
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 void Consume(IVisitor& visitor,
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 const DicomTag& untilTag);
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 void Consume(IVisitor& visitor);
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125
4277
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4224
diff changeset
126 bool IsDone() const;
4220
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127
4277
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4224
diff changeset
128 uint64_t GetProcessedBytes() const;
4493
b57ca702a430 DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
129
b57ca702a430 DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
130 static bool LookupPixelDataOffset(uint64_t& offset,
b57ca702a430 DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
131 const std::string& dicom);
4494
39192eb9b43d New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4493
diff changeset
132
39192eb9b43d New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4493
diff changeset
133 static bool LookupPixelDataOffset(uint64_t& offset,
39192eb9b43d New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4493
diff changeset
134 const void* buffer,
39192eb9b43d New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4493
diff changeset
135 size_t size);
4220
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 };
92a21efa5c96 reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 }