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

Uploaded CPython 3.12+Windows x86-64

fcpw-1.1.7-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.7-cp312-abi3-macosx_11_0_arm64.whl (294.5 kB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

fcpw-1.1.7-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.7-cp311-cp311-win_amd64.whl (14.4 MB view details)

Uploaded CPython 3.11Windows x86-64

fcpw-1.1.7-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.7-cp311-cp311-macosx_11_0_arm64.whl (300.6 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.15+ x86-64

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

Uploaded CPython 3.10Windows x86-64

fcpw-1.1.7-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.7-cp310-cp310-macosx_11_0_arm64.whl (300.4 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

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

Uploaded CPython 3.10macOS 10.15+ x86-64

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

Uploaded CPython 3.9Windows x86-64

fcpw-1.1.7-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.7-cp39-cp39-macosx_11_0_arm64.whl (300.4 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

fcpw-1.1.7-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.7-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: fcpw-1.1.7-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.7-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 5083a70d9dcc583f59653326a071fd1bdbc614bc57ba94dee94cb76067c1884d
MD5 ef93d961d69001a820261d0cabd22a83
BLAKE2b-256 eb58c40786f9726568a4716d5127c6f101a1734251cf4871257bfcbed4ea520a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.7-cp312-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 533f00974ae45eede314be897ee8443510a8ca149cb58b0db5a920702df50bf4
MD5 2c8f29da1e36e8598d3473e1bd0f84c3
BLAKE2b-256 d4740a77ad2e2d4a031134da995e32ab0d6fa5a9c8989a5d92c2b7bb6c1b986a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.1.7-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.7-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ad69b88896ba64e3db5b0716b6dbc48f13ad2a741ed6542c6381fdd9270c831d
MD5 a280a880fa7ba798fce8ebe915ae6c93
BLAKE2b-256 07c18781c0b04ff6fc9ad6959449fd23c98b412df9e7be51c762acdeea6cd9ab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.7-cp312-abi3-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 ee942559d3dd82b5e61f7189d1b70af6719067a4497bf5eca862a4525a5445bd
MD5 e5b9d94cf945b7b6315c2fce0591fd2c
BLAKE2b-256 56dedaddd6e801bc59093650309abdab7bc5bfc0348cbac9de8ce0275012a74f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.1.7-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.7-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 3f518673fb0573cf6976c98437ecf09cbf4df57996bdfe276db71bcc5acf9acb
MD5 a8fa85d25fa4c160fa5397bf708e3c64
BLAKE2b-256 b2871bd0a276756719113643426532de3fad42737a68f93a449c7e660d5871ce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.7-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f70a633365d088890fb01ffb8ef37d57e0ed2e984cb7fb034ce6ee5643016e6c
MD5 262a1fa7c62d5e41ef033110278850f5
BLAKE2b-256 5b9490e9745194857b63b65e6fb0925bddeec196528566fc10d052987490261b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.7-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4f928ca415fca2bb4bbb9946c13ca2901411cbb2e651e1dd619a0ef91e3fc430
MD5 9395f9623f3dcc6a3cf58846e44e6694
BLAKE2b-256 cc035c0f0e4b5a8b4dcfdc28eec8b9dbcd4a763a12554dc68a18241f6833fbbf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.7-cp311-cp311-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 abd241690af4eb077d95c3bc05856d5860db15f45f9903576501bd030da48235
MD5 de319d5ba9a6afb11818fdb912b5c585
BLAKE2b-256 695d2319ec61964d66cb7d7e43ddb37a493de3b764209fad53292b42c3f7f787

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.1.7-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.7-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 e00bf5fd92c75e838487814b5425c05abb7a2bc1acec22aece5820e8df9cfb1d
MD5 4826f0d9c332947cce3a88a1e9d4f7ea
BLAKE2b-256 6571d4ab781ca61e821f32627370764610440d4066b8e1e5f07d449c9823d1e8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.7-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ca80452eb711da18560fabb2c6bb0802801203ea477d7e1e52020c3d1c40cfbc
MD5 e745625e14a6eda01250b5b70277ecfc
BLAKE2b-256 17875438c55d0bb56061f92b18e67574fd94cd7b863952109934a1f4a20ee177

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.7-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6ac35808c7da73d5a0d4a4eba094588ed9a167b453e9c9f3e6c36d29583ea960
MD5 6210c546742b106daa49bf5d7ed0d515
BLAKE2b-256 bcacc91dee428d05f3c2949c1c3e188ec4c9c5fbd9bccd931caf59c4298cc503

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.7-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 6136fbc4fa1d6146d654d01d3baf88682f065e3a145ea7289bbaf09abea0dc98
MD5 e81e6cd839225e20051f9b6c70072c96
BLAKE2b-256 7eb5e9780d108645c70e7031f83bbf2b1b372242e643f1b0037f336090763627

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.1.7-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.7-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 6150a129e53538dec62b4f28f3bb0bea8b523f288a39505eee9718191b182b14
MD5 a5ff777ef37e9d4f2a9ad0bd06e067b6
BLAKE2b-256 94d66a81983b0421f111760fbad98b7d045fd913894e9915603765dffba2fa59

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.7-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1104b29de2459370280e79864cdc30c63d247383fb867ed6740c49330d5b2028
MD5 07eb3fcf8c429700c1e97b3097c13c3a
BLAKE2b-256 e89dad115d89430e63feaf3de883df50db80847c43ca62816e8558886647dbf2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.1.7-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.7-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f1ea2c5c4e1e4c406d693258838c91f0dbd2999b8845ced40d6f77af305c722f
MD5 af1825a18a0ae37e7f3e3353e3bfb26f
BLAKE2b-256 26fd461911f8d2d9f06742d861591644c9a03daff507a21527f430aa37346b6b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.7-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 c406c5b4839d9984eef5dcb8a3a4c18a892514ce09f0a5543f4794d9acc42d41
MD5 99be1c5fc7903a0f8e4353b9cf9262b4
BLAKE2b-256 e03cb26d67f2a429b76a38b2a79ec993c90fed8849e9f055963f067775ab6986

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