FloatGrid to Vec3SGrid and back to FloatGrid problem

81 views
Skip to first unread message

Víctor M. Feliz

unread,
Dec 7, 2022, 7:46:18 AM12/7/22
to OpenVDB Forum
Here is a basic sample converting them and dumping the result into a mesh:


// FloatGrid  to Vec3SGrid
openvdb::Vec3SGrid::Ptr Vec3SGrid = openvdb::Vec3SGrid::create();
Vec3SGrid->setTransform( floatGridA->transformPtr());
for (auto itAll =  floatGridA ->cbeginValueOn(); itAll; ++itAll) {
        auto pos = itAll.getCoord();
        auto valueAll = itAll.getValue();
        auto Vec3s = Vec3SGrid->tree().getValue(pos);
        Vec3s[0] = valueAll;
        Vec3SGrid->tree().setValue(pos, Vec3s);       
 }

// Back to FloatGrid
openvdb::FloatGrid::Ptr floatGridB = openvdb::FloatGrid::create();
floatGridB ->setTransform( Vec3SGrid->transformPtr());
for (auto it = grid->cbeginValueOn(); it; ++it) {
      auto pos = it.getCoord();
      auto Vec3s = it.getValue();
       floatGridB->tree().setValue(pos, Vec3s[0]);
}

 OpenVDBMesh meshA, meshB;
    openvdb::tools::volumeToMesh(*floatGridA ,  meshA.points,  meshA.faces,  meshA.quads, iso, adapt, flag_relax);    openvdb::tools::volumeToMesh(*floatGridB ,  meshB.points,  meshB.faces,  meshB.quads, iso, adapt, flag_relax);


Unfortunately the besides I've copied transform too, the result on both meshes are different. 

Any idea on that? thank you!

Reply all
Reply to author
Forward
0 new messages