1 /*=========================================================================
4 Module: $RCSfile: gdcmFileHelper.cxx,v $
7 Date: $Date: 2005/11/03 08:46:03 $
8 Version: $Revision: 1.78 $
10 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
11 l'Image). All rights reserved. See Doc/License.txt or
12 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
14 This software is distributed WITHOUT ANY WARRANTY; without even
15 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 PURPOSE. See the above copyright notices for more information.
18 =========================================================================*/
20 #include "gdcmFileHelper.h"
21 #include "gdcmGlobal.h"
23 #include "gdcmDocument.h"
24 #include "gdcmDebug.h"
26 #include "gdcmSeqEntry.h"
27 #include "gdcmSQItem.h"
28 #include "gdcmDataEntry.h"
30 #include "gdcmPixelReadConvert.h"
31 #include "gdcmPixelWriteConvert.h"
32 #include "gdcmDocEntryArchive.h"
33 #include "gdcmDictSet.h"
34 #include "gdcmOrientation.h"
39 // ----------------------------- WARNING -------------------------
41 These lines will be moved to the document-to-be 'User's Guide'
43 // To read an image, user needs a gdcm::File
44 gdcm::File *f = new gdcm::File(fileName);
46 // user may also decide he doesn't want to load some parts of the header
47 gdcm::File *f = new gdcm::File();
48 f->SetFileName(fileName);
49 f->SetLoadMode(LD_NOSEQ); // or
50 f->SetLoadMode(LD_NOSHADOW); // or
51 f->SetLoadMode(LD_NOSEQ | LD_NOSHADOW); // or
52 f->SetLoadMode(LD_NOSHADOWSEQ);
55 // user can now check some values
56 std::string v = f->GetEntryValue(groupNb,ElementNb);
58 // to get the pixels, user needs a gdcm::FileHelper
59 gdcm::FileHelper *fh = new gdcm::FileHelper(f);
60 // user may ask not to convert Palette to RGB
61 uint8_t *pixels = fh->GetImageDataRaw();
62 int imageLength = fh->GetImageDataRawSize();
63 // He can now use the pixels, create a new image, ...
64 uint8_t *userPixels = ...
66 To re-write the image, user re-uses the gdcm::FileHelper
68 fh->SetImageData( userPixels, userPixelsLength);
69 fh->SetTypeToRaw(); // Even if it was possible to convert Palette to RGB
72 fh->SetWriteTypeToDcmExpl(); // he wants Explicit Value Representation
73 // Little Endian is the default
74 // no other value is allowed
75 (-->SetWriteType(ExplicitVR);)
76 -->WriteType = ExplicitVR;
77 fh->Write(newFileName); // overwrites the file, if any
80 fh->WriteDcmExplVR(newFileName);
83 // ----------------------------- WARNING -------------------------
85 These lines will be moved to the document-to-be 'Developer's Guide'
87 WriteMode : WMODE_RAW / WMODE_RGB
88 WriteType : ImplicitVR, ExplicitVR, ACR, ACR_LIBIDO
90 fh1->Write(newFileName);
91 SetWriteFileTypeToImplicitVR() / SetWriteFileTypeToExplicitVR();
92 (modifies TransferSyntax)
93 SetWriteToRaw(); / SetWriteToRGB();
94 (modifies, when necessary : photochromatic interpretation,
95 samples per pixel, Planar configuration,
96 bits allocated, bits stored, high bit -ACR 24 bits-
97 Pixels element VR, pushes out the LUT )
98 CheckWriteIntegrity();
99 (checks user given pixels length)
100 FileInternal->Write(fileName,WriteType)
101 fp = opens file(fileName);
102 ComputeGroup0002Length( );
104 RemoveEntry(palettes, etc)
105 Document::WriteContent(fp, writetype);
107 (moves back to the File all the archived elements)
108 RestoreWriteFileType();
109 (pushes back group 0002, with TransferSyntax)
117 //-------------------------------------------------------------------------
118 // Constructor / Destructor
120 * \brief Constructor dedicated to deal with the *pixels* area of a ACR/DICOMV3
121 * file (gdcm::File only deals with the ... header)
122 * Opens (in read only and when possible) an existing file and checks
123 * for DICOM compliance. Returns NULL on failure.
124 * It will be up to the user to load the pixels into memory
125 * ( GetImageDataSize() + GetImageData() methods)
126 * \note the in-memory representation of all available tags found in
127 * the DICOM header is post-poned to first header information access.
128 * This avoid a double parsing of public part of the header when
129 * one sets an a posteriori shadow dictionary (efficiency can be
130 * seen as a side effect).
132 FileHelper::FileHelper( )
134 FileInternal = File::New( );
139 * \brief Constructor dedicated to deal with the *pixels* area of a ACR/DICOMV3
140 * file (File only deals with the ... header)
141 * Opens (in read only and when possible) an existing file and checks
142 * for DICOM compliance. Returns NULL on failure.
143 * It will be up to the user to load the pixels into memory
144 * ( GetImageDataSize() + GetImageData() methods)
145 * \note the in-memory representation of all available tags found in
146 * the DICOM header is post-poned to first header information access.
147 * This avoid a double parsing of public part of the header when
148 * user sets an a posteriori shadow dictionary (efficiency can be
149 * seen as a side effect).
150 * @param header already built Header
152 FileHelper::FileHelper(File *header)
154 gdcmAssertMacro(header);
156 FileInternal = header;
157 FileInternal->Register();
159 if ( FileInternal->IsReadable() )
161 PixelReadConverter->GrabInformationsFromFile( FileInternal );
166 * \brief canonical destructor
167 * \note If the header (gdcm::File) was created by the FileHelper constructor,
168 * it is destroyed by the FileHelper
170 FileHelper::~FileHelper()
172 if ( PixelReadConverter )
174 delete PixelReadConverter;
176 if ( PixelWriteConverter )
178 delete PixelWriteConverter;
185 FileInternal->Unregister();
188 //-----------------------------------------------------------------------------
192 * \brief Sets the LoadMode of the internal gdcm::File as a boolean string.
193 * NO_SEQ, NO_SHADOW, NO_SHADOWSEQ ... (nothing more, right now)
194 * WARNING : before using NO_SHADOW, be sure *all* your files
195 * contain accurate values in the 0x0000 element (if any)
196 * of *each* Shadow Group. The parser will fail if the size is wrong !
197 * @param loadMode Load mode to be used
199 void FileHelper::SetLoadMode(int loadMode)
201 GetFile()->SetLoadMode( loadMode );
204 * \brief Sets the LoadMode of the internal gdcm::File
205 * @param fileName name of the file to be open
207 void FileHelper::SetFileName(std::string const &fileName)
209 FileInternal->SetFileName( fileName );
214 * @return false if file cannot be open or no swap info was found,
215 * or no tag was found.
217 bool FileHelper::Load()
219 if ( !FileInternal->Load() )
222 PixelReadConverter->GrabInformationsFromFile( FileInternal );
227 * \brief Accesses an existing DocEntry (i.e. a Dicom Element)
228 * through it's (group, element) and modifies it's content with
230 * @param content new value (string) to substitute with
231 * @param group group number of the Dicom Element to modify
232 * @param elem element number of the Dicom Element to modify
233 * \return false if DocEntry not found
235 bool FileHelper::SetEntryString(std::string const &content,
236 uint16_t group, uint16_t elem)
238 return FileInternal->SetEntryString(content, group, elem);
243 * \brief Accesses an existing DocEntry (i.e. a Dicom Element)
244 * through it's (group, element) and modifies it's content with
246 * @param content new value (void* -> uint8_t*) to substitute with
247 * @param lgth new value length
248 * @param group group number of the Dicom Element to modify
249 * @param elem element number of the Dicom Element to modify
250 * \return false if DocEntry not found
252 bool FileHelper::SetEntryBinArea(uint8_t *content, int lgth,
253 uint16_t group, uint16_t elem)
255 return FileInternal->SetEntryBinArea(content, lgth, group, elem);
259 * \brief Modifies the value of a given DocEntry (Dicom entry)
260 * when it exists. Creates it with the given value when unexistant.
261 * @param content (string)value to be set
262 * @param group Group number of the Entry
263 * @param elem Element number of the Entry
264 * \return pointer to the modified/created Dicom entry (NULL when creation
267 DataEntry *FileHelper::InsertEntryString(std::string const &content,
268 uint16_t group, uint16_t elem)
270 return FileInternal->InsertEntryString(content, group, elem);
274 * \brief Modifies the value of a given DocEntry (Dicom entry)
275 * when it exists. Creates it with the given value when unexistant.
276 * A copy of the binArea is made to be kept in the Document.
277 * @param binArea (binary)value to be set
278 * @param lgth new value length
279 * @param group Group number of the Entry
280 * @param elem Element number of the Entry
281 * \return pointer to the modified/created Dicom entry (NULL when creation
284 DataEntry *FileHelper::InsertEntryBinArea(uint8_t *binArea, int lgth,
285 uint16_t group, uint16_t elem)
287 return FileInternal->InsertEntryBinArea(binArea, lgth, group, elem);
291 * \brief Modifies the value of a given DocEntry (Dicom entry)
292 * when it exists. Creates it, empty (?!) when unexistant.
293 * @param group Group number of the Entry
294 * @param elem Element number of the Entry
295 * \return pointer to the modified/created Dicom entry (NULL when creation
298 SeqEntry *FileHelper::InsertSeqEntry(uint16_t group, uint16_t elem)
300 return FileInternal->InsertSeqEntry(group, elem);
304 * \brief Get the size of the image data
305 * If the image can be RGB (with a lut or by default), the size
306 * corresponds to the RGB image
307 * (use GetImageDataRawSize if you want to be sure to get *only*
308 * the size of the pixels)
309 * @return The image size
311 size_t FileHelper::GetImageDataSize()
313 if ( PixelWriteConverter->GetUserData() )
315 return PixelWriteConverter->GetUserDataSize();
317 return PixelReadConverter->GetRGBSize();
321 * \brief Get the size of the image data.
322 * If the image could be converted to RGB using a LUT,
323 * this transformation is not taken into account by GetImageDataRawSize
324 * (use GetImageDataSize if you wish)
325 * @return The raw image size
327 size_t FileHelper::GetImageDataRawSize()
329 if ( PixelWriteConverter->GetUserData() )
331 return PixelWriteConverter->GetUserDataSize();
333 return PixelReadConverter->GetRawSize();
337 * \brief brings pixels into memory :
338 * - Allocates necessary memory,
339 * - Reads the pixels from disk (uncompress if necessary),
340 * - Transforms YBR pixels, if any, into RGB pixels,
341 * - Transforms 3 planes R, G, B, if any, into a single RGB Plane
342 * - Transforms single Grey plane + 3 Palettes into a RGB Plane
343 * - Copies the pixel data (image[s]/volume[s]) to newly allocated zone.
344 * @return Pointer to newly allocated pixel data.
345 * (uint8_t is just for prototyping. feel free to cast)
346 * NULL if alloc fails
348 uint8_t *FileHelper::GetImageData()
350 if ( PixelWriteConverter->GetUserData() )
352 return PixelWriteConverter->GetUserData();
357 // If the decompression failed nothing can be done.
361 if ( FileInternal->HasLUT() && PixelReadConverter->BuildRGBImage() )
363 return PixelReadConverter->GetRGB();
367 // When no LUT or LUT conversion fails, return the Raw
368 return PixelReadConverter->GetRaw();
373 * \brief brings pixels into memory :
374 * - Allocates necessary memory,
375 * - Transforms YBR pixels (if any) into RGB pixels
376 * - Transforms 3 planes R, G, B (if any) into a single RGB Plane
377 * - Copies the pixel data (image[s]/volume[s]) to newly allocated zone.
378 * - DOES NOT transform Grey plane + 3 Palettes into a RGB Plane
379 * @return Pointer to newly allocated pixel data.
380 * (uint8_t is just for prototyping. feel free to cast)
381 * NULL if alloc fails
383 uint8_t *FileHelper::GetImageDataRaw ()
388 #ifndef GDCM_LEGACY_REMOVE
390 * \ brief Useless function, since PixelReadConverter forces us
391 * copy the Pixels anyway.
392 * Reads the pixels from disk (uncompress if necessary),
393 * Transforms YBR pixels, if any, into RGB pixels
394 * Transforms 3 planes R, G, B, if any, into a single RGB Plane
395 * Transforms single Grey plane + 3 Palettes into a RGB Plane
396 * Copies at most MaxSize bytes of pixel data to caller allocated
398 * \ warning This function allows people that want to build a volume
399 * from an image stack *not to* have, first to get the image pixels,
400 * and then move them to the volume area.
401 * It's absolutely useless for any VTK user since vtk chooses
402 * to invert the lines of an image, that is the last line comes first
403 * (for some axis related reasons?). Hence he will have
404 * to load the image line by line, starting from the end.
405 * VTK users have to call GetImageData
407 * @ param destination Address (in caller's memory space) at which the
408 * pixel data should be copied
409 * @ param maxSize Maximum number of bytes to be copied. When MaxSize
410 * is not sufficient to hold the pixel data the copy is not
411 * executed (i.e. no partial copy).
412 * @ return On success, the number of bytes actually copied. Zero on
413 * failure e.g. MaxSize is lower than necessary.
415 size_t FileHelper::GetImageDataIntoVector (void *destination, size_t maxSize)
419 // If the decompression failed nothing can be done.
423 if ( FileInternal->HasLUT() && PixelReadConverter->BuildRGBImage() )
425 if ( PixelReadConverter->GetRGBSize() > maxSize )
427 gdcmWarningMacro( "Pixel data bigger than caller's expected MaxSize");
431 (void*)PixelReadConverter->GetRGB(),
432 PixelReadConverter->GetRGBSize() );
433 return PixelReadConverter->GetRGBSize();
436 // Either no LUT conversion necessary or LUT conversion failed
437 if ( PixelReadConverter->GetRawSize() > maxSize )
439 gdcmWarningMacro( "Pixel data bigger than caller's expected MaxSize");
443 (void *)PixelReadConverter->GetRaw(),
444 PixelReadConverter->GetRawSize() );
445 return PixelReadConverter->GetRawSize();
450 * \brief Points the internal pointer to the callers inData
451 * image representation, BUT WITHOUT COPYING THE DATA.
452 * 'image' Pixels are presented as C-like 2D arrays : line per line.
453 * 'volume'Pixels are presented as C-like 3D arrays : plane per plane
454 * \warning Since the pixels are not copied, it is the caller's responsability
455 * not to deallocate its data before gdcm uses them (e.g. with
456 * the Write() method )
457 * @param inData user supplied pixel area (uint8_t* is just for the compiler.
458 * user is allowed to pass any kind of pixelsn since the size is
460 * @param expectedSize total image size, *in Bytes*
462 void FileHelper::SetImageData(uint8_t *inData, size_t expectedSize)
464 SetUserData(inData, expectedSize);
468 * \brief Set the image data defined by the user
469 * \warning When writting the file, this data are get as default data to write
470 * @param inData user supplied pixel area (uint8_t* is just for the compiler.
471 * user is allowed to pass any kind of pixels since the size is
473 * @param expectedSize total image size, *in Bytes*
475 void FileHelper::SetUserData(uint8_t *inData, size_t expectedSize)
477 PixelWriteConverter->SetUserData(inData, expectedSize);
481 * \brief Get the image data defined by the user
482 * \warning When writting the file, this data are get as default data to write
484 uint8_t *FileHelper::GetUserData()
486 return PixelWriteConverter->GetUserData();
490 * \brief Get the image data size defined by the user
491 * \warning When writting the file, this data are get as default data to write
493 size_t FileHelper::GetUserDataSize()
495 return PixelWriteConverter->GetUserDataSize();
499 * \brief Get the image data from the file.
500 * If a LUT is found, the data are expanded to be RGB
502 uint8_t *FileHelper::GetRGBData()
504 return PixelReadConverter->GetRGB();
508 * \brief Get the image data size from the file.
509 * If a LUT is found, the data are expanded to be RGB
511 size_t FileHelper::GetRGBDataSize()
513 return PixelReadConverter->GetRGBSize();
517 * \brief Get the image data from the file.
518 * Even when a LUT is found, the data are not expanded to RGB!
520 uint8_t *FileHelper::GetRawData()
522 return PixelReadConverter->GetRaw();
526 * \brief Get the image data size from the file.
527 * Even when a LUT is found, the data are not expanded to RGB!
529 size_t FileHelper::GetRawDataSize()
531 return PixelReadConverter->GetRawSize();
535 * \brief Access to the underlying \ref PixelReadConverter RGBA LUT
537 uint8_t* FileHelper::GetLutRGBA()
539 if ( PixelReadConverter->GetLutRGBA() ==0 )
540 PixelReadConverter->BuildLUTRGBA();
541 return PixelReadConverter->GetLutRGBA();
545 * \brief Access to the underlying \ref PixelReadConverter RGBA LUT Item Number
547 int FileHelper::GetLutItemNumber()
549 return PixelReadConverter->GetLutItemNumber();
553 * \brief Access to the underlying \ref PixelReadConverter RGBA LUT Item Size
555 int FileHelper::GetLutItemSize()
557 return PixelReadConverter->GetLutItemSize();
561 * \brief Writes on disk A SINGLE Dicom file
562 * NO test is performed on processor "Endiannity".
563 * It's up to the user to call his Reader properly
564 * @param fileName name of the file to be created
565 * (any already existing file is over written)
566 * @return false if write fails
568 bool FileHelper::WriteRawData(std::string const &fileName)
570 std::ofstream fp1(fileName.c_str(), std::ios::out | std::ios::binary );
573 gdcmWarningMacro( "Fail to open (write) file:" << fileName.c_str());
577 if ( PixelWriteConverter->GetUserData() )
579 fp1.write( (char *)PixelWriteConverter->GetUserData(),
580 PixelWriteConverter->GetUserDataSize() );
582 else if ( PixelReadConverter->GetRGB() )
584 fp1.write( (char *)PixelReadConverter->GetRGB(),
585 PixelReadConverter->GetRGBSize());
587 else if ( PixelReadConverter->GetRaw() )
589 fp1.write( (char *)PixelReadConverter->GetRaw(),
590 PixelReadConverter->GetRawSize());
594 gdcmErrorMacro( "Nothing written." );
603 * \brief Writes on disk A SINGLE Dicom file,
604 * using the Implicit Value Representation convention
605 * NO test is performed on processor "Endianity".
606 * @param fileName name of the file to be created
607 * (any already existing file is overwritten)
608 * @return false if write fails
611 bool FileHelper::WriteDcmImplVR (std::string const &fileName)
613 SetWriteTypeToDcmImplVR();
614 return Write(fileName);
618 * \brief Writes on disk A SINGLE Dicom file,
619 * using the Explicit Value Representation convention
620 * NO test is performed on processor "Endiannity".
621 * @param fileName name of the file to be created
622 * (any already existing file is overwritten)
623 * @return false if write fails
626 bool FileHelper::WriteDcmExplVR (std::string const &fileName)
628 SetWriteTypeToDcmExplVR();
629 return Write(fileName);
633 * \brief Writes on disk A SINGLE Dicom file,
634 * using the ACR-NEMA convention
635 * NO test is performed on processor "Endiannity".
636 * (a l'attention des logiciels cliniques
637 * qui ne prennent en entrée QUE des images ACR ...
638 * \warning if a DICOM_V3 header is supplied,
639 * groups < 0x0008 and shadow groups are ignored
640 * \warning NO TEST is performed on processor "Endiannity".
641 * @param fileName name of the file to be created
642 * (any already existing file is overwritten)
643 * @return false if write fails
646 bool FileHelper::WriteAcr (std::string const &fileName)
649 return Write(fileName);
653 * \brief Writes on disk A SINGLE Dicom file,
654 * @param fileName name of the file to be created
655 * (any already existing file is overwritten)
656 * @return false if write fails
658 bool FileHelper::Write(std::string const &fileName)
663 SetWriteFileTypeToImplicitVR();
665 case Unknown: // should never happen; ExplicitVR is the default value
667 SetWriteFileTypeToExplicitVR();
671 // NOTHING is done here just for LibIDO.
672 // Just to avoid further trouble if user creates a file ex-nihilo,
673 // wants to write it as an ACR-NEMA file,
674 // and forgets to create any Entry belonging to group 0008
676 // We add Recognition Code (RET)
677 if ( ! FileInternal->GetDataEntry(0x0008, 0x0010) )
678 FileInternal->InsertEntryString("ACR-NEMA V1.0 ", 0x0008, 0x0010);
679 SetWriteFileTypeToACR();
680 // SetWriteFileTypeToImplicitVR(); // ACR IS implicit VR !
683 SetWriteFileTypeToJPEG();
684 std::cerr << "Writting as JPEG" << std::endl;
687 CheckMandatoryElements();
689 // --------------------------------------------------------------
690 // Special Patch to allow gdcm to re-write ACR-LibIDO formated images
692 // if recognition code tells us we dealt with a LibIDO image
693 // we reproduce on disk the switch between lineNumber and columnNumber
694 // just before writting ...
695 /// \todo the best trick would be *change* the recognition code
696 /// but pb expected if user deals with, e.g. COMPLEX images
698 if ( WriteType == ACR_LIBIDO )
704 SetWriteToNoLibido();
706 // ----------------- End of Special Patch ----------------
711 SetWriteToRaw(); // modifies and pushes to the archive, when necessary
714 SetWriteToRGB(); // modifies and pushes to the archive, when necessary
718 bool check = CheckWriteIntegrity(); // verifies length
719 if (WriteType == JPEG ) check = true;
722 check = FileInternal->Write(fileName,WriteType);
726 RestoreWriteFileType();
727 RestoreWriteMandatory();
729 // --------------------------------------------------------------
730 // Special Patch to allow gdcm to re-write ACR-LibIDO formated images
732 // ...and we restore the header to be Dicom Compliant again
733 // just after writting
734 RestoreWriteOfLibido();
735 // ----------------- End of Special Patch ----------------
740 //-----------------------------------------------------------------------------
743 * \brief Checks the write integrity
745 * The tests made are :
746 * - verify the size of the image to write with the possible write
747 * when the user set an image data
748 * @return true if check is successfull
750 bool FileHelper::CheckWriteIntegrity()
752 if ( PixelWriteConverter->GetUserData() )
754 int numberBitsAllocated = FileInternal->GetBitsAllocated();
755 if ( numberBitsAllocated == 0 || numberBitsAllocated == 12 )
757 gdcmWarningMacro( "numberBitsAllocated changed from "
758 << numberBitsAllocated << " to 16 "
759 << " for consistency purpose" );
760 numberBitsAllocated = 16;
763 size_t decSize = FileInternal->GetXSize()
764 * FileInternal->GetYSize()
765 * FileInternal->GetZSize()
766 * FileInternal->GetSamplesPerPixel()
767 * ( numberBitsAllocated / 8 );
768 size_t rgbSize = decSize;
769 if ( FileInternal->HasLUT() )
770 rgbSize = decSize * 3;
775 if ( decSize!=PixelWriteConverter->GetUserDataSize() )
777 gdcmWarningMacro( "Data size (Raw) is incorrect. Should be "
778 << decSize << " / Found :"
779 << PixelWriteConverter->GetUserDataSize() );
784 if ( rgbSize!=PixelWriteConverter->GetUserDataSize() )
786 gdcmWarningMacro( "Data size (RGB) is incorrect. Should be "
787 << decSize << " / Found "
788 << PixelWriteConverter->GetUserDataSize() );
799 * \brief Updates the File to write RAW data (as opposed to RGB data)
800 * (modifies, when necessary, photochromatic interpretation,
801 * bits allocated, Pixels element VR)
803 void FileHelper::SetWriteToRaw()
805 if ( FileInternal->GetNumberOfScalarComponents() == 3
806 && !FileInternal->HasLUT() )
812 DataEntry *photInt = CopyDataEntry(0x0028,0x0004);
813 if (FileInternal->HasLUT() )
815 photInt->SetString("PALETTE COLOR ");
819 photInt->SetString("MONOCHROME2 ");
822 PixelWriteConverter->SetReadData(PixelReadConverter->GetRaw(),
823 PixelReadConverter->GetRawSize());
825 std::string vr = "OB";
826 if ( FileInternal->GetBitsAllocated()>8 )
828 if ( FileInternal->GetBitsAllocated()==24 ) // For RGB ACR files
831 CopyDataEntry(GetFile()->GetGrPixel(),GetFile()->GetNumPixel(),vr);
832 pixel->SetFlag(DataEntry::FLAG_PIXELDATA);
833 pixel->SetBinArea(PixelWriteConverter->GetData(),false);
834 pixel->SetLength(PixelWriteConverter->GetDataSize());
836 Archive->Push(photInt);
837 Archive->Push(pixel);
845 * \brief Updates the File to write RGB data (as opposed to RAW data)
846 * (modifies, when necessary, photochromatic interpretation,
847 * samples per pixel, Planar configuration,
848 * bits allocated, bits stored, high bit -ACR 24 bits-
849 * Pixels element VR, pushes out the LUT, )
851 void FileHelper::SetWriteToRGB()
853 if ( FileInternal->GetNumberOfScalarComponents()==3 )
855 PixelReadConverter->BuildRGBImage();
857 DataEntry *spp = CopyDataEntry(0x0028,0x0002);
858 spp->SetString("3 ");
860 DataEntry *planConfig = CopyDataEntry(0x0028,0x0006);
861 planConfig->SetString("0 ");
863 DataEntry *photInt = CopyDataEntry(0x0028,0x0004);
864 photInt->SetString("RGB ");
866 if ( PixelReadConverter->GetRGB() )
868 PixelWriteConverter->SetReadData(PixelReadConverter->GetRGB(),
869 PixelReadConverter->GetRGBSize());
873 PixelWriteConverter->SetReadData(PixelReadConverter->GetRaw(),
874 PixelReadConverter->GetRawSize());
877 std::string vr = "OB";
878 if ( FileInternal->GetBitsAllocated()>8 )
880 if ( FileInternal->GetBitsAllocated()==24 ) // For RGB ACR files
883 CopyDataEntry(GetFile()->GetGrPixel(),GetFile()->GetNumPixel(),vr);
884 pixel->SetFlag(DataEntry::FLAG_PIXELDATA);
885 pixel->SetBinArea(PixelWriteConverter->GetData(),false);
886 pixel->SetLength(PixelWriteConverter->GetDataSize());
889 Archive->Push(planConfig);
890 Archive->Push(photInt);
891 Archive->Push(pixel);
894 planConfig->Delete();
899 Archive->Push(0x0028,0x1101);
900 Archive->Push(0x0028,0x1102);
901 Archive->Push(0x0028,0x1103);
902 Archive->Push(0x0028,0x1201);
903 Archive->Push(0x0028,0x1202);
904 Archive->Push(0x0028,0x1203);
906 // push out Palette Color Lookup Table UID, if any
907 Archive->Push(0x0028,0x1199);
909 // For old '24 Bits' ACR-NEMA
910 // Thus, we have a RGB image and the bits allocated = 24 and
911 // samples per pixels = 1 (in the read file)
912 if ( FileInternal->GetBitsAllocated()==24 )
914 DataEntry *bitsAlloc = CopyDataEntry(0x0028,0x0100);
915 bitsAlloc->SetString("8 ");
917 DataEntry *bitsStored = CopyDataEntry(0x0028,0x0101);
918 bitsStored->SetString("8 ");
920 DataEntry *highBit = CopyDataEntry(0x0028,0x0102);
921 highBit->SetString("7 ");
923 Archive->Push(bitsAlloc);
924 Archive->Push(bitsStored);
925 Archive->Push(highBit);
928 bitsStored->Delete();
939 * \brief Restore the File write mode
941 void FileHelper::RestoreWrite()
943 Archive->Restore(0x0028,0x0002);
944 Archive->Restore(0x0028,0x0004);
945 Archive->Restore(0x0028,0x0006);
946 Archive->Restore(GetFile()->GetGrPixel(),GetFile()->GetNumPixel());
948 // For old ACR-NEMA (24 bits problem)
949 Archive->Restore(0x0028,0x0100);
950 Archive->Restore(0x0028,0x0101);
951 Archive->Restore(0x0028,0x0102);
954 Archive->Restore(0x0028,0x1101);
955 Archive->Restore(0x0028,0x1102);
956 Archive->Restore(0x0028,0x1103);
957 Archive->Restore(0x0028,0x1201);
958 Archive->Restore(0x0028,0x1202);
959 Archive->Restore(0x0028,0x1203);
961 // For the Palette Color Lookup Table UID
962 Archive->Restore(0x0028,0x1203);
965 // group 0002 may be pushed out for ACR-NEMA writting purposes
966 Archive->Restore(0x0002,0x0000);
967 Archive->Restore(0x0002,0x0001);
968 Archive->Restore(0x0002,0x0002);
969 Archive->Restore(0x0002,0x0003);
970 Archive->Restore(0x0002,0x0010);
971 Archive->Restore(0x0002,0x0012);
972 Archive->Restore(0x0002,0x0013);
973 Archive->Restore(0x0002,0x0016);
974 Archive->Restore(0x0002,0x0100);
975 Archive->Restore(0x0002,0x0102);
979 * \brief Pushes out the whole group 0002
980 * FIXME : better, set a flag to tell the writer not to write it ...
981 * FIXME : method should probably have an other name !
982 * SetWriteFileTypeToACR is NOT opposed to
983 * SetWriteFileTypeToExplicitVR and SetWriteFileTypeToImplicitVR
985 void FileHelper::SetWriteFileTypeToACR()
987 Archive->Push(0x0002,0x0000);
988 Archive->Push(0x0002,0x0001);
989 Archive->Push(0x0002,0x0002);
990 Archive->Push(0x0002,0x0003);
991 Archive->Push(0x0002,0x0010);
992 Archive->Push(0x0002,0x0012);
993 Archive->Push(0x0002,0x0013);
994 Archive->Push(0x0002,0x0016);
995 Archive->Push(0x0002,0x0100);
996 Archive->Push(0x0002,0x0102);
1000 * \brief Sets in the File the TransferSyntax to 'Explicit VR Little Endian"
1002 void FileHelper::SetWriteFileTypeToJPEG()
1004 std::string ts = Util::DicomString(
1005 Global::GetTS()->GetSpecialTransferSyntax(TS::JPEGBaselineProcess1) );
1007 DataEntry *tss = CopyDataEntry(0x0002,0x0010);
1014 void FileHelper::SetWriteFileTypeToExplicitVR()
1016 std::string ts = Util::DicomString(
1017 Global::GetTS()->GetSpecialTransferSyntax(TS::ExplicitVRLittleEndian) );
1019 DataEntry *tss = CopyDataEntry(0x0002,0x0010);
1027 * \brief Sets in the File the TransferSyntax to 'Implicit VR Little Endian"
1029 void FileHelper::SetWriteFileTypeToImplicitVR()
1031 std::string ts = Util::DicomString(
1032 Global::GetTS()->GetSpecialTransferSyntax(TS::ImplicitVRLittleEndian) );
1034 DataEntry *tss = CopyDataEntry(0x0002,0x0010);
1043 * \brief Restore in the File the initial group 0002
1045 void FileHelper::RestoreWriteFileType()
1050 * \brief Set the Write not to Libido format
1052 void FileHelper::SetWriteToLibido()
1054 DataEntry *oldRow = FileInternal->GetDataEntry(0x0028, 0x0010);
1055 DataEntry *oldCol = FileInternal->GetDataEntry(0x0028, 0x0011);
1057 if ( oldRow && oldCol )
1059 std::string rows, columns;
1061 DataEntry *newRow=DataEntry::New(oldRow->GetDictEntry());
1062 DataEntry *newCol=DataEntry::New(oldCol->GetDictEntry());
1064 newRow->Copy(oldCol);
1065 newCol->Copy(oldRow);
1067 newRow->SetString(oldCol->GetString());
1068 newCol->SetString(oldRow->GetString());
1070 Archive->Push(newRow);
1071 Archive->Push(newCol);
1077 DataEntry *libidoCode = CopyDataEntry(0x0008,0x0010);
1078 libidoCode->SetString("ACRNEMA_LIBIDO_1.1");
1079 Archive->Push(libidoCode);
1080 libidoCode->Delete();
1084 * \brief Set the Write not to No Libido format
1086 void FileHelper::SetWriteToNoLibido()
1088 DataEntry *recCode = FileInternal->GetDataEntry(0x0008,0x0010);
1091 if ( recCode->GetString() == "ACRNEMA_LIBIDO_1.1" )
1093 DataEntry *libidoCode = CopyDataEntry(0x0008,0x0010);
1094 libidoCode->SetString("");
1095 Archive->Push(libidoCode);
1096 libidoCode->Delete();
1102 * \brief Restore the Write format
1104 void FileHelper::RestoreWriteOfLibido()
1106 Archive->Restore(0x0028,0x0010);
1107 Archive->Restore(0x0028,0x0011);
1108 Archive->Restore(0x0008,0x0010);
1110 // Restore 'LibIDO-special' entries, if any
1111 Archive->Restore(0x0028,0x0015);
1112 Archive->Restore(0x0028,0x0016);
1113 Archive->Restore(0x0028,0x0017);
1114 Archive->Restore(0x0028,0x00199);
1118 * \brief Duplicates a DataEntry or creates it.
1119 * @param group Group number of the Entry
1120 * @param elem Element number of the Entry
1121 * @param vr Value Representation of the Entry
1122 * FIXME : what is it used for?
1123 * \return pointer to the new Bin Entry (NULL when creation failed).
1125 DataEntry *FileHelper::CopyDataEntry(uint16_t group, uint16_t elem,
1128 DocEntry *oldE = FileInternal->GetDocEntry(group, elem);
1131 if ( oldE && vr != GDCM_VRUNKNOWN )
1132 if ( oldE->GetVR() != vr )
1137 newE = DataEntry::New(oldE->GetDictEntry());
1142 newE = GetFile()->NewDataEntry(group, elem, vr);
1149 * \brief This method is called automatically, just before writting
1150 * in order to produce a 'True Dicom V3' image
1151 * We cannot know *how* the user made the File (reading an old ACR-NEMA
1152 * file or a not very clean DICOM file ...)
1154 * Just before writting :
1155 * - we check the Entries
1156 * - we create the mandatory entries if they are missing
1157 * - we modify the values if necessary
1158 * - we push the sensitive entries to the Archive
1159 * The writing process will restore the entries as they where before
1160 * entering FileHelper::CheckMandatoryElements, so the user will always
1161 * see the entries just as he left them.
1163 * - Entries whose type is 1 are mandatory, with a mandatory value
1164 * - Entries whose type is 1c are mandatory-inside-a-Sequence,
1165 * with a mandatory value
1166 * - Entries whose type is 2 are mandatory, with an optional value
1167 * - Entries whose type is 2c are mandatory-inside-a-Sequence,
1168 * with an optional value
1169 * - Entries whose type is 3 are optional
1171 * \todo : - warn the user if we had to add some entries :
1172 * even if a mandatory entry is missing, we add it, with a default value
1173 * (we don't want to give up the writting process if user forgot to
1174 * specify Lena's Patient ID, for instance ...)
1175 * - read the whole PS 3.3 Part of DICOM (890 pages)
1176 * and write a *full* checker (probably one method per Modality ...)
1177 * Any contribution is welcome.
1178 * - write a user callable full checker, to allow post reading
1179 * and/or pre writting image consistency check.
1182 /* -------------------------------------------------------------------------------------
1183 To be moved to User's guide / WIKI ?
1186 -->'Media Storage SOP Class UID' (0x0002,0x0002)
1187 -->'SOP Class UID' (0x0008,0x0016) are set to
1188 [Secondary Capture Image Storage]
1189 (Potentialy, the image was modified by user, and post-processed;
1190 it's no longer a 'native' image)
1192 --> 'Image Type' (0x0008,0x0008)
1193 is forced to "DERIVED\PRIMARY"
1194 (The written image is no longer an 'ORIGINAL' one)
1196 --> 'Modality' (0x0008,0x0060)
1197 is defaulted to "OT" (other) if missing.
1198 (a fully user created image belongs to *no* modality)
1200 --> 'Media Storage SOP Instance UID' (0x0002,0x0003)
1201 --> 'Implementation Class UID' (0x0002,0x0012)
1202 are automatically generated; no user intervention possible
1204 --> 'Serie Instance UID'(0x0020,0x000e)
1205 --> 'Study Instance UID'(0x0020,0x000d) are kept as is if already exist
1206 created if it doesn't.
1207 The user is allowed to create his own Series/Studies,
1208 keeping the same 'Serie Instance UID' / 'Study Instance UID'
1211 The user shouldn't add any image to a 'Manufacturer Serie'
1212 but there is no way no to allowed him to do that
1215 --> If 'SOP Class UID' exists in the native image ('true DICOM' image)
1216 we create the 'Source Image Sequence' SeqEntry (0x0008, 0x2112)
1218 --> 'Referenced SOP Class UID' (0x0008, 0x1150)
1219 whose value is the original 'SOP Class UID'
1220 --> 'Referenced SOP Instance UID' (0x0008, 0x1155)
1221 whose value is the original 'SOP Class UID'
1223 --> Bits Stored, Bits Allocated, Hight Bit Position are checked for consistency
1224 --> Pixel Spacing (0x0028,0x0030) is defaulted to "1.0\1.0"
1225 --> Samples Per Pixel (0x0028,0x0002) is defaulted to 1 (grayscale)
1226 --> Imager Pixel Spacing (0x0018,0x1164) : defaulted to 1.0\1.0
1228 --> Instance Creation Date, Instance Creation Time, Study Date, Study Time
1229 are force to current Date and Time
1231 --> Conversion Type (0x0008,0x0064)
1232 is forced to 'SYN' (Synthetic Image)
1234 --> Patient Orientation : (0x0020,0x0020), if not present, is deduced from
1235 Image Orientation (Patient) : (0020|0037)
1237 --> Study ID, Series Number, Instance Number, Patient Orientation (Type 2)
1238 are created, with empty value if there are missing.
1240 --> Manufacturer, Institution Name, Patient's Name, (Type 2)
1241 are defaulted with a 'gdcm' value.
1243 --> Patient ID, Patient's Birth Date, Patient's Sex, (Type 2)
1244 --> Referring Physician's Name (Type 2)
1245 are created, with empty value if there are missing.
1247 -------------------------------------------------------------------------------------*/
1249 void FileHelper::CheckMandatoryElements()
1251 std::string sop = Util::CreateUniqueUID();
1253 // just to remember : 'official' 0002 group
1254 if ( WriteType != ACR && WriteType != ACR_LIBIDO )
1256 // Group 000002 (Meta Elements) already pushed out
1258 //0002 0000 UL 1 Meta Group Length
1259 //0002 0001 OB 1 File Meta Information Version
1260 //0002 0002 UI 1 Media Stored SOP Class UID
1261 //0002 0003 UI 1 Media Stored SOP Instance UID
1262 //0002 0010 UI 1 Transfer Syntax UID
1263 //0002 0012 UI 1 Implementation Class UID
1264 //0002 0013 SH 1 Implementation Version Name
1265 //0002 0016 AE 1 Source Application Entity Title
1266 //0002 0100 UI 1 Private Information Creator
1267 //0002 0102 OB 1 Private Information
1269 // Create them if not found
1270 // Always modify the value
1271 // Push the entries to the archive.
1272 CopyMandatoryEntry(0x0002,0x0000,"0");
1274 DataEntry *e_0002_0001 = CopyDataEntry(0x0002,0x0001, "OB");
1275 e_0002_0001->SetBinArea((uint8_t*)Util::GetFileMetaInformationVersion(),
1277 e_0002_0001->SetLength(2);
1278 Archive->Push(e_0002_0001);
1279 e_0002_0001->Delete();
1281 // FIXME : we should allow user to tell he *wants* to keep the original
1282 // 'Media Storage SOP Class UID'
1283 // Potentialy this is a post-processed image
1284 // 'Media Storage SOP Class UID' --> [Secondary Capture Image Storage]
1286 CopyMandatoryEntry(0x0002,0x0002,"1.2.840.10008.5.1.4.1.1.7");
1288 // 'Media Storage SOP Instance UID'
1289 CopyMandatoryEntry(0x0002,0x0003,sop);
1291 // 'Implementation Class UID'
1292 CopyMandatoryEntry(0x0002,0x0012,Util::CreateUniqueUID());
1294 // 'Implementation Version Name'
1295 std::string version = "GDCM ";
1296 version += Util::GetVersion();
1297 CopyMandatoryEntry(0x0002,0x0013,version);
1300 // Push out 'LibIDO-special' entries, if any
1301 Archive->Push(0x0028,0x0015);
1302 Archive->Push(0x0028,0x0016);
1303 Archive->Push(0x0028,0x0017);
1304 Archive->Push(0x0028,0x00199);
1306 // Deal with the pb of (Bits Stored = 12)
1307 // - we're gonna write the image as Bits Stored = 16
1308 if ( FileInternal->GetEntryString(0x0028,0x0100) == "12")
1310 CopyMandatoryEntry(0x0028,0x0100,"16");
1313 // Check if user wasn't drunk ;-)
1315 std::ostringstream s;
1316 // check 'Bits Allocated' vs decent values
1317 int nbBitsAllocated = FileInternal->GetBitsAllocated();
1318 if ( nbBitsAllocated == 0 || nbBitsAllocated > 32)
1320 CopyMandatoryEntry(0x0028,0x0100,"16");
1321 gdcmWarningMacro("(0028,0100) changed from "
1322 << nbBitsAllocated << " to 16 for consistency purpose");
1323 nbBitsAllocated = 16;
1325 // check 'Bits Stored' vs 'Bits Allocated'
1326 int nbBitsStored = FileInternal->GetBitsStored();
1327 if ( nbBitsStored == 0 || nbBitsStored > nbBitsAllocated )
1330 s << nbBitsAllocated;
1331 CopyMandatoryEntry(0x0028,0x0101,s.str());
1332 gdcmWarningMacro("(0028,0101) changed from "
1333 << nbBitsStored << " to " << nbBitsAllocated
1334 << " for consistency purpose" );
1335 nbBitsStored = nbBitsAllocated;
1337 // check 'Hight Bit Position' vs 'Bits Allocated' and 'Bits Stored'
1338 int highBitPosition = FileInternal->GetHighBitPosition();
1339 if ( highBitPosition == 0 ||
1340 highBitPosition > nbBitsAllocated-1 ||
1341 highBitPosition < nbBitsStored-1 )
1344 s << nbBitsStored - 1;
1345 CopyMandatoryEntry(0x0028,0x0102,s.str());
1346 gdcmWarningMacro("(0028,0102) changed from "
1347 << highBitPosition << " to " << nbBitsAllocated-1
1348 << " for consistency purpose");
1351 // Imager Pixel Spacing : defaulted to 1.0\1.0
1352 // --> This one is the *legal* one !
1353 // FIXME : we should write it only when we are *sure* the image comes from
1354 // an imager (see also 0008,0x0064)
1355 CheckMandatoryEntry(0x0018,0x1164,"1.0\\1.0");
1356 // Pixel Spacing : defaulted to 1.0\1.0
1357 CheckMandatoryEntry(0x0028,0x0030,"1.0\\1.0");
1359 // Samples Per Pixel (type 1) : default to grayscale
1360 CheckMandatoryEntry(0x0028,0x0002,"1");
1362 // --- Check UID-related Entries ---
1364 // If 'SOP Class UID' exists ('true DICOM' image)
1365 // we create the 'Source Image Sequence' SeqEntry
1366 // to hold informations about the Source Image
1368 DataEntry *e_0008_0016 = FileInternal->GetDataEntry(0x0008, 0x0016);
1371 // Create 'Source Image Sequence' SeqEntry
1372 SeqEntry *sis = SeqEntry::New (
1373 Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x2112) );
1374 SQItem *sqi = SQItem::New(1);
1375 // (we assume 'SOP Instance UID' exists too)
1376 // create 'Referenced SOP Class UID'
1377 DataEntry *e_0008_1150 = DataEntry::New(
1378 Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x1150) );
1379 e_0008_1150->SetString( e_0008_0016->GetString());
1380 sqi->AddEntry(e_0008_1150);
1381 e_0008_1150->Delete();
1383 // create 'Referenced SOP Instance UID'
1384 DataEntry *e_0008_0018 = FileInternal->GetDataEntry(0x0008, 0x0018);
1385 DataEntry *e_0008_1155 = DataEntry::New(
1386 Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x1155) );
1387 e_0008_1155->SetString( e_0008_0018->GetString());
1388 sqi->AddEntry(e_0008_1155);
1389 e_0008_1155->Delete();
1391 sis->AddSQItem(sqi,1);
1394 // temporarily replaces any previous 'Source Image Sequence'
1398 // FIXME : is 'Image Type' *really* depending on the presence of'SOP Class UID'?
1400 // 'Image Type' (The written image is no longer an 'ORIGINAL' one)
1401 CopyMandatoryEntry(0x0008,0x0008,"DERIVED\\PRIMARY");
1404 // At the end, not to overwrite the original ones,
1405 // needed by 'Referenced SOP Instance UID', 'Referenced SOP Class UID'
1406 // 'SOP Instance UID'
1407 CopyMandatoryEntry(0x0008,0x0018,sop);
1409 // whether a 'SOP Class UID' already exists or not in the original image
1410 // the gdcm written image *is* a [Secondary Capture Image Storage] !
1411 // 'SOP Class UID' : [Secondary Capture Image Storage]
1412 CopyMandatoryEntry(0x0008,0x0016,"1.2.840.10008.5.1.4.1.1.7");
1414 // ---- The user will never have to take any action on the following ----.
1415 // new value for 'SOP Instance UID'
1416 //SetMandatoryEntry(0x0008,0x0018,Util::CreateUniqueUID());
1418 // Instance Creation Date
1419 const std::string &date = Util::GetCurrentDate();
1420 CopyMandatoryEntry(0x0008,0x0012,date);
1422 // Instance Creation Time
1423 const std::string &time = Util::GetCurrentTime();
1424 CopyMandatoryEntry(0x0008,0x0013,time);
1427 CopyMandatoryEntry(0x0008,0x0020,date);
1429 CopyMandatoryEntry(0x0008,0x0030,time);
1432 //CopyMandatoryEntry(0x0008,0x0050,"");
1433 CheckMandatoryEntry(0x0008,0x0050,"");
1436 // Other possible values are :
1437 // See PS 3.3, Page 408
1439 // DV = Digitized Video
1440 // DI = Digital Interface
1441 // DF = Digitized Film
1442 // WSD = Workstation
1443 // SD = Scanned Document
1444 // SI = Scanned Image
1446 // SYN = Synthetic Image
1448 // FIXME : Must we Force Value, or Default value ?
1449 // Is it Type 1 for any Modality ?
1450 // --> Answer seems to be NO :-(
1451 // FIXME : we should write it only when we are *sure* the image
1452 // *does not* come from an imager (see also 0018,0x1164)
1453 CopyMandatoryEntry(0x0008,0x0064,"SYN");
1455 // ----- Add Mandatory Entries if missing ---
1456 // Entries whose type is 1 are mandatory, with a mandatory value
1457 // Entries whose type is 1c are mandatory-inside-a-Sequence,
1458 // with a mandatory value
1459 // Entries whose type is 2 are mandatory, with an optional value
1460 // Entries whose type is 2c are mandatory-inside-a-Sequence,
1461 // with an optional value
1462 // Entries whose type is 3 are optional
1464 // 'Study Instance UID'
1465 // Keep the value if exists
1466 // The user is allowed to create his own Study,
1467 // keeping the same 'Study Instance UID' for various images
1468 // The user may add images to a 'Manufacturer Study',
1469 // adding new Series to an already existing Study
1470 CheckMandatoryEntry(0x0020,0x000d,Util::CreateUniqueUID());
1472 // 'Serie Instance UID'
1473 // Keep the value if exists
1474 // The user is allowed to create his own Series,
1475 // keeping the same 'Serie Instance UID' for various images
1476 // The user shouldn't add any image to a 'Manufacturer Serie'
1477 // but there is no way no to prevent him for doing that
1478 CheckMandatoryEntry(0x0020,0x000e,Util::CreateUniqueUID());
1481 CheckMandatoryEntry(0x0020,0x0010,"");
1484 CheckMandatoryEntry(0x0020,0x0011,"");
1487 CheckMandatoryEntry(0x0020,0x0013,"");
1489 // Patient Orientation
1490 // Can be computed from (0020|0037) : Image Orientation (Patient)
1491 gdcm::Orientation o;
1492 std::string ori = o.GetOrientation ( FileInternal );
1494 CheckMandatoryEntry(0x0020,0x0020,ori);
1496 CheckMandatoryEntry(0x0020,0x0020,"");
1498 // Modality : if missing we set it to 'OTher'
1499 CheckMandatoryEntry(0x0008,0x0060,"OT");
1501 // Manufacturer : if missing we set it to 'GDCM Factory'
1502 CheckMandatoryEntry(0x0008,0x0070,"GDCM Factory");
1504 // Institution Name : if missing we set it to 'GDCM Hospital'
1505 CheckMandatoryEntry(0x0008,0x0080,"GDCM Hospital");
1507 // Patient's Name : if missing, we set it to 'GDCM^Patient'
1508 CheckMandatoryEntry(0x0010,0x0010,"GDCM^Patient");
1511 CheckMandatoryEntry(0x0010,0x0020,"");
1513 // Patient's Birth Date : 'type 2' entry -> must exist, value not mandatory
1514 CheckMandatoryEntry(0x0010,0x0030,"");
1516 // Patient's Sex :'type 2' entry -> must exist, value not mandatory
1517 CheckMandatoryEntry(0x0010,0x0040,"");
1519 // Referring Physician's Name :'type 2' entry -> must exist, value not mandatory
1520 CheckMandatoryEntry(0x0008,0x0090,"");
1522 // Remove some inconstencies (probably some more will be added)
1524 // if (0028 0008)Number of Frames exists
1525 // Push out (0020 0052),Frame of Reference UID
1526 // (only meaningfull within a Serie)
1527 DataEntry *e_0028_0008 = FileInternal->GetDataEntry(0x0028, 0x0008);
1530 Archive->Push(0x0020, 0x0052);
1534 void FileHelper::CheckMandatoryEntry(uint16_t group,uint16_t elem,std::string value)
1536 DataEntry *entry = FileInternal->GetDataEntry(group,elem);
1539 entry = DataEntry::New(Global::GetDicts()->GetDefaultPubDict()->GetEntry(group,elem));
1540 entry->SetString(value);
1541 Archive->Push(entry);
1546 void FileHelper::SetMandatoryEntry(uint16_t group,uint16_t elem,std::string value)
1548 DataEntry *entry = DataEntry::New(Global::GetDicts()->GetDefaultPubDict()->GetEntry(group,elem));
1549 entry->SetString(value);
1550 Archive->Push(entry);
1554 void FileHelper::CopyMandatoryEntry(uint16_t group,uint16_t elem,std::string value)
1556 DataEntry *entry = CopyDataEntry(group,elem);
1557 entry->SetString(value);
1558 Archive->Push(entry);
1563 * \brief Restore in the File the initial group 0002
1565 void FileHelper::RestoreWriteMandatory()
1567 // group 0002 may be pushed out for ACR-NEMA writting purposes
1568 Archive->Restore(0x0002,0x0000);
1569 Archive->Restore(0x0002,0x0001);
1570 Archive->Restore(0x0002,0x0002);
1571 Archive->Restore(0x0002,0x0003);
1572 Archive->Restore(0x0002,0x0010);
1573 Archive->Restore(0x0002,0x0012);
1574 Archive->Restore(0x0002,0x0013);
1575 Archive->Restore(0x0002,0x0016);
1576 Archive->Restore(0x0002,0x0100);
1577 Archive->Restore(0x0002,0x0102);
1579 Archive->Restore(0x0008,0x0012);
1580 Archive->Restore(0x0008,0x0013);
1581 Archive->Restore(0x0008,0x0016);
1582 Archive->Restore(0x0008,0x0018);
1583 Archive->Restore(0x0008,0x0060);
1584 Archive->Restore(0x0008,0x0070);
1585 Archive->Restore(0x0008,0x0080);
1586 Archive->Restore(0x0008,0x0090);
1587 Archive->Restore(0x0008,0x2112);
1589 Archive->Restore(0x0010,0x0010);
1590 Archive->Restore(0x0010,0x0030);
1591 Archive->Restore(0x0010,0x0040);
1593 Archive->Restore(0x0020,0x000d);
1594 Archive->Restore(0x0020,0x000e);
1597 //-----------------------------------------------------------------------------
1600 * \brief Factorization for various forms of constructors.
1602 void FileHelper::Initialize()
1606 WriteMode = WMODE_RAW;
1607 WriteType = ExplicitVR;
1609 PixelReadConverter = new PixelReadConvert;
1610 PixelWriteConverter = new PixelWriteConvert;
1611 Archive = new DocEntryArchive( FileInternal );
1615 * \brief Reads/[decompresses] the pixels,
1616 * *without* making RGB from Palette Colors
1617 * @return the pixels area, whatever its type
1618 * (uint8_t is just for prototyping : feel free to Cast it)
1620 uint8_t *FileHelper::GetRaw()
1622 PixelReadConverter->SetUserFunction( UserFunction );
1624 uint8_t *raw = PixelReadConverter->GetRaw();
1627 // The Raw image migth not be loaded yet:
1628 std::ifstream *fp = FileInternal->OpenFile();
1629 PixelReadConverter->ReadAndDecompressPixelData( fp );
1631 FileInternal->CloseFile();
1633 raw = PixelReadConverter->GetRaw();
1636 gdcmWarningMacro( "Read/decompress of pixel data apparently went wrong.");
1643 //-----------------------------------------------------------------------------
1645 * \brief Prints the common part of DataEntry, SeqEntry
1646 * @param os ostream we want to print in
1647 * @param indent (unused)
1649 void FileHelper::Print(std::ostream &os, std::string const &)
1651 FileInternal->SetPrintLevel(PrintLevel);
1652 FileInternal->Print(os);
1654 if ( FileInternal->IsReadable() )
1656 PixelReadConverter->SetPrintLevel(PrintLevel);
1657 PixelReadConverter->Print(os);
1661 //-----------------------------------------------------------------------------
1662 } // end namespace gdcm