zarquon42b/Rvcg

vcgImport unnecessarily converts it index elements from int to numeric

Closed this issue · 1 comments

Having numeric (double) indices means that meshes typically occupy order 1.5x more memory than necessary. This arieses when converting from 0- (C) to 1-indexed (R) form when 1 (double) rather 1L (integer) is added.

Rvcg/R/vcgImport.r

Lines 82 to 83 in a7c34a5

if (length(tmp$it))
out$it <- matrix(tmp$it,3,(length(tmp$it)/3))+1

From a debug session, showing the difference between adding 1 and 1L:

> str(out)
List of 2
 $ vb: num [1:4, 1:66055] 402470 194470 143590 1 402504 ...
 $ it: num [1:3, 1:132188] 1 11 15 1 15 6 2 4 44 2 ...
 - attr(*, "class")= chr "mesh3d"
> object.size(out)
5287280 bytes
> out$it <- matrix(tmp$it, 3, (length(tmp$it)/3)) + 1L
> str(out)
List of 2
 $ vb: num [1:4, 1:66055] 402470 194470 143590 1 402504 ...
 $ it: int [1:3, 1:132188] 1 11 15 1 15 6 2 4 44 2 ...
 - attr(*, "class")= chr "mesh3d"
> object.size(out)
3701024 bytes

Thanks for picking this up super quickly @zarquon42b!