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

fcpw-1.1.1-cp312-abi3-win_amd64.whl (10.4 MB view details)

Uploaded CPython 3.12+ Windows x86-64

fcpw-1.1.1-cp312-abi3-manylinux_2_28_x86_64.whl (26.2 MB view details)

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

fcpw-1.1.1-cp312-abi3-macosx_11_0_arm64.whl (290.9 kB view details)

Uploaded CPython 3.12+ macOS 11.0+ ARM64

fcpw-1.1.1-cp312-abi3-macosx_10_15_x86_64.whl (325.8 kB view details)

Uploaded CPython 3.12+ macOS 10.15+ x86-64

fcpw-1.1.1-cp311-cp311-win_amd64.whl (10.4 MB view details)

Uploaded CPython 3.11 Windows x86-64

fcpw-1.1.1-cp311-cp311-manylinux_2_28_x86_64.whl (26.2 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.28+ x86-64

fcpw-1.1.1-cp311-cp311-macosx_11_0_arm64.whl (296.7 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

fcpw-1.1.1-cp311-cp311-macosx_10_15_x86_64.whl (330.8 kB view details)

Uploaded CPython 3.11 macOS 10.15+ x86-64

fcpw-1.1.1-cp310-cp310-win_amd64.whl (10.4 MB view details)

Uploaded CPython 3.10 Windows x86-64

fcpw-1.1.1-cp310-cp310-manylinux_2_28_x86_64.whl (26.2 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.28+ x86-64

fcpw-1.1.1-cp310-cp310-macosx_11_0_arm64.whl (296.5 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

fcpw-1.1.1-cp310-cp310-macosx_10_15_x86_64.whl (330.4 kB view details)

Uploaded CPython 3.10 macOS 10.15+ x86-64

fcpw-1.1.1-cp39-cp39-win_amd64.whl (10.4 MB view details)

Uploaded CPython 3.9 Windows x86-64

fcpw-1.1.1-cp39-cp39-manylinux_2_28_x86_64.whl (26.2 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.28+ x86-64

fcpw-1.1.1-cp39-cp39-macosx_11_0_arm64.whl (296.6 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

fcpw-1.1.1-cp39-cp39-macosx_10_15_x86_64.whl (330.6 kB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

File details

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

File metadata

  • Download URL: fcpw-1.1.1-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

Hashes for fcpw-1.1.1-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 8e93529e0b1ad67958fe10739808d27b60b230f85d091c2bf98341e910c8a606
MD5 dbd586c038b7aaa6cc942cd83c1b3eec
BLAKE2b-256 e155831cd0264c99c78c3a2c4df268f01a39836f3665eff12fbc222d8b12eeb1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.1-cp312-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ccb6b6f94867b7b131cacf7a988517b551878d86fd19cf91ccbe276693d00d76
MD5 3473a60d66ce4fdbe02def7defceb440
BLAKE2b-256 64c012cf142ad660854f855b9831a4bca5fd419abe3f2e182c026b70ec5f1bad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.1-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f7b8c41cca29983da6d5c7e7dc58fbc0e79e01b117254e451796e46236aa9e4c
MD5 b01064c97eb5eb9593ba03a58bfdfeae
BLAKE2b-256 bde619b2b04972d6eeb4f3e22be2eaa898727b634e5e92c1cd138fdec1fa51c7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.1-cp312-abi3-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 2768c54225b1fd5c19ff697e1602ada748c72bf20218692830260fa419578604
MD5 35f1a9949438e969d2ac8f03fe21a5cc
BLAKE2b-256 2cc7b44b9e6bd9caade5f68163312394ba00cbf7a6458f09064021eab7a4f25f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.1.1-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

Hashes for fcpw-1.1.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 ad17701118ab8df5015371c9d73043fcc945d4b526a4f6a07cb6e3be5aad8b20
MD5 e17667c8f9ba860a3687b52e9df2707b
BLAKE2b-256 6a9388fcaf04cce0f5b4fedefdcfe3b20548f03a53039e01d36b7c6e86561313

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.1-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 35428fdf1c3c97fd5f7a20fa78156556e75c8479b5ac45508a3c369f53fb166c
MD5 e164c6c1d36df4b37ad0b14cbae31074
BLAKE2b-256 ebb9d1860153764772781996eb81baa7f9de0bde46f03048af51dae0182582c8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 54aadd5a5bd248d5aa45f79fd25f68695af0f4e7f002ce6a58eba3653ae10d18
MD5 f0b3e1e0a6f9e291c9d7ce02b8639ee4
BLAKE2b-256 7ae199060e0a0a899eebcc7808c935d704c869ee3fbd9c9b60663d59b1e46ad8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.1-cp311-cp311-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 a82710d4cac6d0f23f017fc94592b267b21970b4ef18c2908e18b215e5ae7c48
MD5 1879ff77ea3c630873d0032b5811cb30
BLAKE2b-256 0c2bb187a1e447cb7840c79514e6d43f38f5872bb6adc90c94bba8e4064a1508

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.1.1-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

Hashes for fcpw-1.1.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a9183c6b098383ff0af0f7b5e4290e21078a894053a45f2b1560dcd8e1489fd6
MD5 87a58b01330cfecea85d648e79b91b45
BLAKE2b-256 45023332460d1ae8227128135321c2c61384c9d29eae0d9c1f7bee4fa2b7302c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.1-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 25c43261d125281c0c9b977ba8aadd29ad0e6c072a0827e1e1f69f41743246f9
MD5 58bf30bda57cb4c6adae9c71b783c2b6
BLAKE2b-256 4bfe353c0877c146b12177c84b87bd330aedadecad09d9a521610589130f1ae4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9e19e6edd4fd5bbcb54b067d1869ad01c5ed961e530e65bfb16e64036c40c6ad
MD5 1dda7d24d33d94e7c22573b89687902c
BLAKE2b-256 92c8db3c00ad596f80ccb00ea808860a25afe1e2e460cfe136452a9902b8349e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.1-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 84a460b6d080dc8dfdad795bc19b9c00d51fd921d764ea6b5b88627fa0a19631
MD5 525715cea19c852bdd1fb716f2ac220d
BLAKE2b-256 e594ff3ab344fc0e80654648bfa43a53a04a65c7c669981a794f3ca4e3403855

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.1.1-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

Hashes for fcpw-1.1.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 4e9aee14b09ec8c4bb564ae06ff0726524fb6368a2eabe755d571e483e87e1a6
MD5 f0379f3e5549f30b4fd5ca4e3af9238f
BLAKE2b-256 b3aed067ff17239c0d7c95da8dd92917f6d665f8a8eb069a332c755caa6933f9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.1-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 379201e378629274f3d33290117640f096687b6826a67f48d33880f665984fd7
MD5 5c108ab046d9b2065fa18102e5a00cb2
BLAKE2b-256 ef92038cc6367fa1a541fff609ffefd9da4781909643fc1121fa8a4716e7b7ab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ec9aeda465a53cc4642856afa3c32631f7e80f14e18ea7c4d8a30df3a46804e8
MD5 9f6e2fddc72e2aa2adede39cb862acba
BLAKE2b-256 3bcce83ecdd67e38c59c8145deee8624447472cd9bfc9c4ed4742cec9c4978e3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.1-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 195494b7f4d0daae5549748815b828c8f3c7529585af75813bf8d171a81dc935
MD5 56e227fc249272a8655ebfd96b360cb1
BLAKE2b-256 17f7a64c73f8525804900fc8766802be3404b7a7c28f9efeaa06a73480c9cc34

See more details on using hashes here.

Supported by

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