Program: gdcm
Module: $RCSfile: gdcmDocument.cxx,v $
Language: C++
- Date: $Date: 2004/08/02 16:42:14 $
- Version: $Revision: 1.65 $
+ Date: $Date: 2004/09/07 13:57:04 $
+ Version: $Revision: 1.71 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
/**
* \brief constructor
- * @param inFilename file to be opened for parsing
+ * @param filename file to be opened for parsing
*/
gdcmDocument::gdcmDocument( std::string const & filename )
: gdcmElementSet(-1)
{
return;
}
-
+
dbg.Verbose(0, "gdcmDocument::gdcmDocument: starting parsing of file: ",
Filename.c_str());
rewind(Fp);
{
if( Filetype == gdcmUnknown)
{
- std::cout << " gdcmDocument::IsReadable: Filetype " << Filetype
- << " " << "gdcmUnknown " << gdcmUnknown << std::endl; //JPR
dbg.Verbose(0, "gdcmDocument::IsReadable: wrong filetype");
return false;
}
/**
* \brief Internal function that checks whether the Transfer Syntax given
* as argument is the one present in the current document.
- * @param SyntaxToCheck The transfert syntax we need to check against.
+ * @param syntaxToCheck The transfert syntax we need to check against.
* @return True when SyntaxToCheck corresponds to the Transfer Syntax of
* the current document. False either when the document contains
* no Transfer Syntax, or when the Tranfer Syntaxes doesn't match.
/**
* \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 value (string) Value to be set
+ * @param group Group number of the Entry
+ * @param elem Element number of the Entry
* \return pointer to the modified/created Header Entry (NULL when creation
* failed).
*/
uint16_t elem )
{
gdcmValEntry* valEntry = 0;
-
gdcmDocEntry* currentEntry = GetDocEntryByNumber( group, elem);
+
if (!currentEntry)
{
// The entry wasn't present and we simply create the required ValEntry:
return b;
}
+
+/*
+ * \brief Modifies the value of a given Header Entry (Dicom Element)
+ * when it exists. Create it when unexistant.
+ * @param Group Group number of the Entry
+ * @param Elem Element number of the Entry
+ * \return pointer to the modified/created SeqEntry (NULL when creation
+ * failed).
+ */
+gdcmSeqEntry * gdcmDocument::ReplaceOrCreateByNumber(
+ uint16_t group,
+ uint16_t elem)
+{
+ gdcmSeqEntry* b = 0;
+ gdcmDocEntry* a = GetDocEntryByNumber( group, elem);
+ if (!a)
+ {
+ a = NewSeqEntryByNumber(group, elem);
+ if (!a)
+ {
+ return 0;
+ }
+
+ b = new gdcmSeqEntry(a, 1); // FIXME : 1 (Depth)
+ AddEntry(b);
+ }
+ return b;
+}
+
/**
* \brief Set a new value if the invoked element exists
* Seems to be useless !!!
- * @param Value new element value
- * @param Group group number of the Entry
- * @param Elem element number of the Entry
+ * @param value new element value
+ * @param group group number of the Entry
+ * @param elem element number of the Entry
* \return boolean
*/
bool gdcmDocument::ReplaceIfExistByNumber(std::string const & value,
* \brief Checks if a given Dicom Element exists within the H table
* @param group Group number of the searched Dicom Element
* @param element Element number of the searched Dicom Element
- * @return number of occurences
+ * @return true is found
*/
-int gdcmDocument::CheckIfEntryExistByNumber(uint16_t group, uint16_t element )
+bool gdcmDocument::CheckIfEntryExistByNumber(uint16_t group, uint16_t element )
{
const std::string &key = gdcmDictEntry::TranslateToKey(group, element );
return TagHT.count(key);
gdcmVRKey vr = valEntry->GetVR();
if( vr == "US" || vr == "SS" )
{
- valEntry->SetLength(2);
+ int c = CountSubstring(content, "\\"); // for multivaluated items
+ valEntry->SetLength((c+1)*2);
}
else if( vr == "UL" || vr == "SL" )
{
- valEntry->SetLength(4);
+ int c = CountSubstring(content, "\\"); // for multivaluated items
+ valEntry->SetLength((c+1)*4);
}
else
{
/**
* \brief Gets (from Header) the offset of a 'non string' element value
* (LoadElementValues has already be executed)
- * @param Group group number of the Entry
- * @param Elem element number of the Entry
+ * @param group group number of the Entry
+ * @param elem element number of the Entry
* @return File Offset of the Element Value
*/
size_t gdcmDocument::GetEntryOffsetByNumber(uint16_t group, uint16_t elem)
/**
* \brief Gets (from Header) a 'non string' element value
* (LoadElementValues has already be executed)
- * @param Group group number of the Entry
- * @param Elem element number of the Entry
+ * @param group group number of the Entry
+ * @param elem element number of the Entry
* @return Pointer to the 'non string' area
*/
void * gdcmDocument::GetEntryVoidAreaByNumber(uint16_t group, uint16_t elem)
/**
* \brief Loads (from disk) the element content
* when a string is not suitable
- * @param Group group number of the Entry
- * @param Elem element number of the Entry
+ * @param group group number of the Entry
+ * @param elem element number of the Entry
*/
void *gdcmDocument::LoadEntryVoidArea(uint16_t group, uint16_t elem)
{
/**
* \brief Loads (from disk) the element content
* when a string is not suitable
- * @param Element Entry whose voidArea is going to be loaded
+ * @param element Entry whose voidArea is going to be loaded
*/
void *gdcmDocument::LoadEntryVoidArea(gdcmBinEntry *element)
{
a=( ((a<< 8) & 0xff00ff00) | ((a>>8) & 0x00ff00ff) );
break;
default :
- std::cout << "swapCode= " << SwapCode << std::endl;
+ //std::cout << "swapCode= " << SwapCode << std::endl;
dbg.Error(" gdcmDocument::SwapLong : unset swap code");
a = 0;
}
}
delete newDocEntry;
}
-
return l; // Probably useless
}
/**
* \brief Loads the element content if its length doesn't exceed
* the value specified with gdcmDocument::SetMaxSizeLoadEntry()
- * @param Entry Header Entry (Dicom Element) to be dealt with
+ * @param entry Header Entry (Dicom Element) to be dealt with
*/
void gdcmDocument::LoadDocEntry(gdcmDocEntry* entry)
{
if ( IsDocEntryAnInteger(entry) )
{
uint32_t NewInt;
- std::ostringstream s;
+ //std::ostringstream s; //shadow previous declaration
int nbInt;
// When short integer(s) are expected, read and convert the following
// n *two characters properly i.e. consider them as short integers as
/**
* \brief Find the value Length of the passed Header Entry
- * @param Entry Header Entry whose length of the value shall be loaded.
+ * @param entry Header Entry whose length of the value shall be loaded.
*/
void gdcmDocument::FindDocEntryLength( gdcmDocEntry *entry )
throw ( gdcmFormatError )
{
uint16_t element = entry->GetElement();
std::string vr = entry->GetVR();
- uint16_t length16;
-
+ uint16_t length16;
if ( Filetype == gdcmExplicitVR && !entry->IsImplicitVR() )
{
/**
* \brief Find the Value Representation of the current Dicom Element.
- * @param Entry
+ * @param entry
*/
void gdcmDocument::FindDocEntryVR( gdcmDocEntry *entry )
{
* \brief Check the correspondance between the VR of the header entry
* and the taken VR. If they are different, the header entry is
* updated with the new VR.
- * @param Entry Header Entry to check
+ * @param entry Header Entry to check
* @param vr Dicom Value Representation
* @return false if the VR is incorrect of if the VR isn't referenced
* otherwise, it returns true
* \brief Get the transformed value of the header entry. The VR value
* is used to define the transformation to operate on the value
* \warning NOT end user intended method !
- * @param Entry
+ * @param entry entry to tranform
* @return Transformed entry value
*/
std::string gdcmDocument::GetDocEntryValue(gdcmDocEntry *entry)
* value is used to define the reverse transformation to operate on
* the value
* \warning NOT end user intended method !
- * @param Entry
+ * @param entry Entry to reverse transform
* @return Reverse transformed entry value
*/
std::string gdcmDocument::GetDocEntryUnvalue(gdcmDocEntry* entry)
/**
* \brief Skip a given Header Entry
* \warning NOT end user intended method !
- * @param entry
+ * @param entry entry to skip
*/
void gdcmDocument::SkipDocEntry(gdcmDocEntry *entry)
{
/**
* \brief Skips to the begining of the next Header Entry
* \warning NOT end user intended method !
- * @param entry
+ * @param entry entry to skip
*/
void gdcmDocument::SkipToNextDocEntry(gdcmDocEntry *entry)
{
* \brief When the length of an element value is obviously wrong (because
* the parser went Jabberwocky) one can hope improving things by
* applying some heuristics.
+ * @param entry entry to check
+ * @param foundLength fist assumption about length
*/
void gdcmDocument::FixDocEntryFoundLength(gdcmDocEntry *entry,
uint32_t foundLength)
/**
* \brief Apply some heuristics to predict whether the considered
* element value contains/represents an integer or not.
- * @param Entry The element value on which to apply the predicate.
+ * @param entry The element value on which to apply the predicate.
* @return The result of the heuristical predicate.
*/
bool gdcmDocument::IsDocEntryAnInteger(gdcmDocEntry *entry)
/**
* \brief during parsing, Header Elements too long are not loaded in memory
- * @param NewSize
+ * @param newSize
*/
void gdcmDocument::SetMaxSizeLoadEntry(long newSize)
{
/**
* \brief Header Elements too long will not be printed
* \todo See comments of \ref gdcmDocument::MAX_SIZE_PRINT_ELEMENT_VALUE
- * @param NewSize
+ * @param newSize
*/
void gdcmDocument::SetMaxSizePrintEntry(long newSize)
{
{
// We reached the EOF (or an error occured) therefore
// header parsing has to be considered as finished.
- std::cout << e;
+ //std::cout << e;
return 0;
}
catch ( gdcmFormatError e )
{
// Call it quits
- std::cout << e;
+ //std::cout << e;
delete newEntry;
return 0;
}
}
/**
- * \brief Assuming the internal file pointer \ref gdcmDocument::fp
+ * \brief Assuming the internal file pointer \ref gdcmDocument::Fp
* is placed at the beginning of a tag check whether this
* tag is (TestGroup, TestElement).
- * \warning On success the internal file pointer \ref gdcmDocument::fp
+ * \warning On success the internal file pointer \ref gdcmDocument::Fp
* is modified to point after the tag.
* On failure (i.e. when the tag wasn't the expected tag
* (TestGroup, TestElement) the internal file pointer
- * \ref gdcmDocument::fp is restored to it's original position.
- * @param TestGroup The expected group of the tag.
- * @param TestElement The expected Element of the tag.
+ * \ref gdcmDocument::Fp is restored to it's original position.
+ * @param testGroup The expected group of the tag.
+ * @param testElement The expected Element of the tag.
* @return True on success, false otherwise.
*/
bool gdcmDocument::ReadTag(uint16_t testGroup, uint16_t testElement)
}
/**
- * \brief Assuming the internal file pointer \ref gdcmDocument::fp
+ * \brief Assuming the internal file pointer \ref gdcmDocument::Fp
* is placed at the beginning of a tag (TestGroup, TestElement),
* read the length associated to the Tag.
- * \warning On success the internal file pointer \ref gdcmDocument::fp
+ * \warning On success the internal file pointer \ref gdcmDocument::Fp
* is modified to point after the tag and it's length.
* On failure (i.e. when the tag wasn't the expected tag
* (TestGroup, TestElement) the internal file pointer
- * \ref gdcmDocument::fp is restored to it's original position.
- * @param TestGroup The expected group of the tag.
- * @param TestElement The expected Element of the tag.
+ * \ref gdcmDocument::Fp is restored to it's original position.
+ * @param testGroup The expected group of the tag.
+ * @param testElement The expected Element of the tag.
* @return On success returns the length associated to the tag. On failure
* returns 0.
*/
{
return true;
}
- else if(s1 > s2)
+ else if( s1 > s2 )
{
return false;
}
}
else if ( s1 > s2 )
{
- return true;
+ return false;
}
else
{
{
// Serie Instance UID
s1 = GetEntryByNumber(0x0020,0x000e);
- s2 = document.GetEntryByNumber(0x0020,0x000e);
+ s2 = document.GetEntryByNumber(0x0020,0x000e);
if ( s1 < s2 )
{
return true;