mhogg / pyoctree

Octree structure containing a 3D triangular mesh model
MIT License
86 stars 19 forks source link

pyoctree

Octree structure containing a 3D triangular mesh model. To be used for ray tracing / shadow casting.

Written in C++ for speed, but exposed to Python using Cython.

.. image:: https://img.shields.io/pypi/v/pyoctree.svg :target: https://pypi.python.org/pypi/pyoctree/ :alt: Latest PyPI version

Details

Pyoctree uses an adaptive structure, so it will automatically divide branches to ensure that there are no more than 200 objects per leaf.

Requirements

Optional

Note that a compiler is not required if installing using the provided Python wheel.

Installation

Intersection testing uses parallel processing via OpenMP. To use more than a single processor, use the provided Python wheel or compile from source using a compiler that supports OpenMP. Then set value of environment variable OMP_NUM_THREADS to the number of desired processors.

Note that the compilers provided by the Anaconda Python distribution do not support OpenMP.

  1. Building from source

To compile without OpenMP, open a command prompt, browse to the base directory containing the setup.py file and type:

.. code::

python setup.py install

To compile with OpenMP, open a command prompt, browse to the base directory containing the setup.py file and type:

.. code::

python setup.py install --openmp
  1. Installation using Python wheel

Download the python wheel from releases <https://github.com/mhogg/pyoctree/releases>_ i.e. pyoctree-0.2.10-cp36-cp36m-win_amd64.whl for Python 3.6 on Windows 64-bit. Then, open a command prompt, browse to the download directory and type:

.. code::

pip install pyoctree-0.2.10-cp36-cp36m-win_amd64.whl

Note that Python wheels have been built with OpenMP.

Usage

  1. Creating the octree representation of a 3D triangular mesh model

.. code:: python

from pyoctree import pyoctree as ot
tree = ot.PyOctree(pointCoords,connectivity)

where:

  1. Finding intersection between mesh object and ray

The octree can be used to quickly find intersections between the object and a ray. For example:

.. code:: python

import numpy as np
startPoint = [0.0,0.0,0.0]
endPoint   = [0.0,0.0,1.0]
rayList    = np.array([[startPoint,endPoint]],dtype=np.float32)
intersectionFound  = tree.rayIntersection(rayList)

Examples

Some Jupyter notebooks are provided in the Examples directory on how to use pyoctree.

Help

If help is required, please create an issue on Github.