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

SVG Export #297

Closed jzwar closed 8 months ago

jzwar commented 11 months ago

For sick graphics in publications

Are you tired of png exports in 500MP just to satisfy your eyes? Be afraid no longer, as this PR finally provides vector graphics for 2D geometries.

Addressed issues

Showcase

import splinepy as sp
spline = sp.Bezier(
    degrees=[2], control_points=[[0.2, 0.9], [0.8, 0.7], [0.8, 0.2]]
).bspline
spline.insert_knots(0, [0.4])
spline.show_options["c"] = "k"
sp.io.svg.export("test.svg", spline)

Output

test

THIS PR IS BLOCKED BY FITTING PR #320

Checklists

jzwar commented 11 months ago

@j042 There are some points I would like to discuss with you before I continue...

jzwar commented 8 months ago

Testing script:

import splinepy as spp
import numpy as np

box = spp.helpme.create.box(10, 5).bspline
box.elevate_degrees([0, 1])
box.insert_knots(0, [0.5])

# Create a simple curve
spline_curve = spp.Bezier(
    degrees=[2],
    control_points=[
        [0, 0],
        [2, 0],
        [2, 2]
    ]
)
spp.io.svg.export("spline_curve_1.svg", spline_curve)

# Make it more complex
rational_spline_curve = spline_curve.nurbs
rational_spline_curve.elevate_degrees([0, 0])
rational_spline_curve.insert_knots(0, [0.4, 0.6])
rational_spline_curve.weights = np.random.random(
    (rational_spline_curve.cps.shape[0]))
spp.io.svg.export("spline_curve_3.svg", rational_spline_curve)

# Export some surfaces
circle = spp.helpme.create.surface_circle(1)
spp.io.svg.export("spline_circle_1.svg", circle)

#
circle = circle.nurbs
circle.insert_knots(0, [0.333, 0.666])
circle.insert_knots(1, [0.333, 0.666])
spp.io.svg.export("spline_circle_2.svg", circle)

results in: spline_circle_1 spline_circle_2 spline_curve_1 spline_curve_3

j042 commented 8 months ago

so smooth

danielwolff1 commented 8 months ago

Wooooow, so high-res, I zoomed in until I could count the individual atoms of the lines, this is absolutely mind-blowing 🤯 Amazing job guys! 🔥

jzwar commented 8 months ago

Add round caps using


stroke-linecap:round
jzwar commented 8 months ago

@j042 @danielwolff1 I hope you are impressed 😊 spline_rectangle_with_field

clemens-fricke commented 8 months ago

rebased since merging was blocked due to changes in splinepy.io.__init__.py resolved

jzwar commented 8 months ago

For the reviewers : @j042 @clemens-fricke and whoever has time:

I will add Gustaf objects in a later PR. Vertices and Faces. I can open an issue if required

clemens-fricke commented 8 months ago
2024-02-07 16:20:34,554 splinepy [WARNING] SVG export only supports (up to) cubic polynomial splines -- using approximation
2024-02-07 16:20:34,555 splinepy [INFO] n_control_points was not given and therefore calculated with knot_vector and degree
2024-02-07 16:20:34,557 splinepy [WARNING] SVG export only supports (up to) cubic polynomial splines -- using approximation
2024-02-07 16:20:34,558 splinepy [INFO] n_control_points was not given and therefore calculated with knot_vector and degree
Traceback (most recent call last):
  File "/home/clemensfricke/Documents/git/splinepy/examples/test.py", line 6, in <module>
    splinepy.io.export("gus.svg", spline)
  File "/home/clemensfricke/Documents/git/splinepy/splinepy/io/default.py", line 50, in export
    extension_to_io[extension].export(fname, splinepy_obj)
  File "/home/clemensfricke/Documents/git/splinepy/splinepy/io/svg.py", line 910, in export
    _export_spline(
  File "/home/clemensfricke/Documents/git/splinepy/splinepy/io/svg.py", line 794, in _export_spline
    knot_lines.append(spline.extract.spline(1, knot))
  File "/home/clemensfricke/Documents/git/splinepy/splinepy/helpme/extract.py", line 705, in spline
    return spline(self._helpee, splitting_plane, interval)
  File "/home/clemensfricke/Documents/git/splinepy/splinepy/helpme/extract.py", line 460, in spline
    spline_copy.insert_knots(para_dim, split_plane)
  File "/home/clemensfricke/Documents/git/splinepy/splinepy/bspline.py", line 112, in insert_knots
    inserted = _splinepy_core.insert_knots(
ValueError: vector::reserve

knot insertion for C^-1 at bounding box @j042

jzwar commented 8 months ago
2024-02-07 16:20:34,554 splinepy [WARNING] SVG export only supports (up to) cubic polynomial splines -- using approximation
2024-02-07 16:20:34,555 splinepy [INFO] n_control_points was not given and therefore calculated with knot_vector and degree
2024-02-07 16:20:34,557 splinepy [WARNING] SVG export only supports (up to) cubic polynomial splines -- using approximation
2024-02-07 16:20:34,558 splinepy [INFO] n_control_points was not given and therefore calculated with knot_vector and degree
Traceback (most recent call last):
  File "/home/clemensfricke/Documents/git/splinepy/examples/test.py", line 6, in <module>
    splinepy.io.export("gus.svg", spline)
  File "/home/clemensfricke/Documents/git/splinepy/splinepy/io/default.py", line 50, in export
    extension_to_io[extension].export(fname, splinepy_obj)
  File "/home/clemensfricke/Documents/git/splinepy/splinepy/io/svg.py", line 910, in export
    _export_spline(
  File "/home/clemensfricke/Documents/git/splinepy/splinepy/io/svg.py", line 794, in _export_spline
    knot_lines.append(spline.extract.spline(1, knot))
  File "/home/clemensfricke/Documents/git/splinepy/splinepy/helpme/extract.py", line 705, in spline
    return spline(self._helpee, splitting_plane, interval)
  File "/home/clemensfricke/Documents/git/splinepy/splinepy/helpme/extract.py", line 460, in spline
    spline_copy.insert_knots(para_dim, split_plane)
  File "/home/clemensfricke/Documents/git/splinepy/splinepy/bspline.py", line 112, in insert_knots
    inserted = _splinepy_core.insert_knots(
ValueError: vector::reserve

knot insertion for C^-1 at bounding box @j042

This should be fixed now, please check if the import-export works for you now, I pushed something to your cli convert branch and tested it on linux and Mac. @clemens-fricke

j042 commented 8 months ago

@jzwar knot insertion at bounds is an issue?

jzwar commented 8 months ago

@jzwar knot insertion at bounds is an issue?

It was an issue at the upper bound

clemens-fricke commented 8 months ago

Also works for me now. :+1:

j042 commented 8 months ago

@jzwar knot insertion at bounds is an issue?

It was an issue at the upper bound

Ok, do you want the fix in this PR or are you okay with next PR? I have a few things to update in BSplineLib and I can include this

jzwar commented 8 months ago

@jzwar knot insertion at bounds is an issue?

It was an issue at the upper bound

Ok, do you want the fix in this PR or are you okay with next PR? I have a few things to update in BSplineLib and I can include this

I fixed it "a bit" already. Is this your very subtle way to tell me to retract my changes and leave it to a separate PR

j042 commented 8 months ago

@jzwar knot insertion at bounds is an issue?

It was an issue at the upper bound

Ok, do you want the fix in this PR or are you okay with next PR? I have a few things to update in BSplineLib and I can include this

I fixed it "a bit" already. Is this your very subtle way to tell me to retract my changes and leave it to a separate PR

haha no, it's rather - thanks for your fix, as it fixes the issue, may I have a bit more time to fix the upstream issue?