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

add lzma compressed bmsh file and benchmark #3

Merged
merged 1 commit into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,20 @@ The plots below show performance on an Apple M1 (15w passively cooled MacBook Ai
This is a simple node.js function that you can replicate on your own computer:

```
$ npm install gifti-reader-js atob pako buffer
$ npm install gifti-reader-js atob pako buffer lzma-purejs
$ git clone https://github.com/neurolabusc/MeshFormatsJS.git
$ cd MeshFormatsJS
$ node ./meshtest.js

gifti.gii Size 4384750 Time 2111
gz.mz3 Size 3259141 Time 541
raw.mz3 Size 5898280 Time 31
obj.obj Size 13307997 Time 5318
stl.stl Size 16384084 Time 1075
zlib.jmsh Size 4405604 Time 660
zlib.bmsh Size 3259049 Time 479
raw.min.json Size 12325881 Time 1239
raw.bmsh Size 5898902 Time 38
gz.gii Size 4384750 Time 1905
gz.mz3 Size 3259141 Time 510
raw.mz3 Size 5898280 Time 21
obj.obj Size 13307997 Time 5491
stl.stl Size 16384084 Time 163
zlib.jmsh Size 4405604 Time 593
zlib.bmsh Size 3259049 Time 464
raw.min.json Size 12325881 Time 1352
raw.bmsh Size 5898902 Time 24
lzma.bmsh Size 2295259 Time 5290

```
7 changes: 5 additions & 2 deletions lib/jdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class jdata{
};
this._zipper = (typeof pako !== 'undefined'
? pako
: require('pako'));
: options.hasOwnProperty('compression') ? require(options['compression']) : require('pako'));
if(options.hasOwnProperty('usenumjs') && options['usenumjs']==1){
this._nj = (typeof nj !== 'undefined'
? nj
Expand Down Expand Up @@ -71,7 +71,10 @@ class jdata{
return this._zipper.inflate(str);
else if(method==='gzip')
return this._zipper.ungzip(str);
else
else if(method==='lzma'){
return this._zipper.decompressFile(str); // if using lzma-purejs module
//return Uint8Array.from(this._zipper.decompress(str)); // if using lzma module, 4x slower than lzma-purejs
}else
throw "compression method not supported";
}

Expand Down
Binary file added meshes/lzma.bmsh
Binary file not shown.
6 changes: 5 additions & 1 deletion meshtest.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ readSTL = function (buffer) {
}; // readSTL()

async function main() {
const fnms = ["gz.gii", "gz.mz3", "raw.mz3", "obj.obj", "stl.stl", "zlib.jmsh", "zlib.bmsh", "raw.min.json", "raw.bmsh"];
const fnms = ["gz.gii", "gz.mz3", "raw.mz3", "obj.obj", "stl.stl", "zlib.jmsh", "zlib.bmsh", "raw.min.json", "raw.bmsh", "lzma.bmsh"];
//const fnms = ["gifti.gii", "gz.mz3", "raw.mz3", "obj.obj", "stl.stl"];
let npt = 491526; //number of points, each vertex has 3 (XYZ)
let nidx = 983040; //number of indices: each triangle has 3
Expand Down Expand Up @@ -219,6 +219,10 @@ async function main() {
if(fnm.match(/raw/)){
points = jmsh[0].MeshVertex3;
indices = jmsh[0].MeshTri3;
}else if(fnm.match(/lzma/)){
jmsh=new jd(jmsh[0], {usenumjs:false, compression:'lzma-purejs'}).decode();
points = jmsh.data.MeshVertex3;
indices = jmsh.data.MeshTri3;
}else{
jmsh=new jd(jmsh[0], {usenumjs:false}).decode();
points = jmsh.data.MeshVertex3;
Expand Down