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

gdcm::DicomDir Class Reference

DicomDir defines an object representing a DICOMDIR in memory as a tree-like structure DicomDirPatient -> DicomDirStudy -> DicomDirSerie -> DicomDirImage. More...

#include <gdcmDicomDir.h>

Inheritance diagram for gdcm::DicomDir:

gdcm::Document gdcm::ElementSet gdcm::DocEntrySet gdcm::Base List of all members.

Public Types

typedef void( Method )(void *)
enum  DicomDirType {
  GDCM_DICOMDIR_NONE, GDCM_DICOMDIR_META, GDCM_DICOMDIR_PATIENT, GDCM_DICOMDIR_STUDY,
  GDCM_DICOMDIR_SERIE, GDCM_DICOMDIR_IMAGE
}
 Types of the DicomDirObject within the DicomDir. More...

typedef std::list< ElementListElements

Public Member Functions

 DicomDir (std::string const &filename, bool parseDir=false)
 Constructor Parses recursively the directory and creates the DicomDir or uses an already built DICOMDIR, depending on 'parseDir' value.

 DicomDir ()
 Constructor : creates an empty DicomDir.

 ~DicomDir ()
 Canonical destructor.

void Print (std::ostream &os=std::cout, std::string const &indent="")
 Canonical Printer.

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

DicomDirMetaNewMeta ()
 adds *the* Meta to a partially created DICOMDIR

DicomDirMetaGetMeta ()
 Returns a pointer to the DicomDirMeta for this DICOMDIR.

DicomDirPatientNewPatient ()
 adds a new Patient (with the basic elements) to a partially created DICOMDIR

void ClearPatient ()
 Remove all Patients.

DicomDirPatientGetFirstPatient ()
 Get the first entry while visiting the DicomDirPatients.

DicomDirPatientGetNextPatient ()
 Get the next entry while visiting the DicomDirPatients.

void ParseDirectory ()
 fills the whole structure, starting from a root Directory

void SetStartMethod (DicomDir::Method *method, void *arg=NULL, DicomDir::Method *argDelete=NULL)
 Set the start method to call when the parsing of the directory starts.

void SetProgressMethod (DicomDir::Method *method, void *arg=NULL, DicomDir::Method *argDelete=NULL)
 Set the progress method to call when the parsing of the directory progress.

void SetEndMethod (DicomDir::Method *method, void *arg=NULL, DicomDir::Method *argDelete=NULL)
 Set the end method to call when the parsing of the directory ends.

void SetStartMethodArgDelete (DicomDir::Method *m)
 Set the method to delete the argument The argument is destroyed when the method is changed or when the class is destroyed.

void SetProgressMethodArgDelete (DicomDir::Method *m)
 Set the method to delete the argument The argument is destroyed when the method is changed or when the class is destroyed.

void SetEndMethodArgDelete (DicomDir::Method *m)
 Set the method to delete the argument The argument is destroyed when the method is changed or when the class is destroyed.

float GetProgress ()
 GetProgress GetProgress.

void AbortProgress ()
 AbortProgress AbortProgress.

bool IsAborted ()
 IsAborted IsAborted.

bool WriteDicomDir (std::string const &fileName)
 writes on disc a DICOMDIR \ warning does NOT add the missing elements in the header : it's up to the user doing it !

DictGetPubDict ()
 Get the public dictionary used.

DictGetShaDict ()
 Get the shadow dictionary used.

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

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

bool IsDicomV3 ()
 Predicate for dicom version 3 file.

bool IsPapyrus ()
 Predicate for Papyrus file Dedicated to whomsoever it may concern.

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

std::string GetTransferSyntax ()
 Accessor to the Transfer Syntax (when present) of the current document (it internally handles reading the value from disk when only parsing occured).

std::string GetTransferSyntaxName ()
 Accesses the info from 0002,0010 : Transfer Syntax and TS.

int GetSwapCode ()
 'Swap code' accessor (see SwapCode )

uint16_t SwapShort (uint16_t)
 Swaps the bytes so they agree with the processor order.

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

uint16_t UnswapShort (uint16_t a)
 Unswaps back the bytes of 2-bytes long integer so they agree with the processor order.

uint32_t UnswapLong (uint32_t a)
 Unswaps back the bytes of 4-byte long integer so they agree with the processor order.

const std::string & GetFileName () const
 Accessor to Filename.

void SetFileName (std::string const &fileName)
 Accessor to Filename.

std::ifstream * OpenFile ()
 Tries to open the file Document::Filename and checks the preamble when existing.

bool CloseFile ()
 closes the file

void WriteContent (std::ofstream *fp, FileType type)
 Writes in a file all the Header Entries (Dicom Elements).

virtual void LoadEntryBinArea (uint16_t group, uint16_t elem)
 Loads (from disk) the element content when a string is not suitable.

virtual void LoadEntryBinArea (BinEntry *entry)
 Loads (from disk) the element content when a string is not suitable.

void LoadDocEntrySafe (DocEntry *entry)
 Loads the element while preserving the current underlying file position indicator as opposed to LoadDocEntry that modifies it.

bool operator< (Document &document)
 Compares two documents, according to DicomDir rules.

bool AddEntry (DocEntry *Entry)
 add a new Dicom Element pointer to the H Table

bool RemoveEntry (DocEntry *EntryToRemove)
 Clear the hash table from given entry AND delete the entry.

bool RemoveEntryNoDestroy (DocEntry *EntryToRemove)
 Clear the hash table from given entry BUT keep the entry.

void ClearEntry ()
 delete all entries in the ElementSet

DocEntryGetFirstEntry ()
 Get the first entry while visiting *the* 'zero level' DocEntrySet (DocEntries out of any Sequence).

DocEntryGetNextEntry ()
 Get the next entry while visiting *the* 'zero level' DocEntrySet (DocEntries out of any Sequence).

DocEntryGetDocEntry (uint16_t group, uint16_t elem)
 retrieves a Dicom Element using (group, element)

bool IsEmpty ()
 Tells us if the ElementSet contains no entry.

virtual std::string GetEntryValue (uint16_t group, uint16_t elem)
 Get the "std::string representable" value of the Dicom entry.

virtual void * GetEntryBinArea (uint16_t group, uint16_t elem)
 Gets (from Header) a 'non string' element value.

virtual int GetEntryLength (uint16_t group, uint16_t elem)
 Searches within Header Entries (Dicom Elements) parsed with the public and private dictionaries for the value length of a given tag..

virtual std::string GetEntryVR (uint16_t group, uint16_t elem)
 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.

ValEntryGetValEntry (uint16_t group, uint16_t elem)
 Same as Document::GetDocEntry except it only returns a result when the corresponding entry is of type ValEntry.

BinEntryGetBinEntry (uint16_t group, uint16_t elem)
 Same as Document::GetDocEntry except it only returns a result when the corresponding entry is of type BinEntry.

SeqEntryGetSeqEntry (uint16_t group, uint16_t elem)
 Same as Document::GetDocEntry except it only returns a result when the corresponding entry is of type SeqEntry.

bool SetValEntry (std::string const &content, uint16_t group, uint16_t elem)
 Accesses an existing DocEntry (i.e. a Dicom Element) through it's (group, element) and modifies it's content with the given value.

bool SetValEntry (std::string const &content, ValEntry *entry)
 Accesses an existing DocEntry (i.e. a Dicom Element) and modifies it's content with the given value.

bool SetBinEntry (uint8_t *content, int lgth, uint16_t group, uint16_t elem)
 Accesses an existing DocEntry (i.e. a Dicom Element) through it's (group, element) and modifies it's content with the given value.

bool SetBinEntry (uint8_t *content, int lgth, BinEntry *entry)
 Accesses an existing BinEntry (i.e. a Dicom Element) and modifies it's content with the given value.

ValEntryInsertValEntry (std::string const &value, uint16_t group, uint16_t elem, TagName const &vr=GDCM_UNKNOWN)
 Modifies the value of a given Doc Entry (Dicom Element) when it exists. Create it with the given value when unexistant.

BinEntryInsertBinEntry (uint8_t *binArea, int lgth, uint16_t group, uint16_t elem, TagName const &vr=GDCM_UNKNOWN)
 Modifies the value of a given Header Entry (Dicom Element) when it exists. Create it with the given value when unexistant. A copy of the binArea is made to be kept in the Document.

SeqEntryInsertSeqEntry (uint16_t group, uint16_t elem)
 Modifies the value of a given Doc Entry (Dicom Element) when it exists. Creates it when unexistant.

virtual bool CheckIfEntryExist (uint16_t group, uint16_t elem)
 Checks if a given Dicom Element exists within the H table.

ValEntryNewValEntry (uint16_t group, uint16_t elem, TagName const &vr=GDCM_UNKNOWN)
 Build a new Val Entry from all the low level arguments. Check for existence of dictionary entry, and build a default one when absent.

BinEntryNewBinEntry (uint16_t group, uint16_t elem, TagName const &vr=GDCM_UNKNOWN)
 Build a new Bin Entry from all the low level arguments. Check for existence of dictionary entry, and build a default one when absent.

SeqEntryNewSeqEntry (uint16_t group, uint16_t elem)
 Build a new Seq Entry from all the low level arguments. Check for existence of dictionary entry, and build a default one when absent.

DictEntryNewVirtualDictEntry (uint16_t group, uint16_t elem, TagName const &vr=GDCM_UNKNOWN, TagName const &vm=GDCM_UNKNOWN, TagName const &name=GDCM_UNKNOWN)
 Request a new virtual dict entry to the dict set.

void SetPrintLevel (int level)
 Sets the print level for the Dicom Header Elements.

int GetPrintLevel ()
 Gets the print level for the Dicom Entries.


Protected Member Functions

void CreateDicomDirChainedList (std::string const &path)
 create a Document-like chained list from a root Directory

void CallStartMethod ()
 CallStartMethod.

void CallProgressMethod ()
 CallProgressMethod.

void CallEndMethod ()
 CallEndMethod.

uint16_t ReadInt16 () throw ( FormatError )
 Reads a supposed to be 16 Bits integer (swaps it depending on processor endianness).

uint32_t ReadInt32 () throw ( FormatError )
 Reads a supposed to be 32 Bits integer (swaps it depending on processor endianness).

void SkipBytes (uint32_t)
 skips bytes inside the source file

int ComputeGroup0002Length (FileType filetype)
 Re-computes the length of a ACR-NEMA/Dicom group from a DcmHeader.

DictEntryGetDictEntry (uint16_t group, uint16_t elem)
 Searches [both] the public [and the shadow dictionary (when they exist)] for the presence of the DictEntry with given group and element. The public dictionary has precedence on the shadow one.

DictEntryGetDictEntry (uint16_t group, uint16_t elem, TagName const &vr)
 Searches [both] the public [and the shadow dictionary (when they exist)] for the presence of the DictEntry with given group and element, and create a new virtual DictEntry if necessary.


Protected Attributes

std::string Filename
 Refering underlying filename.

int SwapCode
 Swap code gives an information on the byte order of a supposed to be an int32, as it's read on disc (depending on the image Transfer Syntax *and* on the processor endianess) as opposed as it should in memory to be dealt as an int32. For instance :
  • a 'Little Endian' image, read with a little endian processor will have a SwapCode= 1234 (the order is OK; nothing to do)
  • a 'Little Endian' image, read with a big endian procesor will have a SwapCode= 4321 (the order is wrong; int32 an int16 must be swapped) note : values 2143, 4321, 3412 remain for the ACR-NEMA time, and the well known 'Bad Big Endian' and 'Bad Little Endian' codes.


bool Group0002Parsed
 whether we already parsed group 0002 (Meta Elements)

bool HasDCMPreamble
 whether file has a DCM Preamble

std::ifstream * Fp
 File Pointer, opened during Document parsing.

FileType Filetype
 ACR, ACR_LIBIDO, ExplicitVR, ImplicitVR, Unknown.

ListElements AnonymizeList
 List of element to Anonymize.

int PrintLevel
 Amount of printed details for each Dicom Entries : 0 : stands for the least detail level.


Static Protected Attributes

const unsigned int HEADER_LENGTH_TO_READ
 After opening the file, we read HEADER_LENGTH_TO_READ bytes.

const unsigned int MAX_SIZE_LOAD_ELEMENT_VALUE = 0xfff
 Elements whose value is longer than MAX_SIZE_LOAD_ELEMENT_VALUE are NOT loaded.

const unsigned int MAX_SIZE_PRINT_ELEMENT_VALUE = 0x7fffffff
 Elements whose value is longer than MAX_SIZE_PRINT_ELEMENT_VALUE are NOT printed.


Private Member Functions

void Initialize ()
 Sets all fields to NULL.

void CreateDicomDir ()
 create a 'DicomDir' from a DICOMDIR Header

bool AddPatientToEnd (DicomDirPatient *dd)
 AddPatientToEnd.

bool AddStudyToEnd (DicomDirStudy *dd)
 AddStudyToEnd.

bool AddSerieToEnd (DicomDirSerie *dd)
 AddSerieToEnd.

bool AddImageToEnd (DicomDirImage *dd)
 AddImageToEnd.

void SetElements (std::string const &path, VectDocument const &list)
 for each Header of the chained list, add/update the Patient/Study/Serie/Image info

void SetElement (std::string const &path, DicomDirType type, Document *header)
 adds to the HTable the Entries (Dicom Elements) corresponding to the given type

void MoveSQItem (DocEntrySet *dst, DocEntrySet *src)
 Move the content of the source SQItem to the destination SQItem Only DocEntry's are moved.


Static Private Member Functions

bool HeaderLessThan (Document *header1, Document *header2)
 compares two files


Private Attributes

DicomDirMetaMetaElems
 Pointer on *the* DicomDirObject 'DicomDirMeta Elements'.

ListDicomDirPatient Patients
 Chained list of DicomDirPatient (to be exploited hierarchicaly).

ListDicomDirPatient::iterator ItPatient
MethodStartMethod
 pointer to the initialisation method for any progress bar

MethodProgressMethod
 pointer to the incrementation method for any progress bar

MethodEndMethod
 pointer to the termination method for any progress bar

MethodStartMethodArgDelete
 pointer to the ??? method for any progress bar

MethodProgressMethodArgDelete
 pointer to the ??? method for any progress bar

MethodEndMethodArgDelete
 pointer to the ??? method for any progress bar

void * StartArg
 pointer to the ??? for any progress bar

void * ProgressArg
 pointer to the ??? for any progress bar

void * EndArg
 pointer to the ??? for any progress bar

float Progress
 value of the ??? for any progress bar

bool Abort
 value of the ??? for any progress bar


Detailed Description

DicomDir defines an object representing a DICOMDIR in memory as a tree-like structure DicomDirPatient -> DicomDirStudy -> DicomDirSerie -> DicomDirImage.

Definition at line 49 of file gdcmDicomDir.h.


Member Typedef Documentation

typedef std::list<Element> gdcm::Document::ListElements [inherited]
 

Definition at line 47 of file gdcmDocument.h.

typedef void( gdcm::DicomDir::Method)(void*)
 

Definition at line 52 of file gdcmDicomDir.h.

Referenced by SetEndMethod(), SetEndMethodArgDelete(), SetProgressMethod(), SetProgressMethodArgDelete(), SetStartMethod(), and SetStartMethodArgDelete().


Member Enumeration Documentation

enum gdcm::DicomDir::DicomDirType
 

Types of the DicomDirObject within the DicomDir.

Enumeration values:
GDCM_DICOMDIR_NONE 
GDCM_DICOMDIR_META 
GDCM_DICOMDIR_PATIENT 
GDCM_DICOMDIR_STUDY 
GDCM_DICOMDIR_SERIE 
GDCM_DICOMDIR_IMAGE 

Definition at line 106 of file gdcmDicomDir.h.


Constructor & Destructor Documentation

gdcm::DicomDir::DicomDir std::string const &  fileName,
bool  parseDir = false
 

Constructor Parses recursively the directory and creates the DicomDir or uses an already built DICOMDIR, depending on 'parseDir' value.

Parameters:
fileName name
  • of the root directory (parseDir = true)
  • of the DICOMDIR (parseDir = false)
parseDir boolean
  • true if user passed an entry point and wants to explore recursively the directories
  • false if user passed an already built DICOMDIR file and wants to use it

Todo:
if parseDir == false, it should be tagged as an error

FIXME : what do we do when the parsed file IS NOT a DICOMDIR file ?

Definition at line 131 of file gdcmDicomDir.cxx.

References CreateDicomDir(), gdcmWarningMacro, gdcm::ElementSet::GetDocEntry(), gdcm::ElementSet::GetFirstEntry(), Initialize(), NewMeta(), ParseDirectory(), and gdcm::Document::SetFileName().

00131                                                            :
00132    Document( fileName )
00133 {
00134    // At this step, Document constructor is already executed,
00135    // whatever user passed (a root directory or a DICOMDIR)
00136    // and whatever the value of parseDir was.
00137    // (nothing is cheked in Document constructor, to avoid overhead)
00138 
00139    Initialize();  // sets all private fields to NULL
00140 
00141    // if user passed a root directory, sure we didn't get anything
00142 
00143    if ( GetFirstEntry() == 0 ) // when user passed a Directory to parse
00144    {
00145       if (!parseDir)
00146          gdcmWarningMacro( "Entry HT empty for file: "<<fileName);
00147 
00148    // Only if user passed a root directory
00149    // ------------------------------------
00150       if ( fileName == "." )
00151       {
00152          // user passed '.' as Name
00153          // we get current directory name
00154          char dummy[1000];
00155          getcwd(dummy, (size_t)1000);
00156          SetFileName( dummy ); // will be converted into a string
00157       }
00158 
00159       if ( parseDir ) // user asked for a recursive parsing of a root directory
00160       {
00161          NewMeta();
00162 
00163          gdcmWarningMacro( "Parse directory and create the DicomDir");
00164          ParseDirectory();
00165       }
00166       else
00167       {
00169          // NO ! user may just call ParseDirectory() *after* constructor
00170       }
00171    }
00172    // Only if user passed a DICOMDIR
00173    // ------------------------------
00174    else 
00175    {
00176       // Directory record sequence
00177       DocEntry *e = GetDocEntry(0x0004, 0x1220);
00178       if ( !e )
00179       {
00180          gdcmWarningMacro( "NO 'Directory record sequence' (0x0004,0x1220)"
00181                           << " in file " << fileName);
00184       }
00185       else
00186          CreateDicomDir();
00187    }
00188 }

gdcm::DicomDir::DicomDir  ) 
 

Constructor : creates an empty DicomDir.

Definition at line 112 of file gdcmDicomDir.cxx.

References Initialize(), and NewMeta().

00113          :Document( )
00114 {
00115    Initialize();  // sets all private fields to NULL
00116    NewMeta();
00117 }

gdcm::DicomDir::~DicomDir  ) 
 

Canonical destructor.

Definition at line 193 of file gdcmDicomDir.cxx.

References ClearPatient(), MetaElems, SetEndMethod(), SetProgressMethod(), and SetStartMethod().

00194 {
00195    SetStartMethod(NULL);
00196    SetProgressMethod(NULL);
00197    SetEndMethod(NULL);
00198 
00199    ClearPatient();
00200    if ( MetaElems )
00201    {
00202       delete MetaElems;
00203    }
00204 }


Member Function Documentation

void gdcm::DicomDir::AbortProgress  )  [inline]
 

AbortProgress AbortProgress.

Definition at line 98 of file gdcmDicomDir.h.

00098 { Abort = true; };

bool gdcm::ElementSet::AddEntry DocEntry newEntry  )  [virtual, inherited]
 

add a new Dicom Element pointer to the H Table

Parameters:
newEntry entry to add

Implements gdcm::DocEntrySet.

Definition at line 69 of file gdcmElementSet.cxx.

References gdcmWarningMacro, gdcm::DocEntry::GetKey(), gdcm::ElementSet::TagHT, and gdcm::TagKey.

Referenced by gdcm::File::File(), gdcm::DocEntryArchive::Push(), and gdcm::DocEntryArchive::Restore().

00070 {
00071    const TagKey &key = newEntry->GetKey();
00072 
00073    if( TagHT.count(key) == 1 )
00074    {
00075       gdcmWarningMacro( "Key already present: " << key.c_str());
00076       return false;
00077    }
00078    else
00079    {
00080       TagHT.insert(TagDocEntryHT::value_type(newEntry->GetKey(), newEntry));
00081       return true;
00082    }
00083 }

bool gdcm::DicomDir::AddImageToEnd DicomDirImage dd  )  [private]
 

AddImageToEnd.

Parameters:
dd SQ Item to enqueue to the DicomDirImage chained List

Definition at line 759 of file gdcmDicomDir.cxx.

References gdcm::DicomDirSerie::AddImage(), gdcm::DicomDirStudy::GetLastSerie(), and Patients.

Referenced by CreateDicomDir(), and SetElement().

00760 {
00761    if( Patients.size() > 0 )
00762    {
00763       ListDicomDirPatient::iterator itp = Patients.end();
00764       itp--;
00765 
00766       DicomDirStudy *study = (*itp)->GetLastStudy();
00767       if( study )
00768       {
00769          DicomDirSerie *serie = study->GetLastSerie();
00770          if( serie )
00771          {
00772             serie->AddImage(dd);
00773             return true;
00774          }
00775       }
00776    }
00777    return false;
00778 }

bool gdcm::DicomDir::AddPatientToEnd DicomDirPatient dd  )  [private]
 

AddPatientToEnd.

Parameters:
dd SQ Item to enqueue to the DicomPatient chained List

Definition at line 712 of file gdcmDicomDir.cxx.

References Patients.

Referenced by CreateDicomDir(), NewPatient(), and SetElement().

00713 {
00714    Patients.push_back(dd);
00715    return true;
00716 }

bool gdcm::DicomDir::AddSerieToEnd DicomDirSerie dd  )  [private]
 

AddSerieToEnd.

Parameters:
dd SQ Item to enqueue to the DicomDirSerie chained List

Definition at line 738 of file gdcmDicomDir.cxx.

References gdcm::DicomDirStudy::AddSerie(), and Patients.

Referenced by CreateDicomDir(), and SetElement().

00739 {
00740    if( Patients.size() > 0 )
00741    {
00742       ListDicomDirPatient::iterator itp = Patients.end();
00743       itp--;
00744 
00745       DicomDirStudy *study = (*itp)->GetLastStudy();
00746       if( study )
00747       {
00748          study->AddSerie(dd);
00749          return true;
00750       }
00751    }
00752    return false;
00753 }

bool gdcm::DicomDir::AddStudyToEnd DicomDirStudy dd  )  [private]
 

AddStudyToEnd.

Parameters:
dd SQ Item to enqueue to the DicomDirStudy chained List

Definition at line 722 of file gdcmDicomDir.cxx.

References Patients.

Referenced by CreateDicomDir(), and SetElement().

00723 {
00724    if( Patients.size() > 0 )
00725    {
00726       ListDicomDirPatient::iterator itp = Patients.end();
00727       itp--;
00728       (*itp)->AddStudy(dd);
00729       return true;
00730    }
00731    return false;
00732 }

void gdcm::DicomDir::CallEndMethod  )  [protected]
 

CallEndMethod.

Definition at line 573 of file gdcmDicomDir.cxx.

References EndArg, EndMethod, and Progress.

Referenced by CreateDicomDirChainedList().

00574 {
00575    Progress = 1.0f;
00576    if( EndMethod )
00577    {
00578       EndMethod( EndArg );
00579    }
00580 }

void gdcm::DicomDir::CallProgressMethod  )  [protected]
 

CallProgressMethod.

Definition at line 562 of file gdcmDicomDir.cxx.

References ProgressArg, and ProgressMethod.

Referenced by CreateDicomDirChainedList().

00563 {
00564    if( ProgressMethod )
00565    {
00566       ProgressMethod( ProgressArg );
00567    }
00568 }

void gdcm::DicomDir::CallStartMethod  )  [protected]
 

CallStartMethod.

Definition at line 549 of file gdcmDicomDir.cxx.

References Abort, Progress, StartArg, and StartMethod.

Referenced by CreateDicomDirChainedList().

00550 {
00551    Progress = 0.0f;
00552    Abort    = false;
00553    if( StartMethod )
00554    {
00555       StartMethod( StartArg );
00556    }
00557 }

bool gdcm::DocEntrySet::CheckIfEntryExist uint16_t  group,
uint16_t  elem
[virtual, inherited]
 

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

Parameters:
group Group number of the searched Dicom Element
elem Element number of the searched Dicom Element
Returns:
true is found

Definition at line 434 of file gdcmDocEntrySet.cxx.

References gdcm::DocEntrySet::GetDocEntry().

00435 {
00436    return GetDocEntry(group,elem)!=NULL;
00437 }

void gdcm::ElementSet::ClearEntry  )  [virtual, inherited]
 

delete all entries in the ElementSet

Implements gdcm::DocEntrySet.

Definition at line 125 of file gdcmElementSet.cxx.

References gdcm::ElementSet::TagHT.

Referenced by CreateDicomDir(), SetElements(), and gdcm::ElementSet::~ElementSet().

00126 {
00127    for(TagDocEntryHT::iterator cc = TagHT.begin();cc != TagHT.end(); ++cc)
00128    {
00129       if ( cc->second )
00130       {
00131          delete cc->second;
00132       }
00133    }
00134    TagHT.clear();
00135 }

void gdcm::DicomDir::ClearPatient  ) 
 

Remove all Patients.

Definition at line 284 of file gdcmDicomDir.cxx.

References Patients.

Referenced by SetElements(), and ~DicomDir().

00285 {
00286    for(ListDicomDirPatient::iterator cc = Patients.begin();
00287                                      cc!= Patients.end();
00288                                    ++cc)
00289    {
00290       delete *cc;
00291    }
00292    Patients.clear();
00293 }

bool gdcm::Document::CloseFile  )  [inherited]
 

closes the file

Returns:
TRUE if the close was successfull

Definition at line 464 of file gdcmDocument.cxx.

References gdcm::Document::Fp.

Referenced by gdcm::Document::Document(), gdcm::File::File(), gdcm::FileHelper::GetRaw(), gdcm::Document::LoadEntryBinArea(), and gdcm::Document::OpenFile().

00465 {
00466    if( Fp )
00467    {
00468       Fp->close();
00469       delete Fp;
00470       Fp = 0;
00471    }
00472    return true; //FIXME how do we detect a non-closed ifstream ?
00473 }

int gdcm::Document::ComputeGroup0002Length FileType  filetype  )  [protected, inherited]
 

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

Parameters:
filetype Type of the File to be written

Definition at line 717 of file gdcmDocument.cxx.

References gdcm::ExplicitVR, gdcm::DocEntry::GetElement(), gdcm::ElementSet::GetFirstEntry(), gdcm::DocEntry::GetGroup(), gdcm::DocEntry::GetLength(), gdcm::ElementSet::GetNextEntry(), and gdcm::DocEntry::GetVR().

Referenced by gdcm::File::Write().

00718 {
00719    uint16_t gr;
00720    std::string vr;
00721    
00722    int groupLength = 0;
00723    bool found0002 = false;   
00724   
00725    // for each zero-level Tag in the DCM Header
00726    DocEntry *entry = GetFirstEntry();
00727    while( entry )
00728    {
00729       gr = entry->GetGroup();
00730 
00731       if( gr == 0x0002 )
00732       {
00733          found0002 = true;
00734 
00735          if( entry->GetElement() != 0x0000 )
00736          {
00737             vr = entry->GetVR();
00738  
00739             if( filetype == ExplicitVR )
00740             {
00741                if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") ) 
00742                {
00743                   // explicit VR AND OB, OW, SQ : 4 more bytes
00744                   groupLength +=  4;
00745                }
00746             }
00747             groupLength += 2 + 2 + 4 + entry->GetLength();   
00748          }
00749       }
00750       else if (found0002 )
00751          break;
00752 
00753       entry = GetNextEntry();
00754    }
00755    return groupLength; 
00756 }

void gdcm::DicomDir::CreateDicomDir  )  [private]
 

create a 'DicomDir' from a DICOMDIR Header

Todo:
FIXME: what to do when the parsed file IS NOT a DICOMDIR file ?

Definition at line 608 of file gdcmDicomDir.cxx.

References AddImageToEnd(), AddPatientToEnd(), AddSerieToEnd(), AddStudyToEnd(), gdcm::ElementSet::ClearEntry(), gdcmErrorMacro, gdcmWarningMacro, gdcm::SQItem::GetDocEntry(), gdcm::ElementSet::GetDocEntry(), gdcm::SeqEntry::GetFirstSQItem(), gdcm::SeqEntry::GetNextSQItem(), gdcm::ContentEntry::GetValue(), MoveSQItem(), and NewMeta().

Referenced by DicomDir(), and ParseDirectory().

00609 {
00610    // The SeqEntries of "Directory Record Sequence" are parsed. 
00611    //  When a DicomDir tag ("PATIENT", "STUDY", "SERIE", "IMAGE") is found :
00612    //  1 - we save the beginning iterator
00613    //  2 - we continue to parse
00614    //  3 - we find an other tag
00615    //       + we create the object for the precedent tag
00616    //       + loop to 1 -
00617 
00618    // Directory record sequence
00619    DocEntry *e = GetDocEntry(0x0004, 0x1220);
00620    if ( !e )
00621    {
00622       gdcmWarningMacro( "No Directory Record Sequence (0004,1220) found");
00624       return;         
00625    }
00626    
00627    SeqEntry *s = dynamic_cast<SeqEntry *>(e);
00628    if ( !s )
00629    {
00630       gdcmWarningMacro( "Element (0004,1220) is not a Sequence ?!?");
00631       return;
00632    }
00633 
00634    NewMeta();
00635    
00636    DocEntry *d;
00637    std::string v;
00638    SQItem *si;
00639 
00640    SQItem *tmpSI=s->GetFirstSQItem();
00641    while(tmpSI)
00642    {
00643       d = tmpSI->GetDocEntry(0x0004, 0x1430); // Directory Record Type
00644       if ( ValEntry* valEntry = dynamic_cast<ValEntry *>(d) )
00645       {
00646          v = valEntry->GetValue();
00647       }
00648       else
00649       {
00650          gdcmWarningMacro( "Not a ValEntry.");
00651          continue;
00652       }
00653 
00654       if( v == "PATIENT " )
00655       {
00656          si = new DicomDirPatient(true);
00657          if( !AddPatientToEnd( static_cast<DicomDirPatient *>(si)) )
00658          {
00659             delete si;
00660             si = NULL;
00661             gdcmErrorMacro( "Add PatientToEnd failed");
00662          }
00663       }
00664       else if( v == "STUDY " )
00665       {
00666          si = new DicomDirStudy(true);
00667          if( !AddStudyToEnd( static_cast<DicomDirStudy *>(si)) )
00668          {
00669             delete si;
00670             si = NULL;
00671             gdcmErrorMacro( "Add AddStudyToEnd failed");
00672          }
00673       }
00674       else if( v == "SERIES" )
00675       {
00676          si = new DicomDirSerie(true);
00677          if( !AddSerieToEnd( static_cast<DicomDirSerie *>(si)) )
00678          {
00679             delete si;
00680             si = NULL;
00681             gdcmErrorMacro( "Add AddSerieToEnd failed");
00682          }
00683       }
00684       else if( v == "IMAGE " ) 
00685       {
00686          si = new DicomDirImage(true);
00687          if( !AddImageToEnd( static_cast<DicomDirImage *>(si)) )
00688          {
00689             delete si;
00690             si = NULL;
00691             gdcmErrorMacro( "Add AddImageToEnd failed");
00692          }
00693       }
00694       else
00695       {
00696          // It was not a 'PATIENT', nor a 'STUDY', nor a 'SERIE',
00697          // neither an 'IMAGE' SQItem. Skip to next item.
00698          continue;
00699       }
00700       if( si )
00701          MoveSQItem(si,tmpSI);
00702 
00703       tmpSI=s->GetNextSQItem();
00704    }
00705    ClearEntry();
00706 }

void gdcm::DicomDir::CreateDicomDirChainedList std::string const &  path  )  [protected]
 

create a Document-like chained list from a root Directory

Parameters:
path entry point of the tree-like structure

Definition at line 490 of file gdcmDicomDir.cxx.

References Abort, CallEndMethod(), CallProgressMethod(), CallStartMethod(), gdcm::DirListType, gdcmWarningMacro, gdcm::DirList::GetDirName(), gdcm::DirList::GetFilenames(), gdcm::File::IsReadable(), Progress, SetElements(), and gdcm::VectDocument.

Referenced by ParseDirectory().

00491 {
00492    CallStartMethod();
00493    DirList dirList(path,1); // gets recursively the file list
00494    unsigned int count = 0;
00495    VectDocument list;
00496    File *header;
00497 
00498    DirListType fileList = dirList.GetFilenames();
00499 
00500    for( DirListType::iterator it  = fileList.begin();
00501                               it != fileList.end();
00502                               ++it )
00503    {
00504       Progress = (float)(count+1)/(float)fileList.size();
00505       CallProgressMethod();
00506       if( Abort )
00507       {
00508          break;
00509       }
00510 
00511       header = new File( it->c_str() );
00512       if( !header )
00513       {
00514          gdcmWarningMacro( "Failure in new gdcm::File " << it->c_str() );
00515          continue;
00516       }
00517       
00518       if( header->IsReadable() )
00519       {
00520          // Add the file to the chained list:
00521          list.push_back(header);
00522          gdcmWarningMacro( "Readable " << it->c_str() );
00523        }
00524        else
00525        {
00526           delete header;
00527        }
00528        count++;
00529    }
00530    // sorts Patient/Study/Serie/
00531    std::sort(list.begin(), list.end(), DicomDir::HeaderLessThan );
00532    
00533    std::string tmp = dirList.GetDirName();      
00534    //for each File of the chained list, add/update the Patient/Study/Serie/Image info
00535    SetElements(tmp, list);
00536    CallEndMethod();
00537 
00538    for(VectDocument::iterator itDoc=list.begin();
00539        itDoc!=list.end();
00540        ++itDoc)
00541    {
00542       delete dynamic_cast<File *>(*itDoc);
00543    }
00544 }

BinEntry * gdcm::DocEntrySet::GetBinEntry uint16_t  group,
uint16_t  elem
[inherited]
 

Same as Document::GetDocEntry except it only returns a result when the corresponding entry is of type BinEntry.

Parameters:
group Group number of the searched Dicom Element
elem Element number of the searched Dicom Element
Returns:
When present, the corresponding BinEntry.

Definition at line 127 of file gdcmDocEntrySet.cxx.

References gdcmWarningMacro, and gdcm::DocEntrySet::GetDocEntry().

Referenced by gdcm::DocEntrySet::GetEntryBinArea(), and gdcm::DocEntrySet::SetBinEntry().

00128 {
00129    DocEntry *currentEntry = GetDocEntry(group, elem);
00130    if ( !currentEntry )
00131    {
00132       gdcmWarningMacro( "No corresponding BinEntry " << std::hex << group <<
00133                          "," << elem);
00134       return NULL;
00135    }
00136 
00137    return dynamic_cast<BinEntry*>(currentEntry);
00138 }

DictEntry * gdcm::DocEntrySet::GetDictEntry uint16_t  group,
uint16_t  elem,
TagName const &  vr
[protected, inherited]
 

Searches [both] the public [and the shadow dictionary (when they exist)] for the presence of the DictEntry with given group and element, and create a new virtual DictEntry if necessary.

Parameters:
group group number of the searched DictEntry
elem element number of the searched DictEntry
vr Value Representation to use, if necessary
Returns:
Corresponding DictEntry when it exists, NULL otherwise.

Definition at line 558 of file gdcmDocEntrySet.cxx.

References gdcm::GDCM_UNKNOWN, gdcm::DocEntrySet::GetDictEntry(), gdcm::DictEntry::GetName(), gdcm::DictEntry::GetVR(), gdcm::DocEntrySet::NewVirtualDictEntry(), and gdcm::TagName.

00560 {
00561    DictEntry *dictEntry = GetDictEntry(group,elem);
00562    DictEntry *goodEntry = dictEntry;
00563    std::string goodVR = vr;
00564 
00565    if (elem == 0x0000) goodVR="UL";
00566 
00567    if ( goodEntry )
00568    {
00569       if ( goodVR != goodEntry->GetVR()
00570         && goodVR != GDCM_UNKNOWN )
00571       {
00572          goodEntry = NULL;
00573       }
00574    }
00575 
00576    // Create a new virtual DictEntry if necessary
00577    if (!goodEntry)
00578    {
00579       if (dictEntry)
00580       {
00581          goodEntry = NewVirtualDictEntry(group, elem, goodVR, "FIXME", 
00582                                          dictEntry->GetName() );
00583       }
00584       else
00585       {
00586          goodEntry = NewVirtualDictEntry(group, elem, goodVR);
00587       }
00588    }
00589    return goodEntry;
00590 }

DictEntry * gdcm::DocEntrySet::GetDictEntry uint16_t  group,
uint16_t  elem
[protected, inherited]
 

Searches [both] the public [and the shadow dictionary (when they exist)] for the presence of the DictEntry with given group and element. The public dictionary has precedence on the shadow one.

Parameters:
group group number of the searched DictEntry
elem element number of the searched DictEntry
Returns:
Corresponding DictEntry when it exists, NULL otherwise.

Definition at line 534 of file gdcmDocEntrySet.cxx.

References gdcmWarningMacro, and gdcm::Dict::GetEntry().

Referenced by gdcm::DocEntrySet::GetDictEntry(), gdcm::DocEntrySet::NewBinEntry(), gdcm::DocEntrySet::NewSeqEntry(), gdcm::DocEntrySet::NewValEntry(), and gdcm::Document::ReadNextDocEntry().

00535 {
00536    DictEntry *found = 0;
00537    Dict *pubDict = Global::GetDicts()->GetDefaultPubDict();
00538    if (!pubDict) 
00539    {
00540       gdcmWarningMacro( "We SHOULD have a default dictionary");
00541    }
00542    else
00543    {
00544       found = pubDict->GetEntry(group, elem);  
00545    }
00546    return found;
00547 }

DocEntry * gdcm::ElementSet::GetDocEntry uint16_t  group,
uint16_t  elem
[virtual, inherited]
 

retrieves a Dicom Element using (group, element)

Parameters:
group Group number of the searched Dicom Element
elem Element number of the searched Dicom Element
Returns:

Implements gdcm::DocEntrySet.

Definition at line 172 of file gdcmElementSet.cxx.

References gdcm::ElementSet::TagHT, and gdcm::TagKey.

Referenced by gdcm::File::AnonymizeFile(), gdcm::File::AnonymizeNoLoad(), gdcm::FileHelper::CopyBinEntry(), gdcm::FileHelper::CopyValEntry(), CreateDicomDir(), DicomDir(), gdcm::File::File(), gdcm::File::GetPixelAreaLength(), gdcm::File::GetPixelOffset(), gdcm::Document::GetTransferSyntax(), gdcm::File::HasLUT(), gdcm::Document::IsDicomV3(), gdcm::Document::IsPapyrus(), gdcm::File::IsReadable(), gdcm::Document::LoadEntryBinArea(), gdcm::DocEntryArchive::Push(), gdcm::DocEntryArchive::Restore(), gdcm::FileHelper::SetWriteToLibido(), gdcm::FileHelper::SetWriteToNoLibido(), and gdcm::File::Write().

00173 {
00174    TagKey key = DictEntry::TranslateToKey(group, elem);
00175    TagDocEntryHT::iterator it = TagHT.find(key);
00176 
00177    if ( it!=TagHT.end() )
00178       return it->second;
00179    return NULL;
00180 }

void * gdcm::DocEntrySet::GetEntryBinArea uint16_t  group,
uint16_t  elem
[virtual, inherited]
 

Gets (from Header) a 'non string' element value.

Parameters:
group group number of the Entry
elem element number of the Entry
Returns:
Pointer to the 'non string' area

Definition at line 57 of file gdcmDocEntrySet.cxx.

References gdcm::BinEntry::GetBinArea(), and gdcm::DocEntrySet::GetBinEntry().

Referenced by gdcm::PixelReadConvert::GrabInformationsFromFile().

00058 {
00059    BinEntry *entry = GetBinEntry(group, elem);
00060    if( entry )
00061       return entry->GetBinArea();
00062    return 0;
00063 }

int gdcm::DocEntrySet::GetEntryLength uint16_t  group,
uint16_t  elem
[virtual, inherited]
 

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

Parameters:
group Group number of the searched tag.
elem Element number of the searched tag.
Returns:
Corresponding element length; -2 if not found

Definition at line 73 of file gdcmDocEntrySet.cxx.

References gdcm::DocEntrySet::GetDocEntry(), and gdcm::DocEntry::GetLength().

Referenced by SetElement(), and gdcm::File::Write().

00074 {
00075    DocEntry *entry = GetDocEntry(group, elem);
00076    if( entry )
00077       return entry->GetLength();
00078    return -1;
00079 }

std::string gdcm::DocEntrySet::GetEntryValue uint16_t  group,
uint16_t  elem
[virtual, inherited]
 

Get the "std::string representable" value of the Dicom entry.

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

Definition at line 43 of file gdcmDocEntrySet.cxx.

References gdcm::GDCM_UNFOUND, gdcm::DocEntrySet::GetDocEntry(), and gdcm::ContentEntry::GetValue().

Referenced by gdcm::SerieHelper::AddFileName(), gdcm::File::AnonymizeFile(), gdcm::Document::Document(), gdcm::File::File(), gdcm::File::GetBitsAllocated(), gdcm::File::GetBitsStored(), gdcm::File::GetHighBitPosition(), gdcm::File::GetImageNumber(), gdcm::File::GetImageOrientationPatient(), gdcm::File::GetLUTNbits(), gdcm::File::GetModality(), gdcm::File::GetNumberOfScalarComponents(), gdcm::File::GetPixelType(), gdcm::File::GetPlanarConfiguration(), gdcm::File::GetRescaleIntercept(), gdcm::File::GetRescaleSlope(), gdcm::File::GetSamplesPerPixel(), gdcm::Document::GetTransferSyntaxName(), gdcm::File::GetXOrigin(), gdcm::File::GetXSize(), gdcm::File::GetXSpacing(), gdcm::File::GetYOrigin(), gdcm::File::GetYSize(), gdcm::File::GetYSpacing(), gdcm::File::GetZOrigin(), gdcm::File::GetZSize(), gdcm::File::GetZSpacing(), gdcm::PixelReadConvert::GrabInformationsFromFile(), gdcm::File::IsMonochrome(), gdcm::File::IsPaletteColor(), gdcm::File::IsReadable(), gdcm::File::IsSignedPixelData(), gdcm::File::IsYBRFull(), gdcm::Document::operator<(), SetElement(), and gdcm::File::Write().

00044 {
00045    ContentEntry *entry = dynamic_cast<ContentEntry *>(GetDocEntry(group,elem));
00046    if( entry )
00047       return entry->GetValue();
00048    return GDCM_UNFOUND;
00049 }

std::string gdcm::DocEntrySet::GetEntryVR uint16_t  group,
uint16_t  elem
[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 number of the searched tag.
elem Element number of the searched tag.
Returns:
Corresponding element value representation when it exists, and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.

Definition at line 94 of file gdcmDocEntrySet.cxx.

References gdcm::GDCM_UNFOUND, gdcm::DocEntrySet::GetDocEntry(), and gdcm::DocEntry::GetVR().

00095 {
00096    DocEntry *entry = GetDocEntry(group, elem);
00097    if( entry )
00098       return entry->GetVR();
00099    return GDCM_UNFOUND;
00100 }

const std::string& gdcm::Document::GetFileName  )  const [inline, inherited]
 

Accessor to Filename.

Definition at line 79 of file gdcmDocument.h.

Referenced by gdcm::SerieHelper::FileNameLessThan(), ParseDirectory(), and SetElement().

00079 { return Filename; }

FileType gdcm::Document::GetFileType  )  [inherited]
 

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

Returns:
the FileType code

Definition at line 276 of file gdcmDocument.cxx.

References gdcm::Document::Filetype, and gdcm::FileType.

00277 {
00278    return Filetype;
00279 }

DocEntry * gdcm::ElementSet::GetFirstEntry  )  [virtual, inherited]
 

Get the first entry while visiting *the* 'zero level' DocEntrySet (DocEntries out of any Sequence).

Returns:
The first DocEntry if found, otherwhise NULL

Implements gdcm::DocEntrySet.

Definition at line 142 of file gdcmElementSet.cxx.

References gdcm::ElementSet::ItTagHT, and gdcm::ElementSet::TagHT.

Referenced by gdcm::Document::ComputeGroup0002Length(), DicomDir(), and NewMeta().

00143 {
00144    ItTagHT = TagHT.begin();
00145    if (ItTagHT != TagHT.end())
00146       return  ItTagHT->second;
00147    return NULL;
00148 }

DicomDirPatient * gdcm::DicomDir::GetFirstPatient  ) 
 

Get the first entry while visiting the DicomDirPatients.

Returns:
The first DicomDirPatient if found, otherwhise NULL

Definition at line 299 of file gdcmDicomDir.cxx.

References ItPatient, and Patients.

00300 {
00301    ItPatient = Patients.begin();
00302    if ( ItPatient != Patients.end() )
00303       return *ItPatient;
00304    return NULL;
00305 }

DicomDirMeta* gdcm::DicomDir::GetMeta  )  [inline]
 

Returns a pointer to the DicomDirMeta for this DICOMDIR.

Definition at line 67 of file gdcmDicomDir.h.

Referenced by WriteDicomDir().

00067 { return MetaElems; };

DocEntry * gdcm::ElementSet::GetNextEntry  )  [virtual, inherited]
 

Get the next entry while visiting *the* 'zero level' DocEntrySet (DocEntries out of any Sequence).

Note:
: meaningfull only if GetFirstEntry already called
Returns:
The next DocEntry if found, otherwhise NULL

Implements gdcm::DocEntrySet.

Definition at line 156 of file gdcmElementSet.cxx.

References gdcmAssertMacro, gdcm::ElementSet::ItTagHT, and gdcm::ElementSet::TagHT.

Referenced by gdcm::Document::ComputeGroup0002Length().

00157 {
00158    gdcmAssertMacro (ItTagHT != TagHT.end());
00159 
00160    ++ItTagHT;
00161    if (ItTagHT != TagHT.end())
00162       return  ItTagHT->second;
00163    return NULL;
00164 }

DicomDirPatient * gdcm::DicomDir::GetNextPatient  ) 
 

Get the next entry while visiting the DicomDirPatients.

Note:
: meaningfull only if GetFirstEntry already called
Returns:
The next DicomDirPatient if found, otherwhise NULL

Definition at line 312 of file gdcmDicomDir.cxx.

References gdcmAssertMacro, ItPatient, and Patients.

00313 {
00314    gdcmAssertMacro (ItPatient != Patients.end());
00315 
00316    ++ItPatient;
00317    if ( ItPatient != Patients.end() )
00318       return *ItPatient;
00319    return NULL;
00320 }

int gdcm::Base::GetPrintLevel  )  [inline, inherited]
 

Gets the print level for the Dicom Entries.

Definition at line 48 of file gdcmBase.h.

00048 { return PrintLevel; };

float gdcm::DicomDir::GetProgress  )  [inline]
 

GetProgress GetProgress.

Definition at line 96 of file gdcmDicomDir.h.

00096 { return Progress; };

Dict * gdcm::Document::GetPubDict  )  [inherited]
 

Get the public dictionary used.

Definition at line 183 of file gdcmDocument.cxx.

References gdcm::Document::RefPubDict.

Referenced by SetElement().

00184 {
00185    return RefPubDict;
00186 }

SeqEntry * gdcm::DocEntrySet::GetSeqEntry uint16_t  group,
uint16_t  elem
[inherited]
 

Same as Document::GetDocEntry except it only returns a result when the corresponding entry is of type SeqEntry.

Parameters:
group Group number of the searched Dicom Element
elem Element number of the searched Dicom Element
Returns:
When present, the corresponding SeqEntry.

Definition at line 148 of file gdcmDocEntrySet.cxx.

References gdcmWarningMacro, and gdcm::DocEntrySet::GetDocEntry().

00149 {
00150    DocEntry *currentEntry = GetDocEntry(group, elem);
00151    if ( !currentEntry )
00152    {
00153       gdcmWarningMacro( "No corresponding SeqEntry " << std::hex << group <<
00154                         "," << elem);
00155       return NULL;
00156    }
00157 
00158    return dynamic_cast<SeqEntry*>(currentEntry);
00159 }

Dict * gdcm::Document::GetShaDict  )  [inherited]
 

Get the shadow dictionary used.

Definition at line 191 of file gdcmDocument.cxx.

References gdcm::Document::RefShaDict.

00192 {
00193    return RefShaDict;
00194 }

int gdcm::Document::GetSwapCode  )  [inline, inherited]
 

'Swap code' accessor (see SwapCode )

Definition at line 66 of file gdcmDocument.h.

Referenced by gdcm::PixelReadConvert::GrabInformationsFromFile().

00066 { return SwapCode; }

std::string gdcm::Document::GetTransferSyntax  )  [inherited]
 

Accessor to the Transfer Syntax (when present) of the current document (it internally handles reading the value from disk when only parsing occured).

Returns:
The encountered Transfer Syntax of the current document.

Definition at line 287 of file gdcmDocument.cxx.

References gdcm::GDCM_UNKNOWN, gdcm::ElementSet::GetDocEntry(), gdcm::ContentEntry::GetValue(), and gdcm::Document::LoadDocEntrySafe().

Referenced by gdcm::File::ComputeJPEGFragmentInfo(), gdcm::File::ComputeRLEInfo(), gdcm::File::File(), gdcm::PixelReadConvert::GrabInformationsFromFile(), and gdcm::Document::HandleOutOfGroup0002().

00288 {
00289    DocEntry *entry = GetDocEntry(0x0002, 0x0010);
00290    if ( !entry )
00291    {
00292       return GDCM_UNKNOWN;
00293    }
00294 
00295    // The entry might be present but not loaded (parsing and loading
00296    // happen at different stages): try loading and proceed with check...
00297    LoadDocEntrySafe(entry);
00298    if (ValEntry *valEntry = dynamic_cast< ValEntry* >(entry) )
00299    {
00300       std::string transfer = valEntry->GetValue();
00301       // The actual transfer (as read from disk) might be padded. We
00302       // first need to remove the potential padding. We can make the
00303       // weak assumption that padding was not executed with digits...
00304       if  ( transfer.length() == 0 )
00305       {
00306          // for brain damaged headers
00307          return GDCM_UNKNOWN;
00308       }
00309       while ( !isdigit((unsigned char)transfer[transfer.length()-1]) )
00310       {
00311          transfer.erase(transfer.length()-1, 1);
00312       }
00313       return transfer;
00314    }
00315    return GDCM_UNKNOWN;
00316 }

std::string gdcm::Document::GetTransferSyntaxName  )  [inherited]
 

Accesses the info from 0002,0010 : Transfer Syntax and TS.

Returns:
The full Transfer Syntax Name (as opposed to Transfer Syntax UID)

Definition at line 322 of file gdcmDocument.cxx.

References gdcm::GDCM_NOTLOADED, gdcm::GDCM_UNFOUND, gdcmErrorMacro, gdcmWarningMacro, and gdcm::DocEntrySet::GetEntryValue().

Referenced by gdcm::Document::HandleOutOfGroup0002().

00323 {
00324    // use the TS (TS : Transfer Syntax)
00325    std::string transferSyntax = GetEntryValue(0x0002,0x0010);
00326 
00327    if ( (transferSyntax.find(GDCM_NOTLOADED) < transferSyntax.length()) )
00328    {
00329       gdcmErrorMacro( "Transfer Syntax not loaded. " << std::endl
00330                << "Better you increase MAX_SIZE_LOAD_ELEMENT_VALUE" );
00331       return "Uncompressed ACR-NEMA";
00332    }
00333    if ( transferSyntax == GDCM_UNFOUND )
00334    {
00335       gdcmWarningMacro( "Unfound Transfer Syntax (0002,0010)");
00336       return "Uncompressed ACR-NEMA";
00337    }
00338 
00339    // we do it only when we need it
00340    const TSKey &tsName = Global::GetTS()->GetValue( transferSyntax );
00341 
00342    // Global::GetTS() is a global static you shall never try to delete it!
00343    return tsName;
00344 }

ValEntry * gdcm::DocEntrySet::GetValEntry uint16_t  group,
uint16_t  elem
[inherited]
 

Same as Document::GetDocEntry except it only returns a result when the corresponding entry is of type ValEntry.

Parameters:
group Group number of the searched Dicom Element
elem Element number of the searched Dicom Element
Returns:
When present, the corresponding ValEntry.

Definition at line 110 of file gdcmDocEntrySet.cxx.

References gdcm::DocEntrySet::GetDocEntry().

Referenced by gdcm::DocEntrySet::SetValEntry(), and gdcm::File::Write().

00111 {
00112    DocEntry *currentEntry = GetDocEntry(group, elem);
00113    if ( !currentEntry )
00114       return NULL;
00115 
00116    return dynamic_cast<ValEntry*>(currentEntry);
00117 }

bool gdcm::DicomDir::HeaderLessThan Document header1,
Document header2
[static, private]
 

compares two files

Definition at line 1012 of file gdcmDicomDir.cxx.

01013 {
01014    return *header1 < *header2;
01015 }

void gdcm::DicomDir::Initialize  )  [private]
 

Sets all fields to NULL.

Reimplemented from gdcm::Document.

Definition at line 587 of file gdcmDicomDir.cxx.

References Abort, EndArg, EndMethod, EndMethodArgDelete, MetaElems, Progress, ProgressArg, ProgressMethod, ProgressMethodArgDelete, StartArg, StartMethod, and StartMethodArgDelete.

Referenced by DicomDir().

00588 {
00589    StartMethod             = NULL;
00590    ProgressMethod          = NULL;
00591    EndMethod               = NULL;
00592    StartMethodArgDelete    = NULL;
00593    ProgressMethodArgDelete = NULL;
00594    EndMethodArgDelete      = NULL;
00595    StartArg                = NULL;
00596    ProgressArg             = NULL;
00597    EndArg                  = NULL;
00598 
00599    Progress = 0.0;
00600    Abort = false;
00601 
00602    MetaElems = NULL;   
00603 }

BinEntry * gdcm::DocEntrySet::InsertBinEntry uint8_t *  binArea,
int  lgth,
uint16_t  group,
uint16_t  elem,
TagName const &  vr = GDCM_UNKNOWN
[inherited]
 

Modifies the value of a given Header Entry (Dicom Element) when it exists. Create it with the given value when unexistant. A copy of the binArea is made to be kept in the Document.

Parameters:
binArea (binary) value to be set
lgth length of the Bin Area we want to set
group Group number of the Entry
elem Element number of the Entry
vr V(alue) R(epresentation) of the Entry -if private Entry-
Returns:
pointer to the modified/created Header Entry (NULL when creation failed).

Definition at line 309 of file gdcmDocEntrySet.cxx.

References gdcm::DocEntrySet::AddEntry(), gdcmWarningMacro, gdcm::DocEntrySet::GetDocEntry(), gdcm::DocEntry::GetVR(), gdcm::DocEntrySet::NewBinEntry(), gdcm::DocEntrySet::RemoveEntry(), gdcm::DocEntrySet::SetBinEntry(), and gdcm::TagName.

Referenced by gdcm::File::InitializeDefaultFile(), and gdcm::FileHelper::InsertBinEntry().

00312 {
00313    BinEntry *binEntry = 0;
00314    DocEntry *currentEntry = GetDocEntry( group, elem );
00315 
00316    // Verify the currentEntry
00317    if (currentEntry)
00318    {
00319       binEntry = dynamic_cast<BinEntry *>(currentEntry);
00320 
00321       // Verify the VR
00322       if( binEntry )
00323          if( binEntry->GetVR()!=vr )
00324             binEntry = NULL;
00325 
00326       // if currentEntry doesn't correspond to the requested valEntry
00327       if( !binEntry)
00328       {
00329          if( !RemoveEntry(currentEntry) )
00330          {
00331             gdcmWarningMacro( "Removal of previous DocEntry failed.");
00332 
00333             return NULL;
00334          }
00335       }
00336    }
00337 
00338    // Create a new binEntry if necessary
00339    if( !binEntry)
00340    {
00341       binEntry = NewBinEntry(group, elem, vr);
00342 
00343       if ( !AddEntry(binEntry) )
00344       {
00345          gdcmWarningMacro( "AddEntry failed allthough this is a creation.");
00346 
00347          delete binEntry;
00348          return NULL;
00349       }
00350    }
00351 
00352    // Set the binEntry value
00353    uint8_t *tmpArea;
00354    if( lgth>0 && binArea )
00355    {
00356       tmpArea = new uint8_t[lgth];
00357       memcpy(tmpArea,binArea,lgth);
00358    }
00359    else
00360    {
00361       tmpArea = 0;
00362    }
00363    if( !SetBinEntry(tmpArea,lgth,binEntry) )
00364    {
00365       if( tmpArea )
00366       {
00367          delete[] tmpArea;
00368       }
00369    }
00370 
00371    return binEntry;
00372 }  

SeqEntry * gdcm::DocEntrySet::InsertSeqEntry uint16_t  group,
uint16_t  elem
[inherited]
 

Modifies the value of a given Doc Entry (Dicom Element) when it exists. Creates it when unexistant.

Parameters:
group Group number of the Entry
elem Element number of the Entry
Returns:
pointer to the modified/created SeqEntry (NULL when creation failed).

Definition at line 382 of file gdcmDocEntrySet.cxx.

References gdcm::DocEntrySet::AddEntry(), gdcmWarningMacro, gdcm::DocEntrySet::GetDocEntry(), gdcm::DocEntrySet::NewSeqEntry(), and gdcm::DocEntrySet::RemoveEntry().

Referenced by gdcm::FileHelper::InsertSeqEntry().

00383 {
00384    SeqEntry *seqEntry = 0;
00385    DocEntry *currentEntry = GetDocEntry( group, elem );
00386 
00387    // Verify the currentEntry
00388    if( currentEntry )
00389    {
00390       seqEntry = dynamic_cast<SeqEntry *>(currentEntry);
00391 
00392       // Verify the VR
00393       if( seqEntry )
00394          seqEntry = NULL;
00395 
00396       // if currentEntry doesn't correspond to the requested seqEntry
00397       if( !seqEntry )
00398       {
00399          if (!RemoveEntry(currentEntry))
00400          {
00401             gdcmWarningMacro( "Removal of previous DocEntry failed.");
00402 
00403             return NULL;
00404          }
00405       }
00406    }
00407    // Create a new seqEntry if necessary
00408    if( !seqEntry )
00409    {
00410       seqEntry = NewSeqEntry(group, elem);
00411 
00412       if( !AddEntry(seqEntry) )
00413       {
00414          gdcmWarningMacro( "AddEntry failed allthough this is a creation.");
00415 
00416          delete seqEntry;
00417          return NULL;
00418       }
00419    }
00420 
00421    // TODO : Find a trick to insert a SequenceDelimitationItem 
00422         //       in the SeqEntry, at the end.
00423    return seqEntry;
00424 } 

ValEntry * gdcm::DocEntrySet::InsertValEntry std::string const &  value,
uint16_t  group,
uint16_t  elem,
TagName const &  vr = GDCM_UNKNOWN
[inherited]
 

Modifies the value of a given Doc Entry (Dicom Element) when it exists. Create it with the given value when unexistant.

Parameters:
value (string) Value to be set
group Group number of the Entry
elem Element number of the Entry
vr V(alue) R(epresentation) of the Entry -if private Entry-
Returns:
pointer to the modified/created Header Entry (NULL when creation failed).

Definition at line 250 of file gdcmDocEntrySet.cxx.

References gdcm::DocEntrySet::AddEntry(), gdcmWarningMacro, gdcm::DocEntrySet::GetDocEntry(), gdcm::DocEntry::GetVR(), gdcm::DocEntrySet::NewValEntry(), gdcm::DocEntrySet::RemoveEntry(), gdcm::DocEntrySet::SetValEntry(), and gdcm::TagName.

Referenced by gdcm::File::InitializeDefaultFile(), gdcm::FileHelper::InsertValEntry(), and gdcm::File::Write().

00253 {
00254    ValEntry *valEntry = 0;
00255    DocEntry *currentEntry = GetDocEntry( group, elem );
00256    
00257    if (currentEntry)
00258    {
00259       valEntry = dynamic_cast<ValEntry *>(currentEntry);
00260 
00261       // Verify the VR
00262       if( valEntry )
00263          if( valEntry->GetVR()!=vr )
00264             valEntry = NULL;
00265 
00266       // if currentEntry doesn't correspond to the requested valEntry
00267       if( !valEntry)
00268       {
00269          if( !RemoveEntry(currentEntry) )
00270          {
00271             gdcmWarningMacro( "Removal of previous DocEntry failed.");
00272 
00273             return NULL;
00274          }
00275       }
00276    }
00277 
00278    // Create a new valEntry if necessary
00279    if( !valEntry )
00280    {
00281       valEntry = NewValEntry( group, elem, vr );
00282 
00283       if ( !AddEntry(valEntry) )
00284       {
00285          gdcmWarningMacro("AddEntry failed although this is a creation.");
00286 
00287          delete valEntry;
00288          return NULL;
00289       }
00290    }
00291 
00292    // Set the binEntry value
00293    SetValEntry(value, valEntry); // The std::string value
00294    return valEntry;
00295 }

bool gdcm::DicomDir::IsAborted  )  [inline]
 

IsAborted IsAborted.

Definition at line 100 of file gdcmDicomDir.h.

00100 { return Abort; };

bool gdcm::Document::IsDicomV3  )  [inherited]
 

Predicate for dicom version 3 file.

Returns:
True when the file is a dicom version 3.

Definition at line 245 of file gdcmDocument.cxx.

References gdcm::ElementSet::GetDocEntry().

Referenced by gdcm::File::GetYSize(), and gdcm::PixelReadConvert::GrabInformationsFromFile().

00246 {
00247    // Checking if Transfer Syntax exists is enough
00248    // Anyway, it's to late check if the 'Preamble' was found ...
00249    // And ... would it be a rich idea to check ?
00250    // (some 'no Preamble' DICOM images exist !)
00251    return GetDocEntry(0x0002, 0x0010) != NULL;
00252 }

bool gdcm::ElementSet::IsEmpty  )  [inline, virtual, inherited]
 

Tells us if the ElementSet contains no entry.

Implements gdcm::DocEntrySet.

Definition at line 63 of file gdcmElementSet.h.

Referenced by gdcm::Document::IsReadable().

00063 { return TagHT.empty(); };

bool gdcm::Document::IsPapyrus  )  [inherited]
 

Predicate for Papyrus file Dedicated to whomsoever it may concern.

Returns:
True when the file is a Papyrus file.

Definition at line 259 of file gdcmDocument.cxx.

References gdcm::ElementSet::GetDocEntry().

00260 {
00261    // check for Papyrus private Sequence
00262    DocEntry *e = GetDocEntry(0x0041, 0x1050);
00263    if ( !e )
00264       return false;
00265    // check if it's actually a Sequence
00266    if ( !dynamic_cast<SeqEntry*>(e) )
00267       return  false;
00268    return true;
00269 }

bool gdcm::DicomDir::IsReadable  )  [virtual]
 

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

Returns:
true when Document is the one of a reasonable DicomDir, false otherwise.

Reimplemented from gdcm::Document.

Definition at line 216 of file gdcmDicomDir.cxx.

References gdcmWarningMacro, MetaElems, Patients, and gdcm::Unknown.

00217 {
00218    if( Filetype == Unknown)
00219    {
00220       gdcmWarningMacro( "Wrong filetype");
00221       return false;
00222    }
00223    if( !MetaElems )
00224    {
00225       gdcmWarningMacro( "Meta Elements missing in DicomDir");
00226       return false;
00227    }
00228    if( Patients.size() <= 0 )
00229    {
00230       gdcmWarningMacro( "NO Patient in DicomDir");
00231       return false;
00232    }
00233 
00234    return true;
00235 }

void gdcm::Document::LoadDocEntrySafe DocEntry entry  )  [inherited]
 

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

Parameters:
entry DocEntry whose value will be loaded.

Definition at line 581 of file gdcmDocument.cxx.

References gdcm::Document::Fp, and gdcm::Document::LoadDocEntry().

Referenced by gdcm::Document::GetTransferSyntax().

00582 {
00583    if(Fp)
00584    {
00585       long PositionOnEntry = Fp->tellg();
00586       LoadDocEntry(entry);
00587       Fp->seekg(PositionOnEntry, std::ios::beg);
00588    }
00589 }

void gdcm::Document::LoadEntryBinArea BinEntry elem  )  [virtual, inherited]
 

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

Parameters:
elem Entry whose binArea is going to be loaded

Todo:
check the result

Definition at line 541 of file gdcmDocument.cxx.

References gdcm::Document::CloseFile(), gdcm::Document::Fp, gdcmWarningMacro, gdcm::BinEntry::GetBinArea(), gdcm::DocEntry::GetLength(), gdcm::DocEntry::GetOffset(), gdcm::Document::OpenFile(), and gdcm::BinEntry::SetBinArea().

00542 {
00543    if(elem->GetBinArea())
00544       return;
00545 
00546    bool openFile = !Fp;
00547    if(openFile)
00548       OpenFile();
00549 
00550    size_t o =(size_t)elem->GetOffset();
00551    Fp->seekg(o, std::ios::beg);
00552 
00553    size_t l = elem->GetLength();
00554    uint8_t *a = new uint8_t[l];
00555    if( !a )
00556    {
00557       gdcmWarningMacro( "Cannot allocate BinEntry content");
00558       return;
00559    }
00560 
00562    Fp->read((char*)a, l);
00563    if( Fp->fail() || Fp->eof())
00564    {
00565       delete[] a;
00566       return;
00567    }
00568 
00569    elem->SetBinArea(a);
00570 
00571    if(openFile)
00572       CloseFile();
00573 }

void gdcm::Document::LoadEntryBinArea uint16_t  group,
uint16_t  elem
[virtual, inherited]
 

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

Parameters:
group group number of the Entry
elem element number of the Entry

Definition at line 522 of file gdcmDocument.cxx.

References gdcm::ElementSet::GetDocEntry().

Referenced by gdcm::Document::Document(), gdcm::PixelReadConvert::GrabInformationsFromFile(), and gdcm::Document::LoadDocEntry().

00523 {
00524    // Search the corresponding DocEntry
00525    DocEntry *docElement = GetDocEntry(group, elem);
00526    if ( !docElement )
00527       return;
00528 
00529    BinEntry *binElement = dynamic_cast<BinEntry *>(docElement);
00530    if( !binElement )
00531       return;
00532 
00533    LoadEntryBinArea(binElement);
00534 }

void gdcm::DicomDir::MoveSQItem DocEntrySet dst,
DocEntrySet src
[private]
 

Move the content of the source SQItem to the destination SQItem Only DocEntry's are moved.

Parameters:
dst destination SQItem
src source SQItem

Definition at line 995 of file gdcmDicomDir.cxx.

References gdcm::DocEntrySet::AddEntry(), gdcm::DocEntrySet::GetFirstEntry(), and gdcm::DocEntrySet::RemoveEntryNoDestroy().

Referenced by CreateDicomDir().

00996 {
00997    DocEntry *entry;
00998 
00999    entry = src->GetFirstEntry();
01000    while(entry)
01001    {
01002       src->RemoveEntryNoDestroy(entry);
01003       dst->AddEntry(entry);
01004       // we destroyed -> the current iterator is not longer valid
01005       entry = src->GetFirstEntry();
01006    }
01007 }

BinEntry * gdcm::DocEntrySet::NewBinEntry uint16_t  group,
uint16_t  elem,
TagName const &  vr = GDCM_UNKNOWN
[inherited]
 

Build a new Bin Entry from all the low level arguments. Check for existence of dictionary entry, and build a default one when absent.

Parameters:
group group number of the new Entry
elem element number of the new Entry
vr VR of the new Entry

Definition at line 471 of file gdcmDocEntrySet.cxx.

References gdcmAssertMacro, gdcmWarningMacro, gdcm::DocEntrySet::GetDictEntry(), and gdcm::TagName.

Referenced by gdcm::FileHelper::CopyBinEntry(), gdcm::DocEntrySet::InsertBinEntry(), and gdcm::Document::ReadNextDocEntry().

00473 {
00474    DictEntry *dictEntry = GetDictEntry(group, elem, vr);
00475    gdcmAssertMacro(dictEntry);
00476 
00477    BinEntry *newEntry = new BinEntry(dictEntry);
00478    if (!newEntry) 
00479    {
00480       gdcmWarningMacro( "Failed to allocate BinEntry");
00481       return 0;
00482    }
00483    return newEntry;
00484 }

DicomDirMeta * gdcm::DicomDir::NewMeta  ) 
 

adds *the* Meta to a partially created DICOMDIR

Definition at line 240 of file gdcmDicomDir.cxx.

References gdcm::SQItem::AddEntry(), gdcm::ElementSet::GetFirstEntry(), MetaElems, gdcm::ElementSet::RemoveEntryNoDestroy(), and gdcm::SQItem::SetSQItemNumber().

Referenced by CreateDicomDir(), and DicomDir().

00241 {
00242    if( MetaElems )
00243       delete MetaElems;
00244 
00245    DocEntry *entry = GetFirstEntry();
00246    if( entry )
00247    { 
00248       MetaElems = new DicomDirMeta(true);
00249 
00250       entry = GetFirstEntry();
00251       while( entry )
00252       {
00253          if( dynamic_cast<SeqEntry *>(entry) )
00254             break;
00255 
00256          RemoveEntryNoDestroy(entry);
00257          MetaElems->AddEntry(entry);
00258 
00259          entry = GetFirstEntry();
00260       }
00261    }
00262    else  // after root directory parsing
00263    {
00264       MetaElems = new DicomDirMeta(false);
00265    }
00266    MetaElems->SetSQItemNumber(0); // To avoid further missprinting
00267    return MetaElems;  
00268 }

DicomDirPatient * gdcm::DicomDir::NewPatient  ) 
 

adds a new Patient (with the basic elements) to a partially created DICOMDIR

Definition at line 274 of file gdcmDicomDir.cxx.

References AddPatientToEnd().

00275 {
00276    DicomDirPatient *p = new DicomDirPatient();
00277    AddPatientToEnd( p );
00278    return p;
00279 }

SeqEntry * gdcm::DocEntrySet::NewSeqEntry uint16_t  group,
uint16_t  elem
[inherited]
 

Build a new Seq Entry from all the low level arguments. Check for existence of dictionary entry, and build a default one when absent.

Parameters:
group group number of the new Entry
elem element number of the new Entry

Definition at line 493 of file gdcmDocEntrySet.cxx.

References gdcmAssertMacro, gdcmWarningMacro, and gdcm::DocEntrySet::GetDictEntry().

Referenced by gdcm::DocEntrySet::InsertSeqEntry(), and gdcm::Document::ReadNextDocEntry().

00494 {
00495    DictEntry *dictEntry = GetDictEntry(group, elem, "SQ");
00496    gdcmAssertMacro(dictEntry);
00497 
00498    SeqEntry *newEntry = new SeqEntry( dictEntry );
00499    if (!newEntry)
00500    {
00501       gdcmWarningMacro( "Failed to allocate SeqEntry");
00502       return 0;
00503    }
00504    return newEntry;
00505 }

ValEntry * gdcm::DocEntrySet::NewValEntry uint16_t  group,
uint16_t  elem,
TagName const &  vr = GDCM_UNKNOWN
[inherited]
 

Build a new Val Entry from all the low level arguments. Check for existence of dictionary entry, and build a default one when absent.

Parameters:
group group number of the new Entry
elem element number of the new Entry
vr VR of the new Entry

Definition at line 447 of file gdcmDocEntrySet.cxx.

References gdcmAssertMacro, gdcmWarningMacro, gdcm::DocEntrySet::GetDictEntry(), and gdcm::TagName.

Referenced by gdcm::FileHelper::CopyValEntry(), gdcm::DocEntrySet::InsertValEntry(), and gdcm::Document::ReadNextDocEntry().

00449 {
00450    DictEntry *dictEntry = GetDictEntry(group, elem, vr);
00451    gdcmAssertMacro(dictEntry);
00452 
00453    ValEntry *newEntry = new ValEntry(dictEntry);
00454    if (!newEntry) 
00455    {
00456       gdcmWarningMacro( "Failed to allocate ValEntry");
00457       return 0;
00458    }
00459    return newEntry;
00460 }

DictEntry * gdcm::DocEntrySet::NewVirtualDictEntry uint16_t  group,
uint16_t  elem,
TagName const &  vr = GDCM_UNKNOWN,
TagName const &  vm = GDCM_UNKNOWN,
TagName const &  name = GDCM_UNKNOWN
[inherited]
 

Request a new virtual dict entry to the dict set.

Parameters:
group group number of the underlying DictEntry
elem element number of the underlying DictEntry
vr VR (Value Representation) of the underlying DictEntry
vm VM (Value Multiplicity) of the underlying DictEntry
name english name

Definition at line 515 of file gdcmDocEntrySet.cxx.

References gdcm::TagName.

Referenced by gdcm::File::File(), and gdcm::DocEntrySet::GetDictEntry().

00519 {
00520    return Global::GetDicts()->NewVirtualDictEntry(group,elem,vr,vm,name);
00521 }

std::ifstream * gdcm::Document::OpenFile  )  [inherited]
 

Tries to open the file Document::Filename and checks the preamble when existing.

Returns:
The FILE pointer on success.

Definition at line 395 of file gdcmDocument.cxx.

References gdcm::Document::CloseFile(), gdcm::Document::Fp, gdcmDebugMacro, gdcmWarningMacro, and gdcm::Document::HasDCMPreamble.

Referenced by gdcm::Document::Document(), gdcm::File::File(), gdcm::FileHelper::GetRaw(), and gdcm::Document::LoadEntryBinArea().

00396 {
00397    HasDCMPreamble = false;
00398    if (Filename.length() == 0) 
00399    {
00400       return 0;
00401    }
00402 
00403    if(Fp)
00404    {
00405       gdcmWarningMacro( "File already open: " << Filename.c_str());
00406       CloseFile();
00407    }
00408 
00409    Fp = new std::ifstream(Filename.c_str(), std::ios::in | std::ios::binary);
00410    if( ! *Fp )
00411    {
00412       gdcmDebugMacro( "Cannot open file: " << Filename.c_str());
00413       delete Fp;
00414       Fp = 0;
00415       return 0;
00416    }
00417  
00418    uint16_t zero = 0;
00419    Fp->read((char*)&zero, (size_t)2);
00420    if( Fp->eof() )
00421    {
00422       CloseFile();
00423       return 0;
00424    }
00425  
00426    //ACR -- or DICOM with no Preamble; may start with a Shadow Group --
00427    if( 
00428        zero == 0x0001 || zero == 0x0100 || zero == 0x0002 || zero == 0x0200 ||
00429        zero == 0x0003 || zero == 0x0300 || zero == 0x0004 || zero == 0x0400 ||
00430        zero == 0x0005 || zero == 0x0500 || zero == 0x0006 || zero == 0x0600 ||
00431        zero == 0x0007 || zero == 0x0700 || zero == 0x0008 || zero == 0x0800 )
00432    {
00433       std::string msg 
00434          = Util::Format("ACR/DICOM with no preamble: (%04x)\n", zero);
00435       gdcmWarningMacro( msg.c_str() );
00436       return Fp;
00437    }
00438  
00439    //DICOM
00440    Fp->seekg(126L, std::ios::cur);
00441    char dicm[4] = {' ',' ',' ',' '};
00442    Fp->read(dicm,  (size_t)4);
00443    if( Fp->eof() )
00444    {
00445       CloseFile();
00446       return 0;
00447    }
00448    if( memcmp(dicm, "DICM", 4) == 0 )
00449    {
00450       HasDCMPreamble = true;
00451       return Fp;
00452    }
00453  
00454    CloseFile();
00455    gdcmWarningMacro( "Not DICOM/ACR (missing preamble)" << Filename.c_str());
00456  
00457    return 0;
00458 }

bool gdcm::Document::operator< Document document  )  [inherited]
 

Compares two documents, according to DicomDir rules.

Warning:
Does NOT work with ACR-NEMA files
Todo:
Find a trick to solve the pb (use RET fields ?)
Parameters:
document to compare with current one
Returns:
true if 'smaller'

Definition at line 598 of file gdcmDocument.cxx.

References gdcm::DocEntrySet::GetEntryValue().

00599 {
00600    // Patient Name
00601    std::string s1 = GetEntryValue(0x0010,0x0010);
00602    std::string s2 = document.GetEntryValue(0x0010,0x0010);
00603    if(s1 < s2)
00604    {
00605       return true;
00606    }
00607    else if( s1 > s2 )
00608    {
00609       return false;
00610    }
00611    else
00612    {
00613       // Patient ID
00614       s1 = GetEntryValue(0x0010,0x0020);
00615       s2 = document.GetEntryValue(0x0010,0x0020);
00616       if ( s1 < s2 )
00617       {
00618          return true;
00619       }
00620       else if ( s1 > s2 )
00621       {
00622          return false;
00623       }
00624       else
00625       {
00626          // Study Instance UID
00627          s1 = GetEntryValue(0x0020,0x000d);
00628          s2 = document.GetEntryValue(0x0020,0x000d);
00629          if ( s1 < s2 )
00630          {
00631             return true;
00632          }
00633          else if( s1 > s2 )
00634          {
00635             return false;
00636          }
00637          else
00638          {
00639             // Serie Instance UID
00640             s1 = GetEntryValue(0x0020,0x000e);
00641             s2 = document.GetEntryValue(0x0020,0x000e);    
00642             if ( s1 < s2 )
00643             {
00644                return true;
00645             }
00646             else if( s1 > s2 )
00647             {
00648                return false;
00649             }
00650          }
00651       }
00652    }
00653    return false;
00654 }

void gdcm::DicomDir::ParseDirectory  ) 
 

fills the whole structure, starting from a root Directory

Definition at line 325 of file gdcmDicomDir.cxx.

References CreateDicomDir(), CreateDicomDirChainedList(), and gdcm::Document::GetFileName().

Referenced by DicomDir().

00326 {
00327    CreateDicomDirChainedList( GetFileName() );
00328    CreateDicomDir();
00329 }

void gdcm::DicomDir::Print std::ostream &  os = std::cout,
std::string const &  indent = ""
[virtual]
 

Canonical Printer.

Parameters:
os ostream we want to print in
indent Indentation string to be prepended during printing

Reimplemented from gdcm::ElementSet.

Definition at line 1024 of file gdcmDicomDir.cxx.

References MetaElems, Patients, gdcm::DicomDirMeta::Print(), and gdcm::Base::SetPrintLevel().

01025 {
01026    if( MetaElems )
01027    {
01028       MetaElems->SetPrintLevel(PrintLevel);
01029       MetaElems->Print(os);   
01030    }   
01031    for(ListDicomDirPatient::iterator cc  = Patients.begin();
01032                                      cc != Patients.end();
01033                                    ++cc)
01034    {
01035      (*cc)->SetPrintLevel(PrintLevel);
01036      (*cc)->Print(os);
01037    }
01038 }

uint16_t gdcm::Document::ReadInt16  )  throw ( FormatError ) [protected, inherited]
 

Reads a supposed to be 16 Bits integer (swaps it depending on processor endianness).

Returns:
read value

Definition at line 663 of file gdcmDocument.cxx.

Referenced by gdcm::Document::LoadDocEntry(), gdcm::Document::ReadNextDocEntry(), and gdcm::File::ReadTag().

00665 {
00666    uint16_t g;
00667    Fp->read ((char*)&g, (size_t)2);
00668    if ( Fp->fail() )
00669    {
00670       throw FormatError( "Document::ReadInt16()", " file error." );
00671    }
00672    if( Fp->eof() )
00673    {
00674       throw FormatError( "Document::ReadInt16()", "EOF." );
00675    }
00676    g = SwapShort(g); 
00677    return g;
00678 }

uint32_t gdcm::Document::ReadInt32  )  throw ( FormatError ) [protected, inherited]
 

Reads a supposed to be 32 Bits integer (swaps it depending on processor endianness).

Returns:
read value

Definition at line 685 of file gdcmDocument.cxx.

Referenced by gdcm::File::ComputeRLEInfo(), gdcm::Document::LoadDocEntry(), and gdcm::File::ReadTagLength().

00687 {
00688    uint32_t g;
00689    Fp->read ((char*)&g, (size_t)4);
00690    if ( Fp->fail() )
00691    {
00692       throw FormatError( "Document::ReadInt32()", " file error." );
00693    }
00694    if( Fp->eof() )
00695    {
00696       throw FormatError( "Document::ReadInt32()", "EOF." );
00697    }
00698    g = SwapLong(g);
00699    return g;
00700 }

bool gdcm::ElementSet::RemoveEntry DocEntry entryToRemove  )  [virtual, inherited]
 

Clear the hash table from given entry AND delete the entry.

Parameters:
entryToRemove Entry to remove AND delete.

Implements gdcm::DocEntrySet.

Definition at line 89 of file gdcmElementSet.cxx.

References gdcmWarningMacro, gdcm::DocEntry::GetKey(), gdcm::ElementSet::TagHT, and gdcm::TagKey.

Referenced by gdcm::File::File(), and gdcm::DocEntryArchive::Restore().

00090 {
00091    const TagKey &key = entryToRemove->GetKey();
00092    if( TagHT.count(key) == 1 )
00093    {
00094       TagHT.erase(key);
00095       //gdcmWarningMacro( "One element erased.");
00096       delete entryToRemove;
00097       return true;
00098    }
00099 
00100    gdcmWarningMacro( "Key not present");
00101    return false ;
00102 }

bool gdcm::ElementSet::RemoveEntryNoDestroy DocEntry entryToRemove  )  [virtual, inherited]
 

Clear the hash table from given entry BUT keep the entry.

Parameters:
entryToRemove Entry to remove.

Implements gdcm::DocEntrySet.

Definition at line 108 of file gdcmElementSet.cxx.

References gdcmWarningMacro, gdcm::DocEntry::GetKey(), gdcm::ElementSet::TagHT, and gdcm::TagKey.

Referenced by NewMeta(), gdcm::DocEntryArchive::Push(), and gdcm::File::Write().

00109 {
00110    const TagKey &key = entryToRemove->GetKey();
00111    if( TagHT.count(key) == 1 )
00112    {
00113       TagHT.erase(key);
00114       //gdcmWarningMacro( "One element erased.");
00115       return true;
00116    }
00117 
00118    gdcmWarningMacro( "Key not present");
00119    return false ;
00120 }

bool gdcm::DocEntrySet::SetBinEntry uint8_t *  content,
int  lgth,
BinEntry entry
[inherited]
 

Accesses an existing BinEntry (i.e. a Dicom Element) and modifies it's content with the given value.

Parameters:
content new value (void* -> uint8_t*) to substitute with
entry Entry to be modified
lgth new value length

Definition at line 228 of file gdcmDocEntrySet.cxx.

References gdcm::GDCM_BINLOADED, gdcm::BinEntry::SetBinArea(), gdcm::DocEntry::SetLength(), and gdcm::ContentEntry::SetValue().

00229 {
00230    if(entry)
00231    {
00232       entry->SetBinArea(content);  
00233       entry->SetLength(lgth);
00234       entry->SetValue(GDCM_BINLOADED);
00235       return true;
00236    }
00237    return false;
00238 }

bool gdcm::DocEntrySet::SetBinEntry uint8_t *  content,
int  lgth,
uint16_t  group,
uint16_t  elem
[inherited]
 

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

Parameters:
content new value (void* -> uint8_t*) to substitute with
lgth new value length
group group number of the Dicom Element to modify
elem element number of the Dicom Element to modify

Definition at line 191 of file gdcmDocEntrySet.cxx.

References gdcmWarningMacro, and gdcm::DocEntrySet::GetBinEntry().

Referenced by gdcm::DocEntrySet::InsertBinEntry(), and gdcm::FileHelper::SetBinEntry().

00193 {
00194    BinEntry *entry = GetBinEntry(group, elem);
00195    if (!entry )
00196    {
00197       gdcmWarningMacro( "No corresponding ValEntry " << std::hex << group <<
00198                         "," << elem << " element (try promotion first).");
00199       return false;
00200    }
00201 
00202    return SetBinEntry(content,lgth,entry);
00203 } 

void gdcm::DicomDir::SetElement std::string const &  path,
DicomDirType  type,
Document header
[private]
 

adds to the HTable the Entries (Dicom Elements) corresponding to the given type

Parameters:
path full path file name (only used when type = GDCM_DICOMDIR_IMAGE
type DicomDirObject type to create (GDCM_DICOMDIR_PATIENT, GDCM_DICOMDIR_STUDY, GDCM_DICOMDIR_SERIE ...)
header Header of the current file

Definition at line 855 of file gdcmDicomDir.cxx.

References gdcm::SQItem::AddEntry(), AddImageToEnd(), AddPatientToEnd(), AddSerieToEnd(), AddStudyToEnd(), GDCM_DICOMDIR_IMAGE, GDCM_DICOMDIR_META, GDCM_DICOMDIR_PATIENT, GDCM_DICOMDIR_SERIE, GDCM_DICOMDIR_STUDY, gdcm::GDCM_UNFOUND, gdcmErrorMacro, gdcmWarningMacro, gdcm::Dict::GetEntry(), gdcm::DocEntrySet::GetEntryLength(), gdcm::DocEntrySet::GetEntryValue(), gdcm::Document::GetFileName(), gdcm::Document::GetPubDict(), gdcm::ListDicomDirElem, MetaElems, gdcm::DocEntry::SetOffset(), and gdcm::ValEntry::SetValue().

Referenced by SetElements().

00857 {
00858    ListDicomDirElem elemList; //FIXME this is going to be a by copy operation
00859    ListDicomDirElem::const_iterator it;
00860    uint16_t tmpGr, tmpEl;
00861    DictEntry *dictEntry;
00862    ValEntry *entry;
00863    std::string val;
00864    SQItem *si;
00865 
00866    switch( type )
00867    {
00868       case GDCM_DICOMDIR_IMAGE:
00869          elemList = Global::GetDicomDirElements()->GetDicomDirImageElements();
00870          si = new DicomDirImage(true);
00871          if( !AddImageToEnd(static_cast<DicomDirImage *>(si)) )
00872          {
00873             delete si;
00874             gdcmErrorMacro( "Add ImageToEnd failed");
00875          }
00876          break;
00877       case GDCM_DICOMDIR_SERIE:
00878          elemList = Global::GetDicomDirElements()->GetDicomDirSerieElements();
00879          si = new DicomDirSerie(true);
00880          if( !AddSerieToEnd(static_cast<DicomDirSerie *>(si)) )
00881          {
00882             delete si;
00883             gdcmErrorMacro( "Add SerieToEnd failed");
00884          }
00885          break;
00886       case GDCM_DICOMDIR_STUDY:
00887          elemList = Global::GetDicomDirElements()->GetDicomDirStudyElements();
00888          si = new DicomDirStudy(true);
00889          if( !AddStudyToEnd(static_cast<DicomDirStudy *>(si)) )
00890          {
00891             delete si;
00892             gdcmErrorMacro( "Add StudyToEnd failed");
00893          }
00894          break;
00895       case GDCM_DICOMDIR_PATIENT:
00896          elemList = Global::GetDicomDirElements()->GetDicomDirPatientElements();
00897          si = new DicomDirPatient(true);
00898          if( !AddPatientToEnd(static_cast<DicomDirPatient *>(si)) )
00899          {
00900             delete si;
00901             gdcmErrorMacro( "Add PatientToEnd failed");
00902          }
00903          break;
00904       case GDCM_DICOMDIR_META:
00905          elemList = Global::GetDicomDirElements()->GetDicomDirMetaElements();
00906          si = new DicomDirMeta(true);
00907          if( MetaElems )
00908          {
00909             delete MetaElems;
00910             gdcmErrorMacro( "MetaElements already exist, they will be destroyed");
00911          }
00912          MetaElems = static_cast<DicomDirMeta *>(si);
00913          break;
00914       default:
00915          return;
00916    }
00917    // removed all the seems-to-be-useless stuff about Referenced Image Sequence
00918    // to avoid further troubles
00919    // imageElem 0008 1140 "" // Referenced Image Sequence
00920    // imageElem fffe e000 "" // 'no length' item : length to be set to 0xffffffff later
00921    // imageElem 0008 1150 "" // Referenced SOP Class UID    : to be set/forged later
00922    // imageElem 0008 1155 "" // Referenced SOP Instance UID : to be set/forged later
00923    // imageElem fffe e00d "" // Item delimitation : length to be set to ZERO later
00924  
00925    // FIXME : troubles found when it's a SeqEntry
00926 
00927    // for all the relevant elements found in their own spot of the DicomDir.dic
00928    for( it = elemList.begin(); it != elemList.end(); ++it)
00929    {
00930       tmpGr     = it->Group;
00931       tmpEl     = it->Elem;
00932       dictEntry = GetPubDict()->GetEntry(tmpGr, tmpEl);
00933 
00934       entry     = new ValEntry( dictEntry ); // Be sure it's never a BinEntry !
00935 
00936       entry->SetOffset(0); // just to avoid further missprinting
00937 
00938       if( header )
00939       {
00940          // NULL when we Build Up (ex nihilo) a DICOMDIR
00941          //   or when we add the META elems
00942          val = header->GetEntryValue(tmpGr, tmpEl);
00943       }
00944       else
00945       {
00946          val = GDCM_UNFOUND;
00947       }
00948 
00949       if( val == GDCM_UNFOUND) 
00950       {
00951          if( tmpGr == 0x0004 && tmpEl == 0x1130 ) // File-set ID
00952          {
00953            // force to the *end* File Name
00954            val = Util::GetName( path );
00955          }
00956          else if( tmpGr == 0x0004 && tmpEl == 0x1500 ) // Only used for image
00957          {
00958             if( header->GetFileName().substr(0, path.length()) != path )
00959             {
00960                gdcmWarningMacro( "The base path of file name is incorrect");
00961                val = header->GetFileName();
00962             }
00963             else
00964             {
00965                val = &(header->GetFileName().c_str()[path.length()]);
00966             }
00967          }
00968          else
00969          {
00970             val = it->Value;
00971          }
00972       }
00973       else
00974       {
00975          if ( header->GetEntryLength(tmpGr,tmpEl) == 0 )
00976             val = it->Value;
00977       }
00978 
00979       entry->SetValue( val ); // troubles expected when vr=SQ ...
00980 
00981       if ( type == GDCM_DICOMDIR_META ) // fusible : should never print !
00982       {
00983          gdcmWarningMacro("GDCM_DICOMDIR_META ?!? should never print that");
00984       }
00985       si->AddEntry(entry);
00986    }
00987 }

void gdcm::DicomDir::SetElements std::string const &  path,
VectDocument const &  list
[private]
 

for each Header of the chained list, add/update the Patient/Study/Serie/Image info

Parameters:
path path of the root directory
list chained list of Headers

Definition at line 786 of file gdcmDicomDir.cxx.

References gdcm::ElementSet::ClearEntry(), ClearPatient(), GDCM_DICOMDIR_IMAGE, GDCM_DICOMDIR_PATIENT, GDCM_DICOMDIR_SERIE, GDCM_DICOMDIR_STUDY, SetElement(), and gdcm::VectDocument.

Referenced by CreateDicomDirChainedList().

00787 {
00788    ClearEntry();
00789    ClearPatient();
00790 
00791    std::string patPrevName         = "", patPrevID  = "";
00792    std::string studPrevInstanceUID = "", studPrevID = "";
00793    std::string serPrevInstanceUID  = "", serPrevID  = "";
00794 
00795    std::string patCurName,         patCurID;
00796    std::string studCurInstanceUID, studCurID;
00797    std::string serCurInstanceUID,  serCurID;
00798 
00799    bool first = true;
00800    for( VectDocument::const_iterator it = list.begin();
00801                                      it != list.end(); 
00802                                    ++it )
00803    {
00804       // get the current file characteristics
00805       patCurName         = (*it)->GetEntryValue(0x0010,0x0010);
00806       patCurID           = (*it)->GetEntryValue(0x0010,0x0011);
00807       studCurInstanceUID = (*it)->GetEntryValue(0x0020,0x000d);
00808       studCurID          = (*it)->GetEntryValue(0x0020,0x0010);
00809       serCurInstanceUID  = (*it)->GetEntryValue(0x0020,0x000e);
00810       serCurID           = (*it)->GetEntryValue(0x0020,0x0011);
00811 
00812       if( patCurName != patPrevName || patCurID != patPrevID || first )
00813       {
00814          SetElement(path, GDCM_DICOMDIR_PATIENT, *it);
00815          first = true;
00816       }
00817 
00818       // if new Study Deal with 'STUDY' Elements   
00819       if( studCurInstanceUID != studPrevInstanceUID || studCurID != studPrevID 
00820          || first )
00821       {
00822          SetElement(path, GDCM_DICOMDIR_STUDY, *it);
00823          first = true;
00824       }
00825 
00826       // if new Serie Deal with 'SERIE' Elements   
00827       if( serCurInstanceUID != serPrevInstanceUID || serCurID != serPrevID
00828          || first )
00829       {
00830          SetElement(path, GDCM_DICOMDIR_SERIE, *it);
00831          first = true;
00832       }
00833       
00834       // Always Deal with 'IMAGE' Elements  
00835       SetElement(path, GDCM_DICOMDIR_IMAGE, *it);
00836 
00837       patPrevName         = patCurName;
00838       patPrevID           = patCurID;
00839       studPrevInstanceUID = studCurInstanceUID;
00840       studPrevID          = studCurID;
00841       serPrevInstanceUID  = serCurInstanceUID;
00842       serPrevID           = serCurID;
00843       first = false;
00844    }
00845 }

void gdcm::DicomDir::SetEndMethod DicomDir::Method method,
void *  arg = NULL,
DicomDir::Method argDelete = NULL
 

Set the end method to call when the parsing of the directory ends.

Parameters:
method Method to call
arg Argument to pass to the method
argDelete Argument
Warning:
In python : the arg parameter isn't considered

Definition at line 380 of file gdcmDicomDir.cxx.

References EndArg, EndMethod, EndMethodArgDelete, and Method.

Referenced by ~DicomDir().

00382 {
00383    if( EndArg && EndMethodArgDelete )
00384    {
00385       EndMethodArgDelete( EndArg );
00386    }
00387 
00388    EndMethod          = method;
00389    EndArg             = arg;
00390    EndMethodArgDelete = argDelete;
00391 }

void gdcm::DicomDir::SetEndMethodArgDelete DicomDir::Method method  ) 
 

Set the method to delete the argument The argument is destroyed when the method is changed or when the class is destroyed.

Parameters:
method Method to call to delete the argument

Definition at line 421 of file gdcmDicomDir.cxx.

References EndMethodArgDelete, and Method.

00422 {
00423    EndMethodArgDelete = method;
00424 }

void gdcm::Document::SetFileName std::string const &  fileName  )  [inline, inherited]
 

Accessor to Filename.

Definition at line 81 of file gdcmDocument.h.

Referenced by DicomDir().

00081 { Filename = fileName; }

void gdcm::Base::SetPrintLevel int  level  )  [inline, inherited]
 

Sets the print level for the Dicom Header Elements.

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

Definition at line 45 of file gdcmBase.h.

Referenced by gdcm::SQItem::Print(), gdcm::SeqEntry::Print(), gdcm::FileHelper::Print(), gdcm::ElementSet::Print(), and Print().

00045 { PrintLevel = level; };

void gdcm::DicomDir::SetProgressMethod DicomDir::Method method,
void *  arg = NULL,
DicomDir::Method argDelete = NULL
 

Set the progress method to call when the parsing of the directory progress.

Parameters:
method Method to call
arg Argument to pass to the method
argDelete Argument
Warning:
In python : the arg parameter isn't considered

Definition at line 360 of file gdcmDicomDir.cxx.

References Method, ProgressArg, ProgressMethod, and ProgressMethodArgDelete.

Referenced by ~DicomDir().

00362 {
00363    if( ProgressArg && ProgressMethodArgDelete )
00364    {
00365       ProgressMethodArgDelete( ProgressArg );
00366    }
00367 
00368    ProgressMethod          = method;
00369    ProgressArg             = arg;
00370    ProgressMethodArgDelete = argDelete;
00371 }

void gdcm::DicomDir::SetProgressMethodArgDelete DicomDir::Method method  ) 
 

Set the method to delete the argument The argument is destroyed when the method is changed or when the class is destroyed.

Parameters:
method Method to call to delete the argument

Definition at line 410 of file gdcmDicomDir.cxx.

References Method, and ProgressMethodArgDelete.

00411 {
00412    ProgressMethodArgDelete = method;
00413 }

bool gdcm::Document::SetShaDict DictKey const &  dictName  )  [inherited]
 

Set the shadow dictionary used.

Parameters:
dictName name of the dictionary to use in shadow

Definition at line 210 of file gdcmDocument.cxx.

References gdcm::DictKey, and gdcm::Document::RefShaDict.

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

bool gdcm::Document::SetShaDict Dict dict  )  [inherited]
 

Set the shadow dictionary used.

Parameters:
dict dictionary to use in shadow

Definition at line 200 of file gdcmDocument.cxx.

References gdcm::Document::RefShaDict.

00201 {
00202    RefShaDict = dict;
00203    return !RefShaDict;
00204 }

void gdcm::DicomDir::SetStartMethod DicomDir::Method method,
void *  arg = NULL,
DicomDir::Method argDelete = NULL
 

Set the start method to call when the parsing of the directory starts.

Parameters:
method Method to call
arg Argument to pass to the method
argDelete Argument
Warning:
In python : the arg parameter isn't considered

Definition at line 339 of file gdcmDicomDir.cxx.

References Method, StartArg, StartMethod, and StartMethodArgDelete.

Referenced by ~DicomDir().

00341 {
00342    if( StartArg && StartMethodArgDelete )
00343    {
00344       StartMethodArgDelete( StartArg );
00345    }
00346 
00347    StartMethod          = method;
00348    StartArg             = arg;
00349    StartMethodArgDelete = argDelete;
00350 }

void gdcm::DicomDir::SetStartMethodArgDelete DicomDir::Method method  ) 
 

Set the method to delete the argument The argument is destroyed when the method is changed or when the class is destroyed.

Parameters:
method Method to call to delete the argument

Definition at line 399 of file gdcmDicomDir.cxx.

References Method, and StartMethodArgDelete.

00400 {
00401    StartMethodArgDelete = method;
00402 }

bool gdcm::DocEntrySet::SetValEntry std::string const &  content,
ValEntry entry
[inherited]
 

Accesses an existing DocEntry (i.e. a Dicom Element) and modifies it's content with the given value.

Parameters:
content new value (string) to substitute with
entry Entry to be modified

Definition at line 211 of file gdcmDocEntrySet.cxx.

References gdcm::ValEntry::SetValue().

00212 {
00213    if(entry)
00214    {
00215       entry->SetValue(content);
00216       return true;
00217    }
00218    return false;
00219 }

bool gdcm::DocEntrySet::SetValEntry std::string const &  content,
uint16_t  group,
uint16_t  elem
[inherited]
 

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

Parameters:
content new value (string) to substitute with
group group number of the Dicom Element to modify
elem element number of the Dicom Element to modify

Definition at line 169 of file gdcmDocEntrySet.cxx.

References gdcmWarningMacro, and gdcm::DocEntrySet::GetValEntry().

Referenced by gdcm::File::AnonymizeFile(), gdcm::Document::Document(), gdcm::DocEntrySet::InsertValEntry(), gdcm::FileHelper::SetValEntry(), and gdcm::File::Write().

00171 {
00172    ValEntry *entry = GetValEntry(group, elem);
00173    if (!entry )
00174    {
00175       gdcmWarningMacro( "No corresponding ValEntry " << std::hex << group <<
00176                          "," << elem << " element (try promotion first).");
00177       return false;
00178    }
00179    return SetValEntry(content,entry);
00180 }

void gdcm::Document::SkipBytes uint32_t  nBytes  )  [protected, inherited]
 

skips bytes inside the source file

Warning:
NOT end user intended method !
Returns:

Definition at line 707 of file gdcmDocument.cxx.

References gdcm::Document::Fp.

Referenced by gdcm::File::ComputeJPEGFragmentInfo(), gdcm::File::ComputeRLEInfo(), and gdcm::Document::SkipDocEntry().

00708 {
00709    //FIXME don't dump the returned value
00710    Fp->seekg((long)nBytes, std::ios::cur);
00711 }

uint32_t gdcm::Document::SwapLong uint32_t  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 365 of file gdcmDocument.cxx.

References gdcmErrorMacro, and gdcm::Document::SwapCode.

Referenced by gdcm::Document::GetDocEntryValue().

00366 {
00367    switch (SwapCode)
00368    {
00369       case 1234 :
00370          break;
00371       case 4321 :
00372          a=( ((a<<24) & 0xff000000) | ((a<<8)  & 0x00ff0000) | 
00373              ((a>>8)  & 0x0000ff00) | ((a>>24) & 0x000000ff) );
00374          break;   
00375       case 3412 :
00376          a=( ((a<<16) & 0xffff0000) | ((a>>16) & 0x0000ffff) );
00377          break;  
00378       case 2143 :
00379          a=( ((a<< 8) & 0xff00ff00) | ((a>>8) & 0x00ff00ff)  );
00380       break;
00381       default :
00382          gdcmErrorMacro( "Unset swap code:" << SwapCode );
00383          a = 0;
00384    }
00385    return a;
00386 } 

uint16_t gdcm::Document::SwapShort uint16_t  a  )  [inherited]
 

Swaps the bytes so they agree with the processor order.

Returns:
The properly swaped 16 bits integer.

Definition at line 351 of file gdcmDocument.cxx.

References gdcm::Document::SwapCode.

Referenced by gdcm::Document::GetDocEntryValue(), and gdcm::Document::HandleOutOfGroup0002().

00352 {
00353    if ( SwapCode == 4321 || SwapCode == 2143 )
00354    {
00355       a = ((( a << 8 ) & 0xff00 ) | (( a >> 8 ) & 0x00ff ) );
00356    }
00357    return a;
00358 }

uint32_t gdcm::Document::UnswapLong uint32_t  a  )  [inline, inherited]
 

Unswaps back the bytes of 4-byte long integer so they agree with the processor order.

Definition at line 75 of file gdcmDocument.h.

00075 { return SwapLong(a);}

uint16_t gdcm::Document::UnswapShort uint16_t  a  )  [inline, inherited]
 

Unswaps back the bytes of 2-bytes long integer so they agree with the processor order.

Definition at line 72 of file gdcmDocument.h.

00072 { return SwapShort(a);}

void gdcm::Document::WriteContent std::ofstream *  fp,
FileType  filetype
[virtual, inherited]
 

Writes in a file all the Header Entries (Dicom Elements).

Parameters:
fp file pointer on an already open file (actually: Output File Stream)
filetype Type of the File to be written (ACR-NEMA, ExplicitVR, ImplicitVR)
Returns:
Always true.

Reimplemented from gdcm::ElementSet.

Definition at line 482 of file gdcmDocument.cxx.

References gdcm::ExplicitVR, and gdcm::ImplicitVR.

00483 {
00484    // \TODO move the following lines (and a lot of others, to be written)
00485    // to a future function CheckAndCorrectHeader  
00486 
00487    // (necessary if user wants to write a DICOM V3 file
00488    // starting from an ACR-NEMA (V2) Header
00489 
00490    if ( filetype == ImplicitVR || filetype == ExplicitVR )
00491    {
00492       // writing Dicom File Preamble
00493       char filePreamble[128];
00494       memset(filePreamble, 0, 128);
00495       fp->write(filePreamble, 128);
00496       fp->write("DICM", 4);
00497    }
00498 
00499    /*
00500     * \todo rewrite later, if really usefull
00501     *       - 'Group Length' element is optional in DICOM
00502     *       - but un-updated odd groups lengthes can causes pb
00503     *         (xmedcon breaker)
00504     *
00505     * if ( (filetype == ImplicitVR) || (filetype == ExplicitVR) )
00506     *    UpdateGroupLength(false,filetype);
00507     * if ( filetype == ACR)
00508     *    UpdateGroupLength(true,ACR);
00509     */
00510 
00511    ElementSet::WriteContent(fp, filetype); // This one is recursive
00512 }

bool gdcm::DicomDir::WriteDicomDir std::string const &  fileName  ) 
 

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

Todo:
: to be re-written using the DICOMDIR tree-like structure *not* the chained list (does NOT exist if the DICOMDIR is user-forged !)
Parameters:
fileName file to be written to
Returns:
false only when fail to open

Definition at line 437 of file gdcmDicomDir.cxx.

References gdcm::binary_write(), gdcm::ExplicitVR, gdcmWarningMacro, GetMeta(), Patients, and gdcm::DicomDirMeta::WriteContent().

00438 {  
00439    int i;
00440    uint16_t sq[4] = { 0x0004, 0x1220, 0xffff, 0xffff };
00441    uint16_t sqt[4]= { 0xfffe, 0xe0dd, 0xffff, 0xffff };
00442 
00443    std::ofstream *fp = new std::ofstream(fileName.c_str(),  
00444                                          std::ios::out | std::ios::binary);
00445    if( !fp ) 
00446    {
00447       gdcmWarningMacro("Failed to open(write) File: " << fileName.c_str());
00448       return false;
00449    }
00450 
00451    char filePreamble[128];
00452    memset(filePreamble, 0, 128);
00453    fp->write(filePreamble, 128); //FIXME
00454    binary_write( *fp, "DICM");
00455  
00456    DicomDirMeta *ptrMeta = GetMeta();
00457    ptrMeta->WriteContent(fp, ExplicitVR);
00458    
00459    // force writing 0004|1220 [SQ ], that CANNOT exist within DicomDirMeta
00460    for(i=0;i<4;++i)
00461    {
00462       binary_write(*fp, sq[i]);
00463    }
00464         
00465    for(ListDicomDirPatient::iterator cc  = Patients.begin();
00466                                      cc != Patients.end();
00467                                    ++cc )
00468    {
00469       (*cc)->WriteContent( fp, ExplicitVR );
00470    }
00471    
00472    // force writing Sequence Delimitation Item
00473    for(i=0;i<4;++i)
00474    {
00475       binary_write(*fp, sqt[i]);  // fffe e0dd ffff ffff 
00476    }
00477 
00478    fp->close();
00479    delete fp;
00480 
00481    return true;
00482 }


Member Data Documentation

bool gdcm::DicomDir::Abort [private]
 

value of the ??? for any progress bar

Definition at line 168 of file gdcmDicomDir.h.

Referenced by CallStartMethod(), CreateDicomDirChainedList(), and Initialize().

ListElements gdcm::Document::AnonymizeList [protected, inherited]
 

List of element to Anonymize.

Definition at line 150 of file gdcmDocument.h.

void* gdcm::DicomDir::EndArg [private]
 

pointer to the ??? for any progress bar

Definition at line 164 of file gdcmDicomDir.h.

Referenced by CallEndMethod(), Initialize(), and SetEndMethod().

Method* gdcm::DicomDir::EndMethod [private]
 

pointer to the termination method for any progress bar

Definition at line 152 of file gdcmDicomDir.h.

Referenced by CallEndMethod(), Initialize(), and SetEndMethod().

Method* gdcm::DicomDir::EndMethodArgDelete [private]
 

pointer to the ??? method for any progress bar

Definition at line 158 of file gdcmDicomDir.h.

Referenced by Initialize(), SetEndMethod(), and SetEndMethodArgDelete().

std::string gdcm::Document::Filename [protected, inherited]
 

Refering underlying filename.

Definition at line 112 of file gdcmDocument.h.

FileType gdcm::Document::Filetype [protected, inherited]
 

ACR, ACR_LIBIDO, ExplicitVR, ImplicitVR, Unknown.

Definition at line 138 of file gdcmDocument.h.

Referenced by gdcm::Document::CheckSwap(), gdcm::Document::Document(), gdcm::Document::FindDocEntryVR(), gdcm::Document::GetFileType(), gdcm::Document::HandleOutOfGroup0002(), gdcm::Document::Initialize(), gdcm::Document::IsReadable(), gdcm::Document::ParseDES(), and gdcm::Document::ReadNextDocEntry().

std::ifstream* gdcm::Document::Fp [protected, inherited]
 

File Pointer, opened during Document parsing.

Definition at line 135 of file gdcmDocument.h.

Referenced by gdcm::Document::CheckSwap(), gdcm::Document::CloseFile(), gdcm::Document::Document(), gdcm::Document::FindDocEntryVR(), gdcm::Document::IsDocEntryAnInteger(), gdcm::Document::LoadDocEntry(), gdcm::Document::LoadDocEntrySafe(), gdcm::Document::LoadEntryBinArea(), gdcm::Document::OpenFile(), gdcm::Document::ParseDES(), gdcm::Document::ParseSQ(), gdcm::Document::ReadNextDocEntry(), gdcm::Document::SkipBytes(), and gdcm::Document::SkipToNextDocEntry().

bool gdcm::Document::Group0002Parsed [protected, inherited]
 

whether we already parsed group 0002 (Meta Elements)

Definition at line 129 of file gdcmDocument.h.

Referenced by gdcm::Document::Document(), and gdcm::Document::HandleOutOfGroup0002().

bool gdcm::Document::HasDCMPreamble [protected, inherited]
 

whether file has a DCM Preamble

Definition at line 132 of file gdcmDocument.h.

Referenced by gdcm::Document::OpenFile(), and gdcm::Document::ReadNextDocEntry().

const unsigned int gdcm::Document::HEADER_LENGTH_TO_READ [static, protected, inherited]
 

After opening the file, we read HEADER_LENGTH_TO_READ bytes.

Definition at line 141 of file gdcmDocument.h.

ListDicomDirPatient::iterator gdcm::DicomDir::ItPatient [private]
 

Definition at line 145 of file gdcmDicomDir.h.

Referenced by GetFirstPatient(), and GetNextPatient().

const unsigned int gdcm::Document::MAX_SIZE_LOAD_ELEMENT_VALUE = 0xfff [static, protected, inherited]
 

Elements whose value is longer than MAX_SIZE_LOAD_ELEMENT_VALUE are NOT loaded.

Definition at line 51 of file gdcmDocument.cxx.

Referenced by gdcm::Document::Document().

const unsigned int gdcm::Document::MAX_SIZE_PRINT_ELEMENT_VALUE = 0x7fffffff [static, protected, inherited]
 

Elements whose value is longer than MAX_SIZE_PRINT_ELEMENT_VALUE are NOT printed.

Definition at line 52 of file gdcmDocument.cxx.

DicomDirMeta* gdcm::DicomDir::MetaElems [private]
 

Pointer on *the* DicomDirObject 'DicomDirMeta Elements'.

Definition at line 141 of file gdcmDicomDir.h.

Referenced by Initialize(), IsReadable(), NewMeta(), Print(), SetElement(), and ~DicomDir().

ListDicomDirPatient gdcm::DicomDir::Patients [private]
 

Chained list of DicomDirPatient (to be exploited hierarchicaly).

Definition at line 144 of file gdcmDicomDir.h.

Referenced by AddImageToEnd(), AddPatientToEnd(), AddSerieToEnd(), AddStudyToEnd(), ClearPatient(), GetFirstPatient(), GetNextPatient(), IsReadable(), Print(), and WriteDicomDir().

int gdcm::Base::PrintLevel [protected, inherited]
 

Amount of printed details for each Dicom Entries : 0 : stands for the least detail level.

Definition at line 53 of file gdcmBase.h.

Referenced by gdcm::Base::Base().

float gdcm::DicomDir::Progress [private]
 

value of the ??? for any progress bar

Definition at line 166 of file gdcmDicomDir.h.

Referenced by CallEndMethod(), CallStartMethod(), CreateDicomDirChainedList(), and Initialize().

void* gdcm::DicomDir::ProgressArg [private]
 

pointer to the ??? for any progress bar

Definition at line 162 of file gdcmDicomDir.h.

Referenced by CallProgressMethod(), Initialize(), and SetProgressMethod().

Method* gdcm::DicomDir::ProgressMethod [private]
 

pointer to the incrementation method for any progress bar

Definition at line 150 of file gdcmDicomDir.h.

Referenced by CallProgressMethod(), Initialize(), and SetProgressMethod().

Method* gdcm::DicomDir::ProgressMethodArgDelete [private]
 

pointer to the ??? method for any progress bar

Definition at line 156 of file gdcmDicomDir.h.

Referenced by Initialize(), SetProgressMethod(), and SetProgressMethodArgDelete().

void* gdcm::DicomDir::StartArg [private]
 

pointer to the ??? for any progress bar

Definition at line 160 of file gdcmDicomDir.h.

Referenced by CallStartMethod(), Initialize(), and SetStartMethod().

Method* gdcm::DicomDir::StartMethod [private]
 

pointer to the initialisation method for any progress bar

Definition at line 148 of file gdcmDicomDir.h.

Referenced by CallStartMethod(), Initialize(), and SetStartMethod().

Method* gdcm::DicomDir::StartMethodArgDelete [private]
 

pointer to the ??? method for any progress bar

Definition at line 154 of file gdcmDicomDir.h.

Referenced by Initialize(), SetStartMethod(), and SetStartMethodArgDelete().

int gdcm::Document::SwapCode [protected, inherited]
 

Swap code gives an information on the byte order of a supposed to be an int32, as it's read on disc (depending on the image Transfer Syntax *and* on the processor endianess) as opposed as it should in memory to be dealt as an int32. For instance :

  • a 'Little Endian' image, read with a little endian processor will have a SwapCode= 1234 (the order is OK; nothing to do)
  • a 'Little Endian' image, read with a big endian procesor will have a SwapCode= 4321 (the order is wrong; int32 an int16 must be swapped) note : values 2143, 4321, 3412 remain for the ACR-NEMA time, and the well known 'Bad Big Endian' and 'Bad Little Endian' codes.

Definition at line 126 of file gdcmDocument.h.

Referenced by gdcm::Document::CheckSwap(), gdcm::Document::Document(), gdcm::Document::SwapLong(), gdcm::Document::SwapShort(), and gdcm::Document::SwitchByteSwapCode().


The documentation for this class was generated from the following files:
Generated on Thu Feb 10 22:18:06 2005 for gdcm by doxygen 1.3.6