diff options
Diffstat (limited to 'extern/mantaflow/preprocessed/fileio')
-rw-r--r-- | extern/mantaflow/preprocessed/fileio/iogrids.cpp | 43 | ||||
-rw-r--r-- | extern/mantaflow/preprocessed/fileio/iomeshes.cpp | 19 | ||||
-rw-r--r-- | extern/mantaflow/preprocessed/fileio/ioparticles.cpp | 1 | ||||
-rw-r--r-- | extern/mantaflow/preprocessed/fileio/ioutil.cpp | 21 |
4 files changed, 55 insertions, 29 deletions
diff --git a/extern/mantaflow/preprocessed/fileio/iogrids.cpp b/extern/mantaflow/preprocessed/fileio/iogrids.cpp index e2550d6db8b..825ce0ae8b5 100644 --- a/extern/mantaflow/preprocessed/fileio/iogrids.cpp +++ b/extern/mantaflow/preprocessed/fileio/iogrids.cpp @@ -27,7 +27,10 @@ extern "C" { } #endif -#include "cnpy.h" +#if NO_CNPY != 1 +# include "cnpy.h" +#endif + #include "mantaio.h" #include "grid.h" #include "vector4d.h" @@ -965,12 +968,16 @@ int readGrid4dUni( }; void readGrid4dUniCleanup(void **fileHandle) { +#if NO_ZLIB != 1 gzFile gzf = NULL; if (fileHandle) { gzf = (gzFile)(*fileHandle); gzclose(gzf); *fileHandle = NULL; } +#else + debMsg("file format not supported without zlib", 1); +#endif } template<class T> int writeGrid4dRaw(const string &name, Grid4d<T> *grid) @@ -1021,15 +1028,13 @@ template<class T> int readGrid4dRaw(const string &name, Grid4d<T> *grid) template<class T> int writeGridNumpy(const string &name, Grid<T> *grid) { -#if NO_ZLIB == 1 - debMsg("file format not supported without zlib", 1); - return 0; -#endif + #if FLOATINGPOINT_PRECISION != 1 errMsg("writeGridNumpy: Double precision not yet supported"); return 0; #endif +#if NO_CNPY != 1 // find suffix to differentiate between npy <-> npz , TODO: check for actual "npy" string std::string::size_type idx; bool bUseNpz = false; @@ -1075,19 +1080,21 @@ template<class T> int writeGridNumpy(const string &name, Grid<T> *grid) cnpy::npy_save(name, &grid[0], shape, "w"); } return 1; -}; +#else + debMsg("file format not supported without cnpy", 1); + return 0; +#endif +} template<class T> int readGridNumpy(const string &name, Grid<T> *grid) { -#if NO_ZLIB == 1 - debMsg("file format not supported without zlib", 1); - return 0; -#endif + #if FLOATINGPOINT_PRECISION != 1 errMsg("readGridNumpy: Double precision not yet supported"); return 0; #endif +#if NO_CNPY != 1 // find suffix to differentiate between npy <-> npz std::string::size_type idx; bool bUseNpz = false; @@ -1144,7 +1151,11 @@ template<class T> int readGridNumpy(const string &name, Grid<T> *grid) gridArr.data<T>(), sizeof(T) * grid->getSizeX() * grid->getSizeY() * grid->getSizeZ()); return 1; -}; +#else + debMsg("file format not supported without cnpy", 1); + return 0; +#endif +} int writeGridsNumpy(const string &name, std::vector<PbClass *> *grids) { @@ -1163,13 +1174,12 @@ void getNpzFileSize( const string &name, int &x, int &y, int &z, int *t = NULL, std::string *info = NULL) { x = y = z = 0; -#if NO_ZLIB != 1 - debMsg("file format not supported without zlib", 1); - return; -#endif + #if FLOATINGPOINT_PRECISION != 1 errMsg("getNpzFileSize: Double precision not yet supported"); #endif + +#if NO_CNPY != 1 // find suffix to differentiate between npy <-> npz cnpy::NpyArray gridArr; cnpy::npz_t fNpz = cnpy::npz_load(name); @@ -1180,6 +1190,9 @@ void getNpzFileSize( x = gridArr.shape[2]; if (t) (*t) = 0; // unused for now +#else + debMsg("file format not supported without cnpy", 1); +#endif } Vec3 getNpzFileSize(const string &name) { diff --git a/extern/mantaflow/preprocessed/fileio/iomeshes.cpp b/extern/mantaflow/preprocessed/fileio/iomeshes.cpp index 1c50376de77..b5e51625077 100644 --- a/extern/mantaflow/preprocessed/fileio/iomeshes.cpp +++ b/extern/mantaflow/preprocessed/fileio/iomeshes.cpp @@ -315,10 +315,14 @@ int readObjFile(const std::string &name, Mesh *mesh, bool append) return 0; } + const Real dx = mesh->getParent()->getDx(); + const Vec3 gs = toVec3(mesh->getParent()->getGridSize()); + if (!append) mesh->clear(); int nodebase = mesh->numNodes(); - int cnt = nodebase; + int cntNodes = nodebase, cntNormals = nodebase; + while (ifs.good() && !ifs.eof()) { string id; ifs >> id; @@ -333,19 +337,23 @@ int readObjFile(const std::string &name, Mesh *mesh, bool append) } else if (id == "vn") { // normals - if (!mesh->numNodes()) { + if (mesh->numNodes() != cntNodes) { errMsg("invalid amount of nodes"); return 0; } - Node n = mesh->nodes(cnt); - ifs >> n.normal.x >> n.normal.y >> n.normal.z; - cnt++; + Node *n = &mesh->nodes(cntNormals); + ifs >> n->normal.x >> n->normal.y >> n->normal.z; + cntNormals++; } else if (id == "v") { // vertex Node n; ifs >> n.pos.x >> n.pos.y >> n.pos.z; + // convert to grid space + n.pos /= dx; + n.pos += gs * 0.5; mesh->addNode(n); + cntNodes++; } else if (id == "g") { // group @@ -408,7 +416,6 @@ int writeObjFile(const string &name, Mesh *mesh) // write normals for (int i = 0; i < numVerts; i++) { Vector3D<float> n = toVec3f(mesh->nodes(i).normal); - // normalize to unit cube around 0 ofs << "vn " << n.value[0] << " " << n.value[1] << " " << n.value[2] << " " << "\n"; } diff --git a/extern/mantaflow/preprocessed/fileio/ioparticles.cpp b/extern/mantaflow/preprocessed/fileio/ioparticles.cpp index 84283a25b07..36e10aa1644 100644 --- a/extern/mantaflow/preprocessed/fileio/ioparticles.cpp +++ b/extern/mantaflow/preprocessed/fileio/ioparticles.cpp @@ -322,6 +322,7 @@ template<class T> int readPdataUni(const std::string &name, ParticleDataImpl<T> UniPartHeader head; assertMsg(gzread(gzf, &head, sizeof(UniPartHeader)) == sizeof(UniPartHeader), "can't read file, no header present"); + pdata->getParticleSys()->resize(head.dim); // ensure that parent particle system has same size pdata->resize(head.dim); assertMsg(head.dim == pdata->size(), "pdata size doesn't match"); diff --git a/extern/mantaflow/preprocessed/fileio/ioutil.cpp b/extern/mantaflow/preprocessed/fileio/ioutil.cpp index cc63cf87ac1..cf40d71fcc4 100644 --- a/extern/mantaflow/preprocessed/fileio/ioutil.cpp +++ b/extern/mantaflow/preprocessed/fileio/ioutil.cpp @@ -26,17 +26,18 @@ extern "C" { # include <zlib.h> } +#endif -# if defined(WIN32) || defined(_WIN32) -# include <windows.h> -# include <string> -# endif +#if defined(WIN32) || defined(_WIN32) +# include <windows.h> +# include <string> +#endif using namespace std; namespace Manta { -# if defined(WIN32) || defined(_WIN32) +#if defined(WIN32) || defined(_WIN32) static wstring stringToWstring(const char *str) { const int length_wc = MultiByteToWideChar(CP_UTF8, 0, str, strlen(str), NULL, 0); @@ -44,10 +45,11 @@ static wstring stringToWstring(const char *str) MultiByteToWideChar(CP_UTF8, 0, str, strlen(str), &strWide[0], length_wc); return strWide; } -# endif // WIN32==1 +#endif // WIN32==1 void *safeGzopen(const char *filename, const char *mode) { +#if NO_ZLIB != 1 gzFile gzfile; # if defined(WIN32) || defined(_WIN32) @@ -58,8 +60,11 @@ void *safeGzopen(const char *filename, const char *mode) # endif return gzfile; -} +#else + debMsg("safeGzopen not supported without zlib", 1); + return nullptr; #endif // NO_ZLIB != 1 +} #if defined(OPENVDB) // Convert from OpenVDB value to Manta value. @@ -109,4 +114,4 @@ template<> void convertTo(openvdb::Vec3s *out, Vec3 &in) } #endif // OPENVDB==1 -} // namespace +} // namespace Manta |