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 // Implement 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 
106  static std::string buildFileNameWithExtension(std::string fileName);
107 
108 
109  //----------------------------------------------------------------------
112  //----------------------------------------------------------------------
149  MLErrorCode open(bool truncate = false,
150  const std::string &compressorName = "",
151  const MLImageFormatTagList &compressionArgs = MLImageFormatTagList::getDefaultEmptyTagList(),
152  const MLImageFormatTagList &userTagList = MLImageFormatTagList::getDefaultEmptyTagList(),
153  const MLImageFormatTagList &privateTagList = MLImageFormatTagList::getDefaultEmptyTagList(),
154  const std::string &defaultVoxelVal = "0",
155  bool rewritable = true,
156  bool suppressReadCheckSumTests = false);
157 
166  MLErrorCode openForReading(bool suppressReadCheckSumTests = false);
167 
190  const SubImageBox &box = SubImageBox(),
191  const ScaleShiftData &scaleShiftData = ScaleShiftData(),
192  bool onlyCreate=false);
193 
209  const SubImageBox &box = SubImageBox(),
210  const ScaleShiftData &scaleShiftData = ScaleShiftData());
211 
223  MLErrorCode overwrite(const SubImage &inputSubImg,
224  const ScaleShiftData &scaleShiftData = ScaleShiftData());
225 
245  MLdouble newMaxVoxelValue,
246  std::string *errorDescription = nullptr);
247 
252 
253 
259 
260 
289  MLErrorCode getTile(SubImage &subImgToFill,
290  bool useFileDataType = false,
291  bool useFileRegion = false,
292  const ScaleShiftData &scaleShiftData = ScaleShiftData());
293 
294 
304  void setCallback(MLImageFormatTools::MLImageFormatNotifyCB *callback = nullptr,
305  void *userData = nullptr);
306 
308  MLImageFormatTools::MLImageFormatNotifyCB *getCallbackFunction() const;
309 
311  void *getCallbackFunctionData() const;
312 
314 
315  //----------------------------------------------------------------------
318  //----------------------------------------------------------------------
323 
327 
331 
332  protected:
333 
346 
347  private:
348 
351  MLImageFormat(const MLImageFormat &);
352 
355  MLImageFormat& operator=(const MLImageFormat &){ return *this; };
356 
357 
359  std::string _fileName;
360 
362  MLImageFormatAbstractFileHandle* _fileHandle;
363 
365  MLImageFormatInfos *_infos;
366 
368  MLImageFormatTools::MLImageFormatNotifyCB *_callback;
369 
371  void *_userData;
372 
374  bool _arePartialPagesEnabled;
375 
379  MLdouble _dataPreparationTime;
380 
383  MLdouble _pureSaveTime;
384 
386  MLImageFormatTagList _defaultEmptyTagList;
387  const MLImageFormatTagList _defaultEmptyConstTagList;
388  const MLImageFormatTagList _defaultEmptyUserTagList;
389  const MLImageFormatTagList _defaultEmptyPrivateTagList;
390  const MLImageFormatTagList _defaultEmptyCompressionTagList;
392 
393  };
394 
395 ML_END_NAMESPACE
396 
397 
398 #endif // of __mlImageFormat_H
#define MLIMAGEFORMATBASE_EXPORT
Global and OS specific declarations for the MLImageFormatBase project.
A base class for abstract read/write access of the MLImageFileFormat.
A internal structure containing information about an opened file, not to be used, because it is subje...
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()
Save the file header information a second time over the already written file.
MLImageFormat(MLImageFormatAbstractFileHandle *fileHandle)
Constructor which 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)
Save the file header information a second time over the already written file and replace the min/max ...
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())
Save the specified region of the paged image in the file and leave all regions outside box unchanged.
MLErrorCode openForReading(bool suppressReadCheckSumTests=false)
Convenience method to opens 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())
Save the specified region of the paged image in the file and leave all regions outside box unchanged.
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)
Save the specified region of the paged image in the file and fill all other regions with the value gi...
const MLImageFormatInfos * getInternalInfos() const
Returns a pointer to the private internal information of the managed file; it is subject to change.
MLdouble getPureSaveTime() const
Time needed for the recent save or overwrite operation in seconds, however without data preparation; ...
MLImageFormat(const std::string &fileName="")
Constructor which 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 (which then maintai...
Class which represents an image, which manages properties of an image and image data which is located...
Definition: mlPagedImage.h:70
This class manages/represents a rectangular 6d image region which is organized linearly in memory.
Definition: mlSubImage.h:75
MLint32 MLErrorCode
Type of an ML Error code.
Definition: mlTypeDefs.h:818
double MLdouble
Definition: mlTypeDefs.h:223
TScaleShiftData< MLdouble > ScaleShiftData
Double version of TScaleShiftData for maximum reasonable precision.
TSubImageBox< MLint > SubImageBox
Define the standard SubImageBox type used in the ML. Its size varies with the size of the MLint type.