tataratat / splinepy

Library for prototyping spline geometries of arbitrary dimensions and degrees, and IGA
https://tataratat.github.io/splinepy
Other
47 stars 13 forks source link

add fitting feature in python #320

Closed FSchwar closed 8 months ago

FSchwar commented 10 months ago

Overview

Implement fitting feature in python.

Automatically interpolates (n_cps = n_queries) or approximates (n_cps < n_queries) depending on the given parameters. If input is unambiguous (e.g. given target spline and given knot vector), parameters are prioritised as follows: target spline > knot_vector and degree > n_control_points

If too few parameters are given (e.g. only knot vector/degree): assumes interpolation (n_control_points = n_points) and calculates respective missing parameter (e.g. degree/knot vector)

Results are equal to C++ implementation of interpolation/approximation as shown below (upper row: C++ implementation, lower row: python implementation) curve fit: Clipboard - 20  Dezember 2023 11 07 surface fit: image

Addressed issues

Showcase

A short / one-liner example to highlight the (new) feature

import splinepy

fitted_spline_curve, residual_curve = splinepy.helpme.fit.fit_curve(points=target_points, degree=degree, n_control_points=n_cps)

fitted_spline_surface, residual_surface = splinepy.helpme.fit.fit_surface(points=target_points, size=[size_u, size_v], degrees=[degree_u, degree_v], n_control_points=[n_cps_u, n_cps_v])

1 remaining issue: Tests complete but example file "fitting.py" result is different (as shown below). The maximum errors during least square solving are in the magnitude of 1e-3, therefore it seems strange that the maximum error in the example file is that high. I couldn't find any bug in the code.

image

Checklists

j042 commented 9 months ago

Can you remove draft flag when it's ready?

j042 commented 9 months ago

also, I guess we don't need _fitting_queries as BSpline's member anymore. Just a note for next PR, as it also require some changes in visualize.py

jzwar commented 9 months ago

Just a couple of suggestions for the parameterisation. I have yet to check the rest of the code, but I thought, maybe this could be a more general approach