Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create PointPartitioner from data that is read in ? #109

Closed
nyue opened this issue Dec 7, 2016 · 3 comments
Closed

How to create PointPartitioner from data that is read in ? #109

nyue opened this issue Dec 7, 2016 · 3 comments

Comments

@nyue
Copy link
Contributor

nyue commented Dec 7, 2016

Hi,

After reading in an OpenVDB 4 file with point data, how does one create a partitioner ?

I am looking to the partitioner to provide indices to actual points (per bucket?) and query additional information like position, velocity and other attributes.

So far, I don't know what method in PointDataGrid returns object that can be use for the construction of the Partitioner, here is my current attempt, ::create() fails to compile as I am not providing what it needs

I see the example creating a struct call PointList within an anonymous namespace

`
openvdb::io::File fileIn(vdb_file);
fileIn.open();

    openvdb::GridPtrVecPtr grids = fileIn.getGrids();

    fileIn.close();

	std::cout << boost::format("Grid size = %1%") % grids->size() << std::endl;

	if (!grids->empty())
	{
		openvdb::points::PointDataGrid::Ptr inputPointDataGrid = openvdb::GridBase::grid<openvdb::points::PointDataGrid>((*grids)[0]);
		if (inputPointDataGrid)
		{
			if (!inputPointDataGrid->empty())
			{
			    const float voxelSize = 0.1f;
			    const openvdb::math::Transform::Ptr transform =
			            openvdb::math::Transform::createLinearTransform(voxelSize);

			    typedef openvdb::tools::UInt32PointPartitioner PointPartitioner;

			    PointPartitioner::Ptr partitioner =
			                PointPartitioner::create(pointList, *transform);

`

Cheers

@danrbailey
Copy link
Contributor

Hi @nyue,

I'm currently working on getting the code samples and documentation ready for submission into OpenVDB, so that should help explain this better. In short, the PointPartitioner is only for use with a PointIndexGrid where the attribute data is stored in a linear external array.

Here's a super-simple example for iterating over position data in a PointDataGrid:

for (auto leafIter = grid.tree().cbeginLeaf(); leafIter; ++leafIter) {
    auto handle = openvdb::points::AttributeHandle<Vec3f>::create(leafIter->constAttributeArray("P"));
    for (auto iter = leafIter->beginIndexOn(); iter; ++iter) {
        const Vec3d voxelCoord = iter.getCoord().asVec3d();
        const Vec3d positionVoxelSpace = handle->get(*iter);
        const Vec3d positionWorldSpace = grid.transform().indexToWorld(positionVoxelSpace + voxelCoord);
        std::cerr << "Position: " << positionWorldSpace << std::endl;
    }
}

Hope that helps.

Dan

@nyue
Copy link
Contributor Author

nyue commented Dec 7, 2016

Thank you.

In your code

leafIter->constAttributeArray("P")

How do you know there will be an attribute call "P" ?

How does one programmatically find all the other attribute names ?

Cheers

@danrbailey
Copy link
Contributor

danrbailey commented Dec 8, 2016

"P" is a mandatory attribute.

For simple inspection, you can use some of the convenience methods on the PointDataLeaf:

bool test1 = leafIter->hasAttribute("P");
bool test2 = leafIter->hasAttribute(/*index=*/4);

Otherwise, you'll need to go through the Descriptor:

const AttributeSet::Descriptor& descriptor = leafIter->attributeSet().descriptor();
for (const auto& namePos : descriptor.map()) {
    const Name& name = namePos.first;
    const size_t index = namePos.second;
    const Name& valueType = descriptor.valueType(index);
}

Although the API doesn't enforce this, by convention we assume that the Descriptor is the same across all LeafNodes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants