Odil
A C++11 library for the DICOM standard
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,
61 ByteOrdering byte_ordering, bool explicit_vr);
62
65 std::ostream & stream,
66 ByteOrdering byte_ordering, bool explicit_vr,
67 ItemEncoding item_encoding=ItemEncoding::ExplicitLength,
68 bool use_group_length=false);
69
75 std::ostream & stream,
76 std::string const & transfer_syntax,
77 ItemEncoding item_encoding=ItemEncoding::ExplicitLength,
78 bool use_group_length=false);
79
81 void write_data_set(std::shared_ptr<DataSet const> data_set) const;
82
84 void write_tag(Tag const & tag) const;
85
87 void write_element(Element const & element) const;
88
90 static void write_file(
91 std::shared_ptr<DataSet const> data_set, std::ostream & stream,
92 std::shared_ptr<DataSet const> meta_information={},
93 std::string const & transfer_syntax = registry::ExplicitVRLittleEndian,
94 ItemEncoding item_encoding=ItemEncoding::ExplicitLength,
95 bool use_group_length=false);
96
97private:
98
99 struct Visitor
100 {
101 typedef void result_type;
102
103 std::ostream & stream;
104 VR vr;
105
107 bool explicit_vr;
108 ItemEncoding item_encoding;
109 bool use_group_length;
110
111 Visitor(
112 std::ostream & stream, VR vr,
113 ByteOrdering byte_ordering, bool explicit_vr, ItemEncoding item_encoding,
114 bool use_group_length);
115
116 result_type operator()(Value::Integers const & value) const;
117 result_type operator()(Value::Reals const & value) const;
118 result_type operator()(Value::Strings const & value) const;
119 result_type operator()(Value::DataSets const & value) const;
120 result_type operator()(Value::Binary const & value) const;
121
122 template<typename T>
123 void write_strings(T const & sequence, char padding) const;
124 };
125};
126
127}
128
129#include "odil/Writer.txx"
130
131#endif // _ca5c06d2_04f9_4009_9e98_5607e1060379
Element of a DICOM data set.
Definition: Element.h:27
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
Write DICOM objects to a stream.
Definition: Writer.h:29
bool explicit_vr
Explicit-ness of the Value Representations.
Definition: Writer.h:44
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 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
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.
Writer(std::ostream &stream, ByteOrdering byte_ordering, bool explicit_vr, ItemEncoding item_encoding=ItemEncoding::ExplicitLength, bool use_group_length=false)
Build a writer.
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