Hello,
As a simple test, I'm using MeshToVolume to convert a triangle mesh to a FloatGrid, then using VolumeToMesh to convert the grid back to a mesh.
For the most part it seems to work as I expect but on some models I get some strange behaviour. The attached image demonstrates the problem. The mesh on the left is the original model, and the mesh on the right is the mesh output of VolumeToMesh. It seems like in areas with long cylindrical regions, the voxels get "smeared".
My code looks like this:
openvdb::FloatGrid::Ptr CreateGrid( )
{
openvdb::math::Transform::Ptr transform = openvdb::math::Transform::createLinearTransform();
openvdb::tools::MeshToVolume<openvdb::FloatGrid> meshToVol(transform);
std::vector<openvdb::Vec3s> pointList;
std::vector<openvdb::Vec4I> polyList;
// copy mesh data into lists...
meshToVol.convertToLevelSet(
pointList,
polyList );
return meshToVol.distGridPtr();
}
openvdb::FloatGrid::Ptr grid = CreateGrid();
// Convert the level set sphere to a narrow-band fog volume, in which
// interior voxels have value 1, exterior voxels have value 0, and
// narrow-band voxels have values varying linearly from 0 to 1.
//
// Code taken from cookbook
for( openvdb::FloatGrid::ValueOffIter iter = grid->beginValueOff(); iter; iter++ )
{
if( iter.getValue() < 0.0f )
{
iter.setValue(1.0f);
iter.setValueOff();
}
}
const float outside = grid->background();
const float width = 2.0 * outside;
for( openvdb::FloatGrid::ValueOnIter iter = grid->beginValueOn(); iter; iter++ )
{
float value = iter.getValue();
iter.setValue( (outside - value) / width );
}
grid->setBackground(0.0f);
openvdb::v1_0_0::tools::VolumeToMesh volToMesh;
volToMesh.operator()< openvdb::v1_0_0::FloatGrid >( grid.operator*() );
// convert back into mesh using the point and poly lists from volToMesh...
I've attached the mesh I used as an obj file. Any ideas what I'm doing wrong?