gdcmFileHelper.h

Go to the documentation of this file.
00001 /*=========================================================================
00002                                                                                 
00003   Program:   gdcm
00004   Module:    $RCSfile: gdcmFileHelper.h,v $
00005   Language:  C++
00006   Date:      $Date: 2007/08/24 10:45:18 $
00007   Version:   $Revision: 1.53 $
00008                                                                                 
00009   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
00010   l'Image). All rights reserved. See Doc/License.txt or
00011   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
00012                                                                                 
00013      This software is distributed WITHOUT ANY WARRANTY; without even
00014      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00015      PURPOSE.  See the above copyright notices for more information.
00016                                                                                 
00017 =========================================================================*/
00018 
00019 #ifndef _GDCMFILEHELPER_H_
00020 #define _GDCMFILEHELPER_H_
00021 
00022 #include "gdcmDebug.h"
00023 #include "gdcmRefCounter.h"
00024 #include "gdcmVRKey.h"
00025 #include "gdcmFile.h"
00026 
00027 namespace GDCM_NAME_SPACE
00028 {
00029 //class File;
00030 class DataEntry;
00031 class SeqEntry;
00032 class PixelReadConvert;
00033 class PixelWriteConvert;
00034 class DocEntryArchive;
00035 
00036 typedef void (*VOID_FUNCTION_PUINT8_PFILE_POINTER)(uint8_t *, File *);
00037 
00038 //-----------------------------------------------------------------------------
00044 class GDCM_EXPORT FileHelper : public RefCounter
00045 {
00046    gdcmTypeMacro(FileHelper);
00047 
00048 public:
00049    enum FileMode
00050    {
00051       WMODE_RAW,
00052       WMODE_RGB
00053    };
00054 
00056    static FileHelper *New() {return new FileHelper();}
00058    static FileHelper *New(File *header) {return new FileHelper(header);}
00059 
00060    void Print(std::ostream &os = std::cout, std::string const &indent = ""); 
00061 
00063    File *GetFile() { return FileInternal; }
00064    
00065 
00066    void SetLoadMode(int loadMode);
00067    void SetFileName(std::string const &fileName);
00068    bool Load();
00070    void SetUserFunction( VOID_FUNCTION_PUINT8_PFILE_POINTER userFunc ) 
00071                         { UserFunction = userFunc; }   
00072    // File methods
00073    bool SetEntryString(std::string const &content,
00074                            uint16_t group, uint16_t elem);
00075    bool SetEntryBinArea(uint8_t *content, int lgth,
00076                             uint16_t group, uint16_t elem);
00077 
00078    DataEntry *InsertEntryString(std::string const &content,
00079                                 uint16_t group, uint16_t elem, const VRKey &vr);
00080    DataEntry *InsertEntryBinArea(uint8_t *binArea, int lgth,
00081                                 uint16_t group, uint16_t elem, const VRKey &vr);
00082    SeqEntry *InsertSeqEntry(uint16_t group, uint16_t elem);
00083 
00084    // File helpers
00085    size_t GetImageDataSize();
00086    size_t GetImageDataRawSize();
00087 
00088    uint8_t *GetImageData();
00089    uint8_t *GetImageDataRaw();
00090 
00091 // GDCM_LEGACY(size_t GetImageDataIntoVector(void *destination,size_t maxSize))
00092 
00093    void SetImageData(uint8_t *data, size_t expectedSize);
00094 
00095    // User data
00096    void SetUserData(uint8_t *data, size_t expectedSize);
00097    uint8_t *GetUserData();
00098    size_t GetUserDataSize();
00099    // RBG data (from file)
00100    uint8_t *GetRGBData();
00101    size_t GetRGBDataSize();
00102    // RAW data (from file)
00103    uint8_t *GetRawData();
00104    size_t GetRawDataSize();
00105 
00106    void ConvertFixGreyLevels(uint8_t *data, size_t size);
00107 
00108    // LUT
00109    uint8_t* GetLutRGBA();
00110    int GetLutItemNumber();
00111    int GetLutItemSize();
00112 
00113    // Write mode
00114 
00117    void SetWriteModeToRaw()           { SetWriteMode(WMODE_RAW);  }
00120    void SetWriteModeToRGB()           { SetWriteMode(WMODE_RGB);  }
00122    void SetWriteMode(FileMode mode)   { WriteMode = mode;         }
00124    FileMode GetWriteMode()            { return WriteMode;         }
00125 
00126    // Write format
00127 
00129    void SetWriteTypeToDcmImplVR()     { SetWriteType(ImplicitVR); }
00131    void SetWriteTypeToDcmExplVR()     { SetWriteType(ExplicitVR); }
00133    void SetWriteTypeToAcr()           { SetWriteType(ACR);        }
00135    void SetWriteTypeToAcrLibido()     { SetWriteType(ACR_LIBIDO); }
00137    void SetWriteTypeToJPEG()          { SetWriteType(JPEG);       }
00139    void SetWriteTypeToJPEG2000()      { SetWriteType(JPEG2000);   }
00142    void SetWriteType(FileType format) { WriteType = format;       }
00145    FileType GetWriteType()            { return WriteType;         }
00147    void SetPhotometricInterpretationToMonochrome1() {
00148                                     PhotometricInterpretation = 1;}
00150    void SetPhotometricInterpretationToMonochrome2() {
00151                                     PhotometricInterpretation = 2;}
00153    int GetPhotometricInterpretation() {
00154                                 return PhotometricInterpretation; }
00155 
00156    // Write pixels of ONE image on hard drive
00157    // No test is made on processor "endianness"
00158    // The user must call his reader correctly
00159    bool WriteRawData  (std::string const &fileName);
00160    bool WriteDcmImplVR(std::string const &fileName);
00161    bool WriteDcmExplVR(std::string const &fileName);
00162    bool WriteAcr      (std::string const &fileName);
00163    bool Write         (std::string const &fileName);
00164    
00174 
00175    void SetContentType (ImageContentType c) { ContentType = c; }
00176    // no GetContentType() method, on purpose!
00177    
00178    void CallStartMethod();
00179    void CallProgressMethod();
00180    void CallEndMethod();
00181    
00182 protected:
00183    FileHelper( );
00184    FileHelper( File *header );
00185    ~FileHelper();
00186 
00189    bool CheckWriteIntegrity();
00190 
00191    void SetWriteToRaw();
00192    void SetWriteToRGB();
00193    void RestoreWrite();
00194 
00195    void SetWriteFileTypeToACR();
00196    void SetWriteFileTypeToJPEG();
00197    void SetWriteFileTypeToJPEG2000();
00198    void SetWriteFileTypeToExplicitVR();
00199    void SetWriteFileTypeToImplicitVR();
00200    void RestoreWriteFileType();
00201 
00202    void SetWriteToLibido();
00203    void SetWriteToNoLibido();
00204    void RestoreWriteOfLibido();
00205 
00206    DataEntry *CopyDataEntry(uint16_t group, uint16_t elem, 
00207                             const VRKey &vr = GDCM_VRUNKNOWN);
00208    void CheckMandatoryElements();
00209    void CheckMandatoryEntry(uint16_t group, uint16_t elem, std::string value,
00210                             const VRKey &vr = GDCM_VRUNKNOWN);
00211    void SetMandatoryEntry(uint16_t group, uint16_t elem, std::string value,
00212                           const VRKey &vr = GDCM_VRUNKNOWN);
00213    void CopyMandatoryEntry(uint16_t group, uint16_t elem, std::string value,
00214                            const VRKey &vr = GDCM_VRUNKNOWN);
00215    void RestoreWriteMandatory();
00216 
00217 private:
00218    void Initialize();
00219 
00220    uint8_t *GetRaw();
00221 
00222 // members variables:
00223 protected:
00225    float Progress;
00226    mutable bool Abort;
00227    
00228 private:
00229 
00231    File *FileInternal;
00232 
00234    bool Parsed;
00235 
00236    // Utility pixel converter
00237    
00239    PixelReadConvert *PixelReadConverter;
00240    
00242    PixelWriteConvert *PixelWriteConverter;
00243 
00244    // Utility header archive
00246    DocEntryArchive *Archive;
00247 
00248    // Write variables
00250    FileMode WriteMode;
00251 
00253    FileType WriteType;
00254 
00261    VOID_FUNCTION_PUINT8_PFILE_POINTER UserFunction;
00262    
00268    ImageContentType ContentType;
00269  
00272    int PhotometricInterpretation;
00273 
00274 };
00275 } // end namespace gdcm
00276 
00277 //-----------------------------------------------------------------------------
00278 #endif

Generated on Fri Aug 24 12:53:16 2007 for gdcm by  doxygen 1.4.6