Mercurial > hg > orthanc
annotate OrthancFramework/Sources/DicomFormat/DicomStreamReader.h @ 4293:29729b7eb6ab
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 05 Nov 2020 11:23:47 +0100 |
parents | c5ca798b158a |
children | d9473bd5ed43 |
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 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
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 | 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, |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 bool isLittleEndian) = 0; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 }; |
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 private: |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 enum State |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 State_Preamble, |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 State_MetaHeader, |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 State_DatasetTag, |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 State_SequenceExplicitLength, |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 State_SequenceExplicitValue, |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 State_DatasetExplicitLength, |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 State_DatasetValue, |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 State_Done |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 }; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 StreamBlockReader reader_; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 State state_; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 DicomTransferSyntax transferSyntax_; |
4222
7461f98c23a0
remove debug printf from DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4221
diff
changeset
|
80 DicomTag danglingTag_; // Current root-level tag |
4220
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 ValueRepresentation danglingVR_; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 unsigned int sequenceDepth_; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 bool IsLittleEndian() const; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 void HandlePreamble(IVisitor& visitor, |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 const std::string& block); |
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 void HandleMetaHeader(IVisitor& visitor, |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 const std::string& block); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 void HandleDatasetTag(const std::string& block, |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 const DicomTag& untilTag); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 void HandleDatasetExplicitLength(uint32_t length); |
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 HandleDatasetExplicitLength(const std::string& block); |
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 HandleSequenceExplicitLength(const std::string& block); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 void HandleSequenceExplicitValue(); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 void HandleDatasetValue(IVisitor& visitor, |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 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 public: |
4223 | 107 explicit DicomStreamReader(std::istream& stream); |
4220
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 /** |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 * Consume all the available bytes from the input stream, until |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 * end-of-stream is reached or the current tag is ">= untilTag". |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 * This method can be invoked several times, as more bytes are |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
113 * available from the input stream. To check if the DICOM stream |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
114 * is fully parsed until the goal tag, call "IsDone()". |
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 void Consume(IVisitor& visitor, |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 const DicomTag& untilTag); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
118 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 void Consume(IVisitor& visitor); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
120 |
4277
c5ca798b158a
CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4224
diff
changeset
|
121 bool IsDone() const; |
4220
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 |
4277
c5ca798b158a
CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4224
diff
changeset
|
123 uint64_t GetProcessedBytes() const; |
4220
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 } |