+int gdcmHeader::SetPubElValByNumber(string content, guint16 group,
+ guint16 element)
+{
+ return ( PubElValSet.SetElValueByNumber (content, group, element) );
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief Accesses an existing gdcmElValue in the PubElValSet 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 ( PubElValSet.SetElValueByName (content, TagName) );
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief Accesses an existing gdcmElValue in the PubElValSet of this instance
+ * through it's (group, element) and modifies it's length with
+ * the given value.
+ * \warning Use with extreme caution.
+ * @param length new length to substitute with
+ * @param group group of the ElVal to modify
+ * @param element element of the ElVal to modify
+ * @return 1 on success, 0 otherwise.
+ */
+
+int gdcmHeader::SetPubElValLengthByNumber(guint32 length, guint16 group,
+ guint16 element) {
+ return ( PubElValSet.SetElValueLengthByNumber (length, group, element) );
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief Accesses an existing gdcmElValue in the ShaElValSet 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
+ * @return 1 on success, 0 otherwise.
+ */
+int gdcmHeader::SetShaElValByNumber(string content,
+ guint16 group, guint16 element) {
+ return ( ShaElValSet.SetElValueByNumber (content, group, element) );
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief Accesses an existing gdcmElValue in the ShaElValSet 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 ( ShaElValSet.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);
+ PubElValSet.Add(newElValue);
+ }
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief Retrieve the number of columns of image.
+ * @return The encountered size when found, 0 by default.
+ */
+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.
+ string StrSize = GetPubElValByNumber(0x0028,0x0011);
+ if (StrSize == "gdcm::Unfound")
+ return 0;
+ return atoi(StrSize.c_str());
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief Retrieve the number of lines of image.
+ * \warning The defaulted value is 1 as opposed to gdcmHeader::GetXSize()
+ * @return The encountered size when found, 1 by default.
+ */
+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.
+ string StrSize = GetPubElValByNumber(0x0028,0x0010);
+ if (StrSize != "gdcm::Unfound")
+ return atoi(StrSize.c_str());
+ if ( IsDicomV3() )
+ return 0;
+ else
+ // The Rows (0028,0010) entry is optional for ACR/NEMA. It might
+ // hence be a signal (1d image). So we default to 1:
+ return 1;
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief Retrieve the number of planes of volume or the number
+ * of frames of a multiframe.
+ * \warning When present we consider the "Number of Frames" as the third
+ * dimension. When absent we consider the third dimension as
+ * being the "Planes" tag content.
+ * @return The encountered size when found, 1 by default.
+ */
+int gdcmHeader::GetZSize(void) {
+ // Both in DicomV3 and ACR/Nema the consider the "Number of Frames"
+ // as the third dimension.
+ string StrSize = GetPubElValByNumber(0x0028,0x0008);
+ if (StrSize != "gdcm::Unfound")
+ return atoi(StrSize.c_str());
+
+ // We then consider the "Planes" entry as the third dimension [we
+ // cannot retrieve by name since "Planes tag is present both in
+ // IMG (0028,0012) and OLY (6000,0012) sections of the dictionary].
+ StrSize = GetPubElValByNumber(0x0028,0x0012);
+ if (StrSize != "gdcm::Unfound")
+ return atoi(StrSize.c_str());
+ return 1;
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief Build the Pixel Type of the image.
+ * Possible values are:
+ * - U8 unsigned 8 bit,
+ * - S8 signed 8 bit,
+ * - U16 unsigned 16 bit,
+ * - S16 signed 16 bit,
+ * - U32 unsigned 32 bit,
+ * - S32 signed 32 bit,
+ * \warning 12 bit images appear as 16 bit.
+ * @return
+ */
+string gdcmHeader::GetPixelType(void) {
+ string BitsAlloc;
+ BitsAlloc = GetElValByName("Bits Allocated");
+ if (BitsAlloc == "gdcm::Unfound") {
+ dbg.Verbose(0, "gdcmHeader::GetPixelType: unfound Bits Allocated");
+ BitsAlloc = string("16");
+ }
+ if (BitsAlloc == "12")
+ BitsAlloc = string("16");
+
+ string Signed;
+ Signed = GetElValByName("Pixel Representation");
+ if (Signed == "gdcm::Unfound") {
+ dbg.Verbose(0, "gdcmHeader::GetPixelType: unfound Pixel Representation");
+ BitsAlloc = string("0");
+ }
+ if (Signed == "0")
+ Signed = string("U");
+ else
+ Signed = string("S");
+
+ return( BitsAlloc + Signed);
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief This predicate, based on hopefully reasonnable heuristics,
+ * decides whether or not the current gdcmHeader was properly parsed
+ * and contains the mandatory information for being considered as
+ * a well formed and usable image.
+ * @return true when gdcmHeader is the one of a reasonable Dicom file,
+ * false otherwise.
+ */
+bool gdcmHeader::IsReadable(void) {
+ if ( GetElValByName("Image Dimensions") != "gdcm::Unfound"
+ && atoi(GetElValByName("Image Dimensions").c_str()) > 4 ) {
+ return false;
+ }
+ if ( GetElValByName("Bits Allocated") == "gdcm::Unfound" )
+ return false;
+ if ( GetElValByName("Bits Stored") == "gdcm::Unfound" )
+ return false;
+ if ( GetElValByName("High Bit") == "gdcm::Unfound" )
+ return false;
+ if ( GetElValByName("Pixel Representation") == "gdcm::Unfound" )
+ return false;
+ return true;
+}
+
+/**
+ * \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.
+ * \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 = PubElValSet.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);
+ PubElValSet.Add(NewElVal);
+ return NewElVal;
+