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