for (TagDocEntryHT::iterator tag = Ht.begin(); tag != Ht.end(); ++tag)
{
d = tag->second;
+
+ if ( gdcmBinEntry* b = dynamic_cast<gdcmBinEntry*>(d) )
+ {
// for private elements, the gdcmDictEntry is unknown
// and it's VR is unpredictable ...
// ( In *this* case ReplaceOrCreateByNumber
// should have a knowledge of the virtual dictionary
- // gdcmDictSet::VirtualEntry)
-
- if ( d->GetGroup()%2 == 1) // Skip private Entries
- continue;
-
- if ( gdcmBinEntry* b = dynamic_cast<gdcmBinEntry*>(d) )
- {
-
- // std::cout << "BinEntry : "
- // << "------------- " << b->GetVR() << " "<< std::hex
- // << b->GetGroup() << " " << b->GetElement() << " "
- // << " lg=" << b->GetLength()
- // << std::endl;
+ // gdcmDictSet::VirtualEntry )
+ // ReplaceOrCreateByNumber may now receive the VR of the source Entry
+ // as a extra parameter
+ //
+ //if ( d->GetGroup()%2 == 1) // Skip private Entries
+ // continue;
+
+ // TODO :write ReplaceOrCreateByNumber with VR,
+ // for BinEntries as well!
copy->GetHeader()->ReplaceOrCreateByNumber(
b->GetVoidArea(),
b->GetGroup(),
b->GetElement() );
}
- else if ( gdcmValEntry* v = dynamic_cast<gdcmValEntry*>(d) )
+ else if ( gdcmValEntry* v = dynamic_cast<gdcmValEntry*>(d) )
{
- copy->GetHeader()->ReplaceOrCreateByNumber(
+ if ( d->GetGroup()%2 != 1)
+ {
+ copy->GetHeader()->ReplaceOrCreateByNumber(
v->GetValue(),
v->GetGroup(),
v->GetElement() );
+ }
+ else
+ {
+ copy->GetHeader()->ReplaceOrCreateByNumber(
+ v->GetValue(),
+ v->GetGroup(),
+ v->GetElement(),
+ v->GetVR() );
+ }
}
else
{
Program: gdcm
Module: $RCSfile: gdcmDocEntrySet.cxx,v $
Language: C++
- Date: $Date: 2004/09/10 14:32:04 $
- Version: $Revision: 1.20 $
+ Date: $Date: 2004/09/14 16:47:08 $
+ Version: $Revision: 1.21 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
return newEntry;
}
+
+/** \brief
+ * Creates a new DocEntry (without any 'value' ...)
+ * @param group group number of the underlying DictEntry
+ * @param elem elem number of the underlying DictEntry
+ * @param VR V(alue) R(epresentation) of the Entry -if private Entry-
+
+ */
+gdcmDocEntry* gdcmDocEntrySet::NewDocEntryByNumber(uint16_t group,
+ uint16_t elem,
+ std::string const &VR)
+{
+ // Find out if the tag we encountered is in the dictionaries:
+ gdcmDict *pubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict();
+ gdcmDictEntry *dictEntry = pubDict->GetDictEntryByNumber(group, elem);
+ if (!dictEntry)
+ {
+ dictEntry = NewVirtualDictEntry(group, elem, VR);
+ }
+
+ gdcmDocEntry *newEntry = new gdcmDocEntry(dictEntry);
+ if (!newEntry)
+ {
+ dbg.Verbose(1, "gdcmSQItem::NewDocEntryByNumber",
+ "failed to allocate gdcmDocEntry");
+ return 0;
+ }
+ return newEntry;
+}
/* \brief
* Probabely move, as is, to gdcmDocEntrySet, as a non virtual method
* an remove gdcmDocument::NewDocEntryByName
Program: gdcm
Module: $RCSfile: gdcmDocEntrySet.h,v $
Language: C++
- Date: $Date: 2004/09/13 12:10:53 $
- Version: $Revision: 1.16 $
+ Date: $Date: 2004/09/14 16:47:08 $
+ Version: $Revision: 1.17 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
uint16_t element);
gdcmDocEntry* NewDocEntryByNumber(uint16_t group,
uint16_t element);
+ gdcmDocEntry* NewDocEntryByNumber(uint16_t group,
+ uint16_t element,
+ std::string const & VR);
gdcmDocEntry* NewDocEntryByName (std::string const & name);
gdcmSeqEntry* NewSeqEntryByNumber(uint16_t group,
uint16_t element);
Program: gdcm
Module: $RCSfile: gdcmDocument.cxx,v $
Language: C++
- Date: $Date: 2004/09/13 12:10:53 $
- Version: $Revision: 1.76 $
+ Date: $Date: 2004/09/14 16:47:08 $
+ Version: $Revision: 1.77 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
return valEntry;
}
+/**
+ * \brief Modifies the value of a given Header Entry (Dicom Element)
+ * when it exists. Create it with the given value when unexistant.
+ * @param value (string) Value to be set
+ * @param group Group number of the Entry
+ * @param elem Element number of the Entry
+ * @param VR V(alue) R(epresentation) of the Entry -if private Entry-
+ * \return pointer to the modified/created Header Entry (NULL when creation
+ * failed).
+ */
+
+ // TODO : write something clever, using default value for VR
+ // to avoid code duplication
+ // (I don't know how to tell NewDocEntryByNumber
+ // that ReplaceOrCreateByNumber was called with a default value)
+
+gdcmValEntry * gdcmDocument::ReplaceOrCreateByNumber(
+ std::string const & value,
+ uint16_t group,
+ uint16_t elem,
+ std::string const & VR )
+{
+ gdcmValEntry* valEntry = 0;
+ gdcmDocEntry* currentEntry = GetDocEntryByNumber( group, elem);
+
+ if (!currentEntry)
+ {
+ // check if (group,element) DictEntry exists
+ // if it doesn't, create an entry in gdcmDictSet::VirtualEntry
+ // and use it
+
+ // Find out if the tag we received is in the dictionaries:
+ gdcmDict *pubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict();
+ gdcmDictEntry *dictEntry = pubDict->GetDictEntryByNumber(group, elem);
+ if (!dictEntry)
+ {
+ currentEntry = NewDocEntryByNumber(group, elem,VR);
+ }
+ else
+ {
+ currentEntry = NewDocEntryByNumber(group, elem);
+ }
+
+ if (!currentEntry)
+ {
+ dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: call to"
+ " NewDocEntryByNumber failed.");
+ return NULL;
+ }
+ valEntry = new gdcmValEntry(currentEntry);
+ if ( !AddEntry(valEntry))
+ {
+ dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: AddEntry"
+ " failed allthough this is a creation.");
+ }
+ }
+ else
+ {
+ valEntry = dynamic_cast< gdcmValEntry* >(currentEntry);
+ if ( !valEntry ) // Euuuuh? It wasn't a ValEntry
+ // then we change it to a ValEntry ?
+ // Shouldn't it be considered as an error ?
+ {
+ // We need to promote the gdcmDocEntry to a gdcmValEntry:
+ valEntry = new gdcmValEntry(currentEntry);
+ if (!RemoveEntry(currentEntry))
+ {
+ dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: removal"
+ " of previous DocEntry failed.");
+ return NULL;
+ }
+ if ( !AddEntry(valEntry))
+ {
+ dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: adding"
+ " promoted ValEntry failed.");
+ return NULL;
+ }
+ }
+ }
+
+ SetEntryByNumber(value, group, elem);
+
+ return valEntry;
+}
+
/*
* \brief Modifies the value of a given Header Entry (Dicom Element)
* when it exists. Create it with the given value when unexistant.
}
SetEntryByNumber(voidArea, lgth, group, elem);
- //b->SetVoidArea(voidArea); //what if b == 0 !!
return b;
}
Program: gdcm
Module: $RCSfile: gdcmDocument.h,v $
Language: C++
- Date: $Date: 2004/09/03 15:11:35 $
- Version: $Revision: 1.35 $
+ Date: $Date: 2004/09/14 16:47:08 $
+ Version: $Revision: 1.36 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
gdcmValEntry* ReplaceOrCreateByNumber(std::string const & value,
uint16_t group, uint16_t elem);
+ gdcmValEntry* ReplaceOrCreateByNumber(std::string const & value,
+ uint16_t group, uint16_t elem,
+ std::string const & VR);
+
gdcmBinEntry* ReplaceOrCreateByNumber(void *voidArea, int lgth,
uint16_t group, uint16_t elem);
+
gdcmSeqEntry* ReplaceOrCreateByNumber(uint16_t group, uint16_t elem);
+
bool ReplaceIfExistByNumber ( std::string const & value,
uint16_t group,
uint16_t elem );
Program: gdcm
Module: $RCSfile: gdcmHeader.cxx,v $
Language: C++
- Date: $Date: 2004/09/10 18:54:39 $
- Version: $Revision: 1.185 $
+ Date: $Date: 2004/09/14 16:47:08 $
+ Version: $Revision: 1.186 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
*/
bool gdcmHeader::AnonymizeHeader()
{
- gdcmDocEntry* patientNameHE = GetDocEntryByNumber (0x0010, 0x0010);
+ // If exist, replace by spaces
+ SetEntryByNumber (" ",0x0010, 0x2154); // Telephone
+ SetEntryByNumber (" ",0x0010, 0x1040); // Adress
+ SetEntryByNumber (" ",0x0010, 0x0020); // Patient ID
- ReplaceIfExistByNumber (" ",0x0010, 0x2154); // Telephone
- ReplaceIfExistByNumber (" ",0x0010, 0x1040); // Adress
- ReplaceIfExistByNumber (" ",0x0010, 0x0020); // Patient ID
+ gdcmDocEntry* patientNameHE = GetDocEntryByNumber (0x0010, 0x0010);
- if ( patientNameHE )
+ if ( patientNameHE ) // we replace it by Study Instance UID (why not)
{
std::string studyInstanceUID = GetEntryByNumber (0x0020, 0x000d);
if ( studyInstanceUID != GDCM_UNFOUND )