MeVisLab Toolbox Reference
|
A collection of static IO tool functions. More...
Typedefs | |
typedef std::vector< std::string > | StringVector |
Define often used string vector types. | |
typedef std::vector< StringVector > | StringVectorVector |
Functions | |
MLRELEASE_TOOLS_EXPORT bool | calculateDirectoryMatching (const std::string &srcDirBasePath, const std::string &dstDirBasePath, const StringVector &suppressedItems, const bool applyAmbiguityHeuristics, ProgressLogger *logger, StringVector &srcFiles, StringVector &srcDirs, StringVector &dstFiles, StringVector &dstDirs, StringVector &directlyMovedFilesVec, StringVector &directlyMovedDirsVec, StringVector matchingFileVec[2], StringVector &ambiguousMatchingFileVecSrc, StringVectorVector &ambiguousMatchingFilesVec, StringVector &nonMatchingFileVec, StringVector matchingDirVec[2], StringVector &nonMatchingDirVec, StringVector &ambiguousMatchingDirVecSrc, StringVectorVector &ambiguousMatchingDirsVec, StringVector &newDstFiles, StringVector &newDstDirs) |
This function implements a heuristic to find a good matching from files and directories under srcDirBasePath to files and directories under dstDirBasePath. | |
MLRELEASE_TOOLS_EXPORT bool | isDICOMTiffPair (const std::string &oneFile, std::string *otherFile=nullptr, std::string *dcmFile=nullptr, std::string *tiffFile=nullptr) |
Returns true if oneFile is one of two files of a DICOM/Tiff pair, otherwise false. | |
MLRELEASE_TOOLS_EXPORT bool | hasMLImageSuffix (const std::string &filePathWithName) ML_RETURN_VALUE_SHOULD_BE_USED |
Returns true if the if filePathWithName ends with a string compatible with the .mlimage file format, otherwise false. | |
MLRELEASE_TOOLS_EXPORT bool | isFileOrSuffixInList (const std::string &fileNamePath, const std::vector< std::string > sufList) ML_RETURN_VALUE_SHOULD_BE_USED |
Returns true if fileNamePath ends with a string in sufList which has a leading dot, or if it is the same with an entry without leading dot. | |
MLRELEASE_TOOLS_EXPORT std::string | searchFileTypeInBinaryHeader (const std::string &fullFilePath) ML_RETURN_VALUE_SHOULD_BE_USED |
If a known one is found then it returns the suffix corresponding to the format, otherwise an empty string is returned. | |
MLRELEASE_TOOLS_EXPORT std::string | buildRelativePath (bool useRelativePaths, const std::string &fileRootDirPath, const std::string &fNamePath, bool allowBranchedSubDirs=false, bool allowMultiFrameHandles=false) ML_RETURN_VALUE_SHOULD_BE_USED |
Helper function to make a path relative if it matches a passed parent path. | |
MLRELEASE_TOOLS_EXPORT std::string | removeRedundantPathComponents (const std::string &pathAndFileNameStr) ML_RETURN_VALUE_SHOULD_BE_USED |
Removes ".."/ components from pathAndFileNameStr's such as "abc/xyz/../def" by reducing it to "abc/def" if possible. | |
MLRELEASE_TOOLS_EXPORT void | removeRedundantPathComponents (const std::string &pathToSimplify, std::string &simplifiedPath) |
Same as removeRedundantPathComponents(const std::string &pathAndFileNameStr) but returning value in simplifiedPath. | |
MLRELEASE_TOOLS_EXPORT void | removeRedundantPathComponentsInPlace (std::string &pathToSimplify) |
Same as removeRedundantPathComponents(const std::string &pathAndFileNameStr) but passing input into into and getting out result in pathToSimplifysimplifiedPath. | |
MLRELEASE_TOOLS_EXPORT std::string | buildAbsolutePath (bool allowMakeAbsolute, const std::string &fileRootDirPath, const std::string &relativeFileNameStr, bool simplifyPaths=false, bool allowMultiFrameHandles=false) ML_RETURN_VALUE_SHOULD_BE_USED |
Helper function to make a relative path name absolute under some circumstances. | |
MLRELEASE_TOOLS_EXPORT void | buildAbsolutePath (bool allowMakeAbsolute, const std::string fileRootDirPath, const std::string &relativeFileNameStrIn, bool simplifyPaths, bool allowMultiFrameHandles, std::string &relPathFileName) |
Same as std::string buildAbsolutePath(...) but returning result in relPathFileName. | |
MLRELEASE_TOOLS_EXPORT std::string | appendSingleSlash (const std::string &srcStr) ML_RETURN_VALUE_SHOULD_BE_USED |
Appends a single forward slash to srcStr if it still does not end with one, however, in case of empty strings nothing is appended. | |
MLRELEASE_TOOLS_EXPORT std::vector< std::string > | splitFilePath (const std::string &pathLikeString) ML_RETURN_VALUE_SHOULD_BE_USED |
Splits a (path) string into its components. | |
MLRELEASE_TOOLS_EXPORT void | splitFilePath (const std::string &pathLikeString, std::vector< std::string > &retPath) |
Same as splitFilePath(const std::string &pathLikeString), only returning the result in retVal;. | |
MLRELEASE_TOOLS_EXPORT void | splitPathAndName (std::string fullPathAndName, std::string &fPath, std::string &fName) |
Splits the full path with file fullPathAndName into two components, the base path and the fileName at its end (redundant path components are removed). | |
MLRELEASE_TOOLS_EXPORT std::string | substituteNonPathLikeChars (std::string strToCorrect) ML_RETURN_VALUE_SHOULD_BE_USED |
Small helper function to replace some characters not suitable for paths by '-' or '. | |
MLRELEASE_TOOLS_EXPORT MLErrorCode | loadStringFile (const std::string &strFileName, std::string &readString) ML_RETURN_VALUE_SHOULD_BE_USED |
Load a binary file into readString and return ML_RESULT_OK on success, ML_FILE_IO_ERROR on other file IO errors or ML_NO_MEMORY on allocation failures. | |
MLRELEASE_TOOLS_EXPORT MLErrorCode | reformatColorChannels (const std::vector< SubImage > &frameSubImgs, MLint frameOffset, SubImage &outSubImg, size_t dimIdx, bool isInterleaved, MLint timeUnrollSteps) ML_RETURN_VALUE_SHOULD_BE_USED |
Helper function to copy data from frameSubImages into outSubImg into the dimension given by dimIdx. | |
MLRELEASE_TOOLS_EXPORT bool | scanDirectoriesForFiles (ProgressLogger *progressLogger, const std::string &sourceDir, const std::vector< std::string > *suppressedFilesAndSuffixes, bool recursively, std::vector< std::string > &resultFileVector, std::vector< std::string > *resultDirVector=nullptr, bool returnRelativePaths=false, bool alsoSuppressDirectories=false, bool warnNoSourceSourceDir=false, float progressMinimum=0.0, float progressMaximum=1.0, std::vector< std::string > *checkForFileExtensions=nullptr, bool *checkForFileExtensionsFound=nullptr) |
Searches files and directories optionally recursively in sourceDir; if suppressedFilesAndSuffixes is passed non-nullptr then files and/or directories can be suppressed if they match or terminate with any of the elements. | |
MLRELEASE_TOOLS_EXPORT MLErrorCode | deleteListOfFiles (std::list< std::string > *fileNameList, ProgressLogger *progressLogger=nullptr) |
Tool function that deletes files for a given list of filenames. | |
A collection of static IO tool functions.
typedef std::vector< std::string > ml::ReleaseToolsIO::StringVector |
Define often used string vector types.
Definition at line 27 of file mlDirectoryMatching.h.
typedef std::vector< StringVector > ml::ReleaseToolsIO::StringVectorVector |
Definition at line 28 of file mlDirectoryMatching.h.
MLRELEASE_TOOLS_EXPORT std::string ml::ReleaseToolsIO::appendSingleSlash | ( | const std::string & | srcStr | ) |
Appends a single forward slash to srcStr if it still does not end with one, however, in case of empty strings nothing is appended.
If multiple forward or backward slashes are at the end of the string they are removed until only one forward slash remains.
MLRELEASE_TOOLS_EXPORT std::string ml::ReleaseToolsIO::buildAbsolutePath | ( | bool | allowMakeAbsolute, |
const std::string & | fileRootDirPath, | ||
const std::string & | relativeFileNameStr, | ||
bool | simplifyPaths = false, | ||
bool | allowMultiFrameHandles = false ) |
Helper function to make a relative path name absolute under some circumstances.
allowMakeAbsolute | If false then always relativeFileNameStr is returned, if true then it is tried to return an absolute path. The absolute path is created by replacing the "./" which is expected at the begin of relativeFileNameStr; if that is not possible or "./" is not at begin then relativeFileNameStr is returned unchanged. |
fileRootDirPath | Path to be pasted at begin of relativeFileNameStr instead of "./" if "./" it is found and allowMakeAbsolute is true. |
relativeFileNameStr | The path to be made absolute. |
simplifyPaths | If false (the default) then composed paths do not simplify "./xyz/../abc" patch components to "./abc"; otherwise this simplifications are performed. |
allowMultiFrameHandles | Also handle multi-frame handles in relativeFileNameStr which have an asterisk in their first character. |
MLRELEASE_TOOLS_EXPORT void ml::ReleaseToolsIO::buildAbsolutePath | ( | bool | allowMakeAbsolute, |
const std::string | fileRootDirPath, | ||
const std::string & | relativeFileNameStrIn, | ||
bool | simplifyPaths, | ||
bool | allowMultiFrameHandles, | ||
std::string & | relPathFileName ) |
Same as std::string buildAbsolutePath(...) but returning result in relPathFileName.
MLRELEASE_TOOLS_EXPORT std::string ml::ReleaseToolsIO::buildRelativePath | ( | bool | useRelativePaths, |
const std::string & | fileRootDirPath, | ||
const std::string & | fNamePath, | ||
bool | allowBranchedSubDirs = false, | ||
bool | allowMultiFrameHandles = false ) |
Helper function to make a path relative if it matches a passed parent path.
useRelativePaths | If false then always fNameStr is returned, if true then it is tried to return a relative path. The relative path is created by replacing fileRootDirPath at the begin of fNameStr; if that is not possible then fNameStr is returned unchanged. |
fileRootDirPath | Path to be searched at begin of fNameStr and to replace by "." if it is found and if useRelativePaths is true. If path already ends with "/" then it is replaced by "./" to assure that the path remains valid. Should be a directory path. |
fNamePath | The path and file name to be made relative. Must be a path to a file name or to be more precise: Not to a directory. |
allowBranchedSubDirs | If the flag is true then buildRelativePath tries to determine all identical parts of the fileRootDirPath and fNamePath and to append multiple ".." and "subDir" components to build a relative path, otherwise (the default) fileRootDirPath must be an exact starting part of fNamePath. |
allowMultiFrameHandles | Also handle multi-frame handles in fNamePath which have an asterisk in their first character. |
References buildRelativePath().
Referenced by buildRelativePath().
MLRELEASE_TOOLS_EXPORT bool ml::ReleaseToolsIO::calculateDirectoryMatching | ( | const std::string & | srcDirBasePath, |
const std::string & | dstDirBasePath, | ||
const StringVector & | suppressedItems, | ||
const bool | applyAmbiguityHeuristics, | ||
ProgressLogger * | logger, | ||
StringVector & | srcFiles, | ||
StringVector & | srcDirs, | ||
StringVector & | dstFiles, | ||
StringVector & | dstDirs, | ||
StringVector & | directlyMovedFilesVec, | ||
StringVector & | directlyMovedDirsVec, | ||
StringVector | matchingFileVec[2], | ||
StringVector & | ambiguousMatchingFileVecSrc, | ||
StringVectorVector & | ambiguousMatchingFilesVec, | ||
StringVector & | nonMatchingFileVec, | ||
StringVector | matchingDirVec[2], | ||
StringVector & | nonMatchingDirVec, | ||
StringVector & | ambiguousMatchingDirVecSrc, | ||
StringVectorVector & | ambiguousMatchingDirsVec, | ||
StringVector & | newDstFiles, | ||
StringVector & | newDstDirs ) |
This function implements a heuristic to find a good matching from files and directories under srcDirBasePath to files and directories under dstDirBasePath.
Input parameters:
srcDirBasePath | All files and directories under this directory which are not suppressed by suppressedItems are analyzed and the matching to corresponding ones under dstDirBasePath is searched. |
dstDirBasePath | All files and directories under this directory which are not suppressed by suppressedItems are analyzed for possible matches from corresponding ones found under srcDirBasePath. |
suppressedItems | A list of file names and suffixes (starting with ".") which is skipping matching files found under srcDirBasePath and dstDirBasePath. |
applyAmbiguityHeuristics | If true then a more detailed heuristic is applied to files under srcDirBasePath for which more than one same named version under dstDirBasePath is found. |
logger | A pointer to a progress logger which is fed with status information used for interrupt checking if non nullptr. If nullptr then it is ignored. |
Result parameters:
srcFiles | Returns the list of files found under srcDirBasePath. |
srcDirs | Returns the list of directories found under srcDirBasePath. |
dstFiles | Returns the list of files found under dstDirBasePath. |
dstDirs | Returns the list of directories found under dstDirBasePath. |
directlyMovedFilesVec | Returns the list of files which have the same relative path under srcDirBasePath and dstDirBasePath. |
directlyMovedDirsVec | Returns the list of directories which have the same relative path under srcDirBasePath and dstDirBasePath. |
matchingFileVec | Returns the list of files under srcDirBasePath which have exactly one same named file under dstDirBasePath but with different relative path. Element[0] then contains the source path, element[1] the destination path, both are returned with same size. |
ambiguousMatchingFileVecSrc | List of files under srcDirBasePath which have more than one same named one under dstDirBasePath for which no clear assignment could be determined in ambiguity analysis. |
ambiguousMatchingFilesVec | Vector with same size than ambiguousMatchingFileVecSrc containing a vector of paths for each entry of ambiguousMatchingFileVecSrc which contain the ambiguous matching files under dstDirBasePath. |
nonMatchingFileVec | List of files under srcDirBasePath for which no same named one could be found under dstDirBasePath. |
matchingDirVec | Returns the list of directories under srcDirBasePath which have exactly one same named file under dstDirBasePath but with different relative path. Element[0] contains the source path, element[1] the destination path, both are returned with same size. |
nonMatchingDirVec | List of directories under srcDirBasePath for which no same named one could be found under dstDirBasePath. |
ambiguousMatchingDirVecSrc | List of directories under srcDirBasePath which have more than one same named one under dstDirBasePath for which no clear assignment could be determined in ambiguity analysis. |
ambiguousMatchingDirsVec | Vector with same size than ambiguousMatchingDirVecSrc containing a vector of paths for each entry of ambiguousMatchingDirVecSrc which contain the ambiguous matching directories under dstDirBasePath. |
newDstFiles | List of files under dstDirBasePath which have no same named version under srcDirBasePath or where dstDirBasePath contains more/ambiguous ones for one under srcDirBasePath. |
newDstDirs | List of directories under dstDirBasePath which have no same named version under srcDirBasePath or where dstDirBasePath contains more/ambiguous ones for one under srcDirBasePath. |
References calculateDirectoryMatching().
Referenced by calculateDirectoryMatching().
MLRELEASE_TOOLS_EXPORT MLErrorCode ml::ReleaseToolsIO::deleteListOfFiles | ( | std::list< std::string > * | fileNameList, |
ProgressLogger * | progressLogger = nullptr ) |
Tool function that deletes files for a given list of filenames.
fileNameList | the list file names to be deleted |
progressLogger | If non nullptr then message are sent to this logger, otherwise it is ignored and messages are not logged. |
MLRELEASE_TOOLS_EXPORT bool ml::ReleaseToolsIO::hasMLImageSuffix | ( | const std::string & | filePathWithName | ) |
Returns true if the if filePathWithName ends with a string compatible with the .mlimage file format, otherwise false.
References hasMLImageSuffix().
Referenced by hasMLImageSuffix().
MLRELEASE_TOOLS_EXPORT bool ml::ReleaseToolsIO::isDICOMTiffPair | ( | const std::string & | oneFile, |
std::string * | otherFile = nullptr, | ||
std::string * | dcmFile = nullptr, | ||
std::string * | tiffFile = nullptr ) |
Returns true if oneFile is one of two files of a DICOM/Tiff pair, otherwise false.
If true is returned then also otherFileName is set to the name of the other file of the file pair, otherwise it is set to an empty string. If true is returned then also *dcmFile and *tiffFile are set to the DICOM and Tiff file pair components, respectively. If any of otherFile, dcmFile, or tiffFile is passed as nullptr it will be ignored. Beware, on Windows this check is VERY expensive because it checks for multiple non-existing files.
References isDICOMTiffPair().
Referenced by isDICOMTiffPair().
MLRELEASE_TOOLS_EXPORT bool ml::ReleaseToolsIO::isFileOrSuffixInList | ( | const std::string & | fileNamePath, |
const std::vector< std::string > | sufList ) |
Returns true if fileNamePath ends with a string in sufList which has a leading dot, or if it is the same with an entry without leading dot.
Otherwise is returns false. The comparison is case insensitive (lower and upper cases are considered identical).
References isFileOrSuffixInList().
Referenced by isFileOrSuffixInList().
MLRELEASE_TOOLS_EXPORT MLErrorCode ml::ReleaseToolsIO::loadStringFile | ( | const std::string & | strFileName, |
std::string & | readString ) |
Load a binary file into readString and return ML_RESULT_OK on success, ML_FILE_IO_ERROR on other file IO errors or ML_NO_MEMORY on allocation failures.
On empty but existing files ML_RESULT_OK is returned and readString will be empty. Although the entire file is read, it will only be assigned to the returned string up to the first null-terminating character (which is appended to the end if it is no part of the file).
MLRELEASE_TOOLS_EXPORT MLErrorCode ml::ReleaseToolsIO::reformatColorChannels | ( | const std::vector< SubImage > & | frameSubImgs, |
MLint | frameOffset, | ||
SubImage & | outSubImg, | ||
size_t | dimIdx, | ||
bool | isInterleaved, | ||
MLint | timeUnrollSteps ) |
Helper function to copy data from frameSubImages into outSubImg into the dimension given by dimIdx.
Important: Source and destination subimages must have same data types and must be of integer type, only one special case is supported: outSubImg data type is a standard and integer type and frameSubImgs are of Vector3f type which then is interpreted as interleaved color data (isInterleaved must also be true then). Important: All frameSubImgs must have the same data type.
frameSubImgs | Is a vector with as many frames as the extent of outSubImage in the dimension given by dimIdx. |
frameOffset | Value to be subtracted from a frame index into frameSubImgs; usually needed to load a frame from frameSubImgs[0] which is not positioned at z==0. |
outSubImg | The data buffer to be filled with data from frameSubImgs. It must have an extent in dimension dimIdx as frameSubImgs.size(). |
dimIdx | Is the dimension into which the frames are copied. |
isInterleaved | If true then the data in frameSubmÍmgs is ordered in RGBRGB...RGB format, otherwise in format RRR...GGG...BBB. |
timeUnrollSteps | If frames are spread over z and time dimensions then for each time point we have to jump timeUnrollSteps forward to get the right frame for the corresponding time point. In normal cases where frames are spread over only one dimension this should be 0. |
MLRELEASE_TOOLS_EXPORT std::string ml::ReleaseToolsIO::removeRedundantPathComponents | ( | const std::string & | pathAndFileNameStr | ) |
Removes ".."/ components from pathAndFileNameStr's such as "abc/xyz/../def" by reducing it to "abc/def" if possible.
pathAndFileNameStr | The path to be cleaned up. |
MLRELEASE_TOOLS_EXPORT void ml::ReleaseToolsIO::removeRedundantPathComponents | ( | const std::string & | pathToSimplify, |
std::string & | simplifiedPath ) |
Same as removeRedundantPathComponents(const std::string &pathAndFileNameStr) but returning value in simplifiedPath.
MLRELEASE_TOOLS_EXPORT void ml::ReleaseToolsIO::removeRedundantPathComponentsInPlace | ( | std::string & | pathToSimplify | ) |
Same as removeRedundantPathComponents(const std::string &pathAndFileNameStr) but passing input into into and getting out result in pathToSimplifysimplifiedPath.
MLRELEASE_TOOLS_EXPORT bool ml::ReleaseToolsIO::scanDirectoriesForFiles | ( | ProgressLogger * | progressLogger, |
const std::string & | sourceDir, | ||
const std::vector< std::string > * | suppressedFilesAndSuffixes, | ||
bool | recursively, | ||
std::vector< std::string > & | resultFileVector, | ||
std::vector< std::string > * | resultDirVector = nullptr, | ||
bool | returnRelativePaths = false, | ||
bool | alsoSuppressDirectories = false, | ||
bool | warnNoSourceSourceDir = false, | ||
float | progressMinimum = 0.0, | ||
float | progressMaximum = 1.0, | ||
std::vector< std::string > * | checkForFileExtensions = nullptr, | ||
bool * | checkForFileExtensionsFound = nullptr ) |
Searches files and directories optionally recursively in sourceDir; if suppressedFilesAndSuffixes is passed non-nullptr then files and/or directories can be suppressed if they match or terminate with any of the elements.
progressLogger | Used for message output and progress updates, allowed to be nullptr. |
sourceDir | The directory to be scanned for files which do not have suffixes as described in suppressedFilesAndSuffixes. |
suppressedFilesAndSuffixes | If non nullptr then this array of file suffixes (such as ".tif", ".txt") describes the file types not to be added to resultFileVector. Strings not having a leading dot must match case insensitively. Files are excluded only by string matching on file names, but not by content analysis. nullptr as argument is allowed - then no suppression takes place. Note that suppressing directories is off by default; enable alsoSuppressDirectories if directory suppression is also wanted. |
recursively | If true then directories are recursively parsed; if false then only flat directory scans are performed. |
resultFileVector | The vector to which all found files are appended. |
resultDirVector | The vector to which all found directories are appended if non nullptr. Note that sourceDir itself is not inserted. |
returnRelativePaths | If false (the default) then all paths are returned as absolute paths, otherwise relative paths are returned. |
alsoSuppressDirectories | If true then also directories are suppressed by suppressedFilesAndSuffixes; if false (the default) then directories are not suppressed. |
warnNoSourceSourceDir | If true then a warning about a not existing source directory is posted to the prgressLogger (if it exists), otherwise (the default) this issue is ignored. |
progressMinimum | Start percentage for progress counting. |
progressMaximum | End percentage for progress counting. |
checkForFileExtensions | A list of optional file extensions which are checked for existence. |
checkForFileExtensionsFound | An array of bools which are filled with true/false for each checkForFileExtensions extension that is found. Note that these flags are only set to true, they need to be intialized to false by the caller. |
MLRELEASE_TOOLS_EXPORT std::string ml::ReleaseToolsIO::searchFileTypeInBinaryHeader | ( | const std::string & | fullFilePath | ) |
If a known one is found then it returns the suffix corresponding to the format, otherwise an empty string is returned.
Currently a (perhaps incomplete) check for the following file types is performed: ".mlimage", ".pgm", ".pnm", ".png", ".bmp", ".dcm", ".stl", ".tiff", ".tiff", ".jpg", ".pdf".
References searchFileTypeInBinaryHeader().
Referenced by searchFileTypeInBinaryHeader().
MLRELEASE_TOOLS_EXPORT std::vector< std::string > ml::ReleaseToolsIO::splitFilePath | ( | const std::string & | pathLikeString | ) |
Splits a (path) string into its components.
pathLikeString | A path returned by the function scanDirectoriesForFiles. |
MLRELEASE_TOOLS_EXPORT void ml::ReleaseToolsIO::splitFilePath | ( | const std::string & | pathLikeString, |
std::vector< std::string > & | retPath ) |
Same as splitFilePath(const std::string &pathLikeString), only returning the result in retVal;.
MLRELEASE_TOOLS_EXPORT void ml::ReleaseToolsIO::splitPathAndName | ( | std::string | fullPathAndName, |
std::string & | fPath, | ||
std::string & | fName ) |
Splits the full path with file fullPathAndName into two components, the base path and the fileName at its end (redundant path components are removed).
It makes use of splitFilePath and its approaches for drive and root directory handling. fPath - if not empty - will always be terminated with a forward slash, and directories - if they are no special drives or so - will always be separated by forward slashes, too.
fullPathAndName | The file path to be split. |
fPath | The result path without file name at its end. |
fName | The result file without path before. |
MLRELEASE_TOOLS_EXPORT std::string ml::ReleaseToolsIO::substituteNonPathLikeChars | ( | std::string | strToCorrect | ) |
Small helper function to replace some characters not suitable for paths by '-' or '.
' characters. It replaces '/', '\', and ' ' with '-', and '&', '$', and '"' with '.'.