2020-02-19 18:58:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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"
|
|
|
|
|
|
2020-06-24 12:00:13 +02:00
|
|
|
#if OPENVDB == 1
|
|
|
|
|
# include "openvdb/openvdb.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-02-19 18:58:09 +01:00
|
|
|
#if NO_ZLIB != 1
|
|
|
|
|
extern "C" {
|
|
|
|
|
# include <zlib.h>
|
|
|
|
|
}
|
2020-07-17 15:58:13 +02:00
|
|
|
#endif
|
2020-02-19 18:58:09 +01:00
|
|
|
|
2020-07-17 15:58:13 +02:00
|
|
|
#if defined(WIN32) || defined(_WIN32)
|
|
|
|
|
# include <windows.h>
|
|
|
|
|
# include <string>
|
|
|
|
|
#endif
|
2020-02-21 15:29:32 +01:00
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
2020-02-19 18:58:09 +01:00
|
|
|
namespace Manta {
|
|
|
|
|
|
2020-07-17 15:58:13 +02:00
|
|
|
#if defined(WIN32) || defined(_WIN32)
|
2020-02-21 15:29:32 +01:00
|
|
|
static wstring stringToWstring(const char *str)
|
|
|
|
|
{
|
|
|
|
|
const int length_wc = MultiByteToWideChar(CP_UTF8, 0, str, strlen(str), NULL, 0);
|
|
|
|
|
wstring strWide(length_wc, 0);
|
|
|
|
|
MultiByteToWideChar(CP_UTF8, 0, str, strlen(str), &strWide[0], length_wc);
|
|
|
|
|
return strWide;
|
|
|
|
|
}
|
2020-07-17 15:58:13 +02:00
|
|
|
#endif // WIN32==1
|
2020-02-21 15:29:32 +01:00
|
|
|
|
2020-02-19 18:58:09 +01:00
|
|
|
void *safeGzopen(const char *filename, const char *mode)
|
|
|
|
|
{
|
2020-07-17 15:58:13 +02:00
|
|
|
#if NO_ZLIB != 1
|
2020-02-19 18:58:09 +01:00
|
|
|
gzFile gzfile;
|
|
|
|
|
|
2020-02-21 15:29:32 +01:00
|
|
|
# if defined(WIN32) || defined(_WIN32)
|
|
|
|
|
wstring filenameWide = stringToWstring(filename);
|
|
|
|
|
gzfile = gzopen_w(filenameWide.c_str(), mode);
|
2020-02-19 18:58:09 +01:00
|
|
|
# else
|
|
|
|
|
gzfile = gzopen(filename, mode);
|
|
|
|
|
# endif
|
2020-02-21 15:29:32 +01:00
|
|
|
|
2020-02-19 18:58:09 +01:00
|
|
|
return gzfile;
|
2020-07-17 15:58:13 +02:00
|
|
|
#else
|
|
|
|
|
debMsg("safeGzopen not supported without zlib", 1);
|
|
|
|
|
return nullptr;
|
2020-06-24 12:00:13 +02:00
|
|
|
#endif // NO_ZLIB != 1
|
2020-07-17 15:58:13 +02:00
|
|
|
}
|
2020-06-24 12:00:13 +02:00
|
|
|
|
|
|
|
|
#if defined(OPENVDB)
|
|
|
|
|
// 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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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
|
2020-02-19 18:58:09 +01:00
|
|
|
|
2020-07-17 15:58:13 +02:00
|
|
|
} // namespace Manta
|