Skip to main content

A Python tool for 3D adaptive binary space partitioning and beyond

Project description


License: MIT PyPI version Build status

Introduction

abspy is a Python tool for 3D adaptive binary space partitioning and beyond: an ambient 3D space is adaptively partitioned to form a linear cell complex with pre-detected planar primitives in a point cloud, where an adjacency graph is dynamically obtained. The tool is implemented to support compact surface reconstruction initially, but can be extrapolated to other applications as well.

Key features

  • Manipulation of planar primitives detected from point clouds
  • Linear cell complex creation with adaptive binary space partitioning (a-BSP)
  • Dynamic BSP-tree (NetworkX graph) updated locally upon insertion of primitives
  • Support of polygonal surface reconstruction from graph cuts
  • Compatible data structure with Easy3D on point clouds, primitives, cell complexes and surfaces
  • Robust Boolean spatial operations underpinned by the rational ring from SageMath's exact kernel

Installation

Install requirements

All dependencies except for SageMath can be easily installed with PyPI:

git clone https://github.com/chenzhaiyu/abspy && cd abspy
pip install -r requirements.txt

Optionally, install trimesh and pyglet for benchmarking and visualisation, respectively:

pip install trimesh pyglet

Install SageMath

For Linux and macOS users, the easiest is to install from conda-forge:

conda config --add channels conda-forge
conda install sage

Alternatively, you can use mamba for faster parsing and package installation:

conda config --add channels conda-forge
conda install mamba
mamba install sage

For Windows users, you may have to build SageMath from source or install all other dependencies into a pre-built SageMath environment.

Install abspy

abspy itself can be found and easily installed via PyPI:

pip install abspy

Quick start

Here is an example of loading a point cloud in VertexGroup (.vg), partitioning the ambient space into candidate convexes, creating the adjacency graph, and extracting the outer surface of the object.

import numpy as np
from abspy import VertexGroup, AdjacencyGraph, CellComplex

# load a point cloud in VertexGroup 
vertex_group = VertexGroup(filepath='points.vg')

# normalise the point cloud
vertex_group.normalise_to_centroid_and_scale()

# additional planes to append (e.g., the bounding planes)
additional_planes = [[0, 0, 1, -bounds[:, 0, 2].min()]]

# initialise CellComplex from planar primitives
cell_complex = CellComplex(vertex_group.planes, vertex_group.bounds, vertex_group.points_grouped, build_graph=True, additional_planes=additional_planes)

# refine planar primitives
cell_complex.refine_planes()

# prioritise certain planes (e.g., vertical ones)
cell_complex.prioritise_planes(prioritise_verticals=True)

# construct CellComplex 
cell_complex.construct()

# print info on the cell complex
cell_complex.print_info()

# visualise the cell complex (only if trimesh installation is found)
cell_complex.visualise()

# build adjacency graph of the cell complex
adjacency_graph = AdjacencyGraph(cell_complex.graph)

# apply weights (e.g., SDF values provided by neural network prediction)
sdf_values = np.load(dir_tests / 'test_data' / 'test_sdf.npy')
volumes = cell_complex.volumes(multiplier=10e5)
weights_dict = adjacency_graph.to_dict(sigmoid(sdf_values * volumes))

# assign weights to n-links and st-links to the graph
adjacency_graph.assign_weights_to_n_links(cell_complex.cells, attribute='area_overlap', factor=0.001, cache_interfaces=True)
adjacency_graph.assign_weights_to_st_links(weights_dict)

# perform graph-cut to extract surface
_, _ = adjacency_graph.cut()

# save surface model to an OBJ file
adjacency_graph.save_surface_obj('surface.obj', engine='rendering')

Usage can be found at API reference. For the data structure of a .vg/.bvg file, please refer to VertexGroup.

Misc

  • Why adaptive?

To avoid redundant partitioning, the adaptive strategy only allows intersecting spatially correlated primitives. This spatial correlation is described by intersection tests between the axis-aligned bounding box (AABB) of a primitive and the cells in the leaf nodes of the BSP tree.

partition

Adaptive space partitioning can significantly reduce computations for cell complex creation, compared to an exhaustive partitioning strategy. The excessive number of cells from the latter not only hinders computation but also inclines to defective surfaces (if any) on subtle structures where inaccurate labels are more likely to be assigned.

adaptive

Run the benchmark on the number of candidate cells and runtime among adaptive partitioning, exhaustive partitioning, and SageMath's hyperplane arrangements (provided by SageMath natively) with misc/benchmark.py:

python misc/benchmark.py
  • How can abspy be used for surface reconstruction?

With the cell complex constructed and its adjacency maintained, surface reconstruction can be addressed by solving a binary labelling problem that classifies each cell as being inside or outside the object. The surface, therefore, exists in between adjacent cells where one is inside and the other is outside --- exactly where the graph cut is performed. Points2Poly wraps abspy for building surface reconstruction. For more information on this Markov random field formulation, you may refer to this paper.

adaptive

License

MIT

Citation

If you use abspy in a scientific work, please consider citing it:

@article{chen2021reconstructing,
  title={Reconstructing Compact Building Models from Point Clouds Using Deep Implicit Fields},
  author={Chen, Zhaiyu and Khademi, Seyran and Ledoux, Hugo and Nan, Liangliang},
  journal={arXiv preprint arXiv:2112.13142},
  year={2021}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

abspy-0.1.3.tar.gz (24.3 kB view details)

Uploaded Source

Built Distribution

abspy-0.1.3-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

Details for the file abspy-0.1.3.tar.gz.

File metadata

  • Download URL: abspy-0.1.3.tar.gz
  • Upload date:
  • Size: 24.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.58.0 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.12

File hashes

Hashes for abspy-0.1.3.tar.gz
Algorithm Hash digest
SHA256 7927443f2c419a00d04ce226f320ccefd9feddcbdc6bfcd05a218e9d91564227
MD5 553f32ac5ddf61cedef0d8f785e13391
BLAKE2b-256 b663b6a04f6f3706bac57fbf608deacbb5f0180f7081dfba26536f96f4a82e29

See more details on using hashes here.

File details

Details for the file abspy-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: abspy-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 21.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.58.0 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.12

File hashes

Hashes for abspy-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 84360a349d8415e8045bf391ca17d0ccdf99cb5f11affe9949125731dea5600b
MD5 ed4baf1d88a12bfd0c606e8df32b816d
BLAKE2b-256 2e503378ffa99b9b612f39ed537f5b73fa7764ec730d6b115a57bbabe459bc61

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