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

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastián Barschkis <sebbas@sebbas.org>2020-06-24 13:00:13 +0300
committerSebastián Barschkis <sebbas@sebbas.org>2020-06-24 17:07:35 +0300
commit9fe64948abe991d18c1af3a52d81e87c24d39687 (patch)
treebc7363b04130a7538eeb21a7e42e04038e1f3314 /extern/mantaflow/helper
parent6fec2e4db05f6acdfc2b1b0ba365af143201277c (diff)
Fluid: Updated Mantaflow source with latest OpenVDB changes
This updated set of Mantaflow files includes the improved OpenVDB file IO. With this update it is finally possible to store multiple grids per file. It is also possible to save particle systems and particle data to OpenVDB files.
Diffstat (limited to 'extern/mantaflow/helper')
-rw-r--r--extern/mantaflow/helper/pwrapper/pconvert.cpp93
-rw-r--r--extern/mantaflow/helper/pwrapper/pconvert.h11
2 files changed, 99 insertions, 5 deletions
diff --git a/extern/mantaflow/helper/pwrapper/pconvert.cpp b/extern/mantaflow/helper/pwrapper/pconvert.cpp
index 9ada75519fc..861a2c070bd 100644
--- a/extern/mantaflow/helper/pwrapper/pconvert.cpp
+++ b/extern/mantaflow/helper/pwrapper/pconvert.cpp
@@ -96,6 +96,37 @@ template<> PyObject *toPy<PbClass *>(const PbClass_Ptr &obj)
{
return obj->getPyObject();
}
+template<> PyObject *toPy<std::vector<PbClass *>>(const std::vector<PbClass *> &vec)
+{
+ PyObject *listObj = PyList_New(vec.size());
+ if (!listObj)
+ throw logic_error("Unable to allocate memory for Python list");
+ for (unsigned int i = 0; i < vec.size(); i++) {
+ PbClass *pb = vec[i];
+ PyObject *item = pb->getPyObject();
+ if (!item) {
+ Py_DECREF(listObj);
+ throw logic_error("Unable to allocate memory for Python list");
+ }
+ PyList_SET_ITEM(listObj, i, item);
+ }
+ return listObj;
+}
+template<> PyObject *toPy<std::vector<float>>(const std::vector<float> &vec)
+{
+ PyObject *listObj = PyList_New(vec.size());
+ if (!listObj)
+ throw logic_error("Unable to allocate memory for Python list");
+ for (unsigned int i = 0; i < vec.size(); i++) {
+ PyObject *item = toPy<float>(vec[i]);
+ if (!item) {
+ Py_DECREF(listObj);
+ throw logic_error("Unable to allocate memory for Python list");
+ }
+ PyList_SET_ITEM(listObj, i, item);
+ }
+ return listObj;
+}
template<> float fromPy<float>(PyObject *obj)
{
@@ -125,6 +156,42 @@ template<> PyObject *fromPy<PyObject *>(PyObject *obj)
{
return obj;
}
+template<> PbClass *fromPy<PbClass *>(PyObject *obj)
+{
+ PbClass *pbo = Pb::objFromPy(obj);
+
+ if (!PyType_Check(obj))
+ return pbo;
+
+ const char *tname = ((PyTypeObject *)obj)->tp_name;
+ pbo->setName(tname);
+
+ return pbo;
+}
+template<> std::vector<PbClass *> fromPy<std::vector<PbClass *>>(PyObject *obj)
+{
+ std::vector<PbClass *> vec;
+ if (PyList_Check(obj)) {
+ int sz = PyList_Size(obj);
+ for (int i = 0; i < sz; ++i) {
+ PyObject *lobj = PyList_GetItem(obj, i);
+ vec.push_back(fromPy<PbClass *>(lobj));
+ }
+ }
+ return vec;
+}
+template<> std::vector<float> fromPy<std::vector<float>>(PyObject *obj)
+{
+ std::vector<float> vec;
+ if (PyList_Check(obj)) {
+ int sz = PyList_Size(obj);
+ for (int i = 0; i < sz; ++i) {
+ PyObject *lobj = PyList_GetItem(obj, i);
+ vec.push_back(fromPy<float>(lobj));
+ }
+ }
+ return vec;
+}
template<> int fromPy<int>(PyObject *obj)
{
#if PY_MAJOR_VERSION <= 2
@@ -259,11 +326,10 @@ template<class T> T *tmpAlloc(PyObject *obj, std::vector<void *> *tmp)
{
if (!tmp)
throw Error("dynamic de-ref not supported for this type");
- void *ptr = malloc(sizeof(T));
- tmp->push_back(ptr);
- *((T *)ptr) = fromPy<T>(obj);
- return (T *)ptr;
+ T *ptr = new T(fromPy<T>(obj));
+ tmp->push_back(ptr);
+ return ptr;
}
template<> float *fromPyPtr<float>(PyObject *obj, std::vector<void *> *tmp)
{
@@ -301,6 +367,11 @@ template<> Vec4i *fromPyPtr<Vec4i>(PyObject *obj, std::vector<void *> *tmp)
{
return tmpAlloc<Vec4i>(obj, tmp);
}
+template<>
+std::vector<PbClass *> *fromPyPtr<std::vector<PbClass *>>(PyObject *obj, std::vector<void *> *tmp)
+{
+ return tmpAlloc<std::vector<PbClass *>>(obj, tmp);
+}
template<> bool isPy<float>(PyObject *obj)
{
@@ -404,6 +475,18 @@ template<> bool isPy<PbType>(PyObject *obj)
{
return PyType_Check(obj);
}
+template<> bool isPy<std::vector<PbClass *>>(PyObject *obj)
+{
+ if (PyList_Check(obj))
+ return true;
+ return false;
+}
+template<> bool isPy<std::vector<float>>(PyObject *obj)
+{
+ if (PyList_Check(obj))
+ return true;
+ return false;
+}
//******************************************************************************
// PbArgs class defs
@@ -417,7 +500,7 @@ PbArgs::PbArgs(PyObject *linarg, PyObject *dict) : mLinArgs(0), mKwds(0)
PbArgs::~PbArgs()
{
for (int i = 0; i < (int)mTmpStorage.size(); i++)
- free(mTmpStorage[i]);
+ operator delete(mTmpStorage[i]);
mTmpStorage.clear();
}
diff --git a/extern/mantaflow/helper/pwrapper/pconvert.h b/extern/mantaflow/helper/pwrapper/pconvert.h
index 9c72b8b57b9..87f4248f6f1 100644
--- a/extern/mantaflow/helper/pwrapper/pconvert.h
+++ b/extern/mantaflow/helper/pwrapper/pconvert.h
@@ -57,6 +57,10 @@ template<> Vec3 *fromPyPtr<Vec3>(PyObject *obj, std::vector<void *> *tmp);
template<> Vec3i *fromPyPtr<Vec3i>(PyObject *obj, std::vector<void *> *tmp);
template<> Vec4 *fromPyPtr<Vec4>(PyObject *obj, std::vector<void *> *tmp);
template<> Vec4i *fromPyPtr<Vec4i>(PyObject *obj, std::vector<void *> *tmp);
+template<>
+std::vector<PbClass *> *fromPyPtr<std::vector<PbClass *>>(PyObject *obj, std::vector<void *> *tmp);
+template<>
+std::vector<float> *fromPyPtr<std::vector<float>>(PyObject *obj, std::vector<void *> *tmp);
PyObject *incref(PyObject *obj);
template<class T> PyObject *toPy(const T &v)
@@ -99,6 +103,9 @@ template<> Vec4 fromPy<Vec4>(PyObject *obj);
template<> Vec4i fromPy<Vec4i>(PyObject *obj);
template<> PbType fromPy<PbType>(PyObject *obj);
template<> PbTypeVec fromPy<PbTypeVec>(PyObject *obj);
+template<> PbClass *fromPy<PbClass *>(PyObject *obj);
+template<> std::vector<PbClass *> fromPy<std::vector<PbClass *>>(PyObject *obj);
+template<> std::vector<float> fromPy<std::vector<float>>(PyObject *obj);
template<> PyObject *toPy<int>(const int &v);
template<> PyObject *toPy<std::string>(const std::string &val);
@@ -111,6 +118,8 @@ template<> PyObject *toPy<Vec4i>(const Vec4i &v);
template<> PyObject *toPy<Vec4>(const Vec4 &v);
typedef PbClass *PbClass_Ptr;
template<> PyObject *toPy<PbClass *>(const PbClass_Ptr &obj);
+template<> PyObject *toPy<std::vector<PbClass *>>(const std::vector<PbClass *> &vec);
+template<> PyObject *toPy<std::vector<float>>(const std::vector<float> &vec);
template<> bool isPy<float>(PyObject *obj);
template<> bool isPy<double>(PyObject *obj);
@@ -124,6 +133,8 @@ template<> bool isPy<Vec3i>(PyObject *obj);
template<> bool isPy<Vec4>(PyObject *obj);
template<> bool isPy<Vec4i>(PyObject *obj);
template<> bool isPy<PbType>(PyObject *obj);
+template<> bool isPy<std::vector<PbClass *>>(PyObject *obj);
+template<> bool isPy<std::vector<float>>(PyObject *obj);
//! Encapsulation of python arguments
class PbArgs {