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

Uploaded CPython 3.12+Windows x86-64

fcpw-1.1.4-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.4-cp312-abi3-macosx_11_0_arm64.whl (293.8 kB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

fcpw-1.1.4-cp312-abi3-macosx_10_15_x86_64.whl (329.2 kB view details)

Uploaded CPython 3.12+macOS 10.15+ x86-64

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

Uploaded CPython 3.11Windows x86-64

fcpw-1.1.4-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.4-cp311-cp311-macosx_11_0_arm64.whl (300.0 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

fcpw-1.1.4-cp311-cp311-macosx_10_15_x86_64.whl (334.1 kB view details)

Uploaded CPython 3.11macOS 10.15+ x86-64

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

Uploaded CPython 3.10Windows x86-64

fcpw-1.1.4-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.4-cp310-cp310-macosx_11_0_arm64.whl (299.3 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

fcpw-1.1.4-cp310-cp310-macosx_10_15_x86_64.whl (333.8 kB view details)

Uploaded CPython 3.10macOS 10.15+ x86-64

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

Uploaded CPython 3.9Windows x86-64

fcpw-1.1.4-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.4-cp39-cp39-macosx_11_0_arm64.whl (299.5 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

fcpw-1.1.4-cp39-cp39-macosx_10_15_x86_64.whl (333.9 kB view details)

Uploaded CPython 3.9macOS 10.15+ x86-64

File details

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

File metadata

  • Download URL: fcpw-1.1.4-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.4-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 6f5e1d04207aad86d0a5b84d64a9276152b532b45e01a133b30ced5dd3da4fc1
MD5 92d2cdf1c327dfad07add68817b8b353
BLAKE2b-256 d72f6f9e23d95c4d9843e46823627849285128feb4e04a5efe6b962d44ba24eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.4-cp312-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 558e9c3430a7fd9586430b436d8d9c5685c64984f45247d0b36f5373c0b13317
MD5 08c7d1b7f1980f1cf5ff73c82ee8109d
BLAKE2b-256 01b0e47e71158260037a05b682171214552aaebb791fcb9432063e9c55cd53fb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.1.4-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.4-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e7231ca5d917066d08466bf00bbf86684b9b842d7f437187e01c76cd9022cb8e
MD5 7f7c237d3671d515b9ca4ff2389037f3
BLAKE2b-256 044eca4bcb106488da4146da999bb5a8237ac393695a5eb08d1ab9687d7c7f7b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.4-cp312-abi3-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 60abc30fed3331809e80e55dd250b7b3184b544cd711731d51bbcbf9de6e9d8f
MD5 e5fa766128d98a23239c1522b169a1b4
BLAKE2b-256 820c497ca2301884fd4335ff4ef82f1996c71bb746f0ee94b711477030c5ec98

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.1.4-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.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 d130aeabd40209730c71f7fec1b89f2509d2cc4ac68a8ae1bd6c98c995212fcb
MD5 8afe9bd4a3f4b595ba2342011487a85e
BLAKE2b-256 12166d966acdc958d6599b2fbf54e8ee74b7b1517fefbd0c4030404308382c2c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.4-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 88f12991ba8a37d99bef1db6a245ff704a530730a406bf911a5e3b9accf149f0
MD5 8a991f36fbb2e34138519c0c7019256f
BLAKE2b-256 150b79dd0dd73538a03e4f1fcdb0690cf7bb18a600a34a60146cf898ea94c304

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3073a15473833096be9365d2bbf78345c6cedbdafbfe7f5c03c817cee217234d
MD5 8880164cb9df947b913a6834702bc4e2
BLAKE2b-256 59c9bbf3c54b981e92bd902d2d5b214f03a614f28603db8df08f3cadda3b563d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.4-cp311-cp311-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 cd322428cc16f11f3b8a30104a5c7854efd7de8e70f67ff7d3e6e27da981afca
MD5 3e01861d66b6f48b8e0463bee36e4882
BLAKE2b-256 2681ca3cc975a12deec1ee589391a49d6a0ba91308549cf550008eb3fa990b20

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.1.4-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.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 dece16b15ee127365368eab63ccad578c12d834d42827081ff494269980fc6d9
MD5 89430efb1f899a5fbd25a0f4490d4671
BLAKE2b-256 f984b6d1617b72cf2c98d3fc909415321c629df91ac6bf1ead2049d355ecd108

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.4-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 91b5cf169c9898256746f2211cfcb38ca7dc3439a212c294985cfb4115100d2d
MD5 2bc2a5e6416a37e9a932bd3a8f3e8fe9
BLAKE2b-256 f5e6def0b899fa6daeedd6d9491bb6fe209cdda1de5f143a651e1d09630c4822

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 65475fc21abe0af2c8cd29be578e971561a4397940f976792d0569bf10955f1e
MD5 63b839fb371b7fb419c9638ea30da211
BLAKE2b-256 63019f9dde2f49cb4339628234927c35af0516e4bc0c052eb8188c5bb1d91801

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.4-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 65c385c5513b30f839565ff28c487eb50459e685af11a3398538ebb842d30cc9
MD5 db93240dcc97569c2d43c30a1682b31d
BLAKE2b-256 535d71d2588b5bfbad0e75b67c23da45d477e013f0ea21943123745cc301ef84

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.1.4-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.4-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 3df54432c141724cba6ec03bea39082b303984dba1206fd031564565e2f17e1f
MD5 afbd84d6c09ac221c5ab5f26bb212f43
BLAKE2b-256 339b17ffce59b6aab547be50cdcd2e7c0b10f82fb90ac43f4118bcb1462ce96f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.4-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5b304ad3a278132c3f79700ad3dc7652020c659dfde653592b852329b97504ff
MD5 004871202969dcd03a17302c07f54d57
BLAKE2b-256 7eae9d439bc20213db165c3d9b9649b44526aca18556656c1525e31bfa654177

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fcpw-1.1.4-cp39-cp39-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 299.5 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.4-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3a39f4445ffa05bfa664682c7d963218f7fe2b1e8895d0f557e2b2300f29d19d
MD5 33a068bf89818d3a18d039975355370a
BLAKE2b-256 39d7b95092dff8ef40bcc2fa9289871924c679807dbbe5d30131719d383dede8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fcpw-1.1.4-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 1e938f42772c6529450f4ee2be1d75d85dc87db3cef33ab3ce96cdff108970d4
MD5 5a630804e921c9aba34863cad4212146
BLAKE2b-256 d7ea09ef4f543aa2bd3c929525e86dfad1b5b48cc10e271d5940b15fcb3a1a85

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