34 #include <visp3/core/vpConfig.h>
35 #include <visp3/core/vpEndian.h>
36 #include <visp3/core/vpIoTools.h>
55 std::string <rim(std::string &s)
57 #if VISP_CXX_STANDARD > VISP_CXX_STANDARD_98
58 s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](
int c) { return !std::isspace(c); }));
60 s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
65 std::string &rtrim(std::string &s)
67 #if VISP_CXX_STANDARD > VISP_CXX_STANDARD_98
68 s.erase(std::find_if(s.rbegin(), s.rend(), [](
int c) { return !std::isspace(c); }).base(), s.end());
70 s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
116 std::ifstream confContent(
configFile.c_str(), std::ios::in);
118 if (confContent.is_open()) {
119 std::string line, var, val;
122 std::string stop[3] = {
" ",
"\t",
"#" };
123 while (std::getline(confContent, line)) {
124 if ((line.compare(0, 1,
"#") != 0) && (line.size() > 2)) {
126 k =
static_cast<unsigned long>(line.find(
" "));
127 var = line.substr(0, k);
130 for (
unsigned i = 0; i < 3; ++i) {
132 static_cast<int>(line.find(stop[i],
static_cast<size_t>(k) +
static_cast<size_t>(1))));
135 c =
static_cast<int>(line.size());
137 unsigned long int c_ =
static_cast<unsigned long int>(c);
138 val = line.substr(
static_cast<size_t>(k) +
static_cast<size_t>(1),
139 static_cast<size_t>(c_) -
static_cast<size_t>(k) -
static_cast<size_t>(1));
165 while ((k < configvars_size) && (!found)) {
168 value =
static_cast<float>(M_PI);
171 value =
static_cast<float>(M_PI / 2.0);
174 value =
static_cast<float>(-M_PI / 2.0);
177 value =
static_cast<float>(atof(
configValues[k].c_str()));
184 std::cout << var <<
" not found in config file" << std::endl;
202 while ((k < configvars_size) && (!found)) {
221 std::cout << var <<
" not found in config file" << std::endl;
239 while ((k < configvars_size) && (!found)) {
247 std::cout << var <<
" not found in config file" << std::endl;
264 value =
static_cast<unsigned int>(v);
313 while ((k < configvars_size) && (!found)) {
321 std::cout << var <<
" not found in config file" << std::endl;
340 const unsigned int &nRows)
346 while ((k < configvars_size) && (!found)) {
350 if ((nCols != 0) && (nRows != 0)) {
351 value.
resize(nRows, nCols);
353 size_t ind = 0, ind2;
354 unsigned int value_rows = value.
getRows();
355 unsigned int value_cols = value.
getCols();
356 for (
unsigned int i = 0; i < value_rows; ++i) {
357 for (
unsigned int j = 0; j < value_cols; ++j) {
360 if (nb.compare(
"PI") == 0) {
363 else if (nb.compare(
"PI/2") == 0) {
364 value[i][j] = M_PI / 2;
366 else if (nb.compare(
"-PI/2") == 0) {
367 value[i][j] = -M_PI / 2;
370 value[i][j] = atof(nb.c_str());
378 if (found ==
false) {
379 std::cout << var <<
" not found in config file" << std::endl;
399 else if (strFalse !=
"") {
415 if (std::fabs(val) < std::numeric_limits<double>::epsilon()) {
416 std::stringstream valS;
419 baseName +=
"_" + strTrue + valS.str();
437 std::cout <<
"Creating directory " <<
path << std::endl;
445 std::cout <<
"Emptying directory " <<
path << std::endl;
471 file.read((
char *)(&short_value),
sizeof(short_value));
473 #ifdef VISP_BIG_ENDIAN
484 file.read((
char *)(&ushort_value),
sizeof(ushort_value));
486 #ifdef VISP_BIG_ENDIAN
497 file.read((
char *)(&int_value),
sizeof(int_value));
499 #ifdef VISP_BIG_ENDIAN
510 file.read((
char *)(&uint_value),
sizeof(uint_value));
512 #ifdef VISP_BIG_ENDIAN
523 file.read((
char *)(&float_value),
sizeof(float_value));
525 #ifdef VISP_BIG_ENDIAN
536 file.read((
char *)(&double_value),
sizeof(double_value));
538 #ifdef VISP_BIG_ENDIAN
549 #ifdef VISP_BIG_ENDIAN
552 file.write((
char *)(&swap_short),
sizeof(swap_short));
554 file.write((
char *)(&short_value),
sizeof(short_value));
563 #ifdef VISP_BIG_ENDIAN
566 file.write((
char *)(&swap_ushort),
sizeof(swap_ushort));
568 file.write((
char *)(&ushort_value),
sizeof(ushort_value));
577 #ifdef VISP_BIG_ENDIAN
580 file.write((
char *)(&swap_int),
sizeof(swap_int));
582 file.write((
char *)(&int_value),
sizeof(int_value));
591 #ifdef VISP_BIG_ENDIAN
594 file.write((
char *)(&swap_int),
sizeof(swap_int));
596 file.write((
char *)(&uint_value),
sizeof(uint_value));
605 #ifdef VISP_BIG_ENDIAN
608 file.write((
char *)(&swap_float),
sizeof(swap_float));
610 file.write((
char *)(&float_value),
sizeof(float_value));
619 #ifdef VISP_BIG_ENDIAN
622 file.write((
char *)(&swap_double),
sizeof(swap_double));
624 file.write((
char *)(&double_value),
sizeof(double_value));
630 std::transform(input.begin(), input.end(), input.begin(), ::tolower);
631 std::istringstream is(input);
635 is >> (input.size() > 1 ? std::boolalpha : std::noboolalpha) >> b;
unsigned int getCols() const
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
unsigned int getRows() const
Class to define RGB colors available for display functionalities.
static vpColor getColor(const unsigned int &i)
error that can be emitted by ViSP classes.
static Type minimum(const Type &a, const Type &b)
VISP_EXPORT float swapFloat(float f)
VISP_EXPORT uint32_t swap32bits(uint32_t val)
VISP_EXPORT double swapDouble(double d)
VISP_EXPORT uint16_t swap16bits(uint16_t val)