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)

# initialize bounding spheres
bounding_spheres = fcpw.bounding_sphere_3D_list()
for q in query_points:
	bounding_spheres.append(fcpw.bounding_sphere_3D(q, np.inf))

# perform several closest point queries
interactions = fcpw.interaction_3D_list()
scene.find_closest_points(bounding_spheres, 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)

# initialize bounding spheres
bounding_spheres = fcpw.gpu_bounding_sphere_list()
for q in query_points:
	gpu_query_point = fcpw.float_3D(q[0], q[1], q[2])
	bounding_spheres.append(fcpw.gpu_bounding_sphere(gpu_query_point, np.inf))

# perform several closest point queries on GPU
interactions = fcpw.gpu_interaction_list()
gpu_scene.find_closest_points(bounding_spheres, 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). Installation details for Slang are provided below.

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, for GPU support the FCPW_ENABLE_GPU_SUPPORT option assumes Slang binaries are available under deps/slang. Copy-paste the contents of the latest release under this directory for the relevant platform. 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]

For GPU support, you will need to follow the instructions in the previous section on fetching and placing Slang binaries under deps/slang. 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.0.7-cp312-abi3-win_amd64.whl (10.2 MB view details)

Uploaded CPython 3.12+ Windows x86-64

fcpw-1.0.7-cp312-abi3-manylinux_2_28_x86_64.whl (25.8 MB view details)

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

fcpw-1.0.7-cp312-abi3-macosx_11_0_arm64.whl (298.0 kB view details)

Uploaded CPython 3.12+ macOS 11.0+ ARM64

fcpw-1.0.7-cp312-abi3-macosx_10_15_x86_64.whl (335.6 kB view details)

Uploaded CPython 3.12+ macOS 10.15+ x86-64

fcpw-1.0.7-cp311-cp311-win_amd64.whl (10.1 MB view details)

Uploaded CPython 3.11 Windows x86-64

fcpw-1.0.7-cp311-cp311-manylinux_2_28_x86_64.whl (25.8 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.28+ x86-64

fcpw-1.0.7-cp311-cp311-macosx_11_0_arm64.whl (303.9 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

fcpw-1.0.7-cp311-cp311-macosx_10_15_x86_64.whl (340.6 kB view details)

Uploaded CPython 3.11 macOS 10.15+ x86-64

fcpw-1.0.7-cp310-cp310-win_amd64.whl (10.1 MB view details)

Uploaded CPython 3.10 Windows x86-64

fcpw-1.0.7-cp310-cp310-manylinux_2_28_x86_64.whl (25.8 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.28+ x86-64

fcpw-1.0.7-cp310-cp310-macosx_11_0_arm64.whl (303.5 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

fcpw-1.0.7-cp310-cp310-macosx_10_15_x86_64.whl (340.3 kB view details)

Uploaded CPython 3.10 macOS 10.15+ x86-64

fcpw-1.0.7-cp39-cp39-win_amd64.whl (10.1 MB view details)

Uploaded CPython 3.9 Windows x86-64

fcpw-1.0.7-cp39-cp39-manylinux_2_28_x86_64.whl (25.8 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.28+ x86-64

fcpw-1.0.7-cp39-cp39-macosx_11_0_arm64.whl (303.7 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

fcpw-1.0.7-cp39-cp39-macosx_10_15_x86_64.whl (340.6 kB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

File details

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

File metadata

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

File hashes

Hashes for fcpw-1.0.7-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 bcd1d907df332431f815162d2058ae3b2d86fa237e4d28ce39abdf3579c93168
MD5 1eeb954118fc548d1837766dbf885a75
BLAKE2b-256 79ea05cec0fd8cfc0d83b3fd19b85a670952d1f0e145316482712ae55f72b330

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.7-cp312-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1041ba7b8f76df99cb2c40b93410a8df8a230d0d1a793073aa6f12666e6ed254
MD5 ed8481b8cc0975ef4005e80e93c27772
BLAKE2b-256 0f777b0c682cd4fdb9a85002a9b1d81746ac5f097f6847fef49b33950fa0a7e1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.7-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 024821613dd9138f4f60f809eeef8fffad26f0b6d34c7fad97c4d0119ad60a05
MD5 541acaae731c8e8f67c7e6dab4498a71
BLAKE2b-256 0642e22caf5817be43f58b59eac525e83189be2af98daa17e60e368f512972d4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.7-cp312-abi3-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 3d1583001ced7ef611d2a93946710531b63efd79f389387e339db5f6cc0e43aa
MD5 38feaaff4e9a62bc8431ffcd6b1b1cc6
BLAKE2b-256 d1b6e03d6e2ffdc5cc8d4887c88f71ed43d744baca52fb948ff2cc971a6bb714

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.0.7-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 10.1 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for fcpw-1.0.7-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 8cb6718533a461ca073245e5535c98ab13fad646550f3b9112b63a1e91049b72
MD5 16f07a2aac9b9f5d59e91298aa56efb1
BLAKE2b-256 c38001bc27b28a08fc687dd12b16a5f9ba7279f6390d052b2c6fb135399cade0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.7-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f4f2a3c6fc5f4d2eac2ec8bc8c6084c2aed4e6fb9d1cac887143ecc1bd1da40b
MD5 3df1963f8f0f7ee538e5410bc1c0a089
BLAKE2b-256 25a37bdb7f3545f660c8704f2cd9cc3fe9973fd647df328e7c3586477ae349c9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.7-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4e117b33c0d8731f4d7e9c3d3f571be1f3a285401b54187d7ad20dfa53746316
MD5 c0cc9c82399ff3da298253716852afb9
BLAKE2b-256 4049b944f31f047898917ee63c4c259aec8b24976b92c2855ae038d69220a251

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.7-cp311-cp311-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 3473c6f79807d0f1bd55ca8234b1cdd98943b8d58fbc5265b84aea6d445430ff
MD5 7a932f3bc12c9e74bbd7bb2a47d84748
BLAKE2b-256 9ef42483c17e21fd5dea385b7e60108d28e947935fb86e0a9ebb6fbc73d55cdc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.0.7-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 10.1 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for fcpw-1.0.7-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a69c965a2eaf9538a24e0ef09083deeabb9f7327c4dea8d3ad53afca98085089
MD5 e4d889e14ed341ce980f103e7f406278
BLAKE2b-256 19d284df59170ce333da787a58bdf533b1c1a6269dccda55eb522f1f33b2f1eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.7-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cb7a0e3729d2ae3454976e347f4aaf7f528e2398a332e6e007c7cae0917908f4
MD5 538a368e6179c6b5ffecfdc51605e76e
BLAKE2b-256 a3a6efab3899fea9e576d6efbb3470ff5e588aab67c8fb5c0f938e0455deee42

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.7-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 eb0956ff87fcf9a234a002f7ed1c1b87098b9909f6a424f5e55899c13e6f43da
MD5 b7436002f3272870c7e96116bf085349
BLAKE2b-256 b9df81c1c2a098d19c4ecd87584fe43274c7477ffad8ef8fc053d4422a443f33

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.7-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 69cd13d5c68a7efd3b19eaf068694985200207ef48f3f33f0a01130fe6b6cc43
MD5 673dbc4c5a5aaddbde4727137a73a5ca
BLAKE2b-256 1e9007dbd09bf8e718e7c82c87db8b3080d34f33a44d8eb6dea39c6542fb588b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.0.7-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 10.1 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for fcpw-1.0.7-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 648d0477fa1e0a5d773fb84e3b2e5fa9c7f3f70e1f0994c1ac32f35d1acc7fcd
MD5 d21a7c97e35688235920e6f271475a80
BLAKE2b-256 80a647f2e22dd3524c766310ccc628e29dedc25d4703548932bf9906db84d698

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.7-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 08fffa78481051551bb888de3d5537c00771fc939f41f66e8f8b402cd95db55b
MD5 b0255e3dcf1a6f465391e2faaa727c85
BLAKE2b-256 3ce303cbde9371620106bfc015fcf30a0c20eca3691a9d9d01753da806ae0e04

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.7-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2cb934d2c474ef39ff6013ce9d35c77e8476d0f268b7ac16a8151cc7cbc4bad3
MD5 7ae8bffec39fa84eac3fb63d4ee32f81
BLAKE2b-256 fcf7371d15cf32ca9c605c33ea421b88d765faefb5e16d61d9d4efb0ed9d20e8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.7-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 2a6ecc4e3d96b4f658f0ad8ff90e0b162b8e3676fc9e5d155215886702e93340
MD5 78b6e62a4566781f3121b705dee21974
BLAKE2b-256 8b6cd2b4e18e4671da0b4b74f3d1a1dade8f33b9b5092505e69ca28a113ff539

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