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

Uploaded CPython 3.12+Windows x86-64

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

Uploaded CPython 3.12+macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.15+ x86-64

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

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

Uploaded CPython 3.10macOS 10.15+ x86-64

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

Uploaded CPython 3.9Windows x86-64

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

Uploaded CPython 3.9macOS 11.0+ ARM64

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

File metadata

  • Download URL: fcpw-1.1.5-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.5-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 5ef6d2fffb8491de11159c90f2d8e6833aaf80b3a697771d51fa187660129eb2
MD5 f0caa768d02048bf0f9a2bcf537fa3a5
BLAKE2b-256 5b48917634469943e72f59fbd682dd521d6d901507f8418d1bbb5645d4c0bc47

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.5-cp312-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0e00a02ae6c262f85f7dba13e91334c9902be22349411e9b608fe698add0d279
MD5 a32969e503d50658694119123c524378
BLAKE2b-256 29bbe9416a6fa28c50873bf23220d4c85fa4bf78ff5bcc466b5b9c3a50860fd2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.1.5-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.5-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3a2bd3f8107713a790530b8f3c6812bd28f47ee64b120bae44e7786a51975dcc
MD5 574256012db4f37731f883a578626003
BLAKE2b-256 f2e821f4b29ec015b38110aae83ec38e09a2ea143f5ec6ae98a761f76e1a3ca4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.5-cp312-abi3-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 bde991155204f6392e5975fb9b4dbbaf96bf9c06067739473f28de87fa7fc806
MD5 4df97d5ae230daf433ac6d2e83fe50a9
BLAKE2b-256 bc874a33240bae1f62d5d5db7baaefeee30aae6a17b31972f099e4f17d0a2ba0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.1.5-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.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 1a2a308aac2089c6c80c36efc3be7cb9f871a2b432bdea87a0882008f61f1266
MD5 95b7598addfd93edacf5dad128f71ae2
BLAKE2b-256 78b4e6fb4bcca053b6d33aaa4cb1f53758892b6bd9e1b3b6f1d082e585d03cfd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.5-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d97d199b80a490822b7b12599b2597b29379249fef0840bffd1453ef248e0478
MD5 b0c06a67d1af5eb3fd3458ce2cc5f8e3
BLAKE2b-256 feb7e10080dd5bd2535f8b9735e141982cd34d673ce2701b94741dac134ee9ba

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ca7c04fd2ee84d29825d1f345367c2141d21e4a2b7f8ee48771662371a636522
MD5 e7a61a2cfe330493f4ee227bb7925663
BLAKE2b-256 829d7fdb3e5877dfe5837ddf81637ee42be669cabfa71403fc4061168216f0cc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.5-cp311-cp311-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 9a97b9a64e31b93c3ac99a9ec52c69a94e0f4bc1bbdacd3fe06bdc773067ed38
MD5 ed88c4da705ff7e563e22e67251eb260
BLAKE2b-256 dbc53ec8ede0ffcdabe207c4a461b83801a53c5acfbdcc93e23a36ef1c35a513

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.1.5-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.5-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 fe4e6ff091613809c3ae623e54d7371946cea221fb536868f4885068bd25e7e3
MD5 80ab1f44fc99df2599a89cf587a0db4d
BLAKE2b-256 825d0d67cfb0a8aeac633e9013aaf7d53f7228d737993d29a7081ba1bc7864b3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.5-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 238d9cd0245e1b8c647503b26cb8c79e812f83fc240f79b4d89ed82d95bb6b48
MD5 18588a86ed8e19bb9b6185bda80965c9
BLAKE2b-256 f7b42160d36652bd4f3f87d72db462f3d72df5d1c760f1625551b3f4ad760ad8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 51b40222accb1e96d77c879af87822318aca68cc416f3c1e785c11922d6f52ca
MD5 79233e3ea4316898bb22c3e342e2d425
BLAKE2b-256 2879fecb27706a320a679d6080cf3a4cb7ea4171498ed9a01c42e5c2863713b2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.5-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 46138adb7e0da2f254c54ece65f7fc3df633c8c5b312649c6e4a991c46b8589b
MD5 daf1ee1dd7537773c604a0f4d9c4d79b
BLAKE2b-256 f499c3886b0b59b244d3295571a49c26ad3df18efa6a17d78c4f40dc545e95e0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.1.5-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.5-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 791b45050383658633e6dfaad335cee2ca2bf757920adb4f54300d667ed255b1
MD5 64131d1c10d6319040eaa30f56b8f62c
BLAKE2b-256 063b7aa33b373c1b8d4f845b5a03c375b3c0a0362ec3f5d303201dc97347148f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.5-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1e270c4688d96a1631a8444273826b5a94405031f066561404c8edf3607af8e8
MD5 4ee479b5b70a65ec11c0969d22df557a
BLAKE2b-256 4bba3d1304ca75243ff2a6b8f0c418c3798d8f740aa1d0aec7bbd3ef1913a2ec

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.1.5-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.5-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cfeb67a2a14693fd294d5bfb7e4502ce29e247e2dbed04cb34a4aa7022f46a99
MD5 6b2ed3b66b0b818b4585816cd4e4e460
BLAKE2b-256 0980085364214dac186b2562a84f9e328dec0ec7b053de5f2f322e0921aaccde

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.5-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 a4b769f6dc9eb9fb3811e53a3fc1eb0b1f2cbdcc7da900b083eb621d29adefeb
MD5 8194319eb3a44a9b0f1b8ad0f4de8e19
BLAKE2b-256 456ca5cc60380d788704d12f1ac6d887c74ee9294f2745e518cfc57aea273b2f

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