From 75e18abd585ff81c83f40f374a788b25cdbcf4d0 Mon Sep 17 00:00:00 2001 From: k-chaney Date: Mon, 4 Feb 2019 13:51:56 -0500 Subject: [PATCH 1/3] Fix memory leak caused by objects not being cleaned up --- mesh/src/py_visibility.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mesh/src/py_visibility.cpp b/mesh/src/py_visibility.cpp index 1fdeecb..3df5887 100644 --- a/mesh/src/py_visibility.cpp +++ b/mesh/src/py_visibility.cpp @@ -187,8 +187,7 @@ visibility_compute(PyObject *self, PyObject *args, PyObject *keywds) pSensors, min_dist, visibility, normal_dot_cam); if(py_tree == NULL){ - PyObject* py_bin_visibility = PyCObject_FromVoidPtr((void*)search, visibility_destructor); - PyObject* py_normal_dot_cam = PyCObject_FromVoidPtr((void*)search, visibility_destructor); + delete search; } return Py_BuildValue("NN",py_bin_visibility, py_normal_dot_cam); From 4243bb6bb93337f2d8b2be6a2b43bddceea4151b Mon Sep 17 00:00:00 2001 From: Jean-Claude Passy Date: Wed, 16 Oct 2019 16:05:31 +0200 Subject: [PATCH 2/3] Fix for memory leak in the visibility function. --- .gitignore | 3 ++- mesh/src/py_visibility.cpp | 50 ++++++++++++++++++++------------------ 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 9090e82..41705fa 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ MANIFEST *.xml *.egg-info doc/build -.eggs \ No newline at end of file +.eggs +.idea \ No newline at end of file diff --git a/mesh/src/py_visibility.cpp b/mesh/src/py_visibility.cpp index 6a0e193..6ffd4da 100644 --- a/mesh/src/py_visibility.cpp +++ b/mesh/src/py_visibility.cpp @@ -19,41 +19,44 @@ visibility_compute(PyObject *self, PyObject *args, PyObject *keywds); static PyObject *VisibilityError; static PyMethodDef visibility_methods[] = { - {"visibility_compute", (PyCFunction) visibility_compute, - METH_VARARGS | METH_KEYWORDS, "visibility_compute."}, + {"visibility_compute", + (PyCFunction)visibility_compute, + METH_VARARGS | METH_KEYWORDS, + "visibility_compute."}, {NULL, NULL, 0, NULL} /* Sentinel */ }; - -static struct PyModuleDef moduleDef = -{ - PyModuleDef_HEAD_INIT, - "psbody.mesh.visibility", /* name of module */ - "", /* module documentation, may be NULL */ - -1, /* size of per-interpreter state of the module, or -1 if the module keeps state in global variables. */ - visibility_methods -}; - PyMODINIT_FUNC PyInit_visibility(void) { - PyObject *m = PyModule_Create(&moduleDef); - if (m == NULL) - return NULL; + PyObject *m; + + /// Static module-definition table + static PyModuleDef moduledef = { + PyModuleDef_HEAD_INIT, + "psbody.mesh.visibility", /* name of module */ + "", /* module documentation, may be NULL */ + -1, /* size of per-interpreter state of the module, or -1 if the module keeps state in global variables. */ + visibility_methods /* m_methods */ + }; + + /// Actually initialize the module object, + /// using the new Python 3 module-definition table + m = PyModule_Create(&moduledef); + import_array(); VisibilityError = PyErr_NewException(const_cast("visibility.VisibilityError"), NULL, NULL); Py_INCREF(VisibilityError); PyModule_AddObject(m, "VisibilityError", VisibilityError); + /// Initialize and check module + if (m == NULL) { return NULL; } + + /// Return module object return m; } -void visibility_destructor(PyObject *ptr) -{ - TreeAndTri* search = (TreeAndTri*) PyCapsule_GetPointer(ptr, NULL); - delete search; -} template npy_intp parse_pyarray(const PyArrayObject *py_arr, const array* &cpp_arr){ @@ -198,11 +201,10 @@ visibility_compute(PyObject *self, PyObject *args, PyObject *keywds) _internal_compute(search, pN, pCams, C, use_sensors, pSensors, min_dist, visibility, normal_dot_cam); - if(py_tree == NULL){ - delete search; - } - + // Cleaning and returning + delete search; return Py_BuildValue("NN",py_bin_visibility, py_normal_dot_cam); + } catch (VisibilityException& e) { PyErr_SetString(VisibilityError, e.what()); return NULL; From 16ffba1bcec3a5075ce78a9b07024045fbd7c284 Mon Sep 17 00:00:00 2001 From: Jean-Claude Passy Date: Wed, 23 Oct 2019 14:42:18 +0200 Subject: [PATCH 3/3] Updated README, documentation, and versioning before release. --- README.md | 81 ++++++++++++++++++++++++++++++++++++++++++++ README.txt | 3 -- doc/source/index.rst | 39 ++++++--------------- mesh/version.py | 2 +- 4 files changed, 92 insertions(+), 33 deletions(-) create mode 100644 README.md delete mode 100644 README.txt diff --git a/README.md b/README.md new file mode 100644 index 0000000..b54d6f9 --- /dev/null +++ b/README.md @@ -0,0 +1,81 @@ +Perceiving Systems Mesh Package +=============================== + +This package contains core functions for manipulating meshes and visualizing them. +It requires ``Python 3.5+`` and is supported on Linux and macOS operating systems. + +The ``Mesh`` processing libraries support several of our projects such as +* [CoMA: Convolutional Mesh Encoders for Generating 3D Faces](http://coma.is.tue.mpg.de/) +* [FLAME: Learning a model of facial shape and expression from 4D scans](http://flame.is.tue.mpg.de/) +* [MANO: Modeling and Capturing Hands and Bodies Together](http://mano.is.tue.mpg.de/) +* [SMPL: A Skinned Multi-Person Linear Model](http://smpl.is.tue.mpg.de/) +* [VOCA: Voice Operated Character Animation](https://github.com/TimoBolkart/voca) +* [RingNet: 3D Face Shape and Expression Reconstruction from an Image](https://github.com/soubhiksanyal/RingNet) + +Requirements +------------ + +You first need to install the `Boost `_ libraries. +You can compile your own local version or simply do on Linux: + +``` +$ sudo apt-get install libboost-dev +``` + +On macOS: + +``` +$ brew install boost +``` + +Installation +------------ + +First, create a dedicated Python virtual environment and activate it: + +``` +$ python3 -m venv --copies my_venv +$ source my_venv/bin/activate +``` + +You should then compile and install the ``psbody-mesh`` package using the Makefile. +If you are using the system-wide ``Boost`` libraries: + +``` +$ make all +``` + +or the libraries locally installed: + +``` +$ BOOST_ROOT=/path/to/boost/libraries make all +``` + +Testing +------- + +To run the tests, simply do: + +``` +$ make tests +``` + +Documentation +------------- + +A detailed documentation can be compiled using the Makefile: + +``` +$ make documentation +``` + +License +------- +Please refer for LICENSE.txt for using this software. The software is compiled using CGAL sources following the license in CGAL_LICENSE.pdf + +Acknowledgments +--------------- + +We thank the external contribution from the following people: +* [Kenneth Chaney](https://github.com/k-chaney) ([PR #5](https://github.com/MPI-IS/mesh/pull/5)) +* [Dávid Komorowicz](https://github.com/Dawars) ([PR #8](https://github.com/MPI-IS/mesh/pull/8)) \ No newline at end of file diff --git a/README.txt b/README.txt deleted file mode 100644 index 7c245af..0000000 --- a/README.txt +++ /dev/null @@ -1,3 +0,0 @@ -Perceiving Systems Mesh Package -=============================== - diff --git a/doc/source/index.rst b/doc/source/index.rst index e36b706..fe99afa 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -51,7 +51,7 @@ First, create a dedicated Python virtual environment and activate it: $ python3 -m venv --copies my_venv $ source my_venv/bin/activate - + The easiest way to install the ``psbody-mesh`` package is to use the wheel distribution: .. code:: @@ -98,6 +98,14 @@ To run the tests (only available in the **complete** package), simply do: $ make tests +Documentation +------------- + +A detailed documentation can be compiled using the Makefile: + +.. code:: + + $ make documentation Loading a mesh -------------- @@ -125,35 +133,8 @@ From a previously loaded mesh ``my_mesh``, it is possible to visualize it inside # sets the first (top-left) mesh to my_mesh mvs[0][0].set_static_meshes([my_mesh]) -Running inside a virtual environment ------------------------------------- -*Beware*: there is no problem in running the Mesh package inside a virtual environment. However, -if you want to run within an interactive shell such as **IPython**, you **have** to install IPython -inside the virtual environment as well:: - - In [1]: from psbody.mesh import MeshViewers - - In [2]: mviewer = MeshViewers(shape=(2,2)) - OpenGL test failed: - stdout: - stderr: /usr/bin/python: No module named psbody.mesh - - -As shown above, the python binary is not the correct one. If after having installed IPython inside the -virtual environment, you still encounter this issue, then it is likely that your bash is caching the -``ipython`` command to the wrong one. Example:: - - >> type ipython - ipython is hashed (/usr/bin/ipython) - >> which ipython - /media/renficiaud/linux-data/Code/sandbox/venv_meshviewer/bin/ipython - >> hash -r # clears the cache - >> type ipython - /media/renficiaud/linux-data/Code/sandbox/venv_meshviewer/bin/ipython - - Caching -======= +------- Some operations make use of caching for performance reasons. The default folder used for caching is diff --git a/mesh/version.py b/mesh/version.py index bead075..5290ee6 100644 --- a/mesh/version.py +++ b/mesh/version.py @@ -3,4 +3,4 @@ # Copyright (c) 2016 Max Planck Society. All rights reserved. -__version__ = '0.2' +__version__ = '0.3'