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

Uploaded CPython 3.12+ Windows x86-64

fcpw-1.0.8-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.8-cp312-abi3-macosx_11_0_arm64.whl (298.3 kB view details)

Uploaded CPython 3.12+ macOS 11.0+ ARM64

fcpw-1.0.8-cp312-abi3-macosx_10_15_x86_64.whl (336.1 kB view details)

Uploaded CPython 3.12+ macOS 10.15+ x86-64

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

Uploaded CPython 3.11 Windows x86-64

fcpw-1.0.8-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.8-cp311-cp311-macosx_11_0_arm64.whl (304.3 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

fcpw-1.0.8-cp311-cp311-macosx_10_15_x86_64.whl (341.1 kB view details)

Uploaded CPython 3.11 macOS 10.15+ x86-64

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

Uploaded CPython 3.10 Windows x86-64

fcpw-1.0.8-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.8-cp310-cp310-macosx_11_0_arm64.whl (304.0 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

fcpw-1.0.8-cp310-cp310-macosx_10_15_x86_64.whl (340.7 kB view details)

Uploaded CPython 3.10 macOS 10.15+ x86-64

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

Uploaded CPython 3.9 Windows x86-64

fcpw-1.0.8-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.8-cp39-cp39-macosx_11_0_arm64.whl (304.1 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

fcpw-1.0.8-cp39-cp39-macosx_10_15_x86_64.whl (341.0 kB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

File details

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

File metadata

  • Download URL: fcpw-1.0.8-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.8-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 a48c3da115bdab73b97f4e86433c62895ff572710adfb0cac3f85f5dd5a2fb34
MD5 1c7dabb3e628b505ec3db8d6b4403d5d
BLAKE2b-256 3416ed54fd1060d9c519b6392762873e4b22586a0d2b77dc5bb1aa781a4b6761

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.8-cp312-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 80ecbbb5e4c8abd567e756bc7173edcbd31ab728614236f749f373788dce567f
MD5 5c8872237338d7522a4df1f227a84341
BLAKE2b-256 c51962b1e55e7a8cfbc7b57d33dcaecd47853cf1c1c395764dd922160e4d01d5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.8-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e515fb6e3166b4f1e4ec36d9852a578bb610edb1a0685e249314ed0826d68c14
MD5 dd541ce02ac6e03fa1ba66af430139b2
BLAKE2b-256 363963f92d7a3ac9ebb3e3c38091b4030566da62a317dd532922b1fa0d8b87a5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.8-cp312-abi3-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 c5dd8e2c66d0e564dcf3976646f4c0784956b5c18b6cd99d8b881cc26edf4e5c
MD5 f361d5c583b2eb6e3fcd518c63c36655
BLAKE2b-256 88fa9616c60e428f16d5ac89ab90a8b2d151f0ce7c0521c23e5a8adf799ccf6a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.0.8-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.8-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f1fed7e0fc5b80ddad8f120e47794f54b7f99daf0d284ab379d08507c36c0667
MD5 1fafddc30249adcb34e02423a966bacb
BLAKE2b-256 26f29e14d0104c08ea933207ef747da8a2ac65f64b8ef65b12a4b4df387000ff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.8-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 506d826df31e8cb77900c3a9b67d22dc2c484a44e38b1af2976a4cd39e3af6eb
MD5 ed0c58bea5e18169b5d798ffb3d0b663
BLAKE2b-256 c160baac68a51babf3f39dd05bae42812b91ea646ab154132d202f588cd23a49

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.8-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b8ef12662cea78b6db53d844994f24e07fc44ae66979fa289813f508ec7878f5
MD5 3bcc0076bda96bdfa2e4be61fdbaec65
BLAKE2b-256 b97bebe8e4348ee979a470cc8ac64ee653c80aeee481a01c45a606c71d02a9be

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.8-cp311-cp311-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 fec390badfef3f10474d29012c4ef0de85827518ec3a17f7465fdda0cde52b29
MD5 16171c9e793b553b9f7a6eb0760bc1ab
BLAKE2b-256 37d2f53ae0566c732b51f2cc6df4fb640154b7b13c568870c0fb61d20fe4d15a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.0.8-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.8-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d1fcd6652895435c7cae30150f9d3bca9d683969ebef6dcf5d3682088e42ba7f
MD5 fd97e5a9e3335f898732b7ae6c7fe7b0
BLAKE2b-256 e754f8dc938145491b4d51ae99193d56af191d875cf9d07d188fc5a53a519ee2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.8-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6946b08b91d43af8f10d4ab896f622dc55786455c425f4c2aecf9ded67312b30
MD5 0a5787bc4071ad7cb787459b51f93f42
BLAKE2b-256 2ce19fd121c885749a2c03159aa3643268fbd0fdcb33652060ce6750f37a1e34

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.8-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c6a8b740fb65c82bf0762e3a707e4738a9596febd73ddffbc3ec0bdc5bf3326a
MD5 7c5bcc8974b65ccfef796e3ff0b71606
BLAKE2b-256 d3999251c1c90d9c358e772ca56c52f5c0955c9e93d610f67e061d0a5aa71880

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.8-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 b75b16cdff1b190a15a2183deec14d2d213787de0d6ee8ecc0aacd743a6c2c02
MD5 4d570421d64e8df5d7828e03148b9c11
BLAKE2b-256 47123a8ec69cad9d0609982fad30a3f6445ddd972b1f6df0282a7246335aaaae

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.0.8-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.8-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 1d5c199cd5de3539fa9e3bdf5a9b9294f217a43dfc76fa8c8ff9716a982b3414
MD5 100049b5acfadf569246a8325a14a70a
BLAKE2b-256 2ab9ccaba1561e7281eea2c66577405df8f16d189926072972a0932c7f02ff31

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.8-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2c0e04ed8135ba5643d408beddb3ad96ab3c58297a8bc9da44986cf7437ceffe
MD5 78dc9a0208b31837ef192dae74765dc5
BLAKE2b-256 af6132c238d061ce720d50f849cadd881f4b2bde917a11de73a0d6658beb1870

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.8-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 714cd3ac1afedacd62452dd79367a83983d68e5b1d9b0606e025e787fb6967b2
MD5 ad379d2080476ffcc6fb7c150a2aa8f1
BLAKE2b-256 7378e953b72e5683bbae1221044eaf14c98413cad6d61e5adc14ac5856a1cffa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.0.8-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 9eab7a1bb02f1002f8a5c9f8a953ec3d4915fd86ba19e063f2097e98f9acc808
MD5 93737d6135f10240087dcae6baeece9f
BLAKE2b-256 f5f240f0a0a0693909bf4b0002ce65ff790984e5b2e4597a1b044ac4ad162d52

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