Program: gdcm
Module: $RCSfile: gdcmHeader.cxx,v $
Language: C++
- Date: $Date: 2004/06/21 04:18:25 $
- Version: $Revision: 1.166 $
+ Date: $Date: 2004/06/28 16:00:18 $
+ Version: $Revision: 1.174 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
// Constructor / Destructor
/**
* \brief Constructor
- * @param InFilename name of the file whose header we want to analyze
+ * @param filename name of the file whose header we want to analyze
* @param exception_on_error whether we want to throw an exception or not
* @param enable_sequences = true to allow the header
* to be parsed *inside* the SeQuences, when they have an actual length
bool enable_sequences,
bool ignore_shadow):
gdcmDocument(filename,exception_on_error,enable_sequences,ignore_shadow)
-{
-/*
- typedef struct {
- guint32 totalSQlength;
- guint32 alreadyParsedlength;
- } pileElem;
-*/
-
+{
// for some ACR-NEMA images GrPixel, NumPixel is *not* 7fe0,0010
// We may encounter the 'RETired' (0x0028, 0x0200) tag
// (Image Location") . This Element contains the number of
* \ingroup gdcmHeader
* \brief Canonical destructor.
*/
-gdcmHeader::~gdcmHeader (void) {
+gdcmHeader::~gdcmHeader () {
+}
+
+
+/**
+ * \brief Performs some consistency checking on various 'File related'
+ * (as opposed to 'DicomDir related') entries
+ * then writes in a file all the (Dicom Elements) included the Pixels
+ * @param fp file pointer on an already open file
+ * @param filetype Type of the File to be written
+ * (ACR-NEMA, ExplicitVR, ImplicitVR)
+ */
+void gdcmHeader::Write(FILE* fp,FileType filetype) {
+
+ // Bits Allocated
+ if ( GetEntryByNumber(0x0028,0x0100) == "12") {
+ SetEntryByNumber("16", 0x0028,0x0100);
+ }
+
+ // correct Pixel group Length if necessary
+
+ // TODO : create a gdcmHeader::Write method and move this part.
+ // (only gdcmHeader knows GrPixel, NumPixel)
+
+ int i_lgPix = GetEntryLengthByNumber(GrPixel, NumPixel);
+ if (i_lgPix != -2) { // no (GrPixel, NumPixel) element
+ char * dumm = new char[20];
+ sprintf(dumm ,"%d", i_lgPix+12);
+ std::string s_lgPix = dumm;
+ delete dumm;
+ ReplaceOrCreateByNumber(s_lgPix,GrPixel, 0x0000);
+ }
+
+ // Drop Palette Color, if necessary
+
+ if ( GetEntryByNumber(0x0028,0x0002).c_str()[0] == '3' ) {
+ // if SamplesPerPixel = 3, sure we don't need any LUT !
+ // Drop 0028|1101, 0028|1102, 0028|1103
+ // Drop 0028|1201, 0028|1202, 0028|1203
+
+ gdcmDocEntry *e;
+ e=GetDocEntryByNumber(0x0028,0x01101);
+ if (e)
+ RemoveEntry(e);
+ e=GetDocEntryByNumber(0x0028,0x1102);
+ if (e)
+ RemoveEntry(e);
+ e=GetDocEntryByNumber(0x0028,0x1103);
+
+ if (e)
+ RemoveEntry(e);
+ e=GetDocEntryByNumber(0x0028,0x01201);
+ if (e)
+ RemoveEntry(e);
+ e=GetDocEntryByNumber(0x0028,0x1202);
+ if (e)
+ RemoveEntry(e);
+ e=GetDocEntryByNumber(0x0028,0x1203);
+ if (e)
+ RemoveEntry(e);
+ }
+ gdcmDocument::Write(fp,filetype);
}
//-----------------------------------------------------------------------------
* @return true when gdcmHeader is the one of a reasonable Dicom/Acr file,
* false otherwise.
*/
-bool gdcmHeader::IsReadable(void) {
+bool gdcmHeader::IsReadable() {
if(!gdcmDocument::IsReadable()) {
return false;
}
* @return The encountered size when found, 0 by default.
* 0 means the file is NOT USABLE. The caller will have to check
*/
-int gdcmHeader::GetXSize(void) {
+int gdcmHeader::GetXSize() {
std::string StrSize;
StrSize = GetEntryByNumber(0x0028,0x0011);
if (StrSize == GDCM_UNFOUND)
* \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
- * (The ACR-MEMA file contains a Signal, not an Image).
+ * (The ACR-NEMA file contains a Signal, not an Image).
*/
-int gdcmHeader::GetYSize(void) {
+int gdcmHeader::GetYSize() {
std::string StrSize = GetEntryByNumber(0x0028,0x0010);
if (StrSize != GDCM_UNFOUND)
return atoi(StrSize.c_str());
* being the ACR-NEMA "Planes" tag content.
* @return The encountered size when found, 1 by default (single image).
*/
-int gdcmHeader::GetZSize(void) {
+int gdcmHeader::GetZSize() {
// Both DicomV3 and ACR/Nema consider the "Number of Frames"
// as the third dimension.
std::string StrSize = GetEntryByNumber(0x0028,0x0008);
if (HasLUT()) // PALETTE COLOR is NOT enough
return 3;
else
- return 1;
+ return 1;
}
-
- //beware of trailing space at end of string
+
+ //beware of trailing space at end of string
if (PhotometricInterpretation.find(GDCM_UNFOUND) <
PhotometricInterpretation.length() ||
PhotometricInterpretation.find("MONOCHROME1") <
* \brief gets the info from 0008,0060 : Modality
* @return Modality Type
*/
-ModalityType gdcmHeader::GetModality(void) {
+ModalityType gdcmHeader::GetModality() {
// 0008 0060 CS ID Modality
std::string StrModality = GetEntryByNumber(0x0008,0x0060);
if (StrModality != GDCM_UNFOUND) {
* @return The encountered number of Bits Allocated, 0 by default.
* 0 means the file is NOT USABLE. The caller has to check it !
*/
-int gdcmHeader::GetBitsAllocated(void) {
+int gdcmHeader::GetBitsAllocated() {
std::string StrSize = GetEntryByNumber(0x0028,0x0100);
if (StrSize == GDCM_UNFOUND)
return 0; // It's supposed to be mandatory
* @return The encountered number of Samples Per Pixel, 1 by default.
* (Gray level Pixels)
*/
-int gdcmHeader::GetSamplesPerPixel(void) {
+int gdcmHeader::GetSamplesPerPixel() {
std::string StrSize = GetEntryByNumber(0x0028,0x0002);
if (StrSize == GDCM_UNFOUND)
return 1; // Well, it's supposed to be mandatory ...
* (0 : RGB Pixels , 1 : R Plane + G Plane + B Plane)
* @return The encountered Planar Configuration, 0 by default.
*/
-int gdcmHeader::GetPlanarConfiguration(void) {
+int gdcmHeader::GetPlanarConfiguration() {
std::string StrSize = GetEntryByNumber(0x0028,0x0006);
if (StrSize == GDCM_UNFOUND)
return 0;
* of *image* pixels (not *icone image* pixels, if any !)
* @return Pixel Offset
*/
-size_t gdcmHeader::GetPixelOffset(void) {
+size_t gdcmHeader::GetPixelOffset() {
gdcmDocEntry* PixelElement = GetDocEntryByNumber(GrPixel,NumPixel);
* -in case of embeded compressed image-)
* 0 : NOT USABLE file. The caller has to check.
*/
-size_t gdcmHeader::GetPixelAreaLength(void) {
+size_t gdcmHeader::GetPixelAreaLength() {
gdcmDocEntry* PixelElement = GetDocEntryByNumber(GrPixel,NumPixel);
* when (0028,0004),Photometric Interpretation = [PALETTE COLOR ]
* @ return bit number of each LUT item
*/
-int gdcmHeader::GetLUTNbits(void) {
+int gdcmHeader::GetLUTNbits() {
std::vector<std::string> tokens;
//int LutLength;
//int LutDepth;
* no known Dicom reader deals with them :-(
* @return a RGBA Lookup Table
*/
-unsigned char * gdcmHeader::GetLUTRGBA(void) {
+unsigned char * gdcmHeader::GetLUTRGBA() {
// Not so easy : see
// http://www.barre.nom.fr/medical/dicom2/limitations.html#Color%20Lookup%20Tables
// if Photometric Interpretation # PALETTE COLOR, no LUT to be done
- if (GetEntryByNumber(0x0028,0x0004) != "PALETTE COLOR ") {
+ if (GetEntryByNumber(0x0028,0x0004) != "PALETTE COLOR ") {
return NULL;
}
int lengthR, debR, nbitsR;
std::string LutDescriptionB = GetEntryByNumber(0x0028,0x1103);
if (LutDescriptionB == GDCM_UNFOUND)
return NULL;
-
+
std::vector<std::string> tokens;
tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
GetEntryVoidAreaByNumber(0x0028,0x1202);
unsigned char *lutB = (unsigned char *)
GetEntryVoidAreaByNumber(0x0028,0x1203);
-
+
if (!lutR || !lutG || !lutB ) {
return NULL;
}
* else 1.
* @return The full Transfert Syntax Name (as opposed to Transfert Syntax UID)
*/
-std::string gdcmHeader::GetTransfertSyntaxName(void) {
+std::string gdcmHeader::GetTransfertSyntaxName() {
// use the gdcmTS (TS : Transfert Syntax)
std::string TransfertSyntax = GetEntryByNumber(0x0002,0x0010);
if (TransfertSyntax == GDCM_UNFOUND) {