Odil
A C++11 library for the DICOM standard
Loading...
Searching...
No Matches
Writer.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 _ca5c06d2_04f9_4009_9e98_5607e1060379
10#define _ca5c06d2_04f9_4009_9e98_5607e1060379
11
12#include <ostream>
13#include <string>
14
15#include "odil/DataSet.h"
16#include "odil/Element.h"
17#include "odil/endian.h"
18#include "odil/odil.h"
19#include "odil/registry.h"
20#include "odil/Tag.h"
21#include "odil/Value.h"
22#include "odil/VR.h"
23
24namespace odil
25{
26
29{
30public:
32 enum class ItemEncoding
33 {
34 ExplicitLength,
35 UndefinedLength
36 };
37
39 std::ostream & stream;
40
49
54 template<typename T>
55 static void write_binary(
56 T const & value, std::ostream & stream, ByteOrdering byte_ordering);
57
60 Value::Binary const & value, std::ostream & stream,
62
63 static std::size_t size(
65 bool use_group_length);
66 static std::size_t size(
67 odil::VR vr, odil::Value const &, bool explicit_vr,
69 static std::size_t size(
71 bool use_group_length);
72 static std::size_t size(
74 bool use_group_length);
75
78 std::ostream & stream,
81 bool use_group_length=false);
82
88 std::ostream & stream,
89 std::string const & transfer_syntax,
91 bool use_group_length=false);
92
94 void write_data_set(std::shared_ptr<DataSet const> data_set) const;
95
97 void write_tag(Tag const & tag) const;
98
100 void write_element(Element const & element) const;
101
103 static void write_file(
104 std::shared_ptr<DataSet const> data_set, std::ostream & stream,
105 std::shared_ptr<DataSet const> meta_information={},
106 std::string const & transfer_syntax = registry::ExplicitVRLittleEndian,
107 ItemEncoding item_encoding=ItemEncoding::ExplicitLength,
108 bool use_group_length=false);
109
110private:
111
112 struct WriteVisitor
113 {
114 typedef void result_type;
115
116 std::ostream & stream;
117 VR vr;
118
120 bool explicit_vr;
121 ItemEncoding item_encoding;
122 bool use_group_length;
123
124 WriteVisitor(
125 std::ostream & stream, VR vr,
126 ByteOrdering byte_ordering, bool explicit_vr, ItemEncoding item_encoding,
127 bool use_group_length);
128
129 result_type operator()(Value::Integers const & value) const;
130 result_type operator()(Value::Reals const & value) const;
131 result_type operator()(Value::Strings const & value) const;
132 result_type operator()(Value::DataSets const & value) const;
133 result_type operator()(Value::Binary const & value) const;
134
135 void write_strings(Value::Strings const & sequence, char padding) const;
136 void write_strings(Value::Integers const & sequence, char padding) const;
137 };
138
139 class SizeVisitor
140 {
141 public:
142 using result_type = std::size_t;
143
144 VR vr;
145 bool explicit_vr;
146 ItemEncoding item_encoding;
147 bool use_group_length;
148
149 SizeVisitor(
150 VR vr, bool explicit_vr, ItemEncoding item_encoding,
151 bool use_group_length);
152
153 result_type operator()(Value::Integers const & value) const;
154 result_type operator()(Value::Reals const & value) const;
155 result_type operator()(Value::Strings const & value) const;
156 result_type operator()(Value::DataSets const & value) const;
157 result_type operator()(Value::Binary const & value) const;
158 };
159};
160
161}
162
163#include "odil/Writer.txx"
164
165#endif // _ca5c06d2_04f9_4009_9e98_5607e1060379
DICOM Data set.
Definition DataSet.h:30
Element of a DICOM data set.
Definition Element.h:27
A DICOM element tag.
Definition Tag.h:26
A value held in a DICOM element.
Definition Value.h:29
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
bool explicit_vr
Explicit-ness of the Value Representations.
Definition Writer.h:44
static std::size_t size(odil::DataSet const &, bool explicit_vr, ItemEncoding item_encoding, bool use_group_length)
void write_data_set(std::shared_ptr< DataSet const > data_set) const
Write a data set.
void write_element(Element const &element) const
Write an element (VR, VL and value).
void write_tag(Tag const &tag) const
Write a tag.
static std::size_t size(odil::VR vr, odil::Value const &, bool explicit_vr, ItemEncoding item_encoding, bool use_group_length)
static void write_file(std::shared_ptr< DataSet const > data_set, std::ostream &stream, std::shared_ptr< DataSet const > meta_information={}, std::string const &transfer_syntax=registry::ExplicitVRLittleEndian, ItemEncoding item_encoding=ItemEncoding::ExplicitLength, bool use_group_length=false)
Write a file (meta-information and data set).
std::ostream & stream
Output stream.
Definition Writer.h:39
ItemEncoding
Encodings of sequence items.
Definition Writer.h:33
@ ExplicitLength
Definition Writer.h:34
Writer(std::ostream &stream, std::string const &transfer_syntax, ItemEncoding item_encoding=ItemEncoding::ExplicitLength, bool use_group_length=false)
Build a writer, derive byte ordering and explicit-ness of VR from transfer syntax.
static void write_encapsulated_pixel_data(Value::Binary const &value, std::ostream &stream, ByteOrdering byte_ordering, bool explicit_vr)
Write pixel data in encapsulated form.
static std::size_t size(odil::Element const &, bool explicit_vr, ItemEncoding item_encoding, bool use_group_length)
Writer(std::ostream &stream, ByteOrdering byte_ordering, bool explicit_vr, ItemEncoding item_encoding=ItemEncoding::ExplicitLength, bool use_group_length=false)
Build a writer.
static std::size_t size(odil::Tag const &, bool explicit_vr, ItemEncoding item_encoding, bool use_group_length)
ByteOrdering byte_ordering
Endianness.
Definition Writer.h:42
bool use_group_length
Presence of group length elements.
Definition Writer.h:48
static void write_binary(T const &value, std::ostream &stream, ByteOrdering byte_ordering)
Write binary data to an stream encoded with the given endianness, ensure stream is still good.
ItemEncoding item_encoding
Encoding of sequence items.
Definition Writer.h:46
std::string const ExplicitVRLittleEndian("1.2.840.10008.1.2.1")
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