Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More Compact NDArray #56

Open
mikedh opened this issue Jan 12, 2022 · 0 comments
Open

More Compact NDArray #56

mikedh opened this issue Jan 12, 2022 · 0 comments

Comments

@mikedh
Copy link

mikedh commented Jan 12, 2022

Hi, thanks for the great work! Currently 3MF encodes vertices and triangles with one node per vertex:

<vertices>
<vertex x="20.700998" y="5.546816" z="-4.762500"/>
<vertex x="8.512669" y="7.142977" z="-4.762500"/>
<vertex x="5.556250" y="9.623708" z="-4.762500"/>
<vertex x="-5.556250" y="-9.623708" z="-4.762500"/>
<vertex x="-1.929665" y="-10.943676" z="-4.762500"/>
...

Which is quite verbose and slow in languages with a large object overhead (like Python :). As a proposal: add support for an NDArray element as a child of <vertices> (and probably <triangles> too), such as:

<vertices>
<ndarray shape="10,3" values = "0.84144, 0.37634, 0.924 , 0.95611, 0.42108, 0.73491, 0.84039,
       0.1341, 0.19072, 0.87648, 0.42177, 0.72928, 0.1192, 0.91388,
       0.44683, 0.01963, 0.33069, 0.28099, 0.58583, 0.66842"/>
</vertices>

This reduces storage use by roughly 24%, which isn't infinity but also isn't trivial:

In [39]: v = np.random.random((10, 3))

In [40]: format_original = '<vertex x="{}" y="{}" z="{}"/>\n'

In [41]: format_proposed = '<ndarray shape="{shape}" values={values}"'

In [42]: len(format_proposed.format(shape=str(v.shape)[1:-1], values=',
    ...: '.join(v.flatten().astype(str))))
Out[42]: 605

In [43]: len((format_original * len(v)).format(*v.flatten()))
Out[43]: 795

In [44]: (795-605) / 795
Out[44]: 0.2389937106918239

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant