dcmtkpp
Reader.h
1 /*************************************************************************
2  * dcmtkpp - 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 "dcmtkpp/DataSet.h"
18 #include "dcmtkpp/Element.h"
19 #include "dcmtkpp/Tag.h"
20 #include "dcmtkpp/Value.h"
21 #include "dcmtkpp/VR.h"
22 
23 namespace dcmtkpp
24 {
25 
27 class Reader
28 {
29 public:
31  std::istream & stream;
32 
34  std::string transfer_syntax;
35 
38 
41 
44 
49  Reader(
50  std::istream & stream, std::string const & transfer_syntax,
51  bool keep_group_length=false);
52 
55  std::function<bool(Tag const &)> halt_condition = [](Tag const &) { return false;}) const;
56 
58  Tag read_tag() const;
59 
66  Tag const & tag=Tag(0xffff,0xffff),
67  DataSet const & data_set=DataSet()) const;
68 
69  static std::pair<DataSet, DataSet> read_file(
70  std::istream & stream,
71  bool keep_group_length=false);
72 
73 private:
74  struct Visitor
75  {
76  typedef void result_type;
77 
78  std::istream & stream;
79  VR vr;
80 
81  std::string transfer_syntax;
82  int byte_ordering;
83  bool explicit_vr;
84  bool keep_group_length;
85 
86  Visitor(
87  std::istream & stream, VR vr, std::string const & transfer_syntax,
88  int byte_ordering, bool explicit_vr, bool keep_group_length);
89 
90  result_type operator()(Value::Integers & value) const;
91  result_type operator()(Value::Reals & value) const;
92  result_type operator()(Value::Strings & value) const;
93  result_type operator()(Value::DataSets & value) const;
94  result_type operator()(Value::Binary & value) const;
95 
96  uint32_t read_length() const;
97 
98  Value::Strings split_strings(std::string const & string) const;
99  DataSet read_item(std::istream & specific_stream) const;
100  };
101 };
102 
103 }
104 
105 #endif // _aa2965aa_e891_4713_9c90_e8eacd2944ea
int byte_ordering
Endianness (LITTLE_ENDIAN or BIG_ENDIAN).
Definition: Reader.h:37
std::vector< DataSet > DataSets
Data sets container.
Definition: Value.h:55
Definition: Association.cpp:22
bool explicit_vr
Explicit-ness of the Value Representations.
Definition: Reader.h:40
Read DICOM objects from a stream.
Definition: Reader.h:27
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:125
std::istream & stream
Input stream.
Definition: Reader.h:31
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:43
DataSet read_data_set(std::function< bool(Tag const &)> halt_condition=[](Tag const &){return false;}) const
Read a data set.
Definition: Reader.cpp:83
DICOM Data set.
Definition: DataSet.h:66
Element of a DICOM data set.
Definition: Element.h:25
std::string transfer_syntax
Transfer syntax used to read the file.
Definition: Reader.h:34
std::vector< Real > Reals
Real container.
Definition: Value.h:49
Tag read_tag() const
Read a tag.
Definition: Reader.cpp:116
A DICOM element tag.
Definition: Tag.h:22
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:68
std::vector< Integer > Integers
Integer container.
Definition: Value.h:46
std::vector< uint8_t > Binary
Binary data container.
Definition: Value.h:58