Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

gdcm::FileHelper Class Reference

In addition to Dicom header exploration, this class is designed for accessing the image/volume content. One can also use it to write Dicom/ACR-NEMA/RAW files. More...

#include <gdcmFileHelper.h>

Inheritance diagram for gdcm::FileHelper:

Inheritance graph
[legend]
Collaboration diagram for gdcm::FileHelper:

Collaboration graph
[legend]
List of all members.

Public Types

enum  FileMode { WMODE_RAW, WMODE_RGB }

Public Member Functions

void Print (std::ostream &os=std::cout, std::string const &indent="")
 Prints the common part of DataEntry, SeqEntry.
FileGetFile ()
 Accessor to File.
void SetLoadMode (int loadMode)
 Sets the LoadMode of the internal gdcm::File as a boolean string. NO_SEQ, NO_SHADOW, NO_SHADOWSEQ ... (nothing more, right now) WARNING : before using NO_SHADOW, be sure *all* your files contain accurate values in the 0x0000 element (if any) of *each* Shadow Group. The parser will fail if the size is wrong !
void SetFileName (std::string const &fileName)
 Sets the LoadMode of the internal gdcm::File.
bool Load ()
 Loader.
void SetUserFunction (VOID_FUNCTION_PUINT8_PFILE_POINTER userFunc)
 to allow user to modify pixel order (e.g. Mirror, UpsideDown,...)
bool SetEntryString (std::string const &content, uint16_t group, uint16_t elem)
 Accesses an existing DataEntry through it's (group, element) and modifies it's content with the given value.
bool SetEntryBinArea (uint8_t *content, int lgth, uint16_t group, uint16_t elem)
 Accesses an existing DataEntry through it's (group, element) and modifies it's content with the given value.
DataEntryInsertEntryString (std::string const &content, uint16_t group, uint16_t elem)
 Modifies the value of a given DataEntry when it exists. Creates it with the given value when unexistant.
DataEntryInsertEntryBinArea (uint8_t *binArea, int lgth, uint16_t group, uint16_t elem)
 Modifies the value of a given DataEntry when it exists. Creates it with the given value when unexistant. A copy of the binArea is made to be kept in the Document.
SeqEntryInsertSeqEntry (uint16_t group, uint16_t elem)
 Adds an empty SeqEntry (remove any existing entry with same group,elem).
size_t GetImageDataSize ()
 Get the size of the image data If the image can be RGB (with a lut or by default), the size corresponds to the RGB image (use GetImageDataRawSize if you want to be sure to get *only* the size of the pixels).
size_t GetImageDataRawSize ()
 Get the size of the image data. If the image could be converted to RGB using a LUT, this transformation is not taken into account by GetImageDataRawSize (use GetImageDataSize if you wish).
uint8_t * GetImageData ()
 brings pixels into memory :
  • Allocates necessary memory,
  • Reads the pixels from disk (uncompress if necessary),
  • Transforms YBR pixels, if any, into RGB pixels,
  • Transforms 3 planes R, G, B, if any, into a single RGB Plane
  • Transforms single Grey plane + 3 Palettes into a RGB Plane
  • Copies the pixel data (image[s]/volume[s]) to newly allocated zone.

uint8_t * GetImageDataRaw ()
 brings pixels into memory :
  • Allocates necessary memory,
  • Transforms YBR pixels (if any) into RGB pixels
  • Transforms 3 planes R, G, B (if any) into a single RGB Plane
  • Copies the pixel data (image[s]/volume[s]) to newly allocated zone.
  • DOES NOT transform Grey plane + 3 Palettes into a RGB Plane

 GDCM_LEGACY (size_t GetImageDataIntoVector(void *destination, size_t maxSize))
void SetImageData (uint8_t *data, size_t expectedSize)
 Points the internal pointer to the callers inData image representation, BUT WITHOUT COPYING THE DATA. 'image' Pixels are presented as C-like 2D arrays : line per line. 'volume'Pixels are presented as C-like 3D arrays : plane per plane.
void SetUserData (uint8_t *data, size_t expectedSize)
 Set the image data defined by the user.
uint8_t * GetUserData ()
 Get the image data defined by the user.
size_t GetUserDataSize ()
 Get the image data size defined by the user.
uint8_t * GetRGBData ()
 Get the image data from the file. If a LUT is found, the data are expanded to be RGB.
size_t GetRGBDataSize ()
 Get the image data size from the file. If a LUT is found, the data are expanded to be RGB.
uint8_t * GetRawData ()
 Get the image data from the file. Even when a LUT is found, the data are not expanded to RGB!
size_t GetRawDataSize ()
 Get the image data size from the file. Even when a LUT is found, the data are not expanded to RGB!
uint8_t * GetLutRGBA ()
 Access to the underlying PixelReadConverter RGBA LUT.
int GetLutItemNumber ()
 Access to the underlying PixelReadConverter RGBA LUT Item Number.
int GetLutItemSize ()
 Access to the underlying PixelReadConverter RGBA LUT Item Size.
void SetWriteModeToRaw ()
 Tells the writer we want to keep 'Grey pixels + Palettes color' when possible (as opposed to convert 'Palettes color' to RGB).
void SetWriteModeToRGB ()
 Tells the writer we want to write RGB image when possible (as opposed to 'Grey pixels + Palettes color').
void SetWriteMode (FileMode mode)
 Sets the Write Mode ( ).
FileMode GetWriteMode ()
 Gets the Write Mode ( ).
void SetWriteTypeToDcmImplVR ()
 Tells the writer we want to write as Implicit VR.
void SetWriteTypeToDcmExplVR ()
 Tells the writer we want to write as Explicit VR.
void SetWriteTypeToAcr ()
 Tells the writer we want to write as ACR-NEMA.
void SetWriteTypeToAcrLibido ()
 Tells the writer we want to write as LibIDO.
void SetWriteTypeToJPEG ()
 Tells the writer we want to write as JPEG.
void SetWriteType (FileType format)
 Tells the writer which format we want to write (ImplicitVR, ExplicitVR, ACR, ACR_LIBIDO).
FileType GetWriteType ()
 Gets the format we talled the write we wanted to write (ImplicitVR, ExplicitVR, ACR, ACR_LIBIDO).
bool WriteRawData (std::string const &fileName)
 Writes on disk A SINGLE Dicom file NO test is performed on processor "Endiannity". It's up to the user to call his Reader properly.
bool WriteDcmImplVR (std::string const &fileName)
 Writes on disk A SINGLE Dicom file, using the Implicit Value Representation convention NO test is performed on processor "Endianity".
bool WriteDcmExplVR (std::string const &fileName)
 Writes on disk A SINGLE Dicom file, using the Explicit Value Representation convention NO test is performed on processor "Endiannity".
bool WriteAcr (std::string const &fileName)
 Writes on disk A SINGLE Dicom file, using the ACR-NEMA convention NO test is performed on processor "Endiannity". (a l'attention des logiciels cliniques qui ne prennent en entrée QUE des images ACR ...
bool Write (std::string const &fileName)
 Writes on disk A SINGLE Dicom file,.
void SetKeepMediaStorageSOPClassUID (bool v)
 if user knows he didn't modify the pixels (e.g. he just anonymized the file), he is allowed to ask to keep the original 'Media Storage SOP Class UID' and 'Image Type'
void CallStartMethod ()
 CallStartMethod.
void CallProgressMethod ()
 CallProgressMethod.
void CallEndMethod ()
 CallEndMethod.
void Delete ()
 Delete the object.
void Register ()
 Register the object.
void Unregister ()
 Unregister the object.
const unsigned long & GetRefCount () const
 Get the reference counting.
void SetPrintLevel (int level)
 Sets the print level for the Dicom Header Elements.
int GetPrintLevel ()
 Gets the print level for the Dicom Entries.

Static Public Member Functions

static FileHelperNew ()
 Constructs a FileHelper with a RefCounter.
static FileHelperNew (File *header)
 Constructs a FileHelper with a RefCounter from a fileHelper.

Protected Member Functions

 FileHelper ()
 Constructor dedicated to deal with the *pixels* area of a ACR/DICOMV3 file (gdcm::File only deals with the ... header) Opens (in read only and when possible) an existing file and checks for DICOM compliance. Returns NULL on failure. It will be up to the user to load the pixels into memory ( GetImageDataSize() + GetImageData() methods).
 FileHelper (File *header)
 Constructor dedicated to deal with the *pixels* area of a ACR/DICOMV3 file (File only deals with the ... header) Opens (in read only and when possible) an existing file and checks for DICOM compliance. Returns NULL on failure. It will be up to the user to load the pixels into memory ( GetImageDataSize() + GetImageData() methods).
 ~FileHelper ()
 canonical destructor
bool CheckWriteIntegrity ()
 Checks the write integrity.
void SetWriteToRaw ()
 Updates the File to write RAW data (as opposed to RGB data) (modifies, when necessary, photochromatic interpretation, bits allocated, Pixels element VR).
void SetWriteToRGB ()
 Updates the File to write RGB data (as opposed to RAW data) (modifies, when necessary, photochromatic interpretation, samples per pixel, Planar configuration, bits allocated, bits stored, high bit -ACR 24 bits- Pixels element VR, pushes out the LUT, ).
void RestoreWrite ()
 Restore the File write mode.
void SetWriteFileTypeToACR ()
 Pushes out the whole group 0002 FIXME : better, set a flag to tell the writer not to write it ... FIXME : method should probably have an other name ! SetWriteFileTypeToACR is NOT opposed to SetWriteFileTypeToExplicitVR and SetWriteFileTypeToImplicitVR.
void SetWriteFileTypeToJPEG ()
 Sets in the File the TransferSyntax to 'Explicit VR Little Endian".
void SetWriteFileTypeToExplicitVR ()
void SetWriteFileTypeToImplicitVR ()
 Sets in the File the TransferSyntax to 'Implicit VR Little Endian".
void RestoreWriteFileType ()
 Restore in the File the initial group 0002.
void SetWriteToLibido ()
 Set the Write not to Libido format.
void SetWriteToNoLibido ()
 Set the Write not to No Libido format.
void RestoreWriteOfLibido ()
 Restore the Write format.
DataEntryCopyDataEntry (uint16_t group, uint16_t elem, const TagName &vr=GDCM_VRUNKNOWN)
 Duplicates a DataEntry or creates it.
void CheckMandatoryElements ()
 This method is called automatically, just before writting in order to produce a 'True Dicom V3' image.
void CheckMandatoryEntry (uint16_t group, uint16_t elem, std::string value)
void SetMandatoryEntry (uint16_t group, uint16_t elem, std::string value)
void CopyMandatoryEntry (uint16_t group, uint16_t elem, std::string value)
void RestoreWriteMandatory ()
 Restore in the File the initial group 0002.

Protected Attributes

float Progress
 value of the ??? for any progress bar
bool Abort
int PrintLevel
 Amount of printed details for each Dicom Entries : 0 : stands for the least detail level.

Private Member Functions

 gdcmTypeMacro (FileHelper)
void Initialize ()
 Factorization for various forms of constructors.
uint8_t * GetRaw ()
 Reads/[decompresses] the pixels, *without* making RGB from Palette Colors.

Private Attributes

FileFileInternal
 gdcm::File to use to load the file
bool Parsed
 Whether already parsed or not.
PixelReadConvertPixelReadConverter
 Pointer to the PixelReadConverter.
PixelWriteConvertPixelWriteConverter
 Pointer to the PixelWriteConverter.
DocEntryArchiveArchive
 Pointer to the DocEntryArchive (used while writting process).
FileMode WriteMode
 (WMODE_RAW, WMODE_RGB)
FileType WriteType
 (ImplicitVR, ExplicitVR, ACR, ACR_LIBIDO)
VOID_FUNCTION_PUINT8_PFILE_POINTER UserFunction
 Pointer to a user supplied function to allow modification of pixel order (e.g. : Mirror, UpsideDown, 90°Rotation, ...) use as : void userSuppliedFunction(uint8_t *im, gdcm::File *f) NB : the "uint8_t *" type of first param is just for prototyping. User will Cast it according what he founds with f->GetPixelType() See vtkgdcmSerieViewer for an example.
bool KeepMediaStorageSOPClassUID
 if user knows he didn't modify the pixels (e.g. he just anonymized the file), he is allowed to ask to keep the original 'Media Storage SOP Class UID' and 'Image Type'

Detailed Description

In addition to Dicom header exploration, this class is designed for accessing the image/volume content. One can also use it to write Dicom/ACR-NEMA/RAW files.

Definition at line 43 of file gdcmFileHelper.h.


Member Enumeration Documentation

enum gdcm::FileHelper::FileMode
 

Enumerator:
WMODE_RAW 
WMODE_RGB 

Definition at line 48 of file gdcmFileHelper.h.

00049    {
00050       WMODE_RAW,
00051       WMODE_RGB
00052    };


Constructor & Destructor Documentation

gdcm::FileHelper::FileHelper  )  [protected]
 

Constructor dedicated to deal with the *pixels* area of a ACR/DICOMV3 file (gdcm::File only deals with the ... header) Opens (in read only and when possible) an existing file and checks for DICOM compliance. Returns NULL on failure. It will be up to the user to load the pixels into memory ( GetImageDataSize() + GetImageData() methods).

Note:
the in-memory representation of all available tags found in the DICOM header is post-poned to first header information access. This avoid a double parsing of public part of the header when one sets an a posteriori shadow dictionary (efficiency can be seen as a side effect).

Definition at line 133 of file gdcmFileHelper.cxx.

References FileInternal, Initialize(), and gdcm::File::New().

00134 { 
00135    FileInternal = File::New( );
00136    Initialize();
00137 }

gdcm::FileHelper::FileHelper File header  )  [protected]
 

Constructor dedicated to deal with the *pixels* area of a ACR/DICOMV3 file (File only deals with the ... header) Opens (in read only and when possible) an existing file and checks for DICOM compliance. Returns NULL on failure. It will be up to the user to load the pixels into memory ( GetImageDataSize() + GetImageData() methods).

Note:
the in-memory representation of all available tags found in the DICOM header is post-poned to first header information access. This avoid a double parsing of public part of the header when user sets an a posteriori shadow dictionary (efficiency can be seen as a side effect).
Parameters:
header already built Header

Definition at line 153 of file gdcmFileHelper.cxx.

References FileInternal, gdcmAssertMacro, gdcm::PixelReadConvert::GrabInformationsFromFile(), Initialize(), gdcm::File::IsReadable(), PixelReadConverter, and gdcm::RefCounter::Register().

00154 {
00155    gdcmAssertMacro(header);
00156 
00157    FileInternal = header;
00158    FileInternal->Register();
00159    Initialize();
00160    if ( FileInternal->IsReadable() )
00161    {
00162       PixelReadConverter->GrabInformationsFromFile( FileInternal, this );
00163    }
00164 }

gdcm::FileHelper::~FileHelper  )  [protected]
 

canonical destructor

Note:
If the header (gdcm::File) was created by the FileHelper constructor, it is destroyed by the FileHelper

Definition at line 171 of file gdcmFileHelper.cxx.

References Archive, FileInternal, PixelReadConverter, PixelWriteConverter, and gdcm::RefCounter::Unregister().

00172 { 
00173    if ( PixelReadConverter )
00174    {
00175       delete PixelReadConverter;
00176    }
00177    if ( PixelWriteConverter )
00178    {
00179       delete PixelWriteConverter;
00180    }
00181    if ( Archive )
00182    {
00183       delete Archive;
00184    }
00185 
00186    FileInternal->Unregister();
00187 }


Member Function Documentation

void gdcm::FileHelper::CallEndMethod  ) 
 

CallEndMethod.

Definition at line 1751 of file gdcmFileHelper.cxx.

References gdcm::CMD_ENDPROGRESS, gdcm::CommandManager::ExecuteCommand(), and Progress.

01752 {
01753    Progress = 1.0f;
01754    CommandManager::ExecuteCommand(this,CMD_ENDPROGRESS);
01755 }

void gdcm::FileHelper::CallProgressMethod  ) 
 

CallProgressMethod.

Definition at line 1743 of file gdcmFileHelper.cxx.

References gdcm::CMD_PROGRESS, and gdcm::CommandManager::ExecuteCommand().

01744 {
01745    CommandManager::ExecuteCommand(this,CMD_PROGRESS);
01746 }

void gdcm::FileHelper::CallStartMethod  ) 
 

CallStartMethod.

Definition at line 1733 of file gdcmFileHelper.cxx.

References Abort, gdcm::CMD_STARTPROGRESS, gdcm::CommandManager::ExecuteCommand(), and Progress.

01734 {
01735    Progress = 0.0f;
01736    Abort    = false;
01737    CommandManager::ExecuteCommand(this,CMD_STARTPROGRESS);
01738 }

void gdcm::FileHelper::CheckMandatoryElements  )  [protected]
 

This method is called automatically, just before writting in order to produce a 'True Dicom V3' image.

We cannot know *how* the user made the File : (reading an old ACR-NEMA file or a not very clean DICOM file ...) Just before writting :

  • we check the Entries
  • we create the mandatory entries if they are missing
  • we modify the values if necessary
  • we push the sensitive entries to the Archive The writing process will restore the entries as they where before entering FileHelper::CheckMandatoryElements, so the user will always see the entries just as they were before he decided to write.

Note:
  • Entries whose type is 1 are mandatory, with a mandatory value
  • Entries whose type is 1c are mandatory-inside-a-Sequence, with a mandatory value
  • Entries whose type is 2 are mandatory, with an optional value
  • Entries whose type is 2c are mandatory-inside-a-Sequence, with an optional value
  • Entries whose type is 3 are optional
Todo:
  • warn the user if we had to add some entries : even if a mandatory entry is missing, we add it, with a default value (we don't want to give up the writting process if user forgot to specify Lena's Patient ID, for instance ...)
  • read the whole PS 3.3 Part of DICOM (890 pages) and write a *full* checker (probably one method per Modality ...) Any contribution is welcome.
  • write a user callable full checker, to allow post reading and/or pre writting image consistency check.

Definition at line 1327 of file gdcmFileHelper.cxx.

References gdcm::ACR, gdcm::ACR_LIBIDO, gdcm::SQItem::AddEntry(), gdcm::SeqEntry::AddSQItem(), Archive, CheckMandatoryEntry(), CopyDataEntry(), CopyMandatoryEntry(), gdcm::Util::CreateUniqueUID(), gdcm::RefCounter::Delete(), FileInternal, gdcm::GDCM_UNFOUND, gdcmWarningMacro, gdcm::File::GetBitsAllocated(), gdcm::File::GetBitsStored(), gdcm::Util::GetCurrentDate(), gdcm::Util::GetCurrentTime(), gdcm::DocEntrySet::GetDataEntry(), gdcm::Global::GetDicts(), gdcm::DocEntrySet::GetEntryString(), gdcm::Util::GetFileMetaInformationVersion(), gdcm::File::GetHighBitPosition(), gdcm::Orientation::GetOrientation(), gdcm::DataEntry::GetString(), gdcm::Util::GetVersion(), KeepMediaStorageSOPClassUID, gdcm::Orientation::New(), gdcm::DataEntry::New(), gdcm::SQItem::New(), gdcm::SeqEntry::New(), gdcm::DocEntryArchive::Push(), gdcm::DataEntry::SetBinArea(), gdcm::DocEntry::SetLength(), gdcm::DataEntry::SetString(), and WriteType.

Referenced by Write().

01328 {
01329    std::string sop =  Util::CreateUniqueUID();
01330    
01331    // just to remember : 'official' 0002 group
01332    if ( WriteType != ACR && WriteType != ACR_LIBIDO )
01333    {
01334      // Group 000002 (Meta Elements) already pushed out
01335   
01336    //0002 0000 UL 1 Meta Group Length
01337    //0002 0001 OB 1 File Meta Information Version
01338    //0002 0002 UI 1 Media Stored SOP Class UID
01339    //0002 0003 UI 1 Media Stored SOP Instance UID
01340    //0002 0010 UI 1 Transfer Syntax UID
01341    //0002 0012 UI 1 Implementation Class UID
01342    //0002 0013 SH 1 Implementation Version Name
01343    //0002 0016 AE 1 Source Application Entity Title
01344    //0002 0100 UI 1 Private Information Creator
01345    //0002 0102 OB 1 Private Information
01346   
01347    // Create them if not found
01348    // Always modify the value
01349    // Push the entries to the archive.
01350       CopyMandatoryEntry(0x0002,0x0000,"0");
01351  
01352       DataEntry *e_0002_0001 = CopyDataEntry(0x0002,0x0001, "OB");
01353       e_0002_0001->SetBinArea((uint8_t*)Util::GetFileMetaInformationVersion(),
01354                                false);
01355       e_0002_0001->SetLength(2);
01356       Archive->Push(e_0002_0001);
01357       e_0002_0001->Delete(); 
01358 
01359       if ( KeepMediaStorageSOPClassUID)      
01360    // It up to the use to *know* whether he modified the pixels or not.
01361    // he is allowed to keep the original 'Media Storage SOP Class UID'
01362          CheckMandatoryEntry(0x0002,0x0002,"1.2.840.10008.5.1.4.1.1.7");    
01363       else
01364    // Potentialy this is a post-processed image 
01365    // 'Media Storage SOP Class UID'  --> [Secondary Capture Image Storage]
01366          CopyMandatoryEntry(0x0002,0x0002,"1.2.840.10008.5.1.4.1.1.7");    
01367        
01368    // 'Media Storage SOP Instance UID'   
01369       CopyMandatoryEntry(0x0002,0x0003,sop);
01370       
01371    // 'Implementation Class UID'
01372    // FIXME : in all examples we have, 0x0002,0x0012 is not so long :
01373    //         semms to be Root UID + 4 digits (?)
01374       CopyMandatoryEntry(0x0002,0x0012,Util::CreateUniqueUID());
01375 
01376    // 'Implementation Version Name'
01377       std::string version = "GDCM ";
01378       version += Util::GetVersion();
01379       CopyMandatoryEntry(0x0002,0x0013,version);
01380    }
01381 
01382    // Push out 'LibIDO-special' entries, if any
01383    Archive->Push(0x0028,0x0015);
01384    Archive->Push(0x0028,0x0016);
01385    Archive->Push(0x0028,0x0017);
01386    Archive->Push(0x0028,0x00199);
01387 
01388    // Deal with the pb of (Bits Stored = 12)
01389    // - we're gonna write the image as Bits Stored = 16
01390    if ( FileInternal->GetEntryString(0x0028,0x0100) ==  "12")
01391    {
01392       CopyMandatoryEntry(0x0028,0x0100,"16");
01393    }
01394 
01395    // Check if user wasn't drunk ;-)
01396 
01397    std::ostringstream s;
01398    // check 'Bits Allocated' vs decent values
01399    int nbBitsAllocated = FileInternal->GetBitsAllocated();
01400    if ( nbBitsAllocated == 0 || nbBitsAllocated > 32)
01401    {
01402       CopyMandatoryEntry(0x0028,0x0100,"16");
01403       gdcmWarningMacro("(0028,0100) changed from "
01404          << nbBitsAllocated << " to 16 for consistency purpose");
01405       nbBitsAllocated = 16; 
01406    }
01407    // check 'Bits Stored' vs 'Bits Allocated'   
01408    int nbBitsStored = FileInternal->GetBitsStored();
01409    if ( nbBitsStored == 0 || nbBitsStored > nbBitsAllocated )
01410    {
01411       s.str("");
01412       s << nbBitsAllocated;
01413       CopyMandatoryEntry(0x0028,0x0101,s.str());
01414       gdcmWarningMacro("(0028,0101) changed from "
01415                        << nbBitsStored << " to " << nbBitsAllocated
01416                        << " for consistency purpose" );
01417       nbBitsStored = nbBitsAllocated; 
01418     }
01419    // check 'Hight Bit Position' vs 'Bits Allocated' and 'Bits Stored'
01420    int highBitPosition = FileInternal->GetHighBitPosition();
01421    if ( highBitPosition == 0 || 
01422         highBitPosition > nbBitsAllocated-1 ||
01423         highBitPosition < nbBitsStored-1  )
01424    {
01425       s.str("");
01426       s << nbBitsStored - 1; 
01427       CopyMandatoryEntry(0x0028,0x0102,s.str());
01428       gdcmWarningMacro("(0028,0102) changed from "
01429                        << highBitPosition << " to " << nbBitsAllocated-1
01430                        << " for consistency purpose");
01431    }
01432 
01433    std::string pixelSpacing = FileInternal->GetEntryString(0x0028,0x0030);
01434    if ( pixelSpacing == GDCM_UNFOUND )
01435    {
01436       pixelSpacing = "1.0\\1.0";
01437        // if missing, Pixel Spacing forced to "1.0\1.0"
01438       CopyMandatoryEntry(0x0028,0x0030,pixelSpacing);
01439    }
01440    
01441    // 'Imager Pixel Spacing' : defaulted to 'Pixel Spacing'
01442    // --> This one is the *legal* one !
01443    // FIXME : we should write it only when we are *sure* the image comes from
01444    //         an imager (see also 0008,0x0064)          
01445    CheckMandatoryEntry(0x0018,0x1164,pixelSpacing);
01446    
01447    // Samples Per Pixel (type 1) : default to grayscale 
01448    CheckMandatoryEntry(0x0028,0x0002,"1");
01449    
01450    // --- Check UID-related Entries ---
01451 
01452    // If 'SOP Class UID' exists ('true DICOM' image)
01453    // we create the 'Source Image Sequence' SeqEntry
01454    // to hold informations about the Source Image
01455 
01456    DataEntry *e_0008_0016 = FileInternal->GetDataEntry(0x0008, 0x0016);
01457    if ( e_0008_0016 )
01458    {
01459       // Create 'Source Image Sequence' SeqEntry
01460       SeqEntry *sis = SeqEntry::New (
01461             Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x2112) );
01462       SQItem *sqi = SQItem::New(1);
01463       // (we assume 'SOP Instance UID' exists too) 
01464       // create 'Referenced SOP Class UID'
01465       DataEntry *e_0008_1150 = DataEntry::New(
01466             Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x1150) );
01467       e_0008_1150->SetString( e_0008_0016->GetString());
01468       sqi->AddEntry(e_0008_1150);
01469       e_0008_1150->Delete();
01470       
01471       // create 'Referenced SOP Instance UID'
01472       DataEntry *e_0008_0018 = FileInternal->GetDataEntry(0x0008, 0x0018);
01473       DataEntry *e_0008_1155 = DataEntry::New(
01474             Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x1155) );
01475       e_0008_1155->SetString( e_0008_0018->GetString());
01476       sqi->AddEntry(e_0008_1155);
01477       e_0008_1155->Delete();
01478 
01479       sis->AddSQItem(sqi,1);
01480       sqi->Delete();
01481 
01482       // temporarily replaces any previous 'Source Image Sequence' 
01483       Archive->Push(sis);
01484       sis->Delete();
01485  
01486       // FIXME : is 'Image Type' *really* depending on the presence of'SOP Class UID'?
01487        if ( KeepMediaStorageSOPClassUID)      
01488    // It up to the use to *know* whether he modified the pixels or not.
01489    // he is allowed to keep the original 'Media Storage SOP Class UID'
01490    // and 'Image Type' as well
01491          CheckMandatoryEntry(0x0008,0x0008,"DERIVED\\PRIMARY");    
01492       else
01493    // Potentialy this is a post-processed image 
01494    // (The written image is no longer an 'ORIGINAL' one)
01495       CopyMandatoryEntry(0x0008,0x0008,"DERIVED\\PRIMARY");
01496 
01497    }
01498 
01499    // At the end, not to overwrite the original ones,
01500    // needed by 'Referenced SOP Instance UID', 'Referenced SOP Class UID'   
01501    // 'SOP Instance UID'  
01502    CopyMandatoryEntry(0x0008,0x0018,sop);
01503    
01504    // the gdcm written image is a [Secondary Capture Image Storage]
01505    // except if user told us he dind't modify the pixels, and, therefore
01506    // he want to keep the 'Media Storage SOP Class UID'
01507    
01508       // 'Media Storage SOP Class UID' : [Secondary Capture Image Storage]
01509    if ( KeepMediaStorageSOPClassUID)
01510    {      
01511       // It up to the use to *know* whether he modified the pixels or not.
01512       // he is allowed to keep the original 'Media Storage SOP Class UID'
01513       CheckMandatoryEntry(0x0008,0x0016,"1.2.840.10008.5.1.4.1.1.7");    
01514    }
01515    else
01516    {
01517        // Potentialy this is a post-processed image 
01518        // 'Media Storage SOP Class UID'  --> [Secondary Capture Image Storage]
01519       CopyMandatoryEntry(0x0008,0x0016,"1.2.840.10008.5.1.4.1.1.7");    
01520 
01521        // FIXME : Must we Force Value, or Default value ?
01522        // Is it Type 1 for any Modality ?
01523        //    --> Answer seems to be NO :-(
01524        // FIXME : we should write it only when we are *sure* the image 
01525        //         *does not* come from an imager (see also 0018,0x1164)
01526 
01527        // Conversion Type.
01528        // Other possible values are :
01529        // See PS 3.3, Page 408
01530    
01531        // DV = Digitized Video
01532        // DI = Digital Interface   
01533        // DF = Digitized Film
01534        // WSD = Workstation
01535        // SD = Scanned Document
01536        // SI = Scanned Image
01537        // DRW = Drawing
01538        // SYN = Synthetic Image
01539      
01540       CheckMandatoryEntry(0x0008,0x0064,"SYN");
01541    }   
01542            
01543    // ---- The user will never have to take any action on the following ----
01544    
01545    // new value for 'SOP Instance UID'
01546    //SetMandatoryEntry(0x0008,0x0018,Util::CreateUniqueUID());
01547 
01548    // Instance Creation Date
01549    const std::string &date = Util::GetCurrentDate();
01550    CopyMandatoryEntry(0x0008,0x0012,date);
01551  
01552    // Instance Creation Time
01553    const std::string &time = Util::GetCurrentTime();
01554    CopyMandatoryEntry(0x0008,0x0013,time);
01555 
01556    // Study Date
01557    CheckMandatoryEntry(0x0008,0x0020,date);
01558    // Study Time
01559    CheckMandatoryEntry(0x0008,0x0030,time);
01560 
01561    // Accession Number
01562    //CopyMandatoryEntry(0x0008,0x0050,"");
01563    CheckMandatoryEntry(0x0008,0x0050,"");
01564    
01565 
01566    // ----- Add Mandatory Entries if missing ---
01567    // Entries whose type is 1 are mandatory, with a mandatory value
01568    // Entries whose type is 1c are mandatory-inside-a-Sequence,
01569    //                          with a mandatory value
01570    // Entries whose type is 2 are mandatory, with an optional value
01571    // Entries whose type is 2c are mandatory-inside-a-Sequence,
01572    //                          with an optional value
01573    // Entries whose type is 3 are optional
01574 
01575    // 'Study Instance UID'
01576    // Keep the value if exists
01577    // The user is allowed to create his own Study, 
01578    //          keeping the same 'Study Instance UID' for various images
01579    // The user may add images to a 'Manufacturer Study',
01580    //          adding new Series to an already existing Study 
01581    CheckMandatoryEntry(0x0020,0x000d,Util::CreateUniqueUID());
01582 
01583    // 'Serie Instance UID'
01584    // Keep the value if exists
01585    // The user is allowed to create his own Series, 
01586    // keeping the same 'Serie Instance UID' for various images
01587    // The user shouldn't add any image to a 'Manufacturer Serie'
01588    // but there is no way no to prevent him for doing that 
01589    CheckMandatoryEntry(0x0020,0x000e,Util::CreateUniqueUID());
01590 
01591    // Study ID
01592    CheckMandatoryEntry(0x0020,0x0010,"");
01593 
01594    // Series Number
01595    CheckMandatoryEntry(0x0020,0x0011,"");
01596 
01597    // Instance Number
01598    CheckMandatoryEntry(0x0020,0x0013,"");
01599    
01600    // Patient Orientation
01601    // Can be computed from (0020|0037) :  Image Orientation (Patient)
01602    gdcm::Orientation *o = gdcm::Orientation::New();
01603    std::string ori = o->GetOrientation ( FileInternal );
01604    o->Delete();
01605    if (ori != "\\" )
01606       CheckMandatoryEntry(0x0020,0x0020,ori);
01607    else   
01608       CheckMandatoryEntry(0x0020,0x0020,"");
01609    
01610    // Modality : if missing we set it to 'OTher'
01611    CheckMandatoryEntry(0x0008,0x0060,"OT");
01612 
01613    // Manufacturer : if missing we set it to 'GDCM Factory'
01614    CheckMandatoryEntry(0x0008,0x0070,"GDCM Factory");
01615 
01616    // Institution Name : if missing we set it to 'GDCM Hospital'
01617    CheckMandatoryEntry(0x0008,0x0080,"GDCM Hospital");
01618 
01619    // Patient's Name : if missing, we set it to 'GDCM^Patient'
01620    CheckMandatoryEntry(0x0010,0x0010,"GDCM^Patient");
01621 
01622    // Patient ID
01623    CheckMandatoryEntry(0x0010,0x0020,"");
01624 
01625    // Patient's Birth Date : 'type 2' entry -> must exist, value not mandatory
01626    CheckMandatoryEntry(0x0010,0x0030,"");
01627 
01628    // Patient's Sex :'type 2' entry -> must exist, value not mandatory
01629    CheckMandatoryEntry(0x0010,0x0040,"");
01630 
01631    // Referring Physician's Name :'type 2' entry -> must exist, value not mandatory
01632    CheckMandatoryEntry(0x0008,0x0090,"");
01633    
01634    // Remove some inconstencies (probably some more will be added)
01635 
01636    // if (0028 0008)Number of Frames exists
01637    //    Push out (0020 0052),Frame of Reference UID
01638    //    (only meaningfull within a Serie)
01639    DataEntry *e_0028_0008 = FileInternal->GetDataEntry(0x0028, 0x0008);
01640    if ( !e_0028_0008 )
01641    {
01642       Archive->Push(0x0020, 0x0052);
01643    }
01644  
01645    // Deal with element 0x0000 (group length) of each group.
01646    // First stage : get all the different Groups
01647  /*
01648   GroupHT grHT;
01649   DocEntry *d = FileInternal->GetFirstEntry();
01650   while(d)
01651   {
01652     grHT[d->GetGroup()] = 0;
01653     d=FileInternal->GetNextEntry();
01654   }
01655   // Second stage : add the missing ones (if any)
01656   for (GroupHT::iterator it = grHT.begin(); it != grHT.end(); ++it)  
01657   {
01658       CheckMandatoryEntry(it->first, 0x0000, "0"); 
01659   }    
01660   // Third stage : update all 'zero level' groups length
01661 */   
01662 } 

void gdcm::FileHelper::CheckMandatoryEntry uint16_t  group,
uint16_t  elem,
std::string  value
[protected]
 

Definition at line 1664 of file gdcmFileHelper.cxx.

References Archive, gdcm::RefCounter::Delete(), FileInternal, gdcm::DocEntrySet::GetDataEntry(), gdcm::Global::GetDicts(), gdcm::DataEntry::New(), gdcm::DocEntryArchive::Push(), and gdcm::DataEntry::SetString().

Referenced by CheckMandatoryElements().

01665 {
01666    DataEntry *entry = FileInternal->GetDataEntry(group,elem);
01667    if ( !entry )
01668    {
01669       entry = DataEntry::New(Global::GetDicts()->GetDefaultPubDict()->GetEntry(group,elem));
01670       entry->SetString(value);
01671       Archive->Push(entry);
01672       entry->Delete();
01673    }
01674 }

bool gdcm::FileHelper::CheckWriteIntegrity  )  [protected]
 

Checks the write integrity.

The tests made are :

  • verify the size of the image to write with the possible write when the user set an image data
    Returns:
    true if check is successfull

Definition at line 749 of file gdcmFileHelper.cxx.

References FileInternal, gdcmWarningMacro, gdcm::File::GetBitsAllocated(), gdcm::File::GetSamplesPerPixel(), gdcm::PixelWriteConvert::GetUserData(), gdcm::PixelWriteConvert::GetUserDataSize(), gdcm::File::GetXSize(), gdcm::File::GetYSize(), gdcm::File::GetZSize(), gdcm::File::HasLUT(), PixelWriteConverter, WMODE_RAW, WMODE_RGB, and WriteMode.

Referenced by Write().

00750 {
00751    if ( PixelWriteConverter->GetUserData() )
00752    {
00753       int numberBitsAllocated = FileInternal->GetBitsAllocated();
00754       if ( numberBitsAllocated == 0 || numberBitsAllocated == 12 )
00755       {
00756          gdcmWarningMacro( "numberBitsAllocated changed from " 
00757                           << numberBitsAllocated << " to 16 " 
00758                           << " for consistency purpose" );
00759          numberBitsAllocated = 16;
00760       }
00761 
00762       size_t decSize = FileInternal->GetXSize()
00763                      * FileInternal->GetYSize() 
00764                      * FileInternal->GetZSize()
00765                      * FileInternal->GetSamplesPerPixel()
00766                      * ( numberBitsAllocated / 8 );
00767       size_t rgbSize = decSize;
00768       if ( FileInternal->HasLUT() )
00769          rgbSize = decSize * 3;
00770 
00771       switch(WriteMode)
00772       {
00773          case WMODE_RAW :
00774             if ( decSize!=PixelWriteConverter->GetUserDataSize() )
00775             {
00776                gdcmWarningMacro( "Data size (Raw) is incorrect. Should be " 
00777                            << decSize << " / Found :" 
00778                            << PixelWriteConverter->GetUserDataSize() );
00779                return false;
00780             }
00781             break;
00782          case WMODE_RGB :
00783             if ( rgbSize!=PixelWriteConverter->GetUserDataSize() )
00784             {
00785                gdcmWarningMacro( "Data size (RGB) is incorrect. Should be " 
00786                           << decSize << " / Found " 
00787                           << PixelWriteConverter->GetUserDataSize() );
00788                return false;
00789             }
00790             break;
00791       }
00792    }
00793 
00794    return true;
00795 }

DataEntry * gdcm::FileHelper::CopyDataEntry uint16_t  group,
uint16_t  elem,
const TagName vr = GDCM_VRUNKNOWN
[protected]
 

Duplicates a DataEntry or creates it.

Parameters:
group Group number of the Entry
elem Element number of the Entry
vr Value Representation of the Entry FIXME : what is it used for?
Returns:
pointer to the new Bin Entry (NULL when creation failed).

Definition at line 1124 of file gdcmFileHelper.cxx.

References gdcm::DataEntry::Copy(), FileInternal, gdcm::GDCM_VRUNKNOWN, gdcm::DocEntry::GetDictEntry(), gdcm::ElementSet::GetDocEntry(), GetFile(), gdcm::DocEntry::GetVR(), gdcm::DataEntry::New(), and gdcm::DocEntrySet::NewDataEntry().

Referenced by CheckMandatoryElements(), CopyMandatoryEntry(), SetWriteFileTypeToExplicitVR(), SetWriteFileTypeToImplicitVR(), SetWriteFileTypeToJPEG(), SetWriteToLibido(), SetWriteToNoLibido(), SetWriteToRaw(), and SetWriteToRGB().

01126 {
01127    DocEntry *oldE = FileInternal->GetDocEntry(group, elem);
01128    DataEntry *newE;
01129 
01130    if ( oldE && vr != GDCM_VRUNKNOWN ) 
01131       if ( oldE->GetVR() != vr )
01132          oldE = NULL;
01133 
01134    if ( oldE )
01135    {
01136       newE = DataEntry::New(oldE->GetDictEntry());
01137       newE->Copy(oldE);
01138    }
01139    else
01140    {
01141       newE = GetFile()->NewDataEntry(group, elem, vr);
01142    }
01143 
01144    return newE;
01145 }

void gdcm::FileHelper::CopyMandatoryEntry uint16_t  group,
uint16_t  elem,
std::string  value
[protected]
 

Definition at line 1684 of file gdcmFileHelper.cxx.

References Archive, CopyDataEntry(), gdcm::RefCounter::Delete(), gdcm::DocEntryArchive::Push(), and gdcm::DataEntry::SetString().

Referenced by CheckMandatoryElements().

01685 {
01686    DataEntry *entry = CopyDataEntry(group,elem);
01687    entry->SetString(value);
01688    Archive->Push(entry);
01689    entry->Delete();
01690 }

void gdcm::RefCounter::Delete  )  [inline, inherited]
 

Delete the object.

Remarks:
The object is deleted only if its reference counting is to zero

Definition at line 39 of file gdcmRefCounter.h.

Referenced by gdcm::SerieHelper::AddFileName(), gdcm::Document::Backtrack(), CheckMandatoryElements(), CheckMandatoryEntry(), CopyMandatoryEntry(), gdcm::DicomDir::CreateDicomDirChainedList(), gdcm::File::DoTheLoadingJob(), gdcm::Dict::DoTheLoadingJob(), gdcm::DicomDirObject::FillObject(), gdcm::DocEntrySet::InsertEntryBinArea(), gdcm::DocEntrySet::InsertEntryString(), gdcm::DocEntrySet::InsertSeqEntry(), vtkGdcmReader::LoadFileInformation(), vtkGdcmReader::LoadImageInMemory(), main(), gdcm::DicomDir::NewMeta(), gdcm::DicomDirStudy::NewVisit(), gdcm::Document::ParseDES(), gdcm::Document::ParseSQ(), gdcm::Document::ReadNextDocEntry(), gdcm::DicomDir::SetElement(), SetMandatoryEntry(), SetWriteFileTypeToExplicitVR(), SetWriteFileTypeToImplicitVR(), SetWriteFileTypeToJPEG(), SetWriteToLibido(), SetWriteToNoLibido(), SetWriteToRaw(), SetWriteToRGB(), vtkGdcmWriter::WriteDcmFile(), gdcm::DicomDir::~DicomDir(), and gdcm::Global::~Global().

00039 { Unregister(); }

gdcm::FileHelper::GDCM_LEGACY size_t   GetImageDataIntoVector(void *destination, size_t maxSize)  ) 
 

gdcm::FileHelper::gdcmTypeMacro FileHelper   )  [private]
 

File* gdcm::FileHelper::GetFile  )  [inline]
 

Accessor to File.

Definition at line 63 of file gdcmFileHelper.h.

Referenced by CopyDataEntry(), vtkGdcmReader::LoadImageInMemory(), RestoreWrite(), SetLoadMode(), SetWriteToRaw(), and SetWriteToRGB().

00063 { return FileInternal; }

uint8_t * gdcm::FileHelper::GetImageData  ) 
 

brings pixels into memory :

  • Allocates necessary memory,
  • Reads the pixels from disk (uncompress if necessary),
  • Transforms YBR pixels, if any, into RGB pixels,
  • Transforms 3 planes R, G, B, if any, into a single RGB Plane
  • Transforms single Grey plane + 3 Palettes into a RGB Plane
  • Copies the pixel data (image[s]/volume[s]) to newly allocated zone.

Returns:
Pointer to newly allocated pixel data. (uint8_t is just for prototyping. feel free to cast) NULL if alloc fails

Definition at line 347 of file gdcmFileHelper.cxx.

References gdcm::PixelReadConvert::BuildRGBImage(), FileInternal, gdcm::PixelReadConvert::GetRaw(), GetRaw(), gdcm::PixelReadConvert::GetRGB(), gdcm::PixelWriteConvert::GetUserData(), gdcm::File::HasLUT(), PixelReadConverter, and PixelWriteConverter.

Referenced by vtkGdcmReader::LoadImageInMemory().

00348 {
00349    if ( PixelWriteConverter->GetUserData() )
00350    {
00351       return PixelWriteConverter->GetUserData();
00352    }
00353 
00354    if ( ! GetRaw() )
00355    {
00356       // If the decompression failed nothing can be done.
00357       return 0;
00358    }
00359 
00360    if ( FileInternal->HasLUT() && PixelReadConverter->BuildRGBImage() )
00361    {
00362       return PixelReadConverter->GetRGB();
00363    }
00364    else
00365    {
00366       // When no LUT or LUT conversion fails, return the Raw
00367       return PixelReadConverter->GetRaw();
00368    }
00369 }

uint8_t * gdcm::FileHelper::GetImageDataRaw  ) 
 

brings pixels into memory :

  • Allocates necessary memory,
  • Transforms YBR pixels (if any) into RGB pixels
  • Transforms 3 planes R, G, B (if any) into a single RGB Plane
  • Copies the pixel data (image[s]/volume[s]) to newly allocated zone.
  • DOES NOT transform Grey plane + 3 Palettes into a RGB Plane

Returns:
Pointer to newly allocated pixel data. (uint8_t is just for prototyping. feel free to cast) NULL if alloc fails

Definition at line 382 of file gdcmFileHelper.cxx.

References GetRaw().

Referenced by vtkGdcmReader::LoadImageInMemory().

00383 {
00384    return GetRaw();
00385 }

size_t gdcm::FileHelper::GetImageDataRawSize  ) 
 

Get the size of the image data. If the image could be converted to RGB using a LUT, this transformation is not taken into account by GetImageDataRawSize (use GetImageDataSize if you wish).

Returns:
The raw image size

Definition at line 326 of file gdcmFileHelper.cxx.

References gdcm::PixelReadConvert::GetRawSize(), gdcm::PixelWriteConvert::GetUserData(), gdcm::PixelWriteConvert::GetUserDataSize(), PixelReadConverter, and PixelWriteConverter.

00327 {
00328    if ( PixelWriteConverter->GetUserData() )
00329    {
00330       return PixelWriteConverter->GetUserDataSize();
00331    }
00332    return PixelReadConverter->GetRawSize();
00333 }

size_t gdcm::FileHelper::GetImageDataSize  ) 
 

Get the size of the image data If the image can be RGB (with a lut or by default), the size corresponds to the RGB image (use GetImageDataRawSize if you want to be sure to get *only* the size of the pixels).

Returns:
The image size

Definition at line 310 of file gdcmFileHelper.cxx.

References gdcm::PixelReadConvert::GetRGBSize(), gdcm::PixelWriteConvert::GetUserData(), gdcm::PixelWriteConvert::GetUserDataSize(), PixelReadConverter, and PixelWriteConverter.

Referenced by vtkGdcmReader::LoadImageInMemory().

00311 {
00312    if ( PixelWriteConverter->GetUserData() )
00313    {
00314       return PixelWriteConverter->GetUserDataSize();
00315    }
00316    return PixelReadConverter->GetRGBSize();
00317 }

int gdcm::FileHelper::GetLutItemNumber  ) 
 

Access to the underlying PixelReadConverter RGBA LUT Item Number.

Definition at line 546 of file gdcmFileHelper.cxx.

References gdcm::PixelReadConvert::GetLutItemNumber(), and PixelReadConverter.

00547 {
00548    return PixelReadConverter->GetLutItemNumber();
00549 }

int gdcm::FileHelper::GetLutItemSize  ) 
 

Access to the underlying PixelReadConverter RGBA LUT Item Size.

Definition at line 554 of file gdcmFileHelper.cxx.

References gdcm::PixelReadConvert::GetLutItemSize(), and PixelReadConverter.

00555 {
00556    return PixelReadConverter->GetLutItemSize();
00557 }

uint8_t * gdcm::FileHelper::GetLutRGBA  ) 
 

Access to the underlying PixelReadConverter RGBA LUT.

Definition at line 536 of file gdcmFileHelper.cxx.

References gdcm::PixelReadConvert::BuildLUTRGBA(), gdcm::PixelReadConvert::GetLutRGBA(), and PixelReadConverter.

Referenced by vtkGdcmReader::LoadImageInMemory().

00537 {
00538    if ( PixelReadConverter->GetLutRGBA() ==0 )
00539       PixelReadConverter->BuildLUTRGBA();
00540    return PixelReadConverter->GetLutRGBA();
00541 }

int gdcm::Base::GetPrintLevel  )  [inline, inherited]
 

Gets the print level for the Dicom Entries.

Definition at line 50 of file gdcmBase.h.

00050 { return PrintLevel; }

uint8_t * gdcm::FileHelper::GetRaw  )  [private]
 

Reads/[decompresses] the pixels, *without* making RGB from Palette Colors.

Returns:
the pixels area, whatever its type (uint8_t is just for prototyping : feel free to Cast it)

Definition at line 1781 of file gdcmFileHelper.cxx.

References gdcm::Document::CloseFile(), FileInternal, gdcmWarningMacro, gdcm::PixelReadConvert::GetRaw(), gdcm::Document::OpenFile(), PixelReadConverter, gdcm::PixelReadConvert::ReadAndDecompressPixelData(), gdcm::PixelReadConvert::SetUserFunction(), and UserFunction.

Referenced by GetImageData(), and GetImageDataRaw().

01782 {
01783    PixelReadConverter->SetUserFunction( UserFunction );
01784 
01785    uint8_t *raw = PixelReadConverter->GetRaw();
01786    if ( ! raw )
01787    {
01788       // The Raw image migth not be loaded yet:
01789       std::ifstream *fp = FileInternal->OpenFile();
01790       PixelReadConverter->ReadAndDecompressPixelData( fp );
01791       if ( fp ) 
01792          FileInternal->CloseFile();
01793 
01794       raw = PixelReadConverter->GetRaw();
01795       if ( ! raw )
01796       {
01797          gdcmWarningMacro( "Read/decompress of pixel data apparently went wrong.");
01798          return 0;
01799       }
01800    }
01801    return raw;
01802 }

uint8_t * gdcm::FileHelper::GetRawData  ) 
 

Get the image data from the file. Even when a LUT is found, the data are not expanded to RGB!

Definition at line 519 of file gdcmFileHelper.cxx.

References gdcm::PixelReadConvert::GetRaw(), and PixelReadConverter.

00520 {
00521    return PixelReadConverter->GetRaw();
00522 }

size_t gdcm::FileHelper::GetRawDataSize  ) 
 

Get the image data size from the file. Even when a LUT is found, the data are not expanded to RGB!

Definition at line 528 of file gdcmFileHelper.cxx.

References gdcm::PixelReadConvert::GetRawSize(), and PixelReadConverter.

00529 {
00530    return PixelReadConverter->GetRawSize();
00531 }

const unsigned long& gdcm::RefCounter::GetRefCount  )  const [inline, inherited]
 

Get the reference counting.

Returns:
Reference count

Definition at line 56 of file gdcmRefCounter.h.

00057    {
00058       return RefCount;
00059    }

uint8_t * gdcm::FileHelper::GetRGBData  ) 
 

Get the image data from the file. If a LUT is found, the data are expanded to be RGB.

Definition at line 501 of file gdcmFileHelper.cxx.

References gdcm::PixelReadConvert::GetRGB(), and PixelReadConverter.

00502 {
00503    return PixelReadConverter->GetRGB();
00504 }

size_t gdcm::FileHelper::GetRGBDataSize  ) 
 

Get the image data size from the file. If a LUT is found, the data are expanded to be RGB.

Definition at line 510 of file gdcmFileHelper.cxx.

References gdcm::PixelReadConvert::GetRGBSize(), and PixelReadConverter.

00511 {
00512    return PixelReadConverter->GetRGBSize();
00513 }

uint8_t * gdcm::FileHelper::GetUserData  ) 
 

Get the image data defined by the user.

Warning:
When writting the file, this data are get as default data to write

Definition at line 483 of file gdcmFileHelper.cxx.

References gdcm::PixelWriteConvert::GetUserData(), and PixelWriteConverter.

Referenced by vtkGdcmWriter::WriteDcmFile().

00484 {
00485    return PixelWriteConverter->GetUserData();
00486 }

size_t gdcm::FileHelper::GetUserDataSize  ) 
 

Get the image data size defined by the user.

Warning:
When writting the file, this data are get as default data to write

Definition at line 492 of file gdcmFileHelper.cxx.

References gdcm::PixelWriteConvert::GetUserDataSize(), and PixelWriteConverter.

Referenced by vtkGdcmWriter::WriteDcmFile().

00493 {
00494    return PixelWriteConverter->GetUserDataSize();
00495 }

FileMode gdcm::FileHelper::GetWriteMode  )  [inline]
 

Gets the Write Mode ( ).

Definition at line 122 of file gdcmFileHelper.h.

00122 { return WriteMode;         }

FileType gdcm::FileHelper::GetWriteType  )  [inline]
 

Gets the format we talled the write we wanted to write (ImplicitVR, ExplicitVR, ACR, ACR_LIBIDO).

Definition at line 141 of file gdcmFileHelper.h.

00141 { return WriteType;         }

void gdcm::FileHelper::Initialize  )  [private]
 

Factorization for various forms of constructors.

Definition at line 1762 of file gdcmFileHelper.cxx.

References Archive, gdcm::ExplicitVR, FileInternal, KeepMediaStorageSOPClassUID, PixelReadConverter, PixelWriteConverter, UserFunction, WMODE_RAW, WriteMode, and WriteType.

Referenced by FileHelper().

01763 {
01764    UserFunction = 0;
01765    KeepMediaStorageSOPClassUID = false;
01766    
01767    WriteMode = WMODE_RAW;
01768    WriteType = ExplicitVR;
01769 
01770    PixelReadConverter  = new PixelReadConvert;
01771    PixelWriteConverter = new PixelWriteConvert;
01772    Archive = new DocEntryArchive( FileInternal );
01773 }

DataEntry * gdcm::FileHelper::InsertEntryBinArea uint8_t *  binArea,
int  lgth,
uint16_t  group,
uint16_t  elem
 

Modifies the value of a given DataEntry when it exists. Creates it with the given value when unexistant. A copy of the binArea is made to be kept in the Document.

Parameters:
binArea (binary)value to be set
lgth new value length
group Group number of the Entry
elem Element number of the Entry
Returns:
pointer to the modified/created DataEntry (NULL when creation failed).

Definition at line 283 of file gdcmFileHelper.cxx.

References FileInternal, and gdcm::DocEntrySet::InsertEntryBinArea().

00285 {
00286    return FileInternal->InsertEntryBinArea(binArea, lgth, group, elem);
00287 }

DataEntry * gdcm::FileHelper::InsertEntryString std::string const &  content,
uint16_t  group,
uint16_t  elem
 

Modifies the value of a given DataEntry when it exists. Creates it with the given value when unexistant.

Parameters:
content (string) value to be set
group Group number of the Entry
elem Element number of the Entry
Returns:
pointer to the modified/created DataEntry (NULL when creation failed).

Definition at line 266 of file gdcmFileHelper.cxx.

References FileInternal, and gdcm::DocEntrySet::InsertEntryString().

Referenced by SetImageInformation().

00268 {
00269    return FileInternal->InsertEntryString(content, group, elem);
00270 }

SeqEntry * gdcm::FileHelper::InsertSeqEntry uint16_t  group,
uint16_t  elem
 

Adds an empty SeqEntry (remove any existing entry with same group,elem).

Parameters:
group Group number of the Entry
elem Element number of the Entry
Returns:
pointer to the created SeqEntry (NULL when creation failed).

Definition at line 297 of file gdcmFileHelper.cxx.

References FileInternal, and gdcm::DocEntrySet::InsertSeqEntry().

00298 {
00299    return FileInternal->InsertSeqEntry(group, elem);
00300 }

bool gdcm::FileHelper::Load  ) 
 

Loader.

Returns:
false if file cannot be open or no swap info was found, or no tag was found.

Definition at line 218 of file gdcmFileHelper.cxx.

References FileInternal, gdcm::PixelReadConvert::GrabInformationsFromFile(), gdcm::File::Load(), and PixelReadConverter.

00219 { 
00220    if ( !FileInternal->Load() )
00221       return false;
00222 
00223    PixelReadConverter->GrabInformationsFromFile( FileInternal, this );
00224    return true;
00225 }

static FileHelper* gdcm::FileHelper::New File header  )  [inline, static]
 

Constructs a FileHelper with a RefCounter from a fileHelper.

Definition at line 58 of file gdcmFileHelper.h.

00058 {return new FileHelper(header);}

static FileHelper* gdcm::FileHelper::New  )  [inline, static]
 

Constructs a FileHelper with a RefCounter.

Definition at line 56 of file gdcmFileHelper.h.

Referenced by vtkGdcmReader::LoadImageInMemory(), and vtkGdcmWriter::WriteDcmFile().

00056 {return new FileHelper();}

void gdcm::FileHelper::Print std::ostream &  os = std::cout,
std::string const &  indent = ""
[virtual]
 

Prints the common part of DataEntry, SeqEntry.

Parameters:
os ostream we want to print in
indent (unused)

Reimplemented from gdcm::Base.

Definition at line 1810 of file gdcmFileHelper.cxx.

References FileInternal, gdcm::File::IsReadable(), PixelReadConverter, gdcm::PixelReadConvert::Print(), gdcm::ElementSet::Print(), gdcm::Base::PrintLevel, and gdcm::Base::SetPrintLevel().

01811 {
01812    FileInternal->SetPrintLevel(PrintLevel);
01813    FileInternal->Print(os);
01814 
01815    if ( FileInternal->IsReadable() )
01816    {
01817       PixelReadConverter->SetPrintLevel(PrintLevel);
01818       PixelReadConverter->Print(os);
01819    }
01820 }

void gdcm::RefCounter::Register  )  [inline, inherited]
 

Register the object.

Remarks:
It increments the reference counting

Definition at line 44 of file gdcmRefCounter.h.

Referenced by gdcm::SQItem::AddEntry(), gdcm::ElementSet::AddEntry(), gdcm::Dict::AddEntry(), gdcm::SeqEntry::AddSQItem(), gdcm::SeqEntry::Copy(), gdcm::DicomDir::Copy(), gdcm::DocEntry::DocEntry(), FileHelper(), gdcm::DocEntrySet::GetDictEntry(), gdcm::CommandManager::InSetCommand(), gdcm::DocEntryArchive::Push(), gdcm::Dict::ReplaceEntry(), and gdcm::SeqEntry::SetDelimitationItem().

00044 { RefCount++; }

void gdcm::FileHelper::RestoreWrite  )  [protected]
 

Restore the File write mode.

Definition at line 940 of file gdcmFileHelper.cxx.

References Archive, GetFile(), and gdcm::DocEntryArchive::Restore().

Referenced by Write().

00941 {
00942    Archive->Restore(0x0028,0x0002);
00943    Archive->Restore(0x0028,0x0004);
00944    Archive->Restore(0x0028,0x0006);
00945    Archive->Restore(GetFile()->GetGrPixel(),GetFile()->GetNumPixel());
00946 
00947    // For old ACR-NEMA (24 bits problem)
00948    Archive->Restore(0x0028,0x0100);
00949    Archive->Restore(0x0028,0x0101);
00950    Archive->Restore(0x0028,0x0102);
00951 
00952    // For the LUT
00953    Archive->Restore(0x0028,0x1101);
00954    Archive->Restore(0x0028,0x1102);
00955    Archive->Restore(0x0028,0x1103);
00956    Archive->Restore(0x0028,0x1201);
00957    Archive->Restore(0x0028,0x1202);
00958    Archive->Restore(0x0028,0x1203);
00959 
00960    // For the Palette Color Lookup Table UID
00961    Archive->Restore(0x0028,0x1203); 
00962 
00963 
00964    // group 0002 may be pushed out for ACR-NEMA writting purposes 
00965    Archive->Restore(0x0002,0x0000);
00966    Archive->Restore(0x0002,0x0001);
00967    Archive->Restore(0x0002,0x0002);
00968    Archive->Restore(0x0002,0x0003);
00969    Archive->Restore(0x0002,0x0010);
00970    Archive->Restore(0x0002,0x0012);
00971    Archive->Restore(0x0002,0x0013);
00972    Archive->Restore(0x0002,0x0016);
00973    Archive->Restore(0x0002,0x0100);
00974    Archive->Restore(0x0002,0x0102);
00975 }

void gdcm::FileHelper::RestoreWriteFileType  )  [protected]
 

Restore in the File the initial group 0002.

Definition at line 1044 of file gdcmFileHelper.cxx.

Referenced by Write().

01045 {
01046 }

void gdcm::FileHelper::RestoreWriteMandatory  )  [protected]
 

Restore in the File the initial group 0002.

Definition at line 1695 of file gdcmFileHelper.cxx.

References Archive, and gdcm::DocEntryArchive::Restore().

Referenced by Write().

01696 {
01697    // group 0002 may be pushed out for ACR-NEMA writting purposes 
01698    Archive->Restore(0x0002,0x0000);
01699    Archive->Restore(0x0002,0x0001);
01700    Archive->Restore(0x0002,0x0002);
01701    Archive->Restore(0x0002,0x0003);
01702    Archive->Restore(0x0002,0x0010);
01703    Archive->Restore(0x0002,0x0012);
01704    Archive->Restore(0x0002,0x0013);
01705    Archive->Restore(0x0002,0x0016);
01706    Archive->Restore(0x0002,0x0100);
01707    Archive->Restore(0x0002,0x0102);
01708 
01709    // FIXME : Check if none is missing !
01710    
01711    Archive->Restore(0x0008,0x0012);
01712    Archive->Restore(0x0008,0x0013);
01713    Archive->Restore(0x0008,0x0016);
01714    Archive->Restore(0x0008,0x0018);
01715    Archive->Restore(0x0008,0x0060);
01716    Archive->Restore(0x0008,0x0070);
01717    Archive->Restore(0x0008,0x0080);
01718    Archive->Restore(0x0008,0x0090);
01719    Archive->Restore(0x0008,0x2112);
01720 
01721    Archive->Restore(0x0010,0x0010);
01722    Archive->Restore(0x0010,0x0030);
01723    Archive->Restore(0x0010,0x0040);
01724 
01725    Archive->Restore(0x0020,0x000d);
01726    Archive->Restore(0x0020,0x000e);
01727 }

void gdcm::FileHelper::RestoreWriteOfLibido  )  [protected]
 

Restore the Write format.

Definition at line 1103 of file gdcmFileHelper.cxx.

References Archive, and gdcm::DocEntryArchive::Restore().

Referenced by Write().

01104 {
01105    Archive->Restore(0x0028,0x0010);
01106    Archive->Restore(0x0028,0x0011);
01107    Archive->Restore(0x0008,0x0010);
01108 
01109    // Restore 'LibIDO-special' entries, if any
01110    Archive->Restore(0x0028,0x0015);
01111    Archive->Restore(0x0028,0x0016);
01112    Archive->Restore(0x0028,0x0017);
01113    Archive->Restore(0x0028,0x00199);
01114 }

bool gdcm::FileHelper::SetEntryBinArea uint8_t *  content,
int  lgth,
uint16_t  group,
uint16_t  elem
 

Accesses an existing DataEntry through it's (group, element) and modifies it's content with the given value.

Parameters:
content new value (void* -> uint8_t*) to substitute with
lgth new value length
group group number of the Dicom Element to modify
elem element number of the Dicom Element to modify
Returns:
false if DataEntry not found

Definition at line 251 of file gdcmFileHelper.cxx.

References FileInternal, and gdcm::DocEntrySet::SetEntryBinArea().

00253 {
00254    return FileInternal->SetEntryBinArea(content, lgth, group, elem);
00255 }

bool gdcm::FileHelper::SetEntryString std::string const &  content,
uint16_t  group,
uint16_t  elem
 

Accesses an existing DataEntry through it's (group, element) and modifies it's content with the given value.

Parameters:
content new value (string) to substitute with
group group number of the Dicom Element to modify
elem element number of the Dicom Element to modify
Returns:
false if DataEntry not found

Definition at line 235 of file gdcmFileHelper.cxx.

References FileInternal, and gdcm::DocEntrySet::SetEntryString().

00237 { 
00238    return FileInternal->SetEntryString(content, group, elem);
00239 }

void gdcm::FileHelper::SetFileName std::string const &  fileName  ) 
 

Sets the LoadMode of the internal gdcm::File.

Parameters:
fileName name of the file to be open

Definition at line 208 of file gdcmFileHelper.cxx.

References FileInternal, and gdcm::Document::SetFileName().

00209 {
00210    FileInternal->SetFileName( fileName );
00211 }

void gdcm::FileHelper::SetImageData uint8_t *  inData,
size_t  expectedSize
 

Points the internal pointer to the callers inData image representation, BUT WITHOUT COPYING THE DATA. 'image' Pixels are presented as C-like 2D arrays : line per line. 'volume'Pixels are presented as C-like 3D arrays : plane per plane.

Warning:
Since the pixels are not copied, it is the caller's responsability not to deallocate its data before gdcm uses them (e.g. with the Write() method )
Parameters:
inData user supplied pixel area (uint8_t* is just for the compiler. user is allowed to pass any kind of pixelsn since the size is given in bytes)
expectedSize total image size, *in Bytes*

Definition at line 461 of file gdcmFileHelper.cxx.

References SetUserData().

00462 {
00463    SetUserData(inData, expectedSize);
00464 }

void gdcm::FileHelper::SetKeepMediaStorageSOPClassUID bool  v  )  [inline]
 

if user knows he didn't modify the pixels (e.g. he just anonymized the file), he is allowed to ask to keep the original 'Media Storage SOP Class UID' and 'Image Type'

Definition at line 154 of file gdcmFileHelper.h.

void gdcm::FileHelper::SetLoadMode int  loadMode  ) 
 

Sets the LoadMode of the internal gdcm::File as a boolean string. NO_SEQ, NO_SHADOW, NO_SHADOWSEQ ... (nothing more, right now) WARNING : before using NO_SHADOW, be sure *all* your files contain accurate values in the 0x0000 element (if any) of *each* Shadow Group. The parser will fail if the size is wrong !

Parameters:
loadMode Load mode to be used

Definition at line 200 of file gdcmFileHelper.cxx.

References GetFile(), and gdcm::Document::SetLoadMode().

00201 { 
00202    GetFile()->SetLoadMode( loadMode ); 
00203 }

void gdcm::FileHelper::SetMandatoryEntry uint16_t  group,
uint16_t  elem,
std::string  value
[protected]
 

Definition at line 1676 of file gdcmFileHelper.cxx.

References Archive, gdcm::RefCounter::Delete(), gdcm::Global::GetDicts(), gdcm::DataEntry::New(), gdcm::DocEntryArchive::Push(), and gdcm::DataEntry::SetString().

01677 {
01678    DataEntry *entry = DataEntry::New(Global::GetDicts()->GetDefaultPubDict()->GetEntry(group,elem));
01679    entry->SetString(value);
01680    Archive->Push(entry);
01681    entry->Delete();
01682 }

void gdcm::Base::SetPrintLevel int  level  )  [inline, inherited]
 

Sets the print level for the Dicom Header Elements.

Note:
0 for Light Print; 1 for 'medium' Print, 2 for Heavy Print

Definition at line 47 of file gdcmBase.h.

Referenced by gdcm::SQItem::Print(), gdcm::SeqEntry::Print(), Print(), gdcm::ElementSet::Print(), and gdcm::DicomDir::Print().

00047 { PrintLevel = level; }

void gdcm::FileHelper::SetUserData uint8_t *  inData,
size_t  expectedSize
 

Set the image data defined by the user.

Warning:
When writting the file, this data are get as default data to write
Parameters:
inData user supplied pixel area (uint8_t* is just for the compiler. user is allowed to pass any kind of pixels since the size is given in bytes)
expectedSize total image size, *in Bytes*

Definition at line 474 of file gdcmFileHelper.cxx.

References PixelWriteConverter, and gdcm::PixelWriteConvert::SetUserData().

Referenced by SetImageData(), and SetImageInformation().

00475 {
00476    PixelWriteConverter->SetUserData(inData, expectedSize);
00477 }

void gdcm::FileHelper::SetUserFunction VOID_FUNCTION_PUINT8_PFILE_POINTER  userFunc  )  [inline]
 

to allow user to modify pixel order (e.g. Mirror, UpsideDown,...)

Definition at line 70 of file gdcmFileHelper.h.

Referenced by vtkGdcmReader::LoadImageInMemory().

00071                         { UserFunction = userFunc; }   

void gdcm::FileHelper::SetWriteFileTypeToACR  )  [protected]
 

Pushes out the whole group 0002 FIXME : better, set a flag to tell the writer not to write it ... FIXME : method should probably have an other name ! SetWriteFileTypeToACR is NOT opposed to SetWriteFileTypeToExplicitVR and SetWriteFileTypeToImplicitVR.

Definition at line 984 of file gdcmFileHelper.cxx.

References Archive, and gdcm::DocEntryArchive::Push().

Referenced by Write().

00985 {
00986    Archive->Push(0x0002,0x0000);
00987    Archive->Push(0x0002,0x0001);
00988    Archive->Push(0x0002,0x0002);
00989    Archive->Push(0x0002,0x0003);
00990    Archive->Push(0x0002,0x0010);
00991    Archive->Push(0x0002,0x0012);
00992    Archive->Push(0x0002,0x0013);
00993    Archive->Push(0x0002,0x0016);
00994    Archive->Push(0x0002,0x0100);
00995    Archive->Push(0x0002,0x0102);
00996 }

void gdcm::FileHelper::SetWriteFileTypeToExplicitVR  )  [protected]
 

Definition at line 1013 of file gdcmFileHelper.cxx.

References Archive, CopyDataEntry(), gdcm::RefCounter::Delete(), gdcm::Util::DicomString(), gdcm::Global::GetTS(), gdcm::DocEntryArchive::Push(), and gdcm::DataEntry::SetString().

Referenced by Write().

01014 {
01015    std::string ts = Util::DicomString( 
01016       Global::GetTS()->GetSpecialTransferSyntax(TS::ExplicitVRLittleEndian) );
01017 
01018    DataEntry *tss = CopyDataEntry(0x0002,0x0010);
01019    tss->SetString(ts);
01020 
01021    Archive->Push(tss);
01022    tss->Delete();
01023 }

void gdcm::FileHelper::SetWriteFileTypeToImplicitVR  )  [protected]
 

Sets in the File the TransferSyntax to 'Implicit VR Little Endian".

Definition at line 1028 of file gdcmFileHelper.cxx.

References Archive, CopyDataEntry(), gdcm::RefCounter::Delete(), gdcm::Util::DicomString(), gdcm::Global::GetTS(), gdcm::DocEntryArchive::Push(), and gdcm::DataEntry::SetString().

Referenced by Write().

01029 {
01030    std::string ts = Util::DicomString(
01031       Global::GetTS()->GetSpecialTransferSyntax(TS::ImplicitVRLittleEndian) );
01032 
01033    DataEntry *tss = CopyDataEntry(0x0002,0x0010);
01034    tss->SetString(ts);
01035 
01036    Archive->Push(tss);
01037    tss->Delete();
01038 }

void gdcm::FileHelper::SetWriteFileTypeToJPEG  )  [protected]
 

Sets in the File the TransferSyntax to 'Explicit VR Little Endian".

Definition at line 1001 of file gdcmFileHelper.cxx.

References Archive, CopyDataEntry(), gdcm::RefCounter::Delete(), gdcm::Util::DicomString(), gdcm::Global::GetTS(), gdcm::DocEntryArchive::Push(), and gdcm::DataEntry::SetString().

Referenced by Write().

01002 {
01003    std::string ts = Util::DicomString( 
01004       Global::GetTS()->GetSpecialTransferSyntax(TS::JPEGBaselineProcess1) );
01005 
01006    DataEntry *tss = CopyDataEntry(0x0002,0x0010);
01007    tss->SetString(ts);
01008 
01009    Archive->Push(tss);
01010    tss->Delete();
01011 }

void gdcm::FileHelper::SetWriteMode FileMode  mode  )  [inline]
 

Sets the Write Mode ( ).

Definition at line 120 of file gdcmFileHelper.h.

00120 { WriteMode = mode;         }

void gdcm::FileHelper::SetWriteModeToRaw  )  [inline]
 

Tells the writer we want to keep 'Grey pixels + Palettes color' when possible (as opposed to convert 'Palettes color' to RGB).

Definition at line 115 of file gdcmFileHelper.h.

00115 { SetWriteMode(WMODE_RAW);  }

void gdcm::FileHelper::SetWriteModeToRGB  )  [inline]
 

Tells the writer we want to write RGB image when possible (as opposed to 'Grey pixels + Palettes color').

Definition at line 118 of file gdcmFileHelper.h.

00118 { SetWriteMode(WMODE_RGB);  }

void gdcm::FileHelper::SetWriteToLibido  )  [protected]
 

Set the Write not to Libido format.

Definition at line 1051 of file gdcmFileHelper.cxx.

References Archive, gdcm::DataEntry::Copy(), CopyDataEntry(), gdcm::RefCounter::Delete(), FileInternal, gdcm::DocEntrySet::GetDataEntry(), gdcm::DocEntry::GetDictEntry(), gdcm::DataEntry::GetString(), gdcm::DataEntry::New(), gdcm::DocEntryArchive::Push(), and gdcm::DataEntry::SetString().

Referenced by Write().

01052 {
01053    DataEntry *oldRow = FileInternal->GetDataEntry(0x0028, 0x0010);
01054    DataEntry *oldCol = FileInternal->GetDataEntry(0x0028, 0x0011);
01055    
01056    if ( oldRow && oldCol )
01057    {
01058       std::string rows, columns; 
01059 
01060       DataEntry *newRow=DataEntry::New(oldRow->GetDictEntry());
01061       DataEntry *newCol=DataEntry::New(oldCol->GetDictEntry());
01062 
01063       newRow->Copy(oldCol);
01064       newCol->Copy(oldRow);
01065 
01066       newRow->SetString(oldCol->GetString());
01067       newCol->SetString(oldRow->GetString());
01068 
01069       Archive->Push(newRow);
01070       Archive->Push(newCol);
01071 
01072       newRow->Delete();
01073       newCol->Delete();
01074    }
01075 
01076    DataEntry *libidoCode = CopyDataEntry(0x0008,0x0010);
01077    libidoCode->SetString("ACRNEMA_LIBIDO_1.1");
01078    Archive->Push(libidoCode);
01079    libidoCode->Delete();
01080 }

void gdcm::FileHelper::SetWriteToNoLibido  )  [protected]
 

Set the Write not to No Libido format.

Definition at line 1085 of file gdcmFileHelper.cxx.

References Archive, CopyDataEntry(), gdcm::RefCounter::Delete(), FileInternal, gdcm::DocEntrySet::GetDataEntry(), gdcm::DataEntry::GetString(), gdcm::DocEntryArchive::Push(), and gdcm::DataEntry::SetString().

Referenced by Write().

01086 {
01087    DataEntry *recCode = FileInternal->GetDataEntry(0x0008,0x0010);
01088    if ( recCode )
01089    {
01090       if ( recCode->GetString() == "ACRNEMA_LIBIDO_1.1" )
01091       {
01092          DataEntry *libidoCode = CopyDataEntry(0x0008,0x0010);
01093          libidoCode->SetString("");
01094          Archive->Push(libidoCode);
01095          libidoCode->Delete();
01096       }
01097    }
01098 }

void gdcm::FileHelper::SetWriteToRaw  )  [protected]
 

Updates the File to write RAW data (as opposed to RGB data) (modifies, when necessary, photochromatic interpretation, bits allocated, Pixels element VR).

Definition at line 802 of file gdcmFileHelper.cxx.

References Archive, CopyDataEntry(), gdcm::RefCounter::Delete(), FileInternal, gdcm::DataEntry::FLAG_PIXELDATA, gdcm::File::GetBitsAllocated(), gdcm::PixelWriteConvert::GetData(), gdcm::PixelWriteConvert::GetDataSize(), GetFile(), gdcm::File::GetNumberOfScalarComponents(), gdcm::PixelReadConvert::GetRaw(), gdcm::PixelReadConvert::GetRawSize(), gdcm::File::HasLUT(), PixelReadConverter, PixelWriteConverter, gdcm::DocEntryArchive::Push(), gdcm::DataEntry::SetBinArea(), gdcm::DataEntry::SetFlag(), gdcm::DocEntry::SetLength(), gdcm::PixelWriteConvert::SetReadData(), gdcm::DataEntry::SetString(), and SetWriteToRGB().

Referenced by SetWriteToRGB(), and Write().

00803 {
00804    if ( FileInternal->GetNumberOfScalarComponents() == 3 
00805     && !FileInternal->HasLUT() )
00806    {
00807       SetWriteToRGB();
00808    } 
00809    else
00810    {
00811       DataEntry *photInt = CopyDataEntry(0x0028,0x0004);
00812       if (FileInternal->HasLUT() )
00813       {
00814          photInt->SetString("PALETTE COLOR ");
00815       }
00816       else
00817       {
00818          photInt->SetString("MONOCHROME2 ");
00819       }
00820 
00821       PixelWriteConverter->SetReadData(PixelReadConverter->GetRaw(),
00822                                        PixelReadConverter->GetRawSize());
00823 
00824       std::string vr = "OB";
00825       if ( FileInternal->GetBitsAllocated()>8 )
00826          vr = "OW";
00827       if ( FileInternal->GetBitsAllocated()==24 ) // For RGB ACR files 
00828          vr = "OB";
00829       DataEntry *pixel = 
00830          CopyDataEntry(GetFile()->GetGrPixel(),GetFile()->GetNumPixel(),vr);
00831       pixel->SetFlag(DataEntry::FLAG_PIXELDATA);
00832       pixel->SetBinArea(PixelWriteConverter->GetData(),false);
00833       pixel->SetLength(PixelWriteConverter->GetDataSize());
00834 
00835       Archive->Push(photInt);
00836       Archive->Push(pixel);
00837 
00838       photInt->Delete();
00839       pixel->Delete();
00840    }
00841 }

void gdcm::FileHelper::SetWriteToRGB  )  [protected]
 

Updates the File to write RGB data (as opposed to RAW data) (modifies, when necessary, photochromatic interpretation, samples per pixel, Planar configuration, bits allocated, bits stored, high bit -ACR 24 bits- Pixels element VR, pushes out the LUT, ).

Definition at line 850 of file gdcmFileHelper.cxx.

References Archive, gdcm::PixelReadConvert::BuildRGBImage(), CopyDataEntry(), gdcm::RefCounter::Delete(), FileInternal, gdcm::DataEntry::FLAG_PIXELDATA, gdcm::File::GetBitsAllocated(), gdcm::PixelWriteConvert::GetData(), gdcm::PixelWriteConvert::GetDataSize(), GetFile(), gdcm::File::GetNumberOfScalarComponents(), gdcm::PixelReadConvert::GetRaw(), gdcm::PixelReadConvert::GetRawSize(), gdcm::PixelReadConvert::GetRGB(), gdcm::PixelReadConvert::GetRGBSize(), PixelReadConverter, PixelWriteConverter, gdcm::DocEntryArchive::Push(), gdcm::DataEntry::SetBinArea(), gdcm::DataEntry::SetFlag(), gdcm::DocEntry::SetLength(), gdcm::PixelWriteConvert::SetReadData(), gdcm::DataEntry::SetString(), and SetWriteToRaw().

Referenced by SetWriteToRaw(), and Write().

00851 {
00852    if ( FileInternal->GetNumberOfScalarComponents()==3 )
00853    {
00854       PixelReadConverter->BuildRGBImage();
00855       
00856       DataEntry *spp = CopyDataEntry(0x0028,0x0002);
00857       spp->SetString("3 ");
00858 
00859       DataEntry *planConfig = CopyDataEntry(0x0028,0x0006);
00860       planConfig->SetString("0 ");
00861 
00862       DataEntry *photInt = CopyDataEntry(0x0028,0x0004);
00863       photInt->SetString("RGB ");
00864 
00865       if ( PixelReadConverter->GetRGB() )
00866       {
00867          PixelWriteConverter->SetReadData(PixelReadConverter->GetRGB(),
00868                                           PixelReadConverter->GetRGBSize());
00869       }
00870       else // Raw data
00871       {
00872          PixelWriteConverter->SetReadData(PixelReadConverter->GetRaw(),
00873                                           PixelReadConverter->GetRawSize());
00874       }
00875 
00876       std::string vr = "OB";
00877       if ( FileInternal->GetBitsAllocated()>8 )
00878          vr = "OW";
00879       if ( FileInternal->GetBitsAllocated()==24 ) // For RGB ACR files 
00880          vr = "OB";
00881       DataEntry *pixel = 
00882          CopyDataEntry(GetFile()->GetGrPixel(),GetFile()->GetNumPixel(),vr);
00883       pixel->SetFlag(DataEntry::FLAG_PIXELDATA);
00884       pixel->SetBinArea(PixelWriteConverter->GetData(),false);
00885       pixel->SetLength(PixelWriteConverter->GetDataSize());
00886 
00887       Archive->Push(spp);
00888       Archive->Push(planConfig);
00889       Archive->Push(photInt);
00890       Archive->Push(pixel);
00891 
00892       spp->Delete();
00893       planConfig->Delete();
00894       photInt->Delete();
00895       pixel->Delete();
00896 
00897       // Remove any LUT
00898       Archive->Push(0x0028,0x1101);
00899       Archive->Push(0x0028,0x1102);
00900       Archive->Push(0x0028,0x1103);
00901       Archive->Push(0x0028,0x1201);
00902       Archive->Push(0x0028,0x1202);
00903       Archive->Push(0x0028,0x1203);
00904 
00905       // push out Palette Color Lookup Table UID, if any
00906       Archive->Push(0x0028,0x1199);
00907 
00908       // For old '24 Bits' ACR-NEMA
00909       // Thus, we have a RGB image and the bits allocated = 24 and 
00910       // samples per pixels = 1 (in the read file)
00911       if ( FileInternal->GetBitsAllocated()==24 ) 
00912       {
00913          DataEntry *bitsAlloc = CopyDataEntry(0x0028,0x0100);
00914          bitsAlloc->SetString("8 ");
00915 
00916          DataEntry *bitsStored = CopyDataEntry(0x0028,0x0101);
00917          bitsStored->SetString("8 ");
00918 
00919          DataEntry *highBit = CopyDataEntry(0x0028,0x0102);
00920          highBit->SetString("7 ");
00921 
00922          Archive->Push(bitsAlloc);
00923          Archive->Push(bitsStored);
00924          Archive->Push(highBit);
00925 
00926          bitsAlloc->Delete();
00927          bitsStored->Delete();
00928          highBit->Delete();
00929       }
00930    }
00931    else
00932    {
00933       SetWriteToRaw();
00934    }
00935 }

void gdcm::FileHelper::SetWriteType FileType  format  )  [inline]
 

Tells the writer which format we want to write (ImplicitVR, ExplicitVR, ACR, ACR_LIBIDO).

Definition at line 138 of file gdcmFileHelper.h.

00138 { WriteType = format;       }

void gdcm::FileHelper::SetWriteTypeToAcr  )  [inline]
 

Tells the writer we want to write as ACR-NEMA.

Definition at line 131 of file gdcmFileHelper.h.

References gdcm::ACR.

Referenced by WriteAcr(), and vtkGdcmWriter::WriteDcmFile().

00131 { SetWriteType(ACR);        }

void gdcm::FileHelper::SetWriteTypeToAcrLibido  )  [inline]
 

Tells the writer we want to write as LibIDO.

Definition at line 133 of file gdcmFileHelper.h.

References gdcm::ACR_LIBIDO.

Referenced by vtkGdcmWriter::WriteDcmFile().

void gdcm::FileHelper::SetWriteTypeToDcmExplVR  )  [inline]
 

Tells the writer we want to write as Explicit VR.

Definition at line 129 of file gdcmFileHelper.h.

References gdcm::ExplicitVR.

Referenced by WriteDcmExplVR(), and vtkGdcmWriter::WriteDcmFile().

void gdcm::FileHelper::SetWriteTypeToDcmImplVR  )  [inline]
 

Tells the writer we want to write as Implicit VR.

Definition at line 127 of file gdcmFileHelper.h.

References gdcm::ImplicitVR.

Referenced by vtkGdcmWriter::WriteDcmFile(), and WriteDcmImplVR().

void gdcm::FileHelper::SetWriteTypeToJPEG  )  [inline]
 

Tells the writer we want to write as JPEG.

Definition at line 135 of file gdcmFileHelper.h.

References gdcm::JPEG.

00135 { SetWriteType(JPEG);       }

void gdcm::RefCounter::Unregister  )  [inline, inherited]
 

Unregister the object.

Remarks:
It decrements the reference counting

Definition at line 48 of file gdcmRefCounter.h.

Referenced by gdcm::SeqEntry::ClearSQItem(), gdcm::DicomDir::Copy(), gdcm::DocEntrySet::GetDictEntry(), gdcm::CommandManager::InSetCommand(), gdcm::DocEntrySet::NewDataEntry(), gdcm::DocEntrySet::NewSeqEntry(), gdcm::Document::ReadNextDocEntry(), gdcm::SQItem::RemoveEntry(), gdcm::ElementSet::RemoveEntry(), gdcm::SeqEntry::SetDelimitationItem(), gdcm::DocEntry::~DocEntry(), and ~FileHelper().

00049    {
00050       RefCount--;
00051       if(RefCount<=0)
00052          delete this;
00053    }

bool gdcm::FileHelper::Write std::string const &  fileName  ) 
 

Writes on disk A SINGLE Dicom file,.

Parameters:
fileName name of the file to be created (any already existing file is overwritten)
Returns:
false if write fails
Todo:
the best trick would be *change* the recognition code but pb expected if user deals with, e.g. COMPLEX images

Definition at line 657 of file gdcmFileHelper.cxx.

References gdcm::ACR, gdcm::ACR_LIBIDO, CheckMandatoryElements(), CheckWriteIntegrity(), gdcm::ExplicitVR, FileInternal, gdcm::DocEntrySet::GetDataEntry(), gdcm::ImplicitVR, gdcm::DocEntrySet::InsertEntryString(), gdcm::JPEG, RestoreWrite(), RestoreWriteFileType(), RestoreWriteMandatory(), RestoreWriteOfLibido(), SetWriteFileTypeToACR(), SetWriteFileTypeToExplicitVR(), SetWriteFileTypeToImplicitVR(), SetWriteFileTypeToJPEG(), SetWriteToLibido(), SetWriteToNoLibido(), SetWriteToRaw(), SetWriteToRGB(), gdcm::Unknown, WMODE_RAW, WMODE_RGB, gdcm::File::Write(), WriteMode, and WriteType.

Referenced by WriteAcr(), WriteDcmExplVR(), vtkGdcmWriter::WriteDcmFile(), and WriteDcmImplVR().

00658 {
00659    switch(WriteType)
00660    {
00661       case ImplicitVR:
00662          SetWriteFileTypeToImplicitVR();
00663          break;
00664       case Unknown:  // should never happen; ExplicitVR is the default value
00665       case ExplicitVR:
00666          SetWriteFileTypeToExplicitVR();
00667          break;
00668       case ACR:
00669       case ACR_LIBIDO:
00670       // NOTHING is done here just for LibIDO.
00671       // Just to avoid further trouble if user creates a file ex-nihilo,
00672       // wants to write it as an ACR-NEMA file,
00673       // and forgets to create any Entry belonging to group 0008
00674       // (shame on him !)
00675       // We add Recognition Code (RET)
00676         if ( ! FileInternal->GetDataEntry(0x0008, 0x0010) )
00677             FileInternal->InsertEntryString("ACR-NEMA V1.0 ", 0x0008, 0x0010);
00678          SetWriteFileTypeToACR();
00679         // SetWriteFileTypeToImplicitVR(); // ACR IS implicit VR !
00680          break;
00681       case JPEG:
00682          SetWriteFileTypeToJPEG();
00683          std::cerr << "Writting as JPEG" << std::endl;
00684          break;
00685    }
00686    CheckMandatoryElements();
00687 
00688    // --------------------------------------------------------------
00689    // Special Patch to allow gdcm to re-write ACR-LibIDO formated images
00690    //
00691    // if recognition code tells us we dealt with a LibIDO image
00692    // we reproduce on disk the switch between lineNumber and columnNumber
00693    // just before writting ...
00696    
00697    if ( WriteType == ACR_LIBIDO )
00698    {
00699       SetWriteToLibido();
00700    }
00701    else
00702    {
00703       SetWriteToNoLibido();
00704    }
00705    // ----------------- End of Special Patch ----------------
00706   
00707    switch(WriteMode)
00708    {
00709       case WMODE_RAW :
00710          SetWriteToRaw(); // modifies and pushes to the archive, when necessary
00711          break;
00712       case WMODE_RGB :
00713          SetWriteToRGB(); // modifies and pushes to the archive, when necessary
00714          break;
00715    }
00716 
00717    bool check = CheckWriteIntegrity(); // verifies length
00718    if (WriteType == JPEG ) check = true;
00719    if (check)
00720    {
00721       check = FileInternal->Write(fileName,WriteType);
00722    }
00723 
00724    RestoreWrite();
00725    RestoreWriteFileType();
00726    RestoreWriteMandatory();
00727 
00728    // --------------------------------------------------------------
00729    // Special Patch to allow gdcm to re-write ACR-LibIDO formated images
00730    // 
00731    // ...and we restore the header to be Dicom Compliant again 
00732    // just after writting
00733    RestoreWriteOfLibido();
00734    // ----------------- End of Special Patch ----------------
00735 
00736    return check;
00737 }

bool gdcm::FileHelper::WriteAcr std::string const &  fileName  ) 
 

Writes on disk A SINGLE Dicom file, using the ACR-NEMA convention NO test is performed on processor "Endiannity". (a l'attention des logiciels cliniques qui ne prennent en entrée QUE des images ACR ...

Warning:
if a DICOM_V3 header is supplied, groups < 0x0008 and shadow groups are ignored

NO TEST is performed on processor "Endiannity".

Parameters:
fileName name of the file to be created (any already existing file is overwritten)
Returns:
false if write fails

Definition at line 645 of file gdcmFileHelper.cxx.

References SetWriteTypeToAcr(), and Write().

00646 {
00647    SetWriteTypeToAcr();
00648    return Write(fileName);
00649 }

bool gdcm::FileHelper::WriteDcmExplVR std::string const &  fileName  ) 
 

Writes on disk A SINGLE Dicom file, using the Explicit Value Representation convention NO test is performed on processor "Endiannity".

Parameters:
fileName name of the file to be created (any already existing file is overwritten)
Returns:
false if write fails

Definition at line 625 of file gdcmFileHelper.cxx.

References SetWriteTypeToDcmExplVR(), and Write().

00626 {
00627    SetWriteTypeToDcmExplVR();
00628    return Write(fileName);
00629 }

bool gdcm::FileHelper::WriteDcmImplVR std::string const &  fileName  ) 
 

Writes on disk A SINGLE Dicom file, using the Implicit Value Representation convention NO test is performed on processor "Endianity".

Parameters:
fileName name of the file to be created (any already existing file is overwritten)
Returns:
false if write fails

Definition at line 610 of file gdcmFileHelper.cxx.

References SetWriteTypeToDcmImplVR(), and Write().

00611 {
00612    SetWriteTypeToDcmImplVR();
00613    return Write(fileName);
00614 }

bool gdcm::FileHelper::WriteRawData std::string const &  fileName  ) 
 

Writes on disk A SINGLE Dicom file NO test is performed on processor "Endiannity". It's up to the user to call his Reader properly.

Parameters:
fileName name of the file to be created (any already existing file is over written)
Returns:
false if write fails

Definition at line 567 of file gdcmFileHelper.cxx.

References gdcmErrorMacro, gdcmWarningMacro, gdcm::PixelReadConvert::GetRaw(), gdcm::PixelReadConvert::GetRawSize(), gdcm::PixelReadConvert::GetRGB(), gdcm::PixelReadConvert::GetRGBSize(), gdcm::PixelWriteConvert::GetUserData(), gdcm::PixelWriteConvert::GetUserDataSize(), PixelReadConverter, and PixelWriteConverter.

00568 {
00569    std::ofstream fp1(fileName.c_str(), std::ios::out | std::ios::binary );
00570    if (!fp1)
00571    {
00572       gdcmWarningMacro( "Fail to open (write) file:" << fileName.c_str());
00573       return false;
00574    }
00575 
00576    if ( PixelWriteConverter->GetUserData() )
00577    {
00578       fp1.write( (char *)PixelWriteConverter->GetUserData(), 
00579                  PixelWriteConverter->GetUserDataSize() );
00580    }
00581    else if ( PixelReadConverter->GetRGB() )
00582    {
00583       fp1.write( (char *)PixelReadConverter->GetRGB(), 
00584                  PixelReadConverter->GetRGBSize());
00585    }
00586    else if ( PixelReadConverter->GetRaw() )
00587    {
00588       fp1.write( (char *)PixelReadConverter->GetRaw(), 
00589                  PixelReadConverter->GetRawSize());
00590    }
00591    else
00592    {
00593       gdcmErrorMacro( "Nothing written." );
00594    }
00595 
00596    fp1.close();
00597 
00598    return true;
00599 }


Member Data Documentation

bool gdcm::FileHelper::Abort [mutable, protected]
 

Definition at line 200 of file gdcmFileHelper.h.

Referenced by CallStartMethod().

DocEntryArchive* gdcm::FileHelper::Archive [private]
 

Pointer to the DocEntryArchive (used while writting process).

Definition at line 218 of file gdcmFileHelper.h.

Referenced by CheckMandatoryElements(), CheckMandatoryEntry(), CopyMandatoryEntry(), Initialize(), RestoreWrite(), RestoreWriteMandatory(), RestoreWriteOfLibido(), SetMandatoryEntry(), SetWriteFileTypeToACR(), SetWriteFileTypeToExplicitVR(), SetWriteFileTypeToImplicitVR(), SetWriteFileTypeToJPEG(), SetWriteToLibido(), SetWriteToNoLibido(), SetWriteToRaw(), SetWriteToRGB(), and ~FileHelper().

File* gdcm::FileHelper::FileInternal [private]
 

gdcm::File to use to load the file

Definition at line 205 of file gdcmFileHelper.h.

Referenced by CheckMandatoryElements(), CheckMandatoryEntry(), CheckWriteIntegrity(), CopyDataEntry(), FileHelper(), GetImageData(), GetRaw(), Initialize(), InsertEntryBinArea(), InsertEntryString(), InsertSeqEntry(), Load(), Print(), SetEntryBinArea(), SetEntryString(), SetFileName(), SetWriteToLibido(), SetWriteToNoLibido(), SetWriteToRaw(), SetWriteToRGB(), Write(), and ~FileHelper().

bool gdcm::FileHelper::KeepMediaStorageSOPClassUID [private]
 

if user knows he didn't modify the pixels (e.g. he just anonymized the file), he is allowed to ask to keep the original 'Media Storage SOP Class UID' and 'Image Type'

Definition at line 238 of file gdcmFileHelper.h.

Referenced by CheckMandatoryElements(), and Initialize().

bool gdcm::FileHelper::Parsed [private]
 

Whether already parsed or not.

Definition at line 208 of file gdcmFileHelper.h.

PixelReadConvert* gdcm::FileHelper::PixelReadConverter [private]
 

Pointer to the PixelReadConverter.

Definition at line 212 of file gdcmFileHelper.h.

Referenced by FileHelper(), GetImageData(), GetImageDataRawSize(), GetImageDataSize(), GetLutItemNumber(), GetLutItemSize(), GetLutRGBA(), GetRaw(), GetRawData(), GetRawDataSize(), GetRGBData(), GetRGBDataSize(), Initialize(), Load(), Print(), SetWriteToRaw(), SetWriteToRGB(), WriteRawData(), and ~FileHelper().

PixelWriteConvert* gdcm::FileHelper::PixelWriteConverter [private]
 

Pointer to the PixelWriteConverter.

Definition at line 214 of file gdcmFileHelper.h.

Referenced by CheckWriteIntegrity(), GetImageData(), GetImageDataRawSize(), GetImageDataSize(), GetUserData(), GetUserDataSize(), Initialize(), SetUserData(), SetWriteToRaw(), SetWriteToRGB(), WriteRawData(), and ~FileHelper().

int gdcm::Base::PrintLevel [protected, inherited]
 

Amount of printed details for each Dicom Entries : 0 : stands for the least detail level.

Definition at line 55 of file gdcmBase.h.

Referenced by gdcm::SQItem::Print(), gdcm::SeqEntry::Print(), Print(), gdcm::ElementSet::Print(), gdcm::DocEntry::Print(), gdcm::DictEntry::Print(), gdcm::DicomDirStudy::Print(), gdcm::DicomDirSerie::Print(), gdcm::DicomDirPatient::Print(), gdcm::DicomDirMeta::Print(), gdcm::DicomDir::Print(), and gdcm::DataEntry::Print().

float gdcm::FileHelper::Progress [protected]
 

value of the ??? for any progress bar

Definition at line 199 of file gdcmFileHelper.h.

Referenced by CallEndMethod(), and CallStartMethod().

VOID_FUNCTION_PUINT8_PFILE_POINTER gdcm::FileHelper::UserFunction [private]
 

Pointer to a user supplied function to allow modification of pixel order (e.g. : Mirror, UpsideDown, 90°Rotation, ...) use as : void userSuppliedFunction(uint8_t *im, gdcm::File *f) NB : the "uint8_t *" type of first param is just for prototyping. User will Cast it according what he founds with f->GetPixelType() See vtkgdcmSerieViewer for an example.

Definition at line 233 of file gdcmFileHelper.h.

Referenced by GetRaw(), and Initialize().

FileMode gdcm::FileHelper::WriteMode [private]
 

(WMODE_RAW, WMODE_RGB)

Definition at line 222 of file gdcmFileHelper.h.

Referenced by CheckWriteIntegrity(), Initialize(), and Write().

FileType gdcm::FileHelper::WriteType [private]
 

(ImplicitVR, ExplicitVR, ACR, ACR_LIBIDO)

Definition at line 225 of file gdcmFileHelper.h.

Referenced by CheckMandatoryElements(), Initialize(), and Write().


The documentation for this class was generated from the following files:
Generated on Fri Jan 20 10:15:07 2006 for gdcm by  doxygen 1.4.4