odil
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  Reader(
51  std::istream & stream, std::string const & transfer_syntax,
52  bool keep_group_length=false);
53 
56  std::function<bool(Tag const &)> halt_condition = [](Tag const &) { return false;}) const;
57 
59  Tag read_tag() const;
60 
67  Tag const & tag=Tag(0xffff,0xffff),
68  DataSet const & data_set=DataSet()) const;
69 
70  static std::pair<DataSet, DataSet> read_file(
71  std::istream & stream,
72  bool keep_group_length=false);
73 
74 private:
75  struct Visitor
76  {
77  typedef void result_type;
78 
79  std::istream & stream;
80  VR vr;
81 
82  std::string transfer_syntax;
83  ByteOrdering byte_ordering;
84  bool explicit_vr;
85  bool keep_group_length;
86 
87  Visitor(
88  std::istream & stream, VR vr, std::string const & transfer_syntax,
89  ByteOrdering byte_ordering, bool explicit_vr, bool keep_group_length);
90 
91  result_type operator()(Value::Integers & value) const;
92  result_type operator()(Value::Reals & value) const;
93  result_type operator()(Value::Strings & value) const;
94  result_type operator()(Value::DataSets & value) const;
95  result_type operator()(Value::Binary & value) const;
96 
97  uint32_t read_length() const;
98 
99  Value::Strings split_strings(std::string const & string) const;
100  DataSet read_item(std::istream & specific_stream) const;
101  };
102 };
103 
104 }
105 
106 #endif // _aa2965aa_e891_4713_9c90_e8eacd2944ea
std::string transfer_syntax
Transfer syntax used to read the file.
Definition: Reader.h:35
std::vector< String > Strings
String container.
Definition: Value.h:52
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:49
DataSet read_data_set(std::function< bool(Tag const &)> halt_condition=[](Tag const &){return false;}) const
Read a data set.
Definition: Reader.cpp:90
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:132
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:46
std::vector< DataSet > DataSets
Data sets container.
Definition: Value.h:55
bool explicit_vr
Explicit-ness of the Value Representations.
Definition: Reader.h:41
std::vector< uint8_t > Binary
Binary data container.
Definition: Value.h:58
Tag read_tag() const
Read a tag.
Definition: Reader.cpp:123
DICOM Data set.
Definition: DataSet.h:66
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:75
Element of a DICOM data set.
Definition: Element.h:25