00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "gdcmTS.h"
00020 #include "gdcmDebug.h"
00021 #include "gdcmUtil.h"
00022 #include "gdcmDictSet.h"
00023
00024 #include <fstream>
00025 #include <string>
00026 #include <iostream>
00027 #include <ctype.h>
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 namespace GDCM_NAME_SPACE
00040 {
00041
00043 static const char *SpecialStrings[] = {
00044
00045 "1.2.840.10008.1.2",
00046
00047 "1.2.840.113619.5.2",
00048
00049 "1.2.840.10008.1.2.1",
00050
00051 "1.2.840.10008.1.2.1.99",
00052
00053 "1.2.840.10008.1.2.2",
00054
00055 "1.2.840.10008.1.2.4.50",
00056
00057 "1.2.840.10008.1.2.4.51",
00058
00059 "1.2.840.10008.1.2.4.52",
00060
00061 "1.2.840.10008.1.2.4.53",
00062
00063 "1.2.840.10008.1.2.4.55",
00064
00065 "1.2.840.10008.1.2.4.57",
00066
00067
00068 "1.2.840.10008.1.2.4.70",
00069
00070 "1.2.840.10008.1.2.4.80",
00071
00072 "1.2.840.10008.1.2.4.81",
00073
00074 "1.2.840.10008.1.2.4.90",
00075
00076 "1.2.840.10008.1.2.4.91",
00077
00078 "1.2.840.10008.1.2.5",
00079
00080 "1.2.840.10008.1.2.4.100",
00081
00082
00083
00084 "1.2.840.10008.5.1.4.1.1.6",
00085
00086
00087 "Unknown Transfer Syntax",
00088 NULL
00089 };
00090
00091
00094 void FillDefaultTSDict(TSHT &ts);
00095
00096
00097
00098 TS::TS()
00099 {
00100
00101 std::string filename = DictSet::BuildDictPath() + DICT_TS;
00102 std::ifstream from(filename.c_str());
00103 if ( !from )
00104 {
00105 gdcmWarningMacro("Can't open dictionary" << filename.c_str());
00106 FillDefaultTSDict( TsMap );
00107 }
00108 else
00109 {
00110 TSKey key;
00111 TSAtr name;
00112
00113 while (!from.eof())
00114 {
00115 from >> key;
00116 from >> std::ws;
00117 std::getline(from, name);
00118
00119 if (key != "")
00120 {
00121 TsMap[key] = name;
00122 }
00123 }
00124
00125 from.close();
00126 }
00127 }
00128
00129 TS::~TS()
00130 {
00131 TsMap.clear();
00132 }
00133
00134
00135
00136
00138 int TS::Count(TSKey const &key)
00139 {
00140 return TsMap.count(key);
00141 }
00142
00144 TSAtr const &TS::GetValue(TSKey const &key)
00145 {
00146
00147
00148 std::string copy = key;
00149 while ( copy.size() && !isdigit((unsigned char)copy[copy.size()-1]) )
00150 {
00151 copy.erase(copy.size()-1, 1);
00152 }
00153
00154 TSHT::const_iterator it = TsMap.find(copy);
00155 if (it == TsMap.end())
00156 {
00157 return GDCM_UNFOUND;
00158 }
00159 return it->second;
00160 }
00167 bool TS::IsTransferSyntax(TSKey const &key)
00168 {
00169 TSHT::const_iterator it = TsMap.find(key);
00170 return it != TsMap.end();
00171 }
00172
00179 bool TS::IsRLELossless(TSKey const &key)
00180 {
00181 bool r = false;
00182
00183 if ( IsTransferSyntax(key) )
00184 {
00185 if ( key == SpecialStrings[RLELossless] )
00186 {
00187 r = true;
00188 }
00189 }
00190 return r;
00191 }
00192
00199 bool TS::IsJPEGLossless(TSKey const &key)
00200 {
00201 bool r = false;
00202
00203 if ( IsTransferSyntax(key) )
00204 {
00205 if ( key == SpecialStrings[JPEGFullProgressionProcess10_12]
00206 || key == SpecialStrings[JPEGLosslessProcess14]
00207 || key == SpecialStrings[JPEGLosslessProcess14_1] )
00208 {
00209 r = true;
00210 }
00211 }
00212 return r;
00213 }
00214
00221 bool TS::IsJPEGLossy(TSKey const &key)
00222 {
00223 bool r = false;
00224
00225 if ( IsTransferSyntax(key) )
00226 {
00227 if ( key == SpecialStrings[JPEGBaselineProcess1]
00228 || key == SpecialStrings[JPEGExtendedProcess2_4]
00229 || key == SpecialStrings[JPEGExtendedProcess3_5]
00230 || key == SpecialStrings[JPEGSpectralSelectionProcess6_8] )
00231 {
00232 r = true;
00233 }
00234 }
00235 return r;
00236 }
00237
00244 bool TS::IsJPEG2000(TSKey const &key)
00245 {
00246 bool r = false;
00247
00248 if ( IsTransferSyntax(key) )
00249 {
00250 if ( key == SpecialStrings[JPEG2000Lossless]
00251 || key == SpecialStrings[JPEG2000] )
00252 {
00253 r = true;
00254 }
00255 }
00256 return r;
00257 }
00258
00264 bool TS::IsJPEG(TSKey const &key)
00265 {
00266 bool r = false;
00267
00268 if ( IsTransferSyntax(key) )
00269 {
00270 if ( IsJPEGLossy( key )
00271 || IsJPEGLossless( key )
00272 || IsJPEG2000( key )
00273 || IsJPEGLS( key )
00274 )
00275 {
00276 r = true;
00277 }
00278 }
00279 return r;
00280 }
00281
00287 bool TS::IsJPEGLS(TSKey const &key)
00288 {
00289 bool r = false;
00290
00291 if ( IsTransferSyntax(key) )
00292 {
00293 if ( key == SpecialStrings[JPEGLSLossless]
00294 || key == SpecialStrings[JPEGLSNearLossless] )
00295 {
00296 r = true;
00297 }
00298 }
00299 return r;
00300 }
00301
00307 bool TS::IsMPEG(TSKey const &key)
00308 {
00309 bool r = false;
00310
00311 if ( IsTransferSyntax(key) )
00312 {
00313 if ( key == SpecialStrings[MPEG2MainProfile] )
00314 {
00315 r = true;
00316 }
00317 }
00318 return r;
00319 }
00320
00326 bool TS::IsUltrasoundImageStorage_Retired(TSKey const &key)
00327 {
00328 bool r = false;
00329
00330 if ( IsTransferSyntax(key) )
00331 {
00332 if ( key == SpecialStrings[UltrasoundImageStorage_Retired] )
00333 {
00334 r = true;
00335 }
00336 }
00337 return r;
00338 }
00344 TS::SpecialType TS::GetSpecialTransferSyntax(TSKey const &key)
00345 {
00346 for (int i = 0; SpecialStrings[i] != NULL; i++)
00347 {
00348 if ( SpecialStrings[i] == key )
00349 {
00350 return SpecialType(i);
00351 }
00352 }
00353 return UnknownTS;
00354 }
00355
00361 const char *TS::GetSpecialTransferSyntax(SpecialType t)
00362 {
00363 return SpecialStrings[t];
00364 }
00365
00366
00367
00368
00369
00370
00371
00372
00373
00378 void TS::Print(std::ostream &os,std::string const &)
00379 {
00380 std::ostringstream s;
00381
00382 for (TSHT::const_iterator it = TsMap.begin(); it != TsMap.end(); ++it)
00383 {
00384 s << "TS : " << it->first << " = " << it->second << std::endl;
00385 }
00386 os << s.str();
00387 }
00388
00389
00390 }