In multibezier.py, an algorithm (adaptive_fit
) is proposed to encode a (possibly multi-dimensional) function as a superposition of local Bernstein polynomials (which form the basis of Bézier curves) of increasingly higher resolution with recursive subdivision of the sample space.
This repository also includes demo_SDF01.py to generate signed distance functions (used here as test signals), and vis_sdf.py to visualize 3D SDFs, along with examples SDFs in .npy
files.
Psi, weights = adaptive_fit(x, in_shape, nbOut, nbFct, iterations=1, threshold=0.0, C1=True)
where
-
x
is an array that contains the signal to fit -
in_shape
is a tuple that contains the input dimensions -
nbOut
is the number of output dimensions -
nbFct
specifies the degree + 1 of the polynomials used for the encoding (4 for cubic, 3 for quadratic) -
iterations
is the maximum number of recursive subdivisions to perform -
threshold
is the maximum root mean square error to allow in a subdivision -
C1
: if true, the reconstruction will be$C^1$ continuous. If false, it will be at least$C^0$ continuous
Tests using signed distance functions (SDFs) can be found at the bottom of multibezier.py as usage examples. These can be run with
python multibezier.py
assuming NumPy and matplotlib are installed.
A dictionary of low resolution basis polynomials
with
Then, at each iteration and for each subdivision, the residual error is evaluated:
If the mean square error of the flattened region is bigger than some threshold, then the basis is extended to add more details in this region, i.e. the
The data structure resulting from the recursive subdivision is a binary tree in the case of a one-dimensional signal, a quadtree for a function with two input variables and an octree in the three variables case.
To preserve
- Not guaranteed to work for splines of higher order (only tested for quadratic and cubic)
- Computational complexity grows quickly in the multi-dimensional case