// Here we load a gdcmFile and then try to create from scratch a copy of it,
// copying field by field the dicom image
-int TestCopyDicom(int , char* [])
+int TestCopyDicom(int argc, char* argv[])
{
int i =0;
int retVal = 0; //by default this is an error
// It was commented out by Mathieu, that was a *good* idea
// (the user does NOT have to know the way we implemented the Header !)
// Waiting for a 'clean' solution, I keep the method ...JPRx
-
- TagNameHT & nameHt = original->GetHeader()->GetPubDict()->GetEntriesByName();
- (void)nameHt; //not used ?
- //gdcmValEntry* v;
- //gdcmBinEntry* b;
gdcmDocEntry* d;
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 )
- // 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->GetLength(),
b->GetGroup(),
- b->GetElement() );
+ b->GetElement(),
+ b->GetVR() );
}
else if ( gdcmValEntry* v = dynamic_cast<gdcmValEntry*>(d) )
- {
- if ( d->GetGroup()%2 != 1)
- {
- copy->GetHeader()->ReplaceOrCreateByNumber(
- v->GetValue(),
- v->GetGroup(),
- v->GetElement() );
- }
- else
- {
- copy->GetHeader()->ReplaceOrCreateByNumber(
+ {
+ copy->GetHeader()->ReplaceOrCreateByNumber(
v->GetValue(),
v->GetGroup(),
v->GetElement(),
v->GetVR() );
- }
- }
- else
- {
+ }
+ else
+ {
// We skip pb of SQ recursive exploration
//std::cout << "Skipped Sequence "
// << "------------- " << d->GetVR() << " "<< std::hex
// << d->GetGroup() << " " << d->GetElement()
// << std::endl;
- }
+ }
}
size_t dataSize = original->GetImageDataSize();
Program: gdcm
Module: $RCSfile: gdcmDocument.cxx,v $
Language: C++
- Date: $Date: 2004/09/15 03:50:48 $
- Version: $Revision: 1.78 $
+ Date: $Date: 2004/09/16 06:48:00 $
+ Version: $Revision: 1.79 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
* \return pointer to the modified/created Header Entry (NULL when creation
* failed).
*/
-
+
+/*
gdcmValEntry * gdcmDocument::ReplaceOrCreateByNumber(
std::string const & value,
uint16_t group,
return valEntry;
}
+*/
/**
* \brief Modifies the value of a given Header Entry (Dicom Element)
void *voidArea,
int lgth,
uint16_t group,
- uint16_t elem)
+ uint16_t elem,
+ std::string const & VR )
{
- gdcmBinEntry* b = 0;
- gdcmDocEntry* a = GetDocEntryByNumber( group, elem);
- if (!a)
+ gdcmBinEntry* binEntry = 0;
+ gdcmDocEntry* currentEntry = GetDocEntryByNumber( group, elem);
+ if (!currentEntry)
{
- a = NewBinEntryByNumber(group, elem);
- if (!a)
+
+ // 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)
{
- return 0;
+ currentEntry = NewDocEntryByNumber(group, elem,VR);
}
-
- b = new gdcmBinEntry(a);
- AddEntry(b);
- b->SetVoidArea(voidArea);
- }
+ else
+ {
+ currentEntry = NewDocEntryByNumber(group, elem);
+ }
+ if (!currentEntry)
+ {
+ dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: call to"
+ " NewDocEntryByNumber failed.");
+ return NULL;
+ }
+ binEntry = new gdcmBinEntry(currentEntry);
+ if ( !AddEntry(binEntry))
+ {
+ dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: AddEntry"
+ " failed allthough this is a creation.");
+ }
+ }
+ else
+ {
+ binEntry = dynamic_cast< gdcmBinEntry* >(currentEntry);
+ if ( !binEntry ) // Euuuuh? It wasn't a BinEntry
+ // then we change it to a BinEntry ?
+ // Shouldn't it be considered as an error ?
+ {
+ // We need to promote the gdcmDocEntry to a gdcmBinEntry:
+ binEntry = new gdcmBinEntry(currentEntry);
+ if (!RemoveEntry(currentEntry))
+ {
+ dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: removal"
+ " of previous DocEntry failed.");
+ return NULL;
+ }
+ if ( !AddEntry(binEntry))
+ {
+ dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: adding"
+ " promoted BinEntry failed.");
+ return NULL;
+ }
+ }
+ }
SetEntryByNumber(voidArea, lgth, group, elem);
- return b;
+ return binEntry;
}
Program: gdcm
Module: $RCSfile: gdcmDocument.h,v $
Language: C++
- Date: $Date: 2004/09/14 16:47:08 $
- Version: $Revision: 1.36 $
+ Date: $Date: 2004/09/16 06:48:00 $
+ Version: $Revision: 1.37 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
void Write(FILE* fp, FileType type);
- 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);
+ std::string const & VR ="unkn");
gdcmBinEntry* ReplaceOrCreateByNumber(void *voidArea, int lgth,
- uint16_t group, uint16_t elem);
+ uint16_t group, uint16_t elem,
+ std::string const & VR="unkn");
gdcmSeqEntry* ReplaceOrCreateByNumber(uint16_t group, uint16_t elem);