diff options
Diffstat (limited to 'extern')
25 files changed, 609 insertions, 1057 deletions
diff --git a/extern/audaspace/bindings/python/PySound.cpp b/extern/audaspace/bindings/python/PySound.cpp index 62ee3435e82..f2debccfd33 100644 --- a/extern/audaspace/bindings/python/PySound.cpp +++ b/extern/audaspace/bindings/python/PySound.cpp @@ -1395,9 +1395,9 @@ PyDoc_STRVAR(M_aud_Sound_threshold_doc, " all between to 0.\n\n" " :arg threshold: Threshold value over which an amplitude counts\n" " non-zero.\n\n" - ":type threshold: float\n" - ":return: The created :class:`Sound` object.\n" - ":rtype: :class:`Sound`"); + " :type threshold: float\n" + " :return: The created :class:`Sound` object.\n" + " :rtype: :class:`Sound`"); static PyObject * Sound_threshold(Sound* self, PyObject* args) diff --git a/extern/audaspace/src/respec/JOSResampleReader.cpp b/extern/audaspace/src/respec/JOSResampleReader.cpp index 6753a2e8b6b..378986fee28 100644 --- a/extern/audaspace/src/respec/JOSResampleReader.cpp +++ b/extern/audaspace/src/respec/JOSResampleReader.cpp @@ -119,8 +119,8 @@ void JOSResampleReader::updateBuffer(int size, double factor, int samplesize) P = int_to_fp(m_L) - P;\ \ end = std::floor((m_len - 1) / double(m_L) + m_P) - 1;\ - if(m_cache_valid - m_n - 2 < end)\ - end = m_cache_valid - m_n - 2;\ + if(m_cache_valid - int(m_n) - 2 < end)\ + end = m_cache_valid - int(m_n) - 2;\ \ data = buf + (m_n + 2 + end) * m_channels - 1;\ l = fp_to_int(P);\ @@ -166,8 +166,8 @@ void JOSResampleReader::updateBuffer(int size, double factor, int samplesize) P = 0 - P;\ \ end = (int_to_fp(m_len) - P) / P_increment - 1;\ - if(m_cache_valid - m_n - 2 < end)\ - end = m_cache_valid - m_n - 2;\ + if(m_cache_valid - int(m_n) - 2 < end)\ + end = m_cache_valid - int(m_n) - 2;\ \ P += P_increment * end;\ data = buf + (m_n + 2 + end) * m_channels - 1;\ diff --git a/extern/bullet2/patches/btPolyhedralConvexShape_Inertia_fix.patch b/extern/bullet2/patches/btPolyhedralConvexShape_Inertia_fix.patch new file mode 100644 index 00000000000..abafb5855dd --- /dev/null +++ b/extern/bullet2/patches/btPolyhedralConvexShape_Inertia_fix.patch @@ -0,0 +1,41 @@ +diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp +index 9095c592d87..b831e20c2f9 100644 +--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp ++++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp +@@ -406,17 +406,17 @@ void btPolyhedralConvexShape::calculateLocalInertia(btScalar mass,btVector3& ine + #ifndef __SPU__ + //not yet, return box inertia + +- btScalar margin = getMargin(); ++ //btScalar margin = getMargin(); + + btTransform ident; + ident.setIdentity(); + btVector3 aabbMin,aabbMax; +- getAabb(ident,aabbMin,aabbMax); ++ getAabb(ident,aabbMin,aabbMax); // This already contains the margin + btVector3 halfExtents = (aabbMax-aabbMin)*btScalar(0.5); + +- btScalar lx=btScalar(2.)*(halfExtents.x()+margin); +- btScalar ly=btScalar(2.)*(halfExtents.y()+margin); +- btScalar lz=btScalar(2.)*(halfExtents.z()+margin); ++ btScalar lx=btScalar(2.)*(halfExtents.x()); ++ btScalar ly=btScalar(2.)*(halfExtents.y()); ++ btScalar lz=btScalar(2.)*(halfExtents.z()); + const btScalar x2 = lx*lx; + const btScalar y2 = ly*ly; + const btScalar z2 = lz*lz; +@@ -476,10 +476,10 @@ void btPolyhedralConvexAabbCachingShape::recalcLocalAabb() + + for ( int i = 0; i < 3; ++i ) + { +- m_localAabbMax[i] = _supporting[i][i] + m_collisionMargin; +- m_localAabbMin[i] = _supporting[i + 3][i] - m_collisionMargin; ++ m_localAabbMax[i] = _supporting[i][i]; ++ m_localAabbMin[i] = _supporting[i + 3][i]; + } +- ++ + #else + + for (int i=0;i<3;i++) diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btCompoundShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btCompoundShape.cpp index e8c8c336cd2..1e7f36e0a17 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btCompoundShape.cpp +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btCompoundShape.cpp @@ -180,7 +180,7 @@ void btCompoundShape::getAabb(const btTransform& trans,btVector3& aabbMin,btVect localHalfExtents += btVector3(getMargin(),getMargin(),getMargin()); - btMatrix3x3 abs_b = trans.getBasis().absolute(); + btMatrix3x3 abs_b = trans.getBasis().absolute(); btVector3 center = trans(localCenter); diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp index 9095c592d87..b831e20c2f9 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp @@ -406,17 +406,17 @@ void btPolyhedralConvexShape::calculateLocalInertia(btScalar mass,btVector3& ine #ifndef __SPU__ //not yet, return box inertia - btScalar margin = getMargin(); + //btScalar margin = getMargin(); btTransform ident; ident.setIdentity(); btVector3 aabbMin,aabbMax; - getAabb(ident,aabbMin,aabbMax); + getAabb(ident,aabbMin,aabbMax); // This already contains the margin btVector3 halfExtents = (aabbMax-aabbMin)*btScalar(0.5); - btScalar lx=btScalar(2.)*(halfExtents.x()+margin); - btScalar ly=btScalar(2.)*(halfExtents.y()+margin); - btScalar lz=btScalar(2.)*(halfExtents.z()+margin); + btScalar lx=btScalar(2.)*(halfExtents.x()); + btScalar ly=btScalar(2.)*(halfExtents.y()); + btScalar lz=btScalar(2.)*(halfExtents.z()); const btScalar x2 = lx*lx; const btScalar y2 = ly*ly; const btScalar z2 = lz*lz; @@ -476,10 +476,10 @@ void btPolyhedralConvexAabbCachingShape::recalcLocalAabb() for ( int i = 0; i < 3; ++i ) { - m_localAabbMax[i] = _supporting[i][i] + m_collisionMargin; - m_localAabbMin[i] = _supporting[i + 3][i] - m_collisionMargin; + m_localAabbMax[i] = _supporting[i][i]; + m_localAabbMin[i] = _supporting[i + 3][i]; } - + #else for (int i=0;i<3;i++) diff --git a/extern/cuew/src/cuew.c b/extern/cuew/src/cuew.c index f477ec48a18..7a1b0018a24 100644 --- a/extern/cuew/src/cuew.c +++ b/extern/cuew/src/cuew.c @@ -879,7 +879,7 @@ int cuewCompilerVersion(void) { } /* get --version output */ - strncat(command, "\"", 1); + strcat(command, "\""); strncat(command, path, sizeof(command) - 1); strncat(command, "\" --version", sizeof(command) - strlen(path) - 1); pipe = popen(command, "r"); diff --git a/extern/mantaflow/CMakeLists.txt b/extern/mantaflow/CMakeLists.txt index 8b7453bf4c5..9f66b42c6bf 100644 --- a/extern/mantaflow/CMakeLists.txt +++ b/extern/mantaflow/CMakeLists.txt @@ -31,19 +31,32 @@ if(MSVC_CLANG AND WITH_OPENMP AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "9.0.1 remove_cc_flag("-fopenmp") endif() -set(MANTAVERSION "0.12") +set(MANTAVERSION "0.13") add_definitions(-DWITH_FLUID=1) -set(MANTA_DEP - dependencies -) +# Compile Mantaflow dependencies too (e.g. cnpy for numpy file IO). +# Make sure that dependencies exist before enabling this option by updating the source files in extern/ +set(WITH_MANTA_DEPENDENCIES 0) + +# Enable Mantaflow numpy support +set(WITH_MANTA_NUMPY 0) + +if(NOT WITH_MANTA_DEPENDENCIES) + add_definitions(-DNO_CNPY=1) +endif() + set(MANTA_HLP helper ) set(MANTA_PP preprocessed ) +if(WITH_MANTA_DEPENDENCIES) + set(MANTA_DEP + dependencies + ) +endif() if(WITH_TBB) add_definitions(-DTBB=1) @@ -62,6 +75,10 @@ if(WIN32) add_definitions(-D_USE_MATH_DEFINES) endif() +if(WITH_MANTA_NUMPY AND WITH_PYTHON_INSTALL_NUMPY) + add_definitions(-DNUMPY=1) +endif() + set(INC ${MANTA_PP} ${MANTA_PP}/fileio @@ -69,14 +86,25 @@ set(INC ${MANTA_PP}/plugin ${MANTA_HLP}/pwrapper ${MANTA_HLP}/util - ${MANTA_DEP}/cnpy ) +if(WITH_MANTA_DEPENDENCIES) + list(APPEND INC + ${MANTA_DEP}/cnpy + ) +endif() + set(INC_SYS ${PYTHON_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS} ) +if(WITH_MANTA_NUMPY AND WITH_PYTHON_INSTALL_NUMPY) + list(APPEND INC_SYS + ${PYTHON_NUMPY_INCLUDE_DIRS} + ) +endif() + if(WITH_TBB) list(APPEND INC_SYS ${TBB_INCLUDE_DIRS} @@ -96,9 +124,6 @@ if(WITH_OPENVDB) endif() set(SRC - ${MANTA_DEP}/cnpy/cnpy.cpp - ${MANTA_DEP}/cnpy/cnpy.h - ${MANTA_PP}/commonkernels.h ${MANTA_PP}/commonkernels.h.reg.cpp ${MANTA_PP}/conjugategrad.cpp @@ -161,14 +186,10 @@ set(SRC ${MANTA_PP}/plugin/initplugins.cpp ${MANTA_PP}/plugin/kepsilon.cpp ${MANTA_PP}/plugin/meshplugins.cpp -# TODO (sebbas): add numpy to libraries -# ${MANTA_PP}/plugin/numpyconvert.cpp ${MANTA_PP}/plugin/pressure.cpp ${MANTA_PP}/plugin/ptsplugins.cpp ${MANTA_PP}/plugin/secondaryparticles.cpp ${MANTA_PP}/plugin/surfaceturbulence.cpp -# TODO (sebbas): add numpy to libraries -# ${MANTA_PP}/plugin/tfplugins.cpp ${MANTA_PP}/plugin/vortexplugins.cpp ${MANTA_PP}/plugin/waveletturbulence.cpp ${MANTA_PP}/plugin/waves.cpp @@ -193,9 +214,6 @@ set(SRC ${MANTA_PP}/vortexsheet.h.reg.cpp ${MANTA_HLP}/pwrapper/manta.h -# TODO (sebbas): add numpy to libraries -# ${MANTA_HLP}/pwrapper/numpyWrap.cpp -# ${MANTA_HLP}/pwrapper/numpyWrap.h ${MANTA_HLP}/pwrapper/pclass.cpp ${MANTA_HLP}/pwrapper/pclass.h ${MANTA_HLP}/pwrapper/pconvert.cpp @@ -221,6 +239,22 @@ set(SRC ${MANTA_HLP}/util/vectorbase.h ) +if(WITH_MANTA_DEPENDENCIES) + list(APPEND SRC + ${MANTA_DEP}/cnpy/cnpy.cpp + ${MANTA_DEP}/cnpy/cnpy.h + ) +endif() + +if(WITH_MANTA_NUMPY AND WITH_PYTHON_INSTALL_NUMPY) + list(APPEND SRC + ${MANTA_PP}/plugin/numpyconvert.cpp + ${MANTA_PP}/plugin/tfplugins.cpp + ${MANTA_HLP}/pwrapper/numpyWrap.cpp + ${MANTA_HLP}/pwrapper/numpyWrap.h + ) +endif() + set(LIB ${PYTHON_LINKFLAGS} ${PYTHON_LIBRARIES} diff --git a/extern/mantaflow/UPDATE.sh b/extern/mantaflow/UPDATE.sh index 3feb1ba9226..aed4e2a9b71 100644 --- a/extern/mantaflow/UPDATE.sh +++ b/extern/mantaflow/UPDATE.sh @@ -13,6 +13,12 @@ BLENDER_INSTALLATION=/Users/sebbas/Developer/Blender/fluid-mantaflow # Try to check out Mantaflow repository before building? CLEAN_REPOSITORY=0 +# Skip copying dependency files? +WITH_DEPENDENCIES=0 + +# Build with numpy support? +USE_NUMPY=0 + # Choose which multithreading platform to use for Mantaflow preprocessing USE_OMP=0 USE_TBB=1 @@ -50,17 +56,21 @@ fi MANTA_BUILD_PATH=$MANTA_INSTALLATION/build_blender/ mkdir -p $MANTA_BUILD_PATH cd $MANTA_BUILD_PATH -cmake ../mantaflowgit -DGUI=OFF -DOPENMP=$USE_OMP -DTBB=$USE_TBB -DBLENDER=ON -DPREPDEBUG=ON && make -j8 +cmake ../mantaflowgit -DGUI=0 -DOPENMP=$USE_OMP -DTBB=$USE_TBB -DBLENDER=1 -DPREPDEBUG=1 -DNUMPY=$USE_NUMPY && make -j8 # ==================== 3) COPY MANTAFLOW FILES TO BLENDER ROOT =========================== -mkdir -p $BLENDER_INSTALLATION/blender/tmp/dependencies/ && cp -Rf $MANTA_INSTALLATION/mantaflowgit/dependencies/cnpy "$_" +if [[ "$WITH_DEPENDENCIES" -eq "1" ]]; then + mkdir -p $BLENDER_INSTALLATION/blender/tmp/dependencies/ && cp -Rf $MANTA_INSTALLATION/mantaflowgit/dependencies/cnpy "$_" +fi mkdir -p $BLENDER_INSTALLATION/blender/tmp/helper/ && cp -Rf $MANTA_INSTALLATION/mantaflowgit/source/util "$_" mkdir -p $BLENDER_INSTALLATION/blender/tmp/helper/ && cp -Rf $MANTA_INSTALLATION/mantaflowgit/source/pwrapper "$_" mkdir -p $BLENDER_INSTALLATION/blender/tmp/preprocessed/ && cp -Rf $MANTA_INSTALLATION/build_blender/pp/source/. "$_" # Remove some files that are not need in Blender -rm $BLENDER_INSTALLATION/blender/tmp/dependencies/cnpy/example1.cpp +if [[ "$WITH_DEPENDENCIES" -eq "1" ]]; then + rm $BLENDER_INSTALLATION/blender/tmp/dependencies/cnpy/example1.cpp +fi rm $BLENDER_INSTALLATION/blender/tmp/helper/pwrapper/pymain.cpp rm $BLENDER_INSTALLATION/blender/tmp/preprocessed/*.reg rm $BLENDER_INSTALLATION/blender/tmp/preprocessed/python/*.reg @@ -82,8 +92,13 @@ BLENDER_TMP_DEP=$BLENDER_TMP/dependencies BLENDER_TMP_HLP=$BLENDER_TMP/helper BLENDER_TMP_PP=$BLENDER_TMP/preprocessed +# Before moving new files, delete all existing file in the Blender repository +rm -Rf $BLENDER_MANTA_EXTERN/dependencies $BLENDER_MANTA_EXTERN/helper $BLENDER_MANTA_EXTERN/preprocessed + # Move files from tmp dir to extern/ -cp -Rf $BLENDER_TMP_DEP $BLENDER_MANTA_EXTERN +if [[ "$WITH_DEPENDENCIES" -eq "1" ]]; then + cp -Rf $BLENDER_TMP_DEP $BLENDER_MANTA_EXTERN +fi cp -Rf $BLENDER_TMP_HLP $BLENDER_MANTA_EXTERN cp -Rf $BLENDER_TMP_PP $BLENDER_MANTA_EXTERN diff --git a/extern/mantaflow/dependencies/cnpy/LICENSE b/extern/mantaflow/dependencies/cnpy/LICENSE deleted file mode 100644 index e60eadbccb3..00000000000 --- a/extern/mantaflow/dependencies/cnpy/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License - -Copyright (c) Carl Rogers, 2011 - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/extern/mantaflow/dependencies/cnpy/cnpy.cpp b/extern/mantaflow/dependencies/cnpy/cnpy.cpp deleted file mode 100644 index 7f0ce21ece8..00000000000 --- a/extern/mantaflow/dependencies/cnpy/cnpy.cpp +++ /dev/null @@ -1,385 +0,0 @@ -// Copyright (C) 2011 Carl Rogers -// Released under MIT License -// license available in LICENSE file, or at http://www.opensource.org/licenses/mit-license.php - -#include "cnpy.h" -#include <complex> -#include <cstdlib> -#include <algorithm> -#include <cstring> -#include <iomanip> -#include <stdint.h> -#include <stdexcept> -#include <regex> - -char cnpy::BigEndianTest() -{ - int x = 1; - return (((char *)&x)[0]) ? '<' : '>'; -} - -char cnpy::map_type(const std::type_info &t) -{ - if (t == typeid(float)) - return 'f'; - if (t == typeid(double)) - return 'f'; - if (t == typeid(long double)) - return 'f'; - - if (t == typeid(int)) - return 'i'; - if (t == typeid(char)) - return 'i'; - if (t == typeid(short)) - return 'i'; - if (t == typeid(long)) - return 'i'; - if (t == typeid(long long)) - return 'i'; - - if (t == typeid(unsigned char)) - return 'u'; - if (t == typeid(unsigned short)) - return 'u'; - if (t == typeid(unsigned long)) - return 'u'; - if (t == typeid(unsigned long long)) - return 'u'; - if (t == typeid(unsigned int)) - return 'u'; - - if (t == typeid(bool)) - return 'b'; - - if (t == typeid(std::complex<float>)) - return 'c'; - if (t == typeid(std::complex<double>)) - return 'c'; - if (t == typeid(std::complex<long double>)) - return 'c'; - - else - return '?'; -} - -template<> std::vector<char> &cnpy::operator+=(std::vector<char> &lhs, const std::string rhs) -{ - lhs.insert(lhs.end(), rhs.begin(), rhs.end()); - return lhs; -} - -template<> std::vector<char> &cnpy::operator+=(std::vector<char> &lhs, const char *rhs) -{ - // write in little endian - size_t len = strlen(rhs); - lhs.reserve(len); - for (size_t byte = 0; byte < len; byte++) { - lhs.push_back(rhs[byte]); - } - return lhs; -} - -void cnpy::parse_npy_header(unsigned char *buffer, - size_t &word_size, - std::vector<size_t> &shape, - bool &fortran_order) -{ - // std::string magic_string(buffer,6); - uint8_t major_version = *reinterpret_cast<uint8_t *>(buffer + 6); - uint8_t minor_version = *reinterpret_cast<uint8_t *>(buffer + 7); - uint16_t header_len = *reinterpret_cast<uint16_t *>(buffer + 8); - std::string header(reinterpret_cast<char *>(buffer + 9), header_len); - - size_t loc1, loc2; - - // fortran order - loc1 = header.find("fortran_order") + 16; - fortran_order = (header.substr(loc1, 4) == "True" ? true : false); - - // shape - loc1 = header.find("("); - loc2 = header.find(")"); - - std::regex num_regex("[0-9][0-9]*"); - std::smatch sm; - shape.clear(); - - std::string str_shape = header.substr(loc1 + 1, loc2 - loc1 - 1); - while (std::regex_search(str_shape, sm, num_regex)) { - shape.push_back(std::stoi(sm[0].str())); - str_shape = sm.suffix().str(); - } - - // endian, word size, data type - // byte order code | stands for not applicable. - // not sure when this applies except for byte array - loc1 = header.find("descr") + 9; - bool littleEndian = (header[loc1] == '<' || header[loc1] == '|' ? true : false); - assert(littleEndian); - - // char type = header[loc1+1]; - // assert(type == map_type(T)); - - std::string str_ws = header.substr(loc1 + 2); - loc2 = str_ws.find("'"); - word_size = atoi(str_ws.substr(0, loc2).c_str()); -} - -void cnpy::parse_npy_header(FILE *fp, - size_t &word_size, - std::vector<size_t> &shape, - bool &fortran_order) -{ - char buffer[256]; - size_t res = fread(buffer, sizeof(char), 11, fp); - if (res != 11) - throw std::runtime_error("parse_npy_header: failed fread"); - std::string header = fgets(buffer, 256, fp); - assert(header[header.size() - 1] == '\n'); - - size_t loc1, loc2; - - // fortran order - loc1 = header.find("fortran_order"); - if (loc1 == std::string::npos) - throw std::runtime_error("parse_npy_header: failed to find header keyword: 'fortran_order'"); - loc1 += 16; - fortran_order = (header.substr(loc1, 4) == "True" ? true : false); - - // shape - loc1 = header.find("("); - loc2 = header.find(")"); - if (loc1 == std::string::npos || loc2 == std::string::npos) - throw std::runtime_error("parse_npy_header: failed to find header keyword: '(' or ')'"); - - std::regex num_regex("[0-9][0-9]*"); - std::smatch sm; - shape.clear(); - - std::string str_shape = header.substr(loc1 + 1, loc2 - loc1 - 1); - while (std::regex_search(str_shape, sm, num_regex)) { - shape.push_back(std::stoi(sm[0].str())); - str_shape = sm.suffix().str(); - } - - // endian, word size, data type - // byte order code | stands for not applicable. - // not sure when this applies except for byte array - loc1 = header.find("descr"); - if (loc1 == std::string::npos) - throw std::runtime_error("parse_npy_header: failed to find header keyword: 'descr'"); - loc1 += 9; - bool littleEndian = (header[loc1] == '<' || header[loc1] == '|' ? true : false); - assert(littleEndian); - - // char type = header[loc1+1]; - // assert(type == map_type(T)); - - std::string str_ws = header.substr(loc1 + 2); - loc2 = str_ws.find("'"); - word_size = atoi(str_ws.substr(0, loc2).c_str()); -} - -void cnpy::parse_zip_footer(FILE *fp, - uint16_t &nrecs, - size_t &global_header_size, - size_t &global_header_offset) -{ - std::vector<char> footer(22); - fseek(fp, -22, SEEK_END); - size_t res = fread(&footer[0], sizeof(char), 22, fp); - if (res != 22) - throw std::runtime_error("parse_zip_footer: failed fread"); - - uint16_t disk_no, disk_start, nrecs_on_disk, comment_len; - disk_no = *(uint16_t *)&footer[4]; - disk_start = *(uint16_t *)&footer[6]; - nrecs_on_disk = *(uint16_t *)&footer[8]; - nrecs = *(uint16_t *)&footer[10]; - global_header_size = *(uint32_t *)&footer[12]; - global_header_offset = *(uint32_t *)&footer[16]; - comment_len = *(uint16_t *)&footer[20]; - - assert(disk_no == 0); - assert(disk_start == 0); - assert(nrecs_on_disk == nrecs); - assert(comment_len == 0); -} - -cnpy::NpyArray load_the_npy_file(FILE *fp) -{ - std::vector<size_t> shape; - size_t word_size; - bool fortran_order; - cnpy::parse_npy_header(fp, word_size, shape, fortran_order); - - cnpy::NpyArray arr(shape, word_size, fortran_order); - size_t nread = fread(arr.data<char>(), 1, arr.num_bytes(), fp); - if (nread != arr.num_bytes()) - throw std::runtime_error("load_the_npy_file: failed fread"); - return arr; -} - -cnpy::NpyArray load_the_npz_array(FILE *fp, uint32_t compr_bytes, uint32_t uncompr_bytes) -{ - - std::vector<unsigned char> buffer_compr(compr_bytes); - std::vector<unsigned char> buffer_uncompr(uncompr_bytes); - size_t nread = fread(&buffer_compr[0], 1, compr_bytes, fp); - if (nread != compr_bytes) - throw std::runtime_error("load_the_npy_file: failed fread"); - - int err; - z_stream d_stream; - - d_stream.zalloc = Z_NULL; - d_stream.zfree = Z_NULL; - d_stream.opaque = Z_NULL; - d_stream.avail_in = 0; - d_stream.next_in = Z_NULL; - err = inflateInit2(&d_stream, -MAX_WBITS); - - d_stream.avail_in = compr_bytes; - d_stream.next_in = &buffer_compr[0]; - d_stream.avail_out = uncompr_bytes; - d_stream.next_out = &buffer_uncompr[0]; - - err = inflate(&d_stream, Z_FINISH); - err = inflateEnd(&d_stream); - - std::vector<size_t> shape; - size_t word_size; - bool fortran_order; - cnpy::parse_npy_header(&buffer_uncompr[0], word_size, shape, fortran_order); - - cnpy::NpyArray array(shape, word_size, fortran_order); - - size_t offset = uncompr_bytes - array.num_bytes(); - memcpy(array.data<unsigned char>(), &buffer_uncompr[0] + offset, array.num_bytes()); - - return array; -} - -cnpy::npz_t cnpy::npz_load(std::string fname) -{ - FILE *fp = fopen(fname.c_str(), "rb"); - - if (!fp) { - throw std::runtime_error("npz_load: Error! Unable to open file " + fname + "!"); - } - - cnpy::npz_t arrays; - - while (1) { - std::vector<char> local_header(30); - size_t headerres = fread(&local_header[0], sizeof(char), 30, fp); - if (headerres != 30) - throw std::runtime_error("npz_load: failed fread"); - - // if we've reached the global header, stop reading - if (local_header[2] != 0x03 || local_header[3] != 0x04) - break; - - // read in the variable name - uint16_t name_len = *(uint16_t *)&local_header[26]; - std::string varname(name_len, ' '); - size_t vname_res = fread(&varname[0], sizeof(char), name_len, fp); - if (vname_res != name_len) - throw std::runtime_error("npz_load: failed fread"); - - // erase the lagging .npy - varname.erase(varname.end() - 4, varname.end()); - - // read in the extra field - uint16_t extra_field_len = *(uint16_t *)&local_header[28]; - if (extra_field_len > 0) { - std::vector<char> buff(extra_field_len); - size_t efield_res = fread(&buff[0], sizeof(char), extra_field_len, fp); - if (efield_res != extra_field_len) - throw std::runtime_error("npz_load: failed fread"); - } - - uint16_t compr_method = *reinterpret_cast<uint16_t *>(&local_header[0] + 8); - uint32_t compr_bytes = *reinterpret_cast<uint32_t *>(&local_header[0] + 18); - uint32_t uncompr_bytes = *reinterpret_cast<uint32_t *>(&local_header[0] + 22); - - if (compr_method == 0) { - arrays[varname] = load_the_npy_file(fp); - } - else { - arrays[varname] = load_the_npz_array(fp, compr_bytes, uncompr_bytes); - } - } - - fclose(fp); - return arrays; -} - -cnpy::NpyArray cnpy::npz_load(std::string fname, std::string varname) -{ - FILE *fp = fopen(fname.c_str(), "rb"); - - if (!fp) - throw std::runtime_error("npz_load: Unable to open file " + fname); - - while (1) { - std::vector<char> local_header(30); - size_t header_res = fread(&local_header[0], sizeof(char), 30, fp); - if (header_res != 30) - throw std::runtime_error("npz_load: failed fread"); - - // if we've reached the global header, stop reading - if (local_header[2] != 0x03 || local_header[3] != 0x04) - break; - - // read in the variable name - uint16_t name_len = *(uint16_t *)&local_header[26]; - std::string vname(name_len, ' '); - size_t vname_res = fread(&vname[0], sizeof(char), name_len, fp); - if (vname_res != name_len) - throw std::runtime_error("npz_load: failed fread"); - vname.erase(vname.end() - 4, vname.end()); // erase the lagging .npy - - // read in the extra field - uint16_t extra_field_len = *(uint16_t *)&local_header[28]; - fseek(fp, extra_field_len, SEEK_CUR); // skip past the extra field - - uint16_t compr_method = *reinterpret_cast<uint16_t *>(&local_header[0] + 8); - uint32_t compr_bytes = *reinterpret_cast<uint32_t *>(&local_header[0] + 18); - uint32_t uncompr_bytes = *reinterpret_cast<uint32_t *>(&local_header[0] + 22); - - if (vname == varname) { - NpyArray array = (compr_method == 0) ? load_the_npy_file(fp) : - load_the_npz_array(fp, compr_bytes, uncompr_bytes); - fclose(fp); - return array; - } - else { - // skip past the data - // uint32_t size = *(uint32_t*) &local_header[22]; - uint32_t size = *(uint32_t *)&local_header[18]; // using index 18 instead of 22 enables - // support for compressed data - fseek(fp, size, SEEK_CUR); - } - } - - fclose(fp); - - // if we get here, we haven't found the variable in the file - throw std::runtime_error("npz_load: Variable name " + varname + " not found in " + fname); -} - -cnpy::NpyArray cnpy::npy_load(std::string fname) -{ - - FILE *fp = fopen(fname.c_str(), "rb"); - - if (!fp) - throw std::runtime_error("npy_load: Unable to open file " + fname); - - NpyArray arr = load_the_npy_file(fp); - - fclose(fp); - return arr; -} diff --git a/extern/mantaflow/dependencies/cnpy/cnpy.h b/extern/mantaflow/dependencies/cnpy/cnpy.h deleted file mode 100644 index e4b6365cb6f..00000000000 --- a/extern/mantaflow/dependencies/cnpy/cnpy.h +++ /dev/null @@ -1,310 +0,0 @@ -// Copyright (C) 2011 Carl Rogers -// Released under MIT License -// license available in LICENSE file, or at http://www.opensource.org/licenses/mit-license.php - -#ifndef LIBCNPY_H_ -#define LIBCNPY_H_ - -#include <string> -#include <stdexcept> -#include <sstream> -#include <vector> -#include <cstdio> -#include <typeinfo> -#include <iostream> -#include <cassert> -#include <zlib.h> -#include <map> -#include <memory> -#include <stdint.h> -#include <numeric> - -namespace cnpy { - -struct NpyArray { - NpyArray(const std::vector<size_t> &_shape, size_t _word_size, bool _fortran_order) - : shape(_shape), word_size(_word_size), fortran_order(_fortran_order) - { - num_vals = 1; - for (size_t i = 0; i < shape.size(); i++) - num_vals *= shape[i]; - data_holder = std::shared_ptr<std::vector<char>>(new std::vector<char>(num_vals * word_size)); - } - - NpyArray() : shape(0), word_size(0), fortran_order(0), num_vals(0) - { - } - - template<typename T> T *data() - { - return reinterpret_cast<T *>(&(*data_holder)[0]); - } - - template<typename T> const T *data() const - { - return reinterpret_cast<T *>(&(*data_holder)[0]); - } - - template<typename T> std::vector<T> as_vec() const - { - const T *p = data<T>(); - return std::vector<T>(p, p + num_vals); - } - - size_t num_bytes() const - { - return data_holder->size(); - } - - std::shared_ptr<std::vector<char>> data_holder; - std::vector<size_t> shape; - size_t word_size; - bool fortran_order; - size_t num_vals; -}; - -using npz_t = std::map<std::string, NpyArray>; - -char BigEndianTest(); -char map_type(const std::type_info &t); -template<typename T> std::vector<char> create_npy_header(const std::vector<size_t> &shape); -void parse_npy_header(FILE *fp, - size_t &word_size, - std::vector<size_t> &shape, - bool &fortran_order); -void parse_npy_header(unsigned char *buffer, - size_t &word_size, - std::vector<size_t> &shape, - bool &fortran_order); -void parse_zip_footer(FILE *fp, - uint16_t &nrecs, - size_t &global_header_size, - size_t &global_header_offset); -npz_t npz_load(std::string fname); -NpyArray npz_load(std::string fname, std::string varname); -NpyArray npy_load(std::string fname); - -template<typename T> std::vector<char> &operator+=(std::vector<char> &lhs, const T rhs) -{ - // write in little endian - for (size_t byte = 0; byte < sizeof(T); byte++) { - char val = *((char *)&rhs + byte); - lhs.push_back(val); - } - return lhs; -} - -template<> std::vector<char> &operator+=(std::vector<char> &lhs, const std::string rhs); -template<> std::vector<char> &operator+=(std::vector<char> &lhs, const char *rhs); - -template<typename T> -void npy_save(std::string fname, - const T *data, - const std::vector<size_t> shape, - std::string mode = "w") -{ - FILE *fp = NULL; - std::vector<size_t> true_data_shape; // if appending, the shape of existing + new data - - if (mode == "a") - fp = fopen(fname.c_str(), "r+b"); - - if (fp) { - // file exists. we need to append to it. read the header, modify the array size - size_t word_size; - bool fortran_order; - parse_npy_header(fp, word_size, true_data_shape, fortran_order); - assert(!fortran_order); - - if (word_size != sizeof(T)) { - std::cout << "libnpy error: " << fname << " has word size " << word_size - << " but npy_save appending data sized " << sizeof(T) << "\n"; - assert(word_size == sizeof(T)); - } - if (true_data_shape.size() != shape.size()) { - std::cout << "libnpy error: npy_save attempting to append misdimensioned data to " << fname - << "\n"; - assert(true_data_shape.size() != shape.size()); - } - - for (size_t i = 1; i < shape.size(); i++) { - if (shape[i] != true_data_shape[i]) { - std::cout << "libnpy error: npy_save attempting to append misshaped data to " << fname - << "\n"; - assert(shape[i] == true_data_shape[i]); - } - } - true_data_shape[0] += shape[0]; - } - else { - fp = fopen(fname.c_str(), "wb"); - true_data_shape = shape; - } - - std::vector<char> header = create_npy_header<T>(true_data_shape); - size_t nels = std::accumulate(shape.begin(), shape.end(), 1, std::multiplies<size_t>()); - - fseek(fp, 0, SEEK_SET); - fwrite(&header[0], sizeof(char), header.size(), fp); - fseek(fp, 0, SEEK_END); - fwrite(data, sizeof(T), nels, fp); - fclose(fp); -} - -template<typename T> -void npz_save(std::string zipname, - std::string fname, - const T *data, - const std::vector<size_t> &shape, - std::string mode = "w") -{ - // first, append a .npy to the fname - fname += ".npy"; - - // now, on with the show - FILE *fp = NULL; - uint16_t nrecs = 0; - size_t global_header_offset = 0; - std::vector<char> global_header; - - if (mode == "a") - fp = fopen(zipname.c_str(), "r+b"); - - if (fp) { - // zip file exists. we need to add a new npy file to it. - // first read the footer. this gives us the offset and size of the global header - // then read and store the global header. - // below, we will write the the new data at the start of the global header then append the - // global header and footer below it - size_t global_header_size; - parse_zip_footer(fp, nrecs, global_header_size, global_header_offset); - fseek(fp, global_header_offset, SEEK_SET); - global_header.resize(global_header_size); - size_t res = fread(&global_header[0], sizeof(char), global_header_size, fp); - if (res != global_header_size) { - throw std::runtime_error("npz_save: header read error while adding to existing zip"); - } - fseek(fp, global_header_offset, SEEK_SET); - } - else { - fp = fopen(zipname.c_str(), "wb"); - } - - std::vector<char> npy_header = create_npy_header<T>(shape); - - size_t nels = std::accumulate(shape.begin(), shape.end(), 1, std::multiplies<size_t>()); - size_t nbytes = nels * sizeof(T) + npy_header.size(); - - // get the CRC of the data to be added - uint32_t crc = crc32(0L, (uint8_t *)&npy_header[0], npy_header.size()); - crc = crc32(crc, (uint8_t *)data, nels * sizeof(T)); - - // build the local header - std::vector<char> local_header; - local_header += "PK"; // first part of sig - local_header += (uint16_t)0x0403; // second part of sig - local_header += (uint16_t)20; // min version to extract - local_header += (uint16_t)0; // general purpose bit flag - local_header += (uint16_t)0; // compression method - local_header += (uint16_t)0; // file last mod time - local_header += (uint16_t)0; // file last mod date - local_header += (uint32_t)crc; // crc - local_header += (uint32_t)nbytes; // compressed size - local_header += (uint32_t)nbytes; // uncompressed size - local_header += (uint16_t)fname.size(); // fname length - local_header += (uint16_t)0; // extra field length - local_header += fname; - - // build global header - global_header += "PK"; // first part of sig - global_header += (uint16_t)0x0201; // second part of sig - global_header += (uint16_t)20; // version made by - global_header.insert(global_header.end(), local_header.begin() + 4, local_header.begin() + 30); - global_header += (uint16_t)0; // file comment length - global_header += (uint16_t)0; // disk number where file starts - global_header += (uint16_t)0; // internal file attributes - global_header += (uint32_t)0; // external file attributes - global_header += (uint32_t) - global_header_offset; // relative offset of local file header, since it begins where the - // global header used to begin - global_header += fname; - - // build footer - std::vector<char> footer; - footer += "PK"; // first part of sig - footer += (uint16_t)0x0605; // second part of sig - footer += (uint16_t)0; // number of this disk - footer += (uint16_t)0; // disk where footer starts - footer += (uint16_t)(nrecs + 1); // number of records on this disk - footer += (uint16_t)(nrecs + 1); // total number of records - footer += (uint32_t)global_header.size(); // nbytes of global headers - footer += (uint32_t)(global_header_offset + nbytes + - local_header.size()); // offset of start of global headers, since global - // header now starts after newly written array - footer += (uint16_t)0; // zip file comment length - - // write everything - fwrite(&local_header[0], sizeof(char), local_header.size(), fp); - fwrite(&npy_header[0], sizeof(char), npy_header.size(), fp); - fwrite(data, sizeof(T), nels, fp); - fwrite(&global_header[0], sizeof(char), global_header.size(), fp); - fwrite(&footer[0], sizeof(char), footer.size(), fp); - fclose(fp); -} - -template<typename T> -void npy_save(std::string fname, const std::vector<T> data, std::string mode = "w") -{ - std::vector<size_t> shape; - shape.push_back(data.size()); - npy_save(fname, &data[0], shape, mode); -} - -template<typename T> -void npz_save(std::string zipname, - std::string fname, - const std::vector<T> data, - std::string mode = "w") -{ - std::vector<size_t> shape; - shape.push_back(data.size()); - npz_save(zipname, fname, &data[0], shape, mode); -} - -template<typename T> std::vector<char> create_npy_header(const std::vector<size_t> &shape) -{ - - std::vector<char> dict; - dict += "{'descr': '"; - dict += BigEndianTest(); - dict += map_type(typeid(T)); - dict += std::to_string(sizeof(T)); - dict += "', 'fortran_order': False, 'shape': ("; - dict += std::to_string(shape[0]); - for (size_t i = 1; i < shape.size(); i++) { - dict += ", "; - dict += std::to_string(shape[i]); - } - if (shape.size() == 1) - dict += ","; - dict += "), }"; - // pad with spaces so that preamble+dict is modulo 16 bytes. preamble is 10 bytes. dict needs to - // end with \n - int remainder = 16 - (10 + dict.size()) % 16; - dict.insert(dict.end(), remainder, ' '); - dict.back() = '\n'; - - std::vector<char> header; - header += (char)0x93; - header += "NUMPY"; - header += (char)0x01; // major version of numpy format - header += (char)0x00; // minor version of numpy format - header += (uint16_t)dict.size(); - header.insert(header.end(), dict.begin(), dict.end()); - - return header; -} - -} // namespace cnpy - -#endif diff --git a/extern/mantaflow/helper/util/vectorbase.h b/extern/mantaflow/helper/util/vectorbase.h index 41584663a0f..9b4d9c83f0b 100644 --- a/extern/mantaflow/helper/util/vectorbase.h +++ b/extern/mantaflow/helper/util/vectorbase.h @@ -248,12 +248,14 @@ template<class S> class Vector3D { protected: }; -//! helper to check whether float/double value is non-zero -inline bool notZero(Real f) +//! helper to check whether value is non-zero +template<class S> inline bool notZero(S v) { - if (std::abs(f) > VECTOR_EPSILON) - return true; - return false; + return (std::abs(v) > VECTOR_EPSILON); +} +template<class S> inline bool notZero(Vector3D<S> v) +{ + return (std::abs(norm(v)) > VECTOR_EPSILON); } //************************************************************************ @@ -437,6 +439,36 @@ inline Real normSquare(const int v) return square(v); } +//! Compute sum of all components, allow use of int, Real too +template<class S> inline S sum(const S v) +{ + return v; +} +template<class S> inline S sum(const Vector3D<S> &v) +{ + return v.x + v.y + v.z; +} + +//! Get absolute representation of vector, allow use of int, Real too +inline Real abs(const Real v) +{ + return std::fabs(v); +} +inline int abs(const int v) +{ + return std::abs(v); +} + +template<class S> inline Vector3D<S> abs(const Vector3D<S> &v) +{ + Vector3D<S> cp(v.x, v.y, v.z); + for (int i = 0; i < 3; ++i) { + if (cp[i] < 0) + cp[i] *= (-1.0); + } + return cp; +} + //! Returns a normalized vector template<class S> inline Vector3D<S> getNormalized(const Vector3D<S> &v) { 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 diff --git a/extern/mantaflow/preprocessed/gitinfo.h b/extern/mantaflow/preprocessed/gitinfo.h index 73ff70b10a0..ce088d6c400 100644 --- a/extern/mantaflow/preprocessed/gitinfo.h +++ b/extern/mantaflow/preprocessed/gitinfo.h @@ -1,3 +1,3 @@ -#define MANTA_GIT_VERSION "commit d80d3c821de74315ab26b5efd153d41477b976c4" +#define MANTA_GIT_VERSION "commit 841bfd09c068dfb95637c0ec14fa78305286a433" diff --git a/extern/mantaflow/preprocessed/mesh.cpp b/extern/mantaflow/preprocessed/mesh.cpp index d93c2ac04c0..6a9b0283bef 100644 --- a/extern/mantaflow/preprocessed/mesh.cpp +++ b/extern/mantaflow/preprocessed/mesh.cpp @@ -213,34 +213,36 @@ Mesh &Mesh::operator=(const Mesh &o) return *this; } -void Mesh::load(string name, bool append) +int Mesh::load(string name, bool append) { if (name.find_last_of('.') == string::npos) errMsg("file '" + name + "' does not have an extension"); string ext = name.substr(name.find_last_of('.')); if (ext == ".gz") // assume bobj gz - readBobjFile(name, this, append); + return readBobjFile(name, this, append); else if (ext == ".obj") - readObjFile(name, this, append); + return readObjFile(name, this, append); else errMsg("file '" + name + "' filetype not supported"); // dont always rebuild... // rebuildCorners(); // rebuildLookup(); + return 0; } -void Mesh::save(string name) +int Mesh::save(string name) { if (name.find_last_of('.') == string::npos) errMsg("file '" + name + "' does not have an extension"); string ext = name.substr(name.find_last_of('.')); if (ext == ".obj") - writeObjFile(name, this); + return writeObjFile(name, this); else if (ext == ".gz") - writeBobjFile(name, this); + return writeBobjFile(name, this); else errMsg("file '" + name + "' filetype not supported"); + return 0; } void Mesh::fromShape(Shape &shape, bool append) @@ -1339,8 +1341,8 @@ template<class T> void MeshDataImpl<T>::setSource(Grid<T> *grid, bool isMAC) { mpGridSource = grid; mGridSourceMAC = isMAC; - if (isMAC) - assertMsg(dynamic_cast<MACGrid *>(grid) != NULL, "Given grid is not a valid MAC grid"); + if (grid && isMAC) + assertMsg(grid->getType() & GridBase::TypeMAC, "Given grid is not a valid MAC grid"); } template<class T> void MeshDataImpl<T>::initNewValue(IndexInt idx, Vec3 pos) @@ -1371,38 +1373,40 @@ void Mesh::updateDataFields() for (size_t i = 0; i < mNodes.size(); ++i) { Vec3 pos = mNodes[i].pos; for (IndexInt md = 0; md < (IndexInt)mMdataReal.size(); ++md) - mMdataReal[md]->initNewValue(i, mNodes[i].pos); + mMdataReal[md]->initNewValue(i, pos); for (IndexInt md = 0; md < (IndexInt)mMdataVec3.size(); ++md) - mMdataVec3[md]->initNewValue(i, mNodes[i].pos); + mMdataVec3[md]->initNewValue(i, pos); for (IndexInt md = 0; md < (IndexInt)mMdataInt.size(); ++md) - mMdataInt[md]->initNewValue(i, mNodes[i].pos); + mMdataInt[md]->initNewValue(i, pos); } } -template<typename T> void MeshDataImpl<T>::load(string name) +template<typename T> int MeshDataImpl<T>::load(string name) { if (name.find_last_of('.') == string::npos) errMsg("file '" + name + "' does not have an extension"); string ext = name.substr(name.find_last_of('.')); if (ext == ".uni") - readMdataUni<T>(name, this); + return readMdataUni<T>(name, this); else if (ext == ".raw") // raw = uni for now - readMdataUni<T>(name, this); + return readMdataUni<T>(name, this); else errMsg("mesh data '" + name + "' filetype not supported for loading"); + return 0; } -template<typename T> void MeshDataImpl<T>::save(string name) +template<typename T> int MeshDataImpl<T>::save(string name) { if (name.find_last_of('.') == string::npos) errMsg("file '" + name + "' does not have an extension"); string ext = name.substr(name.find_last_of('.')); if (ext == ".uni") - writeMdataUni<T>(name, this); + return writeMdataUni<T>(name, this); else if (ext == ".raw") // raw = uni for now - writeMdataUni<T>(name, this); + return writeMdataUni<T>(name, this); else errMsg("mesh data '" + name + "' filetype not supported for saving"); + return 0; } // specializations diff --git a/extern/mantaflow/preprocessed/mesh.h b/extern/mantaflow/preprocessed/mesh.h index f49619515ce..4235b9508af 100644 --- a/extern/mantaflow/preprocessed/mesh.h +++ b/extern/mantaflow/preprocessed/mesh.h @@ -240,215 +240,214 @@ class Mesh : public PbClass { } } - void load(std::string name, bool append = false); + void fromShape(Shape &shape, bool append = false); static PyObject *_W_2(PyObject *_self, PyObject *_linargs, PyObject *_kwds) { try { PbArgs _args(_linargs, _kwds); Mesh *pbo = dynamic_cast<Mesh *>(Pb::objFromPy(_self)); bool noTiming = _args.getOpt<bool>("notiming", -1, 0); - pbPreparePlugin(pbo->getParent(), "Mesh::load", !noTiming); + pbPreparePlugin(pbo->getParent(), "Mesh::fromShape", !noTiming); PyObject *_retval = 0; { ArgLocker _lock; - std::string name = _args.get<std::string>("name", 0, &_lock); + Shape &shape = *_args.getPtr<Shape>("shape", 0, &_lock); bool append = _args.getOpt<bool>("append", 1, false, &_lock); pbo->_args.copy(_args); _retval = getPyNone(); - pbo->load(name, append); + pbo->fromShape(shape, append); pbo->_args.check(); } - pbFinalizePlugin(pbo->getParent(), "Mesh::load", !noTiming); + pbFinalizePlugin(pbo->getParent(), "Mesh::fromShape", !noTiming); return _retval; } catch (std::exception &e) { - pbSetError("Mesh::load", e.what()); + pbSetError("Mesh::fromShape", e.what()); return 0; } } - void fromShape(Shape &shape, bool append = false); + void advectInGrid(FlagGrid &flags, MACGrid &vel, int integrationMode); static PyObject *_W_3(PyObject *_self, PyObject *_linargs, PyObject *_kwds) { try { PbArgs _args(_linargs, _kwds); Mesh *pbo = dynamic_cast<Mesh *>(Pb::objFromPy(_self)); bool noTiming = _args.getOpt<bool>("notiming", -1, 0); - pbPreparePlugin(pbo->getParent(), "Mesh::fromShape", !noTiming); + pbPreparePlugin(pbo->getParent(), "Mesh::advectInGrid", !noTiming); PyObject *_retval = 0; { ArgLocker _lock; - Shape &shape = *_args.getPtr<Shape>("shape", 0, &_lock); - bool append = _args.getOpt<bool>("append", 1, false, &_lock); + FlagGrid &flags = *_args.getPtr<FlagGrid>("flags", 0, &_lock); + MACGrid &vel = *_args.getPtr<MACGrid>("vel", 1, &_lock); + int integrationMode = _args.get<int>("integrationMode", 2, &_lock); pbo->_args.copy(_args); _retval = getPyNone(); - pbo->fromShape(shape, append); + pbo->advectInGrid(flags, vel, integrationMode); pbo->_args.check(); } - pbFinalizePlugin(pbo->getParent(), "Mesh::fromShape", !noTiming); + pbFinalizePlugin(pbo->getParent(), "Mesh::advectInGrid", !noTiming); return _retval; } catch (std::exception &e) { - pbSetError("Mesh::fromShape", e.what()); + pbSetError("Mesh::advectInGrid", e.what()); return 0; } } - void save(std::string name); + void scale(Vec3 s); static PyObject *_W_4(PyObject *_self, PyObject *_linargs, PyObject *_kwds) { try { PbArgs _args(_linargs, _kwds); Mesh *pbo = dynamic_cast<Mesh *>(Pb::objFromPy(_self)); bool noTiming = _args.getOpt<bool>("notiming", -1, 0); - pbPreparePlugin(pbo->getParent(), "Mesh::save", !noTiming); + pbPreparePlugin(pbo->getParent(), "Mesh::scale", !noTiming); PyObject *_retval = 0; { ArgLocker _lock; - std::string name = _args.get<std::string>("name", 0, &_lock); + Vec3 s = _args.get<Vec3>("s", 0, &_lock); pbo->_args.copy(_args); _retval = getPyNone(); - pbo->save(name); + pbo->scale(s); pbo->_args.check(); } - pbFinalizePlugin(pbo->getParent(), "Mesh::save", !noTiming); + pbFinalizePlugin(pbo->getParent(), "Mesh::scale", !noTiming); return _retval; } catch (std::exception &e) { - pbSetError("Mesh::save", e.what()); + pbSetError("Mesh::scale", e.what()); return 0; } } - void advectInGrid(FlagGrid &flags, MACGrid &vel, int integrationMode); + void offset(Vec3 o); static PyObject *_W_5(PyObject *_self, PyObject *_linargs, PyObject *_kwds) { try { PbArgs _args(_linargs, _kwds); Mesh *pbo = dynamic_cast<Mesh *>(Pb::objFromPy(_self)); bool noTiming = _args.getOpt<bool>("notiming", -1, 0); - pbPreparePlugin(pbo->getParent(), "Mesh::advectInGrid", !noTiming); + pbPreparePlugin(pbo->getParent(), "Mesh::offset", !noTiming); PyObject *_retval = 0; { ArgLocker _lock; - FlagGrid &flags = *_args.getPtr<FlagGrid>("flags", 0, &_lock); - MACGrid &vel = *_args.getPtr<MACGrid>("vel", 1, &_lock); - int integrationMode = _args.get<int>("integrationMode", 2, &_lock); + Vec3 o = _args.get<Vec3>("o", 0, &_lock); pbo->_args.copy(_args); _retval = getPyNone(); - pbo->advectInGrid(flags, vel, integrationMode); + pbo->offset(o); pbo->_args.check(); } - pbFinalizePlugin(pbo->getParent(), "Mesh::advectInGrid", !noTiming); + pbFinalizePlugin(pbo->getParent(), "Mesh::offset", !noTiming); return _retval; } catch (std::exception &e) { - pbSetError("Mesh::advectInGrid", e.what()); + pbSetError("Mesh::offset", e.what()); return 0; } } - void scale(Vec3 s); + void rotate(Vec3 thetas); static PyObject *_W_6(PyObject *_self, PyObject *_linargs, PyObject *_kwds) { try { PbArgs _args(_linargs, _kwds); Mesh *pbo = dynamic_cast<Mesh *>(Pb::objFromPy(_self)); bool noTiming = _args.getOpt<bool>("notiming", -1, 0); - pbPreparePlugin(pbo->getParent(), "Mesh::scale", !noTiming); + pbPreparePlugin(pbo->getParent(), "Mesh::rotate", !noTiming); PyObject *_retval = 0; { ArgLocker _lock; - Vec3 s = _args.get<Vec3>("s", 0, &_lock); + Vec3 thetas = _args.get<Vec3>("thetas", 0, &_lock); pbo->_args.copy(_args); _retval = getPyNone(); - pbo->scale(s); + pbo->rotate(thetas); pbo->_args.check(); } - pbFinalizePlugin(pbo->getParent(), "Mesh::scale", !noTiming); + pbFinalizePlugin(pbo->getParent(), "Mesh::rotate", !noTiming); return _retval; } catch (std::exception &e) { - pbSetError("Mesh::scale", e.what()); + pbSetError("Mesh::rotate", e.what()); return 0; } } - void offset(Vec3 o); + void computeVelocity(Mesh &oldMesh, MACGrid &vel); static PyObject *_W_7(PyObject *_self, PyObject *_linargs, PyObject *_kwds) { try { PbArgs _args(_linargs, _kwds); Mesh *pbo = dynamic_cast<Mesh *>(Pb::objFromPy(_self)); bool noTiming = _args.getOpt<bool>("notiming", -1, 0); - pbPreparePlugin(pbo->getParent(), "Mesh::offset", !noTiming); + pbPreparePlugin(pbo->getParent(), "Mesh::computeVelocity", !noTiming); PyObject *_retval = 0; { ArgLocker _lock; - Vec3 o = _args.get<Vec3>("o", 0, &_lock); + Mesh &oldMesh = *_args.getPtr<Mesh>("oldMesh", 0, &_lock); + MACGrid &vel = *_args.getPtr<MACGrid>("vel", 1, &_lock); pbo->_args.copy(_args); _retval = getPyNone(); - pbo->offset(o); + pbo->computeVelocity(oldMesh, vel); pbo->_args.check(); } - pbFinalizePlugin(pbo->getParent(), "Mesh::offset", !noTiming); + pbFinalizePlugin(pbo->getParent(), "Mesh::computeVelocity", !noTiming); return _retval; } catch (std::exception &e) { - pbSetError("Mesh::offset", e.what()); + pbSetError("Mesh::computeVelocity", e.what()); return 0; } } - void rotate(Vec3 thetas); + //! file io + int load(std::string name, bool append = false); static PyObject *_W_8(PyObject *_self, PyObject *_linargs, PyObject *_kwds) { try { PbArgs _args(_linargs, _kwds); Mesh *pbo = dynamic_cast<Mesh *>(Pb::objFromPy(_self)); bool noTiming = _args.getOpt<bool>("notiming", -1, 0); - pbPreparePlugin(pbo->getParent(), "Mesh::rotate", !noTiming); + pbPreparePlugin(pbo->getParent(), "Mesh::load", !noTiming); PyObject *_retval = 0; { ArgLocker _lock; - Vec3 thetas = _args.get<Vec3>("thetas", 0, &_lock); + std::string name = _args.get<std::string>("name", 0, &_lock); + bool append = _args.getOpt<bool>("append", 1, false, &_lock); pbo->_args.copy(_args); - _retval = getPyNone(); - pbo->rotate(thetas); + _retval = toPy(pbo->load(name, append)); pbo->_args.check(); } - pbFinalizePlugin(pbo->getParent(), "Mesh::rotate", !noTiming); + pbFinalizePlugin(pbo->getParent(), "Mesh::load", !noTiming); return _retval; } catch (std::exception &e) { - pbSetError("Mesh::rotate", e.what()); + pbSetError("Mesh::load", e.what()); return 0; } } - void computeVelocity(Mesh &oldMesh, MACGrid &vel); + int save(std::string name); static PyObject *_W_9(PyObject *_self, PyObject *_linargs, PyObject *_kwds) { try { PbArgs _args(_linargs, _kwds); Mesh *pbo = dynamic_cast<Mesh *>(Pb::objFromPy(_self)); bool noTiming = _args.getOpt<bool>("notiming", -1, 0); - pbPreparePlugin(pbo->getParent(), "Mesh::computeVelocity", !noTiming); + pbPreparePlugin(pbo->getParent(), "Mesh::save", !noTiming); PyObject *_retval = 0; { ArgLocker _lock; - Mesh &oldMesh = *_args.getPtr<Mesh>("oldMesh", 0, &_lock); - MACGrid &vel = *_args.getPtr<MACGrid>("vel", 1, &_lock); + std::string name = _args.get<std::string>("name", 0, &_lock); pbo->_args.copy(_args); - _retval = getPyNone(); - pbo->computeVelocity(oldMesh, vel); + _retval = toPy(pbo->save(name)); pbo->_args.check(); } - pbFinalizePlugin(pbo->getParent(), "Mesh::computeVelocity", !noTiming); + pbFinalizePlugin(pbo->getParent(), "Mesh::save", !noTiming); return _retval; } catch (std::exception &e) { - pbSetError("Mesh::computeVelocity", e.what()); + pbSetError("Mesh::save", e.what()); return 0; } } @@ -1564,7 +1563,7 @@ template<class T> class MeshDataImpl : public MeshDataBase { } //! file io - void save(const std::string name); + int save(const std::string name); static PyObject *_W_41(PyObject *_self, PyObject *_linargs, PyObject *_kwds) { try { @@ -1577,8 +1576,7 @@ template<class T> class MeshDataImpl : public MeshDataBase { ArgLocker _lock; const std::string name = _args.get<std::string>("name", 0, &_lock); pbo->_args.copy(_args); - _retval = getPyNone(); - pbo->save(name); + _retval = toPy(pbo->save(name)); pbo->_args.check(); } pbFinalizePlugin(pbo->getParent(), "MeshDataImpl::save", !noTiming); @@ -1590,7 +1588,7 @@ template<class T> class MeshDataImpl : public MeshDataBase { } } - void load(const std::string name); + int load(const std::string name); static PyObject *_W_42(PyObject *_self, PyObject *_linargs, PyObject *_kwds) { try { @@ -1603,8 +1601,7 @@ template<class T> class MeshDataImpl : public MeshDataBase { ArgLocker _lock; const std::string name = _args.get<std::string>("name", 0, &_lock); pbo->_args.copy(_args); - _retval = getPyNone(); - pbo->load(name); + _retval = toPy(pbo->load(name)); pbo->_args.check(); } pbFinalizePlugin(pbo->getParent(), "MeshDataImpl::load", !noTiming); diff --git a/extern/mantaflow/preprocessed/mesh.h.reg.cpp b/extern/mantaflow/preprocessed/mesh.h.reg.cpp index b2ba3e22032..664e4c3ff6e 100644 --- a/extern/mantaflow/preprocessed/mesh.h.reg.cpp +++ b/extern/mantaflow/preprocessed/mesh.h.reg.cpp @@ -10,14 +10,14 @@ static const Pb::Register _R_12("Mesh", "Mesh", "PbClass"); template<> const char *Namify<Mesh>::S = "Mesh"; static const Pb::Register _R_13("Mesh", "Mesh", Mesh::_W_0); static const Pb::Register _R_14("Mesh", "clear", Mesh::_W_1); -static const Pb::Register _R_15("Mesh", "load", Mesh::_W_2); -static const Pb::Register _R_16("Mesh", "fromShape", Mesh::_W_3); -static const Pb::Register _R_17("Mesh", "save", Mesh::_W_4); -static const Pb::Register _R_18("Mesh", "advectInGrid", Mesh::_W_5); -static const Pb::Register _R_19("Mesh", "scale", Mesh::_W_6); -static const Pb::Register _R_20("Mesh", "offset", Mesh::_W_7); -static const Pb::Register _R_21("Mesh", "rotate", Mesh::_W_8); -static const Pb::Register _R_22("Mesh", "computeVelocity", Mesh::_W_9); +static const Pb::Register _R_15("Mesh", "fromShape", Mesh::_W_2); +static const Pb::Register _R_16("Mesh", "advectInGrid", Mesh::_W_3); +static const Pb::Register _R_17("Mesh", "scale", Mesh::_W_4); +static const Pb::Register _R_18("Mesh", "offset", Mesh::_W_5); +static const Pb::Register _R_19("Mesh", "rotate", Mesh::_W_6); +static const Pb::Register _R_20("Mesh", "computeVelocity", Mesh::_W_7); +static const Pb::Register _R_21("Mesh", "load", Mesh::_W_8); +static const Pb::Register _R_22("Mesh", "save", Mesh::_W_9); static const Pb::Register _R_23("Mesh", "computeLevelset", Mesh::_W_10); static const Pb::Register _R_24("Mesh", "getLevelset", Mesh::_W_11); static const Pb::Register _R_25("Mesh", "applyMeshToGrid", Mesh::_W_12); diff --git a/extern/mantaflow/preprocessed/particle.cpp b/extern/mantaflow/preprocessed/particle.cpp index c719fc8f27d..8c26156358d 100644 --- a/extern/mantaflow/preprocessed/particle.cpp +++ b/extern/mantaflow/preprocessed/particle.cpp @@ -29,7 +29,7 @@ using namespace std; namespace Manta { ParticleBase::ParticleBase(FluidSolver *parent) - : PbClass(parent), mAllowCompress(true), mFreePdata(false) + : PbClass(parent), mMaxParticles(0), mAllowCompress(true), mFreePdata(false) { } @@ -359,8 +359,8 @@ template<class T> void ParticleDataImpl<T>::setSource(Grid<T> *grid, bool isMAC) { mpGridSource = grid; mGridSourceMAC = isMAC; - if (isMAC) - assertMsg(dynamic_cast<MACGrid *>(grid) != NULL, "Given grid is not a valid MAC grid"); + if (grid && isMAC) + assertMsg(grid->getType() & GridBase::TypeMAC, "Given grid is not a valid MAC grid"); } template<class T> void ParticleDataImpl<T>::initNewValue(IndexInt idx, Vec3 pos) diff --git a/extern/mantaflow/preprocessed/particle.h b/extern/mantaflow/preprocessed/particle.h index 0be141ed26f..da6733b6845 100644 --- a/extern/mantaflow/preprocessed/particle.h +++ b/extern/mantaflow/preprocessed/particle.h @@ -100,6 +100,17 @@ class ParticleBase : public PbClass { //! threads) inline void addBuffered(const Vec3 &pos, int flag = 0); + virtual void resize(IndexInt size) + { + assertMsg(false, "Dont use, override..."); + return; + } + virtual void resizeAll(IndexInt size) + { + assertMsg(false, "Dont use, override..."); + return; + } + //! particle data functions //! create a particle data object @@ -152,6 +163,20 @@ class ParticleBase : public PbClass { return mPartData[i]; } + //! expose maximum number of particles to python + int mMaxParticles; + static PyObject *_GET_mMaxParticles(PyObject *self, void *cl) + { + ParticleBase *pbo = dynamic_cast<ParticleBase *>(Pb::objFromPy(self)); + return toPy(pbo->mMaxParticles); + } + static int _SET_mMaxParticles(PyObject *self, PyObject *val, void *cl) + { + ParticleBase *pbo = dynamic_cast<ParticleBase *>(Pb::objFromPy(self)); + pbo->mMaxParticles = fromPy<int>(val); + return 0; + } + protected: //! new particle candidates std::vector<Vec3> mNewBufferPos; @@ -431,8 +456,14 @@ template<class S> class ParticleSystem : public ParticleBase { } //! insert buffered positions as new particles, update additional particle data void insertBufferedParticles(); + //! resize only the data vector, only use if you know what you're doing, otherwise use + //! resizeAll() + virtual void resize(IndexInt size) + { + mData.resize(size); + } //! resize data vector, and all pdata fields - void resizeAll(IndexInt newsize); + virtual void resizeAll(IndexInt size); //! adding and deleting inline void kill(IndexInt idx); @@ -877,11 +908,6 @@ class ParticleIndexSystem : public ParticleSystem<ParticleIndexData> { return -1; } }; - //! we only need a resize function... - void resize(IndexInt size) - { - mData.resize(size); - } public: PbArgs _args; } @@ -2479,28 +2505,66 @@ template<class S> void ParticleSystem<S>::insertBufferedParticles() for (IndexInt i = 0; i < (IndexInt)mData.size(); ++i) mData[i].flag &= ~PNEW; - if (mNewBufferPos.size() == 0) + if (mNewBufferPos.empty()) return; - IndexInt newCnt = mData.size(); - resizeAll(newCnt + mNewBufferPos.size()); - - for (IndexInt i = 0; i < (IndexInt)mNewBufferPos.size(); ++i) { - int flag = (mNewBufferFlag.size() > 0) ? mNewBufferFlag[i] : 0; - // note, other fields are not initialized here... - mData[newCnt].pos = mNewBufferPos[i]; - mData[newCnt].flag = PNEW | flag; + IndexInt bufferSize = mNewBufferPos.size(); + IndexInt partsSize = mData.size(); + + if (mMaxParticles > 0) + assertMsg(mMaxParticles >= partsSize, + "Particle system cannot contain more particles that the maximum allowed number"); + + // max number of new particles that can be inserted, adjusted buffer size when using maxParticles + // field + IndexInt numNewParts = (mMaxParticles > 0) ? mMaxParticles - mData.size() : bufferSize; + if (numNewParts > bufferSize) + numNewParts = bufferSize; // upper clamp + + assertMsg(numNewParts >= 0, "Must not have negative number of new particles"); + + // new size of particle system + IndexInt newSize = mData.size() + numNewParts; + if (mMaxParticles > 0) + assertMsg(newSize <= mMaxParticles, + "Particle system cannot contain more particles that the maximum allowed number"); + resizeAll(newSize); + + int insertFlag; + Vec3 insertPos; + static RandomStream mRand(9832); + for (IndexInt i = 0; i < numNewParts; ++i) { + + // get random index in newBuffer vector + // we are inserting particles randomly so that they are sampled uniformly in the fluid region + // otherwise, regions of fluid can remain completely empty once mData.size() == maxParticles is + // reached. + int randIndex = floor(mRand.getReal() * mNewBufferPos.size()); + + // get elements from new buffers with random index + std::swap(mNewBufferPos[randIndex], mNewBufferPos.back()); + insertPos = mNewBufferPos.back(); + mNewBufferPos.pop_back(); + + insertFlag = 0; + if (!mNewBufferFlag.empty()) { + std::swap(mNewBufferFlag[randIndex], mNewBufferFlag.back()); + insertFlag = mNewBufferFlag.back(); + mNewBufferFlag.pop_back(); + } + + mData[partsSize].pos = insertPos; + mData[partsSize].flag = PNEW | insertFlag; + // now init pdata fields from associated grids... for (IndexInt pd = 0; pd < (IndexInt)mPdataReal.size(); ++pd) - mPdataReal[pd]->initNewValue(newCnt, mNewBufferPos[i]); + mPdataReal[pd]->initNewValue(partsSize, insertPos); for (IndexInt pd = 0; pd < (IndexInt)mPdataVec3.size(); ++pd) - mPdataVec3[pd]->initNewValue(newCnt, mNewBufferPos[i]); + mPdataVec3[pd]->initNewValue(partsSize, insertPos); for (IndexInt pd = 0; pd < (IndexInt)mPdataInt.size(); ++pd) - mPdataInt[pd]->initNewValue(newCnt, mNewBufferPos[i]); - newCnt++; + mPdataInt[pd]->initNewValue(partsSize, insertPos); + partsSize++; } - if (mNewBufferPos.size() > 0) - debMsg("Added & initialized " << (IndexInt)mNewBufferPos.size() << " particles", - 2); // debug info + debMsg("Added & initialized " << numNewParts << " particles", 2); // debug info mNewBufferPos.clear(); mNewBufferFlag.clear(); } diff --git a/extern/mantaflow/preprocessed/particle.h.reg.cpp b/extern/mantaflow/preprocessed/particle.h.reg.cpp index 6e0466d0203..e9e538ad097 100644 --- a/extern/mantaflow/preprocessed/particle.h.reg.cpp +++ b/extern/mantaflow/preprocessed/particle.h.reg.cpp @@ -29,279 +29,283 @@ static const Pb::Register _R_21("ParticleBase", "ParticleBase", "PbClass"); template<> const char *Namify<ParticleBase>::S = "ParticleBase"; static const Pb::Register _R_22("ParticleBase", "ParticleBase", ParticleBase::_W_0); static const Pb::Register _R_23("ParticleBase", "create", ParticleBase::_W_1); +static const Pb::Register _R_24("ParticleBase", + "maxParticles", + ParticleBase::_GET_mMaxParticles, + ParticleBase::_SET_mMaxParticles); #endif #ifdef _C_ParticleDataBase -static const Pb::Register _R_24("ParticleDataBase", "ParticleDataBase", "PbClass"); +static const Pb::Register _R_25("ParticleDataBase", "ParticleDataBase", "PbClass"); template<> const char *Namify<ParticleDataBase>::S = "ParticleDataBase"; -static const Pb::Register _R_25("ParticleDataBase", "ParticleDataBase", ParticleDataBase::_W_21); +static const Pb::Register _R_26("ParticleDataBase", "ParticleDataBase", ParticleDataBase::_W_21); #endif #ifdef _C_ParticleDataImpl -static const Pb::Register _R_26("ParticleDataImpl<int>", +static const Pb::Register _R_27("ParticleDataImpl<int>", "ParticleDataImpl<int>", "ParticleDataBase"); template<> const char *Namify<ParticleDataImpl<int>>::S = "ParticleDataImpl<int>"; -static const Pb::Register _R_27("ParticleDataImpl<int>", +static const Pb::Register _R_28("ParticleDataImpl<int>", "ParticleDataImpl", ParticleDataImpl<int>::_W_22); -static const Pb::Register _R_28("ParticleDataImpl<int>", "clear", ParticleDataImpl<int>::_W_23); -static const Pb::Register _R_29("ParticleDataImpl<int>", +static const Pb::Register _R_29("ParticleDataImpl<int>", "clear", ParticleDataImpl<int>::_W_23); +static const Pb::Register _R_30("ParticleDataImpl<int>", "setSource", ParticleDataImpl<int>::_W_24); -static const Pb::Register _R_30("ParticleDataImpl<int>", "copyFrom", ParticleDataImpl<int>::_W_25); -static const Pb::Register _R_31("ParticleDataImpl<int>", "setConst", ParticleDataImpl<int>::_W_26); -static const Pb::Register _R_32("ParticleDataImpl<int>", +static const Pb::Register _R_31("ParticleDataImpl<int>", "copyFrom", ParticleDataImpl<int>::_W_25); +static const Pb::Register _R_32("ParticleDataImpl<int>", "setConst", ParticleDataImpl<int>::_W_26); +static const Pb::Register _R_33("ParticleDataImpl<int>", "setConstRange", ParticleDataImpl<int>::_W_27); -static const Pb::Register _R_33("ParticleDataImpl<int>", "add", ParticleDataImpl<int>::_W_28); -static const Pb::Register _R_34("ParticleDataImpl<int>", "sub", ParticleDataImpl<int>::_W_29); -static const Pb::Register _R_35("ParticleDataImpl<int>", "addConst", ParticleDataImpl<int>::_W_30); -static const Pb::Register _R_36("ParticleDataImpl<int>", +static const Pb::Register _R_34("ParticleDataImpl<int>", "add", ParticleDataImpl<int>::_W_28); +static const Pb::Register _R_35("ParticleDataImpl<int>", "sub", ParticleDataImpl<int>::_W_29); +static const Pb::Register _R_36("ParticleDataImpl<int>", "addConst", ParticleDataImpl<int>::_W_30); +static const Pb::Register _R_37("ParticleDataImpl<int>", "addScaled", ParticleDataImpl<int>::_W_31); -static const Pb::Register _R_37("ParticleDataImpl<int>", "mult", ParticleDataImpl<int>::_W_32); -static const Pb::Register _R_38("ParticleDataImpl<int>", +static const Pb::Register _R_38("ParticleDataImpl<int>", "mult", ParticleDataImpl<int>::_W_32); +static const Pb::Register _R_39("ParticleDataImpl<int>", "multConst", ParticleDataImpl<int>::_W_33); -static const Pb::Register _R_39("ParticleDataImpl<int>", "safeDiv", ParticleDataImpl<int>::_W_34); -static const Pb::Register _R_40("ParticleDataImpl<int>", "clamp", ParticleDataImpl<int>::_W_35); -static const Pb::Register _R_41("ParticleDataImpl<int>", "clampMin", ParticleDataImpl<int>::_W_36); -static const Pb::Register _R_42("ParticleDataImpl<int>", "clampMax", ParticleDataImpl<int>::_W_37); -static const Pb::Register _R_43("ParticleDataImpl<int>", +static const Pb::Register _R_40("ParticleDataImpl<int>", "safeDiv", ParticleDataImpl<int>::_W_34); +static const Pb::Register _R_41("ParticleDataImpl<int>", "clamp", ParticleDataImpl<int>::_W_35); +static const Pb::Register _R_42("ParticleDataImpl<int>", "clampMin", ParticleDataImpl<int>::_W_36); +static const Pb::Register _R_43("ParticleDataImpl<int>", "clampMax", ParticleDataImpl<int>::_W_37); +static const Pb::Register _R_44("ParticleDataImpl<int>", "getMaxAbs", ParticleDataImpl<int>::_W_38); -static const Pb::Register _R_44("ParticleDataImpl<int>", "getMax", ParticleDataImpl<int>::_W_39); -static const Pb::Register _R_45("ParticleDataImpl<int>", "getMin", ParticleDataImpl<int>::_W_40); -static const Pb::Register _R_46("ParticleDataImpl<int>", "sum", ParticleDataImpl<int>::_W_41); -static const Pb::Register _R_47("ParticleDataImpl<int>", +static const Pb::Register _R_45("ParticleDataImpl<int>", "getMax", ParticleDataImpl<int>::_W_39); +static const Pb::Register _R_46("ParticleDataImpl<int>", "getMin", ParticleDataImpl<int>::_W_40); +static const Pb::Register _R_47("ParticleDataImpl<int>", "sum", ParticleDataImpl<int>::_W_41); +static const Pb::Register _R_48("ParticleDataImpl<int>", "sumSquare", ParticleDataImpl<int>::_W_42); -static const Pb::Register _R_48("ParticleDataImpl<int>", +static const Pb::Register _R_49("ParticleDataImpl<int>", "sumMagnitude", ParticleDataImpl<int>::_W_43); -static const Pb::Register _R_49("ParticleDataImpl<int>", +static const Pb::Register _R_50("ParticleDataImpl<int>", "setConstIntFlag", ParticleDataImpl<int>::_W_44); -static const Pb::Register _R_50("ParticleDataImpl<int>", +static const Pb::Register _R_51("ParticleDataImpl<int>", "printPdata", ParticleDataImpl<int>::_W_45); -static const Pb::Register _R_51("ParticleDataImpl<int>", "save", ParticleDataImpl<int>::_W_46); -static const Pb::Register _R_52("ParticleDataImpl<int>", "load", ParticleDataImpl<int>::_W_47); -static const Pb::Register _R_53("ParticleDataImpl<int>", +static const Pb::Register _R_52("ParticleDataImpl<int>", "save", ParticleDataImpl<int>::_W_46); +static const Pb::Register _R_53("ParticleDataImpl<int>", "load", ParticleDataImpl<int>::_W_47); +static const Pb::Register _R_54("ParticleDataImpl<int>", "getDataPointer", ParticleDataImpl<int>::_W_48); -static const Pb::Register _R_54("ParticleDataImpl<Real>", +static const Pb::Register _R_55("ParticleDataImpl<Real>", "ParticleDataImpl<Real>", "ParticleDataBase"); template<> const char *Namify<ParticleDataImpl<Real>>::S = "ParticleDataImpl<Real>"; -static const Pb::Register _R_55("ParticleDataImpl<Real>", +static const Pb::Register _R_56("ParticleDataImpl<Real>", "ParticleDataImpl", ParticleDataImpl<Real>::_W_22); -static const Pb::Register _R_56("ParticleDataImpl<Real>", "clear", ParticleDataImpl<Real>::_W_23); -static const Pb::Register _R_57("ParticleDataImpl<Real>", +static const Pb::Register _R_57("ParticleDataImpl<Real>", "clear", ParticleDataImpl<Real>::_W_23); +static const Pb::Register _R_58("ParticleDataImpl<Real>", "setSource", ParticleDataImpl<Real>::_W_24); -static const Pb::Register _R_58("ParticleDataImpl<Real>", +static const Pb::Register _R_59("ParticleDataImpl<Real>", "copyFrom", ParticleDataImpl<Real>::_W_25); -static const Pb::Register _R_59("ParticleDataImpl<Real>", +static const Pb::Register _R_60("ParticleDataImpl<Real>", "setConst", ParticleDataImpl<Real>::_W_26); -static const Pb::Register _R_60("ParticleDataImpl<Real>", +static const Pb::Register _R_61("ParticleDataImpl<Real>", "setConstRange", ParticleDataImpl<Real>::_W_27); -static const Pb::Register _R_61("ParticleDataImpl<Real>", "add", ParticleDataImpl<Real>::_W_28); -static const Pb::Register _R_62("ParticleDataImpl<Real>", "sub", ParticleDataImpl<Real>::_W_29); -static const Pb::Register _R_63("ParticleDataImpl<Real>", +static const Pb::Register _R_62("ParticleDataImpl<Real>", "add", ParticleDataImpl<Real>::_W_28); +static const Pb::Register _R_63("ParticleDataImpl<Real>", "sub", ParticleDataImpl<Real>::_W_29); +static const Pb::Register _R_64("ParticleDataImpl<Real>", "addConst", ParticleDataImpl<Real>::_W_30); -static const Pb::Register _R_64("ParticleDataImpl<Real>", +static const Pb::Register _R_65("ParticleDataImpl<Real>", "addScaled", ParticleDataImpl<Real>::_W_31); -static const Pb::Register _R_65("ParticleDataImpl<Real>", "mult", ParticleDataImpl<Real>::_W_32); -static const Pb::Register _R_66("ParticleDataImpl<Real>", +static const Pb::Register _R_66("ParticleDataImpl<Real>", "mult", ParticleDataImpl<Real>::_W_32); +static const Pb::Register _R_67("ParticleDataImpl<Real>", "multConst", ParticleDataImpl<Real>::_W_33); -static const Pb::Register _R_67("ParticleDataImpl<Real>", +static const Pb::Register _R_68("ParticleDataImpl<Real>", "safeDiv", ParticleDataImpl<Real>::_W_34); -static const Pb::Register _R_68("ParticleDataImpl<Real>", "clamp", ParticleDataImpl<Real>::_W_35); -static const Pb::Register _R_69("ParticleDataImpl<Real>", +static const Pb::Register _R_69("ParticleDataImpl<Real>", "clamp", ParticleDataImpl<Real>::_W_35); +static const Pb::Register _R_70("ParticleDataImpl<Real>", "clampMin", ParticleDataImpl<Real>::_W_36); -static const Pb::Register _R_70("ParticleDataImpl<Real>", +static const Pb::Register _R_71("ParticleDataImpl<Real>", "clampMax", ParticleDataImpl<Real>::_W_37); -static const Pb::Register _R_71("ParticleDataImpl<Real>", +static const Pb::Register _R_72("ParticleDataImpl<Real>", "getMaxAbs", ParticleDataImpl<Real>::_W_38); -static const Pb::Register _R_72("ParticleDataImpl<Real>", "getMax", ParticleDataImpl<Real>::_W_39); -static const Pb::Register _R_73("ParticleDataImpl<Real>", "getMin", ParticleDataImpl<Real>::_W_40); -static const Pb::Register _R_74("ParticleDataImpl<Real>", "sum", ParticleDataImpl<Real>::_W_41); -static const Pb::Register _R_75("ParticleDataImpl<Real>", +static const Pb::Register _R_73("ParticleDataImpl<Real>", "getMax", ParticleDataImpl<Real>::_W_39); +static const Pb::Register _R_74("ParticleDataImpl<Real>", "getMin", ParticleDataImpl<Real>::_W_40); +static const Pb::Register _R_75("ParticleDataImpl<Real>", "sum", ParticleDataImpl<Real>::_W_41); +static const Pb::Register _R_76("ParticleDataImpl<Real>", "sumSquare", ParticleDataImpl<Real>::_W_42); -static const Pb::Register _R_76("ParticleDataImpl<Real>", +static const Pb::Register _R_77("ParticleDataImpl<Real>", "sumMagnitude", ParticleDataImpl<Real>::_W_43); -static const Pb::Register _R_77("ParticleDataImpl<Real>", +static const Pb::Register _R_78("ParticleDataImpl<Real>", "setConstIntFlag", ParticleDataImpl<Real>::_W_44); -static const Pb::Register _R_78("ParticleDataImpl<Real>", +static const Pb::Register _R_79("ParticleDataImpl<Real>", "printPdata", ParticleDataImpl<Real>::_W_45); -static const Pb::Register _R_79("ParticleDataImpl<Real>", "save", ParticleDataImpl<Real>::_W_46); -static const Pb::Register _R_80("ParticleDataImpl<Real>", "load", ParticleDataImpl<Real>::_W_47); -static const Pb::Register _R_81("ParticleDataImpl<Real>", +static const Pb::Register _R_80("ParticleDataImpl<Real>", "save", ParticleDataImpl<Real>::_W_46); +static const Pb::Register _R_81("ParticleDataImpl<Real>", "load", ParticleDataImpl<Real>::_W_47); +static const Pb::Register _R_82("ParticleDataImpl<Real>", "getDataPointer", ParticleDataImpl<Real>::_W_48); -static const Pb::Register _R_82("ParticleDataImpl<Vec3>", +static const Pb::Register _R_83("ParticleDataImpl<Vec3>", "ParticleDataImpl<Vec3>", "ParticleDataBase"); template<> const char *Namify<ParticleDataImpl<Vec3>>::S = "ParticleDataImpl<Vec3>"; -static const Pb::Register _R_83("ParticleDataImpl<Vec3>", +static const Pb::Register _R_84("ParticleDataImpl<Vec3>", "ParticleDataImpl", ParticleDataImpl<Vec3>::_W_22); -static const Pb::Register _R_84("ParticleDataImpl<Vec3>", "clear", ParticleDataImpl<Vec3>::_W_23); -static const Pb::Register _R_85("ParticleDataImpl<Vec3>", +static const Pb::Register _R_85("ParticleDataImpl<Vec3>", "clear", ParticleDataImpl<Vec3>::_W_23); +static const Pb::Register _R_86("ParticleDataImpl<Vec3>", "setSource", ParticleDataImpl<Vec3>::_W_24); -static const Pb::Register _R_86("ParticleDataImpl<Vec3>", +static const Pb::Register _R_87("ParticleDataImpl<Vec3>", "copyFrom", ParticleDataImpl<Vec3>::_W_25); -static const Pb::Register _R_87("ParticleDataImpl<Vec3>", +static const Pb::Register _R_88("ParticleDataImpl<Vec3>", "setConst", ParticleDataImpl<Vec3>::_W_26); -static const Pb::Register _R_88("ParticleDataImpl<Vec3>", +static const Pb::Register _R_89("ParticleDataImpl<Vec3>", "setConstRange", ParticleDataImpl<Vec3>::_W_27); -static const Pb::Register _R_89("ParticleDataImpl<Vec3>", "add", ParticleDataImpl<Vec3>::_W_28); -static const Pb::Register _R_90("ParticleDataImpl<Vec3>", "sub", ParticleDataImpl<Vec3>::_W_29); -static const Pb::Register _R_91("ParticleDataImpl<Vec3>", +static const Pb::Register _R_90("ParticleDataImpl<Vec3>", "add", ParticleDataImpl<Vec3>::_W_28); +static const Pb::Register _R_91("ParticleDataImpl<Vec3>", "sub", ParticleDataImpl<Vec3>::_W_29); +static const Pb::Register _R_92("ParticleDataImpl<Vec3>", "addConst", ParticleDataImpl<Vec3>::_W_30); -static const Pb::Register _R_92("ParticleDataImpl<Vec3>", +static const Pb::Register _R_93("ParticleDataImpl<Vec3>", "addScaled", ParticleDataImpl<Vec3>::_W_31); -static const Pb::Register _R_93("ParticleDataImpl<Vec3>", "mult", ParticleDataImpl<Vec3>::_W_32); -static const Pb::Register _R_94("ParticleDataImpl<Vec3>", +static const Pb::Register _R_94("ParticleDataImpl<Vec3>", "mult", ParticleDataImpl<Vec3>::_W_32); +static const Pb::Register _R_95("ParticleDataImpl<Vec3>", "multConst", ParticleDataImpl<Vec3>::_W_33); -static const Pb::Register _R_95("ParticleDataImpl<Vec3>", +static const Pb::Register _R_96("ParticleDataImpl<Vec3>", "safeDiv", ParticleDataImpl<Vec3>::_W_34); -static const Pb::Register _R_96("ParticleDataImpl<Vec3>", "clamp", ParticleDataImpl<Vec3>::_W_35); -static const Pb::Register _R_97("ParticleDataImpl<Vec3>", +static const Pb::Register _R_97("ParticleDataImpl<Vec3>", "clamp", ParticleDataImpl<Vec3>::_W_35); +static const Pb::Register _R_98("ParticleDataImpl<Vec3>", "clampMin", ParticleDataImpl<Vec3>::_W_36); -static const Pb::Register _R_98("ParticleDataImpl<Vec3>", +static const Pb::Register _R_99("ParticleDataImpl<Vec3>", "clampMax", ParticleDataImpl<Vec3>::_W_37); -static const Pb::Register _R_99("ParticleDataImpl<Vec3>", - "getMaxAbs", - ParticleDataImpl<Vec3>::_W_38); static const Pb::Register _R_100("ParticleDataImpl<Vec3>", + "getMaxAbs", + ParticleDataImpl<Vec3>::_W_38); +static const Pb::Register _R_101("ParticleDataImpl<Vec3>", "getMax", ParticleDataImpl<Vec3>::_W_39); -static const Pb::Register _R_101("ParticleDataImpl<Vec3>", +static const Pb::Register _R_102("ParticleDataImpl<Vec3>", "getMin", ParticleDataImpl<Vec3>::_W_40); -static const Pb::Register _R_102("ParticleDataImpl<Vec3>", "sum", ParticleDataImpl<Vec3>::_W_41); -static const Pb::Register _R_103("ParticleDataImpl<Vec3>", +static const Pb::Register _R_103("ParticleDataImpl<Vec3>", "sum", ParticleDataImpl<Vec3>::_W_41); +static const Pb::Register _R_104("ParticleDataImpl<Vec3>", "sumSquare", ParticleDataImpl<Vec3>::_W_42); -static const Pb::Register _R_104("ParticleDataImpl<Vec3>", +static const Pb::Register _R_105("ParticleDataImpl<Vec3>", "sumMagnitude", ParticleDataImpl<Vec3>::_W_43); -static const Pb::Register _R_105("ParticleDataImpl<Vec3>", +static const Pb::Register _R_106("ParticleDataImpl<Vec3>", "setConstIntFlag", ParticleDataImpl<Vec3>::_W_44); -static const Pb::Register _R_106("ParticleDataImpl<Vec3>", +static const Pb::Register _R_107("ParticleDataImpl<Vec3>", "printPdata", ParticleDataImpl<Vec3>::_W_45); -static const Pb::Register _R_107("ParticleDataImpl<Vec3>", "save", ParticleDataImpl<Vec3>::_W_46); -static const Pb::Register _R_108("ParticleDataImpl<Vec3>", "load", ParticleDataImpl<Vec3>::_W_47); -static const Pb::Register _R_109("ParticleDataImpl<Vec3>", +static const Pb::Register _R_108("ParticleDataImpl<Vec3>", "save", ParticleDataImpl<Vec3>::_W_46); +static const Pb::Register _R_109("ParticleDataImpl<Vec3>", "load", ParticleDataImpl<Vec3>::_W_47); +static const Pb::Register _R_110("ParticleDataImpl<Vec3>", "getDataPointer", ParticleDataImpl<Vec3>::_W_48); #endif #ifdef _C_ParticleIndexSystem -static const Pb::Register _R_110("ParticleIndexSystem", +static const Pb::Register _R_111("ParticleIndexSystem", "ParticleIndexSystem", "ParticleSystem<ParticleIndexData>"); template<> const char *Namify<ParticleIndexSystem>::S = "ParticleIndexSystem"; -static const Pb::Register _R_111("ParticleIndexSystem", +static const Pb::Register _R_112("ParticleIndexSystem", "ParticleIndexSystem", ParticleIndexSystem::_W_19); #endif #ifdef _C_ParticleSystem -static const Pb::Register _R_112("ParticleSystem<BasicParticleData>", +static const Pb::Register _R_113("ParticleSystem<BasicParticleData>", "ParticleSystem<BasicParticleData>", "ParticleBase"); template<> const char *Namify<ParticleSystem<BasicParticleData>>::S = "ParticleSystem<BasicParticleData>"; -static const Pb::Register _R_113("ParticleSystem<BasicParticleData>", +static const Pb::Register _R_114("ParticleSystem<BasicParticleData>", "ParticleSystem", ParticleSystem<BasicParticleData>::_W_2); -static const Pb::Register _R_114("ParticleSystem<BasicParticleData>", +static const Pb::Register _R_115("ParticleSystem<BasicParticleData>", "pySize", ParticleSystem<BasicParticleData>::_W_3); -static const Pb::Register _R_115("ParticleSystem<BasicParticleData>", +static const Pb::Register _R_116("ParticleSystem<BasicParticleData>", "setPos", ParticleSystem<BasicParticleData>::_W_4); -static const Pb::Register _R_116("ParticleSystem<BasicParticleData>", +static const Pb::Register _R_117("ParticleSystem<BasicParticleData>", "getPos", ParticleSystem<BasicParticleData>::_W_5); -static const Pb::Register _R_117("ParticleSystem<BasicParticleData>", +static const Pb::Register _R_118("ParticleSystem<BasicParticleData>", "getPosPdata", ParticleSystem<BasicParticleData>::_W_6); -static const Pb::Register _R_118("ParticleSystem<BasicParticleData>", +static const Pb::Register _R_119("ParticleSystem<BasicParticleData>", "setPosPdata", ParticleSystem<BasicParticleData>::_W_7); -static const Pb::Register _R_119("ParticleSystem<BasicParticleData>", +static const Pb::Register _R_120("ParticleSystem<BasicParticleData>", "clear", ParticleSystem<BasicParticleData>::_W_8); -static const Pb::Register _R_120("ParticleSystem<BasicParticleData>", +static const Pb::Register _R_121("ParticleSystem<BasicParticleData>", "advectInGrid", ParticleSystem<BasicParticleData>::_W_9); -static const Pb::Register _R_121("ParticleSystem<BasicParticleData>", +static const Pb::Register _R_122("ParticleSystem<BasicParticleData>", "projectOutside", ParticleSystem<BasicParticleData>::_W_10); -static const Pb::Register _R_122("ParticleSystem<BasicParticleData>", +static const Pb::Register _R_123("ParticleSystem<BasicParticleData>", "projectOutOfBnd", ParticleSystem<BasicParticleData>::_W_11); -static const Pb::Register _R_123("ParticleSystem<ParticleIndexData>", +static const Pb::Register _R_124("ParticleSystem<ParticleIndexData>", "ParticleSystem<ParticleIndexData>", "ParticleBase"); template<> const char *Namify<ParticleSystem<ParticleIndexData>>::S = "ParticleSystem<ParticleIndexData>"; -static const Pb::Register _R_124("ParticleSystem<ParticleIndexData>", +static const Pb::Register _R_125("ParticleSystem<ParticleIndexData>", "ParticleSystem", ParticleSystem<ParticleIndexData>::_W_2); -static const Pb::Register _R_125("ParticleSystem<ParticleIndexData>", +static const Pb::Register _R_126("ParticleSystem<ParticleIndexData>", "pySize", ParticleSystem<ParticleIndexData>::_W_3); -static const Pb::Register _R_126("ParticleSystem<ParticleIndexData>", +static const Pb::Register _R_127("ParticleSystem<ParticleIndexData>", "setPos", ParticleSystem<ParticleIndexData>::_W_4); -static const Pb::Register _R_127("ParticleSystem<ParticleIndexData>", +static const Pb::Register _R_128("ParticleSystem<ParticleIndexData>", "getPos", ParticleSystem<ParticleIndexData>::_W_5); -static const Pb::Register _R_128("ParticleSystem<ParticleIndexData>", +static const Pb::Register _R_129("ParticleSystem<ParticleIndexData>", "getPosPdata", ParticleSystem<ParticleIndexData>::_W_6); -static const Pb::Register _R_129("ParticleSystem<ParticleIndexData>", +static const Pb::Register _R_130("ParticleSystem<ParticleIndexData>", "setPosPdata", ParticleSystem<ParticleIndexData>::_W_7); -static const Pb::Register _R_130("ParticleSystem<ParticleIndexData>", +static const Pb::Register _R_131("ParticleSystem<ParticleIndexData>", "clear", ParticleSystem<ParticleIndexData>::_W_8); -static const Pb::Register _R_131("ParticleSystem<ParticleIndexData>", +static const Pb::Register _R_132("ParticleSystem<ParticleIndexData>", "advectInGrid", ParticleSystem<ParticleIndexData>::_W_9); -static const Pb::Register _R_132("ParticleSystem<ParticleIndexData>", +static const Pb::Register _R_133("ParticleSystem<ParticleIndexData>", "projectOutside", ParticleSystem<ParticleIndexData>::_W_10); -static const Pb::Register _R_133("ParticleSystem<ParticleIndexData>", +static const Pb::Register _R_134("ParticleSystem<ParticleIndexData>", "projectOutOfBnd", ParticleSystem<ParticleIndexData>::_W_11); #endif @@ -432,6 +436,7 @@ void PbRegister_file_10() KEEP_UNUSED(_R_131); KEEP_UNUSED(_R_132); KEEP_UNUSED(_R_133); + KEEP_UNUSED(_R_134); } } } // namespace Manta
\ No newline at end of file diff --git a/extern/mantaflow/preprocessed/plugin/initplugins.cpp b/extern/mantaflow/preprocessed/plugin/initplugins.cpp index 7a765813f9f..6ccd3afc8d1 100644 --- a/extern/mantaflow/preprocessed/plugin/initplugins.cpp +++ b/extern/mantaflow/preprocessed/plugin/initplugins.cpp @@ -1479,48 +1479,24 @@ void PbRegister_addTestParts() } //! calculate the difference between two pdata fields (note - slow!, not parallelized) - -Real pdataMaxDiff(const ParticleDataBase *a, const ParticleDataBase *b) +template<class T> Real getPdataMaxDiff(const ParticleDataImpl<T> *a, const ParticleDataImpl<T> *b) { - double maxVal = 0.; - // debMsg(" PD "<< a->getType()<<" as"<<a->getSizeSlow()<<" bs"<<b->getSizeSlow() , 1); assertMsg(a->getType() == b->getType(), "pdataMaxDiff problem - different pdata types!"); assertMsg(a->getSizeSlow() == b->getSizeSlow(), "pdataMaxDiff problem - different pdata sizes!"); - if (a->getType() & ParticleDataBase::TypeReal) { - const ParticleDataImpl<Real> &av = *dynamic_cast<const ParticleDataImpl<Real> *>(a); - const ParticleDataImpl<Real> &bv = *dynamic_cast<const ParticleDataImpl<Real> *>(b); - FOR_PARTS(av) - { - maxVal = std::max(maxVal, (double)fabs(av[idx] - bv[idx])); - } - } - else if (a->getType() & ParticleDataBase::TypeInt) { - const ParticleDataImpl<int> &av = *dynamic_cast<const ParticleDataImpl<int> *>(a); - const ParticleDataImpl<int> &bv = *dynamic_cast<const ParticleDataImpl<int> *>(b); - FOR_PARTS(av) - { - maxVal = std::max(maxVal, (double)fabs((double)av[idx] - bv[idx])); - } - } - else if (a->getType() & ParticleDataBase::TypeVec3) { - const ParticleDataImpl<Vec3> &av = *dynamic_cast<const ParticleDataImpl<Vec3> *>(a); - const ParticleDataImpl<Vec3> &bv = *dynamic_cast<const ParticleDataImpl<Vec3> *>(b); - FOR_PARTS(av) - { - double d = 0.; - for (int c = 0; c < 3; ++c) { - d += fabs((double)av[idx][c] - (double)bv[idx][c]); - } - maxVal = std::max(maxVal, d); - } - } - else { - errMsg("pdataMaxDiff: Grid Type is not supported (only Real, Vec3, int)"); + Real maxVal = 0.; + FOR_PARTS(*a) + { + T diff = a->get(idx) - b->get(idx); + Real s = (Real)sum(abs(diff)); + maxVal = std::max(maxVal, s); } - return maxVal; } +Real pdataMaxDiff(const ParticleDataImpl<Real> *a, const ParticleDataImpl<Real> *b) +{ + return getPdataMaxDiff(a, b); +} static PyObject *_W_15(PyObject *_self, PyObject *_linargs, PyObject *_kwds) { try { @@ -1531,8 +1507,8 @@ static PyObject *_W_15(PyObject *_self, PyObject *_linargs, PyObject *_kwds) PyObject *_retval = 0; { ArgLocker _lock; - const ParticleDataBase *a = _args.getPtr<ParticleDataBase>("a", 0, &_lock); - const ParticleDataBase *b = _args.getPtr<ParticleDataBase>("b", 1, &_lock); + const ParticleDataImpl<Real> *a = _args.getPtr<ParticleDataImpl<Real>>("a", 0, &_lock); + const ParticleDataImpl<Real> *b = _args.getPtr<ParticleDataImpl<Real>>("b", 1, &_lock); _retval = toPy(pdataMaxDiff(a, b)); _args.check(); } @@ -1552,6 +1528,76 @@ void PbRegister_pdataMaxDiff() } } +Real pdataMaxDiffInt(const ParticleDataImpl<int> *a, const ParticleDataImpl<int> *b) +{ + return getPdataMaxDiff(a, b); +} +static PyObject *_W_16(PyObject *_self, PyObject *_linargs, PyObject *_kwds) +{ + try { + PbArgs _args(_linargs, _kwds); + FluidSolver *parent = _args.obtainParent(); + bool noTiming = _args.getOpt<bool>("notiming", -1, 0); + pbPreparePlugin(parent, "pdataMaxDiffInt", !noTiming); + PyObject *_retval = 0; + { + ArgLocker _lock; + const ParticleDataImpl<int> *a = _args.getPtr<ParticleDataImpl<int>>("a", 0, &_lock); + const ParticleDataImpl<int> *b = _args.getPtr<ParticleDataImpl<int>>("b", 1, &_lock); + _retval = toPy(pdataMaxDiffInt(a, b)); + _args.check(); + } + pbFinalizePlugin(parent, "pdataMaxDiffInt", !noTiming); + return _retval; + } + catch (std::exception &e) { + pbSetError("pdataMaxDiffInt", e.what()); + return 0; + } +} +static const Pb::Register _RP_pdataMaxDiffInt("", "pdataMaxDiffInt", _W_16); +extern "C" { +void PbRegister_pdataMaxDiffInt() +{ + KEEP_UNUSED(_RP_pdataMaxDiffInt); +} +} + +Real pdataMaxDiffVec3(const ParticleDataImpl<Vec3> *a, const ParticleDataImpl<Vec3> *b) +{ + return getPdataMaxDiff(a, b); +} +static PyObject *_W_17(PyObject *_self, PyObject *_linargs, PyObject *_kwds) +{ + try { + PbArgs _args(_linargs, _kwds); + FluidSolver *parent = _args.obtainParent(); + bool noTiming = _args.getOpt<bool>("notiming", -1, 0); + pbPreparePlugin(parent, "pdataMaxDiffVec3", !noTiming); + PyObject *_retval = 0; + { + ArgLocker _lock; + const ParticleDataImpl<Vec3> *a = _args.getPtr<ParticleDataImpl<Vec3>>("a", 0, &_lock); + const ParticleDataImpl<Vec3> *b = _args.getPtr<ParticleDataImpl<Vec3>>("b", 1, &_lock); + _retval = toPy(pdataMaxDiffVec3(a, b)); + _args.check(); + } + pbFinalizePlugin(parent, "pdataMaxDiffVec3", !noTiming); + return _retval; + } + catch (std::exception &e) { + pbSetError("pdataMaxDiffVec3", e.what()); + return 0; + } +} +static const Pb::Register _RP_pdataMaxDiffVec3("", "pdataMaxDiffVec3", _W_17); +extern "C" { +void PbRegister_pdataMaxDiffVec3() +{ + KEEP_UNUSED(_RP_pdataMaxDiffVec3); +} +} + //! calculate center of mass given density grid, for re-centering Vec3 calcCenterOfMass(const Grid<Real> &density) @@ -1567,7 +1613,7 @@ Vec3 calcCenterOfMass(const Grid<Real> &density) p /= w; return p; } -static PyObject *_W_16(PyObject *_self, PyObject *_linargs, PyObject *_kwds) +static PyObject *_W_18(PyObject *_self, PyObject *_linargs, PyObject *_kwds) { try { PbArgs _args(_linargs, _kwds); @@ -1589,7 +1635,7 @@ static PyObject *_W_16(PyObject *_self, PyObject *_linargs, PyObject *_kwds) return 0; } } -static const Pb::Register _RP_calcCenterOfMass("", "calcCenterOfMass", _W_16); +static const Pb::Register _RP_calcCenterOfMass("", "calcCenterOfMass", _W_18); extern "C" { void PbRegister_calcCenterOfMass() { @@ -1789,7 +1835,7 @@ void updateFractions(const FlagGrid &flags, fractions.setConst(Vec3(0.)); KnUpdateFractions(flags, phiObs, fractions, boundaryWidth, fracThreshold); } -static PyObject *_W_17(PyObject *_self, PyObject *_linargs, PyObject *_kwds) +static PyObject *_W_19(PyObject *_self, PyObject *_linargs, PyObject *_kwds) { try { PbArgs _args(_linargs, _kwds); @@ -1816,7 +1862,7 @@ static PyObject *_W_17(PyObject *_self, PyObject *_linargs, PyObject *_kwds) return 0; } } -static const Pb::Register _RP_updateFractions("", "updateFractions", _W_17); +static const Pb::Register _RP_updateFractions("", "updateFractions", _W_19); extern "C" { void PbRegister_updateFractions() { @@ -1968,7 +2014,7 @@ void setObstacleFlags(FlagGrid &flags, { KnUpdateFlagsObs(flags, fractions, phiObs, phiOut, phiIn, boundaryWidth); } -static PyObject *_W_18(PyObject *_self, PyObject *_linargs, PyObject *_kwds) +static PyObject *_W_20(PyObject *_self, PyObject *_linargs, PyObject *_kwds) { try { PbArgs _args(_linargs, _kwds); @@ -1996,7 +2042,7 @@ static PyObject *_W_18(PyObject *_self, PyObject *_linargs, PyObject *_kwds) return 0; } } -static const Pb::Register _RP_setObstacleFlags("", "setObstacleFlags", _W_18); +static const Pb::Register _RP_setObstacleFlags("", "setObstacleFlags", _W_20); extern "C" { void PbRegister_setObstacleFlags() { @@ -2113,7 +2159,7 @@ void initVortexVelocity(const Grid<Real> &phiObs, { kninitVortexVelocity(phiObs, vel, center, radius); } -static PyObject *_W_19(PyObject *_self, PyObject *_linargs, PyObject *_kwds) +static PyObject *_W_21(PyObject *_self, PyObject *_linargs, PyObject *_kwds) { try { PbArgs _args(_linargs, _kwds); @@ -2139,7 +2185,7 @@ static PyObject *_W_19(PyObject *_self, PyObject *_linargs, PyObject *_kwds) return 0; } } -static const Pb::Register _RP_initVortexVelocity("", "initVortexVelocity", _W_19); +static const Pb::Register _RP_initVortexVelocity("", "initVortexVelocity", _W_21); extern "C" { void PbRegister_initVortexVelocity() { @@ -2465,7 +2511,7 @@ int blurMacGrid(MACGrid &oG, MACGrid &tG, float si) } return tmGK.mDim; } -static PyObject *_W_20(PyObject *_self, PyObject *_linargs, PyObject *_kwds) +static PyObject *_W_22(PyObject *_self, PyObject *_linargs, PyObject *_kwds) { try { PbArgs _args(_linargs, _kwds); @@ -2489,7 +2535,7 @@ static PyObject *_W_20(PyObject *_self, PyObject *_linargs, PyObject *_kwds) return 0; } } -static const Pb::Register _RP_blurMacGrid("", "blurMacGrid", _W_20); +static const Pb::Register _RP_blurMacGrid("", "blurMacGrid", _W_22); extern "C" { void PbRegister_blurMacGrid() { @@ -2501,7 +2547,7 @@ int blurRealGrid(Grid<Real> &oG, Grid<Real> &tG, float si) { return blurGrid<Real>(oG, tG, si); } -static PyObject *_W_21(PyObject *_self, PyObject *_linargs, PyObject *_kwds) +static PyObject *_W_23(PyObject *_self, PyObject *_linargs, PyObject *_kwds) { try { PbArgs _args(_linargs, _kwds); @@ -2525,7 +2571,7 @@ static PyObject *_W_21(PyObject *_self, PyObject *_linargs, PyObject *_kwds) return 0; } } -static const Pb::Register _RP_blurRealGrid("", "blurRealGrid", _W_21); +static const Pb::Register _RP_blurRealGrid("", "blurRealGrid", _W_23); extern "C" { void PbRegister_blurRealGrid() { diff --git a/extern/mantaflow/preprocessed/registration.cpp b/extern/mantaflow/preprocessed/registration.cpp index 6c1e68e6523..d5dae479f0e 100644 --- a/extern/mantaflow/preprocessed/registration.cpp +++ b/extern/mantaflow/preprocessed/registration.cpp @@ -111,6 +111,8 @@ extern void PbRegister_checkSymmetryVec3(); extern void PbRegister_projectPpmFull(); extern void PbRegister_addTestParts(); extern void PbRegister_pdataMaxDiff(); +extern void PbRegister_pdataMaxDiffInt(); +extern void PbRegister_pdataMaxDiffVec3(); extern void PbRegister_calcCenterOfMass(); extern void PbRegister_updateFractions(); extern void PbRegister_setObstacleFlags(); @@ -306,6 +308,8 @@ void MantaEnsureRegistration() PbRegister_projectPpmFull(); PbRegister_addTestParts(); PbRegister_pdataMaxDiff(); + PbRegister_pdataMaxDiffInt(); + PbRegister_pdataMaxDiffVec3(); PbRegister_calcCenterOfMass(); PbRegister_updateFractions(); PbRegister_setObstacleFlags(); |