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). Installation details for Slang are provided below.

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, for GPU support the FCPW_ENABLE_GPU_SUPPORT option assumes Slang binaries are available under deps/slang. Copy-paste the contents of the latest release under this directory for the relevant platform. 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 but without GPU support:

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 with GPU support, 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]

For GPU support, you will need to follow the instructions in the previous section on fetching and placing Slang binaries under deps/slang. 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.5-cp312-abi3-win_amd64.whl (9.9 MB view details)

Uploaded CPython 3.12+ Windows x86-64

fcpw-1.0.5-cp312-abi3-manylinux_2_28_x86_64.whl (25.2 MB view details)

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

fcpw-1.0.5-cp312-abi3-macosx_11_0_arm64.whl (297.0 kB view details)

Uploaded CPython 3.12+ macOS 11.0+ ARM64

fcpw-1.0.5-cp312-abi3-macosx_10_15_x86_64.whl (334.5 kB view details)

Uploaded CPython 3.12+ macOS 10.15+ x86-64

fcpw-1.0.5-cp311-cp311-win_amd64.whl (9.9 MB view details)

Uploaded CPython 3.11 Windows x86-64

fcpw-1.0.5-cp311-cp311-manylinux_2_28_x86_64.whl (25.2 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.28+ x86-64

fcpw-1.0.5-cp311-cp311-macosx_11_0_arm64.whl (303.0 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

fcpw-1.0.5-cp311-cp311-macosx_10_15_x86_64.whl (339.6 kB view details)

Uploaded CPython 3.11 macOS 10.15+ x86-64

fcpw-1.0.5-cp310-cp310-win_amd64.whl (9.9 MB view details)

Uploaded CPython 3.10 Windows x86-64

fcpw-1.0.5-cp310-cp310-manylinux_2_28_x86_64.whl (25.2 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.28+ x86-64

fcpw-1.0.5-cp310-cp310-macosx_11_0_arm64.whl (303.2 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

fcpw-1.0.5-cp310-cp310-macosx_10_15_x86_64.whl (339.7 kB view details)

Uploaded CPython 3.10 macOS 10.15+ x86-64

fcpw-1.0.5-cp39-cp39-win_amd64.whl (9.9 MB view details)

Uploaded CPython 3.9 Windows x86-64

fcpw-1.0.5-cp39-cp39-manylinux_2_28_x86_64.whl (25.2 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.28+ x86-64

fcpw-1.0.5-cp39-cp39-macosx_11_0_arm64.whl (303.3 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

fcpw-1.0.5-cp39-cp39-macosx_10_15_x86_64.whl (340.0 kB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

File details

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

File metadata

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

File hashes

Hashes for fcpw-1.0.5-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 4384f92ecf315802ff3c0835e92805f3972b5f2ea914da66f52f45ff2ec924b6
MD5 4cd8ffb5da5d18045d2bc6581bb7cdfa
BLAKE2b-256 dd07b73f493354836cc259b456357b6298593af9768c9d86a5325ce64845b5bf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.5-cp312-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3d1360700202c8a1184ce60a3d4d5b44502967e90490e81b670e26270928f269
MD5 fb64e17c59b819e2dd96e0790de6fe43
BLAKE2b-256 f6e91ebb200bad17e3f43d5d941a446112e9b458d4167375cb9a6fa314130bbb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.5-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f9930a935cd07f79b512e2ce13fcaf57aeb78a9dc091f3f1b9afb3939053e267
MD5 19c6ba479d805180814eaa511308c27b
BLAKE2b-256 0b7e6217734a73322bc16385d2ac00b63da3837045cfc8906e0af812e938587e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.5-cp312-abi3-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 75954119d70365dec06145e9571e7e4eec6228f86cc8e778dc0631f613e975b2
MD5 d9884a984ad243dcc234d33871203a96
BLAKE2b-256 6a25466f3c0299d0a1eaa81b9789e722ce0e54eff2e683bed6311f3d1a33bd10

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.0.5-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 9.9 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for fcpw-1.0.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 0324986543056b65340e924a6e1e9b432f73813c1d4ed20b57de550145cfc0a0
MD5 b9894065df6e5e455918c9026bbeca08
BLAKE2b-256 618ef57d7792e2e2c883afb9e730eba2f4f77eb731d98232bbc6ce580a70441c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.5-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5716484f304aeed4449e7724112d9140f4525b2ed61d5f07cbb67751a3681ae7
MD5 e44d192db94f603e39c5003eeba5ed44
BLAKE2b-256 50886386614a764b98343c9aaa075e969b3a8f45c59a5e4777f3fd0bdd3caad3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b5e542d7fb2094e105fea3b7b82be451068d523633d24b61d4c775fcabb4961c
MD5 f67073ae06a24ddfb8be8123616c5a70
BLAKE2b-256 aa35609b95cc2ebc02bf238e506c018c6d9689af008a01fb6593a9f50906dff8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.5-cp311-cp311-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 8041dc08408e4230f420b84b6ef44ddaff2bc4b1ea6f6c63c6026bbb5b6e2570
MD5 d4008d0e735afdf7431c4270e9fc1675
BLAKE2b-256 305b866036d51ed3f1c7771563d6ff7643338cba2b52d72a2e70d71ed4c31e56

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.0.5-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 9.9 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for fcpw-1.0.5-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 5e43e731ce1d26db24b663a54e5f2c5d23c9748b3375e031187e7883caf391b0
MD5 595a6ff28f384adc1a1a7e59b2c44da0
BLAKE2b-256 0089999cb7364c448e803d4f7fe9d92e88b40d4dbc0d5da0b8ff5f12bad61de0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.5-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3742a1da01c3ad93ab469f04a5814c99c61f04db2ce125a706ebb45070ee719c
MD5 06deee0ac16be6064087877be1648a91
BLAKE2b-256 e3d700c2b4e41f533619b29ac8a5b66d2186d1ec2b0bfa3a8203d4f5145415bd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b5fd3e80d3292198c4cf1af6a985faa80973186971459c5a7ead59d496cac109
MD5 b969405343d4061bfe20b6af26e6ebf1
BLAKE2b-256 e150bc84bea5c21aeb20361e405a74bcae6faf61e8afd7a566b2985c76040926

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.5-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 a7a8df0feaa1091127a8611e7fba8e227142dc80eb055c17ea0dfa2c2376c8d8
MD5 31b3773560d1b0e42c71a8916d5d40fc
BLAKE2b-256 9549c299d455bac954e3350f2f149c48ef0ac250f6ba5b5088a07ada8865b200

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.0.5-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 9.9 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for fcpw-1.0.5-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 b7a2f00305fda0656b23d900ac74d89d25f39cb3446364f2e7c6d1950f5d5f08
MD5 9ce2d1b84ac65852ff84e0b271b250a7
BLAKE2b-256 5c9e3b1ad337800bb8676e91bb311116f50f1d31bbeb11230dd5a5ab747fd242

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.5-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9549a8a28d74c93a5a6a516c5764b8ea86441ea4f2327779525aecff9870b560
MD5 e44a365bf229ff305e0e552ae06c2f98
BLAKE2b-256 ff56d4006627f192b3720bac3510324d9a7217ae5d0e7a9205c1abb57e424221

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.5-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 849ed09597cbce7aca2390faddf176c99a8b265857ae1f3e3adf26c850806fca
MD5 fb2d600cb7b66f4c1caabd1e45253d33
BLAKE2b-256 9e3ebef44f4d951566d3830b01556d9bb7b92ee416de38a11ef42885a2ab5227

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.5-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 2c0937faa02a8b0e1bfe8a0288c89203770d47147357ea48ee1740d9869414e0
MD5 d1855999ffa6473bac9c999600a89634
BLAKE2b-256 274801c9e03973cc77578344678b891684ff9eb10ccef7dc524f39cd456cb50b

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