29#include <vclib/io/exceptions.h>
31#include <vclib/base.h>
32#include <vclib/mesh.h>
40inline std::ofstream openOutputFileStream(
41 const std::string& filename,
42 const std::string& ext =
"")
44 setlocale(LC_ALL,
"C");
45 std::string actualFileName = filename;
48 if (!path.empty() && !std::filesystem::exists(path)) {
49 bool res = std::filesystem::create_directory(path);
51 throw std::runtime_error(
"Cannot create directory: " + path);
60 fp.imbue(std::locale().classic());
63 fp.open(actualFileName, std::ofstream::binary);
65 throw CannotOpenFileException(actualFileName);
77 FileType format = FileType(),
80 if (isColor && !std::is_integral<T>::value)
84 serialize(file, tmp, format.endian);
86 file << (int) p <<
" ";
93 FileType format = FileType(),
96 if (isColor && !std::is_integral<T>::value)
98 unsigned char tmp = p;
100 serialize(file, tmp, format.endian);
102 file << (uint) p <<
" ";
109 FileType format = FileType(),
110 bool isColor =
false)
112 if (isColor && !std::is_integral<T>::value)
116 serialize(file, tmp, format.endian);
125 FileType format = FileType(),
126 bool isColor =
false)
128 if (isColor && !std::is_integral<T>::value)
130 unsigned short tmp = p;
132 serialize(file, tmp, format.endian);
141 FileType format = FileType(),
142 bool isColor =
false)
144 if (isColor && !std::is_integral<T>::value)
148 serialize(file, tmp, format.endian);
157 FileType format = FileType(),
158 bool isColor =
false)
160 if (isColor && !std::is_integral<T>::value)
164 serialize(file, tmp, format.endian);
173 FileType format = FileType(),
174 bool isColor =
false)
177 if (isColor && std::is_integral<T>::value)
180 serialize(file, tmp, format.endian);
189 FileType format = FileType(),
190 bool isColor =
false)
193 if (isColor && std::is_integral<T>::value)
196 serialize(file, tmp, format.endian);
207 FileType format = FileType(),
208 bool isColor =
false)
211 case PrimitiveType::CHAR: writeChar(file, p, format, isColor);
break;
212 case PrimitiveType::UCHAR: writeUChar(file, p, format, isColor);
break;
213 case PrimitiveType::SHORT: writeShort(file, p, format, isColor);
break;
214 case PrimitiveType::USHORT: writeUShort(file, p, format, isColor);
break;
215 case PrimitiveType::INT: writeInt(file, p, format, isColor);
break;
216 case PrimitiveType::UINT: writeUInt(file, p, format, isColor);
break;
217 case PrimitiveType::FLOAT: writeFloat(file, p, format, isColor);
break;
218 case PrimitiveType::DOUBLE: writeDouble(file, p, format, isColor);
break;
224template<ElementConcept El>
225void writeCustomComponent(
228 const std::string& cName,
230 FileType format = FileType())
232 std::type_index ti = elem.customComponentType(cName);
233 if (ti ==
typeid(
char))
235 file, elem.template customComponent<char>(cName), type, format);
236 else if (ti ==
typeid(
unsigned char))
239 elem.template customComponent<unsigned char>(cName),
242 else if (ti ==
typeid(
short))
244 file, elem.template customComponent<short>(cName), type, format);
245 else if (ti ==
typeid(
unsigned short))
248 elem.template customComponent<unsigned short>(cName),
251 else if (ti ==
typeid(
int))
253 file, elem.template customComponent<int>(cName), type, format);
254 else if (ti ==
typeid(
unsigned int))
256 file, elem.template customComponent<uint>(cName), type, format);
257 else if (ti ==
typeid(
float))
259 file, elem.template customComponent<float>(cName), type, format);
260 else if (ti ==
typeid(
double))
262 file, elem.template customComponent<double>(cName), type, format);
static std::string addExtensionIfNeeded(const std::string &filename, const std::string &ext)
Adds an extension to a file name if it doesn't already have it.
Definition file_info.h:292
static std::string pathWithoutFileName(const std::string &fullpath)
Get the path of a file.
Definition file_info.h:200
PrimitiveType
A simple type that enumerates the main primitive types.
Definition base.h:58