Visual Servoing Platform
version 3.6.1 under development (2024-03-18)
|
#include <visp3/core/vpIoTools.h>
Static Public Member Functions | |
static const std::string & | getBuildInformation () |
static std::string | getTempPath () |
static void | getUserName (std::string &username) |
static std::string | getUserName () |
static std::string | getenv (const std::string &env) |
static std::string | getViSPImagesDataPath () |
static void | getVersion (const std::string &version, unsigned int &major, unsigned int &minor, unsigned int &patch) |
static bool | checkDirectory (const std::string &dirname) |
static bool | checkFifo (const std::string &filename) |
static bool | checkFilename (const std::string &filename) |
static bool | copy (const std::string &src, const std::string &dst) |
static void | makeDirectory (const std::string &dirname) |
static void | makeFifo (const std::string &dirname) |
static std::string | makeTempDirectory (const std::string &dirname) |
static std::string | path (const std::string &pathname) |
static bool | remove (const std::string &filename) |
static bool | rename (const std::string &oldfilename, const std::string &newfilename) |
static std::string | toUpperCase (const std::string &input) |
static std::string | toLowerCase (const std::string &input) |
static std::string | getAbsolutePathname (const std::string &pathname) |
static std::string | getFileExtension (const std::string &pathname, bool checkFile=false) |
static long | getIndex (const std::string &filename, const std::string &format) |
static std::string | getName (const std::string &pathname) |
static std::string | getNameWE (const std::string &pathname) |
static std::string | getParent (const std::string &pathname) |
static std::string | createFilePath (const std::string &parent, const std::string &child) |
static bool | isAbsolutePathname (const std::string &pathname) |
static bool | isSamePathname (const std::string &pathname1, const std::string &pathname2) |
static std::pair< std::string, std::string > | splitDrive (const std::string &pathname) |
static std::vector< std::string > | splitChain (const std::string &chain, const std::string &sep) |
static std::vector< std::string > | getDirFiles (const std::string &dirname) |
Static Public Attributes | |
static const char | separator |
Configuration file parsing | |
static std::string | baseName = "" |
static std::string | baseDir = "" |
static std::string | configFile = "" |
static std::vector< std::string > | configVars = std::vector<std::string>() |
static std::vector< std::string > | configValues = std::vector<std::string>() |
static bool | loadConfigFile (const std::string &confFile) |
static bool | readConfigVar (const std::string &var, float &value) |
static bool | readConfigVar (const std::string &var, double &value) |
static bool | readConfigVar (const std::string &var, int &value) |
static bool | readConfigVar (const std::string &var, unsigned int &value) |
static bool | readConfigVar (const std::string &var, bool &value) |
static bool | readConfigVar (const std::string &var, std::string &value) |
static bool | readConfigVar (const std::string &var, vpColor &value) |
static bool | readConfigVar (const std::string &var, vpArray2D< double > &value, const unsigned int &nCols=0, const unsigned int &nRows=0) |
static void | setBaseName (const std::string &s) |
static void | setBaseDir (const std::string &dir) |
static void | addNameElement (const std::string &strTrue, const bool &cond=true, const std::string &strFalse="") |
static void | addNameElement (const std::string &strTrue, const double &val) |
static std::string | getBaseName () |
static std::string | getFullName () |
static void | saveConfigFile (const bool &actuallySave=true) |
static void | createBaseNamePath (const bool &empty=false) |
static void | readBinaryValueLE (std::ifstream &file, int16_t &short_value) |
static void | readBinaryValueLE (std::ifstream &file, uint16_t &ushort_value) |
static void | readBinaryValueLE (std::ifstream &file, int32_t &int_value) |
static void | readBinaryValueLE (std::ifstream &file, uint32_t &int_value) |
static void | readBinaryValueLE (std::ifstream &file, float &float_value) |
static void | readBinaryValueLE (std::ifstream &file, double &double_value) |
static void | writeBinaryValueLE (std::ofstream &file, const int16_t short_value) |
static void | writeBinaryValueLE (std::ofstream &file, const uint16_t ushort_value) |
static void | writeBinaryValueLE (std::ofstream &file, const int32_t int_value) |
static void | writeBinaryValueLE (std::ofstream &file, const uint32_t int_value) |
static void | writeBinaryValueLE (std::ofstream &file, float float_value) |
static void | writeBinaryValueLE (std::ofstream &file, double double_value) |
static bool | parseBoolean (std::string input) |
static std::string | trim (std::string s) |
File and directories basic tools.
The example below shows how to manipulate the functions of this class to create first a directory which name corresponds to the user name and then create a file in this directory.
The example below shows how to read a configuration file and how to create a name for experiment files. We assume the following file "/home/user/demo/config.txt" :
Definition at line 490 of file vpIoTools.h.
|
static |
Augments the prefix of the experiment files by strTrue if cond is verified, and by strFalse otherwise.
strTrue | : String to add if cond is true |
cond | : Condition managing the file name |
strFalse | : String to add if cond is false (default "") |
Definition at line 1704 of file vpIoTools.cpp.
|
static |
Augments the prefix of the experiment files by strTrue followed by val.
strTrue | : String to add |
val | : Value to add |
Definition at line 1720 of file vpIoTools.cpp.
|
static |
Check if a directory exists.
dirname | : Directory to test if it exists. The directory name is converted to the current system's format; see path(). |
Definition at line 818 of file vpIoTools.cpp.
Referenced by copy(), createBaseNamePath(), getFileExtension(), vpSimulatorAfma6::init(), vpSimulatorViper850::init(), vpSimulatorAfma6::initArms(), vpSimulatorViper850::initArms(), makeFifo(), makeTempDirectory(), vpServoData::open(), remove(), vpRobotFranka::setLogFolder(), vpImageQueue< Type >::vpImageQueue(), and vpWireFrameSimulator::vpWireFrameSimulator().
|
static |
Check if a fifo file exists.
fifofilename | : Fifo filename to test if it exists. |
Definition at line 878 of file vpIoTools.cpp.
References vpException::notImplementedError.
Referenced by makeFifo(), and remove().
|
static |
Check if a file exists.
filename | : Filename to test if it exists. |
Definition at line 1199 of file vpIoTools.cpp.
Referenced by copy(), vpDot2::defineDots(), getFileExtension(), getViSPImagesDataPath(), vpAROgre::init(), vpRobotViper850::init(), vpMbTracker::initClick(), vpMbTracker::loadCAOModel(), vpMbTracker::loadModel(), makeFifo(), vpImageIo::read(), and remove().
|
static |
Copy a src file or directory in dst.
src | : Existing file or directory to copy. |
dst | : New copied file or directory. |
Definition at line 1241 of file vpIoTools.cpp.
References checkDirectory(), checkFilename(), vpException::fatalError, and path().
Referenced by saveConfigFile().
|
static |
Creates the directory baseDir/baseName. If already exists, empties it if empty is true. Useful to save the images corresponding to a particular experiment.
empty | : Indicates if the new directory has to be emptied |
Definition at line 1739 of file vpIoTools.cpp.
References checkDirectory(), makeDirectory(), and remove().
|
static |
Return the file path that corresponds to the concatenated parent and child string files by adding the corresponding separator for unix or windows.
The corresponding path is also converted. Under windows, all the "/" characters are converted into "\\" characters. Under Unix systems all the "\\" characters are converted into "/" characters.
Definition at line 2142 of file vpIoTools.cpp.
References path(), and separator.
Referenced by vpMbTracker::loadCAOModel(), and vpRobotKinova::loadPlugin().
|
static |
Returns the absolute path using realpath() on Unix systems or GetFullPathName() on Windows systems.
Definition at line 2100 of file vpIoTools.cpp.
References vpException::fatalError.
Referenced by isSamePathname(), and vpMbTracker::loadCAOModel().
|
static |
Gets the base name (prefix) of the experiment files.
Definition at line 641 of file vpIoTools.cpp.
|
static |
Return build informations (OS, compiler, build flags, used 3rd parties...).
Definition at line 528 of file vpIoTools.cpp.
|
static |
List of files in directory, in alphabetical order. There is no difference if pathname contains terminating backslash or not Unlike scandir(), does not return "." and ".."
pathname | : path to directory |
Definition at line 2401 of file vpIoTools.cpp.
References vpException::fatalError.
|
static |
Get the content of an environment variable.
env | : Environment variable name (HOME, LOGNAME...). |
vpIoException::cantGetenv | : If an error occur while getting the environment variable value. |
Definition at line 748 of file vpIoTools.cpp.
References vpIoException::cantGetenv.
Referenced by getViSPImagesDataPath(), vpSimulatorAfma6::init(), vpSimulatorViper850::init(), vpSimulatorAfma6::initArms(), vpSimulatorViper850::initArms(), and vpWireFrameSimulator::vpWireFrameSimulator().
|
static |
Returns the extension of the file or an empty string if the file has no extension. If checkFile flag is set, it will check first if the pathname denotes a directory and so return an empty string and second it will check if the file denoted by the pathanme exists. If so, it will return the extension if present.
pathname | : The pathname of the file we want to get the extension. |
checkFile | : If true, the file must exist otherwise an empty string will be returned. |
The following code shows how to use this function:
It produces the following output:
Definition at line 1847 of file vpIoTools.cpp.
References checkDirectory(), and checkFilename().
Referenced by vpMbGenericTracker::loadConfigFile().
|
static |
Gets the full path of the experiment files : baseDir/baseName
Definition at line 648 of file vpIoTools.cpp.
|
static |
Checks file name format and extracts its index.
Format must contain substring "%0xd", defining the length of image index. For example, format can be "img%04d.jpg". Then "img0001.jpg" and "img0000.jpg" satisfy it, while "picture001.jpg" and "img001.jpg" don't.
filename | : Name from which to extract the index. |
format | : Format of the filename. |
The following sample code shows how to use this function:
It produces the following output:
Definition at line 1991 of file vpIoTools.cpp.
|
static |
Returns the name of the file or directory denoted by this pathname.
Definition at line 1928 of file vpIoTools.cpp.
References path(), and separator.
Referenced by getNameWE(), vpMbTracker::loadCAOModel(), vpImageStorageWorker< Type >::run(), and vpVideoReader::setFileName().
|
static |
Returns the name of the file without extension or directory denoted by this pathname.
Definition at line 1950 of file vpIoTools.cpp.
References getName().
Referenced by vpImageStorageWorker< Type >::run().
|
static |
Returns the pathname string of this pathname's parent.
[in] | pathname | : Pathname from which parent name is extracted using vpIoTools::separator. When the separator is not found, it returns "." as the current parent folder. |
pathname
, or an empty string if the pathname
is empty.For example
Definition at line 2033 of file vpIoTools.cpp.
References path(), and separator.
Referenced by vpMbTracker::loadCAOModel(), vpKeyPoint::loadLearningData(), vpVideoWriter::open(), vpImageStorageWorker< Type >::run(), vpKeyPoint::saveLearningData(), and vpImageQueue< Type >::vpImageQueue().
|
static |
Return path to the default temporary folder:
GetTempPath()
/tmp/<username>
The following sample shows how to use this function to create unique temporary directories:
On Windows it produces:
Temp path: C:\Users\<username>\AppData\Local\Temp Created unique temp dir1: C:\Users\<username>\AppData\Local\Temp\ddaac8c3-7a95-447f-8a1c-fe31bb2426f9 Created unique temp dir2: C:\Users\<username>\AppData\Local\Temp\dir_8b9e6e9a-fe9b-4b44-8382-fc2368dfed68 Temp dir1 was deleted Temp dir2 was deleted
while on Unix it produces:
Temp path: /tmp/<username> Created unique temp dir1: /tmp/<username>/AMIsXF Created unique temp dir2: /tmp/<username>/dir_KP7119 Temp dir1 was deleted Temp dir2 was deleted
Definition at line 587 of file vpIoTools.cpp.
References vpIoException::cantGetenv, vpException::fatalError, getUserName(), and makeDirectory().
|
static |
Get the user name.
Definition at line 711 of file vpIoTools.cpp.
Referenced by getTempPath().
|
static |
Get the user name.
username | : The user name. When the username cannot be retrieved, set username to "unknown" string. |
Definition at line 663 of file vpIoTools.cpp.
|
static |
Extract major, minor and patch from a version given as "x.x.x". Ex: If version is "1.2.1", major will be 1, minor 2 and patch 1.
version | : String to extract the values. |
major | : Extracted major. |
minor | : Extracted minor. |
patch | : Extracted patch. |
Definition at line 775 of file vpIoTools.cpp.
|
static |
Get ViSP images data path. ViSP images data can be installed from Debian or Ubuntu visp-images-data package. It can be also installed from visp-images-3.x.y.zip that can be found on https://visp.inria.fr/download page.
This function returns the path to the folder that contains the data.
Definition at line 1781 of file vpIoTools.cpp.
References checkFilename(), and getenv().
|
static |
Return whether a path is absolute.
Definition at line 2183 of file vpIoTools.cpp.
Referenced by vpMbTracker::loadCAOModel(), and vpKeyPoint::loadLearningData().
|
static |
Return true if the two pathnames are identical.
Definition at line 2207 of file vpIoTools.cpp.
References getAbsolutePathname(), and path().
|
static |
Reads the configuration file and parses it.
confFile | : path to the file containing the configuration parameters to parse. |
Definition at line 1456 of file vpIoTools.cpp.
References vpMath::minimum().
|
static |
Create a new directory. It will create recursively the parent directories if needed.
dirname | : Directory to create. The directory name is converted to the current system's format; see path(). |
vpIoException::cantCreateDirectory | : If the directory cannot be created. |
Definition at line 967 of file vpIoTools.cpp.
References vpIoException::cantCreateDirectory, and vpIoException::invalidDirectoryName.
Referenced by createBaseNamePath(), getTempPath(), makeTempDirectory(), vpServoData::open(), vpVideoWriter::open(), vpImageQueue< Type >::record(), vpKeyPoint::saveLearningData(), and vpRobotFranka::setLogFolder().
|
static |
Create a new FIFO file. A FIFO file is a special file, similar to a pipe, but actually existing on the hard drive. It can be used to communicate data between multiple processes.
[in] | fifoname | : Pathname of the fifo file to create. |
vpIoException::invalidDirectoryName | : The dirname is invalid. |
vpIoException::cantCreateDirectory | : If the file cannot be created. |
Definition at line 1018 of file vpIoTools.cpp.
References vpIoException::cantCreateDirectory, checkDirectory(), checkFifo(), checkFilename(), and vpIoException::invalidDirectoryName.
|
static |
Create a new temporary directory with a unique name based on dirname parameter.
dirname | : Parent directory in which a temporary directory will be created or temporary directory that ends with "XXXXXX", which will be converted into random characters in order to create a unique directory name. |
vpIoException::cantCreateDirectory | : If the directory cannot be created. |
The following sample shows how to use this function to create unique temporary directories:
On Windows it produces:
Temp path: C:\Users\<username>\AppData\Local\Temp Created unique temp dir1: C:\Users\<username>\AppData\Local\Temp\ddaac8c3-7a95-447f-8a1c-fe31bb2426f9 Created unique temp dir2: C:\Users\<username>\AppData\Local\Temp\dir_8b9e6e9a-fe9b-4b44-8382-fc2368dfed68 Temp dir1 was deleted Temp dir2 was deleted
while on Unix it produces:
Temp path: /tmp/<username> Created unique temp dir1: /tmp/<username>/AMIsXF Created unique temp dir2: /tmp/<username>/dir_KP7119 Temp dir1 was deleted Temp dir2 was deleted
Definition at line 1121 of file vpIoTools.cpp.
References vpIoException::cantCreateDirectory, checkDirectory(), and makeDirectory().
|
static |
Definition at line 2624 of file vpIoTools.cpp.
Referenced by vpMbTracker::loadCAOModel().
|
static |
Converts a path name to the current system's format.
pathname | : Path name to convert. Under windows, converts all the "/" characters in the pathname string into "\\" characters. Under Unix systems converts all the "\\" characters in the pathname string into "/" characters. |
Definition at line 1416 of file vpIoTools.cpp.
Referenced by copy(), createFilePath(), getName(), getParent(), isSamePathname(), vpMbTracker::loadCAOModel(), vpImageIo::read(), and remove().
|
static |
Read a double value stored in little endian.
Definition at line 2530 of file vpIoTools.cpp.
References vpEndian::swapDouble().
|
static |
Read a float value stored in little endian.
Definition at line 2517 of file vpIoTools.cpp.
References vpEndian::swapFloat().
|
static |
Read a 16-bits integer value stored in little endian.
Definition at line 2465 of file vpIoTools.cpp.
References vpEndian::swap16bits().
Referenced by vpKeyPoint::loadLearningData().
|
static |
Read a 32-bits integer value stored in little endian.
Definition at line 2491 of file vpIoTools.cpp.
References vpEndian::swap32bits().
|
static |
Read a 16-bits unsigned integer value stored in little endian.
Definition at line 2478 of file vpIoTools.cpp.
References vpEndian::swap16bits().
|
static |
Read a 32-bits unsigned integer value stored in little endian.
Definition at line 2504 of file vpIoTools.cpp.
References vpEndian::swap32bits().
|
static |
Tries to read the parameter named var as a bool.
var | : Name of the parameter in the configuration file. |
value | : Value to be read. |
Definition at line 1602 of file vpIoTools.cpp.
|
static |
Tries to read the parameter named var as a double.
var | : Name of the parameter in the configuration file. |
value | : Value to be read. |
Definition at line 1535 of file vpIoTools.cpp.
|
static |
Tries to read the parameter named var as a float.
var | : Name of the parameter in the configuration file. |
value | : Value to be read. |
Definition at line 1507 of file vpIoTools.cpp.
|
static |
Tries to read the parameter named var as a int.
var | : Name of the parameter in the configuration file. |
value | : Value to be read. |
Definition at line 1564 of file vpIoTools.cpp.
|
static |
Tries to read the parameter named var as a std::string.
var | : Name of the parameter in the configuration file. |
value | : Value to be read. |
Definition at line 1634 of file vpIoTools.cpp.
|
static |
Tries to read the parameter named var as a unsigned int.
var | : Name of the parameter in the configuration file. |
value | : Value to be read. |
Definition at line 1586 of file vpIoTools.cpp.
|
static |
Tries to read the parameter named var as a vpMatrix. If nCols and nRows are indicated, will resize the matrix. Otherwise, will try to read as many values as indicated by the dimension of value.
var | : Name of the parameter in the configuration file. |
value | : Value to be read. |
nCols | : Column dimension if resized. |
nRows | : Row dimension if resized |
Definition at line 1661 of file vpIoTools.cpp.
References vpArray2D< Type >::getCols(), vpArray2D< Type >::getRows(), and vpArray2D< Type >::resize().
|
static |
Tries to read the parameter named var as a vpColor.
var | : Name of the parameter in the configuration file. |
value | : Value to be read. See vpColor.cpp for the color number. |
Definition at line 1618 of file vpIoTools.cpp.
References vpColor::getColor().
|
static |
Remove a file or a directory.
file_or_dir | : File name or directory to remove. |
Definition at line 1334 of file vpIoTools.cpp.
References checkDirectory(), checkFifo(), checkFilename(), vpException::fatalError, and path().
Referenced by createBaseNamePath().
|
static |
Rename an existing file oldfilename in newfilename.
oldfilename | : File to rename. |
newfilename | : New file name. |
Definition at line 1398 of file vpIoTools.cpp.
|
static |
Copy the initial configuration file to the experiment directory.
actuallySave | : If false, do not copy the file. |
Definition at line 1759 of file vpIoTools.cpp.
References copy().
|
static |
Sets the base directory of the experiment files.
dir | : Directory where the data will be saved. |
Definition at line 634 of file vpIoTools.cpp.
|
static |
Sets the base name (prefix) of the experiment files.
s | : Prefix of the experiment files. |
Definition at line 627 of file vpIoTools.cpp.
|
static |
Split a chain.
chain | : Input chain to split. |
sep | : Character separator. |
The following code shows how to use this function:
It produces the following output:
Definition at line 2372 of file vpIoTools.cpp.
Referenced by vpDisplayOpenCV::getScreenSize(), vpSimulatorAfma6::init(), vpSimulatorViper850::init(), vpAROgre::init(), vpSimulatorAfma6::initArms(), vpSimulatorViper850::initArms(), vpMbTracker::loadCAOModel(), vpRobotAfma4::readPosFile(), vpRobotAfma6::readPosFile(), vpRobotFranka::readPosFile(), vpRobotUniversalRobots::readPosFile(), vpRobotViper650::readPosFile(), vpRobotViper850::readPosFile(), vpSimulatorAfma6::readPosFile(), vpSimulatorViper850::readPosFile(), vpRobotBiclops::readPositionFile(), vpRobotPtu46::readPositionFile(), and vpWireFrameSimulator::vpWireFrameSimulator().
|
static |
Split a path in a drive specification (a drive letter followed by a colon) and the path specification. It is always true that drivespec + pathspec == p Inspired by the Python 2.7.8 module.
Definition at line 2227 of file vpIoTools.cpp.
|
static |
Return a lower-case version of the string input . Numbers and special characters stay the same.
input | The input string for which we want to ensure that all the characters are in lower case. |
Definition at line 2058 of file vpIoTools.cpp.
Referenced by vpImageFilter::vpCannyBackendTypeFromString(), and vpImageFilter::vpCannyFilteringAndGradientTypeFromString().
|
static |
Return a upper-case version of the string input . Numbers and special characters stay the same.
input | The input string for which we want to ensure that all the characters are in upper case. |
Definition at line 2079 of file vpIoTools.cpp.
|
static |
Remove leading and trailing whitespaces from a string.
Definition at line 2638 of file vpIoTools.cpp.
Referenced by vpMbTracker::loadCAOModel(), and vpMbTracker::parseParameters().
|
static |
Write a 16-bits integer value in little endian.
Definition at line 2543 of file vpIoTools.cpp.
References vpEndian::swap16bits().
Referenced by vpKeyPoint::saveLearningData().
|
static |
Write a 32-bits integer value in little endian.
Definition at line 2571 of file vpIoTools.cpp.
References vpEndian::swap32bits().
|
static |
Write a 16-bits unsigned integer value in little endian.
Definition at line 2557 of file vpIoTools.cpp.
References vpEndian::swap16bits().
|
static |
Write a 32-bits unsigned integer value in little endian.
Definition at line 2585 of file vpIoTools.cpp.
References vpEndian::swap32bits().
|
static |
Write a double value in little endian.
Definition at line 2613 of file vpIoTools.cpp.
References vpEndian::swapDouble().
|
static |
Write a float value in little endian.
Definition at line 2599 of file vpIoTools.cpp.
References vpEndian::swapFloat().
|
staticprotected |
Definition at line 583 of file vpIoTools.h.
|
staticprotected |
Definition at line 582 of file vpIoTools.h.
|
staticprotected |
Definition at line 584 of file vpIoTools.h.
|
staticprotected |
Definition at line 586 of file vpIoTools.h.
|
staticprotected |
Definition at line 585 of file vpIoTools.h.
|
static |
Define the directory separator character, backslash ('\') for windows platform or slash ('/') otherwise.
Definition at line 518 of file vpIoTools.h.
Referenced by createFilePath(), getName(), and getParent().