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

added export check to splinepy/io/iges.py #273

Closed mkofler96 closed 11 months ago

mkofler96 commented 1 year ago

Overview

iges export now checks parametric dimension of spline, if it is 3, then a value error is raised and a suggestion for a solution is presented

Addressed issues

Showcase

calling the example from the issue now gives the following error:

ValueError                                Traceback (most recent call last)
[c:\Users\mkofler\miniconda3\envs\splinepy_dev\Lib\site-packages\splinepy\microstructure_fix.ipynb](file:///C:/Users/mkofler/miniconda3/envs/splinepy_dev/Lib/site-packages/splinepy/microstructure_fix.ipynb) Cell 3 line 1
     [13](vscode-notebook-cell:/c%3A/Users/mkofler/miniconda3/envs/splinepy_dev/Lib/site-packages/splinepy/microstructure_fix.ipynb#W0sZmlsZQ%3D%3D?line=12) microstructure.microtile = getattr(sp.microstructure.tiles, "NutTile3D")().create_tile()[0]
     [14](vscode-notebook-cell:/c%3A/Users/mkofler/miniconda3/envs/splinepy_dev/Lib/site-packages/splinepy/microstructure_fix.ipynb#W0sZmlsZQ%3D%3D?line=13) microstructure.tiling = [8, 4, 1]
---> [16](vscode-notebook-cell:/c%3A/Users/mkofler/miniconda3/envs/splinepy_dev/Lib/site-packages/splinepy/microstructure_fix.ipynb#W0sZmlsZQ%3D%3D?line=15) sp.io.iges.export("test.igs",microstructure.create().patches)
     [17](vscode-notebook-cell:/c%3A/Users/mkofler/miniconda3/envs/splinepy_dev/Lib/site-packages/splinepy/microstructure_fix.ipynb#W0sZmlsZQ%3D%3D?line=16) ig = sp.io.iges.load("test.igs")
     [18](vscode-notebook-cell:/c%3A/Users/mkofler/miniconda3/envs/splinepy_dev/Lib/site-packages/splinepy/microstructure_fix.ipynb#W0sZmlsZQ%3D%3D?line=17) ig.show(control_points=False)

File [c:\Users\mkofler\miniconda3\envs\splinepy_dev\Lib\site-packages\splinepy\io\iges.py:41](file:///C:/Users/mkofler/miniconda3/envs/splinepy_dev/Lib/site-packages/splinepy/io/iges.py:41), in export(fname, splines)
     39 for ispl, spline in enumerate(splines):
     40   if spline.para_dim == 3:
---> 41       raise ValueError(f"Volumetric {type(spline)} found at splines[{ispl}], which cannot be handled by the Iges file format \n"
     42                        "Use a boundary representation instead by calling e.g. spline.boundary_multipatch()")
     44 return splinepy_core.export_iges(fname, splines)

ValueError: Volumetric <class 'splinepy.bezier.Bezier'> found at splines[0], which cannot be handled by the Iges file format 
Use a boundary representation instead by calling e.g. spline.boundary_multipatch()

Checklists

mkofler96 commented 1 year ago

Thanks! Can you add a round-trip test? You can create a separate PR and we can merge both when the test is ready

Did you think of something like this? tests/test_json.py

If yes: should we keep all import/export tests in a single file? Then one could loop over every import/export method, something like

        with tempfile.TemporaryDirectory() as tmpd:
            tmpf = c.to_tmpf(tmpd)

            export_formats = [(c.splinepy.io.json, {"bas64encoding": False}), (c.splinepy.io.iges, {}), (c.splinepy.io.irit, {}) ...]

            for (ef, ef_arguments) in export_formats: 
                ef.export(
                    tmpf, list_of_splines, **ef_arguments
                )
                list_of_splines_loaded = ef.load(tmpf)
                self.assertTrue(
                    all(
                        c.are_splines_equal(a, b)
                        for a, b in zip(list_of_splines, list_of_splines_loaded)
                    )
                )

What do you think?

j042 commented 1 year ago

Thanks! Can you add a round-trip test? You can create a separate PR and we can merge both when the test is ready

Did you think of something like this? tests/test_json.py

If yes: should we keep all import/export tests in a single file? Then one could loop over every import/export method, something like

        with tempfile.TemporaryDirectory() as tmpd:
            tmpf = c.to_tmpf(tmpd)

            export_formats = [(c.splinepy.io.json, {"bas64encoding": False}), (c.splinepy.io.iges, {}), (c.splinepy.io.irit, {}) ...]

            for (ef, ef_arguments) in export_formats: 
                ef.export(
                    tmpf, list_of_splines, **ef_arguments
                )
                list_of_splines_loaded = ef.load(tmpf)
                self.assertTrue(
                    all(
                        c.are_splines_equal(a, b)
                        for a, b in zip(list_of_splines, list_of_splines_loaded)
                    )
                )

What do you think?

yes

jzwar commented 12 months ago

Is this still beeing worked on?

mkofler96 commented 12 months ago

Is this still beeing worked on?

yes, I'm still working on the round-trip tests, I just have not found the time for it yet

j042 commented 11 months ago

so turns out BSplineLib will append zeros in case of dim < para_dim and always export 3D splines (maybe this is IGES rule?)