Forceflow / cuda_voxelizer

CUDA Voxelizer to convert polygon meshes into annotated voxel grids
MIT License
597 stars 98 forks source link

Add translate and scale to binvox file #36

Closed non-void closed 4 years ago

non-void commented 4 years ago

I used cuda_voxelizer to generate binvox files and intended to read the file using binvox_rw_py

However, the file generated lacks translate and scale in its ASCII header, I have to manually add following lines to the function write_binvox:

    output << "translate " << info.bbox.min.x << " " << info.bbox.min.y << " " << info.bbox.min.z << endl;
    output << "scale " << max(max(info.bbox.max.x - info.bbox.min.x, info.bbox.max.y - info.bbox.min.y),
                              info.bbox.max.z - info.bbox.min.z) << endl;

I guess it is right, because I checked that all vertices falls in to voxel using the following coordinate translation function:

def cartesian2voxcoord(v, vox):
    vn = (v - vox.translate) / vox.scale
    vc = np.floor(vn * vox.dims)
    vc = np.clip(vc, 0, vox.dims - np.ones(3, dtype=np.int)).astype(int)
    # original code: vc = np.round(vc).astype(int)
    return vc

Do you have any support for this feature?

Forceflow commented 4 years ago

Since the generated files loaded fine in viewvox, I presumed my binvox output was fine.

This puts the model back in it's original position, I guess? I'll look into adding this, looks like an easy fix. Though I think it is optional in the .binvox spec, but I'd have to check.

Forceflow commented 4 years ago

@non-void

I added this in commit 476c980daf5dd27a24dc4576af29c70bc0be034c to the dev branch.

I'm working on some other features this week (CPU version of solid voxelize, update timings, ...), after that I'll merge dev into master for a new release.

Thanks for the suggestion, I looked up the binvox spec, and the translate and scale header entries don't seem to be optional, but the tool I was using to verify my .binvox files (viewvox) also works if they're not there.

Anyhow, cuda_voxelizer should now spit out .binvox file that work in that python lib you mentioned.

Forceflow commented 4 years ago

Already released it today on 0.4.7 - thanks! https://github.com/Forceflow/cuda_voxelizer/releases/tag/v0.4.7