#endif
# include <iomanip>
+#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"
+#define UI1_2_840_10008_1_2_1_99 "1.2.840.10008.1.2.1.99"
+
//-----------------------------------------------------------------------------
// Refer to gdcmParser::CheckSwap()
const unsigned int gdcmParser::HEADER_LENGTH_TO_READ = 256;
*/
gdcmParser::gdcmParser(const char *InFilename,
bool exception_on_error,
- bool enable_sequences ) {
+ bool enable_sequences )
+{
enableSequences=enable_sequences;
SetMaxSizeLoadEntry(MAX_SIZE_LOAD_ELEMENT_VALUE);
if ( !OpenFile(exception_on_error))
return;
-
Parse();
LoadHeaderEntries();
-
CloseFile();
wasUpdated = 0; // will be set to 1 if user adds an entry
- printLevel = 1; // 'Medium' header print by default
+ printLevel = 1; // 'Heavy' header print by default
}
/**
* \brief
* @param exception_on_error
*/
-gdcmParser::gdcmParser(bool exception_on_error) {
- //enableSequences=0;
+gdcmParser::gdcmParser(bool exception_on_error)
+{
+ enableSequences=0;
SetMaxSizeLoadEntry(MAX_SIZE_LOAD_ELEMENT_VALUE);
Initialise();
* \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;
- s << "------------ gdcmParser::Print, using listEntries ----------------" << std::endl;
+ s << "------------ using listEntries ----------------" << std::endl;
for (ListTag::iterator i = listEntries.begin();
i != listEntries.end();
++i)
* \brief Prints The Dict Entries of THE public Dicom Dictionnry
* @return
*/
-void gdcmParser::PrintPubDict(std::ostream & os) {
+void gdcmParser::PrintPubDict(std::ostream & os)
+{
RefPubDict->Print(os);
}
/**
* \ingroup gdcmParser
- * \brief Prints The Dict Entries of the current shadow Dicom Dictionnry
+ * \brief Prints The Dict Entries of THE shadow Dicom Dictionnry
* @return
*/
-void gdcmParser::PrintShaDict(std::ostream & os) {
+void gdcmParser::PrintShaDict(std::ostream & os)
+{
RefShaDict->Print(os);
}
// Public
/**
* \ingroup gdcmParser
- * \brief Get THE public dictionary used
+ * \brief Get the public dictionary used
*/
gdcmDict *gdcmParser::GetPubDict(void)
{
/**
* \ingroup gdcmParser
- * \brief Get the current shadow dictionary
+ * \brief Get the shadow dictionary used
*/
gdcmDict *gdcmParser::GetShaDict(void)
{
* \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);
}
bool gdcmParser::IsReadable(void)
{
std::string res = GetEntryByNumber(0x0028, 0x0005);
- if ( res != GDCM_UNFOUND && atoi(res.c_str()) > 4 ) {
- //std::cout << "error on : 28 5" << std::endl;
+ if ( res != GDCM_UNFOUND && atoi(res.c_str()) > 4 )
return false; // Image Dimensions
- }
- if ( !GetHeaderEntryByNumber(0x0028, 0x0100) ) {
- //std::cout << "error on : 28 100" << std::endl;
+ if ( !GetHeaderEntryByNumber(0x0028, 0x0100) )
return false; // "Bits Allocated"
- }
- if ( !GetHeaderEntryByNumber(0x0028, 0x0101) ){
- // std::cout << "error on : 28 101" << std::endl;
+ if ( !GetHeaderEntryByNumber(0x0028, 0x0101) )
return false; // "Bits Stored"
- }
- if ( !GetHeaderEntryByNumber(0x0028, 0x0102) ) {
- //std::cout << "error on : 28 102" << std::endl;
+ if ( !GetHeaderEntryByNumber(0x0028, 0x0102) )
return false; // "High Bit"
- }
- if ( !GetHeaderEntryByNumber(0x0028, 0x0103) ) {
- //std::cout << "error on : 28 103" << std::endl;
+ if ( !GetHeaderEntryByNumber(0x0028, 0x0103) )
return false; // "Pixel Representation"
- }
return true;
}
*
* @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;
LoadHeaderEntrySafe(Element);
std::string Transfer = Element->GetValue();
- if ( Transfer == "1.2.840.10008.1.2" )
+ if ( Transfer == UI1_2_840_10008_1_2 )
return true;
return false;
}
LoadHeaderEntrySafe(Element);
std::string Transfer = Element->GetValue();
- if ( Transfer == "1.2.840.10008.1.2.1" )
+ if ( Transfer == UI1_2_840_10008_1_2_1 )
return true;
return false;
}
LoadHeaderEntrySafe(Element);
std::string Transfer = Element->GetValue();
- if ( Transfer == "1.2.840.10008.1.2.1.99" )
+ if ( Transfer == UI1_2_840_10008_1_2_1_99 )
return true;
return false;
}
LoadHeaderEntrySafe(Element);
std::string Transfer = Element->GetValue();
- if ( Transfer == "1.2.840.10008.1.2.2" ) //1.2.2 ??? A verifier !
+ if ( Transfer == UI1_2_840_10008_1_2_2 ) //1.2.2 ??? A verifier !
return true;
return false;
}
* (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
if (type == ImplicitVR)
{
- std::string implicitVRTransfertSyntax = "1.2.840.10008.1.2";
+ std::string implicitVRTransfertSyntax = UI1_2_840_10008_1_2;
ReplaceOrCreateByNumber(implicitVRTransfertSyntax,0x0002, 0x0010);
//FIXME Refer to standards on page 21, chapter 6.2 "Value representation":
if (type == ExplicitVR)
{
- std::string explicitVRTransfertSyntax = "1.2.840.10008.1.2.1";
+ std::string explicitVRTransfertSyntax = UI1_2_840_10008_1_2_1;
ReplaceOrCreateByNumber(explicitVRTransfertSyntax,0x0002, 0x0010);
//FIXME Refer to standards on page 21, chapter 6.2 "Value representation":
* \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 Elem
* \return boolean
*/
-bool gdcmParser::ReplaceIfExistByNumber(char* Value, guint16 Group, guint16 Elem ) {
+bool gdcmParser::ReplaceIfExistByNumber(char* Value, guint16 Group, guint16 Elem )
+{
std::string v = Value;
SetEntryByNumber(v, Group, Elem);
return true;
* @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));
}
* \brief Searches within Header Entries (Dicom Elements) parsed with
* the public and private dictionaries
* for the element value of a given tag.
+ * \warning Don't use any longer : use GetPubEntryByName
* @param tagName name of the searched element.
* @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;
*/
bool gdcmParser::SetEntryByNumber(std::string content,
guint16 group,
- guint16 element) {
+ guint16 element)
+{
TagKey key = gdcmDictEntry::TranslateToKey(group, element);
if ( ! tagHT.count(key))
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 ;
* @param Elem
* @return File Offset of the Element Value
*/
-size_t gdcmParser::GetEntryOffsetByNumber(guint16 Group, guint16 Elem) {
+size_t gdcmParser::GetEntryOffsetByNumber(guint16 Group, guint16 Elem)
+{
gdcmHeaderEntry* Entry = GetHeaderEntryByNumber(Group, Elem);
if (!Entry)
{
* @param Elem
* @return Pointer to the 'non string' area
*/
-void * gdcmParser::GetEntryVoidAreaByNumber(guint16 Group, guint16 Elem) {
+void * gdcmParser::GetEntryVoidAreaByNumber(guint16 Group, guint16 Elem)
+{
gdcmHeaderEntry* Entry = GetHeaderEntryByNumber(Group, Elem);
if (!Entry)
{
* \brief Loads (from disk) the element content
* when a string is not suitable
*/
-void *gdcmParser::LoadEntryVoidArea(guint16 Group, guint16 Elem) {
+void *gdcmParser::LoadEntryVoidArea(guint16 Group, guint16 Elem)
+{
gdcmHeaderEntry * Element= GetHeaderEntryByNumber(Group, Elem);
if ( !Element )
return NULL;
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;
}
// Peer group => search the corresponding dict entry
if(RefShaDict)
- entry=RefShaDict->GetDictEntryByNumber((*it)->GetGroup(),
- (*it)->GetElement());
+ entry=RefShaDict->GetDictEntryByNumber((*it)->GetGroup(),(*it)->GetElement());
else
entry=NULL;
if( group == 0xfffe )
SkipLoad = true;
- if ( SkipLoad ) {
- Entry->SetUsableLength(0);
+ if ( SkipLoad )
+ {
+ Entry->SetLength(0);
Entry->SetValue("gdcm::Skipped");
return;
}
Entry->SetValue("gdcm::UnRead");
return;
}
- Entry->SetValue(NewValue);
+
+ if( (vr == "UI") ) // Because of correspondance with the VR dic
+ Entry->SetValue(NewValue.c_str());
+ else
+ Entry->SetValue(NewValue);
}
/**
{
if(i!=0)
s << '\\';
- NewInt32=(val[4*i+0]&0xFF)+((val[4*i+1]&0xFF)<<8)+((val[4*i+2]&0xFF)<<16)+((val[4*i+3]&0xFF)<<24);
+ NewInt32= (val[4*i+0]&0xFF)+((val[4*i+1]&0xFF)<<8)+
+ ((val[4*i+2]&0xFF)<<16)+((val[4*i+3]&0xFF)<<24);
NewInt32=SwapLong(NewInt32);
s << NewInt32;
}
std::string vr=Entry->GetVR();
std::ostringstream s;
std::vector<std::string> tokens;
- unsigned char *ptr;
if (vr == "US" || vr == "SS")
{
{
Entry->SetReadLength(FoundLength); // will be updated only if a bug is found
- if ( FoundLength == 0xffffffff) {
+ if ( FoundLength == 0xffffffff)
+ {
FoundLength = 0;
}
/**
* \ingroup gdcmParser
* \brief Request a new virtual dict entry to the dict set
- * @param group group of the underlying DictEntry
- * @param element element of the underlying DictEntry
- * @param vr VR of the underlying DictEntry
- * @param fourth owner group
- * @param name english name
+ * @param group group of the underlying DictEntry
+ * @param elem element of the underlying DictEntry
+ * @param vr VR of the underlying DictEntry
+ * @param fourth owner group
+ * @param name english name
*/
gdcmDictEntry *gdcmParser::NewVirtualDictEntry(guint16 group, guint16 element,
std::string vr,