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.0-cp312-abi3-win_amd64.whl
.
File metadata
- Download URL: fcpw-1.1.0-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 | bd0a6e03260d8558246a8dbb97956d54471236df5232f9c505d900de6b2b397f |
|
MD5 | 14ac9a2b1dd3eb8e1a3b66645ecbf71b |
|
BLAKE2b-256 | 178d44769c3d38c0deb1a9264fad6388dacdef402e025d0f165cf0edd918a891 |
File details
Details for the file fcpw-1.1.0-cp312-abi3-manylinux_2_28_x86_64.whl
.
File metadata
- Download URL: fcpw-1.1.0-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 | f4d59ff5ba33d9839dda970b12bf366e99ec9dcdd2bf344e34a4c9d5cba53666 |
|
MD5 | b26108e60a1007aae2d50d691b29f27a |
|
BLAKE2b-256 | 4868282531f8438875e15735a78d4d987ecdd6441b97020558bd660de669e85d |
File details
Details for the file fcpw-1.1.0-cp312-abi3-macosx_11_0_arm64.whl
.
File metadata
- Download URL: fcpw-1.1.0-cp312-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 288.1 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 | f7463f3d0be5d3542835d43ed85a57aca4670e546d25f9e3d7f88bbd00822d44 |
|
MD5 | 288d783e5a8b967751f8f0b4b5dce49c |
|
BLAKE2b-256 | 9e50349a8ac3be448554c50ae92b052bef250efaab52290a5554aceb43442f83 |
File details
Details for the file fcpw-1.1.0-cp312-abi3-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: fcpw-1.1.0-cp312-abi3-macosx_10_15_x86_64.whl
- Upload date:
- Size: 322.7 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 | 6d0902219fd94745bcb1d154586a8d4d2ebe1c6a1743316c00299bba95419810 |
|
MD5 | cae9df27872e3c3fecfbf06b2231070e |
|
BLAKE2b-256 | a0391e85801ae7c73ebc05381c3d5e9db8a0e682ecea19e1ae32b4e2bfa39be1 |
File details
Details for the file fcpw-1.1.0-cp311-cp311-win_amd64.whl
.
File metadata
- Download URL: fcpw-1.1.0-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 | 00a628e4dcab862ca343c4297ccfa5e8febb073e9c5f36b9ed76ccf38455201b |
|
MD5 | af83bae907c8645b7caf4ec58fbffc17 |
|
BLAKE2b-256 | 1eb78f5f616d727ec068d45205be3035c4777326d92c03d106bd8fa0e06787c4 |
File details
Details for the file fcpw-1.1.0-cp311-cp311-manylinux_2_28_x86_64.whl
.
File metadata
- Download URL: fcpw-1.1.0-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 | 028e58035a60e7bfa99d917c1f580ab8473d018ba70581bb47b13c7247aa6065 |
|
MD5 | 8e35066d92eb4c295828fb7fdd3d50a7 |
|
BLAKE2b-256 | c5417fe9015f0cd49e41a872d2ea5e9b50cff33e3ef5a68f67870d1e958bc39a |
File details
Details for the file fcpw-1.1.0-cp311-cp311-macosx_11_0_arm64.whl
.
File metadata
- Download URL: fcpw-1.1.0-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 293.6 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 | bab449f89445d34565f071bcb202e94a512f07c9043e7e341c01c4557e91115c |
|
MD5 | 5d2dd81f54715f51a3765c32a8664dc2 |
|
BLAKE2b-256 | 5c2ff31872abe982fe9016ecd583afc7c1814a317426cfa9c2145d190113c395 |
File details
Details for the file fcpw-1.1.0-cp311-cp311-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: fcpw-1.1.0-cp311-cp311-macosx_10_15_x86_64.whl
- Upload date:
- Size: 327.6 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 | de85a42303d2eea70a04fbc762e91f9f6d1810aae63cfea2ffc42f61e501d19d |
|
MD5 | da4cd032b9ce95f6335dc1929866e59c |
|
BLAKE2b-256 | 9caf9f7db8eb9abca2f09cf80c44ce8c1d82cc1accc5ec2a6a5db43cff611649 |
File details
Details for the file fcpw-1.1.0-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: fcpw-1.1.0-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 | a4e53e060cf11d146e99cf58a0b6ae3f1f10ac9d51d1c0481a5f440ea37be5b7 |
|
MD5 | c19ff22a8d2a57576d68546c84757e1f |
|
BLAKE2b-256 | 5d60f94168566f45151eb7330f3703bfc953c067b35e5cc1f3be66bfb5fc5c43 |
File details
Details for the file fcpw-1.1.0-cp310-cp310-manylinux_2_28_x86_64.whl
.
File metadata
- Download URL: fcpw-1.1.0-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 | 9d5770fc7dfc637636ddd98c1db9fe19984f20aa86d240821b6244d382a86945 |
|
MD5 | 549a9851ce6755888fa6b8fc595f67c3 |
|
BLAKE2b-256 | 1d47db7d5886757bc5a5a5282e69498edcfd5fc9425f600e652da461223ce5b9 |
File details
Details for the file fcpw-1.1.0-cp310-cp310-macosx_11_0_arm64.whl
.
File metadata
- Download URL: fcpw-1.1.0-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 293.2 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 | 308ced1f5cb288b04860cf56f0f3ee04cac23aa914aecddaa3b81c5f16d0b3cf |
|
MD5 | 2a9489d5e5c8b9652f1a8a3be0e2af96 |
|
BLAKE2b-256 | 3826623ff0cbd0917fbb7c8d605fd2cbcedb98bd4ac7caafa050c285dbadd710 |
File details
Details for the file fcpw-1.1.0-cp310-cp310-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: fcpw-1.1.0-cp310-cp310-macosx_10_15_x86_64.whl
- Upload date:
- Size: 327.2 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 | d7b3bbd9315c3a7764b38003df18162b1812da82f28114f9df6cfdead80a08c8 |
|
MD5 | 121f8eb826142cea117cc9ab1ab20b8d |
|
BLAKE2b-256 | df9e78580741eeeaf8b417746e313953d65bb008cf245741a2c89a7d15838f07 |
File details
Details for the file fcpw-1.1.0-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: fcpw-1.1.0-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 | 06adb0cc9b5c9b22ac260f647ce61477c2816c9ee9668d75d804c989d9e868f2 |
|
MD5 | 36afe6f7822da9019ee46e1f8fb1ec78 |
|
BLAKE2b-256 | d9ece6c362cf841cf1e9541f34eb5a51ecaa1cb1abd0a0c2f5fff6930f09456f |
File details
Details for the file fcpw-1.1.0-cp39-cp39-manylinux_2_28_x86_64.whl
.
File metadata
- Download URL: fcpw-1.1.0-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 | 4c7f390b081ae6fe5512af799db8d1e98e2a57cb3709e8111e525fa9798aa53e |
|
MD5 | b41840f378c4b6631feb7b80641bccd5 |
|
BLAKE2b-256 | 2ef6b853645d59ae26458683d5203b3680b6736cf47fa69fa0ace720344598aa |
File details
Details for the file fcpw-1.1.0-cp39-cp39-macosx_11_0_arm64.whl
.
File metadata
- Download URL: fcpw-1.1.0-cp39-cp39-macosx_11_0_arm64.whl
- Upload date:
- Size: 293.4 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 | 5479a6703a570ba27da0b703058ed011768e5fe4b7a32241de968a906b2ddceb |
|
MD5 | 6e5800bfe529bbe1469bc31ed2e7720e |
|
BLAKE2b-256 | 84bc6c3d4db0e11697ab1a742760fc2228d9862bc8fa77a7a678e57cb3079da7 |
File details
Details for the file fcpw-1.1.0-cp39-cp39-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: fcpw-1.1.0-cp39-cp39-macosx_10_15_x86_64.whl
- Upload date:
- Size: 327.5 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 | 580ea2c17fd2ae37d50a36505becc29cf19bba5e3a6d1488b970192ce7924c05 |
|
MD5 | 020c783c7ae61355df94380bc457efcb |
|
BLAKE2b-256 | d4a8fee7cca6f6c4b21ee7b3140b63ce92dd21b373b870f557f90d7f9d037914 |