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