00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef GDCMFILEHELPER_H
00020 #define GDCMFILEHELPER_H
00021
00022 #include "gdcmDebug.h"
00023 #include "gdcmRefCounter.h"
00024
00025
00026 namespace gdcm
00027 {
00028 class File;
00029 class DataEntry;
00030 class SeqEntry;
00031 class PixelReadConvert;
00032 class PixelWriteConvert;
00033 class DocEntryArchive;
00034
00035 typedef void (*VOID_FUNCTION_PUINT8_PFILE_POINTER)(uint8_t *, File *);
00036
00037
00043 class GDCM_EXPORT FileHelper : public RefCounter
00044 {
00045 gdcmTypeMacro(FileHelper);
00046
00047 public:
00048 enum FileMode
00049 {
00050 WMODE_RAW,
00051 WMODE_RGB
00052 };
00053
00054 public:
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
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);
00080 DataEntry *InsertEntryBinArea(uint8_t *binArea, int lgth,
00081 uint16_t group, uint16_t elem);
00082 SeqEntry *InsertSeqEntry(uint16_t group, uint16_t elem);
00083
00084
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
00096 void SetUserData(uint8_t *data, size_t expectedSize);
00097 uint8_t *GetUserData();
00098 size_t GetUserDataSize();
00099
00100 uint8_t *GetRGBData();
00101 size_t GetRGBDataSize();
00102
00103 uint8_t *GetRawData();
00104 size_t GetRawDataSize();
00105
00106
00107 uint8_t* GetLutRGBA();
00108 int GetLutItemNumber();
00109 int GetLutItemSize();
00110
00111
00112
00115 void SetWriteModeToRaw() { SetWriteMode(WMODE_RAW); }
00118 void SetWriteModeToRGB() { SetWriteMode(WMODE_RGB); }
00120 void SetWriteMode(FileMode mode) { WriteMode = mode; }
00122 FileMode GetWriteMode() { return WriteMode; }
00123
00124
00125
00127 void SetWriteTypeToDcmImplVR() { SetWriteType(ImplicitVR); }
00129 void SetWriteTypeToDcmExplVR() { SetWriteType(ExplicitVR); }
00131 void SetWriteTypeToAcr() { SetWriteType(ACR); }
00133 void SetWriteTypeToAcrLibido() { SetWriteType(ACR_LIBIDO); }
00135 void SetWriteTypeToJPEG() { SetWriteType(JPEG); }
00138 void SetWriteType(FileType format) { WriteType = format; }
00141 FileType GetWriteType() { return WriteType; }
00142
00143
00144
00145
00146 bool WriteRawData (std::string const &fileName);
00147 bool WriteDcmImplVR(std::string const &fileName);
00148 bool WriteDcmExplVR(std::string const &fileName);
00149 bool WriteAcr (std::string const &fileName);
00150 bool Write (std::string const &fileName);
00154 void SetKeepMediaStorageSOPClassUID (bool v)
00155 { KeepMediaStorageSOPClassUID = v; }
00156
00157
00158 void CallStartMethod();
00159 void CallProgressMethod();
00160 void CallEndMethod();
00161
00162 protected:
00163 FileHelper( );
00164 FileHelper( File *header );
00165 ~FileHelper();
00166
00167 bool CheckWriteIntegrity();
00168
00169 void SetWriteToRaw();
00170 void SetWriteToRGB();
00171 void RestoreWrite();
00172
00173 void SetWriteFileTypeToACR();
00174 void SetWriteFileTypeToJPEG();
00175 void SetWriteFileTypeToExplicitVR();
00176 void SetWriteFileTypeToImplicitVR();
00177 void RestoreWriteFileType();
00178
00179 void SetWriteToLibido();
00180 void SetWriteToNoLibido();
00181 void RestoreWriteOfLibido();
00182
00183 DataEntry *CopyDataEntry(uint16_t group, uint16_t elem,
00184 const TagName &vr = GDCM_VRUNKNOWN);
00185 void CheckMandatoryElements();
00186 void CheckMandatoryEntry(uint16_t group, uint16_t elem, std::string value);
00187 void SetMandatoryEntry(uint16_t group, uint16_t elem, std::string value);
00188 void CopyMandatoryEntry(uint16_t group, uint16_t elem, std::string value);
00189 void RestoreWriteMandatory();
00190
00191 private:
00192 void Initialize();
00193
00194 uint8_t *GetRaw();
00195
00196
00197 protected:
00199 float Progress;
00200 mutable bool Abort;
00201
00202 private:
00203
00205 File *FileInternal;
00206
00208 bool Parsed;
00209
00210
00212 PixelReadConvert *PixelReadConverter;
00214 PixelWriteConvert *PixelWriteConverter;
00215
00216
00218 DocEntryArchive *Archive;
00219
00220
00222 FileMode WriteMode;
00223
00225 FileType WriteType;
00226
00233 VOID_FUNCTION_PUINT8_PFILE_POINTER UserFunction;
00234
00238 bool KeepMediaStorageSOPClassUID;
00239 };
00240 }
00241
00242
00243 #endif