Visual Servoing Platform  version 3.5.1 under development (2023-09-22)
vpIoTools Class Reference

#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)
 

Detailed Description

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.

#include <fstream>
#include <iostream>
#include <string>
#include <visp3/core/vpIoTools.h>
int main()
{
std::string username;
// Test if a username directory exist. If no try to create it
if (vpIoTools::checkDirectory(username) == false) {
try {
// Create a directory with name "username"
}
catch (...) {
std::cout << "Cannot create " << username << " directory" << std::endl;
return EXIT_FAILURE;
}
}
// Create a empty filename with name "username/file.txt"
std::ofstream f;
std::string filename = username + "/file.txt";
// Under Windows converts the filename string into "username\\file.txt"
filename = vpIoTools::path(filename);
std::cout << "Create: " << filename << std::endl;
f.open(filename.c_str());
f.close();
// Rename the file
std::string newfilename = username + "/newfile.txt";
std::cout << "Rename: " << filename << " in: " << newfilename << std::endl;
if (vpIoTools::rename(filename, newfilename) == false)
std::cout << "Unable to rename: " << filename << std::endl;
// Remove the file
std::cout << "Remove: " << newfilename << std::endl;
if (vpIoTools::remove(newfilename) == false)
std::cout << "Unable to remove: " << newfilename << std::endl;
return EXIT_SUCCESS;
}
static std::string path(const std::string &pathname)
Definition: vpIoTools.cpp:1052
static bool checkDirectory(const std::string &dirname)
Definition: vpIoTools.cpp:449
static bool rename(const std::string &oldfilename, const std::string &newfilename)
Definition: vpIoTools.cpp:1034
static std::string getUserName()
Definition: vpIoTools.cpp:342
static void makeDirectory(const std::string &dirname)
Definition: vpIoTools.cpp:603
static bool remove(const std::string &filename)
Definition: vpIoTools.cpp:970

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" :

expNumber 2
save 0
lambda 0.4
use2D 0
use3D 1
#include <iostream>
#include <string>
#include <visp3/core/vpIoTools.h>
int main()
{
// reading configuration file
vpIoTools::loadConfigFile("/home/user/demo/config.txt");
std::string nExp;vpIoTools::readConfigVar("expNumber", nExp); // nExp <- "2"
double lambda;vpIoTools::readConfigVar("lambda", lambda); // lambda <- 0.4
bool use2D;vpIoTools::readConfigVar("use2D", use2D); // use2D <- false
bool use3D;vpIoTools::readConfigVar("use3D", use3D); // use3D <- true
bool doSave;vpIoTools::readConfigVar("save", doSave); // doSave <- false
// creating name for experiment files
vpIoTools::setBaseDir("/home/user/data");
// full name <- "/home/user/data/exp2"
vpIoTools::setBaseName("exp" + nExp);
// full name <- "/home/user/data/exp2" since use2D==false
// full name <- "/home/user/data/exp2_3D"
// full name <- "/home/user/data/exp2_3D_lambda0.4"
vpIoTools::addNameElement("lambda", lambda);
// Saving file.Would copy "/home/user/demo/config.txt" to
// "/home/user/data/exp2_3D_lambda0.4_config.txt" if doSave was true
// create sub directory
vpIoTools::createBaseNamePath(); // creates "/home/user/data/exp2_3D_lambda0.4/"
}
static bool readConfigVar(const std::string &var, float &value)
Definition: vpIoTools.cpp:1143
static void setBaseName(const std::string &s)
Definition: vpIoTools.cpp:258
static void setBaseDir(const std::string &dir)
Definition: vpIoTools.cpp:265
static bool loadConfigFile(const std::string &confFile)
Definition: vpIoTools.cpp:1092
static void saveConfigFile(const bool &actuallySave=true)
Definition: vpIoTools.cpp:1395
static void addNameElement(const std::string &strTrue, const bool &cond=true, const std::string &strFalse="")
Definition: vpIoTools.cpp:1340
static void createBaseNamePath(const bool &empty=false)
Definition: vpIoTools.cpp:1375

Definition at line 153 of file vpIoTools.h.

Member Function Documentation

◆ addNameElement() [1/2]

void vpIoTools::addNameElement ( const std::string &  strTrue,
const bool &  cond = true,
const std::string &  strFalse = "" 
)
static

Augments the prefix of the experiment files by strTrue if cond is verified, and by strFalse otherwise.

Parameters
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 1340 of file vpIoTools.cpp.

References baseName.

◆ addNameElement() [2/2]

void vpIoTools::addNameElement ( const std::string &  strTrue,
const double &  val 
)
static

Augments the prefix of the experiment files by strTrue followed by val.

Parameters
strTrue: String to add
val: Value to add

Definition at line 1356 of file vpIoTools.cpp.

References baseName.

◆ checkDirectory()

bool vpIoTools::checkDirectory ( const std::string &  dirname)
static

Check if a directory exists.

Parameters
dirname: Directory to test if it exists. The directory name is converted to the current system's format; see path().
Returns
true : If the directory exists and is accessible with write access.
false : If dirname string is null, or is not a directory, or has no write access.
Examples
SickLDMRS-Process.cpp, displayD3D.cpp, displayGTK.cpp, displayOpenCV.cpp, displayX.cpp, displayXMulti.cpp, histogram.cpp, imageDiskRW.cpp, mbtGenericTrackingDepth.cpp, mbtGenericTrackingDepthOnly.cpp, servoAfma4Point2DArtVelocity.cpp, servoAfma4Point2DCamVelocity.cpp, servoAfma4Point2DCamVelocityKalman.cpp, servoAfma6FourPoints2DArtVelocity.cpp, servoAfma6FourPoints2DCamVelocityLs_cur.cpp, servoAfma6FourPoints2DCamVelocityLs_des.cpp, servoAfma6Point2DArtVelocity.cpp, servoAfma6Point2DCamVelocity.cpp, servoAfma6Points2DCamVelocityEyeToHand.cpp, servoAfma6Segment2DCamVelocity.cpp, servoBiclopsPoint2DArtVelocity.cpp, servoSimu3D_cMcd_CamVelocity.cpp, servoSimu3D_cMcd_CamVelocityWithoutVpServo.cpp, servoSimu3D_cdMc_CamVelocity.cpp, servoSimu3D_cdMc_CamVelocityWithoutVpServo.cpp, servoSimuFourPoints2DPolarCamVelocityDisplay.cpp, servoViper650FourPoints2DArtVelocityLs_cur.cpp, servoViper650FourPoints2DCamVelocityLs_cur-SR300.cpp, servoViper650FourPoints2DCamVelocityLs_cur.cpp, servoViper650Point2DCamVelocity.cpp, servoViper850FourPoints2DArtVelocityLs_cur.cpp, servoViper850FourPoints2DArtVelocityLs_des.cpp, servoViper850FourPoints2DCamVelocityLs_cur.cpp, servoViper850FourPointsKinect.cpp, servoViper850Point2DArtVelocity.cpp, servoViper850Point2DCamVelocity.cpp, servoViper850Point2DCamVelocityKalman.cpp, sonarPioneerReader.cpp, testAutoThreshold.cpp, testConnectedComponents.cpp, testContours.cpp, testConversion.cpp, testCrop.cpp, testCropAdvanced.cpp, testFloodFill.cpp, testGenericTracker.cpp, testGenericTrackerDepth.cpp, testImgproc.cpp, testIoEXR.cpp, testIoPFM.cpp, testIoPGM.cpp, testIoPPM.cpp, testIoTools.cpp, testPerformanceLUT.cpp, testRobust.cpp, testUndistortImage.cpp, and testXmlParser.cpp.

Definition at line 449 of file vpIoTools.cpp.

References path(), and separator.

Referenced by copy(), createBaseNamePath(), getDirFiles(), getFileExtension(), vpSimulatorAfma6::init(), vpSimulatorViper850::init(), vpSimulatorAfma6::initArms(), vpSimulatorViper850::initArms(), makeDirectory(), makeFifo(), makeTempDirectory(), vpServoData::open(), remove(), vpRobotFranka::setLogFolder(), vpImageQueue< Type >::vpImageQueue(), and vpWireFrameSimulator::vpWireFrameSimulator().

◆ checkFifo()

bool vpIoTools::checkFifo ( const std::string &  fifofilename)
static

Check if a fifo file exists.

Parameters
fifofilename: Fifo filename to test if it exists.
Returns
true : If the fifo file exists and is accessible with read access.
false : If fifofilename string is null, or is not a fifo filename, or has no read access.
See also
checkFilename(const std::string &)
Examples
testIoTools.cpp.

Definition at line 514 of file vpIoTools.cpp.

References vpException::notImplementedError, and path().

Referenced by makeFifo(), and remove().

◆ checkFilename()

bool vpIoTools::checkFilename ( const std::string &  filename)
static

Check if a file exists.

Parameters
filename: Filename to test if it exists.
Returns
true : If the filename exists and is accessible with read access.
false : If filename string is null, or is not a filename, or has no read access.
Examples
UniversalRobotsMoveToPosition.cpp, fernClassifier.cpp, frankaMoveToPosition.cpp, mbtGenericTrackingDepth.cpp, mbtGenericTrackingDepthOnly.cpp, planarObjectDetector.cpp, readRealSenseData.cpp, testAprilTag.cpp, testForceTorqueAti.cpp, testGenericTracker.cpp, testGenericTrackerDepth.cpp, testImageWarp.cpp, testIoEXR.cpp, testIoPFM.cpp, testIoTools.cpp, testKeyPoint-7.cpp, tutorial-chessboard-pose.cpp, tutorial-detection-object-mbt-deprecated.cpp, tutorial-detection-object-mbt.cpp, tutorial-detection-object-mbt2-deprecated.cpp, tutorial-detection-object-mbt2.cpp, tutorial-dnn-object-detection-live.cpp, tutorial-mb-edge-tracker.cpp, tutorial-mb-generic-tracker-full.cpp, tutorial-mb-generic-tracker-live.cpp, tutorial-mb-generic-tracker-rgbd-blender.cpp, tutorial-mb-generic-tracker-rgbd-realsense.cpp, tutorial-mb-generic-tracker-rgbd-structure-core.cpp, tutorial-mb-generic-tracker-rgbd.cpp, tutorial-mb-hybrid-tracker.cpp, tutorial-mb-klt-tracker.cpp, and tutorial-mb-tracker-full.cpp.

Definition at line 835 of file vpIoTools.cpp.

References path().

Referenced by copy(), vpDot2::defineDots(), getFileExtension(), getViSPImagesDataPath(), vpAROgre::init(), vpRobotViper850::init(), vpMbTracker::initClick(), vpMbTracker::loadCAOModel(), vpMbTracker::loadModel(), makeFifo(), vpImageIo::read(), and remove().

◆ copy()

bool vpIoTools::copy ( const std::string &  src,
const std::string &  dst 
)
static

Copy a src file or directory in dst.

Parameters
src: Existing file or directory to copy.
dst: New copied file or directory.

Definition at line 877 of file vpIoTools.cpp.

References checkDirectory(), checkFilename(), vpException::fatalError, and path().

Referenced by saveConfigFile().

◆ createBaseNamePath()

void vpIoTools::createBaseNamePath ( const bool &  empty = false)
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.

Parameters
empty: Indicates if the new directory has to be emptied

Definition at line 1375 of file vpIoTools.cpp.

References baseDir, baseName, checkDirectory(), makeDirectory(), and remove().

◆ createFilePath()

std::string vpIoTools::createFilePath ( const std::string &  parent,
const std::string &  child 
)
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.

Examples
AROgre.cpp, AROgreBasic.cpp, displayD3D.cpp, displayGTK.cpp, displayOpenCV.cpp, displaySequence.cpp, displayX.cpp, displayXMulti.cpp, fernClassifier.cpp, histogram.cpp, imageDiskRW.cpp, imageSequenceReader.cpp, manSimu4Dots.cpp, manSimu4Points.cpp, mbtEdgeKltTracking.cpp, mbtEdgeTracking.cpp, mbtGenericTracking.cpp, mbtGenericTracking2.cpp, mbtGenericTrackingDepth.cpp, mbtGenericTrackingDepthOnly.cpp, mbtKltTracking.cpp, perfImageAddSub.cpp, photometricVisualServoing.cpp, photometricVisualServoingWithoutVpServo.cpp, planarObjectDetector.cpp, poseVirtualVS.cpp, simulateCircle2DCamVelocity.cpp, simulateFourPoints2DCartesianCamVelocity.cpp, simulateFourPoints2DPolarCamVelocity.cpp, sonarPioneerReader.cpp, templateTracker.cpp, testAprilTag.cpp, testAutoThreshold.cpp, testClick.cpp, testColorConversion.cpp, testConnectedComponents.cpp, testContours.cpp, testConversion.cpp, testCrop.cpp, testCropAdvanced.cpp, testFloodFill.cpp, testGaussianFilter.cpp, testGenericTracker.cpp, testGenericTrackerDepth.cpp, testHistogram.cpp, testImageAddSub.cpp, testImageComparison.cpp, testImageFilter.cpp, testImageNormalizedCorrelation.cpp, testImageTemplateMatching.cpp, testImageWarp.cpp, testImgproc.cpp, testIoEXR.cpp, testIoPFM.cpp, testIoPGM.cpp, testIoPPM.cpp, testIoTools.cpp, testKeyPoint-2.cpp, testKeyPoint-3.cpp, testKeyPoint-4.cpp, testKeyPoint-5.cpp, testKeyPoint-6.cpp, testKeyPoint-7.cpp, testKeyPoint.cpp, testMouseEvent.cpp, testPerformanceLUT.cpp, testReadImage.cpp, testTrackDot.cpp, testUndistortImage.cpp, testVideoDevice.cpp, testXmlParser.cpp, trackDot.cpp, trackDot2.cpp, trackDot2WithAutoDetection.cpp, trackKltOpencv.cpp, trackMeCircle.cpp, trackMeEllipse.cpp, trackMeLine.cpp, trackMeNurbs.cpp, tutorial-hand-eye-calibration.cpp, and videoReader.cpp.

Definition at line 1782 of file vpIoTools.cpp.

References path(), and separator.

Referenced by vpMbTracker::loadCAOModel(), vpRobotKinova::loadPlugin(), and makeTempDirectory().

◆ getAbsolutePathname()

std::string vpIoTools::getAbsolutePathname ( const std::string &  pathname)
static

Returns the absolute path using realpath() on Unix systems or GetFullPathName() on Windows systems.

Returns
According to realpath() manual, returns an absolute pathname that names the same file, whose resolution does not involve '.', '..', or symbolic links for Unix systems. According to GetFullPathName() documentation, retrieves the full path of the specified file for Windows systems.

Definition at line 1740 of file vpIoTools.cpp.

References vpException::fatalError.

Referenced by isSamePathname(), and vpMbTracker::loadCAOModel().

◆ getBaseName()

std::string vpIoTools::getBaseName ( )
static

Gets the base name (prefix) of the experiment files.

Returns
the base name of the experiment files.

Definition at line 272 of file vpIoTools.cpp.

References baseName.

◆ getBuildInformation()

const std::string & vpIoTools::getBuildInformation ( )
static

Return build informations (OS, compiler, build flags, used 3rd parties...).

Examples
testBuildInformation.cpp.

Definition at line 159 of file vpIoTools.cpp.

◆ getDirFiles()

std::vector< std::string > vpIoTools::getDirFiles ( const std::string &  pathname)
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 ".."

Parameters
pathname: path to directory
Returns
A vector of files' names in that directory
Examples
tutorial-hand-eye-calibration.cpp.

Definition at line 2041 of file vpIoTools.cpp.

References checkDirectory(), vpException::fatalError, and path().

◆ getenv()

std::string vpIoTools::getenv ( const std::string &  env)
static

Get the content of an environment variable.

Parameters
env: Environment variable name (HOME, LOGNAME...).
Returns
Value of the environment variable
Exceptions
vpIoException::cantGetenv: If an error occur while getting the environment variable value.
#include <iostream>
#include <string>
#include <visp3/core/vpIoTools.h>
int main()
{
std::string envvalue;
try {
std::string env = "HOME";
envvalue = vpIoTools::getenv(env);
std::cout << "$HOME = \"" << envvalue << "\"" << std::endl;
}
catch (const vpException &e) {
std::cout << e.getMessage() << std::endl;
return -1;
}
return 0;
}
error that can be emitted by ViSP classes.
Definition: vpException.h:59
const char * getMessage() const
Definition: vpException.cpp:64
static std::string getenv(const std::string &env)
Definition: vpIoTools.cpp:379

Definition at line 379 of file vpIoTools.cpp.

References vpIoException::cantGetenv.

Referenced by getUserName(), getViSPImagesDataPath(), vpSimulatorAfma6::init(), vpSimulatorViper850::init(), vpSimulatorAfma6::initArms(), vpSimulatorViper850::initArms(), and vpWireFrameSimulator::vpWireFrameSimulator().

◆ getFileExtension()

std::string vpIoTools::getFileExtension ( const std::string &  pathname,
bool  checkFile = false 
)
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.

Parameters
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.
Returns
The extension of the file including the dot "." or an empty string if the file has no extension or if the pathname is empty.

The following code shows how to use this function:

#include <visp3/core/vpIoTools.h>
int main()
{
std::string filename = "my/path/to/file.xml"
std::string ext = vpIoTools::getFileExtension(opt_learning_data);
std::cout << "ext: " << ext << std::endl;
}
static std::string getFileExtension(const std::string &pathname, bool checkFile=false)
Definition: vpIoTools.cpp:1483

It produces the following output:

ext: .xml
Examples
testIoTools.cpp, and tutorial-undistort.cpp.

Definition at line 1483 of file vpIoTools.cpp.

References checkDirectory(), and checkFilename().

Referenced by vpMbGenericTracker::loadConfigFile().

◆ getFullName()

std::string vpIoTools::getFullName ( )
static

Gets the full path of the experiment files : baseDir/baseName

Returns
the full path of the experiment files.

Definition at line 279 of file vpIoTools.cpp.

References baseDir, and baseName.

◆ getIndex()

long vpIoTools::getIndex ( const std::string &  filename,
const std::string &  format 
)
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.

Parameters
filename: Name from which to extract the index.
format: Format of the filename.
Returns
Extracted index on success, -1 otherwise.

The following sample code shows how to use this function:

#include <visp3/core/vpIoTools.h>
int main()
{
std::cout << vpIoTools::getIndex("file-1.txt", "file-%d.txt") << std::endl;
std::cout << vpIoTools::getIndex("/tmp/file0040.txt", "/tmp/file%04d.txt") << std::endl;
std::cout << vpIoTools::getIndex("file.txt", "file%d.txt") << std::endl;
std::cout << vpIoTools::getIndex("file03.txt", "file%02d.txt") << std::endl;
std::cout << vpIoTools::getIndex("file-03.txt", "file%02d.txt") << std::endl;
}
static long getIndex(const std::string &filename, const std::string &format)
Definition: vpIoTools.cpp:1627

It produces the following output:

1
40
-1
3
-1
Examples
testIoTools.cpp, and tutorial-hand-eye-calibration.cpp.

Definition at line 1627 of file vpIoTools.cpp.

◆ getName()

std::string vpIoTools::getName ( const std::string &  pathname)
static

Returns the name of the file or directory denoted by this pathname.

Returns
The name of the file or directory denoted by this pathname, or an empty string if this pathname's name sequence is empty.
Examples
testIoTools.cpp, and tutorial-hand-eye-calibration.cpp.

Definition at line 1564 of file vpIoTools.cpp.

References path(), and separator.

Referenced by getNameWE(), vpMbTracker::loadCAOModel(), vpImageStorageWorker< Type >::run(), and vpVideoReader::setFileName().

◆ getNameWE()

◆ getParent()

std::string vpIoTools::getParent ( const std::string &  pathname)
static

Returns the pathname string of this pathname's parent.

Parameters
[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.
Returns
The parent of the pathname, or an empty string if the pathname is empty.

For example

  • when pathname is set to "./executable" it returns "."
  • When pathname is set to "folder/executable" it returns "folder"
  • When pathname is set to "folder\subfolder\file.cpp" it returns "folder\subfolder"
  • When pathname is set to "executable" it returns "."
Examples
servoSimu4Points.cpp, testIoTools.cpp, trackMeEllipse.cpp, tutorial-detection-object-mbt-deprecated.cpp, tutorial-detection-object-mbt.cpp, tutorial-detection-object-mbt2-deprecated.cpp, tutorial-detection-object-mbt2.cpp, tutorial-hand-eye-calibration.cpp, tutorial-mb-edge-tracker.cpp, tutorial-mb-generic-tracker-full.cpp, tutorial-mb-generic-tracker-live.cpp, tutorial-mb-generic-tracker-rgbd-realsense-json-settings.cpp, tutorial-mb-generic-tracker-rgbd-realsense.cpp, tutorial-mb-generic-tracker-rgbd-structure-core.cpp, tutorial-mb-generic-tracker-stereo-mono.cpp, tutorial-mb-generic-tracker-stereo.cpp, tutorial-mb-generic-tracker.cpp, tutorial-mb-hybrid-tracker.cpp, tutorial-mb-klt-tracker.cpp, tutorial-mb-tracker-full.cpp, tutorial-mb-tracker.cpp, tutorial-pose-from-planar-object.cpp, tutorial-pose-from-points-image.cpp, and tutorial-pose-from-qrcode-image.cpp.

Definition at line 1669 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().

◆ getTempPath()

std::string vpIoTools::getTempPath ( )
static

Return path to the default temporary folder:

  • on Windows it returns GetTempPath()
  • on Unix it returns /tmp/<username>
Warning
This function is not implemented on WINRT.

The following sample shows how to use this function to create unique temporary directories:

include <visp3/core/vpIoTools.h>
int main()
{
std::string tmp_path = vpIoTools::getTempPath();
std::cout << "Temp path: " << tmp_path << std::endl;
std::string tmp_dir1 = vpIoTools::makeTempDirectory(tmp_path);
std::cout << "Created unique temp dir1: " << tmp_dir1 << std::endl;
std::string tmp_dir2_template = tmp_path + vpIoTools::path("/") + "dir_XXXXXX";
std::string tmp_dir2 = vpIoTools::makeTempDirectory(tmp_dir2_template);
std::cout << "Created unique temp dir2: " << tmp_dir2 << std::endl;
if (vpIoTools::remove(tmp_dir1)) {
std::cout << "Temp dir1 was deleted" << std::endl;
}
if (vpIoTools::remove(tmp_dir2)) {
std::cout << "Temp dir2 was deleted" << std::endl;
}
}
File and directories basic tools.
Definition: vpIoTools.h:154
static std::string getTempPath()
Definition: vpIoTools.cpp:218
static std::string makeTempDirectory(const std::string &dirname)
Definition: vpIoTools.cpp:757

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
See also
makeTempDirectory(), remove()
Examples
testIoEXR.cpp, testIoPFM.cpp, and testIoTools.cpp.

Definition at line 218 of file vpIoTools.cpp.

References vpIoException::cantGetenv, vpException::fatalError, getUserName(), and makeDirectory().

◆ getUserName() [1/2]

std::string vpIoTools::getUserName ( )
static

Get the user name.

  • Under unix, get the content of the LOGNAME environment variable. For most purposes (especially in conjunction with crontab), it is more useful to use the environment variable LOGNAME to find out who the user is, rather than the getlogin() function. This is more flexible precisely because the user can set LOGNAME arbitrarily.
  • Under windows, uses the GetUserName() function.
Returns
The user name.
See also
getUserName(std::string &)
Examples
displayD3D.cpp, displayGTK.cpp, displayOpenCV.cpp, displayX.cpp, displayXMulti.cpp, histogram.cpp, imageDiskRW.cpp, servoAfma4Point2DArtVelocity.cpp, servoAfma4Point2DCamVelocity.cpp, servoAfma4Point2DCamVelocityKalman.cpp, servoAfma6FourPoints2DArtVelocity.cpp, servoAfma6FourPoints2DCamVelocityLs_cur.cpp, servoAfma6FourPoints2DCamVelocityLs_des.cpp, servoAfma6Point2DArtVelocity.cpp, servoAfma6Point2DCamVelocity.cpp, servoAfma6Points2DCamVelocityEyeToHand.cpp, servoAfma6Segment2DCamVelocity.cpp, servoBiclopsPoint2DArtVelocity.cpp, servoSimu3D_cMcd_CamVelocity.cpp, servoSimu3D_cMcd_CamVelocityWithoutVpServo.cpp, servoSimu3D_cdMc_CamVelocity.cpp, servoSimu3D_cdMc_CamVelocityWithoutVpServo.cpp, servoSimuFourPoints2DPolarCamVelocityDisplay.cpp, servoViper650FourPoints2DArtVelocityLs_cur.cpp, servoViper650FourPoints2DCamVelocityLs_cur-SR300.cpp, servoViper650FourPoints2DCamVelocityLs_cur.cpp, servoViper650Point2DCamVelocity.cpp, servoViper850FourPoints2DArtVelocityLs_cur.cpp, servoViper850FourPoints2DArtVelocityLs_des.cpp, servoViper850FourPoints2DCamVelocityLs_cur.cpp, servoViper850FourPointsKinect.cpp, servoViper850Point2DArtVelocity.cpp, servoViper850Point2DCamVelocity.cpp, servoViper850Point2DCamVelocityKalman.cpp, sonarPioneerReader.cpp, templateTracker.cpp, test1394TwoGrabber.cpp, testAutoThreshold.cpp, testConnectedComponents.cpp, testContours.cpp, testConversion.cpp, testCrop.cpp, testCropAdvanced.cpp, testFloodFill.cpp, testImageComparison.cpp, testImgproc.cpp, testIoPGM.cpp, testIoPPM.cpp, testIoTools.cpp, testKeyPoint-7.cpp, testPerformanceLUT.cpp, testPylonGrabber.cpp, testRobust.cpp, testUndistortImage.cpp, and testXmlParser.cpp.

Definition at line 342 of file vpIoTools.cpp.

Referenced by getTempPath().

◆ getUserName() [2/2]

void vpIoTools::getUserName ( std::string &  username)
static

Get the user name.

  • Under unix, get the content of the LOGNAME environment variable. For most purposes (especially in conjunction with crontab), it is more useful to use the environment variable LOGNAME to find out who the user is, rather than the getlogin() function. This is more flexible precisely because the user can set LOGNAME arbitrarily.
  • Under windows, uses the GetUserName() function.
Parameters
username: The user name. When the username cannot be retrieved, set username to "unknown" string.

Definition at line 294 of file vpIoTools.cpp.

References getenv().

◆ getVersion()

void vpIoTools::getVersion ( const std::string &  version,
unsigned int &  major,
unsigned int &  minor,
unsigned int &  patch 
)
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.

Parameters
version: String to extract the values.
major: Extracted major.
minor: Extracted minor.
patch: Extracted patch.

Definition at line 406 of file vpIoTools.cpp.

◆ getViSPImagesDataPath()

std::string vpIoTools::getViSPImagesDataPath ( )
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.

  • It checks first if VISP_INPUT_IMAGE_PATH environment variable that gives the location of the data is set. In that case returns the content of this environment var.
  • Otherwise it checks if visp-images-data binary package (Ubuntu, Debian) is installed. In that case returns then /usr/share/visp-images-data".
  • If the path is not found, returns an empty string.
Examples
AROgre.cpp, AROgreBasic.cpp, displayD3D.cpp, displayGTK.cpp, displayOpenCV.cpp, displaySequence.cpp, displayX.cpp, displayXMulti.cpp, fernClassifier.cpp, grabDisk.cpp, histogram.cpp, imageDiskRW.cpp, imageSequenceReader.cpp, manSimu4Dots.cpp, manSimu4Points.cpp, mbtEdgeKltTracking.cpp, mbtEdgeTracking.cpp, mbtGenericTracking.cpp, mbtGenericTracking2.cpp, mbtGenericTrackingDepth.cpp, mbtGenericTrackingDepthOnly.cpp, mbtKltTracking.cpp, perfImageAddSub.cpp, photometricVisualServoing.cpp, photometricVisualServoingWithoutVpServo.cpp, planarObjectDetector.cpp, poseVirtualVS.cpp, simulateCircle2DCamVelocity.cpp, simulateFourPoints2DCartesianCamVelocity.cpp, simulateFourPoints2DPolarCamVelocity.cpp, templateTracker.cpp, testAprilTag.cpp, testAutoThreshold.cpp, testClick.cpp, testColorConversion.cpp, testConnectedComponents.cpp, testContours.cpp, testConversion.cpp, testCrop.cpp, testCropAdvanced.cpp, testFloodFill.cpp, testGaussianFilter.cpp, testGenericTracker.cpp, testGenericTrackerDepth.cpp, testHistogram.cpp, testImageAddSub.cpp, testImageComparison.cpp, testImageFilter.cpp, testImageNormalizedCorrelation.cpp, testImageTemplateMatching.cpp, testImageWarp.cpp, testImgproc.cpp, testIoEXR.cpp, testIoPFM.cpp, testIoPGM.cpp, testIoPPM.cpp, testIoTools.cpp, testKeyPoint-2.cpp, testKeyPoint-3.cpp, testKeyPoint-4.cpp, testKeyPoint-5.cpp, testKeyPoint-6.cpp, testKeyPoint-7.cpp, testKeyPoint.cpp, testMouseEvent.cpp, testPerformanceLUT.cpp, testReadImage.cpp, testTrackDot.cpp, testUndistortImage.cpp, testVideoDevice.cpp, trackDot.cpp, trackDot2.cpp, trackDot2WithAutoDetection.cpp, trackKltOpencv.cpp, trackMeCircle.cpp, trackMeEllipse.cpp, trackMeLine.cpp, trackMeNurbs.cpp, and videoReader.cpp.

Definition at line 1417 of file vpIoTools.cpp.

References checkFilename(), and getenv().

◆ isAbsolutePathname()

bool vpIoTools::isAbsolutePathname ( const std::string &  pathname)
static

Return whether a path is absolute.

Returns
true if the pathname is absolute, false otherwise.
Examples
testIoTools.cpp.

Definition at line 1823 of file vpIoTools.cpp.

References path(), and splitDrive().

Referenced by vpMbTracker::loadCAOModel(), and vpKeyPoint::loadLearningData().

◆ isSamePathname()

bool vpIoTools::isSamePathname ( const std::string &  pathname1,
const std::string &  pathname2 
)
static

Return true if the two pathnames are identical.

Returns
true if the two pathnames are identical, false otherwise.
Note
It uses path() to normalize the path and getAbsolutePathname() to get the absolute pathname.
Examples
testIoTools.cpp.

Definition at line 1847 of file vpIoTools.cpp.

References getAbsolutePathname(), and path().

◆ loadConfigFile()

bool vpIoTools::loadConfigFile ( const std::string &  confFile)
static

Reads the configuration file and parses it.

Parameters
confFile: path to the file containing the configuration parameters to parse.
Returns
true if succeed, false otherwise.

Definition at line 1092 of file vpIoTools.cpp.

References configFile, configValues, configVars, vpMath::minimum(), and path().

◆ makeDirectory()

void vpIoTools::makeDirectory ( const std::string &  dirname)
static

Create a new directory. It will create recursively the parent directories if needed.

Parameters
dirname: Directory to create. The directory name is converted to the current system's format; see path().
Exceptions
vpIoException::cantCreateDirectory: If the directory cannot be created.
See also
makeTempDirectory(), remove()
Examples
SickLDMRS-Process.cpp, displayD3D.cpp, displayGTK.cpp, displayOpenCV.cpp, displayX.cpp, displayXMulti.cpp, grabV4l2MultiCpp11Thread.cpp, histogram.cpp, imageDiskRW.cpp, readRealSenseData.cpp, saveRealSenseData.cpp, servoAfma4Point2DArtVelocity.cpp, servoAfma4Point2DCamVelocity.cpp, servoAfma4Point2DCamVelocityKalman.cpp, servoAfma6FourPoints2DArtVelocity.cpp, servoAfma6FourPoints2DCamVelocityLs_cur.cpp, servoAfma6FourPoints2DCamVelocityLs_des.cpp, servoAfma6Point2DArtVelocity.cpp, servoAfma6Point2DCamVelocity.cpp, servoAfma6Points2DCamVelocityEyeToHand.cpp, servoAfma6Segment2DCamVelocity.cpp, servoBiclopsPoint2DArtVelocity.cpp, servoSimu3D_cMcd_CamVelocity.cpp, servoSimu3D_cMcd_CamVelocityWithoutVpServo.cpp, servoSimu3D_cdMc_CamVelocity.cpp, servoSimu3D_cdMc_CamVelocityWithoutVpServo.cpp, servoSimuFourPoints2DPolarCamVelocityDisplay.cpp, servoViper650FourPoints2DArtVelocityLs_cur.cpp, servoViper650FourPoints2DCamVelocityLs_cur-SR300.cpp, servoViper650FourPoints2DCamVelocityLs_cur.cpp, servoViper650Point2DCamVelocity.cpp, servoViper850FourPoints2DArtVelocityLs_cur.cpp, servoViper850FourPoints2DArtVelocityLs_des.cpp, servoViper850FourPoints2DCamVelocityLs_cur.cpp, servoViper850FourPointsKinect.cpp, servoViper850Point2DArtVelocity.cpp, servoViper850Point2DCamVelocity.cpp, servoViper850Point2DCamVelocityKalman.cpp, sonarPioneerReader.cpp, test1394TwoGrabber.cpp, testAutoThreshold.cpp, testConnectedComponents.cpp, testContours.cpp, testConversion.cpp, testCrop.cpp, testCropAdvanced.cpp, testFloodFill.cpp, testGenericTracker.cpp, testImgproc.cpp, testIoEXR.cpp, testIoPFM.cpp, testIoPGM.cpp, testIoPPM.cpp, testIoTools.cpp, testKeyPoint-7.cpp, testMathUtils.cpp, testPerformanceLUT.cpp, testPylonGrabber.cpp, testRobust.cpp, testUndistortImage.cpp, testXmlParser.cpp, trackMeEllipse.cpp, tutorial-mb-generic-tracker-full.cpp, tutorial-mb-generic-tracker-rgbd-realsense.cpp, and tutorial-mb-generic-tracker-rgbd-structure-core.cpp.

Definition at line 603 of file vpIoTools.cpp.

References vpIoException::cantCreateDirectory, checkDirectory(), vpIoException::invalidDirectoryName, and path().

Referenced by createBaseNamePath(), getTempPath(), makeTempDirectory(), vpServoData::open(), vpVideoWriter::open(), vpImageQueue< Type >::record(), vpKeyPoint::saveLearningData(), and vpRobotFranka::setLogFolder().

◆ makeFifo()

void vpIoTools::makeFifo ( const std::string &  fifoname)
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.

Warning
This function is only implemented on unix-like OS.
Parameters
[in]fifoname: Pathname of the fifo file to create.
Exceptions
vpIoException::invalidDirectoryName: The dirname is invalid.
vpIoException::cantCreateDirectory: If the file cannot be created.
Examples
testIoTools.cpp.

Definition at line 654 of file vpIoTools.cpp.

References vpIoException::cantCreateDirectory, checkDirectory(), checkFifo(), checkFilename(), and vpIoException::invalidDirectoryName.

◆ makeTempDirectory()

std::string vpIoTools::makeTempDirectory ( const std::string &  dirname)
static

Create a new temporary directory with a unique name based on dirname parameter.

Warning
This function is not implemented on WINRT.
Parameters
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.
Returns
String corresponding to the absolute path to the generated directory name.
Exceptions
vpIoException::cantCreateDirectory: If the directory cannot be created.

The following sample shows how to use this function to create unique temporary directories:

include <visp3/core/vpIoTools.h>
int main()
{
std::string tmp_path = vpIoTools::getTempPath();
std::cout << "Temp path: " << tmp_path << std::endl;
std::string tmp_dir1 = vpIoTools::makeTempDirectory(tmp_path);
std::cout << "Created unique temp dir1: " << tmp_dir1 << std::endl;
std::string tmp_dir2_template = tmp_path + vpIoTools::path("/") + "dir_XXXXXX";
std::string tmp_dir2 = vpIoTools::makeTempDirectory(tmp_dir2_template);
std::cout << "Created unique temp dir2: " << tmp_dir2 << std::endl;
if (vpIoTools::remove(tmp_dir1)) {
std::cout << "Temp dir1 was deleted" << std::endl;
}
if (vpIoTools::remove(tmp_dir2)) {
std::cout << "Temp dir2 was deleted" << std::endl;
}
}

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
See also
makeDirectory(), getTempPath(), remove()
Examples
testIoEXR.cpp, testIoPFM.cpp, and testIoTools.cpp.

Definition at line 757 of file vpIoTools.cpp.

References vpIoException::cantCreateDirectory, checkDirectory(), createFilePath(), and makeDirectory().

◆ parseBoolean()

bool vpIoTools::parseBoolean ( std::string  input)
static

Definition at line 2264 of file vpIoTools.cpp.

Referenced by vpMbTracker::loadCAOModel().

◆ path()

std::string vpIoTools::path ( const std::string &  pathname)
static

Converts a path name to the current system's format.

Parameters
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.
Returns
The converted path name.
Examples
histogram.cpp, testIoTools.cpp, testUndistortImage.cpp, and testXmlParser.cpp.

Definition at line 1052 of file vpIoTools.cpp.

Referenced by checkDirectory(), checkFifo(), checkFilename(), copy(), createFilePath(), getDirFiles(), getName(), getParent(), isAbsolutePathname(), isSamePathname(), vpMbTracker::loadCAOModel(), loadConfigFile(), makeDirectory(), vpImageIo::read(), and remove().

◆ readBinaryValueLE() [1/6]

void vpIoTools::readBinaryValueLE ( std::ifstream &  file,
double &  double_value 
)
static

Read a double value stored in little endian.

Definition at line 2170 of file vpIoTools.cpp.

References vpEndian::swapDouble().

◆ readBinaryValueLE() [2/6]

void vpIoTools::readBinaryValueLE ( std::ifstream &  file,
float &  float_value 
)
static

Read a float value stored in little endian.

Definition at line 2157 of file vpIoTools.cpp.

References vpEndian::swapFloat().

◆ readBinaryValueLE() [3/6]

void vpIoTools::readBinaryValueLE ( std::ifstream &  file,
int16_t &  short_value 
)
static

◆ readBinaryValueLE() [4/6]

void vpIoTools::readBinaryValueLE ( std::ifstream &  file,
int32_t &  int_value 
)
static

Read a 32-bits integer value stored in little endian.

Definition at line 2131 of file vpIoTools.cpp.

References vpEndian::swap32bits().

◆ readBinaryValueLE() [5/6]

void vpIoTools::readBinaryValueLE ( std::ifstream &  file,
uint16_t &  ushort_value 
)
static

Read a 16-bits unsigned integer value stored in little endian.

Definition at line 2118 of file vpIoTools.cpp.

References vpEndian::swap16bits().

◆ readBinaryValueLE() [6/6]

void vpIoTools::readBinaryValueLE ( std::ifstream &  file,
uint32_t &  uint_value 
)
static

Read a 32-bits unsigned integer value stored in little endian.

Definition at line 2144 of file vpIoTools.cpp.

References vpEndian::swap32bits().

◆ readConfigVar() [1/8]

bool vpIoTools::readConfigVar ( const std::string &  var,
bool &  value 
)
static

Tries to read the parameter named var as a bool.

Parameters
var: Name of the parameter in the configuration file.
value: Value to be read.
Returns
true if the parameter could be read.

Definition at line 1238 of file vpIoTools.cpp.

References readConfigVar().

◆ readConfigVar() [2/8]

bool vpIoTools::readConfigVar ( const std::string &  var,
double &  value 
)
static

Tries to read the parameter named var as a double.

Parameters
var: Name of the parameter in the configuration file.
value: Value to be read.
Returns
true if the parameter could be read.

Definition at line 1171 of file vpIoTools.cpp.

References configValues, and configVars.

◆ readConfigVar() [3/8]

bool vpIoTools::readConfigVar ( const std::string &  var,
float &  value 
)
static

Tries to read the parameter named var as a float.

Parameters
var: Name of the parameter in the configuration file.
value: Value to be read.
Returns
true if the parameter could be read.

Definition at line 1143 of file vpIoTools.cpp.

References configValues, and configVars.

Referenced by readConfigVar().

◆ readConfigVar() [4/8]

bool vpIoTools::readConfigVar ( const std::string &  var,
int &  value 
)
static

Tries to read the parameter named var as a int.

Parameters
var: Name of the parameter in the configuration file.
value: Value to be read.
Returns
true if the parameter could be read.

Definition at line 1200 of file vpIoTools.cpp.

References configValues, and configVars.

◆ readConfigVar() [5/8]

bool vpIoTools::readConfigVar ( const std::string &  var,
std::string &  value 
)
static

Tries to read the parameter named var as a std::string.

Parameters
var: Name of the parameter in the configuration file.
value: Value to be read.
Returns
true if the parameter could be read.

Definition at line 1270 of file vpIoTools.cpp.

References configValues, and configVars.

◆ readConfigVar() [6/8]

bool vpIoTools::readConfigVar ( const std::string &  var,
unsigned int &  value 
)
static

Tries to read the parameter named var as a unsigned int.

Parameters
var: Name of the parameter in the configuration file.
value: Value to be read.
Returns
true if the parameter could be read.

Definition at line 1222 of file vpIoTools.cpp.

References readConfigVar().

◆ readConfigVar() [7/8]

bool vpIoTools::readConfigVar ( const std::string &  var,
vpArray2D< double > &  value,
const unsigned int &  nCols = 0,
const unsigned int &  nRows = 0 
)
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.

Parameters
var: Name of the parameter in the configuration file.
value: Value to be read.
nCols: Column dimension if resized.
nRows: Row dimension if resized
Returns
true if the parameter could be read.

Definition at line 1297 of file vpIoTools.cpp.

References configValues, configVars, vpArray2D< Type >::getCols(), vpArray2D< Type >::getRows(), and vpArray2D< Type >::resize().

◆ readConfigVar() [8/8]

bool vpIoTools::readConfigVar ( const std::string &  var,
vpColor value 
)
static

Tries to read the parameter named var as a vpColor.

Parameters
var: Name of the parameter in the configuration file.
value: Value to be read. See vpColor.cpp for the color number.
Returns
true if the parameter could be read.

Definition at line 1254 of file vpIoTools.cpp.

References vpColor::getColor(), and readConfigVar().

◆ remove()

bool vpIoTools::remove ( const std::string &  file_or_dir)
static

Remove a file or a directory.

Parameters
file_or_dir: File name or directory to remove.
Returns
true if the file or the directory was removed, false otherwise.
See also
makeDirectory(), makeTempDirectory()
Examples
testIoEXR.cpp, testIoPFM.cpp, and testIoTools.cpp.

Definition at line 970 of file vpIoTools.cpp.

References checkDirectory(), checkFifo(), checkFilename(), vpException::fatalError, and path().

Referenced by createBaseNamePath().

◆ rename()

bool vpIoTools::rename ( const std::string &  oldfilename,
const std::string &  newfilename 
)
static

Rename an existing file oldfilename in newfilename.

Parameters
oldfilename: File to rename.
newfilename: New file name.
Returns
true if the file was renamed, false otherwise.

Definition at line 1034 of file vpIoTools.cpp.

◆ saveConfigFile()

void vpIoTools::saveConfigFile ( const bool &  actuallySave = true)
static

Copy the initial configuration file to the experiment directory.

Parameters
actuallySave: If false, do not copy the file.

Definition at line 1395 of file vpIoTools.cpp.

References baseDir, baseName, configFile, and copy().

◆ setBaseDir()

void vpIoTools::setBaseDir ( const std::string &  dir)
static

Sets the base directory of the experiment files.

Parameters
dir: Directory where the data will be saved.

Definition at line 265 of file vpIoTools.cpp.

References baseDir.

◆ setBaseName()

void vpIoTools::setBaseName ( const std::string &  s)
static

Sets the base name (prefix) of the experiment files.

Parameters
s: Prefix of the experiment files.

Definition at line 258 of file vpIoTools.cpp.

References baseName.

◆ splitChain()

std::vector< std::string > vpIoTools::splitChain ( const std::string &  chain,
const std::string &  sep 
)
static

Split a chain.

Parameters
chain: Input chain to split.
sep: Character separator.
Returns
A vector that contains all the subchains.

The following code shows how to use this function:

#include <visp3/core/vpIoTools.h>
int main()
{
{
std::string chain("/home/user;/usr/local/include;/usr/include");
std::string sep = ";";
std::vector<std::string> subChain = vpIoTools::splitChain(chain, sep);
std::cout << "Found the following subchains: " << std::endl;
for (size_t i=0; i < subChain.size(); i++)
std::cout << subChain[i] << std::endl;
}
{
std::string chain("This is an other example");
std::string sep = " ";
std::vector<std::string> subChain = vpIoTools::splitChain(chain, sep);
std::cout << "Found the following subchains: " << std::endl;
for (size_t i=0; i < subChain.size(); i++)
std::cout << subChain[i] << std::endl;
}
}
static std::vector< std::string > splitChain(const std::string &chain, const std::string &sep)
Definition: vpIoTools.cpp:2012

It produces the following output:

Found the following subchains:
/home/user
/usr/local/include
/usr/include
Found the following subchains:
This
is
an
other
example

Definition at line 2012 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().

◆ splitDrive()

std::pair< std::string, std::string > vpIoTools::splitDrive ( const std::string &  pathname)
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.

Returns
a pair whose the first element is the drive specification and the second element the path specification
Examples
testIoTools.cpp.

Definition at line 1867 of file vpIoTools.cpp.

Referenced by isAbsolutePathname().

◆ toLowerCase()

std::string vpIoTools::toLowerCase ( const std::string &  input)
static

Return a lower-case version of the string input . Numbers and special characters stay the same.

Parameters
inputThe input string for which we want to ensure that all the characters are in lower case.
Returns
std::string A lower-case version of the string input, where numbers and special characters stay the same
Examples
testIoTools.cpp, tutorial-dnn-object-detection-live.cpp, and tutorial-pcl-viewer.cpp.

Definition at line 1694 of file vpIoTools.cpp.

Referenced by vpDetectorDNNOpenCV::dnnResultsParsingTypeFromString().

◆ toUpperCase()

std::string vpIoTools::toUpperCase ( const std::string &  input)
static

Return a upper-case version of the string input . Numbers and special characters stay the same.

Parameters
inputThe input string for which we want to ensure that all the characters are in upper case.
Returns
std::string A upper-case version of the string input, where numbers and special characters stay the same
Examples
testIoTools.cpp.

Definition at line 1717 of file vpIoTools.cpp.

◆ trim()

std::string vpIoTools::trim ( std::string  s)
static

Remove leading and trailing whitespaces from a string.

Definition at line 2278 of file vpIoTools.cpp.

Referenced by vpMbTracker::loadCAOModel(), and vpMbTracker::parseParameters().

◆ writeBinaryValueLE() [1/6]

void vpIoTools::writeBinaryValueLE ( std::ofstream &  file,
const int16_t  short_value 
)
static

Write a 16-bits integer value in little endian.

Examples
saveRealSenseData.cpp.

Definition at line 2183 of file vpIoTools.cpp.

References vpEndian::swap16bits().

Referenced by vpKeyPoint::saveLearningData().

◆ writeBinaryValueLE() [2/6]

void vpIoTools::writeBinaryValueLE ( std::ofstream &  file,
const int32_t  int_value 
)
static

Write a 32-bits integer value in little endian.

Definition at line 2211 of file vpIoTools.cpp.

References vpEndian::swap32bits().

◆ writeBinaryValueLE() [3/6]

void vpIoTools::writeBinaryValueLE ( std::ofstream &  file,
const uint16_t  ushort_value 
)
static

Write a 16-bits unsigned integer value in little endian.

Definition at line 2197 of file vpIoTools.cpp.

References vpEndian::swap16bits().

◆ writeBinaryValueLE() [4/6]

void vpIoTools::writeBinaryValueLE ( std::ofstream &  file,
const uint32_t  uint_value 
)
static

Write a 32-bits unsigned integer value in little endian.

Definition at line 2225 of file vpIoTools.cpp.

References vpEndian::swap32bits().

◆ writeBinaryValueLE() [5/6]

void vpIoTools::writeBinaryValueLE ( std::ofstream &  file,
double  double_value 
)
static

Write a double value in little endian.

Definition at line 2253 of file vpIoTools.cpp.

References vpEndian::swapDouble().

◆ writeBinaryValueLE() [6/6]

void vpIoTools::writeBinaryValueLE ( std::ofstream &  file,
float  float_value 
)
static

Write a float value in little endian.

Definition at line 2239 of file vpIoTools.cpp.

References vpEndian::swapFloat().

Member Data Documentation

◆ baseDir

std::string vpIoTools::baseDir = ""
staticprotected

Definition at line 250 of file vpIoTools.h.

Referenced by createBaseNamePath(), getFullName(), saveConfigFile(), and setBaseDir().

◆ baseName

std::string vpIoTools::baseName = ""
staticprotected

◆ configFile

std::string vpIoTools::configFile = ""
staticprotected

Definition at line 251 of file vpIoTools.h.

Referenced by loadConfigFile(), and saveConfigFile().

◆ configValues

std::vector< std::string > vpIoTools::configValues = std::vector<std::string>()
staticprotected

Definition at line 253 of file vpIoTools.h.

Referenced by loadConfigFile(), and readConfigVar().

◆ configVars

std::vector< std::string > vpIoTools::configVars = std::vector<std::string>()
staticprotected

Definition at line 252 of file vpIoTools.h.

Referenced by loadConfigFile(), and readConfigVar().

◆ separator

const char vpIoTools::separator
static
Initial value:
=
'/'
Define the directory separator character, backslash ('\') for windows

platform or slash ('/') otherwise.

Examples
testIoTools.cpp.

Definition at line 181 of file vpIoTools.h.

Referenced by checkDirectory(), createFilePath(), getName(), and getParent().