MeVisLab Toolbox Reference
ml::ReleaseToolsMisc Namespace Reference

A collection of miscellaneous tool functions. More...

Enumerations

enum  MonotonicTypes {
  Empty = 1 , Singular = 2 , Irregular = 4 , Uniform = 8 ,
  StrictlyMonotonicDecreasing = 16 , MonotonicDecreasing = 32 , MonotonicIncreasing = 64 , StrictlyMonotonicIncreasing = 128
}
 An enumerator describing whether elements of a vector have a monotonic order. More...
 

Functions

MLRELEASE_TOOLS_EXPORT ReleaseToolsIO::StringVector split (const std::string &value, const std::string &sep=LineSeparator)
 Subdivides value at all positions of sep and returns all values in the vector. More...
 
MLRELEASE_TOOLS_EXPORT ReleaseToolsIO::StringVector filterWithRegExVector (const ReleaseToolsIO::StringVector &strVec, const ReleaseToolsIO::StringVector &regExpressionsVec, std::vector< size_t > *matchedRegExIdxVec=nullptr)
 Filter list of strings in strVec by regular expressions in regExpressionsVec and return list of matching strings. More...
 
MLRELEASE_TOOLS_EXPORT ReleaseToolsIO::StringVector filterWithRegExVector (const ReleaseToolsIO::StringVector &strVec, const std::string &regEx)
 Convenience version of filterWithRegExVector(strVec, regExpressionsVec, matchedRegExIdxVec) where regExpressionsVec is constructed with one entry built from regEx. More...
 
MLRELEASE_TOOLS_EXPORT std::string filterLinesWithRegEx (const std::string &str, const std::string &regEx, const std::string &sep=LineSeparator)
 Decompose str into lines with split(str, sep), filter them with filterWithRegExVector(strLines, regEx) and return a string composed of all matching lines. More...
 
MLRELEASE_TOOLS_EXPORT ReleaseToolsIO::StringVector filterLines (const ReleaseToolsIO::StringVector &inLines, const bool useRegularExpression, const std::string &firstExpression, const std::string &lineEnd, const MLint index, std::string *errorInfos=nullptr)
 Searches lines in inLines which match given strings/expression to extract string value(s). More...
 
MLRELEASE_TOOLS_EXPORT MLErrorCode copyBitSubImagesToUInt8SubImage (SubImage &outSubImage, const std::vector< SubImage > &frameSubImgs, MLint zTranslate=0, MLuint8 value=1, bool orValue=false)
 Decompose packed bit data from packed single pixel data in frameSubImgs to a normal MLuint8Type'd subimage. More...
 
MLRELEASE_TOOLS_EXPORT bool isEquidistant (const std::vector< double > &dblVec, double eps=10e-5)
 Returns true if the number of elements in dblVec is <= 1 or if each dblVec[i]-dblVec[i-1] equals dblVec[1]-dblVec[0] (comparisons are made with the given eps). More...
 
MLRELEASE_TOOLS_EXPORT int getMonotonicProperties (const std::vector< double > &dblVec, double eps=10e-5)
 Returns a bit mask contains bits defined in MonotonicTypes which describe properties of the elements in dblVec; comparisons are performed with the precision given by eps. More...
 
MLRELEASE_TOOLS_EXPORT MLErrorCode calculateAverageOfSumOfSquaredDifferences (const SubImage &subImg1, const SubImage &subImg2, double &avrOfSumOfSquaredDiffs)
 Determines the average of pixel-wise sum of squared differences between the overlapping regions of subImage1 and subImage2. More...
 
template<typename DT1 , typename DT2 >
double calculateAverageOfSumOfSquaredDifferences (TSubImage< DT1 > &img1, TSubImage< DT2 > &img2, SubImageBox box)
 Compares the average of the sum of squared differences over all voxels in the given box in corresponding and overlapping regions in subimg1 and subimg2. More...
 
MLRELEASE_TOOLS_EXPORT std::string toBase64 (const std::string &inString)
 Converts inString including the terminating null character to a Base64 coded string, thus even an empty string always results to a non-empty coded and returned string. More...
 
MLRELEASE_TOOLS_EXPORT std::string fromBase64 (const std::string &inString)
 Converts inString from a Base64 coded string to a decoded original string, assuming that the string has been encoded with toBase64. More...
 
MLRELEASE_TOOLS_EXPORT std::string createHashFromBytes (const unsigned char *data, size_t numBytes, const std::string &hashAlgorithm="SHA1")
 Creates a hash string for the numBytes bytes data pointed to by data; nullptr data and numBytes == 0 are also allowed as arguments; 0-chars in data are also included in hash calculation and are not regarded as terminators. More...
 

Variables

MLRELEASE_TOOLS_EXPORT const std::string LineSeparator
 The default line separator used for line endings. More...
 

Detailed Description

A collection of miscellaneous tool functions.

Enumeration Type Documentation

◆ MonotonicTypes

An enumerator describing whether elements of a vector have a monotonic order.

Enumerator
Empty 

v.size() == 0

Singular 

v.size() == 1

Irregular 

Nothing else: not empty, not singular, not uniform, and not monotonic.

Uniform 

All elements are within an epsilon sized interval.

StrictlyMonotonicDecreasing 

v[0] > v[1] > ... > v[N-1], N = v.size(), N > 1

MonotonicDecreasing 

v[0] >= v[1] >= ... >= v[N-1], N = v.size(), N > 1

MonotonicIncreasing 

v[0] <= v[1] <= ... <= v[N-1], N = v.size(), N > 1

StrictlyMonotonicIncreasing 

v[0] < v[1] < ... < v[N-1], N = v.size(), N > 1

Definition at line 151 of file mlReleaseToolsMisc.h.

Function Documentation

◆ calculateAverageOfSumOfSquaredDifferences() [1/2]

MLRELEASE_TOOLS_EXPORT MLErrorCode ml::ReleaseToolsMisc::calculateAverageOfSumOfSquaredDifferences ( const SubImage subImg1,
const SubImage subImg2,
double &  avrOfSumOfSquaredDiffs 
)

Determines the average of pixel-wise sum of squared differences between the overlapping regions of subImage1 and subImage2.

Overlapping regions of subImage1 and subImage2 must be non-empty(), both must have same and scalar voxel types.

Parameters
subImg1The first subImage for which the difference shall be calculated.
subImg2The second subImage for which the difference shall be calculated.
avrOfSumOfSquaredDiffsReturns -1 is case of failure or non-overlapping regions otherwise the average >= 0 of the sum of squared differences between voxels in overlapping region.
Returns
ML_RESULT_OK if subimages have valid data, same data type, and overlapping regions, otherwise an another error code describing the problem.

◆ calculateAverageOfSumOfSquaredDifferences() [2/2]

template<typename DT1 , typename DT2 >
double ml::ReleaseToolsMisc::calculateAverageOfSumOfSquaredDifferences ( TSubImage< DT1 > &  img1,
TSubImage< DT2 > &  img2,
SubImageBox  box 
)
inline

◆ copyBitSubImagesToUInt8SubImage()

MLRELEASE_TOOLS_EXPORT MLErrorCode ml::ReleaseToolsMisc::copyBitSubImagesToUInt8SubImage ( SubImage outSubImage,
const std::vector< SubImage > &  frameSubImgs,
MLint  zTranslate = 0,
MLuint8  value = 1,
bool  orValue = false 
)

Decompose packed bit data from packed single pixel data in frameSubImgs to a normal MLuint8Type'd subimage.


Note that the data allocations of the input frameSubImgs don't need to be valid input subimages regarding the data size, because their data is expected to be packed bit pixel data which is not supported by other ML functionality.

Parameters
outSubImageThe SubImage to be filled with unpacked single bit mask information; its voxel type shall be MLuint8Type and data must already be allocated according to its box and data type description.
frameSubImgsA vector of subimages containing one or multiple data frames from the DICOM pixel data. In this case the data is expected to have at least (rounded up to next byte position) 1/8th of the normal size of an MLuint8 typed subimage. The data is considered a packed bit image where a voxel is a single bit, and with lsb = lowest x-position, msb = highest bit position. All frame subimages shall be of MLuint8Type and their overlapping region must have at least the x/y extent of the destination outSubImage. From each frameSubImg only the box.v1.z position is read independent of its real z-extent.
zTranslateAn offset added to the z-position of a voxel in outSubImage to determine the index into frameSubImgs for the source subimage. For example if zTranslate is 3 then a voxel at z-Position 8 in outSubImage is read from frameSubImgs[11]. Default is 0.
valueThe value to be set or ORed to the voxel of the output subimage.
orValueIf true the the value is ORed to the output subimage otherwise it will be set.
Returns
ML_RESULT_OK on success or an ML error code describing the problem.

◆ createHashFromBytes()

MLRELEASE_TOOLS_EXPORT std::string ml::ReleaseToolsMisc::createHashFromBytes ( const unsigned char *  data,
size_t  numBytes,
const std::string &  hashAlgorithm = "SHA1" 
)

Creates a hash string for the numBytes bytes data pointed to by data; nullptr data and numBytes == 0 are also allowed as arguments; 0-chars in data are also included in hash calculation and are not regarded as terminators.

Parameters
databuffer of any unsigned char values which must contain at least numBytes accessible characters.
numBytesnumber of accessible characters in data.
hashAlgorithmallowed values are only "SHA1", "SHA256", and "SHA512", all others will return an empty result string.
Returns
a 20 byte long string in case of SHA1, a 32 byte string in case of SHA256, or 64 on SHA512, respectively, an empty string in case of error.

◆ filterLines()

MLRELEASE_TOOLS_EXPORT ReleaseToolsIO::StringVector ml::ReleaseToolsMisc::filterLines ( const ReleaseToolsIO::StringVector inLines,
const bool  useRegularExpression,
const std::string &  firstExpression,
const std::string &  lineEnd,
const MLint  index,
std::string *  errorInfos = nullptr 
)

Searches lines in inLines which match given strings/expression to extract string value(s).

Parameters
inLinesThe set of lines to be filtered.
useRegularExpressionIf true then firstExpression is used as regular expression to match lines and to extract values; if false then the value between firstExpression and lineEnd is extracted matched.
firstExpressionIf useRegularExpression is false then this must exactly match the line start before the value; otherwise if will be used as regular expression to determine match results.
lineEndIf useRegularExpression is false then this must exactly the end of the line after the value, otherwise it is ignored.
index0 returns the result from the first matching line, -1 the last one, or any other inside of found values; if it is larger than the number of matching lines then the return vector will be empty.
errorInfosIf errorInfos is not nullptr then errors such as failing regular expression evaluations will return an error description in *errorInfos or it will be set to "" on success. If this pointer is nullptr then errors will be reported with ML_PRINT_ERROR.
Returns
Empty if
  • no line was matching,
  • index is out of range of number of matching lines,
  • both, firstExpression and lineEnd are empty,
  • or useRegularExpression is true and firstExpression is empty. Otherwise it contains the number of matching values from the regular expression if useRegularExpression is true, otherwise it will contain the selected matching line and the value found between firstExpression and lineEnd in the selected matched line.

◆ filterLinesWithRegEx()

MLRELEASE_TOOLS_EXPORT std::string ml::ReleaseToolsMisc::filterLinesWithRegEx ( const std::string &  str,
const std::string &  regEx,
const std::string &  sep = LineSeparator 
)

Decompose str into lines with split(str, sep), filter them with filterWithRegExVector(strLines, regEx) and return a string composed of all matching lines.

◆ filterWithRegExVector() [1/2]

MLRELEASE_TOOLS_EXPORT ReleaseToolsIO::StringVector ml::ReleaseToolsMisc::filterWithRegExVector ( const ReleaseToolsIO::StringVector strVec,
const ReleaseToolsIO::StringVector regExpressionsVec,
std::vector< size_t > *  matchedRegExIdxVec = nullptr 
)

Filter list of strings in strVec by regular expressions in regExpressionsVec and return list of matching strings.

Parameters
strVecList of strings to be filtered.
regExpressionsVecA container with strings containing regular expressions; empty strings and strings starting with # are ignored; all others are considered as regular expressions. If a string starts with a "!" the expression result of the rest of the string is negated. The used expression parser is boost::regex::extended; expressions causing boost exceptions will be ignored and will not lead to a match even if they carry a leading "!".
matchedRegExIdxVecIf passed non nullptr then for each returned element in the returned vector the index to the matching regular expression is returned. On no matches the vector is returned empty.
Returns
The list of strings which match any of the passed regular expressions.

◆ filterWithRegExVector() [2/2]

MLRELEASE_TOOLS_EXPORT ReleaseToolsIO::StringVector ml::ReleaseToolsMisc::filterWithRegExVector ( const ReleaseToolsIO::StringVector strVec,
const std::string &  regEx 
)

Convenience version of filterWithRegExVector(strVec, regExpressionsVec, matchedRegExIdxVec) where regExpressionsVec is constructed with one entry built from regEx.

◆ fromBase64()

MLRELEASE_TOOLS_EXPORT std::string ml::ReleaseToolsMisc::fromBase64 ( const std::string &  inString)

Converts inString from a Base64 coded string to a decoded original string, assuming that the string has been encoded with toBase64.

◆ getMonotonicProperties()

MLRELEASE_TOOLS_EXPORT int ml::ReleaseToolsMisc::getMonotonicProperties ( const std::vector< double > &  dblVec,
double  eps = 10e-5 
)

Returns a bit mask contains bits defined in MonotonicTypes which describe properties of the elements in dblVec; comparisons are performed with the precision given by eps.

◆ isEquidistant()

MLRELEASE_TOOLS_EXPORT bool ml::ReleaseToolsMisc::isEquidistant ( const std::vector< double > &  dblVec,
double  eps = 10e-5 
)

Returns true if the number of elements in dblVec is <= 1 or if each dblVec[i]-dblVec[i-1] equals dblVec[1]-dblVec[0] (comparisons are made with the given eps).

◆ split()

MLRELEASE_TOOLS_EXPORT ReleaseToolsIO::StringVector ml::ReleaseToolsMisc::split ( const std::string &  value,
const std::string &  sep = LineSeparator 
)

Subdivides value at all positions of sep and returns all values in the vector.

Parameters
valueThe string to be subdivided.
sepThe character sequence used to separate string segments.
Returns
The vector of sep-separated lines; if sep is empty value is returned in a vector of one elements.

◆ toBase64()

MLRELEASE_TOOLS_EXPORT std::string ml::ReleaseToolsMisc::toBase64 ( const std::string &  inString)

Converts inString including the terminating null character to a Base64 coded string, thus even an empty string always results to a non-empty coded and returned string.

Variable Documentation

◆ LineSeparator

MLRELEASE_TOOLS_EXPORT const std::string ml::ReleaseToolsMisc::LineSeparator
extern

The default line separator used for line endings.