1
2
3 // DO NOT EDIT !
4 // This file is generated using the MantaFlow preprocessor (prep generate).
5
6 /******************************************************************************
7 *
8 * MantaFlow fluid solver framework
9 * Copyright 2011-2020 Tobias Pfaff, Nils Thuerey
10 *
11 * This program is free software, distributed under the terms of the
12 * Apache License, Version 2.0
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Helper functions to handle file IO
16 *
17 ******************************************************************************/
18
19 #include "mantaio.h"
20
21 #if OPENVDB == 1
22 # include "openvdb/openvdb.h"
23 #endif
24
25 #if NO_ZLIB != 1
26 extern "C" {
27 # include <zlib.h>
28 }
29 #endif
30
31 #if defined(WIN32) || defined(_WIN32)
32 # include <windows.h>
33 # include <string>
34 #endif
35
36 using namespace std;
37
38 namespace Manta {
39
40 #if defined(WIN32) || defined(_WIN32)
stringToWstring(const char * str)41 static wstring stringToWstring(const char *str)
42 {
43 const int length_wc = MultiByteToWideChar(CP_UTF8, 0, str, strlen(str), NULL, 0);
44 wstring strWide(length_wc, 0);
45 MultiByteToWideChar(CP_UTF8, 0, str, strlen(str), &strWide[0], length_wc);
46 return strWide;
47 }
48 #endif // WIN32==1
49
safeGzopen(const char * filename,const char * mode)50 void *safeGzopen(const char *filename, const char *mode)
51 {
52 #if NO_ZLIB != 1
53 gzFile gzfile;
54
55 # if defined(WIN32) || defined(_WIN32)
56 wstring filenameWide = stringToWstring(filename);
57 gzfile = gzopen_w(filenameWide.c_str(), mode);
58 # else
59 gzfile = gzopen(filename, mode);
60 # endif
61
62 return gzfile;
63 #else
64 debMsg("safeGzopen not supported without zlib", 1);
65 return nullptr;
66 #endif // NO_ZLIB != 1
67 }
68
69 #if defined(OPENVDB)
70 // Convert from OpenVDB value to Manta value.
convertFrom(S & in,T * out)71 template<class S, class T> void convertFrom(S &in, T *out)
72 {
73 errMsg("OpenVDB convertFrom Warning: Unsupported type conversion");
74 }
75
convertFrom(int & in,int * out)76 template<> void convertFrom(int &in, int *out)
77 {
78 (*out) = in;
79 }
80
convertFrom(float & in,Real * out)81 template<> void convertFrom(float &in, Real *out)
82 {
83 (*out) = (Real)in;
84 }
85
convertFrom(openvdb::Vec3s & in,Vec3 * out)86 template<> void convertFrom(openvdb::Vec3s &in, Vec3 *out)
87 {
88 (*out).x = in.x();
89 (*out).y = in.y();
90 (*out).z = in.z();
91 }
92
93 // Convert to OpenVDB value from Manta value.
convertTo(S * out,T & in)94 template<class S, class T> void convertTo(S *out, T &in)
95 {
96 errMsg("OpenVDB convertTo Warning: Unsupported type conversion");
97 }
98
convertTo(int * out,int & in)99 template<> void convertTo(int *out, int &in)
100 {
101 (*out) = in;
102 }
103
convertTo(float * out,Real & in)104 template<> void convertTo(float *out, Real &in)
105 {
106 (*out) = (float)in;
107 }
108
convertTo(openvdb::Vec3s * out,Vec3 & in)109 template<> void convertTo(openvdb::Vec3s *out, Vec3 &in)
110 {
111 (*out).x() = in.x;
112 (*out).y() = in.y;
113 (*out).z() = in.z;
114 }
115 #endif // OPENVDB==1
116
117 } // namespace Manta
118