MeVisLab Toolbox Reference
mlImageFormat.h
Go to the documentation of this file.
1 /*************************************************************************************
2 **
3 ** Copyright 2007, MeVis Medical Solutions AG
4 **
5 ** The user may use this file in accordance with the license agreement provided with
6 ** the Software or, alternatively, in accordance with the terms contained in a
7 ** written agreement between the user and MeVis Medical Solutions AG.
8 **
9 ** For further information use the contact form at https://www.mevislab.de/contact
10 **
11 **************************************************************************************/
12 
13 #ifndef ML_IMAGE_FORMAT_H
14 #define ML_IMAGE_FORMAT_H
15 
19 
20 // Resolve platform independencies.
22 
23 #include "mlModuleIncludes.h"
24 
25 #include "mlImageFormatTools.h"
26 
27 // Implements everything in ML namespace.
28 ML_START_NAMESPACE
29 
31  class MLImageFormatTagList;
32 
33  //----------------------------------------------------------------------
35  //----------------------------------------------------------------------
37 
38  public:
39 
40  //----------------------------------------------------------------------
43  //----------------------------------------------------------------------
44 
47  MLImageFormat(const std::string &fileName = "");
48 
53 
55  virtual ~MLImageFormat();
57 
58 
59  //----------------------------------------------------------------------
62  //----------------------------------------------------------------------
63 
66  const std::string &getFileName() const;
67 
69  bool isOpen() const;
70 
73 
77 
82 
85 
88 
91 
94 
96  bool arePartialPagesEnabled() const;
97 
100  void enablePartialPages(bool enable);
102 
107  static std::string buildFileNameWithExtension(std::string fileName);
108 
109 
110  //----------------------------------------------------------------------
113  //----------------------------------------------------------------------
150  MLErrorCode open(bool truncate = false,
151  const std::string &compressorName = "",
152  const MLImageFormatTagList &compressionArgs = MLImageFormatTagList::getDefaultEmptyTagList(),
153  const MLImageFormatTagList &userTagList = MLImageFormatTagList::getDefaultEmptyTagList(),
154  const MLImageFormatTagList &privateTagList = MLImageFormatTagList::getDefaultEmptyTagList(),
155  const std::string &defaultVoxelVal = "0",
156  bool rewritable = true,
157  bool suppressReadCheckSumTests = false);
158 
167  MLErrorCode openForReading(bool suppressReadCheckSumTests = false);
168 
191  const SubImageBox &box = SubImageBox(),
192  const ScaleShiftData &scaleShiftData = ScaleShiftData(),
193  bool onlyCreate=false);
194 
210  const SubImageBox &box = SubImageBox(),
211  const ScaleShiftData &scaleShiftData = ScaleShiftData());
212 
224  MLErrorCode overwrite(const SubImage &inputSubImg,
225  const ScaleShiftData &scaleShiftData = ScaleShiftData());
226 
246  MLdouble newMaxVoxelValue,
247  std::string *errorDescription = nullptr);
248 
253 
254 
260 
261 
290  MLErrorCode getTile(SubImage &subImgToFill,
291  bool useFileDataType = false,
292  bool useFileRegion = false,
293  const ScaleShiftData &scaleShiftData = ScaleShiftData());
294 
295 
305  void setCallback(MLImageFormatTools::MLImageFormatNotifyCB *callback = nullptr,
306  void *userData = nullptr);
307 
309  MLImageFormatTools::MLImageFormatNotifyCB *getCallbackFunction() const;
310 
312  void *getCallbackFunctionData() const;
313 
315 
316  //----------------------------------------------------------------------
319  //----------------------------------------------------------------------
324 
328 
332 
333  protected:
334 
347 
348  private:
349 
352  MLImageFormat(const MLImageFormat &);
353 
356  MLImageFormat& operator=(const MLImageFormat &){ return *this; };
357 
358 
360  std::string _fileName;
361 
363  MLImageFormatAbstractFileHandle* _fileHandle;
364 
366  MLImageFormatInfos *_infos;
367 
369  MLImageFormatTools::MLImageFormatNotifyCB *_callback;
370 
372  void *_userData;
373 
375  bool _arePartialPagesEnabled;
376 
380  MLdouble _dataPreparationTime;
381 
384  MLdouble _pureSaveTime;
385 
387  MLImageFormatTagList _defaultEmptyTagList;
388  const MLImageFormatTagList _defaultEmptyConstTagList;
389  const MLImageFormatTagList _defaultEmptyUserTagList;
390  const MLImageFormatTagList _defaultEmptyPrivateTagList;
391  const MLImageFormatTagList _defaultEmptyCompressionTagList;
393 
394  };
395 
396 ML_END_NAMESPACE
397 
398 
399 #endif // of __mlImageFormat_H
#define MLIMAGEFORMATBASE_EXPORT
A base class for abstract read/write access of the MLImageFileFormat.
A internal structure containing information about an opened file.
Class defining a list of tags used in the MLImageFormat class.
File format class to store, load, and modify a PagedImage in a file.
Definition: mlImageFormat.h:36
MLErrorCode open(bool truncate=false, const std::string &compressorName="", const MLImageFormatTagList &compressionArgs=MLImageFormatTagList::getDefaultEmptyTagList(), const MLImageFormatTagList &userTagList=MLImageFormatTagList::getDefaultEmptyTagList(), const MLImageFormatTagList &privateTagList=MLImageFormatTagList::getDefaultEmptyTagList(), const std::string &defaultVoxelVal="0", bool rewritable=true, bool suppressReadCheckSumTests=false)
Opens the file for reading and writing.
void setCallback(MLImageFormatTools::MLImageFormatNotifyCB *callback=nullptr, void *userData=nullptr)
Sets a callback function to be called before/after each save of a page.
MLErrorCode _overwriteHeaderAndPageList()
Saves the file header information a second time over the already written file.
MLImageFormat(MLImageFormatAbstractFileHandle *fileHandle)
Constructor that takes a virtual file handle of an already opened file.
bool isOpen() const
Returns true if file is open, false otherwise.
MLErrorCode getTile(SubImage &subImgToFill, bool useFileDataType=false, bool useFileRegion=false, const ScaleShiftData &scaleShiftData=ScaleShiftData())
Loads a subimage from the specified file and returns an MLErrorCode describing success or failure.
const MLImageFormatTagList & getConstUserTagList() const
Returns the current user tags if available or an empty list otherwise.
MLImageFormatTools::MLImageFormatNotifyCB * getCallbackFunction() const
Returns the currently set callback function, default is NULL.
MLImageFormatTagList & getTagList()
Returns the current tag list if available or an empty list otherwise.
MLErrorCode updateMinMaxTagValuesInOpenFile(MLdouble newMinVoxelValue, MLdouble newMaxVoxelValue, std::string *errorDescription=nullptr)
Saves the file header information a second time over the already written file and replaces the minimu...
MLdouble getDataPreparationTime() const
Time needed for data preparation for the recent save or overwrite operation in seconds,...
const MLImageFormatTagList & getConstPrivateTagList() const
Returns the current private tags or an empty list otherwise.
MLErrorCode close()
Closes an open file, closing a non-open file causes the return of an error.
bool arePartialPagesEnabled() const
Returns true if saving of partial pages is allowed; otherwise, it returns false.
MLErrorCode overwrite(PagedImage &inImg, const SubImageBox &box=SubImageBox(), const ScaleShiftData &scaleShiftData=ScaleShiftData())
Saves the specified region of the paged image in the file and leaves all regions outside box unchange...
MLErrorCode openForReading(bool suppressReadCheckSumTests=false)
Convenience method to open files only for reading.
static std::string buildFileNameWithExtension(std::string fileName)
Assures that the passed filename has the extension ".mlimage" and appends it automatically if not.
const MLImageFormatTagList & getConstCompressionTagList() const
Returns the current compression properties if available or en empty list otherwise.
const PagedImage * getImageProperties() const
Returns the current image properties if available or NULL otherwise.
const std::string & getFileName() const
Returns the fileName.
virtual ~MLImageFormat()
Destructor; closes an eventually open file.
void * getCallbackFunctionData() const
Returns the currently set user data for the callback function, default is NULL.
MLErrorCode overwrite(const SubImage &inputSubImg, const ScaleShiftData &scaleShiftData=ScaleShiftData())
Saves the specified region of the paged image in the file and leaves all regions outside box unchange...
void resetTimeMeasurements()
Resets recent time measurements to 0.
MLErrorCode remove()
Closes the file if still not done and removes it from disk.
MLErrorCode save(PagedImage &inImg, const SubImageBox &box=SubImageBox(), const ScaleShiftData &scaleShiftData=ScaleShiftData(), bool onlyCreate=false)
Saves the specified region of the paged image in the file and fills all other regions with the value ...
const MLImageFormatInfos * getInternalInfos() const
Returns a pointer to the private internal information of the managed file.
MLdouble getPureSaveTime() const
Time needed for the recent save or overwrite operation in seconds without data preparation; defaut is...
MLImageFormat(const std::string &fileName="")
Constructor that stores the name of the file without opening the file.
const MLImageFormatTagList & getConstTagList() const
Returns the current tag list if available or an empty list otherwise.
void enablePartialPages(bool enable)
Enables saving with partial pages if true is passed; otherwise, it is set to false.
The class PagedImage, representing a fragmented image that manages properties and data of an image lo...
Definition: mlPagedImage.h:66
This class manages/represents a rectangular 6D image region that is organized linearly in memory.
Definition: mlSubImage.h:75
MLint32 MLErrorCode
Type of an ML Error code.
Definition: mlTypeDefs.h:716
double MLdouble
Definition: mlTypeDefs.h:217
TScaleShiftData< MLdouble > ScaleShiftData
Double version of TScaleShiftData for maximum reasonable precision.
TSubImageBox< MLint > SubImageBox
Defines the standard SubImageBox type used in the ML. Its size varies with the size of the MLint type...