Properties

from geomdb import *
from geomdb.loc import BoundingBox, Plane
from geomdb.prop import Constant, ParsedExpression, PointCloudInterpolation
from geomdb.db import DataBase, plot
import numpy as np

# For visualization
from geomdb.utils import scene_to_notebook

# We can use GPU... but as the default jax is cpu-only, let's disable the "GPU not found" warning for now.
import jax

jax.config.update("jax_platform_name", "cpu")

Create a voxelation

voxel = voxel_from_stl("data/stanford-bunny.stl", 2)
lower_left_corner, upper_right_corner = voxel.bounds
bb1 = BoundingBox(lower_left=lower_left_corner, upper_right=[31, 3, 49])
bb2 = BoundingBox(lower_left=[35, 5, 52], upper_right=upper_right_corner)
pln = Plane([30, 0, 0], [0.6, -0.8, 0], tol=0.5)

By default a property is defined everywhere with no dependent relations

a = Constant("a", 1.3)
b = ParsedExpression("b", "3*a+d")

pntcld = np.load("data/stanford-bunny-pc.npy")
c = PointCloudInterpolation(
    "c", pntcld[:, :3], pntcld[:, 3], interp_options={"method": "nearest"}
)

A property can be restricted to a location using .at()

d1 = Constant("d", 2.6).at(bb1)
d2 = Constant("d", 5.5).at(bb2)
e = Constant("e", -7.7).at(pln)

A relation can be defined using .where()

f = ParsedExpression("f", "d-9").where("b<9")
g = ParsedExpression("g", "c-a").at(~pln).where("d<5")

Properties are only evaluated at query time

db = DataBase(voxel)
db.add_properties([a, b, c, d1, d2, e, f, g])
db.query(["a", "b", "f"]).to_dataframe()
index (a, 0) (d, 0) (b, 0) (f, 0) (index, x) (index, y) (index, z) (coord, x) (coord, y) (coord, z)
0 5794 1.3 2.6 6.5 -6.4 2 15 19 -20.0 -12.0 44.0
1 5795 1.3 2.6 6.5 -6.4 2 15 20 -20.0 -12.0 46.0
2 5796 1.3 2.6 6.5 -6.4 2 15 21 -20.0 -12.0 48.0
3 5848 1.3 2.6 6.5 -6.4 2 16 18 -20.0 -10.0 42.0
4 5849 1.3 2.6 6.5 -6.4 2 16 19 -20.0 -10.0 44.0
... ... ... ... ... ... ... ... ... ... ... ...
7458 68052 1.3 2.6 6.5 -6.4 27 22 17 30.0 2.0 40.0
7459 68053 1.3 2.6 6.5 -6.4 27 22 18 30.0 2.0 42.0
7460 68054 1.3 2.6 6.5 -6.4 27 22 19 30.0 2.0 44.0
7461 68055 1.3 2.6 6.5 -6.4 27 22 20 30.0 2.0 46.0
7462 68056 1.3 2.6 6.5 -6.4 27 22 21 30.0 2.0 48.0

7463 rows × 11 columns

Queries can be visualized

res = db.query(["g"])
scene_to_notebook(plot(res, "g"))