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

Uploaded CPython 3.12+Windows x86-64

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

Uploaded CPython 3.12+macOS 11.0+ ARM64

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

Uploaded CPython 3.12+macOS 10.15+ x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.15+ x86-64

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

Uploaded CPython 3.10Windows x86-64

fcpw-1.1.9-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.9-cp310-cp310-macosx_11_0_arm64.whl (300.2 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

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

Uploaded CPython 3.10macOS 10.15+ x86-64

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

Uploaded CPython 3.9Windows x86-64

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

Uploaded CPython 3.9macOS 11.0+ ARM64

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

File metadata

  • Download URL: fcpw-1.1.9-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.9-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 4620bdc478eabe0d41930be8aac3ff2d865bf365db683e146d70a520261a5c9a
MD5 4dd55ef72771560ecc3fae4439d7e38a
BLAKE2b-256 be652fe4924aa6644005f6db0d450d9122c306de82ff588f92f8fd788ccf214b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.9-cp312-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 385582ee6373b12655b0357f0c8151300cebae550b4312c7317345b878b7da09
MD5 f4d58707b87e7a9f57e41c18c36176e4
BLAKE2b-256 7b1c306e737bd04bd91462b7a884b19cfb245be0095c781adc0f8e27e55fe05a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.1.9-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.1.9-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c2fa81b95c249babd5f5b576d23455db66092e7d28ca77dad3ffb99dec739c36
MD5 ec88eec561e0c8290d8b7ded283f80bc
BLAKE2b-256 6451b2a4452b5b4ad5490e8e4fe51d37362979030cfcac5c184f66f3f38d816c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.9-cp312-abi3-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 980c058920f9f216e3fa48c23ffdea43ff237bd8c681f28e6016108ee568121e
MD5 a360f9c58616eab675542b41cc032f86
BLAKE2b-256 3c231e1dd59b26eed6e459dbd0d3c43da0dfc47593981c152a57b6e6f7844cbe

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.1.9-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.9-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 84f6ca60bd59a1c5e91e1c3e3356a39ee2341023f468c858c7e1ba76d57be9f1
MD5 e14c5eac149d225bce9bd2b418a2e3bc
BLAKE2b-256 a5bc623f1235e00537b6766485ea87f9ae12e10ae6cd6f1d445fd440ce7e5107

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.9-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 110fb1107aad2349fe56530bdcbc16ba286d4cb6de51770b9c7f88bb2e7088fb
MD5 d0cd7bbbf94f4921bfea070d2752bf48
BLAKE2b-256 351a291d9bd7b1cb534ebb1d515f3da61bdad1a025ff74a142e200dff4b9e3b7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.9-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7c172eeecd0b6db35f22b0050efe91db777c8dbcf7c5d6d75c9fd9cea9bee987
MD5 2da274d807ee0de85096b567c95da044
BLAKE2b-256 80a326f59a20e52e96917020587cddcce381ccedb165a020855e8e43feae2b0e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.9-cp311-cp311-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 1857143ff9e1f5a77043513837ac765a7f7f4cbc3a6aabf7d7356fae62dc3d00
MD5 5b55ffd928a10e2dbd9698c200850dbd
BLAKE2b-256 fe577d2d038569bf4dad6a46ef8282834318707afceccf69e62af3347dc6de4b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.1.9-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.9-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 e75d5610c5353a0d8ed6b37efee539234631d2637998a970d95aec74630acd4a
MD5 54b9277ca35cadae7f0ce2e6929d3288
BLAKE2b-256 92f1bfe520af115079bfbb77ac47e5e69f2d6a3fbaca03c427dc9c71d6a8a130

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.9-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 fef6dd4fbcc616c2d3b510123b22e1c19611b11bccd91961d9c7ad3fffc6ed15
MD5 4fc8811ef9927bc7c333506ac45c37f5
BLAKE2b-256 3e88ce892f9f1c7ac77196d1d7aec5d340484bf5e1249fdae9fd3ccfe1e5b4b5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.9-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5372517c29f9d44c1023e0a07aeb9e92a0123ccb43f571d6c0952e8a7cea6d0f
MD5 d084f417cdf2347c2194b5230a388561
BLAKE2b-256 329aa1c59db711f62221ab48b20be87ef07bf84462e8b0c465db48a05922330f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.9-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 7b3dfcbb7dc8a1e27d2ce5419478225db735cac3a826fe8820fa8642d83ace2c
MD5 0bc82efaae6d9e686d36ae905476325a
BLAKE2b-256 3a9d6a363b98ce22a8fb25040fce2f4131f306420398af1672e81d5b3732f350

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.1.9-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.9-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 13beeed7a0a1a975695ab873a08058aa75ad9a509c7c6eb6ff74f2ba86687d59
MD5 e3b3df6b66367e526288a10deb042d03
BLAKE2b-256 e0be88220cfbc8ee0a22fe3ef9620cceba7798d4257499d402613d288e082902

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.1.9-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.1.9-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f5cbeb990ab2cdd85dc7dbb58eeb1925aa5922616063a586cd386367532c71dc
MD5 eabc18e933324198c5fb0ed0aea646f0
BLAKE2b-256 b597ddbe589424b18276e92ce94eeccbb3a600a6c8698df81500c4c503cc8fe8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.1.9-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.9-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 442a6f20818de4a3076c4f24ae89404085d649b4e7cae1ebc003c4dd9b165c6a
MD5 d4d648f803b89410177408f0b9d65af1
BLAKE2b-256 1de092e8403cfbeeced81ff02f171e63831d27baec5179ef94371c5a3bc7e5a9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.9-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 89fb7d91907a549d79226b485570930631e6136be5a6ee51c943ee88d4484ef8
MD5 75cb4464a6396ba1858be6d9170cb23f
BLAKE2b-256 c4d9575d27c0b2a436f84e9b5daaa3aa14f15dbe4cf758d732b90854173cbf53

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