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.2.0-cp312-abi3-win_amd64.whl (14.4 MB view details)

Uploaded CPython 3.12+Windows x86-64

fcpw-1.2.0-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.2.0-cp312-abi3-macosx_11_0_arm64.whl (301.2 kB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

fcpw-1.2.0-cp312-abi3-macosx_10_15_x86_64.whl (336.4 kB view details)

Uploaded CPython 3.12+macOS 10.15+ x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

fcpw-1.2.0-cp311-cp311-macosx_10_15_x86_64.whl (334.5 kB view details)

Uploaded CPython 3.11macOS 10.15+ x86-64

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

fcpw-1.2.0-cp310-cp310-macosx_11_0_arm64.whl (300.2 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

fcpw-1.2.0-cp310-cp310-macosx_10_15_x86_64.whl (334.3 kB view details)

Uploaded CPython 3.10macOS 10.15+ x86-64

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

Uploaded CPython 3.9Windows x86-64

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

Uploaded CPython 3.9manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.9macOS 11.0+ ARM64

fcpw-1.2.0-cp39-cp39-macosx_10_15_x86_64.whl (334.4 kB view details)

Uploaded CPython 3.9macOS 10.15+ x86-64

File details

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

File metadata

  • Download URL: fcpw-1.2.0-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.2.0-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ee767b9c6da9efe4a749cb8d394a8300ea26f492819bbae35135fd051dc75d4a
MD5 50c4f7cf8a4c965245adea63e2699d31
BLAKE2b-256 41e2e32fe76dd5a8244c80562b00a4a76d2dd970e93abaceaf607cffdedbafb3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.2.0-cp312-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 75dade7b6ad878d99bcf6451fc1004de9b1bcd4790f97bc295c2a661f0779356
MD5 334436e5447b6a2c1d066f0d94baa55e
BLAKE2b-256 20d3352dceccb497234bca6d9ee4077aca1bcf9e204fd2dbcdc27d858b890502

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.2.0-cp312-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 301.2 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.2.0-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ded8ef93679a19424d738d68d5a4f44dce43ada2ee7aced4cd85b5d7007e0227
MD5 79f92f6d3f9e9d63f6a60e4696cc8f2d
BLAKE2b-256 086d455a9c235c5ff3ecd2f607664a1569490e5bfd4e241d68fdcf40d34474cb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.2.0-cp312-abi3-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 40f8cbdc86cc76a1ecac6403bf2162f92b78086d8cd59b1e9f9601f34bcec35f
MD5 6846b0b1c70bd9ea68883ccaf0400954
BLAKE2b-256 a60b15539ac72e293bae1ddb6de81707d8d2aca32a058f9b357d05f50793528d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.2.0-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.2.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 fa943c2de489cecf472f646ae8e25bfd90f917df5352c3db846162fe4920e9be
MD5 f81b2d6fcd6353f385d05768ed0ccacc
BLAKE2b-256 68bf9cebd54322be4c6ff496c7e354e2bf1cd71c9d0c56e61dc5e15970418855

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.2.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 41d581958ab3b3fbe6a5bf2bd65c592f185fd8ae010251ea15da28d15cc6469c
MD5 085b8da313fcce4676bb104b24c85394
BLAKE2b-256 44c475e30e9f7e1483eaca8314d8438b3a8f90cf085b2b43213316c435d31c1e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.2.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 95aacae8d5a775de8024484957f9fefd45ca7454e616089350bc25e30924cf17
MD5 9db5fca364da23459f5134d14d1b5624
BLAKE2b-256 c2816c649e6a1e21804bfbbd6c01a300ffc118a3c8e9cd273ced17c7b4a51d9e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.2.0-cp311-cp311-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 b989dddf4b4f168e73e78d3f15fdf481175f8c9a8980ea416a7eb9fc30e60a3a
MD5 10efe77a007dcb3a26cd06e339398534
BLAKE2b-256 d42896e19c8df0647f396913bb811e6495f197d58dbc7d3148d8778eaadf311f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.2.0-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.2.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 0f6f90f563e7cc72a86513bef2b0d194dbed8e1d5e804e139624579bd1ca297b
MD5 d669f131bafcb08a6c294cabaac5da14
BLAKE2b-256 d78712cd6e90484475efed2db241e7830115c9c64efcc28123a8f84281920d61

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.2.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 17934230d81cc7242db0d030339177bfce2f61099da47b0f1e0b0f36a860911a
MD5 1cf3affa0c7f539d14e979823b2b4a1b
BLAKE2b-256 3f859a22786eb88372b4dd8b029e83b1bdaa572fcfa54ecf70344d31a70607c3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.2.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f41831147e299c5f25404c054681ec19d85235e593d782d7386a3045a315fa0f
MD5 3d73fbee63915fcd95df679e9d7e8221
BLAKE2b-256 6fc9e7a068c2a245316ddabeabf060839c9382a867344e5d7f7a6885c5d98b1e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.2.0-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 7a398ab05967db6a6f746ae24d6f72f703e93af29965f949b7eab5bd5b732f81
MD5 d2b8dec969d96ca04d6a31663c545ca5
BLAKE2b-256 3cf47817cf6a8a4ff1ab33110b53ca1ba5e1aa3a100dfc15b520e0945a5daf32

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.2.0-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.2.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 ff288a892b494fee1a3439b494cb42455f9ba10251958dd93cc038bff41dd6c1
MD5 0b95fe19c14c16d1eebdfe0fbd77c88a
BLAKE2b-256 8a82aafdb23a5fc073c76002461639b9624eace63c2967be9f28620f5cd6eee2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.2.0-cp39-cp39-manylinux_2_28_x86_64.whl
  • Upload date:
  • Size: 25.6 MB
  • Tags: CPython 3.9, manylinux: glibc 2.28+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for fcpw-1.2.0-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c472f156ee396895b50f27f78cb2c2ffffbdd42a6e189d7995b7eb9ddcb72ddf
MD5 d6936cae3ac4a51edc43e8237ff6291f
BLAKE2b-256 5584ed9c91d37f090810bd07b63c75a740ed3ad470c75804fb22a3acb4a577d4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.2.0-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.2.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 256afe44adfdd560dfeb886fa49e2dff7c4e0ef3c7aacfb933feab222d2486b4
MD5 ed5bd1a00521e7263bc5303075558aae
BLAKE2b-256 671a733318cbd515c30b1f0ae6f09da2540e5cc1acd99407685f2e88756f306f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.2.0-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 578ed42aa8a4e5e28d1f850adf238aa9f9e1148163fe910af9cb15978dbc33c4
MD5 4c0e53a317f39c0f0cc862594868a056
BLAKE2b-256 92a3f554850b47b6de205b4d9560650111df6c0174d8cefbc46353d95287375f

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