Skip to main content

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

Rohan Sawhney

License

Released under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

fcpw-1.1.8-cp312-abi3-win_amd64.whl (14.4 MB view details)

Uploaded CPython 3.12+Windows x86-64

fcpw-1.1.8-cp312-abi3-manylinux_2_28_x86_64.whl (25.6 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.28+ x86-64

fcpw-1.1.8-cp312-abi3-macosx_11_0_arm64.whl (294.5 kB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

fcpw-1.1.8-cp312-abi3-macosx_10_15_x86_64.whl (329.9 kB view details)

Uploaded CPython 3.12+macOS 10.15+ x86-64

fcpw-1.1.8-cp311-cp311-win_amd64.whl (14.4 MB view details)

Uploaded CPython 3.11Windows x86-64

fcpw-1.1.8-cp311-cp311-manylinux_2_28_x86_64.whl (25.6 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

fcpw-1.1.8-cp311-cp311-macosx_11_0_arm64.whl (300.6 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

fcpw-1.1.8-cp311-cp311-macosx_10_15_x86_64.whl (334.6 kB view details)

Uploaded CPython 3.11macOS 10.15+ x86-64

fcpw-1.1.8-cp310-cp310-win_amd64.whl (14.4 MB view details)

Uploaded CPython 3.10Windows x86-64

fcpw-1.1.8-cp310-cp310-manylinux_2_28_x86_64.whl (25.6 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

fcpw-1.1.8-cp310-cp310-macosx_11_0_arm64.whl (300.4 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

fcpw-1.1.8-cp310-cp310-macosx_10_15_x86_64.whl (334.4 kB view details)

Uploaded CPython 3.10macOS 10.15+ x86-64

fcpw-1.1.8-cp39-cp39-win_amd64.whl (14.4 MB view details)

Uploaded CPython 3.9Windows x86-64

fcpw-1.1.8-cp39-cp39-manylinux_2_28_x86_64.whl (25.6 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ x86-64

fcpw-1.1.8-cp39-cp39-macosx_11_0_arm64.whl (300.4 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

fcpw-1.1.8-cp39-cp39-macosx_10_15_x86_64.whl (334.5 kB view details)

Uploaded CPython 3.9macOS 10.15+ x86-64

File details

Details for the file fcpw-1.1.8-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: fcpw-1.1.8-cp312-abi3-win_amd64.whl
  • Upload date:
  • Size: 14.4 MB
  • Tags: CPython 3.12+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for fcpw-1.1.8-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 608f71391228854778dcd75ec5027ec2f7195fe8420010a78d2a27386a074f40
MD5 08aa6aaebf6218bf91d23a9d3c9a89ed
BLAKE2b-256 a6c62843c6a66bdcf8b5f88000cd72032ac82745ecfa9595ccbffe672eea6911

See more details on using hashes here.

File details

Details for the file fcpw-1.1.8-cp312-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for fcpw-1.1.8-cp312-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 90fdfb52b9073d2a85af325aac6c0d44dfb31df65f9cc6841d7ea22618f65b26
MD5 1abebd320e5529effa8a0c24a5814259
BLAKE2b-256 c11209bb02cfcdb32c11bcf04c14df420838f40babc93673412f9e385b345960

See more details on using hashes here.

File details

Details for the file fcpw-1.1.8-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

  • Download URL: fcpw-1.1.8-cp312-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 294.5 kB
  • Tags: CPython 3.12+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for fcpw-1.1.8-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4fa89ce5d0fd8a071b041e37e045fc6631fb6d5d35c0b35b3ad1be94b1303b5d
MD5 d37f59255c6fb18461e4af8efd562aca
BLAKE2b-256 24648b50460d00c0831133cf71b1a4a9e4d5712de7b2458e26d524f373bb0501

See more details on using hashes here.

File details

Details for the file fcpw-1.1.8-cp312-abi3-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for fcpw-1.1.8-cp312-abi3-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 55c081238a762341f9ac1753b602e7c90aa699ce20e02e5d9bff0865c17ec786
MD5 d5d7f601af801e1a6c2f5d411c63a877
BLAKE2b-256 ec71ae69f32a4f78ffbc946eaf4e50a92dd7f7a5d8ca08339a979b606ab68cc0

See more details on using hashes here.

File details

Details for the file fcpw-1.1.8-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: fcpw-1.1.8-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 14.4 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for fcpw-1.1.8-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 0671113d30932fc2106f4cfdc90acb8a139309342046d9c55318a8f3e74105e3
MD5 808b28ab128ed679b7f910c541546785
BLAKE2b-256 4e8d65ab32f8a899313ef62ab675ce756de48063d51920f740246a1d75a356f6

See more details on using hashes here.

File details

Details for the file fcpw-1.1.8-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for fcpw-1.1.8-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a9389426897e5589bd0ee9dfa79c4970820ef117adc68cc4dac7f4ad9b2d3e40
MD5 763f1bb62b035e8f9c92620acb1ebf58
BLAKE2b-256 71075950082ee55f68baa23f759da13ce694084dd246ed7ad896ae391fabb5be

See more details on using hashes here.

File details

Details for the file fcpw-1.1.8-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fcpw-1.1.8-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a7bb7cc3a4076a3587721c24708b481fe60365047783cfce82932c90c800145e
MD5 1eb9897e812fb964964d892d1dd92033
BLAKE2b-256 d2c8dce8bc0ec9a1cdec3a4fd5c417e330fbfa61a858c09495dbb28823d2ae2c

See more details on using hashes here.

File details

Details for the file fcpw-1.1.8-cp311-cp311-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for fcpw-1.1.8-cp311-cp311-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 9cef3b2e8d9be558011571f92ad70e298188747dd3d17a8377679f2faa28c012
MD5 4df66fc8013f05a6033c9cdfe82881a7
BLAKE2b-256 44c631d72b19504a99a7316792a2a17de346298cf5704d02a1f6d8f780b32c3f

See more details on using hashes here.

File details

Details for the file fcpw-1.1.8-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: fcpw-1.1.8-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 14.4 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for fcpw-1.1.8-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 8c5b7c264c8904b078bfcd27de0efe0fad7fa63d84e4d472aed1bc27198d36e6
MD5 af07db7bbb941b9a5308d76eeba24f72
BLAKE2b-256 46a242474ed36792440bda5eac84aa99542eb75a2fee71b5696b70a89cc52d44

See more details on using hashes here.

File details

Details for the file fcpw-1.1.8-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for fcpw-1.1.8-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6c4bec335de2bb8b07ca9ed81aa5f931858483326595ef9073e0b9211f253e81
MD5 d06cc38d19324e021ca130e4b379318b
BLAKE2b-256 a08e40b11acf5c7be8c4263d68136792b9dce12631d99f579aae33f91ccde0a6

See more details on using hashes here.

File details

Details for the file fcpw-1.1.8-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fcpw-1.1.8-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1b160f4f7453df5832f9bf9c569c1dd3eab95d17db966f9de837103a71fbd605
MD5 5e7c0d8f7bfda91bfdeb171ff47eba12
BLAKE2b-256 ddfda3731fef2b8debfa63ce63272d40d5d1a7438d5996c9f11208528adb6db0

See more details on using hashes here.

File details

Details for the file fcpw-1.1.8-cp310-cp310-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for fcpw-1.1.8-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 30a7c725de11b83f7663e7fb2545bf3ea692ede82eb0f5f368d2d4f963384ae6
MD5 3c7204980df470bb93221a92374ba3eb
BLAKE2b-256 6a40554947305b15cb8e53a1cd3edb1bb85cc01e7e09acbc6b01269e86af3284

See more details on using hashes here.

File details

Details for the file fcpw-1.1.8-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: fcpw-1.1.8-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 14.4 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for fcpw-1.1.8-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 dfd1f403604ec651a29ccb110f27c2d7b5af1b03b861b64ea92f02c199482463
MD5 01992439e4f1de4bd8224bed03b1aa25
BLAKE2b-256 9a5a9b7b932469a26135159565077839ac97f92538593a360bf69ecea788fd1b

See more details on using hashes here.

File details

Details for the file fcpw-1.1.8-cp39-cp39-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for fcpw-1.1.8-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4a26ebe26066095bf057ab72c17a27d5649954384a9f97aaf54fcc7c00b8aa86
MD5 48c021e2e7d40c54ce15f55a0a76e76a
BLAKE2b-256 5e5f79888daeb0bc8c4467bd91d2f8d7312aab30e502dbdf75f67b6457dbe191

See more details on using hashes here.

File details

Details for the file fcpw-1.1.8-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

  • Download URL: fcpw-1.1.8-cp39-cp39-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 300.4 kB
  • Tags: CPython 3.9, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for fcpw-1.1.8-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ca2a581e505cce1b4d599339f6110726abbd1d48041710ea1677438946ec6fea
MD5 829197d6ff68f6cb154a9145b8de17bd
BLAKE2b-256 165115dd1afc2ecbecdd21b25e5a64d845e08760542c33a17aacd4b7189a20d5

See more details on using hashes here.

File details

Details for the file fcpw-1.1.8-cp39-cp39-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for fcpw-1.1.8-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 9f6f107f26d0a0bbc624010d04a05d749684a6432963fa3f2dd673425fae9ac4
MD5 9a0e749b8d6be1efc9a32cf11783035c
BLAKE2b-256 ce6ef81dc32e95ba719c72376dd57f9b6e961d000d7de79b92ae397c7a98dd08

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page