Odil
A C++11 library for the DICOM standard
Reader.h
Go to the documentation of this file.
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
25namespace odil
26{
27
30{
31public:
33 std::istream & stream;
34
36 std::string transfer_syntax;
37
40
43
46
51 template<typename T>
52 static T read_binary(std::istream & stream, ByteOrdering ordering);
53
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
67 std::istream & stream, std::string const & transfer_syntax,
68 bool keep_group_length=false);
69
71 std::shared_ptr<DataSet> read_data_set(
72 std::function<bool(Tag const &)> halt_condition =
73 [](Tag const &) { return false;}) const;
74
76 Tag read_tag() const;
77
79 uint32_t read_length(VR vr) const;
80
87 Tag const & tag=Tag(0xffff,0xffff),
88 std::shared_ptr<DataSet const> data_set=std::make_shared<DataSet>()) const;
89
91 static std::pair<std::shared_ptr<DataSet>, std::shared_ptr<DataSet>>
93 std::istream & stream,
94 bool keep_group_length=false,
95 std::function<bool(Tag const &)> halt_condition = [](Tag const &) { return false;});
96
97private:
98 struct Visitor
99 {
100 typedef void result_type;
101
102 std::istream & stream;
103 VR vr;
104 uint32_t vl;
105
106 std::string transfer_syntax;
108 bool explicit_vr;
109 bool keep_group_length;
110
111 Visitor(
112 std::istream & stream, VR vr, uint32_t vl,
113 std::string const & transfer_syntax, ByteOrdering byte_ordering,
114 bool explicit_vr, bool keep_group_length);
115
116 result_type operator()(Value::Integers & value) const;
117 result_type operator()(Value::Reals & value) const;
118 result_type operator()(Value::Strings & value) const;
119 result_type operator()(Value::DataSets & value) const;
120 result_type operator()(Value::Binary & value) const;
121
122 // uint32_t read_length() const;
123
124 Value::Strings split_strings(std::string const & string) const;
125 std::shared_ptr<DataSet>
126 read_item(std::istream & specific_stream) const;
127 Value::Binary read_encapsulated_pixel_data(
128 std::istream & specific_stream) const;
129 };
130};
131
132}
133
134#include "odil/Reader.txx"
135
136#endif // _aa2965aa_e891_4713_9c90_e8eacd2944ea
Element of a DICOM data set.
Definition: Element.h:27
Read DICOM objects from a stream.
Definition: Reader.h:30
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.
bool keep_group_length
Flag to keep or discard group length tags.
Definition: Reader.h:45
std::shared_ptr< DataSet > read_data_set(std::function< bool(Tag const &)> halt_condition=[](Tag const &) { return false;}) const
Read a data set.
ByteOrdering byte_ordering
Endianness.
Definition: Reader.h:39
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.
std::string transfer_syntax
Transfer syntax used to read the file.
Definition: Reader.h:36
static void ignore(std::istream &stream, std::streamsize size)
Ignore data from a stream, ensure stream is still good.
bool explicit_vr
Explicit-ness of the Value Representations.
Definition: Reader.h:42
std::istream & stream
Input stream.
Definition: Reader.h:33
uint32_t read_length(VR vr) const
Read the length of an element.
static T read_binary(std::istream &stream, ByteOrdering ordering)
Read binary data from an stream encoded with the given endianness, ensure stream is still good.
Tag read_tag() const
Read a tag.
static std::pair< std::shared_ptr< DataSet >, std::shared_ptr< 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.
Element read_element(Tag const &tag=Tag(0xffff, 0xffff), std::shared_ptr< DataSet const > data_set=std::make_shared< DataSet >()) const
Read an element (VR and value), try to guess the VR from the tag, partially read data set,...
A DICOM element tag.
Definition: Tag.h:26
std::vector< String > Strings
String container.
Definition: Value.h:57
std::vector< Integer > Integers
Integer container.
Definition: Value.h:51
std::vector< std::vector< uint8_t > > Binary
Binary data container.
Definition: Value.h:63
std::vector< Real > Reals
Real container.
Definition: Value.h:54
std::vector< std::shared_ptr< DataSet > > DataSets
Data sets container.
Definition: Value.h:60
Definition: Association.h:25
ByteOrdering const byte_ordering
ByteOrdering
Definition: endian.h:30
VR
Value representations of DICOM.
Definition: VR.h:23
#define ODIL_API
Definition: odil.h:28