odil
C++11libraryfortheDICOMstandard
Reader.h
1 /*************************************************************************
2  * odil - Copyright (C) Universite de Strasbourg
3  * Distributed under the terms of the CeCILL-B license, as published by
4  * the CEA-CNRS-INRIA. Refer to the LICENSE file or to
5  * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
6  * for details.
7  ************************************************************************/
8 
9 #ifndef _aa2965aa_e891_4713_9c90_e8eacd2944ea
10 #define _aa2965aa_e891_4713_9c90_e8eacd2944ea
11 
12 #include <functional>
13 #include <istream>
14 #include <string>
15 #include <utility>
16 
17 #include "odil/DataSet.h"
18 #include "odil/Element.h"
19 #include "odil/endian.h"
20 #include "odil/odil.h"
21 #include "odil/Tag.h"
22 #include "odil/Value.h"
23 #include "odil/VR.h"
24 
25 namespace odil
26 {
27 
29 class ODIL_API Reader
30 {
31 public:
33  std::istream & stream;
34 
36  std::string transfer_syntax;
37 
39  ByteOrdering byte_ordering;
40 
43 
46 
51  template<typename T>
52  static T read_binary(std::istream & stream, ByteOrdering byte_ordering);
53 
55  static Value::Binary read_encapsulated_pixel_data(
56  std::istream & stream, ByteOrdering byte_ordering,
57  std::string transfer_syntax, bool keep_group_length=false);
58 
60  static void ignore(std::istream & stream, std::streamsize size);
61 
66  Reader(
67  std::istream & stream, std::string const & transfer_syntax,
68  bool keep_group_length=false);
69 
71  DataSet read_data_set(
72  std::function<bool(Tag const &)> halt_condition = [](Tag const &) { return false;}) const;
73 
75  Tag read_tag() const;
76 
78  uint32_t read_length(VR vr) const;
79 
85  Element read_element(
86  Tag const & tag=Tag(0xffff,0xffff),
87  DataSet const & data_set=DataSet()) const;
88 
90  static std::pair<DataSet, DataSet> read_file(
91  std::istream & stream,
92  bool keep_group_length=false,
93  std::function<bool(Tag const &)> halt_condition = [](Tag const &) { return false;});
94 
95 private:
96  struct Visitor
97  {
98  typedef void result_type;
99 
100  std::istream & stream;
101  VR vr;
102  uint32_t vl;
103 
104  std::string transfer_syntax;
105  ByteOrdering byte_ordering;
106  bool explicit_vr;
107  bool keep_group_length;
108 
109  Visitor(
110  std::istream & stream, VR vr, uint32_t vl,
111  std::string const & transfer_syntax, ByteOrdering byte_ordering,
112  bool explicit_vr, bool keep_group_length);
113 
114  result_type operator()(Value::Integers & value) const;
115  result_type operator()(Value::Reals & value) const;
116  result_type operator()(Value::Strings & value) const;
117  result_type operator()(Value::DataSets & value) const;
118  result_type operator()(Value::Binary & value) const;
119 
120  // uint32_t read_length() const;
121 
122  Value::Strings split_strings(std::string const & string) const;
123  DataSet read_item(std::istream & specific_stream) const;
124  Value::Binary read_encapsulated_pixel_data(
125  std::istream & specific_stream) const;
126  };
127 };
128 
129 }
130 
131 #include "odil/Reader.txx"
132 
133 #endif // _aa2965aa_e891_4713_9c90_e8eacd2944ea
std::string transfer_syntax
Transfer syntax used to read the file.
Definition: Reader.h:36
std::vector< String > Strings
String container.
Definition: Value.h:57
bool keep_group_length
Flag to keep or discard group length tags.
Definition: Reader.h:45
ByteOrdering byte_ordering
Endianness.
Definition: Reader.h:39
std::vector< Real > Reals
Real container.
Definition: Value.h:54
Definition: Association.cpp:39
A DICOM element tag.
Definition: Tag.h:24
Read DICOM objects from a stream.
Definition: Reader.h:29
std::istream & stream
Input stream.
Definition: Reader.h:33
std::vector< Integer > Integers
Integer container.
Definition: Value.h:51
std::vector< DataSet > DataSets
Data sets container.
Definition: Value.h:60
std::vector< std::vector< uint8_t > > Binary
Binary data container.
Definition: Value.h:63
bool explicit_vr
Explicit-ness of the Value Representations.
Definition: Reader.h:42
DICOM Data set.
Definition: DataSet.h:29
Element of a DICOM data set.
Definition: Element.h:26