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

Uploaded CPython 3.12+Windows x86-64

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

Uploaded CPython 3.12+macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.15+ x86-64

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

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

Uploaded CPython 3.10macOS 10.15+ x86-64

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

Uploaded CPython 3.9Windows x86-64

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

Uploaded CPython 3.9macOS 11.0+ ARM64

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

File metadata

  • Download URL: fcpw-1.1.6-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.6-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 3f82dc0ed6b2d4f6d8aa885fb8d7b2f21f5fbfa0ba792a82405fce565b6d4f39
MD5 f0b7e36ee7ba7aad9f8f04fa4ff77eca
BLAKE2b-256 962a3ddcd38ea82ca258aa1a8c15443113f94e2c7e7c6a9f2d3f69093bf302c7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.6-cp312-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f269acfdb9b93d494408f8abff92d1039880ba0cc45722497ec39f479ca8df09
MD5 5e370d2d2d4276d6a8b4c13a3320e7a7
BLAKE2b-256 72b17007b3ea73e48d2e27152d778e105e1207438b8c58450cd2fcf4e9e3cd44

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.1.6-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.6-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e1b2260f70c20250f7a945a03512aa1a4c76ed55bd2a9480232e299eb1635869
MD5 4288e7e1c6ca494664c7cc5abdae354e
BLAKE2b-256 180f6b78b06a091401aa41ed0f0c4803a44fe4a61c1e730b30a9892c5daf110d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.6-cp312-abi3-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 ddc8dadab1545499d6665c9b691519712abf12995aa95d781c08a04e5d34fce9
MD5 2567215aea26d3b0bd4da9c122310c05
BLAKE2b-256 450c4ced1c3d291435a5f512a4333b22ccd919000f49b6104514a814e10d3802

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.1.6-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.6-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 187871d14ca6b88eec892e01719fad3b938e8570fa01bcf633fb1b68c953e26f
MD5 42f83794a7ea15c97a518c85a0505a24
BLAKE2b-256 b755620085dcdf9d72c2ebe8329c07f05583b78de595ba88001c8cb83f81035d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.6-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7400d0cadedd7c6ab51ac48b4766417c7b0b2796b44c95ef4fa00d63d376ee64
MD5 2e03cd84fafe5896ea65bc449dc4b127
BLAKE2b-256 54da9030963f33a41751f49edec064326b6fbc7f4f68f7820746a19791139922

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.6-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 26a308c2184b243de60fc73a134a20118465ed528cf099156406463c0d7a564c
MD5 1d9cb1aed6db0c85c6b078745473e6a6
BLAKE2b-256 eaf6d434ee94cc025d97226119857add55eb5c90e9fb60eca51840b54ad5e673

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.6-cp311-cp311-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 2e61089b5f769eee022719589f4afc4d438a62048aa5e233ef9d5e5ad0e02a75
MD5 096cf84bad6d604f9f454cc96baf2915
BLAKE2b-256 b7459a936ef5862e5191d03d763835e28c8fbaf4e2823ff3403c51a4c8a14dc4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.1.6-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.6-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 68f8cad33423e92df8132503d9c430374da6d098531015cc5a613c574c5de004
MD5 6737d77f541f4a535b214caf0fc223d6
BLAKE2b-256 33996f7aaed978034abd0edd0c653c8d10b7c6930123112fc3e21cb1b908fc57

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.6-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 193276bf3131beaf6b3f8fa0be7c079a2825f0663f6dd68c55593c89d7581d4a
MD5 1a42eaeaf4c59601567cbc106e8c2c4c
BLAKE2b-256 e66960d31591067801cec9382de7674874abd7455e7348d5e3164def5c904274

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.6-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7f85dfd67889bdba8f40b3186905da8637dbc503a37e9f8f2c7389cc22c6fd98
MD5 2652de058a56ea794346a670cf8f8d79
BLAKE2b-256 004d40826c374bebec183687456425dd6c25de8f7552a71c2f3378dcfbd3ec22

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.6-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 61a48edfcdbd8e47d456e5ea43d3fec06470f6fceeb682cda8e85b843553111d
MD5 50fc8ce0c32149759bf8246b0d9d1ebc
BLAKE2b-256 8ee47b4f12a2a7cdace95d1416a25eb3f2136d8130bd5ebe534cef93a3fe3ef1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.1.6-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.6-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 d233cf87ec8e12717354ff0776d715b52346a5701732b837565598f87d60b929
MD5 d5fdfc1328fb660a0301903cb2cccca5
BLAKE2b-256 66055c13ec0301aa059326ab94702b956703b6c50688530ddb1d31031a0bf492

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.6-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 086aeb4f0046506e0c632996ae81ae1113d8904536b44c1be6fb72f9f73d2975
MD5 6fb81c0645de4da67fbe57286c064cc2
BLAKE2b-256 15e04427984ea6114582756557ee189ec450a006f48161f7701de1fd5da924aa

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.1.6-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.6-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 440d06a4f5fe3a296c25e54c7cf23ca1e9fc44571f1ee2e48b2b89a72a77f7bf
MD5 a15055817a48710b290f71b2320ab8a0
BLAKE2b-256 92c0679e61aa319e522aed8b0304a9aa738a73588335c71560ef71a01783fb11

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.6-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 77ba7b3d85bb80cbc7f17d1bd54b154482e1bca399783e973cbb796970a7796c
MD5 5e94ad504a650033e6fdfae5051f9b68
BLAKE2b-256 14c51657dcd54fef4028fb10a334c1ed583f440005d12ce962f685de7f0274af

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