annotate OrthancFramework/Sources/DicomFormat/DicomStreamReader.h @ 5043:ec5c203a97ea

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