Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

gdcmTS.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002                                                                                 
00003   Program:   gdcm
00004   Module:    $RCSfile: gdcmTS.cxx,v $
00005   Language:  C++
00006   Date:      $Date: 2005/12/09 12:23:39 $
00007   Version:   $Revision: 1.53 $
00008                                                                                 
00009   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
00010   l'Image). All rights reserved. See Doc/License.txt or
00011   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
00012                                                                                 
00013      This software is distributed WITHOUT ANY WARRANTY; without even
00014      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00015      PURPOSE.  See the above copyright notices for more information.
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> // for isdigit
00028 
00029 // TODO
00030 // troubles expected with TS : 1.2.840.113619.5.2
00031 // Implicit VR - Big Endian
00032 // http://www.gemedicalsystemseurope.com/euen/it_solutions/pdf/lsqxi_rev2.pdf
00033 // G.E. deliberately violated a lot of Dicom rules are
00034 // (probabely to to avoid other people to read their images)
00035 // Just try and error on new images :
00036 // PrintFile debug filein=...
00037 // and fix the bugs
00038 
00039 namespace gdcm 
00040 {
00041 //-----------------------------------------------------------------------------
00043 static const char *SpecialStrings[] =  {
00044   // Implicit VR Little Endian
00045   "1.2.840.10008.1.2",
00046   // Implicit VR Big Endian (G.E Private)
00047   "1.2.840.113619.5.2",
00048   // Explicit VR Little Endian
00049   "1.2.840.10008.1.2.1",
00050   // Deflated Explicit VR Little Endian
00051   "1.2.840.10008.1.2.1.99",
00052   // Explicit VR Big Endian
00053   "1.2.840.10008.1.2.2",
00054   // JPEG Baseline (Process 1)
00055   "1.2.840.10008.1.2.4.50",
00056   // JPEG Extended (Process 2 & 4)
00057   "1.2.840.10008.1.2.4.51",
00058   // JPEG Extended (Process 3 & 5)
00059   "1.2.840.10008.1.2.4.52",
00060   // JPEG Spectral Selection, Non-Hierarchical (Process 6 & 8)
00061   "1.2.840.10008.1.2.4.53",
00062   // JPEG Full Progression, Non-Hierarchical (Process 10 & 12)
00063   "1.2.840.10008.1.2.4.55",
00064   // JPEG Lossless, Non-Hierarchical (Process 14)
00065   "1.2.840.10008.1.2.4.57",
00066   // JPEG Lossless, Hierarchical, First-Order Prediction (Process 14,
00067   //                                                       [Selection Value 1])
00068   "1.2.840.10008.1.2.4.70",
00069   // JPEG-LS Lossless Image Compression
00070   "1.2.840.10008.1.2.4.80",
00071   // JPEG-LS Lossy (Near-Lossless) Image Compression
00072   "1.2.840.10008.1.2.4.81",
00073   // JPEG 2000 Lossless
00074   "1.2.840.10008.1.2.4.90",
00075   // JPEG 2000
00076   "1.2.840.10008.1.2.4.91",
00077   // RLE Lossless
00078   "1.2.840.10008.1.2.5",
00079   // MPEG2 Main Profile @ Main Level
00080   "1.2.840.10008.1.2.4.100",
00081   // Unknown
00082   "Unknown Transfer Syntax", // Pretty sure we never use this case...
00083   NULL // Compilers have no obligation to finish by NULL, do it ourself
00084 };
00085 
00086 //-----------------------------------------------------------------------------
00089 void FillDefaultTSDict(TSHT &ts);
00090 
00091 //-----------------------------------------------------------------------------
00092 // Constructor / Destructor
00093 TS::TS() 
00094 {
00095    std::string filename = DictSet::BuildDictPath() + DICT_TS;
00096    std::ifstream from(filename.c_str());
00097    if ( !from )
00098    {
00099       gdcmWarningMacro("Can't open dictionary" << filename.c_str());
00100       FillDefaultTSDict( TsMap );
00101    }
00102    else
00103    {
00104       TSKey key;
00105       TSAtr name;
00106 
00107       while (!from.eof())
00108       {
00109          from >> key;
00110          from >> std::ws;
00111          std::getline(from, name);
00112 
00113          if (key != "")
00114          {
00115             TsMap[key] = name;
00116          }
00117       }
00118       from.close();
00119    }
00120 }
00121 
00122 TS::~TS() 
00123 {
00124    TsMap.clear();
00125 }
00126 
00127 //-----------------------------------------------------------------------------
00128 // Public
00129 
00131 int TS::Count(TSKey const &key) 
00132 {
00133    return TsMap.count(key);
00134 }
00135 
00137 TSAtr const &TS::GetValue(TSKey const &key) 
00138 {
00139    // First thing clean up the string 
00140    // (sometimes the transfer syntax is padded with spaces)
00141    std::string copy = key;
00142    while ( copy.size() && !isdigit((unsigned char)copy[copy.size()-1]) )
00143    {
00144       copy.erase(copy.size()-1, 1);
00145    }
00146 
00147    TSHT::const_iterator it = TsMap.find(copy);
00148    if (it == TsMap.end())
00149    {
00150       return GDCM_UNFOUND;
00151    }
00152    return it->second;
00153 }
00160 bool TS::IsTransferSyntax(TSKey const &key)
00161 {
00162    TSHT::const_iterator it = TsMap.find(key);
00163    return it != TsMap.end();
00164 }
00165 
00172 bool TS::IsRLELossless(TSKey const &key)
00173 {
00174    bool r = false;
00175    // First check this is an actual transfer syntax
00176    if ( IsTransferSyntax(key) )
00177    {
00178       if ( key == SpecialStrings[RLELossless] )
00179       {
00180          r = true;
00181       }
00182    }
00183    return r;
00184 }
00185 
00192 bool TS::IsJPEGLossless(TSKey const &key)
00193 {
00194    bool r = false;
00195    // First check this is an actual transfer syntax
00196    if ( IsTransferSyntax(key) )
00197    {
00198       if ( key == SpecialStrings[JPEGFullProgressionProcess10_12]
00199         || key == SpecialStrings[JPEGLosslessProcess14]
00200         || key == SpecialStrings[JPEGLosslessProcess14_1] )
00201       {
00202          r = true;
00203       }
00204    }
00205    return r;
00206 }
00207 
00214 bool TS::IsJPEGLossy(TSKey const &key)
00215 {
00216    bool r = false;
00217    // First check this is an actual transfer syntax
00218    if ( IsTransferSyntax(key) )
00219    {
00220       if ( key == SpecialStrings[JPEGBaselineProcess1]
00221         || key == SpecialStrings[JPEGExtendedProcess2_4]
00222         || key == SpecialStrings[JPEGExtendedProcess3_5]
00223         || key == SpecialStrings[JPEGSpectralSelectionProcess6_8] )
00224       {
00225          r = true;
00226       }
00227    }
00228    return r;
00229 }
00230 
00237 bool TS::IsJPEG2000(TSKey const &key)
00238 {
00239    bool r = false;
00240    // First check this is an actual transfer syntax
00241    if ( IsTransferSyntax(key) )
00242    {
00243       if ( key == SpecialStrings[JPEG2000Lossless]
00244         || key == SpecialStrings[JPEG2000] )
00245       {
00246          r = true;
00247       }
00248    }
00249    return r;
00250 }
00251 
00257 bool TS::IsJPEG(TSKey const &key)
00258 {
00259    bool r = false;
00260    // First check this is an actual transfer syntax
00261    if ( IsTransferSyntax(key) )
00262    {
00263       if ( IsJPEGLossy( key )
00264         || IsJPEGLossless( key )
00265         || IsJPEG2000( key )
00266         || IsJPEGLS( key )
00267          )
00268       {
00269          r = true;
00270       }
00271    }
00272    return r;
00273 }
00274 
00280 bool TS::IsJPEGLS(TSKey const &key)
00281 {
00282    bool r = false;
00283    // First check this is an actual transfer syntax
00284    if ( IsTransferSyntax(key) )
00285    {
00286       if ( key == SpecialStrings[JPEGLSLossless]
00287         || key == SpecialStrings[JPEGLSNearLossless] ) 
00288       {
00289          r = true;
00290       }
00291    }
00292    return r;
00293 }
00294 
00300 bool TS::IsMPEG(TSKey const &key)
00301 {
00302    bool r = false;
00303    // First check this is an actual transfer syntax
00304    if ( IsTransferSyntax(key) )
00305    {
00306       if ( key == SpecialStrings[MPEG2MainProfile] ) 
00307       {
00308          r = true;
00309       }
00310    }
00311    return r;
00312 }
00313 
00319 TS::SpecialType TS::GetSpecialTransferSyntax(TSKey const &key)
00320 {
00321    for (int i = 0; SpecialStrings[i] != NULL; i++)
00322    {
00323       if ( SpecialStrings[i] == key )
00324       {
00325          return SpecialType(i);
00326       }
00327    }
00328    return UnknownTS;
00329 }
00330 
00336 const char* TS::GetSpecialTransferSyntax(SpecialType t)
00337 {
00338    return SpecialStrings[t];
00339 }
00340 
00341 //-----------------------------------------------------------------------------
00342 // Protected
00343 
00344 //-----------------------------------------------------------------------------
00345 // Private
00346 
00347 //-----------------------------------------------------------------------------
00348 // Print
00353 void TS::Print(std::ostream &os,std::string const &)
00354 {
00355    std::ostringstream s;
00356 
00357    for (TSHT::const_iterator it = TsMap.begin(); it != TsMap.end(); ++it)
00358    {
00359       s << "TS : " << it->first << " = " << it->second << std::endl;
00360    }
00361    os << s.str();
00362 }
00363 
00364 //-----------------------------------------------------------------------------
00365 } // end namespace gdcm

Generated on Fri Jan 20 10:14:26 2006 for gdcm by  doxygen 1.4.4