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:

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]

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

Uploaded CPython 3.12+ Windows x86-64

fcpw-1.0.6-cp312-abi3-manylinux_2_28_x86_64.whl (25.7 MB view details)

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

fcpw-1.0.6-cp312-abi3-macosx_11_0_arm64.whl (297.9 kB view details)

Uploaded CPython 3.12+ macOS 11.0+ ARM64

fcpw-1.0.6-cp312-abi3-macosx_10_15_x86_64.whl (335.5 kB view details)

Uploaded CPython 3.12+ macOS 10.15+ x86-64

fcpw-1.0.6-cp311-cp311-win_amd64.whl (10.1 MB view details)

Uploaded CPython 3.11 Windows x86-64

fcpw-1.0.6-cp311-cp311-manylinux_2_28_x86_64.whl (25.7 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.28+ x86-64

fcpw-1.0.6-cp311-cp311-macosx_11_0_arm64.whl (303.8 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

fcpw-1.0.6-cp311-cp311-macosx_10_15_x86_64.whl (340.6 kB view details)

Uploaded CPython 3.11 macOS 10.15+ x86-64

fcpw-1.0.6-cp310-cp310-win_amd64.whl (10.1 MB view details)

Uploaded CPython 3.10 Windows x86-64

fcpw-1.0.6-cp310-cp310-manylinux_2_28_x86_64.whl (25.7 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.28+ x86-64

fcpw-1.0.6-cp310-cp310-macosx_11_0_arm64.whl (303.5 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

fcpw-1.0.6-cp310-cp310-macosx_10_15_x86_64.whl (340.2 kB view details)

Uploaded CPython 3.10 macOS 10.15+ x86-64

fcpw-1.0.6-cp39-cp39-win_amd64.whl (10.1 MB view details)

Uploaded CPython 3.9 Windows x86-64

fcpw-1.0.6-cp39-cp39-manylinux_2_28_x86_64.whl (25.7 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.28+ x86-64

fcpw-1.0.6-cp39-cp39-macosx_11_0_arm64.whl (303.7 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

fcpw-1.0.6-cp39-cp39-macosx_10_15_x86_64.whl (340.5 kB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

File details

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

File metadata

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

File hashes

Hashes for fcpw-1.0.6-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 8462026e410206168d27a8f78cab60012f0bc292f5f775229187a33267820573
MD5 907bc88f334cf2ae30e13fe33ae0c597
BLAKE2b-256 efb4d19fab8eb2d264af2811fadc747268d015f3fbfa1088bc6e85208df87dea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.6-cp312-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f317a8ae3405a7e07991cb9a80810ae58db76b735d5bb435e79007806328f060
MD5 4a4ad0fec06e95b6300d97142bd6c9a3
BLAKE2b-256 0aba002bad17a7acab44ce7f7889416c70ab876aa3aecd52873205f00fc339af

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.6-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a89fdb915daffa49fcd764c3b36000de75bd105ad527635d976e23456e39534c
MD5 a71cb851f58c18812a3f0dba6f4c31ff
BLAKE2b-256 cd9c770cf17adb5ab400f4d36ecf600407a45c86c5260b1e31067a899c216751

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.6-cp312-abi3-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 743b7a9beb7635a948b6a12e3fcbcfbf9e1fc7855a60d182c0a36f9cc5332718
MD5 ab8d00cda7a346157b2a191964eef6b5
BLAKE2b-256 8f0480f2119c6bbf9da98063ecf0f66d75f5acff39782164b168f591324c140a

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for fcpw-1.0.6-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 d30ba304a718afa725d6c924e23e974c287baac99514c0ab4d82a88485df98a3
MD5 a69332ad23483771f5e1cd15fc289112
BLAKE2b-256 65a90533730a7bf691e20d684b21ff193ce44114c298fdda98fc14b71c66bedd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.6-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ae9ef08283918f9aa9d7d72f021360c533e589f9c269bb3eb7e09f37e8533432
MD5 b9c0e49d35ff1681d72118a324ed095a
BLAKE2b-256 cc377f87e18f62499dc350ac1c587139f2e4a046750e5611dbbda0ee9cf171c9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.6-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 03c9ed62022485a7b01bbd41d2c4d16af4e1da1a1be2d53a1bcbcf5c1cbb6f89
MD5 b2f317e9b870f298907f8ced993e8105
BLAKE2b-256 04a16ad6f70144cfbf4e543f43babc5c44b46ba4b755149b5ef6fe6c8b0e2b99

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.6-cp311-cp311-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 d8e45643ddde2b808b7baa5f36ffe4c31efe097ae3d503b57ca22c64a3625c6f
MD5 9f8db03658e2869172c0923db9b985c0
BLAKE2b-256 63018a894e4eb198faa3d4d29ba780fb06598b05c885c32e0b4ec18c4304eab5

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for fcpw-1.0.6-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 062880ba7272772b9cfc576b82383fe7bfdae72f1e136df32dbd222cc52c738e
MD5 c3d8c094c70c1a7d645001a819aa895b
BLAKE2b-256 316cd309379cf812cc884d881ae2d1711efecf97d81d33536edb20632a4d6824

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.6-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6564e0163639c77b17e733ec782880a10b64fcb01ad99bda69faa63a1e204095
MD5 6b4c904f0b5553ce1f821e01cb316fad
BLAKE2b-256 c3e308dd4a4697e7bbb82aabee00045de7b7af319fc870ee85afc9311cabdf4a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.6-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7c26d052aae7d198afd6a040a07d658ccb559cbc65f1edb45debb2659c1df64c
MD5 c5fdafd02a72683d470ae935705e7425
BLAKE2b-256 81d2f8f7be4addcf49ff4f49164e65613b33dce9815275ff68dfb73336811cfd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.6-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 30ac19c6b3fd4543afdfec58ab4084746131c6c1b69f638835aecaca08043b11
MD5 e91fb5ead5990ad13d7bbb900f952fe6
BLAKE2b-256 4609e3b3eaa3ef94d5042f39800e8b43f6c9285ea6a6de8e837b346a7b49891f

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for fcpw-1.0.6-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 e46e1431b43a837b974a8e9e5dec9ffa00a51a2013d3fe40cb74768656cc406c
MD5 2f4dd90f15ebf09f2cd512e80f985848
BLAKE2b-256 4c68b0b7b8a7ffc86b86e83d362480621a32ae28d85820e7d4dc11c122446a33

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.6-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 600dfbcb5511f7e3a3ce8367c937dcf095ef8e6f9a6babf13e06c5d1effe2b52
MD5 ee96117f5176b6ff1fcc05b84f637bb4
BLAKE2b-256 659660422b6a32305d5cb5d537c37e5dd58a8a50acdb999f641f9da15b11224e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.6-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4fd9de6d0df190b9007144c9cf7fb26176ebd8cd0e578131db4b6b0ff183f45b
MD5 4d8f636f7fac48f63a75e7f1b6505f76
BLAKE2b-256 91f17b04088feb777e54348216782ddcbfd170f53b3de5d5d174f316abd63edb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.6-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 7c4de1ab9278f2cd74f677d83e484ad67f44d60362abb830ea4952332e1c9a67
MD5 daad1abba6170313d7ab3a281d9787c9
BLAKE2b-256 3a710e51e8b85660bf3ab254aa11f51f4554fa28a0ca2c81d449ee679f37eed1

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