* @param enable_sequences = true to allow the header
* to be parsed *inside* the SeQuences,
* when they have an actual length
+ * @param ignore_shadow = true if user wants to skip shadow groups
+ during parsing, to save memory space
*\TODO : may be we need one more bool,
* to allow skipping the private elements while parsing the header
* in order to save space
*/
gdcmHeader::gdcmHeader(const char *InFilename,
bool exception_on_error,
- bool enable_sequences ):
- gdcmParser(InFilename,exception_on_error,enable_sequences)
+ bool enable_sequences,
+ bool ignore_shadow):
+ gdcmParser(InFilename,exception_on_error,enable_sequences,ignore_shadow)
{
}
* @return true when gdcmParser is the one of a reasonable Dicom/Acr file,
* false otherwise.
*/
-bool gdcmHeader::IsReadable(void)
-{
+bool gdcmHeader::IsReadable(void) {
if(!gdcmParser::IsReadable())
return(false);
* 0 means the file is NOT USABLE. The caller will have to check
*/
int gdcmHeader::GetXSize(void) {
- // We cannot check for "Columns" because the "Columns" tag is present
- // both in IMG (0028,0011) and OLY (6000,0011) sections of the dictionary.
- std::string StrSize = GetEntryByNumber(0x0028,0x0011);
+ std::string StrSize;
+ StrSize = GetEntryByNumber(0x0028,0x0011);
if (StrSize == GDCM_UNFOUND)
return 0;
return atoi(StrSize.c_str());
* (The file contains a Signal, not an Image).
*/
int gdcmHeader::GetYSize(void) {
- // We cannot check for "Rows" because the "Rows" tag is present
- // both in IMG (0028,0010) and OLY (6000,0010) sections of the dictionary.
std::string StrSize = GetEntryByNumber(0x0028,0x0010);
if (StrSize != GDCM_UNFOUND)
return atoi(StrSize.c_str());
/**
* \ingroup gdcmHeader
- * \brief Recover the offset (from the beginning of the file) of the pixels.
+ * \brief Recover the offset (from the beginning of the file)
+ * \ of *image* pixels (not *icone* pixels, if any !)
*/
size_t gdcmHeader::GetPixelOffset(void) {
// If this file complies with the norm we should encounter the
// Inside the group pointed by "Image Location" the searched element
// is conventionally the element 0x0010 (when the norm is respected).
// When the "Image Location" is absent we default to group 0x7fe0.
+ // If the element (0x0088,0x0200) 'icone image sequence' is found
+ // (grPixel,numPixel) is stored twice : the first one for the icon
+ // the second one for the image ...
+ // pb : sometimes , (0x0088,0x0200) exists, but doesn't contain *anything*
+ // see gdcmData/MxTwinLossLess.dcm ...
guint16 grPixel;
guint16 numPixel;
std::string ImageLocation = GetEntryByNumber(0x0028, 0x0200);
if ( ImageLocation == GDCM_UNFOUND ) { // Image Location
- grPixel = 0x7fe0;
+ grPixel = 0x7fe0; // default value
} else {
grPixel = (guint16) atoi( ImageLocation.c_str() );
}
- if (grPixel != 0x7fe0)
+
+ if (grPixel == 0xe07f) // sometimes Image Location value doesn't follow
+ grPixel = 0x7fe0; // the supposed processor endianity.
+ // see gdcmData/cr172241.dcm
+
+ if (grPixel != 0x7fe0)
// This is a kludge for old dirty Philips imager.
numPixel = 0x1010;
else
numPixel = 0x0010;
-
- gdcmHeaderEntry* PixelElement = GetHeaderEntryByNumber(grPixel,numPixel);
- if (PixelElement)
+
+ IterHT it = GetHeaderEntrySameNumber(grPixel,numPixel);
+ //std::string icone = GetEntryByNumber(0x0088,0x0200); //icone image sequence
+ TagKey key = gdcmDictEntry::TranslateToKey(grPixel,numPixel);
+ gdcmHeaderEntry* PixelElement;
+
+ if (tagHT.count(key) == 1)
+ PixelElement = (it.first)->second;
+ else
+ PixelElement = (++it.first)->second;
+
+ if (PixelElement) {
return PixelElement->GetOffset();
+ }
else
return 0;
}
-
+// TODO : unify those two (previous one and next one)
/**
* \ingroup gdcmHeader
* \brief Recover the pixel area length (in Bytes)
guint16 grPixel;
guint16 numPixel;
std::string ImageLocation = GetEntryByNumber(0x0028, 0x0200);
- if ( ImageLocation == GDCM_UNFOUND ) {
- grPixel = 0x7fe0;
+ if ( ImageLocation == GDCM_UNFOUND ) { // Image Location
+ grPixel = 0x7fe0; // default value
} else {
grPixel = (guint16) atoi( ImageLocation.c_str() );
}
+ if (grPixel == 0xe07f) // sometimes group doesn't follow
+ grPixel = 0x7fe0; // the supposed processor endianity. see cr172241.dcm
+
if (grPixel != 0x7fe0)
// This is a kludge for old dirty Philips imager.
numPixel = 0x1010;
else
numPixel = 0x0010;
-
- gdcmHeaderEntry* PixelElement = GetHeaderEntryByNumber(grPixel,numPixel);
+
+ IterHT it = GetHeaderEntrySameNumber(grPixel,numPixel);
+ //std::string icone = GetEntryByNumber(0x0088,0x0200); //icone image sequence
+ TagKey key = gdcmDictEntry::TranslateToKey(grPixel,numPixel);
+ gdcmHeaderEntry* PixelElement;
+
+ if (tagHT.count(key) == 1)
+ PixelElement = (it.first)->second;
+ else
+ PixelElement = (++it.first)->second;
+
if (PixelElement)
return PixelElement->GetLength();
else {
bool gdcmHeader::HasLUT(void) {
// Check the presence of the LUT Descriptors
+
+ // LutDescriptorRed
if ( !GetHeaderEntryByNumber(0x0028,0x1101) )
return false;
// LutDescriptorGreen
// LutDescriptorBlue
if ( !GetHeaderEntryByNumber(0x0028,0x1103) )
return false;
+
// It is not enough
- // we check also
+ // we check also
+
+ // Red Palette Color Lookup Table Data
if ( !GetHeaderEntryByNumber(0x0028,0x1201) )
- return false;
+ return false;
+ // Green Palette Color Lookup Table Data
if ( !GetHeaderEntryByNumber(0x0028,0x1202) )
return false;
+ // Blue Palette Color Lookup Table Data
if ( !GetHeaderEntryByNumber(0x0028,0x1203) )
return false;
return true;
tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
Tokenize (LutDescriptionG, tokens, "\\");
lengthG=atoi(tokens[0].c_str()); // Green LUT length in Bytes
- debG =atoi(tokens[1].c_str());
- nbitsG =atoi(tokens[2].c_str());
+ debG =atoi(tokens[1].c_str()); // subscript of the first Lut Value
+ nbitsG =atoi(tokens[2].c_str()); // Lut item size (in Bits)
tokens.clear();
tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
Tokenize (LutDescriptionB, tokens, "\\");
lengthB=atoi(tokens[0].c_str()); // Blue LUT length in Bytes
- debB =atoi(tokens[1].c_str());
- nbitsB =atoi(tokens[2].c_str());
+ debB =atoi(tokens[1].c_str()); // subscript of the first Lut Value
+ nbitsB =atoi(tokens[2].c_str()); // Lut item size (in Bits)
tokens.clear();
// Load LUTs into memory, (as they were stored on disk)
#define UI1_2_840_10008_1_2_2 "1.2.840.10008.1.2.2"
#define UI1_2_840_10008_1_2_1_99 "1.2.840.10008.1.2.1.99"
+ // Fourth semantics:
+ //
+ // ---> Warning : This fourth field is NOT part
+ // of the 'official' Dicom Dictionnary
+ // and should NOT be used.
+ // (Not defined for all the groups
+ // may be removed in a future release)
+ //
+ // CMD Command
+ // META Meta Information
+ // DIR Directory
+ // ID
+ // PAT Patient
+ // ACQ Acquisition
+ // REL Related
+ // IMG Image
+ // SDY Study
+ // VIS Visit
+ // WAV Waveform
+ // PRC
+ // DEV Device
+ // NMI Nuclear Medicine
+ // MED
+ // BFS Basic Film Session
+ // BFB Basic Film Box
+ // BIB Basic Image Box
+ // BAB
+ // IOB
+ // PJ
+ // PRINTER
+ // RT Radio Therapy
+ // DVH
+ // SSET
+ // RES Results
+ // CRV Curve
+ // OLY Overlays
+ // PXL Pixels
+ // DL Delimiters
+ //
+
//-----------------------------------------------------------------------------
// Refer to gdcmParser::CheckSwap()
const unsigned int gdcmParser::HEADER_LENGTH_TO_READ = 256;
* @param enable_sequences = true to allow the header
* to be parsed *inside* the SeQuences,
* when they have an actual length
- *\TODO may be we need one more bool,
- * to allow skipping the private elements while parsing the header
- * in order to save space
+ * @param ignore_shadow to allow skipping the shadow elements,
+ * to save memory space.
+ * \warning The TRUE value for this param has to be used
+ * with a FALSE value for the 'enable_sequence' param.
+ * ('public elements' may be embedded in 'shadow Sequences')
*/
gdcmParser::gdcmParser(const char *InFilename,
bool exception_on_error,
- bool enable_sequences )
-{
+ bool enable_sequences,
+ bool ignore_shadow) {
enableSequences=enable_sequences;
+ ignoreShadow =ignore_shadow;
SetMaxSizeLoadEntry(MAX_SIZE_LOAD_ELEMENT_VALUE);
filename = InFilename;
* \brief
* @param exception_on_error
*/
-gdcmParser::gdcmParser(bool exception_on_error)
-{
+gdcmParser::gdcmParser(bool exception_on_error) {
enableSequences=0;
SetMaxSizeLoadEntry(MAX_SIZE_LOAD_ELEMENT_VALUE);
* \ingroup gdcmParser
* \brief Canonical destructor.
*/
-gdcmParser::~gdcmParser (void)
-{
+gdcmParser::~gdcmParser (void) {
RefPubDict = NULL;
RefShaDict = NULL;
}
* both from the H Table and the chained list
* @return
*/
-void gdcmParser::PrintEntry(std::ostream & os)
-{
+void gdcmParser::PrintEntry(std::ostream & os) {
std::ostringstream s;
for (ListTag::iterator i = listEntries.begin();
* \ingroup gdcmParser
* \brief Get the public dictionary used
*/
-gdcmDict *gdcmParser::GetPubDict(void)
-{
+gdcmDict *gdcmParser::GetPubDict(void) {
return(RefPubDict);
}
* \ingroup gdcmParser
* \brief Get the shadow dictionary used
*/
-gdcmDict *gdcmParser::GetShaDict(void)
-{
+gdcmDict *gdcmParser::GetShaDict(void) {
return(RefShaDict);
}
* \brief Set the shadow dictionary used
* \param dict dictionary to use in shadow
*/
-bool gdcmParser::SetShaDict(gdcmDict *dict)
-{
+bool gdcmParser::SetShaDict(gdcmDict *dict){
RefShaDict=dict;
return(!RefShaDict);
}
* \brief Set the shadow dictionary used
* \param dictName name of the dictionary to use in shadow
*/
-bool gdcmParser::SetShaDict(DictKey dictName)
-{
+bool gdcmParser::SetShaDict(DictKey dictName){
RefShaDict=gdcmGlobal::GetDicts()->GetDict(dictName);
return(!RefShaDict);
}
* @return true when gdcmParser is the one of a reasonable Dicom/Acr file,
* false otherwise.
*/
-bool gdcmParser::IsReadable(void)
-{
+bool gdcmParser::IsReadable(void) {
if(filetype==Unknown)
return(false);
*
* @return True when ImplicitVRLittleEndian found. False in all other cases.
*/
-bool gdcmParser::IsImplicitVRLittleEndianTransferSyntax(void)
-{
+bool gdcmParser::IsImplicitVRLittleEndianTransferSyntax(void) {
gdcmHeaderEntry *Element = GetHeaderEntryByNumber(0x0002, 0x0010);
if ( !Element )
return false;
*
* @return True when ExplicitVRLittleEndian found. False in all other cases.
*/
-bool gdcmParser::IsExplicitVRLittleEndianTransferSyntax(void)
-{
+bool gdcmParser::IsExplicitVRLittleEndianTransferSyntax(void) {
gdcmHeaderEntry* Element = GetHeaderEntryByNumber(0x0002, 0x0010);
if ( !Element )
return false;
*
* @return True when DeflatedExplicitVRLittleEndian found. False in all other cases.
*/
-bool gdcmParser::IsDeflatedExplicitVRLittleEndianTransferSyntax(void)
-{
+bool gdcmParser::IsDeflatedExplicitVRLittleEndianTransferSyntax(void) {
gdcmHeaderEntry* Element = GetHeaderEntryByNumber(0x0002, 0x0010);
if ( !Element )
return false;
*
* @return True when big endian found. False in all other cases.
*/
-bool gdcmParser::IsExplicitVRBigEndianTransferSyntax(void)
-{
+bool gdcmParser::IsExplicitVRBigEndianTransferSyntax(void) {
gdcmHeaderEntry* Element = GetHeaderEntryByNumber(0x0002, 0x0010);
if ( !Element )
return false;
* \brief closes the file
* @return TRUE if the close was successfull
*/
-bool gdcmParser::CloseFile(void)
-{
+bool gdcmParser::CloseFile(void) {
int closed = fclose(fp);
fp = (FILE *)0;
if (! closed)
* (ACR-NEMA, ExplicitVR, ImplicitVR)
* @return always "True" ?!
*/
-bool gdcmParser::Write(FILE *fp, FileType type)
-{
+bool gdcmParser::Write(FILE *fp, FileType type) {
// ==============
// TODO The stuff has been rewritten using the chained list instead
// of the H table
* \return boolean
*/
bool gdcmParser::ReplaceOrCreateByNumber(std::string Value,
- guint16 Group, guint16 Elem )
-{
+ guint16 Group,
+ guint16 Elem ){
if (CheckIfEntryExistByNumber(Group, Elem) == 0) {
gdcmHeaderEntry *a =NewHeaderEntryByNumber(Group, Elem);
if (a == NULL)
* \return boolean
*
*/
-bool gdcmParser::ReplaceOrCreateByNumber(char* Value, guint16 Group, guint16 Elem )
-{
+bool gdcmParser::ReplaceOrCreateByNumber(char* Value, guint16 Group, guint16 Elem ) {
gdcmHeaderEntry* nvHeaderEntry=NewHeaderEntryByNumber(Group, Elem);
if(!nvHeaderEntry)
* @param element Element number of the searched Dicom Element
* @return number of occurences
*/
-int gdcmParser::CheckIfEntryExistByNumber(guint16 group, guint16 element )
-{
+int gdcmParser::CheckIfEntryExistByNumber(guint16 group, guint16 element ) {
std::string key = gdcmDictEntry::TranslateToKey(group, element );
return (tagHT.count(key));
}
* @return Corresponding element value when it exists,
* and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
*/
-std::string gdcmParser::GetEntryByName(std::string tagName)
-{
+std::string gdcmParser::GetEntryByName(std::string tagName) {
gdcmDictEntry *dictEntry = RefPubDict->GetDictEntryByName(tagName);
if( dictEntry == NULL)
return GDCM_UNFOUND;
* @return Corresponding element value representation when it exists,
* and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
*/
-std::string gdcmParser::GetEntryVRByName(std::string tagName)
-{
+std::string gdcmParser::GetEntryVRByName(std::string tagName) {
gdcmDictEntry *dictEntry = RefPubDict->GetDictEntryByName(tagName);
if( dictEntry == NULL)
return GDCM_UNFOUND;
* @return Corresponding element value representation when it exists,
* and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
*/
-std::string gdcmParser::GetEntryByNumber(guint16 group, guint16 element)
-{
+std::string gdcmParser::GetEntryByNumber(guint16 group, guint16 element){
TagKey key = gdcmDictEntry::TranslateToKey(group, element);
if ( ! tagHT.count(key))
return GDCM_UNFOUND;
* @return Corresponding element value representation when it exists,
* and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
*/
-std::string gdcmParser::GetEntryVRByNumber(guint16 group, guint16 element)
-{
+std::string gdcmParser::GetEntryVRByNumber(guint16 group, guint16 element) {
gdcmHeaderEntry* elem = GetHeaderEntryByNumber(group, element);
if ( !elem )
return GDCM_UNFOUND;
* @param tagName name of the searched Dicom Element.
* @return true when found
*/
-bool gdcmParser::SetEntryByName(std::string content,std::string tagName)
-{
+bool gdcmParser::SetEntryByName(std::string content,std::string tagName) {
gdcmDictEntry *dictEntry = RefPubDict->GetDictEntryByName(tagName);
if( dictEntry == NULL)
return false;
content = content + '\0';
}
- //tagHT[key]->SetValue(content);
gdcmHeaderEntry * a;
IterHT p;
TagHeaderEntryHT::iterator p2;
a-> SetValue(content);
- //std::string vr = tagHT[key]->GetVR();
std::string vr = a->GetVR();
guint32 lgr;
else
lgr = l;
- //tagHT[key]->SetLength(lgr);
a->SetLength(lgr);
return true;
}
*/
bool gdcmParser::SetEntryLengthByNumber(guint32 length,
- guint16 group, guint16 element)
+ guint16 group,
+ guint16 element)
{
TagKey key = gdcmDictEntry::TranslateToKey(group, element);
if ( ! tagHT.count(key))
return false;
if (length%2) length++; // length must be even
- //tagHT[key]->SetLength(length);
( ((tagHT.equal_range(key)).first)->second )->SetLength(length);
return true ;
* \ingroup gdcmParser
* \brief Loads (from disk) the element content
* when a string is not suitable
+ * @param Group
+ * @param Elem
*/
void *gdcmParser::LoadEntryVoidArea(guint16 Group, guint16 Elem)
{
* @param element Element number of the searched Dicom Element
* @return
*/
-bool gdcmParser::SetEntryVoidAreaByNumber(void * area,guint16 group, guint16 element)
+bool gdcmParser::SetEntryVoidAreaByNumber(void * area,
+ guint16 group,
+ guint16 element)
{
TagKey key = gdcmDictEntry::TranslateToKey(group, element);
if ( ! tagHT.count(key))
return false;
- //tagHT[key]->SetVoidArea(area);
( ((tagHT.equal_range(key)).first)->second )->SetVoidArea(area);
return true;
}
* \brief Update the entries with the shadow dictionary. Only odd entries are
* analized
*/
-void gdcmParser::UpdateShaEntries(void)
-{
+void gdcmParser::UpdateShaEntries(void) {
gdcmDictEntry *entry;
std::string vr;
vr=(*it)->GetVR();
(*it)->SetValue(GetHeaderEntryUnvalue(*it));
- if(entry)
- {
+ if(entry){
// Set the new entry and the new value
(*it)->SetDictEntry(entry);
CheckHeaderEntryVR(*it,vr);
* @return Corresponding Dicom Element when it exists, and NULL
* otherwise.
*/
- gdcmHeaderEntry *gdcmParser::GetHeaderEntryByName(std::string tagName)
- {
+ gdcmHeaderEntry *gdcmParser::GetHeaderEntryByName(std::string tagName) {
gdcmDictEntry *dictEntry = RefPubDict->GetDictEntryByName(tagName);
if( dictEntry == NULL)
return NULL;
return tagHT.find(key)->second;
}
+/**
+ * \ingroup gdcmParser
+ * \brief retrieves the Dicom Elements (all of them) using (group, element)
+ * @param group Group number of the searched Dicom Element.
+ * @param element Element number of the searched Dicom Element.
+ * @return a range (i.e.pair<,>) containing all elements whose key is group|element)
+ */
+
+IterHT gdcmParser::GetHeaderEntrySameNumber(guint16 group, guint16 element){
+ TagKey key = gdcmDictEntry::TranslateToKey(group, element);
+ return (tagHT.equal_range(key));
+}
+
/**
* \ingroup gdcmParser
* \brief Loads the element while preserving the current
* @param entry Header Entry whose value shall be loaded.
* @return
*/
-void gdcmParser::LoadHeaderEntrySafe(gdcmHeaderEntry * entry)
-{
+void gdcmParser::LoadHeaderEntrySafe(gdcmHeaderEntry * entry) {
long PositionOnEntry = ftell(fp);
LoadHeaderEntry(entry);
fseek(fp, PositionOnEntry, SEEK_SET);
* @param SkipSequence TRUE if we don't want to write Sequences (ACR-NEMA Files)
* @param type Type of the File (ExplicitVR,ImplicitVR, ACR, ...)
*/
-void gdcmParser::UpdateGroupLength(bool SkipSequence, FileType type)
-{
+void gdcmParser::UpdateGroupLength(bool SkipSequence, FileType type) {
guint16 gr, el;
std::string vr;
* processor order.
* @return The properly swaped 32 bits integer.
*/
-guint32 gdcmParser::SwapLong(guint32 a)
-{
- switch (sw)
- {
+guint32 gdcmParser::SwapLong(guint32 a) {
+ switch (sw) {
case 0 :
break;
case 4321 :
* processor order.
* @return The properly unswaped 32 bits integer.
*/
-guint32 gdcmParser::UnswapLong(guint32 a)
-{
+guint32 gdcmParser::UnswapLong(guint32 a) {
return (SwapLong(a));
}
* \brief Swaps the bytes so they agree with the processor order
* @return The properly swaped 16 bits integer.
*/
-guint16 gdcmParser::SwapShort(guint16 a)
-{
+guint16 gdcmParser::SwapShort(guint16 a) {
if ( (sw==4321) || (sw==2143) )
a =(((a<<8) & 0x0ff00) | ((a>>8)&0x00ff));
return (a);
* \brief Unswaps the bytes so they agree with the processor order
* @return The properly unswaped 16 bits integer.
*/
-guint16 gdcmParser::UnswapShort(guint16 a)
-{
+guint16 gdcmParser::UnswapShort(guint16 a) {
return (SwapShort(a));
}
* \ingroup gdcmParser
* \brief Parses the header of the file but WITHOUT loading element values.
*/
-void gdcmParser::Parse(bool exception_on_error) throw(gdcmFormatError)
-{
+void gdcmParser::Parse(bool exception_on_error) throw(gdcmFormatError) {
gdcmHeaderEntry *newHeaderEntry = (gdcmHeaderEntry *)0;
rewind(fp);
CheckSwap();
- while ( (newHeaderEntry = ReadNextHeaderEntry()) )
- {
- SkipHeaderEntry(newHeaderEntry);
- AddHeaderEntry(newHeaderEntry);
+ while ( (newHeaderEntry = ReadNextHeaderEntry()) ) {
+ SkipHeaderEntry(newHeaderEntry);
+ if ( (ignoreShadow==0) || (newHeaderEntry->GetGroup()%2) == 0) { //JPR
+ AddHeaderEntry(newHeaderEntry);
+ }
}
}
* \brief Loads the element values of all the Header Entries pointed in the
* public Chained List.
*/
-void gdcmParser::LoadHeaderEntries(void)
-{
+void gdcmParser::LoadHeaderEntries(void) {
rewind(fp);
for (ListTag::iterator i = GetListEntry().begin();
i != GetListEntry().end();
// Load 'non string' values
std::string PhotometricInterpretation = GetEntryByNumber(0x0028,0x0004);
- if( PhotometricInterpretation == "PALETTE COLOR " )
- {
+ if( PhotometricInterpretation == "PALETTE COLOR " ) {
LoadEntryVoidArea(0x0028,0x1200); // gray LUT
LoadEntryVoidArea(0x0028,0x1201); // R LUT
LoadEntryVoidArea(0x0028,0x1202); // G LUT
* gdcmParser::SetMaxSizeLoadEntry()
* @param Entry Header Entry (Dicom Element) to be dealt with
*/
-void gdcmParser::LoadHeaderEntry(gdcmHeaderEntry *Entry)
-{
+void gdcmParser::LoadHeaderEntry(gdcmHeaderEntry *Entry) {
size_t item_read;
guint16 group = Entry->GetGroup();
std::string vr= Entry->GetVR();
if( group == 0xfffe )
SkipLoad = true;
- if ( SkipLoad )
- {
+ if ( SkipLoad ) {
Entry->SetLength(0);
Entry->SetValue("gdcm::Skipped");
return;
}
// When the length is zero things are easy:
- if ( length == 0 )
- {
+ if ( length == 0 ) {
Entry->SetValue("");
return;
}
// The elements whose length is bigger than the specified upper bound
// are not loaded. Instead we leave a short notice of the offset of
// the element content and it's length.
- if (length > MaxSizeLoadEntry)
- {
+ if (length > MaxSizeLoadEntry) {
std::ostringstream s;
s << "gdcm::NotLoaded.";
s << " Address:" << (long)Entry->GetOffset();
// contain a set of integers (not a single one)
// Any compacter code suggested (?)
- if ( IsHeaderEntryAnInteger(Entry) )
- {
+ if ( IsHeaderEntryAnInteger(Entry) ) {
guint32 NewInt;
std::ostringstream s;
int nbInt;
- if (vr == "US" || vr == "SS")
- {
+ if (vr == "US" || vr == "SS") {
nbInt = length / 2;
NewInt = ReadInt16();
s << NewInt;
- if (nbInt > 1)
- {
- for (int i=1; i < nbInt; i++)
- {
+ if (nbInt > 1){
+ for (int i=1; i < nbInt; i++) {
s << '\\';
NewInt = ReadInt16();
s << NewInt;
}
- }
-
+ }
}
- else if (vr == "UL" || vr == "SL")
- {
+ else if (vr == "UL" || vr == "SL") {
nbInt = length / 4;
NewInt = ReadInt32();
s << NewInt;
- if (nbInt > 1)
- {
- for (int i=1; i < nbInt; i++)
- {
+ if (nbInt > 1) {
+ for (int i=1; i < nbInt; i++) {
s << '\\';
NewInt = ReadInt32();
s << NewInt;
#ifdef GDCM_NO_ANSI_STRING_STREAM
s << std::ends; // to avoid oddities on Solaris
#endif //GDCM_NO_ANSI_STRING_STREAM
+
Entry->SetValue(s.str());
return;
}
// We need an additional byte for storing \0 that is not on disk
std::string NewValue(length,0);
item_read = fread(&(NewValue[0]), (size_t)length, (size_t)1, fp);
- if ( item_read != 1 )
- {
+ if ( item_read != 1 ) {
dbg.Verbose(1, "gdcmParser::LoadElementValue","unread element value");
Entry->SetValue("gdcm::UnRead");
return;
* \ when position to be taken care of
* @param newHeaderEntry
*/
-void gdcmParser::AddHeaderEntry(gdcmHeaderEntry *newHeaderEntry)
-{
+void gdcmParser::AddHeaderEntry(gdcmHeaderEntry *newHeaderEntry) {
tagHT.insert( PairHT( newHeaderEntry->GetKey(),newHeaderEntry) );
listEntries.push_back(newHeaderEntry);
wasUpdated = 1;
* @return
*/
- void gdcmParser::FindHeaderEntryLength (gdcmHeaderEntry *Entry)
- {
+ void gdcmParser::FindHeaderEntryLength (gdcmHeaderEntry *Entry) {
guint16 element = Entry->GetElement();
guint16 group = Entry->GetGroup();
std::string vr = Entry->GetVR();
else if ( Entry->GetVR() == "SQ")
{
if (enableSequences) // only if the user does want to !
- FoundLength =0;
+ FoundLength =0; // ReadLength is unchanged
}
// a SeQuence Element is beginning
* @param Entry The element value on which to apply the predicate.
* @return The result of the heuristical predicate.
*/
-bool gdcmParser::IsHeaderEntryAnInteger(gdcmHeaderEntry *Entry)
-{
+bool gdcmParser::IsHeaderEntryAnInteger(gdcmHeaderEntry *Entry) {
guint16 element = Entry->GetElement();
guint16 group = Entry->GetGroup();
std::string vr = Entry->GetVR();
guint32 length = Entry->GetLength();
-
// When we have some semantics on the element we just read, and if we
// a priori know we are dealing with an integer, then we shall be
// able to swap it's element value properly.
else
{
std::ostringstream s;
- s << "Erroneous Group Length element length on :" \
- << std::hex << group << " , " << element;
- dbg.Error("gdcmParser::IsHeaderEntryAnInteger",
- s.str().c_str());
+ int filePosition = ftell(fp);
+ s << "Erroneous Group Length element length on : (" \
+ << std::hex << group << " , " << element
+ << ") -before- position x(" << filePosition << ")"
+ << "lgt : " << length;
+ // These 2 lines commented out : a *very dirty* patch
+ // to go on PrintHeader'ing gdcm-MR-PHILIPS-16-Multi-Seq.dcm.
+ // have a glance at offset x(8336) ...
+ // For *regular* headers, the test is useless..
+ // lets's print a warning message and go on,
+ // instead of giving up with an error message
+ std::cout << s.str().c_str() << std::endl;
+ // dbg.Error("gdcmParser::IsHeaderEntryAnInteger",
+ // s.str().c_str());
}
}
if ( (vr == "UL") || (vr == "US") || (vr == "SL") || (vr == "SS") )
*
* @return
*/
- guint32 gdcmParser::FindHeaderEntryLengthOB(void)
- {
+ guint32 gdcmParser::FindHeaderEntryLengthOB(void) {
// See PS 3.5-2001, section A.4 p. 49 on encapsulation of encoded pixel data.
guint16 g;
guint16 n;
* \brief Reads a supposed to be 16 Bits integer
* \ (swaps it depending on processor endianity)
*
- * @return integer acts as a boolean
+ * @return read value
*/
-guint16 gdcmParser::ReadInt16(void)
-{
+guint16 gdcmParser::ReadInt16(void) {
guint16 g;
size_t item_read;
item_read = fread (&g, (size_t)2,(size_t)1, fp);
- if ( item_read != 1 )
- {
+ if ( item_read != 1 ) {
if(ferror(fp))
dbg.Verbose(0, "gdcmParser::ReadInt16", " File Error");
errno = 1;
return 0;
}
errno = 0;
- g = SwapShort(g);
+ g = SwapShort(g);
return g;
}
* \brief Reads a supposed to be 32 Bits integer
* \ (swaps it depending on processor endianity)
*
- * @return
+ * @return read value
*/
-guint32 gdcmParser::ReadInt32(void)
-{
+guint32 gdcmParser::ReadInt32(void) {
guint32 g;
size_t item_read;
item_read = fread (&g, (size_t)4,(size_t)1, fp);
- if ( item_read != 1 )
- {
+ if ( item_read != 1 ) {
if(ferror(fp))
dbg.Verbose(0, "gdcmParser::ReadInt32", " File Error");
errno = 1;
*
* @return
*/
-void gdcmParser::SkipBytes(guint32 NBytes)
-{
+void gdcmParser::SkipBytes(guint32 NBytes) {
//FIXME don't dump the returned value
(void)fseek(fp, (long)NBytes, SEEK_CUR);
}
* bad little endian, bad big endian).
*
*/
-void gdcmParser::CheckSwap()
-{
- // Fourth semantics:
- //
- // ---> Warning : This fourth field is NOT part
- // of the 'official' Dicom Dictionnary
- // and should NOT be used.
- // (Not defined for all the groups
- // may be removed in a future release)
- //
- // CMD Command
- // META Meta Information
- // DIR Directory
- // ID
- // PAT Patient
- // ACQ Acquisition
- // REL Related
- // IMG Image
- // SDY Study
- // VIS Visit
- // WAV Waveform
- // PRC
- // DEV Device
- // NMI Nuclear Medicine
- // MED
- // BFS Basic Film Session
- // BFB Basic Film Box
- // BIB Basic Image Box
- // BAB
- // IOB
- // PJ
- // PRINTER
- // RT Radio Therapy
- // DVH
- // SSET
- // RES Results
- // CRV Curve
- // OLY Overlays
- // PXL Pixels
- // DL Delimiters
- //
+void gdcmParser::CheckSwap() {
// The only guaranted way of finding the swap code is to find a
// group tag since we know it's length has to be of four bytes i.e.
// 0x00000004. Finding the swap code in then straigthforward. Trouble
// occurs when we can't find such group...
+
guint32 s;
guint32 x=4; // x : for ntohs
bool net2host; // true when HostByteOrder is the same as NetworkByteOrder
net2host = true;
else
net2host = false;
- //cout << net2host << endl;
// The easiest case is the one of a DICOM header, since it possesses a
// file preamble where it suffice to look for the string "DICM".
lgrLue = fread(deb, 1, HEADER_LENGTH_TO_READ, fp);
entCur = deb + 128;
- if(memcmp(entCur, "DICM", (size_t)4) == 0)
- {
+ if(memcmp(entCur, "DICM", (size_t)4) == 0) {
dbg.Verbose(1, "gdcmParser::CheckSwap:", "looks like DICOM Version3");
+
// Next, determine the value representation (VR). Let's skip to the
// first element (0002, 0000) and check there if we find "UL"
// - or "OB" if the 1st one is (0002,0001) -,
// FIXME
// Use gdcmParser::dicom_vr to test all the possibilities
// instead of just checking for UL, OB and UI !?
- if( (memcmp(entCur, "UL", (size_t)2) == 0) ||
+ if( (memcmp(entCur, "UL", (size_t)2) == 0) ||
(memcmp(entCur, "OB", (size_t)2) == 0) ||
(memcmp(entCur, "UI", (size_t)2) == 0) )
{
// representation of a 32 bits integer. Hence the following dirty
// trick :
s = *((guint32 *)(entCur));
-
- switch (s)
- {
+
+ switch (s) {
case 0x00040000 :
sw = 3412;
filetype = ACR;
* \brief Read the next tag but WITHOUT loading it's value
* @return On succes the newly created HeaderEntry, NULL on failure.
*/
-gdcmHeaderEntry *gdcmParser::ReadNextHeaderEntry(void)
-{
+gdcmHeaderEntry *gdcmParser::ReadNextHeaderEntry(void) {
guint16 g,n;
gdcmHeaderEntry *NewEntry;
n = ReadInt16();
if (errno == 1)
- // We reached the EOF (or an error occured) and header parsing
- // has to be considered as finished.
+ // We reached the EOF (or an error occured) therefore
+ // header parsing has to be considered as finished.
return (gdcmHeaderEntry *)0;
+
+/* Pb : how to propagate the element length (used in SkipHeaderEntry)
+// direct call to SkipBytes ?
+ if (ignoreShadow == 1 && g%2 ==1) //JPR
+ // 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
+*/
NewEntry = NewHeaderEntryByNumber(g, n);
FindHeaderEntryVR(NewEntry);
FindHeaderEntryLength(NewEntry);
- if (errno == 1)
- {
+ if (errno == 1) {
// Call it quits
return NULL;
}