odil
C++11libraryfortheDICOMstandard
BasicDirectoryCreator.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 _8836a563_24f6_4afb_89ba_377d49ce9f5d
10 #define _8836a563_24f6_4afb_89ba_377d49ce9f5d
11 
12 #include <map>
13 #include <memory>
14 #include <string>
15 #include <utility>
16 #include <vector>
17 
18 #include "odil/DataSet.h"
19 #include "odil/odil.h"
20 #include "odil/Tag.h"
21 #include "odil/Writer.h"
22 
23 namespace odil
24 {
25 
27 class ODIL_API BasicDirectoryCreator
28 {
29 public:
31  typedef std::pair<Tag, int> RecordKey;
32 
34  typedef std::map<std::string, std::vector<RecordKey>> RecordKeyMap;
35 
37  static RecordKeyMap const default_record_keys;
38 
45  std::string root;
46 
52  std::vector<std::string> files;
53 
55  RecordKeyMap extra_record_keys;
56 
59 
62  std::string const & root="",
63  std::vector<std::string> const & files=std::vector<std::string>(),
64  RecordKeyMap const & extra_record_keys=RecordKeyMap(),
65  Writer::ItemEncoding item_encoding=Writer::ItemEncoding::ExplicitLength
66  );
67 
69  void operator()() const;
70 
71 private:
72  struct Record
73  {
74  typedef std::shared_ptr<Record> Pointer;
75  DataSet data_set;
76  std::map<std::string, Record::Pointer> children;
77  };
78 
79  struct LinearizedTree
80  {
81  std::vector<Record::Pointer> records;
82  std::vector<long> sibling;
83  std::vector<long> child;
84  };
85 
86  typedef std::map<std::string, Record::Pointer> RecordMap;
87 
89  std::map<std::string, Record::Pointer> _create_records() const;
90 
92  Record & _find_record(RecordMap & records, std::string const & key) const;
93 
95  void _fill_record(
96  DataSet const & data_set, Record & record,
97  std::string const & type) const;
98 
100  void _update_record(
101  DataSet const & data_set, Record & record,
102  std::vector<RecordKey> const & keys) const;
103 
105  LinearizedTree _linearize_records(RecordMap const & record_tree) const;
106 
108  std::vector<std::streampos> _get_relative_offsets(
109  std::vector<Record::Pointer> const & records) const;
110 
112  void _write(
113  LinearizedTree const & linearized_tree,
114  std::vector<std::streampos> const & relative_offsets) const;
115 };
116 
117 }
118 
119 #endif // _8836a563_24f6_4afb_89ba_377d49ce9f5d
std::vector< std::string > files
Path to the DICOM files, relative to root.
Definition: BasicDirectoryCreator.h:52
RecordKeyMap extra_record_keys
User-defined record keys, classified by record type.
Definition: BasicDirectoryCreator.h:55
std::string root
Root of the DICOM files and location of the output DICOMDIR file.
Definition: BasicDirectoryCreator.h:45
Write a Basic Directory (i.e. DICOMDIR) object to the disk.
Definition: BasicDirectoryCreator.h:27
Definition: Association.cpp:39
Writer::ItemEncoding item_encoding
Encoding of sequence items, defaults to Writer::ItemEncoding::ExplicitLength.
Definition: BasicDirectoryCreator.h:58
static RecordKeyMap const default_record_keys
Default record keys, classified by record type.
Definition: BasicDirectoryCreator.h:37
DICOM Data set.
Definition: DataSet.h:29
ItemEncoding
Encodings of sequence items.
Definition: Writer.h:32
std::pair< Tag, int > RecordKey
The tag and its associated type in the record.
Definition: BasicDirectoryCreator.h:31
std::map< std::string, std::vector< RecordKey > > RecordKeyMap
Map from a record type to the extra keys.
Definition: BasicDirectoryCreator.h:34