]> Creatis software - gdcm.git/blob - src/gdcmCommon.h
* Correctly use the VRKey for all vr variables... instead of TagName
[gdcm.git] / src / gdcmCommon.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmCommon.h,v $
5   Language:  C++
6   Date:      $Date: 2005/10/18 12:58:27 $
7   Version:   $Revision: 1.95 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18
19 #ifndef GDCMCOMMON_H
20 #define GDCMCOMMON_H
21
22 #include "gdcmConfigure.h"
23 #include "gdcmSystem.h"
24
25 #define FASTTAGKEY 0
26
27 // FIXME: Should rewrite this:
28 #if FASTTAGKEY
29    #include <iostream>
30    #include <iomanip>
31 #endif
32    #if defined(_MSC_VER) && (_MSC_VER == 1200)
33    /* ostream operator for std::string since VS6 does not provide it*/
34       #include <iostream>
35 #endif
36
37 //-----------------------------------------------------------------------------
38 /// \brief namespace for Grass root DiCoM
39 namespace gdcm
40 {
41
42 // Centralize information about the gdcm dictionary in only one file:
43 #ifndef PUB_DICT_PATH
44 #  define PUB_DICT_PATH   "../Dicts/"
45 #endif
46 #define PUB_DICT_NAME     "DicomV3Dict"
47 #define PUB_DICT_FILENAME "gdcm.dic"
48 #define DICT_ELEM         "DicomDir.dic"
49 #define DICT_TS           "dicomTS.dic"
50 #define DICT_VR           "dicomVR.dic"
51 #define DICT_GROUP_NAME   "DictGroupName.dic"
52
53 GDCM_EXPORT extern const std::string GDCM_UNKNOWN;
54 GDCM_EXPORT extern const std::string GDCM_UNFOUND;
55 GDCM_EXPORT extern const std::string GDCM_BINLOADED;
56 GDCM_EXPORT extern const std::string GDCM_NOTLOADED;
57 GDCM_EXPORT extern const std::string GDCM_UNREAD;
58 GDCM_EXPORT extern const std::string GDCM_NOTASCII;
59 GDCM_EXPORT extern const std::string GDCM_PIXELDATA;
60
61 GDCM_EXPORT extern const std::string GDCM_VRUNKNOWN;
62
63 /// \brief TagKey is made to hold the standard Dicom Tag 
64 ///               (Group number, Element number)
65 /// Instead of using the two '16 bits integers' as the Hask Table key, we
66 /// converted into a string (e.g. 0x0018,0x0050 converted into "0018|0050")
67 /// It appears to be a huge waste of time.
68 /// We'll fix the mess up -without any change in the API- as soon as the bench
69 /// marks are fully performed.
70
71 #if FASTTAGKEY
72 typedef union   {
73       uint16_t  tab[2];
74       uint32_t  tagkey;
75     } TagKey;
76 /* ostream operator for TagKey */
77 inline std::ostream& operator<<(std::ostream& _O, TagKey _val)
78 {
79    _O.setf( std::ios::right);
80    return (_O << std::hex << std::setw( 4 ) << std::setfill( '0' )
81       << _val.tab[0] << '|' << std::setw( 4 ) << std::setfill( '0' )
82       << _val.tab[1] << std::setfill( ' ' ) << std::dec);
83 }
84 inline bool operator==(TagKey _self, TagKey _val)
85 {
86    return _self.tagkey == _val.tagkey;
87 }
88 inline bool operator<(TagKey _self, TagKey _val)
89 {
90    // This expression is a tad faster but PrintFile output
91    // is more difficult to read
92    //return _self.tagkey < _val.tagkey;
93
94    // More usal order of dicom tags:
95    if( _self.tab[0] == _val.tab[0] )
96       return _self.tab[1] < _val.tab[1];
97    return _self.tab[0] < _val.tab[0];
98 }
99 #else
100 typedef std::string TagKey;
101 #endif
102 #if defined(_MSC_VER) && (_MSC_VER == 1200)
103 // Doing everything within gdcm namespace to avoid polluting 3d party software
104 inline std::ostream& operator<<(std::ostream& _O, std::string _val)
105 {
106   return _O << _val.c_str();
107 }
108 #endif
109
110 /// \brief TagName is made to hold the 'non hexa" fields (VR, VM, Name) 
111 ///        of Dicom Entries
112 typedef std::string TagName;
113
114 /// \brief various types of a DICOM file (for internal use only)
115 enum FileType {
116    Unknown = 0,
117    ExplicitVR, // DicomDir is in this case. Except when it's ImplicitVR !...
118    ImplicitVR,
119    ACR,
120    ACR_LIBIDO
121 };
122
123 /// \brief type of the elements composing a DICOMDIR (for internal use only)
124 enum DicomDirType {
125    DD_UNKNOWN = 0,
126    DD_META,
127    DD_PATIENT,
128    DD_STUDY,
129    DD_SERIE,
130    DD_IMAGE,
131    DD_VISIT
132 };
133
134 /// \brief comparison operators (as used in SerieHelper::AddRestriction() )
135 enum CompOperators {
136    GDCM_EQUAL = 0,
137    GDCM_DIFFERENT,
138    GDCM_GREATER,
139    GDCM_GREATEROREQUAL,
140    GDCM_LESS,
141    GDCM_LESSOREQUAL
142 };
143
144 /// \brief Loading mode
145 enum LodModeType
146 {
147    LD_ALL         = 0x00000000, // Load all
148    LD_NOSEQ       = 0x00000001, // Don't load Sequences
149    LD_NOSHADOW    = 0x00000002, // Don't load odd groups
150    LD_NOSHADOWSEQ = 0x00000004  // Don't load Sequences if they belong 
151                                 //            to an odd group
152                                 // (*exclusive* from LD_NOSEQ and LD_NOSHADOW)
153 };
154
155 /**
156  * \brief structure, for internal use only
157  */  
158 struct Element
159 {
160    /// DicomGroup number
161    unsigned short int Group;
162    /// DicomElement number
163    unsigned short int Elem;
164    /// value (coded as a std::string) of the Element
165    std::string Value;
166 };
167
168 } //namespace gdcm
169 //-----------------------------------------------------------------------------
170 #endif