Python bindings for FCPW
Project description
FCPW: Fastest Closest Points in the West
FCPW is an acceleration library for performing fast geometric queries, such as closest points and ray intersections, on 3D triangle meshes and 2D line segment meshes. It is available in C++ and Python, and offers GPU acceleration via the Slang shading language and CPU vectorization via the Enoki library.
C++ API
The easiest and most direct way to use FCPW is through the Scene
class which provides methods to load geometry, build and refit the acceleration structure and perform geometric queries. Here is an example of performing a closest point query on a 3D triangle mesh:
#include <fcpw/fcpw.h>
using namespace fcpw;
// initialize a 3d scene
Scene<3> scene;
// load positions and indices of a single triangle mesh
scene.setObjectCount(1);
scene.setObjectVertices(positions, 0);
scene.setObjectTriangles(indices, 0);
// build acceleration structure
AggregateType aggregateType = AggregateType::Bvh_SurfaceArea;
bool buildVectorizedBvh = true;
scene.build(aggregateType, buildVectorizedBvh);
// perform a closest point query
Interaction<3> interaction;
bool found = scene.findClosestPoint(queryPoint, interaction);
// access distance and closest point via interaction.d and interaction.p (resp.)
The Scene
class is templated on dimension, which enables it to work with geometric data in any dimension as long as primitives are defined for the dimension of interest. In addition to triangles in 3D, FCPW also provides support for line segments in 2D. The Interaction class stores information relevant to the query, such as the distance to and closest point on the primitive.
If your scene consists of multiple objects with the same type of primitives (e.g. triangles), it is better to "flatten" those objects into a single object (with a list of positions
and indices
). FCPW then builds a single acceleration structure over all primitives in the scene. If multiple objects are loaded, FCPW instead builds a hierarchy of acceleration structures, with a structure for each object in the scene.
Refer to demo.cpp for a complete demo, and fcpw.h for the full API, which includes the list of supported geometric queries, heuristrics for constructing the accerlation structure, as well as support for refitting, instancing and CSG operations. Details regarding GPU support and installation are provided below.
Python API
FCPW's C++ and Python APIs follow a similar structure. However, since Python does not support templates, Python classes and functions use explicit _2D
or _3D
dimension tags:
import fcpw
# initialize a 3d scene
scene = fcpw.scene_3D()
# load positions and indices of a single triangle mesh
scene.set_object_count(1)
scene.set_object_vertices(positions, 0)
scene.set_object_triangles(indices, 0)
# build acceleration structure
aggregate_type = fcpw.aggregate_type.bvh_surface_area
build_vectorized_bvh = True
scene.build(aggregate_type, build_vectorized_bvh)
# perform several closest point queries
interactions = fcpw.interaction_3D_list()
scene.find_closest_points(query_points, squared_max_radii, interactions)
# extract closest points
closest_points = [i.p for i in interactions]
Refer to demo.py for a complete demo. The full API can be viewed in the Python console using help(fcpw)
.
GPU Support
GPU support for a large collection of query points is provided through the GPUScene class in C++, and gpu_scene_*D
classes in Python. FCPW currently requires the acceleration structure to be built on the CPU and then transferred to the GPU. For instance, in C++ we have:
#include <fcpw/fcpw_gpu.h>
using namespace fcpw;
// initialize a 3d scene and load geometry (same as above)
Scene<3> scene;
...
// build acceleration structure on CPU
bool buildVectorizedCPUBvh = false; // NOTE: must build non-vectorized structure
scene.build(AggregateType::Bvh_SurfaceArea, buildVectorizedCPUBvh);
// transfer scene to GPU
GPUScene<3> gpuScene("PATH_TO_FCPW_DIRECTORY");
gpuScene.transferToGPU(scene);
// initialize bounding spheres
std::vector<GPUBoundingSphere> boundingSpheres;
for (auto q: queryPoints) {
float3 queryPoint = float3{q[0], q[1], q[2]};
boundingSpheres.emplace_back(GPUBoundingSphere(queryPoint, INFINITY));
}
// perform several closest point queries on GPU
std::vector<GPUInteraction> interactions;
gpuScene.findClosestPoints(boundingSpheres, interactions);
and in Python:
import fcpw
# initialize a 3d scene and load geometry (same as above)
scene = fcpw.scene_3D()
...
# build acceleration structure on CPU
build_vectorized_cpu_bvh = False # NOTE: must build non-vectorized structure
scene.build(fcpw.aggregate_type.bvh_surface_area, build_vectorized_cpu_bvh)
# transfer scene to GPU
gpu_scene = fcpw.gpu_scene_3D("PATH_TO_FCPW_DIRECTORY")
gpu_scene.transfer_to_gpu(scene)
# perform several closest point queries on GPU
interactions = fcpw.gpu_interaction_list()
gpu_scene.find_closest_points(query_points, squared_max_radii, interactions)
Refer to demo.cpp and demo.py for complete demos. GPU support is available on Linux and Windows (Slang currently only has unofficial support for macOS).
For those developing directly on the GPU, the acceleration structure can also be accessed through bvh.slang. Slang offers CUDA, HLSL, Vulkan, OpenGL and Metal (experimental) as compilation targets. Refer to its user guide for further details on compiling to these targets.
C++ Installation
FCPW is developed as a header-only library. It can be downloaded and compiled using CMake as follows:
git clone https://github.com/rohan-sawhney/fcpw.git
cd fcpw && git submodule update --init --recursive
[...clone additional dependencies...] // instructions below
mkdir build && cd build
cmake [-DFCPW_BUILD_DEMO=ON] [-DFCPW_USE_ENOKI=OFF] [-DFCPW_ENABLE_GPU_SUPPORT=ON] ..
make -j8 // for Linux and Mac; cmake generates a visual studio project for Windows.
The FCPW_BUILD_DEMO
option requires polyscope as a dependency in the deps
repo. Clone polyscope using:
git clone --recurse-submodules https://github.com/nmwsharp/polyscope.git deps/polyscope
The C++ demo can be run from the build
directory with the command:
./demos/demo [--useGpu]
For CPU vectorization, Enoki is included by default as a submodule. It can be disabled with the command -DFCPW_USE_ENOKI=OFF
, in which case FCPW falls back to Eigen for non-vectorized CPU queries.
To include FCPW in your project without GPU support, add the following lines to your CMakeLists.txt file:
add_subdirectory(fcpw)
target_link_libraries(YOUR_TARGET fcpw)
target_include_directories(YOUR_TARGET PRIVATE ${FCPW_EIGEN_INCLUDES})
target_include_directories(YOUR_TARGET PRIVATE ${FCPW_ENOKI_INCLUDES})
If your prefer to directly include FCPW header files without CMake, then you'll have to define a few extra variables before including the library:
#define FCPW_USE_ENOKI
#define FCPW_SIMD_WIDTH 4 // change based on the SIMD width supported by your machine
#include <fcpw/fcpw.h>
Finally, GPU support can be enabled with the command FCPW_ENABLE_GPU_SUPPORT=ON
. Additionally include the following lines in your CMakeLists.txt file:
target_link_libraries(YOUR_TARGET ${FCPW_SLANG_LIBRARY})
target_link_libraries(YOUR_TARGET ${FCPW_SLANG_GLSLANG_LIBRARY})
target_link_libraries(YOUR_TARGET ${FCPW_GFX_LIBRARY})
target_include_directories(YOUR_TARGET PRIVATE ${FCPW_SLANG_INCLUDES})
On Windows, you may need to download necessary DLL files from the official DirectX Shader Compiler repository on GitHub here. Copy dxil.dll
and dxcompiler.dll
to C:\Windows\System32\
for 64-bit systems or to C:\Windows\SysWOW64\
for 32-bit systems. This makes the DLLs available to all applications system-wide.
Python Installation
Pre-built Python wheels are available for Linux, Windows and macOS on PyPI:
pip install fcpw
These wheels can also be downloaded and installed from Releases:
pip install fcpw-*.whl
Alternatively, to build Python bindings on your local machine, first clone nanobind using:
git clone --recurse-submodules https://github.com/wjakob/nanobind.git deps/nanobind
To build and install the bindings, run:
pip install . [--config-settings=cmake.define.FCPW_ENABLE_GPU_SUPPORT=ON]
Finally, launch the Python demo from the demos
folder using:
python -m pip install polyscope
python demo.py [--use_gpu]
Citation
@software{FCPW,
author = {Sawhney, Rohan},
title = {FCPW: Fastest Closest Points in the West},
version = {1.0},
year = {2021}
}
Author
License
Released under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
File details
Details for the file fcpw-1.1.2-cp312-abi3-win_amd64.whl
.
File metadata
- Download URL: fcpw-1.1.2-cp312-abi3-win_amd64.whl
- Upload date:
- Size: 10.4 MB
- Tags: CPython 3.12+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1aa178d06d5fc69edeb9e77798e7e8a7d270b2706cd42a8e0872a1b8e237852a |
|
MD5 | 48389fc52547be009b328fd022fc445e |
|
BLAKE2b-256 | 6b346c97f98571c426b55e91568f75f8ecea61d9c4bd8b7cb204251fa243ad01 |
File details
Details for the file fcpw-1.1.2-cp312-abi3-manylinux_2_28_x86_64.whl
.
File metadata
- Download URL: fcpw-1.1.2-cp312-abi3-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 26.2 MB
- Tags: CPython 3.12+, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd0e2ba868787a448393126a1ce64b12d1f0815fd52c68f67e851bce1770d07a |
|
MD5 | 3885b090649f227bb841b5ffaf579d6a |
|
BLAKE2b-256 | 53bd51ca060e2429323fbc2ff74911d269a2f12cc2d480a327c1206b3c086c22 |
File details
Details for the file fcpw-1.1.2-cp312-abi3-macosx_11_0_arm64.whl
.
File metadata
- Download URL: fcpw-1.1.2-cp312-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 293.2 kB
- Tags: CPython 3.12+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0ee8c56b154084c65f1fd64d125158aaa646574ee367fdc84b609572b62ea88 |
|
MD5 | ec138c82f132536d29edcd83b82d0402 |
|
BLAKE2b-256 | 9698879a4c5a35b43df1d464fcebfdc6ee17b90fde7e5d6508846fe0bb494ae3 |
File details
Details for the file fcpw-1.1.2-cp312-abi3-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: fcpw-1.1.2-cp312-abi3-macosx_10_15_x86_64.whl
- Upload date:
- Size: 328.3 kB
- Tags: CPython 3.12+, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb4543ef4c0813ff67846936d7662897175daf95a1bebed4f9747843bc0b38dc |
|
MD5 | 7dfeeeded5a265dfd93d03e2ea5f5a48 |
|
BLAKE2b-256 | be89c54d248ce2b00c751ec179475e8bda34ac2f0fb18a2df28bf2077dc5ff81 |
File details
Details for the file fcpw-1.1.2-cp311-cp311-win_amd64.whl
.
File metadata
- Download URL: fcpw-1.1.2-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 10.4 MB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 564fb58866f3e80ad4315435e6eb68f4e1ce5c7b7e80df65e88e63585624880c |
|
MD5 | 0893db07456b0f3d6b7992abe050cb2c |
|
BLAKE2b-256 | 68defcbf8a45a6c38098ff5d6ef61566434f4ecf47b8e7a9ff0fc6bd152044d3 |
File details
Details for the file fcpw-1.1.2-cp311-cp311-manylinux_2_28_x86_64.whl
.
File metadata
- Download URL: fcpw-1.1.2-cp311-cp311-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 26.2 MB
- Tags: CPython 3.11, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41bee2118edb2962d1582ff33171934722113a8be37350af9731898bdb7635ea |
|
MD5 | ad157a22df095996208de3ff7c5ca5b3 |
|
BLAKE2b-256 | 1d8099b6d7cd9714d8d3600c9d4cd4c102132c5d7caad72f644bcb6674fa5fec |
File details
Details for the file fcpw-1.1.2-cp311-cp311-macosx_11_0_arm64.whl
.
File metadata
- Download URL: fcpw-1.1.2-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 299.0 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ba3691a662935a9e53a91882291fe82454ea12938e8e9c30f82b8b8ff8559b3 |
|
MD5 | 191d61be1fe7899322ebfc79bdb16000 |
|
BLAKE2b-256 | 30212099499286bce768ecf476e21fded52fa28a4310efd766a4db1ffe948377 |
File details
Details for the file fcpw-1.1.2-cp311-cp311-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: fcpw-1.1.2-cp311-cp311-macosx_10_15_x86_64.whl
- Upload date:
- Size: 333.3 kB
- Tags: CPython 3.11, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0516a06f7a32b61fe5e816075773a6d1757b6f4ba6b188da372daa660e902362 |
|
MD5 | f4a70939dd01527bf61b4677b9c65676 |
|
BLAKE2b-256 | eabeb664af971acd13e0e524171efe5597755fb07b69e538ead0a4037e7f1f93 |
File details
Details for the file fcpw-1.1.2-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: fcpw-1.1.2-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 10.4 MB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13381fec0b2a7566a5cc09188e1349c57a9114bc556ac133e39af5bf93c08e15 |
|
MD5 | 93bce0fb9624125001c04759e72e9513 |
|
BLAKE2b-256 | f36e963afe616a0c59a6ce05dd43ff351c64a8fe3710dc2bc756a2d588c758ce |
File details
Details for the file fcpw-1.1.2-cp310-cp310-manylinux_2_28_x86_64.whl
.
File metadata
- Download URL: fcpw-1.1.2-cp310-cp310-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 26.2 MB
- Tags: CPython 3.10, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e168ec444612dc442a094c72ed4900f7d286bd9f4795c6a093fc06e323511e65 |
|
MD5 | 2fcccabf88f5692703a61821b550aad7 |
|
BLAKE2b-256 | 8a29bb54cb26a66e062af6101c6519b855bbdf7c19da17b6185e94a048462720 |
File details
Details for the file fcpw-1.1.2-cp310-cp310-macosx_11_0_arm64.whl
.
File metadata
- Download URL: fcpw-1.1.2-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 298.6 kB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d473343457e2d9a44291f4eefa6bf19221f0eb1137be34d7a60957454bde3b3 |
|
MD5 | 80d9692dc5c87b586f83a55d8eb080ee |
|
BLAKE2b-256 | 1234910a24a86770b1103c339d7449f48f00c77c5793da1e0d46a4e4a324b582 |
File details
Details for the file fcpw-1.1.2-cp310-cp310-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: fcpw-1.1.2-cp310-cp310-macosx_10_15_x86_64.whl
- Upload date:
- Size: 332.9 kB
- Tags: CPython 3.10, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 869c9caf8be89c8e34d498b072251acc8138064e6b8f736ab32269aa345a317f |
|
MD5 | d4a42d233a04475446523de9f4e18cbd |
|
BLAKE2b-256 | bfd92ac01144205964c8b110a8444eee7452aad0b5032f0169c1d0edec664d02 |
File details
Details for the file fcpw-1.1.2-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: fcpw-1.1.2-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 10.4 MB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3eaf383a6ff252cbab9bef7e91bcea42b98cd91ce3f00ad535c02e01a1ba8f4d |
|
MD5 | 0cffccaeb8a8a1be8535151aa063b064 |
|
BLAKE2b-256 | 715ffdb5180ce2da5ff82b11958f21ea86a7075f7ba4f2a0b0a14b35ac24346c |
File details
Details for the file fcpw-1.1.2-cp39-cp39-manylinux_2_28_x86_64.whl
.
File metadata
- Download URL: fcpw-1.1.2-cp39-cp39-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 26.2 MB
- Tags: CPython 3.9, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ca45fde1f1f383d043b8ac20d8bd0d9961a502ce73302d9fe4c1a2fdfca44c3 |
|
MD5 | 039cb7427a75e8046ba11da82a6f5250 |
|
BLAKE2b-256 | 2efb9adc351df0681a071668eb812e08552211c559bf2b84efa099bd25eea5cc |
File details
Details for the file fcpw-1.1.2-cp39-cp39-macosx_11_0_arm64.whl
.
File metadata
- Download URL: fcpw-1.1.2-cp39-cp39-macosx_11_0_arm64.whl
- Upload date:
- Size: 298.8 kB
- Tags: CPython 3.9, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e7e1c61f5cb25871abd74d85557a16995b0c8522a10ff9d47e6a1212f8c9d11 |
|
MD5 | 0e380bd47f992c751bbdae4b61fb514f |
|
BLAKE2b-256 | e6b57065d260d44229e5f81913a4182f509f3d8d3892987d65a48b8635e9c680 |
File details
Details for the file fcpw-1.1.2-cp39-cp39-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: fcpw-1.1.2-cp39-cp39-macosx_10_15_x86_64.whl
- Upload date:
- Size: 333.1 kB
- Tags: CPython 3.9, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fee7a47159de77fff8cfa747ee68efebc3dc3b501de863b3abb4a7ad4c9eafe8 |
|
MD5 | 2731e21e708838b56a4d2a928218415d |
|
BLAKE2b-256 | f457661c45a4eca6521082dbdca80359c770819ba473f2853c588063b30ecf62 |