MeVisLab Toolbox Reference
MLDataCompressor Overview

Overview documentation of the ML DataCompressor project.

MLDataCompressor Class Library

This library contains the base class DataCompressor which allows for implementing new data compression algorithms and a factory class DataCompressorFactory allowing for registration of user derived classes. In this way any number of new compression classes can be implemented which are automatically detected by classes using compression algorithms.

How to implement your own DataCompressor class?

  • Be sure to implement everything in the namespace ML_UTILS_NAMESPACE.
  • Derive from the DataCompressor class and override the following methods:
    virtual const std::string getTypeName() const = 0;
    virtual const std::string getVersion() const = 0;
    virtual const bool isSupportedVersion(const std::string &ver) const = 0;
    virtual MLErrorCode compress(const void *srcMem,
    size_t srcSize,
    void *&dstMem,
    MLint &dstNum) const = 0;
    virtual MLErrorCode decompress(const void *srcMem,
    size_t srcSize,
    void *&dstMem,
    MLint64 &resSize) const = 0;
    MLint32 MLErrorCode
    Type of an ML Error code.
    Definition mlTypeDefs.h:716
    Target mlrange_cast(Source arg)
    Generic version of checked ML casts.
    INT64 MLint64
    Include 64 bit integer support for Windows or Unix.
    Definition mlTypeDefs.h:412
    MLint64 MLint
    A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
    Definition mlTypeDefs.h:490
    It is also recommended to implement
    virtual std::string getVendor() const { return ""; }
    virtual std::string getSuffix() const { return ""; }
    virtual bool isLossy() const { return false; }
  • Register your DataCompressor (for example during dll/so registration) first with YourDataCompressor::initClass() in the runtime type system of the ML and then in the DataCompressor factory:
    YourDataCompressor::initClass();
    DataCompressorFactory::registerCompressor(YourDataCompressor::getClassTypeId());
    This requires the usage of
    #define ML_CLASS_HEADER(className)
    Same like ML_CLASS_HEADER_EXPORTED with a non existing export symbol.
    at the end of your class definition and
    #define ML_CLASS_SOURCE(className, parentName)
    This macro has to be put into the source file of a non-abstract class to implement the methods declar...
    in the implementation.
  • Be sure that classes using the your data compressor will find it registered in the DataCompressorFactory BEFORE they are instantiated. In MeVisLab your can do this by specifying the PreloadDll flag in a .def file for your compressor.
  • You may also want to override the numUsedHints() method and initialize the following members appropriately to specify parameters for your compressor which might be detected and passed by some applications to control the behavior of the compression:
    HintType _hintType[MaxHints];
    MLdouble _dblHints[MaxHints];
    MLint _intHints[MaxHints];
    std::string _strHints[MaxHints];
    std::string _hintName[MaxHints];
    double _rangeMin[MaxHints];
    double _rangeMax[MaxHints];
    double MLdouble
    Definition mlTypeDefs.h:217
    The parameters _hintType, _hintName, rangeMin, and _rangeMax should be set by your derived class, all other should be set to default values.

Then all classes using DataCompressors via the DataCompressorFactory (for example the MLImageFormat class) will automatically detect your compression algorithm and offer it as an option.