Code Monkey home page Code Monkey logo

Comments (3)

danrbailey avatar danrbailey commented on May 22, 2024

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

from openvdb.

nyue avatar nyue commented on May 22, 2024

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

from openvdb.

danrbailey avatar danrbailey commented on May 22, 2024

"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.

from openvdb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.