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: 2007/05/23 14:18:11 $
00007   Version:   $Revision: 1.55 $
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_NAME_SPACE 
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   
00082   // The following are *not* t.s. but SOP uid
00083   // Ultrasound Image Storage (Retired)
00084   "1.2.840.10008.5.1.4.1.1.6",
00085      
00086   // Unknown
00087   "Unknown Transfer Syntax", // Pretty sure we never use this case...
00088   NULL // Compilers have no obligation to finish by NULL, do it ourself
00089 };
00090 
00091 //-----------------------------------------------------------------------------
00094 void FillDefaultTSDict(TSHT &ts);
00095 
00096 //-----------------------------------------------------------------------------
00097 // Constructor / Destructor
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 // Public
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    // First thing clean up the string 
00147    // (sometimes the transfer syntax is padded with spaces)
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    // First check this is an actual transfer syntax
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    // First check this is an actual transfer syntax
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    // First check this is an actual transfer syntax
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    // First check this is an actual transfer syntax
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    // First check this is an actual transfer syntax
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    // First check this is an actual transfer syntax
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    // First check this is an actual transfer syntax
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    // First check this is an actual SOP id
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 // Protected
00368 
00369 //-----------------------------------------------------------------------------
00370 // Private
00371 
00372 //-----------------------------------------------------------------------------
00373 // Print
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 } // end namespace gdcm

Generated on Fri Aug 24 12:53:18 2007 for gdcm by  doxygen 1.4.6