odil
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/Tag.h"
20 #include "odil/Writer.h"
21 
22 namespace odil
23 {
24 
27 {
28 public:
30  typedef std::pair<Tag, int> RecordKey;
31 
33  typedef std::map<std::string, std::vector<RecordKey>> RecordKeyMap;
34 
36  static RecordKeyMap const default_record_keys;
37 
44  std::string root;
45 
51  std::vector<std::string> files;
52 
54  RecordKeyMap extra_record_keys;
55 
58 
60  std::string const & root="",
61  std::vector<std::string> const & files=std::vector<std::string>(),
62  RecordKeyMap const & extra_record_keys=RecordKeyMap(),
63  Writer::ItemEncoding item_encoding=Writer::ItemEncoding::ExplicitLength
64  );
65 
66  void operator()() const;
67 
68 private:
69  struct Record
70  {
71  typedef std::shared_ptr<Record> Pointer;
72  DataSet data_set;
73  std::map<std::string, Record::Pointer> children;
74  };
75 
76  struct LinearizedTree
77  {
78  std::vector<Record::Pointer> records;
79  std::vector<long> sibling;
80  std::vector<long> child;
81  };
82 
83  typedef std::map<std::string, Record::Pointer> RecordMap;
84 
86  std::map<std::string, Record::Pointer> _create_records() const;
87 
89  Record & _find_record(RecordMap & records, std::string const & key) const;
90 
92  void _fill_record(
93  DataSet const & data_set, Record & record,
94  std::string const & type) const;
95 
97  void _update_record(
98  DataSet const & data_set, Record & record,
99  std::vector<RecordKey> const & keys) const;
100 
102  LinearizedTree _linearize_records(RecordMap const & record_tree) const;
103 
105  std::vector<std::streampos> _get_relative_offsets(
106  std::vector<Record::Pointer> const & records) const;
107 
109  void _write(
110  LinearizedTree const & linearized_tree,
111  std::vector<std::streampos> const & relative_offsets) const;
112 };
113 
114 }
115 
116 #endif // _8836a563_24f6_4afb_89ba_377d49ce9f5d
std::vector< std::string > files
Path to the DICOM files, relative to root.
Definition: BasicDirectoryCreator.h:51
RecordKeyMap extra_record_keys
User-defined record keys, classified by record type.
Definition: BasicDirectoryCreator.h:54
std::string root
Root of the DICOM files and location of the output DICOMDIR file.
Definition: BasicDirectoryCreator.h:44
Write a Basic Directory (i.e. DICOMDIR) object to the disk.
Definition: BasicDirectoryCreator.h:26
Definition: Association.cpp:39
Writer::ItemEncoding item_encoding
Encoding of sequence items, defaults to Writer::ItemEncoding::ExplicitLength.
Definition: BasicDirectoryCreator.h:57
static RecordKeyMap const default_record_keys
Default record keys, classified by record type.
Definition: BasicDirectoryCreator.h:36
DICOM Data set.
Definition: DataSet.h:66
ItemEncoding
Encodings of sequence items.
Definition: Writer.h:31
std::pair< Tag, int > RecordKey
The tag and its associated type in the record.
Definition: BasicDirectoryCreator.h:30
std::map< std::string, std::vector< RecordKey > > RecordKeyMap
Map from a record type to the extra keys.
Definition: BasicDirectoryCreator.h:33