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

virtual ~FileHelper ()
 canonical destructor
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 DocEntry (i.e. a Dicom Element) 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 DocEntry (i.e. a Dicom Element) 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 DocEntry (Dicom entry) 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 DocEntry (Dicom entry) 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)
 Modifies the value of a given DocEntry (Dicom entry) when it exists. Creates it, empty (?!) when unexistant.
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 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 ()
static FileHelperNew (File *header)

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).
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 We cannot know *how* the user made the File : (reading an old ACR-NEMA file or a not very clean DICOM file ...).
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

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

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  )  [virtual]
 

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 }

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 );
00163    }
00164 }


Member Function Documentation

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 1254 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_UNKNOWN, 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().

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

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

Definition at line 1591 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().

01592 {
01593    DataEntry *entry = FileInternal->GetDataEntry(group,elem);
01594    if ( !entry )
01595    {
01596       entry = DataEntry::New(Global::GetDicts()->GetDefaultPubDict()->GetEntry(group,elem));
01597       entry->SetString(value);
01598       Archive->Push(entry);
01599       entry->Delete();
01600    }
01601 }

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 751 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().

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

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 1126 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().

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

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

Definition at line 1611 of file gdcmFileHelper.cxx.

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

Referenced by CheckMandatoryElements().

01612 {
01613    DataEntry *entry = CopyDataEntry(group,elem);
01614    entry->SetString(value);
01615    Archive->Push(entry);
01616    entry->Delete();
01617 }

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 40 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(), 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(), gdcm::DicomDir::~DicomDir(), and gdcm::Global::~Global().

00040 { 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(), 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 349 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.

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

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 384 of file gdcmFileHelper.cxx.

References GetRaw().

00385 {
00386    return GetRaw();
00387 }

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 328 of file gdcmFileHelper.cxx.

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

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

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 312 of file gdcmFileHelper.cxx.

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

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

int gdcm::FileHelper::GetLutItemNumber  ) 
 

Access to the underlying PixelReadConverter RGBA LUT Item Number.

Definition at line 548 of file gdcmFileHelper.cxx.

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

00549 {
00550    return PixelReadConverter->GetLutItemNumber();
00551 }

int gdcm::FileHelper::GetLutItemSize  ) 
 

Access to the underlying PixelReadConverter RGBA LUT Item Size.

Definition at line 556 of file gdcmFileHelper.cxx.

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

00557 {
00558    return PixelReadConverter->GetLutItemSize();
00559 }

uint8_t * gdcm::FileHelper::GetLutRGBA  ) 
 

Access to the underlying PixelReadConverter RGBA LUT.

Definition at line 538 of file gdcmFileHelper.cxx.

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

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

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 1680 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().

01681 {
01682    PixelReadConverter->SetUserFunction( UserFunction );
01683 
01684    uint8_t *raw = PixelReadConverter->GetRaw();
01685    if ( ! raw )
01686    {
01687       // The Raw image migth not be loaded yet:
01688       std::ifstream *fp = FileInternal->OpenFile();
01689       PixelReadConverter->ReadAndDecompressPixelData( fp );
01690       if ( fp ) 
01691          FileInternal->CloseFile();
01692 
01693       raw = PixelReadConverter->GetRaw();
01694       if ( ! raw )
01695       {
01696          gdcmWarningMacro( "Read/decompress of pixel data apparently went wrong.");
01697          return 0;
01698       }
01699    }
01700    return raw;
01701 }

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 521 of file gdcmFileHelper.cxx.

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

00522 {
00523    return PixelReadConverter->GetRaw();
00524 }

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 530 of file gdcmFileHelper.cxx.

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

00531 {
00532    return PixelReadConverter->GetRawSize();
00533 }

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

Get the reference counting.

Returns:
Reference count

Definition at line 57 of file gdcmRefCounter.h.

00058    {
00059       return RefCount;
00060    }

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 503 of file gdcmFileHelper.cxx.

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

00504 {
00505    return PixelReadConverter->GetRGB();
00506 }

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 512 of file gdcmFileHelper.cxx.

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

00513 {
00514    return PixelReadConverter->GetRGBSize();
00515 }

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 485 of file gdcmFileHelper.cxx.

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

00486 {
00487    return PixelWriteConverter->GetUserData();
00488 }

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 494 of file gdcmFileHelper.cxx.

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

00495 {
00496    return PixelWriteConverter->GetUserDataSize();
00497 }

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 1661 of file gdcmFileHelper.cxx.

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

Referenced by FileHelper().

01662 {
01663    UserFunction = 0;
01664    KeepMediaStorageSOPClassUID = false;
01665    
01666    WriteMode = WMODE_RAW;
01667    WriteType = ExplicitVR;
01668 
01669    PixelReadConverter  = new PixelReadConvert;
01670    PixelWriteConverter = new PixelWriteConvert;
01671    Archive = new DocEntryArchive( FileInternal );
01672 }

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

Modifies the value of a given DocEntry (Dicom entry) 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 Dicom entry (NULL when creation failed).

Definition at line 285 of file gdcmFileHelper.cxx.

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

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

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

Modifies the value of a given DocEntry (Dicom entry) 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 Dicom entry (NULL when creation failed).

Definition at line 268 of file gdcmFileHelper.cxx.

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

00270 {
00271    return FileInternal->InsertEntryString(content, group, elem);
00272 }

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

Modifies the value of a given DocEntry (Dicom entry) when it exists. Creates it, empty (?!) when unexistant.

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

Definition at line 299 of file gdcmFileHelper.cxx.

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

00300 {
00301    return FileInternal->InsertSeqEntry(group, elem);
00302 }

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 );
00224    return true;
00225 }

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

Definition at line 56 of file gdcmFileHelper.h.

00056 {return new FileHelper(header);}

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

Definition at line 55 of file gdcmFileHelper.h.

00055 {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 1709 of file gdcmFileHelper.cxx.

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

01710 {
01711    FileInternal->SetPrintLevel(PrintLevel);
01712    FileInternal->Print(os);
01713 
01714    if ( FileInternal->IsReadable() )
01715    {
01716       PixelReadConverter->SetPrintLevel(PrintLevel);
01717       PixelReadConverter->Print(os);
01718    }
01719 }

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

Register the object.

Remarks:
It increments the reference counting

Definition at line 45 of file gdcmRefCounter.h.

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

00045 { RefCount++; }

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

Restore the File write mode.

Definition at line 942 of file gdcmFileHelper.cxx.

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

Referenced by Write().

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

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

Restore in the File the initial group 0002.

Definition at line 1046 of file gdcmFileHelper.cxx.

Referenced by Write().

01047 {
01048 }

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

Restore in the File the initial group 0002.

Definition at line 1622 of file gdcmFileHelper.cxx.

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

Referenced by Write().

01623 {
01624    // group 0002 may be pushed out for ACR-NEMA writting purposes 
01625    Archive->Restore(0x0002,0x0000);
01626    Archive->Restore(0x0002,0x0001);
01627    Archive->Restore(0x0002,0x0002);
01628    Archive->Restore(0x0002,0x0003);
01629    Archive->Restore(0x0002,0x0010);
01630    Archive->Restore(0x0002,0x0012);
01631    Archive->Restore(0x0002,0x0013);
01632    Archive->Restore(0x0002,0x0016);
01633    Archive->Restore(0x0002,0x0100);
01634    Archive->Restore(0x0002,0x0102);
01635 
01636    // FIXME : Check if none is missing !
01637    
01638    Archive->Restore(0x0008,0x0012);
01639    Archive->Restore(0x0008,0x0013);
01640    Archive->Restore(0x0008,0x0016);
01641    Archive->Restore(0x0008,0x0018);
01642    Archive->Restore(0x0008,0x0060);
01643    Archive->Restore(0x0008,0x0070);
01644    Archive->Restore(0x0008,0x0080);
01645    Archive->Restore(0x0008,0x0090);
01646    Archive->Restore(0x0008,0x2112);
01647 
01648    Archive->Restore(0x0010,0x0010);
01649    Archive->Restore(0x0010,0x0030);
01650    Archive->Restore(0x0010,0x0040);
01651 
01652    Archive->Restore(0x0020,0x000d);
01653    Archive->Restore(0x0020,0x000e);
01654 }

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

Restore the Write format.

Definition at line 1105 of file gdcmFileHelper.cxx.

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

Referenced by Write().

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

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

Accesses an existing DocEntry (i.e. a Dicom Element) 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 DocEntry not found

Definition at line 253 of file gdcmFileHelper.cxx.

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

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

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

Accesses an existing DocEntry (i.e. a Dicom Element) 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 DocEntry not found

Definition at line 236 of file gdcmFileHelper.cxx.

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

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

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 463 of file gdcmFileHelper.cxx.

References SetUserData().

00464 {
00465    SetUserData(inData, expectedSize);
00466 }

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 1603 of file gdcmFileHelper.cxx.

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

01604 {
01605    DataEntry *entry = DataEntry::New(Global::GetDicts()->GetDefaultPubDict()->GetEntry(group,elem));
01606    entry->SetString(value);
01607    Archive->Push(entry);
01608    entry->Delete();
01609 }

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 476 of file gdcmFileHelper.cxx.

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

Referenced by SetImageData().

00477 {
00478    PixelWriteConverter->SetUserData(inData, expectedSize);
00479 }

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.

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 986 of file gdcmFileHelper.cxx.

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

Referenced by Write().

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

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

Definition at line 1015 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().

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

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

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

Definition at line 1030 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().

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

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

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

Definition at line 1003 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().

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

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 1053 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().

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

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

Set the Write not to No Libido format.

Definition at line 1087 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().

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

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 804 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().

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

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 852 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().

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

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().

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.

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().

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 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 49 of file gdcmRefCounter.h.

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

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

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 659 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(), and WriteDcmImplVR().

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

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 647 of file gdcmFileHelper.cxx.

References SetWriteTypeToAcr(), and Write().

00648 {
00649    SetWriteTypeToAcr();
00650    return Write(fileName);
00651 }

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 627 of file gdcmFileHelper.cxx.

References SetWriteTypeToDcmExplVR(), and Write().

00628 {
00629    SetWriteTypeToDcmExplVR();
00630    return Write(fileName);
00631 }

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 612 of file gdcmFileHelper.cxx.

References SetWriteTypeToDcmImplVR(), and Write().

00613 {
00614    SetWriteTypeToDcmImplVR();
00615    return Write(fileName);
00616 }

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 569 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.

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


Member Data Documentation

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

Pointer to the DocEntryArchive (used while writting process).

Definition at line 206 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 193 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 226 of file gdcmFileHelper.h.

Referenced by CheckMandatoryElements(), and Initialize().

bool gdcm::FileHelper::Parsed [private]
 

Whether already parsed or not.

Definition at line 196 of file gdcmFileHelper.h.

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

Pointer to the PixelReadConverter.

Definition at line 200 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 202 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().

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 221 of file gdcmFileHelper.h.

Referenced by GetRaw(), and Initialize().

FileMode gdcm::FileHelper::WriteMode [private]
 

(WMODE_RAW, WMODE_RGB)

Definition at line 210 of file gdcmFileHelper.h.

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

FileType gdcm::FileHelper::WriteType [private]
 

(ImplicitVR, ExplicitVR, ACR, ACR_LIBIDO)

Definition at line 213 of file gdcmFileHelper.h.

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


The documentation for this class was generated from the following files:
Generated on Fri Nov 18 15:58:39 2005 for gdcm by  doxygen 1.4.4