Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ioutil.cpp « fileio « preprocessed « mantaflow « extern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 409760b0a0f39081e5dc81d4d7b8e049033ceed3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124


// DO NOT EDIT !
// This file is generated using the MantaFlow preprocessor (prep generate).

/******************************************************************************
 *
 * MantaFlow fluid solver framework
 * Copyright 2011-2020 Tobias Pfaff, Nils Thuerey
 *
 * This program is free software, distributed under the terms of the
 * Apache License, Version 2.0
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Helper functions to handle file IO
 *
 ******************************************************************************/

#include "mantaio.h"

#if OPENVDB == 1
#  include "openvdb/openvdb.h"
#endif

#if NO_ZLIB != 1
extern "C" {
#  include <zlib.h>
}
#endif

#if defined(WIN32) || defined(_WIN32)
#  include <windows.h>
#  include <string>
#endif

using namespace std;

namespace Manta {

#if defined(WIN32) || defined(_WIN32)
static wstring stringToWstring(const char *str)
{
  const int length_wc = MultiByteToWideChar(CP_UTF8, 0, str, strlen(str), nullptr, 0);
  wstring strWide(length_wc, 0);
  MultiByteToWideChar(CP_UTF8, 0, str, strlen(str), &strWide[0], length_wc);
  return strWide;
}
#endif  // WIN32==1

void *safeGzopen(const char *filename, const char *mode)
{
#if NO_ZLIB != 1
  gzFile gzfile;

#  if defined(WIN32) || defined(_WIN32)
  wstring filenameWide = stringToWstring(filename);
  gzfile = gzopen_w(filenameWide.c_str(), mode);
#  else
  gzfile = gzopen(filename, mode);
#  endif

  return gzfile;
#else
  debMsg("safeGzopen not supported without zlib", 1);
  return nullptr;
#endif  // NO_ZLIB != 1
}

#if OPENVDB == 1
// Convert from OpenVDB value to Manta value.
template<class S, class T> void convertFrom(S &in, T *out)
{
  errMsg("OpenVDB convertFrom Warning: Unsupported type conversion");
}

template<> void convertFrom(int &in, int *out)
{
  (*out) = in;
}

template<> void convertFrom(float &in, Real *out)
{
  (*out) = (Real)in;
}

template<> void convertFrom(openvdb::Vec3s &in, Vec3 *out)
{
  (*out).x = in.x();
  (*out).y = in.y();
  (*out).z = in.z();
}

template<> void convertFrom(openvdb::Vec3i &in, Vec3i *out)
{
  (*out).x = in.x();
  (*out).y = in.y();
  (*out).z = in.z();
}

// Convert to OpenVDB value from Manta value.
template<class S, class T> void convertTo(S *out, T &in)
{
  errMsg("OpenVDB convertTo Warning: Unsupported type conversion");
}

template<> void convertTo(int *out, int &in)
{
  (*out) = in;
}

template<> void convertTo(float *out, Real &in)
{
  (*out) = (float)in;
}

template<> void convertTo(openvdb::Vec3s *out, Vec3 &in)
{
  (*out).x() = in.x;
  (*out).y() = in.y;
  (*out).z() = in.z;
}
#endif  // OPENVDB==1

}  // namespace Manta