Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  Updated README, documentation, and versioning before release.
  Fix for memory leak in the visibility function.
  Fix memory leak caused by objects not being cleaned up
  • Loading branch information
jcpassy committed Oct 23, 2019
2 parents 208e578 + 16ffba1 commit df5db0f
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 59 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ MANIFEST
*.xml
*.egg-info
doc/build
.eggs
.eggs
.idea
81 changes: 81 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 <http://www.boost.org>`_ 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))
3 changes: 0 additions & 3 deletions README.txt

This file was deleted.

39 changes: 10 additions & 29 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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::
Expand Down Expand Up @@ -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
--------------
Expand Down Expand Up @@ -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

Expand Down
51 changes: 26 additions & 25 deletions mesh/src/py_visibility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char*>("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 <typename CTYPE, int PYTYPE>
npy_intp parse_pyarray(const PyArrayObject *py_arr, const array<CTYPE,3>* &cpp_arr){
Expand Down Expand Up @@ -198,12 +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){
PyObject* py_bin_visibility = PyCapsule_New((void*)search, NULL, visibility_destructor);
PyObject* py_normal_dot_cam = PyCapsule_New((void*)search, NULL, visibility_destructor);
}

// 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;
Expand Down
2 changes: 1 addition & 1 deletion mesh/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

# Copyright (c) 2016 Max Planck Society. All rights reserved.

__version__ = '0.2'
__version__ = '0.3'

0 comments on commit df5db0f

Please sign in to comment.