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).

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

fcpw-1.0.9-cp312-abi3-win_amd64.whl (10.4 MB view details)

Uploaded CPython 3.12+ Windows x86-64

fcpw-1.0.9-cp312-abi3-manylinux_2_28_x86_64.whl (26.2 MB view details)

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

fcpw-1.0.9-cp312-abi3-macosx_11_0_arm64.whl (280.1 kB view details)

Uploaded CPython 3.12+ macOS 11.0+ ARM64

fcpw-1.0.9-cp312-abi3-macosx_10_15_x86_64.whl (314.8 kB view details)

Uploaded CPython 3.12+ macOS 10.15+ x86-64

fcpw-1.0.9-cp311-cp311-win_amd64.whl (10.4 MB view details)

Uploaded CPython 3.11 Windows x86-64

fcpw-1.0.9-cp311-cp311-manylinux_2_28_x86_64.whl (26.2 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.28+ x86-64

fcpw-1.0.9-cp311-cp311-macosx_11_0_arm64.whl (285.7 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

fcpw-1.0.9-cp311-cp311-macosx_10_15_x86_64.whl (319.5 kB view details)

Uploaded CPython 3.11 macOS 10.15+ x86-64

fcpw-1.0.9-cp310-cp310-win_amd64.whl (10.4 MB view details)

Uploaded CPython 3.10 Windows x86-64

fcpw-1.0.9-cp310-cp310-manylinux_2_28_x86_64.whl (26.2 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.28+ x86-64

fcpw-1.0.9-cp310-cp310-macosx_11_0_arm64.whl (285.4 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

fcpw-1.0.9-cp310-cp310-macosx_10_15_x86_64.whl (319.2 kB view details)

Uploaded CPython 3.10 macOS 10.15+ x86-64

fcpw-1.0.9-cp39-cp39-win_amd64.whl (10.4 MB view details)

Uploaded CPython 3.9 Windows x86-64

fcpw-1.0.9-cp39-cp39-manylinux_2_28_x86_64.whl (26.2 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.28+ x86-64

fcpw-1.0.9-cp39-cp39-macosx_11_0_arm64.whl (285.5 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

fcpw-1.0.9-cp39-cp39-macosx_10_15_x86_64.whl (319.4 kB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

File details

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

File metadata

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

File hashes

Hashes for fcpw-1.0.9-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 6031eb9c5c624889e4c29d638f1fc3db439a249fc5ea996bbace8ee176c3e9d7
MD5 dec4a962d520858e994da025dba9fd8d
BLAKE2b-256 2b09fb881eb924723d26233a39adc5d721bb3c46663d00e9511ac55d798139a3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.9-cp312-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c5fb3ea6b2749788a99bcdbb67267823dd448397555778b38a4e6127d590629a
MD5 8db99f8ed15ebe18ca183e0828e9dfa5
BLAKE2b-256 6487f9967ac638967dd1d1addda1375cb8cd9be348021af894694054977d0ba2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.9-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1732f0056938ada8cb423a3c10286c9e9fff9fc8c9ed9714d2be33b3e583d900
MD5 4ef494949fc78a2bb30c5c79975aed6d
BLAKE2b-256 34bfeac942f6684e915f6be120d1273f7ea2c628d6ca9cffdda629049567dcf9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.9-cp312-abi3-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 9a0bf8fce85a607a09d0a3abdc7272bb23a9c42fffc488e10e9be3e14b725036
MD5 093ca3d0d4546fa28792245b735523ae
BLAKE2b-256 6dd2745e5bca3b389f0e631220b4fbc0411ff7800516c3fa5c475cdf5e88da45

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for fcpw-1.0.9-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 5b19992d36a4ee665224d74d4f158871f89a8343d9605eb0700054edc6138a4f
MD5 1d88e74d3436d2200c6aa27af696990a
BLAKE2b-256 9d4efa531609a41f4b0b658f4572d9f6e25a59888d5c801cc6a919edfe509a99

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.9-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cfd7604e1882cfb3d5b2019909732329bf9cd4d60f2446873faeee58e6cc88ed
MD5 1782d4fbf927ecf70e58368b7c4f75cc
BLAKE2b-256 fad55b0b727ca603bda497b97736d36c4d97c34bca1e02ecc4d22c3f9cc77e35

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.9-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 91f13b65551b450b83dc117dd8c00f8e9f33be7f4bf3e5dbfde302ba6bb9933f
MD5 deac1c5ee27c43c261f8d96f552fb7fb
BLAKE2b-256 62bc4d1d5483bc21d2ab82997a7999f20e7e1a1b4a07ffe5ed881660ccb237d1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.9-cp311-cp311-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 6f1e62dba5236675649da9139c8831809d4bd40b2bc2cac2574bd815c3ecf710
MD5 12f4d14143727a3c656afd078685d805
BLAKE2b-256 e3a2130c74845e2ad4dfa4c9193d9ec24bcfd93d8c86fddb275c9b9fc034d8ab

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for fcpw-1.0.9-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 10d155b707b93f2b1caca46d83a1eabca9faeaceec382cbf456578a7d0751dd9
MD5 43db198d55b8522de01b71615a8c7485
BLAKE2b-256 b40196e6e801429d9ac7fcd4c8ff82017c46f842faf53d7fbf4c344dfa3b15a8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.9-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f562e95db15520feeb4eacec3a221c4f7ca1c3acbcab6ae2f7a0cf7523bff73b
MD5 b0b79939559f1a1fd952d1d6328d96a5
BLAKE2b-256 45a7ab8d297c3cc5d5a317525228504d8d7566263b21008999100e028cc44bb1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.9-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9c0f484d0025c7f709322e6b23f0efb3a6a2b1bbbb4c954d5a15cc1822f88304
MD5 924ae18b63c119a6af2611890f36a419
BLAKE2b-256 f33554066d5d8b1b25addb4a5ee7c6a8b0ed1e8d74bcb4d3dc0090aaf4f4f6d9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.9-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 19b55f88bc3a2bf88d6b1c5dbd89b5ae887890fa3cdf1147f4d22900dba67125
MD5 7945232fb8a0cd67c29e60d37fc818bc
BLAKE2b-256 b43cd4d30c93f4e3b2ff8d5d6cbffc818cfb89cd7ad9f6fabff91fd2c0977c50

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for fcpw-1.0.9-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 c03afe7a179cd7f9d2cf5acc7ab82444024082ebaaa12b8bed449a14fd3ba5a9
MD5 71faaa3d6cc2fd77799e9ccba1090572
BLAKE2b-256 c341e2207035d892b7f325bd582f79708cdfc8b3cfbaa556045a3f5c53d63e4e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.9-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c5e9af0c5f1110e65ab9c1c2df11ca904cf14bb9a60787af9db3bc6905775a6a
MD5 946172a692d53f4d5be03a723be64e13
BLAKE2b-256 cc95a62680173ea3c6bf9dbe00132f2fef2217fa637c9dcfbe4c5978cf222ea3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.9-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 344223e0ad65f67653d9a97bfb480e37b0ab4db0692b844a2ef355e5579599b9
MD5 f944cfe8e75cc6280099beaf41ced4c1
BLAKE2b-256 ff41509ef959e7dc5c83a6cade8aa552dc7cdb1b7ae815b29c0b771baca7e590

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.9-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 b19f3c7302aeac20d5bb21815c221b5263dd26ab9de4a4e084c87f4de65b9447
MD5 7ab6ed2b8fbd585e23217f7cb65dc794
BLAKE2b-256 55394d9e64c7d9b744559bd6fea4825d4305e1fa3d5732772596cfc6f3c9c6d7

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