+string gdcmHeader::GetPubElValRepByName(string TagName) {
+ gdcmElValue* elem = PubElVals.GetElementByName(TagName);
+ if ( !elem )
+ return "gdcm::Unfound";
+ return elem->GetVR();
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief Searches within elements parsed with the SHADOW dictionary
+ * for the element value of a given tag.
+ * @param group Group of the researched tag.
+ * @param element Element of the researched tag.
+ * @return Corresponding element value representation when it exists,
+ * and the string "gdcm::Unfound" otherwise.
+ */
+string gdcmHeader::GetShaElValByNumber(guint16 group, guint16 element) {
+ return ShaElVals.GetElValueByNumber(group, element);
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief Searches within the elements parsed with the SHADOW dictionary
+ * for the element value representation of a given tag.
+ *
+ * Obtaining the VR (Value Representation) might be needed by caller
+ * to convert the string typed content to caller's native type
+ * (think of C++ vs Python). The VR is actually of a higher level
+ * of semantics than just the native C++ type.
+ * @param group Group of the researched tag.
+ * @param element Element of the researched tag.
+ * @return Corresponding element value representation when it exists,
+ * and the string "gdcm::Unfound" otherwise.
+ */
+string gdcmHeader::GetShaElValRepByNumber(guint16 group, guint16 element) {
+ gdcmElValue* elem = ShaElVals.GetElementByNumber(group, element);
+ if ( !elem )
+ return "gdcm::Unfound";
+ return elem->GetVR();
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief Searches within the elements parsed with the shadow dictionary
+ * for an element value of given tag.
+ * @param TagName name of the researched element.
+ * @return Corresponding element value when it exists, and the string
+ * "gdcm::Unfound" otherwise.
+ */
+string gdcmHeader::GetShaElValByName(string TagName) {
+ return ShaElVals.GetElValueByName(TagName);
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief Searches within the elements parsed with the shadow dictionary for
+ * the element value representation of a given tag.
+ *
+ * Obtaining the VR (Value Representation) might be needed by caller
+ * to convert the string typed content to caller's native type
+ * (think of C++ vs Python). The VR is actually of a higher level
+ * of semantics than just the native C++ type.
+ * @param TagName name of the researched element.
+ * @return Corresponding element value representation when it exists,
+ * and the string "gdcm::Unfound" otherwise.
+ */
+string gdcmHeader::GetShaElValRepByName(string TagName) {
+ gdcmElValue* elem = ShaElVals.GetElementByName(TagName);
+ if ( !elem )
+ return "gdcm::Unfound";
+ return elem->GetVR();
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief Searches within elements parsed with the public dictionary
+ * and then within the elements parsed with the shadow dictionary
+ * for the element value of a given tag.
+ * @param group Group of the researched tag.
+ * @param element Element of the researched tag.
+ * @return Corresponding element value representation when it exists,
+ * and the string "gdcm::Unfound" otherwise.
+ */
+string gdcmHeader::GetElValByNumber(guint16 group, guint16 element) {
+ string pub = GetPubElValByNumber(group, element);
+ if (pub.length())
+ return pub;
+ return GetShaElValByNumber(group, element);
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief Searches within elements parsed with the public dictionary
+ * and then within the elements parsed with the shadow dictionary
+ * for the element value representation of a given tag.
+ *
+ * Obtaining the VR (Value Representation) might be needed by caller
+ * to convert the string typed content to caller's native type
+ * (think of C++ vs Python). The VR is actually of a higher level
+ * of semantics than just the native C++ type.
+ * @param group Group of the researched tag.
+ * @param element Element of the researched tag.
+ * @return Corresponding element value representation when it exists,
+ * and the string "gdcm::Unfound" otherwise.
+ */
+string gdcmHeader::GetElValRepByNumber(guint16 group, guint16 element) {
+ string pub = GetPubElValRepByNumber(group, element);
+ if (pub.length())
+ return pub;
+ return GetShaElValRepByNumber(group, element);
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief Searches within elements parsed with the public dictionary
+ * and then within the elements parsed with the shadow dictionary
+ * for the element value of a given tag.
+ * @param TagName name of the researched element.
+ * @return Corresponding element value when it exists,
+ * and the string "gdcm::Unfound" otherwise.
+ */
+string gdcmHeader::GetElValByName(string TagName) {
+ string pub = GetPubElValByName(TagName);
+ if (pub.length())
+ return pub;
+ return GetShaElValByName(TagName);
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief Searches within elements parsed with the public dictionary
+ * and then within the elements parsed with the shadow dictionary
+ * for the element value representation of a given tag.
+ *
+ * Obtaining the VR (Value Representation) might be needed by caller
+ * to convert the string typed content to caller's native type
+ * (think of C++ vs Python). The VR is actually of a higher level
+ * of semantics than just the native C++ type.
+ * @param TagName name of the researched element.
+ * @return Corresponding element value representation when it exists,
+ * and the string "gdcm::Unfound" otherwise.
+ */
+string gdcmHeader::GetElValRepByName(string TagName) {
+ string pub = GetPubElValRepByName(TagName);
+ if (pub.length())
+ return pub;
+ return GetShaElValRepByName(TagName);
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief Accesses an existing gdcmElValue in the PubElVals of this instance
+ * through it's (group, element) and modifies it's content with
+ * the given value.
+ * @param content new value to substitute with
+ * @param group group of the ElVal to modify
+ * @param element element of the ElVal to modify
+ */
+int gdcmHeader::SetPubElValByNumber(string content, guint16 group,
+ guint16 element)
+{
+ return ( PubElVals.SetElValueByNumber (content, group, element) );
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief Accesses an existing gdcmElValue in the PubElVals of this instance
+ * through tag name and modifies it's content with the given value.
+ * @param content new value to substitute with
+ * @param TagName name of the tag to be modified
+ */
+int gdcmHeader::SetPubElValByName(string content, string TagName) {
+ return ( PubElVals.SetElValueByName (content, TagName) );
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief Accesses an existing gdcmElValue in the PubElVals of this instance
+ * through it's (group, element) and modifies it's length with
+ * the given value.
+ * NOT FOR BOZOs !
+ * @param contents new length to substitute with
+ * @param group group of the ElVal to modify
+ * @param element element of the ElVal to modify
+ */
+int gdcmHeader::SetPubElValLengthByNumber(guint32 lgr, guint16 group,
+ guint16 element)
+{
+ return ( PubElVals.SetElValueLengthByNumber (lgr, group, element) );
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief Accesses an existing gdcmElValue in the ShaElVals of this instance
+ * through it's (group, element) and modifies it's content with
+ * the given value.
+ * @param content new value to substitute with
+ * @param group group of the ElVal to modify
+ * @param element element of the ElVal to modify
+ */
+int gdcmHeader::SetShaElValByNumber(string content,
+ guint16 group, guint16 element)
+{
+ return ( ShaElVals.SetElValueByNumber (content, group, element) );
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief Accesses an existing gdcmElValue in the ShaElVals of this instance
+ * through tag name and modifies it's content with the given value.
+ * @param content new value to substitute with
+ * @param TagName name of the tag to be modified
+ */
+int gdcmHeader::SetShaElValByName(string content, string TagName) {
+ return ( ShaElVals.SetElValueByName (content, TagName) );
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief Parses the header of the file but WITHOUT loading element values.
+ */
+void gdcmHeader::ParseHeader(bool exception_on_error) throw(gdcmFormatError) {
+ gdcmElValue * newElValue = (gdcmElValue *)0;
+
+ rewind(fp);
+ CheckSwap();
+ while ( (newElValue = ReadNextElement()) ) {
+ SkipElementValue(newElValue);
+ PubElVals.Add(newElValue);
+ }
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief Once the header is parsed add some gdcm convenience/helper elements
+ * in the gdcmElValSet. For example add:
+ * - gdcmImageType which is an entry containing a short for the
+ * type of image and whose value ranges in
+ * I8 (unsigned 8 bit image)
+ * I16 (unsigned 8 bit image)
+ * IS16 (signed 8 bit image)
+ * - gdcmXsize, gdcmYsize, gdcmZsize whose values are respectively
+ * the ones of the official DICOM fields Rows, Columns and Planes.
+ */
+void gdcmHeader::AddAndDefaultElements(void) {
+ gdcmElValue* NewElVal = (gdcmElValue*)0;
+ string NewVal;
+
+ NewElVal = NewManualElValToPubDict("gdcmXSize", "US");
+ if (!NewElVal) return;
+ NewVal = GetElValByName("Rows");
+ if (NewVal != "gdcm::Unfound")
+ NewElVal->SetValue(NewVal);
+ else
+ NewElVal->SetValue("0");
+
+
+ NewElVal = NewManualElValToPubDict("gdcmYSize", "US");
+ if (!NewElVal) return;
+ NewVal = GetElValByName("Columns");
+ if (NewVal != "gdcm::Unfound")
+ NewElVal->SetValue(NewVal);
+ else
+ NewElVal->SetValue("0");
+
+
+ NewElVal = NewManualElValToPubDict("gdcmZSize", "US");
+ if (!NewElVal) return;
+ NewVal = GetElValByName("Planes");
+ if (NewVal != "gdcm::Unfound")
+ NewElVal->SetValue(NewVal);
+ else
+ NewElVal->SetValue("0");
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief Small utility function that creates a new manually crafted
+ * (as opposed as read from the file) gdcmElValue with user
+ * specified name and adds it to the public tag hash table.
+ * Refer to gdcmHeader::AddAndDefaultElements for a typical usage.
+ * \note A fake TagKey is generated so the PubDict can keep it's coherence.
+ * @param NewTagName The name to be given to this new tag.
+ * @param VR The Value Representation to be given to this new tag.
+ * @ return The newly hand crafted Element Value.
+ */
+gdcmElValue* gdcmHeader::NewManualElValToPubDict(string NewTagName, string VR) {
+ gdcmElValue* NewElVal = (gdcmElValue*)0;
+ guint32 StuffGroup = 0xffff; // Group to be stuffed with additional info
+ guint32 FreeElem = 0;
+ gdcmDictEntry* NewEntry = (gdcmDictEntry*)0;
+
+ FreeElem = PubElVals.GenerateFreeTagKeyInGroup(StuffGroup);
+ if (FreeElem == UINT32_MAX) {
+ dbg.Verbose(1, "gdcmHeader::NewManualElValToPubDict",
+ "Group 0xffff in Public Dict is full");
+ return (gdcmElValue*)0;
+ }
+ NewEntry = new gdcmDictEntry(StuffGroup, FreeElem,
+ VR, "GDCM", NewTagName);
+ NewElVal = new gdcmElValue(NewEntry);
+ PubElVals.Add(NewElVal);
+ return NewElVal;