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 //-----------------------------------------------------------------------------
87 * \brief Prints the Header Entries (Dicom Elements)
88 * from the chained list
89 * and skips the elements belonging to a SeQuence
92 void gdcmHeader::PrintEntryNoSQ(std::ostream & os) {
94 // FIXME : Is it of any use, now?
98 for (ListTag::iterator i = listEntries.begin();
99 i != listEntries.end();
102 depth= (*i)->GetSQDepthLevel();
106 (*i)->SetPrintLevel(printLevel);
113 * \ingroup gdcmHeader
114 * \brief Prints the Header Entries (Dicom Elements)
115 * from the chained list
116 * and indents the elements belonging to any SeQuence
117 * \warning : will be removed
120 void gdcmHeader::PrintEntryNiceSQ(std::ostream & os) {
123 std::ostringstream tab;
127 for (ListTag::iterator i = listEntries.begin();
128 i != listEntries.end();
130 depth= (*i)->GetSQDepthLevel();
132 for (int k=0;k<depth;k++)
135 (*i)->SetPrintLevel(printLevel);
143 //-----------------------------------------------------------------------------
147 * \ingroup gdcmHeader
148 * \brief This predicate, based on hopefully reasonable heuristics,
149 * decides whether or not the current gdcmParser was properly parsed
150 * and contains the mandatory information for being considered as
151 * a well formed and usable Dicom/Acr File.
152 * @return true when gdcmParser is the one of a reasonable Dicom/Acr file,
155 bool gdcmHeader::IsReadable(void) {
156 if(!gdcmDocument::IsReadable()) {
159 std::string res = GetEntryByNumber(0x0028, 0x0005);
160 if ( res != GDCM_UNFOUND && atoi(res.c_str()) > 4 )
161 return false; // Image Dimensions
162 if ( !GetDocEntryByNumber(0x0028, 0x0100) )
163 return false; // "Bits Allocated"
164 if ( !GetDocEntryByNumber(0x0028, 0x0101) )
165 return false; // "Bits Stored"
166 if ( !GetDocEntryByNumber(0x0028, 0x0102) )
167 return false; // "High Bit"
168 if ( !GetDocEntryByNumber(0x0028, 0x0103) )
169 return false; // "Pixel Representation" i.e. 'Sign'
174 * \ingroup gdcmHeader
175 * \brief Determines if the Transfer Syntax was already encountered
176 * and if it corresponds to a JPEGBaseLineProcess1 one.
177 * @return True when JPEGBaseLineProcess1found. False in all other cases.
179 bool gdcmHeader::IsJPEGBaseLineProcess1TransferSyntax(void) {
180 gdcmDocEntry* Element = GetDocEntryByNumber(0x0002, 0x0010);
183 LoadDocEntrySafe(Element);
185 std::string Transfer = ((gdcmValEntry *)Element)->GetValue();
186 if ( Transfer == "1.2.840.10008.1.2.4.50" )
192 * \ingroup gdcmHeader
193 * \brief Determines if the Transfer Syntax was already encountered
194 * and if it corresponds to a JPEGExtendedProcess2-4 one.
195 * @return True when JPEGExtendedProcess2-4 found. False in all other cases.
197 bool gdcmHeader::IsJPEGExtendedProcess2_4TransferSyntax(void) {
198 gdcmDocEntry* Element = GetDocEntryByNumber(0x0002, 0x0010);
201 LoadDocEntrySafe(Element);
202 return ( ((gdcmValEntry *)Element)->GetValue() == "1.2.840.10008.1.2.4.51" );
206 * \ingroup gdcmHeader
207 * \brief Determines if the Transfer Syntax was already encountered
208 * and if it corresponds to a JPEGExtendeProcess3-5 one.
209 * @return True when JPEGExtendedProcess3-5 found. False in all other cases.
211 bool gdcmHeader::IsJPEGExtendedProcess3_5TransferSyntax(void) {
212 gdcmDocEntry* Element = GetDocEntryByNumber(0x0002, 0x0010);
215 LoadDocEntrySafe(Element);
217 std::string Transfer = ((gdcmValEntry *)Element)->GetValue();
218 if ( Transfer == "1.2.840.10008.1.2.4.52" )
224 * \ingroup gdcmHeader
225 * \brief Determines if the Transfer Syntax was already encountered
226 * and if it corresponds to a JPEGSpectralSelectionProcess6-8 one.
227 * @return True when JPEGSpectralSelectionProcess6-8 found. False in all
230 bool gdcmHeader::IsJPEGSpectralSelectionProcess6_8TransferSyntax(void) {
231 gdcmDocEntry* Element = GetDocEntryByNumber(0x0002, 0x0010);
234 LoadDocEntrySafe(Element);
236 std::string Transfer = ((gdcmValEntry *)Element)->GetValue();
237 if ( Transfer == "1.2.840.10008.1.2.4.53" )
243 * \ingroup gdcmHeader
244 * \brief Determines if the Transfer Syntax was already encountered
245 * and if it corresponds to a RLE Lossless one.
246 * @return True when RLE Lossless found. False in all
249 bool gdcmHeader::IsRLELossLessTransferSyntax(void) {
250 gdcmDocEntry* Element = GetDocEntryByNumber(0x0002, 0x0010);
253 LoadDocEntrySafe(Element);
255 std::string Transfer = ((gdcmValEntry *)Element)->GetValue();
256 if ( Transfer == "1.2.840.10008.1.2.5" ) {
263 * \ingroup gdcmHeader
264 * \brief Determines if Transfer Syntax was already encountered
265 * and if it corresponds to a JPEG Lossless one.
266 * @return True when RLE Lossless found. False in all
269 bool gdcmHeader::IsJPEGLossless(void) {
270 gdcmDocEntry* Element = GetDocEntryByNumber(0x0002, 0x0010);
271 // faire qq chose d'intelligent a la place de ça
274 LoadDocEntrySafe(Element);
276 const char * Transfert = ((gdcmValEntry *)Element)->GetValue().c_str();
278 if ( memcmp(Transfert+strlen(Transfert)-2 ,"70",2)==0) return true;
279 if ( memcmp(Transfert+strlen(Transfert)-2 ,"55",2)==0) return true;
281 if (((gdcmValEntry *)Element)->GetValue() == "1.2.840.10008.1.2.4.57") return true;
287 * \ingroup gdcmHeader
288 * \brief Determines if the Transfer Syntax was already encountered
289 * and if it corresponds to a JPEG2000 one
290 * @return True when JPEG2000 (Lossly or LossLess) found. False in all
293 bool gdcmHeader::IsJPEG2000(void) {
294 gdcmDocEntry* Element = GetDocEntryByNumber(0x0002, 0x0010);
297 LoadDocEntrySafe(Element);
299 std::string Transfer = ((gdcmValEntry *)Element)->GetValue();
300 if ( (Transfer == "1.2.840.10008.1.2.4.90")
301 || (Transfer == "1.2.840.10008.1.2.4.91") )
307 * \ingroup gdcmHeader
308 * \brief Predicate for dicom version 3 file.
309 * @return True when the file is a dicom version 3.
311 bool gdcmHeader::IsDicomV3(void) {
312 // Checking if Transfert Syntax exists is enough
313 // Anyway, it's to late check if the 'Preamble' was found ...
314 // And ... would it be a rich idea to check ?
315 // (some 'no Preamble' DICOM images exist !)
316 return (GetDocEntryByNumber(0x0002, 0x0010) != NULL);
320 * \ingroup gdcmHeader
321 * \brief Retrieve the number of columns of image.
322 * @return The encountered size when found, 0 by default.
323 * 0 means the file is NOT USABLE. The caller will have to check
325 int gdcmHeader::GetXSize(void) {
327 StrSize = GetEntryByNumber(0x0028,0x0011);
328 if (StrSize == GDCM_UNFOUND)
330 return atoi(StrSize.c_str());
334 * \ingroup gdcmHeader
335 * \brief Retrieve the number of lines of image.
336 * \warning The defaulted value is 1 as opposed to gdcmHeader::GetXSize()
337 * @return The encountered size when found, 1 by default
338 * (The ACR-MEMA file contains a Signal, not an Image).
340 int gdcmHeader::GetYSize(void) {
341 std::string StrSize = GetEntryByNumber(0x0028,0x0010);
342 if (StrSize != GDCM_UNFOUND)
343 return atoi(StrSize.c_str());
347 // The Rows (0028,0010) entry was optional for ACR/NEMA. It might
348 // hence be a signal (1d image). So we default to 1:
353 * \ingroup gdcmHeader
354 * \brief Retrieve the number of planes of volume or the number
355 * of frames of a multiframe.
356 * \warning When present we consider the "Number of Frames" as the third
357 * dimension. When absent we consider the third dimension as
358 * being the ACR-NEMA "Planes" tag content.
359 * @return The encountered size when found, 1 by default (single image).
361 int gdcmHeader::GetZSize(void) {
362 // Both DicomV3 and ACR/Nema consider the "Number of Frames"
363 // as the third dimension.
364 std::string StrSize = GetEntryByNumber(0x0028,0x0008);
365 if (StrSize != GDCM_UNFOUND)
366 return atoi(StrSize.c_str());
368 // We then consider the "Planes" entry as the third dimension
369 StrSize = GetEntryByNumber(0x0028,0x0012);
370 if (StrSize != GDCM_UNFOUND)
371 return atoi(StrSize.c_str());
376 * \ingroup gdcmHeader
377 * \brief Retrieve the number of Bits Stored (actually used)
378 * (as opposite to number of Bits Allocated)
379 * @return The encountered number of Bits Stored, 0 by default.
380 * 0 means the file is NOT USABLE. The caller has to check it !
382 int gdcmHeader::GetBitsStored(void) {
383 std::string StrSize = GetEntryByNumber(0x0028,0x0101);
384 if (StrSize == GDCM_UNFOUND)
385 return 0; // It's supposed to be mandatory
386 // the caller will have to check
387 return atoi(StrSize.c_str());
391 * \ingroup gdcmHeader
392 * \brief Retrieve the number of Bits Allocated
393 * (8, 12 -compacted ACR-NEMA files, 16, ...)
394 * @return The encountered number of Bits Allocated, 0 by default.
395 * 0 means the file is NOT USABLE. The caller has to check it !
397 int gdcmHeader::GetBitsAllocated(void) {
398 std::string StrSize = GetEntryByNumber(0x0028,0x0100);
399 if (StrSize == GDCM_UNFOUND)
400 return 0; // It's supposed to be mandatory
401 // the caller will have to check
402 return atoi(StrSize.c_str());
406 * \ingroup gdcmHeader
407 * \brief Retrieve the number of Samples Per Pixel
408 * (1 : gray level, 3 : RGB -1 or 3 Planes-)
409 * @return The encountered number of Samples Per Pixel, 1 by default.
410 * (Gray level Pixels)
412 int gdcmHeader::GetSamplesPerPixel(void) {
413 std::string StrSize = GetEntryByNumber(0x0028,0x0002);
414 if (StrSize == GDCM_UNFOUND)
415 return 1; // Well, it's supposed to be mandatory ...
416 // but sometimes it's missing : *we* assume Gray pixels
417 return atoi(StrSize.c_str());
421 * \ingroup gdcmHeader
422 * \brief Retrieve the Planar Configuration for RGB images
423 * (0 : RGB Pixels , 1 : R Plane + G Plane + B Plane)
424 * @return The encountered Planar Configuration, 0 by default.
426 int gdcmHeader::GetPlanarConfiguration(void) {
427 std::string StrSize = GetEntryByNumber(0x0028,0x0006);
428 if (StrSize == GDCM_UNFOUND)
430 return atoi(StrSize.c_str());
434 * \ingroup gdcmHeader
435 * \brief Return the size (in bytes) of a single pixel of data.
436 * @return The size in bytes of a single pixel of data; 0 by default
437 * 0 means the file is NOT USABLE; the caller will have to check
439 int gdcmHeader::GetPixelSize(void) {
440 std::string PixelType = GetPixelType();
441 if (PixelType == "8U" || PixelType == "8S")
443 if (PixelType == "16U" || PixelType == "16S")
445 if (PixelType == "32U" || PixelType == "32S")
447 if (PixelType == "FD")
449 dbg.Verbose(0, "gdcmHeader::GetPixelSize: Unknown pixel type");
454 * \ingroup gdcmHeader
455 * \brief Build the Pixel Type of the image.
456 * Possible values are:
457 * - 8U unsigned 8 bit,
459 * - 16U unsigned 16 bit,
460 * - 16S signed 16 bit,
461 * - 32U unsigned 32 bit,
462 * - 32S signed 32 bit,
463 * - FD floating double 64 bits (Not kosher DICOM, but so usefull!)
464 * \warning 12 bit images appear as 16 bit.
465 * 24 bit images appear as 8 bit
466 * @return 0S if nothing found. NOT USABLE file. The caller has to check
468 std::string gdcmHeader::GetPixelType(void) {
469 std::string BitsAlloc = GetEntryByNumber(0x0028, 0x0100); // Bits Allocated
470 if (BitsAlloc == GDCM_UNFOUND) {
471 dbg.Verbose(0, "gdcmHeader::GetPixelType: unfound Bits Allocated");
472 BitsAlloc = std::string("16");
474 if (BitsAlloc == "64") // )
476 if (BitsAlloc == "12") // It will be unpacked
477 BitsAlloc = std::string("16");
478 else if (BitsAlloc == "24") // (in order no to be messed up
479 BitsAlloc = std::string("8"); // by old RGB images)
481 std::string Signed = GetEntryByNumber(0x0028, 0x0103); // "Pixel Representation"
482 if (Signed == GDCM_UNFOUND) {
483 dbg.Verbose(0, "gdcmHeader::GetPixelType: unfound Pixel Representation");
484 BitsAlloc = std::string("0");
487 Signed = std::string("U");
489 Signed = std::string("S");
491 return( BitsAlloc + Signed);
496 * \ingroup gdcmHeader
497 * \brief Recover the offset (from the beginning of the file)
498 * of *image* pixels (not *icone image* pixels, if any !)
499 * @return Pixel Offset
501 size_t gdcmHeader::GetPixelOffset(void) {
503 gdcmDocEntry* PixelElement = GetDocEntryByNumber(GrPixel,NumPixel);
506 return PixelElement->GetOffset();
509 std::cout << "Big trouble : Pixel Element ("
510 << std::hex << GrPixel<<","<< NumPixel<< ") NOT found"
516 // TODO : unify those two (previous one and next one)
518 * \ingroup gdcmHeader
519 * \brief Recover the pixel area length (in Bytes)
520 * @return Pixel Element Length, as stored in the header
521 * (NOT the memory space necessary to hold the Pixels
522 * -in case of embeded compressed image-)
523 * 0 : NOT USABLE file. The caller has to check.
525 size_t gdcmHeader::GetPixelAreaLength(void) {
527 gdcmDocEntry* PixelElement = GetDocEntryByNumber(GrPixel,NumPixel);
530 return PixelElement->GetLength();
533 std::cout << "Big trouble : Pixel Element ("
534 << std::hex << GrPixel<<","<< NumPixel<< ") NOT found"
542 * \ingroup gdcmHeader
543 * \brief tells us if LUT are used
544 * \warning Right now, 'Segmented xxx Palette Color Lookup Table Data'
545 * are NOT considered as LUT, since nobody knows
546 * how to deal with them
547 * Please warn me if you know sbdy that *does* know ... jprx
548 * @return true if LUT Descriptors and LUT Tables were found
550 bool gdcmHeader::HasLUT(void) {
552 // Check the presence of the LUT Descriptors, and LUT Tables
554 if ( !GetDocEntryByNumber(0x0028,0x1101) )
556 // LutDescriptorGreen
557 if ( !GetDocEntryByNumber(0x0028,0x1102) )
560 if ( !GetDocEntryByNumber(0x0028,0x1103) )
562 // Red Palette Color Lookup Table Data
563 if ( !GetDocEntryByNumber(0x0028,0x1201) )
565 // Green Palette Color Lookup Table Data
566 if ( !GetDocEntryByNumber(0x0028,0x1202) )
568 // Blue Palette Color Lookup Table Data
569 if ( !GetDocEntryByNumber(0x0028,0x1203) )
571 // FIXME : (0x0028,0x3006) : LUT Data (CTX dependent)
572 // NOT taken into account, but we don't know how to use it ...
577 * \ingroup gdcmHeader
578 * \brief gets the info from 0028,1101 : Lookup Table Desc-Red
580 * @return Lookup Table number of Bits , 0 by default
581 * when (0028,0004),Photometric Interpretation = [PALETTE COLOR ]
582 * @ return bit number of each LUT item
584 int gdcmHeader::GetLUTNbits(void) {
585 std::vector<std::string> tokens;
589 //Just hope Lookup Table Desc-Red = Lookup Table Desc-Red = Lookup Table Desc-Blue
590 // Consistency already checked in GetLUTLength
591 std::string LutDescription = GetEntryByNumber(0x0028,0x1101);
592 if (LutDescription == GDCM_UNFOUND)
594 tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
595 Tokenize (LutDescription, tokens, "\\");
596 //LutLength=atoi(tokens[0].c_str());
597 //LutDepth=atoi(tokens[1].c_str());
598 LutNbits=atoi(tokens[2].c_str());
604 * \ingroup gdcmHeader
605 * \brief builts Red/Green/Blue/Alpha LUT from Header
606 * when (0028,0004),Photometric Interpretation = [PALETTE COLOR ]
607 * and (0028,1101),(0028,1102),(0028,1102)
608 * - xxx Palette Color Lookup Table Descriptor - are found
609 * and (0028,1201),(0028,1202),(0028,1202)
610 * - xxx Palette Color Lookup Table Data - are found
611 * \warning does NOT deal with :
612 * 0028 1100 Gray Lookup Table Descriptor (Retired)
613 * 0028 1221 Segmented Red Palette Color Lookup Table Data
614 * 0028 1222 Segmented Green Palette Color Lookup Table Data
615 * 0028 1223 Segmented Blue Palette Color Lookup Table Data
616 * no known Dicom reader deals with them :-(
617 * @return a RGBA Lookup Table
619 unsigned char * gdcmHeader::GetLUTRGBA(void) {
621 // http://www.barre.nom.fr/medical/dicom2/limitations.html#Color%20Lookup%20Tables
623 // if Photometric Interpretation # PALETTE COLOR, no LUT to be done
624 if (GetEntryByNumber(0x0028,0x0004) != "PALETTE COLOR ") {
627 int lengthR, debR, nbitsR;
628 int lengthG, debG, nbitsG;
629 int lengthB, debB, nbitsB;
631 // Get info from Lut Descriptors
632 // (the 3 LUT descriptors may be different)
633 std::string LutDescriptionR = GetEntryByNumber(0x0028,0x1101);
634 if (LutDescriptionR == GDCM_UNFOUND)
636 std::string LutDescriptionG = GetEntryByNumber(0x0028,0x1102);
637 if (LutDescriptionG == GDCM_UNFOUND)
639 std::string LutDescriptionB = GetEntryByNumber(0x0028,0x1103);
640 if (LutDescriptionB == GDCM_UNFOUND)
643 std::vector<std::string> tokens;
645 tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
646 Tokenize (LutDescriptionR, tokens, "\\");
647 lengthR=atoi(tokens[0].c_str()); // Red LUT length in Bytes
648 debR =atoi(tokens[1].c_str()); // subscript of the first Lut Value
649 nbitsR =atoi(tokens[2].c_str()); // Lut item size (in Bits)
652 tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
653 Tokenize (LutDescriptionG, tokens, "\\");
654 lengthG=atoi(tokens[0].c_str()); // Green LUT length in Bytes
655 debG =atoi(tokens[1].c_str()); // subscript of the first Lut Value
656 nbitsG =atoi(tokens[2].c_str()); // Lut item size (in Bits)
659 tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
660 Tokenize (LutDescriptionB, tokens, "\\");
661 lengthB=atoi(tokens[0].c_str()); // Blue LUT length in Bytes
662 debB =atoi(tokens[1].c_str()); // subscript of the first Lut Value
663 nbitsB =atoi(tokens[2].c_str()); // Lut item size (in Bits)
666 // Load LUTs into memory, (as they were stored on disk)
667 unsigned char *lutR = (unsigned char *)
668 GetEntryVoidAreaByNumber(0x0028,0x1201);
669 unsigned char *lutG = (unsigned char *)
670 GetEntryVoidAreaByNumber(0x0028,0x1202);
671 unsigned char *lutB = (unsigned char *)
672 GetEntryVoidAreaByNumber(0x0028,0x1203);
674 if (!lutR || !lutG || !lutB ) {
677 // forge the 4 * 8 Bits Red/Green/Blue/Alpha LUT
679 unsigned char *LUTRGBA = new unsigned char[1024]; // 256 * 4 (R, G, B, Alpha)
683 memset(LUTRGBA, 0, 1024);
686 std::string str_nb = GetEntryByNumber(0x0028,0x0100);
687 if (str_nb == GDCM_UNFOUND ) {
690 nb = atoi(str_nb.c_str() );
694 if (nbitsR==16 && nb==8) // when LUT item size is different than pixel size
695 mult=2; // high byte must be = low byte
696 else // See PS 3.3-2003 C.11.1.1.2 p 619
699 // if we get a black image, let's just remove the '+1'
700 // from 'i*mult+1' and check again
701 // if it works, we shall have to check the 3 Palettes
702 // to see which byte is ==0 (first one, or second one)
704 // We give up the checking to avoid some (useless ?)overhead
705 // (optimistic asumption)
710 for(i=0;i<lengthR;i++) {
715 for(i=0;i<lengthG;i++) {
720 for(i=0;i<lengthB;i++) {
726 *a = 1; // Alpha component
730 //How to free the now useless LUTs?
731 //free(LutR); free(LutB); free(LutG); // Seg Fault when used
736 * \ingroup gdcmHeader
737 * \brief gets the info from 0002,0010 : Transfert Syntax and gdcmTS
739 * @return the full Transfert Syntax Name (as oposite to Transfert Syntax UID)
741 std::string gdcmHeader::GetTransfertSyntaxName(void) {
742 // use the gdcmTS (TS : Transfert Syntax)
743 std::string TransfertSyntax = GetEntryByNumber(0x0002,0x0010);
744 if (TransfertSyntax == GDCM_UNFOUND) {
745 dbg.Verbose(0, "gdcmHeader::GetTransfertSyntaxName: unfound Transfert Syntax (0002,0010)");
746 return "Uncompressed ACR-NEMA";
748 // we do it only when we need it
749 gdcmTS * ts = gdcmGlobal::GetTS();
750 std::string tsName=ts->GetValue(TransfertSyntax);
751 //delete ts; // Seg Fault when deleted ?!
756 * \ingroup gdcmHeader
757 * \brief Sets the Pixel Area size in the Header
758 * --> not-for-rats function
759 * @param ImageDataSize new Pixel Area Size
760 * warning : nothing else is checked
762 void gdcmHeader::SetImageDataSize(size_t ImageDataSize) {
763 std::string content1;
766 // Assumes DocEntry (GrPixel, NumPixel) is unique ...
767 //\todo deal with multiplicity (see gdcmData/icone.dcm)
768 sprintf(car,"%d",ImageDataSize);
770 gdcmDocEntry *a = GetDocEntryByNumber(GrPixel, NumPixel);
771 a->SetLength(ImageDataSize);
774 sprintf(car,"%d",ImageDataSize);
776 SetEntryByNumber(content1, GrPixel, NumPixel);
781 * \ingroup gdcmHeader
782 * \brief compares 2 Headers, according to DICOMDIR rules
783 * --> not-for-rats function
784 * \warning does NOT work with ACR-NEMA files
785 * \todo find a trick to solve the pb (use RET fields ?)
787 * @return true if 'smaller'
789 bool gdcmHeader::operator<(gdcmHeader &header){
793 s1=this->GetEntryByNumber(0x0010,0x0010);
794 s2=header.GetEntryByNumber(0x0010,0x0010);
802 s1=this->GetEntryByNumber(0x0010,0x0020);
803 s2=header.GetEntryByNumber(0x0010,0x0020);
810 // Study Instance UID
811 s1=this->GetEntryByNumber(0x0020,0x000d);
812 s2=header.GetEntryByNumber(0x0020,0x000d);
819 // Serie Instance UID
820 s1=this->GetEntryByNumber(0x0020,0x000e);
821 s2=header.GetEntryByNumber(0x0020,0x000e);
832 bool gdcmHeader::WriteEntry(gdcmDocEntry *tag, FILE *_fp,FileType type)
834 guint32 length = tag->GetLength();
836 // The value of a tag MUST (see the DICOM norm) be an odd number of
837 // bytes. When this is not the case, pad with an additional byte:
840 // tag->SetValue(tag->GetValue()+"\0"); // to go on compiling
841 tag->SetLength(tag->GetReadLength()+1);
844 WriteEntryTagVRLength(tag, _fp, type);
846 // Pixels are never loaded in the element !
847 // we stop writting when Pixel are processed
848 // FIX : we loose trailing elements (RAB, right now)
849 guint16 el = tag->GetElement();
850 guint16 group = tag->GetGroup();
852 if ((group == GrPixel) && (el == NumPixel) ) {
854 if (compte == countGrPixel) {// we passed *all* the GrPixel,NumPixel
858 WriteEntryValue(tag, _fp, type);
862 //-----------------------------------------------------------------------------
866 * \ingroup gdcmHeader
867 * \brief anonymize a Header (removes Patient's personal info)
868 * (read the code to see which ones ...)
870 bool gdcmHeader::anonymizeHeader() {
872 gdcmDocEntry *patientNameHE = GetDocEntryByNumber (0x0010, 0x0010);
873 // gdcmDocEntry *patientIDHE = GetDocEntryByNumber (0x0010, 0x0020);
875 ReplaceIfExistByNumber (" ",0x0010, 0x2154); // Telephone
876 ReplaceIfExistByNumber (" ",0x0010, 0x1040); // Adress
877 ReplaceIfExistByNumber (" ",0x0010, 0x0020); // Patient ID
880 std::string StudyInstanceUID = GetEntryByNumber (0x0020, 0x000d);
881 if (StudyInstanceUID !=GDCM_UNFOUND)
882 ReplaceOrCreateByNumber(StudyInstanceUID, 0x0010, 0x0010);
884 ReplaceOrCreateByNumber(std::string("anonymised"), 0x0010, 0x0010);
888 // (if any) remove or replace all the stuff that contains a Date
890 //0008 0012 DA ID Instance Creation Date
891 //0008 0020 DA ID Study Date
892 //0008 0021 DA ID Series Date
893 //0008 0022 DA ID Acquisition Date
894 //0008 0023 DA ID Content Date
895 //0008 0024 DA ID Overlay Date
896 //0008 0025 DA ID Curve Date
897 //0008 002a DT ID Acquisition Datetime
898 //0018 9074 DT ACQ Frame Acquisition Datetime
899 //0018 9151 DT ACQ Frame Reference Datetime
900 //0018 a002 DT ACQ Contribution Date Time
901 //0020 3403 SH REL Modified Image Date (RET)
902 //0032 0032 DA SDY Study Verified Date
903 //0032 0034 DA SDY Study Read Date
904 //0032 1000 DA SDY Scheduled Study Start Date
905 //0032 1010 DA SDY Scheduled Study Stop Date
906 //0032 1040 DA SDY Study Arrival Date
907 //0032 1050 DA SDY Study Completion Date
908 //0038 001a DA VIS Scheduled Admission Date
909 //0038 001c DA VIS Scheduled Discharge Date
910 //0038 0020 DA VIS Admitting Date
911 //0038 0030 DA VIS Discharge Date
912 //0040 0002 DA PRC Scheduled Procedure Step Start Date
913 //0040 0004 DA PRC Scheduled Procedure Step End Date
914 //0040 0244 DA PRC Performed Procedure Step Start Date
915 //0040 0250 DA PRC Performed Procedure Step End Date
916 //0040 2004 DA PRC Issue Date of Imaging Service Request
917 //0040 4005 DT PRC Scheduled Procedure Step Start Date and Time
918 //0040 4011 DT PRC Expected Completion Date and Time
919 //0040 a030 DT PRC Verification Date Time
920 //0040 a032 DT PRC Observation Date Time
921 //0040 a120 DT PRC DateTime
922 //0040 a121 DA PRC Date
923 //0040 a13a DT PRC Referenced Datetime
924 //0070 0082 DA ??? Presentation Creation Date
925 //0100 0420 DT ??? SOP Autorization Date and Time
926 //0400 0105 DT ??? Digital Signature DateTime
927 //2100 0040 DA PJ Creation Date
928 //3006 0008 DA SSET Structure Set Date
929 //3008 0024 DA ??? Treatment Control Point Date
930 //3008 0054 DA ??? First Treatment Date
931 //3008 0056 DA ??? Most Recent Treatment Date
932 //3008 0162 DA ??? Safe Position Exit Date
933 //3008 0166 DA ??? Safe Position Return Date
934 //3008 0250 DA ??? Treatment Date
935 //300a 0006 DA RT RT Plan Date
936 //300a 022c DA RT Air Kerma Rate Reference Date
937 //300e 0004 DA RT Review Date
940 //-----------------------------------------------------------------------------
943 //-----------------------------------------------------------------------------