Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | 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/02/05 01:37:09 $
00007   Version:   $Revision: 1.42 $
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 
00028 // TODO
00029 // a lot of troubles expected with TS : 1.2.840.113619.5.2
00030 // Implicit VR - Big Endian
00031 // see : http://www.gemedicalsystemseurope.com/euen/it_solutions/pdf/lsqxi_rev2.pdf
00032 // 
00033 
00034 namespace gdcm 
00035 {
00036 //-----------------------------------------------------------------------------
00037 static const char *SpecialStrings[] =  {
00038   // Implicit VR Little Endian
00039   "1.2.840.10008.1.2",
00040   // Implicit VR Big Endian DLX (G.E Private)
00041   "1.2.840.113619.5.2",
00042   // Explicit VR Little Endian
00043   "1.2.840.10008.1.2.1",
00044   // Deflated Explicit VR Little Endian
00045   "1.2.840.10008.1.2.1.99",
00046   // Explicit VR Big Endian
00047   "1.2.840.10008.1.2.2",
00048   // JPEG Baseline (Process 1)
00049   "1.2.840.10008.1.2.4.50",
00050   // JPEG Extended (Process 2 & 4)
00051   "1.2.840.10008.1.2.4.51",
00052   // JPEG Extended (Process 3 & 5)
00053   "1.2.840.10008.1.2.4.52",
00054   // JPEG Spectral Selection, Non-Hierarchical (Process 6 & 8)
00055   "1.2.840.10008.1.2.4.53",
00056   // JPEG Full Progression, Non-Hierarchical (Process 10 & 12)
00057   "1.2.840.10008.1.2.4.55",
00058   // JPEG Lossless, Non-Hierarchical (Process 14)
00059   "1.2.840.10008.1.2.4.57",
00060   // JPEG Lossless, Hierarchical, First-Order Prediction (Process 14, [Selection Value 1])
00061   "1.2.840.10008.1.2.4.70",
00062   // JPEG-LS Lossless Image Compression
00063   "1.2.840.10008.1.2.4.80",
00064   // JPEG-LS Lossy (Near-Lossless) Image Compression
00065   "1.2.840.10008.1.2.4.81",
00066   // JPEG 2000 Lossless
00067   "1.2.840.10008.1.2.4.90",
00068   // JPEG 2000
00069   "1.2.840.10008.1.2.4.91",
00070   // RLE Lossless
00071   "1.2.840.10008.1.2.5",
00072   // Unknown
00073   "Unknown Transfer Syntax"
00074 };
00075 
00076 //-----------------------------------------------------------------------------
00077 void FillDefaultTSDict(TSHT &ts);
00078 
00079 //-----------------------------------------------------------------------------
00080 // Constructor / Destructor
00081 TS::TS() 
00082 {
00083    std::string filename = DictSet::BuildDictPath() + DICT_TS;
00084    std::ifstream from(filename.c_str());
00085    if( !from )
00086    {
00087       gdcmWarningMacro("Can't open dictionary" << filename.c_str());
00088       FillDefaultTSDict( TsMap );
00089    }
00090    else
00091    {
00092       TSKey key;
00093       TSAtr name;
00094 
00095       while (!from.eof())
00096       {
00097          from >> key;
00098          from >> std::ws;
00099          std::getline(from, name);
00100 
00101          if(key != "")
00102          {
00103             TsMap[key] = name;
00104          }
00105       }
00106       from.close();
00107    }
00108 }
00109 
00110 TS::~TS() 
00111 {
00112    TsMap.clear();
00113 }
00114 
00115 //-----------------------------------------------------------------------------
00116 // Public
00117 int TS::Count(TSKey const &key) 
00118 {
00119    return TsMap.count(key);
00120 }
00121 
00122 TSAtr const &TS::GetValue(TSKey const &key) 
00123 {
00124    // First thing clean up the string sometime the transfer syntax is padded with spaces
00125    std::string copy = key;
00126    while ( copy.size() && !isdigit((unsigned char)copy[copy.size()-1]) )
00127    {
00128       copy.erase(copy.size()-1, 1);
00129    }
00130 
00131    TSHT::const_iterator it = TsMap.find(copy);
00132    if (it == TsMap.end())
00133    {
00134       return GDCM_UNFOUND;
00135    }
00136    return it->second;
00137 }
00144 bool TS::IsTransferSyntax(TSKey const &key)
00145 {
00146    TSHT::const_iterator it = TsMap.find(key);
00147    return it != TsMap.end();
00148 }
00149 
00156 bool TS::IsRLELossless(TSKey const &key)
00157 {
00158    bool r = false;
00159    // First check this is an actual transfer syntax
00160    if( IsTransferSyntax(key) )
00161    {
00162       if ( key == SpecialStrings[RLELossless] )
00163       {
00164          r = true;
00165       }
00166    }
00167    return r;
00168 }
00169 
00176 bool TS::IsJPEGLossless(TSKey const &key)
00177 {
00178    bool r = false;
00179    // First check this is an actual transfer syntax
00180    if( IsTransferSyntax(key) )
00181    {
00182       if ( key == SpecialStrings[JPEGFullProgressionProcess10_12]
00183         || key == SpecialStrings[JPEGLosslessProcess14]
00184         || key == SpecialStrings[JPEGLosslessProcess14_1] )
00185       {
00186          r = true;
00187       }
00188    }
00189    return r;
00190 }
00191 
00198 bool TS::IsJPEGLossy(TSKey const &key)
00199 {
00200    bool r = false;
00201    // First check this is an actual transfer syntax
00202    if( IsTransferSyntax(key) )
00203    {
00204       if ( key == SpecialStrings[JPEGBaselineProcess1]
00205         || key == SpecialStrings[JPEGExtendedProcess2_4]
00206         || key == SpecialStrings[JPEGExtendedProcess3_5]
00207         || key == SpecialStrings[JPEGSpectralSelectionProcess6_8] )
00208       {
00209          r = true;
00210       }
00211    }
00212    return r;
00213 }
00214 
00221 bool TS::IsJPEG2000(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[JPEG2000Lossless]
00228         || key == SpecialStrings[JPEG2000] )
00229       {
00230          r = true;
00231       }
00232    }
00233    return r;
00234 }
00235 
00241 bool TS::IsJPEG(TSKey const &key)
00242 {
00243    bool r = false;
00244    // First check this is an actual transfer syntax
00245    if( IsTransferSyntax(key) )
00246    {
00247       if ( IsJPEGLossy( key )
00248         || IsJPEGLossless( key )
00249          )
00250       {
00251          r = true;
00252       }
00253    }
00254    return r;
00255 }
00256 
00262 bool TS::IsJPEGLS(TSKey const &key)
00263 {
00264    bool r = false;
00265    // First check this is an actual transfer syntax
00266    if( IsTransferSyntax(key) )
00267    {
00268       if ( key == SpecialStrings[JPEGLSLossless]
00269         || key == SpecialStrings[JPEGLSNearLossless] ) 
00270       {
00271          r = true;
00272       }
00273    }
00274    return r;
00275 }
00276 
00277 TS::SpecialType TS::GetSpecialTransferSyntax(TSKey const &key)
00278 {
00279    for (int i = 0; SpecialStrings[i] != NULL; i++)
00280    {
00281       if ( SpecialStrings[i] == key )
00282       {
00283          return SpecialType(i);
00284       }
00285    }
00286 
00287    return UnknownTS;
00288 }
00289 
00290 const char* TS::GetSpecialTransferSyntax(SpecialType t)
00291 {
00292    return SpecialStrings[t];
00293 }
00294 
00295 //-----------------------------------------------------------------------------
00296 // Protected
00297 
00298 //-----------------------------------------------------------------------------
00299 // Private
00300 
00301 //-----------------------------------------------------------------------------
00302 // Print
00307 void TS::Print(std::ostream &os) 
00308 {
00309    std::ostringstream s;
00310 
00311    for (TSHT::const_iterator it = TsMap.begin(); it != TsMap.end(); ++it)
00312    {
00313       s << "TS : " << it->first << " = " << it->second << std::endl;
00314    }
00315    os << s.str();
00316 }
00317 
00318 //-----------------------------------------------------------------------------
00319 } // end namespace gdcm

Generated on Thu Feb 10 22:17:33 2005 for gdcm by doxygen 1.3.6