2 //-----------------------------------------------------------------------------
3 #include "gdcmHeader.h"
4 #include "gdcmGlobal.h"
8 #include "gdcmValEntry.h"
12 //-----------------------------------------------------------------------------
13 // Constructor / Destructor
16 * @param InFilename name of the file whose header we want to analyze
17 * @param exception_on_error whether we want to throw an exception or not
18 * @param enable_sequences = true to allow the header
19 * to be parsed *inside* the SeQuences, when they have an actual length
20 * @param ignore_shadow = true if user wants to skip shadow groups
21 * during parsing, to save memory space
23 gdcmHeader::gdcmHeader(const char *InFilename,
24 bool exception_on_error,
25 bool enable_sequences,
27 gdcmDocument(InFilename,exception_on_error,enable_sequences,ignore_shadow)
31 guint32 totalSQlength;
32 guint32 alreadyParsedlength;
36 // for some ACR-NEMA images GrPixel, NumPixel is *not* 7fe0,0010
37 // We may encounter the 'RETired' (0x0028, 0x0200) tag
38 // (Image Location") . This Element contains the number of
39 // the group that contains the pixel data (hence the "Pixel Data"
40 // is found by indirection through the "Image Location").
41 // Inside the group pointed by "Image Location" the searched element
42 // is conventionally the element 0x0010 (when the norm is respected).
43 // When the "Image Location" is absent we default to group 0x7fe0.
45 // This IS the right place for the code
47 std::string ImageLocation = GetEntryByNumber(0x0028, 0x0200);
48 if ( ImageLocation == GDCM_UNFOUND ) { // Image Location
49 GrPixel = 0x7fe0; // default value
51 GrPixel = (guint16) atoi( ImageLocation.c_str() );
53 if (GrPixel == 0xe07f) // sometimes Image Location value doesn't follow
54 GrPixel = 0x7fe0; // the supposed processor endianity.
55 // see gdcmData/cr172241.dcm
56 if (GrPixel != 0x7fe0)
57 // This is a kludge for old dirty Philips imager.
66 * @param exception_on_error whether we want to throw an exception or not
68 gdcmHeader::gdcmHeader(bool exception_on_error) :
69 gdcmDocument(exception_on_error)
75 * \brief Canonical destructor.
77 gdcmHeader::~gdcmHeader (void) {
80 //-----------------------------------------------------------------------------
84 //-----------------------------------------------------------------------------
89 * \brief This predicate, based on hopefully reasonable heuristics,
90 * decides whether or not the current gdcmParser was properly parsed
91 * and contains the mandatory information for being considered as
92 * a well formed and usable Dicom/Acr File.
93 * @return true when gdcmParser is the one of a reasonable Dicom/Acr file,
96 bool gdcmHeader::IsReadable(void) {
97 if(!gdcmDocument::IsReadable()) {
100 std::string res = GetEntryByNumber(0x0028, 0x0005);
101 if ( res != GDCM_UNFOUND && atoi(res.c_str()) > 4 )
102 return false; // Image Dimensions
103 if ( !GetDocEntryByNumber(0x0028, 0x0100) )
104 return false; // "Bits Allocated"
105 if ( !GetDocEntryByNumber(0x0028, 0x0101) )
106 return false; // "Bits Stored"
107 if ( !GetDocEntryByNumber(0x0028, 0x0102) )
108 return false; // "High Bit"
109 if ( !GetDocEntryByNumber(0x0028, 0x0103) )
110 return false; // "Pixel Representation" i.e. 'Sign'
115 * \ingroup gdcmHeader
116 * \brief Determines if the Transfer Syntax was already encountered
117 * and if it corresponds to a JPEGBaseLineProcess1 one.
118 * @return True when JPEGBaseLineProcess1found. False in all other cases.
120 bool gdcmHeader::IsJPEGBaseLineProcess1TransferSyntax(void) {
121 gdcmDocEntry* Element = GetDocEntryByNumber(0x0002, 0x0010);
124 LoadDocEntrySafe(Element);
126 std::string Transfer = ((gdcmValEntry *)Element)->GetValue();
127 if ( Transfer == "1.2.840.10008.1.2.4.50" )
133 * \ingroup gdcmHeader
134 * \brief Determines if the Transfer Syntax was already encountered
135 * and if it corresponds to a JPEGExtendedProcess2-4 one.
136 * @return True when JPEGExtendedProcess2-4 found. False in all other cases.
138 bool gdcmHeader::IsJPEGExtendedProcess2_4TransferSyntax(void) {
139 gdcmDocEntry* Element = GetDocEntryByNumber(0x0002, 0x0010);
142 LoadDocEntrySafe(Element);
143 return ( ((gdcmValEntry *)Element)->GetValue() == "1.2.840.10008.1.2.4.51" );
147 * \ingroup gdcmHeader
148 * \brief Determines if the Transfer Syntax was already encountered
149 * and if it corresponds to a JPEGExtendeProcess3-5 one.
150 * @return True when JPEGExtendedProcess3-5 found. False in all other cases.
152 bool gdcmHeader::IsJPEGExtendedProcess3_5TransferSyntax(void) {
153 gdcmDocEntry* Element = GetDocEntryByNumber(0x0002, 0x0010);
156 LoadDocEntrySafe(Element);
158 std::string Transfer = ((gdcmValEntry *)Element)->GetValue();
159 if ( Transfer == "1.2.840.10008.1.2.4.52" )
165 * \ingroup gdcmHeader
166 * \brief Determines if the Transfer Syntax was already encountered
167 * and if it corresponds to a JPEGSpectralSelectionProcess6-8 one.
168 * @return True when JPEGSpectralSelectionProcess6-8 found. False in all
171 bool gdcmHeader::IsJPEGSpectralSelectionProcess6_8TransferSyntax(void) {
172 gdcmDocEntry* Element = GetDocEntryByNumber(0x0002, 0x0010);
175 LoadDocEntrySafe(Element);
177 std::string Transfer = ((gdcmValEntry *)Element)->GetValue();
178 if ( Transfer == "1.2.840.10008.1.2.4.53" )
184 * \ingroup gdcmHeader
185 * \brief Determines if the Transfer Syntax was already encountered
186 * and if it corresponds to a RLE Lossless one.
187 * @return True when RLE Lossless found. False in all
190 bool gdcmHeader::IsRLELossLessTransferSyntax(void) {
191 gdcmDocEntry* Element = GetDocEntryByNumber(0x0002, 0x0010);
194 LoadDocEntrySafe(Element);
196 std::string Transfer = ((gdcmValEntry *)Element)->GetValue();
197 if ( Transfer == "1.2.840.10008.1.2.5" ) {
204 * \ingroup gdcmHeader
205 * \brief Determines if Transfer Syntax was already encountered
206 * and if it corresponds to a JPEG Lossless one.
207 * @return True when RLE Lossless found. False in all
210 bool gdcmHeader::IsJPEGLossless(void) {
211 gdcmDocEntry* Element = GetDocEntryByNumber(0x0002, 0x0010);
212 // faire qq chose d'intelligent a la place de ça
215 LoadDocEntrySafe(Element);
217 const char * Transfert = ((gdcmValEntry *)Element)->GetValue().c_str();
219 if ( memcmp(Transfert+strlen(Transfert)-2 ,"70",2)==0) return true;
220 if ( memcmp(Transfert+strlen(Transfert)-2 ,"55",2)==0) return true;
222 if (((gdcmValEntry *)Element)->GetValue() == "1.2.840.10008.1.2.4.57") return true;
228 * \ingroup gdcmHeader
229 * \brief Determines if the Transfer Syntax was already encountered
230 * and if it corresponds to a JPEG2000 one
231 * @return True when JPEG2000 (Lossly or LossLess) found. False in all
234 bool gdcmHeader::IsJPEG2000(void) {
235 gdcmDocEntry* Element = GetDocEntryByNumber(0x0002, 0x0010);
238 LoadDocEntrySafe(Element);
240 std::string Transfer = ((gdcmValEntry *)Element)->GetValue();
241 if ( (Transfer == "1.2.840.10008.1.2.4.90")
242 || (Transfer == "1.2.840.10008.1.2.4.91") )
248 * \ingroup gdcmHeader
249 * \brief Predicate for dicom version 3 file.
250 * @return True when the file is a dicom version 3.
252 bool gdcmHeader::IsDicomV3(void) {
253 // Checking if Transfert Syntax exists is enough
254 // Anyway, it's to late check if the 'Preamble' was found ...
255 // And ... would it be a rich idea to check ?
256 // (some 'no Preamble' DICOM images exist !)
257 return (GetDocEntryByNumber(0x0002, 0x0010) != NULL);
261 * \ingroup gdcmHeader
262 * \brief Retrieve the number of columns of image.
263 * @return The encountered size when found, 0 by default.
264 * 0 means the file is NOT USABLE. The caller will have to check
266 int gdcmHeader::GetXSize(void) {
268 StrSize = GetEntryByNumber(0x0028,0x0011);
269 if (StrSize == GDCM_UNFOUND)
271 return atoi(StrSize.c_str());
275 * \ingroup gdcmHeader
276 * \brief Retrieve the number of lines of image.
277 * \warning The defaulted value is 1 as opposed to gdcmHeader::GetXSize()
278 * @return The encountered size when found, 1 by default
279 * (The ACR-MEMA file contains a Signal, not an Image).
281 int gdcmHeader::GetYSize(void) {
282 std::string StrSize = GetEntryByNumber(0x0028,0x0010);
283 if (StrSize != GDCM_UNFOUND)
284 return atoi(StrSize.c_str());
288 // The Rows (0028,0010) entry was optional for ACR/NEMA. It might
289 // hence be a signal (1d image). So we default to 1:
294 * \ingroup gdcmHeader
295 * \brief Retrieve the number of planes of volume or the number
296 * of frames of a multiframe.
297 * \warning When present we consider the "Number of Frames" as the third
298 * dimension. When absent we consider the third dimension as
299 * being the ACR-NEMA "Planes" tag content.
300 * @return The encountered size when found, 1 by default (single image).
302 int gdcmHeader::GetZSize(void) {
303 // Both DicomV3 and ACR/Nema consider the "Number of Frames"
304 // as the third dimension.
305 std::string StrSize = GetEntryByNumber(0x0028,0x0008);
306 if (StrSize != GDCM_UNFOUND)
307 return atoi(StrSize.c_str());
309 // We then consider the "Planes" entry as the third dimension
310 StrSize = GetEntryByNumber(0x0028,0x0012);
311 if (StrSize != GDCM_UNFOUND)
312 return atoi(StrSize.c_str());
317 * \ingroup gdcmHeader
318 * \brief Retrieve the number of Bits Stored (actually used)
319 * (as opposite to number of Bits Allocated)
320 * @return The encountered number of Bits Stored, 0 by default.
321 * 0 means the file is NOT USABLE. The caller has to check it !
323 int gdcmHeader::GetBitsStored(void) {
324 std::string StrSize = GetEntryByNumber(0x0028,0x0101);
325 if (StrSize == GDCM_UNFOUND)
326 return 0; // It's supposed to be mandatory
327 // the caller will have to check
328 return atoi(StrSize.c_str());
332 * \ingroup gdcmHeader
333 * \brief Retrieve the number of Bits Allocated
334 * (8, 12 -compacted ACR-NEMA files, 16, ...)
335 * @return The encountered number of Bits Allocated, 0 by default.
336 * 0 means the file is NOT USABLE. The caller has to check it !
338 int gdcmHeader::GetBitsAllocated(void) {
339 std::string StrSize = GetEntryByNumber(0x0028,0x0100);
340 if (StrSize == GDCM_UNFOUND)
341 return 0; // It's supposed to be mandatory
342 // the caller will have to check
343 return atoi(StrSize.c_str());
347 * \ingroup gdcmHeader
348 * \brief Retrieve the number of Samples Per Pixel
349 * (1 : gray level, 3 : RGB -1 or 3 Planes-)
350 * @return The encountered number of Samples Per Pixel, 1 by default.
351 * (Gray level Pixels)
353 int gdcmHeader::GetSamplesPerPixel(void) {
354 std::string StrSize = GetEntryByNumber(0x0028,0x0002);
355 if (StrSize == GDCM_UNFOUND)
356 return 1; // Well, it's supposed to be mandatory ...
357 // but sometimes it's missing : *we* assume Gray pixels
358 return atoi(StrSize.c_str());
362 * \ingroup gdcmHeader
363 * \brief Retrieve the Planar Configuration for RGB images
364 * (0 : RGB Pixels , 1 : R Plane + G Plane + B Plane)
365 * @return The encountered Planar Configuration, 0 by default.
367 int gdcmHeader::GetPlanarConfiguration(void) {
368 std::string StrSize = GetEntryByNumber(0x0028,0x0006);
369 if (StrSize == GDCM_UNFOUND)
371 return atoi(StrSize.c_str());
375 * \ingroup gdcmHeader
376 * \brief Return the size (in bytes) of a single pixel of data.
377 * @return The size in bytes of a single pixel of data; 0 by default
378 * 0 means the file is NOT USABLE; the caller will have to check
380 int gdcmHeader::GetPixelSize(void) {
381 std::string PixelType = GetPixelType();
382 if (PixelType == "8U" || PixelType == "8S")
384 if (PixelType == "16U" || PixelType == "16S")
386 if (PixelType == "32U" || PixelType == "32S")
388 if (PixelType == "FD")
390 dbg.Verbose(0, "gdcmHeader::GetPixelSize: Unknown pixel type");
395 * \ingroup gdcmHeader
396 * \brief Build the Pixel Type of the image.
397 * Possible values are:
398 * - 8U unsigned 8 bit,
400 * - 16U unsigned 16 bit,
401 * - 16S signed 16 bit,
402 * - 32U unsigned 32 bit,
403 * - 32S signed 32 bit,
404 * - FD floating double 64 bits (Not kosher DICOM, but so usefull!)
405 * \warning 12 bit images appear as 16 bit.
406 * 24 bit images appear as 8 bit
407 * @return 0S if nothing found. NOT USABLE file. The caller has to check
409 std::string gdcmHeader::GetPixelType(void) {
410 std::string BitsAlloc = GetEntryByNumber(0x0028, 0x0100); // Bits Allocated
411 if (BitsAlloc == GDCM_UNFOUND) {
412 dbg.Verbose(0, "gdcmHeader::GetPixelType: unfound Bits Allocated");
413 BitsAlloc = std::string("16");
415 if (BitsAlloc == "64") // )
417 if (BitsAlloc == "12") // It will be unpacked
418 BitsAlloc = std::string("16");
419 else if (BitsAlloc == "24") // (in order no to be messed up
420 BitsAlloc = std::string("8"); // by old RGB images)
422 std::string Signed = GetEntryByNumber(0x0028, 0x0103); // "Pixel Representation"
423 if (Signed == GDCM_UNFOUND) {
424 dbg.Verbose(0, "gdcmHeader::GetPixelType: unfound Pixel Representation");
425 BitsAlloc = std::string("0");
428 Signed = std::string("U");
430 Signed = std::string("S");
432 return( BitsAlloc + Signed);
437 * \ingroup gdcmHeader
438 * \brief Recover the offset (from the beginning of the file)
439 * of *image* pixels (not *icone image* pixels, if any !)
440 * @return Pixel Offset
442 size_t gdcmHeader::GetPixelOffset(void) {
444 gdcmDocEntry* PixelElement = GetDocEntryByNumber(GrPixel,NumPixel);
447 return PixelElement->GetOffset();
450 std::cout << "Big trouble : Pixel Element ("
451 << std::hex << GrPixel<<","<< NumPixel<< ") NOT found"
457 // TODO : unify those two (previous one and next one)
459 * \ingroup gdcmHeader
460 * \brief Recover the pixel area length (in Bytes)
461 * @return Pixel Element Length, as stored in the header
462 * (NOT the memory space necessary to hold the Pixels
463 * -in case of embeded compressed image-)
464 * 0 : NOT USABLE file. The caller has to check.
466 size_t gdcmHeader::GetPixelAreaLength(void) {
468 gdcmDocEntry* PixelElement = GetDocEntryByNumber(GrPixel,NumPixel);
471 return PixelElement->GetLength();
474 std::cout << "Big trouble : Pixel Element ("
475 << std::hex << GrPixel<<","<< NumPixel<< ") NOT found"
483 * \ingroup gdcmHeader
484 * \brief tells us if LUT are used
485 * \warning Right now, 'Segmented xxx Palette Color Lookup Table Data'
486 * are NOT considered as LUT, since nobody knows
487 * how to deal with them
488 * Please warn me if you know sbdy that *does* know ... jprx
489 * @return true if LUT Descriptors and LUT Tables were found
491 bool gdcmHeader::HasLUT(void) {
493 // Check the presence of the LUT Descriptors, and LUT Tables
495 if ( !GetDocEntryByNumber(0x0028,0x1101) )
497 // LutDescriptorGreen
498 if ( !GetDocEntryByNumber(0x0028,0x1102) )
501 if ( !GetDocEntryByNumber(0x0028,0x1103) )
503 // Red Palette Color Lookup Table Data
504 if ( !GetDocEntryByNumber(0x0028,0x1201) )
506 // Green Palette Color Lookup Table Data
507 if ( !GetDocEntryByNumber(0x0028,0x1202) )
509 // Blue Palette Color Lookup Table Data
510 if ( !GetDocEntryByNumber(0x0028,0x1203) )
512 // FIXME : (0x0028,0x3006) : LUT Data (CTX dependent)
513 // NOT taken into account, but we don't know how to use it ...
518 * \ingroup gdcmHeader
519 * \brief gets the info from 0028,1101 : Lookup Table Desc-Red
521 * @return Lookup Table number of Bits , 0 by default
522 * when (0028,0004),Photometric Interpretation = [PALETTE COLOR ]
523 * @ return bit number of each LUT item
525 int gdcmHeader::GetLUTNbits(void) {
526 std::vector<std::string> tokens;
530 //Just hope Lookup Table Desc-Red = Lookup Table Desc-Red = Lookup Table Desc-Blue
531 // Consistency already checked in GetLUTLength
532 std::string LutDescription = GetEntryByNumber(0x0028,0x1101);
533 if (LutDescription == GDCM_UNFOUND)
535 tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
536 Tokenize (LutDescription, tokens, "\\");
537 //LutLength=atoi(tokens[0].c_str());
538 //LutDepth=atoi(tokens[1].c_str());
539 LutNbits=atoi(tokens[2].c_str());
545 * \ingroup gdcmHeader
546 * \brief builts Red/Green/Blue/Alpha LUT from Header
547 * when (0028,0004),Photometric Interpretation = [PALETTE COLOR ]
548 * and (0028,1101),(0028,1102),(0028,1102)
549 * - xxx Palette Color Lookup Table Descriptor - are found
550 * and (0028,1201),(0028,1202),(0028,1202)
551 * - xxx Palette Color Lookup Table Data - are found
552 * \warning does NOT deal with :
553 * 0028 1100 Gray Lookup Table Descriptor (Retired)
554 * 0028 1221 Segmented Red Palette Color Lookup Table Data
555 * 0028 1222 Segmented Green Palette Color Lookup Table Data
556 * 0028 1223 Segmented Blue Palette Color Lookup Table Data
557 * no known Dicom reader deals with them :-(
558 * @return a RGBA Lookup Table
560 unsigned char * gdcmHeader::GetLUTRGBA(void) {
562 // http://www.barre.nom.fr/medical/dicom2/limitations.html#Color%20Lookup%20Tables
564 // if Photometric Interpretation # PALETTE COLOR, no LUT to be done
565 if (GetEntryByNumber(0x0028,0x0004) != "PALETTE COLOR ") {
568 int lengthR, debR, nbitsR;
569 int lengthG, debG, nbitsG;
570 int lengthB, debB, nbitsB;
572 // Get info from Lut Descriptors
573 // (the 3 LUT descriptors may be different)
574 std::string LutDescriptionR = GetEntryByNumber(0x0028,0x1101);
575 if (LutDescriptionR == GDCM_UNFOUND)
577 std::string LutDescriptionG = GetEntryByNumber(0x0028,0x1102);
578 if (LutDescriptionG == GDCM_UNFOUND)
580 std::string LutDescriptionB = GetEntryByNumber(0x0028,0x1103);
581 if (LutDescriptionB == GDCM_UNFOUND)
584 std::vector<std::string> tokens;
586 tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
587 Tokenize (LutDescriptionR, tokens, "\\");
588 lengthR=atoi(tokens[0].c_str()); // Red LUT length in Bytes
589 debR =atoi(tokens[1].c_str()); // subscript of the first Lut Value
590 nbitsR =atoi(tokens[2].c_str()); // Lut item size (in Bits)
593 tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
594 Tokenize (LutDescriptionG, tokens, "\\");
595 lengthG=atoi(tokens[0].c_str()); // Green LUT length in Bytes
596 debG =atoi(tokens[1].c_str()); // subscript of the first Lut Value
597 nbitsG =atoi(tokens[2].c_str()); // Lut item size (in Bits)
600 tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
601 Tokenize (LutDescriptionB, tokens, "\\");
602 lengthB=atoi(tokens[0].c_str()); // Blue LUT length in Bytes
603 debB =atoi(tokens[1].c_str()); // subscript of the first Lut Value
604 nbitsB =atoi(tokens[2].c_str()); // Lut item size (in Bits)
607 // Load LUTs into memory, (as they were stored on disk)
608 unsigned char *lutR = (unsigned char *)
609 GetEntryVoidAreaByNumber(0x0028,0x1201);
610 unsigned char *lutG = (unsigned char *)
611 GetEntryVoidAreaByNumber(0x0028,0x1202);
612 unsigned char *lutB = (unsigned char *)
613 GetEntryVoidAreaByNumber(0x0028,0x1203);
615 if (!lutR || !lutG || !lutB ) {
618 // forge the 4 * 8 Bits Red/Green/Blue/Alpha LUT
620 unsigned char *LUTRGBA = new unsigned char[1024]; // 256 * 4 (R, G, B, Alpha)
624 memset(LUTRGBA, 0, 1024);
627 std::string str_nb = GetEntryByNumber(0x0028,0x0100);
628 if (str_nb == GDCM_UNFOUND ) {
631 nb = atoi(str_nb.c_str() );
635 if (nbitsR==16 && nb==8) // when LUT item size is different than pixel size
636 mult=2; // high byte must be = low byte
637 else // See PS 3.3-2003 C.11.1.1.2 p 619
640 // if we get a black image, let's just remove the '+1'
641 // from 'i*mult+1' and check again
642 // if it works, we shall have to check the 3 Palettes
643 // to see which byte is ==0 (first one, or second one)
645 // We give up the checking to avoid some (useless ?)overhead
646 // (optimistic asumption)
651 for(i=0;i<lengthR;i++) {
656 for(i=0;i<lengthG;i++) {
661 for(i=0;i<lengthB;i++) {
667 *a = 1; // Alpha component
671 //How to free the now useless LUTs?
672 //free(LutR); free(LutB); free(LutG); // Seg Fault when used
677 * \ingroup gdcmHeader
678 * \brief gets the info from 0002,0010 : Transfert Syntax and gdcmTS
680 * @return the full Transfert Syntax Name (as oposite to Transfert Syntax UID)
682 std::string gdcmHeader::GetTransfertSyntaxName(void) {
683 // use the gdcmTS (TS : Transfert Syntax)
684 std::string TransfertSyntax = GetEntryByNumber(0x0002,0x0010);
685 if (TransfertSyntax == GDCM_UNFOUND) {
686 dbg.Verbose(0, "gdcmHeader::GetTransfertSyntaxName: unfound Transfert Syntax (0002,0010)");
687 return "Uncompressed ACR-NEMA";
689 // we do it only when we need it
690 gdcmTS * ts = gdcmGlobal::GetTS();
691 std::string tsName=ts->GetValue(TransfertSyntax);
692 //delete ts; // Seg Fault when deleted ?!
697 * \ingroup gdcmHeader
698 * \brief Sets the Pixel Area size in the Header
699 * --> not-for-rats function
700 * @param ImageDataSize new Pixel Area Size
701 * warning : nothing else is checked
703 void gdcmHeader::SetImageDataSize(size_t ImageDataSize) {
704 std::string content1;
707 // Assumes DocEntry (GrPixel, NumPixel) is unique ...
708 //\todo deal with multiplicity (see gdcmData/icone.dcm)
709 sprintf(car,"%d",ImageDataSize);
711 gdcmDocEntry *a = GetDocEntryByNumber(GrPixel, NumPixel);
712 a->SetLength(ImageDataSize);
715 sprintf(car,"%d",ImageDataSize);
717 SetEntryByNumber(content1, GrPixel, NumPixel);
722 * \ingroup gdcmHeader
723 * \brief compares 2 Headers, according to DICOMDIR rules
724 * --> not-for-rats function
725 * \warning does NOT work with ACR-NEMA files
726 * \todo find a trick to solve the pb (use RET fields ?)
728 * @return true if 'smaller'
730 bool gdcmHeader::operator<(gdcmHeader &header){
734 s1=this->GetEntryByNumber(0x0010,0x0010);
735 s2=header.GetEntryByNumber(0x0010,0x0010);
743 s1=this->GetEntryByNumber(0x0010,0x0020);
744 s2=header.GetEntryByNumber(0x0010,0x0020);
751 // Study Instance UID
752 s1=this->GetEntryByNumber(0x0020,0x000d);
753 s2=header.GetEntryByNumber(0x0020,0x000d);
760 // Serie Instance UID
761 s1=this->GetEntryByNumber(0x0020,0x000e);
762 s2=header.GetEntryByNumber(0x0020,0x000e);
772 // Replaced by gdcmDocument::WriteEntry
774 bool gdcmHeader::WriteEntry(gdcmDocEntry *tag, FILE *_fp,FileType type)
776 cout << " gdcmHeader::WriteEntry : entree " << endl;
777 guint32 length = tag->GetLength();
779 // The value of a tag MUST (see the DICOM norm) be an odd number of
780 // bytes. When this is not the case, pad with an additional byte:
783 // tag->SetValue(tag->GetValue()+"\0"); // to go on compiling
784 tag->SetLength(tag->GetReadLength()+1);
787 WriteEntryTagVRLength(tag, _fp, type);
789 // Pixels are never loaded in the element !
790 // we stop writting when Pixel are processed
791 // FIX : we loose trailing elements (RAB, right now)
792 guint16 el = tag->GetElement();
793 guint16 group = tag->GetGroup();
794 WriteEntryValue(tag, _fp, type);
798 //-----------------------------------------------------------------------------
802 * \ingroup gdcmHeader
803 * \brief anonymize a Header (removes Patient's personal info)
804 * (read the code to see which ones ...)
806 bool gdcmHeader::anonymizeHeader() {
808 gdcmDocEntry *patientNameHE = GetDocEntryByNumber (0x0010, 0x0010);
809 // gdcmDocEntry *patientIDHE = GetDocEntryByNumber (0x0010, 0x0020);
811 ReplaceIfExistByNumber (" ",0x0010, 0x2154); // Telephone
812 ReplaceIfExistByNumber (" ",0x0010, 0x1040); // Adress
813 ReplaceIfExistByNumber (" ",0x0010, 0x0020); // Patient ID
816 std::string StudyInstanceUID = GetEntryByNumber (0x0020, 0x000d);
817 if (StudyInstanceUID !=GDCM_UNFOUND)
818 ReplaceOrCreateByNumber(StudyInstanceUID, 0x0010, 0x0010);
820 ReplaceOrCreateByNumber(std::string("anonymised"), 0x0010, 0x0010);
824 // (if any) remove or replace all the stuff that contains a Date
826 //0008 0012 DA ID Instance Creation Date
827 //0008 0020 DA ID Study Date
828 //0008 0021 DA ID Series Date
829 //0008 0022 DA ID Acquisition Date
830 //0008 0023 DA ID Content Date
831 //0008 0024 DA ID Overlay Date
832 //0008 0025 DA ID Curve Date
833 //0008 002a DT ID Acquisition Datetime
834 //0018 9074 DT ACQ Frame Acquisition Datetime
835 //0018 9151 DT ACQ Frame Reference Datetime
836 //0018 a002 DT ACQ Contribution Date Time
837 //0020 3403 SH REL Modified Image Date (RET)
838 //0032 0032 DA SDY Study Verified Date
839 //0032 0034 DA SDY Study Read Date
840 //0032 1000 DA SDY Scheduled Study Start Date
841 //0032 1010 DA SDY Scheduled Study Stop Date
842 //0032 1040 DA SDY Study Arrival Date
843 //0032 1050 DA SDY Study Completion Date
844 //0038 001a DA VIS Scheduled Admission Date
845 //0038 001c DA VIS Scheduled Discharge Date
846 //0038 0020 DA VIS Admitting Date
847 //0038 0030 DA VIS Discharge Date
848 //0040 0002 DA PRC Scheduled Procedure Step Start Date
849 //0040 0004 DA PRC Scheduled Procedure Step End Date
850 //0040 0244 DA PRC Performed Procedure Step Start Date
851 //0040 0250 DA PRC Performed Procedure Step End Date
852 //0040 2004 DA PRC Issue Date of Imaging Service Request
853 //0040 4005 DT PRC Scheduled Procedure Step Start Date and Time
854 //0040 4011 DT PRC Expected Completion Date and Time
855 //0040 a030 DT PRC Verification Date Time
856 //0040 a032 DT PRC Observation Date Time
857 //0040 a120 DT PRC DateTime
858 //0040 a121 DA PRC Date
859 //0040 a13a DT PRC Referenced Datetime
860 //0070 0082 DA ??? Presentation Creation Date
861 //0100 0420 DT ??? SOP Autorization Date and Time
862 //0400 0105 DT ??? Digital Signature DateTime
863 //2100 0040 DA PJ Creation Date
864 //3006 0008 DA SSET Structure Set Date
865 //3008 0024 DA ??? Treatment Control Point Date
866 //3008 0054 DA ??? First Treatment Date
867 //3008 0056 DA ??? Most Recent Treatment Date
868 //3008 0162 DA ??? Safe Position Exit Date
869 //3008 0166 DA ??? Safe Position Return Date
870 //3008 0250 DA ??? Treatment Date
871 //300a 0006 DA RT RT Plan Date
872 //300a 022c DA RT Air Kerma Rate Reference Date
873 //300e 0004 DA RT Review Date
876 //-----------------------------------------------------------------------------
879 //-----------------------------------------------------------------------------