// gdcmParser.cxx
//-----------------------------------------------------------------------------
-#include "gdcmParser.h"
-#include "gdcmUtil.h"
#include <errno.h>
+#include <vector>
// For nthos:
#ifdef _MSC_VER
#endif
# include <iomanip>
+#include "gdcmParser.h"
+#include "gdcmUtil.h"
+#include "gdcmDebug.h"
+
#define UI1_2_840_10008_1_2 "1.2.840.10008.1.2"
#define UI1_2_840_10008_1_2_1 "1.2.840.10008.1.2.1"
#define UI1_2_840_10008_1_2_2 "1.2.840.10008.1.2.2"
enableSequences=enable_sequences;
ignoreShadow =ignore_shadow;
- SetMaxSizeLoadEntry(MAX_SIZE_LOAD_ELEMENT_VALUE);
+ SetMaxSizeLoadEntry(MAX_SIZE_LOAD_ELEMENT_VALUE);
filename = inFilename;
Initialise();
/**
* \ingroup gdcmParser
- * \brief Prints The Dict Entries of THE shadow Dicom Dictionnry
+ * \brief Prints The Dict Entries of THE shadow Dicom Dictionnary
* @return
*/
void gdcmParser::PrintShaDict(std::ostream & os) {
SetEntryLengthByNumber(20, 0x0002, 0x0010);
}
-/* TODO : rewrite later
+/* TODO : rewrite later, if really usefull
if ( (type == ImplicitVR) || (type == ExplicitVR) )
UpdateGroupLength(false,type);
* \ingroup gdcmParser
* \brief Modifies the value of a given Header Entry (Dicom Element)
* if it exists; Creates it with the given value if it doesn't
+ * \warning : adds the Header Entry to the HTable, NOT to the chained List
* @param Value passed as a std::string
- * @param Group
- * @param Elem
- * \return false only if new element creation fails
+ * @param Group group of the Entry
+ * @param Elem element of the Entry
+ * \return pointer to the created Header Entry
+ * NULL if creation failed
*/
-bool gdcmParser::ReplaceOrCreateByNumber(std::string Value,
+gdcmHeaderEntry * gdcmParser::ReplaceOrCreateByNumber(
+ std::string Value,
guint16 Group,
- guint16 Elem ){
- if (CheckIfEntryExistByNumber(Group, Elem) == 0) {
+ guint16 Elem ){
+ gdcmHeaderEntry* a;
+ a = GetHeaderEntryByNumber( Group, Elem);
+ if (a == NULL) {
gdcmHeaderEntry *a =NewHeaderEntryByNumber(Group, Elem);
if (a == NULL)
- return false;
+ return NULL;
AddHeaderEntry(a);
}
- SetEntryByNumber(Value, Group, Elem);
- return(true);
+ //SetEntryByNumber(Value, Group, Elem);
+ a->SetValue(Value);
+ return(a);
}
/**
* @param Value passed as a char*
* @param Group group of the Entry
* @param Elem element of the Entry
- * \return boolean
+ * \return pointer to the created Header Entry
+ * NULL if creation failed
*
*/
-bool gdcmParser::ReplaceOrCreateByNumber(char* Value, guint16 Group, guint16 Elem ) {
+gdcmHeaderEntry * gdcmParser::ReplaceOrCreateByNumber(
+ char* Value,
+ guint16 Group,
+ guint16 Elem ) {
gdcmHeaderEntry* nvHeaderEntry=NewHeaderEntryByNumber(Group, Elem);
if(!nvHeaderEntry)
- return(false);
+ return(NULL);
AddHeaderEntry(nvHeaderEntry);
std::string v = Value;
SetEntryByNumber(v, Group, Elem);
- return(true);
+ return(nvHeaderEntry);
}
/**
/**
* \ingroup gdcmParser
* \brief Update the entries with the shadow dictionary.
- * Only non even entries are analyzed
+ * Only non even entries are analyzed
*/
void gdcmParser::UpdateShaEntries(void) {
gdcmDictEntry *entry;
// TODO (?) tester les echecs en ecriture (apres chaque fwrite)
int compte =0;
itsTimeToWritePixels = false;
-
- // === Deal with the length
- // --------------------
- if((tag->GetLength())%2==1)
- {
- tag->SetValue(tag->GetValue()+"\0");
- tag->SetLength(tag->GetReadLength()+1);
- }
gr = tag->GetGroup();
el = tag->GetElement();
val = tag->GetValue().c_str();
vr = tag->GetVR();
voidArea = tag->GetVoidArea();
+
+ // === Deal with the length
+ // --------------------
+ if((tag->GetLength())%2==1)
+ {
+ tag->SetValue(tag->GetValue()+"\0");
+ tag->SetLength(tag->GetReadLength()+1);
+ }
if ( type == ACR )
{
guint16 z=0, shortLgr;
if (gr == 0xfffe) { // NO Value Representation for 'delimiters'
- // no length : write ffffffff
+ // no length : write ffffffff
+
+ // special patch to make some MR PHILIPS
+ if (el == 0x0000) return; // images e-film readable // see gdcmData/gdcm-MR-PHILIPS-16-Multi-Seq.dcm
+ // from Hospital Guy de Chauliac,
+ // Montpellier
+ // we just ignore spurious fffe|0000 tag !
+
fwrite (&ff,(size_t)4 ,(size_t)1 ,_fp);
return; // NO value for 'delimiters'
}
}
if( (vr == "UI") ) // Because of correspondance with the VR dic
- Entry->SetValue(NewValue.c_str()); // ??? JPR ???
+ Entry->SetValue(NewValue.c_str());
else
Entry->SetValue(NewValue);
}
}
// a SeQuence Element is beginning
- // Let's forget it's length
- // (we want to 'go inside')
-
- // Pb : *normaly* fffe|e000 is just a marker, its length *should be* zero
- // in gdcm-MR-PHILIPS-16-Multi-Seq.dcm we find lengthes as big as 28800
- // if we set the length to zero IsHeaderEntryAnInteger() breaks...
- // if we don't, we lost 28800 characters from the Header :-(
-
+ // fffe|e000 is just a marker, its length *should be* zero
else if(Entry->GetGroup() == 0xfffe)
{
- // cout << "ReadLength " <<Entry->GetReadLength() << " UsableLength " << FoundLength << endl;
- // Entry->Print();
- // sometimes, length seems to be wrong
- FoundLength =0; // some more clever checking to be done !
- // I give up!
- // only gdcm-MR-PHILIPS-16-Multi-Seq.dcm
- // causes troubles :-(
- }
-
+ // *normally, fffe|0000 doesn't exist !
+ if( Entry->GetElement() != 0x0000 ) // gdcm-MR-PHILIPS-16-Multi-Seq.dcm
+ // causes extra troubles :-(
+ FoundLength =0;
+ }
Entry->SetUsableLength(FoundLength);
}
return 0;
TotalLength += 4; // We even have to decount the group and element
- if ( g != 0xfffe && g!=0xb00c ) /*for bogus header */
+ if ( g != 0xfffe && g!=0xb00c ) //for bogus header
{
char msg[100]; // for sprintf. Sorry
sprintf(msg,"wrong group (%04x) for an item sequence (%04x,%04x)\n",g, g,n);
errno = 1;
return 0;
}
- if ( n == 0xe0dd || ( g==0xb00c && n==0x0eb6 ) ) /* for bogus header */
+ if ( n == 0xe0dd || ( g==0xb00c && n==0x0eb6 ) ) // for bogus header
FoundSequenceDelimiter = true;
else if ( n != 0xe000 )
{
// header parsing has to be considered as finished.
return (gdcmHeaderEntry *)0;
-/* Pb : how to propagate the element length (used in SkipHeaderEntry)
+// Pb : how to propagate the element length (used in SkipHeaderEntry)
// direct call to SkipBytes ?
- if (ignoreShadow == 1 && g%2 ==1) //JPR
+// if (ignoreShadow == 1 && g%2 ==1)
// if user wants to skip shadow groups
// and current element *is* a shadow element
// we don't create anything
- return (gdcmHeaderEntry *)1; // to tell caller it's NOT finished
-*/
+// return (gdcmHeaderEntry *)1; // to tell caller it's NOT finished
+
NewEntry = NewHeaderEntryByNumber(g, n);
FindHeaderEntryVR(NewEntry);
FindHeaderEntryLength(NewEntry);