2 // * gdcmlib is a library dedicated to reading and writing dicom files.
3 // * LGPL for the license
4 // * lightweigth as opposed to CTN or DCMTK wich come bundled which try
5 // to implement the full DICOM standard (networking...). gdcmlib concentrates
7 // * Formats: this lib should be able to read ACR-NEMA v1 and v2, Dicom v3 (as
8 // stated in part10). [cf dcmtk/dcmdata/docs/datadict.txt]
9 // * Targeted plateforms: Un*xes and Win32/VC++6.0
12 #include <stddef.h> // For size_t
14 // The requirement for the hash table (or map) that we shall use:
15 // 1/ First, next, last (iterators)
16 // 2/ should be sortable (i.e. sorted by TagKey). This condition
17 // shall be droped since the Win32/VC++ implementation doesn't look
18 // a sorted one. Pffff....
19 // 3/ Make sure we can setup some default size value, which should be
20 // around 4500 entries which is the average dictionary size (said JPR)
23 // Tag based hash tables.
24 // We shall use as keys the strings (as the C++ type) obtained by
25 // concatenating the group value and the element value (both of type
26 // unsigned 16 bit integers in Dicom) expressed in hexadecimal.
27 // Example: consider the tag given as (group, element) = (0x0010, 0x0010).
28 // Then the corresponding TagKey shall be the string 00100010 (or maybe
29 // 0x00100x0010, we need some checks here).
30 typedef string TagKey;
31 typedef map<TagKey, char*> TagHT;
33 // Dummy declaration for the time being
34 typedef int guint16; // We shall need glib.h !
38 ////// QUESTION: it is not sure that we need to store the group and
39 ////// and the element within a DictEntry. What is the point
40 ////// of storing the equivalent of a TagKey within the information
41 ////// accessed through that TagKey !?
42 guint16 group; // e.g. 0x0010
43 guint16 element; // e.g. 0x0010
44 string name; // e.g. "Patient_Name"
45 string ValRep; // Value Representation i.e. some clue about the nature
46 // of the data represented e.g. "FD" short for
47 // "Floating Point Double"
48 // DCMTK has many fields for handling a DictEntry (see below). What are the
49 // relevant ones for gdcmlib ?
50 // struct DBI_SimpleEntry {
54 // Uint16 upperElement;
56 // const char* tagName;
59 // const char* standardVersion;
60 // DcmDictRangeRestriction groupRestriction;
61 // DcmDictRangeRestriction elementRestriction;
65 DictEntry(guint16 group, guint16 element, string name, string VR);
68 // A single DICOM dictionary i.e. a container for a collection of dictionary
69 // entries. There should be a single public dictionary (THE dictionary of
70 // the actual DICOM v3) but as many shadow dictionaries as imagers
71 // combined with all software versions...
78 Dict(string filename); // Read Dict from disk
79 int AppendEntry(DictEntry* NewEntry);
82 // Container for managing a set of loaded dictionaries. Sharing dictionaries
84 // * reloading an allready loaded dictionary.
85 // * having many in memory representations of the same dictionary.
89 map<DictId, Dict*> dicts;
90 int AppendDict(Dict* NewDict);
92 DictSet(); // Default constructor loads THE DICOM v3 dictionary
93 int LoadDictFromFile(string filename);
94 ///// QUESTION: the following function might not be thread safe !? Maybe
95 ///// we need some mutex here, to avoid concurent creation of
96 ///// the same dictionary !?!?!
97 int LoadDictFromName(string filename);
98 int LoadAllDictFromDirectory(string directorynanme);
99 string* GetAllDictNames();
100 Dict* GetDict(string DictName);
103 // The dicom header of a Dicom file contains a set of such ELement VALUES
104 // (when successfuly parsed against a given Dicom dictionary)
110 // Container for a set of succefully parsed ElValues.
111 typedef map<TagKey, char*> TagHT;
113 // We need both accesses with a TagKey and the Dicentry.Name
114 ////// QUESTION: this leads to a double storage of a single ElValue
115 map<TagKey, ElValue> tagHt;
116 map<srting, ElValue> NameHt;
121 // The typical usage of objects of this class is to classify a set of
122 // dicom files according to header information e.g. to create a file hierachy
123 // reflecting the Patient/Study/Serie informations, or extracting a given
124 // SerieId. Accesing the content (image[s] or volume[s]) is beyond the
125 // functionality of this class (see dmcFile below).
127 // * the gdcmHeader::Set*Tag* family members cannot be defined as protected
128 // (Swig limitations for as Has_a dependency between gdcmFile and gdcmHeader)
143 static DictSet* Dicts; // Global dictionary container
144 Dict* RefPubDict; // Public Dictionary
145 Dict* RefShaDict; // Shadow Dictionary (optional)
147 ElValSet PubElVals; // Element Values parsed with Public Dictionary
148 ElValSet ShaElVals; // Element Values parsed with Shadow Dictionary
151 EndianType CheckSwap();
152 void _setAcrLibido();
153 guint32 _IdDcmRecupLgr(ID_DCM_HDR *e, int sw, int *skippedLength, int *longueurLue);
155 ///// QUESTION: Maybe Print is a better name than write !?
157 ///// QUESTION: Maybe anonymize should be a friend function !?!?
158 ///// See below for an example of how anonymize might be implemented.
159 int anonymize(ostream&);
162 gdcmHeader(string filename);
165 int SetPubDict(string filename);
166 // When some proprietary shadow groups are disclosed, whe can set
167 // up an additional specific dictionary to access extra information.
168 int SetShaDict(string filename);
170 // Retrieve all potentially available tag [tag = (group, element)] names
171 // from the standard (or public) dictionary (hence static). Typical usage:
172 // enable the user of a GUI based interface to select his favorite fields
173 // for sorting or selection.
174 string* GetPubTagNames();
175 // Get the element values themselves:
176 string GetPubElValByName(string TagName);
177 string GetPubElValByNumber(guint16 group, guint16 element);
178 // Get the element value representation: (VR) might be needed by caller
179 // to convert the string typed content to caller's native type (think
180 // of C/C++ vs Python).
181 string GetPubElValRepByName(string TagName);
182 string GetPubElValRepByNumber(guint16 group, guint16 element);
184 // Same thing with the shadow :
185 string* GetShaTagNames();
186 string GetShaElValByName(string TagName);
187 string GetShaElValByNumber(guint16 group, guint16 element);
188 string GetShaElValRepByName(string TagName);
189 string GetShaElValRepByNumber(guint16 group, guint16 element);
191 // Wrappers of the above (both public and shadow) to avoid bugging the
192 // caller with knowing if ElVal is from the public or shadow dictionary.
193 string GetElValByName(string TagName);
194 string GetElValByNumber(guint16 group, guint16 element);
195 string GetElValRepByName(string TagName);
196 string GetElValRepByNumber(guint16 group, guint16 element);
198 int SetPubElValByName(string content, string TagName);
199 int SetPubElValByNumber(string content, guint16 group, guint16 element);
200 int SetShaElValByName(string content, string ShadowTagName);
201 int SetShaElValByNumber(string content, guint16 group, guint16 element);
206 // In addition to Dicom header exploration, this class is designed
207 // for accessing the image/volume content. One can also use it to
208 // write Dicom files.
209 ////// QUESTION: this looks still like an open question wether the
210 ////// relationship between a gdcmFile and gdcmHeader is of
211 ////// type IS_A or HAS_A !
212 class gdcmFile: gdcmHeader
216 int Parsed; // weather allready parsed
217 string OrigFileName; // To avoid file overwrite
219 // Constructor dedicated to writing a new DICOMV3 part10 compliant
220 // file (see SetFileName, SetDcmTag and Write)
222 // Opens (in read only and when possible) an existing file and checks
223 // for DICOM compliance. Returns NULL on failure.
224 // Note: the in-memory representation of all available tags found in
225 // the DICOM header is post-poned to first header information access.
226 // This avoid a double parsing of public part of the header when
227 // one sets an a posteriori shadow dictionary (efficiency can be
228 // seen a a side effect).
229 gdcmFile(string filename);
230 // For promotion (performs a deepcopy of pointed header object)
231 gdcmFile(gdcmHeader* header);
234 // On writing purposes. When instance was created through
235 // gdcmFile(string filename) then the filename argument MUST be different
236 // from the constructor's one (no overwriting aloud).
237 int SetFileName(string filename);
239 // Allocates necessary memory, copies the data (image[s]/volume[s]) to
240 // newly allocated zone and return a pointer to it:
241 void * GetImageData();
242 // Returns size (in bytes) of required memory to contain data
243 // represented in this file.
244 size_t GetImageDataSize();
245 // Copies (at most MaxSize bytes) of data to caller's memory space.
246 // Returns an error code on failure (if MaxSize is not big enough)
247 int PutImageDataHere(void* destination, size_t MaxSize );
248 // Allocates ExpectedSize bytes of memory at this->Data and copies the
249 // pointed data to it.
250 int SetImageData(void * Data, size_t ExpectedSize);
255 //class gdcmSerie : gdcmFile;
256 //class gdcmMultiFrame : gdcmFile;
260 // * gdcmFile WriteDicom;
261 // WriteDicom.SetFileName("MyDicomFile.dcm");
262 // string * AllTags = gdcmHeader.GetDcmTagNames();
263 // WriteDicom.SetDcmTag(AllTags[5], "253");
264 // WriteDicom.SetDcmTag("Patient Name", "bozo");
265 // WriteDicom.SetDcmTag("Patient Name", "bozo");
266 // WriteDicom.SetImageData(Image);
267 // WriteDicom.Write();
270 // Anonymize(ostream& output) {
271 // a = gdcmFile("toto1");
272 // a.SetPubValueByName("Patient Name", "");
273 // a.SetPubValueByName("Date", "");
274 // a.SetPubValueByName("Study Date", "");