MeVisLab Toolbox Reference
|
Basic tool functions used to store, load, and modify a PagedImage in a file, used by the MLImageFormat. More...
#include <mlImageFormatTools.h>
Public Types | |
enum | SaveModeBits { DefaultSaveMode = 0 , AllowPartialPages = 1 , SaveOnlyDefaultValue = 2 } |
Mode bits describing special save options. More... | |
typedef void | MLImageFormatNotifyCB(double progress, void *usrData) |
Callback type that can be registered in save and overwrite functions to interrupt processing and to get process state information. More... | |
Static Public Member Functions | |
static MLuint32 | calcCheckSum (const void *dataPtr, size_t numBytes, size_t voxSize) |
Calculates a 24 bit checksum for the data given by dataPtr. More... | |
static void | setDICOMTreeSourceFileName (PagedImage &outImg, const std::string &fileName) |
If the paged image has DicomTreeImagePropertyExtensions, then set their file names, as other modules perhaps want to derive destination file names from them as it is done, for example, in ImageSave. More... | |
PUBLIC FILE MANAGEMENT. | |
static MLErrorCode | open (MLImageFormatInfos *&infos, const std::string &fileName, bool truncate=false, const std::string &compressorName="", const MLImageFormatTagList &compressionTagList=MLImageFormatTagList::getDefaultEmptyTagList(), const MLImageFormatTagList &userTagList=MLImageFormatTagList::getDefaultEmptyTagList(), const MLImageFormatTagList &privateTagList=MLImageFormatTagList::getDefaultEmptyTagList(), const std::string &defaultVoxelValue="0", bool rewritable=true, bool suppressReadCheckSumTests=false) |
Opens a file in binary mode returning a descriptor for the opened file. More... | |
static MLErrorCode | open (MLImageFormatInfos *&infos, MLImageFormatAbstractFileHandle *fileHandle, bool truncate=false, const std::string &compressorName="", const MLImageFormatTagList &compressionTagList=MLImageFormatTagList::getDefaultEmptyTagList(), const MLImageFormatTagList &userTagList=MLImageFormatTagList::getDefaultEmptyTagList(), const MLImageFormatTagList &privateTagList=MLImageFormatTagList::getDefaultEmptyTagList(), const std::string &defaultVoxelValue="0", bool rewritable=true, bool suppressReadCheckSumTests=false) |
Overload of open() with a virtual file handle, have a look at open(..., filename, ...). More... | |
static MLErrorCode | close (MLImageFormatInfos *&infos) |
Closes an open file. More... | |
static MLErrorCode | save (MLImageFormatInfos &infos, PagedImage &inputPagedImg, const SubImageBox &box=SubImageBox(), MLImageFormatNotifyCB *callback=nullptr, void *userData=nullptr, const ScaleShiftData &scaleShiftData=ScaleShiftData(), MLuint32 saveModeBits=DefaultSaveMode, MLdouble *saveTime=nullptr, MLdouble *prepTime=nullptr) |
Saves the data of the paged image inputPagedImg from the region given by box in the file. More... | |
static MLErrorCode | overwriteHeaderAndPageList (const MLImageFormatInfos &infos, MLuint32 saveModeBits) |
Saves the file header information a second time over the already written file. More... | |
static MLErrorCode | overwrite (MLImageFormatInfos &infos, PagedImage &inputPagedImg, const SubImageBox &box, MLImageFormatNotifyCB *callback, void *userData, const ScaleShiftData &scaleShiftData, MLuint32 saveModeBits=DefaultSaveMode, MLdouble *saveTime=nullptr, MLdouble *prepTime=nullptr) |
Overwrites a region in a file that has been written before (with save). More... | |
static MLErrorCode | overwrite (MLImageFormatInfos &infos, const SubImage &inputSubImg, MLImageFormatNotifyCB *callback, void *userData, const ScaleShiftData &scaleShiftData, MLuint32 saveModeBits=DefaultSaveMode, MLdouble *saveTime=nullptr, MLdouble *prepTime=nullptr) |
Overwrites a region in a file that has been written before (with save). More... | |
static MLErrorCode | getTile (const MLImageFormatInfos &infos, SubImage &subImgToFill, bool useFileDataType, bool useFileRegion, const ScaleShiftData &scaleShiftData) |
Loads a subimage from the specified file and returns an MLErrorCode describing success or failure. More... | |
Static Public Attributes | |
static const std::string | ML_FILE_VERSION_STRING |
Basic file version string used for MeVisLab release 1.5. More... | |
static const std::string | ML_FILE_VERSION_STRING_EXT |
Basic file version string used for MeVisLab release 1.5 plus addOns. More... | |
static const size_t | ML_MAX_VERSION_AND_FIRST_PAIR_SIZE |
Number of characters that will not be exceeded by version string and first tag pair. More... | |
Static Protected Member Functions | |
static MLErrorCode | _loadFileProperties (MLImageFormatInfos &infos) |
Reads all information from the file given by fileHandle in infos and stores it in the returned information object. More... | |
static MLErrorCode | _destroyFileProperties (MLImageFormatInfos *&infos) |
Destroys the MLImageFileInfo object and resets the pointer to NULL. More... | |
static MLErrorCode | _loadPage (const MLImageFormatInfos &infos, MLint pageId, SubImage &pageBuf) |
Reads page given by ID pageId into memory handled by pageBuf . More... | |
static MLErrorCode | _decompressPageData (const MLImageFormatInfos &infos, const size_t savedPageSizeInBytes, const size_t expectedSizeInBytes, MLuint8 *&loadedPage, bool &isLossy) |
Decompresses and replaces data given as pointer in loadedPage. More... | |
static MLErrorCode | _saveIndexTableAndPages (MLImageFormatInfos &infos, const SubImageBox &box, PagedImage *inputPagedImg, const SubImage *inputSubImg, MLImageFormatNotifyCB *callback, void *userData, const ScaleShiftData &scaleShiftData, bool replaceAreaToSave, MLuint32 saveModeBits, MLdouble *saveTime=nullptr, MLdouble *prepTime=nullptr) |
Saves or overwrites pages overlapping areaToSave of inputPagedImg. More... | |
static MLErrorCode | _savePage (MLImageFormatInfos &infos, const MLint pageId, const bool isOutsideAreaToSave, const MLTypeData *defaultVoxelPtr, const SubImage &subImgToSave, const bool replaceOnlyWrittenPageIds, const MLuint32 saveModeBits, TimeCounter &saveTimer, MLdouble &saveTime, TimeCounter &calcTimer, MLdouble &calcTime) |
Stores the page subImgToSave in file given by infos and updates the corresponding entry in the index table. More... | |
static MLErrorCode | _compressPageData (DataCompressor *compressor, SubImage &dataSubImg, MLint &dstBufSize) |
Compresses data of a subimage. More... | |
Friends | |
class | MLImageFormatSaveHandler |
Basic tool functions used to store, load, and modify a PagedImage in a file, used by the MLImageFormat.
Definition at line 39 of file mlImageFormatTools.h.
typedef void ml::MLImageFormatTools::MLImageFormatNotifyCB(double progress, void *usrData) |
Callback type that can be registered in save and overwrite functions to interrupt processing and to get process state information.
Definition at line 58 of file mlImageFormatTools.h.
Mode bits describing special save options.
Definition at line 45 of file mlImageFormatTools.h.
|
staticprotected |
Compresses data of a subimage.
compressor | Instance of MLDataCompressor used for compression of page data if non-NULL. If NULL, the page data is not compressed. |
dataSubImg | Subimage containing the data to compress. Its data chunk is (only) overwritten with compressed data on effective and successful compression. |
dstBufSize | Size of compressed data or 0 if no compression took place (because it was ineffective or no compressor was available). |
|
staticprotected |
Decompresses and replaces data given as pointer in loadedPage.
infos | The information structure about the current working file. Its settings must match the corresponding settings of inputPagedImg. |
savedPageSizeInBytes | Must be exactly the size of the compressed memory buffer given in loadedPage. |
expectedSizeInBytes | The expected size of the uncompressed memory. |
loadedPage | Must be a valid pointer to loaded and compressed page data. It will be freed with MLFree() and replaced with decompressed data if decompression takes place. On failure, it also could be returned as NULL. |
isLossy | Will be overwritten to false if the data was compressed losslessly, otherwise true . |
|
staticprotected |
Destroys the MLImageFileInfo object and resets the pointer to NULL.
Returns ML_RESULT_OK on success or on failure an MLErrorCode describing the problem.
|
staticprotected |
Reads all information from the file given by fileHandle in infos and stores it in the returned information object.
infos | infos must be a valid information structure created by open() on the file to read from. |
|
staticprotected |
Reads page given by ID pageId
into memory handled by pageBuf
.
pageBuf must provide enough data for a fully loaded page extent. Returns ML_RESULT_OK on success and another MLErrorCode otherwise. Requires that infos is valid, that it describes a file opened for reading, and that all passed parameters (index table and tag list) are already read from that open file. It also requires that data type and box of pageBuf are set correctly. Note that the loading process may cause that the page box is modified to match the valid image region.
|
staticprotected |
Saves or overwrites pages overlapping areaToSave of inputPagedImg.
Note that only one of both pointers, inputPagedImg and inputSubImg, may be non-NULL to define a unique source for the data to be written. Whichever is used, its data type must fit the setting in info and it must contain the box to be saved if box is non-empty.
infos | The information structure about the current working file. Its settings must match the corresponding settings of inputPagedImg. |
box | box describing the pages to be written, pages outside are not stored and marked as pages filled with defaultVoxelValue. Regions outside but inside of pages are filled with defaultVoxelValue. An empty box is considered as full image. |
inputPagedImg | The paged image from where page data and/or image properties are taken to be stored. It must be up-to-date. |
inputSubImg | The subimage from which page data and image properties are taken to be stored. It must be up-to-date. |
callback | Function to be called on different processing and storage to notify and/or break the storage process. May be passed as NULL pointer and is ignored then. |
userData | Application data passed to the callback function or NULL not needed. |
scaleShiftData | Defines a linear transformation to be applied on data from inputPagedImg or inputSubImg before saving it on disk. Default is the identical transformation. |
replaceAreaToSave | If true , then the area to save is overwritten without changes of other file contents outside that region. If false , then all pages are overwritten, even if outside the areaToSave. Note that true also may cause that partially written pages are loaded and rewritten with changes. It also may cause a fragmentation of the file if written pages do not fit into their former data gap. Default is false . |
saveTime | Ignored if NULL; otherwise, it returns the time needed for pure data saving without data preparation such as data reordering or compression. |
prepTime | Ignored if NULL; otherwise, it returns the time needed for data preparation such as reordering or compression without saving. |
saveModeBits | Bit combination setting special save options: See SaveModeBits for possible options. |
|
staticprotected |
Stores the page subImgToSave in file given by infos and updates the corresponding entry in the index table.
Note that pages outside the areaToSave are not stored - only the index table entries are updated. In this case, subImgToSave does not need to have a valid data pointer. If saveModeBits allow storing partial pages, then subImgToSave will be reduced, too.
infos | File information structure from file open in writable and binary mode. |
pageId | ID of page to be stored. |
isOutsideAreaToSave | true if page is outside the area to save, false otherwise. If true , then only entries of the index table are updated. |
defaultVoxelPtr | Pointer to value used for non-stored values outside box and for stored page regions outside box. |
subImgToSave | The page data to be saved. It must be up to date. |
replaceOnlyWrittenPageIds | If true , then entries of the index table are updated only if isOutsideAreaToSave is false. Otherwise, all page IDs are updated, even those whose pages are not stored. |
saveModeBits | Bit combination setting special save options: See SaveModeBits for possible options. |
saveTimer | TimeCounter used to measure the time needed for pure data saving without data preparation such as data reordering or compression. |
saveTime | The time measured with saveTimer is added to this value. |
calcTimer | TimeCounter used to measure the time needed for data processing such as compression, reordering, and computing checksums without saving time. |
calcTime | The time measured with calcTimer is added to this value. |
|
static |
Calculates a 24 bit checksum for the data given by dataPtr.
All values of each byte in the data are multiplied with their byte position and added to the sum. The checksum calculation traverses voxel data endianness-independent; therefore, it assumes that the data is in local machine endianness. Thus the calculated sum will be the same on machines with a different endianness.
dataPtr | Points to the chunk of data to be check-summed. |
numBytes | The whole number of bytes to be included in checksum. |
voxSize | The size of a voxel in bytes stored in the data. numBytes must be divisible exactly by voxSize. |
|
static |
Closes an open file.
Closing a non-open file causes an error.
infos | A pointer to a valid information structure created by open() on the file to be closed. |
|
static |
Loads a subimage from the specified file and returns an MLErrorCode describing success or failure.
Previous settings of the subimage are overwritten. Subimage memory will be (re)allocated if its pointer is NULL or if memory denoted by box and data type is insufficient; otherwise, the memory will be reused.
infos | infos must be a valid information structure created by open() on the file to read from. |
subImgToFill | The subimage to be manage the loaded data. |
useFileDataType | If true , then the data type of the stored file is used; if false , the data type of subImgToFill is used. Default is to use the data type of the subimage. |
useFileRegion | If true , then the extent of the file is loaded as tile and the subImgToFill box is overwritten; if false , the region of subImgToFill is used. Default is to use the region of the subimage. |
scaleShiftData | Specifies scale factor and offset for loaded data. If not passed, the data will not be rescaled. |
Note that this routine will use subImgToFill.free() and subImgToFill.allocate() to (re)allocate the data if its size is insufficient. Be sure that eventually set subimage data was also allocated with subImgToFill.allocate() or MLAllocateMemory (and not with new or a similar method) to avoid collisions of memory managers. Automatically opens the file if still not done and closes it after operation if autoClose is true (the default).
|
static |
Opens a file in binary mode returning a descriptor for the opened file.
infos | A NULL MLImageFormatPointer that is initialized with an object with open file information. |
fileName | The UTF-8 encoded path and name of the file to be opened. |
truncate | Opens the file for new or overwriting the file and discarding the previous contents if true . Reopens an exiting file for reading and manipulation if false . |
compressorName | Name of DataCompressor used for data compression if not "" (the default). |
compressionTagList | The list of MLImageFormatTags storing arguments for the compressor passed in compressor argument. Ignored if compressor is NULL. |
userTagList | The list of MLImageFormatTags storing user information. |
privateTagList | The list of MLImageFormatTags storing private information. |
defaultVoxelValue | The string value used for all non existing pages and not written pages to define a background value for sparsely written image. |
rewritable | If truncate is false , then this flag decides whether the file is opened as read only or as a rewritable file. Default is true , which means that opening is done in read-write mode. This flag is ignored if truncate is true. |
suppressReadCheckSumTests | If true , then checksum tests are disabled while reading page data to gain maximum load performance; the default is off, as this is not recommended. Not allowed if the file is created or modified. |
|
static |
Overload of open() with a virtual file handle, have a look at open(..., filename, ...).
The ownership of the MLImageFormatAbstractFileHandle is passed to the MLImageFormatInfos and it will be deleted when calling close().
|
static |
Overwrites a region in a file that has been written before (with save).
infos | infos must be a valid information structure created by open() on the file to write in. |
inputSubImg | The ML subimage that shall overwrite the corresponding area in the file. |
callback | Function to be executed during the save process to update process state or NULL (the default) if not set. |
userData | Application data to be passed to the callback function if it is called. Otherwise, it is ignored. |
scaleShiftData | Defines a linear transformation to be applied on data from inputPagedImg or inputSubImg before saving it on disk. Default is the identical transformation. |
saveModeBits | Bit combination setting special save options: See SaveModeBits for possible options. |
saveTime | Ignored if NULL; otherwise, it returns the time needed for pure data saving without data preparation such as data reordering or compression. |
prepTime | Ignored if NULL; otherwise, it returns the time needed for data preparation such as reordering or compression without saving. |
|
static |
Overwrites a region in a file that has been written before (with save).
infos | infos must be a valid information structure created by open() on the file to write in. |
inputPagedImg | The ML paged image providing the image data to be stored. |
box | Only pages overlapping with box are written into the file. It defaults to the empty box. An empty box means that the whole image is to be stored. |
callback | Function to be executed during the save process to update process state or NULL (the default) if not set. |
userData | Application data to be passed to the callback function if it is called. Otherwise, it is ignored. |
scaleShiftData | Defines a linear transformation that is to be applied on data from inputPagedImg or inputSubImg before saving it on disk. Default is the identical transformation. |
saveModeBits | Bit combination setting special save options: See SaveModeBits for possible options. |
saveTime | Ignored if NULL; otherwise, it returns the time needed for pure data saving without data preparation such as data reordering or compression. |
prepTime | Ignored if NULL; otherwise, it returns the time needed for data preparation such as reordering or compression without saving. |
|
static |
Saves the file header information a second time over the already written file.
It requires that the file is already written (for example, with save()) and that the file is open. It allows an update of already written tags, for example, after correcting the minimum or maximum voxel values, or other image properties. WARNING, IMPORTANT: It is only possible to overwrite the tag list correctly if its binary size is unchanged, and page properties and indexes remain consistent. It is left to the caller to guarantee this consistency. Use this method with care!
infos | infos must be a valid information structure created by open() on the file to write in. |
saveModeBits | Bit combination setting special save options: See SaveModeBits for possible options. |
|
static |
Saves the data of the paged image inputPagedImg from the region given by box in the file.
Regions outside box are filled with the value given in infos. Existing files will be overwritten without check.
infos | infos must be a valid information structure created by open() on the file to write in. |
inputPagedImg | The ML paged image providing the image data to be stored. |
box | Only pages overlapping with box are written into the file. It defaults to the empty box. An empty box means that the whole image is to be stored. |
callback | Function to be executed during the save process to update process state or NULL (the default) if not set. |
userData | Application data to is be passed to the callback function if it is called. Otherwise, it is ignored. |
scaleShiftData | Defines a linear transformation that is to be applied on data from inputPagedImg or inputSubImg before saving it on disk. Default is the identical transformation. |
saveModeBits | Bit combination setting special save options: See SaveModeBits for possible options. |
saveTime | Ignored if NULL; otherwise, it returns the time needed for pure data saving without data preparation such as data reordering or compression. |
prepTime | Ignored if NULL; otherwise, it returns the time needed for data preparation such as reordering or compression without saving. |
|
static |
If the paged image has DicomTreeImagePropertyExtensions, then set their file names, as other modules perhaps want to derive destination file names from them as it is done, for example, in ImageSave.
If there is no such extension, then create an empty one, as the file name if often needed. Invalid output images are not modified and no names are set.
outImg | The output image in whose DICOM property extensions the file names shall be set. |
fileName | The file name to be set. |
|
friend |
Definition at line 42 of file mlImageFormatTools.h.
|
static |
Basic file version string used for MeVisLab release 1.5.
Version string used by the first MLImageFormat source. If possible, all future versions should be able to read it. The length of the string will not change in future versions.
Definition at line 69 of file mlImageFormatTools.h.
|
static |
Basic file version string used for MeVisLab release 1.5 plus addOns.
Backward compatible to version ML_FILE_VERSION_STRING, but version ML_FILE_VERSION_STRING is not forward compatible with ML_FILE_VERSION_STRING_EXT.
Definition at line 76 of file mlImageFormatTools.h.
|
static |
Number of characters that will not be exceeded by version string and first tag pair.
Definition at line 82 of file mlImageFormatTools.h.