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

gdcmDicomDir Class Reference

#include <gdcmDicomDir.h>

Inheritance diagram for gdcmDicomDir:

gdcmParser List of all members.

Public Types

enum  gdcmDicomDirType {
  GDCM_NONE, GDCM_PATIENT, GDCM_STUDY, GDCM_SERIE,
  GDCM_IMAGE
}

Public Member Functions

 gdcmDicomDir (const char *FileName, bool parseDir=false, bool exception_on_error=false)
 ~gdcmDicomDir (void)
void SetPrintLevel (int level)
 Sets the print level for the Dicom Header.

virtual void Print (std::ostream &os=std::cout)
ListPatientGetPatients ()
bool Write (std::string fileName)
 writes on disc a DICOMDIR \ warning does NOT add the missing elements in the header : it's up to the user doing it !

void ParseDirectory (void)
virtual void PrintEntry (std::ostream &os=std::cout)
 Prints the Header Entries (Dicom Elements) both from the H Table and the chained list.

virtual void PrintPubDict (std::ostream &os=std::cout)
 Prints The Dict Entries of THE public Dicom Dictionnry.

virtual void PrintShaDict (std::ostream &os=std::cout)
 Prints The Dict Entries of THE shadow Dicom Dictionnry.

std::string GetFileName (void)
gdcmDictGetPubDict (void)
 Get the public dictionary used.

gdcmDictGetShaDict (void)
 Get the shadow dictionary used.

bool SetShaDict (gdcmDict *dict)
 Set the shadow dictionary used.

bool SetShaDict (DictKey dictName)
 Set the shadow dictionary used.

virtual bool IsReadable (void)
 This predicate, based on hopefully reasonable heuristics, decides whether or not the current gdcmParser was properly parsed and contains the mandatory information for being considered as a well formed and usable Dicom/Acr File.

bool IsImplicitVRLittleEndianTransferSyntax (void)
 Determines if the Transfer Syntax was already encountered and if it corresponds to a ImplicitVRLittleEndian one.

bool IsExplicitVRLittleEndianTransferSyntax (void)
 Determines if the Transfer Syntax was already encountered and if it corresponds to a ExplicitVRLittleEndian one.

bool IsDeflatedExplicitVRLittleEndianTransferSyntax (void)
 Determines if the Transfer Syntax was already encountered and if it corresponds to a DeflatedExplicitVRLittleEndian one.

bool IsExplicitVRBigEndianTransferSyntax (void)
 Determines if the Transfer Syntax was already encountered and if it corresponds to a Explicit VR Big Endian one.

FileType GetFileType (void)
 returns the File Type (ACR, ACR_LIBIDO, ExplicitVR, ImplicitVR, Unknown)

TagHeaderEntryHTGetEntry (void)
 returns a ref to the Dicom Header H table (multimap) return the Dicom Header H table

ListTagGetListEntry (void)
 returns a ref to the Dicom Header chained list return the Dicom Header chained list

FILE * OpenFile (bool exception_on_error=false) throw (gdcmFileError)
 opens the file

bool CloseFile (void)
 closes the file

virtual bool Write (FILE *, FileType)
bool ReplaceOrCreateByNumber (std::string Value, guint16 Group, guint16 Elem)
 Modifies the value of a given Header Entry (Dicom Element) if it exists; Creates it with the given value if it doesn't.

bool ReplaceOrCreateByNumber (char *Value, guint16 Group, guint16 Elem)
 Modifies the value of a given Header Entry (Dicom Element) if it exists; Creates it with the given value if it doesn't.

bool ReplaceIfExistByNumber (char *Value, guint16 Group, guint16 Elem)
 Set a new value if the invoked element exists Seems to be useless !!!

int GetSwapCode (void)
guint16 GetGrPixel (void)
guint16 GetNumPixel (void)
guint16 SwapShort (guint16)
 Swaps the bytes so they agree with the processor order.

guint32 SwapLong (guint32)
 Swaps back the bytes of 4-byte long integer accordingly to processor order.

guint16 UnswapShort (guint16)
 Unswaps the bytes so they agree with the processor order.

guint32 UnswapLong (guint32)
 Unswaps back the bytes of 4-byte long integer accordingly to processor order.


Protected Member Functions

void NewDicomDir (std::string path)
std::string GetPath (void)
int CheckIfEntryExistByNumber (guint16 Group, guint16 Elem)
 Checks if a given Dicom Element exists within the H table.

virtual std::string GetEntryByName (std::string tagName)
 Searches within Header Entries (Dicom Elements) parsed with the public and private dictionaries for the element value of a given tag.

virtual std::string GetEntryVRByName (std::string tagName)
 Searches within Header Entries (Dicom Elements) parsed with the public and private dictionaries for the element value representation of a given tag.

virtual std::string GetEntryByNumber (guint16 group, guint16 element)
 Searches within Header Entries (Dicom Elements) parsed with the public and private dictionaries for the element value representation of a given tag.

virtual std::string GetEntryVRByNumber (guint16 group, guint16 element)
 Searches within Header Entries (Dicom Elements) parsed with the public and private dictionaries for the element value representation of a given tag..

virtual bool SetEntryByName (std::string content, std::string tagName)
 Sets the value (string) of the Header Entry (Dicom Element).

virtual bool SetEntryByNumber (std::string content, guint16 group, guint16 element)
 Accesses an existing gdcmHeaderEntry (i.e. a Dicom Element) through it's (group, element) and modifies it's content with the given value.

virtual bool SetEntryLengthByNumber (guint32 length, guint16 group, guint16 element)
 Accesses an existing gdcmHeaderEntry (i.e. a Dicom Element) in the PubHeaderEntrySet of this instance through it's (group, element) and modifies it's length with the given value.

virtual size_t GetEntryOffsetByNumber (guint16 Group, guint16 Elem)
 Gets (from Header) the offset of a 'non string' element value (LoadElementValues has already be executed).

virtual void * GetEntryVoidAreaByNumber (guint16 Group, guint16 Elem)
 Gets (from Header) a 'non string' element value (LoadElementValues has already be executed).

virtual void * LoadEntryVoidArea (guint16 Group, guint16 Element)
 Loads (from disk) the element content when a string is not suitable.

virtual bool SetEntryVoidAreaByNumber (void *a, guint16 Group, guint16 Elem)
 Sets a 'non string' value to a given Dicom Element.

virtual void UpdateShaEntries (void)
 Update the entries with the shadow dictionary. Only non even entries are analyzed.

gdcmHeaderEntryGetHeaderEntryByNumber (guint16 group, guint16 element)
 retrieves a Dicom Element (the first one) using (group, element)

gdcmHeaderEntryGetHeaderEntryByName (std::string Name)
 Searches within the Header Entries for a Dicom Element of a given tag.

IterHT GetHeaderEntrySameNumber (guint16 group, guint16 element)
 retrieves the Dicom Elements (all of them) using (group, element)

void LoadHeaderEntrySafe (gdcmHeaderEntry *)
 Loads the element while preserving the current underlying file position indicator as opposed to to LoadHeaderEntry that modifies it.

void UpdateGroupLength (bool SkipSequence=false, FileType type=ImplicitVR)
 Re-computes the length of a ACR-NEMA/Dicom group from a DcmHeader.

void WriteEntries (FILE *_fp, FileType type)
 writes on disc according to the requested format (ACR-NEMA, ExplicitVR, ImplicitVR) the image


Protected Attributes

FILE * fp
FileType filetype
TagHeaderEntryHT tagHT
ListTag listEntries
int enableSequences
int printLevel
guint16 GrPixel
guint16 NumPixel
int countGrPixel

Static Protected Attributes

const unsigned int HEADER_LENGTH_TO_READ = 256
const unsigned int MAX_SIZE_LOAD_ELEMENT_VALUE = 4096
const unsigned int MAX_SIZE_PRINT_ELEMENT_VALUE = 64

Private Member Functions

void CreateDicomDir (void)
void AddObjectToEnd (gdcmDicomDirType type, ListTag::iterator begin, ListTag::iterator end)
void AddPatientToEnd (ListTag::iterator begin, ListTag::iterator end)
void AddStudyToEnd (ListTag::iterator begin, ListTag::iterator end)
void AddSerieToEnd (ListTag::iterator begin, ListTag::iterator end)
void AddImageToEnd (ListTag::iterator begin, ListTag::iterator end)
void SetElements (std::string &path, ListHeader &list)
void SetElement (std::string &path, gdcmDicomDirType type, gdcmHeader *header)

Static Private Member Functions

bool HeaderLessThan (gdcmHeader *header1, gdcmHeader *header2)

Private Attributes

ListPatient patients

Member Enumeration Documentation

enum gdcmDicomDir::gdcmDicomDirType
 

Enumeration values:
GDCM_NONE 
GDCM_PATIENT 
GDCM_STUDY 
GDCM_SERIE 
GDCM_IMAGE 

Definition at line 43 of file gdcmDicomDir.h.

Referenced by CreateDicomDir().

00044    {
00045       GDCM_NONE,
00046       GDCM_PATIENT,
00047       GDCM_STUDY,
00048       GDCM_SERIE,
00049       GDCM_IMAGE,
00050    } gdcmDicomDirType;


Constructor & Destructor Documentation

gdcmDicomDir::gdcmDicomDir const char *  FileName,
bool  parseDir = false,
bool  exception_on_error = false
 

Definition at line 24 of file gdcmDicomDir.cxx.

References CreateDicomDir(), dbg, gdcmParser::GetListEntry(), ParseDirectory(), and gdcmDebug::Verbose().

00025                                                    :
00026    gdcmParser(FileName,exception_on_error,true)
00027 {
00028    if( GetListEntry().begin()==GetListEntry().end() ) 
00029    {
00030       dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : entry list empty");
00031 
00032       if(parseDir)
00033       {
00034          dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : Parse directory and create the DicomDir");
00035          ParseDirectory();
00036       }
00037    }
00038    else
00039       CreateDicomDir();
00040 }

gdcmDicomDir::~gdcmDicomDir void   ) 
 

Definition at line 59 of file gdcmDicomDir.cxx.

References patients.

00060 {
00061    for(ListPatient::iterator cc=patients.begin();cc!=patients.end();++cc)
00062    {
00063       delete *cc;
00064    }
00065 }


Member Function Documentation

void gdcmDicomDir::AddImageToEnd ListTag::iterator  begin,
ListTag::iterator  end
[private]
 

Definition at line 325 of file gdcmDicomDir.cxx.

References patients.

Referenced by AddObjectToEnd().

00326 {
00327    if(patients.size()>0)
00328    {
00329       ListPatient::iterator itp=patients.end();
00330       itp--;
00331 
00332       if((*itp)->GetStudies().size()>0)
00333       {
00334          ListStudy::iterator itst=(*itp)->GetStudies().end();
00335          itst--;
00336 
00337          if((*itst)->GetSeries().size()>0)
00338          {
00339             ListSerie::iterator its=(*itst)->GetSeries().end();
00340             its--;
00341            (*its)->AddImage(new gdcmImage(begin,end));
00342          }
00343       }
00344    }
00345 }

void gdcmDicomDir::AddObjectToEnd gdcmDicomDirType  type,
ListTag::iterator  begin,
ListTag::iterator  end
[private]
 

Definition at line 249 of file gdcmDicomDir.cxx.

References AddImageToEnd(), AddPatientToEnd(), AddSerieToEnd(), AddStudyToEnd(), GDCM_IMAGE, GDCM_PATIENT, GDCM_SERIE, and GDCM_STUDY.

Referenced by CreateDicomDir().

00250 {
00251    if(begin==end)
00252       return;
00253 
00254    switch(type)
00255    {
00256       case gdcmDicomDir::GDCM_PATIENT:
00257          AddPatientToEnd(begin,end);
00258          break;
00259       case gdcmDicomDir::GDCM_STUDY:
00260          AddStudyToEnd(begin,end);
00261          break;
00262       case gdcmDicomDir::GDCM_SERIE:
00263          AddSerieToEnd(begin,end);
00264          break;
00265       case gdcmDicomDir::GDCM_IMAGE:
00266          AddImageToEnd(begin,end);
00267          break;
00268    }
00269 }

void gdcmDicomDir::AddPatientToEnd ListTag::iterator  begin,
ListTag::iterator  end
[private]
 

Definition at line 277 of file gdcmDicomDir.cxx.

References patients.

Referenced by AddObjectToEnd().

00278 {
00279    patients.push_back(new gdcmPatient(begin,end));
00280 }

void gdcmDicomDir::AddSerieToEnd ListTag::iterator  begin,
ListTag::iterator  end
[private]
 

Definition at line 303 of file gdcmDicomDir.cxx.

References patients.

Referenced by AddObjectToEnd().

00304 {
00305    if(patients.size()>0)
00306    {
00307       ListPatient::iterator itp=patients.end();
00308       itp--;
00309 
00310       if((*itp)->GetStudies().size()>0)
00311       {
00312          ListStudy::iterator itst=(*itp)->GetStudies().end();
00313          itst--;
00314         (*itst)->AddSerie(new gdcmSerie(begin,end));
00315       }
00316    }
00317 }

void gdcmDicomDir::AddStudyToEnd ListTag::iterator  begin,
ListTag::iterator  end
[private]
 

Definition at line 288 of file gdcmDicomDir.cxx.

References patients.

Referenced by AddObjectToEnd().

00289 {
00290    if(patients.size()>0)
00291    {
00292       ListPatient::iterator itp=patients.end();
00293       itp--;
00294      (*itp)->AddStudy(new gdcmStudy(begin,end));
00295    }
00296 }

int gdcmParser::CheckIfEntryExistByNumber guint16  group,
guint16  element
[protected, inherited]
 

Checks if a given Dicom Element exists within the H table.

Parameters:
group Group number of the searched Dicom Element
element Element number of the searched Dicom Element
Returns:
number of occurences

Definition at line 509 of file gdcmParser.cxx.

References gdcmParser::tagHT, and gdcmDictEntry::TranslateToKey().

Referenced by gdcmParser::ReplaceOrCreateByNumber().

00509                                                                          {
00510         std::string key = gdcmDictEntry::TranslateToKey(group, element );
00511         return (tagHT.count(key));
00512 }

bool gdcmParser::CloseFile void   )  [inherited]
 

closes the file

Returns:
TRUE if the close was successfull

Definition at line 365 of file gdcmParser.cxx.

References gdcmParser::fp.

Referenced by gdcmParser::gdcmParser(), gdcmFile::ParsePixelData(), and gdcmFile::ReadPixelData().

00365                                {
00366   int closed = fclose(fp);
00367   fp = (FILE *)0;
00368   if (! closed)
00369      return false;
00370   return true;
00371 }

void gdcmDicomDir::CreateDicomDir void   )  [private]
 

Definition at line 184 of file gdcmDicomDir.cxx.

References AddObjectToEnd(), GDCM_IMAGE, GDCM_NONE, GDCM_PATIENT, GDCM_SERIE, GDCM_STUDY, gdcmDicomDirType, and gdcmParser::GetListEntry().

Referenced by gdcmDicomDir(), and ParseDirectory().

00185 {
00186    // The list is parsed. When a tag is found :
00187    //  1 - we save the beginning iterator
00188    //  2 - we continue to parse
00189    //  3 - we find an other tag
00190    //       + we create the object for the precedent tag
00191    //       + loop to 1 -
00192 
00193    gdcmDicomDirType type=gdcmDicomDir::GDCM_NONE;
00194    ListTag::iterator begin;
00195    ListTag::iterator end;
00196 
00197    begin=listEntries.begin();
00198    end=begin;
00199    for(ListTag::iterator i=listEntries.begin();i !=listEntries.end();++i) 
00200    {
00201       std::string v=(*i)->GetValue();
00202       if(v=="PATIENT ") 
00203       {
00204          end=i;
00205          AddObjectToEnd(type,begin,end);
00206 
00207          type=gdcmDicomDir::GDCM_PATIENT;
00208          begin=end;
00209       } 
00210 
00211       if(v=="STUDY ")
00212       {
00213          end=i;
00214          AddObjectToEnd(type,begin,end);
00215 
00216          type=gdcmDicomDir::GDCM_STUDY;
00217          begin=end;
00218       }
00219 
00220       if(v=="SERIES") 
00221       {
00222          end=i;
00223          AddObjectToEnd(type,begin,end);
00224 
00225          type=gdcmDicomDir::GDCM_SERIE;
00226          begin=end;
00227       }
00228 
00229       if(v=="IMAGE ") 
00230       {
00231          end=i;
00232          AddObjectToEnd(type,begin,end);
00233 
00234          type=gdcmDicomDir::GDCM_IMAGE;
00235          begin=end;
00236       }
00237    }
00238 
00239    end=GetListEntry().end();
00240    AddObjectToEnd(type,begin,end);
00241 }

TagHeaderEntryHT& gdcmParser::GetEntry void   )  [inline, inherited]
 

returns a ref to the Dicom Header H table (multimap) return the Dicom Header H table

Definition at line 80 of file gdcmParser.h.

References TagHeaderEntryHT.

Referenced by gdcmHeader::gdcmHeader(), and gdcmFile::WriteBase().

00080 { return tagHT; };

std::string gdcmParser::GetEntryByName std::string  tagName  )  [protected, virtual, inherited]
 

Searches within Header Entries (Dicom Elements) parsed with the public and private dictionaries for the element value of a given tag.

Warning:
Don't use any longer : use GetPubEntryByName
Parameters:
tagName name of the searched element.
Returns:
Corresponding element value when it exists, and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.

Reimplemented in gdcmHeader.

Definition at line 524 of file gdcmParser.cxx.

References GDCM_UNFOUND, gdcmDict::GetDictEntryByName(), gdcmDictEntry::GetElement(), gdcmParser::GetEntryByNumber(), gdcmDictEntry::GetGroup(), and gdcmParser::RefPubDict.

Referenced by gdcmHeader::GetEntryByName().

00524                                                       {
00525    gdcmDictEntry *dictEntry = RefPubDict->GetDictEntryByName(tagName); 
00526    if( dictEntry == NULL)
00527       return GDCM_UNFOUND;
00528 
00529    return(GetEntryByNumber(dictEntry->GetGroup(),dictEntry->GetElement()));  
00530 }

std::string gdcmParser::GetEntryByNumber guint16  group,
guint16  element
[protected, virtual, inherited]
 

Searches within Header Entries (Dicom Elements) parsed with the public and private dictionaries for the element value representation of a given tag.

Parameters:
group Group of the searched tag.
element Element of the searched tag.
Returns:
Corresponding element value representation when it exists, and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.

Reimplemented in gdcmHeader.

Definition at line 566 of file gdcmParser.cxx.

References GDCM_UNFOUND, gdcmParser::tagHT, TagKey, and gdcmDictEntry::TranslateToKey().

Referenced by gdcmParser::GetEntryByName(), gdcmHeader::GetEntryByNumber(), and gdcmParser::LoadHeaderEntries().

00566                                                                     {
00567    TagKey key = gdcmDictEntry::TranslateToKey(group, element);
00568    if ( ! tagHT.count(key))
00569       return GDCM_UNFOUND;
00570    return tagHT.find(key)->second->GetValue();
00571 }

size_t gdcmParser::GetEntryOffsetByNumber guint16  Group,
guint16  Elem
[protected, virtual, inherited]
 

Gets (from Header) the offset of a 'non string' element value (LoadElementValues has already be executed).

Parameters:
Group group of the Entry
Elem element of the Entry
Returns:
File Offset of the Element Value

Definition at line 695 of file gdcmParser.cxx.

References dbg, gdcmParser::GetHeaderEntryByNumber(), gdcmHeaderEntry::GetOffset(), and gdcmDebug::Verbose().

00696 {
00697    gdcmHeaderEntry* Entry = GetHeaderEntryByNumber(Group, Elem);         
00698    if (!Entry) 
00699    {
00700       dbg.Verbose(1, "gdcmParser::GetHeaderEntryByNumber",
00701                       "failed to Locate gdcmHeaderEntry");
00702       return (size_t)0;
00703    }
00704    return Entry->GetOffset();
00705 }

void * gdcmParser::GetEntryVoidAreaByNumber guint16  Group,
guint16  Elem
[protected, virtual, inherited]
 

Gets (from Header) a 'non string' element value (LoadElementValues has already be executed).

Parameters:
Group group of the Entry
Elem element of the Entry
Returns:
Pointer to the 'non string' area

Definition at line 715 of file gdcmParser.cxx.

References dbg, gdcmParser::GetHeaderEntryByNumber(), gdcmHeaderEntry::GetVoidArea(), and gdcmDebug::Verbose().

Referenced by gdcmHeader::GetLUTRGBA().

00716 {
00717    gdcmHeaderEntry* Entry = GetHeaderEntryByNumber(Group, Elem);         
00718    if (!Entry) 
00719    {
00720       dbg.Verbose(1, "gdcmParser::GetHeaderEntryByNumber",
00721                   "failed to Locate gdcmHeaderEntry");
00722       return (NULL);
00723    }
00724    return Entry->GetVoidArea();
00725 }

std::string gdcmParser::GetEntryVRByName std::string  tagName  )  [protected, virtual, inherited]
 

Searches within Header Entries (Dicom Elements) parsed with the public and private dictionaries for the element value representation of a given tag.

Obtaining the VR (Value Representation) might be needed by caller to convert the string typed content to caller's native type (think of C++ vs Python). The VR is actually of a higher level of semantics than just the native C++ type.

Parameters:
tagName name of the searched element.
Returns:
Corresponding element value representation when it exists, and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.

Reimplemented in gdcmHeader.

Definition at line 546 of file gdcmParser.cxx.

References GDCM_UNFOUND, gdcmDict::GetDictEntryByName(), gdcmDictEntry::GetElement(), gdcmDictEntry::GetGroup(), gdcmParser::GetHeaderEntryByNumber(), gdcmHeaderEntry::GetVR(), and gdcmParser::RefPubDict.

Referenced by gdcmHeader::GetEntryVRByName().

00546                                                         {
00547    gdcmDictEntry *dictEntry = RefPubDict->GetDictEntryByName(tagName); 
00548    if( dictEntry == NULL)
00549       return GDCM_UNFOUND;
00550 
00551    gdcmHeaderEntry* elem =  GetHeaderEntryByNumber(dictEntry->GetGroup(),
00552                                                    dictEntry->GetElement());                                    
00553    return elem->GetVR();
00554 }

std::string gdcmParser::GetEntryVRByNumber guint16  group,
guint16  element
[protected, virtual, inherited]
 

Searches within Header Entries (Dicom Elements) parsed with the public and private dictionaries for the element value representation of a given tag..

Obtaining the VR (Value Representation) might be needed by caller to convert the string typed content to caller's native type (think of C++ vs Python). The VR is actually of a higher level of semantics than just the native C++ type.

Parameters:
group Group of the searched tag.
element Element of the searched tag.
Returns:
Corresponding element value representation when it exists, and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.

Reimplemented in gdcmHeader.

Definition at line 588 of file gdcmParser.cxx.

References GDCM_UNFOUND, gdcmParser::GetHeaderEntryByNumber(), and gdcmHeaderEntry::GetVR().

Referenced by gdcmHeader::GetEntryVRByNumber().

00588                                                                        {
00589    gdcmHeaderEntry* elem =  GetHeaderEntryByNumber(group, element);
00590    if ( !elem )
00591       return GDCM_UNFOUND;
00592    return elem->GetVR();
00593 }

std::string gdcmParser::GetFileName void   )  [inline, inherited]
 

Definition at line 58 of file gdcmParser.h.

Referenced by GetPath(), and SetElement().

00058 {return filename;}

FileType gdcmParser::GetFileType void   )  [inherited]
 

returns the File Type (ACR, ACR_LIBIDO, ExplicitVR, ImplicitVR, Unknown)

Returns:
the FileType code

Definition at line 315 of file gdcmParser.cxx.

References gdcmParser::filetype, and FileType.

Referenced by gdcmFile::WriteBase().

00315                                      {
00316    return(filetype);
00317 }

guint16 gdcmParser::GetGrPixel void   )  [inline, inherited]
 

Definition at line 102 of file gdcmParser.h.

Referenced by gdcmFile::WriteBase().

00102 {return GrPixel;}

gdcmHeaderEntry * gdcmParser::GetHeaderEntryByName std::string  tagName  )  [protected, inherited]
 

Searches within the Header Entries for a Dicom Element of a given tag.

Parameters:
tagName name of the searched Dicom Element.
Returns:
Corresponding Dicom Element when it exists, and NULL otherwise.

Definition at line 829 of file gdcmParser.cxx.

References gdcmDict::GetDictEntryByName(), gdcmDictEntry::GetElement(), gdcmDictEntry::GetGroup(), gdcmParser::GetHeaderEntryByNumber(), and gdcmParser::RefPubDict.

00829                                                                     {
00830    gdcmDictEntry *dictEntry = RefPubDict->GetDictEntryByName(tagName); 
00831    if( dictEntry == NULL)
00832       return NULL;
00833 
00834   return(GetHeaderEntryByNumber(dictEntry->GetGroup(),dictEntry->GetElement()));
00835 }

gdcmHeaderEntry * gdcmParser::GetHeaderEntryByNumber guint16  group,
guint16  element
[protected, inherited]
 

retrieves a Dicom Element (the first one) using (group, element)

Warning:
(group, element) IS NOT an identifier inside the Dicom Header if you think it's NOT UNIQUE, check the count number and use iterators to retrieve ALL the Dicoms Elements within a given couple (group, element)
Parameters:
group Group number of the searched Dicom Element
element Element number of the searched Dicom Element
Returns:

Definition at line 848 of file gdcmParser.cxx.

References gdcmParser::tagHT, TagKey, and gdcmDictEntry::TranslateToKey().

Referenced by gdcmHeader::anonymizeHeader(), gdcmParser::GetEntryOffsetByNumber(), gdcmParser::GetEntryVoidAreaByNumber(), gdcmParser::GetEntryVRByName(), gdcmParser::GetEntryVRByNumber(), gdcmParser::GetHeaderEntryByName(), gdcmHeader::HasLUT(), gdcmParser::IsDeflatedExplicitVRLittleEndianTransferSyntax(), gdcmHeader::IsDicomV3(), gdcmParser::IsExplicitVRBigEndianTransferSyntax(), gdcmParser::IsExplicitVRLittleEndianTransferSyntax(), gdcmParser::IsImplicitVRLittleEndianTransferSyntax(), gdcmHeader::IsJPEG2000(), gdcmHeader::IsJPEGBaseLineProcess1TransferSyntax(), gdcmHeader::IsJPEGExtendedProcess2_4TransferSyntax(), gdcmHeader::IsJPEGExtendedProcess3_5TransferSyntax(), gdcmHeader::IsJPEGLossless(), gdcmHeader::IsJPEGSpectralSelectionProcess6_8TransferSyntax(), gdcmHeader::IsReadable(), gdcmHeader::IsRLELossLessTransferSyntax(), gdcmParser::LoadEntryVoidArea(), gdcmHeader::SetImageDataSize(), and gdcmParser::UpdateGroupLength().

00849 {
00850    TagKey key = gdcmDictEntry::TranslateToKey(group, element);
00851    if ( ! tagHT.count(key))
00852       return NULL;
00853    return tagHT.find(key)->second;
00854 }

IterHT gdcmParser::GetHeaderEntrySameNumber guint16  group,
guint16  element
[protected, inherited]
 

retrieves the Dicom Elements (all of them) using (group, element)

Parameters:
group Group number of the searched Dicom Element.
element Element number of the searched Dicom Element.
Returns:
a range (i.e.pair<,>) containing all elements whose key is group|element)

Definition at line 864 of file gdcmParser.cxx.

References IterHT, gdcmParser::tagHT, TagKey, and gdcmDictEntry::TranslateToKey().

Referenced by gdcmHeader::GetPixelAreaLength(), and gdcmHeader::GetPixelOffset().

00864                                                                          {
00865    TagKey key = gdcmDictEntry::TranslateToKey(group, element);
00866    return (tagHT.equal_range(key));
00867 }

ListTag& gdcmParser::GetListEntry void   )  [inline, inherited]
 

returns a ref to the Dicom Header chained list return the Dicom Header chained list

Definition at line 87 of file gdcmParser.h.

References ListTag.

Referenced by CreateDicomDir(), gdcmDicomDir(), and gdcmParser::LoadHeaderEntries().

00087 { return listEntries; };

guint16 gdcmParser::GetNumPixel void   )  [inline, inherited]
 

Definition at line 103 of file gdcmParser.h.

Referenced by gdcmFile::WriteBase().

00103 {return NumPixel;}

std::string gdcmDicomDir::GetPath void   )  [protected]
 

Definition at line 163 of file gdcmDicomDir.cxx.

References gdcmParser::GetFileName().

Referenced by ParseDirectory().

00164 {
00165    std::string path=GetFileName();
00166 
00167    int pos1=path.rfind("/");
00168    int pos2=path.rfind("\\");
00169    if(pos1>pos2)
00170       path.resize(pos1);
00171    else
00172       path.resize(pos2);
00173 
00174    return(path);
00175 }

ListPatient& gdcmDicomDir::GetPatients  )  [inline]
 

Definition at line 36 of file gdcmDicomDir.h.

References ListPatient.

00036 {return patients;};

gdcmDict * gdcmParser::GetPubDict void   )  [inherited]
 

Get the public dictionary used.

Definition at line 185 of file gdcmParser.cxx.

References gdcmParser::RefPubDict.

Referenced by SetElement().

00185                                      {
00186    return(RefPubDict);
00187 }

gdcmDict * gdcmParser::GetShaDict void   )  [inherited]
 

Get the shadow dictionary used.

Definition at line 193 of file gdcmParser.cxx.

References gdcmParser::RefShaDict.

00193                                      {
00194    return(RefShaDict);
00195 }

int gdcmParser::GetSwapCode void   )  [inline, inherited]
 

Definition at line 101 of file gdcmParser.h.

Referenced by gdcmFile::gdcm_read_RLE_file(), gdcmFile::GetImageDataIntoVectorRaw(), gdcmFile::ParsePixelData(), and gdcmFile::ReadPixelData().

00101 { return sw; }

bool gdcmDicomDir::HeaderLessThan gdcmHeader header1,
gdcmHeader header2
[static, private]
 

Definition at line 500 of file gdcmDicomDir.cxx.

Referenced by NewDicomDir().

00501 {
00502    return(*header1<*header2);
00503 }

bool gdcmParser::IsDeflatedExplicitVRLittleEndianTransferSyntax void   )  [inherited]
 

Determines if the Transfer Syntax was already encountered and if it corresponds to a DeflatedExplicitVRLittleEndian one.

Returns:
True when DeflatedExplicitVRLittleEndian found. False in all other cases.

Definition at line 279 of file gdcmParser.cxx.

References gdcmParser::GetHeaderEntryByNumber(), gdcmHeaderEntry::GetValue(), gdcmParser::LoadHeaderEntrySafe(), and UI1_2_840_10008_1_2_1_99.

Referenced by gdcmFile::ParsePixelData(), and gdcmFile::ReadPixelData().

00279                                                                     {
00280    gdcmHeaderEntry* Element = GetHeaderEntryByNumber(0x0002, 0x0010);
00281    if ( !Element )
00282       return false;
00283    LoadHeaderEntrySafe(Element);
00284 
00285    std::string Transfer = Element->GetValue();
00286    if ( Transfer == UI1_2_840_10008_1_2_1_99 )
00287       return true;
00288    return false;
00289 }

bool gdcmParser::IsExplicitVRBigEndianTransferSyntax void   )  [inherited]
 

Determines if the Transfer Syntax was already encountered and if it corresponds to a Explicit VR Big Endian one.

Returns:
True when big endian found. False in all other cases.

Definition at line 297 of file gdcmParser.cxx.

References gdcmParser::GetHeaderEntryByNumber(), gdcmHeaderEntry::GetValue(), gdcmParser::LoadHeaderEntrySafe(), and UI1_2_840_10008_1_2_2.

Referenced by gdcmParser::FindHeaderEntryLength(), gdcmFile::ParsePixelData(), and gdcmFile::ReadPixelData().

00297                                                          {
00298    gdcmHeaderEntry* Element = GetHeaderEntryByNumber(0x0002, 0x0010);
00299    if ( !Element )
00300       return false;
00301    LoadHeaderEntrySafe(Element);
00302 
00303    std::string Transfer = Element->GetValue();
00304    if ( Transfer == UI1_2_840_10008_1_2_2 )  //1.2.2 ??? A verifier !
00305       return true;
00306    return false;
00307 }

bool gdcmParser::IsExplicitVRLittleEndianTransferSyntax void   )  [inherited]
 

Determines if the Transfer Syntax was already encountered and if it corresponds to a ExplicitVRLittleEndian one.

Returns:
True when ExplicitVRLittleEndian found. False in all other cases.

Definition at line 261 of file gdcmParser.cxx.

References gdcmParser::GetHeaderEntryByNumber(), gdcmHeaderEntry::GetValue(), gdcmParser::LoadHeaderEntrySafe(), and UI1_2_840_10008_1_2_1.

Referenced by gdcmFile::ParsePixelData(), and gdcmFile::ReadPixelData().

00261                                                             {
00262    gdcmHeaderEntry* Element = GetHeaderEntryByNumber(0x0002, 0x0010);
00263    if ( !Element )
00264       return false;
00265    LoadHeaderEntrySafe(Element);
00266 
00267    std::string Transfer = Element->GetValue();
00268    if ( Transfer == UI1_2_840_10008_1_2_1 )
00269       return true;
00270    return false;
00271 }

bool gdcmParser::IsImplicitVRLittleEndianTransferSyntax void   )  [inherited]
 

Determines if the Transfer Syntax was already encountered and if it corresponds to a ImplicitVRLittleEndian one.

Returns:
True when ImplicitVRLittleEndian found. False in all other cases.

Definition at line 243 of file gdcmParser.cxx.

References gdcmParser::GetHeaderEntryByNumber(), gdcmHeaderEntry::GetValue(), gdcmParser::LoadHeaderEntrySafe(), and UI1_2_840_10008_1_2.

Referenced by gdcmFile::ParsePixelData(), and gdcmFile::ReadPixelData().

00243                                                             {
00244    gdcmHeaderEntry *Element = GetHeaderEntryByNumber(0x0002, 0x0010);
00245    if ( !Element )
00246       return false;
00247    LoadHeaderEntrySafe(Element);
00248 
00249    std::string Transfer = Element->GetValue();
00250    if ( Transfer == UI1_2_840_10008_1_2 )
00251       return true;
00252    return false;
00253 }

bool gdcmParser::IsReadable void   )  [virtual, inherited]
 

This predicate, based on hopefully reasonable heuristics, decides whether or not the current gdcmParser was properly parsed and contains the mandatory information for being considered as a well formed and usable Dicom/Acr File.

Returns:
true when gdcmParser is the one of a reasonable Dicom/Acr file, false otherwise.

Reimplemented in gdcmHeader.

Definition at line 226 of file gdcmParser.cxx.

References gdcmParser::filetype, gdcmParser::listEntries, and Unknown.

Referenced by gdcmHeader::IsReadable().

00226                                 { 
00227    if(filetype==Unknown) {
00228       return(false);
00229    }
00230    if(listEntries.size()<=0) {    
00231       return(false);
00232    }
00233 
00234    return(true);
00235 }

void * gdcmParser::LoadEntryVoidArea guint16  Group,
guint16  Elem
[protected, virtual, inherited]
 

Loads (from disk) the element content when a string is not suitable.

Parameters:
Group group of the Entry
Elem element of the Entry

Definition at line 734 of file gdcmParser.cxx.

References gdcmParser::fp, gdcmParser::GetHeaderEntryByNumber(), gdcmHeaderEntry::GetLength(), gdcmHeaderEntry::GetOffset(), and gdcmParser::SetEntryVoidAreaByNumber().

Referenced by gdcmParser::LoadHeaderEntries().

00735 {
00736    gdcmHeaderEntry * Element= GetHeaderEntryByNumber(Group, Elem);
00737    if ( !Element )
00738       return NULL;
00739    size_t o =(size_t)Element->GetOffset();
00740    fseek(fp, o, SEEK_SET);
00741    int l=Element->GetLength();
00742    void * a = malloc(l);
00743    if(!a) 
00744         return NULL;
00745 
00746    SetEntryVoidAreaByNumber(a, Group, Elem);
00747    // TODO check the result 
00748    size_t l2 = fread(a, 1, l ,fp);
00749    if(l != l2) 
00750    {
00751         free(a);
00752         return NULL;
00753    }
00754 
00755    return a;  
00756 }

void gdcmParser::LoadHeaderEntrySafe gdcmHeaderEntry entry  )  [protected, inherited]
 

Loads the element while preserving the current underlying file position indicator as opposed to to LoadHeaderEntry that modifies it.

Parameters:
entry Header Entry whose value shall be loaded.
Returns:

Definition at line 877 of file gdcmParser.cxx.

References gdcmParser::fp, and gdcmParser::LoadHeaderEntry().

Referenced by gdcmParser::IsDeflatedExplicitVRLittleEndianTransferSyntax(), gdcmParser::IsExplicitVRBigEndianTransferSyntax(), gdcmParser::IsExplicitVRLittleEndianTransferSyntax(), gdcmParser::IsImplicitVRLittleEndianTransferSyntax(), gdcmHeader::IsJPEG2000(), gdcmHeader::IsJPEGBaseLineProcess1TransferSyntax(), gdcmHeader::IsJPEGExtendedProcess2_4TransferSyntax(), gdcmHeader::IsJPEGExtendedProcess3_5TransferSyntax(), gdcmHeader::IsJPEGLossless(), gdcmHeader::IsJPEGSpectralSelectionProcess6_8TransferSyntax(), and gdcmHeader::IsRLELossLessTransferSyntax().

00877                                                             {
00878    long PositionOnEntry = ftell(fp);
00879    LoadHeaderEntry(entry);
00880    fseek(fp, PositionOnEntry, SEEK_SET);
00881 }

void gdcmDicomDir::NewDicomDir std::string  path  )  [protected]
 

Definition at line 133 of file gdcmDicomDir.cxx.

References gdcmDirList::GetDirName(), HeaderLessThan(), gdcmHeader::IsReadable(), ListHeader, patients, and SetElements().

Referenced by ParseDirectory().

00134 {
00135    gdcmDirList fileList(path,1);
00136    ListHeader list;
00137    gdcmHeader *header;
00138 
00139    listEntries.clear();
00140    patients.clear();
00141 
00142    for(gdcmDirList::iterator it=fileList.begin(); 
00143        it!=fileList.end(); ++it) 
00144    {
00145       header=new gdcmHeader(it->c_str());
00146       if(header->IsReadable())
00147          list.push_back(header);
00148       else
00149          delete header;
00150    }
00151 
00152    std::sort(list.begin(),list.end(),gdcmDicomDir::HeaderLessThan);
00153 
00154    std::string tmp=fileList.GetDirName();
00155    SetElements(tmp,list);
00156 }

FILE * gdcmParser::OpenFile bool  exception_on_error = false  )  throw (gdcmFileError) [inherited]
 

opens the file

Parameters:
exception_on_error 
Returns:

Definition at line 325 of file gdcmParser.cxx.

References dbg, and gdcmDebug::Verbose().

Referenced by gdcmParser::gdcmParser(), gdcmFile::ParsePixelData(), and gdcmFile::ReadPixelData().

00327 {
00328   fp=fopen(filename.c_str(),"rb");
00329   if(exception_on_error) 
00330   {
00331     if(!fp)
00332       throw gdcmFileError("gdcmParser::gdcmParser(const char *, bool)");
00333   }
00334 
00335   if ( fp ) 
00336   {
00337      guint16 zero;
00338      fread(&zero,  (size_t)2, (size_t)1, fp);
00339 
00340     //ACR -- or DICOM with no Preamble --
00341     if( zero == 0x0008 || zero == 0x0800 || zero == 0x0002 || zero == 0x0200)
00342        return(fp);
00343 
00344     //DICOM
00345     fseek(fp, 126L, SEEK_CUR);
00346     char dicm[4];
00347     fread(dicm,  (size_t)4, (size_t)1, fp);
00348     if( memcmp(dicm, "DICM", 4) == 0 )
00349        return(fp);
00350 
00351     fclose(fp);
00352     dbg.Verbose(0, "gdcmParser::OpenFile not DICOM/ACR", filename.c_str());
00353   }
00354   else {
00355     dbg.Verbose(0, "gdcmParser::OpenFile cannot open file", filename.c_str());
00356   }
00357   return(NULL);
00358 }

void gdcmDicomDir::ParseDirectory void   ) 
 

Definition at line 120 of file gdcmDicomDir.cxx.

References CreateDicomDir(), GetPath(), and NewDicomDir().

Referenced by gdcmDicomDir().

00121 {
00122    NewDicomDir(GetPath());
00123    CreateDicomDir();
00124 }

void gdcmDicomDir::Print std::ostream &  os = std::cout  )  [virtual]
 

Reimplemented from gdcmParser.

Definition at line 73 of file gdcmDicomDir.cxx.

References patients.

00074 {
00075    for(ListPatient::iterator cc=patients.begin();cc!=patients.end();++cc)
00076    {
00077      (*cc)->SetPrintLevel(printLevel);
00078      (*cc)->Print(os);
00079    }
00080 }

void gdcmParser::PrintEntry std::ostream &  os = std::cout  )  [virtual, inherited]
 

Prints the Header Entries (Dicom Elements) both from the H Table and the chained list.

Returns:

Definition at line 148 of file gdcmParser.cxx.

References gdcmParser::listEntries.

00148                                            {
00149    std::ostringstream s;   
00150            
00151    for (ListTag::iterator i = listEntries.begin();  
00152            i != listEntries.end();
00153            ++i)
00154    {
00155            (*i)->SetPrintLevel(printLevel);
00156            (*i)->Print(os);   
00157    } 
00158    os<<s.str();
00159 }

void gdcmParser::PrintPubDict std::ostream &  os = std::cout  )  [virtual, inherited]
 

Prints The Dict Entries of THE public Dicom Dictionnry.

Returns:

Definition at line 166 of file gdcmParser.cxx.

References gdcmDict::Print(), and gdcmParser::RefPubDict.

00166                                              {
00167    RefPubDict->Print(os);
00168 }

void gdcmParser::PrintShaDict std::ostream &  os = std::cout  )  [virtual, inherited]
 

Prints The Dict Entries of THE shadow Dicom Dictionnry.

Returns:

Definition at line 175 of file gdcmParser.cxx.

References gdcmDict::Print(), and gdcmParser::RefShaDict.

00175                                              {
00176    RefShaDict->Print(os);
00177 }

bool gdcmParser::ReplaceIfExistByNumber char *  Value,
guint16  Group,
guint16  Elem
[inherited]
 

Set a new value if the invoked element exists Seems to be useless !!!

Parameters:
Value new element value
Group group of the Entry
Elem element of the Entry
Returns:
boolean

Definition at line 491 of file gdcmParser.cxx.

References gdcmParser::SetEntryByNumber().

Referenced by gdcmHeader::anonymizeHeader().

00492 {
00493    std::string v = Value;       
00494    SetEntryByNumber(v, Group, Elem);
00495    return true;
00496 } 

bool gdcmParser::ReplaceOrCreateByNumber char *  Value,
guint16  Group,
guint16  Elem
[inherited]
 

Modifies the value of a given Header Entry (Dicom Element) if it exists; Creates it with the given value if it doesn't.

Parameters:
Value passed as a char*
Group group of the Entry
Elem element of the Entry
Returns:
boolean

Definition at line 469 of file gdcmParser.cxx.

References gdcmParser::AddHeaderEntry(), gdcmParser::NewHeaderEntryByNumber(), and gdcmParser::SetEntryByNumber().

00469                                                                                   {
00470    gdcmHeaderEntry* nvHeaderEntry=NewHeaderEntryByNumber(Group, Elem);
00471 
00472    if(!nvHeaderEntry)
00473       return(false);
00474 
00475    AddHeaderEntry(nvHeaderEntry);
00476 
00477    std::string v = Value;       
00478    SetEntryByNumber(v, Group, Elem);
00479    return(true);
00480 }  

bool gdcmParser::ReplaceOrCreateByNumber std::string  Value,
guint16  Group,
guint16  Elem
[inherited]
 

Modifies the value of a given Header Entry (Dicom Element) if it exists; Creates it with the given value if it doesn't.

Parameters:
Value passed as a std::string
Group 
Elem 
Returns:
false only if new element creation fails

Definition at line 446 of file gdcmParser.cxx.

References gdcmParser::AddHeaderEntry(), gdcmParser::CheckIfEntryExistByNumber(), gdcmParser::NewHeaderEntryByNumber(), and gdcmParser::SetEntryByNumber().

Referenced by gdcmHeader::anonymizeHeader(), and gdcmParser::Write().

00448                                                        {
00449    if (CheckIfEntryExistByNumber(Group, Elem) == 0) {
00450       gdcmHeaderEntry *a =NewHeaderEntryByNumber(Group, Elem);
00451       if (a == NULL) 
00452          return false;
00453       AddHeaderEntry(a);
00454    }   
00455    SetEntryByNumber(Value, Group, Elem);
00456    return(true);
00457 }   

void gdcmDicomDir::SetElement std::string &  path,
gdcmDicomDirType  type,
gdcmHeader header
[private]
 

Definition at line 408 of file gdcmDicomDir.cxx.

References dbg, GDCM_IMAGE, GDCM_NONE, GDCM_PATIENT, GDCM_SERIE, GDCM_STUDY, GDCM_UNFOUND, gdcmGlobal::GetDicomDirElements(), gdcmDict::GetDictEntryByNumber(), gdcmHeader::GetEntryByNumber(), gdcmParser::GetFileName(), gdcmDicomDirElement::GetImageElements(), gdcmDicomDirElement::GetMetaElements(), gdcmDicomDirElement::GetPatientElements(), gdcmParser::GetPubDict(), gdcmDicomDirElement::GetSerieElements(), gdcmDicomDirElement::GetStudyElements(), gdcmHeaderEntry::GetValue(), gdcmDictEntry::GetVR(), gdcmHeaderEntry::SetLength(), gdcmHeaderEntry::SetOffset(), gdcmHeaderEntry::SetValue(), and gdcmDebug::Verbose().

Referenced by SetElements().

00409 {
00410    std::list<gdcmElement> elemList;
00411    std::list<gdcmElement>::iterator it;
00412    guint16 tmpGr, tmpEl;
00413    gdcmDictEntry *dictEntry;
00414    gdcmHeaderEntry *entry;
00415    std::string val;
00416 
00417    switch(type)
00418    {
00419       case GDCM_PATIENT:
00420          elemList=gdcmGlobal::GetDicomDirElements()->GetPatientElements();
00421          break;
00422       case GDCM_STUDY:
00423          elemList=gdcmGlobal::GetDicomDirElements()->GetStudyElements();
00424          break;
00425       case GDCM_SERIE:
00426          elemList=gdcmGlobal::GetDicomDirElements()->GetSerieElements();
00427          break;
00428       case GDCM_IMAGE:
00429          elemList=gdcmGlobal::GetDicomDirElements()->GetImageElements();
00430          break;
00431       case GDCM_NONE:
00432          elemList=gdcmGlobal::GetDicomDirElements()->GetMetaElements();
00433          break;
00434       default:
00435          return;
00436    }
00437 
00438    for(it=elemList.begin();it!=elemList.end();++it)
00439    {
00440       tmpGr=it->group;
00441       tmpEl=it->elem;
00442 
00443       dictEntry=GetPubDict()->GetDictEntryByNumber(tmpGr,tmpEl);
00444       entry=new gdcmHeaderEntry(dictEntry);
00445       entry->SetOffset(0); // just to avoid missprinting
00446 
00447       if(header)
00448          val=header->GetEntryByNumber(tmpGr,tmpEl);
00449       else
00450          val=GDCM_UNFOUND;
00451 
00452       if(val==GDCM_UNFOUND) 
00453       {
00454          if((tmpGr==0x0004) &&(tmpEl==0x1130) )
00455          {
00456             // TODO force the *end* File Name(remove path)
00457             val=path;
00458          }
00459          else if( (tmpGr==0x0004) && (tmpEl==0x1500) ) // Only used for image
00460          {
00461             if(header->GetFileName().substr(0,path.length())!=path)
00462             {
00463                dbg.Verbose(0, "gdcmDicomDir::SetElement : the base path of file name is incorrect");
00464                val=header->GetFileName();
00465             }
00466             else
00467                val=&(header->GetFileName()[path.length()]);
00468          }
00469          else
00470          {
00471             val=it->value;
00472          }
00473       }
00474       entry->SetValue(val);
00475 
00476       if(dictEntry)
00477       {
00478          if( (dictEntry->GetVR()=="UL") || (dictEntry->GetVR()=="SL") ) 
00479          {
00480             entry->SetLength(4);
00481          } 
00482          else if( (dictEntry->GetVR()=="US") || (dictEntry->GetVR()=="SS") ) 
00483          {
00484             entry->SetLength(2); 
00485          } 
00486          else if(dictEntry->GetVR()=="SQ") 
00487          {
00488             entry->SetLength(0xffffffff);
00489          }
00490          else
00491          {
00492             entry->SetLength(entry->GetValue().length());        
00493          }
00494       }
00495 
00496       listEntries.push_back(entry);
00497    }     
00498 }

void gdcmDicomDir::SetElements std::string &  path,
ListHeader list
[private]
 

Definition at line 353 of file gdcmDicomDir.cxx.

References GDCM_IMAGE, GDCM_NONE, GDCM_PATIENT, GDCM_SERIE, GDCM_STUDY, ListHeader, and SetElement().

Referenced by NewDicomDir().

00354 {
00355    std::string patPrevName="", patPrevID="";
00356    std::string studPrevInstanceUID="", studPrevID="";
00357    std::string serPrevInstanceUID="", serPrevID="";
00358 
00359    std::string patCurName, patCurID;
00360    std::string studCurInstanceUID, studCurID;
00361    std::string serCurInstanceUID, serCurID;
00362 
00363    SetElement(path,GDCM_NONE,NULL);
00364 
00365    ListTag::iterator debPat=listEntries.begin();
00366    for(ListHeader::iterator it=list.begin();it!=list.end();++it) 
00367    {
00368       // get the current file characteristics
00369       patCurName=(*it)->GetEntryByNumber(0x0010,0x0010); 
00370       patCurID=(*it)->GetEntryByNumber(0x0010,0x0011); 
00371       studCurInstanceUID=(*it)->GetEntryByNumber(0x0020,0x000d);            
00372       studCurID=(*it)->GetEntryByNumber(0x0020,0x0010);            
00373       serCurInstanceUID=(*it)->GetEntryByNumber(0x0020,0x000e);            
00374       serCurID=(*it)->GetEntryByNumber(0x0020,0x0011);
00375 
00376       if(patCurName!=patPrevName || patCurID!=patPrevID) 
00377          SetElement(path,GDCM_PATIENT,*it);
00378 
00379       // if new Study Deal with 'STUDY' Elements   
00380       if(studCurInstanceUID!=studPrevInstanceUID || studCurID!=studPrevID) 
00381          SetElement(path,GDCM_STUDY,*it);
00382 
00383       // if new Serie Deal with 'SERIE' Elements   
00384       if(serCurInstanceUID!=serPrevInstanceUID || serCurID!=serPrevID) 
00385       {
00386          SetElement(path,GDCM_SERIE,*it);
00387       } 
00388       
00389       // Always Deal with 'IMAGE' Elements  
00390       SetElement(path,GDCM_IMAGE,*it);
00391 
00392       patPrevName=patCurName;
00393       patPrevID=patCurID;
00394       studPrevInstanceUID=studCurInstanceUID;
00395       studPrevID=studCurID;
00396       serPrevInstanceUID=serCurInstanceUID;
00397       serPrevID=serCurID;
00398    }
00399 }

bool gdcmParser::SetEntryByName std::string  content,
std::string  tagName
[protected, virtual, inherited]
 

Sets the value (string) of the Header Entry (Dicom Element).

Parameters:
content string value of the Dicom Element
tagName name of the searched Dicom Element.
Returns:
true when found

Reimplemented in gdcmHeader.

Definition at line 602 of file gdcmParser.cxx.

References gdcmDict::GetDictEntryByName(), gdcmDictEntry::GetElement(), gdcmDictEntry::GetGroup(), gdcmParser::RefPubDict, and gdcmParser::SetEntryByNumber().

Referenced by gdcmHeader::SetEntryByName().

00602                                                                    {
00603    gdcmDictEntry *dictEntry = RefPubDict->GetDictEntryByName(tagName); 
00604    if( dictEntry == NULL)
00605       return false;                                 
00606 
00607    return(SetEntryByNumber(content,dictEntry->GetGroup(),
00608                                    dictEntry->GetElement()));
00609 }

bool gdcmParser::SetEntryByNumber std::string  content,
guint16  group,
guint16  element
[protected, virtual, inherited]
 

Accesses an existing gdcmHeaderEntry (i.e. a Dicom Element) through it's (group, element) and modifies it's content with the given value.

Warning:
Don't use any longer : use SetPubEntryByNumber
Parameters:
content new value to substitute with
group group of the Dicom Element to modify
element element of the Dicom Element to modify

Reimplemented in gdcmHeader.

Definition at line 621 of file gdcmParser.cxx.

References gdcmHeaderEntry::GetVR(), IterHT, gdcmHeaderEntry::SetLength(), gdcmParser::tagHT, TagKey, and gdcmDictEntry::TranslateToKey().

Referenced by gdcmParser::LoadHeaderEntries(), gdcmParser::ReplaceIfExistByNumber(), gdcmParser::ReplaceOrCreateByNumber(), gdcmParser::SetEntryByName(), and gdcmHeader::SetEntryByNumber().

00624 {
00625    TagKey key = gdcmDictEntry::TranslateToKey(group, element);
00626    if ( ! tagHT.count(key))
00627       return false;
00628    int l = content.length();
00629    if(l%2) // Non even length are padded with a space (020H).
00630    {  
00631       l++;
00632       content = content + '\0';
00633    }
00634       
00635    gdcmHeaderEntry * a;
00636    IterHT p;
00637    TagHeaderEntryHT::iterator p2;
00638    // DO NOT remove the following lines : they explain the stuff   
00639    //p= tagHT.equal_range(key); // get a pair of iterators first-last synonym
00640    //p2=p.first;                // iterator on the first synonym 
00641    //a=p2->second;              // H Table target column (2-nd col)
00642     
00643    // or, easier :
00644    a = ((tagHT.equal_range(key)).first)->second; 
00645        
00646    a-> SetValue(content); 
00647    
00648    std::string vr = a->GetVR();
00649    
00650    guint32 lgr;
00651    if( (vr == "US") || (vr == "SS") ) 
00652       lgr = 2;
00653    else if( (vr == "UL") || (vr == "SL") )
00654       lgr = 4;
00655    else
00656       lgr = l;     
00657 
00658    a->SetLength(lgr);   
00659    return true;
00660 }                                         

bool gdcmParser::SetEntryLengthByNumber guint32  l,
guint16  group,
guint16  element
[protected, virtual, inherited]
 

Accesses an existing gdcmHeaderEntry (i.e. a Dicom Element) in the PubHeaderEntrySet of this instance through it's (group, element) and modifies it's length with the given value.

Warning:
Use with extreme caution.
Parameters:
l new length to substitute with
group group of the Entry to modify
element element of the Entry to modify
Returns:
1 on success, 0 otherwise.

Reimplemented in gdcmHeader.

Definition at line 674 of file gdcmParser.cxx.

References gdcmParser::tagHT, TagKey, and gdcmDictEntry::TranslateToKey().

Referenced by gdcmHeader::SetEntryLengthByNumber(), and gdcmParser::Write().

00677 {
00678    TagKey key = gdcmDictEntry::TranslateToKey(group, element);
00679    if ( ! tagHT.count(key))
00680       return false;
00681    if (l%2) l++; // length must be even
00682    ( ((tagHT.equal_range(key)).first)->second )->SetLength(l);   
00683          
00684    return true ;                
00685 }

bool gdcmParser::SetEntryVoidAreaByNumber void *  area,
guint16  group,
guint16  element
[protected, virtual, inherited]
 

Sets a 'non string' value to a given Dicom Element.

Parameters:
area 
group Group number of the searched Dicom Element
element Element number of the searched Dicom Element
Returns:

Definition at line 766 of file gdcmParser.cxx.

References gdcmParser::tagHT, TagKey, and gdcmDictEntry::TranslateToKey().

Referenced by gdcmParser::LoadEntryVoidArea().

00769 {
00770    TagKey key = gdcmDictEntry::TranslateToKey(group, element);
00771    if ( ! tagHT.count(key))
00772       return false;
00773    ( ((tagHT.equal_range(key)).first)->second )->SetVoidArea(area);      
00774    return true;
00775 }

void gdcmDicomDir::SetPrintLevel int  level  )  [inline]
 

Sets the print level for the Dicom Header.

Note:
0 for Light Print; 1 for 'medium' Print, 2 for Heavy

Reimplemented from gdcmParser.

Definition at line 33 of file gdcmDicomDir.h.

00033 { printLevel = level; };

bool gdcmParser::SetShaDict DictKey  dictName  )  [inherited]
 

Set the shadow dictionary used.

Parameters:
dictName name of the dictionary to use in shadow

Definition at line 212 of file gdcmParser.cxx.

References DictKey, gdcmDictSet::GetDict(), gdcmGlobal::GetDicts(), and gdcmParser::RefShaDict.

00212                                            {
00213    RefShaDict=gdcmGlobal::GetDicts()->GetDict(dictName);
00214    return(!RefShaDict);
00215 }

bool gdcmParser::SetShaDict gdcmDict dict  )  [inherited]
 

Set the shadow dictionary used.

Parameters:
dict dictionary to use in shadow

Definition at line 202 of file gdcmParser.cxx.

References gdcmParser::RefShaDict.

00202                                          {
00203    RefShaDict=dict;
00204    return(!RefShaDict);
00205 }

guint32 gdcmParser::SwapLong guint32  a  )  [inherited]
 

Swaps back the bytes of 4-byte long integer accordingly to processor order.

Returns:
The properly swaped 32 bits integer.

Definition at line 1156 of file gdcmParser.cxx.

References dbg, gdcmDebug::Error(), and gdcmParser::sw.

Referenced by gdcmFile::gdcm_read_RLE_file(), gdcmParser::GetHeaderEntryValue(), gdcmFile::ParsePixelData(), gdcmParser::ReadInt32(), gdcmFile::ReadPixelData(), and gdcmParser::UnswapLong().

01156                                       {
01157    switch (sw) {
01158       case    0 :
01159          break;
01160       case 4321 :
01161          a=( ((a<<24) & 0xff000000) | ((a<<8)  & 0x00ff0000) | 
01162              ((a>>8)  & 0x0000ff00) | ((a>>24) & 0x000000ff) );
01163          break;
01164    
01165       case 3412 :
01166          a=( ((a<<16) & 0xffff0000) | ((a>>16) & 0x0000ffff) );
01167          break;
01168    
01169       case 2143 :
01170          a=( ((a<<8) & 0xff00ff00) | ((a>>8) & 0x00ff00ff)  );
01171          break;
01172       default :
01173          dbg.Error(" gdcmParser::SwapLong : unset swap code");
01174          a=0;
01175    }
01176    return(a);
01177 }

guint16 gdcmParser::SwapShort guint16  a  )  [inherited]
 

Swaps the bytes so they agree with the processor order.

Returns:
The properly swaped 16 bits integer.

Definition at line 1194 of file gdcmParser.cxx.

References gdcmParser::sw.

Referenced by gdcmParser::FindHeaderEntryLength(), gdcmFile::gdcm_read_RLE_file(), gdcmParser::GetHeaderEntryValue(), gdcmFile::ParsePixelData(), gdcmParser::ReadInt16(), gdcmFile::ReadPixelData(), and gdcmParser::UnswapShort().

01194                                        {
01195    if ( (sw==4321)  || (sw==2143) )
01196       a =(((a<<8) & 0x0ff00) | ((a>>8)&0x00ff));
01197    return (a);
01198 }

guint32 gdcmParser::UnswapLong guint32  a  )  [inherited]
 

Unswaps back the bytes of 4-byte long integer accordingly to processor order.

Returns:
The properly unswaped 32 bits integer.

Definition at line 1185 of file gdcmParser.cxx.

References gdcmParser::SwapLong().

01185                                         {
01186    return (SwapLong(a));
01187 }

guint16 gdcmParser::UnswapShort guint16  a  )  [inherited]
 

Unswaps the bytes so they agree with the processor order.

Returns:
The properly unswaped 16 bits integer.

Definition at line 1205 of file gdcmParser.cxx.

References gdcmParser::SwapShort().

01205                                          {
01206    return (SwapShort(a));
01207 }

void gdcmParser::UpdateGroupLength bool  SkipSequence = false,
FileType  type = ImplicitVR
[protected, inherited]
 

Re-computes the length of a ACR-NEMA/Dicom group from a DcmHeader.

Warning:
: to be re-written using the chained list instead of the H table.

: DO NOT use (doesn't work any longer because of the multimap)

Todo:
: to be re-written using the chained list instead of the H table
Parameters:
SkipSequence TRUE if we don't want to write Sequences (ACR-NEMA Files)
type Type of the File (ExplicitVR,ImplicitVR, ACR, ...)

Definition at line 892 of file gdcmParser.cxx.

References gdcmParser::AddHeaderEntry(), ExplicitVR, gdcmHeaderEntry::GetElement(), gdcmHeaderEntry::GetGroup(), gdcmParser::GetHeaderEntryByNumber(), gdcmHeaderEntry::GetLength(), gdcmHeaderEntry::GetVR(), GroupHT, GroupKey, gdcmHeaderEntry::SetLength(), gdcmHeaderEntry::SetValue(), gdcmParser::tagHT, and TagKey.

00892                                                                    {
00893    guint16 gr, el;
00894    std::string vr;
00895    
00896    gdcmHeaderEntry *elem;
00897    char trash[10];
00898    std::string str_trash;
00899    
00900    GroupKey key;
00901    GroupHT groupHt;  // to hold the length of each group
00902    TagKey tk;
00903    // remember :
00904    // typedef std::map<GroupKey, int> GroupHT;
00905    
00906    gdcmHeaderEntry *elemZ;
00907   
00908    // for each Tag in the DCM Header
00909    
00910    for (TagHeaderEntryHT::iterator tag2 = tagHT.begin(); 
00911         tag2 != tagHT.end();
00912         ++tag2)
00913    {
00914       elem  = tag2->second;
00915       gr = elem->GetGroup();
00916       el = elem->GetElement();
00917       vr = elem->GetVR(); 
00918                  
00919       sprintf(trash, "%04x", gr);
00920       key = trash;              // generate 'group tag'
00921       
00922       // if the caller decided not to take SEQUENCEs into account 
00923       // e.g : he wants to write an ACR-NEMA File 
00924                 
00925       if (SkipSequence && vr == "SQ") 
00926          continue;
00927       
00928       // Still unsolved problem :
00929       // we cannot find the 'Sequence Delimitation Item'
00930       // since it's at the end of the Hash Table
00931       // (fffe,e0dd) 
00932        
00933       // pas SEQUENCE en ACR-NEMA
00934       // WARNING : 
00935       // --> la descente a l'interieur' des SQ 
00936       // devrait etre faite avec une liste chainee, pas avec une HTable...
00937             
00938       if ( groupHt.count(key) == 0) // we just read the first elem of a given group
00939       { 
00940          if (el == 0x0000) // the first elem is 0x0000
00941          {            
00942             groupHt[key] = 0;         // initialize group length 
00943          } 
00944          else 
00945          {
00946             groupHt[key] = 2 + 2 + 4 + elem->GetLength(); // non 0x0000 first group elem
00947          } 
00948       } 
00949       else // any elem but the first
00950       {   
00951          if (type == ExplicitVR) 
00952          {
00953             if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") ) 
00954             {
00955                groupHt[key] +=  4; // explicit VR AND OB, OW, SQ : 4 more bytes
00956             }
00957          }
00958          groupHt[key] += 2 + 2 + 4 + elem->GetLength(); 
00959       } 
00960    }
00961 
00962    unsigned short int gr_bid;
00963   
00964    for (GroupHT::iterator g = groupHt.begin(); // for each group we found
00965         g != groupHt.end();
00966         ++g)
00967    { 
00968       // FIXME: g++ -Wall -Wstrict-prototypes reports on following line:
00969       //        warning: unsigned int format, different type arg
00970       sscanf(g->first.c_str(),"%x",&gr_bid);
00971       tk = g->first + "|0000";                  // generate the element full tag
00972                      
00973       if ( tagHT.count(tk) == 0) // if element 0x0000 not found
00974       {                 
00975          gdcmDictEntry * tagZ = new gdcmDictEntry(gr_bid, 0x0000, "UL");       
00976          elemZ = new gdcmHeaderEntry(tagZ);
00977          elemZ->SetLength(4);
00978          AddHeaderEntry(elemZ);                         // create it
00979       } 
00980       else 
00981       {
00982          elemZ=GetHeaderEntryByNumber(gr_bid, 0x0000);
00983       }     
00984       sprintf(trash ,"%d",g->second);
00985       str_trash=trash;
00986       elemZ->SetValue(str_trash);
00987    }   
00988 }

void gdcmParser::UpdateShaEntries void   )  [protected, virtual, inherited]
 

Update the entries with the shadow dictionary. Only non even entries are analyzed.

Reimplemented in gdcmHeader.

Definition at line 782 of file gdcmParser.cxx.

References gdcmParser::CheckHeaderEntryVR(), gdcmDict::GetDictEntryByNumber(), gdcmParser::GetHeaderEntryUnvalue(), gdcmParser::GetHeaderEntryValue(), gdcmDictEntry::GetVR(), gdcmParser::listEntries, gdcmParser::NewVirtualDictEntry(), and gdcmParser::RefShaDict.

Referenced by gdcmHeader::UpdateShaEntries().

00782                                       {
00783    gdcmDictEntry *entry;
00784    std::string vr;
00785 
00786    for(ListTag::iterator it=listEntries.begin();
00787        it!=listEntries.end();
00788        ++it)
00789    {
00790       // Odd group => from public dictionary
00791       if((*it)->GetGroup()%2==0)
00792          continue;
00793 
00794       // Peer group => search the corresponding dict entry
00795       if(RefShaDict)
00796          entry=RefShaDict->GetDictEntryByNumber((*it)->GetGroup(),(*it)->GetElement());
00797       else
00798          entry=NULL;
00799 
00800       if((*it)->IsImplicitVR())
00801          vr="Implicit";
00802       else
00803          vr=(*it)->GetVR();
00804 
00805       (*it)->SetValue(GetHeaderEntryUnvalue(*it));
00806       if(entry){
00807          // Set the new entry and the new value
00808          (*it)->SetDictEntry(entry);
00809          CheckHeaderEntryVR(*it,vr);
00810 
00811          (*it)->SetValue(GetHeaderEntryValue(*it));
00812       }
00813       else
00814       {
00815          // Remove precedent value transformation
00816          (*it)->SetDictEntry(NewVirtualDictEntry((*it)->GetGroup(),(*it)->GetElement(),vr));
00817       }
00818    }
00819 }

bool gdcmParser::Write FILE *  fp,
FileType  type
[virtual, inherited]
 

Parameters:
fp file pointer on an already open file
type type of the File to be written (ACR-NEMA, ExplicitVR, ImplicitVR)
Returns:
always "True" ?!

Definition at line 381 of file gdcmParser.cxx.

References ExplicitVR, gdcmParser::ReplaceOrCreateByNumber(), gdcmParser::SetEntryLengthByNumber(), UI1_2_840_10008_1_2, UI1_2_840_10008_1_2_1, and gdcmParser::WriteEntries().

Referenced by gdcmFile::WriteBase().

00381                                               {
00382 // ==============
00383 // TODO The stuff was rewritten using the chained list instead 
00384 //      of the H table
00385 //      so we could remove the GroupHT from the gdcmParser
00386 // To be checked
00387 // =============
00388 
00389    // TODO : move the following lines (and a lot of others, to be written)
00390    // to a future function CheckAndCorrectHeader
00391    
00392         // Question :
00393         // Comment pourrait-on savoir si le DcmHeader vient d'un fichier DicomV3 ou non
00394         // (FileType est un champ de gdcmParser ...)
00395         // WARNING : Si on veut ecrire du DICOM V3 a partir d'un DcmHeader ACR-NEMA
00396         // no way 
00397         // a moins de se livrer a un tres complique ajout des champs manquants.
00398         // faire un CheckAndCorrectHeader (?)  
00399          
00400 
00401    if (type == ImplicitVR) 
00402    {
00403       std::string implicitVRTransfertSyntax = UI1_2_840_10008_1_2;
00404       ReplaceOrCreateByNumber(implicitVRTransfertSyntax,0x0002, 0x0010);
00405       
00406       //FIXME Refer to standards on page 21, chapter 6.2 "Value representation":
00407       //      values with a VR of UI shall be padded with a single trailing null
00408       //      Dans le cas suivant on doit pader manuellement avec un 0
00409       
00410       SetEntryLengthByNumber(18, 0x0002, 0x0010);
00411    } 
00412 
00413    if (type == ExplicitVR) 
00414    {
00415       std::string explicitVRTransfertSyntax = UI1_2_840_10008_1_2_1;
00416       ReplaceOrCreateByNumber(explicitVRTransfertSyntax,0x0002, 0x0010);
00417       
00418       //FIXME Refer to standards on page 21, chapter 6.2 "Value representation":
00419       //      values with a VR of UI shall be padded with a single trailing null
00420       //      Dans le cas suivant on doit pader manuellement avec un 0
00421       
00422       SetEntryLengthByNumber(20, 0x0002, 0x0010);
00423    }
00424 
00425 /* TODO : rewrite later
00426 
00427    if ( (type == ImplicitVR) || (type == ExplicitVR) )
00428       UpdateGroupLength(false,type);
00429    if ( type == ACR)
00430       UpdateGroupLength(true,ACR);
00431 */
00432 
00433    WriteEntries(fp,type);
00434    return(true);
00435  }

bool gdcmDicomDir::Write std::string  fileName  ) 
 

writes on disc a DICOMDIR \ warning does NOT add the missing elements in the header : it's up to the user doing it !

Parameters:
fileName file to be written to
Returns:
false only when fail to open

Definition at line 92 of file gdcmDicomDir.cxx.

References DICOMDIR, and gdcmParser::WriteEntries().

00093 {
00094    FILE * fp1;
00095 
00096    fp1=fopen(fileName.c_str(),"wb");
00097    if(fp1==NULL) 
00098    {
00099       printf("Failed to open(write) File [%s] \n",fileName.c_str());
00100       return(false);
00101    }
00102 
00103    char * filePreamble;
00104    filePreamble=(char*)calloc(128,1);
00105    fwrite(filePreamble,128,1,fp1);
00106    fwrite("DICM",4,1,fp1);
00107    free(filePreamble);
00108 
00109    WriteEntries(fp1,DICOMDIR);
00110 
00111    fclose(fp1);
00112 
00113    return true;
00114 }

void gdcmParser::WriteEntries FILE *  _fp,
FileType  type
[protected, inherited]
 

writes on disc according to the requested format (ACR-NEMA, ExplicitVR, ImplicitVR) the image

Warning:
does NOT add the missing elements in the header : it's up to the user doing it ! (function CheckHeaderCoherence to be written)

DON'T try, right now, to write a DICOM image from an ACR Header (meta elements will be missing!)

Parameters:
type type of the File to be written (ACR-NEMA, ExplicitVR, ImplicitVR)
_fp already open file pointer

Definition at line 1003 of file gdcmParser.cxx.

References ACR, gdcmParser::countGrPixel, DICOMDIR, ExplicitVR, gdcmParser::GrPixel, gdcmParser::listEntries, gdcmParser::NumPixel, and Tokenize().

Referenced by gdcmParser::Write(), and Write().

01004 {
01005    guint16 gr, el;
01006    guint32 lgr;
01007    std::string value;
01008    const char * val;
01009    std::string vr;
01010    guint32 val_uint32;
01011    guint16 val_uint16;
01012    guint16 valZero =0;
01013    void *voidArea;
01014    std::vector<std::string> tokens;
01015    
01016    // TODO : function CheckHeaderCoherence to be written
01017    
01018    //  uses now listEntries to iterate, not TagHt!
01019    //
01020    //        pb : gdcmParser.Add does NOT update listEntries
01021    //       TODO : find a trick (in STL?) to do it, at low cost !
01022 
01023    void *ptr;
01024 
01025    // TODO (?) tester les echecs en ecriture (apres chaque fwrite)
01026    int compte =0;
01027    
01028    for (ListTag::iterator tag2=listEntries.begin();
01029         tag2 != listEntries.end();
01030         ++tag2)
01031    {
01032       // === Deal with the length
01033       //     --------------------
01034       if(((*tag2)->GetLength())%2==1)
01035       {
01036          (*tag2)->SetValue((*tag2)->GetValue()+"\0");
01037          (*tag2)->SetLength((*tag2)->GetLength()+1);
01038       }
01039 
01040       gr    = (*tag2)->GetGroup();
01041       el    = (*tag2)->GetElement();
01042       lgr   = (*tag2)->GetReadLength();
01043       val   = (*tag2)->GetValue().c_str();
01044       vr    = (*tag2)->GetVR();
01045       voidArea = (*tag2)->GetVoidArea();
01046       
01047       if ( type == ACR ) 
01048       { 
01049          if (gr < 0x0008)   continue; // ignore pure DICOM V3 groups
01050          if (gr %2)         continue; // ignore shadow groups
01051          if (vr == "SQ" )   continue; // ignore Sequences
01052                    // TODO : find a trick to *skip* the SeQuences !
01053                    // Not only ignore the SQ element
01054          if (gr == 0xfffe ) continue; // ignore delimiters
01055       } 
01056 
01057       fwrite ( &gr,(size_t)2 ,(size_t)1 ,_fp);  //group
01058       fwrite ( &el,(size_t)2 ,(size_t)1 ,_fp);  //element
01059       
01060       // if ( (type == ExplicitVR) && (gr <= 0x0002) ) // ?!?  < 2  
01061       if ( (type == ExplicitVR) || (type == DICOMDIR) )      
01062       {
01063          // EXPLICIT VR
01064          guint16 z=0, shortLgr;
01065          if (vr == "unkn") 
01066          { // Unknown was 'written'      
01067             shortLgr=lgr;
01068             fwrite ( &shortLgr,(size_t)2 ,(size_t)1 ,_fp);
01069             fwrite ( &z,  (size_t)2 ,(size_t)1 ,_fp);
01070          } 
01071          else 
01072          {
01073             if (gr != 0xfffe) 
01074             { // NO value for 'delimiters'
01075                if (vr == "unkn") // Unknown was 'written'
01076                   fwrite(&z,(size_t)2 ,(size_t)1 ,_fp);
01077                else      
01078                   fwrite (vr.c_str(),(size_t)2 ,(size_t)1 ,_fp);
01079             }
01080 
01081             if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") || gr == 0xfffe)
01082             {
01083                if (gr != 0xfffe)
01084                   fwrite ( &z,  (size_t)2 ,(size_t)1 ,_fp);
01085                   fwrite ( &lgr,(size_t)4 ,(size_t)1 ,_fp);
01086             } 
01087             else 
01088             {
01089                shortLgr=lgr;
01090                fwrite ( &shortLgr,(size_t)2 ,(size_t)1 ,_fp);
01091             }
01092          }
01093       } 
01094       else // IMPLICIT VR 
01095       { 
01096          fwrite ( &lgr,(size_t)4 ,(size_t)1 ,_fp);
01097       }
01098       
01099       // === Deal with the value
01100       //     -------------------
01101       if (vr == "SQ")  continue; // no "value" to write for the SEQuences
01102       if (gr == 0xfffe)continue;
01103       
01104       if (voidArea != NULL) 
01105       { // there is a 'non string' LUT, overlay, etc
01106          fwrite ( voidArea,(size_t)lgr ,(size_t)1 ,_fp); // Elem value
01107          continue;            
01108       }
01109       
01110       if (vr == "US" || vr == "SS") 
01111       {
01112          tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
01113          Tokenize ((*tag2)->GetValue(), tokens, "\\");
01114          for (unsigned int i=0; i<tokens.size();i++) 
01115          {
01116             val_uint16 = atoi(tokens[i].c_str());
01117             ptr = &val_uint16;
01118             fwrite ( ptr,(size_t)2 ,(size_t)1 ,_fp);
01119          }
01120          tokens.clear();
01121          continue;
01122       }
01123       if (vr == "UL" || vr == "SL") 
01124       {
01125          tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
01126          Tokenize ((*tag2)->GetValue(), tokens, "\\");
01127          for (unsigned int i=0; i<tokens.size();i++) 
01128          {
01129             val_uint32 = atoi(tokens[i].c_str());
01130             ptr = &val_uint32;
01131             fwrite ( ptr,(size_t)4 ,(size_t)1 ,_fp);
01132          }
01133          tokens.clear();
01134          continue;
01135       } 
01136           
01137       // Pixels are never loaded in the element !
01138       // we stop writting when Pixel are processed
01139       // FIX : we loose trailing elements (RAB, right now)           
01140             
01141       if ((gr == GrPixel) && (el == NumPixel) ) {
01142          compte++;
01143          if (compte == countGrPixel) // we passed *all* the GrPixel,NumPixel   
01144             break;
01145       }       
01146       fwrite ( val,(size_t)lgr ,(size_t)1 ,_fp); // Elem value
01147    }
01148 }


Member Data Documentation

int gdcmParser::countGrPixel [protected, inherited]
 

Definition at line 160 of file gdcmParser.h.

Referenced by gdcmParser::WriteEntries().

int gdcmParser::enableSequences [protected, inherited]
 

Definition at line 152 of file gdcmParser.h.

Referenced by gdcmParser::FixHeaderEntryFoundLength(), and gdcmParser::gdcmParser().

FileType gdcmParser::filetype [protected, inherited]
 

Definition at line 142 of file gdcmParser.h.

Referenced by gdcmParser::CheckSwap(), gdcmParser::FindHeaderEntryLength(), gdcmParser::FindHeaderEntryVR(), gdcmParser::GetFileType(), gdcmParser::IsReadable(), and gdcmParser::LoadHeaderEntries().

FILE* gdcmParser::fp [protected, inherited]
 

Definition at line 141 of file gdcmParser.h.

Referenced by gdcmParser::CheckSwap(), gdcmParser::CloseFile(), gdcmParser::FindHeaderEntryLength(), gdcmParser::FindHeaderEntryLengthOB(), gdcmParser::FindHeaderEntryVR(), gdcmParser::IsHeaderEntryAnInteger(), gdcmParser::LoadEntryVoidArea(), gdcmParser::LoadHeaderEntries(), gdcmParser::LoadHeaderEntry(), gdcmParser::LoadHeaderEntrySafe(), gdcmParser::ReadInt16(), gdcmParser::ReadInt32(), gdcmParser::ReadNextHeaderEntry(), and gdcmParser::SkipBytes().

guint16 gdcmParser::GrPixel [protected, inherited]
 

Definition at line 156 of file gdcmParser.h.

Referenced by gdcmParser::FindHeaderEntryLength(), and gdcmParser::WriteEntries().

const unsigned int gdcmParser::HEADER_LENGTH_TO_READ = 256 [static, protected, inherited]
 

Definition at line 69 of file gdcmParser.cxx.

Referenced by gdcmParser::CheckSwap().

ListTag gdcmParser::listEntries [protected, inherited]
 

Definition at line 150 of file gdcmParser.h.

Referenced by gdcmParser::AddHeaderEntry(), gdcmParser::IsReadable(), gdcmParser::PrintEntry(), gdcmParser::UpdateShaEntries(), and gdcmParser::WriteEntries().

const unsigned int gdcmParser::MAX_SIZE_LOAD_ELEMENT_VALUE = 4096 [static, protected, inherited]
 

Definition at line 72 of file gdcmParser.cxx.

Referenced by gdcmParser::gdcmParser().

const unsigned int gdcmParser::MAX_SIZE_PRINT_ELEMENT_VALUE = 64 [static, protected, inherited]
 

Definition at line 76 of file gdcmParser.cxx.

guint16 gdcmParser::NumPixel [protected, inherited]
 

Definition at line 157 of file gdcmParser.h.

Referenced by gdcmParser::FindHeaderEntryLength(), and gdcmParser::WriteEntries().

ListPatient gdcmDicomDir::patients [private]
 

Definition at line 69 of file gdcmDicomDir.h.

Referenced by AddImageToEnd(), AddPatientToEnd(), AddSerieToEnd(), AddStudyToEnd(), NewDicomDir(), Print(), and ~gdcmDicomDir().

int gdcmParser::printLevel [protected, inherited]
 

Definition at line 153 of file gdcmParser.h.

TagHeaderEntryHT gdcmParser::tagHT [protected, inherited]
 

Definition at line 149 of file gdcmParser.h.

Referenced by gdcmParser::AddHeaderEntry(), gdcmParser::CheckIfEntryExistByNumber(), gdcmParser::GenerateFreeTagKeyInGroup(), gdcmParser::GetEntryByNumber(), gdcmParser::GetHeaderEntryByNumber(), gdcmParser::GetHeaderEntrySameNumber(), gdcmParser::SetEntryByNumber(), gdcmParser::SetEntryLengthByNumber(), gdcmParser::SetEntryVoidAreaByNumber(), and gdcmParser::UpdateGroupLength().


The documentation for this class was generated from the following files:
Generated on Mon Feb 14 16:13:37 2005 for gdcm by doxygen 1.3.6