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

Uploaded CPython 3.12+Windows x86-64

fcpw-1.1.3-cp312-abi3-manylinux_2_28_x86_64.whl (25.5 MB view details)

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

fcpw-1.1.3-cp312-abi3-macosx_11_0_arm64.whl (293.8 kB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

fcpw-1.1.3-cp312-abi3-macosx_10_15_x86_64.whl (329.5 kB view details)

Uploaded CPython 3.12+macOS 10.15+ x86-64

fcpw-1.1.3-cp311-cp311-win_amd64.whl (14.1 MB view details)

Uploaded CPython 3.11Windows x86-64

fcpw-1.1.3-cp311-cp311-manylinux_2_28_x86_64.whl (25.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

fcpw-1.1.3-cp311-cp311-macosx_11_0_arm64.whl (300.0 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

fcpw-1.1.3-cp311-cp311-macosx_10_15_x86_64.whl (334.3 kB view details)

Uploaded CPython 3.11macOS 10.15+ x86-64

fcpw-1.1.3-cp310-cp310-win_amd64.whl (14.1 MB view details)

Uploaded CPython 3.10Windows x86-64

fcpw-1.1.3-cp310-cp310-manylinux_2_28_x86_64.whl (25.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

fcpw-1.1.3-cp310-cp310-macosx_11_0_arm64.whl (299.5 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

fcpw-1.1.3-cp310-cp310-macosx_10_15_x86_64.whl (334.0 kB view details)

Uploaded CPython 3.10macOS 10.15+ x86-64

fcpw-1.1.3-cp39-cp39-win_amd64.whl (14.1 MB view details)

Uploaded CPython 3.9Windows x86-64

fcpw-1.1.3-cp39-cp39-manylinux_2_28_x86_64.whl (25.5 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ x86-64

fcpw-1.1.3-cp39-cp39-macosx_11_0_arm64.whl (299.8 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

fcpw-1.1.3-cp39-cp39-macosx_10_15_x86_64.whl (334.2 kB view details)

Uploaded CPython 3.9macOS 10.15+ x86-64

File details

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

File metadata

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

File hashes

Hashes for fcpw-1.1.3-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 26a13bb39d2c1ba9d8a1f76c5163420ea54dcc34ff3af4ebb1a325b8d63ccb1e
MD5 1435af470b740095f3e0c2828ea6fb8b
BLAKE2b-256 b129c5bc1007b96afc4ef61e051c46f11b6e6c844a17e138308dfe461584bbe2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.3-cp312-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2afa98a2fe5d8cd7c23f4d5b4b0d791ca77c9ac9884d56665b48372233a6c87b
MD5 fcb04d19dfc81433bb2ec5e144bb7599
BLAKE2b-256 a04503f819e6eef7f8402b0347e630093038d2dc7609e9944f24882da7ab3e00

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.1.3-cp312-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 293.8 kB
  • Tags: CPython 3.12+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for fcpw-1.1.3-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 93c6d3f0e3f0232e52b96fcc6d61b5d23b6eb1bb0f104ca9faa69e283ff48c87
MD5 55a20218fa3831b4b5afafe3488f37ce
BLAKE2b-256 47f88506b0b3ed55c07d4b37aadc912cf09905b91eda3ec012bd83c993656d3c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.3-cp312-abi3-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 c1a0dded52bab5d9761e66417edb704248ac97837eada034a3ca0576fae0608c
MD5 45f974abedc58c5b3f926e0dc29f0d25
BLAKE2b-256 162dc67917a52a99985a9beaa6cbebda590e503a523fa937a2eef350c38746f5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.1.3-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 14.1 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for fcpw-1.1.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 a6a0777fefda4215889c0efc9c90800973f484324e363c2a065d7099456a468f
MD5 f0f0cbfbae5a77f00c063e0d8405a1b9
BLAKE2b-256 9378f60af1d2fa2f6cd6c00f43cd5bebced94725f2894bed25c3f2025fba2dd1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.3-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c2306997c1cfb2a619590667632de2aabcdbbc8be02c4ce10aec9073f06b0e98
MD5 1fc51c65ac739c14591c7c7fcee3a0ec
BLAKE2b-256 b806234bd57aacb2c4065108a0735bc6b0088b32f3ff271af59db7170d73b164

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f80542d27af65d44c0cb39e0619ac69fa70a2643cdd9f6f9a872ed5852c70454
MD5 1db3117e7b90555ea288792940c32434
BLAKE2b-256 5055e511878d9052d96cb3e536c35de3b124b055d120eb97b0c82469b6f33e35

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.3-cp311-cp311-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 c226ec148fe7386a03aee5cac2e3f8da963459bdb3edacacc195e1b83eb92652
MD5 7b6bd2ef83f097008be4756af959ba0a
BLAKE2b-256 54f3cab9f3f7ed665d067b4e49e85809b8c3ff169055886b0360fc2433a2b32b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.1.3-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 14.1 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for fcpw-1.1.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 c544093e4c9c539bfb93c3f22e6c97e61fac5aa1762188820b2d39e3c2a83c20
MD5 d98e3f5c4e95d8e32456d10de6099bf8
BLAKE2b-256 f78b288dec9834ecff70c7521685613179a810873b75638ed3842e223af3c4ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.3-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 89df7228c66d7bd7d5061f1c21dcf4b17e241e6ceef271d7b7efa02e7066b262
MD5 1f95ce79f8defbe0ebbf9253dbc9a926
BLAKE2b-256 b8f0df590691e45b097fe3eada6e63ff58d5e41b34f8fe0a25a94f9947904385

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 16ba5f6542d89c33a05ce6e88c802e0fa534801e2bffd9425c8a09c654f567d1
MD5 d196464a8a221fdc874858fc56854b86
BLAKE2b-256 72510ec5906e0b4532302501019ec6c491823dcace6915257ce7c454862f6f00

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.3-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 2f720a4e485bf89b8dfd8f69b2acb2acd0cd49fcfcf0c6dbd9777f76d6aa1f87
MD5 d017f4f52771db1d63760596c34a106d
BLAKE2b-256 8c6d2afb3feec7f344a696aa08c07afe8801746da259533dcb472a80a6a3ff64

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.1.3-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 14.1 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for fcpw-1.1.3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 0497e59e4cd918ba18b67e12181df2e855a079eb66ee74c7c5feee473d841306
MD5 ce6366f5a60070f4a5eab2c8e9205fc7
BLAKE2b-256 ea9472deb71a98fdcaa725ad689ba9dbfeeea775f50c69a179b1c5f0ce57de10

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.1.3-cp39-cp39-manylinux_2_28_x86_64.whl
  • Upload date:
  • Size: 25.5 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.8

File hashes

Hashes for fcpw-1.1.3-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 89d00f85e439455c3c9d616502c4aa9ef348760a29272f53c1e8a7a5277c548d
MD5 6a41a1e62e78504cf7294779b6f0892a
BLAKE2b-256 f85546aa433e6df2d7feeb9b72634cbdb6ee3e7ef446f547f408af6731207f93

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.1.3-cp39-cp39-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 299.8 kB
  • Tags: CPython 3.9, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for fcpw-1.1.3-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cfa97b12701740f6132e5a0cd779e79a20219d577ada1a1f56e3e918cade43d2
MD5 b470b47cc8c2000a26af5ddbbc88a5b5
BLAKE2b-256 24d6b4b701daf610945049d37474d7f28ac904b9f0968470ec2a2a0bb5bcfea3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.3-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 0f054280acb033ef8abf08d092cc337950a6001fe274d51954ea4419b7ed1759
MD5 4bdd4979b08b11fa09dce1ab72107ec6
BLAKE2b-256 922fe8089fb4b5f828a75eff35b0924a3c0ab147237b4fcb9a7a945ecd77d2a6

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