Skip to main content

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.

Release files for fcpw 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for fcpw 1.2.0
File
fcpw-1.2.0-cp312-abi3-win_amd64.whl CPython 3.12 abi3 Windows x86-64 Details
fcpw-1.2.0-cp312-abi3-manylinux_2_28_x86_64.whl CPython 3.12 abi3 Linux glibc 2.28+ x86-64 Details
fcpw-1.2.0-cp312-abi3-macosx_11_0_arm64.whl CPython 3.12 abi3 macOS 11.0+ ARM64 Details
fcpw-1.2.0-cp312-abi3-macosx_10_15_x86_64.whl CPython 3.12 abi3 macOS 10.15+ x86-64 Details
fcpw-1.2.0-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
fcpw-1.2.0-cp311-cp311-manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ x86-64 Details
fcpw-1.2.0-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details
fcpw-1.2.0-cp311-cp311-macosx_10_15_x86_64.whl CPython 3.11 CPython 3.11 macOS 10.15+ x86-64 Details
fcpw-1.2.0-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
fcpw-1.2.0-cp310-cp310-manylinux_2_28_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.28+ x86-64 Details
fcpw-1.2.0-cp310-cp310-macosx_11_0_arm64.whl CPython 3.10 CPython 3.10 macOS 11.0+ ARM64 Details
fcpw-1.2.0-cp310-cp310-macosx_10_15_x86_64.whl CPython 3.10 CPython 3.10 macOS 10.15+ x86-64 Details
fcpw-1.2.0-cp39-cp39-win_amd64.whl CPython 3.9 CPython 3.9 Windows x86-64 Details
fcpw-1.2.0-cp39-cp39-manylinux_2_28_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.28+ x86-64 Details
fcpw-1.2.0-cp39-cp39-macosx_11_0_arm64.whl CPython 3.9 CPython 3.9 macOS 11.0+ ARM64 Details
fcpw-1.2.0-cp39-cp39-macosx_10_15_x86_64.whl CPython 3.9 CPython 3.9 macOS 10.15+ x86-64 Details

Total release size: 162.7 MB

Release files / fcpw-1.2.0-cp312-abi3-win_amd64.whl

Download URL fcpw-1.2.0-cp312-abi3-win_amd64.whl
Size 14.4 MB
Tags CPython 3.12 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
ee767b9c6da9efe4a749cb8d394a8300ea26f492819bbae35135fd051dc75d4a
BLAKE2b-256 checksum
How to use checksums
41e2e32fe76dd5a8244c80562b00a4a76d2dd970e93abaceaf607cffdedbafb3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / fcpw-1.2.0-cp312-abi3-manylinux_2_28_x86_64.whl

Download URL fcpw-1.2.0-cp312-abi3-manylinux_2_28_x86_64.whl
Size 25.6 MB
Tags CPython 3.12 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
75dade7b6ad878d99bcf6451fc1004de9b1bcd4790f97bc295c2a661f0779356
BLAKE2b-256 checksum
How to use checksums
20d3352dceccb497234bca6d9ee4077aca1bcf9e204fd2dbcdc27d858b890502
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / fcpw-1.2.0-cp312-abi3-macosx_11_0_arm64.whl

Download URL fcpw-1.2.0-cp312-abi3-macosx_11_0_arm64.whl
Size 301.2 kB
Tags CPython 3.12 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
ded8ef93679a19424d738d68d5a4f44dce43ada2ee7aced4cd85b5d7007e0227
BLAKE2b-256 checksum
How to use checksums
086d455a9c235c5ff3ecd2f607664a1569490e5bfd4e241d68fdcf40d34474cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / fcpw-1.2.0-cp312-abi3-macosx_10_15_x86_64.whl

Download URL fcpw-1.2.0-cp312-abi3-macosx_10_15_x86_64.whl
Size 336.4 kB
Tags CPython 3.12 abi3 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
40f8cbdc86cc76a1ecac6403bf2162f92b78086d8cd59b1e9f9601f34bcec35f
BLAKE2b-256 checksum
How to use checksums
a60b15539ac72e293bae1ddb6de81707d8d2aca32a058f9b357d05f50793528d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / fcpw-1.2.0-cp311-cp311-win_amd64.whl

Download URL fcpw-1.2.0-cp311-cp311-win_amd64.whl
Size 14.4 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
fa943c2de489cecf472f646ae8e25bfd90f917df5352c3db846162fe4920e9be
BLAKE2b-256 checksum
How to use checksums
68bf9cebd54322be4c6ff496c7e354e2bf1cd71c9d0c56e61dc5e15970418855
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / fcpw-1.2.0-cp311-cp311-manylinux_2_28_x86_64.whl

Download URL fcpw-1.2.0-cp311-cp311-manylinux_2_28_x86_64.whl
Size 25.6 MB
Tags CPython 3.11 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
41d581958ab3b3fbe6a5bf2bd65c592f185fd8ae010251ea15da28d15cc6469c
BLAKE2b-256 checksum
How to use checksums
44c475e30e9f7e1483eaca8314d8438b3a8f90cf085b2b43213316c435d31c1e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / fcpw-1.2.0-cp311-cp311-macosx_11_0_arm64.whl

Download URL fcpw-1.2.0-cp311-cp311-macosx_11_0_arm64.whl
Size 300.6 kB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
95aacae8d5a775de8024484957f9fefd45ca7454e616089350bc25e30924cf17
BLAKE2b-256 checksum
How to use checksums
c2816c649e6a1e21804bfbbd6c01a300ffc118a3c8e9cd273ced17c7b4a51d9e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / fcpw-1.2.0-cp311-cp311-macosx_10_15_x86_64.whl

Download URL fcpw-1.2.0-cp311-cp311-macosx_10_15_x86_64.whl
Size 334.5 kB
Tags CPython 3.11 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
b989dddf4b4f168e73e78d3f15fdf481175f8c9a8980ea416a7eb9fc30e60a3a
BLAKE2b-256 checksum
How to use checksums
d42896e19c8df0647f396913bb811e6495f197d58dbc7d3148d8778eaadf311f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / fcpw-1.2.0-cp310-cp310-win_amd64.whl

Download URL fcpw-1.2.0-cp310-cp310-win_amd64.whl
Size 14.4 MB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
0f6f90f563e7cc72a86513bef2b0d194dbed8e1d5e804e139624579bd1ca297b
BLAKE2b-256 checksum
How to use checksums
d78712cd6e90484475efed2db241e7830115c9c64efcc28123a8f84281920d61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / fcpw-1.2.0-cp310-cp310-manylinux_2_28_x86_64.whl

Download URL fcpw-1.2.0-cp310-cp310-manylinux_2_28_x86_64.whl
Size 25.6 MB
Tags CPython 3.10 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
17934230d81cc7242db0d030339177bfce2f61099da47b0f1e0b0f36a860911a
BLAKE2b-256 checksum
How to use checksums
3f859a22786eb88372b4dd8b029e83b1bdaa572fcfa54ecf70344d31a70607c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / fcpw-1.2.0-cp310-cp310-macosx_11_0_arm64.whl

Download URL fcpw-1.2.0-cp310-cp310-macosx_11_0_arm64.whl
Size 300.2 kB
Tags CPython 3.10 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
f41831147e299c5f25404c054681ec19d85235e593d782d7386a3045a315fa0f
BLAKE2b-256 checksum
How to use checksums
6fc9e7a068c2a245316ddabeabf060839c9382a867344e5d7f7a6885c5d98b1e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / fcpw-1.2.0-cp310-cp310-macosx_10_15_x86_64.whl

Download URL fcpw-1.2.0-cp310-cp310-macosx_10_15_x86_64.whl
Size 334.3 kB
Tags CPython 3.10 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
7a398ab05967db6a6f746ae24d6f72f703e93af29965f949b7eab5bd5b732f81
BLAKE2b-256 checksum
How to use checksums
3cf47817cf6a8a4ff1ab33110b53ca1ba5e1aa3a100dfc15b520e0945a5daf32
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / fcpw-1.2.0-cp39-cp39-win_amd64.whl

Download URL fcpw-1.2.0-cp39-cp39-win_amd64.whl
Size 14.4 MB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
ff288a892b494fee1a3439b494cb42455f9ba10251958dd93cc038bff41dd6c1
BLAKE2b-256 checksum
How to use checksums
8a82aafdb23a5fc073c76002461639b9624eace63c2967be9f28620f5cd6eee2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / fcpw-1.2.0-cp39-cp39-manylinux_2_28_x86_64.whl

Download URL fcpw-1.2.0-cp39-cp39-manylinux_2_28_x86_64.whl
Size 25.6 MB
Tags CPython 3.9 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
c472f156ee396895b50f27f78cb2c2ffffbdd42a6e189d7995b7eb9ddcb72ddf
BLAKE2b-256 checksum
How to use checksums
5584ed9c91d37f090810bd07b63c75a740ed3ad470c75804fb22a3acb4a577d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / fcpw-1.2.0-cp39-cp39-macosx_11_0_arm64.whl

Download URL fcpw-1.2.0-cp39-cp39-macosx_11_0_arm64.whl
Size 300.4 kB
Tags CPython 3.9 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
256afe44adfdd560dfeb886fa49e2dff7c4e0ef3c7aacfb933feab222d2486b4
BLAKE2b-256 checksum
How to use checksums
671a733318cbd515c30b1f0ae6f09da2540e5cc1acd99407685f2e88756f306f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / fcpw-1.2.0-cp39-cp39-macosx_10_15_x86_64.whl

Download URL fcpw-1.2.0-cp39-cp39-macosx_10_15_x86_64.whl
Size 334.4 kB
Tags CPython 3.9 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
578ed42aa8a4e5e28d1f850adf238aa9f9e1148163fe910af9cb15978dbc33c4
BLAKE2b-256 checksum
How to use checksums
92a3f554850b47b6de205b4d9560650111df6c0174d8cefbc46353d95287375f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release history Release notifications | RSS feed

This release

1.2.0 This release

16 release files

1.1.9

16 release files

1.1.3

16 release files

1.0.7

16 release files

1.0.5

16 release files

1.0.4

37 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page