Convert a vdb file to a signed distance field

126 views
Skip to first unread message

Meher Niger

unread,
Jun 19, 2023, 4:24:10 PM6/19/23
to OpenVDB Forum
Hello everyone,

I am kind of new to openvdb language.
The initial step is I need to convert my loaded vdb file to a signed distance field. 
I was trying to do that using openvdb::tools:: :LevelSetFilter. then fixing an offset value. 
I don't think it is giving me the correct result because when I am converting the output vdb file to npy file and plotting in python it seems wrong.
I am not quite sure if my approach or the filter I am using is right. Can anyone give me any suggestions? 
Thanks in advance. 
Here is my code. 

int main()
{
    openvdb::initialize();

    // Load VDB grid from file
    openvdb::io::File file("input.vdb");
    file.open();

    openvdb::GridBase::Ptr baseGrid;
    for (openvdb::io::File::NameIterator nameIter = file.beginName();
        nameIter != file.endName(); ++nameIter)
    {
        // Read in only the grid we are interested in.
        if (nameIter.gridName() == "LevelSetSphere") {
            baseGrid = file.readGrid(nameIter.gridName());
        }
        else {
            std::cout << "skipping grid " << nameIter.gridName() << std::endl;
        }
    }
    file.close();

 

    openvdb::FloatGrid::Ptr grid = openvdb::gridPtrCast<openvdb::FloatGrid>(baseGrid);

    openvdb::tools::LevelSetFilter<openvdb::FloatGrid> lsf(*grid);
    lsf.offset(-0.5);
     

    // Save the modified grid as a new VDB file
    openvdb::io::File output("output.vdb");
    output.write({ grid });
    output.close();

 

    return 0;
}


andre pradhana

unread,
Jun 21, 2023, 1:22:27 AM6/21/23
to OpenVDB Forum
If I understand you correctly, you want to convert a density field/fog field to a signed distance field. I recommend using

openvdb::v10_0::tools::fogToSdf. You need to include #include <openvdb/tools/FastSweeping.h> to use this tool.

Andre
Message has been deleted
Message has been deleted
Message has been deleted

Meher Niger

unread,
Jun 21, 2023, 5:32:23 PM6/21/23
to OpenVDB Forum
Thank you so much Andre for your response and clarification.
Following your instructions I was trying to apply openvdb::v10_0::tools::fogToSdf(*grid, ISO value= 0) 
But it seems like still it's not creating the signed distance field. I am not sure if I am using a wrong ISO value or I am misunderstanding something else. 
For your clarification, as input I have 3D grids with zeros and ones. I want to fill the rest of the area with SDF.  Please let me know if you have any questions. 
Thank you again for your time and help.
Sincerely
Meher
Reply all
Reply to author
Forward
0 new messages