by Const-me · 5y ago · 0 comments
Text formats are good when human readable, but no sane person gonna read 1GB of data. Not even 100MB. Both numbers are reasonable now for very high-poly models.
They should have designed a true binary format, instead of zipped XML. Speaking of the STL format, it can be either binary or text depending on the header. When they have measured size, pretty sure they have used text variant of STL, otherwise they'd get similar sizes.
Also, the format is rather complex. One of the reasons why STL is so popular, only needs couple pages of code to support, almost regardless on the programming language. For optimal compatibility, one needs the official C++ only lib3mf library to read/write 3MF files.
> Text compression of number data is extremely efficient
Of course it isn't. It is arguably one of the worst there is. It can only ever by more efficient when representing a very low subset of values and the alternative binary representation is exceedingly poor. But those constraint would make the whole discussion kinda silly.
Serializing text, is after all binary encoding data. If you follow this with compression algorithms, you'll likely not end up too far away in either case.
Just take the example you gave. "A 5 digit integer is 3 bytes less than the double to store it". Yes, true. However, a 5 digit integer can also be represented by 12 bits.
And you can even pack them if this is all you really care about (there is a good reason why you wouldn't want to do this, as word alignment is much more important, as you would be able to directly map data to memory allocations, but let's for argument sake say that storage was king). For each 5 digit numbers as a text file, you'll need another byte to encode the line break or delimiter. I.e. 6 bytes instead of 12 bits, or 4 times wasted space. For a million values, 5.7 MiB instead of 1.4 MiB.
In almost all cases in practice one is only serializing a very low subset of values. A 1 TB file, no matter how efficient the encoding, could only contain serialization of less than 0.00005% of the possible IEEE 754 double values.
To reiterate my original point: It is never the case that serializing text that represents numbers is the most efficient representation. The posts here seem to either suggest or think this is the case. And this was only the size consideration. It is even worse in terms of processing. You need to do O(n) operations on the length of text data just in order to decode the values. A step that is entirely avoided with a correct binary format.
Just a anecdotal example here on the computational aspect. Maybe 10 years ago or so, I used an OBJ loading library that would straight up decode 3d models represented as ASCII text. I wrote a simple de/serialization program, just 70 lines of code, to both dump and read dumped data. The load speed for a complicated scene went from 38 to 0.7 seconds.
This isn't to say there aren't good use cases for text formats. However, it is always a tradeoff for human readable data, at the expense of efficiency (storage and computational). The former is much less so when using a simple compression step. Very often this tradeoff is acceptable.
In other cases it’s the opposite. Convert a model from millimeters to inches, and that 1.0/25.4 multiplier gonna cause decimal representation to be much longer than 8 digits. Mechanical engineers are doing things like that pretty often.
> when humans enter data in some specific units
I don’t think it’s a reasonable expectation for a human to type 100 MB, or 1GB of numbers. People do work with triangle meshes that large. These models were made by specialized hardware or software tools, not by entering numbers. It’s the same story with images: they have too many megapixels now, and people aren’t entering millions of RGB numbers. Instead, people using scanners, digital cameras, and Photoshop to deal with these volumes of data.
> Text compression of number data is extremely efficient
The most expensive part is not compression, it’s printing and parsing. That code is very hard to vectorize or parallelize.
When software reads or writes large continuous buffer of binary data like std::vector in C++, the throughput is often limited by physical disk. On many modern computers that’s at least 100 MBytes/sec, often much faster.
I think it’s borderline impossible to print or parse float numbers that fast. Especially given that in 3MF, there’s some XML producer/parser down the stack who needs to escape/unescape these strings.
I think text is a good format for the "truth"; a binary one-to-one representation of that text to avoid floats parsing is the best alternative. Counterintuitive as it is, many times, the text representation takes less space (sometimes there are huge lot of little round values, for examples 0s or 1s or 2s, in some columns).
I often wonder why BCD file formats are not used.
Much of Additive uses SI units, fortunately. One of the bigger players remains with Imperial units, unfortunately
I do sales, service, support in this industry. One of the more hilarious queries I got recently was, "Does your machine support freedom units?"
We all had a nice chuckle, and yes that shop works mixed and it's a pain point for them being a mix of older school and new school tech and people all over the map. They don't see a transition in the near future either. Too much of the work remains Imperial as does equipment that has a long service life ahead.
The real problem lies in formats and software that makes assumptions about units, and or makes it all difficult to manage, or input / extract mixed unit data.
I see meters used fairly often too. Not the same non integer conversion, but the other problems do remain.
hex => dec
a.8 => 10.5
f.88 => 15.55
9.e => 9.875
11.8 => 17.5
a.8E1 => 168 (15.5*16)
a.8E2 => 2688 (15.5*16^2)I ask myself though will it practically matter in the 3MF vs STL case, given 3MF uses a different approach to represent geometries that produces both more accurate and far more compact results than STL for a similarly high precision[0]?
[0] https://hawkridgesys.com/blog/3mf-the-file-format-for-the-fu...
> Text formats are good when human readable, but no sane person gonna read 1GB of data.
People are regularly editing the resulting G-Code file which is even bigger in size. They use old fashioned text editors for this which works because it's not binary but simple text with readable numbers. Then those huge files are processed with little 8-Bit computers which have barely enough processing power to move the motors.
Some common edits are:
Change in process parameters mid program, speed / feed rate tweaks to optimize production jobs, tool number change to run job on different machine / tool setup.
Big G-code files are my favorite text editor test.
As with any format, the tooling needs to develop, and then C++ is not a bad idea to write a library in I think.
I guess there's space for both file formats tbh. If you are sure your STL is correct, and are sure about the dimensioning, go for it. If you want to be a little safer, go for 3MF, with the drawback of a little larger filesize.
Yeah, if in a next version they will move vertex/index buffer data from XML into binary files in the same ZIP (3MF are ZIP files), will be better already. Printing and parsing numbers is surprisingly expensive when you have a gigabyte of them.
> C++ is not a bad idea to write a library
C++ is fine by itself. Still, should the format be simpler, the official library would be optional, as people would be able to implement support in any language without FFI. It’s hard to do in practice, which leaves the official library as the only practical option, IMO. At least that’s what I did when a client asked me to support that format.
As for need of the new formats, for one, modern CAD formats are insanely complex. These IGES/STEP/BREP files require many megabytes of very complicated code to deal with, such as this library https://github.com/tpaviot/oce These formats may even contain proprietary extensions. Also, they need non-trivial processing power to handle. Many people wouldn’t want a Core i7 with gigabytes of RAM in their 3D printers, inflates hardware cost and software complexity.
Besides, we now have high-resolution 3D scanners, and CAE software which algorithmically optimizes models by running numerical simulations. They both output triangle meshes instead of CAD files. Scanners often output point clouds one can convert into triangles, but hard to convert into CAD formats.
I just don’t like the 3MF implementation too much. XML is fine for kilobytes of data, but not many megabytes. If I would be designing that format, I would probably made it binary. Maybe EBML https://en.wikipedia.org/wiki/Extensible_Binary_Meta_Languag... would work for that; it does fine for MKV videos, which is also a huge pile of structured data with non-trivial performance constraints for producers and especially parsers.
Another minor thing, it was not the best idea to make name start with a digit. Most programming languages forbid identifiers like that for their classes / functions / namespaces / modules.
CAD data for products like Fusion360 or SolidWorks depend on a geometric modeling kernel, which is a complex piece of software. To do anything with that data, you need to run the kernel, and you need to run it the same way the software package does. While there is an open source kernel (OpenCascade), it's not as fully featured and in any case not compatible as the industry leader Parasolid.
To use CAD data in a printer or CNC, you'd possibly need to pay a license for the kernel, but also have the exact version available and therefore dozens of versions for compatibility, you'd have to support and debug running all those complex kernels, handle compatibility upgrades, have enough storage CPU/RAM/disk and so on. And then subtle bugs in different versions/kernels would result in different results. Imagine the support nightmare.
G-code generated from these files often contains that info, and some additional info specific to the job created. Same benefits of plain text.
Often, I get these files and that information being available, easy to read without having to have specific software is a huge win.
Humans do read these files :D
It's not the dumbest engineering data format I've seen (seen many, this is at least one you can parse).
But ffs, just use HDF5 people.
It’s not, but should the models be binary, the format would be much better.
> just use HDF5
Last time I checked (a few years ago), HDF5 was only possible to handle with the official C++ library. That library didn’t even support multithreading, when I tried to write 2 HDF5 files from 2 concurrent thread, the program crashed with broken data structures in some global variables deep inside the HDF5 library.
My computer has 16 hardware threads, the servers I’m targeting often have more of them, and I’d like to actually use that hardware. Single-threaded libraries aren’t OK in my books; not in 2021.
IMO the main reason why binary formats suffered from compatibility issues in the past was huge variations of hardware. We had little endian/big endian CPUs, 16/32/64 bit bitness, earlier in the past there were even weirder computers with non-two complement signed integers, or 12 bits in a memory word.
By now we only have big endian CPUs. Vast majority of them are 64 bits. All of them are using IEEE floats, at least for FP64 and FP32 numbers; for FP16 there’re several versions, unfortunately. None of that is likely to change in 10 or 20 years.
For applications where performance matters, like image and video codecs, we do have binary formats which are older than 20 years, still in wide use, with little to no compatibility issues. Examples are PNG from 1997, or Mpeg-4 from 1998.