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/Tag.h"
21 #include "odil/Value.h"
22 #include "odil/VR.h"
23 
24 namespace odil
25 {
26 
28 class Reader
29 {
30 public:
32  std::istream & stream;
33 
35  std::string transfer_syntax;
36 
38  ByteOrdering byte_ordering;
39 
42 
45 
50  template<typename T>
51  static T read_binary(std::istream & stream, ByteOrdering byte_ordering);
52 
55  std::istream & stream, ByteOrdering byte_ordering,
56  std::string transfer_syntax, bool keep_group_length=false);
57 
59  static void ignore(std::istream & stream, std::streamsize size);
60 
65  Reader(
66  std::istream & stream, std::string const & transfer_syntax,
67  bool keep_group_length=false);
68 
71  std::function<bool(Tag const &)> halt_condition = [](Tag const &) { return false;}) const;
72 
74  Tag read_tag() const;
75 
77  uint32_t read_length(VR vr) const;
78 
85  Tag const & tag=Tag(0xffff,0xffff),
86  DataSet const & data_set=DataSet()) const;
87 
89  static std::pair<DataSet, DataSet> read_file(
90  std::istream & stream,
91  bool keep_group_length=false,
92  std::function<bool(Tag const &)> halt_condition = [](Tag const &) { return false;});
93 
94 private:
95  struct Visitor
96  {
97  typedef void result_type;
98 
99  std::istream & stream;
100  VR vr;
101  uint32_t vl;
102 
103  std::string transfer_syntax;
104  ByteOrdering byte_ordering;
105  bool explicit_vr;
106  bool keep_group_length;
107 
108  Visitor(
109  std::istream & stream, VR vr, uint32_t vl,
110  std::string const & transfer_syntax, ByteOrdering byte_ordering,
111  bool explicit_vr, bool keep_group_length);
112 
113  result_type operator()(Value::Integers & value) const;
114  result_type operator()(Value::Reals & value) const;
115  result_type operator()(Value::Strings & value) const;
116  result_type operator()(Value::DataSets & value) const;
117  result_type operator()(Value::Binary & value) const;
118 
119  // uint32_t read_length() const;
120 
121  Value::Strings split_strings(std::string const & string) const;
122  DataSet read_item(std::istream & specific_stream) const;
124  std::istream & specific_stream) const;
125  };
126 };
127 
128 }
129 
130 #include "odil/Reader.txx"
131 
132 #endif // _aa2965aa_e891_4713_9c90_e8eacd2944ea
std::string transfer_syntax
Transfer syntax used to read the file.
Definition: Reader.h:35
static void ignore(std::istream &stream, std::streamsize size)
Ignore data from a stream, ensure stream is still good.
Definition: Reader.cpp:98
std::vector< String > Strings
String container.
Definition: Value.h:55
static T read_binary(std::istream &stream, ByteOrdering byte_ordering)
Read binary data from an stream encoded with the given endianness, ensure stream is still good...
bool keep_group_length
Flag to keep or discard group length tags.
Definition: Reader.h:44
ByteOrdering byte_ordering
Endianness.
Definition: Reader.h:38
std::vector< Real > Reals
Real container.
Definition: Value.h:52
uint32_t read_length(VR vr) const
Read the length of an element.
Definition: Reader.cpp:167
static std::pair< DataSet, DataSet > read_file(std::istream &stream, bool keep_group_length=false, std::function< bool(Tag const &)> halt_condition=[](Tag const &) { return false;})
Return the meta-data header and data set stored in the stream.
Definition: Reader.cpp:267
Element read_element(Tag const &tag=Tag(0xffff, 0xffff), DataSet const &data_set=DataSet()) const
Read an element (VR and value), try to guess the VR from the tag, partially read data set...
Definition: Reader.cpp:200
Definition: Association.cpp:39
A DICOM element tag.
Definition: Tag.h:22
Read DICOM objects from a stream.
Definition: Reader.h:28
std::istream & stream
Input stream.
Definition: Reader.h:32
std::vector< Integer > Integers
Integer container.
Definition: Value.h:49
std::vector< DataSet > DataSets
Data sets container.
Definition: Value.h:58
std::vector< std::vector< uint8_t > > Binary
Binary data container.
Definition: Value.h:61
Tag read_tag() const
Read a tag.
Definition: Reader.cpp:156
DataSet read_data_set(std::function< bool(Tag const &)> halt_condition=[](Tag const &) { return false;}) const
Read a data set.
Definition: Reader.cpp:123
bool explicit_vr
Explicit-ness of the Value Representations.
Definition: Reader.h:41
DICOM Data set.
Definition: DataSet.h:28
static Value::Binary read_encapsulated_pixel_data(std::istream &stream, ByteOrdering byte_ordering, std::string transfer_syntax, bool keep_group_length=false)
Read pixel data in encapsulated form.
Definition: Reader.cpp:49
Reader(std::istream &stream, std::string const &transfer_syntax, bool keep_group_length=false)
Build a reader, derive byte ordering and explicit-ness of VR from transfer syntax.
Definition: Reader.cpp:108
Element of a DICOM data set.
Definition: Element.h:25