Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpIoTools.h
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * See the file LICENSE.txt at the root directory of this source
10 * distribution for additional information about the GNU GPL.
11 *
12 * For using ViSP with software that can not be combined with the GNU
13 * GPL, please contact Inria about acquiring a ViSP Professional
14 * Edition License.
15 *
16 * See https://visp.inria.fr for more information.
17 *
18 * This software was developed at:
19 * Inria Rennes - Bretagne Atlantique
20 * Campus Universitaire de Beaulieu
21 * 35042 Rennes Cedex
22 * France
23 *
24 * If you have questions regarding the use of this file, please contact
25 * Inria at visp@inria.fr
26 *
27 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29 *
30 * Description:
31 * Directory management.
32 */
33
38
39#ifndef VP_IO_TOOLS_H
40#define VP_IO_TOOLS_H
41
42#include <visp3/core/vpConfig.h>
43
44#include <iostream>
45#include <sstream>
46#include <stdint.h> //for uint32_t related types ; works also with >= VS2010 / _MSC_VER >= 1600
47#include <stdlib.h>
48#include <string>
49#include <vector>
50#include <numeric>
51#include <visp3/core/vpColor.h>
52#include <visp3/core/vpEndian.h>
53
54#include <memory>
55#include <map>
56#include <cassert>
57#include <complex>
58
59#if VISP_CXX_STANDARD > VISP_CXX_STANDARD_98
60
61namespace visp
62{
63#ifndef DOXYGEN_SHOULD_SKIP_THIS
64// https://github.com/BinomialLLC/basis_universal/blob/ad9386a4a1cf2a248f7bbd45f543a7448db15267/encoder/basisu_miniz.h#L665
65static inline unsigned long vp_mz_crc32(unsigned long crc, const unsigned char *ptr, size_t buf_len)
66{
67 static const unsigned int s_crc32[16] = { 0, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
68 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c };
69 unsigned int crcu32 = static_cast<unsigned int>(crc);
70 if (!ptr) return 0;
71 crcu32 = ~crcu32;
72 while (buf_len--) {
73 unsigned char b = *ptr++;
74 crcu32 = (crcu32 >> 4) ^ s_crc32[(crcu32 & 0xF) ^ (b & 0xF)];
75 crcu32 = (crcu32 >> 4) ^ s_crc32[(crcu32 & 0xF) ^ (b >> 4)];
76 }
77 return ~crcu32;
78}
79#endif // DOXYGEN_SHOULD_SKIP_THIS
80
81#if defined(VISP_HAVE_MINIZ) && defined(VISP_HAVE_WORKING_REGEX)
93namespace cnpy
94{
95// Copyright (C) 2011 Carl Rogers
96// Released under MIT License
97// license available in LICENSE file, or at http://www.opensource.org/licenses/mit-license.php
99{
100 NpyArray(const std::vector<size_t> &_shape, size_t _word_size, bool _fortran_order, char _data_type) :
101 shape(_shape), word_size(_word_size), fortran_order(_fortran_order), data_type(_data_type)
102 {
103 num_vals = 1;
104 for (size_t i = 0; i < shape.size(); ++i) num_vals *= shape[i];
105 data_holder = std::shared_ptr<std::vector<char> >(
106 new std::vector<char>(num_vals * word_size));
107 }
108
110
111 template<typename T>
112 T *data()
113 {
114 return reinterpret_cast<T *>(&(*data_holder)[0]);
115 }
116
117 template<typename T>
118 const T *data() const
119 {
120 return reinterpret_cast<T *>(&(*data_holder)[0]);
121 }
122
123 template<typename T>
124 std::vector<T> as_vec() const
125 {
126 const T *p = data<T>();
127 if (data_type == 'U') {
128 if (!std::is_same<T, char>::value) {
129 throw std::runtime_error("NpyArray.as_vec(): datatype contains string data but as_vec() is not templated as <char>");
130 }
131 return std::vector<T>(p, p+(num_vals*word_size));
132 }
133 else {
134 return std::vector<T>(p, p+num_vals);
135 }
136 }
137
138 std::vector<std::string> as_utf8_string_vec() const
139 {
140 if (data_type != 'U') {
141 throw std::runtime_error("NpyArray.as_utf8_string_vec(): not a string data");
142 }
143
144 std::vector<std::string> vec_string;
145 vec_string.reserve(num_vals);
146
147 for (size_t i = 0; i < num_vals; i++) {
148 std::string str;
149
150 for (size_t idx = i*word_size; idx < (i+1)*word_size; idx += 4) {
151 if ((*data_holder)[idx] == 0) {
152 // \0 char
153 break;
154 }
155 str += (*data_holder)[idx];
156 }
157
158 vec_string.push_back(str);
159 }
160
161 return vec_string;
162 }
163
164 size_t num_bytes() const
165 {
166 return data_holder->size();
167 }
168
169 std::shared_ptr<std::vector<char> > data_holder;
170 std::vector<size_t> shape;
171 size_t word_size;
173 size_t num_vals;
175};
176
177using npz_t = std::map<std::string, NpyArray>;
178VISP_EXPORT npz_t npz_load(const std::string &fname);
179VISP_EXPORT char BigEndianTest();
180VISP_EXPORT char map_type(const std::type_info &t);
181template<typename T> std::vector<char> create_npy_header(const std::vector<size_t> &shape);
182VISP_EXPORT void parse_npy_header(FILE *fp, size_t &word_size, std::vector<size_t> &shape, bool &fortran_order, bool &little_endian, char &data_type);
183VISP_EXPORT void parse_npy_header(unsigned char *buffer, size_t &word_size, std::vector<size_t> &shape, bool &fortran_order, bool &little_endian, char &data_type);
184VISP_EXPORT void parse_zip_footer(FILE *fp, uint16_t &nrecs, size_t &global_header_size, size_t &global_header_offset);
185VISP_EXPORT NpyArray npz_load(const std::string &fname, const std::string &varname);
186VISP_EXPORT NpyArray npy_load(const std::string &fname);
187// Dedicated functions for saving std::string data
188VISP_EXPORT void npz_save(const std::string &zipname, std::string fname, const std::vector<std::string> &data_vec, const std::vector<size_t> &shape, const std::string &mode = "w");
189VISP_EXPORT void npz_save(const std::string &zipname, const std::string &fname, const std::string &data, const std::string &mode = "w");
190
191template<typename T> std::vector<char> &operator+=(std::vector<char> &lhs, const T rhs)
192{
193 //write in little endian
194 for (size_t byte = 0; byte < sizeof(T); ++byte) {
195 char val = *((char *)&rhs+byte);
196 lhs.push_back(val);
197 }
198 return lhs;
199}
200
201template<> inline std::vector<char> &operator+=(std::vector<char> &lhs, const std::string rhs)
202{
203 lhs.insert(lhs.end(), rhs.begin(), rhs.end());
204 return lhs;
205}
206
207template<> inline std::vector<char> &operator+=(std::vector<char> &lhs, const char *rhs)
208{
209 //write in little endian
210 size_t len = strlen(rhs);
211 lhs.reserve(len);
212 for (size_t byte = 0; byte < len; ++byte) {
213 lhs.push_back(rhs[byte]);
214 }
215 return lhs;
216}
217
228template<typename T> void npy_save(const std::string &fname, const T *data, const std::vector<size_t> &shape, const std::string &mode = "w")
229{
230 FILE *fp = NULL;
231 std::vector<size_t> true_data_shape; //if appending, the shape of existing + new data
232
233 if (mode == "a") fp = fopen(fname.c_str(), "r+b");
234
235 if (fp) {
236 //file exists. we need to append to it. read the header, modify the array size
237 size_t word_size;
238 bool fortran_order, little_endian;
239 char data_type = 'i';
240 parse_npy_header(fp, word_size, true_data_shape, fortran_order, little_endian, data_type);
241 assert(!fortran_order);
242
243 if (word_size != sizeof(T)) {
244 std::cerr << "libnpy error: " << fname << " has word size " << word_size << " but npy_save appending data sized " << sizeof(T) << "\n";
245 assert(word_size == sizeof(T));
246 }
247 if (true_data_shape.size() != shape.size()) {
248 std::cerr << "libnpy error: npy_save attempting to append misdimensioned data to " << fname << "\n";
249 assert(true_data_shape.size() != shape.size());
250 }
251
252 for (size_t i = 1; i < shape.size(); ++i) {
253 if (shape[i] != true_data_shape[i]) {
254 std::cerr << "libnpy error: npy_save attempting to append misshaped data to " << fname << "\n";
255 assert(shape[i] == true_data_shape[i]);
256 }
257 }
258 true_data_shape[0] += shape[0];
259 }
260 else {
261 fp = fopen(fname.c_str(), "wb");
262 true_data_shape = shape;
263 }
264
265 std::vector<char> header = create_npy_header<T>(true_data_shape);
266 // https://github.com/rogersce/cnpy/pull/58/files
267 size_t nels = std::accumulate(shape.begin(), shape.end(), static_cast<size_t>(1), std::multiplies<size_t>());
268
269 fseek(fp, 0, SEEK_SET);
270 fwrite(&header[0], sizeof(char), header.size(), fp);
271 fseek(fp, 0, SEEK_END);
272 if (data != nullptr) {
273 fwrite(&data[0], sizeof(T), nels, fp);
274 }
275 fclose(fp);
276}
277
291template<typename T> void npz_save(const std::string &zipname, std::string fname, const T *data, const std::vector<size_t> &shape, const std::string &mode = "w")
292{
293 //first, append a .npy to the fname
294 fname += ".npy";
295
296 //now, on with the show
297 FILE *fp = NULL;
298 uint16_t nrecs = 0;
299 size_t global_header_offset = 0;
300 std::vector<char> global_header;
301
302 if (mode == "a") fp = fopen(zipname.c_str(), "r+b");
303
304 if (fp) {
305 //zip file exists. we need to add a new npy file to it.
306 //first read the footer. this gives us the offset and size of the global header
307 //then read and store the global header.
308 //below, we will write the the new data at the start of the global header then append the global header and footer below it
309 size_t global_header_size;
310 parse_zip_footer(fp, nrecs, global_header_size, global_header_offset);
311 fseek(fp, static_cast<long>(global_header_offset), SEEK_SET);
312 global_header.resize(global_header_size);
313 size_t res = fread(&global_header[0], sizeof(char), global_header_size, fp);
314 if (res != global_header_size) {
315 throw std::runtime_error("npz_save: header read error while adding to existing zip");
316 }
317 fseek(fp, static_cast<long>(global_header_offset), SEEK_SET);
318 }
319 else {
320 fp = fopen(zipname.c_str(), "wb");
321 }
322
323 std::vector<char> npy_header = create_npy_header<T>(shape);
324
325 // https://github.com/rogersce/cnpy/pull/58/files
326 size_t nels = std::accumulate(shape.begin(), shape.end(), static_cast<size_t>(1), std::multiplies<size_t>());
327 size_t nbytes = nels*sizeof(T) + npy_header.size();
328
329 //get the CRC of the data to be added
330 uint32_t crc = vp_mz_crc32(0L, (uint8_t *)&npy_header[0], npy_header.size());
331 if (nels > 0) {
332 crc = vp_mz_crc32(crc, (uint8_t *)data, nels*sizeof(T));
333 }
334
335 //build the local header
336 std::vector<char> local_header;
337 local_header += "PK"; //first part of sig
338#ifdef VISP_BIG_ENDIAN
339 local_header += vpEndian::swap16bits(static_cast<uint16_t>(0x0403)); //second part of sig
340 local_header += vpEndian::swap16bits(static_cast<uint16_t>(20)); //min version to extract
341 local_header += vpEndian::swap16bits(static_cast<uint16_t>(0)); //general purpose bit flag
342 local_header += vpEndian::swap16bits(static_cast<uint16_t>(0)); //compression method
343 local_header += vpEndian::swap16bits(static_cast<uint16_t>(0)); //file last mod time
344 local_header += vpEndian::swap16bits(static_cast<uint16_t>(0)); //file last mod date
345 local_header += vpEndian::swap32bits(static_cast<uint32_t>(crc)); //crc
346 local_header += vpEndian::swap32bits(static_cast<uint32_t>(nbytes)); //compressed size
347 local_header += vpEndian::swap32bits(static_cast<uint32_t>(nbytes)); //uncompressed size
348 local_header += vpEndian::swap16bits(static_cast<uint16_t>(fname.size())); //fname length
349 local_header += vpEndian::swap16bits(static_cast<uint16_t>(0)); //extra field length
350#else
351 local_header += static_cast<uint16_t>(0x0403); //second part of sig
352 local_header += static_cast<uint16_t>(20); //min version to extract
353 local_header += static_cast<uint16_t>(0); //general purpose bit flag
354 local_header += static_cast<uint16_t>(0); //compression method
355 local_header += static_cast<uint16_t>(0); //file last mod time
356 local_header += static_cast<uint16_t>(0); //file last mod date
357 local_header += static_cast<uint32_t>(crc); //crc
358 local_header += static_cast<uint32_t>(nbytes); //compressed size
359 local_header += static_cast<uint32_t>(nbytes); //uncompressed size
360 local_header += static_cast<uint16_t>(fname.size()); //fname length
361 local_header += static_cast<uint16_t>(0); //extra field length
362#endif
363 local_header += fname;
364
365 //build global header
366 global_header += "PK"; //first part of sig
367#ifdef VISP_BIG_ENDIAN
368 global_header += vpEndian::swap16bits(static_cast<uint16_t>(0x0201)); //second part of sig
369 global_header += vpEndian::swap16bits(static_cast<uint16_t>(20)); //version made by
370 global_header.insert(global_header.end(), local_header.begin()+4, local_header.begin()+30);
371 global_header += static_cast<uint16_t>(0); //file comment length
372 global_header += static_cast<uint16_t>(0); //disk number where file starts
373 global_header += static_cast<uint16_t>(0); //internal file attributes
374 global_header += static_cast<uint32_t>(0); //external file attributes
375 global_header += vpEndian::swap32bits(static_cast<uint32_t>(global_header_offset)); //relative offset of local file header, since it begins where the global header used to begin
376#else
377 global_header += static_cast<uint16_t>(0x0201); //second part of sig
378 global_header += static_cast<uint16_t>(20); //version made by
379 global_header.insert(global_header.end(), local_header.begin()+4, local_header.begin()+30);
380 global_header += static_cast<uint16_t>(0); //file comment length
381 global_header += static_cast<uint16_t>(0); //disk number where file starts
382 global_header += static_cast<uint16_t>(0); //internal file attributes
383 global_header += static_cast<uint32_t>(0); //external file attributes
384 global_header += static_cast<uint32_t>(global_header_offset); //relative offset of local file header, since it begins where the global header used to begin
385#endif
386 global_header += fname;
387
388 //build footer
389 std::vector<char> footer;
390 footer += "PK"; //first part of sig
391#ifdef VISP_BIG_ENDIAN
392 footer += vpEndian::swap16bits(static_cast<uint16_t>(0x0605)); //second part of sig
393 footer += static_cast<uint16_t>(0); //number of this disk
394 footer += static_cast<uint16_t>(0); //disk where footer starts
395 footer += vpEndian::swap16bits(static_cast<uint16_t>(nrecs+1)); //number of records on this disk
396 footer += vpEndian::swap16bits(static_cast<uint16_t>(nrecs+1)); //total number of records
397 footer += vpEndian::swap32bits(static_cast<uint32_t>(global_header.size())); //nbytes of global headers
398 footer += vpEndian::swap32bits(static_cast<uint32_t>(global_header_offset + nbytes + local_header.size())); //offset of start of global headers, since global header now starts after newly written array
399#else
400 footer += static_cast<uint16_t>(0x0605); //second part of sig
401 footer += static_cast<uint16_t>(0); //number of this disk
402 footer += static_cast<uint16_t>(0); //disk where footer starts
403 footer += static_cast<uint16_t>(nrecs+1); //number of records on this disk
404 footer += static_cast<uint16_t>(nrecs+1); //total number of records
405 footer += static_cast<uint32_t>(global_header.size()); //nbytes of global headers
406 footer += static_cast<uint32_t>(global_header_offset + nbytes + local_header.size()); //offset of start of global headers, since global header now starts after newly written array
407#endif
408 footer += static_cast<uint16_t>(0); //zip file comment length
409
410 //write everything
411 fwrite(&local_header[0], sizeof(char), local_header.size(), fp);
412 fwrite(&npy_header[0], sizeof(char), npy_header.size(), fp);
413 if (data != nullptr) {
414 fwrite(&data[0], sizeof(T), nels, fp);
415 }
416 fwrite(&global_header[0], sizeof(char), global_header.size(), fp);
417 fwrite(&footer[0], sizeof(char), footer.size(), fp);
418 fclose(fp);
419}
420
430template<typename T> void npy_save(const std::string &fname, const std::vector<T> &data, const std::string &mode = "w")
431{
432 std::vector<size_t> shape;
433 shape.push_back(data.size());
434 npy_save(fname, &data[0], shape, mode);
435}
436
449template<typename T> void npz_save(const std::string &zipname, const std::string &fname, const std::vector<T> &data, const std::string &mode = "w")
450{
451 std::vector<size_t> shape;
452 shape.push_back(data.size());
453 npz_save(zipname, fname, &data[0], shape, mode);
454}
455
456template<typename T> std::vector<char> create_npy_header(const std::vector<size_t> &shape)
457{
458 std::vector<char> dict;
459 dict += "{'descr': '";
460 dict += BigEndianTest();
461 dict += map_type(typeid(T));
462 dict += std::to_string(sizeof(T));
463 dict += "', 'fortran_order': False, 'shape': (";
464 dict += std::to_string(shape[0]);
465 for (size_t i = 1; i < shape.size(); ++i) {
466 dict += ", ";
467 dict += std::to_string(shape[i]);
468 }
469 if (shape.size() == 1) dict += ",";
470 dict += "), }";
471 //pad with spaces so that preamble+dict is modulo 16 bytes. preamble is 10 bytes. dict needs to end with \n
472 int remainder = 16 - (10 + dict.size()) % 16;
473 dict.insert(dict.end(), remainder, ' ');
474 dict.back() = '\n';
475
476 std::vector<char> header;
477 header += static_cast<char>(0x93);
478 header += "NUMPY";
479 header += static_cast<char>(0x01); //major version of numpy format
480 header += static_cast<char>(0x00); //minor version of numpy format
481#ifdef VISP_BIG_ENDIAN
482 header += vpEndian::swap16bits(static_cast<uint16_t>(dict.size()));
483#else
484 header += static_cast<uint16_t>(dict.size());
485#endif
486 header.insert(header.end(), dict.begin(), dict.end());
487
488 return header;
489}
490
491} // namespace cnpy
492#endif
493} // namespace VISP_NAMESPACE_NAME
494#endif
495
604class VISP_EXPORT vpIoTools
605{
606public:
607 static const std::string &getBuildInformation();
608 static std::string getTempPath();
609 static void getUserName(std::string &username);
610 static std::string getUserName();
611 static std::string getenv(const std::string &env);
612 static std::string getViSPImagesDataPath();
613 static void getVersion(const std::string &version, unsigned int &major, unsigned int &minor, unsigned int &patch);
614 static bool checkDirectory(const std::string &dirname);
615 static bool checkFifo(const std::string &filename);
616 static bool checkFilename(const std::string &filename);
617 static bool copy(const std::string &src, const std::string &dst);
618 static std::string formatString(const std::string &name, unsigned int val);
619
620 static void makeDirectory(const std::string &dirname);
621 static void makeFifo(const std::string &dirname);
622 static std::string makeTempDirectory(const std::string &dirname);
623 static std::string path(const std::string &pathname);
624
625 static bool remove(const std::string &filename);
626 static bool rename(const std::string &oldfilename, const std::string &newfilename);
627
632 static const char separator;
633
634 static std::string toUpperCase(const std::string &input);
635 static std::string toLowerCase(const std::string &input);
636
637 static std::string getAbsolutePathname(const std::string &pathname);
638 static std::string getFileExtension(const std::string &pathname, bool checkFile = false);
639 static long getIndex(const std::string &filename, const std::string &format);
640 static std::string getName(const std::string &pathname);
641 static std::string getNameWE(const std::string &pathname);
642 static std::string getParent(const std::string &pathname);
643 static std::string createFilePath(const std::string &parent, const std::string &child);
644 static bool isAbsolutePathname(const std::string &pathname);
645 static bool isSamePathname(const std::string &pathname1, const std::string &pathname2);
646 static std::pair<std::string, std::string> splitDrive(const std::string &pathname);
647 static std::vector<std::string> splitChain(const std::string &chain, const std::string &sep);
648 static std::vector<std::string> getDirFiles(const std::string &dirname);
649
654 // read configuration file
655 static bool loadConfigFile(const std::string &confFile);
656 static bool readConfigVar(const std::string &var, float &value);
657 static bool readConfigVar(const std::string &var, double &value);
658 static bool readConfigVar(const std::string &var, int &value);
659 static bool readConfigVar(const std::string &var, unsigned int &value);
660 static bool readConfigVar(const std::string &var, bool &value);
661 static bool readConfigVar(const std::string &var, std::string &value);
662 static bool readConfigVar(const std::string &var, vpColor &value);
663 static bool readConfigVar(const std::string &var, vpArray2D<double> &value, const unsigned int &nCols = 0,
664 const unsigned int &nRows = 0);
665
666 // construct experiment filename & path
667 static void setBaseName(const std::string &s);
668 static void setBaseDir(const std::string &dir);
669 static void addNameElement(const std::string &strTrue, const bool &cond = true, const std::string &strFalse = "");
670 static void addNameElement(const std::string &strTrue, const double &val);
671 static std::string getBaseName();
672 static std::string getFullName();
673
674 // write files
675 static void saveConfigFile(const bool &actuallySave = true);
676 static void createBaseNamePath(const bool &empty = false);
678
679 static void readBinaryValueLE(std::ifstream &file, int16_t &short_value);
680 static void readBinaryValueLE(std::ifstream &file, uint16_t &ushort_value);
681 static void readBinaryValueLE(std::ifstream &file, int32_t &int_value);
682 static void readBinaryValueLE(std::ifstream &file, uint32_t &int_value);
683 static void readBinaryValueLE(std::ifstream &file, float &float_value);
684 static void readBinaryValueLE(std::ifstream &file, double &double_value);
685
686 static void writeBinaryValueLE(std::ofstream &file, const int16_t short_value);
687 static void writeBinaryValueLE(std::ofstream &file, const uint16_t ushort_value);
688 static void writeBinaryValueLE(std::ofstream &file, const int32_t int_value);
689 static void writeBinaryValueLE(std::ofstream &file, const uint32_t int_value);
690 static void writeBinaryValueLE(std::ofstream &file, float float_value);
691 static void writeBinaryValueLE(std::ofstream &file, double double_value);
692
693 static bool parseBoolean(std::string input);
694 static std::string trim(std::string s);
695
696protected:
697 static std::string baseName;
698 static std::string baseDir;
699 static std::string configFile;
700 static std::vector<std::string> configVars;
701 static std::vector<std::string> configValues;
702
703#ifndef DOXYGEN_SHOULD_SKIP_THIS
704 static int mkdir_p(const std::string &path, int mode);
705#endif
706};
707END_VISP_NAMESPACE
708#endif
Implementation of a generic 2D array used as base class for matrices and vectors.
Definition vpArray2D.h:146
Class to define RGB colors available for display functionalities.
Definition vpColor.h:157
File and directories basic tools.
Definition vpIoTools.h:605
static std::string configFile
Definition vpIoTools.h:699
static void getVersion(const std::string &version, unsigned int &major, unsigned int &minor, unsigned int &patch)
static std::string getViSPImagesDataPath()
static std::vector< std::string > splitChain(const std::string &chain, const std::string &sep)
static std::string path(const std::string &pathname)
static std::string getAbsolutePathname(const std::string &pathname)
static std::string toLowerCase(const std::string &input)
Return a lower-case version of the string input . Numbers and special characters stay the same.
static bool checkFilename(const std::string &filename)
static bool readConfigVar(const std::string &var, float &value)
static void setBaseName(const std::string &s)
static std::pair< std::string, std::string > splitDrive(const std::string &pathname)
static void getUserName(std::string &username)
static bool isSamePathname(const std::string &pathname1, const std::string &pathname2)
static std::string getTempPath()
static bool isAbsolutePathname(const std::string &pathname)
static void setBaseDir(const std::string &dir)
static bool loadConfigFile(const std::string &confFile)
static bool copy(const std::string &src, const std::string &dst)
static std::string trim(std::string s)
static void readBinaryValueLE(std::ifstream &file, int16_t &short_value)
static void saveConfigFile(const bool &actuallySave=true)
static bool checkDirectory(const std::string &dirname)
static std::vector< std::string > configVars
Definition vpIoTools.h:700
static std::string formatString(const std::string &name, unsigned int val)
static bool rename(const std::string &oldfilename, const std::string &newfilename)
static bool parseBoolean(std::string input)
static long getIndex(const std::string &filename, const std::string &format)
static std::string getFullName()
static void addNameElement(const std::string &strTrue, const bool &cond=true, const std::string &strFalse="")
static std::string createFilePath(const std::string &parent, const std::string &child)
static std::string getenv(const std::string &env)
static std::string getBaseName()
static std::string getFileExtension(const std::string &pathname, bool checkFile=false)
static void createBaseNamePath(const bool &empty=false)
static std::vector< std::string > getDirFiles(const std::string &dirname)
static void makeDirectory(const std::string &dirname)
static void writeBinaryValueLE(std::ofstream &file, const int16_t short_value)
static bool remove(const std::string &filename)
static const std::string & getBuildInformation()
static std::string getNameWE(const std::string &pathname)
static std::string makeTempDirectory(const std::string &dirname)
static bool checkFifo(const std::string &filename)
static std::string getParent(const std::string &pathname)
static std::vector< std::string > configValues
Definition vpIoTools.h:701
static std::string getName(const std::string &pathname)
static std::string baseDir
Definition vpIoTools.h:698
static std::string toUpperCase(const std::string &input)
Return a upper-case version of the string input . Numbers and special characters stay the same.
static const char separator
Definition vpIoTools.h:632
static std::string baseName
Definition vpIoTools.h:697
static void makeFifo(const std::string &dirname)
Helpers to convert NPY/NPZ format to/from ViSP format.
Definition vpIoTools.h:94
VISP_EXPORT npz_t npz_load(const std::string &fname)
VISP_EXPORT char map_type(const std::type_info &t)
std::map< std::string, NpyArray > npz_t
Definition vpIoTools.h:177
std::vector< char > create_npy_header(const std::vector< size_t > &shape)
Definition vpIoTools.h:456
std::vector< char > & operator+=(std::vector< char > &lhs, const T rhs)
Definition vpIoTools.h:191
VISP_EXPORT NpyArray npy_load(const std::string &fname)
VISP_EXPORT void parse_zip_footer(FILE *fp, uint16_t &nrecs, size_t &global_header_size, size_t &global_header_offset)
VISP_EXPORT void npz_save(const std::string &zipname, std::string fname, const std::vector< std::string > &data_vec, const std::vector< size_t > &shape, const std::string &mode="w")
void npy_save(const std::string &fname, const T *data, const std::vector< size_t > &shape, const std::string &mode="w")
Definition vpIoTools.h:228
VISP_EXPORT char BigEndianTest()
VISP_EXPORT void parse_npy_header(FILE *fp, size_t &word_size, std::vector< size_t > &shape, bool &fortran_order, bool &little_endian, char &data_type)
VISP_EXPORT uint32_t swap32bits(uint32_t val)
Definition vpEndian.cpp:60
VISP_EXPORT uint16_t swap16bits(uint16_t val)
Definition vpEndian.cpp:48
std::shared_ptr< std::vector< char > > data_holder
Definition vpIoTools.h:169
size_t num_bytes() const
Definition vpIoTools.h:164
std::vector< size_t > shape
Definition vpIoTools.h:170
std::vector< T > as_vec() const
Definition vpIoTools.h:124
const T * data() const
Definition vpIoTools.h:118
NpyArray(const std::vector< size_t > &_shape, size_t _word_size, bool _fortran_order, char _data_type)
Definition vpIoTools.h:100
std::vector< std::string > as_utf8_string_vec() const
Definition vpIoTools.h:138