Mercurial > hg > orthanc
comparison OrthancFramework/Sources/DicomFormat/DicomStreamReader.h @ 4220:92a21efa5c96
reorganization of DicomStreamReader
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 30 Sep 2020 15:33:47 +0200 |
parents | |
children | e4c0218b6b23 |
comparison
equal
deleted
inserted
replaced
4219:b8ed2852a35d | 4220:92a21efa5c96 |
---|---|
1 /** | |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Lesser General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Lesser General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Lesser General Public | |
18 * License along with this program. If not, see | |
19 * <http://www.gnu.org/licenses/>. | |
20 **/ | |
21 | |
22 | |
23 #pragma once | |
24 | |
25 #include "DicomTag.h" | |
26 #include "StreamBlockReader.h" | |
27 | |
28 namespace Orthanc | |
29 { | |
30 /** | |
31 * This class parses a stream containing a DICOM instance. It does | |
32 * *not* support the visit of sequences (it only works at the first | |
33 * level of the hierarchy), and as a consequence, it doesn't give | |
34 * access to the pixel data of compressed transfer syntaxes. | |
35 **/ | |
36 class DicomStreamReader : public boost::noncopyable | |
37 { | |
38 public: | |
39 class IVisitor : public boost::noncopyable | |
40 { | |
41 public: | |
42 virtual ~IVisitor() | |
43 { | |
44 } | |
45 | |
46 // The data from this function will always be Little Endian (as | |
47 // specified by the DICOM standard) | |
48 virtual void VisitMetaHeaderTag(const DicomTag& tag, | |
49 const ValueRepresentation& vr, | |
50 const std::string& value) = 0; | |
51 | |
52 virtual void VisitTransferSyntax(DicomTransferSyntax transferSyntax) = 0; | |
53 | |
54 // Return "false" to stop processing | |
55 virtual bool VisitDatasetTag(const DicomTag& tag, | |
56 const ValueRepresentation& vr, | |
57 const std::string& value, | |
58 bool isLittleEndian) = 0; | |
59 }; | |
60 | |
61 private: | |
62 enum State | |
63 { | |
64 State_Preamble, | |
65 State_MetaHeader, | |
66 State_DatasetTag, | |
67 State_SequenceExplicitLength, | |
68 State_SequenceExplicitValue, | |
69 State_DatasetExplicitLength, | |
70 State_DatasetValue, | |
71 State_Done | |
72 }; | |
73 | |
74 StreamBlockReader reader_; | |
75 State state_; | |
76 DicomTransferSyntax transferSyntax_; | |
77 DicomTag previousTag_; | |
78 DicomTag danglingTag_; // Root-level tag | |
79 ValueRepresentation danglingVR_; | |
80 unsigned int sequenceDepth_; | |
81 | |
82 bool IsLittleEndian() const; | |
83 | |
84 void HandlePreamble(IVisitor& visitor, | |
85 const std::string& block); | |
86 | |
87 void HandleMetaHeader(IVisitor& visitor, | |
88 const std::string& block); | |
89 | |
90 void HandleDatasetTag(const std::string& block, | |
91 const DicomTag& untilTag); | |
92 | |
93 void HandleDatasetExplicitLength(uint32_t length); | |
94 | |
95 void HandleDatasetExplicitLength(const std::string& block); | |
96 | |
97 void HandleSequenceExplicitLength(const std::string& block); | |
98 | |
99 void HandleSequenceExplicitValue(); | |
100 | |
101 void HandleDatasetValue(IVisitor& visitor, | |
102 const std::string& block); | |
103 | |
104 public: | |
105 DicomStreamReader(std::istream& stream); | |
106 | |
107 /** | |
108 * Consume all the available bytes from the input stream, until | |
109 * end-of-stream is reached or the current tag is ">= untilTag". | |
110 * This method can be invoked several times, as more bytes are | |
111 * available from the input stream. To check if the DICOM stream | |
112 * is fully parsed until the goal tag, call "IsDone()". | |
113 **/ | |
114 void Consume(IVisitor& visitor, | |
115 const DicomTag& untilTag); | |
116 | |
117 void Consume(IVisitor& visitor); | |
118 | |
119 bool IsDone() const | |
120 { | |
121 return (state_ == State_Done); | |
122 } | |
123 | |
124 uint64_t GetProcessedBytes() const | |
125 { | |
126 return reader_.GetProcessedBytes(); | |
127 } | |
128 }; | |
129 } |